1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
23 #include "gdb_string.h"
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
37 #include "remote-notif.h"
40 #include "gdb_assert.h"
43 #include "cli/cli-decode.h"
44 #include "cli/cli-setshow.h"
45 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
73 /* Temp hacks for tracepoint encoding migration. */
74 static char *target_buf
;
75 static long target_buf_size
;
77 /* The size to align memory write packets, when practical. The protocol
78 does not guarantee any alignment, and gdb will generate short
79 writes and unaligned writes, but even as a best-effort attempt this
80 can improve bulk transfers. For instance, if a write is misaligned
81 relative to the target's data bus, the stub may need to make an extra
82 round trip fetching data from the target. This doesn't make a
83 huge difference, but it's easy to do, so we try to be helpful.
85 The alignment chosen is arbitrary; usually data bus width is
86 important here, not the possibly larger cache line size. */
87 enum { REMOTE_ALIGN_WRITES
= 16 };
89 /* Prototypes for local functions. */
90 static void cleanup_sigint_signal_handler (void *dummy
);
91 static void initialize_sigint_signal_handler (void);
92 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
93 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
94 int forever
, int *is_notif
);
96 static void handle_remote_sigint (int);
97 static void handle_remote_sigint_twice (int);
98 static void async_remote_interrupt (gdb_client_data
);
99 void async_remote_interrupt_twice (gdb_client_data
);
101 static void remote_files_info (struct target_ops
*ignore
);
103 static void remote_prepare_to_store (struct regcache
*regcache
);
105 static void remote_open (char *name
, int from_tty
);
107 static void extended_remote_open (char *name
, int from_tty
);
109 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
111 static void remote_close (void);
113 static void remote_mourn (struct target_ops
*ops
);
115 static void extended_remote_restart (void);
117 static void extended_remote_mourn (struct target_ops
*);
119 static void remote_mourn_1 (struct target_ops
*);
121 static void remote_send (char **buf
, long *sizeof_buf_p
);
123 static int readchar (int timeout
);
125 static void remote_kill (struct target_ops
*ops
);
127 static int tohex (int nib
);
129 static int remote_can_async_p (void);
131 static int remote_is_async_p (void);
133 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
134 void *context
), void *context
);
136 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
138 static void remote_interrupt (int signo
);
140 static void remote_interrupt_twice (int signo
);
142 static void interrupt_query (void);
144 static void set_general_thread (struct ptid ptid
);
145 static void set_continue_thread (struct ptid ptid
);
147 static void get_offsets (void);
149 static void skip_frame (void);
151 static long read_frame (char **buf_p
, long *sizeof_buf
);
153 static int hexnumlen (ULONGEST num
);
155 static void init_remote_ops (void);
157 static void init_extended_remote_ops (void);
159 static void remote_stop (ptid_t
);
161 static int ishex (int ch
, int *val
);
163 static int stubhex (int ch
);
165 static int hexnumstr (char *, ULONGEST
);
167 static int hexnumnstr (char *, ULONGEST
, int);
169 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
171 static void print_packet (char *);
173 static void compare_sections_command (char *, int);
175 static void packet_command (char *, int);
177 static int stub_unpack_int (char *buff
, int fieldlength
);
179 static ptid_t
remote_current_thread (ptid_t oldptid
);
181 static void remote_find_new_threads (void);
183 static void record_currthread (ptid_t currthread
);
185 static int fromhex (int a
);
187 static int putpkt_binary (char *buf
, int cnt
);
189 static void check_binary_download (CORE_ADDR addr
);
191 struct packet_config
;
193 static void show_packet_config_cmd (struct packet_config
*config
);
195 static void update_packet_config (struct packet_config
*config
);
197 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
198 struct cmd_list_element
*c
);
200 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
202 struct cmd_list_element
*c
,
205 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
206 static ptid_t
read_ptid (char *buf
, char **obuf
);
208 static void remote_set_permissions (void);
211 static int remote_get_trace_status (struct trace_status
*ts
);
213 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
215 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
217 static void remote_query_supported (void);
219 static void remote_check_symbols (struct objfile
*objfile
);
221 void _initialize_remote (void);
224 static void stop_reply_xfree (struct stop_reply
*);
225 static void remote_parse_stop_reply (char *, struct stop_reply
*);
226 static void push_stop_reply (struct stop_reply
*);
227 static void discard_pending_stop_replies (struct inferior
*);
228 static int peek_stop_reply (ptid_t ptid
);
230 static void remote_async_inferior_event_handler (gdb_client_data
);
232 static void remote_terminal_ours (void);
234 static int remote_read_description_p (struct target_ops
*target
);
236 static void remote_console_output (char *msg
);
238 static int remote_supports_cond_breakpoints (void);
240 static int remote_can_run_breakpoint_commands (void);
244 static struct cmd_list_element
*remote_cmdlist
;
246 /* For "set remote" and "show remote". */
248 static struct cmd_list_element
*remote_set_cmdlist
;
249 static struct cmd_list_element
*remote_show_cmdlist
;
251 /* Description of the remote protocol state for the currently
252 connected target. This is per-target state, and independent of the
253 selected architecture. */
257 /* A buffer to use for incoming packets, and its current size. The
258 buffer is grown dynamically for larger incoming packets.
259 Outgoing packets may also be constructed in this buffer.
260 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
261 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
266 /* True if we're going through initial connection setup (finding out
267 about the remote side's threads, relocating symbols, etc.). */
270 /* If we negotiated packet size explicitly (and thus can bypass
271 heuristics for the largest packet size that will not overflow
272 a buffer in the stub), this will be set to that packet size.
273 Otherwise zero, meaning to use the guessed size. */
274 long explicit_packet_size
;
276 /* remote_wait is normally called when the target is running and
277 waits for a stop reply packet. But sometimes we need to call it
278 when the target is already stopped. We can send a "?" packet
279 and have remote_wait read the response. Or, if we already have
280 the response, we can stash it in BUF and tell remote_wait to
281 skip calling getpkt. This flag is set when BUF contains a
282 stop reply packet and the target is not waiting. */
283 int cached_wait_status
;
285 /* True, if in no ack mode. That is, neither GDB nor the stub will
286 expect acks from each other. The connection is assumed to be
290 /* True if we're connected in extended remote mode. */
293 /* True if the stub reported support for multi-process
295 int multi_process_aware
;
297 /* True if we resumed the target and we're waiting for the target to
298 stop. In the mean time, we can't start another command/query.
299 The remote server wouldn't be ready to process it, so we'd
300 timeout waiting for a reply that would never come and eventually
301 we'd close the connection. This can happen in asynchronous mode
302 because we allow GDB commands while the target is running. */
303 int waiting_for_stop_reply
;
305 /* True if the stub reports support for non-stop mode. */
308 /* True if the stub reports support for vCont;t. */
311 /* True if the stub reports support for conditional tracepoints. */
312 int cond_tracepoints
;
314 /* True if the stub reports support for target-side breakpoint
316 int cond_breakpoints
;
318 /* True if the stub reports support for target-side breakpoint
320 int breakpoint_commands
;
322 /* True if the stub reports support for fast tracepoints. */
323 int fast_tracepoints
;
325 /* True if the stub reports support for static tracepoints. */
326 int static_tracepoints
;
328 /* True if the stub reports support for installing tracepoint while
330 int install_in_trace
;
332 /* True if the stub can continue running a trace while GDB is
334 int disconnected_tracing
;
336 /* True if the stub reports support for enabling and disabling
337 tracepoints while a trace experiment is running. */
338 int enable_disable_tracepoints
;
340 /* True if the stub can collect strings using tracenz bytecode. */
343 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
344 responded to that. */
348 /* Private data that we'll store in (struct thread_info)->private. */
349 struct private_thread_info
356 free_private_thread_info (struct private_thread_info
*info
)
362 /* Returns true if the multi-process extensions are in effect. */
364 remote_multi_process_p (struct remote_state
*rs
)
366 return rs
->multi_process_aware
;
369 /* This data could be associated with a target, but we do not always
370 have access to the current target when we need it, so for now it is
371 static. This will be fine for as long as only one target is in use
373 static struct remote_state remote_state
;
375 static struct remote_state
*
376 get_remote_state_raw (void)
378 return &remote_state
;
381 /* Description of the remote protocol for a given architecture. */
385 long offset
; /* Offset into G packet. */
386 long regnum
; /* GDB's internal register number. */
387 LONGEST pnum
; /* Remote protocol register number. */
388 int in_g_packet
; /* Always part of G packet. */
389 /* long size in bytes; == register_size (target_gdbarch (), regnum);
391 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
395 struct remote_arch_state
397 /* Description of the remote protocol registers. */
398 long sizeof_g_packet
;
400 /* Description of the remote protocol registers indexed by REGNUM
401 (making an array gdbarch_num_regs in size). */
402 struct packet_reg
*regs
;
404 /* This is the size (in chars) of the first response to the ``g''
405 packet. It is used as a heuristic when determining the maximum
406 size of memory-read and memory-write packets. A target will
407 typically only reserve a buffer large enough to hold the ``g''
408 packet. The size does not include packet overhead (headers and
410 long actual_register_packet_size
;
412 /* This is the maximum size (in chars) of a non read/write packet.
413 It is also used as a cap on the size of read/write packets. */
414 long remote_packet_size
;
417 long sizeof_pkt
= 2000;
419 /* Utility: generate error from an incoming stub packet. */
421 trace_error (char *buf
)
424 return; /* not an error msg */
427 case '1': /* malformed packet error */
428 if (*++buf
== '0') /* general case: */
429 error (_("remote.c: error in outgoing packet."));
431 error (_("remote.c: error in outgoing packet at field #%ld."),
432 strtol (buf
, NULL
, 16));
434 error (_("Target returns error code '%s'."), buf
);
438 /* Utility: wait for reply from stub, while accepting "O" packets. */
440 remote_get_noisy_reply (char **buf_p
,
443 do /* Loop on reply from remote stub. */
447 QUIT
; /* Allow user to bail out with ^C. */
448 getpkt (buf_p
, sizeof_buf
, 0);
452 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
455 CORE_ADDR from
, to
, org_to
;
457 int adjusted_size
= 0;
458 volatile struct gdb_exception ex
;
460 p
= buf
+ strlen ("qRelocInsn:");
461 pp
= unpack_varlen_hex (p
, &ul
);
463 error (_("invalid qRelocInsn packet: %s"), buf
);
467 unpack_varlen_hex (p
, &ul
);
472 TRY_CATCH (ex
, RETURN_MASK_ALL
)
474 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
478 adjusted_size
= to
- org_to
;
480 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
483 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
485 /* Propagate memory errors silently back to the target.
486 The stub may have limited the range of addresses we
487 can write to, for example. */
492 /* Something unexpectedly bad happened. Be verbose so
493 we can tell what, and propagate the error back to the
494 stub, so it doesn't get stuck waiting for a
496 exception_fprintf (gdb_stderr
, ex
,
497 _("warning: relocating instruction: "));
501 else if (buf
[0] == 'O' && buf
[1] != 'K')
502 remote_console_output (buf
+ 1); /* 'O' message from stub */
504 return buf
; /* Here's the actual reply. */
509 /* Handle for retreving the remote protocol data from gdbarch. */
510 static struct gdbarch_data
*remote_gdbarch_data_handle
;
512 static struct remote_arch_state
*
513 get_remote_arch_state (void)
515 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
518 /* Fetch the global remote target state. */
520 static struct remote_state
*
521 get_remote_state (void)
523 /* Make sure that the remote architecture state has been
524 initialized, because doing so might reallocate rs->buf. Any
525 function which calls getpkt also needs to be mindful of changes
526 to rs->buf, but this call limits the number of places which run
528 get_remote_arch_state ();
530 return get_remote_state_raw ();
534 compare_pnums (const void *lhs_
, const void *rhs_
)
536 const struct packet_reg
* const *lhs
= lhs_
;
537 const struct packet_reg
* const *rhs
= rhs_
;
539 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
541 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
548 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
550 int regnum
, num_remote_regs
, offset
;
551 struct packet_reg
**remote_regs
;
553 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
555 struct packet_reg
*r
= ®s
[regnum
];
557 if (register_size (gdbarch
, regnum
) == 0)
558 /* Do not try to fetch zero-sized (placeholder) registers. */
561 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
566 /* Define the g/G packet format as the contents of each register
567 with a remote protocol number, in order of ascending protocol
570 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
571 * sizeof (struct packet_reg
*));
572 for (num_remote_regs
= 0, regnum
= 0;
573 regnum
< gdbarch_num_regs (gdbarch
);
575 if (regs
[regnum
].pnum
!= -1)
576 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
578 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
581 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
583 remote_regs
[regnum
]->in_g_packet
= 1;
584 remote_regs
[regnum
]->offset
= offset
;
585 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
591 /* Given the architecture described by GDBARCH, return the remote
592 protocol register's number and the register's offset in the g/G
593 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
594 If the target does not have a mapping for REGNUM, return false,
595 otherwise, return true. */
598 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
599 int *pnum
, int *poffset
)
602 struct packet_reg
*regs
;
603 struct cleanup
*old_chain
;
605 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
607 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
608 old_chain
= make_cleanup (xfree
, regs
);
610 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
612 *pnum
= regs
[regnum
].pnum
;
613 *poffset
= regs
[regnum
].offset
;
615 do_cleanups (old_chain
);
621 init_remote_state (struct gdbarch
*gdbarch
)
623 struct remote_state
*rs
= get_remote_state_raw ();
624 struct remote_arch_state
*rsa
;
626 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
628 /* Use the architecture to build a regnum<->pnum table, which will be
629 1:1 unless a feature set specifies otherwise. */
630 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
631 gdbarch_num_regs (gdbarch
),
634 /* Record the maximum possible size of the g packet - it may turn out
636 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
638 /* Default maximum number of characters in a packet body. Many
639 remote stubs have a hardwired buffer size of 400 bytes
640 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
641 as the maximum packet-size to ensure that the packet and an extra
642 NUL character can always fit in the buffer. This stops GDB
643 trashing stubs that try to squeeze an extra NUL into what is
644 already a full buffer (As of 1999-12-04 that was most stubs). */
645 rsa
->remote_packet_size
= 400 - 1;
647 /* This one is filled in when a ``g'' packet is received. */
648 rsa
->actual_register_packet_size
= 0;
650 /* Should rsa->sizeof_g_packet needs more space than the
651 default, adjust the size accordingly. Remember that each byte is
652 encoded as two characters. 32 is the overhead for the packet
653 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
654 (``$NN:G...#NN'') is a better guess, the below has been padded a
656 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
657 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
659 /* Make sure that the packet buffer is plenty big enough for
660 this architecture. */
661 if (rs
->buf_size
< rsa
->remote_packet_size
)
663 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
664 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
670 /* Return the current allowed size of a remote packet. This is
671 inferred from the current architecture, and should be used to
672 limit the length of outgoing packets. */
674 get_remote_packet_size (void)
676 struct remote_state
*rs
= get_remote_state ();
677 struct remote_arch_state
*rsa
= get_remote_arch_state ();
679 if (rs
->explicit_packet_size
)
680 return rs
->explicit_packet_size
;
682 return rsa
->remote_packet_size
;
685 static struct packet_reg
*
686 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
688 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
692 struct packet_reg
*r
= &rsa
->regs
[regnum
];
694 gdb_assert (r
->regnum
== regnum
);
699 static struct packet_reg
*
700 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
704 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
706 struct packet_reg
*r
= &rsa
->regs
[i
];
714 /* FIXME: graces/2002-08-08: These variables should eventually be
715 bound to an instance of the target object (as in gdbarch-tdep()),
716 when such a thing exists. */
718 /* This is set to the data address of the access causing the target
719 to stop for a watchpoint. */
720 static CORE_ADDR remote_watch_data_address
;
722 /* This is non-zero if target stopped for a watchpoint. */
723 static int remote_stopped_by_watchpoint_p
;
725 static struct target_ops remote_ops
;
727 static struct target_ops extended_remote_ops
;
729 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
730 ``forever'' still use the normal timeout mechanism. This is
731 currently used by the ASYNC code to guarentee that target reads
732 during the initial connect always time-out. Once getpkt has been
733 modified to return a timeout indication and, in turn
734 remote_wait()/wait_for_inferior() have gained a timeout parameter
736 static int wait_forever_enabled_p
= 1;
738 /* Allow the user to specify what sequence to send to the remote
739 when he requests a program interruption: Although ^C is usually
740 what remote systems expect (this is the default, here), it is
741 sometimes preferable to send a break. On other systems such
742 as the Linux kernel, a break followed by g, which is Magic SysRq g
743 is required in order to interrupt the execution. */
744 const char interrupt_sequence_control_c
[] = "Ctrl-C";
745 const char interrupt_sequence_break
[] = "BREAK";
746 const char interrupt_sequence_break_g
[] = "BREAK-g";
747 static const char *const interrupt_sequence_modes
[] =
749 interrupt_sequence_control_c
,
750 interrupt_sequence_break
,
751 interrupt_sequence_break_g
,
754 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
757 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
758 struct cmd_list_element
*c
,
761 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
762 fprintf_filtered (file
,
763 _("Send the ASCII ETX character (Ctrl-c) "
764 "to the remote target to interrupt the "
765 "execution of the program.\n"));
766 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
767 fprintf_filtered (file
,
768 _("send a break signal to the remote target "
769 "to interrupt the execution of the program.\n"));
770 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
771 fprintf_filtered (file
,
772 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
773 "the remote target to interrupt the execution "
774 "of Linux kernel.\n"));
776 internal_error (__FILE__
, __LINE__
,
777 _("Invalid value for interrupt_sequence_mode: %s."),
778 interrupt_sequence_mode
);
781 /* This boolean variable specifies whether interrupt_sequence is sent
782 to the remote target when gdb connects to it.
783 This is mostly needed when you debug the Linux kernel: The Linux kernel
784 expects BREAK g which is Magic SysRq g for connecting gdb. */
785 static int interrupt_on_connect
= 0;
787 /* This variable is used to implement the "set/show remotebreak" commands.
788 Since these commands are now deprecated in favor of "set/show remote
789 interrupt-sequence", it no longer has any effect on the code. */
790 static int remote_break
;
793 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
796 interrupt_sequence_mode
= interrupt_sequence_break
;
798 interrupt_sequence_mode
= interrupt_sequence_control_c
;
802 show_remotebreak (struct ui_file
*file
, int from_tty
,
803 struct cmd_list_element
*c
,
808 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
809 remote_open knows that we don't have a file open when the program
811 static struct serial
*remote_desc
= NULL
;
813 /* This variable sets the number of bits in an address that are to be
814 sent in a memory ("M" or "m") packet. Normally, after stripping
815 leading zeros, the entire address would be sent. This variable
816 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
817 initial implementation of remote.c restricted the address sent in
818 memory packets to ``host::sizeof long'' bytes - (typically 32
819 bits). Consequently, for 64 bit targets, the upper 32 bits of an
820 address was never sent. Since fixing this bug may cause a break in
821 some remote targets this variable is principly provided to
822 facilitate backward compatibility. */
824 static unsigned int remote_address_size
;
826 /* Temporary to track who currently owns the terminal. See
827 remote_terminal_* for more details. */
829 static int remote_async_terminal_ours_p
;
831 /* The executable file to use for "run" on the remote side. */
833 static char *remote_exec_file
= "";
836 /* User configurable variables for the number of characters in a
837 memory read/write packet. MIN (rsa->remote_packet_size,
838 rsa->sizeof_g_packet) is the default. Some targets need smaller
839 values (fifo overruns, et.al.) and some users need larger values
840 (speed up transfers). The variables ``preferred_*'' (the user
841 request), ``current_*'' (what was actually set) and ``forced_*''
842 (Positive - a soft limit, negative - a hard limit). */
844 struct memory_packet_config
851 /* Compute the current size of a read/write packet. Since this makes
852 use of ``actual_register_packet_size'' the computation is dynamic. */
855 get_memory_packet_size (struct memory_packet_config
*config
)
857 struct remote_state
*rs
= get_remote_state ();
858 struct remote_arch_state
*rsa
= get_remote_arch_state ();
860 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
861 law?) that some hosts don't cope very well with large alloca()
862 calls. Eventually the alloca() code will be replaced by calls to
863 xmalloc() and make_cleanups() allowing this restriction to either
864 be lifted or removed. */
865 #ifndef MAX_REMOTE_PACKET_SIZE
866 #define MAX_REMOTE_PACKET_SIZE 16384
868 /* NOTE: 20 ensures we can write at least one byte. */
869 #ifndef MIN_REMOTE_PACKET_SIZE
870 #define MIN_REMOTE_PACKET_SIZE 20
875 if (config
->size
<= 0)
876 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
878 what_they_get
= config
->size
;
882 what_they_get
= get_remote_packet_size ();
883 /* Limit the packet to the size specified by the user. */
885 && what_they_get
> config
->size
)
886 what_they_get
= config
->size
;
888 /* Limit it to the size of the targets ``g'' response unless we have
889 permission from the stub to use a larger packet size. */
890 if (rs
->explicit_packet_size
== 0
891 && rsa
->actual_register_packet_size
> 0
892 && what_they_get
> rsa
->actual_register_packet_size
)
893 what_they_get
= rsa
->actual_register_packet_size
;
895 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
896 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
897 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
898 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
900 /* Make sure there is room in the global buffer for this packet
901 (including its trailing NUL byte). */
902 if (rs
->buf_size
< what_they_get
+ 1)
904 rs
->buf_size
= 2 * what_they_get
;
905 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
908 return what_they_get
;
911 /* Update the size of a read/write packet. If they user wants
912 something really big then do a sanity check. */
915 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
917 int fixed_p
= config
->fixed_p
;
918 long size
= config
->size
;
921 error (_("Argument required (integer, `fixed' or `limited')."));
922 else if (strcmp (args
, "hard") == 0
923 || strcmp (args
, "fixed") == 0)
925 else if (strcmp (args
, "soft") == 0
926 || strcmp (args
, "limit") == 0)
932 size
= strtoul (args
, &end
, 0);
934 error (_("Invalid %s (bad syntax)."), config
->name
);
936 /* Instead of explicitly capping the size of a packet to
937 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
938 instead allowed to set the size to something arbitrarily
940 if (size
> MAX_REMOTE_PACKET_SIZE
)
941 error (_("Invalid %s (too large)."), config
->name
);
945 if (fixed_p
&& !config
->fixed_p
)
947 if (! query (_("The target may not be able to correctly handle a %s\n"
948 "of %ld bytes. Change the packet size? "),
950 error (_("Packet size not changed."));
952 /* Update the config. */
953 config
->fixed_p
= fixed_p
;
958 show_memory_packet_size (struct memory_packet_config
*config
)
960 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
962 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
963 get_memory_packet_size (config
));
965 printf_filtered (_("Packets are limited to %ld bytes.\n"),
966 get_memory_packet_size (config
));
969 static struct memory_packet_config memory_write_packet_config
=
971 "memory-write-packet-size",
975 set_memory_write_packet_size (char *args
, int from_tty
)
977 set_memory_packet_size (args
, &memory_write_packet_config
);
981 show_memory_write_packet_size (char *args
, int from_tty
)
983 show_memory_packet_size (&memory_write_packet_config
);
987 get_memory_write_packet_size (void)
989 return get_memory_packet_size (&memory_write_packet_config
);
992 static struct memory_packet_config memory_read_packet_config
=
994 "memory-read-packet-size",
998 set_memory_read_packet_size (char *args
, int from_tty
)
1000 set_memory_packet_size (args
, &memory_read_packet_config
);
1004 show_memory_read_packet_size (char *args
, int from_tty
)
1006 show_memory_packet_size (&memory_read_packet_config
);
1010 get_memory_read_packet_size (void)
1012 long size
= get_memory_packet_size (&memory_read_packet_config
);
1014 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1015 extra buffer size argument before the memory read size can be
1016 increased beyond this. */
1017 if (size
> get_remote_packet_size ())
1018 size
= get_remote_packet_size ();
1023 /* Generic configuration support for packets the stub optionally
1024 supports. Allows the user to specify the use of the packet as well
1025 as allowing GDB to auto-detect support in the remote stub. */
1029 PACKET_SUPPORT_UNKNOWN
= 0,
1034 struct packet_config
1038 enum auto_boolean detect
;
1039 enum packet_support support
;
1042 /* Analyze a packet's return value and update the packet config
1053 update_packet_config (struct packet_config
*config
)
1055 switch (config
->detect
)
1057 case AUTO_BOOLEAN_TRUE
:
1058 config
->support
= PACKET_ENABLE
;
1060 case AUTO_BOOLEAN_FALSE
:
1061 config
->support
= PACKET_DISABLE
;
1063 case AUTO_BOOLEAN_AUTO
:
1064 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1070 show_packet_config_cmd (struct packet_config
*config
)
1072 char *support
= "internal-error";
1074 switch (config
->support
)
1077 support
= "enabled";
1079 case PACKET_DISABLE
:
1080 support
= "disabled";
1082 case PACKET_SUPPORT_UNKNOWN
:
1083 support
= "unknown";
1086 switch (config
->detect
)
1088 case AUTO_BOOLEAN_AUTO
:
1089 printf_filtered (_("Support for the `%s' packet "
1090 "is auto-detected, currently %s.\n"),
1091 config
->name
, support
);
1093 case AUTO_BOOLEAN_TRUE
:
1094 case AUTO_BOOLEAN_FALSE
:
1095 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1096 config
->name
, support
);
1102 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1103 const char *title
, int legacy
)
1109 config
->name
= name
;
1110 config
->title
= title
;
1111 config
->detect
= AUTO_BOOLEAN_AUTO
;
1112 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1113 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1115 show_doc
= xstrprintf ("Show current use of remote "
1116 "protocol `%s' (%s) packet",
1118 /* set/show TITLE-packet {auto,on,off} */
1119 cmd_name
= xstrprintf ("%s-packet", title
);
1120 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1121 &config
->detect
, set_doc
,
1122 show_doc
, NULL
, /* help_doc */
1123 set_remote_protocol_packet_cmd
,
1124 show_remote_protocol_packet_cmd
,
1125 &remote_set_cmdlist
, &remote_show_cmdlist
);
1126 /* The command code copies the documentation strings. */
1129 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1134 legacy_name
= xstrprintf ("%s-packet", name
);
1135 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1136 &remote_set_cmdlist
);
1137 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1138 &remote_show_cmdlist
);
1142 static enum packet_result
1143 packet_check_result (const char *buf
)
1147 /* The stub recognized the packet request. Check that the
1148 operation succeeded. */
1150 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1152 /* "Enn" - definitly an error. */
1153 return PACKET_ERROR
;
1155 /* Always treat "E." as an error. This will be used for
1156 more verbose error messages, such as E.memtypes. */
1157 if (buf
[0] == 'E' && buf
[1] == '.')
1158 return PACKET_ERROR
;
1160 /* The packet may or may not be OK. Just assume it is. */
1164 /* The stub does not support the packet. */
1165 return PACKET_UNKNOWN
;
1168 static enum packet_result
1169 packet_ok (const char *buf
, struct packet_config
*config
)
1171 enum packet_result result
;
1173 result
= packet_check_result (buf
);
1178 /* The stub recognized the packet request. */
1179 switch (config
->support
)
1181 case PACKET_SUPPORT_UNKNOWN
:
1183 fprintf_unfiltered (gdb_stdlog
,
1184 "Packet %s (%s) is supported\n",
1185 config
->name
, config
->title
);
1186 config
->support
= PACKET_ENABLE
;
1188 case PACKET_DISABLE
:
1189 internal_error (__FILE__
, __LINE__
,
1190 _("packet_ok: attempt to use a disabled packet"));
1196 case PACKET_UNKNOWN
:
1197 /* The stub does not support the packet. */
1198 switch (config
->support
)
1201 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1202 /* If the stub previously indicated that the packet was
1203 supported then there is a protocol error.. */
1204 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1205 config
->name
, config
->title
);
1207 /* The user set it wrong. */
1208 error (_("Enabled packet %s (%s) not recognized by stub"),
1209 config
->name
, config
->title
);
1211 case PACKET_SUPPORT_UNKNOWN
:
1213 fprintf_unfiltered (gdb_stdlog
,
1214 "Packet %s (%s) is NOT supported\n",
1215 config
->name
, config
->title
);
1216 config
->support
= PACKET_DISABLE
;
1218 case PACKET_DISABLE
:
1240 PACKET_vFile_pwrite
,
1242 PACKET_vFile_unlink
,
1243 PACKET_vFile_readlink
,
1245 PACKET_qXfer_features
,
1246 PACKET_qXfer_libraries
,
1247 PACKET_qXfer_libraries_svr4
,
1248 PACKET_qXfer_memory_map
,
1249 PACKET_qXfer_spu_read
,
1250 PACKET_qXfer_spu_write
,
1251 PACKET_qXfer_osdata
,
1252 PACKET_qXfer_threads
,
1253 PACKET_qXfer_statictrace_read
,
1254 PACKET_qXfer_traceframe_info
,
1259 PACKET_QPassSignals
,
1260 PACKET_QProgramSignals
,
1261 PACKET_qSearch_memory
,
1264 PACKET_QStartNoAckMode
,
1266 PACKET_qXfer_siginfo_read
,
1267 PACKET_qXfer_siginfo_write
,
1269 PACKET_ConditionalTracepoints
,
1270 PACKET_ConditionalBreakpoints
,
1271 PACKET_BreakpointCommands
,
1272 PACKET_FastTracepoints
,
1273 PACKET_StaticTracepoints
,
1274 PACKET_InstallInTrace
,
1277 PACKET_TracepointSource
,
1280 PACKET_QDisableRandomization
,
1282 PACKET_QTBuffer_size
,
1285 PACKET_qXfer_btrace
,
1289 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1292 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1293 struct cmd_list_element
*c
)
1295 struct packet_config
*packet
;
1297 for (packet
= remote_protocol_packets
;
1298 packet
< &remote_protocol_packets
[PACKET_MAX
];
1301 if (&packet
->detect
== c
->var
)
1303 update_packet_config (packet
);
1307 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1312 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1313 struct cmd_list_element
*c
,
1316 struct packet_config
*packet
;
1318 for (packet
= remote_protocol_packets
;
1319 packet
< &remote_protocol_packets
[PACKET_MAX
];
1322 if (&packet
->detect
== c
->var
)
1324 show_packet_config_cmd (packet
);
1328 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1332 /* Should we try one of the 'Z' requests? */
1336 Z_PACKET_SOFTWARE_BP
,
1337 Z_PACKET_HARDWARE_BP
,
1344 /* For compatibility with older distributions. Provide a ``set remote
1345 Z-packet ...'' command that updates all the Z packet types. */
1347 static enum auto_boolean remote_Z_packet_detect
;
1350 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1351 struct cmd_list_element
*c
)
1355 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1357 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1358 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1363 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1364 struct cmd_list_element
*c
,
1369 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1371 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1375 /* Should we try the 'ThreadInfo' query packet?
1377 This variable (NOT available to the user: auto-detect only!)
1378 determines whether GDB will use the new, simpler "ThreadInfo"
1379 query or the older, more complex syntax for thread queries.
1380 This is an auto-detect variable (set to true at each connect,
1381 and set to false when the target fails to recognize it). */
1383 static int use_threadinfo_query
;
1384 static int use_threadextra_query
;
1386 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1387 static struct async_signal_handler
*sigint_remote_twice_token
;
1388 static struct async_signal_handler
*sigint_remote_token
;
1391 /* Asynchronous signal handle registered as event loop source for
1392 when we have pending events ready to be passed to the core. */
1394 static struct async_event_handler
*remote_async_inferior_event_token
;
1398 static ptid_t magic_null_ptid
;
1399 static ptid_t not_sent_ptid
;
1400 static ptid_t any_thread_ptid
;
1402 /* These are the threads which we last sent to the remote system. The
1403 TID member will be -1 for all or -2 for not sent yet. */
1405 static ptid_t general_thread
;
1406 static ptid_t continue_thread
;
1408 /* This is the traceframe which we last selected on the remote system.
1409 It will be -1 if no traceframe is selected. */
1410 static int remote_traceframe_number
= -1;
1412 /* Find out if the stub attached to PID (and hence GDB should offer to
1413 detach instead of killing it when bailing out). */
1416 remote_query_attached (int pid
)
1418 struct remote_state
*rs
= get_remote_state ();
1419 size_t size
= get_remote_packet_size ();
1421 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1424 if (remote_multi_process_p (rs
))
1425 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1427 xsnprintf (rs
->buf
, size
, "qAttached");
1430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1432 switch (packet_ok (rs
->buf
,
1433 &remote_protocol_packets
[PACKET_qAttached
]))
1436 if (strcmp (rs
->buf
, "1") == 0)
1440 warning (_("Remote failure reply: %s"), rs
->buf
);
1442 case PACKET_UNKNOWN
:
1449 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1450 has been invented by GDB, instead of reported by the target. Since
1451 we can be connected to a remote system before before knowing about
1452 any inferior, mark the target with execution when we find the first
1453 inferior. If ATTACHED is 1, then we had just attached to this
1454 inferior. If it is 0, then we just created this inferior. If it
1455 is -1, then try querying the remote stub to find out if it had
1456 attached to the inferior or not. */
1458 static struct inferior
*
1459 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1461 struct inferior
*inf
;
1463 /* Check whether this process we're learning about is to be
1464 considered attached, or if is to be considered to have been
1465 spawned by the stub. */
1467 attached
= remote_query_attached (pid
);
1469 if (gdbarch_has_global_solist (target_gdbarch ()))
1471 /* If the target shares code across all inferiors, then every
1472 attach adds a new inferior. */
1473 inf
= add_inferior (pid
);
1475 /* ... and every inferior is bound to the same program space.
1476 However, each inferior may still have its own address
1478 inf
->aspace
= maybe_new_address_space ();
1479 inf
->pspace
= current_program_space
;
1483 /* In the traditional debugging scenario, there's a 1-1 match
1484 between program/address spaces. We simply bind the inferior
1485 to the program space's address space. */
1486 inf
= current_inferior ();
1487 inferior_appeared (inf
, pid
);
1490 inf
->attach_flag
= attached
;
1491 inf
->fake_pid_p
= fake_pid_p
;
1496 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1497 according to RUNNING. */
1500 remote_add_thread (ptid_t ptid
, int running
)
1504 set_executing (ptid
, running
);
1505 set_running (ptid
, running
);
1508 /* Come here when we learn about a thread id from the remote target.
1509 It may be the first time we hear about such thread, so take the
1510 opportunity to add it to GDB's thread list. In case this is the
1511 first time we're noticing its corresponding inferior, add it to
1512 GDB's inferior list as well. */
1515 remote_notice_new_inferior (ptid_t currthread
, int running
)
1517 /* If this is a new thread, add it to GDB's thread list.
1518 If we leave it up to WFI to do this, bad things will happen. */
1520 if (in_thread_list (currthread
) && is_exited (currthread
))
1522 /* We're seeing an event on a thread id we knew had exited.
1523 This has to be a new thread reusing the old id. Add it. */
1524 remote_add_thread (currthread
, running
);
1528 if (!in_thread_list (currthread
))
1530 struct inferior
*inf
= NULL
;
1531 int pid
= ptid_get_pid (currthread
);
1533 if (ptid_is_pid (inferior_ptid
)
1534 && pid
== ptid_get_pid (inferior_ptid
))
1536 /* inferior_ptid has no thread member yet. This can happen
1537 with the vAttach -> remote_wait,"TAAthread:" path if the
1538 stub doesn't support qC. This is the first stop reported
1539 after an attach, so this is the main thread. Update the
1540 ptid in the thread list. */
1541 if (in_thread_list (pid_to_ptid (pid
)))
1542 thread_change_ptid (inferior_ptid
, currthread
);
1545 remote_add_thread (currthread
, running
);
1546 inferior_ptid
= currthread
;
1551 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1553 /* inferior_ptid is not set yet. This can happen with the
1554 vRun -> remote_wait,"TAAthread:" path if the stub
1555 doesn't support qC. This is the first stop reported
1556 after an attach, so this is the main thread. Update the
1557 ptid in the thread list. */
1558 thread_change_ptid (inferior_ptid
, currthread
);
1562 /* When connecting to a target remote, or to a target
1563 extended-remote which already was debugging an inferior, we
1564 may not know about it yet. Add it before adding its child
1565 thread, so notifications are emitted in a sensible order. */
1566 if (!in_inferior_list (ptid_get_pid (currthread
)))
1568 struct remote_state
*rs
= get_remote_state ();
1569 int fake_pid_p
= !remote_multi_process_p (rs
);
1571 inf
= remote_add_inferior (fake_pid_p
,
1572 ptid_get_pid (currthread
), -1);
1575 /* This is really a new thread. Add it. */
1576 remote_add_thread (currthread
, running
);
1578 /* If we found a new inferior, let the common code do whatever
1579 it needs to with it (e.g., read shared libraries, insert
1582 notice_new_inferior (currthread
, running
, 0);
1586 /* Return the private thread data, creating it if necessary. */
1588 static struct private_thread_info
*
1589 demand_private_info (ptid_t ptid
)
1591 struct thread_info
*info
= find_thread_ptid (ptid
);
1597 info
->private = xmalloc (sizeof (*(info
->private)));
1598 info
->private_dtor
= free_private_thread_info
;
1599 info
->private->core
= -1;
1600 info
->private->extra
= 0;
1603 return info
->private;
1606 /* Call this function as a result of
1607 1) A halt indication (T packet) containing a thread id
1608 2) A direct query of currthread
1609 3) Successful execution of set thread */
1612 record_currthread (ptid_t currthread
)
1614 general_thread
= currthread
;
1617 static char *last_pass_packet
;
1619 /* If 'QPassSignals' is supported, tell the remote stub what signals
1620 it can simply pass through to the inferior without reporting. */
1623 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1625 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1627 char *pass_packet
, *p
;
1630 gdb_assert (numsigs
< 256);
1631 for (i
= 0; i
< numsigs
; i
++)
1633 if (pass_signals
[i
])
1636 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1637 strcpy (pass_packet
, "QPassSignals:");
1638 p
= pass_packet
+ strlen (pass_packet
);
1639 for (i
= 0; i
< numsigs
; i
++)
1641 if (pass_signals
[i
])
1644 *p
++ = tohex (i
>> 4);
1645 *p
++ = tohex (i
& 15);
1654 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1656 struct remote_state
*rs
= get_remote_state ();
1657 char *buf
= rs
->buf
;
1659 putpkt (pass_packet
);
1660 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1661 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1662 if (last_pass_packet
)
1663 xfree (last_pass_packet
);
1664 last_pass_packet
= pass_packet
;
1667 xfree (pass_packet
);
1671 /* The last QProgramSignals packet sent to the target. We bypass
1672 sending a new program signals list down to the target if the new
1673 packet is exactly the same as the last we sent. IOW, we only let
1674 the target know about program signals list changes. */
1676 static char *last_program_signals_packet
;
1678 /* If 'QProgramSignals' is supported, tell the remote stub what
1679 signals it should pass through to the inferior when detaching. */
1682 remote_program_signals (int numsigs
, unsigned char *signals
)
1684 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1689 gdb_assert (numsigs
< 256);
1690 for (i
= 0; i
< numsigs
; i
++)
1695 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1696 strcpy (packet
, "QProgramSignals:");
1697 p
= packet
+ strlen (packet
);
1698 for (i
= 0; i
< numsigs
; i
++)
1700 if (signal_pass_state (i
))
1703 *p
++ = tohex (i
>> 4);
1704 *p
++ = tohex (i
& 15);
1713 if (!last_program_signals_packet
1714 || strcmp (last_program_signals_packet
, packet
) != 0)
1716 struct remote_state
*rs
= get_remote_state ();
1717 char *buf
= rs
->buf
;
1720 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1721 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1722 xfree (last_program_signals_packet
);
1723 last_program_signals_packet
= packet
;
1730 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1731 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1732 thread. If GEN is set, set the general thread, if not, then set
1733 the step/continue thread. */
1735 set_thread (struct ptid ptid
, int gen
)
1737 struct remote_state
*rs
= get_remote_state ();
1738 ptid_t state
= gen
? general_thread
: continue_thread
;
1739 char *buf
= rs
->buf
;
1740 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1742 if (ptid_equal (state
, ptid
))
1746 *buf
++ = gen
? 'g' : 'c';
1747 if (ptid_equal (ptid
, magic_null_ptid
))
1748 xsnprintf (buf
, endbuf
- buf
, "0");
1749 else if (ptid_equal (ptid
, any_thread_ptid
))
1750 xsnprintf (buf
, endbuf
- buf
, "0");
1751 else if (ptid_equal (ptid
, minus_one_ptid
))
1752 xsnprintf (buf
, endbuf
- buf
, "-1");
1754 write_ptid (buf
, endbuf
, ptid
);
1756 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1758 general_thread
= ptid
;
1760 continue_thread
= ptid
;
1764 set_general_thread (struct ptid ptid
)
1766 set_thread (ptid
, 1);
1770 set_continue_thread (struct ptid ptid
)
1772 set_thread (ptid
, 0);
1775 /* Change the remote current process. Which thread within the process
1776 ends up selected isn't important, as long as it is the same process
1777 as what INFERIOR_PTID points to.
1779 This comes from that fact that there is no explicit notion of
1780 "selected process" in the protocol. The selected process for
1781 general operations is the process the selected general thread
1785 set_general_process (void)
1787 struct remote_state
*rs
= get_remote_state ();
1789 /* If the remote can't handle multiple processes, don't bother. */
1790 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1793 /* We only need to change the remote current thread if it's pointing
1794 at some other process. */
1795 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1796 set_general_thread (inferior_ptid
);
1800 /* Return nonzero if the thread PTID is still alive on the remote
1804 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1806 struct remote_state
*rs
= get_remote_state ();
1809 if (ptid_equal (ptid
, magic_null_ptid
))
1810 /* The main thread is always alive. */
1813 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1814 /* The main thread is always alive. This can happen after a
1815 vAttach, if the remote side doesn't support
1820 endp
= rs
->buf
+ get_remote_packet_size ();
1823 write_ptid (p
, endp
, ptid
);
1826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1827 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1830 /* About these extended threadlist and threadinfo packets. They are
1831 variable length packets but, the fields within them are often fixed
1832 length. They are redundent enough to send over UDP as is the
1833 remote protocol in general. There is a matching unit test module
1836 #define OPAQUETHREADBYTES 8
1838 /* a 64 bit opaque identifier */
1839 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1841 /* WARNING: This threadref data structure comes from the remote O.S.,
1842 libstub protocol encoding, and remote.c. It is not particularly
1845 /* Right now, the internal structure is int. We want it to be bigger.
1846 Plan to fix this. */
1848 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1850 /* gdb_ext_thread_info is an internal GDB data structure which is
1851 equivalent to the reply of the remote threadinfo packet. */
1853 struct gdb_ext_thread_info
1855 threadref threadid
; /* External form of thread reference. */
1856 int active
; /* Has state interesting to GDB?
1858 char display
[256]; /* Brief state display, name,
1859 blocked/suspended. */
1860 char shortname
[32]; /* To be used to name threads. */
1861 char more_display
[256]; /* Long info, statistics, queue depth,
1865 /* The volume of remote transfers can be limited by submitting
1866 a mask containing bits specifying the desired information.
1867 Use a union of these values as the 'selection' parameter to
1868 get_thread_info. FIXME: Make these TAG names more thread specific. */
1870 #define TAG_THREADID 1
1871 #define TAG_EXISTS 2
1872 #define TAG_DISPLAY 4
1873 #define TAG_THREADNAME 8
1874 #define TAG_MOREDISPLAY 16
1876 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1878 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1880 static char *unpack_nibble (char *buf
, int *val
);
1882 static char *pack_nibble (char *buf
, int nibble
);
1884 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1886 static char *unpack_byte (char *buf
, int *value
);
1888 static char *pack_int (char *buf
, int value
);
1890 static char *unpack_int (char *buf
, int *value
);
1892 static char *unpack_string (char *src
, char *dest
, int length
);
1894 static char *pack_threadid (char *pkt
, threadref
*id
);
1896 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1898 void int_to_threadref (threadref
*id
, int value
);
1900 static int threadref_to_int (threadref
*ref
);
1902 static void copy_threadref (threadref
*dest
, threadref
*src
);
1904 static int threadmatch (threadref
*dest
, threadref
*src
);
1906 static char *pack_threadinfo_request (char *pkt
, int mode
,
1909 static int remote_unpack_thread_info_response (char *pkt
,
1910 threadref
*expectedref
,
1911 struct gdb_ext_thread_info
1915 static int remote_get_threadinfo (threadref
*threadid
,
1916 int fieldset
, /*TAG mask */
1917 struct gdb_ext_thread_info
*info
);
1919 static char *pack_threadlist_request (char *pkt
, int startflag
,
1921 threadref
*nextthread
);
1923 static int parse_threadlist_response (char *pkt
,
1925 threadref
*original_echo
,
1926 threadref
*resultlist
,
1929 static int remote_get_threadlist (int startflag
,
1930 threadref
*nextthread
,
1934 threadref
*threadlist
);
1936 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1938 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1939 void *context
, int looplimit
);
1941 static int remote_newthread_step (threadref
*ref
, void *context
);
1944 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1945 buffer we're allowed to write to. Returns
1946 BUF+CHARACTERS_WRITTEN. */
1949 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1952 struct remote_state
*rs
= get_remote_state ();
1954 if (remote_multi_process_p (rs
))
1956 pid
= ptid_get_pid (ptid
);
1958 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1960 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1962 tid
= ptid_get_tid (ptid
);
1964 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1966 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1971 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1972 passed the last parsed char. Returns null_ptid on error. */
1975 read_ptid (char *buf
, char **obuf
)
1979 ULONGEST pid
= 0, tid
= 0;
1983 /* Multi-process ptid. */
1984 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1986 error (_("invalid remote ptid: %s"), p
);
1989 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1992 return ptid_build (pid
, 0, tid
);
1995 /* No multi-process. Just a tid. */
1996 pp
= unpack_varlen_hex (p
, &tid
);
1998 /* Since the stub is not sending a process id, then default to
1999 what's in inferior_ptid, unless it's null at this point. If so,
2000 then since there's no way to know the pid of the reported
2001 threads, use the magic number. */
2002 if (ptid_equal (inferior_ptid
, null_ptid
))
2003 pid
= ptid_get_pid (magic_null_ptid
);
2005 pid
= ptid_get_pid (inferior_ptid
);
2009 return ptid_build (pid
, 0, tid
);
2012 /* Encode 64 bits in 16 chars of hex. */
2014 static const char hexchars
[] = "0123456789abcdef";
2017 ishex (int ch
, int *val
)
2019 if ((ch
>= 'a') && (ch
<= 'f'))
2021 *val
= ch
- 'a' + 10;
2024 if ((ch
>= 'A') && (ch
<= 'F'))
2026 *val
= ch
- 'A' + 10;
2029 if ((ch
>= '0') && (ch
<= '9'))
2040 if (ch
>= 'a' && ch
<= 'f')
2041 return ch
- 'a' + 10;
2042 if (ch
>= '0' && ch
<= '9')
2044 if (ch
>= 'A' && ch
<= 'F')
2045 return ch
- 'A' + 10;
2050 stub_unpack_int (char *buff
, int fieldlength
)
2057 nibble
= stubhex (*buff
++);
2061 retval
= retval
<< 4;
2067 unpack_varlen_hex (char *buff
, /* packet to parse */
2071 ULONGEST retval
= 0;
2073 while (ishex (*buff
, &nibble
))
2076 retval
= retval
<< 4;
2077 retval
|= nibble
& 0x0f;
2084 unpack_nibble (char *buf
, int *val
)
2086 *val
= fromhex (*buf
++);
2091 pack_nibble (char *buf
, int nibble
)
2093 *buf
++ = hexchars
[(nibble
& 0x0f)];
2098 pack_hex_byte (char *pkt
, int byte
)
2100 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2101 *pkt
++ = hexchars
[(byte
& 0xf)];
2106 unpack_byte (char *buf
, int *value
)
2108 *value
= stub_unpack_int (buf
, 2);
2113 pack_int (char *buf
, int value
)
2115 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2116 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2117 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2118 buf
= pack_hex_byte (buf
, (value
& 0xff));
2123 unpack_int (char *buf
, int *value
)
2125 *value
= stub_unpack_int (buf
, 8);
2129 #if 0 /* Currently unused, uncomment when needed. */
2130 static char *pack_string (char *pkt
, char *string
);
2133 pack_string (char *pkt
, char *string
)
2138 len
= strlen (string
);
2140 len
= 200; /* Bigger than most GDB packets, junk??? */
2141 pkt
= pack_hex_byte (pkt
, len
);
2145 if ((ch
== '\0') || (ch
== '#'))
2146 ch
= '*'; /* Protect encapsulation. */
2151 #endif /* 0 (unused) */
2154 unpack_string (char *src
, char *dest
, int length
)
2163 pack_threadid (char *pkt
, threadref
*id
)
2166 unsigned char *altid
;
2168 altid
= (unsigned char *) id
;
2169 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2171 pkt
= pack_hex_byte (pkt
, *altid
++);
2177 unpack_threadid (char *inbuf
, threadref
*id
)
2180 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2183 altref
= (char *) id
;
2185 while (inbuf
< limit
)
2187 x
= stubhex (*inbuf
++);
2188 y
= stubhex (*inbuf
++);
2189 *altref
++ = (x
<< 4) | y
;
2194 /* Externally, threadrefs are 64 bits but internally, they are still
2195 ints. This is due to a mismatch of specifications. We would like
2196 to use 64bit thread references internally. This is an adapter
2200 int_to_threadref (threadref
*id
, int value
)
2202 unsigned char *scan
;
2204 scan
= (unsigned char *) id
;
2210 *scan
++ = (value
>> 24) & 0xff;
2211 *scan
++ = (value
>> 16) & 0xff;
2212 *scan
++ = (value
>> 8) & 0xff;
2213 *scan
++ = (value
& 0xff);
2217 threadref_to_int (threadref
*ref
)
2220 unsigned char *scan
;
2226 value
= (value
<< 8) | ((*scan
++) & 0xff);
2231 copy_threadref (threadref
*dest
, threadref
*src
)
2234 unsigned char *csrc
, *cdest
;
2236 csrc
= (unsigned char *) src
;
2237 cdest
= (unsigned char *) dest
;
2244 threadmatch (threadref
*dest
, threadref
*src
)
2246 /* Things are broken right now, so just assume we got a match. */
2248 unsigned char *srcp
, *destp
;
2250 srcp
= (char *) src
;
2251 destp
= (char *) dest
;
2255 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2262 threadid:1, # always request threadid
2269 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2272 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2274 *pkt
++ = 'q'; /* Info Query */
2275 *pkt
++ = 'P'; /* process or thread info */
2276 pkt
= pack_int (pkt
, mode
); /* mode */
2277 pkt
= pack_threadid (pkt
, id
); /* threadid */
2278 *pkt
= '\0'; /* terminate */
2282 /* These values tag the fields in a thread info response packet. */
2283 /* Tagging the fields allows us to request specific fields and to
2284 add more fields as time goes by. */
2286 #define TAG_THREADID 1 /* Echo the thread identifier. */
2287 #define TAG_EXISTS 2 /* Is this process defined enough to
2288 fetch registers and its stack? */
2289 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2290 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2291 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2295 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2296 struct gdb_ext_thread_info
*info
)
2298 struct remote_state
*rs
= get_remote_state ();
2302 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2305 /* info->threadid = 0; FIXME: implement zero_threadref. */
2307 info
->display
[0] = '\0';
2308 info
->shortname
[0] = '\0';
2309 info
->more_display
[0] = '\0';
2311 /* Assume the characters indicating the packet type have been
2313 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2314 pkt
= unpack_threadid (pkt
, &ref
);
2317 warning (_("Incomplete response to threadinfo request."));
2318 if (!threadmatch (&ref
, expectedref
))
2319 { /* This is an answer to a different request. */
2320 warning (_("ERROR RMT Thread info mismatch."));
2323 copy_threadref (&info
->threadid
, &ref
);
2325 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2327 /* Packets are terminated with nulls. */
2328 while ((pkt
< limit
) && mask
&& *pkt
)
2330 pkt
= unpack_int (pkt
, &tag
); /* tag */
2331 pkt
= unpack_byte (pkt
, &length
); /* length */
2332 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2334 warning (_("ERROR RMT: threadinfo tag mismatch."));
2338 if (tag
== TAG_THREADID
)
2342 warning (_("ERROR RMT: length of threadid is not 16."));
2346 pkt
= unpack_threadid (pkt
, &ref
);
2347 mask
= mask
& ~TAG_THREADID
;
2350 if (tag
== TAG_EXISTS
)
2352 info
->active
= stub_unpack_int (pkt
, length
);
2354 mask
= mask
& ~(TAG_EXISTS
);
2357 warning (_("ERROR RMT: 'exists' length too long."));
2363 if (tag
== TAG_THREADNAME
)
2365 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2366 mask
= mask
& ~TAG_THREADNAME
;
2369 if (tag
== TAG_DISPLAY
)
2371 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2372 mask
= mask
& ~TAG_DISPLAY
;
2375 if (tag
== TAG_MOREDISPLAY
)
2377 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2378 mask
= mask
& ~TAG_MOREDISPLAY
;
2381 warning (_("ERROR RMT: unknown thread info tag."));
2382 break; /* Not a tag we know about. */
2388 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2389 struct gdb_ext_thread_info
*info
)
2391 struct remote_state
*rs
= get_remote_state ();
2394 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2396 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2398 if (rs
->buf
[0] == '\0')
2401 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2406 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2409 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2410 threadref
*nextthread
)
2412 *pkt
++ = 'q'; /* info query packet */
2413 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2414 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2415 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2416 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2421 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2424 parse_threadlist_response (char *pkt
, int result_limit
,
2425 threadref
*original_echo
, threadref
*resultlist
,
2428 struct remote_state
*rs
= get_remote_state ();
2430 int count
, resultcount
, done
;
2433 /* Assume the 'q' and 'M chars have been stripped. */
2434 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2435 /* done parse past here */
2436 pkt
= unpack_byte (pkt
, &count
); /* count field */
2437 pkt
= unpack_nibble (pkt
, &done
);
2438 /* The first threadid is the argument threadid. */
2439 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2440 while ((count
-- > 0) && (pkt
< limit
))
2442 pkt
= unpack_threadid (pkt
, resultlist
++);
2443 if (resultcount
++ >= result_limit
)
2452 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2453 int *done
, int *result_count
, threadref
*threadlist
)
2455 struct remote_state
*rs
= get_remote_state ();
2456 static threadref echo_nextthread
;
2459 /* Trancate result limit to be smaller than the packet size. */
2460 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2461 >= get_remote_packet_size ())
2462 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2464 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2466 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2468 if (*rs
->buf
== '\0')
2472 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2475 if (!threadmatch (&echo_nextthread
, nextthread
))
2477 /* FIXME: This is a good reason to drop the packet. */
2478 /* Possably, there is a duplicate response. */
2480 retransmit immediatly - race conditions
2481 retransmit after timeout - yes
2483 wait for packet, then exit
2485 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2486 return 0; /* I choose simply exiting. */
2488 if (*result_count
<= 0)
2492 warning (_("RMT ERROR : failed to get remote thread list."));
2495 return result
; /* break; */
2497 if (*result_count
> result_limit
)
2500 warning (_("RMT ERROR: threadlist response longer than requested."));
2506 /* This is the interface between remote and threads, remotes upper
2509 /* remote_find_new_threads retrieves the thread list and for each
2510 thread in the list, looks up the thread in GDB's internal list,
2511 adding the thread if it does not already exist. This involves
2512 getting partial thread lists from the remote target so, polling the
2513 quit_flag is required. */
2516 /* About this many threadisds fit in a packet. */
2518 #define MAXTHREADLISTRESULTS 32
2521 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2524 int done
, i
, result_count
;
2528 static threadref nextthread
;
2529 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2534 if (loopcount
++ > looplimit
)
2537 warning (_("Remote fetch threadlist -infinite loop-."));
2540 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2541 &done
, &result_count
, resultthreadlist
))
2546 /* Clear for later iterations. */
2548 /* Setup to resume next batch of thread references, set nextthread. */
2549 if (result_count
>= 1)
2550 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2552 while (result_count
--)
2553 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2560 remote_newthread_step (threadref
*ref
, void *context
)
2562 int pid
= ptid_get_pid (inferior_ptid
);
2563 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2565 if (!in_thread_list (ptid
))
2567 return 1; /* continue iterator */
2570 #define CRAZY_MAX_THREADS 1000
2573 remote_current_thread (ptid_t oldpid
)
2575 struct remote_state
*rs
= get_remote_state ();
2578 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2579 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2580 return read_ptid (&rs
->buf
[2], NULL
);
2585 /* Find new threads for info threads command.
2586 * Original version, using John Metzler's thread protocol.
2590 remote_find_new_threads (void)
2592 remote_threadlist_iterator (remote_newthread_step
, 0,
2596 #if defined(HAVE_LIBEXPAT)
2598 typedef struct thread_item
2604 DEF_VEC_O(thread_item_t
);
2606 struct threads_parsing_context
2608 VEC (thread_item_t
) *items
;
2612 start_thread (struct gdb_xml_parser
*parser
,
2613 const struct gdb_xml_element
*element
,
2614 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2616 struct threads_parsing_context
*data
= user_data
;
2618 struct thread_item item
;
2620 struct gdb_xml_value
*attr
;
2622 id
= xml_find_attribute (attributes
, "id")->value
;
2623 item
.ptid
= read_ptid (id
, NULL
);
2625 attr
= xml_find_attribute (attributes
, "core");
2627 item
.core
= *(ULONGEST
*) attr
->value
;
2633 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2637 end_thread (struct gdb_xml_parser
*parser
,
2638 const struct gdb_xml_element
*element
,
2639 void *user_data
, const char *body_text
)
2641 struct threads_parsing_context
*data
= user_data
;
2643 if (body_text
&& *body_text
)
2644 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2647 const struct gdb_xml_attribute thread_attributes
[] = {
2648 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2649 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2650 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2653 const struct gdb_xml_element thread_children
[] = {
2654 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2657 const struct gdb_xml_element threads_children
[] = {
2658 { "thread", thread_attributes
, thread_children
,
2659 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2660 start_thread
, end_thread
},
2661 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2664 const struct gdb_xml_element threads_elements
[] = {
2665 { "threads", NULL
, threads_children
,
2666 GDB_XML_EF_NONE
, NULL
, NULL
},
2667 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2670 /* Discard the contents of the constructed thread info context. */
2673 clear_threads_parsing_context (void *p
)
2675 struct threads_parsing_context
*context
= p
;
2677 struct thread_item
*item
;
2679 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2680 xfree (item
->extra
);
2682 VEC_free (thread_item_t
, context
->items
);
2688 * Find all threads for info threads command.
2689 * Uses new thread protocol contributed by Cisco.
2690 * Falls back and attempts to use the older method (above)
2691 * if the target doesn't respond to the new method.
2695 remote_threads_info (struct target_ops
*ops
)
2697 struct remote_state
*rs
= get_remote_state ();
2701 if (remote_desc
== 0) /* paranoia */
2702 error (_("Command can only be used when connected to the remote target."));
2704 #if defined(HAVE_LIBEXPAT)
2705 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2707 char *xml
= target_read_stralloc (¤t_target
,
2708 TARGET_OBJECT_THREADS
, NULL
);
2710 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2714 struct threads_parsing_context context
;
2716 context
.items
= NULL
;
2717 make_cleanup (clear_threads_parsing_context
, &context
);
2719 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2720 threads_elements
, xml
, &context
) == 0)
2723 struct thread_item
*item
;
2726 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2729 if (!ptid_equal (item
->ptid
, null_ptid
))
2731 struct private_thread_info
*info
;
2732 /* In non-stop mode, we assume new found threads
2733 are running until proven otherwise with a
2734 stop reply. In all-stop, we can only get
2735 here if all threads are stopped. */
2736 int running
= non_stop
? 1 : 0;
2738 remote_notice_new_inferior (item
->ptid
, running
);
2740 info
= demand_private_info (item
->ptid
);
2741 info
->core
= item
->core
;
2742 info
->extra
= item
->extra
;
2749 do_cleanups (back_to
);
2754 if (use_threadinfo_query
)
2756 putpkt ("qfThreadInfo");
2757 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2759 if (bufp
[0] != '\0') /* q packet recognized */
2761 struct cleanup
*old_chain
;
2764 /* remote_notice_new_inferior (in the loop below) may make
2765 new RSP calls, which clobber rs->buf. Work with a
2767 bufp
= saved_reply
= xstrdup (rs
->buf
);
2768 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2770 while (*bufp
++ == 'm') /* reply contains one or more TID */
2774 new_thread
= read_ptid (bufp
, &bufp
);
2775 if (!ptid_equal (new_thread
, null_ptid
))
2777 /* In non-stop mode, we assume new found threads
2778 are running until proven otherwise with a
2779 stop reply. In all-stop, we can only get
2780 here if all threads are stopped. */
2781 int running
= non_stop
? 1 : 0;
2783 remote_notice_new_inferior (new_thread
, running
);
2786 while (*bufp
++ == ','); /* comma-separated list */
2787 free_current_contents (&saved_reply
);
2788 putpkt ("qsThreadInfo");
2789 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2790 bufp
= saved_reply
= xstrdup (rs
->buf
);
2792 do_cleanups (old_chain
);
2797 /* Only qfThreadInfo is supported in non-stop mode. */
2801 /* Else fall back to old method based on jmetzler protocol. */
2802 use_threadinfo_query
= 0;
2803 remote_find_new_threads ();
2808 * Collect a descriptive string about the given thread.
2809 * The target may say anything it wants to about the thread
2810 * (typically info about its blocked / runnable state, name, etc.).
2811 * This string will appear in the info threads display.
2813 * Optional: targets are not required to implement this function.
2817 remote_threads_extra_info (struct thread_info
*tp
)
2819 struct remote_state
*rs
= get_remote_state ();
2823 struct gdb_ext_thread_info threadinfo
;
2824 static char display_buf
[100]; /* arbitrary... */
2825 int n
= 0; /* position in display_buf */
2827 if (remote_desc
== 0) /* paranoia */
2828 internal_error (__FILE__
, __LINE__
,
2829 _("remote_threads_extra_info"));
2831 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2832 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2833 /* This is the main thread which was added by GDB. The remote
2834 server doesn't know about it. */
2837 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2839 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2841 if (info
&& info
->private)
2842 return info
->private->extra
;
2847 if (use_threadextra_query
)
2850 char *endb
= rs
->buf
+ get_remote_packet_size ();
2852 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2854 write_ptid (b
, endb
, tp
->ptid
);
2857 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2858 if (rs
->buf
[0] != 0)
2860 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2861 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2862 display_buf
[result
] = '\0';
2867 /* If the above query fails, fall back to the old method. */
2868 use_threadextra_query
= 0;
2869 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2870 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2871 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2872 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2873 if (threadinfo
.active
)
2875 if (*threadinfo
.shortname
)
2876 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2877 " Name: %s,", threadinfo
.shortname
);
2878 if (*threadinfo
.display
)
2879 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2880 " State: %s,", threadinfo
.display
);
2881 if (*threadinfo
.more_display
)
2882 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2883 " Priority: %s", threadinfo
.more_display
);
2887 /* For purely cosmetic reasons, clear up trailing commas. */
2888 if (',' == display_buf
[n
-1])
2889 display_buf
[n
-1] = ' ';
2898 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2899 struct static_tracepoint_marker
*marker
)
2901 struct remote_state
*rs
= get_remote_state ();
2904 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2906 p
+= hexnumstr (p
, addr
);
2908 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2912 error (_("Remote failure reply: %s"), p
);
2916 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2923 static VEC(static_tracepoint_marker_p
) *
2924 remote_static_tracepoint_markers_by_strid (const char *strid
)
2926 struct remote_state
*rs
= get_remote_state ();
2927 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2928 struct static_tracepoint_marker
*marker
= NULL
;
2929 struct cleanup
*old_chain
;
2932 /* Ask for a first packet of static tracepoint marker
2935 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2938 error (_("Remote failure reply: %s"), p
);
2940 old_chain
= make_cleanup (free_current_marker
, &marker
);
2945 marker
= XCNEW (struct static_tracepoint_marker
);
2949 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2951 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2953 VEC_safe_push (static_tracepoint_marker_p
,
2959 release_static_tracepoint_marker (marker
);
2960 memset (marker
, 0, sizeof (*marker
));
2963 while (*p
++ == ','); /* comma-separated list */
2964 /* Ask for another packet of static tracepoint definition. */
2966 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2970 do_cleanups (old_chain
);
2975 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2978 remote_get_ada_task_ptid (long lwp
, long thread
)
2980 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2984 /* Restart the remote side; this is an extended protocol operation. */
2987 extended_remote_restart (void)
2989 struct remote_state
*rs
= get_remote_state ();
2991 /* Send the restart command; for reasons I don't understand the
2992 remote side really expects a number after the "R". */
2993 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2996 remote_fileio_reset ();
2999 /* Clean up connection to a remote debugger. */
3004 if (remote_desc
== NULL
)
3005 return; /* already closed */
3007 /* Make sure we leave stdin registered in the event loop, and we
3008 don't leave the async SIGINT signal handler installed. */
3009 remote_terminal_ours ();
3011 serial_close (remote_desc
);
3014 /* We don't have a connection to the remote stub anymore. Get rid
3015 of all the inferiors and their threads we were controlling.
3016 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3017 will be unable to find the thread corresponding to (pid, 0, 0). */
3018 inferior_ptid
= null_ptid
;
3019 discard_all_inferiors ();
3021 /* Stop replies may from inferiors which are still unknown to GDB.
3022 We are closing the remote target, so we should discard
3023 everything, including the stop replies from GDB-unknown
3025 discard_pending_stop_replies (NULL
);
3027 if (remote_async_inferior_event_token
)
3028 delete_async_event_handler (&remote_async_inferior_event_token
);
3030 remote_notif_unregister_async_event_handler ();
3033 /* Query the remote side for the text, data and bss offsets. */
3038 struct remote_state
*rs
= get_remote_state ();
3041 int lose
, num_segments
= 0, do_sections
, do_segments
;
3042 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3043 struct section_offsets
*offs
;
3044 struct symfile_segment_data
*data
;
3046 if (symfile_objfile
== NULL
)
3049 putpkt ("qOffsets");
3050 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3053 if (buf
[0] == '\000')
3054 return; /* Return silently. Stub doesn't support
3058 warning (_("Remote failure reply: %s"), buf
);
3062 /* Pick up each field in turn. This used to be done with scanf, but
3063 scanf will make trouble if CORE_ADDR size doesn't match
3064 conversion directives correctly. The following code will work
3065 with any size of CORE_ADDR. */
3066 text_addr
= data_addr
= bss_addr
= 0;
3070 if (strncmp (ptr
, "Text=", 5) == 0)
3073 /* Don't use strtol, could lose on big values. */
3074 while (*ptr
&& *ptr
!= ';')
3075 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3077 if (strncmp (ptr
, ";Data=", 6) == 0)
3080 while (*ptr
&& *ptr
!= ';')
3081 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3086 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3089 while (*ptr
&& *ptr
!= ';')
3090 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3092 if (bss_addr
!= data_addr
)
3093 warning (_("Target reported unsupported offsets: %s"), buf
);
3098 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3101 /* Don't use strtol, could lose on big values. */
3102 while (*ptr
&& *ptr
!= ';')
3103 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3106 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3109 while (*ptr
&& *ptr
!= ';')
3110 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3118 error (_("Malformed response to offset query, %s"), buf
);
3119 else if (*ptr
!= '\0')
3120 warning (_("Target reported unsupported offsets: %s"), buf
);
3122 offs
= ((struct section_offsets
*)
3123 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3124 memcpy (offs
, symfile_objfile
->section_offsets
,
3125 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3127 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3128 do_segments
= (data
!= NULL
);
3129 do_sections
= num_segments
== 0;
3131 if (num_segments
> 0)
3133 segments
[0] = text_addr
;
3134 segments
[1] = data_addr
;
3136 /* If we have two segments, we can still try to relocate everything
3137 by assuming that the .text and .data offsets apply to the whole
3138 text and data segments. Convert the offsets given in the packet
3139 to base addresses for symfile_map_offsets_to_segments. */
3140 else if (data
&& data
->num_segments
== 2)
3142 segments
[0] = data
->segment_bases
[0] + text_addr
;
3143 segments
[1] = data
->segment_bases
[1] + data_addr
;
3146 /* If the object file has only one segment, assume that it is text
3147 rather than data; main programs with no writable data are rare,
3148 but programs with no code are useless. Of course the code might
3149 have ended up in the data segment... to detect that we would need
3150 the permissions here. */
3151 else if (data
&& data
->num_segments
== 1)
3153 segments
[0] = data
->segment_bases
[0] + text_addr
;
3156 /* There's no way to relocate by segment. */
3162 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3163 offs
, num_segments
, segments
);
3165 if (ret
== 0 && !do_sections
)
3166 error (_("Can not handle qOffsets TextSeg "
3167 "response with this symbol file"));
3174 free_symfile_segment_data (data
);
3178 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3180 /* This is a temporary kludge to force data and bss to use the
3181 same offsets because that's what nlmconv does now. The real
3182 solution requires changes to the stub and remote.c that I
3183 don't have time to do right now. */
3185 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3186 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3189 objfile_relocate (symfile_objfile
, offs
);
3192 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3193 threads we know are stopped already. This is used during the
3194 initial remote connection in non-stop mode --- threads that are
3195 reported as already being stopped are left stopped. */
3198 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3200 /* If we have a stop reply for this thread, it must be stopped. */
3201 if (peek_stop_reply (thread
->ptid
))
3202 set_stop_requested (thread
->ptid
, 1);
3207 /* Send interrupt_sequence to remote target. */
3209 send_interrupt_sequence (void)
3211 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3212 serial_write (remote_desc
, "\x03", 1);
3213 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3214 serial_send_break (remote_desc
);
3215 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3217 serial_send_break (remote_desc
);
3218 serial_write (remote_desc
, "g", 1);
3221 internal_error (__FILE__
, __LINE__
,
3222 _("Invalid value for interrupt_sequence_mode: %s."),
3223 interrupt_sequence_mode
);
3227 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3228 and extract the PTID. Returns NULL_PTID if not found. */
3231 stop_reply_extract_thread (char *stop_reply
)
3233 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3237 /* Txx r:val ; r:val (...) */
3240 /* Look for "register" named "thread". */
3245 p1
= strchr (p
, ':');
3249 if (strncmp (p
, "thread", p1
- p
) == 0)
3250 return read_ptid (++p1
, &p
);
3252 p1
= strchr (p
, ';');
3264 /* Query the remote target for which is the current thread/process,
3265 add it to our tables, and update INFERIOR_PTID. The caller is
3266 responsible for setting the state such that the remote end is ready
3267 to return the current thread.
3269 This function is called after handling the '?' or 'vRun' packets,
3270 whose response is a stop reply from which we can also try
3271 extracting the thread. If the target doesn't support the explicit
3272 qC query, we infer the current thread from that stop reply, passed
3273 in in WAIT_STATUS, which may be NULL. */
3276 add_current_inferior_and_thread (char *wait_status
)
3278 struct remote_state
*rs
= get_remote_state ();
3280 ptid_t ptid
= null_ptid
;
3282 inferior_ptid
= null_ptid
;
3284 /* Now, if we have thread information, update inferior_ptid. First
3285 if we have a stop reply handy, maybe it's a T stop reply with a
3286 "thread" register we can extract the current thread from. If
3287 not, ask the remote which is the current thread, with qC. The
3288 former method avoids a roundtrip. Note we don't use
3289 remote_parse_stop_reply as that makes use of the target
3290 architecture, which we haven't yet fully determined at this
3292 if (wait_status
!= NULL
)
3293 ptid
= stop_reply_extract_thread (wait_status
);
3294 if (ptid_equal (ptid
, null_ptid
))
3295 ptid
= remote_current_thread (inferior_ptid
);
3297 if (!ptid_equal (ptid
, null_ptid
))
3299 if (!remote_multi_process_p (rs
))
3302 inferior_ptid
= ptid
;
3306 /* Without this, some commands which require an active target
3307 (such as kill) won't work. This variable serves (at least)
3308 double duty as both the pid of the target process (if it has
3309 such), and as a flag indicating that a target is active. */
3310 inferior_ptid
= magic_null_ptid
;
3314 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3316 /* Add the main thread. */
3317 add_thread_silent (inferior_ptid
);
3321 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3323 struct remote_state
*rs
= get_remote_state ();
3324 struct packet_config
*noack_config
;
3325 char *wait_status
= NULL
;
3327 immediate_quit
++; /* Allow user to interrupt it. */
3330 if (interrupt_on_connect
)
3331 send_interrupt_sequence ();
3333 /* Ack any packet which the remote side has already sent. */
3334 serial_write (remote_desc
, "+", 1);
3336 /* Signal other parts that we're going through the initial setup,
3337 and so things may not be stable yet. */
3338 rs
->starting_up
= 1;
3340 /* The first packet we send to the target is the optional "supported
3341 packets" request. If the target can answer this, it will tell us
3342 which later probes to skip. */
3343 remote_query_supported ();
3345 /* If the stub wants to get a QAllow, compose one and send it. */
3346 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3347 remote_set_permissions ();
3349 /* Next, we possibly activate noack mode.
3351 If the QStartNoAckMode packet configuration is set to AUTO,
3352 enable noack mode if the stub reported a wish for it with
3355 If set to TRUE, then enable noack mode even if the stub didn't
3356 report it in qSupported. If the stub doesn't reply OK, the
3357 session ends with an error.
3359 If FALSE, then don't activate noack mode, regardless of what the
3360 stub claimed should be the default with qSupported. */
3362 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3364 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3365 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3366 && noack_config
->support
== PACKET_ENABLE
))
3368 putpkt ("QStartNoAckMode");
3369 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3370 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3376 /* Tell the remote that we are using the extended protocol. */
3378 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3381 /* Let the target know which signals it is allowed to pass down to
3383 update_signals_program_target ();
3385 /* Next, if the target can specify a description, read it. We do
3386 this before anything involving memory or registers. */
3387 target_find_description ();
3389 /* Next, now that we know something about the target, update the
3390 address spaces in the program spaces. */
3391 update_address_spaces ();
3393 /* On OSs where the list of libraries is global to all
3394 processes, we fetch them early. */
3395 if (gdbarch_has_global_solist (target_gdbarch ()))
3396 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3400 if (!rs
->non_stop_aware
)
3401 error (_("Non-stop mode requested, but remote "
3402 "does not support non-stop"));
3404 putpkt ("QNonStop:1");
3405 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3407 if (strcmp (rs
->buf
, "OK") != 0)
3408 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3410 /* Find about threads and processes the stub is already
3411 controlling. We default to adding them in the running state.
3412 The '?' query below will then tell us about which threads are
3414 remote_threads_info (target
);
3416 else if (rs
->non_stop_aware
)
3418 /* Don't assume that the stub can operate in all-stop mode.
3419 Request it explicitly. */
3420 putpkt ("QNonStop:0");
3421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3423 if (strcmp (rs
->buf
, "OK") != 0)
3424 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3427 /* Check whether the target is running now. */
3429 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3435 struct inferior
*inf
;
3437 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3440 error (_("The target is not running (try extended-remote?)"));
3442 /* We're connected, but not running. Drop out before we
3443 call start_remote. */
3444 rs
->starting_up
= 0;
3449 /* Save the reply for later. */
3450 wait_status
= alloca (strlen (rs
->buf
) + 1);
3451 strcpy (wait_status
, rs
->buf
);
3454 /* Let the stub know that we want it to return the thread. */
3455 set_continue_thread (minus_one_ptid
);
3457 add_current_inferior_and_thread (wait_status
);
3459 /* init_wait_for_inferior should be called before get_offsets in order
3460 to manage `inserted' flag in bp loc in a correct state.
3461 breakpoint_init_inferior, called from init_wait_for_inferior, set
3462 `inserted' flag to 0, while before breakpoint_re_set, called from
3463 start_remote, set `inserted' flag to 1. In the initialization of
3464 inferior, breakpoint_init_inferior should be called first, and then
3465 breakpoint_re_set can be called. If this order is broken, state of
3466 `inserted' flag is wrong, and cause some problems on breakpoint
3468 init_wait_for_inferior ();
3470 get_offsets (); /* Get text, data & bss offsets. */
3472 /* If we could not find a description using qXfer, and we know
3473 how to do it some other way, try again. This is not
3474 supported for non-stop; it could be, but it is tricky if
3475 there are no stopped threads when we connect. */
3476 if (remote_read_description_p (target
)
3477 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3479 target_clear_description ();
3480 target_find_description ();
3483 /* Use the previously fetched status. */
3484 gdb_assert (wait_status
!= NULL
);
3485 strcpy (rs
->buf
, wait_status
);
3486 rs
->cached_wait_status
= 1;
3489 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3493 /* Clear WFI global state. Do this before finding about new
3494 threads and inferiors, and setting the current inferior.
3495 Otherwise we would clear the proceed status of the current
3496 inferior when we want its stop_soon state to be preserved
3497 (see notice_new_inferior). */
3498 init_wait_for_inferior ();
3500 /* In non-stop, we will either get an "OK", meaning that there
3501 are no stopped threads at this time; or, a regular stop
3502 reply. In the latter case, there may be more than one thread
3503 stopped --- we pull them all out using the vStopped
3505 if (strcmp (rs
->buf
, "OK") != 0)
3507 struct notif_client
*notif
= ¬if_client_stop
;
3509 /* remote_notif_get_pending_replies acks this one, and gets
3511 notif_client_stop
.pending_event
3512 = remote_notif_parse (notif
, rs
->buf
);
3513 remote_notif_get_pending_events (notif
);
3515 /* Make sure that threads that were stopped remain
3517 iterate_over_threads (set_stop_requested_callback
, NULL
);
3520 if (target_can_async_p ())
3521 target_async (inferior_event_handler
, 0);
3523 if (thread_count () == 0)
3526 error (_("The target is not running (try extended-remote?)"));
3528 /* We're connected, but not running. Drop out before we
3529 call start_remote. */
3530 rs
->starting_up
= 0;
3534 /* Let the stub know that we want it to return the thread. */
3536 /* Force the stub to choose a thread. */
3537 set_general_thread (null_ptid
);
3540 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3541 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3542 error (_("remote didn't report the current thread in non-stop mode"));
3544 get_offsets (); /* Get text, data & bss offsets. */
3546 /* In non-stop mode, any cached wait status will be stored in
3547 the stop reply queue. */
3548 gdb_assert (wait_status
== NULL
);
3550 /* Report all signals during attach/startup. */
3551 remote_pass_signals (0, NULL
);
3554 /* If we connected to a live target, do some additional setup. */
3555 if (target_has_execution
)
3557 if (exec_bfd
) /* No use without an exec file. */
3558 remote_check_symbols (symfile_objfile
);
3561 /* Possibly the target has been engaged in a trace run started
3562 previously; find out where things are at. */
3563 if (remote_get_trace_status (current_trace_status ()) != -1)
3565 struct uploaded_tp
*uploaded_tps
= NULL
;
3566 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3568 if (current_trace_status ()->running
)
3569 printf_filtered (_("Trace is already running on the target.\n"));
3571 /* Get trace state variables first, they may be checked when
3572 parsing uploaded commands. */
3574 remote_upload_trace_state_variables (&uploaded_tsvs
);
3576 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3578 remote_upload_tracepoints (&uploaded_tps
);
3580 merge_uploaded_tracepoints (&uploaded_tps
);
3583 /* The thread and inferior lists are now synchronized with the
3584 target, our symbols have been relocated, and we're merged the
3585 target's tracepoints with ours. We're done with basic start
3587 rs
->starting_up
= 0;
3589 /* If breakpoints are global, insert them now. */
3590 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3591 && breakpoints_always_inserted_mode ())
3592 insert_breakpoints ();
3595 /* Open a connection to a remote debugger.
3596 NAME is the filename used for communication. */
3599 remote_open (char *name
, int from_tty
)
3601 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3604 /* Open a connection to a remote debugger using the extended
3605 remote gdb protocol. NAME is the filename used for communication. */
3608 extended_remote_open (char *name
, int from_tty
)
3610 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3613 /* Generic code for opening a connection to a remote target. */
3616 init_all_packet_configs (void)
3620 for (i
= 0; i
< PACKET_MAX
; i
++)
3621 update_packet_config (&remote_protocol_packets
[i
]);
3624 /* Symbol look-up. */
3627 remote_check_symbols (struct objfile
*objfile
)
3629 struct remote_state
*rs
= get_remote_state ();
3630 char *msg
, *reply
, *tmp
;
3631 struct minimal_symbol
*sym
;
3634 /* The remote side has no concept of inferiors that aren't running
3635 yet, it only knows about running processes. If we're connected
3636 but our current inferior is not running, we should not invite the
3637 remote target to request symbol lookups related to its
3638 (unrelated) current process. */
3639 if (!target_has_execution
)
3642 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3645 /* Make sure the remote is pointing at the right process. Note
3646 there's no way to select "no process". */
3647 set_general_process ();
3649 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3650 because we need both at the same time. */
3651 msg
= alloca (get_remote_packet_size ());
3653 /* Invite target to request symbol lookups. */
3655 putpkt ("qSymbol::");
3656 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3657 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3660 while (strncmp (reply
, "qSymbol:", 8) == 0)
3663 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3665 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3667 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3670 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3671 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3673 /* If this is a function address, return the start of code
3674 instead of any data function descriptor. */
3675 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3679 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3680 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3684 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3689 static struct serial
*
3690 remote_serial_open (char *name
)
3692 static int udp_warning
= 0;
3694 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3695 of in ser-tcp.c, because it is the remote protocol assuming that the
3696 serial connection is reliable and not the serial connection promising
3698 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3700 warning (_("The remote protocol may be unreliable over UDP.\n"
3701 "Some events may be lost, rendering further debugging "
3706 return serial_open (name
);
3709 /* Inform the target of our permission settings. The permission flags
3710 work without this, but if the target knows the settings, it can do
3711 a couple things. First, it can add its own check, to catch cases
3712 that somehow manage to get by the permissions checks in target
3713 methods. Second, if the target is wired to disallow particular
3714 settings (for instance, a system in the field that is not set up to
3715 be able to stop at a breakpoint), it can object to any unavailable
3719 remote_set_permissions (void)
3721 struct remote_state
*rs
= get_remote_state ();
3723 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3724 "WriteReg:%x;WriteMem:%x;"
3725 "InsertBreak:%x;InsertTrace:%x;"
3726 "InsertFastTrace:%x;Stop:%x",
3727 may_write_registers
, may_write_memory
,
3728 may_insert_breakpoints
, may_insert_tracepoints
,
3729 may_insert_fast_tracepoints
, may_stop
);
3731 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3733 /* If the target didn't like the packet, warn the user. Do not try
3734 to undo the user's settings, that would just be maddening. */
3735 if (strcmp (rs
->buf
, "OK") != 0)
3736 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3739 /* This type describes each known response to the qSupported
3741 struct protocol_feature
3743 /* The name of this protocol feature. */
3746 /* The default for this protocol feature. */
3747 enum packet_support default_support
;
3749 /* The function to call when this feature is reported, or after
3750 qSupported processing if the feature is not supported.
3751 The first argument points to this structure. The second
3752 argument indicates whether the packet requested support be
3753 enabled, disabled, or probed (or the default, if this function
3754 is being called at the end of processing and this feature was
3755 not reported). The third argument may be NULL; if not NULL, it
3756 is a NUL-terminated string taken from the packet following
3757 this feature's name and an equals sign. */
3758 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3761 /* The corresponding packet for this feature. Only used if
3762 FUNC is remote_supported_packet. */
3767 remote_supported_packet (const struct protocol_feature
*feature
,
3768 enum packet_support support
,
3769 const char *argument
)
3773 warning (_("Remote qSupported response supplied an unexpected value for"
3774 " \"%s\"."), feature
->name
);
3778 if (remote_protocol_packets
[feature
->packet
].support
3779 == PACKET_SUPPORT_UNKNOWN
)
3780 remote_protocol_packets
[feature
->packet
].support
= support
;
3784 remote_packet_size (const struct protocol_feature
*feature
,
3785 enum packet_support support
, const char *value
)
3787 struct remote_state
*rs
= get_remote_state ();
3792 if (support
!= PACKET_ENABLE
)
3795 if (value
== NULL
|| *value
== '\0')
3797 warning (_("Remote target reported \"%s\" without a size."),
3803 packet_size
= strtol (value
, &value_end
, 16);
3804 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3806 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3807 feature
->name
, value
);
3811 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3813 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3814 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3815 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3818 /* Record the new maximum packet size. */
3819 rs
->explicit_packet_size
= packet_size
;
3823 remote_multi_process_feature (const struct protocol_feature
*feature
,
3824 enum packet_support support
, const char *value
)
3826 struct remote_state
*rs
= get_remote_state ();
3828 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3832 remote_non_stop_feature (const struct protocol_feature
*feature
,
3833 enum packet_support support
, const char *value
)
3835 struct remote_state
*rs
= get_remote_state ();
3837 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3841 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3842 enum packet_support support
,
3845 struct remote_state
*rs
= get_remote_state ();
3847 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3851 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3852 enum packet_support support
,
3855 struct remote_state
*rs
= get_remote_state ();
3857 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3861 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3862 enum packet_support support
,
3865 struct remote_state
*rs
= get_remote_state ();
3867 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3871 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3872 enum packet_support support
,
3875 struct remote_state
*rs
= get_remote_state ();
3877 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3881 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3882 enum packet_support support
,
3885 struct remote_state
*rs
= get_remote_state ();
3887 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3891 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3892 enum packet_support support
,
3895 struct remote_state
*rs
= get_remote_state ();
3897 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3901 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3902 enum packet_support support
,
3905 struct remote_state
*rs
= get_remote_state ();
3907 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3911 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3912 enum packet_support support
,
3915 struct remote_state
*rs
= get_remote_state ();
3917 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3921 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3922 enum packet_support support
,
3925 struct remote_state
*rs
= get_remote_state ();
3927 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3930 static struct protocol_feature remote_protocol_features
[] = {
3931 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3932 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3933 PACKET_qXfer_auxv
},
3934 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3935 PACKET_qXfer_features
},
3936 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3937 PACKET_qXfer_libraries
},
3938 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3939 PACKET_qXfer_libraries_svr4
},
3940 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3941 PACKET_qXfer_memory_map
},
3942 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3943 PACKET_qXfer_spu_read
},
3944 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3945 PACKET_qXfer_spu_write
},
3946 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3947 PACKET_qXfer_osdata
},
3948 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3949 PACKET_qXfer_threads
},
3950 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3951 PACKET_qXfer_traceframe_info
},
3952 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3953 PACKET_QPassSignals
},
3954 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3955 PACKET_QProgramSignals
},
3956 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3957 PACKET_QStartNoAckMode
},
3958 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3959 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3960 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3961 PACKET_qXfer_siginfo_read
},
3962 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3963 PACKET_qXfer_siginfo_write
},
3964 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3965 PACKET_ConditionalTracepoints
},
3966 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
3967 PACKET_ConditionalBreakpoints
},
3968 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
3969 PACKET_BreakpointCommands
},
3970 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3971 PACKET_FastTracepoints
},
3972 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3973 PACKET_StaticTracepoints
},
3974 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3975 PACKET_InstallInTrace
},
3976 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3978 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3980 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3982 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3983 PACKET_TracepointSource
},
3984 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3986 { "EnableDisableTracepoints", PACKET_DISABLE
,
3987 remote_enable_disable_tracepoint_feature
, -1 },
3988 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3989 PACKET_qXfer_fdpic
},
3990 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3992 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3993 PACKET_QDisableRandomization
},
3994 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3995 { "QTBuffer:size", PACKET_DISABLE
,
3996 remote_supported_packet
, PACKET_QTBuffer_size
},
3997 { "tracenz", PACKET_DISABLE
,
3998 remote_string_tracing_feature
, -1 },
3999 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4000 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4001 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4002 PACKET_qXfer_btrace
}
4005 static char *remote_support_xml
;
4007 /* Register string appended to "xmlRegisters=" in qSupported query. */
4010 register_remote_support_xml (const char *xml
)
4012 #if defined(HAVE_LIBEXPAT)
4013 if (remote_support_xml
== NULL
)
4014 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4017 char *copy
= xstrdup (remote_support_xml
+ 13);
4018 char *p
= strtok (copy
, ",");
4022 if (strcmp (p
, xml
) == 0)
4029 while ((p
= strtok (NULL
, ",")) != NULL
);
4032 remote_support_xml
= reconcat (remote_support_xml
,
4033 remote_support_xml
, ",", xml
,
4040 remote_query_supported_append (char *msg
, const char *append
)
4043 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4045 return xstrdup (append
);
4049 remote_query_supported (void)
4051 struct remote_state
*rs
= get_remote_state ();
4054 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4056 /* The packet support flags are handled differently for this packet
4057 than for most others. We treat an error, a disabled packet, and
4058 an empty response identically: any features which must be reported
4059 to be used will be automatically disabled. An empty buffer
4060 accomplishes this, since that is also the representation for a list
4061 containing no features. */
4064 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4067 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4069 q
= remote_query_supported_append (q
, "multiprocess+");
4071 if (remote_support_xml
)
4072 q
= remote_query_supported_append (q
, remote_support_xml
);
4074 q
= remote_query_supported_append (q
, "qRelocInsn+");
4076 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4079 do_cleanups (old_chain
);
4081 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4083 /* If an error occured, warn, but do not return - just reset the
4084 buffer to empty and go on to disable features. */
4085 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4088 warning (_("Remote failure reply: %s"), rs
->buf
);
4093 memset (seen
, 0, sizeof (seen
));
4098 enum packet_support is_supported
;
4099 char *p
, *end
, *name_end
, *value
;
4101 /* First separate out this item from the rest of the packet. If
4102 there's another item after this, we overwrite the separator
4103 (terminated strings are much easier to work with). */
4105 end
= strchr (p
, ';');
4108 end
= p
+ strlen (p
);
4118 warning (_("empty item in \"qSupported\" response"));
4123 name_end
= strchr (p
, '=');
4126 /* This is a name=value entry. */
4127 is_supported
= PACKET_ENABLE
;
4128 value
= name_end
+ 1;
4137 is_supported
= PACKET_ENABLE
;
4141 is_supported
= PACKET_DISABLE
;
4145 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4149 warning (_("unrecognized item \"%s\" "
4150 "in \"qSupported\" response"), p
);
4156 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4157 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4159 const struct protocol_feature
*feature
;
4162 feature
= &remote_protocol_features
[i
];
4163 feature
->func (feature
, is_supported
, value
);
4168 /* If we increased the packet size, make sure to increase the global
4169 buffer size also. We delay this until after parsing the entire
4170 qSupported packet, because this is the same buffer we were
4172 if (rs
->buf_size
< rs
->explicit_packet_size
)
4174 rs
->buf_size
= rs
->explicit_packet_size
;
4175 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4178 /* Handle the defaults for unmentioned features. */
4179 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4182 const struct protocol_feature
*feature
;
4184 feature
= &remote_protocol_features
[i
];
4185 feature
->func (feature
, feature
->default_support
, NULL
);
4189 /* Remove any of the remote.c targets from target stack. Upper targets depend
4190 on it so remove them first. */
4193 remote_unpush_target (void)
4195 pop_all_targets_above (process_stratum
- 1);
4199 remote_open_1 (char *name
, int from_tty
,
4200 struct target_ops
*target
, int extended_p
)
4202 struct remote_state
*rs
= get_remote_state ();
4205 error (_("To open a remote debug connection, you need to specify what\n"
4206 "serial device is attached to the remote system\n"
4207 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4209 /* See FIXME above. */
4210 if (!target_async_permitted
)
4211 wait_forever_enabled_p
= 1;
4213 /* If we're connected to a running target, target_preopen will kill it.
4214 Ask this question first, before target_preopen has a chance to kill
4216 if (remote_desc
!= NULL
&& !have_inferiors ())
4219 && !query (_("Already connected to a remote target. Disconnect? ")))
4220 error (_("Still connected."));
4223 /* Here the possibly existing remote target gets unpushed. */
4224 target_preopen (from_tty
);
4226 /* Make sure we send the passed signals list the next time we resume. */
4227 xfree (last_pass_packet
);
4228 last_pass_packet
= NULL
;
4230 /* Make sure we send the program signals list the next time we
4232 xfree (last_program_signals_packet
);
4233 last_program_signals_packet
= NULL
;
4235 remote_fileio_reset ();
4236 reopen_exec_file ();
4239 remote_desc
= remote_serial_open (name
);
4241 perror_with_name (name
);
4243 if (baud_rate
!= -1)
4245 if (serial_setbaudrate (remote_desc
, baud_rate
))
4247 /* The requested speed could not be set. Error out to
4248 top level after closing remote_desc. Take care to
4249 set remote_desc to NULL to avoid closing remote_desc
4251 serial_close (remote_desc
);
4253 perror_with_name (name
);
4257 serial_raw (remote_desc
);
4259 /* If there is something sitting in the buffer we might take it as a
4260 response to a command, which would be bad. */
4261 serial_flush_input (remote_desc
);
4265 puts_filtered ("Remote debugging using ");
4266 puts_filtered (name
);
4267 puts_filtered ("\n");
4269 push_target (target
); /* Switch to using remote target now. */
4271 /* Register extra event sources in the event loop. */
4272 remote_async_inferior_event_token
4273 = create_async_event_handler (remote_async_inferior_event_handler
,
4275 remote_notif_register_async_event_handler ();
4277 /* Reset the target state; these things will be queried either by
4278 remote_query_supported or as they are needed. */
4279 init_all_packet_configs ();
4280 rs
->cached_wait_status
= 0;
4281 rs
->explicit_packet_size
= 0;
4283 rs
->multi_process_aware
= 0;
4284 rs
->extended
= extended_p
;
4285 rs
->non_stop_aware
= 0;
4286 rs
->waiting_for_stop_reply
= 0;
4287 rs
->ctrlc_pending_p
= 0;
4289 general_thread
= not_sent_ptid
;
4290 continue_thread
= not_sent_ptid
;
4291 remote_traceframe_number
= -1;
4293 /* Probe for ability to use "ThreadInfo" query, as required. */
4294 use_threadinfo_query
= 1;
4295 use_threadextra_query
= 1;
4297 if (target_async_permitted
)
4299 /* With this target we start out by owning the terminal. */
4300 remote_async_terminal_ours_p
= 1;
4302 /* FIXME: cagney/1999-09-23: During the initial connection it is
4303 assumed that the target is already ready and able to respond to
4304 requests. Unfortunately remote_start_remote() eventually calls
4305 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4306 around this. Eventually a mechanism that allows
4307 wait_for_inferior() to expect/get timeouts will be
4309 wait_forever_enabled_p
= 0;
4312 /* First delete any symbols previously loaded from shared libraries. */
4313 no_shared_libraries (NULL
, 0);
4316 init_thread_list ();
4318 /* Start the remote connection. If error() or QUIT, discard this
4319 target (we'd otherwise be in an inconsistent state) and then
4320 propogate the error on up the exception chain. This ensures that
4321 the caller doesn't stumble along blindly assuming that the
4322 function succeeded. The CLI doesn't have this problem but other
4323 UI's, such as MI do.
4325 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4326 this function should return an error indication letting the
4327 caller restore the previous state. Unfortunately the command
4328 ``target remote'' is directly wired to this function making that
4329 impossible. On a positive note, the CLI side of this problem has
4330 been fixed - the function set_cmd_context() makes it possible for
4331 all the ``target ....'' commands to share a common callback
4332 function. See cli-dump.c. */
4334 volatile struct gdb_exception ex
;
4336 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4338 remote_start_remote (from_tty
, target
, extended_p
);
4342 /* Pop the partially set up target - unless something else did
4343 already before throwing the exception. */
4344 if (remote_desc
!= NULL
)
4345 remote_unpush_target ();
4346 if (target_async_permitted
)
4347 wait_forever_enabled_p
= 1;
4348 throw_exception (ex
);
4352 if (target_async_permitted
)
4353 wait_forever_enabled_p
= 1;
4356 /* This takes a program previously attached to and detaches it. After
4357 this is done, GDB can be used to debug some other program. We
4358 better not have left any breakpoints in the target program or it'll
4359 die when it hits one. */
4362 remote_detach_1 (char *args
, int from_tty
, int extended
)
4364 int pid
= ptid_get_pid (inferior_ptid
);
4365 struct remote_state
*rs
= get_remote_state ();
4368 error (_("Argument given to \"detach\" when remotely debugging."));
4370 if (!target_has_execution
)
4371 error (_("No process to detach from."));
4375 char *exec_file
= get_exec_file (0);
4376 if (exec_file
== NULL
)
4378 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4379 target_pid_to_str (pid_to_ptid (pid
)));
4380 gdb_flush (gdb_stdout
);
4383 /* Tell the remote target to detach. */
4384 if (remote_multi_process_p (rs
))
4385 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4387 strcpy (rs
->buf
, "D");
4390 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4392 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4394 else if (rs
->buf
[0] == '\0')
4395 error (_("Remote doesn't know how to detach"));
4397 error (_("Can't detach process."));
4399 if (from_tty
&& !extended
)
4400 puts_filtered (_("Ending remote debugging.\n"));
4402 target_mourn_inferior ();
4406 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4408 remote_detach_1 (args
, from_tty
, 0);
4412 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4414 remote_detach_1 (args
, from_tty
, 1);
4417 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4420 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4423 error (_("Argument given to \"disconnect\" when remotely debugging."));
4425 /* Make sure we unpush even the extended remote targets; mourn
4426 won't do it. So call remote_mourn_1 directly instead of
4427 target_mourn_inferior. */
4428 remote_mourn_1 (target
);
4431 puts_filtered ("Ending remote debugging.\n");
4434 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4435 be chatty about it. */
4438 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4440 struct remote_state
*rs
= get_remote_state ();
4442 char *wait_status
= NULL
;
4444 pid
= parse_pid_to_attach (args
);
4446 /* Remote PID can be freely equal to getpid, do not check it here the same
4447 way as in other targets. */
4449 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4450 error (_("This target does not support attaching to a process"));
4454 char *exec_file
= get_exec_file (0);
4457 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4458 target_pid_to_str (pid_to_ptid (pid
)));
4460 printf_unfiltered (_("Attaching to %s\n"),
4461 target_pid_to_str (pid_to_ptid (pid
)));
4463 gdb_flush (gdb_stdout
);
4466 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4470 if (packet_ok (rs
->buf
,
4471 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4475 /* Save the reply for later. */
4476 wait_status
= alloca (strlen (rs
->buf
) + 1);
4477 strcpy (wait_status
, rs
->buf
);
4479 else if (strcmp (rs
->buf
, "OK") != 0)
4480 error (_("Attaching to %s failed with: %s"),
4481 target_pid_to_str (pid_to_ptid (pid
)),
4484 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4485 error (_("This target does not support attaching to a process"));
4487 error (_("Attaching to %s failed"),
4488 target_pid_to_str (pid_to_ptid (pid
)));
4490 set_current_inferior (remote_add_inferior (0, pid
, 1));
4492 inferior_ptid
= pid_to_ptid (pid
);
4496 struct thread_info
*thread
;
4498 /* Get list of threads. */
4499 remote_threads_info (target
);
4501 thread
= first_thread_of_process (pid
);
4503 inferior_ptid
= thread
->ptid
;
4505 inferior_ptid
= pid_to_ptid (pid
);
4507 /* Invalidate our notion of the remote current thread. */
4508 record_currthread (minus_one_ptid
);
4512 /* Now, if we have thread information, update inferior_ptid. */
4513 inferior_ptid
= remote_current_thread (inferior_ptid
);
4515 /* Add the main thread to the thread list. */
4516 add_thread_silent (inferior_ptid
);
4519 /* Next, if the target can specify a description, read it. We do
4520 this before anything involving memory or registers. */
4521 target_find_description ();
4525 /* Use the previously fetched status. */
4526 gdb_assert (wait_status
!= NULL
);
4528 if (target_can_async_p ())
4530 struct notif_event
*reply
4531 = remote_notif_parse (¬if_client_stop
, wait_status
);
4533 push_stop_reply ((struct stop_reply
*) reply
);
4535 target_async (inferior_event_handler
, 0);
4539 gdb_assert (wait_status
!= NULL
);
4540 strcpy (rs
->buf
, wait_status
);
4541 rs
->cached_wait_status
= 1;
4545 gdb_assert (wait_status
== NULL
);
4549 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4551 extended_remote_attach_1 (ops
, args
, from_tty
);
4554 /* Convert hex digit A to a number. */
4559 if (a
>= '0' && a
<= '9')
4561 else if (a
>= 'a' && a
<= 'f')
4562 return a
- 'a' + 10;
4563 else if (a
>= 'A' && a
<= 'F')
4564 return a
- 'A' + 10;
4566 error (_("Reply contains invalid hex digit %d"), a
);
4570 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4574 for (i
= 0; i
< count
; i
++)
4576 if (hex
[0] == 0 || hex
[1] == 0)
4578 /* Hex string is short, or of uneven length.
4579 Return the count that has been converted so far. */
4582 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4588 /* Convert number NIB to a hex digit. */
4596 return 'a' + nib
- 10;
4600 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4604 /* May use a length, or a nul-terminated string as input. */
4606 count
= strlen ((char *) bin
);
4608 for (i
= 0; i
< count
; i
++)
4610 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4611 *hex
++ = tohex (*bin
++ & 0xf);
4617 /* Check for the availability of vCont. This function should also check
4621 remote_vcont_probe (struct remote_state
*rs
)
4625 strcpy (rs
->buf
, "vCont?");
4627 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4630 /* Make sure that the features we assume are supported. */
4631 if (strncmp (buf
, "vCont", 5) == 0)
4634 int support_s
, support_S
, support_c
, support_C
;
4640 rs
->support_vCont_t
= 0;
4641 while (p
&& *p
== ';')
4644 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4646 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4648 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4650 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4652 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4653 rs
->support_vCont_t
= 1;
4655 p
= strchr (p
, ';');
4658 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4659 BUF will make packet_ok disable the packet. */
4660 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4664 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4667 /* Helper function for building "vCont" resumptions. Write a
4668 resumption to P. ENDP points to one-passed-the-end of the buffer
4669 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4670 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4671 resumed thread should be single-stepped and/or signalled. If PTID
4672 equals minus_one_ptid, then all threads are resumed; if PTID
4673 represents a process, then all threads of the process are resumed;
4674 the thread to be stepped and/or signalled is given in the global
4678 append_resumption (char *p
, char *endp
,
4679 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4681 struct remote_state
*rs
= get_remote_state ();
4683 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4684 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4686 p
+= xsnprintf (p
, endp
- p
, ";s");
4687 else if (siggnal
!= GDB_SIGNAL_0
)
4688 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4690 p
+= xsnprintf (p
, endp
- p
, ";c");
4692 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4696 /* All (-1) threads of process. */
4697 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4699 p
+= xsnprintf (p
, endp
- p
, ":");
4700 p
= write_ptid (p
, endp
, nptid
);
4702 else if (!ptid_equal (ptid
, minus_one_ptid
))
4704 p
+= xsnprintf (p
, endp
- p
, ":");
4705 p
= write_ptid (p
, endp
, ptid
);
4711 /* Append a vCont continue-with-signal action for threads that have a
4712 non-zero stop signal. */
4715 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4717 struct thread_info
*thread
;
4719 ALL_THREADS (thread
)
4720 if (ptid_match (thread
->ptid
, ptid
)
4721 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4722 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4723 && signal_pass_state (thread
->suspend
.stop_signal
))
4725 p
= append_resumption (p
, endp
, thread
->ptid
,
4726 0, thread
->suspend
.stop_signal
);
4727 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4733 /* Resume the remote inferior by using a "vCont" packet. The thread
4734 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4735 resumed thread should be single-stepped and/or signalled. If PTID
4736 equals minus_one_ptid, then all threads are resumed; the thread to
4737 be stepped and/or signalled is given in the global INFERIOR_PTID.
4738 This function returns non-zero iff it resumes the inferior.
4740 This function issues a strict subset of all possible vCont commands at the
4744 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4746 struct remote_state
*rs
= get_remote_state ();
4750 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4751 remote_vcont_probe (rs
);
4753 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4757 endp
= rs
->buf
+ get_remote_packet_size ();
4759 /* If we could generate a wider range of packets, we'd have to worry
4760 about overflowing BUF. Should there be a generic
4761 "multi-part-packet" packet? */
4763 p
+= xsnprintf (p
, endp
- p
, "vCont");
4765 if (ptid_equal (ptid
, magic_null_ptid
))
4767 /* MAGIC_NULL_PTID means that we don't have any active threads,
4768 so we don't have any TID numbers the inferior will
4769 understand. Make sure to only send forms that do not specify
4771 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4773 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4775 /* Resume all threads (of all processes, or of a single
4776 process), with preference for INFERIOR_PTID. This assumes
4777 inferior_ptid belongs to the set of all threads we are about
4779 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4781 /* Step inferior_ptid, with or without signal. */
4782 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4785 /* Also pass down any pending signaled resumption for other
4786 threads not the current. */
4787 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4789 /* And continue others without a signal. */
4790 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4794 /* Scheduler locking; resume only PTID. */
4795 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4798 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4803 /* In non-stop, the stub replies to vCont with "OK". The stop
4804 reply will be reported asynchronously by means of a `%Stop'
4806 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4807 if (strcmp (rs
->buf
, "OK") != 0)
4808 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4814 /* Tell the remote machine to resume. */
4816 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4818 static int last_sent_step
;
4821 remote_resume (struct target_ops
*ops
,
4822 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4824 struct remote_state
*rs
= get_remote_state ();
4827 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4828 (explained in remote-notif.c:handle_notification) so
4829 remote_notif_process is not called. We need find a place where
4830 it is safe to start a 'vNotif' sequence. It is good to do it
4831 before resuming inferior, because inferior was stopped and no RSP
4832 traffic at that moment. */
4834 remote_notif_process (¬if_client_stop
);
4836 last_sent_signal
= siggnal
;
4837 last_sent_step
= step
;
4839 /* The vCont packet doesn't need to specify threads via Hc. */
4840 /* No reverse support (yet) for vCont. */
4841 if (execution_direction
!= EXEC_REVERSE
)
4842 if (remote_vcont_resume (ptid
, step
, siggnal
))
4845 /* All other supported resume packets do use Hc, so set the continue
4847 if (ptid_equal (ptid
, minus_one_ptid
))
4848 set_continue_thread (any_thread_ptid
);
4850 set_continue_thread (ptid
);
4853 if (execution_direction
== EXEC_REVERSE
)
4855 /* We don't pass signals to the target in reverse exec mode. */
4856 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4857 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4861 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4862 error (_("Remote reverse-step not supported."));
4864 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4865 error (_("Remote reverse-continue not supported."));
4867 strcpy (buf
, step
? "bs" : "bc");
4869 else if (siggnal
!= GDB_SIGNAL_0
)
4871 buf
[0] = step
? 'S' : 'C';
4872 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4873 buf
[2] = tohex (((int) siggnal
) & 0xf);
4877 strcpy (buf
, step
? "s" : "c");
4882 /* We are about to start executing the inferior, let's register it
4883 with the event loop. NOTE: this is the one place where all the
4884 execution commands end up. We could alternatively do this in each
4885 of the execution commands in infcmd.c. */
4886 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4887 into infcmd.c in order to allow inferior function calls to work
4888 NOT asynchronously. */
4889 if (target_can_async_p ())
4890 target_async (inferior_event_handler
, 0);
4892 /* We've just told the target to resume. The remote server will
4893 wait for the inferior to stop, and then send a stop reply. In
4894 the mean time, we can't start another command/query ourselves
4895 because the stub wouldn't be ready to process it. This applies
4896 only to the base all-stop protocol, however. In non-stop (which
4897 only supports vCont), the stub replies with an "OK", and is
4898 immediate able to process further serial input. */
4900 rs
->waiting_for_stop_reply
= 1;
4904 /* Set up the signal handler for SIGINT, while the target is
4905 executing, ovewriting the 'regular' SIGINT signal handler. */
4907 initialize_sigint_signal_handler (void)
4909 signal (SIGINT
, handle_remote_sigint
);
4912 /* Signal handler for SIGINT, while the target is executing. */
4914 handle_remote_sigint (int sig
)
4916 signal (sig
, handle_remote_sigint_twice
);
4917 mark_async_signal_handler (sigint_remote_token
);
4920 /* Signal handler for SIGINT, installed after SIGINT has already been
4921 sent once. It will take effect the second time that the user sends
4924 handle_remote_sigint_twice (int sig
)
4926 signal (sig
, handle_remote_sigint
);
4927 mark_async_signal_handler (sigint_remote_twice_token
);
4930 /* Perform the real interruption of the target execution, in response
4933 async_remote_interrupt (gdb_client_data arg
)
4936 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4938 target_stop (inferior_ptid
);
4941 /* Perform interrupt, if the first attempt did not succeed. Just give
4942 up on the target alltogether. */
4944 async_remote_interrupt_twice (gdb_client_data arg
)
4947 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4952 /* Reinstall the usual SIGINT handlers, after the target has
4955 cleanup_sigint_signal_handler (void *dummy
)
4957 signal (SIGINT
, handle_sigint
);
4960 /* Send ^C to target to halt it. Target will respond, and send us a
4962 static void (*ofunc
) (int);
4964 /* The command line interface's stop routine. This function is installed
4965 as a signal handler for SIGINT. The first time a user requests a
4966 stop, we call remote_stop to send a break or ^C. If there is no
4967 response from the target (it didn't stop when the user requested it),
4968 we ask the user if he'd like to detach from the target. */
4970 remote_interrupt (int signo
)
4972 /* If this doesn't work, try more severe steps. */
4973 signal (signo
, remote_interrupt_twice
);
4975 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4978 /* The user typed ^C twice. */
4981 remote_interrupt_twice (int signo
)
4983 signal (signo
, ofunc
);
4984 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4985 signal (signo
, remote_interrupt
);
4988 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4989 thread, all threads of a remote process, or all threads of all
4993 remote_stop_ns (ptid_t ptid
)
4995 struct remote_state
*rs
= get_remote_state ();
4997 char *endp
= rs
->buf
+ get_remote_packet_size ();
4999 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5000 remote_vcont_probe (rs
);
5002 if (!rs
->support_vCont_t
)
5003 error (_("Remote server does not support stopping threads"));
5005 if (ptid_equal (ptid
, minus_one_ptid
)
5006 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5007 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5012 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5014 if (ptid_is_pid (ptid
))
5015 /* All (-1) threads of process. */
5016 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5019 /* Small optimization: if we already have a stop reply for
5020 this thread, no use in telling the stub we want this
5022 if (peek_stop_reply (ptid
))
5028 write_ptid (p
, endp
, nptid
);
5031 /* In non-stop, we get an immediate OK reply. The stop reply will
5032 come in asynchronously by notification. */
5034 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5035 if (strcmp (rs
->buf
, "OK") != 0)
5036 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5039 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5040 remote target. It is undefined which thread of which process
5041 reports the stop. */
5044 remote_stop_as (ptid_t ptid
)
5046 struct remote_state
*rs
= get_remote_state ();
5048 rs
->ctrlc_pending_p
= 1;
5050 /* If the inferior is stopped already, but the core didn't know
5051 about it yet, just ignore the request. The cached wait status
5052 will be collected in remote_wait. */
5053 if (rs
->cached_wait_status
)
5056 /* Send interrupt_sequence to remote target. */
5057 send_interrupt_sequence ();
5060 /* This is the generic stop called via the target vector. When a target
5061 interrupt is requested, either by the command line or the GUI, we
5062 will eventually end up here. */
5065 remote_stop (ptid_t ptid
)
5068 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5071 remote_stop_ns (ptid
);
5073 remote_stop_as (ptid
);
5076 /* Ask the user what to do when an interrupt is received. */
5079 interrupt_query (void)
5081 target_terminal_ours ();
5083 if (target_can_async_p ())
5085 signal (SIGINT
, handle_sigint
);
5086 deprecated_throw_reason (RETURN_QUIT
);
5090 if (query (_("Interrupted while waiting for the program.\n\
5091 Give up (and stop debugging it)? ")))
5093 remote_unpush_target ();
5094 deprecated_throw_reason (RETURN_QUIT
);
5098 target_terminal_inferior ();
5101 /* Enable/disable target terminal ownership. Most targets can use
5102 terminal groups to control terminal ownership. Remote targets are
5103 different in that explicit transfer of ownership to/from GDB/target
5107 remote_terminal_inferior (void)
5109 if (!target_async_permitted
)
5110 /* Nothing to do. */
5113 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5114 idempotent. The event-loop GDB talking to an asynchronous target
5115 with a synchronous command calls this function from both
5116 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5117 transfer the terminal to the target when it shouldn't this guard
5119 if (!remote_async_terminal_ours_p
)
5121 delete_file_handler (input_fd
);
5122 remote_async_terminal_ours_p
= 0;
5123 initialize_sigint_signal_handler ();
5124 /* NOTE: At this point we could also register our selves as the
5125 recipient of all input. Any characters typed could then be
5126 passed on down to the target. */
5130 remote_terminal_ours (void)
5132 if (!target_async_permitted
)
5133 /* Nothing to do. */
5136 /* See FIXME in remote_terminal_inferior. */
5137 if (remote_async_terminal_ours_p
)
5139 cleanup_sigint_signal_handler (NULL
);
5140 add_file_handler (input_fd
, stdin_event_handler
, 0);
5141 remote_async_terminal_ours_p
= 1;
5145 remote_console_output (char *msg
)
5149 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5152 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5156 fputs_unfiltered (tb
, gdb_stdtarg
);
5158 gdb_flush (gdb_stdtarg
);
5161 typedef struct cached_reg
5164 gdb_byte data
[MAX_REGISTER_SIZE
];
5167 DEF_VEC_O(cached_reg_t
);
5169 typedef struct stop_reply
5171 struct notif_event base
;
5173 /* The identifier of the thread about this event */
5176 struct target_waitstatus ws
;
5178 /* Expedited registers. This makes remote debugging a bit more
5179 efficient for those targets that provide critical registers as
5180 part of their normal status mechanism (as another roundtrip to
5181 fetch them is avoided). */
5182 VEC(cached_reg_t
) *regcache
;
5184 int stopped_by_watchpoint_p
;
5185 CORE_ADDR watch_data_address
;
5193 DECLARE_QUEUE_P (stop_reply_p
);
5194 DEFINE_QUEUE_P (stop_reply_p
);
5195 /* The list of already fetched and acknowledged stop events. This
5196 queue is used for notification Stop, and other notifications
5197 don't need queue for their events, because the notification events
5198 of Stop can't be consumed immediately, so that events should be
5199 queued first, and be consumed by remote_wait_{ns,as} one per
5200 time. Other notifications can consume their events immediately,
5201 so queue is not needed for them. */
5202 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5205 stop_reply_xfree (struct stop_reply
*r
)
5209 VEC_free (cached_reg_t
, r
->regcache
);
5215 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5216 struct notif_event
*event
)
5218 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5222 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5223 struct notif_event
*event
)
5225 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5228 putpkt ((char *) self
->ack_command
);
5230 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5231 /* We got an unknown stop reply. */
5232 error (_("Unknown stop reply"));
5234 push_stop_reply (stop_reply
);
5238 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5240 /* We can't get pending events in remote_notif_process for
5241 notification stop, and we have to do this in remote_wait_ns
5242 instead. If we fetch all queued events from stub, remote stub
5243 may exit and we have no chance to process them back in
5245 mark_async_event_handler (remote_async_inferior_event_token
);
5250 stop_reply_dtr (struct notif_event
*event
)
5252 struct stop_reply
*r
= (struct stop_reply
*) event
;
5254 VEC_free (cached_reg_t
, r
->regcache
);
5257 static struct notif_event
*
5258 remote_notif_stop_alloc_reply (void)
5260 struct notif_event
*r
5261 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5263 r
->dtr
= stop_reply_dtr
;
5268 /* A client of notification Stop. */
5270 struct notif_client notif_client_stop
=
5274 remote_notif_stop_parse
,
5275 remote_notif_stop_ack
,
5276 remote_notif_stop_can_get_pending_events
,
5277 remote_notif_stop_alloc_reply
,
5281 /* A parameter to pass data in and out. */
5283 struct queue_iter_param
5286 struct stop_reply
*output
;
5289 /* Remove all queue elements meet the condition it checks. */
5292 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5293 QUEUE_ITER (stop_reply_p
) *iter
,
5297 struct queue_iter_param
*param
= data
;
5298 struct inferior
*inf
= param
->input
;
5300 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5302 stop_reply_xfree (event
);
5303 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5309 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5310 discard everything. */
5313 discard_pending_stop_replies (struct inferior
*inf
)
5316 struct queue_iter_param param
;
5317 struct stop_reply
*reply
5318 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5320 /* Discard the in-flight notification. */
5323 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5325 stop_reply_xfree (reply
);
5326 notif_client_stop
.pending_event
= NULL
;
5330 param
.output
= NULL
;
5331 /* Discard the stop replies we have already pulled with
5333 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5334 remote_notif_remove_all
, ¶m
);
5337 /* A parameter to pass data in and out. */
5340 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5341 QUEUE_ITER (stop_reply_p
) *iter
,
5345 struct queue_iter_param
*param
= data
;
5346 ptid_t
*ptid
= param
->input
;
5348 if (ptid_match (event
->ptid
, *ptid
))
5350 param
->output
= event
;
5351 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5358 /* Remove the first reply in 'stop_reply_queue' which matches
5361 static struct stop_reply
*
5362 remote_notif_remove_queued_reply (ptid_t ptid
)
5364 struct queue_iter_param param
;
5366 param
.input
= &ptid
;
5367 param
.output
= NULL
;
5369 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5370 remote_notif_remove_once_on_match
, ¶m
);
5372 fprintf_unfiltered (gdb_stdlog
,
5373 "notif: discard queued event: 'Stop' in %s\n",
5374 target_pid_to_str (ptid
));
5376 return param
.output
;
5379 /* Look for a queued stop reply belonging to PTID. If one is found,
5380 remove it from the queue, and return it. Returns NULL if none is
5381 found. If there are still queued events left to process, tell the
5382 event loop to get back to target_wait soon. */
5384 static struct stop_reply
*
5385 queued_stop_reply (ptid_t ptid
)
5387 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5389 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5390 /* There's still at least an event left. */
5391 mark_async_event_handler (remote_async_inferior_event_token
);
5396 /* Push a fully parsed stop reply in the stop reply queue. Since we
5397 know that we now have at least one queued event left to pass to the
5398 core side, tell the event loop to get back to target_wait soon. */
5401 push_stop_reply (struct stop_reply
*new_event
)
5403 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5406 fprintf_unfiltered (gdb_stdlog
,
5407 "notif: push 'Stop' %s to queue %d\n",
5408 target_pid_to_str (new_event
->ptid
),
5409 QUEUE_length (stop_reply_p
,
5412 mark_async_event_handler (remote_async_inferior_event_token
);
5416 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5417 QUEUE_ITER (stop_reply_p
) *iter
,
5418 struct stop_reply
*event
,
5421 ptid_t
*ptid
= data
;
5423 return !(ptid_equal (*ptid
, event
->ptid
)
5424 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5427 /* Returns true if we have a stop reply for PTID. */
5430 peek_stop_reply (ptid_t ptid
)
5432 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5433 stop_reply_match_ptid_and_ws
, &ptid
);
5436 /* Parse the stop reply in BUF. Either the function succeeds, and the
5437 result is stored in EVENT, or throws an error. */
5440 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5442 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5446 event
->ptid
= null_ptid
;
5447 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5448 event
->ws
.value
.integer
= 0;
5449 event
->solibs_changed
= 0;
5450 event
->replay_event
= 0;
5451 event
->stopped_by_watchpoint_p
= 0;
5452 event
->regcache
= NULL
;
5457 case 'T': /* Status with PC, SP, FP, ... */
5458 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5459 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5461 n... = register number
5462 r... = register contents
5465 p
= &buf
[3]; /* after Txx */
5473 /* If the packet contains a register number, save it in
5474 pnum and set p1 to point to the character following it.
5475 Otherwise p1 points to p. */
5477 /* If this packet is an awatch packet, don't parse the 'a'
5478 as a register number. */
5480 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5481 && strncmp (p
, "core", strlen ("core") != 0))
5483 /* Read the ``P'' register number. */
5484 pnum
= strtol (p
, &p_temp
, 16);
5490 if (p1
== p
) /* No register number present here. */
5492 p1
= strchr (p
, ':');
5494 error (_("Malformed packet(a) (missing colon): %s\n\
5497 if (strncmp (p
, "thread", p1
- p
) == 0)
5498 event
->ptid
= read_ptid (++p1
, &p
);
5499 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5500 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5501 || (strncmp (p
, "awatch", p1
- p
) == 0))
5503 event
->stopped_by_watchpoint_p
= 1;
5504 p
= unpack_varlen_hex (++p1
, &addr
);
5505 event
->watch_data_address
= (CORE_ADDR
) addr
;
5507 else if (strncmp (p
, "library", p1
- p
) == 0)
5511 while (*p_temp
&& *p_temp
!= ';')
5514 event
->solibs_changed
= 1;
5517 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5519 /* NO_HISTORY event.
5520 p1 will indicate "begin" or "end", but
5521 it makes no difference for now, so ignore it. */
5522 event
->replay_event
= 1;
5523 p_temp
= strchr (p1
+ 1, ';');
5527 else if (strncmp (p
, "core", p1
- p
) == 0)
5531 p
= unpack_varlen_hex (++p1
, &c
);
5536 /* Silently skip unknown optional info. */
5537 p_temp
= strchr (p1
+ 1, ';');
5544 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5545 cached_reg_t cached_reg
;
5550 error (_("Malformed packet(b) (missing colon): %s\n\
5556 error (_("Remote sent bad register number %s: %s\n\
5558 hex_string (pnum
), p
, buf
);
5560 cached_reg
.num
= reg
->regnum
;
5562 fieldsize
= hex2bin (p
, cached_reg
.data
,
5563 register_size (target_gdbarch (),
5566 if (fieldsize
< register_size (target_gdbarch (),
5568 warning (_("Remote reply is too short: %s"), buf
);
5570 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5574 error (_("Remote register badly formatted: %s\nhere: %s"),
5579 case 'S': /* Old style status, just signal only. */
5580 if (event
->solibs_changed
)
5581 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5582 else if (event
->replay_event
)
5583 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5586 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5587 event
->ws
.value
.sig
= (enum gdb_signal
)
5588 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5591 case 'W': /* Target exited. */
5598 /* GDB used to accept only 2 hex chars here. Stubs should
5599 only send more if they detect GDB supports multi-process
5601 p
= unpack_varlen_hex (&buf
[1], &value
);
5605 /* The remote process exited. */
5606 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5607 event
->ws
.value
.integer
= value
;
5611 /* The remote process exited with a signal. */
5612 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5613 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5616 /* If no process is specified, assume inferior_ptid. */
5617 pid
= ptid_get_pid (inferior_ptid
);
5626 else if (strncmp (p
,
5627 "process:", sizeof ("process:") - 1) == 0)
5631 p
+= sizeof ("process:") - 1;
5632 unpack_varlen_hex (p
, &upid
);
5636 error (_("unknown stop reply packet: %s"), buf
);
5639 error (_("unknown stop reply packet: %s"), buf
);
5640 event
->ptid
= pid_to_ptid (pid
);
5645 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5646 error (_("No process or thread specified in stop reply: %s"), buf
);
5649 /* When the stub wants to tell GDB about a new notification reply, it
5650 sends a notification (%Stop, for example). Those can come it at
5651 any time, hence, we have to make sure that any pending
5652 putpkt/getpkt sequence we're making is finished, before querying
5653 the stub for more events with the corresponding ack command
5654 (vStopped, for example). E.g., if we started a vStopped sequence
5655 immediately upon receiving the notification, something like this
5663 1.6) <-- (registers reply to step #1.3)
5665 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5668 To solve this, whenever we parse a %Stop notification successfully,
5669 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5670 doing whatever we were doing:
5676 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5677 2.5) <-- (registers reply to step #2.3)
5679 Eventualy after step #2.5, we return to the event loop, which
5680 notices there's an event on the
5681 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5682 associated callback --- the function below. At this point, we're
5683 always safe to start a vStopped sequence. :
5686 2.7) <-- T05 thread:2
5692 remote_notif_get_pending_events (struct notif_client
*nc
)
5694 struct remote_state
*rs
= get_remote_state ();
5696 if (nc
->pending_event
)
5699 fprintf_unfiltered (gdb_stdlog
,
5700 "notif: process: '%s' ack pending event\n",
5704 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5705 nc
->pending_event
= NULL
;
5709 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5710 if (strcmp (rs
->buf
, "OK") == 0)
5713 remote_notif_ack (nc
, rs
->buf
);
5719 fprintf_unfiltered (gdb_stdlog
,
5720 "notif: process: '%s' no pending reply\n",
5725 /* Called when it is decided that STOP_REPLY holds the info of the
5726 event that is to be returned to the core. This function always
5727 destroys STOP_REPLY. */
5730 process_stop_reply (struct stop_reply
*stop_reply
,
5731 struct target_waitstatus
*status
)
5735 *status
= stop_reply
->ws
;
5736 ptid
= stop_reply
->ptid
;
5738 /* If no thread/process was reported by the stub, assume the current
5740 if (ptid_equal (ptid
, null_ptid
))
5741 ptid
= inferior_ptid
;
5743 if (status
->kind
!= TARGET_WAITKIND_EXITED
5744 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5746 /* Expedited registers. */
5747 if (stop_reply
->regcache
)
5749 struct regcache
*regcache
5750 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5755 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5757 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5758 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5761 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5762 remote_watch_data_address
= stop_reply
->watch_data_address
;
5764 remote_notice_new_inferior (ptid
, 0);
5765 demand_private_info (ptid
)->core
= stop_reply
->core
;
5768 stop_reply_xfree (stop_reply
);
5772 /* The non-stop mode version of target_wait. */
5775 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5777 struct remote_state
*rs
= get_remote_state ();
5778 struct stop_reply
*stop_reply
;
5782 /* If in non-stop mode, get out of getpkt even if a
5783 notification is received. */
5785 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5786 0 /* forever */, &is_notif
);
5789 if (ret
!= -1 && !is_notif
)
5792 case 'E': /* Error of some sort. */
5793 /* We're out of sync with the target now. Did it continue
5794 or not? We can't tell which thread it was in non-stop,
5795 so just ignore this. */
5796 warning (_("Remote failure reply: %s"), rs
->buf
);
5798 case 'O': /* Console output. */
5799 remote_console_output (rs
->buf
+ 1);
5802 warning (_("Invalid remote reply: %s"), rs
->buf
);
5806 /* Acknowledge a pending stop reply that may have arrived in the
5808 if (notif_client_stop
.pending_event
!= NULL
)
5809 remote_notif_get_pending_events (¬if_client_stop
);
5811 /* If indeed we noticed a stop reply, we're done. */
5812 stop_reply
= queued_stop_reply (ptid
);
5813 if (stop_reply
!= NULL
)
5814 return process_stop_reply (stop_reply
, status
);
5816 /* Still no event. If we're just polling for an event, then
5817 return to the event loop. */
5818 if (options
& TARGET_WNOHANG
)
5820 status
->kind
= TARGET_WAITKIND_IGNORE
;
5821 return minus_one_ptid
;
5824 /* Otherwise do a blocking wait. */
5825 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5826 1 /* forever */, &is_notif
);
5830 /* Wait until the remote machine stops, then return, storing status in
5831 STATUS just as `wait' would. */
5834 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5836 struct remote_state
*rs
= get_remote_state ();
5837 ptid_t event_ptid
= null_ptid
;
5839 struct stop_reply
*stop_reply
;
5843 status
->kind
= TARGET_WAITKIND_IGNORE
;
5844 status
->value
.integer
= 0;
5846 stop_reply
= queued_stop_reply (ptid
);
5847 if (stop_reply
!= NULL
)
5848 return process_stop_reply (stop_reply
, status
);
5850 if (rs
->cached_wait_status
)
5851 /* Use the cached wait status, but only once. */
5852 rs
->cached_wait_status
= 0;
5858 if (!target_is_async_p ())
5860 ofunc
= signal (SIGINT
, remote_interrupt
);
5861 /* If the user hit C-c before this packet, or between packets,
5862 pretend that it was hit right here. */
5863 if (check_quit_flag ())
5866 remote_interrupt (SIGINT
);
5870 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5871 _never_ wait for ever -> test on target_is_async_p().
5872 However, before we do that we need to ensure that the caller
5873 knows how to take the target into/out of async mode. */
5874 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5875 wait_forever_enabled_p
, &is_notif
);
5877 /* GDB gets a notification. Return to core as this event is
5879 if (ret
!= -1 && is_notif
)
5880 return minus_one_ptid
;
5882 if (!target_is_async_p ())
5883 signal (SIGINT
, ofunc
);
5888 remote_stopped_by_watchpoint_p
= 0;
5890 /* We got something. */
5891 rs
->waiting_for_stop_reply
= 0;
5893 /* Assume that the target has acknowledged Ctrl-C unless we receive
5894 an 'F' or 'O' packet. */
5895 if (buf
[0] != 'F' && buf
[0] != 'O')
5896 rs
->ctrlc_pending_p
= 0;
5900 case 'E': /* Error of some sort. */
5901 /* We're out of sync with the target now. Did it continue or
5902 not? Not is more likely, so report a stop. */
5903 warning (_("Remote failure reply: %s"), buf
);
5904 status
->kind
= TARGET_WAITKIND_STOPPED
;
5905 status
->value
.sig
= GDB_SIGNAL_0
;
5907 case 'F': /* File-I/O request. */
5908 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5909 rs
->ctrlc_pending_p
= 0;
5911 case 'T': case 'S': case 'X': case 'W':
5913 struct stop_reply
*stop_reply
5914 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
5917 event_ptid
= process_stop_reply (stop_reply
, status
);
5920 case 'O': /* Console output. */
5921 remote_console_output (buf
+ 1);
5923 /* The target didn't really stop; keep waiting. */
5924 rs
->waiting_for_stop_reply
= 1;
5928 if (last_sent_signal
!= GDB_SIGNAL_0
)
5930 /* Zero length reply means that we tried 'S' or 'C' and the
5931 remote system doesn't support it. */
5932 target_terminal_ours_for_output ();
5934 ("Can't send signals to this remote system. %s not sent.\n",
5935 gdb_signal_to_name (last_sent_signal
));
5936 last_sent_signal
= GDB_SIGNAL_0
;
5937 target_terminal_inferior ();
5939 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5940 putpkt ((char *) buf
);
5942 /* We just told the target to resume, so a stop reply is in
5944 rs
->waiting_for_stop_reply
= 1;
5947 /* else fallthrough */
5949 warning (_("Invalid remote reply: %s"), buf
);
5951 rs
->waiting_for_stop_reply
= 1;
5955 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5957 /* Nothing interesting happened. If we're doing a non-blocking
5958 poll, we're done. Otherwise, go back to waiting. */
5959 if (options
& TARGET_WNOHANG
)
5960 return minus_one_ptid
;
5964 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5965 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5967 if (!ptid_equal (event_ptid
, null_ptid
))
5968 record_currthread (event_ptid
);
5970 event_ptid
= inferior_ptid
;
5973 /* A process exit. Invalidate our notion of current thread. */
5974 record_currthread (minus_one_ptid
);
5979 /* Wait until the remote machine stops, then return, storing status in
5980 STATUS just as `wait' would. */
5983 remote_wait (struct target_ops
*ops
,
5984 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5989 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5991 event_ptid
= remote_wait_as (ptid
, status
, options
);
5993 if (target_can_async_p ())
5995 /* If there are are events left in the queue tell the event loop
5997 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5998 mark_async_event_handler (remote_async_inferior_event_token
);
6004 /* Fetch a single register using a 'p' packet. */
6007 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6009 struct remote_state
*rs
= get_remote_state ();
6011 char regp
[MAX_REGISTER_SIZE
];
6014 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6017 if (reg
->pnum
== -1)
6022 p
+= hexnumstr (p
, reg
->pnum
);
6025 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6029 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6033 case PACKET_UNKNOWN
:
6036 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6037 gdbarch_register_name (get_regcache_arch (regcache
),
6042 /* If this register is unfetchable, tell the regcache. */
6045 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6049 /* Otherwise, parse and supply the value. */
6055 error (_("fetch_register_using_p: early buf termination"));
6057 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6060 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6064 /* Fetch the registers included in the target's 'g' packet. */
6067 send_g_packet (void)
6069 struct remote_state
*rs
= get_remote_state ();
6072 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6073 remote_send (&rs
->buf
, &rs
->buf_size
);
6075 /* We can get out of synch in various cases. If the first character
6076 in the buffer is not a hex character, assume that has happened
6077 and try to fetch another packet to read. */
6078 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6079 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6080 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6081 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6084 fprintf_unfiltered (gdb_stdlog
,
6085 "Bad register packet; fetching a new packet\n");
6086 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6089 buf_len
= strlen (rs
->buf
);
6091 /* Sanity check the received packet. */
6092 if (buf_len
% 2 != 0)
6093 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6099 process_g_packet (struct regcache
*regcache
)
6101 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6102 struct remote_state
*rs
= get_remote_state ();
6103 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6108 buf_len
= strlen (rs
->buf
);
6110 /* Further sanity checks, with knowledge of the architecture. */
6111 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6112 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6114 /* Save the size of the packet sent to us by the target. It is used
6115 as a heuristic when determining the max size of packets that the
6116 target can safely receive. */
6117 if (rsa
->actual_register_packet_size
== 0)
6118 rsa
->actual_register_packet_size
= buf_len
;
6120 /* If this is smaller than we guessed the 'g' packet would be,
6121 update our records. A 'g' reply that doesn't include a register's
6122 value implies either that the register is not available, or that
6123 the 'p' packet must be used. */
6124 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6126 rsa
->sizeof_g_packet
= buf_len
/ 2;
6128 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6130 if (rsa
->regs
[i
].pnum
== -1)
6133 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6134 rsa
->regs
[i
].in_g_packet
= 0;
6136 rsa
->regs
[i
].in_g_packet
= 1;
6140 regs
= alloca (rsa
->sizeof_g_packet
);
6142 /* Unimplemented registers read as all bits zero. */
6143 memset (regs
, 0, rsa
->sizeof_g_packet
);
6145 /* Reply describes registers byte by byte, each byte encoded as two
6146 hex characters. Suck them all up, then supply them to the
6147 register cacheing/storage mechanism. */
6150 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6152 if (p
[0] == 0 || p
[1] == 0)
6153 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6154 internal_error (__FILE__
, __LINE__
,
6155 _("unexpected end of 'g' packet reply"));
6157 if (p
[0] == 'x' && p
[1] == 'x')
6158 regs
[i
] = 0; /* 'x' */
6160 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6164 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6166 struct packet_reg
*r
= &rsa
->regs
[i
];
6170 if (r
->offset
* 2 >= strlen (rs
->buf
))
6171 /* This shouldn't happen - we adjusted in_g_packet above. */
6172 internal_error (__FILE__
, __LINE__
,
6173 _("unexpected end of 'g' packet reply"));
6174 else if (rs
->buf
[r
->offset
* 2] == 'x')
6176 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6177 /* The register isn't available, mark it as such (at
6178 the same time setting the value to zero). */
6179 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6182 regcache_raw_supply (regcache
, r
->regnum
,
6189 fetch_registers_using_g (struct regcache
*regcache
)
6192 process_g_packet (regcache
);
6195 /* Make the remote selected traceframe match GDB's selected
6199 set_remote_traceframe (void)
6203 if (remote_traceframe_number
== get_traceframe_number ())
6206 /* Avoid recursion, remote_trace_find calls us again. */
6207 remote_traceframe_number
= get_traceframe_number ();
6209 newnum
= target_trace_find (tfind_number
,
6210 get_traceframe_number (), 0, 0, NULL
);
6212 /* Should not happen. If it does, all bets are off. */
6213 if (newnum
!= get_traceframe_number ())
6214 warning (_("could not set remote traceframe"));
6218 remote_fetch_registers (struct target_ops
*ops
,
6219 struct regcache
*regcache
, int regnum
)
6221 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6224 set_remote_traceframe ();
6225 set_general_thread (inferior_ptid
);
6229 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6231 gdb_assert (reg
!= NULL
);
6233 /* If this register might be in the 'g' packet, try that first -
6234 we are likely to read more than one register. If this is the
6235 first 'g' packet, we might be overly optimistic about its
6236 contents, so fall back to 'p'. */
6237 if (reg
->in_g_packet
)
6239 fetch_registers_using_g (regcache
);
6240 if (reg
->in_g_packet
)
6244 if (fetch_register_using_p (regcache
, reg
))
6247 /* This register is not available. */
6248 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6253 fetch_registers_using_g (regcache
);
6255 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6256 if (!rsa
->regs
[i
].in_g_packet
)
6257 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6259 /* This register is not available. */
6260 regcache_raw_supply (regcache
, i
, NULL
);
6264 /* Prepare to store registers. Since we may send them all (using a
6265 'G' request), we have to read out the ones we don't want to change
6269 remote_prepare_to_store (struct regcache
*regcache
)
6271 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6273 gdb_byte buf
[MAX_REGISTER_SIZE
];
6275 /* Make sure the entire registers array is valid. */
6276 switch (remote_protocol_packets
[PACKET_P
].support
)
6278 case PACKET_DISABLE
:
6279 case PACKET_SUPPORT_UNKNOWN
:
6280 /* Make sure all the necessary registers are cached. */
6281 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6282 if (rsa
->regs
[i
].in_g_packet
)
6283 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6290 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6291 packet was not recognized. */
6294 store_register_using_P (const struct regcache
*regcache
,
6295 struct packet_reg
*reg
)
6297 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6298 struct remote_state
*rs
= get_remote_state ();
6299 /* Try storing a single register. */
6300 char *buf
= rs
->buf
;
6301 gdb_byte regp
[MAX_REGISTER_SIZE
];
6304 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6307 if (reg
->pnum
== -1)
6310 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6311 p
= buf
+ strlen (buf
);
6312 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6313 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6315 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6317 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6322 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6323 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6324 case PACKET_UNKNOWN
:
6327 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6331 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6332 contents of the register cache buffer. FIXME: ignores errors. */
6335 store_registers_using_G (const struct regcache
*regcache
)
6337 struct remote_state
*rs
= get_remote_state ();
6338 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6342 /* Extract all the registers in the regcache copying them into a
6347 regs
= alloca (rsa
->sizeof_g_packet
);
6348 memset (regs
, 0, rsa
->sizeof_g_packet
);
6349 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6351 struct packet_reg
*r
= &rsa
->regs
[i
];
6354 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6358 /* Command describes registers byte by byte,
6359 each byte encoded as two hex characters. */
6362 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6364 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6366 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6367 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6368 error (_("Could not write registers; remote failure reply '%s'"),
6372 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6373 of the register cache buffer. FIXME: ignores errors. */
6376 remote_store_registers (struct target_ops
*ops
,
6377 struct regcache
*regcache
, int regnum
)
6379 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6382 set_remote_traceframe ();
6383 set_general_thread (inferior_ptid
);
6387 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6389 gdb_assert (reg
!= NULL
);
6391 /* Always prefer to store registers using the 'P' packet if
6392 possible; we often change only a small number of registers.
6393 Sometimes we change a larger number; we'd need help from a
6394 higher layer to know to use 'G'. */
6395 if (store_register_using_P (regcache
, reg
))
6398 /* For now, don't complain if we have no way to write the
6399 register. GDB loses track of unavailable registers too
6400 easily. Some day, this may be an error. We don't have
6401 any way to read the register, either... */
6402 if (!reg
->in_g_packet
)
6405 store_registers_using_G (regcache
);
6409 store_registers_using_G (regcache
);
6411 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6412 if (!rsa
->regs
[i
].in_g_packet
)
6413 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6414 /* See above for why we do not issue an error here. */
6419 /* Return the number of hex digits in num. */
6422 hexnumlen (ULONGEST num
)
6426 for (i
= 0; num
!= 0; i
++)
6432 /* Set BUF to the minimum number of hex digits representing NUM. */
6435 hexnumstr (char *buf
, ULONGEST num
)
6437 int len
= hexnumlen (num
);
6439 return hexnumnstr (buf
, num
, len
);
6443 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6446 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6452 for (i
= width
- 1; i
>= 0; i
--)
6454 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6461 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6464 remote_address_masked (CORE_ADDR addr
)
6466 unsigned int address_size
= remote_address_size
;
6468 /* If "remoteaddresssize" was not set, default to target address size. */
6470 address_size
= gdbarch_addr_bit (target_gdbarch ());
6472 if (address_size
> 0
6473 && address_size
< (sizeof (ULONGEST
) * 8))
6475 /* Only create a mask when that mask can safely be constructed
6476 in a ULONGEST variable. */
6479 mask
= (mask
<< address_size
) - 1;
6485 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6486 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6487 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6488 (which may be more than *OUT_LEN due to escape characters). The
6489 total number of bytes in the output buffer will be at most
6493 remote_escape_output (const gdb_byte
*buffer
, int len
,
6494 gdb_byte
*out_buf
, int *out_len
,
6497 int input_index
, output_index
;
6500 for (input_index
= 0; input_index
< len
; input_index
++)
6502 gdb_byte b
= buffer
[input_index
];
6504 if (b
== '$' || b
== '#' || b
== '}')
6506 /* These must be escaped. */
6507 if (output_index
+ 2 > out_maxlen
)
6509 out_buf
[output_index
++] = '}';
6510 out_buf
[output_index
++] = b
^ 0x20;
6514 if (output_index
+ 1 > out_maxlen
)
6516 out_buf
[output_index
++] = b
;
6520 *out_len
= input_index
;
6521 return output_index
;
6524 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6525 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6526 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6528 This function reverses remote_escape_output. It allows more
6529 escaped characters than that function does, in particular because
6530 '*' must be escaped to avoid the run-length encoding processing
6531 in reading packets. */
6534 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6535 gdb_byte
*out_buf
, int out_maxlen
)
6537 int input_index
, output_index
;
6542 for (input_index
= 0; input_index
< len
; input_index
++)
6544 gdb_byte b
= buffer
[input_index
];
6546 if (output_index
+ 1 > out_maxlen
)
6548 warning (_("Received too much data from remote target;"
6549 " ignoring overflow."));
6550 return output_index
;
6555 out_buf
[output_index
++] = b
^ 0x20;
6561 out_buf
[output_index
++] = b
;
6565 error (_("Unmatched escape character in target response."));
6567 return output_index
;
6570 /* Determine whether the remote target supports binary downloading.
6571 This is accomplished by sending a no-op memory write of zero length
6572 to the target at the specified address. It does not suffice to send
6573 the whole packet, since many stubs strip the eighth bit and
6574 subsequently compute a wrong checksum, which causes real havoc with
6577 NOTE: This can still lose if the serial line is not eight-bit
6578 clean. In cases like this, the user should clear "remote
6582 check_binary_download (CORE_ADDR addr
)
6584 struct remote_state
*rs
= get_remote_state ();
6586 switch (remote_protocol_packets
[PACKET_X
].support
)
6588 case PACKET_DISABLE
:
6592 case PACKET_SUPPORT_UNKNOWN
:
6598 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6600 p
+= hexnumstr (p
, (ULONGEST
) 0);
6604 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6605 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6607 if (rs
->buf
[0] == '\0')
6610 fprintf_unfiltered (gdb_stdlog
,
6611 "binary downloading NOT "
6612 "supported by target\n");
6613 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6618 fprintf_unfiltered (gdb_stdlog
,
6619 "binary downloading supported by target\n");
6620 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6627 /* Write memory data directly to the remote machine.
6628 This does not inform the data cache; the data cache uses this.
6629 HEADER is the starting part of the packet.
6630 MEMADDR is the address in the remote memory space.
6631 MYADDR is the address of the buffer in our space.
6632 LEN is the number of bytes.
6633 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6634 should send data as binary ('X'), or hex-encoded ('M').
6636 The function creates packet of the form
6637 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6639 where encoding of <DATA> is termined by PACKET_FORMAT.
6641 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6644 Returns the number of bytes transferred, or 0 (setting errno) for
6645 error. Only transfer a single packet. */
6648 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6649 const gdb_byte
*myaddr
, ssize_t len
,
6650 char packet_format
, int use_length
)
6652 struct remote_state
*rs
= get_remote_state ();
6662 if (packet_format
!= 'X' && packet_format
!= 'M')
6663 internal_error (__FILE__
, __LINE__
,
6664 _("remote_write_bytes_aux: bad packet format"));
6669 payload_size
= get_memory_write_packet_size ();
6671 /* The packet buffer will be large enough for the payload;
6672 get_memory_packet_size ensures this. */
6675 /* Compute the size of the actual payload by subtracting out the
6676 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6678 payload_size
-= strlen ("$,:#NN");
6680 /* The comma won't be used. */
6682 header_length
= strlen (header
);
6683 payload_size
-= header_length
;
6684 payload_size
-= hexnumlen (memaddr
);
6686 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6688 strcat (rs
->buf
, header
);
6689 p
= rs
->buf
+ strlen (header
);
6691 /* Compute a best guess of the number of bytes actually transfered. */
6692 if (packet_format
== 'X')
6694 /* Best guess at number of bytes that will fit. */
6695 todo
= min (len
, payload_size
);
6697 payload_size
-= hexnumlen (todo
);
6698 todo
= min (todo
, payload_size
);
6702 /* Num bytes that will fit. */
6703 todo
= min (len
, payload_size
/ 2);
6705 payload_size
-= hexnumlen (todo
);
6706 todo
= min (todo
, payload_size
/ 2);
6710 internal_error (__FILE__
, __LINE__
,
6711 _("minimum packet size too small to write data"));
6713 /* If we already need another packet, then try to align the end
6714 of this packet to a useful boundary. */
6715 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6716 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6718 /* Append "<memaddr>". */
6719 memaddr
= remote_address_masked (memaddr
);
6720 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6727 /* Append <len>. Retain the location/size of <len>. It may need to
6728 be adjusted once the packet body has been created. */
6730 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6738 /* Append the packet body. */
6739 if (packet_format
== 'X')
6741 /* Binary mode. Send target system values byte by byte, in
6742 increasing byte addresses. Only escape certain critical
6744 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6747 /* If not all TODO bytes fit, then we'll need another packet. Make
6748 a second try to keep the end of the packet aligned. Don't do
6749 this if the packet is tiny. */
6750 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6754 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6756 if (new_nr_bytes
!= nr_bytes
)
6757 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6762 p
+= payload_length
;
6763 if (use_length
&& nr_bytes
< todo
)
6765 /* Escape chars have filled up the buffer prematurely,
6766 and we have actually sent fewer bytes than planned.
6767 Fix-up the length field of the packet. Use the same
6768 number of characters as before. */
6769 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6770 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6775 /* Normal mode: Send target system values byte by byte, in
6776 increasing byte addresses. Each byte is encoded as a two hex
6778 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6782 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6783 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6785 if (rs
->buf
[0] == 'E')
6787 /* There is no correspondance between what the remote protocol
6788 uses for errors and errno codes. We would like a cleaner way
6789 of representing errors (big enough to include errno codes,
6790 bfd_error codes, and others). But for now just return EIO. */
6795 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6796 fewer bytes than we'd planned. */
6800 /* Write memory data directly to the remote machine.
6801 This does not inform the data cache; the data cache uses this.
6802 MEMADDR is the address in the remote memory space.
6803 MYADDR is the address of the buffer in our space.
6804 LEN is the number of bytes.
6806 Returns number of bytes transferred, or 0 (setting errno) for
6807 error. Only transfer a single packet. */
6810 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6812 char *packet_format
= 0;
6814 /* Check whether the target supports binary download. */
6815 check_binary_download (memaddr
);
6817 switch (remote_protocol_packets
[PACKET_X
].support
)
6820 packet_format
= "X";
6822 case PACKET_DISABLE
:
6823 packet_format
= "M";
6825 case PACKET_SUPPORT_UNKNOWN
:
6826 internal_error (__FILE__
, __LINE__
,
6827 _("remote_write_bytes: bad internal state"));
6829 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6832 return remote_write_bytes_aux (packet_format
,
6833 memaddr
, myaddr
, len
, packet_format
[0], 1);
6836 /* Read memory data directly from the remote machine.
6837 This does not use the data cache; the data cache uses this.
6838 MEMADDR is the address in the remote memory space.
6839 MYADDR is the address of the buffer in our space.
6840 LEN is the number of bytes.
6842 Returns number of bytes transferred, or 0 for error. */
6845 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6847 struct remote_state
*rs
= get_remote_state ();
6848 int max_buf_size
; /* Max size of packet output buffer. */
6856 max_buf_size
= get_memory_read_packet_size ();
6857 /* The packet buffer will be large enough for the payload;
6858 get_memory_packet_size ensures this. */
6860 /* Number if bytes that will fit. */
6861 todo
= min (len
, max_buf_size
/ 2);
6863 /* Construct "m"<memaddr>","<len>". */
6864 memaddr
= remote_address_masked (memaddr
);
6867 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6869 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6872 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6873 if (rs
->buf
[0] == 'E'
6874 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6875 && rs
->buf
[3] == '\0')
6877 /* There is no correspondance between what the remote protocol
6878 uses for errors and errno codes. We would like a cleaner way
6879 of representing errors (big enough to include errno codes,
6880 bfd_error codes, and others). But for now just return
6885 /* Reply describes memory byte by byte, each byte encoded as two hex
6888 i
= hex2bin (p
, myaddr
, todo
);
6889 /* Return what we have. Let higher layers handle partial reads. */
6894 /* Read or write LEN bytes from inferior memory at MEMADDR,
6895 transferring to or from debugger address BUFFER. Write to inferior
6896 if SHOULD_WRITE is nonzero. Returns length of data written or
6897 read; 0 for error. TARGET is unused. */
6900 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6901 int should_write
, struct mem_attrib
*attrib
,
6902 struct target_ops
*target
)
6906 set_remote_traceframe ();
6907 set_general_thread (inferior_ptid
);
6910 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6912 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6917 /* Sends a packet with content determined by the printf format string
6918 FORMAT and the remaining arguments, then gets the reply. Returns
6919 whether the packet was a success, a failure, or unknown. */
6921 static enum packet_result
6922 remote_send_printf (const char *format
, ...)
6924 struct remote_state
*rs
= get_remote_state ();
6925 int max_size
= get_remote_packet_size ();
6928 va_start (ap
, format
);
6931 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6932 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6934 if (putpkt (rs
->buf
) < 0)
6935 error (_("Communication problem with target."));
6938 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6940 return packet_check_result (rs
->buf
);
6944 restore_remote_timeout (void *p
)
6946 int value
= *(int *)p
;
6948 remote_timeout
= value
;
6951 /* Flash writing can take quite some time. We'll set
6952 effectively infinite timeout for flash operations.
6953 In future, we'll need to decide on a better approach. */
6954 static const int remote_flash_timeout
= 1000;
6957 remote_flash_erase (struct target_ops
*ops
,
6958 ULONGEST address
, LONGEST length
)
6960 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
6961 int saved_remote_timeout
= remote_timeout
;
6962 enum packet_result ret
;
6963 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6964 &saved_remote_timeout
);
6966 remote_timeout
= remote_flash_timeout
;
6968 ret
= remote_send_printf ("vFlashErase:%s,%s",
6969 phex (address
, addr_size
),
6973 case PACKET_UNKNOWN
:
6974 error (_("Remote target does not support flash erase"));
6976 error (_("Error erasing flash with vFlashErase packet"));
6981 do_cleanups (back_to
);
6985 remote_flash_write (struct target_ops
*ops
,
6986 ULONGEST address
, LONGEST length
,
6987 const gdb_byte
*data
)
6989 int saved_remote_timeout
= remote_timeout
;
6991 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6992 &saved_remote_timeout
);
6994 remote_timeout
= remote_flash_timeout
;
6995 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6996 do_cleanups (back_to
);
7002 remote_flash_done (struct target_ops
*ops
)
7004 int saved_remote_timeout
= remote_timeout
;
7006 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7007 &saved_remote_timeout
);
7009 remote_timeout
= remote_flash_timeout
;
7010 ret
= remote_send_printf ("vFlashDone");
7011 do_cleanups (back_to
);
7015 case PACKET_UNKNOWN
:
7016 error (_("Remote target does not support vFlashDone"));
7018 error (_("Error finishing flash operation"));
7025 remote_files_info (struct target_ops
*ignore
)
7027 puts_filtered ("Debugging a target over a serial line.\n");
7030 /* Stuff for dealing with the packets which are part of this protocol.
7031 See comment at top of file for details. */
7033 /* Read a single character from the remote end. */
7036 readchar (int timeout
)
7040 ch
= serial_readchar (remote_desc
, timeout
);
7045 switch ((enum serial_rc
) ch
)
7048 remote_unpush_target ();
7049 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7052 remote_unpush_target ();
7053 throw_perror_with_name (TARGET_CLOSE_ERROR
,
7054 _("Remote communication error. "
7055 "Target disconnected."));
7057 case SERIAL_TIMEOUT
:
7063 /* Send the command in *BUF to the remote machine, and read the reply
7064 into *BUF. Report an error if we get an error reply. Resize
7065 *BUF using xrealloc if necessary to hold the result, and update
7069 remote_send (char **buf
,
7073 getpkt (buf
, sizeof_buf
, 0);
7075 if ((*buf
)[0] == 'E')
7076 error (_("Remote failure reply: %s"), *buf
);
7079 /* Return a pointer to an xmalloc'ed string representing an escaped
7080 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7081 etc. The caller is responsible for releasing the returned
7085 escape_buffer (const char *buf
, int n
)
7087 struct cleanup
*old_chain
;
7088 struct ui_file
*stb
;
7091 stb
= mem_fileopen ();
7092 old_chain
= make_cleanup_ui_file_delete (stb
);
7094 fputstrn_unfiltered (buf
, n
, 0, stb
);
7095 str
= ui_file_xstrdup (stb
, NULL
);
7096 do_cleanups (old_chain
);
7100 /* Display a null-terminated packet on stdout, for debugging, using C
7104 print_packet (char *buf
)
7106 puts_filtered ("\"");
7107 fputstr_filtered (buf
, '"', gdb_stdout
);
7108 puts_filtered ("\"");
7114 return putpkt_binary (buf
, strlen (buf
));
7117 /* Send a packet to the remote machine, with error checking. The data
7118 of the packet is in BUF. The string in BUF can be at most
7119 get_remote_packet_size () - 5 to account for the $, # and checksum,
7120 and for a possible /0 if we are debugging (remote_debug) and want
7121 to print the sent packet as a string. */
7124 putpkt_binary (char *buf
, int cnt
)
7126 struct remote_state
*rs
= get_remote_state ();
7128 unsigned char csum
= 0;
7129 char *buf2
= alloca (cnt
+ 6);
7136 /* Catch cases like trying to read memory or listing threads while
7137 we're waiting for a stop reply. The remote server wouldn't be
7138 ready to handle this request, so we'd hang and timeout. We don't
7139 have to worry about this in synchronous mode, because in that
7140 case it's not possible to issue a command while the target is
7141 running. This is not a problem in non-stop mode, because in that
7142 case, the stub is always ready to process serial input. */
7143 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7144 error (_("Cannot execute this command while the target is running."));
7146 /* We're sending out a new packet. Make sure we don't look at a
7147 stale cached response. */
7148 rs
->cached_wait_status
= 0;
7150 /* Copy the packet into buffer BUF2, encapsulating it
7151 and giving it a checksum. */
7156 for (i
= 0; i
< cnt
; i
++)
7162 *p
++ = tohex ((csum
>> 4) & 0xf);
7163 *p
++ = tohex (csum
& 0xf);
7165 /* Send it over and over until we get a positive ack. */
7169 int started_error_output
= 0;
7173 struct cleanup
*old_chain
;
7177 str
= escape_buffer (buf2
, p
- buf2
);
7178 old_chain
= make_cleanup (xfree
, str
);
7179 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7180 gdb_flush (gdb_stdlog
);
7181 do_cleanups (old_chain
);
7183 if (serial_write (remote_desc
, buf2
, p
- buf2
))
7184 perror_with_name (_("putpkt: write failed"));
7186 /* If this is a no acks version of the remote protocol, send the
7187 packet and move on. */
7191 /* Read until either a timeout occurs (-2) or '+' is read.
7192 Handle any notification that arrives in the mean time. */
7195 ch
= readchar (remote_timeout
);
7203 case SERIAL_TIMEOUT
:
7206 if (started_error_output
)
7208 putchar_unfiltered ('\n');
7209 started_error_output
= 0;
7218 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7222 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7224 case SERIAL_TIMEOUT
:
7228 break; /* Retransmit buffer. */
7232 fprintf_unfiltered (gdb_stdlog
,
7233 "Packet instead of Ack, ignoring it\n");
7234 /* It's probably an old response sent because an ACK
7235 was lost. Gobble up the packet and ack it so it
7236 doesn't get retransmitted when we resend this
7239 serial_write (remote_desc
, "+", 1);
7240 continue; /* Now, go look for +. */
7247 /* If we got a notification, handle it, and go back to looking
7249 /* We've found the start of a notification. Now
7250 collect the data. */
7251 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7256 struct cleanup
*old_chain
;
7259 str
= escape_buffer (rs
->buf
, val
);
7260 old_chain
= make_cleanup (xfree
, str
);
7261 fprintf_unfiltered (gdb_stdlog
,
7262 " Notification received: %s\n",
7264 do_cleanups (old_chain
);
7266 handle_notification (rs
->buf
);
7267 /* We're in sync now, rewait for the ack. */
7274 if (!started_error_output
)
7276 started_error_output
= 1;
7277 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7279 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7280 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7289 if (!started_error_output
)
7291 started_error_output
= 1;
7292 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7294 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7298 break; /* Here to retransmit. */
7302 /* This is wrong. If doing a long backtrace, the user should be
7303 able to get out next time we call QUIT, without anything as
7304 violent as interrupt_query. If we want to provide a way out of
7305 here without getting to the next QUIT, it should be based on
7306 hitting ^C twice as in remote_wait. */
7317 /* Come here after finding the start of a frame when we expected an
7318 ack. Do our best to discard the rest of this packet. */
7327 c
= readchar (remote_timeout
);
7330 case SERIAL_TIMEOUT
:
7331 /* Nothing we can do. */
7334 /* Discard the two bytes of checksum and stop. */
7335 c
= readchar (remote_timeout
);
7337 c
= readchar (remote_timeout
);
7340 case '*': /* Run length encoding. */
7341 /* Discard the repeat count. */
7342 c
= readchar (remote_timeout
);
7347 /* A regular character. */
7353 /* Come here after finding the start of the frame. Collect the rest
7354 into *BUF, verifying the checksum, length, and handling run-length
7355 compression. NUL terminate the buffer. If there is not enough room,
7356 expand *BUF using xrealloc.
7358 Returns -1 on error, number of characters in buffer (ignoring the
7359 trailing NULL) on success. (could be extended to return one of the
7360 SERIAL status indications). */
7363 read_frame (char **buf_p
,
7370 struct remote_state
*rs
= get_remote_state ();
7377 c
= readchar (remote_timeout
);
7380 case SERIAL_TIMEOUT
:
7382 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7386 fputs_filtered ("Saw new packet start in middle of old one\n",
7388 return -1; /* Start a new packet, count retries. */
7391 unsigned char pktcsum
;
7397 check_0
= readchar (remote_timeout
);
7399 check_1
= readchar (remote_timeout
);
7401 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7404 fputs_filtered ("Timeout in checksum, retrying\n",
7408 else if (check_0
< 0 || check_1
< 0)
7411 fputs_filtered ("Communication error in checksum\n",
7416 /* Don't recompute the checksum; with no ack packets we
7417 don't have any way to indicate a packet retransmission
7422 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7423 if (csum
== pktcsum
)
7428 struct cleanup
*old_chain
;
7431 str
= escape_buffer (buf
, bc
);
7432 old_chain
= make_cleanup (xfree
, str
);
7433 fprintf_unfiltered (gdb_stdlog
,
7434 "Bad checksum, sentsum=0x%x, "
7435 "csum=0x%x, buf=%s\n",
7436 pktcsum
, csum
, str
);
7437 do_cleanups (old_chain
);
7439 /* Number of characters in buffer ignoring trailing
7443 case '*': /* Run length encoding. */
7448 c
= readchar (remote_timeout
);
7450 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7452 /* The character before ``*'' is repeated. */
7454 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7456 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7458 /* Make some more room in the buffer. */
7459 *sizeof_buf
+= repeat
;
7460 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7464 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7470 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7474 if (bc
>= *sizeof_buf
- 1)
7476 /* Make some more room in the buffer. */
7478 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7489 /* Read a packet from the remote machine, with error checking, and
7490 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7491 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7492 rather than timing out; this is used (in synchronous mode) to wait
7493 for a target that is is executing user code to stop. */
7494 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7495 don't have to change all the calls to getpkt to deal with the
7496 return value, because at the moment I don't know what the right
7497 thing to do it for those. */
7505 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7509 /* Read a packet from the remote machine, with error checking, and
7510 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7511 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7512 rather than timing out; this is used (in synchronous mode) to wait
7513 for a target that is is executing user code to stop. If FOREVER ==
7514 0, this function is allowed to time out gracefully and return an
7515 indication of this to the caller. Otherwise return the number of
7516 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7517 enough reason to return to the caller. *IS_NOTIF is an output
7518 boolean that indicates whether *BUF holds a notification or not
7519 (a regular packet). */
7522 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7523 int expecting_notif
, int *is_notif
)
7525 struct remote_state
*rs
= get_remote_state ();
7531 /* We're reading a new response. Make sure we don't look at a
7532 previously cached response. */
7533 rs
->cached_wait_status
= 0;
7535 strcpy (*buf
, "timeout");
7538 timeout
= watchdog
> 0 ? watchdog
: -1;
7539 else if (expecting_notif
)
7540 timeout
= 0; /* There should already be a char in the buffer. If
7543 timeout
= remote_timeout
;
7547 /* Process any number of notifications, and then return when
7551 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7553 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7555 /* This can loop forever if the remote side sends us
7556 characters continuously, but if it pauses, we'll get
7557 SERIAL_TIMEOUT from readchar because of timeout. Then
7558 we'll count that as a retry.
7560 Note that even when forever is set, we will only wait
7561 forever prior to the start of a packet. After that, we
7562 expect characters to arrive at a brisk pace. They should
7563 show up within remote_timeout intervals. */
7565 c
= readchar (timeout
);
7566 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7568 if (c
== SERIAL_TIMEOUT
)
7570 if (expecting_notif
)
7571 return -1; /* Don't complain, it's normal to not get
7572 anything in this case. */
7574 if (forever
) /* Watchdog went off? Kill the target. */
7577 remote_unpush_target ();
7578 throw_error (TARGET_CLOSE_ERROR
,
7579 _("Watchdog timeout has expired. "
7580 "Target detached."));
7583 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7587 /* We've found the start of a packet or notification.
7588 Now collect the data. */
7589 val
= read_frame (buf
, sizeof_buf
);
7594 serial_write (remote_desc
, "-", 1);
7597 if (tries
> MAX_TRIES
)
7599 /* We have tried hard enough, and just can't receive the
7600 packet/notification. Give up. */
7601 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7603 /* Skip the ack char if we're in no-ack mode. */
7604 if (!rs
->noack_mode
)
7605 serial_write (remote_desc
, "+", 1);
7609 /* If we got an ordinary packet, return that to our caller. */
7614 struct cleanup
*old_chain
;
7617 str
= escape_buffer (*buf
, val
);
7618 old_chain
= make_cleanup (xfree
, str
);
7619 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7620 do_cleanups (old_chain
);
7623 /* Skip the ack char if we're in no-ack mode. */
7624 if (!rs
->noack_mode
)
7625 serial_write (remote_desc
, "+", 1);
7626 if (is_notif
!= NULL
)
7631 /* If we got a notification, handle it, and go back to looking
7635 gdb_assert (c
== '%');
7639 struct cleanup
*old_chain
;
7642 str
= escape_buffer (*buf
, val
);
7643 old_chain
= make_cleanup (xfree
, str
);
7644 fprintf_unfiltered (gdb_stdlog
,
7645 " Notification received: %s\n",
7647 do_cleanups (old_chain
);
7649 if (is_notif
!= NULL
)
7652 handle_notification (*buf
);
7654 /* Notifications require no acknowledgement. */
7656 if (expecting_notif
)
7663 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7665 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7669 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7672 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7677 /* A helper function that just calls putpkt; for type correctness. */
7680 putpkt_for_catch_errors (void *arg
)
7682 return putpkt (arg
);
7686 remote_kill (struct target_ops
*ops
)
7688 /* Use catch_errors so the user can quit from gdb even when we
7689 aren't on speaking terms with the remote system. */
7690 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7692 /* Don't wait for it to die. I'm not really sure it matters whether
7693 we do or not. For the existing stubs, kill is a noop. */
7694 target_mourn_inferior ();
7698 remote_vkill (int pid
, struct remote_state
*rs
)
7700 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7703 /* Tell the remote target to detach. */
7704 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7706 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7708 if (packet_ok (rs
->buf
,
7709 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7711 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7718 extended_remote_kill (struct target_ops
*ops
)
7721 int pid
= ptid_get_pid (inferior_ptid
);
7722 struct remote_state
*rs
= get_remote_state ();
7724 res
= remote_vkill (pid
, rs
);
7725 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7727 /* Don't try 'k' on a multi-process aware stub -- it has no way
7728 to specify the pid. */
7732 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7733 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7736 /* Don't wait for it to die. I'm not really sure it matters whether
7737 we do or not. For the existing stubs, kill is a noop. */
7743 error (_("Can't kill process"));
7745 target_mourn_inferior ();
7749 remote_mourn (struct target_ops
*ops
)
7751 remote_mourn_1 (ops
);
7754 /* Worker function for remote_mourn. */
7756 remote_mourn_1 (struct target_ops
*target
)
7758 unpush_target (target
);
7760 /* remote_close takes care of doing most of the clean up. */
7761 generic_mourn_inferior ();
7765 extended_remote_mourn_1 (struct target_ops
*target
)
7767 struct remote_state
*rs
= get_remote_state ();
7769 /* In case we got here due to an error, but we're going to stay
7771 rs
->waiting_for_stop_reply
= 0;
7773 /* If the current general thread belonged to the process we just
7774 detached from or has exited, the remote side current general
7775 thread becomes undefined. Considering a case like this:
7777 - We just got here due to a detach.
7778 - The process that we're detaching from happens to immediately
7779 report a global breakpoint being hit in non-stop mode, in the
7780 same thread we had selected before.
7781 - GDB attaches to this process again.
7782 - This event happens to be the next event we handle.
7784 GDB would consider that the current general thread didn't need to
7785 be set on the stub side (with Hg), since for all it knew,
7786 GENERAL_THREAD hadn't changed.
7788 Notice that although in all-stop mode, the remote server always
7789 sets the current thread to the thread reporting the stop event,
7790 that doesn't happen in non-stop mode; in non-stop, the stub *must
7791 not* change the current thread when reporting a breakpoint hit,
7792 due to the decoupling of event reporting and event handling.
7794 To keep things simple, we always invalidate our notion of the
7796 record_currthread (minus_one_ptid
);
7798 /* Unlike "target remote", we do not want to unpush the target; then
7799 the next time the user says "run", we won't be connected. */
7801 /* Call common code to mark the inferior as not running. */
7802 generic_mourn_inferior ();
7804 if (!have_inferiors ())
7806 if (!remote_multi_process_p (rs
))
7808 /* Check whether the target is running now - some remote stubs
7809 automatically restart after kill. */
7811 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7813 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7815 /* Assume that the target has been restarted. Set
7816 inferior_ptid so that bits of core GDB realizes
7817 there's something here, e.g., so that the user can
7818 say "kill" again. */
7819 inferior_ptid
= magic_null_ptid
;
7826 extended_remote_mourn (struct target_ops
*ops
)
7828 extended_remote_mourn_1 (ops
);
7832 extended_remote_supports_disable_randomization (void)
7834 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7839 extended_remote_disable_randomization (int val
)
7841 struct remote_state
*rs
= get_remote_state ();
7844 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7847 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7849 error (_("Target does not support QDisableRandomization."));
7850 if (strcmp (reply
, "OK") != 0)
7851 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7855 extended_remote_run (char *args
)
7857 struct remote_state
*rs
= get_remote_state ();
7860 /* If the user has disabled vRun support, or we have detected that
7861 support is not available, do not try it. */
7862 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7865 strcpy (rs
->buf
, "vRun;");
7866 len
= strlen (rs
->buf
);
7868 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7869 error (_("Remote file name too long for run packet"));
7870 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7872 gdb_assert (args
!= NULL
);
7875 struct cleanup
*back_to
;
7879 argv
= gdb_buildargv (args
);
7880 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7881 for (i
= 0; argv
[i
] != NULL
; i
++)
7883 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7884 error (_("Argument list too long for run packet"));
7885 rs
->buf
[len
++] = ';';
7886 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7888 do_cleanups (back_to
);
7891 rs
->buf
[len
++] = '\0';
7894 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7896 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7898 /* We have a wait response. All is well. */
7901 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7902 /* It wasn't disabled before, but it is now. */
7906 if (remote_exec_file
[0] == '\0')
7907 error (_("Running the default executable on the remote target failed; "
7908 "try \"set remote exec-file\"?"));
7910 error (_("Running \"%s\" on the remote target failed"),
7915 /* In the extended protocol we want to be able to do things like
7916 "run" and have them basically work as expected. So we need
7917 a special create_inferior function. We support changing the
7918 executable file and the command line arguments, but not the
7922 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7923 char **env
, int from_tty
)
7927 struct remote_state
*rs
= get_remote_state ();
7929 /* If running asynchronously, register the target file descriptor
7930 with the event loop. */
7931 if (target_can_async_p ())
7932 target_async (inferior_event_handler
, 0);
7934 /* Disable address space randomization if requested (and supported). */
7935 if (extended_remote_supports_disable_randomization ())
7936 extended_remote_disable_randomization (disable_randomization
);
7938 /* Now restart the remote server. */
7939 run_worked
= extended_remote_run (args
) != -1;
7942 /* vRun was not supported. Fail if we need it to do what the
7944 if (remote_exec_file
[0])
7945 error (_("Remote target does not support \"set remote exec-file\""));
7947 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7949 /* Fall back to "R". */
7950 extended_remote_restart ();
7953 if (!have_inferiors ())
7955 /* Clean up from the last time we ran, before we mark the target
7956 running again. This will mark breakpoints uninserted, and
7957 get_offsets may insert breakpoints. */
7958 init_thread_list ();
7959 init_wait_for_inferior ();
7962 /* vRun's success return is a stop reply. */
7963 stop_reply
= run_worked
? rs
->buf
: NULL
;
7964 add_current_inferior_and_thread (stop_reply
);
7966 /* Get updated offsets, if the stub uses qOffsets. */
7971 extended_remote_create_inferior (struct target_ops
*ops
,
7972 char *exec_file
, char *args
,
7973 char **env
, int from_tty
)
7975 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7979 /* Given a location's target info BP_TGT and the packet buffer BUF, output
7980 the list of conditions (in agent expression bytecode format), if any, the
7981 target needs to evaluate. The output is placed into the packet buffer
7982 started from BUF and ended at BUF_END. */
7985 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
7986 struct bp_target_info
*bp_tgt
, char *buf
,
7989 struct agent_expr
*aexpr
= NULL
;
7992 char *buf_start
= buf
;
7994 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
7997 buf
+= strlen (buf
);
7998 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8001 /* Send conditions to the target and free the vector. */
8003 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8006 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8007 buf
+= strlen (buf
);
8008 for (i
= 0; i
< aexpr
->len
; ++i
)
8009 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8013 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8018 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8019 struct bp_target_info
*bp_tgt
, char *buf
)
8021 struct agent_expr
*aexpr
= NULL
;
8024 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8027 buf
+= strlen (buf
);
8029 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8030 buf
+= strlen (buf
);
8032 /* Concatenate all the agent expressions that are commands into the
8035 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8038 sprintf (buf
, "X%x,", aexpr
->len
);
8039 buf
+= strlen (buf
);
8040 for (i
= 0; i
< aexpr
->len
; ++i
)
8041 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8045 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8048 /* Insert a breakpoint. On targets that have software breakpoint
8049 support, we ask the remote target to do the work; on targets
8050 which don't, we insert a traditional memory breakpoint. */
8053 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8054 struct bp_target_info
*bp_tgt
)
8056 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8057 If it succeeds, then set the support to PACKET_ENABLE. If it
8058 fails, and the user has explicitly requested the Z support then
8059 report an error, otherwise, mark it disabled and go on. */
8061 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8063 CORE_ADDR addr
= bp_tgt
->placed_address
;
8064 struct remote_state
*rs
;
8067 struct condition_list
*cond
= NULL
;
8069 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8071 rs
= get_remote_state ();
8073 endbuf
= rs
->buf
+ get_remote_packet_size ();
8078 addr
= (ULONGEST
) remote_address_masked (addr
);
8079 p
+= hexnumstr (p
, addr
);
8080 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8082 if (remote_supports_cond_breakpoints ())
8083 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8085 if (remote_can_run_breakpoint_commands ())
8086 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8089 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8091 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8096 bp_tgt
->placed_address
= addr
;
8097 bp_tgt
->placed_size
= bpsize
;
8099 case PACKET_UNKNOWN
:
8104 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8108 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8109 struct bp_target_info
*bp_tgt
)
8111 CORE_ADDR addr
= bp_tgt
->placed_address
;
8112 struct remote_state
*rs
= get_remote_state ();
8114 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8117 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8123 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8124 p
+= hexnumstr (p
, addr
);
8125 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8128 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8130 return (rs
->buf
[0] == 'E');
8133 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8137 watchpoint_to_Z_packet (int type
)
8142 return Z_PACKET_WRITE_WP
;
8145 return Z_PACKET_READ_WP
;
8148 return Z_PACKET_ACCESS_WP
;
8151 internal_error (__FILE__
, __LINE__
,
8152 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8157 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8158 struct expression
*cond
)
8160 struct remote_state
*rs
= get_remote_state ();
8161 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8163 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8165 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8168 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8169 p
= strchr (rs
->buf
, '\0');
8170 addr
= remote_address_masked (addr
);
8171 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8172 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8175 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8177 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8181 case PACKET_UNKNOWN
:
8186 internal_error (__FILE__
, __LINE__
,
8187 _("remote_insert_watchpoint: reached end of function"));
8191 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8192 CORE_ADDR start
, int length
)
8194 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8196 return diff
< length
;
8201 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8202 struct expression
*cond
)
8204 struct remote_state
*rs
= get_remote_state ();
8205 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8207 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8209 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8212 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8213 p
= strchr (rs
->buf
, '\0');
8214 addr
= remote_address_masked (addr
);
8215 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8216 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8218 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8220 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8223 case PACKET_UNKNOWN
:
8228 internal_error (__FILE__
, __LINE__
,
8229 _("remote_remove_watchpoint: reached end of function"));
8233 int remote_hw_watchpoint_limit
= -1;
8234 int remote_hw_watchpoint_length_limit
= -1;
8235 int remote_hw_breakpoint_limit
= -1;
8238 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8240 if (remote_hw_watchpoint_length_limit
== 0)
8242 else if (remote_hw_watchpoint_length_limit
< 0)
8244 else if (len
<= remote_hw_watchpoint_length_limit
)
8251 remote_check_watch_resources (int type
, int cnt
, int ot
)
8253 if (type
== bp_hardware_breakpoint
)
8255 if (remote_hw_breakpoint_limit
== 0)
8257 else if (remote_hw_breakpoint_limit
< 0)
8259 else if (cnt
<= remote_hw_breakpoint_limit
)
8264 if (remote_hw_watchpoint_limit
== 0)
8266 else if (remote_hw_watchpoint_limit
< 0)
8270 else if (cnt
<= remote_hw_watchpoint_limit
)
8277 remote_stopped_by_watchpoint (void)
8279 return remote_stopped_by_watchpoint_p
;
8283 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8287 if (remote_stopped_by_watchpoint ())
8289 *addr_p
= remote_watch_data_address
;
8298 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8299 struct bp_target_info
*bp_tgt
)
8302 struct remote_state
*rs
;
8306 /* The length field should be set to the size of a breakpoint
8307 instruction, even though we aren't inserting one ourselves. */
8309 gdbarch_remote_breakpoint_from_pc
8310 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8312 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8315 rs
= get_remote_state ();
8317 endbuf
= rs
->buf
+ get_remote_packet_size ();
8323 addr
= remote_address_masked (bp_tgt
->placed_address
);
8324 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8325 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8327 if (remote_supports_cond_breakpoints ())
8328 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8330 if (remote_can_run_breakpoint_commands ())
8331 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8334 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8336 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8339 if (rs
->buf
[1] == '.')
8341 message
= strchr (rs
->buf
+ 2, '.');
8343 error (_("Remote failure reply: %s"), message
+ 1);
8346 case PACKET_UNKNOWN
:
8351 internal_error (__FILE__
, __LINE__
,
8352 _("remote_insert_hw_breakpoint: reached end of function"));
8357 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8358 struct bp_target_info
*bp_tgt
)
8361 struct remote_state
*rs
= get_remote_state ();
8363 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8365 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8372 addr
= remote_address_masked (bp_tgt
->placed_address
);
8373 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8374 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8377 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8379 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8382 case PACKET_UNKNOWN
:
8387 internal_error (__FILE__
, __LINE__
,
8388 _("remote_remove_hw_breakpoint: reached end of function"));
8391 /* Table used by the crc32 function to calcuate the checksum. */
8393 static unsigned long crc32_table
[256] =
8396 static unsigned long
8397 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8399 if (!crc32_table
[1])
8401 /* Initialize the CRC table and the decoding table. */
8405 for (i
= 0; i
< 256; i
++)
8407 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8408 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8415 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8421 /* Verify memory using the "qCRC:" request. */
8424 remote_verify_memory (struct target_ops
*ops
,
8425 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8427 struct remote_state
*rs
= get_remote_state ();
8428 unsigned long host_crc
, target_crc
;
8431 /* FIXME: assumes lma can fit into long. */
8432 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8433 (long) lma
, (long) size
);
8436 /* Be clever; compute the host_crc before waiting for target
8438 host_crc
= crc32 (data
, size
, 0xffffffff);
8440 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8441 if (rs
->buf
[0] == 'E')
8444 if (rs
->buf
[0] != 'C')
8445 error (_("remote target does not support this operation"));
8447 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8448 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8450 return (host_crc
== target_crc
);
8453 /* compare-sections command
8455 With no arguments, compares each loadable section in the exec bfd
8456 with the same memory range on the target, and reports mismatches.
8457 Useful for verifying the image on the target against the exec file. */
8460 compare_sections_command (char *args
, int from_tty
)
8463 struct cleanup
*old_chain
;
8465 const char *sectname
;
8473 error (_("command cannot be used without an exec file"));
8475 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8477 if (!(s
->flags
& SEC_LOAD
))
8478 continue; /* Skip non-loadable section. */
8480 size
= bfd_get_section_size (s
);
8482 continue; /* Skip zero-length section. */
8484 sectname
= bfd_get_section_name (exec_bfd
, s
);
8485 if (args
&& strcmp (args
, sectname
) != 0)
8486 continue; /* Not the section selected by user. */
8488 matched
= 1; /* Do this section. */
8491 sectdata
= xmalloc (size
);
8492 old_chain
= make_cleanup (xfree
, sectdata
);
8493 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8495 res
= target_verify_memory (sectdata
, lma
, size
);
8498 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8499 paddress (target_gdbarch (), lma
),
8500 paddress (target_gdbarch (), lma
+ size
));
8502 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8503 paddress (target_gdbarch (), lma
),
8504 paddress (target_gdbarch (), lma
+ size
));
8506 printf_filtered ("matched.\n");
8509 printf_filtered ("MIS-MATCHED!\n");
8513 do_cleanups (old_chain
);
8516 warning (_("One or more sections of the remote executable does not match\n\
8517 the loaded file\n"));
8518 if (args
&& !matched
)
8519 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8522 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8523 into remote target. The number of bytes written to the remote
8524 target is returned, or -1 for error. */
8527 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8528 const char *annex
, const gdb_byte
*writebuf
,
8529 ULONGEST offset
, LONGEST len
,
8530 struct packet_config
*packet
)
8534 struct remote_state
*rs
= get_remote_state ();
8535 int max_size
= get_memory_write_packet_size ();
8537 if (packet
->support
== PACKET_DISABLE
)
8540 /* Insert header. */
8541 i
= snprintf (rs
->buf
, max_size
,
8542 "qXfer:%s:write:%s:%s:",
8543 object_name
, annex
? annex
: "",
8544 phex_nz (offset
, sizeof offset
));
8545 max_size
-= (i
+ 1);
8547 /* Escape as much data as fits into rs->buf. */
8548 buf_len
= remote_escape_output
8549 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8551 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8552 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8553 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8556 unpack_varlen_hex (rs
->buf
, &n
);
8560 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8561 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8562 number of bytes read is returned, or 0 for EOF, or -1 for error.
8563 The number of bytes read may be less than LEN without indicating an
8564 EOF. PACKET is checked and updated to indicate whether the remote
8565 target supports this object. */
8568 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8570 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8571 struct packet_config
*packet
)
8573 static char *finished_object
;
8574 static char *finished_annex
;
8575 static ULONGEST finished_offset
;
8577 struct remote_state
*rs
= get_remote_state ();
8578 LONGEST i
, n
, packet_len
;
8580 if (packet
->support
== PACKET_DISABLE
)
8583 /* Check whether we've cached an end-of-object packet that matches
8585 if (finished_object
)
8587 if (strcmp (object_name
, finished_object
) == 0
8588 && strcmp (annex
? annex
: "", finished_annex
) == 0
8589 && offset
== finished_offset
)
8592 /* Otherwise, we're now reading something different. Discard
8594 xfree (finished_object
);
8595 xfree (finished_annex
);
8596 finished_object
= NULL
;
8597 finished_annex
= NULL
;
8600 /* Request only enough to fit in a single packet. The actual data
8601 may not, since we don't know how much of it will need to be escaped;
8602 the target is free to respond with slightly less data. We subtract
8603 five to account for the response type and the protocol frame. */
8604 n
= min (get_remote_packet_size () - 5, len
);
8605 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8606 object_name
, annex
? annex
: "",
8607 phex_nz (offset
, sizeof offset
),
8608 phex_nz (n
, sizeof n
));
8609 i
= putpkt (rs
->buf
);
8614 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8615 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8618 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8619 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8621 /* 'm' means there is (or at least might be) more data after this
8622 batch. That does not make sense unless there's at least one byte
8623 of data in this reply. */
8624 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8625 error (_("Remote qXfer reply contained no data."));
8627 /* Got some data. */
8628 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8630 /* 'l' is an EOF marker, possibly including a final block of data,
8631 or possibly empty. If we have the final block of a non-empty
8632 object, record this fact to bypass a subsequent partial read. */
8633 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8635 finished_object
= xstrdup (object_name
);
8636 finished_annex
= xstrdup (annex
? annex
: "");
8637 finished_offset
= offset
+ i
;
8644 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8645 const char *annex
, gdb_byte
*readbuf
,
8646 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8648 struct remote_state
*rs
;
8653 set_remote_traceframe ();
8654 set_general_thread (inferior_ptid
);
8656 rs
= get_remote_state ();
8658 /* Handle memory using the standard memory routines. */
8659 if (object
== TARGET_OBJECT_MEMORY
)
8665 /* If the remote target is connected but not running, we should
8666 pass this request down to a lower stratum (e.g. the executable
8668 if (!target_has_execution
)
8671 if (writebuf
!= NULL
)
8672 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8674 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8678 else if (xfered
== 0 && errno
== 0)
8684 /* Handle SPU memory using qxfer packets. */
8685 if (object
== TARGET_OBJECT_SPU
)
8688 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8689 &remote_protocol_packets
8690 [PACKET_qXfer_spu_read
]);
8692 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8693 &remote_protocol_packets
8694 [PACKET_qXfer_spu_write
]);
8697 /* Handle extra signal info using qxfer packets. */
8698 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8701 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8702 &remote_protocol_packets
8703 [PACKET_qXfer_siginfo_read
]);
8705 return remote_write_qxfer (ops
, "siginfo", annex
,
8706 writebuf
, offset
, len
,
8707 &remote_protocol_packets
8708 [PACKET_qXfer_siginfo_write
]);
8711 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8714 return remote_read_qxfer (ops
, "statictrace", annex
,
8715 readbuf
, offset
, len
,
8716 &remote_protocol_packets
8717 [PACKET_qXfer_statictrace_read
]);
8722 /* Only handle flash writes. */
8723 if (writebuf
!= NULL
)
8729 case TARGET_OBJECT_FLASH
:
8730 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8734 else if (xfered
== 0 && errno
== 0)
8744 /* Map pre-existing objects onto letters. DO NOT do this for new
8745 objects!!! Instead specify new query packets. */
8748 case TARGET_OBJECT_AVR
:
8752 case TARGET_OBJECT_AUXV
:
8753 gdb_assert (annex
== NULL
);
8754 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8755 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8757 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8758 return remote_read_qxfer
8759 (ops
, "features", annex
, readbuf
, offset
, len
,
8760 &remote_protocol_packets
[PACKET_qXfer_features
]);
8762 case TARGET_OBJECT_LIBRARIES
:
8763 return remote_read_qxfer
8764 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8765 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8767 case TARGET_OBJECT_LIBRARIES_SVR4
:
8768 return remote_read_qxfer
8769 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8770 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8772 case TARGET_OBJECT_MEMORY_MAP
:
8773 gdb_assert (annex
== NULL
);
8774 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8775 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8777 case TARGET_OBJECT_OSDATA
:
8778 /* Should only get here if we're connected. */
8779 gdb_assert (remote_desc
);
8780 return remote_read_qxfer
8781 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8782 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8784 case TARGET_OBJECT_THREADS
:
8785 gdb_assert (annex
== NULL
);
8786 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8787 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8789 case TARGET_OBJECT_TRACEFRAME_INFO
:
8790 gdb_assert (annex
== NULL
);
8791 return remote_read_qxfer
8792 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8793 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8795 case TARGET_OBJECT_FDPIC
:
8796 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8797 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8799 case TARGET_OBJECT_OPENVMS_UIB
:
8800 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8801 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8803 case TARGET_OBJECT_BTRACE
:
8804 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8805 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8811 /* Note: a zero OFFSET and LEN can be used to query the minimum
8813 if (offset
== 0 && len
== 0)
8814 return (get_remote_packet_size ());
8815 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8816 large enough let the caller deal with it. */
8817 if (len
< get_remote_packet_size ())
8819 len
= get_remote_packet_size ();
8821 /* Except for querying the minimum buffer size, target must be open. */
8823 error (_("remote query is only available after target open"));
8825 gdb_assert (annex
!= NULL
);
8826 gdb_assert (readbuf
!= NULL
);
8832 /* We used one buffer char for the remote protocol q command and
8833 another for the query type. As the remote protocol encapsulation
8834 uses 4 chars plus one extra in case we are debugging
8835 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8838 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8840 /* Bad caller may have sent forbidden characters. */
8841 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8846 gdb_assert (annex
[i
] == '\0');
8848 i
= putpkt (rs
->buf
);
8852 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8853 strcpy ((char *) readbuf
, rs
->buf
);
8855 return strlen ((char *) readbuf
);
8859 remote_search_memory (struct target_ops
* ops
,
8860 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8861 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8862 CORE_ADDR
*found_addrp
)
8864 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8865 struct remote_state
*rs
= get_remote_state ();
8866 int max_size
= get_memory_write_packet_size ();
8867 struct packet_config
*packet
=
8868 &remote_protocol_packets
[PACKET_qSearch_memory
];
8869 /* Number of packet bytes used to encode the pattern;
8870 this could be more than PATTERN_LEN due to escape characters. */
8871 int escaped_pattern_len
;
8872 /* Amount of pattern that was encodable in the packet. */
8873 int used_pattern_len
;
8876 ULONGEST found_addr
;
8878 /* Don't go to the target if we don't have to.
8879 This is done before checking packet->support to avoid the possibility that
8880 a success for this edge case means the facility works in general. */
8881 if (pattern_len
> search_space_len
)
8883 if (pattern_len
== 0)
8885 *found_addrp
= start_addr
;
8889 /* If we already know the packet isn't supported, fall back to the simple
8890 way of searching memory. */
8892 if (packet
->support
== PACKET_DISABLE
)
8894 /* Target doesn't provided special support, fall back and use the
8895 standard support (copy memory and do the search here). */
8896 return simple_search_memory (ops
, start_addr
, search_space_len
,
8897 pattern
, pattern_len
, found_addrp
);
8900 /* Insert header. */
8901 i
= snprintf (rs
->buf
, max_size
,
8902 "qSearch:memory:%s;%s;",
8903 phex_nz (start_addr
, addr_size
),
8904 phex_nz (search_space_len
, sizeof (search_space_len
)));
8905 max_size
-= (i
+ 1);
8907 /* Escape as much data as fits into rs->buf. */
8908 escaped_pattern_len
=
8909 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8910 &used_pattern_len
, max_size
);
8912 /* Bail if the pattern is too large. */
8913 if (used_pattern_len
!= pattern_len
)
8914 error (_("Pattern is too large to transmit to remote target."));
8916 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8917 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8918 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8920 /* The request may not have worked because the command is not
8921 supported. If so, fall back to the simple way. */
8922 if (packet
->support
== PACKET_DISABLE
)
8924 return simple_search_memory (ops
, start_addr
, search_space_len
,
8925 pattern
, pattern_len
, found_addrp
);
8930 if (rs
->buf
[0] == '0')
8932 else if (rs
->buf
[0] == '1')
8935 if (rs
->buf
[1] != ',')
8936 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8937 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8938 *found_addrp
= found_addr
;
8941 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8947 remote_rcmd (char *command
,
8948 struct ui_file
*outbuf
)
8950 struct remote_state
*rs
= get_remote_state ();
8954 error (_("remote rcmd is only available after target open"));
8956 /* Send a NULL command across as an empty command. */
8957 if (command
== NULL
)
8960 /* The query prefix. */
8961 strcpy (rs
->buf
, "qRcmd,");
8962 p
= strchr (rs
->buf
, '\0');
8964 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8965 > get_remote_packet_size ())
8966 error (_("\"monitor\" command ``%s'' is too long."), command
);
8968 /* Encode the actual command. */
8969 bin2hex ((gdb_byte
*) command
, p
, 0);
8971 if (putpkt (rs
->buf
) < 0)
8972 error (_("Communication problem with target."));
8974 /* get/display the response */
8979 /* XXX - see also remote_get_noisy_reply(). */
8980 QUIT
; /* Allow user to bail out with ^C. */
8982 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
8984 /* Timeout. Continue to (try to) read responses.
8985 This is better than stopping with an error, assuming the stub
8986 is still executing the (long) monitor command.
8987 If needed, the user can interrupt gdb using C-c, obtaining
8988 an effect similar to stop on timeout. */
8993 error (_("Target does not support this command."));
8994 if (buf
[0] == 'O' && buf
[1] != 'K')
8996 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8999 if (strcmp (buf
, "OK") == 0)
9001 if (strlen (buf
) == 3 && buf
[0] == 'E'
9002 && isdigit (buf
[1]) && isdigit (buf
[2]))
9004 error (_("Protocol error with Rcmd"));
9006 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9008 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9010 fputc_unfiltered (c
, outbuf
);
9016 static VEC(mem_region_s
) *
9017 remote_memory_map (struct target_ops
*ops
)
9019 VEC(mem_region_s
) *result
= NULL
;
9020 char *text
= target_read_stralloc (¤t_target
,
9021 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9025 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9027 result
= parse_memory_map (text
);
9028 do_cleanups (back_to
);
9035 packet_command (char *args
, int from_tty
)
9037 struct remote_state
*rs
= get_remote_state ();
9040 error (_("command can only be used with remote target"));
9043 error (_("remote-packet command requires packet text as argument"));
9045 puts_filtered ("sending: ");
9046 print_packet (args
);
9047 puts_filtered ("\n");
9050 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9051 puts_filtered ("received: ");
9052 print_packet (rs
->buf
);
9053 puts_filtered ("\n");
9057 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9059 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9061 static void threadset_test_cmd (char *cmd
, int tty
);
9063 static void threadalive_test (char *cmd
, int tty
);
9065 static void threadlist_test_cmd (char *cmd
, int tty
);
9067 int get_and_display_threadinfo (threadref
*ref
);
9069 static void threadinfo_test_cmd (char *cmd
, int tty
);
9071 static int thread_display_step (threadref
*ref
, void *context
);
9073 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9075 static void init_remote_threadtests (void);
9077 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9080 threadset_test_cmd (char *cmd
, int tty
)
9082 int sample_thread
= SAMPLE_THREAD
;
9084 printf_filtered (_("Remote threadset test\n"));
9085 set_general_thread (sample_thread
);
9090 threadalive_test (char *cmd
, int tty
)
9092 int sample_thread
= SAMPLE_THREAD
;
9093 int pid
= ptid_get_pid (inferior_ptid
);
9094 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9096 if (remote_thread_alive (ptid
))
9097 printf_filtered ("PASS: Thread alive test\n");
9099 printf_filtered ("FAIL: Thread alive test\n");
9102 void output_threadid (char *title
, threadref
*ref
);
9105 output_threadid (char *title
, threadref
*ref
)
9109 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9111 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9115 threadlist_test_cmd (char *cmd
, int tty
)
9118 threadref nextthread
;
9119 int done
, result_count
;
9120 threadref threadlist
[3];
9122 printf_filtered ("Remote Threadlist test\n");
9123 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9124 &result_count
, &threadlist
[0]))
9125 printf_filtered ("FAIL: threadlist test\n");
9128 threadref
*scan
= threadlist
;
9129 threadref
*limit
= scan
+ result_count
;
9131 while (scan
< limit
)
9132 output_threadid (" thread ", scan
++);
9137 display_thread_info (struct gdb_ext_thread_info
*info
)
9139 output_threadid ("Threadid: ", &info
->threadid
);
9140 printf_filtered ("Name: %s\n ", info
->shortname
);
9141 printf_filtered ("State: %s\n", info
->display
);
9142 printf_filtered ("other: %s\n\n", info
->more_display
);
9146 get_and_display_threadinfo (threadref
*ref
)
9150 struct gdb_ext_thread_info threadinfo
;
9152 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9153 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9154 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9155 display_thread_info (&threadinfo
);
9160 threadinfo_test_cmd (char *cmd
, int tty
)
9162 int athread
= SAMPLE_THREAD
;
9166 int_to_threadref (&thread
, athread
);
9167 printf_filtered ("Remote Threadinfo test\n");
9168 if (!get_and_display_threadinfo (&thread
))
9169 printf_filtered ("FAIL cannot get thread info\n");
9173 thread_display_step (threadref
*ref
, void *context
)
9175 /* output_threadid(" threadstep ",ref); *//* simple test */
9176 return get_and_display_threadinfo (ref
);
9180 threadlist_update_test_cmd (char *cmd
, int tty
)
9182 printf_filtered ("Remote Threadlist update test\n");
9183 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9187 init_remote_threadtests (void)
9189 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9190 _("Fetch and print the remote list of "
9191 "thread identifiers, one pkt only"));
9192 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9193 _("Fetch and display info about one thread"));
9194 add_com ("tset", class_obscure
, threadset_test_cmd
,
9195 _("Test setting to a different thread"));
9196 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9197 _("Iterate through updating all remote thread info"));
9198 add_com ("talive", class_obscure
, threadalive_test
,
9199 _(" Remote thread alive test "));
9204 /* Convert a thread ID to a string. Returns the string in a static
9208 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9210 static char buf
[64];
9211 struct remote_state
*rs
= get_remote_state ();
9213 if (ptid_equal (ptid
, null_ptid
))
9214 return normal_pid_to_str (ptid
);
9215 else if (ptid_is_pid (ptid
))
9217 /* Printing an inferior target id. */
9219 /* When multi-process extensions are off, there's no way in the
9220 remote protocol to know the remote process id, if there's any
9221 at all. There's one exception --- when we're connected with
9222 target extended-remote, and we manually attached to a process
9223 with "attach PID". We don't record anywhere a flag that
9224 allows us to distinguish that case from the case of
9225 connecting with extended-remote and the stub already being
9226 attached to a process, and reporting yes to qAttached, hence
9227 no smart special casing here. */
9228 if (!remote_multi_process_p (rs
))
9230 xsnprintf (buf
, sizeof buf
, "Remote target");
9234 return normal_pid_to_str (ptid
);
9238 if (ptid_equal (magic_null_ptid
, ptid
))
9239 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9240 else if (rs
->extended
&& remote_multi_process_p (rs
))
9241 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9242 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9244 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9245 ptid_get_tid (ptid
));
9250 /* Get the address of the thread local variable in OBJFILE which is
9251 stored at OFFSET within the thread local storage for thread PTID. */
9254 remote_get_thread_local_address (struct target_ops
*ops
,
9255 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9257 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9259 struct remote_state
*rs
= get_remote_state ();
9261 char *endp
= rs
->buf
+ get_remote_packet_size ();
9262 enum packet_result result
;
9264 strcpy (p
, "qGetTLSAddr:");
9266 p
= write_ptid (p
, endp
, ptid
);
9268 p
+= hexnumstr (p
, offset
);
9270 p
+= hexnumstr (p
, lm
);
9274 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9275 result
= packet_ok (rs
->buf
,
9276 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9277 if (result
== PACKET_OK
)
9281 unpack_varlen_hex (rs
->buf
, &result
);
9284 else if (result
== PACKET_UNKNOWN
)
9285 throw_error (TLS_GENERIC_ERROR
,
9286 _("Remote target doesn't support qGetTLSAddr packet"));
9288 throw_error (TLS_GENERIC_ERROR
,
9289 _("Remote target failed to process qGetTLSAddr request"));
9292 throw_error (TLS_GENERIC_ERROR
,
9293 _("TLS not supported or disabled on this target"));
9298 /* Provide thread local base, i.e. Thread Information Block address.
9299 Returns 1 if ptid is found and thread_local_base is non zero. */
9302 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9304 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9306 struct remote_state
*rs
= get_remote_state ();
9308 char *endp
= rs
->buf
+ get_remote_packet_size ();
9309 enum packet_result result
;
9311 strcpy (p
, "qGetTIBAddr:");
9313 p
= write_ptid (p
, endp
, ptid
);
9317 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9318 result
= packet_ok (rs
->buf
,
9319 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9320 if (result
== PACKET_OK
)
9324 unpack_varlen_hex (rs
->buf
, &result
);
9326 *addr
= (CORE_ADDR
) result
;
9329 else if (result
== PACKET_UNKNOWN
)
9330 error (_("Remote target doesn't support qGetTIBAddr packet"));
9332 error (_("Remote target failed to process qGetTIBAddr request"));
9335 error (_("qGetTIBAddr not supported or disabled on this target"));
9340 /* Support for inferring a target description based on the current
9341 architecture and the size of a 'g' packet. While the 'g' packet
9342 can have any size (since optional registers can be left off the
9343 end), some sizes are easily recognizable given knowledge of the
9344 approximate architecture. */
9346 struct remote_g_packet_guess
9349 const struct target_desc
*tdesc
;
9351 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9352 DEF_VEC_O(remote_g_packet_guess_s
);
9354 struct remote_g_packet_data
9356 VEC(remote_g_packet_guess_s
) *guesses
;
9359 static struct gdbarch_data
*remote_g_packet_data_handle
;
9362 remote_g_packet_data_init (struct obstack
*obstack
)
9364 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9368 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9369 const struct target_desc
*tdesc
)
9371 struct remote_g_packet_data
*data
9372 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9373 struct remote_g_packet_guess new_guess
, *guess
;
9376 gdb_assert (tdesc
!= NULL
);
9379 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9381 if (guess
->bytes
== bytes
)
9382 internal_error (__FILE__
, __LINE__
,
9383 _("Duplicate g packet description added for size %d"),
9386 new_guess
.bytes
= bytes
;
9387 new_guess
.tdesc
= tdesc
;
9388 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9391 /* Return 1 if remote_read_description would do anything on this target
9392 and architecture, 0 otherwise. */
9395 remote_read_description_p (struct target_ops
*target
)
9397 struct remote_g_packet_data
*data
9398 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9400 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9406 static const struct target_desc
*
9407 remote_read_description (struct target_ops
*target
)
9409 struct remote_g_packet_data
*data
9410 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9412 /* Do not try this during initial connection, when we do not know
9413 whether there is a running but stopped thread. */
9414 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9417 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9419 struct remote_g_packet_guess
*guess
;
9421 int bytes
= send_g_packet ();
9424 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9426 if (guess
->bytes
== bytes
)
9427 return guess
->tdesc
;
9429 /* We discard the g packet. A minor optimization would be to
9430 hold on to it, and fill the register cache once we have selected
9431 an architecture, but it's too tricky to do safely. */
9437 /* Remote file transfer support. This is host-initiated I/O, not
9438 target-initiated; for target-initiated, see remote-fileio.c. */
9440 /* If *LEFT is at least the length of STRING, copy STRING to
9441 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9442 decrease *LEFT. Otherwise raise an error. */
9445 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9447 int len
= strlen (string
);
9450 error (_("Packet too long for target."));
9452 memcpy (*buffer
, string
, len
);
9456 /* NUL-terminate the buffer as a convenience, if there is
9462 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9463 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9464 decrease *LEFT. Otherwise raise an error. */
9467 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9470 if (2 * len
> *left
)
9471 error (_("Packet too long for target."));
9473 bin2hex (bytes
, *buffer
, len
);
9477 /* NUL-terminate the buffer as a convenience, if there is
9483 /* If *LEFT is large enough, convert VALUE to hex and add it to
9484 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9485 decrease *LEFT. Otherwise raise an error. */
9488 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9490 int len
= hexnumlen (value
);
9493 error (_("Packet too long for target."));
9495 hexnumstr (*buffer
, value
);
9499 /* NUL-terminate the buffer as a convenience, if there is
9505 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9506 value, *REMOTE_ERRNO to the remote error number or zero if none
9507 was included, and *ATTACHMENT to point to the start of the annex
9508 if any. The length of the packet isn't needed here; there may
9509 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9511 Return 0 if the packet could be parsed, -1 if it could not. If
9512 -1 is returned, the other variables may not be initialized. */
9515 remote_hostio_parse_result (char *buffer
, int *retcode
,
9516 int *remote_errno
, char **attachment
)
9523 if (buffer
[0] != 'F')
9527 *retcode
= strtol (&buffer
[1], &p
, 16);
9528 if (errno
!= 0 || p
== &buffer
[1])
9531 /* Check for ",errno". */
9535 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9536 if (errno
!= 0 || p
+ 1 == p2
)
9541 /* Check for ";attachment". If there is no attachment, the
9542 packet should end here. */
9545 *attachment
= p
+ 1;
9548 else if (*p
== '\0')
9554 /* Send a prepared I/O packet to the target and read its response.
9555 The prepared packet is in the global RS->BUF before this function
9556 is called, and the answer is there when we return.
9558 COMMAND_BYTES is the length of the request to send, which may include
9559 binary data. WHICH_PACKET is the packet configuration to check
9560 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9561 is set to the error number and -1 is returned. Otherwise the value
9562 returned by the function is returned.
9564 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9565 attachment is expected; an error will be reported if there's a
9566 mismatch. If one is found, *ATTACHMENT will be set to point into
9567 the packet buffer and *ATTACHMENT_LEN will be set to the
9568 attachment's length. */
9571 remote_hostio_send_command (int command_bytes
, int which_packet
,
9572 int *remote_errno
, char **attachment
,
9573 int *attachment_len
)
9575 struct remote_state
*rs
= get_remote_state ();
9576 int ret
, bytes_read
;
9577 char *attachment_tmp
;
9580 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9582 *remote_errno
= FILEIO_ENOSYS
;
9586 putpkt_binary (rs
->buf
, command_bytes
);
9587 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9589 /* If it timed out, something is wrong. Don't try to parse the
9593 *remote_errno
= FILEIO_EINVAL
;
9597 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9600 *remote_errno
= FILEIO_EINVAL
;
9602 case PACKET_UNKNOWN
:
9603 *remote_errno
= FILEIO_ENOSYS
;
9609 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9612 *remote_errno
= FILEIO_EINVAL
;
9616 /* Make sure we saw an attachment if and only if we expected one. */
9617 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9618 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9620 *remote_errno
= FILEIO_EINVAL
;
9624 /* If an attachment was found, it must point into the packet buffer;
9625 work out how many bytes there were. */
9626 if (attachment_tmp
!= NULL
)
9628 *attachment
= attachment_tmp
;
9629 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9635 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9636 remote file descriptor, or -1 if an error occurs (and set
9640 remote_hostio_open (const char *filename
, int flags
, int mode
,
9643 struct remote_state
*rs
= get_remote_state ();
9645 int left
= get_remote_packet_size () - 1;
9647 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9649 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9651 remote_buffer_add_string (&p
, &left
, ",");
9653 remote_buffer_add_int (&p
, &left
, flags
);
9654 remote_buffer_add_string (&p
, &left
, ",");
9656 remote_buffer_add_int (&p
, &left
, mode
);
9658 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9659 remote_errno
, NULL
, NULL
);
9662 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9663 Return the number of bytes written, or -1 if an error occurs (and
9664 set *REMOTE_ERRNO). */
9667 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9668 ULONGEST offset
, int *remote_errno
)
9670 struct remote_state
*rs
= get_remote_state ();
9672 int left
= get_remote_packet_size ();
9675 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9677 remote_buffer_add_int (&p
, &left
, fd
);
9678 remote_buffer_add_string (&p
, &left
, ",");
9680 remote_buffer_add_int (&p
, &left
, offset
);
9681 remote_buffer_add_string (&p
, &left
, ",");
9683 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9684 get_remote_packet_size () - (p
- rs
->buf
));
9686 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9687 remote_errno
, NULL
, NULL
);
9690 /* Read up to LEN bytes FD on the remote target into READ_BUF
9691 Return the number of bytes read, or -1 if an error occurs (and
9692 set *REMOTE_ERRNO). */
9695 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9696 ULONGEST offset
, int *remote_errno
)
9698 struct remote_state
*rs
= get_remote_state ();
9701 int left
= get_remote_packet_size ();
9702 int ret
, attachment_len
;
9705 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9707 remote_buffer_add_int (&p
, &left
, fd
);
9708 remote_buffer_add_string (&p
, &left
, ",");
9710 remote_buffer_add_int (&p
, &left
, len
);
9711 remote_buffer_add_string (&p
, &left
, ",");
9713 remote_buffer_add_int (&p
, &left
, offset
);
9715 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9716 remote_errno
, &attachment
,
9722 read_len
= remote_unescape_input (attachment
, attachment_len
,
9724 if (read_len
!= ret
)
9725 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9730 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9731 (and set *REMOTE_ERRNO). */
9734 remote_hostio_close (int fd
, int *remote_errno
)
9736 struct remote_state
*rs
= get_remote_state ();
9738 int left
= get_remote_packet_size () - 1;
9740 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9742 remote_buffer_add_int (&p
, &left
, fd
);
9744 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9745 remote_errno
, NULL
, NULL
);
9748 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9749 occurs (and set *REMOTE_ERRNO). */
9752 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9754 struct remote_state
*rs
= get_remote_state ();
9756 int left
= get_remote_packet_size () - 1;
9758 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9760 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9763 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9764 remote_errno
, NULL
, NULL
);
9767 /* Read value of symbolic link FILENAME on the remote target. Return
9768 a null-terminated string allocated via xmalloc, or NULL if an error
9769 occurs (and set *REMOTE_ERRNO). */
9772 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9774 struct remote_state
*rs
= get_remote_state ();
9777 int left
= get_remote_packet_size ();
9778 int len
, attachment_len
;
9782 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9784 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9787 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9788 remote_errno
, &attachment
,
9794 ret
= xmalloc (len
+ 1);
9796 read_len
= remote_unescape_input (attachment
, attachment_len
,
9798 if (read_len
!= len
)
9799 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9806 remote_fileio_errno_to_host (int errnum
)
9830 case FILEIO_ENOTDIR
:
9850 case FILEIO_ENAMETOOLONG
:
9851 return ENAMETOOLONG
;
9857 remote_hostio_error (int errnum
)
9859 int host_error
= remote_fileio_errno_to_host (errnum
);
9861 if (host_error
== -1)
9862 error (_("Unknown remote I/O error %d"), errnum
);
9864 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9868 remote_hostio_close_cleanup (void *opaque
)
9870 int fd
= *(int *) opaque
;
9873 remote_hostio_close (fd
, &remote_errno
);
9878 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9880 const char *filename
= bfd_get_filename (abfd
);
9881 int fd
, remote_errno
;
9884 gdb_assert (remote_filename_p (filename
));
9886 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9889 errno
= remote_fileio_errno_to_host (remote_errno
);
9890 bfd_set_error (bfd_error_system_call
);
9894 stream
= xmalloc (sizeof (int));
9900 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9902 int fd
= *(int *)stream
;
9907 /* Ignore errors on close; these may happen if the remote
9908 connection was already torn down. */
9909 remote_hostio_close (fd
, &remote_errno
);
9915 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9916 file_ptr nbytes
, file_ptr offset
)
9918 int fd
= *(int *)stream
;
9920 file_ptr pos
, bytes
;
9923 while (nbytes
> pos
)
9925 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9926 offset
+ pos
, &remote_errno
);
9928 /* Success, but no bytes, means end-of-file. */
9932 errno
= remote_fileio_errno_to_host (remote_errno
);
9933 bfd_set_error (bfd_error_system_call
);
9944 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9946 /* FIXME: We should probably implement remote_hostio_stat. */
9947 sb
->st_size
= INT_MAX
;
9952 remote_filename_p (const char *filename
)
9954 return strncmp (filename
, "remote:", 7) == 0;
9958 remote_bfd_open (const char *remote_file
, const char *target
)
9960 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
9961 remote_bfd_iovec_open
, NULL
,
9962 remote_bfd_iovec_pread
,
9963 remote_bfd_iovec_close
,
9964 remote_bfd_iovec_stat
);
9970 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9972 struct cleanup
*back_to
, *close_cleanup
;
9973 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9976 int bytes_in_buffer
;
9981 error (_("command can only be used with remote target"));
9983 file
= fopen (local_file
, "rb");
9985 perror_with_name (local_file
);
9986 back_to
= make_cleanup_fclose (file
);
9988 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9990 0700, &remote_errno
);
9992 remote_hostio_error (remote_errno
);
9994 /* Send up to this many bytes at once. They won't all fit in the
9995 remote packet limit, so we'll transfer slightly fewer. */
9996 io_size
= get_remote_packet_size ();
9997 buffer
= xmalloc (io_size
);
9998 make_cleanup (xfree
, buffer
);
10000 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10002 bytes_in_buffer
= 0;
10005 while (bytes_in_buffer
|| !saw_eof
)
10009 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10010 io_size
- bytes_in_buffer
,
10015 error (_("Error reading %s."), local_file
);
10018 /* EOF. Unless there is something still in the
10019 buffer from the last iteration, we are done. */
10021 if (bytes_in_buffer
== 0)
10029 bytes
+= bytes_in_buffer
;
10030 bytes_in_buffer
= 0;
10032 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10033 offset
, &remote_errno
);
10036 remote_hostio_error (remote_errno
);
10037 else if (retcode
== 0)
10038 error (_("Remote write of %d bytes returned 0!"), bytes
);
10039 else if (retcode
< bytes
)
10041 /* Short write. Save the rest of the read data for the next
10043 bytes_in_buffer
= bytes
- retcode
;
10044 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10050 discard_cleanups (close_cleanup
);
10051 if (remote_hostio_close (fd
, &remote_errno
))
10052 remote_hostio_error (remote_errno
);
10055 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10056 do_cleanups (back_to
);
10060 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10062 struct cleanup
*back_to
, *close_cleanup
;
10063 int fd
, remote_errno
, bytes
, io_size
;
10069 error (_("command can only be used with remote target"));
10071 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10073 remote_hostio_error (remote_errno
);
10075 file
= fopen (local_file
, "wb");
10077 perror_with_name (local_file
);
10078 back_to
= make_cleanup_fclose (file
);
10080 /* Send up to this many bytes at once. They won't all fit in the
10081 remote packet limit, so we'll transfer slightly fewer. */
10082 io_size
= get_remote_packet_size ();
10083 buffer
= xmalloc (io_size
);
10084 make_cleanup (xfree
, buffer
);
10086 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10091 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10093 /* Success, but no bytes, means end-of-file. */
10096 remote_hostio_error (remote_errno
);
10100 bytes
= fwrite (buffer
, 1, bytes
, file
);
10102 perror_with_name (local_file
);
10105 discard_cleanups (close_cleanup
);
10106 if (remote_hostio_close (fd
, &remote_errno
))
10107 remote_hostio_error (remote_errno
);
10110 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10111 do_cleanups (back_to
);
10115 remote_file_delete (const char *remote_file
, int from_tty
)
10117 int retcode
, remote_errno
;
10120 error (_("command can only be used with remote target"));
10122 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10124 remote_hostio_error (remote_errno
);
10127 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10131 remote_put_command (char *args
, int from_tty
)
10133 struct cleanup
*back_to
;
10137 error_no_arg (_("file to put"));
10139 argv
= gdb_buildargv (args
);
10140 back_to
= make_cleanup_freeargv (argv
);
10141 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10142 error (_("Invalid parameters to remote put"));
10144 remote_file_put (argv
[0], argv
[1], from_tty
);
10146 do_cleanups (back_to
);
10150 remote_get_command (char *args
, int from_tty
)
10152 struct cleanup
*back_to
;
10156 error_no_arg (_("file to get"));
10158 argv
= gdb_buildargv (args
);
10159 back_to
= make_cleanup_freeargv (argv
);
10160 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10161 error (_("Invalid parameters to remote get"));
10163 remote_file_get (argv
[0], argv
[1], from_tty
);
10165 do_cleanups (back_to
);
10169 remote_delete_command (char *args
, int from_tty
)
10171 struct cleanup
*back_to
;
10175 error_no_arg (_("file to delete"));
10177 argv
= gdb_buildargv (args
);
10178 back_to
= make_cleanup_freeargv (argv
);
10179 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10180 error (_("Invalid parameters to remote delete"));
10182 remote_file_delete (argv
[0], from_tty
);
10184 do_cleanups (back_to
);
10188 remote_command (char *args
, int from_tty
)
10190 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10194 remote_can_execute_reverse (void)
10196 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10197 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10204 remote_supports_non_stop (void)
10210 remote_supports_disable_randomization (void)
10212 /* Only supported in extended mode. */
10217 remote_supports_multi_process (void)
10219 struct remote_state
*rs
= get_remote_state ();
10221 /* Only extended-remote handles being attached to multiple
10222 processes, even though plain remote can use the multi-process
10223 thread id extensions, so that GDB knows the target process's
10225 return rs
->extended
&& remote_multi_process_p (rs
);
10229 remote_supports_cond_tracepoints (void)
10231 struct remote_state
*rs
= get_remote_state ();
10233 return rs
->cond_tracepoints
;
10237 remote_supports_cond_breakpoints (void)
10239 struct remote_state
*rs
= get_remote_state ();
10241 return rs
->cond_breakpoints
;
10245 remote_supports_fast_tracepoints (void)
10247 struct remote_state
*rs
= get_remote_state ();
10249 return rs
->fast_tracepoints
;
10253 remote_supports_static_tracepoints (void)
10255 struct remote_state
*rs
= get_remote_state ();
10257 return rs
->static_tracepoints
;
10261 remote_supports_install_in_trace (void)
10263 struct remote_state
*rs
= get_remote_state ();
10265 return rs
->install_in_trace
;
10269 remote_supports_enable_disable_tracepoint (void)
10271 struct remote_state
*rs
= get_remote_state ();
10273 return rs
->enable_disable_tracepoints
;
10277 remote_supports_string_tracing (void)
10279 struct remote_state
*rs
= get_remote_state ();
10281 return rs
->string_tracing
;
10285 remote_can_run_breakpoint_commands (void)
10287 struct remote_state
*rs
= get_remote_state ();
10289 return rs
->breakpoint_commands
;
10293 remote_trace_init (void)
10296 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10297 if (strcmp (target_buf
, "OK") != 0)
10298 error (_("Target does not support this command."));
10301 static void free_actions_list (char **actions_list
);
10302 static void free_actions_list_cleanup_wrapper (void *);
10304 free_actions_list_cleanup_wrapper (void *al
)
10306 free_actions_list (al
);
10310 free_actions_list (char **actions_list
)
10314 if (actions_list
== 0)
10317 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10318 xfree (actions_list
[ndx
]);
10320 xfree (actions_list
);
10323 /* Recursive routine to walk through command list including loops, and
10324 download packets for each command. */
10327 remote_download_command_source (int num
, ULONGEST addr
,
10328 struct command_line
*cmds
)
10330 struct remote_state
*rs
= get_remote_state ();
10331 struct command_line
*cmd
;
10333 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10335 QUIT
; /* Allow user to bail out with ^C. */
10336 strcpy (rs
->buf
, "QTDPsrc:");
10337 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10338 rs
->buf
+ strlen (rs
->buf
),
10339 rs
->buf_size
- strlen (rs
->buf
));
10341 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10342 if (strcmp (target_buf
, "OK"))
10343 warning (_("Target does not support source download."));
10345 if (cmd
->control_type
== while_control
10346 || cmd
->control_type
== while_stepping_control
)
10348 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10350 QUIT
; /* Allow user to bail out with ^C. */
10351 strcpy (rs
->buf
, "QTDPsrc:");
10352 encode_source_string (num
, addr
, "cmd", "end",
10353 rs
->buf
+ strlen (rs
->buf
),
10354 rs
->buf_size
- strlen (rs
->buf
));
10356 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10357 if (strcmp (target_buf
, "OK"))
10358 warning (_("Target does not support source download."));
10364 remote_download_tracepoint (struct bp_location
*loc
)
10366 #define BUF_SIZE 2048
10370 char buf
[BUF_SIZE
];
10371 char **tdp_actions
;
10372 char **stepping_actions
;
10374 struct cleanup
*old_chain
= NULL
;
10375 struct agent_expr
*aexpr
;
10376 struct cleanup
*aexpr_chain
= NULL
;
10378 struct breakpoint
*b
= loc
->owner
;
10379 struct tracepoint
*t
= (struct tracepoint
*) b
;
10381 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
10382 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10384 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10387 tpaddr
= loc
->address
;
10388 sprintf_vma (addrbuf
, tpaddr
);
10389 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10390 addrbuf
, /* address */
10391 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10392 t
->step_count
, t
->pass_count
);
10393 /* Fast tracepoints are mostly handled by the target, but we can
10394 tell the target how big of an instruction block should be moved
10396 if (b
->type
== bp_fast_tracepoint
)
10398 /* Only test for support at download time; we may not know
10399 target capabilities at definition time. */
10400 if (remote_supports_fast_tracepoints ())
10404 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10405 tpaddr
, &isize
, NULL
))
10406 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10409 /* If it passed validation at definition but fails now,
10410 something is very wrong. */
10411 internal_error (__FILE__
, __LINE__
,
10412 _("Fast tracepoint not "
10413 "valid during download"));
10416 /* Fast tracepoints are functionally identical to regular
10417 tracepoints, so don't take lack of support as a reason to
10418 give up on the trace run. */
10419 warning (_("Target does not support fast tracepoints, "
10420 "downloading %d as regular tracepoint"), b
->number
);
10422 else if (b
->type
== bp_static_tracepoint
)
10424 /* Only test for support at download time; we may not know
10425 target capabilities at definition time. */
10426 if (remote_supports_static_tracepoints ())
10428 struct static_tracepoint_marker marker
;
10430 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10431 strcat (buf
, ":S");
10433 error (_("Static tracepoint not valid during download"));
10436 /* Fast tracepoints are functionally identical to regular
10437 tracepoints, so don't take lack of support as a reason
10438 to give up on the trace run. */
10439 error (_("Target does not support static tracepoints"));
10441 /* If the tracepoint has a conditional, make it into an agent
10442 expression and append to the definition. */
10445 /* Only test support at download time, we may not know target
10446 capabilities at definition time. */
10447 if (remote_supports_cond_tracepoints ())
10449 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10450 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10451 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10453 pkt
= buf
+ strlen (buf
);
10454 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10455 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10457 do_cleanups (aexpr_chain
);
10460 warning (_("Target does not support conditional tracepoints, "
10461 "ignoring tp %d cond"), b
->number
);
10464 if (b
->commands
|| *default_collect
)
10467 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10468 if (strcmp (target_buf
, "OK"))
10469 error (_("Target does not support tracepoints."));
10471 /* do_single_steps (t); */
10474 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10476 QUIT
; /* Allow user to bail out with ^C. */
10477 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10478 b
->number
, addrbuf
, /* address */
10480 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10483 remote_get_noisy_reply (&target_buf
,
10485 if (strcmp (target_buf
, "OK"))
10486 error (_("Error on target while setting tracepoints."));
10489 if (stepping_actions
)
10491 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10493 QUIT
; /* Allow user to bail out with ^C. */
10494 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10495 b
->number
, addrbuf
, /* address */
10496 ((ndx
== 0) ? "S" : ""),
10497 stepping_actions
[ndx
],
10498 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10500 remote_get_noisy_reply (&target_buf
,
10502 if (strcmp (target_buf
, "OK"))
10503 error (_("Error on target while setting tracepoints."));
10507 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10510 if (b
->addr_string
)
10512 strcpy (buf
, "QTDPsrc:");
10513 encode_source_string (b
->number
, loc
->address
,
10514 "at", b
->addr_string
, buf
+ strlen (buf
),
10515 2048 - strlen (buf
));
10518 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10519 if (strcmp (target_buf
, "OK"))
10520 warning (_("Target does not support source download."));
10522 if (b
->cond_string
)
10524 strcpy (buf
, "QTDPsrc:");
10525 encode_source_string (b
->number
, loc
->address
,
10526 "cond", b
->cond_string
, buf
+ strlen (buf
),
10527 2048 - strlen (buf
));
10529 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10530 if (strcmp (target_buf
, "OK"))
10531 warning (_("Target does not support source download."));
10533 remote_download_command_source (b
->number
, loc
->address
,
10534 breakpoint_commands (b
));
10537 do_cleanups (old_chain
);
10541 remote_can_download_tracepoint (void)
10543 struct remote_state
*rs
= get_remote_state ();
10544 struct trace_status
*ts
;
10547 /* Don't try to install tracepoints until we've relocated our
10548 symbols, and fetched and merged the target's tracepoint list with
10550 if (rs
->starting_up
)
10553 ts
= current_trace_status ();
10554 status
= remote_get_trace_status (ts
);
10556 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10559 /* If we are in a tracing experiment, but remote stub doesn't support
10560 installing tracepoint in trace, we have to return. */
10561 if (!remote_supports_install_in_trace ())
10569 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10571 struct remote_state
*rs
= get_remote_state ();
10574 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10575 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10577 p
= rs
->buf
+ strlen (rs
->buf
);
10578 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10579 error (_("Trace state variable name too long for tsv definition packet"));
10580 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10583 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10584 if (*target_buf
== '\0')
10585 error (_("Target does not support this command."));
10586 if (strcmp (target_buf
, "OK") != 0)
10587 error (_("Error on target while downloading trace state variable."));
10591 remote_enable_tracepoint (struct bp_location
*location
)
10593 struct remote_state
*rs
= get_remote_state ();
10596 sprintf_vma (addr_buf
, location
->address
);
10597 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10598 location
->owner
->number
, addr_buf
);
10600 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10601 if (*rs
->buf
== '\0')
10602 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10603 if (strcmp (rs
->buf
, "OK") != 0)
10604 error (_("Error on target while enabling tracepoint."));
10608 remote_disable_tracepoint (struct bp_location
*location
)
10610 struct remote_state
*rs
= get_remote_state ();
10613 sprintf_vma (addr_buf
, location
->address
);
10614 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10615 location
->owner
->number
, addr_buf
);
10617 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10618 if (*rs
->buf
== '\0')
10619 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10620 if (strcmp (rs
->buf
, "OK") != 0)
10621 error (_("Error on target while disabling tracepoint."));
10625 remote_trace_set_readonly_regions (void)
10629 bfd_size_type size
;
10635 return; /* No information to give. */
10637 strcpy (target_buf
, "QTro");
10638 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10640 char tmp1
[40], tmp2
[40];
10643 if ((s
->flags
& SEC_LOAD
) == 0 ||
10644 /* (s->flags & SEC_CODE) == 0 || */
10645 (s
->flags
& SEC_READONLY
) == 0)
10649 vma
= bfd_get_section_vma (abfd
, s
);
10650 size
= bfd_get_section_size (s
);
10651 sprintf_vma (tmp1
, vma
);
10652 sprintf_vma (tmp2
, vma
+ size
);
10653 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10654 if (offset
+ sec_length
+ 1 > target_buf_size
)
10656 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10659 Too many sections for read-only sections definition packet."));
10662 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10664 offset
+= sec_length
;
10668 putpkt (target_buf
);
10669 getpkt (&target_buf
, &target_buf_size
, 0);
10674 remote_trace_start (void)
10676 putpkt ("QTStart");
10677 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10678 if (*target_buf
== '\0')
10679 error (_("Target does not support this command."));
10680 if (strcmp (target_buf
, "OK") != 0)
10681 error (_("Bogus reply from target: %s"), target_buf
);
10685 remote_get_trace_status (struct trace_status
*ts
)
10687 /* Initialize it just to avoid a GCC false warning. */
10689 /* FIXME we need to get register block size some other way. */
10690 extern int trace_regblock_size
;
10691 volatile struct gdb_exception ex
;
10693 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10695 putpkt ("qTStatus");
10697 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10699 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10703 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10705 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10708 throw_exception (ex
);
10711 /* If the remote target doesn't do tracing, flag it. */
10715 /* We're working with a live target. */
10716 ts
->filename
= NULL
;
10719 error (_("Bogus trace status reply from target: %s"), target_buf
);
10721 /* Function 'parse_trace_status' sets default value of each field of
10722 'ts' at first, so we don't have to do it here. */
10723 parse_trace_status (p
, ts
);
10725 return ts
->running
;
10729 remote_get_tracepoint_status (struct breakpoint
*bp
,
10730 struct uploaded_tp
*utp
)
10732 struct remote_state
*rs
= get_remote_state ();
10734 struct bp_location
*loc
;
10735 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10736 size_t size
= get_remote_packet_size ();
10740 tp
->base
.hit_count
= 0;
10741 tp
->traceframe_usage
= 0;
10742 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10744 /* If the tracepoint was never downloaded, don't go asking for
10746 if (tp
->number_on_target
== 0)
10748 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10749 phex_nz (loc
->address
, 0));
10751 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10752 if (reply
&& *reply
)
10755 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10761 utp
->hit_count
= 0;
10762 utp
->traceframe_usage
= 0;
10763 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10764 phex_nz (utp
->addr
, 0));
10766 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10767 if (reply
&& *reply
)
10770 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10776 remote_trace_stop (void)
10779 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10780 if (*target_buf
== '\0')
10781 error (_("Target does not support this command."));
10782 if (strcmp (target_buf
, "OK") != 0)
10783 error (_("Bogus reply from target: %s"), target_buf
);
10787 remote_trace_find (enum trace_find_type type
, int num
,
10788 ULONGEST addr1
, ULONGEST addr2
,
10791 struct remote_state
*rs
= get_remote_state ();
10792 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10794 int target_frameno
= -1, target_tracept
= -1;
10796 /* Lookups other than by absolute frame number depend on the current
10797 trace selected, so make sure it is correct on the remote end
10799 if (type
!= tfind_number
)
10800 set_remote_traceframe ();
10803 strcpy (p
, "QTFrame:");
10804 p
= strchr (p
, '\0');
10808 xsnprintf (p
, endbuf
- p
, "%x", num
);
10811 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10814 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10817 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10818 phex_nz (addr2
, 0));
10820 case tfind_outside
:
10821 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10822 phex_nz (addr2
, 0));
10825 error (_("Unknown trace find type %d"), type
);
10829 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10830 if (*reply
== '\0')
10831 error (_("Target does not support this command."));
10833 while (reply
&& *reply
)
10838 target_frameno
= (int) strtol (p
, &reply
, 16);
10840 error (_("Unable to parse trace frame number"));
10841 /* Don't update our remote traceframe number cache on failure
10842 to select a remote traceframe. */
10843 if (target_frameno
== -1)
10848 target_tracept
= (int) strtol (p
, &reply
, 16);
10850 error (_("Unable to parse tracepoint number"));
10852 case 'O': /* "OK"? */
10853 if (reply
[1] == 'K' && reply
[2] == '\0')
10856 error (_("Bogus reply from target: %s"), reply
);
10859 error (_("Bogus reply from target: %s"), reply
);
10862 *tpp
= target_tracept
;
10864 remote_traceframe_number
= target_frameno
;
10865 return target_frameno
;
10869 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10871 struct remote_state
*rs
= get_remote_state ();
10875 set_remote_traceframe ();
10877 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10879 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10880 if (reply
&& *reply
)
10884 unpack_varlen_hex (reply
+ 1, &uval
);
10885 *val
= (LONGEST
) uval
;
10893 remote_save_trace_data (const char *filename
)
10895 struct remote_state
*rs
= get_remote_state ();
10899 strcpy (p
, "QTSave:");
10901 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10902 error (_("Remote file name too long for trace save packet"));
10903 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10906 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10907 if (*reply
== '\0')
10908 error (_("Target does not support this command."));
10909 if (strcmp (reply
, "OK") != 0)
10910 error (_("Bogus reply from target: %s"), reply
);
10914 /* This is basically a memory transfer, but needs to be its own packet
10915 because we don't know how the target actually organizes its trace
10916 memory, plus we want to be able to ask for as much as possible, but
10917 not be unhappy if we don't get as much as we ask for. */
10920 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10922 struct remote_state
*rs
= get_remote_state ();
10928 strcpy (p
, "qTBuffer:");
10930 p
+= hexnumstr (p
, offset
);
10932 p
+= hexnumstr (p
, len
);
10936 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10937 if (reply
&& *reply
)
10939 /* 'l' by itself means we're at the end of the buffer and
10940 there is nothing more to get. */
10944 /* Convert the reply into binary. Limit the number of bytes to
10945 convert according to our passed-in buffer size, rather than
10946 what was returned in the packet; if the target is
10947 unexpectedly generous and gives us a bigger reply than we
10948 asked for, we don't want to crash. */
10949 rslt
= hex2bin (target_buf
, buf
, len
);
10953 /* Something went wrong, flag as an error. */
10958 remote_set_disconnected_tracing (int val
)
10960 struct remote_state
*rs
= get_remote_state ();
10962 if (rs
->disconnected_tracing
)
10966 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
10968 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10969 if (*reply
== '\0')
10970 error (_("Target does not support this command."));
10971 if (strcmp (reply
, "OK") != 0)
10972 error (_("Bogus reply from target: %s"), reply
);
10975 warning (_("Target does not support disconnected tracing."));
10979 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10981 struct thread_info
*info
= find_thread_ptid (ptid
);
10983 if (info
&& info
->private)
10984 return info
->private->core
;
10989 remote_set_circular_trace_buffer (int val
)
10991 struct remote_state
*rs
= get_remote_state ();
10994 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
10996 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10997 if (*reply
== '\0')
10998 error (_("Target does not support this command."));
10999 if (strcmp (reply
, "OK") != 0)
11000 error (_("Bogus reply from target: %s"), reply
);
11003 static struct traceframe_info
*
11004 remote_traceframe_info (void)
11008 text
= target_read_stralloc (¤t_target
,
11009 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11012 struct traceframe_info
*info
;
11013 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11015 info
= parse_traceframe_info (text
);
11016 do_cleanups (back_to
);
11023 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11024 instruction on which a fast tracepoint may be placed. Returns -1
11025 if the packet is not supported, and 0 if the minimum instruction
11026 length is unknown. */
11029 remote_get_min_fast_tracepoint_insn_len (void)
11031 struct remote_state
*rs
= get_remote_state ();
11034 /* If we're not debugging a process yet, the IPA can't be
11036 if (!target_has_execution
)
11039 /* Make sure the remote is pointing at the right process. */
11040 set_general_process ();
11042 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11044 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11045 if (*reply
== '\0')
11049 ULONGEST min_insn_len
;
11051 unpack_varlen_hex (reply
, &min_insn_len
);
11053 return (int) min_insn_len
;
11058 remote_set_trace_buffer_size (LONGEST val
)
11060 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11063 struct remote_state
*rs
= get_remote_state ();
11064 char *buf
= rs
->buf
;
11065 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11066 enum packet_result result
;
11068 gdb_assert (val
>= 0 || val
== -1);
11069 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11070 /* Send -1 as literal "-1" to avoid host size dependency. */
11074 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11077 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11080 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11081 result
= packet_ok (rs
->buf
,
11082 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11084 if (result
!= PACKET_OK
)
11085 warning (_("Bogus reply from target: %s"), rs
->buf
);
11090 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
11092 struct remote_state
*rs
= get_remote_state ();
11094 char *buf
= rs
->buf
;
11095 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11098 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11101 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11102 nbytes
= bin2hex (user
, buf
, 0);
11108 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11109 nbytes
= bin2hex (notes
, buf
, 0);
11115 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11116 nbytes
= bin2hex (stop_notes
, buf
, 0);
11120 /* Ensure the buffer is terminated. */
11124 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11125 if (*reply
== '\0')
11128 if (strcmp (reply
, "OK") != 0)
11129 error (_("Bogus reply from target: %s"), reply
);
11135 remote_use_agent (int use
)
11137 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11139 struct remote_state
*rs
= get_remote_state ();
11141 /* If the stub supports QAgent. */
11142 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11144 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11146 if (strcmp (rs
->buf
, "OK") == 0)
11157 remote_can_use_agent (void)
11159 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11162 struct btrace_target_info
11164 /* The ptid of the traced thread. */
11168 /* Check whether the target supports branch tracing. */
11171 remote_supports_btrace (void)
11173 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11175 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11177 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11183 /* Enable branch tracing. */
11185 static struct btrace_target_info
*
11186 remote_enable_btrace (ptid_t ptid
)
11188 struct btrace_target_info
*tinfo
= NULL
;
11189 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11190 struct remote_state
*rs
= get_remote_state ();
11191 char *buf
= rs
->buf
;
11192 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11194 if (packet
->support
!= PACKET_ENABLE
)
11195 error (_("Target does not support branch tracing."));
11197 set_general_thread (ptid
);
11199 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11201 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11203 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11205 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11206 error (_("Could not enable branch tracing for %s: %s"),
11207 target_pid_to_str (ptid
), rs
->buf
+ 2);
11209 error (_("Could not enable branch tracing for %s."),
11210 target_pid_to_str (ptid
));
11213 tinfo
= xzalloc (sizeof (*tinfo
));
11214 tinfo
->ptid
= ptid
;
11219 /* Disable branch tracing. */
11222 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11224 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11225 struct remote_state
*rs
= get_remote_state ();
11226 char *buf
= rs
->buf
;
11227 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11229 if (packet
->support
!= PACKET_ENABLE
)
11230 error (_("Target does not support branch tracing."));
11232 set_general_thread (tinfo
->ptid
);
11234 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11236 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11238 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11240 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11241 error (_("Could not disable branch tracing for %s: %s"),
11242 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11244 error (_("Could not disable branch tracing for %s."),
11245 target_pid_to_str (tinfo
->ptid
));
11251 /* Teardown branch tracing. */
11254 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11256 /* We must not talk to the target during teardown. */
11260 /* Read the branch trace. */
11262 static VEC (btrace_block_s
) *
11263 remote_read_btrace (struct btrace_target_info
*tinfo
,
11264 enum btrace_read_type type
)
11266 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11267 struct remote_state
*rs
= get_remote_state ();
11268 VEC (btrace_block_s
) *btrace
= NULL
;
11272 if (packet
->support
!= PACKET_ENABLE
)
11273 error (_("Target does not support branch tracing."));
11275 #if !defined(HAVE_LIBEXPAT)
11276 error (_("Cannot process branch tracing result. XML parsing not supported."));
11281 case btrace_read_all
:
11284 case btrace_read_new
:
11288 internal_error (__FILE__
, __LINE__
,
11289 _("Bad branch tracing read type: %u."),
11290 (unsigned int) type
);
11293 xml
= target_read_stralloc (¤t_target
,
11294 TARGET_OBJECT_BTRACE
, annex
);
11297 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11299 btrace
= parse_xml_btrace (xml
);
11300 do_cleanups (cleanup
);
11307 init_remote_ops (void)
11309 remote_ops
.to_shortname
= "remote";
11310 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11311 remote_ops
.to_doc
=
11312 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11313 Specify the serial device it is connected to\n\
11314 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11315 remote_ops
.to_open
= remote_open
;
11316 remote_ops
.to_close
= remote_close
;
11317 remote_ops
.to_detach
= remote_detach
;
11318 remote_ops
.to_disconnect
= remote_disconnect
;
11319 remote_ops
.to_resume
= remote_resume
;
11320 remote_ops
.to_wait
= remote_wait
;
11321 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11322 remote_ops
.to_store_registers
= remote_store_registers
;
11323 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11324 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11325 remote_ops
.to_files_info
= remote_files_info
;
11326 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11327 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11328 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11329 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11330 remote_ops
.to_watchpoint_addr_within_range
=
11331 remote_watchpoint_addr_within_range
;
11332 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11333 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11334 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11335 remote_ops
.to_region_ok_for_hw_watchpoint
11336 = remote_region_ok_for_hw_watchpoint
;
11337 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11338 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11339 remote_ops
.to_kill
= remote_kill
;
11340 remote_ops
.to_load
= generic_load
;
11341 remote_ops
.to_mourn_inferior
= remote_mourn
;
11342 remote_ops
.to_pass_signals
= remote_pass_signals
;
11343 remote_ops
.to_program_signals
= remote_program_signals
;
11344 remote_ops
.to_thread_alive
= remote_thread_alive
;
11345 remote_ops
.to_find_new_threads
= remote_threads_info
;
11346 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11347 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11348 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11349 remote_ops
.to_stop
= remote_stop
;
11350 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11351 remote_ops
.to_rcmd
= remote_rcmd
;
11352 remote_ops
.to_log_command
= serial_log_command
;
11353 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11354 remote_ops
.to_stratum
= process_stratum
;
11355 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11356 remote_ops
.to_has_memory
= default_child_has_memory
;
11357 remote_ops
.to_has_stack
= default_child_has_stack
;
11358 remote_ops
.to_has_registers
= default_child_has_registers
;
11359 remote_ops
.to_has_execution
= default_child_has_execution
;
11360 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11361 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11362 remote_ops
.to_magic
= OPS_MAGIC
;
11363 remote_ops
.to_memory_map
= remote_memory_map
;
11364 remote_ops
.to_flash_erase
= remote_flash_erase
;
11365 remote_ops
.to_flash_done
= remote_flash_done
;
11366 remote_ops
.to_read_description
= remote_read_description
;
11367 remote_ops
.to_search_memory
= remote_search_memory
;
11368 remote_ops
.to_can_async_p
= remote_can_async_p
;
11369 remote_ops
.to_is_async_p
= remote_is_async_p
;
11370 remote_ops
.to_async
= remote_async
;
11371 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11372 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11373 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11374 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11375 remote_ops
.to_supports_disable_randomization
11376 = remote_supports_disable_randomization
;
11377 remote_ops
.to_fileio_open
= remote_hostio_open
;
11378 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11379 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11380 remote_ops
.to_fileio_close
= remote_hostio_close
;
11381 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11382 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11383 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11384 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11385 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11386 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11387 remote_ops
.to_trace_init
= remote_trace_init
;
11388 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11389 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11390 remote_ops
.to_download_trace_state_variable
11391 = remote_download_trace_state_variable
;
11392 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11393 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11394 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11395 remote_ops
.to_trace_start
= remote_trace_start
;
11396 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11397 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11398 remote_ops
.to_trace_stop
= remote_trace_stop
;
11399 remote_ops
.to_trace_find
= remote_trace_find
;
11400 remote_ops
.to_get_trace_state_variable_value
11401 = remote_get_trace_state_variable_value
;
11402 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11403 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11404 remote_ops
.to_upload_trace_state_variables
11405 = remote_upload_trace_state_variables
;
11406 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11407 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11408 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11409 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11410 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11411 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11412 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11413 remote_ops
.to_verify_memory
= remote_verify_memory
;
11414 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11415 remote_ops
.to_set_permissions
= remote_set_permissions
;
11416 remote_ops
.to_static_tracepoint_marker_at
11417 = remote_static_tracepoint_marker_at
;
11418 remote_ops
.to_static_tracepoint_markers_by_strid
11419 = remote_static_tracepoint_markers_by_strid
;
11420 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11421 remote_ops
.to_use_agent
= remote_use_agent
;
11422 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11423 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11424 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11425 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11426 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11427 remote_ops
.to_read_btrace
= remote_read_btrace
;
11430 /* Set up the extended remote vector by making a copy of the standard
11431 remote vector and adding to it. */
11434 init_extended_remote_ops (void)
11436 extended_remote_ops
= remote_ops
;
11438 extended_remote_ops
.to_shortname
= "extended-remote";
11439 extended_remote_ops
.to_longname
=
11440 "Extended remote serial target in gdb-specific protocol";
11441 extended_remote_ops
.to_doc
=
11442 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11443 Specify the serial device it is connected to (e.g. /dev/ttya).";
11444 extended_remote_ops
.to_open
= extended_remote_open
;
11445 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11446 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11447 extended_remote_ops
.to_detach
= extended_remote_detach
;
11448 extended_remote_ops
.to_attach
= extended_remote_attach
;
11449 extended_remote_ops
.to_kill
= extended_remote_kill
;
11450 extended_remote_ops
.to_supports_disable_randomization
11451 = extended_remote_supports_disable_randomization
;
11455 remote_can_async_p (void)
11457 if (!target_async_permitted
)
11458 /* We only enable async when the user specifically asks for it. */
11461 /* We're async whenever the serial device is. */
11462 return serial_can_async_p (remote_desc
);
11466 remote_is_async_p (void)
11468 if (!target_async_permitted
)
11469 /* We only enable async when the user specifically asks for it. */
11472 /* We're async whenever the serial device is. */
11473 return serial_is_async_p (remote_desc
);
11476 /* Pass the SERIAL event on and up to the client. One day this code
11477 will be able to delay notifying the client of an event until the
11478 point where an entire packet has been received. */
11480 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11482 static void *async_client_context
;
11483 static serial_event_ftype remote_async_serial_handler
;
11486 remote_async_serial_handler (struct serial
*scb
, void *context
)
11488 /* Don't propogate error information up to the client. Instead let
11489 the client find out about the error by querying the target. */
11490 async_client_callback (INF_REG_EVENT
, async_client_context
);
11494 remote_async_inferior_event_handler (gdb_client_data data
)
11496 inferior_event_handler (INF_REG_EVENT
, NULL
);
11500 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11501 void *context
), void *context
)
11503 if (callback
!= NULL
)
11505 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
11506 async_client_callback
= callback
;
11507 async_client_context
= context
;
11510 serial_async (remote_desc
, NULL
, NULL
);
11514 set_remote_cmd (char *args
, int from_tty
)
11516 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11520 show_remote_cmd (char *args
, int from_tty
)
11522 /* We can't just use cmd_show_list here, because we want to skip
11523 the redundant "show remote Z-packet" and the legacy aliases. */
11524 struct cleanup
*showlist_chain
;
11525 struct cmd_list_element
*list
= remote_show_cmdlist
;
11526 struct ui_out
*uiout
= current_uiout
;
11528 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11529 for (; list
!= NULL
; list
= list
->next
)
11530 if (strcmp (list
->name
, "Z-packet") == 0)
11532 else if (list
->type
== not_set_cmd
)
11533 /* Alias commands are exactly like the original, except they
11534 don't have the normal type. */
11538 struct cleanup
*option_chain
11539 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11541 ui_out_field_string (uiout
, "name", list
->name
);
11542 ui_out_text (uiout
, ": ");
11543 if (list
->type
== show_cmd
)
11544 do_show_command ((char *) NULL
, from_tty
, list
);
11546 cmd_func (list
, NULL
, from_tty
);
11547 /* Close the tuple. */
11548 do_cleanups (option_chain
);
11551 /* Close the tuple. */
11552 do_cleanups (showlist_chain
);
11556 /* Function to be called whenever a new objfile (shlib) is detected. */
11558 remote_new_objfile (struct objfile
*objfile
)
11560 if (remote_desc
!= 0) /* Have a remote connection. */
11561 remote_check_symbols (objfile
);
11564 /* Pull all the tracepoints defined on the target and create local
11565 data structures representing them. We don't want to create real
11566 tracepoints yet, we don't want to mess up the user's existing
11570 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11572 struct remote_state
*rs
= get_remote_state ();
11575 /* Ask for a first packet of tracepoint definition. */
11577 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11579 while (*p
&& *p
!= 'l')
11581 parse_tracepoint_definition (p
, utpp
);
11582 /* Ask for another packet of tracepoint definition. */
11584 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11591 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11593 struct remote_state
*rs
= get_remote_state ();
11596 /* Ask for a first packet of variable definition. */
11598 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11600 while (*p
&& *p
!= 'l')
11602 parse_tsv_definition (p
, utsvp
);
11603 /* Ask for another packet of variable definition. */
11605 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11612 _initialize_remote (void)
11614 struct remote_state
*rs
;
11615 struct cmd_list_element
*cmd
;
11616 const char *cmd_name
;
11618 /* architecture specific data */
11619 remote_gdbarch_data_handle
=
11620 gdbarch_data_register_post_init (init_remote_state
);
11621 remote_g_packet_data_handle
=
11622 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11624 /* Initialize the per-target state. At the moment there is only one
11625 of these, not one per target. Only one target is active at a
11626 time. The default buffer size is unimportant; it will be expanded
11627 whenever a larger buffer is needed. */
11628 rs
= get_remote_state_raw ();
11629 rs
->buf_size
= 400;
11630 rs
->buf
= xmalloc (rs
->buf_size
);
11632 init_remote_ops ();
11633 add_target (&remote_ops
);
11635 init_extended_remote_ops ();
11636 add_target (&extended_remote_ops
);
11638 /* Hook into new objfile notification. */
11639 observer_attach_new_objfile (remote_new_objfile
);
11640 /* We're no longer interested in notification events of an inferior
11642 observer_attach_inferior_exit (discard_pending_stop_replies
);
11644 /* Set up signal handlers. */
11645 sigint_remote_token
=
11646 create_async_signal_handler (async_remote_interrupt
, NULL
);
11647 sigint_remote_twice_token
=
11648 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11651 init_remote_threadtests ();
11654 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11655 /* set/show remote ... */
11657 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11658 Remote protocol specific variables\n\
11659 Configure various remote-protocol specific variables such as\n\
11660 the packets being used"),
11661 &remote_set_cmdlist
, "set remote ",
11662 0 /* allow-unknown */, &setlist
);
11663 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11664 Remote protocol specific variables\n\
11665 Configure various remote-protocol specific variables such as\n\
11666 the packets being used"),
11667 &remote_show_cmdlist
, "show remote ",
11668 0 /* allow-unknown */, &showlist
);
11670 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11671 Compare section data on target to the exec file.\n\
11672 Argument is a single section name (default: all loaded sections)."),
11675 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11676 Send an arbitrary packet to a remote target.\n\
11677 maintenance packet TEXT\n\
11678 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11679 this command sends the string TEXT to the inferior, and displays the\n\
11680 response packet. GDB supplies the initial `$' character, and the\n\
11681 terminating `#' character and checksum."),
11684 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11685 Set whether to send break if interrupted."), _("\
11686 Show whether to send break if interrupted."), _("\
11687 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11688 set_remotebreak
, show_remotebreak
,
11689 &setlist
, &showlist
);
11690 cmd_name
= "remotebreak";
11691 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11692 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11693 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11694 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11695 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11697 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11698 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11700 Set interrupt sequence to remote target."), _("\
11701 Show interrupt sequence to remote target."), _("\
11702 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11703 NULL
, show_interrupt_sequence
,
11704 &remote_set_cmdlist
,
11705 &remote_show_cmdlist
);
11707 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11708 &interrupt_on_connect
, _("\
11709 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11710 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11711 If set, interrupt sequence is sent to remote target."),
11713 &remote_set_cmdlist
, &remote_show_cmdlist
);
11715 /* Install commands for configuring memory read/write packets. */
11717 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11718 Set the maximum number of bytes per memory write packet (deprecated)."),
11720 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11721 Show the maximum number of bytes per memory write packet (deprecated)."),
11723 add_cmd ("memory-write-packet-size", no_class
,
11724 set_memory_write_packet_size
, _("\
11725 Set the maximum number of bytes per memory-write packet.\n\
11726 Specify the number of bytes in a packet or 0 (zero) for the\n\
11727 default packet size. The actual limit is further reduced\n\
11728 dependent on the target. Specify ``fixed'' to disable the\n\
11729 further restriction and ``limit'' to enable that restriction."),
11730 &remote_set_cmdlist
);
11731 add_cmd ("memory-read-packet-size", no_class
,
11732 set_memory_read_packet_size
, _("\
11733 Set the maximum number of bytes per memory-read packet.\n\
11734 Specify the number of bytes in a packet or 0 (zero) for the\n\
11735 default packet size. The actual limit is further reduced\n\
11736 dependent on the target. Specify ``fixed'' to disable the\n\
11737 further restriction and ``limit'' to enable that restriction."),
11738 &remote_set_cmdlist
);
11739 add_cmd ("memory-write-packet-size", no_class
,
11740 show_memory_write_packet_size
,
11741 _("Show the maximum number of bytes per memory-write packet."),
11742 &remote_show_cmdlist
);
11743 add_cmd ("memory-read-packet-size", no_class
,
11744 show_memory_read_packet_size
,
11745 _("Show the maximum number of bytes per memory-read packet."),
11746 &remote_show_cmdlist
);
11748 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11749 &remote_hw_watchpoint_limit
, _("\
11750 Set the maximum number of target hardware watchpoints."), _("\
11751 Show the maximum number of target hardware watchpoints."), _("\
11752 Specify a negative limit for unlimited."),
11753 NULL
, NULL
, /* FIXME: i18n: The maximum
11754 number of target hardware
11755 watchpoints is %s. */
11756 &remote_set_cmdlist
, &remote_show_cmdlist
);
11757 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11758 &remote_hw_watchpoint_length_limit
, _("\
11759 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11760 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11761 Specify a negative limit for unlimited."),
11762 NULL
, NULL
, /* FIXME: i18n: The maximum
11763 length (in bytes) of a target
11764 hardware watchpoint is %s. */
11765 &remote_set_cmdlist
, &remote_show_cmdlist
);
11766 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11767 &remote_hw_breakpoint_limit
, _("\
11768 Set the maximum number of target hardware breakpoints."), _("\
11769 Show the maximum number of target hardware breakpoints."), _("\
11770 Specify a negative limit for unlimited."),
11771 NULL
, NULL
, /* FIXME: i18n: The maximum
11772 number of target hardware
11773 breakpoints is %s. */
11774 &remote_set_cmdlist
, &remote_show_cmdlist
);
11776 add_setshow_uinteger_cmd ("remoteaddresssize", class_obscure
,
11777 &remote_address_size
, _("\
11778 Set the maximum size of the address (in bits) in a memory packet."), _("\
11779 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11781 NULL
, /* FIXME: i18n: */
11782 &setlist
, &showlist
);
11784 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11785 "X", "binary-download", 1);
11787 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11788 "vCont", "verbose-resume", 0);
11790 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11791 "QPassSignals", "pass-signals", 0);
11793 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11794 "QProgramSignals", "program-signals", 0);
11796 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11797 "qSymbol", "symbol-lookup", 0);
11799 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11800 "P", "set-register", 1);
11802 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11803 "p", "fetch-register", 1);
11805 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11806 "Z0", "software-breakpoint", 0);
11808 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11809 "Z1", "hardware-breakpoint", 0);
11811 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11812 "Z2", "write-watchpoint", 0);
11814 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11815 "Z3", "read-watchpoint", 0);
11817 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11818 "Z4", "access-watchpoint", 0);
11820 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11821 "qXfer:auxv:read", "read-aux-vector", 0);
11823 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11824 "qXfer:features:read", "target-features", 0);
11826 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11827 "qXfer:libraries:read", "library-info", 0);
11829 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11830 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11832 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11833 "qXfer:memory-map:read", "memory-map", 0);
11835 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11836 "qXfer:spu:read", "read-spu-object", 0);
11838 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11839 "qXfer:spu:write", "write-spu-object", 0);
11841 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11842 "qXfer:osdata:read", "osdata", 0);
11844 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11845 "qXfer:threads:read", "threads", 0);
11847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11848 "qXfer:siginfo:read", "read-siginfo-object", 0);
11850 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11851 "qXfer:siginfo:write", "write-siginfo-object", 0);
11853 add_packet_config_cmd
11854 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11855 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11857 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
11858 "qXfer:uib:read", "unwind-info-block", 0);
11860 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11861 "qGetTLSAddr", "get-thread-local-storage-address",
11864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11865 "qGetTIBAddr", "get-thread-information-block-address",
11868 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11869 "bc", "reverse-continue", 0);
11871 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11872 "bs", "reverse-step", 0);
11874 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11875 "qSupported", "supported-packets", 0);
11877 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11878 "qSearch:memory", "search-memory", 0);
11880 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11881 "vFile:open", "hostio-open", 0);
11883 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11884 "vFile:pread", "hostio-pread", 0);
11886 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11887 "vFile:pwrite", "hostio-pwrite", 0);
11889 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11890 "vFile:close", "hostio-close", 0);
11892 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11893 "vFile:unlink", "hostio-unlink", 0);
11895 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11896 "vFile:readlink", "hostio-readlink", 0);
11898 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11899 "vAttach", "attach", 0);
11901 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11904 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11905 "QStartNoAckMode", "noack", 0);
11907 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11908 "vKill", "kill", 0);
11910 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11911 "qAttached", "query-attached", 0);
11913 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11914 "ConditionalTracepoints",
11915 "conditional-tracepoints", 0);
11917 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
11918 "ConditionalBreakpoints",
11919 "conditional-breakpoints", 0);
11921 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
11922 "BreakpointCommands",
11923 "breakpoint-commands", 0);
11925 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11926 "FastTracepoints", "fast-tracepoints", 0);
11928 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11929 "TracepointSource", "TracepointSource", 0);
11931 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11932 "QAllow", "allow", 0);
11934 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11935 "StaticTracepoints", "static-tracepoints", 0);
11937 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11938 "InstallInTrace", "install-in-trace", 0);
11940 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11941 "qXfer:statictrace:read", "read-sdata-object", 0);
11943 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11944 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11946 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11947 "QDisableRandomization", "disable-randomization", 0);
11949 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
11950 "QAgent", "agent", 0);
11952 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
11953 "QTBuffer:size", "trace-buffer-size", 0);
11955 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
11956 "Qbtrace:off", "disable-btrace", 0);
11958 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
11959 "Qbtrace:bts", "enable-btrace", 0);
11961 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
11962 "qXfer:btrace", "read-btrace", 0);
11964 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11965 Z sub-packet has its own set and show commands, but users may
11966 have sets to this variable in their .gdbinit files (or in their
11968 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11969 &remote_Z_packet_detect
, _("\
11970 Set use of remote protocol `Z' packets"), _("\
11971 Show use of remote protocol `Z' packets "), _("\
11972 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11974 set_remote_protocol_Z_packet_cmd
,
11975 show_remote_protocol_Z_packet_cmd
,
11976 /* FIXME: i18n: Use of remote protocol
11977 `Z' packets is %s. */
11978 &remote_set_cmdlist
, &remote_show_cmdlist
);
11980 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11981 Manipulate files on the remote system\n\
11982 Transfer files to and from the remote target system."),
11983 &remote_cmdlist
, "remote ",
11984 0 /* allow-unknown */, &cmdlist
);
11986 add_cmd ("put", class_files
, remote_put_command
,
11987 _("Copy a local file to the remote system."),
11990 add_cmd ("get", class_files
, remote_get_command
,
11991 _("Copy a remote file to the local system."),
11994 add_cmd ("delete", class_files
, remote_delete_command
,
11995 _("Delete a remote file."),
11998 remote_exec_file
= xstrdup ("");
11999 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12000 &remote_exec_file
, _("\
12001 Set the remote pathname for \"run\""), _("\
12002 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12003 &remote_set_cmdlist
, &remote_show_cmdlist
);
12005 /* Eventually initialize fileio. See fileio.c */
12006 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12008 /* Take advantage of the fact that the LWP field is not used, to tag
12009 special ptids with it set to != 0. */
12010 magic_null_ptid
= ptid_build (42000, 1, -1);
12011 not_sent_ptid
= ptid_build (42000, 1, -2);
12012 any_thread_ptid
= ptid_build (42000, 1, 0);
12014 target_buf_size
= 2048;
12015 target_buf
= xmalloc (target_buf_size
);