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
,
1141 PACKET_QPassSignals
,
1142 PACKET_qSearch_memory
,
1145 PACKET_QStartNoAckMode
,
1147 PACKET_qXfer_siginfo_read
,
1148 PACKET_qXfer_siginfo_write
,
1150 PACKET_ConditionalTracepoints
,
1151 PACKET_FastTracepoints
,
1154 PACKET_TracepointSource
,
1158 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1161 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1162 struct cmd_list_element
*c
)
1164 struct packet_config
*packet
;
1166 for (packet
= remote_protocol_packets
;
1167 packet
< &remote_protocol_packets
[PACKET_MAX
];
1170 if (&packet
->detect
== c
->var
)
1172 update_packet_config (packet
);
1176 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1181 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1182 struct cmd_list_element
*c
,
1185 struct packet_config
*packet
;
1187 for (packet
= remote_protocol_packets
;
1188 packet
< &remote_protocol_packets
[PACKET_MAX
];
1191 if (&packet
->detect
== c
->var
)
1193 show_packet_config_cmd (packet
);
1197 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1201 /* Should we try one of the 'Z' requests? */
1205 Z_PACKET_SOFTWARE_BP
,
1206 Z_PACKET_HARDWARE_BP
,
1213 /* For compatibility with older distributions. Provide a ``set remote
1214 Z-packet ...'' command that updates all the Z packet types. */
1216 static enum auto_boolean remote_Z_packet_detect
;
1219 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1220 struct cmd_list_element
*c
)
1223 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1225 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1226 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1231 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1232 struct cmd_list_element
*c
,
1236 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1238 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1242 /* Should we try the 'ThreadInfo' query packet?
1244 This variable (NOT available to the user: auto-detect only!)
1245 determines whether GDB will use the new, simpler "ThreadInfo"
1246 query or the older, more complex syntax for thread queries.
1247 This is an auto-detect variable (set to true at each connect,
1248 and set to false when the target fails to recognize it). */
1250 static int use_threadinfo_query
;
1251 static int use_threadextra_query
;
1253 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1254 static struct async_signal_handler
*sigint_remote_twice_token
;
1255 static struct async_signal_handler
*sigint_remote_token
;
1258 /* Asynchronous signal handle registered as event loop source for
1259 when we have pending events ready to be passed to the core. */
1261 static struct async_event_handler
*remote_async_inferior_event_token
;
1263 /* Asynchronous signal handle registered as event loop source for when
1264 the remote sent us a %Stop notification. The registered callback
1265 will do a vStopped sequence to pull the rest of the events out of
1266 the remote side into our event queue. */
1268 static struct async_event_handler
*remote_async_get_pending_events_token
;
1271 static ptid_t magic_null_ptid
;
1272 static ptid_t not_sent_ptid
;
1273 static ptid_t any_thread_ptid
;
1275 /* These are the threads which we last sent to the remote system. The
1276 TID member will be -1 for all or -2 for not sent yet. */
1278 static ptid_t general_thread
;
1279 static ptid_t continue_thread
;
1281 /* Find out if the stub attached to PID (and hence GDB should offer to
1282 detach instead of killing it when bailing out). */
1285 remote_query_attached (int pid
)
1287 struct remote_state
*rs
= get_remote_state ();
1289 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1292 if (remote_multi_process_p (rs
))
1293 sprintf (rs
->buf
, "qAttached:%x", pid
);
1295 sprintf (rs
->buf
, "qAttached");
1298 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1300 switch (packet_ok (rs
->buf
,
1301 &remote_protocol_packets
[PACKET_qAttached
]))
1304 if (strcmp (rs
->buf
, "1") == 0)
1308 warning (_("Remote failure reply: %s"), rs
->buf
);
1310 case PACKET_UNKNOWN
:
1317 /* Add PID to GDB's inferior table. Since we can be connected to a
1318 remote system before before knowing about any inferior, mark the
1319 target with execution when we find the first inferior. If ATTACHED
1320 is 1, then we had just attached to this inferior. If it is 0, then
1321 we just created this inferior. If it is -1, then try querying the
1322 remote stub to find out if it had attached to the inferior or
1325 static struct inferior
*
1326 remote_add_inferior (int pid
, int attached
)
1328 struct inferior
*inf
;
1330 /* Check whether this process we're learning about is to be
1331 considered attached, or if is to be considered to have been
1332 spawned by the stub. */
1334 attached
= remote_query_attached (pid
);
1336 if (gdbarch_has_global_solist (target_gdbarch
))
1338 /* If the target shares code across all inferiors, then every
1339 attach adds a new inferior. */
1340 inf
= add_inferior (pid
);
1342 /* ... and every inferior is bound to the same program space.
1343 However, each inferior may still have its own address
1345 inf
->aspace
= maybe_new_address_space ();
1346 inf
->pspace
= current_program_space
;
1350 /* In the traditional debugging scenario, there's a 1-1 match
1351 between program/address spaces. We simply bind the inferior
1352 to the program space's address space. */
1353 inf
= current_inferior ();
1354 inferior_appeared (inf
, pid
);
1357 inf
->attach_flag
= attached
;
1362 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1363 according to RUNNING. */
1366 remote_add_thread (ptid_t ptid
, int running
)
1370 set_executing (ptid
, running
);
1371 set_running (ptid
, running
);
1374 /* Come here when we learn about a thread id from the remote target.
1375 It may be the first time we hear about such thread, so take the
1376 opportunity to add it to GDB's thread list. In case this is the
1377 first time we're noticing its corresponding inferior, add it to
1378 GDB's inferior list as well. */
1381 remote_notice_new_inferior (ptid_t currthread
, int running
)
1383 /* If this is a new thread, add it to GDB's thread list.
1384 If we leave it up to WFI to do this, bad things will happen. */
1386 if (in_thread_list (currthread
) && is_exited (currthread
))
1388 /* We're seeing an event on a thread id we knew had exited.
1389 This has to be a new thread reusing the old id. Add it. */
1390 remote_add_thread (currthread
, running
);
1394 if (!in_thread_list (currthread
))
1396 struct inferior
*inf
= NULL
;
1397 int pid
= ptid_get_pid (currthread
);
1399 if (ptid_is_pid (inferior_ptid
)
1400 && pid
== ptid_get_pid (inferior_ptid
))
1402 /* inferior_ptid has no thread member yet. This can happen
1403 with the vAttach -> remote_wait,"TAAthread:" path if the
1404 stub doesn't support qC. This is the first stop reported
1405 after an attach, so this is the main thread. Update the
1406 ptid in the thread list. */
1407 if (in_thread_list (pid_to_ptid (pid
)))
1408 thread_change_ptid (inferior_ptid
, currthread
);
1411 remote_add_thread (currthread
, running
);
1412 inferior_ptid
= currthread
;
1417 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1419 /* inferior_ptid is not set yet. This can happen with the
1420 vRun -> remote_wait,"TAAthread:" path if the stub
1421 doesn't support qC. This is the first stop reported
1422 after an attach, so this is the main thread. Update the
1423 ptid in the thread list. */
1424 thread_change_ptid (inferior_ptid
, currthread
);
1428 /* When connecting to a target remote, or to a target
1429 extended-remote which already was debugging an inferior, we
1430 may not know about it yet. Add it before adding its child
1431 thread, so notifications are emitted in a sensible order. */
1432 if (!in_inferior_list (ptid_get_pid (currthread
)))
1433 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1435 /* This is really a new thread. Add it. */
1436 remote_add_thread (currthread
, running
);
1438 /* If we found a new inferior, let the common code do whatever
1439 it needs to with it (e.g., read shared libraries, insert
1442 notice_new_inferior (currthread
, running
, 0);
1446 /* Return the private thread data, creating it if necessary. */
1448 struct private_thread_info
*
1449 demand_private_info (ptid_t ptid
)
1451 struct thread_info
*info
= find_thread_ptid (ptid
);
1457 info
->private = xmalloc (sizeof (*(info
->private)));
1458 info
->private_dtor
= free_private_thread_info
;
1459 info
->private->core
= -1;
1460 info
->private->extra
= 0;
1463 return info
->private;
1466 /* Call this function as a result of
1467 1) A halt indication (T packet) containing a thread id
1468 2) A direct query of currthread
1469 3) Successful execution of set thread
1473 record_currthread (ptid_t currthread
)
1475 general_thread
= currthread
;
1478 static char *last_pass_packet
;
1480 /* If 'QPassSignals' is supported, tell the remote stub what signals
1481 it can simply pass through to the inferior without reporting. */
1484 remote_pass_signals (void)
1486 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1488 char *pass_packet
, *p
;
1489 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1492 gdb_assert (numsigs
< 256);
1493 for (i
= 0; i
< numsigs
; i
++)
1495 if (signal_stop_state (i
) == 0
1496 && signal_print_state (i
) == 0
1497 && signal_pass_state (i
) == 1)
1500 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1501 strcpy (pass_packet
, "QPassSignals:");
1502 p
= pass_packet
+ strlen (pass_packet
);
1503 for (i
= 0; i
< numsigs
; i
++)
1505 if (signal_stop_state (i
) == 0
1506 && signal_print_state (i
) == 0
1507 && signal_pass_state (i
) == 1)
1510 *p
++ = tohex (i
>> 4);
1511 *p
++ = tohex (i
& 15);
1520 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1522 struct remote_state
*rs
= get_remote_state ();
1523 char *buf
= rs
->buf
;
1525 putpkt (pass_packet
);
1526 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1527 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1528 if (last_pass_packet
)
1529 xfree (last_pass_packet
);
1530 last_pass_packet
= pass_packet
;
1533 xfree (pass_packet
);
1537 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1538 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1539 thread. If GEN is set, set the general thread, if not, then set
1540 the step/continue thread. */
1542 set_thread (struct ptid ptid
, int gen
)
1544 struct remote_state
*rs
= get_remote_state ();
1545 ptid_t state
= gen
? general_thread
: continue_thread
;
1546 char *buf
= rs
->buf
;
1547 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1549 if (ptid_equal (state
, ptid
))
1553 *buf
++ = gen
? 'g' : 'c';
1554 if (ptid_equal (ptid
, magic_null_ptid
))
1555 xsnprintf (buf
, endbuf
- buf
, "0");
1556 else if (ptid_equal (ptid
, any_thread_ptid
))
1557 xsnprintf (buf
, endbuf
- buf
, "0");
1558 else if (ptid_equal (ptid
, minus_one_ptid
))
1559 xsnprintf (buf
, endbuf
- buf
, "-1");
1561 write_ptid (buf
, endbuf
, ptid
);
1563 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1565 general_thread
= ptid
;
1567 continue_thread
= ptid
;
1571 set_general_thread (struct ptid ptid
)
1573 set_thread (ptid
, 1);
1577 set_continue_thread (struct ptid ptid
)
1579 set_thread (ptid
, 0);
1582 /* Change the remote current process. Which thread within the process
1583 ends up selected isn't important, as long as it is the same process
1584 as what INFERIOR_PTID points to.
1586 This comes from that fact that there is no explicit notion of
1587 "selected process" in the protocol. The selected process for
1588 general operations is the process the selected general thread
1592 set_general_process (void)
1594 struct remote_state
*rs
= get_remote_state ();
1596 /* If the remote can't handle multiple processes, don't bother. */
1597 if (!remote_multi_process_p (rs
))
1600 /* We only need to change the remote current thread if it's pointing
1601 at some other process. */
1602 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1603 set_general_thread (inferior_ptid
);
1607 /* Return nonzero if the thread PTID is still alive on the remote
1611 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1613 struct remote_state
*rs
= get_remote_state ();
1616 if (ptid_equal (ptid
, magic_null_ptid
))
1617 /* The main thread is always alive. */
1620 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1621 /* The main thread is always alive. This can happen after a
1622 vAttach, if the remote side doesn't support
1627 endp
= rs
->buf
+ get_remote_packet_size ();
1630 write_ptid (p
, endp
, ptid
);
1633 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1634 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1637 /* About these extended threadlist and threadinfo packets. They are
1638 variable length packets but, the fields within them are often fixed
1639 length. They are redundent enough to send over UDP as is the
1640 remote protocol in general. There is a matching unit test module
1643 #define OPAQUETHREADBYTES 8
1645 /* a 64 bit opaque identifier */
1646 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1648 /* WARNING: This threadref data structure comes from the remote O.S.,
1649 libstub protocol encoding, and remote.c. it is not particularly
1652 /* Right now, the internal structure is int. We want it to be bigger.
1656 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1658 /* gdb_ext_thread_info is an internal GDB data structure which is
1659 equivalent to the reply of the remote threadinfo packet. */
1661 struct gdb_ext_thread_info
1663 threadref threadid
; /* External form of thread reference. */
1664 int active
; /* Has state interesting to GDB?
1666 char display
[256]; /* Brief state display, name,
1667 blocked/suspended. */
1668 char shortname
[32]; /* To be used to name threads. */
1669 char more_display
[256]; /* Long info, statistics, queue depth,
1673 /* The volume of remote transfers can be limited by submitting
1674 a mask containing bits specifying the desired information.
1675 Use a union of these values as the 'selection' parameter to
1676 get_thread_info. FIXME: Make these TAG names more thread specific.
1679 #define TAG_THREADID 1
1680 #define TAG_EXISTS 2
1681 #define TAG_DISPLAY 4
1682 #define TAG_THREADNAME 8
1683 #define TAG_MOREDISPLAY 16
1685 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1687 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1689 static char *unpack_nibble (char *buf
, int *val
);
1691 static char *pack_nibble (char *buf
, int nibble
);
1693 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1695 static char *unpack_byte (char *buf
, int *value
);
1697 static char *pack_int (char *buf
, int value
);
1699 static char *unpack_int (char *buf
, int *value
);
1701 static char *unpack_string (char *src
, char *dest
, int length
);
1703 static char *pack_threadid (char *pkt
, threadref
*id
);
1705 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1707 void int_to_threadref (threadref
*id
, int value
);
1709 static int threadref_to_int (threadref
*ref
);
1711 static void copy_threadref (threadref
*dest
, threadref
*src
);
1713 static int threadmatch (threadref
*dest
, threadref
*src
);
1715 static char *pack_threadinfo_request (char *pkt
, int mode
,
1718 static int remote_unpack_thread_info_response (char *pkt
,
1719 threadref
*expectedref
,
1720 struct gdb_ext_thread_info
1724 static int remote_get_threadinfo (threadref
*threadid
,
1725 int fieldset
, /*TAG mask */
1726 struct gdb_ext_thread_info
*info
);
1728 static char *pack_threadlist_request (char *pkt
, int startflag
,
1730 threadref
*nextthread
);
1732 static int parse_threadlist_response (char *pkt
,
1734 threadref
*original_echo
,
1735 threadref
*resultlist
,
1738 static int remote_get_threadlist (int startflag
,
1739 threadref
*nextthread
,
1743 threadref
*threadlist
);
1745 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1747 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1748 void *context
, int looplimit
);
1750 static int remote_newthread_step (threadref
*ref
, void *context
);
1753 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1754 buffer we're allowed to write to. Returns
1755 BUF+CHARACTERS_WRITTEN. */
1758 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1761 struct remote_state
*rs
= get_remote_state ();
1763 if (remote_multi_process_p (rs
))
1765 pid
= ptid_get_pid (ptid
);
1767 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1769 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1771 tid
= ptid_get_tid (ptid
);
1773 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1775 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1780 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1781 passed the last parsed char. Returns null_ptid on error. */
1784 read_ptid (char *buf
, char **obuf
)
1788 ULONGEST pid
= 0, tid
= 0;
1792 /* Multi-process ptid. */
1793 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1795 error (_("invalid remote ptid: %s\n"), p
);
1798 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1801 return ptid_build (pid
, 0, tid
);
1804 /* No multi-process. Just a tid. */
1805 pp
= unpack_varlen_hex (p
, &tid
);
1807 /* Since the stub is not sending a process id, then default to
1808 what's in inferior_ptid, unless it's null at this point. If so,
1809 then since there's no way to know the pid of the reported
1810 threads, use the magic number. */
1811 if (ptid_equal (inferior_ptid
, null_ptid
))
1812 pid
= ptid_get_pid (magic_null_ptid
);
1814 pid
= ptid_get_pid (inferior_ptid
);
1818 return ptid_build (pid
, 0, tid
);
1821 /* Encode 64 bits in 16 chars of hex. */
1823 static const char hexchars
[] = "0123456789abcdef";
1826 ishex (int ch
, int *val
)
1828 if ((ch
>= 'a') && (ch
<= 'f'))
1830 *val
= ch
- 'a' + 10;
1833 if ((ch
>= 'A') && (ch
<= 'F'))
1835 *val
= ch
- 'A' + 10;
1838 if ((ch
>= '0') && (ch
<= '9'))
1849 if (ch
>= 'a' && ch
<= 'f')
1850 return ch
- 'a' + 10;
1851 if (ch
>= '0' && ch
<= '9')
1853 if (ch
>= 'A' && ch
<= 'F')
1854 return ch
- 'A' + 10;
1859 stub_unpack_int (char *buff
, int fieldlength
)
1866 nibble
= stubhex (*buff
++);
1870 retval
= retval
<< 4;
1876 unpack_varlen_hex (char *buff
, /* packet to parse */
1880 ULONGEST retval
= 0;
1882 while (ishex (*buff
, &nibble
))
1885 retval
= retval
<< 4;
1886 retval
|= nibble
& 0x0f;
1893 unpack_nibble (char *buf
, int *val
)
1895 *val
= fromhex (*buf
++);
1900 pack_nibble (char *buf
, int nibble
)
1902 *buf
++ = hexchars
[(nibble
& 0x0f)];
1907 pack_hex_byte (char *pkt
, int byte
)
1909 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1910 *pkt
++ = hexchars
[(byte
& 0xf)];
1915 unpack_byte (char *buf
, int *value
)
1917 *value
= stub_unpack_int (buf
, 2);
1922 pack_int (char *buf
, int value
)
1924 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1925 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1926 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1927 buf
= pack_hex_byte (buf
, (value
& 0xff));
1932 unpack_int (char *buf
, int *value
)
1934 *value
= stub_unpack_int (buf
, 8);
1938 #if 0 /* Currently unused, uncomment when needed. */
1939 static char *pack_string (char *pkt
, char *string
);
1942 pack_string (char *pkt
, char *string
)
1947 len
= strlen (string
);
1949 len
= 200; /* Bigger than most GDB packets, junk??? */
1950 pkt
= pack_hex_byte (pkt
, len
);
1954 if ((ch
== '\0') || (ch
== '#'))
1955 ch
= '*'; /* Protect encapsulation. */
1960 #endif /* 0 (unused) */
1963 unpack_string (char *src
, char *dest
, int length
)
1972 pack_threadid (char *pkt
, threadref
*id
)
1975 unsigned char *altid
;
1977 altid
= (unsigned char *) id
;
1978 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1980 pkt
= pack_hex_byte (pkt
, *altid
++);
1986 unpack_threadid (char *inbuf
, threadref
*id
)
1989 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1992 altref
= (char *) id
;
1994 while (inbuf
< limit
)
1996 x
= stubhex (*inbuf
++);
1997 y
= stubhex (*inbuf
++);
1998 *altref
++ = (x
<< 4) | y
;
2003 /* Externally, threadrefs are 64 bits but internally, they are still
2004 ints. This is due to a mismatch of specifications. We would like
2005 to use 64bit thread references internally. This is an adapter
2009 int_to_threadref (threadref
*id
, int value
)
2011 unsigned char *scan
;
2013 scan
= (unsigned char *) id
;
2019 *scan
++ = (value
>> 24) & 0xff;
2020 *scan
++ = (value
>> 16) & 0xff;
2021 *scan
++ = (value
>> 8) & 0xff;
2022 *scan
++ = (value
& 0xff);
2026 threadref_to_int (threadref
*ref
)
2029 unsigned char *scan
;
2035 value
= (value
<< 8) | ((*scan
++) & 0xff);
2040 copy_threadref (threadref
*dest
, threadref
*src
)
2043 unsigned char *csrc
, *cdest
;
2045 csrc
= (unsigned char *) src
;
2046 cdest
= (unsigned char *) dest
;
2053 threadmatch (threadref
*dest
, threadref
*src
)
2055 /* Things are broken right now, so just assume we got a match. */
2057 unsigned char *srcp
, *destp
;
2059 srcp
= (char *) src
;
2060 destp
= (char *) dest
;
2064 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2071 threadid:1, # always request threadid
2078 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2081 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2083 *pkt
++ = 'q'; /* Info Query */
2084 *pkt
++ = 'P'; /* process or thread info */
2085 pkt
= pack_int (pkt
, mode
); /* mode */
2086 pkt
= pack_threadid (pkt
, id
); /* threadid */
2087 *pkt
= '\0'; /* terminate */
2091 /* These values tag the fields in a thread info response packet. */
2092 /* Tagging the fields allows us to request specific fields and to
2093 add more fields as time goes by. */
2095 #define TAG_THREADID 1 /* Echo the thread identifier. */
2096 #define TAG_EXISTS 2 /* Is this process defined enough to
2097 fetch registers and its stack? */
2098 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2099 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2100 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2104 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2105 struct gdb_ext_thread_info
*info
)
2107 struct remote_state
*rs
= get_remote_state ();
2111 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2114 /* info->threadid = 0; FIXME: implement zero_threadref. */
2116 info
->display
[0] = '\0';
2117 info
->shortname
[0] = '\0';
2118 info
->more_display
[0] = '\0';
2120 /* Assume the characters indicating the packet type have been
2122 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2123 pkt
= unpack_threadid (pkt
, &ref
);
2126 warning (_("Incomplete response to threadinfo request."));
2127 if (!threadmatch (&ref
, expectedref
))
2128 { /* This is an answer to a different request. */
2129 warning (_("ERROR RMT Thread info mismatch."));
2132 copy_threadref (&info
->threadid
, &ref
);
2134 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2136 /* Packets are terminated with nulls. */
2137 while ((pkt
< limit
) && mask
&& *pkt
)
2139 pkt
= unpack_int (pkt
, &tag
); /* tag */
2140 pkt
= unpack_byte (pkt
, &length
); /* length */
2141 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2143 warning (_("ERROR RMT: threadinfo tag mismatch."));
2147 if (tag
== TAG_THREADID
)
2151 warning (_("ERROR RMT: length of threadid is not 16."));
2155 pkt
= unpack_threadid (pkt
, &ref
);
2156 mask
= mask
& ~TAG_THREADID
;
2159 if (tag
== TAG_EXISTS
)
2161 info
->active
= stub_unpack_int (pkt
, length
);
2163 mask
= mask
& ~(TAG_EXISTS
);
2166 warning (_("ERROR RMT: 'exists' length too long."));
2172 if (tag
== TAG_THREADNAME
)
2174 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2175 mask
= mask
& ~TAG_THREADNAME
;
2178 if (tag
== TAG_DISPLAY
)
2180 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2181 mask
= mask
& ~TAG_DISPLAY
;
2184 if (tag
== TAG_MOREDISPLAY
)
2186 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2187 mask
= mask
& ~TAG_MOREDISPLAY
;
2190 warning (_("ERROR RMT: unknown thread info tag."));
2191 break; /* Not a tag we know about. */
2197 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2198 struct gdb_ext_thread_info
*info
)
2200 struct remote_state
*rs
= get_remote_state ();
2203 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2205 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2207 if (rs
->buf
[0] == '\0')
2210 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2215 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2218 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2219 threadref
*nextthread
)
2221 *pkt
++ = 'q'; /* info query packet */
2222 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2223 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2224 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2225 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2230 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2233 parse_threadlist_response (char *pkt
, int result_limit
,
2234 threadref
*original_echo
, threadref
*resultlist
,
2237 struct remote_state
*rs
= get_remote_state ();
2239 int count
, resultcount
, done
;
2242 /* Assume the 'q' and 'M chars have been stripped. */
2243 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2244 /* done parse past here */
2245 pkt
= unpack_byte (pkt
, &count
); /* count field */
2246 pkt
= unpack_nibble (pkt
, &done
);
2247 /* The first threadid is the argument threadid. */
2248 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2249 while ((count
-- > 0) && (pkt
< limit
))
2251 pkt
= unpack_threadid (pkt
, resultlist
++);
2252 if (resultcount
++ >= result_limit
)
2261 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2262 int *done
, int *result_count
, threadref
*threadlist
)
2264 struct remote_state
*rs
= get_remote_state ();
2265 static threadref echo_nextthread
;
2268 /* Trancate result limit to be smaller than the packet size. */
2269 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
2270 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2272 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2274 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2276 if (*rs
->buf
== '\0')
2280 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2283 if (!threadmatch (&echo_nextthread
, nextthread
))
2285 /* FIXME: This is a good reason to drop the packet. */
2286 /* Possably, there is a duplicate response. */
2288 retransmit immediatly - race conditions
2289 retransmit after timeout - yes
2291 wait for packet, then exit
2293 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2294 return 0; /* I choose simply exiting. */
2296 if (*result_count
<= 0)
2300 warning (_("RMT ERROR : failed to get remote thread list."));
2303 return result
; /* break; */
2305 if (*result_count
> result_limit
)
2308 warning (_("RMT ERROR: threadlist response longer than requested."));
2314 /* This is the interface between remote and threads, remotes upper
2317 /* remote_find_new_threads retrieves the thread list and for each
2318 thread in the list, looks up the thread in GDB's internal list,
2319 adding the thread if it does not already exist. This involves
2320 getting partial thread lists from the remote target so, polling the
2321 quit_flag is required. */
2324 /* About this many threadisds fit in a packet. */
2326 #define MAXTHREADLISTRESULTS 32
2329 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2332 int done
, i
, result_count
;
2336 static threadref nextthread
;
2337 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2342 if (loopcount
++ > looplimit
)
2345 warning (_("Remote fetch threadlist -infinite loop-."));
2348 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2349 &done
, &result_count
, resultthreadlist
))
2354 /* Clear for later iterations. */
2356 /* Setup to resume next batch of thread references, set nextthread. */
2357 if (result_count
>= 1)
2358 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2360 while (result_count
--)
2361 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2368 remote_newthread_step (threadref
*ref
, void *context
)
2370 int pid
= ptid_get_pid (inferior_ptid
);
2371 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2373 if (!in_thread_list (ptid
))
2375 return 1; /* continue iterator */
2378 #define CRAZY_MAX_THREADS 1000
2381 remote_current_thread (ptid_t oldpid
)
2383 struct remote_state
*rs
= get_remote_state ();
2386 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2387 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2388 return read_ptid (&rs
->buf
[2], NULL
);
2393 /* Find new threads for info threads command.
2394 * Original version, using John Metzler's thread protocol.
2398 remote_find_new_threads (void)
2400 remote_threadlist_iterator (remote_newthread_step
, 0,
2404 #if defined(HAVE_LIBEXPAT)
2406 typedef struct thread_item
2412 DEF_VEC_O(thread_item_t
);
2414 struct threads_parsing_context
2416 VEC (thread_item_t
) *items
;
2420 start_thread (struct gdb_xml_parser
*parser
,
2421 const struct gdb_xml_element
*element
,
2422 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2424 struct threads_parsing_context
*data
= user_data
;
2426 struct thread_item item
;
2429 id
= VEC_index (gdb_xml_value_s
, attributes
, 0)->value
;
2430 item
.ptid
= read_ptid (id
, NULL
);
2432 if (VEC_length (gdb_xml_value_s
, attributes
) > 1)
2433 item
.core
= *(ULONGEST
*) VEC_index (gdb_xml_value_s
, attributes
, 1)->value
;
2439 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2443 end_thread (struct gdb_xml_parser
*parser
,
2444 const struct gdb_xml_element
*element
,
2445 void *user_data
, const char *body_text
)
2447 struct threads_parsing_context
*data
= user_data
;
2449 if (body_text
&& *body_text
)
2450 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2453 const struct gdb_xml_attribute thread_attributes
[] = {
2454 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2455 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2456 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2459 const struct gdb_xml_element thread_children
[] = {
2460 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2463 const struct gdb_xml_element threads_children
[] = {
2464 { "thread", thread_attributes
, thread_children
,
2465 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2466 start_thread
, end_thread
},
2467 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2470 const struct gdb_xml_element threads_elements
[] = {
2471 { "threads", NULL
, threads_children
,
2472 GDB_XML_EF_NONE
, NULL
, NULL
},
2473 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2479 * Find all threads for info threads command.
2480 * Uses new thread protocol contributed by Cisco.
2481 * Falls back and attempts to use the older method (above)
2482 * if the target doesn't respond to the new method.
2486 remote_threads_info (struct target_ops
*ops
)
2488 struct remote_state
*rs
= get_remote_state ();
2492 if (remote_desc
== 0) /* paranoia */
2493 error (_("Command can only be used when connected to the remote target."));
2495 #if defined(HAVE_LIBEXPAT)
2496 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2498 char *xml
= target_read_stralloc (¤t_target
,
2499 TARGET_OBJECT_THREADS
, NULL
);
2501 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2504 struct gdb_xml_parser
*parser
;
2505 struct threads_parsing_context context
;
2506 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2509 parser
= gdb_xml_create_parser_and_cleanup (_("threads"),
2513 gdb_xml_use_dtd (parser
, "threads.dtd");
2515 if (gdb_xml_parse (parser
, xml
) == 0)
2518 struct thread_item
*item
;
2520 for (i
= 0; VEC_iterate (thread_item_t
, context
.items
, i
, item
); ++i
)
2522 if (!ptid_equal (item
->ptid
, null_ptid
))
2524 struct private_thread_info
*info
;
2525 /* In non-stop mode, we assume new found threads
2526 are running until proven otherwise with a
2527 stop reply. In all-stop, we can only get
2528 here if all threads are stopped. */
2529 int running
= non_stop
? 1 : 0;
2531 remote_notice_new_inferior (item
->ptid
, running
);
2533 info
= demand_private_info (item
->ptid
);
2534 info
->core
= item
->core
;
2535 info
->extra
= item
->extra
;
2538 xfree (item
->extra
);
2542 VEC_free (thread_item_t
, context
.items
);
2545 do_cleanups (back_to
);
2550 if (use_threadinfo_query
)
2552 putpkt ("qfThreadInfo");
2553 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2555 if (bufp
[0] != '\0') /* q packet recognized */
2557 while (*bufp
++ == 'm') /* reply contains one or more TID */
2561 new_thread
= read_ptid (bufp
, &bufp
);
2562 if (!ptid_equal (new_thread
, null_ptid
))
2564 /* In non-stop mode, we assume new found threads
2565 are running until proven otherwise with a
2566 stop reply. In all-stop, we can only get
2567 here if all threads are stopped. */
2568 int running
= non_stop
? 1 : 0;
2570 remote_notice_new_inferior (new_thread
, running
);
2573 while (*bufp
++ == ','); /* comma-separated list */
2574 putpkt ("qsThreadInfo");
2575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2582 /* Only qfThreadInfo is supported in non-stop mode. */
2586 /* Else fall back to old method based on jmetzler protocol. */
2587 use_threadinfo_query
= 0;
2588 remote_find_new_threads ();
2593 * Collect a descriptive string about the given thread.
2594 * The target may say anything it wants to about the thread
2595 * (typically info about its blocked / runnable state, name, etc.).
2596 * This string will appear in the info threads display.
2598 * Optional: targets are not required to implement this function.
2602 remote_threads_extra_info (struct thread_info
*tp
)
2604 struct remote_state
*rs
= get_remote_state ();
2608 struct gdb_ext_thread_info threadinfo
;
2609 static char display_buf
[100]; /* arbitrary... */
2610 int n
= 0; /* position in display_buf */
2612 if (remote_desc
== 0) /* paranoia */
2613 internal_error (__FILE__
, __LINE__
,
2614 _("remote_threads_extra_info"));
2616 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2617 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2618 /* This is the main thread which was added by GDB. The remote
2619 server doesn't know about it. */
2622 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2624 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2625 if (info
&& info
->private)
2626 return info
->private->extra
;
2631 if (use_threadextra_query
)
2634 char *endb
= rs
->buf
+ get_remote_packet_size ();
2636 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2638 write_ptid (b
, endb
, tp
->ptid
);
2641 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2642 if (rs
->buf
[0] != 0)
2644 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2645 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2646 display_buf
[result
] = '\0';
2651 /* If the above query fails, fall back to the old method. */
2652 use_threadextra_query
= 0;
2653 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2654 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2655 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2656 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2657 if (threadinfo
.active
)
2659 if (*threadinfo
.shortname
)
2660 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2661 " Name: %s,", threadinfo
.shortname
);
2662 if (*threadinfo
.display
)
2663 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2664 " State: %s,", threadinfo
.display
);
2665 if (*threadinfo
.more_display
)
2666 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2667 " Priority: %s", threadinfo
.more_display
);
2671 /* For purely cosmetic reasons, clear up trailing commas. */
2672 if (',' == display_buf
[n
-1])
2673 display_buf
[n
-1] = ' ';
2681 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2684 remote_get_ada_task_ptid (long lwp
, long thread
)
2686 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2690 /* Restart the remote side; this is an extended protocol operation. */
2693 extended_remote_restart (void)
2695 struct remote_state
*rs
= get_remote_state ();
2697 /* Send the restart command; for reasons I don't understand the
2698 remote side really expects a number after the "R". */
2699 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2702 remote_fileio_reset ();
2705 /* Clean up connection to a remote debugger. */
2708 remote_close (int quitting
)
2710 if (remote_desc
== NULL
)
2711 return; /* already closed */
2713 /* Make sure we leave stdin registered in the event loop, and we
2714 don't leave the async SIGINT signal handler installed. */
2715 remote_terminal_ours ();
2717 serial_close (remote_desc
);
2720 /* We don't have a connection to the remote stub anymore. Get rid
2721 of all the inferiors and their threads we were controlling. */
2722 discard_all_inferiors ();
2724 /* We're no longer interested in any of these events. */
2725 discard_pending_stop_replies (-1);
2727 if (remote_async_inferior_event_token
)
2728 delete_async_event_handler (&remote_async_inferior_event_token
);
2729 if (remote_async_get_pending_events_token
)
2730 delete_async_event_handler (&remote_async_get_pending_events_token
);
2733 /* Query the remote side for the text, data and bss offsets. */
2738 struct remote_state
*rs
= get_remote_state ();
2741 int lose
, num_segments
= 0, do_sections
, do_segments
;
2742 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2743 struct section_offsets
*offs
;
2744 struct symfile_segment_data
*data
;
2746 if (symfile_objfile
== NULL
)
2749 putpkt ("qOffsets");
2750 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2753 if (buf
[0] == '\000')
2754 return; /* Return silently. Stub doesn't support
2758 warning (_("Remote failure reply: %s"), buf
);
2762 /* Pick up each field in turn. This used to be done with scanf, but
2763 scanf will make trouble if CORE_ADDR size doesn't match
2764 conversion directives correctly. The following code will work
2765 with any size of CORE_ADDR. */
2766 text_addr
= data_addr
= bss_addr
= 0;
2770 if (strncmp (ptr
, "Text=", 5) == 0)
2773 /* Don't use strtol, could lose on big values. */
2774 while (*ptr
&& *ptr
!= ';')
2775 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2777 if (strncmp (ptr
, ";Data=", 6) == 0)
2780 while (*ptr
&& *ptr
!= ';')
2781 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2786 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2789 while (*ptr
&& *ptr
!= ';')
2790 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2792 if (bss_addr
!= data_addr
)
2793 warning (_("Target reported unsupported offsets: %s"), buf
);
2798 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2801 /* Don't use strtol, could lose on big values. */
2802 while (*ptr
&& *ptr
!= ';')
2803 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2806 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2809 while (*ptr
&& *ptr
!= ';')
2810 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2818 error (_("Malformed response to offset query, %s"), buf
);
2819 else if (*ptr
!= '\0')
2820 warning (_("Target reported unsupported offsets: %s"), buf
);
2822 offs
= ((struct section_offsets
*)
2823 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2824 memcpy (offs
, symfile_objfile
->section_offsets
,
2825 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2827 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2828 do_segments
= (data
!= NULL
);
2829 do_sections
= num_segments
== 0;
2831 if (num_segments
> 0)
2833 segments
[0] = text_addr
;
2834 segments
[1] = data_addr
;
2836 /* If we have two segments, we can still try to relocate everything
2837 by assuming that the .text and .data offsets apply to the whole
2838 text and data segments. Convert the offsets given in the packet
2839 to base addresses for symfile_map_offsets_to_segments. */
2840 else if (data
&& data
->num_segments
== 2)
2842 segments
[0] = data
->segment_bases
[0] + text_addr
;
2843 segments
[1] = data
->segment_bases
[1] + data_addr
;
2846 /* If the object file has only one segment, assume that it is text
2847 rather than data; main programs with no writable data are rare,
2848 but programs with no code are useless. Of course the code might
2849 have ended up in the data segment... to detect that we would need
2850 the permissions here. */
2851 else if (data
&& data
->num_segments
== 1)
2853 segments
[0] = data
->segment_bases
[0] + text_addr
;
2856 /* There's no way to relocate by segment. */
2862 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2863 offs
, num_segments
, segments
);
2865 if (ret
== 0 && !do_sections
)
2866 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2873 free_symfile_segment_data (data
);
2877 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2879 /* This is a temporary kludge to force data and bss to use the same offsets
2880 because that's what nlmconv does now. The real solution requires changes
2881 to the stub and remote.c that I don't have time to do right now. */
2883 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2884 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2887 objfile_relocate (symfile_objfile
, offs
);
2890 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
2891 threads we know are stopped already. This is used during the
2892 initial remote connection in non-stop mode --- threads that are
2893 reported as already being stopped are left stopped. */
2896 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
2898 /* If we have a stop reply for this thread, it must be stopped. */
2899 if (peek_stop_reply (thread
->ptid
))
2900 set_stop_requested (thread
->ptid
, 1);
2905 /* Stub for catch_exception. */
2907 struct start_remote_args
2911 /* The current target. */
2912 struct target_ops
*target
;
2914 /* Non-zero if this is an extended-remote target. */
2918 /* Send interrupt_sequence to remote target. */
2920 send_interrupt_sequence ()
2922 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
2923 serial_write (remote_desc
, "\x03", 1);
2924 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
2925 serial_send_break (remote_desc
);
2926 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
2928 serial_send_break (remote_desc
);
2929 serial_write (remote_desc
, "g", 1);
2932 internal_error (__FILE__
, __LINE__
,
2933 _("Invalid value for interrupt_sequence_mode: %s."),
2934 interrupt_sequence_mode
);
2938 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2940 struct start_remote_args
*args
= opaque
;
2941 struct remote_state
*rs
= get_remote_state ();
2942 struct packet_config
*noack_config
;
2943 char *wait_status
= NULL
;
2945 immediate_quit
++; /* Allow user to interrupt it. */
2947 /* Ack any packet which the remote side has already sent. */
2948 serial_write (remote_desc
, "+", 1);
2950 if (interrupt_on_connect
)
2951 send_interrupt_sequence ();
2953 /* The first packet we send to the target is the optional "supported
2954 packets" request. If the target can answer this, it will tell us
2955 which later probes to skip. */
2956 remote_query_supported ();
2958 /* Next, we possibly activate noack mode.
2960 If the QStartNoAckMode packet configuration is set to AUTO,
2961 enable noack mode if the stub reported a wish for it with
2964 If set to TRUE, then enable noack mode even if the stub didn't
2965 report it in qSupported. If the stub doesn't reply OK, the
2966 session ends with an error.
2968 If FALSE, then don't activate noack mode, regardless of what the
2969 stub claimed should be the default with qSupported. */
2971 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2973 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2974 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2975 && noack_config
->support
== PACKET_ENABLE
))
2977 putpkt ("QStartNoAckMode");
2978 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2979 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2983 if (args
->extended_p
)
2985 /* Tell the remote that we are using the extended protocol. */
2987 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2990 /* Next, if the target can specify a description, read it. We do
2991 this before anything involving memory or registers. */
2992 target_find_description ();
2994 /* Next, now that we know something about the target, update the
2995 address spaces in the program spaces. */
2996 update_address_spaces ();
2998 /* On OSs where the list of libraries is global to all
2999 processes, we fetch them early. */
3000 if (gdbarch_has_global_solist (target_gdbarch
))
3001 solib_add (NULL
, args
->from_tty
, args
->target
, auto_solib_add
);
3005 if (!rs
->non_stop_aware
)
3006 error (_("Non-stop mode requested, but remote does not support non-stop"));
3008 putpkt ("QNonStop:1");
3009 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3011 if (strcmp (rs
->buf
, "OK") != 0)
3012 error ("Remote refused setting non-stop mode with: %s", rs
->buf
);
3014 /* Find about threads and processes the stub is already
3015 controlling. We default to adding them in the running state.
3016 The '?' query below will then tell us about which threads are
3018 remote_threads_info (args
->target
);
3020 else if (rs
->non_stop_aware
)
3022 /* Don't assume that the stub can operate in all-stop mode.
3023 Request it explicitely. */
3024 putpkt ("QNonStop:0");
3025 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3027 if (strcmp (rs
->buf
, "OK") != 0)
3028 error ("Remote refused setting all-stop mode with: %s", rs
->buf
);
3031 /* Check whether the target is running now. */
3033 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3037 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3039 if (!args
->extended_p
)
3040 error (_("The target is not running (try extended-remote?)"));
3042 /* We're connected, but not running. Drop out before we
3043 call start_remote. */
3048 /* Save the reply for later. */
3049 wait_status
= alloca (strlen (rs
->buf
) + 1);
3050 strcpy (wait_status
, rs
->buf
);
3053 /* Let the stub know that we want it to return the thread. */
3054 set_continue_thread (minus_one_ptid
);
3056 /* Without this, some commands which require an active target
3057 (such as kill) won't work. This variable serves (at least)
3058 double duty as both the pid of the target process (if it has
3059 such), and as a flag indicating that a target is active.
3060 These functions should be split out into seperate variables,
3061 especially since GDB will someday have a notion of debugging
3062 several processes. */
3063 inferior_ptid
= magic_null_ptid
;
3065 /* Now, if we have thread information, update inferior_ptid. */
3066 inferior_ptid
= remote_current_thread (inferior_ptid
);
3068 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3070 /* Always add the main thread. */
3071 add_thread_silent (inferior_ptid
);
3073 get_offsets (); /* Get text, data & bss offsets. */
3075 /* If we could not find a description using qXfer, and we know
3076 how to do it some other way, try again. This is not
3077 supported for non-stop; it could be, but it is tricky if
3078 there are no stopped threads when we connect. */
3079 if (remote_read_description_p (args
->target
)
3080 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3082 target_clear_description ();
3083 target_find_description ();
3086 /* Use the previously fetched status. */
3087 gdb_assert (wait_status
!= NULL
);
3088 strcpy (rs
->buf
, wait_status
);
3089 rs
->cached_wait_status
= 1;
3092 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
3096 /* Clear WFI global state. Do this before finding about new
3097 threads and inferiors, and setting the current inferior.
3098 Otherwise we would clear the proceed status of the current
3099 inferior when we want its stop_soon state to be preserved
3100 (see notice_new_inferior). */
3101 init_wait_for_inferior ();
3103 /* In non-stop, we will either get an "OK", meaning that there
3104 are no stopped threads at this time; or, a regular stop
3105 reply. In the latter case, there may be more than one thread
3106 stopped --- we pull them all out using the vStopped
3108 if (strcmp (rs
->buf
, "OK") != 0)
3110 struct stop_reply
*stop_reply
;
3111 struct cleanup
*old_chain
;
3113 stop_reply
= stop_reply_xmalloc ();
3114 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3116 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3117 discard_cleanups (old_chain
);
3119 /* get_pending_stop_replies acks this one, and gets the rest
3121 pending_stop_reply
= stop_reply
;
3122 remote_get_pending_stop_replies ();
3124 /* Make sure that threads that were stopped remain
3126 iterate_over_threads (set_stop_requested_callback
, NULL
);
3129 if (target_can_async_p ())
3130 target_async (inferior_event_handler
, 0);
3132 if (thread_count () == 0)
3134 if (!args
->extended_p
)
3135 error (_("The target is not running (try extended-remote?)"));
3137 /* We're connected, but not running. Drop out before we
3138 call start_remote. */
3142 /* Let the stub know that we want it to return the thread. */
3144 /* Force the stub to choose a thread. */
3145 set_general_thread (null_ptid
);
3148 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3149 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3150 error (_("remote didn't report the current thread in non-stop mode"));
3152 get_offsets (); /* Get text, data & bss offsets. */
3154 /* In non-stop mode, any cached wait status will be stored in
3155 the stop reply queue. */
3156 gdb_assert (wait_status
== NULL
);
3159 /* If we connected to a live target, do some additional setup. */
3160 if (target_has_execution
)
3162 if (exec_bfd
) /* No use without an exec file. */
3163 remote_check_symbols (symfile_objfile
);
3166 /* Possibly the target has been engaged in a trace run started
3167 previously; find out where things are at. */
3168 if (remote_get_trace_status (current_trace_status ()) != -1)
3170 struct uploaded_tp
*uploaded_tps
= NULL
;
3171 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3173 if (current_trace_status ()->running
)
3174 printf_filtered (_("Trace is already running on the target.\n"));
3176 /* Get trace state variables first, they may be checked when
3177 parsing uploaded commands. */
3179 remote_upload_trace_state_variables (&uploaded_tsvs
);
3181 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3183 remote_upload_tracepoints (&uploaded_tps
);
3185 merge_uploaded_tracepoints (&uploaded_tps
);
3188 /* If breakpoints are global, insert them now. */
3189 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3190 && breakpoints_always_inserted_mode ())
3191 insert_breakpoints ();
3194 /* Open a connection to a remote debugger.
3195 NAME is the filename used for communication. */
3198 remote_open (char *name
, int from_tty
)
3200 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3203 /* Open a connection to a remote debugger using the extended
3204 remote gdb protocol. NAME is the filename used for communication. */
3207 extended_remote_open (char *name
, int from_tty
)
3209 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3212 /* Generic code for opening a connection to a remote target. */
3215 init_all_packet_configs (void)
3218 for (i
= 0; i
< PACKET_MAX
; i
++)
3219 update_packet_config (&remote_protocol_packets
[i
]);
3222 /* Symbol look-up. */
3225 remote_check_symbols (struct objfile
*objfile
)
3227 struct remote_state
*rs
= get_remote_state ();
3228 char *msg
, *reply
, *tmp
;
3229 struct minimal_symbol
*sym
;
3232 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3235 /* Make sure the remote is pointing at the right process. */
3236 set_general_process ();
3238 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3239 because we need both at the same time. */
3240 msg
= alloca (get_remote_packet_size ());
3242 /* Invite target to request symbol lookups. */
3244 putpkt ("qSymbol::");
3245 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3246 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3249 while (strncmp (reply
, "qSymbol:", 8) == 0)
3252 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3254 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3256 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3259 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3260 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3262 /* If this is a function address, return the start of code
3263 instead of any data function descriptor. */
3264 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3268 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3269 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3273 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3278 static struct serial
*
3279 remote_serial_open (char *name
)
3281 static int udp_warning
= 0;
3283 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3284 of in ser-tcp.c, because it is the remote protocol assuming that the
3285 serial connection is reliable and not the serial connection promising
3287 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3290 The remote protocol may be unreliable over UDP.\n\
3291 Some events may be lost, rendering further debugging impossible."));
3295 return serial_open (name
);
3298 /* This type describes each known response to the qSupported
3300 struct protocol_feature
3302 /* The name of this protocol feature. */
3305 /* The default for this protocol feature. */
3306 enum packet_support default_support
;
3308 /* The function to call when this feature is reported, or after
3309 qSupported processing if the feature is not supported.
3310 The first argument points to this structure. The second
3311 argument indicates whether the packet requested support be
3312 enabled, disabled, or probed (or the default, if this function
3313 is being called at the end of processing and this feature was
3314 not reported). The third argument may be NULL; if not NULL, it
3315 is a NUL-terminated string taken from the packet following
3316 this feature's name and an equals sign. */
3317 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3320 /* The corresponding packet for this feature. Only used if
3321 FUNC is remote_supported_packet. */
3326 remote_supported_packet (const struct protocol_feature
*feature
,
3327 enum packet_support support
,
3328 const char *argument
)
3332 warning (_("Remote qSupported response supplied an unexpected value for"
3333 " \"%s\"."), feature
->name
);
3337 if (remote_protocol_packets
[feature
->packet
].support
3338 == PACKET_SUPPORT_UNKNOWN
)
3339 remote_protocol_packets
[feature
->packet
].support
= support
;
3343 remote_packet_size (const struct protocol_feature
*feature
,
3344 enum packet_support support
, const char *value
)
3346 struct remote_state
*rs
= get_remote_state ();
3351 if (support
!= PACKET_ENABLE
)
3354 if (value
== NULL
|| *value
== '\0')
3356 warning (_("Remote target reported \"%s\" without a size."),
3362 packet_size
= strtol (value
, &value_end
, 16);
3363 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3365 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3366 feature
->name
, value
);
3370 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3372 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3373 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3374 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3377 /* Record the new maximum packet size. */
3378 rs
->explicit_packet_size
= packet_size
;
3382 remote_multi_process_feature (const struct protocol_feature
*feature
,
3383 enum packet_support support
, const char *value
)
3385 struct remote_state
*rs
= get_remote_state ();
3386 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3390 remote_non_stop_feature (const struct protocol_feature
*feature
,
3391 enum packet_support support
, const char *value
)
3393 struct remote_state
*rs
= get_remote_state ();
3394 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3398 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3399 enum packet_support support
,
3402 struct remote_state
*rs
= get_remote_state ();
3403 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3407 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3408 enum packet_support support
,
3411 struct remote_state
*rs
= get_remote_state ();
3412 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3416 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3417 enum packet_support support
,
3420 struct remote_state
*rs
= get_remote_state ();
3421 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3424 static struct protocol_feature remote_protocol_features
[] = {
3425 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3426 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3427 PACKET_qXfer_auxv
},
3428 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3429 PACKET_qXfer_features
},
3430 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3431 PACKET_qXfer_libraries
},
3432 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3433 PACKET_qXfer_memory_map
},
3434 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3435 PACKET_qXfer_spu_read
},
3436 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3437 PACKET_qXfer_spu_write
},
3438 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3439 PACKET_qXfer_osdata
},
3440 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3441 PACKET_qXfer_threads
},
3442 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3443 PACKET_QPassSignals
},
3444 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3445 PACKET_QStartNoAckMode
},
3446 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3447 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3448 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3449 PACKET_qXfer_siginfo_read
},
3450 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3451 PACKET_qXfer_siginfo_write
},
3452 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3453 PACKET_ConditionalTracepoints
},
3454 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3455 PACKET_FastTracepoints
},
3456 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3458 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3460 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3462 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3463 PACKET_TracepointSource
},
3466 static char *remote_support_xml
;
3468 /* Register string appended to "xmlRegisters=" in qSupported query. */
3471 register_remote_support_xml (const char *xml ATTRIBUTE_UNUSED
)
3473 #if defined(HAVE_LIBEXPAT)
3474 if (remote_support_xml
== NULL
)
3475 remote_support_xml
= concat ("xmlRegisters=", xml
, NULL
);
3478 char *copy
= xstrdup (remote_support_xml
+ 13);
3479 char *p
= strtok (copy
, ",");
3483 if (strcmp (p
, xml
) == 0)
3490 while ((p
= strtok (NULL
, ",")) != NULL
);
3493 p
= concat (remote_support_xml
, ",", xml
, NULL
);
3494 xfree (remote_support_xml
);
3495 remote_support_xml
= p
;
3501 remote_query_supported_append (char *msg
, const char *append
)
3505 char *p
= concat (msg
, ";", append
, NULL
);
3510 return xstrdup (append
);
3514 remote_query_supported (void)
3516 struct remote_state
*rs
= get_remote_state ();
3519 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3521 /* The packet support flags are handled differently for this packet
3522 than for most others. We treat an error, a disabled packet, and
3523 an empty response identically: any features which must be reported
3524 to be used will be automatically disabled. An empty buffer
3525 accomplishes this, since that is also the representation for a list
3526 containing no features. */
3529 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3532 const char *qsupported
= gdbarch_qsupported (target_gdbarch
);
3535 q
= remote_query_supported_append (q
, "multiprocess+");
3538 q
= remote_query_supported_append (q
, qsupported
);
3540 if (remote_support_xml
)
3541 q
= remote_query_supported_append (q
, remote_support_xml
);
3545 char *p
= concat ("qSupported:", q
, NULL
);
3551 putpkt ("qSupported");
3553 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3555 /* If an error occured, warn, but do not return - just reset the
3556 buffer to empty and go on to disable features. */
3557 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3560 warning (_("Remote failure reply: %s"), rs
->buf
);
3565 memset (seen
, 0, sizeof (seen
));
3570 enum packet_support is_supported
;
3571 char *p
, *end
, *name_end
, *value
;
3573 /* First separate out this item from the rest of the packet. If
3574 there's another item after this, we overwrite the separator
3575 (terminated strings are much easier to work with). */
3577 end
= strchr (p
, ';');
3580 end
= p
+ strlen (p
);
3590 warning (_("empty item in \"qSupported\" response"));
3595 name_end
= strchr (p
, '=');
3598 /* This is a name=value entry. */
3599 is_supported
= PACKET_ENABLE
;
3600 value
= name_end
+ 1;
3609 is_supported
= PACKET_ENABLE
;
3613 is_supported
= PACKET_DISABLE
;
3617 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3621 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
3627 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3628 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3630 const struct protocol_feature
*feature
;
3633 feature
= &remote_protocol_features
[i
];
3634 feature
->func (feature
, is_supported
, value
);
3639 /* If we increased the packet size, make sure to increase the global
3640 buffer size also. We delay this until after parsing the entire
3641 qSupported packet, because this is the same buffer we were
3643 if (rs
->buf_size
< rs
->explicit_packet_size
)
3645 rs
->buf_size
= rs
->explicit_packet_size
;
3646 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3649 /* Handle the defaults for unmentioned features. */
3650 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3653 const struct protocol_feature
*feature
;
3655 feature
= &remote_protocol_features
[i
];
3656 feature
->func (feature
, feature
->default_support
, NULL
);
3662 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
3664 struct remote_state
*rs
= get_remote_state ();
3667 error (_("To open a remote debug connection, you need to specify what\n"
3668 "serial device is attached to the remote system\n"
3669 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3671 /* See FIXME above. */
3672 if (!target_async_permitted
)
3673 wait_forever_enabled_p
= 1;
3675 /* If we're connected to a running target, target_preopen will kill it.
3676 But if we're connected to a target system with no running process,
3677 then we will still be connected when it returns. Ask this question
3678 first, before target_preopen has a chance to kill anything. */
3679 if (remote_desc
!= NULL
&& !have_inferiors ())
3682 || query (_("Already connected to a remote target. Disconnect? ")))
3685 error (_("Still connected."));
3688 target_preopen (from_tty
);
3690 unpush_target (target
);
3692 /* This time without a query. If we were connected to an
3693 extended-remote target and target_preopen killed the running
3694 process, we may still be connected. If we are starting "target
3695 remote" now, the extended-remote target will not have been
3696 removed by unpush_target. */
3697 if (remote_desc
!= NULL
&& !have_inferiors ())
3700 /* Make sure we send the passed signals list the next time we resume. */
3701 xfree (last_pass_packet
);
3702 last_pass_packet
= NULL
;
3704 remote_fileio_reset ();
3705 reopen_exec_file ();
3708 remote_desc
= remote_serial_open (name
);
3710 perror_with_name (name
);
3712 if (baud_rate
!= -1)
3714 if (serial_setbaudrate (remote_desc
, baud_rate
))
3716 /* The requested speed could not be set. Error out to
3717 top level after closing remote_desc. Take care to
3718 set remote_desc to NULL to avoid closing remote_desc
3720 serial_close (remote_desc
);
3722 perror_with_name (name
);
3726 serial_raw (remote_desc
);
3728 /* If there is something sitting in the buffer we might take it as a
3729 response to a command, which would be bad. */
3730 serial_flush_input (remote_desc
);
3734 puts_filtered ("Remote debugging using ");
3735 puts_filtered (name
);
3736 puts_filtered ("\n");
3738 push_target (target
); /* Switch to using remote target now. */
3740 /* Register extra event sources in the event loop. */
3741 remote_async_inferior_event_token
3742 = create_async_event_handler (remote_async_inferior_event_handler
,
3744 remote_async_get_pending_events_token
3745 = create_async_event_handler (remote_async_get_pending_events_handler
,
3748 /* Reset the target state; these things will be queried either by
3749 remote_query_supported or as they are needed. */
3750 init_all_packet_configs ();
3751 rs
->cached_wait_status
= 0;
3752 rs
->explicit_packet_size
= 0;
3754 rs
->multi_process_aware
= 0;
3755 rs
->extended
= extended_p
;
3756 rs
->non_stop_aware
= 0;
3757 rs
->waiting_for_stop_reply
= 0;
3758 rs
->ctrlc_pending_p
= 0;
3760 general_thread
= not_sent_ptid
;
3761 continue_thread
= not_sent_ptid
;
3763 /* Probe for ability to use "ThreadInfo" query, as required. */
3764 use_threadinfo_query
= 1;
3765 use_threadextra_query
= 1;
3767 if (target_async_permitted
)
3769 /* With this target we start out by owning the terminal. */
3770 remote_async_terminal_ours_p
= 1;
3772 /* FIXME: cagney/1999-09-23: During the initial connection it is
3773 assumed that the target is already ready and able to respond to
3774 requests. Unfortunately remote_start_remote() eventually calls
3775 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
3776 around this. Eventually a mechanism that allows
3777 wait_for_inferior() to expect/get timeouts will be
3779 wait_forever_enabled_p
= 0;
3782 /* First delete any symbols previously loaded from shared libraries. */
3783 no_shared_libraries (NULL
, 0);
3786 init_thread_list ();
3788 /* Start the remote connection. If error() or QUIT, discard this
3789 target (we'd otherwise be in an inconsistent state) and then
3790 propogate the error on up the exception chain. This ensures that
3791 the caller doesn't stumble along blindly assuming that the
3792 function succeeded. The CLI doesn't have this problem but other
3793 UI's, such as MI do.
3795 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
3796 this function should return an error indication letting the
3797 caller restore the previous state. Unfortunately the command
3798 ``target remote'' is directly wired to this function making that
3799 impossible. On a positive note, the CLI side of this problem has
3800 been fixed - the function set_cmd_context() makes it possible for
3801 all the ``target ....'' commands to share a common callback
3802 function. See cli-dump.c. */
3804 struct gdb_exception ex
;
3805 struct start_remote_args args
;
3807 args
.from_tty
= from_tty
;
3808 args
.target
= target
;
3809 args
.extended_p
= extended_p
;
3811 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
3814 /* Pop the partially set up target - unless something else did
3815 already before throwing the exception. */
3816 if (remote_desc
!= NULL
)
3818 if (target_async_permitted
)
3819 wait_forever_enabled_p
= 1;
3820 throw_exception (ex
);
3824 if (target_async_permitted
)
3825 wait_forever_enabled_p
= 1;
3828 /* This takes a program previously attached to and detaches it. After
3829 this is done, GDB can be used to debug some other program. We
3830 better not have left any breakpoints in the target program or it'll
3831 die when it hits one. */
3834 remote_detach_1 (char *args
, int from_tty
, int extended
)
3836 int pid
= ptid_get_pid (inferior_ptid
);
3837 struct remote_state
*rs
= get_remote_state ();
3840 error (_("Argument given to \"detach\" when remotely debugging."));
3842 if (!target_has_execution
)
3843 error (_("No process to detach from."));
3845 /* Tell the remote target to detach. */
3846 if (remote_multi_process_p (rs
))
3847 sprintf (rs
->buf
, "D;%x", pid
);
3849 strcpy (rs
->buf
, "D");
3852 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3854 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3856 else if (rs
->buf
[0] == '\0')
3857 error (_("Remote doesn't know how to detach"));
3859 error (_("Can't detach process."));
3863 if (remote_multi_process_p (rs
))
3864 printf_filtered (_("Detached from remote %s.\n"),
3865 target_pid_to_str (pid_to_ptid (pid
)));
3869 puts_filtered (_("Detached from remote process.\n"));
3871 puts_filtered (_("Ending remote debugging.\n"));
3875 discard_pending_stop_replies (pid
);
3876 target_mourn_inferior ();
3880 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3882 remote_detach_1 (args
, from_tty
, 0);
3886 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3888 remote_detach_1 (args
, from_tty
, 1);
3891 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3894 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3897 error (_("Argument given to \"disconnect\" when remotely debugging."));
3899 /* Make sure we unpush even the extended remote targets; mourn
3900 won't do it. So call remote_mourn_1 directly instead of
3901 target_mourn_inferior. */
3902 remote_mourn_1 (target
);
3905 puts_filtered ("Ending remote debugging.\n");
3908 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3909 be chatty about it. */
3912 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3914 struct remote_state
*rs
= get_remote_state ();
3916 char *wait_status
= NULL
;
3918 pid
= parse_pid_to_attach (args
);
3920 /* Remote PID can be freely equal to getpid, do not check it here the same
3921 way as in other targets. */
3923 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3924 error (_("This target does not support attaching to a process"));
3926 sprintf (rs
->buf
, "vAttach;%x", pid
);
3928 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3930 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3933 printf_unfiltered (_("Attached to %s\n"),
3934 target_pid_to_str (pid_to_ptid (pid
)));
3938 /* Save the reply for later. */
3939 wait_status
= alloca (strlen (rs
->buf
) + 1);
3940 strcpy (wait_status
, rs
->buf
);
3942 else if (strcmp (rs
->buf
, "OK") != 0)
3943 error (_("Attaching to %s failed with: %s"),
3944 target_pid_to_str (pid_to_ptid (pid
)),
3947 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3948 error (_("This target does not support attaching to a process"));
3950 error (_("Attaching to %s failed"),
3951 target_pid_to_str (pid_to_ptid (pid
)));
3953 set_current_inferior (remote_add_inferior (pid
, 1));
3955 inferior_ptid
= pid_to_ptid (pid
);
3959 struct thread_info
*thread
;
3961 /* Get list of threads. */
3962 remote_threads_info (target
);
3964 thread
= first_thread_of_process (pid
);
3966 inferior_ptid
= thread
->ptid
;
3968 inferior_ptid
= pid_to_ptid (pid
);
3970 /* Invalidate our notion of the remote current thread. */
3971 record_currthread (minus_one_ptid
);
3975 /* Now, if we have thread information, update inferior_ptid. */
3976 inferior_ptid
= remote_current_thread (inferior_ptid
);
3978 /* Add the main thread to the thread list. */
3979 add_thread_silent (inferior_ptid
);
3982 /* Next, if the target can specify a description, read it. We do
3983 this before anything involving memory or registers. */
3984 target_find_description ();
3988 /* Use the previously fetched status. */
3989 gdb_assert (wait_status
!= NULL
);
3991 if (target_can_async_p ())
3993 struct stop_reply
*stop_reply
;
3994 struct cleanup
*old_chain
;
3996 stop_reply
= stop_reply_xmalloc ();
3997 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3998 remote_parse_stop_reply (wait_status
, stop_reply
);
3999 discard_cleanups (old_chain
);
4000 push_stop_reply (stop_reply
);
4002 target_async (inferior_event_handler
, 0);
4006 gdb_assert (wait_status
!= NULL
);
4007 strcpy (rs
->buf
, wait_status
);
4008 rs
->cached_wait_status
= 1;
4012 gdb_assert (wait_status
== NULL
);
4016 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4018 extended_remote_attach_1 (ops
, args
, from_tty
);
4021 /* Convert hex digit A to a number. */
4026 if (a
>= '0' && a
<= '9')
4028 else if (a
>= 'a' && a
<= 'f')
4029 return a
- 'a' + 10;
4030 else if (a
>= 'A' && a
<= 'F')
4031 return a
- 'A' + 10;
4033 error (_("Reply contains invalid hex digit %d"), a
);
4037 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4041 for (i
= 0; i
< count
; i
++)
4043 if (hex
[0] == 0 || hex
[1] == 0)
4045 /* Hex string is short, or of uneven length.
4046 Return the count that has been converted so far. */
4049 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4055 /* Convert number NIB to a hex digit. */
4063 return 'a' + nib
- 10;
4067 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4070 /* May use a length, or a nul-terminated string as input. */
4072 count
= strlen ((char *) bin
);
4074 for (i
= 0; i
< count
; i
++)
4076 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4077 *hex
++ = tohex (*bin
++ & 0xf);
4083 /* Check for the availability of vCont. This function should also check
4087 remote_vcont_probe (struct remote_state
*rs
)
4091 strcpy (rs
->buf
, "vCont?");
4093 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4096 /* Make sure that the features we assume are supported. */
4097 if (strncmp (buf
, "vCont", 5) == 0)
4100 int support_s
, support_S
, support_c
, support_C
;
4106 rs
->support_vCont_t
= 0;
4107 while (p
&& *p
== ';')
4110 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4112 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4114 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4116 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4118 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4119 rs
->support_vCont_t
= 1;
4121 p
= strchr (p
, ';');
4124 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4125 BUF will make packet_ok disable the packet. */
4126 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4130 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4133 /* Helper function for building "vCont" resumptions. Write a
4134 resumption to P. ENDP points to one-passed-the-end of the buffer
4135 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4136 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4137 resumed thread should be single-stepped and/or signalled. If PTID
4138 equals minus_one_ptid, then all threads are resumed; if PTID
4139 represents a process, then all threads of the process are resumed;
4140 the thread to be stepped and/or signalled is given in the global
4144 append_resumption (char *p
, char *endp
,
4145 ptid_t ptid
, int step
, enum target_signal siggnal
)
4147 struct remote_state
*rs
= get_remote_state ();
4149 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4150 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4152 p
+= xsnprintf (p
, endp
- p
, ";s");
4153 else if (siggnal
!= TARGET_SIGNAL_0
)
4154 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4156 p
+= xsnprintf (p
, endp
- p
, ";c");
4158 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4162 /* All (-1) threads of process. */
4163 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4165 p
+= xsnprintf (p
, endp
- p
, ":");
4166 p
= write_ptid (p
, endp
, nptid
);
4168 else if (!ptid_equal (ptid
, minus_one_ptid
))
4170 p
+= xsnprintf (p
, endp
- p
, ":");
4171 p
= write_ptid (p
, endp
, ptid
);
4177 /* Resume the remote inferior by using a "vCont" packet. The thread
4178 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4179 resumed thread should be single-stepped and/or signalled. If PTID
4180 equals minus_one_ptid, then all threads are resumed; the thread to
4181 be stepped and/or signalled is given in the global INFERIOR_PTID.
4182 This function returns non-zero iff it resumes the inferior.
4184 This function issues a strict subset of all possible vCont commands at the
4188 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4190 struct remote_state
*rs
= get_remote_state ();
4194 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4195 remote_vcont_probe (rs
);
4197 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4201 endp
= rs
->buf
+ get_remote_packet_size ();
4203 /* If we could generate a wider range of packets, we'd have to worry
4204 about overflowing BUF. Should there be a generic
4205 "multi-part-packet" packet? */
4207 p
+= xsnprintf (p
, endp
- p
, "vCont");
4209 if (ptid_equal (ptid
, magic_null_ptid
))
4211 /* MAGIC_NULL_PTID means that we don't have any active threads,
4212 so we don't have any TID numbers the inferior will
4213 understand. Make sure to only send forms that do not specify
4215 p
= append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4217 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4219 /* Resume all threads (of all processes, or of a single
4220 process), with preference for INFERIOR_PTID. This assumes
4221 inferior_ptid belongs to the set of all threads we are about
4223 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4225 /* Step inferior_ptid, with or without signal. */
4226 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4229 /* And continue others without a signal. */
4230 p
= append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4234 /* Scheduler locking; resume only PTID. */
4235 p
= append_resumption (p
, endp
, ptid
, step
, siggnal
);
4238 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4243 /* In non-stop, the stub replies to vCont with "OK". The stop
4244 reply will be reported asynchronously by means of a `%Stop'
4246 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4247 if (strcmp (rs
->buf
, "OK") != 0)
4248 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4254 /* Tell the remote machine to resume. */
4256 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4258 static int last_sent_step
;
4261 remote_resume (struct target_ops
*ops
,
4262 ptid_t ptid
, int step
, enum target_signal siggnal
)
4264 struct remote_state
*rs
= get_remote_state ();
4267 last_sent_signal
= siggnal
;
4268 last_sent_step
= step
;
4270 /* Update the inferior on signals to silently pass, if they've changed. */
4271 remote_pass_signals ();
4273 /* The vCont packet doesn't need to specify threads via Hc. */
4274 /* No reverse support (yet) for vCont. */
4275 if (execution_direction
!= EXEC_REVERSE
)
4276 if (remote_vcont_resume (ptid
, step
, siggnal
))
4279 /* All other supported resume packets do use Hc, so set the continue
4281 if (ptid_equal (ptid
, minus_one_ptid
))
4282 set_continue_thread (any_thread_ptid
);
4284 set_continue_thread (ptid
);
4287 if (execution_direction
== EXEC_REVERSE
)
4289 /* We don't pass signals to the target in reverse exec mode. */
4290 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4291 warning (" - Can't pass signal %d to target in reverse: ignored.\n",
4295 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4296 error (_("Remote reverse-step not supported."));
4298 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4299 error (_("Remote reverse-continue not supported."));
4301 strcpy (buf
, step
? "bs" : "bc");
4303 else if (siggnal
!= TARGET_SIGNAL_0
)
4305 buf
[0] = step
? 'S' : 'C';
4306 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4307 buf
[2] = tohex (((int) siggnal
) & 0xf);
4311 strcpy (buf
, step
? "s" : "c");
4316 /* We are about to start executing the inferior, let's register it
4317 with the event loop. NOTE: this is the one place where all the
4318 execution commands end up. We could alternatively do this in each
4319 of the execution commands in infcmd.c. */
4320 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4321 into infcmd.c in order to allow inferior function calls to work
4322 NOT asynchronously. */
4323 if (target_can_async_p ())
4324 target_async (inferior_event_handler
, 0);
4326 /* We've just told the target to resume. The remote server will
4327 wait for the inferior to stop, and then send a stop reply. In
4328 the mean time, we can't start another command/query ourselves
4329 because the stub wouldn't be ready to process it. This applies
4330 only to the base all-stop protocol, however. In non-stop (which
4331 only supports vCont), the stub replies with an "OK", and is
4332 immediate able to process further serial input. */
4334 rs
->waiting_for_stop_reply
= 1;
4338 /* Set up the signal handler for SIGINT, while the target is
4339 executing, ovewriting the 'regular' SIGINT signal handler. */
4341 initialize_sigint_signal_handler (void)
4343 signal (SIGINT
, handle_remote_sigint
);
4346 /* Signal handler for SIGINT, while the target is executing. */
4348 handle_remote_sigint (int sig
)
4350 signal (sig
, handle_remote_sigint_twice
);
4351 mark_async_signal_handler_wrapper (sigint_remote_token
);
4354 /* Signal handler for SIGINT, installed after SIGINT has already been
4355 sent once. It will take effect the second time that the user sends
4358 handle_remote_sigint_twice (int sig
)
4360 signal (sig
, handle_remote_sigint
);
4361 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4364 /* Perform the real interruption of the target execution, in response
4367 async_remote_interrupt (gdb_client_data arg
)
4370 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4372 target_stop (inferior_ptid
);
4375 /* Perform interrupt, if the first attempt did not succeed. Just give
4376 up on the target alltogether. */
4378 async_remote_interrupt_twice (gdb_client_data arg
)
4381 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4386 /* Reinstall the usual SIGINT handlers, after the target has
4389 cleanup_sigint_signal_handler (void *dummy
)
4391 signal (SIGINT
, handle_sigint
);
4394 /* Send ^C to target to halt it. Target will respond, and send us a
4396 static void (*ofunc
) (int);
4398 /* The command line interface's stop routine. This function is installed
4399 as a signal handler for SIGINT. The first time a user requests a
4400 stop, we call remote_stop to send a break or ^C. If there is no
4401 response from the target (it didn't stop when the user requested it),
4402 we ask the user if he'd like to detach from the target. */
4404 remote_interrupt (int signo
)
4406 /* If this doesn't work, try more severe steps. */
4407 signal (signo
, remote_interrupt_twice
);
4409 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4412 /* The user typed ^C twice. */
4415 remote_interrupt_twice (int signo
)
4417 signal (signo
, ofunc
);
4418 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4419 signal (signo
, remote_interrupt
);
4422 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4423 thread, all threads of a remote process, or all threads of all
4427 remote_stop_ns (ptid_t ptid
)
4429 struct remote_state
*rs
= get_remote_state ();
4431 char *endp
= rs
->buf
+ get_remote_packet_size ();
4433 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4434 remote_vcont_probe (rs
);
4436 if (!rs
->support_vCont_t
)
4437 error (_("Remote server does not support stopping threads"));
4439 if (ptid_equal (ptid
, minus_one_ptid
)
4440 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4441 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4446 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4448 if (ptid_is_pid (ptid
))
4449 /* All (-1) threads of process. */
4450 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4453 /* Small optimization: if we already have a stop reply for
4454 this thread, no use in telling the stub we want this
4456 if (peek_stop_reply (ptid
))
4462 p
= write_ptid (p
, endp
, nptid
);
4465 /* In non-stop, we get an immediate OK reply. The stop reply will
4466 come in asynchronously by notification. */
4468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4469 if (strcmp (rs
->buf
, "OK") != 0)
4470 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4473 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4474 remote target. It is undefined which thread of which process
4475 reports the stop. */
4478 remote_stop_as (ptid_t ptid
)
4480 struct remote_state
*rs
= get_remote_state ();
4482 rs
->ctrlc_pending_p
= 1;
4484 /* If the inferior is stopped already, but the core didn't know
4485 about it yet, just ignore the request. The cached wait status
4486 will be collected in remote_wait. */
4487 if (rs
->cached_wait_status
)
4490 /* Send interrupt_sequence to remote target. */
4491 send_interrupt_sequence ();
4494 /* This is the generic stop called via the target vector. When a target
4495 interrupt is requested, either by the command line or the GUI, we
4496 will eventually end up here. */
4499 remote_stop (ptid_t ptid
)
4502 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4505 remote_stop_ns (ptid
);
4507 remote_stop_as (ptid
);
4510 /* Ask the user what to do when an interrupt is received. */
4513 interrupt_query (void)
4515 target_terminal_ours ();
4517 if (target_can_async_p ())
4519 signal (SIGINT
, handle_sigint
);
4520 deprecated_throw_reason (RETURN_QUIT
);
4524 if (query (_("Interrupted while waiting for the program.\n\
4525 Give up (and stop debugging it)? ")))
4528 deprecated_throw_reason (RETURN_QUIT
);
4532 target_terminal_inferior ();
4535 /* Enable/disable target terminal ownership. Most targets can use
4536 terminal groups to control terminal ownership. Remote targets are
4537 different in that explicit transfer of ownership to/from GDB/target
4541 remote_terminal_inferior (void)
4543 if (!target_async_permitted
)
4544 /* Nothing to do. */
4547 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4548 idempotent. The event-loop GDB talking to an asynchronous target
4549 with a synchronous command calls this function from both
4550 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4551 transfer the terminal to the target when it shouldn't this guard
4553 if (!remote_async_terminal_ours_p
)
4555 delete_file_handler (input_fd
);
4556 remote_async_terminal_ours_p
= 0;
4557 initialize_sigint_signal_handler ();
4558 /* NOTE: At this point we could also register our selves as the
4559 recipient of all input. Any characters typed could then be
4560 passed on down to the target. */
4564 remote_terminal_ours (void)
4566 if (!target_async_permitted
)
4567 /* Nothing to do. */
4570 /* See FIXME in remote_terminal_inferior. */
4571 if (remote_async_terminal_ours_p
)
4573 cleanup_sigint_signal_handler (NULL
);
4574 add_file_handler (input_fd
, stdin_event_handler
, 0);
4575 remote_async_terminal_ours_p
= 1;
4579 remote_console_output (char *msg
)
4583 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4586 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4589 fputs_unfiltered (tb
, gdb_stdtarg
);
4591 gdb_flush (gdb_stdtarg
);
4594 typedef struct cached_reg
4597 gdb_byte data
[MAX_REGISTER_SIZE
];
4600 DEF_VEC_O(cached_reg_t
);
4604 struct stop_reply
*next
;
4608 struct target_waitstatus ws
;
4610 VEC(cached_reg_t
) *regcache
;
4612 int stopped_by_watchpoint_p
;
4613 CORE_ADDR watch_data_address
;
4621 /* The list of already fetched and acknowledged stop events. */
4622 static struct stop_reply
*stop_reply_queue
;
4624 static struct stop_reply
*
4625 stop_reply_xmalloc (void)
4627 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4633 stop_reply_xfree (struct stop_reply
*r
)
4637 VEC_free (cached_reg_t
, r
->regcache
);
4642 /* Discard all pending stop replies of inferior PID. If PID is -1,
4643 discard everything. */
4646 discard_pending_stop_replies (int pid
)
4648 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4650 /* Discard the in-flight notification. */
4651 if (pending_stop_reply
!= NULL
4653 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4655 stop_reply_xfree (pending_stop_reply
);
4656 pending_stop_reply
= NULL
;
4659 /* Discard the stop replies we have already pulled with
4661 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4665 || ptid_get_pid (reply
->ptid
) == pid
)
4667 if (reply
== stop_reply_queue
)
4668 stop_reply_queue
= reply
->next
;
4670 prev
->next
= reply
->next
;
4672 stop_reply_xfree (reply
);
4679 /* Cleanup wrapper. */
4682 do_stop_reply_xfree (void *arg
)
4684 struct stop_reply
*r
= arg
;
4685 stop_reply_xfree (r
);
4688 /* Look for a queued stop reply belonging to PTID. If one is found,
4689 remove it from the queue, and return it. Returns NULL if none is
4690 found. If there are still queued events left to process, tell the
4691 event loop to get back to target_wait soon. */
4693 static struct stop_reply
*
4694 queued_stop_reply (ptid_t ptid
)
4696 struct stop_reply
*it
;
4697 struct stop_reply
**it_link
;
4699 it
= stop_reply_queue
;
4700 it_link
= &stop_reply_queue
;
4703 if (ptid_match (it
->ptid
, ptid
))
4705 *it_link
= it
->next
;
4710 it_link
= &it
->next
;
4714 if (stop_reply_queue
)
4715 /* There's still at least an event left. */
4716 mark_async_event_handler (remote_async_inferior_event_token
);
4721 /* Push a fully parsed stop reply in the stop reply queue. Since we
4722 know that we now have at least one queued event left to pass to the
4723 core side, tell the event loop to get back to target_wait soon. */
4726 push_stop_reply (struct stop_reply
*new_event
)
4728 struct stop_reply
*event
;
4730 if (stop_reply_queue
)
4732 for (event
= stop_reply_queue
;
4733 event
&& event
->next
;
4734 event
= event
->next
)
4737 event
->next
= new_event
;
4740 stop_reply_queue
= new_event
;
4742 mark_async_event_handler (remote_async_inferior_event_token
);
4745 /* Returns true if we have a stop reply for PTID. */
4748 peek_stop_reply (ptid_t ptid
)
4750 struct stop_reply
*it
;
4752 for (it
= stop_reply_queue
; it
; it
= it
->next
)
4753 if (ptid_equal (ptid
, it
->ptid
))
4755 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
4762 /* Parse the stop reply in BUF. Either the function succeeds, and the
4763 result is stored in EVENT, or throws an error. */
4766 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
4768 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4772 event
->ptid
= null_ptid
;
4773 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
4774 event
->ws
.value
.integer
= 0;
4775 event
->solibs_changed
= 0;
4776 event
->replay_event
= 0;
4777 event
->stopped_by_watchpoint_p
= 0;
4778 event
->regcache
= NULL
;
4783 case 'T': /* Status with PC, SP, FP, ... */
4784 /* Expedited reply, containing Signal, {regno, reg} repeat. */
4785 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
4787 n... = register number
4788 r... = register contents
4791 p
= &buf
[3]; /* after Txx */
4799 /* If the packet contains a register number, save it in
4800 pnum and set p1 to point to the character following it.
4801 Otherwise p1 points to p. */
4803 /* If this packet is an awatch packet, don't parse the 'a'
4804 as a register number. */
4806 if (strncmp (p
, "awatch", strlen("awatch")) != 0
4807 && strncmp (p
, "core", strlen ("core") != 0))
4809 /* Read the ``P'' register number. */
4810 pnum
= strtol (p
, &p_temp
, 16);
4816 if (p1
== p
) /* No register number present here. */
4818 p1
= strchr (p
, ':');
4820 error (_("Malformed packet(a) (missing colon): %s\n\
4823 if (strncmp (p
, "thread", p1
- p
) == 0)
4824 event
->ptid
= read_ptid (++p1
, &p
);
4825 else if ((strncmp (p
, "watch", p1
- p
) == 0)
4826 || (strncmp (p
, "rwatch", p1
- p
) == 0)
4827 || (strncmp (p
, "awatch", p1
- p
) == 0))
4829 event
->stopped_by_watchpoint_p
= 1;
4830 p
= unpack_varlen_hex (++p1
, &addr
);
4831 event
->watch_data_address
= (CORE_ADDR
) addr
;
4833 else if (strncmp (p
, "library", p1
- p
) == 0)
4837 while (*p_temp
&& *p_temp
!= ';')
4840 event
->solibs_changed
= 1;
4843 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
4845 /* NO_HISTORY event.
4846 p1 will indicate "begin" or "end", but
4847 it makes no difference for now, so ignore it. */
4848 event
->replay_event
= 1;
4849 p_temp
= strchr (p1
+ 1, ';');
4853 else if (strncmp (p
, "core", p1
- p
) == 0)
4856 p
= unpack_varlen_hex (++p1
, &c
);
4861 /* Silently skip unknown optional info. */
4862 p_temp
= strchr (p1
+ 1, ';');
4869 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
4870 cached_reg_t cached_reg
;
4875 error (_("Malformed packet(b) (missing colon): %s\n\
4881 error (_("Remote sent bad register number %s: %s\n\
4883 hex_string (pnum
), p
, buf
);
4885 cached_reg
.num
= reg
->regnum
;
4887 fieldsize
= hex2bin (p
, cached_reg
.data
,
4888 register_size (target_gdbarch
,
4891 if (fieldsize
< register_size (target_gdbarch
,
4893 warning (_("Remote reply is too short: %s"), buf
);
4895 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
4899 error (_("Remote register badly formatted: %s\nhere: %s"),
4904 case 'S': /* Old style status, just signal only. */
4905 if (event
->solibs_changed
)
4906 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
4907 else if (event
->replay_event
)
4908 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
4911 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4912 event
->ws
.value
.sig
= (enum target_signal
)
4913 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
4916 case 'W': /* Target exited. */
4923 /* GDB used to accept only 2 hex chars here. Stubs should
4924 only send more if they detect GDB supports multi-process
4926 p
= unpack_varlen_hex (&buf
[1], &value
);
4930 /* The remote process exited. */
4931 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
4932 event
->ws
.value
.integer
= value
;
4936 /* The remote process exited with a signal. */
4937 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
4938 event
->ws
.value
.sig
= (enum target_signal
) value
;
4941 /* If no process is specified, assume inferior_ptid. */
4942 pid
= ptid_get_pid (inferior_ptid
);
4951 else if (strncmp (p
,
4952 "process:", sizeof ("process:") - 1) == 0)
4955 p
+= sizeof ("process:") - 1;
4956 unpack_varlen_hex (p
, &upid
);
4960 error (_("unknown stop reply packet: %s"), buf
);
4963 error (_("unknown stop reply packet: %s"), buf
);
4964 event
->ptid
= pid_to_ptid (pid
);
4969 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
4970 error (_("No process or thread specified in stop reply: %s"), buf
);
4973 /* When the stub wants to tell GDB about a new stop reply, it sends a
4974 stop notification (%Stop). Those can come it at any time, hence,
4975 we have to make sure that any pending putpkt/getpkt sequence we're
4976 making is finished, before querying the stub for more events with
4977 vStopped. E.g., if we started a vStopped sequence immediatelly
4978 upon receiving the %Stop notification, something like this could
4986 1.6) <-- (registers reply to step #1.3)
4988 Obviously, the reply in step #1.6 would be unexpected to a vStopped
4991 To solve this, whenever we parse a %Stop notification sucessfully,
4992 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
4993 doing whatever we were doing:
4999 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5000 2.5) <-- (registers reply to step #2.3)
5002 Eventualy after step #2.5, we return to the event loop, which
5003 notices there's an event on the
5004 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5005 associated callback --- the function below. At this point, we're
5006 always safe to start a vStopped sequence. :
5009 2.7) <-- T05 thread:2
5015 remote_get_pending_stop_replies (void)
5017 struct remote_state
*rs
= get_remote_state ();
5019 if (pending_stop_reply
)
5022 putpkt ("vStopped");
5024 /* Now we can rely on it. */
5025 push_stop_reply (pending_stop_reply
);
5026 pending_stop_reply
= NULL
;
5030 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5031 if (strcmp (rs
->buf
, "OK") == 0)
5035 struct cleanup
*old_chain
;
5036 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5038 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5039 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5042 putpkt ("vStopped");
5044 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5046 /* Now we can rely on it. */
5047 discard_cleanups (old_chain
);
5048 push_stop_reply (stop_reply
);
5051 /* We got an unknown stop reply. */
5052 do_cleanups (old_chain
);
5059 /* Called when it is decided that STOP_REPLY holds the info of the
5060 event that is to be returned to the core. This function always
5061 destroys STOP_REPLY. */
5064 process_stop_reply (struct stop_reply
*stop_reply
,
5065 struct target_waitstatus
*status
)
5068 struct thread_info
*info
;
5070 *status
= stop_reply
->ws
;
5071 ptid
= stop_reply
->ptid
;
5073 /* If no thread/process was reported by the stub, assume the current
5075 if (ptid_equal (ptid
, null_ptid
))
5076 ptid
= inferior_ptid
;
5078 if (status
->kind
!= TARGET_WAITKIND_EXITED
5079 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5081 /* Expedited registers. */
5082 if (stop_reply
->regcache
)
5084 struct regcache
*regcache
5085 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5090 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5092 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5093 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5096 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5097 remote_watch_data_address
= stop_reply
->watch_data_address
;
5099 remote_notice_new_inferior (ptid
, 0);
5100 demand_private_info (ptid
)->core
= stop_reply
->core
;
5103 stop_reply_xfree (stop_reply
);
5107 /* The non-stop mode version of target_wait. */
5110 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5112 struct remote_state
*rs
= get_remote_state ();
5113 struct stop_reply
*stop_reply
;
5116 /* If in non-stop mode, get out of getpkt even if a
5117 notification is received. */
5119 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5126 case 'E': /* Error of some sort. */
5127 /* We're out of sync with the target now. Did it continue
5128 or not? We can't tell which thread it was in non-stop,
5129 so just ignore this. */
5130 warning (_("Remote failure reply: %s"), rs
->buf
);
5132 case 'O': /* Console output. */
5133 remote_console_output (rs
->buf
+ 1);
5136 warning (_("Invalid remote reply: %s"), rs
->buf
);
5140 /* Acknowledge a pending stop reply that may have arrived in the
5142 if (pending_stop_reply
!= NULL
)
5143 remote_get_pending_stop_replies ();
5145 /* If indeed we noticed a stop reply, we're done. */
5146 stop_reply
= queued_stop_reply (ptid
);
5147 if (stop_reply
!= NULL
)
5148 return process_stop_reply (stop_reply
, status
);
5150 /* Still no event. If we're just polling for an event, then
5151 return to the event loop. */
5152 if (options
& TARGET_WNOHANG
)
5154 status
->kind
= TARGET_WAITKIND_IGNORE
;
5155 return minus_one_ptid
;
5158 /* Otherwise do a blocking wait. */
5159 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5164 /* Wait until the remote machine stops, then return, storing status in
5165 STATUS just as `wait' would. */
5168 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5170 struct remote_state
*rs
= get_remote_state ();
5171 ptid_t event_ptid
= null_ptid
;
5173 struct stop_reply
*stop_reply
;
5177 status
->kind
= TARGET_WAITKIND_IGNORE
;
5178 status
->value
.integer
= 0;
5180 stop_reply
= queued_stop_reply (ptid
);
5181 if (stop_reply
!= NULL
)
5182 return process_stop_reply (stop_reply
, status
);
5184 if (rs
->cached_wait_status
)
5185 /* Use the cached wait status, but only once. */
5186 rs
->cached_wait_status
= 0;
5191 if (!target_is_async_p ())
5193 ofunc
= signal (SIGINT
, remote_interrupt
);
5194 /* If the user hit C-c before this packet, or between packets,
5195 pretend that it was hit right here. */
5199 remote_interrupt (SIGINT
);
5203 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5204 _never_ wait for ever -> test on target_is_async_p().
5205 However, before we do that we need to ensure that the caller
5206 knows how to take the target into/out of async mode. */
5207 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5208 if (!target_is_async_p ())
5209 signal (SIGINT
, ofunc
);
5214 remote_stopped_by_watchpoint_p
= 0;
5216 /* We got something. */
5217 rs
->waiting_for_stop_reply
= 0;
5219 /* Assume that the target has acknowledged Ctrl-C unless we receive
5220 an 'F' or 'O' packet. */
5221 if (buf
[0] != 'F' && buf
[0] != 'O')
5222 rs
->ctrlc_pending_p
= 0;
5226 case 'E': /* Error of some sort. */
5227 /* We're out of sync with the target now. Did it continue or
5228 not? Not is more likely, so report a stop. */
5229 warning (_("Remote failure reply: %s"), buf
);
5230 status
->kind
= TARGET_WAITKIND_STOPPED
;
5231 status
->value
.sig
= TARGET_SIGNAL_0
;
5233 case 'F': /* File-I/O request. */
5234 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5235 rs
->ctrlc_pending_p
= 0;
5237 case 'T': case 'S': case 'X': case 'W':
5239 struct stop_reply
*stop_reply
;
5240 struct cleanup
*old_chain
;
5242 stop_reply
= stop_reply_xmalloc ();
5243 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5244 remote_parse_stop_reply (buf
, stop_reply
);
5245 discard_cleanups (old_chain
);
5246 event_ptid
= process_stop_reply (stop_reply
, status
);
5249 case 'O': /* Console output. */
5250 remote_console_output (buf
+ 1);
5252 /* The target didn't really stop; keep waiting. */
5253 rs
->waiting_for_stop_reply
= 1;
5257 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5259 /* Zero length reply means that we tried 'S' or 'C' and the
5260 remote system doesn't support it. */
5261 target_terminal_ours_for_output ();
5263 ("Can't send signals to this remote system. %s not sent.\n",
5264 target_signal_to_name (last_sent_signal
));
5265 last_sent_signal
= TARGET_SIGNAL_0
;
5266 target_terminal_inferior ();
5268 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5269 putpkt ((char *) buf
);
5271 /* We just told the target to resume, so a stop reply is in
5273 rs
->waiting_for_stop_reply
= 1;
5276 /* else fallthrough */
5278 warning (_("Invalid remote reply: %s"), buf
);
5280 rs
->waiting_for_stop_reply
= 1;
5284 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5286 /* Nothing interesting happened. If we're doing a non-blocking
5287 poll, we're done. Otherwise, go back to waiting. */
5288 if (options
& TARGET_WNOHANG
)
5289 return minus_one_ptid
;
5293 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5294 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5296 if (!ptid_equal (event_ptid
, null_ptid
))
5297 record_currthread (event_ptid
);
5299 event_ptid
= inferior_ptid
;
5302 /* A process exit. Invalidate our notion of current thread. */
5303 record_currthread (minus_one_ptid
);
5308 /* Wait until the remote machine stops, then return, storing status in
5309 STATUS just as `wait' would. */
5312 remote_wait (struct target_ops
*ops
,
5313 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5318 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5320 event_ptid
= remote_wait_as (ptid
, status
, options
);
5322 if (target_can_async_p ())
5324 /* If there are are events left in the queue tell the event loop
5326 if (stop_reply_queue
)
5327 mark_async_event_handler (remote_async_inferior_event_token
);
5333 /* Fetch a single register using a 'p' packet. */
5336 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5338 struct remote_state
*rs
= get_remote_state ();
5340 char regp
[MAX_REGISTER_SIZE
];
5343 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5346 if (reg
->pnum
== -1)
5351 p
+= hexnumstr (p
, reg
->pnum
);
5354 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5358 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5362 case PACKET_UNKNOWN
:
5365 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5366 gdbarch_register_name (get_regcache_arch (regcache
),
5371 /* If this register is unfetchable, tell the regcache. */
5374 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5378 /* Otherwise, parse and supply the value. */
5384 error (_("fetch_register_using_p: early buf termination"));
5386 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5389 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5393 /* Fetch the registers included in the target's 'g' packet. */
5396 send_g_packet (void)
5398 struct remote_state
*rs
= get_remote_state ();
5401 sprintf (rs
->buf
, "g");
5402 remote_send (&rs
->buf
, &rs
->buf_size
);
5404 /* We can get out of synch in various cases. If the first character
5405 in the buffer is not a hex character, assume that has happened
5406 and try to fetch another packet to read. */
5407 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5408 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5409 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5410 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5413 fprintf_unfiltered (gdb_stdlog
,
5414 "Bad register packet; fetching a new packet\n");
5415 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5418 buf_len
= strlen (rs
->buf
);
5420 /* Sanity check the received packet. */
5421 if (buf_len
% 2 != 0)
5422 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5428 process_g_packet (struct regcache
*regcache
)
5430 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5431 struct remote_state
*rs
= get_remote_state ();
5432 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5437 buf_len
= strlen (rs
->buf
);
5439 /* Further sanity checks, with knowledge of the architecture. */
5440 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5441 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5443 /* Save the size of the packet sent to us by the target. It is used
5444 as a heuristic when determining the max size of packets that the
5445 target can safely receive. */
5446 if (rsa
->actual_register_packet_size
== 0)
5447 rsa
->actual_register_packet_size
= buf_len
;
5449 /* If this is smaller than we guessed the 'g' packet would be,
5450 update our records. A 'g' reply that doesn't include a register's
5451 value implies either that the register is not available, or that
5452 the 'p' packet must be used. */
5453 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5455 rsa
->sizeof_g_packet
= buf_len
/ 2;
5457 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5459 if (rsa
->regs
[i
].pnum
== -1)
5462 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5463 rsa
->regs
[i
].in_g_packet
= 0;
5465 rsa
->regs
[i
].in_g_packet
= 1;
5469 regs
= alloca (rsa
->sizeof_g_packet
);
5471 /* Unimplemented registers read as all bits zero. */
5472 memset (regs
, 0, rsa
->sizeof_g_packet
);
5474 /* Reply describes registers byte by byte, each byte encoded as two
5475 hex characters. Suck them all up, then supply them to the
5476 register cacheing/storage mechanism. */
5479 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5481 if (p
[0] == 0 || p
[1] == 0)
5482 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5483 internal_error (__FILE__
, __LINE__
,
5484 "unexpected end of 'g' packet reply");
5486 if (p
[0] == 'x' && p
[1] == 'x')
5487 regs
[i
] = 0; /* 'x' */
5489 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5495 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5497 struct packet_reg
*r
= &rsa
->regs
[i
];
5500 if (r
->offset
* 2 >= strlen (rs
->buf
))
5501 /* This shouldn't happen - we adjusted in_g_packet above. */
5502 internal_error (__FILE__
, __LINE__
,
5503 "unexpected end of 'g' packet reply");
5504 else if (rs
->buf
[r
->offset
* 2] == 'x')
5506 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5507 /* The register isn't available, mark it as such (at
5508 the same time setting the value to zero). */
5509 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5512 regcache_raw_supply (regcache
, r
->regnum
,
5520 fetch_registers_using_g (struct regcache
*regcache
)
5523 process_g_packet (regcache
);
5527 remote_fetch_registers (struct target_ops
*ops
,
5528 struct regcache
*regcache
, int regnum
)
5530 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5533 set_general_thread (inferior_ptid
);
5537 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5538 gdb_assert (reg
!= NULL
);
5540 /* If this register might be in the 'g' packet, try that first -
5541 we are likely to read more than one register. If this is the
5542 first 'g' packet, we might be overly optimistic about its
5543 contents, so fall back to 'p'. */
5544 if (reg
->in_g_packet
)
5546 fetch_registers_using_g (regcache
);
5547 if (reg
->in_g_packet
)
5551 if (fetch_register_using_p (regcache
, reg
))
5554 /* This register is not available. */
5555 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5560 fetch_registers_using_g (regcache
);
5562 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5563 if (!rsa
->regs
[i
].in_g_packet
)
5564 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5566 /* This register is not available. */
5567 regcache_raw_supply (regcache
, i
, NULL
);
5571 /* Prepare to store registers. Since we may send them all (using a
5572 'G' request), we have to read out the ones we don't want to change
5576 remote_prepare_to_store (struct regcache
*regcache
)
5578 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5580 gdb_byte buf
[MAX_REGISTER_SIZE
];
5582 /* Make sure the entire registers array is valid. */
5583 switch (remote_protocol_packets
[PACKET_P
].support
)
5585 case PACKET_DISABLE
:
5586 case PACKET_SUPPORT_UNKNOWN
:
5587 /* Make sure all the necessary registers are cached. */
5588 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5589 if (rsa
->regs
[i
].in_g_packet
)
5590 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5597 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5598 packet was not recognized. */
5601 store_register_using_P (const struct regcache
*regcache
,
5602 struct packet_reg
*reg
)
5604 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5605 struct remote_state
*rs
= get_remote_state ();
5606 /* Try storing a single register. */
5607 char *buf
= rs
->buf
;
5608 gdb_byte regp
[MAX_REGISTER_SIZE
];
5611 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5614 if (reg
->pnum
== -1)
5617 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5618 p
= buf
+ strlen (buf
);
5619 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5620 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5622 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5624 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5629 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5630 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5631 case PACKET_UNKNOWN
:
5634 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5638 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5639 contents of the register cache buffer. FIXME: ignores errors. */
5642 store_registers_using_G (const struct regcache
*regcache
)
5644 struct remote_state
*rs
= get_remote_state ();
5645 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5649 /* Extract all the registers in the regcache copying them into a
5653 regs
= alloca (rsa
->sizeof_g_packet
);
5654 memset (regs
, 0, rsa
->sizeof_g_packet
);
5655 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5657 struct packet_reg
*r
= &rsa
->regs
[i
];
5659 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5663 /* Command describes registers byte by byte,
5664 each byte encoded as two hex characters. */
5667 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5669 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5671 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5672 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5673 error (_("Could not write registers; remote failure reply '%s'"),
5677 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
5678 of the register cache buffer. FIXME: ignores errors. */
5681 remote_store_registers (struct target_ops
*ops
,
5682 struct regcache
*regcache
, int regnum
)
5684 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5687 set_general_thread (inferior_ptid
);
5691 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5692 gdb_assert (reg
!= NULL
);
5694 /* Always prefer to store registers using the 'P' packet if
5695 possible; we often change only a small number of registers.
5696 Sometimes we change a larger number; we'd need help from a
5697 higher layer to know to use 'G'. */
5698 if (store_register_using_P (regcache
, reg
))
5701 /* For now, don't complain if we have no way to write the
5702 register. GDB loses track of unavailable registers too
5703 easily. Some day, this may be an error. We don't have
5704 any way to read the register, either... */
5705 if (!reg
->in_g_packet
)
5708 store_registers_using_G (regcache
);
5712 store_registers_using_G (regcache
);
5714 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5715 if (!rsa
->regs
[i
].in_g_packet
)
5716 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
5717 /* See above for why we do not issue an error here. */
5722 /* Return the number of hex digits in num. */
5725 hexnumlen (ULONGEST num
)
5729 for (i
= 0; num
!= 0; i
++)
5735 /* Set BUF to the minimum number of hex digits representing NUM. */
5738 hexnumstr (char *buf
, ULONGEST num
)
5740 int len
= hexnumlen (num
);
5741 return hexnumnstr (buf
, num
, len
);
5745 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
5748 hexnumnstr (char *buf
, ULONGEST num
, int width
)
5754 for (i
= width
- 1; i
>= 0; i
--)
5756 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
5763 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
5766 remote_address_masked (CORE_ADDR addr
)
5768 int address_size
= remote_address_size
;
5769 /* If "remoteaddresssize" was not set, default to target address size. */
5771 address_size
= gdbarch_addr_bit (target_gdbarch
);
5773 if (address_size
> 0
5774 && address_size
< (sizeof (ULONGEST
) * 8))
5776 /* Only create a mask when that mask can safely be constructed
5777 in a ULONGEST variable. */
5779 mask
= (mask
<< address_size
) - 1;
5785 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
5786 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
5787 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
5788 (which may be more than *OUT_LEN due to escape characters). The
5789 total number of bytes in the output buffer will be at most
5793 remote_escape_output (const gdb_byte
*buffer
, int len
,
5794 gdb_byte
*out_buf
, int *out_len
,
5797 int input_index
, output_index
;
5800 for (input_index
= 0; input_index
< len
; input_index
++)
5802 gdb_byte b
= buffer
[input_index
];
5804 if (b
== '$' || b
== '#' || b
== '}')
5806 /* These must be escaped. */
5807 if (output_index
+ 2 > out_maxlen
)
5809 out_buf
[output_index
++] = '}';
5810 out_buf
[output_index
++] = b
^ 0x20;
5814 if (output_index
+ 1 > out_maxlen
)
5816 out_buf
[output_index
++] = b
;
5820 *out_len
= input_index
;
5821 return output_index
;
5824 /* Convert BUFFER, escaped data LEN bytes long, into binary data
5825 in OUT_BUF. Return the number of bytes written to OUT_BUF.
5826 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
5828 This function reverses remote_escape_output. It allows more
5829 escaped characters than that function does, in particular because
5830 '*' must be escaped to avoid the run-length encoding processing
5831 in reading packets. */
5834 remote_unescape_input (const gdb_byte
*buffer
, int len
,
5835 gdb_byte
*out_buf
, int out_maxlen
)
5837 int input_index
, output_index
;
5842 for (input_index
= 0; input_index
< len
; input_index
++)
5844 gdb_byte b
= buffer
[input_index
];
5846 if (output_index
+ 1 > out_maxlen
)
5848 warning (_("Received too much data from remote target;"
5849 " ignoring overflow."));
5850 return output_index
;
5855 out_buf
[output_index
++] = b
^ 0x20;
5861 out_buf
[output_index
++] = b
;
5865 error (_("Unmatched escape character in target response."));
5867 return output_index
;
5870 /* Determine whether the remote target supports binary downloading.
5871 This is accomplished by sending a no-op memory write of zero length
5872 to the target at the specified address. It does not suffice to send
5873 the whole packet, since many stubs strip the eighth bit and
5874 subsequently compute a wrong checksum, which causes real havoc with
5877 NOTE: This can still lose if the serial line is not eight-bit
5878 clean. In cases like this, the user should clear "remote
5882 check_binary_download (CORE_ADDR addr
)
5884 struct remote_state
*rs
= get_remote_state ();
5886 switch (remote_protocol_packets
[PACKET_X
].support
)
5888 case PACKET_DISABLE
:
5892 case PACKET_SUPPORT_UNKNOWN
:
5898 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5900 p
+= hexnumstr (p
, (ULONGEST
) 0);
5904 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5905 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5907 if (rs
->buf
[0] == '\0')
5910 fprintf_unfiltered (gdb_stdlog
,
5911 "binary downloading NOT suppported by target\n");
5912 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
5917 fprintf_unfiltered (gdb_stdlog
,
5918 "binary downloading suppported by target\n");
5919 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
5926 /* Write memory data directly to the remote machine.
5927 This does not inform the data cache; the data cache uses this.
5928 HEADER is the starting part of the packet.
5929 MEMADDR is the address in the remote memory space.
5930 MYADDR is the address of the buffer in our space.
5931 LEN is the number of bytes.
5932 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
5933 should send data as binary ('X'), or hex-encoded ('M').
5935 The function creates packet of the form
5936 <HEADER><ADDRESS>,<LENGTH>:<DATA>
5938 where encoding of <DATA> is termined by PACKET_FORMAT.
5940 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
5943 Returns the number of bytes transferred, or 0 (setting errno) for
5944 error. Only transfer a single packet. */
5947 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
5948 const gdb_byte
*myaddr
, int len
,
5949 char packet_format
, int use_length
)
5951 struct remote_state
*rs
= get_remote_state ();
5961 if (packet_format
!= 'X' && packet_format
!= 'M')
5962 internal_error (__FILE__
, __LINE__
,
5963 "remote_write_bytes_aux: bad packet format");
5968 payload_size
= get_memory_write_packet_size ();
5970 /* The packet buffer will be large enough for the payload;
5971 get_memory_packet_size ensures this. */
5974 /* Compute the size of the actual payload by subtracting out the
5975 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
5977 payload_size
-= strlen ("$,:#NN");
5979 /* The comma won't be used. */
5981 header_length
= strlen (header
);
5982 payload_size
-= header_length
;
5983 payload_size
-= hexnumlen (memaddr
);
5985 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
5987 strcat (rs
->buf
, header
);
5988 p
= rs
->buf
+ strlen (header
);
5990 /* Compute a best guess of the number of bytes actually transfered. */
5991 if (packet_format
== 'X')
5993 /* Best guess at number of bytes that will fit. */
5994 todo
= min (len
, payload_size
);
5996 payload_size
-= hexnumlen (todo
);
5997 todo
= min (todo
, payload_size
);
6001 /* Num bytes that will fit. */
6002 todo
= min (len
, payload_size
/ 2);
6004 payload_size
-= hexnumlen (todo
);
6005 todo
= min (todo
, payload_size
/ 2);
6009 internal_error (__FILE__
, __LINE__
,
6010 _("minumum packet size too small to write data"));
6012 /* If we already need another packet, then try to align the end
6013 of this packet to a useful boundary. */
6014 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6015 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6017 /* Append "<memaddr>". */
6018 memaddr
= remote_address_masked (memaddr
);
6019 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6026 /* Append <len>. Retain the location/size of <len>. It may need to
6027 be adjusted once the packet body has been created. */
6029 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6037 /* Append the packet body. */
6038 if (packet_format
== 'X')
6040 /* Binary mode. Send target system values byte by byte, in
6041 increasing byte addresses. Only escape certain critical
6043 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6046 /* If not all TODO bytes fit, then we'll need another packet. Make
6047 a second try to keep the end of the packet aligned. Don't do
6048 this if the packet is tiny. */
6049 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6053 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6055 if (new_nr_bytes
!= nr_bytes
)
6056 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6061 p
+= payload_length
;
6062 if (use_length
&& nr_bytes
< todo
)
6064 /* Escape chars have filled up the buffer prematurely,
6065 and we have actually sent fewer bytes than planned.
6066 Fix-up the length field of the packet. Use the same
6067 number of characters as before. */
6068 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6069 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6074 /* Normal mode: Send target system values byte by byte, in
6075 increasing byte addresses. Each byte is encoded as a two hex
6077 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6081 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6082 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6084 if (rs
->buf
[0] == 'E')
6086 /* There is no correspondance between what the remote protocol
6087 uses for errors and errno codes. We would like a cleaner way
6088 of representing errors (big enough to include errno codes,
6089 bfd_error codes, and others). But for now just return EIO. */
6094 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6095 fewer bytes than we'd planned. */
6099 /* Write memory data directly to the remote machine.
6100 This does not inform the data cache; the data cache uses this.
6101 MEMADDR is the address in the remote memory space.
6102 MYADDR is the address of the buffer in our space.
6103 LEN is the number of bytes.
6105 Returns number of bytes transferred, or 0 (setting errno) for
6106 error. Only transfer a single packet. */
6109 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6111 char *packet_format
= 0;
6113 /* Check whether the target supports binary download. */
6114 check_binary_download (memaddr
);
6116 switch (remote_protocol_packets
[PACKET_X
].support
)
6119 packet_format
= "X";
6121 case PACKET_DISABLE
:
6122 packet_format
= "M";
6124 case PACKET_SUPPORT_UNKNOWN
:
6125 internal_error (__FILE__
, __LINE__
,
6126 _("remote_write_bytes: bad internal state"));
6128 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6131 return remote_write_bytes_aux (packet_format
,
6132 memaddr
, myaddr
, len
, packet_format
[0], 1);
6135 /* Read memory data directly from the remote machine.
6136 This does not use the data cache; the data cache uses this.
6137 MEMADDR is the address in the remote memory space.
6138 MYADDR is the address of the buffer in our space.
6139 LEN is the number of bytes.
6141 Returns number of bytes transferred, or 0 for error. */
6143 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
6144 remote targets) shouldn't attempt to read the entire buffer.
6145 Instead it should read a single packet worth of data and then
6146 return the byte size of that packet to the caller. The caller (its
6147 caller and its callers caller ;-) already contains code for
6148 handling partial reads. */
6151 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6153 struct remote_state
*rs
= get_remote_state ();
6154 int max_buf_size
; /* Max size of packet output buffer. */
6160 max_buf_size
= get_memory_read_packet_size ();
6161 /* The packet buffer will be large enough for the payload;
6162 get_memory_packet_size ensures this. */
6171 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
6173 /* construct "m"<memaddr>","<len>" */
6174 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
6175 memaddr
= remote_address_masked (memaddr
);
6178 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6180 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6184 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6186 if (rs
->buf
[0] == 'E'
6187 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6188 && rs
->buf
[3] == '\0')
6190 /* There is no correspondance between what the remote
6191 protocol uses for errors and errno codes. We would like
6192 a cleaner way of representing errors (big enough to
6193 include errno codes, bfd_error codes, and others). But
6194 for now just return EIO. */
6199 /* Reply describes memory byte by byte,
6200 each byte encoded as two hex characters. */
6203 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
6205 /* Reply is short. This means that we were able to read
6206 only part of what we wanted to. */
6207 return i
+ (origlen
- len
);
6217 /* Remote notification handler. */
6220 handle_notification (char *buf
, size_t length
)
6222 if (strncmp (buf
, "Stop:", 5) == 0)
6224 if (pending_stop_reply
)
6226 /* We've already parsed the in-flight stop-reply, but the
6227 stub for some reason thought we didn't, possibly due to
6228 timeout on its side. Just ignore it. */
6230 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6234 struct cleanup
*old_chain
;
6235 struct stop_reply
*reply
= stop_reply_xmalloc ();
6236 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6238 remote_parse_stop_reply (buf
+ 5, reply
);
6240 discard_cleanups (old_chain
);
6242 /* Be careful to only set it after parsing, since an error
6243 may be thrown then. */
6244 pending_stop_reply
= reply
;
6246 /* Notify the event loop there's a stop reply to acknowledge
6247 and that there may be more events to fetch. */
6248 mark_async_event_handler (remote_async_get_pending_events_token
);
6251 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6255 /* We ignore notifications we don't recognize, for compatibility
6256 with newer stubs. */
6261 /* Read or write LEN bytes from inferior memory at MEMADDR,
6262 transferring to or from debugger address BUFFER. Write to inferior
6263 if SHOULD_WRITE is nonzero. Returns length of data written or
6264 read; 0 for error. TARGET is unused. */
6267 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6268 int should_write
, struct mem_attrib
*attrib
,
6269 struct target_ops
*target
)
6273 set_general_thread (inferior_ptid
);
6276 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6278 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6283 /* Sends a packet with content determined by the printf format string
6284 FORMAT and the remaining arguments, then gets the reply. Returns
6285 whether the packet was a success, a failure, or unknown. */
6287 static enum packet_result
6288 remote_send_printf (const char *format
, ...)
6290 struct remote_state
*rs
= get_remote_state ();
6291 int max_size
= get_remote_packet_size ();
6294 va_start (ap
, format
);
6297 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6298 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
6300 if (putpkt (rs
->buf
) < 0)
6301 error (_("Communication problem with target."));
6304 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6306 return packet_check_result (rs
->buf
);
6310 restore_remote_timeout (void *p
)
6312 int value
= *(int *)p
;
6313 remote_timeout
= value
;
6316 /* Flash writing can take quite some time. We'll set
6317 effectively infinite timeout for flash operations.
6318 In future, we'll need to decide on a better approach. */
6319 static const int remote_flash_timeout
= 1000;
6322 remote_flash_erase (struct target_ops
*ops
,
6323 ULONGEST address
, LONGEST length
)
6325 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6326 int saved_remote_timeout
= remote_timeout
;
6327 enum packet_result ret
;
6329 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6330 &saved_remote_timeout
);
6331 remote_timeout
= remote_flash_timeout
;
6333 ret
= remote_send_printf ("vFlashErase:%s,%s",
6334 phex (address
, addr_size
),
6338 case PACKET_UNKNOWN
:
6339 error (_("Remote target does not support flash erase"));
6341 error (_("Error erasing flash with vFlashErase packet"));
6346 do_cleanups (back_to
);
6350 remote_flash_write (struct target_ops
*ops
,
6351 ULONGEST address
, LONGEST length
,
6352 const gdb_byte
*data
)
6354 int saved_remote_timeout
= remote_timeout
;
6356 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6357 &saved_remote_timeout
);
6359 remote_timeout
= remote_flash_timeout
;
6360 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6361 do_cleanups (back_to
);
6367 remote_flash_done (struct target_ops
*ops
)
6369 int saved_remote_timeout
= remote_timeout
;
6371 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6372 &saved_remote_timeout
);
6374 remote_timeout
= remote_flash_timeout
;
6375 ret
= remote_send_printf ("vFlashDone");
6376 do_cleanups (back_to
);
6380 case PACKET_UNKNOWN
:
6381 error (_("Remote target does not support vFlashDone"));
6383 error (_("Error finishing flash operation"));
6390 remote_files_info (struct target_ops
*ignore
)
6392 puts_filtered ("Debugging a target over a serial line.\n");
6395 /* Stuff for dealing with the packets which are part of this protocol.
6396 See comment at top of file for details. */
6398 /* Read a single character from the remote end. */
6401 readchar (int timeout
)
6405 ch
= serial_readchar (remote_desc
, timeout
);
6410 switch ((enum serial_rc
) ch
)
6414 error (_("Remote connection closed"));
6417 perror_with_name (_("Remote communication error"));
6419 case SERIAL_TIMEOUT
:
6425 /* Send the command in *BUF to the remote machine, and read the reply
6426 into *BUF. Report an error if we get an error reply. Resize
6427 *BUF using xrealloc if necessary to hold the result, and update
6431 remote_send (char **buf
,
6435 getpkt (buf
, sizeof_buf
, 0);
6437 if ((*buf
)[0] == 'E')
6438 error (_("Remote failure reply: %s"), *buf
);
6441 /* Return a pointer to an xmalloc'ed string representing an escaped
6442 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6443 etc. The caller is responsible for releasing the returned
6447 escape_buffer (const char *buf
, int n
)
6449 struct cleanup
*old_chain
;
6450 struct ui_file
*stb
;
6453 stb
= mem_fileopen ();
6454 old_chain
= make_cleanup_ui_file_delete (stb
);
6456 fputstrn_unfiltered (buf
, n
, 0, stb
);
6457 str
= ui_file_xstrdup (stb
, NULL
);
6458 do_cleanups (old_chain
);
6462 /* Display a null-terminated packet on stdout, for debugging, using C
6466 print_packet (char *buf
)
6468 puts_filtered ("\"");
6469 fputstr_filtered (buf
, '"', gdb_stdout
);
6470 puts_filtered ("\"");
6476 return putpkt_binary (buf
, strlen (buf
));
6479 /* Send a packet to the remote machine, with error checking. The data
6480 of the packet is in BUF. The string in BUF can be at most
6481 get_remote_packet_size () - 5 to account for the $, # and checksum,
6482 and for a possible /0 if we are debugging (remote_debug) and want
6483 to print the sent packet as a string. */
6486 putpkt_binary (char *buf
, int cnt
)
6488 struct remote_state
*rs
= get_remote_state ();
6490 unsigned char csum
= 0;
6491 char *buf2
= alloca (cnt
+ 6);
6497 /* Catch cases like trying to read memory or listing threads while
6498 we're waiting for a stop reply. The remote server wouldn't be
6499 ready to handle this request, so we'd hang and timeout. We don't
6500 have to worry about this in synchronous mode, because in that
6501 case it's not possible to issue a command while the target is
6502 running. This is not a problem in non-stop mode, because in that
6503 case, the stub is always ready to process serial input. */
6504 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6505 error (_("Cannot execute this command while the target is running."));
6507 /* We're sending out a new packet. Make sure we don't look at a
6508 stale cached response. */
6509 rs
->cached_wait_status
= 0;
6511 /* Copy the packet into buffer BUF2, encapsulating it
6512 and giving it a checksum. */
6517 for (i
= 0; i
< cnt
; i
++)
6523 *p
++ = tohex ((csum
>> 4) & 0xf);
6524 *p
++ = tohex (csum
& 0xf);
6526 /* Send it over and over until we get a positive ack. */
6530 int started_error_output
= 0;
6534 struct cleanup
*old_chain
;
6538 str
= escape_buffer (buf2
, p
- buf2
);
6539 old_chain
= make_cleanup (xfree
, str
);
6540 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6541 gdb_flush (gdb_stdlog
);
6542 do_cleanups (old_chain
);
6544 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6545 perror_with_name (_("putpkt: write failed"));
6547 /* If this is a no acks version of the remote protocol, send the
6548 packet and move on. */
6552 /* Read until either a timeout occurs (-2) or '+' is read.
6553 Handle any notification that arrives in the mean time. */
6556 ch
= readchar (remote_timeout
);
6564 case SERIAL_TIMEOUT
:
6567 if (started_error_output
)
6569 putchar_unfiltered ('\n');
6570 started_error_output
= 0;
6579 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6583 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6584 case SERIAL_TIMEOUT
:
6588 break; /* Retransmit buffer. */
6592 fprintf_unfiltered (gdb_stdlog
,
6593 "Packet instead of Ack, ignoring it\n");
6594 /* It's probably an old response sent because an ACK
6595 was lost. Gobble up the packet and ack it so it
6596 doesn't get retransmitted when we resend this
6599 serial_write (remote_desc
, "+", 1);
6600 continue; /* Now, go look for +. */
6607 /* If we got a notification, handle it, and go back to looking
6609 /* We've found the start of a notification. Now
6610 collect the data. */
6611 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6616 struct cleanup
*old_chain
;
6619 str
= escape_buffer (rs
->buf
, val
);
6620 old_chain
= make_cleanup (xfree
, str
);
6621 fprintf_unfiltered (gdb_stdlog
,
6622 " Notification received: %s\n",
6624 do_cleanups (old_chain
);
6626 handle_notification (rs
->buf
, val
);
6627 /* We're in sync now, rewait for the ack. */
6634 if (!started_error_output
)
6636 started_error_output
= 1;
6637 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6639 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6640 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6649 if (!started_error_output
)
6651 started_error_output
= 1;
6652 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6654 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6658 break; /* Here to retransmit. */
6662 /* This is wrong. If doing a long backtrace, the user should be
6663 able to get out next time we call QUIT, without anything as
6664 violent as interrupt_query. If we want to provide a way out of
6665 here without getting to the next QUIT, it should be based on
6666 hitting ^C twice as in remote_wait. */
6677 /* Come here after finding the start of a frame when we expected an
6678 ack. Do our best to discard the rest of this packet. */
6687 c
= readchar (remote_timeout
);
6690 case SERIAL_TIMEOUT
:
6691 /* Nothing we can do. */
6694 /* Discard the two bytes of checksum and stop. */
6695 c
= readchar (remote_timeout
);
6697 c
= readchar (remote_timeout
);
6700 case '*': /* Run length encoding. */
6701 /* Discard the repeat count. */
6702 c
= readchar (remote_timeout
);
6707 /* A regular character. */
6713 /* Come here after finding the start of the frame. Collect the rest
6714 into *BUF, verifying the checksum, length, and handling run-length
6715 compression. NUL terminate the buffer. If there is not enough room,
6716 expand *BUF using xrealloc.
6718 Returns -1 on error, number of characters in buffer (ignoring the
6719 trailing NULL) on success. (could be extended to return one of the
6720 SERIAL status indications). */
6723 read_frame (char **buf_p
,
6730 struct remote_state
*rs
= get_remote_state ();
6737 c
= readchar (remote_timeout
);
6740 case SERIAL_TIMEOUT
:
6742 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
6746 fputs_filtered ("Saw new packet start in middle of old one\n",
6748 return -1; /* Start a new packet, count retries. */
6751 unsigned char pktcsum
;
6757 check_0
= readchar (remote_timeout
);
6759 check_1
= readchar (remote_timeout
);
6761 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
6764 fputs_filtered ("Timeout in checksum, retrying\n",
6768 else if (check_0
< 0 || check_1
< 0)
6771 fputs_filtered ("Communication error in checksum\n",
6776 /* Don't recompute the checksum; with no ack packets we
6777 don't have any way to indicate a packet retransmission
6782 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
6783 if (csum
== pktcsum
)
6788 struct cleanup
*old_chain
;
6791 str
= escape_buffer (buf
, bc
);
6792 old_chain
= make_cleanup (xfree
, str
);
6793 fprintf_unfiltered (gdb_stdlog
,
6795 Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
6796 pktcsum
, csum
, str
);
6797 do_cleanups (old_chain
);
6799 /* Number of characters in buffer ignoring trailing
6803 case '*': /* Run length encoding. */
6808 c
= readchar (remote_timeout
);
6810 repeat
= c
- ' ' + 3; /* Compute repeat count. */
6812 /* The character before ``*'' is repeated. */
6814 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
6816 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
6818 /* Make some more room in the buffer. */
6819 *sizeof_buf
+= repeat
;
6820 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6824 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
6830 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
6834 if (bc
>= *sizeof_buf
- 1)
6836 /* Make some more room in the buffer. */
6838 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6849 /* Read a packet from the remote machine, with error checking, and
6850 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6851 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6852 rather than timing out; this is used (in synchronous mode) to wait
6853 for a target that is is executing user code to stop. */
6854 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
6855 don't have to change all the calls to getpkt to deal with the
6856 return value, because at the moment I don't know what the right
6857 thing to do it for those. */
6865 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
6869 /* Read a packet from the remote machine, with error checking, and
6870 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6871 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6872 rather than timing out; this is used (in synchronous mode) to wait
6873 for a target that is is executing user code to stop. If FOREVER ==
6874 0, this function is allowed to time out gracefully and return an
6875 indication of this to the caller. Otherwise return the number of
6876 bytes read. If EXPECTING_NOTIF, consider receiving a notification
6877 enough reason to return to the caller. */
6880 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
6881 int expecting_notif
)
6883 struct remote_state
*rs
= get_remote_state ();
6889 /* We're reading a new response. Make sure we don't look at a
6890 previously cached response. */
6891 rs
->cached_wait_status
= 0;
6893 strcpy (*buf
, "timeout");
6896 timeout
= watchdog
> 0 ? watchdog
: -1;
6897 else if (expecting_notif
)
6898 timeout
= 0; /* There should already be a char in the buffer. If
6901 timeout
= remote_timeout
;
6905 /* Process any number of notifications, and then return when
6909 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
6911 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
6913 /* This can loop forever if the remote side sends us
6914 characters continuously, but if it pauses, we'll get
6915 SERIAL_TIMEOUT from readchar because of timeout. Then
6916 we'll count that as a retry.
6918 Note that even when forever is set, we will only wait
6919 forever prior to the start of a packet. After that, we
6920 expect characters to arrive at a brisk pace. They should
6921 show up within remote_timeout intervals. */
6923 c
= readchar (timeout
);
6924 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
6926 if (c
== SERIAL_TIMEOUT
)
6928 if (expecting_notif
)
6929 return -1; /* Don't complain, it's normal to not get
6930 anything in this case. */
6932 if (forever
) /* Watchdog went off? Kill the target. */
6936 error (_("Watchdog timeout has expired. Target detached."));
6939 fputs_filtered ("Timed out.\n", gdb_stdlog
);
6943 /* We've found the start of a packet or notification.
6944 Now collect the data. */
6945 val
= read_frame (buf
, sizeof_buf
);
6950 serial_write (remote_desc
, "-", 1);
6953 if (tries
> MAX_TRIES
)
6955 /* We have tried hard enough, and just can't receive the
6956 packet/notification. Give up. */
6957 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
6959 /* Skip the ack char if we're in no-ack mode. */
6960 if (!rs
->noack_mode
)
6961 serial_write (remote_desc
, "+", 1);
6965 /* If we got an ordinary packet, return that to our caller. */
6970 struct cleanup
*old_chain
;
6973 str
= escape_buffer (*buf
, val
);
6974 old_chain
= make_cleanup (xfree
, str
);
6975 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
6976 do_cleanups (old_chain
);
6979 /* Skip the ack char if we're in no-ack mode. */
6980 if (!rs
->noack_mode
)
6981 serial_write (remote_desc
, "+", 1);
6985 /* If we got a notification, handle it, and go back to looking
6989 gdb_assert (c
== '%');
6993 struct cleanup
*old_chain
;
6996 str
= escape_buffer (*buf
, val
);
6997 old_chain
= make_cleanup (xfree
, str
);
6998 fprintf_unfiltered (gdb_stdlog
,
6999 " Notification received: %s\n",
7001 do_cleanups (old_chain
);
7004 handle_notification (*buf
, val
);
7006 /* Notifications require no acknowledgement. */
7008 if (expecting_notif
)
7015 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7017 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7021 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7023 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7028 remote_kill (struct target_ops
*ops
)
7030 /* Use catch_errors so the user can quit from gdb even when we
7031 aren't on speaking terms with the remote system. */
7032 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
7034 /* Don't wait for it to die. I'm not really sure it matters whether
7035 we do or not. For the existing stubs, kill is a noop. */
7036 target_mourn_inferior ();
7040 remote_vkill (int pid
, struct remote_state
*rs
)
7042 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7045 /* Tell the remote target to detach. */
7046 sprintf (rs
->buf
, "vKill;%x", pid
);
7048 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7050 if (packet_ok (rs
->buf
,
7051 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7053 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7060 extended_remote_kill (struct target_ops
*ops
)
7063 int pid
= ptid_get_pid (inferior_ptid
);
7064 struct remote_state
*rs
= get_remote_state ();
7066 res
= remote_vkill (pid
, rs
);
7067 if (res
== -1 && !remote_multi_process_p (rs
))
7069 /* Don't try 'k' on a multi-process aware stub -- it has no way
7070 to specify the pid. */
7074 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7075 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7078 /* Don't wait for it to die. I'm not really sure it matters whether
7079 we do or not. For the existing stubs, kill is a noop. */
7085 error (_("Can't kill process"));
7087 target_mourn_inferior ();
7091 remote_mourn (struct target_ops
*ops
)
7093 remote_mourn_1 (ops
);
7096 /* Worker function for remote_mourn. */
7098 remote_mourn_1 (struct target_ops
*target
)
7100 unpush_target (target
);
7102 /* remote_close takes care of doing most of the clean up. */
7103 generic_mourn_inferior ();
7107 extended_remote_mourn_1 (struct target_ops
*target
)
7109 struct remote_state
*rs
= get_remote_state ();
7111 /* In case we got here due to an error, but we're going to stay
7113 rs
->waiting_for_stop_reply
= 0;
7115 /* We're no longer interested in these events. */
7116 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7118 /* If the current general thread belonged to the process we just
7119 detached from or has exited, the remote side current general
7120 thread becomes undefined. Considering a case like this:
7122 - We just got here due to a detach.
7123 - The process that we're detaching from happens to immediately
7124 report a global breakpoint being hit in non-stop mode, in the
7125 same thread we had selected before.
7126 - GDB attaches to this process again.
7127 - This event happens to be the next event we handle.
7129 GDB would consider that the current general thread didn't need to
7130 be set on the stub side (with Hg), since for all it knew,
7131 GENERAL_THREAD hadn't changed.
7133 Notice that although in all-stop mode, the remote server always
7134 sets the current thread to the thread reporting the stop event,
7135 that doesn't happen in non-stop mode; in non-stop, the stub *must
7136 not* change the current thread when reporting a breakpoint hit,
7137 due to the decoupling of event reporting and event handling.
7139 To keep things simple, we always invalidate our notion of the
7141 record_currthread (minus_one_ptid
);
7143 /* Unlike "target remote", we do not want to unpush the target; then
7144 the next time the user says "run", we won't be connected. */
7146 /* Call common code to mark the inferior as not running. */
7147 generic_mourn_inferior ();
7149 if (!have_inferiors ())
7151 if (!remote_multi_process_p (rs
))
7153 /* Check whether the target is running now - some remote stubs
7154 automatically restart after kill. */
7156 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7158 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7160 /* Assume that the target has been restarted. Set inferior_ptid
7161 so that bits of core GDB realizes there's something here, e.g.,
7162 so that the user can say "kill" again. */
7163 inferior_ptid
= magic_null_ptid
;
7170 extended_remote_mourn (struct target_ops
*ops
)
7172 extended_remote_mourn_1 (ops
);
7176 extended_remote_run (char *args
)
7178 struct remote_state
*rs
= get_remote_state ();
7181 /* If the user has disabled vRun support, or we have detected that
7182 support is not available, do not try it. */
7183 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7186 strcpy (rs
->buf
, "vRun;");
7187 len
= strlen (rs
->buf
);
7189 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7190 error (_("Remote file name too long for run packet"));
7191 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7193 gdb_assert (args
!= NULL
);
7196 struct cleanup
*back_to
;
7200 argv
= gdb_buildargv (args
);
7201 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7202 for (i
= 0; argv
[i
] != NULL
; i
++)
7204 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7205 error (_("Argument list too long for run packet"));
7206 rs
->buf
[len
++] = ';';
7207 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7209 do_cleanups (back_to
);
7212 rs
->buf
[len
++] = '\0';
7215 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7217 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7219 /* We have a wait response; we don't need it, though. All is well. */
7222 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7223 /* It wasn't disabled before, but it is now. */
7227 if (remote_exec_file
[0] == '\0')
7228 error (_("Running the default executable on the remote target failed; "
7229 "try \"set remote exec-file\"?"));
7231 error (_("Running \"%s\" on the remote target failed"),
7236 /* In the extended protocol we want to be able to do things like
7237 "run" and have them basically work as expected. So we need
7238 a special create_inferior function. We support changing the
7239 executable file and the command line arguments, but not the
7243 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7244 char **env
, int from_tty
)
7246 /* If running asynchronously, register the target file descriptor
7247 with the event loop. */
7248 if (target_can_async_p ())
7249 target_async (inferior_event_handler
, 0);
7251 /* Now restart the remote server. */
7252 if (extended_remote_run (args
) == -1)
7254 /* vRun was not supported. Fail if we need it to do what the
7256 if (remote_exec_file
[0])
7257 error (_("Remote target does not support \"set remote exec-file\""));
7259 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7261 /* Fall back to "R". */
7262 extended_remote_restart ();
7265 if (!have_inferiors ())
7267 /* Clean up from the last time we ran, before we mark the target
7268 running again. This will mark breakpoints uninserted, and
7269 get_offsets may insert breakpoints. */
7270 init_thread_list ();
7271 init_wait_for_inferior ();
7274 /* Now mark the inferior as running before we do anything else. */
7275 inferior_ptid
= magic_null_ptid
;
7277 /* Now, if we have thread information, update inferior_ptid. */
7278 inferior_ptid
= remote_current_thread (inferior_ptid
);
7280 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7281 add_thread_silent (inferior_ptid
);
7283 /* Get updated offsets, if the stub uses qOffsets. */
7288 extended_remote_create_inferior (struct target_ops
*ops
,
7289 char *exec_file
, char *args
,
7290 char **env
, int from_tty
)
7292 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7296 /* Insert a breakpoint. On targets that have software breakpoint
7297 support, we ask the remote target to do the work; on targets
7298 which don't, we insert a traditional memory breakpoint. */
7301 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7302 struct bp_target_info
*bp_tgt
)
7304 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7305 If it succeeds, then set the support to PACKET_ENABLE. If it
7306 fails, and the user has explicitly requested the Z support then
7307 report an error, otherwise, mark it disabled and go on. */
7309 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7311 CORE_ADDR addr
= bp_tgt
->placed_address
;
7312 struct remote_state
*rs
;
7316 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7318 rs
= get_remote_state ();
7324 addr
= (ULONGEST
) remote_address_masked (addr
);
7325 p
+= hexnumstr (p
, addr
);
7326 sprintf (p
, ",%d", bpsize
);
7329 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7331 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7336 bp_tgt
->placed_address
= addr
;
7337 bp_tgt
->placed_size
= bpsize
;
7339 case PACKET_UNKNOWN
:
7344 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7348 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7349 struct bp_target_info
*bp_tgt
)
7351 CORE_ADDR addr
= bp_tgt
->placed_address
;
7352 struct remote_state
*rs
= get_remote_state ();
7354 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7362 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7363 p
+= hexnumstr (p
, addr
);
7364 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7367 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7369 return (rs
->buf
[0] == 'E');
7372 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7376 watchpoint_to_Z_packet (int type
)
7381 return Z_PACKET_WRITE_WP
;
7384 return Z_PACKET_READ_WP
;
7387 return Z_PACKET_ACCESS_WP
;
7390 internal_error (__FILE__
, __LINE__
,
7391 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7396 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
7398 struct remote_state
*rs
= get_remote_state ();
7400 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7402 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7405 sprintf (rs
->buf
, "Z%x,", packet
);
7406 p
= strchr (rs
->buf
, '\0');
7407 addr
= remote_address_masked (addr
);
7408 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7409 sprintf (p
, ",%x", len
);
7412 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7414 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7418 case PACKET_UNKNOWN
:
7423 internal_error (__FILE__
, __LINE__
,
7424 _("remote_insert_watchpoint: reached end of function"));
7429 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
7431 struct remote_state
*rs
= get_remote_state ();
7433 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7435 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7438 sprintf (rs
->buf
, "z%x,", packet
);
7439 p
= strchr (rs
->buf
, '\0');
7440 addr
= remote_address_masked (addr
);
7441 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7442 sprintf (p
, ",%x", len
);
7444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7446 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7449 case PACKET_UNKNOWN
:
7454 internal_error (__FILE__
, __LINE__
,
7455 _("remote_remove_watchpoint: reached end of function"));
7459 int remote_hw_watchpoint_limit
= -1;
7460 int remote_hw_breakpoint_limit
= -1;
7463 remote_check_watch_resources (int type
, int cnt
, int ot
)
7465 if (type
== bp_hardware_breakpoint
)
7467 if (remote_hw_breakpoint_limit
== 0)
7469 else if (remote_hw_breakpoint_limit
< 0)
7471 else if (cnt
<= remote_hw_breakpoint_limit
)
7476 if (remote_hw_watchpoint_limit
== 0)
7478 else if (remote_hw_watchpoint_limit
< 0)
7482 else if (cnt
<= remote_hw_watchpoint_limit
)
7489 remote_stopped_by_watchpoint (void)
7491 return remote_stopped_by_watchpoint_p
;
7495 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7498 if (remote_stopped_by_watchpoint ())
7500 *addr_p
= remote_watch_data_address
;
7509 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7510 struct bp_target_info
*bp_tgt
)
7513 struct remote_state
*rs
;
7516 /* The length field should be set to the size of a breakpoint
7517 instruction, even though we aren't inserting one ourselves. */
7519 gdbarch_remote_breakpoint_from_pc
7520 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7522 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7525 rs
= get_remote_state ();
7532 addr
= remote_address_masked (bp_tgt
->placed_address
);
7533 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7534 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7537 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7539 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7542 case PACKET_UNKNOWN
:
7547 internal_error (__FILE__
, __LINE__
,
7548 _("remote_insert_hw_breakpoint: reached end of function"));
7553 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7554 struct bp_target_info
*bp_tgt
)
7557 struct remote_state
*rs
= get_remote_state ();
7560 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7567 addr
= remote_address_masked (bp_tgt
->placed_address
);
7568 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7569 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7572 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7574 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7577 case PACKET_UNKNOWN
:
7582 internal_error (__FILE__
, __LINE__
,
7583 _("remote_remove_hw_breakpoint: reached end of function"));
7586 /* Table used by the crc32 function to calcuate the checksum. */
7588 static unsigned long crc32_table
[256] =
7591 static unsigned long
7592 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7594 if (!crc32_table
[1])
7596 /* Initialize the CRC table and the decoding table. */
7600 for (i
= 0; i
< 256; i
++)
7602 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7603 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7610 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7616 /* Verify memory using the "qCRC:" request. */
7619 remote_verify_memory (struct target_ops
*ops
,
7620 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
7622 struct remote_state
*rs
= get_remote_state ();
7623 unsigned long host_crc
, target_crc
;
7626 /* FIXME: assumes lma can fit into long. */
7627 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7628 (long) lma
, (long) size
);
7631 /* Be clever; compute the host_crc before waiting for target
7633 host_crc
= crc32 (data
, size
, 0xffffffff);
7635 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7636 if (rs
->buf
[0] == 'E')
7639 if (rs
->buf
[0] != 'C')
7640 error (_("remote target does not support this operation"));
7642 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7643 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7645 return (host_crc
== target_crc
);
7648 /* compare-sections command
7650 With no arguments, compares each loadable section in the exec bfd
7651 with the same memory range on the target, and reports mismatches.
7652 Useful for verifying the image on the target against the exec file. */
7655 compare_sections_command (char *args
, int from_tty
)
7658 struct cleanup
*old_chain
;
7660 const char *sectname
;
7668 error (_("command cannot be used without an exec file"));
7670 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7672 if (!(s
->flags
& SEC_LOAD
))
7673 continue; /* skip non-loadable section */
7675 size
= bfd_get_section_size (s
);
7677 continue; /* skip zero-length section */
7679 sectname
= bfd_get_section_name (exec_bfd
, s
);
7680 if (args
&& strcmp (args
, sectname
) != 0)
7681 continue; /* not the section selected by user */
7683 matched
= 1; /* do this section */
7686 sectdata
= xmalloc (size
);
7687 old_chain
= make_cleanup (xfree
, sectdata
);
7688 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
7690 res
= target_verify_memory (sectdata
, lma
, size
);
7693 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
7694 paddress (target_gdbarch
, lma
),
7695 paddress (target_gdbarch
, lma
+ size
));
7697 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
7698 paddress (target_gdbarch
, lma
),
7699 paddress (target_gdbarch
, lma
+ size
));
7701 printf_filtered ("matched.\n");
7704 printf_filtered ("MIS-MATCHED!\n");
7708 do_cleanups (old_chain
);
7711 warning (_("One or more sections of the remote executable does not match\n\
7712 the loaded file\n"));
7713 if (args
&& !matched
)
7714 printf_filtered (_("No loaded section named '%s'.\n"), args
);
7717 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
7718 into remote target. The number of bytes written to the remote
7719 target is returned, or -1 for error. */
7722 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
7723 const char *annex
, const gdb_byte
*writebuf
,
7724 ULONGEST offset
, LONGEST len
,
7725 struct packet_config
*packet
)
7729 struct remote_state
*rs
= get_remote_state ();
7730 int max_size
= get_memory_write_packet_size ();
7732 if (packet
->support
== PACKET_DISABLE
)
7735 /* Insert header. */
7736 i
= snprintf (rs
->buf
, max_size
,
7737 "qXfer:%s:write:%s:%s:",
7738 object_name
, annex
? annex
: "",
7739 phex_nz (offset
, sizeof offset
));
7740 max_size
-= (i
+ 1);
7742 /* Escape as much data as fits into rs->buf. */
7743 buf_len
= remote_escape_output
7744 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
7746 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
7747 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7748 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7751 unpack_varlen_hex (rs
->buf
, &n
);
7755 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
7756 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
7757 number of bytes read is returned, or 0 for EOF, or -1 for error.
7758 The number of bytes read may be less than LEN without indicating an
7759 EOF. PACKET is checked and updated to indicate whether the remote
7760 target supports this object. */
7763 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
7765 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
7766 struct packet_config
*packet
)
7768 static char *finished_object
;
7769 static char *finished_annex
;
7770 static ULONGEST finished_offset
;
7772 struct remote_state
*rs
= get_remote_state ();
7773 LONGEST i
, n
, packet_len
;
7775 if (packet
->support
== PACKET_DISABLE
)
7778 /* Check whether we've cached an end-of-object packet that matches
7780 if (finished_object
)
7782 if (strcmp (object_name
, finished_object
) == 0
7783 && strcmp (annex
? annex
: "", finished_annex
) == 0
7784 && offset
== finished_offset
)
7787 /* Otherwise, we're now reading something different. Discard
7789 xfree (finished_object
);
7790 xfree (finished_annex
);
7791 finished_object
= NULL
;
7792 finished_annex
= NULL
;
7795 /* Request only enough to fit in a single packet. The actual data
7796 may not, since we don't know how much of it will need to be escaped;
7797 the target is free to respond with slightly less data. We subtract
7798 five to account for the response type and the protocol frame. */
7799 n
= min (get_remote_packet_size () - 5, len
);
7800 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
7801 object_name
, annex
? annex
: "",
7802 phex_nz (offset
, sizeof offset
),
7803 phex_nz (n
, sizeof n
));
7804 i
= putpkt (rs
->buf
);
7809 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
7810 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7813 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
7814 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
7816 /* 'm' means there is (or at least might be) more data after this
7817 batch. That does not make sense unless there's at least one byte
7818 of data in this reply. */
7819 if (rs
->buf
[0] == 'm' && packet_len
== 1)
7820 error (_("Remote qXfer reply contained no data."));
7822 /* Got some data. */
7823 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
7825 /* 'l' is an EOF marker, possibly including a final block of data,
7826 or possibly empty. If we have the final block of a non-empty
7827 object, record this fact to bypass a subsequent partial read. */
7828 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
7830 finished_object
= xstrdup (object_name
);
7831 finished_annex
= xstrdup (annex
? annex
: "");
7832 finished_offset
= offset
+ i
;
7839 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
7840 const char *annex
, gdb_byte
*readbuf
,
7841 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
7843 struct remote_state
*rs
;
7848 set_general_thread (inferior_ptid
);
7850 rs
= get_remote_state ();
7852 /* Handle memory using the standard memory routines. */
7853 if (object
== TARGET_OBJECT_MEMORY
)
7858 /* If the remote target is connected but not running, we should
7859 pass this request down to a lower stratum (e.g. the executable
7861 if (!target_has_execution
)
7864 if (writebuf
!= NULL
)
7865 xfered
= remote_write_bytes (offset
, writebuf
, len
);
7867 xfered
= remote_read_bytes (offset
, readbuf
, len
);
7871 else if (xfered
== 0 && errno
== 0)
7877 /* Handle SPU memory using qxfer packets. */
7878 if (object
== TARGET_OBJECT_SPU
)
7881 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
7882 &remote_protocol_packets
7883 [PACKET_qXfer_spu_read
]);
7885 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
7886 &remote_protocol_packets
7887 [PACKET_qXfer_spu_write
]);
7890 /* Handle extra signal info using qxfer packets. */
7891 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
7894 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
7895 &remote_protocol_packets
7896 [PACKET_qXfer_siginfo_read
]);
7898 return remote_write_qxfer (ops
, "siginfo", annex
, writebuf
, offset
, len
,
7899 &remote_protocol_packets
7900 [PACKET_qXfer_siginfo_write
]);
7903 /* Only handle flash writes. */
7904 if (writebuf
!= NULL
)
7910 case TARGET_OBJECT_FLASH
:
7911 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
7915 else if (xfered
== 0 && errno
== 0)
7925 /* Map pre-existing objects onto letters. DO NOT do this for new
7926 objects!!! Instead specify new query packets. */
7929 case TARGET_OBJECT_AVR
:
7933 case TARGET_OBJECT_AUXV
:
7934 gdb_assert (annex
== NULL
);
7935 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
7936 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
7938 case TARGET_OBJECT_AVAILABLE_FEATURES
:
7939 return remote_read_qxfer
7940 (ops
, "features", annex
, readbuf
, offset
, len
,
7941 &remote_protocol_packets
[PACKET_qXfer_features
]);
7943 case TARGET_OBJECT_LIBRARIES
:
7944 return remote_read_qxfer
7945 (ops
, "libraries", annex
, readbuf
, offset
, len
,
7946 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
7948 case TARGET_OBJECT_MEMORY_MAP
:
7949 gdb_assert (annex
== NULL
);
7950 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
7951 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
7953 case TARGET_OBJECT_OSDATA
:
7954 /* Should only get here if we're connected. */
7955 gdb_assert (remote_desc
);
7956 return remote_read_qxfer
7957 (ops
, "osdata", annex
, readbuf
, offset
, len
,
7958 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
7960 case TARGET_OBJECT_THREADS
:
7961 gdb_assert (annex
== NULL
);
7962 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
7963 &remote_protocol_packets
[PACKET_qXfer_threads
]);
7969 /* Note: a zero OFFSET and LEN can be used to query the minimum
7971 if (offset
== 0 && len
== 0)
7972 return (get_remote_packet_size ());
7973 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
7974 large enough let the caller deal with it. */
7975 if (len
< get_remote_packet_size ())
7977 len
= get_remote_packet_size ();
7979 /* Except for querying the minimum buffer size, target must be open. */
7981 error (_("remote query is only available after target open"));
7983 gdb_assert (annex
!= NULL
);
7984 gdb_assert (readbuf
!= NULL
);
7990 /* We used one buffer char for the remote protocol q command and
7991 another for the query type. As the remote protocol encapsulation
7992 uses 4 chars plus one extra in case we are debugging
7993 (remote_debug), we have PBUFZIZ - 7 left to pack the query
7996 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
7998 /* Bad caller may have sent forbidden characters. */
7999 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8004 gdb_assert (annex
[i
] == '\0');
8006 i
= putpkt (rs
->buf
);
8010 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8011 strcpy ((char *) readbuf
, rs
->buf
);
8013 return strlen ((char *) readbuf
);
8017 remote_search_memory (struct target_ops
* ops
,
8018 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8019 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8020 CORE_ADDR
*found_addrp
)
8022 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8023 struct remote_state
*rs
= get_remote_state ();
8024 int max_size
= get_memory_write_packet_size ();
8025 struct packet_config
*packet
=
8026 &remote_protocol_packets
[PACKET_qSearch_memory
];
8027 /* number of packet bytes used to encode the pattern,
8028 this could be more than PATTERN_LEN due to escape characters */
8029 int escaped_pattern_len
;
8030 /* amount of pattern that was encodable in the packet */
8031 int used_pattern_len
;
8034 ULONGEST found_addr
;
8036 /* Don't go to the target if we don't have to.
8037 This is done before checking packet->support to avoid the possibility that
8038 a success for this edge case means the facility works in general. */
8039 if (pattern_len
> search_space_len
)
8041 if (pattern_len
== 0)
8043 *found_addrp
= start_addr
;
8047 /* If we already know the packet isn't supported, fall back to the simple
8048 way of searching memory. */
8050 if (packet
->support
== PACKET_DISABLE
)
8052 /* Target doesn't provided special support, fall back and use the
8053 standard support (copy memory and do the search here). */
8054 return simple_search_memory (ops
, start_addr
, search_space_len
,
8055 pattern
, pattern_len
, found_addrp
);
8058 /* Insert header. */
8059 i
= snprintf (rs
->buf
, max_size
,
8060 "qSearch:memory:%s;%s;",
8061 phex_nz (start_addr
, addr_size
),
8062 phex_nz (search_space_len
, sizeof (search_space_len
)));
8063 max_size
-= (i
+ 1);
8065 /* Escape as much data as fits into rs->buf. */
8066 escaped_pattern_len
=
8067 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8068 &used_pattern_len
, max_size
);
8070 /* Bail if the pattern is too large. */
8071 if (used_pattern_len
!= pattern_len
)
8072 error ("Pattern is too large to transmit to remote target.");
8074 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8075 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8076 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8078 /* The request may not have worked because the command is not
8079 supported. If so, fall back to the simple way. */
8080 if (packet
->support
== PACKET_DISABLE
)
8082 return simple_search_memory (ops
, start_addr
, search_space_len
,
8083 pattern
, pattern_len
, found_addrp
);
8088 if (rs
->buf
[0] == '0')
8090 else if (rs
->buf
[0] == '1')
8093 if (rs
->buf
[1] != ',')
8094 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8095 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8096 *found_addrp
= found_addr
;
8099 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8105 remote_rcmd (char *command
,
8106 struct ui_file
*outbuf
)
8108 struct remote_state
*rs
= get_remote_state ();
8112 error (_("remote rcmd is only available after target open"));
8114 /* Send a NULL command across as an empty command. */
8115 if (command
== NULL
)
8118 /* The query prefix. */
8119 strcpy (rs
->buf
, "qRcmd,");
8120 p
= strchr (rs
->buf
, '\0');
8122 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
8123 error (_("\"monitor\" command ``%s'' is too long."), command
);
8125 /* Encode the actual command. */
8126 bin2hex ((gdb_byte
*) command
, p
, 0);
8128 if (putpkt (rs
->buf
) < 0)
8129 error (_("Communication problem with target."));
8131 /* get/display the response */
8136 /* XXX - see also remote_get_noisy_reply(). */
8138 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8141 error (_("Target does not support this command."));
8142 if (buf
[0] == 'O' && buf
[1] != 'K')
8144 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8147 if (strcmp (buf
, "OK") == 0)
8149 if (strlen (buf
) == 3 && buf
[0] == 'E'
8150 && isdigit (buf
[1]) && isdigit (buf
[2]))
8152 error (_("Protocol error with Rcmd"));
8154 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8156 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8157 fputc_unfiltered (c
, outbuf
);
8163 static VEC(mem_region_s
) *
8164 remote_memory_map (struct target_ops
*ops
)
8166 VEC(mem_region_s
) *result
= NULL
;
8167 char *text
= target_read_stralloc (¤t_target
,
8168 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8172 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8173 result
= parse_memory_map (text
);
8174 do_cleanups (back_to
);
8181 packet_command (char *args
, int from_tty
)
8183 struct remote_state
*rs
= get_remote_state ();
8186 error (_("command can only be used with remote target"));
8189 error (_("remote-packet command requires packet text as argument"));
8191 puts_filtered ("sending: ");
8192 print_packet (args
);
8193 puts_filtered ("\n");
8196 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8197 puts_filtered ("received: ");
8198 print_packet (rs
->buf
);
8199 puts_filtered ("\n");
8203 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8205 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8207 static void threadset_test_cmd (char *cmd
, int tty
);
8209 static void threadalive_test (char *cmd
, int tty
);
8211 static void threadlist_test_cmd (char *cmd
, int tty
);
8213 int get_and_display_threadinfo (threadref
*ref
);
8215 static void threadinfo_test_cmd (char *cmd
, int tty
);
8217 static int thread_display_step (threadref
*ref
, void *context
);
8219 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8221 static void init_remote_threadtests (void);
8223 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8226 threadset_test_cmd (char *cmd
, int tty
)
8228 int sample_thread
= SAMPLE_THREAD
;
8230 printf_filtered (_("Remote threadset test\n"));
8231 set_general_thread (sample_thread
);
8236 threadalive_test (char *cmd
, int tty
)
8238 int sample_thread
= SAMPLE_THREAD
;
8239 int pid
= ptid_get_pid (inferior_ptid
);
8240 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8242 if (remote_thread_alive (ptid
))
8243 printf_filtered ("PASS: Thread alive test\n");
8245 printf_filtered ("FAIL: Thread alive test\n");
8248 void output_threadid (char *title
, threadref
*ref
);
8251 output_threadid (char *title
, threadref
*ref
)
8255 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8257 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8261 threadlist_test_cmd (char *cmd
, int tty
)
8264 threadref nextthread
;
8265 int done
, result_count
;
8266 threadref threadlist
[3];
8268 printf_filtered ("Remote Threadlist test\n");
8269 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8270 &result_count
, &threadlist
[0]))
8271 printf_filtered ("FAIL: threadlist test\n");
8274 threadref
*scan
= threadlist
;
8275 threadref
*limit
= scan
+ result_count
;
8277 while (scan
< limit
)
8278 output_threadid (" thread ", scan
++);
8283 display_thread_info (struct gdb_ext_thread_info
*info
)
8285 output_threadid ("Threadid: ", &info
->threadid
);
8286 printf_filtered ("Name: %s\n ", info
->shortname
);
8287 printf_filtered ("State: %s\n", info
->display
);
8288 printf_filtered ("other: %s\n\n", info
->more_display
);
8292 get_and_display_threadinfo (threadref
*ref
)
8296 struct gdb_ext_thread_info threadinfo
;
8298 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8299 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8300 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8301 display_thread_info (&threadinfo
);
8306 threadinfo_test_cmd (char *cmd
, int tty
)
8308 int athread
= SAMPLE_THREAD
;
8312 int_to_threadref (&thread
, athread
);
8313 printf_filtered ("Remote Threadinfo test\n");
8314 if (!get_and_display_threadinfo (&thread
))
8315 printf_filtered ("FAIL cannot get thread info\n");
8319 thread_display_step (threadref
*ref
, void *context
)
8321 /* output_threadid(" threadstep ",ref); *//* simple test */
8322 return get_and_display_threadinfo (ref
);
8326 threadlist_update_test_cmd (char *cmd
, int tty
)
8328 printf_filtered ("Remote Threadlist update test\n");
8329 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8333 init_remote_threadtests (void)
8335 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
8336 Fetch and print the remote list of thread identifiers, one pkt only"));
8337 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8338 _("Fetch and display info about one thread"));
8339 add_com ("tset", class_obscure
, threadset_test_cmd
,
8340 _("Test setting to a different thread"));
8341 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8342 _("Iterate through updating all remote thread info"));
8343 add_com ("talive", class_obscure
, threadalive_test
,
8344 _(" Remote thread alive test "));
8349 /* Convert a thread ID to a string. Returns the string in a static
8353 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8355 static char buf
[64];
8356 struct remote_state
*rs
= get_remote_state ();
8358 if (ptid_is_pid (ptid
))
8360 /* Printing an inferior target id. */
8362 /* When multi-process extensions are off, there's no way in the
8363 remote protocol to know the remote process id, if there's any
8364 at all. There's one exception --- when we're connected with
8365 target extended-remote, and we manually attached to a process
8366 with "attach PID". We don't record anywhere a flag that
8367 allows us to distinguish that case from the case of
8368 connecting with extended-remote and the stub already being
8369 attached to a process, and reporting yes to qAttached, hence
8370 no smart special casing here. */
8371 if (!remote_multi_process_p (rs
))
8373 xsnprintf (buf
, sizeof buf
, "Remote target");
8377 return normal_pid_to_str (ptid
);
8381 if (ptid_equal (magic_null_ptid
, ptid
))
8382 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8383 else if (remote_multi_process_p (rs
))
8384 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8385 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8387 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8388 ptid_get_tid (ptid
));
8393 /* Get the address of the thread local variable in OBJFILE which is
8394 stored at OFFSET within the thread local storage for thread PTID. */
8397 remote_get_thread_local_address (struct target_ops
*ops
,
8398 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8400 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8402 struct remote_state
*rs
= get_remote_state ();
8404 char *endp
= rs
->buf
+ get_remote_packet_size ();
8405 enum packet_result result
;
8407 strcpy (p
, "qGetTLSAddr:");
8409 p
= write_ptid (p
, endp
, ptid
);
8411 p
+= hexnumstr (p
, offset
);
8413 p
+= hexnumstr (p
, lm
);
8417 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8418 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8419 if (result
== PACKET_OK
)
8423 unpack_varlen_hex (rs
->buf
, &result
);
8426 else if (result
== PACKET_UNKNOWN
)
8427 throw_error (TLS_GENERIC_ERROR
,
8428 _("Remote target doesn't support qGetTLSAddr packet"));
8430 throw_error (TLS_GENERIC_ERROR
,
8431 _("Remote target failed to process qGetTLSAddr request"));
8434 throw_error (TLS_GENERIC_ERROR
,
8435 _("TLS not supported or disabled on this target"));
8440 /* Support for inferring a target description based on the current
8441 architecture and the size of a 'g' packet. While the 'g' packet
8442 can have any size (since optional registers can be left off the
8443 end), some sizes are easily recognizable given knowledge of the
8444 approximate architecture. */
8446 struct remote_g_packet_guess
8449 const struct target_desc
*tdesc
;
8451 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8452 DEF_VEC_O(remote_g_packet_guess_s
);
8454 struct remote_g_packet_data
8456 VEC(remote_g_packet_guess_s
) *guesses
;
8459 static struct gdbarch_data
*remote_g_packet_data_handle
;
8462 remote_g_packet_data_init (struct obstack
*obstack
)
8464 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8468 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8469 const struct target_desc
*tdesc
)
8471 struct remote_g_packet_data
*data
8472 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8473 struct remote_g_packet_guess new_guess
, *guess
;
8476 gdb_assert (tdesc
!= NULL
);
8479 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8481 if (guess
->bytes
== bytes
)
8482 internal_error (__FILE__
, __LINE__
,
8483 "Duplicate g packet description added for size %d",
8486 new_guess
.bytes
= bytes
;
8487 new_guess
.tdesc
= tdesc
;
8488 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8491 /* Return 1 if remote_read_description would do anything on this target
8492 and architecture, 0 otherwise. */
8495 remote_read_description_p (struct target_ops
*target
)
8497 struct remote_g_packet_data
*data
8498 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8500 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8506 static const struct target_desc
*
8507 remote_read_description (struct target_ops
*target
)
8509 struct remote_g_packet_data
*data
8510 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8512 /* Do not try this during initial connection, when we do not know
8513 whether there is a running but stopped thread. */
8514 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8517 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8519 struct remote_g_packet_guess
*guess
;
8521 int bytes
= send_g_packet ();
8524 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8526 if (guess
->bytes
== bytes
)
8527 return guess
->tdesc
;
8529 /* We discard the g packet. A minor optimization would be to
8530 hold on to it, and fill the register cache once we have selected
8531 an architecture, but it's too tricky to do safely. */
8537 /* Remote file transfer support. This is host-initiated I/O, not
8538 target-initiated; for target-initiated, see remote-fileio.c. */
8540 /* If *LEFT is at least the length of STRING, copy STRING to
8541 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8542 decrease *LEFT. Otherwise raise an error. */
8545 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8547 int len
= strlen (string
);
8550 error (_("Packet too long for target."));
8552 memcpy (*buffer
, string
, len
);
8556 /* NUL-terminate the buffer as a convenience, if there is
8562 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8563 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8564 decrease *LEFT. Otherwise raise an error. */
8567 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8570 if (2 * len
> *left
)
8571 error (_("Packet too long for target."));
8573 bin2hex (bytes
, *buffer
, len
);
8577 /* NUL-terminate the buffer as a convenience, if there is
8583 /* If *LEFT is large enough, convert VALUE to hex and add it 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_int (char **buffer
, int *left
, ULONGEST value
)
8590 int len
= hexnumlen (value
);
8593 error (_("Packet too long for target."));
8595 hexnumstr (*buffer
, value
);
8599 /* NUL-terminate the buffer as a convenience, if there is
8605 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8606 value, *REMOTE_ERRNO to the remote error number or zero if none
8607 was included, and *ATTACHMENT to point to the start of the annex
8608 if any. The length of the packet isn't needed here; there may
8609 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8611 Return 0 if the packet could be parsed, -1 if it could not. If
8612 -1 is returned, the other variables may not be initialized. */
8615 remote_hostio_parse_result (char *buffer
, int *retcode
,
8616 int *remote_errno
, char **attachment
)
8623 if (buffer
[0] != 'F')
8627 *retcode
= strtol (&buffer
[1], &p
, 16);
8628 if (errno
!= 0 || p
== &buffer
[1])
8631 /* Check for ",errno". */
8635 *remote_errno
= strtol (p
+ 1, &p2
, 16);
8636 if (errno
!= 0 || p
+ 1 == p2
)
8641 /* Check for ";attachment". If there is no attachment, the
8642 packet should end here. */
8645 *attachment
= p
+ 1;
8648 else if (*p
== '\0')
8654 /* Send a prepared I/O packet to the target and read its response.
8655 The prepared packet is in the global RS->BUF before this function
8656 is called, and the answer is there when we return.
8658 COMMAND_BYTES is the length of the request to send, which may include
8659 binary data. WHICH_PACKET is the packet configuration to check
8660 before attempting a packet. If an error occurs, *REMOTE_ERRNO
8661 is set to the error number and -1 is returned. Otherwise the value
8662 returned by the function is returned.
8664 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
8665 attachment is expected; an error will be reported if there's a
8666 mismatch. If one is found, *ATTACHMENT will be set to point into
8667 the packet buffer and *ATTACHMENT_LEN will be set to the
8668 attachment's length. */
8671 remote_hostio_send_command (int command_bytes
, int which_packet
,
8672 int *remote_errno
, char **attachment
,
8673 int *attachment_len
)
8675 struct remote_state
*rs
= get_remote_state ();
8676 int ret
, bytes_read
;
8677 char *attachment_tmp
;
8680 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
8682 *remote_errno
= FILEIO_ENOSYS
;
8686 putpkt_binary (rs
->buf
, command_bytes
);
8687 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8689 /* If it timed out, something is wrong. Don't try to parse the
8693 *remote_errno
= FILEIO_EINVAL
;
8697 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
8700 *remote_errno
= FILEIO_EINVAL
;
8702 case PACKET_UNKNOWN
:
8703 *remote_errno
= FILEIO_ENOSYS
;
8709 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
8712 *remote_errno
= FILEIO_EINVAL
;
8716 /* Make sure we saw an attachment if and only if we expected one. */
8717 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
8718 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
8720 *remote_errno
= FILEIO_EINVAL
;
8724 /* If an attachment was found, it must point into the packet buffer;
8725 work out how many bytes there were. */
8726 if (attachment_tmp
!= NULL
)
8728 *attachment
= attachment_tmp
;
8729 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
8735 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
8736 remote file descriptor, or -1 if an error occurs (and set
8740 remote_hostio_open (const char *filename
, int flags
, int mode
,
8743 struct remote_state
*rs
= get_remote_state ();
8745 int left
= get_remote_packet_size () - 1;
8747 remote_buffer_add_string (&p
, &left
, "vFile:open:");
8749 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8751 remote_buffer_add_string (&p
, &left
, ",");
8753 remote_buffer_add_int (&p
, &left
, flags
);
8754 remote_buffer_add_string (&p
, &left
, ",");
8756 remote_buffer_add_int (&p
, &left
, mode
);
8758 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
8759 remote_errno
, NULL
, NULL
);
8762 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
8763 Return the number of bytes written, or -1 if an error occurs (and
8764 set *REMOTE_ERRNO). */
8767 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
8768 ULONGEST offset
, int *remote_errno
)
8770 struct remote_state
*rs
= get_remote_state ();
8772 int left
= get_remote_packet_size ();
8775 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
8777 remote_buffer_add_int (&p
, &left
, fd
);
8778 remote_buffer_add_string (&p
, &left
, ",");
8780 remote_buffer_add_int (&p
, &left
, offset
);
8781 remote_buffer_add_string (&p
, &left
, ",");
8783 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
8784 get_remote_packet_size () - (p
- rs
->buf
));
8786 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
8787 remote_errno
, NULL
, NULL
);
8790 /* Read up to LEN bytes FD on the remote target into READ_BUF
8791 Return the number of bytes read, or -1 if an error occurs (and
8792 set *REMOTE_ERRNO). */
8795 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
8796 ULONGEST offset
, int *remote_errno
)
8798 struct remote_state
*rs
= get_remote_state ();
8801 int left
= get_remote_packet_size ();
8802 int ret
, attachment_len
;
8805 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
8807 remote_buffer_add_int (&p
, &left
, fd
);
8808 remote_buffer_add_string (&p
, &left
, ",");
8810 remote_buffer_add_int (&p
, &left
, len
);
8811 remote_buffer_add_string (&p
, &left
, ",");
8813 remote_buffer_add_int (&p
, &left
, offset
);
8815 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
8816 remote_errno
, &attachment
,
8822 read_len
= remote_unescape_input (attachment
, attachment_len
,
8824 if (read_len
!= ret
)
8825 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
8830 /* Close FD on the remote target. Return 0, or -1 if an error occurs
8831 (and set *REMOTE_ERRNO). */
8834 remote_hostio_close (int fd
, int *remote_errno
)
8836 struct remote_state
*rs
= get_remote_state ();
8838 int left
= get_remote_packet_size () - 1;
8840 remote_buffer_add_string (&p
, &left
, "vFile:close:");
8842 remote_buffer_add_int (&p
, &left
, fd
);
8844 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
8845 remote_errno
, NULL
, NULL
);
8848 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
8849 occurs (and set *REMOTE_ERRNO). */
8852 remote_hostio_unlink (const char *filename
, int *remote_errno
)
8854 struct remote_state
*rs
= get_remote_state ();
8856 int left
= get_remote_packet_size () - 1;
8858 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
8860 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8863 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
8864 remote_errno
, NULL
, NULL
);
8868 remote_fileio_errno_to_host (int errnum
)
8892 case FILEIO_ENOTDIR
:
8912 case FILEIO_ENAMETOOLONG
:
8913 return ENAMETOOLONG
;
8919 remote_hostio_error (int errnum
)
8921 int host_error
= remote_fileio_errno_to_host (errnum
);
8923 if (host_error
== -1)
8924 error (_("Unknown remote I/O error %d"), errnum
);
8926 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
8930 remote_hostio_close_cleanup (void *opaque
)
8932 int fd
= *(int *) opaque
;
8935 remote_hostio_close (fd
, &remote_errno
);
8940 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
8942 const char *filename
= bfd_get_filename (abfd
);
8943 int fd
, remote_errno
;
8946 gdb_assert (remote_filename_p (filename
));
8948 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
8951 errno
= remote_fileio_errno_to_host (remote_errno
);
8952 bfd_set_error (bfd_error_system_call
);
8956 stream
= xmalloc (sizeof (int));
8962 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
8964 int fd
= *(int *)stream
;
8969 /* Ignore errors on close; these may happen if the remote
8970 connection was already torn down. */
8971 remote_hostio_close (fd
, &remote_errno
);
8977 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
8978 file_ptr nbytes
, file_ptr offset
)
8980 int fd
= *(int *)stream
;
8982 file_ptr pos
, bytes
;
8985 while (nbytes
> pos
)
8987 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
8988 offset
+ pos
, &remote_errno
);
8990 /* Success, but no bytes, means end-of-file. */
8994 errno
= remote_fileio_errno_to_host (remote_errno
);
8995 bfd_set_error (bfd_error_system_call
);
9006 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9008 /* FIXME: We should probably implement remote_hostio_stat. */
9009 sb
->st_size
= INT_MAX
;
9014 remote_filename_p (const char *filename
)
9016 return strncmp (filename
, "remote:", 7) == 0;
9020 remote_bfd_open (const char *remote_file
, const char *target
)
9022 return bfd_openr_iovec (remote_file
, target
,
9023 remote_bfd_iovec_open
, NULL
,
9024 remote_bfd_iovec_pread
,
9025 remote_bfd_iovec_close
,
9026 remote_bfd_iovec_stat
);
9030 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9032 struct cleanup
*back_to
, *close_cleanup
;
9033 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9036 int bytes_in_buffer
;
9041 error (_("command can only be used with remote target"));
9043 file
= fopen (local_file
, "rb");
9045 perror_with_name (local_file
);
9046 back_to
= make_cleanup_fclose (file
);
9048 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9050 0700, &remote_errno
);
9052 remote_hostio_error (remote_errno
);
9054 /* Send up to this many bytes at once. They won't all fit in the
9055 remote packet limit, so we'll transfer slightly fewer. */
9056 io_size
= get_remote_packet_size ();
9057 buffer
= xmalloc (io_size
);
9058 make_cleanup (xfree
, buffer
);
9060 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9062 bytes_in_buffer
= 0;
9065 while (bytes_in_buffer
|| !saw_eof
)
9069 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
9074 error (_("Error reading %s."), local_file
);
9077 /* EOF. Unless there is something still in the
9078 buffer from the last iteration, we are done. */
9080 if (bytes_in_buffer
== 0)
9088 bytes
+= bytes_in_buffer
;
9089 bytes_in_buffer
= 0;
9091 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
9094 remote_hostio_error (remote_errno
);
9095 else if (retcode
== 0)
9096 error (_("Remote write of %d bytes returned 0!"), bytes
);
9097 else if (retcode
< bytes
)
9099 /* Short write. Save the rest of the read data for the next
9101 bytes_in_buffer
= bytes
- retcode
;
9102 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9108 discard_cleanups (close_cleanup
);
9109 if (remote_hostio_close (fd
, &remote_errno
))
9110 remote_hostio_error (remote_errno
);
9113 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9114 do_cleanups (back_to
);
9118 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9120 struct cleanup
*back_to
, *close_cleanup
;
9121 int fd
, remote_errno
, bytes
, io_size
;
9127 error (_("command can only be used with remote target"));
9129 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9131 remote_hostio_error (remote_errno
);
9133 file
= fopen (local_file
, "wb");
9135 perror_with_name (local_file
);
9136 back_to
= make_cleanup_fclose (file
);
9138 /* Send up to this many bytes at once. They won't all fit in the
9139 remote packet limit, so we'll transfer slightly fewer. */
9140 io_size
= get_remote_packet_size ();
9141 buffer
= xmalloc (io_size
);
9142 make_cleanup (xfree
, buffer
);
9144 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9149 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9151 /* Success, but no bytes, means end-of-file. */
9154 remote_hostio_error (remote_errno
);
9158 bytes
= fwrite (buffer
, 1, bytes
, file
);
9160 perror_with_name (local_file
);
9163 discard_cleanups (close_cleanup
);
9164 if (remote_hostio_close (fd
, &remote_errno
))
9165 remote_hostio_error (remote_errno
);
9168 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9169 do_cleanups (back_to
);
9173 remote_file_delete (const char *remote_file
, int from_tty
)
9175 int retcode
, remote_errno
;
9178 error (_("command can only be used with remote target"));
9180 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9182 remote_hostio_error (remote_errno
);
9185 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9189 remote_put_command (char *args
, int from_tty
)
9191 struct cleanup
*back_to
;
9195 error_no_arg (_("file to put"));
9197 argv
= gdb_buildargv (args
);
9198 back_to
= make_cleanup_freeargv (argv
);
9199 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9200 error (_("Invalid parameters to remote put"));
9202 remote_file_put (argv
[0], argv
[1], from_tty
);
9204 do_cleanups (back_to
);
9208 remote_get_command (char *args
, int from_tty
)
9210 struct cleanup
*back_to
;
9214 error_no_arg (_("file to get"));
9216 argv
= gdb_buildargv (args
);
9217 back_to
= make_cleanup_freeargv (argv
);
9218 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9219 error (_("Invalid parameters to remote get"));
9221 remote_file_get (argv
[0], argv
[1], from_tty
);
9223 do_cleanups (back_to
);
9227 remote_delete_command (char *args
, int from_tty
)
9229 struct cleanup
*back_to
;
9233 error_no_arg (_("file to delete"));
9235 argv
= gdb_buildargv (args
);
9236 back_to
= make_cleanup_freeargv (argv
);
9237 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9238 error (_("Invalid parameters to remote delete"));
9240 remote_file_delete (argv
[0], from_tty
);
9242 do_cleanups (back_to
);
9246 remote_command (char *args
, int from_tty
)
9248 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9252 remote_can_execute_reverse (void)
9254 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9255 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9262 remote_supports_non_stop (void)
9268 remote_supports_multi_process (void)
9270 struct remote_state
*rs
= get_remote_state ();
9271 return remote_multi_process_p (rs
);
9275 remote_supports_cond_tracepoints (void)
9277 struct remote_state
*rs
= get_remote_state ();
9278 return rs
->cond_tracepoints
;
9282 remote_supports_fast_tracepoints (void)
9284 struct remote_state
*rs
= get_remote_state ();
9285 return rs
->fast_tracepoints
;
9289 remote_trace_init (void)
9292 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9293 if (strcmp (target_buf
, "OK") != 0)
9294 error (_("Target does not support this command."));
9297 static void free_actions_list (char **actions_list
);
9298 static void free_actions_list_cleanup_wrapper (void *);
9300 free_actions_list_cleanup_wrapper (void *al
)
9302 free_actions_list (al
);
9306 free_actions_list (char **actions_list
)
9310 if (actions_list
== 0)
9313 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9314 xfree (actions_list
[ndx
]);
9316 xfree (actions_list
);
9319 /* Recursive routine to walk through command list including loops, and
9320 download packets for each command. */
9323 remote_download_command_source (int num
, ULONGEST addr
,
9324 struct command_line
*cmds
)
9326 struct remote_state
*rs
= get_remote_state ();
9327 struct command_line
*cmd
;
9329 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9331 QUIT
; /* allow user to bail out with ^C */
9332 strcpy (rs
->buf
, "QTDPsrc:");
9333 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9334 rs
->buf
+ strlen (rs
->buf
),
9335 rs
->buf_size
- strlen (rs
->buf
));
9337 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9338 if (strcmp (target_buf
, "OK"))
9339 warning (_("Target does not support source download."));
9341 if (cmd
->control_type
== while_control
9342 || cmd
->control_type
== while_stepping_control
)
9344 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9346 QUIT
; /* allow user to bail out with ^C */
9347 strcpy (rs
->buf
, "QTDPsrc:");
9348 encode_source_string (num
, addr
, "cmd", "end",
9349 rs
->buf
+ strlen (rs
->buf
),
9350 rs
->buf_size
- strlen (rs
->buf
));
9352 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9353 if (strcmp (target_buf
, "OK"))
9354 warning (_("Target does not support source download."));
9360 remote_download_tracepoint (struct breakpoint
*t
)
9362 struct bp_location
*loc
;
9367 char **stepping_actions
;
9369 struct cleanup
*old_chain
= NULL
;
9370 struct agent_expr
*aexpr
;
9371 struct cleanup
*aexpr_chain
= NULL
;
9374 /* Iterate over all the tracepoint locations. It's up to the target to
9375 notice multiple tracepoint packets with the same number but different
9376 addresses, and treat them as multiple locations. */
9377 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
9379 encode_actions (t
, loc
, &tdp_actions
, &stepping_actions
);
9380 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9382 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
9384 tpaddr
= loc
->address
;
9385 sprintf_vma (addrbuf
, tpaddr
);
9386 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
9387 addrbuf
, /* address */
9388 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
9389 t
->step_count
, t
->pass_count
);
9390 /* Fast tracepoints are mostly handled by the target, but we can
9391 tell the target how big of an instruction block should be moved
9393 if (t
->type
== bp_fast_tracepoint
)
9395 /* Only test for support at download time; we may not know
9396 target capabilities at definition time. */
9397 if (remote_supports_fast_tracepoints ())
9401 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9402 tpaddr
, &isize
, NULL
))
9403 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9405 /* If it passed validation at definition but fails now,
9406 something is very wrong. */
9407 internal_error (__FILE__
, __LINE__
,
9408 "Fast tracepoint not valid during download");
9411 /* Fast tracepoints are functionally identical to regular
9412 tracepoints, so don't take lack of support as a reason to
9413 give up on the trace run. */
9414 warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t
->number
);
9416 /* If the tracepoint has a conditional, make it into an agent
9417 expression and append to the definition. */
9420 /* Only test support at download time, we may not know target
9421 capabilities at definition time. */
9422 if (remote_supports_cond_tracepoints ())
9424 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9425 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9426 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9427 pkt
= buf
+ strlen (buf
);
9428 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9429 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9431 do_cleanups (aexpr_chain
);
9434 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
9437 if (t
->commands
|| *default_collect
)
9440 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9441 if (strcmp (target_buf
, "OK"))
9442 error (_("Target does not support tracepoints."));
9444 /* do_single_steps (t); */
9447 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9449 QUIT
; /* allow user to bail out with ^C */
9450 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9451 t
->number
, addrbuf
, /* address */
9453 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9456 remote_get_noisy_reply (&target_buf
,
9458 if (strcmp (target_buf
, "OK"))
9459 error (_("Error on target while setting tracepoints."));
9462 if (stepping_actions
)
9464 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9466 QUIT
; /* allow user to bail out with ^C */
9467 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9468 t
->number
, addrbuf
, /* address */
9469 ((ndx
== 0) ? "S" : ""),
9470 stepping_actions
[ndx
],
9471 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9473 remote_get_noisy_reply (&target_buf
,
9475 if (strcmp (target_buf
, "OK"))
9476 error (_("Error on target while setting tracepoints."));
9480 if (remote_protocol_packets
[PACKET_TracepointSource
].support
== PACKET_ENABLE
)
9484 strcpy (buf
, "QTDPsrc:");
9485 encode_source_string (t
->number
, loc
->address
,
9486 "at", t
->addr_string
, buf
+ strlen (buf
),
9487 2048 - strlen (buf
));
9490 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9491 if (strcmp (target_buf
, "OK"))
9492 warning (_("Target does not support source download."));
9496 strcpy (buf
, "QTDPsrc:");
9497 encode_source_string (t
->number
, loc
->address
,
9498 "cond", t
->cond_string
, buf
+ strlen (buf
),
9499 2048 - strlen (buf
));
9501 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9502 if (strcmp (target_buf
, "OK"))
9503 warning (_("Target does not support source download."));
9505 remote_download_command_source (t
->number
, loc
->address
,
9506 breakpoint_commands (t
));
9509 do_cleanups (old_chain
);
9514 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
9516 struct remote_state
*rs
= get_remote_state ();
9519 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
9520 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
9521 p
= rs
->buf
+ strlen (rs
->buf
);
9522 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
9523 error (_("Trace state variable name too long for tsv definition packet"));
9524 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
9527 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9528 if (*target_buf
== '\0')
9529 error (_("Target does not support this command."));
9530 if (strcmp (target_buf
, "OK") != 0)
9531 error (_("Error on target while downloading trace state variable."));
9535 remote_trace_set_readonly_regions (void)
9543 return; /* No information to give. */
9545 strcpy (target_buf
, "QTro");
9546 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9548 char tmp1
[40], tmp2
[40];
9550 if ((s
->flags
& SEC_LOAD
) == 0 ||
9551 /* (s->flags & SEC_CODE) == 0 || */
9552 (s
->flags
& SEC_READONLY
) == 0)
9557 size
= bfd_get_section_size (s
);
9558 sprintf_vma (tmp1
, lma
);
9559 sprintf_vma (tmp2
, lma
+ size
);
9560 sprintf (target_buf
+ strlen (target_buf
),
9561 ":%s,%s", tmp1
, tmp2
);
9565 putpkt (target_buf
);
9566 getpkt (&target_buf
, &target_buf_size
, 0);
9571 remote_trace_start (void)
9574 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9575 if (*target_buf
== '\0')
9576 error (_("Target does not support this command."));
9577 if (strcmp (target_buf
, "OK") != 0)
9578 error (_("Bogus reply from target: %s"), target_buf
);
9582 remote_get_trace_status (struct trace_status
*ts
)
9584 char *p
, *p1
, *p_temp
;
9586 /* FIXME we need to get register block size some other way */
9587 extern int trace_regblock_size
;
9588 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
9590 putpkt ("qTStatus");
9591 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9593 /* If the remote target doesn't do tracing, flag it. */
9597 /* We're working with a live target. */
9600 /* Set some defaults. */
9601 ts
->running_known
= 0;
9602 ts
->stop_reason
= trace_stop_reason_unknown
;
9603 ts
->traceframe_count
= -1;
9604 ts
->buffer_free
= 0;
9607 error (_("Bogus trace status reply from target: %s"), target_buf
);
9609 parse_trace_status (p
, ts
);
9615 remote_trace_stop (void)
9618 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9619 if (*target_buf
== '\0')
9620 error (_("Target does not support this command."));
9621 if (strcmp (target_buf
, "OK") != 0)
9622 error (_("Bogus reply from target: %s"), target_buf
);
9626 remote_trace_find (enum trace_find_type type
, int num
,
9627 ULONGEST addr1
, ULONGEST addr2
,
9630 struct remote_state
*rs
= get_remote_state ();
9632 int target_frameno
= -1, target_tracept
= -1;
9635 strcpy (p
, "QTFrame:");
9636 p
= strchr (p
, '\0');
9640 sprintf (p
, "%x", num
);
9643 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
9646 sprintf (p
, "tdp:%x", num
);
9649 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9652 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9655 error ("Unknown trace find type %d", type
);
9659 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
9661 error (_("Target does not support this command."));
9663 while (reply
&& *reply
)
9668 target_frameno
= (int) strtol (p
, &reply
, 16);
9670 error (_("Unable to parse trace frame number"));
9671 if (target_frameno
== -1)
9676 target_tracept
= (int) strtol (p
, &reply
, 16);
9678 error (_("Unable to parse tracepoint number"));
9680 case 'O': /* "OK"? */
9681 if (reply
[1] == 'K' && reply
[2] == '\0')
9684 error (_("Bogus reply from target: %s"), reply
);
9687 error (_("Bogus reply from target: %s"), reply
);
9690 *tpp
= target_tracept
;
9691 return target_frameno
;
9695 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
9697 struct remote_state
*rs
= get_remote_state ();
9701 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
9703 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9704 if (reply
&& *reply
)
9708 unpack_varlen_hex (reply
+ 1, &uval
);
9709 *val
= (LONGEST
) uval
;
9717 remote_save_trace_data (const char *filename
)
9719 struct remote_state
*rs
= get_remote_state ();
9723 strcpy (p
, "QTSave:");
9725 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
9726 error (_("Remote file name too long for trace save packet"));
9727 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
9730 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9732 error (_("Target does not support this command."));
9733 if (strcmp (reply
, "OK") != 0)
9734 error (_("Bogus reply from target: %s"), reply
);
9738 /* This is basically a memory transfer, but needs to be its own packet
9739 because we don't know how the target actually organizes its trace
9740 memory, plus we want to be able to ask for as much as possible, but
9741 not be unhappy if we don't get as much as we ask for. */
9744 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
9746 struct remote_state
*rs
= get_remote_state ();
9752 strcpy (p
, "qTBuffer:");
9754 p
+= hexnumstr (p
, offset
);
9756 p
+= hexnumstr (p
, len
);
9760 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9761 if (reply
&& *reply
)
9763 /* 'l' by itself means we're at the end of the buffer and
9764 there is nothing more to get. */
9768 /* Convert the reply into binary. Limit the number of bytes to
9769 convert according to our passed-in buffer size, rather than
9770 what was returned in the packet; if the target is
9771 unexpectedly generous and gives us a bigger reply than we
9772 asked for, we don't want to crash. */
9773 rslt
= hex2bin (target_buf
, buf
, len
);
9777 /* Something went wrong, flag as an error. */
9782 remote_set_disconnected_tracing (int val
)
9784 struct remote_state
*rs
= get_remote_state ();
9786 if (rs
->disconnected_tracing
)
9790 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
9792 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9794 error (_("Target does not support this command."));
9795 if (strcmp (reply
, "OK") != 0)
9796 error (_("Bogus reply from target: %s"), reply
);
9799 warning (_("Target does not support disconnected tracing."));
9803 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
9805 struct thread_info
*info
= find_thread_ptid (ptid
);
9806 if (info
&& info
->private)
9807 return info
->private->core
;
9812 remote_set_circular_trace_buffer (int val
)
9814 struct remote_state
*rs
= get_remote_state ();
9817 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
9819 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9821 error (_("Target does not support this command."));
9822 if (strcmp (reply
, "OK") != 0)
9823 error (_("Bogus reply from target: %s"), reply
);
9827 init_remote_ops (void)
9829 remote_ops
.to_shortname
= "remote";
9830 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
9832 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9833 Specify the serial device it is connected to\n\
9834 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
9835 remote_ops
.to_open
= remote_open
;
9836 remote_ops
.to_close
= remote_close
;
9837 remote_ops
.to_detach
= remote_detach
;
9838 remote_ops
.to_disconnect
= remote_disconnect
;
9839 remote_ops
.to_resume
= remote_resume
;
9840 remote_ops
.to_wait
= remote_wait
;
9841 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
9842 remote_ops
.to_store_registers
= remote_store_registers
;
9843 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
9844 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
9845 remote_ops
.to_files_info
= remote_files_info
;
9846 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
9847 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
9848 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
9849 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
9850 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
9851 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
9852 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
9853 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
9854 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
9855 remote_ops
.to_kill
= remote_kill
;
9856 remote_ops
.to_load
= generic_load
;
9857 remote_ops
.to_mourn_inferior
= remote_mourn
;
9858 remote_ops
.to_thread_alive
= remote_thread_alive
;
9859 remote_ops
.to_find_new_threads
= remote_threads_info
;
9860 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
9861 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
9862 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
9863 remote_ops
.to_stop
= remote_stop
;
9864 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
9865 remote_ops
.to_rcmd
= remote_rcmd
;
9866 remote_ops
.to_log_command
= serial_log_command
;
9867 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
9868 remote_ops
.to_stratum
= process_stratum
;
9869 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
9870 remote_ops
.to_has_memory
= default_child_has_memory
;
9871 remote_ops
.to_has_stack
= default_child_has_stack
;
9872 remote_ops
.to_has_registers
= default_child_has_registers
;
9873 remote_ops
.to_has_execution
= default_child_has_execution
;
9874 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
9875 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
9876 remote_ops
.to_magic
= OPS_MAGIC
;
9877 remote_ops
.to_memory_map
= remote_memory_map
;
9878 remote_ops
.to_flash_erase
= remote_flash_erase
;
9879 remote_ops
.to_flash_done
= remote_flash_done
;
9880 remote_ops
.to_read_description
= remote_read_description
;
9881 remote_ops
.to_search_memory
= remote_search_memory
;
9882 remote_ops
.to_can_async_p
= remote_can_async_p
;
9883 remote_ops
.to_is_async_p
= remote_is_async_p
;
9884 remote_ops
.to_async
= remote_async
;
9885 remote_ops
.to_async_mask
= remote_async_mask
;
9886 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
9887 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
9888 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
9889 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
9890 remote_ops
.to_trace_init
= remote_trace_init
;
9891 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
9892 remote_ops
.to_download_trace_state_variable
= remote_download_trace_state_variable
;
9893 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
9894 remote_ops
.to_trace_start
= remote_trace_start
;
9895 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
9896 remote_ops
.to_trace_stop
= remote_trace_stop
;
9897 remote_ops
.to_trace_find
= remote_trace_find
;
9898 remote_ops
.to_get_trace_state_variable_value
= remote_get_trace_state_variable_value
;
9899 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
9900 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
9901 remote_ops
.to_upload_trace_state_variables
= remote_upload_trace_state_variables
;
9902 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
9903 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
9904 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
9905 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
9906 remote_ops
.to_verify_memory
= remote_verify_memory
;
9909 /* Set up the extended remote vector by making a copy of the standard
9910 remote vector and adding to it. */
9913 init_extended_remote_ops (void)
9915 extended_remote_ops
= remote_ops
;
9917 extended_remote_ops
.to_shortname
= "extended-remote";
9918 extended_remote_ops
.to_longname
=
9919 "Extended remote serial target in gdb-specific protocol";
9920 extended_remote_ops
.to_doc
=
9921 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9922 Specify the serial device it is connected to (e.g. /dev/ttya).";
9923 extended_remote_ops
.to_open
= extended_remote_open
;
9924 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
9925 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
9926 extended_remote_ops
.to_detach
= extended_remote_detach
;
9927 extended_remote_ops
.to_attach
= extended_remote_attach
;
9928 extended_remote_ops
.to_kill
= extended_remote_kill
;
9932 remote_can_async_p (void)
9934 if (!target_async_permitted
)
9935 /* We only enable async when the user specifically asks for it. */
9938 /* We're async whenever the serial device is. */
9939 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
9943 remote_is_async_p (void)
9945 if (!target_async_permitted
)
9946 /* We only enable async when the user specifically asks for it. */
9949 /* We're async whenever the serial device is. */
9950 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
9953 /* Pass the SERIAL event on and up to the client. One day this code
9954 will be able to delay notifying the client of an event until the
9955 point where an entire packet has been received. */
9957 static void (*async_client_callback
) (enum inferior_event_type event_type
,
9959 static void *async_client_context
;
9960 static serial_event_ftype remote_async_serial_handler
;
9963 remote_async_serial_handler (struct serial
*scb
, void *context
)
9965 /* Don't propogate error information up to the client. Instead let
9966 the client find out about the error by querying the target. */
9967 async_client_callback (INF_REG_EVENT
, async_client_context
);
9971 remote_async_inferior_event_handler (gdb_client_data data
)
9973 inferior_event_handler (INF_REG_EVENT
, NULL
);
9977 remote_async_get_pending_events_handler (gdb_client_data data
)
9979 remote_get_pending_stop_replies ();
9983 remote_async (void (*callback
) (enum inferior_event_type event_type
,
9984 void *context
), void *context
)
9986 if (remote_async_mask_value
== 0)
9987 internal_error (__FILE__
, __LINE__
,
9988 _("Calling remote_async when async is masked"));
9990 if (callback
!= NULL
)
9992 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
9993 async_client_callback
= callback
;
9994 async_client_context
= context
;
9997 serial_async (remote_desc
, NULL
, NULL
);
10001 remote_async_mask (int new_mask
)
10003 int curr_mask
= remote_async_mask_value
;
10004 remote_async_mask_value
= new_mask
;
10009 set_remote_cmd (char *args
, int from_tty
)
10011 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10015 show_remote_cmd (char *args
, int from_tty
)
10017 /* We can't just use cmd_show_list here, because we want to skip
10018 the redundant "show remote Z-packet" and the legacy aliases. */
10019 struct cleanup
*showlist_chain
;
10020 struct cmd_list_element
*list
= remote_show_cmdlist
;
10022 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10023 for (; list
!= NULL
; list
= list
->next
)
10024 if (strcmp (list
->name
, "Z-packet") == 0)
10026 else if (list
->type
== not_set_cmd
)
10027 /* Alias commands are exactly like the original, except they
10028 don't have the normal type. */
10032 struct cleanup
*option_chain
10033 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10034 ui_out_field_string (uiout
, "name", list
->name
);
10035 ui_out_text (uiout
, ": ");
10036 if (list
->type
== show_cmd
)
10037 do_setshow_command ((char *) NULL
, from_tty
, list
);
10039 cmd_func (list
, NULL
, from_tty
);
10040 /* Close the tuple. */
10041 do_cleanups (option_chain
);
10044 /* Close the tuple. */
10045 do_cleanups (showlist_chain
);
10049 /* Function to be called whenever a new objfile (shlib) is detected. */
10051 remote_new_objfile (struct objfile
*objfile
)
10053 if (remote_desc
!= 0) /* Have a remote connection. */
10054 remote_check_symbols (objfile
);
10057 /* Pull all the tracepoints defined on the target and create local
10058 data structures representing them. We don't want to create real
10059 tracepoints yet, we don't want to mess up the user's existing
10063 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10065 struct remote_state
*rs
= get_remote_state ();
10068 /* Ask for a first packet of tracepoint definition. */
10070 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10072 while (*p
&& *p
!= 'l')
10074 parse_tracepoint_definition (p
, utpp
);
10075 /* Ask for another packet of tracepoint definition. */
10077 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10084 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10086 struct remote_state
*rs
= get_remote_state ();
10089 /* Ask for a first packet of variable definition. */
10091 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10093 while (*p
&& *p
!= 'l')
10095 parse_tsv_definition (p
, utsvp
);
10096 /* Ask for another packet of variable definition. */
10098 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10105 _initialize_remote (void)
10107 struct remote_state
*rs
;
10108 struct cmd_list_element
*cmd
;
10111 /* architecture specific data */
10112 remote_gdbarch_data_handle
=
10113 gdbarch_data_register_post_init (init_remote_state
);
10114 remote_g_packet_data_handle
=
10115 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10117 /* Initialize the per-target state. At the moment there is only one
10118 of these, not one per target. Only one target is active at a
10119 time. The default buffer size is unimportant; it will be expanded
10120 whenever a larger buffer is needed. */
10121 rs
= get_remote_state_raw ();
10122 rs
->buf_size
= 400;
10123 rs
->buf
= xmalloc (rs
->buf_size
);
10125 init_remote_ops ();
10126 add_target (&remote_ops
);
10128 init_extended_remote_ops ();
10129 add_target (&extended_remote_ops
);
10131 /* Hook into new objfile notification. */
10132 observer_attach_new_objfile (remote_new_objfile
);
10134 /* Set up signal handlers. */
10135 sigint_remote_token
=
10136 create_async_signal_handler (async_remote_interrupt
, NULL
);
10137 sigint_remote_twice_token
=
10138 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
10141 init_remote_threadtests ();
10144 /* set/show remote ... */
10146 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10147 Remote protocol specific variables\n\
10148 Configure various remote-protocol specific variables such as\n\
10149 the packets being used"),
10150 &remote_set_cmdlist
, "set remote ",
10151 0 /* allow-unknown */, &setlist
);
10152 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10153 Remote protocol specific variables\n\
10154 Configure various remote-protocol specific variables such as\n\
10155 the packets being used"),
10156 &remote_show_cmdlist
, "show remote ",
10157 0 /* allow-unknown */, &showlist
);
10159 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10160 Compare section data on target to the exec file.\n\
10161 Argument is a single section name (default: all loaded sections)."),
10164 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10165 Send an arbitrary packet to a remote target.\n\
10166 maintenance packet TEXT\n\
10167 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10168 this command sends the string TEXT to the inferior, and displays the\n\
10169 response packet. GDB supplies the initial `$' character, and the\n\
10170 terminating `#' character and checksum."),
10173 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10174 Set whether to send break if interrupted."), _("\
10175 Show whether to send break if interrupted."), _("\
10176 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10177 set_remotebreak
, show_remotebreak
,
10178 &setlist
, &showlist
);
10179 cmd_name
= "remotebreak";
10180 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10181 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10182 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10183 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10184 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10186 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10187 interrupt_sequence_modes
, &interrupt_sequence_mode
, _("\
10188 Set interrupt sequence to remote target."), _("\
10189 Show interrupt sequence to remote target."), _("\
10190 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10191 NULL
, show_interrupt_sequence
,
10192 &remote_set_cmdlist
,
10193 &remote_show_cmdlist
);
10195 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10196 &interrupt_on_connect
, _("\
10197 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10198 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10199 If set, interrupt sequence is sent to remote target."),
10201 &remote_set_cmdlist
, &remote_show_cmdlist
);
10203 /* Install commands for configuring memory read/write packets. */
10205 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10206 Set the maximum number of bytes per memory write packet (deprecated)."),
10208 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10209 Show the maximum number of bytes per memory write packet (deprecated)."),
10211 add_cmd ("memory-write-packet-size", no_class
,
10212 set_memory_write_packet_size
, _("\
10213 Set the maximum number of bytes per memory-write packet.\n\
10214 Specify the number of bytes in a packet or 0 (zero) for the\n\
10215 default packet size. The actual limit is further reduced\n\
10216 dependent on the target. Specify ``fixed'' to disable the\n\
10217 further restriction and ``limit'' to enable that restriction."),
10218 &remote_set_cmdlist
);
10219 add_cmd ("memory-read-packet-size", no_class
,
10220 set_memory_read_packet_size
, _("\
10221 Set the maximum number of bytes per memory-read packet.\n\
10222 Specify the number of bytes in a packet or 0 (zero) for the\n\
10223 default packet size. The actual limit is further reduced\n\
10224 dependent on the target. Specify ``fixed'' to disable the\n\
10225 further restriction and ``limit'' to enable that restriction."),
10226 &remote_set_cmdlist
);
10227 add_cmd ("memory-write-packet-size", no_class
,
10228 show_memory_write_packet_size
,
10229 _("Show the maximum number of bytes per memory-write packet."),
10230 &remote_show_cmdlist
);
10231 add_cmd ("memory-read-packet-size", no_class
,
10232 show_memory_read_packet_size
,
10233 _("Show the maximum number of bytes per memory-read packet."),
10234 &remote_show_cmdlist
);
10236 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10237 &remote_hw_watchpoint_limit
, _("\
10238 Set the maximum number of target hardware watchpoints."), _("\
10239 Show the maximum number of target hardware watchpoints."), _("\
10240 Specify a negative limit for unlimited."),
10241 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
10242 &remote_set_cmdlist
, &remote_show_cmdlist
);
10243 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10244 &remote_hw_breakpoint_limit
, _("\
10245 Set the maximum number of target hardware breakpoints."), _("\
10246 Show the maximum number of target hardware breakpoints."), _("\
10247 Specify a negative limit for unlimited."),
10248 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
10249 &remote_set_cmdlist
, &remote_show_cmdlist
);
10251 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10252 &remote_address_size
, _("\
10253 Set the maximum size of the address (in bits) in a memory packet."), _("\
10254 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10256 NULL
, /* FIXME: i18n: */
10257 &setlist
, &showlist
);
10259 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10260 "X", "binary-download", 1);
10262 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10263 "vCont", "verbose-resume", 0);
10265 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10266 "QPassSignals", "pass-signals", 0);
10268 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10269 "qSymbol", "symbol-lookup", 0);
10271 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10272 "P", "set-register", 1);
10274 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10275 "p", "fetch-register", 1);
10277 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10278 "Z0", "software-breakpoint", 0);
10280 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10281 "Z1", "hardware-breakpoint", 0);
10283 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10284 "Z2", "write-watchpoint", 0);
10286 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10287 "Z3", "read-watchpoint", 0);
10289 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10290 "Z4", "access-watchpoint", 0);
10292 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10293 "qXfer:auxv:read", "read-aux-vector", 0);
10295 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10296 "qXfer:features:read", "target-features", 0);
10298 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10299 "qXfer:libraries:read", "library-info", 0);
10301 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10302 "qXfer:memory-map:read", "memory-map", 0);
10304 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10305 "qXfer:spu:read", "read-spu-object", 0);
10307 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10308 "qXfer:spu:write", "write-spu-object", 0);
10310 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10311 "qXfer:osdata:read", "osdata", 0);
10313 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10314 "qXfer:threads:read", "threads", 0);
10316 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10317 "qXfer:siginfo:read", "read-siginfo-object", 0);
10319 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
10320 "qXfer:siginfo:write", "write-siginfo-object", 0);
10322 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
10323 "qGetTLSAddr", "get-thread-local-storage-address",
10326 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
10327 "bc", "reverse-continue", 0);
10329 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
10330 "bs", "reverse-step", 0);
10332 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
10333 "qSupported", "supported-packets", 0);
10335 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
10336 "qSearch:memory", "search-memory", 0);
10338 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
10339 "vFile:open", "hostio-open", 0);
10341 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
10342 "vFile:pread", "hostio-pread", 0);
10344 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
10345 "vFile:pwrite", "hostio-pwrite", 0);
10347 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
10348 "vFile:close", "hostio-close", 0);
10350 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
10351 "vFile:unlink", "hostio-unlink", 0);
10353 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
10354 "vAttach", "attach", 0);
10356 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
10359 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
10360 "QStartNoAckMode", "noack", 0);
10362 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
10363 "vKill", "kill", 0);
10365 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
10366 "qAttached", "query-attached", 0);
10368 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
10369 "ConditionalTracepoints", "conditional-tracepoints", 0);
10370 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
10371 "FastTracepoints", "fast-tracepoints", 0);
10373 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
10374 "TracepointSource", "TracepointSource", 0);
10376 /* Keep the old ``set remote Z-packet ...'' working. Each individual
10377 Z sub-packet has its own set and show commands, but users may
10378 have sets to this variable in their .gdbinit files (or in their
10380 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
10381 &remote_Z_packet_detect
, _("\
10382 Set use of remote protocol `Z' packets"), _("\
10383 Show use of remote protocol `Z' packets "), _("\
10384 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
10386 set_remote_protocol_Z_packet_cmd
,
10387 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
10388 &remote_set_cmdlist
, &remote_show_cmdlist
);
10390 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
10391 Manipulate files on the remote system\n\
10392 Transfer files to and from the remote target system."),
10393 &remote_cmdlist
, "remote ",
10394 0 /* allow-unknown */, &cmdlist
);
10396 add_cmd ("put", class_files
, remote_put_command
,
10397 _("Copy a local file to the remote system."),
10400 add_cmd ("get", class_files
, remote_get_command
,
10401 _("Copy a remote file to the local system."),
10404 add_cmd ("delete", class_files
, remote_delete_command
,
10405 _("Delete a remote file."),
10408 remote_exec_file
= xstrdup ("");
10409 add_setshow_string_noescape_cmd ("exec-file", class_files
,
10410 &remote_exec_file
, _("\
10411 Set the remote pathname for \"run\""), _("\
10412 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
10413 &remote_set_cmdlist
, &remote_show_cmdlist
);
10415 /* Eventually initialize fileio. See fileio.c */
10416 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
10418 /* Take advantage of the fact that the LWP field is not used, to tag
10419 special ptids with it set to != 0. */
10420 magic_null_ptid
= ptid_build (42000, 1, -1);
10421 not_sent_ptid
= ptid_build (42000, 1, -2);
10422 any_thread_ptid
= ptid_build (42000, 1, 0);
10424 target_buf_size
= 2048;
10425 target_buf
= xmalloc (target_buf_size
);