1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
60 #include "gdb/fileio.h"
62 #include "xml-support.h"
64 #include "memory-map.h"
66 #include "tracepoint.h"
72 /* Temp hacks for tracepoint encoding migration. */
73 static char *target_buf
;
74 static long target_buf_size
;
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void async_cleanup_sigint_signal_handler (void *dummy
);
90 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
91 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
92 int forever
, int *is_notif
);
94 static void async_handle_remote_sigint (int);
95 static void async_handle_remote_sigint_twice (int);
97 static void remote_files_info (struct target_ops
*ignore
);
99 static void remote_prepare_to_store (struct target_ops
*self
,
100 struct regcache
*regcache
);
102 static void remote_open_1 (const char *, int, struct target_ops
*,
105 static void remote_close (struct target_ops
*self
);
109 static int remote_vkill (int pid
, struct remote_state
*rs
);
111 static void remote_mourn (struct target_ops
*ops
);
113 static void extended_remote_restart (void);
115 static void extended_remote_mourn (struct target_ops
*);
117 static void remote_send (char **buf
, long *sizeof_buf_p
);
119 static int readchar (int timeout
);
121 static void remote_serial_write (const char *str
, int len
);
123 static void remote_kill (struct target_ops
*ops
);
125 static int remote_can_async_p (struct target_ops
*);
127 static int remote_is_async_p (struct target_ops
*);
129 static void remote_async (struct target_ops
*ops
, int enable
);
131 static void sync_remote_interrupt_twice (int signo
);
133 static void interrupt_query (void);
135 static void set_general_thread (struct ptid ptid
);
136 static void set_continue_thread (struct ptid ptid
);
138 static void get_offsets (void);
140 static void skip_frame (void);
142 static long read_frame (char **buf_p
, long *sizeof_buf
);
144 static int hexnumlen (ULONGEST num
);
146 static void init_remote_ops (void);
148 static void init_extended_remote_ops (void);
150 static void remote_stop (struct target_ops
*self
, ptid_t
);
152 static int stubhex (int ch
);
154 static int hexnumstr (char *, ULONGEST
);
156 static int hexnumnstr (char *, ULONGEST
, int);
158 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
160 static void print_packet (const char *);
162 static void compare_sections_command (char *, int);
164 static void packet_command (char *, int);
166 static int stub_unpack_int (char *buff
, int fieldlength
);
168 static ptid_t
remote_current_thread (ptid_t oldptid
);
170 static int putpkt_binary (const char *buf
, int cnt
);
172 static void check_binary_download (CORE_ADDR addr
);
174 struct packet_config
;
176 static void show_packet_config_cmd (struct packet_config
*config
);
178 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
180 struct cmd_list_element
*c
,
183 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
184 static ptid_t
read_ptid (char *buf
, char **obuf
);
186 static void remote_set_permissions (struct target_ops
*self
);
188 static int remote_get_trace_status (struct target_ops
*self
,
189 struct trace_status
*ts
);
191 static int remote_upload_tracepoints (struct target_ops
*self
,
192 struct uploaded_tp
**utpp
);
194 static int remote_upload_trace_state_variables (struct target_ops
*self
,
195 struct uploaded_tsv
**utsvp
);
197 static void remote_query_supported (void);
199 static void remote_check_symbols (void);
201 void _initialize_remote (void);
204 static void stop_reply_xfree (struct stop_reply
*);
205 static void remote_parse_stop_reply (char *, struct stop_reply
*);
206 static void push_stop_reply (struct stop_reply
*);
207 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
208 static int peek_stop_reply (ptid_t ptid
);
210 struct threads_listing_context
;
211 static void remove_new_fork_children (struct threads_listing_context
*);
213 static void remote_async_inferior_event_handler (gdb_client_data
);
215 static void remote_terminal_ours (struct target_ops
*self
);
217 static int remote_read_description_p (struct target_ops
*target
);
219 static void remote_console_output (char *msg
);
221 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
223 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
225 static void remote_btrace_reset (void);
229 static struct cmd_list_element
*remote_cmdlist
;
231 /* For "set remote" and "show remote". */
233 static struct cmd_list_element
*remote_set_cmdlist
;
234 static struct cmd_list_element
*remote_show_cmdlist
;
236 /* Stub vCont actions support.
238 Each field is a boolean flag indicating whether the stub reports
239 support for the corresponding action. */
241 struct vCont_action_support
250 /* Controls whether GDB is willing to use range stepping. */
252 static int use_range_stepping
= 1;
254 #define OPAQUETHREADBYTES 8
256 /* a 64 bit opaque identifier */
257 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
259 /* About this many threadisds fit in a packet. */
261 #define MAXTHREADLISTRESULTS 32
263 /* Description of the remote protocol state for the currently
264 connected target. This is per-target state, and independent of the
265 selected architecture. */
269 /* A buffer to use for incoming packets, and its current size. The
270 buffer is grown dynamically for larger incoming packets.
271 Outgoing packets may also be constructed in this buffer.
272 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
273 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
278 /* True if we're going through initial connection setup (finding out
279 about the remote side's threads, relocating symbols, etc.). */
282 /* If we negotiated packet size explicitly (and thus can bypass
283 heuristics for the largest packet size that will not overflow
284 a buffer in the stub), this will be set to that packet size.
285 Otherwise zero, meaning to use the guessed size. */
286 long explicit_packet_size
;
288 /* remote_wait is normally called when the target is running and
289 waits for a stop reply packet. But sometimes we need to call it
290 when the target is already stopped. We can send a "?" packet
291 and have remote_wait read the response. Or, if we already have
292 the response, we can stash it in BUF and tell remote_wait to
293 skip calling getpkt. This flag is set when BUF contains a
294 stop reply packet and the target is not waiting. */
295 int cached_wait_status
;
297 /* True, if in no ack mode. That is, neither GDB nor the stub will
298 expect acks from each other. The connection is assumed to be
302 /* True if we're connected in extended remote mode. */
305 /* True if we resumed the target and we're waiting for the target to
306 stop. In the mean time, we can't start another command/query.
307 The remote server wouldn't be ready to process it, so we'd
308 timeout waiting for a reply that would never come and eventually
309 we'd close the connection. This can happen in asynchronous mode
310 because we allow GDB commands while the target is running. */
311 int waiting_for_stop_reply
;
313 /* The status of the stub support for the various vCont actions. */
314 struct vCont_action_support supports_vCont
;
316 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
317 responded to that. */
320 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
321 remote_open knows that we don't have a file open when the program
323 struct serial
*remote_desc
;
325 /* These are the threads which we last sent to the remote system. The
326 TID member will be -1 for all or -2 for not sent yet. */
327 ptid_t general_thread
;
328 ptid_t continue_thread
;
330 /* This is the traceframe which we last selected on the remote system.
331 It will be -1 if no traceframe is selected. */
332 int remote_traceframe_number
;
334 char *last_pass_packet
;
336 /* The last QProgramSignals packet sent to the target. We bypass
337 sending a new program signals list down to the target if the new
338 packet is exactly the same as the last we sent. IOW, we only let
339 the target know about program signals list changes. */
340 char *last_program_signals_packet
;
342 enum gdb_signal last_sent_signal
;
346 char *finished_object
;
347 char *finished_annex
;
348 ULONGEST finished_offset
;
350 /* Should we try the 'ThreadInfo' query packet?
352 This variable (NOT available to the user: auto-detect only!)
353 determines whether GDB will use the new, simpler "ThreadInfo"
354 query or the older, more complex syntax for thread queries.
355 This is an auto-detect variable (set to true at each connect,
356 and set to false when the target fails to recognize it). */
357 int use_threadinfo_query
;
358 int use_threadextra_query
;
360 /* This is set to the data address of the access causing the target
361 to stop for a watchpoint. */
362 CORE_ADDR remote_watch_data_address
;
364 /* Whether the target stopped for a breakpoint/watchpoint. */
365 enum target_stop_reason stop_reason
;
367 threadref echo_nextthread
;
368 threadref nextthread
;
369 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
371 /* The state of remote notification. */
372 struct remote_notif_state
*notif_state
;
374 /* The branch trace configuration. */
375 struct btrace_config btrace_config
;
377 /* The argument to the last "vFile:setfs:" packet we sent, used
378 to avoid sending repeated unnecessary "vFile:setfs:" packets.
379 Initialized to -1 to indicate that no "vFile:setfs:" packet
380 has yet been sent. */
384 /* Private data that we'll store in (struct thread_info)->private. */
385 struct private_thread_info
392 free_private_thread_info (struct private_thread_info
*info
)
398 /* This data could be associated with a target, but we do not always
399 have access to the current target when we need it, so for now it is
400 static. This will be fine for as long as only one target is in use
402 static struct remote_state
*remote_state
;
404 static struct remote_state
*
405 get_remote_state_raw (void)
410 /* Allocate a new struct remote_state with xmalloc, initialize it, and
413 static struct remote_state
*
414 new_remote_state (void)
416 struct remote_state
*result
= XCNEW (struct remote_state
);
418 /* The default buffer size is unimportant; it will be expanded
419 whenever a larger buffer is needed. */
420 result
->buf_size
= 400;
421 result
->buf
= xmalloc (result
->buf_size
);
422 result
->remote_traceframe_number
= -1;
423 result
->last_sent_signal
= GDB_SIGNAL_0
;
429 /* Description of the remote protocol for a given architecture. */
433 long offset
; /* Offset into G packet. */
434 long regnum
; /* GDB's internal register number. */
435 LONGEST pnum
; /* Remote protocol register number. */
436 int in_g_packet
; /* Always part of G packet. */
437 /* long size in bytes; == register_size (target_gdbarch (), regnum);
439 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
443 struct remote_arch_state
445 /* Description of the remote protocol registers. */
446 long sizeof_g_packet
;
448 /* Description of the remote protocol registers indexed by REGNUM
449 (making an array gdbarch_num_regs in size). */
450 struct packet_reg
*regs
;
452 /* This is the size (in chars) of the first response to the ``g''
453 packet. It is used as a heuristic when determining the maximum
454 size of memory-read and memory-write packets. A target will
455 typically only reserve a buffer large enough to hold the ``g''
456 packet. The size does not include packet overhead (headers and
458 long actual_register_packet_size
;
460 /* This is the maximum size (in chars) of a non read/write packet.
461 It is also used as a cap on the size of read/write packets. */
462 long remote_packet_size
;
465 /* Utility: generate error from an incoming stub packet. */
467 trace_error (char *buf
)
470 return; /* not an error msg */
473 case '1': /* malformed packet error */
474 if (*++buf
== '0') /* general case: */
475 error (_("remote.c: error in outgoing packet."));
477 error (_("remote.c: error in outgoing packet at field #%ld."),
478 strtol (buf
, NULL
, 16));
480 error (_("Target returns error code '%s'."), buf
);
484 /* Utility: wait for reply from stub, while accepting "O" packets. */
486 remote_get_noisy_reply (char **buf_p
,
489 do /* Loop on reply from remote stub. */
493 QUIT
; /* Allow user to bail out with ^C. */
494 getpkt (buf_p
, sizeof_buf
, 0);
498 else if (startswith (buf
, "qRelocInsn:"))
501 CORE_ADDR from
, to
, org_to
;
503 int adjusted_size
= 0;
506 p
= buf
+ strlen ("qRelocInsn:");
507 pp
= unpack_varlen_hex (p
, &ul
);
509 error (_("invalid qRelocInsn packet: %s"), buf
);
513 unpack_varlen_hex (p
, &ul
);
520 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
523 CATCH (ex
, RETURN_MASK_ALL
)
525 if (ex
.error
== MEMORY_ERROR
)
527 /* Propagate memory errors silently back to the
528 target. The stub may have limited the range of
529 addresses we can write to, for example. */
533 /* Something unexpectedly bad happened. Be verbose
534 so we can tell what, and propagate the error back
535 to the stub, so it doesn't get stuck waiting for
537 exception_fprintf (gdb_stderr
, ex
,
538 _("warning: relocating instruction: "));
546 adjusted_size
= to
- org_to
;
548 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
552 else if (buf
[0] == 'O' && buf
[1] != 'K')
553 remote_console_output (buf
+ 1); /* 'O' message from stub */
555 return buf
; /* Here's the actual reply. */
560 /* Handle for retreving the remote protocol data from gdbarch. */
561 static struct gdbarch_data
*remote_gdbarch_data_handle
;
563 static struct remote_arch_state
*
564 get_remote_arch_state (void)
566 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
569 /* Fetch the global remote target state. */
571 static struct remote_state
*
572 get_remote_state (void)
574 /* Make sure that the remote architecture state has been
575 initialized, because doing so might reallocate rs->buf. Any
576 function which calls getpkt also needs to be mindful of changes
577 to rs->buf, but this call limits the number of places which run
579 get_remote_arch_state ();
581 return get_remote_state_raw ();
585 compare_pnums (const void *lhs_
, const void *rhs_
)
587 const struct packet_reg
* const *lhs
= lhs_
;
588 const struct packet_reg
* const *rhs
= rhs_
;
590 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
592 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
599 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
601 int regnum
, num_remote_regs
, offset
;
602 struct packet_reg
**remote_regs
;
604 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
606 struct packet_reg
*r
= ®s
[regnum
];
608 if (register_size (gdbarch
, regnum
) == 0)
609 /* Do not try to fetch zero-sized (placeholder) registers. */
612 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
617 /* Define the g/G packet format as the contents of each register
618 with a remote protocol number, in order of ascending protocol
621 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
622 * sizeof (struct packet_reg
*));
623 for (num_remote_regs
= 0, regnum
= 0;
624 regnum
< gdbarch_num_regs (gdbarch
);
626 if (regs
[regnum
].pnum
!= -1)
627 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
629 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
632 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
634 remote_regs
[regnum
]->in_g_packet
= 1;
635 remote_regs
[regnum
]->offset
= offset
;
636 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
642 /* Given the architecture described by GDBARCH, return the remote
643 protocol register's number and the register's offset in the g/G
644 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
645 If the target does not have a mapping for REGNUM, return false,
646 otherwise, return true. */
649 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
650 int *pnum
, int *poffset
)
653 struct packet_reg
*regs
;
654 struct cleanup
*old_chain
;
656 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
658 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
659 old_chain
= make_cleanup (xfree
, regs
);
661 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
663 *pnum
= regs
[regnum
].pnum
;
664 *poffset
= regs
[regnum
].offset
;
666 do_cleanups (old_chain
);
672 init_remote_state (struct gdbarch
*gdbarch
)
674 struct remote_state
*rs
= get_remote_state_raw ();
675 struct remote_arch_state
*rsa
;
677 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
679 /* Use the architecture to build a regnum<->pnum table, which will be
680 1:1 unless a feature set specifies otherwise. */
681 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
682 gdbarch_num_regs (gdbarch
),
685 /* Record the maximum possible size of the g packet - it may turn out
687 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
689 /* Default maximum number of characters in a packet body. Many
690 remote stubs have a hardwired buffer size of 400 bytes
691 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
692 as the maximum packet-size to ensure that the packet and an extra
693 NUL character can always fit in the buffer. This stops GDB
694 trashing stubs that try to squeeze an extra NUL into what is
695 already a full buffer (As of 1999-12-04 that was most stubs). */
696 rsa
->remote_packet_size
= 400 - 1;
698 /* This one is filled in when a ``g'' packet is received. */
699 rsa
->actual_register_packet_size
= 0;
701 /* Should rsa->sizeof_g_packet needs more space than the
702 default, adjust the size accordingly. Remember that each byte is
703 encoded as two characters. 32 is the overhead for the packet
704 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
705 (``$NN:G...#NN'') is a better guess, the below has been padded a
707 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
708 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
710 /* Make sure that the packet buffer is plenty big enough for
711 this architecture. */
712 if (rs
->buf_size
< rsa
->remote_packet_size
)
714 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
715 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
721 /* Return the current allowed size of a remote packet. This is
722 inferred from the current architecture, and should be used to
723 limit the length of outgoing packets. */
725 get_remote_packet_size (void)
727 struct remote_state
*rs
= get_remote_state ();
728 struct remote_arch_state
*rsa
= get_remote_arch_state ();
730 if (rs
->explicit_packet_size
)
731 return rs
->explicit_packet_size
;
733 return rsa
->remote_packet_size
;
736 static struct packet_reg
*
737 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
739 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
743 struct packet_reg
*r
= &rsa
->regs
[regnum
];
745 gdb_assert (r
->regnum
== regnum
);
750 static struct packet_reg
*
751 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
755 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
757 struct packet_reg
*r
= &rsa
->regs
[i
];
765 static struct target_ops remote_ops
;
767 static struct target_ops extended_remote_ops
;
769 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
770 ``forever'' still use the normal timeout mechanism. This is
771 currently used by the ASYNC code to guarentee that target reads
772 during the initial connect always time-out. Once getpkt has been
773 modified to return a timeout indication and, in turn
774 remote_wait()/wait_for_inferior() have gained a timeout parameter
776 static int wait_forever_enabled_p
= 1;
778 /* Allow the user to specify what sequence to send to the remote
779 when he requests a program interruption: Although ^C is usually
780 what remote systems expect (this is the default, here), it is
781 sometimes preferable to send a break. On other systems such
782 as the Linux kernel, a break followed by g, which is Magic SysRq g
783 is required in order to interrupt the execution. */
784 const char interrupt_sequence_control_c
[] = "Ctrl-C";
785 const char interrupt_sequence_break
[] = "BREAK";
786 const char interrupt_sequence_break_g
[] = "BREAK-g";
787 static const char *const interrupt_sequence_modes
[] =
789 interrupt_sequence_control_c
,
790 interrupt_sequence_break
,
791 interrupt_sequence_break_g
,
794 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
797 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
798 struct cmd_list_element
*c
,
801 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
802 fprintf_filtered (file
,
803 _("Send the ASCII ETX character (Ctrl-c) "
804 "to the remote target to interrupt the "
805 "execution of the program.\n"));
806 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
807 fprintf_filtered (file
,
808 _("send a break signal to the remote target "
809 "to interrupt the execution of the program.\n"));
810 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
811 fprintf_filtered (file
,
812 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
813 "the remote target to interrupt the execution "
814 "of Linux kernel.\n"));
816 internal_error (__FILE__
, __LINE__
,
817 _("Invalid value for interrupt_sequence_mode: %s."),
818 interrupt_sequence_mode
);
821 /* This boolean variable specifies whether interrupt_sequence is sent
822 to the remote target when gdb connects to it.
823 This is mostly needed when you debug the Linux kernel: The Linux kernel
824 expects BREAK g which is Magic SysRq g for connecting gdb. */
825 static int interrupt_on_connect
= 0;
827 /* This variable is used to implement the "set/show remotebreak" commands.
828 Since these commands are now deprecated in favor of "set/show remote
829 interrupt-sequence", it no longer has any effect on the code. */
830 static int remote_break
;
833 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
836 interrupt_sequence_mode
= interrupt_sequence_break
;
838 interrupt_sequence_mode
= interrupt_sequence_control_c
;
842 show_remotebreak (struct ui_file
*file
, int from_tty
,
843 struct cmd_list_element
*c
,
848 /* This variable sets the number of bits in an address that are to be
849 sent in a memory ("M" or "m") packet. Normally, after stripping
850 leading zeros, the entire address would be sent. This variable
851 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
852 initial implementation of remote.c restricted the address sent in
853 memory packets to ``host::sizeof long'' bytes - (typically 32
854 bits). Consequently, for 64 bit targets, the upper 32 bits of an
855 address was never sent. Since fixing this bug may cause a break in
856 some remote targets this variable is principly provided to
857 facilitate backward compatibility. */
859 static unsigned int remote_address_size
;
861 /* Temporary to track who currently owns the terminal. See
862 remote_terminal_* for more details. */
864 static int remote_async_terminal_ours_p
;
866 /* The executable file to use for "run" on the remote side. */
868 static char *remote_exec_file
= "";
871 /* User configurable variables for the number of characters in a
872 memory read/write packet. MIN (rsa->remote_packet_size,
873 rsa->sizeof_g_packet) is the default. Some targets need smaller
874 values (fifo overruns, et.al.) and some users need larger values
875 (speed up transfers). The variables ``preferred_*'' (the user
876 request), ``current_*'' (what was actually set) and ``forced_*''
877 (Positive - a soft limit, negative - a hard limit). */
879 struct memory_packet_config
886 /* Compute the current size of a read/write packet. Since this makes
887 use of ``actual_register_packet_size'' the computation is dynamic. */
890 get_memory_packet_size (struct memory_packet_config
*config
)
892 struct remote_state
*rs
= get_remote_state ();
893 struct remote_arch_state
*rsa
= get_remote_arch_state ();
895 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
896 law?) that some hosts don't cope very well with large alloca()
897 calls. Eventually the alloca() code will be replaced by calls to
898 xmalloc() and make_cleanups() allowing this restriction to either
899 be lifted or removed. */
900 #ifndef MAX_REMOTE_PACKET_SIZE
901 #define MAX_REMOTE_PACKET_SIZE 16384
903 /* NOTE: 20 ensures we can write at least one byte. */
904 #ifndef MIN_REMOTE_PACKET_SIZE
905 #define MIN_REMOTE_PACKET_SIZE 20
910 if (config
->size
<= 0)
911 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
913 what_they_get
= config
->size
;
917 what_they_get
= get_remote_packet_size ();
918 /* Limit the packet to the size specified by the user. */
920 && what_they_get
> config
->size
)
921 what_they_get
= config
->size
;
923 /* Limit it to the size of the targets ``g'' response unless we have
924 permission from the stub to use a larger packet size. */
925 if (rs
->explicit_packet_size
== 0
926 && rsa
->actual_register_packet_size
> 0
927 && what_they_get
> rsa
->actual_register_packet_size
)
928 what_they_get
= rsa
->actual_register_packet_size
;
930 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
931 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
932 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
933 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
935 /* Make sure there is room in the global buffer for this packet
936 (including its trailing NUL byte). */
937 if (rs
->buf_size
< what_they_get
+ 1)
939 rs
->buf_size
= 2 * what_they_get
;
940 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
943 return what_they_get
;
946 /* Update the size of a read/write packet. If they user wants
947 something really big then do a sanity check. */
950 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
952 int fixed_p
= config
->fixed_p
;
953 long size
= config
->size
;
956 error (_("Argument required (integer, `fixed' or `limited')."));
957 else if (strcmp (args
, "hard") == 0
958 || strcmp (args
, "fixed") == 0)
960 else if (strcmp (args
, "soft") == 0
961 || strcmp (args
, "limit") == 0)
967 size
= strtoul (args
, &end
, 0);
969 error (_("Invalid %s (bad syntax)."), config
->name
);
971 /* Instead of explicitly capping the size of a packet to
972 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
973 instead allowed to set the size to something arbitrarily
975 if (size
> MAX_REMOTE_PACKET_SIZE
)
976 error (_("Invalid %s (too large)."), config
->name
);
980 if (fixed_p
&& !config
->fixed_p
)
982 if (! query (_("The target may not be able to correctly handle a %s\n"
983 "of %ld bytes. Change the packet size? "),
985 error (_("Packet size not changed."));
987 /* Update the config. */
988 config
->fixed_p
= fixed_p
;
993 show_memory_packet_size (struct memory_packet_config
*config
)
995 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
997 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
998 get_memory_packet_size (config
));
1000 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1001 get_memory_packet_size (config
));
1004 static struct memory_packet_config memory_write_packet_config
=
1006 "memory-write-packet-size",
1010 set_memory_write_packet_size (char *args
, int from_tty
)
1012 set_memory_packet_size (args
, &memory_write_packet_config
);
1016 show_memory_write_packet_size (char *args
, int from_tty
)
1018 show_memory_packet_size (&memory_write_packet_config
);
1022 get_memory_write_packet_size (void)
1024 return get_memory_packet_size (&memory_write_packet_config
);
1027 static struct memory_packet_config memory_read_packet_config
=
1029 "memory-read-packet-size",
1033 set_memory_read_packet_size (char *args
, int from_tty
)
1035 set_memory_packet_size (args
, &memory_read_packet_config
);
1039 show_memory_read_packet_size (char *args
, int from_tty
)
1041 show_memory_packet_size (&memory_read_packet_config
);
1045 get_memory_read_packet_size (void)
1047 long size
= get_memory_packet_size (&memory_read_packet_config
);
1049 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1050 extra buffer size argument before the memory read size can be
1051 increased beyond this. */
1052 if (size
> get_remote_packet_size ())
1053 size
= get_remote_packet_size ();
1058 /* Generic configuration support for packets the stub optionally
1059 supports. Allows the user to specify the use of the packet as well
1060 as allowing GDB to auto-detect support in the remote stub. */
1064 PACKET_SUPPORT_UNKNOWN
= 0,
1069 struct packet_config
1074 /* If auto, GDB auto-detects support for this packet or feature,
1075 either through qSupported, or by trying the packet and looking
1076 at the response. If true, GDB assumes the target supports this
1077 packet. If false, the packet is disabled. Configs that don't
1078 have an associated command always have this set to auto. */
1079 enum auto_boolean detect
;
1081 /* Does the target support this packet? */
1082 enum packet_support support
;
1085 /* Analyze a packet's return value and update the packet config
1095 static enum packet_support
packet_config_support (struct packet_config
*config
);
1096 static enum packet_support
packet_support (int packet
);
1099 show_packet_config_cmd (struct packet_config
*config
)
1101 char *support
= "internal-error";
1103 switch (packet_config_support (config
))
1106 support
= "enabled";
1108 case PACKET_DISABLE
:
1109 support
= "disabled";
1111 case PACKET_SUPPORT_UNKNOWN
:
1112 support
= "unknown";
1115 switch (config
->detect
)
1117 case AUTO_BOOLEAN_AUTO
:
1118 printf_filtered (_("Support for the `%s' packet "
1119 "is auto-detected, currently %s.\n"),
1120 config
->name
, support
);
1122 case AUTO_BOOLEAN_TRUE
:
1123 case AUTO_BOOLEAN_FALSE
:
1124 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1125 config
->name
, support
);
1131 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1132 const char *title
, int legacy
)
1138 config
->name
= name
;
1139 config
->title
= title
;
1140 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1142 show_doc
= xstrprintf ("Show current use of remote "
1143 "protocol `%s' (%s) packet",
1145 /* set/show TITLE-packet {auto,on,off} */
1146 cmd_name
= xstrprintf ("%s-packet", title
);
1147 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1148 &config
->detect
, set_doc
,
1149 show_doc
, NULL
, /* help_doc */
1151 show_remote_protocol_packet_cmd
,
1152 &remote_set_cmdlist
, &remote_show_cmdlist
);
1153 /* The command code copies the documentation strings. */
1156 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1161 legacy_name
= xstrprintf ("%s-packet", name
);
1162 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1163 &remote_set_cmdlist
);
1164 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1165 &remote_show_cmdlist
);
1169 static enum packet_result
1170 packet_check_result (const char *buf
)
1174 /* The stub recognized the packet request. Check that the
1175 operation succeeded. */
1177 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1179 /* "Enn" - definitly an error. */
1180 return PACKET_ERROR
;
1182 /* Always treat "E." as an error. This will be used for
1183 more verbose error messages, such as E.memtypes. */
1184 if (buf
[0] == 'E' && buf
[1] == '.')
1185 return PACKET_ERROR
;
1187 /* The packet may or may not be OK. Just assume it is. */
1191 /* The stub does not support the packet. */
1192 return PACKET_UNKNOWN
;
1195 static enum packet_result
1196 packet_ok (const char *buf
, struct packet_config
*config
)
1198 enum packet_result result
;
1200 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1201 && config
->support
== PACKET_DISABLE
)
1202 internal_error (__FILE__
, __LINE__
,
1203 _("packet_ok: attempt to use a disabled packet"));
1205 result
= packet_check_result (buf
);
1210 /* The stub recognized the packet request. */
1211 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1214 fprintf_unfiltered (gdb_stdlog
,
1215 "Packet %s (%s) is supported\n",
1216 config
->name
, config
->title
);
1217 config
->support
= PACKET_ENABLE
;
1220 case PACKET_UNKNOWN
:
1221 /* The stub does not support the packet. */
1222 if (config
->detect
== AUTO_BOOLEAN_AUTO
1223 && config
->support
== PACKET_ENABLE
)
1225 /* If the stub previously indicated that the packet was
1226 supported then there is a protocol error. */
1227 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1228 config
->name
, config
->title
);
1230 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1232 /* The user set it wrong. */
1233 error (_("Enabled packet %s (%s) not recognized by stub"),
1234 config
->name
, config
->title
);
1238 fprintf_unfiltered (gdb_stdlog
,
1239 "Packet %s (%s) is NOT supported\n",
1240 config
->name
, config
->title
);
1241 config
->support
= PACKET_DISABLE
;
1262 PACKET_vFile_pwrite
,
1264 PACKET_vFile_unlink
,
1265 PACKET_vFile_readlink
,
1268 PACKET_qXfer_features
,
1269 PACKET_qXfer_exec_file
,
1270 PACKET_qXfer_libraries
,
1271 PACKET_qXfer_libraries_svr4
,
1272 PACKET_qXfer_memory_map
,
1273 PACKET_qXfer_spu_read
,
1274 PACKET_qXfer_spu_write
,
1275 PACKET_qXfer_osdata
,
1276 PACKET_qXfer_threads
,
1277 PACKET_qXfer_statictrace_read
,
1278 PACKET_qXfer_traceframe_info
,
1284 PACKET_QPassSignals
,
1285 PACKET_QProgramSignals
,
1287 PACKET_qSearch_memory
,
1290 PACKET_QStartNoAckMode
,
1292 PACKET_qXfer_siginfo_read
,
1293 PACKET_qXfer_siginfo_write
,
1296 /* Support for conditional tracepoints. */
1297 PACKET_ConditionalTracepoints
,
1299 /* Support for target-side breakpoint conditions. */
1300 PACKET_ConditionalBreakpoints
,
1302 /* Support for target-side breakpoint commands. */
1303 PACKET_BreakpointCommands
,
1305 /* Support for fast tracepoints. */
1306 PACKET_FastTracepoints
,
1308 /* Support for static tracepoints. */
1309 PACKET_StaticTracepoints
,
1311 /* Support for installing tracepoints while a trace experiment is
1313 PACKET_InstallInTrace
,
1317 PACKET_TracepointSource
,
1320 PACKET_QDisableRandomization
,
1322 PACKET_QTBuffer_size
,
1326 PACKET_qXfer_btrace
,
1328 /* Support for the QNonStop packet. */
1331 /* Support for multi-process extensions. */
1332 PACKET_multiprocess_feature
,
1334 /* Support for enabling and disabling tracepoints while a trace
1335 experiment is running. */
1336 PACKET_EnableDisableTracepoints_feature
,
1338 /* Support for collecting strings using the tracenz bytecode. */
1339 PACKET_tracenz_feature
,
1341 /* Support for continuing to run a trace experiment while GDB is
1343 PACKET_DisconnectedTracing_feature
,
1345 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1346 PACKET_augmented_libraries_svr4_read_feature
,
1348 /* Support for the qXfer:btrace-conf:read packet. */
1349 PACKET_qXfer_btrace_conf
,
1351 /* Support for the Qbtrace-conf:bts:size packet. */
1352 PACKET_Qbtrace_conf_bts_size
,
1354 /* Support for swbreak+ feature. */
1355 PACKET_swbreak_feature
,
1357 /* Support for hwbreak+ feature. */
1358 PACKET_hwbreak_feature
,
1360 /* Support for fork events. */
1361 PACKET_fork_event_feature
,
1363 /* Support for vfork events. */
1364 PACKET_vfork_event_feature
,
1366 /* Support for the Qbtrace-conf:pt:size packet. */
1367 PACKET_Qbtrace_conf_pt_size
,
1372 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1374 /* Returns the packet's corresponding "set remote foo-packet" command
1375 state. See struct packet_config for more details. */
1377 static enum auto_boolean
1378 packet_set_cmd_state (int packet
)
1380 return remote_protocol_packets
[packet
].detect
;
1383 /* Returns whether a given packet or feature is supported. This takes
1384 into account the state of the corresponding "set remote foo-packet"
1385 command, which may be used to bypass auto-detection. */
1387 static enum packet_support
1388 packet_config_support (struct packet_config
*config
)
1390 switch (config
->detect
)
1392 case AUTO_BOOLEAN_TRUE
:
1393 return PACKET_ENABLE
;
1394 case AUTO_BOOLEAN_FALSE
:
1395 return PACKET_DISABLE
;
1396 case AUTO_BOOLEAN_AUTO
:
1397 return config
->support
;
1399 gdb_assert_not_reached (_("bad switch"));
1403 /* Same as packet_config_support, but takes the packet's enum value as
1406 static enum packet_support
1407 packet_support (int packet
)
1409 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1411 return packet_config_support (config
);
1415 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1416 struct cmd_list_element
*c
,
1419 struct packet_config
*packet
;
1421 for (packet
= remote_protocol_packets
;
1422 packet
< &remote_protocol_packets
[PACKET_MAX
];
1425 if (&packet
->detect
== c
->var
)
1427 show_packet_config_cmd (packet
);
1431 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1435 /* Should we try one of the 'Z' requests? */
1439 Z_PACKET_SOFTWARE_BP
,
1440 Z_PACKET_HARDWARE_BP
,
1447 /* For compatibility with older distributions. Provide a ``set remote
1448 Z-packet ...'' command that updates all the Z packet types. */
1450 static enum auto_boolean remote_Z_packet_detect
;
1453 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1454 struct cmd_list_element
*c
)
1458 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1459 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1463 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1464 struct cmd_list_element
*c
,
1469 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1471 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1475 /* Returns true if the multi-process extensions are in effect. */
1478 remote_multi_process_p (struct remote_state
*rs
)
1480 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1483 /* Returns true if fork events are supported. */
1486 remote_fork_event_p (struct remote_state
*rs
)
1488 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1491 /* Returns true if vfork events are supported. */
1494 remote_vfork_event_p (struct remote_state
*rs
)
1496 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1499 /* Insert fork catchpoint target routine. If fork events are enabled
1500 then return success, nothing more to do. */
1503 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1505 struct remote_state
*rs
= get_remote_state ();
1507 return !remote_fork_event_p (rs
);
1510 /* Remove fork catchpoint target routine. Nothing to do, just
1514 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1519 /* Insert vfork catchpoint target routine. If vfork events are enabled
1520 then return success, nothing more to do. */
1523 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1525 struct remote_state
*rs
= get_remote_state ();
1527 return !remote_vfork_event_p (rs
);
1530 /* Remove vfork catchpoint target routine. Nothing to do, just
1534 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1539 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1540 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1541 static struct async_signal_handler
*async_sigint_remote_token
;
1544 /* Asynchronous signal handle registered as event loop source for
1545 when we have pending events ready to be passed to the core. */
1547 static struct async_event_handler
*remote_async_inferior_event_token
;
1551 static ptid_t magic_null_ptid
;
1552 static ptid_t not_sent_ptid
;
1553 static ptid_t any_thread_ptid
;
1555 /* Find out if the stub attached to PID (and hence GDB should offer to
1556 detach instead of killing it when bailing out). */
1559 remote_query_attached (int pid
)
1561 struct remote_state
*rs
= get_remote_state ();
1562 size_t size
= get_remote_packet_size ();
1564 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1567 if (remote_multi_process_p (rs
))
1568 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1570 xsnprintf (rs
->buf
, size
, "qAttached");
1573 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1575 switch (packet_ok (rs
->buf
,
1576 &remote_protocol_packets
[PACKET_qAttached
]))
1579 if (strcmp (rs
->buf
, "1") == 0)
1583 warning (_("Remote failure reply: %s"), rs
->buf
);
1585 case PACKET_UNKNOWN
:
1592 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1593 has been invented by GDB, instead of reported by the target. Since
1594 we can be connected to a remote system before before knowing about
1595 any inferior, mark the target with execution when we find the first
1596 inferior. If ATTACHED is 1, then we had just attached to this
1597 inferior. If it is 0, then we just created this inferior. If it
1598 is -1, then try querying the remote stub to find out if it had
1599 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1600 attempt to open this inferior's executable as the main executable
1601 if no main executable is open already. */
1603 static struct inferior
*
1604 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1607 struct inferior
*inf
;
1609 /* Check whether this process we're learning about is to be
1610 considered attached, or if is to be considered to have been
1611 spawned by the stub. */
1613 attached
= remote_query_attached (pid
);
1615 if (gdbarch_has_global_solist (target_gdbarch ()))
1617 /* If the target shares code across all inferiors, then every
1618 attach adds a new inferior. */
1619 inf
= add_inferior (pid
);
1621 /* ... and every inferior is bound to the same program space.
1622 However, each inferior may still have its own address
1624 inf
->aspace
= maybe_new_address_space ();
1625 inf
->pspace
= current_program_space
;
1629 /* In the traditional debugging scenario, there's a 1-1 match
1630 between program/address spaces. We simply bind the inferior
1631 to the program space's address space. */
1632 inf
= current_inferior ();
1633 inferior_appeared (inf
, pid
);
1636 inf
->attach_flag
= attached
;
1637 inf
->fake_pid_p
= fake_pid_p
;
1639 /* If no main executable is currently open then attempt to
1640 open the file that was executed to create this inferior. */
1641 if (try_open_exec
&& get_exec_file (0) == NULL
)
1642 exec_file_locate_attach (pid
, 1);
1647 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1648 according to RUNNING. */
1651 remote_add_thread (ptid_t ptid
, int running
)
1653 struct remote_state
*rs
= get_remote_state ();
1655 /* GDB historically didn't pull threads in the initial connection
1656 setup. If the remote target doesn't even have a concept of
1657 threads (e.g., a bare-metal target), even if internally we
1658 consider that a single-threaded target, mentioning a new thread
1659 might be confusing to the user. Be silent then, preserving the
1660 age old behavior. */
1661 if (rs
->starting_up
)
1662 add_thread_silent (ptid
);
1666 set_executing (ptid
, running
);
1667 set_running (ptid
, running
);
1670 /* Come here when we learn about a thread id from the remote target.
1671 It may be the first time we hear about such thread, so take the
1672 opportunity to add it to GDB's thread list. In case this is the
1673 first time we're noticing its corresponding inferior, add it to
1674 GDB's inferior list as well. */
1677 remote_notice_new_inferior (ptid_t currthread
, int running
)
1679 /* If this is a new thread, add it to GDB's thread list.
1680 If we leave it up to WFI to do this, bad things will happen. */
1682 if (in_thread_list (currthread
) && is_exited (currthread
))
1684 /* We're seeing an event on a thread id we knew had exited.
1685 This has to be a new thread reusing the old id. Add it. */
1686 remote_add_thread (currthread
, running
);
1690 if (!in_thread_list (currthread
))
1692 struct inferior
*inf
= NULL
;
1693 int pid
= ptid_get_pid (currthread
);
1695 if (ptid_is_pid (inferior_ptid
)
1696 && pid
== ptid_get_pid (inferior_ptid
))
1698 /* inferior_ptid has no thread member yet. This can happen
1699 with the vAttach -> remote_wait,"TAAthread:" path if the
1700 stub doesn't support qC. This is the first stop reported
1701 after an attach, so this is the main thread. Update the
1702 ptid in the thread list. */
1703 if (in_thread_list (pid_to_ptid (pid
)))
1704 thread_change_ptid (inferior_ptid
, currthread
);
1707 remote_add_thread (currthread
, running
);
1708 inferior_ptid
= currthread
;
1713 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1715 /* inferior_ptid is not set yet. This can happen with the
1716 vRun -> remote_wait,"TAAthread:" path if the stub
1717 doesn't support qC. This is the first stop reported
1718 after an attach, so this is the main thread. Update the
1719 ptid in the thread list. */
1720 thread_change_ptid (inferior_ptid
, currthread
);
1724 /* When connecting to a target remote, or to a target
1725 extended-remote which already was debugging an inferior, we
1726 may not know about it yet. Add it before adding its child
1727 thread, so notifications are emitted in a sensible order. */
1728 if (!in_inferior_list (ptid_get_pid (currthread
)))
1730 struct remote_state
*rs
= get_remote_state ();
1731 int fake_pid_p
= !remote_multi_process_p (rs
);
1733 inf
= remote_add_inferior (fake_pid_p
,
1734 ptid_get_pid (currthread
), -1, 1);
1737 /* This is really a new thread. Add it. */
1738 remote_add_thread (currthread
, running
);
1740 /* If we found a new inferior, let the common code do whatever
1741 it needs to with it (e.g., read shared libraries, insert
1742 breakpoints), unless we're just setting up an all-stop
1746 struct remote_state
*rs
= get_remote_state ();
1748 if (non_stop
|| !rs
->starting_up
)
1749 notice_new_inferior (currthread
, running
, 0);
1754 /* Return the private thread data, creating it if necessary. */
1756 static struct private_thread_info
*
1757 demand_private_info (ptid_t ptid
)
1759 struct thread_info
*info
= find_thread_ptid (ptid
);
1765 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1766 info
->private_dtor
= free_private_thread_info
;
1767 info
->priv
->core
= -1;
1768 info
->priv
->extra
= 0;
1774 /* Call this function as a result of
1775 1) A halt indication (T packet) containing a thread id
1776 2) A direct query of currthread
1777 3) Successful execution of set thread */
1780 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1782 rs
->general_thread
= currthread
;
1785 /* If 'QPassSignals' is supported, tell the remote stub what signals
1786 it can simply pass through to the inferior without reporting. */
1789 remote_pass_signals (struct target_ops
*self
,
1790 int numsigs
, unsigned char *pass_signals
)
1792 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1794 char *pass_packet
, *p
;
1796 struct remote_state
*rs
= get_remote_state ();
1798 gdb_assert (numsigs
< 256);
1799 for (i
= 0; i
< numsigs
; i
++)
1801 if (pass_signals
[i
])
1804 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1805 strcpy (pass_packet
, "QPassSignals:");
1806 p
= pass_packet
+ strlen (pass_packet
);
1807 for (i
= 0; i
< numsigs
; i
++)
1809 if (pass_signals
[i
])
1812 *p
++ = tohex (i
>> 4);
1813 *p
++ = tohex (i
& 15);
1822 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1824 putpkt (pass_packet
);
1825 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1826 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1827 if (rs
->last_pass_packet
)
1828 xfree (rs
->last_pass_packet
);
1829 rs
->last_pass_packet
= pass_packet
;
1832 xfree (pass_packet
);
1836 /* If 'QProgramSignals' is supported, tell the remote stub what
1837 signals it should pass through to the inferior when detaching. */
1840 remote_program_signals (struct target_ops
*self
,
1841 int numsigs
, unsigned char *signals
)
1843 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1847 struct remote_state
*rs
= get_remote_state ();
1849 gdb_assert (numsigs
< 256);
1850 for (i
= 0; i
< numsigs
; i
++)
1855 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1856 strcpy (packet
, "QProgramSignals:");
1857 p
= packet
+ strlen (packet
);
1858 for (i
= 0; i
< numsigs
; i
++)
1860 if (signal_pass_state (i
))
1863 *p
++ = tohex (i
>> 4);
1864 *p
++ = tohex (i
& 15);
1873 if (!rs
->last_program_signals_packet
1874 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1877 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1878 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1879 xfree (rs
->last_program_signals_packet
);
1880 rs
->last_program_signals_packet
= packet
;
1887 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1888 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1889 thread. If GEN is set, set the general thread, if not, then set
1890 the step/continue thread. */
1892 set_thread (struct ptid ptid
, int gen
)
1894 struct remote_state
*rs
= get_remote_state ();
1895 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1896 char *buf
= rs
->buf
;
1897 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1899 if (ptid_equal (state
, ptid
))
1903 *buf
++ = gen
? 'g' : 'c';
1904 if (ptid_equal (ptid
, magic_null_ptid
))
1905 xsnprintf (buf
, endbuf
- buf
, "0");
1906 else if (ptid_equal (ptid
, any_thread_ptid
))
1907 xsnprintf (buf
, endbuf
- buf
, "0");
1908 else if (ptid_equal (ptid
, minus_one_ptid
))
1909 xsnprintf (buf
, endbuf
- buf
, "-1");
1911 write_ptid (buf
, endbuf
, ptid
);
1913 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1915 rs
->general_thread
= ptid
;
1917 rs
->continue_thread
= ptid
;
1921 set_general_thread (struct ptid ptid
)
1923 set_thread (ptid
, 1);
1927 set_continue_thread (struct ptid ptid
)
1929 set_thread (ptid
, 0);
1932 /* Change the remote current process. Which thread within the process
1933 ends up selected isn't important, as long as it is the same process
1934 as what INFERIOR_PTID points to.
1936 This comes from that fact that there is no explicit notion of
1937 "selected process" in the protocol. The selected process for
1938 general operations is the process the selected general thread
1942 set_general_process (void)
1944 struct remote_state
*rs
= get_remote_state ();
1946 /* If the remote can't handle multiple processes, don't bother. */
1947 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1950 /* We only need to change the remote current thread if it's pointing
1951 at some other process. */
1952 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1953 set_general_thread (inferior_ptid
);
1957 /* Return nonzero if this is the main thread that we made up ourselves
1958 to model non-threaded targets as single-threaded. */
1961 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
1963 struct remote_state
*rs
= get_remote_state ();
1966 if (ptid_equal (ptid
, magic_null_ptid
))
1967 /* The main thread is always alive. */
1970 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1971 /* The main thread is always alive. This can happen after a
1972 vAttach, if the remote side doesn't support
1979 /* Return nonzero if the thread PTID is still alive on the remote
1983 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1985 struct remote_state
*rs
= get_remote_state ();
1988 /* Check if this is a thread that we made up ourselves to model
1989 non-threaded targets as single-threaded. */
1990 if (remote_thread_always_alive (ops
, ptid
))
1994 endp
= rs
->buf
+ get_remote_packet_size ();
1997 write_ptid (p
, endp
, ptid
);
2000 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2001 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2004 /* About these extended threadlist and threadinfo packets. They are
2005 variable length packets but, the fields within them are often fixed
2006 length. They are redundent enough to send over UDP as is the
2007 remote protocol in general. There is a matching unit test module
2010 /* WARNING: This threadref data structure comes from the remote O.S.,
2011 libstub protocol encoding, and remote.c. It is not particularly
2014 /* Right now, the internal structure is int. We want it to be bigger.
2015 Plan to fix this. */
2017 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2019 /* gdb_ext_thread_info is an internal GDB data structure which is
2020 equivalent to the reply of the remote threadinfo packet. */
2022 struct gdb_ext_thread_info
2024 threadref threadid
; /* External form of thread reference. */
2025 int active
; /* Has state interesting to GDB?
2027 char display
[256]; /* Brief state display, name,
2028 blocked/suspended. */
2029 char shortname
[32]; /* To be used to name threads. */
2030 char more_display
[256]; /* Long info, statistics, queue depth,
2034 /* The volume of remote transfers can be limited by submitting
2035 a mask containing bits specifying the desired information.
2036 Use a union of these values as the 'selection' parameter to
2037 get_thread_info. FIXME: Make these TAG names more thread specific. */
2039 #define TAG_THREADID 1
2040 #define TAG_EXISTS 2
2041 #define TAG_DISPLAY 4
2042 #define TAG_THREADNAME 8
2043 #define TAG_MOREDISPLAY 16
2045 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2047 static char *unpack_nibble (char *buf
, int *val
);
2049 static char *unpack_byte (char *buf
, int *value
);
2051 static char *pack_int (char *buf
, int value
);
2053 static char *unpack_int (char *buf
, int *value
);
2055 static char *unpack_string (char *src
, char *dest
, int length
);
2057 static char *pack_threadid (char *pkt
, threadref
*id
);
2059 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2061 void int_to_threadref (threadref
*id
, int value
);
2063 static int threadref_to_int (threadref
*ref
);
2065 static void copy_threadref (threadref
*dest
, threadref
*src
);
2067 static int threadmatch (threadref
*dest
, threadref
*src
);
2069 static char *pack_threadinfo_request (char *pkt
, int mode
,
2072 static int remote_unpack_thread_info_response (char *pkt
,
2073 threadref
*expectedref
,
2074 struct gdb_ext_thread_info
2078 static int remote_get_threadinfo (threadref
*threadid
,
2079 int fieldset
, /*TAG mask */
2080 struct gdb_ext_thread_info
*info
);
2082 static char *pack_threadlist_request (char *pkt
, int startflag
,
2084 threadref
*nextthread
);
2086 static int parse_threadlist_response (char *pkt
,
2088 threadref
*original_echo
,
2089 threadref
*resultlist
,
2092 static int remote_get_threadlist (int startflag
,
2093 threadref
*nextthread
,
2097 threadref
*threadlist
);
2099 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2101 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2102 void *context
, int looplimit
);
2104 static int remote_newthread_step (threadref
*ref
, void *context
);
2107 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2108 buffer we're allowed to write to. Returns
2109 BUF+CHARACTERS_WRITTEN. */
2112 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2115 struct remote_state
*rs
= get_remote_state ();
2117 if (remote_multi_process_p (rs
))
2119 pid
= ptid_get_pid (ptid
);
2121 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2123 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2125 tid
= ptid_get_lwp (ptid
);
2127 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2129 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2134 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2135 passed the last parsed char. Returns null_ptid on error. */
2138 read_ptid (char *buf
, char **obuf
)
2142 ULONGEST pid
= 0, tid
= 0;
2146 /* Multi-process ptid. */
2147 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2149 error (_("invalid remote ptid: %s"), p
);
2152 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2155 return ptid_build (pid
, tid
, 0);
2158 /* No multi-process. Just a tid. */
2159 pp
= unpack_varlen_hex (p
, &tid
);
2161 /* Return null_ptid when no thread id is found. */
2169 /* Since the stub is not sending a process id, then default to
2170 what's in inferior_ptid, unless it's null at this point. If so,
2171 then since there's no way to know the pid of the reported
2172 threads, use the magic number. */
2173 if (ptid_equal (inferior_ptid
, null_ptid
))
2174 pid
= ptid_get_pid (magic_null_ptid
);
2176 pid
= ptid_get_pid (inferior_ptid
);
2180 return ptid_build (pid
, tid
, 0);
2186 if (ch
>= 'a' && ch
<= 'f')
2187 return ch
- 'a' + 10;
2188 if (ch
>= '0' && ch
<= '9')
2190 if (ch
>= 'A' && ch
<= 'F')
2191 return ch
- 'A' + 10;
2196 stub_unpack_int (char *buff
, int fieldlength
)
2203 nibble
= stubhex (*buff
++);
2207 retval
= retval
<< 4;
2213 unpack_nibble (char *buf
, int *val
)
2215 *val
= fromhex (*buf
++);
2220 unpack_byte (char *buf
, int *value
)
2222 *value
= stub_unpack_int (buf
, 2);
2227 pack_int (char *buf
, int value
)
2229 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2230 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2231 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2232 buf
= pack_hex_byte (buf
, (value
& 0xff));
2237 unpack_int (char *buf
, int *value
)
2239 *value
= stub_unpack_int (buf
, 8);
2243 #if 0 /* Currently unused, uncomment when needed. */
2244 static char *pack_string (char *pkt
, char *string
);
2247 pack_string (char *pkt
, char *string
)
2252 len
= strlen (string
);
2254 len
= 200; /* Bigger than most GDB packets, junk??? */
2255 pkt
= pack_hex_byte (pkt
, len
);
2259 if ((ch
== '\0') || (ch
== '#'))
2260 ch
= '*'; /* Protect encapsulation. */
2265 #endif /* 0 (unused) */
2268 unpack_string (char *src
, char *dest
, int length
)
2277 pack_threadid (char *pkt
, threadref
*id
)
2280 unsigned char *altid
;
2282 altid
= (unsigned char *) id
;
2283 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2285 pkt
= pack_hex_byte (pkt
, *altid
++);
2291 unpack_threadid (char *inbuf
, threadref
*id
)
2294 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2297 altref
= (char *) id
;
2299 while (inbuf
< limit
)
2301 x
= stubhex (*inbuf
++);
2302 y
= stubhex (*inbuf
++);
2303 *altref
++ = (x
<< 4) | y
;
2308 /* Externally, threadrefs are 64 bits but internally, they are still
2309 ints. This is due to a mismatch of specifications. We would like
2310 to use 64bit thread references internally. This is an adapter
2314 int_to_threadref (threadref
*id
, int value
)
2316 unsigned char *scan
;
2318 scan
= (unsigned char *) id
;
2324 *scan
++ = (value
>> 24) & 0xff;
2325 *scan
++ = (value
>> 16) & 0xff;
2326 *scan
++ = (value
>> 8) & 0xff;
2327 *scan
++ = (value
& 0xff);
2331 threadref_to_int (threadref
*ref
)
2334 unsigned char *scan
;
2340 value
= (value
<< 8) | ((*scan
++) & 0xff);
2345 copy_threadref (threadref
*dest
, threadref
*src
)
2348 unsigned char *csrc
, *cdest
;
2350 csrc
= (unsigned char *) src
;
2351 cdest
= (unsigned char *) dest
;
2358 threadmatch (threadref
*dest
, threadref
*src
)
2360 /* Things are broken right now, so just assume we got a match. */
2362 unsigned char *srcp
, *destp
;
2364 srcp
= (char *) src
;
2365 destp
= (char *) dest
;
2369 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2376 threadid:1, # always request threadid
2383 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2386 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2388 *pkt
++ = 'q'; /* Info Query */
2389 *pkt
++ = 'P'; /* process or thread info */
2390 pkt
= pack_int (pkt
, mode
); /* mode */
2391 pkt
= pack_threadid (pkt
, id
); /* threadid */
2392 *pkt
= '\0'; /* terminate */
2396 /* These values tag the fields in a thread info response packet. */
2397 /* Tagging the fields allows us to request specific fields and to
2398 add more fields as time goes by. */
2400 #define TAG_THREADID 1 /* Echo the thread identifier. */
2401 #define TAG_EXISTS 2 /* Is this process defined enough to
2402 fetch registers and its stack? */
2403 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2404 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2405 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2409 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2410 struct gdb_ext_thread_info
*info
)
2412 struct remote_state
*rs
= get_remote_state ();
2416 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2419 /* info->threadid = 0; FIXME: implement zero_threadref. */
2421 info
->display
[0] = '\0';
2422 info
->shortname
[0] = '\0';
2423 info
->more_display
[0] = '\0';
2425 /* Assume the characters indicating the packet type have been
2427 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2428 pkt
= unpack_threadid (pkt
, &ref
);
2431 warning (_("Incomplete response to threadinfo request."));
2432 if (!threadmatch (&ref
, expectedref
))
2433 { /* This is an answer to a different request. */
2434 warning (_("ERROR RMT Thread info mismatch."));
2437 copy_threadref (&info
->threadid
, &ref
);
2439 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2441 /* Packets are terminated with nulls. */
2442 while ((pkt
< limit
) && mask
&& *pkt
)
2444 pkt
= unpack_int (pkt
, &tag
); /* tag */
2445 pkt
= unpack_byte (pkt
, &length
); /* length */
2446 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2448 warning (_("ERROR RMT: threadinfo tag mismatch."));
2452 if (tag
== TAG_THREADID
)
2456 warning (_("ERROR RMT: length of threadid is not 16."));
2460 pkt
= unpack_threadid (pkt
, &ref
);
2461 mask
= mask
& ~TAG_THREADID
;
2464 if (tag
== TAG_EXISTS
)
2466 info
->active
= stub_unpack_int (pkt
, length
);
2468 mask
= mask
& ~(TAG_EXISTS
);
2471 warning (_("ERROR RMT: 'exists' length too long."));
2477 if (tag
== TAG_THREADNAME
)
2479 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2480 mask
= mask
& ~TAG_THREADNAME
;
2483 if (tag
== TAG_DISPLAY
)
2485 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2486 mask
= mask
& ~TAG_DISPLAY
;
2489 if (tag
== TAG_MOREDISPLAY
)
2491 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2492 mask
= mask
& ~TAG_MOREDISPLAY
;
2495 warning (_("ERROR RMT: unknown thread info tag."));
2496 break; /* Not a tag we know about. */
2502 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2503 struct gdb_ext_thread_info
*info
)
2505 struct remote_state
*rs
= get_remote_state ();
2508 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2510 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2512 if (rs
->buf
[0] == '\0')
2515 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2520 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2523 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2524 threadref
*nextthread
)
2526 *pkt
++ = 'q'; /* info query packet */
2527 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2528 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2529 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2530 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2535 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2538 parse_threadlist_response (char *pkt
, int result_limit
,
2539 threadref
*original_echo
, threadref
*resultlist
,
2542 struct remote_state
*rs
= get_remote_state ();
2544 int count
, resultcount
, done
;
2547 /* Assume the 'q' and 'M chars have been stripped. */
2548 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2549 /* done parse past here */
2550 pkt
= unpack_byte (pkt
, &count
); /* count field */
2551 pkt
= unpack_nibble (pkt
, &done
);
2552 /* The first threadid is the argument threadid. */
2553 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2554 while ((count
-- > 0) && (pkt
< limit
))
2556 pkt
= unpack_threadid (pkt
, resultlist
++);
2557 if (resultcount
++ >= result_limit
)
2565 /* Fetch the next batch of threads from the remote. Returns -1 if the
2566 qL packet is not supported, 0 on error and 1 on success. */
2569 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2570 int *done
, int *result_count
, threadref
*threadlist
)
2572 struct remote_state
*rs
= get_remote_state ();
2575 /* Trancate result limit to be smaller than the packet size. */
2576 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2577 >= get_remote_packet_size ())
2578 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2580 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2582 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2583 if (*rs
->buf
== '\0')
2585 /* Packet not supported. */
2590 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2591 &rs
->echo_nextthread
, threadlist
, done
);
2593 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2595 /* FIXME: This is a good reason to drop the packet. */
2596 /* Possably, there is a duplicate response. */
2598 retransmit immediatly - race conditions
2599 retransmit after timeout - yes
2601 wait for packet, then exit
2603 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2604 return 0; /* I choose simply exiting. */
2606 if (*result_count
<= 0)
2610 warning (_("RMT ERROR : failed to get remote thread list."));
2613 return result
; /* break; */
2615 if (*result_count
> result_limit
)
2618 warning (_("RMT ERROR: threadlist response longer than requested."));
2624 /* Fetch the list of remote threads, with the qL packet, and call
2625 STEPFUNCTION for each thread found. Stops iterating and returns 1
2626 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2627 STEPFUNCTION returns false. If the packet is not supported,
2631 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2634 struct remote_state
*rs
= get_remote_state ();
2635 int done
, i
, result_count
;
2643 if (loopcount
++ > looplimit
)
2646 warning (_("Remote fetch threadlist -infinite loop-."));
2649 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2650 MAXTHREADLISTRESULTS
,
2651 &done
, &result_count
,
2652 rs
->resultthreadlist
);
2655 /* Clear for later iterations. */
2657 /* Setup to resume next batch of thread references, set nextthread. */
2658 if (result_count
>= 1)
2659 copy_threadref (&rs
->nextthread
,
2660 &rs
->resultthreadlist
[result_count
- 1]);
2662 while (result_count
--)
2664 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2674 /* A thread found on the remote target. */
2676 typedef struct thread_item
2678 /* The thread's PTID. */
2681 /* The thread's extra info. May be NULL. */
2684 /* The core the thread was running on. -1 if not known. */
2687 DEF_VEC_O(thread_item_t
);
2689 /* Context passed around to the various methods listing remote
2690 threads. As new threads are found, they're added to the ITEMS
2693 struct threads_listing_context
2695 /* The threads found on the remote target. */
2696 VEC (thread_item_t
) *items
;
2699 /* Discard the contents of the constructed thread listing context. */
2702 clear_threads_listing_context (void *p
)
2704 struct threads_listing_context
*context
= p
;
2706 struct thread_item
*item
;
2708 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2709 xfree (item
->extra
);
2711 VEC_free (thread_item_t
, context
->items
);
2714 /* Remove the thread specified as the related_pid field of WS
2715 from the CONTEXT list. */
2718 threads_listing_context_remove (struct target_waitstatus
*ws
,
2719 struct threads_listing_context
*context
)
2721 struct thread_item
*item
;
2723 ptid_t child_ptid
= ws
->value
.related_pid
;
2725 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2727 if (ptid_equal (item
->ptid
, child_ptid
))
2729 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2736 remote_newthread_step (threadref
*ref
, void *data
)
2738 struct threads_listing_context
*context
= data
;
2739 struct thread_item item
;
2740 int pid
= ptid_get_pid (inferior_ptid
);
2742 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2746 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2748 return 1; /* continue iterator */
2751 #define CRAZY_MAX_THREADS 1000
2754 remote_current_thread (ptid_t oldpid
)
2756 struct remote_state
*rs
= get_remote_state ();
2759 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2760 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2765 result
= read_ptid (&rs
->buf
[2], &obuf
);
2766 if (*obuf
!= '\0' && remote_debug
)
2767 fprintf_unfiltered (gdb_stdlog
,
2768 "warning: garbage in qC reply\n");
2776 /* List remote threads using the deprecated qL packet. */
2779 remote_get_threads_with_ql (struct target_ops
*ops
,
2780 struct threads_listing_context
*context
)
2782 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2783 CRAZY_MAX_THREADS
) >= 0)
2789 #if defined(HAVE_LIBEXPAT)
2792 start_thread (struct gdb_xml_parser
*parser
,
2793 const struct gdb_xml_element
*element
,
2794 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2796 struct threads_listing_context
*data
= user_data
;
2798 struct thread_item item
;
2800 struct gdb_xml_value
*attr
;
2802 id
= xml_find_attribute (attributes
, "id")->value
;
2803 item
.ptid
= read_ptid (id
, NULL
);
2805 attr
= xml_find_attribute (attributes
, "core");
2807 item
.core
= *(ULONGEST
*) attr
->value
;
2813 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2817 end_thread (struct gdb_xml_parser
*parser
,
2818 const struct gdb_xml_element
*element
,
2819 void *user_data
, const char *body_text
)
2821 struct threads_listing_context
*data
= user_data
;
2823 if (body_text
&& *body_text
)
2824 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2827 const struct gdb_xml_attribute thread_attributes
[] = {
2828 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2829 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2830 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2833 const struct gdb_xml_element thread_children
[] = {
2834 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2837 const struct gdb_xml_element threads_children
[] = {
2838 { "thread", thread_attributes
, thread_children
,
2839 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2840 start_thread
, end_thread
},
2841 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2844 const struct gdb_xml_element threads_elements
[] = {
2845 { "threads", NULL
, threads_children
,
2846 GDB_XML_EF_NONE
, NULL
, NULL
},
2847 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2852 /* List remote threads using qXfer:threads:read. */
2855 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2856 struct threads_listing_context
*context
)
2858 #if defined(HAVE_LIBEXPAT)
2859 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2861 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2862 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2864 if (xml
!= NULL
&& *xml
!= '\0')
2866 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2867 threads_elements
, xml
, context
);
2870 do_cleanups (back_to
);
2878 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2881 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2882 struct threads_listing_context
*context
)
2884 struct remote_state
*rs
= get_remote_state ();
2886 if (rs
->use_threadinfo_query
)
2890 putpkt ("qfThreadInfo");
2891 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2893 if (bufp
[0] != '\0') /* q packet recognized */
2895 while (*bufp
++ == 'm') /* reply contains one or more TID */
2899 struct thread_item item
;
2901 item
.ptid
= read_ptid (bufp
, &bufp
);
2905 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2907 while (*bufp
++ == ','); /* comma-separated list */
2908 putpkt ("qsThreadInfo");
2909 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2916 /* Packet not recognized. */
2917 rs
->use_threadinfo_query
= 0;
2924 /* Implement the to_update_thread_list function for the remote
2928 remote_update_thread_list (struct target_ops
*ops
)
2930 struct remote_state
*rs
= get_remote_state ();
2931 struct threads_listing_context context
;
2932 struct cleanup
*old_chain
;
2935 context
.items
= NULL
;
2936 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2938 /* We have a few different mechanisms to fetch the thread list. Try
2939 them all, starting with the most preferred one first, falling
2940 back to older methods. */
2941 if (remote_get_threads_with_qxfer (ops
, &context
)
2942 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2943 || remote_get_threads_with_ql (ops
, &context
))
2946 struct thread_item
*item
;
2947 struct thread_info
*tp
, *tmp
;
2951 if (VEC_empty (thread_item_t
, context
.items
)
2952 && remote_thread_always_alive (ops
, inferior_ptid
))
2954 /* Some targets don't really support threads, but still
2955 reply an (empty) thread list in response to the thread
2956 listing packets, instead of replying "packet not
2957 supported". Exit early so we don't delete the main
2959 do_cleanups (old_chain
);
2963 /* CONTEXT now holds the current thread list on the remote
2964 target end. Delete GDB-side threads no longer found on the
2966 ALL_THREADS_SAFE (tp
, tmp
)
2969 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2972 if (ptid_equal (item
->ptid
, tp
->ptid
))
2976 if (i
== VEC_length (thread_item_t
, context
.items
))
2979 delete_thread (tp
->ptid
);
2983 /* Remove any unreported fork child threads from CONTEXT so
2984 that we don't interfere with follow fork, which is where
2985 creation of such threads is handled. */
2986 remove_new_fork_children (&context
);
2988 /* And now add threads we don't know about yet to our list. */
2990 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2993 if (!ptid_equal (item
->ptid
, null_ptid
))
2995 struct private_thread_info
*info
;
2996 /* In non-stop mode, we assume new found threads are
2997 running until proven otherwise with a stop reply. In
2998 all-stop, we can only get here if all threads are
3000 int running
= non_stop
? 1 : 0;
3002 remote_notice_new_inferior (item
->ptid
, running
);
3004 info
= demand_private_info (item
->ptid
);
3005 info
->core
= item
->core
;
3006 info
->extra
= item
->extra
;
3014 /* If no thread listing method is supported, then query whether
3015 each known thread is alive, one by one, with the T packet.
3016 If the target doesn't support threads at all, then this is a
3017 no-op. See remote_thread_alive. */
3021 do_cleanups (old_chain
);
3025 * Collect a descriptive string about the given thread.
3026 * The target may say anything it wants to about the thread
3027 * (typically info about its blocked / runnable state, name, etc.).
3028 * This string will appear in the info threads display.
3030 * Optional: targets are not required to implement this function.
3034 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3036 struct remote_state
*rs
= get_remote_state ();
3040 struct gdb_ext_thread_info threadinfo
;
3041 static char display_buf
[100]; /* arbitrary... */
3042 int n
= 0; /* position in display_buf */
3044 if (rs
->remote_desc
== 0) /* paranoia */
3045 internal_error (__FILE__
, __LINE__
,
3046 _("remote_threads_extra_info"));
3048 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3049 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3050 /* This is the main thread which was added by GDB. The remote
3051 server doesn't know about it. */
3054 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3056 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3058 if (info
&& info
->priv
)
3059 return info
->priv
->extra
;
3064 if (rs
->use_threadextra_query
)
3067 char *endb
= rs
->buf
+ get_remote_packet_size ();
3069 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3071 write_ptid (b
, endb
, tp
->ptid
);
3074 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3075 if (rs
->buf
[0] != 0)
3077 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3078 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3079 display_buf
[result
] = '\0';
3084 /* If the above query fails, fall back to the old method. */
3085 rs
->use_threadextra_query
= 0;
3086 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3087 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3088 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3089 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3090 if (threadinfo
.active
)
3092 if (*threadinfo
.shortname
)
3093 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3094 " Name: %s,", threadinfo
.shortname
);
3095 if (*threadinfo
.display
)
3096 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3097 " State: %s,", threadinfo
.display
);
3098 if (*threadinfo
.more_display
)
3099 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3100 " Priority: %s", threadinfo
.more_display
);
3104 /* For purely cosmetic reasons, clear up trailing commas. */
3105 if (',' == display_buf
[n
-1])
3106 display_buf
[n
-1] = ' ';
3115 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3116 struct static_tracepoint_marker
*marker
)
3118 struct remote_state
*rs
= get_remote_state ();
3121 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3123 p
+= hexnumstr (p
, addr
);
3125 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3129 error (_("Remote failure reply: %s"), p
);
3133 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3140 static VEC(static_tracepoint_marker_p
) *
3141 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3144 struct remote_state
*rs
= get_remote_state ();
3145 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3146 struct static_tracepoint_marker
*marker
= NULL
;
3147 struct cleanup
*old_chain
;
3150 /* Ask for a first packet of static tracepoint marker
3153 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3156 error (_("Remote failure reply: %s"), p
);
3158 old_chain
= make_cleanup (free_current_marker
, &marker
);
3163 marker
= XCNEW (struct static_tracepoint_marker
);
3167 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3169 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3171 VEC_safe_push (static_tracepoint_marker_p
,
3177 release_static_tracepoint_marker (marker
);
3178 memset (marker
, 0, sizeof (*marker
));
3181 while (*p
++ == ','); /* comma-separated list */
3182 /* Ask for another packet of static tracepoint definition. */
3184 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3188 do_cleanups (old_chain
);
3193 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3196 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3198 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3202 /* Restart the remote side; this is an extended protocol operation. */
3205 extended_remote_restart (void)
3207 struct remote_state
*rs
= get_remote_state ();
3209 /* Send the restart command; for reasons I don't understand the
3210 remote side really expects a number after the "R". */
3211 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3214 remote_fileio_reset ();
3217 /* Clean up connection to a remote debugger. */
3220 remote_close (struct target_ops
*self
)
3222 struct remote_state
*rs
= get_remote_state ();
3224 if (rs
->remote_desc
== NULL
)
3225 return; /* already closed */
3227 /* Make sure we leave stdin registered in the event loop, and we
3228 don't leave the async SIGINT signal handler installed. */
3229 remote_terminal_ours (self
);
3231 serial_close (rs
->remote_desc
);
3232 rs
->remote_desc
= NULL
;
3234 /* We don't have a connection to the remote stub anymore. Get rid
3235 of all the inferiors and their threads we were controlling.
3236 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3237 will be unable to find the thread corresponding to (pid, 0, 0). */
3238 inferior_ptid
= null_ptid
;
3239 discard_all_inferiors ();
3241 /* We are closing the remote target, so we should discard
3242 everything of this target. */
3243 discard_pending_stop_replies_in_queue (rs
);
3245 if (remote_async_inferior_event_token
)
3246 delete_async_event_handler (&remote_async_inferior_event_token
);
3248 remote_notif_state_xfree (rs
->notif_state
);
3250 trace_reset_local_state ();
3253 /* Query the remote side for the text, data and bss offsets. */
3258 struct remote_state
*rs
= get_remote_state ();
3261 int lose
, num_segments
= 0, do_sections
, do_segments
;
3262 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3263 struct section_offsets
*offs
;
3264 struct symfile_segment_data
*data
;
3266 if (symfile_objfile
== NULL
)
3269 putpkt ("qOffsets");
3270 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3273 if (buf
[0] == '\000')
3274 return; /* Return silently. Stub doesn't support
3278 warning (_("Remote failure reply: %s"), buf
);
3282 /* Pick up each field in turn. This used to be done with scanf, but
3283 scanf will make trouble if CORE_ADDR size doesn't match
3284 conversion directives correctly. The following code will work
3285 with any size of CORE_ADDR. */
3286 text_addr
= data_addr
= bss_addr
= 0;
3290 if (startswith (ptr
, "Text="))
3293 /* Don't use strtol, could lose on big values. */
3294 while (*ptr
&& *ptr
!= ';')
3295 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3297 if (startswith (ptr
, ";Data="))
3300 while (*ptr
&& *ptr
!= ';')
3301 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3306 if (!lose
&& startswith (ptr
, ";Bss="))
3309 while (*ptr
&& *ptr
!= ';')
3310 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3312 if (bss_addr
!= data_addr
)
3313 warning (_("Target reported unsupported offsets: %s"), buf
);
3318 else if (startswith (ptr
, "TextSeg="))
3321 /* Don't use strtol, could lose on big values. */
3322 while (*ptr
&& *ptr
!= ';')
3323 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3326 if (startswith (ptr
, ";DataSeg="))
3329 while (*ptr
&& *ptr
!= ';')
3330 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3338 error (_("Malformed response to offset query, %s"), buf
);
3339 else if (*ptr
!= '\0')
3340 warning (_("Target reported unsupported offsets: %s"), buf
);
3342 offs
= ((struct section_offsets
*)
3343 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3344 memcpy (offs
, symfile_objfile
->section_offsets
,
3345 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3347 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3348 do_segments
= (data
!= NULL
);
3349 do_sections
= num_segments
== 0;
3351 if (num_segments
> 0)
3353 segments
[0] = text_addr
;
3354 segments
[1] = data_addr
;
3356 /* If we have two segments, we can still try to relocate everything
3357 by assuming that the .text and .data offsets apply to the whole
3358 text and data segments. Convert the offsets given in the packet
3359 to base addresses for symfile_map_offsets_to_segments. */
3360 else if (data
&& data
->num_segments
== 2)
3362 segments
[0] = data
->segment_bases
[0] + text_addr
;
3363 segments
[1] = data
->segment_bases
[1] + data_addr
;
3366 /* If the object file has only one segment, assume that it is text
3367 rather than data; main programs with no writable data are rare,
3368 but programs with no code are useless. Of course the code might
3369 have ended up in the data segment... to detect that we would need
3370 the permissions here. */
3371 else if (data
&& data
->num_segments
== 1)
3373 segments
[0] = data
->segment_bases
[0] + text_addr
;
3376 /* There's no way to relocate by segment. */
3382 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3383 offs
, num_segments
, segments
);
3385 if (ret
== 0 && !do_sections
)
3386 error (_("Can not handle qOffsets TextSeg "
3387 "response with this symbol file"));
3394 free_symfile_segment_data (data
);
3398 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3400 /* This is a temporary kludge to force data and bss to use the
3401 same offsets because that's what nlmconv does now. The real
3402 solution requires changes to the stub and remote.c that I
3403 don't have time to do right now. */
3405 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3406 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3409 objfile_relocate (symfile_objfile
, offs
);
3412 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3413 threads we know are stopped already. This is used during the
3414 initial remote connection in non-stop mode --- threads that are
3415 reported as already being stopped are left stopped. */
3418 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3420 /* If we have a stop reply for this thread, it must be stopped. */
3421 if (peek_stop_reply (thread
->ptid
))
3422 set_stop_requested (thread
->ptid
, 1);
3427 /* Send interrupt_sequence to remote target. */
3429 send_interrupt_sequence (void)
3431 struct remote_state
*rs
= get_remote_state ();
3433 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3434 remote_serial_write ("\x03", 1);
3435 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3436 serial_send_break (rs
->remote_desc
);
3437 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3439 serial_send_break (rs
->remote_desc
);
3440 remote_serial_write ("g", 1);
3443 internal_error (__FILE__
, __LINE__
,
3444 _("Invalid value for interrupt_sequence_mode: %s."),
3445 interrupt_sequence_mode
);
3449 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3450 and extract the PTID. Returns NULL_PTID if not found. */
3453 stop_reply_extract_thread (char *stop_reply
)
3455 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3459 /* Txx r:val ; r:val (...) */
3462 /* Look for "register" named "thread". */
3467 p1
= strchr (p
, ':');
3471 if (strncmp (p
, "thread", p1
- p
) == 0)
3472 return read_ptid (++p1
, &p
);
3474 p1
= strchr (p
, ';');
3486 /* Determine the remote side's current thread. If we have a stop
3487 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3488 "thread" register we can extract the current thread from. If not,
3489 ask the remote which is the current thread with qC. The former
3490 method avoids a roundtrip. */
3493 get_current_thread (char *wait_status
)
3495 ptid_t ptid
= null_ptid
;
3497 /* Note we don't use remote_parse_stop_reply as that makes use of
3498 the target architecture, which we haven't yet fully determined at
3500 if (wait_status
!= NULL
)
3501 ptid
= stop_reply_extract_thread (wait_status
);
3502 if (ptid_equal (ptid
, null_ptid
))
3503 ptid
= remote_current_thread (inferior_ptid
);
3508 /* Query the remote target for which is the current thread/process,
3509 add it to our tables, and update INFERIOR_PTID. The caller is
3510 responsible for setting the state such that the remote end is ready
3511 to return the current thread.
3513 This function is called after handling the '?' or 'vRun' packets,
3514 whose response is a stop reply from which we can also try
3515 extracting the thread. If the target doesn't support the explicit
3516 qC query, we infer the current thread from that stop reply, passed
3517 in in WAIT_STATUS, which may be NULL. */
3520 add_current_inferior_and_thread (char *wait_status
)
3522 struct remote_state
*rs
= get_remote_state ();
3526 inferior_ptid
= null_ptid
;
3528 /* Now, if we have thread information, update inferior_ptid. */
3529 ptid
= get_current_thread (wait_status
);
3531 if (!ptid_equal (ptid
, null_ptid
))
3533 if (!remote_multi_process_p (rs
))
3536 inferior_ptid
= ptid
;
3540 /* Without this, some commands which require an active target
3541 (such as kill) won't work. This variable serves (at least)
3542 double duty as both the pid of the target process (if it has
3543 such), and as a flag indicating that a target is active. */
3544 inferior_ptid
= magic_null_ptid
;
3548 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3550 /* Add the main thread. */
3551 add_thread_silent (inferior_ptid
);
3555 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3557 struct remote_state
*rs
= get_remote_state ();
3558 struct packet_config
*noack_config
;
3559 char *wait_status
= NULL
;
3561 immediate_quit
++; /* Allow user to interrupt it. */
3564 if (interrupt_on_connect
)
3565 send_interrupt_sequence ();
3567 /* Ack any packet which the remote side has already sent. */
3568 serial_write (rs
->remote_desc
, "+", 1);
3570 /* Signal other parts that we're going through the initial setup,
3571 and so things may not be stable yet. */
3572 rs
->starting_up
= 1;
3574 /* The first packet we send to the target is the optional "supported
3575 packets" request. If the target can answer this, it will tell us
3576 which later probes to skip. */
3577 remote_query_supported ();
3579 /* If the stub wants to get a QAllow, compose one and send it. */
3580 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3581 remote_set_permissions (target
);
3583 /* Next, we possibly activate noack mode.
3585 If the QStartNoAckMode packet configuration is set to AUTO,
3586 enable noack mode if the stub reported a wish for it with
3589 If set to TRUE, then enable noack mode even if the stub didn't
3590 report it in qSupported. If the stub doesn't reply OK, the
3591 session ends with an error.
3593 If FALSE, then don't activate noack mode, regardless of what the
3594 stub claimed should be the default with qSupported. */
3596 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3597 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3599 putpkt ("QStartNoAckMode");
3600 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3601 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3607 /* Tell the remote that we are using the extended protocol. */
3609 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3612 /* Let the target know which signals it is allowed to pass down to
3614 update_signals_program_target ();
3616 /* Next, if the target can specify a description, read it. We do
3617 this before anything involving memory or registers. */
3618 target_find_description ();
3620 /* Next, now that we know something about the target, update the
3621 address spaces in the program spaces. */
3622 update_address_spaces ();
3624 /* On OSs where the list of libraries is global to all
3625 processes, we fetch them early. */
3626 if (gdbarch_has_global_solist (target_gdbarch ()))
3627 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3631 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3632 error (_("Non-stop mode requested, but remote "
3633 "does not support non-stop"));
3635 putpkt ("QNonStop:1");
3636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3638 if (strcmp (rs
->buf
, "OK") != 0)
3639 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3641 /* Find about threads and processes the stub is already
3642 controlling. We default to adding them in the running state.
3643 The '?' query below will then tell us about which threads are
3645 remote_update_thread_list (target
);
3647 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3649 /* Don't assume that the stub can operate in all-stop mode.
3650 Request it explicitly. */
3651 putpkt ("QNonStop:0");
3652 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3654 if (strcmp (rs
->buf
, "OK") != 0)
3655 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3658 /* Upload TSVs regardless of whether the target is running or not. The
3659 remote stub, such as GDBserver, may have some predefined or builtin
3660 TSVs, even if the target is not running. */
3661 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3663 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3665 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3666 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3669 /* Check whether the target is running now. */
3671 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3677 struct inferior
*inf
;
3679 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3682 error (_("The target is not running (try extended-remote?)"));
3684 /* We're connected, but not running. Drop out before we
3685 call start_remote. */
3686 rs
->starting_up
= 0;
3691 /* Save the reply for later. */
3692 wait_status
= alloca (strlen (rs
->buf
) + 1);
3693 strcpy (wait_status
, rs
->buf
);
3696 /* Fetch thread list. */
3697 target_update_thread_list ();
3699 /* Let the stub know that we want it to return the thread. */
3700 set_continue_thread (minus_one_ptid
);
3702 if (thread_count () == 0)
3704 /* Target has no concept of threads at all. GDB treats
3705 non-threaded target as single-threaded; add a main
3707 add_current_inferior_and_thread (wait_status
);
3711 /* We have thread information; select the thread the target
3712 says should be current. If we're reconnecting to a
3713 multi-threaded program, this will ideally be the thread
3714 that last reported an event before GDB disconnected. */
3715 inferior_ptid
= get_current_thread (wait_status
);
3716 if (ptid_equal (inferior_ptid
, null_ptid
))
3718 /* Odd... The target was able to list threads, but not
3719 tell us which thread was current (no "thread"
3720 register in T stop reply?). Just pick the first
3721 thread in the thread list then. */
3724 fprintf_unfiltered (gdb_stdlog
,
3725 "warning: couldn't determine remote "
3726 "current thread; picking first in list.\n");
3728 inferior_ptid
= thread_list
->ptid
;
3732 /* init_wait_for_inferior should be called before get_offsets in order
3733 to manage `inserted' flag in bp loc in a correct state.
3734 breakpoint_init_inferior, called from init_wait_for_inferior, set
3735 `inserted' flag to 0, while before breakpoint_re_set, called from
3736 start_remote, set `inserted' flag to 1. In the initialization of
3737 inferior, breakpoint_init_inferior should be called first, and then
3738 breakpoint_re_set can be called. If this order is broken, state of
3739 `inserted' flag is wrong, and cause some problems on breakpoint
3741 init_wait_for_inferior ();
3743 get_offsets (); /* Get text, data & bss offsets. */
3745 /* If we could not find a description using qXfer, and we know
3746 how to do it some other way, try again. This is not
3747 supported for non-stop; it could be, but it is tricky if
3748 there are no stopped threads when we connect. */
3749 if (remote_read_description_p (target
)
3750 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3752 target_clear_description ();
3753 target_find_description ();
3756 /* Use the previously fetched status. */
3757 gdb_assert (wait_status
!= NULL
);
3758 strcpy (rs
->buf
, wait_status
);
3759 rs
->cached_wait_status
= 1;
3762 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3766 /* Clear WFI global state. Do this before finding about new
3767 threads and inferiors, and setting the current inferior.
3768 Otherwise we would clear the proceed status of the current
3769 inferior when we want its stop_soon state to be preserved
3770 (see notice_new_inferior). */
3771 init_wait_for_inferior ();
3773 /* In non-stop, we will either get an "OK", meaning that there
3774 are no stopped threads at this time; or, a regular stop
3775 reply. In the latter case, there may be more than one thread
3776 stopped --- we pull them all out using the vStopped
3778 if (strcmp (rs
->buf
, "OK") != 0)
3780 struct notif_client
*notif
= ¬if_client_stop
;
3782 /* remote_notif_get_pending_replies acks this one, and gets
3784 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3785 = remote_notif_parse (notif
, rs
->buf
);
3786 remote_notif_get_pending_events (notif
);
3788 /* Make sure that threads that were stopped remain
3790 iterate_over_threads (set_stop_requested_callback
, NULL
);
3793 if (target_can_async_p ())
3796 if (thread_count () == 0)
3799 error (_("The target is not running (try extended-remote?)"));
3801 /* We're connected, but not running. Drop out before we
3802 call start_remote. */
3803 rs
->starting_up
= 0;
3807 /* Let the stub know that we want it to return the thread. */
3809 /* Force the stub to choose a thread. */
3810 set_general_thread (null_ptid
);
3813 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3814 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3815 error (_("remote didn't report the current thread in non-stop mode"));
3817 get_offsets (); /* Get text, data & bss offsets. */
3819 /* In non-stop mode, any cached wait status will be stored in
3820 the stop reply queue. */
3821 gdb_assert (wait_status
== NULL
);
3823 /* Report all signals during attach/startup. */
3824 remote_pass_signals (target
, 0, NULL
);
3827 /* If we connected to a live target, do some additional setup. */
3828 if (target_has_execution
)
3830 if (symfile_objfile
) /* No use without a symbol-file. */
3831 remote_check_symbols ();
3834 /* Possibly the target has been engaged in a trace run started
3835 previously; find out where things are at. */
3836 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3838 struct uploaded_tp
*uploaded_tps
= NULL
;
3840 if (current_trace_status ()->running
)
3841 printf_filtered (_("Trace is already running on the target.\n"));
3843 remote_upload_tracepoints (target
, &uploaded_tps
);
3845 merge_uploaded_tracepoints (&uploaded_tps
);
3848 /* The thread and inferior lists are now synchronized with the
3849 target, our symbols have been relocated, and we're merged the
3850 target's tracepoints with ours. We're done with basic start
3852 rs
->starting_up
= 0;
3854 /* Maybe breakpoints are global and need to be inserted now. */
3855 if (breakpoints_should_be_inserted_now ())
3856 insert_breakpoints ();
3859 /* Open a connection to a remote debugger.
3860 NAME is the filename used for communication. */
3863 remote_open (const char *name
, int from_tty
)
3865 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3868 /* Open a connection to a remote debugger using the extended
3869 remote gdb protocol. NAME is the filename used for communication. */
3872 extended_remote_open (const char *name
, int from_tty
)
3874 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3877 /* Reset all packets back to "unknown support". Called when opening a
3878 new connection to a remote target. */
3881 reset_all_packet_configs_support (void)
3885 for (i
= 0; i
< PACKET_MAX
; i
++)
3886 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3889 /* Initialize all packet configs. */
3892 init_all_packet_configs (void)
3896 for (i
= 0; i
< PACKET_MAX
; i
++)
3898 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3899 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3903 /* Symbol look-up. */
3906 remote_check_symbols (void)
3908 struct remote_state
*rs
= get_remote_state ();
3909 char *msg
, *reply
, *tmp
;
3910 struct bound_minimal_symbol sym
;
3913 /* The remote side has no concept of inferiors that aren't running
3914 yet, it only knows about running processes. If we're connected
3915 but our current inferior is not running, we should not invite the
3916 remote target to request symbol lookups related to its
3917 (unrelated) current process. */
3918 if (!target_has_execution
)
3921 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3924 /* Make sure the remote is pointing at the right process. Note
3925 there's no way to select "no process". */
3926 set_general_process ();
3928 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3929 because we need both at the same time. */
3930 msg
= alloca (get_remote_packet_size ());
3932 /* Invite target to request symbol lookups. */
3934 putpkt ("qSymbol::");
3935 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3936 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3939 while (startswith (reply
, "qSymbol:"))
3941 struct bound_minimal_symbol sym
;
3944 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3946 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3947 if (sym
.minsym
== NULL
)
3948 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3951 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3952 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3954 /* If this is a function address, return the start of code
3955 instead of any data function descriptor. */
3956 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3960 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3961 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3965 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3970 static struct serial
*
3971 remote_serial_open (const char *name
)
3973 static int udp_warning
= 0;
3975 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3976 of in ser-tcp.c, because it is the remote protocol assuming that the
3977 serial connection is reliable and not the serial connection promising
3979 if (!udp_warning
&& startswith (name
, "udp:"))
3981 warning (_("The remote protocol may be unreliable over UDP.\n"
3982 "Some events may be lost, rendering further debugging "
3987 return serial_open (name
);
3990 /* Inform the target of our permission settings. The permission flags
3991 work without this, but if the target knows the settings, it can do
3992 a couple things. First, it can add its own check, to catch cases
3993 that somehow manage to get by the permissions checks in target
3994 methods. Second, if the target is wired to disallow particular
3995 settings (for instance, a system in the field that is not set up to
3996 be able to stop at a breakpoint), it can object to any unavailable
4000 remote_set_permissions (struct target_ops
*self
)
4002 struct remote_state
*rs
= get_remote_state ();
4004 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4005 "WriteReg:%x;WriteMem:%x;"
4006 "InsertBreak:%x;InsertTrace:%x;"
4007 "InsertFastTrace:%x;Stop:%x",
4008 may_write_registers
, may_write_memory
,
4009 may_insert_breakpoints
, may_insert_tracepoints
,
4010 may_insert_fast_tracepoints
, may_stop
);
4012 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4014 /* If the target didn't like the packet, warn the user. Do not try
4015 to undo the user's settings, that would just be maddening. */
4016 if (strcmp (rs
->buf
, "OK") != 0)
4017 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4020 /* This type describes each known response to the qSupported
4022 struct protocol_feature
4024 /* The name of this protocol feature. */
4027 /* The default for this protocol feature. */
4028 enum packet_support default_support
;
4030 /* The function to call when this feature is reported, or after
4031 qSupported processing if the feature is not supported.
4032 The first argument points to this structure. The second
4033 argument indicates whether the packet requested support be
4034 enabled, disabled, or probed (or the default, if this function
4035 is being called at the end of processing and this feature was
4036 not reported). The third argument may be NULL; if not NULL, it
4037 is a NUL-terminated string taken from the packet following
4038 this feature's name and an equals sign. */
4039 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4042 /* The corresponding packet for this feature. Only used if
4043 FUNC is remote_supported_packet. */
4048 remote_supported_packet (const struct protocol_feature
*feature
,
4049 enum packet_support support
,
4050 const char *argument
)
4054 warning (_("Remote qSupported response supplied an unexpected value for"
4055 " \"%s\"."), feature
->name
);
4059 remote_protocol_packets
[feature
->packet
].support
= support
;
4063 remote_packet_size (const struct protocol_feature
*feature
,
4064 enum packet_support support
, const char *value
)
4066 struct remote_state
*rs
= get_remote_state ();
4071 if (support
!= PACKET_ENABLE
)
4074 if (value
== NULL
|| *value
== '\0')
4076 warning (_("Remote target reported \"%s\" without a size."),
4082 packet_size
= strtol (value
, &value_end
, 16);
4083 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4085 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4086 feature
->name
, value
);
4090 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
4092 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
4093 packet_size
, MAX_REMOTE_PACKET_SIZE
);
4094 packet_size
= MAX_REMOTE_PACKET_SIZE
;
4097 /* Record the new maximum packet size. */
4098 rs
->explicit_packet_size
= packet_size
;
4101 static const struct protocol_feature remote_protocol_features
[] = {
4102 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4103 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4104 PACKET_qXfer_auxv
},
4105 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4106 PACKET_qXfer_exec_file
},
4107 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4108 PACKET_qXfer_features
},
4109 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4110 PACKET_qXfer_libraries
},
4111 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4112 PACKET_qXfer_libraries_svr4
},
4113 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4114 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4115 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4116 PACKET_qXfer_memory_map
},
4117 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4118 PACKET_qXfer_spu_read
},
4119 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4120 PACKET_qXfer_spu_write
},
4121 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4122 PACKET_qXfer_osdata
},
4123 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4124 PACKET_qXfer_threads
},
4125 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4126 PACKET_qXfer_traceframe_info
},
4127 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4128 PACKET_QPassSignals
},
4129 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4130 PACKET_QProgramSignals
},
4131 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4132 PACKET_QStartNoAckMode
},
4133 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4134 PACKET_multiprocess_feature
},
4135 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4136 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4137 PACKET_qXfer_siginfo_read
},
4138 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4139 PACKET_qXfer_siginfo_write
},
4140 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4141 PACKET_ConditionalTracepoints
},
4142 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4143 PACKET_ConditionalBreakpoints
},
4144 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4145 PACKET_BreakpointCommands
},
4146 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4147 PACKET_FastTracepoints
},
4148 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4149 PACKET_StaticTracepoints
},
4150 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4151 PACKET_InstallInTrace
},
4152 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4153 PACKET_DisconnectedTracing_feature
},
4154 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4156 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4158 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4159 PACKET_TracepointSource
},
4160 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4162 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4163 PACKET_EnableDisableTracepoints_feature
},
4164 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4165 PACKET_qXfer_fdpic
},
4166 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4168 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4169 PACKET_QDisableRandomization
},
4170 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4171 { "QTBuffer:size", PACKET_DISABLE
,
4172 remote_supported_packet
, PACKET_QTBuffer_size
},
4173 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4174 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4175 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4176 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4177 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4178 PACKET_qXfer_btrace
},
4179 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4180 PACKET_qXfer_btrace_conf
},
4181 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4182 PACKET_Qbtrace_conf_bts_size
},
4183 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4184 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4185 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4186 PACKET_fork_event_feature
},
4187 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4188 PACKET_vfork_event_feature
},
4189 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4190 PACKET_Qbtrace_conf_pt_size
}
4193 static char *remote_support_xml
;
4195 /* Register string appended to "xmlRegisters=" in qSupported query. */
4198 register_remote_support_xml (const char *xml
)
4200 #if defined(HAVE_LIBEXPAT)
4201 if (remote_support_xml
== NULL
)
4202 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4205 char *copy
= xstrdup (remote_support_xml
+ 13);
4206 char *p
= strtok (copy
, ",");
4210 if (strcmp (p
, xml
) == 0)
4217 while ((p
= strtok (NULL
, ",")) != NULL
);
4220 remote_support_xml
= reconcat (remote_support_xml
,
4221 remote_support_xml
, ",", xml
,
4228 remote_query_supported_append (char *msg
, const char *append
)
4231 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4233 return xstrdup (append
);
4237 remote_query_supported (void)
4239 struct remote_state
*rs
= get_remote_state ();
4242 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4244 /* The packet support flags are handled differently for this packet
4245 than for most others. We treat an error, a disabled packet, and
4246 an empty response identically: any features which must be reported
4247 to be used will be automatically disabled. An empty buffer
4248 accomplishes this, since that is also the representation for a list
4249 containing no features. */
4252 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4255 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4257 q
= remote_query_supported_append (q
, "multiprocess+");
4259 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4260 q
= remote_query_supported_append (q
, "swbreak+");
4261 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4262 q
= remote_query_supported_append (q
, "hwbreak+");
4264 if (remote_support_xml
)
4265 q
= remote_query_supported_append (q
, remote_support_xml
);
4267 q
= remote_query_supported_append (q
, "qRelocInsn+");
4271 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4272 != AUTO_BOOLEAN_FALSE
)
4273 q
= remote_query_supported_append (q
, "fork-events+");
4274 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4275 != AUTO_BOOLEAN_FALSE
)
4276 q
= remote_query_supported_append (q
, "vfork-events+");
4279 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4282 do_cleanups (old_chain
);
4284 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4286 /* If an error occured, warn, but do not return - just reset the
4287 buffer to empty and go on to disable features. */
4288 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4291 warning (_("Remote failure reply: %s"), rs
->buf
);
4296 memset (seen
, 0, sizeof (seen
));
4301 enum packet_support is_supported
;
4302 char *p
, *end
, *name_end
, *value
;
4304 /* First separate out this item from the rest of the packet. If
4305 there's another item after this, we overwrite the separator
4306 (terminated strings are much easier to work with). */
4308 end
= strchr (p
, ';');
4311 end
= p
+ strlen (p
);
4321 warning (_("empty item in \"qSupported\" response"));
4326 name_end
= strchr (p
, '=');
4329 /* This is a name=value entry. */
4330 is_supported
= PACKET_ENABLE
;
4331 value
= name_end
+ 1;
4340 is_supported
= PACKET_ENABLE
;
4344 is_supported
= PACKET_DISABLE
;
4348 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4352 warning (_("unrecognized item \"%s\" "
4353 "in \"qSupported\" response"), p
);
4359 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4360 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4362 const struct protocol_feature
*feature
;
4365 feature
= &remote_protocol_features
[i
];
4366 feature
->func (feature
, is_supported
, value
);
4371 /* If we increased the packet size, make sure to increase the global
4372 buffer size also. We delay this until after parsing the entire
4373 qSupported packet, because this is the same buffer we were
4375 if (rs
->buf_size
< rs
->explicit_packet_size
)
4377 rs
->buf_size
= rs
->explicit_packet_size
;
4378 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4381 /* Handle the defaults for unmentioned features. */
4382 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4385 const struct protocol_feature
*feature
;
4387 feature
= &remote_protocol_features
[i
];
4388 feature
->func (feature
, feature
->default_support
, NULL
);
4392 /* Remove any of the remote.c targets from target stack. Upper targets depend
4393 on it so remove them first. */
4396 remote_unpush_target (void)
4398 pop_all_targets_above (process_stratum
- 1);
4402 remote_open_1 (const char *name
, int from_tty
,
4403 struct target_ops
*target
, int extended_p
)
4405 struct remote_state
*rs
= get_remote_state ();
4408 error (_("To open a remote debug connection, you need to specify what\n"
4409 "serial device is attached to the remote system\n"
4410 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4412 /* See FIXME above. */
4413 if (!target_async_permitted
)
4414 wait_forever_enabled_p
= 1;
4416 /* If we're connected to a running target, target_preopen will kill it.
4417 Ask this question first, before target_preopen has a chance to kill
4419 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4422 && !query (_("Already connected to a remote target. Disconnect? ")))
4423 error (_("Still connected."));
4426 /* Here the possibly existing remote target gets unpushed. */
4427 target_preopen (from_tty
);
4429 /* Make sure we send the passed signals list the next time we resume. */
4430 xfree (rs
->last_pass_packet
);
4431 rs
->last_pass_packet
= NULL
;
4433 /* Make sure we send the program signals list the next time we
4435 xfree (rs
->last_program_signals_packet
);
4436 rs
->last_program_signals_packet
= NULL
;
4438 remote_fileio_reset ();
4439 reopen_exec_file ();
4442 rs
->remote_desc
= remote_serial_open (name
);
4443 if (!rs
->remote_desc
)
4444 perror_with_name (name
);
4446 if (baud_rate
!= -1)
4448 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4450 /* The requested speed could not be set. Error out to
4451 top level after closing remote_desc. Take care to
4452 set remote_desc to NULL to avoid closing remote_desc
4454 serial_close (rs
->remote_desc
);
4455 rs
->remote_desc
= NULL
;
4456 perror_with_name (name
);
4460 serial_setparity (rs
->remote_desc
, serial_parity
);
4461 serial_raw (rs
->remote_desc
);
4463 /* If there is something sitting in the buffer we might take it as a
4464 response to a command, which would be bad. */
4465 serial_flush_input (rs
->remote_desc
);
4469 puts_filtered ("Remote debugging using ");
4470 puts_filtered (name
);
4471 puts_filtered ("\n");
4473 push_target (target
); /* Switch to using remote target now. */
4475 /* Register extra event sources in the event loop. */
4476 remote_async_inferior_event_token
4477 = create_async_event_handler (remote_async_inferior_event_handler
,
4479 rs
->notif_state
= remote_notif_state_allocate ();
4481 /* Reset the target state; these things will be queried either by
4482 remote_query_supported or as they are needed. */
4483 reset_all_packet_configs_support ();
4484 rs
->cached_wait_status
= 0;
4485 rs
->explicit_packet_size
= 0;
4487 rs
->extended
= extended_p
;
4488 rs
->waiting_for_stop_reply
= 0;
4489 rs
->ctrlc_pending_p
= 0;
4491 rs
->general_thread
= not_sent_ptid
;
4492 rs
->continue_thread
= not_sent_ptid
;
4493 rs
->remote_traceframe_number
= -1;
4495 /* Probe for ability to use "ThreadInfo" query, as required. */
4496 rs
->use_threadinfo_query
= 1;
4497 rs
->use_threadextra_query
= 1;
4499 if (target_async_permitted
)
4501 /* With this target we start out by owning the terminal. */
4502 remote_async_terminal_ours_p
= 1;
4504 /* FIXME: cagney/1999-09-23: During the initial connection it is
4505 assumed that the target is already ready and able to respond to
4506 requests. Unfortunately remote_start_remote() eventually calls
4507 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4508 around this. Eventually a mechanism that allows
4509 wait_for_inferior() to expect/get timeouts will be
4511 wait_forever_enabled_p
= 0;
4514 /* First delete any symbols previously loaded from shared libraries. */
4515 no_shared_libraries (NULL
, 0);
4518 init_thread_list ();
4520 /* Start the remote connection. If error() or QUIT, discard this
4521 target (we'd otherwise be in an inconsistent state) and then
4522 propogate the error on up the exception chain. This ensures that
4523 the caller doesn't stumble along blindly assuming that the
4524 function succeeded. The CLI doesn't have this problem but other
4525 UI's, such as MI do.
4527 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4528 this function should return an error indication letting the
4529 caller restore the previous state. Unfortunately the command
4530 ``target remote'' is directly wired to this function making that
4531 impossible. On a positive note, the CLI side of this problem has
4532 been fixed - the function set_cmd_context() makes it possible for
4533 all the ``target ....'' commands to share a common callback
4534 function. See cli-dump.c. */
4539 remote_start_remote (from_tty
, target
, extended_p
);
4541 CATCH (ex
, RETURN_MASK_ALL
)
4543 /* Pop the partially set up target - unless something else did
4544 already before throwing the exception. */
4545 if (rs
->remote_desc
!= NULL
)
4546 remote_unpush_target ();
4547 if (target_async_permitted
)
4548 wait_forever_enabled_p
= 1;
4549 throw_exception (ex
);
4554 remote_btrace_reset ();
4556 if (target_async_permitted
)
4557 wait_forever_enabled_p
= 1;
4560 /* Detach the specified process. */
4563 remote_detach_pid (int pid
)
4565 struct remote_state
*rs
= get_remote_state ();
4567 if (remote_multi_process_p (rs
))
4568 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4570 strcpy (rs
->buf
, "D");
4573 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4575 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4577 else if (rs
->buf
[0] == '\0')
4578 error (_("Remote doesn't know how to detach"));
4580 error (_("Can't detach process."));
4583 /* This detaches a program to which we previously attached, using
4584 inferior_ptid to identify the process. After this is done, GDB
4585 can be used to debug some other program. We better not have left
4586 any breakpoints in the target program or it'll die when it hits
4590 remote_detach_1 (const char *args
, int from_tty
)
4592 int pid
= ptid_get_pid (inferior_ptid
);
4593 struct remote_state
*rs
= get_remote_state ();
4594 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4598 error (_("Argument given to \"detach\" when remotely debugging."));
4600 if (!target_has_execution
)
4601 error (_("No process to detach from."));
4605 char *exec_file
= get_exec_file (0);
4606 if (exec_file
== NULL
)
4608 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4609 target_pid_to_str (pid_to_ptid (pid
)));
4610 gdb_flush (gdb_stdout
);
4613 /* Tell the remote target to detach. */
4614 remote_detach_pid (pid
);
4616 if (from_tty
&& !rs
->extended
)
4617 puts_filtered (_("Ending remote debugging.\n"));
4619 /* Check to see if we are detaching a fork parent. Note that if we
4620 are detaching a fork child, tp == NULL. */
4621 is_fork_parent
= (tp
!= NULL
4622 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4624 /* If doing detach-on-fork, we don't mourn, because that will delete
4625 breakpoints that should be available for the followed inferior. */
4626 if (!is_fork_parent
)
4627 target_mourn_inferior ();
4630 inferior_ptid
= null_ptid
;
4631 detach_inferior (pid
);
4636 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4638 remote_detach_1 (args
, from_tty
);
4642 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4644 remote_detach_1 (args
, from_tty
);
4647 /* Target follow-fork function for remote targets. On entry, and
4648 at return, the current inferior is the fork parent.
4650 Note that although this is currently only used for extended-remote,
4651 it is named remote_follow_fork in anticipation of using it for the
4652 remote target as well. */
4655 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4658 struct remote_state
*rs
= get_remote_state ();
4659 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4661 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4662 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4664 /* When following the parent and detaching the child, we detach
4665 the child here. For the case of following the child and
4666 detaching the parent, the detach is done in the target-
4667 independent follow fork code in infrun.c. We can't use
4668 target_detach when detaching an unfollowed child because
4669 the client side doesn't know anything about the child. */
4670 if (detach_fork
&& !follow_child
)
4672 /* Detach the fork child. */
4676 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4677 child_pid
= ptid_get_pid (child_ptid
);
4679 remote_detach_pid (child_pid
);
4680 detach_inferior (child_pid
);
4686 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4689 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4692 error (_("Argument given to \"disconnect\" when remotely debugging."));
4694 /* Make sure we unpush even the extended remote targets; mourn
4695 won't do it. So call remote_mourn directly instead of
4696 target_mourn_inferior. */
4697 remote_mourn (target
);
4700 puts_filtered ("Ending remote debugging.\n");
4703 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4704 be chatty about it. */
4707 extended_remote_attach (struct target_ops
*target
, const char *args
,
4710 struct remote_state
*rs
= get_remote_state ();
4712 char *wait_status
= NULL
;
4714 pid
= parse_pid_to_attach (args
);
4716 /* Remote PID can be freely equal to getpid, do not check it here the same
4717 way as in other targets. */
4719 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4720 error (_("This target does not support attaching to a process"));
4724 char *exec_file
= get_exec_file (0);
4727 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4728 target_pid_to_str (pid_to_ptid (pid
)));
4730 printf_unfiltered (_("Attaching to %s\n"),
4731 target_pid_to_str (pid_to_ptid (pid
)));
4733 gdb_flush (gdb_stdout
);
4736 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4738 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4740 switch (packet_ok (rs
->buf
,
4741 &remote_protocol_packets
[PACKET_vAttach
]))
4746 /* Save the reply for later. */
4747 wait_status
= alloca (strlen (rs
->buf
) + 1);
4748 strcpy (wait_status
, rs
->buf
);
4750 else if (strcmp (rs
->buf
, "OK") != 0)
4751 error (_("Attaching to %s failed with: %s"),
4752 target_pid_to_str (pid_to_ptid (pid
)),
4755 case PACKET_UNKNOWN
:
4756 error (_("This target does not support attaching to a process"));
4758 error (_("Attaching to %s failed"),
4759 target_pid_to_str (pid_to_ptid (pid
)));
4762 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4764 inferior_ptid
= pid_to_ptid (pid
);
4768 struct thread_info
*thread
;
4770 /* Get list of threads. */
4771 remote_update_thread_list (target
);
4773 thread
= first_thread_of_process (pid
);
4775 inferior_ptid
= thread
->ptid
;
4777 inferior_ptid
= pid_to_ptid (pid
);
4779 /* Invalidate our notion of the remote current thread. */
4780 record_currthread (rs
, minus_one_ptid
);
4784 /* Now, if we have thread information, update inferior_ptid. */
4785 inferior_ptid
= remote_current_thread (inferior_ptid
);
4787 /* Add the main thread to the thread list. */
4788 add_thread_silent (inferior_ptid
);
4791 /* Next, if the target can specify a description, read it. We do
4792 this before anything involving memory or registers. */
4793 target_find_description ();
4797 /* Use the previously fetched status. */
4798 gdb_assert (wait_status
!= NULL
);
4800 if (target_can_async_p ())
4802 struct notif_event
*reply
4803 = remote_notif_parse (¬if_client_stop
, wait_status
);
4805 push_stop_reply ((struct stop_reply
*) reply
);
4811 gdb_assert (wait_status
!= NULL
);
4812 strcpy (rs
->buf
, wait_status
);
4813 rs
->cached_wait_status
= 1;
4817 gdb_assert (wait_status
== NULL
);
4820 /* Implementation of the to_post_attach method. */
4823 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4825 /* In certain cases GDB might not have had the chance to start
4826 symbol lookup up until now. This could happen if the debugged
4827 binary is not using shared libraries, the vsyscall page is not
4828 present (on Linux) and the binary itself hadn't changed since the
4829 debugging process was started. */
4830 if (symfile_objfile
!= NULL
)
4831 remote_check_symbols();
4835 /* Check for the availability of vCont. This function should also check
4839 remote_vcont_probe (struct remote_state
*rs
)
4843 strcpy (rs
->buf
, "vCont?");
4845 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4848 /* Make sure that the features we assume are supported. */
4849 if (startswith (buf
, "vCont"))
4852 int support_s
, support_S
, support_c
, support_C
;
4858 rs
->supports_vCont
.t
= 0;
4859 rs
->supports_vCont
.r
= 0;
4860 while (p
&& *p
== ';')
4863 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4865 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4867 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4869 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4871 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4872 rs
->supports_vCont
.t
= 1;
4873 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4874 rs
->supports_vCont
.r
= 1;
4876 p
= strchr (p
, ';');
4879 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4880 BUF will make packet_ok disable the packet. */
4881 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4885 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4888 /* Helper function for building "vCont" resumptions. Write a
4889 resumption to P. ENDP points to one-passed-the-end of the buffer
4890 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4891 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4892 resumed thread should be single-stepped and/or signalled. If PTID
4893 equals minus_one_ptid, then all threads are resumed; if PTID
4894 represents a process, then all threads of the process are resumed;
4895 the thread to be stepped and/or signalled is given in the global
4899 append_resumption (char *p
, char *endp
,
4900 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4902 struct remote_state
*rs
= get_remote_state ();
4904 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4905 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4907 /* GDB is willing to range step. */
4908 && use_range_stepping
4909 /* Target supports range stepping. */
4910 && rs
->supports_vCont
.r
4911 /* We don't currently support range stepping multiple
4912 threads with a wildcard (though the protocol allows it,
4913 so stubs shouldn't make an active effort to forbid
4915 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4917 struct thread_info
*tp
;
4919 if (ptid_equal (ptid
, minus_one_ptid
))
4921 /* If we don't know about the target thread's tid, then
4922 we're resuming magic_null_ptid (see caller). */
4923 tp
= find_thread_ptid (magic_null_ptid
);
4926 tp
= find_thread_ptid (ptid
);
4927 gdb_assert (tp
!= NULL
);
4929 if (tp
->control
.may_range_step
)
4931 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4933 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4934 phex_nz (tp
->control
.step_range_start
,
4936 phex_nz (tp
->control
.step_range_end
,
4940 p
+= xsnprintf (p
, endp
- p
, ";s");
4943 p
+= xsnprintf (p
, endp
- p
, ";s");
4944 else if (siggnal
!= GDB_SIGNAL_0
)
4945 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4947 p
+= xsnprintf (p
, endp
- p
, ";c");
4949 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4953 /* All (-1) threads of process. */
4954 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4956 p
+= xsnprintf (p
, endp
- p
, ":");
4957 p
= write_ptid (p
, endp
, nptid
);
4959 else if (!ptid_equal (ptid
, minus_one_ptid
))
4961 p
+= xsnprintf (p
, endp
- p
, ":");
4962 p
= write_ptid (p
, endp
, ptid
);
4968 /* Append a vCont continue-with-signal action for threads that have a
4969 non-zero stop signal. */
4972 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4974 struct thread_info
*thread
;
4976 ALL_NON_EXITED_THREADS (thread
)
4977 if (ptid_match (thread
->ptid
, ptid
)
4978 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4979 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4981 p
= append_resumption (p
, endp
, thread
->ptid
,
4982 0, thread
->suspend
.stop_signal
);
4983 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4989 /* Resume the remote inferior by using a "vCont" packet. The thread
4990 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4991 resumed thread should be single-stepped and/or signalled. If PTID
4992 equals minus_one_ptid, then all threads are resumed; the thread to
4993 be stepped and/or signalled is given in the global INFERIOR_PTID.
4994 This function returns non-zero iff it resumes the inferior.
4996 This function issues a strict subset of all possible vCont commands at the
5000 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5002 struct remote_state
*rs
= get_remote_state ();
5006 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5007 remote_vcont_probe (rs
);
5009 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5013 endp
= rs
->buf
+ get_remote_packet_size ();
5015 /* If we could generate a wider range of packets, we'd have to worry
5016 about overflowing BUF. Should there be a generic
5017 "multi-part-packet" packet? */
5019 p
+= xsnprintf (p
, endp
- p
, "vCont");
5021 if (ptid_equal (ptid
, magic_null_ptid
))
5023 /* MAGIC_NULL_PTID means that we don't have any active threads,
5024 so we don't have any TID numbers the inferior will
5025 understand. Make sure to only send forms that do not specify
5027 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5029 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5031 /* Resume all threads (of all processes, or of a single
5032 process), with preference for INFERIOR_PTID. This assumes
5033 inferior_ptid belongs to the set of all threads we are about
5035 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5037 /* Step inferior_ptid, with or without signal. */
5038 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5041 /* Also pass down any pending signaled resumption for other
5042 threads not the current. */
5043 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5045 /* And continue others without a signal. */
5046 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5050 /* Scheduler locking; resume only PTID. */
5051 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5054 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5059 /* In non-stop, the stub replies to vCont with "OK". The stop
5060 reply will be reported asynchronously by means of a `%Stop'
5062 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5063 if (strcmp (rs
->buf
, "OK") != 0)
5064 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5070 /* Tell the remote machine to resume. */
5073 remote_resume (struct target_ops
*ops
,
5074 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5076 struct remote_state
*rs
= get_remote_state ();
5079 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5080 (explained in remote-notif.c:handle_notification) so
5081 remote_notif_process is not called. We need find a place where
5082 it is safe to start a 'vNotif' sequence. It is good to do it
5083 before resuming inferior, because inferior was stopped and no RSP
5084 traffic at that moment. */
5086 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5088 rs
->last_sent_signal
= siggnal
;
5089 rs
->last_sent_step
= step
;
5091 /* The vCont packet doesn't need to specify threads via Hc. */
5092 /* No reverse support (yet) for vCont. */
5093 if (execution_direction
!= EXEC_REVERSE
)
5094 if (remote_vcont_resume (ptid
, step
, siggnal
))
5097 /* All other supported resume packets do use Hc, so set the continue
5099 if (ptid_equal (ptid
, minus_one_ptid
))
5100 set_continue_thread (any_thread_ptid
);
5102 set_continue_thread (ptid
);
5105 if (execution_direction
== EXEC_REVERSE
)
5107 /* We don't pass signals to the target in reverse exec mode. */
5108 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5109 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5112 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5113 error (_("Remote reverse-step not supported."));
5114 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5115 error (_("Remote reverse-continue not supported."));
5117 strcpy (buf
, step
? "bs" : "bc");
5119 else if (siggnal
!= GDB_SIGNAL_0
)
5121 buf
[0] = step
? 'S' : 'C';
5122 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5123 buf
[2] = tohex (((int) siggnal
) & 0xf);
5127 strcpy (buf
, step
? "s" : "c");
5132 /* We are about to start executing the inferior, let's register it
5133 with the event loop. NOTE: this is the one place where all the
5134 execution commands end up. We could alternatively do this in each
5135 of the execution commands in infcmd.c. */
5136 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5137 into infcmd.c in order to allow inferior function calls to work
5138 NOT asynchronously. */
5139 if (target_can_async_p ())
5142 /* We've just told the target to resume. The remote server will
5143 wait for the inferior to stop, and then send a stop reply. In
5144 the mean time, we can't start another command/query ourselves
5145 because the stub wouldn't be ready to process it. This applies
5146 only to the base all-stop protocol, however. In non-stop (which
5147 only supports vCont), the stub replies with an "OK", and is
5148 immediate able to process further serial input. */
5150 rs
->waiting_for_stop_reply
= 1;
5154 /* Set up the signal handler for SIGINT, while the target is
5155 executing, ovewriting the 'regular' SIGINT signal handler. */
5157 async_initialize_sigint_signal_handler (void)
5159 signal (SIGINT
, async_handle_remote_sigint
);
5162 /* Signal handler for SIGINT, while the target is executing. */
5164 async_handle_remote_sigint (int sig
)
5166 signal (sig
, async_handle_remote_sigint_twice
);
5167 /* Note we need to go through gdb_call_async_signal_handler in order
5168 to wake up the event loop on Windows. */
5169 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5172 /* Signal handler for SIGINT, installed after SIGINT has already been
5173 sent once. It will take effect the second time that the user sends
5176 async_handle_remote_sigint_twice (int sig
)
5178 signal (sig
, async_handle_remote_sigint
);
5179 /* See note in async_handle_remote_sigint. */
5180 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5183 /* Perform the real interruption of the target execution, in response
5186 async_remote_interrupt (gdb_client_data arg
)
5189 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5191 target_stop (inferior_ptid
);
5194 /* Perform interrupt, if the first attempt did not succeed. Just give
5195 up on the target alltogether. */
5197 async_remote_interrupt_twice (gdb_client_data arg
)
5200 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5205 /* Reinstall the usual SIGINT handlers, after the target has
5208 async_cleanup_sigint_signal_handler (void *dummy
)
5210 signal (SIGINT
, handle_sigint
);
5213 /* Send ^C to target to halt it. Target will respond, and send us a
5215 static void (*ofunc
) (int);
5217 /* The command line interface's stop routine. This function is installed
5218 as a signal handler for SIGINT. The first time a user requests a
5219 stop, we call remote_stop to send a break or ^C. If there is no
5220 response from the target (it didn't stop when the user requested it),
5221 we ask the user if he'd like to detach from the target. */
5223 sync_remote_interrupt (int signo
)
5225 /* If this doesn't work, try more severe steps. */
5226 signal (signo
, sync_remote_interrupt_twice
);
5228 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5231 /* The user typed ^C twice. */
5234 sync_remote_interrupt_twice (int signo
)
5236 signal (signo
, ofunc
);
5237 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5238 signal (signo
, sync_remote_interrupt
);
5241 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5242 thread, all threads of a remote process, or all threads of all
5246 remote_stop_ns (ptid_t ptid
)
5248 struct remote_state
*rs
= get_remote_state ();
5250 char *endp
= rs
->buf
+ get_remote_packet_size ();
5252 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5253 remote_vcont_probe (rs
);
5255 if (!rs
->supports_vCont
.t
)
5256 error (_("Remote server does not support stopping threads"));
5258 if (ptid_equal (ptid
, minus_one_ptid
)
5259 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5260 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5265 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5267 if (ptid_is_pid (ptid
))
5268 /* All (-1) threads of process. */
5269 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5272 /* Small optimization: if we already have a stop reply for
5273 this thread, no use in telling the stub we want this
5275 if (peek_stop_reply (ptid
))
5281 write_ptid (p
, endp
, nptid
);
5284 /* In non-stop, we get an immediate OK reply. The stop reply will
5285 come in asynchronously by notification. */
5287 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5288 if (strcmp (rs
->buf
, "OK") != 0)
5289 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5292 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5293 remote target. It is undefined which thread of which process
5294 reports the stop. */
5297 remote_stop_as (ptid_t ptid
)
5299 struct remote_state
*rs
= get_remote_state ();
5301 rs
->ctrlc_pending_p
= 1;
5303 /* If the inferior is stopped already, but the core didn't know
5304 about it yet, just ignore the request. The cached wait status
5305 will be collected in remote_wait. */
5306 if (rs
->cached_wait_status
)
5309 /* Send interrupt_sequence to remote target. */
5310 send_interrupt_sequence ();
5313 /* This is the generic stop called via the target vector. When a target
5314 interrupt is requested, either by the command line or the GUI, we
5315 will eventually end up here. */
5318 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5321 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5324 remote_stop_ns (ptid
);
5326 remote_stop_as (ptid
);
5329 /* Ask the user what to do when an interrupt is received. */
5332 interrupt_query (void)
5334 target_terminal_ours ();
5336 if (target_is_async_p ())
5338 signal (SIGINT
, handle_sigint
);
5343 if (query (_("Interrupted while waiting for the program.\n\
5344 Give up (and stop debugging it)? ")))
5346 remote_unpush_target ();
5351 target_terminal_inferior ();
5354 /* Enable/disable target terminal ownership. Most targets can use
5355 terminal groups to control terminal ownership. Remote targets are
5356 different in that explicit transfer of ownership to/from GDB/target
5360 remote_terminal_inferior (struct target_ops
*self
)
5362 if (!target_async_permitted
)
5363 /* Nothing to do. */
5366 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5367 idempotent. The event-loop GDB talking to an asynchronous target
5368 with a synchronous command calls this function from both
5369 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5370 transfer the terminal to the target when it shouldn't this guard
5372 if (!remote_async_terminal_ours_p
)
5374 delete_file_handler (input_fd
);
5375 remote_async_terminal_ours_p
= 0;
5376 async_initialize_sigint_signal_handler ();
5377 /* NOTE: At this point we could also register our selves as the
5378 recipient of all input. Any characters typed could then be
5379 passed on down to the target. */
5383 remote_terminal_ours (struct target_ops
*self
)
5385 if (!target_async_permitted
)
5386 /* Nothing to do. */
5389 /* See FIXME in remote_terminal_inferior. */
5390 if (remote_async_terminal_ours_p
)
5392 async_cleanup_sigint_signal_handler (NULL
);
5393 add_file_handler (input_fd
, stdin_event_handler
, 0);
5394 remote_async_terminal_ours_p
= 1;
5398 remote_console_output (char *msg
)
5402 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5405 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5409 fputs_unfiltered (tb
, gdb_stdtarg
);
5411 gdb_flush (gdb_stdtarg
);
5414 typedef struct cached_reg
5417 gdb_byte data
[MAX_REGISTER_SIZE
];
5420 DEF_VEC_O(cached_reg_t
);
5422 typedef struct stop_reply
5424 struct notif_event base
;
5426 /* The identifier of the thread about this event */
5429 /* The remote state this event is associated with. When the remote
5430 connection, represented by a remote_state object, is closed,
5431 all the associated stop_reply events should be released. */
5432 struct remote_state
*rs
;
5434 struct target_waitstatus ws
;
5436 /* Expedited registers. This makes remote debugging a bit more
5437 efficient for those targets that provide critical registers as
5438 part of their normal status mechanism (as another roundtrip to
5439 fetch them is avoided). */
5440 VEC(cached_reg_t
) *regcache
;
5442 enum target_stop_reason stop_reason
;
5444 CORE_ADDR watch_data_address
;
5449 DECLARE_QUEUE_P (stop_reply_p
);
5450 DEFINE_QUEUE_P (stop_reply_p
);
5451 /* The list of already fetched and acknowledged stop events. This
5452 queue is used for notification Stop, and other notifications
5453 don't need queue for their events, because the notification events
5454 of Stop can't be consumed immediately, so that events should be
5455 queued first, and be consumed by remote_wait_{ns,as} one per
5456 time. Other notifications can consume their events immediately,
5457 so queue is not needed for them. */
5458 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5461 stop_reply_xfree (struct stop_reply
*r
)
5463 notif_event_xfree ((struct notif_event
*) r
);
5467 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5468 struct notif_event
*event
)
5470 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5474 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5475 struct notif_event
*event
)
5477 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5480 putpkt ((char *) self
->ack_command
);
5482 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5483 /* We got an unknown stop reply. */
5484 error (_("Unknown stop reply"));
5486 push_stop_reply (stop_reply
);
5490 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5492 /* We can't get pending events in remote_notif_process for
5493 notification stop, and we have to do this in remote_wait_ns
5494 instead. If we fetch all queued events from stub, remote stub
5495 may exit and we have no chance to process them back in
5497 mark_async_event_handler (remote_async_inferior_event_token
);
5502 stop_reply_dtr (struct notif_event
*event
)
5504 struct stop_reply
*r
= (struct stop_reply
*) event
;
5506 VEC_free (cached_reg_t
, r
->regcache
);
5509 static struct notif_event
*
5510 remote_notif_stop_alloc_reply (void)
5512 struct notif_event
*r
5513 = (struct notif_event
*) XNEW (struct stop_reply
);
5515 r
->dtr
= stop_reply_dtr
;
5520 /* A client of notification Stop. */
5522 struct notif_client notif_client_stop
=
5526 remote_notif_stop_parse
,
5527 remote_notif_stop_ack
,
5528 remote_notif_stop_can_get_pending_events
,
5529 remote_notif_stop_alloc_reply
,
5533 /* A parameter to pass data in and out. */
5535 struct queue_iter_param
5538 struct stop_reply
*output
;
5541 /* Determine if THREAD is a pending fork parent thread. ARG contains
5542 the pid of the process that owns the threads we want to check, or
5543 -1 if we want to check all threads. */
5546 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5549 if (ws
->kind
== TARGET_WAITKIND_FORKED
5550 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5552 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5559 /* Check whether EVENT is a fork event, and if it is, remove the
5560 fork child from the context list passed in DATA. */
5563 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5564 QUEUE_ITER (stop_reply_p
) *iter
,
5568 struct queue_iter_param
*param
= data
;
5569 struct threads_listing_context
*context
= param
->input
;
5571 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5572 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5574 threads_listing_context_remove (&event
->ws
, context
);
5580 /* If CONTEXT contains any fork child threads that have not been
5581 reported yet, remove them from the CONTEXT list. If such a
5582 thread exists it is because we are stopped at a fork catchpoint
5583 and have not yet called follow_fork, which will set up the
5584 host-side data structures for the new process. */
5587 remove_new_fork_children (struct threads_listing_context
*context
)
5589 struct thread_info
* thread
;
5591 struct notif_client
*notif
= ¬if_client_stop
;
5592 struct queue_iter_param param
;
5594 /* For any threads stopped at a fork event, remove the corresponding
5595 fork child threads from the CONTEXT list. */
5596 ALL_NON_EXITED_THREADS (thread
)
5598 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5600 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5602 threads_listing_context_remove (ws
, context
);
5606 /* Check for any pending fork events (not reported or processed yet)
5607 in process PID and remove those fork child threads from the
5608 CONTEXT list as well. */
5609 remote_notif_get_pending_events (notif
);
5610 param
.input
= context
;
5611 param
.output
= NULL
;
5612 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5613 remove_child_of_pending_fork
, ¶m
);
5616 /* Remove stop replies in the queue if its pid is equal to the given
5620 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5621 QUEUE_ITER (stop_reply_p
) *iter
,
5625 struct queue_iter_param
*param
= data
;
5626 struct inferior
*inf
= param
->input
;
5628 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5630 stop_reply_xfree (event
);
5631 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5637 /* Discard all pending stop replies of inferior INF. */
5640 discard_pending_stop_replies (struct inferior
*inf
)
5643 struct queue_iter_param param
;
5644 struct stop_reply
*reply
;
5645 struct remote_state
*rs
= get_remote_state ();
5646 struct remote_notif_state
*rns
= rs
->notif_state
;
5648 /* This function can be notified when an inferior exists. When the
5649 target is not remote, the notification state is NULL. */
5650 if (rs
->remote_desc
== NULL
)
5653 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5655 /* Discard the in-flight notification. */
5656 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5658 stop_reply_xfree (reply
);
5659 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5663 param
.output
= NULL
;
5664 /* Discard the stop replies we have already pulled with
5666 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5667 remove_stop_reply_for_inferior
, ¶m
);
5670 /* If its remote state is equal to the given remote state,
5671 remove EVENT from the stop reply queue. */
5674 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5675 QUEUE_ITER (stop_reply_p
) *iter
,
5679 struct queue_iter_param
*param
= data
;
5680 struct remote_state
*rs
= param
->input
;
5682 if (event
->rs
== rs
)
5684 stop_reply_xfree (event
);
5685 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5691 /* Discard the stop replies for RS in stop_reply_queue. */
5694 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5696 struct queue_iter_param param
;
5699 param
.output
= NULL
;
5700 /* Discard the stop replies we have already pulled with
5702 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5703 remove_stop_reply_of_remote_state
, ¶m
);
5706 /* A parameter to pass data in and out. */
5709 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5710 QUEUE_ITER (stop_reply_p
) *iter
,
5714 struct queue_iter_param
*param
= data
;
5715 ptid_t
*ptid
= param
->input
;
5717 if (ptid_match (event
->ptid
, *ptid
))
5719 param
->output
= event
;
5720 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5727 /* Remove the first reply in 'stop_reply_queue' which matches
5730 static struct stop_reply
*
5731 remote_notif_remove_queued_reply (ptid_t ptid
)
5733 struct queue_iter_param param
;
5735 param
.input
= &ptid
;
5736 param
.output
= NULL
;
5738 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5739 remote_notif_remove_once_on_match
, ¶m
);
5741 fprintf_unfiltered (gdb_stdlog
,
5742 "notif: discard queued event: 'Stop' in %s\n",
5743 target_pid_to_str (ptid
));
5745 return param
.output
;
5748 /* Look for a queued stop reply belonging to PTID. If one is found,
5749 remove it from the queue, and return it. Returns NULL if none is
5750 found. If there are still queued events left to process, tell the
5751 event loop to get back to target_wait soon. */
5753 static struct stop_reply
*
5754 queued_stop_reply (ptid_t ptid
)
5756 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5758 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5759 /* There's still at least an event left. */
5760 mark_async_event_handler (remote_async_inferior_event_token
);
5765 /* Push a fully parsed stop reply in the stop reply queue. Since we
5766 know that we now have at least one queued event left to pass to the
5767 core side, tell the event loop to get back to target_wait soon. */
5770 push_stop_reply (struct stop_reply
*new_event
)
5772 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5775 fprintf_unfiltered (gdb_stdlog
,
5776 "notif: push 'Stop' %s to queue %d\n",
5777 target_pid_to_str (new_event
->ptid
),
5778 QUEUE_length (stop_reply_p
,
5781 mark_async_event_handler (remote_async_inferior_event_token
);
5785 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5786 QUEUE_ITER (stop_reply_p
) *iter
,
5787 struct stop_reply
*event
,
5790 ptid_t
*ptid
= data
;
5792 return !(ptid_equal (*ptid
, event
->ptid
)
5793 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5796 /* Returns true if we have a stop reply for PTID. */
5799 peek_stop_reply (ptid_t ptid
)
5801 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5802 stop_reply_match_ptid_and_ws
, &ptid
);
5805 /* Skip PACKET until the next semi-colon (or end of string). */
5808 skip_to_semicolon (char *p
)
5810 while (*p
!= '\0' && *p
!= ';')
5815 /* Parse the stop reply in BUF. Either the function succeeds, and the
5816 result is stored in EVENT, or throws an error. */
5819 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5821 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5825 event
->ptid
= null_ptid
;
5826 event
->rs
= get_remote_state ();
5827 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5828 event
->ws
.value
.integer
= 0;
5829 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5830 event
->regcache
= NULL
;
5835 case 'T': /* Status with PC, SP, FP, ... */
5836 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5837 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5839 n... = register number
5840 r... = register contents
5843 p
= &buf
[3]; /* after Txx */
5849 p1
= strchr (p
, ':');
5851 error (_("Malformed packet(a) (missing colon): %s\n\
5855 error (_("Malformed packet(a) (missing register number): %s\n\
5859 /* Some "registers" are actually extended stop information.
5860 Note if you're adding a new entry here: GDB 7.9 and
5861 earlier assume that all register "numbers" that start
5862 with an hex digit are real register numbers. Make sure
5863 the server only sends such a packet if it knows the
5864 client understands it. */
5866 if (strncmp (p
, "thread", p1
- p
) == 0)
5867 event
->ptid
= read_ptid (++p1
, &p
);
5868 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5869 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5870 || (strncmp (p
, "awatch", p1
- p
) == 0))
5872 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
5873 p
= unpack_varlen_hex (++p1
, &addr
);
5874 event
->watch_data_address
= (CORE_ADDR
) addr
;
5876 else if (strncmp (p
, "swbreak", p1
- p
) == 0)
5878 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
5880 /* Make sure the stub doesn't forget to indicate support
5882 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
5883 error (_("Unexpected swbreak stop reason"));
5885 /* The value part is documented as "must be empty",
5886 though we ignore it, in case we ever decide to make
5887 use of it in a backward compatible way. */
5888 p
= skip_to_semicolon (p1
+ 1);
5890 else if (strncmp (p
, "hwbreak", p1
- p
) == 0)
5892 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
5894 /* Make sure the stub doesn't forget to indicate support
5896 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
5897 error (_("Unexpected hwbreak stop reason"));
5900 p
= skip_to_semicolon (p1
+ 1);
5902 else if (strncmp (p
, "library", p1
- p
) == 0)
5904 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5905 p
= skip_to_semicolon (p1
+ 1);
5907 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5909 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5910 /* p1 will indicate "begin" or "end", but it makes
5911 no difference for now, so ignore it. */
5912 p
= skip_to_semicolon (p1
+ 1);
5914 else if (strncmp (p
, "core", p1
- p
) == 0)
5918 p
= unpack_varlen_hex (++p1
, &c
);
5921 else if (strncmp (p
, "fork", p1
- p
) == 0)
5923 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5924 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
5926 else if (strncmp (p
, "vfork", p1
- p
) == 0)
5928 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5929 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
5931 else if (strncmp (p
, "vforkdone", p1
- p
) == 0)
5933 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
5934 p
= skip_to_semicolon (p1
+ 1);
5941 /* Maybe a real ``P'' register number. */
5942 p_temp
= unpack_varlen_hex (p
, &pnum
);
5943 /* If the first invalid character is the colon, we got a
5944 register number. Otherwise, it's an unknown stop
5948 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5949 cached_reg_t cached_reg
;
5952 error (_("Remote sent bad register number %s: %s\n\
5954 hex_string (pnum
), p
, buf
);
5956 cached_reg
.num
= reg
->regnum
;
5959 fieldsize
= hex2bin (p
, cached_reg
.data
,
5960 register_size (target_gdbarch (),
5963 if (fieldsize
< register_size (target_gdbarch (),
5965 warning (_("Remote reply is too short: %s"), buf
);
5967 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5971 /* Not a number. Silently skip unknown optional
5973 p
= skip_to_semicolon (p1
+ 1);
5978 error (_("Remote register badly formatted: %s\nhere: %s"),
5983 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5987 case 'S': /* Old style status, just signal only. */
5991 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5992 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5993 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5994 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5996 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5999 case 'W': /* Target exited. */
6006 /* GDB used to accept only 2 hex chars here. Stubs should
6007 only send more if they detect GDB supports multi-process
6009 p
= unpack_varlen_hex (&buf
[1], &value
);
6013 /* The remote process exited. */
6014 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6015 event
->ws
.value
.integer
= value
;
6019 /* The remote process exited with a signal. */
6020 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6021 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6022 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6024 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6027 /* If no process is specified, assume inferior_ptid. */
6028 pid
= ptid_get_pid (inferior_ptid
);
6037 else if (startswith (p
, "process:"))
6041 p
+= sizeof ("process:") - 1;
6042 unpack_varlen_hex (p
, &upid
);
6046 error (_("unknown stop reply packet: %s"), buf
);
6049 error (_("unknown stop reply packet: %s"), buf
);
6050 event
->ptid
= pid_to_ptid (pid
);
6055 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6056 error (_("No process or thread specified in stop reply: %s"), buf
);
6059 /* When the stub wants to tell GDB about a new notification reply, it
6060 sends a notification (%Stop, for example). Those can come it at
6061 any time, hence, we have to make sure that any pending
6062 putpkt/getpkt sequence we're making is finished, before querying
6063 the stub for more events with the corresponding ack command
6064 (vStopped, for example). E.g., if we started a vStopped sequence
6065 immediately upon receiving the notification, something like this
6073 1.6) <-- (registers reply to step #1.3)
6075 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6078 To solve this, whenever we parse a %Stop notification successfully,
6079 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6080 doing whatever we were doing:
6086 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6087 2.5) <-- (registers reply to step #2.3)
6089 Eventualy after step #2.5, we return to the event loop, which
6090 notices there's an event on the
6091 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6092 associated callback --- the function below. At this point, we're
6093 always safe to start a vStopped sequence. :
6096 2.7) <-- T05 thread:2
6102 remote_notif_get_pending_events (struct notif_client
*nc
)
6104 struct remote_state
*rs
= get_remote_state ();
6106 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6109 fprintf_unfiltered (gdb_stdlog
,
6110 "notif: process: '%s' ack pending event\n",
6114 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6115 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6119 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6120 if (strcmp (rs
->buf
, "OK") == 0)
6123 remote_notif_ack (nc
, rs
->buf
);
6129 fprintf_unfiltered (gdb_stdlog
,
6130 "notif: process: '%s' no pending reply\n",
6135 /* Called when it is decided that STOP_REPLY holds the info of the
6136 event that is to be returned to the core. This function always
6137 destroys STOP_REPLY. */
6140 process_stop_reply (struct stop_reply
*stop_reply
,
6141 struct target_waitstatus
*status
)
6145 *status
= stop_reply
->ws
;
6146 ptid
= stop_reply
->ptid
;
6148 /* If no thread/process was reported by the stub, assume the current
6150 if (ptid_equal (ptid
, null_ptid
))
6151 ptid
= inferior_ptid
;
6153 if (status
->kind
!= TARGET_WAITKIND_EXITED
6154 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6156 struct remote_state
*rs
= get_remote_state ();
6158 /* Expedited registers. */
6159 if (stop_reply
->regcache
)
6161 struct regcache
*regcache
6162 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6167 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6169 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6170 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6173 rs
->stop_reason
= stop_reply
->stop_reason
;
6174 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6176 remote_notice_new_inferior (ptid
, 0);
6177 demand_private_info (ptid
)->core
= stop_reply
->core
;
6180 stop_reply_xfree (stop_reply
);
6184 /* The non-stop mode version of target_wait. */
6187 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6189 struct remote_state
*rs
= get_remote_state ();
6190 struct stop_reply
*stop_reply
;
6194 /* If in non-stop mode, get out of getpkt even if a
6195 notification is received. */
6197 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6198 0 /* forever */, &is_notif
);
6201 if (ret
!= -1 && !is_notif
)
6204 case 'E': /* Error of some sort. */
6205 /* We're out of sync with the target now. Did it continue
6206 or not? We can't tell which thread it was in non-stop,
6207 so just ignore this. */
6208 warning (_("Remote failure reply: %s"), rs
->buf
);
6210 case 'O': /* Console output. */
6211 remote_console_output (rs
->buf
+ 1);
6214 warning (_("Invalid remote reply: %s"), rs
->buf
);
6218 /* Acknowledge a pending stop reply that may have arrived in the
6220 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6221 remote_notif_get_pending_events (¬if_client_stop
);
6223 /* If indeed we noticed a stop reply, we're done. */
6224 stop_reply
= queued_stop_reply (ptid
);
6225 if (stop_reply
!= NULL
)
6226 return process_stop_reply (stop_reply
, status
);
6228 /* Still no event. If we're just polling for an event, then
6229 return to the event loop. */
6230 if (options
& TARGET_WNOHANG
)
6232 status
->kind
= TARGET_WAITKIND_IGNORE
;
6233 return minus_one_ptid
;
6236 /* Otherwise do a blocking wait. */
6237 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6238 1 /* forever */, &is_notif
);
6242 /* Wait until the remote machine stops, then return, storing status in
6243 STATUS just as `wait' would. */
6246 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6248 struct remote_state
*rs
= get_remote_state ();
6249 ptid_t event_ptid
= null_ptid
;
6251 struct stop_reply
*stop_reply
;
6255 status
->kind
= TARGET_WAITKIND_IGNORE
;
6256 status
->value
.integer
= 0;
6258 stop_reply
= queued_stop_reply (ptid
);
6259 if (stop_reply
!= NULL
)
6260 return process_stop_reply (stop_reply
, status
);
6262 if (rs
->cached_wait_status
)
6263 /* Use the cached wait status, but only once. */
6264 rs
->cached_wait_status
= 0;
6270 if (!target_is_async_p ())
6272 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6273 /* If the user hit C-c before this packet, or between packets,
6274 pretend that it was hit right here. */
6275 if (check_quit_flag ())
6278 sync_remote_interrupt (SIGINT
);
6282 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6283 _never_ wait for ever -> test on target_is_async_p().
6284 However, before we do that we need to ensure that the caller
6285 knows how to take the target into/out of async mode. */
6286 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6287 wait_forever_enabled_p
, &is_notif
);
6289 if (!target_is_async_p ())
6290 signal (SIGINT
, ofunc
);
6292 /* GDB gets a notification. Return to core as this event is
6294 if (ret
!= -1 && is_notif
)
6295 return minus_one_ptid
;
6300 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6302 /* We got something. */
6303 rs
->waiting_for_stop_reply
= 0;
6305 /* Assume that the target has acknowledged Ctrl-C unless we receive
6306 an 'F' or 'O' packet. */
6307 if (buf
[0] != 'F' && buf
[0] != 'O')
6308 rs
->ctrlc_pending_p
= 0;
6312 case 'E': /* Error of some sort. */
6313 /* We're out of sync with the target now. Did it continue or
6314 not? Not is more likely, so report a stop. */
6315 warning (_("Remote failure reply: %s"), buf
);
6316 status
->kind
= TARGET_WAITKIND_STOPPED
;
6317 status
->value
.sig
= GDB_SIGNAL_0
;
6319 case 'F': /* File-I/O request. */
6320 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6321 rs
->ctrlc_pending_p
= 0;
6323 case 'T': case 'S': case 'X': case 'W':
6325 struct stop_reply
*stop_reply
6326 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6329 event_ptid
= process_stop_reply (stop_reply
, status
);
6332 case 'O': /* Console output. */
6333 remote_console_output (buf
+ 1);
6335 /* The target didn't really stop; keep waiting. */
6336 rs
->waiting_for_stop_reply
= 1;
6340 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6342 /* Zero length reply means that we tried 'S' or 'C' and the
6343 remote system doesn't support it. */
6344 target_terminal_ours_for_output ();
6346 ("Can't send signals to this remote system. %s not sent.\n",
6347 gdb_signal_to_name (rs
->last_sent_signal
));
6348 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6349 target_terminal_inferior ();
6351 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6352 putpkt ((char *) buf
);
6354 /* We just told the target to resume, so a stop reply is in
6356 rs
->waiting_for_stop_reply
= 1;
6359 /* else fallthrough */
6361 warning (_("Invalid remote reply: %s"), buf
);
6363 rs
->waiting_for_stop_reply
= 1;
6367 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6369 /* Nothing interesting happened. If we're doing a non-blocking
6370 poll, we're done. Otherwise, go back to waiting. */
6371 if (options
& TARGET_WNOHANG
)
6372 return minus_one_ptid
;
6376 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6377 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6379 if (!ptid_equal (event_ptid
, null_ptid
))
6380 record_currthread (rs
, event_ptid
);
6382 event_ptid
= inferior_ptid
;
6385 /* A process exit. Invalidate our notion of current thread. */
6386 record_currthread (rs
, minus_one_ptid
);
6391 /* Wait until the remote machine stops, then return, storing status in
6392 STATUS just as `wait' would. */
6395 remote_wait (struct target_ops
*ops
,
6396 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6401 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6403 event_ptid
= remote_wait_as (ptid
, status
, options
);
6405 if (target_is_async_p ())
6407 /* If there are are events left in the queue tell the event loop
6409 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6410 mark_async_event_handler (remote_async_inferior_event_token
);
6416 /* Fetch a single register using a 'p' packet. */
6419 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6421 struct remote_state
*rs
= get_remote_state ();
6423 char regp
[MAX_REGISTER_SIZE
];
6426 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6429 if (reg
->pnum
== -1)
6434 p
+= hexnumstr (p
, reg
->pnum
);
6437 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6441 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6445 case PACKET_UNKNOWN
:
6448 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6449 gdbarch_register_name (get_regcache_arch (regcache
),
6454 /* If this register is unfetchable, tell the regcache. */
6457 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6461 /* Otherwise, parse and supply the value. */
6467 error (_("fetch_register_using_p: early buf termination"));
6469 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6472 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6476 /* Fetch the registers included in the target's 'g' packet. */
6479 send_g_packet (void)
6481 struct remote_state
*rs
= get_remote_state ();
6484 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6485 remote_send (&rs
->buf
, &rs
->buf_size
);
6487 /* We can get out of synch in various cases. If the first character
6488 in the buffer is not a hex character, assume that has happened
6489 and try to fetch another packet to read. */
6490 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6491 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6492 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6493 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6496 fprintf_unfiltered (gdb_stdlog
,
6497 "Bad register packet; fetching a new packet\n");
6498 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6501 buf_len
= strlen (rs
->buf
);
6503 /* Sanity check the received packet. */
6504 if (buf_len
% 2 != 0)
6505 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6511 process_g_packet (struct regcache
*regcache
)
6513 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6514 struct remote_state
*rs
= get_remote_state ();
6515 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6520 buf_len
= strlen (rs
->buf
);
6522 /* Further sanity checks, with knowledge of the architecture. */
6523 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6524 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6526 /* Save the size of the packet sent to us by the target. It is used
6527 as a heuristic when determining the max size of packets that the
6528 target can safely receive. */
6529 if (rsa
->actual_register_packet_size
== 0)
6530 rsa
->actual_register_packet_size
= buf_len
;
6532 /* If this is smaller than we guessed the 'g' packet would be,
6533 update our records. A 'g' reply that doesn't include a register's
6534 value implies either that the register is not available, or that
6535 the 'p' packet must be used. */
6536 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6538 rsa
->sizeof_g_packet
= buf_len
/ 2;
6540 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6542 if (rsa
->regs
[i
].pnum
== -1)
6545 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6546 rsa
->regs
[i
].in_g_packet
= 0;
6548 rsa
->regs
[i
].in_g_packet
= 1;
6552 regs
= alloca (rsa
->sizeof_g_packet
);
6554 /* Unimplemented registers read as all bits zero. */
6555 memset (regs
, 0, rsa
->sizeof_g_packet
);
6557 /* Reply describes registers byte by byte, each byte encoded as two
6558 hex characters. Suck them all up, then supply them to the
6559 register cacheing/storage mechanism. */
6562 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6564 if (p
[0] == 0 || p
[1] == 0)
6565 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6566 internal_error (__FILE__
, __LINE__
,
6567 _("unexpected end of 'g' packet reply"));
6569 if (p
[0] == 'x' && p
[1] == 'x')
6570 regs
[i
] = 0; /* 'x' */
6572 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6576 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6578 struct packet_reg
*r
= &rsa
->regs
[i
];
6582 if (r
->offset
* 2 >= strlen (rs
->buf
))
6583 /* This shouldn't happen - we adjusted in_g_packet above. */
6584 internal_error (__FILE__
, __LINE__
,
6585 _("unexpected end of 'g' packet reply"));
6586 else if (rs
->buf
[r
->offset
* 2] == 'x')
6588 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6589 /* The register isn't available, mark it as such (at
6590 the same time setting the value to zero). */
6591 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6594 regcache_raw_supply (regcache
, r
->regnum
,
6601 fetch_registers_using_g (struct regcache
*regcache
)
6604 process_g_packet (regcache
);
6607 /* Make the remote selected traceframe match GDB's selected
6611 set_remote_traceframe (void)
6614 struct remote_state
*rs
= get_remote_state ();
6616 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6619 /* Avoid recursion, remote_trace_find calls us again. */
6620 rs
->remote_traceframe_number
= get_traceframe_number ();
6622 newnum
= target_trace_find (tfind_number
,
6623 get_traceframe_number (), 0, 0, NULL
);
6625 /* Should not happen. If it does, all bets are off. */
6626 if (newnum
!= get_traceframe_number ())
6627 warning (_("could not set remote traceframe"));
6631 remote_fetch_registers (struct target_ops
*ops
,
6632 struct regcache
*regcache
, int regnum
)
6634 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6637 set_remote_traceframe ();
6638 set_general_thread (inferior_ptid
);
6642 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6644 gdb_assert (reg
!= NULL
);
6646 /* If this register might be in the 'g' packet, try that first -
6647 we are likely to read more than one register. If this is the
6648 first 'g' packet, we might be overly optimistic about its
6649 contents, so fall back to 'p'. */
6650 if (reg
->in_g_packet
)
6652 fetch_registers_using_g (regcache
);
6653 if (reg
->in_g_packet
)
6657 if (fetch_register_using_p (regcache
, reg
))
6660 /* This register is not available. */
6661 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6666 fetch_registers_using_g (regcache
);
6668 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6669 if (!rsa
->regs
[i
].in_g_packet
)
6670 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6672 /* This register is not available. */
6673 regcache_raw_supply (regcache
, i
, NULL
);
6677 /* Prepare to store registers. Since we may send them all (using a
6678 'G' request), we have to read out the ones we don't want to change
6682 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6684 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6686 gdb_byte buf
[MAX_REGISTER_SIZE
];
6688 /* Make sure the entire registers array is valid. */
6689 switch (packet_support (PACKET_P
))
6691 case PACKET_DISABLE
:
6692 case PACKET_SUPPORT_UNKNOWN
:
6693 /* Make sure all the necessary registers are cached. */
6694 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6695 if (rsa
->regs
[i
].in_g_packet
)
6696 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6703 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6704 packet was not recognized. */
6707 store_register_using_P (const struct regcache
*regcache
,
6708 struct packet_reg
*reg
)
6710 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6711 struct remote_state
*rs
= get_remote_state ();
6712 /* Try storing a single register. */
6713 char *buf
= rs
->buf
;
6714 gdb_byte regp
[MAX_REGISTER_SIZE
];
6717 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6720 if (reg
->pnum
== -1)
6723 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6724 p
= buf
+ strlen (buf
);
6725 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6726 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6730 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6735 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6736 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6737 case PACKET_UNKNOWN
:
6740 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6744 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6745 contents of the register cache buffer. FIXME: ignores errors. */
6748 store_registers_using_G (const struct regcache
*regcache
)
6750 struct remote_state
*rs
= get_remote_state ();
6751 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6755 /* Extract all the registers in the regcache copying them into a
6760 regs
= alloca (rsa
->sizeof_g_packet
);
6761 memset (regs
, 0, rsa
->sizeof_g_packet
);
6762 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6764 struct packet_reg
*r
= &rsa
->regs
[i
];
6767 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6771 /* Command describes registers byte by byte,
6772 each byte encoded as two hex characters. */
6775 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6777 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6779 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6780 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6781 error (_("Could not write registers; remote failure reply '%s'"),
6785 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6786 of the register cache buffer. FIXME: ignores errors. */
6789 remote_store_registers (struct target_ops
*ops
,
6790 struct regcache
*regcache
, int regnum
)
6792 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6795 set_remote_traceframe ();
6796 set_general_thread (inferior_ptid
);
6800 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6802 gdb_assert (reg
!= NULL
);
6804 /* Always prefer to store registers using the 'P' packet if
6805 possible; we often change only a small number of registers.
6806 Sometimes we change a larger number; we'd need help from a
6807 higher layer to know to use 'G'. */
6808 if (store_register_using_P (regcache
, reg
))
6811 /* For now, don't complain if we have no way to write the
6812 register. GDB loses track of unavailable registers too
6813 easily. Some day, this may be an error. We don't have
6814 any way to read the register, either... */
6815 if (!reg
->in_g_packet
)
6818 store_registers_using_G (regcache
);
6822 store_registers_using_G (regcache
);
6824 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6825 if (!rsa
->regs
[i
].in_g_packet
)
6826 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6827 /* See above for why we do not issue an error here. */
6832 /* Return the number of hex digits in num. */
6835 hexnumlen (ULONGEST num
)
6839 for (i
= 0; num
!= 0; i
++)
6845 /* Set BUF to the minimum number of hex digits representing NUM. */
6848 hexnumstr (char *buf
, ULONGEST num
)
6850 int len
= hexnumlen (num
);
6852 return hexnumnstr (buf
, num
, len
);
6856 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6859 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6865 for (i
= width
- 1; i
>= 0; i
--)
6867 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6874 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6877 remote_address_masked (CORE_ADDR addr
)
6879 unsigned int address_size
= remote_address_size
;
6881 /* If "remoteaddresssize" was not set, default to target address size. */
6883 address_size
= gdbarch_addr_bit (target_gdbarch ());
6885 if (address_size
> 0
6886 && address_size
< (sizeof (ULONGEST
) * 8))
6888 /* Only create a mask when that mask can safely be constructed
6889 in a ULONGEST variable. */
6892 mask
= (mask
<< address_size
) - 1;
6898 /* Determine whether the remote target supports binary downloading.
6899 This is accomplished by sending a no-op memory write of zero length
6900 to the target at the specified address. It does not suffice to send
6901 the whole packet, since many stubs strip the eighth bit and
6902 subsequently compute a wrong checksum, which causes real havoc with
6905 NOTE: This can still lose if the serial line is not eight-bit
6906 clean. In cases like this, the user should clear "remote
6910 check_binary_download (CORE_ADDR addr
)
6912 struct remote_state
*rs
= get_remote_state ();
6914 switch (packet_support (PACKET_X
))
6916 case PACKET_DISABLE
:
6920 case PACKET_SUPPORT_UNKNOWN
:
6926 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6928 p
+= hexnumstr (p
, (ULONGEST
) 0);
6932 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6933 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6935 if (rs
->buf
[0] == '\0')
6938 fprintf_unfiltered (gdb_stdlog
,
6939 "binary downloading NOT "
6940 "supported by target\n");
6941 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6946 fprintf_unfiltered (gdb_stdlog
,
6947 "binary downloading supported by target\n");
6948 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6955 /* Helper function to resize the payload in order to try to get a good
6956 alignment. We try to write an amount of data such that the next write will
6957 start on an address aligned on REMOTE_ALIGN_WRITES. */
6960 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
6962 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6965 /* Write memory data directly to the remote machine.
6966 This does not inform the data cache; the data cache uses this.
6967 HEADER is the starting part of the packet.
6968 MEMADDR is the address in the remote memory space.
6969 MYADDR is the address of the buffer in our space.
6970 LEN_UNITS is the number of addressable units to write.
6971 UNIT_SIZE is the length in bytes of an addressable unit.
6972 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6973 should send data as binary ('X'), or hex-encoded ('M').
6975 The function creates packet of the form
6976 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6978 where encoding of <DATA> is terminated by PACKET_FORMAT.
6980 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6983 Return the transferred status, error or OK (an
6984 'enum target_xfer_status' value). Save the number of addressable units
6985 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
6987 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
6988 exchange between gdb and the stub could look like (?? in place of the
6994 -> $M1000,3:eeeeffffeeee#??
6998 <- eeeeffffeeeedddd */
7000 static enum target_xfer_status
7001 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7002 const gdb_byte
*myaddr
, ULONGEST len_units
,
7003 int unit_size
, ULONGEST
*xfered_len_units
,
7004 char packet_format
, int use_length
)
7006 struct remote_state
*rs
= get_remote_state ();
7012 int payload_capacity_bytes
;
7013 int payload_length_bytes
;
7015 if (packet_format
!= 'X' && packet_format
!= 'M')
7016 internal_error (__FILE__
, __LINE__
,
7017 _("remote_write_bytes_aux: bad packet format"));
7020 return TARGET_XFER_EOF
;
7022 payload_capacity_bytes
= get_memory_write_packet_size ();
7024 /* The packet buffer will be large enough for the payload;
7025 get_memory_packet_size ensures this. */
7028 /* Compute the size of the actual payload by subtracting out the
7029 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7031 payload_capacity_bytes
-= strlen ("$,:#NN");
7033 /* The comma won't be used. */
7034 payload_capacity_bytes
+= 1;
7035 payload_capacity_bytes
-= strlen (header
);
7036 payload_capacity_bytes
-= hexnumlen (memaddr
);
7038 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7040 strcat (rs
->buf
, header
);
7041 p
= rs
->buf
+ strlen (header
);
7043 /* Compute a best guess of the number of bytes actually transfered. */
7044 if (packet_format
== 'X')
7046 /* Best guess at number of bytes that will fit. */
7047 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7049 payload_capacity_bytes
-= hexnumlen (todo_units
);
7050 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7054 /* Number of bytes that will fit. */
7055 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7057 payload_capacity_bytes
-= hexnumlen (todo_units
);
7058 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7061 if (todo_units
<= 0)
7062 internal_error (__FILE__
, __LINE__
,
7063 _("minimum packet size too small to write data"));
7065 /* If we already need another packet, then try to align the end
7066 of this packet to a useful boundary. */
7067 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7068 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7070 /* Append "<memaddr>". */
7071 memaddr
= remote_address_masked (memaddr
);
7072 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7079 /* Append the length and retain its location and size. It may need to be
7080 adjusted once the packet body has been created. */
7082 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7090 /* Append the packet body. */
7091 if (packet_format
== 'X')
7093 /* Binary mode. Send target system values byte by byte, in
7094 increasing byte addresses. Only escape certain critical
7096 payload_length_bytes
=
7097 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7098 &units_written
, payload_capacity_bytes
);
7100 /* If not all TODO units fit, then we'll need another packet. Make
7101 a second try to keep the end of the packet aligned. Don't do
7102 this if the packet is tiny. */
7103 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7107 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7109 if (new_todo_units
!= units_written
)
7110 payload_length_bytes
=
7111 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7112 (gdb_byte
*) p
, &units_written
,
7113 payload_capacity_bytes
);
7116 p
+= payload_length_bytes
;
7117 if (use_length
&& units_written
< todo_units
)
7119 /* Escape chars have filled up the buffer prematurely,
7120 and we have actually sent fewer units than planned.
7121 Fix-up the length field of the packet. Use the same
7122 number of characters as before. */
7123 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7125 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7130 /* Normal mode: Send target system values byte by byte, in
7131 increasing byte addresses. Each byte is encoded as a two hex
7133 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7134 units_written
= todo_units
;
7137 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7138 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7140 if (rs
->buf
[0] == 'E')
7141 return TARGET_XFER_E_IO
;
7143 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7144 send fewer units than we'd planned. */
7145 *xfered_len_units
= (ULONGEST
) units_written
;
7146 return TARGET_XFER_OK
;
7149 /* Write memory data directly to the remote machine.
7150 This does not inform the data cache; the data cache uses this.
7151 MEMADDR is the address in the remote memory space.
7152 MYADDR is the address of the buffer in our space.
7153 LEN is the number of bytes.
7155 Return the transferred status, error or OK (an
7156 'enum target_xfer_status' value). Save the number of bytes
7157 transferred in *XFERED_LEN. Only transfer a single packet. */
7159 static enum target_xfer_status
7160 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7161 int unit_size
, ULONGEST
*xfered_len
)
7163 char *packet_format
= 0;
7165 /* Check whether the target supports binary download. */
7166 check_binary_download (memaddr
);
7168 switch (packet_support (PACKET_X
))
7171 packet_format
= "X";
7173 case PACKET_DISABLE
:
7174 packet_format
= "M";
7176 case PACKET_SUPPORT_UNKNOWN
:
7177 internal_error (__FILE__
, __LINE__
,
7178 _("remote_write_bytes: bad internal state"));
7180 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7183 return remote_write_bytes_aux (packet_format
,
7184 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7185 packet_format
[0], 1);
7188 /* Read memory data directly from the remote machine.
7189 This does not use the data cache; the data cache uses this.
7190 MEMADDR is the address in the remote memory space.
7191 MYADDR is the address of the buffer in our space.
7192 LEN_UNITS is the number of addressable memory units to read..
7193 UNIT_SIZE is the length in bytes of an addressable unit.
7195 Return the transferred status, error or OK (an
7196 'enum target_xfer_status' value). Save the number of bytes
7197 transferred in *XFERED_LEN_UNITS.
7199 See the comment of remote_write_bytes_aux for an example of
7200 memory read/write exchange between gdb and the stub. */
7202 static enum target_xfer_status
7203 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7204 int unit_size
, ULONGEST
*xfered_len_units
)
7206 struct remote_state
*rs
= get_remote_state ();
7207 int buf_size_bytes
; /* Max size of packet output buffer. */
7212 buf_size_bytes
= get_memory_read_packet_size ();
7213 /* The packet buffer will be large enough for the payload;
7214 get_memory_packet_size ensures this. */
7216 /* Number of units that will fit. */
7217 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7219 /* Construct "m"<memaddr>","<len>". */
7220 memaddr
= remote_address_masked (memaddr
);
7223 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7225 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7228 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7229 if (rs
->buf
[0] == 'E'
7230 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7231 && rs
->buf
[3] == '\0')
7232 return TARGET_XFER_E_IO
;
7233 /* Reply describes memory byte by byte, each byte encoded as two hex
7236 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7237 /* Return what we have. Let higher layers handle partial reads. */
7238 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7239 return TARGET_XFER_OK
;
7242 /* Using the set of read-only target sections of remote, read live
7245 For interface/parameters/return description see target.h,
7248 static enum target_xfer_status
7249 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7250 ULONGEST memaddr
, ULONGEST len
,
7251 int unit_size
, ULONGEST
*xfered_len
)
7253 struct target_section
*secp
;
7254 struct target_section_table
*table
;
7256 secp
= target_section_by_addr (ops
, memaddr
);
7258 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7259 secp
->the_bfd_section
)
7262 struct target_section
*p
;
7263 ULONGEST memend
= memaddr
+ len
;
7265 table
= target_get_section_table (ops
);
7267 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7269 if (memaddr
>= p
->addr
)
7271 if (memend
<= p
->endaddr
)
7273 /* Entire transfer is within this section. */
7274 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7277 else if (memaddr
>= p
->endaddr
)
7279 /* This section ends before the transfer starts. */
7284 /* This section overlaps the transfer. Just do half. */
7285 len
= p
->endaddr
- memaddr
;
7286 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7293 return TARGET_XFER_EOF
;
7296 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7297 first if the requested memory is unavailable in traceframe.
7298 Otherwise, fall back to remote_read_bytes_1. */
7300 static enum target_xfer_status
7301 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7302 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7303 ULONGEST
*xfered_len
)
7306 return TARGET_XFER_EOF
;
7308 if (get_traceframe_number () != -1)
7310 VEC(mem_range_s
) *available
;
7312 /* If we fail to get the set of available memory, then the
7313 target does not support querying traceframe info, and so we
7314 attempt reading from the traceframe anyway (assuming the
7315 target implements the old QTro packet then). */
7316 if (traceframe_available_memory (&available
, memaddr
, len
))
7318 struct cleanup
*old_chain
;
7320 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7322 if (VEC_empty (mem_range_s
, available
)
7323 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7325 enum target_xfer_status res
;
7327 /* Don't read into the traceframe's available
7329 if (!VEC_empty (mem_range_s
, available
))
7331 LONGEST oldlen
= len
;
7333 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7334 gdb_assert (len
<= oldlen
);
7337 do_cleanups (old_chain
);
7339 /* This goes through the topmost target again. */
7340 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7341 len
, unit_size
, xfered_len
);
7342 if (res
== TARGET_XFER_OK
)
7343 return TARGET_XFER_OK
;
7346 /* No use trying further, we know some memory starting
7347 at MEMADDR isn't available. */
7349 return TARGET_XFER_UNAVAILABLE
;
7353 /* Don't try to read more than how much is available, in
7354 case the target implements the deprecated QTro packet to
7355 cater for older GDBs (the target's knowledge of read-only
7356 sections may be outdated by now). */
7357 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7359 do_cleanups (old_chain
);
7363 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7368 /* Sends a packet with content determined by the printf format string
7369 FORMAT and the remaining arguments, then gets the reply. Returns
7370 whether the packet was a success, a failure, or unknown. */
7372 static enum packet_result
remote_send_printf (const char *format
, ...)
7373 ATTRIBUTE_PRINTF (1, 2);
7375 static enum packet_result
7376 remote_send_printf (const char *format
, ...)
7378 struct remote_state
*rs
= get_remote_state ();
7379 int max_size
= get_remote_packet_size ();
7382 va_start (ap
, format
);
7385 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7386 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7388 if (putpkt (rs
->buf
) < 0)
7389 error (_("Communication problem with target."));
7392 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7394 return packet_check_result (rs
->buf
);
7398 restore_remote_timeout (void *p
)
7400 int value
= *(int *)p
;
7402 remote_timeout
= value
;
7405 /* Flash writing can take quite some time. We'll set
7406 effectively infinite timeout for flash operations.
7407 In future, we'll need to decide on a better approach. */
7408 static const int remote_flash_timeout
= 1000;
7411 remote_flash_erase (struct target_ops
*ops
,
7412 ULONGEST address
, LONGEST length
)
7414 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7415 int saved_remote_timeout
= remote_timeout
;
7416 enum packet_result ret
;
7417 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7418 &saved_remote_timeout
);
7420 remote_timeout
= remote_flash_timeout
;
7422 ret
= remote_send_printf ("vFlashErase:%s,%s",
7423 phex (address
, addr_size
),
7427 case PACKET_UNKNOWN
:
7428 error (_("Remote target does not support flash erase"));
7430 error (_("Error erasing flash with vFlashErase packet"));
7435 do_cleanups (back_to
);
7438 static enum target_xfer_status
7439 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7440 ULONGEST length
, ULONGEST
*xfered_len
,
7441 const gdb_byte
*data
)
7443 int saved_remote_timeout
= remote_timeout
;
7444 enum target_xfer_status ret
;
7445 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7446 &saved_remote_timeout
);
7448 remote_timeout
= remote_flash_timeout
;
7449 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7451 do_cleanups (back_to
);
7457 remote_flash_done (struct target_ops
*ops
)
7459 int saved_remote_timeout
= remote_timeout
;
7461 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7462 &saved_remote_timeout
);
7464 remote_timeout
= remote_flash_timeout
;
7465 ret
= remote_send_printf ("vFlashDone");
7466 do_cleanups (back_to
);
7470 case PACKET_UNKNOWN
:
7471 error (_("Remote target does not support vFlashDone"));
7473 error (_("Error finishing flash operation"));
7480 remote_files_info (struct target_ops
*ignore
)
7482 puts_filtered ("Debugging a target over a serial line.\n");
7485 /* Stuff for dealing with the packets which are part of this protocol.
7486 See comment at top of file for details. */
7488 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7489 error to higher layers. Called when a serial error is detected.
7490 The exception message is STRING, followed by a colon and a blank,
7491 the system error message for errno at function entry and final dot
7492 for output compatibility with throw_perror_with_name. */
7495 unpush_and_perror (const char *string
)
7497 int saved_errno
= errno
;
7499 remote_unpush_target ();
7500 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7501 safe_strerror (saved_errno
));
7504 /* Read a single character from the remote end. */
7507 readchar (int timeout
)
7510 struct remote_state
*rs
= get_remote_state ();
7512 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7517 switch ((enum serial_rc
) ch
)
7520 remote_unpush_target ();
7521 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7524 unpush_and_perror (_("Remote communication error. "
7525 "Target disconnected."));
7527 case SERIAL_TIMEOUT
:
7533 /* Wrapper for serial_write that closes the target and throws if
7537 remote_serial_write (const char *str
, int len
)
7539 struct remote_state
*rs
= get_remote_state ();
7541 if (serial_write (rs
->remote_desc
, str
, len
))
7543 unpush_and_perror (_("Remote communication error. "
7544 "Target disconnected."));
7548 /* Send the command in *BUF to the remote machine, and read the reply
7549 into *BUF. Report an error if we get an error reply. Resize
7550 *BUF using xrealloc if necessary to hold the result, and update
7554 remote_send (char **buf
,
7558 getpkt (buf
, sizeof_buf
, 0);
7560 if ((*buf
)[0] == 'E')
7561 error (_("Remote failure reply: %s"), *buf
);
7564 /* Return a pointer to an xmalloc'ed string representing an escaped
7565 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7566 etc. The caller is responsible for releasing the returned
7570 escape_buffer (const char *buf
, int n
)
7572 struct cleanup
*old_chain
;
7573 struct ui_file
*stb
;
7576 stb
= mem_fileopen ();
7577 old_chain
= make_cleanup_ui_file_delete (stb
);
7579 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7580 str
= ui_file_xstrdup (stb
, NULL
);
7581 do_cleanups (old_chain
);
7585 /* Display a null-terminated packet on stdout, for debugging, using C
7589 print_packet (const char *buf
)
7591 puts_filtered ("\"");
7592 fputstr_filtered (buf
, '"', gdb_stdout
);
7593 puts_filtered ("\"");
7597 putpkt (const char *buf
)
7599 return putpkt_binary (buf
, strlen (buf
));
7602 /* Send a packet to the remote machine, with error checking. The data
7603 of the packet is in BUF. The string in BUF can be at most
7604 get_remote_packet_size () - 5 to account for the $, # and checksum,
7605 and for a possible /0 if we are debugging (remote_debug) and want
7606 to print the sent packet as a string. */
7609 putpkt_binary (const char *buf
, int cnt
)
7611 struct remote_state
*rs
= get_remote_state ();
7613 unsigned char csum
= 0;
7614 char *buf2
= alloca (cnt
+ 6);
7621 /* Catch cases like trying to read memory or listing threads while
7622 we're waiting for a stop reply. The remote server wouldn't be
7623 ready to handle this request, so we'd hang and timeout. We don't
7624 have to worry about this in synchronous mode, because in that
7625 case it's not possible to issue a command while the target is
7626 running. This is not a problem in non-stop mode, because in that
7627 case, the stub is always ready to process serial input. */
7628 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7630 error (_("Cannot execute this command while the target is running.\n"
7631 "Use the \"interrupt\" command to stop the target\n"
7632 "and then try again."));
7635 /* We're sending out a new packet. Make sure we don't look at a
7636 stale cached response. */
7637 rs
->cached_wait_status
= 0;
7639 /* Copy the packet into buffer BUF2, encapsulating it
7640 and giving it a checksum. */
7645 for (i
= 0; i
< cnt
; i
++)
7651 *p
++ = tohex ((csum
>> 4) & 0xf);
7652 *p
++ = tohex (csum
& 0xf);
7654 /* Send it over and over until we get a positive ack. */
7658 int started_error_output
= 0;
7662 struct cleanup
*old_chain
;
7666 str
= escape_buffer (buf2
, p
- buf2
);
7667 old_chain
= make_cleanup (xfree
, str
);
7668 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7669 gdb_flush (gdb_stdlog
);
7670 do_cleanups (old_chain
);
7672 remote_serial_write (buf2
, p
- buf2
);
7674 /* If this is a no acks version of the remote protocol, send the
7675 packet and move on. */
7679 /* Read until either a timeout occurs (-2) or '+' is read.
7680 Handle any notification that arrives in the mean time. */
7683 ch
= readchar (remote_timeout
);
7691 case SERIAL_TIMEOUT
:
7694 if (started_error_output
)
7696 putchar_unfiltered ('\n');
7697 started_error_output
= 0;
7706 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7710 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7712 case SERIAL_TIMEOUT
:
7716 break; /* Retransmit buffer. */
7720 fprintf_unfiltered (gdb_stdlog
,
7721 "Packet instead of Ack, ignoring it\n");
7722 /* It's probably an old response sent because an ACK
7723 was lost. Gobble up the packet and ack it so it
7724 doesn't get retransmitted when we resend this
7727 remote_serial_write ("+", 1);
7728 continue; /* Now, go look for +. */
7735 /* If we got a notification, handle it, and go back to looking
7737 /* We've found the start of a notification. Now
7738 collect the data. */
7739 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7744 struct cleanup
*old_chain
;
7747 str
= escape_buffer (rs
->buf
, val
);
7748 old_chain
= make_cleanup (xfree
, str
);
7749 fprintf_unfiltered (gdb_stdlog
,
7750 " Notification received: %s\n",
7752 do_cleanups (old_chain
);
7754 handle_notification (rs
->notif_state
, rs
->buf
);
7755 /* We're in sync now, rewait for the ack. */
7762 if (!started_error_output
)
7764 started_error_output
= 1;
7765 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7767 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7768 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7777 if (!started_error_output
)
7779 started_error_output
= 1;
7780 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7782 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7786 break; /* Here to retransmit. */
7790 /* This is wrong. If doing a long backtrace, the user should be
7791 able to get out next time we call QUIT, without anything as
7792 violent as interrupt_query. If we want to provide a way out of
7793 here without getting to the next QUIT, it should be based on
7794 hitting ^C twice as in remote_wait. */
7805 /* Come here after finding the start of a frame when we expected an
7806 ack. Do our best to discard the rest of this packet. */
7815 c
= readchar (remote_timeout
);
7818 case SERIAL_TIMEOUT
:
7819 /* Nothing we can do. */
7822 /* Discard the two bytes of checksum and stop. */
7823 c
= readchar (remote_timeout
);
7825 c
= readchar (remote_timeout
);
7828 case '*': /* Run length encoding. */
7829 /* Discard the repeat count. */
7830 c
= readchar (remote_timeout
);
7835 /* A regular character. */
7841 /* Come here after finding the start of the frame. Collect the rest
7842 into *BUF, verifying the checksum, length, and handling run-length
7843 compression. NUL terminate the buffer. If there is not enough room,
7844 expand *BUF using xrealloc.
7846 Returns -1 on error, number of characters in buffer (ignoring the
7847 trailing NULL) on success. (could be extended to return one of the
7848 SERIAL status indications). */
7851 read_frame (char **buf_p
,
7858 struct remote_state
*rs
= get_remote_state ();
7865 c
= readchar (remote_timeout
);
7868 case SERIAL_TIMEOUT
:
7870 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7874 fputs_filtered ("Saw new packet start in middle of old one\n",
7876 return -1; /* Start a new packet, count retries. */
7879 unsigned char pktcsum
;
7885 check_0
= readchar (remote_timeout
);
7887 check_1
= readchar (remote_timeout
);
7889 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7892 fputs_filtered ("Timeout in checksum, retrying\n",
7896 else if (check_0
< 0 || check_1
< 0)
7899 fputs_filtered ("Communication error in checksum\n",
7904 /* Don't recompute the checksum; with no ack packets we
7905 don't have any way to indicate a packet retransmission
7910 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7911 if (csum
== pktcsum
)
7916 struct cleanup
*old_chain
;
7919 str
= escape_buffer (buf
, bc
);
7920 old_chain
= make_cleanup (xfree
, str
);
7921 fprintf_unfiltered (gdb_stdlog
,
7922 "Bad checksum, sentsum=0x%x, "
7923 "csum=0x%x, buf=%s\n",
7924 pktcsum
, csum
, str
);
7925 do_cleanups (old_chain
);
7927 /* Number of characters in buffer ignoring trailing
7931 case '*': /* Run length encoding. */
7936 c
= readchar (remote_timeout
);
7938 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7940 /* The character before ``*'' is repeated. */
7942 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7944 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7946 /* Make some more room in the buffer. */
7947 *sizeof_buf
+= repeat
;
7948 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7952 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7958 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7962 if (bc
>= *sizeof_buf
- 1)
7964 /* Make some more room in the buffer. */
7966 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7977 /* Read a packet from the remote machine, with error checking, and
7978 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7979 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7980 rather than timing out; this is used (in synchronous mode) to wait
7981 for a target that is is executing user code to stop. */
7982 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7983 don't have to change all the calls to getpkt to deal with the
7984 return value, because at the moment I don't know what the right
7985 thing to do it for those. */
7993 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7997 /* Read a packet from the remote machine, with error checking, and
7998 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7999 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8000 rather than timing out; this is used (in synchronous mode) to wait
8001 for a target that is is executing user code to stop. If FOREVER ==
8002 0, this function is allowed to time out gracefully and return an
8003 indication of this to the caller. Otherwise return the number of
8004 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8005 enough reason to return to the caller. *IS_NOTIF is an output
8006 boolean that indicates whether *BUF holds a notification or not
8007 (a regular packet). */
8010 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8011 int expecting_notif
, int *is_notif
)
8013 struct remote_state
*rs
= get_remote_state ();
8019 /* We're reading a new response. Make sure we don't look at a
8020 previously cached response. */
8021 rs
->cached_wait_status
= 0;
8023 strcpy (*buf
, "timeout");
8026 timeout
= watchdog
> 0 ? watchdog
: -1;
8027 else if (expecting_notif
)
8028 timeout
= 0; /* There should already be a char in the buffer. If
8031 timeout
= remote_timeout
;
8035 /* Process any number of notifications, and then return when
8039 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8041 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8043 /* This can loop forever if the remote side sends us
8044 characters continuously, but if it pauses, we'll get
8045 SERIAL_TIMEOUT from readchar because of timeout. Then
8046 we'll count that as a retry.
8048 Note that even when forever is set, we will only wait
8049 forever prior to the start of a packet. After that, we
8050 expect characters to arrive at a brisk pace. They should
8051 show up within remote_timeout intervals. */
8053 c
= readchar (timeout
);
8054 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8056 if (c
== SERIAL_TIMEOUT
)
8058 if (expecting_notif
)
8059 return -1; /* Don't complain, it's normal to not get
8060 anything in this case. */
8062 if (forever
) /* Watchdog went off? Kill the target. */
8065 remote_unpush_target ();
8066 throw_error (TARGET_CLOSE_ERROR
,
8067 _("Watchdog timeout has expired. "
8068 "Target detached."));
8071 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8075 /* We've found the start of a packet or notification.
8076 Now collect the data. */
8077 val
= read_frame (buf
, sizeof_buf
);
8082 remote_serial_write ("-", 1);
8085 if (tries
> MAX_TRIES
)
8087 /* We have tried hard enough, and just can't receive the
8088 packet/notification. Give up. */
8089 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8091 /* Skip the ack char if we're in no-ack mode. */
8092 if (!rs
->noack_mode
)
8093 remote_serial_write ("+", 1);
8097 /* If we got an ordinary packet, return that to our caller. */
8102 struct cleanup
*old_chain
;
8105 str
= escape_buffer (*buf
, val
);
8106 old_chain
= make_cleanup (xfree
, str
);
8107 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8108 do_cleanups (old_chain
);
8111 /* Skip the ack char if we're in no-ack mode. */
8112 if (!rs
->noack_mode
)
8113 remote_serial_write ("+", 1);
8114 if (is_notif
!= NULL
)
8119 /* If we got a notification, handle it, and go back to looking
8123 gdb_assert (c
== '%');
8127 struct cleanup
*old_chain
;
8130 str
= escape_buffer (*buf
, val
);
8131 old_chain
= make_cleanup (xfree
, str
);
8132 fprintf_unfiltered (gdb_stdlog
,
8133 " Notification received: %s\n",
8135 do_cleanups (old_chain
);
8137 if (is_notif
!= NULL
)
8140 handle_notification (rs
->notif_state
, *buf
);
8142 /* Notifications require no acknowledgement. */
8144 if (expecting_notif
)
8151 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8153 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8157 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8160 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8164 /* Check whether EVENT is a fork event for the process specified
8165 by the pid passed in DATA, and if it is, kill the fork child. */
8168 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8169 QUEUE_ITER (stop_reply_p
) *iter
,
8173 struct queue_iter_param
*param
= data
;
8174 int parent_pid
= *(int *) param
->input
;
8176 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8178 struct remote_state
*rs
= get_remote_state ();
8179 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8182 res
= remote_vkill (child_pid
, rs
);
8184 error (_("Can't kill fork child process %d"), child_pid
);
8190 /* Kill any new fork children of process PID that haven't been
8191 processed by follow_fork. */
8194 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8196 struct thread_info
*thread
;
8197 struct notif_client
*notif
= ¬if_client_stop
;
8198 struct queue_iter_param param
;
8200 /* Kill the fork child threads of any threads in process PID
8201 that are stopped at a fork event. */
8202 ALL_NON_EXITED_THREADS (thread
)
8204 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8206 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8208 struct remote_state
*rs
= get_remote_state ();
8209 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8212 res
= remote_vkill (child_pid
, rs
);
8214 error (_("Can't kill fork child process %d"), child_pid
);
8218 /* Check for any pending fork events (not reported or processed yet)
8219 in process PID and kill those fork child threads as well. */
8220 remote_notif_get_pending_events (notif
);
8222 param
.output
= NULL
;
8223 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8224 kill_child_of_pending_fork
, ¶m
);
8229 remote_kill (struct target_ops
*ops
)
8232 /* Catch errors so the user can quit from gdb even when we
8233 aren't on speaking terms with the remote system. */
8238 CATCH (ex
, RETURN_MASK_ERROR
)
8240 if (ex
.error
== TARGET_CLOSE_ERROR
)
8242 /* If we got an (EOF) error that caused the target
8243 to go away, then we're done, that's what we wanted.
8244 "k" is susceptible to cause a premature EOF, given
8245 that the remote server isn't actually required to
8246 reply to "k", and it can happen that it doesn't
8247 even get to reply ACK to the "k". */
8251 /* Otherwise, something went wrong. We didn't actually kill
8252 the target. Just propagate the exception, and let the
8253 user or higher layers decide what to do. */
8254 throw_exception (ex
);
8258 /* We've killed the remote end, we get to mourn it. Since this is
8259 target remote, single-process, mourning the inferior also
8260 unpushes remote_ops. */
8261 target_mourn_inferior ();
8265 remote_vkill (int pid
, struct remote_state
*rs
)
8267 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8270 /* Tell the remote target to detach. */
8271 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8273 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8275 switch (packet_ok (rs
->buf
,
8276 &remote_protocol_packets
[PACKET_vKill
]))
8282 case PACKET_UNKNOWN
:
8285 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8290 extended_remote_kill (struct target_ops
*ops
)
8293 int pid
= ptid_get_pid (inferior_ptid
);
8294 struct remote_state
*rs
= get_remote_state ();
8296 /* If we're stopped while forking and we haven't followed yet, kill the
8297 child task. We need to do this before killing the parent task
8298 because if this is a vfork then the parent will be sleeping. */
8299 kill_new_fork_children (pid
, rs
);
8301 res
= remote_vkill (pid
, rs
);
8302 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8304 /* Don't try 'k' on a multi-process aware stub -- it has no way
8305 to specify the pid. */
8309 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8310 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8313 /* Don't wait for it to die. I'm not really sure it matters whether
8314 we do or not. For the existing stubs, kill is a noop. */
8320 error (_("Can't kill process"));
8322 target_mourn_inferior ();
8326 remote_mourn (struct target_ops
*target
)
8328 unpush_target (target
);
8330 /* remote_close takes care of doing most of the clean up. */
8331 generic_mourn_inferior ();
8335 extended_remote_mourn (struct target_ops
*target
)
8337 struct remote_state
*rs
= get_remote_state ();
8339 /* In case we got here due to an error, but we're going to stay
8341 rs
->waiting_for_stop_reply
= 0;
8343 /* If the current general thread belonged to the process we just
8344 detached from or has exited, the remote side current general
8345 thread becomes undefined. Considering a case like this:
8347 - We just got here due to a detach.
8348 - The process that we're detaching from happens to immediately
8349 report a global breakpoint being hit in non-stop mode, in the
8350 same thread we had selected before.
8351 - GDB attaches to this process again.
8352 - This event happens to be the next event we handle.
8354 GDB would consider that the current general thread didn't need to
8355 be set on the stub side (with Hg), since for all it knew,
8356 GENERAL_THREAD hadn't changed.
8358 Notice that although in all-stop mode, the remote server always
8359 sets the current thread to the thread reporting the stop event,
8360 that doesn't happen in non-stop mode; in non-stop, the stub *must
8361 not* change the current thread when reporting a breakpoint hit,
8362 due to the decoupling of event reporting and event handling.
8364 To keep things simple, we always invalidate our notion of the
8366 record_currthread (rs
, minus_one_ptid
);
8368 /* Unlike "target remote", we do not want to unpush the target; then
8369 the next time the user says "run", we won't be connected. */
8371 /* Call common code to mark the inferior as not running. */
8372 generic_mourn_inferior ();
8374 if (!have_inferiors ())
8376 if (!remote_multi_process_p (rs
))
8378 /* Check whether the target is running now - some remote stubs
8379 automatically restart after kill. */
8381 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8383 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8385 /* Assume that the target has been restarted. Set
8386 inferior_ptid so that bits of core GDB realizes
8387 there's something here, e.g., so that the user can
8388 say "kill" again. */
8389 inferior_ptid
= magic_null_ptid
;
8396 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8398 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8402 extended_remote_disable_randomization (int val
)
8404 struct remote_state
*rs
= get_remote_state ();
8407 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8410 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8412 error (_("Target does not support QDisableRandomization."));
8413 if (strcmp (reply
, "OK") != 0)
8414 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8418 extended_remote_run (char *args
)
8420 struct remote_state
*rs
= get_remote_state ();
8423 /* If the user has disabled vRun support, or we have detected that
8424 support is not available, do not try it. */
8425 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8428 strcpy (rs
->buf
, "vRun;");
8429 len
= strlen (rs
->buf
);
8431 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8432 error (_("Remote file name too long for run packet"));
8433 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8434 strlen (remote_exec_file
));
8436 gdb_assert (args
!= NULL
);
8439 struct cleanup
*back_to
;
8443 argv
= gdb_buildargv (args
);
8444 back_to
= make_cleanup_freeargv (argv
);
8445 for (i
= 0; argv
[i
] != NULL
; i
++)
8447 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8448 error (_("Argument list too long for run packet"));
8449 rs
->buf
[len
++] = ';';
8450 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8453 do_cleanups (back_to
);
8456 rs
->buf
[len
++] = '\0';
8459 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8461 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8464 /* We have a wait response. All is well. */
8466 case PACKET_UNKNOWN
:
8469 if (remote_exec_file
[0] == '\0')
8470 error (_("Running the default executable on the remote target failed; "
8471 "try \"set remote exec-file\"?"));
8473 error (_("Running \"%s\" on the remote target failed"),
8476 gdb_assert_not_reached (_("bad switch"));
8480 /* In the extended protocol we want to be able to do things like
8481 "run" and have them basically work as expected. So we need
8482 a special create_inferior function. We support changing the
8483 executable file and the command line arguments, but not the
8487 extended_remote_create_inferior (struct target_ops
*ops
,
8488 char *exec_file
, char *args
,
8489 char **env
, int from_tty
)
8493 struct remote_state
*rs
= get_remote_state ();
8495 /* If running asynchronously, register the target file descriptor
8496 with the event loop. */
8497 if (target_can_async_p ())
8500 /* Disable address space randomization if requested (and supported). */
8501 if (extended_remote_supports_disable_randomization (ops
))
8502 extended_remote_disable_randomization (disable_randomization
);
8504 /* Now restart the remote server. */
8505 run_worked
= extended_remote_run (args
) != -1;
8508 /* vRun was not supported. Fail if we need it to do what the
8510 if (remote_exec_file
[0])
8511 error (_("Remote target does not support \"set remote exec-file\""));
8513 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8515 /* Fall back to "R". */
8516 extended_remote_restart ();
8519 if (!have_inferiors ())
8521 /* Clean up from the last time we ran, before we mark the target
8522 running again. This will mark breakpoints uninserted, and
8523 get_offsets may insert breakpoints. */
8524 init_thread_list ();
8525 init_wait_for_inferior ();
8528 /* vRun's success return is a stop reply. */
8529 stop_reply
= run_worked
? rs
->buf
: NULL
;
8530 add_current_inferior_and_thread (stop_reply
);
8532 /* Get updated offsets, if the stub uses qOffsets. */
8537 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8538 the list of conditions (in agent expression bytecode format), if any, the
8539 target needs to evaluate. The output is placed into the packet buffer
8540 started from BUF and ended at BUF_END. */
8543 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8544 struct bp_target_info
*bp_tgt
, char *buf
,
8547 struct agent_expr
*aexpr
= NULL
;
8550 char *buf_start
= buf
;
8552 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8555 buf
+= strlen (buf
);
8556 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8559 /* Send conditions to the target and free the vector. */
8561 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8564 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8565 buf
+= strlen (buf
);
8566 for (i
= 0; i
< aexpr
->len
; ++i
)
8567 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8574 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8575 struct bp_target_info
*bp_tgt
, char *buf
)
8577 struct agent_expr
*aexpr
= NULL
;
8580 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8583 buf
+= strlen (buf
);
8585 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8586 buf
+= strlen (buf
);
8588 /* Concatenate all the agent expressions that are commands into the
8591 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8594 sprintf (buf
, "X%x,", aexpr
->len
);
8595 buf
+= strlen (buf
);
8596 for (i
= 0; i
< aexpr
->len
; ++i
)
8597 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8602 /* Insert a breakpoint. On targets that have software breakpoint
8603 support, we ask the remote target to do the work; on targets
8604 which don't, we insert a traditional memory breakpoint. */
8607 remote_insert_breakpoint (struct target_ops
*ops
,
8608 struct gdbarch
*gdbarch
,
8609 struct bp_target_info
*bp_tgt
)
8611 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8612 If it succeeds, then set the support to PACKET_ENABLE. If it
8613 fails, and the user has explicitly requested the Z support then
8614 report an error, otherwise, mark it disabled and go on. */
8616 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8618 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8619 struct remote_state
*rs
;
8622 struct condition_list
*cond
= NULL
;
8624 /* Make sure the remote is pointing at the right process, if
8626 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8627 set_general_process ();
8629 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8631 rs
= get_remote_state ();
8633 endbuf
= rs
->buf
+ get_remote_packet_size ();
8638 addr
= (ULONGEST
) remote_address_masked (addr
);
8639 p
+= hexnumstr (p
, addr
);
8640 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8642 if (remote_supports_cond_breakpoints (ops
))
8643 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8645 if (remote_can_run_breakpoint_commands (ops
))
8646 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8649 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8651 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8656 bp_tgt
->placed_address
= addr
;
8657 bp_tgt
->placed_size
= bpsize
;
8659 case PACKET_UNKNOWN
:
8664 /* If this breakpoint has target-side commands but this stub doesn't
8665 support Z0 packets, throw error. */
8666 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8667 throw_error (NOT_SUPPORTED_ERROR
, _("\
8668 Target doesn't support breakpoints that have target side commands."));
8670 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8674 remote_remove_breakpoint (struct target_ops
*ops
,
8675 struct gdbarch
*gdbarch
,
8676 struct bp_target_info
*bp_tgt
)
8678 CORE_ADDR addr
= bp_tgt
->placed_address
;
8679 struct remote_state
*rs
= get_remote_state ();
8681 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8684 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8686 /* Make sure the remote is pointing at the right process, if
8688 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8689 set_general_process ();
8695 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8696 p
+= hexnumstr (p
, addr
);
8697 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8700 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8702 return (rs
->buf
[0] == 'E');
8705 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8709 watchpoint_to_Z_packet (int type
)
8714 return Z_PACKET_WRITE_WP
;
8717 return Z_PACKET_READ_WP
;
8720 return Z_PACKET_ACCESS_WP
;
8723 internal_error (__FILE__
, __LINE__
,
8724 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8729 remote_insert_watchpoint (struct target_ops
*self
,
8730 CORE_ADDR addr
, int len
, int type
,
8731 struct expression
*cond
)
8733 struct remote_state
*rs
= get_remote_state ();
8734 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8736 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8738 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8741 /* Make sure the remote is pointing at the right process, if
8743 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8744 set_general_process ();
8746 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8747 p
= strchr (rs
->buf
, '\0');
8748 addr
= remote_address_masked (addr
);
8749 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8750 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8755 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8759 case PACKET_UNKNOWN
:
8764 internal_error (__FILE__
, __LINE__
,
8765 _("remote_insert_watchpoint: reached end of function"));
8769 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8770 CORE_ADDR start
, int length
)
8772 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8774 return diff
< length
;
8779 remote_remove_watchpoint (struct target_ops
*self
,
8780 CORE_ADDR addr
, int len
, int type
,
8781 struct expression
*cond
)
8783 struct remote_state
*rs
= get_remote_state ();
8784 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8786 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8788 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8791 /* Make sure the remote is pointing at the right process, if
8793 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8794 set_general_process ();
8796 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8797 p
= strchr (rs
->buf
, '\0');
8798 addr
= remote_address_masked (addr
);
8799 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8800 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8802 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8804 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8807 case PACKET_UNKNOWN
:
8812 internal_error (__FILE__
, __LINE__
,
8813 _("remote_remove_watchpoint: reached end of function"));
8817 int remote_hw_watchpoint_limit
= -1;
8818 int remote_hw_watchpoint_length_limit
= -1;
8819 int remote_hw_breakpoint_limit
= -1;
8822 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8823 CORE_ADDR addr
, int len
)
8825 if (remote_hw_watchpoint_length_limit
== 0)
8827 else if (remote_hw_watchpoint_length_limit
< 0)
8829 else if (len
<= remote_hw_watchpoint_length_limit
)
8836 remote_check_watch_resources (struct target_ops
*self
,
8837 int type
, int cnt
, int ot
)
8839 if (type
== bp_hardware_breakpoint
)
8841 if (remote_hw_breakpoint_limit
== 0)
8843 else if (remote_hw_breakpoint_limit
< 0)
8845 else if (cnt
<= remote_hw_breakpoint_limit
)
8850 if (remote_hw_watchpoint_limit
== 0)
8852 else if (remote_hw_watchpoint_limit
< 0)
8856 else if (cnt
<= remote_hw_watchpoint_limit
)
8862 /* The to_stopped_by_sw_breakpoint method of target remote. */
8865 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8867 struct remote_state
*rs
= get_remote_state ();
8869 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
8872 /* The to_supports_stopped_by_sw_breakpoint method of target
8876 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8878 struct remote_state
*rs
= get_remote_state ();
8880 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
8883 /* The to_stopped_by_hw_breakpoint method of target remote. */
8886 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8888 struct remote_state
*rs
= get_remote_state ();
8890 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
8893 /* The to_supports_stopped_by_hw_breakpoint method of target
8897 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8899 struct remote_state
*rs
= get_remote_state ();
8901 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
8905 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8907 struct remote_state
*rs
= get_remote_state ();
8909 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
8913 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8915 struct remote_state
*rs
= get_remote_state ();
8918 if (remote_stopped_by_watchpoint (target
))
8920 *addr_p
= rs
->remote_watch_data_address
;
8929 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8930 struct bp_target_info
*bp_tgt
)
8932 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8933 struct remote_state
*rs
;
8938 /* The length field should be set to the size of a breakpoint
8939 instruction, even though we aren't inserting one ourselves. */
8941 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8943 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8946 /* Make sure the remote is pointing at the right process, if
8948 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8949 set_general_process ();
8951 rs
= get_remote_state ();
8953 endbuf
= rs
->buf
+ get_remote_packet_size ();
8959 addr
= remote_address_masked (addr
);
8960 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8961 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
8963 if (remote_supports_cond_breakpoints (self
))
8964 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8966 if (remote_can_run_breakpoint_commands (self
))
8967 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8972 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8975 if (rs
->buf
[1] == '.')
8977 message
= strchr (rs
->buf
+ 2, '.');
8979 error (_("Remote failure reply: %s"), message
+ 1);
8982 case PACKET_UNKNOWN
:
8985 bp_tgt
->placed_address
= addr
;
8986 bp_tgt
->placed_size
= bpsize
;
8989 internal_error (__FILE__
, __LINE__
,
8990 _("remote_insert_hw_breakpoint: reached end of function"));
8995 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8996 struct bp_target_info
*bp_tgt
)
8999 struct remote_state
*rs
= get_remote_state ();
9001 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9003 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9006 /* Make sure the remote is pointing at the right process, if
9008 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9009 set_general_process ();
9015 addr
= remote_address_masked (bp_tgt
->placed_address
);
9016 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9017 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9020 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9022 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9025 case PACKET_UNKNOWN
:
9030 internal_error (__FILE__
, __LINE__
,
9031 _("remote_remove_hw_breakpoint: reached end of function"));
9034 /* Verify memory using the "qCRC:" request. */
9037 remote_verify_memory (struct target_ops
*ops
,
9038 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9040 struct remote_state
*rs
= get_remote_state ();
9041 unsigned long host_crc
, target_crc
;
9044 /* It doesn't make sense to use qCRC if the remote target is
9045 connected but not running. */
9046 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9048 enum packet_result result
;
9050 /* Make sure the remote is pointing at the right process. */
9051 set_general_process ();
9053 /* FIXME: assumes lma can fit into long. */
9054 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9055 (long) lma
, (long) size
);
9058 /* Be clever; compute the host_crc before waiting for target
9060 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9062 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9064 result
= packet_ok (rs
->buf
,
9065 &remote_protocol_packets
[PACKET_qCRC
]);
9066 if (result
== PACKET_ERROR
)
9068 else if (result
== PACKET_OK
)
9070 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9071 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9073 return (host_crc
== target_crc
);
9077 return simple_verify_memory (ops
, data
, lma
, size
);
9080 /* compare-sections command
9082 With no arguments, compares each loadable section in the exec bfd
9083 with the same memory range on the target, and reports mismatches.
9084 Useful for verifying the image on the target against the exec file. */
9087 compare_sections_command (char *args
, int from_tty
)
9090 struct cleanup
*old_chain
;
9092 const char *sectname
;
9101 error (_("command cannot be used without an exec file"));
9103 /* Make sure the remote is pointing at the right process. */
9104 set_general_process ();
9106 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9112 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9114 if (!(s
->flags
& SEC_LOAD
))
9115 continue; /* Skip non-loadable section. */
9117 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9118 continue; /* Skip writeable sections */
9120 size
= bfd_get_section_size (s
);
9122 continue; /* Skip zero-length section. */
9124 sectname
= bfd_get_section_name (exec_bfd
, s
);
9125 if (args
&& strcmp (args
, sectname
) != 0)
9126 continue; /* Not the section selected by user. */
9128 matched
= 1; /* Do this section. */
9131 sectdata
= xmalloc (size
);
9132 old_chain
= make_cleanup (xfree
, sectdata
);
9133 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9135 res
= target_verify_memory (sectdata
, lma
, size
);
9138 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9139 paddress (target_gdbarch (), lma
),
9140 paddress (target_gdbarch (), lma
+ size
));
9142 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9143 paddress (target_gdbarch (), lma
),
9144 paddress (target_gdbarch (), lma
+ size
));
9146 printf_filtered ("matched.\n");
9149 printf_filtered ("MIS-MATCHED!\n");
9153 do_cleanups (old_chain
);
9156 warning (_("One or more sections of the target image does not match\n\
9157 the loaded file\n"));
9158 if (args
&& !matched
)
9159 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9162 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9163 into remote target. The number of bytes written to the remote
9164 target is returned, or -1 for error. */
9166 static enum target_xfer_status
9167 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9168 const char *annex
, const gdb_byte
*writebuf
,
9169 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9170 struct packet_config
*packet
)
9174 struct remote_state
*rs
= get_remote_state ();
9175 int max_size
= get_memory_write_packet_size ();
9177 if (packet
->support
== PACKET_DISABLE
)
9178 return TARGET_XFER_E_IO
;
9180 /* Insert header. */
9181 i
= snprintf (rs
->buf
, max_size
,
9182 "qXfer:%s:write:%s:%s:",
9183 object_name
, annex
? annex
: "",
9184 phex_nz (offset
, sizeof offset
));
9185 max_size
-= (i
+ 1);
9187 /* Escape as much data as fits into rs->buf. */
9188 buf_len
= remote_escape_output
9189 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9191 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9192 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9193 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9194 return TARGET_XFER_E_IO
;
9196 unpack_varlen_hex (rs
->buf
, &n
);
9199 return TARGET_XFER_OK
;
9202 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9203 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9204 number of bytes read is returned, or 0 for EOF, or -1 for error.
9205 The number of bytes read may be less than LEN without indicating an
9206 EOF. PACKET is checked and updated to indicate whether the remote
9207 target supports this object. */
9209 static enum target_xfer_status
9210 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9212 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9213 ULONGEST
*xfered_len
,
9214 struct packet_config
*packet
)
9216 struct remote_state
*rs
= get_remote_state ();
9217 LONGEST i
, n
, packet_len
;
9219 if (packet
->support
== PACKET_DISABLE
)
9220 return TARGET_XFER_E_IO
;
9222 /* Check whether we've cached an end-of-object packet that matches
9224 if (rs
->finished_object
)
9226 if (strcmp (object_name
, rs
->finished_object
) == 0
9227 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9228 && offset
== rs
->finished_offset
)
9229 return TARGET_XFER_EOF
;
9232 /* Otherwise, we're now reading something different. Discard
9234 xfree (rs
->finished_object
);
9235 xfree (rs
->finished_annex
);
9236 rs
->finished_object
= NULL
;
9237 rs
->finished_annex
= NULL
;
9240 /* Request only enough to fit in a single packet. The actual data
9241 may not, since we don't know how much of it will need to be escaped;
9242 the target is free to respond with slightly less data. We subtract
9243 five to account for the response type and the protocol frame. */
9244 n
= min (get_remote_packet_size () - 5, len
);
9245 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9246 object_name
, annex
? annex
: "",
9247 phex_nz (offset
, sizeof offset
),
9248 phex_nz (n
, sizeof n
));
9249 i
= putpkt (rs
->buf
);
9251 return TARGET_XFER_E_IO
;
9254 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9255 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9256 return TARGET_XFER_E_IO
;
9258 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9259 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9261 /* 'm' means there is (or at least might be) more data after this
9262 batch. That does not make sense unless there's at least one byte
9263 of data in this reply. */
9264 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9265 error (_("Remote qXfer reply contained no data."));
9267 /* Got some data. */
9268 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9269 packet_len
- 1, readbuf
, n
);
9271 /* 'l' is an EOF marker, possibly including a final block of data,
9272 or possibly empty. If we have the final block of a non-empty
9273 object, record this fact to bypass a subsequent partial read. */
9274 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9276 rs
->finished_object
= xstrdup (object_name
);
9277 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9278 rs
->finished_offset
= offset
+ i
;
9282 return TARGET_XFER_EOF
;
9286 return TARGET_XFER_OK
;
9290 static enum target_xfer_status
9291 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9292 const char *annex
, gdb_byte
*readbuf
,
9293 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9294 ULONGEST
*xfered_len
)
9296 struct remote_state
*rs
;
9300 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9302 set_remote_traceframe ();
9303 set_general_thread (inferior_ptid
);
9305 rs
= get_remote_state ();
9307 /* Handle memory using the standard memory routines. */
9308 if (object
== TARGET_OBJECT_MEMORY
)
9310 /* If the remote target is connected but not running, we should
9311 pass this request down to a lower stratum (e.g. the executable
9313 if (!target_has_execution
)
9314 return TARGET_XFER_EOF
;
9316 if (writebuf
!= NULL
)
9317 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9320 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9324 /* Handle SPU memory using qxfer packets. */
9325 if (object
== TARGET_OBJECT_SPU
)
9328 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9329 xfered_len
, &remote_protocol_packets
9330 [PACKET_qXfer_spu_read
]);
9332 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9333 xfered_len
, &remote_protocol_packets
9334 [PACKET_qXfer_spu_write
]);
9337 /* Handle extra signal info using qxfer packets. */
9338 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9341 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9342 xfered_len
, &remote_protocol_packets
9343 [PACKET_qXfer_siginfo_read
]);
9345 return remote_write_qxfer (ops
, "siginfo", annex
,
9346 writebuf
, offset
, len
, xfered_len
,
9347 &remote_protocol_packets
9348 [PACKET_qXfer_siginfo_write
]);
9351 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9354 return remote_read_qxfer (ops
, "statictrace", annex
,
9355 readbuf
, offset
, len
, xfered_len
,
9356 &remote_protocol_packets
9357 [PACKET_qXfer_statictrace_read
]);
9359 return TARGET_XFER_E_IO
;
9362 /* Only handle flash writes. */
9363 if (writebuf
!= NULL
)
9369 case TARGET_OBJECT_FLASH
:
9370 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9374 return TARGET_XFER_E_IO
;
9378 /* Map pre-existing objects onto letters. DO NOT do this for new
9379 objects!!! Instead specify new query packets. */
9382 case TARGET_OBJECT_AVR
:
9386 case TARGET_OBJECT_AUXV
:
9387 gdb_assert (annex
== NULL
);
9388 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9390 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9392 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9393 return remote_read_qxfer
9394 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9395 &remote_protocol_packets
[PACKET_qXfer_features
]);
9397 case TARGET_OBJECT_LIBRARIES
:
9398 return remote_read_qxfer
9399 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9400 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9402 case TARGET_OBJECT_LIBRARIES_SVR4
:
9403 return remote_read_qxfer
9404 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9405 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9407 case TARGET_OBJECT_MEMORY_MAP
:
9408 gdb_assert (annex
== NULL
);
9409 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9411 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9413 case TARGET_OBJECT_OSDATA
:
9414 /* Should only get here if we're connected. */
9415 gdb_assert (rs
->remote_desc
);
9416 return remote_read_qxfer
9417 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9418 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9420 case TARGET_OBJECT_THREADS
:
9421 gdb_assert (annex
== NULL
);
9422 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9424 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9426 case TARGET_OBJECT_TRACEFRAME_INFO
:
9427 gdb_assert (annex
== NULL
);
9428 return remote_read_qxfer
9429 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9430 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9432 case TARGET_OBJECT_FDPIC
:
9433 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9435 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9437 case TARGET_OBJECT_OPENVMS_UIB
:
9438 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9440 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9442 case TARGET_OBJECT_BTRACE
:
9443 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9445 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9447 case TARGET_OBJECT_BTRACE_CONF
:
9448 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9450 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9452 case TARGET_OBJECT_EXEC_FILE
:
9453 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9455 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9458 return TARGET_XFER_E_IO
;
9461 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9462 large enough let the caller deal with it. */
9463 if (len
< get_remote_packet_size ())
9464 return TARGET_XFER_E_IO
;
9465 len
= get_remote_packet_size ();
9467 /* Except for querying the minimum buffer size, target must be open. */
9468 if (!rs
->remote_desc
)
9469 error (_("remote query is only available after target open"));
9471 gdb_assert (annex
!= NULL
);
9472 gdb_assert (readbuf
!= NULL
);
9478 /* We used one buffer char for the remote protocol q command and
9479 another for the query type. As the remote protocol encapsulation
9480 uses 4 chars plus one extra in case we are debugging
9481 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9484 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9486 /* Bad caller may have sent forbidden characters. */
9487 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9492 gdb_assert (annex
[i
] == '\0');
9494 i
= putpkt (rs
->buf
);
9496 return TARGET_XFER_E_IO
;
9498 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9499 strcpy ((char *) readbuf
, rs
->buf
);
9501 *xfered_len
= strlen ((char *) readbuf
);
9502 return TARGET_XFER_OK
;
9506 remote_search_memory (struct target_ops
* ops
,
9507 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9508 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9509 CORE_ADDR
*found_addrp
)
9511 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9512 struct remote_state
*rs
= get_remote_state ();
9513 int max_size
= get_memory_write_packet_size ();
9514 struct packet_config
*packet
=
9515 &remote_protocol_packets
[PACKET_qSearch_memory
];
9516 /* Number of packet bytes used to encode the pattern;
9517 this could be more than PATTERN_LEN due to escape characters. */
9518 int escaped_pattern_len
;
9519 /* Amount of pattern that was encodable in the packet. */
9520 int used_pattern_len
;
9523 ULONGEST found_addr
;
9525 /* Don't go to the target if we don't have to.
9526 This is done before checking packet->support to avoid the possibility that
9527 a success for this edge case means the facility works in general. */
9528 if (pattern_len
> search_space_len
)
9530 if (pattern_len
== 0)
9532 *found_addrp
= start_addr
;
9536 /* If we already know the packet isn't supported, fall back to the simple
9537 way of searching memory. */
9539 if (packet_config_support (packet
) == PACKET_DISABLE
)
9541 /* Target doesn't provided special support, fall back and use the
9542 standard support (copy memory and do the search here). */
9543 return simple_search_memory (ops
, start_addr
, search_space_len
,
9544 pattern
, pattern_len
, found_addrp
);
9547 /* Make sure the remote is pointing at the right process. */
9548 set_general_process ();
9550 /* Insert header. */
9551 i
= snprintf (rs
->buf
, max_size
,
9552 "qSearch:memory:%s;%s;",
9553 phex_nz (start_addr
, addr_size
),
9554 phex_nz (search_space_len
, sizeof (search_space_len
)));
9555 max_size
-= (i
+ 1);
9557 /* Escape as much data as fits into rs->buf. */
9558 escaped_pattern_len
=
9559 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9560 &used_pattern_len
, max_size
);
9562 /* Bail if the pattern is too large. */
9563 if (used_pattern_len
!= pattern_len
)
9564 error (_("Pattern is too large to transmit to remote target."));
9566 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9567 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9568 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9570 /* The request may not have worked because the command is not
9571 supported. If so, fall back to the simple way. */
9572 if (packet
->support
== PACKET_DISABLE
)
9574 return simple_search_memory (ops
, start_addr
, search_space_len
,
9575 pattern
, pattern_len
, found_addrp
);
9580 if (rs
->buf
[0] == '0')
9582 else if (rs
->buf
[0] == '1')
9585 if (rs
->buf
[1] != ',')
9586 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9587 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9588 *found_addrp
= found_addr
;
9591 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9597 remote_rcmd (struct target_ops
*self
, const char *command
,
9598 struct ui_file
*outbuf
)
9600 struct remote_state
*rs
= get_remote_state ();
9603 if (!rs
->remote_desc
)
9604 error (_("remote rcmd is only available after target open"));
9606 /* Send a NULL command across as an empty command. */
9607 if (command
== NULL
)
9610 /* The query prefix. */
9611 strcpy (rs
->buf
, "qRcmd,");
9612 p
= strchr (rs
->buf
, '\0');
9614 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9615 > get_remote_packet_size ())
9616 error (_("\"monitor\" command ``%s'' is too long."), command
);
9618 /* Encode the actual command. */
9619 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9621 if (putpkt (rs
->buf
) < 0)
9622 error (_("Communication problem with target."));
9624 /* get/display the response */
9629 /* XXX - see also remote_get_noisy_reply(). */
9630 QUIT
; /* Allow user to bail out with ^C. */
9632 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9634 /* Timeout. Continue to (try to) read responses.
9635 This is better than stopping with an error, assuming the stub
9636 is still executing the (long) monitor command.
9637 If needed, the user can interrupt gdb using C-c, obtaining
9638 an effect similar to stop on timeout. */
9643 error (_("Target does not support this command."));
9644 if (buf
[0] == 'O' && buf
[1] != 'K')
9646 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9649 if (strcmp (buf
, "OK") == 0)
9651 if (strlen (buf
) == 3 && buf
[0] == 'E'
9652 && isdigit (buf
[1]) && isdigit (buf
[2]))
9654 error (_("Protocol error with Rcmd"));
9656 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9658 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9660 fputc_unfiltered (c
, outbuf
);
9666 static VEC(mem_region_s
) *
9667 remote_memory_map (struct target_ops
*ops
)
9669 VEC(mem_region_s
) *result
= NULL
;
9670 char *text
= target_read_stralloc (¤t_target
,
9671 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9675 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9677 result
= parse_memory_map (text
);
9678 do_cleanups (back_to
);
9685 packet_command (char *args
, int from_tty
)
9687 struct remote_state
*rs
= get_remote_state ();
9689 if (!rs
->remote_desc
)
9690 error (_("command can only be used with remote target"));
9693 error (_("remote-packet command requires packet text as argument"));
9695 puts_filtered ("sending: ");
9696 print_packet (args
);
9697 puts_filtered ("\n");
9700 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9701 puts_filtered ("received: ");
9702 print_packet (rs
->buf
);
9703 puts_filtered ("\n");
9707 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9709 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9711 static void threadset_test_cmd (char *cmd
, int tty
);
9713 static void threadalive_test (char *cmd
, int tty
);
9715 static void threadlist_test_cmd (char *cmd
, int tty
);
9717 int get_and_display_threadinfo (threadref
*ref
);
9719 static void threadinfo_test_cmd (char *cmd
, int tty
);
9721 static int thread_display_step (threadref
*ref
, void *context
);
9723 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9725 static void init_remote_threadtests (void);
9727 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9730 threadset_test_cmd (char *cmd
, int tty
)
9732 int sample_thread
= SAMPLE_THREAD
;
9734 printf_filtered (_("Remote threadset test\n"));
9735 set_general_thread (sample_thread
);
9740 threadalive_test (char *cmd
, int tty
)
9742 int sample_thread
= SAMPLE_THREAD
;
9743 int pid
= ptid_get_pid (inferior_ptid
);
9744 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9746 if (remote_thread_alive (ptid
))
9747 printf_filtered ("PASS: Thread alive test\n");
9749 printf_filtered ("FAIL: Thread alive test\n");
9752 void output_threadid (char *title
, threadref
*ref
);
9755 output_threadid (char *title
, threadref
*ref
)
9759 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9761 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9765 threadlist_test_cmd (char *cmd
, int tty
)
9768 threadref nextthread
;
9769 int done
, result_count
;
9770 threadref threadlist
[3];
9772 printf_filtered ("Remote Threadlist test\n");
9773 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9774 &result_count
, &threadlist
[0]))
9775 printf_filtered ("FAIL: threadlist test\n");
9778 threadref
*scan
= threadlist
;
9779 threadref
*limit
= scan
+ result_count
;
9781 while (scan
< limit
)
9782 output_threadid (" thread ", scan
++);
9787 display_thread_info (struct gdb_ext_thread_info
*info
)
9789 output_threadid ("Threadid: ", &info
->threadid
);
9790 printf_filtered ("Name: %s\n ", info
->shortname
);
9791 printf_filtered ("State: %s\n", info
->display
);
9792 printf_filtered ("other: %s\n\n", info
->more_display
);
9796 get_and_display_threadinfo (threadref
*ref
)
9800 struct gdb_ext_thread_info threadinfo
;
9802 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9803 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9804 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9805 display_thread_info (&threadinfo
);
9810 threadinfo_test_cmd (char *cmd
, int tty
)
9812 int athread
= SAMPLE_THREAD
;
9816 int_to_threadref (&thread
, athread
);
9817 printf_filtered ("Remote Threadinfo test\n");
9818 if (!get_and_display_threadinfo (&thread
))
9819 printf_filtered ("FAIL cannot get thread info\n");
9823 thread_display_step (threadref
*ref
, void *context
)
9825 /* output_threadid(" threadstep ",ref); *//* simple test */
9826 return get_and_display_threadinfo (ref
);
9830 threadlist_update_test_cmd (char *cmd
, int tty
)
9832 printf_filtered ("Remote Threadlist update test\n");
9833 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9837 init_remote_threadtests (void)
9839 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9840 _("Fetch and print the remote list of "
9841 "thread identifiers, one pkt only"));
9842 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9843 _("Fetch and display info about one thread"));
9844 add_com ("tset", class_obscure
, threadset_test_cmd
,
9845 _("Test setting to a different thread"));
9846 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9847 _("Iterate through updating all remote thread info"));
9848 add_com ("talive", class_obscure
, threadalive_test
,
9849 _(" Remote thread alive test "));
9854 /* Convert a thread ID to a string. Returns the string in a static
9858 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9860 static char buf
[64];
9861 struct remote_state
*rs
= get_remote_state ();
9863 if (ptid_equal (ptid
, null_ptid
))
9864 return normal_pid_to_str (ptid
);
9865 else if (ptid_is_pid (ptid
))
9867 /* Printing an inferior target id. */
9869 /* When multi-process extensions are off, there's no way in the
9870 remote protocol to know the remote process id, if there's any
9871 at all. There's one exception --- when we're connected with
9872 target extended-remote, and we manually attached to a process
9873 with "attach PID". We don't record anywhere a flag that
9874 allows us to distinguish that case from the case of
9875 connecting with extended-remote and the stub already being
9876 attached to a process, and reporting yes to qAttached, hence
9877 no smart special casing here. */
9878 if (!remote_multi_process_p (rs
))
9880 xsnprintf (buf
, sizeof buf
, "Remote target");
9884 return normal_pid_to_str (ptid
);
9888 if (ptid_equal (magic_null_ptid
, ptid
))
9889 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9890 else if (rs
->extended
&& remote_multi_process_p (rs
))
9891 if (ptid_get_lwp (ptid
) == 0)
9892 return normal_pid_to_str (ptid
);
9894 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9895 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9897 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9898 ptid_get_lwp (ptid
));
9903 /* Get the address of the thread local variable in OBJFILE which is
9904 stored at OFFSET within the thread local storage for thread PTID. */
9907 remote_get_thread_local_address (struct target_ops
*ops
,
9908 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9910 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9912 struct remote_state
*rs
= get_remote_state ();
9914 char *endp
= rs
->buf
+ get_remote_packet_size ();
9915 enum packet_result result
;
9917 strcpy (p
, "qGetTLSAddr:");
9919 p
= write_ptid (p
, endp
, ptid
);
9921 p
+= hexnumstr (p
, offset
);
9923 p
+= hexnumstr (p
, lm
);
9927 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9928 result
= packet_ok (rs
->buf
,
9929 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9930 if (result
== PACKET_OK
)
9934 unpack_varlen_hex (rs
->buf
, &result
);
9937 else if (result
== PACKET_UNKNOWN
)
9938 throw_error (TLS_GENERIC_ERROR
,
9939 _("Remote target doesn't support qGetTLSAddr packet"));
9941 throw_error (TLS_GENERIC_ERROR
,
9942 _("Remote target failed to process qGetTLSAddr request"));
9945 throw_error (TLS_GENERIC_ERROR
,
9946 _("TLS not supported or disabled on this target"));
9951 /* Provide thread local base, i.e. Thread Information Block address.
9952 Returns 1 if ptid is found and thread_local_base is non zero. */
9955 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9957 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9959 struct remote_state
*rs
= get_remote_state ();
9961 char *endp
= rs
->buf
+ get_remote_packet_size ();
9962 enum packet_result result
;
9964 strcpy (p
, "qGetTIBAddr:");
9966 p
= write_ptid (p
, endp
, ptid
);
9970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9971 result
= packet_ok (rs
->buf
,
9972 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9973 if (result
== PACKET_OK
)
9977 unpack_varlen_hex (rs
->buf
, &result
);
9979 *addr
= (CORE_ADDR
) result
;
9982 else if (result
== PACKET_UNKNOWN
)
9983 error (_("Remote target doesn't support qGetTIBAddr packet"));
9985 error (_("Remote target failed to process qGetTIBAddr request"));
9988 error (_("qGetTIBAddr not supported or disabled on this target"));
9993 /* Support for inferring a target description based on the current
9994 architecture and the size of a 'g' packet. While the 'g' packet
9995 can have any size (since optional registers can be left off the
9996 end), some sizes are easily recognizable given knowledge of the
9997 approximate architecture. */
9999 struct remote_g_packet_guess
10002 const struct target_desc
*tdesc
;
10004 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10005 DEF_VEC_O(remote_g_packet_guess_s
);
10007 struct remote_g_packet_data
10009 VEC(remote_g_packet_guess_s
) *guesses
;
10012 static struct gdbarch_data
*remote_g_packet_data_handle
;
10015 remote_g_packet_data_init (struct obstack
*obstack
)
10017 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10021 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10022 const struct target_desc
*tdesc
)
10024 struct remote_g_packet_data
*data
10025 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
10026 struct remote_g_packet_guess new_guess
, *guess
;
10029 gdb_assert (tdesc
!= NULL
);
10032 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10034 if (guess
->bytes
== bytes
)
10035 internal_error (__FILE__
, __LINE__
,
10036 _("Duplicate g packet description added for size %d"),
10039 new_guess
.bytes
= bytes
;
10040 new_guess
.tdesc
= tdesc
;
10041 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10044 /* Return 1 if remote_read_description would do anything on this target
10045 and architecture, 0 otherwise. */
10048 remote_read_description_p (struct target_ops
*target
)
10050 struct remote_g_packet_data
*data
10051 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10053 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10059 static const struct target_desc
*
10060 remote_read_description (struct target_ops
*target
)
10062 struct remote_g_packet_data
*data
10063 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10065 /* Do not try this during initial connection, when we do not know
10066 whether there is a running but stopped thread. */
10067 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10068 return target
->beneath
->to_read_description (target
->beneath
);
10070 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10072 struct remote_g_packet_guess
*guess
;
10074 int bytes
= send_g_packet ();
10077 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10079 if (guess
->bytes
== bytes
)
10080 return guess
->tdesc
;
10082 /* We discard the g packet. A minor optimization would be to
10083 hold on to it, and fill the register cache once we have selected
10084 an architecture, but it's too tricky to do safely. */
10087 return target
->beneath
->to_read_description (target
->beneath
);
10090 /* Remote file transfer support. This is host-initiated I/O, not
10091 target-initiated; for target-initiated, see remote-fileio.c. */
10093 /* If *LEFT is at least the length of STRING, copy STRING to
10094 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10095 decrease *LEFT. Otherwise raise an error. */
10098 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10100 int len
= strlen (string
);
10103 error (_("Packet too long for target."));
10105 memcpy (*buffer
, string
, len
);
10109 /* NUL-terminate the buffer as a convenience, if there is
10115 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10116 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10117 decrease *LEFT. Otherwise raise an error. */
10120 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10123 if (2 * len
> *left
)
10124 error (_("Packet too long for target."));
10126 bin2hex (bytes
, *buffer
, len
);
10127 *buffer
+= 2 * len
;
10130 /* NUL-terminate the buffer as a convenience, if there is
10136 /* If *LEFT is large enough, convert VALUE to hex and add it to
10137 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10138 decrease *LEFT. Otherwise raise an error. */
10141 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10143 int len
= hexnumlen (value
);
10146 error (_("Packet too long for target."));
10148 hexnumstr (*buffer
, value
);
10152 /* NUL-terminate the buffer as a convenience, if there is
10158 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10159 value, *REMOTE_ERRNO to the remote error number or zero if none
10160 was included, and *ATTACHMENT to point to the start of the annex
10161 if any. The length of the packet isn't needed here; there may
10162 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10164 Return 0 if the packet could be parsed, -1 if it could not. If
10165 -1 is returned, the other variables may not be initialized. */
10168 remote_hostio_parse_result (char *buffer
, int *retcode
,
10169 int *remote_errno
, char **attachment
)
10174 *attachment
= NULL
;
10176 if (buffer
[0] != 'F')
10180 *retcode
= strtol (&buffer
[1], &p
, 16);
10181 if (errno
!= 0 || p
== &buffer
[1])
10184 /* Check for ",errno". */
10188 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10189 if (errno
!= 0 || p
+ 1 == p2
)
10194 /* Check for ";attachment". If there is no attachment, the
10195 packet should end here. */
10198 *attachment
= p
+ 1;
10201 else if (*p
== '\0')
10207 /* Send a prepared I/O packet to the target and read its response.
10208 The prepared packet is in the global RS->BUF before this function
10209 is called, and the answer is there when we return.
10211 COMMAND_BYTES is the length of the request to send, which may include
10212 binary data. WHICH_PACKET is the packet configuration to check
10213 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10214 is set to the error number and -1 is returned. Otherwise the value
10215 returned by the function is returned.
10217 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10218 attachment is expected; an error will be reported if there's a
10219 mismatch. If one is found, *ATTACHMENT will be set to point into
10220 the packet buffer and *ATTACHMENT_LEN will be set to the
10221 attachment's length. */
10224 remote_hostio_send_command (int command_bytes
, int which_packet
,
10225 int *remote_errno
, char **attachment
,
10226 int *attachment_len
)
10228 struct remote_state
*rs
= get_remote_state ();
10229 int ret
, bytes_read
;
10230 char *attachment_tmp
;
10232 if (!rs
->remote_desc
10233 || packet_support (which_packet
) == PACKET_DISABLE
)
10235 *remote_errno
= FILEIO_ENOSYS
;
10239 putpkt_binary (rs
->buf
, command_bytes
);
10240 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10242 /* If it timed out, something is wrong. Don't try to parse the
10244 if (bytes_read
< 0)
10246 *remote_errno
= FILEIO_EINVAL
;
10250 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10253 *remote_errno
= FILEIO_EINVAL
;
10255 case PACKET_UNKNOWN
:
10256 *remote_errno
= FILEIO_ENOSYS
;
10262 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10265 *remote_errno
= FILEIO_EINVAL
;
10269 /* Make sure we saw an attachment if and only if we expected one. */
10270 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10271 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10273 *remote_errno
= FILEIO_EINVAL
;
10277 /* If an attachment was found, it must point into the packet buffer;
10278 work out how many bytes there were. */
10279 if (attachment_tmp
!= NULL
)
10281 *attachment
= attachment_tmp
;
10282 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10288 /* Set the filesystem remote_hostio functions that take FILENAME
10289 arguments will use. Return 0 on success, or -1 if an error
10290 occurs (and set *REMOTE_ERRNO). */
10293 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10295 struct remote_state
*rs
= get_remote_state ();
10296 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10298 int left
= get_remote_packet_size () - 1;
10302 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10305 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10308 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10310 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10311 remote_buffer_add_string (&p
, &left
, arg
);
10313 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10314 remote_errno
, NULL
, NULL
);
10316 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10320 rs
->fs_pid
= required_pid
;
10325 /* Implementation of to_fileio_open. */
10328 remote_hostio_open (struct target_ops
*self
,
10329 struct inferior
*inf
, const char *filename
,
10330 int flags
, int mode
, int *remote_errno
)
10332 struct remote_state
*rs
= get_remote_state ();
10334 int left
= get_remote_packet_size () - 1;
10336 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10339 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10341 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10342 strlen (filename
));
10343 remote_buffer_add_string (&p
, &left
, ",");
10345 remote_buffer_add_int (&p
, &left
, flags
);
10346 remote_buffer_add_string (&p
, &left
, ",");
10348 remote_buffer_add_int (&p
, &left
, mode
);
10350 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10351 remote_errno
, NULL
, NULL
);
10354 /* Implementation of to_fileio_pwrite. */
10357 remote_hostio_pwrite (struct target_ops
*self
,
10358 int fd
, const gdb_byte
*write_buf
, int len
,
10359 ULONGEST offset
, int *remote_errno
)
10361 struct remote_state
*rs
= get_remote_state ();
10363 int left
= get_remote_packet_size ();
10366 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10368 remote_buffer_add_int (&p
, &left
, fd
);
10369 remote_buffer_add_string (&p
, &left
, ",");
10371 remote_buffer_add_int (&p
, &left
, offset
);
10372 remote_buffer_add_string (&p
, &left
, ",");
10374 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10375 get_remote_packet_size () - (p
- rs
->buf
));
10377 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10378 remote_errno
, NULL
, NULL
);
10381 /* Implementation of to_fileio_pread. */
10384 remote_hostio_pread (struct target_ops
*self
,
10385 int fd
, gdb_byte
*read_buf
, int len
,
10386 ULONGEST offset
, int *remote_errno
)
10388 struct remote_state
*rs
= get_remote_state ();
10391 int left
= get_remote_packet_size ();
10392 int ret
, attachment_len
;
10395 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10397 remote_buffer_add_int (&p
, &left
, fd
);
10398 remote_buffer_add_string (&p
, &left
, ",");
10400 remote_buffer_add_int (&p
, &left
, len
);
10401 remote_buffer_add_string (&p
, &left
, ",");
10403 remote_buffer_add_int (&p
, &left
, offset
);
10405 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10406 remote_errno
, &attachment
,
10412 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10414 if (read_len
!= ret
)
10415 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10420 /* Implementation of to_fileio_close. */
10423 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10425 struct remote_state
*rs
= get_remote_state ();
10427 int left
= get_remote_packet_size () - 1;
10429 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10431 remote_buffer_add_int (&p
, &left
, fd
);
10433 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10434 remote_errno
, NULL
, NULL
);
10437 /* Implementation of to_fileio_unlink. */
10440 remote_hostio_unlink (struct target_ops
*self
,
10441 struct inferior
*inf
, const char *filename
,
10444 struct remote_state
*rs
= get_remote_state ();
10446 int left
= get_remote_packet_size () - 1;
10448 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10451 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10453 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10454 strlen (filename
));
10456 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10457 remote_errno
, NULL
, NULL
);
10460 /* Implementation of to_fileio_readlink. */
10463 remote_hostio_readlink (struct target_ops
*self
,
10464 struct inferior
*inf
, const char *filename
,
10467 struct remote_state
*rs
= get_remote_state ();
10470 int left
= get_remote_packet_size ();
10471 int len
, attachment_len
;
10475 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10478 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10480 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10481 strlen (filename
));
10483 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10484 remote_errno
, &attachment
,
10490 ret
= xmalloc (len
+ 1);
10492 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10493 (gdb_byte
*) ret
, len
);
10494 if (read_len
!= len
)
10495 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10501 /* Implementation of to_fileio_fstat. */
10504 remote_hostio_fstat (struct target_ops
*self
,
10505 int fd
, struct stat
*st
,
10508 struct remote_state
*rs
= get_remote_state ();
10510 int left
= get_remote_packet_size ();
10511 int attachment_len
, ret
;
10513 struct fio_stat fst
;
10516 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10518 remote_buffer_add_int (&p
, &left
, fd
);
10520 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10521 remote_errno
, &attachment
,
10525 if (*remote_errno
!= FILEIO_ENOSYS
)
10528 /* Strictly we should return -1, ENOSYS here, but when
10529 "set sysroot remote:" was implemented in August 2008
10530 BFD's need for a stat function was sidestepped with
10531 this hack. This was not remedied until March 2015
10532 so we retain the previous behavior to avoid breaking
10535 Note that the memset is a March 2015 addition; older
10536 GDBs set st_size *and nothing else* so the structure
10537 would have garbage in all other fields. This might
10538 break something but retaining the previous behavior
10539 here would be just too wrong. */
10541 memset (st
, 0, sizeof (struct stat
));
10542 st
->st_size
= INT_MAX
;
10546 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10547 (gdb_byte
*) &fst
, sizeof (fst
));
10549 if (read_len
!= ret
)
10550 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10552 if (read_len
!= sizeof (fst
))
10553 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10554 read_len
, (int) sizeof (fst
));
10556 remote_fileio_to_host_stat (&fst
, st
);
10561 /* Implementation of to_filesystem_is_local. */
10564 remote_filesystem_is_local (struct target_ops
*self
)
10566 /* Valgrind GDB presents itself as a remote target but works
10567 on the local filesystem: it does not implement remote get
10568 and users are not expected to set a sysroot. To handle
10569 this case we treat the remote filesystem as local if the
10570 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
10571 does not support vFile:open. */
10572 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
10574 enum packet_support ps
= packet_support (PACKET_vFile_open
);
10576 if (ps
== PACKET_SUPPORT_UNKNOWN
)
10578 int fd
, remote_errno
;
10580 /* Try opening a file to probe support. The supplied
10581 filename is irrelevant, we only care about whether
10582 the stub recognizes the packet or not. */
10583 fd
= remote_hostio_open (self
, NULL
, "just probing",
10584 FILEIO_O_RDONLY
, 0700,
10588 remote_hostio_close (self
, fd
, &remote_errno
);
10590 ps
= packet_support (PACKET_vFile_open
);
10593 if (ps
== PACKET_DISABLE
)
10595 static int warning_issued
= 0;
10597 if (!warning_issued
)
10599 warning (_("remote target does not support file"
10600 " transfer, attempting to access files"
10601 " from local filesystem."));
10602 warning_issued
= 1;
10613 remote_fileio_errno_to_host (int errnum
)
10619 case FILEIO_ENOENT
:
10627 case FILEIO_EACCES
:
10629 case FILEIO_EFAULT
:
10633 case FILEIO_EEXIST
:
10635 case FILEIO_ENODEV
:
10637 case FILEIO_ENOTDIR
:
10639 case FILEIO_EISDIR
:
10641 case FILEIO_EINVAL
:
10643 case FILEIO_ENFILE
:
10645 case FILEIO_EMFILE
:
10649 case FILEIO_ENOSPC
:
10651 case FILEIO_ESPIPE
:
10655 case FILEIO_ENOSYS
:
10657 case FILEIO_ENAMETOOLONG
:
10658 return ENAMETOOLONG
;
10664 remote_hostio_error (int errnum
)
10666 int host_error
= remote_fileio_errno_to_host (errnum
);
10668 if (host_error
== -1)
10669 error (_("Unknown remote I/O error %d"), errnum
);
10671 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10675 remote_hostio_close_cleanup (void *opaque
)
10677 int fd
= *(int *) opaque
;
10680 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10684 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10686 struct cleanup
*back_to
, *close_cleanup
;
10687 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10690 int bytes_in_buffer
;
10693 struct remote_state
*rs
= get_remote_state ();
10695 if (!rs
->remote_desc
)
10696 error (_("command can only be used with remote target"));
10698 file
= gdb_fopen_cloexec (local_file
, "rb");
10700 perror_with_name (local_file
);
10701 back_to
= make_cleanup_fclose (file
);
10703 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10704 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10706 0700, &remote_errno
);
10708 remote_hostio_error (remote_errno
);
10710 /* Send up to this many bytes at once. They won't all fit in the
10711 remote packet limit, so we'll transfer slightly fewer. */
10712 io_size
= get_remote_packet_size ();
10713 buffer
= xmalloc (io_size
);
10714 make_cleanup (xfree
, buffer
);
10716 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10718 bytes_in_buffer
= 0;
10721 while (bytes_in_buffer
|| !saw_eof
)
10725 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10726 io_size
- bytes_in_buffer
,
10731 error (_("Error reading %s."), local_file
);
10734 /* EOF. Unless there is something still in the
10735 buffer from the last iteration, we are done. */
10737 if (bytes_in_buffer
== 0)
10745 bytes
+= bytes_in_buffer
;
10746 bytes_in_buffer
= 0;
10748 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10750 offset
, &remote_errno
);
10753 remote_hostio_error (remote_errno
);
10754 else if (retcode
== 0)
10755 error (_("Remote write of %d bytes returned 0!"), bytes
);
10756 else if (retcode
< bytes
)
10758 /* Short write. Save the rest of the read data for the next
10760 bytes_in_buffer
= bytes
- retcode
;
10761 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10767 discard_cleanups (close_cleanup
);
10768 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10769 remote_hostio_error (remote_errno
);
10772 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10773 do_cleanups (back_to
);
10777 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10779 struct cleanup
*back_to
, *close_cleanup
;
10780 int fd
, remote_errno
, bytes
, io_size
;
10784 struct remote_state
*rs
= get_remote_state ();
10786 if (!rs
->remote_desc
)
10787 error (_("command can only be used with remote target"));
10789 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10790 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10792 remote_hostio_error (remote_errno
);
10794 file
= gdb_fopen_cloexec (local_file
, "wb");
10796 perror_with_name (local_file
);
10797 back_to
= make_cleanup_fclose (file
);
10799 /* Send up to this many bytes at once. They won't all fit in the
10800 remote packet limit, so we'll transfer slightly fewer. */
10801 io_size
= get_remote_packet_size ();
10802 buffer
= xmalloc (io_size
);
10803 make_cleanup (xfree
, buffer
);
10805 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10810 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10811 fd
, buffer
, io_size
, offset
, &remote_errno
);
10813 /* Success, but no bytes, means end-of-file. */
10816 remote_hostio_error (remote_errno
);
10820 bytes
= fwrite (buffer
, 1, bytes
, file
);
10822 perror_with_name (local_file
);
10825 discard_cleanups (close_cleanup
);
10826 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10827 remote_hostio_error (remote_errno
);
10830 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10831 do_cleanups (back_to
);
10835 remote_file_delete (const char *remote_file
, int from_tty
)
10837 int retcode
, remote_errno
;
10838 struct remote_state
*rs
= get_remote_state ();
10840 if (!rs
->remote_desc
)
10841 error (_("command can only be used with remote target"));
10843 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10844 NULL
, remote_file
, &remote_errno
);
10846 remote_hostio_error (remote_errno
);
10849 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10853 remote_put_command (char *args
, int from_tty
)
10855 struct cleanup
*back_to
;
10859 error_no_arg (_("file to put"));
10861 argv
= gdb_buildargv (args
);
10862 back_to
= make_cleanup_freeargv (argv
);
10863 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10864 error (_("Invalid parameters to remote put"));
10866 remote_file_put (argv
[0], argv
[1], from_tty
);
10868 do_cleanups (back_to
);
10872 remote_get_command (char *args
, int from_tty
)
10874 struct cleanup
*back_to
;
10878 error_no_arg (_("file to get"));
10880 argv
= gdb_buildargv (args
);
10881 back_to
= make_cleanup_freeargv (argv
);
10882 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10883 error (_("Invalid parameters to remote get"));
10885 remote_file_get (argv
[0], argv
[1], from_tty
);
10887 do_cleanups (back_to
);
10891 remote_delete_command (char *args
, int from_tty
)
10893 struct cleanup
*back_to
;
10897 error_no_arg (_("file to delete"));
10899 argv
= gdb_buildargv (args
);
10900 back_to
= make_cleanup_freeargv (argv
);
10901 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10902 error (_("Invalid parameters to remote delete"));
10904 remote_file_delete (argv
[0], from_tty
);
10906 do_cleanups (back_to
);
10910 remote_command (char *args
, int from_tty
)
10912 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10916 remote_can_execute_reverse (struct target_ops
*self
)
10918 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10919 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10926 remote_supports_non_stop (struct target_ops
*self
)
10932 remote_supports_disable_randomization (struct target_ops
*self
)
10934 /* Only supported in extended mode. */
10939 remote_supports_multi_process (struct target_ops
*self
)
10941 struct remote_state
*rs
= get_remote_state ();
10943 /* Only extended-remote handles being attached to multiple
10944 processes, even though plain remote can use the multi-process
10945 thread id extensions, so that GDB knows the target process's
10947 return rs
->extended
&& remote_multi_process_p (rs
);
10951 remote_supports_cond_tracepoints (void)
10953 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10957 remote_supports_cond_breakpoints (struct target_ops
*self
)
10959 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10963 remote_supports_fast_tracepoints (void)
10965 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
10969 remote_supports_static_tracepoints (void)
10971 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
10975 remote_supports_install_in_trace (void)
10977 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
10981 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
10983 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
10988 remote_supports_string_tracing (struct target_ops
*self
)
10990 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
10994 remote_can_run_breakpoint_commands (struct target_ops
*self
)
10996 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11000 remote_trace_init (struct target_ops
*self
)
11003 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11004 if (strcmp (target_buf
, "OK") != 0)
11005 error (_("Target does not support this command."));
11008 static void free_actions_list (char **actions_list
);
11009 static void free_actions_list_cleanup_wrapper (void *);
11011 free_actions_list_cleanup_wrapper (void *al
)
11013 free_actions_list (al
);
11017 free_actions_list (char **actions_list
)
11021 if (actions_list
== 0)
11024 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11025 xfree (actions_list
[ndx
]);
11027 xfree (actions_list
);
11030 /* Recursive routine to walk through command list including loops, and
11031 download packets for each command. */
11034 remote_download_command_source (int num
, ULONGEST addr
,
11035 struct command_line
*cmds
)
11037 struct remote_state
*rs
= get_remote_state ();
11038 struct command_line
*cmd
;
11040 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11042 QUIT
; /* Allow user to bail out with ^C. */
11043 strcpy (rs
->buf
, "QTDPsrc:");
11044 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11045 rs
->buf
+ strlen (rs
->buf
),
11046 rs
->buf_size
- strlen (rs
->buf
));
11048 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11049 if (strcmp (target_buf
, "OK"))
11050 warning (_("Target does not support source download."));
11052 if (cmd
->control_type
== while_control
11053 || cmd
->control_type
== while_stepping_control
)
11055 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11057 QUIT
; /* Allow user to bail out with ^C. */
11058 strcpy (rs
->buf
, "QTDPsrc:");
11059 encode_source_string (num
, addr
, "cmd", "end",
11060 rs
->buf
+ strlen (rs
->buf
),
11061 rs
->buf_size
- strlen (rs
->buf
));
11063 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11064 if (strcmp (target_buf
, "OK"))
11065 warning (_("Target does not support source download."));
11071 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11073 #define BUF_SIZE 2048
11077 char buf
[BUF_SIZE
];
11078 char **tdp_actions
;
11079 char **stepping_actions
;
11081 struct cleanup
*old_chain
= NULL
;
11082 struct agent_expr
*aexpr
;
11083 struct cleanup
*aexpr_chain
= NULL
;
11085 struct breakpoint
*b
= loc
->owner
;
11086 struct tracepoint
*t
= (struct tracepoint
*) b
;
11088 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11089 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11091 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11094 tpaddr
= loc
->address
;
11095 sprintf_vma (addrbuf
, tpaddr
);
11096 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11097 addrbuf
, /* address */
11098 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11099 t
->step_count
, t
->pass_count
);
11100 /* Fast tracepoints are mostly handled by the target, but we can
11101 tell the target how big of an instruction block should be moved
11103 if (b
->type
== bp_fast_tracepoint
)
11105 /* Only test for support at download time; we may not know
11106 target capabilities at definition time. */
11107 if (remote_supports_fast_tracepoints ())
11111 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
11112 tpaddr
, &isize
, NULL
))
11113 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11116 /* If it passed validation at definition but fails now,
11117 something is very wrong. */
11118 internal_error (__FILE__
, __LINE__
,
11119 _("Fast tracepoint not "
11120 "valid during download"));
11123 /* Fast tracepoints are functionally identical to regular
11124 tracepoints, so don't take lack of support as a reason to
11125 give up on the trace run. */
11126 warning (_("Target does not support fast tracepoints, "
11127 "downloading %d as regular tracepoint"), b
->number
);
11129 else if (b
->type
== bp_static_tracepoint
)
11131 /* Only test for support at download time; we may not know
11132 target capabilities at definition time. */
11133 if (remote_supports_static_tracepoints ())
11135 struct static_tracepoint_marker marker
;
11137 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11138 strcat (buf
, ":S");
11140 error (_("Static tracepoint not valid during download"));
11143 /* Fast tracepoints are functionally identical to regular
11144 tracepoints, so don't take lack of support as a reason
11145 to give up on the trace run. */
11146 error (_("Target does not support static tracepoints"));
11148 /* If the tracepoint has a conditional, make it into an agent
11149 expression and append to the definition. */
11152 /* Only test support at download time, we may not know target
11153 capabilities at definition time. */
11154 if (remote_supports_cond_tracepoints ())
11156 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11157 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11158 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11160 pkt
= buf
+ strlen (buf
);
11161 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11162 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11164 do_cleanups (aexpr_chain
);
11167 warning (_("Target does not support conditional tracepoints, "
11168 "ignoring tp %d cond"), b
->number
);
11171 if (b
->commands
|| *default_collect
)
11174 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11175 if (strcmp (target_buf
, "OK"))
11176 error (_("Target does not support tracepoints."));
11178 /* do_single_steps (t); */
11181 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11183 QUIT
; /* Allow user to bail out with ^C. */
11184 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11185 b
->number
, addrbuf
, /* address */
11187 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11190 remote_get_noisy_reply (&target_buf
,
11192 if (strcmp (target_buf
, "OK"))
11193 error (_("Error on target while setting tracepoints."));
11196 if (stepping_actions
)
11198 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11200 QUIT
; /* Allow user to bail out with ^C. */
11201 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11202 b
->number
, addrbuf
, /* address */
11203 ((ndx
== 0) ? "S" : ""),
11204 stepping_actions
[ndx
],
11205 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11207 remote_get_noisy_reply (&target_buf
,
11209 if (strcmp (target_buf
, "OK"))
11210 error (_("Error on target while setting tracepoints."));
11214 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11216 if (b
->addr_string
)
11218 strcpy (buf
, "QTDPsrc:");
11219 encode_source_string (b
->number
, loc
->address
,
11220 "at", b
->addr_string
, buf
+ strlen (buf
),
11221 2048 - strlen (buf
));
11224 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11225 if (strcmp (target_buf
, "OK"))
11226 warning (_("Target does not support source download."));
11228 if (b
->cond_string
)
11230 strcpy (buf
, "QTDPsrc:");
11231 encode_source_string (b
->number
, loc
->address
,
11232 "cond", b
->cond_string
, buf
+ strlen (buf
),
11233 2048 - strlen (buf
));
11235 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11236 if (strcmp (target_buf
, "OK"))
11237 warning (_("Target does not support source download."));
11239 remote_download_command_source (b
->number
, loc
->address
,
11240 breakpoint_commands (b
));
11243 do_cleanups (old_chain
);
11247 remote_can_download_tracepoint (struct target_ops
*self
)
11249 struct remote_state
*rs
= get_remote_state ();
11250 struct trace_status
*ts
;
11253 /* Don't try to install tracepoints until we've relocated our
11254 symbols, and fetched and merged the target's tracepoint list with
11256 if (rs
->starting_up
)
11259 ts
= current_trace_status ();
11260 status
= remote_get_trace_status (self
, ts
);
11262 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11265 /* If we are in a tracing experiment, but remote stub doesn't support
11266 installing tracepoint in trace, we have to return. */
11267 if (!remote_supports_install_in_trace ())
11275 remote_download_trace_state_variable (struct target_ops
*self
,
11276 struct trace_state_variable
*tsv
)
11278 struct remote_state
*rs
= get_remote_state ();
11281 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11282 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11284 p
= rs
->buf
+ strlen (rs
->buf
);
11285 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11286 error (_("Trace state variable name too long for tsv definition packet"));
11287 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11290 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11291 if (*target_buf
== '\0')
11292 error (_("Target does not support this command."));
11293 if (strcmp (target_buf
, "OK") != 0)
11294 error (_("Error on target while downloading trace state variable."));
11298 remote_enable_tracepoint (struct target_ops
*self
,
11299 struct bp_location
*location
)
11301 struct remote_state
*rs
= get_remote_state ();
11304 sprintf_vma (addr_buf
, location
->address
);
11305 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11306 location
->owner
->number
, addr_buf
);
11308 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11309 if (*rs
->buf
== '\0')
11310 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11311 if (strcmp (rs
->buf
, "OK") != 0)
11312 error (_("Error on target while enabling tracepoint."));
11316 remote_disable_tracepoint (struct target_ops
*self
,
11317 struct bp_location
*location
)
11319 struct remote_state
*rs
= get_remote_state ();
11322 sprintf_vma (addr_buf
, location
->address
);
11323 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11324 location
->owner
->number
, addr_buf
);
11326 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11327 if (*rs
->buf
== '\0')
11328 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11329 if (strcmp (rs
->buf
, "OK") != 0)
11330 error (_("Error on target while disabling tracepoint."));
11334 remote_trace_set_readonly_regions (struct target_ops
*self
)
11338 bfd_size_type size
;
11344 return; /* No information to give. */
11346 strcpy (target_buf
, "QTro");
11347 offset
= strlen (target_buf
);
11348 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11350 char tmp1
[40], tmp2
[40];
11353 if ((s
->flags
& SEC_LOAD
) == 0 ||
11354 /* (s->flags & SEC_CODE) == 0 || */
11355 (s
->flags
& SEC_READONLY
) == 0)
11359 vma
= bfd_get_section_vma (abfd
, s
);
11360 size
= bfd_get_section_size (s
);
11361 sprintf_vma (tmp1
, vma
);
11362 sprintf_vma (tmp2
, vma
+ size
);
11363 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11364 if (offset
+ sec_length
+ 1 > target_buf_size
)
11366 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11368 Too many sections for read-only sections definition packet."));
11371 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11373 offset
+= sec_length
;
11377 putpkt (target_buf
);
11378 getpkt (&target_buf
, &target_buf_size
, 0);
11383 remote_trace_start (struct target_ops
*self
)
11385 putpkt ("QTStart");
11386 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11387 if (*target_buf
== '\0')
11388 error (_("Target does not support this command."));
11389 if (strcmp (target_buf
, "OK") != 0)
11390 error (_("Bogus reply from target: %s"), target_buf
);
11394 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11396 /* Initialize it just to avoid a GCC false warning. */
11398 /* FIXME we need to get register block size some other way. */
11399 extern int trace_regblock_size
;
11400 enum packet_result result
;
11402 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11405 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11407 putpkt ("qTStatus");
11411 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11413 CATCH (ex
, RETURN_MASK_ERROR
)
11415 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11417 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11420 throw_exception (ex
);
11424 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11426 /* If the remote target doesn't do tracing, flag it. */
11427 if (result
== PACKET_UNKNOWN
)
11430 /* We're working with a live target. */
11431 ts
->filename
= NULL
;
11434 error (_("Bogus trace status reply from target: %s"), target_buf
);
11436 /* Function 'parse_trace_status' sets default value of each field of
11437 'ts' at first, so we don't have to do it here. */
11438 parse_trace_status (p
, ts
);
11440 return ts
->running
;
11444 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11445 struct uploaded_tp
*utp
)
11447 struct remote_state
*rs
= get_remote_state ();
11449 struct bp_location
*loc
;
11450 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11451 size_t size
= get_remote_packet_size ();
11455 tp
->base
.hit_count
= 0;
11456 tp
->traceframe_usage
= 0;
11457 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11459 /* If the tracepoint was never downloaded, don't go asking for
11461 if (tp
->number_on_target
== 0)
11463 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11464 phex_nz (loc
->address
, 0));
11466 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11467 if (reply
&& *reply
)
11470 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11476 utp
->hit_count
= 0;
11477 utp
->traceframe_usage
= 0;
11478 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11479 phex_nz (utp
->addr
, 0));
11481 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11482 if (reply
&& *reply
)
11485 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11491 remote_trace_stop (struct target_ops
*self
)
11494 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11495 if (*target_buf
== '\0')
11496 error (_("Target does not support this command."));
11497 if (strcmp (target_buf
, "OK") != 0)
11498 error (_("Bogus reply from target: %s"), target_buf
);
11502 remote_trace_find (struct target_ops
*self
,
11503 enum trace_find_type type
, int num
,
11504 CORE_ADDR addr1
, CORE_ADDR addr2
,
11507 struct remote_state
*rs
= get_remote_state ();
11508 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11510 int target_frameno
= -1, target_tracept
= -1;
11512 /* Lookups other than by absolute frame number depend on the current
11513 trace selected, so make sure it is correct on the remote end
11515 if (type
!= tfind_number
)
11516 set_remote_traceframe ();
11519 strcpy (p
, "QTFrame:");
11520 p
= strchr (p
, '\0');
11524 xsnprintf (p
, endbuf
- p
, "%x", num
);
11527 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11530 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11533 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11534 phex_nz (addr2
, 0));
11536 case tfind_outside
:
11537 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11538 phex_nz (addr2
, 0));
11541 error (_("Unknown trace find type %d"), type
);
11545 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11546 if (*reply
== '\0')
11547 error (_("Target does not support this command."));
11549 while (reply
&& *reply
)
11554 target_frameno
= (int) strtol (p
, &reply
, 16);
11556 error (_("Unable to parse trace frame number"));
11557 /* Don't update our remote traceframe number cache on failure
11558 to select a remote traceframe. */
11559 if (target_frameno
== -1)
11564 target_tracept
= (int) strtol (p
, &reply
, 16);
11566 error (_("Unable to parse tracepoint number"));
11568 case 'O': /* "OK"? */
11569 if (reply
[1] == 'K' && reply
[2] == '\0')
11572 error (_("Bogus reply from target: %s"), reply
);
11575 error (_("Bogus reply from target: %s"), reply
);
11578 *tpp
= target_tracept
;
11580 rs
->remote_traceframe_number
= target_frameno
;
11581 return target_frameno
;
11585 remote_get_trace_state_variable_value (struct target_ops
*self
,
11586 int tsvnum
, LONGEST
*val
)
11588 struct remote_state
*rs
= get_remote_state ();
11592 set_remote_traceframe ();
11594 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11596 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11597 if (reply
&& *reply
)
11601 unpack_varlen_hex (reply
+ 1, &uval
);
11602 *val
= (LONGEST
) uval
;
11610 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11612 struct remote_state
*rs
= get_remote_state ();
11616 strcpy (p
, "QTSave:");
11618 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11619 error (_("Remote file name too long for trace save packet"));
11620 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11623 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11624 if (*reply
== '\0')
11625 error (_("Target does not support this command."));
11626 if (strcmp (reply
, "OK") != 0)
11627 error (_("Bogus reply from target: %s"), reply
);
11631 /* This is basically a memory transfer, but needs to be its own packet
11632 because we don't know how the target actually organizes its trace
11633 memory, plus we want to be able to ask for as much as possible, but
11634 not be unhappy if we don't get as much as we ask for. */
11637 remote_get_raw_trace_data (struct target_ops
*self
,
11638 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11640 struct remote_state
*rs
= get_remote_state ();
11646 strcpy (p
, "qTBuffer:");
11648 p
+= hexnumstr (p
, offset
);
11650 p
+= hexnumstr (p
, len
);
11654 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11655 if (reply
&& *reply
)
11657 /* 'l' by itself means we're at the end of the buffer and
11658 there is nothing more to get. */
11662 /* Convert the reply into binary. Limit the number of bytes to
11663 convert according to our passed-in buffer size, rather than
11664 what was returned in the packet; if the target is
11665 unexpectedly generous and gives us a bigger reply than we
11666 asked for, we don't want to crash. */
11667 rslt
= hex2bin (target_buf
, buf
, len
);
11671 /* Something went wrong, flag as an error. */
11676 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11678 struct remote_state
*rs
= get_remote_state ();
11680 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11684 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11686 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11687 if (*reply
== '\0')
11688 error (_("Target does not support this command."));
11689 if (strcmp (reply
, "OK") != 0)
11690 error (_("Bogus reply from target: %s"), reply
);
11693 warning (_("Target does not support disconnected tracing."));
11697 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11699 struct thread_info
*info
= find_thread_ptid (ptid
);
11701 if (info
&& info
->priv
)
11702 return info
->priv
->core
;
11707 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11709 struct remote_state
*rs
= get_remote_state ();
11712 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11714 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11715 if (*reply
== '\0')
11716 error (_("Target does not support this command."));
11717 if (strcmp (reply
, "OK") != 0)
11718 error (_("Bogus reply from target: %s"), reply
);
11721 static struct traceframe_info
*
11722 remote_traceframe_info (struct target_ops
*self
)
11726 text
= target_read_stralloc (¤t_target
,
11727 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11730 struct traceframe_info
*info
;
11731 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11733 info
= parse_traceframe_info (text
);
11734 do_cleanups (back_to
);
11741 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11742 instruction on which a fast tracepoint may be placed. Returns -1
11743 if the packet is not supported, and 0 if the minimum instruction
11744 length is unknown. */
11747 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11749 struct remote_state
*rs
= get_remote_state ();
11752 /* If we're not debugging a process yet, the IPA can't be
11754 if (!target_has_execution
)
11757 /* Make sure the remote is pointing at the right process. */
11758 set_general_process ();
11760 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11762 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11763 if (*reply
== '\0')
11767 ULONGEST min_insn_len
;
11769 unpack_varlen_hex (reply
, &min_insn_len
);
11771 return (int) min_insn_len
;
11776 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11778 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11780 struct remote_state
*rs
= get_remote_state ();
11781 char *buf
= rs
->buf
;
11782 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11783 enum packet_result result
;
11785 gdb_assert (val
>= 0 || val
== -1);
11786 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11787 /* Send -1 as literal "-1" to avoid host size dependency. */
11791 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11794 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11797 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11798 result
= packet_ok (rs
->buf
,
11799 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11801 if (result
!= PACKET_OK
)
11802 warning (_("Bogus reply from target: %s"), rs
->buf
);
11807 remote_set_trace_notes (struct target_ops
*self
,
11808 const char *user
, const char *notes
,
11809 const char *stop_notes
)
11811 struct remote_state
*rs
= get_remote_state ();
11813 char *buf
= rs
->buf
;
11814 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11817 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11820 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11821 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11827 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11828 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11834 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11835 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11839 /* Ensure the buffer is terminated. */
11843 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11844 if (*reply
== '\0')
11847 if (strcmp (reply
, "OK") != 0)
11848 error (_("Bogus reply from target: %s"), reply
);
11854 remote_use_agent (struct target_ops
*self
, int use
)
11856 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11858 struct remote_state
*rs
= get_remote_state ();
11860 /* If the stub supports QAgent. */
11861 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11863 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11865 if (strcmp (rs
->buf
, "OK") == 0)
11876 remote_can_use_agent (struct target_ops
*self
)
11878 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11881 struct btrace_target_info
11883 /* The ptid of the traced thread. */
11886 /* The obtained branch trace configuration. */
11887 struct btrace_config conf
;
11890 /* Reset our idea of our target's btrace configuration. */
11893 remote_btrace_reset (void)
11895 struct remote_state
*rs
= get_remote_state ();
11897 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
11900 /* Check whether the target supports branch tracing. */
11903 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
11905 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11907 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11912 case BTRACE_FORMAT_NONE
:
11915 case BTRACE_FORMAT_BTS
:
11916 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
11918 case BTRACE_FORMAT_PT
:
11919 /* The trace is decoded on the host. Even if our target supports it,
11920 we still need to have libipt to decode the trace. */
11921 #if defined (HAVE_LIBIPT)
11922 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
11923 #else /* !defined (HAVE_LIBIPT) */
11925 #endif /* !defined (HAVE_LIBIPT) */
11928 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
11931 /* Synchronize the configuration with the target. */
11934 btrace_sync_conf (const struct btrace_config
*conf
)
11936 struct packet_config
*packet
;
11937 struct remote_state
*rs
;
11938 char *buf
, *pos
, *endbuf
;
11940 rs
= get_remote_state ();
11942 endbuf
= buf
+ get_remote_packet_size ();
11944 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
11945 if (packet_config_support (packet
) == PACKET_ENABLE
11946 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
11949 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11953 getpkt (&buf
, &rs
->buf_size
, 0);
11955 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11957 if (buf
[0] == 'E' && buf
[1] == '.')
11958 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
11960 error (_("Failed to configure the BTS buffer size."));
11963 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
11966 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
11967 if (packet_config_support (packet
) == PACKET_ENABLE
11968 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
11971 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11975 getpkt (&buf
, &rs
->buf_size
, 0);
11977 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11979 if (buf
[0] == 'E' && buf
[1] == '.')
11980 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
11982 error (_("Failed to configure the trace buffer size."));
11985 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
11989 /* Read the current thread's btrace configuration from the target and
11990 store it into CONF. */
11993 btrace_read_config (struct btrace_config
*conf
)
11997 xml
= target_read_stralloc (¤t_target
,
11998 TARGET_OBJECT_BTRACE_CONF
, "");
12001 struct cleanup
*cleanup
;
12003 cleanup
= make_cleanup (xfree
, xml
);
12004 parse_xml_btrace_conf (conf
, xml
);
12005 do_cleanups (cleanup
);
12009 /* Enable branch tracing. */
12011 static struct btrace_target_info
*
12012 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12013 const struct btrace_config
*conf
)
12015 struct btrace_target_info
*tinfo
= NULL
;
12016 struct packet_config
*packet
= NULL
;
12017 struct remote_state
*rs
= get_remote_state ();
12018 char *buf
= rs
->buf
;
12019 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12021 switch (conf
->format
)
12023 case BTRACE_FORMAT_BTS
:
12024 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12027 case BTRACE_FORMAT_PT
:
12028 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12032 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12033 error (_("Target does not support branch tracing."));
12035 btrace_sync_conf (conf
);
12037 set_general_thread (ptid
);
12039 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12041 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12043 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12045 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12046 error (_("Could not enable branch tracing for %s: %s"),
12047 target_pid_to_str (ptid
), rs
->buf
+ 2);
12049 error (_("Could not enable branch tracing for %s."),
12050 target_pid_to_str (ptid
));
12053 tinfo
= xzalloc (sizeof (*tinfo
));
12054 tinfo
->ptid
= ptid
;
12056 /* If we fail to read the configuration, we lose some information, but the
12057 tracing itself is not impacted. */
12060 btrace_read_config (&tinfo
->conf
);
12062 CATCH (err
, RETURN_MASK_ERROR
)
12064 if (err
.message
!= NULL
)
12065 warning ("%s", err
.message
);
12072 /* Disable branch tracing. */
12075 remote_disable_btrace (struct target_ops
*self
,
12076 struct btrace_target_info
*tinfo
)
12078 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12079 struct remote_state
*rs
= get_remote_state ();
12080 char *buf
= rs
->buf
;
12081 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12083 if (packet_config_support (packet
) != PACKET_ENABLE
)
12084 error (_("Target does not support branch tracing."));
12086 set_general_thread (tinfo
->ptid
);
12088 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12090 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12092 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12094 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12095 error (_("Could not disable branch tracing for %s: %s"),
12096 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12098 error (_("Could not disable branch tracing for %s."),
12099 target_pid_to_str (tinfo
->ptid
));
12105 /* Teardown branch tracing. */
12108 remote_teardown_btrace (struct target_ops
*self
,
12109 struct btrace_target_info
*tinfo
)
12111 /* We must not talk to the target during teardown. */
12115 /* Read the branch trace. */
12117 static enum btrace_error
12118 remote_read_btrace (struct target_ops
*self
,
12119 struct btrace_data
*btrace
,
12120 struct btrace_target_info
*tinfo
,
12121 enum btrace_read_type type
)
12123 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12124 struct remote_state
*rs
= get_remote_state ();
12125 struct cleanup
*cleanup
;
12129 if (packet_config_support (packet
) != PACKET_ENABLE
)
12130 error (_("Target does not support branch tracing."));
12132 #if !defined(HAVE_LIBEXPAT)
12133 error (_("Cannot process branch tracing result. XML parsing not supported."));
12138 case BTRACE_READ_ALL
:
12141 case BTRACE_READ_NEW
:
12144 case BTRACE_READ_DELTA
:
12148 internal_error (__FILE__
, __LINE__
,
12149 _("Bad branch tracing read type: %u."),
12150 (unsigned int) type
);
12153 xml
= target_read_stralloc (¤t_target
,
12154 TARGET_OBJECT_BTRACE
, annex
);
12156 return BTRACE_ERR_UNKNOWN
;
12158 cleanup
= make_cleanup (xfree
, xml
);
12159 parse_xml_btrace (btrace
, xml
);
12160 do_cleanups (cleanup
);
12162 return BTRACE_ERR_NONE
;
12165 static const struct btrace_config
*
12166 remote_btrace_conf (struct target_ops
*self
,
12167 const struct btrace_target_info
*tinfo
)
12169 return &tinfo
->conf
;
12173 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12175 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12179 /* Implementation of to_load. */
12182 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12184 generic_load (name
, from_tty
);
12187 /* Accepts an integer PID; returns a string representing a file that
12188 can be opened on the remote side to get the symbols for the child
12189 process. Returns NULL if the operation is not supported. */
12192 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12194 static char *filename
= NULL
;
12195 struct inferior
*inf
;
12196 char *annex
= NULL
;
12198 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12201 if (filename
!= NULL
)
12204 inf
= find_inferior_pid (pid
);
12206 internal_error (__FILE__
, __LINE__
,
12207 _("not currently attached to process %d"), pid
);
12209 if (!inf
->fake_pid_p
)
12211 const int annex_size
= 9;
12213 annex
= alloca (annex_size
);
12214 xsnprintf (annex
, annex_size
, "%x", pid
);
12217 filename
= target_read_stralloc (¤t_target
,
12218 TARGET_OBJECT_EXEC_FILE
, annex
);
12224 init_remote_ops (void)
12226 remote_ops
.to_shortname
= "remote";
12227 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12228 remote_ops
.to_doc
=
12229 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12230 Specify the serial device it is connected to\n\
12231 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12232 remote_ops
.to_open
= remote_open
;
12233 remote_ops
.to_close
= remote_close
;
12234 remote_ops
.to_detach
= remote_detach
;
12235 remote_ops
.to_disconnect
= remote_disconnect
;
12236 remote_ops
.to_resume
= remote_resume
;
12237 remote_ops
.to_wait
= remote_wait
;
12238 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12239 remote_ops
.to_store_registers
= remote_store_registers
;
12240 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12241 remote_ops
.to_files_info
= remote_files_info
;
12242 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12243 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12244 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12245 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12246 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12247 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12248 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12249 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12250 remote_ops
.to_watchpoint_addr_within_range
=
12251 remote_watchpoint_addr_within_range
;
12252 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12253 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12254 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12255 remote_ops
.to_region_ok_for_hw_watchpoint
12256 = remote_region_ok_for_hw_watchpoint
;
12257 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12258 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12259 remote_ops
.to_kill
= remote_kill
;
12260 remote_ops
.to_load
= remote_load
;
12261 remote_ops
.to_mourn_inferior
= remote_mourn
;
12262 remote_ops
.to_pass_signals
= remote_pass_signals
;
12263 remote_ops
.to_program_signals
= remote_program_signals
;
12264 remote_ops
.to_thread_alive
= remote_thread_alive
;
12265 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12266 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12267 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12268 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12269 remote_ops
.to_stop
= remote_stop
;
12270 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12271 remote_ops
.to_rcmd
= remote_rcmd
;
12272 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12273 remote_ops
.to_log_command
= serial_log_command
;
12274 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12275 remote_ops
.to_stratum
= process_stratum
;
12276 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12277 remote_ops
.to_has_memory
= default_child_has_memory
;
12278 remote_ops
.to_has_stack
= default_child_has_stack
;
12279 remote_ops
.to_has_registers
= default_child_has_registers
;
12280 remote_ops
.to_has_execution
= default_child_has_execution
;
12281 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12282 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12283 remote_ops
.to_magic
= OPS_MAGIC
;
12284 remote_ops
.to_memory_map
= remote_memory_map
;
12285 remote_ops
.to_flash_erase
= remote_flash_erase
;
12286 remote_ops
.to_flash_done
= remote_flash_done
;
12287 remote_ops
.to_read_description
= remote_read_description
;
12288 remote_ops
.to_search_memory
= remote_search_memory
;
12289 remote_ops
.to_can_async_p
= remote_can_async_p
;
12290 remote_ops
.to_is_async_p
= remote_is_async_p
;
12291 remote_ops
.to_async
= remote_async
;
12292 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12293 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12294 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12295 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12296 remote_ops
.to_supports_disable_randomization
12297 = remote_supports_disable_randomization
;
12298 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12299 remote_ops
.to_fileio_open
= remote_hostio_open
;
12300 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12301 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12302 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12303 remote_ops
.to_fileio_close
= remote_hostio_close
;
12304 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12305 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12306 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12307 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12308 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12309 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12310 remote_ops
.to_trace_init
= remote_trace_init
;
12311 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12312 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12313 remote_ops
.to_download_trace_state_variable
12314 = remote_download_trace_state_variable
;
12315 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12316 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12317 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12318 remote_ops
.to_trace_start
= remote_trace_start
;
12319 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12320 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12321 remote_ops
.to_trace_stop
= remote_trace_stop
;
12322 remote_ops
.to_trace_find
= remote_trace_find
;
12323 remote_ops
.to_get_trace_state_variable_value
12324 = remote_get_trace_state_variable_value
;
12325 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12326 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12327 remote_ops
.to_upload_trace_state_variables
12328 = remote_upload_trace_state_variables
;
12329 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12330 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12331 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12332 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12333 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12334 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12335 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12336 remote_ops
.to_verify_memory
= remote_verify_memory
;
12337 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12338 remote_ops
.to_set_permissions
= remote_set_permissions
;
12339 remote_ops
.to_static_tracepoint_marker_at
12340 = remote_static_tracepoint_marker_at
;
12341 remote_ops
.to_static_tracepoint_markers_by_strid
12342 = remote_static_tracepoint_markers_by_strid
;
12343 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12344 remote_ops
.to_use_agent
= remote_use_agent
;
12345 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12346 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12347 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12348 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12349 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12350 remote_ops
.to_read_btrace
= remote_read_btrace
;
12351 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12352 remote_ops
.to_augmented_libraries_svr4_read
=
12353 remote_augmented_libraries_svr4_read
;
12356 /* Set up the extended remote vector by making a copy of the standard
12357 remote vector and adding to it. */
12360 init_extended_remote_ops (void)
12362 extended_remote_ops
= remote_ops
;
12364 extended_remote_ops
.to_shortname
= "extended-remote";
12365 extended_remote_ops
.to_longname
=
12366 "Extended remote serial target in gdb-specific protocol";
12367 extended_remote_ops
.to_doc
=
12368 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12369 Specify the serial device it is connected to (e.g. /dev/ttya).";
12370 extended_remote_ops
.to_open
= extended_remote_open
;
12371 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12372 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12373 extended_remote_ops
.to_detach
= extended_remote_detach
;
12374 extended_remote_ops
.to_attach
= extended_remote_attach
;
12375 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12376 extended_remote_ops
.to_kill
= extended_remote_kill
;
12377 extended_remote_ops
.to_supports_disable_randomization
12378 = extended_remote_supports_disable_randomization
;
12379 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12380 extended_remote_ops
.to_insert_fork_catchpoint
12381 = remote_insert_fork_catchpoint
;
12382 extended_remote_ops
.to_remove_fork_catchpoint
12383 = remote_remove_fork_catchpoint
;
12384 extended_remote_ops
.to_insert_vfork_catchpoint
12385 = remote_insert_vfork_catchpoint
;
12386 extended_remote_ops
.to_remove_vfork_catchpoint
12387 = remote_remove_vfork_catchpoint
;
12391 remote_can_async_p (struct target_ops
*ops
)
12393 struct remote_state
*rs
= get_remote_state ();
12395 if (!target_async_permitted
)
12396 /* We only enable async when the user specifically asks for it. */
12399 /* We're async whenever the serial device is. */
12400 return serial_can_async_p (rs
->remote_desc
);
12404 remote_is_async_p (struct target_ops
*ops
)
12406 struct remote_state
*rs
= get_remote_state ();
12408 if (!target_async_permitted
)
12409 /* We only enable async when the user specifically asks for it. */
12412 /* We're async whenever the serial device is. */
12413 return serial_is_async_p (rs
->remote_desc
);
12416 /* Pass the SERIAL event on and up to the client. One day this code
12417 will be able to delay notifying the client of an event until the
12418 point where an entire packet has been received. */
12420 static serial_event_ftype remote_async_serial_handler
;
12423 remote_async_serial_handler (struct serial
*scb
, void *context
)
12425 struct remote_state
*rs
= context
;
12427 /* Don't propogate error information up to the client. Instead let
12428 the client find out about the error by querying the target. */
12429 inferior_event_handler (INF_REG_EVENT
, NULL
);
12433 remote_async_inferior_event_handler (gdb_client_data data
)
12435 inferior_event_handler (INF_REG_EVENT
, NULL
);
12439 remote_async (struct target_ops
*ops
, int enable
)
12441 struct remote_state
*rs
= get_remote_state ();
12445 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12447 /* If there are pending events in the stop reply queue tell the
12448 event loop to process them. */
12449 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12450 mark_async_event_handler (remote_async_inferior_event_token
);
12454 serial_async (rs
->remote_desc
, NULL
, NULL
);
12455 clear_async_event_handler (remote_async_inferior_event_token
);
12460 set_remote_cmd (char *args
, int from_tty
)
12462 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12466 show_remote_cmd (char *args
, int from_tty
)
12468 /* We can't just use cmd_show_list here, because we want to skip
12469 the redundant "show remote Z-packet" and the legacy aliases. */
12470 struct cleanup
*showlist_chain
;
12471 struct cmd_list_element
*list
= remote_show_cmdlist
;
12472 struct ui_out
*uiout
= current_uiout
;
12474 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12475 for (; list
!= NULL
; list
= list
->next
)
12476 if (strcmp (list
->name
, "Z-packet") == 0)
12478 else if (list
->type
== not_set_cmd
)
12479 /* Alias commands are exactly like the original, except they
12480 don't have the normal type. */
12484 struct cleanup
*option_chain
12485 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12487 ui_out_field_string (uiout
, "name", list
->name
);
12488 ui_out_text (uiout
, ": ");
12489 if (list
->type
== show_cmd
)
12490 do_show_command ((char *) NULL
, from_tty
, list
);
12492 cmd_func (list
, NULL
, from_tty
);
12493 /* Close the tuple. */
12494 do_cleanups (option_chain
);
12497 /* Close the tuple. */
12498 do_cleanups (showlist_chain
);
12502 /* Function to be called whenever a new objfile (shlib) is detected. */
12504 remote_new_objfile (struct objfile
*objfile
)
12506 struct remote_state
*rs
= get_remote_state ();
12508 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12509 remote_check_symbols ();
12512 /* Pull all the tracepoints defined on the target and create local
12513 data structures representing them. We don't want to create real
12514 tracepoints yet, we don't want to mess up the user's existing
12518 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12520 struct remote_state
*rs
= get_remote_state ();
12523 /* Ask for a first packet of tracepoint definition. */
12525 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12527 while (*p
&& *p
!= 'l')
12529 parse_tracepoint_definition (p
, utpp
);
12530 /* Ask for another packet of tracepoint definition. */
12532 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12539 remote_upload_trace_state_variables (struct target_ops
*self
,
12540 struct uploaded_tsv
**utsvp
)
12542 struct remote_state
*rs
= get_remote_state ();
12545 /* Ask for a first packet of variable definition. */
12547 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12549 while (*p
&& *p
!= 'l')
12551 parse_tsv_definition (p
, utsvp
);
12552 /* Ask for another packet of variable definition. */
12554 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12560 /* The "set/show range-stepping" show hook. */
12563 show_range_stepping (struct ui_file
*file
, int from_tty
,
12564 struct cmd_list_element
*c
,
12567 fprintf_filtered (file
,
12568 _("Debugger's willingness to use range stepping "
12569 "is %s.\n"), value
);
12572 /* The "set/show range-stepping" set hook. */
12575 set_range_stepping (char *ignore_args
, int from_tty
,
12576 struct cmd_list_element
*c
)
12578 struct remote_state
*rs
= get_remote_state ();
12580 /* Whene enabling, check whether range stepping is actually
12581 supported by the target, and warn if not. */
12582 if (use_range_stepping
)
12584 if (rs
->remote_desc
!= NULL
)
12586 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12587 remote_vcont_probe (rs
);
12589 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12590 && rs
->supports_vCont
.r
)
12594 warning (_("Range stepping is not supported by the current target"));
12599 _initialize_remote (void)
12601 struct remote_state
*rs
;
12602 struct cmd_list_element
*cmd
;
12603 const char *cmd_name
;
12605 /* architecture specific data */
12606 remote_gdbarch_data_handle
=
12607 gdbarch_data_register_post_init (init_remote_state
);
12608 remote_g_packet_data_handle
=
12609 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12611 /* Initialize the per-target state. At the moment there is only one
12612 of these, not one per target. Only one target is active at a
12614 remote_state
= new_remote_state ();
12616 init_remote_ops ();
12617 add_target (&remote_ops
);
12619 init_extended_remote_ops ();
12620 add_target (&extended_remote_ops
);
12622 /* Hook into new objfile notification. */
12623 observer_attach_new_objfile (remote_new_objfile
);
12624 /* We're no longer interested in notification events of an inferior
12626 observer_attach_inferior_exit (discard_pending_stop_replies
);
12628 /* Set up signal handlers. */
12629 async_sigint_remote_token
=
12630 create_async_signal_handler (async_remote_interrupt
, NULL
);
12631 async_sigint_remote_twice_token
=
12632 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12635 init_remote_threadtests ();
12638 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12639 /* set/show remote ... */
12641 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12642 Remote protocol specific variables\n\
12643 Configure various remote-protocol specific variables such as\n\
12644 the packets being used"),
12645 &remote_set_cmdlist
, "set remote ",
12646 0 /* allow-unknown */, &setlist
);
12647 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12648 Remote protocol specific variables\n\
12649 Configure various remote-protocol specific variables such as\n\
12650 the packets being used"),
12651 &remote_show_cmdlist
, "show remote ",
12652 0 /* allow-unknown */, &showlist
);
12654 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12655 Compare section data on target to the exec file.\n\
12656 Argument is a single section name (default: all loaded sections).\n\
12657 To compare only read-only loaded sections, specify the -r option."),
12660 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12661 Send an arbitrary packet to a remote target.\n\
12662 maintenance packet TEXT\n\
12663 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12664 this command sends the string TEXT to the inferior, and displays the\n\
12665 response packet. GDB supplies the initial `$' character, and the\n\
12666 terminating `#' character and checksum."),
12669 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12670 Set whether to send break if interrupted."), _("\
12671 Show whether to send break if interrupted."), _("\
12672 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12673 set_remotebreak
, show_remotebreak
,
12674 &setlist
, &showlist
);
12675 cmd_name
= "remotebreak";
12676 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12677 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12678 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12679 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12680 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12682 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12683 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12685 Set interrupt sequence to remote target."), _("\
12686 Show interrupt sequence to remote target."), _("\
12687 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12688 NULL
, show_interrupt_sequence
,
12689 &remote_set_cmdlist
,
12690 &remote_show_cmdlist
);
12692 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12693 &interrupt_on_connect
, _("\
12694 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12695 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12696 If set, interrupt sequence is sent to remote target."),
12698 &remote_set_cmdlist
, &remote_show_cmdlist
);
12700 /* Install commands for configuring memory read/write packets. */
12702 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12703 Set the maximum number of bytes per memory write packet (deprecated)."),
12705 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12706 Show the maximum number of bytes per memory write packet (deprecated)."),
12708 add_cmd ("memory-write-packet-size", no_class
,
12709 set_memory_write_packet_size
, _("\
12710 Set the maximum number of bytes per memory-write packet.\n\
12711 Specify the number of bytes in a packet or 0 (zero) for the\n\
12712 default packet size. The actual limit is further reduced\n\
12713 dependent on the target. Specify ``fixed'' to disable the\n\
12714 further restriction and ``limit'' to enable that restriction."),
12715 &remote_set_cmdlist
);
12716 add_cmd ("memory-read-packet-size", no_class
,
12717 set_memory_read_packet_size
, _("\
12718 Set the maximum number of bytes per memory-read packet.\n\
12719 Specify the number of bytes in a packet or 0 (zero) for the\n\
12720 default packet size. The actual limit is further reduced\n\
12721 dependent on the target. Specify ``fixed'' to disable the\n\
12722 further restriction and ``limit'' to enable that restriction."),
12723 &remote_set_cmdlist
);
12724 add_cmd ("memory-write-packet-size", no_class
,
12725 show_memory_write_packet_size
,
12726 _("Show the maximum number of bytes per memory-write packet."),
12727 &remote_show_cmdlist
);
12728 add_cmd ("memory-read-packet-size", no_class
,
12729 show_memory_read_packet_size
,
12730 _("Show the maximum number of bytes per memory-read packet."),
12731 &remote_show_cmdlist
);
12733 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12734 &remote_hw_watchpoint_limit
, _("\
12735 Set the maximum number of target hardware watchpoints."), _("\
12736 Show the maximum number of target hardware watchpoints."), _("\
12737 Specify a negative limit for unlimited."),
12738 NULL
, NULL
, /* FIXME: i18n: The maximum
12739 number of target hardware
12740 watchpoints is %s. */
12741 &remote_set_cmdlist
, &remote_show_cmdlist
);
12742 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12743 &remote_hw_watchpoint_length_limit
, _("\
12744 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12745 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12746 Specify a negative limit for unlimited."),
12747 NULL
, NULL
, /* FIXME: i18n: The maximum
12748 length (in bytes) of a target
12749 hardware watchpoint is %s. */
12750 &remote_set_cmdlist
, &remote_show_cmdlist
);
12751 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12752 &remote_hw_breakpoint_limit
, _("\
12753 Set the maximum number of target hardware breakpoints."), _("\
12754 Show the maximum number of target hardware breakpoints."), _("\
12755 Specify a negative limit for unlimited."),
12756 NULL
, NULL
, /* FIXME: i18n: The maximum
12757 number of target hardware
12758 breakpoints is %s. */
12759 &remote_set_cmdlist
, &remote_show_cmdlist
);
12761 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12762 &remote_address_size
, _("\
12763 Set the maximum size of the address (in bits) in a memory packet."), _("\
12764 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12766 NULL
, /* FIXME: i18n: */
12767 &setlist
, &showlist
);
12769 init_all_packet_configs ();
12771 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12772 "X", "binary-download", 1);
12774 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12775 "vCont", "verbose-resume", 0);
12777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12778 "QPassSignals", "pass-signals", 0);
12780 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12781 "QProgramSignals", "program-signals", 0);
12783 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12784 "qSymbol", "symbol-lookup", 0);
12786 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12787 "P", "set-register", 1);
12789 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12790 "p", "fetch-register", 1);
12792 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12793 "Z0", "software-breakpoint", 0);
12795 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12796 "Z1", "hardware-breakpoint", 0);
12798 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12799 "Z2", "write-watchpoint", 0);
12801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12802 "Z3", "read-watchpoint", 0);
12804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12805 "Z4", "access-watchpoint", 0);
12807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12808 "qXfer:auxv:read", "read-aux-vector", 0);
12810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
12811 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12813 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12814 "qXfer:features:read", "target-features", 0);
12816 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12817 "qXfer:libraries:read", "library-info", 0);
12819 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12820 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12823 "qXfer:memory-map:read", "memory-map", 0);
12825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12826 "qXfer:spu:read", "read-spu-object", 0);
12828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12829 "qXfer:spu:write", "write-spu-object", 0);
12831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12832 "qXfer:osdata:read", "osdata", 0);
12834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12835 "qXfer:threads:read", "threads", 0);
12837 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12838 "qXfer:siginfo:read", "read-siginfo-object", 0);
12840 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12841 "qXfer:siginfo:write", "write-siginfo-object", 0);
12843 add_packet_config_cmd
12844 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12845 "qXfer:traceframe-info:read", "traceframe-info", 0);
12847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12848 "qXfer:uib:read", "unwind-info-block", 0);
12850 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12851 "qGetTLSAddr", "get-thread-local-storage-address",
12854 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12855 "qGetTIBAddr", "get-thread-information-block-address",
12858 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12859 "bc", "reverse-continue", 0);
12861 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12862 "bs", "reverse-step", 0);
12864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12865 "qSupported", "supported-packets", 0);
12867 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12868 "qSearch:memory", "search-memory", 0);
12870 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12871 "qTStatus", "trace-status", 0);
12873 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
12874 "vFile:setfs", "hostio-setfs", 0);
12876 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12877 "vFile:open", "hostio-open", 0);
12879 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12880 "vFile:pread", "hostio-pread", 0);
12882 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12883 "vFile:pwrite", "hostio-pwrite", 0);
12885 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12886 "vFile:close", "hostio-close", 0);
12888 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12889 "vFile:unlink", "hostio-unlink", 0);
12891 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12892 "vFile:readlink", "hostio-readlink", 0);
12894 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
12895 "vFile:fstat", "hostio-fstat", 0);
12897 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12898 "vAttach", "attach", 0);
12900 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12903 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12904 "QStartNoAckMode", "noack", 0);
12906 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12907 "vKill", "kill", 0);
12909 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12910 "qAttached", "query-attached", 0);
12912 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12913 "ConditionalTracepoints",
12914 "conditional-tracepoints", 0);
12916 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12917 "ConditionalBreakpoints",
12918 "conditional-breakpoints", 0);
12920 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12921 "BreakpointCommands",
12922 "breakpoint-commands", 0);
12924 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12925 "FastTracepoints", "fast-tracepoints", 0);
12927 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12928 "TracepointSource", "TracepointSource", 0);
12930 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12931 "QAllow", "allow", 0);
12933 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12934 "StaticTracepoints", "static-tracepoints", 0);
12936 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12937 "InstallInTrace", "install-in-trace", 0);
12939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12940 "qXfer:statictrace:read", "read-sdata-object", 0);
12942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12943 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12946 "QDisableRandomization", "disable-randomization", 0);
12948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12949 "QAgent", "agent", 0);
12951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12952 "QTBuffer:size", "trace-buffer-size", 0);
12954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12955 "Qbtrace:off", "disable-btrace", 0);
12957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12958 "Qbtrace:bts", "enable-btrace-bts", 0);
12960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
12961 "Qbtrace:pt", "enable-btrace-pt", 0);
12963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12964 "qXfer:btrace", "read-btrace", 0);
12966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
12967 "qXfer:btrace-conf", "read-btrace-conf", 0);
12969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
12970 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
12972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
12973 "swbreak-feature", "swbreak-feature", 0);
12975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
12976 "hwbreak-feature", "hwbreak-feature", 0);
12978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
12979 "fork-event-feature", "fork-event-feature", 0);
12981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
12982 "vfork-event-feature", "vfork-event-feature", 0);
12984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
12985 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
12987 /* Assert that we've registered "set remote foo-packet" commands
12988 for all packet configs. */
12992 for (i
= 0; i
< PACKET_MAX
; i
++)
12994 /* Ideally all configs would have a command associated. Some
12995 still don't though. */
13000 case PACKET_QNonStop
:
13001 case PACKET_multiprocess_feature
:
13002 case PACKET_EnableDisableTracepoints_feature
:
13003 case PACKET_tracenz_feature
:
13004 case PACKET_DisconnectedTracing_feature
:
13005 case PACKET_augmented_libraries_svr4_read_feature
:
13007 /* Additions to this list need to be well justified:
13008 pre-existing packets are OK; new packets are not. */
13016 /* This catches both forgetting to add a config command, and
13017 forgetting to remove a packet from the exception list. */
13018 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13022 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13023 Z sub-packet has its own set and show commands, but users may
13024 have sets to this variable in their .gdbinit files (or in their
13026 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13027 &remote_Z_packet_detect
, _("\
13028 Set use of remote protocol `Z' packets"), _("\
13029 Show use of remote protocol `Z' packets "), _("\
13030 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13032 set_remote_protocol_Z_packet_cmd
,
13033 show_remote_protocol_Z_packet_cmd
,
13034 /* FIXME: i18n: Use of remote protocol
13035 `Z' packets is %s. */
13036 &remote_set_cmdlist
, &remote_show_cmdlist
);
13038 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13039 Manipulate files on the remote system\n\
13040 Transfer files to and from the remote target system."),
13041 &remote_cmdlist
, "remote ",
13042 0 /* allow-unknown */, &cmdlist
);
13044 add_cmd ("put", class_files
, remote_put_command
,
13045 _("Copy a local file to the remote system."),
13048 add_cmd ("get", class_files
, remote_get_command
,
13049 _("Copy a remote file to the local system."),
13052 add_cmd ("delete", class_files
, remote_delete_command
,
13053 _("Delete a remote file."),
13056 remote_exec_file
= xstrdup ("");
13057 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13058 &remote_exec_file
, _("\
13059 Set the remote pathname for \"run\""), _("\
13060 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
13061 &remote_set_cmdlist
, &remote_show_cmdlist
);
13063 add_setshow_boolean_cmd ("range-stepping", class_run
,
13064 &use_range_stepping
, _("\
13065 Enable or disable range stepping."), _("\
13066 Show whether target-assisted range stepping is enabled."), _("\
13067 If on, and the target supports it, when stepping a source line, GDB\n\
13068 tells the target to step the corresponding range of addresses itself instead\n\
13069 of issuing multiple single-steps. This speeds up source level\n\
13070 stepping. If off, GDB always issues single-steps, even if range\n\
13071 stepping is supported by the target. The default is on."),
13072 set_range_stepping
,
13073 show_range_stepping
,
13077 /* Eventually initialize fileio. See fileio.c */
13078 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13080 /* Take advantage of the fact that the TID field is not used, to tag
13081 special ptids with it set to != 0. */
13082 magic_null_ptid
= ptid_build (42000, -1, 1);
13083 not_sent_ptid
= ptid_build (42000, -2, 1);
13084 any_thread_ptid
= ptid_build (42000, 0, 1);
13086 target_buf_size
= 2048;
13087 target_buf
= xmalloc (target_buf_size
);