1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2015 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. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
60 #include "gdb/fileio.h"
62 #include "xml-support.h"
64 #include "memory-map.h"
66 #include "tracepoint.h"
72 /* Temp hacks for tracepoint encoding migration. */
73 static char *target_buf
;
74 static long target_buf_size
;
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void async_cleanup_sigint_signal_handler (void *dummy
);
90 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
91 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
92 int forever
, int *is_notif
);
94 static void async_handle_remote_sigint (int);
95 static void async_handle_remote_sigint_twice (int);
97 static void remote_files_info (struct target_ops
*ignore
);
99 static void remote_prepare_to_store (struct target_ops
*self
,
100 struct regcache
*regcache
);
102 static void remote_open_1 (const char *, int, struct target_ops
*,
105 static void remote_close (struct target_ops
*self
);
107 static void remote_mourn (struct target_ops
*ops
);
109 static void extended_remote_restart (void);
111 static void extended_remote_mourn (struct target_ops
*);
113 static void remote_send (char **buf
, long *sizeof_buf_p
);
115 static int readchar (int timeout
);
117 static void remote_serial_write (const char *str
, int len
);
119 static void remote_kill (struct target_ops
*ops
);
121 static int remote_can_async_p (struct target_ops
*);
123 static int remote_is_async_p (struct target_ops
*);
125 static void remote_async (struct target_ops
*ops
, int enable
);
127 static void sync_remote_interrupt_twice (int signo
);
129 static void interrupt_query (void);
131 static void set_general_thread (struct ptid ptid
);
132 static void set_continue_thread (struct ptid ptid
);
134 static void get_offsets (void);
136 static void skip_frame (void);
138 static long read_frame (char **buf_p
, long *sizeof_buf
);
140 static int hexnumlen (ULONGEST num
);
142 static void init_remote_ops (void);
144 static void init_extended_remote_ops (void);
146 static void remote_stop (struct target_ops
*self
, ptid_t
);
148 static int stubhex (int ch
);
150 static int hexnumstr (char *, ULONGEST
);
152 static int hexnumnstr (char *, ULONGEST
, int);
154 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
156 static void print_packet (const char *);
158 static void compare_sections_command (char *, int);
160 static void packet_command (char *, int);
162 static int stub_unpack_int (char *buff
, int fieldlength
);
164 static ptid_t
remote_current_thread (ptid_t oldptid
);
166 static int putpkt_binary (const char *buf
, int cnt
);
168 static void check_binary_download (CORE_ADDR addr
);
170 struct packet_config
;
172 static void show_packet_config_cmd (struct packet_config
*config
);
174 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
176 struct cmd_list_element
*c
,
179 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
180 static ptid_t
read_ptid (char *buf
, char **obuf
);
182 static void remote_set_permissions (struct target_ops
*self
);
185 static int remote_get_trace_status (struct target_ops
*self
,
186 struct trace_status
*ts
);
188 static int remote_upload_tracepoints (struct target_ops
*self
,
189 struct uploaded_tp
**utpp
);
191 static int remote_upload_trace_state_variables (struct target_ops
*self
,
192 struct uploaded_tsv
**utsvp
);
194 static void remote_query_supported (void);
196 static void remote_check_symbols (void);
198 void _initialize_remote (void);
201 static void stop_reply_xfree (struct stop_reply
*);
202 static void remote_parse_stop_reply (char *, struct stop_reply
*);
203 static void push_stop_reply (struct stop_reply
*);
204 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
205 static int peek_stop_reply (ptid_t ptid
);
207 static void remote_async_inferior_event_handler (gdb_client_data
);
209 static void remote_terminal_ours (struct target_ops
*self
);
211 static int remote_read_description_p (struct target_ops
*target
);
213 static void remote_console_output (char *msg
);
215 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
217 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
219 static void remote_btrace_reset (void);
223 static struct cmd_list_element
*remote_cmdlist
;
225 /* For "set remote" and "show remote". */
227 static struct cmd_list_element
*remote_set_cmdlist
;
228 static struct cmd_list_element
*remote_show_cmdlist
;
230 /* Stub vCont actions support.
232 Each field is a boolean flag indicating whether the stub reports
233 support for the corresponding action. */
235 struct vCont_action_support
244 /* Controls whether GDB is willing to use range stepping. */
246 static int use_range_stepping
= 1;
248 #define OPAQUETHREADBYTES 8
250 /* a 64 bit opaque identifier */
251 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
253 /* About this many threadisds fit in a packet. */
255 #define MAXTHREADLISTRESULTS 32
257 /* Description of the remote protocol state for the currently
258 connected target. This is per-target state, and independent of the
259 selected architecture. */
263 /* A buffer to use for incoming packets, and its current size. The
264 buffer is grown dynamically for larger incoming packets.
265 Outgoing packets may also be constructed in this buffer.
266 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
267 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
272 /* True if we're going through initial connection setup (finding out
273 about the remote side's threads, relocating symbols, etc.). */
276 /* If we negotiated packet size explicitly (and thus can bypass
277 heuristics for the largest packet size that will not overflow
278 a buffer in the stub), this will be set to that packet size.
279 Otherwise zero, meaning to use the guessed size. */
280 long explicit_packet_size
;
282 /* remote_wait is normally called when the target is running and
283 waits for a stop reply packet. But sometimes we need to call it
284 when the target is already stopped. We can send a "?" packet
285 and have remote_wait read the response. Or, if we already have
286 the response, we can stash it in BUF and tell remote_wait to
287 skip calling getpkt. This flag is set when BUF contains a
288 stop reply packet and the target is not waiting. */
289 int cached_wait_status
;
291 /* True, if in no ack mode. That is, neither GDB nor the stub will
292 expect acks from each other. The connection is assumed to be
296 /* True if we're connected in extended remote mode. */
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 /* The status of the stub support for the various vCont actions. */
308 struct vCont_action_support supports_vCont
;
310 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
311 responded to that. */
314 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
315 remote_open knows that we don't have a file open when the program
317 struct serial
*remote_desc
;
319 /* These are the threads which we last sent to the remote system. The
320 TID member will be -1 for all or -2 for not sent yet. */
321 ptid_t general_thread
;
322 ptid_t continue_thread
;
324 /* This is the traceframe which we last selected on the remote system.
325 It will be -1 if no traceframe is selected. */
326 int remote_traceframe_number
;
328 char *last_pass_packet
;
330 /* The last QProgramSignals packet sent to the target. We bypass
331 sending a new program signals list down to the target if the new
332 packet is exactly the same as the last we sent. IOW, we only let
333 the target know about program signals list changes. */
334 char *last_program_signals_packet
;
336 enum gdb_signal last_sent_signal
;
340 char *finished_object
;
341 char *finished_annex
;
342 ULONGEST finished_offset
;
344 /* Should we try the 'ThreadInfo' query packet?
346 This variable (NOT available to the user: auto-detect only!)
347 determines whether GDB will use the new, simpler "ThreadInfo"
348 query or the older, more complex syntax for thread queries.
349 This is an auto-detect variable (set to true at each connect,
350 and set to false when the target fails to recognize it). */
351 int use_threadinfo_query
;
352 int use_threadextra_query
;
354 /* This is set to the data address of the access causing the target
355 to stop for a watchpoint. */
356 CORE_ADDR remote_watch_data_address
;
358 /* Whether the target stopped for a breakpoint/watchpoint. */
359 enum target_stop_reason stop_reason
;
361 threadref echo_nextthread
;
362 threadref nextthread
;
363 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
365 /* The state of remote notification. */
366 struct remote_notif_state
*notif_state
;
368 /* The branch trace configuration. */
369 struct btrace_config btrace_config
;
372 /* Private data that we'll store in (struct thread_info)->private. */
373 struct private_thread_info
380 free_private_thread_info (struct private_thread_info
*info
)
386 /* This data could be associated with a target, but we do not always
387 have access to the current target when we need it, so for now it is
388 static. This will be fine for as long as only one target is in use
390 static struct remote_state
*remote_state
;
392 static struct remote_state
*
393 get_remote_state_raw (void)
398 /* Allocate a new struct remote_state with xmalloc, initialize it, and
401 static struct remote_state
*
402 new_remote_state (void)
404 struct remote_state
*result
= XCNEW (struct remote_state
);
406 /* The default buffer size is unimportant; it will be expanded
407 whenever a larger buffer is needed. */
408 result
->buf_size
= 400;
409 result
->buf
= xmalloc (result
->buf_size
);
410 result
->remote_traceframe_number
= -1;
411 result
->last_sent_signal
= GDB_SIGNAL_0
;
416 /* Description of the remote protocol for a given architecture. */
420 long offset
; /* Offset into G packet. */
421 long regnum
; /* GDB's internal register number. */
422 LONGEST pnum
; /* Remote protocol register number. */
423 int in_g_packet
; /* Always part of G packet. */
424 /* long size in bytes; == register_size (target_gdbarch (), regnum);
426 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
430 struct remote_arch_state
432 /* Description of the remote protocol registers. */
433 long sizeof_g_packet
;
435 /* Description of the remote protocol registers indexed by REGNUM
436 (making an array gdbarch_num_regs in size). */
437 struct packet_reg
*regs
;
439 /* This is the size (in chars) of the first response to the ``g''
440 packet. It is used as a heuristic when determining the maximum
441 size of memory-read and memory-write packets. A target will
442 typically only reserve a buffer large enough to hold the ``g''
443 packet. The size does not include packet overhead (headers and
445 long actual_register_packet_size
;
447 /* This is the maximum size (in chars) of a non read/write packet.
448 It is also used as a cap on the size of read/write packets. */
449 long remote_packet_size
;
452 /* Utility: generate error from an incoming stub packet. */
454 trace_error (char *buf
)
457 return; /* not an error msg */
460 case '1': /* malformed packet error */
461 if (*++buf
== '0') /* general case: */
462 error (_("remote.c: error in outgoing packet."));
464 error (_("remote.c: error in outgoing packet at field #%ld."),
465 strtol (buf
, NULL
, 16));
467 error (_("Target returns error code '%s'."), buf
);
471 /* Utility: wait for reply from stub, while accepting "O" packets. */
473 remote_get_noisy_reply (char **buf_p
,
476 do /* Loop on reply from remote stub. */
480 QUIT
; /* Allow user to bail out with ^C. */
481 getpkt (buf_p
, sizeof_buf
, 0);
485 else if (startswith (buf
, "qRelocInsn:"))
488 CORE_ADDR from
, to
, org_to
;
490 int adjusted_size
= 0;
493 p
= buf
+ strlen ("qRelocInsn:");
494 pp
= unpack_varlen_hex (p
, &ul
);
496 error (_("invalid qRelocInsn packet: %s"), buf
);
500 unpack_varlen_hex (p
, &ul
);
507 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
510 CATCH (ex
, RETURN_MASK_ALL
)
512 if (ex
.error
== MEMORY_ERROR
)
514 /* Propagate memory errors silently back to the
515 target. The stub may have limited the range of
516 addresses we can write to, for example. */
520 /* Something unexpectedly bad happened. Be verbose
521 so we can tell what, and propagate the error back
522 to the stub, so it doesn't get stuck waiting for
524 exception_fprintf (gdb_stderr
, ex
,
525 _("warning: relocating instruction: "));
533 adjusted_size
= to
- org_to
;
535 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
539 else if (buf
[0] == 'O' && buf
[1] != 'K')
540 remote_console_output (buf
+ 1); /* 'O' message from stub */
542 return buf
; /* Here's the actual reply. */
547 /* Handle for retreving the remote protocol data from gdbarch. */
548 static struct gdbarch_data
*remote_gdbarch_data_handle
;
550 static struct remote_arch_state
*
551 get_remote_arch_state (void)
553 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
556 /* Fetch the global remote target state. */
558 static struct remote_state
*
559 get_remote_state (void)
561 /* Make sure that the remote architecture state has been
562 initialized, because doing so might reallocate rs->buf. Any
563 function which calls getpkt also needs to be mindful of changes
564 to rs->buf, but this call limits the number of places which run
566 get_remote_arch_state ();
568 return get_remote_state_raw ();
572 compare_pnums (const void *lhs_
, const void *rhs_
)
574 const struct packet_reg
* const *lhs
= lhs_
;
575 const struct packet_reg
* const *rhs
= rhs_
;
577 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
579 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
586 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
588 int regnum
, num_remote_regs
, offset
;
589 struct packet_reg
**remote_regs
;
591 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
593 struct packet_reg
*r
= ®s
[regnum
];
595 if (register_size (gdbarch
, regnum
) == 0)
596 /* Do not try to fetch zero-sized (placeholder) registers. */
599 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
604 /* Define the g/G packet format as the contents of each register
605 with a remote protocol number, in order of ascending protocol
608 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
609 * sizeof (struct packet_reg
*));
610 for (num_remote_regs
= 0, regnum
= 0;
611 regnum
< gdbarch_num_regs (gdbarch
);
613 if (regs
[regnum
].pnum
!= -1)
614 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
616 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
619 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
621 remote_regs
[regnum
]->in_g_packet
= 1;
622 remote_regs
[regnum
]->offset
= offset
;
623 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
629 /* Given the architecture described by GDBARCH, return the remote
630 protocol register's number and the register's offset in the g/G
631 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
632 If the target does not have a mapping for REGNUM, return false,
633 otherwise, return true. */
636 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
637 int *pnum
, int *poffset
)
640 struct packet_reg
*regs
;
641 struct cleanup
*old_chain
;
643 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
645 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
646 old_chain
= make_cleanup (xfree
, regs
);
648 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
650 *pnum
= regs
[regnum
].pnum
;
651 *poffset
= regs
[regnum
].offset
;
653 do_cleanups (old_chain
);
659 init_remote_state (struct gdbarch
*gdbarch
)
661 struct remote_state
*rs
= get_remote_state_raw ();
662 struct remote_arch_state
*rsa
;
664 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
666 /* Use the architecture to build a regnum<->pnum table, which will be
667 1:1 unless a feature set specifies otherwise. */
668 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
669 gdbarch_num_regs (gdbarch
),
672 /* Record the maximum possible size of the g packet - it may turn out
674 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
676 /* Default maximum number of characters in a packet body. Many
677 remote stubs have a hardwired buffer size of 400 bytes
678 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
679 as the maximum packet-size to ensure that the packet and an extra
680 NUL character can always fit in the buffer. This stops GDB
681 trashing stubs that try to squeeze an extra NUL into what is
682 already a full buffer (As of 1999-12-04 that was most stubs). */
683 rsa
->remote_packet_size
= 400 - 1;
685 /* This one is filled in when a ``g'' packet is received. */
686 rsa
->actual_register_packet_size
= 0;
688 /* Should rsa->sizeof_g_packet needs more space than the
689 default, adjust the size accordingly. Remember that each byte is
690 encoded as two characters. 32 is the overhead for the packet
691 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
692 (``$NN:G...#NN'') is a better guess, the below has been padded a
694 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
695 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
697 /* Make sure that the packet buffer is plenty big enough for
698 this architecture. */
699 if (rs
->buf_size
< rsa
->remote_packet_size
)
701 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
702 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
708 /* Return the current allowed size of a remote packet. This is
709 inferred from the current architecture, and should be used to
710 limit the length of outgoing packets. */
712 get_remote_packet_size (void)
714 struct remote_state
*rs
= get_remote_state ();
715 struct remote_arch_state
*rsa
= get_remote_arch_state ();
717 if (rs
->explicit_packet_size
)
718 return rs
->explicit_packet_size
;
720 return rsa
->remote_packet_size
;
723 static struct packet_reg
*
724 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
726 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
730 struct packet_reg
*r
= &rsa
->regs
[regnum
];
732 gdb_assert (r
->regnum
== regnum
);
737 static struct packet_reg
*
738 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
742 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
744 struct packet_reg
*r
= &rsa
->regs
[i
];
752 static struct target_ops remote_ops
;
754 static struct target_ops extended_remote_ops
;
756 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
757 ``forever'' still use the normal timeout mechanism. This is
758 currently used by the ASYNC code to guarentee that target reads
759 during the initial connect always time-out. Once getpkt has been
760 modified to return a timeout indication and, in turn
761 remote_wait()/wait_for_inferior() have gained a timeout parameter
763 static int wait_forever_enabled_p
= 1;
765 /* Allow the user to specify what sequence to send to the remote
766 when he requests a program interruption: Although ^C is usually
767 what remote systems expect (this is the default, here), it is
768 sometimes preferable to send a break. On other systems such
769 as the Linux kernel, a break followed by g, which is Magic SysRq g
770 is required in order to interrupt the execution. */
771 const char interrupt_sequence_control_c
[] = "Ctrl-C";
772 const char interrupt_sequence_break
[] = "BREAK";
773 const char interrupt_sequence_break_g
[] = "BREAK-g";
774 static const char *const interrupt_sequence_modes
[] =
776 interrupt_sequence_control_c
,
777 interrupt_sequence_break
,
778 interrupt_sequence_break_g
,
781 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
784 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
785 struct cmd_list_element
*c
,
788 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
789 fprintf_filtered (file
,
790 _("Send the ASCII ETX character (Ctrl-c) "
791 "to the remote target to interrupt the "
792 "execution of the program.\n"));
793 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
794 fprintf_filtered (file
,
795 _("send a break signal to the remote target "
796 "to interrupt the execution of the program.\n"));
797 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
798 fprintf_filtered (file
,
799 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
800 "the remote target to interrupt the execution "
801 "of Linux kernel.\n"));
803 internal_error (__FILE__
, __LINE__
,
804 _("Invalid value for interrupt_sequence_mode: %s."),
805 interrupt_sequence_mode
);
808 /* This boolean variable specifies whether interrupt_sequence is sent
809 to the remote target when gdb connects to it.
810 This is mostly needed when you debug the Linux kernel: The Linux kernel
811 expects BREAK g which is Magic SysRq g for connecting gdb. */
812 static int interrupt_on_connect
= 0;
814 /* This variable is used to implement the "set/show remotebreak" commands.
815 Since these commands are now deprecated in favor of "set/show remote
816 interrupt-sequence", it no longer has any effect on the code. */
817 static int remote_break
;
820 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
823 interrupt_sequence_mode
= interrupt_sequence_break
;
825 interrupt_sequence_mode
= interrupt_sequence_control_c
;
829 show_remotebreak (struct ui_file
*file
, int from_tty
,
830 struct cmd_list_element
*c
,
835 /* This variable sets the number of bits in an address that are to be
836 sent in a memory ("M" or "m") packet. Normally, after stripping
837 leading zeros, the entire address would be sent. This variable
838 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
839 initial implementation of remote.c restricted the address sent in
840 memory packets to ``host::sizeof long'' bytes - (typically 32
841 bits). Consequently, for 64 bit targets, the upper 32 bits of an
842 address was never sent. Since fixing this bug may cause a break in
843 some remote targets this variable is principly provided to
844 facilitate backward compatibility. */
846 static unsigned int remote_address_size
;
848 /* Temporary to track who currently owns the terminal. See
849 remote_terminal_* for more details. */
851 static int remote_async_terminal_ours_p
;
853 /* The executable file to use for "run" on the remote side. */
855 static char *remote_exec_file
= "";
858 /* User configurable variables for the number of characters in a
859 memory read/write packet. MIN (rsa->remote_packet_size,
860 rsa->sizeof_g_packet) is the default. Some targets need smaller
861 values (fifo overruns, et.al.) and some users need larger values
862 (speed up transfers). The variables ``preferred_*'' (the user
863 request), ``current_*'' (what was actually set) and ``forced_*''
864 (Positive - a soft limit, negative - a hard limit). */
866 struct memory_packet_config
873 /* Compute the current size of a read/write packet. Since this makes
874 use of ``actual_register_packet_size'' the computation is dynamic. */
877 get_memory_packet_size (struct memory_packet_config
*config
)
879 struct remote_state
*rs
= get_remote_state ();
880 struct remote_arch_state
*rsa
= get_remote_arch_state ();
882 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
883 law?) that some hosts don't cope very well with large alloca()
884 calls. Eventually the alloca() code will be replaced by calls to
885 xmalloc() and make_cleanups() allowing this restriction to either
886 be lifted or removed. */
887 #ifndef MAX_REMOTE_PACKET_SIZE
888 #define MAX_REMOTE_PACKET_SIZE 16384
890 /* NOTE: 20 ensures we can write at least one byte. */
891 #ifndef MIN_REMOTE_PACKET_SIZE
892 #define MIN_REMOTE_PACKET_SIZE 20
897 if (config
->size
<= 0)
898 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
900 what_they_get
= config
->size
;
904 what_they_get
= get_remote_packet_size ();
905 /* Limit the packet to the size specified by the user. */
907 && what_they_get
> config
->size
)
908 what_they_get
= config
->size
;
910 /* Limit it to the size of the targets ``g'' response unless we have
911 permission from the stub to use a larger packet size. */
912 if (rs
->explicit_packet_size
== 0
913 && rsa
->actual_register_packet_size
> 0
914 && what_they_get
> rsa
->actual_register_packet_size
)
915 what_they_get
= rsa
->actual_register_packet_size
;
917 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
918 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
919 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
920 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
922 /* Make sure there is room in the global buffer for this packet
923 (including its trailing NUL byte). */
924 if (rs
->buf_size
< what_they_get
+ 1)
926 rs
->buf_size
= 2 * what_they_get
;
927 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
930 return what_they_get
;
933 /* Update the size of a read/write packet. If they user wants
934 something really big then do a sanity check. */
937 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
939 int fixed_p
= config
->fixed_p
;
940 long size
= config
->size
;
943 error (_("Argument required (integer, `fixed' or `limited')."));
944 else if (strcmp (args
, "hard") == 0
945 || strcmp (args
, "fixed") == 0)
947 else if (strcmp (args
, "soft") == 0
948 || strcmp (args
, "limit") == 0)
954 size
= strtoul (args
, &end
, 0);
956 error (_("Invalid %s (bad syntax)."), config
->name
);
958 /* Instead of explicitly capping the size of a packet to
959 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
960 instead allowed to set the size to something arbitrarily
962 if (size
> MAX_REMOTE_PACKET_SIZE
)
963 error (_("Invalid %s (too large)."), config
->name
);
967 if (fixed_p
&& !config
->fixed_p
)
969 if (! query (_("The target may not be able to correctly handle a %s\n"
970 "of %ld bytes. Change the packet size? "),
972 error (_("Packet size not changed."));
974 /* Update the config. */
975 config
->fixed_p
= fixed_p
;
980 show_memory_packet_size (struct memory_packet_config
*config
)
982 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
984 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
985 get_memory_packet_size (config
));
987 printf_filtered (_("Packets are limited to %ld bytes.\n"),
988 get_memory_packet_size (config
));
991 static struct memory_packet_config memory_write_packet_config
=
993 "memory-write-packet-size",
997 set_memory_write_packet_size (char *args
, int from_tty
)
999 set_memory_packet_size (args
, &memory_write_packet_config
);
1003 show_memory_write_packet_size (char *args
, int from_tty
)
1005 show_memory_packet_size (&memory_write_packet_config
);
1009 get_memory_write_packet_size (void)
1011 return get_memory_packet_size (&memory_write_packet_config
);
1014 static struct memory_packet_config memory_read_packet_config
=
1016 "memory-read-packet-size",
1020 set_memory_read_packet_size (char *args
, int from_tty
)
1022 set_memory_packet_size (args
, &memory_read_packet_config
);
1026 show_memory_read_packet_size (char *args
, int from_tty
)
1028 show_memory_packet_size (&memory_read_packet_config
);
1032 get_memory_read_packet_size (void)
1034 long size
= get_memory_packet_size (&memory_read_packet_config
);
1036 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1037 extra buffer size argument before the memory read size can be
1038 increased beyond this. */
1039 if (size
> get_remote_packet_size ())
1040 size
= get_remote_packet_size ();
1045 /* Generic configuration support for packets the stub optionally
1046 supports. Allows the user to specify the use of the packet as well
1047 as allowing GDB to auto-detect support in the remote stub. */
1051 PACKET_SUPPORT_UNKNOWN
= 0,
1056 struct packet_config
1061 /* If auto, GDB auto-detects support for this packet or feature,
1062 either through qSupported, or by trying the packet and looking
1063 at the response. If true, GDB assumes the target supports this
1064 packet. If false, the packet is disabled. Configs that don't
1065 have an associated command always have this set to auto. */
1066 enum auto_boolean detect
;
1068 /* Does the target support this packet? */
1069 enum packet_support support
;
1072 /* Analyze a packet's return value and update the packet config
1082 static enum packet_support
packet_config_support (struct packet_config
*config
);
1083 static enum packet_support
packet_support (int packet
);
1086 show_packet_config_cmd (struct packet_config
*config
)
1088 char *support
= "internal-error";
1090 switch (packet_config_support (config
))
1093 support
= "enabled";
1095 case PACKET_DISABLE
:
1096 support
= "disabled";
1098 case PACKET_SUPPORT_UNKNOWN
:
1099 support
= "unknown";
1102 switch (config
->detect
)
1104 case AUTO_BOOLEAN_AUTO
:
1105 printf_filtered (_("Support for the `%s' packet "
1106 "is auto-detected, currently %s.\n"),
1107 config
->name
, support
);
1109 case AUTO_BOOLEAN_TRUE
:
1110 case AUTO_BOOLEAN_FALSE
:
1111 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1112 config
->name
, support
);
1118 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1119 const char *title
, int legacy
)
1125 config
->name
= name
;
1126 config
->title
= title
;
1127 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1129 show_doc
= xstrprintf ("Show current use of remote "
1130 "protocol `%s' (%s) packet",
1132 /* set/show TITLE-packet {auto,on,off} */
1133 cmd_name
= xstrprintf ("%s-packet", title
);
1134 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1135 &config
->detect
, set_doc
,
1136 show_doc
, NULL
, /* help_doc */
1138 show_remote_protocol_packet_cmd
,
1139 &remote_set_cmdlist
, &remote_show_cmdlist
);
1140 /* The command code copies the documentation strings. */
1143 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1148 legacy_name
= xstrprintf ("%s-packet", name
);
1149 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1150 &remote_set_cmdlist
);
1151 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1152 &remote_show_cmdlist
);
1156 static enum packet_result
1157 packet_check_result (const char *buf
)
1161 /* The stub recognized the packet request. Check that the
1162 operation succeeded. */
1164 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1166 /* "Enn" - definitly an error. */
1167 return PACKET_ERROR
;
1169 /* Always treat "E." as an error. This will be used for
1170 more verbose error messages, such as E.memtypes. */
1171 if (buf
[0] == 'E' && buf
[1] == '.')
1172 return PACKET_ERROR
;
1174 /* The packet may or may not be OK. Just assume it is. */
1178 /* The stub does not support the packet. */
1179 return PACKET_UNKNOWN
;
1182 static enum packet_result
1183 packet_ok (const char *buf
, struct packet_config
*config
)
1185 enum packet_result result
;
1187 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1188 && config
->support
== PACKET_DISABLE
)
1189 internal_error (__FILE__
, __LINE__
,
1190 _("packet_ok: attempt to use a disabled packet"));
1192 result
= packet_check_result (buf
);
1197 /* The stub recognized the packet request. */
1198 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1201 fprintf_unfiltered (gdb_stdlog
,
1202 "Packet %s (%s) is supported\n",
1203 config
->name
, config
->title
);
1204 config
->support
= PACKET_ENABLE
;
1207 case PACKET_UNKNOWN
:
1208 /* The stub does not support the packet. */
1209 if (config
->detect
== AUTO_BOOLEAN_AUTO
1210 && config
->support
== PACKET_ENABLE
)
1212 /* If the stub previously indicated that the packet was
1213 supported then there is a protocol error. */
1214 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1215 config
->name
, config
->title
);
1217 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1219 /* The user set it wrong. */
1220 error (_("Enabled packet %s (%s) not recognized by stub"),
1221 config
->name
, config
->title
);
1225 fprintf_unfiltered (gdb_stdlog
,
1226 "Packet %s (%s) is NOT supported\n",
1227 config
->name
, config
->title
);
1228 config
->support
= PACKET_DISABLE
;
1248 PACKET_vFile_pwrite
,
1250 PACKET_vFile_unlink
,
1251 PACKET_vFile_readlink
,
1254 PACKET_qXfer_features
,
1255 PACKET_qXfer_exec_file
,
1256 PACKET_qXfer_libraries
,
1257 PACKET_qXfer_libraries_svr4
,
1258 PACKET_qXfer_memory_map
,
1259 PACKET_qXfer_spu_read
,
1260 PACKET_qXfer_spu_write
,
1261 PACKET_qXfer_osdata
,
1262 PACKET_qXfer_threads
,
1263 PACKET_qXfer_statictrace_read
,
1264 PACKET_qXfer_traceframe_info
,
1270 PACKET_QPassSignals
,
1271 PACKET_QProgramSignals
,
1273 PACKET_qSearch_memory
,
1276 PACKET_QStartNoAckMode
,
1278 PACKET_qXfer_siginfo_read
,
1279 PACKET_qXfer_siginfo_write
,
1282 /* Support for conditional tracepoints. */
1283 PACKET_ConditionalTracepoints
,
1285 /* Support for target-side breakpoint conditions. */
1286 PACKET_ConditionalBreakpoints
,
1288 /* Support for target-side breakpoint commands. */
1289 PACKET_BreakpointCommands
,
1291 /* Support for fast tracepoints. */
1292 PACKET_FastTracepoints
,
1294 /* Support for static tracepoints. */
1295 PACKET_StaticTracepoints
,
1297 /* Support for installing tracepoints while a trace experiment is
1299 PACKET_InstallInTrace
,
1303 PACKET_TracepointSource
,
1306 PACKET_QDisableRandomization
,
1308 PACKET_QTBuffer_size
,
1311 PACKET_qXfer_btrace
,
1313 /* Support for the QNonStop packet. */
1316 /* Support for multi-process extensions. */
1317 PACKET_multiprocess_feature
,
1319 /* Support for enabling and disabling tracepoints while a trace
1320 experiment is running. */
1321 PACKET_EnableDisableTracepoints_feature
,
1323 /* Support for collecting strings using the tracenz bytecode. */
1324 PACKET_tracenz_feature
,
1326 /* Support for continuing to run a trace experiment while GDB is
1328 PACKET_DisconnectedTracing_feature
,
1330 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1331 PACKET_augmented_libraries_svr4_read_feature
,
1333 /* Support for the qXfer:btrace-conf:read packet. */
1334 PACKET_qXfer_btrace_conf
,
1336 /* Support for the Qbtrace-conf:bts:size packet. */
1337 PACKET_Qbtrace_conf_bts_size
,
1339 /* Support for swbreak+ feature. */
1340 PACKET_swbreak_feature
,
1342 /* Support for hwbreak+ feature. */
1343 PACKET_hwbreak_feature
,
1345 /* Support for fork events. */
1346 PACKET_fork_event_feature
,
1348 /* Support for vfork events. */
1349 PACKET_vfork_event_feature
,
1354 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1356 /* Returns the packet's corresponding "set remote foo-packet" command
1357 state. See struct packet_config for more details. */
1359 static enum auto_boolean
1360 packet_set_cmd_state (int packet
)
1362 return remote_protocol_packets
[packet
].detect
;
1365 /* Returns whether a given packet or feature is supported. This takes
1366 into account the state of the corresponding "set remote foo-packet"
1367 command, which may be used to bypass auto-detection. */
1369 static enum packet_support
1370 packet_config_support (struct packet_config
*config
)
1372 switch (config
->detect
)
1374 case AUTO_BOOLEAN_TRUE
:
1375 return PACKET_ENABLE
;
1376 case AUTO_BOOLEAN_FALSE
:
1377 return PACKET_DISABLE
;
1378 case AUTO_BOOLEAN_AUTO
:
1379 return config
->support
;
1381 gdb_assert_not_reached (_("bad switch"));
1385 /* Same as packet_config_support, but takes the packet's enum value as
1388 static enum packet_support
1389 packet_support (int packet
)
1391 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1393 return packet_config_support (config
);
1397 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1398 struct cmd_list_element
*c
,
1401 struct packet_config
*packet
;
1403 for (packet
= remote_protocol_packets
;
1404 packet
< &remote_protocol_packets
[PACKET_MAX
];
1407 if (&packet
->detect
== c
->var
)
1409 show_packet_config_cmd (packet
);
1413 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1417 /* Should we try one of the 'Z' requests? */
1421 Z_PACKET_SOFTWARE_BP
,
1422 Z_PACKET_HARDWARE_BP
,
1429 /* For compatibility with older distributions. Provide a ``set remote
1430 Z-packet ...'' command that updates all the Z packet types. */
1432 static enum auto_boolean remote_Z_packet_detect
;
1435 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1436 struct cmd_list_element
*c
)
1440 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1441 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1445 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1446 struct cmd_list_element
*c
,
1451 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1453 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1457 /* Returns true if the multi-process extensions are in effect. */
1460 remote_multi_process_p (struct remote_state
*rs
)
1462 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1465 /* Returns true if fork events are supported. */
1468 remote_fork_event_p (struct remote_state
*rs
)
1470 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1473 /* Returns true if vfork events are supported. */
1476 remote_vfork_event_p (struct remote_state
*rs
)
1478 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1481 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1482 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1483 static struct async_signal_handler
*async_sigint_remote_token
;
1486 /* Asynchronous signal handle registered as event loop source for
1487 when we have pending events ready to be passed to the core. */
1489 static struct async_event_handler
*remote_async_inferior_event_token
;
1493 static ptid_t magic_null_ptid
;
1494 static ptid_t not_sent_ptid
;
1495 static ptid_t any_thread_ptid
;
1497 /* Find out if the stub attached to PID (and hence GDB should offer to
1498 detach instead of killing it when bailing out). */
1501 remote_query_attached (int pid
)
1503 struct remote_state
*rs
= get_remote_state ();
1504 size_t size
= get_remote_packet_size ();
1506 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1509 if (remote_multi_process_p (rs
))
1510 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1512 xsnprintf (rs
->buf
, size
, "qAttached");
1515 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1517 switch (packet_ok (rs
->buf
,
1518 &remote_protocol_packets
[PACKET_qAttached
]))
1521 if (strcmp (rs
->buf
, "1") == 0)
1525 warning (_("Remote failure reply: %s"), rs
->buf
);
1527 case PACKET_UNKNOWN
:
1534 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1535 has been invented by GDB, instead of reported by the target. Since
1536 we can be connected to a remote system before before knowing about
1537 any inferior, mark the target with execution when we find the first
1538 inferior. If ATTACHED is 1, then we had just attached to this
1539 inferior. If it is 0, then we just created this inferior. If it
1540 is -1, then try querying the remote stub to find out if it had
1541 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1542 attempt to open this inferior's executable as the main executable
1543 if no main executable is open already. */
1545 static struct inferior
*
1546 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1549 struct inferior
*inf
;
1551 /* Check whether this process we're learning about is to be
1552 considered attached, or if is to be considered to have been
1553 spawned by the stub. */
1555 attached
= remote_query_attached (pid
);
1557 if (gdbarch_has_global_solist (target_gdbarch ()))
1559 /* If the target shares code across all inferiors, then every
1560 attach adds a new inferior. */
1561 inf
= add_inferior (pid
);
1563 /* ... and every inferior is bound to the same program space.
1564 However, each inferior may still have its own address
1566 inf
->aspace
= maybe_new_address_space ();
1567 inf
->pspace
= current_program_space
;
1571 /* In the traditional debugging scenario, there's a 1-1 match
1572 between program/address spaces. We simply bind the inferior
1573 to the program space's address space. */
1574 inf
= current_inferior ();
1575 inferior_appeared (inf
, pid
);
1578 inf
->attach_flag
= attached
;
1579 inf
->fake_pid_p
= fake_pid_p
;
1581 /* If no main executable is currently open then attempt to
1582 open the file that was executed to create this inferior. */
1583 if (try_open_exec
&& get_exec_file (0) == NULL
)
1584 exec_file_locate_attach (pid
, 1);
1589 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1590 according to RUNNING. */
1593 remote_add_thread (ptid_t ptid
, int running
)
1595 struct remote_state
*rs
= get_remote_state ();
1597 /* GDB historically didn't pull threads in the initial connection
1598 setup. If the remote target doesn't even have a concept of
1599 threads (e.g., a bare-metal target), even if internally we
1600 consider that a single-threaded target, mentioning a new thread
1601 might be confusing to the user. Be silent then, preserving the
1602 age old behavior. */
1603 if (rs
->starting_up
)
1604 add_thread_silent (ptid
);
1608 set_executing (ptid
, running
);
1609 set_running (ptid
, running
);
1612 /* Come here when we learn about a thread id from the remote target.
1613 It may be the first time we hear about such thread, so take the
1614 opportunity to add it to GDB's thread list. In case this is the
1615 first time we're noticing its corresponding inferior, add it to
1616 GDB's inferior list as well. */
1619 remote_notice_new_inferior (ptid_t currthread
, int running
)
1621 /* If this is a new thread, add it to GDB's thread list.
1622 If we leave it up to WFI to do this, bad things will happen. */
1624 if (in_thread_list (currthread
) && is_exited (currthread
))
1626 /* We're seeing an event on a thread id we knew had exited.
1627 This has to be a new thread reusing the old id. Add it. */
1628 remote_add_thread (currthread
, running
);
1632 if (!in_thread_list (currthread
))
1634 struct inferior
*inf
= NULL
;
1635 int pid
= ptid_get_pid (currthread
);
1637 if (ptid_is_pid (inferior_ptid
)
1638 && pid
== ptid_get_pid (inferior_ptid
))
1640 /* inferior_ptid has no thread member yet. This can happen
1641 with the vAttach -> remote_wait,"TAAthread:" path if the
1642 stub doesn't support qC. This is the first stop reported
1643 after an attach, so this is the main thread. Update the
1644 ptid in the thread list. */
1645 if (in_thread_list (pid_to_ptid (pid
)))
1646 thread_change_ptid (inferior_ptid
, currthread
);
1649 remote_add_thread (currthread
, running
);
1650 inferior_ptid
= currthread
;
1655 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1657 /* inferior_ptid is not set yet. This can happen with the
1658 vRun -> remote_wait,"TAAthread:" path if the stub
1659 doesn't support qC. This is the first stop reported
1660 after an attach, so this is the main thread. Update the
1661 ptid in the thread list. */
1662 thread_change_ptid (inferior_ptid
, currthread
);
1666 /* When connecting to a target remote, or to a target
1667 extended-remote which already was debugging an inferior, we
1668 may not know about it yet. Add it before adding its child
1669 thread, so notifications are emitted in a sensible order. */
1670 if (!in_inferior_list (ptid_get_pid (currthread
)))
1672 struct remote_state
*rs
= get_remote_state ();
1673 int fake_pid_p
= !remote_multi_process_p (rs
);
1675 inf
= remote_add_inferior (fake_pid_p
,
1676 ptid_get_pid (currthread
), -1, 1);
1679 /* This is really a new thread. Add it. */
1680 remote_add_thread (currthread
, running
);
1682 /* If we found a new inferior, let the common code do whatever
1683 it needs to with it (e.g., read shared libraries, insert
1684 breakpoints), unless we're just setting up an all-stop
1688 struct remote_state
*rs
= get_remote_state ();
1690 if (non_stop
|| !rs
->starting_up
)
1691 notice_new_inferior (currthread
, running
, 0);
1696 /* Return the private thread data, creating it if necessary. */
1698 static struct private_thread_info
*
1699 demand_private_info (ptid_t ptid
)
1701 struct thread_info
*info
= find_thread_ptid (ptid
);
1707 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1708 info
->private_dtor
= free_private_thread_info
;
1709 info
->priv
->core
= -1;
1710 info
->priv
->extra
= 0;
1716 /* Call this function as a result of
1717 1) A halt indication (T packet) containing a thread id
1718 2) A direct query of currthread
1719 3) Successful execution of set thread */
1722 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1724 rs
->general_thread
= currthread
;
1727 /* If 'QPassSignals' is supported, tell the remote stub what signals
1728 it can simply pass through to the inferior without reporting. */
1731 remote_pass_signals (struct target_ops
*self
,
1732 int numsigs
, unsigned char *pass_signals
)
1734 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1736 char *pass_packet
, *p
;
1738 struct remote_state
*rs
= get_remote_state ();
1740 gdb_assert (numsigs
< 256);
1741 for (i
= 0; i
< numsigs
; i
++)
1743 if (pass_signals
[i
])
1746 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1747 strcpy (pass_packet
, "QPassSignals:");
1748 p
= pass_packet
+ strlen (pass_packet
);
1749 for (i
= 0; i
< numsigs
; i
++)
1751 if (pass_signals
[i
])
1754 *p
++ = tohex (i
>> 4);
1755 *p
++ = tohex (i
& 15);
1764 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1766 putpkt (pass_packet
);
1767 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1768 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1769 if (rs
->last_pass_packet
)
1770 xfree (rs
->last_pass_packet
);
1771 rs
->last_pass_packet
= pass_packet
;
1774 xfree (pass_packet
);
1778 /* If 'QProgramSignals' is supported, tell the remote stub what
1779 signals it should pass through to the inferior when detaching. */
1782 remote_program_signals (struct target_ops
*self
,
1783 int numsigs
, unsigned char *signals
)
1785 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1789 struct remote_state
*rs
= get_remote_state ();
1791 gdb_assert (numsigs
< 256);
1792 for (i
= 0; i
< numsigs
; i
++)
1797 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1798 strcpy (packet
, "QProgramSignals:");
1799 p
= packet
+ strlen (packet
);
1800 for (i
= 0; i
< numsigs
; i
++)
1802 if (signal_pass_state (i
))
1805 *p
++ = tohex (i
>> 4);
1806 *p
++ = tohex (i
& 15);
1815 if (!rs
->last_program_signals_packet
1816 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1819 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1820 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1821 xfree (rs
->last_program_signals_packet
);
1822 rs
->last_program_signals_packet
= packet
;
1829 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1830 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1831 thread. If GEN is set, set the general thread, if not, then set
1832 the step/continue thread. */
1834 set_thread (struct ptid ptid
, int gen
)
1836 struct remote_state
*rs
= get_remote_state ();
1837 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1838 char *buf
= rs
->buf
;
1839 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1841 if (ptid_equal (state
, ptid
))
1845 *buf
++ = gen
? 'g' : 'c';
1846 if (ptid_equal (ptid
, magic_null_ptid
))
1847 xsnprintf (buf
, endbuf
- buf
, "0");
1848 else if (ptid_equal (ptid
, any_thread_ptid
))
1849 xsnprintf (buf
, endbuf
- buf
, "0");
1850 else if (ptid_equal (ptid
, minus_one_ptid
))
1851 xsnprintf (buf
, endbuf
- buf
, "-1");
1853 write_ptid (buf
, endbuf
, ptid
);
1855 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1857 rs
->general_thread
= ptid
;
1859 rs
->continue_thread
= ptid
;
1863 set_general_thread (struct ptid ptid
)
1865 set_thread (ptid
, 1);
1869 set_continue_thread (struct ptid ptid
)
1871 set_thread (ptid
, 0);
1874 /* Change the remote current process. Which thread within the process
1875 ends up selected isn't important, as long as it is the same process
1876 as what INFERIOR_PTID points to.
1878 This comes from that fact that there is no explicit notion of
1879 "selected process" in the protocol. The selected process for
1880 general operations is the process the selected general thread
1884 set_general_process (void)
1886 struct remote_state
*rs
= get_remote_state ();
1888 /* If the remote can't handle multiple processes, don't bother. */
1889 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1892 /* We only need to change the remote current thread if it's pointing
1893 at some other process. */
1894 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1895 set_general_thread (inferior_ptid
);
1899 /* Return nonzero if this is the main thread that we made up ourselves
1900 to model non-threaded targets as single-threaded. */
1903 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
1905 struct remote_state
*rs
= get_remote_state ();
1908 if (ptid_equal (ptid
, magic_null_ptid
))
1909 /* The main thread is always alive. */
1912 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1913 /* The main thread is always alive. This can happen after a
1914 vAttach, if the remote side doesn't support
1921 /* Return nonzero if the thread PTID is still alive on the remote
1925 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1927 struct remote_state
*rs
= get_remote_state ();
1930 /* Check if this is a thread that we made up ourselves to model
1931 non-threaded targets as single-threaded. */
1932 if (remote_thread_always_alive (ops
, ptid
))
1936 endp
= rs
->buf
+ get_remote_packet_size ();
1939 write_ptid (p
, endp
, ptid
);
1942 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1943 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1946 /* About these extended threadlist and threadinfo packets. They are
1947 variable length packets but, the fields within them are often fixed
1948 length. They are redundent enough to send over UDP as is the
1949 remote protocol in general. There is a matching unit test module
1952 /* WARNING: This threadref data structure comes from the remote O.S.,
1953 libstub protocol encoding, and remote.c. It is not particularly
1956 /* Right now, the internal structure is int. We want it to be bigger.
1957 Plan to fix this. */
1959 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1961 /* gdb_ext_thread_info is an internal GDB data structure which is
1962 equivalent to the reply of the remote threadinfo packet. */
1964 struct gdb_ext_thread_info
1966 threadref threadid
; /* External form of thread reference. */
1967 int active
; /* Has state interesting to GDB?
1969 char display
[256]; /* Brief state display, name,
1970 blocked/suspended. */
1971 char shortname
[32]; /* To be used to name threads. */
1972 char more_display
[256]; /* Long info, statistics, queue depth,
1976 /* The volume of remote transfers can be limited by submitting
1977 a mask containing bits specifying the desired information.
1978 Use a union of these values as the 'selection' parameter to
1979 get_thread_info. FIXME: Make these TAG names more thread specific. */
1981 #define TAG_THREADID 1
1982 #define TAG_EXISTS 2
1983 #define TAG_DISPLAY 4
1984 #define TAG_THREADNAME 8
1985 #define TAG_MOREDISPLAY 16
1987 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1989 static char *unpack_nibble (char *buf
, int *val
);
1991 static char *unpack_byte (char *buf
, int *value
);
1993 static char *pack_int (char *buf
, int value
);
1995 static char *unpack_int (char *buf
, int *value
);
1997 static char *unpack_string (char *src
, char *dest
, int length
);
1999 static char *pack_threadid (char *pkt
, threadref
*id
);
2001 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2003 void int_to_threadref (threadref
*id
, int value
);
2005 static int threadref_to_int (threadref
*ref
);
2007 static void copy_threadref (threadref
*dest
, threadref
*src
);
2009 static int threadmatch (threadref
*dest
, threadref
*src
);
2011 static char *pack_threadinfo_request (char *pkt
, int mode
,
2014 static int remote_unpack_thread_info_response (char *pkt
,
2015 threadref
*expectedref
,
2016 struct gdb_ext_thread_info
2020 static int remote_get_threadinfo (threadref
*threadid
,
2021 int fieldset
, /*TAG mask */
2022 struct gdb_ext_thread_info
*info
);
2024 static char *pack_threadlist_request (char *pkt
, int startflag
,
2026 threadref
*nextthread
);
2028 static int parse_threadlist_response (char *pkt
,
2030 threadref
*original_echo
,
2031 threadref
*resultlist
,
2034 static int remote_get_threadlist (int startflag
,
2035 threadref
*nextthread
,
2039 threadref
*threadlist
);
2041 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2043 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2044 void *context
, int looplimit
);
2046 static int remote_newthread_step (threadref
*ref
, void *context
);
2049 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2050 buffer we're allowed to write to. Returns
2051 BUF+CHARACTERS_WRITTEN. */
2054 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2057 struct remote_state
*rs
= get_remote_state ();
2059 if (remote_multi_process_p (rs
))
2061 pid
= ptid_get_pid (ptid
);
2063 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2065 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2067 tid
= ptid_get_lwp (ptid
);
2069 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2071 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2076 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2077 passed the last parsed char. Returns null_ptid on error. */
2080 read_ptid (char *buf
, char **obuf
)
2084 ULONGEST pid
= 0, tid
= 0;
2088 /* Multi-process ptid. */
2089 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2091 error (_("invalid remote ptid: %s"), p
);
2094 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2097 return ptid_build (pid
, tid
, 0);
2100 /* No multi-process. Just a tid. */
2101 pp
= unpack_varlen_hex (p
, &tid
);
2103 /* Since the stub is not sending a process id, then default to
2104 what's in inferior_ptid, unless it's null at this point. If so,
2105 then since there's no way to know the pid of the reported
2106 threads, use the magic number. */
2107 if (ptid_equal (inferior_ptid
, null_ptid
))
2108 pid
= ptid_get_pid (magic_null_ptid
);
2110 pid
= ptid_get_pid (inferior_ptid
);
2114 return ptid_build (pid
, tid
, 0);
2120 if (ch
>= 'a' && ch
<= 'f')
2121 return ch
- 'a' + 10;
2122 if (ch
>= '0' && ch
<= '9')
2124 if (ch
>= 'A' && ch
<= 'F')
2125 return ch
- 'A' + 10;
2130 stub_unpack_int (char *buff
, int fieldlength
)
2137 nibble
= stubhex (*buff
++);
2141 retval
= retval
<< 4;
2147 unpack_nibble (char *buf
, int *val
)
2149 *val
= fromhex (*buf
++);
2154 unpack_byte (char *buf
, int *value
)
2156 *value
= stub_unpack_int (buf
, 2);
2161 pack_int (char *buf
, int value
)
2163 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2164 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2165 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2166 buf
= pack_hex_byte (buf
, (value
& 0xff));
2171 unpack_int (char *buf
, int *value
)
2173 *value
= stub_unpack_int (buf
, 8);
2177 #if 0 /* Currently unused, uncomment when needed. */
2178 static char *pack_string (char *pkt
, char *string
);
2181 pack_string (char *pkt
, char *string
)
2186 len
= strlen (string
);
2188 len
= 200; /* Bigger than most GDB packets, junk??? */
2189 pkt
= pack_hex_byte (pkt
, len
);
2193 if ((ch
== '\0') || (ch
== '#'))
2194 ch
= '*'; /* Protect encapsulation. */
2199 #endif /* 0 (unused) */
2202 unpack_string (char *src
, char *dest
, int length
)
2211 pack_threadid (char *pkt
, threadref
*id
)
2214 unsigned char *altid
;
2216 altid
= (unsigned char *) id
;
2217 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2219 pkt
= pack_hex_byte (pkt
, *altid
++);
2225 unpack_threadid (char *inbuf
, threadref
*id
)
2228 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2231 altref
= (char *) id
;
2233 while (inbuf
< limit
)
2235 x
= stubhex (*inbuf
++);
2236 y
= stubhex (*inbuf
++);
2237 *altref
++ = (x
<< 4) | y
;
2242 /* Externally, threadrefs are 64 bits but internally, they are still
2243 ints. This is due to a mismatch of specifications. We would like
2244 to use 64bit thread references internally. This is an adapter
2248 int_to_threadref (threadref
*id
, int value
)
2250 unsigned char *scan
;
2252 scan
= (unsigned char *) id
;
2258 *scan
++ = (value
>> 24) & 0xff;
2259 *scan
++ = (value
>> 16) & 0xff;
2260 *scan
++ = (value
>> 8) & 0xff;
2261 *scan
++ = (value
& 0xff);
2265 threadref_to_int (threadref
*ref
)
2268 unsigned char *scan
;
2274 value
= (value
<< 8) | ((*scan
++) & 0xff);
2279 copy_threadref (threadref
*dest
, threadref
*src
)
2282 unsigned char *csrc
, *cdest
;
2284 csrc
= (unsigned char *) src
;
2285 cdest
= (unsigned char *) dest
;
2292 threadmatch (threadref
*dest
, threadref
*src
)
2294 /* Things are broken right now, so just assume we got a match. */
2296 unsigned char *srcp
, *destp
;
2298 srcp
= (char *) src
;
2299 destp
= (char *) dest
;
2303 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2310 threadid:1, # always request threadid
2317 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2320 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2322 *pkt
++ = 'q'; /* Info Query */
2323 *pkt
++ = 'P'; /* process or thread info */
2324 pkt
= pack_int (pkt
, mode
); /* mode */
2325 pkt
= pack_threadid (pkt
, id
); /* threadid */
2326 *pkt
= '\0'; /* terminate */
2330 /* These values tag the fields in a thread info response packet. */
2331 /* Tagging the fields allows us to request specific fields and to
2332 add more fields as time goes by. */
2334 #define TAG_THREADID 1 /* Echo the thread identifier. */
2335 #define TAG_EXISTS 2 /* Is this process defined enough to
2336 fetch registers and its stack? */
2337 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2338 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2339 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2343 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2344 struct gdb_ext_thread_info
*info
)
2346 struct remote_state
*rs
= get_remote_state ();
2350 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2353 /* info->threadid = 0; FIXME: implement zero_threadref. */
2355 info
->display
[0] = '\0';
2356 info
->shortname
[0] = '\0';
2357 info
->more_display
[0] = '\0';
2359 /* Assume the characters indicating the packet type have been
2361 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2362 pkt
= unpack_threadid (pkt
, &ref
);
2365 warning (_("Incomplete response to threadinfo request."));
2366 if (!threadmatch (&ref
, expectedref
))
2367 { /* This is an answer to a different request. */
2368 warning (_("ERROR RMT Thread info mismatch."));
2371 copy_threadref (&info
->threadid
, &ref
);
2373 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2375 /* Packets are terminated with nulls. */
2376 while ((pkt
< limit
) && mask
&& *pkt
)
2378 pkt
= unpack_int (pkt
, &tag
); /* tag */
2379 pkt
= unpack_byte (pkt
, &length
); /* length */
2380 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2382 warning (_("ERROR RMT: threadinfo tag mismatch."));
2386 if (tag
== TAG_THREADID
)
2390 warning (_("ERROR RMT: length of threadid is not 16."));
2394 pkt
= unpack_threadid (pkt
, &ref
);
2395 mask
= mask
& ~TAG_THREADID
;
2398 if (tag
== TAG_EXISTS
)
2400 info
->active
= stub_unpack_int (pkt
, length
);
2402 mask
= mask
& ~(TAG_EXISTS
);
2405 warning (_("ERROR RMT: 'exists' length too long."));
2411 if (tag
== TAG_THREADNAME
)
2413 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2414 mask
= mask
& ~TAG_THREADNAME
;
2417 if (tag
== TAG_DISPLAY
)
2419 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2420 mask
= mask
& ~TAG_DISPLAY
;
2423 if (tag
== TAG_MOREDISPLAY
)
2425 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2426 mask
= mask
& ~TAG_MOREDISPLAY
;
2429 warning (_("ERROR RMT: unknown thread info tag."));
2430 break; /* Not a tag we know about. */
2436 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2437 struct gdb_ext_thread_info
*info
)
2439 struct remote_state
*rs
= get_remote_state ();
2442 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2446 if (rs
->buf
[0] == '\0')
2449 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2454 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2457 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2458 threadref
*nextthread
)
2460 *pkt
++ = 'q'; /* info query packet */
2461 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2462 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2463 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2464 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2469 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2472 parse_threadlist_response (char *pkt
, int result_limit
,
2473 threadref
*original_echo
, threadref
*resultlist
,
2476 struct remote_state
*rs
= get_remote_state ();
2478 int count
, resultcount
, done
;
2481 /* Assume the 'q' and 'M chars have been stripped. */
2482 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2483 /* done parse past here */
2484 pkt
= unpack_byte (pkt
, &count
); /* count field */
2485 pkt
= unpack_nibble (pkt
, &done
);
2486 /* The first threadid is the argument threadid. */
2487 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2488 while ((count
-- > 0) && (pkt
< limit
))
2490 pkt
= unpack_threadid (pkt
, resultlist
++);
2491 if (resultcount
++ >= result_limit
)
2499 /* Fetch the next batch of threads from the remote. Returns -1 if the
2500 qL packet is not supported, 0 on error and 1 on success. */
2503 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2504 int *done
, int *result_count
, threadref
*threadlist
)
2506 struct remote_state
*rs
= get_remote_state ();
2509 /* Trancate result limit to be smaller than the packet size. */
2510 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2511 >= get_remote_packet_size ())
2512 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2514 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2516 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2517 if (*rs
->buf
== '\0')
2519 /* Packet not supported. */
2524 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2525 &rs
->echo_nextthread
, threadlist
, done
);
2527 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2529 /* FIXME: This is a good reason to drop the packet. */
2530 /* Possably, there is a duplicate response. */
2532 retransmit immediatly - race conditions
2533 retransmit after timeout - yes
2535 wait for packet, then exit
2537 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2538 return 0; /* I choose simply exiting. */
2540 if (*result_count
<= 0)
2544 warning (_("RMT ERROR : failed to get remote thread list."));
2547 return result
; /* break; */
2549 if (*result_count
> result_limit
)
2552 warning (_("RMT ERROR: threadlist response longer than requested."));
2558 /* Fetch the list of remote threads, with the qL packet, and call
2559 STEPFUNCTION for each thread found. Stops iterating and returns 1
2560 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2561 STEPFUNCTION returns false. If the packet is not supported,
2565 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2568 struct remote_state
*rs
= get_remote_state ();
2569 int done
, i
, result_count
;
2577 if (loopcount
++ > looplimit
)
2580 warning (_("Remote fetch threadlist -infinite loop-."));
2583 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2584 MAXTHREADLISTRESULTS
,
2585 &done
, &result_count
,
2586 rs
->resultthreadlist
);
2589 /* Clear for later iterations. */
2591 /* Setup to resume next batch of thread references, set nextthread. */
2592 if (result_count
>= 1)
2593 copy_threadref (&rs
->nextthread
,
2594 &rs
->resultthreadlist
[result_count
- 1]);
2596 while (result_count
--)
2598 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2608 /* A thread found on the remote target. */
2610 typedef struct thread_item
2612 /* The thread's PTID. */
2615 /* The thread's extra info. May be NULL. */
2618 /* The core the thread was running on. -1 if not known. */
2621 DEF_VEC_O(thread_item_t
);
2623 /* Context passed around to the various methods listing remote
2624 threads. As new threads are found, they're added to the ITEMS
2627 struct threads_listing_context
2629 /* The threads found on the remote target. */
2630 VEC (thread_item_t
) *items
;
2633 /* Discard the contents of the constructed thread listing context. */
2636 clear_threads_listing_context (void *p
)
2638 struct threads_listing_context
*context
= p
;
2640 struct thread_item
*item
;
2642 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2643 xfree (item
->extra
);
2645 VEC_free (thread_item_t
, context
->items
);
2649 remote_newthread_step (threadref
*ref
, void *data
)
2651 struct threads_listing_context
*context
= data
;
2652 struct thread_item item
;
2653 int pid
= ptid_get_pid (inferior_ptid
);
2655 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2659 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2661 return 1; /* continue iterator */
2664 #define CRAZY_MAX_THREADS 1000
2667 remote_current_thread (ptid_t oldpid
)
2669 struct remote_state
*rs
= get_remote_state ();
2672 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2673 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2674 return read_ptid (&rs
->buf
[2], NULL
);
2679 /* List remote threads using the deprecated qL packet. */
2682 remote_get_threads_with_ql (struct target_ops
*ops
,
2683 struct threads_listing_context
*context
)
2685 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2686 CRAZY_MAX_THREADS
) >= 0)
2692 #if defined(HAVE_LIBEXPAT)
2695 start_thread (struct gdb_xml_parser
*parser
,
2696 const struct gdb_xml_element
*element
,
2697 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2699 struct threads_listing_context
*data
= user_data
;
2701 struct thread_item item
;
2703 struct gdb_xml_value
*attr
;
2705 id
= xml_find_attribute (attributes
, "id")->value
;
2706 item
.ptid
= read_ptid (id
, NULL
);
2708 attr
= xml_find_attribute (attributes
, "core");
2710 item
.core
= *(ULONGEST
*) attr
->value
;
2716 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2720 end_thread (struct gdb_xml_parser
*parser
,
2721 const struct gdb_xml_element
*element
,
2722 void *user_data
, const char *body_text
)
2724 struct threads_listing_context
*data
= user_data
;
2726 if (body_text
&& *body_text
)
2727 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2730 const struct gdb_xml_attribute thread_attributes
[] = {
2731 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2732 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2733 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2736 const struct gdb_xml_element thread_children
[] = {
2737 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2740 const struct gdb_xml_element threads_children
[] = {
2741 { "thread", thread_attributes
, thread_children
,
2742 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2743 start_thread
, end_thread
},
2744 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2747 const struct gdb_xml_element threads_elements
[] = {
2748 { "threads", NULL
, threads_children
,
2749 GDB_XML_EF_NONE
, NULL
, NULL
},
2750 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2755 /* List remote threads using qXfer:threads:read. */
2758 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2759 struct threads_listing_context
*context
)
2761 #if defined(HAVE_LIBEXPAT)
2762 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2764 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2765 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2767 if (xml
!= NULL
&& *xml
!= '\0')
2769 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2770 threads_elements
, xml
, context
);
2773 do_cleanups (back_to
);
2781 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2784 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2785 struct threads_listing_context
*context
)
2787 struct remote_state
*rs
= get_remote_state ();
2789 if (rs
->use_threadinfo_query
)
2793 putpkt ("qfThreadInfo");
2794 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2796 if (bufp
[0] != '\0') /* q packet recognized */
2798 while (*bufp
++ == 'm') /* reply contains one or more TID */
2802 struct thread_item item
;
2804 item
.ptid
= read_ptid (bufp
, &bufp
);
2808 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2810 while (*bufp
++ == ','); /* comma-separated list */
2811 putpkt ("qsThreadInfo");
2812 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2819 /* Packet not recognized. */
2820 rs
->use_threadinfo_query
= 0;
2827 /* Implement the to_update_thread_list function for the remote
2831 remote_update_thread_list (struct target_ops
*ops
)
2833 struct remote_state
*rs
= get_remote_state ();
2834 struct threads_listing_context context
;
2835 struct cleanup
*old_chain
;
2838 context
.items
= NULL
;
2839 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2841 /* We have a few different mechanisms to fetch the thread list. Try
2842 them all, starting with the most preferred one first, falling
2843 back to older methods. */
2844 if (remote_get_threads_with_qxfer (ops
, &context
)
2845 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2846 || remote_get_threads_with_ql (ops
, &context
))
2849 struct thread_item
*item
;
2850 struct thread_info
*tp
, *tmp
;
2854 if (VEC_empty (thread_item_t
, context
.items
)
2855 && remote_thread_always_alive (ops
, inferior_ptid
))
2857 /* Some targets don't really support threads, but still
2858 reply an (empty) thread list in response to the thread
2859 listing packets, instead of replying "packet not
2860 supported". Exit early so we don't delete the main
2862 do_cleanups (old_chain
);
2866 /* CONTEXT now holds the current thread list on the remote
2867 target end. Delete GDB-side threads no longer found on the
2869 ALL_THREADS_SAFE (tp
, tmp
)
2872 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2875 if (ptid_equal (item
->ptid
, tp
->ptid
))
2879 if (i
== VEC_length (thread_item_t
, context
.items
))
2882 delete_thread (tp
->ptid
);
2886 /* And now add threads we don't know about yet to our list. */
2888 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2891 if (!ptid_equal (item
->ptid
, null_ptid
))
2893 struct private_thread_info
*info
;
2894 /* In non-stop mode, we assume new found threads are
2895 running until proven otherwise with a stop reply. In
2896 all-stop, we can only get here if all threads are
2898 int running
= non_stop
? 1 : 0;
2900 remote_notice_new_inferior (item
->ptid
, running
);
2902 info
= demand_private_info (item
->ptid
);
2903 info
->core
= item
->core
;
2904 info
->extra
= item
->extra
;
2912 /* If no thread listing method is supported, then query whether
2913 each known thread is alive, one by one, with the T packet.
2914 If the target doesn't support threads at all, then this is a
2915 no-op. See remote_thread_alive. */
2919 do_cleanups (old_chain
);
2923 * Collect a descriptive string about the given thread.
2924 * The target may say anything it wants to about the thread
2925 * (typically info about its blocked / runnable state, name, etc.).
2926 * This string will appear in the info threads display.
2928 * Optional: targets are not required to implement this function.
2932 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
2934 struct remote_state
*rs
= get_remote_state ();
2938 struct gdb_ext_thread_info threadinfo
;
2939 static char display_buf
[100]; /* arbitrary... */
2940 int n
= 0; /* position in display_buf */
2942 if (rs
->remote_desc
== 0) /* paranoia */
2943 internal_error (__FILE__
, __LINE__
,
2944 _("remote_threads_extra_info"));
2946 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2947 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
2948 /* This is the main thread which was added by GDB. The remote
2949 server doesn't know about it. */
2952 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2954 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2956 if (info
&& info
->priv
)
2957 return info
->priv
->extra
;
2962 if (rs
->use_threadextra_query
)
2965 char *endb
= rs
->buf
+ get_remote_packet_size ();
2967 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2969 write_ptid (b
, endb
, tp
->ptid
);
2972 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2973 if (rs
->buf
[0] != 0)
2975 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2976 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2977 display_buf
[result
] = '\0';
2982 /* If the above query fails, fall back to the old method. */
2983 rs
->use_threadextra_query
= 0;
2984 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2985 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2986 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
2987 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2988 if (threadinfo
.active
)
2990 if (*threadinfo
.shortname
)
2991 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2992 " Name: %s,", threadinfo
.shortname
);
2993 if (*threadinfo
.display
)
2994 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2995 " State: %s,", threadinfo
.display
);
2996 if (*threadinfo
.more_display
)
2997 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2998 " Priority: %s", threadinfo
.more_display
);
3002 /* For purely cosmetic reasons, clear up trailing commas. */
3003 if (',' == display_buf
[n
-1])
3004 display_buf
[n
-1] = ' ';
3013 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3014 struct static_tracepoint_marker
*marker
)
3016 struct remote_state
*rs
= get_remote_state ();
3019 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3021 p
+= hexnumstr (p
, addr
);
3023 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3027 error (_("Remote failure reply: %s"), p
);
3031 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3038 static VEC(static_tracepoint_marker_p
) *
3039 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3042 struct remote_state
*rs
= get_remote_state ();
3043 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3044 struct static_tracepoint_marker
*marker
= NULL
;
3045 struct cleanup
*old_chain
;
3048 /* Ask for a first packet of static tracepoint marker
3051 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3054 error (_("Remote failure reply: %s"), p
);
3056 old_chain
= make_cleanup (free_current_marker
, &marker
);
3061 marker
= XCNEW (struct static_tracepoint_marker
);
3065 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3067 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3069 VEC_safe_push (static_tracepoint_marker_p
,
3075 release_static_tracepoint_marker (marker
);
3076 memset (marker
, 0, sizeof (*marker
));
3079 while (*p
++ == ','); /* comma-separated list */
3080 /* Ask for another packet of static tracepoint definition. */
3082 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3086 do_cleanups (old_chain
);
3091 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3094 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3096 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3100 /* Restart the remote side; this is an extended protocol operation. */
3103 extended_remote_restart (void)
3105 struct remote_state
*rs
= get_remote_state ();
3107 /* Send the restart command; for reasons I don't understand the
3108 remote side really expects a number after the "R". */
3109 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3112 remote_fileio_reset ();
3115 /* Clean up connection to a remote debugger. */
3118 remote_close (struct target_ops
*self
)
3120 struct remote_state
*rs
= get_remote_state ();
3122 if (rs
->remote_desc
== NULL
)
3123 return; /* already closed */
3125 /* Make sure we leave stdin registered in the event loop, and we
3126 don't leave the async SIGINT signal handler installed. */
3127 remote_terminal_ours (self
);
3129 serial_close (rs
->remote_desc
);
3130 rs
->remote_desc
= NULL
;
3132 /* We don't have a connection to the remote stub anymore. Get rid
3133 of all the inferiors and their threads we were controlling.
3134 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3135 will be unable to find the thread corresponding to (pid, 0, 0). */
3136 inferior_ptid
= null_ptid
;
3137 discard_all_inferiors ();
3139 /* We are closing the remote target, so we should discard
3140 everything of this target. */
3141 discard_pending_stop_replies_in_queue (rs
);
3143 if (remote_async_inferior_event_token
)
3144 delete_async_event_handler (&remote_async_inferior_event_token
);
3146 remote_notif_state_xfree (rs
->notif_state
);
3148 trace_reset_local_state ();
3151 /* Query the remote side for the text, data and bss offsets. */
3156 struct remote_state
*rs
= get_remote_state ();
3159 int lose
, num_segments
= 0, do_sections
, do_segments
;
3160 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3161 struct section_offsets
*offs
;
3162 struct symfile_segment_data
*data
;
3164 if (symfile_objfile
== NULL
)
3167 putpkt ("qOffsets");
3168 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3171 if (buf
[0] == '\000')
3172 return; /* Return silently. Stub doesn't support
3176 warning (_("Remote failure reply: %s"), buf
);
3180 /* Pick up each field in turn. This used to be done with scanf, but
3181 scanf will make trouble if CORE_ADDR size doesn't match
3182 conversion directives correctly. The following code will work
3183 with any size of CORE_ADDR. */
3184 text_addr
= data_addr
= bss_addr
= 0;
3188 if (startswith (ptr
, "Text="))
3191 /* Don't use strtol, could lose on big values. */
3192 while (*ptr
&& *ptr
!= ';')
3193 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3195 if (startswith (ptr
, ";Data="))
3198 while (*ptr
&& *ptr
!= ';')
3199 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3204 if (!lose
&& startswith (ptr
, ";Bss="))
3207 while (*ptr
&& *ptr
!= ';')
3208 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3210 if (bss_addr
!= data_addr
)
3211 warning (_("Target reported unsupported offsets: %s"), buf
);
3216 else if (startswith (ptr
, "TextSeg="))
3219 /* Don't use strtol, could lose on big values. */
3220 while (*ptr
&& *ptr
!= ';')
3221 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3224 if (startswith (ptr
, ";DataSeg="))
3227 while (*ptr
&& *ptr
!= ';')
3228 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3236 error (_("Malformed response to offset query, %s"), buf
);
3237 else if (*ptr
!= '\0')
3238 warning (_("Target reported unsupported offsets: %s"), buf
);
3240 offs
= ((struct section_offsets
*)
3241 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3242 memcpy (offs
, symfile_objfile
->section_offsets
,
3243 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3245 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3246 do_segments
= (data
!= NULL
);
3247 do_sections
= num_segments
== 0;
3249 if (num_segments
> 0)
3251 segments
[0] = text_addr
;
3252 segments
[1] = data_addr
;
3254 /* If we have two segments, we can still try to relocate everything
3255 by assuming that the .text and .data offsets apply to the whole
3256 text and data segments. Convert the offsets given in the packet
3257 to base addresses for symfile_map_offsets_to_segments. */
3258 else if (data
&& data
->num_segments
== 2)
3260 segments
[0] = data
->segment_bases
[0] + text_addr
;
3261 segments
[1] = data
->segment_bases
[1] + data_addr
;
3264 /* If the object file has only one segment, assume that it is text
3265 rather than data; main programs with no writable data are rare,
3266 but programs with no code are useless. Of course the code might
3267 have ended up in the data segment... to detect that we would need
3268 the permissions here. */
3269 else if (data
&& data
->num_segments
== 1)
3271 segments
[0] = data
->segment_bases
[0] + text_addr
;
3274 /* There's no way to relocate by segment. */
3280 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3281 offs
, num_segments
, segments
);
3283 if (ret
== 0 && !do_sections
)
3284 error (_("Can not handle qOffsets TextSeg "
3285 "response with this symbol file"));
3292 free_symfile_segment_data (data
);
3296 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3298 /* This is a temporary kludge to force data and bss to use the
3299 same offsets because that's what nlmconv does now. The real
3300 solution requires changes to the stub and remote.c that I
3301 don't have time to do right now. */
3303 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3304 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3307 objfile_relocate (symfile_objfile
, offs
);
3310 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3311 threads we know are stopped already. This is used during the
3312 initial remote connection in non-stop mode --- threads that are
3313 reported as already being stopped are left stopped. */
3316 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3318 /* If we have a stop reply for this thread, it must be stopped. */
3319 if (peek_stop_reply (thread
->ptid
))
3320 set_stop_requested (thread
->ptid
, 1);
3325 /* Send interrupt_sequence to remote target. */
3327 send_interrupt_sequence (void)
3329 struct remote_state
*rs
= get_remote_state ();
3331 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3332 remote_serial_write ("\x03", 1);
3333 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3334 serial_send_break (rs
->remote_desc
);
3335 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3337 serial_send_break (rs
->remote_desc
);
3338 remote_serial_write ("g", 1);
3341 internal_error (__FILE__
, __LINE__
,
3342 _("Invalid value for interrupt_sequence_mode: %s."),
3343 interrupt_sequence_mode
);
3347 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3348 and extract the PTID. Returns NULL_PTID if not found. */
3351 stop_reply_extract_thread (char *stop_reply
)
3353 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3357 /* Txx r:val ; r:val (...) */
3360 /* Look for "register" named "thread". */
3365 p1
= strchr (p
, ':');
3369 if (strncmp (p
, "thread", p1
- p
) == 0)
3370 return read_ptid (++p1
, &p
);
3372 p1
= strchr (p
, ';');
3384 /* Determine the remote side's current thread. If we have a stop
3385 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3386 "thread" register we can extract the current thread from. If not,
3387 ask the remote which is the current thread with qC. The former
3388 method avoids a roundtrip. */
3391 get_current_thread (char *wait_status
)
3395 /* Note we don't use remote_parse_stop_reply as that makes use of
3396 the target architecture, which we haven't yet fully determined at
3398 if (wait_status
!= NULL
)
3399 ptid
= stop_reply_extract_thread (wait_status
);
3400 if (ptid_equal (ptid
, null_ptid
))
3401 ptid
= remote_current_thread (inferior_ptid
);
3406 /* Query the remote target for which is the current thread/process,
3407 add it to our tables, and update INFERIOR_PTID. The caller is
3408 responsible for setting the state such that the remote end is ready
3409 to return the current thread.
3411 This function is called after handling the '?' or 'vRun' packets,
3412 whose response is a stop reply from which we can also try
3413 extracting the thread. If the target doesn't support the explicit
3414 qC query, we infer the current thread from that stop reply, passed
3415 in in WAIT_STATUS, which may be NULL. */
3418 add_current_inferior_and_thread (char *wait_status
)
3420 struct remote_state
*rs
= get_remote_state ();
3422 ptid_t ptid
= null_ptid
;
3424 inferior_ptid
= null_ptid
;
3426 /* Now, if we have thread information, update inferior_ptid. */
3427 ptid
= get_current_thread (wait_status
);
3429 if (!ptid_equal (ptid
, null_ptid
))
3431 if (!remote_multi_process_p (rs
))
3434 inferior_ptid
= ptid
;
3438 /* Without this, some commands which require an active target
3439 (such as kill) won't work. This variable serves (at least)
3440 double duty as both the pid of the target process (if it has
3441 such), and as a flag indicating that a target is active. */
3442 inferior_ptid
= magic_null_ptid
;
3446 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3448 /* Add the main thread. */
3449 add_thread_silent (inferior_ptid
);
3453 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3455 struct remote_state
*rs
= get_remote_state ();
3456 struct packet_config
*noack_config
;
3457 char *wait_status
= NULL
;
3459 immediate_quit
++; /* Allow user to interrupt it. */
3462 if (interrupt_on_connect
)
3463 send_interrupt_sequence ();
3465 /* Ack any packet which the remote side has already sent. */
3466 serial_write (rs
->remote_desc
, "+", 1);
3468 /* Signal other parts that we're going through the initial setup,
3469 and so things may not be stable yet. */
3470 rs
->starting_up
= 1;
3472 /* The first packet we send to the target is the optional "supported
3473 packets" request. If the target can answer this, it will tell us
3474 which later probes to skip. */
3475 remote_query_supported ();
3477 /* If the stub wants to get a QAllow, compose one and send it. */
3478 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3479 remote_set_permissions (target
);
3481 /* Next, we possibly activate noack mode.
3483 If the QStartNoAckMode packet configuration is set to AUTO,
3484 enable noack mode if the stub reported a wish for it with
3487 If set to TRUE, then enable noack mode even if the stub didn't
3488 report it in qSupported. If the stub doesn't reply OK, the
3489 session ends with an error.
3491 If FALSE, then don't activate noack mode, regardless of what the
3492 stub claimed should be the default with qSupported. */
3494 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3495 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3497 putpkt ("QStartNoAckMode");
3498 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3499 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3505 /* Tell the remote that we are using the extended protocol. */
3507 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3510 /* Let the target know which signals it is allowed to pass down to
3512 update_signals_program_target ();
3514 /* Next, if the target can specify a description, read it. We do
3515 this before anything involving memory or registers. */
3516 target_find_description ();
3518 /* Next, now that we know something about the target, update the
3519 address spaces in the program spaces. */
3520 update_address_spaces ();
3522 /* On OSs where the list of libraries is global to all
3523 processes, we fetch them early. */
3524 if (gdbarch_has_global_solist (target_gdbarch ()))
3525 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3529 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3530 error (_("Non-stop mode requested, but remote "
3531 "does not support non-stop"));
3533 putpkt ("QNonStop:1");
3534 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3536 if (strcmp (rs
->buf
, "OK") != 0)
3537 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3539 /* Find about threads and processes the stub is already
3540 controlling. We default to adding them in the running state.
3541 The '?' query below will then tell us about which threads are
3543 remote_update_thread_list (target
);
3545 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3547 /* Don't assume that the stub can operate in all-stop mode.
3548 Request it explicitly. */
3549 putpkt ("QNonStop:0");
3550 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3552 if (strcmp (rs
->buf
, "OK") != 0)
3553 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3556 /* Upload TSVs regardless of whether the target is running or not. The
3557 remote stub, such as GDBserver, may have some predefined or builtin
3558 TSVs, even if the target is not running. */
3559 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3561 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3563 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3564 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3567 /* Check whether the target is running now. */
3569 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3575 struct inferior
*inf
;
3577 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3580 error (_("The target is not running (try extended-remote?)"));
3582 /* We're connected, but not running. Drop out before we
3583 call start_remote. */
3584 rs
->starting_up
= 0;
3589 /* Save the reply for later. */
3590 wait_status
= alloca (strlen (rs
->buf
) + 1);
3591 strcpy (wait_status
, rs
->buf
);
3594 /* Fetch thread list. */
3595 target_update_thread_list ();
3597 /* Let the stub know that we want it to return the thread. */
3598 set_continue_thread (minus_one_ptid
);
3600 if (thread_count () == 0)
3602 /* Target has no concept of threads at all. GDB treats
3603 non-threaded target as single-threaded; add a main
3605 add_current_inferior_and_thread (wait_status
);
3609 /* We have thread information; select the thread the target
3610 says should be current. If we're reconnecting to a
3611 multi-threaded program, this will ideally be the thread
3612 that last reported an event before GDB disconnected. */
3613 inferior_ptid
= get_current_thread (wait_status
);
3614 if (ptid_equal (inferior_ptid
, null_ptid
))
3616 /* Odd... The target was able to list threads, but not
3617 tell us which thread was current (no "thread"
3618 register in T stop reply?). Just pick the first
3619 thread in the thread list then. */
3620 inferior_ptid
= thread_list
->ptid
;
3624 /* init_wait_for_inferior should be called before get_offsets in order
3625 to manage `inserted' flag in bp loc in a correct state.
3626 breakpoint_init_inferior, called from init_wait_for_inferior, set
3627 `inserted' flag to 0, while before breakpoint_re_set, called from
3628 start_remote, set `inserted' flag to 1. In the initialization of
3629 inferior, breakpoint_init_inferior should be called first, and then
3630 breakpoint_re_set can be called. If this order is broken, state of
3631 `inserted' flag is wrong, and cause some problems on breakpoint
3633 init_wait_for_inferior ();
3635 get_offsets (); /* Get text, data & bss offsets. */
3637 /* If we could not find a description using qXfer, and we know
3638 how to do it some other way, try again. This is not
3639 supported for non-stop; it could be, but it is tricky if
3640 there are no stopped threads when we connect. */
3641 if (remote_read_description_p (target
)
3642 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3644 target_clear_description ();
3645 target_find_description ();
3648 /* Use the previously fetched status. */
3649 gdb_assert (wait_status
!= NULL
);
3650 strcpy (rs
->buf
, wait_status
);
3651 rs
->cached_wait_status
= 1;
3654 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3658 /* Clear WFI global state. Do this before finding about new
3659 threads and inferiors, and setting the current inferior.
3660 Otherwise we would clear the proceed status of the current
3661 inferior when we want its stop_soon state to be preserved
3662 (see notice_new_inferior). */
3663 init_wait_for_inferior ();
3665 /* In non-stop, we will either get an "OK", meaning that there
3666 are no stopped threads at this time; or, a regular stop
3667 reply. In the latter case, there may be more than one thread
3668 stopped --- we pull them all out using the vStopped
3670 if (strcmp (rs
->buf
, "OK") != 0)
3672 struct notif_client
*notif
= ¬if_client_stop
;
3674 /* remote_notif_get_pending_replies acks this one, and gets
3676 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3677 = remote_notif_parse (notif
, rs
->buf
);
3678 remote_notif_get_pending_events (notif
);
3680 /* Make sure that threads that were stopped remain
3682 iterate_over_threads (set_stop_requested_callback
, NULL
);
3685 if (target_can_async_p ())
3688 if (thread_count () == 0)
3691 error (_("The target is not running (try extended-remote?)"));
3693 /* We're connected, but not running. Drop out before we
3694 call start_remote. */
3695 rs
->starting_up
= 0;
3699 /* Let the stub know that we want it to return the thread. */
3701 /* Force the stub to choose a thread. */
3702 set_general_thread (null_ptid
);
3705 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3706 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3707 error (_("remote didn't report the current thread in non-stop mode"));
3709 get_offsets (); /* Get text, data & bss offsets. */
3711 /* In non-stop mode, any cached wait status will be stored in
3712 the stop reply queue. */
3713 gdb_assert (wait_status
== NULL
);
3715 /* Report all signals during attach/startup. */
3716 remote_pass_signals (target
, 0, NULL
);
3719 /* If we connected to a live target, do some additional setup. */
3720 if (target_has_execution
)
3722 if (symfile_objfile
) /* No use without a symbol-file. */
3723 remote_check_symbols ();
3726 /* Possibly the target has been engaged in a trace run started
3727 previously; find out where things are at. */
3728 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3730 struct uploaded_tp
*uploaded_tps
= NULL
;
3732 if (current_trace_status ()->running
)
3733 printf_filtered (_("Trace is already running on the target.\n"));
3735 remote_upload_tracepoints (target
, &uploaded_tps
);
3737 merge_uploaded_tracepoints (&uploaded_tps
);
3740 /* The thread and inferior lists are now synchronized with the
3741 target, our symbols have been relocated, and we're merged the
3742 target's tracepoints with ours. We're done with basic start
3744 rs
->starting_up
= 0;
3746 /* Maybe breakpoints are global and need to be inserted now. */
3747 if (breakpoints_should_be_inserted_now ())
3748 insert_breakpoints ();
3751 /* Open a connection to a remote debugger.
3752 NAME is the filename used for communication. */
3755 remote_open (const char *name
, int from_tty
)
3757 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3760 /* Open a connection to a remote debugger using the extended
3761 remote gdb protocol. NAME is the filename used for communication. */
3764 extended_remote_open (const char *name
, int from_tty
)
3766 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3769 /* Reset all packets back to "unknown support". Called when opening a
3770 new connection to a remote target. */
3773 reset_all_packet_configs_support (void)
3777 for (i
= 0; i
< PACKET_MAX
; i
++)
3778 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3781 /* Initialize all packet configs. */
3784 init_all_packet_configs (void)
3788 for (i
= 0; i
< PACKET_MAX
; i
++)
3790 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3791 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3795 /* Symbol look-up. */
3798 remote_check_symbols (void)
3800 struct remote_state
*rs
= get_remote_state ();
3801 char *msg
, *reply
, *tmp
;
3802 struct bound_minimal_symbol sym
;
3805 /* The remote side has no concept of inferiors that aren't running
3806 yet, it only knows about running processes. If we're connected
3807 but our current inferior is not running, we should not invite the
3808 remote target to request symbol lookups related to its
3809 (unrelated) current process. */
3810 if (!target_has_execution
)
3813 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3816 /* Make sure the remote is pointing at the right process. Note
3817 there's no way to select "no process". */
3818 set_general_process ();
3820 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3821 because we need both at the same time. */
3822 msg
= alloca (get_remote_packet_size ());
3824 /* Invite target to request symbol lookups. */
3826 putpkt ("qSymbol::");
3827 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3828 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3831 while (startswith (reply
, "qSymbol:"))
3833 struct bound_minimal_symbol sym
;
3836 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3838 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3839 if (sym
.minsym
== NULL
)
3840 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3843 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3844 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3846 /* If this is a function address, return the start of code
3847 instead of any data function descriptor. */
3848 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3852 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3853 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3857 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3862 static struct serial
*
3863 remote_serial_open (const char *name
)
3865 static int udp_warning
= 0;
3867 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3868 of in ser-tcp.c, because it is the remote protocol assuming that the
3869 serial connection is reliable and not the serial connection promising
3871 if (!udp_warning
&& startswith (name
, "udp:"))
3873 warning (_("The remote protocol may be unreliable over UDP.\n"
3874 "Some events may be lost, rendering further debugging "
3879 return serial_open (name
);
3882 /* Inform the target of our permission settings. The permission flags
3883 work without this, but if the target knows the settings, it can do
3884 a couple things. First, it can add its own check, to catch cases
3885 that somehow manage to get by the permissions checks in target
3886 methods. Second, if the target is wired to disallow particular
3887 settings (for instance, a system in the field that is not set up to
3888 be able to stop at a breakpoint), it can object to any unavailable
3892 remote_set_permissions (struct target_ops
*self
)
3894 struct remote_state
*rs
= get_remote_state ();
3896 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3897 "WriteReg:%x;WriteMem:%x;"
3898 "InsertBreak:%x;InsertTrace:%x;"
3899 "InsertFastTrace:%x;Stop:%x",
3900 may_write_registers
, may_write_memory
,
3901 may_insert_breakpoints
, may_insert_tracepoints
,
3902 may_insert_fast_tracepoints
, may_stop
);
3904 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3906 /* If the target didn't like the packet, warn the user. Do not try
3907 to undo the user's settings, that would just be maddening. */
3908 if (strcmp (rs
->buf
, "OK") != 0)
3909 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3912 /* This type describes each known response to the qSupported
3914 struct protocol_feature
3916 /* The name of this protocol feature. */
3919 /* The default for this protocol feature. */
3920 enum packet_support default_support
;
3922 /* The function to call when this feature is reported, or after
3923 qSupported processing if the feature is not supported.
3924 The first argument points to this structure. The second
3925 argument indicates whether the packet requested support be
3926 enabled, disabled, or probed (or the default, if this function
3927 is being called at the end of processing and this feature was
3928 not reported). The third argument may be NULL; if not NULL, it
3929 is a NUL-terminated string taken from the packet following
3930 this feature's name and an equals sign. */
3931 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3934 /* The corresponding packet for this feature. Only used if
3935 FUNC is remote_supported_packet. */
3940 remote_supported_packet (const struct protocol_feature
*feature
,
3941 enum packet_support support
,
3942 const char *argument
)
3946 warning (_("Remote qSupported response supplied an unexpected value for"
3947 " \"%s\"."), feature
->name
);
3951 remote_protocol_packets
[feature
->packet
].support
= support
;
3955 remote_packet_size (const struct protocol_feature
*feature
,
3956 enum packet_support support
, const char *value
)
3958 struct remote_state
*rs
= get_remote_state ();
3963 if (support
!= PACKET_ENABLE
)
3966 if (value
== NULL
|| *value
== '\0')
3968 warning (_("Remote target reported \"%s\" without a size."),
3974 packet_size
= strtol (value
, &value_end
, 16);
3975 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3977 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3978 feature
->name
, value
);
3982 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3984 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3985 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3986 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3989 /* Record the new maximum packet size. */
3990 rs
->explicit_packet_size
= packet_size
;
3993 static const struct protocol_feature remote_protocol_features
[] = {
3994 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3995 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3996 PACKET_qXfer_auxv
},
3997 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
3998 PACKET_qXfer_exec_file
},
3999 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4000 PACKET_qXfer_features
},
4001 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4002 PACKET_qXfer_libraries
},
4003 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4004 PACKET_qXfer_libraries_svr4
},
4005 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4006 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4007 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4008 PACKET_qXfer_memory_map
},
4009 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4010 PACKET_qXfer_spu_read
},
4011 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4012 PACKET_qXfer_spu_write
},
4013 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4014 PACKET_qXfer_osdata
},
4015 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4016 PACKET_qXfer_threads
},
4017 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4018 PACKET_qXfer_traceframe_info
},
4019 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4020 PACKET_QPassSignals
},
4021 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4022 PACKET_QProgramSignals
},
4023 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4024 PACKET_QStartNoAckMode
},
4025 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4026 PACKET_multiprocess_feature
},
4027 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4028 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4029 PACKET_qXfer_siginfo_read
},
4030 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4031 PACKET_qXfer_siginfo_write
},
4032 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4033 PACKET_ConditionalTracepoints
},
4034 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4035 PACKET_ConditionalBreakpoints
},
4036 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4037 PACKET_BreakpointCommands
},
4038 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4039 PACKET_FastTracepoints
},
4040 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4041 PACKET_StaticTracepoints
},
4042 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4043 PACKET_InstallInTrace
},
4044 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4045 PACKET_DisconnectedTracing_feature
},
4046 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4048 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4050 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4051 PACKET_TracepointSource
},
4052 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4054 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4055 PACKET_EnableDisableTracepoints_feature
},
4056 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4057 PACKET_qXfer_fdpic
},
4058 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4060 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4061 PACKET_QDisableRandomization
},
4062 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4063 { "QTBuffer:size", PACKET_DISABLE
,
4064 remote_supported_packet
, PACKET_QTBuffer_size
},
4065 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4066 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4067 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4068 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4069 PACKET_qXfer_btrace
},
4070 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4071 PACKET_qXfer_btrace_conf
},
4072 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4073 PACKET_Qbtrace_conf_bts_size
},
4074 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4075 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4076 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4077 PACKET_fork_event_feature
},
4078 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4079 PACKET_vfork_event_feature
},
4082 static char *remote_support_xml
;
4084 /* Register string appended to "xmlRegisters=" in qSupported query. */
4087 register_remote_support_xml (const char *xml
)
4089 #if defined(HAVE_LIBEXPAT)
4090 if (remote_support_xml
== NULL
)
4091 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4094 char *copy
= xstrdup (remote_support_xml
+ 13);
4095 char *p
= strtok (copy
, ",");
4099 if (strcmp (p
, xml
) == 0)
4106 while ((p
= strtok (NULL
, ",")) != NULL
);
4109 remote_support_xml
= reconcat (remote_support_xml
,
4110 remote_support_xml
, ",", xml
,
4117 remote_query_supported_append (char *msg
, const char *append
)
4120 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4122 return xstrdup (append
);
4126 remote_query_supported (void)
4128 struct remote_state
*rs
= get_remote_state ();
4131 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4133 /* The packet support flags are handled differently for this packet
4134 than for most others. We treat an error, a disabled packet, and
4135 an empty response identically: any features which must be reported
4136 to be used will be automatically disabled. An empty buffer
4137 accomplishes this, since that is also the representation for a list
4138 containing no features. */
4141 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4144 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4146 q
= remote_query_supported_append (q
, "multiprocess+");
4148 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4149 q
= remote_query_supported_append (q
, "swbreak+");
4150 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4151 q
= remote_query_supported_append (q
, "hwbreak+");
4153 if (remote_support_xml
)
4154 q
= remote_query_supported_append (q
, remote_support_xml
);
4156 q
= remote_query_supported_append (q
, "qRelocInsn+");
4160 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4161 != AUTO_BOOLEAN_FALSE
)
4162 q
= remote_query_supported_append (q
, "fork-events+");
4163 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4164 != AUTO_BOOLEAN_FALSE
)
4165 q
= remote_query_supported_append (q
, "vfork-events+");
4168 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4171 do_cleanups (old_chain
);
4173 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4175 /* If an error occured, warn, but do not return - just reset the
4176 buffer to empty and go on to disable features. */
4177 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4180 warning (_("Remote failure reply: %s"), rs
->buf
);
4185 memset (seen
, 0, sizeof (seen
));
4190 enum packet_support is_supported
;
4191 char *p
, *end
, *name_end
, *value
;
4193 /* First separate out this item from the rest of the packet. If
4194 there's another item after this, we overwrite the separator
4195 (terminated strings are much easier to work with). */
4197 end
= strchr (p
, ';');
4200 end
= p
+ strlen (p
);
4210 warning (_("empty item in \"qSupported\" response"));
4215 name_end
= strchr (p
, '=');
4218 /* This is a name=value entry. */
4219 is_supported
= PACKET_ENABLE
;
4220 value
= name_end
+ 1;
4229 is_supported
= PACKET_ENABLE
;
4233 is_supported
= PACKET_DISABLE
;
4237 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4241 warning (_("unrecognized item \"%s\" "
4242 "in \"qSupported\" response"), p
);
4248 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4249 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4251 const struct protocol_feature
*feature
;
4254 feature
= &remote_protocol_features
[i
];
4255 feature
->func (feature
, is_supported
, value
);
4260 /* If we increased the packet size, make sure to increase the global
4261 buffer size also. We delay this until after parsing the entire
4262 qSupported packet, because this is the same buffer we were
4264 if (rs
->buf_size
< rs
->explicit_packet_size
)
4266 rs
->buf_size
= rs
->explicit_packet_size
;
4267 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4270 /* Handle the defaults for unmentioned features. */
4271 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4274 const struct protocol_feature
*feature
;
4276 feature
= &remote_protocol_features
[i
];
4277 feature
->func (feature
, feature
->default_support
, NULL
);
4281 /* Remove any of the remote.c targets from target stack. Upper targets depend
4282 on it so remove them first. */
4285 remote_unpush_target (void)
4287 pop_all_targets_above (process_stratum
- 1);
4291 remote_open_1 (const char *name
, int from_tty
,
4292 struct target_ops
*target
, int extended_p
)
4294 struct remote_state
*rs
= get_remote_state ();
4297 error (_("To open a remote debug connection, you need to specify what\n"
4298 "serial device is attached to the remote system\n"
4299 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4301 /* See FIXME above. */
4302 if (!target_async_permitted
)
4303 wait_forever_enabled_p
= 1;
4305 /* If we're connected to a running target, target_preopen will kill it.
4306 Ask this question first, before target_preopen has a chance to kill
4308 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4311 && !query (_("Already connected to a remote target. Disconnect? ")))
4312 error (_("Still connected."));
4315 /* Here the possibly existing remote target gets unpushed. */
4316 target_preopen (from_tty
);
4318 /* Make sure we send the passed signals list the next time we resume. */
4319 xfree (rs
->last_pass_packet
);
4320 rs
->last_pass_packet
= NULL
;
4322 /* Make sure we send the program signals list the next time we
4324 xfree (rs
->last_program_signals_packet
);
4325 rs
->last_program_signals_packet
= NULL
;
4327 remote_fileio_reset ();
4328 reopen_exec_file ();
4331 rs
->remote_desc
= remote_serial_open (name
);
4332 if (!rs
->remote_desc
)
4333 perror_with_name (name
);
4335 if (baud_rate
!= -1)
4337 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4339 /* The requested speed could not be set. Error out to
4340 top level after closing remote_desc. Take care to
4341 set remote_desc to NULL to avoid closing remote_desc
4343 serial_close (rs
->remote_desc
);
4344 rs
->remote_desc
= NULL
;
4345 perror_with_name (name
);
4349 serial_setparity (rs
->remote_desc
, serial_parity
);
4350 serial_raw (rs
->remote_desc
);
4352 /* If there is something sitting in the buffer we might take it as a
4353 response to a command, which would be bad. */
4354 serial_flush_input (rs
->remote_desc
);
4358 puts_filtered ("Remote debugging using ");
4359 puts_filtered (name
);
4360 puts_filtered ("\n");
4362 push_target (target
); /* Switch to using remote target now. */
4364 /* Register extra event sources in the event loop. */
4365 remote_async_inferior_event_token
4366 = create_async_event_handler (remote_async_inferior_event_handler
,
4368 rs
->notif_state
= remote_notif_state_allocate ();
4370 /* Reset the target state; these things will be queried either by
4371 remote_query_supported or as they are needed. */
4372 reset_all_packet_configs_support ();
4373 rs
->cached_wait_status
= 0;
4374 rs
->explicit_packet_size
= 0;
4376 rs
->extended
= extended_p
;
4377 rs
->waiting_for_stop_reply
= 0;
4378 rs
->ctrlc_pending_p
= 0;
4380 rs
->general_thread
= not_sent_ptid
;
4381 rs
->continue_thread
= not_sent_ptid
;
4382 rs
->remote_traceframe_number
= -1;
4384 /* Probe for ability to use "ThreadInfo" query, as required. */
4385 rs
->use_threadinfo_query
= 1;
4386 rs
->use_threadextra_query
= 1;
4388 if (target_async_permitted
)
4390 /* With this target we start out by owning the terminal. */
4391 remote_async_terminal_ours_p
= 1;
4393 /* FIXME: cagney/1999-09-23: During the initial connection it is
4394 assumed that the target is already ready and able to respond to
4395 requests. Unfortunately remote_start_remote() eventually calls
4396 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4397 around this. Eventually a mechanism that allows
4398 wait_for_inferior() to expect/get timeouts will be
4400 wait_forever_enabled_p
= 0;
4403 /* First delete any symbols previously loaded from shared libraries. */
4404 no_shared_libraries (NULL
, 0);
4407 init_thread_list ();
4409 /* Start the remote connection. If error() or QUIT, discard this
4410 target (we'd otherwise be in an inconsistent state) and then
4411 propogate the error on up the exception chain. This ensures that
4412 the caller doesn't stumble along blindly assuming that the
4413 function succeeded. The CLI doesn't have this problem but other
4414 UI's, such as MI do.
4416 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4417 this function should return an error indication letting the
4418 caller restore the previous state. Unfortunately the command
4419 ``target remote'' is directly wired to this function making that
4420 impossible. On a positive note, the CLI side of this problem has
4421 been fixed - the function set_cmd_context() makes it possible for
4422 all the ``target ....'' commands to share a common callback
4423 function. See cli-dump.c. */
4428 remote_start_remote (from_tty
, target
, extended_p
);
4430 CATCH (ex
, RETURN_MASK_ALL
)
4432 /* Pop the partially set up target - unless something else did
4433 already before throwing the exception. */
4434 if (rs
->remote_desc
!= NULL
)
4435 remote_unpush_target ();
4436 if (target_async_permitted
)
4437 wait_forever_enabled_p
= 1;
4438 throw_exception (ex
);
4443 remote_btrace_reset ();
4445 if (target_async_permitted
)
4446 wait_forever_enabled_p
= 1;
4449 /* Detach the specified process. */
4452 remote_detach_pid (int pid
)
4454 struct remote_state
*rs
= get_remote_state ();
4456 if (remote_multi_process_p (rs
))
4457 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4459 strcpy (rs
->buf
, "D");
4462 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4464 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4466 else if (rs
->buf
[0] == '\0')
4467 error (_("Remote doesn't know how to detach"));
4469 error (_("Can't detach process."));
4472 /* This detaches a program to which we previously attached, using
4473 inferior_ptid to identify the process. After this is done, GDB
4474 can be used to debug some other program. We better not have left
4475 any breakpoints in the target program or it'll die when it hits
4479 remote_detach_1 (const char *args
, int from_tty
)
4481 int pid
= ptid_get_pid (inferior_ptid
);
4482 struct remote_state
*rs
= get_remote_state ();
4483 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4487 error (_("Argument given to \"detach\" when remotely debugging."));
4489 if (!target_has_execution
)
4490 error (_("No process to detach from."));
4494 char *exec_file
= get_exec_file (0);
4495 if (exec_file
== NULL
)
4497 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4498 target_pid_to_str (pid_to_ptid (pid
)));
4499 gdb_flush (gdb_stdout
);
4502 /* Tell the remote target to detach. */
4503 remote_detach_pid (pid
);
4505 if (from_tty
&& !rs
->extended
)
4506 puts_filtered (_("Ending remote debugging.\n"));
4508 /* Check to see if we are detaching a fork parent. Note that if we
4509 are detaching a fork child, tp == NULL. */
4510 is_fork_parent
= (tp
!= NULL
4511 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4513 /* If doing detach-on-fork, we don't mourn, because that will delete
4514 breakpoints that should be available for the followed inferior. */
4515 if (!is_fork_parent
)
4516 target_mourn_inferior ();
4519 inferior_ptid
= null_ptid
;
4520 detach_inferior (pid
);
4525 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4527 remote_detach_1 (args
, from_tty
);
4531 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4533 remote_detach_1 (args
, from_tty
);
4536 /* Target follow-fork function for remote targets. On entry, and
4537 at return, the current inferior is the fork parent.
4539 Note that although this is currently only used for extended-remote,
4540 it is named remote_follow_fork in anticipation of using it for the
4541 remote target as well. */
4544 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4547 struct remote_state
*rs
= get_remote_state ();
4548 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4550 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4551 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4553 /* When following the parent and detaching the child, we detach
4554 the child here. For the case of following the child and
4555 detaching the parent, the detach is done in the target-
4556 independent follow fork code in infrun.c. We can't use
4557 target_detach when detaching an unfollowed child because
4558 the client side doesn't know anything about the child. */
4559 if (detach_fork
&& !follow_child
)
4561 /* Detach the fork child. */
4565 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4566 child_pid
= ptid_get_pid (child_ptid
);
4568 remote_detach_pid (child_pid
);
4569 detach_inferior (child_pid
);
4575 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4578 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4581 error (_("Argument given to \"disconnect\" when remotely debugging."));
4583 /* Make sure we unpush even the extended remote targets; mourn
4584 won't do it. So call remote_mourn directly instead of
4585 target_mourn_inferior. */
4586 remote_mourn (target
);
4589 puts_filtered ("Ending remote debugging.\n");
4592 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4593 be chatty about it. */
4596 extended_remote_attach (struct target_ops
*target
, const char *args
,
4599 struct remote_state
*rs
= get_remote_state ();
4601 char *wait_status
= NULL
;
4603 pid
= parse_pid_to_attach (args
);
4605 /* Remote PID can be freely equal to getpid, do not check it here the same
4606 way as in other targets. */
4608 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4609 error (_("This target does not support attaching to a process"));
4613 char *exec_file
= get_exec_file (0);
4616 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4617 target_pid_to_str (pid_to_ptid (pid
)));
4619 printf_unfiltered (_("Attaching to %s\n"),
4620 target_pid_to_str (pid_to_ptid (pid
)));
4622 gdb_flush (gdb_stdout
);
4625 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4627 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4629 switch (packet_ok (rs
->buf
,
4630 &remote_protocol_packets
[PACKET_vAttach
]))
4635 /* Save the reply for later. */
4636 wait_status
= alloca (strlen (rs
->buf
) + 1);
4637 strcpy (wait_status
, rs
->buf
);
4639 else if (strcmp (rs
->buf
, "OK") != 0)
4640 error (_("Attaching to %s failed with: %s"),
4641 target_pid_to_str (pid_to_ptid (pid
)),
4644 case PACKET_UNKNOWN
:
4645 error (_("This target does not support attaching to a process"));
4647 error (_("Attaching to %s failed"),
4648 target_pid_to_str (pid_to_ptid (pid
)));
4651 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4653 inferior_ptid
= pid_to_ptid (pid
);
4657 struct thread_info
*thread
;
4659 /* Get list of threads. */
4660 remote_update_thread_list (target
);
4662 thread
= first_thread_of_process (pid
);
4664 inferior_ptid
= thread
->ptid
;
4666 inferior_ptid
= pid_to_ptid (pid
);
4668 /* Invalidate our notion of the remote current thread. */
4669 record_currthread (rs
, minus_one_ptid
);
4673 /* Now, if we have thread information, update inferior_ptid. */
4674 inferior_ptid
= remote_current_thread (inferior_ptid
);
4676 /* Add the main thread to the thread list. */
4677 add_thread_silent (inferior_ptid
);
4680 /* Next, if the target can specify a description, read it. We do
4681 this before anything involving memory or registers. */
4682 target_find_description ();
4686 /* Use the previously fetched status. */
4687 gdb_assert (wait_status
!= NULL
);
4689 if (target_can_async_p ())
4691 struct notif_event
*reply
4692 = remote_notif_parse (¬if_client_stop
, wait_status
);
4694 push_stop_reply ((struct stop_reply
*) reply
);
4700 gdb_assert (wait_status
!= NULL
);
4701 strcpy (rs
->buf
, wait_status
);
4702 rs
->cached_wait_status
= 1;
4706 gdb_assert (wait_status
== NULL
);
4709 /* Implementation of the to_post_attach method. */
4712 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4714 /* In certain cases GDB might not have had the chance to start
4715 symbol lookup up until now. This could happen if the debugged
4716 binary is not using shared libraries, the vsyscall page is not
4717 present (on Linux) and the binary itself hadn't changed since the
4718 debugging process was started. */
4719 if (symfile_objfile
!= NULL
)
4720 remote_check_symbols();
4724 /* Check for the availability of vCont. This function should also check
4728 remote_vcont_probe (struct remote_state
*rs
)
4732 strcpy (rs
->buf
, "vCont?");
4734 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4737 /* Make sure that the features we assume are supported. */
4738 if (startswith (buf
, "vCont"))
4741 int support_s
, support_S
, support_c
, support_C
;
4747 rs
->supports_vCont
.t
= 0;
4748 rs
->supports_vCont
.r
= 0;
4749 while (p
&& *p
== ';')
4752 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4754 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4756 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4758 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4760 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4761 rs
->supports_vCont
.t
= 1;
4762 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4763 rs
->supports_vCont
.r
= 1;
4765 p
= strchr (p
, ';');
4768 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4769 BUF will make packet_ok disable the packet. */
4770 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4774 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4777 /* Helper function for building "vCont" resumptions. Write a
4778 resumption to P. ENDP points to one-passed-the-end of the buffer
4779 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4780 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4781 resumed thread should be single-stepped and/or signalled. If PTID
4782 equals minus_one_ptid, then all threads are resumed; if PTID
4783 represents a process, then all threads of the process are resumed;
4784 the thread to be stepped and/or signalled is given in the global
4788 append_resumption (char *p
, char *endp
,
4789 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4791 struct remote_state
*rs
= get_remote_state ();
4793 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4794 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4796 /* GDB is willing to range step. */
4797 && use_range_stepping
4798 /* Target supports range stepping. */
4799 && rs
->supports_vCont
.r
4800 /* We don't currently support range stepping multiple
4801 threads with a wildcard (though the protocol allows it,
4802 so stubs shouldn't make an active effort to forbid
4804 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4806 struct thread_info
*tp
;
4808 if (ptid_equal (ptid
, minus_one_ptid
))
4810 /* If we don't know about the target thread's tid, then
4811 we're resuming magic_null_ptid (see caller). */
4812 tp
= find_thread_ptid (magic_null_ptid
);
4815 tp
= find_thread_ptid (ptid
);
4816 gdb_assert (tp
!= NULL
);
4818 if (tp
->control
.may_range_step
)
4820 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4822 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4823 phex_nz (tp
->control
.step_range_start
,
4825 phex_nz (tp
->control
.step_range_end
,
4829 p
+= xsnprintf (p
, endp
- p
, ";s");
4832 p
+= xsnprintf (p
, endp
- p
, ";s");
4833 else if (siggnal
!= GDB_SIGNAL_0
)
4834 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4836 p
+= xsnprintf (p
, endp
- p
, ";c");
4838 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4842 /* All (-1) threads of process. */
4843 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4845 p
+= xsnprintf (p
, endp
- p
, ":");
4846 p
= write_ptid (p
, endp
, nptid
);
4848 else if (!ptid_equal (ptid
, minus_one_ptid
))
4850 p
+= xsnprintf (p
, endp
- p
, ":");
4851 p
= write_ptid (p
, endp
, ptid
);
4857 /* Append a vCont continue-with-signal action for threads that have a
4858 non-zero stop signal. */
4861 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4863 struct thread_info
*thread
;
4865 ALL_NON_EXITED_THREADS (thread
)
4866 if (ptid_match (thread
->ptid
, ptid
)
4867 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4868 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4870 p
= append_resumption (p
, endp
, thread
->ptid
,
4871 0, thread
->suspend
.stop_signal
);
4872 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4878 /* Resume the remote inferior by using a "vCont" packet. The thread
4879 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4880 resumed thread should be single-stepped and/or signalled. If PTID
4881 equals minus_one_ptid, then all threads are resumed; the thread to
4882 be stepped and/or signalled is given in the global INFERIOR_PTID.
4883 This function returns non-zero iff it resumes the inferior.
4885 This function issues a strict subset of all possible vCont commands at the
4889 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4891 struct remote_state
*rs
= get_remote_state ();
4895 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
4896 remote_vcont_probe (rs
);
4898 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
4902 endp
= rs
->buf
+ get_remote_packet_size ();
4904 /* If we could generate a wider range of packets, we'd have to worry
4905 about overflowing BUF. Should there be a generic
4906 "multi-part-packet" packet? */
4908 p
+= xsnprintf (p
, endp
- p
, "vCont");
4910 if (ptid_equal (ptid
, magic_null_ptid
))
4912 /* MAGIC_NULL_PTID means that we don't have any active threads,
4913 so we don't have any TID numbers the inferior will
4914 understand. Make sure to only send forms that do not specify
4916 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4918 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4920 /* Resume all threads (of all processes, or of a single
4921 process), with preference for INFERIOR_PTID. This assumes
4922 inferior_ptid belongs to the set of all threads we are about
4924 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4926 /* Step inferior_ptid, with or without signal. */
4927 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4930 /* Also pass down any pending signaled resumption for other
4931 threads not the current. */
4932 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4934 /* And continue others without a signal. */
4935 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4939 /* Scheduler locking; resume only PTID. */
4940 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4943 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4948 /* In non-stop, the stub replies to vCont with "OK". The stop
4949 reply will be reported asynchronously by means of a `%Stop'
4951 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4952 if (strcmp (rs
->buf
, "OK") != 0)
4953 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4959 /* Tell the remote machine to resume. */
4962 remote_resume (struct target_ops
*ops
,
4963 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4965 struct remote_state
*rs
= get_remote_state ();
4968 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4969 (explained in remote-notif.c:handle_notification) so
4970 remote_notif_process is not called. We need find a place where
4971 it is safe to start a 'vNotif' sequence. It is good to do it
4972 before resuming inferior, because inferior was stopped and no RSP
4973 traffic at that moment. */
4975 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
4977 rs
->last_sent_signal
= siggnal
;
4978 rs
->last_sent_step
= step
;
4980 /* The vCont packet doesn't need to specify threads via Hc. */
4981 /* No reverse support (yet) for vCont. */
4982 if (execution_direction
!= EXEC_REVERSE
)
4983 if (remote_vcont_resume (ptid
, step
, siggnal
))
4986 /* All other supported resume packets do use Hc, so set the continue
4988 if (ptid_equal (ptid
, minus_one_ptid
))
4989 set_continue_thread (any_thread_ptid
);
4991 set_continue_thread (ptid
);
4994 if (execution_direction
== EXEC_REVERSE
)
4996 /* We don't pass signals to the target in reverse exec mode. */
4997 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4998 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5001 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5002 error (_("Remote reverse-step not supported."));
5003 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5004 error (_("Remote reverse-continue not supported."));
5006 strcpy (buf
, step
? "bs" : "bc");
5008 else if (siggnal
!= GDB_SIGNAL_0
)
5010 buf
[0] = step
? 'S' : 'C';
5011 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5012 buf
[2] = tohex (((int) siggnal
) & 0xf);
5016 strcpy (buf
, step
? "s" : "c");
5021 /* We are about to start executing the inferior, let's register it
5022 with the event loop. NOTE: this is the one place where all the
5023 execution commands end up. We could alternatively do this in each
5024 of the execution commands in infcmd.c. */
5025 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5026 into infcmd.c in order to allow inferior function calls to work
5027 NOT asynchronously. */
5028 if (target_can_async_p ())
5031 /* We've just told the target to resume. The remote server will
5032 wait for the inferior to stop, and then send a stop reply. In
5033 the mean time, we can't start another command/query ourselves
5034 because the stub wouldn't be ready to process it. This applies
5035 only to the base all-stop protocol, however. In non-stop (which
5036 only supports vCont), the stub replies with an "OK", and is
5037 immediate able to process further serial input. */
5039 rs
->waiting_for_stop_reply
= 1;
5043 /* Set up the signal handler for SIGINT, while the target is
5044 executing, ovewriting the 'regular' SIGINT signal handler. */
5046 async_initialize_sigint_signal_handler (void)
5048 signal (SIGINT
, async_handle_remote_sigint
);
5051 /* Signal handler for SIGINT, while the target is executing. */
5053 async_handle_remote_sigint (int sig
)
5055 signal (sig
, async_handle_remote_sigint_twice
);
5056 /* Note we need to go through gdb_call_async_signal_handler in order
5057 to wake up the event loop on Windows. */
5058 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5061 /* Signal handler for SIGINT, installed after SIGINT has already been
5062 sent once. It will take effect the second time that the user sends
5065 async_handle_remote_sigint_twice (int sig
)
5067 signal (sig
, async_handle_remote_sigint
);
5068 /* See note in async_handle_remote_sigint. */
5069 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5072 /* Perform the real interruption of the target execution, in response
5075 async_remote_interrupt (gdb_client_data arg
)
5078 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5080 target_stop (inferior_ptid
);
5083 /* Perform interrupt, if the first attempt did not succeed. Just give
5084 up on the target alltogether. */
5086 async_remote_interrupt_twice (gdb_client_data arg
)
5089 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5094 /* Reinstall the usual SIGINT handlers, after the target has
5097 async_cleanup_sigint_signal_handler (void *dummy
)
5099 signal (SIGINT
, handle_sigint
);
5102 /* Send ^C to target to halt it. Target will respond, and send us a
5104 static void (*ofunc
) (int);
5106 /* The command line interface's stop routine. This function is installed
5107 as a signal handler for SIGINT. The first time a user requests a
5108 stop, we call remote_stop to send a break or ^C. If there is no
5109 response from the target (it didn't stop when the user requested it),
5110 we ask the user if he'd like to detach from the target. */
5112 sync_remote_interrupt (int signo
)
5114 /* If this doesn't work, try more severe steps. */
5115 signal (signo
, sync_remote_interrupt_twice
);
5117 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5120 /* The user typed ^C twice. */
5123 sync_remote_interrupt_twice (int signo
)
5125 signal (signo
, ofunc
);
5126 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5127 signal (signo
, sync_remote_interrupt
);
5130 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5131 thread, all threads of a remote process, or all threads of all
5135 remote_stop_ns (ptid_t ptid
)
5137 struct remote_state
*rs
= get_remote_state ();
5139 char *endp
= rs
->buf
+ get_remote_packet_size ();
5141 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5142 remote_vcont_probe (rs
);
5144 if (!rs
->supports_vCont
.t
)
5145 error (_("Remote server does not support stopping threads"));
5147 if (ptid_equal (ptid
, minus_one_ptid
)
5148 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5149 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5154 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5156 if (ptid_is_pid (ptid
))
5157 /* All (-1) threads of process. */
5158 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5161 /* Small optimization: if we already have a stop reply for
5162 this thread, no use in telling the stub we want this
5164 if (peek_stop_reply (ptid
))
5170 write_ptid (p
, endp
, nptid
);
5173 /* In non-stop, we get an immediate OK reply. The stop reply will
5174 come in asynchronously by notification. */
5176 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5177 if (strcmp (rs
->buf
, "OK") != 0)
5178 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5181 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5182 remote target. It is undefined which thread of which process
5183 reports the stop. */
5186 remote_stop_as (ptid_t ptid
)
5188 struct remote_state
*rs
= get_remote_state ();
5190 rs
->ctrlc_pending_p
= 1;
5192 /* If the inferior is stopped already, but the core didn't know
5193 about it yet, just ignore the request. The cached wait status
5194 will be collected in remote_wait. */
5195 if (rs
->cached_wait_status
)
5198 /* Send interrupt_sequence to remote target. */
5199 send_interrupt_sequence ();
5202 /* This is the generic stop called via the target vector. When a target
5203 interrupt is requested, either by the command line or the GUI, we
5204 will eventually end up here. */
5207 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5210 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5213 remote_stop_ns (ptid
);
5215 remote_stop_as (ptid
);
5218 /* Ask the user what to do when an interrupt is received. */
5221 interrupt_query (void)
5223 target_terminal_ours ();
5225 if (target_is_async_p ())
5227 signal (SIGINT
, handle_sigint
);
5232 if (query (_("Interrupted while waiting for the program.\n\
5233 Give up (and stop debugging it)? ")))
5235 remote_unpush_target ();
5240 target_terminal_inferior ();
5243 /* Enable/disable target terminal ownership. Most targets can use
5244 terminal groups to control terminal ownership. Remote targets are
5245 different in that explicit transfer of ownership to/from GDB/target
5249 remote_terminal_inferior (struct target_ops
*self
)
5251 if (!target_async_permitted
)
5252 /* Nothing to do. */
5255 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5256 idempotent. The event-loop GDB talking to an asynchronous target
5257 with a synchronous command calls this function from both
5258 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5259 transfer the terminal to the target when it shouldn't this guard
5261 if (!remote_async_terminal_ours_p
)
5263 delete_file_handler (input_fd
);
5264 remote_async_terminal_ours_p
= 0;
5265 async_initialize_sigint_signal_handler ();
5266 /* NOTE: At this point we could also register our selves as the
5267 recipient of all input. Any characters typed could then be
5268 passed on down to the target. */
5272 remote_terminal_ours (struct target_ops
*self
)
5274 if (!target_async_permitted
)
5275 /* Nothing to do. */
5278 /* See FIXME in remote_terminal_inferior. */
5279 if (remote_async_terminal_ours_p
)
5281 async_cleanup_sigint_signal_handler (NULL
);
5282 add_file_handler (input_fd
, stdin_event_handler
, 0);
5283 remote_async_terminal_ours_p
= 1;
5287 remote_console_output (char *msg
)
5291 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5294 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5298 fputs_unfiltered (tb
, gdb_stdtarg
);
5300 gdb_flush (gdb_stdtarg
);
5303 typedef struct cached_reg
5306 gdb_byte data
[MAX_REGISTER_SIZE
];
5309 DEF_VEC_O(cached_reg_t
);
5311 typedef struct stop_reply
5313 struct notif_event base
;
5315 /* The identifier of the thread about this event */
5318 /* The remote state this event is associated with. When the remote
5319 connection, represented by a remote_state object, is closed,
5320 all the associated stop_reply events should be released. */
5321 struct remote_state
*rs
;
5323 struct target_waitstatus ws
;
5325 /* Expedited registers. This makes remote debugging a bit more
5326 efficient for those targets that provide critical registers as
5327 part of their normal status mechanism (as another roundtrip to
5328 fetch them is avoided). */
5329 VEC(cached_reg_t
) *regcache
;
5331 enum target_stop_reason stop_reason
;
5333 CORE_ADDR watch_data_address
;
5338 DECLARE_QUEUE_P (stop_reply_p
);
5339 DEFINE_QUEUE_P (stop_reply_p
);
5340 /* The list of already fetched and acknowledged stop events. This
5341 queue is used for notification Stop, and other notifications
5342 don't need queue for their events, because the notification events
5343 of Stop can't be consumed immediately, so that events should be
5344 queued first, and be consumed by remote_wait_{ns,as} one per
5345 time. Other notifications can consume their events immediately,
5346 so queue is not needed for them. */
5347 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5350 stop_reply_xfree (struct stop_reply
*r
)
5352 notif_event_xfree ((struct notif_event
*) r
);
5356 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5357 struct notif_event
*event
)
5359 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5363 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5364 struct notif_event
*event
)
5366 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5369 putpkt ((char *) self
->ack_command
);
5371 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5372 /* We got an unknown stop reply. */
5373 error (_("Unknown stop reply"));
5375 push_stop_reply (stop_reply
);
5379 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5381 /* We can't get pending events in remote_notif_process for
5382 notification stop, and we have to do this in remote_wait_ns
5383 instead. If we fetch all queued events from stub, remote stub
5384 may exit and we have no chance to process them back in
5386 mark_async_event_handler (remote_async_inferior_event_token
);
5391 stop_reply_dtr (struct notif_event
*event
)
5393 struct stop_reply
*r
= (struct stop_reply
*) event
;
5395 VEC_free (cached_reg_t
, r
->regcache
);
5398 static struct notif_event
*
5399 remote_notif_stop_alloc_reply (void)
5401 struct notif_event
*r
5402 = (struct notif_event
*) XNEW (struct stop_reply
);
5404 r
->dtr
= stop_reply_dtr
;
5409 /* A client of notification Stop. */
5411 struct notif_client notif_client_stop
=
5415 remote_notif_stop_parse
,
5416 remote_notif_stop_ack
,
5417 remote_notif_stop_can_get_pending_events
,
5418 remote_notif_stop_alloc_reply
,
5422 /* A parameter to pass data in and out. */
5424 struct queue_iter_param
5427 struct stop_reply
*output
;
5430 /* Remove stop replies in the queue if its pid is equal to the given
5434 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5435 QUEUE_ITER (stop_reply_p
) *iter
,
5439 struct queue_iter_param
*param
= data
;
5440 struct inferior
*inf
= param
->input
;
5442 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5444 stop_reply_xfree (event
);
5445 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5451 /* Discard all pending stop replies of inferior INF. */
5454 discard_pending_stop_replies (struct inferior
*inf
)
5457 struct queue_iter_param param
;
5458 struct stop_reply
*reply
;
5459 struct remote_state
*rs
= get_remote_state ();
5460 struct remote_notif_state
*rns
= rs
->notif_state
;
5462 /* This function can be notified when an inferior exists. When the
5463 target is not remote, the notification state is NULL. */
5464 if (rs
->remote_desc
== NULL
)
5467 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5469 /* Discard the in-flight notification. */
5470 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5472 stop_reply_xfree (reply
);
5473 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5477 param
.output
= NULL
;
5478 /* Discard the stop replies we have already pulled with
5480 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5481 remove_stop_reply_for_inferior
, ¶m
);
5484 /* If its remote state is equal to the given remote state,
5485 remove EVENT from the stop reply queue. */
5488 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5489 QUEUE_ITER (stop_reply_p
) *iter
,
5493 struct queue_iter_param
*param
= data
;
5494 struct remote_state
*rs
= param
->input
;
5496 if (event
->rs
== rs
)
5498 stop_reply_xfree (event
);
5499 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5505 /* Discard the stop replies for RS in stop_reply_queue. */
5508 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5510 struct queue_iter_param param
;
5513 param
.output
= NULL
;
5514 /* Discard the stop replies we have already pulled with
5516 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5517 remove_stop_reply_of_remote_state
, ¶m
);
5520 /* A parameter to pass data in and out. */
5523 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5524 QUEUE_ITER (stop_reply_p
) *iter
,
5528 struct queue_iter_param
*param
= data
;
5529 ptid_t
*ptid
= param
->input
;
5531 if (ptid_match (event
->ptid
, *ptid
))
5533 param
->output
= event
;
5534 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5541 /* Remove the first reply in 'stop_reply_queue' which matches
5544 static struct stop_reply
*
5545 remote_notif_remove_queued_reply (ptid_t ptid
)
5547 struct queue_iter_param param
;
5549 param
.input
= &ptid
;
5550 param
.output
= NULL
;
5552 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5553 remote_notif_remove_once_on_match
, ¶m
);
5555 fprintf_unfiltered (gdb_stdlog
,
5556 "notif: discard queued event: 'Stop' in %s\n",
5557 target_pid_to_str (ptid
));
5559 return param
.output
;
5562 /* Look for a queued stop reply belonging to PTID. If one is found,
5563 remove it from the queue, and return it. Returns NULL if none is
5564 found. If there are still queued events left to process, tell the
5565 event loop to get back to target_wait soon. */
5567 static struct stop_reply
*
5568 queued_stop_reply (ptid_t ptid
)
5570 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5572 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5573 /* There's still at least an event left. */
5574 mark_async_event_handler (remote_async_inferior_event_token
);
5579 /* Push a fully parsed stop reply in the stop reply queue. Since we
5580 know that we now have at least one queued event left to pass to the
5581 core side, tell the event loop to get back to target_wait soon. */
5584 push_stop_reply (struct stop_reply
*new_event
)
5586 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5589 fprintf_unfiltered (gdb_stdlog
,
5590 "notif: push 'Stop' %s to queue %d\n",
5591 target_pid_to_str (new_event
->ptid
),
5592 QUEUE_length (stop_reply_p
,
5595 mark_async_event_handler (remote_async_inferior_event_token
);
5599 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5600 QUEUE_ITER (stop_reply_p
) *iter
,
5601 struct stop_reply
*event
,
5604 ptid_t
*ptid
= data
;
5606 return !(ptid_equal (*ptid
, event
->ptid
)
5607 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5610 /* Returns true if we have a stop reply for PTID. */
5613 peek_stop_reply (ptid_t ptid
)
5615 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5616 stop_reply_match_ptid_and_ws
, &ptid
);
5619 /* Skip PACKET until the next semi-colon (or end of string). */
5622 skip_to_semicolon (char *p
)
5624 while (*p
!= '\0' && *p
!= ';')
5629 /* Parse the stop reply in BUF. Either the function succeeds, and the
5630 result is stored in EVENT, or throws an error. */
5633 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5635 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5639 event
->ptid
= null_ptid
;
5640 event
->rs
= get_remote_state ();
5641 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5642 event
->ws
.value
.integer
= 0;
5643 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5644 event
->regcache
= NULL
;
5649 case 'T': /* Status with PC, SP, FP, ... */
5650 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5651 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5653 n... = register number
5654 r... = register contents
5657 p
= &buf
[3]; /* after Txx */
5663 p1
= strchr (p
, ':');
5665 error (_("Malformed packet(a) (missing colon): %s\n\
5669 error (_("Malformed packet(a) (missing register number): %s\n\
5673 /* Some "registers" are actually extended stop information.
5674 Note if you're adding a new entry here: GDB 7.9 and
5675 earlier assume that all register "numbers" that start
5676 with an hex digit are real register numbers. Make sure
5677 the server only sends such a packet if it knows the
5678 client understands it. */
5680 if (strncmp (p
, "thread", p1
- p
) == 0)
5681 event
->ptid
= read_ptid (++p1
, &p
);
5682 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5683 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5684 || (strncmp (p
, "awatch", p1
- p
) == 0))
5686 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
5687 p
= unpack_varlen_hex (++p1
, &addr
);
5688 event
->watch_data_address
= (CORE_ADDR
) addr
;
5690 else if (strncmp (p
, "swbreak", p1
- p
) == 0)
5692 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
5694 /* Make sure the stub doesn't forget to indicate support
5696 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
5697 error (_("Unexpected swbreak stop reason"));
5699 /* The value part is documented as "must be empty",
5700 though we ignore it, in case we ever decide to make
5701 use of it in a backward compatible way. */
5702 p
= skip_to_semicolon (p1
+ 1);
5704 else if (strncmp (p
, "hwbreak", p1
- p
) == 0)
5706 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
5708 /* Make sure the stub doesn't forget to indicate support
5710 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
5711 error (_("Unexpected hwbreak stop reason"));
5714 p
= skip_to_semicolon (p1
+ 1);
5716 else if (strncmp (p
, "library", p1
- p
) == 0)
5718 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5719 p
= skip_to_semicolon (p1
+ 1);
5721 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5723 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5724 /* p1 will indicate "begin" or "end", but it makes
5725 no difference for now, so ignore it. */
5726 p
= skip_to_semicolon (p1
+ 1);
5728 else if (strncmp (p
, "core", p1
- p
) == 0)
5732 p
= unpack_varlen_hex (++p1
, &c
);
5735 else if (strncmp (p
, "fork", p1
- p
) == 0)
5737 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5738 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
5740 else if (strncmp (p
, "vfork", p1
- p
) == 0)
5742 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5743 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
5745 else if (strncmp (p
, "vforkdone", p1
- p
) == 0)
5747 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
5748 p
= skip_to_semicolon (p1
+ 1);
5755 /* Maybe a real ``P'' register number. */
5756 p_temp
= unpack_varlen_hex (p
, &pnum
);
5757 /* If the first invalid character is the colon, we got a
5758 register number. Otherwise, it's an unknown stop
5762 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5763 cached_reg_t cached_reg
;
5766 error (_("Remote sent bad register number %s: %s\n\
5768 hex_string (pnum
), p
, buf
);
5770 cached_reg
.num
= reg
->regnum
;
5773 fieldsize
= hex2bin (p
, cached_reg
.data
,
5774 register_size (target_gdbarch (),
5777 if (fieldsize
< register_size (target_gdbarch (),
5779 warning (_("Remote reply is too short: %s"), buf
);
5781 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5785 /* Not a number. Silently skip unknown optional
5787 p
= skip_to_semicolon (p1
+ 1);
5792 error (_("Remote register badly formatted: %s\nhere: %s"),
5797 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5801 case 'S': /* Old style status, just signal only. */
5805 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5806 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5807 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5808 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5810 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5813 case 'W': /* Target exited. */
5820 /* GDB used to accept only 2 hex chars here. Stubs should
5821 only send more if they detect GDB supports multi-process
5823 p
= unpack_varlen_hex (&buf
[1], &value
);
5827 /* The remote process exited. */
5828 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5829 event
->ws
.value
.integer
= value
;
5833 /* The remote process exited with a signal. */
5834 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5835 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
5836 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5838 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5841 /* If no process is specified, assume inferior_ptid. */
5842 pid
= ptid_get_pid (inferior_ptid
);
5851 else if (startswith (p
, "process:"))
5855 p
+= sizeof ("process:") - 1;
5856 unpack_varlen_hex (p
, &upid
);
5860 error (_("unknown stop reply packet: %s"), buf
);
5863 error (_("unknown stop reply packet: %s"), buf
);
5864 event
->ptid
= pid_to_ptid (pid
);
5869 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5870 error (_("No process or thread specified in stop reply: %s"), buf
);
5873 /* When the stub wants to tell GDB about a new notification reply, it
5874 sends a notification (%Stop, for example). Those can come it at
5875 any time, hence, we have to make sure that any pending
5876 putpkt/getpkt sequence we're making is finished, before querying
5877 the stub for more events with the corresponding ack command
5878 (vStopped, for example). E.g., if we started a vStopped sequence
5879 immediately upon receiving the notification, something like this
5887 1.6) <-- (registers reply to step #1.3)
5889 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5892 To solve this, whenever we parse a %Stop notification successfully,
5893 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5894 doing whatever we were doing:
5900 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5901 2.5) <-- (registers reply to step #2.3)
5903 Eventualy after step #2.5, we return to the event loop, which
5904 notices there's an event on the
5905 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5906 associated callback --- the function below. At this point, we're
5907 always safe to start a vStopped sequence. :
5910 2.7) <-- T05 thread:2
5916 remote_notif_get_pending_events (struct notif_client
*nc
)
5918 struct remote_state
*rs
= get_remote_state ();
5920 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
5923 fprintf_unfiltered (gdb_stdlog
,
5924 "notif: process: '%s' ack pending event\n",
5928 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
5929 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
5933 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5934 if (strcmp (rs
->buf
, "OK") == 0)
5937 remote_notif_ack (nc
, rs
->buf
);
5943 fprintf_unfiltered (gdb_stdlog
,
5944 "notif: process: '%s' no pending reply\n",
5949 /* Called when it is decided that STOP_REPLY holds the info of the
5950 event that is to be returned to the core. This function always
5951 destroys STOP_REPLY. */
5954 process_stop_reply (struct stop_reply
*stop_reply
,
5955 struct target_waitstatus
*status
)
5959 *status
= stop_reply
->ws
;
5960 ptid
= stop_reply
->ptid
;
5962 /* If no thread/process was reported by the stub, assume the current
5964 if (ptid_equal (ptid
, null_ptid
))
5965 ptid
= inferior_ptid
;
5967 if (status
->kind
!= TARGET_WAITKIND_EXITED
5968 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5970 struct remote_state
*rs
= get_remote_state ();
5972 /* Expedited registers. */
5973 if (stop_reply
->regcache
)
5975 struct regcache
*regcache
5976 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5981 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5983 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5984 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5987 rs
->stop_reason
= stop_reply
->stop_reason
;
5988 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
5990 remote_notice_new_inferior (ptid
, 0);
5991 demand_private_info (ptid
)->core
= stop_reply
->core
;
5994 stop_reply_xfree (stop_reply
);
5998 /* The non-stop mode version of target_wait. */
6001 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6003 struct remote_state
*rs
= get_remote_state ();
6004 struct stop_reply
*stop_reply
;
6008 /* If in non-stop mode, get out of getpkt even if a
6009 notification is received. */
6011 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6012 0 /* forever */, &is_notif
);
6015 if (ret
!= -1 && !is_notif
)
6018 case 'E': /* Error of some sort. */
6019 /* We're out of sync with the target now. Did it continue
6020 or not? We can't tell which thread it was in non-stop,
6021 so just ignore this. */
6022 warning (_("Remote failure reply: %s"), rs
->buf
);
6024 case 'O': /* Console output. */
6025 remote_console_output (rs
->buf
+ 1);
6028 warning (_("Invalid remote reply: %s"), rs
->buf
);
6032 /* Acknowledge a pending stop reply that may have arrived in the
6034 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6035 remote_notif_get_pending_events (¬if_client_stop
);
6037 /* If indeed we noticed a stop reply, we're done. */
6038 stop_reply
= queued_stop_reply (ptid
);
6039 if (stop_reply
!= NULL
)
6040 return process_stop_reply (stop_reply
, status
);
6042 /* Still no event. If we're just polling for an event, then
6043 return to the event loop. */
6044 if (options
& TARGET_WNOHANG
)
6046 status
->kind
= TARGET_WAITKIND_IGNORE
;
6047 return minus_one_ptid
;
6050 /* Otherwise do a blocking wait. */
6051 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6052 1 /* forever */, &is_notif
);
6056 /* Wait until the remote machine stops, then return, storing status in
6057 STATUS just as `wait' would. */
6060 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6062 struct remote_state
*rs
= get_remote_state ();
6063 ptid_t event_ptid
= null_ptid
;
6065 struct stop_reply
*stop_reply
;
6069 status
->kind
= TARGET_WAITKIND_IGNORE
;
6070 status
->value
.integer
= 0;
6072 stop_reply
= queued_stop_reply (ptid
);
6073 if (stop_reply
!= NULL
)
6074 return process_stop_reply (stop_reply
, status
);
6076 if (rs
->cached_wait_status
)
6077 /* Use the cached wait status, but only once. */
6078 rs
->cached_wait_status
= 0;
6084 if (!target_is_async_p ())
6086 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6087 /* If the user hit C-c before this packet, or between packets,
6088 pretend that it was hit right here. */
6089 if (check_quit_flag ())
6092 sync_remote_interrupt (SIGINT
);
6096 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6097 _never_ wait for ever -> test on target_is_async_p().
6098 However, before we do that we need to ensure that the caller
6099 knows how to take the target into/out of async mode. */
6100 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6101 wait_forever_enabled_p
, &is_notif
);
6103 if (!target_is_async_p ())
6104 signal (SIGINT
, ofunc
);
6106 /* GDB gets a notification. Return to core as this event is
6108 if (ret
!= -1 && is_notif
)
6109 return minus_one_ptid
;
6114 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6116 /* We got something. */
6117 rs
->waiting_for_stop_reply
= 0;
6119 /* Assume that the target has acknowledged Ctrl-C unless we receive
6120 an 'F' or 'O' packet. */
6121 if (buf
[0] != 'F' && buf
[0] != 'O')
6122 rs
->ctrlc_pending_p
= 0;
6126 case 'E': /* Error of some sort. */
6127 /* We're out of sync with the target now. Did it continue or
6128 not? Not is more likely, so report a stop. */
6129 warning (_("Remote failure reply: %s"), buf
);
6130 status
->kind
= TARGET_WAITKIND_STOPPED
;
6131 status
->value
.sig
= GDB_SIGNAL_0
;
6133 case 'F': /* File-I/O request. */
6134 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6135 rs
->ctrlc_pending_p
= 0;
6137 case 'T': case 'S': case 'X': case 'W':
6139 struct stop_reply
*stop_reply
6140 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6143 event_ptid
= process_stop_reply (stop_reply
, status
);
6146 case 'O': /* Console output. */
6147 remote_console_output (buf
+ 1);
6149 /* The target didn't really stop; keep waiting. */
6150 rs
->waiting_for_stop_reply
= 1;
6154 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6156 /* Zero length reply means that we tried 'S' or 'C' and the
6157 remote system doesn't support it. */
6158 target_terminal_ours_for_output ();
6160 ("Can't send signals to this remote system. %s not sent.\n",
6161 gdb_signal_to_name (rs
->last_sent_signal
));
6162 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6163 target_terminal_inferior ();
6165 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6166 putpkt ((char *) buf
);
6168 /* We just told the target to resume, so a stop reply is in
6170 rs
->waiting_for_stop_reply
= 1;
6173 /* else fallthrough */
6175 warning (_("Invalid remote reply: %s"), buf
);
6177 rs
->waiting_for_stop_reply
= 1;
6181 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6183 /* Nothing interesting happened. If we're doing a non-blocking
6184 poll, we're done. Otherwise, go back to waiting. */
6185 if (options
& TARGET_WNOHANG
)
6186 return minus_one_ptid
;
6190 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6191 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6193 if (!ptid_equal (event_ptid
, null_ptid
))
6194 record_currthread (rs
, event_ptid
);
6196 event_ptid
= inferior_ptid
;
6199 /* A process exit. Invalidate our notion of current thread. */
6200 record_currthread (rs
, minus_one_ptid
);
6205 /* Wait until the remote machine stops, then return, storing status in
6206 STATUS just as `wait' would. */
6209 remote_wait (struct target_ops
*ops
,
6210 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6215 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6217 event_ptid
= remote_wait_as (ptid
, status
, options
);
6219 if (target_is_async_p ())
6221 /* If there are are events left in the queue tell the event loop
6223 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6224 mark_async_event_handler (remote_async_inferior_event_token
);
6230 /* Fetch a single register using a 'p' packet. */
6233 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6235 struct remote_state
*rs
= get_remote_state ();
6237 char regp
[MAX_REGISTER_SIZE
];
6240 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6243 if (reg
->pnum
== -1)
6248 p
+= hexnumstr (p
, reg
->pnum
);
6251 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6255 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6259 case PACKET_UNKNOWN
:
6262 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6263 gdbarch_register_name (get_regcache_arch (regcache
),
6268 /* If this register is unfetchable, tell the regcache. */
6271 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6275 /* Otherwise, parse and supply the value. */
6281 error (_("fetch_register_using_p: early buf termination"));
6283 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6286 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6290 /* Fetch the registers included in the target's 'g' packet. */
6293 send_g_packet (void)
6295 struct remote_state
*rs
= get_remote_state ();
6298 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6299 remote_send (&rs
->buf
, &rs
->buf_size
);
6301 /* We can get out of synch in various cases. If the first character
6302 in the buffer is not a hex character, assume that has happened
6303 and try to fetch another packet to read. */
6304 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6305 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6306 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6307 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6310 fprintf_unfiltered (gdb_stdlog
,
6311 "Bad register packet; fetching a new packet\n");
6312 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6315 buf_len
= strlen (rs
->buf
);
6317 /* Sanity check the received packet. */
6318 if (buf_len
% 2 != 0)
6319 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6325 process_g_packet (struct regcache
*regcache
)
6327 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6328 struct remote_state
*rs
= get_remote_state ();
6329 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6334 buf_len
= strlen (rs
->buf
);
6336 /* Further sanity checks, with knowledge of the architecture. */
6337 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6338 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6340 /* Save the size of the packet sent to us by the target. It is used
6341 as a heuristic when determining the max size of packets that the
6342 target can safely receive. */
6343 if (rsa
->actual_register_packet_size
== 0)
6344 rsa
->actual_register_packet_size
= buf_len
;
6346 /* If this is smaller than we guessed the 'g' packet would be,
6347 update our records. A 'g' reply that doesn't include a register's
6348 value implies either that the register is not available, or that
6349 the 'p' packet must be used. */
6350 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6352 rsa
->sizeof_g_packet
= buf_len
/ 2;
6354 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6356 if (rsa
->regs
[i
].pnum
== -1)
6359 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6360 rsa
->regs
[i
].in_g_packet
= 0;
6362 rsa
->regs
[i
].in_g_packet
= 1;
6366 regs
= alloca (rsa
->sizeof_g_packet
);
6368 /* Unimplemented registers read as all bits zero. */
6369 memset (regs
, 0, rsa
->sizeof_g_packet
);
6371 /* Reply describes registers byte by byte, each byte encoded as two
6372 hex characters. Suck them all up, then supply them to the
6373 register cacheing/storage mechanism. */
6376 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6378 if (p
[0] == 0 || p
[1] == 0)
6379 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6380 internal_error (__FILE__
, __LINE__
,
6381 _("unexpected end of 'g' packet reply"));
6383 if (p
[0] == 'x' && p
[1] == 'x')
6384 regs
[i
] = 0; /* 'x' */
6386 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6390 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6392 struct packet_reg
*r
= &rsa
->regs
[i
];
6396 if (r
->offset
* 2 >= strlen (rs
->buf
))
6397 /* This shouldn't happen - we adjusted in_g_packet above. */
6398 internal_error (__FILE__
, __LINE__
,
6399 _("unexpected end of 'g' packet reply"));
6400 else if (rs
->buf
[r
->offset
* 2] == 'x')
6402 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6403 /* The register isn't available, mark it as such (at
6404 the same time setting the value to zero). */
6405 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6408 regcache_raw_supply (regcache
, r
->regnum
,
6415 fetch_registers_using_g (struct regcache
*regcache
)
6418 process_g_packet (regcache
);
6421 /* Make the remote selected traceframe match GDB's selected
6425 set_remote_traceframe (void)
6428 struct remote_state
*rs
= get_remote_state ();
6430 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6433 /* Avoid recursion, remote_trace_find calls us again. */
6434 rs
->remote_traceframe_number
= get_traceframe_number ();
6436 newnum
= target_trace_find (tfind_number
,
6437 get_traceframe_number (), 0, 0, NULL
);
6439 /* Should not happen. If it does, all bets are off. */
6440 if (newnum
!= get_traceframe_number ())
6441 warning (_("could not set remote traceframe"));
6445 remote_fetch_registers (struct target_ops
*ops
,
6446 struct regcache
*regcache
, int regnum
)
6448 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6451 set_remote_traceframe ();
6452 set_general_thread (inferior_ptid
);
6456 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6458 gdb_assert (reg
!= NULL
);
6460 /* If this register might be in the 'g' packet, try that first -
6461 we are likely to read more than one register. If this is the
6462 first 'g' packet, we might be overly optimistic about its
6463 contents, so fall back to 'p'. */
6464 if (reg
->in_g_packet
)
6466 fetch_registers_using_g (regcache
);
6467 if (reg
->in_g_packet
)
6471 if (fetch_register_using_p (regcache
, reg
))
6474 /* This register is not available. */
6475 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6480 fetch_registers_using_g (regcache
);
6482 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6483 if (!rsa
->regs
[i
].in_g_packet
)
6484 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6486 /* This register is not available. */
6487 regcache_raw_supply (regcache
, i
, NULL
);
6491 /* Prepare to store registers. Since we may send them all (using a
6492 'G' request), we have to read out the ones we don't want to change
6496 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6498 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6500 gdb_byte buf
[MAX_REGISTER_SIZE
];
6502 /* Make sure the entire registers array is valid. */
6503 switch (packet_support (PACKET_P
))
6505 case PACKET_DISABLE
:
6506 case PACKET_SUPPORT_UNKNOWN
:
6507 /* Make sure all the necessary registers are cached. */
6508 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6509 if (rsa
->regs
[i
].in_g_packet
)
6510 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6517 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6518 packet was not recognized. */
6521 store_register_using_P (const struct regcache
*regcache
,
6522 struct packet_reg
*reg
)
6524 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6525 struct remote_state
*rs
= get_remote_state ();
6526 /* Try storing a single register. */
6527 char *buf
= rs
->buf
;
6528 gdb_byte regp
[MAX_REGISTER_SIZE
];
6531 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6534 if (reg
->pnum
== -1)
6537 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6538 p
= buf
+ strlen (buf
);
6539 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6540 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6542 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6544 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6549 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6550 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6551 case PACKET_UNKNOWN
:
6554 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6558 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6559 contents of the register cache buffer. FIXME: ignores errors. */
6562 store_registers_using_G (const struct regcache
*regcache
)
6564 struct remote_state
*rs
= get_remote_state ();
6565 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6569 /* Extract all the registers in the regcache copying them into a
6574 regs
= alloca (rsa
->sizeof_g_packet
);
6575 memset (regs
, 0, rsa
->sizeof_g_packet
);
6576 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6578 struct packet_reg
*r
= &rsa
->regs
[i
];
6581 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6585 /* Command describes registers byte by byte,
6586 each byte encoded as two hex characters. */
6589 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6591 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6593 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6594 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6595 error (_("Could not write registers; remote failure reply '%s'"),
6599 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6600 of the register cache buffer. FIXME: ignores errors. */
6603 remote_store_registers (struct target_ops
*ops
,
6604 struct regcache
*regcache
, int regnum
)
6606 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6609 set_remote_traceframe ();
6610 set_general_thread (inferior_ptid
);
6614 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6616 gdb_assert (reg
!= NULL
);
6618 /* Always prefer to store registers using the 'P' packet if
6619 possible; we often change only a small number of registers.
6620 Sometimes we change a larger number; we'd need help from a
6621 higher layer to know to use 'G'. */
6622 if (store_register_using_P (regcache
, reg
))
6625 /* For now, don't complain if we have no way to write the
6626 register. GDB loses track of unavailable registers too
6627 easily. Some day, this may be an error. We don't have
6628 any way to read the register, either... */
6629 if (!reg
->in_g_packet
)
6632 store_registers_using_G (regcache
);
6636 store_registers_using_G (regcache
);
6638 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6639 if (!rsa
->regs
[i
].in_g_packet
)
6640 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6641 /* See above for why we do not issue an error here. */
6646 /* Return the number of hex digits in num. */
6649 hexnumlen (ULONGEST num
)
6653 for (i
= 0; num
!= 0; i
++)
6659 /* Set BUF to the minimum number of hex digits representing NUM. */
6662 hexnumstr (char *buf
, ULONGEST num
)
6664 int len
= hexnumlen (num
);
6666 return hexnumnstr (buf
, num
, len
);
6670 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6673 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6679 for (i
= width
- 1; i
>= 0; i
--)
6681 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6688 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6691 remote_address_masked (CORE_ADDR addr
)
6693 unsigned int address_size
= remote_address_size
;
6695 /* If "remoteaddresssize" was not set, default to target address size. */
6697 address_size
= gdbarch_addr_bit (target_gdbarch ());
6699 if (address_size
> 0
6700 && address_size
< (sizeof (ULONGEST
) * 8))
6702 /* Only create a mask when that mask can safely be constructed
6703 in a ULONGEST variable. */
6706 mask
= (mask
<< address_size
) - 1;
6712 /* Determine whether the remote target supports binary downloading.
6713 This is accomplished by sending a no-op memory write of zero length
6714 to the target at the specified address. It does not suffice to send
6715 the whole packet, since many stubs strip the eighth bit and
6716 subsequently compute a wrong checksum, which causes real havoc with
6719 NOTE: This can still lose if the serial line is not eight-bit
6720 clean. In cases like this, the user should clear "remote
6724 check_binary_download (CORE_ADDR addr
)
6726 struct remote_state
*rs
= get_remote_state ();
6728 switch (packet_support (PACKET_X
))
6730 case PACKET_DISABLE
:
6734 case PACKET_SUPPORT_UNKNOWN
:
6740 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6742 p
+= hexnumstr (p
, (ULONGEST
) 0);
6746 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6747 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6749 if (rs
->buf
[0] == '\0')
6752 fprintf_unfiltered (gdb_stdlog
,
6753 "binary downloading NOT "
6754 "supported by target\n");
6755 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6760 fprintf_unfiltered (gdb_stdlog
,
6761 "binary downloading supported by target\n");
6762 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6769 /* Write memory data directly to the remote machine.
6770 This does not inform the data cache; the data cache uses this.
6771 HEADER is the starting part of the packet.
6772 MEMADDR is the address in the remote memory space.
6773 MYADDR is the address of the buffer in our space.
6774 LEN is the number of bytes.
6775 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6776 should send data as binary ('X'), or hex-encoded ('M').
6778 The function creates packet of the form
6779 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6781 where encoding of <DATA> is termined by PACKET_FORMAT.
6783 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6786 Return the transferred status, error or OK (an
6787 'enum target_xfer_status' value). Save the number of bytes
6788 transferred in *XFERED_LEN. Only transfer a single packet. */
6790 static enum target_xfer_status
6791 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6792 const gdb_byte
*myaddr
, ULONGEST len
,
6793 ULONGEST
*xfered_len
, char packet_format
,
6796 struct remote_state
*rs
= get_remote_state ();
6806 if (packet_format
!= 'X' && packet_format
!= 'M')
6807 internal_error (__FILE__
, __LINE__
,
6808 _("remote_write_bytes_aux: bad packet format"));
6811 return TARGET_XFER_EOF
;
6813 payload_size
= get_memory_write_packet_size ();
6815 /* The packet buffer will be large enough for the payload;
6816 get_memory_packet_size ensures this. */
6819 /* Compute the size of the actual payload by subtracting out the
6820 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6822 payload_size
-= strlen ("$,:#NN");
6824 /* The comma won't be used. */
6826 header_length
= strlen (header
);
6827 payload_size
-= header_length
;
6828 payload_size
-= hexnumlen (memaddr
);
6830 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6832 strcat (rs
->buf
, header
);
6833 p
= rs
->buf
+ strlen (header
);
6835 /* Compute a best guess of the number of bytes actually transfered. */
6836 if (packet_format
== 'X')
6838 /* Best guess at number of bytes that will fit. */
6839 todo
= min (len
, payload_size
);
6841 payload_size
-= hexnumlen (todo
);
6842 todo
= min (todo
, payload_size
);
6846 /* Num bytes that will fit. */
6847 todo
= min (len
, payload_size
/ 2);
6849 payload_size
-= hexnumlen (todo
);
6850 todo
= min (todo
, payload_size
/ 2);
6854 internal_error (__FILE__
, __LINE__
,
6855 _("minimum packet size too small to write data"));
6857 /* If we already need another packet, then try to align the end
6858 of this packet to a useful boundary. */
6859 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6860 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6862 /* Append "<memaddr>". */
6863 memaddr
= remote_address_masked (memaddr
);
6864 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6871 /* Append <len>. Retain the location/size of <len>. It may need to
6872 be adjusted once the packet body has been created. */
6874 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6882 /* Append the packet body. */
6883 if (packet_format
== 'X')
6885 /* Binary mode. Send target system values byte by byte, in
6886 increasing byte addresses. Only escape certain critical
6888 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6889 &nr_bytes
, payload_size
);
6891 /* If not all TODO bytes fit, then we'll need another packet. Make
6892 a second try to keep the end of the packet aligned. Don't do
6893 this if the packet is tiny. */
6894 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6898 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6900 if (new_nr_bytes
!= nr_bytes
)
6901 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6902 (gdb_byte
*) p
, &nr_bytes
,
6906 p
+= payload_length
;
6907 if (use_length
&& nr_bytes
< todo
)
6909 /* Escape chars have filled up the buffer prematurely,
6910 and we have actually sent fewer bytes than planned.
6911 Fix-up the length field of the packet. Use the same
6912 number of characters as before. */
6913 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6914 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6919 /* Normal mode: Send target system values byte by byte, in
6920 increasing byte addresses. Each byte is encoded as a two hex
6922 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6926 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6927 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6929 if (rs
->buf
[0] == 'E')
6930 return TARGET_XFER_E_IO
;
6932 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6933 fewer bytes than we'd planned. */
6934 *xfered_len
= (ULONGEST
) nr_bytes
;
6935 return TARGET_XFER_OK
;
6938 /* Write memory data directly to the remote machine.
6939 This does not inform the data cache; the data cache uses this.
6940 MEMADDR is the address in the remote memory space.
6941 MYADDR is the address of the buffer in our space.
6942 LEN is the number of bytes.
6944 Return the transferred status, error or OK (an
6945 'enum target_xfer_status' value). Save the number of bytes
6946 transferred in *XFERED_LEN. Only transfer a single packet. */
6948 static enum target_xfer_status
6949 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
6950 ULONGEST
*xfered_len
)
6952 char *packet_format
= 0;
6954 /* Check whether the target supports binary download. */
6955 check_binary_download (memaddr
);
6957 switch (packet_support (PACKET_X
))
6960 packet_format
= "X";
6962 case PACKET_DISABLE
:
6963 packet_format
= "M";
6965 case PACKET_SUPPORT_UNKNOWN
:
6966 internal_error (__FILE__
, __LINE__
,
6967 _("remote_write_bytes: bad internal state"));
6969 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6972 return remote_write_bytes_aux (packet_format
,
6973 memaddr
, myaddr
, len
, xfered_len
,
6974 packet_format
[0], 1);
6977 /* Read memory data directly from the remote machine.
6978 This does not use the data cache; the data cache uses this.
6979 MEMADDR is the address in the remote memory space.
6980 MYADDR is the address of the buffer in our space.
6981 LEN is the number of bytes.
6983 Return the transferred status, error or OK (an
6984 'enum target_xfer_status' value). Save the number of bytes
6985 transferred in *XFERED_LEN. */
6987 static enum target_xfer_status
6988 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len
,
6989 ULONGEST
*xfered_len
)
6991 struct remote_state
*rs
= get_remote_state ();
6992 int max_buf_size
; /* Max size of packet output buffer. */
6997 max_buf_size
= get_memory_read_packet_size ();
6998 /* The packet buffer will be large enough for the payload;
6999 get_memory_packet_size ensures this. */
7001 /* Number if bytes that will fit. */
7002 todo
= min (len
, max_buf_size
/ 2);
7004 /* Construct "m"<memaddr>","<len>". */
7005 memaddr
= remote_address_masked (memaddr
);
7008 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7010 p
+= hexnumstr (p
, (ULONGEST
) todo
);
7013 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7014 if (rs
->buf
[0] == 'E'
7015 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7016 && rs
->buf
[3] == '\0')
7017 return TARGET_XFER_E_IO
;
7018 /* Reply describes memory byte by byte, each byte encoded as two hex
7021 i
= hex2bin (p
, myaddr
, todo
);
7022 /* Return what we have. Let higher layers handle partial reads. */
7023 *xfered_len
= (ULONGEST
) i
;
7024 return TARGET_XFER_OK
;
7027 /* Using the set of read-only target sections of remote, read live
7030 For interface/parameters/return description see target.h,
7033 static enum target_xfer_status
7034 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7035 ULONGEST memaddr
, ULONGEST len
,
7036 ULONGEST
*xfered_len
)
7038 struct target_section
*secp
;
7039 struct target_section_table
*table
;
7041 secp
= target_section_by_addr (ops
, memaddr
);
7043 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7044 secp
->the_bfd_section
)
7047 struct target_section
*p
;
7048 ULONGEST memend
= memaddr
+ len
;
7050 table
= target_get_section_table (ops
);
7052 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7054 if (memaddr
>= p
->addr
)
7056 if (memend
<= p
->endaddr
)
7058 /* Entire transfer is within this section. */
7059 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
7062 else if (memaddr
>= p
->endaddr
)
7064 /* This section ends before the transfer starts. */
7069 /* This section overlaps the transfer. Just do half. */
7070 len
= p
->endaddr
- memaddr
;
7071 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
7078 return TARGET_XFER_EOF
;
7081 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7082 first if the requested memory is unavailable in traceframe.
7083 Otherwise, fall back to remote_read_bytes_1. */
7085 static enum target_xfer_status
7086 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7087 gdb_byte
*myaddr
, ULONGEST len
, ULONGEST
*xfered_len
)
7090 return TARGET_XFER_EOF
;
7092 if (get_traceframe_number () != -1)
7094 VEC(mem_range_s
) *available
;
7096 /* If we fail to get the set of available memory, then the
7097 target does not support querying traceframe info, and so we
7098 attempt reading from the traceframe anyway (assuming the
7099 target implements the old QTro packet then). */
7100 if (traceframe_available_memory (&available
, memaddr
, len
))
7102 struct cleanup
*old_chain
;
7104 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7106 if (VEC_empty (mem_range_s
, available
)
7107 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7109 enum target_xfer_status res
;
7111 /* Don't read into the traceframe's available
7113 if (!VEC_empty (mem_range_s
, available
))
7115 LONGEST oldlen
= len
;
7117 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7118 gdb_assert (len
<= oldlen
);
7121 do_cleanups (old_chain
);
7123 /* This goes through the topmost target again. */
7124 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7126 if (res
== TARGET_XFER_OK
)
7127 return TARGET_XFER_OK
;
7130 /* No use trying further, we know some memory starting
7131 at MEMADDR isn't available. */
7133 return TARGET_XFER_UNAVAILABLE
;
7137 /* Don't try to read more than how much is available, in
7138 case the target implements the deprecated QTro packet to
7139 cater for older GDBs (the target's knowledge of read-only
7140 sections may be outdated by now). */
7141 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7143 do_cleanups (old_chain
);
7147 return remote_read_bytes_1 (memaddr
, myaddr
, len
, xfered_len
);
7152 /* Sends a packet with content determined by the printf format string
7153 FORMAT and the remaining arguments, then gets the reply. Returns
7154 whether the packet was a success, a failure, or unknown. */
7156 static enum packet_result
remote_send_printf (const char *format
, ...)
7157 ATTRIBUTE_PRINTF (1, 2);
7159 static enum packet_result
7160 remote_send_printf (const char *format
, ...)
7162 struct remote_state
*rs
= get_remote_state ();
7163 int max_size
= get_remote_packet_size ();
7166 va_start (ap
, format
);
7169 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7170 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7172 if (putpkt (rs
->buf
) < 0)
7173 error (_("Communication problem with target."));
7176 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7178 return packet_check_result (rs
->buf
);
7182 restore_remote_timeout (void *p
)
7184 int value
= *(int *)p
;
7186 remote_timeout
= value
;
7189 /* Flash writing can take quite some time. We'll set
7190 effectively infinite timeout for flash operations.
7191 In future, we'll need to decide on a better approach. */
7192 static const int remote_flash_timeout
= 1000;
7195 remote_flash_erase (struct target_ops
*ops
,
7196 ULONGEST address
, LONGEST length
)
7198 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7199 int saved_remote_timeout
= remote_timeout
;
7200 enum packet_result ret
;
7201 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7202 &saved_remote_timeout
);
7204 remote_timeout
= remote_flash_timeout
;
7206 ret
= remote_send_printf ("vFlashErase:%s,%s",
7207 phex (address
, addr_size
),
7211 case PACKET_UNKNOWN
:
7212 error (_("Remote target does not support flash erase"));
7214 error (_("Error erasing flash with vFlashErase packet"));
7219 do_cleanups (back_to
);
7222 static enum target_xfer_status
7223 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7224 ULONGEST length
, ULONGEST
*xfered_len
,
7225 const gdb_byte
*data
)
7227 int saved_remote_timeout
= remote_timeout
;
7228 enum target_xfer_status ret
;
7229 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7230 &saved_remote_timeout
);
7232 remote_timeout
= remote_flash_timeout
;
7233 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
,
7235 do_cleanups (back_to
);
7241 remote_flash_done (struct target_ops
*ops
)
7243 int saved_remote_timeout
= remote_timeout
;
7245 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7246 &saved_remote_timeout
);
7248 remote_timeout
= remote_flash_timeout
;
7249 ret
= remote_send_printf ("vFlashDone");
7250 do_cleanups (back_to
);
7254 case PACKET_UNKNOWN
:
7255 error (_("Remote target does not support vFlashDone"));
7257 error (_("Error finishing flash operation"));
7264 remote_files_info (struct target_ops
*ignore
)
7266 puts_filtered ("Debugging a target over a serial line.\n");
7269 /* Stuff for dealing with the packets which are part of this protocol.
7270 See comment at top of file for details. */
7272 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7273 error to higher layers. Called when a serial error is detected.
7274 The exception message is STRING, followed by a colon and a blank,
7275 the system error message for errno at function entry and final dot
7276 for output compatibility with throw_perror_with_name. */
7279 unpush_and_perror (const char *string
)
7281 int saved_errno
= errno
;
7283 remote_unpush_target ();
7284 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7285 safe_strerror (saved_errno
));
7288 /* Read a single character from the remote end. */
7291 readchar (int timeout
)
7294 struct remote_state
*rs
= get_remote_state ();
7296 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7301 switch ((enum serial_rc
) ch
)
7304 remote_unpush_target ();
7305 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7308 unpush_and_perror (_("Remote communication error. "
7309 "Target disconnected."));
7311 case SERIAL_TIMEOUT
:
7317 /* Wrapper for serial_write that closes the target and throws if
7321 remote_serial_write (const char *str
, int len
)
7323 struct remote_state
*rs
= get_remote_state ();
7325 if (serial_write (rs
->remote_desc
, str
, len
))
7327 unpush_and_perror (_("Remote communication error. "
7328 "Target disconnected."));
7332 /* Send the command in *BUF to the remote machine, and read the reply
7333 into *BUF. Report an error if we get an error reply. Resize
7334 *BUF using xrealloc if necessary to hold the result, and update
7338 remote_send (char **buf
,
7342 getpkt (buf
, sizeof_buf
, 0);
7344 if ((*buf
)[0] == 'E')
7345 error (_("Remote failure reply: %s"), *buf
);
7348 /* Return a pointer to an xmalloc'ed string representing an escaped
7349 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7350 etc. The caller is responsible for releasing the returned
7354 escape_buffer (const char *buf
, int n
)
7356 struct cleanup
*old_chain
;
7357 struct ui_file
*stb
;
7360 stb
= mem_fileopen ();
7361 old_chain
= make_cleanup_ui_file_delete (stb
);
7363 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7364 str
= ui_file_xstrdup (stb
, NULL
);
7365 do_cleanups (old_chain
);
7369 /* Display a null-terminated packet on stdout, for debugging, using C
7373 print_packet (const char *buf
)
7375 puts_filtered ("\"");
7376 fputstr_filtered (buf
, '"', gdb_stdout
);
7377 puts_filtered ("\"");
7381 putpkt (const char *buf
)
7383 return putpkt_binary (buf
, strlen (buf
));
7386 /* Send a packet to the remote machine, with error checking. The data
7387 of the packet is in BUF. The string in BUF can be at most
7388 get_remote_packet_size () - 5 to account for the $, # and checksum,
7389 and for a possible /0 if we are debugging (remote_debug) and want
7390 to print the sent packet as a string. */
7393 putpkt_binary (const char *buf
, int cnt
)
7395 struct remote_state
*rs
= get_remote_state ();
7397 unsigned char csum
= 0;
7398 char *buf2
= alloca (cnt
+ 6);
7405 /* Catch cases like trying to read memory or listing threads while
7406 we're waiting for a stop reply. The remote server wouldn't be
7407 ready to handle this request, so we'd hang and timeout. We don't
7408 have to worry about this in synchronous mode, because in that
7409 case it's not possible to issue a command while the target is
7410 running. This is not a problem in non-stop mode, because in that
7411 case, the stub is always ready to process serial input. */
7412 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7414 error (_("Cannot execute this command while the target is running.\n"
7415 "Use the \"interrupt\" command to stop the target\n"
7416 "and then try again."));
7419 /* We're sending out a new packet. Make sure we don't look at a
7420 stale cached response. */
7421 rs
->cached_wait_status
= 0;
7423 /* Copy the packet into buffer BUF2, encapsulating it
7424 and giving it a checksum. */
7429 for (i
= 0; i
< cnt
; i
++)
7435 *p
++ = tohex ((csum
>> 4) & 0xf);
7436 *p
++ = tohex (csum
& 0xf);
7438 /* Send it over and over until we get a positive ack. */
7442 int started_error_output
= 0;
7446 struct cleanup
*old_chain
;
7450 str
= escape_buffer (buf2
, p
- buf2
);
7451 old_chain
= make_cleanup (xfree
, str
);
7452 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7453 gdb_flush (gdb_stdlog
);
7454 do_cleanups (old_chain
);
7456 remote_serial_write (buf2
, p
- buf2
);
7458 /* If this is a no acks version of the remote protocol, send the
7459 packet and move on. */
7463 /* Read until either a timeout occurs (-2) or '+' is read.
7464 Handle any notification that arrives in the mean time. */
7467 ch
= readchar (remote_timeout
);
7475 case SERIAL_TIMEOUT
:
7478 if (started_error_output
)
7480 putchar_unfiltered ('\n');
7481 started_error_output
= 0;
7490 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7494 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7496 case SERIAL_TIMEOUT
:
7500 break; /* Retransmit buffer. */
7504 fprintf_unfiltered (gdb_stdlog
,
7505 "Packet instead of Ack, ignoring it\n");
7506 /* It's probably an old response sent because an ACK
7507 was lost. Gobble up the packet and ack it so it
7508 doesn't get retransmitted when we resend this
7511 remote_serial_write ("+", 1);
7512 continue; /* Now, go look for +. */
7519 /* If we got a notification, handle it, and go back to looking
7521 /* We've found the start of a notification. Now
7522 collect the data. */
7523 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7528 struct cleanup
*old_chain
;
7531 str
= escape_buffer (rs
->buf
, val
);
7532 old_chain
= make_cleanup (xfree
, str
);
7533 fprintf_unfiltered (gdb_stdlog
,
7534 " Notification received: %s\n",
7536 do_cleanups (old_chain
);
7538 handle_notification (rs
->notif_state
, rs
->buf
);
7539 /* We're in sync now, rewait for the ack. */
7546 if (!started_error_output
)
7548 started_error_output
= 1;
7549 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7551 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7552 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7561 if (!started_error_output
)
7563 started_error_output
= 1;
7564 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7566 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7570 break; /* Here to retransmit. */
7574 /* This is wrong. If doing a long backtrace, the user should be
7575 able to get out next time we call QUIT, without anything as
7576 violent as interrupt_query. If we want to provide a way out of
7577 here without getting to the next QUIT, it should be based on
7578 hitting ^C twice as in remote_wait. */
7589 /* Come here after finding the start of a frame when we expected an
7590 ack. Do our best to discard the rest of this packet. */
7599 c
= readchar (remote_timeout
);
7602 case SERIAL_TIMEOUT
:
7603 /* Nothing we can do. */
7606 /* Discard the two bytes of checksum and stop. */
7607 c
= readchar (remote_timeout
);
7609 c
= readchar (remote_timeout
);
7612 case '*': /* Run length encoding. */
7613 /* Discard the repeat count. */
7614 c
= readchar (remote_timeout
);
7619 /* A regular character. */
7625 /* Come here after finding the start of the frame. Collect the rest
7626 into *BUF, verifying the checksum, length, and handling run-length
7627 compression. NUL terminate the buffer. If there is not enough room,
7628 expand *BUF using xrealloc.
7630 Returns -1 on error, number of characters in buffer (ignoring the
7631 trailing NULL) on success. (could be extended to return one of the
7632 SERIAL status indications). */
7635 read_frame (char **buf_p
,
7642 struct remote_state
*rs
= get_remote_state ();
7649 c
= readchar (remote_timeout
);
7652 case SERIAL_TIMEOUT
:
7654 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7658 fputs_filtered ("Saw new packet start in middle of old one\n",
7660 return -1; /* Start a new packet, count retries. */
7663 unsigned char pktcsum
;
7669 check_0
= readchar (remote_timeout
);
7671 check_1
= readchar (remote_timeout
);
7673 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7676 fputs_filtered ("Timeout in checksum, retrying\n",
7680 else if (check_0
< 0 || check_1
< 0)
7683 fputs_filtered ("Communication error in checksum\n",
7688 /* Don't recompute the checksum; with no ack packets we
7689 don't have any way to indicate a packet retransmission
7694 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7695 if (csum
== pktcsum
)
7700 struct cleanup
*old_chain
;
7703 str
= escape_buffer (buf
, bc
);
7704 old_chain
= make_cleanup (xfree
, str
);
7705 fprintf_unfiltered (gdb_stdlog
,
7706 "Bad checksum, sentsum=0x%x, "
7707 "csum=0x%x, buf=%s\n",
7708 pktcsum
, csum
, str
);
7709 do_cleanups (old_chain
);
7711 /* Number of characters in buffer ignoring trailing
7715 case '*': /* Run length encoding. */
7720 c
= readchar (remote_timeout
);
7722 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7724 /* The character before ``*'' is repeated. */
7726 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7728 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7730 /* Make some more room in the buffer. */
7731 *sizeof_buf
+= repeat
;
7732 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7736 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7742 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7746 if (bc
>= *sizeof_buf
- 1)
7748 /* Make some more room in the buffer. */
7750 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7761 /* Read a packet from the remote machine, with error checking, and
7762 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7763 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7764 rather than timing out; this is used (in synchronous mode) to wait
7765 for a target that is is executing user code to stop. */
7766 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7767 don't have to change all the calls to getpkt to deal with the
7768 return value, because at the moment I don't know what the right
7769 thing to do it for those. */
7777 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7781 /* Read a packet from the remote machine, with error checking, and
7782 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7783 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7784 rather than timing out; this is used (in synchronous mode) to wait
7785 for a target that is is executing user code to stop. If FOREVER ==
7786 0, this function is allowed to time out gracefully and return an
7787 indication of this to the caller. Otherwise return the number of
7788 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7789 enough reason to return to the caller. *IS_NOTIF is an output
7790 boolean that indicates whether *BUF holds a notification or not
7791 (a regular packet). */
7794 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7795 int expecting_notif
, int *is_notif
)
7797 struct remote_state
*rs
= get_remote_state ();
7803 /* We're reading a new response. Make sure we don't look at a
7804 previously cached response. */
7805 rs
->cached_wait_status
= 0;
7807 strcpy (*buf
, "timeout");
7810 timeout
= watchdog
> 0 ? watchdog
: -1;
7811 else if (expecting_notif
)
7812 timeout
= 0; /* There should already be a char in the buffer. If
7815 timeout
= remote_timeout
;
7819 /* Process any number of notifications, and then return when
7823 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7825 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7827 /* This can loop forever if the remote side sends us
7828 characters continuously, but if it pauses, we'll get
7829 SERIAL_TIMEOUT from readchar because of timeout. Then
7830 we'll count that as a retry.
7832 Note that even when forever is set, we will only wait
7833 forever prior to the start of a packet. After that, we
7834 expect characters to arrive at a brisk pace. They should
7835 show up within remote_timeout intervals. */
7837 c
= readchar (timeout
);
7838 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7840 if (c
== SERIAL_TIMEOUT
)
7842 if (expecting_notif
)
7843 return -1; /* Don't complain, it's normal to not get
7844 anything in this case. */
7846 if (forever
) /* Watchdog went off? Kill the target. */
7849 remote_unpush_target ();
7850 throw_error (TARGET_CLOSE_ERROR
,
7851 _("Watchdog timeout has expired. "
7852 "Target detached."));
7855 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7859 /* We've found the start of a packet or notification.
7860 Now collect the data. */
7861 val
= read_frame (buf
, sizeof_buf
);
7866 remote_serial_write ("-", 1);
7869 if (tries
> MAX_TRIES
)
7871 /* We have tried hard enough, and just can't receive the
7872 packet/notification. Give up. */
7873 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7875 /* Skip the ack char if we're in no-ack mode. */
7876 if (!rs
->noack_mode
)
7877 remote_serial_write ("+", 1);
7881 /* If we got an ordinary packet, return that to our caller. */
7886 struct cleanup
*old_chain
;
7889 str
= escape_buffer (*buf
, val
);
7890 old_chain
= make_cleanup (xfree
, str
);
7891 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7892 do_cleanups (old_chain
);
7895 /* Skip the ack char if we're in no-ack mode. */
7896 if (!rs
->noack_mode
)
7897 remote_serial_write ("+", 1);
7898 if (is_notif
!= NULL
)
7903 /* If we got a notification, handle it, and go back to looking
7907 gdb_assert (c
== '%');
7911 struct cleanup
*old_chain
;
7914 str
= escape_buffer (*buf
, val
);
7915 old_chain
= make_cleanup (xfree
, str
);
7916 fprintf_unfiltered (gdb_stdlog
,
7917 " Notification received: %s\n",
7919 do_cleanups (old_chain
);
7921 if (is_notif
!= NULL
)
7924 handle_notification (rs
->notif_state
, *buf
);
7926 /* Notifications require no acknowledgement. */
7928 if (expecting_notif
)
7935 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7937 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7941 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7944 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7950 remote_kill (struct target_ops
*ops
)
7953 /* Catch errors so the user can quit from gdb even when we
7954 aren't on speaking terms with the remote system. */
7959 CATCH (ex
, RETURN_MASK_ERROR
)
7961 if (ex
.error
== TARGET_CLOSE_ERROR
)
7963 /* If we got an (EOF) error that caused the target
7964 to go away, then we're done, that's what we wanted.
7965 "k" is susceptible to cause a premature EOF, given
7966 that the remote server isn't actually required to
7967 reply to "k", and it can happen that it doesn't
7968 even get to reply ACK to the "k". */
7972 /* Otherwise, something went wrong. We didn't actually kill
7973 the target. Just propagate the exception, and let the
7974 user or higher layers decide what to do. */
7975 throw_exception (ex
);
7979 /* We've killed the remote end, we get to mourn it. Since this is
7980 target remote, single-process, mourning the inferior also
7981 unpushes remote_ops. */
7982 target_mourn_inferior ();
7986 remote_vkill (int pid
, struct remote_state
*rs
)
7988 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
7991 /* Tell the remote target to detach. */
7992 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7994 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7996 switch (packet_ok (rs
->buf
,
7997 &remote_protocol_packets
[PACKET_vKill
]))
8003 case PACKET_UNKNOWN
:
8006 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8011 extended_remote_kill (struct target_ops
*ops
)
8014 int pid
= ptid_get_pid (inferior_ptid
);
8015 struct remote_state
*rs
= get_remote_state ();
8017 res
= remote_vkill (pid
, rs
);
8018 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8020 /* Don't try 'k' on a multi-process aware stub -- it has no way
8021 to specify the pid. */
8025 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8026 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8029 /* Don't wait for it to die. I'm not really sure it matters whether
8030 we do or not. For the existing stubs, kill is a noop. */
8036 error (_("Can't kill process"));
8038 target_mourn_inferior ();
8042 remote_mourn (struct target_ops
*target
)
8044 unpush_target (target
);
8046 /* remote_close takes care of doing most of the clean up. */
8047 generic_mourn_inferior ();
8051 extended_remote_mourn (struct target_ops
*target
)
8053 struct remote_state
*rs
= get_remote_state ();
8055 /* In case we got here due to an error, but we're going to stay
8057 rs
->waiting_for_stop_reply
= 0;
8059 /* If the current general thread belonged to the process we just
8060 detached from or has exited, the remote side current general
8061 thread becomes undefined. Considering a case like this:
8063 - We just got here due to a detach.
8064 - The process that we're detaching from happens to immediately
8065 report a global breakpoint being hit in non-stop mode, in the
8066 same thread we had selected before.
8067 - GDB attaches to this process again.
8068 - This event happens to be the next event we handle.
8070 GDB would consider that the current general thread didn't need to
8071 be set on the stub side (with Hg), since for all it knew,
8072 GENERAL_THREAD hadn't changed.
8074 Notice that although in all-stop mode, the remote server always
8075 sets the current thread to the thread reporting the stop event,
8076 that doesn't happen in non-stop mode; in non-stop, the stub *must
8077 not* change the current thread when reporting a breakpoint hit,
8078 due to the decoupling of event reporting and event handling.
8080 To keep things simple, we always invalidate our notion of the
8082 record_currthread (rs
, minus_one_ptid
);
8084 /* Unlike "target remote", we do not want to unpush the target; then
8085 the next time the user says "run", we won't be connected. */
8087 /* Call common code to mark the inferior as not running. */
8088 generic_mourn_inferior ();
8090 if (!have_inferiors ())
8092 if (!remote_multi_process_p (rs
))
8094 /* Check whether the target is running now - some remote stubs
8095 automatically restart after kill. */
8097 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8099 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8101 /* Assume that the target has been restarted. Set
8102 inferior_ptid so that bits of core GDB realizes
8103 there's something here, e.g., so that the user can
8104 say "kill" again. */
8105 inferior_ptid
= magic_null_ptid
;
8112 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8114 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8118 extended_remote_disable_randomization (int val
)
8120 struct remote_state
*rs
= get_remote_state ();
8123 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8126 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8128 error (_("Target does not support QDisableRandomization."));
8129 if (strcmp (reply
, "OK") != 0)
8130 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8134 extended_remote_run (char *args
)
8136 struct remote_state
*rs
= get_remote_state ();
8139 /* If the user has disabled vRun support, or we have detected that
8140 support is not available, do not try it. */
8141 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8144 strcpy (rs
->buf
, "vRun;");
8145 len
= strlen (rs
->buf
);
8147 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8148 error (_("Remote file name too long for run packet"));
8149 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8150 strlen (remote_exec_file
));
8152 gdb_assert (args
!= NULL
);
8155 struct cleanup
*back_to
;
8159 argv
= gdb_buildargv (args
);
8160 back_to
= make_cleanup_freeargv (argv
);
8161 for (i
= 0; argv
[i
] != NULL
; i
++)
8163 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8164 error (_("Argument list too long for run packet"));
8165 rs
->buf
[len
++] = ';';
8166 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8169 do_cleanups (back_to
);
8172 rs
->buf
[len
++] = '\0';
8175 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8177 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8180 /* We have a wait response. All is well. */
8182 case PACKET_UNKNOWN
:
8185 if (remote_exec_file
[0] == '\0')
8186 error (_("Running the default executable on the remote target failed; "
8187 "try \"set remote exec-file\"?"));
8189 error (_("Running \"%s\" on the remote target failed"),
8192 gdb_assert_not_reached (_("bad switch"));
8196 /* In the extended protocol we want to be able to do things like
8197 "run" and have them basically work as expected. So we need
8198 a special create_inferior function. We support changing the
8199 executable file and the command line arguments, but not the
8203 extended_remote_create_inferior (struct target_ops
*ops
,
8204 char *exec_file
, char *args
,
8205 char **env
, int from_tty
)
8209 struct remote_state
*rs
= get_remote_state ();
8211 /* If running asynchronously, register the target file descriptor
8212 with the event loop. */
8213 if (target_can_async_p ())
8216 /* Disable address space randomization if requested (and supported). */
8217 if (extended_remote_supports_disable_randomization (ops
))
8218 extended_remote_disable_randomization (disable_randomization
);
8220 /* Now restart the remote server. */
8221 run_worked
= extended_remote_run (args
) != -1;
8224 /* vRun was not supported. Fail if we need it to do what the
8226 if (remote_exec_file
[0])
8227 error (_("Remote target does not support \"set remote exec-file\""));
8229 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8231 /* Fall back to "R". */
8232 extended_remote_restart ();
8235 if (!have_inferiors ())
8237 /* Clean up from the last time we ran, before we mark the target
8238 running again. This will mark breakpoints uninserted, and
8239 get_offsets may insert breakpoints. */
8240 init_thread_list ();
8241 init_wait_for_inferior ();
8244 /* vRun's success return is a stop reply. */
8245 stop_reply
= run_worked
? rs
->buf
: NULL
;
8246 add_current_inferior_and_thread (stop_reply
);
8248 /* Get updated offsets, if the stub uses qOffsets. */
8253 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8254 the list of conditions (in agent expression bytecode format), if any, the
8255 target needs to evaluate. The output is placed into the packet buffer
8256 started from BUF and ended at BUF_END. */
8259 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8260 struct bp_target_info
*bp_tgt
, char *buf
,
8263 struct agent_expr
*aexpr
= NULL
;
8266 char *buf_start
= buf
;
8268 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8271 buf
+= strlen (buf
);
8272 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8275 /* Send conditions to the target and free the vector. */
8277 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8280 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8281 buf
+= strlen (buf
);
8282 for (i
= 0; i
< aexpr
->len
; ++i
)
8283 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8290 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8291 struct bp_target_info
*bp_tgt
, char *buf
)
8293 struct agent_expr
*aexpr
= NULL
;
8296 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8299 buf
+= strlen (buf
);
8301 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8302 buf
+= strlen (buf
);
8304 /* Concatenate all the agent expressions that are commands into the
8307 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8310 sprintf (buf
, "X%x,", aexpr
->len
);
8311 buf
+= strlen (buf
);
8312 for (i
= 0; i
< aexpr
->len
; ++i
)
8313 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8318 /* Insert a breakpoint. On targets that have software breakpoint
8319 support, we ask the remote target to do the work; on targets
8320 which don't, we insert a traditional memory breakpoint. */
8323 remote_insert_breakpoint (struct target_ops
*ops
,
8324 struct gdbarch
*gdbarch
,
8325 struct bp_target_info
*bp_tgt
)
8327 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8328 If it succeeds, then set the support to PACKET_ENABLE. If it
8329 fails, and the user has explicitly requested the Z support then
8330 report an error, otherwise, mark it disabled and go on. */
8332 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8334 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8335 struct remote_state
*rs
;
8338 struct condition_list
*cond
= NULL
;
8340 /* Make sure the remote is pointing at the right process, if
8342 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8343 set_general_process ();
8345 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8347 rs
= get_remote_state ();
8349 endbuf
= rs
->buf
+ get_remote_packet_size ();
8354 addr
= (ULONGEST
) remote_address_masked (addr
);
8355 p
+= hexnumstr (p
, addr
);
8356 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8358 if (remote_supports_cond_breakpoints (ops
))
8359 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8361 if (remote_can_run_breakpoint_commands (ops
))
8362 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8365 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8367 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8372 bp_tgt
->placed_address
= addr
;
8373 bp_tgt
->placed_size
= bpsize
;
8375 case PACKET_UNKNOWN
:
8380 /* If this breakpoint has target-side commands but this stub doesn't
8381 support Z0 packets, throw error. */
8382 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8383 throw_error (NOT_SUPPORTED_ERROR
, _("\
8384 Target doesn't support breakpoints that have target side commands."));
8386 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8390 remote_remove_breakpoint (struct target_ops
*ops
,
8391 struct gdbarch
*gdbarch
,
8392 struct bp_target_info
*bp_tgt
)
8394 CORE_ADDR addr
= bp_tgt
->placed_address
;
8395 struct remote_state
*rs
= get_remote_state ();
8397 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8400 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8402 /* Make sure the remote is pointing at the right process, if
8404 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8405 set_general_process ();
8411 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8412 p
+= hexnumstr (p
, addr
);
8413 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8416 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8418 return (rs
->buf
[0] == 'E');
8421 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8425 watchpoint_to_Z_packet (int type
)
8430 return Z_PACKET_WRITE_WP
;
8433 return Z_PACKET_READ_WP
;
8436 return Z_PACKET_ACCESS_WP
;
8439 internal_error (__FILE__
, __LINE__
,
8440 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8445 remote_insert_watchpoint (struct target_ops
*self
,
8446 CORE_ADDR addr
, int len
, int type
,
8447 struct expression
*cond
)
8449 struct remote_state
*rs
= get_remote_state ();
8450 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8452 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8454 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8457 /* Make sure the remote is pointing at the right process, if
8459 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8460 set_general_process ();
8462 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8463 p
= strchr (rs
->buf
, '\0');
8464 addr
= remote_address_masked (addr
);
8465 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8466 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8471 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8475 case PACKET_UNKNOWN
:
8480 internal_error (__FILE__
, __LINE__
,
8481 _("remote_insert_watchpoint: reached end of function"));
8485 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8486 CORE_ADDR start
, int length
)
8488 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8490 return diff
< length
;
8495 remote_remove_watchpoint (struct target_ops
*self
,
8496 CORE_ADDR addr
, int len
, int type
,
8497 struct expression
*cond
)
8499 struct remote_state
*rs
= get_remote_state ();
8500 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8502 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8504 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8507 /* Make sure the remote is pointing at the right process, if
8509 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8510 set_general_process ();
8512 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8513 p
= strchr (rs
->buf
, '\0');
8514 addr
= remote_address_masked (addr
);
8515 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8516 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8518 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8520 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8523 case PACKET_UNKNOWN
:
8528 internal_error (__FILE__
, __LINE__
,
8529 _("remote_remove_watchpoint: reached end of function"));
8533 int remote_hw_watchpoint_limit
= -1;
8534 int remote_hw_watchpoint_length_limit
= -1;
8535 int remote_hw_breakpoint_limit
= -1;
8538 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8539 CORE_ADDR addr
, int len
)
8541 if (remote_hw_watchpoint_length_limit
== 0)
8543 else if (remote_hw_watchpoint_length_limit
< 0)
8545 else if (len
<= remote_hw_watchpoint_length_limit
)
8552 remote_check_watch_resources (struct target_ops
*self
,
8553 int type
, int cnt
, int ot
)
8555 if (type
== bp_hardware_breakpoint
)
8557 if (remote_hw_breakpoint_limit
== 0)
8559 else if (remote_hw_breakpoint_limit
< 0)
8561 else if (cnt
<= remote_hw_breakpoint_limit
)
8566 if (remote_hw_watchpoint_limit
== 0)
8568 else if (remote_hw_watchpoint_limit
< 0)
8572 else if (cnt
<= remote_hw_watchpoint_limit
)
8578 /* The to_stopped_by_sw_breakpoint method of target remote. */
8581 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8583 struct remote_state
*rs
= get_remote_state ();
8585 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
8588 /* The to_supports_stopped_by_sw_breakpoint method of target
8592 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8594 struct remote_state
*rs
= get_remote_state ();
8596 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
8599 /* The to_stopped_by_hw_breakpoint method of target remote. */
8602 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8604 struct remote_state
*rs
= get_remote_state ();
8606 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
8609 /* The to_supports_stopped_by_hw_breakpoint method of target
8613 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8615 struct remote_state
*rs
= get_remote_state ();
8617 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
8621 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8623 struct remote_state
*rs
= get_remote_state ();
8625 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
8629 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8631 struct remote_state
*rs
= get_remote_state ();
8634 if (remote_stopped_by_watchpoint (target
))
8636 *addr_p
= rs
->remote_watch_data_address
;
8645 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8646 struct bp_target_info
*bp_tgt
)
8648 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8649 struct remote_state
*rs
;
8654 /* The length field should be set to the size of a breakpoint
8655 instruction, even though we aren't inserting one ourselves. */
8657 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8659 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8662 /* Make sure the remote is pointing at the right process, if
8664 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8665 set_general_process ();
8667 rs
= get_remote_state ();
8669 endbuf
= rs
->buf
+ get_remote_packet_size ();
8675 addr
= remote_address_masked (addr
);
8676 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8677 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
8679 if (remote_supports_cond_breakpoints (self
))
8680 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8682 if (remote_can_run_breakpoint_commands (self
))
8683 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8686 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8688 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8691 if (rs
->buf
[1] == '.')
8693 message
= strchr (rs
->buf
+ 2, '.');
8695 error (_("Remote failure reply: %s"), message
+ 1);
8698 case PACKET_UNKNOWN
:
8701 bp_tgt
->placed_address
= addr
;
8702 bp_tgt
->placed_size
= bpsize
;
8705 internal_error (__FILE__
, __LINE__
,
8706 _("remote_insert_hw_breakpoint: reached end of function"));
8711 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8712 struct bp_target_info
*bp_tgt
)
8715 struct remote_state
*rs
= get_remote_state ();
8717 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8719 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8722 /* Make sure the remote is pointing at the right process, if
8724 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8725 set_general_process ();
8731 addr
= remote_address_masked (bp_tgt
->placed_address
);
8732 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8733 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8738 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8741 case PACKET_UNKNOWN
:
8746 internal_error (__FILE__
, __LINE__
,
8747 _("remote_remove_hw_breakpoint: reached end of function"));
8750 /* Verify memory using the "qCRC:" request. */
8753 remote_verify_memory (struct target_ops
*ops
,
8754 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8756 struct remote_state
*rs
= get_remote_state ();
8757 unsigned long host_crc
, target_crc
;
8760 /* It doesn't make sense to use qCRC if the remote target is
8761 connected but not running. */
8762 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
8764 enum packet_result result
;
8766 /* Make sure the remote is pointing at the right process. */
8767 set_general_process ();
8769 /* FIXME: assumes lma can fit into long. */
8770 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8771 (long) lma
, (long) size
);
8774 /* Be clever; compute the host_crc before waiting for target
8776 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8778 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8780 result
= packet_ok (rs
->buf
,
8781 &remote_protocol_packets
[PACKET_qCRC
]);
8782 if (result
== PACKET_ERROR
)
8784 else if (result
== PACKET_OK
)
8786 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8787 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8789 return (host_crc
== target_crc
);
8793 return simple_verify_memory (ops
, data
, lma
, size
);
8796 /* compare-sections command
8798 With no arguments, compares each loadable section in the exec bfd
8799 with the same memory range on the target, and reports mismatches.
8800 Useful for verifying the image on the target against the exec file. */
8803 compare_sections_command (char *args
, int from_tty
)
8806 struct cleanup
*old_chain
;
8808 const char *sectname
;
8817 error (_("command cannot be used without an exec file"));
8819 /* Make sure the remote is pointing at the right process. */
8820 set_general_process ();
8822 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
8828 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8830 if (!(s
->flags
& SEC_LOAD
))
8831 continue; /* Skip non-loadable section. */
8833 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
8834 continue; /* Skip writeable sections */
8836 size
= bfd_get_section_size (s
);
8838 continue; /* Skip zero-length section. */
8840 sectname
= bfd_get_section_name (exec_bfd
, s
);
8841 if (args
&& strcmp (args
, sectname
) != 0)
8842 continue; /* Not the section selected by user. */
8844 matched
= 1; /* Do this section. */
8847 sectdata
= xmalloc (size
);
8848 old_chain
= make_cleanup (xfree
, sectdata
);
8849 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8851 res
= target_verify_memory (sectdata
, lma
, size
);
8854 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8855 paddress (target_gdbarch (), lma
),
8856 paddress (target_gdbarch (), lma
+ size
));
8858 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8859 paddress (target_gdbarch (), lma
),
8860 paddress (target_gdbarch (), lma
+ size
));
8862 printf_filtered ("matched.\n");
8865 printf_filtered ("MIS-MATCHED!\n");
8869 do_cleanups (old_chain
);
8872 warning (_("One or more sections of the target image does not match\n\
8873 the loaded file\n"));
8874 if (args
&& !matched
)
8875 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8878 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8879 into remote target. The number of bytes written to the remote
8880 target is returned, or -1 for error. */
8882 static enum target_xfer_status
8883 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8884 const char *annex
, const gdb_byte
*writebuf
,
8885 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
8886 struct packet_config
*packet
)
8890 struct remote_state
*rs
= get_remote_state ();
8891 int max_size
= get_memory_write_packet_size ();
8893 if (packet
->support
== PACKET_DISABLE
)
8894 return TARGET_XFER_E_IO
;
8896 /* Insert header. */
8897 i
= snprintf (rs
->buf
, max_size
,
8898 "qXfer:%s:write:%s:%s:",
8899 object_name
, annex
? annex
: "",
8900 phex_nz (offset
, sizeof offset
));
8901 max_size
-= (i
+ 1);
8903 /* Escape as much data as fits into rs->buf. */
8904 buf_len
= remote_escape_output
8905 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8907 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8908 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8909 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8910 return TARGET_XFER_E_IO
;
8912 unpack_varlen_hex (rs
->buf
, &n
);
8915 return TARGET_XFER_OK
;
8918 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8919 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8920 number of bytes read is returned, or 0 for EOF, or -1 for error.
8921 The number of bytes read may be less than LEN without indicating an
8922 EOF. PACKET is checked and updated to indicate whether the remote
8923 target supports this object. */
8925 static enum target_xfer_status
8926 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8928 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8929 ULONGEST
*xfered_len
,
8930 struct packet_config
*packet
)
8932 struct remote_state
*rs
= get_remote_state ();
8933 LONGEST i
, n
, packet_len
;
8935 if (packet
->support
== PACKET_DISABLE
)
8936 return TARGET_XFER_E_IO
;
8938 /* Check whether we've cached an end-of-object packet that matches
8940 if (rs
->finished_object
)
8942 if (strcmp (object_name
, rs
->finished_object
) == 0
8943 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8944 && offset
== rs
->finished_offset
)
8945 return TARGET_XFER_EOF
;
8948 /* Otherwise, we're now reading something different. Discard
8950 xfree (rs
->finished_object
);
8951 xfree (rs
->finished_annex
);
8952 rs
->finished_object
= NULL
;
8953 rs
->finished_annex
= NULL
;
8956 /* Request only enough to fit in a single packet. The actual data
8957 may not, since we don't know how much of it will need to be escaped;
8958 the target is free to respond with slightly less data. We subtract
8959 five to account for the response type and the protocol frame. */
8960 n
= min (get_remote_packet_size () - 5, len
);
8961 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8962 object_name
, annex
? annex
: "",
8963 phex_nz (offset
, sizeof offset
),
8964 phex_nz (n
, sizeof n
));
8965 i
= putpkt (rs
->buf
);
8967 return TARGET_XFER_E_IO
;
8970 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8971 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8972 return TARGET_XFER_E_IO
;
8974 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8975 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8977 /* 'm' means there is (or at least might be) more data after this
8978 batch. That does not make sense unless there's at least one byte
8979 of data in this reply. */
8980 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8981 error (_("Remote qXfer reply contained no data."));
8983 /* Got some data. */
8984 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8985 packet_len
- 1, readbuf
, n
);
8987 /* 'l' is an EOF marker, possibly including a final block of data,
8988 or possibly empty. If we have the final block of a non-empty
8989 object, record this fact to bypass a subsequent partial read. */
8990 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8992 rs
->finished_object
= xstrdup (object_name
);
8993 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8994 rs
->finished_offset
= offset
+ i
;
8998 return TARGET_XFER_EOF
;
9002 return TARGET_XFER_OK
;
9006 static enum target_xfer_status
9007 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9008 const char *annex
, gdb_byte
*readbuf
,
9009 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9010 ULONGEST
*xfered_len
)
9012 struct remote_state
*rs
;
9017 set_remote_traceframe ();
9018 set_general_thread (inferior_ptid
);
9020 rs
= get_remote_state ();
9022 /* Handle memory using the standard memory routines. */
9023 if (object
== TARGET_OBJECT_MEMORY
)
9025 /* If the remote target is connected but not running, we should
9026 pass this request down to a lower stratum (e.g. the executable
9028 if (!target_has_execution
)
9029 return TARGET_XFER_EOF
;
9031 if (writebuf
!= NULL
)
9032 return remote_write_bytes (offset
, writebuf
, len
, xfered_len
);
9034 return remote_read_bytes (ops
, offset
, readbuf
, len
, xfered_len
);
9037 /* Handle SPU memory using qxfer packets. */
9038 if (object
== TARGET_OBJECT_SPU
)
9041 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9042 xfered_len
, &remote_protocol_packets
9043 [PACKET_qXfer_spu_read
]);
9045 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9046 xfered_len
, &remote_protocol_packets
9047 [PACKET_qXfer_spu_write
]);
9050 /* Handle extra signal info using qxfer packets. */
9051 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9054 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9055 xfered_len
, &remote_protocol_packets
9056 [PACKET_qXfer_siginfo_read
]);
9058 return remote_write_qxfer (ops
, "siginfo", annex
,
9059 writebuf
, offset
, len
, xfered_len
,
9060 &remote_protocol_packets
9061 [PACKET_qXfer_siginfo_write
]);
9064 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9067 return remote_read_qxfer (ops
, "statictrace", annex
,
9068 readbuf
, offset
, len
, xfered_len
,
9069 &remote_protocol_packets
9070 [PACKET_qXfer_statictrace_read
]);
9072 return TARGET_XFER_E_IO
;
9075 /* Only handle flash writes. */
9076 if (writebuf
!= NULL
)
9082 case TARGET_OBJECT_FLASH
:
9083 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9087 return TARGET_XFER_E_IO
;
9091 /* Map pre-existing objects onto letters. DO NOT do this for new
9092 objects!!! Instead specify new query packets. */
9095 case TARGET_OBJECT_AVR
:
9099 case TARGET_OBJECT_AUXV
:
9100 gdb_assert (annex
== NULL
);
9101 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9103 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9105 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9106 return remote_read_qxfer
9107 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9108 &remote_protocol_packets
[PACKET_qXfer_features
]);
9110 case TARGET_OBJECT_LIBRARIES
:
9111 return remote_read_qxfer
9112 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9113 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9115 case TARGET_OBJECT_LIBRARIES_SVR4
:
9116 return remote_read_qxfer
9117 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9118 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9120 case TARGET_OBJECT_MEMORY_MAP
:
9121 gdb_assert (annex
== NULL
);
9122 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9124 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9126 case TARGET_OBJECT_OSDATA
:
9127 /* Should only get here if we're connected. */
9128 gdb_assert (rs
->remote_desc
);
9129 return remote_read_qxfer
9130 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9131 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9133 case TARGET_OBJECT_THREADS
:
9134 gdb_assert (annex
== NULL
);
9135 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9137 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9139 case TARGET_OBJECT_TRACEFRAME_INFO
:
9140 gdb_assert (annex
== NULL
);
9141 return remote_read_qxfer
9142 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9143 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9145 case TARGET_OBJECT_FDPIC
:
9146 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9148 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9150 case TARGET_OBJECT_OPENVMS_UIB
:
9151 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9153 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9155 case TARGET_OBJECT_BTRACE
:
9156 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9158 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9160 case TARGET_OBJECT_BTRACE_CONF
:
9161 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9163 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9165 case TARGET_OBJECT_EXEC_FILE
:
9166 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9168 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9171 return TARGET_XFER_E_IO
;
9174 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9175 large enough let the caller deal with it. */
9176 if (len
< get_remote_packet_size ())
9177 return TARGET_XFER_E_IO
;
9178 len
= get_remote_packet_size ();
9180 /* Except for querying the minimum buffer size, target must be open. */
9181 if (!rs
->remote_desc
)
9182 error (_("remote query is only available after target open"));
9184 gdb_assert (annex
!= NULL
);
9185 gdb_assert (readbuf
!= NULL
);
9191 /* We used one buffer char for the remote protocol q command and
9192 another for the query type. As the remote protocol encapsulation
9193 uses 4 chars plus one extra in case we are debugging
9194 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9197 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9199 /* Bad caller may have sent forbidden characters. */
9200 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9205 gdb_assert (annex
[i
] == '\0');
9207 i
= putpkt (rs
->buf
);
9209 return TARGET_XFER_E_IO
;
9211 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9212 strcpy ((char *) readbuf
, rs
->buf
);
9214 *xfered_len
= strlen ((char *) readbuf
);
9215 return TARGET_XFER_OK
;
9219 remote_search_memory (struct target_ops
* ops
,
9220 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9221 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9222 CORE_ADDR
*found_addrp
)
9224 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9225 struct remote_state
*rs
= get_remote_state ();
9226 int max_size
= get_memory_write_packet_size ();
9227 struct packet_config
*packet
=
9228 &remote_protocol_packets
[PACKET_qSearch_memory
];
9229 /* Number of packet bytes used to encode the pattern;
9230 this could be more than PATTERN_LEN due to escape characters. */
9231 int escaped_pattern_len
;
9232 /* Amount of pattern that was encodable in the packet. */
9233 int used_pattern_len
;
9236 ULONGEST found_addr
;
9238 /* Don't go to the target if we don't have to.
9239 This is done before checking packet->support to avoid the possibility that
9240 a success for this edge case means the facility works in general. */
9241 if (pattern_len
> search_space_len
)
9243 if (pattern_len
== 0)
9245 *found_addrp
= start_addr
;
9249 /* If we already know the packet isn't supported, fall back to the simple
9250 way of searching memory. */
9252 if (packet_config_support (packet
) == PACKET_DISABLE
)
9254 /* Target doesn't provided special support, fall back and use the
9255 standard support (copy memory and do the search here). */
9256 return simple_search_memory (ops
, start_addr
, search_space_len
,
9257 pattern
, pattern_len
, found_addrp
);
9260 /* Make sure the remote is pointing at the right process. */
9261 set_general_process ();
9263 /* Insert header. */
9264 i
= snprintf (rs
->buf
, max_size
,
9265 "qSearch:memory:%s;%s;",
9266 phex_nz (start_addr
, addr_size
),
9267 phex_nz (search_space_len
, sizeof (search_space_len
)));
9268 max_size
-= (i
+ 1);
9270 /* Escape as much data as fits into rs->buf. */
9271 escaped_pattern_len
=
9272 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
9273 &used_pattern_len
, max_size
);
9275 /* Bail if the pattern is too large. */
9276 if (used_pattern_len
!= pattern_len
)
9277 error (_("Pattern is too large to transmit to remote target."));
9279 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9280 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9281 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9283 /* The request may not have worked because the command is not
9284 supported. If so, fall back to the simple way. */
9285 if (packet
->support
== PACKET_DISABLE
)
9287 return simple_search_memory (ops
, start_addr
, search_space_len
,
9288 pattern
, pattern_len
, found_addrp
);
9293 if (rs
->buf
[0] == '0')
9295 else if (rs
->buf
[0] == '1')
9298 if (rs
->buf
[1] != ',')
9299 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9300 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9301 *found_addrp
= found_addr
;
9304 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9310 remote_rcmd (struct target_ops
*self
, const char *command
,
9311 struct ui_file
*outbuf
)
9313 struct remote_state
*rs
= get_remote_state ();
9316 if (!rs
->remote_desc
)
9317 error (_("remote rcmd is only available after target open"));
9319 /* Send a NULL command across as an empty command. */
9320 if (command
== NULL
)
9323 /* The query prefix. */
9324 strcpy (rs
->buf
, "qRcmd,");
9325 p
= strchr (rs
->buf
, '\0');
9327 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9328 > get_remote_packet_size ())
9329 error (_("\"monitor\" command ``%s'' is too long."), command
);
9331 /* Encode the actual command. */
9332 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9334 if (putpkt (rs
->buf
) < 0)
9335 error (_("Communication problem with target."));
9337 /* get/display the response */
9342 /* XXX - see also remote_get_noisy_reply(). */
9343 QUIT
; /* Allow user to bail out with ^C. */
9345 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9347 /* Timeout. Continue to (try to) read responses.
9348 This is better than stopping with an error, assuming the stub
9349 is still executing the (long) monitor command.
9350 If needed, the user can interrupt gdb using C-c, obtaining
9351 an effect similar to stop on timeout. */
9356 error (_("Target does not support this command."));
9357 if (buf
[0] == 'O' && buf
[1] != 'K')
9359 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9362 if (strcmp (buf
, "OK") == 0)
9364 if (strlen (buf
) == 3 && buf
[0] == 'E'
9365 && isdigit (buf
[1]) && isdigit (buf
[2]))
9367 error (_("Protocol error with Rcmd"));
9369 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9371 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9373 fputc_unfiltered (c
, outbuf
);
9379 static VEC(mem_region_s
) *
9380 remote_memory_map (struct target_ops
*ops
)
9382 VEC(mem_region_s
) *result
= NULL
;
9383 char *text
= target_read_stralloc (¤t_target
,
9384 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9388 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9390 result
= parse_memory_map (text
);
9391 do_cleanups (back_to
);
9398 packet_command (char *args
, int from_tty
)
9400 struct remote_state
*rs
= get_remote_state ();
9402 if (!rs
->remote_desc
)
9403 error (_("command can only be used with remote target"));
9406 error (_("remote-packet command requires packet text as argument"));
9408 puts_filtered ("sending: ");
9409 print_packet (args
);
9410 puts_filtered ("\n");
9413 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9414 puts_filtered ("received: ");
9415 print_packet (rs
->buf
);
9416 puts_filtered ("\n");
9420 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9422 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9424 static void threadset_test_cmd (char *cmd
, int tty
);
9426 static void threadalive_test (char *cmd
, int tty
);
9428 static void threadlist_test_cmd (char *cmd
, int tty
);
9430 int get_and_display_threadinfo (threadref
*ref
);
9432 static void threadinfo_test_cmd (char *cmd
, int tty
);
9434 static int thread_display_step (threadref
*ref
, void *context
);
9436 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9438 static void init_remote_threadtests (void);
9440 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9443 threadset_test_cmd (char *cmd
, int tty
)
9445 int sample_thread
= SAMPLE_THREAD
;
9447 printf_filtered (_("Remote threadset test\n"));
9448 set_general_thread (sample_thread
);
9453 threadalive_test (char *cmd
, int tty
)
9455 int sample_thread
= SAMPLE_THREAD
;
9456 int pid
= ptid_get_pid (inferior_ptid
);
9457 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9459 if (remote_thread_alive (ptid
))
9460 printf_filtered ("PASS: Thread alive test\n");
9462 printf_filtered ("FAIL: Thread alive test\n");
9465 void output_threadid (char *title
, threadref
*ref
);
9468 output_threadid (char *title
, threadref
*ref
)
9472 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9474 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9478 threadlist_test_cmd (char *cmd
, int tty
)
9481 threadref nextthread
;
9482 int done
, result_count
;
9483 threadref threadlist
[3];
9485 printf_filtered ("Remote Threadlist test\n");
9486 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9487 &result_count
, &threadlist
[0]))
9488 printf_filtered ("FAIL: threadlist test\n");
9491 threadref
*scan
= threadlist
;
9492 threadref
*limit
= scan
+ result_count
;
9494 while (scan
< limit
)
9495 output_threadid (" thread ", scan
++);
9500 display_thread_info (struct gdb_ext_thread_info
*info
)
9502 output_threadid ("Threadid: ", &info
->threadid
);
9503 printf_filtered ("Name: %s\n ", info
->shortname
);
9504 printf_filtered ("State: %s\n", info
->display
);
9505 printf_filtered ("other: %s\n\n", info
->more_display
);
9509 get_and_display_threadinfo (threadref
*ref
)
9513 struct gdb_ext_thread_info threadinfo
;
9515 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9516 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9517 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9518 display_thread_info (&threadinfo
);
9523 threadinfo_test_cmd (char *cmd
, int tty
)
9525 int athread
= SAMPLE_THREAD
;
9529 int_to_threadref (&thread
, athread
);
9530 printf_filtered ("Remote Threadinfo test\n");
9531 if (!get_and_display_threadinfo (&thread
))
9532 printf_filtered ("FAIL cannot get thread info\n");
9536 thread_display_step (threadref
*ref
, void *context
)
9538 /* output_threadid(" threadstep ",ref); *//* simple test */
9539 return get_and_display_threadinfo (ref
);
9543 threadlist_update_test_cmd (char *cmd
, int tty
)
9545 printf_filtered ("Remote Threadlist update test\n");
9546 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9550 init_remote_threadtests (void)
9552 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9553 _("Fetch and print the remote list of "
9554 "thread identifiers, one pkt only"));
9555 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9556 _("Fetch and display info about one thread"));
9557 add_com ("tset", class_obscure
, threadset_test_cmd
,
9558 _("Test setting to a different thread"));
9559 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9560 _("Iterate through updating all remote thread info"));
9561 add_com ("talive", class_obscure
, threadalive_test
,
9562 _(" Remote thread alive test "));
9567 /* Convert a thread ID to a string. Returns the string in a static
9571 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9573 static char buf
[64];
9574 struct remote_state
*rs
= get_remote_state ();
9576 if (ptid_equal (ptid
, null_ptid
))
9577 return normal_pid_to_str (ptid
);
9578 else if (ptid_is_pid (ptid
))
9580 /* Printing an inferior target id. */
9582 /* When multi-process extensions are off, there's no way in the
9583 remote protocol to know the remote process id, if there's any
9584 at all. There's one exception --- when we're connected with
9585 target extended-remote, and we manually attached to a process
9586 with "attach PID". We don't record anywhere a flag that
9587 allows us to distinguish that case from the case of
9588 connecting with extended-remote and the stub already being
9589 attached to a process, and reporting yes to qAttached, hence
9590 no smart special casing here. */
9591 if (!remote_multi_process_p (rs
))
9593 xsnprintf (buf
, sizeof buf
, "Remote target");
9597 return normal_pid_to_str (ptid
);
9601 if (ptid_equal (magic_null_ptid
, ptid
))
9602 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9603 else if (rs
->extended
&& remote_multi_process_p (rs
))
9604 if (ptid_get_lwp (ptid
) == 0)
9605 return normal_pid_to_str (ptid
);
9607 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9608 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9610 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9611 ptid_get_lwp (ptid
));
9616 /* Get the address of the thread local variable in OBJFILE which is
9617 stored at OFFSET within the thread local storage for thread PTID. */
9620 remote_get_thread_local_address (struct target_ops
*ops
,
9621 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9623 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9625 struct remote_state
*rs
= get_remote_state ();
9627 char *endp
= rs
->buf
+ get_remote_packet_size ();
9628 enum packet_result result
;
9630 strcpy (p
, "qGetTLSAddr:");
9632 p
= write_ptid (p
, endp
, ptid
);
9634 p
+= hexnumstr (p
, offset
);
9636 p
+= hexnumstr (p
, lm
);
9640 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9641 result
= packet_ok (rs
->buf
,
9642 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9643 if (result
== PACKET_OK
)
9647 unpack_varlen_hex (rs
->buf
, &result
);
9650 else if (result
== PACKET_UNKNOWN
)
9651 throw_error (TLS_GENERIC_ERROR
,
9652 _("Remote target doesn't support qGetTLSAddr packet"));
9654 throw_error (TLS_GENERIC_ERROR
,
9655 _("Remote target failed to process qGetTLSAddr request"));
9658 throw_error (TLS_GENERIC_ERROR
,
9659 _("TLS not supported or disabled on this target"));
9664 /* Provide thread local base, i.e. Thread Information Block address.
9665 Returns 1 if ptid is found and thread_local_base is non zero. */
9668 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9670 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9672 struct remote_state
*rs
= get_remote_state ();
9674 char *endp
= rs
->buf
+ get_remote_packet_size ();
9675 enum packet_result result
;
9677 strcpy (p
, "qGetTIBAddr:");
9679 p
= write_ptid (p
, endp
, ptid
);
9683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9684 result
= packet_ok (rs
->buf
,
9685 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9686 if (result
== PACKET_OK
)
9690 unpack_varlen_hex (rs
->buf
, &result
);
9692 *addr
= (CORE_ADDR
) result
;
9695 else if (result
== PACKET_UNKNOWN
)
9696 error (_("Remote target doesn't support qGetTIBAddr packet"));
9698 error (_("Remote target failed to process qGetTIBAddr request"));
9701 error (_("qGetTIBAddr not supported or disabled on this target"));
9706 /* Support for inferring a target description based on the current
9707 architecture and the size of a 'g' packet. While the 'g' packet
9708 can have any size (since optional registers can be left off the
9709 end), some sizes are easily recognizable given knowledge of the
9710 approximate architecture. */
9712 struct remote_g_packet_guess
9715 const struct target_desc
*tdesc
;
9717 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9718 DEF_VEC_O(remote_g_packet_guess_s
);
9720 struct remote_g_packet_data
9722 VEC(remote_g_packet_guess_s
) *guesses
;
9725 static struct gdbarch_data
*remote_g_packet_data_handle
;
9728 remote_g_packet_data_init (struct obstack
*obstack
)
9730 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9734 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9735 const struct target_desc
*tdesc
)
9737 struct remote_g_packet_data
*data
9738 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9739 struct remote_g_packet_guess new_guess
, *guess
;
9742 gdb_assert (tdesc
!= NULL
);
9745 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9747 if (guess
->bytes
== bytes
)
9748 internal_error (__FILE__
, __LINE__
,
9749 _("Duplicate g packet description added for size %d"),
9752 new_guess
.bytes
= bytes
;
9753 new_guess
.tdesc
= tdesc
;
9754 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9757 /* Return 1 if remote_read_description would do anything on this target
9758 and architecture, 0 otherwise. */
9761 remote_read_description_p (struct target_ops
*target
)
9763 struct remote_g_packet_data
*data
9764 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9766 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9772 static const struct target_desc
*
9773 remote_read_description (struct target_ops
*target
)
9775 struct remote_g_packet_data
*data
9776 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9778 /* Do not try this during initial connection, when we do not know
9779 whether there is a running but stopped thread. */
9780 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9781 return target
->beneath
->to_read_description (target
->beneath
);
9783 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9785 struct remote_g_packet_guess
*guess
;
9787 int bytes
= send_g_packet ();
9790 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9792 if (guess
->bytes
== bytes
)
9793 return guess
->tdesc
;
9795 /* We discard the g packet. A minor optimization would be to
9796 hold on to it, and fill the register cache once we have selected
9797 an architecture, but it's too tricky to do safely. */
9800 return target
->beneath
->to_read_description (target
->beneath
);
9803 /* Remote file transfer support. This is host-initiated I/O, not
9804 target-initiated; for target-initiated, see remote-fileio.c. */
9806 /* If *LEFT is at least the length of STRING, copy STRING to
9807 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9808 decrease *LEFT. Otherwise raise an error. */
9811 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9813 int len
= strlen (string
);
9816 error (_("Packet too long for target."));
9818 memcpy (*buffer
, string
, len
);
9822 /* NUL-terminate the buffer as a convenience, if there is
9828 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9829 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9830 decrease *LEFT. Otherwise raise an error. */
9833 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9836 if (2 * len
> *left
)
9837 error (_("Packet too long for target."));
9839 bin2hex (bytes
, *buffer
, len
);
9843 /* NUL-terminate the buffer as a convenience, if there is
9849 /* If *LEFT is large enough, convert VALUE to hex and add it to
9850 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9851 decrease *LEFT. Otherwise raise an error. */
9854 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9856 int len
= hexnumlen (value
);
9859 error (_("Packet too long for target."));
9861 hexnumstr (*buffer
, value
);
9865 /* NUL-terminate the buffer as a convenience, if there is
9871 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9872 value, *REMOTE_ERRNO to the remote error number or zero if none
9873 was included, and *ATTACHMENT to point to the start of the annex
9874 if any. The length of the packet isn't needed here; there may
9875 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9877 Return 0 if the packet could be parsed, -1 if it could not. If
9878 -1 is returned, the other variables may not be initialized. */
9881 remote_hostio_parse_result (char *buffer
, int *retcode
,
9882 int *remote_errno
, char **attachment
)
9889 if (buffer
[0] != 'F')
9893 *retcode
= strtol (&buffer
[1], &p
, 16);
9894 if (errno
!= 0 || p
== &buffer
[1])
9897 /* Check for ",errno". */
9901 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9902 if (errno
!= 0 || p
+ 1 == p2
)
9907 /* Check for ";attachment". If there is no attachment, the
9908 packet should end here. */
9911 *attachment
= p
+ 1;
9914 else if (*p
== '\0')
9920 /* Send a prepared I/O packet to the target and read its response.
9921 The prepared packet is in the global RS->BUF before this function
9922 is called, and the answer is there when we return.
9924 COMMAND_BYTES is the length of the request to send, which may include
9925 binary data. WHICH_PACKET is the packet configuration to check
9926 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9927 is set to the error number and -1 is returned. Otherwise the value
9928 returned by the function is returned.
9930 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9931 attachment is expected; an error will be reported if there's a
9932 mismatch. If one is found, *ATTACHMENT will be set to point into
9933 the packet buffer and *ATTACHMENT_LEN will be set to the
9934 attachment's length. */
9937 remote_hostio_send_command (int command_bytes
, int which_packet
,
9938 int *remote_errno
, char **attachment
,
9939 int *attachment_len
)
9941 struct remote_state
*rs
= get_remote_state ();
9942 int ret
, bytes_read
;
9943 char *attachment_tmp
;
9945 if (!rs
->remote_desc
9946 || packet_support (which_packet
) == PACKET_DISABLE
)
9948 *remote_errno
= FILEIO_ENOSYS
;
9952 putpkt_binary (rs
->buf
, command_bytes
);
9953 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9955 /* If it timed out, something is wrong. Don't try to parse the
9959 *remote_errno
= FILEIO_EINVAL
;
9963 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9966 *remote_errno
= FILEIO_EINVAL
;
9968 case PACKET_UNKNOWN
:
9969 *remote_errno
= FILEIO_ENOSYS
;
9975 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9978 *remote_errno
= FILEIO_EINVAL
;
9982 /* Make sure we saw an attachment if and only if we expected one. */
9983 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9984 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9986 *remote_errno
= FILEIO_EINVAL
;
9990 /* If an attachment was found, it must point into the packet buffer;
9991 work out how many bytes there were. */
9992 if (attachment_tmp
!= NULL
)
9994 *attachment
= attachment_tmp
;
9995 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10001 /* Return nonzero if the filesystem accessed by the target_fileio_*
10002 methods is the local filesystem, zero otherwise. */
10005 remote_filesystem_is_local (struct target_ops
*self
)
10010 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
10011 remote file descriptor, or -1 if an error occurs (and set
10015 remote_hostio_open (struct target_ops
*self
,
10016 const char *filename
, int flags
, int mode
,
10019 struct remote_state
*rs
= get_remote_state ();
10021 int left
= get_remote_packet_size () - 1;
10023 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10025 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10026 strlen (filename
));
10027 remote_buffer_add_string (&p
, &left
, ",");
10029 remote_buffer_add_int (&p
, &left
, flags
);
10030 remote_buffer_add_string (&p
, &left
, ",");
10032 remote_buffer_add_int (&p
, &left
, mode
);
10034 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10035 remote_errno
, NULL
, NULL
);
10038 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
10039 Return the number of bytes written, or -1 if an error occurs (and
10040 set *REMOTE_ERRNO). */
10043 remote_hostio_pwrite (struct target_ops
*self
,
10044 int fd
, const gdb_byte
*write_buf
, int len
,
10045 ULONGEST offset
, int *remote_errno
)
10047 struct remote_state
*rs
= get_remote_state ();
10049 int left
= get_remote_packet_size ();
10052 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10054 remote_buffer_add_int (&p
, &left
, fd
);
10055 remote_buffer_add_string (&p
, &left
, ",");
10057 remote_buffer_add_int (&p
, &left
, offset
);
10058 remote_buffer_add_string (&p
, &left
, ",");
10060 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
10061 get_remote_packet_size () - (p
- rs
->buf
));
10063 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10064 remote_errno
, NULL
, NULL
);
10067 /* Read up to LEN bytes FD on the remote target into READ_BUF
10068 Return the number of bytes read, or -1 if an error occurs (and
10069 set *REMOTE_ERRNO). */
10072 remote_hostio_pread (struct target_ops
*self
,
10073 int fd
, gdb_byte
*read_buf
, int len
,
10074 ULONGEST offset
, int *remote_errno
)
10076 struct remote_state
*rs
= get_remote_state ();
10079 int left
= get_remote_packet_size ();
10080 int ret
, attachment_len
;
10083 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10085 remote_buffer_add_int (&p
, &left
, fd
);
10086 remote_buffer_add_string (&p
, &left
, ",");
10088 remote_buffer_add_int (&p
, &left
, len
);
10089 remote_buffer_add_string (&p
, &left
, ",");
10091 remote_buffer_add_int (&p
, &left
, offset
);
10093 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10094 remote_errno
, &attachment
,
10100 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10102 if (read_len
!= ret
)
10103 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10108 /* Close FD on the remote target. Return 0, or -1 if an error occurs
10109 (and set *REMOTE_ERRNO). */
10112 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10114 struct remote_state
*rs
= get_remote_state ();
10116 int left
= get_remote_packet_size () - 1;
10118 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10120 remote_buffer_add_int (&p
, &left
, fd
);
10122 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10123 remote_errno
, NULL
, NULL
);
10126 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
10127 occurs (and set *REMOTE_ERRNO). */
10130 remote_hostio_unlink (struct target_ops
*self
,
10131 const char *filename
, int *remote_errno
)
10133 struct remote_state
*rs
= get_remote_state ();
10135 int left
= get_remote_packet_size () - 1;
10137 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10139 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10140 strlen (filename
));
10142 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10143 remote_errno
, NULL
, NULL
);
10146 /* Read value of symbolic link FILENAME on the remote target. Return
10147 a null-terminated string allocated via xmalloc, or NULL if an error
10148 occurs (and set *REMOTE_ERRNO). */
10151 remote_hostio_readlink (struct target_ops
*self
,
10152 const char *filename
, int *remote_errno
)
10154 struct remote_state
*rs
= get_remote_state ();
10157 int left
= get_remote_packet_size ();
10158 int len
, attachment_len
;
10162 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10164 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10165 strlen (filename
));
10167 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10168 remote_errno
, &attachment
,
10174 ret
= xmalloc (len
+ 1);
10176 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10177 (gdb_byte
*) ret
, len
);
10178 if (read_len
!= len
)
10179 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10185 /* Read information about the open file FD on the remote target
10186 into ST. Return 0 on success, or -1 if an error occurs (and
10187 set *REMOTE_ERRNO). */
10190 remote_hostio_fstat (struct target_ops
*self
,
10191 int fd
, struct stat
*st
,
10194 struct remote_state
*rs
= get_remote_state ();
10196 int left
= get_remote_packet_size ();
10197 int attachment_len
, ret
;
10199 struct fio_stat fst
;
10202 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10204 remote_buffer_add_int (&p
, &left
, fd
);
10206 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10207 remote_errno
, &attachment
,
10211 if (*remote_errno
!= FILEIO_ENOSYS
)
10214 /* Strictly we should return -1, ENOSYS here, but when
10215 "set sysroot remote:" was implemented in August 2008
10216 BFD's need for a stat function was sidestepped with
10217 this hack. This was not remedied until March 2015
10218 so we retain the previous behavior to avoid breaking
10221 Note that the memset is a March 2015 addition; older
10222 GDBs set st_size *and nothing else* so the structure
10223 would have garbage in all other fields. This might
10224 break something but retaining the previous behavior
10225 here would be just too wrong. */
10227 memset (st
, 0, sizeof (struct stat
));
10228 st
->st_size
= INT_MAX
;
10232 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10233 (gdb_byte
*) &fst
, sizeof (fst
));
10235 if (read_len
!= ret
)
10236 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10238 if (read_len
!= sizeof (fst
))
10239 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10240 read_len
, (int) sizeof (fst
));
10242 remote_fileio_to_host_stat (&fst
, st
);
10248 remote_fileio_errno_to_host (int errnum
)
10254 case FILEIO_ENOENT
:
10262 case FILEIO_EACCES
:
10264 case FILEIO_EFAULT
:
10268 case FILEIO_EEXIST
:
10270 case FILEIO_ENODEV
:
10272 case FILEIO_ENOTDIR
:
10274 case FILEIO_EISDIR
:
10276 case FILEIO_EINVAL
:
10278 case FILEIO_ENFILE
:
10280 case FILEIO_EMFILE
:
10284 case FILEIO_ENOSPC
:
10286 case FILEIO_ESPIPE
:
10290 case FILEIO_ENOSYS
:
10292 case FILEIO_ENAMETOOLONG
:
10293 return ENAMETOOLONG
;
10299 remote_hostio_error (int errnum
)
10301 int host_error
= remote_fileio_errno_to_host (errnum
);
10303 if (host_error
== -1)
10304 error (_("Unknown remote I/O error %d"), errnum
);
10306 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10310 remote_hostio_close_cleanup (void *opaque
)
10312 int fd
= *(int *) opaque
;
10315 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10319 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10321 struct cleanup
*back_to
, *close_cleanup
;
10322 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10325 int bytes_in_buffer
;
10328 struct remote_state
*rs
= get_remote_state ();
10330 if (!rs
->remote_desc
)
10331 error (_("command can only be used with remote target"));
10333 file
= gdb_fopen_cloexec (local_file
, "rb");
10335 perror_with_name (local_file
);
10336 back_to
= make_cleanup_fclose (file
);
10338 fd
= remote_hostio_open (find_target_at (process_stratum
),
10339 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10341 0700, &remote_errno
);
10343 remote_hostio_error (remote_errno
);
10345 /* Send up to this many bytes at once. They won't all fit in the
10346 remote packet limit, so we'll transfer slightly fewer. */
10347 io_size
= get_remote_packet_size ();
10348 buffer
= xmalloc (io_size
);
10349 make_cleanup (xfree
, buffer
);
10351 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10353 bytes_in_buffer
= 0;
10356 while (bytes_in_buffer
|| !saw_eof
)
10360 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10361 io_size
- bytes_in_buffer
,
10366 error (_("Error reading %s."), local_file
);
10369 /* EOF. Unless there is something still in the
10370 buffer from the last iteration, we are done. */
10372 if (bytes_in_buffer
== 0)
10380 bytes
+= bytes_in_buffer
;
10381 bytes_in_buffer
= 0;
10383 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10385 offset
, &remote_errno
);
10388 remote_hostio_error (remote_errno
);
10389 else if (retcode
== 0)
10390 error (_("Remote write of %d bytes returned 0!"), bytes
);
10391 else if (retcode
< bytes
)
10393 /* Short write. Save the rest of the read data for the next
10395 bytes_in_buffer
= bytes
- retcode
;
10396 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10402 discard_cleanups (close_cleanup
);
10403 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10404 remote_hostio_error (remote_errno
);
10407 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10408 do_cleanups (back_to
);
10412 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10414 struct cleanup
*back_to
, *close_cleanup
;
10415 int fd
, remote_errno
, bytes
, io_size
;
10419 struct remote_state
*rs
= get_remote_state ();
10421 if (!rs
->remote_desc
)
10422 error (_("command can only be used with remote target"));
10424 fd
= remote_hostio_open (find_target_at (process_stratum
),
10425 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10427 remote_hostio_error (remote_errno
);
10429 file
= gdb_fopen_cloexec (local_file
, "wb");
10431 perror_with_name (local_file
);
10432 back_to
= make_cleanup_fclose (file
);
10434 /* Send up to this many bytes at once. They won't all fit in the
10435 remote packet limit, so we'll transfer slightly fewer. */
10436 io_size
= get_remote_packet_size ();
10437 buffer
= xmalloc (io_size
);
10438 make_cleanup (xfree
, buffer
);
10440 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10445 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10446 fd
, buffer
, io_size
, offset
, &remote_errno
);
10448 /* Success, but no bytes, means end-of-file. */
10451 remote_hostio_error (remote_errno
);
10455 bytes
= fwrite (buffer
, 1, bytes
, file
);
10457 perror_with_name (local_file
);
10460 discard_cleanups (close_cleanup
);
10461 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10462 remote_hostio_error (remote_errno
);
10465 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10466 do_cleanups (back_to
);
10470 remote_file_delete (const char *remote_file
, int from_tty
)
10472 int retcode
, remote_errno
;
10473 struct remote_state
*rs
= get_remote_state ();
10475 if (!rs
->remote_desc
)
10476 error (_("command can only be used with remote target"));
10478 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10479 remote_file
, &remote_errno
);
10481 remote_hostio_error (remote_errno
);
10484 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10488 remote_put_command (char *args
, int from_tty
)
10490 struct cleanup
*back_to
;
10494 error_no_arg (_("file to put"));
10496 argv
= gdb_buildargv (args
);
10497 back_to
= make_cleanup_freeargv (argv
);
10498 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10499 error (_("Invalid parameters to remote put"));
10501 remote_file_put (argv
[0], argv
[1], from_tty
);
10503 do_cleanups (back_to
);
10507 remote_get_command (char *args
, int from_tty
)
10509 struct cleanup
*back_to
;
10513 error_no_arg (_("file to get"));
10515 argv
= gdb_buildargv (args
);
10516 back_to
= make_cleanup_freeargv (argv
);
10517 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10518 error (_("Invalid parameters to remote get"));
10520 remote_file_get (argv
[0], argv
[1], from_tty
);
10522 do_cleanups (back_to
);
10526 remote_delete_command (char *args
, int from_tty
)
10528 struct cleanup
*back_to
;
10532 error_no_arg (_("file to delete"));
10534 argv
= gdb_buildargv (args
);
10535 back_to
= make_cleanup_freeargv (argv
);
10536 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10537 error (_("Invalid parameters to remote delete"));
10539 remote_file_delete (argv
[0], from_tty
);
10541 do_cleanups (back_to
);
10545 remote_command (char *args
, int from_tty
)
10547 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10551 remote_can_execute_reverse (struct target_ops
*self
)
10553 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10554 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10561 remote_supports_non_stop (struct target_ops
*self
)
10567 remote_supports_disable_randomization (struct target_ops
*self
)
10569 /* Only supported in extended mode. */
10574 remote_supports_multi_process (struct target_ops
*self
)
10576 struct remote_state
*rs
= get_remote_state ();
10578 /* Only extended-remote handles being attached to multiple
10579 processes, even though plain remote can use the multi-process
10580 thread id extensions, so that GDB knows the target process's
10582 return rs
->extended
&& remote_multi_process_p (rs
);
10586 remote_supports_cond_tracepoints (void)
10588 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10592 remote_supports_cond_breakpoints (struct target_ops
*self
)
10594 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10598 remote_supports_fast_tracepoints (void)
10600 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
10604 remote_supports_static_tracepoints (void)
10606 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
10610 remote_supports_install_in_trace (void)
10612 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
10616 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
10618 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
10623 remote_supports_string_tracing (struct target_ops
*self
)
10625 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
10629 remote_can_run_breakpoint_commands (struct target_ops
*self
)
10631 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
10635 remote_trace_init (struct target_ops
*self
)
10638 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10639 if (strcmp (target_buf
, "OK") != 0)
10640 error (_("Target does not support this command."));
10643 static void free_actions_list (char **actions_list
);
10644 static void free_actions_list_cleanup_wrapper (void *);
10646 free_actions_list_cleanup_wrapper (void *al
)
10648 free_actions_list (al
);
10652 free_actions_list (char **actions_list
)
10656 if (actions_list
== 0)
10659 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10660 xfree (actions_list
[ndx
]);
10662 xfree (actions_list
);
10665 /* Recursive routine to walk through command list including loops, and
10666 download packets for each command. */
10669 remote_download_command_source (int num
, ULONGEST addr
,
10670 struct command_line
*cmds
)
10672 struct remote_state
*rs
= get_remote_state ();
10673 struct command_line
*cmd
;
10675 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10677 QUIT
; /* Allow user to bail out with ^C. */
10678 strcpy (rs
->buf
, "QTDPsrc:");
10679 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10680 rs
->buf
+ strlen (rs
->buf
),
10681 rs
->buf_size
- strlen (rs
->buf
));
10683 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10684 if (strcmp (target_buf
, "OK"))
10685 warning (_("Target does not support source download."));
10687 if (cmd
->control_type
== while_control
10688 || cmd
->control_type
== while_stepping_control
)
10690 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10692 QUIT
; /* Allow user to bail out with ^C. */
10693 strcpy (rs
->buf
, "QTDPsrc:");
10694 encode_source_string (num
, addr
, "cmd", "end",
10695 rs
->buf
+ strlen (rs
->buf
),
10696 rs
->buf_size
- strlen (rs
->buf
));
10698 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10699 if (strcmp (target_buf
, "OK"))
10700 warning (_("Target does not support source download."));
10706 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
10708 #define BUF_SIZE 2048
10712 char buf
[BUF_SIZE
];
10713 char **tdp_actions
;
10714 char **stepping_actions
;
10716 struct cleanup
*old_chain
= NULL
;
10717 struct agent_expr
*aexpr
;
10718 struct cleanup
*aexpr_chain
= NULL
;
10720 struct breakpoint
*b
= loc
->owner
;
10721 struct tracepoint
*t
= (struct tracepoint
*) b
;
10723 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10724 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10726 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10729 tpaddr
= loc
->address
;
10730 sprintf_vma (addrbuf
, tpaddr
);
10731 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10732 addrbuf
, /* address */
10733 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10734 t
->step_count
, t
->pass_count
);
10735 /* Fast tracepoints are mostly handled by the target, but we can
10736 tell the target how big of an instruction block should be moved
10738 if (b
->type
== bp_fast_tracepoint
)
10740 /* Only test for support at download time; we may not know
10741 target capabilities at definition time. */
10742 if (remote_supports_fast_tracepoints ())
10746 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10747 tpaddr
, &isize
, NULL
))
10748 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10751 /* If it passed validation at definition but fails now,
10752 something is very wrong. */
10753 internal_error (__FILE__
, __LINE__
,
10754 _("Fast tracepoint not "
10755 "valid during download"));
10758 /* Fast tracepoints are functionally identical to regular
10759 tracepoints, so don't take lack of support as a reason to
10760 give up on the trace run. */
10761 warning (_("Target does not support fast tracepoints, "
10762 "downloading %d as regular tracepoint"), b
->number
);
10764 else if (b
->type
== bp_static_tracepoint
)
10766 /* Only test for support at download time; we may not know
10767 target capabilities at definition time. */
10768 if (remote_supports_static_tracepoints ())
10770 struct static_tracepoint_marker marker
;
10772 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10773 strcat (buf
, ":S");
10775 error (_("Static tracepoint not valid during download"));
10778 /* Fast tracepoints are functionally identical to regular
10779 tracepoints, so don't take lack of support as a reason
10780 to give up on the trace run. */
10781 error (_("Target does not support static tracepoints"));
10783 /* If the tracepoint has a conditional, make it into an agent
10784 expression and append to the definition. */
10787 /* Only test support at download time, we may not know target
10788 capabilities at definition time. */
10789 if (remote_supports_cond_tracepoints ())
10791 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10792 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10793 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10795 pkt
= buf
+ strlen (buf
);
10796 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10797 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10799 do_cleanups (aexpr_chain
);
10802 warning (_("Target does not support conditional tracepoints, "
10803 "ignoring tp %d cond"), b
->number
);
10806 if (b
->commands
|| *default_collect
)
10809 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10810 if (strcmp (target_buf
, "OK"))
10811 error (_("Target does not support tracepoints."));
10813 /* do_single_steps (t); */
10816 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10818 QUIT
; /* Allow user to bail out with ^C. */
10819 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10820 b
->number
, addrbuf
, /* address */
10822 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10825 remote_get_noisy_reply (&target_buf
,
10827 if (strcmp (target_buf
, "OK"))
10828 error (_("Error on target while setting tracepoints."));
10831 if (stepping_actions
)
10833 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10835 QUIT
; /* Allow user to bail out with ^C. */
10836 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10837 b
->number
, addrbuf
, /* address */
10838 ((ndx
== 0) ? "S" : ""),
10839 stepping_actions
[ndx
],
10840 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10842 remote_get_noisy_reply (&target_buf
,
10844 if (strcmp (target_buf
, "OK"))
10845 error (_("Error on target while setting tracepoints."));
10849 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
10851 if (b
->addr_string
)
10853 strcpy (buf
, "QTDPsrc:");
10854 encode_source_string (b
->number
, loc
->address
,
10855 "at", b
->addr_string
, buf
+ strlen (buf
),
10856 2048 - strlen (buf
));
10859 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10860 if (strcmp (target_buf
, "OK"))
10861 warning (_("Target does not support source download."));
10863 if (b
->cond_string
)
10865 strcpy (buf
, "QTDPsrc:");
10866 encode_source_string (b
->number
, loc
->address
,
10867 "cond", b
->cond_string
, buf
+ strlen (buf
),
10868 2048 - strlen (buf
));
10870 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10871 if (strcmp (target_buf
, "OK"))
10872 warning (_("Target does not support source download."));
10874 remote_download_command_source (b
->number
, loc
->address
,
10875 breakpoint_commands (b
));
10878 do_cleanups (old_chain
);
10882 remote_can_download_tracepoint (struct target_ops
*self
)
10884 struct remote_state
*rs
= get_remote_state ();
10885 struct trace_status
*ts
;
10888 /* Don't try to install tracepoints until we've relocated our
10889 symbols, and fetched and merged the target's tracepoint list with
10891 if (rs
->starting_up
)
10894 ts
= current_trace_status ();
10895 status
= remote_get_trace_status (self
, ts
);
10897 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10900 /* If we are in a tracing experiment, but remote stub doesn't support
10901 installing tracepoint in trace, we have to return. */
10902 if (!remote_supports_install_in_trace ())
10910 remote_download_trace_state_variable (struct target_ops
*self
,
10911 struct trace_state_variable
*tsv
)
10913 struct remote_state
*rs
= get_remote_state ();
10916 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10917 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10919 p
= rs
->buf
+ strlen (rs
->buf
);
10920 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10921 error (_("Trace state variable name too long for tsv definition packet"));
10922 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
10925 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10926 if (*target_buf
== '\0')
10927 error (_("Target does not support this command."));
10928 if (strcmp (target_buf
, "OK") != 0)
10929 error (_("Error on target while downloading trace state variable."));
10933 remote_enable_tracepoint (struct target_ops
*self
,
10934 struct bp_location
*location
)
10936 struct remote_state
*rs
= get_remote_state ();
10939 sprintf_vma (addr_buf
, location
->address
);
10940 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10941 location
->owner
->number
, addr_buf
);
10943 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10944 if (*rs
->buf
== '\0')
10945 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10946 if (strcmp (rs
->buf
, "OK") != 0)
10947 error (_("Error on target while enabling tracepoint."));
10951 remote_disable_tracepoint (struct target_ops
*self
,
10952 struct bp_location
*location
)
10954 struct remote_state
*rs
= get_remote_state ();
10957 sprintf_vma (addr_buf
, location
->address
);
10958 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10959 location
->owner
->number
, addr_buf
);
10961 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10962 if (*rs
->buf
== '\0')
10963 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10964 if (strcmp (rs
->buf
, "OK") != 0)
10965 error (_("Error on target while disabling tracepoint."));
10969 remote_trace_set_readonly_regions (struct target_ops
*self
)
10973 bfd_size_type size
;
10979 return; /* No information to give. */
10981 strcpy (target_buf
, "QTro");
10982 offset
= strlen (target_buf
);
10983 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10985 char tmp1
[40], tmp2
[40];
10988 if ((s
->flags
& SEC_LOAD
) == 0 ||
10989 /* (s->flags & SEC_CODE) == 0 || */
10990 (s
->flags
& SEC_READONLY
) == 0)
10994 vma
= bfd_get_section_vma (abfd
, s
);
10995 size
= bfd_get_section_size (s
);
10996 sprintf_vma (tmp1
, vma
);
10997 sprintf_vma (tmp2
, vma
+ size
);
10998 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10999 if (offset
+ sec_length
+ 1 > target_buf_size
)
11001 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11003 Too many sections for read-only sections definition packet."));
11006 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11008 offset
+= sec_length
;
11012 putpkt (target_buf
);
11013 getpkt (&target_buf
, &target_buf_size
, 0);
11018 remote_trace_start (struct target_ops
*self
)
11020 putpkt ("QTStart");
11021 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11022 if (*target_buf
== '\0')
11023 error (_("Target does not support this command."));
11024 if (strcmp (target_buf
, "OK") != 0)
11025 error (_("Bogus reply from target: %s"), target_buf
);
11029 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11031 /* Initialize it just to avoid a GCC false warning. */
11033 /* FIXME we need to get register block size some other way. */
11034 extern int trace_regblock_size
;
11035 enum packet_result result
;
11037 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11040 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11042 putpkt ("qTStatus");
11046 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11048 CATCH (ex
, RETURN_MASK_ERROR
)
11050 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11052 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11055 throw_exception (ex
);
11059 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11061 /* If the remote target doesn't do tracing, flag it. */
11062 if (result
== PACKET_UNKNOWN
)
11065 /* We're working with a live target. */
11066 ts
->filename
= NULL
;
11069 error (_("Bogus trace status reply from target: %s"), target_buf
);
11071 /* Function 'parse_trace_status' sets default value of each field of
11072 'ts' at first, so we don't have to do it here. */
11073 parse_trace_status (p
, ts
);
11075 return ts
->running
;
11079 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11080 struct uploaded_tp
*utp
)
11082 struct remote_state
*rs
= get_remote_state ();
11084 struct bp_location
*loc
;
11085 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11086 size_t size
= get_remote_packet_size ();
11090 tp
->base
.hit_count
= 0;
11091 tp
->traceframe_usage
= 0;
11092 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11094 /* If the tracepoint was never downloaded, don't go asking for
11096 if (tp
->number_on_target
== 0)
11098 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11099 phex_nz (loc
->address
, 0));
11101 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11102 if (reply
&& *reply
)
11105 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11111 utp
->hit_count
= 0;
11112 utp
->traceframe_usage
= 0;
11113 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11114 phex_nz (utp
->addr
, 0));
11116 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11117 if (reply
&& *reply
)
11120 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11126 remote_trace_stop (struct target_ops
*self
)
11129 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11130 if (*target_buf
== '\0')
11131 error (_("Target does not support this command."));
11132 if (strcmp (target_buf
, "OK") != 0)
11133 error (_("Bogus reply from target: %s"), target_buf
);
11137 remote_trace_find (struct target_ops
*self
,
11138 enum trace_find_type type
, int num
,
11139 CORE_ADDR addr1
, CORE_ADDR addr2
,
11142 struct remote_state
*rs
= get_remote_state ();
11143 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11145 int target_frameno
= -1, target_tracept
= -1;
11147 /* Lookups other than by absolute frame number depend on the current
11148 trace selected, so make sure it is correct on the remote end
11150 if (type
!= tfind_number
)
11151 set_remote_traceframe ();
11154 strcpy (p
, "QTFrame:");
11155 p
= strchr (p
, '\0');
11159 xsnprintf (p
, endbuf
- p
, "%x", num
);
11162 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11165 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11168 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11169 phex_nz (addr2
, 0));
11171 case tfind_outside
:
11172 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11173 phex_nz (addr2
, 0));
11176 error (_("Unknown trace find type %d"), type
);
11180 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11181 if (*reply
== '\0')
11182 error (_("Target does not support this command."));
11184 while (reply
&& *reply
)
11189 target_frameno
= (int) strtol (p
, &reply
, 16);
11191 error (_("Unable to parse trace frame number"));
11192 /* Don't update our remote traceframe number cache on failure
11193 to select a remote traceframe. */
11194 if (target_frameno
== -1)
11199 target_tracept
= (int) strtol (p
, &reply
, 16);
11201 error (_("Unable to parse tracepoint number"));
11203 case 'O': /* "OK"? */
11204 if (reply
[1] == 'K' && reply
[2] == '\0')
11207 error (_("Bogus reply from target: %s"), reply
);
11210 error (_("Bogus reply from target: %s"), reply
);
11213 *tpp
= target_tracept
;
11215 rs
->remote_traceframe_number
= target_frameno
;
11216 return target_frameno
;
11220 remote_get_trace_state_variable_value (struct target_ops
*self
,
11221 int tsvnum
, LONGEST
*val
)
11223 struct remote_state
*rs
= get_remote_state ();
11227 set_remote_traceframe ();
11229 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11231 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11232 if (reply
&& *reply
)
11236 unpack_varlen_hex (reply
+ 1, &uval
);
11237 *val
= (LONGEST
) uval
;
11245 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11247 struct remote_state
*rs
= get_remote_state ();
11251 strcpy (p
, "QTSave:");
11253 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11254 error (_("Remote file name too long for trace save packet"));
11255 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11258 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11259 if (*reply
== '\0')
11260 error (_("Target does not support this command."));
11261 if (strcmp (reply
, "OK") != 0)
11262 error (_("Bogus reply from target: %s"), reply
);
11266 /* This is basically a memory transfer, but needs to be its own packet
11267 because we don't know how the target actually organizes its trace
11268 memory, plus we want to be able to ask for as much as possible, but
11269 not be unhappy if we don't get as much as we ask for. */
11272 remote_get_raw_trace_data (struct target_ops
*self
,
11273 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11275 struct remote_state
*rs
= get_remote_state ();
11281 strcpy (p
, "qTBuffer:");
11283 p
+= hexnumstr (p
, offset
);
11285 p
+= hexnumstr (p
, len
);
11289 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11290 if (reply
&& *reply
)
11292 /* 'l' by itself means we're at the end of the buffer and
11293 there is nothing more to get. */
11297 /* Convert the reply into binary. Limit the number of bytes to
11298 convert according to our passed-in buffer size, rather than
11299 what was returned in the packet; if the target is
11300 unexpectedly generous and gives us a bigger reply than we
11301 asked for, we don't want to crash. */
11302 rslt
= hex2bin (target_buf
, buf
, len
);
11306 /* Something went wrong, flag as an error. */
11311 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11313 struct remote_state
*rs
= get_remote_state ();
11315 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11319 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11321 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11322 if (*reply
== '\0')
11323 error (_("Target does not support this command."));
11324 if (strcmp (reply
, "OK") != 0)
11325 error (_("Bogus reply from target: %s"), reply
);
11328 warning (_("Target does not support disconnected tracing."));
11332 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11334 struct thread_info
*info
= find_thread_ptid (ptid
);
11336 if (info
&& info
->priv
)
11337 return info
->priv
->core
;
11342 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11344 struct remote_state
*rs
= get_remote_state ();
11347 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11349 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11350 if (*reply
== '\0')
11351 error (_("Target does not support this command."));
11352 if (strcmp (reply
, "OK") != 0)
11353 error (_("Bogus reply from target: %s"), reply
);
11356 static struct traceframe_info
*
11357 remote_traceframe_info (struct target_ops
*self
)
11361 text
= target_read_stralloc (¤t_target
,
11362 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11365 struct traceframe_info
*info
;
11366 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11368 info
= parse_traceframe_info (text
);
11369 do_cleanups (back_to
);
11376 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11377 instruction on which a fast tracepoint may be placed. Returns -1
11378 if the packet is not supported, and 0 if the minimum instruction
11379 length is unknown. */
11382 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11384 struct remote_state
*rs
= get_remote_state ();
11387 /* If we're not debugging a process yet, the IPA can't be
11389 if (!target_has_execution
)
11392 /* Make sure the remote is pointing at the right process. */
11393 set_general_process ();
11395 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11397 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11398 if (*reply
== '\0')
11402 ULONGEST min_insn_len
;
11404 unpack_varlen_hex (reply
, &min_insn_len
);
11406 return (int) min_insn_len
;
11411 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11413 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11415 struct remote_state
*rs
= get_remote_state ();
11416 char *buf
= rs
->buf
;
11417 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11418 enum packet_result result
;
11420 gdb_assert (val
>= 0 || val
== -1);
11421 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11422 /* Send -1 as literal "-1" to avoid host size dependency. */
11426 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11429 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11432 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11433 result
= packet_ok (rs
->buf
,
11434 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11436 if (result
!= PACKET_OK
)
11437 warning (_("Bogus reply from target: %s"), rs
->buf
);
11442 remote_set_trace_notes (struct target_ops
*self
,
11443 const char *user
, const char *notes
,
11444 const char *stop_notes
)
11446 struct remote_state
*rs
= get_remote_state ();
11448 char *buf
= rs
->buf
;
11449 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11452 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11455 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11456 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11462 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11463 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11469 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11470 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11474 /* Ensure the buffer is terminated. */
11478 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11479 if (*reply
== '\0')
11482 if (strcmp (reply
, "OK") != 0)
11483 error (_("Bogus reply from target: %s"), reply
);
11489 remote_use_agent (struct target_ops
*self
, int use
)
11491 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11493 struct remote_state
*rs
= get_remote_state ();
11495 /* If the stub supports QAgent. */
11496 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11498 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11500 if (strcmp (rs
->buf
, "OK") == 0)
11511 remote_can_use_agent (struct target_ops
*self
)
11513 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11516 struct btrace_target_info
11518 /* The ptid of the traced thread. */
11521 /* The obtained branch trace configuration. */
11522 struct btrace_config conf
;
11525 /* Reset our idea of our target's btrace configuration. */
11528 remote_btrace_reset (void)
11530 struct remote_state
*rs
= get_remote_state ();
11532 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
11535 /* Check whether the target supports branch tracing. */
11538 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
11540 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11542 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11547 case BTRACE_FORMAT_NONE
:
11550 case BTRACE_FORMAT_BTS
:
11551 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
11554 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
11557 /* Synchronize the configuration with the target. */
11560 btrace_sync_conf (const struct btrace_config
*conf
)
11562 struct packet_config
*packet
;
11563 struct remote_state
*rs
;
11564 char *buf
, *pos
, *endbuf
;
11566 rs
= get_remote_state ();
11568 endbuf
= buf
+ get_remote_packet_size ();
11570 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
11571 if (packet_config_support (packet
) == PACKET_ENABLE
11572 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
11575 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11579 getpkt (&buf
, &rs
->buf_size
, 0);
11581 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11583 if (buf
[0] == 'E' && buf
[1] == '.')
11584 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
11586 error (_("Failed to configure the BTS buffer size."));
11589 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
11593 /* Read the current thread's btrace configuration from the target and
11594 store it into CONF. */
11597 btrace_read_config (struct btrace_config
*conf
)
11601 xml
= target_read_stralloc (¤t_target
,
11602 TARGET_OBJECT_BTRACE_CONF
, "");
11605 struct cleanup
*cleanup
;
11607 cleanup
= make_cleanup (xfree
, xml
);
11608 parse_xml_btrace_conf (conf
, xml
);
11609 do_cleanups (cleanup
);
11613 /* Enable branch tracing. */
11615 static struct btrace_target_info
*
11616 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
11617 const struct btrace_config
*conf
)
11619 struct btrace_target_info
*tinfo
= NULL
;
11620 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11621 struct remote_state
*rs
= get_remote_state ();
11622 char *buf
= rs
->buf
;
11623 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11625 if (packet_config_support (packet
) != PACKET_ENABLE
)
11626 error (_("Target does not support branch tracing."));
11628 btrace_sync_conf (conf
);
11630 set_general_thread (ptid
);
11632 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11634 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11636 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11638 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11639 error (_("Could not enable branch tracing for %s: %s"),
11640 target_pid_to_str (ptid
), rs
->buf
+ 2);
11642 error (_("Could not enable branch tracing for %s."),
11643 target_pid_to_str (ptid
));
11646 tinfo
= xzalloc (sizeof (*tinfo
));
11647 tinfo
->ptid
= ptid
;
11649 /* If we fail to read the configuration, we lose some information, but the
11650 tracing itself is not impacted. */
11653 btrace_read_config (&tinfo
->conf
);
11655 CATCH (err
, RETURN_MASK_ERROR
)
11657 if (err
.message
!= NULL
)
11658 warning ("%s", err
.message
);
11665 /* Disable branch tracing. */
11668 remote_disable_btrace (struct target_ops
*self
,
11669 struct btrace_target_info
*tinfo
)
11671 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11672 struct remote_state
*rs
= get_remote_state ();
11673 char *buf
= rs
->buf
;
11674 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11676 if (packet_config_support (packet
) != PACKET_ENABLE
)
11677 error (_("Target does not support branch tracing."));
11679 set_general_thread (tinfo
->ptid
);
11681 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11685 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11687 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11688 error (_("Could not disable branch tracing for %s: %s"),
11689 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11691 error (_("Could not disable branch tracing for %s."),
11692 target_pid_to_str (tinfo
->ptid
));
11698 /* Teardown branch tracing. */
11701 remote_teardown_btrace (struct target_ops
*self
,
11702 struct btrace_target_info
*tinfo
)
11704 /* We must not talk to the target during teardown. */
11708 /* Read the branch trace. */
11710 static enum btrace_error
11711 remote_read_btrace (struct target_ops
*self
,
11712 struct btrace_data
*btrace
,
11713 struct btrace_target_info
*tinfo
,
11714 enum btrace_read_type type
)
11716 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11717 struct remote_state
*rs
= get_remote_state ();
11718 struct cleanup
*cleanup
;
11722 if (packet_config_support (packet
) != PACKET_ENABLE
)
11723 error (_("Target does not support branch tracing."));
11725 #if !defined(HAVE_LIBEXPAT)
11726 error (_("Cannot process branch tracing result. XML parsing not supported."));
11731 case BTRACE_READ_ALL
:
11734 case BTRACE_READ_NEW
:
11737 case BTRACE_READ_DELTA
:
11741 internal_error (__FILE__
, __LINE__
,
11742 _("Bad branch tracing read type: %u."),
11743 (unsigned int) type
);
11746 xml
= target_read_stralloc (¤t_target
,
11747 TARGET_OBJECT_BTRACE
, annex
);
11749 return BTRACE_ERR_UNKNOWN
;
11751 cleanup
= make_cleanup (xfree
, xml
);
11752 parse_xml_btrace (btrace
, xml
);
11753 do_cleanups (cleanup
);
11755 return BTRACE_ERR_NONE
;
11758 static const struct btrace_config
*
11759 remote_btrace_conf (struct target_ops
*self
,
11760 const struct btrace_target_info
*tinfo
)
11762 return &tinfo
->conf
;
11766 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
11768 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
11772 /* Implementation of to_load. */
11775 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
11777 generic_load (name
, from_tty
);
11780 /* Accepts an integer PID; returns a string representing a file that
11781 can be opened on the remote side to get the symbols for the child
11782 process. Returns NULL if the operation is not supported. */
11785 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
11787 static char *filename
= NULL
;
11788 struct inferior
*inf
;
11789 char *annex
= NULL
;
11791 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
11794 if (filename
!= NULL
)
11797 inf
= find_inferior_pid (pid
);
11799 internal_error (__FILE__
, __LINE__
,
11800 _("not currently attached to process %d"), pid
);
11802 if (!inf
->fake_pid_p
)
11804 const int annex_size
= 9;
11806 annex
= alloca (annex_size
);
11807 xsnprintf (annex
, annex_size
, "%x", pid
);
11810 filename
= target_read_stralloc (¤t_target
,
11811 TARGET_OBJECT_EXEC_FILE
, annex
);
11817 init_remote_ops (void)
11819 remote_ops
.to_shortname
= "remote";
11820 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11821 remote_ops
.to_doc
=
11822 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11823 Specify the serial device it is connected to\n\
11824 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11825 remote_ops
.to_open
= remote_open
;
11826 remote_ops
.to_close
= remote_close
;
11827 remote_ops
.to_detach
= remote_detach
;
11828 remote_ops
.to_disconnect
= remote_disconnect
;
11829 remote_ops
.to_resume
= remote_resume
;
11830 remote_ops
.to_wait
= remote_wait
;
11831 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11832 remote_ops
.to_store_registers
= remote_store_registers
;
11833 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11834 remote_ops
.to_files_info
= remote_files_info
;
11835 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11836 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11837 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
11838 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
11839 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
11840 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
11841 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11842 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11843 remote_ops
.to_watchpoint_addr_within_range
=
11844 remote_watchpoint_addr_within_range
;
11845 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11846 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11847 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11848 remote_ops
.to_region_ok_for_hw_watchpoint
11849 = remote_region_ok_for_hw_watchpoint
;
11850 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11851 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11852 remote_ops
.to_kill
= remote_kill
;
11853 remote_ops
.to_load
= remote_load
;
11854 remote_ops
.to_mourn_inferior
= remote_mourn
;
11855 remote_ops
.to_pass_signals
= remote_pass_signals
;
11856 remote_ops
.to_program_signals
= remote_program_signals
;
11857 remote_ops
.to_thread_alive
= remote_thread_alive
;
11858 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
11859 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11860 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11861 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11862 remote_ops
.to_stop
= remote_stop
;
11863 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11864 remote_ops
.to_rcmd
= remote_rcmd
;
11865 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
11866 remote_ops
.to_log_command
= serial_log_command
;
11867 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11868 remote_ops
.to_stratum
= process_stratum
;
11869 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11870 remote_ops
.to_has_memory
= default_child_has_memory
;
11871 remote_ops
.to_has_stack
= default_child_has_stack
;
11872 remote_ops
.to_has_registers
= default_child_has_registers
;
11873 remote_ops
.to_has_execution
= default_child_has_execution
;
11874 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11875 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11876 remote_ops
.to_magic
= OPS_MAGIC
;
11877 remote_ops
.to_memory_map
= remote_memory_map
;
11878 remote_ops
.to_flash_erase
= remote_flash_erase
;
11879 remote_ops
.to_flash_done
= remote_flash_done
;
11880 remote_ops
.to_read_description
= remote_read_description
;
11881 remote_ops
.to_search_memory
= remote_search_memory
;
11882 remote_ops
.to_can_async_p
= remote_can_async_p
;
11883 remote_ops
.to_is_async_p
= remote_is_async_p
;
11884 remote_ops
.to_async
= remote_async
;
11885 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11886 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11887 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11888 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11889 remote_ops
.to_supports_disable_randomization
11890 = remote_supports_disable_randomization
;
11891 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
11892 remote_ops
.to_fileio_open
= remote_hostio_open
;
11893 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11894 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11895 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
11896 remote_ops
.to_fileio_close
= remote_hostio_close
;
11897 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11898 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11899 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11900 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11901 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11902 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11903 remote_ops
.to_trace_init
= remote_trace_init
;
11904 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11905 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11906 remote_ops
.to_download_trace_state_variable
11907 = remote_download_trace_state_variable
;
11908 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11909 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11910 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11911 remote_ops
.to_trace_start
= remote_trace_start
;
11912 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11913 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11914 remote_ops
.to_trace_stop
= remote_trace_stop
;
11915 remote_ops
.to_trace_find
= remote_trace_find
;
11916 remote_ops
.to_get_trace_state_variable_value
11917 = remote_get_trace_state_variable_value
;
11918 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11919 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11920 remote_ops
.to_upload_trace_state_variables
11921 = remote_upload_trace_state_variables
;
11922 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11923 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11924 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11925 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11926 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11927 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11928 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11929 remote_ops
.to_verify_memory
= remote_verify_memory
;
11930 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11931 remote_ops
.to_set_permissions
= remote_set_permissions
;
11932 remote_ops
.to_static_tracepoint_marker_at
11933 = remote_static_tracepoint_marker_at
;
11934 remote_ops
.to_static_tracepoint_markers_by_strid
11935 = remote_static_tracepoint_markers_by_strid
;
11936 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11937 remote_ops
.to_use_agent
= remote_use_agent
;
11938 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11939 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11940 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11941 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11942 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11943 remote_ops
.to_read_btrace
= remote_read_btrace
;
11944 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
11945 remote_ops
.to_augmented_libraries_svr4_read
=
11946 remote_augmented_libraries_svr4_read
;
11949 /* Set up the extended remote vector by making a copy of the standard
11950 remote vector and adding to it. */
11953 init_extended_remote_ops (void)
11955 extended_remote_ops
= remote_ops
;
11957 extended_remote_ops
.to_shortname
= "extended-remote";
11958 extended_remote_ops
.to_longname
=
11959 "Extended remote serial target in gdb-specific protocol";
11960 extended_remote_ops
.to_doc
=
11961 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11962 Specify the serial device it is connected to (e.g. /dev/ttya).";
11963 extended_remote_ops
.to_open
= extended_remote_open
;
11964 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11965 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11966 extended_remote_ops
.to_detach
= extended_remote_detach
;
11967 extended_remote_ops
.to_attach
= extended_remote_attach
;
11968 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
11969 extended_remote_ops
.to_kill
= extended_remote_kill
;
11970 extended_remote_ops
.to_supports_disable_randomization
11971 = extended_remote_supports_disable_randomization
;
11972 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
11976 remote_can_async_p (struct target_ops
*ops
)
11978 struct remote_state
*rs
= get_remote_state ();
11980 if (!target_async_permitted
)
11981 /* We only enable async when the user specifically asks for it. */
11984 /* We're async whenever the serial device is. */
11985 return serial_can_async_p (rs
->remote_desc
);
11989 remote_is_async_p (struct target_ops
*ops
)
11991 struct remote_state
*rs
= get_remote_state ();
11993 if (!target_async_permitted
)
11994 /* We only enable async when the user specifically asks for it. */
11997 /* We're async whenever the serial device is. */
11998 return serial_is_async_p (rs
->remote_desc
);
12001 /* Pass the SERIAL event on and up to the client. One day this code
12002 will be able to delay notifying the client of an event until the
12003 point where an entire packet has been received. */
12005 static serial_event_ftype remote_async_serial_handler
;
12008 remote_async_serial_handler (struct serial
*scb
, void *context
)
12010 struct remote_state
*rs
= context
;
12012 /* Don't propogate error information up to the client. Instead let
12013 the client find out about the error by querying the target. */
12014 inferior_event_handler (INF_REG_EVENT
, NULL
);
12018 remote_async_inferior_event_handler (gdb_client_data data
)
12020 inferior_event_handler (INF_REG_EVENT
, NULL
);
12024 remote_async (struct target_ops
*ops
, int enable
)
12026 struct remote_state
*rs
= get_remote_state ();
12030 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12032 /* If there are pending events in the stop reply queue tell the
12033 event loop to process them. */
12034 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12035 mark_async_event_handler (remote_async_inferior_event_token
);
12039 serial_async (rs
->remote_desc
, NULL
, NULL
);
12040 clear_async_event_handler (remote_async_inferior_event_token
);
12045 set_remote_cmd (char *args
, int from_tty
)
12047 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12051 show_remote_cmd (char *args
, int from_tty
)
12053 /* We can't just use cmd_show_list here, because we want to skip
12054 the redundant "show remote Z-packet" and the legacy aliases. */
12055 struct cleanup
*showlist_chain
;
12056 struct cmd_list_element
*list
= remote_show_cmdlist
;
12057 struct ui_out
*uiout
= current_uiout
;
12059 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12060 for (; list
!= NULL
; list
= list
->next
)
12061 if (strcmp (list
->name
, "Z-packet") == 0)
12063 else if (list
->type
== not_set_cmd
)
12064 /* Alias commands are exactly like the original, except they
12065 don't have the normal type. */
12069 struct cleanup
*option_chain
12070 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12072 ui_out_field_string (uiout
, "name", list
->name
);
12073 ui_out_text (uiout
, ": ");
12074 if (list
->type
== show_cmd
)
12075 do_show_command ((char *) NULL
, from_tty
, list
);
12077 cmd_func (list
, NULL
, from_tty
);
12078 /* Close the tuple. */
12079 do_cleanups (option_chain
);
12082 /* Close the tuple. */
12083 do_cleanups (showlist_chain
);
12087 /* Function to be called whenever a new objfile (shlib) is detected. */
12089 remote_new_objfile (struct objfile
*objfile
)
12091 struct remote_state
*rs
= get_remote_state ();
12093 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12094 remote_check_symbols ();
12097 /* Pull all the tracepoints defined on the target and create local
12098 data structures representing them. We don't want to create real
12099 tracepoints yet, we don't want to mess up the user's existing
12103 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12105 struct remote_state
*rs
= get_remote_state ();
12108 /* Ask for a first packet of tracepoint definition. */
12110 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12112 while (*p
&& *p
!= 'l')
12114 parse_tracepoint_definition (p
, utpp
);
12115 /* Ask for another packet of tracepoint definition. */
12117 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12124 remote_upload_trace_state_variables (struct target_ops
*self
,
12125 struct uploaded_tsv
**utsvp
)
12127 struct remote_state
*rs
= get_remote_state ();
12130 /* Ask for a first packet of variable definition. */
12132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12134 while (*p
&& *p
!= 'l')
12136 parse_tsv_definition (p
, utsvp
);
12137 /* Ask for another packet of variable definition. */
12139 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12145 /* The "set/show range-stepping" show hook. */
12148 show_range_stepping (struct ui_file
*file
, int from_tty
,
12149 struct cmd_list_element
*c
,
12152 fprintf_filtered (file
,
12153 _("Debugger's willingness to use range stepping "
12154 "is %s.\n"), value
);
12157 /* The "set/show range-stepping" set hook. */
12160 set_range_stepping (char *ignore_args
, int from_tty
,
12161 struct cmd_list_element
*c
)
12163 struct remote_state
*rs
= get_remote_state ();
12165 /* Whene enabling, check whether range stepping is actually
12166 supported by the target, and warn if not. */
12167 if (use_range_stepping
)
12169 if (rs
->remote_desc
!= NULL
)
12171 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12172 remote_vcont_probe (rs
);
12174 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12175 && rs
->supports_vCont
.r
)
12179 warning (_("Range stepping is not supported by the current target"));
12184 _initialize_remote (void)
12186 struct remote_state
*rs
;
12187 struct cmd_list_element
*cmd
;
12188 const char *cmd_name
;
12190 /* architecture specific data */
12191 remote_gdbarch_data_handle
=
12192 gdbarch_data_register_post_init (init_remote_state
);
12193 remote_g_packet_data_handle
=
12194 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12196 /* Initialize the per-target state. At the moment there is only one
12197 of these, not one per target. Only one target is active at a
12199 remote_state
= new_remote_state ();
12201 init_remote_ops ();
12202 add_target (&remote_ops
);
12204 init_extended_remote_ops ();
12205 add_target (&extended_remote_ops
);
12207 /* Hook into new objfile notification. */
12208 observer_attach_new_objfile (remote_new_objfile
);
12209 /* We're no longer interested in notification events of an inferior
12211 observer_attach_inferior_exit (discard_pending_stop_replies
);
12213 /* Set up signal handlers. */
12214 async_sigint_remote_token
=
12215 create_async_signal_handler (async_remote_interrupt
, NULL
);
12216 async_sigint_remote_twice_token
=
12217 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12220 init_remote_threadtests ();
12223 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12224 /* set/show remote ... */
12226 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12227 Remote protocol specific variables\n\
12228 Configure various remote-protocol specific variables such as\n\
12229 the packets being used"),
12230 &remote_set_cmdlist
, "set remote ",
12231 0 /* allow-unknown */, &setlist
);
12232 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12233 Remote protocol specific variables\n\
12234 Configure various remote-protocol specific variables such as\n\
12235 the packets being used"),
12236 &remote_show_cmdlist
, "show remote ",
12237 0 /* allow-unknown */, &showlist
);
12239 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12240 Compare section data on target to the exec file.\n\
12241 Argument is a single section name (default: all loaded sections).\n\
12242 To compare only read-only loaded sections, specify the -r option."),
12245 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12246 Send an arbitrary packet to a remote target.\n\
12247 maintenance packet TEXT\n\
12248 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12249 this command sends the string TEXT to the inferior, and displays the\n\
12250 response packet. GDB supplies the initial `$' character, and the\n\
12251 terminating `#' character and checksum."),
12254 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12255 Set whether to send break if interrupted."), _("\
12256 Show whether to send break if interrupted."), _("\
12257 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12258 set_remotebreak
, show_remotebreak
,
12259 &setlist
, &showlist
);
12260 cmd_name
= "remotebreak";
12261 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12262 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12263 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12264 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12265 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12267 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12268 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12270 Set interrupt sequence to remote target."), _("\
12271 Show interrupt sequence to remote target."), _("\
12272 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12273 NULL
, show_interrupt_sequence
,
12274 &remote_set_cmdlist
,
12275 &remote_show_cmdlist
);
12277 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12278 &interrupt_on_connect
, _("\
12279 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12280 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12281 If set, interrupt sequence is sent to remote target."),
12283 &remote_set_cmdlist
, &remote_show_cmdlist
);
12285 /* Install commands for configuring memory read/write packets. */
12287 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12288 Set the maximum number of bytes per memory write packet (deprecated)."),
12290 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12291 Show the maximum number of bytes per memory write packet (deprecated)."),
12293 add_cmd ("memory-write-packet-size", no_class
,
12294 set_memory_write_packet_size
, _("\
12295 Set the maximum number of bytes per memory-write packet.\n\
12296 Specify the number of bytes in a packet or 0 (zero) for the\n\
12297 default packet size. The actual limit is further reduced\n\
12298 dependent on the target. Specify ``fixed'' to disable the\n\
12299 further restriction and ``limit'' to enable that restriction."),
12300 &remote_set_cmdlist
);
12301 add_cmd ("memory-read-packet-size", no_class
,
12302 set_memory_read_packet_size
, _("\
12303 Set the maximum number of bytes per memory-read packet.\n\
12304 Specify the number of bytes in a packet or 0 (zero) for the\n\
12305 default packet size. The actual limit is further reduced\n\
12306 dependent on the target. Specify ``fixed'' to disable the\n\
12307 further restriction and ``limit'' to enable that restriction."),
12308 &remote_set_cmdlist
);
12309 add_cmd ("memory-write-packet-size", no_class
,
12310 show_memory_write_packet_size
,
12311 _("Show the maximum number of bytes per memory-write packet."),
12312 &remote_show_cmdlist
);
12313 add_cmd ("memory-read-packet-size", no_class
,
12314 show_memory_read_packet_size
,
12315 _("Show the maximum number of bytes per memory-read packet."),
12316 &remote_show_cmdlist
);
12318 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12319 &remote_hw_watchpoint_limit
, _("\
12320 Set the maximum number of target hardware watchpoints."), _("\
12321 Show the maximum number of target hardware watchpoints."), _("\
12322 Specify a negative limit for unlimited."),
12323 NULL
, NULL
, /* FIXME: i18n: The maximum
12324 number of target hardware
12325 watchpoints is %s. */
12326 &remote_set_cmdlist
, &remote_show_cmdlist
);
12327 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12328 &remote_hw_watchpoint_length_limit
, _("\
12329 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12330 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12331 Specify a negative limit for unlimited."),
12332 NULL
, NULL
, /* FIXME: i18n: The maximum
12333 length (in bytes) of a target
12334 hardware watchpoint is %s. */
12335 &remote_set_cmdlist
, &remote_show_cmdlist
);
12336 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12337 &remote_hw_breakpoint_limit
, _("\
12338 Set the maximum number of target hardware breakpoints."), _("\
12339 Show the maximum number of target hardware breakpoints."), _("\
12340 Specify a negative limit for unlimited."),
12341 NULL
, NULL
, /* FIXME: i18n: The maximum
12342 number of target hardware
12343 breakpoints is %s. */
12344 &remote_set_cmdlist
, &remote_show_cmdlist
);
12346 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12347 &remote_address_size
, _("\
12348 Set the maximum size of the address (in bits) in a memory packet."), _("\
12349 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12351 NULL
, /* FIXME: i18n: */
12352 &setlist
, &showlist
);
12354 init_all_packet_configs ();
12356 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12357 "X", "binary-download", 1);
12359 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12360 "vCont", "verbose-resume", 0);
12362 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12363 "QPassSignals", "pass-signals", 0);
12365 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12366 "QProgramSignals", "program-signals", 0);
12368 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12369 "qSymbol", "symbol-lookup", 0);
12371 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12372 "P", "set-register", 1);
12374 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12375 "p", "fetch-register", 1);
12377 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12378 "Z0", "software-breakpoint", 0);
12380 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12381 "Z1", "hardware-breakpoint", 0);
12383 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12384 "Z2", "write-watchpoint", 0);
12386 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12387 "Z3", "read-watchpoint", 0);
12389 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12390 "Z4", "access-watchpoint", 0);
12392 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12393 "qXfer:auxv:read", "read-aux-vector", 0);
12395 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
12396 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12398 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12399 "qXfer:features:read", "target-features", 0);
12401 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12402 "qXfer:libraries:read", "library-info", 0);
12404 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12405 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12407 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12408 "qXfer:memory-map:read", "memory-map", 0);
12410 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12411 "qXfer:spu:read", "read-spu-object", 0);
12413 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12414 "qXfer:spu:write", "write-spu-object", 0);
12416 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12417 "qXfer:osdata:read", "osdata", 0);
12419 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12420 "qXfer:threads:read", "threads", 0);
12422 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12423 "qXfer:siginfo:read", "read-siginfo-object", 0);
12425 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12426 "qXfer:siginfo:write", "write-siginfo-object", 0);
12428 add_packet_config_cmd
12429 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12430 "qXfer:traceframe-info:read", "traceframe-info", 0);
12432 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12433 "qXfer:uib:read", "unwind-info-block", 0);
12435 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12436 "qGetTLSAddr", "get-thread-local-storage-address",
12439 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12440 "qGetTIBAddr", "get-thread-information-block-address",
12443 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12444 "bc", "reverse-continue", 0);
12446 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12447 "bs", "reverse-step", 0);
12449 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12450 "qSupported", "supported-packets", 0);
12452 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12453 "qSearch:memory", "search-memory", 0);
12455 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12456 "qTStatus", "trace-status", 0);
12458 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12459 "vFile:open", "hostio-open", 0);
12461 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12462 "vFile:pread", "hostio-pread", 0);
12464 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12465 "vFile:pwrite", "hostio-pwrite", 0);
12467 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12468 "vFile:close", "hostio-close", 0);
12470 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12471 "vFile:unlink", "hostio-unlink", 0);
12473 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12474 "vFile:readlink", "hostio-readlink", 0);
12476 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
12477 "vFile:fstat", "hostio-fstat", 0);
12479 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12480 "vAttach", "attach", 0);
12482 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12485 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12486 "QStartNoAckMode", "noack", 0);
12488 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12489 "vKill", "kill", 0);
12491 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12492 "qAttached", "query-attached", 0);
12494 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12495 "ConditionalTracepoints",
12496 "conditional-tracepoints", 0);
12498 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12499 "ConditionalBreakpoints",
12500 "conditional-breakpoints", 0);
12502 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12503 "BreakpointCommands",
12504 "breakpoint-commands", 0);
12506 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12507 "FastTracepoints", "fast-tracepoints", 0);
12509 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12510 "TracepointSource", "TracepointSource", 0);
12512 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12513 "QAllow", "allow", 0);
12515 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12516 "StaticTracepoints", "static-tracepoints", 0);
12518 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12519 "InstallInTrace", "install-in-trace", 0);
12521 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12522 "qXfer:statictrace:read", "read-sdata-object", 0);
12524 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12525 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12527 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12528 "QDisableRandomization", "disable-randomization", 0);
12530 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12531 "QAgent", "agent", 0);
12533 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12534 "QTBuffer:size", "trace-buffer-size", 0);
12536 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12537 "Qbtrace:off", "disable-btrace", 0);
12539 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12540 "Qbtrace:bts", "enable-btrace", 0);
12542 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12543 "qXfer:btrace", "read-btrace", 0);
12545 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
12546 "qXfer:btrace-conf", "read-btrace-conf", 0);
12548 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
12549 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
12551 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
12552 "swbreak-feature", "swbreak-feature", 0);
12554 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
12555 "hwbreak-feature", "hwbreak-feature", 0);
12557 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
12558 "fork-event-feature", "fork-event-feature", 0);
12560 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
12561 "vfork-event-feature", "vfork-event-feature", 0);
12563 /* Assert that we've registered "set remote foo-packet" commands
12564 for all packet configs. */
12568 for (i
= 0; i
< PACKET_MAX
; i
++)
12570 /* Ideally all configs would have a command associated. Some
12571 still don't though. */
12576 case PACKET_QNonStop
:
12577 case PACKET_multiprocess_feature
:
12578 case PACKET_EnableDisableTracepoints_feature
:
12579 case PACKET_tracenz_feature
:
12580 case PACKET_DisconnectedTracing_feature
:
12581 case PACKET_augmented_libraries_svr4_read_feature
:
12583 /* Additions to this list need to be well justified:
12584 pre-existing packets are OK; new packets are not. */
12592 /* This catches both forgetting to add a config command, and
12593 forgetting to remove a packet from the exception list. */
12594 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
12598 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12599 Z sub-packet has its own set and show commands, but users may
12600 have sets to this variable in their .gdbinit files (or in their
12602 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12603 &remote_Z_packet_detect
, _("\
12604 Set use of remote protocol `Z' packets"), _("\
12605 Show use of remote protocol `Z' packets "), _("\
12606 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12608 set_remote_protocol_Z_packet_cmd
,
12609 show_remote_protocol_Z_packet_cmd
,
12610 /* FIXME: i18n: Use of remote protocol
12611 `Z' packets is %s. */
12612 &remote_set_cmdlist
, &remote_show_cmdlist
);
12614 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12615 Manipulate files on the remote system\n\
12616 Transfer files to and from the remote target system."),
12617 &remote_cmdlist
, "remote ",
12618 0 /* allow-unknown */, &cmdlist
);
12620 add_cmd ("put", class_files
, remote_put_command
,
12621 _("Copy a local file to the remote system."),
12624 add_cmd ("get", class_files
, remote_get_command
,
12625 _("Copy a remote file to the local system."),
12628 add_cmd ("delete", class_files
, remote_delete_command
,
12629 _("Delete a remote file."),
12632 remote_exec_file
= xstrdup ("");
12633 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12634 &remote_exec_file
, _("\
12635 Set the remote pathname for \"run\""), _("\
12636 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12637 &remote_set_cmdlist
, &remote_show_cmdlist
);
12639 add_setshow_boolean_cmd ("range-stepping", class_run
,
12640 &use_range_stepping
, _("\
12641 Enable or disable range stepping."), _("\
12642 Show whether target-assisted range stepping is enabled."), _("\
12643 If on, and the target supports it, when stepping a source line, GDB\n\
12644 tells the target to step the corresponding range of addresses itself instead\n\
12645 of issuing multiple single-steps. This speeds up source level\n\
12646 stepping. If off, GDB always issues single-steps, even if range\n\
12647 stepping is supported by the target. The default is on."),
12648 set_range_stepping
,
12649 show_range_stepping
,
12653 /* Eventually initialize fileio. See fileio.c */
12654 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12656 /* Take advantage of the fact that the TID field is not used, to tag
12657 special ptids with it set to != 0. */
12658 magic_null_ptid
= ptid_build (42000, -1, 1);
12659 not_sent_ptid
= ptid_build (42000, -2, 1);
12660 any_thread_ptid
= ptid_build (42000, 0, 1);
12662 target_buf_size
= 2048;
12663 target_buf
= xmalloc (target_buf_size
);