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);
7372 /* A helper function that just calls putpkt; for type correctness. */
7375 putpkt_for_catch_errors (void *arg
)
7377 return putpkt (arg
);
7381 remote_kill (struct target_ops
*ops
)
7383 /* Use catch_errors so the user can quit from gdb even when we
7384 aren't on speaking terms with the remote system. */
7385 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7387 /* Don't wait for it to die. I'm not really sure it matters whether
7388 we do or not. For the existing stubs, kill is a noop. */
7389 target_mourn_inferior ();
7393 remote_vkill (int pid
, struct remote_state
*rs
)
7395 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7398 /* Tell the remote target to detach. */
7399 sprintf (rs
->buf
, "vKill;%x", pid
);
7401 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7403 if (packet_ok (rs
->buf
,
7404 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7406 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7413 extended_remote_kill (struct target_ops
*ops
)
7416 int pid
= ptid_get_pid (inferior_ptid
);
7417 struct remote_state
*rs
= get_remote_state ();
7419 res
= remote_vkill (pid
, rs
);
7420 if (res
== -1 && !remote_multi_process_p (rs
))
7422 /* Don't try 'k' on a multi-process aware stub -- it has no way
7423 to specify the pid. */
7427 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7428 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7431 /* Don't wait for it to die. I'm not really sure it matters whether
7432 we do or not. For the existing stubs, kill is a noop. */
7438 error (_("Can't kill process"));
7440 target_mourn_inferior ();
7444 remote_mourn (struct target_ops
*ops
)
7446 remote_mourn_1 (ops
);
7449 /* Worker function for remote_mourn. */
7451 remote_mourn_1 (struct target_ops
*target
)
7453 unpush_target (target
);
7455 /* remote_close takes care of doing most of the clean up. */
7456 generic_mourn_inferior ();
7460 extended_remote_mourn_1 (struct target_ops
*target
)
7462 struct remote_state
*rs
= get_remote_state ();
7464 /* In case we got here due to an error, but we're going to stay
7466 rs
->waiting_for_stop_reply
= 0;
7468 /* We're no longer interested in these events. */
7469 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7471 /* If the current general thread belonged to the process we just
7472 detached from or has exited, the remote side current general
7473 thread becomes undefined. Considering a case like this:
7475 - We just got here due to a detach.
7476 - The process that we're detaching from happens to immediately
7477 report a global breakpoint being hit in non-stop mode, in the
7478 same thread we had selected before.
7479 - GDB attaches to this process again.
7480 - This event happens to be the next event we handle.
7482 GDB would consider that the current general thread didn't need to
7483 be set on the stub side (with Hg), since for all it knew,
7484 GENERAL_THREAD hadn't changed.
7486 Notice that although in all-stop mode, the remote server always
7487 sets the current thread to the thread reporting the stop event,
7488 that doesn't happen in non-stop mode; in non-stop, the stub *must
7489 not* change the current thread when reporting a breakpoint hit,
7490 due to the decoupling of event reporting and event handling.
7492 To keep things simple, we always invalidate our notion of the
7494 record_currthread (minus_one_ptid
);
7496 /* Unlike "target remote", we do not want to unpush the target; then
7497 the next time the user says "run", we won't be connected. */
7499 /* Call common code to mark the inferior as not running. */
7500 generic_mourn_inferior ();
7502 if (!have_inferiors ())
7504 if (!remote_multi_process_p (rs
))
7506 /* Check whether the target is running now - some remote stubs
7507 automatically restart after kill. */
7509 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7511 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7513 /* Assume that the target has been restarted. Set
7514 inferior_ptid so that bits of core GDB realizes
7515 there's something here, e.g., so that the user can
7516 say "kill" again. */
7517 inferior_ptid
= magic_null_ptid
;
7524 extended_remote_mourn (struct target_ops
*ops
)
7526 extended_remote_mourn_1 (ops
);
7530 extended_remote_supports_disable_randomization (void)
7532 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7537 extended_remote_disable_randomization (int val
)
7539 struct remote_state
*rs
= get_remote_state ();
7542 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7544 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7546 error (_("Target does not support QDisableRandomization."));
7547 if (strcmp (reply
, "OK") != 0)
7548 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7552 extended_remote_run (char *args
)
7554 struct remote_state
*rs
= get_remote_state ();
7557 /* If the user has disabled vRun support, or we have detected that
7558 support is not available, do not try it. */
7559 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7562 strcpy (rs
->buf
, "vRun;");
7563 len
= strlen (rs
->buf
);
7565 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7566 error (_("Remote file name too long for run packet"));
7567 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7569 gdb_assert (args
!= NULL
);
7572 struct cleanup
*back_to
;
7576 argv
= gdb_buildargv (args
);
7577 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7578 for (i
= 0; argv
[i
] != NULL
; i
++)
7580 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7581 error (_("Argument list too long for run packet"));
7582 rs
->buf
[len
++] = ';';
7583 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7585 do_cleanups (back_to
);
7588 rs
->buf
[len
++] = '\0';
7591 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7593 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7595 /* We have a wait response; we don't need it, though. All is well. */
7598 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7599 /* It wasn't disabled before, but it is now. */
7603 if (remote_exec_file
[0] == '\0')
7604 error (_("Running the default executable on the remote target failed; "
7605 "try \"set remote exec-file\"?"));
7607 error (_("Running \"%s\" on the remote target failed"),
7612 /* In the extended protocol we want to be able to do things like
7613 "run" and have them basically work as expected. So we need
7614 a special create_inferior function. We support changing the
7615 executable file and the command line arguments, but not the
7619 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7620 char **env
, int from_tty
)
7622 /* If running asynchronously, register the target file descriptor
7623 with the event loop. */
7624 if (target_can_async_p ())
7625 target_async (inferior_event_handler
, 0);
7627 /* Disable address space randomization if requested (and supported). */
7628 if (extended_remote_supports_disable_randomization ())
7629 extended_remote_disable_randomization (disable_randomization
);
7631 /* Now restart the remote server. */
7632 if (extended_remote_run (args
) == -1)
7634 /* vRun was not supported. Fail if we need it to do what the
7636 if (remote_exec_file
[0])
7637 error (_("Remote target does not support \"set remote exec-file\""));
7639 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7641 /* Fall back to "R". */
7642 extended_remote_restart ();
7645 if (!have_inferiors ())
7647 /* Clean up from the last time we ran, before we mark the target
7648 running again. This will mark breakpoints uninserted, and
7649 get_offsets may insert breakpoints. */
7650 init_thread_list ();
7651 init_wait_for_inferior ();
7654 /* Now mark the inferior as running before we do anything else. */
7655 inferior_ptid
= magic_null_ptid
;
7657 /* Now, if we have thread information, update inferior_ptid. */
7658 inferior_ptid
= remote_current_thread (inferior_ptid
);
7660 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7661 add_thread_silent (inferior_ptid
);
7663 /* Get updated offsets, if the stub uses qOffsets. */
7668 extended_remote_create_inferior (struct target_ops
*ops
,
7669 char *exec_file
, char *args
,
7670 char **env
, int from_tty
)
7672 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7676 /* Insert a breakpoint. On targets that have software breakpoint
7677 support, we ask the remote target to do the work; on targets
7678 which don't, we insert a traditional memory breakpoint. */
7681 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7682 struct bp_target_info
*bp_tgt
)
7684 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7685 If it succeeds, then set the support to PACKET_ENABLE. If it
7686 fails, and the user has explicitly requested the Z support then
7687 report an error, otherwise, mark it disabled and go on. */
7689 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7691 CORE_ADDR addr
= bp_tgt
->placed_address
;
7692 struct remote_state
*rs
;
7696 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7698 rs
= get_remote_state ();
7704 addr
= (ULONGEST
) remote_address_masked (addr
);
7705 p
+= hexnumstr (p
, addr
);
7706 sprintf (p
, ",%d", bpsize
);
7709 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7711 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7716 bp_tgt
->placed_address
= addr
;
7717 bp_tgt
->placed_size
= bpsize
;
7719 case PACKET_UNKNOWN
:
7724 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7728 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7729 struct bp_target_info
*bp_tgt
)
7731 CORE_ADDR addr
= bp_tgt
->placed_address
;
7732 struct remote_state
*rs
= get_remote_state ();
7734 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7742 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7743 p
+= hexnumstr (p
, addr
);
7744 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7747 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7749 return (rs
->buf
[0] == 'E');
7752 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7756 watchpoint_to_Z_packet (int type
)
7761 return Z_PACKET_WRITE_WP
;
7764 return Z_PACKET_READ_WP
;
7767 return Z_PACKET_ACCESS_WP
;
7770 internal_error (__FILE__
, __LINE__
,
7771 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7776 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7777 struct expression
*cond
)
7779 struct remote_state
*rs
= get_remote_state ();
7781 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7783 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7786 sprintf (rs
->buf
, "Z%x,", packet
);
7787 p
= strchr (rs
->buf
, '\0');
7788 addr
= remote_address_masked (addr
);
7789 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7790 sprintf (p
, ",%x", len
);
7793 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7795 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7799 case PACKET_UNKNOWN
:
7804 internal_error (__FILE__
, __LINE__
,
7805 _("remote_insert_watchpoint: reached end of function"));
7810 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7811 struct expression
*cond
)
7813 struct remote_state
*rs
= get_remote_state ();
7815 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7817 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7820 sprintf (rs
->buf
, "z%x,", packet
);
7821 p
= strchr (rs
->buf
, '\0');
7822 addr
= remote_address_masked (addr
);
7823 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7824 sprintf (p
, ",%x", len
);
7826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7828 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7831 case PACKET_UNKNOWN
:
7836 internal_error (__FILE__
, __LINE__
,
7837 _("remote_remove_watchpoint: reached end of function"));
7841 int remote_hw_watchpoint_limit
= -1;
7842 int remote_hw_watchpoint_length_limit
= -1;
7843 int remote_hw_breakpoint_limit
= -1;
7846 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7848 if (remote_hw_watchpoint_length_limit
== 0)
7850 else if (remote_hw_watchpoint_length_limit
< 0)
7852 else if (len
<= remote_hw_watchpoint_length_limit
)
7859 remote_check_watch_resources (int type
, int cnt
, int ot
)
7861 if (type
== bp_hardware_breakpoint
)
7863 if (remote_hw_breakpoint_limit
== 0)
7865 else if (remote_hw_breakpoint_limit
< 0)
7867 else if (cnt
<= remote_hw_breakpoint_limit
)
7872 if (remote_hw_watchpoint_limit
== 0)
7874 else if (remote_hw_watchpoint_limit
< 0)
7878 else if (cnt
<= remote_hw_watchpoint_limit
)
7885 remote_stopped_by_watchpoint (void)
7887 return remote_stopped_by_watchpoint_p
;
7891 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7895 if (remote_stopped_by_watchpoint ())
7897 *addr_p
= remote_watch_data_address
;
7906 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7907 struct bp_target_info
*bp_tgt
)
7910 struct remote_state
*rs
;
7913 /* The length field should be set to the size of a breakpoint
7914 instruction, even though we aren't inserting one ourselves. */
7916 gdbarch_remote_breakpoint_from_pc
7917 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7919 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7922 rs
= get_remote_state ();
7929 addr
= remote_address_masked (bp_tgt
->placed_address
);
7930 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7931 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7934 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7936 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7939 case PACKET_UNKNOWN
:
7944 internal_error (__FILE__
, __LINE__
,
7945 _("remote_insert_hw_breakpoint: reached end of function"));
7950 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7951 struct bp_target_info
*bp_tgt
)
7954 struct remote_state
*rs
= get_remote_state ();
7957 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7964 addr
= remote_address_masked (bp_tgt
->placed_address
);
7965 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7966 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7971 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7974 case PACKET_UNKNOWN
:
7979 internal_error (__FILE__
, __LINE__
,
7980 _("remote_remove_hw_breakpoint: reached end of function"));
7983 /* Table used by the crc32 function to calcuate the checksum. */
7985 static unsigned long crc32_table
[256] =
7988 static unsigned long
7989 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7991 if (!crc32_table
[1])
7993 /* Initialize the CRC table and the decoding table. */
7997 for (i
= 0; i
< 256; i
++)
7999 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8000 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8007 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8013 /* Verify memory using the "qCRC:" request. */
8016 remote_verify_memory (struct target_ops
*ops
,
8017 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8019 struct remote_state
*rs
= get_remote_state ();
8020 unsigned long host_crc
, target_crc
;
8023 /* FIXME: assumes lma can fit into long. */
8024 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8025 (long) lma
, (long) size
);
8028 /* Be clever; compute the host_crc before waiting for target
8030 host_crc
= crc32 (data
, size
, 0xffffffff);
8032 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8033 if (rs
->buf
[0] == 'E')
8036 if (rs
->buf
[0] != 'C')
8037 error (_("remote target does not support this operation"));
8039 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8040 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8042 return (host_crc
== target_crc
);
8045 /* compare-sections command
8047 With no arguments, compares each loadable section in the exec bfd
8048 with the same memory range on the target, and reports mismatches.
8049 Useful for verifying the image on the target against the exec file. */
8052 compare_sections_command (char *args
, int from_tty
)
8055 struct cleanup
*old_chain
;
8057 const char *sectname
;
8065 error (_("command cannot be used without an exec file"));
8067 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8069 if (!(s
->flags
& SEC_LOAD
))
8070 continue; /* Skip non-loadable section. */
8072 size
= bfd_get_section_size (s
);
8074 continue; /* Skip zero-length section. */
8076 sectname
= bfd_get_section_name (exec_bfd
, s
);
8077 if (args
&& strcmp (args
, sectname
) != 0)
8078 continue; /* Not the section selected by user. */
8080 matched
= 1; /* Do this section. */
8083 sectdata
= xmalloc (size
);
8084 old_chain
= make_cleanup (xfree
, sectdata
);
8085 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8087 res
= target_verify_memory (sectdata
, lma
, size
);
8090 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8091 paddress (target_gdbarch
, lma
),
8092 paddress (target_gdbarch
, lma
+ size
));
8094 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8095 paddress (target_gdbarch
, lma
),
8096 paddress (target_gdbarch
, lma
+ size
));
8098 printf_filtered ("matched.\n");
8101 printf_filtered ("MIS-MATCHED!\n");
8105 do_cleanups (old_chain
);
8108 warning (_("One or more sections of the remote executable does not match\n\
8109 the loaded file\n"));
8110 if (args
&& !matched
)
8111 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8114 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8115 into remote target. The number of bytes written to the remote
8116 target is returned, or -1 for error. */
8119 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8120 const char *annex
, const gdb_byte
*writebuf
,
8121 ULONGEST offset
, LONGEST len
,
8122 struct packet_config
*packet
)
8126 struct remote_state
*rs
= get_remote_state ();
8127 int max_size
= get_memory_write_packet_size ();
8129 if (packet
->support
== PACKET_DISABLE
)
8132 /* Insert header. */
8133 i
= snprintf (rs
->buf
, max_size
,
8134 "qXfer:%s:write:%s:%s:",
8135 object_name
, annex
? annex
: "",
8136 phex_nz (offset
, sizeof offset
));
8137 max_size
-= (i
+ 1);
8139 /* Escape as much data as fits into rs->buf. */
8140 buf_len
= remote_escape_output
8141 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8143 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8144 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8145 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8148 unpack_varlen_hex (rs
->buf
, &n
);
8152 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8153 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8154 number of bytes read is returned, or 0 for EOF, or -1 for error.
8155 The number of bytes read may be less than LEN without indicating an
8156 EOF. PACKET is checked and updated to indicate whether the remote
8157 target supports this object. */
8160 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8162 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8163 struct packet_config
*packet
)
8165 static char *finished_object
;
8166 static char *finished_annex
;
8167 static ULONGEST finished_offset
;
8169 struct remote_state
*rs
= get_remote_state ();
8170 LONGEST i
, n
, packet_len
;
8172 if (packet
->support
== PACKET_DISABLE
)
8175 /* Check whether we've cached an end-of-object packet that matches
8177 if (finished_object
)
8179 if (strcmp (object_name
, finished_object
) == 0
8180 && strcmp (annex
? annex
: "", finished_annex
) == 0
8181 && offset
== finished_offset
)
8184 /* Otherwise, we're now reading something different. Discard
8186 xfree (finished_object
);
8187 xfree (finished_annex
);
8188 finished_object
= NULL
;
8189 finished_annex
= NULL
;
8192 /* Request only enough to fit in a single packet. The actual data
8193 may not, since we don't know how much of it will need to be escaped;
8194 the target is free to respond with slightly less data. We subtract
8195 five to account for the response type and the protocol frame. */
8196 n
= min (get_remote_packet_size () - 5, len
);
8197 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8198 object_name
, annex
? annex
: "",
8199 phex_nz (offset
, sizeof offset
),
8200 phex_nz (n
, sizeof n
));
8201 i
= putpkt (rs
->buf
);
8206 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8207 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8210 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8211 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8213 /* 'm' means there is (or at least might be) more data after this
8214 batch. That does not make sense unless there's at least one byte
8215 of data in this reply. */
8216 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8217 error (_("Remote qXfer reply contained no data."));
8219 /* Got some data. */
8220 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8222 /* 'l' is an EOF marker, possibly including a final block of data,
8223 or possibly empty. If we have the final block of a non-empty
8224 object, record this fact to bypass a subsequent partial read. */
8225 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8227 finished_object
= xstrdup (object_name
);
8228 finished_annex
= xstrdup (annex
? annex
: "");
8229 finished_offset
= offset
+ i
;
8236 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8237 const char *annex
, gdb_byte
*readbuf
,
8238 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8240 struct remote_state
*rs
;
8245 set_remote_traceframe ();
8246 set_general_thread (inferior_ptid
);
8248 rs
= get_remote_state ();
8250 /* Handle memory using the standard memory routines. */
8251 if (object
== TARGET_OBJECT_MEMORY
)
8257 /* If the remote target is connected but not running, we should
8258 pass this request down to a lower stratum (e.g. the executable
8260 if (!target_has_execution
)
8263 if (writebuf
!= NULL
)
8264 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8266 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8270 else if (xfered
== 0 && errno
== 0)
8276 /* Handle SPU memory using qxfer packets. */
8277 if (object
== TARGET_OBJECT_SPU
)
8280 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8281 &remote_protocol_packets
8282 [PACKET_qXfer_spu_read
]);
8284 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8285 &remote_protocol_packets
8286 [PACKET_qXfer_spu_write
]);
8289 /* Handle extra signal info using qxfer packets. */
8290 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8293 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8294 &remote_protocol_packets
8295 [PACKET_qXfer_siginfo_read
]);
8297 return remote_write_qxfer (ops
, "siginfo", annex
,
8298 writebuf
, offset
, len
,
8299 &remote_protocol_packets
8300 [PACKET_qXfer_siginfo_write
]);
8303 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8306 return remote_read_qxfer (ops
, "statictrace", annex
,
8307 readbuf
, offset
, len
,
8308 &remote_protocol_packets
8309 [PACKET_qXfer_statictrace_read
]);
8314 /* Only handle flash writes. */
8315 if (writebuf
!= NULL
)
8321 case TARGET_OBJECT_FLASH
:
8322 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8326 else if (xfered
== 0 && errno
== 0)
8336 /* Map pre-existing objects onto letters. DO NOT do this for new
8337 objects!!! Instead specify new query packets. */
8340 case TARGET_OBJECT_AVR
:
8344 case TARGET_OBJECT_AUXV
:
8345 gdb_assert (annex
== NULL
);
8346 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8347 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8349 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8350 return remote_read_qxfer
8351 (ops
, "features", annex
, readbuf
, offset
, len
,
8352 &remote_protocol_packets
[PACKET_qXfer_features
]);
8354 case TARGET_OBJECT_LIBRARIES
:
8355 return remote_read_qxfer
8356 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8357 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8359 case TARGET_OBJECT_MEMORY_MAP
:
8360 gdb_assert (annex
== NULL
);
8361 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8362 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8364 case TARGET_OBJECT_OSDATA
:
8365 /* Should only get here if we're connected. */
8366 gdb_assert (remote_desc
);
8367 return remote_read_qxfer
8368 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8369 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8371 case TARGET_OBJECT_THREADS
:
8372 gdb_assert (annex
== NULL
);
8373 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8374 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8376 case TARGET_OBJECT_TRACEFRAME_INFO
:
8377 gdb_assert (annex
== NULL
);
8378 return remote_read_qxfer
8379 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8380 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8382 case TARGET_OBJECT_FDPIC
:
8383 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8384 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8389 /* Note: a zero OFFSET and LEN can be used to query the minimum
8391 if (offset
== 0 && len
== 0)
8392 return (get_remote_packet_size ());
8393 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8394 large enough let the caller deal with it. */
8395 if (len
< get_remote_packet_size ())
8397 len
= get_remote_packet_size ();
8399 /* Except for querying the minimum buffer size, target must be open. */
8401 error (_("remote query is only available after target open"));
8403 gdb_assert (annex
!= NULL
);
8404 gdb_assert (readbuf
!= NULL
);
8410 /* We used one buffer char for the remote protocol q command and
8411 another for the query type. As the remote protocol encapsulation
8412 uses 4 chars plus one extra in case we are debugging
8413 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8416 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8418 /* Bad caller may have sent forbidden characters. */
8419 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8424 gdb_assert (annex
[i
] == '\0');
8426 i
= putpkt (rs
->buf
);
8430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8431 strcpy ((char *) readbuf
, rs
->buf
);
8433 return strlen ((char *) readbuf
);
8437 remote_search_memory (struct target_ops
* ops
,
8438 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8439 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8440 CORE_ADDR
*found_addrp
)
8442 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8443 struct remote_state
*rs
= get_remote_state ();
8444 int max_size
= get_memory_write_packet_size ();
8445 struct packet_config
*packet
=
8446 &remote_protocol_packets
[PACKET_qSearch_memory
];
8447 /* Number of packet bytes used to encode the pattern;
8448 this could be more than PATTERN_LEN due to escape characters. */
8449 int escaped_pattern_len
;
8450 /* Amount of pattern that was encodable in the packet. */
8451 int used_pattern_len
;
8454 ULONGEST found_addr
;
8456 /* Don't go to the target if we don't have to.
8457 This is done before checking packet->support to avoid the possibility that
8458 a success for this edge case means the facility works in general. */
8459 if (pattern_len
> search_space_len
)
8461 if (pattern_len
== 0)
8463 *found_addrp
= start_addr
;
8467 /* If we already know the packet isn't supported, fall back to the simple
8468 way of searching memory. */
8470 if (packet
->support
== PACKET_DISABLE
)
8472 /* Target doesn't provided special support, fall back and use the
8473 standard support (copy memory and do the search here). */
8474 return simple_search_memory (ops
, start_addr
, search_space_len
,
8475 pattern
, pattern_len
, found_addrp
);
8478 /* Insert header. */
8479 i
= snprintf (rs
->buf
, max_size
,
8480 "qSearch:memory:%s;%s;",
8481 phex_nz (start_addr
, addr_size
),
8482 phex_nz (search_space_len
, sizeof (search_space_len
)));
8483 max_size
-= (i
+ 1);
8485 /* Escape as much data as fits into rs->buf. */
8486 escaped_pattern_len
=
8487 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8488 &used_pattern_len
, max_size
);
8490 /* Bail if the pattern is too large. */
8491 if (used_pattern_len
!= pattern_len
)
8492 error (_("Pattern is too large to transmit to remote target."));
8494 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8495 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8496 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8498 /* The request may not have worked because the command is not
8499 supported. If so, fall back to the simple way. */
8500 if (packet
->support
== PACKET_DISABLE
)
8502 return simple_search_memory (ops
, start_addr
, search_space_len
,
8503 pattern
, pattern_len
, found_addrp
);
8508 if (rs
->buf
[0] == '0')
8510 else if (rs
->buf
[0] == '1')
8513 if (rs
->buf
[1] != ',')
8514 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8515 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8516 *found_addrp
= found_addr
;
8519 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8525 remote_rcmd (char *command
,
8526 struct ui_file
*outbuf
)
8528 struct remote_state
*rs
= get_remote_state ();
8532 error (_("remote rcmd is only available after target open"));
8534 /* Send a NULL command across as an empty command. */
8535 if (command
== NULL
)
8538 /* The query prefix. */
8539 strcpy (rs
->buf
, "qRcmd,");
8540 p
= strchr (rs
->buf
, '\0');
8542 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8543 > get_remote_packet_size ())
8544 error (_("\"monitor\" command ``%s'' is too long."), command
);
8546 /* Encode the actual command. */
8547 bin2hex ((gdb_byte
*) command
, p
, 0);
8549 if (putpkt (rs
->buf
) < 0)
8550 error (_("Communication problem with target."));
8552 /* get/display the response */
8557 /* XXX - see also remote_get_noisy_reply(). */
8559 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8562 error (_("Target does not support this command."));
8563 if (buf
[0] == 'O' && buf
[1] != 'K')
8565 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8568 if (strcmp (buf
, "OK") == 0)
8570 if (strlen (buf
) == 3 && buf
[0] == 'E'
8571 && isdigit (buf
[1]) && isdigit (buf
[2]))
8573 error (_("Protocol error with Rcmd"));
8575 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8577 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8579 fputc_unfiltered (c
, outbuf
);
8585 static VEC(mem_region_s
) *
8586 remote_memory_map (struct target_ops
*ops
)
8588 VEC(mem_region_s
) *result
= NULL
;
8589 char *text
= target_read_stralloc (¤t_target
,
8590 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8594 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8596 result
= parse_memory_map (text
);
8597 do_cleanups (back_to
);
8604 packet_command (char *args
, int from_tty
)
8606 struct remote_state
*rs
= get_remote_state ();
8609 error (_("command can only be used with remote target"));
8612 error (_("remote-packet command requires packet text as argument"));
8614 puts_filtered ("sending: ");
8615 print_packet (args
);
8616 puts_filtered ("\n");
8619 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8620 puts_filtered ("received: ");
8621 print_packet (rs
->buf
);
8622 puts_filtered ("\n");
8626 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8628 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8630 static void threadset_test_cmd (char *cmd
, int tty
);
8632 static void threadalive_test (char *cmd
, int tty
);
8634 static void threadlist_test_cmd (char *cmd
, int tty
);
8636 int get_and_display_threadinfo (threadref
*ref
);
8638 static void threadinfo_test_cmd (char *cmd
, int tty
);
8640 static int thread_display_step (threadref
*ref
, void *context
);
8642 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8644 static void init_remote_threadtests (void);
8646 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8649 threadset_test_cmd (char *cmd
, int tty
)
8651 int sample_thread
= SAMPLE_THREAD
;
8653 printf_filtered (_("Remote threadset test\n"));
8654 set_general_thread (sample_thread
);
8659 threadalive_test (char *cmd
, int tty
)
8661 int sample_thread
= SAMPLE_THREAD
;
8662 int pid
= ptid_get_pid (inferior_ptid
);
8663 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8665 if (remote_thread_alive (ptid
))
8666 printf_filtered ("PASS: Thread alive test\n");
8668 printf_filtered ("FAIL: Thread alive test\n");
8671 void output_threadid (char *title
, threadref
*ref
);
8674 output_threadid (char *title
, threadref
*ref
)
8678 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8680 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8684 threadlist_test_cmd (char *cmd
, int tty
)
8687 threadref nextthread
;
8688 int done
, result_count
;
8689 threadref threadlist
[3];
8691 printf_filtered ("Remote Threadlist test\n");
8692 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8693 &result_count
, &threadlist
[0]))
8694 printf_filtered ("FAIL: threadlist test\n");
8697 threadref
*scan
= threadlist
;
8698 threadref
*limit
= scan
+ result_count
;
8700 while (scan
< limit
)
8701 output_threadid (" thread ", scan
++);
8706 display_thread_info (struct gdb_ext_thread_info
*info
)
8708 output_threadid ("Threadid: ", &info
->threadid
);
8709 printf_filtered ("Name: %s\n ", info
->shortname
);
8710 printf_filtered ("State: %s\n", info
->display
);
8711 printf_filtered ("other: %s\n\n", info
->more_display
);
8715 get_and_display_threadinfo (threadref
*ref
)
8719 struct gdb_ext_thread_info threadinfo
;
8721 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8722 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8723 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8724 display_thread_info (&threadinfo
);
8729 threadinfo_test_cmd (char *cmd
, int tty
)
8731 int athread
= SAMPLE_THREAD
;
8735 int_to_threadref (&thread
, athread
);
8736 printf_filtered ("Remote Threadinfo test\n");
8737 if (!get_and_display_threadinfo (&thread
))
8738 printf_filtered ("FAIL cannot get thread info\n");
8742 thread_display_step (threadref
*ref
, void *context
)
8744 /* output_threadid(" threadstep ",ref); *//* simple test */
8745 return get_and_display_threadinfo (ref
);
8749 threadlist_update_test_cmd (char *cmd
, int tty
)
8751 printf_filtered ("Remote Threadlist update test\n");
8752 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8756 init_remote_threadtests (void)
8758 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8759 _("Fetch and print the remote list of "
8760 "thread identifiers, one pkt only"));
8761 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8762 _("Fetch and display info about one thread"));
8763 add_com ("tset", class_obscure
, threadset_test_cmd
,
8764 _("Test setting to a different thread"));
8765 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8766 _("Iterate through updating all remote thread info"));
8767 add_com ("talive", class_obscure
, threadalive_test
,
8768 _(" Remote thread alive test "));
8773 /* Convert a thread ID to a string. Returns the string in a static
8777 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8779 static char buf
[64];
8780 struct remote_state
*rs
= get_remote_state ();
8782 if (ptid_is_pid (ptid
))
8784 /* Printing an inferior target id. */
8786 /* When multi-process extensions are off, there's no way in the
8787 remote protocol to know the remote process id, if there's any
8788 at all. There's one exception --- when we're connected with
8789 target extended-remote, and we manually attached to a process
8790 with "attach PID". We don't record anywhere a flag that
8791 allows us to distinguish that case from the case of
8792 connecting with extended-remote and the stub already being
8793 attached to a process, and reporting yes to qAttached, hence
8794 no smart special casing here. */
8795 if (!remote_multi_process_p (rs
))
8797 xsnprintf (buf
, sizeof buf
, "Remote target");
8801 return normal_pid_to_str (ptid
);
8805 if (ptid_equal (magic_null_ptid
, ptid
))
8806 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8807 else if (remote_multi_process_p (rs
))
8808 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8809 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8811 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8812 ptid_get_tid (ptid
));
8817 /* Get the address of the thread local variable in OBJFILE which is
8818 stored at OFFSET within the thread local storage for thread PTID. */
8821 remote_get_thread_local_address (struct target_ops
*ops
,
8822 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8824 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8826 struct remote_state
*rs
= get_remote_state ();
8828 char *endp
= rs
->buf
+ get_remote_packet_size ();
8829 enum packet_result result
;
8831 strcpy (p
, "qGetTLSAddr:");
8833 p
= write_ptid (p
, endp
, ptid
);
8835 p
+= hexnumstr (p
, offset
);
8837 p
+= hexnumstr (p
, lm
);
8841 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8842 result
= packet_ok (rs
->buf
,
8843 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8844 if (result
== PACKET_OK
)
8848 unpack_varlen_hex (rs
->buf
, &result
);
8851 else if (result
== PACKET_UNKNOWN
)
8852 throw_error (TLS_GENERIC_ERROR
,
8853 _("Remote target doesn't support qGetTLSAddr packet"));
8855 throw_error (TLS_GENERIC_ERROR
,
8856 _("Remote target failed to process qGetTLSAddr request"));
8859 throw_error (TLS_GENERIC_ERROR
,
8860 _("TLS not supported or disabled on this target"));
8865 /* Provide thread local base, i.e. Thread Information Block address.
8866 Returns 1 if ptid is found and thread_local_base is non zero. */
8869 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8871 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8873 struct remote_state
*rs
= get_remote_state ();
8875 char *endp
= rs
->buf
+ get_remote_packet_size ();
8876 enum packet_result result
;
8878 strcpy (p
, "qGetTIBAddr:");
8880 p
= write_ptid (p
, endp
, ptid
);
8884 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8885 result
= packet_ok (rs
->buf
,
8886 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8887 if (result
== PACKET_OK
)
8891 unpack_varlen_hex (rs
->buf
, &result
);
8893 *addr
= (CORE_ADDR
) result
;
8896 else if (result
== PACKET_UNKNOWN
)
8897 error (_("Remote target doesn't support qGetTIBAddr packet"));
8899 error (_("Remote target failed to process qGetTIBAddr request"));
8902 error (_("qGetTIBAddr not supported or disabled on this target"));
8907 /* Support for inferring a target description based on the current
8908 architecture and the size of a 'g' packet. While the 'g' packet
8909 can have any size (since optional registers can be left off the
8910 end), some sizes are easily recognizable given knowledge of the
8911 approximate architecture. */
8913 struct remote_g_packet_guess
8916 const struct target_desc
*tdesc
;
8918 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8919 DEF_VEC_O(remote_g_packet_guess_s
);
8921 struct remote_g_packet_data
8923 VEC(remote_g_packet_guess_s
) *guesses
;
8926 static struct gdbarch_data
*remote_g_packet_data_handle
;
8929 remote_g_packet_data_init (struct obstack
*obstack
)
8931 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8935 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8936 const struct target_desc
*tdesc
)
8938 struct remote_g_packet_data
*data
8939 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8940 struct remote_g_packet_guess new_guess
, *guess
;
8943 gdb_assert (tdesc
!= NULL
);
8946 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8948 if (guess
->bytes
== bytes
)
8949 internal_error (__FILE__
, __LINE__
,
8950 _("Duplicate g packet description added for size %d"),
8953 new_guess
.bytes
= bytes
;
8954 new_guess
.tdesc
= tdesc
;
8955 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8958 /* Return 1 if remote_read_description would do anything on this target
8959 and architecture, 0 otherwise. */
8962 remote_read_description_p (struct target_ops
*target
)
8964 struct remote_g_packet_data
*data
8965 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8967 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8973 static const struct target_desc
*
8974 remote_read_description (struct target_ops
*target
)
8976 struct remote_g_packet_data
*data
8977 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8979 /* Do not try this during initial connection, when we do not know
8980 whether there is a running but stopped thread. */
8981 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8984 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8986 struct remote_g_packet_guess
*guess
;
8988 int bytes
= send_g_packet ();
8991 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8993 if (guess
->bytes
== bytes
)
8994 return guess
->tdesc
;
8996 /* We discard the g packet. A minor optimization would be to
8997 hold on to it, and fill the register cache once we have selected
8998 an architecture, but it's too tricky to do safely. */
9004 /* Remote file transfer support. This is host-initiated I/O, not
9005 target-initiated; for target-initiated, see remote-fileio.c. */
9007 /* If *LEFT is at least the length of STRING, copy STRING to
9008 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9009 decrease *LEFT. Otherwise raise an error. */
9012 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9014 int len
= strlen (string
);
9017 error (_("Packet too long for target."));
9019 memcpy (*buffer
, string
, len
);
9023 /* NUL-terminate the buffer as a convenience, if there is
9029 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9030 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9031 decrease *LEFT. Otherwise raise an error. */
9034 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9037 if (2 * len
> *left
)
9038 error (_("Packet too long for target."));
9040 bin2hex (bytes
, *buffer
, len
);
9044 /* NUL-terminate the buffer as a convenience, if there is
9050 /* If *LEFT is large enough, convert VALUE to hex and add it to
9051 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9052 decrease *LEFT. Otherwise raise an error. */
9055 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9057 int len
= hexnumlen (value
);
9060 error (_("Packet too long for target."));
9062 hexnumstr (*buffer
, value
);
9066 /* NUL-terminate the buffer as a convenience, if there is
9072 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9073 value, *REMOTE_ERRNO to the remote error number or zero if none
9074 was included, and *ATTACHMENT to point to the start of the annex
9075 if any. The length of the packet isn't needed here; there may
9076 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9078 Return 0 if the packet could be parsed, -1 if it could not. If
9079 -1 is returned, the other variables may not be initialized. */
9082 remote_hostio_parse_result (char *buffer
, int *retcode
,
9083 int *remote_errno
, char **attachment
)
9090 if (buffer
[0] != 'F')
9094 *retcode
= strtol (&buffer
[1], &p
, 16);
9095 if (errno
!= 0 || p
== &buffer
[1])
9098 /* Check for ",errno". */
9102 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9103 if (errno
!= 0 || p
+ 1 == p2
)
9108 /* Check for ";attachment". If there is no attachment, the
9109 packet should end here. */
9112 *attachment
= p
+ 1;
9115 else if (*p
== '\0')
9121 /* Send a prepared I/O packet to the target and read its response.
9122 The prepared packet is in the global RS->BUF before this function
9123 is called, and the answer is there when we return.
9125 COMMAND_BYTES is the length of the request to send, which may include
9126 binary data. WHICH_PACKET is the packet configuration to check
9127 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9128 is set to the error number and -1 is returned. Otherwise the value
9129 returned by the function is returned.
9131 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9132 attachment is expected; an error will be reported if there's a
9133 mismatch. If one is found, *ATTACHMENT will be set to point into
9134 the packet buffer and *ATTACHMENT_LEN will be set to the
9135 attachment's length. */
9138 remote_hostio_send_command (int command_bytes
, int which_packet
,
9139 int *remote_errno
, char **attachment
,
9140 int *attachment_len
)
9142 struct remote_state
*rs
= get_remote_state ();
9143 int ret
, bytes_read
;
9144 char *attachment_tmp
;
9147 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9149 *remote_errno
= FILEIO_ENOSYS
;
9153 putpkt_binary (rs
->buf
, command_bytes
);
9154 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9156 /* If it timed out, something is wrong. Don't try to parse the
9160 *remote_errno
= FILEIO_EINVAL
;
9164 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9167 *remote_errno
= FILEIO_EINVAL
;
9169 case PACKET_UNKNOWN
:
9170 *remote_errno
= FILEIO_ENOSYS
;
9176 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9179 *remote_errno
= FILEIO_EINVAL
;
9183 /* Make sure we saw an attachment if and only if we expected one. */
9184 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9185 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9187 *remote_errno
= FILEIO_EINVAL
;
9191 /* If an attachment was found, it must point into the packet buffer;
9192 work out how many bytes there were. */
9193 if (attachment_tmp
!= NULL
)
9195 *attachment
= attachment_tmp
;
9196 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9202 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9203 remote file descriptor, or -1 if an error occurs (and set
9207 remote_hostio_open (const char *filename
, int flags
, int mode
,
9210 struct remote_state
*rs
= get_remote_state ();
9212 int left
= get_remote_packet_size () - 1;
9214 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9216 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9218 remote_buffer_add_string (&p
, &left
, ",");
9220 remote_buffer_add_int (&p
, &left
, flags
);
9221 remote_buffer_add_string (&p
, &left
, ",");
9223 remote_buffer_add_int (&p
, &left
, mode
);
9225 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9226 remote_errno
, NULL
, NULL
);
9229 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9230 Return the number of bytes written, or -1 if an error occurs (and
9231 set *REMOTE_ERRNO). */
9234 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9235 ULONGEST offset
, int *remote_errno
)
9237 struct remote_state
*rs
= get_remote_state ();
9239 int left
= get_remote_packet_size ();
9242 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9244 remote_buffer_add_int (&p
, &left
, fd
);
9245 remote_buffer_add_string (&p
, &left
, ",");
9247 remote_buffer_add_int (&p
, &left
, offset
);
9248 remote_buffer_add_string (&p
, &left
, ",");
9250 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9251 get_remote_packet_size () - (p
- rs
->buf
));
9253 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9254 remote_errno
, NULL
, NULL
);
9257 /* Read up to LEN bytes FD on the remote target into READ_BUF
9258 Return the number of bytes read, or -1 if an error occurs (and
9259 set *REMOTE_ERRNO). */
9262 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9263 ULONGEST offset
, int *remote_errno
)
9265 struct remote_state
*rs
= get_remote_state ();
9268 int left
= get_remote_packet_size ();
9269 int ret
, attachment_len
;
9272 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9274 remote_buffer_add_int (&p
, &left
, fd
);
9275 remote_buffer_add_string (&p
, &left
, ",");
9277 remote_buffer_add_int (&p
, &left
, len
);
9278 remote_buffer_add_string (&p
, &left
, ",");
9280 remote_buffer_add_int (&p
, &left
, offset
);
9282 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9283 remote_errno
, &attachment
,
9289 read_len
= remote_unescape_input (attachment
, attachment_len
,
9291 if (read_len
!= ret
)
9292 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9297 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9298 (and set *REMOTE_ERRNO). */
9301 remote_hostio_close (int fd
, int *remote_errno
)
9303 struct remote_state
*rs
= get_remote_state ();
9305 int left
= get_remote_packet_size () - 1;
9307 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9309 remote_buffer_add_int (&p
, &left
, fd
);
9311 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9312 remote_errno
, NULL
, NULL
);
9315 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9316 occurs (and set *REMOTE_ERRNO). */
9319 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9321 struct remote_state
*rs
= get_remote_state ();
9323 int left
= get_remote_packet_size () - 1;
9325 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9327 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9330 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9331 remote_errno
, NULL
, NULL
);
9335 remote_fileio_errno_to_host (int errnum
)
9359 case FILEIO_ENOTDIR
:
9379 case FILEIO_ENAMETOOLONG
:
9380 return ENAMETOOLONG
;
9386 remote_hostio_error (int errnum
)
9388 int host_error
= remote_fileio_errno_to_host (errnum
);
9390 if (host_error
== -1)
9391 error (_("Unknown remote I/O error %d"), errnum
);
9393 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9397 remote_hostio_close_cleanup (void *opaque
)
9399 int fd
= *(int *) opaque
;
9402 remote_hostio_close (fd
, &remote_errno
);
9407 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9409 const char *filename
= bfd_get_filename (abfd
);
9410 int fd
, remote_errno
;
9413 gdb_assert (remote_filename_p (filename
));
9415 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9418 errno
= remote_fileio_errno_to_host (remote_errno
);
9419 bfd_set_error (bfd_error_system_call
);
9423 stream
= xmalloc (sizeof (int));
9429 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9431 int fd
= *(int *)stream
;
9436 /* Ignore errors on close; these may happen if the remote
9437 connection was already torn down. */
9438 remote_hostio_close (fd
, &remote_errno
);
9444 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9445 file_ptr nbytes
, file_ptr offset
)
9447 int fd
= *(int *)stream
;
9449 file_ptr pos
, bytes
;
9452 while (nbytes
> pos
)
9454 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9455 offset
+ pos
, &remote_errno
);
9457 /* Success, but no bytes, means end-of-file. */
9461 errno
= remote_fileio_errno_to_host (remote_errno
);
9462 bfd_set_error (bfd_error_system_call
);
9473 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9475 /* FIXME: We should probably implement remote_hostio_stat. */
9476 sb
->st_size
= INT_MAX
;
9481 remote_filename_p (const char *filename
)
9483 return strncmp (filename
, "remote:", 7) == 0;
9487 remote_bfd_open (const char *remote_file
, const char *target
)
9489 return bfd_openr_iovec (remote_file
, target
,
9490 remote_bfd_iovec_open
, NULL
,
9491 remote_bfd_iovec_pread
,
9492 remote_bfd_iovec_close
,
9493 remote_bfd_iovec_stat
);
9497 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9499 struct cleanup
*back_to
, *close_cleanup
;
9500 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9503 int bytes_in_buffer
;
9508 error (_("command can only be used with remote target"));
9510 file
= fopen (local_file
, "rb");
9512 perror_with_name (local_file
);
9513 back_to
= make_cleanup_fclose (file
);
9515 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9517 0700, &remote_errno
);
9519 remote_hostio_error (remote_errno
);
9521 /* Send up to this many bytes at once. They won't all fit in the
9522 remote packet limit, so we'll transfer slightly fewer. */
9523 io_size
= get_remote_packet_size ();
9524 buffer
= xmalloc (io_size
);
9525 make_cleanup (xfree
, buffer
);
9527 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9529 bytes_in_buffer
= 0;
9532 while (bytes_in_buffer
|| !saw_eof
)
9536 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9537 io_size
- bytes_in_buffer
,
9542 error (_("Error reading %s."), local_file
);
9545 /* EOF. Unless there is something still in the
9546 buffer from the last iteration, we are done. */
9548 if (bytes_in_buffer
== 0)
9556 bytes
+= bytes_in_buffer
;
9557 bytes_in_buffer
= 0;
9559 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9560 offset
, &remote_errno
);
9563 remote_hostio_error (remote_errno
);
9564 else if (retcode
== 0)
9565 error (_("Remote write of %d bytes returned 0!"), bytes
);
9566 else if (retcode
< bytes
)
9568 /* Short write. Save the rest of the read data for the next
9570 bytes_in_buffer
= bytes
- retcode
;
9571 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9577 discard_cleanups (close_cleanup
);
9578 if (remote_hostio_close (fd
, &remote_errno
))
9579 remote_hostio_error (remote_errno
);
9582 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9583 do_cleanups (back_to
);
9587 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9589 struct cleanup
*back_to
, *close_cleanup
;
9590 int fd
, remote_errno
, bytes
, io_size
;
9596 error (_("command can only be used with remote target"));
9598 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9600 remote_hostio_error (remote_errno
);
9602 file
= fopen (local_file
, "wb");
9604 perror_with_name (local_file
);
9605 back_to
= make_cleanup_fclose (file
);
9607 /* Send up to this many bytes at once. They won't all fit in the
9608 remote packet limit, so we'll transfer slightly fewer. */
9609 io_size
= get_remote_packet_size ();
9610 buffer
= xmalloc (io_size
);
9611 make_cleanup (xfree
, buffer
);
9613 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9618 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9620 /* Success, but no bytes, means end-of-file. */
9623 remote_hostio_error (remote_errno
);
9627 bytes
= fwrite (buffer
, 1, bytes
, file
);
9629 perror_with_name (local_file
);
9632 discard_cleanups (close_cleanup
);
9633 if (remote_hostio_close (fd
, &remote_errno
))
9634 remote_hostio_error (remote_errno
);
9637 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9638 do_cleanups (back_to
);
9642 remote_file_delete (const char *remote_file
, int from_tty
)
9644 int retcode
, remote_errno
;
9647 error (_("command can only be used with remote target"));
9649 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9651 remote_hostio_error (remote_errno
);
9654 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9658 remote_put_command (char *args
, int from_tty
)
9660 struct cleanup
*back_to
;
9664 error_no_arg (_("file to put"));
9666 argv
= gdb_buildargv (args
);
9667 back_to
= make_cleanup_freeargv (argv
);
9668 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9669 error (_("Invalid parameters to remote put"));
9671 remote_file_put (argv
[0], argv
[1], from_tty
);
9673 do_cleanups (back_to
);
9677 remote_get_command (char *args
, int from_tty
)
9679 struct cleanup
*back_to
;
9683 error_no_arg (_("file to get"));
9685 argv
= gdb_buildargv (args
);
9686 back_to
= make_cleanup_freeargv (argv
);
9687 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9688 error (_("Invalid parameters to remote get"));
9690 remote_file_get (argv
[0], argv
[1], from_tty
);
9692 do_cleanups (back_to
);
9696 remote_delete_command (char *args
, int from_tty
)
9698 struct cleanup
*back_to
;
9702 error_no_arg (_("file to delete"));
9704 argv
= gdb_buildargv (args
);
9705 back_to
= make_cleanup_freeargv (argv
);
9706 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9707 error (_("Invalid parameters to remote delete"));
9709 remote_file_delete (argv
[0], from_tty
);
9711 do_cleanups (back_to
);
9715 remote_command (char *args
, int from_tty
)
9717 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9721 remote_can_execute_reverse (void)
9723 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9724 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9731 remote_supports_non_stop (void)
9737 remote_supports_disable_randomization (void)
9739 /* Only supported in extended mode. */
9744 remote_supports_multi_process (void)
9746 struct remote_state
*rs
= get_remote_state ();
9748 return remote_multi_process_p (rs
);
9752 remote_supports_cond_tracepoints (void)
9754 struct remote_state
*rs
= get_remote_state ();
9756 return rs
->cond_tracepoints
;
9760 remote_supports_fast_tracepoints (void)
9762 struct remote_state
*rs
= get_remote_state ();
9764 return rs
->fast_tracepoints
;
9768 remote_supports_static_tracepoints (void)
9770 struct remote_state
*rs
= get_remote_state ();
9772 return rs
->static_tracepoints
;
9776 remote_supports_install_in_trace (void)
9778 struct remote_state
*rs
= get_remote_state ();
9780 return rs
->install_in_trace
;
9784 remote_supports_enable_disable_tracepoint (void)
9786 struct remote_state
*rs
= get_remote_state ();
9788 return rs
->enable_disable_tracepoints
;
9792 remote_supports_string_tracing (void)
9794 struct remote_state
*rs
= get_remote_state ();
9796 return rs
->string_tracing
;
9800 remote_trace_init (void)
9803 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9804 if (strcmp (target_buf
, "OK") != 0)
9805 error (_("Target does not support this command."));
9808 static void free_actions_list (char **actions_list
);
9809 static void free_actions_list_cleanup_wrapper (void *);
9811 free_actions_list_cleanup_wrapper (void *al
)
9813 free_actions_list (al
);
9817 free_actions_list (char **actions_list
)
9821 if (actions_list
== 0)
9824 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9825 xfree (actions_list
[ndx
]);
9827 xfree (actions_list
);
9830 /* Recursive routine to walk through command list including loops, and
9831 download packets for each command. */
9834 remote_download_command_source (int num
, ULONGEST addr
,
9835 struct command_line
*cmds
)
9837 struct remote_state
*rs
= get_remote_state ();
9838 struct command_line
*cmd
;
9840 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9842 QUIT
; /* Allow user to bail out with ^C. */
9843 strcpy (rs
->buf
, "QTDPsrc:");
9844 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9845 rs
->buf
+ strlen (rs
->buf
),
9846 rs
->buf_size
- strlen (rs
->buf
));
9848 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9849 if (strcmp (target_buf
, "OK"))
9850 warning (_("Target does not support source download."));
9852 if (cmd
->control_type
== while_control
9853 || cmd
->control_type
== while_stepping_control
)
9855 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9857 QUIT
; /* Allow user to bail out with ^C. */
9858 strcpy (rs
->buf
, "QTDPsrc:");
9859 encode_source_string (num
, addr
, "cmd", "end",
9860 rs
->buf
+ strlen (rs
->buf
),
9861 rs
->buf_size
- strlen (rs
->buf
));
9863 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9864 if (strcmp (target_buf
, "OK"))
9865 warning (_("Target does not support source download."));
9871 remote_download_tracepoint (struct bp_location
*loc
)
9878 char **stepping_actions
;
9880 struct cleanup
*old_chain
= NULL
;
9881 struct agent_expr
*aexpr
;
9882 struct cleanup
*aexpr_chain
= NULL
;
9884 struct breakpoint
*b
= loc
->owner
;
9885 struct tracepoint
*t
= (struct tracepoint
*) b
;
9887 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9888 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9890 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9893 tpaddr
= loc
->address
;
9894 sprintf_vma (addrbuf
, tpaddr
);
9895 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9896 addrbuf
, /* address */
9897 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9898 t
->step_count
, t
->pass_count
);
9899 /* Fast tracepoints are mostly handled by the target, but we can
9900 tell the target how big of an instruction block should be moved
9902 if (b
->type
== bp_fast_tracepoint
)
9904 /* Only test for support at download time; we may not know
9905 target capabilities at definition time. */
9906 if (remote_supports_fast_tracepoints ())
9910 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9911 tpaddr
, &isize
, NULL
))
9912 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9914 /* If it passed validation at definition but fails now,
9915 something is very wrong. */
9916 internal_error (__FILE__
, __LINE__
,
9917 _("Fast tracepoint not "
9918 "valid during download"));
9921 /* Fast tracepoints are functionally identical to regular
9922 tracepoints, so don't take lack of support as a reason to
9923 give up on the trace run. */
9924 warning (_("Target does not support fast tracepoints, "
9925 "downloading %d as regular tracepoint"), b
->number
);
9927 else if (b
->type
== bp_static_tracepoint
)
9929 /* Only test for support at download time; we may not know
9930 target capabilities at definition time. */
9931 if (remote_supports_static_tracepoints ())
9933 struct static_tracepoint_marker marker
;
9935 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
9938 error (_("Static tracepoint not valid during download"));
9941 /* Fast tracepoints are functionally identical to regular
9942 tracepoints, so don't take lack of support as a reason
9943 to give up on the trace run. */
9944 error (_("Target does not support static tracepoints"));
9946 /* If the tracepoint has a conditional, make it into an agent
9947 expression and append to the definition. */
9950 /* Only test support at download time, we may not know target
9951 capabilities at definition time. */
9952 if (remote_supports_cond_tracepoints ())
9954 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9955 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9956 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9957 pkt
= buf
+ strlen (buf
);
9958 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9959 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9961 do_cleanups (aexpr_chain
);
9964 warning (_("Target does not support conditional tracepoints, "
9965 "ignoring tp %d cond"), b
->number
);
9968 if (b
->commands
|| *default_collect
)
9971 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9972 if (strcmp (target_buf
, "OK"))
9973 error (_("Target does not support tracepoints."));
9975 /* do_single_steps (t); */
9978 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9980 QUIT
; /* Allow user to bail out with ^C. */
9981 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9982 b
->number
, addrbuf
, /* address */
9984 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9987 remote_get_noisy_reply (&target_buf
,
9989 if (strcmp (target_buf
, "OK"))
9990 error (_("Error on target while setting tracepoints."));
9993 if (stepping_actions
)
9995 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9997 QUIT
; /* Allow user to bail out with ^C. */
9998 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9999 b
->number
, addrbuf
, /* address */
10000 ((ndx
== 0) ? "S" : ""),
10001 stepping_actions
[ndx
],
10002 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10004 remote_get_noisy_reply (&target_buf
,
10006 if (strcmp (target_buf
, "OK"))
10007 error (_("Error on target while setting tracepoints."));
10011 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10014 if (b
->addr_string
)
10016 strcpy (buf
, "QTDPsrc:");
10017 encode_source_string (b
->number
, loc
->address
,
10018 "at", b
->addr_string
, buf
+ strlen (buf
),
10019 2048 - strlen (buf
));
10022 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10023 if (strcmp (target_buf
, "OK"))
10024 warning (_("Target does not support source download."));
10026 if (b
->cond_string
)
10028 strcpy (buf
, "QTDPsrc:");
10029 encode_source_string (b
->number
, loc
->address
,
10030 "cond", b
->cond_string
, buf
+ strlen (buf
),
10031 2048 - strlen (buf
));
10033 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10034 if (strcmp (target_buf
, "OK"))
10035 warning (_("Target does not support source download."));
10037 remote_download_command_source (b
->number
, loc
->address
,
10038 breakpoint_commands (b
));
10041 do_cleanups (old_chain
);
10045 remote_can_download_tracepoint (void)
10047 struct trace_status
*ts
= current_trace_status ();
10048 int status
= remote_get_trace_status (ts
);
10050 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10053 /* If we are in a tracing experiment, but remote stub doesn't support
10054 installing tracepoint in trace, we have to return. */
10055 if (!remote_supports_install_in_trace ())
10063 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10065 struct remote_state
*rs
= get_remote_state ();
10068 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10069 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10070 p
= rs
->buf
+ strlen (rs
->buf
);
10071 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10072 error (_("Trace state variable name too long for tsv definition packet"));
10073 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10076 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10077 if (*target_buf
== '\0')
10078 error (_("Target does not support this command."));
10079 if (strcmp (target_buf
, "OK") != 0)
10080 error (_("Error on target while downloading trace state variable."));
10084 remote_enable_tracepoint (struct bp_location
*location
)
10086 struct remote_state
*rs
= get_remote_state ();
10089 sprintf_vma (addr_buf
, location
->address
);
10090 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10092 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10093 if (*rs
->buf
== '\0')
10094 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10095 if (strcmp (rs
->buf
, "OK") != 0)
10096 error (_("Error on target while enabling tracepoint."));
10100 remote_disable_tracepoint (struct bp_location
*location
)
10102 struct remote_state
*rs
= get_remote_state ();
10105 sprintf_vma (addr_buf
, location
->address
);
10106 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10108 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10109 if (*rs
->buf
== '\0')
10110 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10111 if (strcmp (rs
->buf
, "OK") != 0)
10112 error (_("Error on target while disabling tracepoint."));
10116 remote_trace_set_readonly_regions (void)
10119 bfd_size_type size
;
10125 return; /* No information to give. */
10127 strcpy (target_buf
, "QTro");
10128 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10130 char tmp1
[40], tmp2
[40];
10133 if ((s
->flags
& SEC_LOAD
) == 0 ||
10134 /* (s->flags & SEC_CODE) == 0 || */
10135 (s
->flags
& SEC_READONLY
) == 0)
10139 vma
= bfd_get_section_vma (,s
);
10140 size
= bfd_get_section_size (s
);
10141 sprintf_vma (tmp1
, vma
);
10142 sprintf_vma (tmp2
, vma
+ size
);
10143 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10144 if (offset
+ sec_length
+ 1 > target_buf_size
)
10146 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10149 Too many sections for read-only sections definition packet."));
10152 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10153 offset
+= sec_length
;
10157 putpkt (target_buf
);
10158 getpkt (&target_buf
, &target_buf_size
, 0);
10163 remote_trace_start (void)
10165 putpkt ("QTStart");
10166 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10167 if (*target_buf
== '\0')
10168 error (_("Target does not support this command."));
10169 if (strcmp (target_buf
, "OK") != 0)
10170 error (_("Bogus reply from target: %s"), target_buf
);
10174 remote_get_trace_status (struct trace_status
*ts
)
10176 /* Initialize it just to avoid a GCC false warning. */
10178 /* FIXME we need to get register block size some other way. */
10179 extern int trace_regblock_size
;
10180 volatile struct gdb_exception ex
;
10182 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10184 putpkt ("qTStatus");
10186 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10188 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10192 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10196 /* If the remote target doesn't do tracing, flag it. */
10200 /* We're working with a live target. */
10203 /* Set some defaults. */
10204 ts
->running_known
= 0;
10205 ts
->stop_reason
= trace_stop_reason_unknown
;
10206 ts
->traceframe_count
= -1;
10207 ts
->buffer_free
= 0;
10210 error (_("Bogus trace status reply from target: %s"), target_buf
);
10212 parse_trace_status (p
, ts
);
10214 return ts
->running
;
10218 remote_get_tracepoint_status (struct breakpoint
*bp
,
10219 struct uploaded_tp
*utp
)
10221 struct remote_state
*rs
= get_remote_state ();
10223 struct bp_location
*loc
;
10224 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10228 tp
->base
.hit_count
= 0;
10229 tp
->traceframe_usage
= 0;
10230 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10232 /* If the tracepoint was never downloaded, don't go asking for
10234 if (tp
->number_on_target
== 0)
10236 sprintf (rs
->buf
, "qTP:%x:%s", tp
->number_on_target
,
10237 phex_nz (loc
->address
, 0));
10239 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10240 if (reply
&& *reply
)
10243 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10249 utp
->hit_count
= 0;
10250 utp
->traceframe_usage
= 0;
10251 sprintf (rs
->buf
, "qTP:%x:%s", utp
->number
, phex_nz (utp
->addr
, 0));
10253 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10254 if (reply
&& *reply
)
10257 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10263 remote_trace_stop (void)
10266 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10267 if (*target_buf
== '\0')
10268 error (_("Target does not support this command."));
10269 if (strcmp (target_buf
, "OK") != 0)
10270 error (_("Bogus reply from target: %s"), target_buf
);
10274 remote_trace_find (enum trace_find_type type
, int num
,
10275 ULONGEST addr1
, ULONGEST addr2
,
10278 struct remote_state
*rs
= get_remote_state ();
10280 int target_frameno
= -1, target_tracept
= -1;
10282 /* Lookups other than by absolute frame number depend on the current
10283 trace selected, so make sure it is correct on the remote end
10285 if (type
!= tfind_number
)
10286 set_remote_traceframe ();
10289 strcpy (p
, "QTFrame:");
10290 p
= strchr (p
, '\0');
10294 sprintf (p
, "%x", num
);
10297 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10300 sprintf (p
, "tdp:%x", num
);
10303 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10305 case tfind_outside
:
10306 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10309 error (_("Unknown trace find type %d"), type
);
10313 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10314 if (*reply
== '\0')
10315 error (_("Target does not support this command."));
10317 while (reply
&& *reply
)
10322 target_frameno
= (int) strtol (p
, &reply
, 16);
10324 error (_("Unable to parse trace frame number"));
10325 /* Don't update our remote traceframe number cache on failure
10326 to select a remote traceframe. */
10327 if (target_frameno
== -1)
10332 target_tracept
= (int) strtol (p
, &reply
, 16);
10334 error (_("Unable to parse tracepoint number"));
10336 case 'O': /* "OK"? */
10337 if (reply
[1] == 'K' && reply
[2] == '\0')
10340 error (_("Bogus reply from target: %s"), reply
);
10343 error (_("Bogus reply from target: %s"), reply
);
10346 *tpp
= target_tracept
;
10348 remote_traceframe_number
= target_frameno
;
10349 return target_frameno
;
10353 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10355 struct remote_state
*rs
= get_remote_state ();
10359 set_remote_traceframe ();
10361 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10363 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10364 if (reply
&& *reply
)
10368 unpack_varlen_hex (reply
+ 1, &uval
);
10369 *val
= (LONGEST
) uval
;
10377 remote_save_trace_data (const char *filename
)
10379 struct remote_state
*rs
= get_remote_state ();
10383 strcpy (p
, "QTSave:");
10385 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10386 error (_("Remote file name too long for trace save packet"));
10387 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10390 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10391 if (*reply
== '\0')
10392 error (_("Target does not support this command."));
10393 if (strcmp (reply
, "OK") != 0)
10394 error (_("Bogus reply from target: %s"), reply
);
10398 /* This is basically a memory transfer, but needs to be its own packet
10399 because we don't know how the target actually organizes its trace
10400 memory, plus we want to be able to ask for as much as possible, but
10401 not be unhappy if we don't get as much as we ask for. */
10404 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10406 struct remote_state
*rs
= get_remote_state ();
10412 strcpy (p
, "qTBuffer:");
10414 p
+= hexnumstr (p
, offset
);
10416 p
+= hexnumstr (p
, len
);
10420 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10421 if (reply
&& *reply
)
10423 /* 'l' by itself means we're at the end of the buffer and
10424 there is nothing more to get. */
10428 /* Convert the reply into binary. Limit the number of bytes to
10429 convert according to our passed-in buffer size, rather than
10430 what was returned in the packet; if the target is
10431 unexpectedly generous and gives us a bigger reply than we
10432 asked for, we don't want to crash. */
10433 rslt
= hex2bin (target_buf
, buf
, len
);
10437 /* Something went wrong, flag as an error. */
10442 remote_set_disconnected_tracing (int val
)
10444 struct remote_state
*rs
= get_remote_state ();
10446 if (rs
->disconnected_tracing
)
10450 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10452 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10453 if (*reply
== '\0')
10454 error (_("Target does not support this command."));
10455 if (strcmp (reply
, "OK") != 0)
10456 error (_("Bogus reply from target: %s"), reply
);
10459 warning (_("Target does not support disconnected tracing."));
10463 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10465 struct thread_info
*info
= find_thread_ptid (ptid
);
10467 if (info
&& info
->private)
10468 return info
->private->core
;
10473 remote_set_circular_trace_buffer (int val
)
10475 struct remote_state
*rs
= get_remote_state ();
10478 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10480 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10481 if (*reply
== '\0')
10482 error (_("Target does not support this command."));
10483 if (strcmp (reply
, "OK") != 0)
10484 error (_("Bogus reply from target: %s"), reply
);
10487 static struct traceframe_info
*
10488 remote_traceframe_info (void)
10492 text
= target_read_stralloc (¤t_target
,
10493 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10496 struct traceframe_info
*info
;
10497 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10499 info
= parse_traceframe_info (text
);
10500 do_cleanups (back_to
);
10507 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10508 instruction on which a fast tracepoint may be placed. Returns -1
10509 if the packet is not supported, and 0 if the minimum instruction
10510 length is unknown. */
10513 remote_get_min_fast_tracepoint_insn_len (void)
10515 struct remote_state
*rs
= get_remote_state ();
10518 sprintf (rs
->buf
, "qTMinFTPILen");
10520 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10521 if (*reply
== '\0')
10525 ULONGEST min_insn_len
;
10527 unpack_varlen_hex (reply
, &min_insn_len
);
10529 return (int) min_insn_len
;
10534 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10536 struct remote_state
*rs
= get_remote_state ();
10538 char *buf
= rs
->buf
;
10539 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10542 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10545 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10546 nbytes
= bin2hex (user
, buf
, 0);
10552 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10553 nbytes
= bin2hex (notes
, buf
, 0);
10559 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10560 nbytes
= bin2hex (stop_notes
, buf
, 0);
10564 /* Ensure the buffer is terminated. */
10568 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10569 if (*reply
== '\0')
10572 if (strcmp (reply
, "OK") != 0)
10573 error (_("Bogus reply from target: %s"), reply
);
10579 init_remote_ops (void)
10581 remote_ops
.to_shortname
= "remote";
10582 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10583 remote_ops
.to_doc
=
10584 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10585 Specify the serial device it is connected to\n\
10586 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10587 remote_ops
.to_open
= remote_open
;
10588 remote_ops
.to_close
= remote_close
;
10589 remote_ops
.to_detach
= remote_detach
;
10590 remote_ops
.to_disconnect
= remote_disconnect
;
10591 remote_ops
.to_resume
= remote_resume
;
10592 remote_ops
.to_wait
= remote_wait
;
10593 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10594 remote_ops
.to_store_registers
= remote_store_registers
;
10595 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10596 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10597 remote_ops
.to_files_info
= remote_files_info
;
10598 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10599 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10600 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10601 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10602 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10603 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10604 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10605 remote_ops
.to_region_ok_for_hw_watchpoint
10606 = remote_region_ok_for_hw_watchpoint
;
10607 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10608 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10609 remote_ops
.to_kill
= remote_kill
;
10610 remote_ops
.to_load
= generic_load
;
10611 remote_ops
.to_mourn_inferior
= remote_mourn
;
10612 remote_ops
.to_pass_signals
= remote_pass_signals
;
10613 remote_ops
.to_thread_alive
= remote_thread_alive
;
10614 remote_ops
.to_find_new_threads
= remote_threads_info
;
10615 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10616 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10617 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10618 remote_ops
.to_stop
= remote_stop
;
10619 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10620 remote_ops
.to_rcmd
= remote_rcmd
;
10621 remote_ops
.to_log_command
= serial_log_command
;
10622 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10623 remote_ops
.to_stratum
= process_stratum
;
10624 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10625 remote_ops
.to_has_memory
= default_child_has_memory
;
10626 remote_ops
.to_has_stack
= default_child_has_stack
;
10627 remote_ops
.to_has_registers
= default_child_has_registers
;
10628 remote_ops
.to_has_execution
= default_child_has_execution
;
10629 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10630 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10631 remote_ops
.to_magic
= OPS_MAGIC
;
10632 remote_ops
.to_memory_map
= remote_memory_map
;
10633 remote_ops
.to_flash_erase
= remote_flash_erase
;
10634 remote_ops
.to_flash_done
= remote_flash_done
;
10635 remote_ops
.to_read_description
= remote_read_description
;
10636 remote_ops
.to_search_memory
= remote_search_memory
;
10637 remote_ops
.to_can_async_p
= remote_can_async_p
;
10638 remote_ops
.to_is_async_p
= remote_is_async_p
;
10639 remote_ops
.to_async
= remote_async
;
10640 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10641 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10642 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10643 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10644 remote_ops
.to_supports_disable_randomization
10645 = remote_supports_disable_randomization
;
10646 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10647 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10648 remote_ops
.to_trace_init
= remote_trace_init
;
10649 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10650 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10651 remote_ops
.to_download_trace_state_variable
10652 = remote_download_trace_state_variable
;
10653 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10654 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10655 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10656 remote_ops
.to_trace_start
= remote_trace_start
;
10657 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10658 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
10659 remote_ops
.to_trace_stop
= remote_trace_stop
;
10660 remote_ops
.to_trace_find
= remote_trace_find
;
10661 remote_ops
.to_get_trace_state_variable_value
10662 = remote_get_trace_state_variable_value
;
10663 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10664 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10665 remote_ops
.to_upload_trace_state_variables
10666 = remote_upload_trace_state_variables
;
10667 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10668 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10669 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10670 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10671 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
10672 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10673 remote_ops
.to_verify_memory
= remote_verify_memory
;
10674 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10675 remote_ops
.to_set_permissions
= remote_set_permissions
;
10676 remote_ops
.to_static_tracepoint_marker_at
10677 = remote_static_tracepoint_marker_at
;
10678 remote_ops
.to_static_tracepoint_markers_by_strid
10679 = remote_static_tracepoint_markers_by_strid
;
10680 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10683 /* Set up the extended remote vector by making a copy of the standard
10684 remote vector and adding to it. */
10687 init_extended_remote_ops (void)
10689 extended_remote_ops
= remote_ops
;
10691 extended_remote_ops
.to_shortname
= "extended-remote";
10692 extended_remote_ops
.to_longname
=
10693 "Extended remote serial target in gdb-specific protocol";
10694 extended_remote_ops
.to_doc
=
10695 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10696 Specify the serial device it is connected to (e.g. /dev/ttya).";
10697 extended_remote_ops
.to_open
= extended_remote_open
;
10698 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10699 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10700 extended_remote_ops
.to_detach
= extended_remote_detach
;
10701 extended_remote_ops
.to_attach
= extended_remote_attach
;
10702 extended_remote_ops
.to_kill
= extended_remote_kill
;
10703 extended_remote_ops
.to_supports_disable_randomization
10704 = extended_remote_supports_disable_randomization
;
10708 remote_can_async_p (void)
10710 if (!target_async_permitted
)
10711 /* We only enable async when the user specifically asks for it. */
10714 /* We're async whenever the serial device is. */
10715 return serial_can_async_p (remote_desc
);
10719 remote_is_async_p (void)
10721 if (!target_async_permitted
)
10722 /* We only enable async when the user specifically asks for it. */
10725 /* We're async whenever the serial device is. */
10726 return serial_is_async_p (remote_desc
);
10729 /* Pass the SERIAL event on and up to the client. One day this code
10730 will be able to delay notifying the client of an event until the
10731 point where an entire packet has been received. */
10733 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10735 static void *async_client_context
;
10736 static serial_event_ftype remote_async_serial_handler
;
10739 remote_async_serial_handler (struct serial
*scb
, void *context
)
10741 /* Don't propogate error information up to the client. Instead let
10742 the client find out about the error by querying the target. */
10743 async_client_callback (INF_REG_EVENT
, async_client_context
);
10747 remote_async_inferior_event_handler (gdb_client_data data
)
10749 inferior_event_handler (INF_REG_EVENT
, NULL
);
10753 remote_async_get_pending_events_handler (gdb_client_data data
)
10755 remote_get_pending_stop_replies ();
10759 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10760 void *context
), void *context
)
10762 if (callback
!= NULL
)
10764 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10765 async_client_callback
= callback
;
10766 async_client_context
= context
;
10769 serial_async (remote_desc
, NULL
, NULL
);
10773 set_remote_cmd (char *args
, int from_tty
)
10775 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10779 show_remote_cmd (char *args
, int from_tty
)
10781 /* We can't just use cmd_show_list here, because we want to skip
10782 the redundant "show remote Z-packet" and the legacy aliases. */
10783 struct cleanup
*showlist_chain
;
10784 struct cmd_list_element
*list
= remote_show_cmdlist
;
10785 struct ui_out
*uiout
= current_uiout
;
10787 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10788 for (; list
!= NULL
; list
= list
->next
)
10789 if (strcmp (list
->name
, "Z-packet") == 0)
10791 else if (list
->type
== not_set_cmd
)
10792 /* Alias commands are exactly like the original, except they
10793 don't have the normal type. */
10797 struct cleanup
*option_chain
10798 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10800 ui_out_field_string (uiout
, "name", list
->name
);
10801 ui_out_text (uiout
, ": ");
10802 if (list
->type
== show_cmd
)
10803 do_setshow_command ((char *) NULL
, from_tty
, list
);
10805 cmd_func (list
, NULL
, from_tty
);
10806 /* Close the tuple. */
10807 do_cleanups (option_chain
);
10810 /* Close the tuple. */
10811 do_cleanups (showlist_chain
);
10815 /* Function to be called whenever a new objfile (shlib) is detected. */
10817 remote_new_objfile (struct objfile
*objfile
)
10819 if (remote_desc
!= 0) /* Have a remote connection. */
10820 remote_check_symbols (objfile
);
10823 /* Pull all the tracepoints defined on the target and create local
10824 data structures representing them. We don't want to create real
10825 tracepoints yet, we don't want to mess up the user's existing
10829 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10831 struct remote_state
*rs
= get_remote_state ();
10834 /* Ask for a first packet of tracepoint definition. */
10836 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10838 while (*p
&& *p
!= 'l')
10840 parse_tracepoint_definition (p
, utpp
);
10841 /* Ask for another packet of tracepoint definition. */
10843 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10850 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10852 struct remote_state
*rs
= get_remote_state ();
10855 /* Ask for a first packet of variable definition. */
10857 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10859 while (*p
&& *p
!= 'l')
10861 parse_tsv_definition (p
, utsvp
);
10862 /* Ask for another packet of variable definition. */
10864 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10871 _initialize_remote (void)
10873 struct remote_state
*rs
;
10874 struct cmd_list_element
*cmd
;
10877 /* architecture specific data */
10878 remote_gdbarch_data_handle
=
10879 gdbarch_data_register_post_init (init_remote_state
);
10880 remote_g_packet_data_handle
=
10881 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10883 /* Initialize the per-target state. At the moment there is only one
10884 of these, not one per target. Only one target is active at a
10885 time. The default buffer size is unimportant; it will be expanded
10886 whenever a larger buffer is needed. */
10887 rs
= get_remote_state_raw ();
10888 rs
->buf_size
= 400;
10889 rs
->buf
= xmalloc (rs
->buf_size
);
10891 init_remote_ops ();
10892 add_target (&remote_ops
);
10894 init_extended_remote_ops ();
10895 add_target (&extended_remote_ops
);
10897 /* Hook into new objfile notification. */
10898 observer_attach_new_objfile (remote_new_objfile
);
10900 /* Set up signal handlers. */
10901 sigint_remote_token
=
10902 create_async_signal_handler (async_remote_interrupt
, NULL
);
10903 sigint_remote_twice_token
=
10904 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10907 init_remote_threadtests ();
10910 /* set/show remote ... */
10912 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10913 Remote protocol specific variables\n\
10914 Configure various remote-protocol specific variables such as\n\
10915 the packets being used"),
10916 &remote_set_cmdlist
, "set remote ",
10917 0 /* allow-unknown */, &setlist
);
10918 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10919 Remote protocol specific variables\n\
10920 Configure various remote-protocol specific variables such as\n\
10921 the packets being used"),
10922 &remote_show_cmdlist
, "show remote ",
10923 0 /* allow-unknown */, &showlist
);
10925 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10926 Compare section data on target to the exec file.\n\
10927 Argument is a single section name (default: all loaded sections)."),
10930 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10931 Send an arbitrary packet to a remote target.\n\
10932 maintenance packet TEXT\n\
10933 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10934 this command sends the string TEXT to the inferior, and displays the\n\
10935 response packet. GDB supplies the initial `$' character, and the\n\
10936 terminating `#' character and checksum."),
10939 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10940 Set whether to send break if interrupted."), _("\
10941 Show whether to send break if interrupted."), _("\
10942 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10943 set_remotebreak
, show_remotebreak
,
10944 &setlist
, &showlist
);
10945 cmd_name
= "remotebreak";
10946 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10947 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10948 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10949 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10950 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10952 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10953 interrupt_sequence_modes
, &interrupt_sequence_mode
,
10955 Set interrupt sequence to remote target."), _("\
10956 Show interrupt sequence to remote target."), _("\
10957 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10958 NULL
, show_interrupt_sequence
,
10959 &remote_set_cmdlist
,
10960 &remote_show_cmdlist
);
10962 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10963 &interrupt_on_connect
, _("\
10964 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10965 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10966 If set, interrupt sequence is sent to remote target."),
10968 &remote_set_cmdlist
, &remote_show_cmdlist
);
10970 /* Install commands for configuring memory read/write packets. */
10972 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10973 Set the maximum number of bytes per memory write packet (deprecated)."),
10975 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10976 Show the maximum number of bytes per memory write packet (deprecated)."),
10978 add_cmd ("memory-write-packet-size", no_class
,
10979 set_memory_write_packet_size
, _("\
10980 Set the maximum number of bytes per memory-write packet.\n\
10981 Specify the number of bytes in a packet or 0 (zero) for the\n\
10982 default packet size. The actual limit is further reduced\n\
10983 dependent on the target. Specify ``fixed'' to disable the\n\
10984 further restriction and ``limit'' to enable that restriction."),
10985 &remote_set_cmdlist
);
10986 add_cmd ("memory-read-packet-size", no_class
,
10987 set_memory_read_packet_size
, _("\
10988 Set the maximum number of bytes per memory-read packet.\n\
10989 Specify the number of bytes in a packet or 0 (zero) for the\n\
10990 default packet size. The actual limit is further reduced\n\
10991 dependent on the target. Specify ``fixed'' to disable the\n\
10992 further restriction and ``limit'' to enable that restriction."),
10993 &remote_set_cmdlist
);
10994 add_cmd ("memory-write-packet-size", no_class
,
10995 show_memory_write_packet_size
,
10996 _("Show the maximum number of bytes per memory-write packet."),
10997 &remote_show_cmdlist
);
10998 add_cmd ("memory-read-packet-size", no_class
,
10999 show_memory_read_packet_size
,
11000 _("Show the maximum number of bytes per memory-read packet."),
11001 &remote_show_cmdlist
);
11003 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11004 &remote_hw_watchpoint_limit
, _("\
11005 Set the maximum number of target hardware watchpoints."), _("\
11006 Show the maximum number of target hardware watchpoints."), _("\
11007 Specify a negative limit for unlimited."),
11008 NULL
, NULL
, /* FIXME: i18n: The maximum
11009 number of target hardware
11010 watchpoints is %s. */
11011 &remote_set_cmdlist
, &remote_show_cmdlist
);
11012 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11013 &remote_hw_watchpoint_length_limit
, _("\
11014 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11015 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11016 Specify a negative limit for unlimited."),
11017 NULL
, NULL
, /* FIXME: i18n: The maximum
11018 length (in bytes) of a target
11019 hardware watchpoint is %s. */
11020 &remote_set_cmdlist
, &remote_show_cmdlist
);
11021 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11022 &remote_hw_breakpoint_limit
, _("\
11023 Set the maximum number of target hardware breakpoints."), _("\
11024 Show the maximum number of target hardware breakpoints."), _("\
11025 Specify a negative limit for unlimited."),
11026 NULL
, NULL
, /* FIXME: i18n: The maximum
11027 number of target hardware
11028 breakpoints is %s. */
11029 &remote_set_cmdlist
, &remote_show_cmdlist
);
11031 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
11032 &remote_address_size
, _("\
11033 Set the maximum size of the address (in bits) in a memory packet."), _("\
11034 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11036 NULL
, /* FIXME: i18n: */
11037 &setlist
, &showlist
);
11039 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11040 "X", "binary-download", 1);
11042 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11043 "vCont", "verbose-resume", 0);
11045 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11046 "QPassSignals", "pass-signals", 0);
11048 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11049 "qSymbol", "symbol-lookup", 0);
11051 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11052 "P", "set-register", 1);
11054 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11055 "p", "fetch-register", 1);
11057 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11058 "Z0", "software-breakpoint", 0);
11060 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11061 "Z1", "hardware-breakpoint", 0);
11063 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11064 "Z2", "write-watchpoint", 0);
11066 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11067 "Z3", "read-watchpoint", 0);
11069 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11070 "Z4", "access-watchpoint", 0);
11072 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11073 "qXfer:auxv:read", "read-aux-vector", 0);
11075 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11076 "qXfer:features:read", "target-features", 0);
11078 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11079 "qXfer:libraries:read", "library-info", 0);
11081 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11082 "qXfer:memory-map:read", "memory-map", 0);
11084 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11085 "qXfer:spu:read", "read-spu-object", 0);
11087 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11088 "qXfer:spu:write", "write-spu-object", 0);
11090 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11091 "qXfer:osdata:read", "osdata", 0);
11093 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11094 "qXfer:threads:read", "threads", 0);
11096 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11097 "qXfer:siginfo:read", "read-siginfo-object", 0);
11099 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11100 "qXfer:siginfo:write", "write-siginfo-object", 0);
11102 add_packet_config_cmd
11103 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11104 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11106 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11107 "qGetTLSAddr", "get-thread-local-storage-address",
11110 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11111 "qGetTIBAddr", "get-thread-information-block-address",
11114 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11115 "bc", "reverse-continue", 0);
11117 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11118 "bs", "reverse-step", 0);
11120 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11121 "qSupported", "supported-packets", 0);
11123 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11124 "qSearch:memory", "search-memory", 0);
11126 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11127 "vFile:open", "hostio-open", 0);
11129 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11130 "vFile:pread", "hostio-pread", 0);
11132 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11133 "vFile:pwrite", "hostio-pwrite", 0);
11135 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11136 "vFile:close", "hostio-close", 0);
11138 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11139 "vFile:unlink", "hostio-unlink", 0);
11141 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11142 "vAttach", "attach", 0);
11144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11147 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11148 "QStartNoAckMode", "noack", 0);
11150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11151 "vKill", "kill", 0);
11153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11154 "qAttached", "query-attached", 0);
11156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11157 "ConditionalTracepoints",
11158 "conditional-tracepoints", 0);
11159 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11160 "FastTracepoints", "fast-tracepoints", 0);
11162 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11163 "TracepointSource", "TracepointSource", 0);
11165 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11166 "QAllow", "allow", 0);
11168 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11169 "StaticTracepoints", "static-tracepoints", 0);
11171 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11172 "InstallInTrace", "install-in-trace", 0);
11174 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11175 "qXfer:statictrace:read", "read-sdata-object", 0);
11177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11178 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11181 "QDisableRandomization", "disable-randomization", 0);
11183 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11184 Z sub-packet has its own set and show commands, but users may
11185 have sets to this variable in their .gdbinit files (or in their
11187 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11188 &remote_Z_packet_detect
, _("\
11189 Set use of remote protocol `Z' packets"), _("\
11190 Show use of remote protocol `Z' packets "), _("\
11191 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11193 set_remote_protocol_Z_packet_cmd
,
11194 show_remote_protocol_Z_packet_cmd
,
11195 /* FIXME: i18n: Use of remote protocol
11196 `Z' packets is %s. */
11197 &remote_set_cmdlist
, &remote_show_cmdlist
);
11199 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11200 Manipulate files on the remote system\n\
11201 Transfer files to and from the remote target system."),
11202 &remote_cmdlist
, "remote ",
11203 0 /* allow-unknown */, &cmdlist
);
11205 add_cmd ("put", class_files
, remote_put_command
,
11206 _("Copy a local file to the remote system."),
11209 add_cmd ("get", class_files
, remote_get_command
,
11210 _("Copy a remote file to the local system."),
11213 add_cmd ("delete", class_files
, remote_delete_command
,
11214 _("Delete a remote file."),
11217 remote_exec_file
= xstrdup ("");
11218 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11219 &remote_exec_file
, _("\
11220 Set the remote pathname for \"run\""), _("\
11221 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11222 &remote_set_cmdlist
, &remote_show_cmdlist
);
11224 /* Eventually initialize fileio. See fileio.c */
11225 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11227 /* Take advantage of the fact that the LWP field is not used, to tag
11228 special ptids with it set to != 0. */
11229 magic_null_ptid
= ptid_build (42000, 1, -1);
11230 not_sent_ptid
= ptid_build (42000, 1, -2);
11231 any_thread_ptid
= ptid_build (42000, 1, 0);
11233 target_buf_size
= 2048;
11234 target_buf
= xmalloc (target_buf_size
);