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"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void async_cleanup_sigint_signal_handler (void *dummy
);
92 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
93 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
94 int forever
, int *is_notif
);
96 static void async_handle_remote_sigint (int);
97 static void async_handle_remote_sigint_twice (int);
99 static void remote_files_info (struct target_ops
*ignore
);
101 static void remote_prepare_to_store (struct target_ops
*self
,
102 struct regcache
*regcache
);
104 static void remote_open_1 (const char *, int, struct target_ops
*,
107 static void remote_close (struct target_ops
*self
);
111 static int remote_vkill (int pid
, struct remote_state
*rs
);
113 static void remote_mourn (struct target_ops
*ops
);
115 static void extended_remote_restart (void);
117 static void extended_remote_mourn (struct target_ops
*);
119 static void remote_send (char **buf
, long *sizeof_buf_p
);
121 static int readchar (int timeout
);
123 static void remote_serial_write (const char *str
, int len
);
125 static void remote_kill (struct target_ops
*ops
);
127 static int remote_can_async_p (struct target_ops
*);
129 static int remote_is_async_p (struct target_ops
*);
131 static void remote_async (struct target_ops
*ops
, int enable
);
133 static void sync_remote_interrupt_twice (int signo
);
135 static void interrupt_query (void);
137 static void set_general_thread (struct ptid ptid
);
138 static void set_continue_thread (struct ptid ptid
);
140 static void get_offsets (void);
142 static void skip_frame (void);
144 static long read_frame (char **buf_p
, long *sizeof_buf
);
146 static int hexnumlen (ULONGEST num
);
148 static void init_remote_ops (void);
150 static void init_extended_remote_ops (void);
152 static void remote_stop (struct target_ops
*self
, ptid_t
);
154 static int stubhex (int ch
);
156 static int hexnumstr (char *, ULONGEST
);
158 static int hexnumnstr (char *, ULONGEST
, int);
160 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
162 static void print_packet (const char *);
164 static void compare_sections_command (char *, int);
166 static void packet_command (char *, int);
168 static int stub_unpack_int (char *buff
, int fieldlength
);
170 static ptid_t
remote_current_thread (ptid_t oldptid
);
172 static int putpkt_binary (const char *buf
, int cnt
);
174 static void check_binary_download (CORE_ADDR addr
);
176 struct packet_config
;
178 static void show_packet_config_cmd (struct packet_config
*config
);
180 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
182 struct cmd_list_element
*c
,
185 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
186 static ptid_t
read_ptid (char *buf
, char **obuf
);
188 static void remote_set_permissions (struct target_ops
*self
);
190 static int remote_get_trace_status (struct target_ops
*self
,
191 struct trace_status
*ts
);
193 static int remote_upload_tracepoints (struct target_ops
*self
,
194 struct uploaded_tp
**utpp
);
196 static int remote_upload_trace_state_variables (struct target_ops
*self
,
197 struct uploaded_tsv
**utsvp
);
199 static void remote_query_supported (void);
201 static void remote_check_symbols (void);
203 void _initialize_remote (void);
206 static void stop_reply_xfree (struct stop_reply
*);
207 static void remote_parse_stop_reply (char *, struct stop_reply
*);
208 static void push_stop_reply (struct stop_reply
*);
209 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
210 static int peek_stop_reply (ptid_t ptid
);
212 struct threads_listing_context
;
213 static void remove_new_fork_children (struct threads_listing_context
*);
215 static void remote_async_inferior_event_handler (gdb_client_data
);
217 static void remote_terminal_ours (struct target_ops
*self
);
219 static int remote_read_description_p (struct target_ops
*target
);
221 static void remote_console_output (char *msg
);
223 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
225 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
227 static void remote_btrace_reset (void);
231 static struct cmd_list_element
*remote_cmdlist
;
233 /* For "set remote" and "show remote". */
235 static struct cmd_list_element
*remote_set_cmdlist
;
236 static struct cmd_list_element
*remote_show_cmdlist
;
238 /* Stub vCont actions support.
240 Each field is a boolean flag indicating whether the stub reports
241 support for the corresponding action. */
243 struct vCont_action_support
252 /* Controls whether GDB is willing to use range stepping. */
254 static int use_range_stepping
= 1;
256 #define OPAQUETHREADBYTES 8
258 /* a 64 bit opaque identifier */
259 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
261 /* About this many threadisds fit in a packet. */
263 #define MAXTHREADLISTRESULTS 32
265 /* Description of the remote protocol state for the currently
266 connected target. This is per-target state, and independent of the
267 selected architecture. */
271 /* A buffer to use for incoming packets, and its current size. The
272 buffer is grown dynamically for larger incoming packets.
273 Outgoing packets may also be constructed in this buffer.
274 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
275 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
280 /* True if we're going through initial connection setup (finding out
281 about the remote side's threads, relocating symbols, etc.). */
284 /* If we negotiated packet size explicitly (and thus can bypass
285 heuristics for the largest packet size that will not overflow
286 a buffer in the stub), this will be set to that packet size.
287 Otherwise zero, meaning to use the guessed size. */
288 long explicit_packet_size
;
290 /* remote_wait is normally called when the target is running and
291 waits for a stop reply packet. But sometimes we need to call it
292 when the target is already stopped. We can send a "?" packet
293 and have remote_wait read the response. Or, if we already have
294 the response, we can stash it in BUF and tell remote_wait to
295 skip calling getpkt. This flag is set when BUF contains a
296 stop reply packet and the target is not waiting. */
297 int cached_wait_status
;
299 /* True, if in no ack mode. That is, neither GDB nor the stub will
300 expect acks from each other. The connection is assumed to be
304 /* True if we're connected in extended remote mode. */
307 /* True if we resumed the target and we're waiting for the target to
308 stop. In the mean time, we can't start another command/query.
309 The remote server wouldn't be ready to process it, so we'd
310 timeout waiting for a reply that would never come and eventually
311 we'd close the connection. This can happen in asynchronous mode
312 because we allow GDB commands while the target is running. */
313 int waiting_for_stop_reply
;
315 /* The status of the stub support for the various vCont actions. */
316 struct vCont_action_support supports_vCont
;
318 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
319 responded to that. */
322 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
323 remote_open knows that we don't have a file open when the program
325 struct serial
*remote_desc
;
327 /* These are the threads which we last sent to the remote system. The
328 TID member will be -1 for all or -2 for not sent yet. */
329 ptid_t general_thread
;
330 ptid_t continue_thread
;
332 /* This is the traceframe which we last selected on the remote system.
333 It will be -1 if no traceframe is selected. */
334 int remote_traceframe_number
;
336 char *last_pass_packet
;
338 /* The last QProgramSignals packet sent to the target. We bypass
339 sending a new program signals list down to the target if the new
340 packet is exactly the same as the last we sent. IOW, we only let
341 the target know about program signals list changes. */
342 char *last_program_signals_packet
;
344 enum gdb_signal last_sent_signal
;
348 char *finished_object
;
349 char *finished_annex
;
350 ULONGEST finished_offset
;
352 /* Should we try the 'ThreadInfo' query packet?
354 This variable (NOT available to the user: auto-detect only!)
355 determines whether GDB will use the new, simpler "ThreadInfo"
356 query or the older, more complex syntax for thread queries.
357 This is an auto-detect variable (set to true at each connect,
358 and set to false when the target fails to recognize it). */
359 int use_threadinfo_query
;
360 int use_threadextra_query
;
362 /* This is set to the data address of the access causing the target
363 to stop for a watchpoint. */
364 CORE_ADDR remote_watch_data_address
;
366 /* Whether the target stopped for a breakpoint/watchpoint. */
367 enum target_stop_reason stop_reason
;
369 threadref echo_nextthread
;
370 threadref nextthread
;
371 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
373 /* The state of remote notification. */
374 struct remote_notif_state
*notif_state
;
376 /* The branch trace configuration. */
377 struct btrace_config btrace_config
;
379 /* The argument to the last "vFile:setfs:" packet we sent, used
380 to avoid sending repeated unnecessary "vFile:setfs:" packets.
381 Initialized to -1 to indicate that no "vFile:setfs:" packet
382 has yet been sent. */
386 /* Private data that we'll store in (struct thread_info)->private. */
387 struct private_thread_info
394 free_private_thread_info (struct private_thread_info
*info
)
400 /* This data could be associated with a target, but we do not always
401 have access to the current target when we need it, so for now it is
402 static. This will be fine for as long as only one target is in use
404 static struct remote_state
*remote_state
;
406 static struct remote_state
*
407 get_remote_state_raw (void)
412 /* Allocate a new struct remote_state with xmalloc, initialize it, and
415 static struct remote_state
*
416 new_remote_state (void)
418 struct remote_state
*result
= XCNEW (struct remote_state
);
420 /* The default buffer size is unimportant; it will be expanded
421 whenever a larger buffer is needed. */
422 result
->buf_size
= 400;
423 result
->buf
= xmalloc (result
->buf_size
);
424 result
->remote_traceframe_number
= -1;
425 result
->last_sent_signal
= GDB_SIGNAL_0
;
431 /* Description of the remote protocol for a given architecture. */
435 long offset
; /* Offset into G packet. */
436 long regnum
; /* GDB's internal register number. */
437 LONGEST pnum
; /* Remote protocol register number. */
438 int in_g_packet
; /* Always part of G packet. */
439 /* long size in bytes; == register_size (target_gdbarch (), regnum);
441 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
445 struct remote_arch_state
447 /* Description of the remote protocol registers. */
448 long sizeof_g_packet
;
450 /* Description of the remote protocol registers indexed by REGNUM
451 (making an array gdbarch_num_regs in size). */
452 struct packet_reg
*regs
;
454 /* This is the size (in chars) of the first response to the ``g''
455 packet. It is used as a heuristic when determining the maximum
456 size of memory-read and memory-write packets. A target will
457 typically only reserve a buffer large enough to hold the ``g''
458 packet. The size does not include packet overhead (headers and
460 long actual_register_packet_size
;
462 /* This is the maximum size (in chars) of a non read/write packet.
463 It is also used as a cap on the size of read/write packets. */
464 long remote_packet_size
;
467 /* Utility: generate error from an incoming stub packet. */
469 trace_error (char *buf
)
472 return; /* not an error msg */
475 case '1': /* malformed packet error */
476 if (*++buf
== '0') /* general case: */
477 error (_("remote.c: error in outgoing packet."));
479 error (_("remote.c: error in outgoing packet at field #%ld."),
480 strtol (buf
, NULL
, 16));
482 error (_("Target returns error code '%s'."), buf
);
486 /* Utility: wait for reply from stub, while accepting "O" packets. */
488 remote_get_noisy_reply (char **buf_p
,
491 do /* Loop on reply from remote stub. */
495 QUIT
; /* Allow user to bail out with ^C. */
496 getpkt (buf_p
, sizeof_buf
, 0);
500 else if (startswith (buf
, "qRelocInsn:"))
503 CORE_ADDR from
, to
, org_to
;
505 int adjusted_size
= 0;
508 p
= buf
+ strlen ("qRelocInsn:");
509 pp
= unpack_varlen_hex (p
, &ul
);
511 error (_("invalid qRelocInsn packet: %s"), buf
);
515 unpack_varlen_hex (p
, &ul
);
522 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
525 CATCH (ex
, RETURN_MASK_ALL
)
527 if (ex
.error
== MEMORY_ERROR
)
529 /* Propagate memory errors silently back to the
530 target. The stub may have limited the range of
531 addresses we can write to, for example. */
535 /* Something unexpectedly bad happened. Be verbose
536 so we can tell what, and propagate the error back
537 to the stub, so it doesn't get stuck waiting for
539 exception_fprintf (gdb_stderr
, ex
,
540 _("warning: relocating instruction: "));
548 adjusted_size
= to
- org_to
;
550 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
554 else if (buf
[0] == 'O' && buf
[1] != 'K')
555 remote_console_output (buf
+ 1); /* 'O' message from stub */
557 return buf
; /* Here's the actual reply. */
562 /* Handle for retreving the remote protocol data from gdbarch. */
563 static struct gdbarch_data
*remote_gdbarch_data_handle
;
565 static struct remote_arch_state
*
566 get_remote_arch_state (void)
568 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
571 /* Fetch the global remote target state. */
573 static struct remote_state
*
574 get_remote_state (void)
576 /* Make sure that the remote architecture state has been
577 initialized, because doing so might reallocate rs->buf. Any
578 function which calls getpkt also needs to be mindful of changes
579 to rs->buf, but this call limits the number of places which run
581 get_remote_arch_state ();
583 return get_remote_state_raw ();
587 compare_pnums (const void *lhs_
, const void *rhs_
)
589 const struct packet_reg
* const *lhs
= lhs_
;
590 const struct packet_reg
* const *rhs
= rhs_
;
592 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
594 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
601 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
603 int regnum
, num_remote_regs
, offset
;
604 struct packet_reg
**remote_regs
;
606 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
608 struct packet_reg
*r
= ®s
[regnum
];
610 if (register_size (gdbarch
, regnum
) == 0)
611 /* Do not try to fetch zero-sized (placeholder) registers. */
614 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
619 /* Define the g/G packet format as the contents of each register
620 with a remote protocol number, in order of ascending protocol
623 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
624 * sizeof (struct packet_reg
*));
625 for (num_remote_regs
= 0, regnum
= 0;
626 regnum
< gdbarch_num_regs (gdbarch
);
628 if (regs
[regnum
].pnum
!= -1)
629 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
631 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
634 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
636 remote_regs
[regnum
]->in_g_packet
= 1;
637 remote_regs
[regnum
]->offset
= offset
;
638 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
644 /* Given the architecture described by GDBARCH, return the remote
645 protocol register's number and the register's offset in the g/G
646 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
647 If the target does not have a mapping for REGNUM, return false,
648 otherwise, return true. */
651 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
652 int *pnum
, int *poffset
)
655 struct packet_reg
*regs
;
656 struct cleanup
*old_chain
;
658 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
660 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
661 old_chain
= make_cleanup (xfree
, regs
);
663 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
665 *pnum
= regs
[regnum
].pnum
;
666 *poffset
= regs
[regnum
].offset
;
668 do_cleanups (old_chain
);
674 init_remote_state (struct gdbarch
*gdbarch
)
676 struct remote_state
*rs
= get_remote_state_raw ();
677 struct remote_arch_state
*rsa
;
679 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
681 /* Use the architecture to build a regnum<->pnum table, which will be
682 1:1 unless a feature set specifies otherwise. */
683 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
684 gdbarch_num_regs (gdbarch
),
687 /* Record the maximum possible size of the g packet - it may turn out
689 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
691 /* Default maximum number of characters in a packet body. Many
692 remote stubs have a hardwired buffer size of 400 bytes
693 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
694 as the maximum packet-size to ensure that the packet and an extra
695 NUL character can always fit in the buffer. This stops GDB
696 trashing stubs that try to squeeze an extra NUL into what is
697 already a full buffer (As of 1999-12-04 that was most stubs). */
698 rsa
->remote_packet_size
= 400 - 1;
700 /* This one is filled in when a ``g'' packet is received. */
701 rsa
->actual_register_packet_size
= 0;
703 /* Should rsa->sizeof_g_packet needs more space than the
704 default, adjust the size accordingly. Remember that each byte is
705 encoded as two characters. 32 is the overhead for the packet
706 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
707 (``$NN:G...#NN'') is a better guess, the below has been padded a
709 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
710 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
712 /* Make sure that the packet buffer is plenty big enough for
713 this architecture. */
714 if (rs
->buf_size
< rsa
->remote_packet_size
)
716 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
717 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
723 /* Return the current allowed size of a remote packet. This is
724 inferred from the current architecture, and should be used to
725 limit the length of outgoing packets. */
727 get_remote_packet_size (void)
729 struct remote_state
*rs
= get_remote_state ();
730 struct remote_arch_state
*rsa
= get_remote_arch_state ();
732 if (rs
->explicit_packet_size
)
733 return rs
->explicit_packet_size
;
735 return rsa
->remote_packet_size
;
738 static struct packet_reg
*
739 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
741 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
745 struct packet_reg
*r
= &rsa
->regs
[regnum
];
747 gdb_assert (r
->regnum
== regnum
);
752 static struct packet_reg
*
753 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
757 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
759 struct packet_reg
*r
= &rsa
->regs
[i
];
767 static struct target_ops remote_ops
;
769 static struct target_ops extended_remote_ops
;
771 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
772 ``forever'' still use the normal timeout mechanism. This is
773 currently used by the ASYNC code to guarentee that target reads
774 during the initial connect always time-out. Once getpkt has been
775 modified to return a timeout indication and, in turn
776 remote_wait()/wait_for_inferior() have gained a timeout parameter
778 static int wait_forever_enabled_p
= 1;
780 /* Allow the user to specify what sequence to send to the remote
781 when he requests a program interruption: Although ^C is usually
782 what remote systems expect (this is the default, here), it is
783 sometimes preferable to send a break. On other systems such
784 as the Linux kernel, a break followed by g, which is Magic SysRq g
785 is required in order to interrupt the execution. */
786 const char interrupt_sequence_control_c
[] = "Ctrl-C";
787 const char interrupt_sequence_break
[] = "BREAK";
788 const char interrupt_sequence_break_g
[] = "BREAK-g";
789 static const char *const interrupt_sequence_modes
[] =
791 interrupt_sequence_control_c
,
792 interrupt_sequence_break
,
793 interrupt_sequence_break_g
,
796 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
799 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
800 struct cmd_list_element
*c
,
803 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
804 fprintf_filtered (file
,
805 _("Send the ASCII ETX character (Ctrl-c) "
806 "to the remote target to interrupt the "
807 "execution of the program.\n"));
808 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
809 fprintf_filtered (file
,
810 _("send a break signal to the remote target "
811 "to interrupt the execution of the program.\n"));
812 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
813 fprintf_filtered (file
,
814 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
815 "the remote target to interrupt the execution "
816 "of Linux kernel.\n"));
818 internal_error (__FILE__
, __LINE__
,
819 _("Invalid value for interrupt_sequence_mode: %s."),
820 interrupt_sequence_mode
);
823 /* This boolean variable specifies whether interrupt_sequence is sent
824 to the remote target when gdb connects to it.
825 This is mostly needed when you debug the Linux kernel: The Linux kernel
826 expects BREAK g which is Magic SysRq g for connecting gdb. */
827 static int interrupt_on_connect
= 0;
829 /* This variable is used to implement the "set/show remotebreak" commands.
830 Since these commands are now deprecated in favor of "set/show remote
831 interrupt-sequence", it no longer has any effect on the code. */
832 static int remote_break
;
835 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
838 interrupt_sequence_mode
= interrupt_sequence_break
;
840 interrupt_sequence_mode
= interrupt_sequence_control_c
;
844 show_remotebreak (struct ui_file
*file
, int from_tty
,
845 struct cmd_list_element
*c
,
850 /* This variable sets the number of bits in an address that are to be
851 sent in a memory ("M" or "m") packet. Normally, after stripping
852 leading zeros, the entire address would be sent. This variable
853 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
854 initial implementation of remote.c restricted the address sent in
855 memory packets to ``host::sizeof long'' bytes - (typically 32
856 bits). Consequently, for 64 bit targets, the upper 32 bits of an
857 address was never sent. Since fixing this bug may cause a break in
858 some remote targets this variable is principly provided to
859 facilitate backward compatibility. */
861 static unsigned int remote_address_size
;
863 /* Temporary to track who currently owns the terminal. See
864 remote_terminal_* for more details. */
866 static int remote_async_terminal_ours_p
;
868 /* The executable file to use for "run" on the remote side. */
870 static char *remote_exec_file
= "";
873 /* User configurable variables for the number of characters in a
874 memory read/write packet. MIN (rsa->remote_packet_size,
875 rsa->sizeof_g_packet) is the default. Some targets need smaller
876 values (fifo overruns, et.al.) and some users need larger values
877 (speed up transfers). The variables ``preferred_*'' (the user
878 request), ``current_*'' (what was actually set) and ``forced_*''
879 (Positive - a soft limit, negative - a hard limit). */
881 struct memory_packet_config
888 /* Compute the current size of a read/write packet. Since this makes
889 use of ``actual_register_packet_size'' the computation is dynamic. */
892 get_memory_packet_size (struct memory_packet_config
*config
)
894 struct remote_state
*rs
= get_remote_state ();
895 struct remote_arch_state
*rsa
= get_remote_arch_state ();
897 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
898 law?) that some hosts don't cope very well with large alloca()
899 calls. Eventually the alloca() code will be replaced by calls to
900 xmalloc() and make_cleanups() allowing this restriction to either
901 be lifted or removed. */
902 #ifndef MAX_REMOTE_PACKET_SIZE
903 #define MAX_REMOTE_PACKET_SIZE 16384
905 /* NOTE: 20 ensures we can write at least one byte. */
906 #ifndef MIN_REMOTE_PACKET_SIZE
907 #define MIN_REMOTE_PACKET_SIZE 20
912 if (config
->size
<= 0)
913 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
915 what_they_get
= config
->size
;
919 what_they_get
= get_remote_packet_size ();
920 /* Limit the packet to the size specified by the user. */
922 && what_they_get
> config
->size
)
923 what_they_get
= config
->size
;
925 /* Limit it to the size of the targets ``g'' response unless we have
926 permission from the stub to use a larger packet size. */
927 if (rs
->explicit_packet_size
== 0
928 && rsa
->actual_register_packet_size
> 0
929 && what_they_get
> rsa
->actual_register_packet_size
)
930 what_they_get
= rsa
->actual_register_packet_size
;
932 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
933 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
934 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
935 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
937 /* Make sure there is room in the global buffer for this packet
938 (including its trailing NUL byte). */
939 if (rs
->buf_size
< what_they_get
+ 1)
941 rs
->buf_size
= 2 * what_they_get
;
942 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
945 return what_they_get
;
948 /* Update the size of a read/write packet. If they user wants
949 something really big then do a sanity check. */
952 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
954 int fixed_p
= config
->fixed_p
;
955 long size
= config
->size
;
958 error (_("Argument required (integer, `fixed' or `limited')."));
959 else if (strcmp (args
, "hard") == 0
960 || strcmp (args
, "fixed") == 0)
962 else if (strcmp (args
, "soft") == 0
963 || strcmp (args
, "limit") == 0)
969 size
= strtoul (args
, &end
, 0);
971 error (_("Invalid %s (bad syntax)."), config
->name
);
973 /* Instead of explicitly capping the size of a packet to
974 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
975 instead allowed to set the size to something arbitrarily
977 if (size
> MAX_REMOTE_PACKET_SIZE
)
978 error (_("Invalid %s (too large)."), config
->name
);
982 if (fixed_p
&& !config
->fixed_p
)
984 if (! query (_("The target may not be able to correctly handle a %s\n"
985 "of %ld bytes. Change the packet size? "),
987 error (_("Packet size not changed."));
989 /* Update the config. */
990 config
->fixed_p
= fixed_p
;
995 show_memory_packet_size (struct memory_packet_config
*config
)
997 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
999 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1000 get_memory_packet_size (config
));
1002 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1003 get_memory_packet_size (config
));
1006 static struct memory_packet_config memory_write_packet_config
=
1008 "memory-write-packet-size",
1012 set_memory_write_packet_size (char *args
, int from_tty
)
1014 set_memory_packet_size (args
, &memory_write_packet_config
);
1018 show_memory_write_packet_size (char *args
, int from_tty
)
1020 show_memory_packet_size (&memory_write_packet_config
);
1024 get_memory_write_packet_size (void)
1026 return get_memory_packet_size (&memory_write_packet_config
);
1029 static struct memory_packet_config memory_read_packet_config
=
1031 "memory-read-packet-size",
1035 set_memory_read_packet_size (char *args
, int from_tty
)
1037 set_memory_packet_size (args
, &memory_read_packet_config
);
1041 show_memory_read_packet_size (char *args
, int from_tty
)
1043 show_memory_packet_size (&memory_read_packet_config
);
1047 get_memory_read_packet_size (void)
1049 long size
= get_memory_packet_size (&memory_read_packet_config
);
1051 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1052 extra buffer size argument before the memory read size can be
1053 increased beyond this. */
1054 if (size
> get_remote_packet_size ())
1055 size
= get_remote_packet_size ();
1060 /* Generic configuration support for packets the stub optionally
1061 supports. Allows the user to specify the use of the packet as well
1062 as allowing GDB to auto-detect support in the remote stub. */
1066 PACKET_SUPPORT_UNKNOWN
= 0,
1071 struct packet_config
1076 /* If auto, GDB auto-detects support for this packet or feature,
1077 either through qSupported, or by trying the packet and looking
1078 at the response. If true, GDB assumes the target supports this
1079 packet. If false, the packet is disabled. Configs that don't
1080 have an associated command always have this set to auto. */
1081 enum auto_boolean detect
;
1083 /* Does the target support this packet? */
1084 enum packet_support support
;
1087 /* Analyze a packet's return value and update the packet config
1097 static enum packet_support
packet_config_support (struct packet_config
*config
);
1098 static enum packet_support
packet_support (int packet
);
1101 show_packet_config_cmd (struct packet_config
*config
)
1103 char *support
= "internal-error";
1105 switch (packet_config_support (config
))
1108 support
= "enabled";
1110 case PACKET_DISABLE
:
1111 support
= "disabled";
1113 case PACKET_SUPPORT_UNKNOWN
:
1114 support
= "unknown";
1117 switch (config
->detect
)
1119 case AUTO_BOOLEAN_AUTO
:
1120 printf_filtered (_("Support for the `%s' packet "
1121 "is auto-detected, currently %s.\n"),
1122 config
->name
, support
);
1124 case AUTO_BOOLEAN_TRUE
:
1125 case AUTO_BOOLEAN_FALSE
:
1126 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1127 config
->name
, support
);
1133 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1134 const char *title
, int legacy
)
1140 config
->name
= name
;
1141 config
->title
= title
;
1142 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1144 show_doc
= xstrprintf ("Show current use of remote "
1145 "protocol `%s' (%s) packet",
1147 /* set/show TITLE-packet {auto,on,off} */
1148 cmd_name
= xstrprintf ("%s-packet", title
);
1149 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1150 &config
->detect
, set_doc
,
1151 show_doc
, NULL
, /* help_doc */
1153 show_remote_protocol_packet_cmd
,
1154 &remote_set_cmdlist
, &remote_show_cmdlist
);
1155 /* The command code copies the documentation strings. */
1158 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1163 legacy_name
= xstrprintf ("%s-packet", name
);
1164 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1165 &remote_set_cmdlist
);
1166 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1167 &remote_show_cmdlist
);
1171 static enum packet_result
1172 packet_check_result (const char *buf
)
1176 /* The stub recognized the packet request. Check that the
1177 operation succeeded. */
1179 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1181 /* "Enn" - definitly an error. */
1182 return PACKET_ERROR
;
1184 /* Always treat "E." as an error. This will be used for
1185 more verbose error messages, such as E.memtypes. */
1186 if (buf
[0] == 'E' && buf
[1] == '.')
1187 return PACKET_ERROR
;
1189 /* The packet may or may not be OK. Just assume it is. */
1193 /* The stub does not support the packet. */
1194 return PACKET_UNKNOWN
;
1197 static enum packet_result
1198 packet_ok (const char *buf
, struct packet_config
*config
)
1200 enum packet_result result
;
1202 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1203 && config
->support
== PACKET_DISABLE
)
1204 internal_error (__FILE__
, __LINE__
,
1205 _("packet_ok: attempt to use a disabled packet"));
1207 result
= packet_check_result (buf
);
1212 /* The stub recognized the packet request. */
1213 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1216 fprintf_unfiltered (gdb_stdlog
,
1217 "Packet %s (%s) is supported\n",
1218 config
->name
, config
->title
);
1219 config
->support
= PACKET_ENABLE
;
1222 case PACKET_UNKNOWN
:
1223 /* The stub does not support the packet. */
1224 if (config
->detect
== AUTO_BOOLEAN_AUTO
1225 && config
->support
== PACKET_ENABLE
)
1227 /* If the stub previously indicated that the packet was
1228 supported then there is a protocol error. */
1229 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1230 config
->name
, config
->title
);
1232 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1234 /* The user set it wrong. */
1235 error (_("Enabled packet %s (%s) not recognized by stub"),
1236 config
->name
, config
->title
);
1240 fprintf_unfiltered (gdb_stdlog
,
1241 "Packet %s (%s) is NOT supported\n",
1242 config
->name
, config
->title
);
1243 config
->support
= PACKET_DISABLE
;
1264 PACKET_vFile_pwrite
,
1266 PACKET_vFile_unlink
,
1267 PACKET_vFile_readlink
,
1270 PACKET_qXfer_features
,
1271 PACKET_qXfer_exec_file
,
1272 PACKET_qXfer_libraries
,
1273 PACKET_qXfer_libraries_svr4
,
1274 PACKET_qXfer_memory_map
,
1275 PACKET_qXfer_spu_read
,
1276 PACKET_qXfer_spu_write
,
1277 PACKET_qXfer_osdata
,
1278 PACKET_qXfer_threads
,
1279 PACKET_qXfer_statictrace_read
,
1280 PACKET_qXfer_traceframe_info
,
1286 PACKET_QPassSignals
,
1287 PACKET_QProgramSignals
,
1289 PACKET_qSearch_memory
,
1292 PACKET_QStartNoAckMode
,
1294 PACKET_qXfer_siginfo_read
,
1295 PACKET_qXfer_siginfo_write
,
1298 /* Support for conditional tracepoints. */
1299 PACKET_ConditionalTracepoints
,
1301 /* Support for target-side breakpoint conditions. */
1302 PACKET_ConditionalBreakpoints
,
1304 /* Support for target-side breakpoint commands. */
1305 PACKET_BreakpointCommands
,
1307 /* Support for fast tracepoints. */
1308 PACKET_FastTracepoints
,
1310 /* Support for static tracepoints. */
1311 PACKET_StaticTracepoints
,
1313 /* Support for installing tracepoints while a trace experiment is
1315 PACKET_InstallInTrace
,
1319 PACKET_TracepointSource
,
1322 PACKET_QDisableRandomization
,
1324 PACKET_QTBuffer_size
,
1328 PACKET_qXfer_btrace
,
1330 /* Support for the QNonStop packet. */
1333 /* Support for multi-process extensions. */
1334 PACKET_multiprocess_feature
,
1336 /* Support for enabling and disabling tracepoints while a trace
1337 experiment is running. */
1338 PACKET_EnableDisableTracepoints_feature
,
1340 /* Support for collecting strings using the tracenz bytecode. */
1341 PACKET_tracenz_feature
,
1343 /* Support for continuing to run a trace experiment while GDB is
1345 PACKET_DisconnectedTracing_feature
,
1347 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1348 PACKET_augmented_libraries_svr4_read_feature
,
1350 /* Support for the qXfer:btrace-conf:read packet. */
1351 PACKET_qXfer_btrace_conf
,
1353 /* Support for the Qbtrace-conf:bts:size packet. */
1354 PACKET_Qbtrace_conf_bts_size
,
1356 /* Support for swbreak+ feature. */
1357 PACKET_swbreak_feature
,
1359 /* Support for hwbreak+ feature. */
1360 PACKET_hwbreak_feature
,
1362 /* Support for fork events. */
1363 PACKET_fork_event_feature
,
1365 /* Support for vfork events. */
1366 PACKET_vfork_event_feature
,
1368 /* Support for the Qbtrace-conf:pt:size packet. */
1369 PACKET_Qbtrace_conf_pt_size
,
1374 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1376 /* Returns the packet's corresponding "set remote foo-packet" command
1377 state. See struct packet_config for more details. */
1379 static enum auto_boolean
1380 packet_set_cmd_state (int packet
)
1382 return remote_protocol_packets
[packet
].detect
;
1385 /* Returns whether a given packet or feature is supported. This takes
1386 into account the state of the corresponding "set remote foo-packet"
1387 command, which may be used to bypass auto-detection. */
1389 static enum packet_support
1390 packet_config_support (struct packet_config
*config
)
1392 switch (config
->detect
)
1394 case AUTO_BOOLEAN_TRUE
:
1395 return PACKET_ENABLE
;
1396 case AUTO_BOOLEAN_FALSE
:
1397 return PACKET_DISABLE
;
1398 case AUTO_BOOLEAN_AUTO
:
1399 return config
->support
;
1401 gdb_assert_not_reached (_("bad switch"));
1405 /* Same as packet_config_support, but takes the packet's enum value as
1408 static enum packet_support
1409 packet_support (int packet
)
1411 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1413 return packet_config_support (config
);
1417 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1418 struct cmd_list_element
*c
,
1421 struct packet_config
*packet
;
1423 for (packet
= remote_protocol_packets
;
1424 packet
< &remote_protocol_packets
[PACKET_MAX
];
1427 if (&packet
->detect
== c
->var
)
1429 show_packet_config_cmd (packet
);
1433 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1437 /* Should we try one of the 'Z' requests? */
1441 Z_PACKET_SOFTWARE_BP
,
1442 Z_PACKET_HARDWARE_BP
,
1449 /* For compatibility with older distributions. Provide a ``set remote
1450 Z-packet ...'' command that updates all the Z packet types. */
1452 static enum auto_boolean remote_Z_packet_detect
;
1455 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1456 struct cmd_list_element
*c
)
1460 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1461 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1465 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1466 struct cmd_list_element
*c
,
1471 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1473 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1477 /* Returns true if the multi-process extensions are in effect. */
1480 remote_multi_process_p (struct remote_state
*rs
)
1482 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1485 /* Returns true if fork events are supported. */
1488 remote_fork_event_p (struct remote_state
*rs
)
1490 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1493 /* Returns true if vfork events are supported. */
1496 remote_vfork_event_p (struct remote_state
*rs
)
1498 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1501 /* Insert fork catchpoint target routine. If fork events are enabled
1502 then return success, nothing more to do. */
1505 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1507 struct remote_state
*rs
= get_remote_state ();
1509 return !remote_fork_event_p (rs
);
1512 /* Remove fork catchpoint target routine. Nothing to do, just
1516 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1521 /* Insert vfork catchpoint target routine. If vfork events are enabled
1522 then return success, nothing more to do. */
1525 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1527 struct remote_state
*rs
= get_remote_state ();
1529 return !remote_vfork_event_p (rs
);
1532 /* Remove vfork catchpoint target routine. Nothing to do, just
1536 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1541 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1542 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1543 static struct async_signal_handler
*async_sigint_remote_token
;
1546 /* Asynchronous signal handle registered as event loop source for
1547 when we have pending events ready to be passed to the core. */
1549 static struct async_event_handler
*remote_async_inferior_event_token
;
1553 static ptid_t magic_null_ptid
;
1554 static ptid_t not_sent_ptid
;
1555 static ptid_t any_thread_ptid
;
1557 /* Find out if the stub attached to PID (and hence GDB should offer to
1558 detach instead of killing it when bailing out). */
1561 remote_query_attached (int pid
)
1563 struct remote_state
*rs
= get_remote_state ();
1564 size_t size
= get_remote_packet_size ();
1566 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1569 if (remote_multi_process_p (rs
))
1570 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1572 xsnprintf (rs
->buf
, size
, "qAttached");
1575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1577 switch (packet_ok (rs
->buf
,
1578 &remote_protocol_packets
[PACKET_qAttached
]))
1581 if (strcmp (rs
->buf
, "1") == 0)
1585 warning (_("Remote failure reply: %s"), rs
->buf
);
1587 case PACKET_UNKNOWN
:
1594 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1595 has been invented by GDB, instead of reported by the target. Since
1596 we can be connected to a remote system before before knowing about
1597 any inferior, mark the target with execution when we find the first
1598 inferior. If ATTACHED is 1, then we had just attached to this
1599 inferior. If it is 0, then we just created this inferior. If it
1600 is -1, then try querying the remote stub to find out if it had
1601 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1602 attempt to open this inferior's executable as the main executable
1603 if no main executable is open already. */
1605 static struct inferior
*
1606 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1609 struct inferior
*inf
;
1611 /* Check whether this process we're learning about is to be
1612 considered attached, or if is to be considered to have been
1613 spawned by the stub. */
1615 attached
= remote_query_attached (pid
);
1617 if (gdbarch_has_global_solist (target_gdbarch ()))
1619 /* If the target shares code across all inferiors, then every
1620 attach adds a new inferior. */
1621 inf
= add_inferior (pid
);
1623 /* ... and every inferior is bound to the same program space.
1624 However, each inferior may still have its own address
1626 inf
->aspace
= maybe_new_address_space ();
1627 inf
->pspace
= current_program_space
;
1631 /* In the traditional debugging scenario, there's a 1-1 match
1632 between program/address spaces. We simply bind the inferior
1633 to the program space's address space. */
1634 inf
= current_inferior ();
1635 inferior_appeared (inf
, pid
);
1638 inf
->attach_flag
= attached
;
1639 inf
->fake_pid_p
= fake_pid_p
;
1641 /* If no main executable is currently open then attempt to
1642 open the file that was executed to create this inferior. */
1643 if (try_open_exec
&& get_exec_file (0) == NULL
)
1644 exec_file_locate_attach (pid
, 1);
1649 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1650 according to RUNNING. */
1653 remote_add_thread (ptid_t ptid
, int running
)
1655 struct remote_state
*rs
= get_remote_state ();
1657 /* GDB historically didn't pull threads in the initial connection
1658 setup. If the remote target doesn't even have a concept of
1659 threads (e.g., a bare-metal target), even if internally we
1660 consider that a single-threaded target, mentioning a new thread
1661 might be confusing to the user. Be silent then, preserving the
1662 age old behavior. */
1663 if (rs
->starting_up
)
1664 add_thread_silent (ptid
);
1668 set_executing (ptid
, running
);
1669 set_running (ptid
, running
);
1672 /* Come here when we learn about a thread id from the remote target.
1673 It may be the first time we hear about such thread, so take the
1674 opportunity to add it to GDB's thread list. In case this is the
1675 first time we're noticing its corresponding inferior, add it to
1676 GDB's inferior list as well. */
1679 remote_notice_new_inferior (ptid_t currthread
, int running
)
1681 /* If this is a new thread, add it to GDB's thread list.
1682 If we leave it up to WFI to do this, bad things will happen. */
1684 if (in_thread_list (currthread
) && is_exited (currthread
))
1686 /* We're seeing an event on a thread id we knew had exited.
1687 This has to be a new thread reusing the old id. Add it. */
1688 remote_add_thread (currthread
, running
);
1692 if (!in_thread_list (currthread
))
1694 struct inferior
*inf
= NULL
;
1695 int pid
= ptid_get_pid (currthread
);
1697 if (ptid_is_pid (inferior_ptid
)
1698 && pid
== ptid_get_pid (inferior_ptid
))
1700 /* inferior_ptid has no thread member yet. This can happen
1701 with the vAttach -> remote_wait,"TAAthread:" path if the
1702 stub doesn't support qC. This is the first stop reported
1703 after an attach, so this is the main thread. Update the
1704 ptid in the thread list. */
1705 if (in_thread_list (pid_to_ptid (pid
)))
1706 thread_change_ptid (inferior_ptid
, currthread
);
1709 remote_add_thread (currthread
, running
);
1710 inferior_ptid
= currthread
;
1715 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1717 /* inferior_ptid is not set yet. This can happen with the
1718 vRun -> remote_wait,"TAAthread:" path if the stub
1719 doesn't support qC. This is the first stop reported
1720 after an attach, so this is the main thread. Update the
1721 ptid in the thread list. */
1722 thread_change_ptid (inferior_ptid
, currthread
);
1726 /* When connecting to a target remote, or to a target
1727 extended-remote which already was debugging an inferior, we
1728 may not know about it yet. Add it before adding its child
1729 thread, so notifications are emitted in a sensible order. */
1730 if (!in_inferior_list (ptid_get_pid (currthread
)))
1732 struct remote_state
*rs
= get_remote_state ();
1733 int fake_pid_p
= !remote_multi_process_p (rs
);
1735 inf
= remote_add_inferior (fake_pid_p
,
1736 ptid_get_pid (currthread
), -1, 1);
1739 /* This is really a new thread. Add it. */
1740 remote_add_thread (currthread
, running
);
1742 /* If we found a new inferior, let the common code do whatever
1743 it needs to with it (e.g., read shared libraries, insert
1744 breakpoints), unless we're just setting up an all-stop
1748 struct remote_state
*rs
= get_remote_state ();
1750 if (non_stop
|| !rs
->starting_up
)
1751 notice_new_inferior (currthread
, running
, 0);
1756 /* Return the private thread data, creating it if necessary. */
1758 static struct private_thread_info
*
1759 demand_private_info (ptid_t ptid
)
1761 struct thread_info
*info
= find_thread_ptid (ptid
);
1767 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1768 info
->private_dtor
= free_private_thread_info
;
1769 info
->priv
->core
= -1;
1770 info
->priv
->extra
= 0;
1776 /* Call this function as a result of
1777 1) A halt indication (T packet) containing a thread id
1778 2) A direct query of currthread
1779 3) Successful execution of set thread */
1782 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1784 rs
->general_thread
= currthread
;
1787 /* If 'QPassSignals' is supported, tell the remote stub what signals
1788 it can simply pass through to the inferior without reporting. */
1791 remote_pass_signals (struct target_ops
*self
,
1792 int numsigs
, unsigned char *pass_signals
)
1794 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1796 char *pass_packet
, *p
;
1798 struct remote_state
*rs
= get_remote_state ();
1800 gdb_assert (numsigs
< 256);
1801 for (i
= 0; i
< numsigs
; i
++)
1803 if (pass_signals
[i
])
1806 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1807 strcpy (pass_packet
, "QPassSignals:");
1808 p
= pass_packet
+ strlen (pass_packet
);
1809 for (i
= 0; i
< numsigs
; i
++)
1811 if (pass_signals
[i
])
1814 *p
++ = tohex (i
>> 4);
1815 *p
++ = tohex (i
& 15);
1824 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1826 putpkt (pass_packet
);
1827 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1828 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1829 if (rs
->last_pass_packet
)
1830 xfree (rs
->last_pass_packet
);
1831 rs
->last_pass_packet
= pass_packet
;
1834 xfree (pass_packet
);
1838 /* If 'QProgramSignals' is supported, tell the remote stub what
1839 signals it should pass through to the inferior when detaching. */
1842 remote_program_signals (struct target_ops
*self
,
1843 int numsigs
, unsigned char *signals
)
1845 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1849 struct remote_state
*rs
= get_remote_state ();
1851 gdb_assert (numsigs
< 256);
1852 for (i
= 0; i
< numsigs
; i
++)
1857 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1858 strcpy (packet
, "QProgramSignals:");
1859 p
= packet
+ strlen (packet
);
1860 for (i
= 0; i
< numsigs
; i
++)
1862 if (signal_pass_state (i
))
1865 *p
++ = tohex (i
>> 4);
1866 *p
++ = tohex (i
& 15);
1875 if (!rs
->last_program_signals_packet
1876 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1879 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1880 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1881 xfree (rs
->last_program_signals_packet
);
1882 rs
->last_program_signals_packet
= packet
;
1889 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1890 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1891 thread. If GEN is set, set the general thread, if not, then set
1892 the step/continue thread. */
1894 set_thread (struct ptid ptid
, int gen
)
1896 struct remote_state
*rs
= get_remote_state ();
1897 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1898 char *buf
= rs
->buf
;
1899 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1901 if (ptid_equal (state
, ptid
))
1905 *buf
++ = gen
? 'g' : 'c';
1906 if (ptid_equal (ptid
, magic_null_ptid
))
1907 xsnprintf (buf
, endbuf
- buf
, "0");
1908 else if (ptid_equal (ptid
, any_thread_ptid
))
1909 xsnprintf (buf
, endbuf
- buf
, "0");
1910 else if (ptid_equal (ptid
, minus_one_ptid
))
1911 xsnprintf (buf
, endbuf
- buf
, "-1");
1913 write_ptid (buf
, endbuf
, ptid
);
1915 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1917 rs
->general_thread
= ptid
;
1919 rs
->continue_thread
= ptid
;
1923 set_general_thread (struct ptid ptid
)
1925 set_thread (ptid
, 1);
1929 set_continue_thread (struct ptid ptid
)
1931 set_thread (ptid
, 0);
1934 /* Change the remote current process. Which thread within the process
1935 ends up selected isn't important, as long as it is the same process
1936 as what INFERIOR_PTID points to.
1938 This comes from that fact that there is no explicit notion of
1939 "selected process" in the protocol. The selected process for
1940 general operations is the process the selected general thread
1944 set_general_process (void)
1946 struct remote_state
*rs
= get_remote_state ();
1948 /* If the remote can't handle multiple processes, don't bother. */
1949 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1952 /* We only need to change the remote current thread if it's pointing
1953 at some other process. */
1954 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1955 set_general_thread (inferior_ptid
);
1959 /* Return nonzero if this is the main thread that we made up ourselves
1960 to model non-threaded targets as single-threaded. */
1963 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
1965 struct remote_state
*rs
= get_remote_state ();
1968 if (ptid_equal (ptid
, magic_null_ptid
))
1969 /* The main thread is always alive. */
1972 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1973 /* The main thread is always alive. This can happen after a
1974 vAttach, if the remote side doesn't support
1981 /* Return nonzero if the thread PTID is still alive on the remote
1985 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1987 struct remote_state
*rs
= get_remote_state ();
1990 /* Check if this is a thread that we made up ourselves to model
1991 non-threaded targets as single-threaded. */
1992 if (remote_thread_always_alive (ops
, ptid
))
1996 endp
= rs
->buf
+ get_remote_packet_size ();
1999 write_ptid (p
, endp
, ptid
);
2002 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2003 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2006 /* About these extended threadlist and threadinfo packets. They are
2007 variable length packets but, the fields within them are often fixed
2008 length. They are redundent enough to send over UDP as is the
2009 remote protocol in general. There is a matching unit test module
2012 /* WARNING: This threadref data structure comes from the remote O.S.,
2013 libstub protocol encoding, and remote.c. It is not particularly
2016 /* Right now, the internal structure is int. We want it to be bigger.
2017 Plan to fix this. */
2019 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2021 /* gdb_ext_thread_info is an internal GDB data structure which is
2022 equivalent to the reply of the remote threadinfo packet. */
2024 struct gdb_ext_thread_info
2026 threadref threadid
; /* External form of thread reference. */
2027 int active
; /* Has state interesting to GDB?
2029 char display
[256]; /* Brief state display, name,
2030 blocked/suspended. */
2031 char shortname
[32]; /* To be used to name threads. */
2032 char more_display
[256]; /* Long info, statistics, queue depth,
2036 /* The volume of remote transfers can be limited by submitting
2037 a mask containing bits specifying the desired information.
2038 Use a union of these values as the 'selection' parameter to
2039 get_thread_info. FIXME: Make these TAG names more thread specific. */
2041 #define TAG_THREADID 1
2042 #define TAG_EXISTS 2
2043 #define TAG_DISPLAY 4
2044 #define TAG_THREADNAME 8
2045 #define TAG_MOREDISPLAY 16
2047 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2049 static char *unpack_nibble (char *buf
, int *val
);
2051 static char *unpack_byte (char *buf
, int *value
);
2053 static char *pack_int (char *buf
, int value
);
2055 static char *unpack_int (char *buf
, int *value
);
2057 static char *unpack_string (char *src
, char *dest
, int length
);
2059 static char *pack_threadid (char *pkt
, threadref
*id
);
2061 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2063 void int_to_threadref (threadref
*id
, int value
);
2065 static int threadref_to_int (threadref
*ref
);
2067 static void copy_threadref (threadref
*dest
, threadref
*src
);
2069 static int threadmatch (threadref
*dest
, threadref
*src
);
2071 static char *pack_threadinfo_request (char *pkt
, int mode
,
2074 static int remote_unpack_thread_info_response (char *pkt
,
2075 threadref
*expectedref
,
2076 struct gdb_ext_thread_info
2080 static int remote_get_threadinfo (threadref
*threadid
,
2081 int fieldset
, /*TAG mask */
2082 struct gdb_ext_thread_info
*info
);
2084 static char *pack_threadlist_request (char *pkt
, int startflag
,
2086 threadref
*nextthread
);
2088 static int parse_threadlist_response (char *pkt
,
2090 threadref
*original_echo
,
2091 threadref
*resultlist
,
2094 static int remote_get_threadlist (int startflag
,
2095 threadref
*nextthread
,
2099 threadref
*threadlist
);
2101 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2103 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2104 void *context
, int looplimit
);
2106 static int remote_newthread_step (threadref
*ref
, void *context
);
2109 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2110 buffer we're allowed to write to. Returns
2111 BUF+CHARACTERS_WRITTEN. */
2114 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2117 struct remote_state
*rs
= get_remote_state ();
2119 if (remote_multi_process_p (rs
))
2121 pid
= ptid_get_pid (ptid
);
2123 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2125 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2127 tid
= ptid_get_lwp (ptid
);
2129 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2131 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2136 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2137 passed the last parsed char. Returns null_ptid on error. */
2140 read_ptid (char *buf
, char **obuf
)
2144 ULONGEST pid
= 0, tid
= 0;
2148 /* Multi-process ptid. */
2149 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2151 error (_("invalid remote ptid: %s"), p
);
2154 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2157 return ptid_build (pid
, tid
, 0);
2160 /* No multi-process. Just a tid. */
2161 pp
= unpack_varlen_hex (p
, &tid
);
2163 /* Return null_ptid when no thread id is found. */
2171 /* Since the stub is not sending a process id, then default to
2172 what's in inferior_ptid, unless it's null at this point. If so,
2173 then since there's no way to know the pid of the reported
2174 threads, use the magic number. */
2175 if (ptid_equal (inferior_ptid
, null_ptid
))
2176 pid
= ptid_get_pid (magic_null_ptid
);
2178 pid
= ptid_get_pid (inferior_ptid
);
2182 return ptid_build (pid
, tid
, 0);
2188 if (ch
>= 'a' && ch
<= 'f')
2189 return ch
- 'a' + 10;
2190 if (ch
>= '0' && ch
<= '9')
2192 if (ch
>= 'A' && ch
<= 'F')
2193 return ch
- 'A' + 10;
2198 stub_unpack_int (char *buff
, int fieldlength
)
2205 nibble
= stubhex (*buff
++);
2209 retval
= retval
<< 4;
2215 unpack_nibble (char *buf
, int *val
)
2217 *val
= fromhex (*buf
++);
2222 unpack_byte (char *buf
, int *value
)
2224 *value
= stub_unpack_int (buf
, 2);
2229 pack_int (char *buf
, int value
)
2231 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2232 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2233 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2234 buf
= pack_hex_byte (buf
, (value
& 0xff));
2239 unpack_int (char *buf
, int *value
)
2241 *value
= stub_unpack_int (buf
, 8);
2245 #if 0 /* Currently unused, uncomment when needed. */
2246 static char *pack_string (char *pkt
, char *string
);
2249 pack_string (char *pkt
, char *string
)
2254 len
= strlen (string
);
2256 len
= 200; /* Bigger than most GDB packets, junk??? */
2257 pkt
= pack_hex_byte (pkt
, len
);
2261 if ((ch
== '\0') || (ch
== '#'))
2262 ch
= '*'; /* Protect encapsulation. */
2267 #endif /* 0 (unused) */
2270 unpack_string (char *src
, char *dest
, int length
)
2279 pack_threadid (char *pkt
, threadref
*id
)
2282 unsigned char *altid
;
2284 altid
= (unsigned char *) id
;
2285 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2287 pkt
= pack_hex_byte (pkt
, *altid
++);
2293 unpack_threadid (char *inbuf
, threadref
*id
)
2296 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2299 altref
= (char *) id
;
2301 while (inbuf
< limit
)
2303 x
= stubhex (*inbuf
++);
2304 y
= stubhex (*inbuf
++);
2305 *altref
++ = (x
<< 4) | y
;
2310 /* Externally, threadrefs are 64 bits but internally, they are still
2311 ints. This is due to a mismatch of specifications. We would like
2312 to use 64bit thread references internally. This is an adapter
2316 int_to_threadref (threadref
*id
, int value
)
2318 unsigned char *scan
;
2320 scan
= (unsigned char *) id
;
2326 *scan
++ = (value
>> 24) & 0xff;
2327 *scan
++ = (value
>> 16) & 0xff;
2328 *scan
++ = (value
>> 8) & 0xff;
2329 *scan
++ = (value
& 0xff);
2333 threadref_to_int (threadref
*ref
)
2336 unsigned char *scan
;
2342 value
= (value
<< 8) | ((*scan
++) & 0xff);
2347 copy_threadref (threadref
*dest
, threadref
*src
)
2350 unsigned char *csrc
, *cdest
;
2352 csrc
= (unsigned char *) src
;
2353 cdest
= (unsigned char *) dest
;
2360 threadmatch (threadref
*dest
, threadref
*src
)
2362 /* Things are broken right now, so just assume we got a match. */
2364 unsigned char *srcp
, *destp
;
2366 srcp
= (char *) src
;
2367 destp
= (char *) dest
;
2371 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2378 threadid:1, # always request threadid
2385 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2388 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2390 *pkt
++ = 'q'; /* Info Query */
2391 *pkt
++ = 'P'; /* process or thread info */
2392 pkt
= pack_int (pkt
, mode
); /* mode */
2393 pkt
= pack_threadid (pkt
, id
); /* threadid */
2394 *pkt
= '\0'; /* terminate */
2398 /* These values tag the fields in a thread info response packet. */
2399 /* Tagging the fields allows us to request specific fields and to
2400 add more fields as time goes by. */
2402 #define TAG_THREADID 1 /* Echo the thread identifier. */
2403 #define TAG_EXISTS 2 /* Is this process defined enough to
2404 fetch registers and its stack? */
2405 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2406 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2407 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2411 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2412 struct gdb_ext_thread_info
*info
)
2414 struct remote_state
*rs
= get_remote_state ();
2418 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2421 /* info->threadid = 0; FIXME: implement zero_threadref. */
2423 info
->display
[0] = '\0';
2424 info
->shortname
[0] = '\0';
2425 info
->more_display
[0] = '\0';
2427 /* Assume the characters indicating the packet type have been
2429 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2430 pkt
= unpack_threadid (pkt
, &ref
);
2433 warning (_("Incomplete response to threadinfo request."));
2434 if (!threadmatch (&ref
, expectedref
))
2435 { /* This is an answer to a different request. */
2436 warning (_("ERROR RMT Thread info mismatch."));
2439 copy_threadref (&info
->threadid
, &ref
);
2441 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2443 /* Packets are terminated with nulls. */
2444 while ((pkt
< limit
) && mask
&& *pkt
)
2446 pkt
= unpack_int (pkt
, &tag
); /* tag */
2447 pkt
= unpack_byte (pkt
, &length
); /* length */
2448 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2450 warning (_("ERROR RMT: threadinfo tag mismatch."));
2454 if (tag
== TAG_THREADID
)
2458 warning (_("ERROR RMT: length of threadid is not 16."));
2462 pkt
= unpack_threadid (pkt
, &ref
);
2463 mask
= mask
& ~TAG_THREADID
;
2466 if (tag
== TAG_EXISTS
)
2468 info
->active
= stub_unpack_int (pkt
, length
);
2470 mask
= mask
& ~(TAG_EXISTS
);
2473 warning (_("ERROR RMT: 'exists' length too long."));
2479 if (tag
== TAG_THREADNAME
)
2481 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2482 mask
= mask
& ~TAG_THREADNAME
;
2485 if (tag
== TAG_DISPLAY
)
2487 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2488 mask
= mask
& ~TAG_DISPLAY
;
2491 if (tag
== TAG_MOREDISPLAY
)
2493 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2494 mask
= mask
& ~TAG_MOREDISPLAY
;
2497 warning (_("ERROR RMT: unknown thread info tag."));
2498 break; /* Not a tag we know about. */
2504 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2505 struct gdb_ext_thread_info
*info
)
2507 struct remote_state
*rs
= get_remote_state ();
2510 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2512 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2514 if (rs
->buf
[0] == '\0')
2517 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2522 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2525 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2526 threadref
*nextthread
)
2528 *pkt
++ = 'q'; /* info query packet */
2529 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2530 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2531 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2532 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2537 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2540 parse_threadlist_response (char *pkt
, int result_limit
,
2541 threadref
*original_echo
, threadref
*resultlist
,
2544 struct remote_state
*rs
= get_remote_state ();
2546 int count
, resultcount
, done
;
2549 /* Assume the 'q' and 'M chars have been stripped. */
2550 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2551 /* done parse past here */
2552 pkt
= unpack_byte (pkt
, &count
); /* count field */
2553 pkt
= unpack_nibble (pkt
, &done
);
2554 /* The first threadid is the argument threadid. */
2555 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2556 while ((count
-- > 0) && (pkt
< limit
))
2558 pkt
= unpack_threadid (pkt
, resultlist
++);
2559 if (resultcount
++ >= result_limit
)
2567 /* Fetch the next batch of threads from the remote. Returns -1 if the
2568 qL packet is not supported, 0 on error and 1 on success. */
2571 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2572 int *done
, int *result_count
, threadref
*threadlist
)
2574 struct remote_state
*rs
= get_remote_state ();
2577 /* Trancate result limit to be smaller than the packet size. */
2578 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2579 >= get_remote_packet_size ())
2580 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2582 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2584 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2585 if (*rs
->buf
== '\0')
2587 /* Packet not supported. */
2592 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2593 &rs
->echo_nextthread
, threadlist
, done
);
2595 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2597 /* FIXME: This is a good reason to drop the packet. */
2598 /* Possably, there is a duplicate response. */
2600 retransmit immediatly - race conditions
2601 retransmit after timeout - yes
2603 wait for packet, then exit
2605 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2606 return 0; /* I choose simply exiting. */
2608 if (*result_count
<= 0)
2612 warning (_("RMT ERROR : failed to get remote thread list."));
2615 return result
; /* break; */
2617 if (*result_count
> result_limit
)
2620 warning (_("RMT ERROR: threadlist response longer than requested."));
2626 /* Fetch the list of remote threads, with the qL packet, and call
2627 STEPFUNCTION for each thread found. Stops iterating and returns 1
2628 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2629 STEPFUNCTION returns false. If the packet is not supported,
2633 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2636 struct remote_state
*rs
= get_remote_state ();
2637 int done
, i
, result_count
;
2645 if (loopcount
++ > looplimit
)
2648 warning (_("Remote fetch threadlist -infinite loop-."));
2651 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2652 MAXTHREADLISTRESULTS
,
2653 &done
, &result_count
,
2654 rs
->resultthreadlist
);
2657 /* Clear for later iterations. */
2659 /* Setup to resume next batch of thread references, set nextthread. */
2660 if (result_count
>= 1)
2661 copy_threadref (&rs
->nextthread
,
2662 &rs
->resultthreadlist
[result_count
- 1]);
2664 while (result_count
--)
2666 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2676 /* A thread found on the remote target. */
2678 typedef struct thread_item
2680 /* The thread's PTID. */
2683 /* The thread's extra info. May be NULL. */
2686 /* The core the thread was running on. -1 if not known. */
2689 DEF_VEC_O(thread_item_t
);
2691 /* Context passed around to the various methods listing remote
2692 threads. As new threads are found, they're added to the ITEMS
2695 struct threads_listing_context
2697 /* The threads found on the remote target. */
2698 VEC (thread_item_t
) *items
;
2701 /* Discard the contents of the constructed thread listing context. */
2704 clear_threads_listing_context (void *p
)
2706 struct threads_listing_context
*context
= p
;
2708 struct thread_item
*item
;
2710 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2711 xfree (item
->extra
);
2713 VEC_free (thread_item_t
, context
->items
);
2716 /* Remove the thread specified as the related_pid field of WS
2717 from the CONTEXT list. */
2720 threads_listing_context_remove (struct target_waitstatus
*ws
,
2721 struct threads_listing_context
*context
)
2723 struct thread_item
*item
;
2725 ptid_t child_ptid
= ws
->value
.related_pid
;
2727 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2729 if (ptid_equal (item
->ptid
, child_ptid
))
2731 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2738 remote_newthread_step (threadref
*ref
, void *data
)
2740 struct threads_listing_context
*context
= data
;
2741 struct thread_item item
;
2742 int pid
= ptid_get_pid (inferior_ptid
);
2744 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2748 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2750 return 1; /* continue iterator */
2753 #define CRAZY_MAX_THREADS 1000
2756 remote_current_thread (ptid_t oldpid
)
2758 struct remote_state
*rs
= get_remote_state ();
2761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2762 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2767 result
= read_ptid (&rs
->buf
[2], &obuf
);
2768 if (*obuf
!= '\0' && remote_debug
)
2769 fprintf_unfiltered (gdb_stdlog
,
2770 "warning: garbage in qC reply\n");
2778 /* List remote threads using the deprecated qL packet. */
2781 remote_get_threads_with_ql (struct target_ops
*ops
,
2782 struct threads_listing_context
*context
)
2784 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2785 CRAZY_MAX_THREADS
) >= 0)
2791 #if defined(HAVE_LIBEXPAT)
2794 start_thread (struct gdb_xml_parser
*parser
,
2795 const struct gdb_xml_element
*element
,
2796 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2798 struct threads_listing_context
*data
= user_data
;
2800 struct thread_item item
;
2802 struct gdb_xml_value
*attr
;
2804 id
= xml_find_attribute (attributes
, "id")->value
;
2805 item
.ptid
= read_ptid (id
, NULL
);
2807 attr
= xml_find_attribute (attributes
, "core");
2809 item
.core
= *(ULONGEST
*) attr
->value
;
2815 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2819 end_thread (struct gdb_xml_parser
*parser
,
2820 const struct gdb_xml_element
*element
,
2821 void *user_data
, const char *body_text
)
2823 struct threads_listing_context
*data
= user_data
;
2825 if (body_text
&& *body_text
)
2826 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2829 const struct gdb_xml_attribute thread_attributes
[] = {
2830 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2831 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2832 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2835 const struct gdb_xml_element thread_children
[] = {
2836 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2839 const struct gdb_xml_element threads_children
[] = {
2840 { "thread", thread_attributes
, thread_children
,
2841 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2842 start_thread
, end_thread
},
2843 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2846 const struct gdb_xml_element threads_elements
[] = {
2847 { "threads", NULL
, threads_children
,
2848 GDB_XML_EF_NONE
, NULL
, NULL
},
2849 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2854 /* List remote threads using qXfer:threads:read. */
2857 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2858 struct threads_listing_context
*context
)
2860 #if defined(HAVE_LIBEXPAT)
2861 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2863 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2864 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2866 if (xml
!= NULL
&& *xml
!= '\0')
2868 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2869 threads_elements
, xml
, context
);
2872 do_cleanups (back_to
);
2880 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2883 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2884 struct threads_listing_context
*context
)
2886 struct remote_state
*rs
= get_remote_state ();
2888 if (rs
->use_threadinfo_query
)
2892 putpkt ("qfThreadInfo");
2893 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2895 if (bufp
[0] != '\0') /* q packet recognized */
2897 while (*bufp
++ == 'm') /* reply contains one or more TID */
2901 struct thread_item item
;
2903 item
.ptid
= read_ptid (bufp
, &bufp
);
2907 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2909 while (*bufp
++ == ','); /* comma-separated list */
2910 putpkt ("qsThreadInfo");
2911 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2918 /* Packet not recognized. */
2919 rs
->use_threadinfo_query
= 0;
2926 /* Implement the to_update_thread_list function for the remote
2930 remote_update_thread_list (struct target_ops
*ops
)
2932 struct remote_state
*rs
= get_remote_state ();
2933 struct threads_listing_context context
;
2934 struct cleanup
*old_chain
;
2937 context
.items
= NULL
;
2938 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2940 /* We have a few different mechanisms to fetch the thread list. Try
2941 them all, starting with the most preferred one first, falling
2942 back to older methods. */
2943 if (remote_get_threads_with_qxfer (ops
, &context
)
2944 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2945 || remote_get_threads_with_ql (ops
, &context
))
2948 struct thread_item
*item
;
2949 struct thread_info
*tp
, *tmp
;
2953 if (VEC_empty (thread_item_t
, context
.items
)
2954 && remote_thread_always_alive (ops
, inferior_ptid
))
2956 /* Some targets don't really support threads, but still
2957 reply an (empty) thread list in response to the thread
2958 listing packets, instead of replying "packet not
2959 supported". Exit early so we don't delete the main
2961 do_cleanups (old_chain
);
2965 /* CONTEXT now holds the current thread list on the remote
2966 target end. Delete GDB-side threads no longer found on the
2968 ALL_THREADS_SAFE (tp
, tmp
)
2971 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2974 if (ptid_equal (item
->ptid
, tp
->ptid
))
2978 if (i
== VEC_length (thread_item_t
, context
.items
))
2981 delete_thread (tp
->ptid
);
2985 /* Remove any unreported fork child threads from CONTEXT so
2986 that we don't interfere with follow fork, which is where
2987 creation of such threads is handled. */
2988 remove_new_fork_children (&context
);
2990 /* And now add threads we don't know about yet to our list. */
2992 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2995 if (!ptid_equal (item
->ptid
, null_ptid
))
2997 struct private_thread_info
*info
;
2998 /* In non-stop mode, we assume new found threads are
2999 running until proven otherwise with a stop reply. In
3000 all-stop, we can only get here if all threads are
3002 int running
= non_stop
? 1 : 0;
3004 remote_notice_new_inferior (item
->ptid
, running
);
3006 info
= demand_private_info (item
->ptid
);
3007 info
->core
= item
->core
;
3008 info
->extra
= item
->extra
;
3016 /* If no thread listing method is supported, then query whether
3017 each known thread is alive, one by one, with the T packet.
3018 If the target doesn't support threads at all, then this is a
3019 no-op. See remote_thread_alive. */
3023 do_cleanups (old_chain
);
3027 * Collect a descriptive string about the given thread.
3028 * The target may say anything it wants to about the thread
3029 * (typically info about its blocked / runnable state, name, etc.).
3030 * This string will appear in the info threads display.
3032 * Optional: targets are not required to implement this function.
3036 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3038 struct remote_state
*rs
= get_remote_state ();
3042 struct gdb_ext_thread_info threadinfo
;
3043 static char display_buf
[100]; /* arbitrary... */
3044 int n
= 0; /* position in display_buf */
3046 if (rs
->remote_desc
== 0) /* paranoia */
3047 internal_error (__FILE__
, __LINE__
,
3048 _("remote_threads_extra_info"));
3050 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3051 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3052 /* This is the main thread which was added by GDB. The remote
3053 server doesn't know about it. */
3056 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3058 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3060 if (info
&& info
->priv
)
3061 return info
->priv
->extra
;
3066 if (rs
->use_threadextra_query
)
3069 char *endb
= rs
->buf
+ get_remote_packet_size ();
3071 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3073 write_ptid (b
, endb
, tp
->ptid
);
3076 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3077 if (rs
->buf
[0] != 0)
3079 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3080 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3081 display_buf
[result
] = '\0';
3086 /* If the above query fails, fall back to the old method. */
3087 rs
->use_threadextra_query
= 0;
3088 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3089 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3090 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3091 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3092 if (threadinfo
.active
)
3094 if (*threadinfo
.shortname
)
3095 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3096 " Name: %s,", threadinfo
.shortname
);
3097 if (*threadinfo
.display
)
3098 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3099 " State: %s,", threadinfo
.display
);
3100 if (*threadinfo
.more_display
)
3101 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3102 " Priority: %s", threadinfo
.more_display
);
3106 /* For purely cosmetic reasons, clear up trailing commas. */
3107 if (',' == display_buf
[n
-1])
3108 display_buf
[n
-1] = ' ';
3117 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3118 struct static_tracepoint_marker
*marker
)
3120 struct remote_state
*rs
= get_remote_state ();
3123 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3125 p
+= hexnumstr (p
, addr
);
3127 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3131 error (_("Remote failure reply: %s"), p
);
3135 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3142 static VEC(static_tracepoint_marker_p
) *
3143 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3146 struct remote_state
*rs
= get_remote_state ();
3147 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3148 struct static_tracepoint_marker
*marker
= NULL
;
3149 struct cleanup
*old_chain
;
3152 /* Ask for a first packet of static tracepoint marker
3155 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3158 error (_("Remote failure reply: %s"), p
);
3160 old_chain
= make_cleanup (free_current_marker
, &marker
);
3165 marker
= XCNEW (struct static_tracepoint_marker
);
3169 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3171 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3173 VEC_safe_push (static_tracepoint_marker_p
,
3179 release_static_tracepoint_marker (marker
);
3180 memset (marker
, 0, sizeof (*marker
));
3183 while (*p
++ == ','); /* comma-separated list */
3184 /* Ask for another packet of static tracepoint definition. */
3186 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3190 do_cleanups (old_chain
);
3195 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3198 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3200 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3204 /* Restart the remote side; this is an extended protocol operation. */
3207 extended_remote_restart (void)
3209 struct remote_state
*rs
= get_remote_state ();
3211 /* Send the restart command; for reasons I don't understand the
3212 remote side really expects a number after the "R". */
3213 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3216 remote_fileio_reset ();
3219 /* Clean up connection to a remote debugger. */
3222 remote_close (struct target_ops
*self
)
3224 struct remote_state
*rs
= get_remote_state ();
3226 if (rs
->remote_desc
== NULL
)
3227 return; /* already closed */
3229 /* Make sure we leave stdin registered in the event loop, and we
3230 don't leave the async SIGINT signal handler installed. */
3231 remote_terminal_ours (self
);
3233 serial_close (rs
->remote_desc
);
3234 rs
->remote_desc
= NULL
;
3236 /* We don't have a connection to the remote stub anymore. Get rid
3237 of all the inferiors and their threads we were controlling.
3238 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3239 will be unable to find the thread corresponding to (pid, 0, 0). */
3240 inferior_ptid
= null_ptid
;
3241 discard_all_inferiors ();
3243 /* We are closing the remote target, so we should discard
3244 everything of this target. */
3245 discard_pending_stop_replies_in_queue (rs
);
3247 if (remote_async_inferior_event_token
)
3248 delete_async_event_handler (&remote_async_inferior_event_token
);
3250 remote_notif_state_xfree (rs
->notif_state
);
3252 trace_reset_local_state ();
3255 /* Query the remote side for the text, data and bss offsets. */
3260 struct remote_state
*rs
= get_remote_state ();
3263 int lose
, num_segments
= 0, do_sections
, do_segments
;
3264 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3265 struct section_offsets
*offs
;
3266 struct symfile_segment_data
*data
;
3268 if (symfile_objfile
== NULL
)
3271 putpkt ("qOffsets");
3272 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3275 if (buf
[0] == '\000')
3276 return; /* Return silently. Stub doesn't support
3280 warning (_("Remote failure reply: %s"), buf
);
3284 /* Pick up each field in turn. This used to be done with scanf, but
3285 scanf will make trouble if CORE_ADDR size doesn't match
3286 conversion directives correctly. The following code will work
3287 with any size of CORE_ADDR. */
3288 text_addr
= data_addr
= bss_addr
= 0;
3292 if (startswith (ptr
, "Text="))
3295 /* Don't use strtol, could lose on big values. */
3296 while (*ptr
&& *ptr
!= ';')
3297 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3299 if (startswith (ptr
, ";Data="))
3302 while (*ptr
&& *ptr
!= ';')
3303 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3308 if (!lose
&& startswith (ptr
, ";Bss="))
3311 while (*ptr
&& *ptr
!= ';')
3312 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3314 if (bss_addr
!= data_addr
)
3315 warning (_("Target reported unsupported offsets: %s"), buf
);
3320 else if (startswith (ptr
, "TextSeg="))
3323 /* Don't use strtol, could lose on big values. */
3324 while (*ptr
&& *ptr
!= ';')
3325 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3328 if (startswith (ptr
, ";DataSeg="))
3331 while (*ptr
&& *ptr
!= ';')
3332 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3340 error (_("Malformed response to offset query, %s"), buf
);
3341 else if (*ptr
!= '\0')
3342 warning (_("Target reported unsupported offsets: %s"), buf
);
3344 offs
= ((struct section_offsets
*)
3345 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3346 memcpy (offs
, symfile_objfile
->section_offsets
,
3347 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3349 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3350 do_segments
= (data
!= NULL
);
3351 do_sections
= num_segments
== 0;
3353 if (num_segments
> 0)
3355 segments
[0] = text_addr
;
3356 segments
[1] = data_addr
;
3358 /* If we have two segments, we can still try to relocate everything
3359 by assuming that the .text and .data offsets apply to the whole
3360 text and data segments. Convert the offsets given in the packet
3361 to base addresses for symfile_map_offsets_to_segments. */
3362 else if (data
&& data
->num_segments
== 2)
3364 segments
[0] = data
->segment_bases
[0] + text_addr
;
3365 segments
[1] = data
->segment_bases
[1] + data_addr
;
3368 /* If the object file has only one segment, assume that it is text
3369 rather than data; main programs with no writable data are rare,
3370 but programs with no code are useless. Of course the code might
3371 have ended up in the data segment... to detect that we would need
3372 the permissions here. */
3373 else if (data
&& data
->num_segments
== 1)
3375 segments
[0] = data
->segment_bases
[0] + text_addr
;
3378 /* There's no way to relocate by segment. */
3384 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3385 offs
, num_segments
, segments
);
3387 if (ret
== 0 && !do_sections
)
3388 error (_("Can not handle qOffsets TextSeg "
3389 "response with this symbol file"));
3396 free_symfile_segment_data (data
);
3400 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3402 /* This is a temporary kludge to force data and bss to use the
3403 same offsets because that's what nlmconv does now. The real
3404 solution requires changes to the stub and remote.c that I
3405 don't have time to do right now. */
3407 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3408 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3411 objfile_relocate (symfile_objfile
, offs
);
3414 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3415 threads we know are stopped already. This is used during the
3416 initial remote connection in non-stop mode --- threads that are
3417 reported as already being stopped are left stopped. */
3420 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3422 /* If we have a stop reply for this thread, it must be stopped. */
3423 if (peek_stop_reply (thread
->ptid
))
3424 set_stop_requested (thread
->ptid
, 1);
3429 /* Send interrupt_sequence to remote target. */
3431 send_interrupt_sequence (void)
3433 struct remote_state
*rs
= get_remote_state ();
3435 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3436 remote_serial_write ("\x03", 1);
3437 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3438 serial_send_break (rs
->remote_desc
);
3439 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3441 serial_send_break (rs
->remote_desc
);
3442 remote_serial_write ("g", 1);
3445 internal_error (__FILE__
, __LINE__
,
3446 _("Invalid value for interrupt_sequence_mode: %s."),
3447 interrupt_sequence_mode
);
3451 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3452 and extract the PTID. Returns NULL_PTID if not found. */
3455 stop_reply_extract_thread (char *stop_reply
)
3457 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3461 /* Txx r:val ; r:val (...) */
3464 /* Look for "register" named "thread". */
3469 p1
= strchr (p
, ':');
3473 if (strncmp (p
, "thread", p1
- p
) == 0)
3474 return read_ptid (++p1
, &p
);
3476 p1
= strchr (p
, ';');
3488 /* Determine the remote side's current thread. If we have a stop
3489 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3490 "thread" register we can extract the current thread from. If not,
3491 ask the remote which is the current thread with qC. The former
3492 method avoids a roundtrip. */
3495 get_current_thread (char *wait_status
)
3497 ptid_t ptid
= null_ptid
;
3499 /* Note we don't use remote_parse_stop_reply as that makes use of
3500 the target architecture, which we haven't yet fully determined at
3502 if (wait_status
!= NULL
)
3503 ptid
= stop_reply_extract_thread (wait_status
);
3504 if (ptid_equal (ptid
, null_ptid
))
3505 ptid
= remote_current_thread (inferior_ptid
);
3510 /* Query the remote target for which is the current thread/process,
3511 add it to our tables, and update INFERIOR_PTID. The caller is
3512 responsible for setting the state such that the remote end is ready
3513 to return the current thread.
3515 This function is called after handling the '?' or 'vRun' packets,
3516 whose response is a stop reply from which we can also try
3517 extracting the thread. If the target doesn't support the explicit
3518 qC query, we infer the current thread from that stop reply, passed
3519 in in WAIT_STATUS, which may be NULL. */
3522 add_current_inferior_and_thread (char *wait_status
)
3524 struct remote_state
*rs
= get_remote_state ();
3528 inferior_ptid
= null_ptid
;
3530 /* Now, if we have thread information, update inferior_ptid. */
3531 ptid
= get_current_thread (wait_status
);
3533 if (!ptid_equal (ptid
, null_ptid
))
3535 if (!remote_multi_process_p (rs
))
3538 inferior_ptid
= ptid
;
3542 /* Without this, some commands which require an active target
3543 (such as kill) won't work. This variable serves (at least)
3544 double duty as both the pid of the target process (if it has
3545 such), and as a flag indicating that a target is active. */
3546 inferior_ptid
= magic_null_ptid
;
3550 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3552 /* Add the main thread. */
3553 add_thread_silent (inferior_ptid
);
3557 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3559 struct remote_state
*rs
= get_remote_state ();
3560 struct packet_config
*noack_config
;
3561 char *wait_status
= NULL
;
3563 immediate_quit
++; /* Allow user to interrupt it. */
3566 if (interrupt_on_connect
)
3567 send_interrupt_sequence ();
3569 /* Ack any packet which the remote side has already sent. */
3570 serial_write (rs
->remote_desc
, "+", 1);
3572 /* Signal other parts that we're going through the initial setup,
3573 and so things may not be stable yet. */
3574 rs
->starting_up
= 1;
3576 /* The first packet we send to the target is the optional "supported
3577 packets" request. If the target can answer this, it will tell us
3578 which later probes to skip. */
3579 remote_query_supported ();
3581 /* If the stub wants to get a QAllow, compose one and send it. */
3582 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3583 remote_set_permissions (target
);
3585 /* Next, we possibly activate noack mode.
3587 If the QStartNoAckMode packet configuration is set to AUTO,
3588 enable noack mode if the stub reported a wish for it with
3591 If set to TRUE, then enable noack mode even if the stub didn't
3592 report it in qSupported. If the stub doesn't reply OK, the
3593 session ends with an error.
3595 If FALSE, then don't activate noack mode, regardless of what the
3596 stub claimed should be the default with qSupported. */
3598 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3599 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3601 putpkt ("QStartNoAckMode");
3602 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3603 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3609 /* Tell the remote that we are using the extended protocol. */
3611 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3614 /* Let the target know which signals it is allowed to pass down to
3616 update_signals_program_target ();
3618 /* Next, if the target can specify a description, read it. We do
3619 this before anything involving memory or registers. */
3620 target_find_description ();
3622 /* Next, now that we know something about the target, update the
3623 address spaces in the program spaces. */
3624 update_address_spaces ();
3626 /* On OSs where the list of libraries is global to all
3627 processes, we fetch them early. */
3628 if (gdbarch_has_global_solist (target_gdbarch ()))
3629 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3633 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3634 error (_("Non-stop mode requested, but remote "
3635 "does not support non-stop"));
3637 putpkt ("QNonStop:1");
3638 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3640 if (strcmp (rs
->buf
, "OK") != 0)
3641 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3643 /* Find about threads and processes the stub is already
3644 controlling. We default to adding them in the running state.
3645 The '?' query below will then tell us about which threads are
3647 remote_update_thread_list (target
);
3649 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3651 /* Don't assume that the stub can operate in all-stop mode.
3652 Request it explicitly. */
3653 putpkt ("QNonStop:0");
3654 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3656 if (strcmp (rs
->buf
, "OK") != 0)
3657 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3660 /* Upload TSVs regardless of whether the target is running or not. The
3661 remote stub, such as GDBserver, may have some predefined or builtin
3662 TSVs, even if the target is not running. */
3663 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3665 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3667 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3668 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3671 /* Check whether the target is running now. */
3673 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3679 struct inferior
*inf
;
3681 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3684 error (_("The target is not running (try extended-remote?)"));
3686 /* We're connected, but not running. Drop out before we
3687 call start_remote. */
3688 rs
->starting_up
= 0;
3693 /* Save the reply for later. */
3694 wait_status
= alloca (strlen (rs
->buf
) + 1);
3695 strcpy (wait_status
, rs
->buf
);
3698 /* Fetch thread list. */
3699 target_update_thread_list ();
3701 /* Let the stub know that we want it to return the thread. */
3702 set_continue_thread (minus_one_ptid
);
3704 if (thread_count () == 0)
3706 /* Target has no concept of threads at all. GDB treats
3707 non-threaded target as single-threaded; add a main
3709 add_current_inferior_and_thread (wait_status
);
3713 /* We have thread information; select the thread the target
3714 says should be current. If we're reconnecting to a
3715 multi-threaded program, this will ideally be the thread
3716 that last reported an event before GDB disconnected. */
3717 inferior_ptid
= get_current_thread (wait_status
);
3718 if (ptid_equal (inferior_ptid
, null_ptid
))
3720 /* Odd... The target was able to list threads, but not
3721 tell us which thread was current (no "thread"
3722 register in T stop reply?). Just pick the first
3723 thread in the thread list then. */
3726 fprintf_unfiltered (gdb_stdlog
,
3727 "warning: couldn't determine remote "
3728 "current thread; picking first in list.\n");
3730 inferior_ptid
= thread_list
->ptid
;
3734 /* init_wait_for_inferior should be called before get_offsets in order
3735 to manage `inserted' flag in bp loc in a correct state.
3736 breakpoint_init_inferior, called from init_wait_for_inferior, set
3737 `inserted' flag to 0, while before breakpoint_re_set, called from
3738 start_remote, set `inserted' flag to 1. In the initialization of
3739 inferior, breakpoint_init_inferior should be called first, and then
3740 breakpoint_re_set can be called. If this order is broken, state of
3741 `inserted' flag is wrong, and cause some problems on breakpoint
3743 init_wait_for_inferior ();
3745 get_offsets (); /* Get text, data & bss offsets. */
3747 /* If we could not find a description using qXfer, and we know
3748 how to do it some other way, try again. This is not
3749 supported for non-stop; it could be, but it is tricky if
3750 there are no stopped threads when we connect. */
3751 if (remote_read_description_p (target
)
3752 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3754 target_clear_description ();
3755 target_find_description ();
3758 /* Use the previously fetched status. */
3759 gdb_assert (wait_status
!= NULL
);
3760 strcpy (rs
->buf
, wait_status
);
3761 rs
->cached_wait_status
= 1;
3764 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3768 /* Clear WFI global state. Do this before finding about new
3769 threads and inferiors, and setting the current inferior.
3770 Otherwise we would clear the proceed status of the current
3771 inferior when we want its stop_soon state to be preserved
3772 (see notice_new_inferior). */
3773 init_wait_for_inferior ();
3775 /* In non-stop, we will either get an "OK", meaning that there
3776 are no stopped threads at this time; or, a regular stop
3777 reply. In the latter case, there may be more than one thread
3778 stopped --- we pull them all out using the vStopped
3780 if (strcmp (rs
->buf
, "OK") != 0)
3782 struct notif_client
*notif
= ¬if_client_stop
;
3784 /* remote_notif_get_pending_replies acks this one, and gets
3786 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3787 = remote_notif_parse (notif
, rs
->buf
);
3788 remote_notif_get_pending_events (notif
);
3790 /* Make sure that threads that were stopped remain
3792 iterate_over_threads (set_stop_requested_callback
, NULL
);
3795 if (target_can_async_p ())
3798 if (thread_count () == 0)
3801 error (_("The target is not running (try extended-remote?)"));
3803 /* We're connected, but not running. Drop out before we
3804 call start_remote. */
3805 rs
->starting_up
= 0;
3809 /* Let the stub know that we want it to return the thread. */
3811 /* Force the stub to choose a thread. */
3812 set_general_thread (null_ptid
);
3815 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3816 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3817 error (_("remote didn't report the current thread in non-stop mode"));
3819 get_offsets (); /* Get text, data & bss offsets. */
3821 /* In non-stop mode, any cached wait status will be stored in
3822 the stop reply queue. */
3823 gdb_assert (wait_status
== NULL
);
3825 /* Report all signals during attach/startup. */
3826 remote_pass_signals (target
, 0, NULL
);
3829 /* If we connected to a live target, do some additional setup. */
3830 if (target_has_execution
)
3832 if (symfile_objfile
) /* No use without a symbol-file. */
3833 remote_check_symbols ();
3836 /* Possibly the target has been engaged in a trace run started
3837 previously; find out where things are at. */
3838 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3840 struct uploaded_tp
*uploaded_tps
= NULL
;
3842 if (current_trace_status ()->running
)
3843 printf_filtered (_("Trace is already running on the target.\n"));
3845 remote_upload_tracepoints (target
, &uploaded_tps
);
3847 merge_uploaded_tracepoints (&uploaded_tps
);
3850 /* The thread and inferior lists are now synchronized with the
3851 target, our symbols have been relocated, and we're merged the
3852 target's tracepoints with ours. We're done with basic start
3854 rs
->starting_up
= 0;
3856 /* Maybe breakpoints are global and need to be inserted now. */
3857 if (breakpoints_should_be_inserted_now ())
3858 insert_breakpoints ();
3861 /* Open a connection to a remote debugger.
3862 NAME is the filename used for communication. */
3865 remote_open (const char *name
, int from_tty
)
3867 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3870 /* Open a connection to a remote debugger using the extended
3871 remote gdb protocol. NAME is the filename used for communication. */
3874 extended_remote_open (const char *name
, int from_tty
)
3876 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3879 /* Reset all packets back to "unknown support". Called when opening a
3880 new connection to a remote target. */
3883 reset_all_packet_configs_support (void)
3887 for (i
= 0; i
< PACKET_MAX
; i
++)
3888 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3891 /* Initialize all packet configs. */
3894 init_all_packet_configs (void)
3898 for (i
= 0; i
< PACKET_MAX
; i
++)
3900 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3901 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3905 /* Symbol look-up. */
3908 remote_check_symbols (void)
3910 struct remote_state
*rs
= get_remote_state ();
3911 char *msg
, *reply
, *tmp
;
3912 struct bound_minimal_symbol sym
;
3915 /* The remote side has no concept of inferiors that aren't running
3916 yet, it only knows about running processes. If we're connected
3917 but our current inferior is not running, we should not invite the
3918 remote target to request symbol lookups related to its
3919 (unrelated) current process. */
3920 if (!target_has_execution
)
3923 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3926 /* Make sure the remote is pointing at the right process. Note
3927 there's no way to select "no process". */
3928 set_general_process ();
3930 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3931 because we need both at the same time. */
3932 msg
= alloca (get_remote_packet_size ());
3934 /* Invite target to request symbol lookups. */
3936 putpkt ("qSymbol::");
3937 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3938 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3941 while (startswith (reply
, "qSymbol:"))
3943 struct bound_minimal_symbol sym
;
3946 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3948 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3949 if (sym
.minsym
== NULL
)
3950 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3953 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3954 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3956 /* If this is a function address, return the start of code
3957 instead of any data function descriptor. */
3958 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3962 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3963 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3967 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3972 static struct serial
*
3973 remote_serial_open (const char *name
)
3975 static int udp_warning
= 0;
3977 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3978 of in ser-tcp.c, because it is the remote protocol assuming that the
3979 serial connection is reliable and not the serial connection promising
3981 if (!udp_warning
&& startswith (name
, "udp:"))
3983 warning (_("The remote protocol may be unreliable over UDP.\n"
3984 "Some events may be lost, rendering further debugging "
3989 return serial_open (name
);
3992 /* Inform the target of our permission settings. The permission flags
3993 work without this, but if the target knows the settings, it can do
3994 a couple things. First, it can add its own check, to catch cases
3995 that somehow manage to get by the permissions checks in target
3996 methods. Second, if the target is wired to disallow particular
3997 settings (for instance, a system in the field that is not set up to
3998 be able to stop at a breakpoint), it can object to any unavailable
4002 remote_set_permissions (struct target_ops
*self
)
4004 struct remote_state
*rs
= get_remote_state ();
4006 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4007 "WriteReg:%x;WriteMem:%x;"
4008 "InsertBreak:%x;InsertTrace:%x;"
4009 "InsertFastTrace:%x;Stop:%x",
4010 may_write_registers
, may_write_memory
,
4011 may_insert_breakpoints
, may_insert_tracepoints
,
4012 may_insert_fast_tracepoints
, may_stop
);
4014 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4016 /* If the target didn't like the packet, warn the user. Do not try
4017 to undo the user's settings, that would just be maddening. */
4018 if (strcmp (rs
->buf
, "OK") != 0)
4019 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4022 /* This type describes each known response to the qSupported
4024 struct protocol_feature
4026 /* The name of this protocol feature. */
4029 /* The default for this protocol feature. */
4030 enum packet_support default_support
;
4032 /* The function to call when this feature is reported, or after
4033 qSupported processing if the feature is not supported.
4034 The first argument points to this structure. The second
4035 argument indicates whether the packet requested support be
4036 enabled, disabled, or probed (or the default, if this function
4037 is being called at the end of processing and this feature was
4038 not reported). The third argument may be NULL; if not NULL, it
4039 is a NUL-terminated string taken from the packet following
4040 this feature's name and an equals sign. */
4041 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4044 /* The corresponding packet for this feature. Only used if
4045 FUNC is remote_supported_packet. */
4050 remote_supported_packet (const struct protocol_feature
*feature
,
4051 enum packet_support support
,
4052 const char *argument
)
4056 warning (_("Remote qSupported response supplied an unexpected value for"
4057 " \"%s\"."), feature
->name
);
4061 remote_protocol_packets
[feature
->packet
].support
= support
;
4065 remote_packet_size (const struct protocol_feature
*feature
,
4066 enum packet_support support
, const char *value
)
4068 struct remote_state
*rs
= get_remote_state ();
4073 if (support
!= PACKET_ENABLE
)
4076 if (value
== NULL
|| *value
== '\0')
4078 warning (_("Remote target reported \"%s\" without a size."),
4084 packet_size
= strtol (value
, &value_end
, 16);
4085 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4087 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4088 feature
->name
, value
);
4092 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
4094 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
4095 packet_size
, MAX_REMOTE_PACKET_SIZE
);
4096 packet_size
= MAX_REMOTE_PACKET_SIZE
;
4099 /* Record the new maximum packet size. */
4100 rs
->explicit_packet_size
= packet_size
;
4103 static const struct protocol_feature remote_protocol_features
[] = {
4104 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4105 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4106 PACKET_qXfer_auxv
},
4107 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4108 PACKET_qXfer_exec_file
},
4109 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4110 PACKET_qXfer_features
},
4111 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4112 PACKET_qXfer_libraries
},
4113 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4114 PACKET_qXfer_libraries_svr4
},
4115 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4116 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4117 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4118 PACKET_qXfer_memory_map
},
4119 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4120 PACKET_qXfer_spu_read
},
4121 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4122 PACKET_qXfer_spu_write
},
4123 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4124 PACKET_qXfer_osdata
},
4125 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4126 PACKET_qXfer_threads
},
4127 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4128 PACKET_qXfer_traceframe_info
},
4129 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4130 PACKET_QPassSignals
},
4131 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4132 PACKET_QProgramSignals
},
4133 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4134 PACKET_QStartNoAckMode
},
4135 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4136 PACKET_multiprocess_feature
},
4137 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4138 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4139 PACKET_qXfer_siginfo_read
},
4140 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4141 PACKET_qXfer_siginfo_write
},
4142 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4143 PACKET_ConditionalTracepoints
},
4144 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4145 PACKET_ConditionalBreakpoints
},
4146 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4147 PACKET_BreakpointCommands
},
4148 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4149 PACKET_FastTracepoints
},
4150 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4151 PACKET_StaticTracepoints
},
4152 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4153 PACKET_InstallInTrace
},
4154 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4155 PACKET_DisconnectedTracing_feature
},
4156 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4158 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4160 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4161 PACKET_TracepointSource
},
4162 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4164 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4165 PACKET_EnableDisableTracepoints_feature
},
4166 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4167 PACKET_qXfer_fdpic
},
4168 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4170 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4171 PACKET_QDisableRandomization
},
4172 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4173 { "QTBuffer:size", PACKET_DISABLE
,
4174 remote_supported_packet
, PACKET_QTBuffer_size
},
4175 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4176 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4177 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4178 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4179 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4180 PACKET_qXfer_btrace
},
4181 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4182 PACKET_qXfer_btrace_conf
},
4183 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4184 PACKET_Qbtrace_conf_bts_size
},
4185 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4186 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4187 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4188 PACKET_fork_event_feature
},
4189 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4190 PACKET_vfork_event_feature
},
4191 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4192 PACKET_Qbtrace_conf_pt_size
}
4195 static char *remote_support_xml
;
4197 /* Register string appended to "xmlRegisters=" in qSupported query. */
4200 register_remote_support_xml (const char *xml
)
4202 #if defined(HAVE_LIBEXPAT)
4203 if (remote_support_xml
== NULL
)
4204 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4207 char *copy
= xstrdup (remote_support_xml
+ 13);
4208 char *p
= strtok (copy
, ",");
4212 if (strcmp (p
, xml
) == 0)
4219 while ((p
= strtok (NULL
, ",")) != NULL
);
4222 remote_support_xml
= reconcat (remote_support_xml
,
4223 remote_support_xml
, ",", xml
,
4230 remote_query_supported_append (char *msg
, const char *append
)
4233 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4235 return xstrdup (append
);
4239 remote_query_supported (void)
4241 struct remote_state
*rs
= get_remote_state ();
4244 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4246 /* The packet support flags are handled differently for this packet
4247 than for most others. We treat an error, a disabled packet, and
4248 an empty response identically: any features which must be reported
4249 to be used will be automatically disabled. An empty buffer
4250 accomplishes this, since that is also the representation for a list
4251 containing no features. */
4254 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4257 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4259 q
= remote_query_supported_append (q
, "multiprocess+");
4261 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4262 q
= remote_query_supported_append (q
, "swbreak+");
4263 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4264 q
= remote_query_supported_append (q
, "hwbreak+");
4266 if (remote_support_xml
)
4267 q
= remote_query_supported_append (q
, remote_support_xml
);
4269 q
= remote_query_supported_append (q
, "qRelocInsn+");
4273 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4274 != AUTO_BOOLEAN_FALSE
)
4275 q
= remote_query_supported_append (q
, "fork-events+");
4276 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4277 != AUTO_BOOLEAN_FALSE
)
4278 q
= remote_query_supported_append (q
, "vfork-events+");
4281 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4284 do_cleanups (old_chain
);
4286 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4288 /* If an error occured, warn, but do not return - just reset the
4289 buffer to empty and go on to disable features. */
4290 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4293 warning (_("Remote failure reply: %s"), rs
->buf
);
4298 memset (seen
, 0, sizeof (seen
));
4303 enum packet_support is_supported
;
4304 char *p
, *end
, *name_end
, *value
;
4306 /* First separate out this item from the rest of the packet. If
4307 there's another item after this, we overwrite the separator
4308 (terminated strings are much easier to work with). */
4310 end
= strchr (p
, ';');
4313 end
= p
+ strlen (p
);
4323 warning (_("empty item in \"qSupported\" response"));
4328 name_end
= strchr (p
, '=');
4331 /* This is a name=value entry. */
4332 is_supported
= PACKET_ENABLE
;
4333 value
= name_end
+ 1;
4342 is_supported
= PACKET_ENABLE
;
4346 is_supported
= PACKET_DISABLE
;
4350 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4354 warning (_("unrecognized item \"%s\" "
4355 "in \"qSupported\" response"), p
);
4361 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4362 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4364 const struct protocol_feature
*feature
;
4367 feature
= &remote_protocol_features
[i
];
4368 feature
->func (feature
, is_supported
, value
);
4373 /* If we increased the packet size, make sure to increase the global
4374 buffer size also. We delay this until after parsing the entire
4375 qSupported packet, because this is the same buffer we were
4377 if (rs
->buf_size
< rs
->explicit_packet_size
)
4379 rs
->buf_size
= rs
->explicit_packet_size
;
4380 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4383 /* Handle the defaults for unmentioned features. */
4384 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4387 const struct protocol_feature
*feature
;
4389 feature
= &remote_protocol_features
[i
];
4390 feature
->func (feature
, feature
->default_support
, NULL
);
4394 /* Remove any of the remote.c targets from target stack. Upper targets depend
4395 on it so remove them first. */
4398 remote_unpush_target (void)
4400 pop_all_targets_above (process_stratum
- 1);
4404 remote_open_1 (const char *name
, int from_tty
,
4405 struct target_ops
*target
, int extended_p
)
4407 struct remote_state
*rs
= get_remote_state ();
4410 error (_("To open a remote debug connection, you need to specify what\n"
4411 "serial device is attached to the remote system\n"
4412 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4414 /* See FIXME above. */
4415 if (!target_async_permitted
)
4416 wait_forever_enabled_p
= 1;
4418 /* If we're connected to a running target, target_preopen will kill it.
4419 Ask this question first, before target_preopen has a chance to kill
4421 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4424 && !query (_("Already connected to a remote target. Disconnect? ")))
4425 error (_("Still connected."));
4428 /* Here the possibly existing remote target gets unpushed. */
4429 target_preopen (from_tty
);
4431 /* Make sure we send the passed signals list the next time we resume. */
4432 xfree (rs
->last_pass_packet
);
4433 rs
->last_pass_packet
= NULL
;
4435 /* Make sure we send the program signals list the next time we
4437 xfree (rs
->last_program_signals_packet
);
4438 rs
->last_program_signals_packet
= NULL
;
4440 remote_fileio_reset ();
4441 reopen_exec_file ();
4444 rs
->remote_desc
= remote_serial_open (name
);
4445 if (!rs
->remote_desc
)
4446 perror_with_name (name
);
4448 if (baud_rate
!= -1)
4450 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4452 /* The requested speed could not be set. Error out to
4453 top level after closing remote_desc. Take care to
4454 set remote_desc to NULL to avoid closing remote_desc
4456 serial_close (rs
->remote_desc
);
4457 rs
->remote_desc
= NULL
;
4458 perror_with_name (name
);
4462 serial_setparity (rs
->remote_desc
, serial_parity
);
4463 serial_raw (rs
->remote_desc
);
4465 /* If there is something sitting in the buffer we might take it as a
4466 response to a command, which would be bad. */
4467 serial_flush_input (rs
->remote_desc
);
4471 puts_filtered ("Remote debugging using ");
4472 puts_filtered (name
);
4473 puts_filtered ("\n");
4475 push_target (target
); /* Switch to using remote target now. */
4477 /* Register extra event sources in the event loop. */
4478 remote_async_inferior_event_token
4479 = create_async_event_handler (remote_async_inferior_event_handler
,
4481 rs
->notif_state
= remote_notif_state_allocate ();
4483 /* Reset the target state; these things will be queried either by
4484 remote_query_supported or as they are needed. */
4485 reset_all_packet_configs_support ();
4486 rs
->cached_wait_status
= 0;
4487 rs
->explicit_packet_size
= 0;
4489 rs
->extended
= extended_p
;
4490 rs
->waiting_for_stop_reply
= 0;
4491 rs
->ctrlc_pending_p
= 0;
4493 rs
->general_thread
= not_sent_ptid
;
4494 rs
->continue_thread
= not_sent_ptid
;
4495 rs
->remote_traceframe_number
= -1;
4497 /* Probe for ability to use "ThreadInfo" query, as required. */
4498 rs
->use_threadinfo_query
= 1;
4499 rs
->use_threadextra_query
= 1;
4501 if (target_async_permitted
)
4503 /* With this target we start out by owning the terminal. */
4504 remote_async_terminal_ours_p
= 1;
4506 /* FIXME: cagney/1999-09-23: During the initial connection it is
4507 assumed that the target is already ready and able to respond to
4508 requests. Unfortunately remote_start_remote() eventually calls
4509 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4510 around this. Eventually a mechanism that allows
4511 wait_for_inferior() to expect/get timeouts will be
4513 wait_forever_enabled_p
= 0;
4516 /* First delete any symbols previously loaded from shared libraries. */
4517 no_shared_libraries (NULL
, 0);
4520 init_thread_list ();
4522 /* Start the remote connection. If error() or QUIT, discard this
4523 target (we'd otherwise be in an inconsistent state) and then
4524 propogate the error on up the exception chain. This ensures that
4525 the caller doesn't stumble along blindly assuming that the
4526 function succeeded. The CLI doesn't have this problem but other
4527 UI's, such as MI do.
4529 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4530 this function should return an error indication letting the
4531 caller restore the previous state. Unfortunately the command
4532 ``target remote'' is directly wired to this function making that
4533 impossible. On a positive note, the CLI side of this problem has
4534 been fixed - the function set_cmd_context() makes it possible for
4535 all the ``target ....'' commands to share a common callback
4536 function. See cli-dump.c. */
4541 remote_start_remote (from_tty
, target
, extended_p
);
4543 CATCH (ex
, RETURN_MASK_ALL
)
4545 /* Pop the partially set up target - unless something else did
4546 already before throwing the exception. */
4547 if (rs
->remote_desc
!= NULL
)
4548 remote_unpush_target ();
4549 if (target_async_permitted
)
4550 wait_forever_enabled_p
= 1;
4551 throw_exception (ex
);
4556 remote_btrace_reset ();
4558 if (target_async_permitted
)
4559 wait_forever_enabled_p
= 1;
4562 /* Detach the specified process. */
4565 remote_detach_pid (int pid
)
4567 struct remote_state
*rs
= get_remote_state ();
4569 if (remote_multi_process_p (rs
))
4570 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4572 strcpy (rs
->buf
, "D");
4575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4577 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4579 else if (rs
->buf
[0] == '\0')
4580 error (_("Remote doesn't know how to detach"));
4582 error (_("Can't detach process."));
4585 /* This detaches a program to which we previously attached, using
4586 inferior_ptid to identify the process. After this is done, GDB
4587 can be used to debug some other program. We better not have left
4588 any breakpoints in the target program or it'll die when it hits
4592 remote_detach_1 (const char *args
, int from_tty
)
4594 int pid
= ptid_get_pid (inferior_ptid
);
4595 struct remote_state
*rs
= get_remote_state ();
4596 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4600 error (_("Argument given to \"detach\" when remotely debugging."));
4602 if (!target_has_execution
)
4603 error (_("No process to detach from."));
4607 char *exec_file
= get_exec_file (0);
4608 if (exec_file
== NULL
)
4610 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4611 target_pid_to_str (pid_to_ptid (pid
)));
4612 gdb_flush (gdb_stdout
);
4615 /* Tell the remote target to detach. */
4616 remote_detach_pid (pid
);
4618 if (from_tty
&& !rs
->extended
)
4619 puts_filtered (_("Ending remote debugging.\n"));
4621 /* Check to see if we are detaching a fork parent. Note that if we
4622 are detaching a fork child, tp == NULL. */
4623 is_fork_parent
= (tp
!= NULL
4624 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4626 /* If doing detach-on-fork, we don't mourn, because that will delete
4627 breakpoints that should be available for the followed inferior. */
4628 if (!is_fork_parent
)
4629 target_mourn_inferior ();
4632 inferior_ptid
= null_ptid
;
4633 detach_inferior (pid
);
4638 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4640 remote_detach_1 (args
, from_tty
);
4644 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4646 remote_detach_1 (args
, from_tty
);
4649 /* Target follow-fork function for remote targets. On entry, and
4650 at return, the current inferior is the fork parent.
4652 Note that although this is currently only used for extended-remote,
4653 it is named remote_follow_fork in anticipation of using it for the
4654 remote target as well. */
4657 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4660 struct remote_state
*rs
= get_remote_state ();
4661 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4663 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4664 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4666 /* When following the parent and detaching the child, we detach
4667 the child here. For the case of following the child and
4668 detaching the parent, the detach is done in the target-
4669 independent follow fork code in infrun.c. We can't use
4670 target_detach when detaching an unfollowed child because
4671 the client side doesn't know anything about the child. */
4672 if (detach_fork
&& !follow_child
)
4674 /* Detach the fork child. */
4678 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4679 child_pid
= ptid_get_pid (child_ptid
);
4681 remote_detach_pid (child_pid
);
4682 detach_inferior (child_pid
);
4688 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4691 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4694 error (_("Argument given to \"disconnect\" when remotely debugging."));
4696 /* Make sure we unpush even the extended remote targets; mourn
4697 won't do it. So call remote_mourn directly instead of
4698 target_mourn_inferior. */
4699 remote_mourn (target
);
4702 puts_filtered ("Ending remote debugging.\n");
4705 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4706 be chatty about it. */
4709 extended_remote_attach (struct target_ops
*target
, const char *args
,
4712 struct remote_state
*rs
= get_remote_state ();
4714 char *wait_status
= NULL
;
4716 pid
= parse_pid_to_attach (args
);
4718 /* Remote PID can be freely equal to getpid, do not check it here the same
4719 way as in other targets. */
4721 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4722 error (_("This target does not support attaching to a process"));
4726 char *exec_file
= get_exec_file (0);
4729 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4730 target_pid_to_str (pid_to_ptid (pid
)));
4732 printf_unfiltered (_("Attaching to %s\n"),
4733 target_pid_to_str (pid_to_ptid (pid
)));
4735 gdb_flush (gdb_stdout
);
4738 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4740 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4742 switch (packet_ok (rs
->buf
,
4743 &remote_protocol_packets
[PACKET_vAttach
]))
4748 /* Save the reply for later. */
4749 wait_status
= alloca (strlen (rs
->buf
) + 1);
4750 strcpy (wait_status
, rs
->buf
);
4752 else if (strcmp (rs
->buf
, "OK") != 0)
4753 error (_("Attaching to %s failed with: %s"),
4754 target_pid_to_str (pid_to_ptid (pid
)),
4757 case PACKET_UNKNOWN
:
4758 error (_("This target does not support attaching to a process"));
4760 error (_("Attaching to %s failed"),
4761 target_pid_to_str (pid_to_ptid (pid
)));
4764 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4766 inferior_ptid
= pid_to_ptid (pid
);
4770 struct thread_info
*thread
;
4772 /* Get list of threads. */
4773 remote_update_thread_list (target
);
4775 thread
= first_thread_of_process (pid
);
4777 inferior_ptid
= thread
->ptid
;
4779 inferior_ptid
= pid_to_ptid (pid
);
4781 /* Invalidate our notion of the remote current thread. */
4782 record_currthread (rs
, minus_one_ptid
);
4786 /* Now, if we have thread information, update inferior_ptid. */
4787 inferior_ptid
= remote_current_thread (inferior_ptid
);
4789 /* Add the main thread to the thread list. */
4790 add_thread_silent (inferior_ptid
);
4793 /* Next, if the target can specify a description, read it. We do
4794 this before anything involving memory or registers. */
4795 target_find_description ();
4799 /* Use the previously fetched status. */
4800 gdb_assert (wait_status
!= NULL
);
4802 if (target_can_async_p ())
4804 struct notif_event
*reply
4805 = remote_notif_parse (¬if_client_stop
, wait_status
);
4807 push_stop_reply ((struct stop_reply
*) reply
);
4813 gdb_assert (wait_status
!= NULL
);
4814 strcpy (rs
->buf
, wait_status
);
4815 rs
->cached_wait_status
= 1;
4819 gdb_assert (wait_status
== NULL
);
4822 /* Implementation of the to_post_attach method. */
4825 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4827 /* In certain cases GDB might not have had the chance to start
4828 symbol lookup up until now. This could happen if the debugged
4829 binary is not using shared libraries, the vsyscall page is not
4830 present (on Linux) and the binary itself hadn't changed since the
4831 debugging process was started. */
4832 if (symfile_objfile
!= NULL
)
4833 remote_check_symbols();
4837 /* Check for the availability of vCont. This function should also check
4841 remote_vcont_probe (struct remote_state
*rs
)
4845 strcpy (rs
->buf
, "vCont?");
4847 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4850 /* Make sure that the features we assume are supported. */
4851 if (startswith (buf
, "vCont"))
4854 int support_s
, support_S
, support_c
, support_C
;
4860 rs
->supports_vCont
.t
= 0;
4861 rs
->supports_vCont
.r
= 0;
4862 while (p
&& *p
== ';')
4865 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4867 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4869 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4871 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4873 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4874 rs
->supports_vCont
.t
= 1;
4875 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4876 rs
->supports_vCont
.r
= 1;
4878 p
= strchr (p
, ';');
4881 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4882 BUF will make packet_ok disable the packet. */
4883 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4887 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4890 /* Helper function for building "vCont" resumptions. Write a
4891 resumption to P. ENDP points to one-passed-the-end of the buffer
4892 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4893 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4894 resumed thread should be single-stepped and/or signalled. If PTID
4895 equals minus_one_ptid, then all threads are resumed; if PTID
4896 represents a process, then all threads of the process are resumed;
4897 the thread to be stepped and/or signalled is given in the global
4901 append_resumption (char *p
, char *endp
,
4902 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4904 struct remote_state
*rs
= get_remote_state ();
4906 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4907 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4909 /* GDB is willing to range step. */
4910 && use_range_stepping
4911 /* Target supports range stepping. */
4912 && rs
->supports_vCont
.r
4913 /* We don't currently support range stepping multiple
4914 threads with a wildcard (though the protocol allows it,
4915 so stubs shouldn't make an active effort to forbid
4917 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4919 struct thread_info
*tp
;
4921 if (ptid_equal (ptid
, minus_one_ptid
))
4923 /* If we don't know about the target thread's tid, then
4924 we're resuming magic_null_ptid (see caller). */
4925 tp
= find_thread_ptid (magic_null_ptid
);
4928 tp
= find_thread_ptid (ptid
);
4929 gdb_assert (tp
!= NULL
);
4931 if (tp
->control
.may_range_step
)
4933 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4935 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4936 phex_nz (tp
->control
.step_range_start
,
4938 phex_nz (tp
->control
.step_range_end
,
4942 p
+= xsnprintf (p
, endp
- p
, ";s");
4945 p
+= xsnprintf (p
, endp
- p
, ";s");
4946 else if (siggnal
!= GDB_SIGNAL_0
)
4947 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4949 p
+= xsnprintf (p
, endp
- p
, ";c");
4951 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4955 /* All (-1) threads of process. */
4956 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4958 p
+= xsnprintf (p
, endp
- p
, ":");
4959 p
= write_ptid (p
, endp
, nptid
);
4961 else if (!ptid_equal (ptid
, minus_one_ptid
))
4963 p
+= xsnprintf (p
, endp
- p
, ":");
4964 p
= write_ptid (p
, endp
, ptid
);
4970 /* Append a vCont continue-with-signal action for threads that have a
4971 non-zero stop signal. */
4974 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4976 struct thread_info
*thread
;
4978 ALL_NON_EXITED_THREADS (thread
)
4979 if (ptid_match (thread
->ptid
, ptid
)
4980 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4981 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4983 p
= append_resumption (p
, endp
, thread
->ptid
,
4984 0, thread
->suspend
.stop_signal
);
4985 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4991 /* Resume the remote inferior by using a "vCont" packet. The thread
4992 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4993 resumed thread should be single-stepped and/or signalled. If PTID
4994 equals minus_one_ptid, then all threads are resumed; the thread to
4995 be stepped and/or signalled is given in the global INFERIOR_PTID.
4996 This function returns non-zero iff it resumes the inferior.
4998 This function issues a strict subset of all possible vCont commands at the
5002 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5004 struct remote_state
*rs
= get_remote_state ();
5008 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5009 remote_vcont_probe (rs
);
5011 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5015 endp
= rs
->buf
+ get_remote_packet_size ();
5017 /* If we could generate a wider range of packets, we'd have to worry
5018 about overflowing BUF. Should there be a generic
5019 "multi-part-packet" packet? */
5021 p
+= xsnprintf (p
, endp
- p
, "vCont");
5023 if (ptid_equal (ptid
, magic_null_ptid
))
5025 /* MAGIC_NULL_PTID means that we don't have any active threads,
5026 so we don't have any TID numbers the inferior will
5027 understand. Make sure to only send forms that do not specify
5029 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5031 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5033 /* Resume all threads (of all processes, or of a single
5034 process), with preference for INFERIOR_PTID. This assumes
5035 inferior_ptid belongs to the set of all threads we are about
5037 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5039 /* Step inferior_ptid, with or without signal. */
5040 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5043 /* Also pass down any pending signaled resumption for other
5044 threads not the current. */
5045 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5047 /* And continue others without a signal. */
5048 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5052 /* Scheduler locking; resume only PTID. */
5053 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5056 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5061 /* In non-stop, the stub replies to vCont with "OK". The stop
5062 reply will be reported asynchronously by means of a `%Stop'
5064 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5065 if (strcmp (rs
->buf
, "OK") != 0)
5066 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5072 /* Tell the remote machine to resume. */
5075 remote_resume (struct target_ops
*ops
,
5076 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5078 struct remote_state
*rs
= get_remote_state ();
5081 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5082 (explained in remote-notif.c:handle_notification) so
5083 remote_notif_process is not called. We need find a place where
5084 it is safe to start a 'vNotif' sequence. It is good to do it
5085 before resuming inferior, because inferior was stopped and no RSP
5086 traffic at that moment. */
5088 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5090 rs
->last_sent_signal
= siggnal
;
5091 rs
->last_sent_step
= step
;
5093 /* The vCont packet doesn't need to specify threads via Hc. */
5094 /* No reverse support (yet) for vCont. */
5095 if (execution_direction
!= EXEC_REVERSE
)
5096 if (remote_vcont_resume (ptid
, step
, siggnal
))
5099 /* All other supported resume packets do use Hc, so set the continue
5101 if (ptid_equal (ptid
, minus_one_ptid
))
5102 set_continue_thread (any_thread_ptid
);
5104 set_continue_thread (ptid
);
5107 if (execution_direction
== EXEC_REVERSE
)
5109 /* We don't pass signals to the target in reverse exec mode. */
5110 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5111 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5114 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5115 error (_("Remote reverse-step not supported."));
5116 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5117 error (_("Remote reverse-continue not supported."));
5119 strcpy (buf
, step
? "bs" : "bc");
5121 else if (siggnal
!= GDB_SIGNAL_0
)
5123 buf
[0] = step
? 'S' : 'C';
5124 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5125 buf
[2] = tohex (((int) siggnal
) & 0xf);
5129 strcpy (buf
, step
? "s" : "c");
5134 /* We are about to start executing the inferior, let's register it
5135 with the event loop. NOTE: this is the one place where all the
5136 execution commands end up. We could alternatively do this in each
5137 of the execution commands in infcmd.c. */
5138 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5139 into infcmd.c in order to allow inferior function calls to work
5140 NOT asynchronously. */
5141 if (target_can_async_p ())
5144 /* We've just told the target to resume. The remote server will
5145 wait for the inferior to stop, and then send a stop reply. In
5146 the mean time, we can't start another command/query ourselves
5147 because the stub wouldn't be ready to process it. This applies
5148 only to the base all-stop protocol, however. In non-stop (which
5149 only supports vCont), the stub replies with an "OK", and is
5150 immediate able to process further serial input. */
5152 rs
->waiting_for_stop_reply
= 1;
5156 /* Set up the signal handler for SIGINT, while the target is
5157 executing, ovewriting the 'regular' SIGINT signal handler. */
5159 async_initialize_sigint_signal_handler (void)
5161 signal (SIGINT
, async_handle_remote_sigint
);
5164 /* Signal handler for SIGINT, while the target is executing. */
5166 async_handle_remote_sigint (int sig
)
5168 signal (sig
, async_handle_remote_sigint_twice
);
5169 /* Note we need to go through gdb_call_async_signal_handler in order
5170 to wake up the event loop on Windows. */
5171 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5174 /* Signal handler for SIGINT, installed after SIGINT has already been
5175 sent once. It will take effect the second time that the user sends
5178 async_handle_remote_sigint_twice (int sig
)
5180 signal (sig
, async_handle_remote_sigint
);
5181 /* See note in async_handle_remote_sigint. */
5182 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5185 /* Perform the real interruption of the target execution, in response
5188 async_remote_interrupt (gdb_client_data arg
)
5191 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5193 target_stop (inferior_ptid
);
5196 /* Perform interrupt, if the first attempt did not succeed. Just give
5197 up on the target alltogether. */
5199 async_remote_interrupt_twice (gdb_client_data arg
)
5202 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5207 /* Reinstall the usual SIGINT handlers, after the target has
5210 async_cleanup_sigint_signal_handler (void *dummy
)
5212 signal (SIGINT
, handle_sigint
);
5215 /* Send ^C to target to halt it. Target will respond, and send us a
5217 static void (*ofunc
) (int);
5219 /* The command line interface's interrupt routine. This function is installed
5220 as a signal handler for SIGINT. The first time a user requests an
5221 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5222 response from the target (it didn't stop when the user requested it),
5223 we ask the user if he'd like to detach from the target. */
5226 sync_remote_interrupt (int signo
)
5228 /* If this doesn't work, try more severe steps. */
5229 signal (signo
, sync_remote_interrupt_twice
);
5231 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5234 /* The user typed ^C twice. */
5237 sync_remote_interrupt_twice (int signo
)
5239 signal (signo
, ofunc
);
5240 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5241 signal (signo
, sync_remote_interrupt
);
5244 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5245 thread, all threads of a remote process, or all threads of all
5249 remote_stop_ns (ptid_t ptid
)
5251 struct remote_state
*rs
= get_remote_state ();
5253 char *endp
= rs
->buf
+ get_remote_packet_size ();
5255 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5256 remote_vcont_probe (rs
);
5258 if (!rs
->supports_vCont
.t
)
5259 error (_("Remote server does not support stopping threads"));
5261 if (ptid_equal (ptid
, minus_one_ptid
)
5262 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5263 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5268 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5270 if (ptid_is_pid (ptid
))
5271 /* All (-1) threads of process. */
5272 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5275 /* Small optimization: if we already have a stop reply for
5276 this thread, no use in telling the stub we want this
5278 if (peek_stop_reply (ptid
))
5284 write_ptid (p
, endp
, nptid
);
5287 /* In non-stop, we get an immediate OK reply. The stop reply will
5288 come in asynchronously by notification. */
5290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5291 if (strcmp (rs
->buf
, "OK") != 0)
5292 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5295 /* All-stop version of target_interrupt. Sends a break or a ^C to
5296 interrupt the remote target. It is undefined which thread of which
5297 process reports the interrupt. */
5300 remote_interrupt_as (ptid_t ptid
)
5302 struct remote_state
*rs
= get_remote_state ();
5304 rs
->ctrlc_pending_p
= 1;
5306 /* If the inferior is stopped already, but the core didn't know
5307 about it yet, just ignore the request. The cached wait status
5308 will be collected in remote_wait. */
5309 if (rs
->cached_wait_status
)
5312 /* Send interrupt_sequence to remote target. */
5313 send_interrupt_sequence ();
5316 /* Implement the to_stop function for the remote targets. */
5319 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5322 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5325 remote_stop_ns (ptid
);
5328 /* We don't currently have a way to transparently pause the
5329 remote target in all-stop mode. Interrupt it instead. */
5330 remote_interrupt_as (ptid
);
5334 /* Implement the to_interrupt function for the remote targets. */
5337 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5340 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5344 /* We don't currently have a way to ^C the remote target in
5345 non-stop mode. Stop it (with no signal) instead. */
5346 remote_stop_ns (ptid
);
5349 remote_interrupt_as (ptid
);
5352 /* Ask the user what to do when an interrupt is received. */
5355 interrupt_query (void)
5357 target_terminal_ours ();
5359 if (target_is_async_p ())
5361 signal (SIGINT
, handle_sigint
);
5366 if (query (_("Interrupted while waiting for the program.\n\
5367 Give up (and stop debugging it)? ")))
5369 remote_unpush_target ();
5374 target_terminal_inferior ();
5377 /* Enable/disable target terminal ownership. Most targets can use
5378 terminal groups to control terminal ownership. Remote targets are
5379 different in that explicit transfer of ownership to/from GDB/target
5383 remote_terminal_inferior (struct target_ops
*self
)
5385 if (!target_async_permitted
)
5386 /* Nothing to do. */
5389 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5390 idempotent. The event-loop GDB talking to an asynchronous target
5391 with a synchronous command calls this function from both
5392 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5393 transfer the terminal to the target when it shouldn't this guard
5395 if (!remote_async_terminal_ours_p
)
5397 delete_file_handler (input_fd
);
5398 remote_async_terminal_ours_p
= 0;
5399 async_initialize_sigint_signal_handler ();
5400 /* NOTE: At this point we could also register our selves as the
5401 recipient of all input. Any characters typed could then be
5402 passed on down to the target. */
5406 remote_terminal_ours (struct target_ops
*self
)
5408 if (!target_async_permitted
)
5409 /* Nothing to do. */
5412 /* See FIXME in remote_terminal_inferior. */
5413 if (remote_async_terminal_ours_p
)
5415 async_cleanup_sigint_signal_handler (NULL
);
5416 add_file_handler (input_fd
, stdin_event_handler
, 0);
5417 remote_async_terminal_ours_p
= 1;
5421 remote_console_output (char *msg
)
5425 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5428 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5432 fputs_unfiltered (tb
, gdb_stdtarg
);
5434 gdb_flush (gdb_stdtarg
);
5437 typedef struct cached_reg
5440 gdb_byte data
[MAX_REGISTER_SIZE
];
5443 DEF_VEC_O(cached_reg_t
);
5445 typedef struct stop_reply
5447 struct notif_event base
;
5449 /* The identifier of the thread about this event */
5452 /* The remote state this event is associated with. When the remote
5453 connection, represented by a remote_state object, is closed,
5454 all the associated stop_reply events should be released. */
5455 struct remote_state
*rs
;
5457 struct target_waitstatus ws
;
5459 /* Expedited registers. This makes remote debugging a bit more
5460 efficient for those targets that provide critical registers as
5461 part of their normal status mechanism (as another roundtrip to
5462 fetch them is avoided). */
5463 VEC(cached_reg_t
) *regcache
;
5465 enum target_stop_reason stop_reason
;
5467 CORE_ADDR watch_data_address
;
5472 DECLARE_QUEUE_P (stop_reply_p
);
5473 DEFINE_QUEUE_P (stop_reply_p
);
5474 /* The list of already fetched and acknowledged stop events. This
5475 queue is used for notification Stop, and other notifications
5476 don't need queue for their events, because the notification events
5477 of Stop can't be consumed immediately, so that events should be
5478 queued first, and be consumed by remote_wait_{ns,as} one per
5479 time. Other notifications can consume their events immediately,
5480 so queue is not needed for them. */
5481 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5484 stop_reply_xfree (struct stop_reply
*r
)
5486 notif_event_xfree ((struct notif_event
*) r
);
5490 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5491 struct notif_event
*event
)
5493 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5497 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5498 struct notif_event
*event
)
5500 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5503 putpkt ((char *) self
->ack_command
);
5505 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5506 /* We got an unknown stop reply. */
5507 error (_("Unknown stop reply"));
5509 push_stop_reply (stop_reply
);
5513 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5515 /* We can't get pending events in remote_notif_process for
5516 notification stop, and we have to do this in remote_wait_ns
5517 instead. If we fetch all queued events from stub, remote stub
5518 may exit and we have no chance to process them back in
5520 mark_async_event_handler (remote_async_inferior_event_token
);
5525 stop_reply_dtr (struct notif_event
*event
)
5527 struct stop_reply
*r
= (struct stop_reply
*) event
;
5529 VEC_free (cached_reg_t
, r
->regcache
);
5532 static struct notif_event
*
5533 remote_notif_stop_alloc_reply (void)
5535 struct notif_event
*r
5536 = (struct notif_event
*) XNEW (struct stop_reply
);
5538 r
->dtr
= stop_reply_dtr
;
5543 /* A client of notification Stop. */
5545 struct notif_client notif_client_stop
=
5549 remote_notif_stop_parse
,
5550 remote_notif_stop_ack
,
5551 remote_notif_stop_can_get_pending_events
,
5552 remote_notif_stop_alloc_reply
,
5556 /* A parameter to pass data in and out. */
5558 struct queue_iter_param
5561 struct stop_reply
*output
;
5564 /* Determine if THREAD is a pending fork parent thread. ARG contains
5565 the pid of the process that owns the threads we want to check, or
5566 -1 if we want to check all threads. */
5569 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5572 if (ws
->kind
== TARGET_WAITKIND_FORKED
5573 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5575 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5582 /* Check whether EVENT is a fork event, and if it is, remove the
5583 fork child from the context list passed in DATA. */
5586 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5587 QUEUE_ITER (stop_reply_p
) *iter
,
5591 struct queue_iter_param
*param
= data
;
5592 struct threads_listing_context
*context
= param
->input
;
5594 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5595 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5597 threads_listing_context_remove (&event
->ws
, context
);
5603 /* If CONTEXT contains any fork child threads that have not been
5604 reported yet, remove them from the CONTEXT list. If such a
5605 thread exists it is because we are stopped at a fork catchpoint
5606 and have not yet called follow_fork, which will set up the
5607 host-side data structures for the new process. */
5610 remove_new_fork_children (struct threads_listing_context
*context
)
5612 struct thread_info
* thread
;
5614 struct notif_client
*notif
= ¬if_client_stop
;
5615 struct queue_iter_param param
;
5617 /* For any threads stopped at a fork event, remove the corresponding
5618 fork child threads from the CONTEXT list. */
5619 ALL_NON_EXITED_THREADS (thread
)
5621 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5623 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5625 threads_listing_context_remove (ws
, context
);
5629 /* Check for any pending fork events (not reported or processed yet)
5630 in process PID and remove those fork child threads from the
5631 CONTEXT list as well. */
5632 remote_notif_get_pending_events (notif
);
5633 param
.input
= context
;
5634 param
.output
= NULL
;
5635 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5636 remove_child_of_pending_fork
, ¶m
);
5639 /* Remove stop replies in the queue if its pid is equal to the given
5643 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5644 QUEUE_ITER (stop_reply_p
) *iter
,
5648 struct queue_iter_param
*param
= data
;
5649 struct inferior
*inf
= param
->input
;
5651 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5653 stop_reply_xfree (event
);
5654 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5660 /* Discard all pending stop replies of inferior INF. */
5663 discard_pending_stop_replies (struct inferior
*inf
)
5666 struct queue_iter_param param
;
5667 struct stop_reply
*reply
;
5668 struct remote_state
*rs
= get_remote_state ();
5669 struct remote_notif_state
*rns
= rs
->notif_state
;
5671 /* This function can be notified when an inferior exists. When the
5672 target is not remote, the notification state is NULL. */
5673 if (rs
->remote_desc
== NULL
)
5676 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5678 /* Discard the in-flight notification. */
5679 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5681 stop_reply_xfree (reply
);
5682 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5686 param
.output
= NULL
;
5687 /* Discard the stop replies we have already pulled with
5689 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5690 remove_stop_reply_for_inferior
, ¶m
);
5693 /* If its remote state is equal to the given remote state,
5694 remove EVENT from the stop reply queue. */
5697 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5698 QUEUE_ITER (stop_reply_p
) *iter
,
5702 struct queue_iter_param
*param
= data
;
5703 struct remote_state
*rs
= param
->input
;
5705 if (event
->rs
== rs
)
5707 stop_reply_xfree (event
);
5708 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5714 /* Discard the stop replies for RS in stop_reply_queue. */
5717 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5719 struct queue_iter_param param
;
5722 param
.output
= NULL
;
5723 /* Discard the stop replies we have already pulled with
5725 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5726 remove_stop_reply_of_remote_state
, ¶m
);
5729 /* A parameter to pass data in and out. */
5732 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5733 QUEUE_ITER (stop_reply_p
) *iter
,
5737 struct queue_iter_param
*param
= data
;
5738 ptid_t
*ptid
= param
->input
;
5740 if (ptid_match (event
->ptid
, *ptid
))
5742 param
->output
= event
;
5743 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5750 /* Remove the first reply in 'stop_reply_queue' which matches
5753 static struct stop_reply
*
5754 remote_notif_remove_queued_reply (ptid_t ptid
)
5756 struct queue_iter_param param
;
5758 param
.input
= &ptid
;
5759 param
.output
= NULL
;
5761 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5762 remote_notif_remove_once_on_match
, ¶m
);
5764 fprintf_unfiltered (gdb_stdlog
,
5765 "notif: discard queued event: 'Stop' in %s\n",
5766 target_pid_to_str (ptid
));
5768 return param
.output
;
5771 /* Look for a queued stop reply belonging to PTID. If one is found,
5772 remove it from the queue, and return it. Returns NULL if none is
5773 found. If there are still queued events left to process, tell the
5774 event loop to get back to target_wait soon. */
5776 static struct stop_reply
*
5777 queued_stop_reply (ptid_t ptid
)
5779 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5781 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5782 /* There's still at least an event left. */
5783 mark_async_event_handler (remote_async_inferior_event_token
);
5788 /* Push a fully parsed stop reply in the stop reply queue. Since we
5789 know that we now have at least one queued event left to pass to the
5790 core side, tell the event loop to get back to target_wait soon. */
5793 push_stop_reply (struct stop_reply
*new_event
)
5795 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5798 fprintf_unfiltered (gdb_stdlog
,
5799 "notif: push 'Stop' %s to queue %d\n",
5800 target_pid_to_str (new_event
->ptid
),
5801 QUEUE_length (stop_reply_p
,
5804 mark_async_event_handler (remote_async_inferior_event_token
);
5808 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5809 QUEUE_ITER (stop_reply_p
) *iter
,
5810 struct stop_reply
*event
,
5813 ptid_t
*ptid
= data
;
5815 return !(ptid_equal (*ptid
, event
->ptid
)
5816 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5819 /* Returns true if we have a stop reply for PTID. */
5822 peek_stop_reply (ptid_t ptid
)
5824 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5825 stop_reply_match_ptid_and_ws
, &ptid
);
5828 /* Skip PACKET until the next semi-colon (or end of string). */
5831 skip_to_semicolon (char *p
)
5833 while (*p
!= '\0' && *p
!= ';')
5838 /* Parse the stop reply in BUF. Either the function succeeds, and the
5839 result is stored in EVENT, or throws an error. */
5842 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5844 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5848 event
->ptid
= null_ptid
;
5849 event
->rs
= get_remote_state ();
5850 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5851 event
->ws
.value
.integer
= 0;
5852 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5853 event
->regcache
= NULL
;
5858 case 'T': /* Status with PC, SP, FP, ... */
5859 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5860 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5862 n... = register number
5863 r... = register contents
5866 p
= &buf
[3]; /* after Txx */
5872 p1
= strchr (p
, ':');
5874 error (_("Malformed packet(a) (missing colon): %s\n\
5878 error (_("Malformed packet(a) (missing register number): %s\n\
5882 /* Some "registers" are actually extended stop information.
5883 Note if you're adding a new entry here: GDB 7.9 and
5884 earlier assume that all register "numbers" that start
5885 with an hex digit are real register numbers. Make sure
5886 the server only sends such a packet if it knows the
5887 client understands it. */
5889 if (strncmp (p
, "thread", p1
- p
) == 0)
5890 event
->ptid
= read_ptid (++p1
, &p
);
5891 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5892 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5893 || (strncmp (p
, "awatch", p1
- p
) == 0))
5895 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
5896 p
= unpack_varlen_hex (++p1
, &addr
);
5897 event
->watch_data_address
= (CORE_ADDR
) addr
;
5899 else if (strncmp (p
, "swbreak", p1
- p
) == 0)
5901 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
5903 /* Make sure the stub doesn't forget to indicate support
5905 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
5906 error (_("Unexpected swbreak stop reason"));
5908 /* The value part is documented as "must be empty",
5909 though we ignore it, in case we ever decide to make
5910 use of it in a backward compatible way. */
5911 p
= skip_to_semicolon (p1
+ 1);
5913 else if (strncmp (p
, "hwbreak", p1
- p
) == 0)
5915 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
5917 /* Make sure the stub doesn't forget to indicate support
5919 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
5920 error (_("Unexpected hwbreak stop reason"));
5923 p
= skip_to_semicolon (p1
+ 1);
5925 else if (strncmp (p
, "library", p1
- p
) == 0)
5927 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5928 p
= skip_to_semicolon (p1
+ 1);
5930 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5932 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5933 /* p1 will indicate "begin" or "end", but it makes
5934 no difference for now, so ignore it. */
5935 p
= skip_to_semicolon (p1
+ 1);
5937 else if (strncmp (p
, "core", p1
- p
) == 0)
5941 p
= unpack_varlen_hex (++p1
, &c
);
5944 else if (strncmp (p
, "fork", p1
- p
) == 0)
5946 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5947 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
5949 else if (strncmp (p
, "vfork", p1
- p
) == 0)
5951 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5952 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
5954 else if (strncmp (p
, "vforkdone", p1
- p
) == 0)
5956 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
5957 p
= skip_to_semicolon (p1
+ 1);
5964 /* Maybe a real ``P'' register number. */
5965 p_temp
= unpack_varlen_hex (p
, &pnum
);
5966 /* If the first invalid character is the colon, we got a
5967 register number. Otherwise, it's an unknown stop
5971 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5972 cached_reg_t cached_reg
;
5975 error (_("Remote sent bad register number %s: %s\n\
5977 hex_string (pnum
), p
, buf
);
5979 cached_reg
.num
= reg
->regnum
;
5982 fieldsize
= hex2bin (p
, cached_reg
.data
,
5983 register_size (target_gdbarch (),
5986 if (fieldsize
< register_size (target_gdbarch (),
5988 warning (_("Remote reply is too short: %s"), buf
);
5990 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5994 /* Not a number. Silently skip unknown optional
5996 p
= skip_to_semicolon (p1
+ 1);
6001 error (_("Remote register badly formatted: %s\nhere: %s"),
6006 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6010 case 'S': /* Old style status, just signal only. */
6014 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6015 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6016 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6017 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6019 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6022 case 'W': /* Target exited. */
6029 /* GDB used to accept only 2 hex chars here. Stubs should
6030 only send more if they detect GDB supports multi-process
6032 p
= unpack_varlen_hex (&buf
[1], &value
);
6036 /* The remote process exited. */
6037 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6038 event
->ws
.value
.integer
= value
;
6042 /* The remote process exited with a signal. */
6043 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6044 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6045 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6047 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6050 /* If no process is specified, assume inferior_ptid. */
6051 pid
= ptid_get_pid (inferior_ptid
);
6060 else if (startswith (p
, "process:"))
6064 p
+= sizeof ("process:") - 1;
6065 unpack_varlen_hex (p
, &upid
);
6069 error (_("unknown stop reply packet: %s"), buf
);
6072 error (_("unknown stop reply packet: %s"), buf
);
6073 event
->ptid
= pid_to_ptid (pid
);
6078 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6079 error (_("No process or thread specified in stop reply: %s"), buf
);
6082 /* When the stub wants to tell GDB about a new notification reply, it
6083 sends a notification (%Stop, for example). Those can come it at
6084 any time, hence, we have to make sure that any pending
6085 putpkt/getpkt sequence we're making is finished, before querying
6086 the stub for more events with the corresponding ack command
6087 (vStopped, for example). E.g., if we started a vStopped sequence
6088 immediately upon receiving the notification, something like this
6096 1.6) <-- (registers reply to step #1.3)
6098 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6101 To solve this, whenever we parse a %Stop notification successfully,
6102 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6103 doing whatever we were doing:
6109 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6110 2.5) <-- (registers reply to step #2.3)
6112 Eventualy after step #2.5, we return to the event loop, which
6113 notices there's an event on the
6114 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6115 associated callback --- the function below. At this point, we're
6116 always safe to start a vStopped sequence. :
6119 2.7) <-- T05 thread:2
6125 remote_notif_get_pending_events (struct notif_client
*nc
)
6127 struct remote_state
*rs
= get_remote_state ();
6129 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6132 fprintf_unfiltered (gdb_stdlog
,
6133 "notif: process: '%s' ack pending event\n",
6137 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6138 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6142 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6143 if (strcmp (rs
->buf
, "OK") == 0)
6146 remote_notif_ack (nc
, rs
->buf
);
6152 fprintf_unfiltered (gdb_stdlog
,
6153 "notif: process: '%s' no pending reply\n",
6158 /* Called when it is decided that STOP_REPLY holds the info of the
6159 event that is to be returned to the core. This function always
6160 destroys STOP_REPLY. */
6163 process_stop_reply (struct stop_reply
*stop_reply
,
6164 struct target_waitstatus
*status
)
6168 *status
= stop_reply
->ws
;
6169 ptid
= stop_reply
->ptid
;
6171 /* If no thread/process was reported by the stub, assume the current
6173 if (ptid_equal (ptid
, null_ptid
))
6174 ptid
= inferior_ptid
;
6176 if (status
->kind
!= TARGET_WAITKIND_EXITED
6177 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6179 struct remote_state
*rs
= get_remote_state ();
6181 /* Expedited registers. */
6182 if (stop_reply
->regcache
)
6184 struct regcache
*regcache
6185 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6190 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6192 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6193 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6196 rs
->stop_reason
= stop_reply
->stop_reason
;
6197 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6199 remote_notice_new_inferior (ptid
, 0);
6200 demand_private_info (ptid
)->core
= stop_reply
->core
;
6203 stop_reply_xfree (stop_reply
);
6207 /* The non-stop mode version of target_wait. */
6210 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6212 struct remote_state
*rs
= get_remote_state ();
6213 struct stop_reply
*stop_reply
;
6217 /* If in non-stop mode, get out of getpkt even if a
6218 notification is received. */
6220 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6221 0 /* forever */, &is_notif
);
6224 if (ret
!= -1 && !is_notif
)
6227 case 'E': /* Error of some sort. */
6228 /* We're out of sync with the target now. Did it continue
6229 or not? We can't tell which thread it was in non-stop,
6230 so just ignore this. */
6231 warning (_("Remote failure reply: %s"), rs
->buf
);
6233 case 'O': /* Console output. */
6234 remote_console_output (rs
->buf
+ 1);
6237 warning (_("Invalid remote reply: %s"), rs
->buf
);
6241 /* Acknowledge a pending stop reply that may have arrived in the
6243 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6244 remote_notif_get_pending_events (¬if_client_stop
);
6246 /* If indeed we noticed a stop reply, we're done. */
6247 stop_reply
= queued_stop_reply (ptid
);
6248 if (stop_reply
!= NULL
)
6249 return process_stop_reply (stop_reply
, status
);
6251 /* Still no event. If we're just polling for an event, then
6252 return to the event loop. */
6253 if (options
& TARGET_WNOHANG
)
6255 status
->kind
= TARGET_WAITKIND_IGNORE
;
6256 return minus_one_ptid
;
6259 /* Otherwise do a blocking wait. */
6260 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6261 1 /* forever */, &is_notif
);
6265 /* Wait until the remote machine stops, then return, storing status in
6266 STATUS just as `wait' would. */
6269 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6271 struct remote_state
*rs
= get_remote_state ();
6272 ptid_t event_ptid
= null_ptid
;
6274 struct stop_reply
*stop_reply
;
6278 status
->kind
= TARGET_WAITKIND_IGNORE
;
6279 status
->value
.integer
= 0;
6281 stop_reply
= queued_stop_reply (ptid
);
6282 if (stop_reply
!= NULL
)
6283 return process_stop_reply (stop_reply
, status
);
6285 if (rs
->cached_wait_status
)
6286 /* Use the cached wait status, but only once. */
6287 rs
->cached_wait_status
= 0;
6292 int forever
= ((options
& TARGET_WNOHANG
) == 0
6293 && wait_forever_enabled_p
);
6295 if (!rs
->waiting_for_stop_reply
)
6297 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6298 return minus_one_ptid
;
6301 if (!target_is_async_p ())
6303 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6304 /* If the user hit C-c before this packet, or between packets,
6305 pretend that it was hit right here. */
6306 if (check_quit_flag ())
6309 sync_remote_interrupt (SIGINT
);
6313 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6314 _never_ wait for ever -> test on target_is_async_p().
6315 However, before we do that we need to ensure that the caller
6316 knows how to take the target into/out of async mode. */
6317 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6318 forever
, &is_notif
);
6320 if (!target_is_async_p ())
6321 signal (SIGINT
, ofunc
);
6323 /* GDB gets a notification. Return to core as this event is
6325 if (ret
!= -1 && is_notif
)
6326 return minus_one_ptid
;
6328 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6329 return minus_one_ptid
;
6334 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6336 /* We got something. */
6337 rs
->waiting_for_stop_reply
= 0;
6339 /* Assume that the target has acknowledged Ctrl-C unless we receive
6340 an 'F' or 'O' packet. */
6341 if (buf
[0] != 'F' && buf
[0] != 'O')
6342 rs
->ctrlc_pending_p
= 0;
6346 case 'E': /* Error of some sort. */
6347 /* We're out of sync with the target now. Did it continue or
6348 not? Not is more likely, so report a stop. */
6349 warning (_("Remote failure reply: %s"), buf
);
6350 status
->kind
= TARGET_WAITKIND_STOPPED
;
6351 status
->value
.sig
= GDB_SIGNAL_0
;
6353 case 'F': /* File-I/O request. */
6354 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6355 rs
->ctrlc_pending_p
= 0;
6357 case 'T': case 'S': case 'X': case 'W':
6359 struct stop_reply
*stop_reply
6360 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6363 event_ptid
= process_stop_reply (stop_reply
, status
);
6366 case 'O': /* Console output. */
6367 remote_console_output (buf
+ 1);
6369 /* The target didn't really stop; keep waiting. */
6370 rs
->waiting_for_stop_reply
= 1;
6374 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6376 /* Zero length reply means that we tried 'S' or 'C' and the
6377 remote system doesn't support it. */
6378 target_terminal_ours_for_output ();
6380 ("Can't send signals to this remote system. %s not sent.\n",
6381 gdb_signal_to_name (rs
->last_sent_signal
));
6382 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6383 target_terminal_inferior ();
6385 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6386 putpkt ((char *) buf
);
6388 /* We just told the target to resume, so a stop reply is in
6390 rs
->waiting_for_stop_reply
= 1;
6393 /* else fallthrough */
6395 warning (_("Invalid remote reply: %s"), buf
);
6397 rs
->waiting_for_stop_reply
= 1;
6401 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6403 /* Nothing interesting happened. If we're doing a non-blocking
6404 poll, we're done. Otherwise, go back to waiting. */
6405 if (options
& TARGET_WNOHANG
)
6406 return minus_one_ptid
;
6410 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6411 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6413 if (!ptid_equal (event_ptid
, null_ptid
))
6414 record_currthread (rs
, event_ptid
);
6416 event_ptid
= inferior_ptid
;
6419 /* A process exit. Invalidate our notion of current thread. */
6420 record_currthread (rs
, minus_one_ptid
);
6425 /* Wait until the remote machine stops, then return, storing status in
6426 STATUS just as `wait' would. */
6429 remote_wait (struct target_ops
*ops
,
6430 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6435 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6437 event_ptid
= remote_wait_as (ptid
, status
, options
);
6439 if (target_is_async_p ())
6441 /* If there are are events left in the queue tell the event loop
6443 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6444 mark_async_event_handler (remote_async_inferior_event_token
);
6450 /* Fetch a single register using a 'p' packet. */
6453 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6455 struct remote_state
*rs
= get_remote_state ();
6457 char regp
[MAX_REGISTER_SIZE
];
6460 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6463 if (reg
->pnum
== -1)
6468 p
+= hexnumstr (p
, reg
->pnum
);
6471 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6475 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6479 case PACKET_UNKNOWN
:
6482 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6483 gdbarch_register_name (get_regcache_arch (regcache
),
6488 /* If this register is unfetchable, tell the regcache. */
6491 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6495 /* Otherwise, parse and supply the value. */
6501 error (_("fetch_register_using_p: early buf termination"));
6503 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6506 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6510 /* Fetch the registers included in the target's 'g' packet. */
6513 send_g_packet (void)
6515 struct remote_state
*rs
= get_remote_state ();
6518 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6519 remote_send (&rs
->buf
, &rs
->buf_size
);
6521 /* We can get out of synch in various cases. If the first character
6522 in the buffer is not a hex character, assume that has happened
6523 and try to fetch another packet to read. */
6524 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6525 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6526 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6527 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6530 fprintf_unfiltered (gdb_stdlog
,
6531 "Bad register packet; fetching a new packet\n");
6532 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6535 buf_len
= strlen (rs
->buf
);
6537 /* Sanity check the received packet. */
6538 if (buf_len
% 2 != 0)
6539 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6545 process_g_packet (struct regcache
*regcache
)
6547 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6548 struct remote_state
*rs
= get_remote_state ();
6549 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6554 buf_len
= strlen (rs
->buf
);
6556 /* Further sanity checks, with knowledge of the architecture. */
6557 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6558 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6560 /* Save the size of the packet sent to us by the target. It is used
6561 as a heuristic when determining the max size of packets that the
6562 target can safely receive. */
6563 if (rsa
->actual_register_packet_size
== 0)
6564 rsa
->actual_register_packet_size
= buf_len
;
6566 /* If this is smaller than we guessed the 'g' packet would be,
6567 update our records. A 'g' reply that doesn't include a register's
6568 value implies either that the register is not available, or that
6569 the 'p' packet must be used. */
6570 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6572 rsa
->sizeof_g_packet
= buf_len
/ 2;
6574 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6576 if (rsa
->regs
[i
].pnum
== -1)
6579 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6580 rsa
->regs
[i
].in_g_packet
= 0;
6582 rsa
->regs
[i
].in_g_packet
= 1;
6586 regs
= alloca (rsa
->sizeof_g_packet
);
6588 /* Unimplemented registers read as all bits zero. */
6589 memset (regs
, 0, rsa
->sizeof_g_packet
);
6591 /* Reply describes registers byte by byte, each byte encoded as two
6592 hex characters. Suck them all up, then supply them to the
6593 register cacheing/storage mechanism. */
6596 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6598 if (p
[0] == 0 || p
[1] == 0)
6599 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6600 internal_error (__FILE__
, __LINE__
,
6601 _("unexpected end of 'g' packet reply"));
6603 if (p
[0] == 'x' && p
[1] == 'x')
6604 regs
[i
] = 0; /* 'x' */
6606 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6610 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6612 struct packet_reg
*r
= &rsa
->regs
[i
];
6616 if (r
->offset
* 2 >= strlen (rs
->buf
))
6617 /* This shouldn't happen - we adjusted in_g_packet above. */
6618 internal_error (__FILE__
, __LINE__
,
6619 _("unexpected end of 'g' packet reply"));
6620 else if (rs
->buf
[r
->offset
* 2] == 'x')
6622 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6623 /* The register isn't available, mark it as such (at
6624 the same time setting the value to zero). */
6625 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6628 regcache_raw_supply (regcache
, r
->regnum
,
6635 fetch_registers_using_g (struct regcache
*regcache
)
6638 process_g_packet (regcache
);
6641 /* Make the remote selected traceframe match GDB's selected
6645 set_remote_traceframe (void)
6648 struct remote_state
*rs
= get_remote_state ();
6650 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6653 /* Avoid recursion, remote_trace_find calls us again. */
6654 rs
->remote_traceframe_number
= get_traceframe_number ();
6656 newnum
= target_trace_find (tfind_number
,
6657 get_traceframe_number (), 0, 0, NULL
);
6659 /* Should not happen. If it does, all bets are off. */
6660 if (newnum
!= get_traceframe_number ())
6661 warning (_("could not set remote traceframe"));
6665 remote_fetch_registers (struct target_ops
*ops
,
6666 struct regcache
*regcache
, int regnum
)
6668 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6671 set_remote_traceframe ();
6672 set_general_thread (inferior_ptid
);
6676 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6678 gdb_assert (reg
!= NULL
);
6680 /* If this register might be in the 'g' packet, try that first -
6681 we are likely to read more than one register. If this is the
6682 first 'g' packet, we might be overly optimistic about its
6683 contents, so fall back to 'p'. */
6684 if (reg
->in_g_packet
)
6686 fetch_registers_using_g (regcache
);
6687 if (reg
->in_g_packet
)
6691 if (fetch_register_using_p (regcache
, reg
))
6694 /* This register is not available. */
6695 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6700 fetch_registers_using_g (regcache
);
6702 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6703 if (!rsa
->regs
[i
].in_g_packet
)
6704 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6706 /* This register is not available. */
6707 regcache_raw_supply (regcache
, i
, NULL
);
6711 /* Prepare to store registers. Since we may send them all (using a
6712 'G' request), we have to read out the ones we don't want to change
6716 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6718 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6720 gdb_byte buf
[MAX_REGISTER_SIZE
];
6722 /* Make sure the entire registers array is valid. */
6723 switch (packet_support (PACKET_P
))
6725 case PACKET_DISABLE
:
6726 case PACKET_SUPPORT_UNKNOWN
:
6727 /* Make sure all the necessary registers are cached. */
6728 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6729 if (rsa
->regs
[i
].in_g_packet
)
6730 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6737 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6738 packet was not recognized. */
6741 store_register_using_P (const struct regcache
*regcache
,
6742 struct packet_reg
*reg
)
6744 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6745 struct remote_state
*rs
= get_remote_state ();
6746 /* Try storing a single register. */
6747 char *buf
= rs
->buf
;
6748 gdb_byte regp
[MAX_REGISTER_SIZE
];
6751 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6754 if (reg
->pnum
== -1)
6757 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6758 p
= buf
+ strlen (buf
);
6759 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6760 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6762 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6764 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6769 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6770 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6771 case PACKET_UNKNOWN
:
6774 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6778 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6779 contents of the register cache buffer. FIXME: ignores errors. */
6782 store_registers_using_G (const struct regcache
*regcache
)
6784 struct remote_state
*rs
= get_remote_state ();
6785 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6789 /* Extract all the registers in the regcache copying them into a
6794 regs
= alloca (rsa
->sizeof_g_packet
);
6795 memset (regs
, 0, rsa
->sizeof_g_packet
);
6796 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6798 struct packet_reg
*r
= &rsa
->regs
[i
];
6801 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6805 /* Command describes registers byte by byte,
6806 each byte encoded as two hex characters. */
6809 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6811 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6813 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6814 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6815 error (_("Could not write registers; remote failure reply '%s'"),
6819 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6820 of the register cache buffer. FIXME: ignores errors. */
6823 remote_store_registers (struct target_ops
*ops
,
6824 struct regcache
*regcache
, int regnum
)
6826 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6829 set_remote_traceframe ();
6830 set_general_thread (inferior_ptid
);
6834 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6836 gdb_assert (reg
!= NULL
);
6838 /* Always prefer to store registers using the 'P' packet if
6839 possible; we often change only a small number of registers.
6840 Sometimes we change a larger number; we'd need help from a
6841 higher layer to know to use 'G'. */
6842 if (store_register_using_P (regcache
, reg
))
6845 /* For now, don't complain if we have no way to write the
6846 register. GDB loses track of unavailable registers too
6847 easily. Some day, this may be an error. We don't have
6848 any way to read the register, either... */
6849 if (!reg
->in_g_packet
)
6852 store_registers_using_G (regcache
);
6856 store_registers_using_G (regcache
);
6858 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6859 if (!rsa
->regs
[i
].in_g_packet
)
6860 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6861 /* See above for why we do not issue an error here. */
6866 /* Return the number of hex digits in num. */
6869 hexnumlen (ULONGEST num
)
6873 for (i
= 0; num
!= 0; i
++)
6879 /* Set BUF to the minimum number of hex digits representing NUM. */
6882 hexnumstr (char *buf
, ULONGEST num
)
6884 int len
= hexnumlen (num
);
6886 return hexnumnstr (buf
, num
, len
);
6890 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6893 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6899 for (i
= width
- 1; i
>= 0; i
--)
6901 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6908 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6911 remote_address_masked (CORE_ADDR addr
)
6913 unsigned int address_size
= remote_address_size
;
6915 /* If "remoteaddresssize" was not set, default to target address size. */
6917 address_size
= gdbarch_addr_bit (target_gdbarch ());
6919 if (address_size
> 0
6920 && address_size
< (sizeof (ULONGEST
) * 8))
6922 /* Only create a mask when that mask can safely be constructed
6923 in a ULONGEST variable. */
6926 mask
= (mask
<< address_size
) - 1;
6932 /* Determine whether the remote target supports binary downloading.
6933 This is accomplished by sending a no-op memory write of zero length
6934 to the target at the specified address. It does not suffice to send
6935 the whole packet, since many stubs strip the eighth bit and
6936 subsequently compute a wrong checksum, which causes real havoc with
6939 NOTE: This can still lose if the serial line is not eight-bit
6940 clean. In cases like this, the user should clear "remote
6944 check_binary_download (CORE_ADDR addr
)
6946 struct remote_state
*rs
= get_remote_state ();
6948 switch (packet_support (PACKET_X
))
6950 case PACKET_DISABLE
:
6954 case PACKET_SUPPORT_UNKNOWN
:
6960 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6962 p
+= hexnumstr (p
, (ULONGEST
) 0);
6966 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6967 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6969 if (rs
->buf
[0] == '\0')
6972 fprintf_unfiltered (gdb_stdlog
,
6973 "binary downloading NOT "
6974 "supported by target\n");
6975 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6980 fprintf_unfiltered (gdb_stdlog
,
6981 "binary downloading supported by target\n");
6982 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6989 /* Helper function to resize the payload in order to try to get a good
6990 alignment. We try to write an amount of data such that the next write will
6991 start on an address aligned on REMOTE_ALIGN_WRITES. */
6994 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
6996 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6999 /* Write memory data directly to the remote machine.
7000 This does not inform the data cache; the data cache uses this.
7001 HEADER is the starting part of the packet.
7002 MEMADDR is the address in the remote memory space.
7003 MYADDR is the address of the buffer in our space.
7004 LEN_UNITS is the number of addressable units to write.
7005 UNIT_SIZE is the length in bytes of an addressable unit.
7006 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7007 should send data as binary ('X'), or hex-encoded ('M').
7009 The function creates packet of the form
7010 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7012 where encoding of <DATA> is terminated by PACKET_FORMAT.
7014 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7017 Return the transferred status, error or OK (an
7018 'enum target_xfer_status' value). Save the number of addressable units
7019 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7021 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7022 exchange between gdb and the stub could look like (?? in place of the
7028 -> $M1000,3:eeeeffffeeee#??
7032 <- eeeeffffeeeedddd */
7034 static enum target_xfer_status
7035 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7036 const gdb_byte
*myaddr
, ULONGEST len_units
,
7037 int unit_size
, ULONGEST
*xfered_len_units
,
7038 char packet_format
, int use_length
)
7040 struct remote_state
*rs
= get_remote_state ();
7046 int payload_capacity_bytes
;
7047 int payload_length_bytes
;
7049 if (packet_format
!= 'X' && packet_format
!= 'M')
7050 internal_error (__FILE__
, __LINE__
,
7051 _("remote_write_bytes_aux: bad packet format"));
7054 return TARGET_XFER_EOF
;
7056 payload_capacity_bytes
= get_memory_write_packet_size ();
7058 /* The packet buffer will be large enough for the payload;
7059 get_memory_packet_size ensures this. */
7062 /* Compute the size of the actual payload by subtracting out the
7063 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7065 payload_capacity_bytes
-= strlen ("$,:#NN");
7067 /* The comma won't be used. */
7068 payload_capacity_bytes
+= 1;
7069 payload_capacity_bytes
-= strlen (header
);
7070 payload_capacity_bytes
-= hexnumlen (memaddr
);
7072 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7074 strcat (rs
->buf
, header
);
7075 p
= rs
->buf
+ strlen (header
);
7077 /* Compute a best guess of the number of bytes actually transfered. */
7078 if (packet_format
== 'X')
7080 /* Best guess at number of bytes that will fit. */
7081 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7083 payload_capacity_bytes
-= hexnumlen (todo_units
);
7084 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7088 /* Number of bytes that will fit. */
7089 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7091 payload_capacity_bytes
-= hexnumlen (todo_units
);
7092 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7095 if (todo_units
<= 0)
7096 internal_error (__FILE__
, __LINE__
,
7097 _("minimum packet size too small to write data"));
7099 /* If we already need another packet, then try to align the end
7100 of this packet to a useful boundary. */
7101 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7102 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7104 /* Append "<memaddr>". */
7105 memaddr
= remote_address_masked (memaddr
);
7106 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7113 /* Append the length and retain its location and size. It may need to be
7114 adjusted once the packet body has been created. */
7116 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7124 /* Append the packet body. */
7125 if (packet_format
== 'X')
7127 /* Binary mode. Send target system values byte by byte, in
7128 increasing byte addresses. Only escape certain critical
7130 payload_length_bytes
=
7131 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7132 &units_written
, payload_capacity_bytes
);
7134 /* If not all TODO units fit, then we'll need another packet. Make
7135 a second try to keep the end of the packet aligned. Don't do
7136 this if the packet is tiny. */
7137 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7141 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7143 if (new_todo_units
!= units_written
)
7144 payload_length_bytes
=
7145 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7146 (gdb_byte
*) p
, &units_written
,
7147 payload_capacity_bytes
);
7150 p
+= payload_length_bytes
;
7151 if (use_length
&& units_written
< todo_units
)
7153 /* Escape chars have filled up the buffer prematurely,
7154 and we have actually sent fewer units than planned.
7155 Fix-up the length field of the packet. Use the same
7156 number of characters as before. */
7157 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7159 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7164 /* Normal mode: Send target system values byte by byte, in
7165 increasing byte addresses. Each byte is encoded as a two hex
7167 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7168 units_written
= todo_units
;
7171 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7172 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7174 if (rs
->buf
[0] == 'E')
7175 return TARGET_XFER_E_IO
;
7177 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7178 send fewer units than we'd planned. */
7179 *xfered_len_units
= (ULONGEST
) units_written
;
7180 return TARGET_XFER_OK
;
7183 /* Write memory data directly to the remote machine.
7184 This does not inform the data cache; the data cache uses this.
7185 MEMADDR is the address in the remote memory space.
7186 MYADDR is the address of the buffer in our space.
7187 LEN is the number of bytes.
7189 Return the transferred status, error or OK (an
7190 'enum target_xfer_status' value). Save the number of bytes
7191 transferred in *XFERED_LEN. Only transfer a single packet. */
7193 static enum target_xfer_status
7194 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7195 int unit_size
, ULONGEST
*xfered_len
)
7197 char *packet_format
= 0;
7199 /* Check whether the target supports binary download. */
7200 check_binary_download (memaddr
);
7202 switch (packet_support (PACKET_X
))
7205 packet_format
= "X";
7207 case PACKET_DISABLE
:
7208 packet_format
= "M";
7210 case PACKET_SUPPORT_UNKNOWN
:
7211 internal_error (__FILE__
, __LINE__
,
7212 _("remote_write_bytes: bad internal state"));
7214 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7217 return remote_write_bytes_aux (packet_format
,
7218 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7219 packet_format
[0], 1);
7222 /* Read memory data directly from the remote machine.
7223 This does not use the data cache; the data cache uses this.
7224 MEMADDR is the address in the remote memory space.
7225 MYADDR is the address of the buffer in our space.
7226 LEN_UNITS is the number of addressable memory units to read..
7227 UNIT_SIZE is the length in bytes of an addressable unit.
7229 Return the transferred status, error or OK (an
7230 'enum target_xfer_status' value). Save the number of bytes
7231 transferred in *XFERED_LEN_UNITS.
7233 See the comment of remote_write_bytes_aux for an example of
7234 memory read/write exchange between gdb and the stub. */
7236 static enum target_xfer_status
7237 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7238 int unit_size
, ULONGEST
*xfered_len_units
)
7240 struct remote_state
*rs
= get_remote_state ();
7241 int buf_size_bytes
; /* Max size of packet output buffer. */
7246 buf_size_bytes
= get_memory_read_packet_size ();
7247 /* The packet buffer will be large enough for the payload;
7248 get_memory_packet_size ensures this. */
7250 /* Number of units that will fit. */
7251 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7253 /* Construct "m"<memaddr>","<len>". */
7254 memaddr
= remote_address_masked (memaddr
);
7257 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7259 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7263 if (rs
->buf
[0] == 'E'
7264 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7265 && rs
->buf
[3] == '\0')
7266 return TARGET_XFER_E_IO
;
7267 /* Reply describes memory byte by byte, each byte encoded as two hex
7270 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7271 /* Return what we have. Let higher layers handle partial reads. */
7272 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7273 return TARGET_XFER_OK
;
7276 /* Using the set of read-only target sections of remote, read live
7279 For interface/parameters/return description see target.h,
7282 static enum target_xfer_status
7283 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7284 ULONGEST memaddr
, ULONGEST len
,
7285 int unit_size
, ULONGEST
*xfered_len
)
7287 struct target_section
*secp
;
7288 struct target_section_table
*table
;
7290 secp
= target_section_by_addr (ops
, memaddr
);
7292 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7293 secp
->the_bfd_section
)
7296 struct target_section
*p
;
7297 ULONGEST memend
= memaddr
+ len
;
7299 table
= target_get_section_table (ops
);
7301 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7303 if (memaddr
>= p
->addr
)
7305 if (memend
<= p
->endaddr
)
7307 /* Entire transfer is within this section. */
7308 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7311 else if (memaddr
>= p
->endaddr
)
7313 /* This section ends before the transfer starts. */
7318 /* This section overlaps the transfer. Just do half. */
7319 len
= p
->endaddr
- memaddr
;
7320 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7327 return TARGET_XFER_EOF
;
7330 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7331 first if the requested memory is unavailable in traceframe.
7332 Otherwise, fall back to remote_read_bytes_1. */
7334 static enum target_xfer_status
7335 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7336 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7337 ULONGEST
*xfered_len
)
7340 return TARGET_XFER_EOF
;
7342 if (get_traceframe_number () != -1)
7344 VEC(mem_range_s
) *available
;
7346 /* If we fail to get the set of available memory, then the
7347 target does not support querying traceframe info, and so we
7348 attempt reading from the traceframe anyway (assuming the
7349 target implements the old QTro packet then). */
7350 if (traceframe_available_memory (&available
, memaddr
, len
))
7352 struct cleanup
*old_chain
;
7354 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7356 if (VEC_empty (mem_range_s
, available
)
7357 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7359 enum target_xfer_status res
;
7361 /* Don't read into the traceframe's available
7363 if (!VEC_empty (mem_range_s
, available
))
7365 LONGEST oldlen
= len
;
7367 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7368 gdb_assert (len
<= oldlen
);
7371 do_cleanups (old_chain
);
7373 /* This goes through the topmost target again. */
7374 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7375 len
, unit_size
, xfered_len
);
7376 if (res
== TARGET_XFER_OK
)
7377 return TARGET_XFER_OK
;
7380 /* No use trying further, we know some memory starting
7381 at MEMADDR isn't available. */
7383 return TARGET_XFER_UNAVAILABLE
;
7387 /* Don't try to read more than how much is available, in
7388 case the target implements the deprecated QTro packet to
7389 cater for older GDBs (the target's knowledge of read-only
7390 sections may be outdated by now). */
7391 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7393 do_cleanups (old_chain
);
7397 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7402 /* Sends a packet with content determined by the printf format string
7403 FORMAT and the remaining arguments, then gets the reply. Returns
7404 whether the packet was a success, a failure, or unknown. */
7406 static enum packet_result
remote_send_printf (const char *format
, ...)
7407 ATTRIBUTE_PRINTF (1, 2);
7409 static enum packet_result
7410 remote_send_printf (const char *format
, ...)
7412 struct remote_state
*rs
= get_remote_state ();
7413 int max_size
= get_remote_packet_size ();
7416 va_start (ap
, format
);
7419 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7420 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7422 if (putpkt (rs
->buf
) < 0)
7423 error (_("Communication problem with target."));
7426 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7428 return packet_check_result (rs
->buf
);
7432 restore_remote_timeout (void *p
)
7434 int value
= *(int *)p
;
7436 remote_timeout
= value
;
7439 /* Flash writing can take quite some time. We'll set
7440 effectively infinite timeout for flash operations.
7441 In future, we'll need to decide on a better approach. */
7442 static const int remote_flash_timeout
= 1000;
7445 remote_flash_erase (struct target_ops
*ops
,
7446 ULONGEST address
, LONGEST length
)
7448 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7449 int saved_remote_timeout
= remote_timeout
;
7450 enum packet_result ret
;
7451 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7452 &saved_remote_timeout
);
7454 remote_timeout
= remote_flash_timeout
;
7456 ret
= remote_send_printf ("vFlashErase:%s,%s",
7457 phex (address
, addr_size
),
7461 case PACKET_UNKNOWN
:
7462 error (_("Remote target does not support flash erase"));
7464 error (_("Error erasing flash with vFlashErase packet"));
7469 do_cleanups (back_to
);
7472 static enum target_xfer_status
7473 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7474 ULONGEST length
, ULONGEST
*xfered_len
,
7475 const gdb_byte
*data
)
7477 int saved_remote_timeout
= remote_timeout
;
7478 enum target_xfer_status ret
;
7479 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7480 &saved_remote_timeout
);
7482 remote_timeout
= remote_flash_timeout
;
7483 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7485 do_cleanups (back_to
);
7491 remote_flash_done (struct target_ops
*ops
)
7493 int saved_remote_timeout
= remote_timeout
;
7495 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7496 &saved_remote_timeout
);
7498 remote_timeout
= remote_flash_timeout
;
7499 ret
= remote_send_printf ("vFlashDone");
7500 do_cleanups (back_to
);
7504 case PACKET_UNKNOWN
:
7505 error (_("Remote target does not support vFlashDone"));
7507 error (_("Error finishing flash operation"));
7514 remote_files_info (struct target_ops
*ignore
)
7516 puts_filtered ("Debugging a target over a serial line.\n");
7519 /* Stuff for dealing with the packets which are part of this protocol.
7520 See comment at top of file for details. */
7522 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7523 error to higher layers. Called when a serial error is detected.
7524 The exception message is STRING, followed by a colon and a blank,
7525 the system error message for errno at function entry and final dot
7526 for output compatibility with throw_perror_with_name. */
7529 unpush_and_perror (const char *string
)
7531 int saved_errno
= errno
;
7533 remote_unpush_target ();
7534 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7535 safe_strerror (saved_errno
));
7538 /* Read a single character from the remote end. */
7541 readchar (int timeout
)
7544 struct remote_state
*rs
= get_remote_state ();
7546 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7551 switch ((enum serial_rc
) ch
)
7554 remote_unpush_target ();
7555 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7558 unpush_and_perror (_("Remote communication error. "
7559 "Target disconnected."));
7561 case SERIAL_TIMEOUT
:
7567 /* Wrapper for serial_write that closes the target and throws if
7571 remote_serial_write (const char *str
, int len
)
7573 struct remote_state
*rs
= get_remote_state ();
7575 if (serial_write (rs
->remote_desc
, str
, len
))
7577 unpush_and_perror (_("Remote communication error. "
7578 "Target disconnected."));
7582 /* Send the command in *BUF to the remote machine, and read the reply
7583 into *BUF. Report an error if we get an error reply. Resize
7584 *BUF using xrealloc if necessary to hold the result, and update
7588 remote_send (char **buf
,
7592 getpkt (buf
, sizeof_buf
, 0);
7594 if ((*buf
)[0] == 'E')
7595 error (_("Remote failure reply: %s"), *buf
);
7598 /* Return a pointer to an xmalloc'ed string representing an escaped
7599 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7600 etc. The caller is responsible for releasing the returned
7604 escape_buffer (const char *buf
, int n
)
7606 struct cleanup
*old_chain
;
7607 struct ui_file
*stb
;
7610 stb
= mem_fileopen ();
7611 old_chain
= make_cleanup_ui_file_delete (stb
);
7613 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7614 str
= ui_file_xstrdup (stb
, NULL
);
7615 do_cleanups (old_chain
);
7619 /* Display a null-terminated packet on stdout, for debugging, using C
7623 print_packet (const char *buf
)
7625 puts_filtered ("\"");
7626 fputstr_filtered (buf
, '"', gdb_stdout
);
7627 puts_filtered ("\"");
7631 putpkt (const char *buf
)
7633 return putpkt_binary (buf
, strlen (buf
));
7636 /* Send a packet to the remote machine, with error checking. The data
7637 of the packet is in BUF. The string in BUF can be at most
7638 get_remote_packet_size () - 5 to account for the $, # and checksum,
7639 and for a possible /0 if we are debugging (remote_debug) and want
7640 to print the sent packet as a string. */
7643 putpkt_binary (const char *buf
, int cnt
)
7645 struct remote_state
*rs
= get_remote_state ();
7647 unsigned char csum
= 0;
7648 char *buf2
= alloca (cnt
+ 6);
7655 /* Catch cases like trying to read memory or listing threads while
7656 we're waiting for a stop reply. The remote server wouldn't be
7657 ready to handle this request, so we'd hang and timeout. We don't
7658 have to worry about this in synchronous mode, because in that
7659 case it's not possible to issue a command while the target is
7660 running. This is not a problem in non-stop mode, because in that
7661 case, the stub is always ready to process serial input. */
7662 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7664 error (_("Cannot execute this command while the target is running.\n"
7665 "Use the \"interrupt\" command to stop the target\n"
7666 "and then try again."));
7669 /* We're sending out a new packet. Make sure we don't look at a
7670 stale cached response. */
7671 rs
->cached_wait_status
= 0;
7673 /* Copy the packet into buffer BUF2, encapsulating it
7674 and giving it a checksum. */
7679 for (i
= 0; i
< cnt
; i
++)
7685 *p
++ = tohex ((csum
>> 4) & 0xf);
7686 *p
++ = tohex (csum
& 0xf);
7688 /* Send it over and over until we get a positive ack. */
7692 int started_error_output
= 0;
7696 struct cleanup
*old_chain
;
7700 str
= escape_buffer (buf2
, p
- buf2
);
7701 old_chain
= make_cleanup (xfree
, str
);
7702 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7703 gdb_flush (gdb_stdlog
);
7704 do_cleanups (old_chain
);
7706 remote_serial_write (buf2
, p
- buf2
);
7708 /* If this is a no acks version of the remote protocol, send the
7709 packet and move on. */
7713 /* Read until either a timeout occurs (-2) or '+' is read.
7714 Handle any notification that arrives in the mean time. */
7717 ch
= readchar (remote_timeout
);
7725 case SERIAL_TIMEOUT
:
7728 if (started_error_output
)
7730 putchar_unfiltered ('\n');
7731 started_error_output
= 0;
7740 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7744 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7746 case SERIAL_TIMEOUT
:
7750 break; /* Retransmit buffer. */
7754 fprintf_unfiltered (gdb_stdlog
,
7755 "Packet instead of Ack, ignoring it\n");
7756 /* It's probably an old response sent because an ACK
7757 was lost. Gobble up the packet and ack it so it
7758 doesn't get retransmitted when we resend this
7761 remote_serial_write ("+", 1);
7762 continue; /* Now, go look for +. */
7769 /* If we got a notification, handle it, and go back to looking
7771 /* We've found the start of a notification. Now
7772 collect the data. */
7773 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7778 struct cleanup
*old_chain
;
7781 str
= escape_buffer (rs
->buf
, val
);
7782 old_chain
= make_cleanup (xfree
, str
);
7783 fprintf_unfiltered (gdb_stdlog
,
7784 " Notification received: %s\n",
7786 do_cleanups (old_chain
);
7788 handle_notification (rs
->notif_state
, rs
->buf
);
7789 /* We're in sync now, rewait for the ack. */
7796 if (!started_error_output
)
7798 started_error_output
= 1;
7799 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7801 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7802 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7811 if (!started_error_output
)
7813 started_error_output
= 1;
7814 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7816 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7820 break; /* Here to retransmit. */
7824 /* This is wrong. If doing a long backtrace, the user should be
7825 able to get out next time we call QUIT, without anything as
7826 violent as interrupt_query. If we want to provide a way out of
7827 here without getting to the next QUIT, it should be based on
7828 hitting ^C twice as in remote_wait. */
7839 /* Come here after finding the start of a frame when we expected an
7840 ack. Do our best to discard the rest of this packet. */
7849 c
= readchar (remote_timeout
);
7852 case SERIAL_TIMEOUT
:
7853 /* Nothing we can do. */
7856 /* Discard the two bytes of checksum and stop. */
7857 c
= readchar (remote_timeout
);
7859 c
= readchar (remote_timeout
);
7862 case '*': /* Run length encoding. */
7863 /* Discard the repeat count. */
7864 c
= readchar (remote_timeout
);
7869 /* A regular character. */
7875 /* Come here after finding the start of the frame. Collect the rest
7876 into *BUF, verifying the checksum, length, and handling run-length
7877 compression. NUL terminate the buffer. If there is not enough room,
7878 expand *BUF using xrealloc.
7880 Returns -1 on error, number of characters in buffer (ignoring the
7881 trailing NULL) on success. (could be extended to return one of the
7882 SERIAL status indications). */
7885 read_frame (char **buf_p
,
7892 struct remote_state
*rs
= get_remote_state ();
7899 c
= readchar (remote_timeout
);
7902 case SERIAL_TIMEOUT
:
7904 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7908 fputs_filtered ("Saw new packet start in middle of old one\n",
7910 return -1; /* Start a new packet, count retries. */
7913 unsigned char pktcsum
;
7919 check_0
= readchar (remote_timeout
);
7921 check_1
= readchar (remote_timeout
);
7923 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7926 fputs_filtered ("Timeout in checksum, retrying\n",
7930 else if (check_0
< 0 || check_1
< 0)
7933 fputs_filtered ("Communication error in checksum\n",
7938 /* Don't recompute the checksum; with no ack packets we
7939 don't have any way to indicate a packet retransmission
7944 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7945 if (csum
== pktcsum
)
7950 struct cleanup
*old_chain
;
7953 str
= escape_buffer (buf
, bc
);
7954 old_chain
= make_cleanup (xfree
, str
);
7955 fprintf_unfiltered (gdb_stdlog
,
7956 "Bad checksum, sentsum=0x%x, "
7957 "csum=0x%x, buf=%s\n",
7958 pktcsum
, csum
, str
);
7959 do_cleanups (old_chain
);
7961 /* Number of characters in buffer ignoring trailing
7965 case '*': /* Run length encoding. */
7970 c
= readchar (remote_timeout
);
7972 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7974 /* The character before ``*'' is repeated. */
7976 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7978 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7980 /* Make some more room in the buffer. */
7981 *sizeof_buf
+= repeat
;
7982 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7986 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7992 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7996 if (bc
>= *sizeof_buf
- 1)
7998 /* Make some more room in the buffer. */
8000 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
8011 /* Read a packet from the remote machine, with error checking, and
8012 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8013 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8014 rather than timing out; this is used (in synchronous mode) to wait
8015 for a target that is is executing user code to stop. */
8016 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8017 don't have to change all the calls to getpkt to deal with the
8018 return value, because at the moment I don't know what the right
8019 thing to do it for those. */
8027 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
8031 /* Read a packet from the remote machine, with error checking, and
8032 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8033 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8034 rather than timing out; this is used (in synchronous mode) to wait
8035 for a target that is is executing user code to stop. If FOREVER ==
8036 0, this function is allowed to time out gracefully and return an
8037 indication of this to the caller. Otherwise return the number of
8038 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8039 enough reason to return to the caller. *IS_NOTIF is an output
8040 boolean that indicates whether *BUF holds a notification or not
8041 (a regular packet). */
8044 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8045 int expecting_notif
, int *is_notif
)
8047 struct remote_state
*rs
= get_remote_state ();
8053 /* We're reading a new response. Make sure we don't look at a
8054 previously cached response. */
8055 rs
->cached_wait_status
= 0;
8057 strcpy (*buf
, "timeout");
8060 timeout
= watchdog
> 0 ? watchdog
: -1;
8061 else if (expecting_notif
)
8062 timeout
= 0; /* There should already be a char in the buffer. If
8065 timeout
= remote_timeout
;
8069 /* Process any number of notifications, and then return when
8073 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8075 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8077 /* This can loop forever if the remote side sends us
8078 characters continuously, but if it pauses, we'll get
8079 SERIAL_TIMEOUT from readchar because of timeout. Then
8080 we'll count that as a retry.
8082 Note that even when forever is set, we will only wait
8083 forever prior to the start of a packet. After that, we
8084 expect characters to arrive at a brisk pace. They should
8085 show up within remote_timeout intervals. */
8087 c
= readchar (timeout
);
8088 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8090 if (c
== SERIAL_TIMEOUT
)
8092 if (expecting_notif
)
8093 return -1; /* Don't complain, it's normal to not get
8094 anything in this case. */
8096 if (forever
) /* Watchdog went off? Kill the target. */
8099 remote_unpush_target ();
8100 throw_error (TARGET_CLOSE_ERROR
,
8101 _("Watchdog timeout has expired. "
8102 "Target detached."));
8105 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8109 /* We've found the start of a packet or notification.
8110 Now collect the data. */
8111 val
= read_frame (buf
, sizeof_buf
);
8116 remote_serial_write ("-", 1);
8119 if (tries
> MAX_TRIES
)
8121 /* We have tried hard enough, and just can't receive the
8122 packet/notification. Give up. */
8123 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8125 /* Skip the ack char if we're in no-ack mode. */
8126 if (!rs
->noack_mode
)
8127 remote_serial_write ("+", 1);
8131 /* If we got an ordinary packet, return that to our caller. */
8136 struct cleanup
*old_chain
;
8139 str
= escape_buffer (*buf
, val
);
8140 old_chain
= make_cleanup (xfree
, str
);
8141 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8142 do_cleanups (old_chain
);
8145 /* Skip the ack char if we're in no-ack mode. */
8146 if (!rs
->noack_mode
)
8147 remote_serial_write ("+", 1);
8148 if (is_notif
!= NULL
)
8153 /* If we got a notification, handle it, and go back to looking
8157 gdb_assert (c
== '%');
8161 struct cleanup
*old_chain
;
8164 str
= escape_buffer (*buf
, val
);
8165 old_chain
= make_cleanup (xfree
, str
);
8166 fprintf_unfiltered (gdb_stdlog
,
8167 " Notification received: %s\n",
8169 do_cleanups (old_chain
);
8171 if (is_notif
!= NULL
)
8174 handle_notification (rs
->notif_state
, *buf
);
8176 /* Notifications require no acknowledgement. */
8178 if (expecting_notif
)
8185 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8187 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8191 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8194 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8198 /* Check whether EVENT is a fork event for the process specified
8199 by the pid passed in DATA, and if it is, kill the fork child. */
8202 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8203 QUEUE_ITER (stop_reply_p
) *iter
,
8207 struct queue_iter_param
*param
= data
;
8208 int parent_pid
= *(int *) param
->input
;
8210 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8212 struct remote_state
*rs
= get_remote_state ();
8213 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8216 res
= remote_vkill (child_pid
, rs
);
8218 error (_("Can't kill fork child process %d"), child_pid
);
8224 /* Kill any new fork children of process PID that haven't been
8225 processed by follow_fork. */
8228 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8230 struct thread_info
*thread
;
8231 struct notif_client
*notif
= ¬if_client_stop
;
8232 struct queue_iter_param param
;
8234 /* Kill the fork child threads of any threads in process PID
8235 that are stopped at a fork event. */
8236 ALL_NON_EXITED_THREADS (thread
)
8238 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8240 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8242 struct remote_state
*rs
= get_remote_state ();
8243 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8246 res
= remote_vkill (child_pid
, rs
);
8248 error (_("Can't kill fork child process %d"), child_pid
);
8252 /* Check for any pending fork events (not reported or processed yet)
8253 in process PID and kill those fork child threads as well. */
8254 remote_notif_get_pending_events (notif
);
8256 param
.output
= NULL
;
8257 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8258 kill_child_of_pending_fork
, ¶m
);
8263 remote_kill (struct target_ops
*ops
)
8266 /* Catch errors so the user can quit from gdb even when we
8267 aren't on speaking terms with the remote system. */
8272 CATCH (ex
, RETURN_MASK_ERROR
)
8274 if (ex
.error
== TARGET_CLOSE_ERROR
)
8276 /* If we got an (EOF) error that caused the target
8277 to go away, then we're done, that's what we wanted.
8278 "k" is susceptible to cause a premature EOF, given
8279 that the remote server isn't actually required to
8280 reply to "k", and it can happen that it doesn't
8281 even get to reply ACK to the "k". */
8285 /* Otherwise, something went wrong. We didn't actually kill
8286 the target. Just propagate the exception, and let the
8287 user or higher layers decide what to do. */
8288 throw_exception (ex
);
8292 /* We've killed the remote end, we get to mourn it. Since this is
8293 target remote, single-process, mourning the inferior also
8294 unpushes remote_ops. */
8295 target_mourn_inferior ();
8299 remote_vkill (int pid
, struct remote_state
*rs
)
8301 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8304 /* Tell the remote target to detach. */
8305 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8307 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8309 switch (packet_ok (rs
->buf
,
8310 &remote_protocol_packets
[PACKET_vKill
]))
8316 case PACKET_UNKNOWN
:
8319 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8324 extended_remote_kill (struct target_ops
*ops
)
8327 int pid
= ptid_get_pid (inferior_ptid
);
8328 struct remote_state
*rs
= get_remote_state ();
8330 /* If we're stopped while forking and we haven't followed yet, kill the
8331 child task. We need to do this before killing the parent task
8332 because if this is a vfork then the parent will be sleeping. */
8333 kill_new_fork_children (pid
, rs
);
8335 res
= remote_vkill (pid
, rs
);
8336 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8338 /* Don't try 'k' on a multi-process aware stub -- it has no way
8339 to specify the pid. */
8343 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8344 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8347 /* Don't wait for it to die. I'm not really sure it matters whether
8348 we do or not. For the existing stubs, kill is a noop. */
8354 error (_("Can't kill process"));
8356 target_mourn_inferior ();
8360 remote_mourn (struct target_ops
*target
)
8362 unpush_target (target
);
8364 /* remote_close takes care of doing most of the clean up. */
8365 generic_mourn_inferior ();
8369 extended_remote_mourn (struct target_ops
*target
)
8371 struct remote_state
*rs
= get_remote_state ();
8373 /* In case we got here due to an error, but we're going to stay
8375 rs
->waiting_for_stop_reply
= 0;
8377 /* If the current general thread belonged to the process we just
8378 detached from or has exited, the remote side current general
8379 thread becomes undefined. Considering a case like this:
8381 - We just got here due to a detach.
8382 - The process that we're detaching from happens to immediately
8383 report a global breakpoint being hit in non-stop mode, in the
8384 same thread we had selected before.
8385 - GDB attaches to this process again.
8386 - This event happens to be the next event we handle.
8388 GDB would consider that the current general thread didn't need to
8389 be set on the stub side (with Hg), since for all it knew,
8390 GENERAL_THREAD hadn't changed.
8392 Notice that although in all-stop mode, the remote server always
8393 sets the current thread to the thread reporting the stop event,
8394 that doesn't happen in non-stop mode; in non-stop, the stub *must
8395 not* change the current thread when reporting a breakpoint hit,
8396 due to the decoupling of event reporting and event handling.
8398 To keep things simple, we always invalidate our notion of the
8400 record_currthread (rs
, minus_one_ptid
);
8402 /* Unlike "target remote", we do not want to unpush the target; then
8403 the next time the user says "run", we won't be connected. */
8405 /* Call common code to mark the inferior as not running. */
8406 generic_mourn_inferior ();
8408 if (!have_inferiors ())
8410 if (!remote_multi_process_p (rs
))
8412 /* Check whether the target is running now - some remote stubs
8413 automatically restart after kill. */
8415 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8417 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8419 /* Assume that the target has been restarted. Set
8420 inferior_ptid so that bits of core GDB realizes
8421 there's something here, e.g., so that the user can
8422 say "kill" again. */
8423 inferior_ptid
= magic_null_ptid
;
8430 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8432 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8436 extended_remote_disable_randomization (int val
)
8438 struct remote_state
*rs
= get_remote_state ();
8441 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8444 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8446 error (_("Target does not support QDisableRandomization."));
8447 if (strcmp (reply
, "OK") != 0)
8448 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8452 extended_remote_run (char *args
)
8454 struct remote_state
*rs
= get_remote_state ();
8457 /* If the user has disabled vRun support, or we have detected that
8458 support is not available, do not try it. */
8459 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8462 strcpy (rs
->buf
, "vRun;");
8463 len
= strlen (rs
->buf
);
8465 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8466 error (_("Remote file name too long for run packet"));
8467 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8468 strlen (remote_exec_file
));
8470 gdb_assert (args
!= NULL
);
8473 struct cleanup
*back_to
;
8477 argv
= gdb_buildargv (args
);
8478 back_to
= make_cleanup_freeargv (argv
);
8479 for (i
= 0; argv
[i
] != NULL
; i
++)
8481 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8482 error (_("Argument list too long for run packet"));
8483 rs
->buf
[len
++] = ';';
8484 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8487 do_cleanups (back_to
);
8490 rs
->buf
[len
++] = '\0';
8493 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8495 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8498 /* We have a wait response. All is well. */
8500 case PACKET_UNKNOWN
:
8503 if (remote_exec_file
[0] == '\0')
8504 error (_("Running the default executable on the remote target failed; "
8505 "try \"set remote exec-file\"?"));
8507 error (_("Running \"%s\" on the remote target failed"),
8510 gdb_assert_not_reached (_("bad switch"));
8514 /* In the extended protocol we want to be able to do things like
8515 "run" and have them basically work as expected. So we need
8516 a special create_inferior function. We support changing the
8517 executable file and the command line arguments, but not the
8521 extended_remote_create_inferior (struct target_ops
*ops
,
8522 char *exec_file
, char *args
,
8523 char **env
, int from_tty
)
8527 struct remote_state
*rs
= get_remote_state ();
8529 /* If running asynchronously, register the target file descriptor
8530 with the event loop. */
8531 if (target_can_async_p ())
8534 /* Disable address space randomization if requested (and supported). */
8535 if (extended_remote_supports_disable_randomization (ops
))
8536 extended_remote_disable_randomization (disable_randomization
);
8538 /* Now restart the remote server. */
8539 run_worked
= extended_remote_run (args
) != -1;
8542 /* vRun was not supported. Fail if we need it to do what the
8544 if (remote_exec_file
[0])
8545 error (_("Remote target does not support \"set remote exec-file\""));
8547 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8549 /* Fall back to "R". */
8550 extended_remote_restart ();
8553 if (!have_inferiors ())
8555 /* Clean up from the last time we ran, before we mark the target
8556 running again. This will mark breakpoints uninserted, and
8557 get_offsets may insert breakpoints. */
8558 init_thread_list ();
8559 init_wait_for_inferior ();
8562 /* vRun's success return is a stop reply. */
8563 stop_reply
= run_worked
? rs
->buf
: NULL
;
8564 add_current_inferior_and_thread (stop_reply
);
8566 /* Get updated offsets, if the stub uses qOffsets. */
8571 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8572 the list of conditions (in agent expression bytecode format), if any, the
8573 target needs to evaluate. The output is placed into the packet buffer
8574 started from BUF and ended at BUF_END. */
8577 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8578 struct bp_target_info
*bp_tgt
, char *buf
,
8581 struct agent_expr
*aexpr
= NULL
;
8584 char *buf_start
= buf
;
8586 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8589 buf
+= strlen (buf
);
8590 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8593 /* Send conditions to the target and free the vector. */
8595 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8598 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8599 buf
+= strlen (buf
);
8600 for (i
= 0; i
< aexpr
->len
; ++i
)
8601 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8608 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8609 struct bp_target_info
*bp_tgt
, char *buf
)
8611 struct agent_expr
*aexpr
= NULL
;
8614 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8617 buf
+= strlen (buf
);
8619 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8620 buf
+= strlen (buf
);
8622 /* Concatenate all the agent expressions that are commands into the
8625 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8628 sprintf (buf
, "X%x,", aexpr
->len
);
8629 buf
+= strlen (buf
);
8630 for (i
= 0; i
< aexpr
->len
; ++i
)
8631 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8636 /* Insert a breakpoint. On targets that have software breakpoint
8637 support, we ask the remote target to do the work; on targets
8638 which don't, we insert a traditional memory breakpoint. */
8641 remote_insert_breakpoint (struct target_ops
*ops
,
8642 struct gdbarch
*gdbarch
,
8643 struct bp_target_info
*bp_tgt
)
8645 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8646 If it succeeds, then set the support to PACKET_ENABLE. If it
8647 fails, and the user has explicitly requested the Z support then
8648 report an error, otherwise, mark it disabled and go on. */
8650 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8652 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8653 struct remote_state
*rs
;
8656 struct condition_list
*cond
= NULL
;
8658 /* Make sure the remote is pointing at the right process, if
8660 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8661 set_general_process ();
8663 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8665 rs
= get_remote_state ();
8667 endbuf
= rs
->buf
+ get_remote_packet_size ();
8672 addr
= (ULONGEST
) remote_address_masked (addr
);
8673 p
+= hexnumstr (p
, addr
);
8674 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8676 if (remote_supports_cond_breakpoints (ops
))
8677 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8679 if (remote_can_run_breakpoint_commands (ops
))
8680 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8685 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8690 bp_tgt
->placed_address
= addr
;
8691 bp_tgt
->placed_size
= bpsize
;
8693 case PACKET_UNKNOWN
:
8698 /* If this breakpoint has target-side commands but this stub doesn't
8699 support Z0 packets, throw error. */
8700 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8701 throw_error (NOT_SUPPORTED_ERROR
, _("\
8702 Target doesn't support breakpoints that have target side commands."));
8704 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8708 remote_remove_breakpoint (struct target_ops
*ops
,
8709 struct gdbarch
*gdbarch
,
8710 struct bp_target_info
*bp_tgt
)
8712 CORE_ADDR addr
= bp_tgt
->placed_address
;
8713 struct remote_state
*rs
= get_remote_state ();
8715 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8718 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8720 /* Make sure the remote is pointing at the right process, if
8722 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8723 set_general_process ();
8729 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8730 p
+= hexnumstr (p
, addr
);
8731 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8734 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8736 return (rs
->buf
[0] == 'E');
8739 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8742 static enum Z_packet_type
8743 watchpoint_to_Z_packet (int type
)
8748 return Z_PACKET_WRITE_WP
;
8751 return Z_PACKET_READ_WP
;
8754 return Z_PACKET_ACCESS_WP
;
8757 internal_error (__FILE__
, __LINE__
,
8758 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8763 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8764 enum target_hw_bp_type type
, struct expression
*cond
)
8766 struct remote_state
*rs
= get_remote_state ();
8767 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8769 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8771 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8774 /* Make sure the remote is pointing at the right process, if
8776 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8777 set_general_process ();
8779 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8780 p
= strchr (rs
->buf
, '\0');
8781 addr
= remote_address_masked (addr
);
8782 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8783 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8786 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8788 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8792 case PACKET_UNKNOWN
:
8797 internal_error (__FILE__
, __LINE__
,
8798 _("remote_insert_watchpoint: reached end of function"));
8802 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8803 CORE_ADDR start
, int length
)
8805 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8807 return diff
< length
;
8812 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8813 enum target_hw_bp_type type
, struct expression
*cond
)
8815 struct remote_state
*rs
= get_remote_state ();
8816 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8818 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8820 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8823 /* Make sure the remote is pointing at the right process, if
8825 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8826 set_general_process ();
8828 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8829 p
= strchr (rs
->buf
, '\0');
8830 addr
= remote_address_masked (addr
);
8831 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8832 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8834 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8836 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8839 case PACKET_UNKNOWN
:
8844 internal_error (__FILE__
, __LINE__
,
8845 _("remote_remove_watchpoint: reached end of function"));
8849 int remote_hw_watchpoint_limit
= -1;
8850 int remote_hw_watchpoint_length_limit
= -1;
8851 int remote_hw_breakpoint_limit
= -1;
8854 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8855 CORE_ADDR addr
, int len
)
8857 if (remote_hw_watchpoint_length_limit
== 0)
8859 else if (remote_hw_watchpoint_length_limit
< 0)
8861 else if (len
<= remote_hw_watchpoint_length_limit
)
8868 remote_check_watch_resources (struct target_ops
*self
,
8869 enum bptype type
, int cnt
, int ot
)
8871 if (type
== bp_hardware_breakpoint
)
8873 if (remote_hw_breakpoint_limit
== 0)
8875 else if (remote_hw_breakpoint_limit
< 0)
8877 else if (cnt
<= remote_hw_breakpoint_limit
)
8882 if (remote_hw_watchpoint_limit
== 0)
8884 else if (remote_hw_watchpoint_limit
< 0)
8888 else if (cnt
<= remote_hw_watchpoint_limit
)
8894 /* The to_stopped_by_sw_breakpoint method of target remote. */
8897 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8899 struct remote_state
*rs
= get_remote_state ();
8901 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
8904 /* The to_supports_stopped_by_sw_breakpoint method of target
8908 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8910 struct remote_state
*rs
= get_remote_state ();
8912 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
8915 /* The to_stopped_by_hw_breakpoint method of target remote. */
8918 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8920 struct remote_state
*rs
= get_remote_state ();
8922 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
8925 /* The to_supports_stopped_by_hw_breakpoint method of target
8929 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8931 struct remote_state
*rs
= get_remote_state ();
8933 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
8937 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8939 struct remote_state
*rs
= get_remote_state ();
8941 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
8945 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8947 struct remote_state
*rs
= get_remote_state ();
8950 if (remote_stopped_by_watchpoint (target
))
8952 *addr_p
= rs
->remote_watch_data_address
;
8961 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8962 struct bp_target_info
*bp_tgt
)
8964 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8965 struct remote_state
*rs
;
8970 /* The length field should be set to the size of a breakpoint
8971 instruction, even though we aren't inserting one ourselves. */
8973 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8975 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8978 /* Make sure the remote is pointing at the right process, if
8980 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8981 set_general_process ();
8983 rs
= get_remote_state ();
8985 endbuf
= rs
->buf
+ get_remote_packet_size ();
8991 addr
= remote_address_masked (addr
);
8992 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8993 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
8995 if (remote_supports_cond_breakpoints (self
))
8996 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8998 if (remote_can_run_breakpoint_commands (self
))
8999 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9002 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9004 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9007 if (rs
->buf
[1] == '.')
9009 message
= strchr (rs
->buf
+ 2, '.');
9011 error (_("Remote failure reply: %s"), message
+ 1);
9014 case PACKET_UNKNOWN
:
9017 bp_tgt
->placed_address
= addr
;
9018 bp_tgt
->placed_size
= bpsize
;
9021 internal_error (__FILE__
, __LINE__
,
9022 _("remote_insert_hw_breakpoint: reached end of function"));
9027 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9028 struct bp_target_info
*bp_tgt
)
9031 struct remote_state
*rs
= get_remote_state ();
9033 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9035 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9038 /* Make sure the remote is pointing at the right process, if
9040 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9041 set_general_process ();
9047 addr
= remote_address_masked (bp_tgt
->placed_address
);
9048 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9049 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9054 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9057 case PACKET_UNKNOWN
:
9062 internal_error (__FILE__
, __LINE__
,
9063 _("remote_remove_hw_breakpoint: reached end of function"));
9066 /* Verify memory using the "qCRC:" request. */
9069 remote_verify_memory (struct target_ops
*ops
,
9070 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9072 struct remote_state
*rs
= get_remote_state ();
9073 unsigned long host_crc
, target_crc
;
9076 /* It doesn't make sense to use qCRC if the remote target is
9077 connected but not running. */
9078 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9080 enum packet_result result
;
9082 /* Make sure the remote is pointing at the right process. */
9083 set_general_process ();
9085 /* FIXME: assumes lma can fit into long. */
9086 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9087 (long) lma
, (long) size
);
9090 /* Be clever; compute the host_crc before waiting for target
9092 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9094 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9096 result
= packet_ok (rs
->buf
,
9097 &remote_protocol_packets
[PACKET_qCRC
]);
9098 if (result
== PACKET_ERROR
)
9100 else if (result
== PACKET_OK
)
9102 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9103 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9105 return (host_crc
== target_crc
);
9109 return simple_verify_memory (ops
, data
, lma
, size
);
9112 /* compare-sections command
9114 With no arguments, compares each loadable section in the exec bfd
9115 with the same memory range on the target, and reports mismatches.
9116 Useful for verifying the image on the target against the exec file. */
9119 compare_sections_command (char *args
, int from_tty
)
9122 struct cleanup
*old_chain
;
9124 const char *sectname
;
9133 error (_("command cannot be used without an exec file"));
9135 /* Make sure the remote is pointing at the right process. */
9136 set_general_process ();
9138 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9144 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9146 if (!(s
->flags
& SEC_LOAD
))
9147 continue; /* Skip non-loadable section. */
9149 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9150 continue; /* Skip writeable sections */
9152 size
= bfd_get_section_size (s
);
9154 continue; /* Skip zero-length section. */
9156 sectname
= bfd_get_section_name (exec_bfd
, s
);
9157 if (args
&& strcmp (args
, sectname
) != 0)
9158 continue; /* Not the section selected by user. */
9160 matched
= 1; /* Do this section. */
9163 sectdata
= xmalloc (size
);
9164 old_chain
= make_cleanup (xfree
, sectdata
);
9165 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9167 res
= target_verify_memory (sectdata
, lma
, size
);
9170 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9171 paddress (target_gdbarch (), lma
),
9172 paddress (target_gdbarch (), lma
+ size
));
9174 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9175 paddress (target_gdbarch (), lma
),
9176 paddress (target_gdbarch (), lma
+ size
));
9178 printf_filtered ("matched.\n");
9181 printf_filtered ("MIS-MATCHED!\n");
9185 do_cleanups (old_chain
);
9188 warning (_("One or more sections of the target image does not match\n\
9189 the loaded file\n"));
9190 if (args
&& !matched
)
9191 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9194 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9195 into remote target. The number of bytes written to the remote
9196 target is returned, or -1 for error. */
9198 static enum target_xfer_status
9199 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9200 const char *annex
, const gdb_byte
*writebuf
,
9201 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9202 struct packet_config
*packet
)
9206 struct remote_state
*rs
= get_remote_state ();
9207 int max_size
= get_memory_write_packet_size ();
9209 if (packet
->support
== PACKET_DISABLE
)
9210 return TARGET_XFER_E_IO
;
9212 /* Insert header. */
9213 i
= snprintf (rs
->buf
, max_size
,
9214 "qXfer:%s:write:%s:%s:",
9215 object_name
, annex
? annex
: "",
9216 phex_nz (offset
, sizeof offset
));
9217 max_size
-= (i
+ 1);
9219 /* Escape as much data as fits into rs->buf. */
9220 buf_len
= remote_escape_output
9221 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9223 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9224 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9225 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9226 return TARGET_XFER_E_IO
;
9228 unpack_varlen_hex (rs
->buf
, &n
);
9231 return TARGET_XFER_OK
;
9234 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9235 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9236 number of bytes read is returned, or 0 for EOF, or -1 for error.
9237 The number of bytes read may be less than LEN without indicating an
9238 EOF. PACKET is checked and updated to indicate whether the remote
9239 target supports this object. */
9241 static enum target_xfer_status
9242 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9244 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9245 ULONGEST
*xfered_len
,
9246 struct packet_config
*packet
)
9248 struct remote_state
*rs
= get_remote_state ();
9249 LONGEST i
, n
, packet_len
;
9251 if (packet
->support
== PACKET_DISABLE
)
9252 return TARGET_XFER_E_IO
;
9254 /* Check whether we've cached an end-of-object packet that matches
9256 if (rs
->finished_object
)
9258 if (strcmp (object_name
, rs
->finished_object
) == 0
9259 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9260 && offset
== rs
->finished_offset
)
9261 return TARGET_XFER_EOF
;
9264 /* Otherwise, we're now reading something different. Discard
9266 xfree (rs
->finished_object
);
9267 xfree (rs
->finished_annex
);
9268 rs
->finished_object
= NULL
;
9269 rs
->finished_annex
= NULL
;
9272 /* Request only enough to fit in a single packet. The actual data
9273 may not, since we don't know how much of it will need to be escaped;
9274 the target is free to respond with slightly less data. We subtract
9275 five to account for the response type and the protocol frame. */
9276 n
= min (get_remote_packet_size () - 5, len
);
9277 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9278 object_name
, annex
? annex
: "",
9279 phex_nz (offset
, sizeof offset
),
9280 phex_nz (n
, sizeof n
));
9281 i
= putpkt (rs
->buf
);
9283 return TARGET_XFER_E_IO
;
9286 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9287 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9288 return TARGET_XFER_E_IO
;
9290 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9291 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9293 /* 'm' means there is (or at least might be) more data after this
9294 batch. That does not make sense unless there's at least one byte
9295 of data in this reply. */
9296 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9297 error (_("Remote qXfer reply contained no data."));
9299 /* Got some data. */
9300 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9301 packet_len
- 1, readbuf
, n
);
9303 /* 'l' is an EOF marker, possibly including a final block of data,
9304 or possibly empty. If we have the final block of a non-empty
9305 object, record this fact to bypass a subsequent partial read. */
9306 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9308 rs
->finished_object
= xstrdup (object_name
);
9309 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9310 rs
->finished_offset
= offset
+ i
;
9314 return TARGET_XFER_EOF
;
9318 return TARGET_XFER_OK
;
9322 static enum target_xfer_status
9323 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9324 const char *annex
, gdb_byte
*readbuf
,
9325 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9326 ULONGEST
*xfered_len
)
9328 struct remote_state
*rs
;
9332 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9334 set_remote_traceframe ();
9335 set_general_thread (inferior_ptid
);
9337 rs
= get_remote_state ();
9339 /* Handle memory using the standard memory routines. */
9340 if (object
== TARGET_OBJECT_MEMORY
)
9342 /* If the remote target is connected but not running, we should
9343 pass this request down to a lower stratum (e.g. the executable
9345 if (!target_has_execution
)
9346 return TARGET_XFER_EOF
;
9348 if (writebuf
!= NULL
)
9349 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9352 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9356 /* Handle SPU memory using qxfer packets. */
9357 if (object
== TARGET_OBJECT_SPU
)
9360 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9361 xfered_len
, &remote_protocol_packets
9362 [PACKET_qXfer_spu_read
]);
9364 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9365 xfered_len
, &remote_protocol_packets
9366 [PACKET_qXfer_spu_write
]);
9369 /* Handle extra signal info using qxfer packets. */
9370 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9373 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9374 xfered_len
, &remote_protocol_packets
9375 [PACKET_qXfer_siginfo_read
]);
9377 return remote_write_qxfer (ops
, "siginfo", annex
,
9378 writebuf
, offset
, len
, xfered_len
,
9379 &remote_protocol_packets
9380 [PACKET_qXfer_siginfo_write
]);
9383 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9386 return remote_read_qxfer (ops
, "statictrace", annex
,
9387 readbuf
, offset
, len
, xfered_len
,
9388 &remote_protocol_packets
9389 [PACKET_qXfer_statictrace_read
]);
9391 return TARGET_XFER_E_IO
;
9394 /* Only handle flash writes. */
9395 if (writebuf
!= NULL
)
9401 case TARGET_OBJECT_FLASH
:
9402 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9406 return TARGET_XFER_E_IO
;
9410 /* Map pre-existing objects onto letters. DO NOT do this for new
9411 objects!!! Instead specify new query packets. */
9414 case TARGET_OBJECT_AVR
:
9418 case TARGET_OBJECT_AUXV
:
9419 gdb_assert (annex
== NULL
);
9420 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9422 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9424 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9425 return remote_read_qxfer
9426 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9427 &remote_protocol_packets
[PACKET_qXfer_features
]);
9429 case TARGET_OBJECT_LIBRARIES
:
9430 return remote_read_qxfer
9431 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9432 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9434 case TARGET_OBJECT_LIBRARIES_SVR4
:
9435 return remote_read_qxfer
9436 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9437 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9439 case TARGET_OBJECT_MEMORY_MAP
:
9440 gdb_assert (annex
== NULL
);
9441 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9443 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9445 case TARGET_OBJECT_OSDATA
:
9446 /* Should only get here if we're connected. */
9447 gdb_assert (rs
->remote_desc
);
9448 return remote_read_qxfer
9449 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9450 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9452 case TARGET_OBJECT_THREADS
:
9453 gdb_assert (annex
== NULL
);
9454 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9456 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9458 case TARGET_OBJECT_TRACEFRAME_INFO
:
9459 gdb_assert (annex
== NULL
);
9460 return remote_read_qxfer
9461 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9462 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9464 case TARGET_OBJECT_FDPIC
:
9465 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9467 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9469 case TARGET_OBJECT_OPENVMS_UIB
:
9470 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9472 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9474 case TARGET_OBJECT_BTRACE
:
9475 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9477 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9479 case TARGET_OBJECT_BTRACE_CONF
:
9480 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9482 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9484 case TARGET_OBJECT_EXEC_FILE
:
9485 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9487 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9490 return TARGET_XFER_E_IO
;
9493 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9494 large enough let the caller deal with it. */
9495 if (len
< get_remote_packet_size ())
9496 return TARGET_XFER_E_IO
;
9497 len
= get_remote_packet_size ();
9499 /* Except for querying the minimum buffer size, target must be open. */
9500 if (!rs
->remote_desc
)
9501 error (_("remote query is only available after target open"));
9503 gdb_assert (annex
!= NULL
);
9504 gdb_assert (readbuf
!= NULL
);
9510 /* We used one buffer char for the remote protocol q command and
9511 another for the query type. As the remote protocol encapsulation
9512 uses 4 chars plus one extra in case we are debugging
9513 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9516 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9518 /* Bad caller may have sent forbidden characters. */
9519 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9524 gdb_assert (annex
[i
] == '\0');
9526 i
= putpkt (rs
->buf
);
9528 return TARGET_XFER_E_IO
;
9530 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9531 strcpy ((char *) readbuf
, rs
->buf
);
9533 *xfered_len
= strlen ((char *) readbuf
);
9534 return TARGET_XFER_OK
;
9538 remote_search_memory (struct target_ops
* ops
,
9539 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9540 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9541 CORE_ADDR
*found_addrp
)
9543 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9544 struct remote_state
*rs
= get_remote_state ();
9545 int max_size
= get_memory_write_packet_size ();
9546 struct packet_config
*packet
=
9547 &remote_protocol_packets
[PACKET_qSearch_memory
];
9548 /* Number of packet bytes used to encode the pattern;
9549 this could be more than PATTERN_LEN due to escape characters. */
9550 int escaped_pattern_len
;
9551 /* Amount of pattern that was encodable in the packet. */
9552 int used_pattern_len
;
9555 ULONGEST found_addr
;
9557 /* Don't go to the target if we don't have to.
9558 This is done before checking packet->support to avoid the possibility that
9559 a success for this edge case means the facility works in general. */
9560 if (pattern_len
> search_space_len
)
9562 if (pattern_len
== 0)
9564 *found_addrp
= start_addr
;
9568 /* If we already know the packet isn't supported, fall back to the simple
9569 way of searching memory. */
9571 if (packet_config_support (packet
) == PACKET_DISABLE
)
9573 /* Target doesn't provided special support, fall back and use the
9574 standard support (copy memory and do the search here). */
9575 return simple_search_memory (ops
, start_addr
, search_space_len
,
9576 pattern
, pattern_len
, found_addrp
);
9579 /* Make sure the remote is pointing at the right process. */
9580 set_general_process ();
9582 /* Insert header. */
9583 i
= snprintf (rs
->buf
, max_size
,
9584 "qSearch:memory:%s;%s;",
9585 phex_nz (start_addr
, addr_size
),
9586 phex_nz (search_space_len
, sizeof (search_space_len
)));
9587 max_size
-= (i
+ 1);
9589 /* Escape as much data as fits into rs->buf. */
9590 escaped_pattern_len
=
9591 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9592 &used_pattern_len
, max_size
);
9594 /* Bail if the pattern is too large. */
9595 if (used_pattern_len
!= pattern_len
)
9596 error (_("Pattern is too large to transmit to remote target."));
9598 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9599 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9600 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9602 /* The request may not have worked because the command is not
9603 supported. If so, fall back to the simple way. */
9604 if (packet
->support
== PACKET_DISABLE
)
9606 return simple_search_memory (ops
, start_addr
, search_space_len
,
9607 pattern
, pattern_len
, found_addrp
);
9612 if (rs
->buf
[0] == '0')
9614 else if (rs
->buf
[0] == '1')
9617 if (rs
->buf
[1] != ',')
9618 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9619 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9620 *found_addrp
= found_addr
;
9623 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9629 remote_rcmd (struct target_ops
*self
, const char *command
,
9630 struct ui_file
*outbuf
)
9632 struct remote_state
*rs
= get_remote_state ();
9635 if (!rs
->remote_desc
)
9636 error (_("remote rcmd is only available after target open"));
9638 /* Send a NULL command across as an empty command. */
9639 if (command
== NULL
)
9642 /* The query prefix. */
9643 strcpy (rs
->buf
, "qRcmd,");
9644 p
= strchr (rs
->buf
, '\0');
9646 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9647 > get_remote_packet_size ())
9648 error (_("\"monitor\" command ``%s'' is too long."), command
);
9650 /* Encode the actual command. */
9651 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9653 if (putpkt (rs
->buf
) < 0)
9654 error (_("Communication problem with target."));
9656 /* get/display the response */
9661 /* XXX - see also remote_get_noisy_reply(). */
9662 QUIT
; /* Allow user to bail out with ^C. */
9664 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9666 /* Timeout. Continue to (try to) read responses.
9667 This is better than stopping with an error, assuming the stub
9668 is still executing the (long) monitor command.
9669 If needed, the user can interrupt gdb using C-c, obtaining
9670 an effect similar to stop on timeout. */
9675 error (_("Target does not support this command."));
9676 if (buf
[0] == 'O' && buf
[1] != 'K')
9678 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9681 if (strcmp (buf
, "OK") == 0)
9683 if (strlen (buf
) == 3 && buf
[0] == 'E'
9684 && isdigit (buf
[1]) && isdigit (buf
[2]))
9686 error (_("Protocol error with Rcmd"));
9688 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9690 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9692 fputc_unfiltered (c
, outbuf
);
9698 static VEC(mem_region_s
) *
9699 remote_memory_map (struct target_ops
*ops
)
9701 VEC(mem_region_s
) *result
= NULL
;
9702 char *text
= target_read_stralloc (¤t_target
,
9703 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9707 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9709 result
= parse_memory_map (text
);
9710 do_cleanups (back_to
);
9717 packet_command (char *args
, int from_tty
)
9719 struct remote_state
*rs
= get_remote_state ();
9721 if (!rs
->remote_desc
)
9722 error (_("command can only be used with remote target"));
9725 error (_("remote-packet command requires packet text as argument"));
9727 puts_filtered ("sending: ");
9728 print_packet (args
);
9729 puts_filtered ("\n");
9732 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9733 puts_filtered ("received: ");
9734 print_packet (rs
->buf
);
9735 puts_filtered ("\n");
9739 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9741 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9743 static void threadset_test_cmd (char *cmd
, int tty
);
9745 static void threadalive_test (char *cmd
, int tty
);
9747 static void threadlist_test_cmd (char *cmd
, int tty
);
9749 int get_and_display_threadinfo (threadref
*ref
);
9751 static void threadinfo_test_cmd (char *cmd
, int tty
);
9753 static int thread_display_step (threadref
*ref
, void *context
);
9755 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9757 static void init_remote_threadtests (void);
9759 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9762 threadset_test_cmd (char *cmd
, int tty
)
9764 int sample_thread
= SAMPLE_THREAD
;
9766 printf_filtered (_("Remote threadset test\n"));
9767 set_general_thread (sample_thread
);
9772 threadalive_test (char *cmd
, int tty
)
9774 int sample_thread
= SAMPLE_THREAD
;
9775 int pid
= ptid_get_pid (inferior_ptid
);
9776 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9778 if (remote_thread_alive (ptid
))
9779 printf_filtered ("PASS: Thread alive test\n");
9781 printf_filtered ("FAIL: Thread alive test\n");
9784 void output_threadid (char *title
, threadref
*ref
);
9787 output_threadid (char *title
, threadref
*ref
)
9791 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9793 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9797 threadlist_test_cmd (char *cmd
, int tty
)
9800 threadref nextthread
;
9801 int done
, result_count
;
9802 threadref threadlist
[3];
9804 printf_filtered ("Remote Threadlist test\n");
9805 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9806 &result_count
, &threadlist
[0]))
9807 printf_filtered ("FAIL: threadlist test\n");
9810 threadref
*scan
= threadlist
;
9811 threadref
*limit
= scan
+ result_count
;
9813 while (scan
< limit
)
9814 output_threadid (" thread ", scan
++);
9819 display_thread_info (struct gdb_ext_thread_info
*info
)
9821 output_threadid ("Threadid: ", &info
->threadid
);
9822 printf_filtered ("Name: %s\n ", info
->shortname
);
9823 printf_filtered ("State: %s\n", info
->display
);
9824 printf_filtered ("other: %s\n\n", info
->more_display
);
9828 get_and_display_threadinfo (threadref
*ref
)
9832 struct gdb_ext_thread_info threadinfo
;
9834 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9835 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9836 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9837 display_thread_info (&threadinfo
);
9842 threadinfo_test_cmd (char *cmd
, int tty
)
9844 int athread
= SAMPLE_THREAD
;
9848 int_to_threadref (&thread
, athread
);
9849 printf_filtered ("Remote Threadinfo test\n");
9850 if (!get_and_display_threadinfo (&thread
))
9851 printf_filtered ("FAIL cannot get thread info\n");
9855 thread_display_step (threadref
*ref
, void *context
)
9857 /* output_threadid(" threadstep ",ref); *//* simple test */
9858 return get_and_display_threadinfo (ref
);
9862 threadlist_update_test_cmd (char *cmd
, int tty
)
9864 printf_filtered ("Remote Threadlist update test\n");
9865 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9869 init_remote_threadtests (void)
9871 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9872 _("Fetch and print the remote list of "
9873 "thread identifiers, one pkt only"));
9874 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9875 _("Fetch and display info about one thread"));
9876 add_com ("tset", class_obscure
, threadset_test_cmd
,
9877 _("Test setting to a different thread"));
9878 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9879 _("Iterate through updating all remote thread info"));
9880 add_com ("talive", class_obscure
, threadalive_test
,
9881 _(" Remote thread alive test "));
9886 /* Convert a thread ID to a string. Returns the string in a static
9890 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9892 static char buf
[64];
9893 struct remote_state
*rs
= get_remote_state ();
9895 if (ptid_equal (ptid
, null_ptid
))
9896 return normal_pid_to_str (ptid
);
9897 else if (ptid_is_pid (ptid
))
9899 /* Printing an inferior target id. */
9901 /* When multi-process extensions are off, there's no way in the
9902 remote protocol to know the remote process id, if there's any
9903 at all. There's one exception --- when we're connected with
9904 target extended-remote, and we manually attached to a process
9905 with "attach PID". We don't record anywhere a flag that
9906 allows us to distinguish that case from the case of
9907 connecting with extended-remote and the stub already being
9908 attached to a process, and reporting yes to qAttached, hence
9909 no smart special casing here. */
9910 if (!remote_multi_process_p (rs
))
9912 xsnprintf (buf
, sizeof buf
, "Remote target");
9916 return normal_pid_to_str (ptid
);
9920 if (ptid_equal (magic_null_ptid
, ptid
))
9921 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9922 else if (rs
->extended
&& remote_multi_process_p (rs
))
9923 if (ptid_get_lwp (ptid
) == 0)
9924 return normal_pid_to_str (ptid
);
9926 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9927 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9929 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9930 ptid_get_lwp (ptid
));
9935 /* Get the address of the thread local variable in OBJFILE which is
9936 stored at OFFSET within the thread local storage for thread PTID. */
9939 remote_get_thread_local_address (struct target_ops
*ops
,
9940 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9942 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9944 struct remote_state
*rs
= get_remote_state ();
9946 char *endp
= rs
->buf
+ get_remote_packet_size ();
9947 enum packet_result result
;
9949 strcpy (p
, "qGetTLSAddr:");
9951 p
= write_ptid (p
, endp
, ptid
);
9953 p
+= hexnumstr (p
, offset
);
9955 p
+= hexnumstr (p
, lm
);
9959 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9960 result
= packet_ok (rs
->buf
,
9961 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9962 if (result
== PACKET_OK
)
9966 unpack_varlen_hex (rs
->buf
, &result
);
9969 else if (result
== PACKET_UNKNOWN
)
9970 throw_error (TLS_GENERIC_ERROR
,
9971 _("Remote target doesn't support qGetTLSAddr packet"));
9973 throw_error (TLS_GENERIC_ERROR
,
9974 _("Remote target failed to process qGetTLSAddr request"));
9977 throw_error (TLS_GENERIC_ERROR
,
9978 _("TLS not supported or disabled on this target"));
9983 /* Provide thread local base, i.e. Thread Information Block address.
9984 Returns 1 if ptid is found and thread_local_base is non zero. */
9987 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9989 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9991 struct remote_state
*rs
= get_remote_state ();
9993 char *endp
= rs
->buf
+ get_remote_packet_size ();
9994 enum packet_result result
;
9996 strcpy (p
, "qGetTIBAddr:");
9998 p
= write_ptid (p
, endp
, ptid
);
10002 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10003 result
= packet_ok (rs
->buf
,
10004 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10005 if (result
== PACKET_OK
)
10009 unpack_varlen_hex (rs
->buf
, &result
);
10011 *addr
= (CORE_ADDR
) result
;
10014 else if (result
== PACKET_UNKNOWN
)
10015 error (_("Remote target doesn't support qGetTIBAddr packet"));
10017 error (_("Remote target failed to process qGetTIBAddr request"));
10020 error (_("qGetTIBAddr not supported or disabled on this target"));
10025 /* Support for inferring a target description based on the current
10026 architecture and the size of a 'g' packet. While the 'g' packet
10027 can have any size (since optional registers can be left off the
10028 end), some sizes are easily recognizable given knowledge of the
10029 approximate architecture. */
10031 struct remote_g_packet_guess
10034 const struct target_desc
*tdesc
;
10036 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10037 DEF_VEC_O(remote_g_packet_guess_s
);
10039 struct remote_g_packet_data
10041 VEC(remote_g_packet_guess_s
) *guesses
;
10044 static struct gdbarch_data
*remote_g_packet_data_handle
;
10047 remote_g_packet_data_init (struct obstack
*obstack
)
10049 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10053 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10054 const struct target_desc
*tdesc
)
10056 struct remote_g_packet_data
*data
10057 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
10058 struct remote_g_packet_guess new_guess
, *guess
;
10061 gdb_assert (tdesc
!= NULL
);
10064 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10066 if (guess
->bytes
== bytes
)
10067 internal_error (__FILE__
, __LINE__
,
10068 _("Duplicate g packet description added for size %d"),
10071 new_guess
.bytes
= bytes
;
10072 new_guess
.tdesc
= tdesc
;
10073 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10076 /* Return 1 if remote_read_description would do anything on this target
10077 and architecture, 0 otherwise. */
10080 remote_read_description_p (struct target_ops
*target
)
10082 struct remote_g_packet_data
*data
10083 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10085 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10091 static const struct target_desc
*
10092 remote_read_description (struct target_ops
*target
)
10094 struct remote_g_packet_data
*data
10095 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10097 /* Do not try this during initial connection, when we do not know
10098 whether there is a running but stopped thread. */
10099 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10100 return target
->beneath
->to_read_description (target
->beneath
);
10102 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10104 struct remote_g_packet_guess
*guess
;
10106 int bytes
= send_g_packet ();
10109 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10111 if (guess
->bytes
== bytes
)
10112 return guess
->tdesc
;
10114 /* We discard the g packet. A minor optimization would be to
10115 hold on to it, and fill the register cache once we have selected
10116 an architecture, but it's too tricky to do safely. */
10119 return target
->beneath
->to_read_description (target
->beneath
);
10122 /* Remote file transfer support. This is host-initiated I/O, not
10123 target-initiated; for target-initiated, see remote-fileio.c. */
10125 /* If *LEFT is at least the length of STRING, copy STRING to
10126 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10127 decrease *LEFT. Otherwise raise an error. */
10130 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10132 int len
= strlen (string
);
10135 error (_("Packet too long for target."));
10137 memcpy (*buffer
, string
, len
);
10141 /* NUL-terminate the buffer as a convenience, if there is
10147 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10148 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10149 decrease *LEFT. Otherwise raise an error. */
10152 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10155 if (2 * len
> *left
)
10156 error (_("Packet too long for target."));
10158 bin2hex (bytes
, *buffer
, len
);
10159 *buffer
+= 2 * len
;
10162 /* NUL-terminate the buffer as a convenience, if there is
10168 /* If *LEFT is large enough, convert VALUE to hex and add it to
10169 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10170 decrease *LEFT. Otherwise raise an error. */
10173 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10175 int len
= hexnumlen (value
);
10178 error (_("Packet too long for target."));
10180 hexnumstr (*buffer
, value
);
10184 /* NUL-terminate the buffer as a convenience, if there is
10190 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10191 value, *REMOTE_ERRNO to the remote error number or zero if none
10192 was included, and *ATTACHMENT to point to the start of the annex
10193 if any. The length of the packet isn't needed here; there may
10194 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10196 Return 0 if the packet could be parsed, -1 if it could not. If
10197 -1 is returned, the other variables may not be initialized. */
10200 remote_hostio_parse_result (char *buffer
, int *retcode
,
10201 int *remote_errno
, char **attachment
)
10206 *attachment
= NULL
;
10208 if (buffer
[0] != 'F')
10212 *retcode
= strtol (&buffer
[1], &p
, 16);
10213 if (errno
!= 0 || p
== &buffer
[1])
10216 /* Check for ",errno". */
10220 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10221 if (errno
!= 0 || p
+ 1 == p2
)
10226 /* Check for ";attachment". If there is no attachment, the
10227 packet should end here. */
10230 *attachment
= p
+ 1;
10233 else if (*p
== '\0')
10239 /* Send a prepared I/O packet to the target and read its response.
10240 The prepared packet is in the global RS->BUF before this function
10241 is called, and the answer is there when we return.
10243 COMMAND_BYTES is the length of the request to send, which may include
10244 binary data. WHICH_PACKET is the packet configuration to check
10245 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10246 is set to the error number and -1 is returned. Otherwise the value
10247 returned by the function is returned.
10249 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10250 attachment is expected; an error will be reported if there's a
10251 mismatch. If one is found, *ATTACHMENT will be set to point into
10252 the packet buffer and *ATTACHMENT_LEN will be set to the
10253 attachment's length. */
10256 remote_hostio_send_command (int command_bytes
, int which_packet
,
10257 int *remote_errno
, char **attachment
,
10258 int *attachment_len
)
10260 struct remote_state
*rs
= get_remote_state ();
10261 int ret
, bytes_read
;
10262 char *attachment_tmp
;
10264 if (!rs
->remote_desc
10265 || packet_support (which_packet
) == PACKET_DISABLE
)
10267 *remote_errno
= FILEIO_ENOSYS
;
10271 putpkt_binary (rs
->buf
, command_bytes
);
10272 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10274 /* If it timed out, something is wrong. Don't try to parse the
10276 if (bytes_read
< 0)
10278 *remote_errno
= FILEIO_EINVAL
;
10282 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10285 *remote_errno
= FILEIO_EINVAL
;
10287 case PACKET_UNKNOWN
:
10288 *remote_errno
= FILEIO_ENOSYS
;
10294 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10297 *remote_errno
= FILEIO_EINVAL
;
10301 /* Make sure we saw an attachment if and only if we expected one. */
10302 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10303 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10305 *remote_errno
= FILEIO_EINVAL
;
10309 /* If an attachment was found, it must point into the packet buffer;
10310 work out how many bytes there were. */
10311 if (attachment_tmp
!= NULL
)
10313 *attachment
= attachment_tmp
;
10314 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10320 /* Set the filesystem remote_hostio functions that take FILENAME
10321 arguments will use. Return 0 on success, or -1 if an error
10322 occurs (and set *REMOTE_ERRNO). */
10325 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10327 struct remote_state
*rs
= get_remote_state ();
10328 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10330 int left
= get_remote_packet_size () - 1;
10334 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10337 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10340 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10342 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10343 remote_buffer_add_string (&p
, &left
, arg
);
10345 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10346 remote_errno
, NULL
, NULL
);
10348 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10352 rs
->fs_pid
= required_pid
;
10357 /* Implementation of to_fileio_open. */
10360 remote_hostio_open (struct target_ops
*self
,
10361 struct inferior
*inf
, const char *filename
,
10362 int flags
, int mode
, int *remote_errno
)
10364 struct remote_state
*rs
= get_remote_state ();
10366 int left
= get_remote_packet_size () - 1;
10368 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10371 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10373 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10374 strlen (filename
));
10375 remote_buffer_add_string (&p
, &left
, ",");
10377 remote_buffer_add_int (&p
, &left
, flags
);
10378 remote_buffer_add_string (&p
, &left
, ",");
10380 remote_buffer_add_int (&p
, &left
, mode
);
10382 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10383 remote_errno
, NULL
, NULL
);
10386 /* Implementation of to_fileio_pwrite. */
10389 remote_hostio_pwrite (struct target_ops
*self
,
10390 int fd
, const gdb_byte
*write_buf
, int len
,
10391 ULONGEST offset
, int *remote_errno
)
10393 struct remote_state
*rs
= get_remote_state ();
10395 int left
= get_remote_packet_size ();
10398 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10400 remote_buffer_add_int (&p
, &left
, fd
);
10401 remote_buffer_add_string (&p
, &left
, ",");
10403 remote_buffer_add_int (&p
, &left
, offset
);
10404 remote_buffer_add_string (&p
, &left
, ",");
10406 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10407 get_remote_packet_size () - (p
- rs
->buf
));
10409 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10410 remote_errno
, NULL
, NULL
);
10413 /* Implementation of to_fileio_pread. */
10416 remote_hostio_pread (struct target_ops
*self
,
10417 int fd
, gdb_byte
*read_buf
, int len
,
10418 ULONGEST offset
, int *remote_errno
)
10420 struct remote_state
*rs
= get_remote_state ();
10423 int left
= get_remote_packet_size ();
10424 int ret
, attachment_len
;
10427 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10429 remote_buffer_add_int (&p
, &left
, fd
);
10430 remote_buffer_add_string (&p
, &left
, ",");
10432 remote_buffer_add_int (&p
, &left
, len
);
10433 remote_buffer_add_string (&p
, &left
, ",");
10435 remote_buffer_add_int (&p
, &left
, offset
);
10437 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10438 remote_errno
, &attachment
,
10444 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10446 if (read_len
!= ret
)
10447 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10452 /* Implementation of to_fileio_close. */
10455 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10457 struct remote_state
*rs
= get_remote_state ();
10459 int left
= get_remote_packet_size () - 1;
10461 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10463 remote_buffer_add_int (&p
, &left
, fd
);
10465 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10466 remote_errno
, NULL
, NULL
);
10469 /* Implementation of to_fileio_unlink. */
10472 remote_hostio_unlink (struct target_ops
*self
,
10473 struct inferior
*inf
, const char *filename
,
10476 struct remote_state
*rs
= get_remote_state ();
10478 int left
= get_remote_packet_size () - 1;
10480 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10483 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10485 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10486 strlen (filename
));
10488 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10489 remote_errno
, NULL
, NULL
);
10492 /* Implementation of to_fileio_readlink. */
10495 remote_hostio_readlink (struct target_ops
*self
,
10496 struct inferior
*inf
, const char *filename
,
10499 struct remote_state
*rs
= get_remote_state ();
10502 int left
= get_remote_packet_size ();
10503 int len
, attachment_len
;
10507 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10510 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10512 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10513 strlen (filename
));
10515 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10516 remote_errno
, &attachment
,
10522 ret
= xmalloc (len
+ 1);
10524 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10525 (gdb_byte
*) ret
, len
);
10526 if (read_len
!= len
)
10527 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10533 /* Implementation of to_fileio_fstat. */
10536 remote_hostio_fstat (struct target_ops
*self
,
10537 int fd
, struct stat
*st
,
10540 struct remote_state
*rs
= get_remote_state ();
10542 int left
= get_remote_packet_size ();
10543 int attachment_len
, ret
;
10545 struct fio_stat fst
;
10548 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10550 remote_buffer_add_int (&p
, &left
, fd
);
10552 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10553 remote_errno
, &attachment
,
10557 if (*remote_errno
!= FILEIO_ENOSYS
)
10560 /* Strictly we should return -1, ENOSYS here, but when
10561 "set sysroot remote:" was implemented in August 2008
10562 BFD's need for a stat function was sidestepped with
10563 this hack. This was not remedied until March 2015
10564 so we retain the previous behavior to avoid breaking
10567 Note that the memset is a March 2015 addition; older
10568 GDBs set st_size *and nothing else* so the structure
10569 would have garbage in all other fields. This might
10570 break something but retaining the previous behavior
10571 here would be just too wrong. */
10573 memset (st
, 0, sizeof (struct stat
));
10574 st
->st_size
= INT_MAX
;
10578 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10579 (gdb_byte
*) &fst
, sizeof (fst
));
10581 if (read_len
!= ret
)
10582 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10584 if (read_len
!= sizeof (fst
))
10585 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10586 read_len
, (int) sizeof (fst
));
10588 remote_fileio_to_host_stat (&fst
, st
);
10593 /* Implementation of to_filesystem_is_local. */
10596 remote_filesystem_is_local (struct target_ops
*self
)
10598 /* Valgrind GDB presents itself as a remote target but works
10599 on the local filesystem: it does not implement remote get
10600 and users are not expected to set a sysroot. To handle
10601 this case we treat the remote filesystem as local if the
10602 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
10603 does not support vFile:open. */
10604 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
10606 enum packet_support ps
= packet_support (PACKET_vFile_open
);
10608 if (ps
== PACKET_SUPPORT_UNKNOWN
)
10610 int fd
, remote_errno
;
10612 /* Try opening a file to probe support. The supplied
10613 filename is irrelevant, we only care about whether
10614 the stub recognizes the packet or not. */
10615 fd
= remote_hostio_open (self
, NULL
, "just probing",
10616 FILEIO_O_RDONLY
, 0700,
10620 remote_hostio_close (self
, fd
, &remote_errno
);
10622 ps
= packet_support (PACKET_vFile_open
);
10625 if (ps
== PACKET_DISABLE
)
10627 static int warning_issued
= 0;
10629 if (!warning_issued
)
10631 warning (_("remote target does not support file"
10632 " transfer, attempting to access files"
10633 " from local filesystem."));
10634 warning_issued
= 1;
10645 remote_fileio_errno_to_host (int errnum
)
10651 case FILEIO_ENOENT
:
10659 case FILEIO_EACCES
:
10661 case FILEIO_EFAULT
:
10665 case FILEIO_EEXIST
:
10667 case FILEIO_ENODEV
:
10669 case FILEIO_ENOTDIR
:
10671 case FILEIO_EISDIR
:
10673 case FILEIO_EINVAL
:
10675 case FILEIO_ENFILE
:
10677 case FILEIO_EMFILE
:
10681 case FILEIO_ENOSPC
:
10683 case FILEIO_ESPIPE
:
10687 case FILEIO_ENOSYS
:
10689 case FILEIO_ENAMETOOLONG
:
10690 return ENAMETOOLONG
;
10696 remote_hostio_error (int errnum
)
10698 int host_error
= remote_fileio_errno_to_host (errnum
);
10700 if (host_error
== -1)
10701 error (_("Unknown remote I/O error %d"), errnum
);
10703 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10707 remote_hostio_close_cleanup (void *opaque
)
10709 int fd
= *(int *) opaque
;
10712 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10716 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10718 struct cleanup
*back_to
, *close_cleanup
;
10719 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10722 int bytes_in_buffer
;
10725 struct remote_state
*rs
= get_remote_state ();
10727 if (!rs
->remote_desc
)
10728 error (_("command can only be used with remote target"));
10730 file
= gdb_fopen_cloexec (local_file
, "rb");
10732 perror_with_name (local_file
);
10733 back_to
= make_cleanup_fclose (file
);
10735 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10736 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10738 0700, &remote_errno
);
10740 remote_hostio_error (remote_errno
);
10742 /* Send up to this many bytes at once. They won't all fit in the
10743 remote packet limit, so we'll transfer slightly fewer. */
10744 io_size
= get_remote_packet_size ();
10745 buffer
= xmalloc (io_size
);
10746 make_cleanup (xfree
, buffer
);
10748 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10750 bytes_in_buffer
= 0;
10753 while (bytes_in_buffer
|| !saw_eof
)
10757 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10758 io_size
- bytes_in_buffer
,
10763 error (_("Error reading %s."), local_file
);
10766 /* EOF. Unless there is something still in the
10767 buffer from the last iteration, we are done. */
10769 if (bytes_in_buffer
== 0)
10777 bytes
+= bytes_in_buffer
;
10778 bytes_in_buffer
= 0;
10780 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10782 offset
, &remote_errno
);
10785 remote_hostio_error (remote_errno
);
10786 else if (retcode
== 0)
10787 error (_("Remote write of %d bytes returned 0!"), bytes
);
10788 else if (retcode
< bytes
)
10790 /* Short write. Save the rest of the read data for the next
10792 bytes_in_buffer
= bytes
- retcode
;
10793 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10799 discard_cleanups (close_cleanup
);
10800 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10801 remote_hostio_error (remote_errno
);
10804 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10805 do_cleanups (back_to
);
10809 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10811 struct cleanup
*back_to
, *close_cleanup
;
10812 int fd
, remote_errno
, bytes
, io_size
;
10816 struct remote_state
*rs
= get_remote_state ();
10818 if (!rs
->remote_desc
)
10819 error (_("command can only be used with remote target"));
10821 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10822 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10824 remote_hostio_error (remote_errno
);
10826 file
= gdb_fopen_cloexec (local_file
, "wb");
10828 perror_with_name (local_file
);
10829 back_to
= make_cleanup_fclose (file
);
10831 /* Send up to this many bytes at once. They won't all fit in the
10832 remote packet limit, so we'll transfer slightly fewer. */
10833 io_size
= get_remote_packet_size ();
10834 buffer
= xmalloc (io_size
);
10835 make_cleanup (xfree
, buffer
);
10837 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10842 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10843 fd
, buffer
, io_size
, offset
, &remote_errno
);
10845 /* Success, but no bytes, means end-of-file. */
10848 remote_hostio_error (remote_errno
);
10852 bytes
= fwrite (buffer
, 1, bytes
, file
);
10854 perror_with_name (local_file
);
10857 discard_cleanups (close_cleanup
);
10858 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10859 remote_hostio_error (remote_errno
);
10862 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10863 do_cleanups (back_to
);
10867 remote_file_delete (const char *remote_file
, int from_tty
)
10869 int retcode
, remote_errno
;
10870 struct remote_state
*rs
= get_remote_state ();
10872 if (!rs
->remote_desc
)
10873 error (_("command can only be used with remote target"));
10875 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10876 NULL
, remote_file
, &remote_errno
);
10878 remote_hostio_error (remote_errno
);
10881 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10885 remote_put_command (char *args
, int from_tty
)
10887 struct cleanup
*back_to
;
10891 error_no_arg (_("file to put"));
10893 argv
= gdb_buildargv (args
);
10894 back_to
= make_cleanup_freeargv (argv
);
10895 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10896 error (_("Invalid parameters to remote put"));
10898 remote_file_put (argv
[0], argv
[1], from_tty
);
10900 do_cleanups (back_to
);
10904 remote_get_command (char *args
, int from_tty
)
10906 struct cleanup
*back_to
;
10910 error_no_arg (_("file to get"));
10912 argv
= gdb_buildargv (args
);
10913 back_to
= make_cleanup_freeargv (argv
);
10914 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10915 error (_("Invalid parameters to remote get"));
10917 remote_file_get (argv
[0], argv
[1], from_tty
);
10919 do_cleanups (back_to
);
10923 remote_delete_command (char *args
, int from_tty
)
10925 struct cleanup
*back_to
;
10929 error_no_arg (_("file to delete"));
10931 argv
= gdb_buildargv (args
);
10932 back_to
= make_cleanup_freeargv (argv
);
10933 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10934 error (_("Invalid parameters to remote delete"));
10936 remote_file_delete (argv
[0], from_tty
);
10938 do_cleanups (back_to
);
10942 remote_command (char *args
, int from_tty
)
10944 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10948 remote_can_execute_reverse (struct target_ops
*self
)
10950 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10951 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10958 remote_supports_non_stop (struct target_ops
*self
)
10964 remote_supports_disable_randomization (struct target_ops
*self
)
10966 /* Only supported in extended mode. */
10971 remote_supports_multi_process (struct target_ops
*self
)
10973 struct remote_state
*rs
= get_remote_state ();
10975 /* Only extended-remote handles being attached to multiple
10976 processes, even though plain remote can use the multi-process
10977 thread id extensions, so that GDB knows the target process's
10979 return rs
->extended
&& remote_multi_process_p (rs
);
10983 remote_supports_cond_tracepoints (void)
10985 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10989 remote_supports_cond_breakpoints (struct target_ops
*self
)
10991 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10995 remote_supports_fast_tracepoints (void)
10997 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11001 remote_supports_static_tracepoints (void)
11003 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11007 remote_supports_install_in_trace (void)
11009 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11013 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11015 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11020 remote_supports_string_tracing (struct target_ops
*self
)
11022 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11026 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11028 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11032 remote_trace_init (struct target_ops
*self
)
11035 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11036 if (strcmp (target_buf
, "OK") != 0)
11037 error (_("Target does not support this command."));
11040 static void free_actions_list (char **actions_list
);
11041 static void free_actions_list_cleanup_wrapper (void *);
11043 free_actions_list_cleanup_wrapper (void *al
)
11045 free_actions_list (al
);
11049 free_actions_list (char **actions_list
)
11053 if (actions_list
== 0)
11056 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11057 xfree (actions_list
[ndx
]);
11059 xfree (actions_list
);
11062 /* Recursive routine to walk through command list including loops, and
11063 download packets for each command. */
11066 remote_download_command_source (int num
, ULONGEST addr
,
11067 struct command_line
*cmds
)
11069 struct remote_state
*rs
= get_remote_state ();
11070 struct command_line
*cmd
;
11072 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11074 QUIT
; /* Allow user to bail out with ^C. */
11075 strcpy (rs
->buf
, "QTDPsrc:");
11076 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11077 rs
->buf
+ strlen (rs
->buf
),
11078 rs
->buf_size
- strlen (rs
->buf
));
11080 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11081 if (strcmp (target_buf
, "OK"))
11082 warning (_("Target does not support source download."));
11084 if (cmd
->control_type
== while_control
11085 || cmd
->control_type
== while_stepping_control
)
11087 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11089 QUIT
; /* Allow user to bail out with ^C. */
11090 strcpy (rs
->buf
, "QTDPsrc:");
11091 encode_source_string (num
, addr
, "cmd", "end",
11092 rs
->buf
+ strlen (rs
->buf
),
11093 rs
->buf_size
- strlen (rs
->buf
));
11095 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11096 if (strcmp (target_buf
, "OK"))
11097 warning (_("Target does not support source download."));
11103 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11105 #define BUF_SIZE 2048
11109 char buf
[BUF_SIZE
];
11110 char **tdp_actions
;
11111 char **stepping_actions
;
11113 struct cleanup
*old_chain
= NULL
;
11114 struct agent_expr
*aexpr
;
11115 struct cleanup
*aexpr_chain
= NULL
;
11117 struct breakpoint
*b
= loc
->owner
;
11118 struct tracepoint
*t
= (struct tracepoint
*) b
;
11120 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11121 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11123 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11126 tpaddr
= loc
->address
;
11127 sprintf_vma (addrbuf
, tpaddr
);
11128 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11129 addrbuf
, /* address */
11130 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11131 t
->step_count
, t
->pass_count
);
11132 /* Fast tracepoints are mostly handled by the target, but we can
11133 tell the target how big of an instruction block should be moved
11135 if (b
->type
== bp_fast_tracepoint
)
11137 /* Only test for support at download time; we may not know
11138 target capabilities at definition time. */
11139 if (remote_supports_fast_tracepoints ())
11141 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11143 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11144 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11146 /* If it passed validation at definition but fails now,
11147 something is very wrong. */
11148 internal_error (__FILE__
, __LINE__
,
11149 _("Fast tracepoint not "
11150 "valid during download"));
11153 /* Fast tracepoints are functionally identical to regular
11154 tracepoints, so don't take lack of support as a reason to
11155 give up on the trace run. */
11156 warning (_("Target does not support fast tracepoints, "
11157 "downloading %d as regular tracepoint"), b
->number
);
11159 else if (b
->type
== bp_static_tracepoint
)
11161 /* Only test for support at download time; we may not know
11162 target capabilities at definition time. */
11163 if (remote_supports_static_tracepoints ())
11165 struct static_tracepoint_marker marker
;
11167 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11168 strcat (buf
, ":S");
11170 error (_("Static tracepoint not valid during download"));
11173 /* Fast tracepoints are functionally identical to regular
11174 tracepoints, so don't take lack of support as a reason
11175 to give up on the trace run. */
11176 error (_("Target does not support static tracepoints"));
11178 /* If the tracepoint has a conditional, make it into an agent
11179 expression and append to the definition. */
11182 /* Only test support at download time, we may not know target
11183 capabilities at definition time. */
11184 if (remote_supports_cond_tracepoints ())
11186 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11187 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11188 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11190 pkt
= buf
+ strlen (buf
);
11191 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11192 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11194 do_cleanups (aexpr_chain
);
11197 warning (_("Target does not support conditional tracepoints, "
11198 "ignoring tp %d cond"), b
->number
);
11201 if (b
->commands
|| *default_collect
)
11204 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11205 if (strcmp (target_buf
, "OK"))
11206 error (_("Target does not support tracepoints."));
11208 /* do_single_steps (t); */
11211 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11213 QUIT
; /* Allow user to bail out with ^C. */
11214 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11215 b
->number
, addrbuf
, /* address */
11217 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11220 remote_get_noisy_reply (&target_buf
,
11222 if (strcmp (target_buf
, "OK"))
11223 error (_("Error on target while setting tracepoints."));
11226 if (stepping_actions
)
11228 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11230 QUIT
; /* Allow user to bail out with ^C. */
11231 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11232 b
->number
, addrbuf
, /* address */
11233 ((ndx
== 0) ? "S" : ""),
11234 stepping_actions
[ndx
],
11235 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11237 remote_get_noisy_reply (&target_buf
,
11239 if (strcmp (target_buf
, "OK"))
11240 error (_("Error on target while setting tracepoints."));
11244 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11246 if (b
->location
!= NULL
)
11248 strcpy (buf
, "QTDPsrc:");
11249 encode_source_string (b
->number
, loc
->address
, "at",
11250 event_location_to_string (b
->location
),
11251 buf
+ strlen (buf
), 2048 - strlen (buf
));
11253 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11254 if (strcmp (target_buf
, "OK"))
11255 warning (_("Target does not support source download."));
11257 if (b
->cond_string
)
11259 strcpy (buf
, "QTDPsrc:");
11260 encode_source_string (b
->number
, loc
->address
,
11261 "cond", b
->cond_string
, buf
+ strlen (buf
),
11262 2048 - strlen (buf
));
11264 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11265 if (strcmp (target_buf
, "OK"))
11266 warning (_("Target does not support source download."));
11268 remote_download_command_source (b
->number
, loc
->address
,
11269 breakpoint_commands (b
));
11272 do_cleanups (old_chain
);
11276 remote_can_download_tracepoint (struct target_ops
*self
)
11278 struct remote_state
*rs
= get_remote_state ();
11279 struct trace_status
*ts
;
11282 /* Don't try to install tracepoints until we've relocated our
11283 symbols, and fetched and merged the target's tracepoint list with
11285 if (rs
->starting_up
)
11288 ts
= current_trace_status ();
11289 status
= remote_get_trace_status (self
, ts
);
11291 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11294 /* If we are in a tracing experiment, but remote stub doesn't support
11295 installing tracepoint in trace, we have to return. */
11296 if (!remote_supports_install_in_trace ())
11304 remote_download_trace_state_variable (struct target_ops
*self
,
11305 struct trace_state_variable
*tsv
)
11307 struct remote_state
*rs
= get_remote_state ();
11310 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11311 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11313 p
= rs
->buf
+ strlen (rs
->buf
);
11314 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11315 error (_("Trace state variable name too long for tsv definition packet"));
11316 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11319 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11320 if (*target_buf
== '\0')
11321 error (_("Target does not support this command."));
11322 if (strcmp (target_buf
, "OK") != 0)
11323 error (_("Error on target while downloading trace state variable."));
11327 remote_enable_tracepoint (struct target_ops
*self
,
11328 struct bp_location
*location
)
11330 struct remote_state
*rs
= get_remote_state ();
11333 sprintf_vma (addr_buf
, location
->address
);
11334 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11335 location
->owner
->number
, addr_buf
);
11337 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11338 if (*rs
->buf
== '\0')
11339 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11340 if (strcmp (rs
->buf
, "OK") != 0)
11341 error (_("Error on target while enabling tracepoint."));
11345 remote_disable_tracepoint (struct target_ops
*self
,
11346 struct bp_location
*location
)
11348 struct remote_state
*rs
= get_remote_state ();
11351 sprintf_vma (addr_buf
, location
->address
);
11352 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11353 location
->owner
->number
, addr_buf
);
11355 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11356 if (*rs
->buf
== '\0')
11357 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11358 if (strcmp (rs
->buf
, "OK") != 0)
11359 error (_("Error on target while disabling tracepoint."));
11363 remote_trace_set_readonly_regions (struct target_ops
*self
)
11367 bfd_size_type size
;
11373 return; /* No information to give. */
11375 strcpy (target_buf
, "QTro");
11376 offset
= strlen (target_buf
);
11377 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11379 char tmp1
[40], tmp2
[40];
11382 if ((s
->flags
& SEC_LOAD
) == 0 ||
11383 /* (s->flags & SEC_CODE) == 0 || */
11384 (s
->flags
& SEC_READONLY
) == 0)
11388 vma
= bfd_get_section_vma (abfd
, s
);
11389 size
= bfd_get_section_size (s
);
11390 sprintf_vma (tmp1
, vma
);
11391 sprintf_vma (tmp2
, vma
+ size
);
11392 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11393 if (offset
+ sec_length
+ 1 > target_buf_size
)
11395 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11397 Too many sections for read-only sections definition packet."));
11400 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11402 offset
+= sec_length
;
11406 putpkt (target_buf
);
11407 getpkt (&target_buf
, &target_buf_size
, 0);
11412 remote_trace_start (struct target_ops
*self
)
11414 putpkt ("QTStart");
11415 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11416 if (*target_buf
== '\0')
11417 error (_("Target does not support this command."));
11418 if (strcmp (target_buf
, "OK") != 0)
11419 error (_("Bogus reply from target: %s"), target_buf
);
11423 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11425 /* Initialize it just to avoid a GCC false warning. */
11427 /* FIXME we need to get register block size some other way. */
11428 extern int trace_regblock_size
;
11429 enum packet_result result
;
11431 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11434 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11436 putpkt ("qTStatus");
11440 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11442 CATCH (ex
, RETURN_MASK_ERROR
)
11444 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11446 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11449 throw_exception (ex
);
11453 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11455 /* If the remote target doesn't do tracing, flag it. */
11456 if (result
== PACKET_UNKNOWN
)
11459 /* We're working with a live target. */
11460 ts
->filename
= NULL
;
11463 error (_("Bogus trace status reply from target: %s"), target_buf
);
11465 /* Function 'parse_trace_status' sets default value of each field of
11466 'ts' at first, so we don't have to do it here. */
11467 parse_trace_status (p
, ts
);
11469 return ts
->running
;
11473 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11474 struct uploaded_tp
*utp
)
11476 struct remote_state
*rs
= get_remote_state ();
11478 struct bp_location
*loc
;
11479 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11480 size_t size
= get_remote_packet_size ();
11484 tp
->base
.hit_count
= 0;
11485 tp
->traceframe_usage
= 0;
11486 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11488 /* If the tracepoint was never downloaded, don't go asking for
11490 if (tp
->number_on_target
== 0)
11492 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11493 phex_nz (loc
->address
, 0));
11495 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11496 if (reply
&& *reply
)
11499 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11505 utp
->hit_count
= 0;
11506 utp
->traceframe_usage
= 0;
11507 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11508 phex_nz (utp
->addr
, 0));
11510 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11511 if (reply
&& *reply
)
11514 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11520 remote_trace_stop (struct target_ops
*self
)
11523 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11524 if (*target_buf
== '\0')
11525 error (_("Target does not support this command."));
11526 if (strcmp (target_buf
, "OK") != 0)
11527 error (_("Bogus reply from target: %s"), target_buf
);
11531 remote_trace_find (struct target_ops
*self
,
11532 enum trace_find_type type
, int num
,
11533 CORE_ADDR addr1
, CORE_ADDR addr2
,
11536 struct remote_state
*rs
= get_remote_state ();
11537 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11539 int target_frameno
= -1, target_tracept
= -1;
11541 /* Lookups other than by absolute frame number depend on the current
11542 trace selected, so make sure it is correct on the remote end
11544 if (type
!= tfind_number
)
11545 set_remote_traceframe ();
11548 strcpy (p
, "QTFrame:");
11549 p
= strchr (p
, '\0');
11553 xsnprintf (p
, endbuf
- p
, "%x", num
);
11556 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11559 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11562 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11563 phex_nz (addr2
, 0));
11565 case tfind_outside
:
11566 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11567 phex_nz (addr2
, 0));
11570 error (_("Unknown trace find type %d"), type
);
11574 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11575 if (*reply
== '\0')
11576 error (_("Target does not support this command."));
11578 while (reply
&& *reply
)
11583 target_frameno
= (int) strtol (p
, &reply
, 16);
11585 error (_("Unable to parse trace frame number"));
11586 /* Don't update our remote traceframe number cache on failure
11587 to select a remote traceframe. */
11588 if (target_frameno
== -1)
11593 target_tracept
= (int) strtol (p
, &reply
, 16);
11595 error (_("Unable to parse tracepoint number"));
11597 case 'O': /* "OK"? */
11598 if (reply
[1] == 'K' && reply
[2] == '\0')
11601 error (_("Bogus reply from target: %s"), reply
);
11604 error (_("Bogus reply from target: %s"), reply
);
11607 *tpp
= target_tracept
;
11609 rs
->remote_traceframe_number
= target_frameno
;
11610 return target_frameno
;
11614 remote_get_trace_state_variable_value (struct target_ops
*self
,
11615 int tsvnum
, LONGEST
*val
)
11617 struct remote_state
*rs
= get_remote_state ();
11621 set_remote_traceframe ();
11623 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11625 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11626 if (reply
&& *reply
)
11630 unpack_varlen_hex (reply
+ 1, &uval
);
11631 *val
= (LONGEST
) uval
;
11639 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11641 struct remote_state
*rs
= get_remote_state ();
11645 strcpy (p
, "QTSave:");
11647 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11648 error (_("Remote file name too long for trace save packet"));
11649 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11652 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11653 if (*reply
== '\0')
11654 error (_("Target does not support this command."));
11655 if (strcmp (reply
, "OK") != 0)
11656 error (_("Bogus reply from target: %s"), reply
);
11660 /* This is basically a memory transfer, but needs to be its own packet
11661 because we don't know how the target actually organizes its trace
11662 memory, plus we want to be able to ask for as much as possible, but
11663 not be unhappy if we don't get as much as we ask for. */
11666 remote_get_raw_trace_data (struct target_ops
*self
,
11667 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11669 struct remote_state
*rs
= get_remote_state ();
11675 strcpy (p
, "qTBuffer:");
11677 p
+= hexnumstr (p
, offset
);
11679 p
+= hexnumstr (p
, len
);
11683 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11684 if (reply
&& *reply
)
11686 /* 'l' by itself means we're at the end of the buffer and
11687 there is nothing more to get. */
11691 /* Convert the reply into binary. Limit the number of bytes to
11692 convert according to our passed-in buffer size, rather than
11693 what was returned in the packet; if the target is
11694 unexpectedly generous and gives us a bigger reply than we
11695 asked for, we don't want to crash. */
11696 rslt
= hex2bin (target_buf
, buf
, len
);
11700 /* Something went wrong, flag as an error. */
11705 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11707 struct remote_state
*rs
= get_remote_state ();
11709 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11713 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11715 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11716 if (*reply
== '\0')
11717 error (_("Target does not support this command."));
11718 if (strcmp (reply
, "OK") != 0)
11719 error (_("Bogus reply from target: %s"), reply
);
11722 warning (_("Target does not support disconnected tracing."));
11726 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11728 struct thread_info
*info
= find_thread_ptid (ptid
);
11730 if (info
&& info
->priv
)
11731 return info
->priv
->core
;
11736 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11738 struct remote_state
*rs
= get_remote_state ();
11741 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11743 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11744 if (*reply
== '\0')
11745 error (_("Target does not support this command."));
11746 if (strcmp (reply
, "OK") != 0)
11747 error (_("Bogus reply from target: %s"), reply
);
11750 static struct traceframe_info
*
11751 remote_traceframe_info (struct target_ops
*self
)
11755 text
= target_read_stralloc (¤t_target
,
11756 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11759 struct traceframe_info
*info
;
11760 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11762 info
= parse_traceframe_info (text
);
11763 do_cleanups (back_to
);
11770 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11771 instruction on which a fast tracepoint may be placed. Returns -1
11772 if the packet is not supported, and 0 if the minimum instruction
11773 length is unknown. */
11776 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11778 struct remote_state
*rs
= get_remote_state ();
11781 /* If we're not debugging a process yet, the IPA can't be
11783 if (!target_has_execution
)
11786 /* Make sure the remote is pointing at the right process. */
11787 set_general_process ();
11789 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11791 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11792 if (*reply
== '\0')
11796 ULONGEST min_insn_len
;
11798 unpack_varlen_hex (reply
, &min_insn_len
);
11800 return (int) min_insn_len
;
11805 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11807 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11809 struct remote_state
*rs
= get_remote_state ();
11810 char *buf
= rs
->buf
;
11811 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11812 enum packet_result result
;
11814 gdb_assert (val
>= 0 || val
== -1);
11815 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11816 /* Send -1 as literal "-1" to avoid host size dependency. */
11820 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11823 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11826 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11827 result
= packet_ok (rs
->buf
,
11828 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11830 if (result
!= PACKET_OK
)
11831 warning (_("Bogus reply from target: %s"), rs
->buf
);
11836 remote_set_trace_notes (struct target_ops
*self
,
11837 const char *user
, const char *notes
,
11838 const char *stop_notes
)
11840 struct remote_state
*rs
= get_remote_state ();
11842 char *buf
= rs
->buf
;
11843 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11846 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11849 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11850 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11856 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11857 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11863 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11864 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11868 /* Ensure the buffer is terminated. */
11872 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11873 if (*reply
== '\0')
11876 if (strcmp (reply
, "OK") != 0)
11877 error (_("Bogus reply from target: %s"), reply
);
11883 remote_use_agent (struct target_ops
*self
, int use
)
11885 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11887 struct remote_state
*rs
= get_remote_state ();
11889 /* If the stub supports QAgent. */
11890 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11892 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11894 if (strcmp (rs
->buf
, "OK") == 0)
11905 remote_can_use_agent (struct target_ops
*self
)
11907 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11910 struct btrace_target_info
11912 /* The ptid of the traced thread. */
11915 /* The obtained branch trace configuration. */
11916 struct btrace_config conf
;
11919 /* Reset our idea of our target's btrace configuration. */
11922 remote_btrace_reset (void)
11924 struct remote_state
*rs
= get_remote_state ();
11926 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
11929 /* Check whether the target supports branch tracing. */
11932 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
11934 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11936 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11941 case BTRACE_FORMAT_NONE
:
11944 case BTRACE_FORMAT_BTS
:
11945 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
11947 case BTRACE_FORMAT_PT
:
11948 /* The trace is decoded on the host. Even if our target supports it,
11949 we still need to have libipt to decode the trace. */
11950 #if defined (HAVE_LIBIPT)
11951 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
11952 #else /* !defined (HAVE_LIBIPT) */
11954 #endif /* !defined (HAVE_LIBIPT) */
11957 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
11960 /* Synchronize the configuration with the target. */
11963 btrace_sync_conf (const struct btrace_config
*conf
)
11965 struct packet_config
*packet
;
11966 struct remote_state
*rs
;
11967 char *buf
, *pos
, *endbuf
;
11969 rs
= get_remote_state ();
11971 endbuf
= buf
+ get_remote_packet_size ();
11973 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
11974 if (packet_config_support (packet
) == PACKET_ENABLE
11975 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
11978 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11982 getpkt (&buf
, &rs
->buf_size
, 0);
11984 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11986 if (buf
[0] == 'E' && buf
[1] == '.')
11987 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
11989 error (_("Failed to configure the BTS buffer size."));
11992 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
11995 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
11996 if (packet_config_support (packet
) == PACKET_ENABLE
11997 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12000 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12004 getpkt (&buf
, &rs
->buf_size
, 0);
12006 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12008 if (buf
[0] == 'E' && buf
[1] == '.')
12009 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12011 error (_("Failed to configure the trace buffer size."));
12014 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12018 /* Read the current thread's btrace configuration from the target and
12019 store it into CONF. */
12022 btrace_read_config (struct btrace_config
*conf
)
12026 xml
= target_read_stralloc (¤t_target
,
12027 TARGET_OBJECT_BTRACE_CONF
, "");
12030 struct cleanup
*cleanup
;
12032 cleanup
= make_cleanup (xfree
, xml
);
12033 parse_xml_btrace_conf (conf
, xml
);
12034 do_cleanups (cleanup
);
12038 /* Enable branch tracing. */
12040 static struct btrace_target_info
*
12041 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12042 const struct btrace_config
*conf
)
12044 struct btrace_target_info
*tinfo
= NULL
;
12045 struct packet_config
*packet
= NULL
;
12046 struct remote_state
*rs
= get_remote_state ();
12047 char *buf
= rs
->buf
;
12048 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12050 switch (conf
->format
)
12052 case BTRACE_FORMAT_BTS
:
12053 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12056 case BTRACE_FORMAT_PT
:
12057 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12061 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12062 error (_("Target does not support branch tracing."));
12064 btrace_sync_conf (conf
);
12066 set_general_thread (ptid
);
12068 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12070 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12072 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12074 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12075 error (_("Could not enable branch tracing for %s: %s"),
12076 target_pid_to_str (ptid
), rs
->buf
+ 2);
12078 error (_("Could not enable branch tracing for %s."),
12079 target_pid_to_str (ptid
));
12082 tinfo
= xzalloc (sizeof (*tinfo
));
12083 tinfo
->ptid
= ptid
;
12085 /* If we fail to read the configuration, we lose some information, but the
12086 tracing itself is not impacted. */
12089 btrace_read_config (&tinfo
->conf
);
12091 CATCH (err
, RETURN_MASK_ERROR
)
12093 if (err
.message
!= NULL
)
12094 warning ("%s", err
.message
);
12101 /* Disable branch tracing. */
12104 remote_disable_btrace (struct target_ops
*self
,
12105 struct btrace_target_info
*tinfo
)
12107 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12108 struct remote_state
*rs
= get_remote_state ();
12109 char *buf
= rs
->buf
;
12110 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12112 if (packet_config_support (packet
) != PACKET_ENABLE
)
12113 error (_("Target does not support branch tracing."));
12115 set_general_thread (tinfo
->ptid
);
12117 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12119 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12121 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12123 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12124 error (_("Could not disable branch tracing for %s: %s"),
12125 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12127 error (_("Could not disable branch tracing for %s."),
12128 target_pid_to_str (tinfo
->ptid
));
12134 /* Teardown branch tracing. */
12137 remote_teardown_btrace (struct target_ops
*self
,
12138 struct btrace_target_info
*tinfo
)
12140 /* We must not talk to the target during teardown. */
12144 /* Read the branch trace. */
12146 static enum btrace_error
12147 remote_read_btrace (struct target_ops
*self
,
12148 struct btrace_data
*btrace
,
12149 struct btrace_target_info
*tinfo
,
12150 enum btrace_read_type type
)
12152 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12153 struct remote_state
*rs
= get_remote_state ();
12154 struct cleanup
*cleanup
;
12158 if (packet_config_support (packet
) != PACKET_ENABLE
)
12159 error (_("Target does not support branch tracing."));
12161 #if !defined(HAVE_LIBEXPAT)
12162 error (_("Cannot process branch tracing result. XML parsing not supported."));
12167 case BTRACE_READ_ALL
:
12170 case BTRACE_READ_NEW
:
12173 case BTRACE_READ_DELTA
:
12177 internal_error (__FILE__
, __LINE__
,
12178 _("Bad branch tracing read type: %u."),
12179 (unsigned int) type
);
12182 xml
= target_read_stralloc (¤t_target
,
12183 TARGET_OBJECT_BTRACE
, annex
);
12185 return BTRACE_ERR_UNKNOWN
;
12187 cleanup
= make_cleanup (xfree
, xml
);
12188 parse_xml_btrace (btrace
, xml
);
12189 do_cleanups (cleanup
);
12191 return BTRACE_ERR_NONE
;
12194 static const struct btrace_config
*
12195 remote_btrace_conf (struct target_ops
*self
,
12196 const struct btrace_target_info
*tinfo
)
12198 return &tinfo
->conf
;
12202 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12204 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12208 /* Implementation of to_load. */
12211 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12213 generic_load (name
, from_tty
);
12216 /* Accepts an integer PID; returns a string representing a file that
12217 can be opened on the remote side to get the symbols for the child
12218 process. Returns NULL if the operation is not supported. */
12221 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12223 static char *filename
= NULL
;
12224 struct inferior
*inf
;
12225 char *annex
= NULL
;
12227 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12230 if (filename
!= NULL
)
12233 inf
= find_inferior_pid (pid
);
12235 internal_error (__FILE__
, __LINE__
,
12236 _("not currently attached to process %d"), pid
);
12238 if (!inf
->fake_pid_p
)
12240 const int annex_size
= 9;
12242 annex
= alloca (annex_size
);
12243 xsnprintf (annex
, annex_size
, "%x", pid
);
12246 filename
= target_read_stralloc (¤t_target
,
12247 TARGET_OBJECT_EXEC_FILE
, annex
);
12253 init_remote_ops (void)
12255 remote_ops
.to_shortname
= "remote";
12256 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12257 remote_ops
.to_doc
=
12258 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12259 Specify the serial device it is connected to\n\
12260 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12261 remote_ops
.to_open
= remote_open
;
12262 remote_ops
.to_close
= remote_close
;
12263 remote_ops
.to_detach
= remote_detach
;
12264 remote_ops
.to_disconnect
= remote_disconnect
;
12265 remote_ops
.to_resume
= remote_resume
;
12266 remote_ops
.to_wait
= remote_wait
;
12267 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12268 remote_ops
.to_store_registers
= remote_store_registers
;
12269 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12270 remote_ops
.to_files_info
= remote_files_info
;
12271 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12272 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12273 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12274 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12275 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12276 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12277 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12278 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12279 remote_ops
.to_watchpoint_addr_within_range
=
12280 remote_watchpoint_addr_within_range
;
12281 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12282 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12283 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12284 remote_ops
.to_region_ok_for_hw_watchpoint
12285 = remote_region_ok_for_hw_watchpoint
;
12286 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12287 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12288 remote_ops
.to_kill
= remote_kill
;
12289 remote_ops
.to_load
= remote_load
;
12290 remote_ops
.to_mourn_inferior
= remote_mourn
;
12291 remote_ops
.to_pass_signals
= remote_pass_signals
;
12292 remote_ops
.to_program_signals
= remote_program_signals
;
12293 remote_ops
.to_thread_alive
= remote_thread_alive
;
12294 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12295 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12296 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12297 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12298 remote_ops
.to_stop
= remote_stop
;
12299 remote_ops
.to_interrupt
= remote_interrupt
;
12300 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12301 remote_ops
.to_rcmd
= remote_rcmd
;
12302 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12303 remote_ops
.to_log_command
= serial_log_command
;
12304 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12305 remote_ops
.to_stratum
= process_stratum
;
12306 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12307 remote_ops
.to_has_memory
= default_child_has_memory
;
12308 remote_ops
.to_has_stack
= default_child_has_stack
;
12309 remote_ops
.to_has_registers
= default_child_has_registers
;
12310 remote_ops
.to_has_execution
= default_child_has_execution
;
12311 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12312 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12313 remote_ops
.to_magic
= OPS_MAGIC
;
12314 remote_ops
.to_memory_map
= remote_memory_map
;
12315 remote_ops
.to_flash_erase
= remote_flash_erase
;
12316 remote_ops
.to_flash_done
= remote_flash_done
;
12317 remote_ops
.to_read_description
= remote_read_description
;
12318 remote_ops
.to_search_memory
= remote_search_memory
;
12319 remote_ops
.to_can_async_p
= remote_can_async_p
;
12320 remote_ops
.to_is_async_p
= remote_is_async_p
;
12321 remote_ops
.to_async
= remote_async
;
12322 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12323 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12324 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12325 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12326 remote_ops
.to_supports_disable_randomization
12327 = remote_supports_disable_randomization
;
12328 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12329 remote_ops
.to_fileio_open
= remote_hostio_open
;
12330 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12331 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12332 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12333 remote_ops
.to_fileio_close
= remote_hostio_close
;
12334 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12335 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12336 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12337 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12338 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12339 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12340 remote_ops
.to_trace_init
= remote_trace_init
;
12341 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12342 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12343 remote_ops
.to_download_trace_state_variable
12344 = remote_download_trace_state_variable
;
12345 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12346 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12347 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12348 remote_ops
.to_trace_start
= remote_trace_start
;
12349 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12350 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12351 remote_ops
.to_trace_stop
= remote_trace_stop
;
12352 remote_ops
.to_trace_find
= remote_trace_find
;
12353 remote_ops
.to_get_trace_state_variable_value
12354 = remote_get_trace_state_variable_value
;
12355 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12356 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12357 remote_ops
.to_upload_trace_state_variables
12358 = remote_upload_trace_state_variables
;
12359 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12360 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12361 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12362 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12363 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12364 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12365 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12366 remote_ops
.to_verify_memory
= remote_verify_memory
;
12367 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12368 remote_ops
.to_set_permissions
= remote_set_permissions
;
12369 remote_ops
.to_static_tracepoint_marker_at
12370 = remote_static_tracepoint_marker_at
;
12371 remote_ops
.to_static_tracepoint_markers_by_strid
12372 = remote_static_tracepoint_markers_by_strid
;
12373 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12374 remote_ops
.to_use_agent
= remote_use_agent
;
12375 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12376 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12377 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12378 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12379 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12380 remote_ops
.to_read_btrace
= remote_read_btrace
;
12381 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12382 remote_ops
.to_augmented_libraries_svr4_read
=
12383 remote_augmented_libraries_svr4_read
;
12386 /* Set up the extended remote vector by making a copy of the standard
12387 remote vector and adding to it. */
12390 init_extended_remote_ops (void)
12392 extended_remote_ops
= remote_ops
;
12394 extended_remote_ops
.to_shortname
= "extended-remote";
12395 extended_remote_ops
.to_longname
=
12396 "Extended remote serial target in gdb-specific protocol";
12397 extended_remote_ops
.to_doc
=
12398 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12399 Specify the serial device it is connected to (e.g. /dev/ttya).";
12400 extended_remote_ops
.to_open
= extended_remote_open
;
12401 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12402 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12403 extended_remote_ops
.to_detach
= extended_remote_detach
;
12404 extended_remote_ops
.to_attach
= extended_remote_attach
;
12405 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12406 extended_remote_ops
.to_kill
= extended_remote_kill
;
12407 extended_remote_ops
.to_supports_disable_randomization
12408 = extended_remote_supports_disable_randomization
;
12409 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12410 extended_remote_ops
.to_insert_fork_catchpoint
12411 = remote_insert_fork_catchpoint
;
12412 extended_remote_ops
.to_remove_fork_catchpoint
12413 = remote_remove_fork_catchpoint
;
12414 extended_remote_ops
.to_insert_vfork_catchpoint
12415 = remote_insert_vfork_catchpoint
;
12416 extended_remote_ops
.to_remove_vfork_catchpoint
12417 = remote_remove_vfork_catchpoint
;
12421 remote_can_async_p (struct target_ops
*ops
)
12423 struct remote_state
*rs
= get_remote_state ();
12425 if (!target_async_permitted
)
12426 /* We only enable async when the user specifically asks for it. */
12429 /* We're async whenever the serial device is. */
12430 return serial_can_async_p (rs
->remote_desc
);
12434 remote_is_async_p (struct target_ops
*ops
)
12436 struct remote_state
*rs
= get_remote_state ();
12438 if (!target_async_permitted
)
12439 /* We only enable async when the user specifically asks for it. */
12442 /* We're async whenever the serial device is. */
12443 return serial_is_async_p (rs
->remote_desc
);
12446 /* Pass the SERIAL event on and up to the client. One day this code
12447 will be able to delay notifying the client of an event until the
12448 point where an entire packet has been received. */
12450 static serial_event_ftype remote_async_serial_handler
;
12453 remote_async_serial_handler (struct serial
*scb
, void *context
)
12455 struct remote_state
*rs
= context
;
12457 /* Don't propogate error information up to the client. Instead let
12458 the client find out about the error by querying the target. */
12459 inferior_event_handler (INF_REG_EVENT
, NULL
);
12463 remote_async_inferior_event_handler (gdb_client_data data
)
12465 inferior_event_handler (INF_REG_EVENT
, NULL
);
12469 remote_async (struct target_ops
*ops
, int enable
)
12471 struct remote_state
*rs
= get_remote_state ();
12475 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12477 /* If there are pending events in the stop reply queue tell the
12478 event loop to process them. */
12479 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12480 mark_async_event_handler (remote_async_inferior_event_token
);
12484 serial_async (rs
->remote_desc
, NULL
, NULL
);
12485 clear_async_event_handler (remote_async_inferior_event_token
);
12490 set_remote_cmd (char *args
, int from_tty
)
12492 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12496 show_remote_cmd (char *args
, int from_tty
)
12498 /* We can't just use cmd_show_list here, because we want to skip
12499 the redundant "show remote Z-packet" and the legacy aliases. */
12500 struct cleanup
*showlist_chain
;
12501 struct cmd_list_element
*list
= remote_show_cmdlist
;
12502 struct ui_out
*uiout
= current_uiout
;
12504 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12505 for (; list
!= NULL
; list
= list
->next
)
12506 if (strcmp (list
->name
, "Z-packet") == 0)
12508 else if (list
->type
== not_set_cmd
)
12509 /* Alias commands are exactly like the original, except they
12510 don't have the normal type. */
12514 struct cleanup
*option_chain
12515 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12517 ui_out_field_string (uiout
, "name", list
->name
);
12518 ui_out_text (uiout
, ": ");
12519 if (list
->type
== show_cmd
)
12520 do_show_command ((char *) NULL
, from_tty
, list
);
12522 cmd_func (list
, NULL
, from_tty
);
12523 /* Close the tuple. */
12524 do_cleanups (option_chain
);
12527 /* Close the tuple. */
12528 do_cleanups (showlist_chain
);
12532 /* Function to be called whenever a new objfile (shlib) is detected. */
12534 remote_new_objfile (struct objfile
*objfile
)
12536 struct remote_state
*rs
= get_remote_state ();
12538 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12539 remote_check_symbols ();
12542 /* Pull all the tracepoints defined on the target and create local
12543 data structures representing them. We don't want to create real
12544 tracepoints yet, we don't want to mess up the user's existing
12548 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12550 struct remote_state
*rs
= get_remote_state ();
12553 /* Ask for a first packet of tracepoint definition. */
12555 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12557 while (*p
&& *p
!= 'l')
12559 parse_tracepoint_definition (p
, utpp
);
12560 /* Ask for another packet of tracepoint definition. */
12562 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12569 remote_upload_trace_state_variables (struct target_ops
*self
,
12570 struct uploaded_tsv
**utsvp
)
12572 struct remote_state
*rs
= get_remote_state ();
12575 /* Ask for a first packet of variable definition. */
12577 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12579 while (*p
&& *p
!= 'l')
12581 parse_tsv_definition (p
, utsvp
);
12582 /* Ask for another packet of variable definition. */
12584 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12590 /* The "set/show range-stepping" show hook. */
12593 show_range_stepping (struct ui_file
*file
, int from_tty
,
12594 struct cmd_list_element
*c
,
12597 fprintf_filtered (file
,
12598 _("Debugger's willingness to use range stepping "
12599 "is %s.\n"), value
);
12602 /* The "set/show range-stepping" set hook. */
12605 set_range_stepping (char *ignore_args
, int from_tty
,
12606 struct cmd_list_element
*c
)
12608 struct remote_state
*rs
= get_remote_state ();
12610 /* Whene enabling, check whether range stepping is actually
12611 supported by the target, and warn if not. */
12612 if (use_range_stepping
)
12614 if (rs
->remote_desc
!= NULL
)
12616 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12617 remote_vcont_probe (rs
);
12619 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12620 && rs
->supports_vCont
.r
)
12624 warning (_("Range stepping is not supported by the current target"));
12629 _initialize_remote (void)
12631 struct remote_state
*rs
;
12632 struct cmd_list_element
*cmd
;
12633 const char *cmd_name
;
12635 /* architecture specific data */
12636 remote_gdbarch_data_handle
=
12637 gdbarch_data_register_post_init (init_remote_state
);
12638 remote_g_packet_data_handle
=
12639 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12641 /* Initialize the per-target state. At the moment there is only one
12642 of these, not one per target. Only one target is active at a
12644 remote_state
= new_remote_state ();
12646 init_remote_ops ();
12647 add_target (&remote_ops
);
12649 init_extended_remote_ops ();
12650 add_target (&extended_remote_ops
);
12652 /* Hook into new objfile notification. */
12653 observer_attach_new_objfile (remote_new_objfile
);
12654 /* We're no longer interested in notification events of an inferior
12656 observer_attach_inferior_exit (discard_pending_stop_replies
);
12658 /* Set up signal handlers. */
12659 async_sigint_remote_token
=
12660 create_async_signal_handler (async_remote_interrupt
, NULL
);
12661 async_sigint_remote_twice_token
=
12662 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12665 init_remote_threadtests ();
12668 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12669 /* set/show remote ... */
12671 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12672 Remote protocol specific variables\n\
12673 Configure various remote-protocol specific variables such as\n\
12674 the packets being used"),
12675 &remote_set_cmdlist
, "set remote ",
12676 0 /* allow-unknown */, &setlist
);
12677 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12678 Remote protocol specific variables\n\
12679 Configure various remote-protocol specific variables such as\n\
12680 the packets being used"),
12681 &remote_show_cmdlist
, "show remote ",
12682 0 /* allow-unknown */, &showlist
);
12684 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12685 Compare section data on target to the exec file.\n\
12686 Argument is a single section name (default: all loaded sections).\n\
12687 To compare only read-only loaded sections, specify the -r option."),
12690 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12691 Send an arbitrary packet to a remote target.\n\
12692 maintenance packet TEXT\n\
12693 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12694 this command sends the string TEXT to the inferior, and displays the\n\
12695 response packet. GDB supplies the initial `$' character, and the\n\
12696 terminating `#' character and checksum."),
12699 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12700 Set whether to send break if interrupted."), _("\
12701 Show whether to send break if interrupted."), _("\
12702 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12703 set_remotebreak
, show_remotebreak
,
12704 &setlist
, &showlist
);
12705 cmd_name
= "remotebreak";
12706 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12707 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12708 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12709 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12710 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12712 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12713 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12715 Set interrupt sequence to remote target."), _("\
12716 Show interrupt sequence to remote target."), _("\
12717 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12718 NULL
, show_interrupt_sequence
,
12719 &remote_set_cmdlist
,
12720 &remote_show_cmdlist
);
12722 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12723 &interrupt_on_connect
, _("\
12724 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12725 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12726 If set, interrupt sequence is sent to remote target."),
12728 &remote_set_cmdlist
, &remote_show_cmdlist
);
12730 /* Install commands for configuring memory read/write packets. */
12732 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12733 Set the maximum number of bytes per memory write packet (deprecated)."),
12735 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12736 Show the maximum number of bytes per memory write packet (deprecated)."),
12738 add_cmd ("memory-write-packet-size", no_class
,
12739 set_memory_write_packet_size
, _("\
12740 Set the maximum number of bytes per memory-write packet.\n\
12741 Specify the number of bytes in a packet or 0 (zero) for the\n\
12742 default packet size. The actual limit is further reduced\n\
12743 dependent on the target. Specify ``fixed'' to disable the\n\
12744 further restriction and ``limit'' to enable that restriction."),
12745 &remote_set_cmdlist
);
12746 add_cmd ("memory-read-packet-size", no_class
,
12747 set_memory_read_packet_size
, _("\
12748 Set the maximum number of bytes per memory-read packet.\n\
12749 Specify the number of bytes in a packet or 0 (zero) for the\n\
12750 default packet size. The actual limit is further reduced\n\
12751 dependent on the target. Specify ``fixed'' to disable the\n\
12752 further restriction and ``limit'' to enable that restriction."),
12753 &remote_set_cmdlist
);
12754 add_cmd ("memory-write-packet-size", no_class
,
12755 show_memory_write_packet_size
,
12756 _("Show the maximum number of bytes per memory-write packet."),
12757 &remote_show_cmdlist
);
12758 add_cmd ("memory-read-packet-size", no_class
,
12759 show_memory_read_packet_size
,
12760 _("Show the maximum number of bytes per memory-read packet."),
12761 &remote_show_cmdlist
);
12763 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12764 &remote_hw_watchpoint_limit
, _("\
12765 Set the maximum number of target hardware watchpoints."), _("\
12766 Show the maximum number of target hardware watchpoints."), _("\
12767 Specify a negative limit for unlimited."),
12768 NULL
, NULL
, /* FIXME: i18n: The maximum
12769 number of target hardware
12770 watchpoints is %s. */
12771 &remote_set_cmdlist
, &remote_show_cmdlist
);
12772 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12773 &remote_hw_watchpoint_length_limit
, _("\
12774 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12775 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12776 Specify a negative limit for unlimited."),
12777 NULL
, NULL
, /* FIXME: i18n: The maximum
12778 length (in bytes) of a target
12779 hardware watchpoint is %s. */
12780 &remote_set_cmdlist
, &remote_show_cmdlist
);
12781 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12782 &remote_hw_breakpoint_limit
, _("\
12783 Set the maximum number of target hardware breakpoints."), _("\
12784 Show the maximum number of target hardware breakpoints."), _("\
12785 Specify a negative limit for unlimited."),
12786 NULL
, NULL
, /* FIXME: i18n: The maximum
12787 number of target hardware
12788 breakpoints is %s. */
12789 &remote_set_cmdlist
, &remote_show_cmdlist
);
12791 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12792 &remote_address_size
, _("\
12793 Set the maximum size of the address (in bits) in a memory packet."), _("\
12794 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12796 NULL
, /* FIXME: i18n: */
12797 &setlist
, &showlist
);
12799 init_all_packet_configs ();
12801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12802 "X", "binary-download", 1);
12804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12805 "vCont", "verbose-resume", 0);
12807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12808 "QPassSignals", "pass-signals", 0);
12810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12811 "QProgramSignals", "program-signals", 0);
12813 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12814 "qSymbol", "symbol-lookup", 0);
12816 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12817 "P", "set-register", 1);
12819 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12820 "p", "fetch-register", 1);
12822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12823 "Z0", "software-breakpoint", 0);
12825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12826 "Z1", "hardware-breakpoint", 0);
12828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12829 "Z2", "write-watchpoint", 0);
12831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12832 "Z3", "read-watchpoint", 0);
12834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12835 "Z4", "access-watchpoint", 0);
12837 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12838 "qXfer:auxv:read", "read-aux-vector", 0);
12840 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
12841 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12843 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12844 "qXfer:features:read", "target-features", 0);
12846 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12847 "qXfer:libraries:read", "library-info", 0);
12849 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12850 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12852 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12853 "qXfer:memory-map:read", "memory-map", 0);
12855 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12856 "qXfer:spu:read", "read-spu-object", 0);
12858 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12859 "qXfer:spu:write", "write-spu-object", 0);
12861 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12862 "qXfer:osdata:read", "osdata", 0);
12864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12865 "qXfer:threads:read", "threads", 0);
12867 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12868 "qXfer:siginfo:read", "read-siginfo-object", 0);
12870 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12871 "qXfer:siginfo:write", "write-siginfo-object", 0);
12873 add_packet_config_cmd
12874 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12875 "qXfer:traceframe-info:read", "traceframe-info", 0);
12877 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12878 "qXfer:uib:read", "unwind-info-block", 0);
12880 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12881 "qGetTLSAddr", "get-thread-local-storage-address",
12884 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12885 "qGetTIBAddr", "get-thread-information-block-address",
12888 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12889 "bc", "reverse-continue", 0);
12891 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12892 "bs", "reverse-step", 0);
12894 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12895 "qSupported", "supported-packets", 0);
12897 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12898 "qSearch:memory", "search-memory", 0);
12900 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12901 "qTStatus", "trace-status", 0);
12903 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
12904 "vFile:setfs", "hostio-setfs", 0);
12906 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12907 "vFile:open", "hostio-open", 0);
12909 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12910 "vFile:pread", "hostio-pread", 0);
12912 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12913 "vFile:pwrite", "hostio-pwrite", 0);
12915 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12916 "vFile:close", "hostio-close", 0);
12918 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12919 "vFile:unlink", "hostio-unlink", 0);
12921 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12922 "vFile:readlink", "hostio-readlink", 0);
12924 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
12925 "vFile:fstat", "hostio-fstat", 0);
12927 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12928 "vAttach", "attach", 0);
12930 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12933 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12934 "QStartNoAckMode", "noack", 0);
12936 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12937 "vKill", "kill", 0);
12939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12940 "qAttached", "query-attached", 0);
12942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12943 "ConditionalTracepoints",
12944 "conditional-tracepoints", 0);
12946 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12947 "ConditionalBreakpoints",
12948 "conditional-breakpoints", 0);
12950 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12951 "BreakpointCommands",
12952 "breakpoint-commands", 0);
12954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12955 "FastTracepoints", "fast-tracepoints", 0);
12957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12958 "TracepointSource", "TracepointSource", 0);
12960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12961 "QAllow", "allow", 0);
12963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12964 "StaticTracepoints", "static-tracepoints", 0);
12966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12967 "InstallInTrace", "install-in-trace", 0);
12969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12970 "qXfer:statictrace:read", "read-sdata-object", 0);
12972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12973 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12976 "QDisableRandomization", "disable-randomization", 0);
12978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12979 "QAgent", "agent", 0);
12981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12982 "QTBuffer:size", "trace-buffer-size", 0);
12984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12985 "Qbtrace:off", "disable-btrace", 0);
12987 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12988 "Qbtrace:bts", "enable-btrace-bts", 0);
12990 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
12991 "Qbtrace:pt", "enable-btrace-pt", 0);
12993 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12994 "qXfer:btrace", "read-btrace", 0);
12996 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
12997 "qXfer:btrace-conf", "read-btrace-conf", 0);
12999 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13000 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13002 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13003 "swbreak-feature", "swbreak-feature", 0);
13005 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13006 "hwbreak-feature", "hwbreak-feature", 0);
13008 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13009 "fork-event-feature", "fork-event-feature", 0);
13011 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13012 "vfork-event-feature", "vfork-event-feature", 0);
13014 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13015 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13017 /* Assert that we've registered "set remote foo-packet" commands
13018 for all packet configs. */
13022 for (i
= 0; i
< PACKET_MAX
; i
++)
13024 /* Ideally all configs would have a command associated. Some
13025 still don't though. */
13030 case PACKET_QNonStop
:
13031 case PACKET_multiprocess_feature
:
13032 case PACKET_EnableDisableTracepoints_feature
:
13033 case PACKET_tracenz_feature
:
13034 case PACKET_DisconnectedTracing_feature
:
13035 case PACKET_augmented_libraries_svr4_read_feature
:
13037 /* Additions to this list need to be well justified:
13038 pre-existing packets are OK; new packets are not. */
13046 /* This catches both forgetting to add a config command, and
13047 forgetting to remove a packet from the exception list. */
13048 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13052 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13053 Z sub-packet has its own set and show commands, but users may
13054 have sets to this variable in their .gdbinit files (or in their
13056 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13057 &remote_Z_packet_detect
, _("\
13058 Set use of remote protocol `Z' packets"), _("\
13059 Show use of remote protocol `Z' packets "), _("\
13060 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13062 set_remote_protocol_Z_packet_cmd
,
13063 show_remote_protocol_Z_packet_cmd
,
13064 /* FIXME: i18n: Use of remote protocol
13065 `Z' packets is %s. */
13066 &remote_set_cmdlist
, &remote_show_cmdlist
);
13068 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13069 Manipulate files on the remote system\n\
13070 Transfer files to and from the remote target system."),
13071 &remote_cmdlist
, "remote ",
13072 0 /* allow-unknown */, &cmdlist
);
13074 add_cmd ("put", class_files
, remote_put_command
,
13075 _("Copy a local file to the remote system."),
13078 add_cmd ("get", class_files
, remote_get_command
,
13079 _("Copy a remote file to the local system."),
13082 add_cmd ("delete", class_files
, remote_delete_command
,
13083 _("Delete a remote file."),
13086 remote_exec_file
= xstrdup ("");
13087 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13088 &remote_exec_file
, _("\
13089 Set the remote pathname for \"run\""), _("\
13090 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
13091 &remote_set_cmdlist
, &remote_show_cmdlist
);
13093 add_setshow_boolean_cmd ("range-stepping", class_run
,
13094 &use_range_stepping
, _("\
13095 Enable or disable range stepping."), _("\
13096 Show whether target-assisted range stepping is enabled."), _("\
13097 If on, and the target supports it, when stepping a source line, GDB\n\
13098 tells the target to step the corresponding range of addresses itself instead\n\
13099 of issuing multiple single-steps. This speeds up source level\n\
13100 stepping. If off, GDB always issues single-steps, even if range\n\
13101 stepping is supported by the target. The default is on."),
13102 set_range_stepping
,
13103 show_range_stepping
,
13107 /* Eventually initialize fileio. See fileio.c */
13108 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13110 /* Take advantage of the fact that the TID field is not used, to tag
13111 special ptids with it set to != 0. */
13112 magic_null_ptid
= ptid_build (42000, -1, 1);
13113 not_sent_ptid
= ptid_build (42000, -2, 1);
13114 any_thread_ptid
= ptid_build (42000, 0, 1);
13116 target_buf_size
= 2048;
13117 target_buf
= xmalloc (target_buf_size
);