1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
31 #include "exceptions.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-setshow.h"
46 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
71 /* Temp hacks for tracepoint encoding migration. */
72 static char *target_buf
;
73 static long target_buf_size
;
75 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
76 char ***tdp_actions
, char ***stepping_actions
);
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void cleanup_sigint_signal_handler (void *dummy
);
92 static void initialize_sigint_signal_handler (void);
93 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
94 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
97 static void handle_remote_sigint (int);
98 static void handle_remote_sigint_twice (int);
99 static void async_remote_interrupt (gdb_client_data
);
100 void async_remote_interrupt_twice (gdb_client_data
);
102 static void remote_files_info (struct target_ops
*ignore
);
104 static void remote_prepare_to_store (struct regcache
*regcache
);
106 static void remote_open (char *name
, int from_tty
);
108 static void extended_remote_open (char *name
, int from_tty
);
110 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
112 static void remote_close (int quitting
);
114 static void remote_mourn (struct target_ops
*ops
);
116 static void extended_remote_restart (void);
118 static void extended_remote_mourn (struct target_ops
*);
120 static void remote_mourn_1 (struct target_ops
*);
122 static void remote_send (char **buf
, long *sizeof_buf_p
);
124 static int readchar (int timeout
);
126 static void remote_kill (struct target_ops
*ops
);
128 static int tohex (int nib
);
130 static int remote_can_async_p (void);
132 static int remote_is_async_p (void);
134 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
135 void *context
), void *context
);
137 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
139 static void remote_interrupt (int signo
);
141 static void remote_interrupt_twice (int signo
);
143 static void interrupt_query (void);
145 static void set_general_thread (struct ptid ptid
);
146 static void set_continue_thread (struct ptid ptid
);
148 static void get_offsets (void);
150 static void skip_frame (void);
152 static long read_frame (char **buf_p
, long *sizeof_buf
);
154 static int hexnumlen (ULONGEST num
);
156 static void init_remote_ops (void);
158 static void init_extended_remote_ops (void);
160 static void remote_stop (ptid_t
);
162 static int ishex (int ch
, int *val
);
164 static int stubhex (int ch
);
166 static int hexnumstr (char *, ULONGEST
);
168 static int hexnumnstr (char *, ULONGEST
, int);
170 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
172 static void print_packet (char *);
174 static void compare_sections_command (char *, int);
176 static void packet_command (char *, int);
178 static int stub_unpack_int (char *buff
, int fieldlength
);
180 static ptid_t
remote_current_thread (ptid_t oldptid
);
182 static void remote_find_new_threads (void);
184 static void record_currthread (ptid_t currthread
);
186 static int fromhex (int a
);
188 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
190 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
192 static int putpkt_binary (char *buf
, int cnt
);
194 static void check_binary_download (CORE_ADDR addr
);
196 struct packet_config
;
198 static void show_packet_config_cmd (struct packet_config
*config
);
200 static void update_packet_config (struct packet_config
*config
);
202 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
203 struct cmd_list_element
*c
);
205 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
207 struct cmd_list_element
*c
,
210 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
211 static ptid_t
read_ptid (char *buf
, char **obuf
);
213 static void remote_set_permissions (void);
216 static int remote_get_trace_status (struct trace_status
*ts
);
218 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
220 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
222 static void remote_query_supported (void);
224 static void remote_check_symbols (struct objfile
*objfile
);
226 void _initialize_remote (void);
229 static struct stop_reply
*stop_reply_xmalloc (void);
230 static void stop_reply_xfree (struct stop_reply
*);
231 static void do_stop_reply_xfree (void *arg
);
232 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
233 static void push_stop_reply (struct stop_reply
*);
234 static void remote_get_pending_stop_replies (void);
235 static void discard_pending_stop_replies (int pid
);
236 static int peek_stop_reply (ptid_t ptid
);
238 static void remote_async_inferior_event_handler (gdb_client_data
);
239 static void remote_async_get_pending_events_handler (gdb_client_data
);
241 static void remote_terminal_ours (void);
243 static int remote_read_description_p (struct target_ops
*target
);
245 static void remote_console_output (char *msg
);
247 /* The non-stop remote protocol provisions for one pending stop reply.
248 This is where we keep it until it is acknowledged. */
250 static struct stop_reply
*pending_stop_reply
= NULL
;
254 static struct cmd_list_element
*remote_cmdlist
;
256 /* For "set remote" and "show remote". */
258 static struct cmd_list_element
*remote_set_cmdlist
;
259 static struct cmd_list_element
*remote_show_cmdlist
;
261 /* Description of the remote protocol state for the currently
262 connected target. This is per-target state, and independent of the
263 selected architecture. */
267 /* A buffer to use for incoming packets, and its current size. The
268 buffer is grown dynamically for larger incoming packets.
269 Outgoing packets may also be constructed in this buffer.
270 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
271 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
276 /* If we negotiated packet size explicitly (and thus can bypass
277 heuristics for the largest packet size that will not overflow
278 a buffer in the stub), this will be set to that packet size.
279 Otherwise zero, meaning to use the guessed size. */
280 long explicit_packet_size
;
282 /* remote_wait is normally called when the target is running and
283 waits for a stop reply packet. But sometimes we need to call it
284 when the target is already stopped. We can send a "?" packet
285 and have remote_wait read the response. Or, if we already have
286 the response, we can stash it in BUF and tell remote_wait to
287 skip calling getpkt. This flag is set when BUF contains a
288 stop reply packet and the target is not waiting. */
289 int cached_wait_status
;
291 /* True, if in no ack mode. That is, neither GDB nor the stub will
292 expect acks from each other. The connection is assumed to be
296 /* True if we're connected in extended remote mode. */
299 /* True if the stub reported support for multi-process
301 int multi_process_aware
;
303 /* True if we resumed the target and we're waiting for the target to
304 stop. In the mean time, we can't start another command/query.
305 The remote server wouldn't be ready to process it, so we'd
306 timeout waiting for a reply that would never come and eventually
307 we'd close the connection. This can happen in asynchronous mode
308 because we allow GDB commands while the target is running. */
309 int waiting_for_stop_reply
;
311 /* True if the stub reports support for non-stop mode. */
314 /* True if the stub reports support for vCont;t. */
317 /* True if the stub reports support for conditional tracepoints. */
318 int cond_tracepoints
;
320 /* True if the stub reports support for fast tracepoints. */
321 int fast_tracepoints
;
323 /* True if the stub reports support for static tracepoints. */
324 int static_tracepoints
;
326 /* True if the stub reports support for installing tracepoint while
328 int install_in_trace
;
330 /* True if the stub can continue running a trace while GDB is
332 int disconnected_tracing
;
334 /* True if the stub reports support for enabling and disabling
335 tracepoints while a trace experiment is running. */
336 int enable_disable_tracepoints
;
338 /* True if the stub can collect strings using tracenz bytecode. */
341 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
342 responded to that. */
346 /* Private data that we'll store in (struct thread_info)->private. */
347 struct private_thread_info
354 free_private_thread_info (struct private_thread_info
*info
)
360 /* Returns true if the multi-process extensions are in effect. */
362 remote_multi_process_p (struct remote_state
*rs
)
364 return rs
->extended
&& rs
->multi_process_aware
;
367 /* This data could be associated with a target, but we do not always
368 have access to the current target when we need it, so for now it is
369 static. This will be fine for as long as only one target is in use
371 static struct remote_state remote_state
;
373 static struct remote_state
*
374 get_remote_state_raw (void)
376 return &remote_state
;
379 /* Description of the remote protocol for a given architecture. */
383 long offset
; /* Offset into G packet. */
384 long regnum
; /* GDB's internal register number. */
385 LONGEST pnum
; /* Remote protocol register number. */
386 int in_g_packet
; /* Always part of G packet. */
387 /* long size in bytes; == register_size (target_gdbarch, regnum);
389 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
393 struct remote_arch_state
395 /* Description of the remote protocol registers. */
396 long sizeof_g_packet
;
398 /* Description of the remote protocol registers indexed by REGNUM
399 (making an array gdbarch_num_regs in size). */
400 struct packet_reg
*regs
;
402 /* This is the size (in chars) of the first response to the ``g''
403 packet. It is used as a heuristic when determining the maximum
404 size of memory-read and memory-write packets. A target will
405 typically only reserve a buffer large enough to hold the ``g''
406 packet. The size does not include packet overhead (headers and
408 long actual_register_packet_size
;
410 /* This is the maximum size (in chars) of a non read/write packet.
411 It is also used as a cap on the size of read/write packets. */
412 long remote_packet_size
;
415 long sizeof_pkt
= 2000;
417 /* Utility: generate error from an incoming stub packet. */
419 trace_error (char *buf
)
422 return; /* not an error msg */
425 case '1': /* malformed packet error */
426 if (*++buf
== '0') /* general case: */
427 error (_("remote.c: error in outgoing packet."));
429 error (_("remote.c: error in outgoing packet at field #%ld."),
430 strtol (buf
, NULL
, 16));
432 error (_("trace API error 0x%s."), ++buf
);
434 error (_("Target returns error code '%s'."), buf
);
438 /* Utility: wait for reply from stub, while accepting "O" packets. */
440 remote_get_noisy_reply (char **buf_p
,
443 do /* Loop on reply from remote stub. */
447 QUIT
; /* Allow user to bail out with ^C. */
448 getpkt (buf_p
, sizeof_buf
, 0);
452 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
455 CORE_ADDR from
, to
, org_to
;
457 int adjusted_size
= 0;
458 volatile struct gdb_exception ex
;
460 p
= buf
+ strlen ("qRelocInsn:");
461 pp
= unpack_varlen_hex (p
, &ul
);
463 error (_("invalid qRelocInsn packet: %s"), buf
);
467 unpack_varlen_hex (p
, &ul
);
472 TRY_CATCH (ex
, RETURN_MASK_ALL
)
474 gdbarch_relocate_instruction (target_gdbarch
, &to
, from
);
478 adjusted_size
= to
- org_to
;
480 sprintf (buf
, "qRelocInsn:%x", adjusted_size
);
483 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
485 /* Propagate memory errors silently back to the target.
486 The stub may have limited the range of addresses we
487 can write to, for example. */
492 /* Something unexpectedly bad happened. Be verbose so
493 we can tell what, and propagate the error back to the
494 stub, so it doesn't get stuck waiting for a
496 exception_fprintf (gdb_stderr
, ex
,
497 _("warning: relocating instruction: "));
501 else if (buf
[0] == 'O' && buf
[1] != 'K')
502 remote_console_output (buf
+ 1); /* 'O' message from stub */
504 return buf
; /* Here's the actual reply. */
509 /* Handle for retreving the remote protocol data from gdbarch. */
510 static struct gdbarch_data
*remote_gdbarch_data_handle
;
512 static struct remote_arch_state
*
513 get_remote_arch_state (void)
515 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
518 /* Fetch the global remote target state. */
520 static struct remote_state
*
521 get_remote_state (void)
523 /* Make sure that the remote architecture state has been
524 initialized, because doing so might reallocate rs->buf. Any
525 function which calls getpkt also needs to be mindful of changes
526 to rs->buf, but this call limits the number of places which run
528 get_remote_arch_state ();
530 return get_remote_state_raw ();
534 compare_pnums (const void *lhs_
, const void *rhs_
)
536 const struct packet_reg
* const *lhs
= lhs_
;
537 const struct packet_reg
* const *rhs
= rhs_
;
539 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
541 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
548 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
550 int regnum
, num_remote_regs
, offset
;
551 struct packet_reg
**remote_regs
;
553 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
555 struct packet_reg
*r
= ®s
[regnum
];
557 if (register_size (gdbarch
, regnum
) == 0)
558 /* Do not try to fetch zero-sized (placeholder) registers. */
561 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
566 /* Define the g/G packet format as the contents of each register
567 with a remote protocol number, in order of ascending protocol
570 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
571 * sizeof (struct packet_reg
*));
572 for (num_remote_regs
= 0, regnum
= 0;
573 regnum
< gdbarch_num_regs (gdbarch
);
575 if (regs
[regnum
].pnum
!= -1)
576 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
578 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
581 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
583 remote_regs
[regnum
]->in_g_packet
= 1;
584 remote_regs
[regnum
]->offset
= offset
;
585 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
591 /* Given the architecture described by GDBARCH, return the remote
592 protocol register's number and the register's offset in the g/G
593 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
594 If the target does not have a mapping for REGNUM, return false,
595 otherwise, return true. */
598 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
599 int *pnum
, int *poffset
)
602 struct packet_reg
*regs
;
603 struct cleanup
*old_chain
;
605 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
607 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
608 old_chain
= make_cleanup (xfree
, regs
);
610 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
612 *pnum
= regs
[regnum
].pnum
;
613 *poffset
= regs
[regnum
].offset
;
615 do_cleanups (old_chain
);
621 init_remote_state (struct gdbarch
*gdbarch
)
623 struct remote_state
*rs
= get_remote_state_raw ();
624 struct remote_arch_state
*rsa
;
626 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
628 /* Use the architecture to build a regnum<->pnum table, which will be
629 1:1 unless a feature set specifies otherwise. */
630 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
631 gdbarch_num_regs (gdbarch
),
634 /* Record the maximum possible size of the g packet - it may turn out
636 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
638 /* Default maximum number of characters in a packet body. Many
639 remote stubs have a hardwired buffer size of 400 bytes
640 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
641 as the maximum packet-size to ensure that the packet and an extra
642 NUL character can always fit in the buffer. This stops GDB
643 trashing stubs that try to squeeze an extra NUL into what is
644 already a full buffer (As of 1999-12-04 that was most stubs). */
645 rsa
->remote_packet_size
= 400 - 1;
647 /* This one is filled in when a ``g'' packet is received. */
648 rsa
->actual_register_packet_size
= 0;
650 /* Should rsa->sizeof_g_packet needs more space than the
651 default, adjust the size accordingly. Remember that each byte is
652 encoded as two characters. 32 is the overhead for the packet
653 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
654 (``$NN:G...#NN'') is a better guess, the below has been padded a
656 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
657 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
659 /* Make sure that the packet buffer is plenty big enough for
660 this architecture. */
661 if (rs
->buf_size
< rsa
->remote_packet_size
)
663 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
664 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
670 /* Return the current allowed size of a remote packet. This is
671 inferred from the current architecture, and should be used to
672 limit the length of outgoing packets. */
674 get_remote_packet_size (void)
676 struct remote_state
*rs
= get_remote_state ();
677 struct remote_arch_state
*rsa
= get_remote_arch_state ();
679 if (rs
->explicit_packet_size
)
680 return rs
->explicit_packet_size
;
682 return rsa
->remote_packet_size
;
685 static struct packet_reg
*
686 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
688 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
692 struct packet_reg
*r
= &rsa
->regs
[regnum
];
694 gdb_assert (r
->regnum
== regnum
);
699 static struct packet_reg
*
700 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
704 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
706 struct packet_reg
*r
= &rsa
->regs
[i
];
714 /* FIXME: graces/2002-08-08: These variables should eventually be
715 bound to an instance of the target object (as in gdbarch-tdep()),
716 when such a thing exists. */
718 /* This is set to the data address of the access causing the target
719 to stop for a watchpoint. */
720 static CORE_ADDR remote_watch_data_address
;
722 /* This is non-zero if target stopped for a watchpoint. */
723 static int remote_stopped_by_watchpoint_p
;
725 static struct target_ops remote_ops
;
727 static struct target_ops extended_remote_ops
;
729 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
730 ``forever'' still use the normal timeout mechanism. This is
731 currently used by the ASYNC code to guarentee that target reads
732 during the initial connect always time-out. Once getpkt has been
733 modified to return a timeout indication and, in turn
734 remote_wait()/wait_for_inferior() have gained a timeout parameter
736 static int wait_forever_enabled_p
= 1;
738 /* Allow the user to specify what sequence to send to the remote
739 when he requests a program interruption: Although ^C is usually
740 what remote systems expect (this is the default, here), it is
741 sometimes preferable to send a break. On other systems such
742 as the Linux kernel, a break followed by g, which is Magic SysRq g
743 is required in order to interrupt the execution. */
744 const char interrupt_sequence_control_c
[] = "Ctrl-C";
745 const char interrupt_sequence_break
[] = "BREAK";
746 const char interrupt_sequence_break_g
[] = "BREAK-g";
747 static const char *interrupt_sequence_modes
[] =
749 interrupt_sequence_control_c
,
750 interrupt_sequence_break
,
751 interrupt_sequence_break_g
,
754 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
757 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
758 struct cmd_list_element
*c
,
761 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
762 fprintf_filtered (file
,
763 _("Send the ASCII ETX character (Ctrl-c) "
764 "to the remote target to interrupt the "
765 "execution of the program.\n"));
766 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
767 fprintf_filtered (file
,
768 _("send a break signal to the remote target "
769 "to interrupt the execution of the program.\n"));
770 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
771 fprintf_filtered (file
,
772 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
773 "the remote target to interrupt the execution "
774 "of Linux kernel.\n"));
776 internal_error (__FILE__
, __LINE__
,
777 _("Invalid value for interrupt_sequence_mode: %s."),
778 interrupt_sequence_mode
);
781 /* This boolean variable specifies whether interrupt_sequence is sent
782 to the remote target when gdb connects to it.
783 This is mostly needed when you debug the Linux kernel: The Linux kernel
784 expects BREAK g which is Magic SysRq g for connecting gdb. */
785 static int interrupt_on_connect
= 0;
787 /* This variable is used to implement the "set/show remotebreak" commands.
788 Since these commands are now deprecated in favor of "set/show remote
789 interrupt-sequence", it no longer has any effect on the code. */
790 static int remote_break
;
793 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
796 interrupt_sequence_mode
= interrupt_sequence_break
;
798 interrupt_sequence_mode
= interrupt_sequence_control_c
;
802 show_remotebreak (struct ui_file
*file
, int from_tty
,
803 struct cmd_list_element
*c
,
808 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
809 remote_open knows that we don't have a file open when the program
811 static struct serial
*remote_desc
= NULL
;
813 /* This variable sets the number of bits in an address that are to be
814 sent in a memory ("M" or "m") packet. Normally, after stripping
815 leading zeros, the entire address would be sent. This variable
816 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
817 initial implementation of remote.c restricted the address sent in
818 memory packets to ``host::sizeof long'' bytes - (typically 32
819 bits). Consequently, for 64 bit targets, the upper 32 bits of an
820 address was never sent. Since fixing this bug may cause a break in
821 some remote targets this variable is principly provided to
822 facilitate backward compatibility. */
824 static int remote_address_size
;
826 /* Temporary to track who currently owns the terminal. See
827 remote_terminal_* for more details. */
829 static int remote_async_terminal_ours_p
;
831 /* The executable file to use for "run" on the remote side. */
833 static char *remote_exec_file
= "";
836 /* User configurable variables for the number of characters in a
837 memory read/write packet. MIN (rsa->remote_packet_size,
838 rsa->sizeof_g_packet) is the default. Some targets need smaller
839 values (fifo overruns, et.al.) and some users need larger values
840 (speed up transfers). The variables ``preferred_*'' (the user
841 request), ``current_*'' (what was actually set) and ``forced_*''
842 (Positive - a soft limit, negative - a hard limit). */
844 struct memory_packet_config
851 /* Compute the current size of a read/write packet. Since this makes
852 use of ``actual_register_packet_size'' the computation is dynamic. */
855 get_memory_packet_size (struct memory_packet_config
*config
)
857 struct remote_state
*rs
= get_remote_state ();
858 struct remote_arch_state
*rsa
= get_remote_arch_state ();
860 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
861 law?) that some hosts don't cope very well with large alloca()
862 calls. Eventually the alloca() code will be replaced by calls to
863 xmalloc() and make_cleanups() allowing this restriction to either
864 be lifted or removed. */
865 #ifndef MAX_REMOTE_PACKET_SIZE
866 #define MAX_REMOTE_PACKET_SIZE 16384
868 /* NOTE: 20 ensures we can write at least one byte. */
869 #ifndef MIN_REMOTE_PACKET_SIZE
870 #define MIN_REMOTE_PACKET_SIZE 20
875 if (config
->size
<= 0)
876 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
878 what_they_get
= config
->size
;
882 what_they_get
= get_remote_packet_size ();
883 /* Limit the packet to the size specified by the user. */
885 && what_they_get
> config
->size
)
886 what_they_get
= config
->size
;
888 /* Limit it to the size of the targets ``g'' response unless we have
889 permission from the stub to use a larger packet size. */
890 if (rs
->explicit_packet_size
== 0
891 && rsa
->actual_register_packet_size
> 0
892 && what_they_get
> rsa
->actual_register_packet_size
)
893 what_they_get
= rsa
->actual_register_packet_size
;
895 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
896 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
897 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
898 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
900 /* Make sure there is room in the global buffer for this packet
901 (including its trailing NUL byte). */
902 if (rs
->buf_size
< what_they_get
+ 1)
904 rs
->buf_size
= 2 * what_they_get
;
905 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
908 return what_they_get
;
911 /* Update the size of a read/write packet. If they user wants
912 something really big then do a sanity check. */
915 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
917 int fixed_p
= config
->fixed_p
;
918 long size
= config
->size
;
921 error (_("Argument required (integer, `fixed' or `limited')."));
922 else if (strcmp (args
, "hard") == 0
923 || strcmp (args
, "fixed") == 0)
925 else if (strcmp (args
, "soft") == 0
926 || strcmp (args
, "limit") == 0)
932 size
= strtoul (args
, &end
, 0);
934 error (_("Invalid %s (bad syntax)."), config
->name
);
936 /* Instead of explicitly capping the size of a packet to
937 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
938 instead allowed to set the size to something arbitrarily
940 if (size
> MAX_REMOTE_PACKET_SIZE
)
941 error (_("Invalid %s (too large)."), config
->name
);
945 if (fixed_p
&& !config
->fixed_p
)
947 if (! query (_("The target may not be able to correctly handle a %s\n"
948 "of %ld bytes. Change the packet size? "),
950 error (_("Packet size not changed."));
952 /* Update the config. */
953 config
->fixed_p
= fixed_p
;
958 show_memory_packet_size (struct memory_packet_config
*config
)
960 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
962 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
963 get_memory_packet_size (config
));
965 printf_filtered (_("Packets are limited to %ld bytes.\n"),
966 get_memory_packet_size (config
));
969 static struct memory_packet_config memory_write_packet_config
=
971 "memory-write-packet-size",
975 set_memory_write_packet_size (char *args
, int from_tty
)
977 set_memory_packet_size (args
, &memory_write_packet_config
);
981 show_memory_write_packet_size (char *args
, int from_tty
)
983 show_memory_packet_size (&memory_write_packet_config
);
987 get_memory_write_packet_size (void)
989 return get_memory_packet_size (&memory_write_packet_config
);
992 static struct memory_packet_config memory_read_packet_config
=
994 "memory-read-packet-size",
998 set_memory_read_packet_size (char *args
, int from_tty
)
1000 set_memory_packet_size (args
, &memory_read_packet_config
);
1004 show_memory_read_packet_size (char *args
, int from_tty
)
1006 show_memory_packet_size (&memory_read_packet_config
);
1010 get_memory_read_packet_size (void)
1012 long size
= get_memory_packet_size (&memory_read_packet_config
);
1014 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1015 extra buffer size argument before the memory read size can be
1016 increased beyond this. */
1017 if (size
> get_remote_packet_size ())
1018 size
= get_remote_packet_size ();
1023 /* Generic configuration support for packets the stub optionally
1024 supports. Allows the user to specify the use of the packet as well
1025 as allowing GDB to auto-detect support in the remote stub. */
1029 PACKET_SUPPORT_UNKNOWN
= 0,
1034 struct packet_config
1038 enum auto_boolean detect
;
1039 enum packet_support support
;
1042 /* Analyze a packet's return value and update the packet config
1053 update_packet_config (struct packet_config
*config
)
1055 switch (config
->detect
)
1057 case AUTO_BOOLEAN_TRUE
:
1058 config
->support
= PACKET_ENABLE
;
1060 case AUTO_BOOLEAN_FALSE
:
1061 config
->support
= PACKET_DISABLE
;
1063 case AUTO_BOOLEAN_AUTO
:
1064 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1070 show_packet_config_cmd (struct packet_config
*config
)
1072 char *support
= "internal-error";
1074 switch (config
->support
)
1077 support
= "enabled";
1079 case PACKET_DISABLE
:
1080 support
= "disabled";
1082 case PACKET_SUPPORT_UNKNOWN
:
1083 support
= "unknown";
1086 switch (config
->detect
)
1088 case AUTO_BOOLEAN_AUTO
:
1089 printf_filtered (_("Support for the `%s' packet "
1090 "is auto-detected, currently %s.\n"),
1091 config
->name
, support
);
1093 case AUTO_BOOLEAN_TRUE
:
1094 case AUTO_BOOLEAN_FALSE
:
1095 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1096 config
->name
, support
);
1102 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1103 const char *title
, int legacy
)
1109 config
->name
= name
;
1110 config
->title
= title
;
1111 config
->detect
= AUTO_BOOLEAN_AUTO
;
1112 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1113 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1115 show_doc
= xstrprintf ("Show current use of remote "
1116 "protocol `%s' (%s) packet",
1118 /* set/show TITLE-packet {auto,on,off} */
1119 cmd_name
= xstrprintf ("%s-packet", title
);
1120 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1121 &config
->detect
, set_doc
,
1122 show_doc
, NULL
, /* help_doc */
1123 set_remote_protocol_packet_cmd
,
1124 show_remote_protocol_packet_cmd
,
1125 &remote_set_cmdlist
, &remote_show_cmdlist
);
1126 /* The command code copies the documentation strings. */
1129 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1134 legacy_name
= xstrprintf ("%s-packet", name
);
1135 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1136 &remote_set_cmdlist
);
1137 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1138 &remote_show_cmdlist
);
1142 static enum packet_result
1143 packet_check_result (const char *buf
)
1147 /* The stub recognized the packet request. Check that the
1148 operation succeeded. */
1150 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1152 /* "Enn" - definitly an error. */
1153 return PACKET_ERROR
;
1155 /* Always treat "E." as an error. This will be used for
1156 more verbose error messages, such as E.memtypes. */
1157 if (buf
[0] == 'E' && buf
[1] == '.')
1158 return PACKET_ERROR
;
1160 /* The packet may or may not be OK. Just assume it is. */
1164 /* The stub does not support the packet. */
1165 return PACKET_UNKNOWN
;
1168 static enum packet_result
1169 packet_ok (const char *buf
, struct packet_config
*config
)
1171 enum packet_result result
;
1173 result
= packet_check_result (buf
);
1178 /* The stub recognized the packet request. */
1179 switch (config
->support
)
1181 case PACKET_SUPPORT_UNKNOWN
:
1183 fprintf_unfiltered (gdb_stdlog
,
1184 "Packet %s (%s) is supported\n",
1185 config
->name
, config
->title
);
1186 config
->support
= PACKET_ENABLE
;
1188 case PACKET_DISABLE
:
1189 internal_error (__FILE__
, __LINE__
,
1190 _("packet_ok: attempt to use a disabled packet"));
1196 case PACKET_UNKNOWN
:
1197 /* The stub does not support the packet. */
1198 switch (config
->support
)
1201 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1202 /* If the stub previously indicated that the packet was
1203 supported then there is a protocol error.. */
1204 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1205 config
->name
, config
->title
);
1207 /* The user set it wrong. */
1208 error (_("Enabled packet %s (%s) not recognized by stub"),
1209 config
->name
, config
->title
);
1211 case PACKET_SUPPORT_UNKNOWN
:
1213 fprintf_unfiltered (gdb_stdlog
,
1214 "Packet %s (%s) is NOT supported\n",
1215 config
->name
, config
->title
);
1216 config
->support
= PACKET_DISABLE
;
1218 case PACKET_DISABLE
:
1240 PACKET_vFile_pwrite
,
1242 PACKET_vFile_unlink
,
1244 PACKET_qXfer_features
,
1245 PACKET_qXfer_libraries
,
1246 PACKET_qXfer_memory_map
,
1247 PACKET_qXfer_spu_read
,
1248 PACKET_qXfer_spu_write
,
1249 PACKET_qXfer_osdata
,
1250 PACKET_qXfer_threads
,
1251 PACKET_qXfer_statictrace_read
,
1252 PACKET_qXfer_traceframe_info
,
1256 PACKET_QPassSignals
,
1257 PACKET_qSearch_memory
,
1260 PACKET_QStartNoAckMode
,
1262 PACKET_qXfer_siginfo_read
,
1263 PACKET_qXfer_siginfo_write
,
1265 PACKET_ConditionalTracepoints
,
1266 PACKET_FastTracepoints
,
1267 PACKET_StaticTracepoints
,
1268 PACKET_InstallInTrace
,
1271 PACKET_TracepointSource
,
1274 PACKET_QDisableRandomization
,
1278 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1281 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1282 struct cmd_list_element
*c
)
1284 struct packet_config
*packet
;
1286 for (packet
= remote_protocol_packets
;
1287 packet
< &remote_protocol_packets
[PACKET_MAX
];
1290 if (&packet
->detect
== c
->var
)
1292 update_packet_config (packet
);
1296 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1301 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1302 struct cmd_list_element
*c
,
1305 struct packet_config
*packet
;
1307 for (packet
= remote_protocol_packets
;
1308 packet
< &remote_protocol_packets
[PACKET_MAX
];
1311 if (&packet
->detect
== c
->var
)
1313 show_packet_config_cmd (packet
);
1317 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1321 /* Should we try one of the 'Z' requests? */
1325 Z_PACKET_SOFTWARE_BP
,
1326 Z_PACKET_HARDWARE_BP
,
1333 /* For compatibility with older distributions. Provide a ``set remote
1334 Z-packet ...'' command that updates all the Z packet types. */
1336 static enum auto_boolean remote_Z_packet_detect
;
1339 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1340 struct cmd_list_element
*c
)
1344 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1346 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1347 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1352 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1353 struct cmd_list_element
*c
,
1358 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1360 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1364 /* Should we try the 'ThreadInfo' query packet?
1366 This variable (NOT available to the user: auto-detect only!)
1367 determines whether GDB will use the new, simpler "ThreadInfo"
1368 query or the older, more complex syntax for thread queries.
1369 This is an auto-detect variable (set to true at each connect,
1370 and set to false when the target fails to recognize it). */
1372 static int use_threadinfo_query
;
1373 static int use_threadextra_query
;
1375 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1376 static struct async_signal_handler
*sigint_remote_twice_token
;
1377 static struct async_signal_handler
*sigint_remote_token
;
1380 /* Asynchronous signal handle registered as event loop source for
1381 when we have pending events ready to be passed to the core. */
1383 static struct async_event_handler
*remote_async_inferior_event_token
;
1385 /* Asynchronous signal handle registered as event loop source for when
1386 the remote sent us a %Stop notification. The registered callback
1387 will do a vStopped sequence to pull the rest of the events out of
1388 the remote side into our event queue. */
1390 static struct async_event_handler
*remote_async_get_pending_events_token
;
1393 static ptid_t magic_null_ptid
;
1394 static ptid_t not_sent_ptid
;
1395 static ptid_t any_thread_ptid
;
1397 /* These are the threads which we last sent to the remote system. The
1398 TID member will be -1 for all or -2 for not sent yet. */
1400 static ptid_t general_thread
;
1401 static ptid_t continue_thread
;
1403 /* This the traceframe which we last selected on the remote system.
1404 It will be -1 if no traceframe is selected. */
1405 static int remote_traceframe_number
= -1;
1407 /* Find out if the stub attached to PID (and hence GDB should offer to
1408 detach instead of killing it when bailing out). */
1411 remote_query_attached (int pid
)
1413 struct remote_state
*rs
= get_remote_state ();
1415 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1418 if (remote_multi_process_p (rs
))
1419 sprintf (rs
->buf
, "qAttached:%x", pid
);
1421 sprintf (rs
->buf
, "qAttached");
1424 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1426 switch (packet_ok (rs
->buf
,
1427 &remote_protocol_packets
[PACKET_qAttached
]))
1430 if (strcmp (rs
->buf
, "1") == 0)
1434 warning (_("Remote failure reply: %s"), rs
->buf
);
1436 case PACKET_UNKNOWN
:
1443 /* Add PID to GDB's inferior table. Since we can be connected to a
1444 remote system before before knowing about any inferior, mark the
1445 target with execution when we find the first inferior. If ATTACHED
1446 is 1, then we had just attached to this inferior. If it is 0, then
1447 we just created this inferior. If it is -1, then try querying the
1448 remote stub to find out if it had attached to the inferior or
1451 static struct inferior
*
1452 remote_add_inferior (int pid
, int attached
)
1454 struct inferior
*inf
;
1456 /* Check whether this process we're learning about is to be
1457 considered attached, or if is to be considered to have been
1458 spawned by the stub. */
1460 attached
= remote_query_attached (pid
);
1462 if (gdbarch_has_global_solist (target_gdbarch
))
1464 /* If the target shares code across all inferiors, then every
1465 attach adds a new inferior. */
1466 inf
= add_inferior (pid
);
1468 /* ... and every inferior is bound to the same program space.
1469 However, each inferior may still have its own address
1471 inf
->aspace
= maybe_new_address_space ();
1472 inf
->pspace
= current_program_space
;
1476 /* In the traditional debugging scenario, there's a 1-1 match
1477 between program/address spaces. We simply bind the inferior
1478 to the program space's address space. */
1479 inf
= current_inferior ();
1480 inferior_appeared (inf
, pid
);
1483 inf
->attach_flag
= attached
;
1488 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1489 according to RUNNING. */
1492 remote_add_thread (ptid_t ptid
, int running
)
1496 set_executing (ptid
, running
);
1497 set_running (ptid
, running
);
1500 /* Come here when we learn about a thread id from the remote target.
1501 It may be the first time we hear about such thread, so take the
1502 opportunity to add it to GDB's thread list. In case this is the
1503 first time we're noticing its corresponding inferior, add it to
1504 GDB's inferior list as well. */
1507 remote_notice_new_inferior (ptid_t currthread
, int running
)
1509 /* If this is a new thread, add it to GDB's thread list.
1510 If we leave it up to WFI to do this, bad things will happen. */
1512 if (in_thread_list (currthread
) && is_exited (currthread
))
1514 /* We're seeing an event on a thread id we knew had exited.
1515 This has to be a new thread reusing the old id. Add it. */
1516 remote_add_thread (currthread
, running
);
1520 if (!in_thread_list (currthread
))
1522 struct inferior
*inf
= NULL
;
1523 int pid
= ptid_get_pid (currthread
);
1525 if (ptid_is_pid (inferior_ptid
)
1526 && pid
== ptid_get_pid (inferior_ptid
))
1528 /* inferior_ptid has no thread member yet. This can happen
1529 with the vAttach -> remote_wait,"TAAthread:" path if the
1530 stub doesn't support qC. This is the first stop reported
1531 after an attach, so this is the main thread. Update the
1532 ptid in the thread list. */
1533 if (in_thread_list (pid_to_ptid (pid
)))
1534 thread_change_ptid (inferior_ptid
, currthread
);
1537 remote_add_thread (currthread
, running
);
1538 inferior_ptid
= currthread
;
1543 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1545 /* inferior_ptid is not set yet. This can happen with the
1546 vRun -> remote_wait,"TAAthread:" path if the stub
1547 doesn't support qC. This is the first stop reported
1548 after an attach, so this is the main thread. Update the
1549 ptid in the thread list. */
1550 thread_change_ptid (inferior_ptid
, currthread
);
1554 /* When connecting to a target remote, or to a target
1555 extended-remote which already was debugging an inferior, we
1556 may not know about it yet. Add it before adding its child
1557 thread, so notifications are emitted in a sensible order. */
1558 if (!in_inferior_list (ptid_get_pid (currthread
)))
1559 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1561 /* This is really a new thread. Add it. */
1562 remote_add_thread (currthread
, running
);
1564 /* If we found a new inferior, let the common code do whatever
1565 it needs to with it (e.g., read shared libraries, insert
1568 notice_new_inferior (currthread
, running
, 0);
1572 /* Return the private thread data, creating it if necessary. */
1574 struct private_thread_info
*
1575 demand_private_info (ptid_t ptid
)
1577 struct thread_info
*info
= find_thread_ptid (ptid
);
1583 info
->private = xmalloc (sizeof (*(info
->private)));
1584 info
->private_dtor
= free_private_thread_info
;
1585 info
->private->core
= -1;
1586 info
->private->extra
= 0;
1589 return info
->private;
1592 /* Call this function as a result of
1593 1) A halt indication (T packet) containing a thread id
1594 2) A direct query of currthread
1595 3) Successful execution of set thread */
1598 record_currthread (ptid_t currthread
)
1600 general_thread
= currthread
;
1603 static char *last_pass_packet
;
1605 /* If 'QPassSignals' is supported, tell the remote stub what signals
1606 it can simply pass through to the inferior without reporting. */
1609 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1611 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1613 char *pass_packet
, *p
;
1616 gdb_assert (numsigs
< 256);
1617 for (i
= 0; i
< numsigs
; i
++)
1619 if (pass_signals
[i
])
1622 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1623 strcpy (pass_packet
, "QPassSignals:");
1624 p
= pass_packet
+ strlen (pass_packet
);
1625 for (i
= 0; i
< numsigs
; i
++)
1627 if (pass_signals
[i
])
1630 *p
++ = tohex (i
>> 4);
1631 *p
++ = tohex (i
& 15);
1640 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1642 struct remote_state
*rs
= get_remote_state ();
1643 char *buf
= rs
->buf
;
1645 putpkt (pass_packet
);
1646 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1647 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1648 if (last_pass_packet
)
1649 xfree (last_pass_packet
);
1650 last_pass_packet
= pass_packet
;
1653 xfree (pass_packet
);
1657 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1658 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1659 thread. If GEN is set, set the general thread, if not, then set
1660 the step/continue thread. */
1662 set_thread (struct ptid ptid
, int gen
)
1664 struct remote_state
*rs
= get_remote_state ();
1665 ptid_t state
= gen
? general_thread
: continue_thread
;
1666 char *buf
= rs
->buf
;
1667 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1669 if (ptid_equal (state
, ptid
))
1673 *buf
++ = gen
? 'g' : 'c';
1674 if (ptid_equal (ptid
, magic_null_ptid
))
1675 xsnprintf (buf
, endbuf
- buf
, "0");
1676 else if (ptid_equal (ptid
, any_thread_ptid
))
1677 xsnprintf (buf
, endbuf
- buf
, "0");
1678 else if (ptid_equal (ptid
, minus_one_ptid
))
1679 xsnprintf (buf
, endbuf
- buf
, "-1");
1681 write_ptid (buf
, endbuf
, ptid
);
1683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1685 general_thread
= ptid
;
1687 continue_thread
= ptid
;
1691 set_general_thread (struct ptid ptid
)
1693 set_thread (ptid
, 1);
1697 set_continue_thread (struct ptid ptid
)
1699 set_thread (ptid
, 0);
1702 /* Change the remote current process. Which thread within the process
1703 ends up selected isn't important, as long as it is the same process
1704 as what INFERIOR_PTID points to.
1706 This comes from that fact that there is no explicit notion of
1707 "selected process" in the protocol. The selected process for
1708 general operations is the process the selected general thread
1712 set_general_process (void)
1714 struct remote_state
*rs
= get_remote_state ();
1716 /* If the remote can't handle multiple processes, don't bother. */
1717 if (!remote_multi_process_p (rs
))
1720 /* We only need to change the remote current thread if it's pointing
1721 at some other process. */
1722 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1723 set_general_thread (inferior_ptid
);
1727 /* Return nonzero if the thread PTID is still alive on the remote
1731 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1733 struct remote_state
*rs
= get_remote_state ();
1736 if (ptid_equal (ptid
, magic_null_ptid
))
1737 /* The main thread is always alive. */
1740 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1741 /* The main thread is always alive. This can happen after a
1742 vAttach, if the remote side doesn't support
1747 endp
= rs
->buf
+ get_remote_packet_size ();
1750 write_ptid (p
, endp
, ptid
);
1753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1754 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1757 /* About these extended threadlist and threadinfo packets. They are
1758 variable length packets but, the fields within them are often fixed
1759 length. They are redundent enough to send over UDP as is the
1760 remote protocol in general. There is a matching unit test module
1763 #define OPAQUETHREADBYTES 8
1765 /* a 64 bit opaque identifier */
1766 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1768 /* WARNING: This threadref data structure comes from the remote O.S.,
1769 libstub protocol encoding, and remote.c. It is not particularly
1772 /* Right now, the internal structure is int. We want it to be bigger.
1773 Plan to fix this. */
1775 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1777 /* gdb_ext_thread_info is an internal GDB data structure which is
1778 equivalent to the reply of the remote threadinfo packet. */
1780 struct gdb_ext_thread_info
1782 threadref threadid
; /* External form of thread reference. */
1783 int active
; /* Has state interesting to GDB?
1785 char display
[256]; /* Brief state display, name,
1786 blocked/suspended. */
1787 char shortname
[32]; /* To be used to name threads. */
1788 char more_display
[256]; /* Long info, statistics, queue depth,
1792 /* The volume of remote transfers can be limited by submitting
1793 a mask containing bits specifying the desired information.
1794 Use a union of these values as the 'selection' parameter to
1795 get_thread_info. FIXME: Make these TAG names more thread specific. */
1797 #define TAG_THREADID 1
1798 #define TAG_EXISTS 2
1799 #define TAG_DISPLAY 4
1800 #define TAG_THREADNAME 8
1801 #define TAG_MOREDISPLAY 16
1803 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1805 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1807 static char *unpack_nibble (char *buf
, int *val
);
1809 static char *pack_nibble (char *buf
, int nibble
);
1811 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1813 static char *unpack_byte (char *buf
, int *value
);
1815 static char *pack_int (char *buf
, int value
);
1817 static char *unpack_int (char *buf
, int *value
);
1819 static char *unpack_string (char *src
, char *dest
, int length
);
1821 static char *pack_threadid (char *pkt
, threadref
*id
);
1823 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1825 void int_to_threadref (threadref
*id
, int value
);
1827 static int threadref_to_int (threadref
*ref
);
1829 static void copy_threadref (threadref
*dest
, threadref
*src
);
1831 static int threadmatch (threadref
*dest
, threadref
*src
);
1833 static char *pack_threadinfo_request (char *pkt
, int mode
,
1836 static int remote_unpack_thread_info_response (char *pkt
,
1837 threadref
*expectedref
,
1838 struct gdb_ext_thread_info
1842 static int remote_get_threadinfo (threadref
*threadid
,
1843 int fieldset
, /*TAG mask */
1844 struct gdb_ext_thread_info
*info
);
1846 static char *pack_threadlist_request (char *pkt
, int startflag
,
1848 threadref
*nextthread
);
1850 static int parse_threadlist_response (char *pkt
,
1852 threadref
*original_echo
,
1853 threadref
*resultlist
,
1856 static int remote_get_threadlist (int startflag
,
1857 threadref
*nextthread
,
1861 threadref
*threadlist
);
1863 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1865 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1866 void *context
, int looplimit
);
1868 static int remote_newthread_step (threadref
*ref
, void *context
);
1871 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1872 buffer we're allowed to write to. Returns
1873 BUF+CHARACTERS_WRITTEN. */
1876 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1879 struct remote_state
*rs
= get_remote_state ();
1881 if (remote_multi_process_p (rs
))
1883 pid
= ptid_get_pid (ptid
);
1885 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1887 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1889 tid
= ptid_get_tid (ptid
);
1891 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1893 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1898 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1899 passed the last parsed char. Returns null_ptid on error. */
1902 read_ptid (char *buf
, char **obuf
)
1906 ULONGEST pid
= 0, tid
= 0;
1910 /* Multi-process ptid. */
1911 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1913 error (_("invalid remote ptid: %s"), p
);
1916 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1919 return ptid_build (pid
, 0, tid
);
1922 /* No multi-process. Just a tid. */
1923 pp
= unpack_varlen_hex (p
, &tid
);
1925 /* Since the stub is not sending a process id, then default to
1926 what's in inferior_ptid, unless it's null at this point. If so,
1927 then since there's no way to know the pid of the reported
1928 threads, use the magic number. */
1929 if (ptid_equal (inferior_ptid
, null_ptid
))
1930 pid
= ptid_get_pid (magic_null_ptid
);
1932 pid
= ptid_get_pid (inferior_ptid
);
1936 return ptid_build (pid
, 0, tid
);
1939 /* Encode 64 bits in 16 chars of hex. */
1941 static const char hexchars
[] = "0123456789abcdef";
1944 ishex (int ch
, int *val
)
1946 if ((ch
>= 'a') && (ch
<= 'f'))
1948 *val
= ch
- 'a' + 10;
1951 if ((ch
>= 'A') && (ch
<= 'F'))
1953 *val
= ch
- 'A' + 10;
1956 if ((ch
>= '0') && (ch
<= '9'))
1967 if (ch
>= 'a' && ch
<= 'f')
1968 return ch
- 'a' + 10;
1969 if (ch
>= '0' && ch
<= '9')
1971 if (ch
>= 'A' && ch
<= 'F')
1972 return ch
- 'A' + 10;
1977 stub_unpack_int (char *buff
, int fieldlength
)
1984 nibble
= stubhex (*buff
++);
1988 retval
= retval
<< 4;
1994 unpack_varlen_hex (char *buff
, /* packet to parse */
1998 ULONGEST retval
= 0;
2000 while (ishex (*buff
, &nibble
))
2003 retval
= retval
<< 4;
2004 retval
|= nibble
& 0x0f;
2011 unpack_nibble (char *buf
, int *val
)
2013 *val
= fromhex (*buf
++);
2018 pack_nibble (char *buf
, int nibble
)
2020 *buf
++ = hexchars
[(nibble
& 0x0f)];
2025 pack_hex_byte (char *pkt
, int byte
)
2027 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2028 *pkt
++ = hexchars
[(byte
& 0xf)];
2033 unpack_byte (char *buf
, int *value
)
2035 *value
= stub_unpack_int (buf
, 2);
2040 pack_int (char *buf
, int value
)
2042 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2043 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2044 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2045 buf
= pack_hex_byte (buf
, (value
& 0xff));
2050 unpack_int (char *buf
, int *value
)
2052 *value
= stub_unpack_int (buf
, 8);
2056 #if 0 /* Currently unused, uncomment when needed. */
2057 static char *pack_string (char *pkt
, char *string
);
2060 pack_string (char *pkt
, char *string
)
2065 len
= strlen (string
);
2067 len
= 200; /* Bigger than most GDB packets, junk??? */
2068 pkt
= pack_hex_byte (pkt
, len
);
2072 if ((ch
== '\0') || (ch
== '#'))
2073 ch
= '*'; /* Protect encapsulation. */
2078 #endif /* 0 (unused) */
2081 unpack_string (char *src
, char *dest
, int length
)
2090 pack_threadid (char *pkt
, threadref
*id
)
2093 unsigned char *altid
;
2095 altid
= (unsigned char *) id
;
2096 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2098 pkt
= pack_hex_byte (pkt
, *altid
++);
2104 unpack_threadid (char *inbuf
, threadref
*id
)
2107 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2110 altref
= (char *) id
;
2112 while (inbuf
< limit
)
2114 x
= stubhex (*inbuf
++);
2115 y
= stubhex (*inbuf
++);
2116 *altref
++ = (x
<< 4) | y
;
2121 /* Externally, threadrefs are 64 bits but internally, they are still
2122 ints. This is due to a mismatch of specifications. We would like
2123 to use 64bit thread references internally. This is an adapter
2127 int_to_threadref (threadref
*id
, int value
)
2129 unsigned char *scan
;
2131 scan
= (unsigned char *) id
;
2137 *scan
++ = (value
>> 24) & 0xff;
2138 *scan
++ = (value
>> 16) & 0xff;
2139 *scan
++ = (value
>> 8) & 0xff;
2140 *scan
++ = (value
& 0xff);
2144 threadref_to_int (threadref
*ref
)
2147 unsigned char *scan
;
2153 value
= (value
<< 8) | ((*scan
++) & 0xff);
2158 copy_threadref (threadref
*dest
, threadref
*src
)
2161 unsigned char *csrc
, *cdest
;
2163 csrc
= (unsigned char *) src
;
2164 cdest
= (unsigned char *) dest
;
2171 threadmatch (threadref
*dest
, threadref
*src
)
2173 /* Things are broken right now, so just assume we got a match. */
2175 unsigned char *srcp
, *destp
;
2177 srcp
= (char *) src
;
2178 destp
= (char *) dest
;
2182 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2189 threadid:1, # always request threadid
2196 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2199 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2201 *pkt
++ = 'q'; /* Info Query */
2202 *pkt
++ = 'P'; /* process or thread info */
2203 pkt
= pack_int (pkt
, mode
); /* mode */
2204 pkt
= pack_threadid (pkt
, id
); /* threadid */
2205 *pkt
= '\0'; /* terminate */
2209 /* These values tag the fields in a thread info response packet. */
2210 /* Tagging the fields allows us to request specific fields and to
2211 add more fields as time goes by. */
2213 #define TAG_THREADID 1 /* Echo the thread identifier. */
2214 #define TAG_EXISTS 2 /* Is this process defined enough to
2215 fetch registers and its stack? */
2216 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2217 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2218 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2222 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2223 struct gdb_ext_thread_info
*info
)
2225 struct remote_state
*rs
= get_remote_state ();
2229 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2232 /* info->threadid = 0; FIXME: implement zero_threadref. */
2234 info
->display
[0] = '\0';
2235 info
->shortname
[0] = '\0';
2236 info
->more_display
[0] = '\0';
2238 /* Assume the characters indicating the packet type have been
2240 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2241 pkt
= unpack_threadid (pkt
, &ref
);
2244 warning (_("Incomplete response to threadinfo request."));
2245 if (!threadmatch (&ref
, expectedref
))
2246 { /* This is an answer to a different request. */
2247 warning (_("ERROR RMT Thread info mismatch."));
2250 copy_threadref (&info
->threadid
, &ref
);
2252 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2254 /* Packets are terminated with nulls. */
2255 while ((pkt
< limit
) && mask
&& *pkt
)
2257 pkt
= unpack_int (pkt
, &tag
); /* tag */
2258 pkt
= unpack_byte (pkt
, &length
); /* length */
2259 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2261 warning (_("ERROR RMT: threadinfo tag mismatch."));
2265 if (tag
== TAG_THREADID
)
2269 warning (_("ERROR RMT: length of threadid is not 16."));
2273 pkt
= unpack_threadid (pkt
, &ref
);
2274 mask
= mask
& ~TAG_THREADID
;
2277 if (tag
== TAG_EXISTS
)
2279 info
->active
= stub_unpack_int (pkt
, length
);
2281 mask
= mask
& ~(TAG_EXISTS
);
2284 warning (_("ERROR RMT: 'exists' length too long."));
2290 if (tag
== TAG_THREADNAME
)
2292 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2293 mask
= mask
& ~TAG_THREADNAME
;
2296 if (tag
== TAG_DISPLAY
)
2298 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2299 mask
= mask
& ~TAG_DISPLAY
;
2302 if (tag
== TAG_MOREDISPLAY
)
2304 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2305 mask
= mask
& ~TAG_MOREDISPLAY
;
2308 warning (_("ERROR RMT: unknown thread info tag."));
2309 break; /* Not a tag we know about. */
2315 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2316 struct gdb_ext_thread_info
*info
)
2318 struct remote_state
*rs
= get_remote_state ();
2321 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2323 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2325 if (rs
->buf
[0] == '\0')
2328 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2333 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2336 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2337 threadref
*nextthread
)
2339 *pkt
++ = 'q'; /* info query packet */
2340 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2341 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2342 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2343 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2348 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2351 parse_threadlist_response (char *pkt
, int result_limit
,
2352 threadref
*original_echo
, threadref
*resultlist
,
2355 struct remote_state
*rs
= get_remote_state ();
2357 int count
, resultcount
, done
;
2360 /* Assume the 'q' and 'M chars have been stripped. */
2361 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2362 /* done parse past here */
2363 pkt
= unpack_byte (pkt
, &count
); /* count field */
2364 pkt
= unpack_nibble (pkt
, &done
);
2365 /* The first threadid is the argument threadid. */
2366 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2367 while ((count
-- > 0) && (pkt
< limit
))
2369 pkt
= unpack_threadid (pkt
, resultlist
++);
2370 if (resultcount
++ >= result_limit
)
2379 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2380 int *done
, int *result_count
, threadref
*threadlist
)
2382 struct remote_state
*rs
= get_remote_state ();
2383 static threadref echo_nextthread
;
2386 /* Trancate result limit to be smaller than the packet size. */
2387 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2388 >= get_remote_packet_size ())
2389 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2391 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2395 if (*rs
->buf
== '\0')
2399 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2402 if (!threadmatch (&echo_nextthread
, nextthread
))
2404 /* FIXME: This is a good reason to drop the packet. */
2405 /* Possably, there is a duplicate response. */
2407 retransmit immediatly - race conditions
2408 retransmit after timeout - yes
2410 wait for packet, then exit
2412 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2413 return 0; /* I choose simply exiting. */
2415 if (*result_count
<= 0)
2419 warning (_("RMT ERROR : failed to get remote thread list."));
2422 return result
; /* break; */
2424 if (*result_count
> result_limit
)
2427 warning (_("RMT ERROR: threadlist response longer than requested."));
2433 /* This is the interface between remote and threads, remotes upper
2436 /* remote_find_new_threads retrieves the thread list and for each
2437 thread in the list, looks up the thread in GDB's internal list,
2438 adding the thread if it does not already exist. This involves
2439 getting partial thread lists from the remote target so, polling the
2440 quit_flag is required. */
2443 /* About this many threadisds fit in a packet. */
2445 #define MAXTHREADLISTRESULTS 32
2448 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2451 int done
, i
, result_count
;
2455 static threadref nextthread
;
2456 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2461 if (loopcount
++ > looplimit
)
2464 warning (_("Remote fetch threadlist -infinite loop-."));
2467 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2468 &done
, &result_count
, resultthreadlist
))
2473 /* Clear for later iterations. */
2475 /* Setup to resume next batch of thread references, set nextthread. */
2476 if (result_count
>= 1)
2477 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2479 while (result_count
--)
2480 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2487 remote_newthread_step (threadref
*ref
, void *context
)
2489 int pid
= ptid_get_pid (inferior_ptid
);
2490 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2492 if (!in_thread_list (ptid
))
2494 return 1; /* continue iterator */
2497 #define CRAZY_MAX_THREADS 1000
2500 remote_current_thread (ptid_t oldpid
)
2502 struct remote_state
*rs
= get_remote_state ();
2505 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2506 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2507 return read_ptid (&rs
->buf
[2], NULL
);
2512 /* Find new threads for info threads command.
2513 * Original version, using John Metzler's thread protocol.
2517 remote_find_new_threads (void)
2519 remote_threadlist_iterator (remote_newthread_step
, 0,
2523 #if defined(HAVE_LIBEXPAT)
2525 typedef struct thread_item
2531 DEF_VEC_O(thread_item_t
);
2533 struct threads_parsing_context
2535 VEC (thread_item_t
) *items
;
2539 start_thread (struct gdb_xml_parser
*parser
,
2540 const struct gdb_xml_element
*element
,
2541 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2543 struct threads_parsing_context
*data
= user_data
;
2545 struct thread_item item
;
2547 struct gdb_xml_value
*attr
;
2549 id
= xml_find_attribute (attributes
, "id")->value
;
2550 item
.ptid
= read_ptid (id
, NULL
);
2552 attr
= xml_find_attribute (attributes
, "core");
2554 item
.core
= *(ULONGEST
*) attr
->value
;
2560 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2564 end_thread (struct gdb_xml_parser
*parser
,
2565 const struct gdb_xml_element
*element
,
2566 void *user_data
, const char *body_text
)
2568 struct threads_parsing_context
*data
= user_data
;
2570 if (body_text
&& *body_text
)
2571 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2574 const struct gdb_xml_attribute thread_attributes
[] = {
2575 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2576 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2577 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2580 const struct gdb_xml_element thread_children
[] = {
2581 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2584 const struct gdb_xml_element threads_children
[] = {
2585 { "thread", thread_attributes
, thread_children
,
2586 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2587 start_thread
, end_thread
},
2588 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2591 const struct gdb_xml_element threads_elements
[] = {
2592 { "threads", NULL
, threads_children
,
2593 GDB_XML_EF_NONE
, NULL
, NULL
},
2594 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2597 /* Discard the contents of the constructed thread info context. */
2600 clear_threads_parsing_context (void *p
)
2602 struct threads_parsing_context
*context
= p
;
2604 struct thread_item
*item
;
2606 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2607 xfree (item
->extra
);
2609 VEC_free (thread_item_t
, context
->items
);
2615 * Find all threads for info threads command.
2616 * Uses new thread protocol contributed by Cisco.
2617 * Falls back and attempts to use the older method (above)
2618 * if the target doesn't respond to the new method.
2622 remote_threads_info (struct target_ops
*ops
)
2624 struct remote_state
*rs
= get_remote_state ();
2628 if (remote_desc
== 0) /* paranoia */
2629 error (_("Command can only be used when connected to the remote target."));
2631 #if defined(HAVE_LIBEXPAT)
2632 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2634 char *xml
= target_read_stralloc (¤t_target
,
2635 TARGET_OBJECT_THREADS
, NULL
);
2637 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2641 struct threads_parsing_context context
;
2643 context
.items
= NULL
;
2644 make_cleanup (clear_threads_parsing_context
, &context
);
2646 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2647 threads_elements
, xml
, &context
) == 0)
2650 struct thread_item
*item
;
2653 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2656 if (!ptid_equal (item
->ptid
, null_ptid
))
2658 struct private_thread_info
*info
;
2659 /* In non-stop mode, we assume new found threads
2660 are running until proven otherwise with a
2661 stop reply. In all-stop, we can only get
2662 here if all threads are stopped. */
2663 int running
= non_stop
? 1 : 0;
2665 remote_notice_new_inferior (item
->ptid
, running
);
2667 info
= demand_private_info (item
->ptid
);
2668 info
->core
= item
->core
;
2669 info
->extra
= item
->extra
;
2676 do_cleanups (back_to
);
2681 if (use_threadinfo_query
)
2683 putpkt ("qfThreadInfo");
2684 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2686 if (bufp
[0] != '\0') /* q packet recognized */
2688 while (*bufp
++ == 'm') /* reply contains one or more TID */
2692 new_thread
= read_ptid (bufp
, &bufp
);
2693 if (!ptid_equal (new_thread
, null_ptid
))
2695 /* In non-stop mode, we assume new found threads
2696 are running until proven otherwise with a
2697 stop reply. In all-stop, we can only get
2698 here if all threads are stopped. */
2699 int running
= non_stop
? 1 : 0;
2701 remote_notice_new_inferior (new_thread
, running
);
2704 while (*bufp
++ == ','); /* comma-separated list */
2705 putpkt ("qsThreadInfo");
2706 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2713 /* Only qfThreadInfo is supported in non-stop mode. */
2717 /* Else fall back to old method based on jmetzler protocol. */
2718 use_threadinfo_query
= 0;
2719 remote_find_new_threads ();
2724 * Collect a descriptive string about the given thread.
2725 * The target may say anything it wants to about the thread
2726 * (typically info about its blocked / runnable state, name, etc.).
2727 * This string will appear in the info threads display.
2729 * Optional: targets are not required to implement this function.
2733 remote_threads_extra_info (struct thread_info
*tp
)
2735 struct remote_state
*rs
= get_remote_state ();
2739 struct gdb_ext_thread_info threadinfo
;
2740 static char display_buf
[100]; /* arbitrary... */
2741 int n
= 0; /* position in display_buf */
2743 if (remote_desc
== 0) /* paranoia */
2744 internal_error (__FILE__
, __LINE__
,
2745 _("remote_threads_extra_info"));
2747 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2748 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2749 /* This is the main thread which was added by GDB. The remote
2750 server doesn't know about it. */
2753 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2755 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2757 if (info
&& info
->private)
2758 return info
->private->extra
;
2763 if (use_threadextra_query
)
2766 char *endb
= rs
->buf
+ get_remote_packet_size ();
2768 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2770 write_ptid (b
, endb
, tp
->ptid
);
2773 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2774 if (rs
->buf
[0] != 0)
2776 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2777 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2778 display_buf
[result
] = '\0';
2783 /* If the above query fails, fall back to the old method. */
2784 use_threadextra_query
= 0;
2785 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2786 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2787 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2788 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2789 if (threadinfo
.active
)
2791 if (*threadinfo
.shortname
)
2792 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2793 " Name: %s,", threadinfo
.shortname
);
2794 if (*threadinfo
.display
)
2795 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2796 " State: %s,", threadinfo
.display
);
2797 if (*threadinfo
.more_display
)
2798 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2799 " Priority: %s", threadinfo
.more_display
);
2803 /* For purely cosmetic reasons, clear up trailing commas. */
2804 if (',' == display_buf
[n
-1])
2805 display_buf
[n
-1] = ' ';
2814 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2815 struct static_tracepoint_marker
*marker
)
2817 struct remote_state
*rs
= get_remote_state ();
2820 sprintf (p
, "qTSTMat:");
2822 p
+= hexnumstr (p
, addr
);
2824 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2828 error (_("Remote failure reply: %s"), p
);
2832 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2840 free_current_marker (void *arg
)
2842 struct static_tracepoint_marker
**marker_p
= arg
;
2844 if (*marker_p
!= NULL
)
2846 release_static_tracepoint_marker (*marker_p
);
2853 static VEC(static_tracepoint_marker_p
) *
2854 remote_static_tracepoint_markers_by_strid (const char *strid
)
2856 struct remote_state
*rs
= get_remote_state ();
2857 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2858 struct static_tracepoint_marker
*marker
= NULL
;
2859 struct cleanup
*old_chain
;
2862 /* Ask for a first packet of static tracepoint marker
2865 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2868 error (_("Remote failure reply: %s"), p
);
2870 old_chain
= make_cleanup (free_current_marker
, &marker
);
2875 marker
= XCNEW (struct static_tracepoint_marker
);
2879 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2881 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2883 VEC_safe_push (static_tracepoint_marker_p
,
2889 release_static_tracepoint_marker (marker
);
2890 memset (marker
, 0, sizeof (*marker
));
2893 while (*p
++ == ','); /* comma-separated list */
2894 /* Ask for another packet of static tracepoint definition. */
2896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2900 do_cleanups (old_chain
);
2905 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2908 remote_get_ada_task_ptid (long lwp
, long thread
)
2910 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2914 /* Restart the remote side; this is an extended protocol operation. */
2917 extended_remote_restart (void)
2919 struct remote_state
*rs
= get_remote_state ();
2921 /* Send the restart command; for reasons I don't understand the
2922 remote side really expects a number after the "R". */
2923 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2926 remote_fileio_reset ();
2929 /* Clean up connection to a remote debugger. */
2932 remote_close (int quitting
)
2934 if (remote_desc
== NULL
)
2935 return; /* already closed */
2937 /* Make sure we leave stdin registered in the event loop, and we
2938 don't leave the async SIGINT signal handler installed. */
2939 remote_terminal_ours ();
2941 serial_close (remote_desc
);
2944 /* We don't have a connection to the remote stub anymore. Get rid
2945 of all the inferiors and their threads we were controlling.
2946 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
2947 will be unable to find the thread corresponding to (pid, 0, 0). */
2948 inferior_ptid
= null_ptid
;
2949 discard_all_inferiors ();
2951 /* We're no longer interested in any of these events. */
2952 discard_pending_stop_replies (-1);
2954 if (remote_async_inferior_event_token
)
2955 delete_async_event_handler (&remote_async_inferior_event_token
);
2956 if (remote_async_get_pending_events_token
)
2957 delete_async_event_handler (&remote_async_get_pending_events_token
);
2960 /* Query the remote side for the text, data and bss offsets. */
2965 struct remote_state
*rs
= get_remote_state ();
2968 int lose
, num_segments
= 0, do_sections
, do_segments
;
2969 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2970 struct section_offsets
*offs
;
2971 struct symfile_segment_data
*data
;
2973 if (symfile_objfile
== NULL
)
2976 putpkt ("qOffsets");
2977 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2980 if (buf
[0] == '\000')
2981 return; /* Return silently. Stub doesn't support
2985 warning (_("Remote failure reply: %s"), buf
);
2989 /* Pick up each field in turn. This used to be done with scanf, but
2990 scanf will make trouble if CORE_ADDR size doesn't match
2991 conversion directives correctly. The following code will work
2992 with any size of CORE_ADDR. */
2993 text_addr
= data_addr
= bss_addr
= 0;
2997 if (strncmp (ptr
, "Text=", 5) == 0)
3000 /* Don't use strtol, could lose on big values. */
3001 while (*ptr
&& *ptr
!= ';')
3002 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3004 if (strncmp (ptr
, ";Data=", 6) == 0)
3007 while (*ptr
&& *ptr
!= ';')
3008 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3013 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3016 while (*ptr
&& *ptr
!= ';')
3017 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3019 if (bss_addr
!= data_addr
)
3020 warning (_("Target reported unsupported offsets: %s"), buf
);
3025 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3028 /* Don't use strtol, could lose on big values. */
3029 while (*ptr
&& *ptr
!= ';')
3030 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3033 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3036 while (*ptr
&& *ptr
!= ';')
3037 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3045 error (_("Malformed response to offset query, %s"), buf
);
3046 else if (*ptr
!= '\0')
3047 warning (_("Target reported unsupported offsets: %s"), buf
);
3049 offs
= ((struct section_offsets
*)
3050 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3051 memcpy (offs
, symfile_objfile
->section_offsets
,
3052 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3054 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3055 do_segments
= (data
!= NULL
);
3056 do_sections
= num_segments
== 0;
3058 if (num_segments
> 0)
3060 segments
[0] = text_addr
;
3061 segments
[1] = data_addr
;
3063 /* If we have two segments, we can still try to relocate everything
3064 by assuming that the .text and .data offsets apply to the whole
3065 text and data segments. Convert the offsets given in the packet
3066 to base addresses for symfile_map_offsets_to_segments. */
3067 else if (data
&& data
->num_segments
== 2)
3069 segments
[0] = data
->segment_bases
[0] + text_addr
;
3070 segments
[1] = data
->segment_bases
[1] + data_addr
;
3073 /* If the object file has only one segment, assume that it is text
3074 rather than data; main programs with no writable data are rare,
3075 but programs with no code are useless. Of course the code might
3076 have ended up in the data segment... to detect that we would need
3077 the permissions here. */
3078 else if (data
&& data
->num_segments
== 1)
3080 segments
[0] = data
->segment_bases
[0] + text_addr
;
3083 /* There's no way to relocate by segment. */
3089 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3090 offs
, num_segments
, segments
);
3092 if (ret
== 0 && !do_sections
)
3093 error (_("Can not handle qOffsets TextSeg "
3094 "response with this symbol file"));
3101 free_symfile_segment_data (data
);
3105 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3107 /* This is a temporary kludge to force data and bss to use the
3108 same offsets because that's what nlmconv does now. The real
3109 solution requires changes to the stub and remote.c that I
3110 don't have time to do right now. */
3112 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3113 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3116 objfile_relocate (symfile_objfile
, offs
);
3119 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3120 threads we know are stopped already. This is used during the
3121 initial remote connection in non-stop mode --- threads that are
3122 reported as already being stopped are left stopped. */
3125 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3127 /* If we have a stop reply for this thread, it must be stopped. */
3128 if (peek_stop_reply (thread
->ptid
))
3129 set_stop_requested (thread
->ptid
, 1);
3134 /* Send interrupt_sequence to remote target. */
3136 send_interrupt_sequence (void)
3138 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3139 serial_write (remote_desc
, "\x03", 1);
3140 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3141 serial_send_break (remote_desc
);
3142 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3144 serial_send_break (remote_desc
);
3145 serial_write (remote_desc
, "g", 1);
3148 internal_error (__FILE__
, __LINE__
,
3149 _("Invalid value for interrupt_sequence_mode: %s."),
3150 interrupt_sequence_mode
);
3154 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3156 struct remote_state
*rs
= get_remote_state ();
3157 struct packet_config
*noack_config
;
3158 char *wait_status
= NULL
;
3160 immediate_quit
++; /* Allow user to interrupt it. */
3162 if (interrupt_on_connect
)
3163 send_interrupt_sequence ();
3165 /* Ack any packet which the remote side has already sent. */
3166 serial_write (remote_desc
, "+", 1);
3168 /* The first packet we send to the target is the optional "supported
3169 packets" request. If the target can answer this, it will tell us
3170 which later probes to skip. */
3171 remote_query_supported ();
3173 /* If the stub wants to get a QAllow, compose one and send it. */
3174 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3175 remote_set_permissions ();
3177 /* Next, we possibly activate noack mode.
3179 If the QStartNoAckMode packet configuration is set to AUTO,
3180 enable noack mode if the stub reported a wish for it with
3183 If set to TRUE, then enable noack mode even if the stub didn't
3184 report it in qSupported. If the stub doesn't reply OK, the
3185 session ends with an error.
3187 If FALSE, then don't activate noack mode, regardless of what the
3188 stub claimed should be the default with qSupported. */
3190 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3192 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3193 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3194 && noack_config
->support
== PACKET_ENABLE
))
3196 putpkt ("QStartNoAckMode");
3197 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3198 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3204 /* Tell the remote that we are using the extended protocol. */
3206 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3209 /* Next, if the target can specify a description, read it. We do
3210 this before anything involving memory or registers. */
3211 target_find_description ();
3213 /* Next, now that we know something about the target, update the
3214 address spaces in the program spaces. */
3215 update_address_spaces ();
3217 /* On OSs where the list of libraries is global to all
3218 processes, we fetch them early. */
3219 if (gdbarch_has_global_solist (target_gdbarch
))
3220 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3224 if (!rs
->non_stop_aware
)
3225 error (_("Non-stop mode requested, but remote "
3226 "does not support non-stop"));
3228 putpkt ("QNonStop:1");
3229 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3231 if (strcmp (rs
->buf
, "OK") != 0)
3232 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3234 /* Find about threads and processes the stub is already
3235 controlling. We default to adding them in the running state.
3236 The '?' query below will then tell us about which threads are
3238 remote_threads_info (target
);
3240 else if (rs
->non_stop_aware
)
3242 /* Don't assume that the stub can operate in all-stop mode.
3243 Request it explicitely. */
3244 putpkt ("QNonStop:0");
3245 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3247 if (strcmp (rs
->buf
, "OK") != 0)
3248 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3251 /* Check whether the target is running now. */
3253 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3257 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3260 error (_("The target is not running (try extended-remote?)"));
3262 /* We're connected, but not running. Drop out before we
3263 call start_remote. */
3268 /* Save the reply for later. */
3269 wait_status
= alloca (strlen (rs
->buf
) + 1);
3270 strcpy (wait_status
, rs
->buf
);
3273 /* Let the stub know that we want it to return the thread. */
3274 set_continue_thread (minus_one_ptid
);
3276 /* Without this, some commands which require an active target
3277 (such as kill) won't work. This variable serves (at least)
3278 double duty as both the pid of the target process (if it has
3279 such), and as a flag indicating that a target is active.
3280 These functions should be split out into seperate variables,
3281 especially since GDB will someday have a notion of debugging
3282 several processes. */
3283 inferior_ptid
= magic_null_ptid
;
3285 /* Now, if we have thread information, update inferior_ptid. */
3286 inferior_ptid
= remote_current_thread (inferior_ptid
);
3288 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3290 /* Always add the main thread. */
3291 add_thread_silent (inferior_ptid
);
3293 /* init_wait_for_inferior should be called before get_offsets in order
3294 to manage `inserted' flag in bp loc in a correct state.
3295 breakpoint_init_inferior, called from init_wait_for_inferior, set
3296 `inserted' flag to 0, while before breakpoint_re_set, called from
3297 start_remote, set `inserted' flag to 1. In the initialization of
3298 inferior, breakpoint_init_inferior should be called first, and then
3299 breakpoint_re_set can be called. If this order is broken, state of
3300 `inserted' flag is wrong, and cause some problems on breakpoint
3302 init_wait_for_inferior ();
3304 get_offsets (); /* Get text, data & bss offsets. */
3306 /* If we could not find a description using qXfer, and we know
3307 how to do it some other way, try again. This is not
3308 supported for non-stop; it could be, but it is tricky if
3309 there are no stopped threads when we connect. */
3310 if (remote_read_description_p (target
)
3311 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3313 target_clear_description ();
3314 target_find_description ();
3317 /* Use the previously fetched status. */
3318 gdb_assert (wait_status
!= NULL
);
3319 strcpy (rs
->buf
, wait_status
);
3320 rs
->cached_wait_status
= 1;
3323 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3327 /* Clear WFI global state. Do this before finding about new
3328 threads and inferiors, and setting the current inferior.
3329 Otherwise we would clear the proceed status of the current
3330 inferior when we want its stop_soon state to be preserved
3331 (see notice_new_inferior). */
3332 init_wait_for_inferior ();
3334 /* In non-stop, we will either get an "OK", meaning that there
3335 are no stopped threads at this time; or, a regular stop
3336 reply. In the latter case, there may be more than one thread
3337 stopped --- we pull them all out using the vStopped
3339 if (strcmp (rs
->buf
, "OK") != 0)
3341 struct stop_reply
*stop_reply
;
3342 struct cleanup
*old_chain
;
3344 stop_reply
= stop_reply_xmalloc ();
3345 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3347 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3348 discard_cleanups (old_chain
);
3350 /* get_pending_stop_replies acks this one, and gets the rest
3352 pending_stop_reply
= stop_reply
;
3353 remote_get_pending_stop_replies ();
3355 /* Make sure that threads that were stopped remain
3357 iterate_over_threads (set_stop_requested_callback
, NULL
);
3360 if (target_can_async_p ())
3361 target_async (inferior_event_handler
, 0);
3363 if (thread_count () == 0)
3366 error (_("The target is not running (try extended-remote?)"));
3368 /* We're connected, but not running. Drop out before we
3369 call start_remote. */
3373 /* Let the stub know that we want it to return the thread. */
3375 /* Force the stub to choose a thread. */
3376 set_general_thread (null_ptid
);
3379 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3380 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3381 error (_("remote didn't report the current thread in non-stop mode"));
3383 get_offsets (); /* Get text, data & bss offsets. */
3385 /* In non-stop mode, any cached wait status will be stored in
3386 the stop reply queue. */
3387 gdb_assert (wait_status
== NULL
);
3389 /* Report all signals during attach/startup. */
3390 remote_pass_signals (0, NULL
);
3393 /* If we connected to a live target, do some additional setup. */
3394 if (target_has_execution
)
3396 if (exec_bfd
) /* No use without an exec file. */
3397 remote_check_symbols (symfile_objfile
);
3400 /* Possibly the target has been engaged in a trace run started
3401 previously; find out where things are at. */
3402 if (remote_get_trace_status (current_trace_status ()) != -1)
3404 struct uploaded_tp
*uploaded_tps
= NULL
;
3405 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3407 if (current_trace_status ()->running
)
3408 printf_filtered (_("Trace is already running on the target.\n"));
3410 /* Get trace state variables first, they may be checked when
3411 parsing uploaded commands. */
3413 remote_upload_trace_state_variables (&uploaded_tsvs
);
3415 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3417 remote_upload_tracepoints (&uploaded_tps
);
3419 merge_uploaded_tracepoints (&uploaded_tps
);
3422 /* If breakpoints are global, insert them now. */
3423 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3424 && breakpoints_always_inserted_mode ())
3425 insert_breakpoints ();
3428 /* Open a connection to a remote debugger.
3429 NAME is the filename used for communication. */
3432 remote_open (char *name
, int from_tty
)
3434 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3437 /* Open a connection to a remote debugger using the extended
3438 remote gdb protocol. NAME is the filename used for communication. */
3441 extended_remote_open (char *name
, int from_tty
)
3443 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3446 /* Generic code for opening a connection to a remote target. */
3449 init_all_packet_configs (void)
3453 for (i
= 0; i
< PACKET_MAX
; i
++)
3454 update_packet_config (&remote_protocol_packets
[i
]);
3457 /* Symbol look-up. */
3460 remote_check_symbols (struct objfile
*objfile
)
3462 struct remote_state
*rs
= get_remote_state ();
3463 char *msg
, *reply
, *tmp
;
3464 struct minimal_symbol
*sym
;
3467 /* The remote side has no concept of inferiors that aren't running
3468 yet, it only knows about running processes. If we're connected
3469 but our current inferior is not running, we should not invite the
3470 remote target to request symbol lookups related to its
3471 (unrelated) current process. */
3472 if (!target_has_execution
)
3475 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3478 /* Make sure the remote is pointing at the right process. Note
3479 there's no way to select "no process". */
3480 set_general_process ();
3482 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3483 because we need both at the same time. */
3484 msg
= alloca (get_remote_packet_size ());
3486 /* Invite target to request symbol lookups. */
3488 putpkt ("qSymbol::");
3489 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3490 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3493 while (strncmp (reply
, "qSymbol:", 8) == 0)
3496 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3498 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3500 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3503 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3504 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3506 /* If this is a function address, return the start of code
3507 instead of any data function descriptor. */
3508 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3512 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3513 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3517 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3522 static struct serial
*
3523 remote_serial_open (char *name
)
3525 static int udp_warning
= 0;
3527 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3528 of in ser-tcp.c, because it is the remote protocol assuming that the
3529 serial connection is reliable and not the serial connection promising
3531 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3533 warning (_("The remote protocol may be unreliable over UDP.\n"
3534 "Some events may be lost, rendering further debugging "
3539 return serial_open (name
);
3542 /* Inform the target of our permission settings. The permission flags
3543 work without this, but if the target knows the settings, it can do
3544 a couple things. First, it can add its own check, to catch cases
3545 that somehow manage to get by the permissions checks in target
3546 methods. Second, if the target is wired to disallow particular
3547 settings (for instance, a system in the field that is not set up to
3548 be able to stop at a breakpoint), it can object to any unavailable
3552 remote_set_permissions (void)
3554 struct remote_state
*rs
= get_remote_state ();
3556 sprintf (rs
->buf
, "QAllow:"
3557 "WriteReg:%x;WriteMem:%x;"
3558 "InsertBreak:%x;InsertTrace:%x;"
3559 "InsertFastTrace:%x;Stop:%x",
3560 may_write_registers
, may_write_memory
,
3561 may_insert_breakpoints
, may_insert_tracepoints
,
3562 may_insert_fast_tracepoints
, may_stop
);
3564 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3566 /* If the target didn't like the packet, warn the user. Do not try
3567 to undo the user's settings, that would just be maddening. */
3568 if (strcmp (rs
->buf
, "OK") != 0)
3569 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3572 /* This type describes each known response to the qSupported
3574 struct protocol_feature
3576 /* The name of this protocol feature. */
3579 /* The default for this protocol feature. */
3580 enum packet_support default_support
;
3582 /* The function to call when this feature is reported, or after
3583 qSupported processing if the feature is not supported.
3584 The first argument points to this structure. The second
3585 argument indicates whether the packet requested support be
3586 enabled, disabled, or probed (or the default, if this function
3587 is being called at the end of processing and this feature was
3588 not reported). The third argument may be NULL; if not NULL, it
3589 is a NUL-terminated string taken from the packet following
3590 this feature's name and an equals sign. */
3591 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3594 /* The corresponding packet for this feature. Only used if
3595 FUNC is remote_supported_packet. */
3600 remote_supported_packet (const struct protocol_feature
*feature
,
3601 enum packet_support support
,
3602 const char *argument
)
3606 warning (_("Remote qSupported response supplied an unexpected value for"
3607 " \"%s\"."), feature
->name
);
3611 if (remote_protocol_packets
[feature
->packet
].support
3612 == PACKET_SUPPORT_UNKNOWN
)
3613 remote_protocol_packets
[feature
->packet
].support
= support
;
3617 remote_packet_size (const struct protocol_feature
*feature
,
3618 enum packet_support support
, const char *value
)
3620 struct remote_state
*rs
= get_remote_state ();
3625 if (support
!= PACKET_ENABLE
)
3628 if (value
== NULL
|| *value
== '\0')
3630 warning (_("Remote target reported \"%s\" without a size."),
3636 packet_size
= strtol (value
, &value_end
, 16);
3637 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3639 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3640 feature
->name
, value
);
3644 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3646 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3647 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3648 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3651 /* Record the new maximum packet size. */
3652 rs
->explicit_packet_size
= packet_size
;
3656 remote_multi_process_feature (const struct protocol_feature
*feature
,
3657 enum packet_support support
, const char *value
)
3659 struct remote_state
*rs
= get_remote_state ();
3661 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3665 remote_non_stop_feature (const struct protocol_feature
*feature
,
3666 enum packet_support support
, const char *value
)
3668 struct remote_state
*rs
= get_remote_state ();
3670 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3674 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3675 enum packet_support support
,
3678 struct remote_state
*rs
= get_remote_state ();
3680 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3684 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3685 enum packet_support support
,
3688 struct remote_state
*rs
= get_remote_state ();
3690 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3694 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3695 enum packet_support support
,
3698 struct remote_state
*rs
= get_remote_state ();
3700 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3704 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3705 enum packet_support support
,
3708 struct remote_state
*rs
= get_remote_state ();
3710 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3714 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3715 enum packet_support support
,
3718 struct remote_state
*rs
= get_remote_state ();
3720 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3724 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3725 enum packet_support support
,
3728 struct remote_state
*rs
= get_remote_state ();
3730 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3734 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3735 enum packet_support support
,
3738 struct remote_state
*rs
= get_remote_state ();
3740 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3743 static struct protocol_feature remote_protocol_features
[] = {
3744 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3745 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3746 PACKET_qXfer_auxv
},
3747 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3748 PACKET_qXfer_features
},
3749 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3750 PACKET_qXfer_libraries
},
3751 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3752 PACKET_qXfer_memory_map
},
3753 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3754 PACKET_qXfer_spu_read
},
3755 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3756 PACKET_qXfer_spu_write
},
3757 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3758 PACKET_qXfer_osdata
},
3759 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3760 PACKET_qXfer_threads
},
3761 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3762 PACKET_qXfer_traceframe_info
},
3763 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3764 PACKET_QPassSignals
},
3765 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3766 PACKET_QStartNoAckMode
},
3767 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3768 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3769 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3770 PACKET_qXfer_siginfo_read
},
3771 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3772 PACKET_qXfer_siginfo_write
},
3773 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3774 PACKET_ConditionalTracepoints
},
3775 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3776 PACKET_FastTracepoints
},
3777 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3778 PACKET_StaticTracepoints
},
3779 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3780 PACKET_InstallInTrace
},
3781 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3783 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3785 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3787 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3788 PACKET_TracepointSource
},
3789 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3791 { "EnableDisableTracepoints", PACKET_DISABLE
,
3792 remote_enable_disable_tracepoint_feature
, -1 },
3793 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3794 PACKET_qXfer_fdpic
},
3795 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3796 PACKET_QDisableRandomization
},
3797 { "tracenz", PACKET_DISABLE
,
3798 remote_string_tracing_feature
, -1 },
3801 static char *remote_support_xml
;
3803 /* Register string appended to "xmlRegisters=" in qSupported query. */
3806 register_remote_support_xml (const char *xml
)
3808 #if defined(HAVE_LIBEXPAT)
3809 if (remote_support_xml
== NULL
)
3810 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3813 char *copy
= xstrdup (remote_support_xml
+ 13);
3814 char *p
= strtok (copy
, ",");
3818 if (strcmp (p
, xml
) == 0)
3825 while ((p
= strtok (NULL
, ",")) != NULL
);
3828 remote_support_xml
= reconcat (remote_support_xml
,
3829 remote_support_xml
, ",", xml
,
3836 remote_query_supported_append (char *msg
, const char *append
)
3839 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3841 return xstrdup (append
);
3845 remote_query_supported (void)
3847 struct remote_state
*rs
= get_remote_state ();
3850 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3852 /* The packet support flags are handled differently for this packet
3853 than for most others. We treat an error, a disabled packet, and
3854 an empty response identically: any features which must be reported
3855 to be used will be automatically disabled. An empty buffer
3856 accomplishes this, since that is also the representation for a list
3857 containing no features. */
3860 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3863 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3866 q
= remote_query_supported_append (q
, "multiprocess+");
3868 if (remote_support_xml
)
3869 q
= remote_query_supported_append (q
, remote_support_xml
);
3871 q
= remote_query_supported_append (q
, "qRelocInsn+");
3873 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3876 do_cleanups (old_chain
);
3878 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3880 /* If an error occured, warn, but do not return - just reset the
3881 buffer to empty and go on to disable features. */
3882 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3885 warning (_("Remote failure reply: %s"), rs
->buf
);
3890 memset (seen
, 0, sizeof (seen
));
3895 enum packet_support is_supported
;
3896 char *p
, *end
, *name_end
, *value
;
3898 /* First separate out this item from the rest of the packet. If
3899 there's another item after this, we overwrite the separator
3900 (terminated strings are much easier to work with). */
3902 end
= strchr (p
, ';');
3905 end
= p
+ strlen (p
);
3915 warning (_("empty item in \"qSupported\" response"));
3920 name_end
= strchr (p
, '=');
3923 /* This is a name=value entry. */
3924 is_supported
= PACKET_ENABLE
;
3925 value
= name_end
+ 1;
3934 is_supported
= PACKET_ENABLE
;
3938 is_supported
= PACKET_DISABLE
;
3942 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3946 warning (_("unrecognized item \"%s\" "
3947 "in \"qSupported\" response"), p
);
3953 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3954 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3956 const struct protocol_feature
*feature
;
3959 feature
= &remote_protocol_features
[i
];
3960 feature
->func (feature
, is_supported
, value
);
3965 /* If we increased the packet size, make sure to increase the global
3966 buffer size also. We delay this until after parsing the entire
3967 qSupported packet, because this is the same buffer we were
3969 if (rs
->buf_size
< rs
->explicit_packet_size
)
3971 rs
->buf_size
= rs
->explicit_packet_size
;
3972 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3975 /* Handle the defaults for unmentioned features. */
3976 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3979 const struct protocol_feature
*feature
;
3981 feature
= &remote_protocol_features
[i
];
3982 feature
->func (feature
, feature
->default_support
, NULL
);
3988 remote_open_1 (char *name
, int from_tty
,
3989 struct target_ops
*target
, int extended_p
)
3991 struct remote_state
*rs
= get_remote_state ();
3994 error (_("To open a remote debug connection, you need to specify what\n"
3995 "serial device is attached to the remote system\n"
3996 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3998 /* See FIXME above. */
3999 if (!target_async_permitted
)
4000 wait_forever_enabled_p
= 1;
4002 /* If we're connected to a running target, target_preopen will kill it.
4003 But if we're connected to a target system with no running process,
4004 then we will still be connected when it returns. Ask this question
4005 first, before target_preopen has a chance to kill anything. */
4006 if (remote_desc
!= NULL
&& !have_inferiors ())
4009 || query (_("Already connected to a remote target. Disconnect? ")))
4012 error (_("Still connected."));
4015 target_preopen (from_tty
);
4017 unpush_target (target
);
4019 /* This time without a query. If we were connected to an
4020 extended-remote target and target_preopen killed the running
4021 process, we may still be connected. If we are starting "target
4022 remote" now, the extended-remote target will not have been
4023 removed by unpush_target. */
4024 if (remote_desc
!= NULL
&& !have_inferiors ())
4027 /* Make sure we send the passed signals list the next time we resume. */
4028 xfree (last_pass_packet
);
4029 last_pass_packet
= NULL
;
4031 remote_fileio_reset ();
4032 reopen_exec_file ();
4035 remote_desc
= remote_serial_open (name
);
4037 perror_with_name (name
);
4039 if (baud_rate
!= -1)
4041 if (serial_setbaudrate (remote_desc
, baud_rate
))
4043 /* The requested speed could not be set. Error out to
4044 top level after closing remote_desc. Take care to
4045 set remote_desc to NULL to avoid closing remote_desc
4047 serial_close (remote_desc
);
4049 perror_with_name (name
);
4053 serial_raw (remote_desc
);
4055 /* If there is something sitting in the buffer we might take it as a
4056 response to a command, which would be bad. */
4057 serial_flush_input (remote_desc
);
4061 puts_filtered ("Remote debugging using ");
4062 puts_filtered (name
);
4063 puts_filtered ("\n");
4065 push_target (target
); /* Switch to using remote target now. */
4067 /* Register extra event sources in the event loop. */
4068 remote_async_inferior_event_token
4069 = create_async_event_handler (remote_async_inferior_event_handler
,
4071 remote_async_get_pending_events_token
4072 = create_async_event_handler (remote_async_get_pending_events_handler
,
4075 /* Reset the target state; these things will be queried either by
4076 remote_query_supported or as they are needed. */
4077 init_all_packet_configs ();
4078 rs
->cached_wait_status
= 0;
4079 rs
->explicit_packet_size
= 0;
4081 rs
->multi_process_aware
= 0;
4082 rs
->extended
= extended_p
;
4083 rs
->non_stop_aware
= 0;
4084 rs
->waiting_for_stop_reply
= 0;
4085 rs
->ctrlc_pending_p
= 0;
4087 general_thread
= not_sent_ptid
;
4088 continue_thread
= not_sent_ptid
;
4089 remote_traceframe_number
= -1;
4091 /* Probe for ability to use "ThreadInfo" query, as required. */
4092 use_threadinfo_query
= 1;
4093 use_threadextra_query
= 1;
4095 if (target_async_permitted
)
4097 /* With this target we start out by owning the terminal. */
4098 remote_async_terminal_ours_p
= 1;
4100 /* FIXME: cagney/1999-09-23: During the initial connection it is
4101 assumed that the target is already ready and able to respond to
4102 requests. Unfortunately remote_start_remote() eventually calls
4103 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4104 around this. Eventually a mechanism that allows
4105 wait_for_inferior() to expect/get timeouts will be
4107 wait_forever_enabled_p
= 0;
4110 /* First delete any symbols previously loaded from shared libraries. */
4111 no_shared_libraries (NULL
, 0);
4114 init_thread_list ();
4116 /* Start the remote connection. If error() or QUIT, discard this
4117 target (we'd otherwise be in an inconsistent state) and then
4118 propogate the error on up the exception chain. This ensures that
4119 the caller doesn't stumble along blindly assuming that the
4120 function succeeded. The CLI doesn't have this problem but other
4121 UI's, such as MI do.
4123 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4124 this function should return an error indication letting the
4125 caller restore the previous state. Unfortunately the command
4126 ``target remote'' is directly wired to this function making that
4127 impossible. On a positive note, the CLI side of this problem has
4128 been fixed - the function set_cmd_context() makes it possible for
4129 all the ``target ....'' commands to share a common callback
4130 function. See cli-dump.c. */
4132 volatile struct gdb_exception ex
;
4134 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4136 remote_start_remote (from_tty
, target
, extended_p
);
4140 /* Pop the partially set up target - unless something else did
4141 already before throwing the exception. */
4142 if (remote_desc
!= NULL
)
4144 if (target_async_permitted
)
4145 wait_forever_enabled_p
= 1;
4146 throw_exception (ex
);
4150 if (target_async_permitted
)
4151 wait_forever_enabled_p
= 1;
4154 /* This takes a program previously attached to and detaches it. After
4155 this is done, GDB can be used to debug some other program. We
4156 better not have left any breakpoints in the target program or it'll
4157 die when it hits one. */
4160 remote_detach_1 (char *args
, int from_tty
, int extended
)
4162 int pid
= ptid_get_pid (inferior_ptid
);
4163 struct remote_state
*rs
= get_remote_state ();
4166 error (_("Argument given to \"detach\" when remotely debugging."));
4168 if (!target_has_execution
)
4169 error (_("No process to detach from."));
4171 /* Tell the remote target to detach. */
4172 if (remote_multi_process_p (rs
))
4173 sprintf (rs
->buf
, "D;%x", pid
);
4175 strcpy (rs
->buf
, "D");
4178 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4180 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4182 else if (rs
->buf
[0] == '\0')
4183 error (_("Remote doesn't know how to detach"));
4185 error (_("Can't detach process."));
4189 if (remote_multi_process_p (rs
))
4190 printf_filtered (_("Detached from remote %s.\n"),
4191 target_pid_to_str (pid_to_ptid (pid
)));
4195 puts_filtered (_("Detached from remote process.\n"));
4197 puts_filtered (_("Ending remote debugging.\n"));
4201 discard_pending_stop_replies (pid
);
4202 target_mourn_inferior ();
4206 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4208 remote_detach_1 (args
, from_tty
, 0);
4212 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4214 remote_detach_1 (args
, from_tty
, 1);
4217 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4220 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4223 error (_("Argument given to \"disconnect\" when remotely debugging."));
4225 /* Make sure we unpush even the extended remote targets; mourn
4226 won't do it. So call remote_mourn_1 directly instead of
4227 target_mourn_inferior. */
4228 remote_mourn_1 (target
);
4231 puts_filtered ("Ending remote debugging.\n");
4234 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4235 be chatty about it. */
4238 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4240 struct remote_state
*rs
= get_remote_state ();
4242 char *wait_status
= NULL
;
4244 pid
= parse_pid_to_attach (args
);
4246 /* Remote PID can be freely equal to getpid, do not check it here the same
4247 way as in other targets. */
4249 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4250 error (_("This target does not support attaching to a process"));
4252 sprintf (rs
->buf
, "vAttach;%x", pid
);
4254 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4256 if (packet_ok (rs
->buf
,
4257 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4260 printf_unfiltered (_("Attached to %s\n"),
4261 target_pid_to_str (pid_to_ptid (pid
)));
4265 /* Save the reply for later. */
4266 wait_status
= alloca (strlen (rs
->buf
) + 1);
4267 strcpy (wait_status
, rs
->buf
);
4269 else if (strcmp (rs
->buf
, "OK") != 0)
4270 error (_("Attaching to %s failed with: %s"),
4271 target_pid_to_str (pid_to_ptid (pid
)),
4274 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4275 error (_("This target does not support attaching to a process"));
4277 error (_("Attaching to %s failed"),
4278 target_pid_to_str (pid_to_ptid (pid
)));
4280 set_current_inferior (remote_add_inferior (pid
, 1));
4282 inferior_ptid
= pid_to_ptid (pid
);
4286 struct thread_info
*thread
;
4288 /* Get list of threads. */
4289 remote_threads_info (target
);
4291 thread
= first_thread_of_process (pid
);
4293 inferior_ptid
= thread
->ptid
;
4295 inferior_ptid
= pid_to_ptid (pid
);
4297 /* Invalidate our notion of the remote current thread. */
4298 record_currthread (minus_one_ptid
);
4302 /* Now, if we have thread information, update inferior_ptid. */
4303 inferior_ptid
= remote_current_thread (inferior_ptid
);
4305 /* Add the main thread to the thread list. */
4306 add_thread_silent (inferior_ptid
);
4309 /* Next, if the target can specify a description, read it. We do
4310 this before anything involving memory or registers. */
4311 target_find_description ();
4315 /* Use the previously fetched status. */
4316 gdb_assert (wait_status
!= NULL
);
4318 if (target_can_async_p ())
4320 struct stop_reply
*stop_reply
;
4321 struct cleanup
*old_chain
;
4323 stop_reply
= stop_reply_xmalloc ();
4324 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4325 remote_parse_stop_reply (wait_status
, stop_reply
);
4326 discard_cleanups (old_chain
);
4327 push_stop_reply (stop_reply
);
4329 target_async (inferior_event_handler
, 0);
4333 gdb_assert (wait_status
!= NULL
);
4334 strcpy (rs
->buf
, wait_status
);
4335 rs
->cached_wait_status
= 1;
4339 gdb_assert (wait_status
== NULL
);
4343 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4345 extended_remote_attach_1 (ops
, args
, from_tty
);
4348 /* Convert hex digit A to a number. */
4353 if (a
>= '0' && a
<= '9')
4355 else if (a
>= 'a' && a
<= 'f')
4356 return a
- 'a' + 10;
4357 else if (a
>= 'A' && a
<= 'F')
4358 return a
- 'A' + 10;
4360 error (_("Reply contains invalid hex digit %d"), a
);
4364 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4368 for (i
= 0; i
< count
; i
++)
4370 if (hex
[0] == 0 || hex
[1] == 0)
4372 /* Hex string is short, or of uneven length.
4373 Return the count that has been converted so far. */
4376 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4382 /* Convert number NIB to a hex digit. */
4390 return 'a' + nib
- 10;
4394 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4398 /* May use a length, or a nul-terminated string as input. */
4400 count
= strlen ((char *) bin
);
4402 for (i
= 0; i
< count
; i
++)
4404 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4405 *hex
++ = tohex (*bin
++ & 0xf);
4411 /* Check for the availability of vCont. This function should also check
4415 remote_vcont_probe (struct remote_state
*rs
)
4419 strcpy (rs
->buf
, "vCont?");
4421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4424 /* Make sure that the features we assume are supported. */
4425 if (strncmp (buf
, "vCont", 5) == 0)
4428 int support_s
, support_S
, support_c
, support_C
;
4434 rs
->support_vCont_t
= 0;
4435 while (p
&& *p
== ';')
4438 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4440 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4442 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4444 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4446 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4447 rs
->support_vCont_t
= 1;
4449 p
= strchr (p
, ';');
4452 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4453 BUF will make packet_ok disable the packet. */
4454 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4458 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4461 /* Helper function for building "vCont" resumptions. Write a
4462 resumption to P. ENDP points to one-passed-the-end of the buffer
4463 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4464 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4465 resumed thread should be single-stepped and/or signalled. If PTID
4466 equals minus_one_ptid, then all threads are resumed; if PTID
4467 represents a process, then all threads of the process are resumed;
4468 the thread to be stepped and/or signalled is given in the global
4472 append_resumption (char *p
, char *endp
,
4473 ptid_t ptid
, int step
, enum target_signal siggnal
)
4475 struct remote_state
*rs
= get_remote_state ();
4477 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4478 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4480 p
+= xsnprintf (p
, endp
- p
, ";s");
4481 else if (siggnal
!= TARGET_SIGNAL_0
)
4482 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4484 p
+= xsnprintf (p
, endp
- p
, ";c");
4486 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4490 /* All (-1) threads of process. */
4491 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4493 p
+= xsnprintf (p
, endp
- p
, ":");
4494 p
= write_ptid (p
, endp
, nptid
);
4496 else if (!ptid_equal (ptid
, minus_one_ptid
))
4498 p
+= xsnprintf (p
, endp
- p
, ":");
4499 p
= write_ptid (p
, endp
, ptid
);
4505 /* Resume the remote inferior by using a "vCont" packet. The thread
4506 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4507 resumed thread should be single-stepped and/or signalled. If PTID
4508 equals minus_one_ptid, then all threads are resumed; the thread to
4509 be stepped and/or signalled is given in the global INFERIOR_PTID.
4510 This function returns non-zero iff it resumes the inferior.
4512 This function issues a strict subset of all possible vCont commands at the
4516 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4518 struct remote_state
*rs
= get_remote_state ();
4522 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4523 remote_vcont_probe (rs
);
4525 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4529 endp
= rs
->buf
+ get_remote_packet_size ();
4531 /* If we could generate a wider range of packets, we'd have to worry
4532 about overflowing BUF. Should there be a generic
4533 "multi-part-packet" packet? */
4535 p
+= xsnprintf (p
, endp
- p
, "vCont");
4537 if (ptid_equal (ptid
, magic_null_ptid
))
4539 /* MAGIC_NULL_PTID means that we don't have any active threads,
4540 so we don't have any TID numbers the inferior will
4541 understand. Make sure to only send forms that do not specify
4543 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4545 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4547 /* Resume all threads (of all processes, or of a single
4548 process), with preference for INFERIOR_PTID. This assumes
4549 inferior_ptid belongs to the set of all threads we are about
4551 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4553 /* Step inferior_ptid, with or without signal. */
4554 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4557 /* And continue others without a signal. */
4558 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4562 /* Scheduler locking; resume only PTID. */
4563 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4566 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4571 /* In non-stop, the stub replies to vCont with "OK". The stop
4572 reply will be reported asynchronously by means of a `%Stop'
4574 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4575 if (strcmp (rs
->buf
, "OK") != 0)
4576 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4582 /* Tell the remote machine to resume. */
4584 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4586 static int last_sent_step
;
4589 remote_resume (struct target_ops
*ops
,
4590 ptid_t ptid
, int step
, enum target_signal siggnal
)
4592 struct remote_state
*rs
= get_remote_state ();
4595 last_sent_signal
= siggnal
;
4596 last_sent_step
= step
;
4598 /* The vCont packet doesn't need to specify threads via Hc. */
4599 /* No reverse support (yet) for vCont. */
4600 if (execution_direction
!= EXEC_REVERSE
)
4601 if (remote_vcont_resume (ptid
, step
, siggnal
))
4604 /* All other supported resume packets do use Hc, so set the continue
4606 if (ptid_equal (ptid
, minus_one_ptid
))
4607 set_continue_thread (any_thread_ptid
);
4609 set_continue_thread (ptid
);
4612 if (execution_direction
== EXEC_REVERSE
)
4614 /* We don't pass signals to the target in reverse exec mode. */
4615 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4616 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4620 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4621 error (_("Remote reverse-step not supported."));
4623 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4624 error (_("Remote reverse-continue not supported."));
4626 strcpy (buf
, step
? "bs" : "bc");
4628 else if (siggnal
!= TARGET_SIGNAL_0
)
4630 buf
[0] = step
? 'S' : 'C';
4631 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4632 buf
[2] = tohex (((int) siggnal
) & 0xf);
4636 strcpy (buf
, step
? "s" : "c");
4641 /* We are about to start executing the inferior, let's register it
4642 with the event loop. NOTE: this is the one place where all the
4643 execution commands end up. We could alternatively do this in each
4644 of the execution commands in infcmd.c. */
4645 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4646 into infcmd.c in order to allow inferior function calls to work
4647 NOT asynchronously. */
4648 if (target_can_async_p ())
4649 target_async (inferior_event_handler
, 0);
4651 /* We've just told the target to resume. The remote server will
4652 wait for the inferior to stop, and then send a stop reply. In
4653 the mean time, we can't start another command/query ourselves
4654 because the stub wouldn't be ready to process it. This applies
4655 only to the base all-stop protocol, however. In non-stop (which
4656 only supports vCont), the stub replies with an "OK", and is
4657 immediate able to process further serial input. */
4659 rs
->waiting_for_stop_reply
= 1;
4663 /* Set up the signal handler for SIGINT, while the target is
4664 executing, ovewriting the 'regular' SIGINT signal handler. */
4666 initialize_sigint_signal_handler (void)
4668 signal (SIGINT
, handle_remote_sigint
);
4671 /* Signal handler for SIGINT, while the target is executing. */
4673 handle_remote_sigint (int sig
)
4675 signal (sig
, handle_remote_sigint_twice
);
4676 mark_async_signal_handler_wrapper (sigint_remote_token
);
4679 /* Signal handler for SIGINT, installed after SIGINT has already been
4680 sent once. It will take effect the second time that the user sends
4683 handle_remote_sigint_twice (int sig
)
4685 signal (sig
, handle_remote_sigint
);
4686 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4689 /* Perform the real interruption of the target execution, in response
4692 async_remote_interrupt (gdb_client_data arg
)
4695 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4697 target_stop (inferior_ptid
);
4700 /* Perform interrupt, if the first attempt did not succeed. Just give
4701 up on the target alltogether. */
4703 async_remote_interrupt_twice (gdb_client_data arg
)
4706 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4711 /* Reinstall the usual SIGINT handlers, after the target has
4714 cleanup_sigint_signal_handler (void *dummy
)
4716 signal (SIGINT
, handle_sigint
);
4719 /* Send ^C to target to halt it. Target will respond, and send us a
4721 static void (*ofunc
) (int);
4723 /* The command line interface's stop routine. This function is installed
4724 as a signal handler for SIGINT. The first time a user requests a
4725 stop, we call remote_stop to send a break or ^C. If there is no
4726 response from the target (it didn't stop when the user requested it),
4727 we ask the user if he'd like to detach from the target. */
4729 remote_interrupt (int signo
)
4731 /* If this doesn't work, try more severe steps. */
4732 signal (signo
, remote_interrupt_twice
);
4734 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4737 /* The user typed ^C twice. */
4740 remote_interrupt_twice (int signo
)
4742 signal (signo
, ofunc
);
4743 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4744 signal (signo
, remote_interrupt
);
4747 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4748 thread, all threads of a remote process, or all threads of all
4752 remote_stop_ns (ptid_t ptid
)
4754 struct remote_state
*rs
= get_remote_state ();
4756 char *endp
= rs
->buf
+ get_remote_packet_size ();
4758 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4759 remote_vcont_probe (rs
);
4761 if (!rs
->support_vCont_t
)
4762 error (_("Remote server does not support stopping threads"));
4764 if (ptid_equal (ptid
, minus_one_ptid
)
4765 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4766 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4771 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4773 if (ptid_is_pid (ptid
))
4774 /* All (-1) threads of process. */
4775 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4778 /* Small optimization: if we already have a stop reply for
4779 this thread, no use in telling the stub we want this
4781 if (peek_stop_reply (ptid
))
4787 write_ptid (p
, endp
, nptid
);
4790 /* In non-stop, we get an immediate OK reply. The stop reply will
4791 come in asynchronously by notification. */
4793 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4794 if (strcmp (rs
->buf
, "OK") != 0)
4795 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4798 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4799 remote target. It is undefined which thread of which process
4800 reports the stop. */
4803 remote_stop_as (ptid_t ptid
)
4805 struct remote_state
*rs
= get_remote_state ();
4807 rs
->ctrlc_pending_p
= 1;
4809 /* If the inferior is stopped already, but the core didn't know
4810 about it yet, just ignore the request. The cached wait status
4811 will be collected in remote_wait. */
4812 if (rs
->cached_wait_status
)
4815 /* Send interrupt_sequence to remote target. */
4816 send_interrupt_sequence ();
4819 /* This is the generic stop called via the target vector. When a target
4820 interrupt is requested, either by the command line or the GUI, we
4821 will eventually end up here. */
4824 remote_stop (ptid_t ptid
)
4827 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4830 remote_stop_ns (ptid
);
4832 remote_stop_as (ptid
);
4835 /* Ask the user what to do when an interrupt is received. */
4838 interrupt_query (void)
4840 target_terminal_ours ();
4842 if (target_can_async_p ())
4844 signal (SIGINT
, handle_sigint
);
4845 deprecated_throw_reason (RETURN_QUIT
);
4849 if (query (_("Interrupted while waiting for the program.\n\
4850 Give up (and stop debugging it)? ")))
4853 deprecated_throw_reason (RETURN_QUIT
);
4857 target_terminal_inferior ();
4860 /* Enable/disable target terminal ownership. Most targets can use
4861 terminal groups to control terminal ownership. Remote targets are
4862 different in that explicit transfer of ownership to/from GDB/target
4866 remote_terminal_inferior (void)
4868 if (!target_async_permitted
)
4869 /* Nothing to do. */
4872 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4873 idempotent. The event-loop GDB talking to an asynchronous target
4874 with a synchronous command calls this function from both
4875 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4876 transfer the terminal to the target when it shouldn't this guard
4878 if (!remote_async_terminal_ours_p
)
4880 delete_file_handler (input_fd
);
4881 remote_async_terminal_ours_p
= 0;
4882 initialize_sigint_signal_handler ();
4883 /* NOTE: At this point we could also register our selves as the
4884 recipient of all input. Any characters typed could then be
4885 passed on down to the target. */
4889 remote_terminal_ours (void)
4891 if (!target_async_permitted
)
4892 /* Nothing to do. */
4895 /* See FIXME in remote_terminal_inferior. */
4896 if (remote_async_terminal_ours_p
)
4898 cleanup_sigint_signal_handler (NULL
);
4899 add_file_handler (input_fd
, stdin_event_handler
, 0);
4900 remote_async_terminal_ours_p
= 1;
4904 remote_console_output (char *msg
)
4908 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4911 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4915 fputs_unfiltered (tb
, gdb_stdtarg
);
4917 gdb_flush (gdb_stdtarg
);
4920 typedef struct cached_reg
4923 gdb_byte data
[MAX_REGISTER_SIZE
];
4926 DEF_VEC_O(cached_reg_t
);
4930 struct stop_reply
*next
;
4934 struct target_waitstatus ws
;
4936 /* Expedited registers. This makes remote debugging a bit more
4937 efficient for those targets that provide critical registers as
4938 part of their normal status mechanism (as another roundtrip to
4939 fetch them is avoided). */
4940 VEC(cached_reg_t
) *regcache
;
4942 int stopped_by_watchpoint_p
;
4943 CORE_ADDR watch_data_address
;
4951 /* The list of already fetched and acknowledged stop events. */
4952 static struct stop_reply
*stop_reply_queue
;
4954 static struct stop_reply
*
4955 stop_reply_xmalloc (void)
4957 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4964 stop_reply_xfree (struct stop_reply
*r
)
4968 VEC_free (cached_reg_t
, r
->regcache
);
4973 /* Discard all pending stop replies of inferior PID. If PID is -1,
4974 discard everything. */
4977 discard_pending_stop_replies (int pid
)
4979 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4981 /* Discard the in-flight notification. */
4982 if (pending_stop_reply
!= NULL
4984 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4986 stop_reply_xfree (pending_stop_reply
);
4987 pending_stop_reply
= NULL
;
4990 /* Discard the stop replies we have already pulled with
4992 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4996 || ptid_get_pid (reply
->ptid
) == pid
)
4998 if (reply
== stop_reply_queue
)
4999 stop_reply_queue
= reply
->next
;
5001 prev
->next
= reply
->next
;
5003 stop_reply_xfree (reply
);
5010 /* Cleanup wrapper. */
5013 do_stop_reply_xfree (void *arg
)
5015 struct stop_reply
*r
= arg
;
5017 stop_reply_xfree (r
);
5020 /* Look for a queued stop reply belonging to PTID. If one is found,
5021 remove it from the queue, and return it. Returns NULL if none is
5022 found. If there are still queued events left to process, tell the
5023 event loop to get back to target_wait soon. */
5025 static struct stop_reply
*
5026 queued_stop_reply (ptid_t ptid
)
5028 struct stop_reply
*it
;
5029 struct stop_reply
**it_link
;
5031 it
= stop_reply_queue
;
5032 it_link
= &stop_reply_queue
;
5035 if (ptid_match (it
->ptid
, ptid
))
5037 *it_link
= it
->next
;
5042 it_link
= &it
->next
;
5046 if (stop_reply_queue
)
5047 /* There's still at least an event left. */
5048 mark_async_event_handler (remote_async_inferior_event_token
);
5053 /* Push a fully parsed stop reply in the stop reply queue. Since we
5054 know that we now have at least one queued event left to pass to the
5055 core side, tell the event loop to get back to target_wait soon. */
5058 push_stop_reply (struct stop_reply
*new_event
)
5060 struct stop_reply
*event
;
5062 if (stop_reply_queue
)
5064 for (event
= stop_reply_queue
;
5065 event
&& event
->next
;
5066 event
= event
->next
)
5069 event
->next
= new_event
;
5072 stop_reply_queue
= new_event
;
5074 mark_async_event_handler (remote_async_inferior_event_token
);
5077 /* Returns true if we have a stop reply for PTID. */
5080 peek_stop_reply (ptid_t ptid
)
5082 struct stop_reply
*it
;
5084 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5085 if (ptid_equal (ptid
, it
->ptid
))
5087 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5094 /* Parse the stop reply in BUF. Either the function succeeds, and the
5095 result is stored in EVENT, or throws an error. */
5098 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5100 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5104 event
->ptid
= null_ptid
;
5105 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5106 event
->ws
.value
.integer
= 0;
5107 event
->solibs_changed
= 0;
5108 event
->replay_event
= 0;
5109 event
->stopped_by_watchpoint_p
= 0;
5110 event
->regcache
= NULL
;
5115 case 'T': /* Status with PC, SP, FP, ... */
5116 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5117 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5119 n... = register number
5120 r... = register contents
5123 p
= &buf
[3]; /* after Txx */
5131 /* If the packet contains a register number, save it in
5132 pnum and set p1 to point to the character following it.
5133 Otherwise p1 points to p. */
5135 /* If this packet is an awatch packet, don't parse the 'a'
5136 as a register number. */
5138 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5139 && strncmp (p
, "core", strlen ("core") != 0))
5141 /* Read the ``P'' register number. */
5142 pnum
= strtol (p
, &p_temp
, 16);
5148 if (p1
== p
) /* No register number present here. */
5150 p1
= strchr (p
, ':');
5152 error (_("Malformed packet(a) (missing colon): %s\n\
5155 if (strncmp (p
, "thread", p1
- p
) == 0)
5156 event
->ptid
= read_ptid (++p1
, &p
);
5157 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5158 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5159 || (strncmp (p
, "awatch", p1
- p
) == 0))
5161 event
->stopped_by_watchpoint_p
= 1;
5162 p
= unpack_varlen_hex (++p1
, &addr
);
5163 event
->watch_data_address
= (CORE_ADDR
) addr
;
5165 else if (strncmp (p
, "library", p1
- p
) == 0)
5169 while (*p_temp
&& *p_temp
!= ';')
5172 event
->solibs_changed
= 1;
5175 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5177 /* NO_HISTORY event.
5178 p1 will indicate "begin" or "end", but
5179 it makes no difference for now, so ignore it. */
5180 event
->replay_event
= 1;
5181 p_temp
= strchr (p1
+ 1, ';');
5185 else if (strncmp (p
, "core", p1
- p
) == 0)
5189 p
= unpack_varlen_hex (++p1
, &c
);
5194 /* Silently skip unknown optional info. */
5195 p_temp
= strchr (p1
+ 1, ';');
5202 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5203 cached_reg_t cached_reg
;
5208 error (_("Malformed packet(b) (missing colon): %s\n\
5214 error (_("Remote sent bad register number %s: %s\n\
5216 hex_string (pnum
), p
, buf
);
5218 cached_reg
.num
= reg
->regnum
;
5220 fieldsize
= hex2bin (p
, cached_reg
.data
,
5221 register_size (target_gdbarch
,
5224 if (fieldsize
< register_size (target_gdbarch
,
5226 warning (_("Remote reply is too short: %s"), buf
);
5228 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5232 error (_("Remote register badly formatted: %s\nhere: %s"),
5237 case 'S': /* Old style status, just signal only. */
5238 if (event
->solibs_changed
)
5239 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5240 else if (event
->replay_event
)
5241 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5244 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5245 event
->ws
.value
.sig
= (enum target_signal
)
5246 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5249 case 'W': /* Target exited. */
5256 /* GDB used to accept only 2 hex chars here. Stubs should
5257 only send more if they detect GDB supports multi-process
5259 p
= unpack_varlen_hex (&buf
[1], &value
);
5263 /* The remote process exited. */
5264 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5265 event
->ws
.value
.integer
= value
;
5269 /* The remote process exited with a signal. */
5270 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5271 event
->ws
.value
.sig
= (enum target_signal
) value
;
5274 /* If no process is specified, assume inferior_ptid. */
5275 pid
= ptid_get_pid (inferior_ptid
);
5284 else if (strncmp (p
,
5285 "process:", sizeof ("process:") - 1) == 0)
5289 p
+= sizeof ("process:") - 1;
5290 unpack_varlen_hex (p
, &upid
);
5294 error (_("unknown stop reply packet: %s"), buf
);
5297 error (_("unknown stop reply packet: %s"), buf
);
5298 event
->ptid
= pid_to_ptid (pid
);
5303 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5304 error (_("No process or thread specified in stop reply: %s"), buf
);
5307 /* When the stub wants to tell GDB about a new stop reply, it sends a
5308 stop notification (%Stop). Those can come it at any time, hence,
5309 we have to make sure that any pending putpkt/getpkt sequence we're
5310 making is finished, before querying the stub for more events with
5311 vStopped. E.g., if we started a vStopped sequence immediatelly
5312 upon receiving the %Stop notification, something like this could
5320 1.6) <-- (registers reply to step #1.3)
5322 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5325 To solve this, whenever we parse a %Stop notification sucessfully,
5326 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5327 doing whatever we were doing:
5333 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5334 2.5) <-- (registers reply to step #2.3)
5336 Eventualy after step #2.5, we return to the event loop, which
5337 notices there's an event on the
5338 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5339 associated callback --- the function below. At this point, we're
5340 always safe to start a vStopped sequence. :
5343 2.7) <-- T05 thread:2
5349 remote_get_pending_stop_replies (void)
5351 struct remote_state
*rs
= get_remote_state ();
5353 if (pending_stop_reply
)
5356 putpkt ("vStopped");
5358 /* Now we can rely on it. */
5359 push_stop_reply (pending_stop_reply
);
5360 pending_stop_reply
= NULL
;
5364 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5365 if (strcmp (rs
->buf
, "OK") == 0)
5369 struct cleanup
*old_chain
;
5370 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5372 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5373 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5376 putpkt ("vStopped");
5378 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5380 /* Now we can rely on it. */
5381 discard_cleanups (old_chain
);
5382 push_stop_reply (stop_reply
);
5385 /* We got an unknown stop reply. */
5386 do_cleanups (old_chain
);
5393 /* Called when it is decided that STOP_REPLY holds the info of the
5394 event that is to be returned to the core. This function always
5395 destroys STOP_REPLY. */
5398 process_stop_reply (struct stop_reply
*stop_reply
,
5399 struct target_waitstatus
*status
)
5403 *status
= stop_reply
->ws
;
5404 ptid
= stop_reply
->ptid
;
5406 /* If no thread/process was reported by the stub, assume the current
5408 if (ptid_equal (ptid
, null_ptid
))
5409 ptid
= inferior_ptid
;
5411 if (status
->kind
!= TARGET_WAITKIND_EXITED
5412 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5414 /* Expedited registers. */
5415 if (stop_reply
->regcache
)
5417 struct regcache
*regcache
5418 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5423 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5425 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5426 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5429 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5430 remote_watch_data_address
= stop_reply
->watch_data_address
;
5432 remote_notice_new_inferior (ptid
, 0);
5433 demand_private_info (ptid
)->core
= stop_reply
->core
;
5436 stop_reply_xfree (stop_reply
);
5440 /* The non-stop mode version of target_wait. */
5443 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5445 struct remote_state
*rs
= get_remote_state ();
5446 struct stop_reply
*stop_reply
;
5449 /* If in non-stop mode, get out of getpkt even if a
5450 notification is received. */
5452 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5459 case 'E': /* Error of some sort. */
5460 /* We're out of sync with the target now. Did it continue
5461 or not? We can't tell which thread it was in non-stop,
5462 so just ignore this. */
5463 warning (_("Remote failure reply: %s"), rs
->buf
);
5465 case 'O': /* Console output. */
5466 remote_console_output (rs
->buf
+ 1);
5469 warning (_("Invalid remote reply: %s"), rs
->buf
);
5473 /* Acknowledge a pending stop reply that may have arrived in the
5475 if (pending_stop_reply
!= NULL
)
5476 remote_get_pending_stop_replies ();
5478 /* If indeed we noticed a stop reply, we're done. */
5479 stop_reply
= queued_stop_reply (ptid
);
5480 if (stop_reply
!= NULL
)
5481 return process_stop_reply (stop_reply
, status
);
5483 /* Still no event. If we're just polling for an event, then
5484 return to the event loop. */
5485 if (options
& TARGET_WNOHANG
)
5487 status
->kind
= TARGET_WAITKIND_IGNORE
;
5488 return minus_one_ptid
;
5491 /* Otherwise do a blocking wait. */
5492 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5497 /* Wait until the remote machine stops, then return, storing status in
5498 STATUS just as `wait' would. */
5501 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5503 struct remote_state
*rs
= get_remote_state ();
5504 ptid_t event_ptid
= null_ptid
;
5506 struct stop_reply
*stop_reply
;
5510 status
->kind
= TARGET_WAITKIND_IGNORE
;
5511 status
->value
.integer
= 0;
5513 stop_reply
= queued_stop_reply (ptid
);
5514 if (stop_reply
!= NULL
)
5515 return process_stop_reply (stop_reply
, status
);
5517 if (rs
->cached_wait_status
)
5518 /* Use the cached wait status, but only once. */
5519 rs
->cached_wait_status
= 0;
5524 if (!target_is_async_p ())
5526 ofunc
= signal (SIGINT
, remote_interrupt
);
5527 /* If the user hit C-c before this packet, or between packets,
5528 pretend that it was hit right here. */
5532 remote_interrupt (SIGINT
);
5536 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5537 _never_ wait for ever -> test on target_is_async_p().
5538 However, before we do that we need to ensure that the caller
5539 knows how to take the target into/out of async mode. */
5540 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5541 if (!target_is_async_p ())
5542 signal (SIGINT
, ofunc
);
5547 remote_stopped_by_watchpoint_p
= 0;
5549 /* We got something. */
5550 rs
->waiting_for_stop_reply
= 0;
5552 /* Assume that the target has acknowledged Ctrl-C unless we receive
5553 an 'F' or 'O' packet. */
5554 if (buf
[0] != 'F' && buf
[0] != 'O')
5555 rs
->ctrlc_pending_p
= 0;
5559 case 'E': /* Error of some sort. */
5560 /* We're out of sync with the target now. Did it continue or
5561 not? Not is more likely, so report a stop. */
5562 warning (_("Remote failure reply: %s"), buf
);
5563 status
->kind
= TARGET_WAITKIND_STOPPED
;
5564 status
->value
.sig
= TARGET_SIGNAL_0
;
5566 case 'F': /* File-I/O request. */
5567 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5568 rs
->ctrlc_pending_p
= 0;
5570 case 'T': case 'S': case 'X': case 'W':
5572 struct stop_reply
*stop_reply
;
5573 struct cleanup
*old_chain
;
5575 stop_reply
= stop_reply_xmalloc ();
5576 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5577 remote_parse_stop_reply (buf
, stop_reply
);
5578 discard_cleanups (old_chain
);
5579 event_ptid
= process_stop_reply (stop_reply
, status
);
5582 case 'O': /* Console output. */
5583 remote_console_output (buf
+ 1);
5585 /* The target didn't really stop; keep waiting. */
5586 rs
->waiting_for_stop_reply
= 1;
5590 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5592 /* Zero length reply means that we tried 'S' or 'C' and the
5593 remote system doesn't support it. */
5594 target_terminal_ours_for_output ();
5596 ("Can't send signals to this remote system. %s not sent.\n",
5597 target_signal_to_name (last_sent_signal
));
5598 last_sent_signal
= TARGET_SIGNAL_0
;
5599 target_terminal_inferior ();
5601 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5602 putpkt ((char *) buf
);
5604 /* We just told the target to resume, so a stop reply is in
5606 rs
->waiting_for_stop_reply
= 1;
5609 /* else fallthrough */
5611 warning (_("Invalid remote reply: %s"), buf
);
5613 rs
->waiting_for_stop_reply
= 1;
5617 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5619 /* Nothing interesting happened. If we're doing a non-blocking
5620 poll, we're done. Otherwise, go back to waiting. */
5621 if (options
& TARGET_WNOHANG
)
5622 return minus_one_ptid
;
5626 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5627 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5629 if (!ptid_equal (event_ptid
, null_ptid
))
5630 record_currthread (event_ptid
);
5632 event_ptid
= inferior_ptid
;
5635 /* A process exit. Invalidate our notion of current thread. */
5636 record_currthread (minus_one_ptid
);
5641 /* Wait until the remote machine stops, then return, storing status in
5642 STATUS just as `wait' would. */
5645 remote_wait (struct target_ops
*ops
,
5646 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5651 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5653 event_ptid
= remote_wait_as (ptid
, status
, options
);
5655 if (target_can_async_p ())
5657 /* If there are are events left in the queue tell the event loop
5659 if (stop_reply_queue
)
5660 mark_async_event_handler (remote_async_inferior_event_token
);
5666 /* Fetch a single register using a 'p' packet. */
5669 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5671 struct remote_state
*rs
= get_remote_state ();
5673 char regp
[MAX_REGISTER_SIZE
];
5676 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5679 if (reg
->pnum
== -1)
5684 p
+= hexnumstr (p
, reg
->pnum
);
5687 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5691 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5695 case PACKET_UNKNOWN
:
5698 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5699 gdbarch_register_name (get_regcache_arch (regcache
),
5704 /* If this register is unfetchable, tell the regcache. */
5707 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5711 /* Otherwise, parse and supply the value. */
5717 error (_("fetch_register_using_p: early buf termination"));
5719 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5722 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5726 /* Fetch the registers included in the target's 'g' packet. */
5729 send_g_packet (void)
5731 struct remote_state
*rs
= get_remote_state ();
5734 sprintf (rs
->buf
, "g");
5735 remote_send (&rs
->buf
, &rs
->buf_size
);
5737 /* We can get out of synch in various cases. If the first character
5738 in the buffer is not a hex character, assume that has happened
5739 and try to fetch another packet to read. */
5740 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5741 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5742 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5743 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5746 fprintf_unfiltered (gdb_stdlog
,
5747 "Bad register packet; fetching a new packet\n");
5748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5751 buf_len
= strlen (rs
->buf
);
5753 /* Sanity check the received packet. */
5754 if (buf_len
% 2 != 0)
5755 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5761 process_g_packet (struct regcache
*regcache
)
5763 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5764 struct remote_state
*rs
= get_remote_state ();
5765 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5770 buf_len
= strlen (rs
->buf
);
5772 /* Further sanity checks, with knowledge of the architecture. */
5773 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5774 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5776 /* Save the size of the packet sent to us by the target. It is used
5777 as a heuristic when determining the max size of packets that the
5778 target can safely receive. */
5779 if (rsa
->actual_register_packet_size
== 0)
5780 rsa
->actual_register_packet_size
= buf_len
;
5782 /* If this is smaller than we guessed the 'g' packet would be,
5783 update our records. A 'g' reply that doesn't include a register's
5784 value implies either that the register is not available, or that
5785 the 'p' packet must be used. */
5786 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5788 rsa
->sizeof_g_packet
= buf_len
/ 2;
5790 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5792 if (rsa
->regs
[i
].pnum
== -1)
5795 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5796 rsa
->regs
[i
].in_g_packet
= 0;
5798 rsa
->regs
[i
].in_g_packet
= 1;
5802 regs
= alloca (rsa
->sizeof_g_packet
);
5804 /* Unimplemented registers read as all bits zero. */
5805 memset (regs
, 0, rsa
->sizeof_g_packet
);
5807 /* Reply describes registers byte by byte, each byte encoded as two
5808 hex characters. Suck them all up, then supply them to the
5809 register cacheing/storage mechanism. */
5812 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5814 if (p
[0] == 0 || p
[1] == 0)
5815 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5816 internal_error (__FILE__
, __LINE__
,
5817 _("unexpected end of 'g' packet reply"));
5819 if (p
[0] == 'x' && p
[1] == 'x')
5820 regs
[i
] = 0; /* 'x' */
5822 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5826 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5828 struct packet_reg
*r
= &rsa
->regs
[i
];
5832 if (r
->offset
* 2 >= strlen (rs
->buf
))
5833 /* This shouldn't happen - we adjusted in_g_packet above. */
5834 internal_error (__FILE__
, __LINE__
,
5835 _("unexpected end of 'g' packet reply"));
5836 else if (rs
->buf
[r
->offset
* 2] == 'x')
5838 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5839 /* The register isn't available, mark it as such (at
5840 the same time setting the value to zero). */
5841 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5844 regcache_raw_supply (regcache
, r
->regnum
,
5851 fetch_registers_using_g (struct regcache
*regcache
)
5854 process_g_packet (regcache
);
5857 /* Make the remote selected traceframe match GDB's selected
5861 set_remote_traceframe (void)
5865 if (remote_traceframe_number
== get_traceframe_number ())
5868 /* Avoid recursion, remote_trace_find calls us again. */
5869 remote_traceframe_number
= get_traceframe_number ();
5871 newnum
= target_trace_find (tfind_number
,
5872 get_traceframe_number (), 0, 0, NULL
);
5874 /* Should not happen. If it does, all bets are off. */
5875 if (newnum
!= get_traceframe_number ())
5876 warning (_("could not set remote traceframe"));
5880 remote_fetch_registers (struct target_ops
*ops
,
5881 struct regcache
*regcache
, int regnum
)
5883 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5886 set_remote_traceframe ();
5887 set_general_thread (inferior_ptid
);
5891 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5893 gdb_assert (reg
!= NULL
);
5895 /* If this register might be in the 'g' packet, try that first -
5896 we are likely to read more than one register. If this is the
5897 first 'g' packet, we might be overly optimistic about its
5898 contents, so fall back to 'p'. */
5899 if (reg
->in_g_packet
)
5901 fetch_registers_using_g (regcache
);
5902 if (reg
->in_g_packet
)
5906 if (fetch_register_using_p (regcache
, reg
))
5909 /* This register is not available. */
5910 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5915 fetch_registers_using_g (regcache
);
5917 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5918 if (!rsa
->regs
[i
].in_g_packet
)
5919 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5921 /* This register is not available. */
5922 regcache_raw_supply (regcache
, i
, NULL
);
5926 /* Prepare to store registers. Since we may send them all (using a
5927 'G' request), we have to read out the ones we don't want to change
5931 remote_prepare_to_store (struct regcache
*regcache
)
5933 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5935 gdb_byte buf
[MAX_REGISTER_SIZE
];
5937 /* Make sure the entire registers array is valid. */
5938 switch (remote_protocol_packets
[PACKET_P
].support
)
5940 case PACKET_DISABLE
:
5941 case PACKET_SUPPORT_UNKNOWN
:
5942 /* Make sure all the necessary registers are cached. */
5943 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5944 if (rsa
->regs
[i
].in_g_packet
)
5945 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5952 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5953 packet was not recognized. */
5956 store_register_using_P (const struct regcache
*regcache
,
5957 struct packet_reg
*reg
)
5959 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5960 struct remote_state
*rs
= get_remote_state ();
5961 /* Try storing a single register. */
5962 char *buf
= rs
->buf
;
5963 gdb_byte regp
[MAX_REGISTER_SIZE
];
5966 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5969 if (reg
->pnum
== -1)
5972 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5973 p
= buf
+ strlen (buf
);
5974 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5975 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5977 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5979 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5984 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5985 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5986 case PACKET_UNKNOWN
:
5989 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5993 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5994 contents of the register cache buffer. FIXME: ignores errors. */
5997 store_registers_using_G (const struct regcache
*regcache
)
5999 struct remote_state
*rs
= get_remote_state ();
6000 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6004 /* Extract all the registers in the regcache copying them into a
6009 regs
= alloca (rsa
->sizeof_g_packet
);
6010 memset (regs
, 0, rsa
->sizeof_g_packet
);
6011 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6013 struct packet_reg
*r
= &rsa
->regs
[i
];
6016 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6020 /* Command describes registers byte by byte,
6021 each byte encoded as two hex characters. */
6024 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6026 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6029 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6030 error (_("Could not write registers; remote failure reply '%s'"),
6034 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6035 of the register cache buffer. FIXME: ignores errors. */
6038 remote_store_registers (struct target_ops
*ops
,
6039 struct regcache
*regcache
, int regnum
)
6041 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6044 set_remote_traceframe ();
6045 set_general_thread (inferior_ptid
);
6049 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6051 gdb_assert (reg
!= NULL
);
6053 /* Always prefer to store registers using the 'P' packet if
6054 possible; we often change only a small number of registers.
6055 Sometimes we change a larger number; we'd need help from a
6056 higher layer to know to use 'G'. */
6057 if (store_register_using_P (regcache
, reg
))
6060 /* For now, don't complain if we have no way to write the
6061 register. GDB loses track of unavailable registers too
6062 easily. Some day, this may be an error. We don't have
6063 any way to read the register, either... */
6064 if (!reg
->in_g_packet
)
6067 store_registers_using_G (regcache
);
6071 store_registers_using_G (regcache
);
6073 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6074 if (!rsa
->regs
[i
].in_g_packet
)
6075 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6076 /* See above for why we do not issue an error here. */
6081 /* Return the number of hex digits in num. */
6084 hexnumlen (ULONGEST num
)
6088 for (i
= 0; num
!= 0; i
++)
6094 /* Set BUF to the minimum number of hex digits representing NUM. */
6097 hexnumstr (char *buf
, ULONGEST num
)
6099 int len
= hexnumlen (num
);
6101 return hexnumnstr (buf
, num
, len
);
6105 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6108 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6114 for (i
= width
- 1; i
>= 0; i
--)
6116 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6123 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6126 remote_address_masked (CORE_ADDR addr
)
6128 int address_size
= remote_address_size
;
6130 /* If "remoteaddresssize" was not set, default to target address size. */
6132 address_size
= gdbarch_addr_bit (target_gdbarch
);
6134 if (address_size
> 0
6135 && address_size
< (sizeof (ULONGEST
) * 8))
6137 /* Only create a mask when that mask can safely be constructed
6138 in a ULONGEST variable. */
6141 mask
= (mask
<< address_size
) - 1;
6147 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6148 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6149 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6150 (which may be more than *OUT_LEN due to escape characters). The
6151 total number of bytes in the output buffer will be at most
6155 remote_escape_output (const gdb_byte
*buffer
, int len
,
6156 gdb_byte
*out_buf
, int *out_len
,
6159 int input_index
, output_index
;
6162 for (input_index
= 0; input_index
< len
; input_index
++)
6164 gdb_byte b
= buffer
[input_index
];
6166 if (b
== '$' || b
== '#' || b
== '}')
6168 /* These must be escaped. */
6169 if (output_index
+ 2 > out_maxlen
)
6171 out_buf
[output_index
++] = '}';
6172 out_buf
[output_index
++] = b
^ 0x20;
6176 if (output_index
+ 1 > out_maxlen
)
6178 out_buf
[output_index
++] = b
;
6182 *out_len
= input_index
;
6183 return output_index
;
6186 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6187 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6188 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6190 This function reverses remote_escape_output. It allows more
6191 escaped characters than that function does, in particular because
6192 '*' must be escaped to avoid the run-length encoding processing
6193 in reading packets. */
6196 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6197 gdb_byte
*out_buf
, int out_maxlen
)
6199 int input_index
, output_index
;
6204 for (input_index
= 0; input_index
< len
; input_index
++)
6206 gdb_byte b
= buffer
[input_index
];
6208 if (output_index
+ 1 > out_maxlen
)
6210 warning (_("Received too much data from remote target;"
6211 " ignoring overflow."));
6212 return output_index
;
6217 out_buf
[output_index
++] = b
^ 0x20;
6223 out_buf
[output_index
++] = b
;
6227 error (_("Unmatched escape character in target response."));
6229 return output_index
;
6232 /* Determine whether the remote target supports binary downloading.
6233 This is accomplished by sending a no-op memory write of zero length
6234 to the target at the specified address. It does not suffice to send
6235 the whole packet, since many stubs strip the eighth bit and
6236 subsequently compute a wrong checksum, which causes real havoc with
6239 NOTE: This can still lose if the serial line is not eight-bit
6240 clean. In cases like this, the user should clear "remote
6244 check_binary_download (CORE_ADDR addr
)
6246 struct remote_state
*rs
= get_remote_state ();
6248 switch (remote_protocol_packets
[PACKET_X
].support
)
6250 case PACKET_DISABLE
:
6254 case PACKET_SUPPORT_UNKNOWN
:
6260 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6262 p
+= hexnumstr (p
, (ULONGEST
) 0);
6266 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6267 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6269 if (rs
->buf
[0] == '\0')
6272 fprintf_unfiltered (gdb_stdlog
,
6273 "binary downloading NOT "
6274 "supported by target\n");
6275 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6280 fprintf_unfiltered (gdb_stdlog
,
6281 "binary downloading supported by target\n");
6282 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6289 /* Write memory data directly to the remote machine.
6290 This does not inform the data cache; the data cache uses this.
6291 HEADER is the starting part of the packet.
6292 MEMADDR is the address in the remote memory space.
6293 MYADDR is the address of the buffer in our space.
6294 LEN is the number of bytes.
6295 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6296 should send data as binary ('X'), or hex-encoded ('M').
6298 The function creates packet of the form
6299 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6301 where encoding of <DATA> is termined by PACKET_FORMAT.
6303 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6306 Returns the number of bytes transferred, or 0 (setting errno) for
6307 error. Only transfer a single packet. */
6310 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6311 const gdb_byte
*myaddr
, int len
,
6312 char packet_format
, int use_length
)
6314 struct remote_state
*rs
= get_remote_state ();
6324 if (packet_format
!= 'X' && packet_format
!= 'M')
6325 internal_error (__FILE__
, __LINE__
,
6326 _("remote_write_bytes_aux: bad packet format"));
6331 payload_size
= get_memory_write_packet_size ();
6333 /* The packet buffer will be large enough for the payload;
6334 get_memory_packet_size ensures this. */
6337 /* Compute the size of the actual payload by subtracting out the
6338 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6340 payload_size
-= strlen ("$,:#NN");
6342 /* The comma won't be used. */
6344 header_length
= strlen (header
);
6345 payload_size
-= header_length
;
6346 payload_size
-= hexnumlen (memaddr
);
6348 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6350 strcat (rs
->buf
, header
);
6351 p
= rs
->buf
+ strlen (header
);
6353 /* Compute a best guess of the number of bytes actually transfered. */
6354 if (packet_format
== 'X')
6356 /* Best guess at number of bytes that will fit. */
6357 todo
= min (len
, payload_size
);
6359 payload_size
-= hexnumlen (todo
);
6360 todo
= min (todo
, payload_size
);
6364 /* Num bytes that will fit. */
6365 todo
= min (len
, payload_size
/ 2);
6367 payload_size
-= hexnumlen (todo
);
6368 todo
= min (todo
, payload_size
/ 2);
6372 internal_error (__FILE__
, __LINE__
,
6373 _("minimum packet size too small to write data"));
6375 /* If we already need another packet, then try to align the end
6376 of this packet to a useful boundary. */
6377 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6378 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6380 /* Append "<memaddr>". */
6381 memaddr
= remote_address_masked (memaddr
);
6382 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6389 /* Append <len>. Retain the location/size of <len>. It may need to
6390 be adjusted once the packet body has been created. */
6392 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6400 /* Append the packet body. */
6401 if (packet_format
== 'X')
6403 /* Binary mode. Send target system values byte by byte, in
6404 increasing byte addresses. Only escape certain critical
6406 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6409 /* If not all TODO bytes fit, then we'll need another packet. Make
6410 a second try to keep the end of the packet aligned. Don't do
6411 this if the packet is tiny. */
6412 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6416 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6418 if (new_nr_bytes
!= nr_bytes
)
6419 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6424 p
+= payload_length
;
6425 if (use_length
&& nr_bytes
< todo
)
6427 /* Escape chars have filled up the buffer prematurely,
6428 and we have actually sent fewer bytes than planned.
6429 Fix-up the length field of the packet. Use the same
6430 number of characters as before. */
6431 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6432 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6437 /* Normal mode: Send target system values byte by byte, in
6438 increasing byte addresses. Each byte is encoded as a two hex
6440 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6444 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6445 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6447 if (rs
->buf
[0] == 'E')
6449 /* There is no correspondance between what the remote protocol
6450 uses for errors and errno codes. We would like a cleaner way
6451 of representing errors (big enough to include errno codes,
6452 bfd_error codes, and others). But for now just return EIO. */
6457 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6458 fewer bytes than we'd planned. */
6462 /* Write memory data directly to the remote machine.
6463 This does not inform the data cache; the data cache uses this.
6464 MEMADDR is the address in the remote memory space.
6465 MYADDR is the address of the buffer in our space.
6466 LEN is the number of bytes.
6468 Returns number of bytes transferred, or 0 (setting errno) for
6469 error. Only transfer a single packet. */
6472 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6474 char *packet_format
= 0;
6476 /* Check whether the target supports binary download. */
6477 check_binary_download (memaddr
);
6479 switch (remote_protocol_packets
[PACKET_X
].support
)
6482 packet_format
= "X";
6484 case PACKET_DISABLE
:
6485 packet_format
= "M";
6487 case PACKET_SUPPORT_UNKNOWN
:
6488 internal_error (__FILE__
, __LINE__
,
6489 _("remote_write_bytes: bad internal state"));
6491 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6494 return remote_write_bytes_aux (packet_format
,
6495 memaddr
, myaddr
, len
, packet_format
[0], 1);
6498 /* Read memory data directly from the remote machine.
6499 This does not use the data cache; the data cache uses this.
6500 MEMADDR is the address in the remote memory space.
6501 MYADDR is the address of the buffer in our space.
6502 LEN is the number of bytes.
6504 Returns number of bytes transferred, or 0 for error. */
6507 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6509 struct remote_state
*rs
= get_remote_state ();
6510 int max_buf_size
; /* Max size of packet output buffer. */
6518 max_buf_size
= get_memory_read_packet_size ();
6519 /* The packet buffer will be large enough for the payload;
6520 get_memory_packet_size ensures this. */
6522 /* Number if bytes that will fit. */
6523 todo
= min (len
, max_buf_size
/ 2);
6525 /* Construct "m"<memaddr>","<len>". */
6526 memaddr
= remote_address_masked (memaddr
);
6529 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6531 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6534 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6535 if (rs
->buf
[0] == 'E'
6536 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6537 && rs
->buf
[3] == '\0')
6539 /* There is no correspondance between what the remote protocol
6540 uses for errors and errno codes. We would like a cleaner way
6541 of representing errors (big enough to include errno codes,
6542 bfd_error codes, and others). But for now just return
6547 /* Reply describes memory byte by byte, each byte encoded as two hex
6550 i
= hex2bin (p
, myaddr
, todo
);
6551 /* Return what we have. Let higher layers handle partial reads. */
6556 /* Remote notification handler. */
6559 handle_notification (char *buf
, size_t length
)
6561 if (strncmp (buf
, "Stop:", 5) == 0)
6563 if (pending_stop_reply
)
6565 /* We've already parsed the in-flight stop-reply, but the
6566 stub for some reason thought we didn't, possibly due to
6567 timeout on its side. Just ignore it. */
6569 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6573 struct cleanup
*old_chain
;
6574 struct stop_reply
*reply
= stop_reply_xmalloc ();
6576 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6578 remote_parse_stop_reply (buf
+ 5, reply
);
6580 discard_cleanups (old_chain
);
6582 /* Be careful to only set it after parsing, since an error
6583 may be thrown then. */
6584 pending_stop_reply
= reply
;
6586 /* Notify the event loop there's a stop reply to acknowledge
6587 and that there may be more events to fetch. */
6588 mark_async_event_handler (remote_async_get_pending_events_token
);
6591 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6595 /* We ignore notifications we don't recognize, for compatibility
6596 with newer stubs. */
6601 /* Read or write LEN bytes from inferior memory at MEMADDR,
6602 transferring to or from debugger address BUFFER. Write to inferior
6603 if SHOULD_WRITE is nonzero. Returns length of data written or
6604 read; 0 for error. TARGET is unused. */
6607 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6608 int should_write
, struct mem_attrib
*attrib
,
6609 struct target_ops
*target
)
6613 set_remote_traceframe ();
6614 set_general_thread (inferior_ptid
);
6617 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6619 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6624 /* Sends a packet with content determined by the printf format string
6625 FORMAT and the remaining arguments, then gets the reply. Returns
6626 whether the packet was a success, a failure, or unknown. */
6628 static enum packet_result
6629 remote_send_printf (const char *format
, ...)
6631 struct remote_state
*rs
= get_remote_state ();
6632 int max_size
= get_remote_packet_size ();
6635 va_start (ap
, format
);
6638 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6639 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6641 if (putpkt (rs
->buf
) < 0)
6642 error (_("Communication problem with target."));
6645 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6647 return packet_check_result (rs
->buf
);
6651 restore_remote_timeout (void *p
)
6653 int value
= *(int *)p
;
6655 remote_timeout
= value
;
6658 /* Flash writing can take quite some time. We'll set
6659 effectively infinite timeout for flash operations.
6660 In future, we'll need to decide on a better approach. */
6661 static const int remote_flash_timeout
= 1000;
6664 remote_flash_erase (struct target_ops
*ops
,
6665 ULONGEST address
, LONGEST length
)
6667 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6668 int saved_remote_timeout
= remote_timeout
;
6669 enum packet_result ret
;
6670 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6671 &saved_remote_timeout
);
6673 remote_timeout
= remote_flash_timeout
;
6675 ret
= remote_send_printf ("vFlashErase:%s,%s",
6676 phex (address
, addr_size
),
6680 case PACKET_UNKNOWN
:
6681 error (_("Remote target does not support flash erase"));
6683 error (_("Error erasing flash with vFlashErase packet"));
6688 do_cleanups (back_to
);
6692 remote_flash_write (struct target_ops
*ops
,
6693 ULONGEST address
, LONGEST length
,
6694 const gdb_byte
*data
)
6696 int saved_remote_timeout
= remote_timeout
;
6698 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6699 &saved_remote_timeout
);
6701 remote_timeout
= remote_flash_timeout
;
6702 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6703 do_cleanups (back_to
);
6709 remote_flash_done (struct target_ops
*ops
)
6711 int saved_remote_timeout
= remote_timeout
;
6713 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6714 &saved_remote_timeout
);
6716 remote_timeout
= remote_flash_timeout
;
6717 ret
= remote_send_printf ("vFlashDone");
6718 do_cleanups (back_to
);
6722 case PACKET_UNKNOWN
:
6723 error (_("Remote target does not support vFlashDone"));
6725 error (_("Error finishing flash operation"));
6732 remote_files_info (struct target_ops
*ignore
)
6734 puts_filtered ("Debugging a target over a serial line.\n");
6737 /* Stuff for dealing with the packets which are part of this protocol.
6738 See comment at top of file for details. */
6740 /* Read a single character from the remote end. */
6743 readchar (int timeout
)
6747 ch
= serial_readchar (remote_desc
, timeout
);
6752 switch ((enum serial_rc
) ch
)
6756 error (_("Remote connection closed"));
6760 perror_with_name (_("Remote communication error. "
6761 "Target disconnected."));
6763 case SERIAL_TIMEOUT
:
6769 /* Send the command in *BUF to the remote machine, and read the reply
6770 into *BUF. Report an error if we get an error reply. Resize
6771 *BUF using xrealloc if necessary to hold the result, and update
6775 remote_send (char **buf
,
6779 getpkt (buf
, sizeof_buf
, 0);
6781 if ((*buf
)[0] == 'E')
6782 error (_("Remote failure reply: %s"), *buf
);
6785 /* Return a pointer to an xmalloc'ed string representing an escaped
6786 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6787 etc. The caller is responsible for releasing the returned
6791 escape_buffer (const char *buf
, int n
)
6793 struct cleanup
*old_chain
;
6794 struct ui_file
*stb
;
6797 stb
= mem_fileopen ();
6798 old_chain
= make_cleanup_ui_file_delete (stb
);
6800 fputstrn_unfiltered (buf
, n
, 0, stb
);
6801 str
= ui_file_xstrdup (stb
, NULL
);
6802 do_cleanups (old_chain
);
6806 /* Display a null-terminated packet on stdout, for debugging, using C
6810 print_packet (char *buf
)
6812 puts_filtered ("\"");
6813 fputstr_filtered (buf
, '"', gdb_stdout
);
6814 puts_filtered ("\"");
6820 return putpkt_binary (buf
, strlen (buf
));
6823 /* Send a packet to the remote machine, with error checking. The data
6824 of the packet is in BUF. The string in BUF can be at most
6825 get_remote_packet_size () - 5 to account for the $, # and checksum,
6826 and for a possible /0 if we are debugging (remote_debug) and want
6827 to print the sent packet as a string. */
6830 putpkt_binary (char *buf
, int cnt
)
6832 struct remote_state
*rs
= get_remote_state ();
6834 unsigned char csum
= 0;
6835 char *buf2
= alloca (cnt
+ 6);
6841 /* Catch cases like trying to read memory or listing threads while
6842 we're waiting for a stop reply. The remote server wouldn't be
6843 ready to handle this request, so we'd hang and timeout. We don't
6844 have to worry about this in synchronous mode, because in that
6845 case it's not possible to issue a command while the target is
6846 running. This is not a problem in non-stop mode, because in that
6847 case, the stub is always ready to process serial input. */
6848 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6849 error (_("Cannot execute this command while the target is running."));
6851 /* We're sending out a new packet. Make sure we don't look at a
6852 stale cached response. */
6853 rs
->cached_wait_status
= 0;
6855 /* Copy the packet into buffer BUF2, encapsulating it
6856 and giving it a checksum. */
6861 for (i
= 0; i
< cnt
; i
++)
6867 *p
++ = tohex ((csum
>> 4) & 0xf);
6868 *p
++ = tohex (csum
& 0xf);
6870 /* Send it over and over until we get a positive ack. */
6874 int started_error_output
= 0;
6878 struct cleanup
*old_chain
;
6882 str
= escape_buffer (buf2
, p
- buf2
);
6883 old_chain
= make_cleanup (xfree
, str
);
6884 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6885 gdb_flush (gdb_stdlog
);
6886 do_cleanups (old_chain
);
6888 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6889 perror_with_name (_("putpkt: write failed"));
6891 /* If this is a no acks version of the remote protocol, send the
6892 packet and move on. */
6896 /* Read until either a timeout occurs (-2) or '+' is read.
6897 Handle any notification that arrives in the mean time. */
6900 ch
= readchar (remote_timeout
);
6908 case SERIAL_TIMEOUT
:
6911 if (started_error_output
)
6913 putchar_unfiltered ('\n');
6914 started_error_output
= 0;
6923 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6927 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6929 case SERIAL_TIMEOUT
:
6933 break; /* Retransmit buffer. */
6937 fprintf_unfiltered (gdb_stdlog
,
6938 "Packet instead of Ack, ignoring it\n");
6939 /* It's probably an old response sent because an ACK
6940 was lost. Gobble up the packet and ack it so it
6941 doesn't get retransmitted when we resend this
6944 serial_write (remote_desc
, "+", 1);
6945 continue; /* Now, go look for +. */
6952 /* If we got a notification, handle it, and go back to looking
6954 /* We've found the start of a notification. Now
6955 collect the data. */
6956 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6961 struct cleanup
*old_chain
;
6964 str
= escape_buffer (rs
->buf
, val
);
6965 old_chain
= make_cleanup (xfree
, str
);
6966 fprintf_unfiltered (gdb_stdlog
,
6967 " Notification received: %s\n",
6969 do_cleanups (old_chain
);
6971 handle_notification (rs
->buf
, val
);
6972 /* We're in sync now, rewait for the ack. */
6979 if (!started_error_output
)
6981 started_error_output
= 1;
6982 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6984 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6985 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6994 if (!started_error_output
)
6996 started_error_output
= 1;
6997 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6999 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7003 break; /* Here to retransmit. */
7007 /* This is wrong. If doing a long backtrace, the user should be
7008 able to get out next time we call QUIT, without anything as
7009 violent as interrupt_query. If we want to provide a way out of
7010 here without getting to the next QUIT, it should be based on
7011 hitting ^C twice as in remote_wait. */
7022 /* Come here after finding the start of a frame when we expected an
7023 ack. Do our best to discard the rest of this packet. */
7032 c
= readchar (remote_timeout
);
7035 case SERIAL_TIMEOUT
:
7036 /* Nothing we can do. */
7039 /* Discard the two bytes of checksum and stop. */
7040 c
= readchar (remote_timeout
);
7042 c
= readchar (remote_timeout
);
7045 case '*': /* Run length encoding. */
7046 /* Discard the repeat count. */
7047 c
= readchar (remote_timeout
);
7052 /* A regular character. */
7058 /* Come here after finding the start of the frame. Collect the rest
7059 into *BUF, verifying the checksum, length, and handling run-length
7060 compression. NUL terminate the buffer. If there is not enough room,
7061 expand *BUF using xrealloc.
7063 Returns -1 on error, number of characters in buffer (ignoring the
7064 trailing NULL) on success. (could be extended to return one of the
7065 SERIAL status indications). */
7068 read_frame (char **buf_p
,
7075 struct remote_state
*rs
= get_remote_state ();
7082 c
= readchar (remote_timeout
);
7085 case SERIAL_TIMEOUT
:
7087 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7091 fputs_filtered ("Saw new packet start in middle of old one\n",
7093 return -1; /* Start a new packet, count retries. */
7096 unsigned char pktcsum
;
7102 check_0
= readchar (remote_timeout
);
7104 check_1
= readchar (remote_timeout
);
7106 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7109 fputs_filtered ("Timeout in checksum, retrying\n",
7113 else if (check_0
< 0 || check_1
< 0)
7116 fputs_filtered ("Communication error in checksum\n",
7121 /* Don't recompute the checksum; with no ack packets we
7122 don't have any way to indicate a packet retransmission
7127 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7128 if (csum
== pktcsum
)
7133 struct cleanup
*old_chain
;
7136 str
= escape_buffer (buf
, bc
);
7137 old_chain
= make_cleanup (xfree
, str
);
7138 fprintf_unfiltered (gdb_stdlog
,
7139 "Bad checksum, sentsum=0x%x, "
7140 "csum=0x%x, buf=%s\n",
7141 pktcsum
, csum
, str
);
7142 do_cleanups (old_chain
);
7144 /* Number of characters in buffer ignoring trailing
7148 case '*': /* Run length encoding. */
7153 c
= readchar (remote_timeout
);
7155 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7157 /* The character before ``*'' is repeated. */
7159 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7161 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7163 /* Make some more room in the buffer. */
7164 *sizeof_buf
+= repeat
;
7165 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7169 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7175 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7179 if (bc
>= *sizeof_buf
- 1)
7181 /* Make some more room in the buffer. */
7183 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7194 /* Read a packet from the remote machine, with error checking, and
7195 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7196 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7197 rather than timing out; this is used (in synchronous mode) to wait
7198 for a target that is is executing user code to stop. */
7199 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7200 don't have to change all the calls to getpkt to deal with the
7201 return value, because at the moment I don't know what the right
7202 thing to do it for those. */
7210 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7214 /* Read a packet from the remote machine, with error checking, and
7215 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7216 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7217 rather than timing out; this is used (in synchronous mode) to wait
7218 for a target that is is executing user code to stop. If FOREVER ==
7219 0, this function is allowed to time out gracefully and return an
7220 indication of this to the caller. Otherwise return the number of
7221 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7222 enough reason to return to the caller. */
7225 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7226 int expecting_notif
)
7228 struct remote_state
*rs
= get_remote_state ();
7234 /* We're reading a new response. Make sure we don't look at a
7235 previously cached response. */
7236 rs
->cached_wait_status
= 0;
7238 strcpy (*buf
, "timeout");
7241 timeout
= watchdog
> 0 ? watchdog
: -1;
7242 else if (expecting_notif
)
7243 timeout
= 0; /* There should already be a char in the buffer. If
7246 timeout
= remote_timeout
;
7250 /* Process any number of notifications, and then return when
7254 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7256 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7258 /* This can loop forever if the remote side sends us
7259 characters continuously, but if it pauses, we'll get
7260 SERIAL_TIMEOUT from readchar because of timeout. Then
7261 we'll count that as a retry.
7263 Note that even when forever is set, we will only wait
7264 forever prior to the start of a packet. After that, we
7265 expect characters to arrive at a brisk pace. They should
7266 show up within remote_timeout intervals. */
7268 c
= readchar (timeout
);
7269 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7271 if (c
== SERIAL_TIMEOUT
)
7273 if (expecting_notif
)
7274 return -1; /* Don't complain, it's normal to not get
7275 anything in this case. */
7277 if (forever
) /* Watchdog went off? Kill the target. */
7281 error (_("Watchdog timeout has expired. Target detached."));
7284 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7288 /* We've found the start of a packet or notification.
7289 Now collect the data. */
7290 val
= read_frame (buf
, sizeof_buf
);
7295 serial_write (remote_desc
, "-", 1);
7298 if (tries
> MAX_TRIES
)
7300 /* We have tried hard enough, and just can't receive the
7301 packet/notification. Give up. */
7302 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7304 /* Skip the ack char if we're in no-ack mode. */
7305 if (!rs
->noack_mode
)
7306 serial_write (remote_desc
, "+", 1);
7310 /* If we got an ordinary packet, return that to our caller. */
7315 struct cleanup
*old_chain
;
7318 str
= escape_buffer (*buf
, val
);
7319 old_chain
= make_cleanup (xfree
, str
);
7320 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7321 do_cleanups (old_chain
);
7324 /* Skip the ack char if we're in no-ack mode. */
7325 if (!rs
->noack_mode
)
7326 serial_write (remote_desc
, "+", 1);
7330 /* If we got a notification, handle it, and go back to looking
7334 gdb_assert (c
== '%');
7338 struct cleanup
*old_chain
;
7341 str
= escape_buffer (*buf
, val
);
7342 old_chain
= make_cleanup (xfree
, str
);
7343 fprintf_unfiltered (gdb_stdlog
,
7344 " Notification received: %s\n",
7346 do_cleanups (old_chain
);
7349 handle_notification (*buf
, val
);
7351 /* Notifications require no acknowledgement. */
7353 if (expecting_notif
)
7360 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7362 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7366 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7368 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7373 remote_kill (struct target_ops
*ops
)
7375 /* Use catch_errors so the user can quit from gdb even when we
7376 aren't on speaking terms with the remote system. */
7377 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
7379 /* Don't wait for it to die. I'm not really sure it matters whether
7380 we do or not. For the existing stubs, kill is a noop. */
7381 target_mourn_inferior ();
7385 remote_vkill (int pid
, struct remote_state
*rs
)
7387 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7390 /* Tell the remote target to detach. */
7391 sprintf (rs
->buf
, "vKill;%x", pid
);
7393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7395 if (packet_ok (rs
->buf
,
7396 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7398 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7405 extended_remote_kill (struct target_ops
*ops
)
7408 int pid
= ptid_get_pid (inferior_ptid
);
7409 struct remote_state
*rs
= get_remote_state ();
7411 res
= remote_vkill (pid
, rs
);
7412 if (res
== -1 && !remote_multi_process_p (rs
))
7414 /* Don't try 'k' on a multi-process aware stub -- it has no way
7415 to specify the pid. */
7419 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7420 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7423 /* Don't wait for it to die. I'm not really sure it matters whether
7424 we do or not. For the existing stubs, kill is a noop. */
7430 error (_("Can't kill process"));
7432 target_mourn_inferior ();
7436 remote_mourn (struct target_ops
*ops
)
7438 remote_mourn_1 (ops
);
7441 /* Worker function for remote_mourn. */
7443 remote_mourn_1 (struct target_ops
*target
)
7445 unpush_target (target
);
7447 /* remote_close takes care of doing most of the clean up. */
7448 generic_mourn_inferior ();
7452 extended_remote_mourn_1 (struct target_ops
*target
)
7454 struct remote_state
*rs
= get_remote_state ();
7456 /* In case we got here due to an error, but we're going to stay
7458 rs
->waiting_for_stop_reply
= 0;
7460 /* We're no longer interested in these events. */
7461 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7463 /* If the current general thread belonged to the process we just
7464 detached from or has exited, the remote side current general
7465 thread becomes undefined. Considering a case like this:
7467 - We just got here due to a detach.
7468 - The process that we're detaching from happens to immediately
7469 report a global breakpoint being hit in non-stop mode, in the
7470 same thread we had selected before.
7471 - GDB attaches to this process again.
7472 - This event happens to be the next event we handle.
7474 GDB would consider that the current general thread didn't need to
7475 be set on the stub side (with Hg), since for all it knew,
7476 GENERAL_THREAD hadn't changed.
7478 Notice that although in all-stop mode, the remote server always
7479 sets the current thread to the thread reporting the stop event,
7480 that doesn't happen in non-stop mode; in non-stop, the stub *must
7481 not* change the current thread when reporting a breakpoint hit,
7482 due to the decoupling of event reporting and event handling.
7484 To keep things simple, we always invalidate our notion of the
7486 record_currthread (minus_one_ptid
);
7488 /* Unlike "target remote", we do not want to unpush the target; then
7489 the next time the user says "run", we won't be connected. */
7491 /* Call common code to mark the inferior as not running. */
7492 generic_mourn_inferior ();
7494 if (!have_inferiors ())
7496 if (!remote_multi_process_p (rs
))
7498 /* Check whether the target is running now - some remote stubs
7499 automatically restart after kill. */
7501 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7503 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7505 /* Assume that the target has been restarted. Set
7506 inferior_ptid so that bits of core GDB realizes
7507 there's something here, e.g., so that the user can
7508 say "kill" again. */
7509 inferior_ptid
= magic_null_ptid
;
7516 extended_remote_mourn (struct target_ops
*ops
)
7518 extended_remote_mourn_1 (ops
);
7522 extended_remote_supports_disable_randomization (void)
7524 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7529 extended_remote_disable_randomization (int val
)
7531 struct remote_state
*rs
= get_remote_state ();
7534 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7536 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7538 error (_("Target does not support QDisableRandomization."));
7539 if (strcmp (reply
, "OK") != 0)
7540 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7544 extended_remote_run (char *args
)
7546 struct remote_state
*rs
= get_remote_state ();
7549 /* If the user has disabled vRun support, or we have detected that
7550 support is not available, do not try it. */
7551 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7554 strcpy (rs
->buf
, "vRun;");
7555 len
= strlen (rs
->buf
);
7557 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7558 error (_("Remote file name too long for run packet"));
7559 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7561 gdb_assert (args
!= NULL
);
7564 struct cleanup
*back_to
;
7568 argv
= gdb_buildargv (args
);
7569 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7570 for (i
= 0; argv
[i
] != NULL
; i
++)
7572 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7573 error (_("Argument list too long for run packet"));
7574 rs
->buf
[len
++] = ';';
7575 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7577 do_cleanups (back_to
);
7580 rs
->buf
[len
++] = '\0';
7583 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7585 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7587 /* We have a wait response; we don't need it, though. All is well. */
7590 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7591 /* It wasn't disabled before, but it is now. */
7595 if (remote_exec_file
[0] == '\0')
7596 error (_("Running the default executable on the remote target failed; "
7597 "try \"set remote exec-file\"?"));
7599 error (_("Running \"%s\" on the remote target failed"),
7604 /* In the extended protocol we want to be able to do things like
7605 "run" and have them basically work as expected. So we need
7606 a special create_inferior function. We support changing the
7607 executable file and the command line arguments, but not the
7611 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7612 char **env
, int from_tty
)
7614 /* If running asynchronously, register the target file descriptor
7615 with the event loop. */
7616 if (target_can_async_p ())
7617 target_async (inferior_event_handler
, 0);
7619 /* Disable address space randomization if requested (and supported). */
7620 if (extended_remote_supports_disable_randomization ())
7621 extended_remote_disable_randomization (disable_randomization
);
7623 /* Now restart the remote server. */
7624 if (extended_remote_run (args
) == -1)
7626 /* vRun was not supported. Fail if we need it to do what the
7628 if (remote_exec_file
[0])
7629 error (_("Remote target does not support \"set remote exec-file\""));
7631 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7633 /* Fall back to "R". */
7634 extended_remote_restart ();
7637 if (!have_inferiors ())
7639 /* Clean up from the last time we ran, before we mark the target
7640 running again. This will mark breakpoints uninserted, and
7641 get_offsets may insert breakpoints. */
7642 init_thread_list ();
7643 init_wait_for_inferior ();
7646 /* Now mark the inferior as running before we do anything else. */
7647 inferior_ptid
= magic_null_ptid
;
7649 /* Now, if we have thread information, update inferior_ptid. */
7650 inferior_ptid
= remote_current_thread (inferior_ptid
);
7652 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7653 add_thread_silent (inferior_ptid
);
7655 /* Get updated offsets, if the stub uses qOffsets. */
7660 extended_remote_create_inferior (struct target_ops
*ops
,
7661 char *exec_file
, char *args
,
7662 char **env
, int from_tty
)
7664 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7668 /* Insert a breakpoint. On targets that have software breakpoint
7669 support, we ask the remote target to do the work; on targets
7670 which don't, we insert a traditional memory breakpoint. */
7673 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7674 struct bp_target_info
*bp_tgt
)
7676 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7677 If it succeeds, then set the support to PACKET_ENABLE. If it
7678 fails, and the user has explicitly requested the Z support then
7679 report an error, otherwise, mark it disabled and go on. */
7681 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7683 CORE_ADDR addr
= bp_tgt
->placed_address
;
7684 struct remote_state
*rs
;
7688 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7690 rs
= get_remote_state ();
7696 addr
= (ULONGEST
) remote_address_masked (addr
);
7697 p
+= hexnumstr (p
, addr
);
7698 sprintf (p
, ",%d", bpsize
);
7701 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7703 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7708 bp_tgt
->placed_address
= addr
;
7709 bp_tgt
->placed_size
= bpsize
;
7711 case PACKET_UNKNOWN
:
7716 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7720 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7721 struct bp_target_info
*bp_tgt
)
7723 CORE_ADDR addr
= bp_tgt
->placed_address
;
7724 struct remote_state
*rs
= get_remote_state ();
7726 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7734 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7735 p
+= hexnumstr (p
, addr
);
7736 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7739 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7741 return (rs
->buf
[0] == 'E');
7744 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7748 watchpoint_to_Z_packet (int type
)
7753 return Z_PACKET_WRITE_WP
;
7756 return Z_PACKET_READ_WP
;
7759 return Z_PACKET_ACCESS_WP
;
7762 internal_error (__FILE__
, __LINE__
,
7763 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7768 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7769 struct expression
*cond
)
7771 struct remote_state
*rs
= get_remote_state ();
7773 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7775 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7778 sprintf (rs
->buf
, "Z%x,", packet
);
7779 p
= strchr (rs
->buf
, '\0');
7780 addr
= remote_address_masked (addr
);
7781 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7782 sprintf (p
, ",%x", len
);
7785 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7787 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7791 case PACKET_UNKNOWN
:
7796 internal_error (__FILE__
, __LINE__
,
7797 _("remote_insert_watchpoint: reached end of function"));
7802 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7803 struct expression
*cond
)
7805 struct remote_state
*rs
= get_remote_state ();
7807 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7809 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7812 sprintf (rs
->buf
, "z%x,", packet
);
7813 p
= strchr (rs
->buf
, '\0');
7814 addr
= remote_address_masked (addr
);
7815 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7816 sprintf (p
, ",%x", len
);
7818 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7820 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7823 case PACKET_UNKNOWN
:
7828 internal_error (__FILE__
, __LINE__
,
7829 _("remote_remove_watchpoint: reached end of function"));
7833 int remote_hw_watchpoint_limit
= -1;
7834 int remote_hw_watchpoint_length_limit
= -1;
7835 int remote_hw_breakpoint_limit
= -1;
7838 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7840 if (remote_hw_watchpoint_length_limit
== 0)
7842 else if (remote_hw_watchpoint_length_limit
< 0)
7844 else if (len
<= remote_hw_watchpoint_length_limit
)
7851 remote_check_watch_resources (int type
, int cnt
, int ot
)
7853 if (type
== bp_hardware_breakpoint
)
7855 if (remote_hw_breakpoint_limit
== 0)
7857 else if (remote_hw_breakpoint_limit
< 0)
7859 else if (cnt
<= remote_hw_breakpoint_limit
)
7864 if (remote_hw_watchpoint_limit
== 0)
7866 else if (remote_hw_watchpoint_limit
< 0)
7870 else if (cnt
<= remote_hw_watchpoint_limit
)
7877 remote_stopped_by_watchpoint (void)
7879 return remote_stopped_by_watchpoint_p
;
7883 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7887 if (remote_stopped_by_watchpoint ())
7889 *addr_p
= remote_watch_data_address
;
7898 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7899 struct bp_target_info
*bp_tgt
)
7902 struct remote_state
*rs
;
7905 /* The length field should be set to the size of a breakpoint
7906 instruction, even though we aren't inserting one ourselves. */
7908 gdbarch_remote_breakpoint_from_pc
7909 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7911 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7914 rs
= get_remote_state ();
7921 addr
= remote_address_masked (bp_tgt
->placed_address
);
7922 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7923 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7926 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7928 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7931 case PACKET_UNKNOWN
:
7936 internal_error (__FILE__
, __LINE__
,
7937 _("remote_insert_hw_breakpoint: reached end of function"));
7942 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7943 struct bp_target_info
*bp_tgt
)
7946 struct remote_state
*rs
= get_remote_state ();
7949 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7956 addr
= remote_address_masked (bp_tgt
->placed_address
);
7957 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7958 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7961 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7963 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7966 case PACKET_UNKNOWN
:
7971 internal_error (__FILE__
, __LINE__
,
7972 _("remote_remove_hw_breakpoint: reached end of function"));
7975 /* Table used by the crc32 function to calcuate the checksum. */
7977 static unsigned long crc32_table
[256] =
7980 static unsigned long
7981 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7983 if (!crc32_table
[1])
7985 /* Initialize the CRC table and the decoding table. */
7989 for (i
= 0; i
< 256; i
++)
7991 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7992 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7999 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8005 /* Verify memory using the "qCRC:" request. */
8008 remote_verify_memory (struct target_ops
*ops
,
8009 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8011 struct remote_state
*rs
= get_remote_state ();
8012 unsigned long host_crc
, target_crc
;
8015 /* FIXME: assumes lma can fit into long. */
8016 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8017 (long) lma
, (long) size
);
8020 /* Be clever; compute the host_crc before waiting for target
8022 host_crc
= crc32 (data
, size
, 0xffffffff);
8024 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8025 if (rs
->buf
[0] == 'E')
8028 if (rs
->buf
[0] != 'C')
8029 error (_("remote target does not support this operation"));
8031 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8032 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8034 return (host_crc
== target_crc
);
8037 /* compare-sections command
8039 With no arguments, compares each loadable section in the exec bfd
8040 with the same memory range on the target, and reports mismatches.
8041 Useful for verifying the image on the target against the exec file. */
8044 compare_sections_command (char *args
, int from_tty
)
8047 struct cleanup
*old_chain
;
8049 const char *sectname
;
8057 error (_("command cannot be used without an exec file"));
8059 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8061 if (!(s
->flags
& SEC_LOAD
))
8062 continue; /* Skip non-loadable section. */
8064 size
= bfd_get_section_size (s
);
8066 continue; /* Skip zero-length section. */
8068 sectname
= bfd_get_section_name (exec_bfd
, s
);
8069 if (args
&& strcmp (args
, sectname
) != 0)
8070 continue; /* Not the section selected by user. */
8072 matched
= 1; /* Do this section. */
8075 sectdata
= xmalloc (size
);
8076 old_chain
= make_cleanup (xfree
, sectdata
);
8077 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8079 res
= target_verify_memory (sectdata
, lma
, size
);
8082 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8083 paddress (target_gdbarch
, lma
),
8084 paddress (target_gdbarch
, lma
+ size
));
8086 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8087 paddress (target_gdbarch
, lma
),
8088 paddress (target_gdbarch
, lma
+ size
));
8090 printf_filtered ("matched.\n");
8093 printf_filtered ("MIS-MATCHED!\n");
8097 do_cleanups (old_chain
);
8100 warning (_("One or more sections of the remote executable does not match\n\
8101 the loaded file\n"));
8102 if (args
&& !matched
)
8103 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8106 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8107 into remote target. The number of bytes written to the remote
8108 target is returned, or -1 for error. */
8111 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8112 const char *annex
, const gdb_byte
*writebuf
,
8113 ULONGEST offset
, LONGEST len
,
8114 struct packet_config
*packet
)
8118 struct remote_state
*rs
= get_remote_state ();
8119 int max_size
= get_memory_write_packet_size ();
8121 if (packet
->support
== PACKET_DISABLE
)
8124 /* Insert header. */
8125 i
= snprintf (rs
->buf
, max_size
,
8126 "qXfer:%s:write:%s:%s:",
8127 object_name
, annex
? annex
: "",
8128 phex_nz (offset
, sizeof offset
));
8129 max_size
-= (i
+ 1);
8131 /* Escape as much data as fits into rs->buf. */
8132 buf_len
= remote_escape_output
8133 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8135 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8136 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8137 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8140 unpack_varlen_hex (rs
->buf
, &n
);
8144 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8145 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8146 number of bytes read is returned, or 0 for EOF, or -1 for error.
8147 The number of bytes read may be less than LEN without indicating an
8148 EOF. PACKET is checked and updated to indicate whether the remote
8149 target supports this object. */
8152 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8154 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8155 struct packet_config
*packet
)
8157 static char *finished_object
;
8158 static char *finished_annex
;
8159 static ULONGEST finished_offset
;
8161 struct remote_state
*rs
= get_remote_state ();
8162 LONGEST i
, n
, packet_len
;
8164 if (packet
->support
== PACKET_DISABLE
)
8167 /* Check whether we've cached an end-of-object packet that matches
8169 if (finished_object
)
8171 if (strcmp (object_name
, finished_object
) == 0
8172 && strcmp (annex
? annex
: "", finished_annex
) == 0
8173 && offset
== finished_offset
)
8176 /* Otherwise, we're now reading something different. Discard
8178 xfree (finished_object
);
8179 xfree (finished_annex
);
8180 finished_object
= NULL
;
8181 finished_annex
= NULL
;
8184 /* Request only enough to fit in a single packet. The actual data
8185 may not, since we don't know how much of it will need to be escaped;
8186 the target is free to respond with slightly less data. We subtract
8187 five to account for the response type and the protocol frame. */
8188 n
= min (get_remote_packet_size () - 5, len
);
8189 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8190 object_name
, annex
? annex
: "",
8191 phex_nz (offset
, sizeof offset
),
8192 phex_nz (n
, sizeof n
));
8193 i
= putpkt (rs
->buf
);
8198 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8199 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8202 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8203 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8205 /* 'm' means there is (or at least might be) more data after this
8206 batch. That does not make sense unless there's at least one byte
8207 of data in this reply. */
8208 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8209 error (_("Remote qXfer reply contained no data."));
8211 /* Got some data. */
8212 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8214 /* 'l' is an EOF marker, possibly including a final block of data,
8215 or possibly empty. If we have the final block of a non-empty
8216 object, record this fact to bypass a subsequent partial read. */
8217 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8219 finished_object
= xstrdup (object_name
);
8220 finished_annex
= xstrdup (annex
? annex
: "");
8221 finished_offset
= offset
+ i
;
8228 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8229 const char *annex
, gdb_byte
*readbuf
,
8230 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8232 struct remote_state
*rs
;
8237 set_remote_traceframe ();
8238 set_general_thread (inferior_ptid
);
8240 rs
= get_remote_state ();
8242 /* Handle memory using the standard memory routines. */
8243 if (object
== TARGET_OBJECT_MEMORY
)
8249 /* If the remote target is connected but not running, we should
8250 pass this request down to a lower stratum (e.g. the executable
8252 if (!target_has_execution
)
8255 if (writebuf
!= NULL
)
8256 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8258 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8262 else if (xfered
== 0 && errno
== 0)
8268 /* Handle SPU memory using qxfer packets. */
8269 if (object
== TARGET_OBJECT_SPU
)
8272 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8273 &remote_protocol_packets
8274 [PACKET_qXfer_spu_read
]);
8276 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8277 &remote_protocol_packets
8278 [PACKET_qXfer_spu_write
]);
8281 /* Handle extra signal info using qxfer packets. */
8282 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8285 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8286 &remote_protocol_packets
8287 [PACKET_qXfer_siginfo_read
]);
8289 return remote_write_qxfer (ops
, "siginfo", annex
,
8290 writebuf
, offset
, len
,
8291 &remote_protocol_packets
8292 [PACKET_qXfer_siginfo_write
]);
8295 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8298 return remote_read_qxfer (ops
, "statictrace", annex
,
8299 readbuf
, offset
, len
,
8300 &remote_protocol_packets
8301 [PACKET_qXfer_statictrace_read
]);
8306 /* Only handle flash writes. */
8307 if (writebuf
!= NULL
)
8313 case TARGET_OBJECT_FLASH
:
8314 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8318 else if (xfered
== 0 && errno
== 0)
8328 /* Map pre-existing objects onto letters. DO NOT do this for new
8329 objects!!! Instead specify new query packets. */
8332 case TARGET_OBJECT_AVR
:
8336 case TARGET_OBJECT_AUXV
:
8337 gdb_assert (annex
== NULL
);
8338 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8339 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8341 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8342 return remote_read_qxfer
8343 (ops
, "features", annex
, readbuf
, offset
, len
,
8344 &remote_protocol_packets
[PACKET_qXfer_features
]);
8346 case TARGET_OBJECT_LIBRARIES
:
8347 return remote_read_qxfer
8348 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8349 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8351 case TARGET_OBJECT_MEMORY_MAP
:
8352 gdb_assert (annex
== NULL
);
8353 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8354 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8356 case TARGET_OBJECT_OSDATA
:
8357 /* Should only get here if we're connected. */
8358 gdb_assert (remote_desc
);
8359 return remote_read_qxfer
8360 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8361 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8363 case TARGET_OBJECT_THREADS
:
8364 gdb_assert (annex
== NULL
);
8365 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8366 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8368 case TARGET_OBJECT_TRACEFRAME_INFO
:
8369 gdb_assert (annex
== NULL
);
8370 return remote_read_qxfer
8371 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8372 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8374 case TARGET_OBJECT_FDPIC
:
8375 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8376 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8381 /* Note: a zero OFFSET and LEN can be used to query the minimum
8383 if (offset
== 0 && len
== 0)
8384 return (get_remote_packet_size ());
8385 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8386 large enough let the caller deal with it. */
8387 if (len
< get_remote_packet_size ())
8389 len
= get_remote_packet_size ();
8391 /* Except for querying the minimum buffer size, target must be open. */
8393 error (_("remote query is only available after target open"));
8395 gdb_assert (annex
!= NULL
);
8396 gdb_assert (readbuf
!= NULL
);
8402 /* We used one buffer char for the remote protocol q command and
8403 another for the query type. As the remote protocol encapsulation
8404 uses 4 chars plus one extra in case we are debugging
8405 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8408 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8410 /* Bad caller may have sent forbidden characters. */
8411 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8416 gdb_assert (annex
[i
] == '\0');
8418 i
= putpkt (rs
->buf
);
8422 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8423 strcpy ((char *) readbuf
, rs
->buf
);
8425 return strlen ((char *) readbuf
);
8429 remote_search_memory (struct target_ops
* ops
,
8430 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8431 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8432 CORE_ADDR
*found_addrp
)
8434 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8435 struct remote_state
*rs
= get_remote_state ();
8436 int max_size
= get_memory_write_packet_size ();
8437 struct packet_config
*packet
=
8438 &remote_protocol_packets
[PACKET_qSearch_memory
];
8439 /* Number of packet bytes used to encode the pattern;
8440 this could be more than PATTERN_LEN due to escape characters. */
8441 int escaped_pattern_len
;
8442 /* Amount of pattern that was encodable in the packet. */
8443 int used_pattern_len
;
8446 ULONGEST found_addr
;
8448 /* Don't go to the target if we don't have to.
8449 This is done before checking packet->support to avoid the possibility that
8450 a success for this edge case means the facility works in general. */
8451 if (pattern_len
> search_space_len
)
8453 if (pattern_len
== 0)
8455 *found_addrp
= start_addr
;
8459 /* If we already know the packet isn't supported, fall back to the simple
8460 way of searching memory. */
8462 if (packet
->support
== PACKET_DISABLE
)
8464 /* Target doesn't provided special support, fall back and use the
8465 standard support (copy memory and do the search here). */
8466 return simple_search_memory (ops
, start_addr
, search_space_len
,
8467 pattern
, pattern_len
, found_addrp
);
8470 /* Insert header. */
8471 i
= snprintf (rs
->buf
, max_size
,
8472 "qSearch:memory:%s;%s;",
8473 phex_nz (start_addr
, addr_size
),
8474 phex_nz (search_space_len
, sizeof (search_space_len
)));
8475 max_size
-= (i
+ 1);
8477 /* Escape as much data as fits into rs->buf. */
8478 escaped_pattern_len
=
8479 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8480 &used_pattern_len
, max_size
);
8482 /* Bail if the pattern is too large. */
8483 if (used_pattern_len
!= pattern_len
)
8484 error (_("Pattern is too large to transmit to remote target."));
8486 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8487 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8488 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8490 /* The request may not have worked because the command is not
8491 supported. If so, fall back to the simple way. */
8492 if (packet
->support
== PACKET_DISABLE
)
8494 return simple_search_memory (ops
, start_addr
, search_space_len
,
8495 pattern
, pattern_len
, found_addrp
);
8500 if (rs
->buf
[0] == '0')
8502 else if (rs
->buf
[0] == '1')
8505 if (rs
->buf
[1] != ',')
8506 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8507 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8508 *found_addrp
= found_addr
;
8511 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8517 remote_rcmd (char *command
,
8518 struct ui_file
*outbuf
)
8520 struct remote_state
*rs
= get_remote_state ();
8524 error (_("remote rcmd is only available after target open"));
8526 /* Send a NULL command across as an empty command. */
8527 if (command
== NULL
)
8530 /* The query prefix. */
8531 strcpy (rs
->buf
, "qRcmd,");
8532 p
= strchr (rs
->buf
, '\0');
8534 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8535 > get_remote_packet_size ())
8536 error (_("\"monitor\" command ``%s'' is too long."), command
);
8538 /* Encode the actual command. */
8539 bin2hex ((gdb_byte
*) command
, p
, 0);
8541 if (putpkt (rs
->buf
) < 0)
8542 error (_("Communication problem with target."));
8544 /* get/display the response */
8549 /* XXX - see also remote_get_noisy_reply(). */
8551 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8554 error (_("Target does not support this command."));
8555 if (buf
[0] == 'O' && buf
[1] != 'K')
8557 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8560 if (strcmp (buf
, "OK") == 0)
8562 if (strlen (buf
) == 3 && buf
[0] == 'E'
8563 && isdigit (buf
[1]) && isdigit (buf
[2]))
8565 error (_("Protocol error with Rcmd"));
8567 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8569 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8571 fputc_unfiltered (c
, outbuf
);
8577 static VEC(mem_region_s
) *
8578 remote_memory_map (struct target_ops
*ops
)
8580 VEC(mem_region_s
) *result
= NULL
;
8581 char *text
= target_read_stralloc (¤t_target
,
8582 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8586 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8588 result
= parse_memory_map (text
);
8589 do_cleanups (back_to
);
8596 packet_command (char *args
, int from_tty
)
8598 struct remote_state
*rs
= get_remote_state ();
8601 error (_("command can only be used with remote target"));
8604 error (_("remote-packet command requires packet text as argument"));
8606 puts_filtered ("sending: ");
8607 print_packet (args
);
8608 puts_filtered ("\n");
8611 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8612 puts_filtered ("received: ");
8613 print_packet (rs
->buf
);
8614 puts_filtered ("\n");
8618 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8620 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8622 static void threadset_test_cmd (char *cmd
, int tty
);
8624 static void threadalive_test (char *cmd
, int tty
);
8626 static void threadlist_test_cmd (char *cmd
, int tty
);
8628 int get_and_display_threadinfo (threadref
*ref
);
8630 static void threadinfo_test_cmd (char *cmd
, int tty
);
8632 static int thread_display_step (threadref
*ref
, void *context
);
8634 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8636 static void init_remote_threadtests (void);
8638 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8641 threadset_test_cmd (char *cmd
, int tty
)
8643 int sample_thread
= SAMPLE_THREAD
;
8645 printf_filtered (_("Remote threadset test\n"));
8646 set_general_thread (sample_thread
);
8651 threadalive_test (char *cmd
, int tty
)
8653 int sample_thread
= SAMPLE_THREAD
;
8654 int pid
= ptid_get_pid (inferior_ptid
);
8655 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8657 if (remote_thread_alive (ptid
))
8658 printf_filtered ("PASS: Thread alive test\n");
8660 printf_filtered ("FAIL: Thread alive test\n");
8663 void output_threadid (char *title
, threadref
*ref
);
8666 output_threadid (char *title
, threadref
*ref
)
8670 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8672 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8676 threadlist_test_cmd (char *cmd
, int tty
)
8679 threadref nextthread
;
8680 int done
, result_count
;
8681 threadref threadlist
[3];
8683 printf_filtered ("Remote Threadlist test\n");
8684 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8685 &result_count
, &threadlist
[0]))
8686 printf_filtered ("FAIL: threadlist test\n");
8689 threadref
*scan
= threadlist
;
8690 threadref
*limit
= scan
+ result_count
;
8692 while (scan
< limit
)
8693 output_threadid (" thread ", scan
++);
8698 display_thread_info (struct gdb_ext_thread_info
*info
)
8700 output_threadid ("Threadid: ", &info
->threadid
);
8701 printf_filtered ("Name: %s\n ", info
->shortname
);
8702 printf_filtered ("State: %s\n", info
->display
);
8703 printf_filtered ("other: %s\n\n", info
->more_display
);
8707 get_and_display_threadinfo (threadref
*ref
)
8711 struct gdb_ext_thread_info threadinfo
;
8713 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8714 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8715 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8716 display_thread_info (&threadinfo
);
8721 threadinfo_test_cmd (char *cmd
, int tty
)
8723 int athread
= SAMPLE_THREAD
;
8727 int_to_threadref (&thread
, athread
);
8728 printf_filtered ("Remote Threadinfo test\n");
8729 if (!get_and_display_threadinfo (&thread
))
8730 printf_filtered ("FAIL cannot get thread info\n");
8734 thread_display_step (threadref
*ref
, void *context
)
8736 /* output_threadid(" threadstep ",ref); *//* simple test */
8737 return get_and_display_threadinfo (ref
);
8741 threadlist_update_test_cmd (char *cmd
, int tty
)
8743 printf_filtered ("Remote Threadlist update test\n");
8744 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8748 init_remote_threadtests (void)
8750 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8751 _("Fetch and print the remote list of "
8752 "thread identifiers, one pkt only"));
8753 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8754 _("Fetch and display info about one thread"));
8755 add_com ("tset", class_obscure
, threadset_test_cmd
,
8756 _("Test setting to a different thread"));
8757 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8758 _("Iterate through updating all remote thread info"));
8759 add_com ("talive", class_obscure
, threadalive_test
,
8760 _(" Remote thread alive test "));
8765 /* Convert a thread ID to a string. Returns the string in a static
8769 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8771 static char buf
[64];
8772 struct remote_state
*rs
= get_remote_state ();
8774 if (ptid_is_pid (ptid
))
8776 /* Printing an inferior target id. */
8778 /* When multi-process extensions are off, there's no way in the
8779 remote protocol to know the remote process id, if there's any
8780 at all. There's one exception --- when we're connected with
8781 target extended-remote, and we manually attached to a process
8782 with "attach PID". We don't record anywhere a flag that
8783 allows us to distinguish that case from the case of
8784 connecting with extended-remote and the stub already being
8785 attached to a process, and reporting yes to qAttached, hence
8786 no smart special casing here. */
8787 if (!remote_multi_process_p (rs
))
8789 xsnprintf (buf
, sizeof buf
, "Remote target");
8793 return normal_pid_to_str (ptid
);
8797 if (ptid_equal (magic_null_ptid
, ptid
))
8798 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8799 else if (remote_multi_process_p (rs
))
8800 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8801 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8803 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8804 ptid_get_tid (ptid
));
8809 /* Get the address of the thread local variable in OBJFILE which is
8810 stored at OFFSET within the thread local storage for thread PTID. */
8813 remote_get_thread_local_address (struct target_ops
*ops
,
8814 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8816 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8818 struct remote_state
*rs
= get_remote_state ();
8820 char *endp
= rs
->buf
+ get_remote_packet_size ();
8821 enum packet_result result
;
8823 strcpy (p
, "qGetTLSAddr:");
8825 p
= write_ptid (p
, endp
, ptid
);
8827 p
+= hexnumstr (p
, offset
);
8829 p
+= hexnumstr (p
, lm
);
8833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8834 result
= packet_ok (rs
->buf
,
8835 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8836 if (result
== PACKET_OK
)
8840 unpack_varlen_hex (rs
->buf
, &result
);
8843 else if (result
== PACKET_UNKNOWN
)
8844 throw_error (TLS_GENERIC_ERROR
,
8845 _("Remote target doesn't support qGetTLSAddr packet"));
8847 throw_error (TLS_GENERIC_ERROR
,
8848 _("Remote target failed to process qGetTLSAddr request"));
8851 throw_error (TLS_GENERIC_ERROR
,
8852 _("TLS not supported or disabled on this target"));
8857 /* Provide thread local base, i.e. Thread Information Block address.
8858 Returns 1 if ptid is found and thread_local_base is non zero. */
8861 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8863 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8865 struct remote_state
*rs
= get_remote_state ();
8867 char *endp
= rs
->buf
+ get_remote_packet_size ();
8868 enum packet_result result
;
8870 strcpy (p
, "qGetTIBAddr:");
8872 p
= write_ptid (p
, endp
, ptid
);
8876 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8877 result
= packet_ok (rs
->buf
,
8878 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8879 if (result
== PACKET_OK
)
8883 unpack_varlen_hex (rs
->buf
, &result
);
8885 *addr
= (CORE_ADDR
) result
;
8888 else if (result
== PACKET_UNKNOWN
)
8889 error (_("Remote target doesn't support qGetTIBAddr packet"));
8891 error (_("Remote target failed to process qGetTIBAddr request"));
8894 error (_("qGetTIBAddr not supported or disabled on this target"));
8899 /* Support for inferring a target description based on the current
8900 architecture and the size of a 'g' packet. While the 'g' packet
8901 can have any size (since optional registers can be left off the
8902 end), some sizes are easily recognizable given knowledge of the
8903 approximate architecture. */
8905 struct remote_g_packet_guess
8908 const struct target_desc
*tdesc
;
8910 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8911 DEF_VEC_O(remote_g_packet_guess_s
);
8913 struct remote_g_packet_data
8915 VEC(remote_g_packet_guess_s
) *guesses
;
8918 static struct gdbarch_data
*remote_g_packet_data_handle
;
8921 remote_g_packet_data_init (struct obstack
*obstack
)
8923 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8927 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8928 const struct target_desc
*tdesc
)
8930 struct remote_g_packet_data
*data
8931 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8932 struct remote_g_packet_guess new_guess
, *guess
;
8935 gdb_assert (tdesc
!= NULL
);
8938 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8940 if (guess
->bytes
== bytes
)
8941 internal_error (__FILE__
, __LINE__
,
8942 _("Duplicate g packet description added for size %d"),
8945 new_guess
.bytes
= bytes
;
8946 new_guess
.tdesc
= tdesc
;
8947 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8950 /* Return 1 if remote_read_description would do anything on this target
8951 and architecture, 0 otherwise. */
8954 remote_read_description_p (struct target_ops
*target
)
8956 struct remote_g_packet_data
*data
8957 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8959 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8965 static const struct target_desc
*
8966 remote_read_description (struct target_ops
*target
)
8968 struct remote_g_packet_data
*data
8969 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8971 /* Do not try this during initial connection, when we do not know
8972 whether there is a running but stopped thread. */
8973 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8976 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8978 struct remote_g_packet_guess
*guess
;
8980 int bytes
= send_g_packet ();
8983 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8985 if (guess
->bytes
== bytes
)
8986 return guess
->tdesc
;
8988 /* We discard the g packet. A minor optimization would be to
8989 hold on to it, and fill the register cache once we have selected
8990 an architecture, but it's too tricky to do safely. */
8996 /* Remote file transfer support. This is host-initiated I/O, not
8997 target-initiated; for target-initiated, see remote-fileio.c. */
8999 /* If *LEFT is at least the length of STRING, copy STRING to
9000 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9001 decrease *LEFT. Otherwise raise an error. */
9004 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9006 int len
= strlen (string
);
9009 error (_("Packet too long for target."));
9011 memcpy (*buffer
, string
, len
);
9015 /* NUL-terminate the buffer as a convenience, if there is
9021 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9022 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9023 decrease *LEFT. Otherwise raise an error. */
9026 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9029 if (2 * len
> *left
)
9030 error (_("Packet too long for target."));
9032 bin2hex (bytes
, *buffer
, len
);
9036 /* NUL-terminate the buffer as a convenience, if there is
9042 /* If *LEFT is large enough, convert VALUE to hex and add it to
9043 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9044 decrease *LEFT. Otherwise raise an error. */
9047 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9049 int len
= hexnumlen (value
);
9052 error (_("Packet too long for target."));
9054 hexnumstr (*buffer
, value
);
9058 /* NUL-terminate the buffer as a convenience, if there is
9064 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9065 value, *REMOTE_ERRNO to the remote error number or zero if none
9066 was included, and *ATTACHMENT to point to the start of the annex
9067 if any. The length of the packet isn't needed here; there may
9068 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9070 Return 0 if the packet could be parsed, -1 if it could not. If
9071 -1 is returned, the other variables may not be initialized. */
9074 remote_hostio_parse_result (char *buffer
, int *retcode
,
9075 int *remote_errno
, char **attachment
)
9082 if (buffer
[0] != 'F')
9086 *retcode
= strtol (&buffer
[1], &p
, 16);
9087 if (errno
!= 0 || p
== &buffer
[1])
9090 /* Check for ",errno". */
9094 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9095 if (errno
!= 0 || p
+ 1 == p2
)
9100 /* Check for ";attachment". If there is no attachment, the
9101 packet should end here. */
9104 *attachment
= p
+ 1;
9107 else if (*p
== '\0')
9113 /* Send a prepared I/O packet to the target and read its response.
9114 The prepared packet is in the global RS->BUF before this function
9115 is called, and the answer is there when we return.
9117 COMMAND_BYTES is the length of the request to send, which may include
9118 binary data. WHICH_PACKET is the packet configuration to check
9119 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9120 is set to the error number and -1 is returned. Otherwise the value
9121 returned by the function is returned.
9123 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9124 attachment is expected; an error will be reported if there's a
9125 mismatch. If one is found, *ATTACHMENT will be set to point into
9126 the packet buffer and *ATTACHMENT_LEN will be set to the
9127 attachment's length. */
9130 remote_hostio_send_command (int command_bytes
, int which_packet
,
9131 int *remote_errno
, char **attachment
,
9132 int *attachment_len
)
9134 struct remote_state
*rs
= get_remote_state ();
9135 int ret
, bytes_read
;
9136 char *attachment_tmp
;
9139 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9141 *remote_errno
= FILEIO_ENOSYS
;
9145 putpkt_binary (rs
->buf
, command_bytes
);
9146 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9148 /* If it timed out, something is wrong. Don't try to parse the
9152 *remote_errno
= FILEIO_EINVAL
;
9156 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9159 *remote_errno
= FILEIO_EINVAL
;
9161 case PACKET_UNKNOWN
:
9162 *remote_errno
= FILEIO_ENOSYS
;
9168 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9171 *remote_errno
= FILEIO_EINVAL
;
9175 /* Make sure we saw an attachment if and only if we expected one. */
9176 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9177 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9179 *remote_errno
= FILEIO_EINVAL
;
9183 /* If an attachment was found, it must point into the packet buffer;
9184 work out how many bytes there were. */
9185 if (attachment_tmp
!= NULL
)
9187 *attachment
= attachment_tmp
;
9188 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9194 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9195 remote file descriptor, or -1 if an error occurs (and set
9199 remote_hostio_open (const char *filename
, int flags
, int mode
,
9202 struct remote_state
*rs
= get_remote_state ();
9204 int left
= get_remote_packet_size () - 1;
9206 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9208 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9210 remote_buffer_add_string (&p
, &left
, ",");
9212 remote_buffer_add_int (&p
, &left
, flags
);
9213 remote_buffer_add_string (&p
, &left
, ",");
9215 remote_buffer_add_int (&p
, &left
, mode
);
9217 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9218 remote_errno
, NULL
, NULL
);
9221 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9222 Return the number of bytes written, or -1 if an error occurs (and
9223 set *REMOTE_ERRNO). */
9226 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9227 ULONGEST offset
, int *remote_errno
)
9229 struct remote_state
*rs
= get_remote_state ();
9231 int left
= get_remote_packet_size ();
9234 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9236 remote_buffer_add_int (&p
, &left
, fd
);
9237 remote_buffer_add_string (&p
, &left
, ",");
9239 remote_buffer_add_int (&p
, &left
, offset
);
9240 remote_buffer_add_string (&p
, &left
, ",");
9242 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9243 get_remote_packet_size () - (p
- rs
->buf
));
9245 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9246 remote_errno
, NULL
, NULL
);
9249 /* Read up to LEN bytes FD on the remote target into READ_BUF
9250 Return the number of bytes read, or -1 if an error occurs (and
9251 set *REMOTE_ERRNO). */
9254 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9255 ULONGEST offset
, int *remote_errno
)
9257 struct remote_state
*rs
= get_remote_state ();
9260 int left
= get_remote_packet_size ();
9261 int ret
, attachment_len
;
9264 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9266 remote_buffer_add_int (&p
, &left
, fd
);
9267 remote_buffer_add_string (&p
, &left
, ",");
9269 remote_buffer_add_int (&p
, &left
, len
);
9270 remote_buffer_add_string (&p
, &left
, ",");
9272 remote_buffer_add_int (&p
, &left
, offset
);
9274 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9275 remote_errno
, &attachment
,
9281 read_len
= remote_unescape_input (attachment
, attachment_len
,
9283 if (read_len
!= ret
)
9284 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9289 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9290 (and set *REMOTE_ERRNO). */
9293 remote_hostio_close (int fd
, int *remote_errno
)
9295 struct remote_state
*rs
= get_remote_state ();
9297 int left
= get_remote_packet_size () - 1;
9299 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9301 remote_buffer_add_int (&p
, &left
, fd
);
9303 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9304 remote_errno
, NULL
, NULL
);
9307 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9308 occurs (and set *REMOTE_ERRNO). */
9311 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9313 struct remote_state
*rs
= get_remote_state ();
9315 int left
= get_remote_packet_size () - 1;
9317 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9319 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9322 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9323 remote_errno
, NULL
, NULL
);
9327 remote_fileio_errno_to_host (int errnum
)
9351 case FILEIO_ENOTDIR
:
9371 case FILEIO_ENAMETOOLONG
:
9372 return ENAMETOOLONG
;
9378 remote_hostio_error (int errnum
)
9380 int host_error
= remote_fileio_errno_to_host (errnum
);
9382 if (host_error
== -1)
9383 error (_("Unknown remote I/O error %d"), errnum
);
9385 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9389 remote_hostio_close_cleanup (void *opaque
)
9391 int fd
= *(int *) opaque
;
9394 remote_hostio_close (fd
, &remote_errno
);
9399 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9401 const char *filename
= bfd_get_filename (abfd
);
9402 int fd
, remote_errno
;
9405 gdb_assert (remote_filename_p (filename
));
9407 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9410 errno
= remote_fileio_errno_to_host (remote_errno
);
9411 bfd_set_error (bfd_error_system_call
);
9415 stream
= xmalloc (sizeof (int));
9421 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9423 int fd
= *(int *)stream
;
9428 /* Ignore errors on close; these may happen if the remote
9429 connection was already torn down. */
9430 remote_hostio_close (fd
, &remote_errno
);
9436 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9437 file_ptr nbytes
, file_ptr offset
)
9439 int fd
= *(int *)stream
;
9441 file_ptr pos
, bytes
;
9444 while (nbytes
> pos
)
9446 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9447 offset
+ pos
, &remote_errno
);
9449 /* Success, but no bytes, means end-of-file. */
9453 errno
= remote_fileio_errno_to_host (remote_errno
);
9454 bfd_set_error (bfd_error_system_call
);
9465 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9467 /* FIXME: We should probably implement remote_hostio_stat. */
9468 sb
->st_size
= INT_MAX
;
9473 remote_filename_p (const char *filename
)
9475 return strncmp (filename
, "remote:", 7) == 0;
9479 remote_bfd_open (const char *remote_file
, const char *target
)
9481 return bfd_openr_iovec (remote_file
, target
,
9482 remote_bfd_iovec_open
, NULL
,
9483 remote_bfd_iovec_pread
,
9484 remote_bfd_iovec_close
,
9485 remote_bfd_iovec_stat
);
9489 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9491 struct cleanup
*back_to
, *close_cleanup
;
9492 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9495 int bytes_in_buffer
;
9500 error (_("command can only be used with remote target"));
9502 file
= fopen (local_file
, "rb");
9504 perror_with_name (local_file
);
9505 back_to
= make_cleanup_fclose (file
);
9507 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9509 0700, &remote_errno
);
9511 remote_hostio_error (remote_errno
);
9513 /* Send up to this many bytes at once. They won't all fit in the
9514 remote packet limit, so we'll transfer slightly fewer. */
9515 io_size
= get_remote_packet_size ();
9516 buffer
= xmalloc (io_size
);
9517 make_cleanup (xfree
, buffer
);
9519 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9521 bytes_in_buffer
= 0;
9524 while (bytes_in_buffer
|| !saw_eof
)
9528 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9529 io_size
- bytes_in_buffer
,
9534 error (_("Error reading %s."), local_file
);
9537 /* EOF. Unless there is something still in the
9538 buffer from the last iteration, we are done. */
9540 if (bytes_in_buffer
== 0)
9548 bytes
+= bytes_in_buffer
;
9549 bytes_in_buffer
= 0;
9551 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9552 offset
, &remote_errno
);
9555 remote_hostio_error (remote_errno
);
9556 else if (retcode
== 0)
9557 error (_("Remote write of %d bytes returned 0!"), bytes
);
9558 else if (retcode
< bytes
)
9560 /* Short write. Save the rest of the read data for the next
9562 bytes_in_buffer
= bytes
- retcode
;
9563 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9569 discard_cleanups (close_cleanup
);
9570 if (remote_hostio_close (fd
, &remote_errno
))
9571 remote_hostio_error (remote_errno
);
9574 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9575 do_cleanups (back_to
);
9579 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9581 struct cleanup
*back_to
, *close_cleanup
;
9582 int fd
, remote_errno
, bytes
, io_size
;
9588 error (_("command can only be used with remote target"));
9590 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9592 remote_hostio_error (remote_errno
);
9594 file
= fopen (local_file
, "wb");
9596 perror_with_name (local_file
);
9597 back_to
= make_cleanup_fclose (file
);
9599 /* Send up to this many bytes at once. They won't all fit in the
9600 remote packet limit, so we'll transfer slightly fewer. */
9601 io_size
= get_remote_packet_size ();
9602 buffer
= xmalloc (io_size
);
9603 make_cleanup (xfree
, buffer
);
9605 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9610 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9612 /* Success, but no bytes, means end-of-file. */
9615 remote_hostio_error (remote_errno
);
9619 bytes
= fwrite (buffer
, 1, bytes
, file
);
9621 perror_with_name (local_file
);
9624 discard_cleanups (close_cleanup
);
9625 if (remote_hostio_close (fd
, &remote_errno
))
9626 remote_hostio_error (remote_errno
);
9629 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9630 do_cleanups (back_to
);
9634 remote_file_delete (const char *remote_file
, int from_tty
)
9636 int retcode
, remote_errno
;
9639 error (_("command can only be used with remote target"));
9641 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9643 remote_hostio_error (remote_errno
);
9646 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9650 remote_put_command (char *args
, int from_tty
)
9652 struct cleanup
*back_to
;
9656 error_no_arg (_("file to put"));
9658 argv
= gdb_buildargv (args
);
9659 back_to
= make_cleanup_freeargv (argv
);
9660 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9661 error (_("Invalid parameters to remote put"));
9663 remote_file_put (argv
[0], argv
[1], from_tty
);
9665 do_cleanups (back_to
);
9669 remote_get_command (char *args
, int from_tty
)
9671 struct cleanup
*back_to
;
9675 error_no_arg (_("file to get"));
9677 argv
= gdb_buildargv (args
);
9678 back_to
= make_cleanup_freeargv (argv
);
9679 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9680 error (_("Invalid parameters to remote get"));
9682 remote_file_get (argv
[0], argv
[1], from_tty
);
9684 do_cleanups (back_to
);
9688 remote_delete_command (char *args
, int from_tty
)
9690 struct cleanup
*back_to
;
9694 error_no_arg (_("file to delete"));
9696 argv
= gdb_buildargv (args
);
9697 back_to
= make_cleanup_freeargv (argv
);
9698 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9699 error (_("Invalid parameters to remote delete"));
9701 remote_file_delete (argv
[0], from_tty
);
9703 do_cleanups (back_to
);
9707 remote_command (char *args
, int from_tty
)
9709 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9713 remote_can_execute_reverse (void)
9715 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9716 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9723 remote_supports_non_stop (void)
9729 remote_supports_disable_randomization (void)
9731 /* Only supported in extended mode. */
9736 remote_supports_multi_process (void)
9738 struct remote_state
*rs
= get_remote_state ();
9740 return remote_multi_process_p (rs
);
9744 remote_supports_cond_tracepoints (void)
9746 struct remote_state
*rs
= get_remote_state ();
9748 return rs
->cond_tracepoints
;
9752 remote_supports_fast_tracepoints (void)
9754 struct remote_state
*rs
= get_remote_state ();
9756 return rs
->fast_tracepoints
;
9760 remote_supports_static_tracepoints (void)
9762 struct remote_state
*rs
= get_remote_state ();
9764 return rs
->static_tracepoints
;
9768 remote_supports_install_in_trace (void)
9770 struct remote_state
*rs
= get_remote_state ();
9772 return rs
->install_in_trace
;
9776 remote_supports_enable_disable_tracepoint (void)
9778 struct remote_state
*rs
= get_remote_state ();
9780 return rs
->enable_disable_tracepoints
;
9784 remote_supports_string_tracing (void)
9786 struct remote_state
*rs
= get_remote_state ();
9788 return rs
->string_tracing
;
9792 remote_trace_init (void)
9795 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9796 if (strcmp (target_buf
, "OK") != 0)
9797 error (_("Target does not support this command."));
9800 static void free_actions_list (char **actions_list
);
9801 static void free_actions_list_cleanup_wrapper (void *);
9803 free_actions_list_cleanup_wrapper (void *al
)
9805 free_actions_list (al
);
9809 free_actions_list (char **actions_list
)
9813 if (actions_list
== 0)
9816 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9817 xfree (actions_list
[ndx
]);
9819 xfree (actions_list
);
9822 /* Recursive routine to walk through command list including loops, and
9823 download packets for each command. */
9826 remote_download_command_source (int num
, ULONGEST addr
,
9827 struct command_line
*cmds
)
9829 struct remote_state
*rs
= get_remote_state ();
9830 struct command_line
*cmd
;
9832 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9834 QUIT
; /* Allow user to bail out with ^C. */
9835 strcpy (rs
->buf
, "QTDPsrc:");
9836 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9837 rs
->buf
+ strlen (rs
->buf
),
9838 rs
->buf_size
- strlen (rs
->buf
));
9840 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9841 if (strcmp (target_buf
, "OK"))
9842 warning (_("Target does not support source download."));
9844 if (cmd
->control_type
== while_control
9845 || cmd
->control_type
== while_stepping_control
)
9847 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9849 QUIT
; /* Allow user to bail out with ^C. */
9850 strcpy (rs
->buf
, "QTDPsrc:");
9851 encode_source_string (num
, addr
, "cmd", "end",
9852 rs
->buf
+ strlen (rs
->buf
),
9853 rs
->buf_size
- strlen (rs
->buf
));
9855 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9856 if (strcmp (target_buf
, "OK"))
9857 warning (_("Target does not support source download."));
9863 remote_download_tracepoint (struct bp_location
*loc
)
9870 char **stepping_actions
;
9872 struct cleanup
*old_chain
= NULL
;
9873 struct agent_expr
*aexpr
;
9874 struct cleanup
*aexpr_chain
= NULL
;
9876 struct breakpoint
*b
= loc
->owner
;
9877 struct tracepoint
*t
= (struct tracepoint
*) b
;
9879 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9880 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9882 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9885 tpaddr
= loc
->address
;
9886 sprintf_vma (addrbuf
, tpaddr
);
9887 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9888 addrbuf
, /* address */
9889 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9890 t
->step_count
, t
->pass_count
);
9891 /* Fast tracepoints are mostly handled by the target, but we can
9892 tell the target how big of an instruction block should be moved
9894 if (b
->type
== bp_fast_tracepoint
)
9896 /* Only test for support at download time; we may not know
9897 target capabilities at definition time. */
9898 if (remote_supports_fast_tracepoints ())
9902 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9903 tpaddr
, &isize
, NULL
))
9904 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9906 /* If it passed validation at definition but fails now,
9907 something is very wrong. */
9908 internal_error (__FILE__
, __LINE__
,
9909 _("Fast tracepoint not "
9910 "valid during download"));
9913 /* Fast tracepoints are functionally identical to regular
9914 tracepoints, so don't take lack of support as a reason to
9915 give up on the trace run. */
9916 warning (_("Target does not support fast tracepoints, "
9917 "downloading %d as regular tracepoint"), b
->number
);
9919 else if (b
->type
== bp_static_tracepoint
)
9921 /* Only test for support at download time; we may not know
9922 target capabilities at definition time. */
9923 if (remote_supports_static_tracepoints ())
9925 struct static_tracepoint_marker marker
;
9927 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
9930 error (_("Static tracepoint not valid during download"));
9933 /* Fast tracepoints are functionally identical to regular
9934 tracepoints, so don't take lack of support as a reason
9935 to give up on the trace run. */
9936 error (_("Target does not support static tracepoints"));
9938 /* If the tracepoint has a conditional, make it into an agent
9939 expression and append to the definition. */
9942 /* Only test support at download time, we may not know target
9943 capabilities at definition time. */
9944 if (remote_supports_cond_tracepoints ())
9946 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9947 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9948 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9949 pkt
= buf
+ strlen (buf
);
9950 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9951 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9953 do_cleanups (aexpr_chain
);
9956 warning (_("Target does not support conditional tracepoints, "
9957 "ignoring tp %d cond"), b
->number
);
9960 if (b
->commands
|| *default_collect
)
9963 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9964 if (strcmp (target_buf
, "OK"))
9965 error (_("Target does not support tracepoints."));
9967 /* do_single_steps (t); */
9970 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9972 QUIT
; /* Allow user to bail out with ^C. */
9973 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9974 b
->number
, addrbuf
, /* address */
9976 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9979 remote_get_noisy_reply (&target_buf
,
9981 if (strcmp (target_buf
, "OK"))
9982 error (_("Error on target while setting tracepoints."));
9985 if (stepping_actions
)
9987 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9989 QUIT
; /* Allow user to bail out with ^C. */
9990 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9991 b
->number
, addrbuf
, /* address */
9992 ((ndx
== 0) ? "S" : ""),
9993 stepping_actions
[ndx
],
9994 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9996 remote_get_noisy_reply (&target_buf
,
9998 if (strcmp (target_buf
, "OK"))
9999 error (_("Error on target while setting tracepoints."));
10003 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10006 if (b
->addr_string
)
10008 strcpy (buf
, "QTDPsrc:");
10009 encode_source_string (b
->number
, loc
->address
,
10010 "at", b
->addr_string
, buf
+ strlen (buf
),
10011 2048 - strlen (buf
));
10014 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10015 if (strcmp (target_buf
, "OK"))
10016 warning (_("Target does not support source download."));
10018 if (b
->cond_string
)
10020 strcpy (buf
, "QTDPsrc:");
10021 encode_source_string (b
->number
, loc
->address
,
10022 "cond", b
->cond_string
, buf
+ strlen (buf
),
10023 2048 - strlen (buf
));
10025 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10026 if (strcmp (target_buf
, "OK"))
10027 warning (_("Target does not support source download."));
10029 remote_download_command_source (b
->number
, loc
->address
,
10030 breakpoint_commands (b
));
10033 do_cleanups (old_chain
);
10037 remote_can_download_tracepoint (void)
10039 struct trace_status
*ts
= current_trace_status ();
10040 int status
= remote_get_trace_status (ts
);
10042 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10045 /* If we are in a tracing experiment, but remote stub doesn't support
10046 installing tracepoint in trace, we have to return. */
10047 if (!remote_supports_install_in_trace ())
10055 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10057 struct remote_state
*rs
= get_remote_state ();
10060 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10061 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10062 p
= rs
->buf
+ strlen (rs
->buf
);
10063 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10064 error (_("Trace state variable name too long for tsv definition packet"));
10065 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10068 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10069 if (*target_buf
== '\0')
10070 error (_("Target does not support this command."));
10071 if (strcmp (target_buf
, "OK") != 0)
10072 error (_("Error on target while downloading trace state variable."));
10076 remote_enable_tracepoint (struct bp_location
*location
)
10078 struct remote_state
*rs
= get_remote_state ();
10081 sprintf_vma (addr_buf
, location
->address
);
10082 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10084 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10085 if (*rs
->buf
== '\0')
10086 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10087 if (strcmp (rs
->buf
, "OK") != 0)
10088 error (_("Error on target while enabling tracepoint."));
10092 remote_disable_tracepoint (struct bp_location
*location
)
10094 struct remote_state
*rs
= get_remote_state ();
10097 sprintf_vma (addr_buf
, location
->address
);
10098 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10100 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10101 if (*rs
->buf
== '\0')
10102 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10103 if (strcmp (rs
->buf
, "OK") != 0)
10104 error (_("Error on target while disabling tracepoint."));
10108 remote_trace_set_readonly_regions (void)
10111 bfd_size_type size
;
10117 return; /* No information to give. */
10119 strcpy (target_buf
, "QTro");
10120 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10122 char tmp1
[40], tmp2
[40];
10125 if ((s
->flags
& SEC_LOAD
) == 0 ||
10126 /* (s->flags & SEC_CODE) == 0 || */
10127 (s
->flags
& SEC_READONLY
) == 0)
10131 vma
= bfd_get_section_vma (,s
);
10132 size
= bfd_get_section_size (s
);
10133 sprintf_vma (tmp1
, vma
);
10134 sprintf_vma (tmp2
, vma
+ size
);
10135 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10136 if (offset
+ sec_length
+ 1 > target_buf_size
)
10138 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10141 Too many sections for read-only sections definition packet."));
10144 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10145 offset
+= sec_length
;
10149 putpkt (target_buf
);
10150 getpkt (&target_buf
, &target_buf_size
, 0);
10155 remote_trace_start (void)
10157 putpkt ("QTStart");
10158 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10159 if (*target_buf
== '\0')
10160 error (_("Target does not support this command."));
10161 if (strcmp (target_buf
, "OK") != 0)
10162 error (_("Bogus reply from target: %s"), target_buf
);
10166 remote_get_trace_status (struct trace_status
*ts
)
10168 /* Initialize it just to avoid a GCC false warning. */
10170 /* FIXME we need to get register block size some other way. */
10171 extern int trace_regblock_size
;
10172 volatile struct gdb_exception ex
;
10174 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10176 putpkt ("qTStatus");
10178 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10180 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10184 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10188 /* If the remote target doesn't do tracing, flag it. */
10192 /* We're working with a live target. */
10195 /* Set some defaults. */
10196 ts
->running_known
= 0;
10197 ts
->stop_reason
= trace_stop_reason_unknown
;
10198 ts
->traceframe_count
= -1;
10199 ts
->buffer_free
= 0;
10202 error (_("Bogus trace status reply from target: %s"), target_buf
);
10204 parse_trace_status (p
, ts
);
10206 return ts
->running
;
10210 remote_trace_stop (void)
10213 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10214 if (*target_buf
== '\0')
10215 error (_("Target does not support this command."));
10216 if (strcmp (target_buf
, "OK") != 0)
10217 error (_("Bogus reply from target: %s"), target_buf
);
10221 remote_trace_find (enum trace_find_type type
, int num
,
10222 ULONGEST addr1
, ULONGEST addr2
,
10225 struct remote_state
*rs
= get_remote_state ();
10227 int target_frameno
= -1, target_tracept
= -1;
10229 /* Lookups other than by absolute frame number depend on the current
10230 trace selected, so make sure it is correct on the remote end
10232 if (type
!= tfind_number
)
10233 set_remote_traceframe ();
10236 strcpy (p
, "QTFrame:");
10237 p
= strchr (p
, '\0');
10241 sprintf (p
, "%x", num
);
10244 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10247 sprintf (p
, "tdp:%x", num
);
10250 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10252 case tfind_outside
:
10253 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10256 error (_("Unknown trace find type %d"), type
);
10260 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10261 if (*reply
== '\0')
10262 error (_("Target does not support this command."));
10264 while (reply
&& *reply
)
10269 target_frameno
= (int) strtol (p
, &reply
, 16);
10271 error (_("Unable to parse trace frame number"));
10272 /* Don't update our remote traceframe number cache on failure
10273 to select a remote traceframe. */
10274 if (target_frameno
== -1)
10279 target_tracept
= (int) strtol (p
, &reply
, 16);
10281 error (_("Unable to parse tracepoint number"));
10283 case 'O': /* "OK"? */
10284 if (reply
[1] == 'K' && reply
[2] == '\0')
10287 error (_("Bogus reply from target: %s"), reply
);
10290 error (_("Bogus reply from target: %s"), reply
);
10293 *tpp
= target_tracept
;
10295 remote_traceframe_number
= target_frameno
;
10296 return target_frameno
;
10300 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10302 struct remote_state
*rs
= get_remote_state ();
10306 set_remote_traceframe ();
10308 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10310 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10311 if (reply
&& *reply
)
10315 unpack_varlen_hex (reply
+ 1, &uval
);
10316 *val
= (LONGEST
) uval
;
10324 remote_save_trace_data (const char *filename
)
10326 struct remote_state
*rs
= get_remote_state ();
10330 strcpy (p
, "QTSave:");
10332 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10333 error (_("Remote file name too long for trace save packet"));
10334 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10337 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10338 if (*reply
== '\0')
10339 error (_("Target does not support this command."));
10340 if (strcmp (reply
, "OK") != 0)
10341 error (_("Bogus reply from target: %s"), reply
);
10345 /* This is basically a memory transfer, but needs to be its own packet
10346 because we don't know how the target actually organizes its trace
10347 memory, plus we want to be able to ask for as much as possible, but
10348 not be unhappy if we don't get as much as we ask for. */
10351 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10353 struct remote_state
*rs
= get_remote_state ();
10359 strcpy (p
, "qTBuffer:");
10361 p
+= hexnumstr (p
, offset
);
10363 p
+= hexnumstr (p
, len
);
10367 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10368 if (reply
&& *reply
)
10370 /* 'l' by itself means we're at the end of the buffer and
10371 there is nothing more to get. */
10375 /* Convert the reply into binary. Limit the number of bytes to
10376 convert according to our passed-in buffer size, rather than
10377 what was returned in the packet; if the target is
10378 unexpectedly generous and gives us a bigger reply than we
10379 asked for, we don't want to crash. */
10380 rslt
= hex2bin (target_buf
, buf
, len
);
10384 /* Something went wrong, flag as an error. */
10389 remote_set_disconnected_tracing (int val
)
10391 struct remote_state
*rs
= get_remote_state ();
10393 if (rs
->disconnected_tracing
)
10397 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10399 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10400 if (*reply
== '\0')
10401 error (_("Target does not support this command."));
10402 if (strcmp (reply
, "OK") != 0)
10403 error (_("Bogus reply from target: %s"), reply
);
10406 warning (_("Target does not support disconnected tracing."));
10410 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10412 struct thread_info
*info
= find_thread_ptid (ptid
);
10414 if (info
&& info
->private)
10415 return info
->private->core
;
10420 remote_set_circular_trace_buffer (int val
)
10422 struct remote_state
*rs
= get_remote_state ();
10425 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10427 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10428 if (*reply
== '\0')
10429 error (_("Target does not support this command."));
10430 if (strcmp (reply
, "OK") != 0)
10431 error (_("Bogus reply from target: %s"), reply
);
10434 static struct traceframe_info
*
10435 remote_traceframe_info (void)
10439 text
= target_read_stralloc (¤t_target
,
10440 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10443 struct traceframe_info
*info
;
10444 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10446 info
= parse_traceframe_info (text
);
10447 do_cleanups (back_to
);
10454 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10455 instruction on which a fast tracepoint may be placed. Returns -1
10456 if the packet is not supported, and 0 if the minimum instruction
10457 length is unknown. */
10460 remote_get_min_fast_tracepoint_insn_len (void)
10462 struct remote_state
*rs
= get_remote_state ();
10465 sprintf (rs
->buf
, "qTMinFTPILen");
10467 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10468 if (*reply
== '\0')
10472 ULONGEST min_insn_len
;
10474 unpack_varlen_hex (reply
, &min_insn_len
);
10476 return (int) min_insn_len
;
10481 init_remote_ops (void)
10483 remote_ops
.to_shortname
= "remote";
10484 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10485 remote_ops
.to_doc
=
10486 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10487 Specify the serial device it is connected to\n\
10488 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10489 remote_ops
.to_open
= remote_open
;
10490 remote_ops
.to_close
= remote_close
;
10491 remote_ops
.to_detach
= remote_detach
;
10492 remote_ops
.to_disconnect
= remote_disconnect
;
10493 remote_ops
.to_resume
= remote_resume
;
10494 remote_ops
.to_wait
= remote_wait
;
10495 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10496 remote_ops
.to_store_registers
= remote_store_registers
;
10497 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10498 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10499 remote_ops
.to_files_info
= remote_files_info
;
10500 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10501 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10502 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10503 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10504 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10505 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10506 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10507 remote_ops
.to_region_ok_for_hw_watchpoint
10508 = remote_region_ok_for_hw_watchpoint
;
10509 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10510 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10511 remote_ops
.to_kill
= remote_kill
;
10512 remote_ops
.to_load
= generic_load
;
10513 remote_ops
.to_mourn_inferior
= remote_mourn
;
10514 remote_ops
.to_pass_signals
= remote_pass_signals
;
10515 remote_ops
.to_thread_alive
= remote_thread_alive
;
10516 remote_ops
.to_find_new_threads
= remote_threads_info
;
10517 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10518 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10519 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10520 remote_ops
.to_stop
= remote_stop
;
10521 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10522 remote_ops
.to_rcmd
= remote_rcmd
;
10523 remote_ops
.to_log_command
= serial_log_command
;
10524 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10525 remote_ops
.to_stratum
= process_stratum
;
10526 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10527 remote_ops
.to_has_memory
= default_child_has_memory
;
10528 remote_ops
.to_has_stack
= default_child_has_stack
;
10529 remote_ops
.to_has_registers
= default_child_has_registers
;
10530 remote_ops
.to_has_execution
= default_child_has_execution
;
10531 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10532 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10533 remote_ops
.to_magic
= OPS_MAGIC
;
10534 remote_ops
.to_memory_map
= remote_memory_map
;
10535 remote_ops
.to_flash_erase
= remote_flash_erase
;
10536 remote_ops
.to_flash_done
= remote_flash_done
;
10537 remote_ops
.to_read_description
= remote_read_description
;
10538 remote_ops
.to_search_memory
= remote_search_memory
;
10539 remote_ops
.to_can_async_p
= remote_can_async_p
;
10540 remote_ops
.to_is_async_p
= remote_is_async_p
;
10541 remote_ops
.to_async
= remote_async
;
10542 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10543 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10544 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10545 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10546 remote_ops
.to_supports_disable_randomization
10547 = remote_supports_disable_randomization
;
10548 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10549 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10550 remote_ops
.to_trace_init
= remote_trace_init
;
10551 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10552 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10553 remote_ops
.to_download_trace_state_variable
10554 = remote_download_trace_state_variable
;
10555 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10556 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10557 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10558 remote_ops
.to_trace_start
= remote_trace_start
;
10559 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10560 remote_ops
.to_trace_stop
= remote_trace_stop
;
10561 remote_ops
.to_trace_find
= remote_trace_find
;
10562 remote_ops
.to_get_trace_state_variable_value
10563 = remote_get_trace_state_variable_value
;
10564 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10565 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10566 remote_ops
.to_upload_trace_state_variables
10567 = remote_upload_trace_state_variables
;
10568 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10569 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10570 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10571 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10572 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10573 remote_ops
.to_verify_memory
= remote_verify_memory
;
10574 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10575 remote_ops
.to_set_permissions
= remote_set_permissions
;
10576 remote_ops
.to_static_tracepoint_marker_at
10577 = remote_static_tracepoint_marker_at
;
10578 remote_ops
.to_static_tracepoint_markers_by_strid
10579 = remote_static_tracepoint_markers_by_strid
;
10580 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10583 /* Set up the extended remote vector by making a copy of the standard
10584 remote vector and adding to it. */
10587 init_extended_remote_ops (void)
10589 extended_remote_ops
= remote_ops
;
10591 extended_remote_ops
.to_shortname
= "extended-remote";
10592 extended_remote_ops
.to_longname
=
10593 "Extended remote serial target in gdb-specific protocol";
10594 extended_remote_ops
.to_doc
=
10595 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10596 Specify the serial device it is connected to (e.g. /dev/ttya).";
10597 extended_remote_ops
.to_open
= extended_remote_open
;
10598 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10599 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10600 extended_remote_ops
.to_detach
= extended_remote_detach
;
10601 extended_remote_ops
.to_attach
= extended_remote_attach
;
10602 extended_remote_ops
.to_kill
= extended_remote_kill
;
10603 extended_remote_ops
.to_supports_disable_randomization
10604 = extended_remote_supports_disable_randomization
;
10608 remote_can_async_p (void)
10610 if (!target_async_permitted
)
10611 /* We only enable async when the user specifically asks for it. */
10614 /* We're async whenever the serial device is. */
10615 return serial_can_async_p (remote_desc
);
10619 remote_is_async_p (void)
10621 if (!target_async_permitted
)
10622 /* We only enable async when the user specifically asks for it. */
10625 /* We're async whenever the serial device is. */
10626 return serial_is_async_p (remote_desc
);
10629 /* Pass the SERIAL event on and up to the client. One day this code
10630 will be able to delay notifying the client of an event until the
10631 point where an entire packet has been received. */
10633 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10635 static void *async_client_context
;
10636 static serial_event_ftype remote_async_serial_handler
;
10639 remote_async_serial_handler (struct serial
*scb
, void *context
)
10641 /* Don't propogate error information up to the client. Instead let
10642 the client find out about the error by querying the target. */
10643 async_client_callback (INF_REG_EVENT
, async_client_context
);
10647 remote_async_inferior_event_handler (gdb_client_data data
)
10649 inferior_event_handler (INF_REG_EVENT
, NULL
);
10653 remote_async_get_pending_events_handler (gdb_client_data data
)
10655 remote_get_pending_stop_replies ();
10659 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10660 void *context
), void *context
)
10662 if (callback
!= NULL
)
10664 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10665 async_client_callback
= callback
;
10666 async_client_context
= context
;
10669 serial_async (remote_desc
, NULL
, NULL
);
10673 set_remote_cmd (char *args
, int from_tty
)
10675 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10679 show_remote_cmd (char *args
, int from_tty
)
10681 /* We can't just use cmd_show_list here, because we want to skip
10682 the redundant "show remote Z-packet" and the legacy aliases. */
10683 struct cleanup
*showlist_chain
;
10684 struct cmd_list_element
*list
= remote_show_cmdlist
;
10685 struct ui_out
*uiout
= current_uiout
;
10687 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10688 for (; list
!= NULL
; list
= list
->next
)
10689 if (strcmp (list
->name
, "Z-packet") == 0)
10691 else if (list
->type
== not_set_cmd
)
10692 /* Alias commands are exactly like the original, except they
10693 don't have the normal type. */
10697 struct cleanup
*option_chain
10698 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10700 ui_out_field_string (uiout
, "name", list
->name
);
10701 ui_out_text (uiout
, ": ");
10702 if (list
->type
== show_cmd
)
10703 do_setshow_command ((char *) NULL
, from_tty
, list
);
10705 cmd_func (list
, NULL
, from_tty
);
10706 /* Close the tuple. */
10707 do_cleanups (option_chain
);
10710 /* Close the tuple. */
10711 do_cleanups (showlist_chain
);
10715 /* Function to be called whenever a new objfile (shlib) is detected. */
10717 remote_new_objfile (struct objfile
*objfile
)
10719 if (remote_desc
!= 0) /* Have a remote connection. */
10720 remote_check_symbols (objfile
);
10723 /* Pull all the tracepoints defined on the target and create local
10724 data structures representing them. We don't want to create real
10725 tracepoints yet, we don't want to mess up the user's existing
10729 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10731 struct remote_state
*rs
= get_remote_state ();
10734 /* Ask for a first packet of tracepoint definition. */
10736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10738 while (*p
&& *p
!= 'l')
10740 parse_tracepoint_definition (p
, utpp
);
10741 /* Ask for another packet of tracepoint definition. */
10743 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10750 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10752 struct remote_state
*rs
= get_remote_state ();
10755 /* Ask for a first packet of variable definition. */
10757 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10759 while (*p
&& *p
!= 'l')
10761 parse_tsv_definition (p
, utsvp
);
10762 /* Ask for another packet of variable definition. */
10764 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10771 _initialize_remote (void)
10773 struct remote_state
*rs
;
10774 struct cmd_list_element
*cmd
;
10777 /* architecture specific data */
10778 remote_gdbarch_data_handle
=
10779 gdbarch_data_register_post_init (init_remote_state
);
10780 remote_g_packet_data_handle
=
10781 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10783 /* Initialize the per-target state. At the moment there is only one
10784 of these, not one per target. Only one target is active at a
10785 time. The default buffer size is unimportant; it will be expanded
10786 whenever a larger buffer is needed. */
10787 rs
= get_remote_state_raw ();
10788 rs
->buf_size
= 400;
10789 rs
->buf
= xmalloc (rs
->buf_size
);
10791 init_remote_ops ();
10792 add_target (&remote_ops
);
10794 init_extended_remote_ops ();
10795 add_target (&extended_remote_ops
);
10797 /* Hook into new objfile notification. */
10798 observer_attach_new_objfile (remote_new_objfile
);
10800 /* Set up signal handlers. */
10801 sigint_remote_token
=
10802 create_async_signal_handler (async_remote_interrupt
, NULL
);
10803 sigint_remote_twice_token
=
10804 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10807 init_remote_threadtests ();
10810 /* set/show remote ... */
10812 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10813 Remote protocol specific variables\n\
10814 Configure various remote-protocol specific variables such as\n\
10815 the packets being used"),
10816 &remote_set_cmdlist
, "set remote ",
10817 0 /* allow-unknown */, &setlist
);
10818 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10819 Remote protocol specific variables\n\
10820 Configure various remote-protocol specific variables such as\n\
10821 the packets being used"),
10822 &remote_show_cmdlist
, "show remote ",
10823 0 /* allow-unknown */, &showlist
);
10825 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10826 Compare section data on target to the exec file.\n\
10827 Argument is a single section name (default: all loaded sections)."),
10830 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10831 Send an arbitrary packet to a remote target.\n\
10832 maintenance packet TEXT\n\
10833 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10834 this command sends the string TEXT to the inferior, and displays the\n\
10835 response packet. GDB supplies the initial `$' character, and the\n\
10836 terminating `#' character and checksum."),
10839 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10840 Set whether to send break if interrupted."), _("\
10841 Show whether to send break if interrupted."), _("\
10842 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10843 set_remotebreak
, show_remotebreak
,
10844 &setlist
, &showlist
);
10845 cmd_name
= "remotebreak";
10846 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10847 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10848 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10849 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10850 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10852 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10853 interrupt_sequence_modes
, &interrupt_sequence_mode
,
10855 Set interrupt sequence to remote target."), _("\
10856 Show interrupt sequence to remote target."), _("\
10857 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10858 NULL
, show_interrupt_sequence
,
10859 &remote_set_cmdlist
,
10860 &remote_show_cmdlist
);
10862 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10863 &interrupt_on_connect
, _("\
10864 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10865 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10866 If set, interrupt sequence is sent to remote target."),
10868 &remote_set_cmdlist
, &remote_show_cmdlist
);
10870 /* Install commands for configuring memory read/write packets. */
10872 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10873 Set the maximum number of bytes per memory write packet (deprecated)."),
10875 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10876 Show the maximum number of bytes per memory write packet (deprecated)."),
10878 add_cmd ("memory-write-packet-size", no_class
,
10879 set_memory_write_packet_size
, _("\
10880 Set the maximum number of bytes per memory-write packet.\n\
10881 Specify the number of bytes in a packet or 0 (zero) for the\n\
10882 default packet size. The actual limit is further reduced\n\
10883 dependent on the target. Specify ``fixed'' to disable the\n\
10884 further restriction and ``limit'' to enable that restriction."),
10885 &remote_set_cmdlist
);
10886 add_cmd ("memory-read-packet-size", no_class
,
10887 set_memory_read_packet_size
, _("\
10888 Set the maximum number of bytes per memory-read packet.\n\
10889 Specify the number of bytes in a packet or 0 (zero) for the\n\
10890 default packet size. The actual limit is further reduced\n\
10891 dependent on the target. Specify ``fixed'' to disable the\n\
10892 further restriction and ``limit'' to enable that restriction."),
10893 &remote_set_cmdlist
);
10894 add_cmd ("memory-write-packet-size", no_class
,
10895 show_memory_write_packet_size
,
10896 _("Show the maximum number of bytes per memory-write packet."),
10897 &remote_show_cmdlist
);
10898 add_cmd ("memory-read-packet-size", no_class
,
10899 show_memory_read_packet_size
,
10900 _("Show the maximum number of bytes per memory-read packet."),
10901 &remote_show_cmdlist
);
10903 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10904 &remote_hw_watchpoint_limit
, _("\
10905 Set the maximum number of target hardware watchpoints."), _("\
10906 Show the maximum number of target hardware watchpoints."), _("\
10907 Specify a negative limit for unlimited."),
10908 NULL
, NULL
, /* FIXME: i18n: The maximum
10909 number of target hardware
10910 watchpoints is %s. */
10911 &remote_set_cmdlist
, &remote_show_cmdlist
);
10912 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
10913 &remote_hw_watchpoint_length_limit
, _("\
10914 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
10915 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
10916 Specify a negative limit for unlimited."),
10917 NULL
, NULL
, /* FIXME: i18n: The maximum
10918 length (in bytes) of a target
10919 hardware watchpoint is %s. */
10920 &remote_set_cmdlist
, &remote_show_cmdlist
);
10921 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10922 &remote_hw_breakpoint_limit
, _("\
10923 Set the maximum number of target hardware breakpoints."), _("\
10924 Show the maximum number of target hardware breakpoints."), _("\
10925 Specify a negative limit for unlimited."),
10926 NULL
, NULL
, /* FIXME: i18n: The maximum
10927 number of target hardware
10928 breakpoints is %s. */
10929 &remote_set_cmdlist
, &remote_show_cmdlist
);
10931 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10932 &remote_address_size
, _("\
10933 Set the maximum size of the address (in bits) in a memory packet."), _("\
10934 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10936 NULL
, /* FIXME: i18n: */
10937 &setlist
, &showlist
);
10939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10940 "X", "binary-download", 1);
10942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10943 "vCont", "verbose-resume", 0);
10945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10946 "QPassSignals", "pass-signals", 0);
10948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10949 "qSymbol", "symbol-lookup", 0);
10951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10952 "P", "set-register", 1);
10954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10955 "p", "fetch-register", 1);
10957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10958 "Z0", "software-breakpoint", 0);
10960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10961 "Z1", "hardware-breakpoint", 0);
10963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10964 "Z2", "write-watchpoint", 0);
10966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10967 "Z3", "read-watchpoint", 0);
10969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10970 "Z4", "access-watchpoint", 0);
10972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10973 "qXfer:auxv:read", "read-aux-vector", 0);
10975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10976 "qXfer:features:read", "target-features", 0);
10978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10979 "qXfer:libraries:read", "library-info", 0);
10981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10982 "qXfer:memory-map:read", "memory-map", 0);
10984 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10985 "qXfer:spu:read", "read-spu-object", 0);
10987 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10988 "qXfer:spu:write", "write-spu-object", 0);
10990 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10991 "qXfer:osdata:read", "osdata", 0);
10993 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10994 "qXfer:threads:read", "threads", 0);
10996 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10997 "qXfer:siginfo:read", "read-siginfo-object", 0);
10999 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11000 "qXfer:siginfo:write", "write-siginfo-object", 0);
11002 add_packet_config_cmd
11003 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11004 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11006 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11007 "qGetTLSAddr", "get-thread-local-storage-address",
11010 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11011 "qGetTIBAddr", "get-thread-information-block-address",
11014 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11015 "bc", "reverse-continue", 0);
11017 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11018 "bs", "reverse-step", 0);
11020 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11021 "qSupported", "supported-packets", 0);
11023 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11024 "qSearch:memory", "search-memory", 0);
11026 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11027 "vFile:open", "hostio-open", 0);
11029 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11030 "vFile:pread", "hostio-pread", 0);
11032 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11033 "vFile:pwrite", "hostio-pwrite", 0);
11035 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11036 "vFile:close", "hostio-close", 0);
11038 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11039 "vFile:unlink", "hostio-unlink", 0);
11041 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11042 "vAttach", "attach", 0);
11044 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11047 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11048 "QStartNoAckMode", "noack", 0);
11050 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11051 "vKill", "kill", 0);
11053 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11054 "qAttached", "query-attached", 0);
11056 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11057 "ConditionalTracepoints",
11058 "conditional-tracepoints", 0);
11059 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11060 "FastTracepoints", "fast-tracepoints", 0);
11062 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11063 "TracepointSource", "TracepointSource", 0);
11065 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11066 "QAllow", "allow", 0);
11068 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11069 "StaticTracepoints", "static-tracepoints", 0);
11071 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11072 "InstallInTrace", "install-in-trace", 0);
11074 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11075 "qXfer:statictrace:read", "read-sdata-object", 0);
11077 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11078 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11080 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11081 "QDisableRandomization", "disable-randomization", 0);
11083 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11084 Z sub-packet has its own set and show commands, but users may
11085 have sets to this variable in their .gdbinit files (or in their
11087 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11088 &remote_Z_packet_detect
, _("\
11089 Set use of remote protocol `Z' packets"), _("\
11090 Show use of remote protocol `Z' packets "), _("\
11091 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11093 set_remote_protocol_Z_packet_cmd
,
11094 show_remote_protocol_Z_packet_cmd
,
11095 /* FIXME: i18n: Use of remote protocol
11096 `Z' packets is %s. */
11097 &remote_set_cmdlist
, &remote_show_cmdlist
);
11099 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11100 Manipulate files on the remote system\n\
11101 Transfer files to and from the remote target system."),
11102 &remote_cmdlist
, "remote ",
11103 0 /* allow-unknown */, &cmdlist
);
11105 add_cmd ("put", class_files
, remote_put_command
,
11106 _("Copy a local file to the remote system."),
11109 add_cmd ("get", class_files
, remote_get_command
,
11110 _("Copy a remote file to the local system."),
11113 add_cmd ("delete", class_files
, remote_delete_command
,
11114 _("Delete a remote file."),
11117 remote_exec_file
= xstrdup ("");
11118 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11119 &remote_exec_file
, _("\
11120 Set the remote pathname for \"run\""), _("\
11121 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11122 &remote_set_cmdlist
, &remote_show_cmdlist
);
11124 /* Eventually initialize fileio. See fileio.c */
11125 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11127 /* Take advantage of the fact that the LWP field is not used, to tag
11128 special ptids with it set to != 0. */
11129 magic_null_ptid
= ptid_build (42000, 1, -1);
11130 not_sent_ptid
= ptid_build (42000, 1, -2);
11131 any_thread_ptid
= ptid_build (42000, 1, 0);
11133 target_buf_size
= 2048;
11134 target_buf
= xmalloc (target_buf_size
);