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_serial_write (const char *str
, int len
);
127 static void remote_kill (struct target_ops
*ops
);
129 static int tohex (int nib
);
131 static int remote_can_async_p (void);
133 static int remote_is_async_p (void);
135 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
136 void *context
), void *context
);
138 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
140 static void remote_interrupt (int signo
);
142 static void remote_interrupt_twice (int signo
);
144 static void interrupt_query (void);
146 static void set_general_thread (struct ptid ptid
);
147 static void set_continue_thread (struct ptid ptid
);
149 static void get_offsets (void);
151 static void skip_frame (void);
153 static long read_frame (char **buf_p
, long *sizeof_buf
);
155 static int hexnumlen (ULONGEST num
);
157 static void init_remote_ops (void);
159 static void init_extended_remote_ops (void);
161 static void remote_stop (ptid_t
);
163 static int ishex (int ch
, int *val
);
165 static int stubhex (int ch
);
167 static int hexnumstr (char *, ULONGEST
);
169 static int hexnumnstr (char *, ULONGEST
, int);
171 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
173 static void print_packet (char *);
175 static void compare_sections_command (char *, int);
177 static void packet_command (char *, int);
179 static int stub_unpack_int (char *buff
, int fieldlength
);
181 static ptid_t
remote_current_thread (ptid_t oldptid
);
183 static void remote_find_new_threads (void);
185 static void record_currthread (ptid_t currthread
);
187 static int fromhex (int a
);
189 static int putpkt_binary (char *buf
, int cnt
);
191 static void check_binary_download (CORE_ADDR addr
);
193 struct packet_config
;
195 static void show_packet_config_cmd (struct packet_config
*config
);
197 static void update_packet_config (struct packet_config
*config
);
199 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
200 struct cmd_list_element
*c
);
202 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
204 struct cmd_list_element
*c
,
207 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
208 static ptid_t
read_ptid (char *buf
, char **obuf
);
210 static void remote_set_permissions (void);
213 static int remote_get_trace_status (struct trace_status
*ts
);
215 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
217 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
219 static void remote_query_supported (void);
221 static void remote_check_symbols (struct objfile
*objfile
);
223 void _initialize_remote (void);
226 static void stop_reply_xfree (struct stop_reply
*);
227 static void remote_parse_stop_reply (char *, struct stop_reply
*);
228 static void push_stop_reply (struct stop_reply
*);
229 static void discard_pending_stop_replies (struct inferior
*);
230 static int peek_stop_reply (ptid_t ptid
);
232 static void remote_async_inferior_event_handler (gdb_client_data
);
234 static void remote_terminal_ours (void);
236 static int remote_read_description_p (struct target_ops
*target
);
238 static void remote_console_output (char *msg
);
240 static int remote_supports_cond_breakpoints (void);
242 static int remote_can_run_breakpoint_commands (void);
246 static struct cmd_list_element
*remote_cmdlist
;
248 /* For "set remote" and "show remote". */
250 static struct cmd_list_element
*remote_set_cmdlist
;
251 static struct cmd_list_element
*remote_show_cmdlist
;
253 /* Description of the remote protocol state for the currently
254 connected target. This is per-target state, and independent of the
255 selected architecture. */
259 /* A buffer to use for incoming packets, and its current size. The
260 buffer is grown dynamically for larger incoming packets.
261 Outgoing packets may also be constructed in this buffer.
262 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
263 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
268 /* True if we're going through initial connection setup (finding out
269 about the remote side's threads, relocating symbols, etc.). */
272 /* If we negotiated packet size explicitly (and thus can bypass
273 heuristics for the largest packet size that will not overflow
274 a buffer in the stub), this will be set to that packet size.
275 Otherwise zero, meaning to use the guessed size. */
276 long explicit_packet_size
;
278 /* remote_wait is normally called when the target is running and
279 waits for a stop reply packet. But sometimes we need to call it
280 when the target is already stopped. We can send a "?" packet
281 and have remote_wait read the response. Or, if we already have
282 the response, we can stash it in BUF and tell remote_wait to
283 skip calling getpkt. This flag is set when BUF contains a
284 stop reply packet and the target is not waiting. */
285 int cached_wait_status
;
287 /* True, if in no ack mode. That is, neither GDB nor the stub will
288 expect acks from each other. The connection is assumed to be
292 /* True if we're connected in extended remote mode. */
295 /* True if the stub reported support for multi-process
297 int multi_process_aware
;
299 /* True if we resumed the target and we're waiting for the target to
300 stop. In the mean time, we can't start another command/query.
301 The remote server wouldn't be ready to process it, so we'd
302 timeout waiting for a reply that would never come and eventually
303 we'd close the connection. This can happen in asynchronous mode
304 because we allow GDB commands while the target is running. */
305 int waiting_for_stop_reply
;
307 /* True if the stub reports support for non-stop mode. */
310 /* True if the stub reports support for vCont;t. */
313 /* True if the stub reports support for conditional tracepoints. */
314 int cond_tracepoints
;
316 /* True if the stub reports support for target-side breakpoint
318 int cond_breakpoints
;
320 /* True if the stub reports support for target-side breakpoint
322 int breakpoint_commands
;
324 /* True if the stub reports support for fast tracepoints. */
325 int fast_tracepoints
;
327 /* True if the stub reports support for static tracepoints. */
328 int static_tracepoints
;
330 /* True if the stub reports support for installing tracepoint while
332 int install_in_trace
;
334 /* True if the stub can continue running a trace while GDB is
336 int disconnected_tracing
;
338 /* True if the stub reports support for enabling and disabling
339 tracepoints while a trace experiment is running. */
340 int enable_disable_tracepoints
;
342 /* True if the stub can collect strings using tracenz bytecode. */
345 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
346 responded to that. */
350 /* Private data that we'll store in (struct thread_info)->private. */
351 struct private_thread_info
358 free_private_thread_info (struct private_thread_info
*info
)
364 /* Returns true if the multi-process extensions are in effect. */
366 remote_multi_process_p (struct remote_state
*rs
)
368 return rs
->multi_process_aware
;
371 /* This data could be associated with a target, but we do not always
372 have access to the current target when we need it, so for now it is
373 static. This will be fine for as long as only one target is in use
375 static struct remote_state remote_state
;
377 static struct remote_state
*
378 get_remote_state_raw (void)
380 return &remote_state
;
383 /* Description of the remote protocol for a given architecture. */
387 long offset
; /* Offset into G packet. */
388 long regnum
; /* GDB's internal register number. */
389 LONGEST pnum
; /* Remote protocol register number. */
390 int in_g_packet
; /* Always part of G packet. */
391 /* long size in bytes; == register_size (target_gdbarch (), regnum);
393 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
397 struct remote_arch_state
399 /* Description of the remote protocol registers. */
400 long sizeof_g_packet
;
402 /* Description of the remote protocol registers indexed by REGNUM
403 (making an array gdbarch_num_regs in size). */
404 struct packet_reg
*regs
;
406 /* This is the size (in chars) of the first response to the ``g''
407 packet. It is used as a heuristic when determining the maximum
408 size of memory-read and memory-write packets. A target will
409 typically only reserve a buffer large enough to hold the ``g''
410 packet. The size does not include packet overhead (headers and
412 long actual_register_packet_size
;
414 /* This is the maximum size (in chars) of a non read/write packet.
415 It is also used as a cap on the size of read/write packets. */
416 long remote_packet_size
;
419 long sizeof_pkt
= 2000;
421 /* Utility: generate error from an incoming stub packet. */
423 trace_error (char *buf
)
426 return; /* not an error msg */
429 case '1': /* malformed packet error */
430 if (*++buf
== '0') /* general case: */
431 error (_("remote.c: error in outgoing packet."));
433 error (_("remote.c: error in outgoing packet at field #%ld."),
434 strtol (buf
, NULL
, 16));
436 error (_("Target returns error code '%s'."), buf
);
440 /* Utility: wait for reply from stub, while accepting "O" packets. */
442 remote_get_noisy_reply (char **buf_p
,
445 do /* Loop on reply from remote stub. */
449 QUIT
; /* Allow user to bail out with ^C. */
450 getpkt (buf_p
, sizeof_buf
, 0);
454 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
457 CORE_ADDR from
, to
, org_to
;
459 int adjusted_size
= 0;
460 volatile struct gdb_exception ex
;
462 p
= buf
+ strlen ("qRelocInsn:");
463 pp
= unpack_varlen_hex (p
, &ul
);
465 error (_("invalid qRelocInsn packet: %s"), buf
);
469 unpack_varlen_hex (p
, &ul
);
474 TRY_CATCH (ex
, RETURN_MASK_ALL
)
476 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
480 adjusted_size
= to
- org_to
;
482 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
485 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
487 /* Propagate memory errors silently back to the target.
488 The stub may have limited the range of addresses we
489 can write to, for example. */
494 /* Something unexpectedly bad happened. Be verbose so
495 we can tell what, and propagate the error back to the
496 stub, so it doesn't get stuck waiting for a
498 exception_fprintf (gdb_stderr
, ex
,
499 _("warning: relocating instruction: "));
503 else if (buf
[0] == 'O' && buf
[1] != 'K')
504 remote_console_output (buf
+ 1); /* 'O' message from stub */
506 return buf
; /* Here's the actual reply. */
511 /* Handle for retreving the remote protocol data from gdbarch. */
512 static struct gdbarch_data
*remote_gdbarch_data_handle
;
514 static struct remote_arch_state
*
515 get_remote_arch_state (void)
517 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
520 /* Fetch the global remote target state. */
522 static struct remote_state
*
523 get_remote_state (void)
525 /* Make sure that the remote architecture state has been
526 initialized, because doing so might reallocate rs->buf. Any
527 function which calls getpkt also needs to be mindful of changes
528 to rs->buf, but this call limits the number of places which run
530 get_remote_arch_state ();
532 return get_remote_state_raw ();
536 compare_pnums (const void *lhs_
, const void *rhs_
)
538 const struct packet_reg
* const *lhs
= lhs_
;
539 const struct packet_reg
* const *rhs
= rhs_
;
541 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
543 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
550 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
552 int regnum
, num_remote_regs
, offset
;
553 struct packet_reg
**remote_regs
;
555 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
557 struct packet_reg
*r
= ®s
[regnum
];
559 if (register_size (gdbarch
, regnum
) == 0)
560 /* Do not try to fetch zero-sized (placeholder) registers. */
563 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
568 /* Define the g/G packet format as the contents of each register
569 with a remote protocol number, in order of ascending protocol
572 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
573 * sizeof (struct packet_reg
*));
574 for (num_remote_regs
= 0, regnum
= 0;
575 regnum
< gdbarch_num_regs (gdbarch
);
577 if (regs
[regnum
].pnum
!= -1)
578 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
580 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
583 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
585 remote_regs
[regnum
]->in_g_packet
= 1;
586 remote_regs
[regnum
]->offset
= offset
;
587 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
593 /* Given the architecture described by GDBARCH, return the remote
594 protocol register's number and the register's offset in the g/G
595 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
596 If the target does not have a mapping for REGNUM, return false,
597 otherwise, return true. */
600 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
601 int *pnum
, int *poffset
)
604 struct packet_reg
*regs
;
605 struct cleanup
*old_chain
;
607 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
609 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
610 old_chain
= make_cleanup (xfree
, regs
);
612 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
614 *pnum
= regs
[regnum
].pnum
;
615 *poffset
= regs
[regnum
].offset
;
617 do_cleanups (old_chain
);
623 init_remote_state (struct gdbarch
*gdbarch
)
625 struct remote_state
*rs
= get_remote_state_raw ();
626 struct remote_arch_state
*rsa
;
628 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
630 /* Use the architecture to build a regnum<->pnum table, which will be
631 1:1 unless a feature set specifies otherwise. */
632 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
633 gdbarch_num_regs (gdbarch
),
636 /* Record the maximum possible size of the g packet - it may turn out
638 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
640 /* Default maximum number of characters in a packet body. Many
641 remote stubs have a hardwired buffer size of 400 bytes
642 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
643 as the maximum packet-size to ensure that the packet and an extra
644 NUL character can always fit in the buffer. This stops GDB
645 trashing stubs that try to squeeze an extra NUL into what is
646 already a full buffer (As of 1999-12-04 that was most stubs). */
647 rsa
->remote_packet_size
= 400 - 1;
649 /* This one is filled in when a ``g'' packet is received. */
650 rsa
->actual_register_packet_size
= 0;
652 /* Should rsa->sizeof_g_packet needs more space than the
653 default, adjust the size accordingly. Remember that each byte is
654 encoded as two characters. 32 is the overhead for the packet
655 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
656 (``$NN:G...#NN'') is a better guess, the below has been padded a
658 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
659 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
661 /* Make sure that the packet buffer is plenty big enough for
662 this architecture. */
663 if (rs
->buf_size
< rsa
->remote_packet_size
)
665 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
666 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
672 /* Return the current allowed size of a remote packet. This is
673 inferred from the current architecture, and should be used to
674 limit the length of outgoing packets. */
676 get_remote_packet_size (void)
678 struct remote_state
*rs
= get_remote_state ();
679 struct remote_arch_state
*rsa
= get_remote_arch_state ();
681 if (rs
->explicit_packet_size
)
682 return rs
->explicit_packet_size
;
684 return rsa
->remote_packet_size
;
687 static struct packet_reg
*
688 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
690 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
694 struct packet_reg
*r
= &rsa
->regs
[regnum
];
696 gdb_assert (r
->regnum
== regnum
);
701 static struct packet_reg
*
702 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
706 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
708 struct packet_reg
*r
= &rsa
->regs
[i
];
716 /* FIXME: graces/2002-08-08: These variables should eventually be
717 bound to an instance of the target object (as in gdbarch-tdep()),
718 when such a thing exists. */
720 /* This is set to the data address of the access causing the target
721 to stop for a watchpoint. */
722 static CORE_ADDR remote_watch_data_address
;
724 /* This is non-zero if target stopped for a watchpoint. */
725 static int remote_stopped_by_watchpoint_p
;
727 static struct target_ops remote_ops
;
729 static struct target_ops extended_remote_ops
;
731 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
732 ``forever'' still use the normal timeout mechanism. This is
733 currently used by the ASYNC code to guarentee that target reads
734 during the initial connect always time-out. Once getpkt has been
735 modified to return a timeout indication and, in turn
736 remote_wait()/wait_for_inferior() have gained a timeout parameter
738 static int wait_forever_enabled_p
= 1;
740 /* Allow the user to specify what sequence to send to the remote
741 when he requests a program interruption: Although ^C is usually
742 what remote systems expect (this is the default, here), it is
743 sometimes preferable to send a break. On other systems such
744 as the Linux kernel, a break followed by g, which is Magic SysRq g
745 is required in order to interrupt the execution. */
746 const char interrupt_sequence_control_c
[] = "Ctrl-C";
747 const char interrupt_sequence_break
[] = "BREAK";
748 const char interrupt_sequence_break_g
[] = "BREAK-g";
749 static const char *const interrupt_sequence_modes
[] =
751 interrupt_sequence_control_c
,
752 interrupt_sequence_break
,
753 interrupt_sequence_break_g
,
756 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
759 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
760 struct cmd_list_element
*c
,
763 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
764 fprintf_filtered (file
,
765 _("Send the ASCII ETX character (Ctrl-c) "
766 "to the remote target to interrupt the "
767 "execution of the program.\n"));
768 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
769 fprintf_filtered (file
,
770 _("send a break signal to the remote target "
771 "to interrupt the execution of the program.\n"));
772 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
773 fprintf_filtered (file
,
774 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
775 "the remote target to interrupt the execution "
776 "of Linux kernel.\n"));
778 internal_error (__FILE__
, __LINE__
,
779 _("Invalid value for interrupt_sequence_mode: %s."),
780 interrupt_sequence_mode
);
783 /* This boolean variable specifies whether interrupt_sequence is sent
784 to the remote target when gdb connects to it.
785 This is mostly needed when you debug the Linux kernel: The Linux kernel
786 expects BREAK g which is Magic SysRq g for connecting gdb. */
787 static int interrupt_on_connect
= 0;
789 /* This variable is used to implement the "set/show remotebreak" commands.
790 Since these commands are now deprecated in favor of "set/show remote
791 interrupt-sequence", it no longer has any effect on the code. */
792 static int remote_break
;
795 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
798 interrupt_sequence_mode
= interrupt_sequence_break
;
800 interrupt_sequence_mode
= interrupt_sequence_control_c
;
804 show_remotebreak (struct ui_file
*file
, int from_tty
,
805 struct cmd_list_element
*c
,
810 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
811 remote_open knows that we don't have a file open when the program
813 static struct serial
*remote_desc
= NULL
;
815 /* This variable sets the number of bits in an address that are to be
816 sent in a memory ("M" or "m") packet. Normally, after stripping
817 leading zeros, the entire address would be sent. This variable
818 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
819 initial implementation of remote.c restricted the address sent in
820 memory packets to ``host::sizeof long'' bytes - (typically 32
821 bits). Consequently, for 64 bit targets, the upper 32 bits of an
822 address was never sent. Since fixing this bug may cause a break in
823 some remote targets this variable is principly provided to
824 facilitate backward compatibility. */
826 static unsigned int remote_address_size
;
828 /* Temporary to track who currently owns the terminal. See
829 remote_terminal_* for more details. */
831 static int remote_async_terminal_ours_p
;
833 /* The executable file to use for "run" on the remote side. */
835 static char *remote_exec_file
= "";
838 /* User configurable variables for the number of characters in a
839 memory read/write packet. MIN (rsa->remote_packet_size,
840 rsa->sizeof_g_packet) is the default. Some targets need smaller
841 values (fifo overruns, et.al.) and some users need larger values
842 (speed up transfers). The variables ``preferred_*'' (the user
843 request), ``current_*'' (what was actually set) and ``forced_*''
844 (Positive - a soft limit, negative - a hard limit). */
846 struct memory_packet_config
853 /* Compute the current size of a read/write packet. Since this makes
854 use of ``actual_register_packet_size'' the computation is dynamic. */
857 get_memory_packet_size (struct memory_packet_config
*config
)
859 struct remote_state
*rs
= get_remote_state ();
860 struct remote_arch_state
*rsa
= get_remote_arch_state ();
862 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
863 law?) that some hosts don't cope very well with large alloca()
864 calls. Eventually the alloca() code will be replaced by calls to
865 xmalloc() and make_cleanups() allowing this restriction to either
866 be lifted or removed. */
867 #ifndef MAX_REMOTE_PACKET_SIZE
868 #define MAX_REMOTE_PACKET_SIZE 16384
870 /* NOTE: 20 ensures we can write at least one byte. */
871 #ifndef MIN_REMOTE_PACKET_SIZE
872 #define MIN_REMOTE_PACKET_SIZE 20
877 if (config
->size
<= 0)
878 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
880 what_they_get
= config
->size
;
884 what_they_get
= get_remote_packet_size ();
885 /* Limit the packet to the size specified by the user. */
887 && what_they_get
> config
->size
)
888 what_they_get
= config
->size
;
890 /* Limit it to the size of the targets ``g'' response unless we have
891 permission from the stub to use a larger packet size. */
892 if (rs
->explicit_packet_size
== 0
893 && rsa
->actual_register_packet_size
> 0
894 && what_they_get
> rsa
->actual_register_packet_size
)
895 what_they_get
= rsa
->actual_register_packet_size
;
897 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
898 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
899 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
900 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
902 /* Make sure there is room in the global buffer for this packet
903 (including its trailing NUL byte). */
904 if (rs
->buf_size
< what_they_get
+ 1)
906 rs
->buf_size
= 2 * what_they_get
;
907 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
910 return what_they_get
;
913 /* Update the size of a read/write packet. If they user wants
914 something really big then do a sanity check. */
917 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
919 int fixed_p
= config
->fixed_p
;
920 long size
= config
->size
;
923 error (_("Argument required (integer, `fixed' or `limited')."));
924 else if (strcmp (args
, "hard") == 0
925 || strcmp (args
, "fixed") == 0)
927 else if (strcmp (args
, "soft") == 0
928 || strcmp (args
, "limit") == 0)
934 size
= strtoul (args
, &end
, 0);
936 error (_("Invalid %s (bad syntax)."), config
->name
);
938 /* Instead of explicitly capping the size of a packet to
939 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
940 instead allowed to set the size to something arbitrarily
942 if (size
> MAX_REMOTE_PACKET_SIZE
)
943 error (_("Invalid %s (too large)."), config
->name
);
947 if (fixed_p
&& !config
->fixed_p
)
949 if (! query (_("The target may not be able to correctly handle a %s\n"
950 "of %ld bytes. Change the packet size? "),
952 error (_("Packet size not changed."));
954 /* Update the config. */
955 config
->fixed_p
= fixed_p
;
960 show_memory_packet_size (struct memory_packet_config
*config
)
962 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
964 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
965 get_memory_packet_size (config
));
967 printf_filtered (_("Packets are limited to %ld bytes.\n"),
968 get_memory_packet_size (config
));
971 static struct memory_packet_config memory_write_packet_config
=
973 "memory-write-packet-size",
977 set_memory_write_packet_size (char *args
, int from_tty
)
979 set_memory_packet_size (args
, &memory_write_packet_config
);
983 show_memory_write_packet_size (char *args
, int from_tty
)
985 show_memory_packet_size (&memory_write_packet_config
);
989 get_memory_write_packet_size (void)
991 return get_memory_packet_size (&memory_write_packet_config
);
994 static struct memory_packet_config memory_read_packet_config
=
996 "memory-read-packet-size",
1000 set_memory_read_packet_size (char *args
, int from_tty
)
1002 set_memory_packet_size (args
, &memory_read_packet_config
);
1006 show_memory_read_packet_size (char *args
, int from_tty
)
1008 show_memory_packet_size (&memory_read_packet_config
);
1012 get_memory_read_packet_size (void)
1014 long size
= get_memory_packet_size (&memory_read_packet_config
);
1016 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1017 extra buffer size argument before the memory read size can be
1018 increased beyond this. */
1019 if (size
> get_remote_packet_size ())
1020 size
= get_remote_packet_size ();
1025 /* Generic configuration support for packets the stub optionally
1026 supports. Allows the user to specify the use of the packet as well
1027 as allowing GDB to auto-detect support in the remote stub. */
1031 PACKET_SUPPORT_UNKNOWN
= 0,
1036 struct packet_config
1040 enum auto_boolean detect
;
1041 enum packet_support support
;
1044 /* Analyze a packet's return value and update the packet config
1055 update_packet_config (struct packet_config
*config
)
1057 switch (config
->detect
)
1059 case AUTO_BOOLEAN_TRUE
:
1060 config
->support
= PACKET_ENABLE
;
1062 case AUTO_BOOLEAN_FALSE
:
1063 config
->support
= PACKET_DISABLE
;
1065 case AUTO_BOOLEAN_AUTO
:
1066 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1072 show_packet_config_cmd (struct packet_config
*config
)
1074 char *support
= "internal-error";
1076 switch (config
->support
)
1079 support
= "enabled";
1081 case PACKET_DISABLE
:
1082 support
= "disabled";
1084 case PACKET_SUPPORT_UNKNOWN
:
1085 support
= "unknown";
1088 switch (config
->detect
)
1090 case AUTO_BOOLEAN_AUTO
:
1091 printf_filtered (_("Support for the `%s' packet "
1092 "is auto-detected, currently %s.\n"),
1093 config
->name
, support
);
1095 case AUTO_BOOLEAN_TRUE
:
1096 case AUTO_BOOLEAN_FALSE
:
1097 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1098 config
->name
, support
);
1104 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1105 const char *title
, int legacy
)
1111 config
->name
= name
;
1112 config
->title
= title
;
1113 config
->detect
= AUTO_BOOLEAN_AUTO
;
1114 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1115 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1117 show_doc
= xstrprintf ("Show current use of remote "
1118 "protocol `%s' (%s) packet",
1120 /* set/show TITLE-packet {auto,on,off} */
1121 cmd_name
= xstrprintf ("%s-packet", title
);
1122 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1123 &config
->detect
, set_doc
,
1124 show_doc
, NULL
, /* help_doc */
1125 set_remote_protocol_packet_cmd
,
1126 show_remote_protocol_packet_cmd
,
1127 &remote_set_cmdlist
, &remote_show_cmdlist
);
1128 /* The command code copies the documentation strings. */
1131 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1136 legacy_name
= xstrprintf ("%s-packet", name
);
1137 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1138 &remote_set_cmdlist
);
1139 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1140 &remote_show_cmdlist
);
1144 static enum packet_result
1145 packet_check_result (const char *buf
)
1149 /* The stub recognized the packet request. Check that the
1150 operation succeeded. */
1152 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1154 /* "Enn" - definitly an error. */
1155 return PACKET_ERROR
;
1157 /* Always treat "E." as an error. This will be used for
1158 more verbose error messages, such as E.memtypes. */
1159 if (buf
[0] == 'E' && buf
[1] == '.')
1160 return PACKET_ERROR
;
1162 /* The packet may or may not be OK. Just assume it is. */
1166 /* The stub does not support the packet. */
1167 return PACKET_UNKNOWN
;
1170 static enum packet_result
1171 packet_ok (const char *buf
, struct packet_config
*config
)
1173 enum packet_result result
;
1175 result
= packet_check_result (buf
);
1180 /* The stub recognized the packet request. */
1181 switch (config
->support
)
1183 case PACKET_SUPPORT_UNKNOWN
:
1185 fprintf_unfiltered (gdb_stdlog
,
1186 "Packet %s (%s) is supported\n",
1187 config
->name
, config
->title
);
1188 config
->support
= PACKET_ENABLE
;
1190 case PACKET_DISABLE
:
1191 internal_error (__FILE__
, __LINE__
,
1192 _("packet_ok: attempt to use a disabled packet"));
1198 case PACKET_UNKNOWN
:
1199 /* The stub does not support the packet. */
1200 switch (config
->support
)
1203 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1204 /* If the stub previously indicated that the packet was
1205 supported then there is a protocol error.. */
1206 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1207 config
->name
, config
->title
);
1209 /* The user set it wrong. */
1210 error (_("Enabled packet %s (%s) not recognized by stub"),
1211 config
->name
, config
->title
);
1213 case PACKET_SUPPORT_UNKNOWN
:
1215 fprintf_unfiltered (gdb_stdlog
,
1216 "Packet %s (%s) is NOT supported\n",
1217 config
->name
, config
->title
);
1218 config
->support
= PACKET_DISABLE
;
1220 case PACKET_DISABLE
:
1242 PACKET_vFile_pwrite
,
1244 PACKET_vFile_unlink
,
1245 PACKET_vFile_readlink
,
1247 PACKET_qXfer_features
,
1248 PACKET_qXfer_libraries
,
1249 PACKET_qXfer_libraries_svr4
,
1250 PACKET_qXfer_memory_map
,
1251 PACKET_qXfer_spu_read
,
1252 PACKET_qXfer_spu_write
,
1253 PACKET_qXfer_osdata
,
1254 PACKET_qXfer_threads
,
1255 PACKET_qXfer_statictrace_read
,
1256 PACKET_qXfer_traceframe_info
,
1262 PACKET_QPassSignals
,
1263 PACKET_QProgramSignals
,
1264 PACKET_qSearch_memory
,
1267 PACKET_QStartNoAckMode
,
1269 PACKET_qXfer_siginfo_read
,
1270 PACKET_qXfer_siginfo_write
,
1272 PACKET_ConditionalTracepoints
,
1273 PACKET_ConditionalBreakpoints
,
1274 PACKET_BreakpointCommands
,
1275 PACKET_FastTracepoints
,
1276 PACKET_StaticTracepoints
,
1277 PACKET_InstallInTrace
,
1280 PACKET_TracepointSource
,
1283 PACKET_QDisableRandomization
,
1285 PACKET_QTBuffer_size
,
1288 PACKET_qXfer_btrace
,
1292 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1295 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1296 struct cmd_list_element
*c
)
1298 struct packet_config
*packet
;
1300 for (packet
= remote_protocol_packets
;
1301 packet
< &remote_protocol_packets
[PACKET_MAX
];
1304 if (&packet
->detect
== c
->var
)
1306 update_packet_config (packet
);
1310 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1315 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1316 struct cmd_list_element
*c
,
1319 struct packet_config
*packet
;
1321 for (packet
= remote_protocol_packets
;
1322 packet
< &remote_protocol_packets
[PACKET_MAX
];
1325 if (&packet
->detect
== c
->var
)
1327 show_packet_config_cmd (packet
);
1331 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1335 /* Should we try one of the 'Z' requests? */
1339 Z_PACKET_SOFTWARE_BP
,
1340 Z_PACKET_HARDWARE_BP
,
1347 /* For compatibility with older distributions. Provide a ``set remote
1348 Z-packet ...'' command that updates all the Z packet types. */
1350 static enum auto_boolean remote_Z_packet_detect
;
1353 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1354 struct cmd_list_element
*c
)
1358 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1360 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1361 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1366 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1367 struct cmd_list_element
*c
,
1372 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1374 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1378 /* Should we try the 'ThreadInfo' query packet?
1380 This variable (NOT available to the user: auto-detect only!)
1381 determines whether GDB will use the new, simpler "ThreadInfo"
1382 query or the older, more complex syntax for thread queries.
1383 This is an auto-detect variable (set to true at each connect,
1384 and set to false when the target fails to recognize it). */
1386 static int use_threadinfo_query
;
1387 static int use_threadextra_query
;
1389 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1390 static struct async_signal_handler
*sigint_remote_twice_token
;
1391 static struct async_signal_handler
*sigint_remote_token
;
1394 /* Asynchronous signal handle registered as event loop source for
1395 when we have pending events ready to be passed to the core. */
1397 static struct async_event_handler
*remote_async_inferior_event_token
;
1401 static ptid_t magic_null_ptid
;
1402 static ptid_t not_sent_ptid
;
1403 static ptid_t any_thread_ptid
;
1405 /* These are the threads which we last sent to the remote system. The
1406 TID member will be -1 for all or -2 for not sent yet. */
1408 static ptid_t general_thread
;
1409 static ptid_t continue_thread
;
1411 /* This is the traceframe which we last selected on the remote system.
1412 It will be -1 if no traceframe is selected. */
1413 static int remote_traceframe_number
= -1;
1415 /* Find out if the stub attached to PID (and hence GDB should offer to
1416 detach instead of killing it when bailing out). */
1419 remote_query_attached (int pid
)
1421 struct remote_state
*rs
= get_remote_state ();
1422 size_t size
= get_remote_packet_size ();
1424 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1427 if (remote_multi_process_p (rs
))
1428 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1430 xsnprintf (rs
->buf
, size
, "qAttached");
1433 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1435 switch (packet_ok (rs
->buf
,
1436 &remote_protocol_packets
[PACKET_qAttached
]))
1439 if (strcmp (rs
->buf
, "1") == 0)
1443 warning (_("Remote failure reply: %s"), rs
->buf
);
1445 case PACKET_UNKNOWN
:
1452 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1453 has been invented by GDB, instead of reported by the target. Since
1454 we can be connected to a remote system before before knowing about
1455 any inferior, mark the target with execution when we find the first
1456 inferior. If ATTACHED is 1, then we had just attached to this
1457 inferior. If it is 0, then we just created this inferior. If it
1458 is -1, then try querying the remote stub to find out if it had
1459 attached to the inferior or not. */
1461 static struct inferior
*
1462 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1464 struct inferior
*inf
;
1466 /* Check whether this process we're learning about is to be
1467 considered attached, or if is to be considered to have been
1468 spawned by the stub. */
1470 attached
= remote_query_attached (pid
);
1472 if (gdbarch_has_global_solist (target_gdbarch ()))
1474 /* If the target shares code across all inferiors, then every
1475 attach adds a new inferior. */
1476 inf
= add_inferior (pid
);
1478 /* ... and every inferior is bound to the same program space.
1479 However, each inferior may still have its own address
1481 inf
->aspace
= maybe_new_address_space ();
1482 inf
->pspace
= current_program_space
;
1486 /* In the traditional debugging scenario, there's a 1-1 match
1487 between program/address spaces. We simply bind the inferior
1488 to the program space's address space. */
1489 inf
= current_inferior ();
1490 inferior_appeared (inf
, pid
);
1493 inf
->attach_flag
= attached
;
1494 inf
->fake_pid_p
= fake_pid_p
;
1499 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1500 according to RUNNING. */
1503 remote_add_thread (ptid_t ptid
, int running
)
1507 set_executing (ptid
, running
);
1508 set_running (ptid
, running
);
1511 /* Come here when we learn about a thread id from the remote target.
1512 It may be the first time we hear about such thread, so take the
1513 opportunity to add it to GDB's thread list. In case this is the
1514 first time we're noticing its corresponding inferior, add it to
1515 GDB's inferior list as well. */
1518 remote_notice_new_inferior (ptid_t currthread
, int running
)
1520 /* If this is a new thread, add it to GDB's thread list.
1521 If we leave it up to WFI to do this, bad things will happen. */
1523 if (in_thread_list (currthread
) && is_exited (currthread
))
1525 /* We're seeing an event on a thread id we knew had exited.
1526 This has to be a new thread reusing the old id. Add it. */
1527 remote_add_thread (currthread
, running
);
1531 if (!in_thread_list (currthread
))
1533 struct inferior
*inf
= NULL
;
1534 int pid
= ptid_get_pid (currthread
);
1536 if (ptid_is_pid (inferior_ptid
)
1537 && pid
== ptid_get_pid (inferior_ptid
))
1539 /* inferior_ptid has no thread member yet. This can happen
1540 with the vAttach -> remote_wait,"TAAthread:" path if the
1541 stub doesn't support qC. This is the first stop reported
1542 after an attach, so this is the main thread. Update the
1543 ptid in the thread list. */
1544 if (in_thread_list (pid_to_ptid (pid
)))
1545 thread_change_ptid (inferior_ptid
, currthread
);
1548 remote_add_thread (currthread
, running
);
1549 inferior_ptid
= currthread
;
1554 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1556 /* inferior_ptid is not set yet. This can happen with the
1557 vRun -> remote_wait,"TAAthread:" path if the stub
1558 doesn't support qC. This is the first stop reported
1559 after an attach, so this is the main thread. Update the
1560 ptid in the thread list. */
1561 thread_change_ptid (inferior_ptid
, currthread
);
1565 /* When connecting to a target remote, or to a target
1566 extended-remote which already was debugging an inferior, we
1567 may not know about it yet. Add it before adding its child
1568 thread, so notifications are emitted in a sensible order. */
1569 if (!in_inferior_list (ptid_get_pid (currthread
)))
1571 struct remote_state
*rs
= get_remote_state ();
1572 int fake_pid_p
= !remote_multi_process_p (rs
);
1574 inf
= remote_add_inferior (fake_pid_p
,
1575 ptid_get_pid (currthread
), -1);
1578 /* This is really a new thread. Add it. */
1579 remote_add_thread (currthread
, running
);
1581 /* If we found a new inferior, let the common code do whatever
1582 it needs to with it (e.g., read shared libraries, insert
1585 notice_new_inferior (currthread
, running
, 0);
1589 /* Return the private thread data, creating it if necessary. */
1591 static struct private_thread_info
*
1592 demand_private_info (ptid_t ptid
)
1594 struct thread_info
*info
= find_thread_ptid (ptid
);
1600 info
->private = xmalloc (sizeof (*(info
->private)));
1601 info
->private_dtor
= free_private_thread_info
;
1602 info
->private->core
= -1;
1603 info
->private->extra
= 0;
1606 return info
->private;
1609 /* Call this function as a result of
1610 1) A halt indication (T packet) containing a thread id
1611 2) A direct query of currthread
1612 3) Successful execution of set thread */
1615 record_currthread (ptid_t currthread
)
1617 general_thread
= currthread
;
1620 static char *last_pass_packet
;
1622 /* If 'QPassSignals' is supported, tell the remote stub what signals
1623 it can simply pass through to the inferior without reporting. */
1626 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1628 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1630 char *pass_packet
, *p
;
1633 gdb_assert (numsigs
< 256);
1634 for (i
= 0; i
< numsigs
; i
++)
1636 if (pass_signals
[i
])
1639 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1640 strcpy (pass_packet
, "QPassSignals:");
1641 p
= pass_packet
+ strlen (pass_packet
);
1642 for (i
= 0; i
< numsigs
; i
++)
1644 if (pass_signals
[i
])
1647 *p
++ = tohex (i
>> 4);
1648 *p
++ = tohex (i
& 15);
1657 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1659 struct remote_state
*rs
= get_remote_state ();
1660 char *buf
= rs
->buf
;
1662 putpkt (pass_packet
);
1663 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1664 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1665 if (last_pass_packet
)
1666 xfree (last_pass_packet
);
1667 last_pass_packet
= pass_packet
;
1670 xfree (pass_packet
);
1674 /* The last QProgramSignals packet sent to the target. We bypass
1675 sending a new program signals list down to the target if the new
1676 packet is exactly the same as the last we sent. IOW, we only let
1677 the target know about program signals list changes. */
1679 static char *last_program_signals_packet
;
1681 /* If 'QProgramSignals' is supported, tell the remote stub what
1682 signals it should pass through to the inferior when detaching. */
1685 remote_program_signals (int numsigs
, unsigned char *signals
)
1687 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1692 gdb_assert (numsigs
< 256);
1693 for (i
= 0; i
< numsigs
; i
++)
1698 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1699 strcpy (packet
, "QProgramSignals:");
1700 p
= packet
+ strlen (packet
);
1701 for (i
= 0; i
< numsigs
; i
++)
1703 if (signal_pass_state (i
))
1706 *p
++ = tohex (i
>> 4);
1707 *p
++ = tohex (i
& 15);
1716 if (!last_program_signals_packet
1717 || strcmp (last_program_signals_packet
, packet
) != 0)
1719 struct remote_state
*rs
= get_remote_state ();
1720 char *buf
= rs
->buf
;
1723 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1724 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1725 xfree (last_program_signals_packet
);
1726 last_program_signals_packet
= packet
;
1733 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1734 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1735 thread. If GEN is set, set the general thread, if not, then set
1736 the step/continue thread. */
1738 set_thread (struct ptid ptid
, int gen
)
1740 struct remote_state
*rs
= get_remote_state ();
1741 ptid_t state
= gen
? general_thread
: continue_thread
;
1742 char *buf
= rs
->buf
;
1743 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1745 if (ptid_equal (state
, ptid
))
1749 *buf
++ = gen
? 'g' : 'c';
1750 if (ptid_equal (ptid
, magic_null_ptid
))
1751 xsnprintf (buf
, endbuf
- buf
, "0");
1752 else if (ptid_equal (ptid
, any_thread_ptid
))
1753 xsnprintf (buf
, endbuf
- buf
, "0");
1754 else if (ptid_equal (ptid
, minus_one_ptid
))
1755 xsnprintf (buf
, endbuf
- buf
, "-1");
1757 write_ptid (buf
, endbuf
, ptid
);
1759 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1761 general_thread
= ptid
;
1763 continue_thread
= ptid
;
1767 set_general_thread (struct ptid ptid
)
1769 set_thread (ptid
, 1);
1773 set_continue_thread (struct ptid ptid
)
1775 set_thread (ptid
, 0);
1778 /* Change the remote current process. Which thread within the process
1779 ends up selected isn't important, as long as it is the same process
1780 as what INFERIOR_PTID points to.
1782 This comes from that fact that there is no explicit notion of
1783 "selected process" in the protocol. The selected process for
1784 general operations is the process the selected general thread
1788 set_general_process (void)
1790 struct remote_state
*rs
= get_remote_state ();
1792 /* If the remote can't handle multiple processes, don't bother. */
1793 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1796 /* We only need to change the remote current thread if it's pointing
1797 at some other process. */
1798 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1799 set_general_thread (inferior_ptid
);
1803 /* Return nonzero if the thread PTID is still alive on the remote
1807 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1809 struct remote_state
*rs
= get_remote_state ();
1812 if (ptid_equal (ptid
, magic_null_ptid
))
1813 /* The main thread is always alive. */
1816 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1817 /* The main thread is always alive. This can happen after a
1818 vAttach, if the remote side doesn't support
1823 endp
= rs
->buf
+ get_remote_packet_size ();
1826 write_ptid (p
, endp
, ptid
);
1829 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1830 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1833 /* About these extended threadlist and threadinfo packets. They are
1834 variable length packets but, the fields within them are often fixed
1835 length. They are redundent enough to send over UDP as is the
1836 remote protocol in general. There is a matching unit test module
1839 #define OPAQUETHREADBYTES 8
1841 /* a 64 bit opaque identifier */
1842 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1844 /* WARNING: This threadref data structure comes from the remote O.S.,
1845 libstub protocol encoding, and remote.c. It is not particularly
1848 /* Right now, the internal structure is int. We want it to be bigger.
1849 Plan to fix this. */
1851 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1853 /* gdb_ext_thread_info is an internal GDB data structure which is
1854 equivalent to the reply of the remote threadinfo packet. */
1856 struct gdb_ext_thread_info
1858 threadref threadid
; /* External form of thread reference. */
1859 int active
; /* Has state interesting to GDB?
1861 char display
[256]; /* Brief state display, name,
1862 blocked/suspended. */
1863 char shortname
[32]; /* To be used to name threads. */
1864 char more_display
[256]; /* Long info, statistics, queue depth,
1868 /* The volume of remote transfers can be limited by submitting
1869 a mask containing bits specifying the desired information.
1870 Use a union of these values as the 'selection' parameter to
1871 get_thread_info. FIXME: Make these TAG names more thread specific. */
1873 #define TAG_THREADID 1
1874 #define TAG_EXISTS 2
1875 #define TAG_DISPLAY 4
1876 #define TAG_THREADNAME 8
1877 #define TAG_MOREDISPLAY 16
1879 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1881 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1883 static char *unpack_nibble (char *buf
, int *val
);
1885 static char *pack_nibble (char *buf
, int nibble
);
1887 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1889 static char *unpack_byte (char *buf
, int *value
);
1891 static char *pack_int (char *buf
, int value
);
1893 static char *unpack_int (char *buf
, int *value
);
1895 static char *unpack_string (char *src
, char *dest
, int length
);
1897 static char *pack_threadid (char *pkt
, threadref
*id
);
1899 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1901 void int_to_threadref (threadref
*id
, int value
);
1903 static int threadref_to_int (threadref
*ref
);
1905 static void copy_threadref (threadref
*dest
, threadref
*src
);
1907 static int threadmatch (threadref
*dest
, threadref
*src
);
1909 static char *pack_threadinfo_request (char *pkt
, int mode
,
1912 static int remote_unpack_thread_info_response (char *pkt
,
1913 threadref
*expectedref
,
1914 struct gdb_ext_thread_info
1918 static int remote_get_threadinfo (threadref
*threadid
,
1919 int fieldset
, /*TAG mask */
1920 struct gdb_ext_thread_info
*info
);
1922 static char *pack_threadlist_request (char *pkt
, int startflag
,
1924 threadref
*nextthread
);
1926 static int parse_threadlist_response (char *pkt
,
1928 threadref
*original_echo
,
1929 threadref
*resultlist
,
1932 static int remote_get_threadlist (int startflag
,
1933 threadref
*nextthread
,
1937 threadref
*threadlist
);
1939 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1941 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1942 void *context
, int looplimit
);
1944 static int remote_newthread_step (threadref
*ref
, void *context
);
1947 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1948 buffer we're allowed to write to. Returns
1949 BUF+CHARACTERS_WRITTEN. */
1952 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1955 struct remote_state
*rs
= get_remote_state ();
1957 if (remote_multi_process_p (rs
))
1959 pid
= ptid_get_pid (ptid
);
1961 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1963 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1965 tid
= ptid_get_tid (ptid
);
1967 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1969 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1974 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1975 passed the last parsed char. Returns null_ptid on error. */
1978 read_ptid (char *buf
, char **obuf
)
1982 ULONGEST pid
= 0, tid
= 0;
1986 /* Multi-process ptid. */
1987 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1989 error (_("invalid remote ptid: %s"), p
);
1992 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1995 return ptid_build (pid
, 0, tid
);
1998 /* No multi-process. Just a tid. */
1999 pp
= unpack_varlen_hex (p
, &tid
);
2001 /* Since the stub is not sending a process id, then default to
2002 what's in inferior_ptid, unless it's null at this point. If so,
2003 then since there's no way to know the pid of the reported
2004 threads, use the magic number. */
2005 if (ptid_equal (inferior_ptid
, null_ptid
))
2006 pid
= ptid_get_pid (magic_null_ptid
);
2008 pid
= ptid_get_pid (inferior_ptid
);
2012 return ptid_build (pid
, 0, tid
);
2015 /* Encode 64 bits in 16 chars of hex. */
2017 static const char hexchars
[] = "0123456789abcdef";
2020 ishex (int ch
, int *val
)
2022 if ((ch
>= 'a') && (ch
<= 'f'))
2024 *val
= ch
- 'a' + 10;
2027 if ((ch
>= 'A') && (ch
<= 'F'))
2029 *val
= ch
- 'A' + 10;
2032 if ((ch
>= '0') && (ch
<= '9'))
2043 if (ch
>= 'a' && ch
<= 'f')
2044 return ch
- 'a' + 10;
2045 if (ch
>= '0' && ch
<= '9')
2047 if (ch
>= 'A' && ch
<= 'F')
2048 return ch
- 'A' + 10;
2053 stub_unpack_int (char *buff
, int fieldlength
)
2060 nibble
= stubhex (*buff
++);
2064 retval
= retval
<< 4;
2070 unpack_varlen_hex (char *buff
, /* packet to parse */
2074 ULONGEST retval
= 0;
2076 while (ishex (*buff
, &nibble
))
2079 retval
= retval
<< 4;
2080 retval
|= nibble
& 0x0f;
2087 unpack_nibble (char *buf
, int *val
)
2089 *val
= fromhex (*buf
++);
2094 pack_nibble (char *buf
, int nibble
)
2096 *buf
++ = hexchars
[(nibble
& 0x0f)];
2101 pack_hex_byte (char *pkt
, int byte
)
2103 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2104 *pkt
++ = hexchars
[(byte
& 0xf)];
2109 unpack_byte (char *buf
, int *value
)
2111 *value
= stub_unpack_int (buf
, 2);
2116 pack_int (char *buf
, int value
)
2118 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2119 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2120 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2121 buf
= pack_hex_byte (buf
, (value
& 0xff));
2126 unpack_int (char *buf
, int *value
)
2128 *value
= stub_unpack_int (buf
, 8);
2132 #if 0 /* Currently unused, uncomment when needed. */
2133 static char *pack_string (char *pkt
, char *string
);
2136 pack_string (char *pkt
, char *string
)
2141 len
= strlen (string
);
2143 len
= 200; /* Bigger than most GDB packets, junk??? */
2144 pkt
= pack_hex_byte (pkt
, len
);
2148 if ((ch
== '\0') || (ch
== '#'))
2149 ch
= '*'; /* Protect encapsulation. */
2154 #endif /* 0 (unused) */
2157 unpack_string (char *src
, char *dest
, int length
)
2166 pack_threadid (char *pkt
, threadref
*id
)
2169 unsigned char *altid
;
2171 altid
= (unsigned char *) id
;
2172 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2174 pkt
= pack_hex_byte (pkt
, *altid
++);
2180 unpack_threadid (char *inbuf
, threadref
*id
)
2183 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2186 altref
= (char *) id
;
2188 while (inbuf
< limit
)
2190 x
= stubhex (*inbuf
++);
2191 y
= stubhex (*inbuf
++);
2192 *altref
++ = (x
<< 4) | y
;
2197 /* Externally, threadrefs are 64 bits but internally, they are still
2198 ints. This is due to a mismatch of specifications. We would like
2199 to use 64bit thread references internally. This is an adapter
2203 int_to_threadref (threadref
*id
, int value
)
2205 unsigned char *scan
;
2207 scan
= (unsigned char *) id
;
2213 *scan
++ = (value
>> 24) & 0xff;
2214 *scan
++ = (value
>> 16) & 0xff;
2215 *scan
++ = (value
>> 8) & 0xff;
2216 *scan
++ = (value
& 0xff);
2220 threadref_to_int (threadref
*ref
)
2223 unsigned char *scan
;
2229 value
= (value
<< 8) | ((*scan
++) & 0xff);
2234 copy_threadref (threadref
*dest
, threadref
*src
)
2237 unsigned char *csrc
, *cdest
;
2239 csrc
= (unsigned char *) src
;
2240 cdest
= (unsigned char *) dest
;
2247 threadmatch (threadref
*dest
, threadref
*src
)
2249 /* Things are broken right now, so just assume we got a match. */
2251 unsigned char *srcp
, *destp
;
2253 srcp
= (char *) src
;
2254 destp
= (char *) dest
;
2258 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2265 threadid:1, # always request threadid
2272 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2275 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2277 *pkt
++ = 'q'; /* Info Query */
2278 *pkt
++ = 'P'; /* process or thread info */
2279 pkt
= pack_int (pkt
, mode
); /* mode */
2280 pkt
= pack_threadid (pkt
, id
); /* threadid */
2281 *pkt
= '\0'; /* terminate */
2285 /* These values tag the fields in a thread info response packet. */
2286 /* Tagging the fields allows us to request specific fields and to
2287 add more fields as time goes by. */
2289 #define TAG_THREADID 1 /* Echo the thread identifier. */
2290 #define TAG_EXISTS 2 /* Is this process defined enough to
2291 fetch registers and its stack? */
2292 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2293 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2294 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2298 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2299 struct gdb_ext_thread_info
*info
)
2301 struct remote_state
*rs
= get_remote_state ();
2305 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2308 /* info->threadid = 0; FIXME: implement zero_threadref. */
2310 info
->display
[0] = '\0';
2311 info
->shortname
[0] = '\0';
2312 info
->more_display
[0] = '\0';
2314 /* Assume the characters indicating the packet type have been
2316 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2317 pkt
= unpack_threadid (pkt
, &ref
);
2320 warning (_("Incomplete response to threadinfo request."));
2321 if (!threadmatch (&ref
, expectedref
))
2322 { /* This is an answer to a different request. */
2323 warning (_("ERROR RMT Thread info mismatch."));
2326 copy_threadref (&info
->threadid
, &ref
);
2328 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2330 /* Packets are terminated with nulls. */
2331 while ((pkt
< limit
) && mask
&& *pkt
)
2333 pkt
= unpack_int (pkt
, &tag
); /* tag */
2334 pkt
= unpack_byte (pkt
, &length
); /* length */
2335 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2337 warning (_("ERROR RMT: threadinfo tag mismatch."));
2341 if (tag
== TAG_THREADID
)
2345 warning (_("ERROR RMT: length of threadid is not 16."));
2349 pkt
= unpack_threadid (pkt
, &ref
);
2350 mask
= mask
& ~TAG_THREADID
;
2353 if (tag
== TAG_EXISTS
)
2355 info
->active
= stub_unpack_int (pkt
, length
);
2357 mask
= mask
& ~(TAG_EXISTS
);
2360 warning (_("ERROR RMT: 'exists' length too long."));
2366 if (tag
== TAG_THREADNAME
)
2368 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2369 mask
= mask
& ~TAG_THREADNAME
;
2372 if (tag
== TAG_DISPLAY
)
2374 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2375 mask
= mask
& ~TAG_DISPLAY
;
2378 if (tag
== TAG_MOREDISPLAY
)
2380 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2381 mask
= mask
& ~TAG_MOREDISPLAY
;
2384 warning (_("ERROR RMT: unknown thread info tag."));
2385 break; /* Not a tag we know about. */
2391 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2392 struct gdb_ext_thread_info
*info
)
2394 struct remote_state
*rs
= get_remote_state ();
2397 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2399 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2401 if (rs
->buf
[0] == '\0')
2404 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2409 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2412 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2413 threadref
*nextthread
)
2415 *pkt
++ = 'q'; /* info query packet */
2416 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2417 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2418 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2419 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2424 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2427 parse_threadlist_response (char *pkt
, int result_limit
,
2428 threadref
*original_echo
, threadref
*resultlist
,
2431 struct remote_state
*rs
= get_remote_state ();
2433 int count
, resultcount
, done
;
2436 /* Assume the 'q' and 'M chars have been stripped. */
2437 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2438 /* done parse past here */
2439 pkt
= unpack_byte (pkt
, &count
); /* count field */
2440 pkt
= unpack_nibble (pkt
, &done
);
2441 /* The first threadid is the argument threadid. */
2442 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2443 while ((count
-- > 0) && (pkt
< limit
))
2445 pkt
= unpack_threadid (pkt
, resultlist
++);
2446 if (resultcount
++ >= result_limit
)
2455 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2456 int *done
, int *result_count
, threadref
*threadlist
)
2458 struct remote_state
*rs
= get_remote_state ();
2459 static threadref echo_nextthread
;
2462 /* Trancate result limit to be smaller than the packet size. */
2463 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2464 >= get_remote_packet_size ())
2465 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2467 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2471 if (*rs
->buf
== '\0')
2475 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2478 if (!threadmatch (&echo_nextthread
, nextthread
))
2480 /* FIXME: This is a good reason to drop the packet. */
2481 /* Possably, there is a duplicate response. */
2483 retransmit immediatly - race conditions
2484 retransmit after timeout - yes
2486 wait for packet, then exit
2488 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2489 return 0; /* I choose simply exiting. */
2491 if (*result_count
<= 0)
2495 warning (_("RMT ERROR : failed to get remote thread list."));
2498 return result
; /* break; */
2500 if (*result_count
> result_limit
)
2503 warning (_("RMT ERROR: threadlist response longer than requested."));
2509 /* This is the interface between remote and threads, remotes upper
2512 /* remote_find_new_threads retrieves the thread list and for each
2513 thread in the list, looks up the thread in GDB's internal list,
2514 adding the thread if it does not already exist. This involves
2515 getting partial thread lists from the remote target so, polling the
2516 quit_flag is required. */
2519 /* About this many threadisds fit in a packet. */
2521 #define MAXTHREADLISTRESULTS 32
2524 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2527 int done
, i
, result_count
;
2531 static threadref nextthread
;
2532 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2537 if (loopcount
++ > looplimit
)
2540 warning (_("Remote fetch threadlist -infinite loop-."));
2543 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2544 &done
, &result_count
, resultthreadlist
))
2549 /* Clear for later iterations. */
2551 /* Setup to resume next batch of thread references, set nextthread. */
2552 if (result_count
>= 1)
2553 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2555 while (result_count
--)
2556 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2563 remote_newthread_step (threadref
*ref
, void *context
)
2565 int pid
= ptid_get_pid (inferior_ptid
);
2566 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2568 if (!in_thread_list (ptid
))
2570 return 1; /* continue iterator */
2573 #define CRAZY_MAX_THREADS 1000
2576 remote_current_thread (ptid_t oldpid
)
2578 struct remote_state
*rs
= get_remote_state ();
2581 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2582 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2583 return read_ptid (&rs
->buf
[2], NULL
);
2588 /* Find new threads for info threads command.
2589 * Original version, using John Metzler's thread protocol.
2593 remote_find_new_threads (void)
2595 remote_threadlist_iterator (remote_newthread_step
, 0,
2599 #if defined(HAVE_LIBEXPAT)
2601 typedef struct thread_item
2607 DEF_VEC_O(thread_item_t
);
2609 struct threads_parsing_context
2611 VEC (thread_item_t
) *items
;
2615 start_thread (struct gdb_xml_parser
*parser
,
2616 const struct gdb_xml_element
*element
,
2617 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2619 struct threads_parsing_context
*data
= user_data
;
2621 struct thread_item item
;
2623 struct gdb_xml_value
*attr
;
2625 id
= xml_find_attribute (attributes
, "id")->value
;
2626 item
.ptid
= read_ptid (id
, NULL
);
2628 attr
= xml_find_attribute (attributes
, "core");
2630 item
.core
= *(ULONGEST
*) attr
->value
;
2636 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2640 end_thread (struct gdb_xml_parser
*parser
,
2641 const struct gdb_xml_element
*element
,
2642 void *user_data
, const char *body_text
)
2644 struct threads_parsing_context
*data
= user_data
;
2646 if (body_text
&& *body_text
)
2647 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2650 const struct gdb_xml_attribute thread_attributes
[] = {
2651 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2652 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2653 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2656 const struct gdb_xml_element thread_children
[] = {
2657 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2660 const struct gdb_xml_element threads_children
[] = {
2661 { "thread", thread_attributes
, thread_children
,
2662 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2663 start_thread
, end_thread
},
2664 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2667 const struct gdb_xml_element threads_elements
[] = {
2668 { "threads", NULL
, threads_children
,
2669 GDB_XML_EF_NONE
, NULL
, NULL
},
2670 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2673 /* Discard the contents of the constructed thread info context. */
2676 clear_threads_parsing_context (void *p
)
2678 struct threads_parsing_context
*context
= p
;
2680 struct thread_item
*item
;
2682 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2683 xfree (item
->extra
);
2685 VEC_free (thread_item_t
, context
->items
);
2691 * Find all threads for info threads command.
2692 * Uses new thread protocol contributed by Cisco.
2693 * Falls back and attempts to use the older method (above)
2694 * if the target doesn't respond to the new method.
2698 remote_threads_info (struct target_ops
*ops
)
2700 struct remote_state
*rs
= get_remote_state ();
2704 if (remote_desc
== 0) /* paranoia */
2705 error (_("Command can only be used when connected to the remote target."));
2707 #if defined(HAVE_LIBEXPAT)
2708 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2710 char *xml
= target_read_stralloc (¤t_target
,
2711 TARGET_OBJECT_THREADS
, NULL
);
2713 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2717 struct threads_parsing_context context
;
2719 context
.items
= NULL
;
2720 make_cleanup (clear_threads_parsing_context
, &context
);
2722 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2723 threads_elements
, xml
, &context
) == 0)
2726 struct thread_item
*item
;
2729 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2732 if (!ptid_equal (item
->ptid
, null_ptid
))
2734 struct private_thread_info
*info
;
2735 /* In non-stop mode, we assume new found threads
2736 are running until proven otherwise with a
2737 stop reply. In all-stop, we can only get
2738 here if all threads are stopped. */
2739 int running
= non_stop
? 1 : 0;
2741 remote_notice_new_inferior (item
->ptid
, running
);
2743 info
= demand_private_info (item
->ptid
);
2744 info
->core
= item
->core
;
2745 info
->extra
= item
->extra
;
2752 do_cleanups (back_to
);
2757 if (use_threadinfo_query
)
2759 putpkt ("qfThreadInfo");
2760 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2762 if (bufp
[0] != '\0') /* q packet recognized */
2764 struct cleanup
*old_chain
;
2767 /* remote_notice_new_inferior (in the loop below) may make
2768 new RSP calls, which clobber rs->buf. Work with a
2770 bufp
= saved_reply
= xstrdup (rs
->buf
);
2771 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2773 while (*bufp
++ == 'm') /* reply contains one or more TID */
2777 new_thread
= read_ptid (bufp
, &bufp
);
2778 if (!ptid_equal (new_thread
, null_ptid
))
2780 /* In non-stop mode, we assume new found threads
2781 are running until proven otherwise with a
2782 stop reply. In all-stop, we can only get
2783 here if all threads are stopped. */
2784 int running
= non_stop
? 1 : 0;
2786 remote_notice_new_inferior (new_thread
, running
);
2789 while (*bufp
++ == ','); /* comma-separated list */
2790 free_current_contents (&saved_reply
);
2791 putpkt ("qsThreadInfo");
2792 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2793 bufp
= saved_reply
= xstrdup (rs
->buf
);
2795 do_cleanups (old_chain
);
2800 /* Only qfThreadInfo is supported in non-stop mode. */
2804 /* Else fall back to old method based on jmetzler protocol. */
2805 use_threadinfo_query
= 0;
2806 remote_find_new_threads ();
2811 * Collect a descriptive string about the given thread.
2812 * The target may say anything it wants to about the thread
2813 * (typically info about its blocked / runnable state, name, etc.).
2814 * This string will appear in the info threads display.
2816 * Optional: targets are not required to implement this function.
2820 remote_threads_extra_info (struct thread_info
*tp
)
2822 struct remote_state
*rs
= get_remote_state ();
2826 struct gdb_ext_thread_info threadinfo
;
2827 static char display_buf
[100]; /* arbitrary... */
2828 int n
= 0; /* position in display_buf */
2830 if (remote_desc
== 0) /* paranoia */
2831 internal_error (__FILE__
, __LINE__
,
2832 _("remote_threads_extra_info"));
2834 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2835 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2836 /* This is the main thread which was added by GDB. The remote
2837 server doesn't know about it. */
2840 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2842 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2844 if (info
&& info
->private)
2845 return info
->private->extra
;
2850 if (use_threadextra_query
)
2853 char *endb
= rs
->buf
+ get_remote_packet_size ();
2855 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2857 write_ptid (b
, endb
, tp
->ptid
);
2860 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2861 if (rs
->buf
[0] != 0)
2863 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2864 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2865 display_buf
[result
] = '\0';
2870 /* If the above query fails, fall back to the old method. */
2871 use_threadextra_query
= 0;
2872 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2873 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2874 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2875 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2876 if (threadinfo
.active
)
2878 if (*threadinfo
.shortname
)
2879 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2880 " Name: %s,", threadinfo
.shortname
);
2881 if (*threadinfo
.display
)
2882 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2883 " State: %s,", threadinfo
.display
);
2884 if (*threadinfo
.more_display
)
2885 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2886 " Priority: %s", threadinfo
.more_display
);
2890 /* For purely cosmetic reasons, clear up trailing commas. */
2891 if (',' == display_buf
[n
-1])
2892 display_buf
[n
-1] = ' ';
2901 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2902 struct static_tracepoint_marker
*marker
)
2904 struct remote_state
*rs
= get_remote_state ();
2907 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2909 p
+= hexnumstr (p
, addr
);
2911 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2915 error (_("Remote failure reply: %s"), p
);
2919 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2926 static VEC(static_tracepoint_marker_p
) *
2927 remote_static_tracepoint_markers_by_strid (const char *strid
)
2929 struct remote_state
*rs
= get_remote_state ();
2930 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2931 struct static_tracepoint_marker
*marker
= NULL
;
2932 struct cleanup
*old_chain
;
2935 /* Ask for a first packet of static tracepoint marker
2938 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2941 error (_("Remote failure reply: %s"), p
);
2943 old_chain
= make_cleanup (free_current_marker
, &marker
);
2948 marker
= XCNEW (struct static_tracepoint_marker
);
2952 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2954 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2956 VEC_safe_push (static_tracepoint_marker_p
,
2962 release_static_tracepoint_marker (marker
);
2963 memset (marker
, 0, sizeof (*marker
));
2966 while (*p
++ == ','); /* comma-separated list */
2967 /* Ask for another packet of static tracepoint definition. */
2969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2973 do_cleanups (old_chain
);
2978 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2981 remote_get_ada_task_ptid (long lwp
, long thread
)
2983 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2987 /* Restart the remote side; this is an extended protocol operation. */
2990 extended_remote_restart (void)
2992 struct remote_state
*rs
= get_remote_state ();
2994 /* Send the restart command; for reasons I don't understand the
2995 remote side really expects a number after the "R". */
2996 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2999 remote_fileio_reset ();
3002 /* Clean up connection to a remote debugger. */
3007 if (remote_desc
== NULL
)
3008 return; /* already closed */
3010 /* Make sure we leave stdin registered in the event loop, and we
3011 don't leave the async SIGINT signal handler installed. */
3012 remote_terminal_ours ();
3014 serial_close (remote_desc
);
3017 /* We don't have a connection to the remote stub anymore. Get rid
3018 of all the inferiors and their threads we were controlling.
3019 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3020 will be unable to find the thread corresponding to (pid, 0, 0). */
3021 inferior_ptid
= null_ptid
;
3022 discard_all_inferiors ();
3024 /* Stop replies may from inferiors which are still unknown to GDB.
3025 We are closing the remote target, so we should discard
3026 everything, including the stop replies from GDB-unknown
3028 discard_pending_stop_replies (NULL
);
3030 if (remote_async_inferior_event_token
)
3031 delete_async_event_handler (&remote_async_inferior_event_token
);
3033 remote_notif_unregister_async_event_handler ();
3036 /* Query the remote side for the text, data and bss offsets. */
3041 struct remote_state
*rs
= get_remote_state ();
3044 int lose
, num_segments
= 0, do_sections
, do_segments
;
3045 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3046 struct section_offsets
*offs
;
3047 struct symfile_segment_data
*data
;
3049 if (symfile_objfile
== NULL
)
3052 putpkt ("qOffsets");
3053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3056 if (buf
[0] == '\000')
3057 return; /* Return silently. Stub doesn't support
3061 warning (_("Remote failure reply: %s"), buf
);
3065 /* Pick up each field in turn. This used to be done with scanf, but
3066 scanf will make trouble if CORE_ADDR size doesn't match
3067 conversion directives correctly. The following code will work
3068 with any size of CORE_ADDR. */
3069 text_addr
= data_addr
= bss_addr
= 0;
3073 if (strncmp (ptr
, "Text=", 5) == 0)
3076 /* Don't use strtol, could lose on big values. */
3077 while (*ptr
&& *ptr
!= ';')
3078 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3080 if (strncmp (ptr
, ";Data=", 6) == 0)
3083 while (*ptr
&& *ptr
!= ';')
3084 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3089 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3092 while (*ptr
&& *ptr
!= ';')
3093 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3095 if (bss_addr
!= data_addr
)
3096 warning (_("Target reported unsupported offsets: %s"), buf
);
3101 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3104 /* Don't use strtol, could lose on big values. */
3105 while (*ptr
&& *ptr
!= ';')
3106 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3109 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3112 while (*ptr
&& *ptr
!= ';')
3113 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3121 error (_("Malformed response to offset query, %s"), buf
);
3122 else if (*ptr
!= '\0')
3123 warning (_("Target reported unsupported offsets: %s"), buf
);
3125 offs
= ((struct section_offsets
*)
3126 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3127 memcpy (offs
, symfile_objfile
->section_offsets
,
3128 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3130 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3131 do_segments
= (data
!= NULL
);
3132 do_sections
= num_segments
== 0;
3134 if (num_segments
> 0)
3136 segments
[0] = text_addr
;
3137 segments
[1] = data_addr
;
3139 /* If we have two segments, we can still try to relocate everything
3140 by assuming that the .text and .data offsets apply to the whole
3141 text and data segments. Convert the offsets given in the packet
3142 to base addresses for symfile_map_offsets_to_segments. */
3143 else if (data
&& data
->num_segments
== 2)
3145 segments
[0] = data
->segment_bases
[0] + text_addr
;
3146 segments
[1] = data
->segment_bases
[1] + data_addr
;
3149 /* If the object file has only one segment, assume that it is text
3150 rather than data; main programs with no writable data are rare,
3151 but programs with no code are useless. Of course the code might
3152 have ended up in the data segment... to detect that we would need
3153 the permissions here. */
3154 else if (data
&& data
->num_segments
== 1)
3156 segments
[0] = data
->segment_bases
[0] + text_addr
;
3159 /* There's no way to relocate by segment. */
3165 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3166 offs
, num_segments
, segments
);
3168 if (ret
== 0 && !do_sections
)
3169 error (_("Can not handle qOffsets TextSeg "
3170 "response with this symbol file"));
3177 free_symfile_segment_data (data
);
3181 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3183 /* This is a temporary kludge to force data and bss to use the
3184 same offsets because that's what nlmconv does now. The real
3185 solution requires changes to the stub and remote.c that I
3186 don't have time to do right now. */
3188 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3189 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3192 objfile_relocate (symfile_objfile
, offs
);
3195 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3196 threads we know are stopped already. This is used during the
3197 initial remote connection in non-stop mode --- threads that are
3198 reported as already being stopped are left stopped. */
3201 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3203 /* If we have a stop reply for this thread, it must be stopped. */
3204 if (peek_stop_reply (thread
->ptid
))
3205 set_stop_requested (thread
->ptid
, 1);
3210 /* Send interrupt_sequence to remote target. */
3212 send_interrupt_sequence (void)
3214 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3215 remote_serial_write ("\x03", 1);
3216 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3217 serial_send_break (remote_desc
);
3218 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3220 serial_send_break (remote_desc
);
3221 remote_serial_write ("g", 1);
3224 internal_error (__FILE__
, __LINE__
,
3225 _("Invalid value for interrupt_sequence_mode: %s."),
3226 interrupt_sequence_mode
);
3230 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3231 and extract the PTID. Returns NULL_PTID if not found. */
3234 stop_reply_extract_thread (char *stop_reply
)
3236 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3240 /* Txx r:val ; r:val (...) */
3243 /* Look for "register" named "thread". */
3248 p1
= strchr (p
, ':');
3252 if (strncmp (p
, "thread", p1
- p
) == 0)
3253 return read_ptid (++p1
, &p
);
3255 p1
= strchr (p
, ';');
3267 /* Query the remote target for which is the current thread/process,
3268 add it to our tables, and update INFERIOR_PTID. The caller is
3269 responsible for setting the state such that the remote end is ready
3270 to return the current thread.
3272 This function is called after handling the '?' or 'vRun' packets,
3273 whose response is a stop reply from which we can also try
3274 extracting the thread. If the target doesn't support the explicit
3275 qC query, we infer the current thread from that stop reply, passed
3276 in in WAIT_STATUS, which may be NULL. */
3279 add_current_inferior_and_thread (char *wait_status
)
3281 struct remote_state
*rs
= get_remote_state ();
3283 ptid_t ptid
= null_ptid
;
3285 inferior_ptid
= null_ptid
;
3287 /* Now, if we have thread information, update inferior_ptid. First
3288 if we have a stop reply handy, maybe it's a T stop reply with a
3289 "thread" register we can extract the current thread from. If
3290 not, ask the remote which is the current thread, with qC. The
3291 former method avoids a roundtrip. Note we don't use
3292 remote_parse_stop_reply as that makes use of the target
3293 architecture, which we haven't yet fully determined at this
3295 if (wait_status
!= NULL
)
3296 ptid
= stop_reply_extract_thread (wait_status
);
3297 if (ptid_equal (ptid
, null_ptid
))
3298 ptid
= remote_current_thread (inferior_ptid
);
3300 if (!ptid_equal (ptid
, null_ptid
))
3302 if (!remote_multi_process_p (rs
))
3305 inferior_ptid
= ptid
;
3309 /* Without this, some commands which require an active target
3310 (such as kill) won't work. This variable serves (at least)
3311 double duty as both the pid of the target process (if it has
3312 such), and as a flag indicating that a target is active. */
3313 inferior_ptid
= magic_null_ptid
;
3317 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3319 /* Add the main thread. */
3320 add_thread_silent (inferior_ptid
);
3324 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3326 struct remote_state
*rs
= get_remote_state ();
3327 struct packet_config
*noack_config
;
3328 char *wait_status
= NULL
;
3330 immediate_quit
++; /* Allow user to interrupt it. */
3333 if (interrupt_on_connect
)
3334 send_interrupt_sequence ();
3336 /* Ack any packet which the remote side has already sent. */
3337 serial_write (remote_desc
, "+", 1);
3339 /* Signal other parts that we're going through the initial setup,
3340 and so things may not be stable yet. */
3341 rs
->starting_up
= 1;
3343 /* The first packet we send to the target is the optional "supported
3344 packets" request. If the target can answer this, it will tell us
3345 which later probes to skip. */
3346 remote_query_supported ();
3348 /* If the stub wants to get a QAllow, compose one and send it. */
3349 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3350 remote_set_permissions ();
3352 /* Next, we possibly activate noack mode.
3354 If the QStartNoAckMode packet configuration is set to AUTO,
3355 enable noack mode if the stub reported a wish for it with
3358 If set to TRUE, then enable noack mode even if the stub didn't
3359 report it in qSupported. If the stub doesn't reply OK, the
3360 session ends with an error.
3362 If FALSE, then don't activate noack mode, regardless of what the
3363 stub claimed should be the default with qSupported. */
3365 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3367 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3368 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3369 && noack_config
->support
== PACKET_ENABLE
))
3371 putpkt ("QStartNoAckMode");
3372 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3373 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3379 /* Tell the remote that we are using the extended protocol. */
3381 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3384 /* Let the target know which signals it is allowed to pass down to
3386 update_signals_program_target ();
3388 /* Next, if the target can specify a description, read it. We do
3389 this before anything involving memory or registers. */
3390 target_find_description ();
3392 /* Next, now that we know something about the target, update the
3393 address spaces in the program spaces. */
3394 update_address_spaces ();
3396 /* On OSs where the list of libraries is global to all
3397 processes, we fetch them early. */
3398 if (gdbarch_has_global_solist (target_gdbarch ()))
3399 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3403 if (!rs
->non_stop_aware
)
3404 error (_("Non-stop mode requested, but remote "
3405 "does not support non-stop"));
3407 putpkt ("QNonStop:1");
3408 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3410 if (strcmp (rs
->buf
, "OK") != 0)
3411 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3413 /* Find about threads and processes the stub is already
3414 controlling. We default to adding them in the running state.
3415 The '?' query below will then tell us about which threads are
3417 remote_threads_info (target
);
3419 else if (rs
->non_stop_aware
)
3421 /* Don't assume that the stub can operate in all-stop mode.
3422 Request it explicitly. */
3423 putpkt ("QNonStop:0");
3424 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3426 if (strcmp (rs
->buf
, "OK") != 0)
3427 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3430 /* Check whether the target is running now. */
3432 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3438 struct inferior
*inf
;
3440 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3443 error (_("The target is not running (try extended-remote?)"));
3445 /* We're connected, but not running. Drop out before we
3446 call start_remote. */
3447 rs
->starting_up
= 0;
3452 /* Save the reply for later. */
3453 wait_status
= alloca (strlen (rs
->buf
) + 1);
3454 strcpy (wait_status
, rs
->buf
);
3457 /* Let the stub know that we want it to return the thread. */
3458 set_continue_thread (minus_one_ptid
);
3460 add_current_inferior_and_thread (wait_status
);
3462 /* init_wait_for_inferior should be called before get_offsets in order
3463 to manage `inserted' flag in bp loc in a correct state.
3464 breakpoint_init_inferior, called from init_wait_for_inferior, set
3465 `inserted' flag to 0, while before breakpoint_re_set, called from
3466 start_remote, set `inserted' flag to 1. In the initialization of
3467 inferior, breakpoint_init_inferior should be called first, and then
3468 breakpoint_re_set can be called. If this order is broken, state of
3469 `inserted' flag is wrong, and cause some problems on breakpoint
3471 init_wait_for_inferior ();
3473 get_offsets (); /* Get text, data & bss offsets. */
3475 /* If we could not find a description using qXfer, and we know
3476 how to do it some other way, try again. This is not
3477 supported for non-stop; it could be, but it is tricky if
3478 there are no stopped threads when we connect. */
3479 if (remote_read_description_p (target
)
3480 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3482 target_clear_description ();
3483 target_find_description ();
3486 /* Use the previously fetched status. */
3487 gdb_assert (wait_status
!= NULL
);
3488 strcpy (rs
->buf
, wait_status
);
3489 rs
->cached_wait_status
= 1;
3492 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3496 /* Clear WFI global state. Do this before finding about new
3497 threads and inferiors, and setting the current inferior.
3498 Otherwise we would clear the proceed status of the current
3499 inferior when we want its stop_soon state to be preserved
3500 (see notice_new_inferior). */
3501 init_wait_for_inferior ();
3503 /* In non-stop, we will either get an "OK", meaning that there
3504 are no stopped threads at this time; or, a regular stop
3505 reply. In the latter case, there may be more than one thread
3506 stopped --- we pull them all out using the vStopped
3508 if (strcmp (rs
->buf
, "OK") != 0)
3510 struct notif_client
*notif
= ¬if_client_stop
;
3512 /* remote_notif_get_pending_replies acks this one, and gets
3514 notif_client_stop
.pending_event
3515 = remote_notif_parse (notif
, rs
->buf
);
3516 remote_notif_get_pending_events (notif
);
3518 /* Make sure that threads that were stopped remain
3520 iterate_over_threads (set_stop_requested_callback
, NULL
);
3523 if (target_can_async_p ())
3524 target_async (inferior_event_handler
, 0);
3526 if (thread_count () == 0)
3529 error (_("The target is not running (try extended-remote?)"));
3531 /* We're connected, but not running. Drop out before we
3532 call start_remote. */
3533 rs
->starting_up
= 0;
3537 /* Let the stub know that we want it to return the thread. */
3539 /* Force the stub to choose a thread. */
3540 set_general_thread (null_ptid
);
3543 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3544 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3545 error (_("remote didn't report the current thread in non-stop mode"));
3547 get_offsets (); /* Get text, data & bss offsets. */
3549 /* In non-stop mode, any cached wait status will be stored in
3550 the stop reply queue. */
3551 gdb_assert (wait_status
== NULL
);
3553 /* Report all signals during attach/startup. */
3554 remote_pass_signals (0, NULL
);
3557 /* If we connected to a live target, do some additional setup. */
3558 if (target_has_execution
)
3560 if (exec_bfd
) /* No use without an exec file. */
3561 remote_check_symbols (symfile_objfile
);
3564 /* Possibly the target has been engaged in a trace run started
3565 previously; find out where things are at. */
3566 if (remote_get_trace_status (current_trace_status ()) != -1)
3568 struct uploaded_tp
*uploaded_tps
= NULL
;
3569 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3571 if (current_trace_status ()->running
)
3572 printf_filtered (_("Trace is already running on the target.\n"));
3574 /* Get trace state variables first, they may be checked when
3575 parsing uploaded commands. */
3577 remote_upload_trace_state_variables (&uploaded_tsvs
);
3579 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3581 remote_upload_tracepoints (&uploaded_tps
);
3583 merge_uploaded_tracepoints (&uploaded_tps
);
3586 /* The thread and inferior lists are now synchronized with the
3587 target, our symbols have been relocated, and we're merged the
3588 target's tracepoints with ours. We're done with basic start
3590 rs
->starting_up
= 0;
3592 /* If breakpoints are global, insert them now. */
3593 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3594 && breakpoints_always_inserted_mode ())
3595 insert_breakpoints ();
3598 /* Open a connection to a remote debugger.
3599 NAME is the filename used for communication. */
3602 remote_open (char *name
, int from_tty
)
3604 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3607 /* Open a connection to a remote debugger using the extended
3608 remote gdb protocol. NAME is the filename used for communication. */
3611 extended_remote_open (char *name
, int from_tty
)
3613 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3616 /* Generic code for opening a connection to a remote target. */
3619 init_all_packet_configs (void)
3623 for (i
= 0; i
< PACKET_MAX
; i
++)
3624 update_packet_config (&remote_protocol_packets
[i
]);
3627 /* Symbol look-up. */
3630 remote_check_symbols (struct objfile
*objfile
)
3632 struct remote_state
*rs
= get_remote_state ();
3633 char *msg
, *reply
, *tmp
;
3634 struct minimal_symbol
*sym
;
3637 /* The remote side has no concept of inferiors that aren't running
3638 yet, it only knows about running processes. If we're connected
3639 but our current inferior is not running, we should not invite the
3640 remote target to request symbol lookups related to its
3641 (unrelated) current process. */
3642 if (!target_has_execution
)
3645 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3648 /* Make sure the remote is pointing at the right process. Note
3649 there's no way to select "no process". */
3650 set_general_process ();
3652 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3653 because we need both at the same time. */
3654 msg
= alloca (get_remote_packet_size ());
3656 /* Invite target to request symbol lookups. */
3658 putpkt ("qSymbol::");
3659 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3660 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3663 while (strncmp (reply
, "qSymbol:", 8) == 0)
3666 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3668 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3670 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3673 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3674 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3676 /* If this is a function address, return the start of code
3677 instead of any data function descriptor. */
3678 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3682 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3683 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3687 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3692 static struct serial
*
3693 remote_serial_open (char *name
)
3695 static int udp_warning
= 0;
3697 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3698 of in ser-tcp.c, because it is the remote protocol assuming that the
3699 serial connection is reliable and not the serial connection promising
3701 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3703 warning (_("The remote protocol may be unreliable over UDP.\n"
3704 "Some events may be lost, rendering further debugging "
3709 return serial_open (name
);
3712 /* Inform the target of our permission settings. The permission flags
3713 work without this, but if the target knows the settings, it can do
3714 a couple things. First, it can add its own check, to catch cases
3715 that somehow manage to get by the permissions checks in target
3716 methods. Second, if the target is wired to disallow particular
3717 settings (for instance, a system in the field that is not set up to
3718 be able to stop at a breakpoint), it can object to any unavailable
3722 remote_set_permissions (void)
3724 struct remote_state
*rs
= get_remote_state ();
3726 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3727 "WriteReg:%x;WriteMem:%x;"
3728 "InsertBreak:%x;InsertTrace:%x;"
3729 "InsertFastTrace:%x;Stop:%x",
3730 may_write_registers
, may_write_memory
,
3731 may_insert_breakpoints
, may_insert_tracepoints
,
3732 may_insert_fast_tracepoints
, may_stop
);
3734 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3736 /* If the target didn't like the packet, warn the user. Do not try
3737 to undo the user's settings, that would just be maddening. */
3738 if (strcmp (rs
->buf
, "OK") != 0)
3739 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3742 /* This type describes each known response to the qSupported
3744 struct protocol_feature
3746 /* The name of this protocol feature. */
3749 /* The default for this protocol feature. */
3750 enum packet_support default_support
;
3752 /* The function to call when this feature is reported, or after
3753 qSupported processing if the feature is not supported.
3754 The first argument points to this structure. The second
3755 argument indicates whether the packet requested support be
3756 enabled, disabled, or probed (or the default, if this function
3757 is being called at the end of processing and this feature was
3758 not reported). The third argument may be NULL; if not NULL, it
3759 is a NUL-terminated string taken from the packet following
3760 this feature's name and an equals sign. */
3761 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3764 /* The corresponding packet for this feature. Only used if
3765 FUNC is remote_supported_packet. */
3770 remote_supported_packet (const struct protocol_feature
*feature
,
3771 enum packet_support support
,
3772 const char *argument
)
3776 warning (_("Remote qSupported response supplied an unexpected value for"
3777 " \"%s\"."), feature
->name
);
3781 if (remote_protocol_packets
[feature
->packet
].support
3782 == PACKET_SUPPORT_UNKNOWN
)
3783 remote_protocol_packets
[feature
->packet
].support
= support
;
3787 remote_packet_size (const struct protocol_feature
*feature
,
3788 enum packet_support support
, const char *value
)
3790 struct remote_state
*rs
= get_remote_state ();
3795 if (support
!= PACKET_ENABLE
)
3798 if (value
== NULL
|| *value
== '\0')
3800 warning (_("Remote target reported \"%s\" without a size."),
3806 packet_size
= strtol (value
, &value_end
, 16);
3807 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3809 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3810 feature
->name
, value
);
3814 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3816 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3817 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3818 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3821 /* Record the new maximum packet size. */
3822 rs
->explicit_packet_size
= packet_size
;
3826 remote_multi_process_feature (const struct protocol_feature
*feature
,
3827 enum packet_support support
, const char *value
)
3829 struct remote_state
*rs
= get_remote_state ();
3831 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3835 remote_non_stop_feature (const struct protocol_feature
*feature
,
3836 enum packet_support support
, const char *value
)
3838 struct remote_state
*rs
= get_remote_state ();
3840 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3844 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3845 enum packet_support support
,
3848 struct remote_state
*rs
= get_remote_state ();
3850 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3854 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3855 enum packet_support support
,
3858 struct remote_state
*rs
= get_remote_state ();
3860 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3864 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3865 enum packet_support support
,
3868 struct remote_state
*rs
= get_remote_state ();
3870 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3874 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3875 enum packet_support support
,
3878 struct remote_state
*rs
= get_remote_state ();
3880 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3884 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3885 enum packet_support support
,
3888 struct remote_state
*rs
= get_remote_state ();
3890 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3894 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3895 enum packet_support support
,
3898 struct remote_state
*rs
= get_remote_state ();
3900 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3904 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3905 enum packet_support support
,
3908 struct remote_state
*rs
= get_remote_state ();
3910 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3914 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3915 enum packet_support support
,
3918 struct remote_state
*rs
= get_remote_state ();
3920 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3924 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3925 enum packet_support support
,
3928 struct remote_state
*rs
= get_remote_state ();
3930 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3933 static struct protocol_feature remote_protocol_features
[] = {
3934 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3935 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3936 PACKET_qXfer_auxv
},
3937 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3938 PACKET_qXfer_features
},
3939 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3940 PACKET_qXfer_libraries
},
3941 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3942 PACKET_qXfer_libraries_svr4
},
3943 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3944 PACKET_qXfer_memory_map
},
3945 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3946 PACKET_qXfer_spu_read
},
3947 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3948 PACKET_qXfer_spu_write
},
3949 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3950 PACKET_qXfer_osdata
},
3951 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3952 PACKET_qXfer_threads
},
3953 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3954 PACKET_qXfer_traceframe_info
},
3955 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3956 PACKET_QPassSignals
},
3957 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3958 PACKET_QProgramSignals
},
3959 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3960 PACKET_QStartNoAckMode
},
3961 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3962 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3963 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3964 PACKET_qXfer_siginfo_read
},
3965 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3966 PACKET_qXfer_siginfo_write
},
3967 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3968 PACKET_ConditionalTracepoints
},
3969 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
3970 PACKET_ConditionalBreakpoints
},
3971 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
3972 PACKET_BreakpointCommands
},
3973 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3974 PACKET_FastTracepoints
},
3975 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3976 PACKET_StaticTracepoints
},
3977 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3978 PACKET_InstallInTrace
},
3979 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3981 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3983 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3985 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3986 PACKET_TracepointSource
},
3987 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3989 { "EnableDisableTracepoints", PACKET_DISABLE
,
3990 remote_enable_disable_tracepoint_feature
, -1 },
3991 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3992 PACKET_qXfer_fdpic
},
3993 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3995 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3996 PACKET_QDisableRandomization
},
3997 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3998 { "QTBuffer:size", PACKET_DISABLE
,
3999 remote_supported_packet
, PACKET_QTBuffer_size
},
4000 { "tracenz", PACKET_DISABLE
,
4001 remote_string_tracing_feature
, -1 },
4002 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4003 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4004 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4005 PACKET_qXfer_btrace
}
4008 static char *remote_support_xml
;
4010 /* Register string appended to "xmlRegisters=" in qSupported query. */
4013 register_remote_support_xml (const char *xml
)
4015 #if defined(HAVE_LIBEXPAT)
4016 if (remote_support_xml
== NULL
)
4017 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4020 char *copy
= xstrdup (remote_support_xml
+ 13);
4021 char *p
= strtok (copy
, ",");
4025 if (strcmp (p
, xml
) == 0)
4032 while ((p
= strtok (NULL
, ",")) != NULL
);
4035 remote_support_xml
= reconcat (remote_support_xml
,
4036 remote_support_xml
, ",", xml
,
4043 remote_query_supported_append (char *msg
, const char *append
)
4046 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4048 return xstrdup (append
);
4052 remote_query_supported (void)
4054 struct remote_state
*rs
= get_remote_state ();
4057 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4059 /* The packet support flags are handled differently for this packet
4060 than for most others. We treat an error, a disabled packet, and
4061 an empty response identically: any features which must be reported
4062 to be used will be automatically disabled. An empty buffer
4063 accomplishes this, since that is also the representation for a list
4064 containing no features. */
4067 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4070 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4072 q
= remote_query_supported_append (q
, "multiprocess+");
4074 if (remote_support_xml
)
4075 q
= remote_query_supported_append (q
, remote_support_xml
);
4077 q
= remote_query_supported_append (q
, "qRelocInsn+");
4079 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4082 do_cleanups (old_chain
);
4084 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4086 /* If an error occured, warn, but do not return - just reset the
4087 buffer to empty and go on to disable features. */
4088 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4091 warning (_("Remote failure reply: %s"), rs
->buf
);
4096 memset (seen
, 0, sizeof (seen
));
4101 enum packet_support is_supported
;
4102 char *p
, *end
, *name_end
, *value
;
4104 /* First separate out this item from the rest of the packet. If
4105 there's another item after this, we overwrite the separator
4106 (terminated strings are much easier to work with). */
4108 end
= strchr (p
, ';');
4111 end
= p
+ strlen (p
);
4121 warning (_("empty item in \"qSupported\" response"));
4126 name_end
= strchr (p
, '=');
4129 /* This is a name=value entry. */
4130 is_supported
= PACKET_ENABLE
;
4131 value
= name_end
+ 1;
4140 is_supported
= PACKET_ENABLE
;
4144 is_supported
= PACKET_DISABLE
;
4148 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4152 warning (_("unrecognized item \"%s\" "
4153 "in \"qSupported\" response"), p
);
4159 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4160 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4162 const struct protocol_feature
*feature
;
4165 feature
= &remote_protocol_features
[i
];
4166 feature
->func (feature
, is_supported
, value
);
4171 /* If we increased the packet size, make sure to increase the global
4172 buffer size also. We delay this until after parsing the entire
4173 qSupported packet, because this is the same buffer we were
4175 if (rs
->buf_size
< rs
->explicit_packet_size
)
4177 rs
->buf_size
= rs
->explicit_packet_size
;
4178 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4181 /* Handle the defaults for unmentioned features. */
4182 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4185 const struct protocol_feature
*feature
;
4187 feature
= &remote_protocol_features
[i
];
4188 feature
->func (feature
, feature
->default_support
, NULL
);
4192 /* Remove any of the remote.c targets from target stack. Upper targets depend
4193 on it so remove them first. */
4196 remote_unpush_target (void)
4198 pop_all_targets_above (process_stratum
- 1);
4202 remote_open_1 (char *name
, int from_tty
,
4203 struct target_ops
*target
, int extended_p
)
4205 struct remote_state
*rs
= get_remote_state ();
4208 error (_("To open a remote debug connection, you need to specify what\n"
4209 "serial device is attached to the remote system\n"
4210 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4212 /* See FIXME above. */
4213 if (!target_async_permitted
)
4214 wait_forever_enabled_p
= 1;
4216 /* If we're connected to a running target, target_preopen will kill it.
4217 Ask this question first, before target_preopen has a chance to kill
4219 if (remote_desc
!= NULL
&& !have_inferiors ())
4222 && !query (_("Already connected to a remote target. Disconnect? ")))
4223 error (_("Still connected."));
4226 /* Here the possibly existing remote target gets unpushed. */
4227 target_preopen (from_tty
);
4229 /* Make sure we send the passed signals list the next time we resume. */
4230 xfree (last_pass_packet
);
4231 last_pass_packet
= NULL
;
4233 /* Make sure we send the program signals list the next time we
4235 xfree (last_program_signals_packet
);
4236 last_program_signals_packet
= NULL
;
4238 remote_fileio_reset ();
4239 reopen_exec_file ();
4242 remote_desc
= remote_serial_open (name
);
4244 perror_with_name (name
);
4246 if (baud_rate
!= -1)
4248 if (serial_setbaudrate (remote_desc
, baud_rate
))
4250 /* The requested speed could not be set. Error out to
4251 top level after closing remote_desc. Take care to
4252 set remote_desc to NULL to avoid closing remote_desc
4254 serial_close (remote_desc
);
4256 perror_with_name (name
);
4260 serial_raw (remote_desc
);
4262 /* If there is something sitting in the buffer we might take it as a
4263 response to a command, which would be bad. */
4264 serial_flush_input (remote_desc
);
4268 puts_filtered ("Remote debugging using ");
4269 puts_filtered (name
);
4270 puts_filtered ("\n");
4272 push_target (target
); /* Switch to using remote target now. */
4274 /* Register extra event sources in the event loop. */
4275 remote_async_inferior_event_token
4276 = create_async_event_handler (remote_async_inferior_event_handler
,
4278 remote_notif_register_async_event_handler ();
4280 /* Reset the target state; these things will be queried either by
4281 remote_query_supported or as they are needed. */
4282 init_all_packet_configs ();
4283 rs
->cached_wait_status
= 0;
4284 rs
->explicit_packet_size
= 0;
4286 rs
->multi_process_aware
= 0;
4287 rs
->extended
= extended_p
;
4288 rs
->non_stop_aware
= 0;
4289 rs
->waiting_for_stop_reply
= 0;
4290 rs
->ctrlc_pending_p
= 0;
4292 general_thread
= not_sent_ptid
;
4293 continue_thread
= not_sent_ptid
;
4294 remote_traceframe_number
= -1;
4296 /* Probe for ability to use "ThreadInfo" query, as required. */
4297 use_threadinfo_query
= 1;
4298 use_threadextra_query
= 1;
4300 if (target_async_permitted
)
4302 /* With this target we start out by owning the terminal. */
4303 remote_async_terminal_ours_p
= 1;
4305 /* FIXME: cagney/1999-09-23: During the initial connection it is
4306 assumed that the target is already ready and able to respond to
4307 requests. Unfortunately remote_start_remote() eventually calls
4308 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4309 around this. Eventually a mechanism that allows
4310 wait_for_inferior() to expect/get timeouts will be
4312 wait_forever_enabled_p
= 0;
4315 /* First delete any symbols previously loaded from shared libraries. */
4316 no_shared_libraries (NULL
, 0);
4319 init_thread_list ();
4321 /* Start the remote connection. If error() or QUIT, discard this
4322 target (we'd otherwise be in an inconsistent state) and then
4323 propogate the error on up the exception chain. This ensures that
4324 the caller doesn't stumble along blindly assuming that the
4325 function succeeded. The CLI doesn't have this problem but other
4326 UI's, such as MI do.
4328 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4329 this function should return an error indication letting the
4330 caller restore the previous state. Unfortunately the command
4331 ``target remote'' is directly wired to this function making that
4332 impossible. On a positive note, the CLI side of this problem has
4333 been fixed - the function set_cmd_context() makes it possible for
4334 all the ``target ....'' commands to share a common callback
4335 function. See cli-dump.c. */
4337 volatile struct gdb_exception ex
;
4339 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4341 remote_start_remote (from_tty
, target
, extended_p
);
4345 /* Pop the partially set up target - unless something else did
4346 already before throwing the exception. */
4347 if (remote_desc
!= NULL
)
4348 remote_unpush_target ();
4349 if (target_async_permitted
)
4350 wait_forever_enabled_p
= 1;
4351 throw_exception (ex
);
4355 if (target_async_permitted
)
4356 wait_forever_enabled_p
= 1;
4359 /* This takes a program previously attached to and detaches it. After
4360 this is done, GDB can be used to debug some other program. We
4361 better not have left any breakpoints in the target program or it'll
4362 die when it hits one. */
4365 remote_detach_1 (char *args
, int from_tty
, int extended
)
4367 int pid
= ptid_get_pid (inferior_ptid
);
4368 struct remote_state
*rs
= get_remote_state ();
4371 error (_("Argument given to \"detach\" when remotely debugging."));
4373 if (!target_has_execution
)
4374 error (_("No process to detach from."));
4378 char *exec_file
= get_exec_file (0);
4379 if (exec_file
== NULL
)
4381 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4382 target_pid_to_str (pid_to_ptid (pid
)));
4383 gdb_flush (gdb_stdout
);
4386 /* Tell the remote target to detach. */
4387 if (remote_multi_process_p (rs
))
4388 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4390 strcpy (rs
->buf
, "D");
4393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4395 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4397 else if (rs
->buf
[0] == '\0')
4398 error (_("Remote doesn't know how to detach"));
4400 error (_("Can't detach process."));
4402 if (from_tty
&& !extended
)
4403 puts_filtered (_("Ending remote debugging.\n"));
4405 target_mourn_inferior ();
4409 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4411 remote_detach_1 (args
, from_tty
, 0);
4415 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4417 remote_detach_1 (args
, from_tty
, 1);
4420 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4423 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4426 error (_("Argument given to \"disconnect\" when remotely debugging."));
4428 /* Make sure we unpush even the extended remote targets; mourn
4429 won't do it. So call remote_mourn_1 directly instead of
4430 target_mourn_inferior. */
4431 remote_mourn_1 (target
);
4434 puts_filtered ("Ending remote debugging.\n");
4437 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4438 be chatty about it. */
4441 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4443 struct remote_state
*rs
= get_remote_state ();
4445 char *wait_status
= NULL
;
4447 pid
= parse_pid_to_attach (args
);
4449 /* Remote PID can be freely equal to getpid, do not check it here the same
4450 way as in other targets. */
4452 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4453 error (_("This target does not support attaching to a process"));
4457 char *exec_file
= get_exec_file (0);
4460 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4461 target_pid_to_str (pid_to_ptid (pid
)));
4463 printf_unfiltered (_("Attaching to %s\n"),
4464 target_pid_to_str (pid_to_ptid (pid
)));
4466 gdb_flush (gdb_stdout
);
4469 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4471 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4473 if (packet_ok (rs
->buf
,
4474 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4478 /* Save the reply for later. */
4479 wait_status
= alloca (strlen (rs
->buf
) + 1);
4480 strcpy (wait_status
, rs
->buf
);
4482 else if (strcmp (rs
->buf
, "OK") != 0)
4483 error (_("Attaching to %s failed with: %s"),
4484 target_pid_to_str (pid_to_ptid (pid
)),
4487 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4488 error (_("This target does not support attaching to a process"));
4490 error (_("Attaching to %s failed"),
4491 target_pid_to_str (pid_to_ptid (pid
)));
4493 set_current_inferior (remote_add_inferior (0, pid
, 1));
4495 inferior_ptid
= pid_to_ptid (pid
);
4499 struct thread_info
*thread
;
4501 /* Get list of threads. */
4502 remote_threads_info (target
);
4504 thread
= first_thread_of_process (pid
);
4506 inferior_ptid
= thread
->ptid
;
4508 inferior_ptid
= pid_to_ptid (pid
);
4510 /* Invalidate our notion of the remote current thread. */
4511 record_currthread (minus_one_ptid
);
4515 /* Now, if we have thread information, update inferior_ptid. */
4516 inferior_ptid
= remote_current_thread (inferior_ptid
);
4518 /* Add the main thread to the thread list. */
4519 add_thread_silent (inferior_ptid
);
4522 /* Next, if the target can specify a description, read it. We do
4523 this before anything involving memory or registers. */
4524 target_find_description ();
4528 /* Use the previously fetched status. */
4529 gdb_assert (wait_status
!= NULL
);
4531 if (target_can_async_p ())
4533 struct notif_event
*reply
4534 = remote_notif_parse (¬if_client_stop
, wait_status
);
4536 push_stop_reply ((struct stop_reply
*) reply
);
4538 target_async (inferior_event_handler
, 0);
4542 gdb_assert (wait_status
!= NULL
);
4543 strcpy (rs
->buf
, wait_status
);
4544 rs
->cached_wait_status
= 1;
4548 gdb_assert (wait_status
== NULL
);
4552 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4554 extended_remote_attach_1 (ops
, args
, from_tty
);
4557 /* Convert hex digit A to a number. */
4562 if (a
>= '0' && a
<= '9')
4564 else if (a
>= 'a' && a
<= 'f')
4565 return a
- 'a' + 10;
4566 else if (a
>= 'A' && a
<= 'F')
4567 return a
- 'A' + 10;
4569 error (_("Reply contains invalid hex digit %d"), a
);
4573 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4577 for (i
= 0; i
< count
; i
++)
4579 if (hex
[0] == 0 || hex
[1] == 0)
4581 /* Hex string is short, or of uneven length.
4582 Return the count that has been converted so far. */
4585 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4591 /* Convert number NIB to a hex digit. */
4599 return 'a' + nib
- 10;
4603 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4607 /* May use a length, or a nul-terminated string as input. */
4609 count
= strlen ((char *) bin
);
4611 for (i
= 0; i
< count
; i
++)
4613 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4614 *hex
++ = tohex (*bin
++ & 0xf);
4620 /* Check for the availability of vCont. This function should also check
4624 remote_vcont_probe (struct remote_state
*rs
)
4628 strcpy (rs
->buf
, "vCont?");
4630 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4633 /* Make sure that the features we assume are supported. */
4634 if (strncmp (buf
, "vCont", 5) == 0)
4637 int support_s
, support_S
, support_c
, support_C
;
4643 rs
->support_vCont_t
= 0;
4644 while (p
&& *p
== ';')
4647 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4649 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4651 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4653 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4655 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4656 rs
->support_vCont_t
= 1;
4658 p
= strchr (p
, ';');
4661 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4662 BUF will make packet_ok disable the packet. */
4663 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4667 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4670 /* Helper function for building "vCont" resumptions. Write a
4671 resumption to P. ENDP points to one-passed-the-end of the buffer
4672 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4673 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4674 resumed thread should be single-stepped and/or signalled. If PTID
4675 equals minus_one_ptid, then all threads are resumed; if PTID
4676 represents a process, then all threads of the process are resumed;
4677 the thread to be stepped and/or signalled is given in the global
4681 append_resumption (char *p
, char *endp
,
4682 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4684 struct remote_state
*rs
= get_remote_state ();
4686 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4687 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4689 p
+= xsnprintf (p
, endp
- p
, ";s");
4690 else if (siggnal
!= GDB_SIGNAL_0
)
4691 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4693 p
+= xsnprintf (p
, endp
- p
, ";c");
4695 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4699 /* All (-1) threads of process. */
4700 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4702 p
+= xsnprintf (p
, endp
- p
, ":");
4703 p
= write_ptid (p
, endp
, nptid
);
4705 else if (!ptid_equal (ptid
, minus_one_ptid
))
4707 p
+= xsnprintf (p
, endp
- p
, ":");
4708 p
= write_ptid (p
, endp
, ptid
);
4714 /* Append a vCont continue-with-signal action for threads that have a
4715 non-zero stop signal. */
4718 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4720 struct thread_info
*thread
;
4722 ALL_THREADS (thread
)
4723 if (ptid_match (thread
->ptid
, ptid
)
4724 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4725 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4726 && signal_pass_state (thread
->suspend
.stop_signal
))
4728 p
= append_resumption (p
, endp
, thread
->ptid
,
4729 0, thread
->suspend
.stop_signal
);
4730 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4736 /* Resume the remote inferior by using a "vCont" packet. The thread
4737 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4738 resumed thread should be single-stepped and/or signalled. If PTID
4739 equals minus_one_ptid, then all threads are resumed; the thread to
4740 be stepped and/or signalled is given in the global INFERIOR_PTID.
4741 This function returns non-zero iff it resumes the inferior.
4743 This function issues a strict subset of all possible vCont commands at the
4747 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4749 struct remote_state
*rs
= get_remote_state ();
4753 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4754 remote_vcont_probe (rs
);
4756 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4760 endp
= rs
->buf
+ get_remote_packet_size ();
4762 /* If we could generate a wider range of packets, we'd have to worry
4763 about overflowing BUF. Should there be a generic
4764 "multi-part-packet" packet? */
4766 p
+= xsnprintf (p
, endp
- p
, "vCont");
4768 if (ptid_equal (ptid
, magic_null_ptid
))
4770 /* MAGIC_NULL_PTID means that we don't have any active threads,
4771 so we don't have any TID numbers the inferior will
4772 understand. Make sure to only send forms that do not specify
4774 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4776 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4778 /* Resume all threads (of all processes, or of a single
4779 process), with preference for INFERIOR_PTID. This assumes
4780 inferior_ptid belongs to the set of all threads we are about
4782 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4784 /* Step inferior_ptid, with or without signal. */
4785 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4788 /* Also pass down any pending signaled resumption for other
4789 threads not the current. */
4790 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4792 /* And continue others without a signal. */
4793 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4797 /* Scheduler locking; resume only PTID. */
4798 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4801 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4806 /* In non-stop, the stub replies to vCont with "OK". The stop
4807 reply will be reported asynchronously by means of a `%Stop'
4809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4810 if (strcmp (rs
->buf
, "OK") != 0)
4811 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4817 /* Tell the remote machine to resume. */
4819 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4821 static int last_sent_step
;
4824 remote_resume (struct target_ops
*ops
,
4825 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4827 struct remote_state
*rs
= get_remote_state ();
4830 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4831 (explained in remote-notif.c:handle_notification) so
4832 remote_notif_process is not called. We need find a place where
4833 it is safe to start a 'vNotif' sequence. It is good to do it
4834 before resuming inferior, because inferior was stopped and no RSP
4835 traffic at that moment. */
4837 remote_notif_process (¬if_client_stop
);
4839 last_sent_signal
= siggnal
;
4840 last_sent_step
= step
;
4842 /* The vCont packet doesn't need to specify threads via Hc. */
4843 /* No reverse support (yet) for vCont. */
4844 if (execution_direction
!= EXEC_REVERSE
)
4845 if (remote_vcont_resume (ptid
, step
, siggnal
))
4848 /* All other supported resume packets do use Hc, so set the continue
4850 if (ptid_equal (ptid
, minus_one_ptid
))
4851 set_continue_thread (any_thread_ptid
);
4853 set_continue_thread (ptid
);
4856 if (execution_direction
== EXEC_REVERSE
)
4858 /* We don't pass signals to the target in reverse exec mode. */
4859 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4860 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4864 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4865 error (_("Remote reverse-step not supported."));
4867 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4868 error (_("Remote reverse-continue not supported."));
4870 strcpy (buf
, step
? "bs" : "bc");
4872 else if (siggnal
!= GDB_SIGNAL_0
)
4874 buf
[0] = step
? 'S' : 'C';
4875 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4876 buf
[2] = tohex (((int) siggnal
) & 0xf);
4880 strcpy (buf
, step
? "s" : "c");
4885 /* We are about to start executing the inferior, let's register it
4886 with the event loop. NOTE: this is the one place where all the
4887 execution commands end up. We could alternatively do this in each
4888 of the execution commands in infcmd.c. */
4889 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4890 into infcmd.c in order to allow inferior function calls to work
4891 NOT asynchronously. */
4892 if (target_can_async_p ())
4893 target_async (inferior_event_handler
, 0);
4895 /* We've just told the target to resume. The remote server will
4896 wait for the inferior to stop, and then send a stop reply. In
4897 the mean time, we can't start another command/query ourselves
4898 because the stub wouldn't be ready to process it. This applies
4899 only to the base all-stop protocol, however. In non-stop (which
4900 only supports vCont), the stub replies with an "OK", and is
4901 immediate able to process further serial input. */
4903 rs
->waiting_for_stop_reply
= 1;
4907 /* Set up the signal handler for SIGINT, while the target is
4908 executing, ovewriting the 'regular' SIGINT signal handler. */
4910 initialize_sigint_signal_handler (void)
4912 signal (SIGINT
, handle_remote_sigint
);
4915 /* Signal handler for SIGINT, while the target is executing. */
4917 handle_remote_sigint (int sig
)
4919 signal (sig
, handle_remote_sigint_twice
);
4920 mark_async_signal_handler (sigint_remote_token
);
4923 /* Signal handler for SIGINT, installed after SIGINT has already been
4924 sent once. It will take effect the second time that the user sends
4927 handle_remote_sigint_twice (int sig
)
4929 signal (sig
, handle_remote_sigint
);
4930 mark_async_signal_handler (sigint_remote_twice_token
);
4933 /* Perform the real interruption of the target execution, in response
4936 async_remote_interrupt (gdb_client_data arg
)
4939 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4941 target_stop (inferior_ptid
);
4944 /* Perform interrupt, if the first attempt did not succeed. Just give
4945 up on the target alltogether. */
4947 async_remote_interrupt_twice (gdb_client_data arg
)
4950 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4955 /* Reinstall the usual SIGINT handlers, after the target has
4958 cleanup_sigint_signal_handler (void *dummy
)
4960 signal (SIGINT
, handle_sigint
);
4963 /* Send ^C to target to halt it. Target will respond, and send us a
4965 static void (*ofunc
) (int);
4967 /* The command line interface's stop routine. This function is installed
4968 as a signal handler for SIGINT. The first time a user requests a
4969 stop, we call remote_stop to send a break or ^C. If there is no
4970 response from the target (it didn't stop when the user requested it),
4971 we ask the user if he'd like to detach from the target. */
4973 remote_interrupt (int signo
)
4975 /* If this doesn't work, try more severe steps. */
4976 signal (signo
, remote_interrupt_twice
);
4978 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4981 /* The user typed ^C twice. */
4984 remote_interrupt_twice (int signo
)
4986 signal (signo
, ofunc
);
4987 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4988 signal (signo
, remote_interrupt
);
4991 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4992 thread, all threads of a remote process, or all threads of all
4996 remote_stop_ns (ptid_t ptid
)
4998 struct remote_state
*rs
= get_remote_state ();
5000 char *endp
= rs
->buf
+ get_remote_packet_size ();
5002 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
5003 remote_vcont_probe (rs
);
5005 if (!rs
->support_vCont_t
)
5006 error (_("Remote server does not support stopping threads"));
5008 if (ptid_equal (ptid
, minus_one_ptid
)
5009 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5010 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5015 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5017 if (ptid_is_pid (ptid
))
5018 /* All (-1) threads of process. */
5019 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5022 /* Small optimization: if we already have a stop reply for
5023 this thread, no use in telling the stub we want this
5025 if (peek_stop_reply (ptid
))
5031 write_ptid (p
, endp
, nptid
);
5034 /* In non-stop, we get an immediate OK reply. The stop reply will
5035 come in asynchronously by notification. */
5037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5038 if (strcmp (rs
->buf
, "OK") != 0)
5039 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5042 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5043 remote target. It is undefined which thread of which process
5044 reports the stop. */
5047 remote_stop_as (ptid_t ptid
)
5049 struct remote_state
*rs
= get_remote_state ();
5051 rs
->ctrlc_pending_p
= 1;
5053 /* If the inferior is stopped already, but the core didn't know
5054 about it yet, just ignore the request. The cached wait status
5055 will be collected in remote_wait. */
5056 if (rs
->cached_wait_status
)
5059 /* Send interrupt_sequence to remote target. */
5060 send_interrupt_sequence ();
5063 /* This is the generic stop called via the target vector. When a target
5064 interrupt is requested, either by the command line or the GUI, we
5065 will eventually end up here. */
5068 remote_stop (ptid_t ptid
)
5071 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5074 remote_stop_ns (ptid
);
5076 remote_stop_as (ptid
);
5079 /* Ask the user what to do when an interrupt is received. */
5082 interrupt_query (void)
5084 target_terminal_ours ();
5086 if (target_can_async_p ())
5088 signal (SIGINT
, handle_sigint
);
5089 deprecated_throw_reason (RETURN_QUIT
);
5093 if (query (_("Interrupted while waiting for the program.\n\
5094 Give up (and stop debugging it)? ")))
5096 remote_unpush_target ();
5097 deprecated_throw_reason (RETURN_QUIT
);
5101 target_terminal_inferior ();
5104 /* Enable/disable target terminal ownership. Most targets can use
5105 terminal groups to control terminal ownership. Remote targets are
5106 different in that explicit transfer of ownership to/from GDB/target
5110 remote_terminal_inferior (void)
5112 if (!target_async_permitted
)
5113 /* Nothing to do. */
5116 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5117 idempotent. The event-loop GDB talking to an asynchronous target
5118 with a synchronous command calls this function from both
5119 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5120 transfer the terminal to the target when it shouldn't this guard
5122 if (!remote_async_terminal_ours_p
)
5124 delete_file_handler (input_fd
);
5125 remote_async_terminal_ours_p
= 0;
5126 initialize_sigint_signal_handler ();
5127 /* NOTE: At this point we could also register our selves as the
5128 recipient of all input. Any characters typed could then be
5129 passed on down to the target. */
5133 remote_terminal_ours (void)
5135 if (!target_async_permitted
)
5136 /* Nothing to do. */
5139 /* See FIXME in remote_terminal_inferior. */
5140 if (remote_async_terminal_ours_p
)
5142 cleanup_sigint_signal_handler (NULL
);
5143 add_file_handler (input_fd
, stdin_event_handler
, 0);
5144 remote_async_terminal_ours_p
= 1;
5148 remote_console_output (char *msg
)
5152 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5155 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5159 fputs_unfiltered (tb
, gdb_stdtarg
);
5161 gdb_flush (gdb_stdtarg
);
5164 typedef struct cached_reg
5167 gdb_byte data
[MAX_REGISTER_SIZE
];
5170 DEF_VEC_O(cached_reg_t
);
5172 typedef struct stop_reply
5174 struct notif_event base
;
5176 /* The identifier of the thread about this event */
5179 struct target_waitstatus ws
;
5181 /* Expedited registers. This makes remote debugging a bit more
5182 efficient for those targets that provide critical registers as
5183 part of their normal status mechanism (as another roundtrip to
5184 fetch them is avoided). */
5185 VEC(cached_reg_t
) *regcache
;
5187 int stopped_by_watchpoint_p
;
5188 CORE_ADDR watch_data_address
;
5196 DECLARE_QUEUE_P (stop_reply_p
);
5197 DEFINE_QUEUE_P (stop_reply_p
);
5198 /* The list of already fetched and acknowledged stop events. This
5199 queue is used for notification Stop, and other notifications
5200 don't need queue for their events, because the notification events
5201 of Stop can't be consumed immediately, so that events should be
5202 queued first, and be consumed by remote_wait_{ns,as} one per
5203 time. Other notifications can consume their events immediately,
5204 so queue is not needed for them. */
5205 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5208 stop_reply_xfree (struct stop_reply
*r
)
5212 VEC_free (cached_reg_t
, r
->regcache
);
5218 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5219 struct notif_event
*event
)
5221 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5225 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5226 struct notif_event
*event
)
5228 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5231 putpkt ((char *) self
->ack_command
);
5233 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5234 /* We got an unknown stop reply. */
5235 error (_("Unknown stop reply"));
5237 push_stop_reply (stop_reply
);
5241 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5243 /* We can't get pending events in remote_notif_process for
5244 notification stop, and we have to do this in remote_wait_ns
5245 instead. If we fetch all queued events from stub, remote stub
5246 may exit and we have no chance to process them back in
5248 mark_async_event_handler (remote_async_inferior_event_token
);
5253 stop_reply_dtr (struct notif_event
*event
)
5255 struct stop_reply
*r
= (struct stop_reply
*) event
;
5257 VEC_free (cached_reg_t
, r
->regcache
);
5260 static struct notif_event
*
5261 remote_notif_stop_alloc_reply (void)
5263 struct notif_event
*r
5264 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5266 r
->dtr
= stop_reply_dtr
;
5271 /* A client of notification Stop. */
5273 struct notif_client notif_client_stop
=
5277 remote_notif_stop_parse
,
5278 remote_notif_stop_ack
,
5279 remote_notif_stop_can_get_pending_events
,
5280 remote_notif_stop_alloc_reply
,
5284 /* A parameter to pass data in and out. */
5286 struct queue_iter_param
5289 struct stop_reply
*output
;
5292 /* Remove all queue elements meet the condition it checks. */
5295 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5296 QUEUE_ITER (stop_reply_p
) *iter
,
5300 struct queue_iter_param
*param
= data
;
5301 struct inferior
*inf
= param
->input
;
5303 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5305 stop_reply_xfree (event
);
5306 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5312 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5313 discard everything. */
5316 discard_pending_stop_replies (struct inferior
*inf
)
5319 struct queue_iter_param param
;
5320 struct stop_reply
*reply
5321 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5323 /* Discard the in-flight notification. */
5326 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5328 stop_reply_xfree (reply
);
5329 notif_client_stop
.pending_event
= NULL
;
5333 param
.output
= NULL
;
5334 /* Discard the stop replies we have already pulled with
5336 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5337 remote_notif_remove_all
, ¶m
);
5340 /* A parameter to pass data in and out. */
5343 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5344 QUEUE_ITER (stop_reply_p
) *iter
,
5348 struct queue_iter_param
*param
= data
;
5349 ptid_t
*ptid
= param
->input
;
5351 if (ptid_match (event
->ptid
, *ptid
))
5353 param
->output
= event
;
5354 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5361 /* Remove the first reply in 'stop_reply_queue' which matches
5364 static struct stop_reply
*
5365 remote_notif_remove_queued_reply (ptid_t ptid
)
5367 struct queue_iter_param param
;
5369 param
.input
= &ptid
;
5370 param
.output
= NULL
;
5372 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5373 remote_notif_remove_once_on_match
, ¶m
);
5375 fprintf_unfiltered (gdb_stdlog
,
5376 "notif: discard queued event: 'Stop' in %s\n",
5377 target_pid_to_str (ptid
));
5379 return param
.output
;
5382 /* Look for a queued stop reply belonging to PTID. If one is found,
5383 remove it from the queue, and return it. Returns NULL if none is
5384 found. If there are still queued events left to process, tell the
5385 event loop to get back to target_wait soon. */
5387 static struct stop_reply
*
5388 queued_stop_reply (ptid_t ptid
)
5390 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5392 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5393 /* There's still at least an event left. */
5394 mark_async_event_handler (remote_async_inferior_event_token
);
5399 /* Push a fully parsed stop reply in the stop reply queue. Since we
5400 know that we now have at least one queued event left to pass to the
5401 core side, tell the event loop to get back to target_wait soon. */
5404 push_stop_reply (struct stop_reply
*new_event
)
5406 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5409 fprintf_unfiltered (gdb_stdlog
,
5410 "notif: push 'Stop' %s to queue %d\n",
5411 target_pid_to_str (new_event
->ptid
),
5412 QUEUE_length (stop_reply_p
,
5415 mark_async_event_handler (remote_async_inferior_event_token
);
5419 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5420 QUEUE_ITER (stop_reply_p
) *iter
,
5421 struct stop_reply
*event
,
5424 ptid_t
*ptid
= data
;
5426 return !(ptid_equal (*ptid
, event
->ptid
)
5427 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5430 /* Returns true if we have a stop reply for PTID. */
5433 peek_stop_reply (ptid_t ptid
)
5435 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5436 stop_reply_match_ptid_and_ws
, &ptid
);
5439 /* Parse the stop reply in BUF. Either the function succeeds, and the
5440 result is stored in EVENT, or throws an error. */
5443 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5445 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5449 event
->ptid
= null_ptid
;
5450 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5451 event
->ws
.value
.integer
= 0;
5452 event
->solibs_changed
= 0;
5453 event
->replay_event
= 0;
5454 event
->stopped_by_watchpoint_p
= 0;
5455 event
->regcache
= NULL
;
5460 case 'T': /* Status with PC, SP, FP, ... */
5461 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5462 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5464 n... = register number
5465 r... = register contents
5468 p
= &buf
[3]; /* after Txx */
5476 /* If the packet contains a register number, save it in
5477 pnum and set p1 to point to the character following it.
5478 Otherwise p1 points to p. */
5480 /* If this packet is an awatch packet, don't parse the 'a'
5481 as a register number. */
5483 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5484 && strncmp (p
, "core", strlen ("core") != 0))
5486 /* Read the ``P'' register number. */
5487 pnum
= strtol (p
, &p_temp
, 16);
5493 if (p1
== p
) /* No register number present here. */
5495 p1
= strchr (p
, ':');
5497 error (_("Malformed packet(a) (missing colon): %s\n\
5500 if (strncmp (p
, "thread", p1
- p
) == 0)
5501 event
->ptid
= read_ptid (++p1
, &p
);
5502 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5503 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5504 || (strncmp (p
, "awatch", p1
- p
) == 0))
5506 event
->stopped_by_watchpoint_p
= 1;
5507 p
= unpack_varlen_hex (++p1
, &addr
);
5508 event
->watch_data_address
= (CORE_ADDR
) addr
;
5510 else if (strncmp (p
, "library", p1
- p
) == 0)
5514 while (*p_temp
&& *p_temp
!= ';')
5517 event
->solibs_changed
= 1;
5520 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5522 /* NO_HISTORY event.
5523 p1 will indicate "begin" or "end", but
5524 it makes no difference for now, so ignore it. */
5525 event
->replay_event
= 1;
5526 p_temp
= strchr (p1
+ 1, ';');
5530 else if (strncmp (p
, "core", p1
- p
) == 0)
5534 p
= unpack_varlen_hex (++p1
, &c
);
5539 /* Silently skip unknown optional info. */
5540 p_temp
= strchr (p1
+ 1, ';');
5547 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5548 cached_reg_t cached_reg
;
5553 error (_("Malformed packet(b) (missing colon): %s\n\
5559 error (_("Remote sent bad register number %s: %s\n\
5561 hex_string (pnum
), p
, buf
);
5563 cached_reg
.num
= reg
->regnum
;
5565 fieldsize
= hex2bin (p
, cached_reg
.data
,
5566 register_size (target_gdbarch (),
5569 if (fieldsize
< register_size (target_gdbarch (),
5571 warning (_("Remote reply is too short: %s"), buf
);
5573 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5577 error (_("Remote register badly formatted: %s\nhere: %s"),
5582 case 'S': /* Old style status, just signal only. */
5583 if (event
->solibs_changed
)
5584 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5585 else if (event
->replay_event
)
5586 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5589 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5590 event
->ws
.value
.sig
= (enum gdb_signal
)
5591 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5594 case 'W': /* Target exited. */
5601 /* GDB used to accept only 2 hex chars here. Stubs should
5602 only send more if they detect GDB supports multi-process
5604 p
= unpack_varlen_hex (&buf
[1], &value
);
5608 /* The remote process exited. */
5609 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5610 event
->ws
.value
.integer
= value
;
5614 /* The remote process exited with a signal. */
5615 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5616 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5619 /* If no process is specified, assume inferior_ptid. */
5620 pid
= ptid_get_pid (inferior_ptid
);
5629 else if (strncmp (p
,
5630 "process:", sizeof ("process:") - 1) == 0)
5634 p
+= sizeof ("process:") - 1;
5635 unpack_varlen_hex (p
, &upid
);
5639 error (_("unknown stop reply packet: %s"), buf
);
5642 error (_("unknown stop reply packet: %s"), buf
);
5643 event
->ptid
= pid_to_ptid (pid
);
5648 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5649 error (_("No process or thread specified in stop reply: %s"), buf
);
5652 /* When the stub wants to tell GDB about a new notification reply, it
5653 sends a notification (%Stop, for example). Those can come it at
5654 any time, hence, we have to make sure that any pending
5655 putpkt/getpkt sequence we're making is finished, before querying
5656 the stub for more events with the corresponding ack command
5657 (vStopped, for example). E.g., if we started a vStopped sequence
5658 immediately upon receiving the notification, something like this
5666 1.6) <-- (registers reply to step #1.3)
5668 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5671 To solve this, whenever we parse a %Stop notification successfully,
5672 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5673 doing whatever we were doing:
5679 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5680 2.5) <-- (registers reply to step #2.3)
5682 Eventualy after step #2.5, we return to the event loop, which
5683 notices there's an event on the
5684 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5685 associated callback --- the function below. At this point, we're
5686 always safe to start a vStopped sequence. :
5689 2.7) <-- T05 thread:2
5695 remote_notif_get_pending_events (struct notif_client
*nc
)
5697 struct remote_state
*rs
= get_remote_state ();
5699 if (nc
->pending_event
)
5702 fprintf_unfiltered (gdb_stdlog
,
5703 "notif: process: '%s' ack pending event\n",
5707 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5708 nc
->pending_event
= NULL
;
5712 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5713 if (strcmp (rs
->buf
, "OK") == 0)
5716 remote_notif_ack (nc
, rs
->buf
);
5722 fprintf_unfiltered (gdb_stdlog
,
5723 "notif: process: '%s' no pending reply\n",
5728 /* Called when it is decided that STOP_REPLY holds the info of the
5729 event that is to be returned to the core. This function always
5730 destroys STOP_REPLY. */
5733 process_stop_reply (struct stop_reply
*stop_reply
,
5734 struct target_waitstatus
*status
)
5738 *status
= stop_reply
->ws
;
5739 ptid
= stop_reply
->ptid
;
5741 /* If no thread/process was reported by the stub, assume the current
5743 if (ptid_equal (ptid
, null_ptid
))
5744 ptid
= inferior_ptid
;
5746 if (status
->kind
!= TARGET_WAITKIND_EXITED
5747 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5749 /* Expedited registers. */
5750 if (stop_reply
->regcache
)
5752 struct regcache
*regcache
5753 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5758 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5760 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5761 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5764 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5765 remote_watch_data_address
= stop_reply
->watch_data_address
;
5767 remote_notice_new_inferior (ptid
, 0);
5768 demand_private_info (ptid
)->core
= stop_reply
->core
;
5771 stop_reply_xfree (stop_reply
);
5775 /* The non-stop mode version of target_wait. */
5778 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5780 struct remote_state
*rs
= get_remote_state ();
5781 struct stop_reply
*stop_reply
;
5785 /* If in non-stop mode, get out of getpkt even if a
5786 notification is received. */
5788 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5789 0 /* forever */, &is_notif
);
5792 if (ret
!= -1 && !is_notif
)
5795 case 'E': /* Error of some sort. */
5796 /* We're out of sync with the target now. Did it continue
5797 or not? We can't tell which thread it was in non-stop,
5798 so just ignore this. */
5799 warning (_("Remote failure reply: %s"), rs
->buf
);
5801 case 'O': /* Console output. */
5802 remote_console_output (rs
->buf
+ 1);
5805 warning (_("Invalid remote reply: %s"), rs
->buf
);
5809 /* Acknowledge a pending stop reply that may have arrived in the
5811 if (notif_client_stop
.pending_event
!= NULL
)
5812 remote_notif_get_pending_events (¬if_client_stop
);
5814 /* If indeed we noticed a stop reply, we're done. */
5815 stop_reply
= queued_stop_reply (ptid
);
5816 if (stop_reply
!= NULL
)
5817 return process_stop_reply (stop_reply
, status
);
5819 /* Still no event. If we're just polling for an event, then
5820 return to the event loop. */
5821 if (options
& TARGET_WNOHANG
)
5823 status
->kind
= TARGET_WAITKIND_IGNORE
;
5824 return minus_one_ptid
;
5827 /* Otherwise do a blocking wait. */
5828 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5829 1 /* forever */, &is_notif
);
5833 /* Wait until the remote machine stops, then return, storing status in
5834 STATUS just as `wait' would. */
5837 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5839 struct remote_state
*rs
= get_remote_state ();
5840 ptid_t event_ptid
= null_ptid
;
5842 struct stop_reply
*stop_reply
;
5846 status
->kind
= TARGET_WAITKIND_IGNORE
;
5847 status
->value
.integer
= 0;
5849 stop_reply
= queued_stop_reply (ptid
);
5850 if (stop_reply
!= NULL
)
5851 return process_stop_reply (stop_reply
, status
);
5853 if (rs
->cached_wait_status
)
5854 /* Use the cached wait status, but only once. */
5855 rs
->cached_wait_status
= 0;
5861 if (!target_is_async_p ())
5863 ofunc
= signal (SIGINT
, remote_interrupt
);
5864 /* If the user hit C-c before this packet, or between packets,
5865 pretend that it was hit right here. */
5866 if (check_quit_flag ())
5869 remote_interrupt (SIGINT
);
5873 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5874 _never_ wait for ever -> test on target_is_async_p().
5875 However, before we do that we need to ensure that the caller
5876 knows how to take the target into/out of async mode. */
5877 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5878 wait_forever_enabled_p
, &is_notif
);
5880 /* GDB gets a notification. Return to core as this event is
5882 if (ret
!= -1 && is_notif
)
5883 return minus_one_ptid
;
5885 if (!target_is_async_p ())
5886 signal (SIGINT
, ofunc
);
5891 remote_stopped_by_watchpoint_p
= 0;
5893 /* We got something. */
5894 rs
->waiting_for_stop_reply
= 0;
5896 /* Assume that the target has acknowledged Ctrl-C unless we receive
5897 an 'F' or 'O' packet. */
5898 if (buf
[0] != 'F' && buf
[0] != 'O')
5899 rs
->ctrlc_pending_p
= 0;
5903 case 'E': /* Error of some sort. */
5904 /* We're out of sync with the target now. Did it continue or
5905 not? Not is more likely, so report a stop. */
5906 warning (_("Remote failure reply: %s"), buf
);
5907 status
->kind
= TARGET_WAITKIND_STOPPED
;
5908 status
->value
.sig
= GDB_SIGNAL_0
;
5910 case 'F': /* File-I/O request. */
5911 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5912 rs
->ctrlc_pending_p
= 0;
5914 case 'T': case 'S': case 'X': case 'W':
5916 struct stop_reply
*stop_reply
5917 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
5920 event_ptid
= process_stop_reply (stop_reply
, status
);
5923 case 'O': /* Console output. */
5924 remote_console_output (buf
+ 1);
5926 /* The target didn't really stop; keep waiting. */
5927 rs
->waiting_for_stop_reply
= 1;
5931 if (last_sent_signal
!= GDB_SIGNAL_0
)
5933 /* Zero length reply means that we tried 'S' or 'C' and the
5934 remote system doesn't support it. */
5935 target_terminal_ours_for_output ();
5937 ("Can't send signals to this remote system. %s not sent.\n",
5938 gdb_signal_to_name (last_sent_signal
));
5939 last_sent_signal
= GDB_SIGNAL_0
;
5940 target_terminal_inferior ();
5942 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5943 putpkt ((char *) buf
);
5945 /* We just told the target to resume, so a stop reply is in
5947 rs
->waiting_for_stop_reply
= 1;
5950 /* else fallthrough */
5952 warning (_("Invalid remote reply: %s"), buf
);
5954 rs
->waiting_for_stop_reply
= 1;
5958 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5960 /* Nothing interesting happened. If we're doing a non-blocking
5961 poll, we're done. Otherwise, go back to waiting. */
5962 if (options
& TARGET_WNOHANG
)
5963 return minus_one_ptid
;
5967 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5968 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5970 if (!ptid_equal (event_ptid
, null_ptid
))
5971 record_currthread (event_ptid
);
5973 event_ptid
= inferior_ptid
;
5976 /* A process exit. Invalidate our notion of current thread. */
5977 record_currthread (minus_one_ptid
);
5982 /* Wait until the remote machine stops, then return, storing status in
5983 STATUS just as `wait' would. */
5986 remote_wait (struct target_ops
*ops
,
5987 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5992 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5994 event_ptid
= remote_wait_as (ptid
, status
, options
);
5996 if (target_can_async_p ())
5998 /* If there are are events left in the queue tell the event loop
6000 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6001 mark_async_event_handler (remote_async_inferior_event_token
);
6007 /* Fetch a single register using a 'p' packet. */
6010 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6012 struct remote_state
*rs
= get_remote_state ();
6014 char regp
[MAX_REGISTER_SIZE
];
6017 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6020 if (reg
->pnum
== -1)
6025 p
+= hexnumstr (p
, reg
->pnum
);
6028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6032 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6036 case PACKET_UNKNOWN
:
6039 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6040 gdbarch_register_name (get_regcache_arch (regcache
),
6045 /* If this register is unfetchable, tell the regcache. */
6048 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6052 /* Otherwise, parse and supply the value. */
6058 error (_("fetch_register_using_p: early buf termination"));
6060 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6063 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6067 /* Fetch the registers included in the target's 'g' packet. */
6070 send_g_packet (void)
6072 struct remote_state
*rs
= get_remote_state ();
6075 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6076 remote_send (&rs
->buf
, &rs
->buf_size
);
6078 /* We can get out of synch in various cases. If the first character
6079 in the buffer is not a hex character, assume that has happened
6080 and try to fetch another packet to read. */
6081 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6082 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6083 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6084 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6087 fprintf_unfiltered (gdb_stdlog
,
6088 "Bad register packet; fetching a new packet\n");
6089 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6092 buf_len
= strlen (rs
->buf
);
6094 /* Sanity check the received packet. */
6095 if (buf_len
% 2 != 0)
6096 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6102 process_g_packet (struct regcache
*regcache
)
6104 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6105 struct remote_state
*rs
= get_remote_state ();
6106 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6111 buf_len
= strlen (rs
->buf
);
6113 /* Further sanity checks, with knowledge of the architecture. */
6114 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6115 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6117 /* Save the size of the packet sent to us by the target. It is used
6118 as a heuristic when determining the max size of packets that the
6119 target can safely receive. */
6120 if (rsa
->actual_register_packet_size
== 0)
6121 rsa
->actual_register_packet_size
= buf_len
;
6123 /* If this is smaller than we guessed the 'g' packet would be,
6124 update our records. A 'g' reply that doesn't include a register's
6125 value implies either that the register is not available, or that
6126 the 'p' packet must be used. */
6127 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6129 rsa
->sizeof_g_packet
= buf_len
/ 2;
6131 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6133 if (rsa
->regs
[i
].pnum
== -1)
6136 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6137 rsa
->regs
[i
].in_g_packet
= 0;
6139 rsa
->regs
[i
].in_g_packet
= 1;
6143 regs
= alloca (rsa
->sizeof_g_packet
);
6145 /* Unimplemented registers read as all bits zero. */
6146 memset (regs
, 0, rsa
->sizeof_g_packet
);
6148 /* Reply describes registers byte by byte, each byte encoded as two
6149 hex characters. Suck them all up, then supply them to the
6150 register cacheing/storage mechanism. */
6153 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6155 if (p
[0] == 0 || p
[1] == 0)
6156 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6157 internal_error (__FILE__
, __LINE__
,
6158 _("unexpected end of 'g' packet reply"));
6160 if (p
[0] == 'x' && p
[1] == 'x')
6161 regs
[i
] = 0; /* 'x' */
6163 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6167 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6169 struct packet_reg
*r
= &rsa
->regs
[i
];
6173 if (r
->offset
* 2 >= strlen (rs
->buf
))
6174 /* This shouldn't happen - we adjusted in_g_packet above. */
6175 internal_error (__FILE__
, __LINE__
,
6176 _("unexpected end of 'g' packet reply"));
6177 else if (rs
->buf
[r
->offset
* 2] == 'x')
6179 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6180 /* The register isn't available, mark it as such (at
6181 the same time setting the value to zero). */
6182 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6185 regcache_raw_supply (regcache
, r
->regnum
,
6192 fetch_registers_using_g (struct regcache
*regcache
)
6195 process_g_packet (regcache
);
6198 /* Make the remote selected traceframe match GDB's selected
6202 set_remote_traceframe (void)
6206 if (remote_traceframe_number
== get_traceframe_number ())
6209 /* Avoid recursion, remote_trace_find calls us again. */
6210 remote_traceframe_number
= get_traceframe_number ();
6212 newnum
= target_trace_find (tfind_number
,
6213 get_traceframe_number (), 0, 0, NULL
);
6215 /* Should not happen. If it does, all bets are off. */
6216 if (newnum
!= get_traceframe_number ())
6217 warning (_("could not set remote traceframe"));
6221 remote_fetch_registers (struct target_ops
*ops
,
6222 struct regcache
*regcache
, int regnum
)
6224 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6227 set_remote_traceframe ();
6228 set_general_thread (inferior_ptid
);
6232 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6234 gdb_assert (reg
!= NULL
);
6236 /* If this register might be in the 'g' packet, try that first -
6237 we are likely to read more than one register. If this is the
6238 first 'g' packet, we might be overly optimistic about its
6239 contents, so fall back to 'p'. */
6240 if (reg
->in_g_packet
)
6242 fetch_registers_using_g (regcache
);
6243 if (reg
->in_g_packet
)
6247 if (fetch_register_using_p (regcache
, reg
))
6250 /* This register is not available. */
6251 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6256 fetch_registers_using_g (regcache
);
6258 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6259 if (!rsa
->regs
[i
].in_g_packet
)
6260 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6262 /* This register is not available. */
6263 regcache_raw_supply (regcache
, i
, NULL
);
6267 /* Prepare to store registers. Since we may send them all (using a
6268 'G' request), we have to read out the ones we don't want to change
6272 remote_prepare_to_store (struct regcache
*regcache
)
6274 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6276 gdb_byte buf
[MAX_REGISTER_SIZE
];
6278 /* Make sure the entire registers array is valid. */
6279 switch (remote_protocol_packets
[PACKET_P
].support
)
6281 case PACKET_DISABLE
:
6282 case PACKET_SUPPORT_UNKNOWN
:
6283 /* Make sure all the necessary registers are cached. */
6284 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6285 if (rsa
->regs
[i
].in_g_packet
)
6286 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6293 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6294 packet was not recognized. */
6297 store_register_using_P (const struct regcache
*regcache
,
6298 struct packet_reg
*reg
)
6300 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6301 struct remote_state
*rs
= get_remote_state ();
6302 /* Try storing a single register. */
6303 char *buf
= rs
->buf
;
6304 gdb_byte regp
[MAX_REGISTER_SIZE
];
6307 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6310 if (reg
->pnum
== -1)
6313 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6314 p
= buf
+ strlen (buf
);
6315 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6316 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6318 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6320 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6325 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6326 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6327 case PACKET_UNKNOWN
:
6330 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6334 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6335 contents of the register cache buffer. FIXME: ignores errors. */
6338 store_registers_using_G (const struct regcache
*regcache
)
6340 struct remote_state
*rs
= get_remote_state ();
6341 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6345 /* Extract all the registers in the regcache copying them into a
6350 regs
= alloca (rsa
->sizeof_g_packet
);
6351 memset (regs
, 0, rsa
->sizeof_g_packet
);
6352 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6354 struct packet_reg
*r
= &rsa
->regs
[i
];
6357 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6361 /* Command describes registers byte by byte,
6362 each byte encoded as two hex characters. */
6365 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6367 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6369 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6370 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6371 error (_("Could not write registers; remote failure reply '%s'"),
6375 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6376 of the register cache buffer. FIXME: ignores errors. */
6379 remote_store_registers (struct target_ops
*ops
,
6380 struct regcache
*regcache
, int regnum
)
6382 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6385 set_remote_traceframe ();
6386 set_general_thread (inferior_ptid
);
6390 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6392 gdb_assert (reg
!= NULL
);
6394 /* Always prefer to store registers using the 'P' packet if
6395 possible; we often change only a small number of registers.
6396 Sometimes we change a larger number; we'd need help from a
6397 higher layer to know to use 'G'. */
6398 if (store_register_using_P (regcache
, reg
))
6401 /* For now, don't complain if we have no way to write the
6402 register. GDB loses track of unavailable registers too
6403 easily. Some day, this may be an error. We don't have
6404 any way to read the register, either... */
6405 if (!reg
->in_g_packet
)
6408 store_registers_using_G (regcache
);
6412 store_registers_using_G (regcache
);
6414 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6415 if (!rsa
->regs
[i
].in_g_packet
)
6416 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6417 /* See above for why we do not issue an error here. */
6422 /* Return the number of hex digits in num. */
6425 hexnumlen (ULONGEST num
)
6429 for (i
= 0; num
!= 0; i
++)
6435 /* Set BUF to the minimum number of hex digits representing NUM. */
6438 hexnumstr (char *buf
, ULONGEST num
)
6440 int len
= hexnumlen (num
);
6442 return hexnumnstr (buf
, num
, len
);
6446 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6449 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6455 for (i
= width
- 1; i
>= 0; i
--)
6457 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6464 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6467 remote_address_masked (CORE_ADDR addr
)
6469 unsigned int address_size
= remote_address_size
;
6471 /* If "remoteaddresssize" was not set, default to target address size. */
6473 address_size
= gdbarch_addr_bit (target_gdbarch ());
6475 if (address_size
> 0
6476 && address_size
< (sizeof (ULONGEST
) * 8))
6478 /* Only create a mask when that mask can safely be constructed
6479 in a ULONGEST variable. */
6482 mask
= (mask
<< address_size
) - 1;
6488 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6489 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6490 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6491 (which may be more than *OUT_LEN due to escape characters). The
6492 total number of bytes in the output buffer will be at most
6496 remote_escape_output (const gdb_byte
*buffer
, int len
,
6497 gdb_byte
*out_buf
, int *out_len
,
6500 int input_index
, output_index
;
6503 for (input_index
= 0; input_index
< len
; input_index
++)
6505 gdb_byte b
= buffer
[input_index
];
6507 if (b
== '$' || b
== '#' || b
== '}')
6509 /* These must be escaped. */
6510 if (output_index
+ 2 > out_maxlen
)
6512 out_buf
[output_index
++] = '}';
6513 out_buf
[output_index
++] = b
^ 0x20;
6517 if (output_index
+ 1 > out_maxlen
)
6519 out_buf
[output_index
++] = b
;
6523 *out_len
= input_index
;
6524 return output_index
;
6527 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6528 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6529 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6531 This function reverses remote_escape_output. It allows more
6532 escaped characters than that function does, in particular because
6533 '*' must be escaped to avoid the run-length encoding processing
6534 in reading packets. */
6537 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6538 gdb_byte
*out_buf
, int out_maxlen
)
6540 int input_index
, output_index
;
6545 for (input_index
= 0; input_index
< len
; input_index
++)
6547 gdb_byte b
= buffer
[input_index
];
6549 if (output_index
+ 1 > out_maxlen
)
6551 warning (_("Received too much data from remote target;"
6552 " ignoring overflow."));
6553 return output_index
;
6558 out_buf
[output_index
++] = b
^ 0x20;
6564 out_buf
[output_index
++] = b
;
6568 error (_("Unmatched escape character in target response."));
6570 return output_index
;
6573 /* Determine whether the remote target supports binary downloading.
6574 This is accomplished by sending a no-op memory write of zero length
6575 to the target at the specified address. It does not suffice to send
6576 the whole packet, since many stubs strip the eighth bit and
6577 subsequently compute a wrong checksum, which causes real havoc with
6580 NOTE: This can still lose if the serial line is not eight-bit
6581 clean. In cases like this, the user should clear "remote
6585 check_binary_download (CORE_ADDR addr
)
6587 struct remote_state
*rs
= get_remote_state ();
6589 switch (remote_protocol_packets
[PACKET_X
].support
)
6591 case PACKET_DISABLE
:
6595 case PACKET_SUPPORT_UNKNOWN
:
6601 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6603 p
+= hexnumstr (p
, (ULONGEST
) 0);
6607 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6608 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6610 if (rs
->buf
[0] == '\0')
6613 fprintf_unfiltered (gdb_stdlog
,
6614 "binary downloading NOT "
6615 "supported by target\n");
6616 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6621 fprintf_unfiltered (gdb_stdlog
,
6622 "binary downloading supported by target\n");
6623 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6630 /* Write memory data directly to the remote machine.
6631 This does not inform the data cache; the data cache uses this.
6632 HEADER is the starting part of the packet.
6633 MEMADDR is the address in the remote memory space.
6634 MYADDR is the address of the buffer in our space.
6635 LEN is the number of bytes.
6636 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6637 should send data as binary ('X'), or hex-encoded ('M').
6639 The function creates packet of the form
6640 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6642 where encoding of <DATA> is termined by PACKET_FORMAT.
6644 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6647 Returns the number of bytes transferred, or 0 (setting errno) for
6648 error. Only transfer a single packet. */
6651 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6652 const gdb_byte
*myaddr
, ssize_t len
,
6653 char packet_format
, int use_length
)
6655 struct remote_state
*rs
= get_remote_state ();
6665 if (packet_format
!= 'X' && packet_format
!= 'M')
6666 internal_error (__FILE__
, __LINE__
,
6667 _("remote_write_bytes_aux: bad packet format"));
6672 payload_size
= get_memory_write_packet_size ();
6674 /* The packet buffer will be large enough for the payload;
6675 get_memory_packet_size ensures this. */
6678 /* Compute the size of the actual payload by subtracting out the
6679 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6681 payload_size
-= strlen ("$,:#NN");
6683 /* The comma won't be used. */
6685 header_length
= strlen (header
);
6686 payload_size
-= header_length
;
6687 payload_size
-= hexnumlen (memaddr
);
6689 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6691 strcat (rs
->buf
, header
);
6692 p
= rs
->buf
+ strlen (header
);
6694 /* Compute a best guess of the number of bytes actually transfered. */
6695 if (packet_format
== 'X')
6697 /* Best guess at number of bytes that will fit. */
6698 todo
= min (len
, payload_size
);
6700 payload_size
-= hexnumlen (todo
);
6701 todo
= min (todo
, payload_size
);
6705 /* Num bytes that will fit. */
6706 todo
= min (len
, payload_size
/ 2);
6708 payload_size
-= hexnumlen (todo
);
6709 todo
= min (todo
, payload_size
/ 2);
6713 internal_error (__FILE__
, __LINE__
,
6714 _("minimum packet size too small to write data"));
6716 /* If we already need another packet, then try to align the end
6717 of this packet to a useful boundary. */
6718 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6719 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6721 /* Append "<memaddr>". */
6722 memaddr
= remote_address_masked (memaddr
);
6723 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6730 /* Append <len>. Retain the location/size of <len>. It may need to
6731 be adjusted once the packet body has been created. */
6733 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6741 /* Append the packet body. */
6742 if (packet_format
== 'X')
6744 /* Binary mode. Send target system values byte by byte, in
6745 increasing byte addresses. Only escape certain critical
6747 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6750 /* If not all TODO bytes fit, then we'll need another packet. Make
6751 a second try to keep the end of the packet aligned. Don't do
6752 this if the packet is tiny. */
6753 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6757 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6759 if (new_nr_bytes
!= nr_bytes
)
6760 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6765 p
+= payload_length
;
6766 if (use_length
&& nr_bytes
< todo
)
6768 /* Escape chars have filled up the buffer prematurely,
6769 and we have actually sent fewer bytes than planned.
6770 Fix-up the length field of the packet. Use the same
6771 number of characters as before. */
6772 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6773 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6778 /* Normal mode: Send target system values byte by byte, in
6779 increasing byte addresses. Each byte is encoded as a two hex
6781 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6785 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6786 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6788 if (rs
->buf
[0] == 'E')
6790 /* There is no correspondance between what the remote protocol
6791 uses for errors and errno codes. We would like a cleaner way
6792 of representing errors (big enough to include errno codes,
6793 bfd_error codes, and others). But for now just return EIO. */
6798 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6799 fewer bytes than we'd planned. */
6803 /* Write memory data directly to the remote machine.
6804 This does not inform the data cache; the data cache uses this.
6805 MEMADDR is the address in the remote memory space.
6806 MYADDR is the address of the buffer in our space.
6807 LEN is the number of bytes.
6809 Returns number of bytes transferred, or 0 (setting errno) for
6810 error. Only transfer a single packet. */
6813 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6815 char *packet_format
= 0;
6817 /* Check whether the target supports binary download. */
6818 check_binary_download (memaddr
);
6820 switch (remote_protocol_packets
[PACKET_X
].support
)
6823 packet_format
= "X";
6825 case PACKET_DISABLE
:
6826 packet_format
= "M";
6828 case PACKET_SUPPORT_UNKNOWN
:
6829 internal_error (__FILE__
, __LINE__
,
6830 _("remote_write_bytes: bad internal state"));
6832 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6835 return remote_write_bytes_aux (packet_format
,
6836 memaddr
, myaddr
, len
, packet_format
[0], 1);
6839 /* Read memory data directly from the remote machine.
6840 This does not use the data cache; the data cache uses this.
6841 MEMADDR is the address in the remote memory space.
6842 MYADDR is the address of the buffer in our space.
6843 LEN is the number of bytes.
6845 Returns number of bytes transferred, or 0 for error. */
6848 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6850 struct remote_state
*rs
= get_remote_state ();
6851 int max_buf_size
; /* Max size of packet output buffer. */
6859 max_buf_size
= get_memory_read_packet_size ();
6860 /* The packet buffer will be large enough for the payload;
6861 get_memory_packet_size ensures this. */
6863 /* Number if bytes that will fit. */
6864 todo
= min (len
, max_buf_size
/ 2);
6866 /* Construct "m"<memaddr>","<len>". */
6867 memaddr
= remote_address_masked (memaddr
);
6870 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6872 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6875 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6876 if (rs
->buf
[0] == 'E'
6877 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6878 && rs
->buf
[3] == '\0')
6880 /* There is no correspondance between what the remote protocol
6881 uses for errors and errno codes. We would like a cleaner way
6882 of representing errors (big enough to include errno codes,
6883 bfd_error codes, and others). But for now just return
6888 /* Reply describes memory byte by byte, each byte encoded as two hex
6891 i
= hex2bin (p
, myaddr
, todo
);
6892 /* Return what we have. Let higher layers handle partial reads. */
6897 /* Read or write LEN bytes from inferior memory at MEMADDR,
6898 transferring to or from debugger address BUFFER. Write to inferior
6899 if SHOULD_WRITE is nonzero. Returns length of data written or
6900 read; 0 for error. TARGET is unused. */
6903 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6904 int should_write
, struct mem_attrib
*attrib
,
6905 struct target_ops
*target
)
6909 set_remote_traceframe ();
6910 set_general_thread (inferior_ptid
);
6913 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6915 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6920 /* Sends a packet with content determined by the printf format string
6921 FORMAT and the remaining arguments, then gets the reply. Returns
6922 whether the packet was a success, a failure, or unknown. */
6924 static enum packet_result
6925 remote_send_printf (const char *format
, ...)
6927 struct remote_state
*rs
= get_remote_state ();
6928 int max_size
= get_remote_packet_size ();
6931 va_start (ap
, format
);
6934 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6935 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6937 if (putpkt (rs
->buf
) < 0)
6938 error (_("Communication problem with target."));
6941 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6943 return packet_check_result (rs
->buf
);
6947 restore_remote_timeout (void *p
)
6949 int value
= *(int *)p
;
6951 remote_timeout
= value
;
6954 /* Flash writing can take quite some time. We'll set
6955 effectively infinite timeout for flash operations.
6956 In future, we'll need to decide on a better approach. */
6957 static const int remote_flash_timeout
= 1000;
6960 remote_flash_erase (struct target_ops
*ops
,
6961 ULONGEST address
, LONGEST length
)
6963 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
6964 int saved_remote_timeout
= remote_timeout
;
6965 enum packet_result ret
;
6966 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6967 &saved_remote_timeout
);
6969 remote_timeout
= remote_flash_timeout
;
6971 ret
= remote_send_printf ("vFlashErase:%s,%s",
6972 phex (address
, addr_size
),
6976 case PACKET_UNKNOWN
:
6977 error (_("Remote target does not support flash erase"));
6979 error (_("Error erasing flash with vFlashErase packet"));
6984 do_cleanups (back_to
);
6988 remote_flash_write (struct target_ops
*ops
,
6989 ULONGEST address
, LONGEST length
,
6990 const gdb_byte
*data
)
6992 int saved_remote_timeout
= remote_timeout
;
6994 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6995 &saved_remote_timeout
);
6997 remote_timeout
= remote_flash_timeout
;
6998 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6999 do_cleanups (back_to
);
7005 remote_flash_done (struct target_ops
*ops
)
7007 int saved_remote_timeout
= remote_timeout
;
7009 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7010 &saved_remote_timeout
);
7012 remote_timeout
= remote_flash_timeout
;
7013 ret
= remote_send_printf ("vFlashDone");
7014 do_cleanups (back_to
);
7018 case PACKET_UNKNOWN
:
7019 error (_("Remote target does not support vFlashDone"));
7021 error (_("Error finishing flash operation"));
7028 remote_files_info (struct target_ops
*ignore
)
7030 puts_filtered ("Debugging a target over a serial line.\n");
7033 /* Stuff for dealing with the packets which are part of this protocol.
7034 See comment at top of file for details. */
7036 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7037 error to higher layers. Called when a serial error is detected.
7038 The exception message is STRING, followed by a colon and a blank,
7039 the system error message for errno at function entry and final dot
7040 for output compatibility with throw_perror_with_name. */
7043 unpush_and_perror (const char *string
)
7045 int saved_errno
= errno
;
7047 remote_unpush_target ();
7048 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7049 safe_strerror (saved_errno
));
7052 /* Read a single character from the remote end. */
7055 readchar (int timeout
)
7059 ch
= serial_readchar (remote_desc
, timeout
);
7064 switch ((enum serial_rc
) ch
)
7067 remote_unpush_target ();
7068 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7071 unpush_and_perror (_("Remote communication error. "
7072 "Target disconnected."));
7074 case SERIAL_TIMEOUT
:
7080 /* Wrapper for serial_write that closes the target and throws if
7084 remote_serial_write (const char *str
, int len
)
7086 if (serial_write (remote_desc
, str
, len
))
7088 unpush_and_perror (_("Remote communication error. "
7089 "Target disconnected."));
7093 /* Send the command in *BUF to the remote machine, and read the reply
7094 into *BUF. Report an error if we get an error reply. Resize
7095 *BUF using xrealloc if necessary to hold the result, and update
7099 remote_send (char **buf
,
7103 getpkt (buf
, sizeof_buf
, 0);
7105 if ((*buf
)[0] == 'E')
7106 error (_("Remote failure reply: %s"), *buf
);
7109 /* Return a pointer to an xmalloc'ed string representing an escaped
7110 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7111 etc. The caller is responsible for releasing the returned
7115 escape_buffer (const char *buf
, int n
)
7117 struct cleanup
*old_chain
;
7118 struct ui_file
*stb
;
7121 stb
= mem_fileopen ();
7122 old_chain
= make_cleanup_ui_file_delete (stb
);
7124 fputstrn_unfiltered (buf
, n
, 0, stb
);
7125 str
= ui_file_xstrdup (stb
, NULL
);
7126 do_cleanups (old_chain
);
7130 /* Display a null-terminated packet on stdout, for debugging, using C
7134 print_packet (char *buf
)
7136 puts_filtered ("\"");
7137 fputstr_filtered (buf
, '"', gdb_stdout
);
7138 puts_filtered ("\"");
7144 return putpkt_binary (buf
, strlen (buf
));
7147 /* Send a packet to the remote machine, with error checking. The data
7148 of the packet is in BUF. The string in BUF can be at most
7149 get_remote_packet_size () - 5 to account for the $, # and checksum,
7150 and for a possible /0 if we are debugging (remote_debug) and want
7151 to print the sent packet as a string. */
7154 putpkt_binary (char *buf
, int cnt
)
7156 struct remote_state
*rs
= get_remote_state ();
7158 unsigned char csum
= 0;
7159 char *buf2
= alloca (cnt
+ 6);
7166 /* Catch cases like trying to read memory or listing threads while
7167 we're waiting for a stop reply. The remote server wouldn't be
7168 ready to handle this request, so we'd hang and timeout. We don't
7169 have to worry about this in synchronous mode, because in that
7170 case it's not possible to issue a command while the target is
7171 running. This is not a problem in non-stop mode, because in that
7172 case, the stub is always ready to process serial input. */
7173 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7174 error (_("Cannot execute this command while the target is running."));
7176 /* We're sending out a new packet. Make sure we don't look at a
7177 stale cached response. */
7178 rs
->cached_wait_status
= 0;
7180 /* Copy the packet into buffer BUF2, encapsulating it
7181 and giving it a checksum. */
7186 for (i
= 0; i
< cnt
; i
++)
7192 *p
++ = tohex ((csum
>> 4) & 0xf);
7193 *p
++ = tohex (csum
& 0xf);
7195 /* Send it over and over until we get a positive ack. */
7199 int started_error_output
= 0;
7203 struct cleanup
*old_chain
;
7207 str
= escape_buffer (buf2
, p
- buf2
);
7208 old_chain
= make_cleanup (xfree
, str
);
7209 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7210 gdb_flush (gdb_stdlog
);
7211 do_cleanups (old_chain
);
7213 remote_serial_write (buf2
, p
- buf2
);
7215 /* If this is a no acks version of the remote protocol, send the
7216 packet and move on. */
7220 /* Read until either a timeout occurs (-2) or '+' is read.
7221 Handle any notification that arrives in the mean time. */
7224 ch
= readchar (remote_timeout
);
7232 case SERIAL_TIMEOUT
:
7235 if (started_error_output
)
7237 putchar_unfiltered ('\n');
7238 started_error_output
= 0;
7247 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7251 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7253 case SERIAL_TIMEOUT
:
7257 break; /* Retransmit buffer. */
7261 fprintf_unfiltered (gdb_stdlog
,
7262 "Packet instead of Ack, ignoring it\n");
7263 /* It's probably an old response sent because an ACK
7264 was lost. Gobble up the packet and ack it so it
7265 doesn't get retransmitted when we resend this
7268 remote_serial_write ("+", 1);
7269 continue; /* Now, go look for +. */
7276 /* If we got a notification, handle it, and go back to looking
7278 /* We've found the start of a notification. Now
7279 collect the data. */
7280 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7285 struct cleanup
*old_chain
;
7288 str
= escape_buffer (rs
->buf
, val
);
7289 old_chain
= make_cleanup (xfree
, str
);
7290 fprintf_unfiltered (gdb_stdlog
,
7291 " Notification received: %s\n",
7293 do_cleanups (old_chain
);
7295 handle_notification (rs
->buf
);
7296 /* We're in sync now, rewait for the ack. */
7303 if (!started_error_output
)
7305 started_error_output
= 1;
7306 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7308 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7309 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7318 if (!started_error_output
)
7320 started_error_output
= 1;
7321 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7323 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7327 break; /* Here to retransmit. */
7331 /* This is wrong. If doing a long backtrace, the user should be
7332 able to get out next time we call QUIT, without anything as
7333 violent as interrupt_query. If we want to provide a way out of
7334 here without getting to the next QUIT, it should be based on
7335 hitting ^C twice as in remote_wait. */
7346 /* Come here after finding the start of a frame when we expected an
7347 ack. Do our best to discard the rest of this packet. */
7356 c
= readchar (remote_timeout
);
7359 case SERIAL_TIMEOUT
:
7360 /* Nothing we can do. */
7363 /* Discard the two bytes of checksum and stop. */
7364 c
= readchar (remote_timeout
);
7366 c
= readchar (remote_timeout
);
7369 case '*': /* Run length encoding. */
7370 /* Discard the repeat count. */
7371 c
= readchar (remote_timeout
);
7376 /* A regular character. */
7382 /* Come here after finding the start of the frame. Collect the rest
7383 into *BUF, verifying the checksum, length, and handling run-length
7384 compression. NUL terminate the buffer. If there is not enough room,
7385 expand *BUF using xrealloc.
7387 Returns -1 on error, number of characters in buffer (ignoring the
7388 trailing NULL) on success. (could be extended to return one of the
7389 SERIAL status indications). */
7392 read_frame (char **buf_p
,
7399 struct remote_state
*rs
= get_remote_state ();
7406 c
= readchar (remote_timeout
);
7409 case SERIAL_TIMEOUT
:
7411 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7415 fputs_filtered ("Saw new packet start in middle of old one\n",
7417 return -1; /* Start a new packet, count retries. */
7420 unsigned char pktcsum
;
7426 check_0
= readchar (remote_timeout
);
7428 check_1
= readchar (remote_timeout
);
7430 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7433 fputs_filtered ("Timeout in checksum, retrying\n",
7437 else if (check_0
< 0 || check_1
< 0)
7440 fputs_filtered ("Communication error in checksum\n",
7445 /* Don't recompute the checksum; with no ack packets we
7446 don't have any way to indicate a packet retransmission
7451 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7452 if (csum
== pktcsum
)
7457 struct cleanup
*old_chain
;
7460 str
= escape_buffer (buf
, bc
);
7461 old_chain
= make_cleanup (xfree
, str
);
7462 fprintf_unfiltered (gdb_stdlog
,
7463 "Bad checksum, sentsum=0x%x, "
7464 "csum=0x%x, buf=%s\n",
7465 pktcsum
, csum
, str
);
7466 do_cleanups (old_chain
);
7468 /* Number of characters in buffer ignoring trailing
7472 case '*': /* Run length encoding. */
7477 c
= readchar (remote_timeout
);
7479 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7481 /* The character before ``*'' is repeated. */
7483 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7485 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7487 /* Make some more room in the buffer. */
7488 *sizeof_buf
+= repeat
;
7489 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7493 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7499 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7503 if (bc
>= *sizeof_buf
- 1)
7505 /* Make some more room in the buffer. */
7507 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7518 /* Read a packet from the remote machine, with error checking, and
7519 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7520 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7521 rather than timing out; this is used (in synchronous mode) to wait
7522 for a target that is is executing user code to stop. */
7523 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7524 don't have to change all the calls to getpkt to deal with the
7525 return value, because at the moment I don't know what the right
7526 thing to do it for those. */
7534 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7538 /* Read a packet from the remote machine, with error checking, and
7539 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7540 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7541 rather than timing out; this is used (in synchronous mode) to wait
7542 for a target that is is executing user code to stop. If FOREVER ==
7543 0, this function is allowed to time out gracefully and return an
7544 indication of this to the caller. Otherwise return the number of
7545 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7546 enough reason to return to the caller. *IS_NOTIF is an output
7547 boolean that indicates whether *BUF holds a notification or not
7548 (a regular packet). */
7551 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7552 int expecting_notif
, int *is_notif
)
7554 struct remote_state
*rs
= get_remote_state ();
7560 /* We're reading a new response. Make sure we don't look at a
7561 previously cached response. */
7562 rs
->cached_wait_status
= 0;
7564 strcpy (*buf
, "timeout");
7567 timeout
= watchdog
> 0 ? watchdog
: -1;
7568 else if (expecting_notif
)
7569 timeout
= 0; /* There should already be a char in the buffer. If
7572 timeout
= remote_timeout
;
7576 /* Process any number of notifications, and then return when
7580 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7582 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7584 /* This can loop forever if the remote side sends us
7585 characters continuously, but if it pauses, we'll get
7586 SERIAL_TIMEOUT from readchar because of timeout. Then
7587 we'll count that as a retry.
7589 Note that even when forever is set, we will only wait
7590 forever prior to the start of a packet. After that, we
7591 expect characters to arrive at a brisk pace. They should
7592 show up within remote_timeout intervals. */
7594 c
= readchar (timeout
);
7595 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7597 if (c
== SERIAL_TIMEOUT
)
7599 if (expecting_notif
)
7600 return -1; /* Don't complain, it's normal to not get
7601 anything in this case. */
7603 if (forever
) /* Watchdog went off? Kill the target. */
7606 remote_unpush_target ();
7607 throw_error (TARGET_CLOSE_ERROR
,
7608 _("Watchdog timeout has expired. "
7609 "Target detached."));
7612 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7616 /* We've found the start of a packet or notification.
7617 Now collect the data. */
7618 val
= read_frame (buf
, sizeof_buf
);
7623 remote_serial_write ("-", 1);
7626 if (tries
> MAX_TRIES
)
7628 /* We have tried hard enough, and just can't receive the
7629 packet/notification. Give up. */
7630 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7632 /* Skip the ack char if we're in no-ack mode. */
7633 if (!rs
->noack_mode
)
7634 remote_serial_write ("+", 1);
7638 /* If we got an ordinary packet, return that to our caller. */
7643 struct cleanup
*old_chain
;
7646 str
= escape_buffer (*buf
, val
);
7647 old_chain
= make_cleanup (xfree
, str
);
7648 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7649 do_cleanups (old_chain
);
7652 /* Skip the ack char if we're in no-ack mode. */
7653 if (!rs
->noack_mode
)
7654 remote_serial_write ("+", 1);
7655 if (is_notif
!= NULL
)
7660 /* If we got a notification, handle it, and go back to looking
7664 gdb_assert (c
== '%');
7668 struct cleanup
*old_chain
;
7671 str
= escape_buffer (*buf
, val
);
7672 old_chain
= make_cleanup (xfree
, str
);
7673 fprintf_unfiltered (gdb_stdlog
,
7674 " Notification received: %s\n",
7676 do_cleanups (old_chain
);
7678 if (is_notif
!= NULL
)
7681 handle_notification (*buf
);
7683 /* Notifications require no acknowledgement. */
7685 if (expecting_notif
)
7692 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7694 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7698 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7701 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7706 /* A helper function that just calls putpkt; for type correctness. */
7709 putpkt_for_catch_errors (void *arg
)
7711 return putpkt (arg
);
7715 remote_kill (struct target_ops
*ops
)
7717 /* Use catch_errors so the user can quit from gdb even when we
7718 aren't on speaking terms with the remote system. */
7719 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7721 /* Don't wait for it to die. I'm not really sure it matters whether
7722 we do or not. For the existing stubs, kill is a noop. */
7723 target_mourn_inferior ();
7727 remote_vkill (int pid
, struct remote_state
*rs
)
7729 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7732 /* Tell the remote target to detach. */
7733 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7735 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7737 if (packet_ok (rs
->buf
,
7738 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7740 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7747 extended_remote_kill (struct target_ops
*ops
)
7750 int pid
= ptid_get_pid (inferior_ptid
);
7751 struct remote_state
*rs
= get_remote_state ();
7753 res
= remote_vkill (pid
, rs
);
7754 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7756 /* Don't try 'k' on a multi-process aware stub -- it has no way
7757 to specify the pid. */
7761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7762 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7765 /* Don't wait for it to die. I'm not really sure it matters whether
7766 we do or not. For the existing stubs, kill is a noop. */
7772 error (_("Can't kill process"));
7774 target_mourn_inferior ();
7778 remote_mourn (struct target_ops
*ops
)
7780 remote_mourn_1 (ops
);
7783 /* Worker function for remote_mourn. */
7785 remote_mourn_1 (struct target_ops
*target
)
7787 unpush_target (target
);
7789 /* remote_close takes care of doing most of the clean up. */
7790 generic_mourn_inferior ();
7794 extended_remote_mourn_1 (struct target_ops
*target
)
7796 struct remote_state
*rs
= get_remote_state ();
7798 /* In case we got here due to an error, but we're going to stay
7800 rs
->waiting_for_stop_reply
= 0;
7802 /* If the current general thread belonged to the process we just
7803 detached from or has exited, the remote side current general
7804 thread becomes undefined. Considering a case like this:
7806 - We just got here due to a detach.
7807 - The process that we're detaching from happens to immediately
7808 report a global breakpoint being hit in non-stop mode, in the
7809 same thread we had selected before.
7810 - GDB attaches to this process again.
7811 - This event happens to be the next event we handle.
7813 GDB would consider that the current general thread didn't need to
7814 be set on the stub side (with Hg), since for all it knew,
7815 GENERAL_THREAD hadn't changed.
7817 Notice that although in all-stop mode, the remote server always
7818 sets the current thread to the thread reporting the stop event,
7819 that doesn't happen in non-stop mode; in non-stop, the stub *must
7820 not* change the current thread when reporting a breakpoint hit,
7821 due to the decoupling of event reporting and event handling.
7823 To keep things simple, we always invalidate our notion of the
7825 record_currthread (minus_one_ptid
);
7827 /* Unlike "target remote", we do not want to unpush the target; then
7828 the next time the user says "run", we won't be connected. */
7830 /* Call common code to mark the inferior as not running. */
7831 generic_mourn_inferior ();
7833 if (!have_inferiors ())
7835 if (!remote_multi_process_p (rs
))
7837 /* Check whether the target is running now - some remote stubs
7838 automatically restart after kill. */
7840 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7842 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7844 /* Assume that the target has been restarted. Set
7845 inferior_ptid so that bits of core GDB realizes
7846 there's something here, e.g., so that the user can
7847 say "kill" again. */
7848 inferior_ptid
= magic_null_ptid
;
7855 extended_remote_mourn (struct target_ops
*ops
)
7857 extended_remote_mourn_1 (ops
);
7861 extended_remote_supports_disable_randomization (void)
7863 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7868 extended_remote_disable_randomization (int val
)
7870 struct remote_state
*rs
= get_remote_state ();
7873 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7876 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7878 error (_("Target does not support QDisableRandomization."));
7879 if (strcmp (reply
, "OK") != 0)
7880 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7884 extended_remote_run (char *args
)
7886 struct remote_state
*rs
= get_remote_state ();
7889 /* If the user has disabled vRun support, or we have detected that
7890 support is not available, do not try it. */
7891 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7894 strcpy (rs
->buf
, "vRun;");
7895 len
= strlen (rs
->buf
);
7897 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7898 error (_("Remote file name too long for run packet"));
7899 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7901 gdb_assert (args
!= NULL
);
7904 struct cleanup
*back_to
;
7908 argv
= gdb_buildargv (args
);
7909 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7910 for (i
= 0; argv
[i
] != NULL
; i
++)
7912 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7913 error (_("Argument list too long for run packet"));
7914 rs
->buf
[len
++] = ';';
7915 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7917 do_cleanups (back_to
);
7920 rs
->buf
[len
++] = '\0';
7923 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7925 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7927 /* We have a wait response. All is well. */
7930 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7931 /* It wasn't disabled before, but it is now. */
7935 if (remote_exec_file
[0] == '\0')
7936 error (_("Running the default executable on the remote target failed; "
7937 "try \"set remote exec-file\"?"));
7939 error (_("Running \"%s\" on the remote target failed"),
7944 /* In the extended protocol we want to be able to do things like
7945 "run" and have them basically work as expected. So we need
7946 a special create_inferior function. We support changing the
7947 executable file and the command line arguments, but not the
7951 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7952 char **env
, int from_tty
)
7956 struct remote_state
*rs
= get_remote_state ();
7958 /* If running asynchronously, register the target file descriptor
7959 with the event loop. */
7960 if (target_can_async_p ())
7961 target_async (inferior_event_handler
, 0);
7963 /* Disable address space randomization if requested (and supported). */
7964 if (extended_remote_supports_disable_randomization ())
7965 extended_remote_disable_randomization (disable_randomization
);
7967 /* Now restart the remote server. */
7968 run_worked
= extended_remote_run (args
) != -1;
7971 /* vRun was not supported. Fail if we need it to do what the
7973 if (remote_exec_file
[0])
7974 error (_("Remote target does not support \"set remote exec-file\""));
7976 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7978 /* Fall back to "R". */
7979 extended_remote_restart ();
7982 if (!have_inferiors ())
7984 /* Clean up from the last time we ran, before we mark the target
7985 running again. This will mark breakpoints uninserted, and
7986 get_offsets may insert breakpoints. */
7987 init_thread_list ();
7988 init_wait_for_inferior ();
7991 /* vRun's success return is a stop reply. */
7992 stop_reply
= run_worked
? rs
->buf
: NULL
;
7993 add_current_inferior_and_thread (stop_reply
);
7995 /* Get updated offsets, if the stub uses qOffsets. */
8000 extended_remote_create_inferior (struct target_ops
*ops
,
8001 char *exec_file
, char *args
,
8002 char **env
, int from_tty
)
8004 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
8008 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8009 the list of conditions (in agent expression bytecode format), if any, the
8010 target needs to evaluate. The output is placed into the packet buffer
8011 started from BUF and ended at BUF_END. */
8014 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8015 struct bp_target_info
*bp_tgt
, char *buf
,
8018 struct agent_expr
*aexpr
= NULL
;
8021 char *buf_start
= buf
;
8023 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8026 buf
+= strlen (buf
);
8027 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8030 /* Send conditions to the target and free the vector. */
8032 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8035 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8036 buf
+= strlen (buf
);
8037 for (i
= 0; i
< aexpr
->len
; ++i
)
8038 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8042 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8047 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8048 struct bp_target_info
*bp_tgt
, char *buf
)
8050 struct agent_expr
*aexpr
= NULL
;
8053 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8056 buf
+= strlen (buf
);
8058 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8059 buf
+= strlen (buf
);
8061 /* Concatenate all the agent expressions that are commands into the
8064 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8067 sprintf (buf
, "X%x,", aexpr
->len
);
8068 buf
+= strlen (buf
);
8069 for (i
= 0; i
< aexpr
->len
; ++i
)
8070 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8074 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8077 /* Insert a breakpoint. On targets that have software breakpoint
8078 support, we ask the remote target to do the work; on targets
8079 which don't, we insert a traditional memory breakpoint. */
8082 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8083 struct bp_target_info
*bp_tgt
)
8085 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8086 If it succeeds, then set the support to PACKET_ENABLE. If it
8087 fails, and the user has explicitly requested the Z support then
8088 report an error, otherwise, mark it disabled and go on. */
8090 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8092 CORE_ADDR addr
= bp_tgt
->placed_address
;
8093 struct remote_state
*rs
;
8096 struct condition_list
*cond
= NULL
;
8098 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8100 rs
= get_remote_state ();
8102 endbuf
= rs
->buf
+ get_remote_packet_size ();
8107 addr
= (ULONGEST
) remote_address_masked (addr
);
8108 p
+= hexnumstr (p
, addr
);
8109 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8111 if (remote_supports_cond_breakpoints ())
8112 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8114 if (remote_can_run_breakpoint_commands ())
8115 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8120 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8125 bp_tgt
->placed_address
= addr
;
8126 bp_tgt
->placed_size
= bpsize
;
8128 case PACKET_UNKNOWN
:
8133 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8137 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8138 struct bp_target_info
*bp_tgt
)
8140 CORE_ADDR addr
= bp_tgt
->placed_address
;
8141 struct remote_state
*rs
= get_remote_state ();
8143 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8146 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8152 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8153 p
+= hexnumstr (p
, addr
);
8154 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8157 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8159 return (rs
->buf
[0] == 'E');
8162 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8166 watchpoint_to_Z_packet (int type
)
8171 return Z_PACKET_WRITE_WP
;
8174 return Z_PACKET_READ_WP
;
8177 return Z_PACKET_ACCESS_WP
;
8180 internal_error (__FILE__
, __LINE__
,
8181 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8186 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8187 struct expression
*cond
)
8189 struct remote_state
*rs
= get_remote_state ();
8190 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8192 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8194 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8197 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8198 p
= strchr (rs
->buf
, '\0');
8199 addr
= remote_address_masked (addr
);
8200 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8201 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8204 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8206 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8210 case PACKET_UNKNOWN
:
8215 internal_error (__FILE__
, __LINE__
,
8216 _("remote_insert_watchpoint: reached end of function"));
8220 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8221 CORE_ADDR start
, int length
)
8223 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8225 return diff
< length
;
8230 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8231 struct expression
*cond
)
8233 struct remote_state
*rs
= get_remote_state ();
8234 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8236 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8238 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8241 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8242 p
= strchr (rs
->buf
, '\0');
8243 addr
= remote_address_masked (addr
);
8244 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8245 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8247 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8249 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8252 case PACKET_UNKNOWN
:
8257 internal_error (__FILE__
, __LINE__
,
8258 _("remote_remove_watchpoint: reached end of function"));
8262 int remote_hw_watchpoint_limit
= -1;
8263 int remote_hw_watchpoint_length_limit
= -1;
8264 int remote_hw_breakpoint_limit
= -1;
8267 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8269 if (remote_hw_watchpoint_length_limit
== 0)
8271 else if (remote_hw_watchpoint_length_limit
< 0)
8273 else if (len
<= remote_hw_watchpoint_length_limit
)
8280 remote_check_watch_resources (int type
, int cnt
, int ot
)
8282 if (type
== bp_hardware_breakpoint
)
8284 if (remote_hw_breakpoint_limit
== 0)
8286 else if (remote_hw_breakpoint_limit
< 0)
8288 else if (cnt
<= remote_hw_breakpoint_limit
)
8293 if (remote_hw_watchpoint_limit
== 0)
8295 else if (remote_hw_watchpoint_limit
< 0)
8299 else if (cnt
<= remote_hw_watchpoint_limit
)
8306 remote_stopped_by_watchpoint (void)
8308 return remote_stopped_by_watchpoint_p
;
8312 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8316 if (remote_stopped_by_watchpoint ())
8318 *addr_p
= remote_watch_data_address
;
8327 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8328 struct bp_target_info
*bp_tgt
)
8331 struct remote_state
*rs
;
8335 /* The length field should be set to the size of a breakpoint
8336 instruction, even though we aren't inserting one ourselves. */
8338 gdbarch_remote_breakpoint_from_pc
8339 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8341 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8344 rs
= get_remote_state ();
8346 endbuf
= rs
->buf
+ get_remote_packet_size ();
8352 addr
= remote_address_masked (bp_tgt
->placed_address
);
8353 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8354 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8356 if (remote_supports_cond_breakpoints ())
8357 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8359 if (remote_can_run_breakpoint_commands ())
8360 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8363 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8365 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8368 if (rs
->buf
[1] == '.')
8370 message
= strchr (rs
->buf
+ 2, '.');
8372 error (_("Remote failure reply: %s"), message
+ 1);
8375 case PACKET_UNKNOWN
:
8380 internal_error (__FILE__
, __LINE__
,
8381 _("remote_insert_hw_breakpoint: reached end of function"));
8386 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8387 struct bp_target_info
*bp_tgt
)
8390 struct remote_state
*rs
= get_remote_state ();
8392 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8394 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8401 addr
= remote_address_masked (bp_tgt
->placed_address
);
8402 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8403 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8406 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8408 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8411 case PACKET_UNKNOWN
:
8416 internal_error (__FILE__
, __LINE__
,
8417 _("remote_remove_hw_breakpoint: reached end of function"));
8420 /* Table used by the crc32 function to calcuate the checksum. */
8422 static unsigned long crc32_table
[256] =
8425 static unsigned long
8426 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8428 if (!crc32_table
[1])
8430 /* Initialize the CRC table and the decoding table. */
8434 for (i
= 0; i
< 256; i
++)
8436 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8437 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8444 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8450 /* Verify memory using the "qCRC:" request. */
8453 remote_verify_memory (struct target_ops
*ops
,
8454 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8456 struct remote_state
*rs
= get_remote_state ();
8457 unsigned long host_crc
, target_crc
;
8460 /* FIXME: assumes lma can fit into long. */
8461 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8462 (long) lma
, (long) size
);
8465 /* Be clever; compute the host_crc before waiting for target
8467 host_crc
= crc32 (data
, size
, 0xffffffff);
8469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8470 if (rs
->buf
[0] == 'E')
8473 if (rs
->buf
[0] != 'C')
8474 error (_("remote target does not support this operation"));
8476 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8477 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8479 return (host_crc
== target_crc
);
8482 /* compare-sections command
8484 With no arguments, compares each loadable section in the exec bfd
8485 with the same memory range on the target, and reports mismatches.
8486 Useful for verifying the image on the target against the exec file. */
8489 compare_sections_command (char *args
, int from_tty
)
8492 struct cleanup
*old_chain
;
8494 const char *sectname
;
8502 error (_("command cannot be used without an exec file"));
8504 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8506 if (!(s
->flags
& SEC_LOAD
))
8507 continue; /* Skip non-loadable section. */
8509 size
= bfd_get_section_size (s
);
8511 continue; /* Skip zero-length section. */
8513 sectname
= bfd_get_section_name (exec_bfd
, s
);
8514 if (args
&& strcmp (args
, sectname
) != 0)
8515 continue; /* Not the section selected by user. */
8517 matched
= 1; /* Do this section. */
8520 sectdata
= xmalloc (size
);
8521 old_chain
= make_cleanup (xfree
, sectdata
);
8522 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8524 res
= target_verify_memory (sectdata
, lma
, size
);
8527 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8528 paddress (target_gdbarch (), lma
),
8529 paddress (target_gdbarch (), lma
+ size
));
8531 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8532 paddress (target_gdbarch (), lma
),
8533 paddress (target_gdbarch (), lma
+ size
));
8535 printf_filtered ("matched.\n");
8538 printf_filtered ("MIS-MATCHED!\n");
8542 do_cleanups (old_chain
);
8545 warning (_("One or more sections of the remote executable does not match\n\
8546 the loaded file\n"));
8547 if (args
&& !matched
)
8548 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8551 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8552 into remote target. The number of bytes written to the remote
8553 target is returned, or -1 for error. */
8556 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8557 const char *annex
, const gdb_byte
*writebuf
,
8558 ULONGEST offset
, LONGEST len
,
8559 struct packet_config
*packet
)
8563 struct remote_state
*rs
= get_remote_state ();
8564 int max_size
= get_memory_write_packet_size ();
8566 if (packet
->support
== PACKET_DISABLE
)
8569 /* Insert header. */
8570 i
= snprintf (rs
->buf
, max_size
,
8571 "qXfer:%s:write:%s:%s:",
8572 object_name
, annex
? annex
: "",
8573 phex_nz (offset
, sizeof offset
));
8574 max_size
-= (i
+ 1);
8576 /* Escape as much data as fits into rs->buf. */
8577 buf_len
= remote_escape_output
8578 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8580 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8581 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8582 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8585 unpack_varlen_hex (rs
->buf
, &n
);
8589 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8590 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8591 number of bytes read is returned, or 0 for EOF, or -1 for error.
8592 The number of bytes read may be less than LEN without indicating an
8593 EOF. PACKET is checked and updated to indicate whether the remote
8594 target supports this object. */
8597 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8599 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8600 struct packet_config
*packet
)
8602 static char *finished_object
;
8603 static char *finished_annex
;
8604 static ULONGEST finished_offset
;
8606 struct remote_state
*rs
= get_remote_state ();
8607 LONGEST i
, n
, packet_len
;
8609 if (packet
->support
== PACKET_DISABLE
)
8612 /* Check whether we've cached an end-of-object packet that matches
8614 if (finished_object
)
8616 if (strcmp (object_name
, finished_object
) == 0
8617 && strcmp (annex
? annex
: "", finished_annex
) == 0
8618 && offset
== finished_offset
)
8621 /* Otherwise, we're now reading something different. Discard
8623 xfree (finished_object
);
8624 xfree (finished_annex
);
8625 finished_object
= NULL
;
8626 finished_annex
= NULL
;
8629 /* Request only enough to fit in a single packet. The actual data
8630 may not, since we don't know how much of it will need to be escaped;
8631 the target is free to respond with slightly less data. We subtract
8632 five to account for the response type and the protocol frame. */
8633 n
= min (get_remote_packet_size () - 5, len
);
8634 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8635 object_name
, annex
? annex
: "",
8636 phex_nz (offset
, sizeof offset
),
8637 phex_nz (n
, sizeof n
));
8638 i
= putpkt (rs
->buf
);
8643 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8644 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8647 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8648 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8650 /* 'm' means there is (or at least might be) more data after this
8651 batch. That does not make sense unless there's at least one byte
8652 of data in this reply. */
8653 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8654 error (_("Remote qXfer reply contained no data."));
8656 /* Got some data. */
8657 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8659 /* 'l' is an EOF marker, possibly including a final block of data,
8660 or possibly empty. If we have the final block of a non-empty
8661 object, record this fact to bypass a subsequent partial read. */
8662 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8664 finished_object
= xstrdup (object_name
);
8665 finished_annex
= xstrdup (annex
? annex
: "");
8666 finished_offset
= offset
+ i
;
8673 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8674 const char *annex
, gdb_byte
*readbuf
,
8675 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8677 struct remote_state
*rs
;
8682 set_remote_traceframe ();
8683 set_general_thread (inferior_ptid
);
8685 rs
= get_remote_state ();
8687 /* Handle memory using the standard memory routines. */
8688 if (object
== TARGET_OBJECT_MEMORY
)
8694 /* If the remote target is connected but not running, we should
8695 pass this request down to a lower stratum (e.g. the executable
8697 if (!target_has_execution
)
8700 if (writebuf
!= NULL
)
8701 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8703 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8707 else if (xfered
== 0 && errno
== 0)
8713 /* Handle SPU memory using qxfer packets. */
8714 if (object
== TARGET_OBJECT_SPU
)
8717 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8718 &remote_protocol_packets
8719 [PACKET_qXfer_spu_read
]);
8721 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8722 &remote_protocol_packets
8723 [PACKET_qXfer_spu_write
]);
8726 /* Handle extra signal info using qxfer packets. */
8727 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8730 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8731 &remote_protocol_packets
8732 [PACKET_qXfer_siginfo_read
]);
8734 return remote_write_qxfer (ops
, "siginfo", annex
,
8735 writebuf
, offset
, len
,
8736 &remote_protocol_packets
8737 [PACKET_qXfer_siginfo_write
]);
8740 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8743 return remote_read_qxfer (ops
, "statictrace", annex
,
8744 readbuf
, offset
, len
,
8745 &remote_protocol_packets
8746 [PACKET_qXfer_statictrace_read
]);
8751 /* Only handle flash writes. */
8752 if (writebuf
!= NULL
)
8758 case TARGET_OBJECT_FLASH
:
8759 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8763 else if (xfered
== 0 && errno
== 0)
8773 /* Map pre-existing objects onto letters. DO NOT do this for new
8774 objects!!! Instead specify new query packets. */
8777 case TARGET_OBJECT_AVR
:
8781 case TARGET_OBJECT_AUXV
:
8782 gdb_assert (annex
== NULL
);
8783 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8784 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8786 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8787 return remote_read_qxfer
8788 (ops
, "features", annex
, readbuf
, offset
, len
,
8789 &remote_protocol_packets
[PACKET_qXfer_features
]);
8791 case TARGET_OBJECT_LIBRARIES
:
8792 return remote_read_qxfer
8793 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8794 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8796 case TARGET_OBJECT_LIBRARIES_SVR4
:
8797 return remote_read_qxfer
8798 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8799 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8801 case TARGET_OBJECT_MEMORY_MAP
:
8802 gdb_assert (annex
== NULL
);
8803 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8804 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8806 case TARGET_OBJECT_OSDATA
:
8807 /* Should only get here if we're connected. */
8808 gdb_assert (remote_desc
);
8809 return remote_read_qxfer
8810 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8811 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8813 case TARGET_OBJECT_THREADS
:
8814 gdb_assert (annex
== NULL
);
8815 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8816 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8818 case TARGET_OBJECT_TRACEFRAME_INFO
:
8819 gdb_assert (annex
== NULL
);
8820 return remote_read_qxfer
8821 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8822 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8824 case TARGET_OBJECT_FDPIC
:
8825 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8826 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8828 case TARGET_OBJECT_OPENVMS_UIB
:
8829 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8830 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8832 case TARGET_OBJECT_BTRACE
:
8833 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8834 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8840 /* Note: a zero OFFSET and LEN can be used to query the minimum
8842 if (offset
== 0 && len
== 0)
8843 return (get_remote_packet_size ());
8844 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8845 large enough let the caller deal with it. */
8846 if (len
< get_remote_packet_size ())
8848 len
= get_remote_packet_size ();
8850 /* Except for querying the minimum buffer size, target must be open. */
8852 error (_("remote query is only available after target open"));
8854 gdb_assert (annex
!= NULL
);
8855 gdb_assert (readbuf
!= NULL
);
8861 /* We used one buffer char for the remote protocol q command and
8862 another for the query type. As the remote protocol encapsulation
8863 uses 4 chars plus one extra in case we are debugging
8864 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8867 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8869 /* Bad caller may have sent forbidden characters. */
8870 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8875 gdb_assert (annex
[i
] == '\0');
8877 i
= putpkt (rs
->buf
);
8881 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8882 strcpy ((char *) readbuf
, rs
->buf
);
8884 return strlen ((char *) readbuf
);
8888 remote_search_memory (struct target_ops
* ops
,
8889 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8890 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8891 CORE_ADDR
*found_addrp
)
8893 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8894 struct remote_state
*rs
= get_remote_state ();
8895 int max_size
= get_memory_write_packet_size ();
8896 struct packet_config
*packet
=
8897 &remote_protocol_packets
[PACKET_qSearch_memory
];
8898 /* Number of packet bytes used to encode the pattern;
8899 this could be more than PATTERN_LEN due to escape characters. */
8900 int escaped_pattern_len
;
8901 /* Amount of pattern that was encodable in the packet. */
8902 int used_pattern_len
;
8905 ULONGEST found_addr
;
8907 /* Don't go to the target if we don't have to.
8908 This is done before checking packet->support to avoid the possibility that
8909 a success for this edge case means the facility works in general. */
8910 if (pattern_len
> search_space_len
)
8912 if (pattern_len
== 0)
8914 *found_addrp
= start_addr
;
8918 /* If we already know the packet isn't supported, fall back to the simple
8919 way of searching memory. */
8921 if (packet
->support
== PACKET_DISABLE
)
8923 /* Target doesn't provided special support, fall back and use the
8924 standard support (copy memory and do the search here). */
8925 return simple_search_memory (ops
, start_addr
, search_space_len
,
8926 pattern
, pattern_len
, found_addrp
);
8929 /* Insert header. */
8930 i
= snprintf (rs
->buf
, max_size
,
8931 "qSearch:memory:%s;%s;",
8932 phex_nz (start_addr
, addr_size
),
8933 phex_nz (search_space_len
, sizeof (search_space_len
)));
8934 max_size
-= (i
+ 1);
8936 /* Escape as much data as fits into rs->buf. */
8937 escaped_pattern_len
=
8938 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8939 &used_pattern_len
, max_size
);
8941 /* Bail if the pattern is too large. */
8942 if (used_pattern_len
!= pattern_len
)
8943 error (_("Pattern is too large to transmit to remote target."));
8945 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8946 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8947 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8949 /* The request may not have worked because the command is not
8950 supported. If so, fall back to the simple way. */
8951 if (packet
->support
== PACKET_DISABLE
)
8953 return simple_search_memory (ops
, start_addr
, search_space_len
,
8954 pattern
, pattern_len
, found_addrp
);
8959 if (rs
->buf
[0] == '0')
8961 else if (rs
->buf
[0] == '1')
8964 if (rs
->buf
[1] != ',')
8965 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8966 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8967 *found_addrp
= found_addr
;
8970 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8976 remote_rcmd (char *command
,
8977 struct ui_file
*outbuf
)
8979 struct remote_state
*rs
= get_remote_state ();
8983 error (_("remote rcmd is only available after target open"));
8985 /* Send a NULL command across as an empty command. */
8986 if (command
== NULL
)
8989 /* The query prefix. */
8990 strcpy (rs
->buf
, "qRcmd,");
8991 p
= strchr (rs
->buf
, '\0');
8993 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8994 > get_remote_packet_size ())
8995 error (_("\"monitor\" command ``%s'' is too long."), command
);
8997 /* Encode the actual command. */
8998 bin2hex ((gdb_byte
*) command
, p
, 0);
9000 if (putpkt (rs
->buf
) < 0)
9001 error (_("Communication problem with target."));
9003 /* get/display the response */
9008 /* XXX - see also remote_get_noisy_reply(). */
9009 QUIT
; /* Allow user to bail out with ^C. */
9011 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9013 /* Timeout. Continue to (try to) read responses.
9014 This is better than stopping with an error, assuming the stub
9015 is still executing the (long) monitor command.
9016 If needed, the user can interrupt gdb using C-c, obtaining
9017 an effect similar to stop on timeout. */
9022 error (_("Target does not support this command."));
9023 if (buf
[0] == 'O' && buf
[1] != 'K')
9025 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9028 if (strcmp (buf
, "OK") == 0)
9030 if (strlen (buf
) == 3 && buf
[0] == 'E'
9031 && isdigit (buf
[1]) && isdigit (buf
[2]))
9033 error (_("Protocol error with Rcmd"));
9035 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9037 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9039 fputc_unfiltered (c
, outbuf
);
9045 static VEC(mem_region_s
) *
9046 remote_memory_map (struct target_ops
*ops
)
9048 VEC(mem_region_s
) *result
= NULL
;
9049 char *text
= target_read_stralloc (¤t_target
,
9050 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9054 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9056 result
= parse_memory_map (text
);
9057 do_cleanups (back_to
);
9064 packet_command (char *args
, int from_tty
)
9066 struct remote_state
*rs
= get_remote_state ();
9069 error (_("command can only be used with remote target"));
9072 error (_("remote-packet command requires packet text as argument"));
9074 puts_filtered ("sending: ");
9075 print_packet (args
);
9076 puts_filtered ("\n");
9079 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9080 puts_filtered ("received: ");
9081 print_packet (rs
->buf
);
9082 puts_filtered ("\n");
9086 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9088 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9090 static void threadset_test_cmd (char *cmd
, int tty
);
9092 static void threadalive_test (char *cmd
, int tty
);
9094 static void threadlist_test_cmd (char *cmd
, int tty
);
9096 int get_and_display_threadinfo (threadref
*ref
);
9098 static void threadinfo_test_cmd (char *cmd
, int tty
);
9100 static int thread_display_step (threadref
*ref
, void *context
);
9102 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9104 static void init_remote_threadtests (void);
9106 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9109 threadset_test_cmd (char *cmd
, int tty
)
9111 int sample_thread
= SAMPLE_THREAD
;
9113 printf_filtered (_("Remote threadset test\n"));
9114 set_general_thread (sample_thread
);
9119 threadalive_test (char *cmd
, int tty
)
9121 int sample_thread
= SAMPLE_THREAD
;
9122 int pid
= ptid_get_pid (inferior_ptid
);
9123 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9125 if (remote_thread_alive (ptid
))
9126 printf_filtered ("PASS: Thread alive test\n");
9128 printf_filtered ("FAIL: Thread alive test\n");
9131 void output_threadid (char *title
, threadref
*ref
);
9134 output_threadid (char *title
, threadref
*ref
)
9138 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9140 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9144 threadlist_test_cmd (char *cmd
, int tty
)
9147 threadref nextthread
;
9148 int done
, result_count
;
9149 threadref threadlist
[3];
9151 printf_filtered ("Remote Threadlist test\n");
9152 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9153 &result_count
, &threadlist
[0]))
9154 printf_filtered ("FAIL: threadlist test\n");
9157 threadref
*scan
= threadlist
;
9158 threadref
*limit
= scan
+ result_count
;
9160 while (scan
< limit
)
9161 output_threadid (" thread ", scan
++);
9166 display_thread_info (struct gdb_ext_thread_info
*info
)
9168 output_threadid ("Threadid: ", &info
->threadid
);
9169 printf_filtered ("Name: %s\n ", info
->shortname
);
9170 printf_filtered ("State: %s\n", info
->display
);
9171 printf_filtered ("other: %s\n\n", info
->more_display
);
9175 get_and_display_threadinfo (threadref
*ref
)
9179 struct gdb_ext_thread_info threadinfo
;
9181 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9182 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9183 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9184 display_thread_info (&threadinfo
);
9189 threadinfo_test_cmd (char *cmd
, int tty
)
9191 int athread
= SAMPLE_THREAD
;
9195 int_to_threadref (&thread
, athread
);
9196 printf_filtered ("Remote Threadinfo test\n");
9197 if (!get_and_display_threadinfo (&thread
))
9198 printf_filtered ("FAIL cannot get thread info\n");
9202 thread_display_step (threadref
*ref
, void *context
)
9204 /* output_threadid(" threadstep ",ref); *//* simple test */
9205 return get_and_display_threadinfo (ref
);
9209 threadlist_update_test_cmd (char *cmd
, int tty
)
9211 printf_filtered ("Remote Threadlist update test\n");
9212 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9216 init_remote_threadtests (void)
9218 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9219 _("Fetch and print the remote list of "
9220 "thread identifiers, one pkt only"));
9221 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9222 _("Fetch and display info about one thread"));
9223 add_com ("tset", class_obscure
, threadset_test_cmd
,
9224 _("Test setting to a different thread"));
9225 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9226 _("Iterate through updating all remote thread info"));
9227 add_com ("talive", class_obscure
, threadalive_test
,
9228 _(" Remote thread alive test "));
9233 /* Convert a thread ID to a string. Returns the string in a static
9237 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9239 static char buf
[64];
9240 struct remote_state
*rs
= get_remote_state ();
9242 if (ptid_equal (ptid
, null_ptid
))
9243 return normal_pid_to_str (ptid
);
9244 else if (ptid_is_pid (ptid
))
9246 /* Printing an inferior target id. */
9248 /* When multi-process extensions are off, there's no way in the
9249 remote protocol to know the remote process id, if there's any
9250 at all. There's one exception --- when we're connected with
9251 target extended-remote, and we manually attached to a process
9252 with "attach PID". We don't record anywhere a flag that
9253 allows us to distinguish that case from the case of
9254 connecting with extended-remote and the stub already being
9255 attached to a process, and reporting yes to qAttached, hence
9256 no smart special casing here. */
9257 if (!remote_multi_process_p (rs
))
9259 xsnprintf (buf
, sizeof buf
, "Remote target");
9263 return normal_pid_to_str (ptid
);
9267 if (ptid_equal (magic_null_ptid
, ptid
))
9268 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9269 else if (rs
->extended
&& remote_multi_process_p (rs
))
9270 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9271 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9273 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9274 ptid_get_tid (ptid
));
9279 /* Get the address of the thread local variable in OBJFILE which is
9280 stored at OFFSET within the thread local storage for thread PTID. */
9283 remote_get_thread_local_address (struct target_ops
*ops
,
9284 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9286 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9288 struct remote_state
*rs
= get_remote_state ();
9290 char *endp
= rs
->buf
+ get_remote_packet_size ();
9291 enum packet_result result
;
9293 strcpy (p
, "qGetTLSAddr:");
9295 p
= write_ptid (p
, endp
, ptid
);
9297 p
+= hexnumstr (p
, offset
);
9299 p
+= hexnumstr (p
, lm
);
9303 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9304 result
= packet_ok (rs
->buf
,
9305 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9306 if (result
== PACKET_OK
)
9310 unpack_varlen_hex (rs
->buf
, &result
);
9313 else if (result
== PACKET_UNKNOWN
)
9314 throw_error (TLS_GENERIC_ERROR
,
9315 _("Remote target doesn't support qGetTLSAddr packet"));
9317 throw_error (TLS_GENERIC_ERROR
,
9318 _("Remote target failed to process qGetTLSAddr request"));
9321 throw_error (TLS_GENERIC_ERROR
,
9322 _("TLS not supported or disabled on this target"));
9327 /* Provide thread local base, i.e. Thread Information Block address.
9328 Returns 1 if ptid is found and thread_local_base is non zero. */
9331 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9333 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9335 struct remote_state
*rs
= get_remote_state ();
9337 char *endp
= rs
->buf
+ get_remote_packet_size ();
9338 enum packet_result result
;
9340 strcpy (p
, "qGetTIBAddr:");
9342 p
= write_ptid (p
, endp
, ptid
);
9346 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9347 result
= packet_ok (rs
->buf
,
9348 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9349 if (result
== PACKET_OK
)
9353 unpack_varlen_hex (rs
->buf
, &result
);
9355 *addr
= (CORE_ADDR
) result
;
9358 else if (result
== PACKET_UNKNOWN
)
9359 error (_("Remote target doesn't support qGetTIBAddr packet"));
9361 error (_("Remote target failed to process qGetTIBAddr request"));
9364 error (_("qGetTIBAddr not supported or disabled on this target"));
9369 /* Support for inferring a target description based on the current
9370 architecture and the size of a 'g' packet. While the 'g' packet
9371 can have any size (since optional registers can be left off the
9372 end), some sizes are easily recognizable given knowledge of the
9373 approximate architecture. */
9375 struct remote_g_packet_guess
9378 const struct target_desc
*tdesc
;
9380 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9381 DEF_VEC_O(remote_g_packet_guess_s
);
9383 struct remote_g_packet_data
9385 VEC(remote_g_packet_guess_s
) *guesses
;
9388 static struct gdbarch_data
*remote_g_packet_data_handle
;
9391 remote_g_packet_data_init (struct obstack
*obstack
)
9393 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9397 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9398 const struct target_desc
*tdesc
)
9400 struct remote_g_packet_data
*data
9401 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9402 struct remote_g_packet_guess new_guess
, *guess
;
9405 gdb_assert (tdesc
!= NULL
);
9408 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9410 if (guess
->bytes
== bytes
)
9411 internal_error (__FILE__
, __LINE__
,
9412 _("Duplicate g packet description added for size %d"),
9415 new_guess
.bytes
= bytes
;
9416 new_guess
.tdesc
= tdesc
;
9417 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9420 /* Return 1 if remote_read_description would do anything on this target
9421 and architecture, 0 otherwise. */
9424 remote_read_description_p (struct target_ops
*target
)
9426 struct remote_g_packet_data
*data
9427 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9429 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9435 static const struct target_desc
*
9436 remote_read_description (struct target_ops
*target
)
9438 struct remote_g_packet_data
*data
9439 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9441 /* Do not try this during initial connection, when we do not know
9442 whether there is a running but stopped thread. */
9443 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9446 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9448 struct remote_g_packet_guess
*guess
;
9450 int bytes
= send_g_packet ();
9453 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9455 if (guess
->bytes
== bytes
)
9456 return guess
->tdesc
;
9458 /* We discard the g packet. A minor optimization would be to
9459 hold on to it, and fill the register cache once we have selected
9460 an architecture, but it's too tricky to do safely. */
9466 /* Remote file transfer support. This is host-initiated I/O, not
9467 target-initiated; for target-initiated, see remote-fileio.c. */
9469 /* If *LEFT is at least the length of STRING, copy STRING to
9470 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9471 decrease *LEFT. Otherwise raise an error. */
9474 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9476 int len
= strlen (string
);
9479 error (_("Packet too long for target."));
9481 memcpy (*buffer
, string
, len
);
9485 /* NUL-terminate the buffer as a convenience, if there is
9491 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9492 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9493 decrease *LEFT. Otherwise raise an error. */
9496 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9499 if (2 * len
> *left
)
9500 error (_("Packet too long for target."));
9502 bin2hex (bytes
, *buffer
, len
);
9506 /* NUL-terminate the buffer as a convenience, if there is
9512 /* If *LEFT is large enough, convert VALUE to hex and add it to
9513 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9514 decrease *LEFT. Otherwise raise an error. */
9517 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9519 int len
= hexnumlen (value
);
9522 error (_("Packet too long for target."));
9524 hexnumstr (*buffer
, value
);
9528 /* NUL-terminate the buffer as a convenience, if there is
9534 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9535 value, *REMOTE_ERRNO to the remote error number or zero if none
9536 was included, and *ATTACHMENT to point to the start of the annex
9537 if any. The length of the packet isn't needed here; there may
9538 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9540 Return 0 if the packet could be parsed, -1 if it could not. If
9541 -1 is returned, the other variables may not be initialized. */
9544 remote_hostio_parse_result (char *buffer
, int *retcode
,
9545 int *remote_errno
, char **attachment
)
9552 if (buffer
[0] != 'F')
9556 *retcode
= strtol (&buffer
[1], &p
, 16);
9557 if (errno
!= 0 || p
== &buffer
[1])
9560 /* Check for ",errno". */
9564 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9565 if (errno
!= 0 || p
+ 1 == p2
)
9570 /* Check for ";attachment". If there is no attachment, the
9571 packet should end here. */
9574 *attachment
= p
+ 1;
9577 else if (*p
== '\0')
9583 /* Send a prepared I/O packet to the target and read its response.
9584 The prepared packet is in the global RS->BUF before this function
9585 is called, and the answer is there when we return.
9587 COMMAND_BYTES is the length of the request to send, which may include
9588 binary data. WHICH_PACKET is the packet configuration to check
9589 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9590 is set to the error number and -1 is returned. Otherwise the value
9591 returned by the function is returned.
9593 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9594 attachment is expected; an error will be reported if there's a
9595 mismatch. If one is found, *ATTACHMENT will be set to point into
9596 the packet buffer and *ATTACHMENT_LEN will be set to the
9597 attachment's length. */
9600 remote_hostio_send_command (int command_bytes
, int which_packet
,
9601 int *remote_errno
, char **attachment
,
9602 int *attachment_len
)
9604 struct remote_state
*rs
= get_remote_state ();
9605 int ret
, bytes_read
;
9606 char *attachment_tmp
;
9609 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9611 *remote_errno
= FILEIO_ENOSYS
;
9615 putpkt_binary (rs
->buf
, command_bytes
);
9616 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9618 /* If it timed out, something is wrong. Don't try to parse the
9622 *remote_errno
= FILEIO_EINVAL
;
9626 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9629 *remote_errno
= FILEIO_EINVAL
;
9631 case PACKET_UNKNOWN
:
9632 *remote_errno
= FILEIO_ENOSYS
;
9638 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9641 *remote_errno
= FILEIO_EINVAL
;
9645 /* Make sure we saw an attachment if and only if we expected one. */
9646 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9647 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9649 *remote_errno
= FILEIO_EINVAL
;
9653 /* If an attachment was found, it must point into the packet buffer;
9654 work out how many bytes there were. */
9655 if (attachment_tmp
!= NULL
)
9657 *attachment
= attachment_tmp
;
9658 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9664 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9665 remote file descriptor, or -1 if an error occurs (and set
9669 remote_hostio_open (const char *filename
, int flags
, int mode
,
9672 struct remote_state
*rs
= get_remote_state ();
9674 int left
= get_remote_packet_size () - 1;
9676 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9678 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9680 remote_buffer_add_string (&p
, &left
, ",");
9682 remote_buffer_add_int (&p
, &left
, flags
);
9683 remote_buffer_add_string (&p
, &left
, ",");
9685 remote_buffer_add_int (&p
, &left
, mode
);
9687 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9688 remote_errno
, NULL
, NULL
);
9691 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9692 Return the number of bytes written, or -1 if an error occurs (and
9693 set *REMOTE_ERRNO). */
9696 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9697 ULONGEST offset
, int *remote_errno
)
9699 struct remote_state
*rs
= get_remote_state ();
9701 int left
= get_remote_packet_size ();
9704 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9706 remote_buffer_add_int (&p
, &left
, fd
);
9707 remote_buffer_add_string (&p
, &left
, ",");
9709 remote_buffer_add_int (&p
, &left
, offset
);
9710 remote_buffer_add_string (&p
, &left
, ",");
9712 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9713 get_remote_packet_size () - (p
- rs
->buf
));
9715 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9716 remote_errno
, NULL
, NULL
);
9719 /* Read up to LEN bytes FD on the remote target into READ_BUF
9720 Return the number of bytes read, or -1 if an error occurs (and
9721 set *REMOTE_ERRNO). */
9724 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9725 ULONGEST offset
, int *remote_errno
)
9727 struct remote_state
*rs
= get_remote_state ();
9730 int left
= get_remote_packet_size ();
9731 int ret
, attachment_len
;
9734 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9736 remote_buffer_add_int (&p
, &left
, fd
);
9737 remote_buffer_add_string (&p
, &left
, ",");
9739 remote_buffer_add_int (&p
, &left
, len
);
9740 remote_buffer_add_string (&p
, &left
, ",");
9742 remote_buffer_add_int (&p
, &left
, offset
);
9744 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9745 remote_errno
, &attachment
,
9751 read_len
= remote_unescape_input (attachment
, attachment_len
,
9753 if (read_len
!= ret
)
9754 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9759 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9760 (and set *REMOTE_ERRNO). */
9763 remote_hostio_close (int fd
, int *remote_errno
)
9765 struct remote_state
*rs
= get_remote_state ();
9767 int left
= get_remote_packet_size () - 1;
9769 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9771 remote_buffer_add_int (&p
, &left
, fd
);
9773 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9774 remote_errno
, NULL
, NULL
);
9777 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9778 occurs (and set *REMOTE_ERRNO). */
9781 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9783 struct remote_state
*rs
= get_remote_state ();
9785 int left
= get_remote_packet_size () - 1;
9787 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9789 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9792 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9793 remote_errno
, NULL
, NULL
);
9796 /* Read value of symbolic link FILENAME on the remote target. Return
9797 a null-terminated string allocated via xmalloc, or NULL if an error
9798 occurs (and set *REMOTE_ERRNO). */
9801 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9803 struct remote_state
*rs
= get_remote_state ();
9806 int left
= get_remote_packet_size ();
9807 int len
, attachment_len
;
9811 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9813 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9816 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9817 remote_errno
, &attachment
,
9823 ret
= xmalloc (len
+ 1);
9825 read_len
= remote_unescape_input (attachment
, attachment_len
,
9827 if (read_len
!= len
)
9828 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9835 remote_fileio_errno_to_host (int errnum
)
9859 case FILEIO_ENOTDIR
:
9879 case FILEIO_ENAMETOOLONG
:
9880 return ENAMETOOLONG
;
9886 remote_hostio_error (int errnum
)
9888 int host_error
= remote_fileio_errno_to_host (errnum
);
9890 if (host_error
== -1)
9891 error (_("Unknown remote I/O error %d"), errnum
);
9893 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9897 remote_hostio_close_cleanup (void *opaque
)
9899 int fd
= *(int *) opaque
;
9902 remote_hostio_close (fd
, &remote_errno
);
9907 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9909 const char *filename
= bfd_get_filename (abfd
);
9910 int fd
, remote_errno
;
9913 gdb_assert (remote_filename_p (filename
));
9915 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9918 errno
= remote_fileio_errno_to_host (remote_errno
);
9919 bfd_set_error (bfd_error_system_call
);
9923 stream
= xmalloc (sizeof (int));
9929 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9931 int fd
= *(int *)stream
;
9936 /* Ignore errors on close; these may happen if the remote
9937 connection was already torn down. */
9938 remote_hostio_close (fd
, &remote_errno
);
9940 /* Zero means success. */
9945 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9946 file_ptr nbytes
, file_ptr offset
)
9948 int fd
= *(int *)stream
;
9950 file_ptr pos
, bytes
;
9953 while (nbytes
> pos
)
9955 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9956 offset
+ pos
, &remote_errno
);
9958 /* Success, but no bytes, means end-of-file. */
9962 errno
= remote_fileio_errno_to_host (remote_errno
);
9963 bfd_set_error (bfd_error_system_call
);
9974 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9976 /* FIXME: We should probably implement remote_hostio_stat. */
9977 sb
->st_size
= INT_MAX
;
9982 remote_filename_p (const char *filename
)
9984 return strncmp (filename
, "remote:", 7) == 0;
9988 remote_bfd_open (const char *remote_file
, const char *target
)
9990 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
9991 remote_bfd_iovec_open
, NULL
,
9992 remote_bfd_iovec_pread
,
9993 remote_bfd_iovec_close
,
9994 remote_bfd_iovec_stat
);
10000 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10002 struct cleanup
*back_to
, *close_cleanup
;
10003 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10006 int bytes_in_buffer
;
10011 error (_("command can only be used with remote target"));
10013 file
= fopen (local_file
, "rb");
10015 perror_with_name (local_file
);
10016 back_to
= make_cleanup_fclose (file
);
10018 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10020 0700, &remote_errno
);
10022 remote_hostio_error (remote_errno
);
10024 /* Send up to this many bytes at once. They won't all fit in the
10025 remote packet limit, so we'll transfer slightly fewer. */
10026 io_size
= get_remote_packet_size ();
10027 buffer
= xmalloc (io_size
);
10028 make_cleanup (xfree
, buffer
);
10030 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10032 bytes_in_buffer
= 0;
10035 while (bytes_in_buffer
|| !saw_eof
)
10039 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10040 io_size
- bytes_in_buffer
,
10045 error (_("Error reading %s."), local_file
);
10048 /* EOF. Unless there is something still in the
10049 buffer from the last iteration, we are done. */
10051 if (bytes_in_buffer
== 0)
10059 bytes
+= bytes_in_buffer
;
10060 bytes_in_buffer
= 0;
10062 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10063 offset
, &remote_errno
);
10066 remote_hostio_error (remote_errno
);
10067 else if (retcode
== 0)
10068 error (_("Remote write of %d bytes returned 0!"), bytes
);
10069 else if (retcode
< bytes
)
10071 /* Short write. Save the rest of the read data for the next
10073 bytes_in_buffer
= bytes
- retcode
;
10074 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10080 discard_cleanups (close_cleanup
);
10081 if (remote_hostio_close (fd
, &remote_errno
))
10082 remote_hostio_error (remote_errno
);
10085 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10086 do_cleanups (back_to
);
10090 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10092 struct cleanup
*back_to
, *close_cleanup
;
10093 int fd
, remote_errno
, bytes
, io_size
;
10099 error (_("command can only be used with remote target"));
10101 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10103 remote_hostio_error (remote_errno
);
10105 file
= fopen (local_file
, "wb");
10107 perror_with_name (local_file
);
10108 back_to
= make_cleanup_fclose (file
);
10110 /* Send up to this many bytes at once. They won't all fit in the
10111 remote packet limit, so we'll transfer slightly fewer. */
10112 io_size
= get_remote_packet_size ();
10113 buffer
= xmalloc (io_size
);
10114 make_cleanup (xfree
, buffer
);
10116 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10121 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10123 /* Success, but no bytes, means end-of-file. */
10126 remote_hostio_error (remote_errno
);
10130 bytes
= fwrite (buffer
, 1, bytes
, file
);
10132 perror_with_name (local_file
);
10135 discard_cleanups (close_cleanup
);
10136 if (remote_hostio_close (fd
, &remote_errno
))
10137 remote_hostio_error (remote_errno
);
10140 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10141 do_cleanups (back_to
);
10145 remote_file_delete (const char *remote_file
, int from_tty
)
10147 int retcode
, remote_errno
;
10150 error (_("command can only be used with remote target"));
10152 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10154 remote_hostio_error (remote_errno
);
10157 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10161 remote_put_command (char *args
, int from_tty
)
10163 struct cleanup
*back_to
;
10167 error_no_arg (_("file to put"));
10169 argv
= gdb_buildargv (args
);
10170 back_to
= make_cleanup_freeargv (argv
);
10171 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10172 error (_("Invalid parameters to remote put"));
10174 remote_file_put (argv
[0], argv
[1], from_tty
);
10176 do_cleanups (back_to
);
10180 remote_get_command (char *args
, int from_tty
)
10182 struct cleanup
*back_to
;
10186 error_no_arg (_("file to get"));
10188 argv
= gdb_buildargv (args
);
10189 back_to
= make_cleanup_freeargv (argv
);
10190 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10191 error (_("Invalid parameters to remote get"));
10193 remote_file_get (argv
[0], argv
[1], from_tty
);
10195 do_cleanups (back_to
);
10199 remote_delete_command (char *args
, int from_tty
)
10201 struct cleanup
*back_to
;
10205 error_no_arg (_("file to delete"));
10207 argv
= gdb_buildargv (args
);
10208 back_to
= make_cleanup_freeargv (argv
);
10209 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10210 error (_("Invalid parameters to remote delete"));
10212 remote_file_delete (argv
[0], from_tty
);
10214 do_cleanups (back_to
);
10218 remote_command (char *args
, int from_tty
)
10220 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10224 remote_can_execute_reverse (void)
10226 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10227 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10234 remote_supports_non_stop (void)
10240 remote_supports_disable_randomization (void)
10242 /* Only supported in extended mode. */
10247 remote_supports_multi_process (void)
10249 struct remote_state
*rs
= get_remote_state ();
10251 /* Only extended-remote handles being attached to multiple
10252 processes, even though plain remote can use the multi-process
10253 thread id extensions, so that GDB knows the target process's
10255 return rs
->extended
&& remote_multi_process_p (rs
);
10259 remote_supports_cond_tracepoints (void)
10261 struct remote_state
*rs
= get_remote_state ();
10263 return rs
->cond_tracepoints
;
10267 remote_supports_cond_breakpoints (void)
10269 struct remote_state
*rs
= get_remote_state ();
10271 return rs
->cond_breakpoints
;
10275 remote_supports_fast_tracepoints (void)
10277 struct remote_state
*rs
= get_remote_state ();
10279 return rs
->fast_tracepoints
;
10283 remote_supports_static_tracepoints (void)
10285 struct remote_state
*rs
= get_remote_state ();
10287 return rs
->static_tracepoints
;
10291 remote_supports_install_in_trace (void)
10293 struct remote_state
*rs
= get_remote_state ();
10295 return rs
->install_in_trace
;
10299 remote_supports_enable_disable_tracepoint (void)
10301 struct remote_state
*rs
= get_remote_state ();
10303 return rs
->enable_disable_tracepoints
;
10307 remote_supports_string_tracing (void)
10309 struct remote_state
*rs
= get_remote_state ();
10311 return rs
->string_tracing
;
10315 remote_can_run_breakpoint_commands (void)
10317 struct remote_state
*rs
= get_remote_state ();
10319 return rs
->breakpoint_commands
;
10323 remote_trace_init (void)
10326 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10327 if (strcmp (target_buf
, "OK") != 0)
10328 error (_("Target does not support this command."));
10331 static void free_actions_list (char **actions_list
);
10332 static void free_actions_list_cleanup_wrapper (void *);
10334 free_actions_list_cleanup_wrapper (void *al
)
10336 free_actions_list (al
);
10340 free_actions_list (char **actions_list
)
10344 if (actions_list
== 0)
10347 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10348 xfree (actions_list
[ndx
]);
10350 xfree (actions_list
);
10353 /* Recursive routine to walk through command list including loops, and
10354 download packets for each command. */
10357 remote_download_command_source (int num
, ULONGEST addr
,
10358 struct command_line
*cmds
)
10360 struct remote_state
*rs
= get_remote_state ();
10361 struct command_line
*cmd
;
10363 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10365 QUIT
; /* Allow user to bail out with ^C. */
10366 strcpy (rs
->buf
, "QTDPsrc:");
10367 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10368 rs
->buf
+ strlen (rs
->buf
),
10369 rs
->buf_size
- strlen (rs
->buf
));
10371 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10372 if (strcmp (target_buf
, "OK"))
10373 warning (_("Target does not support source download."));
10375 if (cmd
->control_type
== while_control
10376 || cmd
->control_type
== while_stepping_control
)
10378 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10380 QUIT
; /* Allow user to bail out with ^C. */
10381 strcpy (rs
->buf
, "QTDPsrc:");
10382 encode_source_string (num
, addr
, "cmd", "end",
10383 rs
->buf
+ strlen (rs
->buf
),
10384 rs
->buf_size
- strlen (rs
->buf
));
10386 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10387 if (strcmp (target_buf
, "OK"))
10388 warning (_("Target does not support source download."));
10394 remote_download_tracepoint (struct bp_location
*loc
)
10396 #define BUF_SIZE 2048
10400 char buf
[BUF_SIZE
];
10401 char **tdp_actions
;
10402 char **stepping_actions
;
10404 struct cleanup
*old_chain
= NULL
;
10405 struct agent_expr
*aexpr
;
10406 struct cleanup
*aexpr_chain
= NULL
;
10408 struct breakpoint
*b
= loc
->owner
;
10409 struct tracepoint
*t
= (struct tracepoint
*) b
;
10411 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
10412 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10414 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10417 tpaddr
= loc
->address
;
10418 sprintf_vma (addrbuf
, tpaddr
);
10419 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10420 addrbuf
, /* address */
10421 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10422 t
->step_count
, t
->pass_count
);
10423 /* Fast tracepoints are mostly handled by the target, but we can
10424 tell the target how big of an instruction block should be moved
10426 if (b
->type
== bp_fast_tracepoint
)
10428 /* Only test for support at download time; we may not know
10429 target capabilities at definition time. */
10430 if (remote_supports_fast_tracepoints ())
10434 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10435 tpaddr
, &isize
, NULL
))
10436 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10439 /* If it passed validation at definition but fails now,
10440 something is very wrong. */
10441 internal_error (__FILE__
, __LINE__
,
10442 _("Fast tracepoint not "
10443 "valid during download"));
10446 /* Fast tracepoints are functionally identical to regular
10447 tracepoints, so don't take lack of support as a reason to
10448 give up on the trace run. */
10449 warning (_("Target does not support fast tracepoints, "
10450 "downloading %d as regular tracepoint"), b
->number
);
10452 else if (b
->type
== bp_static_tracepoint
)
10454 /* Only test for support at download time; we may not know
10455 target capabilities at definition time. */
10456 if (remote_supports_static_tracepoints ())
10458 struct static_tracepoint_marker marker
;
10460 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10461 strcat (buf
, ":S");
10463 error (_("Static tracepoint not valid during download"));
10466 /* Fast tracepoints are functionally identical to regular
10467 tracepoints, so don't take lack of support as a reason
10468 to give up on the trace run. */
10469 error (_("Target does not support static tracepoints"));
10471 /* If the tracepoint has a conditional, make it into an agent
10472 expression and append to the definition. */
10475 /* Only test support at download time, we may not know target
10476 capabilities at definition time. */
10477 if (remote_supports_cond_tracepoints ())
10479 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10480 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10481 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10483 pkt
= buf
+ strlen (buf
);
10484 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10485 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10487 do_cleanups (aexpr_chain
);
10490 warning (_("Target does not support conditional tracepoints, "
10491 "ignoring tp %d cond"), b
->number
);
10494 if (b
->commands
|| *default_collect
)
10497 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10498 if (strcmp (target_buf
, "OK"))
10499 error (_("Target does not support tracepoints."));
10501 /* do_single_steps (t); */
10504 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10506 QUIT
; /* Allow user to bail out with ^C. */
10507 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10508 b
->number
, addrbuf
, /* address */
10510 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10513 remote_get_noisy_reply (&target_buf
,
10515 if (strcmp (target_buf
, "OK"))
10516 error (_("Error on target while setting tracepoints."));
10519 if (stepping_actions
)
10521 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10523 QUIT
; /* Allow user to bail out with ^C. */
10524 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10525 b
->number
, addrbuf
, /* address */
10526 ((ndx
== 0) ? "S" : ""),
10527 stepping_actions
[ndx
],
10528 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10530 remote_get_noisy_reply (&target_buf
,
10532 if (strcmp (target_buf
, "OK"))
10533 error (_("Error on target while setting tracepoints."));
10537 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10540 if (b
->addr_string
)
10542 strcpy (buf
, "QTDPsrc:");
10543 encode_source_string (b
->number
, loc
->address
,
10544 "at", b
->addr_string
, buf
+ strlen (buf
),
10545 2048 - strlen (buf
));
10548 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10549 if (strcmp (target_buf
, "OK"))
10550 warning (_("Target does not support source download."));
10552 if (b
->cond_string
)
10554 strcpy (buf
, "QTDPsrc:");
10555 encode_source_string (b
->number
, loc
->address
,
10556 "cond", b
->cond_string
, buf
+ strlen (buf
),
10557 2048 - strlen (buf
));
10559 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10560 if (strcmp (target_buf
, "OK"))
10561 warning (_("Target does not support source download."));
10563 remote_download_command_source (b
->number
, loc
->address
,
10564 breakpoint_commands (b
));
10567 do_cleanups (old_chain
);
10571 remote_can_download_tracepoint (void)
10573 struct remote_state
*rs
= get_remote_state ();
10574 struct trace_status
*ts
;
10577 /* Don't try to install tracepoints until we've relocated our
10578 symbols, and fetched and merged the target's tracepoint list with
10580 if (rs
->starting_up
)
10583 ts
= current_trace_status ();
10584 status
= remote_get_trace_status (ts
);
10586 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10589 /* If we are in a tracing experiment, but remote stub doesn't support
10590 installing tracepoint in trace, we have to return. */
10591 if (!remote_supports_install_in_trace ())
10599 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10601 struct remote_state
*rs
= get_remote_state ();
10604 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10605 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10607 p
= rs
->buf
+ strlen (rs
->buf
);
10608 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10609 error (_("Trace state variable name too long for tsv definition packet"));
10610 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10613 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10614 if (*target_buf
== '\0')
10615 error (_("Target does not support this command."));
10616 if (strcmp (target_buf
, "OK") != 0)
10617 error (_("Error on target while downloading trace state variable."));
10621 remote_enable_tracepoint (struct bp_location
*location
)
10623 struct remote_state
*rs
= get_remote_state ();
10626 sprintf_vma (addr_buf
, location
->address
);
10627 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10628 location
->owner
->number
, addr_buf
);
10630 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10631 if (*rs
->buf
== '\0')
10632 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10633 if (strcmp (rs
->buf
, "OK") != 0)
10634 error (_("Error on target while enabling tracepoint."));
10638 remote_disable_tracepoint (struct bp_location
*location
)
10640 struct remote_state
*rs
= get_remote_state ();
10643 sprintf_vma (addr_buf
, location
->address
);
10644 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10645 location
->owner
->number
, addr_buf
);
10647 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10648 if (*rs
->buf
== '\0')
10649 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10650 if (strcmp (rs
->buf
, "OK") != 0)
10651 error (_("Error on target while disabling tracepoint."));
10655 remote_trace_set_readonly_regions (void)
10659 bfd_size_type size
;
10665 return; /* No information to give. */
10667 strcpy (target_buf
, "QTro");
10668 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10670 char tmp1
[40], tmp2
[40];
10673 if ((s
->flags
& SEC_LOAD
) == 0 ||
10674 /* (s->flags & SEC_CODE) == 0 || */
10675 (s
->flags
& SEC_READONLY
) == 0)
10679 vma
= bfd_get_section_vma (abfd
, s
);
10680 size
= bfd_get_section_size (s
);
10681 sprintf_vma (tmp1
, vma
);
10682 sprintf_vma (tmp2
, vma
+ size
);
10683 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10684 if (offset
+ sec_length
+ 1 > target_buf_size
)
10686 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10689 Too many sections for read-only sections definition packet."));
10692 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10694 offset
+= sec_length
;
10698 putpkt (target_buf
);
10699 getpkt (&target_buf
, &target_buf_size
, 0);
10704 remote_trace_start (void)
10706 putpkt ("QTStart");
10707 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10708 if (*target_buf
== '\0')
10709 error (_("Target does not support this command."));
10710 if (strcmp (target_buf
, "OK") != 0)
10711 error (_("Bogus reply from target: %s"), target_buf
);
10715 remote_get_trace_status (struct trace_status
*ts
)
10717 /* Initialize it just to avoid a GCC false warning. */
10719 /* FIXME we need to get register block size some other way. */
10720 extern int trace_regblock_size
;
10721 volatile struct gdb_exception ex
;
10722 enum packet_result result
;
10724 if (remote_protocol_packets
[PACKET_qTStatus
].support
== PACKET_DISABLE
)
10727 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10729 putpkt ("qTStatus");
10731 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10733 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10737 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10739 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10742 throw_exception (ex
);
10745 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10747 /* If the remote target doesn't do tracing, flag it. */
10748 if (result
== PACKET_UNKNOWN
)
10751 /* We're working with a live target. */
10752 ts
->filename
= NULL
;
10755 error (_("Bogus trace status reply from target: %s"), target_buf
);
10757 /* Function 'parse_trace_status' sets default value of each field of
10758 'ts' at first, so we don't have to do it here. */
10759 parse_trace_status (p
, ts
);
10761 return ts
->running
;
10765 remote_get_tracepoint_status (struct breakpoint
*bp
,
10766 struct uploaded_tp
*utp
)
10768 struct remote_state
*rs
= get_remote_state ();
10770 struct bp_location
*loc
;
10771 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10772 size_t size
= get_remote_packet_size ();
10776 tp
->base
.hit_count
= 0;
10777 tp
->traceframe_usage
= 0;
10778 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10780 /* If the tracepoint was never downloaded, don't go asking for
10782 if (tp
->number_on_target
== 0)
10784 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10785 phex_nz (loc
->address
, 0));
10787 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10788 if (reply
&& *reply
)
10791 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10797 utp
->hit_count
= 0;
10798 utp
->traceframe_usage
= 0;
10799 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10800 phex_nz (utp
->addr
, 0));
10802 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10803 if (reply
&& *reply
)
10806 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10812 remote_trace_stop (void)
10815 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10816 if (*target_buf
== '\0')
10817 error (_("Target does not support this command."));
10818 if (strcmp (target_buf
, "OK") != 0)
10819 error (_("Bogus reply from target: %s"), target_buf
);
10823 remote_trace_find (enum trace_find_type type
, int num
,
10824 CORE_ADDR addr1
, CORE_ADDR addr2
,
10827 struct remote_state
*rs
= get_remote_state ();
10828 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10830 int target_frameno
= -1, target_tracept
= -1;
10832 /* Lookups other than by absolute frame number depend on the current
10833 trace selected, so make sure it is correct on the remote end
10835 if (type
!= tfind_number
)
10836 set_remote_traceframe ();
10839 strcpy (p
, "QTFrame:");
10840 p
= strchr (p
, '\0');
10844 xsnprintf (p
, endbuf
- p
, "%x", num
);
10847 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10850 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10853 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10854 phex_nz (addr2
, 0));
10856 case tfind_outside
:
10857 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10858 phex_nz (addr2
, 0));
10861 error (_("Unknown trace find type %d"), type
);
10865 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10866 if (*reply
== '\0')
10867 error (_("Target does not support this command."));
10869 while (reply
&& *reply
)
10874 target_frameno
= (int) strtol (p
, &reply
, 16);
10876 error (_("Unable to parse trace frame number"));
10877 /* Don't update our remote traceframe number cache on failure
10878 to select a remote traceframe. */
10879 if (target_frameno
== -1)
10884 target_tracept
= (int) strtol (p
, &reply
, 16);
10886 error (_("Unable to parse tracepoint number"));
10888 case 'O': /* "OK"? */
10889 if (reply
[1] == 'K' && reply
[2] == '\0')
10892 error (_("Bogus reply from target: %s"), reply
);
10895 error (_("Bogus reply from target: %s"), reply
);
10898 *tpp
= target_tracept
;
10900 remote_traceframe_number
= target_frameno
;
10901 return target_frameno
;
10905 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10907 struct remote_state
*rs
= get_remote_state ();
10911 set_remote_traceframe ();
10913 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10915 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10916 if (reply
&& *reply
)
10920 unpack_varlen_hex (reply
+ 1, &uval
);
10921 *val
= (LONGEST
) uval
;
10929 remote_save_trace_data (const char *filename
)
10931 struct remote_state
*rs
= get_remote_state ();
10935 strcpy (p
, "QTSave:");
10937 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10938 error (_("Remote file name too long for trace save packet"));
10939 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10942 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10943 if (*reply
== '\0')
10944 error (_("Target does not support this command."));
10945 if (strcmp (reply
, "OK") != 0)
10946 error (_("Bogus reply from target: %s"), reply
);
10950 /* This is basically a memory transfer, but needs to be its own packet
10951 because we don't know how the target actually organizes its trace
10952 memory, plus we want to be able to ask for as much as possible, but
10953 not be unhappy if we don't get as much as we ask for. */
10956 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10958 struct remote_state
*rs
= get_remote_state ();
10964 strcpy (p
, "qTBuffer:");
10966 p
+= hexnumstr (p
, offset
);
10968 p
+= hexnumstr (p
, len
);
10972 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10973 if (reply
&& *reply
)
10975 /* 'l' by itself means we're at the end of the buffer and
10976 there is nothing more to get. */
10980 /* Convert the reply into binary. Limit the number of bytes to
10981 convert according to our passed-in buffer size, rather than
10982 what was returned in the packet; if the target is
10983 unexpectedly generous and gives us a bigger reply than we
10984 asked for, we don't want to crash. */
10985 rslt
= hex2bin (target_buf
, buf
, len
);
10989 /* Something went wrong, flag as an error. */
10994 remote_set_disconnected_tracing (int val
)
10996 struct remote_state
*rs
= get_remote_state ();
10998 if (rs
->disconnected_tracing
)
11002 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11004 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11005 if (*reply
== '\0')
11006 error (_("Target does not support this command."));
11007 if (strcmp (reply
, "OK") != 0)
11008 error (_("Bogus reply from target: %s"), reply
);
11011 warning (_("Target does not support disconnected tracing."));
11015 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11017 struct thread_info
*info
= find_thread_ptid (ptid
);
11019 if (info
&& info
->private)
11020 return info
->private->core
;
11025 remote_set_circular_trace_buffer (int val
)
11027 struct remote_state
*rs
= get_remote_state ();
11030 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11032 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11033 if (*reply
== '\0')
11034 error (_("Target does not support this command."));
11035 if (strcmp (reply
, "OK") != 0)
11036 error (_("Bogus reply from target: %s"), reply
);
11039 static struct traceframe_info
*
11040 remote_traceframe_info (void)
11044 text
= target_read_stralloc (¤t_target
,
11045 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11048 struct traceframe_info
*info
;
11049 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11051 info
= parse_traceframe_info (text
);
11052 do_cleanups (back_to
);
11059 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11060 instruction on which a fast tracepoint may be placed. Returns -1
11061 if the packet is not supported, and 0 if the minimum instruction
11062 length is unknown. */
11065 remote_get_min_fast_tracepoint_insn_len (void)
11067 struct remote_state
*rs
= get_remote_state ();
11070 /* If we're not debugging a process yet, the IPA can't be
11072 if (!target_has_execution
)
11075 /* Make sure the remote is pointing at the right process. */
11076 set_general_process ();
11078 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11080 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11081 if (*reply
== '\0')
11085 ULONGEST min_insn_len
;
11087 unpack_varlen_hex (reply
, &min_insn_len
);
11089 return (int) min_insn_len
;
11094 remote_set_trace_buffer_size (LONGEST val
)
11096 if (remote_protocol_packets
[PACKET_QTBuffer_size
].support
11099 struct remote_state
*rs
= get_remote_state ();
11100 char *buf
= rs
->buf
;
11101 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11102 enum packet_result result
;
11104 gdb_assert (val
>= 0 || val
== -1);
11105 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11106 /* Send -1 as literal "-1" to avoid host size dependency. */
11110 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11113 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11116 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11117 result
= packet_ok (rs
->buf
,
11118 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11120 if (result
!= PACKET_OK
)
11121 warning (_("Bogus reply from target: %s"), rs
->buf
);
11126 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
11128 struct remote_state
*rs
= get_remote_state ();
11130 char *buf
= rs
->buf
;
11131 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11134 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11137 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11138 nbytes
= bin2hex (user
, buf
, 0);
11144 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11145 nbytes
= bin2hex (notes
, buf
, 0);
11151 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11152 nbytes
= bin2hex (stop_notes
, buf
, 0);
11156 /* Ensure the buffer is terminated. */
11160 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11161 if (*reply
== '\0')
11164 if (strcmp (reply
, "OK") != 0)
11165 error (_("Bogus reply from target: %s"), reply
);
11171 remote_use_agent (int use
)
11173 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11175 struct remote_state
*rs
= get_remote_state ();
11177 /* If the stub supports QAgent. */
11178 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11180 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11182 if (strcmp (rs
->buf
, "OK") == 0)
11193 remote_can_use_agent (void)
11195 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11198 struct btrace_target_info
11200 /* The ptid of the traced thread. */
11204 /* Check whether the target supports branch tracing. */
11207 remote_supports_btrace (void)
11209 if (remote_protocol_packets
[PACKET_Qbtrace_off
].support
!= PACKET_ENABLE
)
11211 if (remote_protocol_packets
[PACKET_Qbtrace_bts
].support
!= PACKET_ENABLE
)
11213 if (remote_protocol_packets
[PACKET_qXfer_btrace
].support
!= PACKET_ENABLE
)
11219 /* Enable branch tracing. */
11221 static struct btrace_target_info
*
11222 remote_enable_btrace (ptid_t ptid
)
11224 struct btrace_target_info
*tinfo
= NULL
;
11225 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11226 struct remote_state
*rs
= get_remote_state ();
11227 char *buf
= rs
->buf
;
11228 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11230 if (packet
->support
!= PACKET_ENABLE
)
11231 error (_("Target does not support branch tracing."));
11233 set_general_thread (ptid
);
11235 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11237 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11239 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11241 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11242 error (_("Could not enable branch tracing for %s: %s"),
11243 target_pid_to_str (ptid
), rs
->buf
+ 2);
11245 error (_("Could not enable branch tracing for %s."),
11246 target_pid_to_str (ptid
));
11249 tinfo
= xzalloc (sizeof (*tinfo
));
11250 tinfo
->ptid
= ptid
;
11255 /* Disable branch tracing. */
11258 remote_disable_btrace (struct btrace_target_info
*tinfo
)
11260 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11261 struct remote_state
*rs
= get_remote_state ();
11262 char *buf
= rs
->buf
;
11263 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11265 if (packet
->support
!= PACKET_ENABLE
)
11266 error (_("Target does not support branch tracing."));
11268 set_general_thread (tinfo
->ptid
);
11270 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11272 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11274 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11276 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11277 error (_("Could not disable branch tracing for %s: %s"),
11278 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11280 error (_("Could not disable branch tracing for %s."),
11281 target_pid_to_str (tinfo
->ptid
));
11287 /* Teardown branch tracing. */
11290 remote_teardown_btrace (struct btrace_target_info
*tinfo
)
11292 /* We must not talk to the target during teardown. */
11296 /* Read the branch trace. */
11298 static VEC (btrace_block_s
) *
11299 remote_read_btrace (struct btrace_target_info
*tinfo
,
11300 enum btrace_read_type type
)
11302 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11303 struct remote_state
*rs
= get_remote_state ();
11304 VEC (btrace_block_s
) *btrace
= NULL
;
11308 if (packet
->support
!= PACKET_ENABLE
)
11309 error (_("Target does not support branch tracing."));
11311 #if !defined(HAVE_LIBEXPAT)
11312 error (_("Cannot process branch tracing result. XML parsing not supported."));
11317 case btrace_read_all
:
11320 case btrace_read_new
:
11324 internal_error (__FILE__
, __LINE__
,
11325 _("Bad branch tracing read type: %u."),
11326 (unsigned int) type
);
11329 xml
= target_read_stralloc (¤t_target
,
11330 TARGET_OBJECT_BTRACE
, annex
);
11333 struct cleanup
*cleanup
= make_cleanup (xfree
, xml
);
11335 btrace
= parse_xml_btrace (xml
);
11336 do_cleanups (cleanup
);
11343 init_remote_ops (void)
11345 remote_ops
.to_shortname
= "remote";
11346 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11347 remote_ops
.to_doc
=
11348 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11349 Specify the serial device it is connected to\n\
11350 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11351 remote_ops
.to_open
= remote_open
;
11352 remote_ops
.to_close
= remote_close
;
11353 remote_ops
.to_detach
= remote_detach
;
11354 remote_ops
.to_disconnect
= remote_disconnect
;
11355 remote_ops
.to_resume
= remote_resume
;
11356 remote_ops
.to_wait
= remote_wait
;
11357 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11358 remote_ops
.to_store_registers
= remote_store_registers
;
11359 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11360 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11361 remote_ops
.to_files_info
= remote_files_info
;
11362 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11363 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11364 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11365 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11366 remote_ops
.to_watchpoint_addr_within_range
=
11367 remote_watchpoint_addr_within_range
;
11368 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11369 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11370 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11371 remote_ops
.to_region_ok_for_hw_watchpoint
11372 = remote_region_ok_for_hw_watchpoint
;
11373 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11374 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11375 remote_ops
.to_kill
= remote_kill
;
11376 remote_ops
.to_load
= generic_load
;
11377 remote_ops
.to_mourn_inferior
= remote_mourn
;
11378 remote_ops
.to_pass_signals
= remote_pass_signals
;
11379 remote_ops
.to_program_signals
= remote_program_signals
;
11380 remote_ops
.to_thread_alive
= remote_thread_alive
;
11381 remote_ops
.to_find_new_threads
= remote_threads_info
;
11382 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11383 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11384 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11385 remote_ops
.to_stop
= remote_stop
;
11386 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11387 remote_ops
.to_rcmd
= remote_rcmd
;
11388 remote_ops
.to_log_command
= serial_log_command
;
11389 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11390 remote_ops
.to_stratum
= process_stratum
;
11391 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11392 remote_ops
.to_has_memory
= default_child_has_memory
;
11393 remote_ops
.to_has_stack
= default_child_has_stack
;
11394 remote_ops
.to_has_registers
= default_child_has_registers
;
11395 remote_ops
.to_has_execution
= default_child_has_execution
;
11396 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11397 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11398 remote_ops
.to_magic
= OPS_MAGIC
;
11399 remote_ops
.to_memory_map
= remote_memory_map
;
11400 remote_ops
.to_flash_erase
= remote_flash_erase
;
11401 remote_ops
.to_flash_done
= remote_flash_done
;
11402 remote_ops
.to_read_description
= remote_read_description
;
11403 remote_ops
.to_search_memory
= remote_search_memory
;
11404 remote_ops
.to_can_async_p
= remote_can_async_p
;
11405 remote_ops
.to_is_async_p
= remote_is_async_p
;
11406 remote_ops
.to_async
= remote_async
;
11407 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11408 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11409 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11410 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11411 remote_ops
.to_supports_disable_randomization
11412 = remote_supports_disable_randomization
;
11413 remote_ops
.to_fileio_open
= remote_hostio_open
;
11414 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11415 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11416 remote_ops
.to_fileio_close
= remote_hostio_close
;
11417 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11418 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11419 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11420 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11421 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11422 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11423 remote_ops
.to_trace_init
= remote_trace_init
;
11424 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11425 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11426 remote_ops
.to_download_trace_state_variable
11427 = remote_download_trace_state_variable
;
11428 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11429 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11430 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11431 remote_ops
.to_trace_start
= remote_trace_start
;
11432 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11433 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11434 remote_ops
.to_trace_stop
= remote_trace_stop
;
11435 remote_ops
.to_trace_find
= remote_trace_find
;
11436 remote_ops
.to_get_trace_state_variable_value
11437 = remote_get_trace_state_variable_value
;
11438 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11439 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11440 remote_ops
.to_upload_trace_state_variables
11441 = remote_upload_trace_state_variables
;
11442 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11443 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11444 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11445 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11446 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11447 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11448 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11449 remote_ops
.to_verify_memory
= remote_verify_memory
;
11450 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11451 remote_ops
.to_set_permissions
= remote_set_permissions
;
11452 remote_ops
.to_static_tracepoint_marker_at
11453 = remote_static_tracepoint_marker_at
;
11454 remote_ops
.to_static_tracepoint_markers_by_strid
11455 = remote_static_tracepoint_markers_by_strid
;
11456 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11457 remote_ops
.to_use_agent
= remote_use_agent
;
11458 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11459 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11460 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11461 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11462 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11463 remote_ops
.to_read_btrace
= remote_read_btrace
;
11466 /* Set up the extended remote vector by making a copy of the standard
11467 remote vector and adding to it. */
11470 init_extended_remote_ops (void)
11472 extended_remote_ops
= remote_ops
;
11474 extended_remote_ops
.to_shortname
= "extended-remote";
11475 extended_remote_ops
.to_longname
=
11476 "Extended remote serial target in gdb-specific protocol";
11477 extended_remote_ops
.to_doc
=
11478 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11479 Specify the serial device it is connected to (e.g. /dev/ttya).";
11480 extended_remote_ops
.to_open
= extended_remote_open
;
11481 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11482 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11483 extended_remote_ops
.to_detach
= extended_remote_detach
;
11484 extended_remote_ops
.to_attach
= extended_remote_attach
;
11485 extended_remote_ops
.to_kill
= extended_remote_kill
;
11486 extended_remote_ops
.to_supports_disable_randomization
11487 = extended_remote_supports_disable_randomization
;
11491 remote_can_async_p (void)
11493 if (!target_async_permitted
)
11494 /* We only enable async when the user specifically asks for it. */
11497 /* We're async whenever the serial device is. */
11498 return serial_can_async_p (remote_desc
);
11502 remote_is_async_p (void)
11504 if (!target_async_permitted
)
11505 /* We only enable async when the user specifically asks for it. */
11508 /* We're async whenever the serial device is. */
11509 return serial_is_async_p (remote_desc
);
11512 /* Pass the SERIAL event on and up to the client. One day this code
11513 will be able to delay notifying the client of an event until the
11514 point where an entire packet has been received. */
11516 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11518 static void *async_client_context
;
11519 static serial_event_ftype remote_async_serial_handler
;
11522 remote_async_serial_handler (struct serial
*scb
, void *context
)
11524 /* Don't propogate error information up to the client. Instead let
11525 the client find out about the error by querying the target. */
11526 async_client_callback (INF_REG_EVENT
, async_client_context
);
11530 remote_async_inferior_event_handler (gdb_client_data data
)
11532 inferior_event_handler (INF_REG_EVENT
, NULL
);
11536 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11537 void *context
), void *context
)
11539 if (callback
!= NULL
)
11541 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
11542 async_client_callback
= callback
;
11543 async_client_context
= context
;
11546 serial_async (remote_desc
, NULL
, NULL
);
11550 set_remote_cmd (char *args
, int from_tty
)
11552 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11556 show_remote_cmd (char *args
, int from_tty
)
11558 /* We can't just use cmd_show_list here, because we want to skip
11559 the redundant "show remote Z-packet" and the legacy aliases. */
11560 struct cleanup
*showlist_chain
;
11561 struct cmd_list_element
*list
= remote_show_cmdlist
;
11562 struct ui_out
*uiout
= current_uiout
;
11564 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11565 for (; list
!= NULL
; list
= list
->next
)
11566 if (strcmp (list
->name
, "Z-packet") == 0)
11568 else if (list
->type
== not_set_cmd
)
11569 /* Alias commands are exactly like the original, except they
11570 don't have the normal type. */
11574 struct cleanup
*option_chain
11575 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11577 ui_out_field_string (uiout
, "name", list
->name
);
11578 ui_out_text (uiout
, ": ");
11579 if (list
->type
== show_cmd
)
11580 do_show_command ((char *) NULL
, from_tty
, list
);
11582 cmd_func (list
, NULL
, from_tty
);
11583 /* Close the tuple. */
11584 do_cleanups (option_chain
);
11587 /* Close the tuple. */
11588 do_cleanups (showlist_chain
);
11592 /* Function to be called whenever a new objfile (shlib) is detected. */
11594 remote_new_objfile (struct objfile
*objfile
)
11596 if (remote_desc
!= 0) /* Have a remote connection. */
11597 remote_check_symbols (objfile
);
11600 /* Pull all the tracepoints defined on the target and create local
11601 data structures representing them. We don't want to create real
11602 tracepoints yet, we don't want to mess up the user's existing
11606 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11608 struct remote_state
*rs
= get_remote_state ();
11611 /* Ask for a first packet of tracepoint definition. */
11613 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11615 while (*p
&& *p
!= 'l')
11617 parse_tracepoint_definition (p
, utpp
);
11618 /* Ask for another packet of tracepoint definition. */
11620 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11627 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11629 struct remote_state
*rs
= get_remote_state ();
11632 /* Ask for a first packet of variable definition. */
11634 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11636 while (*p
&& *p
!= 'l')
11638 parse_tsv_definition (p
, utsvp
);
11639 /* Ask for another packet of variable definition. */
11641 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11648 _initialize_remote (void)
11650 struct remote_state
*rs
;
11651 struct cmd_list_element
*cmd
;
11652 const char *cmd_name
;
11654 /* architecture specific data */
11655 remote_gdbarch_data_handle
=
11656 gdbarch_data_register_post_init (init_remote_state
);
11657 remote_g_packet_data_handle
=
11658 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11660 /* Initialize the per-target state. At the moment there is only one
11661 of these, not one per target. Only one target is active at a
11662 time. The default buffer size is unimportant; it will be expanded
11663 whenever a larger buffer is needed. */
11664 rs
= get_remote_state_raw ();
11665 rs
->buf_size
= 400;
11666 rs
->buf
= xmalloc (rs
->buf_size
);
11668 init_remote_ops ();
11669 add_target (&remote_ops
);
11671 init_extended_remote_ops ();
11672 add_target (&extended_remote_ops
);
11674 /* Hook into new objfile notification. */
11675 observer_attach_new_objfile (remote_new_objfile
);
11676 /* We're no longer interested in notification events of an inferior
11678 observer_attach_inferior_exit (discard_pending_stop_replies
);
11680 /* Set up signal handlers. */
11681 sigint_remote_token
=
11682 create_async_signal_handler (async_remote_interrupt
, NULL
);
11683 sigint_remote_twice_token
=
11684 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11687 init_remote_threadtests ();
11690 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11691 /* set/show remote ... */
11693 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11694 Remote protocol specific variables\n\
11695 Configure various remote-protocol specific variables such as\n\
11696 the packets being used"),
11697 &remote_set_cmdlist
, "set remote ",
11698 0 /* allow-unknown */, &setlist
);
11699 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11700 Remote protocol specific variables\n\
11701 Configure various remote-protocol specific variables such as\n\
11702 the packets being used"),
11703 &remote_show_cmdlist
, "show remote ",
11704 0 /* allow-unknown */, &showlist
);
11706 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11707 Compare section data on target to the exec file.\n\
11708 Argument is a single section name (default: all loaded sections)."),
11711 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11712 Send an arbitrary packet to a remote target.\n\
11713 maintenance packet TEXT\n\
11714 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11715 this command sends the string TEXT to the inferior, and displays the\n\
11716 response packet. GDB supplies the initial `$' character, and the\n\
11717 terminating `#' character and checksum."),
11720 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11721 Set whether to send break if interrupted."), _("\
11722 Show whether to send break if interrupted."), _("\
11723 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11724 set_remotebreak
, show_remotebreak
,
11725 &setlist
, &showlist
);
11726 cmd_name
= "remotebreak";
11727 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11728 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11729 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11730 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11731 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11733 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11734 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11736 Set interrupt sequence to remote target."), _("\
11737 Show interrupt sequence to remote target."), _("\
11738 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11739 NULL
, show_interrupt_sequence
,
11740 &remote_set_cmdlist
,
11741 &remote_show_cmdlist
);
11743 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11744 &interrupt_on_connect
, _("\
11745 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11746 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11747 If set, interrupt sequence is sent to remote target."),
11749 &remote_set_cmdlist
, &remote_show_cmdlist
);
11751 /* Install commands for configuring memory read/write packets. */
11753 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11754 Set the maximum number of bytes per memory write packet (deprecated)."),
11756 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11757 Show the maximum number of bytes per memory write packet (deprecated)."),
11759 add_cmd ("memory-write-packet-size", no_class
,
11760 set_memory_write_packet_size
, _("\
11761 Set the maximum number of bytes per memory-write packet.\n\
11762 Specify the number of bytes in a packet or 0 (zero) for the\n\
11763 default packet size. The actual limit is further reduced\n\
11764 dependent on the target. Specify ``fixed'' to disable the\n\
11765 further restriction and ``limit'' to enable that restriction."),
11766 &remote_set_cmdlist
);
11767 add_cmd ("memory-read-packet-size", no_class
,
11768 set_memory_read_packet_size
, _("\
11769 Set the maximum number of bytes per memory-read packet.\n\
11770 Specify the number of bytes in a packet or 0 (zero) for the\n\
11771 default packet size. The actual limit is further reduced\n\
11772 dependent on the target. Specify ``fixed'' to disable the\n\
11773 further restriction and ``limit'' to enable that restriction."),
11774 &remote_set_cmdlist
);
11775 add_cmd ("memory-write-packet-size", no_class
,
11776 show_memory_write_packet_size
,
11777 _("Show the maximum number of bytes per memory-write packet."),
11778 &remote_show_cmdlist
);
11779 add_cmd ("memory-read-packet-size", no_class
,
11780 show_memory_read_packet_size
,
11781 _("Show the maximum number of bytes per memory-read packet."),
11782 &remote_show_cmdlist
);
11784 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11785 &remote_hw_watchpoint_limit
, _("\
11786 Set the maximum number of target hardware watchpoints."), _("\
11787 Show the maximum number of target hardware watchpoints."), _("\
11788 Specify a negative limit for unlimited."),
11789 NULL
, NULL
, /* FIXME: i18n: The maximum
11790 number of target hardware
11791 watchpoints is %s. */
11792 &remote_set_cmdlist
, &remote_show_cmdlist
);
11793 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11794 &remote_hw_watchpoint_length_limit
, _("\
11795 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11796 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11797 Specify a negative limit for unlimited."),
11798 NULL
, NULL
, /* FIXME: i18n: The maximum
11799 length (in bytes) of a target
11800 hardware watchpoint is %s. */
11801 &remote_set_cmdlist
, &remote_show_cmdlist
);
11802 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11803 &remote_hw_breakpoint_limit
, _("\
11804 Set the maximum number of target hardware breakpoints."), _("\
11805 Show the maximum number of target hardware breakpoints."), _("\
11806 Specify a negative limit for unlimited."),
11807 NULL
, NULL
, /* FIXME: i18n: The maximum
11808 number of target hardware
11809 breakpoints is %s. */
11810 &remote_set_cmdlist
, &remote_show_cmdlist
);
11812 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11813 &remote_address_size
, _("\
11814 Set the maximum size of the address (in bits) in a memory packet."), _("\
11815 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11817 NULL
, /* FIXME: i18n: */
11818 &setlist
, &showlist
);
11820 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11821 "X", "binary-download", 1);
11823 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11824 "vCont", "verbose-resume", 0);
11826 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11827 "QPassSignals", "pass-signals", 0);
11829 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11830 "QProgramSignals", "program-signals", 0);
11832 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11833 "qSymbol", "symbol-lookup", 0);
11835 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11836 "P", "set-register", 1);
11838 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11839 "p", "fetch-register", 1);
11841 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11842 "Z0", "software-breakpoint", 0);
11844 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11845 "Z1", "hardware-breakpoint", 0);
11847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11848 "Z2", "write-watchpoint", 0);
11850 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11851 "Z3", "read-watchpoint", 0);
11853 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11854 "Z4", "access-watchpoint", 0);
11856 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11857 "qXfer:auxv:read", "read-aux-vector", 0);
11859 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11860 "qXfer:features:read", "target-features", 0);
11862 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11863 "qXfer:libraries:read", "library-info", 0);
11865 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11866 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11868 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11869 "qXfer:memory-map:read", "memory-map", 0);
11871 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11872 "qXfer:spu:read", "read-spu-object", 0);
11874 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11875 "qXfer:spu:write", "write-spu-object", 0);
11877 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11878 "qXfer:osdata:read", "osdata", 0);
11880 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11881 "qXfer:threads:read", "threads", 0);
11883 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11884 "qXfer:siginfo:read", "read-siginfo-object", 0);
11886 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11887 "qXfer:siginfo:write", "write-siginfo-object", 0);
11889 add_packet_config_cmd
11890 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11891 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11893 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
11894 "qXfer:uib:read", "unwind-info-block", 0);
11896 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11897 "qGetTLSAddr", "get-thread-local-storage-address",
11900 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11901 "qGetTIBAddr", "get-thread-information-block-address",
11904 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11905 "bc", "reverse-continue", 0);
11907 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11908 "bs", "reverse-step", 0);
11910 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11911 "qSupported", "supported-packets", 0);
11913 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11914 "qSearch:memory", "search-memory", 0);
11916 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
11917 "qTStatus", "trace-status", 0);
11919 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11920 "vFile:open", "hostio-open", 0);
11922 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11923 "vFile:pread", "hostio-pread", 0);
11925 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11926 "vFile:pwrite", "hostio-pwrite", 0);
11928 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11929 "vFile:close", "hostio-close", 0);
11931 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11932 "vFile:unlink", "hostio-unlink", 0);
11934 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11935 "vFile:readlink", "hostio-readlink", 0);
11937 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11938 "vAttach", "attach", 0);
11940 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11943 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11944 "QStartNoAckMode", "noack", 0);
11946 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11947 "vKill", "kill", 0);
11949 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11950 "qAttached", "query-attached", 0);
11952 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11953 "ConditionalTracepoints",
11954 "conditional-tracepoints", 0);
11956 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
11957 "ConditionalBreakpoints",
11958 "conditional-breakpoints", 0);
11960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
11961 "BreakpointCommands",
11962 "breakpoint-commands", 0);
11964 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11965 "FastTracepoints", "fast-tracepoints", 0);
11967 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11968 "TracepointSource", "TracepointSource", 0);
11970 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11971 "QAllow", "allow", 0);
11973 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11974 "StaticTracepoints", "static-tracepoints", 0);
11976 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11977 "InstallInTrace", "install-in-trace", 0);
11979 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11980 "qXfer:statictrace:read", "read-sdata-object", 0);
11982 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11983 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11985 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11986 "QDisableRandomization", "disable-randomization", 0);
11988 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
11989 "QAgent", "agent", 0);
11991 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
11992 "QTBuffer:size", "trace-buffer-size", 0);
11994 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
11995 "Qbtrace:off", "disable-btrace", 0);
11997 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
11998 "Qbtrace:bts", "enable-btrace", 0);
12000 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12001 "qXfer:btrace", "read-btrace", 0);
12003 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12004 Z sub-packet has its own set and show commands, but users may
12005 have sets to this variable in their .gdbinit files (or in their
12007 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12008 &remote_Z_packet_detect
, _("\
12009 Set use of remote protocol `Z' packets"), _("\
12010 Show use of remote protocol `Z' packets "), _("\
12011 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12013 set_remote_protocol_Z_packet_cmd
,
12014 show_remote_protocol_Z_packet_cmd
,
12015 /* FIXME: i18n: Use of remote protocol
12016 `Z' packets is %s. */
12017 &remote_set_cmdlist
, &remote_show_cmdlist
);
12019 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12020 Manipulate files on the remote system\n\
12021 Transfer files to and from the remote target system."),
12022 &remote_cmdlist
, "remote ",
12023 0 /* allow-unknown */, &cmdlist
);
12025 add_cmd ("put", class_files
, remote_put_command
,
12026 _("Copy a local file to the remote system."),
12029 add_cmd ("get", class_files
, remote_get_command
,
12030 _("Copy a remote file to the local system."),
12033 add_cmd ("delete", class_files
, remote_delete_command
,
12034 _("Delete a remote file."),
12037 remote_exec_file
= xstrdup ("");
12038 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12039 &remote_exec_file
, _("\
12040 Set the remote pathname for \"run\""), _("\
12041 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12042 &remote_set_cmdlist
, &remote_show_cmdlist
);
12044 /* Eventually initialize fileio. See fileio.c */
12045 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12047 /* Take advantage of the fact that the LWP field is not used, to tag
12048 special ptids with it set to != 0. */
12049 magic_null_ptid
= ptid_build (42000, 1, -1);
12050 not_sent_ptid
= ptid_build (42000, 1, -2);
12051 any_thread_ptid
= ptid_build (42000, 1, 0);
12053 target_buf_size
= 2048;
12054 target_buf
= xmalloc (target_buf_size
);