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);
434 error (_("Target does not support this command."));
435 else if (buf
[0] == 'E')
437 else if (buf
[0] == 'O' &&
439 remote_console_output (buf
+ 1); /* 'O' message from stub */
441 return buf
; /* here's the actual reply */
446 /* Handle for retreving the remote protocol data from gdbarch. */
447 static struct gdbarch_data
*remote_gdbarch_data_handle
;
449 static struct remote_arch_state
*
450 get_remote_arch_state (void)
452 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
455 /* Fetch the global remote target state. */
457 static struct remote_state
*
458 get_remote_state (void)
460 /* Make sure that the remote architecture state has been
461 initialized, because doing so might reallocate rs->buf. Any
462 function which calls getpkt also needs to be mindful of changes
463 to rs->buf, but this call limits the number of places which run
465 get_remote_arch_state ();
467 return get_remote_state_raw ();
471 compare_pnums (const void *lhs_
, const void *rhs_
)
473 const struct packet_reg
* const *lhs
= lhs_
;
474 const struct packet_reg
* const *rhs
= rhs_
;
476 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
478 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
485 init_remote_state (struct gdbarch
*gdbarch
)
487 int regnum
, num_remote_regs
, offset
;
488 struct remote_state
*rs
= get_remote_state_raw ();
489 struct remote_arch_state
*rsa
;
490 struct packet_reg
**remote_regs
;
492 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
494 /* Use the architecture to build a regnum<->pnum table, which will be
495 1:1 unless a feature set specifies otherwise. */
496 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
497 gdbarch_num_regs (gdbarch
),
499 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
501 struct packet_reg
*r
= &rsa
->regs
[regnum
];
503 if (register_size (gdbarch
, regnum
) == 0)
504 /* Do not try to fetch zero-sized (placeholder) registers. */
507 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
512 /* Define the g/G packet format as the contents of each register
513 with a remote protocol number, in order of ascending protocol
516 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
517 * sizeof (struct packet_reg
*));
518 for (num_remote_regs
= 0, regnum
= 0;
519 regnum
< gdbarch_num_regs (gdbarch
);
521 if (rsa
->regs
[regnum
].pnum
!= -1)
522 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
524 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
527 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
529 remote_regs
[regnum
]->in_g_packet
= 1;
530 remote_regs
[regnum
]->offset
= offset
;
531 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
534 /* Record the maximum possible size of the g packet - it may turn out
536 rsa
->sizeof_g_packet
= offset
;
538 /* Default maximum number of characters in a packet body. Many
539 remote stubs have a hardwired buffer size of 400 bytes
540 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
541 as the maximum packet-size to ensure that the packet and an extra
542 NUL character can always fit in the buffer. This stops GDB
543 trashing stubs that try to squeeze an extra NUL into what is
544 already a full buffer (As of 1999-12-04 that was most stubs). */
545 rsa
->remote_packet_size
= 400 - 1;
547 /* This one is filled in when a ``g'' packet is received. */
548 rsa
->actual_register_packet_size
= 0;
550 /* Should rsa->sizeof_g_packet needs more space than the
551 default, adjust the size accordingly. Remember that each byte is
552 encoded as two characters. 32 is the overhead for the packet
553 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
554 (``$NN:G...#NN'') is a better guess, the below has been padded a
556 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
557 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
559 /* Make sure that the packet buffer is plenty big enough for
560 this architecture. */
561 if (rs
->buf_size
< rsa
->remote_packet_size
)
563 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
564 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
570 /* Return the current allowed size of a remote packet. This is
571 inferred from the current architecture, and should be used to
572 limit the length of outgoing packets. */
574 get_remote_packet_size (void)
576 struct remote_state
*rs
= get_remote_state ();
577 struct remote_arch_state
*rsa
= get_remote_arch_state ();
579 if (rs
->explicit_packet_size
)
580 return rs
->explicit_packet_size
;
582 return rsa
->remote_packet_size
;
585 static struct packet_reg
*
586 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
588 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
592 struct packet_reg
*r
= &rsa
->regs
[regnum
];
593 gdb_assert (r
->regnum
== regnum
);
598 static struct packet_reg
*
599 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
602 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
604 struct packet_reg
*r
= &rsa
->regs
[i
];
611 /* FIXME: graces/2002-08-08: These variables should eventually be
612 bound to an instance of the target object (as in gdbarch-tdep()),
613 when such a thing exists. */
615 /* This is set to the data address of the access causing the target
616 to stop for a watchpoint. */
617 static CORE_ADDR remote_watch_data_address
;
619 /* This is non-zero if target stopped for a watchpoint. */
620 static int remote_stopped_by_watchpoint_p
;
622 static struct target_ops remote_ops
;
624 static struct target_ops extended_remote_ops
;
626 static int remote_async_mask_value
= 1;
628 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
629 ``forever'' still use the normal timeout mechanism. This is
630 currently used by the ASYNC code to guarentee that target reads
631 during the initial connect always time-out. Once getpkt has been
632 modified to return a timeout indication and, in turn
633 remote_wait()/wait_for_inferior() have gained a timeout parameter
635 static int wait_forever_enabled_p
= 1;
637 /* Allow the user to specify what sequence to send to the remote
638 when he requests a program interruption: Although ^C is usually
639 what remote systems expect (this is the default, here), it is
640 sometimes preferable to send a break. On other systems such
641 as the Linux kernel, a break followed by g, which is Magic SysRq g
642 is required in order to interrupt the execution. */
643 const char interrupt_sequence_control_c
[] = "Ctrl-C";
644 const char interrupt_sequence_break
[] = "BREAK";
645 const char interrupt_sequence_break_g
[] = "BREAK-g";
646 static const char *interrupt_sequence_modes
[] =
648 interrupt_sequence_control_c
,
649 interrupt_sequence_break
,
650 interrupt_sequence_break_g
,
653 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
656 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
657 struct cmd_list_element
*c
,
660 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
661 fprintf_filtered (file
,
662 _("Send the ASCII ETX character (Ctrl-c) "
663 "to the remote target to interrupt the "
664 "execution of the program.\n"));
665 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
666 fprintf_filtered (file
,
667 _("send a break signal to the remote target "
668 "to interrupt the execution of the program.\n"));
669 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
670 fprintf_filtered (file
,
671 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
672 "the remote target to interrupt the execution "
673 "of Linux kernel.\n"));
675 internal_error (__FILE__
, __LINE__
,
676 _("Invalid value for interrupt_sequence_mode: %s."),
677 interrupt_sequence_mode
);
680 /* This boolean variable specifies whether interrupt_sequence is sent
681 to the remote target when gdb connects to it.
682 This is mostly needed when you debug the Linux kernel: The Linux kernel
683 expects BREAK g which is Magic SysRq g for connecting gdb. */
684 static int interrupt_on_connect
= 0;
686 /* This variable is used to implement the "set/show remotebreak" commands.
687 Since these commands are now deprecated in favor of "set/show remote
688 interrupt-sequence", it no longer has any effect on the code. */
689 static int remote_break
;
692 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
695 interrupt_sequence_mode
= interrupt_sequence_break
;
697 interrupt_sequence_mode
= interrupt_sequence_control_c
;
701 show_remotebreak (struct ui_file
*file
, int from_tty
,
702 struct cmd_list_element
*c
,
707 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
708 remote_open knows that we don't have a file open when the program
710 static struct serial
*remote_desc
= NULL
;
712 /* This variable sets the number of bits in an address that are to be
713 sent in a memory ("M" or "m") packet. Normally, after stripping
714 leading zeros, the entire address would be sent. This variable
715 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
716 initial implementation of remote.c restricted the address sent in
717 memory packets to ``host::sizeof long'' bytes - (typically 32
718 bits). Consequently, for 64 bit targets, the upper 32 bits of an
719 address was never sent. Since fixing this bug may cause a break in
720 some remote targets this variable is principly provided to
721 facilitate backward compatibility. */
723 static int remote_address_size
;
725 /* Temporary to track who currently owns the terminal. See
726 remote_terminal_* for more details. */
728 static int remote_async_terminal_ours_p
;
730 /* The executable file to use for "run" on the remote side. */
732 static char *remote_exec_file
= "";
735 /* User configurable variables for the number of characters in a
736 memory read/write packet. MIN (rsa->remote_packet_size,
737 rsa->sizeof_g_packet) is the default. Some targets need smaller
738 values (fifo overruns, et.al.) and some users need larger values
739 (speed up transfers). The variables ``preferred_*'' (the user
740 request), ``current_*'' (what was actually set) and ``forced_*''
741 (Positive - a soft limit, negative - a hard limit). */
743 struct memory_packet_config
750 /* Compute the current size of a read/write packet. Since this makes
751 use of ``actual_register_packet_size'' the computation is dynamic. */
754 get_memory_packet_size (struct memory_packet_config
*config
)
756 struct remote_state
*rs
= get_remote_state ();
757 struct remote_arch_state
*rsa
= get_remote_arch_state ();
759 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
760 law?) that some hosts don't cope very well with large alloca()
761 calls. Eventually the alloca() code will be replaced by calls to
762 xmalloc() and make_cleanups() allowing this restriction to either
763 be lifted or removed. */
764 #ifndef MAX_REMOTE_PACKET_SIZE
765 #define MAX_REMOTE_PACKET_SIZE 16384
767 /* NOTE: 20 ensures we can write at least one byte. */
768 #ifndef MIN_REMOTE_PACKET_SIZE
769 #define MIN_REMOTE_PACKET_SIZE 20
774 if (config
->size
<= 0)
775 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
777 what_they_get
= config
->size
;
781 what_they_get
= get_remote_packet_size ();
782 /* Limit the packet to the size specified by the user. */
784 && what_they_get
> config
->size
)
785 what_they_get
= config
->size
;
787 /* Limit it to the size of the targets ``g'' response unless we have
788 permission from the stub to use a larger packet size. */
789 if (rs
->explicit_packet_size
== 0
790 && rsa
->actual_register_packet_size
> 0
791 && what_they_get
> rsa
->actual_register_packet_size
)
792 what_they_get
= rsa
->actual_register_packet_size
;
794 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
795 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
796 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
797 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
799 /* Make sure there is room in the global buffer for this packet
800 (including its trailing NUL byte). */
801 if (rs
->buf_size
< what_they_get
+ 1)
803 rs
->buf_size
= 2 * what_they_get
;
804 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
807 return what_they_get
;
810 /* Update the size of a read/write packet. If they user wants
811 something really big then do a sanity check. */
814 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
816 int fixed_p
= config
->fixed_p
;
817 long size
= config
->size
;
819 error (_("Argument required (integer, `fixed' or `limited')."));
820 else if (strcmp (args
, "hard") == 0
821 || strcmp (args
, "fixed") == 0)
823 else if (strcmp (args
, "soft") == 0
824 || strcmp (args
, "limit") == 0)
829 size
= strtoul (args
, &end
, 0);
831 error (_("Invalid %s (bad syntax)."), config
->name
);
833 /* Instead of explicitly capping the size of a packet to
834 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
835 instead allowed to set the size to something arbitrarily
837 if (size
> MAX_REMOTE_PACKET_SIZE
)
838 error (_("Invalid %s (too large)."), config
->name
);
842 if (fixed_p
&& !config
->fixed_p
)
844 if (! query (_("The target may not be able to correctly handle a %s\n"
845 "of %ld bytes. Change the packet size? "),
847 error (_("Packet size not changed."));
849 /* Update the config. */
850 config
->fixed_p
= fixed_p
;
855 show_memory_packet_size (struct memory_packet_config
*config
)
857 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
859 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
860 get_memory_packet_size (config
));
862 printf_filtered (_("Packets are limited to %ld bytes.\n"),
863 get_memory_packet_size (config
));
866 static struct memory_packet_config memory_write_packet_config
=
868 "memory-write-packet-size",
872 set_memory_write_packet_size (char *args
, int from_tty
)
874 set_memory_packet_size (args
, &memory_write_packet_config
);
878 show_memory_write_packet_size (char *args
, int from_tty
)
880 show_memory_packet_size (&memory_write_packet_config
);
884 get_memory_write_packet_size (void)
886 return get_memory_packet_size (&memory_write_packet_config
);
889 static struct memory_packet_config memory_read_packet_config
=
891 "memory-read-packet-size",
895 set_memory_read_packet_size (char *args
, int from_tty
)
897 set_memory_packet_size (args
, &memory_read_packet_config
);
901 show_memory_read_packet_size (char *args
, int from_tty
)
903 show_memory_packet_size (&memory_read_packet_config
);
907 get_memory_read_packet_size (void)
909 long size
= get_memory_packet_size (&memory_read_packet_config
);
910 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
911 extra buffer size argument before the memory read size can be
912 increased beyond this. */
913 if (size
> get_remote_packet_size ())
914 size
= get_remote_packet_size ();
919 /* Generic configuration support for packets the stub optionally
920 supports. Allows the user to specify the use of the packet as well
921 as allowing GDB to auto-detect support in the remote stub. */
925 PACKET_SUPPORT_UNKNOWN
= 0,
934 enum auto_boolean detect
;
935 enum packet_support support
;
938 /* Analyze a packet's return value and update the packet config
949 update_packet_config (struct packet_config
*config
)
951 switch (config
->detect
)
953 case AUTO_BOOLEAN_TRUE
:
954 config
->support
= PACKET_ENABLE
;
956 case AUTO_BOOLEAN_FALSE
:
957 config
->support
= PACKET_DISABLE
;
959 case AUTO_BOOLEAN_AUTO
:
960 config
->support
= PACKET_SUPPORT_UNKNOWN
;
966 show_packet_config_cmd (struct packet_config
*config
)
968 char *support
= "internal-error";
969 switch (config
->support
)
975 support
= "disabled";
977 case PACKET_SUPPORT_UNKNOWN
:
981 switch (config
->detect
)
983 case AUTO_BOOLEAN_AUTO
:
984 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
985 config
->name
, support
);
987 case AUTO_BOOLEAN_TRUE
:
988 case AUTO_BOOLEAN_FALSE
:
989 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
990 config
->name
, support
);
996 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
997 const char *title
, int legacy
)
1003 config
->name
= name
;
1004 config
->title
= title
;
1005 config
->detect
= AUTO_BOOLEAN_AUTO
;
1006 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1007 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1009 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
1011 /* set/show TITLE-packet {auto,on,off} */
1012 cmd_name
= xstrprintf ("%s-packet", title
);
1013 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1014 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
1015 set_remote_protocol_packet_cmd
,
1016 show_remote_protocol_packet_cmd
,
1017 &remote_set_cmdlist
, &remote_show_cmdlist
);
1018 /* The command code copies the documentation strings. */
1021 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1025 legacy_name
= xstrprintf ("%s-packet", name
);
1026 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1027 &remote_set_cmdlist
);
1028 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1029 &remote_show_cmdlist
);
1033 static enum packet_result
1034 packet_check_result (const char *buf
)
1038 /* The stub recognized the packet request. Check that the
1039 operation succeeded. */
1041 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1043 /* "Enn" - definitly an error. */
1044 return PACKET_ERROR
;
1046 /* Always treat "E." as an error. This will be used for
1047 more verbose error messages, such as E.memtypes. */
1048 if (buf
[0] == 'E' && buf
[1] == '.')
1049 return PACKET_ERROR
;
1051 /* The packet may or may not be OK. Just assume it is. */
1055 /* The stub does not support the packet. */
1056 return PACKET_UNKNOWN
;
1059 static enum packet_result
1060 packet_ok (const char *buf
, struct packet_config
*config
)
1062 enum packet_result result
;
1064 result
= packet_check_result (buf
);
1069 /* The stub recognized the packet request. */
1070 switch (config
->support
)
1072 case PACKET_SUPPORT_UNKNOWN
:
1074 fprintf_unfiltered (gdb_stdlog
,
1075 "Packet %s (%s) is supported\n",
1076 config
->name
, config
->title
);
1077 config
->support
= PACKET_ENABLE
;
1079 case PACKET_DISABLE
:
1080 internal_error (__FILE__
, __LINE__
,
1081 _("packet_ok: attempt to use a disabled packet"));
1087 case PACKET_UNKNOWN
:
1088 /* The stub does not support the packet. */
1089 switch (config
->support
)
1092 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1093 /* If the stub previously indicated that the packet was
1094 supported then there is a protocol error.. */
1095 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1096 config
->name
, config
->title
);
1098 /* The user set it wrong. */
1099 error (_("Enabled packet %s (%s) not recognized by stub"),
1100 config
->name
, config
->title
);
1102 case PACKET_SUPPORT_UNKNOWN
:
1104 fprintf_unfiltered (gdb_stdlog
,
1105 "Packet %s (%s) is NOT supported\n",
1106 config
->name
, config
->title
);
1107 config
->support
= PACKET_DISABLE
;
1109 case PACKET_DISABLE
:
1131 PACKET_vFile_pwrite
,
1133 PACKET_vFile_unlink
,
1135 PACKET_qXfer_features
,
1136 PACKET_qXfer_libraries
,
1137 PACKET_qXfer_memory_map
,
1138 PACKET_qXfer_spu_read
,
1139 PACKET_qXfer_spu_write
,
1140 PACKET_qXfer_osdata
,
1141 PACKET_qXfer_threads
,
1144 PACKET_QPassSignals
,
1145 PACKET_qSearch_memory
,
1148 PACKET_QStartNoAckMode
,
1150 PACKET_qXfer_siginfo_read
,
1151 PACKET_qXfer_siginfo_write
,
1153 PACKET_ConditionalTracepoints
,
1154 PACKET_FastTracepoints
,
1157 PACKET_TracepointSource
,
1161 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1164 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1165 struct cmd_list_element
*c
)
1167 struct packet_config
*packet
;
1169 for (packet
= remote_protocol_packets
;
1170 packet
< &remote_protocol_packets
[PACKET_MAX
];
1173 if (&packet
->detect
== c
->var
)
1175 update_packet_config (packet
);
1179 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1184 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1185 struct cmd_list_element
*c
,
1188 struct packet_config
*packet
;
1190 for (packet
= remote_protocol_packets
;
1191 packet
< &remote_protocol_packets
[PACKET_MAX
];
1194 if (&packet
->detect
== c
->var
)
1196 show_packet_config_cmd (packet
);
1200 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1204 /* Should we try one of the 'Z' requests? */
1208 Z_PACKET_SOFTWARE_BP
,
1209 Z_PACKET_HARDWARE_BP
,
1216 /* For compatibility with older distributions. Provide a ``set remote
1217 Z-packet ...'' command that updates all the Z packet types. */
1219 static enum auto_boolean remote_Z_packet_detect
;
1222 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1223 struct cmd_list_element
*c
)
1226 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1228 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1229 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1234 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1235 struct cmd_list_element
*c
,
1239 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1241 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1245 /* Should we try the 'ThreadInfo' query packet?
1247 This variable (NOT available to the user: auto-detect only!)
1248 determines whether GDB will use the new, simpler "ThreadInfo"
1249 query or the older, more complex syntax for thread queries.
1250 This is an auto-detect variable (set to true at each connect,
1251 and set to false when the target fails to recognize it). */
1253 static int use_threadinfo_query
;
1254 static int use_threadextra_query
;
1256 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1257 static struct async_signal_handler
*sigint_remote_twice_token
;
1258 static struct async_signal_handler
*sigint_remote_token
;
1261 /* Asynchronous signal handle registered as event loop source for
1262 when we have pending events ready to be passed to the core. */
1264 static struct async_event_handler
*remote_async_inferior_event_token
;
1266 /* Asynchronous signal handle registered as event loop source for when
1267 the remote sent us a %Stop notification. The registered callback
1268 will do a vStopped sequence to pull the rest of the events out of
1269 the remote side into our event queue. */
1271 static struct async_event_handler
*remote_async_get_pending_events_token
;
1274 static ptid_t magic_null_ptid
;
1275 static ptid_t not_sent_ptid
;
1276 static ptid_t any_thread_ptid
;
1278 /* These are the threads which we last sent to the remote system. The
1279 TID member will be -1 for all or -2 for not sent yet. */
1281 static ptid_t general_thread
;
1282 static ptid_t continue_thread
;
1284 /* Find out if the stub attached to PID (and hence GDB should offer to
1285 detach instead of killing it when bailing out). */
1288 remote_query_attached (int pid
)
1290 struct remote_state
*rs
= get_remote_state ();
1292 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1295 if (remote_multi_process_p (rs
))
1296 sprintf (rs
->buf
, "qAttached:%x", pid
);
1298 sprintf (rs
->buf
, "qAttached");
1301 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1303 switch (packet_ok (rs
->buf
,
1304 &remote_protocol_packets
[PACKET_qAttached
]))
1307 if (strcmp (rs
->buf
, "1") == 0)
1311 warning (_("Remote failure reply: %s"), rs
->buf
);
1313 case PACKET_UNKNOWN
:
1320 /* Add PID to GDB's inferior table. Since we can be connected to a
1321 remote system before before knowing about any inferior, mark the
1322 target with execution when we find the first inferior. If ATTACHED
1323 is 1, then we had just attached to this inferior. If it is 0, then
1324 we just created this inferior. If it is -1, then try querying the
1325 remote stub to find out if it had attached to the inferior or
1328 static struct inferior
*
1329 remote_add_inferior (int pid
, int attached
)
1331 struct inferior
*inf
;
1333 /* Check whether this process we're learning about is to be
1334 considered attached, or if is to be considered to have been
1335 spawned by the stub. */
1337 attached
= remote_query_attached (pid
);
1339 if (gdbarch_has_global_solist (target_gdbarch
))
1341 /* If the target shares code across all inferiors, then every
1342 attach adds a new inferior. */
1343 inf
= add_inferior (pid
);
1345 /* ... and every inferior is bound to the same program space.
1346 However, each inferior may still have its own address
1348 inf
->aspace
= maybe_new_address_space ();
1349 inf
->pspace
= current_program_space
;
1353 /* In the traditional debugging scenario, there's a 1-1 match
1354 between program/address spaces. We simply bind the inferior
1355 to the program space's address space. */
1356 inf
= current_inferior ();
1357 inferior_appeared (inf
, pid
);
1360 inf
->attach_flag
= attached
;
1365 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1366 according to RUNNING. */
1369 remote_add_thread (ptid_t ptid
, int running
)
1373 set_executing (ptid
, running
);
1374 set_running (ptid
, running
);
1377 /* Come here when we learn about a thread id from the remote target.
1378 It may be the first time we hear about such thread, so take the
1379 opportunity to add it to GDB's thread list. In case this is the
1380 first time we're noticing its corresponding inferior, add it to
1381 GDB's inferior list as well. */
1384 remote_notice_new_inferior (ptid_t currthread
, int running
)
1386 /* If this is a new thread, add it to GDB's thread list.
1387 If we leave it up to WFI to do this, bad things will happen. */
1389 if (in_thread_list (currthread
) && is_exited (currthread
))
1391 /* We're seeing an event on a thread id we knew had exited.
1392 This has to be a new thread reusing the old id. Add it. */
1393 remote_add_thread (currthread
, running
);
1397 if (!in_thread_list (currthread
))
1399 struct inferior
*inf
= NULL
;
1400 int pid
= ptid_get_pid (currthread
);
1402 if (ptid_is_pid (inferior_ptid
)
1403 && pid
== ptid_get_pid (inferior_ptid
))
1405 /* inferior_ptid has no thread member yet. This can happen
1406 with the vAttach -> remote_wait,"TAAthread:" path if the
1407 stub doesn't support qC. This is the first stop reported
1408 after an attach, so this is the main thread. Update the
1409 ptid in the thread list. */
1410 if (in_thread_list (pid_to_ptid (pid
)))
1411 thread_change_ptid (inferior_ptid
, currthread
);
1414 remote_add_thread (currthread
, running
);
1415 inferior_ptid
= currthread
;
1420 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1422 /* inferior_ptid is not set yet. This can happen with the
1423 vRun -> remote_wait,"TAAthread:" path if the stub
1424 doesn't support qC. This is the first stop reported
1425 after an attach, so this is the main thread. Update the
1426 ptid in the thread list. */
1427 thread_change_ptid (inferior_ptid
, currthread
);
1431 /* When connecting to a target remote, or to a target
1432 extended-remote which already was debugging an inferior, we
1433 may not know about it yet. Add it before adding its child
1434 thread, so notifications are emitted in a sensible order. */
1435 if (!in_inferior_list (ptid_get_pid (currthread
)))
1436 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1438 /* This is really a new thread. Add it. */
1439 remote_add_thread (currthread
, running
);
1441 /* If we found a new inferior, let the common code do whatever
1442 it needs to with it (e.g., read shared libraries, insert
1445 notice_new_inferior (currthread
, running
, 0);
1449 /* Return the private thread data, creating it if necessary. */
1451 struct private_thread_info
*
1452 demand_private_info (ptid_t ptid
)
1454 struct thread_info
*info
= find_thread_ptid (ptid
);
1460 info
->private = xmalloc (sizeof (*(info
->private)));
1461 info
->private_dtor
= free_private_thread_info
;
1462 info
->private->core
= -1;
1463 info
->private->extra
= 0;
1466 return info
->private;
1469 /* Call this function as a result of
1470 1) A halt indication (T packet) containing a thread id
1471 2) A direct query of currthread
1472 3) Successful execution of set thread
1476 record_currthread (ptid_t currthread
)
1478 general_thread
= currthread
;
1481 static char *last_pass_packet
;
1483 /* If 'QPassSignals' is supported, tell the remote stub what signals
1484 it can simply pass through to the inferior without reporting. */
1487 remote_pass_signals (void)
1489 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1491 char *pass_packet
, *p
;
1492 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1495 gdb_assert (numsigs
< 256);
1496 for (i
= 0; i
< numsigs
; i
++)
1498 if (signal_stop_state (i
) == 0
1499 && signal_print_state (i
) == 0
1500 && signal_pass_state (i
) == 1)
1503 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1504 strcpy (pass_packet
, "QPassSignals:");
1505 p
= pass_packet
+ strlen (pass_packet
);
1506 for (i
= 0; i
< numsigs
; i
++)
1508 if (signal_stop_state (i
) == 0
1509 && signal_print_state (i
) == 0
1510 && signal_pass_state (i
) == 1)
1513 *p
++ = tohex (i
>> 4);
1514 *p
++ = tohex (i
& 15);
1523 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1525 struct remote_state
*rs
= get_remote_state ();
1526 char *buf
= rs
->buf
;
1528 putpkt (pass_packet
);
1529 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1530 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1531 if (last_pass_packet
)
1532 xfree (last_pass_packet
);
1533 last_pass_packet
= pass_packet
;
1536 xfree (pass_packet
);
1540 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1541 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1542 thread. If GEN is set, set the general thread, if not, then set
1543 the step/continue thread. */
1545 set_thread (struct ptid ptid
, int gen
)
1547 struct remote_state
*rs
= get_remote_state ();
1548 ptid_t state
= gen
? general_thread
: continue_thread
;
1549 char *buf
= rs
->buf
;
1550 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1552 if (ptid_equal (state
, ptid
))
1556 *buf
++ = gen
? 'g' : 'c';
1557 if (ptid_equal (ptid
, magic_null_ptid
))
1558 xsnprintf (buf
, endbuf
- buf
, "0");
1559 else if (ptid_equal (ptid
, any_thread_ptid
))
1560 xsnprintf (buf
, endbuf
- buf
, "0");
1561 else if (ptid_equal (ptid
, minus_one_ptid
))
1562 xsnprintf (buf
, endbuf
- buf
, "-1");
1564 write_ptid (buf
, endbuf
, ptid
);
1566 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1568 general_thread
= ptid
;
1570 continue_thread
= ptid
;
1574 set_general_thread (struct ptid ptid
)
1576 set_thread (ptid
, 1);
1580 set_continue_thread (struct ptid ptid
)
1582 set_thread (ptid
, 0);
1585 /* Change the remote current process. Which thread within the process
1586 ends up selected isn't important, as long as it is the same process
1587 as what INFERIOR_PTID points to.
1589 This comes from that fact that there is no explicit notion of
1590 "selected process" in the protocol. The selected process for
1591 general operations is the process the selected general thread
1595 set_general_process (void)
1597 struct remote_state
*rs
= get_remote_state ();
1599 /* If the remote can't handle multiple processes, don't bother. */
1600 if (!remote_multi_process_p (rs
))
1603 /* We only need to change the remote current thread if it's pointing
1604 at some other process. */
1605 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1606 set_general_thread (inferior_ptid
);
1610 /* Return nonzero if the thread PTID is still alive on the remote
1614 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1616 struct remote_state
*rs
= get_remote_state ();
1619 if (ptid_equal (ptid
, magic_null_ptid
))
1620 /* The main thread is always alive. */
1623 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1624 /* The main thread is always alive. This can happen after a
1625 vAttach, if the remote side doesn't support
1630 endp
= rs
->buf
+ get_remote_packet_size ();
1633 write_ptid (p
, endp
, ptid
);
1636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1637 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1640 /* About these extended threadlist and threadinfo packets. They are
1641 variable length packets but, the fields within them are often fixed
1642 length. They are redundent enough to send over UDP as is the
1643 remote protocol in general. There is a matching unit test module
1646 #define OPAQUETHREADBYTES 8
1648 /* a 64 bit opaque identifier */
1649 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1651 /* WARNING: This threadref data structure comes from the remote O.S.,
1652 libstub protocol encoding, and remote.c. it is not particularly
1655 /* Right now, the internal structure is int. We want it to be bigger.
1659 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1661 /* gdb_ext_thread_info is an internal GDB data structure which is
1662 equivalent to the reply of the remote threadinfo packet. */
1664 struct gdb_ext_thread_info
1666 threadref threadid
; /* External form of thread reference. */
1667 int active
; /* Has state interesting to GDB?
1669 char display
[256]; /* Brief state display, name,
1670 blocked/suspended. */
1671 char shortname
[32]; /* To be used to name threads. */
1672 char more_display
[256]; /* Long info, statistics, queue depth,
1676 /* The volume of remote transfers can be limited by submitting
1677 a mask containing bits specifying the desired information.
1678 Use a union of these values as the 'selection' parameter to
1679 get_thread_info. FIXME: Make these TAG names more thread specific.
1682 #define TAG_THREADID 1
1683 #define TAG_EXISTS 2
1684 #define TAG_DISPLAY 4
1685 #define TAG_THREADNAME 8
1686 #define TAG_MOREDISPLAY 16
1688 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1690 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1692 static char *unpack_nibble (char *buf
, int *val
);
1694 static char *pack_nibble (char *buf
, int nibble
);
1696 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1698 static char *unpack_byte (char *buf
, int *value
);
1700 static char *pack_int (char *buf
, int value
);
1702 static char *unpack_int (char *buf
, int *value
);
1704 static char *unpack_string (char *src
, char *dest
, int length
);
1706 static char *pack_threadid (char *pkt
, threadref
*id
);
1708 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1710 void int_to_threadref (threadref
*id
, int value
);
1712 static int threadref_to_int (threadref
*ref
);
1714 static void copy_threadref (threadref
*dest
, threadref
*src
);
1716 static int threadmatch (threadref
*dest
, threadref
*src
);
1718 static char *pack_threadinfo_request (char *pkt
, int mode
,
1721 static int remote_unpack_thread_info_response (char *pkt
,
1722 threadref
*expectedref
,
1723 struct gdb_ext_thread_info
1727 static int remote_get_threadinfo (threadref
*threadid
,
1728 int fieldset
, /*TAG mask */
1729 struct gdb_ext_thread_info
*info
);
1731 static char *pack_threadlist_request (char *pkt
, int startflag
,
1733 threadref
*nextthread
);
1735 static int parse_threadlist_response (char *pkt
,
1737 threadref
*original_echo
,
1738 threadref
*resultlist
,
1741 static int remote_get_threadlist (int startflag
,
1742 threadref
*nextthread
,
1746 threadref
*threadlist
);
1748 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1750 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1751 void *context
, int looplimit
);
1753 static int remote_newthread_step (threadref
*ref
, void *context
);
1756 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1757 buffer we're allowed to write to. Returns
1758 BUF+CHARACTERS_WRITTEN. */
1761 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1764 struct remote_state
*rs
= get_remote_state ();
1766 if (remote_multi_process_p (rs
))
1768 pid
= ptid_get_pid (ptid
);
1770 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1772 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1774 tid
= ptid_get_tid (ptid
);
1776 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1778 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1783 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1784 passed the last parsed char. Returns null_ptid on error. */
1787 read_ptid (char *buf
, char **obuf
)
1791 ULONGEST pid
= 0, tid
= 0;
1795 /* Multi-process ptid. */
1796 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1798 error (_("invalid remote ptid: %s\n"), p
);
1801 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1804 return ptid_build (pid
, 0, tid
);
1807 /* No multi-process. Just a tid. */
1808 pp
= unpack_varlen_hex (p
, &tid
);
1810 /* Since the stub is not sending a process id, then default to
1811 what's in inferior_ptid, unless it's null at this point. If so,
1812 then since there's no way to know the pid of the reported
1813 threads, use the magic number. */
1814 if (ptid_equal (inferior_ptid
, null_ptid
))
1815 pid
= ptid_get_pid (magic_null_ptid
);
1817 pid
= ptid_get_pid (inferior_ptid
);
1821 return ptid_build (pid
, 0, tid
);
1824 /* Encode 64 bits in 16 chars of hex. */
1826 static const char hexchars
[] = "0123456789abcdef";
1829 ishex (int ch
, int *val
)
1831 if ((ch
>= 'a') && (ch
<= 'f'))
1833 *val
= ch
- 'a' + 10;
1836 if ((ch
>= 'A') && (ch
<= 'F'))
1838 *val
= ch
- 'A' + 10;
1841 if ((ch
>= '0') && (ch
<= '9'))
1852 if (ch
>= 'a' && ch
<= 'f')
1853 return ch
- 'a' + 10;
1854 if (ch
>= '0' && ch
<= '9')
1856 if (ch
>= 'A' && ch
<= 'F')
1857 return ch
- 'A' + 10;
1862 stub_unpack_int (char *buff
, int fieldlength
)
1869 nibble
= stubhex (*buff
++);
1873 retval
= retval
<< 4;
1879 unpack_varlen_hex (char *buff
, /* packet to parse */
1883 ULONGEST retval
= 0;
1885 while (ishex (*buff
, &nibble
))
1888 retval
= retval
<< 4;
1889 retval
|= nibble
& 0x0f;
1896 unpack_nibble (char *buf
, int *val
)
1898 *val
= fromhex (*buf
++);
1903 pack_nibble (char *buf
, int nibble
)
1905 *buf
++ = hexchars
[(nibble
& 0x0f)];
1910 pack_hex_byte (char *pkt
, int byte
)
1912 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1913 *pkt
++ = hexchars
[(byte
& 0xf)];
1918 unpack_byte (char *buf
, int *value
)
1920 *value
= stub_unpack_int (buf
, 2);
1925 pack_int (char *buf
, int value
)
1927 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1928 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1929 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1930 buf
= pack_hex_byte (buf
, (value
& 0xff));
1935 unpack_int (char *buf
, int *value
)
1937 *value
= stub_unpack_int (buf
, 8);
1941 #if 0 /* Currently unused, uncomment when needed. */
1942 static char *pack_string (char *pkt
, char *string
);
1945 pack_string (char *pkt
, char *string
)
1950 len
= strlen (string
);
1952 len
= 200; /* Bigger than most GDB packets, junk??? */
1953 pkt
= pack_hex_byte (pkt
, len
);
1957 if ((ch
== '\0') || (ch
== '#'))
1958 ch
= '*'; /* Protect encapsulation. */
1963 #endif /* 0 (unused) */
1966 unpack_string (char *src
, char *dest
, int length
)
1975 pack_threadid (char *pkt
, threadref
*id
)
1978 unsigned char *altid
;
1980 altid
= (unsigned char *) id
;
1981 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1983 pkt
= pack_hex_byte (pkt
, *altid
++);
1989 unpack_threadid (char *inbuf
, threadref
*id
)
1992 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1995 altref
= (char *) id
;
1997 while (inbuf
< limit
)
1999 x
= stubhex (*inbuf
++);
2000 y
= stubhex (*inbuf
++);
2001 *altref
++ = (x
<< 4) | y
;
2006 /* Externally, threadrefs are 64 bits but internally, they are still
2007 ints. This is due to a mismatch of specifications. We would like
2008 to use 64bit thread references internally. This is an adapter
2012 int_to_threadref (threadref
*id
, int value
)
2014 unsigned char *scan
;
2016 scan
= (unsigned char *) id
;
2022 *scan
++ = (value
>> 24) & 0xff;
2023 *scan
++ = (value
>> 16) & 0xff;
2024 *scan
++ = (value
>> 8) & 0xff;
2025 *scan
++ = (value
& 0xff);
2029 threadref_to_int (threadref
*ref
)
2032 unsigned char *scan
;
2038 value
= (value
<< 8) | ((*scan
++) & 0xff);
2043 copy_threadref (threadref
*dest
, threadref
*src
)
2046 unsigned char *csrc
, *cdest
;
2048 csrc
= (unsigned char *) src
;
2049 cdest
= (unsigned char *) dest
;
2056 threadmatch (threadref
*dest
, threadref
*src
)
2058 /* Things are broken right now, so just assume we got a match. */
2060 unsigned char *srcp
, *destp
;
2062 srcp
= (char *) src
;
2063 destp
= (char *) dest
;
2067 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2074 threadid:1, # always request threadid
2081 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2084 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2086 *pkt
++ = 'q'; /* Info Query */
2087 *pkt
++ = 'P'; /* process or thread info */
2088 pkt
= pack_int (pkt
, mode
); /* mode */
2089 pkt
= pack_threadid (pkt
, id
); /* threadid */
2090 *pkt
= '\0'; /* terminate */
2094 /* These values tag the fields in a thread info response packet. */
2095 /* Tagging the fields allows us to request specific fields and to
2096 add more fields as time goes by. */
2098 #define TAG_THREADID 1 /* Echo the thread identifier. */
2099 #define TAG_EXISTS 2 /* Is this process defined enough to
2100 fetch registers and its stack? */
2101 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2102 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2103 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2107 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2108 struct gdb_ext_thread_info
*info
)
2110 struct remote_state
*rs
= get_remote_state ();
2114 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2117 /* info->threadid = 0; FIXME: implement zero_threadref. */
2119 info
->display
[0] = '\0';
2120 info
->shortname
[0] = '\0';
2121 info
->more_display
[0] = '\0';
2123 /* Assume the characters indicating the packet type have been
2125 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2126 pkt
= unpack_threadid (pkt
, &ref
);
2129 warning (_("Incomplete response to threadinfo request."));
2130 if (!threadmatch (&ref
, expectedref
))
2131 { /* This is an answer to a different request. */
2132 warning (_("ERROR RMT Thread info mismatch."));
2135 copy_threadref (&info
->threadid
, &ref
);
2137 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2139 /* Packets are terminated with nulls. */
2140 while ((pkt
< limit
) && mask
&& *pkt
)
2142 pkt
= unpack_int (pkt
, &tag
); /* tag */
2143 pkt
= unpack_byte (pkt
, &length
); /* length */
2144 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2146 warning (_("ERROR RMT: threadinfo tag mismatch."));
2150 if (tag
== TAG_THREADID
)
2154 warning (_("ERROR RMT: length of threadid is not 16."));
2158 pkt
= unpack_threadid (pkt
, &ref
);
2159 mask
= mask
& ~TAG_THREADID
;
2162 if (tag
== TAG_EXISTS
)
2164 info
->active
= stub_unpack_int (pkt
, length
);
2166 mask
= mask
& ~(TAG_EXISTS
);
2169 warning (_("ERROR RMT: 'exists' length too long."));
2175 if (tag
== TAG_THREADNAME
)
2177 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2178 mask
= mask
& ~TAG_THREADNAME
;
2181 if (tag
== TAG_DISPLAY
)
2183 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2184 mask
= mask
& ~TAG_DISPLAY
;
2187 if (tag
== TAG_MOREDISPLAY
)
2189 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2190 mask
= mask
& ~TAG_MOREDISPLAY
;
2193 warning (_("ERROR RMT: unknown thread info tag."));
2194 break; /* Not a tag we know about. */
2200 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2201 struct gdb_ext_thread_info
*info
)
2203 struct remote_state
*rs
= get_remote_state ();
2206 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2208 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2210 if (rs
->buf
[0] == '\0')
2213 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2218 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2221 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2222 threadref
*nextthread
)
2224 *pkt
++ = 'q'; /* info query packet */
2225 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2226 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2227 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2228 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2233 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2236 parse_threadlist_response (char *pkt
, int result_limit
,
2237 threadref
*original_echo
, threadref
*resultlist
,
2240 struct remote_state
*rs
= get_remote_state ();
2242 int count
, resultcount
, done
;
2245 /* Assume the 'q' and 'M chars have been stripped. */
2246 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2247 /* done parse past here */
2248 pkt
= unpack_byte (pkt
, &count
); /* count field */
2249 pkt
= unpack_nibble (pkt
, &done
);
2250 /* The first threadid is the argument threadid. */
2251 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2252 while ((count
-- > 0) && (pkt
< limit
))
2254 pkt
= unpack_threadid (pkt
, resultlist
++);
2255 if (resultcount
++ >= result_limit
)
2264 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2265 int *done
, int *result_count
, threadref
*threadlist
)
2267 struct remote_state
*rs
= get_remote_state ();
2268 static threadref echo_nextthread
;
2271 /* Trancate result limit to be smaller than the packet size. */
2272 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
2273 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2275 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2277 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2279 if (*rs
->buf
== '\0')
2283 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2286 if (!threadmatch (&echo_nextthread
, nextthread
))
2288 /* FIXME: This is a good reason to drop the packet. */
2289 /* Possably, there is a duplicate response. */
2291 retransmit immediatly - race conditions
2292 retransmit after timeout - yes
2294 wait for packet, then exit
2296 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2297 return 0; /* I choose simply exiting. */
2299 if (*result_count
<= 0)
2303 warning (_("RMT ERROR : failed to get remote thread list."));
2306 return result
; /* break; */
2308 if (*result_count
> result_limit
)
2311 warning (_("RMT ERROR: threadlist response longer than requested."));
2317 /* This is the interface between remote and threads, remotes upper
2320 /* remote_find_new_threads retrieves the thread list and for each
2321 thread in the list, looks up the thread in GDB's internal list,
2322 adding the thread if it does not already exist. This involves
2323 getting partial thread lists from the remote target so, polling the
2324 quit_flag is required. */
2327 /* About this many threadisds fit in a packet. */
2329 #define MAXTHREADLISTRESULTS 32
2332 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2335 int done
, i
, result_count
;
2339 static threadref nextthread
;
2340 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2345 if (loopcount
++ > looplimit
)
2348 warning (_("Remote fetch threadlist -infinite loop-."));
2351 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2352 &done
, &result_count
, resultthreadlist
))
2357 /* Clear for later iterations. */
2359 /* Setup to resume next batch of thread references, set nextthread. */
2360 if (result_count
>= 1)
2361 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2363 while (result_count
--)
2364 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2371 remote_newthread_step (threadref
*ref
, void *context
)
2373 int pid
= ptid_get_pid (inferior_ptid
);
2374 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2376 if (!in_thread_list (ptid
))
2378 return 1; /* continue iterator */
2381 #define CRAZY_MAX_THREADS 1000
2384 remote_current_thread (ptid_t oldpid
)
2386 struct remote_state
*rs
= get_remote_state ();
2389 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2390 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2391 return read_ptid (&rs
->buf
[2], NULL
);
2396 /* Find new threads for info threads command.
2397 * Original version, using John Metzler's thread protocol.
2401 remote_find_new_threads (void)
2403 remote_threadlist_iterator (remote_newthread_step
, 0,
2407 #if defined(HAVE_LIBEXPAT)
2409 typedef struct thread_item
2415 DEF_VEC_O(thread_item_t
);
2417 struct threads_parsing_context
2419 VEC (thread_item_t
) *items
;
2423 start_thread (struct gdb_xml_parser
*parser
,
2424 const struct gdb_xml_element
*element
,
2425 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2427 struct threads_parsing_context
*data
= user_data
;
2429 struct thread_item item
;
2432 id
= VEC_index (gdb_xml_value_s
, attributes
, 0)->value
;
2433 item
.ptid
= read_ptid (id
, NULL
);
2435 if (VEC_length (gdb_xml_value_s
, attributes
) > 1)
2436 item
.core
= *(ULONGEST
*) VEC_index (gdb_xml_value_s
, attributes
, 1)->value
;
2442 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2446 end_thread (struct gdb_xml_parser
*parser
,
2447 const struct gdb_xml_element
*element
,
2448 void *user_data
, const char *body_text
)
2450 struct threads_parsing_context
*data
= user_data
;
2452 if (body_text
&& *body_text
)
2453 VEC_last (thread_item_t
, data
->items
)->extra
= strdup (body_text
);
2456 const struct gdb_xml_attribute thread_attributes
[] = {
2457 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2458 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2459 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2462 const struct gdb_xml_element thread_children
[] = {
2463 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2466 const struct gdb_xml_element threads_children
[] = {
2467 { "thread", thread_attributes
, thread_children
,
2468 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2469 start_thread
, end_thread
},
2470 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2473 const struct gdb_xml_element threads_elements
[] = {
2474 { "threads", NULL
, threads_children
,
2475 GDB_XML_EF_NONE
, NULL
, NULL
},
2476 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2482 * Find all threads for info threads command.
2483 * Uses new thread protocol contributed by Cisco.
2484 * Falls back and attempts to use the older method (above)
2485 * if the target doesn't respond to the new method.
2489 remote_threads_info (struct target_ops
*ops
)
2491 struct remote_state
*rs
= get_remote_state ();
2495 if (remote_desc
== 0) /* paranoia */
2496 error (_("Command can only be used when connected to the remote target."));
2498 #if defined(HAVE_LIBEXPAT)
2499 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2501 char *xml
= target_read_stralloc (¤t_target
,
2502 TARGET_OBJECT_THREADS
, NULL
);
2504 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2507 struct gdb_xml_parser
*parser
;
2508 struct threads_parsing_context context
;
2509 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2512 parser
= gdb_xml_create_parser_and_cleanup (_("threads"),
2516 gdb_xml_use_dtd (parser
, "threads.dtd");
2518 if (gdb_xml_parse (parser
, xml
) == 0)
2521 struct thread_item
*item
;
2523 for (i
= 0; VEC_iterate (thread_item_t
, context
.items
, i
, item
); ++i
)
2525 if (!ptid_equal (item
->ptid
, null_ptid
))
2527 struct private_thread_info
*info
;
2528 /* In non-stop mode, we assume new found threads
2529 are running until proven otherwise with a
2530 stop reply. In all-stop, we can only get
2531 here if all threads are stopped. */
2532 int running
= non_stop
? 1 : 0;
2534 remote_notice_new_inferior (item
->ptid
, running
);
2536 info
= demand_private_info (item
->ptid
);
2537 info
->core
= item
->core
;
2538 info
->extra
= item
->extra
;
2541 xfree (item
->extra
);
2545 VEC_free (thread_item_t
, context
.items
);
2548 do_cleanups (back_to
);
2553 if (use_threadinfo_query
)
2555 putpkt ("qfThreadInfo");
2556 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2558 if (bufp
[0] != '\0') /* q packet recognized */
2560 while (*bufp
++ == 'm') /* reply contains one or more TID */
2564 new_thread
= read_ptid (bufp
, &bufp
);
2565 if (!ptid_equal (new_thread
, null_ptid
))
2567 /* In non-stop mode, we assume new found threads
2568 are running until proven otherwise with a
2569 stop reply. In all-stop, we can only get
2570 here if all threads are stopped. */
2571 int running
= non_stop
? 1 : 0;
2573 remote_notice_new_inferior (new_thread
, running
);
2576 while (*bufp
++ == ','); /* comma-separated list */
2577 putpkt ("qsThreadInfo");
2578 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2585 /* Only qfThreadInfo is supported in non-stop mode. */
2589 /* Else fall back to old method based on jmetzler protocol. */
2590 use_threadinfo_query
= 0;
2591 remote_find_new_threads ();
2596 * Collect a descriptive string about the given thread.
2597 * The target may say anything it wants to about the thread
2598 * (typically info about its blocked / runnable state, name, etc.).
2599 * This string will appear in the info threads display.
2601 * Optional: targets are not required to implement this function.
2605 remote_threads_extra_info (struct thread_info
*tp
)
2607 struct remote_state
*rs
= get_remote_state ();
2611 struct gdb_ext_thread_info threadinfo
;
2612 static char display_buf
[100]; /* arbitrary... */
2613 int n
= 0; /* position in display_buf */
2615 if (remote_desc
== 0) /* paranoia */
2616 internal_error (__FILE__
, __LINE__
,
2617 _("remote_threads_extra_info"));
2619 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2620 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2621 /* This is the main thread which was added by GDB. The remote
2622 server doesn't know about it. */
2625 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2627 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2628 if (info
&& info
->private)
2629 return info
->private->extra
;
2634 if (use_threadextra_query
)
2637 char *endb
= rs
->buf
+ get_remote_packet_size ();
2639 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2641 write_ptid (b
, endb
, tp
->ptid
);
2644 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2645 if (rs
->buf
[0] != 0)
2647 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2648 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2649 display_buf
[result
] = '\0';
2654 /* If the above query fails, fall back to the old method. */
2655 use_threadextra_query
= 0;
2656 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2657 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2658 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2659 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2660 if (threadinfo
.active
)
2662 if (*threadinfo
.shortname
)
2663 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2664 " Name: %s,", threadinfo
.shortname
);
2665 if (*threadinfo
.display
)
2666 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2667 " State: %s,", threadinfo
.display
);
2668 if (*threadinfo
.more_display
)
2669 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2670 " Priority: %s", threadinfo
.more_display
);
2674 /* For purely cosmetic reasons, clear up trailing commas. */
2675 if (',' == display_buf
[n
-1])
2676 display_buf
[n
-1] = ' ';
2684 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2687 remote_get_ada_task_ptid (long lwp
, long thread
)
2689 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2693 /* Restart the remote side; this is an extended protocol operation. */
2696 extended_remote_restart (void)
2698 struct remote_state
*rs
= get_remote_state ();
2700 /* Send the restart command; for reasons I don't understand the
2701 remote side really expects a number after the "R". */
2702 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2705 remote_fileio_reset ();
2708 /* Clean up connection to a remote debugger. */
2711 remote_close (int quitting
)
2713 if (remote_desc
== NULL
)
2714 return; /* already closed */
2716 /* Make sure we leave stdin registered in the event loop, and we
2717 don't leave the async SIGINT signal handler installed. */
2718 remote_terminal_ours ();
2720 serial_close (remote_desc
);
2723 /* We don't have a connection to the remote stub anymore. Get rid
2724 of all the inferiors and their threads we were controlling. */
2725 discard_all_inferiors ();
2727 /* We're no longer interested in any of these events. */
2728 discard_pending_stop_replies (-1);
2730 if (remote_async_inferior_event_token
)
2731 delete_async_event_handler (&remote_async_inferior_event_token
);
2732 if (remote_async_get_pending_events_token
)
2733 delete_async_event_handler (&remote_async_get_pending_events_token
);
2736 /* Query the remote side for the text, data and bss offsets. */
2741 struct remote_state
*rs
= get_remote_state ();
2744 int lose
, num_segments
= 0, do_sections
, do_segments
;
2745 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2746 struct section_offsets
*offs
;
2747 struct symfile_segment_data
*data
;
2749 if (symfile_objfile
== NULL
)
2752 putpkt ("qOffsets");
2753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2756 if (buf
[0] == '\000')
2757 return; /* Return silently. Stub doesn't support
2761 warning (_("Remote failure reply: %s"), buf
);
2765 /* Pick up each field in turn. This used to be done with scanf, but
2766 scanf will make trouble if CORE_ADDR size doesn't match
2767 conversion directives correctly. The following code will work
2768 with any size of CORE_ADDR. */
2769 text_addr
= data_addr
= bss_addr
= 0;
2773 if (strncmp (ptr
, "Text=", 5) == 0)
2776 /* Don't use strtol, could lose on big values. */
2777 while (*ptr
&& *ptr
!= ';')
2778 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2780 if (strncmp (ptr
, ";Data=", 6) == 0)
2783 while (*ptr
&& *ptr
!= ';')
2784 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2789 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2792 while (*ptr
&& *ptr
!= ';')
2793 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2795 if (bss_addr
!= data_addr
)
2796 warning (_("Target reported unsupported offsets: %s"), buf
);
2801 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2804 /* Don't use strtol, could lose on big values. */
2805 while (*ptr
&& *ptr
!= ';')
2806 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2809 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2812 while (*ptr
&& *ptr
!= ';')
2813 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2821 error (_("Malformed response to offset query, %s"), buf
);
2822 else if (*ptr
!= '\0')
2823 warning (_("Target reported unsupported offsets: %s"), buf
);
2825 offs
= ((struct section_offsets
*)
2826 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2827 memcpy (offs
, symfile_objfile
->section_offsets
,
2828 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2830 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2831 do_segments
= (data
!= NULL
);
2832 do_sections
= num_segments
== 0;
2834 if (num_segments
> 0)
2836 segments
[0] = text_addr
;
2837 segments
[1] = data_addr
;
2839 /* If we have two segments, we can still try to relocate everything
2840 by assuming that the .text and .data offsets apply to the whole
2841 text and data segments. Convert the offsets given in the packet
2842 to base addresses for symfile_map_offsets_to_segments. */
2843 else if (data
&& data
->num_segments
== 2)
2845 segments
[0] = data
->segment_bases
[0] + text_addr
;
2846 segments
[1] = data
->segment_bases
[1] + data_addr
;
2849 /* If the object file has only one segment, assume that it is text
2850 rather than data; main programs with no writable data are rare,
2851 but programs with no code are useless. Of course the code might
2852 have ended up in the data segment... to detect that we would need
2853 the permissions here. */
2854 else if (data
&& data
->num_segments
== 1)
2856 segments
[0] = data
->segment_bases
[0] + text_addr
;
2859 /* There's no way to relocate by segment. */
2865 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2866 offs
, num_segments
, segments
);
2868 if (ret
== 0 && !do_sections
)
2869 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2876 free_symfile_segment_data (data
);
2880 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2882 /* This is a temporary kludge to force data and bss to use the same offsets
2883 because that's what nlmconv does now. The real solution requires changes
2884 to the stub and remote.c that I don't have time to do right now. */
2886 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2887 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2890 objfile_relocate (symfile_objfile
, offs
);
2893 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
2894 threads we know are stopped already. This is used during the
2895 initial remote connection in non-stop mode --- threads that are
2896 reported as already being stopped are left stopped. */
2899 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
2901 /* If we have a stop reply for this thread, it must be stopped. */
2902 if (peek_stop_reply (thread
->ptid
))
2903 set_stop_requested (thread
->ptid
, 1);
2908 /* Stub for catch_exception. */
2910 struct start_remote_args
2914 /* The current target. */
2915 struct target_ops
*target
;
2917 /* Non-zero if this is an extended-remote target. */
2921 /* Send interrupt_sequence to remote target. */
2923 send_interrupt_sequence ()
2925 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
2926 serial_write (remote_desc
, "\x03", 1);
2927 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
2928 serial_send_break (remote_desc
);
2929 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
2931 serial_send_break (remote_desc
);
2932 serial_write (remote_desc
, "g", 1);
2935 internal_error (__FILE__
, __LINE__
,
2936 _("Invalid value for interrupt_sequence_mode: %s."),
2937 interrupt_sequence_mode
);
2941 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2943 struct start_remote_args
*args
= opaque
;
2944 struct remote_state
*rs
= get_remote_state ();
2945 struct packet_config
*noack_config
;
2946 char *wait_status
= NULL
;
2948 immediate_quit
++; /* Allow user to interrupt it. */
2950 /* Ack any packet which the remote side has already sent. */
2951 serial_write (remote_desc
, "+", 1);
2953 if (interrupt_on_connect
)
2954 send_interrupt_sequence ();
2956 /* The first packet we send to the target is the optional "supported
2957 packets" request. If the target can answer this, it will tell us
2958 which later probes to skip. */
2959 remote_query_supported ();
2961 /* Next, we possibly activate noack mode.
2963 If the QStartNoAckMode packet configuration is set to AUTO,
2964 enable noack mode if the stub reported a wish for it with
2967 If set to TRUE, then enable noack mode even if the stub didn't
2968 report it in qSupported. If the stub doesn't reply OK, the
2969 session ends with an error.
2971 If FALSE, then don't activate noack mode, regardless of what the
2972 stub claimed should be the default with qSupported. */
2974 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2976 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2977 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2978 && noack_config
->support
== PACKET_ENABLE
))
2980 putpkt ("QStartNoAckMode");
2981 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2982 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2986 if (args
->extended_p
)
2988 /* Tell the remote that we are using the extended protocol. */
2990 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2993 /* Next, if the target can specify a description, read it. We do
2994 this before anything involving memory or registers. */
2995 target_find_description ();
2997 /* Next, now that we know something about the target, update the
2998 address spaces in the program spaces. */
2999 update_address_spaces ();
3001 /* On OSs where the list of libraries is global to all
3002 processes, we fetch them early. */
3003 if (gdbarch_has_global_solist (target_gdbarch
))
3004 solib_add (NULL
, args
->from_tty
, args
->target
, auto_solib_add
);
3008 if (!rs
->non_stop_aware
)
3009 error (_("Non-stop mode requested, but remote does not support non-stop"));
3011 putpkt ("QNonStop:1");
3012 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3014 if (strcmp (rs
->buf
, "OK") != 0)
3015 error ("Remote refused setting non-stop mode with: %s", rs
->buf
);
3017 /* Find about threads and processes the stub is already
3018 controlling. We default to adding them in the running state.
3019 The '?' query below will then tell us about which threads are
3021 remote_threads_info (args
->target
);
3023 else if (rs
->non_stop_aware
)
3025 /* Don't assume that the stub can operate in all-stop mode.
3026 Request it explicitely. */
3027 putpkt ("QNonStop:0");
3028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3030 if (strcmp (rs
->buf
, "OK") != 0)
3031 error ("Remote refused setting all-stop mode with: %s", rs
->buf
);
3034 /* Check whether the target is running now. */
3036 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3040 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3042 if (!args
->extended_p
)
3043 error (_("The target is not running (try extended-remote?)"));
3045 /* We're connected, but not running. Drop out before we
3046 call start_remote. */
3051 /* Save the reply for later. */
3052 wait_status
= alloca (strlen (rs
->buf
) + 1);
3053 strcpy (wait_status
, rs
->buf
);
3056 /* Let the stub know that we want it to return the thread. */
3057 set_continue_thread (minus_one_ptid
);
3059 /* Without this, some commands which require an active target
3060 (such as kill) won't work. This variable serves (at least)
3061 double duty as both the pid of the target process (if it has
3062 such), and as a flag indicating that a target is active.
3063 These functions should be split out into seperate variables,
3064 especially since GDB will someday have a notion of debugging
3065 several processes. */
3066 inferior_ptid
= magic_null_ptid
;
3068 /* Now, if we have thread information, update inferior_ptid. */
3069 inferior_ptid
= remote_current_thread (inferior_ptid
);
3071 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3073 /* Always add the main thread. */
3074 add_thread_silent (inferior_ptid
);
3076 get_offsets (); /* Get text, data & bss offsets. */
3078 /* If we could not find a description using qXfer, and we know
3079 how to do it some other way, try again. This is not
3080 supported for non-stop; it could be, but it is tricky if
3081 there are no stopped threads when we connect. */
3082 if (remote_read_description_p (args
->target
)
3083 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3085 target_clear_description ();
3086 target_find_description ();
3089 /* Use the previously fetched status. */
3090 gdb_assert (wait_status
!= NULL
);
3091 strcpy (rs
->buf
, wait_status
);
3092 rs
->cached_wait_status
= 1;
3095 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
3099 /* Clear WFI global state. Do this before finding about new
3100 threads and inferiors, and setting the current inferior.
3101 Otherwise we would clear the proceed status of the current
3102 inferior when we want its stop_soon state to be preserved
3103 (see notice_new_inferior). */
3104 init_wait_for_inferior ();
3106 /* In non-stop, we will either get an "OK", meaning that there
3107 are no stopped threads at this time; or, a regular stop
3108 reply. In the latter case, there may be more than one thread
3109 stopped --- we pull them all out using the vStopped
3111 if (strcmp (rs
->buf
, "OK") != 0)
3113 struct stop_reply
*stop_reply
;
3114 struct cleanup
*old_chain
;
3116 stop_reply
= stop_reply_xmalloc ();
3117 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3119 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3120 discard_cleanups (old_chain
);
3122 /* get_pending_stop_replies acks this one, and gets the rest
3124 pending_stop_reply
= stop_reply
;
3125 remote_get_pending_stop_replies ();
3127 /* Make sure that threads that were stopped remain
3129 iterate_over_threads (set_stop_requested_callback
, NULL
);
3132 if (target_can_async_p ())
3133 target_async (inferior_event_handler
, 0);
3135 if (thread_count () == 0)
3137 if (!args
->extended_p
)
3138 error (_("The target is not running (try extended-remote?)"));
3140 /* We're connected, but not running. Drop out before we
3141 call start_remote. */
3145 /* Let the stub know that we want it to return the thread. */
3147 /* Force the stub to choose a thread. */
3148 set_general_thread (null_ptid
);
3151 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3152 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3153 error (_("remote didn't report the current thread in non-stop mode"));
3155 get_offsets (); /* Get text, data & bss offsets. */
3157 /* In non-stop mode, any cached wait status will be stored in
3158 the stop reply queue. */
3159 gdb_assert (wait_status
== NULL
);
3162 /* If we connected to a live target, do some additional setup. */
3163 if (target_has_execution
)
3165 if (exec_bfd
) /* No use without an exec file. */
3166 remote_check_symbols (symfile_objfile
);
3169 /* Possibly the target has been engaged in a trace run started
3170 previously; find out where things are at. */
3171 if (rs
->disconnected_tracing
)
3173 struct uploaded_tp
*uploaded_tps
= NULL
;
3174 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3176 remote_get_trace_status (current_trace_status ());
3177 if (current_trace_status ()->running
)
3178 printf_filtered (_("Trace is already running on the target.\n"));
3180 /* Get trace state variables first, they may be checked when
3181 parsing uploaded commands. */
3183 remote_upload_trace_state_variables (&uploaded_tsvs
);
3185 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3187 remote_upload_tracepoints (&uploaded_tps
);
3189 merge_uploaded_tracepoints (&uploaded_tps
);
3192 /* If breakpoints are global, insert them now. */
3193 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3194 && breakpoints_always_inserted_mode ())
3195 insert_breakpoints ();
3198 /* Open a connection to a remote debugger.
3199 NAME is the filename used for communication. */
3202 remote_open (char *name
, int from_tty
)
3204 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3207 /* Open a connection to a remote debugger using the extended
3208 remote gdb protocol. NAME is the filename used for communication. */
3211 extended_remote_open (char *name
, int from_tty
)
3213 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3216 /* Generic code for opening a connection to a remote target. */
3219 init_all_packet_configs (void)
3222 for (i
= 0; i
< PACKET_MAX
; i
++)
3223 update_packet_config (&remote_protocol_packets
[i
]);
3226 /* Symbol look-up. */
3229 remote_check_symbols (struct objfile
*objfile
)
3231 struct remote_state
*rs
= get_remote_state ();
3232 char *msg
, *reply
, *tmp
;
3233 struct minimal_symbol
*sym
;
3236 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3239 /* Make sure the remote is pointing at the right process. */
3240 set_general_process ();
3242 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3243 because we need both at the same time. */
3244 msg
= alloca (get_remote_packet_size ());
3246 /* Invite target to request symbol lookups. */
3248 putpkt ("qSymbol::");
3249 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3250 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3253 while (strncmp (reply
, "qSymbol:", 8) == 0)
3256 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3258 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3260 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3263 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3264 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3266 /* If this is a function address, return the start of code
3267 instead of any data function descriptor. */
3268 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3272 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3273 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3277 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3282 static struct serial
*
3283 remote_serial_open (char *name
)
3285 static int udp_warning
= 0;
3287 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3288 of in ser-tcp.c, because it is the remote protocol assuming that the
3289 serial connection is reliable and not the serial connection promising
3291 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3294 The remote protocol may be unreliable over UDP.\n\
3295 Some events may be lost, rendering further debugging impossible."));
3299 return serial_open (name
);
3302 /* This type describes each known response to the qSupported
3304 struct protocol_feature
3306 /* The name of this protocol feature. */
3309 /* The default for this protocol feature. */
3310 enum packet_support default_support
;
3312 /* The function to call when this feature is reported, or after
3313 qSupported processing if the feature is not supported.
3314 The first argument points to this structure. The second
3315 argument indicates whether the packet requested support be
3316 enabled, disabled, or probed (or the default, if this function
3317 is being called at the end of processing and this feature was
3318 not reported). The third argument may be NULL; if not NULL, it
3319 is a NUL-terminated string taken from the packet following
3320 this feature's name and an equals sign. */
3321 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3324 /* The corresponding packet for this feature. Only used if
3325 FUNC is remote_supported_packet. */
3330 remote_supported_packet (const struct protocol_feature
*feature
,
3331 enum packet_support support
,
3332 const char *argument
)
3336 warning (_("Remote qSupported response supplied an unexpected value for"
3337 " \"%s\"."), feature
->name
);
3341 if (remote_protocol_packets
[feature
->packet
].support
3342 == PACKET_SUPPORT_UNKNOWN
)
3343 remote_protocol_packets
[feature
->packet
].support
= support
;
3347 remote_packet_size (const struct protocol_feature
*feature
,
3348 enum packet_support support
, const char *value
)
3350 struct remote_state
*rs
= get_remote_state ();
3355 if (support
!= PACKET_ENABLE
)
3358 if (value
== NULL
|| *value
== '\0')
3360 warning (_("Remote target reported \"%s\" without a size."),
3366 packet_size
= strtol (value
, &value_end
, 16);
3367 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3369 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3370 feature
->name
, value
);
3374 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3376 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3377 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3378 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3381 /* Record the new maximum packet size. */
3382 rs
->explicit_packet_size
= packet_size
;
3386 remote_multi_process_feature (const struct protocol_feature
*feature
,
3387 enum packet_support support
, const char *value
)
3389 struct remote_state
*rs
= get_remote_state ();
3390 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3394 remote_non_stop_feature (const struct protocol_feature
*feature
,
3395 enum packet_support support
, const char *value
)
3397 struct remote_state
*rs
= get_remote_state ();
3398 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3402 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3403 enum packet_support support
,
3406 struct remote_state
*rs
= get_remote_state ();
3407 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3411 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3412 enum packet_support support
,
3415 struct remote_state
*rs
= get_remote_state ();
3416 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3420 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3421 enum packet_support support
,
3424 struct remote_state
*rs
= get_remote_state ();
3425 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3428 static struct protocol_feature remote_protocol_features
[] = {
3429 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3430 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3431 PACKET_qXfer_auxv
},
3432 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3433 PACKET_qXfer_features
},
3434 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3435 PACKET_qXfer_libraries
},
3436 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3437 PACKET_qXfer_memory_map
},
3438 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3439 PACKET_qXfer_spu_read
},
3440 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3441 PACKET_qXfer_spu_write
},
3442 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3443 PACKET_qXfer_osdata
},
3444 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3445 PACKET_qXfer_threads
},
3446 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3447 PACKET_QPassSignals
},
3448 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3449 PACKET_QStartNoAckMode
},
3450 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3451 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3452 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3453 PACKET_qXfer_siginfo_read
},
3454 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3455 PACKET_qXfer_siginfo_write
},
3456 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3457 PACKET_ConditionalTracepoints
},
3458 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3459 PACKET_FastTracepoints
},
3460 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3462 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3464 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3466 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3467 PACKET_TracepointSource
},
3470 static char *remote_support_xml
;
3472 /* Register string appended to "xmlRegisters=" in qSupported query. */
3475 register_remote_support_xml (const char *xml ATTRIBUTE_UNUSED
)
3477 #if defined(HAVE_LIBEXPAT)
3478 if (remote_support_xml
== NULL
)
3479 remote_support_xml
= concat ("xmlRegisters=", xml
, NULL
);
3482 char *copy
= xstrdup (remote_support_xml
+ 13);
3483 char *p
= strtok (copy
, ",");
3487 if (strcmp (p
, xml
) == 0)
3494 while ((p
= strtok (NULL
, ",")) != NULL
);
3497 p
= concat (remote_support_xml
, ",", xml
, NULL
);
3498 xfree (remote_support_xml
);
3499 remote_support_xml
= p
;
3505 remote_query_supported_append (char *msg
, const char *append
)
3509 char *p
= concat (msg
, ";", append
, NULL
);
3514 return xstrdup (append
);
3518 remote_query_supported (void)
3520 struct remote_state
*rs
= get_remote_state ();
3523 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3525 /* The packet support flags are handled differently for this packet
3526 than for most others. We treat an error, a disabled packet, and
3527 an empty response identically: any features which must be reported
3528 to be used will be automatically disabled. An empty buffer
3529 accomplishes this, since that is also the representation for a list
3530 containing no features. */
3533 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3536 const char *qsupported
= gdbarch_qsupported (target_gdbarch
);
3539 q
= remote_query_supported_append (q
, "multiprocess+");
3542 q
= remote_query_supported_append (q
, qsupported
);
3544 if (remote_support_xml
)
3545 q
= remote_query_supported_append (q
, remote_support_xml
);
3549 char *p
= concat ("qSupported:", q
, NULL
);
3555 putpkt ("qSupported");
3557 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3559 /* If an error occured, warn, but do not return - just reset the
3560 buffer to empty and go on to disable features. */
3561 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3564 warning (_("Remote failure reply: %s"), rs
->buf
);
3569 memset (seen
, 0, sizeof (seen
));
3574 enum packet_support is_supported
;
3575 char *p
, *end
, *name_end
, *value
;
3577 /* First separate out this item from the rest of the packet. If
3578 there's another item after this, we overwrite the separator
3579 (terminated strings are much easier to work with). */
3581 end
= strchr (p
, ';');
3584 end
= p
+ strlen (p
);
3594 warning (_("empty item in \"qSupported\" response"));
3599 name_end
= strchr (p
, '=');
3602 /* This is a name=value entry. */
3603 is_supported
= PACKET_ENABLE
;
3604 value
= name_end
+ 1;
3613 is_supported
= PACKET_ENABLE
;
3617 is_supported
= PACKET_DISABLE
;
3621 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3625 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
3631 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3632 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3634 const struct protocol_feature
*feature
;
3637 feature
= &remote_protocol_features
[i
];
3638 feature
->func (feature
, is_supported
, value
);
3643 /* If we increased the packet size, make sure to increase the global
3644 buffer size also. We delay this until after parsing the entire
3645 qSupported packet, because this is the same buffer we were
3647 if (rs
->buf_size
< rs
->explicit_packet_size
)
3649 rs
->buf_size
= rs
->explicit_packet_size
;
3650 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3653 /* Handle the defaults for unmentioned features. */
3654 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3657 const struct protocol_feature
*feature
;
3659 feature
= &remote_protocol_features
[i
];
3660 feature
->func (feature
, feature
->default_support
, NULL
);
3666 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
3668 struct remote_state
*rs
= get_remote_state ();
3671 error (_("To open a remote debug connection, you need to specify what\n"
3672 "serial device is attached to the remote system\n"
3673 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3675 /* See FIXME above. */
3676 if (!target_async_permitted
)
3677 wait_forever_enabled_p
= 1;
3679 /* If we're connected to a running target, target_preopen will kill it.
3680 But if we're connected to a target system with no running process,
3681 then we will still be connected when it returns. Ask this question
3682 first, before target_preopen has a chance to kill anything. */
3683 if (remote_desc
!= NULL
&& !have_inferiors ())
3686 || query (_("Already connected to a remote target. Disconnect? ")))
3689 error (_("Still connected."));
3692 target_preopen (from_tty
);
3694 unpush_target (target
);
3696 /* This time without a query. If we were connected to an
3697 extended-remote target and target_preopen killed the running
3698 process, we may still be connected. If we are starting "target
3699 remote" now, the extended-remote target will not have been
3700 removed by unpush_target. */
3701 if (remote_desc
!= NULL
&& !have_inferiors ())
3704 /* Make sure we send the passed signals list the next time we resume. */
3705 xfree (last_pass_packet
);
3706 last_pass_packet
= NULL
;
3708 remote_fileio_reset ();
3709 reopen_exec_file ();
3712 remote_desc
= remote_serial_open (name
);
3714 perror_with_name (name
);
3716 if (baud_rate
!= -1)
3718 if (serial_setbaudrate (remote_desc
, baud_rate
))
3720 /* The requested speed could not be set. Error out to
3721 top level after closing remote_desc. Take care to
3722 set remote_desc to NULL to avoid closing remote_desc
3724 serial_close (remote_desc
);
3726 perror_with_name (name
);
3730 serial_raw (remote_desc
);
3732 /* If there is something sitting in the buffer we might take it as a
3733 response to a command, which would be bad. */
3734 serial_flush_input (remote_desc
);
3738 puts_filtered ("Remote debugging using ");
3739 puts_filtered (name
);
3740 puts_filtered ("\n");
3742 push_target (target
); /* Switch to using remote target now. */
3744 /* Register extra event sources in the event loop. */
3745 remote_async_inferior_event_token
3746 = create_async_event_handler (remote_async_inferior_event_handler
,
3748 remote_async_get_pending_events_token
3749 = create_async_event_handler (remote_async_get_pending_events_handler
,
3752 /* Reset the target state; these things will be queried either by
3753 remote_query_supported or as they are needed. */
3754 init_all_packet_configs ();
3755 rs
->cached_wait_status
= 0;
3756 rs
->explicit_packet_size
= 0;
3758 rs
->multi_process_aware
= 0;
3759 rs
->extended
= extended_p
;
3760 rs
->non_stop_aware
= 0;
3761 rs
->waiting_for_stop_reply
= 0;
3762 rs
->ctrlc_pending_p
= 0;
3764 general_thread
= not_sent_ptid
;
3765 continue_thread
= not_sent_ptid
;
3767 /* Probe for ability to use "ThreadInfo" query, as required. */
3768 use_threadinfo_query
= 1;
3769 use_threadextra_query
= 1;
3771 if (target_async_permitted
)
3773 /* With this target we start out by owning the terminal. */
3774 remote_async_terminal_ours_p
= 1;
3776 /* FIXME: cagney/1999-09-23: During the initial connection it is
3777 assumed that the target is already ready and able to respond to
3778 requests. Unfortunately remote_start_remote() eventually calls
3779 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
3780 around this. Eventually a mechanism that allows
3781 wait_for_inferior() to expect/get timeouts will be
3783 wait_forever_enabled_p
= 0;
3786 /* First delete any symbols previously loaded from shared libraries. */
3787 no_shared_libraries (NULL
, 0);
3790 init_thread_list ();
3792 /* Start the remote connection. If error() or QUIT, discard this
3793 target (we'd otherwise be in an inconsistent state) and then
3794 propogate the error on up the exception chain. This ensures that
3795 the caller doesn't stumble along blindly assuming that the
3796 function succeeded. The CLI doesn't have this problem but other
3797 UI's, such as MI do.
3799 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
3800 this function should return an error indication letting the
3801 caller restore the previous state. Unfortunately the command
3802 ``target remote'' is directly wired to this function making that
3803 impossible. On a positive note, the CLI side of this problem has
3804 been fixed - the function set_cmd_context() makes it possible for
3805 all the ``target ....'' commands to share a common callback
3806 function. See cli-dump.c. */
3808 struct gdb_exception ex
;
3809 struct start_remote_args args
;
3811 args
.from_tty
= from_tty
;
3812 args
.target
= target
;
3813 args
.extended_p
= extended_p
;
3815 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
3818 /* Pop the partially set up target - unless something else did
3819 already before throwing the exception. */
3820 if (remote_desc
!= NULL
)
3822 if (target_async_permitted
)
3823 wait_forever_enabled_p
= 1;
3824 throw_exception (ex
);
3828 if (target_async_permitted
)
3829 wait_forever_enabled_p
= 1;
3832 /* This takes a program previously attached to and detaches it. After
3833 this is done, GDB can be used to debug some other program. We
3834 better not have left any breakpoints in the target program or it'll
3835 die when it hits one. */
3838 remote_detach_1 (char *args
, int from_tty
, int extended
)
3840 int pid
= ptid_get_pid (inferior_ptid
);
3841 struct remote_state
*rs
= get_remote_state ();
3844 error (_("Argument given to \"detach\" when remotely debugging."));
3846 if (!target_has_execution
)
3847 error (_("No process to detach from."));
3849 /* Tell the remote target to detach. */
3850 if (remote_multi_process_p (rs
))
3851 sprintf (rs
->buf
, "D;%x", pid
);
3853 strcpy (rs
->buf
, "D");
3856 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3858 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3860 else if (rs
->buf
[0] == '\0')
3861 error (_("Remote doesn't know how to detach"));
3863 error (_("Can't detach process."));
3867 if (remote_multi_process_p (rs
))
3868 printf_filtered (_("Detached from remote %s.\n"),
3869 target_pid_to_str (pid_to_ptid (pid
)));
3873 puts_filtered (_("Detached from remote process.\n"));
3875 puts_filtered (_("Ending remote debugging.\n"));
3879 discard_pending_stop_replies (pid
);
3880 target_mourn_inferior ();
3884 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3886 remote_detach_1 (args
, from_tty
, 0);
3890 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3892 remote_detach_1 (args
, from_tty
, 1);
3895 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3898 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3901 error (_("Argument given to \"disconnect\" when remotely debugging."));
3903 /* Make sure we unpush even the extended remote targets; mourn
3904 won't do it. So call remote_mourn_1 directly instead of
3905 target_mourn_inferior. */
3906 remote_mourn_1 (target
);
3909 puts_filtered ("Ending remote debugging.\n");
3912 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3913 be chatty about it. */
3916 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3918 struct remote_state
*rs
= get_remote_state ();
3920 char *wait_status
= NULL
;
3922 pid
= parse_pid_to_attach (args
);
3924 /* Remote PID can be freely equal to getpid, do not check it here the same
3925 way as in other targets. */
3927 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3928 error (_("This target does not support attaching to a process"));
3930 sprintf (rs
->buf
, "vAttach;%x", pid
);
3932 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3934 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3937 printf_unfiltered (_("Attached to %s\n"),
3938 target_pid_to_str (pid_to_ptid (pid
)));
3942 /* Save the reply for later. */
3943 wait_status
= alloca (strlen (rs
->buf
) + 1);
3944 strcpy (wait_status
, rs
->buf
);
3946 else if (strcmp (rs
->buf
, "OK") != 0)
3947 error (_("Attaching to %s failed with: %s"),
3948 target_pid_to_str (pid_to_ptid (pid
)),
3951 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3952 error (_("This target does not support attaching to a process"));
3954 error (_("Attaching to %s failed"),
3955 target_pid_to_str (pid_to_ptid (pid
)));
3957 set_current_inferior (remote_add_inferior (pid
, 1));
3959 inferior_ptid
= pid_to_ptid (pid
);
3963 struct thread_info
*thread
;
3965 /* Get list of threads. */
3966 remote_threads_info (target
);
3968 thread
= first_thread_of_process (pid
);
3970 inferior_ptid
= thread
->ptid
;
3972 inferior_ptid
= pid_to_ptid (pid
);
3974 /* Invalidate our notion of the remote current thread. */
3975 record_currthread (minus_one_ptid
);
3979 /* Now, if we have thread information, update inferior_ptid. */
3980 inferior_ptid
= remote_current_thread (inferior_ptid
);
3982 /* Add the main thread to the thread list. */
3983 add_thread_silent (inferior_ptid
);
3986 /* Next, if the target can specify a description, read it. We do
3987 this before anything involving memory or registers. */
3988 target_find_description ();
3992 /* Use the previously fetched status. */
3993 gdb_assert (wait_status
!= NULL
);
3995 if (target_can_async_p ())
3997 struct stop_reply
*stop_reply
;
3998 struct cleanup
*old_chain
;
4000 stop_reply
= stop_reply_xmalloc ();
4001 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4002 remote_parse_stop_reply (wait_status
, stop_reply
);
4003 discard_cleanups (old_chain
);
4004 push_stop_reply (stop_reply
);
4006 target_async (inferior_event_handler
, 0);
4010 gdb_assert (wait_status
!= NULL
);
4011 strcpy (rs
->buf
, wait_status
);
4012 rs
->cached_wait_status
= 1;
4016 gdb_assert (wait_status
== NULL
);
4020 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4022 extended_remote_attach_1 (ops
, args
, from_tty
);
4025 /* Convert hex digit A to a number. */
4030 if (a
>= '0' && a
<= '9')
4032 else if (a
>= 'a' && a
<= 'f')
4033 return a
- 'a' + 10;
4034 else if (a
>= 'A' && a
<= 'F')
4035 return a
- 'A' + 10;
4037 error (_("Reply contains invalid hex digit %d"), a
);
4041 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4045 for (i
= 0; i
< count
; i
++)
4047 if (hex
[0] == 0 || hex
[1] == 0)
4049 /* Hex string is short, or of uneven length.
4050 Return the count that has been converted so far. */
4053 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4059 /* Convert number NIB to a hex digit. */
4067 return 'a' + nib
- 10;
4071 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4074 /* May use a length, or a nul-terminated string as input. */
4076 count
= strlen ((char *) bin
);
4078 for (i
= 0; i
< count
; i
++)
4080 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4081 *hex
++ = tohex (*bin
++ & 0xf);
4087 /* Check for the availability of vCont. This function should also check
4091 remote_vcont_probe (struct remote_state
*rs
)
4095 strcpy (rs
->buf
, "vCont?");
4097 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4100 /* Make sure that the features we assume are supported. */
4101 if (strncmp (buf
, "vCont", 5) == 0)
4104 int support_s
, support_S
, support_c
, support_C
;
4110 rs
->support_vCont_t
= 0;
4111 while (p
&& *p
== ';')
4114 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4116 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4118 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4120 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4122 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4123 rs
->support_vCont_t
= 1;
4125 p
= strchr (p
, ';');
4128 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4129 BUF will make packet_ok disable the packet. */
4130 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4134 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4137 /* Helper function for building "vCont" resumptions. Write a
4138 resumption to P. ENDP points to one-passed-the-end of the buffer
4139 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4140 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4141 resumed thread should be single-stepped and/or signalled. If PTID
4142 equals minus_one_ptid, then all threads are resumed; if PTID
4143 represents a process, then all threads of the process are resumed;
4144 the thread to be stepped and/or signalled is given in the global
4148 append_resumption (char *p
, char *endp
,
4149 ptid_t ptid
, int step
, enum target_signal siggnal
)
4151 struct remote_state
*rs
= get_remote_state ();
4153 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4154 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4156 p
+= xsnprintf (p
, endp
- p
, ";s");
4157 else if (siggnal
!= TARGET_SIGNAL_0
)
4158 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4160 p
+= xsnprintf (p
, endp
- p
, ";c");
4162 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4166 /* All (-1) threads of process. */
4167 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4169 p
+= xsnprintf (p
, endp
- p
, ":");
4170 p
= write_ptid (p
, endp
, nptid
);
4172 else if (!ptid_equal (ptid
, minus_one_ptid
))
4174 p
+= xsnprintf (p
, endp
- p
, ":");
4175 p
= write_ptid (p
, endp
, ptid
);
4181 /* Resume the remote inferior by using a "vCont" packet. The thread
4182 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4183 resumed thread should be single-stepped and/or signalled. If PTID
4184 equals minus_one_ptid, then all threads are resumed; the thread to
4185 be stepped and/or signalled is given in the global INFERIOR_PTID.
4186 This function returns non-zero iff it resumes the inferior.
4188 This function issues a strict subset of all possible vCont commands at the
4192 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4194 struct remote_state
*rs
= get_remote_state ();
4198 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4199 remote_vcont_probe (rs
);
4201 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4205 endp
= rs
->buf
+ get_remote_packet_size ();
4207 /* If we could generate a wider range of packets, we'd have to worry
4208 about overflowing BUF. Should there be a generic
4209 "multi-part-packet" packet? */
4211 p
+= xsnprintf (p
, endp
- p
, "vCont");
4213 if (ptid_equal (ptid
, magic_null_ptid
))
4215 /* MAGIC_NULL_PTID means that we don't have any active threads,
4216 so we don't have any TID numbers the inferior will
4217 understand. Make sure to only send forms that do not specify
4219 p
= append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4221 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4223 /* Resume all threads (of all processes, or of a single
4224 process), with preference for INFERIOR_PTID. This assumes
4225 inferior_ptid belongs to the set of all threads we are about
4227 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4229 /* Step inferior_ptid, with or without signal. */
4230 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4233 /* And continue others without a signal. */
4234 p
= append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4238 /* Scheduler locking; resume only PTID. */
4239 p
= append_resumption (p
, endp
, ptid
, step
, siggnal
);
4242 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4247 /* In non-stop, the stub replies to vCont with "OK". The stop
4248 reply will be reported asynchronously by means of a `%Stop'
4250 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4251 if (strcmp (rs
->buf
, "OK") != 0)
4252 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4258 /* Tell the remote machine to resume. */
4260 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4262 static int last_sent_step
;
4265 remote_resume (struct target_ops
*ops
,
4266 ptid_t ptid
, int step
, enum target_signal siggnal
)
4268 struct remote_state
*rs
= get_remote_state ();
4271 last_sent_signal
= siggnal
;
4272 last_sent_step
= step
;
4274 /* Update the inferior on signals to silently pass, if they've changed. */
4275 remote_pass_signals ();
4277 /* The vCont packet doesn't need to specify threads via Hc. */
4278 /* No reverse support (yet) for vCont. */
4279 if (execution_direction
!= EXEC_REVERSE
)
4280 if (remote_vcont_resume (ptid
, step
, siggnal
))
4283 /* All other supported resume packets do use Hc, so set the continue
4285 if (ptid_equal (ptid
, minus_one_ptid
))
4286 set_continue_thread (any_thread_ptid
);
4288 set_continue_thread (ptid
);
4291 if (execution_direction
== EXEC_REVERSE
)
4293 /* We don't pass signals to the target in reverse exec mode. */
4294 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4295 warning (" - Can't pass signal %d to target in reverse: ignored.\n",
4299 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4300 error (_("Remote reverse-step not supported."));
4302 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4303 error (_("Remote reverse-continue not supported."));
4305 strcpy (buf
, step
? "bs" : "bc");
4307 else if (siggnal
!= TARGET_SIGNAL_0
)
4309 buf
[0] = step
? 'S' : 'C';
4310 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4311 buf
[2] = tohex (((int) siggnal
) & 0xf);
4315 strcpy (buf
, step
? "s" : "c");
4320 /* We are about to start executing the inferior, let's register it
4321 with the event loop. NOTE: this is the one place where all the
4322 execution commands end up. We could alternatively do this in each
4323 of the execution commands in infcmd.c. */
4324 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4325 into infcmd.c in order to allow inferior function calls to work
4326 NOT asynchronously. */
4327 if (target_can_async_p ())
4328 target_async (inferior_event_handler
, 0);
4330 /* We've just told the target to resume. The remote server will
4331 wait for the inferior to stop, and then send a stop reply. In
4332 the mean time, we can't start another command/query ourselves
4333 because the stub wouldn't be ready to process it. This applies
4334 only to the base all-stop protocol, however. In non-stop (which
4335 only supports vCont), the stub replies with an "OK", and is
4336 immediate able to process further serial input. */
4338 rs
->waiting_for_stop_reply
= 1;
4342 /* Set up the signal handler for SIGINT, while the target is
4343 executing, ovewriting the 'regular' SIGINT signal handler. */
4345 initialize_sigint_signal_handler (void)
4347 signal (SIGINT
, handle_remote_sigint
);
4350 /* Signal handler for SIGINT, while the target is executing. */
4352 handle_remote_sigint (int sig
)
4354 signal (sig
, handle_remote_sigint_twice
);
4355 mark_async_signal_handler_wrapper (sigint_remote_token
);
4358 /* Signal handler for SIGINT, installed after SIGINT has already been
4359 sent once. It will take effect the second time that the user sends
4362 handle_remote_sigint_twice (int sig
)
4364 signal (sig
, handle_remote_sigint
);
4365 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4368 /* Perform the real interruption of the target execution, in response
4371 async_remote_interrupt (gdb_client_data arg
)
4374 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4376 target_stop (inferior_ptid
);
4379 /* Perform interrupt, if the first attempt did not succeed. Just give
4380 up on the target alltogether. */
4382 async_remote_interrupt_twice (gdb_client_data arg
)
4385 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4390 /* Reinstall the usual SIGINT handlers, after the target has
4393 cleanup_sigint_signal_handler (void *dummy
)
4395 signal (SIGINT
, handle_sigint
);
4398 /* Send ^C to target to halt it. Target will respond, and send us a
4400 static void (*ofunc
) (int);
4402 /* The command line interface's stop routine. This function is installed
4403 as a signal handler for SIGINT. The first time a user requests a
4404 stop, we call remote_stop to send a break or ^C. If there is no
4405 response from the target (it didn't stop when the user requested it),
4406 we ask the user if he'd like to detach from the target. */
4408 remote_interrupt (int signo
)
4410 /* If this doesn't work, try more severe steps. */
4411 signal (signo
, remote_interrupt_twice
);
4413 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4416 /* The user typed ^C twice. */
4419 remote_interrupt_twice (int signo
)
4421 signal (signo
, ofunc
);
4422 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4423 signal (signo
, remote_interrupt
);
4426 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4427 thread, all threads of a remote process, or all threads of all
4431 remote_stop_ns (ptid_t ptid
)
4433 struct remote_state
*rs
= get_remote_state ();
4435 char *endp
= rs
->buf
+ get_remote_packet_size ();
4437 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4438 remote_vcont_probe (rs
);
4440 if (!rs
->support_vCont_t
)
4441 error (_("Remote server does not support stopping threads"));
4443 if (ptid_equal (ptid
, minus_one_ptid
)
4444 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4445 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4450 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4452 if (ptid_is_pid (ptid
))
4453 /* All (-1) threads of process. */
4454 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4457 /* Small optimization: if we already have a stop reply for
4458 this thread, no use in telling the stub we want this
4460 if (peek_stop_reply (ptid
))
4466 p
= write_ptid (p
, endp
, nptid
);
4469 /* In non-stop, we get an immediate OK reply. The stop reply will
4470 come in asynchronously by notification. */
4472 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4473 if (strcmp (rs
->buf
, "OK") != 0)
4474 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4477 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4478 remote target. It is undefined which thread of which process
4479 reports the stop. */
4482 remote_stop_as (ptid_t ptid
)
4484 struct remote_state
*rs
= get_remote_state ();
4486 rs
->ctrlc_pending_p
= 1;
4488 /* If the inferior is stopped already, but the core didn't know
4489 about it yet, just ignore the request. The cached wait status
4490 will be collected in remote_wait. */
4491 if (rs
->cached_wait_status
)
4494 /* Send interrupt_sequence to remote target. */
4495 send_interrupt_sequence ();
4498 /* This is the generic stop called via the target vector. When a target
4499 interrupt is requested, either by the command line or the GUI, we
4500 will eventually end up here. */
4503 remote_stop (ptid_t ptid
)
4506 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4509 remote_stop_ns (ptid
);
4511 remote_stop_as (ptid
);
4514 /* Ask the user what to do when an interrupt is received. */
4517 interrupt_query (void)
4519 target_terminal_ours ();
4521 if (target_can_async_p ())
4523 signal (SIGINT
, handle_sigint
);
4524 deprecated_throw_reason (RETURN_QUIT
);
4528 if (query (_("Interrupted while waiting for the program.\n\
4529 Give up (and stop debugging it)? ")))
4532 deprecated_throw_reason (RETURN_QUIT
);
4536 target_terminal_inferior ();
4539 /* Enable/disable target terminal ownership. Most targets can use
4540 terminal groups to control terminal ownership. Remote targets are
4541 different in that explicit transfer of ownership to/from GDB/target
4545 remote_terminal_inferior (void)
4547 if (!target_async_permitted
)
4548 /* Nothing to do. */
4551 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4552 idempotent. The event-loop GDB talking to an asynchronous target
4553 with a synchronous command calls this function from both
4554 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4555 transfer the terminal to the target when it shouldn't this guard
4557 if (!remote_async_terminal_ours_p
)
4559 delete_file_handler (input_fd
);
4560 remote_async_terminal_ours_p
= 0;
4561 initialize_sigint_signal_handler ();
4562 /* NOTE: At this point we could also register our selves as the
4563 recipient of all input. Any characters typed could then be
4564 passed on down to the target. */
4568 remote_terminal_ours (void)
4570 if (!target_async_permitted
)
4571 /* Nothing to do. */
4574 /* See FIXME in remote_terminal_inferior. */
4575 if (remote_async_terminal_ours_p
)
4577 cleanup_sigint_signal_handler (NULL
);
4578 add_file_handler (input_fd
, stdin_event_handler
, 0);
4579 remote_async_terminal_ours_p
= 1;
4583 remote_console_output (char *msg
)
4587 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4590 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4593 fputs_unfiltered (tb
, gdb_stdtarg
);
4595 gdb_flush (gdb_stdtarg
);
4598 typedef struct cached_reg
4601 gdb_byte data
[MAX_REGISTER_SIZE
];
4604 DEF_VEC_O(cached_reg_t
);
4608 struct stop_reply
*next
;
4612 struct target_waitstatus ws
;
4614 VEC(cached_reg_t
) *regcache
;
4616 int stopped_by_watchpoint_p
;
4617 CORE_ADDR watch_data_address
;
4625 /* The list of already fetched and acknowledged stop events. */
4626 static struct stop_reply
*stop_reply_queue
;
4628 static struct stop_reply
*
4629 stop_reply_xmalloc (void)
4631 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4637 stop_reply_xfree (struct stop_reply
*r
)
4641 VEC_free (cached_reg_t
, r
->regcache
);
4646 /* Discard all pending stop replies of inferior PID. If PID is -1,
4647 discard everything. */
4650 discard_pending_stop_replies (int pid
)
4652 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4654 /* Discard the in-flight notification. */
4655 if (pending_stop_reply
!= NULL
4657 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4659 stop_reply_xfree (pending_stop_reply
);
4660 pending_stop_reply
= NULL
;
4663 /* Discard the stop replies we have already pulled with
4665 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4669 || ptid_get_pid (reply
->ptid
) == pid
)
4671 if (reply
== stop_reply_queue
)
4672 stop_reply_queue
= reply
->next
;
4674 prev
->next
= reply
->next
;
4676 stop_reply_xfree (reply
);
4683 /* Cleanup wrapper. */
4686 do_stop_reply_xfree (void *arg
)
4688 struct stop_reply
*r
= arg
;
4689 stop_reply_xfree (r
);
4692 /* Look for a queued stop reply belonging to PTID. If one is found,
4693 remove it from the queue, and return it. Returns NULL if none is
4694 found. If there are still queued events left to process, tell the
4695 event loop to get back to target_wait soon. */
4697 static struct stop_reply
*
4698 queued_stop_reply (ptid_t ptid
)
4700 struct stop_reply
*it
;
4701 struct stop_reply
**it_link
;
4703 it
= stop_reply_queue
;
4704 it_link
= &stop_reply_queue
;
4707 if (ptid_match (it
->ptid
, ptid
))
4709 *it_link
= it
->next
;
4714 it_link
= &it
->next
;
4718 if (stop_reply_queue
)
4719 /* There's still at least an event left. */
4720 mark_async_event_handler (remote_async_inferior_event_token
);
4725 /* Push a fully parsed stop reply in the stop reply queue. Since we
4726 know that we now have at least one queued event left to pass to the
4727 core side, tell the event loop to get back to target_wait soon. */
4730 push_stop_reply (struct stop_reply
*new_event
)
4732 struct stop_reply
*event
;
4734 if (stop_reply_queue
)
4736 for (event
= stop_reply_queue
;
4737 event
&& event
->next
;
4738 event
= event
->next
)
4741 event
->next
= new_event
;
4744 stop_reply_queue
= new_event
;
4746 mark_async_event_handler (remote_async_inferior_event_token
);
4749 /* Returns true if we have a stop reply for PTID. */
4752 peek_stop_reply (ptid_t ptid
)
4754 struct stop_reply
*it
;
4756 for (it
= stop_reply_queue
; it
; it
= it
->next
)
4757 if (ptid_equal (ptid
, it
->ptid
))
4759 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
4766 /* Parse the stop reply in BUF. Either the function succeeds, and the
4767 result is stored in EVENT, or throws an error. */
4770 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
4772 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4776 event
->ptid
= null_ptid
;
4777 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
4778 event
->ws
.value
.integer
= 0;
4779 event
->solibs_changed
= 0;
4780 event
->replay_event
= 0;
4781 event
->stopped_by_watchpoint_p
= 0;
4782 event
->regcache
= NULL
;
4787 case 'T': /* Status with PC, SP, FP, ... */
4788 /* Expedited reply, containing Signal, {regno, reg} repeat. */
4789 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
4791 n... = register number
4792 r... = register contents
4795 p
= &buf
[3]; /* after Txx */
4803 /* If the packet contains a register number, save it in
4804 pnum and set p1 to point to the character following it.
4805 Otherwise p1 points to p. */
4807 /* If this packet is an awatch packet, don't parse the 'a'
4808 as a register number. */
4810 if (strncmp (p
, "awatch", strlen("awatch")) != 0
4811 && strncmp (p
, "core", strlen ("core") != 0))
4813 /* Read the ``P'' register number. */
4814 pnum
= strtol (p
, &p_temp
, 16);
4820 if (p1
== p
) /* No register number present here. */
4822 p1
= strchr (p
, ':');
4824 error (_("Malformed packet(a) (missing colon): %s\n\
4827 if (strncmp (p
, "thread", p1
- p
) == 0)
4828 event
->ptid
= read_ptid (++p1
, &p
);
4829 else if ((strncmp (p
, "watch", p1
- p
) == 0)
4830 || (strncmp (p
, "rwatch", p1
- p
) == 0)
4831 || (strncmp (p
, "awatch", p1
- p
) == 0))
4833 event
->stopped_by_watchpoint_p
= 1;
4834 p
= unpack_varlen_hex (++p1
, &addr
);
4835 event
->watch_data_address
= (CORE_ADDR
) addr
;
4837 else if (strncmp (p
, "library", p1
- p
) == 0)
4841 while (*p_temp
&& *p_temp
!= ';')
4844 event
->solibs_changed
= 1;
4847 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
4849 /* NO_HISTORY event.
4850 p1 will indicate "begin" or "end", but
4851 it makes no difference for now, so ignore it. */
4852 event
->replay_event
= 1;
4853 p_temp
= strchr (p1
+ 1, ';');
4857 else if (strncmp (p
, "core", p1
- p
) == 0)
4860 p
= unpack_varlen_hex (++p1
, &c
);
4865 /* Silently skip unknown optional info. */
4866 p_temp
= strchr (p1
+ 1, ';');
4873 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
4874 cached_reg_t cached_reg
;
4879 error (_("Malformed packet(b) (missing colon): %s\n\
4885 error (_("Remote sent bad register number %s: %s\n\
4887 phex_nz (pnum
, 0), p
, buf
);
4889 cached_reg
.num
= reg
->regnum
;
4891 fieldsize
= hex2bin (p
, cached_reg
.data
,
4892 register_size (target_gdbarch
,
4895 if (fieldsize
< register_size (target_gdbarch
,
4897 warning (_("Remote reply is too short: %s"), buf
);
4899 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
4903 error (_("Remote register badly formatted: %s\nhere: %s"),
4908 case 'S': /* Old style status, just signal only. */
4909 if (event
->solibs_changed
)
4910 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
4911 else if (event
->replay_event
)
4912 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
4915 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4916 event
->ws
.value
.sig
= (enum target_signal
)
4917 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
4920 case 'W': /* Target exited. */
4927 /* GDB used to accept only 2 hex chars here. Stubs should
4928 only send more if they detect GDB supports multi-process
4930 p
= unpack_varlen_hex (&buf
[1], &value
);
4934 /* The remote process exited. */
4935 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
4936 event
->ws
.value
.integer
= value
;
4940 /* The remote process exited with a signal. */
4941 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
4942 event
->ws
.value
.sig
= (enum target_signal
) value
;
4945 /* If no process is specified, assume inferior_ptid. */
4946 pid
= ptid_get_pid (inferior_ptid
);
4955 else if (strncmp (p
,
4956 "process:", sizeof ("process:") - 1) == 0)
4959 p
+= sizeof ("process:") - 1;
4960 unpack_varlen_hex (p
, &upid
);
4964 error (_("unknown stop reply packet: %s"), buf
);
4967 error (_("unknown stop reply packet: %s"), buf
);
4968 event
->ptid
= pid_to_ptid (pid
);
4973 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
4974 error (_("No process or thread specified in stop reply: %s"), buf
);
4977 /* When the stub wants to tell GDB about a new stop reply, it sends a
4978 stop notification (%Stop). Those can come it at any time, hence,
4979 we have to make sure that any pending putpkt/getpkt sequence we're
4980 making is finished, before querying the stub for more events with
4981 vStopped. E.g., if we started a vStopped sequence immediatelly
4982 upon receiving the %Stop notification, something like this could
4990 1.6) <-- (registers reply to step #1.3)
4992 Obviously, the reply in step #1.6 would be unexpected to a vStopped
4995 To solve this, whenever we parse a %Stop notification sucessfully,
4996 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
4997 doing whatever we were doing:
5003 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5004 2.5) <-- (registers reply to step #2.3)
5006 Eventualy after step #2.5, we return to the event loop, which
5007 notices there's an event on the
5008 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5009 associated callback --- the function below. At this point, we're
5010 always safe to start a vStopped sequence. :
5013 2.7) <-- T05 thread:2
5019 remote_get_pending_stop_replies (void)
5021 struct remote_state
*rs
= get_remote_state ();
5023 if (pending_stop_reply
)
5026 putpkt ("vStopped");
5028 /* Now we can rely on it. */
5029 push_stop_reply (pending_stop_reply
);
5030 pending_stop_reply
= NULL
;
5034 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5035 if (strcmp (rs
->buf
, "OK") == 0)
5039 struct cleanup
*old_chain
;
5040 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5042 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5043 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5046 putpkt ("vStopped");
5048 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5050 /* Now we can rely on it. */
5051 discard_cleanups (old_chain
);
5052 push_stop_reply (stop_reply
);
5055 /* We got an unknown stop reply. */
5056 do_cleanups (old_chain
);
5063 /* Called when it is decided that STOP_REPLY holds the info of the
5064 event that is to be returned to the core. This function always
5065 destroys STOP_REPLY. */
5068 process_stop_reply (struct stop_reply
*stop_reply
,
5069 struct target_waitstatus
*status
)
5072 struct thread_info
*info
;
5074 *status
= stop_reply
->ws
;
5075 ptid
= stop_reply
->ptid
;
5077 /* If no thread/process was reported by the stub, assume the current
5079 if (ptid_equal (ptid
, null_ptid
))
5080 ptid
= inferior_ptid
;
5082 if (status
->kind
!= TARGET_WAITKIND_EXITED
5083 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5085 /* Expedited registers. */
5086 if (stop_reply
->regcache
)
5088 struct regcache
*regcache
5089 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5094 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5096 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5097 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5100 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5101 remote_watch_data_address
= stop_reply
->watch_data_address
;
5103 remote_notice_new_inferior (ptid
, 0);
5104 demand_private_info (ptid
)->core
= stop_reply
->core
;
5107 stop_reply_xfree (stop_reply
);
5111 /* The non-stop mode version of target_wait. */
5114 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5116 struct remote_state
*rs
= get_remote_state ();
5117 struct stop_reply
*stop_reply
;
5120 /* If in non-stop mode, get out of getpkt even if a
5121 notification is received. */
5123 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5130 case 'E': /* Error of some sort. */
5131 /* We're out of sync with the target now. Did it continue
5132 or not? We can't tell which thread it was in non-stop,
5133 so just ignore this. */
5134 warning (_("Remote failure reply: %s"), rs
->buf
);
5136 case 'O': /* Console output. */
5137 remote_console_output (rs
->buf
+ 1);
5140 warning (_("Invalid remote reply: %s"), rs
->buf
);
5144 /* Acknowledge a pending stop reply that may have arrived in the
5146 if (pending_stop_reply
!= NULL
)
5147 remote_get_pending_stop_replies ();
5149 /* If indeed we noticed a stop reply, we're done. */
5150 stop_reply
= queued_stop_reply (ptid
);
5151 if (stop_reply
!= NULL
)
5152 return process_stop_reply (stop_reply
, status
);
5154 /* Still no event. If we're just polling for an event, then
5155 return to the event loop. */
5156 if (options
& TARGET_WNOHANG
)
5158 status
->kind
= TARGET_WAITKIND_IGNORE
;
5159 return minus_one_ptid
;
5162 /* Otherwise do a blocking wait. */
5163 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5168 /* Wait until the remote machine stops, then return, storing status in
5169 STATUS just as `wait' would. */
5172 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5174 struct remote_state
*rs
= get_remote_state ();
5175 ptid_t event_ptid
= null_ptid
;
5177 struct stop_reply
*stop_reply
;
5181 status
->kind
= TARGET_WAITKIND_IGNORE
;
5182 status
->value
.integer
= 0;
5184 stop_reply
= queued_stop_reply (ptid
);
5185 if (stop_reply
!= NULL
)
5186 return process_stop_reply (stop_reply
, status
);
5188 if (rs
->cached_wait_status
)
5189 /* Use the cached wait status, but only once. */
5190 rs
->cached_wait_status
= 0;
5195 if (!target_is_async_p ())
5197 ofunc
= signal (SIGINT
, remote_interrupt
);
5198 /* If the user hit C-c before this packet, or between packets,
5199 pretend that it was hit right here. */
5203 remote_interrupt (SIGINT
);
5207 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5208 _never_ wait for ever -> test on target_is_async_p().
5209 However, before we do that we need to ensure that the caller
5210 knows how to take the target into/out of async mode. */
5211 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5212 if (!target_is_async_p ())
5213 signal (SIGINT
, ofunc
);
5218 remote_stopped_by_watchpoint_p
= 0;
5220 /* We got something. */
5221 rs
->waiting_for_stop_reply
= 0;
5223 /* Assume that the target has acknowledged Ctrl-C unless we receive
5224 an 'F' or 'O' packet. */
5225 if (buf
[0] != 'F' && buf
[0] != 'O')
5226 rs
->ctrlc_pending_p
= 0;
5230 case 'E': /* Error of some sort. */
5231 /* We're out of sync with the target now. Did it continue or
5232 not? Not is more likely, so report a stop. */
5233 warning (_("Remote failure reply: %s"), buf
);
5234 status
->kind
= TARGET_WAITKIND_STOPPED
;
5235 status
->value
.sig
= TARGET_SIGNAL_0
;
5237 case 'F': /* File-I/O request. */
5238 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5239 rs
->ctrlc_pending_p
= 0;
5241 case 'T': case 'S': case 'X': case 'W':
5243 struct stop_reply
*stop_reply
;
5244 struct cleanup
*old_chain
;
5246 stop_reply
= stop_reply_xmalloc ();
5247 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5248 remote_parse_stop_reply (buf
, stop_reply
);
5249 discard_cleanups (old_chain
);
5250 event_ptid
= process_stop_reply (stop_reply
, status
);
5253 case 'O': /* Console output. */
5254 remote_console_output (buf
+ 1);
5256 /* The target didn't really stop; keep waiting. */
5257 rs
->waiting_for_stop_reply
= 1;
5261 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5263 /* Zero length reply means that we tried 'S' or 'C' and the
5264 remote system doesn't support it. */
5265 target_terminal_ours_for_output ();
5267 ("Can't send signals to this remote system. %s not sent.\n",
5268 target_signal_to_name (last_sent_signal
));
5269 last_sent_signal
= TARGET_SIGNAL_0
;
5270 target_terminal_inferior ();
5272 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5273 putpkt ((char *) buf
);
5275 /* We just told the target to resume, so a stop reply is in
5277 rs
->waiting_for_stop_reply
= 1;
5280 /* else fallthrough */
5282 warning (_("Invalid remote reply: %s"), buf
);
5284 rs
->waiting_for_stop_reply
= 1;
5288 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5290 /* Nothing interesting happened. If we're doing a non-blocking
5291 poll, we're done. Otherwise, go back to waiting. */
5292 if (options
& TARGET_WNOHANG
)
5293 return minus_one_ptid
;
5297 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5298 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5300 if (!ptid_equal (event_ptid
, null_ptid
))
5301 record_currthread (event_ptid
);
5303 event_ptid
= inferior_ptid
;
5306 /* A process exit. Invalidate our notion of current thread. */
5307 record_currthread (minus_one_ptid
);
5312 /* Wait until the remote machine stops, then return, storing status in
5313 STATUS just as `wait' would. */
5316 remote_wait (struct target_ops
*ops
,
5317 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5322 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5324 event_ptid
= remote_wait_as (ptid
, status
, options
);
5326 if (target_can_async_p ())
5328 /* If there are are events left in the queue tell the event loop
5330 if (stop_reply_queue
)
5331 mark_async_event_handler (remote_async_inferior_event_token
);
5337 /* Fetch a single register using a 'p' packet. */
5340 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5342 struct remote_state
*rs
= get_remote_state ();
5344 char regp
[MAX_REGISTER_SIZE
];
5347 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5350 if (reg
->pnum
== -1)
5355 p
+= hexnumstr (p
, reg
->pnum
);
5358 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5362 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5366 case PACKET_UNKNOWN
:
5369 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5370 gdbarch_register_name (get_regcache_arch (regcache
),
5375 /* If this register is unfetchable, tell the regcache. */
5378 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5382 /* Otherwise, parse and supply the value. */
5388 error (_("fetch_register_using_p: early buf termination"));
5390 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5393 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5397 /* Fetch the registers included in the target's 'g' packet. */
5400 send_g_packet (void)
5402 struct remote_state
*rs
= get_remote_state ();
5405 sprintf (rs
->buf
, "g");
5406 remote_send (&rs
->buf
, &rs
->buf_size
);
5408 /* We can get out of synch in various cases. If the first character
5409 in the buffer is not a hex character, assume that has happened
5410 and try to fetch another packet to read. */
5411 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5412 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5413 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5414 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5417 fprintf_unfiltered (gdb_stdlog
,
5418 "Bad register packet; fetching a new packet\n");
5419 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5422 buf_len
= strlen (rs
->buf
);
5424 /* Sanity check the received packet. */
5425 if (buf_len
% 2 != 0)
5426 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5432 process_g_packet (struct regcache
*regcache
)
5434 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5435 struct remote_state
*rs
= get_remote_state ();
5436 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5441 buf_len
= strlen (rs
->buf
);
5443 /* Further sanity checks, with knowledge of the architecture. */
5444 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5445 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5447 /* Save the size of the packet sent to us by the target. It is used
5448 as a heuristic when determining the max size of packets that the
5449 target can safely receive. */
5450 if (rsa
->actual_register_packet_size
== 0)
5451 rsa
->actual_register_packet_size
= buf_len
;
5453 /* If this is smaller than we guessed the 'g' packet would be,
5454 update our records. A 'g' reply that doesn't include a register's
5455 value implies either that the register is not available, or that
5456 the 'p' packet must be used. */
5457 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5459 rsa
->sizeof_g_packet
= buf_len
/ 2;
5461 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5463 if (rsa
->regs
[i
].pnum
== -1)
5466 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5467 rsa
->regs
[i
].in_g_packet
= 0;
5469 rsa
->regs
[i
].in_g_packet
= 1;
5473 regs
= alloca (rsa
->sizeof_g_packet
);
5475 /* Unimplemented registers read as all bits zero. */
5476 memset (regs
, 0, rsa
->sizeof_g_packet
);
5478 /* Reply describes registers byte by byte, each byte encoded as two
5479 hex characters. Suck them all up, then supply them to the
5480 register cacheing/storage mechanism. */
5483 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5485 if (p
[0] == 0 || p
[1] == 0)
5486 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5487 internal_error (__FILE__
, __LINE__
,
5488 "unexpected end of 'g' packet reply");
5490 if (p
[0] == 'x' && p
[1] == 'x')
5491 regs
[i
] = 0; /* 'x' */
5493 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5499 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5501 struct packet_reg
*r
= &rsa
->regs
[i
];
5504 if (r
->offset
* 2 >= strlen (rs
->buf
))
5505 /* This shouldn't happen - we adjusted in_g_packet above. */
5506 internal_error (__FILE__
, __LINE__
,
5507 "unexpected end of 'g' packet reply");
5508 else if (rs
->buf
[r
->offset
* 2] == 'x')
5510 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5511 /* The register isn't available, mark it as such (at
5512 the same time setting the value to zero). */
5513 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5516 regcache_raw_supply (regcache
, r
->regnum
,
5524 fetch_registers_using_g (struct regcache
*regcache
)
5527 process_g_packet (regcache
);
5531 remote_fetch_registers (struct target_ops
*ops
,
5532 struct regcache
*regcache
, int regnum
)
5534 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5537 set_general_thread (inferior_ptid
);
5541 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5542 gdb_assert (reg
!= NULL
);
5544 /* If this register might be in the 'g' packet, try that first -
5545 we are likely to read more than one register. If this is the
5546 first 'g' packet, we might be overly optimistic about its
5547 contents, so fall back to 'p'. */
5548 if (reg
->in_g_packet
)
5550 fetch_registers_using_g (regcache
);
5551 if (reg
->in_g_packet
)
5555 if (fetch_register_using_p (regcache
, reg
))
5558 /* This register is not available. */
5559 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5564 fetch_registers_using_g (regcache
);
5566 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5567 if (!rsa
->regs
[i
].in_g_packet
)
5568 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5570 /* This register is not available. */
5571 regcache_raw_supply (regcache
, i
, NULL
);
5575 /* Prepare to store registers. Since we may send them all (using a
5576 'G' request), we have to read out the ones we don't want to change
5580 remote_prepare_to_store (struct regcache
*regcache
)
5582 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5584 gdb_byte buf
[MAX_REGISTER_SIZE
];
5586 /* Make sure the entire registers array is valid. */
5587 switch (remote_protocol_packets
[PACKET_P
].support
)
5589 case PACKET_DISABLE
:
5590 case PACKET_SUPPORT_UNKNOWN
:
5591 /* Make sure all the necessary registers are cached. */
5592 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5593 if (rsa
->regs
[i
].in_g_packet
)
5594 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5601 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5602 packet was not recognized. */
5605 store_register_using_P (const struct regcache
*regcache
,
5606 struct packet_reg
*reg
)
5608 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5609 struct remote_state
*rs
= get_remote_state ();
5610 /* Try storing a single register. */
5611 char *buf
= rs
->buf
;
5612 gdb_byte regp
[MAX_REGISTER_SIZE
];
5615 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5618 if (reg
->pnum
== -1)
5621 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5622 p
= buf
+ strlen (buf
);
5623 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5624 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5626 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5628 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5633 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5634 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5635 case PACKET_UNKNOWN
:
5638 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5642 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5643 contents of the register cache buffer. FIXME: ignores errors. */
5646 store_registers_using_G (const struct regcache
*regcache
)
5648 struct remote_state
*rs
= get_remote_state ();
5649 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5653 /* Extract all the registers in the regcache copying them into a
5657 regs
= alloca (rsa
->sizeof_g_packet
);
5658 memset (regs
, 0, rsa
->sizeof_g_packet
);
5659 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5661 struct packet_reg
*r
= &rsa
->regs
[i
];
5663 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5667 /* Command describes registers byte by byte,
5668 each byte encoded as two hex characters. */
5671 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5673 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5675 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5676 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5677 error (_("Could not write registers; remote failure reply '%s'"),
5681 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
5682 of the register cache buffer. FIXME: ignores errors. */
5685 remote_store_registers (struct target_ops
*ops
,
5686 struct regcache
*regcache
, int regnum
)
5688 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5691 set_general_thread (inferior_ptid
);
5695 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5696 gdb_assert (reg
!= NULL
);
5698 /* Always prefer to store registers using the 'P' packet if
5699 possible; we often change only a small number of registers.
5700 Sometimes we change a larger number; we'd need help from a
5701 higher layer to know to use 'G'. */
5702 if (store_register_using_P (regcache
, reg
))
5705 /* For now, don't complain if we have no way to write the
5706 register. GDB loses track of unavailable registers too
5707 easily. Some day, this may be an error. We don't have
5708 any way to read the register, either... */
5709 if (!reg
->in_g_packet
)
5712 store_registers_using_G (regcache
);
5716 store_registers_using_G (regcache
);
5718 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5719 if (!rsa
->regs
[i
].in_g_packet
)
5720 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
5721 /* See above for why we do not issue an error here. */
5726 /* Return the number of hex digits in num. */
5729 hexnumlen (ULONGEST num
)
5733 for (i
= 0; num
!= 0; i
++)
5739 /* Set BUF to the minimum number of hex digits representing NUM. */
5742 hexnumstr (char *buf
, ULONGEST num
)
5744 int len
= hexnumlen (num
);
5745 return hexnumnstr (buf
, num
, len
);
5749 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
5752 hexnumnstr (char *buf
, ULONGEST num
, int width
)
5758 for (i
= width
- 1; i
>= 0; i
--)
5760 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
5767 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
5770 remote_address_masked (CORE_ADDR addr
)
5772 int address_size
= remote_address_size
;
5773 /* If "remoteaddresssize" was not set, default to target address size. */
5775 address_size
= gdbarch_addr_bit (target_gdbarch
);
5777 if (address_size
> 0
5778 && address_size
< (sizeof (ULONGEST
) * 8))
5780 /* Only create a mask when that mask can safely be constructed
5781 in a ULONGEST variable. */
5783 mask
= (mask
<< address_size
) - 1;
5789 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
5790 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
5791 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
5792 (which may be more than *OUT_LEN due to escape characters). The
5793 total number of bytes in the output buffer will be at most
5797 remote_escape_output (const gdb_byte
*buffer
, int len
,
5798 gdb_byte
*out_buf
, int *out_len
,
5801 int input_index
, output_index
;
5804 for (input_index
= 0; input_index
< len
; input_index
++)
5806 gdb_byte b
= buffer
[input_index
];
5808 if (b
== '$' || b
== '#' || b
== '}')
5810 /* These must be escaped. */
5811 if (output_index
+ 2 > out_maxlen
)
5813 out_buf
[output_index
++] = '}';
5814 out_buf
[output_index
++] = b
^ 0x20;
5818 if (output_index
+ 1 > out_maxlen
)
5820 out_buf
[output_index
++] = b
;
5824 *out_len
= input_index
;
5825 return output_index
;
5828 /* Convert BUFFER, escaped data LEN bytes long, into binary data
5829 in OUT_BUF. Return the number of bytes written to OUT_BUF.
5830 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
5832 This function reverses remote_escape_output. It allows more
5833 escaped characters than that function does, in particular because
5834 '*' must be escaped to avoid the run-length encoding processing
5835 in reading packets. */
5838 remote_unescape_input (const gdb_byte
*buffer
, int len
,
5839 gdb_byte
*out_buf
, int out_maxlen
)
5841 int input_index
, output_index
;
5846 for (input_index
= 0; input_index
< len
; input_index
++)
5848 gdb_byte b
= buffer
[input_index
];
5850 if (output_index
+ 1 > out_maxlen
)
5852 warning (_("Received too much data from remote target;"
5853 " ignoring overflow."));
5854 return output_index
;
5859 out_buf
[output_index
++] = b
^ 0x20;
5865 out_buf
[output_index
++] = b
;
5869 error (_("Unmatched escape character in target response."));
5871 return output_index
;
5874 /* Determine whether the remote target supports binary downloading.
5875 This is accomplished by sending a no-op memory write of zero length
5876 to the target at the specified address. It does not suffice to send
5877 the whole packet, since many stubs strip the eighth bit and
5878 subsequently compute a wrong checksum, which causes real havoc with
5881 NOTE: This can still lose if the serial line is not eight-bit
5882 clean. In cases like this, the user should clear "remote
5886 check_binary_download (CORE_ADDR addr
)
5888 struct remote_state
*rs
= get_remote_state ();
5890 switch (remote_protocol_packets
[PACKET_X
].support
)
5892 case PACKET_DISABLE
:
5896 case PACKET_SUPPORT_UNKNOWN
:
5902 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5904 p
+= hexnumstr (p
, (ULONGEST
) 0);
5908 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5909 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5911 if (rs
->buf
[0] == '\0')
5914 fprintf_unfiltered (gdb_stdlog
,
5915 "binary downloading NOT suppported by target\n");
5916 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
5921 fprintf_unfiltered (gdb_stdlog
,
5922 "binary downloading suppported by target\n");
5923 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
5930 /* Write memory data directly to the remote machine.
5931 This does not inform the data cache; the data cache uses this.
5932 HEADER is the starting part of the packet.
5933 MEMADDR is the address in the remote memory space.
5934 MYADDR is the address of the buffer in our space.
5935 LEN is the number of bytes.
5936 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
5937 should send data as binary ('X'), or hex-encoded ('M').
5939 The function creates packet of the form
5940 <HEADER><ADDRESS>,<LENGTH>:<DATA>
5942 where encoding of <DATA> is termined by PACKET_FORMAT.
5944 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
5947 Returns the number of bytes transferred, or 0 (setting errno) for
5948 error. Only transfer a single packet. */
5951 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
5952 const gdb_byte
*myaddr
, int len
,
5953 char packet_format
, int use_length
)
5955 struct remote_state
*rs
= get_remote_state ();
5965 if (packet_format
!= 'X' && packet_format
!= 'M')
5966 internal_error (__FILE__
, __LINE__
,
5967 "remote_write_bytes_aux: bad packet format");
5972 payload_size
= get_memory_write_packet_size ();
5974 /* The packet buffer will be large enough for the payload;
5975 get_memory_packet_size ensures this. */
5978 /* Compute the size of the actual payload by subtracting out the
5979 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
5981 payload_size
-= strlen ("$,:#NN");
5983 /* The comma won't be used. */
5985 header_length
= strlen (header
);
5986 payload_size
-= header_length
;
5987 payload_size
-= hexnumlen (memaddr
);
5989 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
5991 strcat (rs
->buf
, header
);
5992 p
= rs
->buf
+ strlen (header
);
5994 /* Compute a best guess of the number of bytes actually transfered. */
5995 if (packet_format
== 'X')
5997 /* Best guess at number of bytes that will fit. */
5998 todo
= min (len
, payload_size
);
6000 payload_size
-= hexnumlen (todo
);
6001 todo
= min (todo
, payload_size
);
6005 /* Num bytes that will fit. */
6006 todo
= min (len
, payload_size
/ 2);
6008 payload_size
-= hexnumlen (todo
);
6009 todo
= min (todo
, payload_size
/ 2);
6013 internal_error (__FILE__
, __LINE__
,
6014 _("minumum packet size too small to write data"));
6016 /* If we already need another packet, then try to align the end
6017 of this packet to a useful boundary. */
6018 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6019 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6021 /* Append "<memaddr>". */
6022 memaddr
= remote_address_masked (memaddr
);
6023 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6030 /* Append <len>. Retain the location/size of <len>. It may need to
6031 be adjusted once the packet body has been created. */
6033 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6041 /* Append the packet body. */
6042 if (packet_format
== 'X')
6044 /* Binary mode. Send target system values byte by byte, in
6045 increasing byte addresses. Only escape certain critical
6047 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6050 /* If not all TODO bytes fit, then we'll need another packet. Make
6051 a second try to keep the end of the packet aligned. Don't do
6052 this if the packet is tiny. */
6053 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6057 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6059 if (new_nr_bytes
!= nr_bytes
)
6060 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6065 p
+= payload_length
;
6066 if (use_length
&& nr_bytes
< todo
)
6068 /* Escape chars have filled up the buffer prematurely,
6069 and we have actually sent fewer bytes than planned.
6070 Fix-up the length field of the packet. Use the same
6071 number of characters as before. */
6072 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6073 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6078 /* Normal mode: Send target system values byte by byte, in
6079 increasing byte addresses. Each byte is encoded as a two hex
6081 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6085 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6086 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6088 if (rs
->buf
[0] == 'E')
6090 /* There is no correspondance between what the remote protocol
6091 uses for errors and errno codes. We would like a cleaner way
6092 of representing errors (big enough to include errno codes,
6093 bfd_error codes, and others). But for now just return EIO. */
6098 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6099 fewer bytes than we'd planned. */
6103 /* Write memory data directly to the remote machine.
6104 This does not inform the data cache; the data cache uses this.
6105 MEMADDR is the address in the remote memory space.
6106 MYADDR is the address of the buffer in our space.
6107 LEN is the number of bytes.
6109 Returns number of bytes transferred, or 0 (setting errno) for
6110 error. Only transfer a single packet. */
6113 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6115 char *packet_format
= 0;
6117 /* Check whether the target supports binary download. */
6118 check_binary_download (memaddr
);
6120 switch (remote_protocol_packets
[PACKET_X
].support
)
6123 packet_format
= "X";
6125 case PACKET_DISABLE
:
6126 packet_format
= "M";
6128 case PACKET_SUPPORT_UNKNOWN
:
6129 internal_error (__FILE__
, __LINE__
,
6130 _("remote_write_bytes: bad internal state"));
6132 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6135 return remote_write_bytes_aux (packet_format
,
6136 memaddr
, myaddr
, len
, packet_format
[0], 1);
6139 /* Read memory data directly from the remote machine.
6140 This does not use the data cache; the data cache uses this.
6141 MEMADDR is the address in the remote memory space.
6142 MYADDR is the address of the buffer in our space.
6143 LEN is the number of bytes.
6145 Returns number of bytes transferred, or 0 for error. */
6147 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
6148 remote targets) shouldn't attempt to read the entire buffer.
6149 Instead it should read a single packet worth of data and then
6150 return the byte size of that packet to the caller. The caller (its
6151 caller and its callers caller ;-) already contains code for
6152 handling partial reads. */
6155 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6157 struct remote_state
*rs
= get_remote_state ();
6158 int max_buf_size
; /* Max size of packet output buffer. */
6164 max_buf_size
= get_memory_read_packet_size ();
6165 /* The packet buffer will be large enough for the payload;
6166 get_memory_packet_size ensures this. */
6175 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
6177 /* construct "m"<memaddr>","<len>" */
6178 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
6179 memaddr
= remote_address_masked (memaddr
);
6182 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6184 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6188 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6190 if (rs
->buf
[0] == 'E'
6191 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6192 && rs
->buf
[3] == '\0')
6194 /* There is no correspondance between what the remote
6195 protocol uses for errors and errno codes. We would like
6196 a cleaner way of representing errors (big enough to
6197 include errno codes, bfd_error codes, and others). But
6198 for now just return EIO. */
6203 /* Reply describes memory byte by byte,
6204 each byte encoded as two hex characters. */
6207 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
6209 /* Reply is short. This means that we were able to read
6210 only part of what we wanted to. */
6211 return i
+ (origlen
- len
);
6221 /* Remote notification handler. */
6224 handle_notification (char *buf
, size_t length
)
6226 if (strncmp (buf
, "Stop:", 5) == 0)
6228 if (pending_stop_reply
)
6230 /* We've already parsed the in-flight stop-reply, but the
6231 stub for some reason thought we didn't, possibly due to
6232 timeout on its side. Just ignore it. */
6234 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6238 struct cleanup
*old_chain
;
6239 struct stop_reply
*reply
= stop_reply_xmalloc ();
6240 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6242 remote_parse_stop_reply (buf
+ 5, reply
);
6244 discard_cleanups (old_chain
);
6246 /* Be careful to only set it after parsing, since an error
6247 may be thrown then. */
6248 pending_stop_reply
= reply
;
6250 /* Notify the event loop there's a stop reply to acknowledge
6251 and that there may be more events to fetch. */
6252 mark_async_event_handler (remote_async_get_pending_events_token
);
6255 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6259 /* We ignore notifications we don't recognize, for compatibility
6260 with newer stubs. */
6265 /* Read or write LEN bytes from inferior memory at MEMADDR,
6266 transferring to or from debugger address BUFFER. Write to inferior
6267 if SHOULD_WRITE is nonzero. Returns length of data written or
6268 read; 0 for error. TARGET is unused. */
6271 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6272 int should_write
, struct mem_attrib
*attrib
,
6273 struct target_ops
*target
)
6277 set_general_thread (inferior_ptid
);
6280 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6282 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6287 /* Sends a packet with content determined by the printf format string
6288 FORMAT and the remaining arguments, then gets the reply. Returns
6289 whether the packet was a success, a failure, or unknown. */
6291 static enum packet_result
6292 remote_send_printf (const char *format
, ...)
6294 struct remote_state
*rs
= get_remote_state ();
6295 int max_size
= get_remote_packet_size ();
6298 va_start (ap
, format
);
6301 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6302 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
6304 if (putpkt (rs
->buf
) < 0)
6305 error (_("Communication problem with target."));
6308 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6310 return packet_check_result (rs
->buf
);
6314 restore_remote_timeout (void *p
)
6316 int value
= *(int *)p
;
6317 remote_timeout
= value
;
6320 /* Flash writing can take quite some time. We'll set
6321 effectively infinite timeout for flash operations.
6322 In future, we'll need to decide on a better approach. */
6323 static const int remote_flash_timeout
= 1000;
6326 remote_flash_erase (struct target_ops
*ops
,
6327 ULONGEST address
, LONGEST length
)
6329 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6330 int saved_remote_timeout
= remote_timeout
;
6331 enum packet_result ret
;
6333 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6334 &saved_remote_timeout
);
6335 remote_timeout
= remote_flash_timeout
;
6337 ret
= remote_send_printf ("vFlashErase:%s,%s",
6338 phex (address
, addr_size
),
6342 case PACKET_UNKNOWN
:
6343 error (_("Remote target does not support flash erase"));
6345 error (_("Error erasing flash with vFlashErase packet"));
6350 do_cleanups (back_to
);
6354 remote_flash_write (struct target_ops
*ops
,
6355 ULONGEST address
, LONGEST length
,
6356 const gdb_byte
*data
)
6358 int saved_remote_timeout
= remote_timeout
;
6360 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6361 &saved_remote_timeout
);
6363 remote_timeout
= remote_flash_timeout
;
6364 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6365 do_cleanups (back_to
);
6371 remote_flash_done (struct target_ops
*ops
)
6373 int saved_remote_timeout
= remote_timeout
;
6375 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6376 &saved_remote_timeout
);
6378 remote_timeout
= remote_flash_timeout
;
6379 ret
= remote_send_printf ("vFlashDone");
6380 do_cleanups (back_to
);
6384 case PACKET_UNKNOWN
:
6385 error (_("Remote target does not support vFlashDone"));
6387 error (_("Error finishing flash operation"));
6394 remote_files_info (struct target_ops
*ignore
)
6396 puts_filtered ("Debugging a target over a serial line.\n");
6399 /* Stuff for dealing with the packets which are part of this protocol.
6400 See comment at top of file for details. */
6402 /* Read a single character from the remote end. */
6405 readchar (int timeout
)
6409 ch
= serial_readchar (remote_desc
, timeout
);
6414 switch ((enum serial_rc
) ch
)
6418 error (_("Remote connection closed"));
6421 perror_with_name (_("Remote communication error"));
6423 case SERIAL_TIMEOUT
:
6429 /* Send the command in *BUF to the remote machine, and read the reply
6430 into *BUF. Report an error if we get an error reply. Resize
6431 *BUF using xrealloc if necessary to hold the result, and update
6435 remote_send (char **buf
,
6439 getpkt (buf
, sizeof_buf
, 0);
6441 if ((*buf
)[0] == 'E')
6442 error (_("Remote failure reply: %s"), *buf
);
6445 /* Return a pointer to an xmalloc'ed string representing an escaped
6446 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6447 etc. The caller is responsible for releasing the returned
6451 escape_buffer (const char *buf
, int n
)
6453 struct cleanup
*old_chain
;
6454 struct ui_file
*stb
;
6457 stb
= mem_fileopen ();
6458 old_chain
= make_cleanup_ui_file_delete (stb
);
6460 fputstrn_unfiltered (buf
, n
, 0, stb
);
6461 str
= ui_file_xstrdup (stb
, NULL
);
6462 do_cleanups (old_chain
);
6466 /* Display a null-terminated packet on stdout, for debugging, using C
6470 print_packet (char *buf
)
6472 puts_filtered ("\"");
6473 fputstr_filtered (buf
, '"', gdb_stdout
);
6474 puts_filtered ("\"");
6480 return putpkt_binary (buf
, strlen (buf
));
6483 /* Send a packet to the remote machine, with error checking. The data
6484 of the packet is in BUF. The string in BUF can be at most
6485 get_remote_packet_size () - 5 to account for the $, # and checksum,
6486 and for a possible /0 if we are debugging (remote_debug) and want
6487 to print the sent packet as a string. */
6490 putpkt_binary (char *buf
, int cnt
)
6492 struct remote_state
*rs
= get_remote_state ();
6494 unsigned char csum
= 0;
6495 char *buf2
= alloca (cnt
+ 6);
6501 /* Catch cases like trying to read memory or listing threads while
6502 we're waiting for a stop reply. The remote server wouldn't be
6503 ready to handle this request, so we'd hang and timeout. We don't
6504 have to worry about this in synchronous mode, because in that
6505 case it's not possible to issue a command while the target is
6506 running. This is not a problem in non-stop mode, because in that
6507 case, the stub is always ready to process serial input. */
6508 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6509 error (_("Cannot execute this command while the target is running."));
6511 /* We're sending out a new packet. Make sure we don't look at a
6512 stale cached response. */
6513 rs
->cached_wait_status
= 0;
6515 /* Copy the packet into buffer BUF2, encapsulating it
6516 and giving it a checksum. */
6521 for (i
= 0; i
< cnt
; i
++)
6527 *p
++ = tohex ((csum
>> 4) & 0xf);
6528 *p
++ = tohex (csum
& 0xf);
6530 /* Send it over and over until we get a positive ack. */
6534 int started_error_output
= 0;
6538 struct cleanup
*old_chain
;
6542 str
= escape_buffer (buf2
, p
- buf2
);
6543 old_chain
= make_cleanup (xfree
, str
);
6544 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6545 gdb_flush (gdb_stdlog
);
6546 do_cleanups (old_chain
);
6548 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6549 perror_with_name (_("putpkt: write failed"));
6551 /* If this is a no acks version of the remote protocol, send the
6552 packet and move on. */
6556 /* Read until either a timeout occurs (-2) or '+' is read.
6557 Handle any notification that arrives in the mean time. */
6560 ch
= readchar (remote_timeout
);
6568 case SERIAL_TIMEOUT
:
6571 if (started_error_output
)
6573 putchar_unfiltered ('\n');
6574 started_error_output
= 0;
6583 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6587 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6588 case SERIAL_TIMEOUT
:
6592 break; /* Retransmit buffer. */
6596 fprintf_unfiltered (gdb_stdlog
,
6597 "Packet instead of Ack, ignoring it\n");
6598 /* It's probably an old response sent because an ACK
6599 was lost. Gobble up the packet and ack it so it
6600 doesn't get retransmitted when we resend this
6603 serial_write (remote_desc
, "+", 1);
6604 continue; /* Now, go look for +. */
6611 /* If we got a notification, handle it, and go back to looking
6613 /* We've found the start of a notification. Now
6614 collect the data. */
6615 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6620 struct cleanup
*old_chain
;
6623 str
= escape_buffer (rs
->buf
, val
);
6624 old_chain
= make_cleanup (xfree
, str
);
6625 fprintf_unfiltered (gdb_stdlog
,
6626 " Notification received: %s\n",
6628 do_cleanups (old_chain
);
6630 handle_notification (rs
->buf
, val
);
6631 /* We're in sync now, rewait for the ack. */
6638 if (!started_error_output
)
6640 started_error_output
= 1;
6641 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6643 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6644 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6653 if (!started_error_output
)
6655 started_error_output
= 1;
6656 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6658 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6662 break; /* Here to retransmit. */
6666 /* This is wrong. If doing a long backtrace, the user should be
6667 able to get out next time we call QUIT, without anything as
6668 violent as interrupt_query. If we want to provide a way out of
6669 here without getting to the next QUIT, it should be based on
6670 hitting ^C twice as in remote_wait. */
6681 /* Come here after finding the start of a frame when we expected an
6682 ack. Do our best to discard the rest of this packet. */
6691 c
= readchar (remote_timeout
);
6694 case SERIAL_TIMEOUT
:
6695 /* Nothing we can do. */
6698 /* Discard the two bytes of checksum and stop. */
6699 c
= readchar (remote_timeout
);
6701 c
= readchar (remote_timeout
);
6704 case '*': /* Run length encoding. */
6705 /* Discard the repeat count. */
6706 c
= readchar (remote_timeout
);
6711 /* A regular character. */
6717 /* Come here after finding the start of the frame. Collect the rest
6718 into *BUF, verifying the checksum, length, and handling run-length
6719 compression. NUL terminate the buffer. If there is not enough room,
6720 expand *BUF using xrealloc.
6722 Returns -1 on error, number of characters in buffer (ignoring the
6723 trailing NULL) on success. (could be extended to return one of the
6724 SERIAL status indications). */
6727 read_frame (char **buf_p
,
6734 struct remote_state
*rs
= get_remote_state ();
6741 c
= readchar (remote_timeout
);
6744 case SERIAL_TIMEOUT
:
6746 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
6750 fputs_filtered ("Saw new packet start in middle of old one\n",
6752 return -1; /* Start a new packet, count retries. */
6755 unsigned char pktcsum
;
6761 check_0
= readchar (remote_timeout
);
6763 check_1
= readchar (remote_timeout
);
6765 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
6768 fputs_filtered ("Timeout in checksum, retrying\n",
6772 else if (check_0
< 0 || check_1
< 0)
6775 fputs_filtered ("Communication error in checksum\n",
6780 /* Don't recompute the checksum; with no ack packets we
6781 don't have any way to indicate a packet retransmission
6786 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
6787 if (csum
== pktcsum
)
6792 struct cleanup
*old_chain
;
6795 str
= escape_buffer (buf
, bc
);
6796 old_chain
= make_cleanup (xfree
, str
);
6797 fprintf_unfiltered (gdb_stdlog
,
6799 Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
6800 pktcsum
, csum
, str
);
6801 do_cleanups (old_chain
);
6803 /* Number of characters in buffer ignoring trailing
6807 case '*': /* Run length encoding. */
6812 c
= readchar (remote_timeout
);
6814 repeat
= c
- ' ' + 3; /* Compute repeat count. */
6816 /* The character before ``*'' is repeated. */
6818 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
6820 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
6822 /* Make some more room in the buffer. */
6823 *sizeof_buf
+= repeat
;
6824 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6828 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
6834 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
6838 if (bc
>= *sizeof_buf
- 1)
6840 /* Make some more room in the buffer. */
6842 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6853 /* Read a packet from the remote machine, with error checking, and
6854 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6855 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6856 rather than timing out; this is used (in synchronous mode) to wait
6857 for a target that is is executing user code to stop. */
6858 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
6859 don't have to change all the calls to getpkt to deal with the
6860 return value, because at the moment I don't know what the right
6861 thing to do it for those. */
6869 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
6873 /* Read a packet from the remote machine, with error checking, and
6874 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6875 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6876 rather than timing out; this is used (in synchronous mode) to wait
6877 for a target that is is executing user code to stop. If FOREVER ==
6878 0, this function is allowed to time out gracefully and return an
6879 indication of this to the caller. Otherwise return the number of
6880 bytes read. If EXPECTING_NOTIF, consider receiving a notification
6881 enough reason to return to the caller. */
6884 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
6885 int expecting_notif
)
6887 struct remote_state
*rs
= get_remote_state ();
6893 /* We're reading a new response. Make sure we don't look at a
6894 previously cached response. */
6895 rs
->cached_wait_status
= 0;
6897 strcpy (*buf
, "timeout");
6900 timeout
= watchdog
> 0 ? watchdog
: -1;
6901 else if (expecting_notif
)
6902 timeout
= 0; /* There should already be a char in the buffer. If
6905 timeout
= remote_timeout
;
6909 /* Process any number of notifications, and then return when
6913 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
6915 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
6917 /* This can loop forever if the remote side sends us
6918 characters continuously, but if it pauses, we'll get
6919 SERIAL_TIMEOUT from readchar because of timeout. Then
6920 we'll count that as a retry.
6922 Note that even when forever is set, we will only wait
6923 forever prior to the start of a packet. After that, we
6924 expect characters to arrive at a brisk pace. They should
6925 show up within remote_timeout intervals. */
6927 c
= readchar (timeout
);
6928 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
6930 if (c
== SERIAL_TIMEOUT
)
6932 if (expecting_notif
)
6933 return -1; /* Don't complain, it's normal to not get
6934 anything in this case. */
6936 if (forever
) /* Watchdog went off? Kill the target. */
6940 error (_("Watchdog timeout has expired. Target detached."));
6943 fputs_filtered ("Timed out.\n", gdb_stdlog
);
6947 /* We've found the start of a packet or notification.
6948 Now collect the data. */
6949 val
= read_frame (buf
, sizeof_buf
);
6954 serial_write (remote_desc
, "-", 1);
6957 if (tries
> MAX_TRIES
)
6959 /* We have tried hard enough, and just can't receive the
6960 packet/notification. Give up. */
6961 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
6963 /* Skip the ack char if we're in no-ack mode. */
6964 if (!rs
->noack_mode
)
6965 serial_write (remote_desc
, "+", 1);
6969 /* If we got an ordinary packet, return that to our caller. */
6974 struct cleanup
*old_chain
;
6977 str
= escape_buffer (*buf
, val
);
6978 old_chain
= make_cleanup (xfree
, str
);
6979 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
6980 do_cleanups (old_chain
);
6983 /* Skip the ack char if we're in no-ack mode. */
6984 if (!rs
->noack_mode
)
6985 serial_write (remote_desc
, "+", 1);
6989 /* If we got a notification, handle it, and go back to looking
6993 gdb_assert (c
== '%');
6997 struct cleanup
*old_chain
;
7000 str
= escape_buffer (*buf
, val
);
7001 old_chain
= make_cleanup (xfree
, str
);
7002 fprintf_unfiltered (gdb_stdlog
,
7003 " Notification received: %s\n",
7005 do_cleanups (old_chain
);
7008 handle_notification (*buf
, val
);
7010 /* Notifications require no acknowledgement. */
7012 if (expecting_notif
)
7019 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7021 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7025 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7027 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7032 remote_kill (struct target_ops
*ops
)
7034 /* Use catch_errors so the user can quit from gdb even when we
7035 aren't on speaking terms with the remote system. */
7036 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
7038 /* Don't wait for it to die. I'm not really sure it matters whether
7039 we do or not. For the existing stubs, kill is a noop. */
7040 target_mourn_inferior ();
7044 remote_vkill (int pid
, struct remote_state
*rs
)
7046 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7049 /* Tell the remote target to detach. */
7050 sprintf (rs
->buf
, "vKill;%x", pid
);
7052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7054 if (packet_ok (rs
->buf
,
7055 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7057 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7064 extended_remote_kill (struct target_ops
*ops
)
7067 int pid
= ptid_get_pid (inferior_ptid
);
7068 struct remote_state
*rs
= get_remote_state ();
7070 res
= remote_vkill (pid
, rs
);
7071 if (res
== -1 && !remote_multi_process_p (rs
))
7073 /* Don't try 'k' on a multi-process aware stub -- it has no way
7074 to specify the pid. */
7078 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7079 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7082 /* Don't wait for it to die. I'm not really sure it matters whether
7083 we do or not. For the existing stubs, kill is a noop. */
7089 error (_("Can't kill process"));
7091 target_mourn_inferior ();
7095 remote_mourn (struct target_ops
*ops
)
7097 remote_mourn_1 (ops
);
7100 /* Worker function for remote_mourn. */
7102 remote_mourn_1 (struct target_ops
*target
)
7104 unpush_target (target
);
7106 /* remote_close takes care of doing most of the clean up. */
7107 generic_mourn_inferior ();
7111 extended_remote_mourn_1 (struct target_ops
*target
)
7113 struct remote_state
*rs
= get_remote_state ();
7115 /* In case we got here due to an error, but we're going to stay
7117 rs
->waiting_for_stop_reply
= 0;
7119 /* We're no longer interested in these events. */
7120 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7122 /* If the current general thread belonged to the process we just
7123 detached from or has exited, the remote side current general
7124 thread becomes undefined. Considering a case like this:
7126 - We just got here due to a detach.
7127 - The process that we're detaching from happens to immediately
7128 report a global breakpoint being hit in non-stop mode, in the
7129 same thread we had selected before.
7130 - GDB attaches to this process again.
7131 - This event happens to be the next event we handle.
7133 GDB would consider that the current general thread didn't need to
7134 be set on the stub side (with Hg), since for all it knew,
7135 GENERAL_THREAD hadn't changed.
7137 Notice that although in all-stop mode, the remote server always
7138 sets the current thread to the thread reporting the stop event,
7139 that doesn't happen in non-stop mode; in non-stop, the stub *must
7140 not* change the current thread when reporting a breakpoint hit,
7141 due to the decoupling of event reporting and event handling.
7143 To keep things simple, we always invalidate our notion of the
7145 record_currthread (minus_one_ptid
);
7147 /* Unlike "target remote", we do not want to unpush the target; then
7148 the next time the user says "run", we won't be connected. */
7150 /* Call common code to mark the inferior as not running. */
7151 generic_mourn_inferior ();
7153 if (!have_inferiors ())
7155 if (!remote_multi_process_p (rs
))
7157 /* Check whether the target is running now - some remote stubs
7158 automatically restart after kill. */
7160 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7162 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7164 /* Assume that the target has been restarted. Set inferior_ptid
7165 so that bits of core GDB realizes there's something here, e.g.,
7166 so that the user can say "kill" again. */
7167 inferior_ptid
= magic_null_ptid
;
7174 extended_remote_mourn (struct target_ops
*ops
)
7176 extended_remote_mourn_1 (ops
);
7180 extended_remote_run (char *args
)
7182 struct remote_state
*rs
= get_remote_state ();
7185 /* If the user has disabled vRun support, or we have detected that
7186 support is not available, do not try it. */
7187 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7190 strcpy (rs
->buf
, "vRun;");
7191 len
= strlen (rs
->buf
);
7193 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7194 error (_("Remote file name too long for run packet"));
7195 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7197 gdb_assert (args
!= NULL
);
7200 struct cleanup
*back_to
;
7204 argv
= gdb_buildargv (args
);
7205 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7206 for (i
= 0; argv
[i
] != NULL
; i
++)
7208 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7209 error (_("Argument list too long for run packet"));
7210 rs
->buf
[len
++] = ';';
7211 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7213 do_cleanups (back_to
);
7216 rs
->buf
[len
++] = '\0';
7219 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7221 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7223 /* We have a wait response; we don't need it, though. All is well. */
7226 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7227 /* It wasn't disabled before, but it is now. */
7231 if (remote_exec_file
[0] == '\0')
7232 error (_("Running the default executable on the remote target failed; "
7233 "try \"set remote exec-file\"?"));
7235 error (_("Running \"%s\" on the remote target failed"),
7240 /* In the extended protocol we want to be able to do things like
7241 "run" and have them basically work as expected. So we need
7242 a special create_inferior function. We support changing the
7243 executable file and the command line arguments, but not the
7247 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7248 char **env
, int from_tty
)
7250 /* If running asynchronously, register the target file descriptor
7251 with the event loop. */
7252 if (target_can_async_p ())
7253 target_async (inferior_event_handler
, 0);
7255 /* Now restart the remote server. */
7256 if (extended_remote_run (args
) == -1)
7258 /* vRun was not supported. Fail if we need it to do what the
7260 if (remote_exec_file
[0])
7261 error (_("Remote target does not support \"set remote exec-file\""));
7263 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7265 /* Fall back to "R". */
7266 extended_remote_restart ();
7269 if (!have_inferiors ())
7271 /* Clean up from the last time we ran, before we mark the target
7272 running again. This will mark breakpoints uninserted, and
7273 get_offsets may insert breakpoints. */
7274 init_thread_list ();
7275 init_wait_for_inferior ();
7278 /* Now mark the inferior as running before we do anything else. */
7279 inferior_ptid
= magic_null_ptid
;
7281 /* Now, if we have thread information, update inferior_ptid. */
7282 inferior_ptid
= remote_current_thread (inferior_ptid
);
7284 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7285 add_thread_silent (inferior_ptid
);
7287 /* Get updated offsets, if the stub uses qOffsets. */
7292 extended_remote_create_inferior (struct target_ops
*ops
,
7293 char *exec_file
, char *args
,
7294 char **env
, int from_tty
)
7296 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7300 /* Insert a breakpoint. On targets that have software breakpoint
7301 support, we ask the remote target to do the work; on targets
7302 which don't, we insert a traditional memory breakpoint. */
7305 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7306 struct bp_target_info
*bp_tgt
)
7308 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7309 If it succeeds, then set the support to PACKET_ENABLE. If it
7310 fails, and the user has explicitly requested the Z support then
7311 report an error, otherwise, mark it disabled and go on. */
7313 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7315 CORE_ADDR addr
= bp_tgt
->placed_address
;
7316 struct remote_state
*rs
;
7320 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7322 rs
= get_remote_state ();
7328 addr
= (ULONGEST
) remote_address_masked (addr
);
7329 p
+= hexnumstr (p
, addr
);
7330 sprintf (p
, ",%d", bpsize
);
7333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7335 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7340 bp_tgt
->placed_address
= addr
;
7341 bp_tgt
->placed_size
= bpsize
;
7343 case PACKET_UNKNOWN
:
7348 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7352 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7353 struct bp_target_info
*bp_tgt
)
7355 CORE_ADDR addr
= bp_tgt
->placed_address
;
7356 struct remote_state
*rs
= get_remote_state ();
7358 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7366 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7367 p
+= hexnumstr (p
, addr
);
7368 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7371 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7373 return (rs
->buf
[0] == 'E');
7376 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7380 watchpoint_to_Z_packet (int type
)
7385 return Z_PACKET_WRITE_WP
;
7388 return Z_PACKET_READ_WP
;
7391 return Z_PACKET_ACCESS_WP
;
7394 internal_error (__FILE__
, __LINE__
,
7395 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7400 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
7402 struct remote_state
*rs
= get_remote_state ();
7404 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7406 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7409 sprintf (rs
->buf
, "Z%x,", packet
);
7410 p
= strchr (rs
->buf
, '\0');
7411 addr
= remote_address_masked (addr
);
7412 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7413 sprintf (p
, ",%x", len
);
7416 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7418 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7422 case PACKET_UNKNOWN
:
7427 internal_error (__FILE__
, __LINE__
,
7428 _("remote_insert_watchpoint: reached end of function"));
7433 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
7435 struct remote_state
*rs
= get_remote_state ();
7437 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7439 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7442 sprintf (rs
->buf
, "z%x,", packet
);
7443 p
= strchr (rs
->buf
, '\0');
7444 addr
= remote_address_masked (addr
);
7445 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7446 sprintf (p
, ",%x", len
);
7448 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7450 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7453 case PACKET_UNKNOWN
:
7458 internal_error (__FILE__
, __LINE__
,
7459 _("remote_remove_watchpoint: reached end of function"));
7463 int remote_hw_watchpoint_limit
= -1;
7464 int remote_hw_breakpoint_limit
= -1;
7467 remote_check_watch_resources (int type
, int cnt
, int ot
)
7469 if (type
== bp_hardware_breakpoint
)
7471 if (remote_hw_breakpoint_limit
== 0)
7473 else if (remote_hw_breakpoint_limit
< 0)
7475 else if (cnt
<= remote_hw_breakpoint_limit
)
7480 if (remote_hw_watchpoint_limit
== 0)
7482 else if (remote_hw_watchpoint_limit
< 0)
7486 else if (cnt
<= remote_hw_watchpoint_limit
)
7493 remote_stopped_by_watchpoint (void)
7495 return remote_stopped_by_watchpoint_p
;
7499 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7502 if (remote_stopped_by_watchpoint ())
7504 *addr_p
= remote_watch_data_address
;
7513 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7514 struct bp_target_info
*bp_tgt
)
7517 struct remote_state
*rs
;
7520 /* The length field should be set to the size of a breakpoint
7521 instruction, even though we aren't inserting one ourselves. */
7523 gdbarch_remote_breakpoint_from_pc
7524 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7526 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7529 rs
= get_remote_state ();
7536 addr
= remote_address_masked (bp_tgt
->placed_address
);
7537 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7538 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7541 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7543 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7546 case PACKET_UNKNOWN
:
7551 internal_error (__FILE__
, __LINE__
,
7552 _("remote_insert_hw_breakpoint: reached end of function"));
7557 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7558 struct bp_target_info
*bp_tgt
)
7561 struct remote_state
*rs
= get_remote_state ();
7564 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7571 addr
= remote_address_masked (bp_tgt
->placed_address
);
7572 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7573 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7576 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7578 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7581 case PACKET_UNKNOWN
:
7586 internal_error (__FILE__
, __LINE__
,
7587 _("remote_remove_hw_breakpoint: reached end of function"));
7590 /* Table used by the crc32 function to calcuate the checksum. */
7592 static unsigned long crc32_table
[256] =
7595 static unsigned long
7596 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7598 if (!crc32_table
[1])
7600 /* Initialize the CRC table and the decoding table. */
7604 for (i
= 0; i
< 256; i
++)
7606 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7607 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7614 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7620 /* Verify memory using the "qCRC:" request. */
7623 remote_verify_memory (struct target_ops
*ops
,
7624 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
7626 struct remote_state
*rs
= get_remote_state ();
7627 unsigned long host_crc
, target_crc
;
7630 /* FIXME: assumes lma can fit into long. */
7631 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7632 (long) lma
, (long) size
);
7635 /* Be clever; compute the host_crc before waiting for target
7637 host_crc
= crc32 (data
, size
, 0xffffffff);
7639 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7640 if (rs
->buf
[0] == 'E')
7643 if (rs
->buf
[0] != 'C')
7644 error (_("remote target does not support this operation"));
7646 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7647 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7649 return (host_crc
== target_crc
);
7652 /* compare-sections command
7654 With no arguments, compares each loadable section in the exec bfd
7655 with the same memory range on the target, and reports mismatches.
7656 Useful for verifying the image on the target against the exec file. */
7659 compare_sections_command (char *args
, int from_tty
)
7662 struct cleanup
*old_chain
;
7664 const char *sectname
;
7672 error (_("command cannot be used without an exec file"));
7674 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7676 if (!(s
->flags
& SEC_LOAD
))
7677 continue; /* skip non-loadable section */
7679 size
= bfd_get_section_size (s
);
7681 continue; /* skip zero-length section */
7683 sectname
= bfd_get_section_name (exec_bfd
, s
);
7684 if (args
&& strcmp (args
, sectname
) != 0)
7685 continue; /* not the section selected by user */
7687 matched
= 1; /* do this section */
7690 sectdata
= xmalloc (size
);
7691 old_chain
= make_cleanup (xfree
, sectdata
);
7692 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
7694 res
= target_verify_memory (sectdata
, lma
, size
);
7697 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
7698 paddress (target_gdbarch
, lma
),
7699 paddress (target_gdbarch
, lma
+ size
));
7701 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
7702 paddress (target_gdbarch
, lma
),
7703 paddress (target_gdbarch
, lma
+ size
));
7705 printf_filtered ("matched.\n");
7708 printf_filtered ("MIS-MATCHED!\n");
7712 do_cleanups (old_chain
);
7715 warning (_("One or more sections of the remote executable does not match\n\
7716 the loaded file\n"));
7717 if (args
&& !matched
)
7718 printf_filtered (_("No loaded section named '%s'.\n"), args
);
7721 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
7722 into remote target. The number of bytes written to the remote
7723 target is returned, or -1 for error. */
7726 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
7727 const char *annex
, const gdb_byte
*writebuf
,
7728 ULONGEST offset
, LONGEST len
,
7729 struct packet_config
*packet
)
7733 struct remote_state
*rs
= get_remote_state ();
7734 int max_size
= get_memory_write_packet_size ();
7736 if (packet
->support
== PACKET_DISABLE
)
7739 /* Insert header. */
7740 i
= snprintf (rs
->buf
, max_size
,
7741 "qXfer:%s:write:%s:%s:",
7742 object_name
, annex
? annex
: "",
7743 phex_nz (offset
, sizeof offset
));
7744 max_size
-= (i
+ 1);
7746 /* Escape as much data as fits into rs->buf. */
7747 buf_len
= remote_escape_output
7748 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
7750 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
7751 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7752 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7755 unpack_varlen_hex (rs
->buf
, &n
);
7759 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
7760 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
7761 number of bytes read is returned, or 0 for EOF, or -1 for error.
7762 The number of bytes read may be less than LEN without indicating an
7763 EOF. PACKET is checked and updated to indicate whether the remote
7764 target supports this object. */
7767 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
7769 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
7770 struct packet_config
*packet
)
7772 static char *finished_object
;
7773 static char *finished_annex
;
7774 static ULONGEST finished_offset
;
7776 struct remote_state
*rs
= get_remote_state ();
7777 LONGEST i
, n
, packet_len
;
7779 if (packet
->support
== PACKET_DISABLE
)
7782 /* Check whether we've cached an end-of-object packet that matches
7784 if (finished_object
)
7786 if (strcmp (object_name
, finished_object
) == 0
7787 && strcmp (annex
? annex
: "", finished_annex
) == 0
7788 && offset
== finished_offset
)
7791 /* Otherwise, we're now reading something different. Discard
7793 xfree (finished_object
);
7794 xfree (finished_annex
);
7795 finished_object
= NULL
;
7796 finished_annex
= NULL
;
7799 /* Request only enough to fit in a single packet. The actual data
7800 may not, since we don't know how much of it will need to be escaped;
7801 the target is free to respond with slightly less data. We subtract
7802 five to account for the response type and the protocol frame. */
7803 n
= min (get_remote_packet_size () - 5, len
);
7804 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
7805 object_name
, annex
? annex
: "",
7806 phex_nz (offset
, sizeof offset
),
7807 phex_nz (n
, sizeof n
));
7808 i
= putpkt (rs
->buf
);
7813 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
7814 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7817 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
7818 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
7820 /* 'm' means there is (or at least might be) more data after this
7821 batch. That does not make sense unless there's at least one byte
7822 of data in this reply. */
7823 if (rs
->buf
[0] == 'm' && packet_len
== 1)
7824 error (_("Remote qXfer reply contained no data."));
7826 /* Got some data. */
7827 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
7829 /* 'l' is an EOF marker, possibly including a final block of data,
7830 or possibly empty. If we have the final block of a non-empty
7831 object, record this fact to bypass a subsequent partial read. */
7832 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
7834 finished_object
= xstrdup (object_name
);
7835 finished_annex
= xstrdup (annex
? annex
: "");
7836 finished_offset
= offset
+ i
;
7843 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
7844 const char *annex
, gdb_byte
*readbuf
,
7845 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
7847 struct remote_state
*rs
;
7852 set_general_thread (inferior_ptid
);
7854 rs
= get_remote_state ();
7856 /* Handle memory using the standard memory routines. */
7857 if (object
== TARGET_OBJECT_MEMORY
)
7862 /* If the remote target is connected but not running, we should
7863 pass this request down to a lower stratum (e.g. the executable
7865 if (!target_has_execution
)
7868 if (writebuf
!= NULL
)
7869 xfered
= remote_write_bytes (offset
, writebuf
, len
);
7871 xfered
= remote_read_bytes (offset
, readbuf
, len
);
7875 else if (xfered
== 0 && errno
== 0)
7881 /* Handle SPU memory using qxfer packets. */
7882 if (object
== TARGET_OBJECT_SPU
)
7885 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
7886 &remote_protocol_packets
7887 [PACKET_qXfer_spu_read
]);
7889 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
7890 &remote_protocol_packets
7891 [PACKET_qXfer_spu_write
]);
7894 /* Handle extra signal info using qxfer packets. */
7895 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
7898 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
7899 &remote_protocol_packets
7900 [PACKET_qXfer_siginfo_read
]);
7902 return remote_write_qxfer (ops
, "siginfo", annex
, writebuf
, offset
, len
,
7903 &remote_protocol_packets
7904 [PACKET_qXfer_siginfo_write
]);
7907 /* Only handle flash writes. */
7908 if (writebuf
!= NULL
)
7914 case TARGET_OBJECT_FLASH
:
7915 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
7919 else if (xfered
== 0 && errno
== 0)
7929 /* Map pre-existing objects onto letters. DO NOT do this for new
7930 objects!!! Instead specify new query packets. */
7933 case TARGET_OBJECT_AVR
:
7937 case TARGET_OBJECT_AUXV
:
7938 gdb_assert (annex
== NULL
);
7939 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
7940 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
7942 case TARGET_OBJECT_AVAILABLE_FEATURES
:
7943 return remote_read_qxfer
7944 (ops
, "features", annex
, readbuf
, offset
, len
,
7945 &remote_protocol_packets
[PACKET_qXfer_features
]);
7947 case TARGET_OBJECT_LIBRARIES
:
7948 return remote_read_qxfer
7949 (ops
, "libraries", annex
, readbuf
, offset
, len
,
7950 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
7952 case TARGET_OBJECT_MEMORY_MAP
:
7953 gdb_assert (annex
== NULL
);
7954 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
7955 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
7957 case TARGET_OBJECT_OSDATA
:
7958 /* Should only get here if we're connected. */
7959 gdb_assert (remote_desc
);
7960 return remote_read_qxfer
7961 (ops
, "osdata", annex
, readbuf
, offset
, len
,
7962 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
7964 case TARGET_OBJECT_THREADS
:
7965 gdb_assert (annex
== NULL
);
7966 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
7967 &remote_protocol_packets
[PACKET_qXfer_threads
]);
7973 /* Note: a zero OFFSET and LEN can be used to query the minimum
7975 if (offset
== 0 && len
== 0)
7976 return (get_remote_packet_size ());
7977 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
7978 large enough let the caller deal with it. */
7979 if (len
< get_remote_packet_size ())
7981 len
= get_remote_packet_size ();
7983 /* Except for querying the minimum buffer size, target must be open. */
7985 error (_("remote query is only available after target open"));
7987 gdb_assert (annex
!= NULL
);
7988 gdb_assert (readbuf
!= NULL
);
7994 /* We used one buffer char for the remote protocol q command and
7995 another for the query type. As the remote protocol encapsulation
7996 uses 4 chars plus one extra in case we are debugging
7997 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8000 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8002 /* Bad caller may have sent forbidden characters. */
8003 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8008 gdb_assert (annex
[i
] == '\0');
8010 i
= putpkt (rs
->buf
);
8014 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8015 strcpy ((char *) readbuf
, rs
->buf
);
8017 return strlen ((char *) readbuf
);
8021 remote_search_memory (struct target_ops
* ops
,
8022 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8023 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8024 CORE_ADDR
*found_addrp
)
8026 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8027 struct remote_state
*rs
= get_remote_state ();
8028 int max_size
= get_memory_write_packet_size ();
8029 struct packet_config
*packet
=
8030 &remote_protocol_packets
[PACKET_qSearch_memory
];
8031 /* number of packet bytes used to encode the pattern,
8032 this could be more than PATTERN_LEN due to escape characters */
8033 int escaped_pattern_len
;
8034 /* amount of pattern that was encodable in the packet */
8035 int used_pattern_len
;
8038 ULONGEST found_addr
;
8040 /* Don't go to the target if we don't have to.
8041 This is done before checking packet->support to avoid the possibility that
8042 a success for this edge case means the facility works in general. */
8043 if (pattern_len
> search_space_len
)
8045 if (pattern_len
== 0)
8047 *found_addrp
= start_addr
;
8051 /* If we already know the packet isn't supported, fall back to the simple
8052 way of searching memory. */
8054 if (packet
->support
== PACKET_DISABLE
)
8056 /* Target doesn't provided special support, fall back and use the
8057 standard support (copy memory and do the search here). */
8058 return simple_search_memory (ops
, start_addr
, search_space_len
,
8059 pattern
, pattern_len
, found_addrp
);
8062 /* Insert header. */
8063 i
= snprintf (rs
->buf
, max_size
,
8064 "qSearch:memory:%s;%s;",
8065 phex_nz (start_addr
, addr_size
),
8066 phex_nz (search_space_len
, sizeof (search_space_len
)));
8067 max_size
-= (i
+ 1);
8069 /* Escape as much data as fits into rs->buf. */
8070 escaped_pattern_len
=
8071 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8072 &used_pattern_len
, max_size
);
8074 /* Bail if the pattern is too large. */
8075 if (used_pattern_len
!= pattern_len
)
8076 error ("Pattern is too large to transmit to remote target.");
8078 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8079 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8080 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8082 /* The request may not have worked because the command is not
8083 supported. If so, fall back to the simple way. */
8084 if (packet
->support
== PACKET_DISABLE
)
8086 return simple_search_memory (ops
, start_addr
, search_space_len
,
8087 pattern
, pattern_len
, found_addrp
);
8092 if (rs
->buf
[0] == '0')
8094 else if (rs
->buf
[0] == '1')
8097 if (rs
->buf
[1] != ',')
8098 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8099 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8100 *found_addrp
= found_addr
;
8103 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8109 remote_rcmd (char *command
,
8110 struct ui_file
*outbuf
)
8112 struct remote_state
*rs
= get_remote_state ();
8116 error (_("remote rcmd is only available after target open"));
8118 /* Send a NULL command across as an empty command. */
8119 if (command
== NULL
)
8122 /* The query prefix. */
8123 strcpy (rs
->buf
, "qRcmd,");
8124 p
= strchr (rs
->buf
, '\0');
8126 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
8127 error (_("\"monitor\" command ``%s'' is too long."), command
);
8129 /* Encode the actual command. */
8130 bin2hex ((gdb_byte
*) command
, p
, 0);
8132 if (putpkt (rs
->buf
) < 0)
8133 error (_("Communication problem with target."));
8135 /* get/display the response */
8140 /* XXX - see also remote_get_noisy_reply(). */
8142 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8145 error (_("Target does not support this command."));
8146 if (buf
[0] == 'O' && buf
[1] != 'K')
8148 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8151 if (strcmp (buf
, "OK") == 0)
8153 if (strlen (buf
) == 3 && buf
[0] == 'E'
8154 && isdigit (buf
[1]) && isdigit (buf
[2]))
8156 error (_("Protocol error with Rcmd"));
8158 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8160 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8161 fputc_unfiltered (c
, outbuf
);
8167 static VEC(mem_region_s
) *
8168 remote_memory_map (struct target_ops
*ops
)
8170 VEC(mem_region_s
) *result
= NULL
;
8171 char *text
= target_read_stralloc (¤t_target
,
8172 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8176 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8177 result
= parse_memory_map (text
);
8178 do_cleanups (back_to
);
8185 packet_command (char *args
, int from_tty
)
8187 struct remote_state
*rs
= get_remote_state ();
8190 error (_("command can only be used with remote target"));
8193 error (_("remote-packet command requires packet text as argument"));
8195 puts_filtered ("sending: ");
8196 print_packet (args
);
8197 puts_filtered ("\n");
8200 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8201 puts_filtered ("received: ");
8202 print_packet (rs
->buf
);
8203 puts_filtered ("\n");
8207 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8209 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8211 static void threadset_test_cmd (char *cmd
, int tty
);
8213 static void threadalive_test (char *cmd
, int tty
);
8215 static void threadlist_test_cmd (char *cmd
, int tty
);
8217 int get_and_display_threadinfo (threadref
*ref
);
8219 static void threadinfo_test_cmd (char *cmd
, int tty
);
8221 static int thread_display_step (threadref
*ref
, void *context
);
8223 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8225 static void init_remote_threadtests (void);
8227 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8230 threadset_test_cmd (char *cmd
, int tty
)
8232 int sample_thread
= SAMPLE_THREAD
;
8234 printf_filtered (_("Remote threadset test\n"));
8235 set_general_thread (sample_thread
);
8240 threadalive_test (char *cmd
, int tty
)
8242 int sample_thread
= SAMPLE_THREAD
;
8243 int pid
= ptid_get_pid (inferior_ptid
);
8244 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8246 if (remote_thread_alive (ptid
))
8247 printf_filtered ("PASS: Thread alive test\n");
8249 printf_filtered ("FAIL: Thread alive test\n");
8252 void output_threadid (char *title
, threadref
*ref
);
8255 output_threadid (char *title
, threadref
*ref
)
8259 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8261 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8265 threadlist_test_cmd (char *cmd
, int tty
)
8268 threadref nextthread
;
8269 int done
, result_count
;
8270 threadref threadlist
[3];
8272 printf_filtered ("Remote Threadlist test\n");
8273 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8274 &result_count
, &threadlist
[0]))
8275 printf_filtered ("FAIL: threadlist test\n");
8278 threadref
*scan
= threadlist
;
8279 threadref
*limit
= scan
+ result_count
;
8281 while (scan
< limit
)
8282 output_threadid (" thread ", scan
++);
8287 display_thread_info (struct gdb_ext_thread_info
*info
)
8289 output_threadid ("Threadid: ", &info
->threadid
);
8290 printf_filtered ("Name: %s\n ", info
->shortname
);
8291 printf_filtered ("State: %s\n", info
->display
);
8292 printf_filtered ("other: %s\n\n", info
->more_display
);
8296 get_and_display_threadinfo (threadref
*ref
)
8300 struct gdb_ext_thread_info threadinfo
;
8302 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8303 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8304 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8305 display_thread_info (&threadinfo
);
8310 threadinfo_test_cmd (char *cmd
, int tty
)
8312 int athread
= SAMPLE_THREAD
;
8316 int_to_threadref (&thread
, athread
);
8317 printf_filtered ("Remote Threadinfo test\n");
8318 if (!get_and_display_threadinfo (&thread
))
8319 printf_filtered ("FAIL cannot get thread info\n");
8323 thread_display_step (threadref
*ref
, void *context
)
8325 /* output_threadid(" threadstep ",ref); *//* simple test */
8326 return get_and_display_threadinfo (ref
);
8330 threadlist_update_test_cmd (char *cmd
, int tty
)
8332 printf_filtered ("Remote Threadlist update test\n");
8333 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8337 init_remote_threadtests (void)
8339 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
8340 Fetch and print the remote list of thread identifiers, one pkt only"));
8341 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8342 _("Fetch and display info about one thread"));
8343 add_com ("tset", class_obscure
, threadset_test_cmd
,
8344 _("Test setting to a different thread"));
8345 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8346 _("Iterate through updating all remote thread info"));
8347 add_com ("talive", class_obscure
, threadalive_test
,
8348 _(" Remote thread alive test "));
8353 /* Convert a thread ID to a string. Returns the string in a static
8357 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8359 static char buf
[64];
8360 struct remote_state
*rs
= get_remote_state ();
8362 if (ptid_is_pid (ptid
))
8364 /* Printing an inferior target id. */
8366 /* When multi-process extensions are off, there's no way in the
8367 remote protocol to know the remote process id, if there's any
8368 at all. There's one exception --- when we're connected with
8369 target extended-remote, and we manually attached to a process
8370 with "attach PID". We don't record anywhere a flag that
8371 allows us to distinguish that case from the case of
8372 connecting with extended-remote and the stub already being
8373 attached to a process, and reporting yes to qAttached, hence
8374 no smart special casing here. */
8375 if (!remote_multi_process_p (rs
))
8377 xsnprintf (buf
, sizeof buf
, "Remote target");
8381 return normal_pid_to_str (ptid
);
8385 if (ptid_equal (magic_null_ptid
, ptid
))
8386 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8387 else if (remote_multi_process_p (rs
))
8388 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8389 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8391 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8392 ptid_get_tid (ptid
));
8397 /* Get the address of the thread local variable in OBJFILE which is
8398 stored at OFFSET within the thread local storage for thread PTID. */
8401 remote_get_thread_local_address (struct target_ops
*ops
,
8402 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8404 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8406 struct remote_state
*rs
= get_remote_state ();
8408 char *endp
= rs
->buf
+ get_remote_packet_size ();
8409 enum packet_result result
;
8411 strcpy (p
, "qGetTLSAddr:");
8413 p
= write_ptid (p
, endp
, ptid
);
8415 p
+= hexnumstr (p
, offset
);
8417 p
+= hexnumstr (p
, lm
);
8421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8422 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8423 if (result
== PACKET_OK
)
8427 unpack_varlen_hex (rs
->buf
, &result
);
8430 else if (result
== PACKET_UNKNOWN
)
8431 throw_error (TLS_GENERIC_ERROR
,
8432 _("Remote target doesn't support qGetTLSAddr packet"));
8434 throw_error (TLS_GENERIC_ERROR
,
8435 _("Remote target failed to process qGetTLSAddr request"));
8438 throw_error (TLS_GENERIC_ERROR
,
8439 _("TLS not supported or disabled on this target"));
8444 /* Support for inferring a target description based on the current
8445 architecture and the size of a 'g' packet. While the 'g' packet
8446 can have any size (since optional registers can be left off the
8447 end), some sizes are easily recognizable given knowledge of the
8448 approximate architecture. */
8450 struct remote_g_packet_guess
8453 const struct target_desc
*tdesc
;
8455 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8456 DEF_VEC_O(remote_g_packet_guess_s
);
8458 struct remote_g_packet_data
8460 VEC(remote_g_packet_guess_s
) *guesses
;
8463 static struct gdbarch_data
*remote_g_packet_data_handle
;
8466 remote_g_packet_data_init (struct obstack
*obstack
)
8468 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8472 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8473 const struct target_desc
*tdesc
)
8475 struct remote_g_packet_data
*data
8476 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8477 struct remote_g_packet_guess new_guess
, *guess
;
8480 gdb_assert (tdesc
!= NULL
);
8483 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8485 if (guess
->bytes
== bytes
)
8486 internal_error (__FILE__
, __LINE__
,
8487 "Duplicate g packet description added for size %d",
8490 new_guess
.bytes
= bytes
;
8491 new_guess
.tdesc
= tdesc
;
8492 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8495 /* Return 1 if remote_read_description would do anything on this target
8496 and architecture, 0 otherwise. */
8499 remote_read_description_p (struct target_ops
*target
)
8501 struct remote_g_packet_data
*data
8502 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8504 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8510 static const struct target_desc
*
8511 remote_read_description (struct target_ops
*target
)
8513 struct remote_g_packet_data
*data
8514 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8516 /* Do not try this during initial connection, when we do not know
8517 whether there is a running but stopped thread. */
8518 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8521 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8523 struct remote_g_packet_guess
*guess
;
8525 int bytes
= send_g_packet ();
8528 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8530 if (guess
->bytes
== bytes
)
8531 return guess
->tdesc
;
8533 /* We discard the g packet. A minor optimization would be to
8534 hold on to it, and fill the register cache once we have selected
8535 an architecture, but it's too tricky to do safely. */
8541 /* Remote file transfer support. This is host-initiated I/O, not
8542 target-initiated; for target-initiated, see remote-fileio.c. */
8544 /* If *LEFT is at least the length of STRING, copy STRING to
8545 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8546 decrease *LEFT. Otherwise raise an error. */
8549 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8551 int len
= strlen (string
);
8554 error (_("Packet too long for target."));
8556 memcpy (*buffer
, string
, len
);
8560 /* NUL-terminate the buffer as a convenience, if there is
8566 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8567 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8568 decrease *LEFT. Otherwise raise an error. */
8571 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8574 if (2 * len
> *left
)
8575 error (_("Packet too long for target."));
8577 bin2hex (bytes
, *buffer
, len
);
8581 /* NUL-terminate the buffer as a convenience, if there is
8587 /* If *LEFT is large enough, convert VALUE to hex and add it to
8588 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8589 decrease *LEFT. Otherwise raise an error. */
8592 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
8594 int len
= hexnumlen (value
);
8597 error (_("Packet too long for target."));
8599 hexnumstr (*buffer
, value
);
8603 /* NUL-terminate the buffer as a convenience, if there is
8609 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8610 value, *REMOTE_ERRNO to the remote error number or zero if none
8611 was included, and *ATTACHMENT to point to the start of the annex
8612 if any. The length of the packet isn't needed here; there may
8613 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8615 Return 0 if the packet could be parsed, -1 if it could not. If
8616 -1 is returned, the other variables may not be initialized. */
8619 remote_hostio_parse_result (char *buffer
, int *retcode
,
8620 int *remote_errno
, char **attachment
)
8627 if (buffer
[0] != 'F')
8631 *retcode
= strtol (&buffer
[1], &p
, 16);
8632 if (errno
!= 0 || p
== &buffer
[1])
8635 /* Check for ",errno". */
8639 *remote_errno
= strtol (p
+ 1, &p2
, 16);
8640 if (errno
!= 0 || p
+ 1 == p2
)
8645 /* Check for ";attachment". If there is no attachment, the
8646 packet should end here. */
8649 *attachment
= p
+ 1;
8652 else if (*p
== '\0')
8658 /* Send a prepared I/O packet to the target and read its response.
8659 The prepared packet is in the global RS->BUF before this function
8660 is called, and the answer is there when we return.
8662 COMMAND_BYTES is the length of the request to send, which may include
8663 binary data. WHICH_PACKET is the packet configuration to check
8664 before attempting a packet. If an error occurs, *REMOTE_ERRNO
8665 is set to the error number and -1 is returned. Otherwise the value
8666 returned by the function is returned.
8668 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
8669 attachment is expected; an error will be reported if there's a
8670 mismatch. If one is found, *ATTACHMENT will be set to point into
8671 the packet buffer and *ATTACHMENT_LEN will be set to the
8672 attachment's length. */
8675 remote_hostio_send_command (int command_bytes
, int which_packet
,
8676 int *remote_errno
, char **attachment
,
8677 int *attachment_len
)
8679 struct remote_state
*rs
= get_remote_state ();
8680 int ret
, bytes_read
;
8681 char *attachment_tmp
;
8684 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
8686 *remote_errno
= FILEIO_ENOSYS
;
8690 putpkt_binary (rs
->buf
, command_bytes
);
8691 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8693 /* If it timed out, something is wrong. Don't try to parse the
8697 *remote_errno
= FILEIO_EINVAL
;
8701 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
8704 *remote_errno
= FILEIO_EINVAL
;
8706 case PACKET_UNKNOWN
:
8707 *remote_errno
= FILEIO_ENOSYS
;
8713 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
8716 *remote_errno
= FILEIO_EINVAL
;
8720 /* Make sure we saw an attachment if and only if we expected one. */
8721 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
8722 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
8724 *remote_errno
= FILEIO_EINVAL
;
8728 /* If an attachment was found, it must point into the packet buffer;
8729 work out how many bytes there were. */
8730 if (attachment_tmp
!= NULL
)
8732 *attachment
= attachment_tmp
;
8733 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
8739 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
8740 remote file descriptor, or -1 if an error occurs (and set
8744 remote_hostio_open (const char *filename
, int flags
, int mode
,
8747 struct remote_state
*rs
= get_remote_state ();
8749 int left
= get_remote_packet_size () - 1;
8751 remote_buffer_add_string (&p
, &left
, "vFile:open:");
8753 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8755 remote_buffer_add_string (&p
, &left
, ",");
8757 remote_buffer_add_int (&p
, &left
, flags
);
8758 remote_buffer_add_string (&p
, &left
, ",");
8760 remote_buffer_add_int (&p
, &left
, mode
);
8762 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
8763 remote_errno
, NULL
, NULL
);
8766 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
8767 Return the number of bytes written, or -1 if an error occurs (and
8768 set *REMOTE_ERRNO). */
8771 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
8772 ULONGEST offset
, int *remote_errno
)
8774 struct remote_state
*rs
= get_remote_state ();
8776 int left
= get_remote_packet_size ();
8779 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
8781 remote_buffer_add_int (&p
, &left
, fd
);
8782 remote_buffer_add_string (&p
, &left
, ",");
8784 remote_buffer_add_int (&p
, &left
, offset
);
8785 remote_buffer_add_string (&p
, &left
, ",");
8787 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
8788 get_remote_packet_size () - (p
- rs
->buf
));
8790 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
8791 remote_errno
, NULL
, NULL
);
8794 /* Read up to LEN bytes FD on the remote target into READ_BUF
8795 Return the number of bytes read, or -1 if an error occurs (and
8796 set *REMOTE_ERRNO). */
8799 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
8800 ULONGEST offset
, int *remote_errno
)
8802 struct remote_state
*rs
= get_remote_state ();
8805 int left
= get_remote_packet_size ();
8806 int ret
, attachment_len
;
8809 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
8811 remote_buffer_add_int (&p
, &left
, fd
);
8812 remote_buffer_add_string (&p
, &left
, ",");
8814 remote_buffer_add_int (&p
, &left
, len
);
8815 remote_buffer_add_string (&p
, &left
, ",");
8817 remote_buffer_add_int (&p
, &left
, offset
);
8819 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
8820 remote_errno
, &attachment
,
8826 read_len
= remote_unescape_input (attachment
, attachment_len
,
8828 if (read_len
!= ret
)
8829 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
8834 /* Close FD on the remote target. Return 0, or -1 if an error occurs
8835 (and set *REMOTE_ERRNO). */
8838 remote_hostio_close (int fd
, int *remote_errno
)
8840 struct remote_state
*rs
= get_remote_state ();
8842 int left
= get_remote_packet_size () - 1;
8844 remote_buffer_add_string (&p
, &left
, "vFile:close:");
8846 remote_buffer_add_int (&p
, &left
, fd
);
8848 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
8849 remote_errno
, NULL
, NULL
);
8852 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
8853 occurs (and set *REMOTE_ERRNO). */
8856 remote_hostio_unlink (const char *filename
, int *remote_errno
)
8858 struct remote_state
*rs
= get_remote_state ();
8860 int left
= get_remote_packet_size () - 1;
8862 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
8864 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8867 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
8868 remote_errno
, NULL
, NULL
);
8872 remote_fileio_errno_to_host (int errnum
)
8896 case FILEIO_ENOTDIR
:
8916 case FILEIO_ENAMETOOLONG
:
8917 return ENAMETOOLONG
;
8923 remote_hostio_error (int errnum
)
8925 int host_error
= remote_fileio_errno_to_host (errnum
);
8927 if (host_error
== -1)
8928 error (_("Unknown remote I/O error %d"), errnum
);
8930 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
8934 remote_hostio_close_cleanup (void *opaque
)
8936 int fd
= *(int *) opaque
;
8939 remote_hostio_close (fd
, &remote_errno
);
8944 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
8946 const char *filename
= bfd_get_filename (abfd
);
8947 int fd
, remote_errno
;
8950 gdb_assert (remote_filename_p (filename
));
8952 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
8955 errno
= remote_fileio_errno_to_host (remote_errno
);
8956 bfd_set_error (bfd_error_system_call
);
8960 stream
= xmalloc (sizeof (int));
8966 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
8968 int fd
= *(int *)stream
;
8973 /* Ignore errors on close; these may happen if the remote
8974 connection was already torn down. */
8975 remote_hostio_close (fd
, &remote_errno
);
8981 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
8982 file_ptr nbytes
, file_ptr offset
)
8984 int fd
= *(int *)stream
;
8986 file_ptr pos
, bytes
;
8989 while (nbytes
> pos
)
8991 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
8992 offset
+ pos
, &remote_errno
);
8994 /* Success, but no bytes, means end-of-file. */
8998 errno
= remote_fileio_errno_to_host (remote_errno
);
8999 bfd_set_error (bfd_error_system_call
);
9010 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9012 /* FIXME: We should probably implement remote_hostio_stat. */
9013 sb
->st_size
= INT_MAX
;
9018 remote_filename_p (const char *filename
)
9020 return strncmp (filename
, "remote:", 7) == 0;
9024 remote_bfd_open (const char *remote_file
, const char *target
)
9026 return bfd_openr_iovec (remote_file
, target
,
9027 remote_bfd_iovec_open
, NULL
,
9028 remote_bfd_iovec_pread
,
9029 remote_bfd_iovec_close
,
9030 remote_bfd_iovec_stat
);
9034 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9036 struct cleanup
*back_to
, *close_cleanup
;
9037 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9040 int bytes_in_buffer
;
9045 error (_("command can only be used with remote target"));
9047 file
= fopen (local_file
, "rb");
9049 perror_with_name (local_file
);
9050 back_to
= make_cleanup_fclose (file
);
9052 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9054 0700, &remote_errno
);
9056 remote_hostio_error (remote_errno
);
9058 /* Send up to this many bytes at once. They won't all fit in the
9059 remote packet limit, so we'll transfer slightly fewer. */
9060 io_size
= get_remote_packet_size ();
9061 buffer
= xmalloc (io_size
);
9062 make_cleanup (xfree
, buffer
);
9064 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9066 bytes_in_buffer
= 0;
9069 while (bytes_in_buffer
|| !saw_eof
)
9073 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
9078 error (_("Error reading %s."), local_file
);
9081 /* EOF. Unless there is something still in the
9082 buffer from the last iteration, we are done. */
9084 if (bytes_in_buffer
== 0)
9092 bytes
+= bytes_in_buffer
;
9093 bytes_in_buffer
= 0;
9095 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
9098 remote_hostio_error (remote_errno
);
9099 else if (retcode
== 0)
9100 error (_("Remote write of %d bytes returned 0!"), bytes
);
9101 else if (retcode
< bytes
)
9103 /* Short write. Save the rest of the read data for the next
9105 bytes_in_buffer
= bytes
- retcode
;
9106 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9112 discard_cleanups (close_cleanup
);
9113 if (remote_hostio_close (fd
, &remote_errno
))
9114 remote_hostio_error (remote_errno
);
9117 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9118 do_cleanups (back_to
);
9122 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9124 struct cleanup
*back_to
, *close_cleanup
;
9125 int fd
, remote_errno
, bytes
, io_size
;
9131 error (_("command can only be used with remote target"));
9133 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9135 remote_hostio_error (remote_errno
);
9137 file
= fopen (local_file
, "wb");
9139 perror_with_name (local_file
);
9140 back_to
= make_cleanup_fclose (file
);
9142 /* Send up to this many bytes at once. They won't all fit in the
9143 remote packet limit, so we'll transfer slightly fewer. */
9144 io_size
= get_remote_packet_size ();
9145 buffer
= xmalloc (io_size
);
9146 make_cleanup (xfree
, buffer
);
9148 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9153 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9155 /* Success, but no bytes, means end-of-file. */
9158 remote_hostio_error (remote_errno
);
9162 bytes
= fwrite (buffer
, 1, bytes
, file
);
9164 perror_with_name (local_file
);
9167 discard_cleanups (close_cleanup
);
9168 if (remote_hostio_close (fd
, &remote_errno
))
9169 remote_hostio_error (remote_errno
);
9172 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9173 do_cleanups (back_to
);
9177 remote_file_delete (const char *remote_file
, int from_tty
)
9179 int retcode
, remote_errno
;
9182 error (_("command can only be used with remote target"));
9184 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9186 remote_hostio_error (remote_errno
);
9189 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9193 remote_put_command (char *args
, int from_tty
)
9195 struct cleanup
*back_to
;
9199 error_no_arg (_("file to put"));
9201 argv
= gdb_buildargv (args
);
9202 back_to
= make_cleanup_freeargv (argv
);
9203 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9204 error (_("Invalid parameters to remote put"));
9206 remote_file_put (argv
[0], argv
[1], from_tty
);
9208 do_cleanups (back_to
);
9212 remote_get_command (char *args
, int from_tty
)
9214 struct cleanup
*back_to
;
9218 error_no_arg (_("file to get"));
9220 argv
= gdb_buildargv (args
);
9221 back_to
= make_cleanup_freeargv (argv
);
9222 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9223 error (_("Invalid parameters to remote get"));
9225 remote_file_get (argv
[0], argv
[1], from_tty
);
9227 do_cleanups (back_to
);
9231 remote_delete_command (char *args
, int from_tty
)
9233 struct cleanup
*back_to
;
9237 error_no_arg (_("file to delete"));
9239 argv
= gdb_buildargv (args
);
9240 back_to
= make_cleanup_freeargv (argv
);
9241 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9242 error (_("Invalid parameters to remote delete"));
9244 remote_file_delete (argv
[0], from_tty
);
9246 do_cleanups (back_to
);
9250 remote_command (char *args
, int from_tty
)
9252 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9256 remote_can_execute_reverse (void)
9258 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9259 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9266 remote_supports_non_stop (void)
9272 remote_supports_multi_process (void)
9274 struct remote_state
*rs
= get_remote_state ();
9275 return remote_multi_process_p (rs
);
9279 remote_supports_cond_tracepoints (void)
9281 struct remote_state
*rs
= get_remote_state ();
9282 return rs
->cond_tracepoints
;
9286 remote_supports_fast_tracepoints (void)
9288 struct remote_state
*rs
= get_remote_state ();
9289 return rs
->fast_tracepoints
;
9293 remote_trace_init ()
9296 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9297 if (strcmp (target_buf
, "OK"))
9298 error (_("Target does not support this command."));
9301 static void free_actions_list (char **actions_list
);
9302 static void free_actions_list_cleanup_wrapper (void *);
9304 free_actions_list_cleanup_wrapper (void *al
)
9306 free_actions_list (al
);
9310 free_actions_list (char **actions_list
)
9314 if (actions_list
== 0)
9317 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9318 xfree (actions_list
[ndx
]);
9320 xfree (actions_list
);
9323 /* Recursive routine to walk through command list including loops, and
9324 download packets for each command. */
9327 remote_download_command_source (int num
, ULONGEST addr
,
9328 struct command_line
*cmds
)
9330 struct remote_state
*rs
= get_remote_state ();
9331 struct command_line
*cmd
;
9333 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9335 QUIT
; /* allow user to bail out with ^C */
9336 strcpy (rs
->buf
, "QTDPsrc:");
9337 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9338 rs
->buf
+ strlen (rs
->buf
),
9339 rs
->buf_size
- strlen (rs
->buf
));
9341 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9342 if (strcmp (target_buf
, "OK"))
9343 warning (_("Target does not support source download."));
9345 if (cmd
->control_type
== while_control
9346 || cmd
->control_type
== while_stepping_control
)
9348 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9350 QUIT
; /* allow user to bail out with ^C */
9351 strcpy (rs
->buf
, "QTDPsrc:");
9352 encode_source_string (num
, addr
, "cmd", "end",
9353 rs
->buf
+ strlen (rs
->buf
),
9354 rs
->buf_size
- strlen (rs
->buf
));
9356 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9357 if (strcmp (target_buf
, "OK"))
9358 warning (_("Target does not support source download."));
9364 remote_download_tracepoint (struct breakpoint
*t
)
9366 struct bp_location
*loc
;
9371 char **stepping_actions
;
9373 struct cleanup
*old_chain
= NULL
;
9374 struct agent_expr
*aexpr
;
9375 struct cleanup
*aexpr_chain
= NULL
;
9378 /* Iterate over all the tracepoint locations. It's up to the target to
9379 notice multiple tracepoint packets with the same number but different
9380 addresses, and treat them as multiple locations. */
9381 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
9383 encode_actions (t
, loc
, &tdp_actions
, &stepping_actions
);
9384 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9386 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
9388 tpaddr
= loc
->address
;
9389 sprintf_vma (addrbuf
, tpaddr
);
9390 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
9391 addrbuf
, /* address */
9392 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
9393 t
->step_count
, t
->pass_count
);
9394 /* Fast tracepoints are mostly handled by the target, but we can
9395 tell the target how big of an instruction block should be moved
9397 if (t
->type
== bp_fast_tracepoint
)
9399 /* Only test for support at download time; we may not know
9400 target capabilities at definition time. */
9401 if (remote_supports_fast_tracepoints ())
9405 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9406 tpaddr
, &isize
, NULL
))
9407 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9409 /* If it passed validation at definition but fails now,
9410 something is very wrong. */
9411 internal_error (__FILE__
, __LINE__
,
9412 "Fast tracepoint not valid during download");
9415 /* Fast tracepoints are functionally identical to regular
9416 tracepoints, so don't take lack of support as a reason to
9417 give up on the trace run. */
9418 warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t
->number
);
9420 /* If the tracepoint has a conditional, make it into an agent
9421 expression and append to the definition. */
9424 /* Only test support at download time, we may not know target
9425 capabilities at definition time. */
9426 if (remote_supports_cond_tracepoints ())
9428 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9429 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9430 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9431 pkt
= buf
+ strlen (buf
);
9432 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9433 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9435 do_cleanups (aexpr_chain
);
9438 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
9441 if (t
->commands
|| *default_collect
)
9444 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9445 if (strcmp (target_buf
, "OK"))
9446 error (_("Target does not support tracepoints."));
9448 /* do_single_steps (t); */
9451 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9453 QUIT
; /* allow user to bail out with ^C */
9454 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9455 t
->number
, addrbuf
, /* address */
9457 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9460 remote_get_noisy_reply (&target_buf
,
9462 if (strcmp (target_buf
, "OK"))
9463 error (_("Error on target while setting tracepoints."));
9466 if (stepping_actions
)
9468 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9470 QUIT
; /* allow user to bail out with ^C */
9471 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9472 t
->number
, addrbuf
, /* address */
9473 ((ndx
== 0) ? "S" : ""),
9474 stepping_actions
[ndx
],
9475 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9477 remote_get_noisy_reply (&target_buf
,
9479 if (strcmp (target_buf
, "OK"))
9480 error (_("Error on target while setting tracepoints."));
9484 if (remote_protocol_packets
[PACKET_TracepointSource
].support
== PACKET_ENABLE
)
9488 strcpy (buf
, "QTDPsrc:");
9489 encode_source_string (t
->number
, loc
->address
,
9490 "at", t
->addr_string
, buf
+ strlen (buf
),
9491 2048 - strlen (buf
));
9494 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9495 if (strcmp (target_buf
, "OK"))
9496 warning (_("Target does not support source download."));
9500 strcpy (buf
, "QTDPsrc:");
9501 encode_source_string (t
->number
, loc
->address
,
9502 "cond", t
->cond_string
, buf
+ strlen (buf
),
9503 2048 - strlen (buf
));
9505 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9506 if (strcmp (target_buf
, "OK"))
9507 warning (_("Target does not support source download."));
9509 remote_download_command_source (t
->number
, loc
->address
,
9510 t
->commands
->commands
);
9513 do_cleanups (old_chain
);
9518 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
9520 struct remote_state
*rs
= get_remote_state ();
9523 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
9524 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
9525 p
= rs
->buf
+ strlen (rs
->buf
);
9526 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
9527 error (_("Trace state variable name too long for tsv definition packet"));
9528 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
9531 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9535 remote_trace_set_readonly_regions ()
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 ()
9574 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9575 if (strcmp (target_buf
, "OK"))
9576 error (_("Bogus reply from target: %s"), target_buf
);
9580 remote_get_trace_status (struct trace_status
*ts
)
9582 char *p
, *p1
, *p_temp
;
9584 /* FIXME we need to get register block size some other way */
9585 extern int trace_regblock_size
;
9586 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
9588 putpkt ("qTStatus");
9589 getpkt (&target_buf
, &target_buf_size
, 0);
9590 /* FIXME should handle more variety of replies */
9594 /* If the remote target doesn't do tracing, flag it. */
9598 /* We're working with a live target. */
9601 /* Set some defaults. */
9602 ts
->running_known
= 0;
9603 ts
->stop_reason
= trace_stop_reason_unknown
;
9604 ts
->traceframe_count
= -1;
9605 ts
->buffer_free
= 0;
9608 error (_("Bogus trace status reply from target: %s"), target_buf
);
9610 parse_trace_status (p
, ts
);
9616 remote_trace_stop ()
9619 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9620 if (strcmp (target_buf
, "OK"))
9621 error (_("Bogus reply from target: %s"), target_buf
);
9625 remote_trace_find (enum trace_find_type type
, int num
,
9626 ULONGEST addr1
, ULONGEST addr2
,
9629 struct remote_state
*rs
= get_remote_state ();
9631 int target_frameno
= -1, target_tracept
= -1;
9634 strcpy (p
, "QTFrame:");
9635 p
= strchr (p
, '\0');
9639 sprintf (p
, "%x", num
);
9642 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
9645 sprintf (p
, "tdp:%x", num
);
9648 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9651 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9654 error ("Unknown trace find type %d", type
);
9658 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
9660 while (reply
&& *reply
)
9665 target_frameno
= (int) strtol (p
, &reply
, 16);
9667 error (_("Unable to parse trace frame number"));
9668 if (target_frameno
== -1)
9673 target_tracept
= (int) strtol (p
, &reply
, 16);
9675 error (_("Unable to parse tracepoint number"));
9677 case 'O': /* "OK"? */
9678 if (reply
[1] == 'K' && reply
[2] == '\0')
9681 error (_("Bogus reply from target: %s"), reply
);
9684 error (_("Bogus reply from target: %s"), reply
);
9687 *tpp
= target_tracept
;
9688 return target_frameno
;
9692 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
9694 struct remote_state
*rs
= get_remote_state ();
9698 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
9700 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9701 if (reply
&& *reply
)
9705 unpack_varlen_hex (reply
+ 1, &uval
);
9706 *val
= (LONGEST
) uval
;
9714 remote_save_trace_data (const char *filename
)
9716 struct remote_state
*rs
= get_remote_state ();
9720 strcpy (p
, "QTSave:");
9722 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
9723 error (_("Remote file name too long for trace save packet"));
9724 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
9727 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9731 /* This is basically a memory transfer, but needs to be its own packet
9732 because we don't know how the target actually organizes its trace
9733 memory, plus we want to be able to ask for as much as possible, but
9734 not be unhappy if we don't get as much as we ask for. */
9737 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
9739 struct remote_state
*rs
= get_remote_state ();
9745 strcpy (p
, "qTBuffer:");
9747 p
+= hexnumstr (p
, offset
);
9749 p
+= hexnumstr (p
, len
);
9753 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9754 if (reply
&& *reply
)
9756 /* 'l' by itself means we're at the end of the buffer and
9757 there is nothing more to get. */
9761 /* Convert the reply into binary. Limit the number of bytes to
9762 convert according to our passed-in buffer size, rather than
9763 what was returned in the packet; if the target is
9764 unexpectedly generous and gives us a bigger reply than we
9765 asked for, we don't want to crash. */
9766 rslt
= hex2bin (target_buf
, buf
, len
);
9770 /* Something went wrong, flag as an error. */
9775 remote_set_disconnected_tracing (int val
)
9777 struct remote_state
*rs
= get_remote_state ();
9779 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
9781 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9782 if (strcmp (target_buf
, "OK"))
9783 error (_("Target does not support this command."));
9787 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
9789 struct thread_info
*info
= find_thread_ptid (ptid
);
9790 if (info
&& info
->private)
9791 return info
->private->core
;
9796 remote_set_circular_trace_buffer (int val
)
9798 struct remote_state
*rs
= get_remote_state ();
9800 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
9802 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9803 if (strcmp (target_buf
, "OK"))
9804 error (_("Target does not support this command."));
9808 init_remote_ops (void)
9810 remote_ops
.to_shortname
= "remote";
9811 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
9813 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9814 Specify the serial device it is connected to\n\
9815 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
9816 remote_ops
.to_open
= remote_open
;
9817 remote_ops
.to_close
= remote_close
;
9818 remote_ops
.to_detach
= remote_detach
;
9819 remote_ops
.to_disconnect
= remote_disconnect
;
9820 remote_ops
.to_resume
= remote_resume
;
9821 remote_ops
.to_wait
= remote_wait
;
9822 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
9823 remote_ops
.to_store_registers
= remote_store_registers
;
9824 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
9825 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
9826 remote_ops
.to_files_info
= remote_files_info
;
9827 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
9828 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
9829 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
9830 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
9831 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
9832 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
9833 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
9834 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
9835 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
9836 remote_ops
.to_kill
= remote_kill
;
9837 remote_ops
.to_load
= generic_load
;
9838 remote_ops
.to_mourn_inferior
= remote_mourn
;
9839 remote_ops
.to_thread_alive
= remote_thread_alive
;
9840 remote_ops
.to_find_new_threads
= remote_threads_info
;
9841 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
9842 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
9843 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
9844 remote_ops
.to_stop
= remote_stop
;
9845 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
9846 remote_ops
.to_rcmd
= remote_rcmd
;
9847 remote_ops
.to_log_command
= serial_log_command
;
9848 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
9849 remote_ops
.to_stratum
= process_stratum
;
9850 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
9851 remote_ops
.to_has_memory
= default_child_has_memory
;
9852 remote_ops
.to_has_stack
= default_child_has_stack
;
9853 remote_ops
.to_has_registers
= default_child_has_registers
;
9854 remote_ops
.to_has_execution
= default_child_has_execution
;
9855 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
9856 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
9857 remote_ops
.to_magic
= OPS_MAGIC
;
9858 remote_ops
.to_memory_map
= remote_memory_map
;
9859 remote_ops
.to_flash_erase
= remote_flash_erase
;
9860 remote_ops
.to_flash_done
= remote_flash_done
;
9861 remote_ops
.to_read_description
= remote_read_description
;
9862 remote_ops
.to_search_memory
= remote_search_memory
;
9863 remote_ops
.to_can_async_p
= remote_can_async_p
;
9864 remote_ops
.to_is_async_p
= remote_is_async_p
;
9865 remote_ops
.to_async
= remote_async
;
9866 remote_ops
.to_async_mask
= remote_async_mask
;
9867 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
9868 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
9869 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
9870 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
9871 remote_ops
.to_trace_init
= remote_trace_init
;
9872 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
9873 remote_ops
.to_download_trace_state_variable
= remote_download_trace_state_variable
;
9874 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
9875 remote_ops
.to_trace_start
= remote_trace_start
;
9876 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
9877 remote_ops
.to_trace_stop
= remote_trace_stop
;
9878 remote_ops
.to_trace_find
= remote_trace_find
;
9879 remote_ops
.to_get_trace_state_variable_value
= remote_get_trace_state_variable_value
;
9880 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
9881 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
9882 remote_ops
.to_upload_trace_state_variables
= remote_upload_trace_state_variables
;
9883 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
9884 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
9885 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
9886 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
9887 remote_ops
.to_verify_memory
= remote_verify_memory
;
9890 /* Set up the extended remote vector by making a copy of the standard
9891 remote vector and adding to it. */
9894 init_extended_remote_ops (void)
9896 extended_remote_ops
= remote_ops
;
9898 extended_remote_ops
.to_shortname
= "extended-remote";
9899 extended_remote_ops
.to_longname
=
9900 "Extended remote serial target in gdb-specific protocol";
9901 extended_remote_ops
.to_doc
=
9902 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9903 Specify the serial device it is connected to (e.g. /dev/ttya).";
9904 extended_remote_ops
.to_open
= extended_remote_open
;
9905 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
9906 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
9907 extended_remote_ops
.to_detach
= extended_remote_detach
;
9908 extended_remote_ops
.to_attach
= extended_remote_attach
;
9909 extended_remote_ops
.to_kill
= extended_remote_kill
;
9913 remote_can_async_p (void)
9915 if (!target_async_permitted
)
9916 /* We only enable async when the user specifically asks for it. */
9919 /* We're async whenever the serial device is. */
9920 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
9924 remote_is_async_p (void)
9926 if (!target_async_permitted
)
9927 /* We only enable async when the user specifically asks for it. */
9930 /* We're async whenever the serial device is. */
9931 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
9934 /* Pass the SERIAL event on and up to the client. One day this code
9935 will be able to delay notifying the client of an event until the
9936 point where an entire packet has been received. */
9938 static void (*async_client_callback
) (enum inferior_event_type event_type
,
9940 static void *async_client_context
;
9941 static serial_event_ftype remote_async_serial_handler
;
9944 remote_async_serial_handler (struct serial
*scb
, void *context
)
9946 /* Don't propogate error information up to the client. Instead let
9947 the client find out about the error by querying the target. */
9948 async_client_callback (INF_REG_EVENT
, async_client_context
);
9952 remote_async_inferior_event_handler (gdb_client_data data
)
9954 inferior_event_handler (INF_REG_EVENT
, NULL
);
9958 remote_async_get_pending_events_handler (gdb_client_data data
)
9960 remote_get_pending_stop_replies ();
9964 remote_async (void (*callback
) (enum inferior_event_type event_type
,
9965 void *context
), void *context
)
9967 if (remote_async_mask_value
== 0)
9968 internal_error (__FILE__
, __LINE__
,
9969 _("Calling remote_async when async is masked"));
9971 if (callback
!= NULL
)
9973 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
9974 async_client_callback
= callback
;
9975 async_client_context
= context
;
9978 serial_async (remote_desc
, NULL
, NULL
);
9982 remote_async_mask (int new_mask
)
9984 int curr_mask
= remote_async_mask_value
;
9985 remote_async_mask_value
= new_mask
;
9990 set_remote_cmd (char *args
, int from_tty
)
9992 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
9996 show_remote_cmd (char *args
, int from_tty
)
9998 /* We can't just use cmd_show_list here, because we want to skip
9999 the redundant "show remote Z-packet" and the legacy aliases. */
10000 struct cleanup
*showlist_chain
;
10001 struct cmd_list_element
*list
= remote_show_cmdlist
;
10003 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10004 for (; list
!= NULL
; list
= list
->next
)
10005 if (strcmp (list
->name
, "Z-packet") == 0)
10007 else if (list
->type
== not_set_cmd
)
10008 /* Alias commands are exactly like the original, except they
10009 don't have the normal type. */
10013 struct cleanup
*option_chain
10014 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10015 ui_out_field_string (uiout
, "name", list
->name
);
10016 ui_out_text (uiout
, ": ");
10017 if (list
->type
== show_cmd
)
10018 do_setshow_command ((char *) NULL
, from_tty
, list
);
10020 cmd_func (list
, NULL
, from_tty
);
10021 /* Close the tuple. */
10022 do_cleanups (option_chain
);
10025 /* Close the tuple. */
10026 do_cleanups (showlist_chain
);
10030 /* Function to be called whenever a new objfile (shlib) is detected. */
10032 remote_new_objfile (struct objfile
*objfile
)
10034 if (remote_desc
!= 0) /* Have a remote connection. */
10035 remote_check_symbols (objfile
);
10038 /* Pull all the tracepoints defined on the target and create local
10039 data structures representing them. We don't want to create real
10040 tracepoints yet, we don't want to mess up the user's existing
10044 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10046 struct remote_state
*rs
= get_remote_state ();
10049 /* Ask for a first packet of tracepoint definition. */
10051 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10053 while (*p
&& *p
!= 'l')
10055 parse_tracepoint_definition (p
, utpp
);
10056 /* Ask for another packet of tracepoint definition. */
10058 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10065 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10067 struct remote_state
*rs
= get_remote_state ();
10070 /* Ask for a first packet of variable definition. */
10072 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10074 while (*p
&& *p
!= 'l')
10076 parse_tsv_definition (p
, utsvp
);
10077 /* Ask for another packet of variable definition. */
10079 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10086 _initialize_remote (void)
10088 struct remote_state
*rs
;
10089 struct cmd_list_element
*cmd
;
10092 /* architecture specific data */
10093 remote_gdbarch_data_handle
=
10094 gdbarch_data_register_post_init (init_remote_state
);
10095 remote_g_packet_data_handle
=
10096 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10098 /* Initialize the per-target state. At the moment there is only one
10099 of these, not one per target. Only one target is active at a
10100 time. The default buffer size is unimportant; it will be expanded
10101 whenever a larger buffer is needed. */
10102 rs
= get_remote_state_raw ();
10103 rs
->buf_size
= 400;
10104 rs
->buf
= xmalloc (rs
->buf_size
);
10106 init_remote_ops ();
10107 add_target (&remote_ops
);
10109 init_extended_remote_ops ();
10110 add_target (&extended_remote_ops
);
10112 /* Hook into new objfile notification. */
10113 observer_attach_new_objfile (remote_new_objfile
);
10115 /* Set up signal handlers. */
10116 sigint_remote_token
=
10117 create_async_signal_handler (async_remote_interrupt
, NULL
);
10118 sigint_remote_twice_token
=
10119 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
10122 init_remote_threadtests ();
10125 /* set/show remote ... */
10127 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10128 Remote protocol specific variables\n\
10129 Configure various remote-protocol specific variables such as\n\
10130 the packets being used"),
10131 &remote_set_cmdlist
, "set remote ",
10132 0 /* allow-unknown */, &setlist
);
10133 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10134 Remote protocol specific variables\n\
10135 Configure various remote-protocol specific variables such as\n\
10136 the packets being used"),
10137 &remote_show_cmdlist
, "show remote ",
10138 0 /* allow-unknown */, &showlist
);
10140 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10141 Compare section data on target to the exec file.\n\
10142 Argument is a single section name (default: all loaded sections)."),
10145 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10146 Send an arbitrary packet to a remote target.\n\
10147 maintenance packet TEXT\n\
10148 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10149 this command sends the string TEXT to the inferior, and displays the\n\
10150 response packet. GDB supplies the initial `$' character, and the\n\
10151 terminating `#' character and checksum."),
10154 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10155 Set whether to send break if interrupted."), _("\
10156 Show whether to send break if interrupted."), _("\
10157 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10158 set_remotebreak
, show_remotebreak
,
10159 &setlist
, &showlist
);
10160 cmd_name
= "remotebreak";
10161 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10162 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10163 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10164 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10165 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10167 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10168 interrupt_sequence_modes
, &interrupt_sequence_mode
, _("\
10169 Set interrupt sequence to remote target."), _("\
10170 Show interrupt sequence to remote target."), _("\
10171 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10172 NULL
, show_interrupt_sequence
,
10173 &remote_set_cmdlist
,
10174 &remote_show_cmdlist
);
10176 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10177 &interrupt_on_connect
, _("\
10178 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10179 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10180 If set, interrupt sequence is sent to remote target."),
10182 &remote_set_cmdlist
, &remote_show_cmdlist
);
10184 /* Install commands for configuring memory read/write packets. */
10186 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10187 Set the maximum number of bytes per memory write packet (deprecated)."),
10189 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10190 Show the maximum number of bytes per memory write packet (deprecated)."),
10192 add_cmd ("memory-write-packet-size", no_class
,
10193 set_memory_write_packet_size
, _("\
10194 Set the maximum number of bytes per memory-write packet.\n\
10195 Specify the number of bytes in a packet or 0 (zero) for the\n\
10196 default packet size. The actual limit is further reduced\n\
10197 dependent on the target. Specify ``fixed'' to disable the\n\
10198 further restriction and ``limit'' to enable that restriction."),
10199 &remote_set_cmdlist
);
10200 add_cmd ("memory-read-packet-size", no_class
,
10201 set_memory_read_packet_size
, _("\
10202 Set the maximum number of bytes per memory-read packet.\n\
10203 Specify the number of bytes in a packet or 0 (zero) for the\n\
10204 default packet size. The actual limit is further reduced\n\
10205 dependent on the target. Specify ``fixed'' to disable the\n\
10206 further restriction and ``limit'' to enable that restriction."),
10207 &remote_set_cmdlist
);
10208 add_cmd ("memory-write-packet-size", no_class
,
10209 show_memory_write_packet_size
,
10210 _("Show the maximum number of bytes per memory-write packet."),
10211 &remote_show_cmdlist
);
10212 add_cmd ("memory-read-packet-size", no_class
,
10213 show_memory_read_packet_size
,
10214 _("Show the maximum number of bytes per memory-read packet."),
10215 &remote_show_cmdlist
);
10217 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10218 &remote_hw_watchpoint_limit
, _("\
10219 Set the maximum number of target hardware watchpoints."), _("\
10220 Show the maximum number of target hardware watchpoints."), _("\
10221 Specify a negative limit for unlimited."),
10222 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
10223 &remote_set_cmdlist
, &remote_show_cmdlist
);
10224 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10225 &remote_hw_breakpoint_limit
, _("\
10226 Set the maximum number of target hardware breakpoints."), _("\
10227 Show the maximum number of target hardware breakpoints."), _("\
10228 Specify a negative limit for unlimited."),
10229 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
10230 &remote_set_cmdlist
, &remote_show_cmdlist
);
10232 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10233 &remote_address_size
, _("\
10234 Set the maximum size of the address (in bits) in a memory packet."), _("\
10235 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10237 NULL
, /* FIXME: i18n: */
10238 &setlist
, &showlist
);
10240 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10241 "X", "binary-download", 1);
10243 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10244 "vCont", "verbose-resume", 0);
10246 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10247 "QPassSignals", "pass-signals", 0);
10249 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10250 "qSymbol", "symbol-lookup", 0);
10252 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10253 "P", "set-register", 1);
10255 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10256 "p", "fetch-register", 1);
10258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10259 "Z0", "software-breakpoint", 0);
10261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10262 "Z1", "hardware-breakpoint", 0);
10264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10265 "Z2", "write-watchpoint", 0);
10267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10268 "Z3", "read-watchpoint", 0);
10270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10271 "Z4", "access-watchpoint", 0);
10273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10274 "qXfer:auxv:read", "read-aux-vector", 0);
10276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10277 "qXfer:features:read", "target-features", 0);
10279 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10280 "qXfer:libraries:read", "library-info", 0);
10282 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10283 "qXfer:memory-map:read", "memory-map", 0);
10285 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10286 "qXfer:spu:read", "read-spu-object", 0);
10288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10289 "qXfer:spu:write", "write-spu-object", 0);
10291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10292 "qXfer:osdata:read", "osdata", 0);
10294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10295 "qXfer:threads:read", "threads", 0);
10297 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10298 "qXfer:siginfo:read", "read-siginfo-object", 0);
10300 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
10301 "qXfer:siginfo:write", "write-siginfo-object", 0);
10303 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
10304 "qGetTLSAddr", "get-thread-local-storage-address",
10307 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
10308 "bc", "reverse-continue", 0);
10310 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
10311 "bs", "reverse-step", 0);
10313 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
10314 "qSupported", "supported-packets", 0);
10316 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
10317 "qSearch:memory", "search-memory", 0);
10319 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
10320 "vFile:open", "hostio-open", 0);
10322 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
10323 "vFile:pread", "hostio-pread", 0);
10325 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
10326 "vFile:pwrite", "hostio-pwrite", 0);
10328 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
10329 "vFile:close", "hostio-close", 0);
10331 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
10332 "vFile:unlink", "hostio-unlink", 0);
10334 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
10335 "vAttach", "attach", 0);
10337 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
10340 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
10341 "QStartNoAckMode", "noack", 0);
10343 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
10344 "vKill", "kill", 0);
10346 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
10347 "qAttached", "query-attached", 0);
10349 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
10350 "ConditionalTracepoints", "conditional-tracepoints", 0);
10351 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
10352 "FastTracepoints", "fast-tracepoints", 0);
10354 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
10355 "TracepointSource", "TracepointSource", 0);
10357 /* Keep the old ``set remote Z-packet ...'' working. Each individual
10358 Z sub-packet has its own set and show commands, but users may
10359 have sets to this variable in their .gdbinit files (or in their
10361 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
10362 &remote_Z_packet_detect
, _("\
10363 Set use of remote protocol `Z' packets"), _("\
10364 Show use of remote protocol `Z' packets "), _("\
10365 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
10367 set_remote_protocol_Z_packet_cmd
,
10368 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
10369 &remote_set_cmdlist
, &remote_show_cmdlist
);
10371 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
10372 Manipulate files on the remote system\n\
10373 Transfer files to and from the remote target system."),
10374 &remote_cmdlist
, "remote ",
10375 0 /* allow-unknown */, &cmdlist
);
10377 add_cmd ("put", class_files
, remote_put_command
,
10378 _("Copy a local file to the remote system."),
10381 add_cmd ("get", class_files
, remote_get_command
,
10382 _("Copy a remote file to the local system."),
10385 add_cmd ("delete", class_files
, remote_delete_command
,
10386 _("Delete a remote file."),
10389 remote_exec_file
= xstrdup ("");
10390 add_setshow_string_noescape_cmd ("exec-file", class_files
,
10391 &remote_exec_file
, _("\
10392 Set the remote pathname for \"run\""), _("\
10393 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
10394 &remote_set_cmdlist
, &remote_show_cmdlist
);
10396 /* Eventually initialize fileio. See fileio.c */
10397 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
10399 /* Take advantage of the fact that the LWP field is not used, to tag
10400 special ptids with it set to != 0. */
10401 magic_null_ptid
= ptid_build (42000, 1, -1);
10402 not_sent_ptid
= ptid_build (42000, 1, -2);
10403 any_thread_ptid
= ptid_build (42000, 1, 0);
10405 target_buf_size
= 2048;
10406 target_buf
= xmalloc (target_buf_size
);