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"
47 #include "filestuff.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void cleanup_sigint_signal_handler (void *dummy
);
92 static void initialize_sigint_signal_handler (void);
93 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
94 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
95 int forever
, int *is_notif
);
97 static void handle_remote_sigint (int);
98 static void handle_remote_sigint_twice (int);
99 static void async_remote_interrupt (gdb_client_data
);
100 void async_remote_interrupt_twice (gdb_client_data
);
102 static void remote_files_info (struct target_ops
*ignore
);
104 static void remote_prepare_to_store (struct regcache
*regcache
);
106 static void remote_open (char *name
, int from_tty
);
108 static void extended_remote_open (char *name
, int from_tty
);
110 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
112 static void remote_close (void);
114 static void remote_mourn (struct target_ops
*ops
);
116 static void extended_remote_restart (void);
118 static void extended_remote_mourn (struct target_ops
*);
120 static void remote_mourn_1 (struct target_ops
*);
122 static void remote_send (char **buf
, long *sizeof_buf_p
);
124 static int readchar (int timeout
);
126 static void remote_serial_write (const char *str
, int len
);
128 static void remote_kill (struct target_ops
*ops
);
130 static int tohex (int nib
);
132 static int remote_can_async_p (void);
134 static int remote_is_async_p (void);
136 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
137 void *context
), void *context
);
139 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
141 static void remote_interrupt (int signo
);
143 static void remote_interrupt_twice (int signo
);
145 static void interrupt_query (void);
147 static void set_general_thread (struct ptid ptid
);
148 static void set_continue_thread (struct ptid ptid
);
150 static void get_offsets (void);
152 static void skip_frame (void);
154 static long read_frame (char **buf_p
, long *sizeof_buf
);
156 static int hexnumlen (ULONGEST num
);
158 static void init_remote_ops (void);
160 static void init_extended_remote_ops (void);
162 static void remote_stop (ptid_t
);
164 static int ishex (int ch
, int *val
);
166 static int stubhex (int ch
);
168 static int hexnumstr (char *, ULONGEST
);
170 static int hexnumnstr (char *, ULONGEST
, int);
172 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
174 static void print_packet (char *);
176 static void compare_sections_command (char *, int);
178 static void packet_command (char *, int);
180 static int stub_unpack_int (char *buff
, int fieldlength
);
182 static ptid_t
remote_current_thread (ptid_t oldptid
);
184 static void remote_find_new_threads (void);
186 static void record_currthread (ptid_t currthread
);
188 static int fromhex (int a
);
190 static int putpkt_binary (char *buf
, int cnt
);
192 static void check_binary_download (CORE_ADDR addr
);
194 struct packet_config
;
196 static void show_packet_config_cmd (struct packet_config
*config
);
198 static void update_packet_config (struct packet_config
*config
);
200 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
201 struct cmd_list_element
*c
);
203 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
205 struct cmd_list_element
*c
,
208 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
209 static ptid_t
read_ptid (char *buf
, char **obuf
);
211 static void remote_set_permissions (void);
214 static int remote_get_trace_status (struct trace_status
*ts
);
216 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
218 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
220 static void remote_query_supported (void);
222 static void remote_check_symbols (struct objfile
*objfile
);
224 void _initialize_remote (void);
227 static void stop_reply_xfree (struct stop_reply
*);
228 static void remote_parse_stop_reply (char *, struct stop_reply
*);
229 static void push_stop_reply (struct stop_reply
*);
230 static void discard_pending_stop_replies (struct inferior
*);
231 static int peek_stop_reply (ptid_t ptid
);
233 static void remote_async_inferior_event_handler (gdb_client_data
);
235 static void remote_terminal_ours (void);
237 static int remote_read_description_p (struct target_ops
*target
);
239 static void remote_console_output (char *msg
);
241 static int remote_supports_cond_breakpoints (void);
243 static int remote_can_run_breakpoint_commands (void);
247 static struct cmd_list_element
*remote_cmdlist
;
249 /* For "set remote" and "show remote". */
251 static struct cmd_list_element
*remote_set_cmdlist
;
252 static struct cmd_list_element
*remote_show_cmdlist
;
254 /* Description of the remote protocol state for the currently
255 connected target. This is per-target state, and independent of the
256 selected architecture. */
260 /* A buffer to use for incoming packets, and its current size. The
261 buffer is grown dynamically for larger incoming packets.
262 Outgoing packets may also be constructed in this buffer.
263 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
264 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
269 /* True if we're going through initial connection setup (finding out
270 about the remote side's threads, relocating symbols, etc.). */
273 /* If we negotiated packet size explicitly (and thus can bypass
274 heuristics for the largest packet size that will not overflow
275 a buffer in the stub), this will be set to that packet size.
276 Otherwise zero, meaning to use the guessed size. */
277 long explicit_packet_size
;
279 /* remote_wait is normally called when the target is running and
280 waits for a stop reply packet. But sometimes we need to call it
281 when the target is already stopped. We can send a "?" packet
282 and have remote_wait read the response. Or, if we already have
283 the response, we can stash it in BUF and tell remote_wait to
284 skip calling getpkt. This flag is set when BUF contains a
285 stop reply packet and the target is not waiting. */
286 int cached_wait_status
;
288 /* True, if in no ack mode. That is, neither GDB nor the stub will
289 expect acks from each other. The connection is assumed to be
293 /* True if we're connected in extended remote mode. */
296 /* True if the stub reported support for multi-process
298 int multi_process_aware
;
300 /* True if we resumed the target and we're waiting for the target to
301 stop. In the mean time, we can't start another command/query.
302 The remote server wouldn't be ready to process it, so we'd
303 timeout waiting for a reply that would never come and eventually
304 we'd close the connection. This can happen in asynchronous mode
305 because we allow GDB commands while the target is running. */
306 int waiting_for_stop_reply
;
308 /* True if the stub reports support for non-stop mode. */
311 /* True if the stub reports support for vCont;t. */
314 /* True if the stub reports support for conditional tracepoints. */
315 int cond_tracepoints
;
317 /* True if the stub reports support for target-side breakpoint
319 int cond_breakpoints
;
321 /* True if the stub reports support for target-side breakpoint
323 int breakpoint_commands
;
325 /* True if the stub reports support for fast tracepoints. */
326 int fast_tracepoints
;
328 /* True if the stub reports support for static tracepoints. */
329 int static_tracepoints
;
331 /* True if the stub reports support for installing tracepoint while
333 int install_in_trace
;
335 /* True if the stub can continue running a trace while GDB is
337 int disconnected_tracing
;
339 /* True if the stub reports support for enabling and disabling
340 tracepoints while a trace experiment is running. */
341 int enable_disable_tracepoints
;
343 /* True if the stub can collect strings using tracenz bytecode. */
346 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
347 responded to that. */
351 /* Private data that we'll store in (struct thread_info)->private. */
352 struct private_thread_info
359 free_private_thread_info (struct private_thread_info
*info
)
365 /* Returns true if the multi-process extensions are in effect. */
367 remote_multi_process_p (struct remote_state
*rs
)
369 return rs
->multi_process_aware
;
372 /* This data could be associated with a target, but we do not always
373 have access to the current target when we need it, so for now it is
374 static. This will be fine for as long as only one target is in use
376 static struct remote_state remote_state
;
378 static struct remote_state
*
379 get_remote_state_raw (void)
381 return &remote_state
;
384 /* Description of the remote protocol for a given architecture. */
388 long offset
; /* Offset into G packet. */
389 long regnum
; /* GDB's internal register number. */
390 LONGEST pnum
; /* Remote protocol register number. */
391 int in_g_packet
; /* Always part of G packet. */
392 /* long size in bytes; == register_size (target_gdbarch (), regnum);
394 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
398 struct remote_arch_state
400 /* Description of the remote protocol registers. */
401 long sizeof_g_packet
;
403 /* Description of the remote protocol registers indexed by REGNUM
404 (making an array gdbarch_num_regs in size). */
405 struct packet_reg
*regs
;
407 /* This is the size (in chars) of the first response to the ``g''
408 packet. It is used as a heuristic when determining the maximum
409 size of memory-read and memory-write packets. A target will
410 typically only reserve a buffer large enough to hold the ``g''
411 packet. The size does not include packet overhead (headers and
413 long actual_register_packet_size
;
415 /* This is the maximum size (in chars) of a non read/write packet.
416 It is also used as a cap on the size of read/write packets. */
417 long remote_packet_size
;
420 long sizeof_pkt
= 2000;
422 /* Utility: generate error from an incoming stub packet. */
424 trace_error (char *buf
)
427 return; /* not an error msg */
430 case '1': /* malformed packet error */
431 if (*++buf
== '0') /* general case: */
432 error (_("remote.c: error in outgoing packet."));
434 error (_("remote.c: error in outgoing packet at field #%ld."),
435 strtol (buf
, NULL
, 16));
437 error (_("Target returns error code '%s'."), buf
);
441 /* Utility: wait for reply from stub, while accepting "O" packets. */
443 remote_get_noisy_reply (char **buf_p
,
446 do /* Loop on reply from remote stub. */
450 QUIT
; /* Allow user to bail out with ^C. */
451 getpkt (buf_p
, sizeof_buf
, 0);
455 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
458 CORE_ADDR from
, to
, org_to
;
460 int adjusted_size
= 0;
461 volatile struct gdb_exception ex
;
463 p
= buf
+ strlen ("qRelocInsn:");
464 pp
= unpack_varlen_hex (p
, &ul
);
466 error (_("invalid qRelocInsn packet: %s"), buf
);
470 unpack_varlen_hex (p
, &ul
);
475 TRY_CATCH (ex
, RETURN_MASK_ALL
)
477 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
481 adjusted_size
= to
- org_to
;
483 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
486 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
488 /* Propagate memory errors silently back to the target.
489 The stub may have limited the range of addresses we
490 can write to, for example. */
495 /* Something unexpectedly bad happened. Be verbose so
496 we can tell what, and propagate the error back to the
497 stub, so it doesn't get stuck waiting for a
499 exception_fprintf (gdb_stderr
, ex
,
500 _("warning: relocating instruction: "));
504 else if (buf
[0] == 'O' && buf
[1] != 'K')
505 remote_console_output (buf
+ 1); /* 'O' message from stub */
507 return buf
; /* Here's the actual reply. */
512 /* Handle for retreving the remote protocol data from gdbarch. */
513 static struct gdbarch_data
*remote_gdbarch_data_handle
;
515 static struct remote_arch_state
*
516 get_remote_arch_state (void)
518 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
521 /* Fetch the global remote target state. */
523 static struct remote_state
*
524 get_remote_state (void)
526 /* Make sure that the remote architecture state has been
527 initialized, because doing so might reallocate rs->buf. Any
528 function which calls getpkt also needs to be mindful of changes
529 to rs->buf, but this call limits the number of places which run
531 get_remote_arch_state ();
533 return get_remote_state_raw ();
537 compare_pnums (const void *lhs_
, const void *rhs_
)
539 const struct packet_reg
* const *lhs
= lhs_
;
540 const struct packet_reg
* const *rhs
= rhs_
;
542 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
544 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
551 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
553 int regnum
, num_remote_regs
, offset
;
554 struct packet_reg
**remote_regs
;
556 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
558 struct packet_reg
*r
= ®s
[regnum
];
560 if (register_size (gdbarch
, regnum
) == 0)
561 /* Do not try to fetch zero-sized (placeholder) registers. */
564 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
569 /* Define the g/G packet format as the contents of each register
570 with a remote protocol number, in order of ascending protocol
573 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
574 * sizeof (struct packet_reg
*));
575 for (num_remote_regs
= 0, regnum
= 0;
576 regnum
< gdbarch_num_regs (gdbarch
);
578 if (regs
[regnum
].pnum
!= -1)
579 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
581 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
584 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
586 remote_regs
[regnum
]->in_g_packet
= 1;
587 remote_regs
[regnum
]->offset
= offset
;
588 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
594 /* Given the architecture described by GDBARCH, return the remote
595 protocol register's number and the register's offset in the g/G
596 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
597 If the target does not have a mapping for REGNUM, return false,
598 otherwise, return true. */
601 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
602 int *pnum
, int *poffset
)
605 struct packet_reg
*regs
;
606 struct cleanup
*old_chain
;
608 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
610 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
611 old_chain
= make_cleanup (xfree
, regs
);
613 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
615 *pnum
= regs
[regnum
].pnum
;
616 *poffset
= regs
[regnum
].offset
;
618 do_cleanups (old_chain
);
624 init_remote_state (struct gdbarch
*gdbarch
)
626 struct remote_state
*rs
= get_remote_state_raw ();
627 struct remote_arch_state
*rsa
;
629 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
631 /* Use the architecture to build a regnum<->pnum table, which will be
632 1:1 unless a feature set specifies otherwise. */
633 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
634 gdbarch_num_regs (gdbarch
),
637 /* Record the maximum possible size of the g packet - it may turn out
639 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
641 /* Default maximum number of characters in a packet body. Many
642 remote stubs have a hardwired buffer size of 400 bytes
643 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
644 as the maximum packet-size to ensure that the packet and an extra
645 NUL character can always fit in the buffer. This stops GDB
646 trashing stubs that try to squeeze an extra NUL into what is
647 already a full buffer (As of 1999-12-04 that was most stubs). */
648 rsa
->remote_packet_size
= 400 - 1;
650 /* This one is filled in when a ``g'' packet is received. */
651 rsa
->actual_register_packet_size
= 0;
653 /* Should rsa->sizeof_g_packet needs more space than the
654 default, adjust the size accordingly. Remember that each byte is
655 encoded as two characters. 32 is the overhead for the packet
656 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
657 (``$NN:G...#NN'') is a better guess, the below has been padded a
659 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
660 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
662 /* Make sure that the packet buffer is plenty big enough for
663 this architecture. */
664 if (rs
->buf_size
< rsa
->remote_packet_size
)
666 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
667 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
673 /* Return the current allowed size of a remote packet. This is
674 inferred from the current architecture, and should be used to
675 limit the length of outgoing packets. */
677 get_remote_packet_size (void)
679 struct remote_state
*rs
= get_remote_state ();
680 struct remote_arch_state
*rsa
= get_remote_arch_state ();
682 if (rs
->explicit_packet_size
)
683 return rs
->explicit_packet_size
;
685 return rsa
->remote_packet_size
;
688 static struct packet_reg
*
689 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
691 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
695 struct packet_reg
*r
= &rsa
->regs
[regnum
];
697 gdb_assert (r
->regnum
== regnum
);
702 static struct packet_reg
*
703 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
707 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
709 struct packet_reg
*r
= &rsa
->regs
[i
];
717 /* FIXME: graces/2002-08-08: These variables should eventually be
718 bound to an instance of the target object (as in gdbarch-tdep()),
719 when such a thing exists. */
721 /* This is set to the data address of the access causing the target
722 to stop for a watchpoint. */
723 static CORE_ADDR remote_watch_data_address
;
725 /* This is non-zero if target stopped for a watchpoint. */
726 static int remote_stopped_by_watchpoint_p
;
728 static struct target_ops remote_ops
;
730 static struct target_ops extended_remote_ops
;
732 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
733 ``forever'' still use the normal timeout mechanism. This is
734 currently used by the ASYNC code to guarentee that target reads
735 during the initial connect always time-out. Once getpkt has been
736 modified to return a timeout indication and, in turn
737 remote_wait()/wait_for_inferior() have gained a timeout parameter
739 static int wait_forever_enabled_p
= 1;
741 /* Allow the user to specify what sequence to send to the remote
742 when he requests a program interruption: Although ^C is usually
743 what remote systems expect (this is the default, here), it is
744 sometimes preferable to send a break. On other systems such
745 as the Linux kernel, a break followed by g, which is Magic SysRq g
746 is required in order to interrupt the execution. */
747 const char interrupt_sequence_control_c
[] = "Ctrl-C";
748 const char interrupt_sequence_break
[] = "BREAK";
749 const char interrupt_sequence_break_g
[] = "BREAK-g";
750 static const char *const interrupt_sequence_modes
[] =
752 interrupt_sequence_control_c
,
753 interrupt_sequence_break
,
754 interrupt_sequence_break_g
,
757 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
760 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
761 struct cmd_list_element
*c
,
764 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
765 fprintf_filtered (file
,
766 _("Send the ASCII ETX character (Ctrl-c) "
767 "to the remote target to interrupt the "
768 "execution of the program.\n"));
769 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
770 fprintf_filtered (file
,
771 _("send a break signal to the remote target "
772 "to interrupt the execution of the program.\n"));
773 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
774 fprintf_filtered (file
,
775 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
776 "the remote target to interrupt the execution "
777 "of Linux kernel.\n"));
779 internal_error (__FILE__
, __LINE__
,
780 _("Invalid value for interrupt_sequence_mode: %s."),
781 interrupt_sequence_mode
);
784 /* This boolean variable specifies whether interrupt_sequence is sent
785 to the remote target when gdb connects to it.
786 This is mostly needed when you debug the Linux kernel: The Linux kernel
787 expects BREAK g which is Magic SysRq g for connecting gdb. */
788 static int interrupt_on_connect
= 0;
790 /* This variable is used to implement the "set/show remotebreak" commands.
791 Since these commands are now deprecated in favor of "set/show remote
792 interrupt-sequence", it no longer has any effect on the code. */
793 static int remote_break
;
796 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
799 interrupt_sequence_mode
= interrupt_sequence_break
;
801 interrupt_sequence_mode
= interrupt_sequence_control_c
;
805 show_remotebreak (struct ui_file
*file
, int from_tty
,
806 struct cmd_list_element
*c
,
811 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
812 remote_open knows that we don't have a file open when the program
814 static struct serial
*remote_desc
= NULL
;
816 /* This variable sets the number of bits in an address that are to be
817 sent in a memory ("M" or "m") packet. Normally, after stripping
818 leading zeros, the entire address would be sent. This variable
819 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
820 initial implementation of remote.c restricted the address sent in
821 memory packets to ``host::sizeof long'' bytes - (typically 32
822 bits). Consequently, for 64 bit targets, the upper 32 bits of an
823 address was never sent. Since fixing this bug may cause a break in
824 some remote targets this variable is principly provided to
825 facilitate backward compatibility. */
827 static unsigned int remote_address_size
;
829 /* Temporary to track who currently owns the terminal. See
830 remote_terminal_* for more details. */
832 static int remote_async_terminal_ours_p
;
834 /* The executable file to use for "run" on the remote side. */
836 static char *remote_exec_file
= "";
839 /* User configurable variables for the number of characters in a
840 memory read/write packet. MIN (rsa->remote_packet_size,
841 rsa->sizeof_g_packet) is the default. Some targets need smaller
842 values (fifo overruns, et.al.) and some users need larger values
843 (speed up transfers). The variables ``preferred_*'' (the user
844 request), ``current_*'' (what was actually set) and ``forced_*''
845 (Positive - a soft limit, negative - a hard limit). */
847 struct memory_packet_config
854 /* Compute the current size of a read/write packet. Since this makes
855 use of ``actual_register_packet_size'' the computation is dynamic. */
858 get_memory_packet_size (struct memory_packet_config
*config
)
860 struct remote_state
*rs
= get_remote_state ();
861 struct remote_arch_state
*rsa
= get_remote_arch_state ();
863 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
864 law?) that some hosts don't cope very well with large alloca()
865 calls. Eventually the alloca() code will be replaced by calls to
866 xmalloc() and make_cleanups() allowing this restriction to either
867 be lifted or removed. */
868 #ifndef MAX_REMOTE_PACKET_SIZE
869 #define MAX_REMOTE_PACKET_SIZE 16384
871 /* NOTE: 20 ensures we can write at least one byte. */
872 #ifndef MIN_REMOTE_PACKET_SIZE
873 #define MIN_REMOTE_PACKET_SIZE 20
878 if (config
->size
<= 0)
879 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
881 what_they_get
= config
->size
;
885 what_they_get
= get_remote_packet_size ();
886 /* Limit the packet to the size specified by the user. */
888 && what_they_get
> config
->size
)
889 what_they_get
= config
->size
;
891 /* Limit it to the size of the targets ``g'' response unless we have
892 permission from the stub to use a larger packet size. */
893 if (rs
->explicit_packet_size
== 0
894 && rsa
->actual_register_packet_size
> 0
895 && what_they_get
> rsa
->actual_register_packet_size
)
896 what_they_get
= rsa
->actual_register_packet_size
;
898 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
899 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
900 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
901 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
903 /* Make sure there is room in the global buffer for this packet
904 (including its trailing NUL byte). */
905 if (rs
->buf_size
< what_they_get
+ 1)
907 rs
->buf_size
= 2 * what_they_get
;
908 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
911 return what_they_get
;
914 /* Update the size of a read/write packet. If they user wants
915 something really big then do a sanity check. */
918 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
920 int fixed_p
= config
->fixed_p
;
921 long size
= config
->size
;
924 error (_("Argument required (integer, `fixed' or `limited')."));
925 else if (strcmp (args
, "hard") == 0
926 || strcmp (args
, "fixed") == 0)
928 else if (strcmp (args
, "soft") == 0
929 || strcmp (args
, "limit") == 0)
935 size
= strtoul (args
, &end
, 0);
937 error (_("Invalid %s (bad syntax)."), config
->name
);
939 /* Instead of explicitly capping the size of a packet to
940 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
941 instead allowed to set the size to something arbitrarily
943 if (size
> MAX_REMOTE_PACKET_SIZE
)
944 error (_("Invalid %s (too large)."), config
->name
);
948 if (fixed_p
&& !config
->fixed_p
)
950 if (! query (_("The target may not be able to correctly handle a %s\n"
951 "of %ld bytes. Change the packet size? "),
953 error (_("Packet size not changed."));
955 /* Update the config. */
956 config
->fixed_p
= fixed_p
;
961 show_memory_packet_size (struct memory_packet_config
*config
)
963 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
965 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
966 get_memory_packet_size (config
));
968 printf_filtered (_("Packets are limited to %ld bytes.\n"),
969 get_memory_packet_size (config
));
972 static struct memory_packet_config memory_write_packet_config
=
974 "memory-write-packet-size",
978 set_memory_write_packet_size (char *args
, int from_tty
)
980 set_memory_packet_size (args
, &memory_write_packet_config
);
984 show_memory_write_packet_size (char *args
, int from_tty
)
986 show_memory_packet_size (&memory_write_packet_config
);
990 get_memory_write_packet_size (void)
992 return get_memory_packet_size (&memory_write_packet_config
);
995 static struct memory_packet_config memory_read_packet_config
=
997 "memory-read-packet-size",
1001 set_memory_read_packet_size (char *args
, int from_tty
)
1003 set_memory_packet_size (args
, &memory_read_packet_config
);
1007 show_memory_read_packet_size (char *args
, int from_tty
)
1009 show_memory_packet_size (&memory_read_packet_config
);
1013 get_memory_read_packet_size (void)
1015 long size
= get_memory_packet_size (&memory_read_packet_config
);
1017 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1018 extra buffer size argument before the memory read size can be
1019 increased beyond this. */
1020 if (size
> get_remote_packet_size ())
1021 size
= get_remote_packet_size ();
1026 /* Generic configuration support for packets the stub optionally
1027 supports. Allows the user to specify the use of the packet as well
1028 as allowing GDB to auto-detect support in the remote stub. */
1032 PACKET_SUPPORT_UNKNOWN
= 0,
1037 struct packet_config
1041 enum auto_boolean detect
;
1042 enum packet_support support
;
1045 /* Analyze a packet's return value and update the packet config
1056 update_packet_config (struct packet_config
*config
)
1058 switch (config
->detect
)
1060 case AUTO_BOOLEAN_TRUE
:
1061 config
->support
= PACKET_ENABLE
;
1063 case AUTO_BOOLEAN_FALSE
:
1064 config
->support
= PACKET_DISABLE
;
1066 case AUTO_BOOLEAN_AUTO
:
1067 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1073 show_packet_config_cmd (struct packet_config
*config
)
1075 char *support
= "internal-error";
1077 switch (config
->support
)
1080 support
= "enabled";
1082 case PACKET_DISABLE
:
1083 support
= "disabled";
1085 case PACKET_SUPPORT_UNKNOWN
:
1086 support
= "unknown";
1089 switch (config
->detect
)
1091 case AUTO_BOOLEAN_AUTO
:
1092 printf_filtered (_("Support for the `%s' packet "
1093 "is auto-detected, currently %s.\n"),
1094 config
->name
, support
);
1096 case AUTO_BOOLEAN_TRUE
:
1097 case AUTO_BOOLEAN_FALSE
:
1098 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1099 config
->name
, support
);
1105 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1106 const char *title
, int legacy
)
1112 config
->name
= name
;
1113 config
->title
= title
;
1114 config
->detect
= AUTO_BOOLEAN_AUTO
;
1115 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1116 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1118 show_doc
= xstrprintf ("Show current use of remote "
1119 "protocol `%s' (%s) packet",
1121 /* set/show TITLE-packet {auto,on,off} */
1122 cmd_name
= xstrprintf ("%s-packet", title
);
1123 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1124 &config
->detect
, set_doc
,
1125 show_doc
, NULL
, /* help_doc */
1126 set_remote_protocol_packet_cmd
,
1127 show_remote_protocol_packet_cmd
,
1128 &remote_set_cmdlist
, &remote_show_cmdlist
);
1129 /* The command code copies the documentation strings. */
1132 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1137 legacy_name
= xstrprintf ("%s-packet", name
);
1138 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1139 &remote_set_cmdlist
);
1140 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1141 &remote_show_cmdlist
);
1145 static enum packet_result
1146 packet_check_result (const char *buf
)
1150 /* The stub recognized the packet request. Check that the
1151 operation succeeded. */
1153 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1155 /* "Enn" - definitly an error. */
1156 return PACKET_ERROR
;
1158 /* Always treat "E." as an error. This will be used for
1159 more verbose error messages, such as E.memtypes. */
1160 if (buf
[0] == 'E' && buf
[1] == '.')
1161 return PACKET_ERROR
;
1163 /* The packet may or may not be OK. Just assume it is. */
1167 /* The stub does not support the packet. */
1168 return PACKET_UNKNOWN
;
1171 static enum packet_result
1172 packet_ok (const char *buf
, struct packet_config
*config
)
1174 enum packet_result result
;
1176 result
= packet_check_result (buf
);
1181 /* The stub recognized the packet request. */
1182 switch (config
->support
)
1184 case PACKET_SUPPORT_UNKNOWN
:
1186 fprintf_unfiltered (gdb_stdlog
,
1187 "Packet %s (%s) is supported\n",
1188 config
->name
, config
->title
);
1189 config
->support
= PACKET_ENABLE
;
1191 case PACKET_DISABLE
:
1192 internal_error (__FILE__
, __LINE__
,
1193 _("packet_ok: attempt to use a disabled packet"));
1199 case PACKET_UNKNOWN
:
1200 /* The stub does not support the packet. */
1201 switch (config
->support
)
1204 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1205 /* If the stub previously indicated that the packet was
1206 supported then there is a protocol error.. */
1207 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1208 config
->name
, config
->title
);
1210 /* The user set it wrong. */
1211 error (_("Enabled packet %s (%s) not recognized by stub"),
1212 config
->name
, config
->title
);
1214 case PACKET_SUPPORT_UNKNOWN
:
1216 fprintf_unfiltered (gdb_stdlog
,
1217 "Packet %s (%s) is NOT supported\n",
1218 config
->name
, config
->title
);
1219 config
->support
= PACKET_DISABLE
;
1221 case PACKET_DISABLE
:
1243 PACKET_vFile_pwrite
,
1245 PACKET_vFile_unlink
,
1246 PACKET_vFile_readlink
,
1248 PACKET_qXfer_features
,
1249 PACKET_qXfer_libraries
,
1250 PACKET_qXfer_libraries_svr4
,
1251 PACKET_qXfer_memory_map
,
1252 PACKET_qXfer_spu_read
,
1253 PACKET_qXfer_spu_write
,
1254 PACKET_qXfer_osdata
,
1255 PACKET_qXfer_threads
,
1256 PACKET_qXfer_statictrace_read
,
1257 PACKET_qXfer_traceframe_info
,
1263 PACKET_QPassSignals
,
1264 PACKET_QProgramSignals
,
1265 PACKET_qSearch_memory
,
1268 PACKET_QStartNoAckMode
,
1270 PACKET_qXfer_siginfo_read
,
1271 PACKET_qXfer_siginfo_write
,
1273 PACKET_ConditionalTracepoints
,
1274 PACKET_ConditionalBreakpoints
,
1275 PACKET_BreakpointCommands
,
1276 PACKET_FastTracepoints
,
1277 PACKET_StaticTracepoints
,
1278 PACKET_InstallInTrace
,
1281 PACKET_TracepointSource
,
1284 PACKET_QDisableRandomization
,
1286 PACKET_QTBuffer_size
,
1289 PACKET_qXfer_btrace
,
1293 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1296 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1297 struct cmd_list_element
*c
)
1299 struct packet_config
*packet
;
1301 for (packet
= remote_protocol_packets
;
1302 packet
< &remote_protocol_packets
[PACKET_MAX
];
1305 if (&packet
->detect
== c
->var
)
1307 update_packet_config (packet
);
1311 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1316 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1317 struct cmd_list_element
*c
,
1320 struct packet_config
*packet
;
1322 for (packet
= remote_protocol_packets
;
1323 packet
< &remote_protocol_packets
[PACKET_MAX
];
1326 if (&packet
->detect
== c
->var
)
1328 show_packet_config_cmd (packet
);
1332 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1336 /* Should we try one of the 'Z' requests? */
1340 Z_PACKET_SOFTWARE_BP
,
1341 Z_PACKET_HARDWARE_BP
,
1348 /* For compatibility with older distributions. Provide a ``set remote
1349 Z-packet ...'' command that updates all the Z packet types. */
1351 static enum auto_boolean remote_Z_packet_detect
;
1354 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1355 struct cmd_list_element
*c
)
1359 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1361 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1362 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1367 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1368 struct cmd_list_element
*c
,
1373 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1375 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1379 /* Should we try the 'ThreadInfo' query packet?
1381 This variable (NOT available to the user: auto-detect only!)
1382 determines whether GDB will use the new, simpler "ThreadInfo"
1383 query or the older, more complex syntax for thread queries.
1384 This is an auto-detect variable (set to true at each connect,
1385 and set to false when the target fails to recognize it). */
1387 static int use_threadinfo_query
;
1388 static int use_threadextra_query
;
1390 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1391 static struct async_signal_handler
*sigint_remote_twice_token
;
1392 static struct async_signal_handler
*sigint_remote_token
;
1395 /* Asynchronous signal handle registered as event loop source for
1396 when we have pending events ready to be passed to the core. */
1398 static struct async_event_handler
*remote_async_inferior_event_token
;
1402 static ptid_t magic_null_ptid
;
1403 static ptid_t not_sent_ptid
;
1404 static ptid_t any_thread_ptid
;
1406 /* These are the threads which we last sent to the remote system. The
1407 TID member will be -1 for all or -2 for not sent yet. */
1409 static ptid_t general_thread
;
1410 static ptid_t continue_thread
;
1412 /* This is the traceframe which we last selected on the remote system.
1413 It will be -1 if no traceframe is selected. */
1414 static int remote_traceframe_number
= -1;
1416 /* Find out if the stub attached to PID (and hence GDB should offer to
1417 detach instead of killing it when bailing out). */
1420 remote_query_attached (int pid
)
1422 struct remote_state
*rs
= get_remote_state ();
1423 size_t size
= get_remote_packet_size ();
1425 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1428 if (remote_multi_process_p (rs
))
1429 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1431 xsnprintf (rs
->buf
, size
, "qAttached");
1434 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1436 switch (packet_ok (rs
->buf
,
1437 &remote_protocol_packets
[PACKET_qAttached
]))
1440 if (strcmp (rs
->buf
, "1") == 0)
1444 warning (_("Remote failure reply: %s"), rs
->buf
);
1446 case PACKET_UNKNOWN
:
1453 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1454 has been invented by GDB, instead of reported by the target. Since
1455 we can be connected to a remote system before before knowing about
1456 any inferior, mark the target with execution when we find the first
1457 inferior. If ATTACHED is 1, then we had just attached to this
1458 inferior. If it is 0, then we just created this inferior. If it
1459 is -1, then try querying the remote stub to find out if it had
1460 attached to the inferior or not. */
1462 static struct inferior
*
1463 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1465 struct inferior
*inf
;
1467 /* Check whether this process we're learning about is to be
1468 considered attached, or if is to be considered to have been
1469 spawned by the stub. */
1471 attached
= remote_query_attached (pid
);
1473 if (gdbarch_has_global_solist (target_gdbarch ()))
1475 /* If the target shares code across all inferiors, then every
1476 attach adds a new inferior. */
1477 inf
= add_inferior (pid
);
1479 /* ... and every inferior is bound to the same program space.
1480 However, each inferior may still have its own address
1482 inf
->aspace
= maybe_new_address_space ();
1483 inf
->pspace
= current_program_space
;
1487 /* In the traditional debugging scenario, there's a 1-1 match
1488 between program/address spaces. We simply bind the inferior
1489 to the program space's address space. */
1490 inf
= current_inferior ();
1491 inferior_appeared (inf
, pid
);
1494 inf
->attach_flag
= attached
;
1495 inf
->fake_pid_p
= fake_pid_p
;
1500 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1501 according to RUNNING. */
1504 remote_add_thread (ptid_t ptid
, int running
)
1508 set_executing (ptid
, running
);
1509 set_running (ptid
, running
);
1512 /* Come here when we learn about a thread id from the remote target.
1513 It may be the first time we hear about such thread, so take the
1514 opportunity to add it to GDB's thread list. In case this is the
1515 first time we're noticing its corresponding inferior, add it to
1516 GDB's inferior list as well. */
1519 remote_notice_new_inferior (ptid_t currthread
, int running
)
1521 /* If this is a new thread, add it to GDB's thread list.
1522 If we leave it up to WFI to do this, bad things will happen. */
1524 if (in_thread_list (currthread
) && is_exited (currthread
))
1526 /* We're seeing an event on a thread id we knew had exited.
1527 This has to be a new thread reusing the old id. Add it. */
1528 remote_add_thread (currthread
, running
);
1532 if (!in_thread_list (currthread
))
1534 struct inferior
*inf
= NULL
;
1535 int pid
= ptid_get_pid (currthread
);
1537 if (ptid_is_pid (inferior_ptid
)
1538 && pid
== ptid_get_pid (inferior_ptid
))
1540 /* inferior_ptid has no thread member yet. This can happen
1541 with the vAttach -> remote_wait,"TAAthread:" path if the
1542 stub doesn't support qC. This is the first stop reported
1543 after an attach, so this is the main thread. Update the
1544 ptid in the thread list. */
1545 if (in_thread_list (pid_to_ptid (pid
)))
1546 thread_change_ptid (inferior_ptid
, currthread
);
1549 remote_add_thread (currthread
, running
);
1550 inferior_ptid
= currthread
;
1555 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1557 /* inferior_ptid is not set yet. This can happen with the
1558 vRun -> remote_wait,"TAAthread:" path if the stub
1559 doesn't support qC. This is the first stop reported
1560 after an attach, so this is the main thread. Update the
1561 ptid in the thread list. */
1562 thread_change_ptid (inferior_ptid
, currthread
);
1566 /* When connecting to a target remote, or to a target
1567 extended-remote which already was debugging an inferior, we
1568 may not know about it yet. Add it before adding its child
1569 thread, so notifications are emitted in a sensible order. */
1570 if (!in_inferior_list (ptid_get_pid (currthread
)))
1572 struct remote_state
*rs
= get_remote_state ();
1573 int fake_pid_p
= !remote_multi_process_p (rs
);
1575 inf
= remote_add_inferior (fake_pid_p
,
1576 ptid_get_pid (currthread
), -1);
1579 /* This is really a new thread. Add it. */
1580 remote_add_thread (currthread
, running
);
1582 /* If we found a new inferior, let the common code do whatever
1583 it needs to with it (e.g., read shared libraries, insert
1586 notice_new_inferior (currthread
, running
, 0);
1590 /* Return the private thread data, creating it if necessary. */
1592 static struct private_thread_info
*
1593 demand_private_info (ptid_t ptid
)
1595 struct thread_info
*info
= find_thread_ptid (ptid
);
1601 info
->private = xmalloc (sizeof (*(info
->private)));
1602 info
->private_dtor
= free_private_thread_info
;
1603 info
->private->core
= -1;
1604 info
->private->extra
= 0;
1607 return info
->private;
1610 /* Call this function as a result of
1611 1) A halt indication (T packet) containing a thread id
1612 2) A direct query of currthread
1613 3) Successful execution of set thread */
1616 record_currthread (ptid_t currthread
)
1618 general_thread
= currthread
;
1621 static char *last_pass_packet
;
1623 /* If 'QPassSignals' is supported, tell the remote stub what signals
1624 it can simply pass through to the inferior without reporting. */
1627 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1629 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1631 char *pass_packet
, *p
;
1634 gdb_assert (numsigs
< 256);
1635 for (i
= 0; i
< numsigs
; i
++)
1637 if (pass_signals
[i
])
1640 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1641 strcpy (pass_packet
, "QPassSignals:");
1642 p
= pass_packet
+ strlen (pass_packet
);
1643 for (i
= 0; i
< numsigs
; i
++)
1645 if (pass_signals
[i
])
1648 *p
++ = tohex (i
>> 4);
1649 *p
++ = tohex (i
& 15);
1658 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1660 struct remote_state
*rs
= get_remote_state ();
1661 char *buf
= rs
->buf
;
1663 putpkt (pass_packet
);
1664 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1665 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1666 if (last_pass_packet
)
1667 xfree (last_pass_packet
);
1668 last_pass_packet
= pass_packet
;
1671 xfree (pass_packet
);
1675 /* The last QProgramSignals packet sent to the target. We bypass
1676 sending a new program signals list down to the target if the new
1677 packet is exactly the same as the last we sent. IOW, we only let
1678 the target know about program signals list changes. */
1680 static char *last_program_signals_packet
;
1682 /* If 'QProgramSignals' is supported, tell the remote stub what
1683 signals it should pass through to the inferior when detaching. */
1686 remote_program_signals (int numsigs
, unsigned char *signals
)
1688 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1693 gdb_assert (numsigs
< 256);
1694 for (i
= 0; i
< numsigs
; i
++)
1699 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1700 strcpy (packet
, "QProgramSignals:");
1701 p
= packet
+ strlen (packet
);
1702 for (i
= 0; i
< numsigs
; i
++)
1704 if (signal_pass_state (i
))
1707 *p
++ = tohex (i
>> 4);
1708 *p
++ = tohex (i
& 15);
1717 if (!last_program_signals_packet
1718 || strcmp (last_program_signals_packet
, packet
) != 0)
1720 struct remote_state
*rs
= get_remote_state ();
1721 char *buf
= rs
->buf
;
1724 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1725 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1726 xfree (last_program_signals_packet
);
1727 last_program_signals_packet
= packet
;
1734 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1735 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1736 thread. If GEN is set, set the general thread, if not, then set
1737 the step/continue thread. */
1739 set_thread (struct ptid ptid
, int gen
)
1741 struct remote_state
*rs
= get_remote_state ();
1742 ptid_t state
= gen
? general_thread
: continue_thread
;
1743 char *buf
= rs
->buf
;
1744 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1746 if (ptid_equal (state
, ptid
))
1750 *buf
++ = gen
? 'g' : 'c';
1751 if (ptid_equal (ptid
, magic_null_ptid
))
1752 xsnprintf (buf
, endbuf
- buf
, "0");
1753 else if (ptid_equal (ptid
, any_thread_ptid
))
1754 xsnprintf (buf
, endbuf
- buf
, "0");
1755 else if (ptid_equal (ptid
, minus_one_ptid
))
1756 xsnprintf (buf
, endbuf
- buf
, "-1");
1758 write_ptid (buf
, endbuf
, ptid
);
1760 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1762 general_thread
= ptid
;
1764 continue_thread
= ptid
;
1768 set_general_thread (struct ptid ptid
)
1770 set_thread (ptid
, 1);
1774 set_continue_thread (struct ptid ptid
)
1776 set_thread (ptid
, 0);
1779 /* Change the remote current process. Which thread within the process
1780 ends up selected isn't important, as long as it is the same process
1781 as what INFERIOR_PTID points to.
1783 This comes from that fact that there is no explicit notion of
1784 "selected process" in the protocol. The selected process for
1785 general operations is the process the selected general thread
1789 set_general_process (void)
1791 struct remote_state
*rs
= get_remote_state ();
1793 /* If the remote can't handle multiple processes, don't bother. */
1794 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1797 /* We only need to change the remote current thread if it's pointing
1798 at some other process. */
1799 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1800 set_general_thread (inferior_ptid
);
1804 /* Return nonzero if the thread PTID is still alive on the remote
1808 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1810 struct remote_state
*rs
= get_remote_state ();
1813 if (ptid_equal (ptid
, magic_null_ptid
))
1814 /* The main thread is always alive. */
1817 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1818 /* The main thread is always alive. This can happen after a
1819 vAttach, if the remote side doesn't support
1824 endp
= rs
->buf
+ get_remote_packet_size ();
1827 write_ptid (p
, endp
, ptid
);
1830 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1831 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1834 /* About these extended threadlist and threadinfo packets. They are
1835 variable length packets but, the fields within them are often fixed
1836 length. They are redundent enough to send over UDP as is the
1837 remote protocol in general. There is a matching unit test module
1840 #define OPAQUETHREADBYTES 8
1842 /* a 64 bit opaque identifier */
1843 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1845 /* WARNING: This threadref data structure comes from the remote O.S.,
1846 libstub protocol encoding, and remote.c. It is not particularly
1849 /* Right now, the internal structure is int. We want it to be bigger.
1850 Plan to fix this. */
1852 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1854 /* gdb_ext_thread_info is an internal GDB data structure which is
1855 equivalent to the reply of the remote threadinfo packet. */
1857 struct gdb_ext_thread_info
1859 threadref threadid
; /* External form of thread reference. */
1860 int active
; /* Has state interesting to GDB?
1862 char display
[256]; /* Brief state display, name,
1863 blocked/suspended. */
1864 char shortname
[32]; /* To be used to name threads. */
1865 char more_display
[256]; /* Long info, statistics, queue depth,
1869 /* The volume of remote transfers can be limited by submitting
1870 a mask containing bits specifying the desired information.
1871 Use a union of these values as the 'selection' parameter to
1872 get_thread_info. FIXME: Make these TAG names more thread specific. */
1874 #define TAG_THREADID 1
1875 #define TAG_EXISTS 2
1876 #define TAG_DISPLAY 4
1877 #define TAG_THREADNAME 8
1878 #define TAG_MOREDISPLAY 16
1880 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1882 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1884 static char *unpack_nibble (char *buf
, int *val
);
1886 static char *pack_nibble (char *buf
, int nibble
);
1888 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1890 static char *unpack_byte (char *buf
, int *value
);
1892 static char *pack_int (char *buf
, int value
);
1894 static char *unpack_int (char *buf
, int *value
);
1896 static char *unpack_string (char *src
, char *dest
, int length
);
1898 static char *pack_threadid (char *pkt
, threadref
*id
);
1900 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1902 void int_to_threadref (threadref
*id
, int value
);
1904 static int threadref_to_int (threadref
*ref
);
1906 static void copy_threadref (threadref
*dest
, threadref
*src
);
1908 static int threadmatch (threadref
*dest
, threadref
*src
);
1910 static char *pack_threadinfo_request (char *pkt
, int mode
,
1913 static int remote_unpack_thread_info_response (char *pkt
,
1914 threadref
*expectedref
,
1915 struct gdb_ext_thread_info
1919 static int remote_get_threadinfo (threadref
*threadid
,
1920 int fieldset
, /*TAG mask */
1921 struct gdb_ext_thread_info
*info
);
1923 static char *pack_threadlist_request (char *pkt
, int startflag
,
1925 threadref
*nextthread
);
1927 static int parse_threadlist_response (char *pkt
,
1929 threadref
*original_echo
,
1930 threadref
*resultlist
,
1933 static int remote_get_threadlist (int startflag
,
1934 threadref
*nextthread
,
1938 threadref
*threadlist
);
1940 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1942 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1943 void *context
, int looplimit
);
1945 static int remote_newthread_step (threadref
*ref
, void *context
);
1948 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1949 buffer we're allowed to write to. Returns
1950 BUF+CHARACTERS_WRITTEN. */
1953 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1956 struct remote_state
*rs
= get_remote_state ();
1958 if (remote_multi_process_p (rs
))
1960 pid
= ptid_get_pid (ptid
);
1962 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1964 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1966 tid
= ptid_get_tid (ptid
);
1968 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1970 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1975 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1976 passed the last parsed char. Returns null_ptid on error. */
1979 read_ptid (char *buf
, char **obuf
)
1983 ULONGEST pid
= 0, tid
= 0;
1987 /* Multi-process ptid. */
1988 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1990 error (_("invalid remote ptid: %s"), p
);
1993 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1996 return ptid_build (pid
, 0, tid
);
1999 /* No multi-process. Just a tid. */
2000 pp
= unpack_varlen_hex (p
, &tid
);
2002 /* Since the stub is not sending a process id, then default to
2003 what's in inferior_ptid, unless it's null at this point. If so,
2004 then since there's no way to know the pid of the reported
2005 threads, use the magic number. */
2006 if (ptid_equal (inferior_ptid
, null_ptid
))
2007 pid
= ptid_get_pid (magic_null_ptid
);
2009 pid
= ptid_get_pid (inferior_ptid
);
2013 return ptid_build (pid
, 0, tid
);
2016 /* Encode 64 bits in 16 chars of hex. */
2018 static const char hexchars
[] = "0123456789abcdef";
2021 ishex (int ch
, int *val
)
2023 if ((ch
>= 'a') && (ch
<= 'f'))
2025 *val
= ch
- 'a' + 10;
2028 if ((ch
>= 'A') && (ch
<= 'F'))
2030 *val
= ch
- 'A' + 10;
2033 if ((ch
>= '0') && (ch
<= '9'))
2044 if (ch
>= 'a' && ch
<= 'f')
2045 return ch
- 'a' + 10;
2046 if (ch
>= '0' && ch
<= '9')
2048 if (ch
>= 'A' && ch
<= 'F')
2049 return ch
- 'A' + 10;
2054 stub_unpack_int (char *buff
, int fieldlength
)
2061 nibble
= stubhex (*buff
++);
2065 retval
= retval
<< 4;
2071 unpack_varlen_hex (char *buff
, /* packet to parse */
2075 ULONGEST retval
= 0;
2077 while (ishex (*buff
, &nibble
))
2080 retval
= retval
<< 4;
2081 retval
|= nibble
& 0x0f;
2088 unpack_nibble (char *buf
, int *val
)
2090 *val
= fromhex (*buf
++);
2095 pack_nibble (char *buf
, int nibble
)
2097 *buf
++ = hexchars
[(nibble
& 0x0f)];
2102 pack_hex_byte (char *pkt
, int byte
)
2104 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2105 *pkt
++ = hexchars
[(byte
& 0xf)];
2110 unpack_byte (char *buf
, int *value
)
2112 *value
= stub_unpack_int (buf
, 2);
2117 pack_int (char *buf
, int value
)
2119 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2120 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2121 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2122 buf
= pack_hex_byte (buf
, (value
& 0xff));
2127 unpack_int (char *buf
, int *value
)
2129 *value
= stub_unpack_int (buf
, 8);
2133 #if 0 /* Currently unused, uncomment when needed. */
2134 static char *pack_string (char *pkt
, char *string
);
2137 pack_string (char *pkt
, char *string
)
2142 len
= strlen (string
);
2144 len
= 200; /* Bigger than most GDB packets, junk??? */
2145 pkt
= pack_hex_byte (pkt
, len
);
2149 if ((ch
== '\0') || (ch
== '#'))
2150 ch
= '*'; /* Protect encapsulation. */
2155 #endif /* 0 (unused) */
2158 unpack_string (char *src
, char *dest
, int length
)
2167 pack_threadid (char *pkt
, threadref
*id
)
2170 unsigned char *altid
;
2172 altid
= (unsigned char *) id
;
2173 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2175 pkt
= pack_hex_byte (pkt
, *altid
++);
2181 unpack_threadid (char *inbuf
, threadref
*id
)
2184 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2187 altref
= (char *) id
;
2189 while (inbuf
< limit
)
2191 x
= stubhex (*inbuf
++);
2192 y
= stubhex (*inbuf
++);
2193 *altref
++ = (x
<< 4) | y
;
2198 /* Externally, threadrefs are 64 bits but internally, they are still
2199 ints. This is due to a mismatch of specifications. We would like
2200 to use 64bit thread references internally. This is an adapter
2204 int_to_threadref (threadref
*id
, int value
)
2206 unsigned char *scan
;
2208 scan
= (unsigned char *) id
;
2214 *scan
++ = (value
>> 24) & 0xff;
2215 *scan
++ = (value
>> 16) & 0xff;
2216 *scan
++ = (value
>> 8) & 0xff;
2217 *scan
++ = (value
& 0xff);
2221 threadref_to_int (threadref
*ref
)
2224 unsigned char *scan
;
2230 value
= (value
<< 8) | ((*scan
++) & 0xff);
2235 copy_threadref (threadref
*dest
, threadref
*src
)
2238 unsigned char *csrc
, *cdest
;
2240 csrc
= (unsigned char *) src
;
2241 cdest
= (unsigned char *) dest
;
2248 threadmatch (threadref
*dest
, threadref
*src
)
2250 /* Things are broken right now, so just assume we got a match. */
2252 unsigned char *srcp
, *destp
;
2254 srcp
= (char *) src
;
2255 destp
= (char *) dest
;
2259 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2266 threadid:1, # always request threadid
2273 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2276 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2278 *pkt
++ = 'q'; /* Info Query */
2279 *pkt
++ = 'P'; /* process or thread info */
2280 pkt
= pack_int (pkt
, mode
); /* mode */
2281 pkt
= pack_threadid (pkt
, id
); /* threadid */
2282 *pkt
= '\0'; /* terminate */
2286 /* These values tag the fields in a thread info response packet. */
2287 /* Tagging the fields allows us to request specific fields and to
2288 add more fields as time goes by. */
2290 #define TAG_THREADID 1 /* Echo the thread identifier. */
2291 #define TAG_EXISTS 2 /* Is this process defined enough to
2292 fetch registers and its stack? */
2293 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2294 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2295 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2299 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2300 struct gdb_ext_thread_info
*info
)
2302 struct remote_state
*rs
= get_remote_state ();
2306 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2309 /* info->threadid = 0; FIXME: implement zero_threadref. */
2311 info
->display
[0] = '\0';
2312 info
->shortname
[0] = '\0';
2313 info
->more_display
[0] = '\0';
2315 /* Assume the characters indicating the packet type have been
2317 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2318 pkt
= unpack_threadid (pkt
, &ref
);
2321 warning (_("Incomplete response to threadinfo request."));
2322 if (!threadmatch (&ref
, expectedref
))
2323 { /* This is an answer to a different request. */
2324 warning (_("ERROR RMT Thread info mismatch."));
2327 copy_threadref (&info
->threadid
, &ref
);
2329 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2331 /* Packets are terminated with nulls. */
2332 while ((pkt
< limit
) && mask
&& *pkt
)
2334 pkt
= unpack_int (pkt
, &tag
); /* tag */
2335 pkt
= unpack_byte (pkt
, &length
); /* length */
2336 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2338 warning (_("ERROR RMT: threadinfo tag mismatch."));
2342 if (tag
== TAG_THREADID
)
2346 warning (_("ERROR RMT: length of threadid is not 16."));
2350 pkt
= unpack_threadid (pkt
, &ref
);
2351 mask
= mask
& ~TAG_THREADID
;
2354 if (tag
== TAG_EXISTS
)
2356 info
->active
= stub_unpack_int (pkt
, length
);
2358 mask
= mask
& ~(TAG_EXISTS
);
2361 warning (_("ERROR RMT: 'exists' length too long."));
2367 if (tag
== TAG_THREADNAME
)
2369 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2370 mask
= mask
& ~TAG_THREADNAME
;
2373 if (tag
== TAG_DISPLAY
)
2375 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2376 mask
= mask
& ~TAG_DISPLAY
;
2379 if (tag
== TAG_MOREDISPLAY
)
2381 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2382 mask
= mask
& ~TAG_MOREDISPLAY
;
2385 warning (_("ERROR RMT: unknown thread info tag."));
2386 break; /* Not a tag we know about. */
2392 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2393 struct gdb_ext_thread_info
*info
)
2395 struct remote_state
*rs
= get_remote_state ();
2398 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2400 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2402 if (rs
->buf
[0] == '\0')
2405 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2410 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2413 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2414 threadref
*nextthread
)
2416 *pkt
++ = 'q'; /* info query packet */
2417 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2418 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2419 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2420 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2425 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2428 parse_threadlist_response (char *pkt
, int result_limit
,
2429 threadref
*original_echo
, threadref
*resultlist
,
2432 struct remote_state
*rs
= get_remote_state ();
2434 int count
, resultcount
, done
;
2437 /* Assume the 'q' and 'M chars have been stripped. */
2438 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2439 /* done parse past here */
2440 pkt
= unpack_byte (pkt
, &count
); /* count field */
2441 pkt
= unpack_nibble (pkt
, &done
);
2442 /* The first threadid is the argument threadid. */
2443 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2444 while ((count
-- > 0) && (pkt
< limit
))
2446 pkt
= unpack_threadid (pkt
, resultlist
++);
2447 if (resultcount
++ >= result_limit
)
2456 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2457 int *done
, int *result_count
, threadref
*threadlist
)
2459 struct remote_state
*rs
= get_remote_state ();
2460 static threadref echo_nextthread
;
2463 /* Trancate result limit to be smaller than the packet size. */
2464 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2465 >= get_remote_packet_size ())
2466 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2468 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2470 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2472 if (*rs
->buf
== '\0')
2476 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2479 if (!threadmatch (&echo_nextthread
, nextthread
))
2481 /* FIXME: This is a good reason to drop the packet. */
2482 /* Possably, there is a duplicate response. */
2484 retransmit immediatly - race conditions
2485 retransmit after timeout - yes
2487 wait for packet, then exit
2489 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2490 return 0; /* I choose simply exiting. */
2492 if (*result_count
<= 0)
2496 warning (_("RMT ERROR : failed to get remote thread list."));
2499 return result
; /* break; */
2501 if (*result_count
> result_limit
)
2504 warning (_("RMT ERROR: threadlist response longer than requested."));
2510 /* This is the interface between remote and threads, remotes upper
2513 /* remote_find_new_threads retrieves the thread list and for each
2514 thread in the list, looks up the thread in GDB's internal list,
2515 adding the thread if it does not already exist. This involves
2516 getting partial thread lists from the remote target so, polling the
2517 quit_flag is required. */
2520 /* About this many threadisds fit in a packet. */
2522 #define MAXTHREADLISTRESULTS 32
2525 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2528 int done
, i
, result_count
;
2532 static threadref nextthread
;
2533 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2538 if (loopcount
++ > looplimit
)
2541 warning (_("Remote fetch threadlist -infinite loop-."));
2544 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2545 &done
, &result_count
, resultthreadlist
))
2550 /* Clear for later iterations. */
2552 /* Setup to resume next batch of thread references, set nextthread. */
2553 if (result_count
>= 1)
2554 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2556 while (result_count
--)
2557 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2564 remote_newthread_step (threadref
*ref
, void *context
)
2566 int pid
= ptid_get_pid (inferior_ptid
);
2567 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2569 if (!in_thread_list (ptid
))
2571 return 1; /* continue iterator */
2574 #define CRAZY_MAX_THREADS 1000
2577 remote_current_thread (ptid_t oldpid
)
2579 struct remote_state
*rs
= get_remote_state ();
2582 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2583 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2584 return read_ptid (&rs
->buf
[2], NULL
);
2589 /* Find new threads for info threads command.
2590 * Original version, using John Metzler's thread protocol.
2594 remote_find_new_threads (void)
2596 remote_threadlist_iterator (remote_newthread_step
, 0,
2600 #if defined(HAVE_LIBEXPAT)
2602 typedef struct thread_item
2608 DEF_VEC_O(thread_item_t
);
2610 struct threads_parsing_context
2612 VEC (thread_item_t
) *items
;
2616 start_thread (struct gdb_xml_parser
*parser
,
2617 const struct gdb_xml_element
*element
,
2618 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2620 struct threads_parsing_context
*data
= user_data
;
2622 struct thread_item item
;
2624 struct gdb_xml_value
*attr
;
2626 id
= xml_find_attribute (attributes
, "id")->value
;
2627 item
.ptid
= read_ptid (id
, NULL
);
2629 attr
= xml_find_attribute (attributes
, "core");
2631 item
.core
= *(ULONGEST
*) attr
->value
;
2637 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2641 end_thread (struct gdb_xml_parser
*parser
,
2642 const struct gdb_xml_element
*element
,
2643 void *user_data
, const char *body_text
)
2645 struct threads_parsing_context
*data
= user_data
;
2647 if (body_text
&& *body_text
)
2648 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2651 const struct gdb_xml_attribute thread_attributes
[] = {
2652 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2653 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2654 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2657 const struct gdb_xml_element thread_children
[] = {
2658 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2661 const struct gdb_xml_element threads_children
[] = {
2662 { "thread", thread_attributes
, thread_children
,
2663 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2664 start_thread
, end_thread
},
2665 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2668 const struct gdb_xml_element threads_elements
[] = {
2669 { "threads", NULL
, threads_children
,
2670 GDB_XML_EF_NONE
, NULL
, NULL
},
2671 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2674 /* Discard the contents of the constructed thread info context. */
2677 clear_threads_parsing_context (void *p
)
2679 struct threads_parsing_context
*context
= p
;
2681 struct thread_item
*item
;
2683 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2684 xfree (item
->extra
);
2686 VEC_free (thread_item_t
, context
->items
);
2692 * Find all threads for info threads command.
2693 * Uses new thread protocol contributed by Cisco.
2694 * Falls back and attempts to use the older method (above)
2695 * if the target doesn't respond to the new method.
2699 remote_threads_info (struct target_ops
*ops
)
2701 struct remote_state
*rs
= get_remote_state ();
2705 if (remote_desc
== 0) /* paranoia */
2706 error (_("Command can only be used when connected to the remote target."));
2708 #if defined(HAVE_LIBEXPAT)
2709 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2711 char *xml
= target_read_stralloc (¤t_target
,
2712 TARGET_OBJECT_THREADS
, NULL
);
2714 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2718 struct threads_parsing_context context
;
2720 context
.items
= NULL
;
2721 make_cleanup (clear_threads_parsing_context
, &context
);
2723 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2724 threads_elements
, xml
, &context
) == 0)
2727 struct thread_item
*item
;
2730 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2733 if (!ptid_equal (item
->ptid
, null_ptid
))
2735 struct private_thread_info
*info
;
2736 /* In non-stop mode, we assume new found threads
2737 are running until proven otherwise with a
2738 stop reply. In all-stop, we can only get
2739 here if all threads are stopped. */
2740 int running
= non_stop
? 1 : 0;
2742 remote_notice_new_inferior (item
->ptid
, running
);
2744 info
= demand_private_info (item
->ptid
);
2745 info
->core
= item
->core
;
2746 info
->extra
= item
->extra
;
2753 do_cleanups (back_to
);
2758 if (use_threadinfo_query
)
2760 putpkt ("qfThreadInfo");
2761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2763 if (bufp
[0] != '\0') /* q packet recognized */
2765 struct cleanup
*old_chain
;
2768 /* remote_notice_new_inferior (in the loop below) may make
2769 new RSP calls, which clobber rs->buf. Work with a
2771 bufp
= saved_reply
= xstrdup (rs
->buf
);
2772 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2774 while (*bufp
++ == 'm') /* reply contains one or more TID */
2778 new_thread
= read_ptid (bufp
, &bufp
);
2779 if (!ptid_equal (new_thread
, null_ptid
))
2781 /* In non-stop mode, we assume new found threads
2782 are running until proven otherwise with a
2783 stop reply. In all-stop, we can only get
2784 here if all threads are stopped. */
2785 int running
= non_stop
? 1 : 0;
2787 remote_notice_new_inferior (new_thread
, running
);
2790 while (*bufp
++ == ','); /* comma-separated list */
2791 free_current_contents (&saved_reply
);
2792 putpkt ("qsThreadInfo");
2793 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2794 bufp
= saved_reply
= xstrdup (rs
->buf
);
2796 do_cleanups (old_chain
);
2801 /* Only qfThreadInfo is supported in non-stop mode. */
2805 /* Else fall back to old method based on jmetzler protocol. */
2806 use_threadinfo_query
= 0;
2807 remote_find_new_threads ();
2812 * Collect a descriptive string about the given thread.
2813 * The target may say anything it wants to about the thread
2814 * (typically info about its blocked / runnable state, name, etc.).
2815 * This string will appear in the info threads display.
2817 * Optional: targets are not required to implement this function.
2821 remote_threads_extra_info (struct thread_info
*tp
)
2823 struct remote_state
*rs
= get_remote_state ();
2827 struct gdb_ext_thread_info threadinfo
;
2828 static char display_buf
[100]; /* arbitrary... */
2829 int n
= 0; /* position in display_buf */
2831 if (remote_desc
== 0) /* paranoia */
2832 internal_error (__FILE__
, __LINE__
,
2833 _("remote_threads_extra_info"));
2835 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2836 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2837 /* This is the main thread which was added by GDB. The remote
2838 server doesn't know about it. */
2841 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2843 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2845 if (info
&& info
->private)
2846 return info
->private->extra
;
2851 if (use_threadextra_query
)
2854 char *endb
= rs
->buf
+ get_remote_packet_size ();
2856 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2858 write_ptid (b
, endb
, tp
->ptid
);
2861 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2862 if (rs
->buf
[0] != 0)
2864 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2865 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2866 display_buf
[result
] = '\0';
2871 /* If the above query fails, fall back to the old method. */
2872 use_threadextra_query
= 0;
2873 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2874 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2875 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2876 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2877 if (threadinfo
.active
)
2879 if (*threadinfo
.shortname
)
2880 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2881 " Name: %s,", threadinfo
.shortname
);
2882 if (*threadinfo
.display
)
2883 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2884 " State: %s,", threadinfo
.display
);
2885 if (*threadinfo
.more_display
)
2886 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2887 " Priority: %s", threadinfo
.more_display
);
2891 /* For purely cosmetic reasons, clear up trailing commas. */
2892 if (',' == display_buf
[n
-1])
2893 display_buf
[n
-1] = ' ';
2902 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2903 struct static_tracepoint_marker
*marker
)
2905 struct remote_state
*rs
= get_remote_state ();
2908 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2910 p
+= hexnumstr (p
, addr
);
2912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2916 error (_("Remote failure reply: %s"), p
);
2920 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2927 static VEC(static_tracepoint_marker_p
) *
2928 remote_static_tracepoint_markers_by_strid (const char *strid
)
2930 struct remote_state
*rs
= get_remote_state ();
2931 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2932 struct static_tracepoint_marker
*marker
= NULL
;
2933 struct cleanup
*old_chain
;
2936 /* Ask for a first packet of static tracepoint marker
2939 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2942 error (_("Remote failure reply: %s"), p
);
2944 old_chain
= make_cleanup (free_current_marker
, &marker
);
2949 marker
= XCNEW (struct static_tracepoint_marker
);
2953 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2955 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2957 VEC_safe_push (static_tracepoint_marker_p
,
2963 release_static_tracepoint_marker (marker
);
2964 memset (marker
, 0, sizeof (*marker
));
2967 while (*p
++ == ','); /* comma-separated list */
2968 /* Ask for another packet of static tracepoint definition. */
2970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2974 do_cleanups (old_chain
);
2979 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2982 remote_get_ada_task_ptid (long lwp
, long thread
)
2984 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2988 /* Restart the remote side; this is an extended protocol operation. */
2991 extended_remote_restart (void)
2993 struct remote_state
*rs
= get_remote_state ();
2995 /* Send the restart command; for reasons I don't understand the
2996 remote side really expects a number after the "R". */
2997 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3000 remote_fileio_reset ();
3003 /* Clean up connection to a remote debugger. */
3008 if (remote_desc
== NULL
)
3009 return; /* already closed */
3011 /* Make sure we leave stdin registered in the event loop, and we
3012 don't leave the async SIGINT signal handler installed. */
3013 remote_terminal_ours ();
3015 serial_close (remote_desc
);
3018 /* We don't have a connection to the remote stub anymore. Get rid
3019 of all the inferiors and their threads we were controlling.
3020 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3021 will be unable to find the thread corresponding to (pid, 0, 0). */
3022 inferior_ptid
= null_ptid
;
3023 discard_all_inferiors ();
3025 /* Stop replies may from inferiors which are still unknown to GDB.
3026 We are closing the remote target, so we should discard
3027 everything, including the stop replies from GDB-unknown
3029 discard_pending_stop_replies (NULL
);
3031 if (remote_async_inferior_event_token
)
3032 delete_async_event_handler (&remote_async_inferior_event_token
);
3034 remote_notif_unregister_async_event_handler ();
3037 /* Query the remote side for the text, data and bss offsets. */
3042 struct remote_state
*rs
= get_remote_state ();
3045 int lose
, num_segments
= 0, do_sections
, do_segments
;
3046 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3047 struct section_offsets
*offs
;
3048 struct symfile_segment_data
*data
;
3050 if (symfile_objfile
== NULL
)
3053 putpkt ("qOffsets");
3054 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3057 if (buf
[0] == '\000')
3058 return; /* Return silently. Stub doesn't support
3062 warning (_("Remote failure reply: %s"), buf
);
3066 /* Pick up each field in turn. This used to be done with scanf, but
3067 scanf will make trouble if CORE_ADDR size doesn't match
3068 conversion directives correctly. The following code will work
3069 with any size of CORE_ADDR. */
3070 text_addr
= data_addr
= bss_addr
= 0;
3074 if (strncmp (ptr
, "Text=", 5) == 0)
3077 /* Don't use strtol, could lose on big values. */
3078 while (*ptr
&& *ptr
!= ';')
3079 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3081 if (strncmp (ptr
, ";Data=", 6) == 0)
3084 while (*ptr
&& *ptr
!= ';')
3085 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3090 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3093 while (*ptr
&& *ptr
!= ';')
3094 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3096 if (bss_addr
!= data_addr
)
3097 warning (_("Target reported unsupported offsets: %s"), buf
);
3102 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3105 /* Don't use strtol, could lose on big values. */
3106 while (*ptr
&& *ptr
!= ';')
3107 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3110 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3113 while (*ptr
&& *ptr
!= ';')
3114 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3122 error (_("Malformed response to offset query, %s"), buf
);
3123 else if (*ptr
!= '\0')
3124 warning (_("Target reported unsupported offsets: %s"), buf
);
3126 offs
= ((struct section_offsets
*)
3127 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3128 memcpy (offs
, symfile_objfile
->section_offsets
,
3129 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3131 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3132 do_segments
= (data
!= NULL
);
3133 do_sections
= num_segments
== 0;
3135 if (num_segments
> 0)
3137 segments
[0] = text_addr
;
3138 segments
[1] = data_addr
;
3140 /* If we have two segments, we can still try to relocate everything
3141 by assuming that the .text and .data offsets apply to the whole
3142 text and data segments. Convert the offsets given in the packet
3143 to base addresses for symfile_map_offsets_to_segments. */
3144 else if (data
&& data
->num_segments
== 2)
3146 segments
[0] = data
->segment_bases
[0] + text_addr
;
3147 segments
[1] = data
->segment_bases
[1] + data_addr
;
3150 /* If the object file has only one segment, assume that it is text
3151 rather than data; main programs with no writable data are rare,
3152 but programs with no code are useless. Of course the code might
3153 have ended up in the data segment... to detect that we would need
3154 the permissions here. */
3155 else if (data
&& data
->num_segments
== 1)
3157 segments
[0] = data
->segment_bases
[0] + text_addr
;
3160 /* There's no way to relocate by segment. */
3166 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3167 offs
, num_segments
, segments
);
3169 if (ret
== 0 && !do_sections
)
3170 error (_("Can not handle qOffsets TextSeg "
3171 "response with this symbol file"));
3178 free_symfile_segment_data (data
);
3182 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3184 /* This is a temporary kludge to force data and bss to use the
3185 same offsets because that's what nlmconv does now. The real
3186 solution requires changes to the stub and remote.c that I
3187 don't have time to do right now. */
3189 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3190 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3193 objfile_relocate (symfile_objfile
, offs
);
3196 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3197 threads we know are stopped already. This is used during the
3198 initial remote connection in non-stop mode --- threads that are
3199 reported as already being stopped are left stopped. */
3202 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3204 /* If we have a stop reply for this thread, it must be stopped. */
3205 if (peek_stop_reply (thread
->ptid
))
3206 set_stop_requested (thread
->ptid
, 1);
3211 /* Send interrupt_sequence to remote target. */
3213 send_interrupt_sequence (void)
3215 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3216 remote_serial_write ("\x03", 1);
3217 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3218 serial_send_break (remote_desc
);
3219 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3221 serial_send_break (remote_desc
);
3222 remote_serial_write ("g", 1);
3225 internal_error (__FILE__
, __LINE__
,
3226 _("Invalid value for interrupt_sequence_mode: %s."),
3227 interrupt_sequence_mode
);
3231 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3232 and extract the PTID. Returns NULL_PTID if not found. */
3235 stop_reply_extract_thread (char *stop_reply
)
3237 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3241 /* Txx r:val ; r:val (...) */
3244 /* Look for "register" named "thread". */
3249 p1
= strchr (p
, ':');
3253 if (strncmp (p
, "thread", p1
- p
) == 0)
3254 return read_ptid (++p1
, &p
);
3256 p1
= strchr (p
, ';');
3268 /* Query the remote target for which is the current thread/process,
3269 add it to our tables, and update INFERIOR_PTID. The caller is
3270 responsible for setting the state such that the remote end is ready
3271 to return the current thread.
3273 This function is called after handling the '?' or 'vRun' packets,
3274 whose response is a stop reply from which we can also try
3275 extracting the thread. If the target doesn't support the explicit
3276 qC query, we infer the current thread from that stop reply, passed
3277 in in WAIT_STATUS, which may be NULL. */
3280 add_current_inferior_and_thread (char *wait_status
)
3282 struct remote_state
*rs
= get_remote_state ();
3284 ptid_t ptid
= null_ptid
;
3286 inferior_ptid
= null_ptid
;
3288 /* Now, if we have thread information, update inferior_ptid. First
3289 if we have a stop reply handy, maybe it's a T stop reply with a
3290 "thread" register we can extract the current thread from. If
3291 not, ask the remote which is the current thread, with qC. The
3292 former method avoids a roundtrip. Note we don't use
3293 remote_parse_stop_reply as that makes use of the target
3294 architecture, which we haven't yet fully determined at this
3296 if (wait_status
!= NULL
)
3297 ptid
= stop_reply_extract_thread (wait_status
);
3298 if (ptid_equal (ptid
, null_ptid
))
3299 ptid
= remote_current_thread (inferior_ptid
);
3301 if (!ptid_equal (ptid
, null_ptid
))
3303 if (!remote_multi_process_p (rs
))
3306 inferior_ptid
= ptid
;
3310 /* Without this, some commands which require an active target
3311 (such as kill) won't work. This variable serves (at least)
3312 double duty as both the pid of the target process (if it has
3313 such), and as a flag indicating that a target is active. */
3314 inferior_ptid
= magic_null_ptid
;
3318 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3320 /* Add the main thread. */
3321 add_thread_silent (inferior_ptid
);
3325 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3327 struct remote_state
*rs
= get_remote_state ();
3328 struct packet_config
*noack_config
;
3329 char *wait_status
= NULL
;
3331 immediate_quit
++; /* Allow user to interrupt it. */
3334 if (interrupt_on_connect
)
3335 send_interrupt_sequence ();
3337 /* Ack any packet which the remote side has already sent. */
3338 serial_write (remote_desc
, "+", 1);
3340 /* Signal other parts that we're going through the initial setup,
3341 and so things may not be stable yet. */
3342 rs
->starting_up
= 1;
3344 /* The first packet we send to the target is the optional "supported
3345 packets" request. If the target can answer this, it will tell us
3346 which later probes to skip. */
3347 remote_query_supported ();
3349 /* If the stub wants to get a QAllow, compose one and send it. */
3350 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3351 remote_set_permissions ();
3353 /* Next, we possibly activate noack mode.
3355 If the QStartNoAckMode packet configuration is set to AUTO,
3356 enable noack mode if the stub reported a wish for it with
3359 If set to TRUE, then enable noack mode even if the stub didn't
3360 report it in qSupported. If the stub doesn't reply OK, the
3361 session ends with an error.
3363 If FALSE, then don't activate noack mode, regardless of what the
3364 stub claimed should be the default with qSupported. */
3366 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3368 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3369 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3370 && noack_config
->support
== PACKET_ENABLE
))
3372 putpkt ("QStartNoAckMode");
3373 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3374 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3380 /* Tell the remote that we are using the extended protocol. */
3382 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3385 /* Let the target know which signals it is allowed to pass down to
3387 update_signals_program_target ();
3389 /* Next, if the target can specify a description, read it. We do
3390 this before anything involving memory or registers. */
3391 target_find_description ();
3393 /* Next, now that we know something about the target, update the
3394 address spaces in the program spaces. */
3395 update_address_spaces ();
3397 /* On OSs where the list of libraries is global to all
3398 processes, we fetch them early. */
3399 if (gdbarch_has_global_solist (target_gdbarch ()))
3400 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3404 if (!rs
->non_stop_aware
)
3405 error (_("Non-stop mode requested, but remote "
3406 "does not support non-stop"));
3408 putpkt ("QNonStop:1");
3409 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3411 if (strcmp (rs
->buf
, "OK") != 0)
3412 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3414 /* Find about threads and processes the stub is already
3415 controlling. We default to adding them in the running state.
3416 The '?' query below will then tell us about which threads are
3418 remote_threads_info (target
);
3420 else if (rs
->non_stop_aware
)
3422 /* Don't assume that the stub can operate in all-stop mode.
3423 Request it explicitly. */
3424 putpkt ("QNonStop:0");
3425 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3427 if (strcmp (rs
->buf
, "OK") != 0)
3428 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3431 /* Check whether the target is running now. */
3433 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3439 struct inferior
*inf
;
3441 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3444 error (_("The target is not running (try extended-remote?)"));
3446 /* We're connected, but not running. Drop out before we
3447 call start_remote. */
3448 rs
->starting_up
= 0;
3453 /* Save the reply for later. */
3454 wait_status
= alloca (strlen (rs
->buf
) + 1);
3455 strcpy (wait_status
, rs
->buf
);
3458 /* Let the stub know that we want it to return the thread. */
3459 set_continue_thread (minus_one_ptid
);
3461 add_current_inferior_and_thread (wait_status
);
3463 /* init_wait_for_inferior should be called before get_offsets in order
3464 to manage `inserted' flag in bp loc in a correct state.
3465 breakpoint_init_inferior, called from init_wait_for_inferior, set
3466 `inserted' flag to 0, while before breakpoint_re_set, called from
3467 start_remote, set `inserted' flag to 1. In the initialization of
3468 inferior, breakpoint_init_inferior should be called first, and then
3469 breakpoint_re_set can be called. If this order is broken, state of
3470 `inserted' flag is wrong, and cause some problems on breakpoint
3472 init_wait_for_inferior ();
3474 get_offsets (); /* Get text, data & bss offsets. */
3476 /* If we could not find a description using qXfer, and we know
3477 how to do it some other way, try again. This is not
3478 supported for non-stop; it could be, but it is tricky if
3479 there are no stopped threads when we connect. */
3480 if (remote_read_description_p (target
)
3481 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3483 target_clear_description ();
3484 target_find_description ();
3487 /* Use the previously fetched status. */
3488 gdb_assert (wait_status
!= NULL
);
3489 strcpy (rs
->buf
, wait_status
);
3490 rs
->cached_wait_status
= 1;
3493 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3497 /* Clear WFI global state. Do this before finding about new
3498 threads and inferiors, and setting the current inferior.
3499 Otherwise we would clear the proceed status of the current
3500 inferior when we want its stop_soon state to be preserved
3501 (see notice_new_inferior). */
3502 init_wait_for_inferior ();
3504 /* In non-stop, we will either get an "OK", meaning that there
3505 are no stopped threads at this time; or, a regular stop
3506 reply. In the latter case, there may be more than one thread
3507 stopped --- we pull them all out using the vStopped
3509 if (strcmp (rs
->buf
, "OK") != 0)
3511 struct notif_client
*notif
= ¬if_client_stop
;
3513 /* remote_notif_get_pending_replies acks this one, and gets
3515 notif_client_stop
.pending_event
3516 = remote_notif_parse (notif
, rs
->buf
);
3517 remote_notif_get_pending_events (notif
);
3519 /* Make sure that threads that were stopped remain
3521 iterate_over_threads (set_stop_requested_callback
, NULL
);
3524 if (target_can_async_p ())
3525 target_async (inferior_event_handler
, 0);
3527 if (thread_count () == 0)
3530 error (_("The target is not running (try extended-remote?)"));
3532 /* We're connected, but not running. Drop out before we
3533 call start_remote. */
3534 rs
->starting_up
= 0;
3538 /* Let the stub know that we want it to return the thread. */
3540 /* Force the stub to choose a thread. */
3541 set_general_thread (null_ptid
);
3544 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3545 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3546 error (_("remote didn't report the current thread in non-stop mode"));
3548 get_offsets (); /* Get text, data & bss offsets. */
3550 /* In non-stop mode, any cached wait status will be stored in
3551 the stop reply queue. */
3552 gdb_assert (wait_status
== NULL
);
3554 /* Report all signals during attach/startup. */
3555 remote_pass_signals (0, NULL
);
3558 /* If we connected to a live target, do some additional setup. */
3559 if (target_has_execution
)
3561 if (exec_bfd
) /* No use without an exec file. */
3562 remote_check_symbols (symfile_objfile
);
3565 /* Possibly the target has been engaged in a trace run started
3566 previously; find out where things are at. */
3567 if (remote_get_trace_status (current_trace_status ()) != -1)
3569 struct uploaded_tp
*uploaded_tps
= NULL
;
3570 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3572 if (current_trace_status ()->running
)
3573 printf_filtered (_("Trace is already running on the target.\n"));
3575 /* Get trace state variables first, they may be checked when
3576 parsing uploaded commands. */
3578 remote_upload_trace_state_variables (&uploaded_tsvs
);
3580 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3582 remote_upload_tracepoints (&uploaded_tps
);
3584 merge_uploaded_tracepoints (&uploaded_tps
);
3587 /* The thread and inferior lists are now synchronized with the
3588 target, our symbols have been relocated, and we're merged the
3589 target's tracepoints with ours. We're done with basic start
3591 rs
->starting_up
= 0;
3593 /* If breakpoints are global, insert them now. */
3594 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3595 && breakpoints_always_inserted_mode ())
3596 insert_breakpoints ();
3599 /* Open a connection to a remote debugger.
3600 NAME is the filename used for communication. */
3603 remote_open (char *name
, int from_tty
)
3605 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3608 /* Open a connection to a remote debugger using the extended
3609 remote gdb protocol. NAME is the filename used for communication. */
3612 extended_remote_open (char *name
, int from_tty
)
3614 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3617 /* Generic code for opening a connection to a remote target. */
3620 init_all_packet_configs (void)
3624 for (i
= 0; i
< PACKET_MAX
; i
++)
3625 update_packet_config (&remote_protocol_packets
[i
]);
3628 /* Symbol look-up. */
3631 remote_check_symbols (struct objfile
*objfile
)
3633 struct remote_state
*rs
= get_remote_state ();
3634 char *msg
, *reply
, *tmp
;
3635 struct minimal_symbol
*sym
;
3638 /* The remote side has no concept of inferiors that aren't running
3639 yet, it only knows about running processes. If we're connected
3640 but our current inferior is not running, we should not invite the
3641 remote target to request symbol lookups related to its
3642 (unrelated) current process. */
3643 if (!target_has_execution
)
3646 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3649 /* Make sure the remote is pointing at the right process. Note
3650 there's no way to select "no process". */
3651 set_general_process ();
3653 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3654 because we need both at the same time. */
3655 msg
= alloca (get_remote_packet_size ());
3657 /* Invite target to request symbol lookups. */
3659 putpkt ("qSymbol::");
3660 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3661 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3664 while (strncmp (reply
, "qSymbol:", 8) == 0)
3667 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3669 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3671 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3674 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3675 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3677 /* If this is a function address, return the start of code
3678 instead of any data function descriptor. */
3679 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3683 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3684 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3688 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3693 static struct serial
*
3694 remote_serial_open (char *name
)
3696 static int udp_warning
= 0;
3698 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3699 of in ser-tcp.c, because it is the remote protocol assuming that the
3700 serial connection is reliable and not the serial connection promising
3702 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3704 warning (_("The remote protocol may be unreliable over UDP.\n"
3705 "Some events may be lost, rendering further debugging "
3710 return serial_open (name
);
3713 /* Inform the target of our permission settings. The permission flags
3714 work without this, but if the target knows the settings, it can do
3715 a couple things. First, it can add its own check, to catch cases
3716 that somehow manage to get by the permissions checks in target
3717 methods. Second, if the target is wired to disallow particular
3718 settings (for instance, a system in the field that is not set up to
3719 be able to stop at a breakpoint), it can object to any unavailable
3723 remote_set_permissions (void)
3725 struct remote_state
*rs
= get_remote_state ();
3727 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3728 "WriteReg:%x;WriteMem:%x;"
3729 "InsertBreak:%x;InsertTrace:%x;"
3730 "InsertFastTrace:%x;Stop:%x",
3731 may_write_registers
, may_write_memory
,
3732 may_insert_breakpoints
, may_insert_tracepoints
,
3733 may_insert_fast_tracepoints
, may_stop
);
3735 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3737 /* If the target didn't like the packet, warn the user. Do not try
3738 to undo the user's settings, that would just be maddening. */
3739 if (strcmp (rs
->buf
, "OK") != 0)
3740 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3743 /* This type describes each known response to the qSupported
3745 struct protocol_feature
3747 /* The name of this protocol feature. */
3750 /* The default for this protocol feature. */
3751 enum packet_support default_support
;
3753 /* The function to call when this feature is reported, or after
3754 qSupported processing if the feature is not supported.
3755 The first argument points to this structure. The second
3756 argument indicates whether the packet requested support be
3757 enabled, disabled, or probed (or the default, if this function
3758 is being called at the end of processing and this feature was
3759 not reported). The third argument may be NULL; if not NULL, it
3760 is a NUL-terminated string taken from the packet following
3761 this feature's name and an equals sign. */
3762 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3765 /* The corresponding packet for this feature. Only used if
3766 FUNC is remote_supported_packet. */
3771 remote_supported_packet (const struct protocol_feature
*feature
,
3772 enum packet_support support
,
3773 const char *argument
)
3777 warning (_("Remote qSupported response supplied an unexpected value for"
3778 " \"%s\"."), feature
->name
);
3782 if (remote_protocol_packets
[feature
->packet
].support
3783 == PACKET_SUPPORT_UNKNOWN
)
3784 remote_protocol_packets
[feature
->packet
].support
= support
;
3788 remote_packet_size (const struct protocol_feature
*feature
,
3789 enum packet_support support
, const char *value
)
3791 struct remote_state
*rs
= get_remote_state ();
3796 if (support
!= PACKET_ENABLE
)
3799 if (value
== NULL
|| *value
== '\0')
3801 warning (_("Remote target reported \"%s\" without a size."),
3807 packet_size
= strtol (value
, &value_end
, 16);
3808 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3810 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3811 feature
->name
, value
);
3815 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3817 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3818 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3819 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3822 /* Record the new maximum packet size. */
3823 rs
->explicit_packet_size
= packet_size
;
3827 remote_multi_process_feature (const struct protocol_feature
*feature
,
3828 enum packet_support support
, const char *value
)
3830 struct remote_state
*rs
= get_remote_state ();
3832 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3836 remote_non_stop_feature (const struct protocol_feature
*feature
,
3837 enum packet_support support
, const char *value
)
3839 struct remote_state
*rs
= get_remote_state ();
3841 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3845 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3846 enum packet_support support
,
3849 struct remote_state
*rs
= get_remote_state ();
3851 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3855 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3856 enum packet_support support
,
3859 struct remote_state
*rs
= get_remote_state ();
3861 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3865 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3866 enum packet_support support
,
3869 struct remote_state
*rs
= get_remote_state ();
3871 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3875 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3876 enum packet_support support
,
3879 struct remote_state
*rs
= get_remote_state ();
3881 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3885 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3886 enum packet_support support
,
3889 struct remote_state
*rs
= get_remote_state ();
3891 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3895 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3896 enum packet_support support
,
3899 struct remote_state
*rs
= get_remote_state ();
3901 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3905 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3906 enum packet_support support
,
3909 struct remote_state
*rs
= get_remote_state ();
3911 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3915 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3916 enum packet_support support
,
3919 struct remote_state
*rs
= get_remote_state ();
3921 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3925 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3926 enum packet_support support
,
3929 struct remote_state
*rs
= get_remote_state ();
3931 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3934 static struct protocol_feature remote_protocol_features
[] = {
3935 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3936 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3937 PACKET_qXfer_auxv
},
3938 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3939 PACKET_qXfer_features
},
3940 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3941 PACKET_qXfer_libraries
},
3942 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3943 PACKET_qXfer_libraries_svr4
},
3944 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3945 PACKET_qXfer_memory_map
},
3946 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3947 PACKET_qXfer_spu_read
},
3948 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3949 PACKET_qXfer_spu_write
},
3950 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3951 PACKET_qXfer_osdata
},
3952 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3953 PACKET_qXfer_threads
},
3954 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3955 PACKET_qXfer_traceframe_info
},
3956 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3957 PACKET_QPassSignals
},
3958 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3959 PACKET_QProgramSignals
},
3960 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3961 PACKET_QStartNoAckMode
},
3962 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3963 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3964 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3965 PACKET_qXfer_siginfo_read
},
3966 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3967 PACKET_qXfer_siginfo_write
},
3968 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3969 PACKET_ConditionalTracepoints
},
3970 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
3971 PACKET_ConditionalBreakpoints
},
3972 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
3973 PACKET_BreakpointCommands
},
3974 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3975 PACKET_FastTracepoints
},
3976 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3977 PACKET_StaticTracepoints
},
3978 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3979 PACKET_InstallInTrace
},
3980 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3982 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3984 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3986 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3987 PACKET_TracepointSource
},
3988 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3990 { "EnableDisableTracepoints", PACKET_DISABLE
,
3991 remote_enable_disable_tracepoint_feature
, -1 },
3992 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3993 PACKET_qXfer_fdpic
},
3994 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3996 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3997 PACKET_QDisableRandomization
},
3998 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3999 { "QTBuffer:size", PACKET_DISABLE
,
4000 remote_supported_packet
, PACKET_QTBuffer_size
},
4001 { "tracenz", PACKET_DISABLE
,
4002 remote_string_tracing_feature
, -1 },
4003 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4004 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4005 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4006 PACKET_qXfer_btrace
}
4009 static char *remote_support_xml
;
4011 /* Register string appended to "xmlRegisters=" in qSupported query. */
4014 register_remote_support_xml (const char *xml
)
4016 #if defined(HAVE_LIBEXPAT)
4017 if (remote_support_xml
== NULL
)
4018 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4021 char *copy
= xstrdup (remote_support_xml
+ 13);
4022 char *p
= strtok (copy
, ",");
4026 if (strcmp (p
, xml
) == 0)
4033 while ((p
= strtok (NULL
, ",")) != NULL
);
4036 remote_support_xml
= reconcat (remote_support_xml
,
4037 remote_support_xml
, ",", xml
,
4044 remote_query_supported_append (char *msg
, const char *append
)
4047 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4049 return xstrdup (append
);
4053 remote_query_supported (void)
4055 struct remote_state
*rs
= get_remote_state ();
4058 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4060 /* The packet support flags are handled differently for this packet
4061 than for most others. We treat an error, a disabled packet, and
4062 an empty response identically: any features which must be reported
4063 to be used will be automatically disabled. An empty buffer
4064 accomplishes this, since that is also the representation for a list
4065 containing no features. */
4068 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4071 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4073 q
= remote_query_supported_append (q
, "multiprocess+");
4075 if (remote_support_xml
)
4076 q
= remote_query_supported_append (q
, remote_support_xml
);
4078 q
= remote_query_supported_append (q
, "qRelocInsn+");
4080 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4083 do_cleanups (old_chain
);
4085 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4087 /* If an error occured, warn, but do not return - just reset the
4088 buffer to empty and go on to disable features. */
4089 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4092 warning (_("Remote failure reply: %s"), rs
->buf
);
4097 memset (seen
, 0, sizeof (seen
));
4102 enum packet_support is_supported
;
4103 char *p
, *end
, *name_end
, *value
;
4105 /* First separate out this item from the rest of the packet. If
4106 there's another item after this, we overwrite the separator
4107 (terminated strings are much easier to work with). */
4109 end
= strchr (p
, ';');
4112 end
= p
+ strlen (p
);
4122 warning (_("empty item in \"qSupported\" response"));
4127 name_end
= strchr (p
, '=');
4130 /* This is a name=value entry. */
4131 is_supported
= PACKET_ENABLE
;
4132 value
= name_end
+ 1;
4141 is_supported
= PACKET_ENABLE
;
4145 is_supported
= PACKET_DISABLE
;
4149 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4153 warning (_("unrecognized item \"%s\" "
4154 "in \"qSupported\" response"), p
);
4160 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4161 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4163 const struct protocol_feature
*feature
;
4166 feature
= &remote_protocol_features
[i
];
4167 feature
->func (feature
, is_supported
, value
);
4172 /* If we increased the packet size, make sure to increase the global
4173 buffer size also. We delay this until after parsing the entire
4174 qSupported packet, because this is the same buffer we were
4176 if (rs
->buf_size
< rs
->explicit_packet_size
)
4178 rs
->buf_size
= rs
->explicit_packet_size
;
4179 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4182 /* Handle the defaults for unmentioned features. */
4183 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4186 const struct protocol_feature
*feature
;
4188 feature
= &remote_protocol_features
[i
];
4189 feature
->func (feature
, feature
->default_support
, NULL
);
4193 /* Remove any of the remote.c targets from target stack. Upper targets depend
4194 on it so remove them first. */
4197 remote_unpush_target (void)
4199 pop_all_targets_above (process_stratum
- 1);
4203 remote_open_1 (char *name
, int from_tty
,
4204 struct target_ops
*target
, int extended_p
)
4206 struct remote_state
*rs
= get_remote_state ();
4209 error (_("To open a remote debug connection, you need to specify what\n"
4210 "serial device is attached to the remote system\n"
4211 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4213 /* See FIXME above. */
4214 if (!target_async_permitted
)
4215 wait_forever_enabled_p
= 1;
4217 /* If we're connected to a running target, target_preopen will kill it.
4218 Ask this question first, before target_preopen has a chance to kill
4220 if (remote_desc
!= NULL
&& !have_inferiors ())
4223 && !query (_("Already connected to a remote target. Disconnect? ")))
4224 error (_("Still connected."));
4227 /* Here the possibly existing remote target gets unpushed. */
4228 target_preopen (from_tty
);
4230 /* Make sure we send the passed signals list the next time we resume. */
4231 xfree (last_pass_packet
);
4232 last_pass_packet
= NULL
;
4234 /* Make sure we send the program signals list the next time we
4236 xfree (last_program_signals_packet
);
4237 last_program_signals_packet
= NULL
;
4239 remote_fileio_reset ();
4240 reopen_exec_file ();
4243 remote_desc
= remote_serial_open (name
);
4245 perror_with_name (name
);
4247 if (baud_rate
!= -1)
4249 if (serial_setbaudrate (remote_desc
, baud_rate
))
4251 /* The requested speed could not be set. Error out to
4252 top level after closing remote_desc. Take care to
4253 set remote_desc to NULL to avoid closing remote_desc
4255 serial_close (remote_desc
);
4257 perror_with_name (name
);
4261 serial_raw (remote_desc
);
4263 /* If there is something sitting in the buffer we might take it as a
4264 response to a command, which would be bad. */
4265 serial_flush_input (remote_desc
);
4269 puts_filtered ("Remote debugging using ");
4270 puts_filtered (name
);
4271 puts_filtered ("\n");
4273 push_target (target
); /* Switch to using remote target now. */
4275 /* Register extra event sources in the event loop. */
4276 remote_async_inferior_event_token
4277 = create_async_event_handler (remote_async_inferior_event_handler
,
4279 remote_notif_register_async_event_handler ();
4281 /* Reset the target state; these things will be queried either by
4282 remote_query_supported or as they are needed. */
4283 init_all_packet_configs ();
4284 rs
->cached_wait_status
= 0;
4285 rs
->explicit_packet_size
= 0;
4287 rs
->multi_process_aware
= 0;
4288 rs
->extended
= extended_p
;
4289 rs
->non_stop_aware
= 0;
4290 rs
->waiting_for_stop_reply
= 0;
4291 rs
->ctrlc_pending_p
= 0;
4293 general_thread
= not_sent_ptid
;
4294 continue_thread
= not_sent_ptid
;
4295 remote_traceframe_number
= -1;
4297 /* Probe for ability to use "ThreadInfo" query, as required. */
4298 use_threadinfo_query
= 1;
4299 use_threadextra_query
= 1;
4301 if (target_async_permitted
)
4303 /* With this target we start out by owning the terminal. */
4304 remote_async_terminal_ours_p
= 1;
4306 /* FIXME: cagney/1999-09-23: During the initial connection it is
4307 assumed that the target is already ready and able to respond to
4308 requests. Unfortunately remote_start_remote() eventually calls
4309 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4310 around this. Eventually a mechanism that allows
4311 wait_for_inferior() to expect/get timeouts will be
4313 wait_forever_enabled_p
= 0;
4316 /* First delete any symbols previously loaded from shared libraries. */
4317 no_shared_libraries (NULL
, 0);
4320 init_thread_list ();
4322 /* Start the remote connection. If error() or QUIT, discard this
4323 target (we'd otherwise be in an inconsistent state) and then
4324 propogate the error on up the exception chain. This ensures that
4325 the caller doesn't stumble along blindly assuming that the
4326 function succeeded. The CLI doesn't have this problem but other
4327 UI's, such as MI do.
4329 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4330 this function should return an error indication letting the
4331 caller restore the previous state. Unfortunately the command
4332 ``target remote'' is directly wired to this function making that
4333 impossible. On a positive note, the CLI side of this problem has
4334 been fixed - the function set_cmd_context() makes it possible for
4335 all the ``target ....'' commands to share a common callback
4336 function. See cli-dump.c. */
4338 volatile struct gdb_exception ex
;
4340 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4342 remote_start_remote (from_tty
, target
, extended_p
);
4346 /* Pop the partially set up target - unless something else did
4347 already before throwing the exception. */
4348 if (remote_desc
!= NULL
)
4349 remote_unpush_target ();
4350 if (target_async_permitted
)
4351 wait_forever_enabled_p
= 1;
4352 throw_exception (ex
);
4356 if (target_async_permitted
)
4357 wait_forever_enabled_p
= 1;
4360 /* This takes a program previously attached to and detaches it. After
4361 this is done, GDB can be used to debug some other program. We
4362 better not have left any breakpoints in the target program or it'll
4363 die when it hits one. */
4366 remote_detach_1 (char *args
, int from_tty
, int extended
)
4368 int pid
= ptid_get_pid (inferior_ptid
);
4369 struct remote_state
*rs
= get_remote_state ();
4372 error (_("Argument given to \"detach\" when remotely debugging."));
4374 if (!target_has_execution
)
4375 error (_("No process to detach from."));
4379 char *exec_file
= get_exec_file (0);
4380 if (exec_file
== NULL
)
4382 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4383 target_pid_to_str (pid_to_ptid (pid
)));
4384 gdb_flush (gdb_stdout
);
4387 /* Tell the remote target to detach. */
4388 if (remote_multi_process_p (rs
))
4389 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4391 strcpy (rs
->buf
, "D");
4394 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4396 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4398 else if (rs
->buf
[0] == '\0')
4399 error (_("Remote doesn't know how to detach"));
4401 error (_("Can't detach process."));
4403 if (from_tty
&& !extended
)
4404 puts_filtered (_("Ending remote debugging.\n"));
4406 target_mourn_inferior ();
4410 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4412 remote_detach_1 (args
, from_tty
, 0);
4416 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4418 remote_detach_1 (args
, from_tty
, 1);
4421 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4424 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4427 error (_("Argument given to \"disconnect\" when remotely debugging."));
4429 /* Make sure we unpush even the extended remote targets; mourn
4430 won't do it. So call remote_mourn_1 directly instead of
4431 target_mourn_inferior. */
4432 remote_mourn_1 (target
);
4435 puts_filtered ("Ending remote debugging.\n");
4438 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4439 be chatty about it. */
4442 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4444 struct remote_state
*rs
= get_remote_state ();
4446 char *wait_status
= NULL
;
4448 pid
= parse_pid_to_attach (args
);
4450 /* Remote PID can be freely equal to getpid, do not check it here the same
4451 way as in other targets. */
4453 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4454 error (_("This target does not support attaching to a process"));
4458 char *exec_file
= get_exec_file (0);
4461 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4462 target_pid_to_str (pid_to_ptid (pid
)));
4464 printf_unfiltered (_("Attaching to %s\n"),
4465 target_pid_to_str (pid_to_ptid (pid
)));
4467 gdb_flush (gdb_stdout
);
4470 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4472 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4474 if (packet_ok (rs
->buf
,
4475 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4479 /* Save the reply for later. */
4480 wait_status
= alloca (strlen (rs
->buf
) + 1);
4481 strcpy (wait_status
, rs
->buf
);
4483 else if (strcmp (rs
->buf
, "OK") != 0)
4484 error (_("Attaching to %s failed with: %s"),
4485 target_pid_to_str (pid_to_ptid (pid
)),
4488 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4489 error (_("This target does not support attaching to a process"));
4491 error (_("Attaching to %s failed"),
4492 target_pid_to_str (pid_to_ptid (pid
)));
4494 set_current_inferior (remote_add_inferior (0, pid
, 1));
4496 inferior_ptid
= pid_to_ptid (pid
);
4500 struct thread_info
*thread
;
4502 /* Get list of threads. */
4503 remote_threads_info (target
);
4505 thread
= first_thread_of_process (pid
);
4507 inferior_ptid
= thread
->ptid
;
4509 inferior_ptid
= pid_to_ptid (pid
);
4511 /* Invalidate our notion of the remote current thread. */
4512 record_currthread (minus_one_ptid
);
4516 /* Now, if we have thread information, update inferior_ptid. */
4517 inferior_ptid
= remote_current_thread (inferior_ptid
);
4519 /* Add the main thread to the thread list. */
4520 add_thread_silent (inferior_ptid
);
4523 /* Next, if the target can specify a description, read it. We do
4524 this before anything involving memory or registers. */
4525 target_find_description ();
4529 /* Use the previously fetched status. */
4530 gdb_assert (wait_status
!= NULL
);
4532 if (target_can_async_p ())
4534 struct notif_event
*reply
4535 = remote_notif_parse (¬if_client_stop
, wait_status
);
4537 push_stop_reply ((struct stop_reply
*) reply
);
4539 target_async (inferior_event_handler
, 0);
4543 gdb_assert (wait_status
!= NULL
);
4544 strcpy (rs
->buf
, wait_status
);
4545 rs
->cached_wait_status
= 1;
4549 gdb_assert (wait_status
== NULL
);
4553 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4555 extended_remote_attach_1 (ops
, args
, from_tty
);
4558 /* Convert hex digit A to a number. */
4563 if (a
>= '0' && a
<= '9')
4565 else if (a
>= 'a' && a
<= 'f')
4566 return a
- 'a' + 10;
4567 else if (a
>= 'A' && a
<= 'F')
4568 return a
- 'A' + 10;
4570 error (_("Reply contains invalid hex digit %d"), a
);
4574 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4578 for (i
= 0; i
< count
; i
++)
4580 if (hex
[0] == 0 || hex
[1] == 0)
4582 /* Hex string is short, or of uneven length.
4583 Return the count that has been converted so far. */
4586 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4592 /* Convert number NIB to a hex digit. */
4600 return 'a' + nib
- 10;
4604 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4608 /* May use a length, or a nul-terminated string as input. */
4610 count
= strlen ((char *) bin
);
4612 for (i
= 0; i
< count
; i
++)
4614 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4615 *hex
++ = tohex (*bin
++ & 0xf);
4621 /* Check for the availability of vCont. This function should also check
4625 remote_vcont_probe (struct remote_state
*rs
)
4629 strcpy (rs
->buf
, "vCont?");
4631 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4634 /* Make sure that the features we assume are supported. */
4635 if (strncmp (buf
, "vCont", 5) == 0)
4638 int support_s
, support_S
, support_c
, support_C
;
4644 rs
->support_vCont_t
= 0;
4645 while (p
&& *p
== ';')
4648 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4650 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4652 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4654 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4656 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4657 rs
->support_vCont_t
= 1;
4659 p
= strchr (p
, ';');
4662 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4663 BUF will make packet_ok disable the packet. */
4664 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4668 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4671 /* Helper function for building "vCont" resumptions. Write a
4672 resumption to P. ENDP points to one-passed-the-end of the buffer
4673 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4674 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4675 resumed thread should be single-stepped and/or signalled. If PTID
4676 equals minus_one_ptid, then all threads are resumed; if PTID
4677 represents a process, then all threads of the process are resumed;
4678 the thread to be stepped and/or signalled is given in the global
4682 append_resumption (char *p
, char *endp
,
4683 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4685 struct remote_state
*rs
= get_remote_state ();
4687 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4688 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4690 p
+= xsnprintf (p
, endp
- p
, ";s");
4691 else if (siggnal
!= GDB_SIGNAL_0
)
4692 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4694 p
+= xsnprintf (p
, endp
- p
, ";c");
4696 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4700 /* All (-1) threads of process. */
4701 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4703 p
+= xsnprintf (p
, endp
- p
, ":");
4704 p
= write_ptid (p
, endp
, nptid
);
4706 else if (!ptid_equal (ptid
, minus_one_ptid
))
4708 p
+= xsnprintf (p
, endp
- p
, ":");
4709 p
= write_ptid (p
, endp
, ptid
);
4715 /* Append a vCont continue-with-signal action for threads that have a
4716 non-zero stop signal. */
4719 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4721 struct thread_info
*thread
;
4723 ALL_THREADS (thread
)
4724 if (ptid_match (thread
->ptid
, ptid
)
4725 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4726 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4727 && signal_pass_state (thread
->suspend
.stop_signal
))
4729 p
= append_resumption (p
, endp
, thread
->ptid
,
4730 0, thread
->suspend
.stop_signal
);
4731 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4737 /* Resume the remote inferior by using a "vCont" packet. The thread
4738 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4739 resumed thread should be single-stepped and/or signalled. If PTID
4740 equals minus_one_ptid, then all threads are resumed; the thread to
4741 be stepped and/or signalled is given in the global INFERIOR_PTID.
4742 This function returns non-zero iff it resumes the inferior.
4744 This function issues a strict subset of all possible vCont commands at the
4748 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4750 struct remote_state
*rs
= get_remote_state ();
4754 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4755 remote_vcont_probe (rs
);
4757 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4761 endp
= rs
->buf
+ get_remote_packet_size ();
4763 /* If we could generate a wider range of packets, we'd have to worry
4764 about overflowing BUF. Should there be a generic
4765 "multi-part-packet" packet? */
4767 p
+= xsnprintf (p
, endp
- p
, "vCont");
4769 if (ptid_equal (ptid
, magic_null_ptid
))
4771 /* MAGIC_NULL_PTID means that we don't have any active threads,
4772 so we don't have any TID numbers the inferior will
4773 understand. Make sure to only send forms that do not specify
4775 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4777 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4779 /* Resume all threads (of all processes, or of a single
4780 process), with preference for INFERIOR_PTID. This assumes
4781 inferior_ptid belongs to the set of all threads we are about
4783 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4785 /* Step inferior_ptid, with or without signal. */
4786 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4789 /* Also pass down any pending signaled resumption for other
4790 threads not the current. */
4791 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4793 /* And continue others without a signal. */
4794 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4798 /* Scheduler locking; resume only PTID. */
4799 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4802 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4807 /* In non-stop, the stub replies to vCont with "OK". The stop
4808 reply will be reported asynchronously by means of a `%Stop'
4810 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4811 if (strcmp (rs
->buf
, "OK") != 0)
4812 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4818 /* Tell the remote machine to resume. */
4820 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4822 static int last_sent_step
;
4825 remote_resume (struct target_ops
*ops
,
4826 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4828 struct remote_state
*rs
= get_remote_state ();
4831 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4832 (explained in remote-notif.c:handle_notification) so
4833 remote_notif_process is not called. We need find a place where
4834 it is safe to start a 'vNotif' sequence. It is good to do it
4835 before resuming inferior, because inferior was stopped and no RSP
4836 traffic at that moment. */
4838 remote_notif_process (¬if_client_stop
);
4840 last_sent_signal
= siggnal
;
4841 last_sent_step
= step
;
4843 /* The vCont packet doesn't need to specify threads via Hc. */
4844 /* No reverse support (yet) for vCont. */
4845 if (execution_direction
!= EXEC_REVERSE
)
4846 if (remote_vcont_resume (ptid
, step
, siggnal
))
4849 /* All other supported resume packets do use Hc, so set the continue
4851 if (ptid_equal (ptid
, minus_one_ptid
))
4852 set_continue_thread (any_thread_ptid
);
4854 set_continue_thread (ptid
);
4857 if (execution_direction
== EXEC_REVERSE
)
4859 /* We don't pass signals to the target in reverse exec mode. */
4860 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4861 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4865 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4866 error (_("Remote reverse-step not supported."));
4868 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4869 error (_("Remote reverse-continue not supported."));
4871 strcpy (buf
, step
? "bs" : "bc");
4873 else if (siggnal
!= GDB_SIGNAL_0
)
4875 buf
[0] = step
? 'S' : 'C';
4876 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4877 buf
[2] = tohex (((int) siggnal
) & 0xf);
4881 strcpy (buf
, step
? "s" : "c");
4886 /* We are about to start executing the inferior, let's register it
4887 with the event loop. NOTE: this is the one place where all the
4888 execution commands end up. We could alternatively do this in each
4889 of the execution commands in infcmd.c. */
4890 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4891 into infcmd.c in order to allow inferior function calls to work
4892 NOT asynchronously. */
4893 if (target_can_async_p ())
4894 target_async (inferior_event_handler
, 0);
4896 /* We've just told the target to resume. The remote server will
4897 wait for the inferior to stop, and then send a stop reply. In
4898 the mean time, we can't start another command/query ourselves
4899 because the stub wouldn't be ready to process it. This applies
4900 only to the base all-stop protocol, however. In non-stop (which
4901 only supports vCont), the stub replies with an "OK", and is
4902 immediate able to process further serial input. */
4904 rs
->waiting_for_stop_reply
= 1;
4908 /* Set up the signal handler for SIGINT, while the target is
4909 executing, ovewriting the 'regular' SIGINT signal handler. */
4911 initialize_sigint_signal_handler (void)
4913 signal (SIGINT
, handle_remote_sigint
);
4916 /* Signal handler for SIGINT, while the target is executing. */
4918 handle_remote_sigint (int sig
)
4920 signal (sig
, handle_remote_sigint_twice
);
4921 mark_async_signal_handler (sigint_remote_token
);
4924 /* Signal handler for SIGINT, installed after SIGINT has already been
4925 sent once. It will take effect the second time that the user sends
4928 handle_remote_sigint_twice (int sig
)
4930 signal (sig
, handle_remote_sigint
);
4931 mark_async_signal_handler (sigint_remote_twice_token
);
4934 /* Perform the real interruption of the target execution, in response
4937 async_remote_interrupt (gdb_client_data arg
)
4940 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4942 target_stop (inferior_ptid
);
4945 /* Perform interrupt, if the first attempt did not succeed. Just give
4946 up on the target alltogether. */
4948 async_remote_interrupt_twice (gdb_client_data arg
)
4951 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4956 /* Reinstall the usual SIGINT handlers, after the target has
4959 cleanup_sigint_signal_handler (void *dummy
)
4961 signal (SIGINT
, handle_sigint
);
4964 /* Send ^C to target to halt it. Target will respond, and send us a
4966 static void (*ofunc
) (int);
4968 /* The command line interface's stop routine. This function is installed
4969 as a signal handler for SIGINT. The first time a user requests a
4970 stop, we call remote_stop to send a break or ^C. If there is no
4971 response from the target (it didn't stop when the user requested it),
4972 we ask the user if he'd like to detach from the target. */
4974 remote_interrupt (int signo
)
4976 /* If this doesn't work, try more severe steps. */
4977 signal (signo
, remote_interrupt_twice
);
4979 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4982 /* The user typed ^C twice. */
4985 remote_interrupt_twice (int signo
)
4987 signal (signo
, ofunc
);
4988 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4989 signal (signo
, remote_interrupt
);
4992 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4993 thread, all threads of a remote process, or all threads of all
4997 remote_stop_ns (ptid_t ptid
)
4999 struct remote_state
*rs
= get_remote_state ();
5001 char *endp
= rs
->buf
+ get_remote_packet_size ();
5003 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5004 remote_vcont_probe (rs
);
5006 if (!rs
->support_vCont_t
)
5007 error (_("Remote server does not support stopping threads"));
5009 if (ptid_equal (ptid
, minus_one_ptid
)
5010 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5011 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5016 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5018 if (ptid_is_pid (ptid
))
5019 /* All (-1) threads of process. */
5020 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5023 /* Small optimization: if we already have a stop reply for
5024 this thread, no use in telling the stub we want this
5026 if (peek_stop_reply (ptid
))
5032 write_ptid (p
, endp
, nptid
);
5035 /* In non-stop, we get an immediate OK reply. The stop reply will
5036 come in asynchronously by notification. */
5038 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5039 if (strcmp (rs
->buf
, "OK") != 0)
5040 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5043 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5044 remote target. It is undefined which thread of which process
5045 reports the stop. */
5048 remote_stop_as (ptid_t ptid
)
5050 struct remote_state
*rs
= get_remote_state ();
5052 rs
->ctrlc_pending_p
= 1;
5054 /* If the inferior is stopped already, but the core didn't know
5055 about it yet, just ignore the request. The cached wait status
5056 will be collected in remote_wait. */
5057 if (rs
->cached_wait_status
)
5060 /* Send interrupt_sequence to remote target. */
5061 send_interrupt_sequence ();
5064 /* This is the generic stop called via the target vector. When a target
5065 interrupt is requested, either by the command line or the GUI, we
5066 will eventually end up here. */
5069 remote_stop (ptid_t ptid
)
5072 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5075 remote_stop_ns (ptid
);
5077 remote_stop_as (ptid
);
5080 /* Ask the user what to do when an interrupt is received. */
5083 interrupt_query (void)
5085 target_terminal_ours ();
5087 if (target_can_async_p ())
5089 signal (SIGINT
, handle_sigint
);
5090 deprecated_throw_reason (RETURN_QUIT
);
5094 if (query (_("Interrupted while waiting for the program.\n\
5095 Give up (and stop debugging it)? ")))
5097 remote_unpush_target ();
5098 deprecated_throw_reason (RETURN_QUIT
);
5102 target_terminal_inferior ();
5105 /* Enable/disable target terminal ownership. Most targets can use
5106 terminal groups to control terminal ownership. Remote targets are
5107 different in that explicit transfer of ownership to/from GDB/target
5111 remote_terminal_inferior (void)
5113 if (!target_async_permitted
)
5114 /* Nothing to do. */
5117 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5118 idempotent. The event-loop GDB talking to an asynchronous target
5119 with a synchronous command calls this function from both
5120 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5121 transfer the terminal to the target when it shouldn't this guard
5123 if (!remote_async_terminal_ours_p
)
5125 delete_file_handler (input_fd
);
5126 remote_async_terminal_ours_p
= 0;
5127 initialize_sigint_signal_handler ();
5128 /* NOTE: At this point we could also register our selves as the
5129 recipient of all input. Any characters typed could then be
5130 passed on down to the target. */
5134 remote_terminal_ours (void)
5136 if (!target_async_permitted
)
5137 /* Nothing to do. */
5140 /* See FIXME in remote_terminal_inferior. */
5141 if (remote_async_terminal_ours_p
)
5143 cleanup_sigint_signal_handler (NULL
);
5144 add_file_handler (input_fd
, stdin_event_handler
, 0);
5145 remote_async_terminal_ours_p
= 1;
5149 remote_console_output (char *msg
)
5153 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5156 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5160 fputs_unfiltered (tb
, gdb_stdtarg
);
5162 gdb_flush (gdb_stdtarg
);
5165 typedef struct cached_reg
5168 gdb_byte data
[MAX_REGISTER_SIZE
];
5171 DEF_VEC_O(cached_reg_t
);
5173 typedef struct stop_reply
5175 struct notif_event base
;
5177 /* The identifier of the thread about this event */
5180 struct target_waitstatus ws
;
5182 /* Expedited registers. This makes remote debugging a bit more
5183 efficient for those targets that provide critical registers as
5184 part of their normal status mechanism (as another roundtrip to
5185 fetch them is avoided). */
5186 VEC(cached_reg_t
) *regcache
;
5188 int stopped_by_watchpoint_p
;
5189 CORE_ADDR watch_data_address
;
5197 DECLARE_QUEUE_P (stop_reply_p
);
5198 DEFINE_QUEUE_P (stop_reply_p
);
5199 /* The list of already fetched and acknowledged stop events. This
5200 queue is used for notification Stop, and other notifications
5201 don't need queue for their events, because the notification events
5202 of Stop can't be consumed immediately, so that events should be
5203 queued first, and be consumed by remote_wait_{ns,as} one per
5204 time. Other notifications can consume their events immediately,
5205 so queue is not needed for them. */
5206 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5209 stop_reply_xfree (struct stop_reply
*r
)
5213 VEC_free (cached_reg_t
, r
->regcache
);
5219 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5220 struct notif_event
*event
)
5222 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5226 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5227 struct notif_event
*event
)
5229 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5232 putpkt ((char *) self
->ack_command
);
5234 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5235 /* We got an unknown stop reply. */
5236 error (_("Unknown stop reply"));
5238 push_stop_reply (stop_reply
);
5242 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5244 /* We can't get pending events in remote_notif_process for
5245 notification stop, and we have to do this in remote_wait_ns
5246 instead. If we fetch all queued events from stub, remote stub
5247 may exit and we have no chance to process them back in
5249 mark_async_event_handler (remote_async_inferior_event_token
);
5254 stop_reply_dtr (struct notif_event
*event
)
5256 struct stop_reply
*r
= (struct stop_reply
*) event
;
5258 VEC_free (cached_reg_t
, r
->regcache
);
5261 static struct notif_event
*
5262 remote_notif_stop_alloc_reply (void)
5264 struct notif_event
*r
5265 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5267 r
->dtr
= stop_reply_dtr
;
5272 /* A client of notification Stop. */
5274 struct notif_client notif_client_stop
=
5278 remote_notif_stop_parse
,
5279 remote_notif_stop_ack
,
5280 remote_notif_stop_can_get_pending_events
,
5281 remote_notif_stop_alloc_reply
,
5285 /* A parameter to pass data in and out. */
5287 struct queue_iter_param
5290 struct stop_reply
*output
;
5293 /* Remove all queue elements meet the condition it checks. */
5296 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5297 QUEUE_ITER (stop_reply_p
) *iter
,
5301 struct queue_iter_param
*param
= data
;
5302 struct inferior
*inf
= param
->input
;
5304 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5306 stop_reply_xfree (event
);
5307 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5313 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5314 discard everything. */
5317 discard_pending_stop_replies (struct inferior
*inf
)
5320 struct queue_iter_param param
;
5321 struct stop_reply
*reply
5322 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5324 /* Discard the in-flight notification. */
5327 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5329 stop_reply_xfree (reply
);
5330 notif_client_stop
.pending_event
= NULL
;
5334 param
.output
= NULL
;
5335 /* Discard the stop replies we have already pulled with
5337 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5338 remote_notif_remove_all
, ¶m
);
5341 /* A parameter to pass data in and out. */
5344 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5345 QUEUE_ITER (stop_reply_p
) *iter
,
5349 struct queue_iter_param
*param
= data
;
5350 ptid_t
*ptid
= param
->input
;
5352 if (ptid_match (event
->ptid
, *ptid
))
5354 param
->output
= event
;
5355 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5362 /* Remove the first reply in 'stop_reply_queue' which matches
5365 static struct stop_reply
*
5366 remote_notif_remove_queued_reply (ptid_t ptid
)
5368 struct queue_iter_param param
;
5370 param
.input
= &ptid
;
5371 param
.output
= NULL
;
5373 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5374 remote_notif_remove_once_on_match
, ¶m
);
5376 fprintf_unfiltered (gdb_stdlog
,
5377 "notif: discard queued event: 'Stop' in %s\n",
5378 target_pid_to_str (ptid
));
5380 return param
.output
;
5383 /* Look for a queued stop reply belonging to PTID. If one is found,
5384 remove it from the queue, and return it. Returns NULL if none is
5385 found. If there are still queued events left to process, tell the
5386 event loop to get back to target_wait soon. */
5388 static struct stop_reply
*
5389 queued_stop_reply (ptid_t ptid
)
5391 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5393 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5394 /* There's still at least an event left. */
5395 mark_async_event_handler (remote_async_inferior_event_token
);
5400 /* Push a fully parsed stop reply in the stop reply queue. Since we
5401 know that we now have at least one queued event left to pass to the
5402 core side, tell the event loop to get back to target_wait soon. */
5405 push_stop_reply (struct stop_reply
*new_event
)
5407 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5410 fprintf_unfiltered (gdb_stdlog
,
5411 "notif: push 'Stop' %s to queue %d\n",
5412 target_pid_to_str (new_event
->ptid
),
5413 QUEUE_length (stop_reply_p
,
5416 mark_async_event_handler (remote_async_inferior_event_token
);
5420 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5421 QUEUE_ITER (stop_reply_p
) *iter
,
5422 struct stop_reply
*event
,
5425 ptid_t
*ptid
= data
;
5427 return !(ptid_equal (*ptid
, event
->ptid
)
5428 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5431 /* Returns true if we have a stop reply for PTID. */
5434 peek_stop_reply (ptid_t ptid
)
5436 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5437 stop_reply_match_ptid_and_ws
, &ptid
);
5440 /* Parse the stop reply in BUF. Either the function succeeds, and the
5441 result is stored in EVENT, or throws an error. */
5444 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5446 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5450 event
->ptid
= null_ptid
;
5451 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5452 event
->ws
.value
.integer
= 0;
5453 event
->solibs_changed
= 0;
5454 event
->replay_event
= 0;
5455 event
->stopped_by_watchpoint_p
= 0;
5456 event
->regcache
= NULL
;
5461 case 'T': /* Status with PC, SP, FP, ... */
5462 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5463 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5465 n... = register number
5466 r... = register contents
5469 p
= &buf
[3]; /* after Txx */
5477 /* If the packet contains a register number, save it in
5478 pnum and set p1 to point to the character following it.
5479 Otherwise p1 points to p. */
5481 /* If this packet is an awatch packet, don't parse the 'a'
5482 as a register number. */
5484 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5485 && strncmp (p
, "core", strlen ("core") != 0))
5487 /* Read the ``P'' register number. */
5488 pnum
= strtol (p
, &p_temp
, 16);
5494 if (p1
== p
) /* No register number present here. */
5496 p1
= strchr (p
, ':');
5498 error (_("Malformed packet(a) (missing colon): %s\n\
5501 if (strncmp (p
, "thread", p1
- p
) == 0)
5502 event
->ptid
= read_ptid (++p1
, &p
);
5503 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5504 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5505 || (strncmp (p
, "awatch", p1
- p
) == 0))
5507 event
->stopped_by_watchpoint_p
= 1;
5508 p
= unpack_varlen_hex (++p1
, &addr
);
5509 event
->watch_data_address
= (CORE_ADDR
) addr
;
5511 else if (strncmp (p
, "library", p1
- p
) == 0)
5515 while (*p_temp
&& *p_temp
!= ';')
5518 event
->solibs_changed
= 1;
5521 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5523 /* NO_HISTORY event.
5524 p1 will indicate "begin" or "end", but
5525 it makes no difference for now, so ignore it. */
5526 event
->replay_event
= 1;
5527 p_temp
= strchr (p1
+ 1, ';');
5531 else if (strncmp (p
, "core", p1
- p
) == 0)
5535 p
= unpack_varlen_hex (++p1
, &c
);
5540 /* Silently skip unknown optional info. */
5541 p_temp
= strchr (p1
+ 1, ';');
5548 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5549 cached_reg_t cached_reg
;
5554 error (_("Malformed packet(b) (missing colon): %s\n\
5560 error (_("Remote sent bad register number %s: %s\n\
5562 hex_string (pnum
), p
, buf
);
5564 cached_reg
.num
= reg
->regnum
;
5566 fieldsize
= hex2bin (p
, cached_reg
.data
,
5567 register_size (target_gdbarch (),
5570 if (fieldsize
< register_size (target_gdbarch (),
5572 warning (_("Remote reply is too short: %s"), buf
);
5574 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5578 error (_("Remote register badly formatted: %s\nhere: %s"),
5583 case 'S': /* Old style status, just signal only. */
5584 if (event
->solibs_changed
)
5585 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5586 else if (event
->replay_event
)
5587 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5590 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5591 event
->ws
.value
.sig
= (enum gdb_signal
)
5592 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5595 case 'W': /* Target exited. */
5602 /* GDB used to accept only 2 hex chars here. Stubs should
5603 only send more if they detect GDB supports multi-process
5605 p
= unpack_varlen_hex (&buf
[1], &value
);
5609 /* The remote process exited. */
5610 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5611 event
->ws
.value
.integer
= value
;
5615 /* The remote process exited with a signal. */
5616 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5617 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5620 /* If no process is specified, assume inferior_ptid. */
5621 pid
= ptid_get_pid (inferior_ptid
);
5630 else if (strncmp (p
,
5631 "process:", sizeof ("process:") - 1) == 0)
5635 p
+= sizeof ("process:") - 1;
5636 unpack_varlen_hex (p
, &upid
);
5640 error (_("unknown stop reply packet: %s"), buf
);
5643 error (_("unknown stop reply packet: %s"), buf
);
5644 event
->ptid
= pid_to_ptid (pid
);
5649 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5650 error (_("No process or thread specified in stop reply: %s"), buf
);
5653 /* When the stub wants to tell GDB about a new notification reply, it
5654 sends a notification (%Stop, for example). Those can come it at
5655 any time, hence, we have to make sure that any pending
5656 putpkt/getpkt sequence we're making is finished, before querying
5657 the stub for more events with the corresponding ack command
5658 (vStopped, for example). E.g., if we started a vStopped sequence
5659 immediately upon receiving the notification, something like this
5667 1.6) <-- (registers reply to step #1.3)
5669 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5672 To solve this, whenever we parse a %Stop notification successfully,
5673 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5674 doing whatever we were doing:
5680 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5681 2.5) <-- (registers reply to step #2.3)
5683 Eventualy after step #2.5, we return to the event loop, which
5684 notices there's an event on the
5685 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5686 associated callback --- the function below. At this point, we're
5687 always safe to start a vStopped sequence. :
5690 2.7) <-- T05 thread:2
5696 remote_notif_get_pending_events (struct notif_client
*nc
)
5698 struct remote_state
*rs
= get_remote_state ();
5700 if (nc
->pending_event
)
5703 fprintf_unfiltered (gdb_stdlog
,
5704 "notif: process: '%s' ack pending event\n",
5708 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5709 nc
->pending_event
= NULL
;
5713 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5714 if (strcmp (rs
->buf
, "OK") == 0)
5717 remote_notif_ack (nc
, rs
->buf
);
5723 fprintf_unfiltered (gdb_stdlog
,
5724 "notif: process: '%s' no pending reply\n",
5729 /* Called when it is decided that STOP_REPLY holds the info of the
5730 event that is to be returned to the core. This function always
5731 destroys STOP_REPLY. */
5734 process_stop_reply (struct stop_reply
*stop_reply
,
5735 struct target_waitstatus
*status
)
5739 *status
= stop_reply
->ws
;
5740 ptid
= stop_reply
->ptid
;
5742 /* If no thread/process was reported by the stub, assume the current
5744 if (ptid_equal (ptid
, null_ptid
))
5745 ptid
= inferior_ptid
;
5747 if (status
->kind
!= TARGET_WAITKIND_EXITED
5748 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5750 /* Expedited registers. */
5751 if (stop_reply
->regcache
)
5753 struct regcache
*regcache
5754 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5759 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5761 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5762 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5765 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5766 remote_watch_data_address
= stop_reply
->watch_data_address
;
5768 remote_notice_new_inferior (ptid
, 0);
5769 demand_private_info (ptid
)->core
= stop_reply
->core
;
5772 stop_reply_xfree (stop_reply
);
5776 /* The non-stop mode version of target_wait. */
5779 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5781 struct remote_state
*rs
= get_remote_state ();
5782 struct stop_reply
*stop_reply
;
5786 /* If in non-stop mode, get out of getpkt even if a
5787 notification is received. */
5789 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5790 0 /* forever */, &is_notif
);
5793 if (ret
!= -1 && !is_notif
)
5796 case 'E': /* Error of some sort. */
5797 /* We're out of sync with the target now. Did it continue
5798 or not? We can't tell which thread it was in non-stop,
5799 so just ignore this. */
5800 warning (_("Remote failure reply: %s"), rs
->buf
);
5802 case 'O': /* Console output. */
5803 remote_console_output (rs
->buf
+ 1);
5806 warning (_("Invalid remote reply: %s"), rs
->buf
);
5810 /* Acknowledge a pending stop reply that may have arrived in the
5812 if (notif_client_stop
.pending_event
!= NULL
)
5813 remote_notif_get_pending_events (¬if_client_stop
);
5815 /* If indeed we noticed a stop reply, we're done. */
5816 stop_reply
= queued_stop_reply (ptid
);
5817 if (stop_reply
!= NULL
)
5818 return process_stop_reply (stop_reply
, status
);
5820 /* Still no event. If we're just polling for an event, then
5821 return to the event loop. */
5822 if (options
& TARGET_WNOHANG
)
5824 status
->kind
= TARGET_WAITKIND_IGNORE
;
5825 return minus_one_ptid
;
5828 /* Otherwise do a blocking wait. */
5829 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5830 1 /* forever */, &is_notif
);
5834 /* Wait until the remote machine stops, then return, storing status in
5835 STATUS just as `wait' would. */
5838 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5840 struct remote_state
*rs
= get_remote_state ();
5841 ptid_t event_ptid
= null_ptid
;
5843 struct stop_reply
*stop_reply
;
5847 status
->kind
= TARGET_WAITKIND_IGNORE
;
5848 status
->value
.integer
= 0;
5850 stop_reply
= queued_stop_reply (ptid
);
5851 if (stop_reply
!= NULL
)
5852 return process_stop_reply (stop_reply
, status
);
5854 if (rs
->cached_wait_status
)
5855 /* Use the cached wait status, but only once. */
5856 rs
->cached_wait_status
= 0;
5862 if (!target_is_async_p ())
5864 ofunc
= signal (SIGINT
, remote_interrupt
);
5865 /* If the user hit C-c before this packet, or between packets,
5866 pretend that it was hit right here. */
5867 if (check_quit_flag ())
5870 remote_interrupt (SIGINT
);
5874 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5875 _never_ wait for ever -> test on target_is_async_p().
5876 However, before we do that we need to ensure that the caller
5877 knows how to take the target into/out of async mode. */
5878 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5879 wait_forever_enabled_p
, &is_notif
);
5881 /* GDB gets a notification. Return to core as this event is
5883 if (ret
!= -1 && is_notif
)
5884 return minus_one_ptid
;
5886 if (!target_is_async_p ())
5887 signal (SIGINT
, ofunc
);
5892 remote_stopped_by_watchpoint_p
= 0;
5894 /* We got something. */
5895 rs
->waiting_for_stop_reply
= 0;
5897 /* Assume that the target has acknowledged Ctrl-C unless we receive
5898 an 'F' or 'O' packet. */
5899 if (buf
[0] != 'F' && buf
[0] != 'O')
5900 rs
->ctrlc_pending_p
= 0;
5904 case 'E': /* Error of some sort. */
5905 /* We're out of sync with the target now. Did it continue or
5906 not? Not is more likely, so report a stop. */
5907 warning (_("Remote failure reply: %s"), buf
);
5908 status
->kind
= TARGET_WAITKIND_STOPPED
;
5909 status
->value
.sig
= GDB_SIGNAL_0
;
5911 case 'F': /* File-I/O request. */
5912 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5913 rs
->ctrlc_pending_p
= 0;
5915 case 'T': case 'S': case 'X': case 'W':
5917 struct stop_reply
*stop_reply
5918 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
5921 event_ptid
= process_stop_reply (stop_reply
, status
);
5924 case 'O': /* Console output. */
5925 remote_console_output (buf
+ 1);
5927 /* The target didn't really stop; keep waiting. */
5928 rs
->waiting_for_stop_reply
= 1;
5932 if (last_sent_signal
!= GDB_SIGNAL_0
)
5934 /* Zero length reply means that we tried 'S' or 'C' and the
5935 remote system doesn't support it. */
5936 target_terminal_ours_for_output ();
5938 ("Can't send signals to this remote system. %s not sent.\n",
5939 gdb_signal_to_name (last_sent_signal
));
5940 last_sent_signal
= GDB_SIGNAL_0
;
5941 target_terminal_inferior ();
5943 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5944 putpkt ((char *) buf
);
5946 /* We just told the target to resume, so a stop reply is in
5948 rs
->waiting_for_stop_reply
= 1;
5951 /* else fallthrough */
5953 warning (_("Invalid remote reply: %s"), buf
);
5955 rs
->waiting_for_stop_reply
= 1;
5959 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5961 /* Nothing interesting happened. If we're doing a non-blocking
5962 poll, we're done. Otherwise, go back to waiting. */
5963 if (options
& TARGET_WNOHANG
)
5964 return minus_one_ptid
;
5968 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5969 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5971 if (!ptid_equal (event_ptid
, null_ptid
))
5972 record_currthread (event_ptid
);
5974 event_ptid
= inferior_ptid
;
5977 /* A process exit. Invalidate our notion of current thread. */
5978 record_currthread (minus_one_ptid
);
5983 /* Wait until the remote machine stops, then return, storing status in
5984 STATUS just as `wait' would. */
5987 remote_wait (struct target_ops
*ops
,
5988 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5993 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5995 event_ptid
= remote_wait_as (ptid
, status
, options
);
5997 if (target_can_async_p ())
5999 /* If there are are events left in the queue tell the event loop
6001 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6002 mark_async_event_handler (remote_async_inferior_event_token
);
6008 /* Fetch a single register using a 'p' packet. */
6011 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6013 struct remote_state
*rs
= get_remote_state ();
6015 char regp
[MAX_REGISTER_SIZE
];
6018 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6021 if (reg
->pnum
== -1)
6026 p
+= hexnumstr (p
, reg
->pnum
);
6029 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6033 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6037 case PACKET_UNKNOWN
:
6040 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6041 gdbarch_register_name (get_regcache_arch (regcache
),
6046 /* If this register is unfetchable, tell the regcache. */
6049 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6053 /* Otherwise, parse and supply the value. */
6059 error (_("fetch_register_using_p: early buf termination"));
6061 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6064 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6068 /* Fetch the registers included in the target's 'g' packet. */
6071 send_g_packet (void)
6073 struct remote_state
*rs
= get_remote_state ();
6076 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6077 remote_send (&rs
->buf
, &rs
->buf_size
);
6079 /* We can get out of synch in various cases. If the first character
6080 in the buffer is not a hex character, assume that has happened
6081 and try to fetch another packet to read. */
6082 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6083 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6084 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6085 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6088 fprintf_unfiltered (gdb_stdlog
,
6089 "Bad register packet; fetching a new packet\n");
6090 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6093 buf_len
= strlen (rs
->buf
);
6095 /* Sanity check the received packet. */
6096 if (buf_len
% 2 != 0)
6097 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6103 process_g_packet (struct regcache
*regcache
)
6105 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6106 struct remote_state
*rs
= get_remote_state ();
6107 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6112 buf_len
= strlen (rs
->buf
);
6114 /* Further sanity checks, with knowledge of the architecture. */
6115 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6116 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6118 /* Save the size of the packet sent to us by the target. It is used
6119 as a heuristic when determining the max size of packets that the
6120 target can safely receive. */
6121 if (rsa
->actual_register_packet_size
== 0)
6122 rsa
->actual_register_packet_size
= buf_len
;
6124 /* If this is smaller than we guessed the 'g' packet would be,
6125 update our records. A 'g' reply that doesn't include a register's
6126 value implies either that the register is not available, or that
6127 the 'p' packet must be used. */
6128 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6130 rsa
->sizeof_g_packet
= buf_len
/ 2;
6132 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6134 if (rsa
->regs
[i
].pnum
== -1)
6137 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6138 rsa
->regs
[i
].in_g_packet
= 0;
6140 rsa
->regs
[i
].in_g_packet
= 1;
6144 regs
= alloca (rsa
->sizeof_g_packet
);
6146 /* Unimplemented registers read as all bits zero. */
6147 memset (regs
, 0, rsa
->sizeof_g_packet
);
6149 /* Reply describes registers byte by byte, each byte encoded as two
6150 hex characters. Suck them all up, then supply them to the
6151 register cacheing/storage mechanism. */
6154 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6156 if (p
[0] == 0 || p
[1] == 0)
6157 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6158 internal_error (__FILE__
, __LINE__
,
6159 _("unexpected end of 'g' packet reply"));
6161 if (p
[0] == 'x' && p
[1] == 'x')
6162 regs
[i
] = 0; /* 'x' */
6164 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6168 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6170 struct packet_reg
*r
= &rsa
->regs
[i
];
6174 if (r
->offset
* 2 >= strlen (rs
->buf
))
6175 /* This shouldn't happen - we adjusted in_g_packet above. */
6176 internal_error (__FILE__
, __LINE__
,
6177 _("unexpected end of 'g' packet reply"));
6178 else if (rs
->buf
[r
->offset
* 2] == 'x')
6180 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6181 /* The register isn't available, mark it as such (at
6182 the same time setting the value to zero). */
6183 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6186 regcache_raw_supply (regcache
, r
->regnum
,
6193 fetch_registers_using_g (struct regcache
*regcache
)
6196 process_g_packet (regcache
);
6199 /* Make the remote selected traceframe match GDB's selected
6203 set_remote_traceframe (void)
6207 if (remote_traceframe_number
== get_traceframe_number ())
6210 /* Avoid recursion, remote_trace_find calls us again. */
6211 remote_traceframe_number
= get_traceframe_number ();
6213 newnum
= target_trace_find (tfind_number
,
6214 get_traceframe_number (), 0, 0, NULL
);
6216 /* Should not happen. If it does, all bets are off. */
6217 if (newnum
!= get_traceframe_number ())
6218 warning (_("could not set remote traceframe"));
6222 remote_fetch_registers (struct target_ops
*ops
,
6223 struct regcache
*regcache
, int regnum
)
6225 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6228 set_remote_traceframe ();
6229 set_general_thread (inferior_ptid
);
6233 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6235 gdb_assert (reg
!= NULL
);
6237 /* If this register might be in the 'g' packet, try that first -
6238 we are likely to read more than one register. If this is the
6239 first 'g' packet, we might be overly optimistic about its
6240 contents, so fall back to 'p'. */
6241 if (reg
->in_g_packet
)
6243 fetch_registers_using_g (regcache
);
6244 if (reg
->in_g_packet
)
6248 if (fetch_register_using_p (regcache
, reg
))
6251 /* This register is not available. */
6252 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6257 fetch_registers_using_g (regcache
);
6259 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6260 if (!rsa
->regs
[i
].in_g_packet
)
6261 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6263 /* This register is not available. */
6264 regcache_raw_supply (regcache
, i
, NULL
);
6268 /* Prepare to store registers. Since we may send them all (using a
6269 'G' request), we have to read out the ones we don't want to change
6273 remote_prepare_to_store (struct regcache
*regcache
)
6275 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6277 gdb_byte buf
[MAX_REGISTER_SIZE
];
6279 /* Make sure the entire registers array is valid. */
6280 switch (remote_protocol_packets
[PACKET_P
].support
)
6282 case PACKET_DISABLE
:
6283 case PACKET_SUPPORT_UNKNOWN
:
6284 /* Make sure all the necessary registers are cached. */
6285 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6286 if (rsa
->regs
[i
].in_g_packet
)
6287 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6294 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6295 packet was not recognized. */
6298 store_register_using_P (const struct regcache
*regcache
,
6299 struct packet_reg
*reg
)
6301 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6302 struct remote_state
*rs
= get_remote_state ();
6303 /* Try storing a single register. */
6304 char *buf
= rs
->buf
;
6305 gdb_byte regp
[MAX_REGISTER_SIZE
];
6308 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6311 if (reg
->pnum
== -1)
6314 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6315 p
= buf
+ strlen (buf
);
6316 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6317 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6319 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6321 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6326 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6327 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6328 case PACKET_UNKNOWN
:
6331 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6335 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6336 contents of the register cache buffer. FIXME: ignores errors. */
6339 store_registers_using_G (const struct regcache
*regcache
)
6341 struct remote_state
*rs
= get_remote_state ();
6342 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6346 /* Extract all the registers in the regcache copying them into a
6351 regs
= alloca (rsa
->sizeof_g_packet
);
6352 memset (regs
, 0, rsa
->sizeof_g_packet
);
6353 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6355 struct packet_reg
*r
= &rsa
->regs
[i
];
6358 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6362 /* Command describes registers byte by byte,
6363 each byte encoded as two hex characters. */
6366 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6368 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6370 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6371 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6372 error (_("Could not write registers; remote failure reply '%s'"),
6376 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6377 of the register cache buffer. FIXME: ignores errors. */
6380 remote_store_registers (struct target_ops
*ops
,
6381 struct regcache
*regcache
, int regnum
)
6383 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6386 set_remote_traceframe ();
6387 set_general_thread (inferior_ptid
);
6391 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6393 gdb_assert (reg
!= NULL
);
6395 /* Always prefer to store registers using the 'P' packet if
6396 possible; we often change only a small number of registers.
6397 Sometimes we change a larger number; we'd need help from a
6398 higher layer to know to use 'G'. */
6399 if (store_register_using_P (regcache
, reg
))
6402 /* For now, don't complain if we have no way to write the
6403 register. GDB loses track of unavailable registers too
6404 easily. Some day, this may be an error. We don't have
6405 any way to read the register, either... */
6406 if (!reg
->in_g_packet
)
6409 store_registers_using_G (regcache
);
6413 store_registers_using_G (regcache
);
6415 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6416 if (!rsa
->regs
[i
].in_g_packet
)
6417 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6418 /* See above for why we do not issue an error here. */
6423 /* Return the number of hex digits in num. */
6426 hexnumlen (ULONGEST num
)
6430 for (i
= 0; num
!= 0; i
++)
6436 /* Set BUF to the minimum number of hex digits representing NUM. */
6439 hexnumstr (char *buf
, ULONGEST num
)
6441 int len
= hexnumlen (num
);
6443 return hexnumnstr (buf
, num
, len
);
6447 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6450 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6456 for (i
= width
- 1; i
>= 0; i
--)
6458 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6465 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6468 remote_address_masked (CORE_ADDR addr
)
6470 unsigned int address_size
= remote_address_size
;
6472 /* If "remoteaddresssize" was not set, default to target address size. */
6474 address_size
= gdbarch_addr_bit (target_gdbarch ());
6476 if (address_size
> 0
6477 && address_size
< (sizeof (ULONGEST
) * 8))
6479 /* Only create a mask when that mask can safely be constructed
6480 in a ULONGEST variable. */
6483 mask
= (mask
<< address_size
) - 1;
6489 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6490 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6491 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6492 (which may be more than *OUT_LEN due to escape characters). The
6493 total number of bytes in the output buffer will be at most
6497 remote_escape_output (const gdb_byte
*buffer
, int len
,
6498 gdb_byte
*out_buf
, int *out_len
,
6501 int input_index
, output_index
;
6504 for (input_index
= 0; input_index
< len
; input_index
++)
6506 gdb_byte b
= buffer
[input_index
];
6508 if (b
== '$' || b
== '#' || b
== '}')
6510 /* These must be escaped. */
6511 if (output_index
+ 2 > out_maxlen
)
6513 out_buf
[output_index
++] = '}';
6514 out_buf
[output_index
++] = b
^ 0x20;
6518 if (output_index
+ 1 > out_maxlen
)
6520 out_buf
[output_index
++] = b
;
6524 *out_len
= input_index
;
6525 return output_index
;
6528 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6529 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6530 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6532 This function reverses remote_escape_output. It allows more
6533 escaped characters than that function does, in particular because
6534 '*' must be escaped to avoid the run-length encoding processing
6535 in reading packets. */
6538 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6539 gdb_byte
*out_buf
, int out_maxlen
)
6541 int input_index
, output_index
;
6546 for (input_index
= 0; input_index
< len
; input_index
++)
6548 gdb_byte b
= buffer
[input_index
];
6550 if (output_index
+ 1 > out_maxlen
)
6552 warning (_("Received too much data from remote target;"
6553 " ignoring overflow."));
6554 return output_index
;
6559 out_buf
[output_index
++] = b
^ 0x20;
6565 out_buf
[output_index
++] = b
;
6569 error (_("Unmatched escape character in target response."));
6571 return output_index
;
6574 /* Determine whether the remote target supports binary downloading.
6575 This is accomplished by sending a no-op memory write of zero length
6576 to the target at the specified address. It does not suffice to send
6577 the whole packet, since many stubs strip the eighth bit and
6578 subsequently compute a wrong checksum, which causes real havoc with
6581 NOTE: This can still lose if the serial line is not eight-bit
6582 clean. In cases like this, the user should clear "remote
6586 check_binary_download (CORE_ADDR addr
)
6588 struct remote_state
*rs
= get_remote_state ();
6590 switch (remote_protocol_packets
[PACKET_X
].support
)
6592 case PACKET_DISABLE
:
6596 case PACKET_SUPPORT_UNKNOWN
:
6602 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6604 p
+= hexnumstr (p
, (ULONGEST
) 0);
6608 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6609 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6611 if (rs
->buf
[0] == '\0')
6614 fprintf_unfiltered (gdb_stdlog
,
6615 "binary downloading NOT "
6616 "supported by target\n");
6617 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6622 fprintf_unfiltered (gdb_stdlog
,
6623 "binary downloading supported by target\n");
6624 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6631 /* Write memory data directly to the remote machine.
6632 This does not inform the data cache; the data cache uses this.
6633 HEADER is the starting part of the packet.
6634 MEMADDR is the address in the remote memory space.
6635 MYADDR is the address of the buffer in our space.
6636 LEN is the number of bytes.
6637 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6638 should send data as binary ('X'), or hex-encoded ('M').
6640 The function creates packet of the form
6641 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6643 where encoding of <DATA> is termined by PACKET_FORMAT.
6645 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6648 Returns the number of bytes transferred, or 0 (setting errno) for
6649 error. Only transfer a single packet. */
6652 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6653 const gdb_byte
*myaddr
, ssize_t len
,
6654 char packet_format
, int use_length
)
6656 struct remote_state
*rs
= get_remote_state ();
6666 if (packet_format
!= 'X' && packet_format
!= 'M')
6667 internal_error (__FILE__
, __LINE__
,
6668 _("remote_write_bytes_aux: bad packet format"));
6673 payload_size
= get_memory_write_packet_size ();
6675 /* The packet buffer will be large enough for the payload;
6676 get_memory_packet_size ensures this. */
6679 /* Compute the size of the actual payload by subtracting out the
6680 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6682 payload_size
-= strlen ("$,:#NN");
6684 /* The comma won't be used. */
6686 header_length
= strlen (header
);
6687 payload_size
-= header_length
;
6688 payload_size
-= hexnumlen (memaddr
);
6690 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6692 strcat (rs
->buf
, header
);
6693 p
= rs
->buf
+ strlen (header
);
6695 /* Compute a best guess of the number of bytes actually transfered. */
6696 if (packet_format
== 'X')
6698 /* Best guess at number of bytes that will fit. */
6699 todo
= min (len
, payload_size
);
6701 payload_size
-= hexnumlen (todo
);
6702 todo
= min (todo
, payload_size
);
6706 /* Num bytes that will fit. */
6707 todo
= min (len
, payload_size
/ 2);
6709 payload_size
-= hexnumlen (todo
);
6710 todo
= min (todo
, payload_size
/ 2);
6714 internal_error (__FILE__
, __LINE__
,
6715 _("minimum packet size too small to write data"));
6717 /* If we already need another packet, then try to align the end
6718 of this packet to a useful boundary. */
6719 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6720 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6722 /* Append "<memaddr>". */
6723 memaddr
= remote_address_masked (memaddr
);
6724 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6731 /* Append <len>. Retain the location/size of <len>. It may need to
6732 be adjusted once the packet body has been created. */
6734 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6742 /* Append the packet body. */
6743 if (packet_format
== 'X')
6745 /* Binary mode. Send target system values byte by byte, in
6746 increasing byte addresses. Only escape certain critical
6748 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6749 &nr_bytes
, payload_size
);
6751 /* If not all TODO bytes fit, then we'll need another packet. Make
6752 a second try to keep the end of the packet aligned. Don't do
6753 this if the packet is tiny. */
6754 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6758 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6760 if (new_nr_bytes
!= nr_bytes
)
6761 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6762 (gdb_byte
*) p
, &nr_bytes
,
6766 p
+= payload_length
;
6767 if (use_length
&& nr_bytes
< todo
)
6769 /* Escape chars have filled up the buffer prematurely,
6770 and we have actually sent fewer bytes than planned.
6771 Fix-up the length field of the packet. Use the same
6772 number of characters as before. */
6773 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6774 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6779 /* Normal mode: Send target system values byte by byte, in
6780 increasing byte addresses. Each byte is encoded as a two hex
6782 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6786 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6787 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6789 if (rs
->buf
[0] == 'E')
6791 /* There is no correspondance between what the remote protocol
6792 uses for errors and errno codes. We would like a cleaner way
6793 of representing errors (big enough to include errno codes,
6794 bfd_error codes, and others). But for now just return EIO. */
6799 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6800 fewer bytes than we'd planned. */
6804 /* Write memory data directly to the remote machine.
6805 This does not inform the data cache; the data cache uses this.
6806 MEMADDR is the address in the remote memory space.
6807 MYADDR is the address of the buffer in our space.
6808 LEN is the number of bytes.
6810 Returns number of bytes transferred, or 0 (setting errno) for
6811 error. Only transfer a single packet. */
6814 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6816 char *packet_format
= 0;
6818 /* Check whether the target supports binary download. */
6819 check_binary_download (memaddr
);
6821 switch (remote_protocol_packets
[PACKET_X
].support
)
6824 packet_format
= "X";
6826 case PACKET_DISABLE
:
6827 packet_format
= "M";
6829 case PACKET_SUPPORT_UNKNOWN
:
6830 internal_error (__FILE__
, __LINE__
,
6831 _("remote_write_bytes: bad internal state"));
6833 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6836 return remote_write_bytes_aux (packet_format
,
6837 memaddr
, myaddr
, len
, packet_format
[0], 1);
6840 /* Read memory data directly from the remote machine.
6841 This does not use the data cache; the data cache uses this.
6842 MEMADDR is the address in the remote memory space.
6843 MYADDR is the address of the buffer in our space.
6844 LEN is the number of bytes.
6846 Returns number of bytes transferred, or 0 for error. */
6849 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6851 struct remote_state
*rs
= get_remote_state ();
6852 int max_buf_size
; /* Max size of packet output buffer. */
6860 max_buf_size
= get_memory_read_packet_size ();
6861 /* The packet buffer will be large enough for the payload;
6862 get_memory_packet_size ensures this. */
6864 /* Number if bytes that will fit. */
6865 todo
= min (len
, max_buf_size
/ 2);
6867 /* Construct "m"<memaddr>","<len>". */
6868 memaddr
= remote_address_masked (memaddr
);
6871 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6873 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6876 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6877 if (rs
->buf
[0] == 'E'
6878 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6879 && rs
->buf
[3] == '\0')
6881 /* There is no correspondance between what the remote protocol
6882 uses for errors and errno codes. We would like a cleaner way
6883 of representing errors (big enough to include errno codes,
6884 bfd_error codes, and others). But for now just return
6889 /* Reply describes memory byte by byte, each byte encoded as two hex
6892 i
= hex2bin (p
, myaddr
, todo
);
6893 /* Return what we have. Let higher layers handle partial reads. */
6898 /* Read or write LEN bytes from inferior memory at MEMADDR,
6899 transferring to or from debugger address BUFFER. Write to inferior
6900 if SHOULD_WRITE is nonzero. Returns length of data written or
6901 read; 0 for error. TARGET is unused. */
6904 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6905 int should_write
, struct mem_attrib
*attrib
,
6906 struct target_ops
*target
)
6910 set_remote_traceframe ();
6911 set_general_thread (inferior_ptid
);
6914 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6916 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6921 /* Sends a packet with content determined by the printf format string
6922 FORMAT and the remaining arguments, then gets the reply. Returns
6923 whether the packet was a success, a failure, or unknown. */
6925 static enum packet_result
6926 remote_send_printf (const char *format
, ...)
6928 struct remote_state
*rs
= get_remote_state ();
6929 int max_size
= get_remote_packet_size ();
6932 va_start (ap
, format
);
6935 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6936 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6938 if (putpkt (rs
->buf
) < 0)
6939 error (_("Communication problem with target."));
6942 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6944 return packet_check_result (rs
->buf
);
6948 restore_remote_timeout (void *p
)
6950 int value
= *(int *)p
;
6952 remote_timeout
= value
;
6955 /* Flash writing can take quite some time. We'll set
6956 effectively infinite timeout for flash operations.
6957 In future, we'll need to decide on a better approach. */
6958 static const int remote_flash_timeout
= 1000;
6961 remote_flash_erase (struct target_ops
*ops
,
6962 ULONGEST address
, LONGEST length
)
6964 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
6965 int saved_remote_timeout
= remote_timeout
;
6966 enum packet_result ret
;
6967 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6968 &saved_remote_timeout
);
6970 remote_timeout
= remote_flash_timeout
;
6972 ret
= remote_send_printf ("vFlashErase:%s,%s",
6973 phex (address
, addr_size
),
6977 case PACKET_UNKNOWN
:
6978 error (_("Remote target does not support flash erase"));
6980 error (_("Error erasing flash with vFlashErase packet"));
6985 do_cleanups (back_to
);
6989 remote_flash_write (struct target_ops
*ops
,
6990 ULONGEST address
, LONGEST length
,
6991 const gdb_byte
*data
)
6993 int saved_remote_timeout
= remote_timeout
;
6995 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6996 &saved_remote_timeout
);
6998 remote_timeout
= remote_flash_timeout
;
6999 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
7000 do_cleanups (back_to
);
7006 remote_flash_done (struct target_ops
*ops
)
7008 int saved_remote_timeout
= remote_timeout
;
7010 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7011 &saved_remote_timeout
);
7013 remote_timeout
= remote_flash_timeout
;
7014 ret
= remote_send_printf ("vFlashDone");
7015 do_cleanups (back_to
);
7019 case PACKET_UNKNOWN
:
7020 error (_("Remote target does not support vFlashDone"));
7022 error (_("Error finishing flash operation"));
7029 remote_files_info (struct target_ops
*ignore
)
7031 puts_filtered ("Debugging a target over a serial line.\n");
7034 /* Stuff for dealing with the packets which are part of this protocol.
7035 See comment at top of file for details. */
7037 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7038 error to higher layers. Called when a serial error is detected.
7039 The exception message is STRING, followed by a colon and a blank,
7040 the system error message for errno at function entry and final dot
7041 for output compatibility with throw_perror_with_name. */
7044 unpush_and_perror (const char *string
)
7046 int saved_errno
= errno
;
7048 remote_unpush_target ();
7049 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7050 safe_strerror (saved_errno
));
7053 /* Read a single character from the remote end. */
7056 readchar (int timeout
)
7060 ch
= serial_readchar (remote_desc
, timeout
);
7065 switch ((enum serial_rc
) ch
)
7068 remote_unpush_target ();
7069 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7072 unpush_and_perror (_("Remote communication error. "
7073 "Target disconnected."));
7075 case SERIAL_TIMEOUT
:
7081 /* Wrapper for serial_write that closes the target and throws if
7085 remote_serial_write (const char *str
, int len
)
7087 if (serial_write (remote_desc
, str
, len
))
7089 unpush_and_perror (_("Remote communication error. "
7090 "Target disconnected."));
7094 /* Send the command in *BUF to the remote machine, and read the reply
7095 into *BUF. Report an error if we get an error reply. Resize
7096 *BUF using xrealloc if necessary to hold the result, and update
7100 remote_send (char **buf
,
7104 getpkt (buf
, sizeof_buf
, 0);
7106 if ((*buf
)[0] == 'E')
7107 error (_("Remote failure reply: %s"), *buf
);
7110 /* Return a pointer to an xmalloc'ed string representing an escaped
7111 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7112 etc. The caller is responsible for releasing the returned
7116 escape_buffer (const char *buf
, int n
)
7118 struct cleanup
*old_chain
;
7119 struct ui_file
*stb
;
7122 stb
= mem_fileopen ();
7123 old_chain
= make_cleanup_ui_file_delete (stb
);
7125 fputstrn_unfiltered (buf
, n
, 0, stb
);
7126 str
= ui_file_xstrdup (stb
, NULL
);
7127 do_cleanups (old_chain
);
7131 /* Display a null-terminated packet on stdout, for debugging, using C
7135 print_packet (char *buf
)
7137 puts_filtered ("\"");
7138 fputstr_filtered (buf
, '"', gdb_stdout
);
7139 puts_filtered ("\"");
7145 return putpkt_binary (buf
, strlen (buf
));
7148 /* Send a packet to the remote machine, with error checking. The data
7149 of the packet is in BUF. The string in BUF can be at most
7150 get_remote_packet_size () - 5 to account for the $, # and checksum,
7151 and for a possible /0 if we are debugging (remote_debug) and want
7152 to print the sent packet as a string. */
7155 putpkt_binary (char *buf
, int cnt
)
7157 struct remote_state
*rs
= get_remote_state ();
7159 unsigned char csum
= 0;
7160 char *buf2
= alloca (cnt
+ 6);
7167 /* Catch cases like trying to read memory or listing threads while
7168 we're waiting for a stop reply. The remote server wouldn't be
7169 ready to handle this request, so we'd hang and timeout. We don't
7170 have to worry about this in synchronous mode, because in that
7171 case it's not possible to issue a command while the target is
7172 running. This is not a problem in non-stop mode, because in that
7173 case, the stub is always ready to process serial input. */
7174 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7175 error (_("Cannot execute this command while the target is running."));
7177 /* We're sending out a new packet. Make sure we don't look at a
7178 stale cached response. */
7179 rs
->cached_wait_status
= 0;
7181 /* Copy the packet into buffer BUF2, encapsulating it
7182 and giving it a checksum. */
7187 for (i
= 0; i
< cnt
; i
++)
7193 *p
++ = tohex ((csum
>> 4) & 0xf);
7194 *p
++ = tohex (csum
& 0xf);
7196 /* Send it over and over until we get a positive ack. */
7200 int started_error_output
= 0;
7204 struct cleanup
*old_chain
;
7208 str
= escape_buffer (buf2
, p
- buf2
);
7209 old_chain
= make_cleanup (xfree
, str
);
7210 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7211 gdb_flush (gdb_stdlog
);
7212 do_cleanups (old_chain
);
7214 remote_serial_write (buf2
, p
- buf2
);
7216 /* If this is a no acks version of the remote protocol, send the
7217 packet and move on. */
7221 /* Read until either a timeout occurs (-2) or '+' is read.
7222 Handle any notification that arrives in the mean time. */
7225 ch
= readchar (remote_timeout
);
7233 case SERIAL_TIMEOUT
:
7236 if (started_error_output
)
7238 putchar_unfiltered ('\n');
7239 started_error_output
= 0;
7248 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7252 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7254 case SERIAL_TIMEOUT
:
7258 break; /* Retransmit buffer. */
7262 fprintf_unfiltered (gdb_stdlog
,
7263 "Packet instead of Ack, ignoring it\n");
7264 /* It's probably an old response sent because an ACK
7265 was lost. Gobble up the packet and ack it so it
7266 doesn't get retransmitted when we resend this
7269 remote_serial_write ("+", 1);
7270 continue; /* Now, go look for +. */
7277 /* If we got a notification, handle it, and go back to looking
7279 /* We've found the start of a notification. Now
7280 collect the data. */
7281 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7286 struct cleanup
*old_chain
;
7289 str
= escape_buffer (rs
->buf
, val
);
7290 old_chain
= make_cleanup (xfree
, str
);
7291 fprintf_unfiltered (gdb_stdlog
,
7292 " Notification received: %s\n",
7294 do_cleanups (old_chain
);
7296 handle_notification (rs
->buf
);
7297 /* We're in sync now, rewait for the ack. */
7304 if (!started_error_output
)
7306 started_error_output
= 1;
7307 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7309 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7310 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7319 if (!started_error_output
)
7321 started_error_output
= 1;
7322 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7324 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7328 break; /* Here to retransmit. */
7332 /* This is wrong. If doing a long backtrace, the user should be
7333 able to get out next time we call QUIT, without anything as
7334 violent as interrupt_query. If we want to provide a way out of
7335 here without getting to the next QUIT, it should be based on
7336 hitting ^C twice as in remote_wait. */
7347 /* Come here after finding the start of a frame when we expected an
7348 ack. Do our best to discard the rest of this packet. */
7357 c
= readchar (remote_timeout
);
7360 case SERIAL_TIMEOUT
:
7361 /* Nothing we can do. */
7364 /* Discard the two bytes of checksum and stop. */
7365 c
= readchar (remote_timeout
);
7367 c
= readchar (remote_timeout
);
7370 case '*': /* Run length encoding. */
7371 /* Discard the repeat count. */
7372 c
= readchar (remote_timeout
);
7377 /* A regular character. */
7383 /* Come here after finding the start of the frame. Collect the rest
7384 into *BUF, verifying the checksum, length, and handling run-length
7385 compression. NUL terminate the buffer. If there is not enough room,
7386 expand *BUF using xrealloc.
7388 Returns -1 on error, number of characters in buffer (ignoring the
7389 trailing NULL) on success. (could be extended to return one of the
7390 SERIAL status indications). */
7393 read_frame (char **buf_p
,
7400 struct remote_state
*rs
= get_remote_state ();
7407 c
= readchar (remote_timeout
);
7410 case SERIAL_TIMEOUT
:
7412 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7416 fputs_filtered ("Saw new packet start in middle of old one\n",
7418 return -1; /* Start a new packet, count retries. */
7421 unsigned char pktcsum
;
7427 check_0
= readchar (remote_timeout
);
7429 check_1
= readchar (remote_timeout
);
7431 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7434 fputs_filtered ("Timeout in checksum, retrying\n",
7438 else if (check_0
< 0 || check_1
< 0)
7441 fputs_filtered ("Communication error in checksum\n",
7446 /* Don't recompute the checksum; with no ack packets we
7447 don't have any way to indicate a packet retransmission
7452 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7453 if (csum
== pktcsum
)
7458 struct cleanup
*old_chain
;
7461 str
= escape_buffer (buf
, bc
);
7462 old_chain
= make_cleanup (xfree
, str
);
7463 fprintf_unfiltered (gdb_stdlog
,
7464 "Bad checksum, sentsum=0x%x, "
7465 "csum=0x%x, buf=%s\n",
7466 pktcsum
, csum
, str
);
7467 do_cleanups (old_chain
);
7469 /* Number of characters in buffer ignoring trailing
7473 case '*': /* Run length encoding. */
7478 c
= readchar (remote_timeout
);
7480 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7482 /* The character before ``*'' is repeated. */
7484 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7486 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7488 /* Make some more room in the buffer. */
7489 *sizeof_buf
+= repeat
;
7490 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7494 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7500 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7504 if (bc
>= *sizeof_buf
- 1)
7506 /* Make some more room in the buffer. */
7508 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7519 /* Read a packet from the remote machine, with error checking, and
7520 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7521 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7522 rather than timing out; this is used (in synchronous mode) to wait
7523 for a target that is is executing user code to stop. */
7524 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7525 don't have to change all the calls to getpkt to deal with the
7526 return value, because at the moment I don't know what the right
7527 thing to do it for those. */
7535 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7539 /* Read a packet from the remote machine, with error checking, and
7540 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7541 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7542 rather than timing out; this is used (in synchronous mode) to wait
7543 for a target that is is executing user code to stop. If FOREVER ==
7544 0, this function is allowed to time out gracefully and return an
7545 indication of this to the caller. Otherwise return the number of
7546 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7547 enough reason to return to the caller. *IS_NOTIF is an output
7548 boolean that indicates whether *BUF holds a notification or not
7549 (a regular packet). */
7552 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7553 int expecting_notif
, int *is_notif
)
7555 struct remote_state
*rs
= get_remote_state ();
7561 /* We're reading a new response. Make sure we don't look at a
7562 previously cached response. */
7563 rs
->cached_wait_status
= 0;
7565 strcpy (*buf
, "timeout");
7568 timeout
= watchdog
> 0 ? watchdog
: -1;
7569 else if (expecting_notif
)
7570 timeout
= 0; /* There should already be a char in the buffer. If
7573 timeout
= remote_timeout
;
7577 /* Process any number of notifications, and then return when
7581 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7583 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7585 /* This can loop forever if the remote side sends us
7586 characters continuously, but if it pauses, we'll get
7587 SERIAL_TIMEOUT from readchar because of timeout. Then
7588 we'll count that as a retry.
7590 Note that even when forever is set, we will only wait
7591 forever prior to the start of a packet. After that, we
7592 expect characters to arrive at a brisk pace. They should
7593 show up within remote_timeout intervals. */
7595 c
= readchar (timeout
);
7596 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7598 if (c
== SERIAL_TIMEOUT
)
7600 if (expecting_notif
)
7601 return -1; /* Don't complain, it's normal to not get
7602 anything in this case. */
7604 if (forever
) /* Watchdog went off? Kill the target. */
7607 remote_unpush_target ();
7608 throw_error (TARGET_CLOSE_ERROR
,
7609 _("Watchdog timeout has expired. "
7610 "Target detached."));
7613 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7617 /* We've found the start of a packet or notification.
7618 Now collect the data. */
7619 val
= read_frame (buf
, sizeof_buf
);
7624 remote_serial_write ("-", 1);
7627 if (tries
> MAX_TRIES
)
7629 /* We have tried hard enough, and just can't receive the
7630 packet/notification. Give up. */
7631 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7633 /* Skip the ack char if we're in no-ack mode. */
7634 if (!rs
->noack_mode
)
7635 remote_serial_write ("+", 1);
7639 /* If we got an ordinary packet, return that to our caller. */
7644 struct cleanup
*old_chain
;
7647 str
= escape_buffer (*buf
, val
);
7648 old_chain
= make_cleanup (xfree
, str
);
7649 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7650 do_cleanups (old_chain
);
7653 /* Skip the ack char if we're in no-ack mode. */
7654 if (!rs
->noack_mode
)
7655 remote_serial_write ("+", 1);
7656 if (is_notif
!= NULL
)
7661 /* If we got a notification, handle it, and go back to looking
7665 gdb_assert (c
== '%');
7669 struct cleanup
*old_chain
;
7672 str
= escape_buffer (*buf
, val
);
7673 old_chain
= make_cleanup (xfree
, str
);
7674 fprintf_unfiltered (gdb_stdlog
,
7675 " Notification received: %s\n",
7677 do_cleanups (old_chain
);
7679 if (is_notif
!= NULL
)
7682 handle_notification (*buf
);
7684 /* Notifications require no acknowledgement. */
7686 if (expecting_notif
)
7693 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7695 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7699 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7702 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7707 /* A helper function that just calls putpkt; for type correctness. */
7710 putpkt_for_catch_errors (void *arg
)
7712 return putpkt (arg
);
7716 remote_kill (struct target_ops
*ops
)
7718 /* Use catch_errors so the user can quit from gdb even when we
7719 aren't on speaking terms with the remote system. */
7720 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7722 /* Don't wait for it to die. I'm not really sure it matters whether
7723 we do or not. For the existing stubs, kill is a noop. */
7724 target_mourn_inferior ();
7728 remote_vkill (int pid
, struct remote_state
*rs
)
7730 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7733 /* Tell the remote target to detach. */
7734 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7738 if (packet_ok (rs
->buf
,
7739 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7741 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7748 extended_remote_kill (struct target_ops
*ops
)
7751 int pid
= ptid_get_pid (inferior_ptid
);
7752 struct remote_state
*rs
= get_remote_state ();
7754 res
= remote_vkill (pid
, rs
);
7755 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7757 /* Don't try 'k' on a multi-process aware stub -- it has no way
7758 to specify the pid. */
7762 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7763 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7766 /* Don't wait for it to die. I'm not really sure it matters whether
7767 we do or not. For the existing stubs, kill is a noop. */
7773 error (_("Can't kill process"));
7775 target_mourn_inferior ();
7779 remote_mourn (struct target_ops
*ops
)
7781 remote_mourn_1 (ops
);
7784 /* Worker function for remote_mourn. */
7786 remote_mourn_1 (struct target_ops
*target
)
7788 unpush_target (target
);
7790 /* remote_close takes care of doing most of the clean up. */
7791 generic_mourn_inferior ();
7795 extended_remote_mourn_1 (struct target_ops
*target
)
7797 struct remote_state
*rs
= get_remote_state ();
7799 /* In case we got here due to an error, but we're going to stay
7801 rs
->waiting_for_stop_reply
= 0;
7803 /* If the current general thread belonged to the process we just
7804 detached from or has exited, the remote side current general
7805 thread becomes undefined. Considering a case like this:
7807 - We just got here due to a detach.
7808 - The process that we're detaching from happens to immediately
7809 report a global breakpoint being hit in non-stop mode, in the
7810 same thread we had selected before.
7811 - GDB attaches to this process again.
7812 - This event happens to be the next event we handle.
7814 GDB would consider that the current general thread didn't need to
7815 be set on the stub side (with Hg), since for all it knew,
7816 GENERAL_THREAD hadn't changed.
7818 Notice that although in all-stop mode, the remote server always
7819 sets the current thread to the thread reporting the stop event,
7820 that doesn't happen in non-stop mode; in non-stop, the stub *must
7821 not* change the current thread when reporting a breakpoint hit,
7822 due to the decoupling of event reporting and event handling.
7824 To keep things simple, we always invalidate our notion of the
7826 record_currthread (minus_one_ptid
);
7828 /* Unlike "target remote", we do not want to unpush the target; then
7829 the next time the user says "run", we won't be connected. */
7831 /* Call common code to mark the inferior as not running. */
7832 generic_mourn_inferior ();
7834 if (!have_inferiors ())
7836 if (!remote_multi_process_p (rs
))
7838 /* Check whether the target is running now - some remote stubs
7839 automatically restart after kill. */
7841 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7843 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7845 /* Assume that the target has been restarted. Set
7846 inferior_ptid so that bits of core GDB realizes
7847 there's something here, e.g., so that the user can
7848 say "kill" again. */
7849 inferior_ptid
= magic_null_ptid
;
7856 extended_remote_mourn (struct target_ops
*ops
)
7858 extended_remote_mourn_1 (ops
);
7862 extended_remote_supports_disable_randomization (void)
7864 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7869 extended_remote_disable_randomization (int val
)
7871 struct remote_state
*rs
= get_remote_state ();
7874 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7877 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7879 error (_("Target does not support QDisableRandomization."));
7880 if (strcmp (reply
, "OK") != 0)
7881 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7885 extended_remote_run (char *args
)
7887 struct remote_state
*rs
= get_remote_state ();
7890 /* If the user has disabled vRun support, or we have detected that
7891 support is not available, do not try it. */
7892 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7895 strcpy (rs
->buf
, "vRun;");
7896 len
= strlen (rs
->buf
);
7898 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7899 error (_("Remote file name too long for run packet"));
7900 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7902 gdb_assert (args
!= NULL
);
7905 struct cleanup
*back_to
;
7909 argv
= gdb_buildargv (args
);
7910 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7911 for (i
= 0; argv
[i
] != NULL
; i
++)
7913 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7914 error (_("Argument list too long for run packet"));
7915 rs
->buf
[len
++] = ';';
7916 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7918 do_cleanups (back_to
);
7921 rs
->buf
[len
++] = '\0';
7924 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7926 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7928 /* We have a wait response. All is well. */
7931 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7932 /* It wasn't disabled before, but it is now. */
7936 if (remote_exec_file
[0] == '\0')
7937 error (_("Running the default executable on the remote target failed; "
7938 "try \"set remote exec-file\"?"));
7940 error (_("Running \"%s\" on the remote target failed"),
7945 /* In the extended protocol we want to be able to do things like
7946 "run" and have them basically work as expected. So we need
7947 a special create_inferior function. We support changing the
7948 executable file and the command line arguments, but not the
7952 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7953 char **env
, int from_tty
)
7957 struct remote_state
*rs
= get_remote_state ();
7959 /* If running asynchronously, register the target file descriptor
7960 with the event loop. */
7961 if (target_can_async_p ())
7962 target_async (inferior_event_handler
, 0);
7964 /* Disable address space randomization if requested (and supported). */
7965 if (extended_remote_supports_disable_randomization ())
7966 extended_remote_disable_randomization (disable_randomization
);
7968 /* Now restart the remote server. */
7969 run_worked
= extended_remote_run (args
) != -1;
7972 /* vRun was not supported. Fail if we need it to do what the
7974 if (remote_exec_file
[0])
7975 error (_("Remote target does not support \"set remote exec-file\""));
7977 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7979 /* Fall back to "R". */
7980 extended_remote_restart ();
7983 if (!have_inferiors ())
7985 /* Clean up from the last time we ran, before we mark the target
7986 running again. This will mark breakpoints uninserted, and
7987 get_offsets may insert breakpoints. */
7988 init_thread_list ();
7989 init_wait_for_inferior ();
7992 /* vRun's success return is a stop reply. */
7993 stop_reply
= run_worked
? rs
->buf
: NULL
;
7994 add_current_inferior_and_thread (stop_reply
);
7996 /* Get updated offsets, if the stub uses qOffsets. */
8001 extended_remote_create_inferior (struct target_ops
*ops
,
8002 char *exec_file
, char *args
,
8003 char **env
, int from_tty
)
8005 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8009 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8010 the list of conditions (in agent expression bytecode format), if any, the
8011 target needs to evaluate. The output is placed into the packet buffer
8012 started from BUF and ended at BUF_END. */
8015 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8016 struct bp_target_info
*bp_tgt
, char *buf
,
8019 struct agent_expr
*aexpr
= NULL
;
8022 char *buf_start
= buf
;
8024 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8027 buf
+= strlen (buf
);
8028 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8031 /* Send conditions to the target and free the vector. */
8033 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8036 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8037 buf
+= strlen (buf
);
8038 for (i
= 0; i
< aexpr
->len
; ++i
)
8039 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8043 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8048 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8049 struct bp_target_info
*bp_tgt
, char *buf
)
8051 struct agent_expr
*aexpr
= NULL
;
8054 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8057 buf
+= strlen (buf
);
8059 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8060 buf
+= strlen (buf
);
8062 /* Concatenate all the agent expressions that are commands into the
8065 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8068 sprintf (buf
, "X%x,", aexpr
->len
);
8069 buf
+= strlen (buf
);
8070 for (i
= 0; i
< aexpr
->len
; ++i
)
8071 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8075 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8078 /* Insert a breakpoint. On targets that have software breakpoint
8079 support, we ask the remote target to do the work; on targets
8080 which don't, we insert a traditional memory breakpoint. */
8083 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8084 struct bp_target_info
*bp_tgt
)
8086 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8087 If it succeeds, then set the support to PACKET_ENABLE. If it
8088 fails, and the user has explicitly requested the Z support then
8089 report an error, otherwise, mark it disabled and go on. */
8091 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8093 CORE_ADDR addr
= bp_tgt
->placed_address
;
8094 struct remote_state
*rs
;
8097 struct condition_list
*cond
= NULL
;
8099 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8101 rs
= get_remote_state ();
8103 endbuf
= rs
->buf
+ get_remote_packet_size ();
8108 addr
= (ULONGEST
) remote_address_masked (addr
);
8109 p
+= hexnumstr (p
, addr
);
8110 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8112 if (remote_supports_cond_breakpoints ())
8113 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8115 if (remote_can_run_breakpoint_commands ())
8116 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8119 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8121 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8126 bp_tgt
->placed_address
= addr
;
8127 bp_tgt
->placed_size
= bpsize
;
8129 case PACKET_UNKNOWN
:
8134 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8138 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8139 struct bp_target_info
*bp_tgt
)
8141 CORE_ADDR addr
= bp_tgt
->placed_address
;
8142 struct remote_state
*rs
= get_remote_state ();
8144 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8147 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8153 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8154 p
+= hexnumstr (p
, addr
);
8155 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8158 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8160 return (rs
->buf
[0] == 'E');
8163 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8167 watchpoint_to_Z_packet (int type
)
8172 return Z_PACKET_WRITE_WP
;
8175 return Z_PACKET_READ_WP
;
8178 return Z_PACKET_ACCESS_WP
;
8181 internal_error (__FILE__
, __LINE__
,
8182 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8187 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8188 struct expression
*cond
)
8190 struct remote_state
*rs
= get_remote_state ();
8191 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8193 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8195 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8198 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8199 p
= strchr (rs
->buf
, '\0');
8200 addr
= remote_address_masked (addr
);
8201 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8202 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8205 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8207 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8211 case PACKET_UNKNOWN
:
8216 internal_error (__FILE__
, __LINE__
,
8217 _("remote_insert_watchpoint: reached end of function"));
8221 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8222 CORE_ADDR start
, int length
)
8224 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8226 return diff
< length
;
8231 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8232 struct expression
*cond
)
8234 struct remote_state
*rs
= get_remote_state ();
8235 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8237 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8239 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8242 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8243 p
= strchr (rs
->buf
, '\0');
8244 addr
= remote_address_masked (addr
);
8245 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8246 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8248 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8250 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8253 case PACKET_UNKNOWN
:
8258 internal_error (__FILE__
, __LINE__
,
8259 _("remote_remove_watchpoint: reached end of function"));
8263 int remote_hw_watchpoint_limit
= -1;
8264 int remote_hw_watchpoint_length_limit
= -1;
8265 int remote_hw_breakpoint_limit
= -1;
8268 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8270 if (remote_hw_watchpoint_length_limit
== 0)
8272 else if (remote_hw_watchpoint_length_limit
< 0)
8274 else if (len
<= remote_hw_watchpoint_length_limit
)
8281 remote_check_watch_resources (int type
, int cnt
, int ot
)
8283 if (type
== bp_hardware_breakpoint
)
8285 if (remote_hw_breakpoint_limit
== 0)
8287 else if (remote_hw_breakpoint_limit
< 0)
8289 else if (cnt
<= remote_hw_breakpoint_limit
)
8294 if (remote_hw_watchpoint_limit
== 0)
8296 else if (remote_hw_watchpoint_limit
< 0)
8300 else if (cnt
<= remote_hw_watchpoint_limit
)
8307 remote_stopped_by_watchpoint (void)
8309 return remote_stopped_by_watchpoint_p
;
8313 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8317 if (remote_stopped_by_watchpoint ())
8319 *addr_p
= remote_watch_data_address
;
8328 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8329 struct bp_target_info
*bp_tgt
)
8332 struct remote_state
*rs
;
8336 /* The length field should be set to the size of a breakpoint
8337 instruction, even though we aren't inserting one ourselves. */
8339 gdbarch_remote_breakpoint_from_pc
8340 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8342 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8345 rs
= get_remote_state ();
8347 endbuf
= rs
->buf
+ get_remote_packet_size ();
8353 addr
= remote_address_masked (bp_tgt
->placed_address
);
8354 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8355 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8357 if (remote_supports_cond_breakpoints ())
8358 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8360 if (remote_can_run_breakpoint_commands ())
8361 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8364 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8366 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8369 if (rs
->buf
[1] == '.')
8371 message
= strchr (rs
->buf
+ 2, '.');
8373 error (_("Remote failure reply: %s"), message
+ 1);
8376 case PACKET_UNKNOWN
:
8381 internal_error (__FILE__
, __LINE__
,
8382 _("remote_insert_hw_breakpoint: reached end of function"));
8387 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8388 struct bp_target_info
*bp_tgt
)
8391 struct remote_state
*rs
= get_remote_state ();
8393 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8395 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8402 addr
= remote_address_masked (bp_tgt
->placed_address
);
8403 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8404 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8407 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8409 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8412 case PACKET_UNKNOWN
:
8417 internal_error (__FILE__
, __LINE__
,
8418 _("remote_remove_hw_breakpoint: reached end of function"));
8421 /* Table used by the crc32 function to calcuate the checksum. */
8423 static unsigned long crc32_table
[256] =
8426 static unsigned long
8427 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8429 if (!crc32_table
[1])
8431 /* Initialize the CRC table and the decoding table. */
8435 for (i
= 0; i
< 256; i
++)
8437 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8438 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8445 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8451 /* Verify memory using the "qCRC:" request. */
8454 remote_verify_memory (struct target_ops
*ops
,
8455 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8457 struct remote_state
*rs
= get_remote_state ();
8458 unsigned long host_crc
, target_crc
;
8461 /* FIXME: assumes lma can fit into long. */
8462 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8463 (long) lma
, (long) size
);
8466 /* Be clever; compute the host_crc before waiting for target
8468 host_crc
= crc32 (data
, size
, 0xffffffff);
8470 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8471 if (rs
->buf
[0] == 'E')
8474 if (rs
->buf
[0] != 'C')
8475 error (_("remote target does not support this operation"));
8477 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8478 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8480 return (host_crc
== target_crc
);
8483 /* compare-sections command
8485 With no arguments, compares each loadable section in the exec bfd
8486 with the same memory range on the target, and reports mismatches.
8487 Useful for verifying the image on the target against the exec file. */
8490 compare_sections_command (char *args
, int from_tty
)
8493 struct cleanup
*old_chain
;
8495 const char *sectname
;
8503 error (_("command cannot be used without an exec file"));
8505 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8507 if (!(s
->flags
& SEC_LOAD
))
8508 continue; /* Skip non-loadable section. */
8510 size
= bfd_get_section_size (s
);
8512 continue; /* Skip zero-length section. */
8514 sectname
= bfd_get_section_name (exec_bfd
, s
);
8515 if (args
&& strcmp (args
, sectname
) != 0)
8516 continue; /* Not the section selected by user. */
8518 matched
= 1; /* Do this section. */
8521 sectdata
= xmalloc (size
);
8522 old_chain
= make_cleanup (xfree
, sectdata
);
8523 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8525 res
= target_verify_memory (sectdata
, lma
, size
);
8528 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8529 paddress (target_gdbarch (), lma
),
8530 paddress (target_gdbarch (), lma
+ size
));
8532 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8533 paddress (target_gdbarch (), lma
),
8534 paddress (target_gdbarch (), lma
+ size
));
8536 printf_filtered ("matched.\n");
8539 printf_filtered ("MIS-MATCHED!\n");
8543 do_cleanups (old_chain
);
8546 warning (_("One or more sections of the remote executable does not match\n\
8547 the loaded file\n"));
8548 if (args
&& !matched
)
8549 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8552 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8553 into remote target. The number of bytes written to the remote
8554 target is returned, or -1 for error. */
8557 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8558 const char *annex
, const gdb_byte
*writebuf
,
8559 ULONGEST offset
, LONGEST len
,
8560 struct packet_config
*packet
)
8564 struct remote_state
*rs
= get_remote_state ();
8565 int max_size
= get_memory_write_packet_size ();
8567 if (packet
->support
== PACKET_DISABLE
)
8570 /* Insert header. */
8571 i
= snprintf (rs
->buf
, max_size
,
8572 "qXfer:%s:write:%s:%s:",
8573 object_name
, annex
? annex
: "",
8574 phex_nz (offset
, sizeof offset
));
8575 max_size
-= (i
+ 1);
8577 /* Escape as much data as fits into rs->buf. */
8578 buf_len
= remote_escape_output
8579 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8581 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8582 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8583 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8586 unpack_varlen_hex (rs
->buf
, &n
);
8590 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8591 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8592 number of bytes read is returned, or 0 for EOF, or -1 for error.
8593 The number of bytes read may be less than LEN without indicating an
8594 EOF. PACKET is checked and updated to indicate whether the remote
8595 target supports this object. */
8598 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8600 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8601 struct packet_config
*packet
)
8603 static char *finished_object
;
8604 static char *finished_annex
;
8605 static ULONGEST finished_offset
;
8607 struct remote_state
*rs
= get_remote_state ();
8608 LONGEST i
, n
, packet_len
;
8610 if (packet
->support
== PACKET_DISABLE
)
8613 /* Check whether we've cached an end-of-object packet that matches
8615 if (finished_object
)
8617 if (strcmp (object_name
, finished_object
) == 0
8618 && strcmp (annex
? annex
: "", finished_annex
) == 0
8619 && offset
== finished_offset
)
8622 /* Otherwise, we're now reading something different. Discard
8624 xfree (finished_object
);
8625 xfree (finished_annex
);
8626 finished_object
= NULL
;
8627 finished_annex
= NULL
;
8630 /* Request only enough to fit in a single packet. The actual data
8631 may not, since we don't know how much of it will need to be escaped;
8632 the target is free to respond with slightly less data. We subtract
8633 five to account for the response type and the protocol frame. */
8634 n
= min (get_remote_packet_size () - 5, len
);
8635 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8636 object_name
, annex
? annex
: "",
8637 phex_nz (offset
, sizeof offset
),
8638 phex_nz (n
, sizeof n
));
8639 i
= putpkt (rs
->buf
);
8644 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8645 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8648 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8649 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8651 /* 'm' means there is (or at least might be) more data after this
8652 batch. That does not make sense unless there's at least one byte
8653 of data in this reply. */
8654 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8655 error (_("Remote qXfer reply contained no data."));
8657 /* Got some data. */
8658 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8659 packet_len
- 1, readbuf
, n
);
8661 /* 'l' is an EOF marker, possibly including a final block of data,
8662 or possibly empty. If we have the final block of a non-empty
8663 object, record this fact to bypass a subsequent partial read. */
8664 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8666 finished_object
= xstrdup (object_name
);
8667 finished_annex
= xstrdup (annex
? annex
: "");
8668 finished_offset
= offset
+ i
;
8675 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8676 const char *annex
, gdb_byte
*readbuf
,
8677 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8679 struct remote_state
*rs
;
8684 set_remote_traceframe ();
8685 set_general_thread (inferior_ptid
);
8687 rs
= get_remote_state ();
8689 /* Handle memory using the standard memory routines. */
8690 if (object
== TARGET_OBJECT_MEMORY
)
8696 /* If the remote target is connected but not running, we should
8697 pass this request down to a lower stratum (e.g. the executable
8699 if (!target_has_execution
)
8702 if (writebuf
!= NULL
)
8703 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8705 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8709 else if (xfered
== 0 && errno
== 0)
8715 /* Handle SPU memory using qxfer packets. */
8716 if (object
== TARGET_OBJECT_SPU
)
8719 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8720 &remote_protocol_packets
8721 [PACKET_qXfer_spu_read
]);
8723 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8724 &remote_protocol_packets
8725 [PACKET_qXfer_spu_write
]);
8728 /* Handle extra signal info using qxfer packets. */
8729 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8732 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8733 &remote_protocol_packets
8734 [PACKET_qXfer_siginfo_read
]);
8736 return remote_write_qxfer (ops
, "siginfo", annex
,
8737 writebuf
, offset
, len
,
8738 &remote_protocol_packets
8739 [PACKET_qXfer_siginfo_write
]);
8742 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8745 return remote_read_qxfer (ops
, "statictrace", annex
,
8746 readbuf
, offset
, len
,
8747 &remote_protocol_packets
8748 [PACKET_qXfer_statictrace_read
]);
8753 /* Only handle flash writes. */
8754 if (writebuf
!= NULL
)
8760 case TARGET_OBJECT_FLASH
:
8761 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8765 else if (xfered
== 0 && errno
== 0)
8775 /* Map pre-existing objects onto letters. DO NOT do this for new
8776 objects!!! Instead specify new query packets. */
8779 case TARGET_OBJECT_AVR
:
8783 case TARGET_OBJECT_AUXV
:
8784 gdb_assert (annex
== NULL
);
8785 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8786 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8788 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8789 return remote_read_qxfer
8790 (ops
, "features", annex
, readbuf
, offset
, len
,
8791 &remote_protocol_packets
[PACKET_qXfer_features
]);
8793 case TARGET_OBJECT_LIBRARIES
:
8794 return remote_read_qxfer
8795 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8796 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8798 case TARGET_OBJECT_LIBRARIES_SVR4
:
8799 return remote_read_qxfer
8800 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8801 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8803 case TARGET_OBJECT_MEMORY_MAP
:
8804 gdb_assert (annex
== NULL
);
8805 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8806 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8808 case TARGET_OBJECT_OSDATA
:
8809 /* Should only get here if we're connected. */
8810 gdb_assert (remote_desc
);
8811 return remote_read_qxfer
8812 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8813 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8815 case TARGET_OBJECT_THREADS
:
8816 gdb_assert (annex
== NULL
);
8817 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8818 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8820 case TARGET_OBJECT_TRACEFRAME_INFO
:
8821 gdb_assert (annex
== NULL
);
8822 return remote_read_qxfer
8823 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8824 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8826 case TARGET_OBJECT_FDPIC
:
8827 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8828 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8830 case TARGET_OBJECT_OPENVMS_UIB
:
8831 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8832 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8834 case TARGET_OBJECT_BTRACE
:
8835 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8836 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8842 /* Note: a zero OFFSET and LEN can be used to query the minimum
8844 if (offset
== 0 && len
== 0)
8845 return (get_remote_packet_size ());
8846 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8847 large enough let the caller deal with it. */
8848 if (len
< get_remote_packet_size ())
8850 len
= get_remote_packet_size ();
8852 /* Except for querying the minimum buffer size, target must be open. */
8854 error (_("remote query is only available after target open"));
8856 gdb_assert (annex
!= NULL
);
8857 gdb_assert (readbuf
!= NULL
);
8863 /* We used one buffer char for the remote protocol q command and
8864 another for the query type. As the remote protocol encapsulation
8865 uses 4 chars plus one extra in case we are debugging
8866 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8869 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8871 /* Bad caller may have sent forbidden characters. */
8872 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8877 gdb_assert (annex
[i
] == '\0');
8879 i
= putpkt (rs
->buf
);
8883 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8884 strcpy ((char *) readbuf
, rs
->buf
);
8886 return strlen ((char *) readbuf
);
8890 remote_search_memory (struct target_ops
* ops
,
8891 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8892 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8893 CORE_ADDR
*found_addrp
)
8895 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8896 struct remote_state
*rs
= get_remote_state ();
8897 int max_size
= get_memory_write_packet_size ();
8898 struct packet_config
*packet
=
8899 &remote_protocol_packets
[PACKET_qSearch_memory
];
8900 /* Number of packet bytes used to encode the pattern;
8901 this could be more than PATTERN_LEN due to escape characters. */
8902 int escaped_pattern_len
;
8903 /* Amount of pattern that was encodable in the packet. */
8904 int used_pattern_len
;
8907 ULONGEST found_addr
;
8909 /* Don't go to the target if we don't have to.
8910 This is done before checking packet->support to avoid the possibility that
8911 a success for this edge case means the facility works in general. */
8912 if (pattern_len
> search_space_len
)
8914 if (pattern_len
== 0)
8916 *found_addrp
= start_addr
;
8920 /* If we already know the packet isn't supported, fall back to the simple
8921 way of searching memory. */
8923 if (packet
->support
== PACKET_DISABLE
)
8925 /* Target doesn't provided special support, fall back and use the
8926 standard support (copy memory and do the search here). */
8927 return simple_search_memory (ops
, start_addr
, search_space_len
,
8928 pattern
, pattern_len
, found_addrp
);
8931 /* Insert header. */
8932 i
= snprintf (rs
->buf
, max_size
,
8933 "qSearch:memory:%s;%s;",
8934 phex_nz (start_addr
, addr_size
),
8935 phex_nz (search_space_len
, sizeof (search_space_len
)));
8936 max_size
-= (i
+ 1);
8938 /* Escape as much data as fits into rs->buf. */
8939 escaped_pattern_len
=
8940 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
8941 &used_pattern_len
, max_size
);
8943 /* Bail if the pattern is too large. */
8944 if (used_pattern_len
!= pattern_len
)
8945 error (_("Pattern is too large to transmit to remote target."));
8947 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8948 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8949 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8951 /* The request may not have worked because the command is not
8952 supported. If so, fall back to the simple way. */
8953 if (packet
->support
== PACKET_DISABLE
)
8955 return simple_search_memory (ops
, start_addr
, search_space_len
,
8956 pattern
, pattern_len
, found_addrp
);
8961 if (rs
->buf
[0] == '0')
8963 else if (rs
->buf
[0] == '1')
8966 if (rs
->buf
[1] != ',')
8967 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8968 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8969 *found_addrp
= found_addr
;
8972 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8978 remote_rcmd (char *command
,
8979 struct ui_file
*outbuf
)
8981 struct remote_state
*rs
= get_remote_state ();
8985 error (_("remote rcmd is only available after target open"));
8987 /* Send a NULL command across as an empty command. */
8988 if (command
== NULL
)
8991 /* The query prefix. */
8992 strcpy (rs
->buf
, "qRcmd,");
8993 p
= strchr (rs
->buf
, '\0');
8995 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8996 > get_remote_packet_size ())
8997 error (_("\"monitor\" command ``%s'' is too long."), command
);
8999 /* Encode the actual command. */
9000 bin2hex ((gdb_byte
*) command
, p
, 0);
9002 if (putpkt (rs
->buf
) < 0)
9003 error (_("Communication problem with target."));
9005 /* get/display the response */
9010 /* XXX - see also remote_get_noisy_reply(). */
9011 QUIT
; /* Allow user to bail out with ^C. */
9013 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9015 /* Timeout. Continue to (try to) read responses.
9016 This is better than stopping with an error, assuming the stub
9017 is still executing the (long) monitor command.
9018 If needed, the user can interrupt gdb using C-c, obtaining
9019 an effect similar to stop on timeout. */
9024 error (_("Target does not support this command."));
9025 if (buf
[0] == 'O' && buf
[1] != 'K')
9027 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9030 if (strcmp (buf
, "OK") == 0)
9032 if (strlen (buf
) == 3 && buf
[0] == 'E'
9033 && isdigit (buf
[1]) && isdigit (buf
[2]))
9035 error (_("Protocol error with Rcmd"));
9037 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9039 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9041 fputc_unfiltered (c
, outbuf
);
9047 static VEC(mem_region_s
) *
9048 remote_memory_map (struct target_ops
*ops
)
9050 VEC(mem_region_s
) *result
= NULL
;
9051 char *text
= target_read_stralloc (¤t_target
,
9052 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9056 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9058 result
= parse_memory_map (text
);
9059 do_cleanups (back_to
);
9066 packet_command (char *args
, int from_tty
)
9068 struct remote_state
*rs
= get_remote_state ();
9071 error (_("command can only be used with remote target"));
9074 error (_("remote-packet command requires packet text as argument"));
9076 puts_filtered ("sending: ");
9077 print_packet (args
);
9078 puts_filtered ("\n");
9081 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9082 puts_filtered ("received: ");
9083 print_packet (rs
->buf
);
9084 puts_filtered ("\n");
9088 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9090 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9092 static void threadset_test_cmd (char *cmd
, int tty
);
9094 static void threadalive_test (char *cmd
, int tty
);
9096 static void threadlist_test_cmd (char *cmd
, int tty
);
9098 int get_and_display_threadinfo (threadref
*ref
);
9100 static void threadinfo_test_cmd (char *cmd
, int tty
);
9102 static int thread_display_step (threadref
*ref
, void *context
);
9104 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9106 static void init_remote_threadtests (void);
9108 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9111 threadset_test_cmd (char *cmd
, int tty
)
9113 int sample_thread
= SAMPLE_THREAD
;
9115 printf_filtered (_("Remote threadset test\n"));
9116 set_general_thread (sample_thread
);
9121 threadalive_test (char *cmd
, int tty
)
9123 int sample_thread
= SAMPLE_THREAD
;
9124 int pid
= ptid_get_pid (inferior_ptid
);
9125 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9127 if (remote_thread_alive (ptid
))
9128 printf_filtered ("PASS: Thread alive test\n");
9130 printf_filtered ("FAIL: Thread alive test\n");
9133 void output_threadid (char *title
, threadref
*ref
);
9136 output_threadid (char *title
, threadref
*ref
)
9140 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9142 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9146 threadlist_test_cmd (char *cmd
, int tty
)
9149 threadref nextthread
;
9150 int done
, result_count
;
9151 threadref threadlist
[3];
9153 printf_filtered ("Remote Threadlist test\n");
9154 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9155 &result_count
, &threadlist
[0]))
9156 printf_filtered ("FAIL: threadlist test\n");
9159 threadref
*scan
= threadlist
;
9160 threadref
*limit
= scan
+ result_count
;
9162 while (scan
< limit
)
9163 output_threadid (" thread ", scan
++);
9168 display_thread_info (struct gdb_ext_thread_info
*info
)
9170 output_threadid ("Threadid: ", &info
->threadid
);
9171 printf_filtered ("Name: %s\n ", info
->shortname
);
9172 printf_filtered ("State: %s\n", info
->display
);
9173 printf_filtered ("other: %s\n\n", info
->more_display
);
9177 get_and_display_threadinfo (threadref
*ref
)
9181 struct gdb_ext_thread_info threadinfo
;
9183 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9184 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9185 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9186 display_thread_info (&threadinfo
);
9191 threadinfo_test_cmd (char *cmd
, int tty
)
9193 int athread
= SAMPLE_THREAD
;
9197 int_to_threadref (&thread
, athread
);
9198 printf_filtered ("Remote Threadinfo test\n");
9199 if (!get_and_display_threadinfo (&thread
))
9200 printf_filtered ("FAIL cannot get thread info\n");
9204 thread_display_step (threadref
*ref
, void *context
)
9206 /* output_threadid(" threadstep ",ref); *//* simple test */
9207 return get_and_display_threadinfo (ref
);
9211 threadlist_update_test_cmd (char *cmd
, int tty
)
9213 printf_filtered ("Remote Threadlist update test\n");
9214 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9218 init_remote_threadtests (void)
9220 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9221 _("Fetch and print the remote list of "
9222 "thread identifiers, one pkt only"));
9223 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9224 _("Fetch and display info about one thread"));
9225 add_com ("tset", class_obscure
, threadset_test_cmd
,
9226 _("Test setting to a different thread"));
9227 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9228 _("Iterate through updating all remote thread info"));
9229 add_com ("talive", class_obscure
, threadalive_test
,
9230 _(" Remote thread alive test "));
9235 /* Convert a thread ID to a string. Returns the string in a static
9239 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9241 static char buf
[64];
9242 struct remote_state
*rs
= get_remote_state ();
9244 if (ptid_equal (ptid
, null_ptid
))
9245 return normal_pid_to_str (ptid
);
9246 else if (ptid_is_pid (ptid
))
9248 /* Printing an inferior target id. */
9250 /* When multi-process extensions are off, there's no way in the
9251 remote protocol to know the remote process id, if there's any
9252 at all. There's one exception --- when we're connected with
9253 target extended-remote, and we manually attached to a process
9254 with "attach PID". We don't record anywhere a flag that
9255 allows us to distinguish that case from the case of
9256 connecting with extended-remote and the stub already being
9257 attached to a process, and reporting yes to qAttached, hence
9258 no smart special casing here. */
9259 if (!remote_multi_process_p (rs
))
9261 xsnprintf (buf
, sizeof buf
, "Remote target");
9265 return normal_pid_to_str (ptid
);
9269 if (ptid_equal (magic_null_ptid
, ptid
))
9270 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9271 else if (rs
->extended
&& remote_multi_process_p (rs
))
9272 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9273 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9275 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9276 ptid_get_tid (ptid
));
9281 /* Get the address of the thread local variable in OBJFILE which is
9282 stored at OFFSET within the thread local storage for thread PTID. */
9285 remote_get_thread_local_address (struct target_ops
*ops
,
9286 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9288 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9290 struct remote_state
*rs
= get_remote_state ();
9292 char *endp
= rs
->buf
+ get_remote_packet_size ();
9293 enum packet_result result
;
9295 strcpy (p
, "qGetTLSAddr:");
9297 p
= write_ptid (p
, endp
, ptid
);
9299 p
+= hexnumstr (p
, offset
);
9301 p
+= hexnumstr (p
, lm
);
9305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9306 result
= packet_ok (rs
->buf
,
9307 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9308 if (result
== PACKET_OK
)
9312 unpack_varlen_hex (rs
->buf
, &result
);
9315 else if (result
== PACKET_UNKNOWN
)
9316 throw_error (TLS_GENERIC_ERROR
,
9317 _("Remote target doesn't support qGetTLSAddr packet"));
9319 throw_error (TLS_GENERIC_ERROR
,
9320 _("Remote target failed to process qGetTLSAddr request"));
9323 throw_error (TLS_GENERIC_ERROR
,
9324 _("TLS not supported or disabled on this target"));
9329 /* Provide thread local base, i.e. Thread Information Block address.
9330 Returns 1 if ptid is found and thread_local_base is non zero. */
9333 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9335 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9337 struct remote_state
*rs
= get_remote_state ();
9339 char *endp
= rs
->buf
+ get_remote_packet_size ();
9340 enum packet_result result
;
9342 strcpy (p
, "qGetTIBAddr:");
9344 p
= write_ptid (p
, endp
, ptid
);
9348 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9349 result
= packet_ok (rs
->buf
,
9350 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9351 if (result
== PACKET_OK
)
9355 unpack_varlen_hex (rs
->buf
, &result
);
9357 *addr
= (CORE_ADDR
) result
;
9360 else if (result
== PACKET_UNKNOWN
)
9361 error (_("Remote target doesn't support qGetTIBAddr packet"));
9363 error (_("Remote target failed to process qGetTIBAddr request"));
9366 error (_("qGetTIBAddr not supported or disabled on this target"));
9371 /* Support for inferring a target description based on the current
9372 architecture and the size of a 'g' packet. While the 'g' packet
9373 can have any size (since optional registers can be left off the
9374 end), some sizes are easily recognizable given knowledge of the
9375 approximate architecture. */
9377 struct remote_g_packet_guess
9380 const struct target_desc
*tdesc
;
9382 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9383 DEF_VEC_O(remote_g_packet_guess_s
);
9385 struct remote_g_packet_data
9387 VEC(remote_g_packet_guess_s
) *guesses
;
9390 static struct gdbarch_data
*remote_g_packet_data_handle
;
9393 remote_g_packet_data_init (struct obstack
*obstack
)
9395 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9399 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9400 const struct target_desc
*tdesc
)
9402 struct remote_g_packet_data
*data
9403 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9404 struct remote_g_packet_guess new_guess
, *guess
;
9407 gdb_assert (tdesc
!= NULL
);
9410 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9412 if (guess
->bytes
== bytes
)
9413 internal_error (__FILE__
, __LINE__
,
9414 _("Duplicate g packet description added for size %d"),
9417 new_guess
.bytes
= bytes
;
9418 new_guess
.tdesc
= tdesc
;
9419 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9422 /* Return 1 if remote_read_description would do anything on this target
9423 and architecture, 0 otherwise. */
9426 remote_read_description_p (struct target_ops
*target
)
9428 struct remote_g_packet_data
*data
9429 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9431 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9437 static const struct target_desc
*
9438 remote_read_description (struct target_ops
*target
)
9440 struct remote_g_packet_data
*data
9441 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9443 /* Do not try this during initial connection, when we do not know
9444 whether there is a running but stopped thread. */
9445 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9448 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9450 struct remote_g_packet_guess
*guess
;
9452 int bytes
= send_g_packet ();
9455 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9457 if (guess
->bytes
== bytes
)
9458 return guess
->tdesc
;
9460 /* We discard the g packet. A minor optimization would be to
9461 hold on to it, and fill the register cache once we have selected
9462 an architecture, but it's too tricky to do safely. */
9468 /* Remote file transfer support. This is host-initiated I/O, not
9469 target-initiated; for target-initiated, see remote-fileio.c. */
9471 /* If *LEFT is at least the length of STRING, copy STRING 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_string (char **buffer
, int *left
, char *string
)
9478 int len
= strlen (string
);
9481 error (_("Packet too long for target."));
9483 memcpy (*buffer
, string
, len
);
9487 /* NUL-terminate the buffer as a convenience, if there is
9493 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9494 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9495 decrease *LEFT. Otherwise raise an error. */
9498 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9501 if (2 * len
> *left
)
9502 error (_("Packet too long for target."));
9504 bin2hex (bytes
, *buffer
, len
);
9508 /* NUL-terminate the buffer as a convenience, if there is
9514 /* If *LEFT is large enough, convert VALUE to hex and add it to
9515 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9516 decrease *LEFT. Otherwise raise an error. */
9519 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9521 int len
= hexnumlen (value
);
9524 error (_("Packet too long for target."));
9526 hexnumstr (*buffer
, value
);
9530 /* NUL-terminate the buffer as a convenience, if there is
9536 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9537 value, *REMOTE_ERRNO to the remote error number or zero if none
9538 was included, and *ATTACHMENT to point to the start of the annex
9539 if any. The length of the packet isn't needed here; there may
9540 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9542 Return 0 if the packet could be parsed, -1 if it could not. If
9543 -1 is returned, the other variables may not be initialized. */
9546 remote_hostio_parse_result (char *buffer
, int *retcode
,
9547 int *remote_errno
, char **attachment
)
9554 if (buffer
[0] != 'F')
9558 *retcode
= strtol (&buffer
[1], &p
, 16);
9559 if (errno
!= 0 || p
== &buffer
[1])
9562 /* Check for ",errno". */
9566 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9567 if (errno
!= 0 || p
+ 1 == p2
)
9572 /* Check for ";attachment". If there is no attachment, the
9573 packet should end here. */
9576 *attachment
= p
+ 1;
9579 else if (*p
== '\0')
9585 /* Send a prepared I/O packet to the target and read its response.
9586 The prepared packet is in the global RS->BUF before this function
9587 is called, and the answer is there when we return.
9589 COMMAND_BYTES is the length of the request to send, which may include
9590 binary data. WHICH_PACKET is the packet configuration to check
9591 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9592 is set to the error number and -1 is returned. Otherwise the value
9593 returned by the function is returned.
9595 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9596 attachment is expected; an error will be reported if there's a
9597 mismatch. If one is found, *ATTACHMENT will be set to point into
9598 the packet buffer and *ATTACHMENT_LEN will be set to the
9599 attachment's length. */
9602 remote_hostio_send_command (int command_bytes
, int which_packet
,
9603 int *remote_errno
, char **attachment
,
9604 int *attachment_len
)
9606 struct remote_state
*rs
= get_remote_state ();
9607 int ret
, bytes_read
;
9608 char *attachment_tmp
;
9611 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9613 *remote_errno
= FILEIO_ENOSYS
;
9617 putpkt_binary (rs
->buf
, command_bytes
);
9618 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9620 /* If it timed out, something is wrong. Don't try to parse the
9624 *remote_errno
= FILEIO_EINVAL
;
9628 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9631 *remote_errno
= FILEIO_EINVAL
;
9633 case PACKET_UNKNOWN
:
9634 *remote_errno
= FILEIO_ENOSYS
;
9640 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9643 *remote_errno
= FILEIO_EINVAL
;
9647 /* Make sure we saw an attachment if and only if we expected one. */
9648 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9649 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9651 *remote_errno
= FILEIO_EINVAL
;
9655 /* If an attachment was found, it must point into the packet buffer;
9656 work out how many bytes there were. */
9657 if (attachment_tmp
!= NULL
)
9659 *attachment
= attachment_tmp
;
9660 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9666 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9667 remote file descriptor, or -1 if an error occurs (and set
9671 remote_hostio_open (const char *filename
, int flags
, int mode
,
9674 struct remote_state
*rs
= get_remote_state ();
9676 int left
= get_remote_packet_size () - 1;
9678 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9680 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9682 remote_buffer_add_string (&p
, &left
, ",");
9684 remote_buffer_add_int (&p
, &left
, flags
);
9685 remote_buffer_add_string (&p
, &left
, ",");
9687 remote_buffer_add_int (&p
, &left
, mode
);
9689 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9690 remote_errno
, NULL
, NULL
);
9693 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9694 Return the number of bytes written, or -1 if an error occurs (and
9695 set *REMOTE_ERRNO). */
9698 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9699 ULONGEST offset
, int *remote_errno
)
9701 struct remote_state
*rs
= get_remote_state ();
9703 int left
= get_remote_packet_size ();
9706 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9708 remote_buffer_add_int (&p
, &left
, fd
);
9709 remote_buffer_add_string (&p
, &left
, ",");
9711 remote_buffer_add_int (&p
, &left
, offset
);
9712 remote_buffer_add_string (&p
, &left
, ",");
9714 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9715 get_remote_packet_size () - (p
- rs
->buf
));
9717 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9718 remote_errno
, NULL
, NULL
);
9721 /* Read up to LEN bytes FD on the remote target into READ_BUF
9722 Return the number of bytes read, or -1 if an error occurs (and
9723 set *REMOTE_ERRNO). */
9726 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9727 ULONGEST offset
, int *remote_errno
)
9729 struct remote_state
*rs
= get_remote_state ();
9732 int left
= get_remote_packet_size ();
9733 int ret
, attachment_len
;
9736 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9738 remote_buffer_add_int (&p
, &left
, fd
);
9739 remote_buffer_add_string (&p
, &left
, ",");
9741 remote_buffer_add_int (&p
, &left
, len
);
9742 remote_buffer_add_string (&p
, &left
, ",");
9744 remote_buffer_add_int (&p
, &left
, offset
);
9746 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9747 remote_errno
, &attachment
,
9753 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9755 if (read_len
!= ret
)
9756 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9761 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9762 (and set *REMOTE_ERRNO). */
9765 remote_hostio_close (int fd
, int *remote_errno
)
9767 struct remote_state
*rs
= get_remote_state ();
9769 int left
= get_remote_packet_size () - 1;
9771 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9773 remote_buffer_add_int (&p
, &left
, fd
);
9775 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9776 remote_errno
, NULL
, NULL
);
9779 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9780 occurs (and set *REMOTE_ERRNO). */
9783 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9785 struct remote_state
*rs
= get_remote_state ();
9787 int left
= get_remote_packet_size () - 1;
9789 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9791 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9794 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9795 remote_errno
, NULL
, NULL
);
9798 /* Read value of symbolic link FILENAME on the remote target. Return
9799 a null-terminated string allocated via xmalloc, or NULL if an error
9800 occurs (and set *REMOTE_ERRNO). */
9803 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9805 struct remote_state
*rs
= get_remote_state ();
9808 int left
= get_remote_packet_size ();
9809 int len
, attachment_len
;
9813 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9815 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9818 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9819 remote_errno
, &attachment
,
9825 ret
= xmalloc (len
+ 1);
9827 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9828 (gdb_byte
*) ret
, len
);
9829 if (read_len
!= len
)
9830 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9837 remote_fileio_errno_to_host (int errnum
)
9861 case FILEIO_ENOTDIR
:
9881 case FILEIO_ENAMETOOLONG
:
9882 return ENAMETOOLONG
;
9888 remote_hostio_error (int errnum
)
9890 int host_error
= remote_fileio_errno_to_host (errnum
);
9892 if (host_error
== -1)
9893 error (_("Unknown remote I/O error %d"), errnum
);
9895 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9899 remote_hostio_close_cleanup (void *opaque
)
9901 int fd
= *(int *) opaque
;
9904 remote_hostio_close (fd
, &remote_errno
);
9909 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9911 const char *filename
= bfd_get_filename (abfd
);
9912 int fd
, remote_errno
;
9915 gdb_assert (remote_filename_p (filename
));
9917 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9920 errno
= remote_fileio_errno_to_host (remote_errno
);
9921 bfd_set_error (bfd_error_system_call
);
9925 stream
= xmalloc (sizeof (int));
9931 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9933 int fd
= *(int *)stream
;
9938 /* Ignore errors on close; these may happen if the remote
9939 connection was already torn down. */
9940 remote_hostio_close (fd
, &remote_errno
);
9942 /* Zero means success. */
9947 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9948 file_ptr nbytes
, file_ptr offset
)
9950 int fd
= *(int *)stream
;
9952 file_ptr pos
, bytes
;
9955 while (nbytes
> pos
)
9957 bytes
= remote_hostio_pread (fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
9958 offset
+ pos
, &remote_errno
);
9960 /* Success, but no bytes, means end-of-file. */
9964 errno
= remote_fileio_errno_to_host (remote_errno
);
9965 bfd_set_error (bfd_error_system_call
);
9976 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9978 /* FIXME: We should probably implement remote_hostio_stat. */
9979 sb
->st_size
= INT_MAX
;
9984 remote_filename_p (const char *filename
)
9986 return strncmp (filename
, "remote:", 7) == 0;
9990 remote_bfd_open (const char *remote_file
, const char *target
)
9992 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
9993 remote_bfd_iovec_open
, NULL
,
9994 remote_bfd_iovec_pread
,
9995 remote_bfd_iovec_close
,
9996 remote_bfd_iovec_stat
);
10002 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10004 struct cleanup
*back_to
, *close_cleanup
;
10005 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10008 int bytes_in_buffer
;
10013 error (_("command can only be used with remote target"));
10015 file
= gdb_fopen_cloexec (local_file
, "rb");
10017 perror_with_name (local_file
);
10018 back_to
= make_cleanup_fclose (file
);
10020 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10022 0700, &remote_errno
);
10024 remote_hostio_error (remote_errno
);
10026 /* Send up to this many bytes at once. They won't all fit in the
10027 remote packet limit, so we'll transfer slightly fewer. */
10028 io_size
= get_remote_packet_size ();
10029 buffer
= xmalloc (io_size
);
10030 make_cleanup (xfree
, buffer
);
10032 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10034 bytes_in_buffer
= 0;
10037 while (bytes_in_buffer
|| !saw_eof
)
10041 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10042 io_size
- bytes_in_buffer
,
10047 error (_("Error reading %s."), local_file
);
10050 /* EOF. Unless there is something still in the
10051 buffer from the last iteration, we are done. */
10053 if (bytes_in_buffer
== 0)
10061 bytes
+= bytes_in_buffer
;
10062 bytes_in_buffer
= 0;
10064 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10065 offset
, &remote_errno
);
10068 remote_hostio_error (remote_errno
);
10069 else if (retcode
== 0)
10070 error (_("Remote write of %d bytes returned 0!"), bytes
);
10071 else if (retcode
< bytes
)
10073 /* Short write. Save the rest of the read data for the next
10075 bytes_in_buffer
= bytes
- retcode
;
10076 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10082 discard_cleanups (close_cleanup
);
10083 if (remote_hostio_close (fd
, &remote_errno
))
10084 remote_hostio_error (remote_errno
);
10087 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10088 do_cleanups (back_to
);
10092 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10094 struct cleanup
*back_to
, *close_cleanup
;
10095 int fd
, remote_errno
, bytes
, io_size
;
10101 error (_("command can only be used with remote target"));
10103 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10105 remote_hostio_error (remote_errno
);
10107 file
= gdb_fopen_cloexec (local_file
, "wb");
10109 perror_with_name (local_file
);
10110 back_to
= make_cleanup_fclose (file
);
10112 /* Send up to this many bytes at once. They won't all fit in the
10113 remote packet limit, so we'll transfer slightly fewer. */
10114 io_size
= get_remote_packet_size ();
10115 buffer
= xmalloc (io_size
);
10116 make_cleanup (xfree
, buffer
);
10118 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10123 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10125 /* Success, but no bytes, means end-of-file. */
10128 remote_hostio_error (remote_errno
);
10132 bytes
= fwrite (buffer
, 1, bytes
, file
);
10134 perror_with_name (local_file
);
10137 discard_cleanups (close_cleanup
);
10138 if (remote_hostio_close (fd
, &remote_errno
))
10139 remote_hostio_error (remote_errno
);
10142 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10143 do_cleanups (back_to
);
10147 remote_file_delete (const char *remote_file
, int from_tty
)
10149 int retcode
, remote_errno
;
10152 error (_("command can only be used with remote target"));
10154 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10156 remote_hostio_error (remote_errno
);
10159 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10163 remote_put_command (char *args
, int from_tty
)
10165 struct cleanup
*back_to
;
10169 error_no_arg (_("file to put"));
10171 argv
= gdb_buildargv (args
);
10172 back_to
= make_cleanup_freeargv (argv
);
10173 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10174 error (_("Invalid parameters to remote put"));
10176 remote_file_put (argv
[0], argv
[1], from_tty
);
10178 do_cleanups (back_to
);
10182 remote_get_command (char *args
, int from_tty
)
10184 struct cleanup
*back_to
;
10188 error_no_arg (_("file to get"));
10190 argv
= gdb_buildargv (args
);
10191 back_to
= make_cleanup_freeargv (argv
);
10192 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10193 error (_("Invalid parameters to remote get"));
10195 remote_file_get (argv
[0], argv
[1], from_tty
);
10197 do_cleanups (back_to
);
10201 remote_delete_command (char *args
, int from_tty
)
10203 struct cleanup
*back_to
;
10207 error_no_arg (_("file to delete"));
10209 argv
= gdb_buildargv (args
);
10210 back_to
= make_cleanup_freeargv (argv
);
10211 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10212 error (_("Invalid parameters to remote delete"));
10214 remote_file_delete (argv
[0], from_tty
);
10216 do_cleanups (back_to
);
10220 remote_command (char *args
, int from_tty
)
10222 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10226 remote_can_execute_reverse (void)
10228 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10229 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10236 remote_supports_non_stop (void)
10242 remote_supports_disable_randomization (void)
10244 /* Only supported in extended mode. */
10249 remote_supports_multi_process (void)
10251 struct remote_state
*rs
= get_remote_state ();
10253 /* Only extended-remote handles being attached to multiple
10254 processes, even though plain remote can use the multi-process
10255 thread id extensions, so that GDB knows the target process's
10257 return rs
->extended
&& remote_multi_process_p (rs
);
10261 remote_supports_cond_tracepoints (void)
10263 struct remote_state
*rs
= get_remote_state ();
10265 return rs
->cond_tracepoints
;
10269 remote_supports_cond_breakpoints (void)
10271 struct remote_state
*rs
= get_remote_state ();
10273 return rs
->cond_breakpoints
;
10277 remote_supports_fast_tracepoints (void)
10279 struct remote_state
*rs
= get_remote_state ();
10281 return rs
->fast_tracepoints
;
10285 remote_supports_static_tracepoints (void)
10287 struct remote_state
*rs
= get_remote_state ();
10289 return rs
->static_tracepoints
;
10293 remote_supports_install_in_trace (void)
10295 struct remote_state
*rs
= get_remote_state ();
10297 return rs
->install_in_trace
;
10301 remote_supports_enable_disable_tracepoint (void)
10303 struct remote_state
*rs
= get_remote_state ();
10305 return rs
->enable_disable_tracepoints
;
10309 remote_supports_string_tracing (void)
10311 struct remote_state
*rs
= get_remote_state ();
10313 return rs
->string_tracing
;
10317 remote_can_run_breakpoint_commands (void)
10319 struct remote_state
*rs
= get_remote_state ();
10321 return rs
->breakpoint_commands
;
10325 remote_trace_init (void)
10328 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10329 if (strcmp (target_buf
, "OK") != 0)
10330 error (_("Target does not support this command."));
10333 static void free_actions_list (char **actions_list
);
10334 static void free_actions_list_cleanup_wrapper (void *);
10336 free_actions_list_cleanup_wrapper (void *al
)
10338 free_actions_list (al
);
10342 free_actions_list (char **actions_list
)
10346 if (actions_list
== 0)
10349 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10350 xfree (actions_list
[ndx
]);
10352 xfree (actions_list
);
10355 /* Recursive routine to walk through command list including loops, and
10356 download packets for each command. */
10359 remote_download_command_source (int num
, ULONGEST addr
,
10360 struct command_line
*cmds
)
10362 struct remote_state
*rs
= get_remote_state ();
10363 struct command_line
*cmd
;
10365 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10367 QUIT
; /* Allow user to bail out with ^C. */
10368 strcpy (rs
->buf
, "QTDPsrc:");
10369 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10370 rs
->buf
+ strlen (rs
->buf
),
10371 rs
->buf_size
- strlen (rs
->buf
));
10373 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10374 if (strcmp (target_buf
, "OK"))
10375 warning (_("Target does not support source download."));
10377 if (cmd
->control_type
== while_control
10378 || cmd
->control_type
== while_stepping_control
)
10380 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10382 QUIT
; /* Allow user to bail out with ^C. */
10383 strcpy (rs
->buf
, "QTDPsrc:");
10384 encode_source_string (num
, addr
, "cmd", "end",
10385 rs
->buf
+ strlen (rs
->buf
),
10386 rs
->buf_size
- strlen (rs
->buf
));
10388 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10389 if (strcmp (target_buf
, "OK"))
10390 warning (_("Target does not support source download."));
10396 remote_download_tracepoint (struct bp_location
*loc
)
10398 #define BUF_SIZE 2048
10402 char buf
[BUF_SIZE
];
10403 char **tdp_actions
;
10404 char **stepping_actions
;
10406 struct cleanup
*old_chain
= NULL
;
10407 struct agent_expr
*aexpr
;
10408 struct cleanup
*aexpr_chain
= NULL
;
10410 struct breakpoint
*b
= loc
->owner
;
10411 struct tracepoint
*t
= (struct tracepoint
*) b
;
10413 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
10414 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10416 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10419 tpaddr
= loc
->address
;
10420 sprintf_vma (addrbuf
, tpaddr
);
10421 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10422 addrbuf
, /* address */
10423 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10424 t
->step_count
, t
->pass_count
);
10425 /* Fast tracepoints are mostly handled by the target, but we can
10426 tell the target how big of an instruction block should be moved
10428 if (b
->type
== bp_fast_tracepoint
)
10430 /* Only test for support at download time; we may not know
10431 target capabilities at definition time. */
10432 if (remote_supports_fast_tracepoints ())
10436 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10437 tpaddr
, &isize
, NULL
))
10438 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10441 /* If it passed validation at definition but fails now,
10442 something is very wrong. */
10443 internal_error (__FILE__
, __LINE__
,
10444 _("Fast tracepoint not "
10445 "valid during download"));
10448 /* Fast tracepoints are functionally identical to regular
10449 tracepoints, so don't take lack of support as a reason to
10450 give up on the trace run. */
10451 warning (_("Target does not support fast tracepoints, "
10452 "downloading %d as regular tracepoint"), b
->number
);
10454 else if (b
->type
== bp_static_tracepoint
)
10456 /* Only test for support at download time; we may not know
10457 target capabilities at definition time. */
10458 if (remote_supports_static_tracepoints ())
10460 struct static_tracepoint_marker marker
;
10462 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10463 strcat (buf
, ":S");
10465 error (_("Static tracepoint not valid during download"));
10468 /* Fast tracepoints are functionally identical to regular
10469 tracepoints, so don't take lack of support as a reason
10470 to give up on the trace run. */
10471 error (_("Target does not support static tracepoints"));
10473 /* If the tracepoint has a conditional, make it into an agent
10474 expression and append to the definition. */
10477 /* Only test support at download time, we may not know target
10478 capabilities at definition time. */
10479 if (remote_supports_cond_tracepoints ())
10481 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10482 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10483 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10485 pkt
= buf
+ strlen (buf
);
10486 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10487 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10489 do_cleanups (aexpr_chain
);
10492 warning (_("Target does not support conditional tracepoints, "
10493 "ignoring tp %d cond"), b
->number
);
10496 if (b
->commands
|| *default_collect
)
10499 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10500 if (strcmp (target_buf
, "OK"))
10501 error (_("Target does not support tracepoints."));
10503 /* do_single_steps (t); */
10506 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10508 QUIT
; /* Allow user to bail out with ^C. */
10509 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10510 b
->number
, addrbuf
, /* address */
10512 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10515 remote_get_noisy_reply (&target_buf
,
10517 if (strcmp (target_buf
, "OK"))
10518 error (_("Error on target while setting tracepoints."));
10521 if (stepping_actions
)
10523 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10525 QUIT
; /* Allow user to bail out with ^C. */
10526 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10527 b
->number
, addrbuf
, /* address */
10528 ((ndx
== 0) ? "S" : ""),
10529 stepping_actions
[ndx
],
10530 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10532 remote_get_noisy_reply (&target_buf
,
10534 if (strcmp (target_buf
, "OK"))
10535 error (_("Error on target while setting tracepoints."));
10539 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10542 if (b
->addr_string
)
10544 strcpy (buf
, "QTDPsrc:");
10545 encode_source_string (b
->number
, loc
->address
,
10546 "at", b
->addr_string
, buf
+ strlen (buf
),
10547 2048 - strlen (buf
));
10550 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10551 if (strcmp (target_buf
, "OK"))
10552 warning (_("Target does not support source download."));
10554 if (b
->cond_string
)
10556 strcpy (buf
, "QTDPsrc:");
10557 encode_source_string (b
->number
, loc
->address
,
10558 "cond", b
->cond_string
, buf
+ strlen (buf
),
10559 2048 - strlen (buf
));
10561 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10562 if (strcmp (target_buf
, "OK"))
10563 warning (_("Target does not support source download."));
10565 remote_download_command_source (b
->number
, loc
->address
,
10566 breakpoint_commands (b
));
10569 do_cleanups (old_chain
);
10573 remote_can_download_tracepoint (void)
10575 struct remote_state
*rs
= get_remote_state ();
10576 struct trace_status
*ts
;
10579 /* Don't try to install tracepoints until we've relocated our
10580 symbols, and fetched and merged the target's tracepoint list with
10582 if (rs
->starting_up
)
10585 ts
= current_trace_status ();
10586 status
= remote_get_trace_status (ts
);
10588 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10591 /* If we are in a tracing experiment, but remote stub doesn't support
10592 installing tracepoint in trace, we have to return. */
10593 if (!remote_supports_install_in_trace ())
10601 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10603 struct remote_state
*rs
= get_remote_state ();
10606 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10607 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10609 p
= rs
->buf
+ strlen (rs
->buf
);
10610 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10611 error (_("Trace state variable name too long for tsv definition packet"));
10612 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10615 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10616 if (*target_buf
== '\0')
10617 error (_("Target does not support this command."));
10618 if (strcmp (target_buf
, "OK") != 0)
10619 error (_("Error on target while downloading trace state variable."));
10623 remote_enable_tracepoint (struct bp_location
*location
)
10625 struct remote_state
*rs
= get_remote_state ();
10628 sprintf_vma (addr_buf
, location
->address
);
10629 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10630 location
->owner
->number
, addr_buf
);
10632 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10633 if (*rs
->buf
== '\0')
10634 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10635 if (strcmp (rs
->buf
, "OK") != 0)
10636 error (_("Error on target while enabling tracepoint."));
10640 remote_disable_tracepoint (struct bp_location
*location
)
10642 struct remote_state
*rs
= get_remote_state ();
10645 sprintf_vma (addr_buf
, location
->address
);
10646 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10647 location
->owner
->number
, addr_buf
);
10649 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10650 if (*rs
->buf
== '\0')
10651 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10652 if (strcmp (rs
->buf
, "OK") != 0)
10653 error (_("Error on target while disabling tracepoint."));
10657 remote_trace_set_readonly_regions (void)
10661 bfd_size_type size
;
10667 return; /* No information to give. */
10669 strcpy (target_buf
, "QTro");
10670 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10672 char tmp1
[40], tmp2
[40];
10675 if ((s
->flags
& SEC_LOAD
) == 0 ||
10676 /* (s->flags & SEC_CODE) == 0 || */
10677 (s
->flags
& SEC_READONLY
) == 0)
10681 vma
= bfd_get_section_vma (abfd
, s
);
10682 size
= bfd_get_section_size (s
);
10683 sprintf_vma (tmp1
, vma
);
10684 sprintf_vma (tmp2
, vma
+ size
);
10685 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10686 if (offset
+ sec_length
+ 1 > target_buf_size
)
10688 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10691 Too many sections for read-only sections definition packet."));
10694 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10696 offset
+= sec_length
;
10700 putpkt (target_buf
);
10701 getpkt (&target_buf
, &target_buf_size
, 0);
10706 remote_trace_start (void)
10708 putpkt ("QTStart");
10709 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10710 if (*target_buf
== '\0')
10711 error (_("Target does not support this command."));
10712 if (strcmp (target_buf
, "OK") != 0)
10713 error (_("Bogus reply from target: %s"), target_buf
);
10717 remote_get_trace_status (struct trace_status
*ts
)
10719 /* Initialize it just to avoid a GCC false warning. */
10721 /* FIXME we need to get register block size some other way. */
10722 extern int trace_regblock_size
;
10723 volatile struct gdb_exception ex
;
10724 enum packet_result result
;
10726 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10729 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10731 putpkt ("qTStatus");
10733 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10735 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10739 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10741 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10744 throw_exception (ex
);
10747 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10749 /* If the remote target doesn't do tracing, flag it. */
10750 if (result
== PACKET_UNKNOWN
)
10753 /* We're working with a live target. */
10754 ts
->filename
= NULL
;
10757 error (_("Bogus trace status reply from target: %s"), target_buf
);
10759 /* Function 'parse_trace_status' sets default value of each field of
10760 'ts' at first, so we don't have to do it here. */
10761 parse_trace_status (p
, ts
);
10763 return ts
->running
;
10767 remote_get_tracepoint_status (struct breakpoint
*bp
,
10768 struct uploaded_tp
*utp
)
10770 struct remote_state
*rs
= get_remote_state ();
10772 struct bp_location
*loc
;
10773 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10774 size_t size
= get_remote_packet_size ();
10778 tp
->base
.hit_count
= 0;
10779 tp
->traceframe_usage
= 0;
10780 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10782 /* If the tracepoint was never downloaded, don't go asking for
10784 if (tp
->number_on_target
== 0)
10786 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10787 phex_nz (loc
->address
, 0));
10789 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10790 if (reply
&& *reply
)
10793 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10799 utp
->hit_count
= 0;
10800 utp
->traceframe_usage
= 0;
10801 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10802 phex_nz (utp
->addr
, 0));
10804 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10805 if (reply
&& *reply
)
10808 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10814 remote_trace_stop (void)
10817 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10818 if (*target_buf
== '\0')
10819 error (_("Target does not support this command."));
10820 if (strcmp (target_buf
, "OK") != 0)
10821 error (_("Bogus reply from target: %s"), target_buf
);
10825 remote_trace_find (enum trace_find_type type
, int num
,
10826 CORE_ADDR addr1
, CORE_ADDR addr2
,
10829 struct remote_state
*rs
= get_remote_state ();
10830 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10832 int target_frameno
= -1, target_tracept
= -1;
10834 /* Lookups other than by absolute frame number depend on the current
10835 trace selected, so make sure it is correct on the remote end
10837 if (type
!= tfind_number
)
10838 set_remote_traceframe ();
10841 strcpy (p
, "QTFrame:");
10842 p
= strchr (p
, '\0');
10846 xsnprintf (p
, endbuf
- p
, "%x", num
);
10849 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10852 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10855 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10856 phex_nz (addr2
, 0));
10858 case tfind_outside
:
10859 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10860 phex_nz (addr2
, 0));
10863 error (_("Unknown trace find type %d"), type
);
10867 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10868 if (*reply
== '\0')
10869 error (_("Target does not support this command."));
10871 while (reply
&& *reply
)
10876 target_frameno
= (int) strtol (p
, &reply
, 16);
10878 error (_("Unable to parse trace frame number"));
10879 /* Don't update our remote traceframe number cache on failure
10880 to select a remote traceframe. */
10881 if (target_frameno
== -1)
10886 target_tracept
= (int) strtol (p
, &reply
, 16);
10888 error (_("Unable to parse tracepoint number"));
10890 case 'O': /* "OK"? */
10891 if (reply
[1] == 'K' && reply
[2] == '\0')
10894 error (_("Bogus reply from target: %s"), reply
);
10897 error (_("Bogus reply from target: %s"), reply
);
10900 *tpp
= target_tracept
;
10902 remote_traceframe_number
= target_frameno
;
10903 return target_frameno
;
10907 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10909 struct remote_state
*rs
= get_remote_state ();
10913 set_remote_traceframe ();
10915 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10917 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10918 if (reply
&& *reply
)
10922 unpack_varlen_hex (reply
+ 1, &uval
);
10923 *val
= (LONGEST
) uval
;
10931 remote_save_trace_data (const char *filename
)
10933 struct remote_state
*rs
= get_remote_state ();
10937 strcpy (p
, "QTSave:");
10939 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10940 error (_("Remote file name too long for trace save packet"));
10941 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10944 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10945 if (*reply
== '\0')
10946 error (_("Target does not support this command."));
10947 if (strcmp (reply
, "OK") != 0)
10948 error (_("Bogus reply from target: %s"), reply
);
10952 /* This is basically a memory transfer, but needs to be its own packet
10953 because we don't know how the target actually organizes its trace
10954 memory, plus we want to be able to ask for as much as possible, but
10955 not be unhappy if we don't get as much as we ask for. */
10958 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10960 struct remote_state
*rs
= get_remote_state ();
10966 strcpy (p
, "qTBuffer:");
10968 p
+= hexnumstr (p
, offset
);
10970 p
+= hexnumstr (p
, len
);
10974 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10975 if (reply
&& *reply
)
10977 /* 'l' by itself means we're at the end of the buffer and
10978 there is nothing more to get. */
10982 /* Convert the reply into binary. Limit the number of bytes to
10983 convert according to our passed-in buffer size, rather than
10984 what was returned in the packet; if the target is
10985 unexpectedly generous and gives us a bigger reply than we
10986 asked for, we don't want to crash. */
10987 rslt
= hex2bin (target_buf
, buf
, len
);
10991 /* Something went wrong, flag as an error. */
10996 remote_set_disconnected_tracing (int val
)
10998 struct remote_state
*rs
= get_remote_state ();
11000 if (rs
->disconnected_tracing
)
11004 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11006 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11007 if (*reply
== '\0')
11008 error (_("Target does not support this command."));
11009 if (strcmp (reply
, "OK") != 0)
11010 error (_("Bogus reply from target: %s"), reply
);
11013 warning (_("Target does not support disconnected tracing."));
11017 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11019 struct thread_info
*info
= find_thread_ptid (ptid
);
11021 if (info
&& info
->private)
11022 return info
->private->core
;
11027 remote_set_circular_trace_buffer (int val
)
11029 struct remote_state
*rs
= get_remote_state ();
11032 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11034 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11035 if (*reply
== '\0')
11036 error (_("Target does not support this command."));
11037 if (strcmp (reply
, "OK") != 0)
11038 error (_("Bogus reply from target: %s"), reply
);
11041 static struct traceframe_info
*
11042 remote_traceframe_info (void)
11046 text
= target_read_stralloc (¤t_target
,
11047 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11050 struct traceframe_info
*info
;
11051 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11053 info
= parse_traceframe_info (text
);
11054 do_cleanups (back_to
);
11061 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11062 instruction on which a fast tracepoint may be placed. Returns -1
11063 if the packet is not supported, and 0 if the minimum instruction
11064 length is unknown. */
11067 remote_get_min_fast_tracepoint_insn_len (void)
11069 struct remote_state
*rs
= get_remote_state ();
11072 /* If we're not debugging a process yet, the IPA can't be
11074 if (!target_has_execution
)
11077 /* Make sure the remote is pointing at the right process. */
11078 set_general_process ();
11080 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11082 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11083 if (*reply
== '\0')
11087 ULONGEST min_insn_len
;
11089 unpack_varlen_hex (reply
, &min_insn_len
);
11091 return (int) min_insn_len
;
11096 remote_set_trace_buffer_size (LONGEST val
)
11098 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11101 struct remote_state
*rs
= get_remote_state ();
11102 char *buf
= rs
->buf
;
11103 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11104 enum packet_result result
;
11106 gdb_assert (val
>= 0 || val
== -1);
11107 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11108 /* Send -1 as literal "-1" to avoid host size dependency. */
11112 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11115 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11118 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11119 result
= packet_ok (rs
->buf
,
11120 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11122 if (result
!= PACKET_OK
)
11123 warning (_("Bogus reply from target: %s"), rs
->buf
);
11128 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
11130 struct remote_state
*rs
= get_remote_state ();
11132 char *buf
= rs
->buf
;
11133 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11136 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11139 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11140 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, 0);
11146 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11147 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, 0);
11153 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11154 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, 0);
11158 /* Ensure the buffer is terminated. */
11162 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11163 if (*reply
== '\0')
11166 if (strcmp (reply
, "OK") != 0)
11167 error (_("Bogus reply from target: %s"), reply
);
11173 remote_use_agent (int use
)
11175 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11177 struct remote_state
*rs
= get_remote_state ();
11179 /* If the stub supports QAgent. */
11180 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11182 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11184 if (strcmp (rs
->buf
, "OK") == 0)
11195 remote_can_use_agent (void)
11197 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11200 struct btrace_target_info
11202 /* The ptid of the traced thread. */
11206 /* Check whether the target supports branch tracing. */
11209 remote_supports_btrace (void)
11211 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11213 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11215 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11221 /* Enable branch tracing. */
11223 static struct btrace_target_info
*
11224 remote_enable_btrace (ptid_t ptid
)
11226 struct btrace_target_info
*tinfo
= NULL
;
11227 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11228 struct remote_state
*rs
= get_remote_state ();
11229 char *buf
= rs
->buf
;
11230 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11232 if (packet
->support
!= PACKET_ENABLE
)
11233 error (_("Target does not support branch tracing."));
11235 set_general_thread (ptid
);
11237 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11239 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11241 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11243 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11244 error (_("Could not enable branch tracing for %s: %s"),
11245 target_pid_to_str (ptid
), rs
->buf
+ 2);
11247 error (_("Could not enable branch tracing for %s."),
11248 target_pid_to_str (ptid
));
11251 tinfo
= xzalloc (sizeof (*tinfo
));
11252 tinfo
->ptid
= ptid
;
11257 /* Disable branch tracing. */
11260 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11262 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11263 struct remote_state
*rs
= get_remote_state ();
11264 char *buf
= rs
->buf
;
11265 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11267 if (packet
->support
!= PACKET_ENABLE
)
11268 error (_("Target does not support branch tracing."));
11270 set_general_thread (tinfo
->ptid
);
11272 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11274 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11276 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11278 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11279 error (_("Could not disable branch tracing for %s: %s"),
11280 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11282 error (_("Could not disable branch tracing for %s."),
11283 target_pid_to_str (tinfo
->ptid
));
11289 /* Teardown branch tracing. */
11292 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11294 /* We must not talk to the target during teardown. */
11298 /* Read the branch trace. */
11300 static VEC (btrace_block_s
) *
11301 remote_read_btrace (struct btrace_target_info
*tinfo
,
11302 enum btrace_read_type type
)
11304 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11305 struct remote_state
*rs
= get_remote_state ();
11306 VEC (btrace_block_s
) *btrace
= NULL
;
11310 if (packet
->support
!= PACKET_ENABLE
)
11311 error (_("Target does not support branch tracing."));
11313 #if !defined(HAVE_LIBEXPAT)
11314 error (_("Cannot process branch tracing result. XML parsing not supported."));
11319 case btrace_read_all
:
11322 case btrace_read_new
:
11326 internal_error (__FILE__
, __LINE__
,
11327 _("Bad branch tracing read type: %u."),
11328 (unsigned int) type
);
11331 xml
= target_read_stralloc (¤t_target
,
11332 TARGET_OBJECT_BTRACE
, annex
);
11335 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11337 btrace
= parse_xml_btrace (xml
);
11338 do_cleanups (cleanup
);
11345 init_remote_ops (void)
11347 remote_ops
.to_shortname
= "remote";
11348 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11349 remote_ops
.to_doc
=
11350 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11351 Specify the serial device it is connected to\n\
11352 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11353 remote_ops
.to_open
= remote_open
;
11354 remote_ops
.to_close
= remote_close
;
11355 remote_ops
.to_detach
= remote_detach
;
11356 remote_ops
.to_disconnect
= remote_disconnect
;
11357 remote_ops
.to_resume
= remote_resume
;
11358 remote_ops
.to_wait
= remote_wait
;
11359 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11360 remote_ops
.to_store_registers
= remote_store_registers
;
11361 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11362 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11363 remote_ops
.to_files_info
= remote_files_info
;
11364 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11365 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11366 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11367 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11368 remote_ops
.to_watchpoint_addr_within_range
=
11369 remote_watchpoint_addr_within_range
;
11370 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11371 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11372 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11373 remote_ops
.to_region_ok_for_hw_watchpoint
11374 = remote_region_ok_for_hw_watchpoint
;
11375 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11376 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11377 remote_ops
.to_kill
= remote_kill
;
11378 remote_ops
.to_load
= generic_load
;
11379 remote_ops
.to_mourn_inferior
= remote_mourn
;
11380 remote_ops
.to_pass_signals
= remote_pass_signals
;
11381 remote_ops
.to_program_signals
= remote_program_signals
;
11382 remote_ops
.to_thread_alive
= remote_thread_alive
;
11383 remote_ops
.to_find_new_threads
= remote_threads_info
;
11384 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11385 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11386 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11387 remote_ops
.to_stop
= remote_stop
;
11388 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11389 remote_ops
.to_rcmd
= remote_rcmd
;
11390 remote_ops
.to_log_command
= serial_log_command
;
11391 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11392 remote_ops
.to_stratum
= process_stratum
;
11393 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11394 remote_ops
.to_has_memory
= default_child_has_memory
;
11395 remote_ops
.to_has_stack
= default_child_has_stack
;
11396 remote_ops
.to_has_registers
= default_child_has_registers
;
11397 remote_ops
.to_has_execution
= default_child_has_execution
;
11398 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11399 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11400 remote_ops
.to_magic
= OPS_MAGIC
;
11401 remote_ops
.to_memory_map
= remote_memory_map
;
11402 remote_ops
.to_flash_erase
= remote_flash_erase
;
11403 remote_ops
.to_flash_done
= remote_flash_done
;
11404 remote_ops
.to_read_description
= remote_read_description
;
11405 remote_ops
.to_search_memory
= remote_search_memory
;
11406 remote_ops
.to_can_async_p
= remote_can_async_p
;
11407 remote_ops
.to_is_async_p
= remote_is_async_p
;
11408 remote_ops
.to_async
= remote_async
;
11409 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11410 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11411 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11412 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11413 remote_ops
.to_supports_disable_randomization
11414 = remote_supports_disable_randomization
;
11415 remote_ops
.to_fileio_open
= remote_hostio_open
;
11416 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11417 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11418 remote_ops
.to_fileio_close
= remote_hostio_close
;
11419 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11420 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11421 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11422 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11423 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11424 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11425 remote_ops
.to_trace_init
= remote_trace_init
;
11426 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11427 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11428 remote_ops
.to_download_trace_state_variable
11429 = remote_download_trace_state_variable
;
11430 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11431 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11432 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11433 remote_ops
.to_trace_start
= remote_trace_start
;
11434 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11435 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11436 remote_ops
.to_trace_stop
= remote_trace_stop
;
11437 remote_ops
.to_trace_find
= remote_trace_find
;
11438 remote_ops
.to_get_trace_state_variable_value
11439 = remote_get_trace_state_variable_value
;
11440 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11441 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11442 remote_ops
.to_upload_trace_state_variables
11443 = remote_upload_trace_state_variables
;
11444 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11445 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11446 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11447 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11448 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11449 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11450 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11451 remote_ops
.to_verify_memory
= remote_verify_memory
;
11452 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11453 remote_ops
.to_set_permissions
= remote_set_permissions
;
11454 remote_ops
.to_static_tracepoint_marker_at
11455 = remote_static_tracepoint_marker_at
;
11456 remote_ops
.to_static_tracepoint_markers_by_strid
11457 = remote_static_tracepoint_markers_by_strid
;
11458 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11459 remote_ops
.to_use_agent
= remote_use_agent
;
11460 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11461 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11462 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11463 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11464 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11465 remote_ops
.to_read_btrace
= remote_read_btrace
;
11468 /* Set up the extended remote vector by making a copy of the standard
11469 remote vector and adding to it. */
11472 init_extended_remote_ops (void)
11474 extended_remote_ops
= remote_ops
;
11476 extended_remote_ops
.to_shortname
= "extended-remote";
11477 extended_remote_ops
.to_longname
=
11478 "Extended remote serial target in gdb-specific protocol";
11479 extended_remote_ops
.to_doc
=
11480 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11481 Specify the serial device it is connected to (e.g. /dev/ttya).";
11482 extended_remote_ops
.to_open
= extended_remote_open
;
11483 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11484 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11485 extended_remote_ops
.to_detach
= extended_remote_detach
;
11486 extended_remote_ops
.to_attach
= extended_remote_attach
;
11487 extended_remote_ops
.to_kill
= extended_remote_kill
;
11488 extended_remote_ops
.to_supports_disable_randomization
11489 = extended_remote_supports_disable_randomization
;
11493 remote_can_async_p (void)
11495 if (!target_async_permitted
)
11496 /* We only enable async when the user specifically asks for it. */
11499 /* We're async whenever the serial device is. */
11500 return serial_can_async_p (remote_desc
);
11504 remote_is_async_p (void)
11506 if (!target_async_permitted
)
11507 /* We only enable async when the user specifically asks for it. */
11510 /* We're async whenever the serial device is. */
11511 return serial_is_async_p (remote_desc
);
11514 /* Pass the SERIAL event on and up to the client. One day this code
11515 will be able to delay notifying the client of an event until the
11516 point where an entire packet has been received. */
11518 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11520 static void *async_client_context
;
11521 static serial_event_ftype remote_async_serial_handler
;
11524 remote_async_serial_handler (struct serial
*scb
, void *context
)
11526 /* Don't propogate error information up to the client. Instead let
11527 the client find out about the error by querying the target. */
11528 async_client_callback (INF_REG_EVENT
, async_client_context
);
11532 remote_async_inferior_event_handler (gdb_client_data data
)
11534 inferior_event_handler (INF_REG_EVENT
, NULL
);
11538 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11539 void *context
), void *context
)
11541 if (callback
!= NULL
)
11543 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
11544 async_client_callback
= callback
;
11545 async_client_context
= context
;
11548 serial_async (remote_desc
, NULL
, NULL
);
11552 set_remote_cmd (char *args
, int from_tty
)
11554 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11558 show_remote_cmd (char *args
, int from_tty
)
11560 /* We can't just use cmd_show_list here, because we want to skip
11561 the redundant "show remote Z-packet" and the legacy aliases. */
11562 struct cleanup
*showlist_chain
;
11563 struct cmd_list_element
*list
= remote_show_cmdlist
;
11564 struct ui_out
*uiout
= current_uiout
;
11566 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11567 for (; list
!= NULL
; list
= list
->next
)
11568 if (strcmp (list
->name
, "Z-packet") == 0)
11570 else if (list
->type
== not_set_cmd
)
11571 /* Alias commands are exactly like the original, except they
11572 don't have the normal type. */
11576 struct cleanup
*option_chain
11577 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11579 ui_out_field_string (uiout
, "name", list
->name
);
11580 ui_out_text (uiout
, ": ");
11581 if (list
->type
== show_cmd
)
11582 do_show_command ((char *) NULL
, from_tty
, list
);
11584 cmd_func (list
, NULL
, from_tty
);
11585 /* Close the tuple. */
11586 do_cleanups (option_chain
);
11589 /* Close the tuple. */
11590 do_cleanups (showlist_chain
);
11594 /* Function to be called whenever a new objfile (shlib) is detected. */
11596 remote_new_objfile (struct objfile
*objfile
)
11598 if (remote_desc
!= 0) /* Have a remote connection. */
11599 remote_check_symbols (objfile
);
11602 /* Pull all the tracepoints defined on the target and create local
11603 data structures representing them. We don't want to create real
11604 tracepoints yet, we don't want to mess up the user's existing
11608 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11610 struct remote_state
*rs
= get_remote_state ();
11613 /* Ask for a first packet of tracepoint definition. */
11615 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11617 while (*p
&& *p
!= 'l')
11619 parse_tracepoint_definition (p
, utpp
);
11620 /* Ask for another packet of tracepoint definition. */
11622 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11629 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11631 struct remote_state
*rs
= get_remote_state ();
11634 /* Ask for a first packet of variable definition. */
11636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11638 while (*p
&& *p
!= 'l')
11640 parse_tsv_definition (p
, utsvp
);
11641 /* Ask for another packet of variable definition. */
11643 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11650 _initialize_remote (void)
11652 struct remote_state
*rs
;
11653 struct cmd_list_element
*cmd
;
11654 const char *cmd_name
;
11656 /* architecture specific data */
11657 remote_gdbarch_data_handle
=
11658 gdbarch_data_register_post_init (init_remote_state
);
11659 remote_g_packet_data_handle
=
11660 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11662 /* Initialize the per-target state. At the moment there is only one
11663 of these, not one per target. Only one target is active at a
11664 time. The default buffer size is unimportant; it will be expanded
11665 whenever a larger buffer is needed. */
11666 rs
= get_remote_state_raw ();
11667 rs
->buf_size
= 400;
11668 rs
->buf
= xmalloc (rs
->buf_size
);
11670 init_remote_ops ();
11671 add_target (&remote_ops
);
11673 init_extended_remote_ops ();
11674 add_target (&extended_remote_ops
);
11676 /* Hook into new objfile notification. */
11677 observer_attach_new_objfile (remote_new_objfile
);
11678 /* We're no longer interested in notification events of an inferior
11680 observer_attach_inferior_exit (discard_pending_stop_replies
);
11682 /* Set up signal handlers. */
11683 sigint_remote_token
=
11684 create_async_signal_handler (async_remote_interrupt
, NULL
);
11685 sigint_remote_twice_token
=
11686 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11689 init_remote_threadtests ();
11692 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11693 /* set/show remote ... */
11695 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11696 Remote protocol specific variables\n\
11697 Configure various remote-protocol specific variables such as\n\
11698 the packets being used"),
11699 &remote_set_cmdlist
, "set remote ",
11700 0 /* allow-unknown */, &setlist
);
11701 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11702 Remote protocol specific variables\n\
11703 Configure various remote-protocol specific variables such as\n\
11704 the packets being used"),
11705 &remote_show_cmdlist
, "show remote ",
11706 0 /* allow-unknown */, &showlist
);
11708 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11709 Compare section data on target to the exec file.\n\
11710 Argument is a single section name (default: all loaded sections)."),
11713 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11714 Send an arbitrary packet to a remote target.\n\
11715 maintenance packet TEXT\n\
11716 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11717 this command sends the string TEXT to the inferior, and displays the\n\
11718 response packet. GDB supplies the initial `$' character, and the\n\
11719 terminating `#' character and checksum."),
11722 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11723 Set whether to send break if interrupted."), _("\
11724 Show whether to send break if interrupted."), _("\
11725 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11726 set_remotebreak
, show_remotebreak
,
11727 &setlist
, &showlist
);
11728 cmd_name
= "remotebreak";
11729 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11730 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11731 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11732 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11733 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11735 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11736 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11738 Set interrupt sequence to remote target."), _("\
11739 Show interrupt sequence to remote target."), _("\
11740 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11741 NULL
, show_interrupt_sequence
,
11742 &remote_set_cmdlist
,
11743 &remote_show_cmdlist
);
11745 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11746 &interrupt_on_connect
, _("\
11747 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11748 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11749 If set, interrupt sequence is sent to remote target."),
11751 &remote_set_cmdlist
, &remote_show_cmdlist
);
11753 /* Install commands for configuring memory read/write packets. */
11755 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11756 Set the maximum number of bytes per memory write packet (deprecated)."),
11758 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11759 Show the maximum number of bytes per memory write packet (deprecated)."),
11761 add_cmd ("memory-write-packet-size", no_class
,
11762 set_memory_write_packet_size
, _("\
11763 Set the maximum number of bytes per memory-write packet.\n\
11764 Specify the number of bytes in a packet or 0 (zero) for the\n\
11765 default packet size. The actual limit is further reduced\n\
11766 dependent on the target. Specify ``fixed'' to disable the\n\
11767 further restriction and ``limit'' to enable that restriction."),
11768 &remote_set_cmdlist
);
11769 add_cmd ("memory-read-packet-size", no_class
,
11770 set_memory_read_packet_size
, _("\
11771 Set the maximum number of bytes per memory-read packet.\n\
11772 Specify the number of bytes in a packet or 0 (zero) for the\n\
11773 default packet size. The actual limit is further reduced\n\
11774 dependent on the target. Specify ``fixed'' to disable the\n\
11775 further restriction and ``limit'' to enable that restriction."),
11776 &remote_set_cmdlist
);
11777 add_cmd ("memory-write-packet-size", no_class
,
11778 show_memory_write_packet_size
,
11779 _("Show the maximum number of bytes per memory-write packet."),
11780 &remote_show_cmdlist
);
11781 add_cmd ("memory-read-packet-size", no_class
,
11782 show_memory_read_packet_size
,
11783 _("Show the maximum number of bytes per memory-read packet."),
11784 &remote_show_cmdlist
);
11786 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11787 &remote_hw_watchpoint_limit
, _("\
11788 Set the maximum number of target hardware watchpoints."), _("\
11789 Show the maximum number of target hardware watchpoints."), _("\
11790 Specify a negative limit for unlimited."),
11791 NULL
, NULL
, /* FIXME: i18n: The maximum
11792 number of target hardware
11793 watchpoints is %s. */
11794 &remote_set_cmdlist
, &remote_show_cmdlist
);
11795 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11796 &remote_hw_watchpoint_length_limit
, _("\
11797 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11798 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11799 Specify a negative limit for unlimited."),
11800 NULL
, NULL
, /* FIXME: i18n: The maximum
11801 length (in bytes) of a target
11802 hardware watchpoint is %s. */
11803 &remote_set_cmdlist
, &remote_show_cmdlist
);
11804 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11805 &remote_hw_breakpoint_limit
, _("\
11806 Set the maximum number of target hardware breakpoints."), _("\
11807 Show the maximum number of target hardware breakpoints."), _("\
11808 Specify a negative limit for unlimited."),
11809 NULL
, NULL
, /* FIXME: i18n: The maximum
11810 number of target hardware
11811 breakpoints is %s. */
11812 &remote_set_cmdlist
, &remote_show_cmdlist
);
11814 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11815 &remote_address_size
, _("\
11816 Set the maximum size of the address (in bits) in a memory packet."), _("\
11817 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11819 NULL
, /* FIXME: i18n: */
11820 &setlist
, &showlist
);
11822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11823 "X", "binary-download", 1);
11825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11826 "vCont", "verbose-resume", 0);
11828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11829 "QPassSignals", "pass-signals", 0);
11831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11832 "QProgramSignals", "program-signals", 0);
11834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11835 "qSymbol", "symbol-lookup", 0);
11837 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11838 "P", "set-register", 1);
11840 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11841 "p", "fetch-register", 1);
11843 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11844 "Z0", "software-breakpoint", 0);
11846 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11847 "Z1", "hardware-breakpoint", 0);
11849 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11850 "Z2", "write-watchpoint", 0);
11852 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11853 "Z3", "read-watchpoint", 0);
11855 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11856 "Z4", "access-watchpoint", 0);
11858 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11859 "qXfer:auxv:read", "read-aux-vector", 0);
11861 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11862 "qXfer:features:read", "target-features", 0);
11864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11865 "qXfer:libraries:read", "library-info", 0);
11867 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11868 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11870 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11871 "qXfer:memory-map:read", "memory-map", 0);
11873 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11874 "qXfer:spu:read", "read-spu-object", 0);
11876 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11877 "qXfer:spu:write", "write-spu-object", 0);
11879 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11880 "qXfer:osdata:read", "osdata", 0);
11882 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11883 "qXfer:threads:read", "threads", 0);
11885 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11886 "qXfer:siginfo:read", "read-siginfo-object", 0);
11888 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11889 "qXfer:siginfo:write", "write-siginfo-object", 0);
11891 add_packet_config_cmd
11892 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11893 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11895 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
11896 "qXfer:uib:read", "unwind-info-block", 0);
11898 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11899 "qGetTLSAddr", "get-thread-local-storage-address",
11902 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11903 "qGetTIBAddr", "get-thread-information-block-address",
11906 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11907 "bc", "reverse-continue", 0);
11909 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11910 "bs", "reverse-step", 0);
11912 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11913 "qSupported", "supported-packets", 0);
11915 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11916 "qSearch:memory", "search-memory", 0);
11918 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
11919 "qTStatus", "trace-status", 0);
11921 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11922 "vFile:open", "hostio-open", 0);
11924 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11925 "vFile:pread", "hostio-pread", 0);
11927 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11928 "vFile:pwrite", "hostio-pwrite", 0);
11930 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11931 "vFile:close", "hostio-close", 0);
11933 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11934 "vFile:unlink", "hostio-unlink", 0);
11936 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11937 "vFile:readlink", "hostio-readlink", 0);
11939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11940 "vAttach", "attach", 0);
11942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11946 "QStartNoAckMode", "noack", 0);
11948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11949 "vKill", "kill", 0);
11951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11952 "qAttached", "query-attached", 0);
11954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11955 "ConditionalTracepoints",
11956 "conditional-tracepoints", 0);
11958 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
11959 "ConditionalBreakpoints",
11960 "conditional-breakpoints", 0);
11962 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
11963 "BreakpointCommands",
11964 "breakpoint-commands", 0);
11966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11967 "FastTracepoints", "fast-tracepoints", 0);
11969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11970 "TracepointSource", "TracepointSource", 0);
11972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11973 "QAllow", "allow", 0);
11975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11976 "StaticTracepoints", "static-tracepoints", 0);
11978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11979 "InstallInTrace", "install-in-trace", 0);
11981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11982 "qXfer:statictrace:read", "read-sdata-object", 0);
11984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11985 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11987 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11988 "QDisableRandomization", "disable-randomization", 0);
11990 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
11991 "QAgent", "agent", 0);
11993 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
11994 "QTBuffer:size", "trace-buffer-size", 0);
11996 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
11997 "Qbtrace:off", "disable-btrace", 0);
11999 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12000 "Qbtrace:bts", "enable-btrace", 0);
12002 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12003 "qXfer:btrace", "read-btrace", 0);
12005 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12006 Z sub-packet has its own set and show commands, but users may
12007 have sets to this variable in their .gdbinit files (or in their
12009 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12010 &remote_Z_packet_detect
, _("\
12011 Set use of remote protocol `Z' packets"), _("\
12012 Show use of remote protocol `Z' packets "), _("\
12013 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12015 set_remote_protocol_Z_packet_cmd
,
12016 show_remote_protocol_Z_packet_cmd
,
12017 /* FIXME: i18n: Use of remote protocol
12018 `Z' packets is %s. */
12019 &remote_set_cmdlist
, &remote_show_cmdlist
);
12021 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12022 Manipulate files on the remote system\n\
12023 Transfer files to and from the remote target system."),
12024 &remote_cmdlist
, "remote ",
12025 0 /* allow-unknown */, &cmdlist
);
12027 add_cmd ("put", class_files
, remote_put_command
,
12028 _("Copy a local file to the remote system."),
12031 add_cmd ("get", class_files
, remote_get_command
,
12032 _("Copy a remote file to the local system."),
12035 add_cmd ("delete", class_files
, remote_delete_command
,
12036 _("Delete a remote file."),
12039 remote_exec_file
= xstrdup ("");
12040 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12041 &remote_exec_file
, _("\
12042 Set the remote pathname for \"run\""), _("\
12043 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12044 &remote_set_cmdlist
, &remote_show_cmdlist
);
12046 /* Eventually initialize fileio. See fileio.c */
12047 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12049 /* Take advantage of the fact that the LWP field is not used, to tag
12050 special ptids with it set to != 0. */
12051 magic_null_ptid
= ptid_build (42000, 1, -1);
12052 not_sent_ptid
= ptid_build (42000, 1, -2);
12053 any_thread_ptid
= ptid_build (42000, 1, 0);
12055 target_buf_size
= 2048;
12056 target_buf
= xmalloc (target_buf_size
);