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 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 int remote_async_mask (int new_mask
);
139 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
141 static void remote_interrupt (int signo
);
143 static void remote_interrupt_twice (int signo
);
145 static void interrupt_query (void);
147 static void set_general_thread (struct ptid ptid
);
148 static void set_continue_thread (struct ptid ptid
);
150 static void get_offsets (void);
152 static void skip_frame (void);
154 static long read_frame (char **buf_p
, long *sizeof_buf
);
156 static int hexnumlen (ULONGEST num
);
158 static void init_remote_ops (void);
160 static void init_extended_remote_ops (void);
162 static void remote_stop (ptid_t
);
164 static int ishex (int ch
, int *val
);
166 static int stubhex (int ch
);
168 static int hexnumstr (char *, ULONGEST
);
170 static int hexnumnstr (char *, ULONGEST
, int);
172 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
174 static void print_packet (char *);
176 static void compare_sections_command (char *, int);
178 static void packet_command (char *, int);
180 static int stub_unpack_int (char *buff
, int fieldlength
);
182 static ptid_t
remote_current_thread (ptid_t oldptid
);
184 static void remote_find_new_threads (void);
186 static void record_currthread (ptid_t currthread
);
188 static int fromhex (int a
);
190 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
192 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
194 static int putpkt_binary (char *buf
, int cnt
);
196 static void check_binary_download (CORE_ADDR addr
);
198 struct packet_config
;
200 static void show_packet_config_cmd (struct packet_config
*config
);
202 static void update_packet_config (struct packet_config
*config
);
204 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
205 struct cmd_list_element
*c
);
207 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
209 struct cmd_list_element
*c
,
212 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
213 static ptid_t
read_ptid (char *buf
, char **obuf
);
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 /* The non-stop remote protocol provisions for one pending stop reply.
246 This is where we keep it until it is acknowledged. */
248 static struct stop_reply
*pending_stop_reply
= NULL
;
252 static struct cmd_list_element
*remote_cmdlist
;
254 /* For "set remote" and "show remote". */
256 static struct cmd_list_element
*remote_set_cmdlist
;
257 static struct cmd_list_element
*remote_show_cmdlist
;
259 /* Description of the remote protocol state for the currently
260 connected target. This is per-target state, and independent of the
261 selected architecture. */
265 /* A buffer to use for incoming packets, and its current size. The
266 buffer is grown dynamically for larger incoming packets.
267 Outgoing packets may also be constructed in this buffer.
268 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
269 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
274 /* If we negotiated packet size explicitly (and thus can bypass
275 heuristics for the largest packet size that will not overflow
276 a buffer in the stub), this will be set to that packet size.
277 Otherwise zero, meaning to use the guessed size. */
278 long explicit_packet_size
;
280 /* remote_wait is normally called when the target is running and
281 waits for a stop reply packet. But sometimes we need to call it
282 when the target is already stopped. We can send a "?" packet
283 and have remote_wait read the response. Or, if we already have
284 the response, we can stash it in BUF and tell remote_wait to
285 skip calling getpkt. This flag is set when BUF contains a
286 stop reply packet and the target is not waiting. */
287 int cached_wait_status
;
289 /* True, if in no ack mode. That is, neither GDB nor the stub will
290 expect acks from each other. The connection is assumed to be
294 /* True if we're connected in extended remote mode. */
297 /* True if the stub reported support for multi-process
299 int multi_process_aware
;
301 /* True if we resumed the target and we're waiting for the target to
302 stop. In the mean time, we can't start another command/query.
303 The remote server wouldn't be ready to process it, so we'd
304 timeout waiting for a reply that would never come and eventually
305 we'd close the connection. This can happen in asynchronous mode
306 because we allow GDB commands while the target is running. */
307 int waiting_for_stop_reply
;
309 /* True if the stub reports support for non-stop mode. */
312 /* True if the stub reports support for vCont;t. */
315 /* True if the stub reports support for conditional tracepoints. */
316 int cond_tracepoints
;
318 /* True if the stub reports support for fast tracepoints. */
319 int fast_tracepoints
;
321 /* True if the stub can continue running a trace while GDB is
323 int disconnected_tracing
;
325 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
326 responded to that. */
330 /* Private data that we'll store in (struct thread_info)->private. */
331 struct private_thread_info
338 free_private_thread_info (struct private_thread_info
*info
)
344 /* Returns true if the multi-process extensions are in effect. */
346 remote_multi_process_p (struct remote_state
*rs
)
348 return rs
->extended
&& rs
->multi_process_aware
;
351 /* This data could be associated with a target, but we do not always
352 have access to the current target when we need it, so for now it is
353 static. This will be fine for as long as only one target is in use
355 static struct remote_state remote_state
;
357 static struct remote_state
*
358 get_remote_state_raw (void)
360 return &remote_state
;
363 /* Description of the remote protocol for a given architecture. */
367 long offset
; /* Offset into G packet. */
368 long regnum
; /* GDB's internal register number. */
369 LONGEST pnum
; /* Remote protocol register number. */
370 int in_g_packet
; /* Always part of G packet. */
371 /* long size in bytes; == register_size (target_gdbarch, regnum);
373 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
377 struct remote_arch_state
379 /* Description of the remote protocol registers. */
380 long sizeof_g_packet
;
382 /* Description of the remote protocol registers indexed by REGNUM
383 (making an array gdbarch_num_regs in size). */
384 struct packet_reg
*regs
;
386 /* This is the size (in chars) of the first response to the ``g''
387 packet. It is used as a heuristic when determining the maximum
388 size of memory-read and memory-write packets. A target will
389 typically only reserve a buffer large enough to hold the ``g''
390 packet. The size does not include packet overhead (headers and
392 long actual_register_packet_size
;
394 /* This is the maximum size (in chars) of a non read/write packet.
395 It is also used as a cap on the size of read/write packets. */
396 long remote_packet_size
;
399 long sizeof_pkt
= 2000;
401 /* Utility: generate error from an incoming stub packet. */
403 trace_error (char *buf
)
406 return; /* not an error msg */
409 case '1': /* malformed packet error */
410 if (*++buf
== '0') /* general case: */
411 error (_("remote.c: error in outgoing packet."));
413 error (_("remote.c: error in outgoing packet at field #%ld."),
414 strtol (buf
, NULL
, 16));
416 error (_("trace API error 0x%s."), ++buf
);
418 error (_("Target returns error code '%s'."), buf
);
422 /* Utility: wait for reply from stub, while accepting "O" packets. */
424 remote_get_noisy_reply (char **buf_p
,
427 do /* Loop on reply from remote stub. */
430 QUIT
; /* allow user to bail out with ^C */
431 getpkt (buf_p
, sizeof_buf
, 0);
435 else if (buf
[0] == 'O' && buf
[1] != 'K')
436 remote_console_output (buf
+ 1); /* 'O' message from stub */
438 return buf
; /* here's the actual reply */
443 /* Handle for retreving the remote protocol data from gdbarch. */
444 static struct gdbarch_data
*remote_gdbarch_data_handle
;
446 static struct remote_arch_state
*
447 get_remote_arch_state (void)
449 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
452 /* Fetch the global remote target state. */
454 static struct remote_state
*
455 get_remote_state (void)
457 /* Make sure that the remote architecture state has been
458 initialized, because doing so might reallocate rs->buf. Any
459 function which calls getpkt also needs to be mindful of changes
460 to rs->buf, but this call limits the number of places which run
462 get_remote_arch_state ();
464 return get_remote_state_raw ();
468 compare_pnums (const void *lhs_
, const void *rhs_
)
470 const struct packet_reg
* const *lhs
= lhs_
;
471 const struct packet_reg
* const *rhs
= rhs_
;
473 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
475 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
482 init_remote_state (struct gdbarch
*gdbarch
)
484 int regnum
, num_remote_regs
, offset
;
485 struct remote_state
*rs
= get_remote_state_raw ();
486 struct remote_arch_state
*rsa
;
487 struct packet_reg
**remote_regs
;
489 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
491 /* Use the architecture to build a regnum<->pnum table, which will be
492 1:1 unless a feature set specifies otherwise. */
493 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
494 gdbarch_num_regs (gdbarch
),
496 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
498 struct packet_reg
*r
= &rsa
->regs
[regnum
];
500 if (register_size (gdbarch
, regnum
) == 0)
501 /* Do not try to fetch zero-sized (placeholder) registers. */
504 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
509 /* Define the g/G packet format as the contents of each register
510 with a remote protocol number, in order of ascending protocol
513 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
514 * sizeof (struct packet_reg
*));
515 for (num_remote_regs
= 0, regnum
= 0;
516 regnum
< gdbarch_num_regs (gdbarch
);
518 if (rsa
->regs
[regnum
].pnum
!= -1)
519 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
521 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
524 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
526 remote_regs
[regnum
]->in_g_packet
= 1;
527 remote_regs
[regnum
]->offset
= offset
;
528 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
531 /* Record the maximum possible size of the g packet - it may turn out
533 rsa
->sizeof_g_packet
= offset
;
535 /* Default maximum number of characters in a packet body. Many
536 remote stubs have a hardwired buffer size of 400 bytes
537 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
538 as the maximum packet-size to ensure that the packet and an extra
539 NUL character can always fit in the buffer. This stops GDB
540 trashing stubs that try to squeeze an extra NUL into what is
541 already a full buffer (As of 1999-12-04 that was most stubs). */
542 rsa
->remote_packet_size
= 400 - 1;
544 /* This one is filled in when a ``g'' packet is received. */
545 rsa
->actual_register_packet_size
= 0;
547 /* Should rsa->sizeof_g_packet needs more space than the
548 default, adjust the size accordingly. Remember that each byte is
549 encoded as two characters. 32 is the overhead for the packet
550 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
551 (``$NN:G...#NN'') is a better guess, the below has been padded a
553 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
554 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
556 /* Make sure that the packet buffer is plenty big enough for
557 this architecture. */
558 if (rs
->buf_size
< rsa
->remote_packet_size
)
560 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
561 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
567 /* Return the current allowed size of a remote packet. This is
568 inferred from the current architecture, and should be used to
569 limit the length of outgoing packets. */
571 get_remote_packet_size (void)
573 struct remote_state
*rs
= get_remote_state ();
574 struct remote_arch_state
*rsa
= get_remote_arch_state ();
576 if (rs
->explicit_packet_size
)
577 return rs
->explicit_packet_size
;
579 return rsa
->remote_packet_size
;
582 static struct packet_reg
*
583 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
585 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
589 struct packet_reg
*r
= &rsa
->regs
[regnum
];
590 gdb_assert (r
->regnum
== regnum
);
595 static struct packet_reg
*
596 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
599 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
601 struct packet_reg
*r
= &rsa
->regs
[i
];
608 /* FIXME: graces/2002-08-08: These variables should eventually be
609 bound to an instance of the target object (as in gdbarch-tdep()),
610 when such a thing exists. */
612 /* This is set to the data address of the access causing the target
613 to stop for a watchpoint. */
614 static CORE_ADDR remote_watch_data_address
;
616 /* This is non-zero if target stopped for a watchpoint. */
617 static int remote_stopped_by_watchpoint_p
;
619 static struct target_ops remote_ops
;
621 static struct target_ops extended_remote_ops
;
623 static int remote_async_mask_value
= 1;
625 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
626 ``forever'' still use the normal timeout mechanism. This is
627 currently used by the ASYNC code to guarentee that target reads
628 during the initial connect always time-out. Once getpkt has been
629 modified to return a timeout indication and, in turn
630 remote_wait()/wait_for_inferior() have gained a timeout parameter
632 static int wait_forever_enabled_p
= 1;
634 /* Allow the user to specify what sequence to send to the remote
635 when he requests a program interruption: Although ^C is usually
636 what remote systems expect (this is the default, here), it is
637 sometimes preferable to send a break. On other systems such
638 as the Linux kernel, a break followed by g, which is Magic SysRq g
639 is required in order to interrupt the execution. */
640 const char interrupt_sequence_control_c
[] = "Ctrl-C";
641 const char interrupt_sequence_break
[] = "BREAK";
642 const char interrupt_sequence_break_g
[] = "BREAK-g";
643 static const char *interrupt_sequence_modes
[] =
645 interrupt_sequence_control_c
,
646 interrupt_sequence_break
,
647 interrupt_sequence_break_g
,
650 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
653 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
654 struct cmd_list_element
*c
,
657 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
658 fprintf_filtered (file
,
659 _("Send the ASCII ETX character (Ctrl-c) "
660 "to the remote target to interrupt the "
661 "execution of the program.\n"));
662 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
663 fprintf_filtered (file
,
664 _("send a break signal to the remote target "
665 "to interrupt the execution of the program.\n"));
666 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
667 fprintf_filtered (file
,
668 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
669 "the remote target to interrupt the execution "
670 "of Linux kernel.\n"));
672 internal_error (__FILE__
, __LINE__
,
673 _("Invalid value for interrupt_sequence_mode: %s."),
674 interrupt_sequence_mode
);
677 /* This boolean variable specifies whether interrupt_sequence is sent
678 to the remote target when gdb connects to it.
679 This is mostly needed when you debug the Linux kernel: The Linux kernel
680 expects BREAK g which is Magic SysRq g for connecting gdb. */
681 static int interrupt_on_connect
= 0;
683 /* This variable is used to implement the "set/show remotebreak" commands.
684 Since these commands are now deprecated in favor of "set/show remote
685 interrupt-sequence", it no longer has any effect on the code. */
686 static int remote_break
;
689 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
692 interrupt_sequence_mode
= interrupt_sequence_break
;
694 interrupt_sequence_mode
= interrupt_sequence_control_c
;
698 show_remotebreak (struct ui_file
*file
, int from_tty
,
699 struct cmd_list_element
*c
,
704 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
705 remote_open knows that we don't have a file open when the program
707 static struct serial
*remote_desc
= NULL
;
709 /* This variable sets the number of bits in an address that are to be
710 sent in a memory ("M" or "m") packet. Normally, after stripping
711 leading zeros, the entire address would be sent. This variable
712 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
713 initial implementation of remote.c restricted the address sent in
714 memory packets to ``host::sizeof long'' bytes - (typically 32
715 bits). Consequently, for 64 bit targets, the upper 32 bits of an
716 address was never sent. Since fixing this bug may cause a break in
717 some remote targets this variable is principly provided to
718 facilitate backward compatibility. */
720 static int remote_address_size
;
722 /* Temporary to track who currently owns the terminal. See
723 remote_terminal_* for more details. */
725 static int remote_async_terminal_ours_p
;
727 /* The executable file to use for "run" on the remote side. */
729 static char *remote_exec_file
= "";
732 /* User configurable variables for the number of characters in a
733 memory read/write packet. MIN (rsa->remote_packet_size,
734 rsa->sizeof_g_packet) is the default. Some targets need smaller
735 values (fifo overruns, et.al.) and some users need larger values
736 (speed up transfers). The variables ``preferred_*'' (the user
737 request), ``current_*'' (what was actually set) and ``forced_*''
738 (Positive - a soft limit, negative - a hard limit). */
740 struct memory_packet_config
747 /* Compute the current size of a read/write packet. Since this makes
748 use of ``actual_register_packet_size'' the computation is dynamic. */
751 get_memory_packet_size (struct memory_packet_config
*config
)
753 struct remote_state
*rs
= get_remote_state ();
754 struct remote_arch_state
*rsa
= get_remote_arch_state ();
756 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
757 law?) that some hosts don't cope very well with large alloca()
758 calls. Eventually the alloca() code will be replaced by calls to
759 xmalloc() and make_cleanups() allowing this restriction to either
760 be lifted or removed. */
761 #ifndef MAX_REMOTE_PACKET_SIZE
762 #define MAX_REMOTE_PACKET_SIZE 16384
764 /* NOTE: 20 ensures we can write at least one byte. */
765 #ifndef MIN_REMOTE_PACKET_SIZE
766 #define MIN_REMOTE_PACKET_SIZE 20
771 if (config
->size
<= 0)
772 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
774 what_they_get
= config
->size
;
778 what_they_get
= get_remote_packet_size ();
779 /* Limit the packet to the size specified by the user. */
781 && what_they_get
> config
->size
)
782 what_they_get
= config
->size
;
784 /* Limit it to the size of the targets ``g'' response unless we have
785 permission from the stub to use a larger packet size. */
786 if (rs
->explicit_packet_size
== 0
787 && rsa
->actual_register_packet_size
> 0
788 && what_they_get
> rsa
->actual_register_packet_size
)
789 what_they_get
= rsa
->actual_register_packet_size
;
791 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
792 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
793 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
794 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
796 /* Make sure there is room in the global buffer for this packet
797 (including its trailing NUL byte). */
798 if (rs
->buf_size
< what_they_get
+ 1)
800 rs
->buf_size
= 2 * what_they_get
;
801 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
804 return what_they_get
;
807 /* Update the size of a read/write packet. If they user wants
808 something really big then do a sanity check. */
811 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
813 int fixed_p
= config
->fixed_p
;
814 long size
= config
->size
;
816 error (_("Argument required (integer, `fixed' or `limited')."));
817 else if (strcmp (args
, "hard") == 0
818 || strcmp (args
, "fixed") == 0)
820 else if (strcmp (args
, "soft") == 0
821 || strcmp (args
, "limit") == 0)
826 size
= strtoul (args
, &end
, 0);
828 error (_("Invalid %s (bad syntax)."), config
->name
);
830 /* Instead of explicitly capping the size of a packet to
831 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
832 instead allowed to set the size to something arbitrarily
834 if (size
> MAX_REMOTE_PACKET_SIZE
)
835 error (_("Invalid %s (too large)."), config
->name
);
839 if (fixed_p
&& !config
->fixed_p
)
841 if (! query (_("The target may not be able to correctly handle a %s\n"
842 "of %ld bytes. Change the packet size? "),
844 error (_("Packet size not changed."));
846 /* Update the config. */
847 config
->fixed_p
= fixed_p
;
852 show_memory_packet_size (struct memory_packet_config
*config
)
854 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
856 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
857 get_memory_packet_size (config
));
859 printf_filtered (_("Packets are limited to %ld bytes.\n"),
860 get_memory_packet_size (config
));
863 static struct memory_packet_config memory_write_packet_config
=
865 "memory-write-packet-size",
869 set_memory_write_packet_size (char *args
, int from_tty
)
871 set_memory_packet_size (args
, &memory_write_packet_config
);
875 show_memory_write_packet_size (char *args
, int from_tty
)
877 show_memory_packet_size (&memory_write_packet_config
);
881 get_memory_write_packet_size (void)
883 return get_memory_packet_size (&memory_write_packet_config
);
886 static struct memory_packet_config memory_read_packet_config
=
888 "memory-read-packet-size",
892 set_memory_read_packet_size (char *args
, int from_tty
)
894 set_memory_packet_size (args
, &memory_read_packet_config
);
898 show_memory_read_packet_size (char *args
, int from_tty
)
900 show_memory_packet_size (&memory_read_packet_config
);
904 get_memory_read_packet_size (void)
906 long size
= get_memory_packet_size (&memory_read_packet_config
);
907 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
908 extra buffer size argument before the memory read size can be
909 increased beyond this. */
910 if (size
> get_remote_packet_size ())
911 size
= get_remote_packet_size ();
916 /* Generic configuration support for packets the stub optionally
917 supports. Allows the user to specify the use of the packet as well
918 as allowing GDB to auto-detect support in the remote stub. */
922 PACKET_SUPPORT_UNKNOWN
= 0,
931 enum auto_boolean detect
;
932 enum packet_support support
;
935 /* Analyze a packet's return value and update the packet config
946 update_packet_config (struct packet_config
*config
)
948 switch (config
->detect
)
950 case AUTO_BOOLEAN_TRUE
:
951 config
->support
= PACKET_ENABLE
;
953 case AUTO_BOOLEAN_FALSE
:
954 config
->support
= PACKET_DISABLE
;
956 case AUTO_BOOLEAN_AUTO
:
957 config
->support
= PACKET_SUPPORT_UNKNOWN
;
963 show_packet_config_cmd (struct packet_config
*config
)
965 char *support
= "internal-error";
966 switch (config
->support
)
972 support
= "disabled";
974 case PACKET_SUPPORT_UNKNOWN
:
978 switch (config
->detect
)
980 case AUTO_BOOLEAN_AUTO
:
981 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
982 config
->name
, support
);
984 case AUTO_BOOLEAN_TRUE
:
985 case AUTO_BOOLEAN_FALSE
:
986 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
987 config
->name
, support
);
993 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
994 const char *title
, int legacy
)
1000 config
->name
= name
;
1001 config
->title
= title
;
1002 config
->detect
= AUTO_BOOLEAN_AUTO
;
1003 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1004 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1006 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
1008 /* set/show TITLE-packet {auto,on,off} */
1009 cmd_name
= xstrprintf ("%s-packet", title
);
1010 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1011 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
1012 set_remote_protocol_packet_cmd
,
1013 show_remote_protocol_packet_cmd
,
1014 &remote_set_cmdlist
, &remote_show_cmdlist
);
1015 /* The command code copies the documentation strings. */
1018 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1022 legacy_name
= xstrprintf ("%s-packet", name
);
1023 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1024 &remote_set_cmdlist
);
1025 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1026 &remote_show_cmdlist
);
1030 static enum packet_result
1031 packet_check_result (const char *buf
)
1035 /* The stub recognized the packet request. Check that the
1036 operation succeeded. */
1038 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1040 /* "Enn" - definitly an error. */
1041 return PACKET_ERROR
;
1043 /* Always treat "E." as an error. This will be used for
1044 more verbose error messages, such as E.memtypes. */
1045 if (buf
[0] == 'E' && buf
[1] == '.')
1046 return PACKET_ERROR
;
1048 /* The packet may or may not be OK. Just assume it is. */
1052 /* The stub does not support the packet. */
1053 return PACKET_UNKNOWN
;
1056 static enum packet_result
1057 packet_ok (const char *buf
, struct packet_config
*config
)
1059 enum packet_result result
;
1061 result
= packet_check_result (buf
);
1066 /* The stub recognized the packet request. */
1067 switch (config
->support
)
1069 case PACKET_SUPPORT_UNKNOWN
:
1071 fprintf_unfiltered (gdb_stdlog
,
1072 "Packet %s (%s) is supported\n",
1073 config
->name
, config
->title
);
1074 config
->support
= PACKET_ENABLE
;
1076 case PACKET_DISABLE
:
1077 internal_error (__FILE__
, __LINE__
,
1078 _("packet_ok: attempt to use a disabled packet"));
1084 case PACKET_UNKNOWN
:
1085 /* The stub does not support the packet. */
1086 switch (config
->support
)
1089 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1090 /* If the stub previously indicated that the packet was
1091 supported then there is a protocol error.. */
1092 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1093 config
->name
, config
->title
);
1095 /* The user set it wrong. */
1096 error (_("Enabled packet %s (%s) not recognized by stub"),
1097 config
->name
, config
->title
);
1099 case PACKET_SUPPORT_UNKNOWN
:
1101 fprintf_unfiltered (gdb_stdlog
,
1102 "Packet %s (%s) is NOT supported\n",
1103 config
->name
, config
->title
);
1104 config
->support
= PACKET_DISABLE
;
1106 case PACKET_DISABLE
:
1128 PACKET_vFile_pwrite
,
1130 PACKET_vFile_unlink
,
1132 PACKET_qXfer_features
,
1133 PACKET_qXfer_libraries
,
1134 PACKET_qXfer_memory_map
,
1135 PACKET_qXfer_spu_read
,
1136 PACKET_qXfer_spu_write
,
1137 PACKET_qXfer_osdata
,
1138 PACKET_qXfer_threads
,
1142 PACKET_QPassSignals
,
1143 PACKET_qSearch_memory
,
1146 PACKET_QStartNoAckMode
,
1148 PACKET_qXfer_siginfo_read
,
1149 PACKET_qXfer_siginfo_write
,
1151 PACKET_ConditionalTracepoints
,
1152 PACKET_FastTracepoints
,
1155 PACKET_TracepointSource
,
1159 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1162 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1163 struct cmd_list_element
*c
)
1165 struct packet_config
*packet
;
1167 for (packet
= remote_protocol_packets
;
1168 packet
< &remote_protocol_packets
[PACKET_MAX
];
1171 if (&packet
->detect
== c
->var
)
1173 update_packet_config (packet
);
1177 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1182 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1183 struct cmd_list_element
*c
,
1186 struct packet_config
*packet
;
1188 for (packet
= remote_protocol_packets
;
1189 packet
< &remote_protocol_packets
[PACKET_MAX
];
1192 if (&packet
->detect
== c
->var
)
1194 show_packet_config_cmd (packet
);
1198 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1202 /* Should we try one of the 'Z' requests? */
1206 Z_PACKET_SOFTWARE_BP
,
1207 Z_PACKET_HARDWARE_BP
,
1214 /* For compatibility with older distributions. Provide a ``set remote
1215 Z-packet ...'' command that updates all the Z packet types. */
1217 static enum auto_boolean remote_Z_packet_detect
;
1220 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1221 struct cmd_list_element
*c
)
1224 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1226 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1227 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1232 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1233 struct cmd_list_element
*c
,
1237 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1239 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1243 /* Should we try the 'ThreadInfo' query packet?
1245 This variable (NOT available to the user: auto-detect only!)
1246 determines whether GDB will use the new, simpler "ThreadInfo"
1247 query or the older, more complex syntax for thread queries.
1248 This is an auto-detect variable (set to true at each connect,
1249 and set to false when the target fails to recognize it). */
1251 static int use_threadinfo_query
;
1252 static int use_threadextra_query
;
1254 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1255 static struct async_signal_handler
*sigint_remote_twice_token
;
1256 static struct async_signal_handler
*sigint_remote_token
;
1259 /* Asynchronous signal handle registered as event loop source for
1260 when we have pending events ready to be passed to the core. */
1262 static struct async_event_handler
*remote_async_inferior_event_token
;
1264 /* Asynchronous signal handle registered as event loop source for when
1265 the remote sent us a %Stop notification. The registered callback
1266 will do a vStopped sequence to pull the rest of the events out of
1267 the remote side into our event queue. */
1269 static struct async_event_handler
*remote_async_get_pending_events_token
;
1272 static ptid_t magic_null_ptid
;
1273 static ptid_t not_sent_ptid
;
1274 static ptid_t any_thread_ptid
;
1276 /* These are the threads which we last sent to the remote system. The
1277 TID member will be -1 for all or -2 for not sent yet. */
1279 static ptid_t general_thread
;
1280 static ptid_t continue_thread
;
1282 /* Find out if the stub attached to PID (and hence GDB should offer to
1283 detach instead of killing it when bailing out). */
1286 remote_query_attached (int pid
)
1288 struct remote_state
*rs
= get_remote_state ();
1290 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1293 if (remote_multi_process_p (rs
))
1294 sprintf (rs
->buf
, "qAttached:%x", pid
);
1296 sprintf (rs
->buf
, "qAttached");
1299 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1301 switch (packet_ok (rs
->buf
,
1302 &remote_protocol_packets
[PACKET_qAttached
]))
1305 if (strcmp (rs
->buf
, "1") == 0)
1309 warning (_("Remote failure reply: %s"), rs
->buf
);
1311 case PACKET_UNKNOWN
:
1318 /* Add PID to GDB's inferior table. Since we can be connected to a
1319 remote system before before knowing about any inferior, mark the
1320 target with execution when we find the first inferior. If ATTACHED
1321 is 1, then we had just attached to this inferior. If it is 0, then
1322 we just created this inferior. If it is -1, then try querying the
1323 remote stub to find out if it had attached to the inferior or
1326 static struct inferior
*
1327 remote_add_inferior (int pid
, int attached
)
1329 struct inferior
*inf
;
1331 /* Check whether this process we're learning about is to be
1332 considered attached, or if is to be considered to have been
1333 spawned by the stub. */
1335 attached
= remote_query_attached (pid
);
1337 if (gdbarch_has_global_solist (target_gdbarch
))
1339 /* If the target shares code across all inferiors, then every
1340 attach adds a new inferior. */
1341 inf
= add_inferior (pid
);
1343 /* ... and every inferior is bound to the same program space.
1344 However, each inferior may still have its own address
1346 inf
->aspace
= maybe_new_address_space ();
1347 inf
->pspace
= current_program_space
;
1351 /* In the traditional debugging scenario, there's a 1-1 match
1352 between program/address spaces. We simply bind the inferior
1353 to the program space's address space. */
1354 inf
= current_inferior ();
1355 inferior_appeared (inf
, pid
);
1358 inf
->attach_flag
= attached
;
1363 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1364 according to RUNNING. */
1367 remote_add_thread (ptid_t ptid
, int running
)
1371 set_executing (ptid
, running
);
1372 set_running (ptid
, running
);
1375 /* Come here when we learn about a thread id from the remote target.
1376 It may be the first time we hear about such thread, so take the
1377 opportunity to add it to GDB's thread list. In case this is the
1378 first time we're noticing its corresponding inferior, add it to
1379 GDB's inferior list as well. */
1382 remote_notice_new_inferior (ptid_t currthread
, int running
)
1384 /* If this is a new thread, add it to GDB's thread list.
1385 If we leave it up to WFI to do this, bad things will happen. */
1387 if (in_thread_list (currthread
) && is_exited (currthread
))
1389 /* We're seeing an event on a thread id we knew had exited.
1390 This has to be a new thread reusing the old id. Add it. */
1391 remote_add_thread (currthread
, running
);
1395 if (!in_thread_list (currthread
))
1397 struct inferior
*inf
= NULL
;
1398 int pid
= ptid_get_pid (currthread
);
1400 if (ptid_is_pid (inferior_ptid
)
1401 && pid
== ptid_get_pid (inferior_ptid
))
1403 /* inferior_ptid has no thread member yet. This can happen
1404 with the vAttach -> remote_wait,"TAAthread:" path if the
1405 stub doesn't support qC. This is the first stop reported
1406 after an attach, so this is the main thread. Update the
1407 ptid in the thread list. */
1408 if (in_thread_list (pid_to_ptid (pid
)))
1409 thread_change_ptid (inferior_ptid
, currthread
);
1412 remote_add_thread (currthread
, running
);
1413 inferior_ptid
= currthread
;
1418 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1420 /* inferior_ptid is not set yet. This can happen with the
1421 vRun -> remote_wait,"TAAthread:" path if the stub
1422 doesn't support qC. This is the first stop reported
1423 after an attach, so this is the main thread. Update the
1424 ptid in the thread list. */
1425 thread_change_ptid (inferior_ptid
, currthread
);
1429 /* When connecting to a target remote, or to a target
1430 extended-remote which already was debugging an inferior, we
1431 may not know about it yet. Add it before adding its child
1432 thread, so notifications are emitted in a sensible order. */
1433 if (!in_inferior_list (ptid_get_pid (currthread
)))
1434 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1436 /* This is really a new thread. Add it. */
1437 remote_add_thread (currthread
, running
);
1439 /* If we found a new inferior, let the common code do whatever
1440 it needs to with it (e.g., read shared libraries, insert
1443 notice_new_inferior (currthread
, running
, 0);
1447 /* Return the private thread data, creating it if necessary. */
1449 struct private_thread_info
*
1450 demand_private_info (ptid_t ptid
)
1452 struct thread_info
*info
= find_thread_ptid (ptid
);
1458 info
->private = xmalloc (sizeof (*(info
->private)));
1459 info
->private_dtor
= free_private_thread_info
;
1460 info
->private->core
= -1;
1461 info
->private->extra
= 0;
1464 return info
->private;
1467 /* Call this function as a result of
1468 1) A halt indication (T packet) containing a thread id
1469 2) A direct query of currthread
1470 3) Successful execution of set thread
1474 record_currthread (ptid_t currthread
)
1476 general_thread
= currthread
;
1479 static char *last_pass_packet
;
1481 /* If 'QPassSignals' is supported, tell the remote stub what signals
1482 it can simply pass through to the inferior without reporting. */
1485 remote_pass_signals (void)
1487 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1489 char *pass_packet
, *p
;
1490 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1493 gdb_assert (numsigs
< 256);
1494 for (i
= 0; i
< numsigs
; i
++)
1496 if (signal_stop_state (i
) == 0
1497 && signal_print_state (i
) == 0
1498 && signal_pass_state (i
) == 1)
1501 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1502 strcpy (pass_packet
, "QPassSignals:");
1503 p
= pass_packet
+ strlen (pass_packet
);
1504 for (i
= 0; i
< numsigs
; i
++)
1506 if (signal_stop_state (i
) == 0
1507 && signal_print_state (i
) == 0
1508 && signal_pass_state (i
) == 1)
1511 *p
++ = tohex (i
>> 4);
1512 *p
++ = tohex (i
& 15);
1521 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1523 struct remote_state
*rs
= get_remote_state ();
1524 char *buf
= rs
->buf
;
1526 putpkt (pass_packet
);
1527 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1528 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1529 if (last_pass_packet
)
1530 xfree (last_pass_packet
);
1531 last_pass_packet
= pass_packet
;
1534 xfree (pass_packet
);
1538 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1539 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1540 thread. If GEN is set, set the general thread, if not, then set
1541 the step/continue thread. */
1543 set_thread (struct ptid ptid
, int gen
)
1545 struct remote_state
*rs
= get_remote_state ();
1546 ptid_t state
= gen
? general_thread
: continue_thread
;
1547 char *buf
= rs
->buf
;
1548 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1550 if (ptid_equal (state
, ptid
))
1554 *buf
++ = gen
? 'g' : 'c';
1555 if (ptid_equal (ptid
, magic_null_ptid
))
1556 xsnprintf (buf
, endbuf
- buf
, "0");
1557 else if (ptid_equal (ptid
, any_thread_ptid
))
1558 xsnprintf (buf
, endbuf
- buf
, "0");
1559 else if (ptid_equal (ptid
, minus_one_ptid
))
1560 xsnprintf (buf
, endbuf
- buf
, "-1");
1562 write_ptid (buf
, endbuf
, ptid
);
1564 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1566 general_thread
= ptid
;
1568 continue_thread
= ptid
;
1572 set_general_thread (struct ptid ptid
)
1574 set_thread (ptid
, 1);
1578 set_continue_thread (struct ptid ptid
)
1580 set_thread (ptid
, 0);
1583 /* Change the remote current process. Which thread within the process
1584 ends up selected isn't important, as long as it is the same process
1585 as what INFERIOR_PTID points to.
1587 This comes from that fact that there is no explicit notion of
1588 "selected process" in the protocol. The selected process for
1589 general operations is the process the selected general thread
1593 set_general_process (void)
1595 struct remote_state
*rs
= get_remote_state ();
1597 /* If the remote can't handle multiple processes, don't bother. */
1598 if (!remote_multi_process_p (rs
))
1601 /* We only need to change the remote current thread if it's pointing
1602 at some other process. */
1603 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1604 set_general_thread (inferior_ptid
);
1608 /* Return nonzero if the thread PTID is still alive on the remote
1612 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1614 struct remote_state
*rs
= get_remote_state ();
1617 if (ptid_equal (ptid
, magic_null_ptid
))
1618 /* The main thread is always alive. */
1621 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1622 /* The main thread is always alive. This can happen after a
1623 vAttach, if the remote side doesn't support
1628 endp
= rs
->buf
+ get_remote_packet_size ();
1631 write_ptid (p
, endp
, ptid
);
1634 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1635 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1638 /* About these extended threadlist and threadinfo packets. They are
1639 variable length packets but, the fields within them are often fixed
1640 length. They are redundent enough to send over UDP as is the
1641 remote protocol in general. There is a matching unit test module
1644 #define OPAQUETHREADBYTES 8
1646 /* a 64 bit opaque identifier */
1647 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1649 /* WARNING: This threadref data structure comes from the remote O.S.,
1650 libstub protocol encoding, and remote.c. it is not particularly
1653 /* Right now, the internal structure is int. We want it to be bigger.
1657 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1659 /* gdb_ext_thread_info is an internal GDB data structure which is
1660 equivalent to the reply of the remote threadinfo packet. */
1662 struct gdb_ext_thread_info
1664 threadref threadid
; /* External form of thread reference. */
1665 int active
; /* Has state interesting to GDB?
1667 char display
[256]; /* Brief state display, name,
1668 blocked/suspended. */
1669 char shortname
[32]; /* To be used to name threads. */
1670 char more_display
[256]; /* Long info, statistics, queue depth,
1674 /* The volume of remote transfers can be limited by submitting
1675 a mask containing bits specifying the desired information.
1676 Use a union of these values as the 'selection' parameter to
1677 get_thread_info. FIXME: Make these TAG names more thread specific.
1680 #define TAG_THREADID 1
1681 #define TAG_EXISTS 2
1682 #define TAG_DISPLAY 4
1683 #define TAG_THREADNAME 8
1684 #define TAG_MOREDISPLAY 16
1686 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1688 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1690 static char *unpack_nibble (char *buf
, int *val
);
1692 static char *pack_nibble (char *buf
, int nibble
);
1694 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1696 static char *unpack_byte (char *buf
, int *value
);
1698 static char *pack_int (char *buf
, int value
);
1700 static char *unpack_int (char *buf
, int *value
);
1702 static char *unpack_string (char *src
, char *dest
, int length
);
1704 static char *pack_threadid (char *pkt
, threadref
*id
);
1706 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1708 void int_to_threadref (threadref
*id
, int value
);
1710 static int threadref_to_int (threadref
*ref
);
1712 static void copy_threadref (threadref
*dest
, threadref
*src
);
1714 static int threadmatch (threadref
*dest
, threadref
*src
);
1716 static char *pack_threadinfo_request (char *pkt
, int mode
,
1719 static int remote_unpack_thread_info_response (char *pkt
,
1720 threadref
*expectedref
,
1721 struct gdb_ext_thread_info
1725 static int remote_get_threadinfo (threadref
*threadid
,
1726 int fieldset
, /*TAG mask */
1727 struct gdb_ext_thread_info
*info
);
1729 static char *pack_threadlist_request (char *pkt
, int startflag
,
1731 threadref
*nextthread
);
1733 static int parse_threadlist_response (char *pkt
,
1735 threadref
*original_echo
,
1736 threadref
*resultlist
,
1739 static int remote_get_threadlist (int startflag
,
1740 threadref
*nextthread
,
1744 threadref
*threadlist
);
1746 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1748 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1749 void *context
, int looplimit
);
1751 static int remote_newthread_step (threadref
*ref
, void *context
);
1754 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1755 buffer we're allowed to write to. Returns
1756 BUF+CHARACTERS_WRITTEN. */
1759 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1762 struct remote_state
*rs
= get_remote_state ();
1764 if (remote_multi_process_p (rs
))
1766 pid
= ptid_get_pid (ptid
);
1768 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1770 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1772 tid
= ptid_get_tid (ptid
);
1774 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1776 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1781 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1782 passed the last parsed char. Returns null_ptid on error. */
1785 read_ptid (char *buf
, char **obuf
)
1789 ULONGEST pid
= 0, tid
= 0;
1793 /* Multi-process ptid. */
1794 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1796 error (_("invalid remote ptid: %s\n"), p
);
1799 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1802 return ptid_build (pid
, 0, tid
);
1805 /* No multi-process. Just a tid. */
1806 pp
= unpack_varlen_hex (p
, &tid
);
1808 /* Since the stub is not sending a process id, then default to
1809 what's in inferior_ptid, unless it's null at this point. If so,
1810 then since there's no way to know the pid of the reported
1811 threads, use the magic number. */
1812 if (ptid_equal (inferior_ptid
, null_ptid
))
1813 pid
= ptid_get_pid (magic_null_ptid
);
1815 pid
= ptid_get_pid (inferior_ptid
);
1819 return ptid_build (pid
, 0, tid
);
1822 /* Encode 64 bits in 16 chars of hex. */
1824 static const char hexchars
[] = "0123456789abcdef";
1827 ishex (int ch
, int *val
)
1829 if ((ch
>= 'a') && (ch
<= 'f'))
1831 *val
= ch
- 'a' + 10;
1834 if ((ch
>= 'A') && (ch
<= 'F'))
1836 *val
= ch
- 'A' + 10;
1839 if ((ch
>= '0') && (ch
<= '9'))
1850 if (ch
>= 'a' && ch
<= 'f')
1851 return ch
- 'a' + 10;
1852 if (ch
>= '0' && ch
<= '9')
1854 if (ch
>= 'A' && ch
<= 'F')
1855 return ch
- 'A' + 10;
1860 stub_unpack_int (char *buff
, int fieldlength
)
1867 nibble
= stubhex (*buff
++);
1871 retval
= retval
<< 4;
1877 unpack_varlen_hex (char *buff
, /* packet to parse */
1881 ULONGEST retval
= 0;
1883 while (ishex (*buff
, &nibble
))
1886 retval
= retval
<< 4;
1887 retval
|= nibble
& 0x0f;
1894 unpack_nibble (char *buf
, int *val
)
1896 *val
= fromhex (*buf
++);
1901 pack_nibble (char *buf
, int nibble
)
1903 *buf
++ = hexchars
[(nibble
& 0x0f)];
1908 pack_hex_byte (char *pkt
, int byte
)
1910 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1911 *pkt
++ = hexchars
[(byte
& 0xf)];
1916 unpack_byte (char *buf
, int *value
)
1918 *value
= stub_unpack_int (buf
, 2);
1923 pack_int (char *buf
, int value
)
1925 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1926 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1927 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1928 buf
= pack_hex_byte (buf
, (value
& 0xff));
1933 unpack_int (char *buf
, int *value
)
1935 *value
= stub_unpack_int (buf
, 8);
1939 #if 0 /* Currently unused, uncomment when needed. */
1940 static char *pack_string (char *pkt
, char *string
);
1943 pack_string (char *pkt
, char *string
)
1948 len
= strlen (string
);
1950 len
= 200; /* Bigger than most GDB packets, junk??? */
1951 pkt
= pack_hex_byte (pkt
, len
);
1955 if ((ch
== '\0') || (ch
== '#'))
1956 ch
= '*'; /* Protect encapsulation. */
1961 #endif /* 0 (unused) */
1964 unpack_string (char *src
, char *dest
, int length
)
1973 pack_threadid (char *pkt
, threadref
*id
)
1976 unsigned char *altid
;
1978 altid
= (unsigned char *) id
;
1979 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1981 pkt
= pack_hex_byte (pkt
, *altid
++);
1987 unpack_threadid (char *inbuf
, threadref
*id
)
1990 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1993 altref
= (char *) id
;
1995 while (inbuf
< limit
)
1997 x
= stubhex (*inbuf
++);
1998 y
= stubhex (*inbuf
++);
1999 *altref
++ = (x
<< 4) | y
;
2004 /* Externally, threadrefs are 64 bits but internally, they are still
2005 ints. This is due to a mismatch of specifications. We would like
2006 to use 64bit thread references internally. This is an adapter
2010 int_to_threadref (threadref
*id
, int value
)
2012 unsigned char *scan
;
2014 scan
= (unsigned char *) id
;
2020 *scan
++ = (value
>> 24) & 0xff;
2021 *scan
++ = (value
>> 16) & 0xff;
2022 *scan
++ = (value
>> 8) & 0xff;
2023 *scan
++ = (value
& 0xff);
2027 threadref_to_int (threadref
*ref
)
2030 unsigned char *scan
;
2036 value
= (value
<< 8) | ((*scan
++) & 0xff);
2041 copy_threadref (threadref
*dest
, threadref
*src
)
2044 unsigned char *csrc
, *cdest
;
2046 csrc
= (unsigned char *) src
;
2047 cdest
= (unsigned char *) dest
;
2054 threadmatch (threadref
*dest
, threadref
*src
)
2056 /* Things are broken right now, so just assume we got a match. */
2058 unsigned char *srcp
, *destp
;
2060 srcp
= (char *) src
;
2061 destp
= (char *) dest
;
2065 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2072 threadid:1, # always request threadid
2079 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2082 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2084 *pkt
++ = 'q'; /* Info Query */
2085 *pkt
++ = 'P'; /* process or thread info */
2086 pkt
= pack_int (pkt
, mode
); /* mode */
2087 pkt
= pack_threadid (pkt
, id
); /* threadid */
2088 *pkt
= '\0'; /* terminate */
2092 /* These values tag the fields in a thread info response packet. */
2093 /* Tagging the fields allows us to request specific fields and to
2094 add more fields as time goes by. */
2096 #define TAG_THREADID 1 /* Echo the thread identifier. */
2097 #define TAG_EXISTS 2 /* Is this process defined enough to
2098 fetch registers and its stack? */
2099 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2100 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2101 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2105 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2106 struct gdb_ext_thread_info
*info
)
2108 struct remote_state
*rs
= get_remote_state ();
2112 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2115 /* info->threadid = 0; FIXME: implement zero_threadref. */
2117 info
->display
[0] = '\0';
2118 info
->shortname
[0] = '\0';
2119 info
->more_display
[0] = '\0';
2121 /* Assume the characters indicating the packet type have been
2123 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2124 pkt
= unpack_threadid (pkt
, &ref
);
2127 warning (_("Incomplete response to threadinfo request."));
2128 if (!threadmatch (&ref
, expectedref
))
2129 { /* This is an answer to a different request. */
2130 warning (_("ERROR RMT Thread info mismatch."));
2133 copy_threadref (&info
->threadid
, &ref
);
2135 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2137 /* Packets are terminated with nulls. */
2138 while ((pkt
< limit
) && mask
&& *pkt
)
2140 pkt
= unpack_int (pkt
, &tag
); /* tag */
2141 pkt
= unpack_byte (pkt
, &length
); /* length */
2142 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2144 warning (_("ERROR RMT: threadinfo tag mismatch."));
2148 if (tag
== TAG_THREADID
)
2152 warning (_("ERROR RMT: length of threadid is not 16."));
2156 pkt
= unpack_threadid (pkt
, &ref
);
2157 mask
= mask
& ~TAG_THREADID
;
2160 if (tag
== TAG_EXISTS
)
2162 info
->active
= stub_unpack_int (pkt
, length
);
2164 mask
= mask
& ~(TAG_EXISTS
);
2167 warning (_("ERROR RMT: 'exists' length too long."));
2173 if (tag
== TAG_THREADNAME
)
2175 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2176 mask
= mask
& ~TAG_THREADNAME
;
2179 if (tag
== TAG_DISPLAY
)
2181 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2182 mask
= mask
& ~TAG_DISPLAY
;
2185 if (tag
== TAG_MOREDISPLAY
)
2187 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2188 mask
= mask
& ~TAG_MOREDISPLAY
;
2191 warning (_("ERROR RMT: unknown thread info tag."));
2192 break; /* Not a tag we know about. */
2198 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2199 struct gdb_ext_thread_info
*info
)
2201 struct remote_state
*rs
= get_remote_state ();
2204 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2206 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2208 if (rs
->buf
[0] == '\0')
2211 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2216 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2219 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2220 threadref
*nextthread
)
2222 *pkt
++ = 'q'; /* info query packet */
2223 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2224 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2225 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2226 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2231 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2234 parse_threadlist_response (char *pkt
, int result_limit
,
2235 threadref
*original_echo
, threadref
*resultlist
,
2238 struct remote_state
*rs
= get_remote_state ();
2240 int count
, resultcount
, done
;
2243 /* Assume the 'q' and 'M chars have been stripped. */
2244 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2245 /* done parse past here */
2246 pkt
= unpack_byte (pkt
, &count
); /* count field */
2247 pkt
= unpack_nibble (pkt
, &done
);
2248 /* The first threadid is the argument threadid. */
2249 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2250 while ((count
-- > 0) && (pkt
< limit
))
2252 pkt
= unpack_threadid (pkt
, resultlist
++);
2253 if (resultcount
++ >= result_limit
)
2262 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2263 int *done
, int *result_count
, threadref
*threadlist
)
2265 struct remote_state
*rs
= get_remote_state ();
2266 static threadref echo_nextthread
;
2269 /* Trancate result limit to be smaller than the packet size. */
2270 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
2271 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2273 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2275 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2277 if (*rs
->buf
== '\0')
2281 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2284 if (!threadmatch (&echo_nextthread
, nextthread
))
2286 /* FIXME: This is a good reason to drop the packet. */
2287 /* Possably, there is a duplicate response. */
2289 retransmit immediatly - race conditions
2290 retransmit after timeout - yes
2292 wait for packet, then exit
2294 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2295 return 0; /* I choose simply exiting. */
2297 if (*result_count
<= 0)
2301 warning (_("RMT ERROR : failed to get remote thread list."));
2304 return result
; /* break; */
2306 if (*result_count
> result_limit
)
2309 warning (_("RMT ERROR: threadlist response longer than requested."));
2315 /* This is the interface between remote and threads, remotes upper
2318 /* remote_find_new_threads retrieves the thread list and for each
2319 thread in the list, looks up the thread in GDB's internal list,
2320 adding the thread if it does not already exist. This involves
2321 getting partial thread lists from the remote target so, polling the
2322 quit_flag is required. */
2325 /* About this many threadisds fit in a packet. */
2327 #define MAXTHREADLISTRESULTS 32
2330 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2333 int done
, i
, result_count
;
2337 static threadref nextthread
;
2338 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2343 if (loopcount
++ > looplimit
)
2346 warning (_("Remote fetch threadlist -infinite loop-."));
2349 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2350 &done
, &result_count
, resultthreadlist
))
2355 /* Clear for later iterations. */
2357 /* Setup to resume next batch of thread references, set nextthread. */
2358 if (result_count
>= 1)
2359 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2361 while (result_count
--)
2362 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2369 remote_newthread_step (threadref
*ref
, void *context
)
2371 int pid
= ptid_get_pid (inferior_ptid
);
2372 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2374 if (!in_thread_list (ptid
))
2376 return 1; /* continue iterator */
2379 #define CRAZY_MAX_THREADS 1000
2382 remote_current_thread (ptid_t oldpid
)
2384 struct remote_state
*rs
= get_remote_state ();
2387 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2388 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2389 return read_ptid (&rs
->buf
[2], NULL
);
2394 /* Find new threads for info threads command.
2395 * Original version, using John Metzler's thread protocol.
2399 remote_find_new_threads (void)
2401 remote_threadlist_iterator (remote_newthread_step
, 0,
2405 #if defined(HAVE_LIBEXPAT)
2407 typedef struct thread_item
2413 DEF_VEC_O(thread_item_t
);
2415 struct threads_parsing_context
2417 VEC (thread_item_t
) *items
;
2421 start_thread (struct gdb_xml_parser
*parser
,
2422 const struct gdb_xml_element
*element
,
2423 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2425 struct threads_parsing_context
*data
= user_data
;
2427 struct thread_item item
;
2430 id
= VEC_index (gdb_xml_value_s
, attributes
, 0)->value
;
2431 item
.ptid
= read_ptid (id
, NULL
);
2433 if (VEC_length (gdb_xml_value_s
, attributes
) > 1)
2434 item
.core
= *(ULONGEST
*) VEC_index (gdb_xml_value_s
, attributes
, 1)->value
;
2440 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2444 end_thread (struct gdb_xml_parser
*parser
,
2445 const struct gdb_xml_element
*element
,
2446 void *user_data
, const char *body_text
)
2448 struct threads_parsing_context
*data
= user_data
;
2450 if (body_text
&& *body_text
)
2451 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2454 const struct gdb_xml_attribute thread_attributes
[] = {
2455 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2456 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2457 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2460 const struct gdb_xml_element thread_children
[] = {
2461 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2464 const struct gdb_xml_element threads_children
[] = {
2465 { "thread", thread_attributes
, thread_children
,
2466 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2467 start_thread
, end_thread
},
2468 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2471 const struct gdb_xml_element threads_elements
[] = {
2472 { "threads", NULL
, threads_children
,
2473 GDB_XML_EF_NONE
, NULL
, NULL
},
2474 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2480 * Find all threads for info threads command.
2481 * Uses new thread protocol contributed by Cisco.
2482 * Falls back and attempts to use the older method (above)
2483 * if the target doesn't respond to the new method.
2487 remote_threads_info (struct target_ops
*ops
)
2489 struct remote_state
*rs
= get_remote_state ();
2493 if (remote_desc
== 0) /* paranoia */
2494 error (_("Command can only be used when connected to the remote target."));
2496 #if defined(HAVE_LIBEXPAT)
2497 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2499 char *xml
= target_read_stralloc (¤t_target
,
2500 TARGET_OBJECT_THREADS
, NULL
);
2502 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2505 struct gdb_xml_parser
*parser
;
2506 struct threads_parsing_context context
;
2507 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2510 parser
= gdb_xml_create_parser_and_cleanup (_("threads"),
2514 gdb_xml_use_dtd (parser
, "threads.dtd");
2516 if (gdb_xml_parse (parser
, xml
) == 0)
2519 struct thread_item
*item
;
2521 for (i
= 0; VEC_iterate (thread_item_t
, context
.items
, i
, item
); ++i
)
2523 if (!ptid_equal (item
->ptid
, null_ptid
))
2525 struct private_thread_info
*info
;
2526 /* In non-stop mode, we assume new found threads
2527 are running until proven otherwise with a
2528 stop reply. In all-stop, we can only get
2529 here if all threads are stopped. */
2530 int running
= non_stop
? 1 : 0;
2532 remote_notice_new_inferior (item
->ptid
, running
);
2534 info
= demand_private_info (item
->ptid
);
2535 info
->core
= item
->core
;
2536 info
->extra
= item
->extra
;
2539 xfree (item
->extra
);
2543 VEC_free (thread_item_t
, context
.items
);
2546 do_cleanups (back_to
);
2551 if (use_threadinfo_query
)
2553 putpkt ("qfThreadInfo");
2554 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2556 if (bufp
[0] != '\0') /* q packet recognized */
2558 while (*bufp
++ == 'm') /* reply contains one or more TID */
2562 new_thread
= read_ptid (bufp
, &bufp
);
2563 if (!ptid_equal (new_thread
, null_ptid
))
2565 /* In non-stop mode, we assume new found threads
2566 are running until proven otherwise with a
2567 stop reply. In all-stop, we can only get
2568 here if all threads are stopped. */
2569 int running
= non_stop
? 1 : 0;
2571 remote_notice_new_inferior (new_thread
, running
);
2574 while (*bufp
++ == ','); /* comma-separated list */
2575 putpkt ("qsThreadInfo");
2576 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2583 /* Only qfThreadInfo is supported in non-stop mode. */
2587 /* Else fall back to old method based on jmetzler protocol. */
2588 use_threadinfo_query
= 0;
2589 remote_find_new_threads ();
2594 * Collect a descriptive string about the given thread.
2595 * The target may say anything it wants to about the thread
2596 * (typically info about its blocked / runnable state, name, etc.).
2597 * This string will appear in the info threads display.
2599 * Optional: targets are not required to implement this function.
2603 remote_threads_extra_info (struct thread_info
*tp
)
2605 struct remote_state
*rs
= get_remote_state ();
2609 struct gdb_ext_thread_info threadinfo
;
2610 static char display_buf
[100]; /* arbitrary... */
2611 int n
= 0; /* position in display_buf */
2613 if (remote_desc
== 0) /* paranoia */
2614 internal_error (__FILE__
, __LINE__
,
2615 _("remote_threads_extra_info"));
2617 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2618 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2619 /* This is the main thread which was added by GDB. The remote
2620 server doesn't know about it. */
2623 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2625 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2626 if (info
&& info
->private)
2627 return info
->private->extra
;
2632 if (use_threadextra_query
)
2635 char *endb
= rs
->buf
+ get_remote_packet_size ();
2637 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2639 write_ptid (b
, endb
, tp
->ptid
);
2642 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2643 if (rs
->buf
[0] != 0)
2645 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2646 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2647 display_buf
[result
] = '\0';
2652 /* If the above query fails, fall back to the old method. */
2653 use_threadextra_query
= 0;
2654 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2655 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2656 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2657 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2658 if (threadinfo
.active
)
2660 if (*threadinfo
.shortname
)
2661 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2662 " Name: %s,", threadinfo
.shortname
);
2663 if (*threadinfo
.display
)
2664 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2665 " State: %s,", threadinfo
.display
);
2666 if (*threadinfo
.more_display
)
2667 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2668 " Priority: %s", threadinfo
.more_display
);
2672 /* For purely cosmetic reasons, clear up trailing commas. */
2673 if (',' == display_buf
[n
-1])
2674 display_buf
[n
-1] = ' ';
2682 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2685 remote_get_ada_task_ptid (long lwp
, long thread
)
2687 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2691 /* Restart the remote side; this is an extended protocol operation. */
2694 extended_remote_restart (void)
2696 struct remote_state
*rs
= get_remote_state ();
2698 /* Send the restart command; for reasons I don't understand the
2699 remote side really expects a number after the "R". */
2700 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2703 remote_fileio_reset ();
2706 /* Clean up connection to a remote debugger. */
2709 remote_close (int quitting
)
2711 if (remote_desc
== NULL
)
2712 return; /* already closed */
2714 /* Make sure we leave stdin registered in the event loop, and we
2715 don't leave the async SIGINT signal handler installed. */
2716 remote_terminal_ours ();
2718 serial_close (remote_desc
);
2721 /* We don't have a connection to the remote stub anymore. Get rid
2722 of all the inferiors and their threads we were controlling. */
2723 discard_all_inferiors ();
2725 /* We're no longer interested in any of these events. */
2726 discard_pending_stop_replies (-1);
2728 if (remote_async_inferior_event_token
)
2729 delete_async_event_handler (&remote_async_inferior_event_token
);
2730 if (remote_async_get_pending_events_token
)
2731 delete_async_event_handler (&remote_async_get_pending_events_token
);
2734 /* Query the remote side for the text, data and bss offsets. */
2739 struct remote_state
*rs
= get_remote_state ();
2742 int lose
, num_segments
= 0, do_sections
, do_segments
;
2743 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2744 struct section_offsets
*offs
;
2745 struct symfile_segment_data
*data
;
2747 if (symfile_objfile
== NULL
)
2750 putpkt ("qOffsets");
2751 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2754 if (buf
[0] == '\000')
2755 return; /* Return silently. Stub doesn't support
2759 warning (_("Remote failure reply: %s"), buf
);
2763 /* Pick up each field in turn. This used to be done with scanf, but
2764 scanf will make trouble if CORE_ADDR size doesn't match
2765 conversion directives correctly. The following code will work
2766 with any size of CORE_ADDR. */
2767 text_addr
= data_addr
= bss_addr
= 0;
2771 if (strncmp (ptr
, "Text=", 5) == 0)
2774 /* Don't use strtol, could lose on big values. */
2775 while (*ptr
&& *ptr
!= ';')
2776 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2778 if (strncmp (ptr
, ";Data=", 6) == 0)
2781 while (*ptr
&& *ptr
!= ';')
2782 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2787 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2790 while (*ptr
&& *ptr
!= ';')
2791 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2793 if (bss_addr
!= data_addr
)
2794 warning (_("Target reported unsupported offsets: %s"), buf
);
2799 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2802 /* Don't use strtol, could lose on big values. */
2803 while (*ptr
&& *ptr
!= ';')
2804 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2807 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2810 while (*ptr
&& *ptr
!= ';')
2811 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2819 error (_("Malformed response to offset query, %s"), buf
);
2820 else if (*ptr
!= '\0')
2821 warning (_("Target reported unsupported offsets: %s"), buf
);
2823 offs
= ((struct section_offsets
*)
2824 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2825 memcpy (offs
, symfile_objfile
->section_offsets
,
2826 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2828 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2829 do_segments
= (data
!= NULL
);
2830 do_sections
= num_segments
== 0;
2832 if (num_segments
> 0)
2834 segments
[0] = text_addr
;
2835 segments
[1] = data_addr
;
2837 /* If we have two segments, we can still try to relocate everything
2838 by assuming that the .text and .data offsets apply to the whole
2839 text and data segments. Convert the offsets given in the packet
2840 to base addresses for symfile_map_offsets_to_segments. */
2841 else if (data
&& data
->num_segments
== 2)
2843 segments
[0] = data
->segment_bases
[0] + text_addr
;
2844 segments
[1] = data
->segment_bases
[1] + data_addr
;
2847 /* If the object file has only one segment, assume that it is text
2848 rather than data; main programs with no writable data are rare,
2849 but programs with no code are useless. Of course the code might
2850 have ended up in the data segment... to detect that we would need
2851 the permissions here. */
2852 else if (data
&& data
->num_segments
== 1)
2854 segments
[0] = data
->segment_bases
[0] + text_addr
;
2857 /* There's no way to relocate by segment. */
2863 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2864 offs
, num_segments
, segments
);
2866 if (ret
== 0 && !do_sections
)
2867 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2874 free_symfile_segment_data (data
);
2878 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2880 /* This is a temporary kludge to force data and bss to use the same offsets
2881 because that's what nlmconv does now. The real solution requires changes
2882 to the stub and remote.c that I don't have time to do right now. */
2884 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2885 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2888 objfile_relocate (symfile_objfile
, offs
);
2891 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
2892 threads we know are stopped already. This is used during the
2893 initial remote connection in non-stop mode --- threads that are
2894 reported as already being stopped are left stopped. */
2897 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
2899 /* If we have a stop reply for this thread, it must be stopped. */
2900 if (peek_stop_reply (thread
->ptid
))
2901 set_stop_requested (thread
->ptid
, 1);
2906 /* Stub for catch_exception. */
2908 struct start_remote_args
2912 /* The current target. */
2913 struct target_ops
*target
;
2915 /* Non-zero if this is an extended-remote target. */
2919 /* Send interrupt_sequence to remote target. */
2921 send_interrupt_sequence ()
2923 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
2924 serial_write (remote_desc
, "\x03", 1);
2925 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
2926 serial_send_break (remote_desc
);
2927 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
2929 serial_send_break (remote_desc
);
2930 serial_write (remote_desc
, "g", 1);
2933 internal_error (__FILE__
, __LINE__
,
2934 _("Invalid value for interrupt_sequence_mode: %s."),
2935 interrupt_sequence_mode
);
2939 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2941 struct start_remote_args
*args
= opaque
;
2942 struct remote_state
*rs
= get_remote_state ();
2943 struct packet_config
*noack_config
;
2944 char *wait_status
= NULL
;
2946 immediate_quit
++; /* Allow user to interrupt it. */
2948 /* Ack any packet which the remote side has already sent. */
2949 serial_write (remote_desc
, "+", 1);
2951 if (interrupt_on_connect
)
2952 send_interrupt_sequence ();
2954 /* The first packet we send to the target is the optional "supported
2955 packets" request. If the target can answer this, it will tell us
2956 which later probes to skip. */
2957 remote_query_supported ();
2959 /* Next, we possibly activate noack mode.
2961 If the QStartNoAckMode packet configuration is set to AUTO,
2962 enable noack mode if the stub reported a wish for it with
2965 If set to TRUE, then enable noack mode even if the stub didn't
2966 report it in qSupported. If the stub doesn't reply OK, the
2967 session ends with an error.
2969 If FALSE, then don't activate noack mode, regardless of what the
2970 stub claimed should be the default with qSupported. */
2972 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2974 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2975 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2976 && noack_config
->support
== PACKET_ENABLE
))
2978 putpkt ("QStartNoAckMode");
2979 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2980 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2984 if (args
->extended_p
)
2986 /* Tell the remote that we are using the extended protocol. */
2988 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2991 /* Next, if the target can specify a description, read it. We do
2992 this before anything involving memory or registers. */
2993 target_find_description ();
2995 /* Next, now that we know something about the target, update the
2996 address spaces in the program spaces. */
2997 update_address_spaces ();
2999 /* On OSs where the list of libraries is global to all
3000 processes, we fetch them early. */
3001 if (gdbarch_has_global_solist (target_gdbarch
))
3002 solib_add (NULL
, args
->from_tty
, args
->target
, auto_solib_add
);
3006 if (!rs
->non_stop_aware
)
3007 error (_("Non-stop mode requested, but remote does not support non-stop"));
3009 putpkt ("QNonStop:1");
3010 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3012 if (strcmp (rs
->buf
, "OK") != 0)
3013 error ("Remote refused setting non-stop mode with: %s", rs
->buf
);
3015 /* Find about threads and processes the stub is already
3016 controlling. We default to adding them in the running state.
3017 The '?' query below will then tell us about which threads are
3019 remote_threads_info (args
->target
);
3021 else if (rs
->non_stop_aware
)
3023 /* Don't assume that the stub can operate in all-stop mode.
3024 Request it explicitely. */
3025 putpkt ("QNonStop:0");
3026 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3028 if (strcmp (rs
->buf
, "OK") != 0)
3029 error ("Remote refused setting all-stop mode with: %s", rs
->buf
);
3032 /* Check whether the target is running now. */
3034 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3038 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3040 if (!args
->extended_p
)
3041 error (_("The target is not running (try extended-remote?)"));
3043 /* We're connected, but not running. Drop out before we
3044 call start_remote. */
3049 /* Save the reply for later. */
3050 wait_status
= alloca (strlen (rs
->buf
) + 1);
3051 strcpy (wait_status
, rs
->buf
);
3054 /* Let the stub know that we want it to return the thread. */
3055 set_continue_thread (minus_one_ptid
);
3057 /* Without this, some commands which require an active target
3058 (such as kill) won't work. This variable serves (at least)
3059 double duty as both the pid of the target process (if it has
3060 such), and as a flag indicating that a target is active.
3061 These functions should be split out into seperate variables,
3062 especially since GDB will someday have a notion of debugging
3063 several processes. */
3064 inferior_ptid
= magic_null_ptid
;
3066 /* Now, if we have thread information, update inferior_ptid. */
3067 inferior_ptid
= remote_current_thread (inferior_ptid
);
3069 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3071 /* Always add the main thread. */
3072 add_thread_silent (inferior_ptid
);
3074 get_offsets (); /* Get text, data & bss offsets. */
3076 /* If we could not find a description using qXfer, and we know
3077 how to do it some other way, try again. This is not
3078 supported for non-stop; it could be, but it is tricky if
3079 there are no stopped threads when we connect. */
3080 if (remote_read_description_p (args
->target
)
3081 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3083 target_clear_description ();
3084 target_find_description ();
3087 /* Use the previously fetched status. */
3088 gdb_assert (wait_status
!= NULL
);
3089 strcpy (rs
->buf
, wait_status
);
3090 rs
->cached_wait_status
= 1;
3093 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
3097 /* Clear WFI global state. Do this before finding about new
3098 threads and inferiors, and setting the current inferior.
3099 Otherwise we would clear the proceed status of the current
3100 inferior when we want its stop_soon state to be preserved
3101 (see notice_new_inferior). */
3102 init_wait_for_inferior ();
3104 /* In non-stop, we will either get an "OK", meaning that there
3105 are no stopped threads at this time; or, a regular stop
3106 reply. In the latter case, there may be more than one thread
3107 stopped --- we pull them all out using the vStopped
3109 if (strcmp (rs
->buf
, "OK") != 0)
3111 struct stop_reply
*stop_reply
;
3112 struct cleanup
*old_chain
;
3114 stop_reply
= stop_reply_xmalloc ();
3115 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3117 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3118 discard_cleanups (old_chain
);
3120 /* get_pending_stop_replies acks this one, and gets the rest
3122 pending_stop_reply
= stop_reply
;
3123 remote_get_pending_stop_replies ();
3125 /* Make sure that threads that were stopped remain
3127 iterate_over_threads (set_stop_requested_callback
, NULL
);
3130 if (target_can_async_p ())
3131 target_async (inferior_event_handler
, 0);
3133 if (thread_count () == 0)
3135 if (!args
->extended_p
)
3136 error (_("The target is not running (try extended-remote?)"));
3138 /* We're connected, but not running. Drop out before we
3139 call start_remote. */
3143 /* Let the stub know that we want it to return the thread. */
3145 /* Force the stub to choose a thread. */
3146 set_general_thread (null_ptid
);
3149 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3150 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3151 error (_("remote didn't report the current thread in non-stop mode"));
3153 get_offsets (); /* Get text, data & bss offsets. */
3155 /* In non-stop mode, any cached wait status will be stored in
3156 the stop reply queue. */
3157 gdb_assert (wait_status
== NULL
);
3160 /* If we connected to a live target, do some additional setup. */
3161 if (target_has_execution
)
3163 if (exec_bfd
) /* No use without an exec file. */
3164 remote_check_symbols (symfile_objfile
);
3167 /* Possibly the target has been engaged in a trace run started
3168 previously; find out where things are at. */
3169 if (remote_get_trace_status (current_trace_status ()) != -1)
3171 struct uploaded_tp
*uploaded_tps
= NULL
;
3172 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3174 if (current_trace_status ()->running
)
3175 printf_filtered (_("Trace is already running on the target.\n"));
3177 /* Get trace state variables first, they may be checked when
3178 parsing uploaded commands. */
3180 remote_upload_trace_state_variables (&uploaded_tsvs
);
3182 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3184 remote_upload_tracepoints (&uploaded_tps
);
3186 merge_uploaded_tracepoints (&uploaded_tps
);
3189 /* If breakpoints are global, insert them now. */
3190 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3191 && breakpoints_always_inserted_mode ())
3192 insert_breakpoints ();
3195 /* Open a connection to a remote debugger.
3196 NAME is the filename used for communication. */
3199 remote_open (char *name
, int from_tty
)
3201 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3204 /* Open a connection to a remote debugger using the extended
3205 remote gdb protocol. NAME is the filename used for communication. */
3208 extended_remote_open (char *name
, int from_tty
)
3210 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3213 /* Generic code for opening a connection to a remote target. */
3216 init_all_packet_configs (void)
3219 for (i
= 0; i
< PACKET_MAX
; i
++)
3220 update_packet_config (&remote_protocol_packets
[i
]);
3223 /* Symbol look-up. */
3226 remote_check_symbols (struct objfile
*objfile
)
3228 struct remote_state
*rs
= get_remote_state ();
3229 char *msg
, *reply
, *tmp
;
3230 struct minimal_symbol
*sym
;
3233 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3236 /* Make sure the remote is pointing at the right process. */
3237 set_general_process ();
3239 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3240 because we need both at the same time. */
3241 msg
= alloca (get_remote_packet_size ());
3243 /* Invite target to request symbol lookups. */
3245 putpkt ("qSymbol::");
3246 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3247 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3250 while (strncmp (reply
, "qSymbol:", 8) == 0)
3253 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3255 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3257 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3260 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3261 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3263 /* If this is a function address, return the start of code
3264 instead of any data function descriptor. */
3265 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3269 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3270 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3274 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3279 static struct serial
*
3280 remote_serial_open (char *name
)
3282 static int udp_warning
= 0;
3284 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3285 of in ser-tcp.c, because it is the remote protocol assuming that the
3286 serial connection is reliable and not the serial connection promising
3288 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3291 The remote protocol may be unreliable over UDP.\n\
3292 Some events may be lost, rendering further debugging impossible."));
3296 return serial_open (name
);
3299 /* This type describes each known response to the qSupported
3301 struct protocol_feature
3303 /* The name of this protocol feature. */
3306 /* The default for this protocol feature. */
3307 enum packet_support default_support
;
3309 /* The function to call when this feature is reported, or after
3310 qSupported processing if the feature is not supported.
3311 The first argument points to this structure. The second
3312 argument indicates whether the packet requested support be
3313 enabled, disabled, or probed (or the default, if this function
3314 is being called at the end of processing and this feature was
3315 not reported). The third argument may be NULL; if not NULL, it
3316 is a NUL-terminated string taken from the packet following
3317 this feature's name and an equals sign. */
3318 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3321 /* The corresponding packet for this feature. Only used if
3322 FUNC is remote_supported_packet. */
3327 remote_supported_packet (const struct protocol_feature
*feature
,
3328 enum packet_support support
,
3329 const char *argument
)
3333 warning (_("Remote qSupported response supplied an unexpected value for"
3334 " \"%s\"."), feature
->name
);
3338 if (remote_protocol_packets
[feature
->packet
].support
3339 == PACKET_SUPPORT_UNKNOWN
)
3340 remote_protocol_packets
[feature
->packet
].support
= support
;
3344 remote_packet_size (const struct protocol_feature
*feature
,
3345 enum packet_support support
, const char *value
)
3347 struct remote_state
*rs
= get_remote_state ();
3352 if (support
!= PACKET_ENABLE
)
3355 if (value
== NULL
|| *value
== '\0')
3357 warning (_("Remote target reported \"%s\" without a size."),
3363 packet_size
= strtol (value
, &value_end
, 16);
3364 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3366 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3367 feature
->name
, value
);
3371 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3373 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3374 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3375 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3378 /* Record the new maximum packet size. */
3379 rs
->explicit_packet_size
= packet_size
;
3383 remote_multi_process_feature (const struct protocol_feature
*feature
,
3384 enum packet_support support
, const char *value
)
3386 struct remote_state
*rs
= get_remote_state ();
3387 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3391 remote_non_stop_feature (const struct protocol_feature
*feature
,
3392 enum packet_support support
, const char *value
)
3394 struct remote_state
*rs
= get_remote_state ();
3395 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3399 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3400 enum packet_support support
,
3403 struct remote_state
*rs
= get_remote_state ();
3404 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3408 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3409 enum packet_support support
,
3412 struct remote_state
*rs
= get_remote_state ();
3413 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3417 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3418 enum packet_support support
,
3421 struct remote_state
*rs
= get_remote_state ();
3422 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3425 static struct protocol_feature remote_protocol_features
[] = {
3426 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3427 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3428 PACKET_qXfer_auxv
},
3429 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3430 PACKET_qXfer_features
},
3431 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3432 PACKET_qXfer_libraries
},
3433 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3434 PACKET_qXfer_memory_map
},
3435 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3436 PACKET_qXfer_spu_read
},
3437 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3438 PACKET_qXfer_spu_write
},
3439 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3440 PACKET_qXfer_osdata
},
3441 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3442 PACKET_qXfer_threads
},
3443 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3444 PACKET_QPassSignals
},
3445 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3446 PACKET_QStartNoAckMode
},
3447 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3448 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3449 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3450 PACKET_qXfer_siginfo_read
},
3451 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3452 PACKET_qXfer_siginfo_write
},
3453 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3454 PACKET_ConditionalTracepoints
},
3455 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3456 PACKET_FastTracepoints
},
3457 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3459 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3461 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3463 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3464 PACKET_TracepointSource
},
3467 static char *remote_support_xml
;
3469 /* Register string appended to "xmlRegisters=" in qSupported query. */
3472 register_remote_support_xml (const char *xml ATTRIBUTE_UNUSED
)
3474 #if defined(HAVE_LIBEXPAT)
3475 if (remote_support_xml
== NULL
)
3476 remote_support_xml
= concat ("xmlRegisters=", xml
, NULL
);
3479 char *copy
= xstrdup (remote_support_xml
+ 13);
3480 char *p
= strtok (copy
, ",");
3484 if (strcmp (p
, xml
) == 0)
3491 while ((p
= strtok (NULL
, ",")) != NULL
);
3494 p
= concat (remote_support_xml
, ",", xml
, NULL
);
3495 xfree (remote_support_xml
);
3496 remote_support_xml
= p
;
3502 remote_query_supported_append (char *msg
, const char *append
)
3506 char *p
= concat (msg
, ";", append
, NULL
);
3511 return xstrdup (append
);
3515 remote_query_supported (void)
3517 struct remote_state
*rs
= get_remote_state ();
3520 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3522 /* The packet support flags are handled differently for this packet
3523 than for most others. We treat an error, a disabled packet, and
3524 an empty response identically: any features which must be reported
3525 to be used will be automatically disabled. An empty buffer
3526 accomplishes this, since that is also the representation for a list
3527 containing no features. */
3530 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3533 const char *qsupported
= gdbarch_qsupported (target_gdbarch
);
3536 q
= remote_query_supported_append (q
, "multiprocess+");
3539 q
= remote_query_supported_append (q
, qsupported
);
3541 if (remote_support_xml
)
3542 q
= remote_query_supported_append (q
, remote_support_xml
);
3546 char *p
= concat ("qSupported:", q
, NULL
);
3552 putpkt ("qSupported");
3554 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3556 /* If an error occured, warn, but do not return - just reset the
3557 buffer to empty and go on to disable features. */
3558 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3561 warning (_("Remote failure reply: %s"), rs
->buf
);
3566 memset (seen
, 0, sizeof (seen
));
3571 enum packet_support is_supported
;
3572 char *p
, *end
, *name_end
, *value
;
3574 /* First separate out this item from the rest of the packet. If
3575 there's another item after this, we overwrite the separator
3576 (terminated strings are much easier to work with). */
3578 end
= strchr (p
, ';');
3581 end
= p
+ strlen (p
);
3591 warning (_("empty item in \"qSupported\" response"));
3596 name_end
= strchr (p
, '=');
3599 /* This is a name=value entry. */
3600 is_supported
= PACKET_ENABLE
;
3601 value
= name_end
+ 1;
3610 is_supported
= PACKET_ENABLE
;
3614 is_supported
= PACKET_DISABLE
;
3618 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3622 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
3628 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3629 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3631 const struct protocol_feature
*feature
;
3634 feature
= &remote_protocol_features
[i
];
3635 feature
->func (feature
, is_supported
, value
);
3640 /* If we increased the packet size, make sure to increase the global
3641 buffer size also. We delay this until after parsing the entire
3642 qSupported packet, because this is the same buffer we were
3644 if (rs
->buf_size
< rs
->explicit_packet_size
)
3646 rs
->buf_size
= rs
->explicit_packet_size
;
3647 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3650 /* Handle the defaults for unmentioned features. */
3651 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3654 const struct protocol_feature
*feature
;
3656 feature
= &remote_protocol_features
[i
];
3657 feature
->func (feature
, feature
->default_support
, NULL
);
3663 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
3665 struct remote_state
*rs
= get_remote_state ();
3668 error (_("To open a remote debug connection, you need to specify what\n"
3669 "serial device is attached to the remote system\n"
3670 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3672 /* See FIXME above. */
3673 if (!target_async_permitted
)
3674 wait_forever_enabled_p
= 1;
3676 /* If we're connected to a running target, target_preopen will kill it.
3677 But if we're connected to a target system with no running process,
3678 then we will still be connected when it returns. Ask this question
3679 first, before target_preopen has a chance to kill anything. */
3680 if (remote_desc
!= NULL
&& !have_inferiors ())
3683 || query (_("Already connected to a remote target. Disconnect? ")))
3686 error (_("Still connected."));
3689 target_preopen (from_tty
);
3691 unpush_target (target
);
3693 /* This time without a query. If we were connected to an
3694 extended-remote target and target_preopen killed the running
3695 process, we may still be connected. If we are starting "target
3696 remote" now, the extended-remote target will not have been
3697 removed by unpush_target. */
3698 if (remote_desc
!= NULL
&& !have_inferiors ())
3701 /* Make sure we send the passed signals list the next time we resume. */
3702 xfree (last_pass_packet
);
3703 last_pass_packet
= NULL
;
3705 remote_fileio_reset ();
3706 reopen_exec_file ();
3709 remote_desc
= remote_serial_open (name
);
3711 perror_with_name (name
);
3713 if (baud_rate
!= -1)
3715 if (serial_setbaudrate (remote_desc
, baud_rate
))
3717 /* The requested speed could not be set. Error out to
3718 top level after closing remote_desc. Take care to
3719 set remote_desc to NULL to avoid closing remote_desc
3721 serial_close (remote_desc
);
3723 perror_with_name (name
);
3727 serial_raw (remote_desc
);
3729 /* If there is something sitting in the buffer we might take it as a
3730 response to a command, which would be bad. */
3731 serial_flush_input (remote_desc
);
3735 puts_filtered ("Remote debugging using ");
3736 puts_filtered (name
);
3737 puts_filtered ("\n");
3739 push_target (target
); /* Switch to using remote target now. */
3741 /* Register extra event sources in the event loop. */
3742 remote_async_inferior_event_token
3743 = create_async_event_handler (remote_async_inferior_event_handler
,
3745 remote_async_get_pending_events_token
3746 = create_async_event_handler (remote_async_get_pending_events_handler
,
3749 /* Reset the target state; these things will be queried either by
3750 remote_query_supported or as they are needed. */
3751 init_all_packet_configs ();
3752 rs
->cached_wait_status
= 0;
3753 rs
->explicit_packet_size
= 0;
3755 rs
->multi_process_aware
= 0;
3756 rs
->extended
= extended_p
;
3757 rs
->non_stop_aware
= 0;
3758 rs
->waiting_for_stop_reply
= 0;
3759 rs
->ctrlc_pending_p
= 0;
3761 general_thread
= not_sent_ptid
;
3762 continue_thread
= not_sent_ptid
;
3764 /* Probe for ability to use "ThreadInfo" query, as required. */
3765 use_threadinfo_query
= 1;
3766 use_threadextra_query
= 1;
3768 if (target_async_permitted
)
3770 /* With this target we start out by owning the terminal. */
3771 remote_async_terminal_ours_p
= 1;
3773 /* FIXME: cagney/1999-09-23: During the initial connection it is
3774 assumed that the target is already ready and able to respond to
3775 requests. Unfortunately remote_start_remote() eventually calls
3776 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
3777 around this. Eventually a mechanism that allows
3778 wait_for_inferior() to expect/get timeouts will be
3780 wait_forever_enabled_p
= 0;
3783 /* First delete any symbols previously loaded from shared libraries. */
3784 no_shared_libraries (NULL
, 0);
3787 init_thread_list ();
3789 /* Start the remote connection. If error() or QUIT, discard this
3790 target (we'd otherwise be in an inconsistent state) and then
3791 propogate the error on up the exception chain. This ensures that
3792 the caller doesn't stumble along blindly assuming that the
3793 function succeeded. The CLI doesn't have this problem but other
3794 UI's, such as MI do.
3796 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
3797 this function should return an error indication letting the
3798 caller restore the previous state. Unfortunately the command
3799 ``target remote'' is directly wired to this function making that
3800 impossible. On a positive note, the CLI side of this problem has
3801 been fixed - the function set_cmd_context() makes it possible for
3802 all the ``target ....'' commands to share a common callback
3803 function. See cli-dump.c. */
3805 struct gdb_exception ex
;
3806 struct start_remote_args args
;
3808 args
.from_tty
= from_tty
;
3809 args
.target
= target
;
3810 args
.extended_p
= extended_p
;
3812 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
3815 /* Pop the partially set up target - unless something else did
3816 already before throwing the exception. */
3817 if (remote_desc
!= NULL
)
3819 if (target_async_permitted
)
3820 wait_forever_enabled_p
= 1;
3821 throw_exception (ex
);
3825 if (target_async_permitted
)
3826 wait_forever_enabled_p
= 1;
3829 /* This takes a program previously attached to and detaches it. After
3830 this is done, GDB can be used to debug some other program. We
3831 better not have left any breakpoints in the target program or it'll
3832 die when it hits one. */
3835 remote_detach_1 (char *args
, int from_tty
, int extended
)
3837 int pid
= ptid_get_pid (inferior_ptid
);
3838 struct remote_state
*rs
= get_remote_state ();
3841 error (_("Argument given to \"detach\" when remotely debugging."));
3843 if (!target_has_execution
)
3844 error (_("No process to detach from."));
3846 /* Tell the remote target to detach. */
3847 if (remote_multi_process_p (rs
))
3848 sprintf (rs
->buf
, "D;%x", pid
);
3850 strcpy (rs
->buf
, "D");
3853 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3855 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3857 else if (rs
->buf
[0] == '\0')
3858 error (_("Remote doesn't know how to detach"));
3860 error (_("Can't detach process."));
3864 if (remote_multi_process_p (rs
))
3865 printf_filtered (_("Detached from remote %s.\n"),
3866 target_pid_to_str (pid_to_ptid (pid
)));
3870 puts_filtered (_("Detached from remote process.\n"));
3872 puts_filtered (_("Ending remote debugging.\n"));
3876 discard_pending_stop_replies (pid
);
3877 target_mourn_inferior ();
3881 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3883 remote_detach_1 (args
, from_tty
, 0);
3887 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3889 remote_detach_1 (args
, from_tty
, 1);
3892 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3895 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3898 error (_("Argument given to \"disconnect\" when remotely debugging."));
3900 /* Make sure we unpush even the extended remote targets; mourn
3901 won't do it. So call remote_mourn_1 directly instead of
3902 target_mourn_inferior. */
3903 remote_mourn_1 (target
);
3906 puts_filtered ("Ending remote debugging.\n");
3909 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3910 be chatty about it. */
3913 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3915 struct remote_state
*rs
= get_remote_state ();
3917 char *wait_status
= NULL
;
3919 pid
= parse_pid_to_attach (args
);
3921 /* Remote PID can be freely equal to getpid, do not check it here the same
3922 way as in other targets. */
3924 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3925 error (_("This target does not support attaching to a process"));
3927 sprintf (rs
->buf
, "vAttach;%x", pid
);
3929 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3931 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3934 printf_unfiltered (_("Attached to %s\n"),
3935 target_pid_to_str (pid_to_ptid (pid
)));
3939 /* Save the reply for later. */
3940 wait_status
= alloca (strlen (rs
->buf
) + 1);
3941 strcpy (wait_status
, rs
->buf
);
3943 else if (strcmp (rs
->buf
, "OK") != 0)
3944 error (_("Attaching to %s failed with: %s"),
3945 target_pid_to_str (pid_to_ptid (pid
)),
3948 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3949 error (_("This target does not support attaching to a process"));
3951 error (_("Attaching to %s failed"),
3952 target_pid_to_str (pid_to_ptid (pid
)));
3954 set_current_inferior (remote_add_inferior (pid
, 1));
3956 inferior_ptid
= pid_to_ptid (pid
);
3960 struct thread_info
*thread
;
3962 /* Get list of threads. */
3963 remote_threads_info (target
);
3965 thread
= first_thread_of_process (pid
);
3967 inferior_ptid
= thread
->ptid
;
3969 inferior_ptid
= pid_to_ptid (pid
);
3971 /* Invalidate our notion of the remote current thread. */
3972 record_currthread (minus_one_ptid
);
3976 /* Now, if we have thread information, update inferior_ptid. */
3977 inferior_ptid
= remote_current_thread (inferior_ptid
);
3979 /* Add the main thread to the thread list. */
3980 add_thread_silent (inferior_ptid
);
3983 /* Next, if the target can specify a description, read it. We do
3984 this before anything involving memory or registers. */
3985 target_find_description ();
3989 /* Use the previously fetched status. */
3990 gdb_assert (wait_status
!= NULL
);
3992 if (target_can_async_p ())
3994 struct stop_reply
*stop_reply
;
3995 struct cleanup
*old_chain
;
3997 stop_reply
= stop_reply_xmalloc ();
3998 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3999 remote_parse_stop_reply (wait_status
, stop_reply
);
4000 discard_cleanups (old_chain
);
4001 push_stop_reply (stop_reply
);
4003 target_async (inferior_event_handler
, 0);
4007 gdb_assert (wait_status
!= NULL
);
4008 strcpy (rs
->buf
, wait_status
);
4009 rs
->cached_wait_status
= 1;
4013 gdb_assert (wait_status
== NULL
);
4017 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4019 extended_remote_attach_1 (ops
, args
, from_tty
);
4022 /* Convert hex digit A to a number. */
4027 if (a
>= '0' && a
<= '9')
4029 else if (a
>= 'a' && a
<= 'f')
4030 return a
- 'a' + 10;
4031 else if (a
>= 'A' && a
<= 'F')
4032 return a
- 'A' + 10;
4034 error (_("Reply contains invalid hex digit %d"), a
);
4038 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4042 for (i
= 0; i
< count
; i
++)
4044 if (hex
[0] == 0 || hex
[1] == 0)
4046 /* Hex string is short, or of uneven length.
4047 Return the count that has been converted so far. */
4050 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4056 /* Convert number NIB to a hex digit. */
4064 return 'a' + nib
- 10;
4068 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4071 /* May use a length, or a nul-terminated string as input. */
4073 count
= strlen ((char *) bin
);
4075 for (i
= 0; i
< count
; i
++)
4077 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4078 *hex
++ = tohex (*bin
++ & 0xf);
4084 /* Check for the availability of vCont. This function should also check
4088 remote_vcont_probe (struct remote_state
*rs
)
4092 strcpy (rs
->buf
, "vCont?");
4094 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4097 /* Make sure that the features we assume are supported. */
4098 if (strncmp (buf
, "vCont", 5) == 0)
4101 int support_s
, support_S
, support_c
, support_C
;
4107 rs
->support_vCont_t
= 0;
4108 while (p
&& *p
== ';')
4111 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4113 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4115 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4117 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4119 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4120 rs
->support_vCont_t
= 1;
4122 p
= strchr (p
, ';');
4125 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4126 BUF will make packet_ok disable the packet. */
4127 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4131 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4134 /* Helper function for building "vCont" resumptions. Write a
4135 resumption to P. ENDP points to one-passed-the-end of the buffer
4136 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4137 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4138 resumed thread should be single-stepped and/or signalled. If PTID
4139 equals minus_one_ptid, then all threads are resumed; if PTID
4140 represents a process, then all threads of the process are resumed;
4141 the thread to be stepped and/or signalled is given in the global
4145 append_resumption (char *p
, char *endp
,
4146 ptid_t ptid
, int step
, enum target_signal siggnal
)
4148 struct remote_state
*rs
= get_remote_state ();
4150 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4151 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4153 p
+= xsnprintf (p
, endp
- p
, ";s");
4154 else if (siggnal
!= TARGET_SIGNAL_0
)
4155 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4157 p
+= xsnprintf (p
, endp
- p
, ";c");
4159 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4163 /* All (-1) threads of process. */
4164 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4166 p
+= xsnprintf (p
, endp
- p
, ":");
4167 p
= write_ptid (p
, endp
, nptid
);
4169 else if (!ptid_equal (ptid
, minus_one_ptid
))
4171 p
+= xsnprintf (p
, endp
- p
, ":");
4172 p
= write_ptid (p
, endp
, ptid
);
4178 /* Resume the remote inferior by using a "vCont" packet. The thread
4179 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4180 resumed thread should be single-stepped and/or signalled. If PTID
4181 equals minus_one_ptid, then all threads are resumed; the thread to
4182 be stepped and/or signalled is given in the global INFERIOR_PTID.
4183 This function returns non-zero iff it resumes the inferior.
4185 This function issues a strict subset of all possible vCont commands at the
4189 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4191 struct remote_state
*rs
= get_remote_state ();
4195 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4196 remote_vcont_probe (rs
);
4198 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4202 endp
= rs
->buf
+ get_remote_packet_size ();
4204 /* If we could generate a wider range of packets, we'd have to worry
4205 about overflowing BUF. Should there be a generic
4206 "multi-part-packet" packet? */
4208 p
+= xsnprintf (p
, endp
- p
, "vCont");
4210 if (ptid_equal (ptid
, magic_null_ptid
))
4212 /* MAGIC_NULL_PTID means that we don't have any active threads,
4213 so we don't have any TID numbers the inferior will
4214 understand. Make sure to only send forms that do not specify
4216 p
= append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4218 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4220 /* Resume all threads (of all processes, or of a single
4221 process), with preference for INFERIOR_PTID. This assumes
4222 inferior_ptid belongs to the set of all threads we are about
4224 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4226 /* Step inferior_ptid, with or without signal. */
4227 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4230 /* And continue others without a signal. */
4231 p
= append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4235 /* Scheduler locking; resume only PTID. */
4236 p
= append_resumption (p
, endp
, ptid
, step
, siggnal
);
4239 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4244 /* In non-stop, the stub replies to vCont with "OK". The stop
4245 reply will be reported asynchronously by means of a `%Stop'
4247 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4248 if (strcmp (rs
->buf
, "OK") != 0)
4249 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4255 /* Tell the remote machine to resume. */
4257 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4259 static int last_sent_step
;
4262 remote_resume (struct target_ops
*ops
,
4263 ptid_t ptid
, int step
, enum target_signal siggnal
)
4265 struct remote_state
*rs
= get_remote_state ();
4268 last_sent_signal
= siggnal
;
4269 last_sent_step
= step
;
4271 /* Update the inferior on signals to silently pass, if they've changed. */
4272 remote_pass_signals ();
4274 /* The vCont packet doesn't need to specify threads via Hc. */
4275 /* No reverse support (yet) for vCont. */
4276 if (execution_direction
!= EXEC_REVERSE
)
4277 if (remote_vcont_resume (ptid
, step
, siggnal
))
4280 /* All other supported resume packets do use Hc, so set the continue
4282 if (ptid_equal (ptid
, minus_one_ptid
))
4283 set_continue_thread (any_thread_ptid
);
4285 set_continue_thread (ptid
);
4288 if (execution_direction
== EXEC_REVERSE
)
4290 /* We don't pass signals to the target in reverse exec mode. */
4291 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4292 warning (" - Can't pass signal %d to target in reverse: ignored.\n",
4296 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4297 error (_("Remote reverse-step not supported."));
4299 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4300 error (_("Remote reverse-continue not supported."));
4302 strcpy (buf
, step
? "bs" : "bc");
4304 else if (siggnal
!= TARGET_SIGNAL_0
)
4306 buf
[0] = step
? 'S' : 'C';
4307 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4308 buf
[2] = tohex (((int) siggnal
) & 0xf);
4312 strcpy (buf
, step
? "s" : "c");
4317 /* We are about to start executing the inferior, let's register it
4318 with the event loop. NOTE: this is the one place where all the
4319 execution commands end up. We could alternatively do this in each
4320 of the execution commands in infcmd.c. */
4321 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4322 into infcmd.c in order to allow inferior function calls to work
4323 NOT asynchronously. */
4324 if (target_can_async_p ())
4325 target_async (inferior_event_handler
, 0);
4327 /* We've just told the target to resume. The remote server will
4328 wait for the inferior to stop, and then send a stop reply. In
4329 the mean time, we can't start another command/query ourselves
4330 because the stub wouldn't be ready to process it. This applies
4331 only to the base all-stop protocol, however. In non-stop (which
4332 only supports vCont), the stub replies with an "OK", and is
4333 immediate able to process further serial input. */
4335 rs
->waiting_for_stop_reply
= 1;
4339 /* Set up the signal handler for SIGINT, while the target is
4340 executing, ovewriting the 'regular' SIGINT signal handler. */
4342 initialize_sigint_signal_handler (void)
4344 signal (SIGINT
, handle_remote_sigint
);
4347 /* Signal handler for SIGINT, while the target is executing. */
4349 handle_remote_sigint (int sig
)
4351 signal (sig
, handle_remote_sigint_twice
);
4352 mark_async_signal_handler_wrapper (sigint_remote_token
);
4355 /* Signal handler for SIGINT, installed after SIGINT has already been
4356 sent once. It will take effect the second time that the user sends
4359 handle_remote_sigint_twice (int sig
)
4361 signal (sig
, handle_remote_sigint
);
4362 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4365 /* Perform the real interruption of the target execution, in response
4368 async_remote_interrupt (gdb_client_data arg
)
4371 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4373 target_stop (inferior_ptid
);
4376 /* Perform interrupt, if the first attempt did not succeed. Just give
4377 up on the target alltogether. */
4379 async_remote_interrupt_twice (gdb_client_data arg
)
4382 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4387 /* Reinstall the usual SIGINT handlers, after the target has
4390 cleanup_sigint_signal_handler (void *dummy
)
4392 signal (SIGINT
, handle_sigint
);
4395 /* Send ^C to target to halt it. Target will respond, and send us a
4397 static void (*ofunc
) (int);
4399 /* The command line interface's stop routine. This function is installed
4400 as a signal handler for SIGINT. The first time a user requests a
4401 stop, we call remote_stop to send a break or ^C. If there is no
4402 response from the target (it didn't stop when the user requested it),
4403 we ask the user if he'd like to detach from the target. */
4405 remote_interrupt (int signo
)
4407 /* If this doesn't work, try more severe steps. */
4408 signal (signo
, remote_interrupt_twice
);
4410 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4413 /* The user typed ^C twice. */
4416 remote_interrupt_twice (int signo
)
4418 signal (signo
, ofunc
);
4419 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4420 signal (signo
, remote_interrupt
);
4423 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4424 thread, all threads of a remote process, or all threads of all
4428 remote_stop_ns (ptid_t ptid
)
4430 struct remote_state
*rs
= get_remote_state ();
4432 char *endp
= rs
->buf
+ get_remote_packet_size ();
4434 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4435 remote_vcont_probe (rs
);
4437 if (!rs
->support_vCont_t
)
4438 error (_("Remote server does not support stopping threads"));
4440 if (ptid_equal (ptid
, minus_one_ptid
)
4441 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4442 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4447 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4449 if (ptid_is_pid (ptid
))
4450 /* All (-1) threads of process. */
4451 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4454 /* Small optimization: if we already have a stop reply for
4455 this thread, no use in telling the stub we want this
4457 if (peek_stop_reply (ptid
))
4463 p
= write_ptid (p
, endp
, nptid
);
4466 /* In non-stop, we get an immediate OK reply. The stop reply will
4467 come in asynchronously by notification. */
4469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4470 if (strcmp (rs
->buf
, "OK") != 0)
4471 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4474 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4475 remote target. It is undefined which thread of which process
4476 reports the stop. */
4479 remote_stop_as (ptid_t ptid
)
4481 struct remote_state
*rs
= get_remote_state ();
4483 rs
->ctrlc_pending_p
= 1;
4485 /* If the inferior is stopped already, but the core didn't know
4486 about it yet, just ignore the request. The cached wait status
4487 will be collected in remote_wait. */
4488 if (rs
->cached_wait_status
)
4491 /* Send interrupt_sequence to remote target. */
4492 send_interrupt_sequence ();
4495 /* This is the generic stop called via the target vector. When a target
4496 interrupt is requested, either by the command line or the GUI, we
4497 will eventually end up here. */
4500 remote_stop (ptid_t ptid
)
4503 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4506 remote_stop_ns (ptid
);
4508 remote_stop_as (ptid
);
4511 /* Ask the user what to do when an interrupt is received. */
4514 interrupt_query (void)
4516 target_terminal_ours ();
4518 if (target_can_async_p ())
4520 signal (SIGINT
, handle_sigint
);
4521 deprecated_throw_reason (RETURN_QUIT
);
4525 if (query (_("Interrupted while waiting for the program.\n\
4526 Give up (and stop debugging it)? ")))
4529 deprecated_throw_reason (RETURN_QUIT
);
4533 target_terminal_inferior ();
4536 /* Enable/disable target terminal ownership. Most targets can use
4537 terminal groups to control terminal ownership. Remote targets are
4538 different in that explicit transfer of ownership to/from GDB/target
4542 remote_terminal_inferior (void)
4544 if (!target_async_permitted
)
4545 /* Nothing to do. */
4548 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4549 idempotent. The event-loop GDB talking to an asynchronous target
4550 with a synchronous command calls this function from both
4551 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4552 transfer the terminal to the target when it shouldn't this guard
4554 if (!remote_async_terminal_ours_p
)
4556 delete_file_handler (input_fd
);
4557 remote_async_terminal_ours_p
= 0;
4558 initialize_sigint_signal_handler ();
4559 /* NOTE: At this point we could also register our selves as the
4560 recipient of all input. Any characters typed could then be
4561 passed on down to the target. */
4565 remote_terminal_ours (void)
4567 if (!target_async_permitted
)
4568 /* Nothing to do. */
4571 /* See FIXME in remote_terminal_inferior. */
4572 if (remote_async_terminal_ours_p
)
4574 cleanup_sigint_signal_handler (NULL
);
4575 add_file_handler (input_fd
, stdin_event_handler
, 0);
4576 remote_async_terminal_ours_p
= 1;
4580 remote_console_output (char *msg
)
4584 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4587 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4590 fputs_unfiltered (tb
, gdb_stdtarg
);
4592 gdb_flush (gdb_stdtarg
);
4595 typedef struct cached_reg
4598 gdb_byte data
[MAX_REGISTER_SIZE
];
4601 DEF_VEC_O(cached_reg_t
);
4605 struct stop_reply
*next
;
4609 struct target_waitstatus ws
;
4611 VEC(cached_reg_t
) *regcache
;
4613 int stopped_by_watchpoint_p
;
4614 CORE_ADDR watch_data_address
;
4622 /* The list of already fetched and acknowledged stop events. */
4623 static struct stop_reply
*stop_reply_queue
;
4625 static struct stop_reply
*
4626 stop_reply_xmalloc (void)
4628 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4634 stop_reply_xfree (struct stop_reply
*r
)
4638 VEC_free (cached_reg_t
, r
->regcache
);
4643 /* Discard all pending stop replies of inferior PID. If PID is -1,
4644 discard everything. */
4647 discard_pending_stop_replies (int pid
)
4649 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4651 /* Discard the in-flight notification. */
4652 if (pending_stop_reply
!= NULL
4654 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4656 stop_reply_xfree (pending_stop_reply
);
4657 pending_stop_reply
= NULL
;
4660 /* Discard the stop replies we have already pulled with
4662 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4666 || ptid_get_pid (reply
->ptid
) == pid
)
4668 if (reply
== stop_reply_queue
)
4669 stop_reply_queue
= reply
->next
;
4671 prev
->next
= reply
->next
;
4673 stop_reply_xfree (reply
);
4680 /* Cleanup wrapper. */
4683 do_stop_reply_xfree (void *arg
)
4685 struct stop_reply
*r
= arg
;
4686 stop_reply_xfree (r
);
4689 /* Look for a queued stop reply belonging to PTID. If one is found,
4690 remove it from the queue, and return it. Returns NULL if none is
4691 found. If there are still queued events left to process, tell the
4692 event loop to get back to target_wait soon. */
4694 static struct stop_reply
*
4695 queued_stop_reply (ptid_t ptid
)
4697 struct stop_reply
*it
;
4698 struct stop_reply
**it_link
;
4700 it
= stop_reply_queue
;
4701 it_link
= &stop_reply_queue
;
4704 if (ptid_match (it
->ptid
, ptid
))
4706 *it_link
= it
->next
;
4711 it_link
= &it
->next
;
4715 if (stop_reply_queue
)
4716 /* There's still at least an event left. */
4717 mark_async_event_handler (remote_async_inferior_event_token
);
4722 /* Push a fully parsed stop reply in the stop reply queue. Since we
4723 know that we now have at least one queued event left to pass to the
4724 core side, tell the event loop to get back to target_wait soon. */
4727 push_stop_reply (struct stop_reply
*new_event
)
4729 struct stop_reply
*event
;
4731 if (stop_reply_queue
)
4733 for (event
= stop_reply_queue
;
4734 event
&& event
->next
;
4735 event
= event
->next
)
4738 event
->next
= new_event
;
4741 stop_reply_queue
= new_event
;
4743 mark_async_event_handler (remote_async_inferior_event_token
);
4746 /* Returns true if we have a stop reply for PTID. */
4749 peek_stop_reply (ptid_t ptid
)
4751 struct stop_reply
*it
;
4753 for (it
= stop_reply_queue
; it
; it
= it
->next
)
4754 if (ptid_equal (ptid
, it
->ptid
))
4756 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
4763 /* Parse the stop reply in BUF. Either the function succeeds, and the
4764 result is stored in EVENT, or throws an error. */
4767 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
4769 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4773 event
->ptid
= null_ptid
;
4774 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
4775 event
->ws
.value
.integer
= 0;
4776 event
->solibs_changed
= 0;
4777 event
->replay_event
= 0;
4778 event
->stopped_by_watchpoint_p
= 0;
4779 event
->regcache
= NULL
;
4784 case 'T': /* Status with PC, SP, FP, ... */
4785 /* Expedited reply, containing Signal, {regno, reg} repeat. */
4786 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
4788 n... = register number
4789 r... = register contents
4792 p
= &buf
[3]; /* after Txx */
4800 /* If the packet contains a register number, save it in
4801 pnum and set p1 to point to the character following it.
4802 Otherwise p1 points to p. */
4804 /* If this packet is an awatch packet, don't parse the 'a'
4805 as a register number. */
4807 if (strncmp (p
, "awatch", strlen("awatch")) != 0
4808 && strncmp (p
, "core", strlen ("core") != 0))
4810 /* Read the ``P'' register number. */
4811 pnum
= strtol (p
, &p_temp
, 16);
4817 if (p1
== p
) /* No register number present here. */
4819 p1
= strchr (p
, ':');
4821 error (_("Malformed packet(a) (missing colon): %s\n\
4824 if (strncmp (p
, "thread", p1
- p
) == 0)
4825 event
->ptid
= read_ptid (++p1
, &p
);
4826 else if ((strncmp (p
, "watch", p1
- p
) == 0)
4827 || (strncmp (p
, "rwatch", p1
- p
) == 0)
4828 || (strncmp (p
, "awatch", p1
- p
) == 0))
4830 event
->stopped_by_watchpoint_p
= 1;
4831 p
= unpack_varlen_hex (++p1
, &addr
);
4832 event
->watch_data_address
= (CORE_ADDR
) addr
;
4834 else if (strncmp (p
, "library", p1
- p
) == 0)
4838 while (*p_temp
&& *p_temp
!= ';')
4841 event
->solibs_changed
= 1;
4844 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
4846 /* NO_HISTORY event.
4847 p1 will indicate "begin" or "end", but
4848 it makes no difference for now, so ignore it. */
4849 event
->replay_event
= 1;
4850 p_temp
= strchr (p1
+ 1, ';');
4854 else if (strncmp (p
, "core", p1
- p
) == 0)
4857 p
= unpack_varlen_hex (++p1
, &c
);
4862 /* Silently skip unknown optional info. */
4863 p_temp
= strchr (p1
+ 1, ';');
4870 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
4871 cached_reg_t cached_reg
;
4876 error (_("Malformed packet(b) (missing colon): %s\n\
4882 error (_("Remote sent bad register number %s: %s\n\
4884 hex_string (pnum
), p
, buf
);
4886 cached_reg
.num
= reg
->regnum
;
4888 fieldsize
= hex2bin (p
, cached_reg
.data
,
4889 register_size (target_gdbarch
,
4892 if (fieldsize
< register_size (target_gdbarch
,
4894 warning (_("Remote reply is too short: %s"), buf
);
4896 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
4900 error (_("Remote register badly formatted: %s\nhere: %s"),
4905 case 'S': /* Old style status, just signal only. */
4906 if (event
->solibs_changed
)
4907 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
4908 else if (event
->replay_event
)
4909 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
4912 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4913 event
->ws
.value
.sig
= (enum target_signal
)
4914 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
4917 case 'W': /* Target exited. */
4924 /* GDB used to accept only 2 hex chars here. Stubs should
4925 only send more if they detect GDB supports multi-process
4927 p
= unpack_varlen_hex (&buf
[1], &value
);
4931 /* The remote process exited. */
4932 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
4933 event
->ws
.value
.integer
= value
;
4937 /* The remote process exited with a signal. */
4938 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
4939 event
->ws
.value
.sig
= (enum target_signal
) value
;
4942 /* If no process is specified, assume inferior_ptid. */
4943 pid
= ptid_get_pid (inferior_ptid
);
4952 else if (strncmp (p
,
4953 "process:", sizeof ("process:") - 1) == 0)
4956 p
+= sizeof ("process:") - 1;
4957 unpack_varlen_hex (p
, &upid
);
4961 error (_("unknown stop reply packet: %s"), buf
);
4964 error (_("unknown stop reply packet: %s"), buf
);
4965 event
->ptid
= pid_to_ptid (pid
);
4970 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
4971 error (_("No process or thread specified in stop reply: %s"), buf
);
4974 /* When the stub wants to tell GDB about a new stop reply, it sends a
4975 stop notification (%Stop). Those can come it at any time, hence,
4976 we have to make sure that any pending putpkt/getpkt sequence we're
4977 making is finished, before querying the stub for more events with
4978 vStopped. E.g., if we started a vStopped sequence immediatelly
4979 upon receiving the %Stop notification, something like this could
4987 1.6) <-- (registers reply to step #1.3)
4989 Obviously, the reply in step #1.6 would be unexpected to a vStopped
4992 To solve this, whenever we parse a %Stop notification sucessfully,
4993 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
4994 doing whatever we were doing:
5000 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5001 2.5) <-- (registers reply to step #2.3)
5003 Eventualy after step #2.5, we return to the event loop, which
5004 notices there's an event on the
5005 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5006 associated callback --- the function below. At this point, we're
5007 always safe to start a vStopped sequence. :
5010 2.7) <-- T05 thread:2
5016 remote_get_pending_stop_replies (void)
5018 struct remote_state
*rs
= get_remote_state ();
5020 if (pending_stop_reply
)
5023 putpkt ("vStopped");
5025 /* Now we can rely on it. */
5026 push_stop_reply (pending_stop_reply
);
5027 pending_stop_reply
= NULL
;
5031 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5032 if (strcmp (rs
->buf
, "OK") == 0)
5036 struct cleanup
*old_chain
;
5037 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5039 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5040 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5043 putpkt ("vStopped");
5045 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5047 /* Now we can rely on it. */
5048 discard_cleanups (old_chain
);
5049 push_stop_reply (stop_reply
);
5052 /* We got an unknown stop reply. */
5053 do_cleanups (old_chain
);
5060 /* Called when it is decided that STOP_REPLY holds the info of the
5061 event that is to be returned to the core. This function always
5062 destroys STOP_REPLY. */
5065 process_stop_reply (struct stop_reply
*stop_reply
,
5066 struct target_waitstatus
*status
)
5069 struct thread_info
*info
;
5071 *status
= stop_reply
->ws
;
5072 ptid
= stop_reply
->ptid
;
5074 /* If no thread/process was reported by the stub, assume the current
5076 if (ptid_equal (ptid
, null_ptid
))
5077 ptid
= inferior_ptid
;
5079 if (status
->kind
!= TARGET_WAITKIND_EXITED
5080 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5082 /* Expedited registers. */
5083 if (stop_reply
->regcache
)
5085 struct regcache
*regcache
5086 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5091 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5093 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5094 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5097 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5098 remote_watch_data_address
= stop_reply
->watch_data_address
;
5100 remote_notice_new_inferior (ptid
, 0);
5101 demand_private_info (ptid
)->core
= stop_reply
->core
;
5104 stop_reply_xfree (stop_reply
);
5108 /* The non-stop mode version of target_wait. */
5111 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5113 struct remote_state
*rs
= get_remote_state ();
5114 struct stop_reply
*stop_reply
;
5117 /* If in non-stop mode, get out of getpkt even if a
5118 notification is received. */
5120 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5127 case 'E': /* Error of some sort. */
5128 /* We're out of sync with the target now. Did it continue
5129 or not? We can't tell which thread it was in non-stop,
5130 so just ignore this. */
5131 warning (_("Remote failure reply: %s"), rs
->buf
);
5133 case 'O': /* Console output. */
5134 remote_console_output (rs
->buf
+ 1);
5137 warning (_("Invalid remote reply: %s"), rs
->buf
);
5141 /* Acknowledge a pending stop reply that may have arrived in the
5143 if (pending_stop_reply
!= NULL
)
5144 remote_get_pending_stop_replies ();
5146 /* If indeed we noticed a stop reply, we're done. */
5147 stop_reply
= queued_stop_reply (ptid
);
5148 if (stop_reply
!= NULL
)
5149 return process_stop_reply (stop_reply
, status
);
5151 /* Still no event. If we're just polling for an event, then
5152 return to the event loop. */
5153 if (options
& TARGET_WNOHANG
)
5155 status
->kind
= TARGET_WAITKIND_IGNORE
;
5156 return minus_one_ptid
;
5159 /* Otherwise do a blocking wait. */
5160 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5165 /* Wait until the remote machine stops, then return, storing status in
5166 STATUS just as `wait' would. */
5169 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5171 struct remote_state
*rs
= get_remote_state ();
5172 ptid_t event_ptid
= null_ptid
;
5174 struct stop_reply
*stop_reply
;
5178 status
->kind
= TARGET_WAITKIND_IGNORE
;
5179 status
->value
.integer
= 0;
5181 stop_reply
= queued_stop_reply (ptid
);
5182 if (stop_reply
!= NULL
)
5183 return process_stop_reply (stop_reply
, status
);
5185 if (rs
->cached_wait_status
)
5186 /* Use the cached wait status, but only once. */
5187 rs
->cached_wait_status
= 0;
5192 if (!target_is_async_p ())
5194 ofunc
= signal (SIGINT
, remote_interrupt
);
5195 /* If the user hit C-c before this packet, or between packets,
5196 pretend that it was hit right here. */
5200 remote_interrupt (SIGINT
);
5204 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5205 _never_ wait for ever -> test on target_is_async_p().
5206 However, before we do that we need to ensure that the caller
5207 knows how to take the target into/out of async mode. */
5208 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5209 if (!target_is_async_p ())
5210 signal (SIGINT
, ofunc
);
5215 remote_stopped_by_watchpoint_p
= 0;
5217 /* We got something. */
5218 rs
->waiting_for_stop_reply
= 0;
5220 /* Assume that the target has acknowledged Ctrl-C unless we receive
5221 an 'F' or 'O' packet. */
5222 if (buf
[0] != 'F' && buf
[0] != 'O')
5223 rs
->ctrlc_pending_p
= 0;
5227 case 'E': /* Error of some sort. */
5228 /* We're out of sync with the target now. Did it continue or
5229 not? Not is more likely, so report a stop. */
5230 warning (_("Remote failure reply: %s"), buf
);
5231 status
->kind
= TARGET_WAITKIND_STOPPED
;
5232 status
->value
.sig
= TARGET_SIGNAL_0
;
5234 case 'F': /* File-I/O request. */
5235 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5236 rs
->ctrlc_pending_p
= 0;
5238 case 'T': case 'S': case 'X': case 'W':
5240 struct stop_reply
*stop_reply
;
5241 struct cleanup
*old_chain
;
5243 stop_reply
= stop_reply_xmalloc ();
5244 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5245 remote_parse_stop_reply (buf
, stop_reply
);
5246 discard_cleanups (old_chain
);
5247 event_ptid
= process_stop_reply (stop_reply
, status
);
5250 case 'O': /* Console output. */
5251 remote_console_output (buf
+ 1);
5253 /* The target didn't really stop; keep waiting. */
5254 rs
->waiting_for_stop_reply
= 1;
5258 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5260 /* Zero length reply means that we tried 'S' or 'C' and the
5261 remote system doesn't support it. */
5262 target_terminal_ours_for_output ();
5264 ("Can't send signals to this remote system. %s not sent.\n",
5265 target_signal_to_name (last_sent_signal
));
5266 last_sent_signal
= TARGET_SIGNAL_0
;
5267 target_terminal_inferior ();
5269 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5270 putpkt ((char *) buf
);
5272 /* We just told the target to resume, so a stop reply is in
5274 rs
->waiting_for_stop_reply
= 1;
5277 /* else fallthrough */
5279 warning (_("Invalid remote reply: %s"), buf
);
5281 rs
->waiting_for_stop_reply
= 1;
5285 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5287 /* Nothing interesting happened. If we're doing a non-blocking
5288 poll, we're done. Otherwise, go back to waiting. */
5289 if (options
& TARGET_WNOHANG
)
5290 return minus_one_ptid
;
5294 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5295 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5297 if (!ptid_equal (event_ptid
, null_ptid
))
5298 record_currthread (event_ptid
);
5300 event_ptid
= inferior_ptid
;
5303 /* A process exit. Invalidate our notion of current thread. */
5304 record_currthread (minus_one_ptid
);
5309 /* Wait until the remote machine stops, then return, storing status in
5310 STATUS just as `wait' would. */
5313 remote_wait (struct target_ops
*ops
,
5314 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5319 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5321 event_ptid
= remote_wait_as (ptid
, status
, options
);
5323 if (target_can_async_p ())
5325 /* If there are are events left in the queue tell the event loop
5327 if (stop_reply_queue
)
5328 mark_async_event_handler (remote_async_inferior_event_token
);
5334 /* Fetch a single register using a 'p' packet. */
5337 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5339 struct remote_state
*rs
= get_remote_state ();
5341 char regp
[MAX_REGISTER_SIZE
];
5344 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5347 if (reg
->pnum
== -1)
5352 p
+= hexnumstr (p
, reg
->pnum
);
5355 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5359 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5363 case PACKET_UNKNOWN
:
5366 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5367 gdbarch_register_name (get_regcache_arch (regcache
),
5372 /* If this register is unfetchable, tell the regcache. */
5375 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5379 /* Otherwise, parse and supply the value. */
5385 error (_("fetch_register_using_p: early buf termination"));
5387 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5390 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5394 /* Fetch the registers included in the target's 'g' packet. */
5397 send_g_packet (void)
5399 struct remote_state
*rs
= get_remote_state ();
5402 sprintf (rs
->buf
, "g");
5403 remote_send (&rs
->buf
, &rs
->buf_size
);
5405 /* We can get out of synch in various cases. If the first character
5406 in the buffer is not a hex character, assume that has happened
5407 and try to fetch another packet to read. */
5408 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5409 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5410 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5411 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5414 fprintf_unfiltered (gdb_stdlog
,
5415 "Bad register packet; fetching a new packet\n");
5416 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5419 buf_len
= strlen (rs
->buf
);
5421 /* Sanity check the received packet. */
5422 if (buf_len
% 2 != 0)
5423 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5429 process_g_packet (struct regcache
*regcache
)
5431 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5432 struct remote_state
*rs
= get_remote_state ();
5433 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5438 buf_len
= strlen (rs
->buf
);
5440 /* Further sanity checks, with knowledge of the architecture. */
5441 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5442 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5444 /* Save the size of the packet sent to us by the target. It is used
5445 as a heuristic when determining the max size of packets that the
5446 target can safely receive. */
5447 if (rsa
->actual_register_packet_size
== 0)
5448 rsa
->actual_register_packet_size
= buf_len
;
5450 /* If this is smaller than we guessed the 'g' packet would be,
5451 update our records. A 'g' reply that doesn't include a register's
5452 value implies either that the register is not available, or that
5453 the 'p' packet must be used. */
5454 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5456 rsa
->sizeof_g_packet
= buf_len
/ 2;
5458 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5460 if (rsa
->regs
[i
].pnum
== -1)
5463 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5464 rsa
->regs
[i
].in_g_packet
= 0;
5466 rsa
->regs
[i
].in_g_packet
= 1;
5470 regs
= alloca (rsa
->sizeof_g_packet
);
5472 /* Unimplemented registers read as all bits zero. */
5473 memset (regs
, 0, rsa
->sizeof_g_packet
);
5475 /* Reply describes registers byte by byte, each byte encoded as two
5476 hex characters. Suck them all up, then supply them to the
5477 register cacheing/storage mechanism. */
5480 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5482 if (p
[0] == 0 || p
[1] == 0)
5483 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5484 internal_error (__FILE__
, __LINE__
,
5485 "unexpected end of 'g' packet reply");
5487 if (p
[0] == 'x' && p
[1] == 'x')
5488 regs
[i
] = 0; /* 'x' */
5490 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5496 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5498 struct packet_reg
*r
= &rsa
->regs
[i
];
5501 if (r
->offset
* 2 >= strlen (rs
->buf
))
5502 /* This shouldn't happen - we adjusted in_g_packet above. */
5503 internal_error (__FILE__
, __LINE__
,
5504 "unexpected end of 'g' packet reply");
5505 else if (rs
->buf
[r
->offset
* 2] == 'x')
5507 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5508 /* The register isn't available, mark it as such (at
5509 the same time setting the value to zero). */
5510 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5513 regcache_raw_supply (regcache
, r
->regnum
,
5521 fetch_registers_using_g (struct regcache
*regcache
)
5524 process_g_packet (regcache
);
5528 remote_fetch_registers (struct target_ops
*ops
,
5529 struct regcache
*regcache
, int regnum
)
5531 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5534 set_general_thread (inferior_ptid
);
5538 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5539 gdb_assert (reg
!= NULL
);
5541 /* If this register might be in the 'g' packet, try that first -
5542 we are likely to read more than one register. If this is the
5543 first 'g' packet, we might be overly optimistic about its
5544 contents, so fall back to 'p'. */
5545 if (reg
->in_g_packet
)
5547 fetch_registers_using_g (regcache
);
5548 if (reg
->in_g_packet
)
5552 if (fetch_register_using_p (regcache
, reg
))
5555 /* This register is not available. */
5556 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5561 fetch_registers_using_g (regcache
);
5563 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5564 if (!rsa
->regs
[i
].in_g_packet
)
5565 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5567 /* This register is not available. */
5568 regcache_raw_supply (regcache
, i
, NULL
);
5572 /* Prepare to store registers. Since we may send them all (using a
5573 'G' request), we have to read out the ones we don't want to change
5577 remote_prepare_to_store (struct regcache
*regcache
)
5579 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5581 gdb_byte buf
[MAX_REGISTER_SIZE
];
5583 /* Make sure the entire registers array is valid. */
5584 switch (remote_protocol_packets
[PACKET_P
].support
)
5586 case PACKET_DISABLE
:
5587 case PACKET_SUPPORT_UNKNOWN
:
5588 /* Make sure all the necessary registers are cached. */
5589 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5590 if (rsa
->regs
[i
].in_g_packet
)
5591 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5598 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5599 packet was not recognized. */
5602 store_register_using_P (const struct regcache
*regcache
,
5603 struct packet_reg
*reg
)
5605 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5606 struct remote_state
*rs
= get_remote_state ();
5607 /* Try storing a single register. */
5608 char *buf
= rs
->buf
;
5609 gdb_byte regp
[MAX_REGISTER_SIZE
];
5612 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5615 if (reg
->pnum
== -1)
5618 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5619 p
= buf
+ strlen (buf
);
5620 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5621 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5623 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5625 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5630 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5631 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5632 case PACKET_UNKNOWN
:
5635 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5639 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5640 contents of the register cache buffer. FIXME: ignores errors. */
5643 store_registers_using_G (const struct regcache
*regcache
)
5645 struct remote_state
*rs
= get_remote_state ();
5646 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5650 /* Extract all the registers in the regcache copying them into a
5654 regs
= alloca (rsa
->sizeof_g_packet
);
5655 memset (regs
, 0, rsa
->sizeof_g_packet
);
5656 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5658 struct packet_reg
*r
= &rsa
->regs
[i
];
5660 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5664 /* Command describes registers byte by byte,
5665 each byte encoded as two hex characters. */
5668 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5670 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5672 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5673 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5674 error (_("Could not write registers; remote failure reply '%s'"),
5678 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
5679 of the register cache buffer. FIXME: ignores errors. */
5682 remote_store_registers (struct target_ops
*ops
,
5683 struct regcache
*regcache
, int regnum
)
5685 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5688 set_general_thread (inferior_ptid
);
5692 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5693 gdb_assert (reg
!= NULL
);
5695 /* Always prefer to store registers using the 'P' packet if
5696 possible; we often change only a small number of registers.
5697 Sometimes we change a larger number; we'd need help from a
5698 higher layer to know to use 'G'. */
5699 if (store_register_using_P (regcache
, reg
))
5702 /* For now, don't complain if we have no way to write the
5703 register. GDB loses track of unavailable registers too
5704 easily. Some day, this may be an error. We don't have
5705 any way to read the register, either... */
5706 if (!reg
->in_g_packet
)
5709 store_registers_using_G (regcache
);
5713 store_registers_using_G (regcache
);
5715 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5716 if (!rsa
->regs
[i
].in_g_packet
)
5717 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
5718 /* See above for why we do not issue an error here. */
5723 /* Return the number of hex digits in num. */
5726 hexnumlen (ULONGEST num
)
5730 for (i
= 0; num
!= 0; i
++)
5736 /* Set BUF to the minimum number of hex digits representing NUM. */
5739 hexnumstr (char *buf
, ULONGEST num
)
5741 int len
= hexnumlen (num
);
5742 return hexnumnstr (buf
, num
, len
);
5746 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
5749 hexnumnstr (char *buf
, ULONGEST num
, int width
)
5755 for (i
= width
- 1; i
>= 0; i
--)
5757 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
5764 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
5767 remote_address_masked (CORE_ADDR addr
)
5769 int address_size
= remote_address_size
;
5770 /* If "remoteaddresssize" was not set, default to target address size. */
5772 address_size
= gdbarch_addr_bit (target_gdbarch
);
5774 if (address_size
> 0
5775 && address_size
< (sizeof (ULONGEST
) * 8))
5777 /* Only create a mask when that mask can safely be constructed
5778 in a ULONGEST variable. */
5780 mask
= (mask
<< address_size
) - 1;
5786 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
5787 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
5788 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
5789 (which may be more than *OUT_LEN due to escape characters). The
5790 total number of bytes in the output buffer will be at most
5794 remote_escape_output (const gdb_byte
*buffer
, int len
,
5795 gdb_byte
*out_buf
, int *out_len
,
5798 int input_index
, output_index
;
5801 for (input_index
= 0; input_index
< len
; input_index
++)
5803 gdb_byte b
= buffer
[input_index
];
5805 if (b
== '$' || b
== '#' || b
== '}')
5807 /* These must be escaped. */
5808 if (output_index
+ 2 > out_maxlen
)
5810 out_buf
[output_index
++] = '}';
5811 out_buf
[output_index
++] = b
^ 0x20;
5815 if (output_index
+ 1 > out_maxlen
)
5817 out_buf
[output_index
++] = b
;
5821 *out_len
= input_index
;
5822 return output_index
;
5825 /* Convert BUFFER, escaped data LEN bytes long, into binary data
5826 in OUT_BUF. Return the number of bytes written to OUT_BUF.
5827 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
5829 This function reverses remote_escape_output. It allows more
5830 escaped characters than that function does, in particular because
5831 '*' must be escaped to avoid the run-length encoding processing
5832 in reading packets. */
5835 remote_unescape_input (const gdb_byte
*buffer
, int len
,
5836 gdb_byte
*out_buf
, int out_maxlen
)
5838 int input_index
, output_index
;
5843 for (input_index
= 0; input_index
< len
; input_index
++)
5845 gdb_byte b
= buffer
[input_index
];
5847 if (output_index
+ 1 > out_maxlen
)
5849 warning (_("Received too much data from remote target;"
5850 " ignoring overflow."));
5851 return output_index
;
5856 out_buf
[output_index
++] = b
^ 0x20;
5862 out_buf
[output_index
++] = b
;
5866 error (_("Unmatched escape character in target response."));
5868 return output_index
;
5871 /* Determine whether the remote target supports binary downloading.
5872 This is accomplished by sending a no-op memory write of zero length
5873 to the target at the specified address. It does not suffice to send
5874 the whole packet, since many stubs strip the eighth bit and
5875 subsequently compute a wrong checksum, which causes real havoc with
5878 NOTE: This can still lose if the serial line is not eight-bit
5879 clean. In cases like this, the user should clear "remote
5883 check_binary_download (CORE_ADDR addr
)
5885 struct remote_state
*rs
= get_remote_state ();
5887 switch (remote_protocol_packets
[PACKET_X
].support
)
5889 case PACKET_DISABLE
:
5893 case PACKET_SUPPORT_UNKNOWN
:
5899 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5901 p
+= hexnumstr (p
, (ULONGEST
) 0);
5905 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5906 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5908 if (rs
->buf
[0] == '\0')
5911 fprintf_unfiltered (gdb_stdlog
,
5912 "binary downloading NOT suppported by target\n");
5913 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
5918 fprintf_unfiltered (gdb_stdlog
,
5919 "binary downloading suppported by target\n");
5920 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
5927 /* Write memory data directly to the remote machine.
5928 This does not inform the data cache; the data cache uses this.
5929 HEADER is the starting part of the packet.
5930 MEMADDR is the address in the remote memory space.
5931 MYADDR is the address of the buffer in our space.
5932 LEN is the number of bytes.
5933 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
5934 should send data as binary ('X'), or hex-encoded ('M').
5936 The function creates packet of the form
5937 <HEADER><ADDRESS>,<LENGTH>:<DATA>
5939 where encoding of <DATA> is termined by PACKET_FORMAT.
5941 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
5944 Returns the number of bytes transferred, or 0 (setting errno) for
5945 error. Only transfer a single packet. */
5948 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
5949 const gdb_byte
*myaddr
, int len
,
5950 char packet_format
, int use_length
)
5952 struct remote_state
*rs
= get_remote_state ();
5962 if (packet_format
!= 'X' && packet_format
!= 'M')
5963 internal_error (__FILE__
, __LINE__
,
5964 "remote_write_bytes_aux: bad packet format");
5969 payload_size
= get_memory_write_packet_size ();
5971 /* The packet buffer will be large enough for the payload;
5972 get_memory_packet_size ensures this. */
5975 /* Compute the size of the actual payload by subtracting out the
5976 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
5978 payload_size
-= strlen ("$,:#NN");
5980 /* The comma won't be used. */
5982 header_length
= strlen (header
);
5983 payload_size
-= header_length
;
5984 payload_size
-= hexnumlen (memaddr
);
5986 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
5988 strcat (rs
->buf
, header
);
5989 p
= rs
->buf
+ strlen (header
);
5991 /* Compute a best guess of the number of bytes actually transfered. */
5992 if (packet_format
== 'X')
5994 /* Best guess at number of bytes that will fit. */
5995 todo
= min (len
, payload_size
);
5997 payload_size
-= hexnumlen (todo
);
5998 todo
= min (todo
, payload_size
);
6002 /* Num bytes that will fit. */
6003 todo
= min (len
, payload_size
/ 2);
6005 payload_size
-= hexnumlen (todo
);
6006 todo
= min (todo
, payload_size
/ 2);
6010 internal_error (__FILE__
, __LINE__
,
6011 _("minumum packet size too small to write data"));
6013 /* If we already need another packet, then try to align the end
6014 of this packet to a useful boundary. */
6015 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6016 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6018 /* Append "<memaddr>". */
6019 memaddr
= remote_address_masked (memaddr
);
6020 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6027 /* Append <len>. Retain the location/size of <len>. It may need to
6028 be adjusted once the packet body has been created. */
6030 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6038 /* Append the packet body. */
6039 if (packet_format
== 'X')
6041 /* Binary mode. Send target system values byte by byte, in
6042 increasing byte addresses. Only escape certain critical
6044 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6047 /* If not all TODO bytes fit, then we'll need another packet. Make
6048 a second try to keep the end of the packet aligned. Don't do
6049 this if the packet is tiny. */
6050 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6054 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6056 if (new_nr_bytes
!= nr_bytes
)
6057 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6062 p
+= payload_length
;
6063 if (use_length
&& nr_bytes
< todo
)
6065 /* Escape chars have filled up the buffer prematurely,
6066 and we have actually sent fewer bytes than planned.
6067 Fix-up the length field of the packet. Use the same
6068 number of characters as before. */
6069 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6070 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6075 /* Normal mode: Send target system values byte by byte, in
6076 increasing byte addresses. Each byte is encoded as a two hex
6078 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6082 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6083 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6085 if (rs
->buf
[0] == 'E')
6087 /* There is no correspondance between what the remote protocol
6088 uses for errors and errno codes. We would like a cleaner way
6089 of representing errors (big enough to include errno codes,
6090 bfd_error codes, and others). But for now just return EIO. */
6095 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6096 fewer bytes than we'd planned. */
6100 /* Write memory data directly to the remote machine.
6101 This does not inform the data cache; the data cache uses this.
6102 MEMADDR is the address in the remote memory space.
6103 MYADDR is the address of the buffer in our space.
6104 LEN is the number of bytes.
6106 Returns number of bytes transferred, or 0 (setting errno) for
6107 error. Only transfer a single packet. */
6110 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6112 char *packet_format
= 0;
6114 /* Check whether the target supports binary download. */
6115 check_binary_download (memaddr
);
6117 switch (remote_protocol_packets
[PACKET_X
].support
)
6120 packet_format
= "X";
6122 case PACKET_DISABLE
:
6123 packet_format
= "M";
6125 case PACKET_SUPPORT_UNKNOWN
:
6126 internal_error (__FILE__
, __LINE__
,
6127 _("remote_write_bytes: bad internal state"));
6129 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6132 return remote_write_bytes_aux (packet_format
,
6133 memaddr
, myaddr
, len
, packet_format
[0], 1);
6136 /* Read memory data directly from the remote machine.
6137 This does not use the data cache; the data cache uses this.
6138 MEMADDR is the address in the remote memory space.
6139 MYADDR is the address of the buffer in our space.
6140 LEN is the number of bytes.
6142 Returns number of bytes transferred, or 0 for error. */
6144 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
6145 remote targets) shouldn't attempt to read the entire buffer.
6146 Instead it should read a single packet worth of data and then
6147 return the byte size of that packet to the caller. The caller (its
6148 caller and its callers caller ;-) already contains code for
6149 handling partial reads. */
6152 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6154 struct remote_state
*rs
= get_remote_state ();
6155 int max_buf_size
; /* Max size of packet output buffer. */
6161 max_buf_size
= get_memory_read_packet_size ();
6162 /* The packet buffer will be large enough for the payload;
6163 get_memory_packet_size ensures this. */
6172 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
6174 /* construct "m"<memaddr>","<len>" */
6175 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
6176 memaddr
= remote_address_masked (memaddr
);
6179 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6181 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6187 if (rs
->buf
[0] == 'E'
6188 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6189 && rs
->buf
[3] == '\0')
6191 /* There is no correspondance between what the remote
6192 protocol uses for errors and errno codes. We would like
6193 a cleaner way of representing errors (big enough to
6194 include errno codes, bfd_error codes, and others). But
6195 for now just return EIO. */
6200 /* Reply describes memory byte by byte,
6201 each byte encoded as two hex characters. */
6204 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
6206 /* Reply is short. This means that we were able to read
6207 only part of what we wanted to. */
6208 return i
+ (origlen
- len
);
6218 /* Remote notification handler. */
6221 handle_notification (char *buf
, size_t length
)
6223 if (strncmp (buf
, "Stop:", 5) == 0)
6225 if (pending_stop_reply
)
6227 /* We've already parsed the in-flight stop-reply, but the
6228 stub for some reason thought we didn't, possibly due to
6229 timeout on its side. Just ignore it. */
6231 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6235 struct cleanup
*old_chain
;
6236 struct stop_reply
*reply
= stop_reply_xmalloc ();
6237 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6239 remote_parse_stop_reply (buf
+ 5, reply
);
6241 discard_cleanups (old_chain
);
6243 /* Be careful to only set it after parsing, since an error
6244 may be thrown then. */
6245 pending_stop_reply
= reply
;
6247 /* Notify the event loop there's a stop reply to acknowledge
6248 and that there may be more events to fetch. */
6249 mark_async_event_handler (remote_async_get_pending_events_token
);
6252 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6256 /* We ignore notifications we don't recognize, for compatibility
6257 with newer stubs. */
6262 /* Read or write LEN bytes from inferior memory at MEMADDR,
6263 transferring to or from debugger address BUFFER. Write to inferior
6264 if SHOULD_WRITE is nonzero. Returns length of data written or
6265 read; 0 for error. TARGET is unused. */
6268 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6269 int should_write
, struct mem_attrib
*attrib
,
6270 struct target_ops
*target
)
6274 set_general_thread (inferior_ptid
);
6277 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6279 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6284 /* Sends a packet with content determined by the printf format string
6285 FORMAT and the remaining arguments, then gets the reply. Returns
6286 whether the packet was a success, a failure, or unknown. */
6288 static enum packet_result
6289 remote_send_printf (const char *format
, ...)
6291 struct remote_state
*rs
= get_remote_state ();
6292 int max_size
= get_remote_packet_size ();
6295 va_start (ap
, format
);
6298 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6299 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
6301 if (putpkt (rs
->buf
) < 0)
6302 error (_("Communication problem with target."));
6305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6307 return packet_check_result (rs
->buf
);
6311 restore_remote_timeout (void *p
)
6313 int value
= *(int *)p
;
6314 remote_timeout
= value
;
6317 /* Flash writing can take quite some time. We'll set
6318 effectively infinite timeout for flash operations.
6319 In future, we'll need to decide on a better approach. */
6320 static const int remote_flash_timeout
= 1000;
6323 remote_flash_erase (struct target_ops
*ops
,
6324 ULONGEST address
, LONGEST length
)
6326 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6327 int saved_remote_timeout
= remote_timeout
;
6328 enum packet_result ret
;
6330 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6331 &saved_remote_timeout
);
6332 remote_timeout
= remote_flash_timeout
;
6334 ret
= remote_send_printf ("vFlashErase:%s,%s",
6335 phex (address
, addr_size
),
6339 case PACKET_UNKNOWN
:
6340 error (_("Remote target does not support flash erase"));
6342 error (_("Error erasing flash with vFlashErase packet"));
6347 do_cleanups (back_to
);
6351 remote_flash_write (struct target_ops
*ops
,
6352 ULONGEST address
, LONGEST length
,
6353 const gdb_byte
*data
)
6355 int saved_remote_timeout
= remote_timeout
;
6357 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6358 &saved_remote_timeout
);
6360 remote_timeout
= remote_flash_timeout
;
6361 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6362 do_cleanups (back_to
);
6368 remote_flash_done (struct target_ops
*ops
)
6370 int saved_remote_timeout
= remote_timeout
;
6372 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6373 &saved_remote_timeout
);
6375 remote_timeout
= remote_flash_timeout
;
6376 ret
= remote_send_printf ("vFlashDone");
6377 do_cleanups (back_to
);
6381 case PACKET_UNKNOWN
:
6382 error (_("Remote target does not support vFlashDone"));
6384 error (_("Error finishing flash operation"));
6391 remote_files_info (struct target_ops
*ignore
)
6393 puts_filtered ("Debugging a target over a serial line.\n");
6396 /* Stuff for dealing with the packets which are part of this protocol.
6397 See comment at top of file for details. */
6399 /* Read a single character from the remote end. */
6402 readchar (int timeout
)
6406 ch
= serial_readchar (remote_desc
, timeout
);
6411 switch ((enum serial_rc
) ch
)
6415 error (_("Remote connection closed"));
6418 perror_with_name (_("Remote communication error"));
6420 case SERIAL_TIMEOUT
:
6426 /* Send the command in *BUF to the remote machine, and read the reply
6427 into *BUF. Report an error if we get an error reply. Resize
6428 *BUF using xrealloc if necessary to hold the result, and update
6432 remote_send (char **buf
,
6436 getpkt (buf
, sizeof_buf
, 0);
6438 if ((*buf
)[0] == 'E')
6439 error (_("Remote failure reply: %s"), *buf
);
6442 /* Return a pointer to an xmalloc'ed string representing an escaped
6443 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6444 etc. The caller is responsible for releasing the returned
6448 escape_buffer (const char *buf
, int n
)
6450 struct cleanup
*old_chain
;
6451 struct ui_file
*stb
;
6454 stb
= mem_fileopen ();
6455 old_chain
= make_cleanup_ui_file_delete (stb
);
6457 fputstrn_unfiltered (buf
, n
, 0, stb
);
6458 str
= ui_file_xstrdup (stb
, NULL
);
6459 do_cleanups (old_chain
);
6463 /* Display a null-terminated packet on stdout, for debugging, using C
6467 print_packet (char *buf
)
6469 puts_filtered ("\"");
6470 fputstr_filtered (buf
, '"', gdb_stdout
);
6471 puts_filtered ("\"");
6477 return putpkt_binary (buf
, strlen (buf
));
6480 /* Send a packet to the remote machine, with error checking. The data
6481 of the packet is in BUF. The string in BUF can be at most
6482 get_remote_packet_size () - 5 to account for the $, # and checksum,
6483 and for a possible /0 if we are debugging (remote_debug) and want
6484 to print the sent packet as a string. */
6487 putpkt_binary (char *buf
, int cnt
)
6489 struct remote_state
*rs
= get_remote_state ();
6491 unsigned char csum
= 0;
6492 char *buf2
= alloca (cnt
+ 6);
6498 /* Catch cases like trying to read memory or listing threads while
6499 we're waiting for a stop reply. The remote server wouldn't be
6500 ready to handle this request, so we'd hang and timeout. We don't
6501 have to worry about this in synchronous mode, because in that
6502 case it's not possible to issue a command while the target is
6503 running. This is not a problem in non-stop mode, because in that
6504 case, the stub is always ready to process serial input. */
6505 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6506 error (_("Cannot execute this command while the target is running."));
6508 /* We're sending out a new packet. Make sure we don't look at a
6509 stale cached response. */
6510 rs
->cached_wait_status
= 0;
6512 /* Copy the packet into buffer BUF2, encapsulating it
6513 and giving it a checksum. */
6518 for (i
= 0; i
< cnt
; i
++)
6524 *p
++ = tohex ((csum
>> 4) & 0xf);
6525 *p
++ = tohex (csum
& 0xf);
6527 /* Send it over and over until we get a positive ack. */
6531 int started_error_output
= 0;
6535 struct cleanup
*old_chain
;
6539 str
= escape_buffer (buf2
, p
- buf2
);
6540 old_chain
= make_cleanup (xfree
, str
);
6541 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6542 gdb_flush (gdb_stdlog
);
6543 do_cleanups (old_chain
);
6545 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6546 perror_with_name (_("putpkt: write failed"));
6548 /* If this is a no acks version of the remote protocol, send the
6549 packet and move on. */
6553 /* Read until either a timeout occurs (-2) or '+' is read.
6554 Handle any notification that arrives in the mean time. */
6557 ch
= readchar (remote_timeout
);
6565 case SERIAL_TIMEOUT
:
6568 if (started_error_output
)
6570 putchar_unfiltered ('\n');
6571 started_error_output
= 0;
6580 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6584 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6585 case SERIAL_TIMEOUT
:
6589 break; /* Retransmit buffer. */
6593 fprintf_unfiltered (gdb_stdlog
,
6594 "Packet instead of Ack, ignoring it\n");
6595 /* It's probably an old response sent because an ACK
6596 was lost. Gobble up the packet and ack it so it
6597 doesn't get retransmitted when we resend this
6600 serial_write (remote_desc
, "+", 1);
6601 continue; /* Now, go look for +. */
6608 /* If we got a notification, handle it, and go back to looking
6610 /* We've found the start of a notification. Now
6611 collect the data. */
6612 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6617 struct cleanup
*old_chain
;
6620 str
= escape_buffer (rs
->buf
, val
);
6621 old_chain
= make_cleanup (xfree
, str
);
6622 fprintf_unfiltered (gdb_stdlog
,
6623 " Notification received: %s\n",
6625 do_cleanups (old_chain
);
6627 handle_notification (rs
->buf
, val
);
6628 /* We're in sync now, rewait for the ack. */
6635 if (!started_error_output
)
6637 started_error_output
= 1;
6638 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6640 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6641 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6650 if (!started_error_output
)
6652 started_error_output
= 1;
6653 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6655 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6659 break; /* Here to retransmit. */
6663 /* This is wrong. If doing a long backtrace, the user should be
6664 able to get out next time we call QUIT, without anything as
6665 violent as interrupt_query. If we want to provide a way out of
6666 here without getting to the next QUIT, it should be based on
6667 hitting ^C twice as in remote_wait. */
6678 /* Come here after finding the start of a frame when we expected an
6679 ack. Do our best to discard the rest of this packet. */
6688 c
= readchar (remote_timeout
);
6691 case SERIAL_TIMEOUT
:
6692 /* Nothing we can do. */
6695 /* Discard the two bytes of checksum and stop. */
6696 c
= readchar (remote_timeout
);
6698 c
= readchar (remote_timeout
);
6701 case '*': /* Run length encoding. */
6702 /* Discard the repeat count. */
6703 c
= readchar (remote_timeout
);
6708 /* A regular character. */
6714 /* Come here after finding the start of the frame. Collect the rest
6715 into *BUF, verifying the checksum, length, and handling run-length
6716 compression. NUL terminate the buffer. If there is not enough room,
6717 expand *BUF using xrealloc.
6719 Returns -1 on error, number of characters in buffer (ignoring the
6720 trailing NULL) on success. (could be extended to return one of the
6721 SERIAL status indications). */
6724 read_frame (char **buf_p
,
6731 struct remote_state
*rs
= get_remote_state ();
6738 c
= readchar (remote_timeout
);
6741 case SERIAL_TIMEOUT
:
6743 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
6747 fputs_filtered ("Saw new packet start in middle of old one\n",
6749 return -1; /* Start a new packet, count retries. */
6752 unsigned char pktcsum
;
6758 check_0
= readchar (remote_timeout
);
6760 check_1
= readchar (remote_timeout
);
6762 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
6765 fputs_filtered ("Timeout in checksum, retrying\n",
6769 else if (check_0
< 0 || check_1
< 0)
6772 fputs_filtered ("Communication error in checksum\n",
6777 /* Don't recompute the checksum; with no ack packets we
6778 don't have any way to indicate a packet retransmission
6783 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
6784 if (csum
== pktcsum
)
6789 struct cleanup
*old_chain
;
6792 str
= escape_buffer (buf
, bc
);
6793 old_chain
= make_cleanup (xfree
, str
);
6794 fprintf_unfiltered (gdb_stdlog
,
6796 Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
6797 pktcsum
, csum
, str
);
6798 do_cleanups (old_chain
);
6800 /* Number of characters in buffer ignoring trailing
6804 case '*': /* Run length encoding. */
6809 c
= readchar (remote_timeout
);
6811 repeat
= c
- ' ' + 3; /* Compute repeat count. */
6813 /* The character before ``*'' is repeated. */
6815 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
6817 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
6819 /* Make some more room in the buffer. */
6820 *sizeof_buf
+= repeat
;
6821 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6825 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
6831 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
6835 if (bc
>= *sizeof_buf
- 1)
6837 /* Make some more room in the buffer. */
6839 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6850 /* Read a packet from the remote machine, with error checking, and
6851 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6852 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6853 rather than timing out; this is used (in synchronous mode) to wait
6854 for a target that is is executing user code to stop. */
6855 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
6856 don't have to change all the calls to getpkt to deal with the
6857 return value, because at the moment I don't know what the right
6858 thing to do it for those. */
6866 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
6870 /* Read a packet from the remote machine, with error checking, and
6871 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6872 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6873 rather than timing out; this is used (in synchronous mode) to wait
6874 for a target that is is executing user code to stop. If FOREVER ==
6875 0, this function is allowed to time out gracefully and return an
6876 indication of this to the caller. Otherwise return the number of
6877 bytes read. If EXPECTING_NOTIF, consider receiving a notification
6878 enough reason to return to the caller. */
6881 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
6882 int expecting_notif
)
6884 struct remote_state
*rs
= get_remote_state ();
6890 /* We're reading a new response. Make sure we don't look at a
6891 previously cached response. */
6892 rs
->cached_wait_status
= 0;
6894 strcpy (*buf
, "timeout");
6897 timeout
= watchdog
> 0 ? watchdog
: -1;
6898 else if (expecting_notif
)
6899 timeout
= 0; /* There should already be a char in the buffer. If
6902 timeout
= remote_timeout
;
6906 /* Process any number of notifications, and then return when
6910 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
6912 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
6914 /* This can loop forever if the remote side sends us
6915 characters continuously, but if it pauses, we'll get
6916 SERIAL_TIMEOUT from readchar because of timeout. Then
6917 we'll count that as a retry.
6919 Note that even when forever is set, we will only wait
6920 forever prior to the start of a packet. After that, we
6921 expect characters to arrive at a brisk pace. They should
6922 show up within remote_timeout intervals. */
6924 c
= readchar (timeout
);
6925 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
6927 if (c
== SERIAL_TIMEOUT
)
6929 if (expecting_notif
)
6930 return -1; /* Don't complain, it's normal to not get
6931 anything in this case. */
6933 if (forever
) /* Watchdog went off? Kill the target. */
6937 error (_("Watchdog timeout has expired. Target detached."));
6940 fputs_filtered ("Timed out.\n", gdb_stdlog
);
6944 /* We've found the start of a packet or notification.
6945 Now collect the data. */
6946 val
= read_frame (buf
, sizeof_buf
);
6951 serial_write (remote_desc
, "-", 1);
6954 if (tries
> MAX_TRIES
)
6956 /* We have tried hard enough, and just can't receive the
6957 packet/notification. Give up. */
6958 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
6960 /* Skip the ack char if we're in no-ack mode. */
6961 if (!rs
->noack_mode
)
6962 serial_write (remote_desc
, "+", 1);
6966 /* If we got an ordinary packet, return that to our caller. */
6971 struct cleanup
*old_chain
;
6974 str
= escape_buffer (*buf
, val
);
6975 old_chain
= make_cleanup (xfree
, str
);
6976 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
6977 do_cleanups (old_chain
);
6980 /* Skip the ack char if we're in no-ack mode. */
6981 if (!rs
->noack_mode
)
6982 serial_write (remote_desc
, "+", 1);
6986 /* If we got a notification, handle it, and go back to looking
6990 gdb_assert (c
== '%');
6994 struct cleanup
*old_chain
;
6997 str
= escape_buffer (*buf
, val
);
6998 old_chain
= make_cleanup (xfree
, str
);
6999 fprintf_unfiltered (gdb_stdlog
,
7000 " Notification received: %s\n",
7002 do_cleanups (old_chain
);
7005 handle_notification (*buf
, val
);
7007 /* Notifications require no acknowledgement. */
7009 if (expecting_notif
)
7016 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7018 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7022 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7024 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7029 remote_kill (struct target_ops
*ops
)
7031 /* Use catch_errors so the user can quit from gdb even when we
7032 aren't on speaking terms with the remote system. */
7033 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
7035 /* Don't wait for it to die. I'm not really sure it matters whether
7036 we do or not. For the existing stubs, kill is a noop. */
7037 target_mourn_inferior ();
7041 remote_vkill (int pid
, struct remote_state
*rs
)
7043 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7046 /* Tell the remote target to detach. */
7047 sprintf (rs
->buf
, "vKill;%x", pid
);
7049 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7051 if (packet_ok (rs
->buf
,
7052 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7054 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7061 extended_remote_kill (struct target_ops
*ops
)
7064 int pid
= ptid_get_pid (inferior_ptid
);
7065 struct remote_state
*rs
= get_remote_state ();
7067 res
= remote_vkill (pid
, rs
);
7068 if (res
== -1 && !remote_multi_process_p (rs
))
7070 /* Don't try 'k' on a multi-process aware stub -- it has no way
7071 to specify the pid. */
7075 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7076 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7079 /* Don't wait for it to die. I'm not really sure it matters whether
7080 we do or not. For the existing stubs, kill is a noop. */
7086 error (_("Can't kill process"));
7088 target_mourn_inferior ();
7092 remote_mourn (struct target_ops
*ops
)
7094 remote_mourn_1 (ops
);
7097 /* Worker function for remote_mourn. */
7099 remote_mourn_1 (struct target_ops
*target
)
7101 unpush_target (target
);
7103 /* remote_close takes care of doing most of the clean up. */
7104 generic_mourn_inferior ();
7108 extended_remote_mourn_1 (struct target_ops
*target
)
7110 struct remote_state
*rs
= get_remote_state ();
7112 /* In case we got here due to an error, but we're going to stay
7114 rs
->waiting_for_stop_reply
= 0;
7116 /* We're no longer interested in these events. */
7117 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7119 /* If the current general thread belonged to the process we just
7120 detached from or has exited, the remote side current general
7121 thread becomes undefined. Considering a case like this:
7123 - We just got here due to a detach.
7124 - The process that we're detaching from happens to immediately
7125 report a global breakpoint being hit in non-stop mode, in the
7126 same thread we had selected before.
7127 - GDB attaches to this process again.
7128 - This event happens to be the next event we handle.
7130 GDB would consider that the current general thread didn't need to
7131 be set on the stub side (with Hg), since for all it knew,
7132 GENERAL_THREAD hadn't changed.
7134 Notice that although in all-stop mode, the remote server always
7135 sets the current thread to the thread reporting the stop event,
7136 that doesn't happen in non-stop mode; in non-stop, the stub *must
7137 not* change the current thread when reporting a breakpoint hit,
7138 due to the decoupling of event reporting and event handling.
7140 To keep things simple, we always invalidate our notion of the
7142 record_currthread (minus_one_ptid
);
7144 /* Unlike "target remote", we do not want to unpush the target; then
7145 the next time the user says "run", we won't be connected. */
7147 /* Call common code to mark the inferior as not running. */
7148 generic_mourn_inferior ();
7150 if (!have_inferiors ())
7152 if (!remote_multi_process_p (rs
))
7154 /* Check whether the target is running now - some remote stubs
7155 automatically restart after kill. */
7157 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7159 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7161 /* Assume that the target has been restarted. Set inferior_ptid
7162 so that bits of core GDB realizes there's something here, e.g.,
7163 so that the user can say "kill" again. */
7164 inferior_ptid
= magic_null_ptid
;
7171 extended_remote_mourn (struct target_ops
*ops
)
7173 extended_remote_mourn_1 (ops
);
7177 extended_remote_run (char *args
)
7179 struct remote_state
*rs
= get_remote_state ();
7182 /* If the user has disabled vRun support, or we have detected that
7183 support is not available, do not try it. */
7184 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7187 strcpy (rs
->buf
, "vRun;");
7188 len
= strlen (rs
->buf
);
7190 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7191 error (_("Remote file name too long for run packet"));
7192 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7194 gdb_assert (args
!= NULL
);
7197 struct cleanup
*back_to
;
7201 argv
= gdb_buildargv (args
);
7202 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7203 for (i
= 0; argv
[i
] != NULL
; i
++)
7205 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7206 error (_("Argument list too long for run packet"));
7207 rs
->buf
[len
++] = ';';
7208 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7210 do_cleanups (back_to
);
7213 rs
->buf
[len
++] = '\0';
7216 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7218 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7220 /* We have a wait response; we don't need it, though. All is well. */
7223 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7224 /* It wasn't disabled before, but it is now. */
7228 if (remote_exec_file
[0] == '\0')
7229 error (_("Running the default executable on the remote target failed; "
7230 "try \"set remote exec-file\"?"));
7232 error (_("Running \"%s\" on the remote target failed"),
7237 /* In the extended protocol we want to be able to do things like
7238 "run" and have them basically work as expected. So we need
7239 a special create_inferior function. We support changing the
7240 executable file and the command line arguments, but not the
7244 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7245 char **env
, int from_tty
)
7247 /* If running asynchronously, register the target file descriptor
7248 with the event loop. */
7249 if (target_can_async_p ())
7250 target_async (inferior_event_handler
, 0);
7252 /* Now restart the remote server. */
7253 if (extended_remote_run (args
) == -1)
7255 /* vRun was not supported. Fail if we need it to do what the
7257 if (remote_exec_file
[0])
7258 error (_("Remote target does not support \"set remote exec-file\""));
7260 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7262 /* Fall back to "R". */
7263 extended_remote_restart ();
7266 if (!have_inferiors ())
7268 /* Clean up from the last time we ran, before we mark the target
7269 running again. This will mark breakpoints uninserted, and
7270 get_offsets may insert breakpoints. */
7271 init_thread_list ();
7272 init_wait_for_inferior ();
7275 /* Now mark the inferior as running before we do anything else. */
7276 inferior_ptid
= magic_null_ptid
;
7278 /* Now, if we have thread information, update inferior_ptid. */
7279 inferior_ptid
= remote_current_thread (inferior_ptid
);
7281 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7282 add_thread_silent (inferior_ptid
);
7284 /* Get updated offsets, if the stub uses qOffsets. */
7289 extended_remote_create_inferior (struct target_ops
*ops
,
7290 char *exec_file
, char *args
,
7291 char **env
, int from_tty
)
7293 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7297 /* Insert a breakpoint. On targets that have software breakpoint
7298 support, we ask the remote target to do the work; on targets
7299 which don't, we insert a traditional memory breakpoint. */
7302 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7303 struct bp_target_info
*bp_tgt
)
7305 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7306 If it succeeds, then set the support to PACKET_ENABLE. If it
7307 fails, and the user has explicitly requested the Z support then
7308 report an error, otherwise, mark it disabled and go on. */
7310 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7312 CORE_ADDR addr
= bp_tgt
->placed_address
;
7313 struct remote_state
*rs
;
7317 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7319 rs
= get_remote_state ();
7325 addr
= (ULONGEST
) remote_address_masked (addr
);
7326 p
+= hexnumstr (p
, addr
);
7327 sprintf (p
, ",%d", bpsize
);
7330 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7332 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7337 bp_tgt
->placed_address
= addr
;
7338 bp_tgt
->placed_size
= bpsize
;
7340 case PACKET_UNKNOWN
:
7345 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7349 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7350 struct bp_target_info
*bp_tgt
)
7352 CORE_ADDR addr
= bp_tgt
->placed_address
;
7353 struct remote_state
*rs
= get_remote_state ();
7355 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7363 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7364 p
+= hexnumstr (p
, addr
);
7365 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7368 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7370 return (rs
->buf
[0] == 'E');
7373 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7377 watchpoint_to_Z_packet (int type
)
7382 return Z_PACKET_WRITE_WP
;
7385 return Z_PACKET_READ_WP
;
7388 return Z_PACKET_ACCESS_WP
;
7391 internal_error (__FILE__
, __LINE__
,
7392 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7397 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
7399 struct remote_state
*rs
= get_remote_state ();
7401 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7403 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7406 sprintf (rs
->buf
, "Z%x,", packet
);
7407 p
= strchr (rs
->buf
, '\0');
7408 addr
= remote_address_masked (addr
);
7409 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7410 sprintf (p
, ",%x", len
);
7413 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7415 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7419 case PACKET_UNKNOWN
:
7424 internal_error (__FILE__
, __LINE__
,
7425 _("remote_insert_watchpoint: reached end of function"));
7430 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
7432 struct remote_state
*rs
= get_remote_state ();
7434 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7436 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7439 sprintf (rs
->buf
, "z%x,", packet
);
7440 p
= strchr (rs
->buf
, '\0');
7441 addr
= remote_address_masked (addr
);
7442 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7443 sprintf (p
, ",%x", len
);
7445 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7447 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7450 case PACKET_UNKNOWN
:
7455 internal_error (__FILE__
, __LINE__
,
7456 _("remote_remove_watchpoint: reached end of function"));
7460 int remote_hw_watchpoint_limit
= -1;
7461 int remote_hw_breakpoint_limit
= -1;
7464 remote_check_watch_resources (int type
, int cnt
, int ot
)
7466 if (type
== bp_hardware_breakpoint
)
7468 if (remote_hw_breakpoint_limit
== 0)
7470 else if (remote_hw_breakpoint_limit
< 0)
7472 else if (cnt
<= remote_hw_breakpoint_limit
)
7477 if (remote_hw_watchpoint_limit
== 0)
7479 else if (remote_hw_watchpoint_limit
< 0)
7483 else if (cnt
<= remote_hw_watchpoint_limit
)
7490 remote_stopped_by_watchpoint (void)
7492 return remote_stopped_by_watchpoint_p
;
7496 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7499 if (remote_stopped_by_watchpoint ())
7501 *addr_p
= remote_watch_data_address
;
7510 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7511 struct bp_target_info
*bp_tgt
)
7514 struct remote_state
*rs
;
7517 /* The length field should be set to the size of a breakpoint
7518 instruction, even though we aren't inserting one ourselves. */
7520 gdbarch_remote_breakpoint_from_pc
7521 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7523 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7526 rs
= get_remote_state ();
7533 addr
= remote_address_masked (bp_tgt
->placed_address
);
7534 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7535 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7538 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7540 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7543 case PACKET_UNKNOWN
:
7548 internal_error (__FILE__
, __LINE__
,
7549 _("remote_insert_hw_breakpoint: reached end of function"));
7554 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7555 struct bp_target_info
*bp_tgt
)
7558 struct remote_state
*rs
= get_remote_state ();
7561 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7568 addr
= remote_address_masked (bp_tgt
->placed_address
);
7569 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7570 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7573 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7575 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7578 case PACKET_UNKNOWN
:
7583 internal_error (__FILE__
, __LINE__
,
7584 _("remote_remove_hw_breakpoint: reached end of function"));
7587 /* Table used by the crc32 function to calcuate the checksum. */
7589 static unsigned long crc32_table
[256] =
7592 static unsigned long
7593 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7595 if (!crc32_table
[1])
7597 /* Initialize the CRC table and the decoding table. */
7601 for (i
= 0; i
< 256; i
++)
7603 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7604 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7611 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7617 /* Verify memory using the "qCRC:" request. */
7620 remote_verify_memory (struct target_ops
*ops
,
7621 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
7623 struct remote_state
*rs
= get_remote_state ();
7624 unsigned long host_crc
, target_crc
;
7627 /* FIXME: assumes lma can fit into long. */
7628 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7629 (long) lma
, (long) size
);
7632 /* Be clever; compute the host_crc before waiting for target
7634 host_crc
= crc32 (data
, size
, 0xffffffff);
7636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7637 if (rs
->buf
[0] == 'E')
7640 if (rs
->buf
[0] != 'C')
7641 error (_("remote target does not support this operation"));
7643 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7644 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7646 return (host_crc
== target_crc
);
7649 /* compare-sections command
7651 With no arguments, compares each loadable section in the exec bfd
7652 with the same memory range on the target, and reports mismatches.
7653 Useful for verifying the image on the target against the exec file. */
7656 compare_sections_command (char *args
, int from_tty
)
7659 struct cleanup
*old_chain
;
7661 const char *sectname
;
7669 error (_("command cannot be used without an exec file"));
7671 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7673 if (!(s
->flags
& SEC_LOAD
))
7674 continue; /* skip non-loadable section */
7676 size
= bfd_get_section_size (s
);
7678 continue; /* skip zero-length section */
7680 sectname
= bfd_get_section_name (exec_bfd
, s
);
7681 if (args
&& strcmp (args
, sectname
) != 0)
7682 continue; /* not the section selected by user */
7684 matched
= 1; /* do this section */
7687 sectdata
= xmalloc (size
);
7688 old_chain
= make_cleanup (xfree
, sectdata
);
7689 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
7691 res
= target_verify_memory (sectdata
, lma
, size
);
7694 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
7695 paddress (target_gdbarch
, lma
),
7696 paddress (target_gdbarch
, lma
+ size
));
7698 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
7699 paddress (target_gdbarch
, lma
),
7700 paddress (target_gdbarch
, lma
+ size
));
7702 printf_filtered ("matched.\n");
7705 printf_filtered ("MIS-MATCHED!\n");
7709 do_cleanups (old_chain
);
7712 warning (_("One or more sections of the remote executable does not match\n\
7713 the loaded file\n"));
7714 if (args
&& !matched
)
7715 printf_filtered (_("No loaded section named '%s'.\n"), args
);
7718 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
7719 into remote target. The number of bytes written to the remote
7720 target is returned, or -1 for error. */
7723 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
7724 const char *annex
, const gdb_byte
*writebuf
,
7725 ULONGEST offset
, LONGEST len
,
7726 struct packet_config
*packet
)
7730 struct remote_state
*rs
= get_remote_state ();
7731 int max_size
= get_memory_write_packet_size ();
7733 if (packet
->support
== PACKET_DISABLE
)
7736 /* Insert header. */
7737 i
= snprintf (rs
->buf
, max_size
,
7738 "qXfer:%s:write:%s:%s:",
7739 object_name
, annex
? annex
: "",
7740 phex_nz (offset
, sizeof offset
));
7741 max_size
-= (i
+ 1);
7743 /* Escape as much data as fits into rs->buf. */
7744 buf_len
= remote_escape_output
7745 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
7747 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
7748 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7749 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7752 unpack_varlen_hex (rs
->buf
, &n
);
7756 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
7757 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
7758 number of bytes read is returned, or 0 for EOF, or -1 for error.
7759 The number of bytes read may be less than LEN without indicating an
7760 EOF. PACKET is checked and updated to indicate whether the remote
7761 target supports this object. */
7764 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
7766 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
7767 struct packet_config
*packet
)
7769 static char *finished_object
;
7770 static char *finished_annex
;
7771 static ULONGEST finished_offset
;
7773 struct remote_state
*rs
= get_remote_state ();
7774 LONGEST i
, n
, packet_len
;
7776 if (packet
->support
== PACKET_DISABLE
)
7779 /* Check whether we've cached an end-of-object packet that matches
7781 if (finished_object
)
7783 if (strcmp (object_name
, finished_object
) == 0
7784 && strcmp (annex
? annex
: "", finished_annex
) == 0
7785 && offset
== finished_offset
)
7788 /* Otherwise, we're now reading something different. Discard
7790 xfree (finished_object
);
7791 xfree (finished_annex
);
7792 finished_object
= NULL
;
7793 finished_annex
= NULL
;
7796 /* Request only enough to fit in a single packet. The actual data
7797 may not, since we don't know how much of it will need to be escaped;
7798 the target is free to respond with slightly less data. We subtract
7799 five to account for the response type and the protocol frame. */
7800 n
= min (get_remote_packet_size () - 5, len
);
7801 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
7802 object_name
, annex
? annex
: "",
7803 phex_nz (offset
, sizeof offset
),
7804 phex_nz (n
, sizeof n
));
7805 i
= putpkt (rs
->buf
);
7810 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
7811 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7814 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
7815 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
7817 /* 'm' means there is (or at least might be) more data after this
7818 batch. That does not make sense unless there's at least one byte
7819 of data in this reply. */
7820 if (rs
->buf
[0] == 'm' && packet_len
== 1)
7821 error (_("Remote qXfer reply contained no data."));
7823 /* Got some data. */
7824 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
7826 /* 'l' is an EOF marker, possibly including a final block of data,
7827 or possibly empty. If we have the final block of a non-empty
7828 object, record this fact to bypass a subsequent partial read. */
7829 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
7831 finished_object
= xstrdup (object_name
);
7832 finished_annex
= xstrdup (annex
? annex
: "");
7833 finished_offset
= offset
+ i
;
7840 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
7841 const char *annex
, gdb_byte
*readbuf
,
7842 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
7844 struct remote_state
*rs
;
7849 set_general_thread (inferior_ptid
);
7851 rs
= get_remote_state ();
7853 /* Handle memory using the standard memory routines. */
7854 if (object
== TARGET_OBJECT_MEMORY
)
7859 /* If the remote target is connected but not running, we should
7860 pass this request down to a lower stratum (e.g. the executable
7862 if (!target_has_execution
)
7865 if (writebuf
!= NULL
)
7866 xfered
= remote_write_bytes (offset
, writebuf
, len
);
7868 xfered
= remote_read_bytes (offset
, readbuf
, len
);
7872 else if (xfered
== 0 && errno
== 0)
7878 /* Handle SPU memory using qxfer packets. */
7879 if (object
== TARGET_OBJECT_SPU
)
7882 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
7883 &remote_protocol_packets
7884 [PACKET_qXfer_spu_read
]);
7886 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
7887 &remote_protocol_packets
7888 [PACKET_qXfer_spu_write
]);
7891 /* Handle extra signal info using qxfer packets. */
7892 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
7895 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
7896 &remote_protocol_packets
7897 [PACKET_qXfer_siginfo_read
]);
7899 return remote_write_qxfer (ops
, "siginfo", annex
, writebuf
, offset
, len
,
7900 &remote_protocol_packets
7901 [PACKET_qXfer_siginfo_write
]);
7904 /* Only handle flash writes. */
7905 if (writebuf
!= NULL
)
7911 case TARGET_OBJECT_FLASH
:
7912 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
7916 else if (xfered
== 0 && errno
== 0)
7926 /* Map pre-existing objects onto letters. DO NOT do this for new
7927 objects!!! Instead specify new query packets. */
7930 case TARGET_OBJECT_AVR
:
7934 case TARGET_OBJECT_AUXV
:
7935 gdb_assert (annex
== NULL
);
7936 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
7937 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
7939 case TARGET_OBJECT_AVAILABLE_FEATURES
:
7940 return remote_read_qxfer
7941 (ops
, "features", annex
, readbuf
, offset
, len
,
7942 &remote_protocol_packets
[PACKET_qXfer_features
]);
7944 case TARGET_OBJECT_LIBRARIES
:
7945 return remote_read_qxfer
7946 (ops
, "libraries", annex
, readbuf
, offset
, len
,
7947 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
7949 case TARGET_OBJECT_MEMORY_MAP
:
7950 gdb_assert (annex
== NULL
);
7951 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
7952 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
7954 case TARGET_OBJECT_OSDATA
:
7955 /* Should only get here if we're connected. */
7956 gdb_assert (remote_desc
);
7957 return remote_read_qxfer
7958 (ops
, "osdata", annex
, readbuf
, offset
, len
,
7959 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
7961 case TARGET_OBJECT_THREADS
:
7962 gdb_assert (annex
== NULL
);
7963 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
7964 &remote_protocol_packets
[PACKET_qXfer_threads
]);
7970 /* Note: a zero OFFSET and LEN can be used to query the minimum
7972 if (offset
== 0 && len
== 0)
7973 return (get_remote_packet_size ());
7974 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
7975 large enough let the caller deal with it. */
7976 if (len
< get_remote_packet_size ())
7978 len
= get_remote_packet_size ();
7980 /* Except for querying the minimum buffer size, target must be open. */
7982 error (_("remote query is only available after target open"));
7984 gdb_assert (annex
!= NULL
);
7985 gdb_assert (readbuf
!= NULL
);
7991 /* We used one buffer char for the remote protocol q command and
7992 another for the query type. As the remote protocol encapsulation
7993 uses 4 chars plus one extra in case we are debugging
7994 (remote_debug), we have PBUFZIZ - 7 left to pack the query
7997 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
7999 /* Bad caller may have sent forbidden characters. */
8000 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8005 gdb_assert (annex
[i
] == '\0');
8007 i
= putpkt (rs
->buf
);
8011 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8012 strcpy ((char *) readbuf
, rs
->buf
);
8014 return strlen ((char *) readbuf
);
8018 remote_search_memory (struct target_ops
* ops
,
8019 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8020 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8021 CORE_ADDR
*found_addrp
)
8023 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8024 struct remote_state
*rs
= get_remote_state ();
8025 int max_size
= get_memory_write_packet_size ();
8026 struct packet_config
*packet
=
8027 &remote_protocol_packets
[PACKET_qSearch_memory
];
8028 /* number of packet bytes used to encode the pattern,
8029 this could be more than PATTERN_LEN due to escape characters */
8030 int escaped_pattern_len
;
8031 /* amount of pattern that was encodable in the packet */
8032 int used_pattern_len
;
8035 ULONGEST found_addr
;
8037 /* Don't go to the target if we don't have to.
8038 This is done before checking packet->support to avoid the possibility that
8039 a success for this edge case means the facility works in general. */
8040 if (pattern_len
> search_space_len
)
8042 if (pattern_len
== 0)
8044 *found_addrp
= start_addr
;
8048 /* If we already know the packet isn't supported, fall back to the simple
8049 way of searching memory. */
8051 if (packet
->support
== PACKET_DISABLE
)
8053 /* Target doesn't provided special support, fall back and use the
8054 standard support (copy memory and do the search here). */
8055 return simple_search_memory (ops
, start_addr
, search_space_len
,
8056 pattern
, pattern_len
, found_addrp
);
8059 /* Insert header. */
8060 i
= snprintf (rs
->buf
, max_size
,
8061 "qSearch:memory:%s;%s;",
8062 phex_nz (start_addr
, addr_size
),
8063 phex_nz (search_space_len
, sizeof (search_space_len
)));
8064 max_size
-= (i
+ 1);
8066 /* Escape as much data as fits into rs->buf. */
8067 escaped_pattern_len
=
8068 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8069 &used_pattern_len
, max_size
);
8071 /* Bail if the pattern is too large. */
8072 if (used_pattern_len
!= pattern_len
)
8073 error ("Pattern is too large to transmit to remote target.");
8075 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8076 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8077 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8079 /* The request may not have worked because the command is not
8080 supported. If so, fall back to the simple way. */
8081 if (packet
->support
== PACKET_DISABLE
)
8083 return simple_search_memory (ops
, start_addr
, search_space_len
,
8084 pattern
, pattern_len
, found_addrp
);
8089 if (rs
->buf
[0] == '0')
8091 else if (rs
->buf
[0] == '1')
8094 if (rs
->buf
[1] != ',')
8095 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8096 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8097 *found_addrp
= found_addr
;
8100 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8106 remote_rcmd (char *command
,
8107 struct ui_file
*outbuf
)
8109 struct remote_state
*rs
= get_remote_state ();
8113 error (_("remote rcmd is only available after target open"));
8115 /* Send a NULL command across as an empty command. */
8116 if (command
== NULL
)
8119 /* The query prefix. */
8120 strcpy (rs
->buf
, "qRcmd,");
8121 p
= strchr (rs
->buf
, '\0');
8123 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
8124 error (_("\"monitor\" command ``%s'' is too long."), command
);
8126 /* Encode the actual command. */
8127 bin2hex ((gdb_byte
*) command
, p
, 0);
8129 if (putpkt (rs
->buf
) < 0)
8130 error (_("Communication problem with target."));
8132 /* get/display the response */
8137 /* XXX - see also remote_get_noisy_reply(). */
8139 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8142 error (_("Target does not support this command."));
8143 if (buf
[0] == 'O' && buf
[1] != 'K')
8145 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8148 if (strcmp (buf
, "OK") == 0)
8150 if (strlen (buf
) == 3 && buf
[0] == 'E'
8151 && isdigit (buf
[1]) && isdigit (buf
[2]))
8153 error (_("Protocol error with Rcmd"));
8155 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8157 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8158 fputc_unfiltered (c
, outbuf
);
8164 static VEC(mem_region_s
) *
8165 remote_memory_map (struct target_ops
*ops
)
8167 VEC(mem_region_s
) *result
= NULL
;
8168 char *text
= target_read_stralloc (¤t_target
,
8169 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8173 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8174 result
= parse_memory_map (text
);
8175 do_cleanups (back_to
);
8182 packet_command (char *args
, int from_tty
)
8184 struct remote_state
*rs
= get_remote_state ();
8187 error (_("command can only be used with remote target"));
8190 error (_("remote-packet command requires packet text as argument"));
8192 puts_filtered ("sending: ");
8193 print_packet (args
);
8194 puts_filtered ("\n");
8197 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8198 puts_filtered ("received: ");
8199 print_packet (rs
->buf
);
8200 puts_filtered ("\n");
8204 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8206 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8208 static void threadset_test_cmd (char *cmd
, int tty
);
8210 static void threadalive_test (char *cmd
, int tty
);
8212 static void threadlist_test_cmd (char *cmd
, int tty
);
8214 int get_and_display_threadinfo (threadref
*ref
);
8216 static void threadinfo_test_cmd (char *cmd
, int tty
);
8218 static int thread_display_step (threadref
*ref
, void *context
);
8220 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8222 static void init_remote_threadtests (void);
8224 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8227 threadset_test_cmd (char *cmd
, int tty
)
8229 int sample_thread
= SAMPLE_THREAD
;
8231 printf_filtered (_("Remote threadset test\n"));
8232 set_general_thread (sample_thread
);
8237 threadalive_test (char *cmd
, int tty
)
8239 int sample_thread
= SAMPLE_THREAD
;
8240 int pid
= ptid_get_pid (inferior_ptid
);
8241 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8243 if (remote_thread_alive (ptid
))
8244 printf_filtered ("PASS: Thread alive test\n");
8246 printf_filtered ("FAIL: Thread alive test\n");
8249 void output_threadid (char *title
, threadref
*ref
);
8252 output_threadid (char *title
, threadref
*ref
)
8256 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8258 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8262 threadlist_test_cmd (char *cmd
, int tty
)
8265 threadref nextthread
;
8266 int done
, result_count
;
8267 threadref threadlist
[3];
8269 printf_filtered ("Remote Threadlist test\n");
8270 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8271 &result_count
, &threadlist
[0]))
8272 printf_filtered ("FAIL: threadlist test\n");
8275 threadref
*scan
= threadlist
;
8276 threadref
*limit
= scan
+ result_count
;
8278 while (scan
< limit
)
8279 output_threadid (" thread ", scan
++);
8284 display_thread_info (struct gdb_ext_thread_info
*info
)
8286 output_threadid ("Threadid: ", &info
->threadid
);
8287 printf_filtered ("Name: %s\n ", info
->shortname
);
8288 printf_filtered ("State: %s\n", info
->display
);
8289 printf_filtered ("other: %s\n\n", info
->more_display
);
8293 get_and_display_threadinfo (threadref
*ref
)
8297 struct gdb_ext_thread_info threadinfo
;
8299 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8300 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8301 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8302 display_thread_info (&threadinfo
);
8307 threadinfo_test_cmd (char *cmd
, int tty
)
8309 int athread
= SAMPLE_THREAD
;
8313 int_to_threadref (&thread
, athread
);
8314 printf_filtered ("Remote Threadinfo test\n");
8315 if (!get_and_display_threadinfo (&thread
))
8316 printf_filtered ("FAIL cannot get thread info\n");
8320 thread_display_step (threadref
*ref
, void *context
)
8322 /* output_threadid(" threadstep ",ref); *//* simple test */
8323 return get_and_display_threadinfo (ref
);
8327 threadlist_update_test_cmd (char *cmd
, int tty
)
8329 printf_filtered ("Remote Threadlist update test\n");
8330 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8334 init_remote_threadtests (void)
8336 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
8337 Fetch and print the remote list of thread identifiers, one pkt only"));
8338 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8339 _("Fetch and display info about one thread"));
8340 add_com ("tset", class_obscure
, threadset_test_cmd
,
8341 _("Test setting to a different thread"));
8342 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8343 _("Iterate through updating all remote thread info"));
8344 add_com ("talive", class_obscure
, threadalive_test
,
8345 _(" Remote thread alive test "));
8350 /* Convert a thread ID to a string. Returns the string in a static
8354 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8356 static char buf
[64];
8357 struct remote_state
*rs
= get_remote_state ();
8359 if (ptid_is_pid (ptid
))
8361 /* Printing an inferior target id. */
8363 /* When multi-process extensions are off, there's no way in the
8364 remote protocol to know the remote process id, if there's any
8365 at all. There's one exception --- when we're connected with
8366 target extended-remote, and we manually attached to a process
8367 with "attach PID". We don't record anywhere a flag that
8368 allows us to distinguish that case from the case of
8369 connecting with extended-remote and the stub already being
8370 attached to a process, and reporting yes to qAttached, hence
8371 no smart special casing here. */
8372 if (!remote_multi_process_p (rs
))
8374 xsnprintf (buf
, sizeof buf
, "Remote target");
8378 return normal_pid_to_str (ptid
);
8382 if (ptid_equal (magic_null_ptid
, ptid
))
8383 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8384 else if (remote_multi_process_p (rs
))
8385 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8386 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8388 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8389 ptid_get_tid (ptid
));
8394 /* Get the address of the thread local variable in OBJFILE which is
8395 stored at OFFSET within the thread local storage for thread PTID. */
8398 remote_get_thread_local_address (struct target_ops
*ops
,
8399 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8401 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8403 struct remote_state
*rs
= get_remote_state ();
8405 char *endp
= rs
->buf
+ get_remote_packet_size ();
8406 enum packet_result result
;
8408 strcpy (p
, "qGetTLSAddr:");
8410 p
= write_ptid (p
, endp
, ptid
);
8412 p
+= hexnumstr (p
, offset
);
8414 p
+= hexnumstr (p
, lm
);
8418 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8419 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8420 if (result
== PACKET_OK
)
8424 unpack_varlen_hex (rs
->buf
, &result
);
8427 else if (result
== PACKET_UNKNOWN
)
8428 throw_error (TLS_GENERIC_ERROR
,
8429 _("Remote target doesn't support qGetTLSAddr packet"));
8431 throw_error (TLS_GENERIC_ERROR
,
8432 _("Remote target failed to process qGetTLSAddr request"));
8435 throw_error (TLS_GENERIC_ERROR
,
8436 _("TLS not supported or disabled on this target"));
8441 /* Provide thread local base, i.e. Thread Information Block address.
8442 Returns 1 if ptid is found and thread_local_base is non zero. */
8445 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8447 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8449 struct remote_state
*rs
= get_remote_state ();
8451 char *endp
= rs
->buf
+ get_remote_packet_size ();
8452 enum packet_result result
;
8454 strcpy (p
, "qGetTIBAddr:");
8456 p
= write_ptid (p
, endp
, ptid
);
8460 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8461 result
= packet_ok (rs
->buf
,
8462 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8463 if (result
== PACKET_OK
)
8467 unpack_varlen_hex (rs
->buf
, &result
);
8469 *addr
= (CORE_ADDR
) result
;
8472 else if (result
== PACKET_UNKNOWN
)
8473 error (_("Remote target doesn't support qGetTIBAddr packet"));
8475 error (_("Remote target failed to process qGetTIBAddr request"));
8478 error (_("qGetTIBAddr not supported or disabled on this target"));
8483 /* Support for inferring a target description based on the current
8484 architecture and the size of a 'g' packet. While the 'g' packet
8485 can have any size (since optional registers can be left off the
8486 end), some sizes are easily recognizable given knowledge of the
8487 approximate architecture. */
8489 struct remote_g_packet_guess
8492 const struct target_desc
*tdesc
;
8494 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8495 DEF_VEC_O(remote_g_packet_guess_s
);
8497 struct remote_g_packet_data
8499 VEC(remote_g_packet_guess_s
) *guesses
;
8502 static struct gdbarch_data
*remote_g_packet_data_handle
;
8505 remote_g_packet_data_init (struct obstack
*obstack
)
8507 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8511 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8512 const struct target_desc
*tdesc
)
8514 struct remote_g_packet_data
*data
8515 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8516 struct remote_g_packet_guess new_guess
, *guess
;
8519 gdb_assert (tdesc
!= NULL
);
8522 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8524 if (guess
->bytes
== bytes
)
8525 internal_error (__FILE__
, __LINE__
,
8526 "Duplicate g packet description added for size %d",
8529 new_guess
.bytes
= bytes
;
8530 new_guess
.tdesc
= tdesc
;
8531 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8534 /* Return 1 if remote_read_description would do anything on this target
8535 and architecture, 0 otherwise. */
8538 remote_read_description_p (struct target_ops
*target
)
8540 struct remote_g_packet_data
*data
8541 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8543 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8549 static const struct target_desc
*
8550 remote_read_description (struct target_ops
*target
)
8552 struct remote_g_packet_data
*data
8553 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8555 /* Do not try this during initial connection, when we do not know
8556 whether there is a running but stopped thread. */
8557 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8560 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8562 struct remote_g_packet_guess
*guess
;
8564 int bytes
= send_g_packet ();
8567 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8569 if (guess
->bytes
== bytes
)
8570 return guess
->tdesc
;
8572 /* We discard the g packet. A minor optimization would be to
8573 hold on to it, and fill the register cache once we have selected
8574 an architecture, but it's too tricky to do safely. */
8580 /* Remote file transfer support. This is host-initiated I/O, not
8581 target-initiated; for target-initiated, see remote-fileio.c. */
8583 /* If *LEFT is at least the length of STRING, copy STRING to
8584 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8585 decrease *LEFT. Otherwise raise an error. */
8588 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8590 int len
= strlen (string
);
8593 error (_("Packet too long for target."));
8595 memcpy (*buffer
, string
, len
);
8599 /* NUL-terminate the buffer as a convenience, if there is
8605 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8606 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8607 decrease *LEFT. Otherwise raise an error. */
8610 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8613 if (2 * len
> *left
)
8614 error (_("Packet too long for target."));
8616 bin2hex (bytes
, *buffer
, len
);
8620 /* NUL-terminate the buffer as a convenience, if there is
8626 /* If *LEFT is large enough, convert VALUE to hex and add it to
8627 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8628 decrease *LEFT. Otherwise raise an error. */
8631 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
8633 int len
= hexnumlen (value
);
8636 error (_("Packet too long for target."));
8638 hexnumstr (*buffer
, value
);
8642 /* NUL-terminate the buffer as a convenience, if there is
8648 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8649 value, *REMOTE_ERRNO to the remote error number or zero if none
8650 was included, and *ATTACHMENT to point to the start of the annex
8651 if any. The length of the packet isn't needed here; there may
8652 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8654 Return 0 if the packet could be parsed, -1 if it could not. If
8655 -1 is returned, the other variables may not be initialized. */
8658 remote_hostio_parse_result (char *buffer
, int *retcode
,
8659 int *remote_errno
, char **attachment
)
8666 if (buffer
[0] != 'F')
8670 *retcode
= strtol (&buffer
[1], &p
, 16);
8671 if (errno
!= 0 || p
== &buffer
[1])
8674 /* Check for ",errno". */
8678 *remote_errno
= strtol (p
+ 1, &p2
, 16);
8679 if (errno
!= 0 || p
+ 1 == p2
)
8684 /* Check for ";attachment". If there is no attachment, the
8685 packet should end here. */
8688 *attachment
= p
+ 1;
8691 else if (*p
== '\0')
8697 /* Send a prepared I/O packet to the target and read its response.
8698 The prepared packet is in the global RS->BUF before this function
8699 is called, and the answer is there when we return.
8701 COMMAND_BYTES is the length of the request to send, which may include
8702 binary data. WHICH_PACKET is the packet configuration to check
8703 before attempting a packet. If an error occurs, *REMOTE_ERRNO
8704 is set to the error number and -1 is returned. Otherwise the value
8705 returned by the function is returned.
8707 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
8708 attachment is expected; an error will be reported if there's a
8709 mismatch. If one is found, *ATTACHMENT will be set to point into
8710 the packet buffer and *ATTACHMENT_LEN will be set to the
8711 attachment's length. */
8714 remote_hostio_send_command (int command_bytes
, int which_packet
,
8715 int *remote_errno
, char **attachment
,
8716 int *attachment_len
)
8718 struct remote_state
*rs
= get_remote_state ();
8719 int ret
, bytes_read
;
8720 char *attachment_tmp
;
8723 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
8725 *remote_errno
= FILEIO_ENOSYS
;
8729 putpkt_binary (rs
->buf
, command_bytes
);
8730 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8732 /* If it timed out, something is wrong. Don't try to parse the
8736 *remote_errno
= FILEIO_EINVAL
;
8740 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
8743 *remote_errno
= FILEIO_EINVAL
;
8745 case PACKET_UNKNOWN
:
8746 *remote_errno
= FILEIO_ENOSYS
;
8752 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
8755 *remote_errno
= FILEIO_EINVAL
;
8759 /* Make sure we saw an attachment if and only if we expected one. */
8760 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
8761 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
8763 *remote_errno
= FILEIO_EINVAL
;
8767 /* If an attachment was found, it must point into the packet buffer;
8768 work out how many bytes there were. */
8769 if (attachment_tmp
!= NULL
)
8771 *attachment
= attachment_tmp
;
8772 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
8778 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
8779 remote file descriptor, or -1 if an error occurs (and set
8783 remote_hostio_open (const char *filename
, int flags
, int mode
,
8786 struct remote_state
*rs
= get_remote_state ();
8788 int left
= get_remote_packet_size () - 1;
8790 remote_buffer_add_string (&p
, &left
, "vFile:open:");
8792 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8794 remote_buffer_add_string (&p
, &left
, ",");
8796 remote_buffer_add_int (&p
, &left
, flags
);
8797 remote_buffer_add_string (&p
, &left
, ",");
8799 remote_buffer_add_int (&p
, &left
, mode
);
8801 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
8802 remote_errno
, NULL
, NULL
);
8805 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
8806 Return the number of bytes written, or -1 if an error occurs (and
8807 set *REMOTE_ERRNO). */
8810 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
8811 ULONGEST offset
, int *remote_errno
)
8813 struct remote_state
*rs
= get_remote_state ();
8815 int left
= get_remote_packet_size ();
8818 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
8820 remote_buffer_add_int (&p
, &left
, fd
);
8821 remote_buffer_add_string (&p
, &left
, ",");
8823 remote_buffer_add_int (&p
, &left
, offset
);
8824 remote_buffer_add_string (&p
, &left
, ",");
8826 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
8827 get_remote_packet_size () - (p
- rs
->buf
));
8829 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
8830 remote_errno
, NULL
, NULL
);
8833 /* Read up to LEN bytes FD on the remote target into READ_BUF
8834 Return the number of bytes read, or -1 if an error occurs (and
8835 set *REMOTE_ERRNO). */
8838 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
8839 ULONGEST offset
, int *remote_errno
)
8841 struct remote_state
*rs
= get_remote_state ();
8844 int left
= get_remote_packet_size ();
8845 int ret
, attachment_len
;
8848 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
8850 remote_buffer_add_int (&p
, &left
, fd
);
8851 remote_buffer_add_string (&p
, &left
, ",");
8853 remote_buffer_add_int (&p
, &left
, len
);
8854 remote_buffer_add_string (&p
, &left
, ",");
8856 remote_buffer_add_int (&p
, &left
, offset
);
8858 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
8859 remote_errno
, &attachment
,
8865 read_len
= remote_unescape_input (attachment
, attachment_len
,
8867 if (read_len
!= ret
)
8868 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
8873 /* Close FD on the remote target. Return 0, or -1 if an error occurs
8874 (and set *REMOTE_ERRNO). */
8877 remote_hostio_close (int fd
, int *remote_errno
)
8879 struct remote_state
*rs
= get_remote_state ();
8881 int left
= get_remote_packet_size () - 1;
8883 remote_buffer_add_string (&p
, &left
, "vFile:close:");
8885 remote_buffer_add_int (&p
, &left
, fd
);
8887 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
8888 remote_errno
, NULL
, NULL
);
8891 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
8892 occurs (and set *REMOTE_ERRNO). */
8895 remote_hostio_unlink (const char *filename
, int *remote_errno
)
8897 struct remote_state
*rs
= get_remote_state ();
8899 int left
= get_remote_packet_size () - 1;
8901 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
8903 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8906 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
8907 remote_errno
, NULL
, NULL
);
8911 remote_fileio_errno_to_host (int errnum
)
8935 case FILEIO_ENOTDIR
:
8955 case FILEIO_ENAMETOOLONG
:
8956 return ENAMETOOLONG
;
8962 remote_hostio_error (int errnum
)
8964 int host_error
= remote_fileio_errno_to_host (errnum
);
8966 if (host_error
== -1)
8967 error (_("Unknown remote I/O error %d"), errnum
);
8969 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
8973 remote_hostio_close_cleanup (void *opaque
)
8975 int fd
= *(int *) opaque
;
8978 remote_hostio_close (fd
, &remote_errno
);
8983 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
8985 const char *filename
= bfd_get_filename (abfd
);
8986 int fd
, remote_errno
;
8989 gdb_assert (remote_filename_p (filename
));
8991 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
8994 errno
= remote_fileio_errno_to_host (remote_errno
);
8995 bfd_set_error (bfd_error_system_call
);
8999 stream
= xmalloc (sizeof (int));
9005 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9007 int fd
= *(int *)stream
;
9012 /* Ignore errors on close; these may happen if the remote
9013 connection was already torn down. */
9014 remote_hostio_close (fd
, &remote_errno
);
9020 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9021 file_ptr nbytes
, file_ptr offset
)
9023 int fd
= *(int *)stream
;
9025 file_ptr pos
, bytes
;
9028 while (nbytes
> pos
)
9030 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9031 offset
+ pos
, &remote_errno
);
9033 /* Success, but no bytes, means end-of-file. */
9037 errno
= remote_fileio_errno_to_host (remote_errno
);
9038 bfd_set_error (bfd_error_system_call
);
9049 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9051 /* FIXME: We should probably implement remote_hostio_stat. */
9052 sb
->st_size
= INT_MAX
;
9057 remote_filename_p (const char *filename
)
9059 return strncmp (filename
, "remote:", 7) == 0;
9063 remote_bfd_open (const char *remote_file
, const char *target
)
9065 return bfd_openr_iovec (remote_file
, target
,
9066 remote_bfd_iovec_open
, NULL
,
9067 remote_bfd_iovec_pread
,
9068 remote_bfd_iovec_close
,
9069 remote_bfd_iovec_stat
);
9073 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9075 struct cleanup
*back_to
, *close_cleanup
;
9076 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9079 int bytes_in_buffer
;
9084 error (_("command can only be used with remote target"));
9086 file
= fopen (local_file
, "rb");
9088 perror_with_name (local_file
);
9089 back_to
= make_cleanup_fclose (file
);
9091 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9093 0700, &remote_errno
);
9095 remote_hostio_error (remote_errno
);
9097 /* Send up to this many bytes at once. They won't all fit in the
9098 remote packet limit, so we'll transfer slightly fewer. */
9099 io_size
= get_remote_packet_size ();
9100 buffer
= xmalloc (io_size
);
9101 make_cleanup (xfree
, buffer
);
9103 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9105 bytes_in_buffer
= 0;
9108 while (bytes_in_buffer
|| !saw_eof
)
9112 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
9117 error (_("Error reading %s."), local_file
);
9120 /* EOF. Unless there is something still in the
9121 buffer from the last iteration, we are done. */
9123 if (bytes_in_buffer
== 0)
9131 bytes
+= bytes_in_buffer
;
9132 bytes_in_buffer
= 0;
9134 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
9137 remote_hostio_error (remote_errno
);
9138 else if (retcode
== 0)
9139 error (_("Remote write of %d bytes returned 0!"), bytes
);
9140 else if (retcode
< bytes
)
9142 /* Short write. Save the rest of the read data for the next
9144 bytes_in_buffer
= bytes
- retcode
;
9145 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9151 discard_cleanups (close_cleanup
);
9152 if (remote_hostio_close (fd
, &remote_errno
))
9153 remote_hostio_error (remote_errno
);
9156 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9157 do_cleanups (back_to
);
9161 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9163 struct cleanup
*back_to
, *close_cleanup
;
9164 int fd
, remote_errno
, bytes
, io_size
;
9170 error (_("command can only be used with remote target"));
9172 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9174 remote_hostio_error (remote_errno
);
9176 file
= fopen (local_file
, "wb");
9178 perror_with_name (local_file
);
9179 back_to
= make_cleanup_fclose (file
);
9181 /* Send up to this many bytes at once. They won't all fit in the
9182 remote packet limit, so we'll transfer slightly fewer. */
9183 io_size
= get_remote_packet_size ();
9184 buffer
= xmalloc (io_size
);
9185 make_cleanup (xfree
, buffer
);
9187 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9192 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9194 /* Success, but no bytes, means end-of-file. */
9197 remote_hostio_error (remote_errno
);
9201 bytes
= fwrite (buffer
, 1, bytes
, file
);
9203 perror_with_name (local_file
);
9206 discard_cleanups (close_cleanup
);
9207 if (remote_hostio_close (fd
, &remote_errno
))
9208 remote_hostio_error (remote_errno
);
9211 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9212 do_cleanups (back_to
);
9216 remote_file_delete (const char *remote_file
, int from_tty
)
9218 int retcode
, remote_errno
;
9221 error (_("command can only be used with remote target"));
9223 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9225 remote_hostio_error (remote_errno
);
9228 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9232 remote_put_command (char *args
, int from_tty
)
9234 struct cleanup
*back_to
;
9238 error_no_arg (_("file to put"));
9240 argv
= gdb_buildargv (args
);
9241 back_to
= make_cleanup_freeargv (argv
);
9242 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9243 error (_("Invalid parameters to remote put"));
9245 remote_file_put (argv
[0], argv
[1], from_tty
);
9247 do_cleanups (back_to
);
9251 remote_get_command (char *args
, int from_tty
)
9253 struct cleanup
*back_to
;
9257 error_no_arg (_("file to get"));
9259 argv
= gdb_buildargv (args
);
9260 back_to
= make_cleanup_freeargv (argv
);
9261 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9262 error (_("Invalid parameters to remote get"));
9264 remote_file_get (argv
[0], argv
[1], from_tty
);
9266 do_cleanups (back_to
);
9270 remote_delete_command (char *args
, int from_tty
)
9272 struct cleanup
*back_to
;
9276 error_no_arg (_("file to delete"));
9278 argv
= gdb_buildargv (args
);
9279 back_to
= make_cleanup_freeargv (argv
);
9280 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9281 error (_("Invalid parameters to remote delete"));
9283 remote_file_delete (argv
[0], from_tty
);
9285 do_cleanups (back_to
);
9289 remote_command (char *args
, int from_tty
)
9291 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9295 remote_can_execute_reverse (void)
9297 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9298 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9305 remote_supports_non_stop (void)
9311 remote_supports_multi_process (void)
9313 struct remote_state
*rs
= get_remote_state ();
9314 return remote_multi_process_p (rs
);
9318 remote_supports_cond_tracepoints (void)
9320 struct remote_state
*rs
= get_remote_state ();
9321 return rs
->cond_tracepoints
;
9325 remote_supports_fast_tracepoints (void)
9327 struct remote_state
*rs
= get_remote_state ();
9328 return rs
->fast_tracepoints
;
9332 remote_trace_init (void)
9335 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9336 if (strcmp (target_buf
, "OK") != 0)
9337 error (_("Target does not support this command."));
9340 static void free_actions_list (char **actions_list
);
9341 static void free_actions_list_cleanup_wrapper (void *);
9343 free_actions_list_cleanup_wrapper (void *al
)
9345 free_actions_list (al
);
9349 free_actions_list (char **actions_list
)
9353 if (actions_list
== 0)
9356 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9357 xfree (actions_list
[ndx
]);
9359 xfree (actions_list
);
9362 /* Recursive routine to walk through command list including loops, and
9363 download packets for each command. */
9366 remote_download_command_source (int num
, ULONGEST addr
,
9367 struct command_line
*cmds
)
9369 struct remote_state
*rs
= get_remote_state ();
9370 struct command_line
*cmd
;
9372 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9374 QUIT
; /* allow user to bail out with ^C */
9375 strcpy (rs
->buf
, "QTDPsrc:");
9376 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9377 rs
->buf
+ strlen (rs
->buf
),
9378 rs
->buf_size
- strlen (rs
->buf
));
9380 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9381 if (strcmp (target_buf
, "OK"))
9382 warning (_("Target does not support source download."));
9384 if (cmd
->control_type
== while_control
9385 || cmd
->control_type
== while_stepping_control
)
9387 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9389 QUIT
; /* allow user to bail out with ^C */
9390 strcpy (rs
->buf
, "QTDPsrc:");
9391 encode_source_string (num
, addr
, "cmd", "end",
9392 rs
->buf
+ strlen (rs
->buf
),
9393 rs
->buf_size
- strlen (rs
->buf
));
9395 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9396 if (strcmp (target_buf
, "OK"))
9397 warning (_("Target does not support source download."));
9403 remote_download_tracepoint (struct breakpoint
*t
)
9405 struct bp_location
*loc
;
9410 char **stepping_actions
;
9412 struct cleanup
*old_chain
= NULL
;
9413 struct agent_expr
*aexpr
;
9414 struct cleanup
*aexpr_chain
= NULL
;
9417 /* Iterate over all the tracepoint locations. It's up to the target to
9418 notice multiple tracepoint packets with the same number but different
9419 addresses, and treat them as multiple locations. */
9420 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
9422 encode_actions (t
, loc
, &tdp_actions
, &stepping_actions
);
9423 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9425 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
9427 tpaddr
= loc
->address
;
9428 sprintf_vma (addrbuf
, tpaddr
);
9429 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
9430 addrbuf
, /* address */
9431 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
9432 t
->step_count
, t
->pass_count
);
9433 /* Fast tracepoints are mostly handled by the target, but we can
9434 tell the target how big of an instruction block should be moved
9436 if (t
->type
== bp_fast_tracepoint
)
9438 /* Only test for support at download time; we may not know
9439 target capabilities at definition time. */
9440 if (remote_supports_fast_tracepoints ())
9444 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9445 tpaddr
, &isize
, NULL
))
9446 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9448 /* If it passed validation at definition but fails now,
9449 something is very wrong. */
9450 internal_error (__FILE__
, __LINE__
,
9451 "Fast tracepoint not valid during download");
9454 /* Fast tracepoints are functionally identical to regular
9455 tracepoints, so don't take lack of support as a reason to
9456 give up on the trace run. */
9457 warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t
->number
);
9459 /* If the tracepoint has a conditional, make it into an agent
9460 expression and append to the definition. */
9463 /* Only test support at download time, we may not know target
9464 capabilities at definition time. */
9465 if (remote_supports_cond_tracepoints ())
9467 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9468 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9469 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9470 pkt
= buf
+ strlen (buf
);
9471 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9472 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9474 do_cleanups (aexpr_chain
);
9477 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
9480 if (t
->commands
|| *default_collect
)
9483 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9484 if (strcmp (target_buf
, "OK"))
9485 error (_("Target does not support tracepoints."));
9487 /* do_single_steps (t); */
9490 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9492 QUIT
; /* allow user to bail out with ^C */
9493 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9494 t
->number
, addrbuf
, /* address */
9496 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9499 remote_get_noisy_reply (&target_buf
,
9501 if (strcmp (target_buf
, "OK"))
9502 error (_("Error on target while setting tracepoints."));
9505 if (stepping_actions
)
9507 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9509 QUIT
; /* allow user to bail out with ^C */
9510 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9511 t
->number
, addrbuf
, /* address */
9512 ((ndx
== 0) ? "S" : ""),
9513 stepping_actions
[ndx
],
9514 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9516 remote_get_noisy_reply (&target_buf
,
9518 if (strcmp (target_buf
, "OK"))
9519 error (_("Error on target while setting tracepoints."));
9523 if (remote_protocol_packets
[PACKET_TracepointSource
].support
== PACKET_ENABLE
)
9527 strcpy (buf
, "QTDPsrc:");
9528 encode_source_string (t
->number
, loc
->address
,
9529 "at", t
->addr_string
, buf
+ strlen (buf
),
9530 2048 - strlen (buf
));
9533 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9534 if (strcmp (target_buf
, "OK"))
9535 warning (_("Target does not support source download."));
9539 strcpy (buf
, "QTDPsrc:");
9540 encode_source_string (t
->number
, loc
->address
,
9541 "cond", t
->cond_string
, buf
+ strlen (buf
),
9542 2048 - strlen (buf
));
9544 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9545 if (strcmp (target_buf
, "OK"))
9546 warning (_("Target does not support source download."));
9548 remote_download_command_source (t
->number
, loc
->address
,
9549 breakpoint_commands (t
));
9552 do_cleanups (old_chain
);
9557 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
9559 struct remote_state
*rs
= get_remote_state ();
9562 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
9563 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
9564 p
= rs
->buf
+ strlen (rs
->buf
);
9565 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
9566 error (_("Trace state variable name too long for tsv definition packet"));
9567 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
9570 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9571 if (*target_buf
== '\0')
9572 error (_("Target does not support this command."));
9573 if (strcmp (target_buf
, "OK") != 0)
9574 error (_("Error on target while downloading trace state variable."));
9578 remote_trace_set_readonly_regions (void)
9586 return; /* No information to give. */
9588 strcpy (target_buf
, "QTro");
9589 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9591 char tmp1
[40], tmp2
[40];
9593 if ((s
->flags
& SEC_LOAD
) == 0 ||
9594 /* (s->flags & SEC_CODE) == 0 || */
9595 (s
->flags
& SEC_READONLY
) == 0)
9600 size
= bfd_get_section_size (s
);
9601 sprintf_vma (tmp1
, lma
);
9602 sprintf_vma (tmp2
, lma
+ size
);
9603 sprintf (target_buf
+ strlen (target_buf
),
9604 ":%s,%s", tmp1
, tmp2
);
9608 putpkt (target_buf
);
9609 getpkt (&target_buf
, &target_buf_size
, 0);
9614 remote_trace_start (void)
9617 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9618 if (*target_buf
== '\0')
9619 error (_("Target does not support this command."));
9620 if (strcmp (target_buf
, "OK") != 0)
9621 error (_("Bogus reply from target: %s"), target_buf
);
9625 remote_get_trace_status (struct trace_status
*ts
)
9627 char *p
, *p1
, *p_temp
;
9629 /* FIXME we need to get register block size some other way */
9630 extern int trace_regblock_size
;
9631 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
9633 putpkt ("qTStatus");
9634 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9636 /* If the remote target doesn't do tracing, flag it. */
9640 /* We're working with a live target. */
9643 /* Set some defaults. */
9644 ts
->running_known
= 0;
9645 ts
->stop_reason
= trace_stop_reason_unknown
;
9646 ts
->traceframe_count
= -1;
9647 ts
->buffer_free
= 0;
9650 error (_("Bogus trace status reply from target: %s"), target_buf
);
9652 parse_trace_status (p
, ts
);
9658 remote_trace_stop (void)
9661 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9662 if (*target_buf
== '\0')
9663 error (_("Target does not support this command."));
9664 if (strcmp (target_buf
, "OK") != 0)
9665 error (_("Bogus reply from target: %s"), target_buf
);
9669 remote_trace_find (enum trace_find_type type
, int num
,
9670 ULONGEST addr1
, ULONGEST addr2
,
9673 struct remote_state
*rs
= get_remote_state ();
9675 int target_frameno
= -1, target_tracept
= -1;
9678 strcpy (p
, "QTFrame:");
9679 p
= strchr (p
, '\0');
9683 sprintf (p
, "%x", num
);
9686 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
9689 sprintf (p
, "tdp:%x", num
);
9692 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9695 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9698 error ("Unknown trace find type %d", type
);
9702 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
9704 error (_("Target does not support this command."));
9706 while (reply
&& *reply
)
9711 target_frameno
= (int) strtol (p
, &reply
, 16);
9713 error (_("Unable to parse trace frame number"));
9714 if (target_frameno
== -1)
9719 target_tracept
= (int) strtol (p
, &reply
, 16);
9721 error (_("Unable to parse tracepoint number"));
9723 case 'O': /* "OK"? */
9724 if (reply
[1] == 'K' && reply
[2] == '\0')
9727 error (_("Bogus reply from target: %s"), reply
);
9730 error (_("Bogus reply from target: %s"), reply
);
9733 *tpp
= target_tracept
;
9734 return target_frameno
;
9738 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
9740 struct remote_state
*rs
= get_remote_state ();
9744 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
9746 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9747 if (reply
&& *reply
)
9751 unpack_varlen_hex (reply
+ 1, &uval
);
9752 *val
= (LONGEST
) uval
;
9760 remote_save_trace_data (const char *filename
)
9762 struct remote_state
*rs
= get_remote_state ();
9766 strcpy (p
, "QTSave:");
9768 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
9769 error (_("Remote file name too long for trace save packet"));
9770 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
9773 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9775 error (_("Target does not support this command."));
9776 if (strcmp (reply
, "OK") != 0)
9777 error (_("Bogus reply from target: %s"), reply
);
9781 /* This is basically a memory transfer, but needs to be its own packet
9782 because we don't know how the target actually organizes its trace
9783 memory, plus we want to be able to ask for as much as possible, but
9784 not be unhappy if we don't get as much as we ask for. */
9787 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
9789 struct remote_state
*rs
= get_remote_state ();
9795 strcpy (p
, "qTBuffer:");
9797 p
+= hexnumstr (p
, offset
);
9799 p
+= hexnumstr (p
, len
);
9803 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9804 if (reply
&& *reply
)
9806 /* 'l' by itself means we're at the end of the buffer and
9807 there is nothing more to get. */
9811 /* Convert the reply into binary. Limit the number of bytes to
9812 convert according to our passed-in buffer size, rather than
9813 what was returned in the packet; if the target is
9814 unexpectedly generous and gives us a bigger reply than we
9815 asked for, we don't want to crash. */
9816 rslt
= hex2bin (target_buf
, buf
, len
);
9820 /* Something went wrong, flag as an error. */
9825 remote_set_disconnected_tracing (int val
)
9827 struct remote_state
*rs
= get_remote_state ();
9829 if (rs
->disconnected_tracing
)
9833 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
9835 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9837 error (_("Target does not support this command."));
9838 if (strcmp (reply
, "OK") != 0)
9839 error (_("Bogus reply from target: %s"), reply
);
9842 warning (_("Target does not support disconnected tracing."));
9846 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
9848 struct thread_info
*info
= find_thread_ptid (ptid
);
9849 if (info
&& info
->private)
9850 return info
->private->core
;
9855 remote_set_circular_trace_buffer (int val
)
9857 struct remote_state
*rs
= get_remote_state ();
9860 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
9862 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9864 error (_("Target does not support this command."));
9865 if (strcmp (reply
, "OK") != 0)
9866 error (_("Bogus reply from target: %s"), reply
);
9870 init_remote_ops (void)
9872 remote_ops
.to_shortname
= "remote";
9873 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
9875 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9876 Specify the serial device it is connected to\n\
9877 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
9878 remote_ops
.to_open
= remote_open
;
9879 remote_ops
.to_close
= remote_close
;
9880 remote_ops
.to_detach
= remote_detach
;
9881 remote_ops
.to_disconnect
= remote_disconnect
;
9882 remote_ops
.to_resume
= remote_resume
;
9883 remote_ops
.to_wait
= remote_wait
;
9884 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
9885 remote_ops
.to_store_registers
= remote_store_registers
;
9886 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
9887 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
9888 remote_ops
.to_files_info
= remote_files_info
;
9889 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
9890 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
9891 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
9892 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
9893 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
9894 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
9895 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
9896 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
9897 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
9898 remote_ops
.to_kill
= remote_kill
;
9899 remote_ops
.to_load
= generic_load
;
9900 remote_ops
.to_mourn_inferior
= remote_mourn
;
9901 remote_ops
.to_thread_alive
= remote_thread_alive
;
9902 remote_ops
.to_find_new_threads
= remote_threads_info
;
9903 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
9904 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
9905 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
9906 remote_ops
.to_stop
= remote_stop
;
9907 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
9908 remote_ops
.to_rcmd
= remote_rcmd
;
9909 remote_ops
.to_log_command
= serial_log_command
;
9910 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
9911 remote_ops
.to_stratum
= process_stratum
;
9912 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
9913 remote_ops
.to_has_memory
= default_child_has_memory
;
9914 remote_ops
.to_has_stack
= default_child_has_stack
;
9915 remote_ops
.to_has_registers
= default_child_has_registers
;
9916 remote_ops
.to_has_execution
= default_child_has_execution
;
9917 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
9918 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
9919 remote_ops
.to_magic
= OPS_MAGIC
;
9920 remote_ops
.to_memory_map
= remote_memory_map
;
9921 remote_ops
.to_flash_erase
= remote_flash_erase
;
9922 remote_ops
.to_flash_done
= remote_flash_done
;
9923 remote_ops
.to_read_description
= remote_read_description
;
9924 remote_ops
.to_search_memory
= remote_search_memory
;
9925 remote_ops
.to_can_async_p
= remote_can_async_p
;
9926 remote_ops
.to_is_async_p
= remote_is_async_p
;
9927 remote_ops
.to_async
= remote_async
;
9928 remote_ops
.to_async_mask
= remote_async_mask
;
9929 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
9930 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
9931 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
9932 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
9933 remote_ops
.to_trace_init
= remote_trace_init
;
9934 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
9935 remote_ops
.to_download_trace_state_variable
= remote_download_trace_state_variable
;
9936 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
9937 remote_ops
.to_trace_start
= remote_trace_start
;
9938 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
9939 remote_ops
.to_trace_stop
= remote_trace_stop
;
9940 remote_ops
.to_trace_find
= remote_trace_find
;
9941 remote_ops
.to_get_trace_state_variable_value
= remote_get_trace_state_variable_value
;
9942 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
9943 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
9944 remote_ops
.to_upload_trace_state_variables
= remote_upload_trace_state_variables
;
9945 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
9946 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
9947 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
9948 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
9949 remote_ops
.to_verify_memory
= remote_verify_memory
;
9950 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
9953 /* Set up the extended remote vector by making a copy of the standard
9954 remote vector and adding to it. */
9957 init_extended_remote_ops (void)
9959 extended_remote_ops
= remote_ops
;
9961 extended_remote_ops
.to_shortname
= "extended-remote";
9962 extended_remote_ops
.to_longname
=
9963 "Extended remote serial target in gdb-specific protocol";
9964 extended_remote_ops
.to_doc
=
9965 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9966 Specify the serial device it is connected to (e.g. /dev/ttya).";
9967 extended_remote_ops
.to_open
= extended_remote_open
;
9968 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
9969 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
9970 extended_remote_ops
.to_detach
= extended_remote_detach
;
9971 extended_remote_ops
.to_attach
= extended_remote_attach
;
9972 extended_remote_ops
.to_kill
= extended_remote_kill
;
9976 remote_can_async_p (void)
9978 if (!target_async_permitted
)
9979 /* We only enable async when the user specifically asks for it. */
9982 /* We're async whenever the serial device is. */
9983 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
9987 remote_is_async_p (void)
9989 if (!target_async_permitted
)
9990 /* We only enable async when the user specifically asks for it. */
9993 /* We're async whenever the serial device is. */
9994 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
9997 /* Pass the SERIAL event on and up to the client. One day this code
9998 will be able to delay notifying the client of an event until the
9999 point where an entire packet has been received. */
10001 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10003 static void *async_client_context
;
10004 static serial_event_ftype remote_async_serial_handler
;
10007 remote_async_serial_handler (struct serial
*scb
, void *context
)
10009 /* Don't propogate error information up to the client. Instead let
10010 the client find out about the error by querying the target. */
10011 async_client_callback (INF_REG_EVENT
, async_client_context
);
10015 remote_async_inferior_event_handler (gdb_client_data data
)
10017 inferior_event_handler (INF_REG_EVENT
, NULL
);
10021 remote_async_get_pending_events_handler (gdb_client_data data
)
10023 remote_get_pending_stop_replies ();
10027 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10028 void *context
), void *context
)
10030 if (remote_async_mask_value
== 0)
10031 internal_error (__FILE__
, __LINE__
,
10032 _("Calling remote_async when async is masked"));
10034 if (callback
!= NULL
)
10036 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10037 async_client_callback
= callback
;
10038 async_client_context
= context
;
10041 serial_async (remote_desc
, NULL
, NULL
);
10045 remote_async_mask (int new_mask
)
10047 int curr_mask
= remote_async_mask_value
;
10048 remote_async_mask_value
= new_mask
;
10053 set_remote_cmd (char *args
, int from_tty
)
10055 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10059 show_remote_cmd (char *args
, int from_tty
)
10061 /* We can't just use cmd_show_list here, because we want to skip
10062 the redundant "show remote Z-packet" and the legacy aliases. */
10063 struct cleanup
*showlist_chain
;
10064 struct cmd_list_element
*list
= remote_show_cmdlist
;
10066 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10067 for (; list
!= NULL
; list
= list
->next
)
10068 if (strcmp (list
->name
, "Z-packet") == 0)
10070 else if (list
->type
== not_set_cmd
)
10071 /* Alias commands are exactly like the original, except they
10072 don't have the normal type. */
10076 struct cleanup
*option_chain
10077 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10078 ui_out_field_string (uiout
, "name", list
->name
);
10079 ui_out_text (uiout
, ": ");
10080 if (list
->type
== show_cmd
)
10081 do_setshow_command ((char *) NULL
, from_tty
, list
);
10083 cmd_func (list
, NULL
, from_tty
);
10084 /* Close the tuple. */
10085 do_cleanups (option_chain
);
10088 /* Close the tuple. */
10089 do_cleanups (showlist_chain
);
10093 /* Function to be called whenever a new objfile (shlib) is detected. */
10095 remote_new_objfile (struct objfile
*objfile
)
10097 if (remote_desc
!= 0) /* Have a remote connection. */
10098 remote_check_symbols (objfile
);
10101 /* Pull all the tracepoints defined on the target and create local
10102 data structures representing them. We don't want to create real
10103 tracepoints yet, we don't want to mess up the user's existing
10107 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10109 struct remote_state
*rs
= get_remote_state ();
10112 /* Ask for a first packet of tracepoint definition. */
10114 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10116 while (*p
&& *p
!= 'l')
10118 parse_tracepoint_definition (p
, utpp
);
10119 /* Ask for another packet of tracepoint definition. */
10121 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10128 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10130 struct remote_state
*rs
= get_remote_state ();
10133 /* Ask for a first packet of variable definition. */
10135 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10137 while (*p
&& *p
!= 'l')
10139 parse_tsv_definition (p
, utsvp
);
10140 /* Ask for another packet of variable definition. */
10142 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10149 _initialize_remote (void)
10151 struct remote_state
*rs
;
10152 struct cmd_list_element
*cmd
;
10155 /* architecture specific data */
10156 remote_gdbarch_data_handle
=
10157 gdbarch_data_register_post_init (init_remote_state
);
10158 remote_g_packet_data_handle
=
10159 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10161 /* Initialize the per-target state. At the moment there is only one
10162 of these, not one per target. Only one target is active at a
10163 time. The default buffer size is unimportant; it will be expanded
10164 whenever a larger buffer is needed. */
10165 rs
= get_remote_state_raw ();
10166 rs
->buf_size
= 400;
10167 rs
->buf
= xmalloc (rs
->buf_size
);
10169 init_remote_ops ();
10170 add_target (&remote_ops
);
10172 init_extended_remote_ops ();
10173 add_target (&extended_remote_ops
);
10175 /* Hook into new objfile notification. */
10176 observer_attach_new_objfile (remote_new_objfile
);
10178 /* Set up signal handlers. */
10179 sigint_remote_token
=
10180 create_async_signal_handler (async_remote_interrupt
, NULL
);
10181 sigint_remote_twice_token
=
10182 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
10185 init_remote_threadtests ();
10188 /* set/show remote ... */
10190 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10191 Remote protocol specific variables\n\
10192 Configure various remote-protocol specific variables such as\n\
10193 the packets being used"),
10194 &remote_set_cmdlist
, "set remote ",
10195 0 /* allow-unknown */, &setlist
);
10196 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10197 Remote protocol specific variables\n\
10198 Configure various remote-protocol specific variables such as\n\
10199 the packets being used"),
10200 &remote_show_cmdlist
, "show remote ",
10201 0 /* allow-unknown */, &showlist
);
10203 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10204 Compare section data on target to the exec file.\n\
10205 Argument is a single section name (default: all loaded sections)."),
10208 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10209 Send an arbitrary packet to a remote target.\n\
10210 maintenance packet TEXT\n\
10211 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10212 this command sends the string TEXT to the inferior, and displays the\n\
10213 response packet. GDB supplies the initial `$' character, and the\n\
10214 terminating `#' character and checksum."),
10217 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10218 Set whether to send break if interrupted."), _("\
10219 Show whether to send break if interrupted."), _("\
10220 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10221 set_remotebreak
, show_remotebreak
,
10222 &setlist
, &showlist
);
10223 cmd_name
= "remotebreak";
10224 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10225 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10226 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10227 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10228 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10230 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10231 interrupt_sequence_modes
, &interrupt_sequence_mode
, _("\
10232 Set interrupt sequence to remote target."), _("\
10233 Show interrupt sequence to remote target."), _("\
10234 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10235 NULL
, show_interrupt_sequence
,
10236 &remote_set_cmdlist
,
10237 &remote_show_cmdlist
);
10239 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10240 &interrupt_on_connect
, _("\
10241 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10242 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10243 If set, interrupt sequence is sent to remote target."),
10245 &remote_set_cmdlist
, &remote_show_cmdlist
);
10247 /* Install commands for configuring memory read/write packets. */
10249 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10250 Set the maximum number of bytes per memory write packet (deprecated)."),
10252 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10253 Show the maximum number of bytes per memory write packet (deprecated)."),
10255 add_cmd ("memory-write-packet-size", no_class
,
10256 set_memory_write_packet_size
, _("\
10257 Set the maximum number of bytes per memory-write packet.\n\
10258 Specify the number of bytes in a packet or 0 (zero) for the\n\
10259 default packet size. The actual limit is further reduced\n\
10260 dependent on the target. Specify ``fixed'' to disable the\n\
10261 further restriction and ``limit'' to enable that restriction."),
10262 &remote_set_cmdlist
);
10263 add_cmd ("memory-read-packet-size", no_class
,
10264 set_memory_read_packet_size
, _("\
10265 Set the maximum number of bytes per memory-read packet.\n\
10266 Specify the number of bytes in a packet or 0 (zero) for the\n\
10267 default packet size. The actual limit is further reduced\n\
10268 dependent on the target. Specify ``fixed'' to disable the\n\
10269 further restriction and ``limit'' to enable that restriction."),
10270 &remote_set_cmdlist
);
10271 add_cmd ("memory-write-packet-size", no_class
,
10272 show_memory_write_packet_size
,
10273 _("Show the maximum number of bytes per memory-write packet."),
10274 &remote_show_cmdlist
);
10275 add_cmd ("memory-read-packet-size", no_class
,
10276 show_memory_read_packet_size
,
10277 _("Show the maximum number of bytes per memory-read packet."),
10278 &remote_show_cmdlist
);
10280 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10281 &remote_hw_watchpoint_limit
, _("\
10282 Set the maximum number of target hardware watchpoints."), _("\
10283 Show the maximum number of target hardware watchpoints."), _("\
10284 Specify a negative limit for unlimited."),
10285 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
10286 &remote_set_cmdlist
, &remote_show_cmdlist
);
10287 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10288 &remote_hw_breakpoint_limit
, _("\
10289 Set the maximum number of target hardware breakpoints."), _("\
10290 Show the maximum number of target hardware breakpoints."), _("\
10291 Specify a negative limit for unlimited."),
10292 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
10293 &remote_set_cmdlist
, &remote_show_cmdlist
);
10295 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10296 &remote_address_size
, _("\
10297 Set the maximum size of the address (in bits) in a memory packet."), _("\
10298 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10300 NULL
, /* FIXME: i18n: */
10301 &setlist
, &showlist
);
10303 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10304 "X", "binary-download", 1);
10306 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10307 "vCont", "verbose-resume", 0);
10309 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10310 "QPassSignals", "pass-signals", 0);
10312 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10313 "qSymbol", "symbol-lookup", 0);
10315 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10316 "P", "set-register", 1);
10318 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10319 "p", "fetch-register", 1);
10321 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10322 "Z0", "software-breakpoint", 0);
10324 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10325 "Z1", "hardware-breakpoint", 0);
10327 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10328 "Z2", "write-watchpoint", 0);
10330 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10331 "Z3", "read-watchpoint", 0);
10333 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10334 "Z4", "access-watchpoint", 0);
10336 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10337 "qXfer:auxv:read", "read-aux-vector", 0);
10339 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10340 "qXfer:features:read", "target-features", 0);
10342 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10343 "qXfer:libraries:read", "library-info", 0);
10345 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10346 "qXfer:memory-map:read", "memory-map", 0);
10348 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10349 "qXfer:spu:read", "read-spu-object", 0);
10351 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10352 "qXfer:spu:write", "write-spu-object", 0);
10354 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10355 "qXfer:osdata:read", "osdata", 0);
10357 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10358 "qXfer:threads:read", "threads", 0);
10360 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10361 "qXfer:siginfo:read", "read-siginfo-object", 0);
10363 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
10364 "qXfer:siginfo:write", "write-siginfo-object", 0);
10366 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
10367 "qGetTLSAddr", "get-thread-local-storage-address",
10370 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
10371 "qGetTIBAddr", "get-thread-information-block-address",
10374 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
10375 "bc", "reverse-continue", 0);
10377 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
10378 "bs", "reverse-step", 0);
10380 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
10381 "qSupported", "supported-packets", 0);
10383 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
10384 "qSearch:memory", "search-memory", 0);
10386 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
10387 "vFile:open", "hostio-open", 0);
10389 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
10390 "vFile:pread", "hostio-pread", 0);
10392 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
10393 "vFile:pwrite", "hostio-pwrite", 0);
10395 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
10396 "vFile:close", "hostio-close", 0);
10398 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
10399 "vFile:unlink", "hostio-unlink", 0);
10401 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
10402 "vAttach", "attach", 0);
10404 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
10407 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
10408 "QStartNoAckMode", "noack", 0);
10410 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
10411 "vKill", "kill", 0);
10413 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
10414 "qAttached", "query-attached", 0);
10416 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
10417 "ConditionalTracepoints", "conditional-tracepoints", 0);
10418 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
10419 "FastTracepoints", "fast-tracepoints", 0);
10421 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
10422 "TracepointSource", "TracepointSource", 0);
10424 /* Keep the old ``set remote Z-packet ...'' working. Each individual
10425 Z sub-packet has its own set and show commands, but users may
10426 have sets to this variable in their .gdbinit files (or in their
10428 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
10429 &remote_Z_packet_detect
, _("\
10430 Set use of remote protocol `Z' packets"), _("\
10431 Show use of remote protocol `Z' packets "), _("\
10432 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
10434 set_remote_protocol_Z_packet_cmd
,
10435 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
10436 &remote_set_cmdlist
, &remote_show_cmdlist
);
10438 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
10439 Manipulate files on the remote system\n\
10440 Transfer files to and from the remote target system."),
10441 &remote_cmdlist
, "remote ",
10442 0 /* allow-unknown */, &cmdlist
);
10444 add_cmd ("put", class_files
, remote_put_command
,
10445 _("Copy a local file to the remote system."),
10448 add_cmd ("get", class_files
, remote_get_command
,
10449 _("Copy a remote file to the local system."),
10452 add_cmd ("delete", class_files
, remote_delete_command
,
10453 _("Delete a remote file."),
10456 remote_exec_file
= xstrdup ("");
10457 add_setshow_string_noescape_cmd ("exec-file", class_files
,
10458 &remote_exec_file
, _("\
10459 Set the remote pathname for \"run\""), _("\
10460 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
10461 &remote_set_cmdlist
, &remote_show_cmdlist
);
10463 /* Eventually initialize fileio. See fileio.c */
10464 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
10466 /* Take advantage of the fact that the LWP field is not used, to tag
10467 special ptids with it set to != 0. */
10468 magic_null_ptid
= ptid_build (42000, 1, -1);
10469 not_sent_ptid
= ptid_build (42000, 1, -2);
10470 any_thread_ptid
= ptid_build (42000, 1, 0);
10472 target_buf_size
= 2048;
10473 target_buf
= xmalloc (target_buf_size
);