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 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"
64 #include "memory-map.h"
66 /* The size to align memory write packets, when practical. The protocol
67 does not guarantee any alignment, and gdb will generate short
68 writes and unaligned writes, but even as a best-effort attempt this
69 can improve bulk transfers. For instance, if a write is misaligned
70 relative to the target's data bus, the stub may need to make an extra
71 round trip fetching data from the target. This doesn't make a
72 huge difference, but it's easy to do, so we try to be helpful.
74 The alignment chosen is arbitrary; usually data bus width is
75 important here, not the possibly larger cache line size. */
76 enum { REMOTE_ALIGN_WRITES
= 16 };
78 /* Prototypes for local functions. */
79 static void cleanup_sigint_signal_handler (void *dummy
);
80 static void initialize_sigint_signal_handler (void);
81 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
82 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
85 static void handle_remote_sigint (int);
86 static void handle_remote_sigint_twice (int);
87 static void async_remote_interrupt (gdb_client_data
);
88 void async_remote_interrupt_twice (gdb_client_data
);
90 static void remote_files_info (struct target_ops
*ignore
);
92 static void remote_prepare_to_store (struct regcache
*regcache
);
94 static void remote_open (char *name
, int from_tty
);
96 static void extended_remote_open (char *name
, int from_tty
);
98 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
100 static void remote_close (int quitting
);
102 static void remote_mourn (struct target_ops
*ops
);
104 static void extended_remote_restart (void);
106 static void extended_remote_mourn (struct target_ops
*);
108 static void remote_mourn_1 (struct target_ops
*);
110 static void remote_send (char **buf
, long *sizeof_buf_p
);
112 static int readchar (int timeout
);
114 static void remote_kill (struct target_ops
*ops
);
116 static int tohex (int nib
);
118 static int remote_can_async_p (void);
120 static int remote_is_async_p (void);
122 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
123 void *context
), void *context
);
125 static int remote_async_mask (int new_mask
);
127 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
129 static void remote_interrupt (int signo
);
131 static void remote_interrupt_twice (int signo
);
133 static void interrupt_query (void);
135 static void set_general_thread (struct ptid ptid
);
136 static void set_continue_thread (struct ptid ptid
);
138 static void get_offsets (void);
140 static void skip_frame (void);
142 static long read_frame (char **buf_p
, long *sizeof_buf
);
144 static int hexnumlen (ULONGEST num
);
146 static void init_remote_ops (void);
148 static void init_extended_remote_ops (void);
150 static void remote_stop (ptid_t
);
152 static int ishex (int ch
, int *val
);
154 static int stubhex (int ch
);
156 static int hexnumstr (char *, ULONGEST
);
158 static int hexnumnstr (char *, ULONGEST
, int);
160 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
162 static void print_packet (char *);
164 static unsigned long crc32 (unsigned char *, int, unsigned int);
166 static void compare_sections_command (char *, int);
168 static void packet_command (char *, int);
170 static int stub_unpack_int (char *buff
, int fieldlength
);
172 static ptid_t
remote_current_thread (ptid_t oldptid
);
174 static void remote_find_new_threads (void);
176 static void record_currthread (ptid_t currthread
);
178 static int fromhex (int a
);
180 static int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
182 static int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
184 static int putpkt_binary (char *buf
, int cnt
);
186 static void check_binary_download (CORE_ADDR addr
);
188 struct packet_config
;
190 static void show_packet_config_cmd (struct packet_config
*config
);
192 static void update_packet_config (struct packet_config
*config
);
194 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
195 struct cmd_list_element
*c
);
197 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
199 struct cmd_list_element
*c
,
202 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
203 static ptid_t
read_ptid (char *buf
, char **obuf
);
205 static void remote_query_supported (void);
207 static void remote_check_symbols (struct objfile
*objfile
);
209 void _initialize_remote (void);
212 static struct stop_reply
*stop_reply_xmalloc (void);
213 static void stop_reply_xfree (struct stop_reply
*);
214 static void do_stop_reply_xfree (void *arg
);
215 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
216 static void push_stop_reply (struct stop_reply
*);
217 static void remote_get_pending_stop_replies (void);
218 static void discard_pending_stop_replies (int pid
);
219 static int peek_stop_reply (ptid_t ptid
);
221 static void remote_async_inferior_event_handler (gdb_client_data
);
222 static void remote_async_get_pending_events_handler (gdb_client_data
);
224 static void remote_terminal_ours (void);
226 static int remote_read_description_p (struct target_ops
*target
);
228 /* The non-stop remote protocol provisions for one pending stop reply.
229 This is where we keep it until it is acknowledged. */
231 static struct stop_reply
*pending_stop_reply
= NULL
;
235 static struct cmd_list_element
*remote_cmdlist
;
237 /* For "set remote" and "show remote". */
239 static struct cmd_list_element
*remote_set_cmdlist
;
240 static struct cmd_list_element
*remote_show_cmdlist
;
242 /* Description of the remote protocol state for the currently
243 connected target. This is per-target state, and independent of the
244 selected architecture. */
248 /* A buffer to use for incoming packets, and its current size. The
249 buffer is grown dynamically for larger incoming packets.
250 Outgoing packets may also be constructed in this buffer.
251 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
252 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
257 /* If we negotiated packet size explicitly (and thus can bypass
258 heuristics for the largest packet size that will not overflow
259 a buffer in the stub), this will be set to that packet size.
260 Otherwise zero, meaning to use the guessed size. */
261 long explicit_packet_size
;
263 /* remote_wait is normally called when the target is running and
264 waits for a stop reply packet. But sometimes we need to call it
265 when the target is already stopped. We can send a "?" packet
266 and have remote_wait read the response. Or, if we already have
267 the response, we can stash it in BUF and tell remote_wait to
268 skip calling getpkt. This flag is set when BUF contains a
269 stop reply packet and the target is not waiting. */
270 int cached_wait_status
;
272 /* True, if in no ack mode. That is, neither GDB nor the stub will
273 expect acks from each other. The connection is assumed to be
277 /* True if we're connected in extended remote mode. */
280 /* True if the stub reported support for multi-process
282 int multi_process_aware
;
284 /* True if we resumed the target and we're waiting for the target to
285 stop. In the mean time, we can't start another command/query.
286 The remote server wouldn't be ready to process it, so we'd
287 timeout waiting for a reply that would never come and eventually
288 we'd close the connection. This can happen in asynchronous mode
289 because we allow GDB commands while the target is running. */
290 int waiting_for_stop_reply
;
292 /* True if the stub reports support for non-stop mode. */
295 /* True if the stub reports support for vCont;t. */
298 /* True if the stub reports support for conditional tracepoints. */
299 int cond_tracepoints
;
302 /* Returns true if the multi-process extensions are in effect. */
304 remote_multi_process_p (struct remote_state
*rs
)
306 return rs
->extended
&& rs
->multi_process_aware
;
309 /* This data could be associated with a target, but we do not always
310 have access to the current target when we need it, so for now it is
311 static. This will be fine for as long as only one target is in use
313 static struct remote_state remote_state
;
315 static struct remote_state
*
316 get_remote_state_raw (void)
318 return &remote_state
;
321 /* Description of the remote protocol for a given architecture. */
325 long offset
; /* Offset into G packet. */
326 long regnum
; /* GDB's internal register number. */
327 LONGEST pnum
; /* Remote protocol register number. */
328 int in_g_packet
; /* Always part of G packet. */
329 /* long size in bytes; == register_size (target_gdbarch, regnum);
331 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
335 struct remote_arch_state
337 /* Description of the remote protocol registers. */
338 long sizeof_g_packet
;
340 /* Description of the remote protocol registers indexed by REGNUM
341 (making an array gdbarch_num_regs in size). */
342 struct packet_reg
*regs
;
344 /* This is the size (in chars) of the first response to the ``g''
345 packet. It is used as a heuristic when determining the maximum
346 size of memory-read and memory-write packets. A target will
347 typically only reserve a buffer large enough to hold the ``g''
348 packet. The size does not include packet overhead (headers and
350 long actual_register_packet_size
;
352 /* This is the maximum size (in chars) of a non read/write packet.
353 It is also used as a cap on the size of read/write packets. */
354 long remote_packet_size
;
358 /* Handle for retreving the remote protocol data from gdbarch. */
359 static struct gdbarch_data
*remote_gdbarch_data_handle
;
361 static struct remote_arch_state
*
362 get_remote_arch_state (void)
364 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
367 /* Fetch the global remote target state. */
369 static struct remote_state
*
370 get_remote_state (void)
372 /* Make sure that the remote architecture state has been
373 initialized, because doing so might reallocate rs->buf. Any
374 function which calls getpkt also needs to be mindful of changes
375 to rs->buf, but this call limits the number of places which run
377 get_remote_arch_state ();
379 return get_remote_state_raw ();
383 compare_pnums (const void *lhs_
, const void *rhs_
)
385 const struct packet_reg
* const *lhs
= lhs_
;
386 const struct packet_reg
* const *rhs
= rhs_
;
388 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
390 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
397 init_remote_state (struct gdbarch
*gdbarch
)
399 int regnum
, num_remote_regs
, offset
;
400 struct remote_state
*rs
= get_remote_state_raw ();
401 struct remote_arch_state
*rsa
;
402 struct packet_reg
**remote_regs
;
404 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
406 /* Use the architecture to build a regnum<->pnum table, which will be
407 1:1 unless a feature set specifies otherwise. */
408 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
409 gdbarch_num_regs (gdbarch
),
411 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
413 struct packet_reg
*r
= &rsa
->regs
[regnum
];
415 if (register_size (gdbarch
, regnum
) == 0)
416 /* Do not try to fetch zero-sized (placeholder) registers. */
419 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
424 /* Define the g/G packet format as the contents of each register
425 with a remote protocol number, in order of ascending protocol
428 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
429 * sizeof (struct packet_reg
*));
430 for (num_remote_regs
= 0, regnum
= 0;
431 regnum
< gdbarch_num_regs (gdbarch
);
433 if (rsa
->regs
[regnum
].pnum
!= -1)
434 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
436 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
439 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
441 remote_regs
[regnum
]->in_g_packet
= 1;
442 remote_regs
[regnum
]->offset
= offset
;
443 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
446 /* Record the maximum possible size of the g packet - it may turn out
448 rsa
->sizeof_g_packet
= offset
;
450 /* Default maximum number of characters in a packet body. Many
451 remote stubs have a hardwired buffer size of 400 bytes
452 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
453 as the maximum packet-size to ensure that the packet and an extra
454 NUL character can always fit in the buffer. This stops GDB
455 trashing stubs that try to squeeze an extra NUL into what is
456 already a full buffer (As of 1999-12-04 that was most stubs). */
457 rsa
->remote_packet_size
= 400 - 1;
459 /* This one is filled in when a ``g'' packet is received. */
460 rsa
->actual_register_packet_size
= 0;
462 /* Should rsa->sizeof_g_packet needs more space than the
463 default, adjust the size accordingly. Remember that each byte is
464 encoded as two characters. 32 is the overhead for the packet
465 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
466 (``$NN:G...#NN'') is a better guess, the below has been padded a
468 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
469 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
471 /* Make sure that the packet buffer is plenty big enough for
472 this architecture. */
473 if (rs
->buf_size
< rsa
->remote_packet_size
)
475 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
476 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
482 /* Return the current allowed size of a remote packet. This is
483 inferred from the current architecture, and should be used to
484 limit the length of outgoing packets. */
486 get_remote_packet_size (void)
488 struct remote_state
*rs
= get_remote_state ();
489 struct remote_arch_state
*rsa
= get_remote_arch_state ();
491 if (rs
->explicit_packet_size
)
492 return rs
->explicit_packet_size
;
494 return rsa
->remote_packet_size
;
497 static struct packet_reg
*
498 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
500 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
504 struct packet_reg
*r
= &rsa
->regs
[regnum
];
505 gdb_assert (r
->regnum
== regnum
);
510 static struct packet_reg
*
511 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
514 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
516 struct packet_reg
*r
= &rsa
->regs
[i
];
523 /* FIXME: graces/2002-08-08: These variables should eventually be
524 bound to an instance of the target object (as in gdbarch-tdep()),
525 when such a thing exists. */
527 /* This is set to the data address of the access causing the target
528 to stop for a watchpoint. */
529 static CORE_ADDR remote_watch_data_address
;
531 /* This is non-zero if target stopped for a watchpoint. */
532 static int remote_stopped_by_watchpoint_p
;
534 static struct target_ops remote_ops
;
536 static struct target_ops extended_remote_ops
;
538 static int remote_async_mask_value
= 1;
540 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
541 ``forever'' still use the normal timeout mechanism. This is
542 currently used by the ASYNC code to guarentee that target reads
543 during the initial connect always time-out. Once getpkt has been
544 modified to return a timeout indication and, in turn
545 remote_wait()/wait_for_inferior() have gained a timeout parameter
547 static int wait_forever_enabled_p
= 1;
549 /* Allow the user to specify what sequence to send to the remote
550 when he requests a program interruption: Although ^C is usually
551 what remote systems expect (this is the default, here), it is
552 sometimes preferable to send a break. On other systems such
553 as the Linux kernel, a break followed by g, which is Magic SysRq g
554 is required in order to interrupt the execution. */
555 const char interrupt_sequence_control_c
[] = "Ctrl-C";
556 const char interrupt_sequence_break
[] = "BREAK";
557 const char interrupt_sequence_break_g
[] = "BREAK-g";
558 static const char *interrupt_sequence_modes
[] =
560 interrupt_sequence_control_c
,
561 interrupt_sequence_break
,
562 interrupt_sequence_break_g
,
565 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
568 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
569 struct cmd_list_element
*c
,
572 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
573 fprintf_filtered (file
,
574 _("Send the ASCII ETX character (Ctrl-c) "
575 "to the remote target to interrupt the "
576 "execution of the program.\n"));
577 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
578 fprintf_filtered (file
,
579 _("send a break signal to the remote target "
580 "to interrupt the execution of the program.\n"));
581 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
582 fprintf_filtered (file
,
583 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
584 "the remote target to interrupt the execution "
585 "of Linux kernel.\n"));
587 internal_error (__FILE__
, __LINE__
,
588 _("Invalid value for interrupt_sequence_mode: %s."),
589 interrupt_sequence_mode
);
592 /* This boolean variable specifies whether interrupt_sequence is sent
593 to the remote target when gdb connects to it.
594 This is mostly needed when you debug the Linux kernel: The Linux kernel
595 expects BREAK g which is Magic SysRq g for connecting gdb. */
596 static int interrupt_on_connect
= 0;
598 /* This variable is used to implement the "set/show remotebreak" commands.
599 Since these commands are now deprecated in favor of "set/show remote
600 interrupt-sequence", it no longer has any effect on the code. */
601 static int remote_break
;
604 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
607 interrupt_sequence_mode
= interrupt_sequence_break
;
609 interrupt_sequence_mode
= interrupt_sequence_control_c
;
613 show_remotebreak (struct ui_file
*file
, int from_tty
,
614 struct cmd_list_element
*c
,
619 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
620 remote_open knows that we don't have a file open when the program
622 static struct serial
*remote_desc
= NULL
;
624 /* This variable sets the number of bits in an address that are to be
625 sent in a memory ("M" or "m") packet. Normally, after stripping
626 leading zeros, the entire address would be sent. This variable
627 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
628 initial implementation of remote.c restricted the address sent in
629 memory packets to ``host::sizeof long'' bytes - (typically 32
630 bits). Consequently, for 64 bit targets, the upper 32 bits of an
631 address was never sent. Since fixing this bug may cause a break in
632 some remote targets this variable is principly provided to
633 facilitate backward compatibility. */
635 static int remote_address_size
;
637 /* Temporary to track who currently owns the terminal. See
638 remote_terminal_* for more details. */
640 static int remote_async_terminal_ours_p
;
642 /* The executable file to use for "run" on the remote side. */
644 static char *remote_exec_file
= "";
647 /* User configurable variables for the number of characters in a
648 memory read/write packet. MIN (rsa->remote_packet_size,
649 rsa->sizeof_g_packet) is the default. Some targets need smaller
650 values (fifo overruns, et.al.) and some users need larger values
651 (speed up transfers). The variables ``preferred_*'' (the user
652 request), ``current_*'' (what was actually set) and ``forced_*''
653 (Positive - a soft limit, negative - a hard limit). */
655 struct memory_packet_config
662 /* Compute the current size of a read/write packet. Since this makes
663 use of ``actual_register_packet_size'' the computation is dynamic. */
666 get_memory_packet_size (struct memory_packet_config
*config
)
668 struct remote_state
*rs
= get_remote_state ();
669 struct remote_arch_state
*rsa
= get_remote_arch_state ();
671 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
672 law?) that some hosts don't cope very well with large alloca()
673 calls. Eventually the alloca() code will be replaced by calls to
674 xmalloc() and make_cleanups() allowing this restriction to either
675 be lifted or removed. */
676 #ifndef MAX_REMOTE_PACKET_SIZE
677 #define MAX_REMOTE_PACKET_SIZE 16384
679 /* NOTE: 20 ensures we can write at least one byte. */
680 #ifndef MIN_REMOTE_PACKET_SIZE
681 #define MIN_REMOTE_PACKET_SIZE 20
686 if (config
->size
<= 0)
687 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
689 what_they_get
= config
->size
;
693 what_they_get
= get_remote_packet_size ();
694 /* Limit the packet to the size specified by the user. */
696 && what_they_get
> config
->size
)
697 what_they_get
= config
->size
;
699 /* Limit it to the size of the targets ``g'' response unless we have
700 permission from the stub to use a larger packet size. */
701 if (rs
->explicit_packet_size
== 0
702 && rsa
->actual_register_packet_size
> 0
703 && what_they_get
> rsa
->actual_register_packet_size
)
704 what_they_get
= rsa
->actual_register_packet_size
;
706 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
707 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
708 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
709 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
711 /* Make sure there is room in the global buffer for this packet
712 (including its trailing NUL byte). */
713 if (rs
->buf_size
< what_they_get
+ 1)
715 rs
->buf_size
= 2 * what_they_get
;
716 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
719 return what_they_get
;
722 /* Update the size of a read/write packet. If they user wants
723 something really big then do a sanity check. */
726 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
728 int fixed_p
= config
->fixed_p
;
729 long size
= config
->size
;
731 error (_("Argument required (integer, `fixed' or `limited')."));
732 else if (strcmp (args
, "hard") == 0
733 || strcmp (args
, "fixed") == 0)
735 else if (strcmp (args
, "soft") == 0
736 || strcmp (args
, "limit") == 0)
741 size
= strtoul (args
, &end
, 0);
743 error (_("Invalid %s (bad syntax)."), config
->name
);
745 /* Instead of explicitly capping the size of a packet to
746 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
747 instead allowed to set the size to something arbitrarily
749 if (size
> MAX_REMOTE_PACKET_SIZE
)
750 error (_("Invalid %s (too large)."), config
->name
);
754 if (fixed_p
&& !config
->fixed_p
)
756 if (! query (_("The target may not be able to correctly handle a %s\n"
757 "of %ld bytes. Change the packet size? "),
759 error (_("Packet size not changed."));
761 /* Update the config. */
762 config
->fixed_p
= fixed_p
;
767 show_memory_packet_size (struct memory_packet_config
*config
)
769 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
771 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
772 get_memory_packet_size (config
));
774 printf_filtered (_("Packets are limited to %ld bytes.\n"),
775 get_memory_packet_size (config
));
778 static struct memory_packet_config memory_write_packet_config
=
780 "memory-write-packet-size",
784 set_memory_write_packet_size (char *args
, int from_tty
)
786 set_memory_packet_size (args
, &memory_write_packet_config
);
790 show_memory_write_packet_size (char *args
, int from_tty
)
792 show_memory_packet_size (&memory_write_packet_config
);
796 get_memory_write_packet_size (void)
798 return get_memory_packet_size (&memory_write_packet_config
);
801 static struct memory_packet_config memory_read_packet_config
=
803 "memory-read-packet-size",
807 set_memory_read_packet_size (char *args
, int from_tty
)
809 set_memory_packet_size (args
, &memory_read_packet_config
);
813 show_memory_read_packet_size (char *args
, int from_tty
)
815 show_memory_packet_size (&memory_read_packet_config
);
819 get_memory_read_packet_size (void)
821 long size
= get_memory_packet_size (&memory_read_packet_config
);
822 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
823 extra buffer size argument before the memory read size can be
824 increased beyond this. */
825 if (size
> get_remote_packet_size ())
826 size
= get_remote_packet_size ();
831 /* Generic configuration support for packets the stub optionally
832 supports. Allows the user to specify the use of the packet as well
833 as allowing GDB to auto-detect support in the remote stub. */
837 PACKET_SUPPORT_UNKNOWN
= 0,
846 enum auto_boolean detect
;
847 enum packet_support support
;
850 /* Analyze a packet's return value and update the packet config
861 update_packet_config (struct packet_config
*config
)
863 switch (config
->detect
)
865 case AUTO_BOOLEAN_TRUE
:
866 config
->support
= PACKET_ENABLE
;
868 case AUTO_BOOLEAN_FALSE
:
869 config
->support
= PACKET_DISABLE
;
871 case AUTO_BOOLEAN_AUTO
:
872 config
->support
= PACKET_SUPPORT_UNKNOWN
;
878 show_packet_config_cmd (struct packet_config
*config
)
880 char *support
= "internal-error";
881 switch (config
->support
)
887 support
= "disabled";
889 case PACKET_SUPPORT_UNKNOWN
:
893 switch (config
->detect
)
895 case AUTO_BOOLEAN_AUTO
:
896 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
897 config
->name
, support
);
899 case AUTO_BOOLEAN_TRUE
:
900 case AUTO_BOOLEAN_FALSE
:
901 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
902 config
->name
, support
);
908 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
909 const char *title
, int legacy
)
916 config
->title
= title
;
917 config
->detect
= AUTO_BOOLEAN_AUTO
;
918 config
->support
= PACKET_SUPPORT_UNKNOWN
;
919 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
921 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
923 /* set/show TITLE-packet {auto,on,off} */
924 cmd_name
= xstrprintf ("%s-packet", title
);
925 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
926 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
927 set_remote_protocol_packet_cmd
,
928 show_remote_protocol_packet_cmd
,
929 &remote_set_cmdlist
, &remote_show_cmdlist
);
930 /* The command code copies the documentation strings. */
933 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
937 legacy_name
= xstrprintf ("%s-packet", name
);
938 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
939 &remote_set_cmdlist
);
940 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
941 &remote_show_cmdlist
);
945 static enum packet_result
946 packet_check_result (const char *buf
)
950 /* The stub recognized the packet request. Check that the
951 operation succeeded. */
953 && isxdigit (buf
[1]) && isxdigit (buf
[2])
955 /* "Enn" - definitly an error. */
958 /* Always treat "E." as an error. This will be used for
959 more verbose error messages, such as E.memtypes. */
960 if (buf
[0] == 'E' && buf
[1] == '.')
963 /* The packet may or may not be OK. Just assume it is. */
967 /* The stub does not support the packet. */
968 return PACKET_UNKNOWN
;
971 static enum packet_result
972 packet_ok (const char *buf
, struct packet_config
*config
)
974 enum packet_result result
;
976 result
= packet_check_result (buf
);
981 /* The stub recognized the packet request. */
982 switch (config
->support
)
984 case PACKET_SUPPORT_UNKNOWN
:
986 fprintf_unfiltered (gdb_stdlog
,
987 "Packet %s (%s) is supported\n",
988 config
->name
, config
->title
);
989 config
->support
= PACKET_ENABLE
;
992 internal_error (__FILE__
, __LINE__
,
993 _("packet_ok: attempt to use a disabled packet"));
1000 /* The stub does not support the packet. */
1001 switch (config
->support
)
1004 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1005 /* If the stub previously indicated that the packet was
1006 supported then there is a protocol error.. */
1007 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1008 config
->name
, config
->title
);
1010 /* The user set it wrong. */
1011 error (_("Enabled packet %s (%s) not recognized by stub"),
1012 config
->name
, config
->title
);
1014 case PACKET_SUPPORT_UNKNOWN
:
1016 fprintf_unfiltered (gdb_stdlog
,
1017 "Packet %s (%s) is NOT supported\n",
1018 config
->name
, config
->title
);
1019 config
->support
= PACKET_DISABLE
;
1021 case PACKET_DISABLE
:
1043 PACKET_vFile_pwrite
,
1045 PACKET_vFile_unlink
,
1047 PACKET_qXfer_features
,
1048 PACKET_qXfer_libraries
,
1049 PACKET_qXfer_memory_map
,
1050 PACKET_qXfer_spu_read
,
1051 PACKET_qXfer_spu_write
,
1052 PACKET_qXfer_osdata
,
1055 PACKET_QPassSignals
,
1056 PACKET_qSearch_memory
,
1059 PACKET_QStartNoAckMode
,
1061 PACKET_qXfer_siginfo_read
,
1062 PACKET_qXfer_siginfo_write
,
1064 PACKET_ConditionalTracepoints
,
1070 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1073 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1074 struct cmd_list_element
*c
)
1076 struct packet_config
*packet
;
1078 for (packet
= remote_protocol_packets
;
1079 packet
< &remote_protocol_packets
[PACKET_MAX
];
1082 if (&packet
->detect
== c
->var
)
1084 update_packet_config (packet
);
1088 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1093 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1094 struct cmd_list_element
*c
,
1097 struct packet_config
*packet
;
1099 for (packet
= remote_protocol_packets
;
1100 packet
< &remote_protocol_packets
[PACKET_MAX
];
1103 if (&packet
->detect
== c
->var
)
1105 show_packet_config_cmd (packet
);
1109 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1113 /* Should we try one of the 'Z' requests? */
1117 Z_PACKET_SOFTWARE_BP
,
1118 Z_PACKET_HARDWARE_BP
,
1125 /* For compatibility with older distributions. Provide a ``set remote
1126 Z-packet ...'' command that updates all the Z packet types. */
1128 static enum auto_boolean remote_Z_packet_detect
;
1131 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1132 struct cmd_list_element
*c
)
1135 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1137 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1138 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1143 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1144 struct cmd_list_element
*c
,
1148 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1150 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1154 /* Should we try the 'ThreadInfo' query packet?
1156 This variable (NOT available to the user: auto-detect only!)
1157 determines whether GDB will use the new, simpler "ThreadInfo"
1158 query or the older, more complex syntax for thread queries.
1159 This is an auto-detect variable (set to true at each connect,
1160 and set to false when the target fails to recognize it). */
1162 static int use_threadinfo_query
;
1163 static int use_threadextra_query
;
1165 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1166 static struct async_signal_handler
*sigint_remote_twice_token
;
1167 static struct async_signal_handler
*sigint_remote_token
;
1170 /* Asynchronous signal handle registered as event loop source for
1171 when we have pending events ready to be passed to the core. */
1173 static struct async_event_handler
*remote_async_inferior_event_token
;
1175 /* Asynchronous signal handle registered as event loop source for when
1176 the remote sent us a %Stop notification. The registered callback
1177 will do a vStopped sequence to pull the rest of the events out of
1178 the remote side into our event queue. */
1180 static struct async_event_handler
*remote_async_get_pending_events_token
;
1183 static ptid_t magic_null_ptid
;
1184 static ptid_t not_sent_ptid
;
1185 static ptid_t any_thread_ptid
;
1187 /* These are the threads which we last sent to the remote system. The
1188 TID member will be -1 for all or -2 for not sent yet. */
1190 static ptid_t general_thread
;
1191 static ptid_t continue_thread
;
1193 /* Find out if the stub attached to PID (and hence GDB should offer to
1194 detach instead of killing it when bailing out). */
1197 remote_query_attached (int pid
)
1199 struct remote_state
*rs
= get_remote_state ();
1201 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1204 if (remote_multi_process_p (rs
))
1205 sprintf (rs
->buf
, "qAttached:%x", pid
);
1207 sprintf (rs
->buf
, "qAttached");
1210 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1212 switch (packet_ok (rs
->buf
,
1213 &remote_protocol_packets
[PACKET_qAttached
]))
1216 if (strcmp (rs
->buf
, "1") == 0)
1220 warning (_("Remote failure reply: %s"), rs
->buf
);
1222 case PACKET_UNKNOWN
:
1229 /* Add PID to GDB's inferior table. Since we can be connected to a
1230 remote system before before knowing about any inferior, mark the
1231 target with execution when we find the first inferior. If ATTACHED
1232 is 1, then we had just attached to this inferior. If it is 0, then
1233 we just created this inferior. If it is -1, then try querying the
1234 remote stub to find out if it had attached to the inferior or
1237 static struct inferior
*
1238 remote_add_inferior (int pid
, int attached
)
1240 struct inferior
*inf
;
1242 /* Check whether this process we're learning about is to be
1243 considered attached, or if is to be considered to have been
1244 spawned by the stub. */
1246 attached
= remote_query_attached (pid
);
1248 if (gdbarch_has_global_solist (target_gdbarch
))
1250 /* If the target shares code across all inferiors, then every
1251 attach adds a new inferior. */
1252 inf
= add_inferior (pid
);
1254 /* ... and every inferior is bound to the same program space.
1255 However, each inferior may still have its own address
1257 inf
->aspace
= maybe_new_address_space ();
1258 inf
->pspace
= current_program_space
;
1262 /* In the traditional debugging scenario, there's a 1-1 match
1263 between program/address spaces. We simply bind the inferior
1264 to the program space's address space. */
1265 inf
= current_inferior ();
1266 inferior_appeared (inf
, pid
);
1269 inf
->attach_flag
= attached
;
1274 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1275 according to RUNNING. */
1278 remote_add_thread (ptid_t ptid
, int running
)
1282 set_executing (ptid
, running
);
1283 set_running (ptid
, running
);
1286 /* Come here when we learn about a thread id from the remote target.
1287 It may be the first time we hear about such thread, so take the
1288 opportunity to add it to GDB's thread list. In case this is the
1289 first time we're noticing its corresponding inferior, add it to
1290 GDB's inferior list as well. */
1293 remote_notice_new_inferior (ptid_t currthread
, int running
)
1295 /* If this is a new thread, add it to GDB's thread list.
1296 If we leave it up to WFI to do this, bad things will happen. */
1298 if (in_thread_list (currthread
) && is_exited (currthread
))
1300 /* We're seeing an event on a thread id we knew had exited.
1301 This has to be a new thread reusing the old id. Add it. */
1302 remote_add_thread (currthread
, running
);
1306 if (!in_thread_list (currthread
))
1308 struct inferior
*inf
= NULL
;
1309 int pid
= ptid_get_pid (currthread
);
1311 if (ptid_is_pid (inferior_ptid
)
1312 && pid
== ptid_get_pid (inferior_ptid
))
1314 /* inferior_ptid has no thread member yet. This can happen
1315 with the vAttach -> remote_wait,"TAAthread:" path if the
1316 stub doesn't support qC. This is the first stop reported
1317 after an attach, so this is the main thread. Update the
1318 ptid in the thread list. */
1319 if (in_thread_list (pid_to_ptid (pid
)))
1320 thread_change_ptid (inferior_ptid
, currthread
);
1323 remote_add_thread (currthread
, running
);
1324 inferior_ptid
= currthread
;
1329 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1331 /* inferior_ptid is not set yet. This can happen with the
1332 vRun -> remote_wait,"TAAthread:" path if the stub
1333 doesn't support qC. This is the first stop reported
1334 after an attach, so this is the main thread. Update the
1335 ptid in the thread list. */
1336 thread_change_ptid (inferior_ptid
, currthread
);
1340 /* When connecting to a target remote, or to a target
1341 extended-remote which already was debugging an inferior, we
1342 may not know about it yet. Add it before adding its child
1343 thread, so notifications are emitted in a sensible order. */
1344 if (!in_inferior_list (ptid_get_pid (currthread
)))
1345 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1347 /* This is really a new thread. Add it. */
1348 remote_add_thread (currthread
, running
);
1350 /* If we found a new inferior, let the common code do whatever
1351 it needs to with it (e.g., read shared libraries, insert
1354 notice_new_inferior (currthread
, running
, 0);
1358 /* Call this function as a result of
1359 1) A halt indication (T packet) containing a thread id
1360 2) A direct query of currthread
1361 3) Successful execution of set thread
1365 record_currthread (ptid_t currthread
)
1367 general_thread
= currthread
;
1369 if (ptid_equal (currthread
, minus_one_ptid
))
1370 /* We're just invalidating the local thread mirror. */
1373 remote_notice_new_inferior (currthread
, 0);
1376 static char *last_pass_packet
;
1378 /* If 'QPassSignals' is supported, tell the remote stub what signals
1379 it can simply pass through to the inferior without reporting. */
1382 remote_pass_signals (void)
1384 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1386 char *pass_packet
, *p
;
1387 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1390 gdb_assert (numsigs
< 256);
1391 for (i
= 0; i
< numsigs
; i
++)
1393 if (signal_stop_state (i
) == 0
1394 && signal_print_state (i
) == 0
1395 && signal_pass_state (i
) == 1)
1398 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1399 strcpy (pass_packet
, "QPassSignals:");
1400 p
= pass_packet
+ strlen (pass_packet
);
1401 for (i
= 0; i
< numsigs
; i
++)
1403 if (signal_stop_state (i
) == 0
1404 && signal_print_state (i
) == 0
1405 && signal_pass_state (i
) == 1)
1408 *p
++ = tohex (i
>> 4);
1409 *p
++ = tohex (i
& 15);
1418 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1420 struct remote_state
*rs
= get_remote_state ();
1421 char *buf
= rs
->buf
;
1423 putpkt (pass_packet
);
1424 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1425 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1426 if (last_pass_packet
)
1427 xfree (last_pass_packet
);
1428 last_pass_packet
= pass_packet
;
1431 xfree (pass_packet
);
1435 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1436 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1437 thread. If GEN is set, set the general thread, if not, then set
1438 the step/continue thread. */
1440 set_thread (struct ptid ptid
, int gen
)
1442 struct remote_state
*rs
= get_remote_state ();
1443 ptid_t state
= gen
? general_thread
: continue_thread
;
1444 char *buf
= rs
->buf
;
1445 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1447 if (ptid_equal (state
, ptid
))
1451 *buf
++ = gen
? 'g' : 'c';
1452 if (ptid_equal (ptid
, magic_null_ptid
))
1453 xsnprintf (buf
, endbuf
- buf
, "0");
1454 else if (ptid_equal (ptid
, any_thread_ptid
))
1455 xsnprintf (buf
, endbuf
- buf
, "0");
1456 else if (ptid_equal (ptid
, minus_one_ptid
))
1457 xsnprintf (buf
, endbuf
- buf
, "-1");
1459 write_ptid (buf
, endbuf
, ptid
);
1461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1463 general_thread
= ptid
;
1465 continue_thread
= ptid
;
1469 set_general_thread (struct ptid ptid
)
1471 set_thread (ptid
, 1);
1475 set_continue_thread (struct ptid ptid
)
1477 set_thread (ptid
, 0);
1480 /* Change the remote current process. Which thread within the process
1481 ends up selected isn't important, as long as it is the same process
1482 as what INFERIOR_PTID points to.
1484 This comes from that fact that there is no explicit notion of
1485 "selected process" in the protocol. The selected process for
1486 general operations is the process the selected general thread
1490 set_general_process (void)
1492 struct remote_state
*rs
= get_remote_state ();
1494 /* If the remote can't handle multiple processes, don't bother. */
1495 if (!remote_multi_process_p (rs
))
1498 /* We only need to change the remote current thread if it's pointing
1499 at some other process. */
1500 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1501 set_general_thread (inferior_ptid
);
1505 /* Return nonzero if the thread PTID is still alive on the remote
1509 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1511 struct remote_state
*rs
= get_remote_state ();
1514 if (ptid_equal (ptid
, magic_null_ptid
))
1515 /* The main thread is always alive. */
1518 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1519 /* The main thread is always alive. This can happen after a
1520 vAttach, if the remote side doesn't support
1525 endp
= rs
->buf
+ get_remote_packet_size ();
1528 write_ptid (p
, endp
, ptid
);
1531 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1532 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1535 /* About these extended threadlist and threadinfo packets. They are
1536 variable length packets but, the fields within them are often fixed
1537 length. They are redundent enough to send over UDP as is the
1538 remote protocol in general. There is a matching unit test module
1541 #define OPAQUETHREADBYTES 8
1543 /* a 64 bit opaque identifier */
1544 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1546 /* WARNING: This threadref data structure comes from the remote O.S.,
1547 libstub protocol encoding, and remote.c. it is not particularly
1550 /* Right now, the internal structure is int. We want it to be bigger.
1554 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1556 /* gdb_ext_thread_info is an internal GDB data structure which is
1557 equivalent to the reply of the remote threadinfo packet. */
1559 struct gdb_ext_thread_info
1561 threadref threadid
; /* External form of thread reference. */
1562 int active
; /* Has state interesting to GDB?
1564 char display
[256]; /* Brief state display, name,
1565 blocked/suspended. */
1566 char shortname
[32]; /* To be used to name threads. */
1567 char more_display
[256]; /* Long info, statistics, queue depth,
1571 /* The volume of remote transfers can be limited by submitting
1572 a mask containing bits specifying the desired information.
1573 Use a union of these values as the 'selection' parameter to
1574 get_thread_info. FIXME: Make these TAG names more thread specific.
1577 #define TAG_THREADID 1
1578 #define TAG_EXISTS 2
1579 #define TAG_DISPLAY 4
1580 #define TAG_THREADNAME 8
1581 #define TAG_MOREDISPLAY 16
1583 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1585 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1587 static char *unpack_nibble (char *buf
, int *val
);
1589 static char *pack_nibble (char *buf
, int nibble
);
1591 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1593 static char *unpack_byte (char *buf
, int *value
);
1595 static char *pack_int (char *buf
, int value
);
1597 static char *unpack_int (char *buf
, int *value
);
1599 static char *unpack_string (char *src
, char *dest
, int length
);
1601 static char *pack_threadid (char *pkt
, threadref
*id
);
1603 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1605 void int_to_threadref (threadref
*id
, int value
);
1607 static int threadref_to_int (threadref
*ref
);
1609 static void copy_threadref (threadref
*dest
, threadref
*src
);
1611 static int threadmatch (threadref
*dest
, threadref
*src
);
1613 static char *pack_threadinfo_request (char *pkt
, int mode
,
1616 static int remote_unpack_thread_info_response (char *pkt
,
1617 threadref
*expectedref
,
1618 struct gdb_ext_thread_info
1622 static int remote_get_threadinfo (threadref
*threadid
,
1623 int fieldset
, /*TAG mask */
1624 struct gdb_ext_thread_info
*info
);
1626 static char *pack_threadlist_request (char *pkt
, int startflag
,
1628 threadref
*nextthread
);
1630 static int parse_threadlist_response (char *pkt
,
1632 threadref
*original_echo
,
1633 threadref
*resultlist
,
1636 static int remote_get_threadlist (int startflag
,
1637 threadref
*nextthread
,
1641 threadref
*threadlist
);
1643 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1645 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1646 void *context
, int looplimit
);
1648 static int remote_newthread_step (threadref
*ref
, void *context
);
1651 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1652 buffer we're allowed to write to. Returns
1653 BUF+CHARACTERS_WRITTEN. */
1656 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1659 struct remote_state
*rs
= get_remote_state ();
1661 if (remote_multi_process_p (rs
))
1663 pid
= ptid_get_pid (ptid
);
1665 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1667 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1669 tid
= ptid_get_tid (ptid
);
1671 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1673 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1678 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1679 passed the last parsed char. Returns null_ptid on error. */
1682 read_ptid (char *buf
, char **obuf
)
1686 ULONGEST pid
= 0, tid
= 0;
1690 /* Multi-process ptid. */
1691 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1693 error (_("invalid remote ptid: %s\n"), p
);
1696 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1699 return ptid_build (pid
, 0, tid
);
1702 /* No multi-process. Just a tid. */
1703 pp
= unpack_varlen_hex (p
, &tid
);
1705 /* Since the stub is not sending a process id, then default to
1706 what's in inferior_ptid, unless it's null at this point. If so,
1707 then since there's no way to know the pid of the reported
1708 threads, use the magic number. */
1709 if (ptid_equal (inferior_ptid
, null_ptid
))
1710 pid
= ptid_get_pid (magic_null_ptid
);
1712 pid
= ptid_get_pid (inferior_ptid
);
1716 return ptid_build (pid
, 0, tid
);
1719 /* Encode 64 bits in 16 chars of hex. */
1721 static const char hexchars
[] = "0123456789abcdef";
1724 ishex (int ch
, int *val
)
1726 if ((ch
>= 'a') && (ch
<= 'f'))
1728 *val
= ch
- 'a' + 10;
1731 if ((ch
>= 'A') && (ch
<= 'F'))
1733 *val
= ch
- 'A' + 10;
1736 if ((ch
>= '0') && (ch
<= '9'))
1747 if (ch
>= 'a' && ch
<= 'f')
1748 return ch
- 'a' + 10;
1749 if (ch
>= '0' && ch
<= '9')
1751 if (ch
>= 'A' && ch
<= 'F')
1752 return ch
- 'A' + 10;
1757 stub_unpack_int (char *buff
, int fieldlength
)
1764 nibble
= stubhex (*buff
++);
1768 retval
= retval
<< 4;
1774 unpack_varlen_hex (char *buff
, /* packet to parse */
1778 ULONGEST retval
= 0;
1780 while (ishex (*buff
, &nibble
))
1783 retval
= retval
<< 4;
1784 retval
|= nibble
& 0x0f;
1791 unpack_nibble (char *buf
, int *val
)
1793 *val
= fromhex (*buf
++);
1798 pack_nibble (char *buf
, int nibble
)
1800 *buf
++ = hexchars
[(nibble
& 0x0f)];
1805 pack_hex_byte (char *pkt
, int byte
)
1807 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1808 *pkt
++ = hexchars
[(byte
& 0xf)];
1813 unpack_byte (char *buf
, int *value
)
1815 *value
= stub_unpack_int (buf
, 2);
1820 pack_int (char *buf
, int value
)
1822 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1823 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1824 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1825 buf
= pack_hex_byte (buf
, (value
& 0xff));
1830 unpack_int (char *buf
, int *value
)
1832 *value
= stub_unpack_int (buf
, 8);
1836 #if 0 /* Currently unused, uncomment when needed. */
1837 static char *pack_string (char *pkt
, char *string
);
1840 pack_string (char *pkt
, char *string
)
1845 len
= strlen (string
);
1847 len
= 200; /* Bigger than most GDB packets, junk??? */
1848 pkt
= pack_hex_byte (pkt
, len
);
1852 if ((ch
== '\0') || (ch
== '#'))
1853 ch
= '*'; /* Protect encapsulation. */
1858 #endif /* 0 (unused) */
1861 unpack_string (char *src
, char *dest
, int length
)
1870 pack_threadid (char *pkt
, threadref
*id
)
1873 unsigned char *altid
;
1875 altid
= (unsigned char *) id
;
1876 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1878 pkt
= pack_hex_byte (pkt
, *altid
++);
1884 unpack_threadid (char *inbuf
, threadref
*id
)
1887 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1890 altref
= (char *) id
;
1892 while (inbuf
< limit
)
1894 x
= stubhex (*inbuf
++);
1895 y
= stubhex (*inbuf
++);
1896 *altref
++ = (x
<< 4) | y
;
1901 /* Externally, threadrefs are 64 bits but internally, they are still
1902 ints. This is due to a mismatch of specifications. We would like
1903 to use 64bit thread references internally. This is an adapter
1907 int_to_threadref (threadref
*id
, int value
)
1909 unsigned char *scan
;
1911 scan
= (unsigned char *) id
;
1917 *scan
++ = (value
>> 24) & 0xff;
1918 *scan
++ = (value
>> 16) & 0xff;
1919 *scan
++ = (value
>> 8) & 0xff;
1920 *scan
++ = (value
& 0xff);
1924 threadref_to_int (threadref
*ref
)
1927 unsigned char *scan
;
1933 value
= (value
<< 8) | ((*scan
++) & 0xff);
1938 copy_threadref (threadref
*dest
, threadref
*src
)
1941 unsigned char *csrc
, *cdest
;
1943 csrc
= (unsigned char *) src
;
1944 cdest
= (unsigned char *) dest
;
1951 threadmatch (threadref
*dest
, threadref
*src
)
1953 /* Things are broken right now, so just assume we got a match. */
1955 unsigned char *srcp
, *destp
;
1957 srcp
= (char *) src
;
1958 destp
= (char *) dest
;
1962 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1969 threadid:1, # always request threadid
1976 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1979 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1981 *pkt
++ = 'q'; /* Info Query */
1982 *pkt
++ = 'P'; /* process or thread info */
1983 pkt
= pack_int (pkt
, mode
); /* mode */
1984 pkt
= pack_threadid (pkt
, id
); /* threadid */
1985 *pkt
= '\0'; /* terminate */
1989 /* These values tag the fields in a thread info response packet. */
1990 /* Tagging the fields allows us to request specific fields and to
1991 add more fields as time goes by. */
1993 #define TAG_THREADID 1 /* Echo the thread identifier. */
1994 #define TAG_EXISTS 2 /* Is this process defined enough to
1995 fetch registers and its stack? */
1996 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1997 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1998 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2002 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2003 struct gdb_ext_thread_info
*info
)
2005 struct remote_state
*rs
= get_remote_state ();
2009 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2012 /* info->threadid = 0; FIXME: implement zero_threadref. */
2014 info
->display
[0] = '\0';
2015 info
->shortname
[0] = '\0';
2016 info
->more_display
[0] = '\0';
2018 /* Assume the characters indicating the packet type have been
2020 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2021 pkt
= unpack_threadid (pkt
, &ref
);
2024 warning (_("Incomplete response to threadinfo request."));
2025 if (!threadmatch (&ref
, expectedref
))
2026 { /* This is an answer to a different request. */
2027 warning (_("ERROR RMT Thread info mismatch."));
2030 copy_threadref (&info
->threadid
, &ref
);
2032 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2034 /* Packets are terminated with nulls. */
2035 while ((pkt
< limit
) && mask
&& *pkt
)
2037 pkt
= unpack_int (pkt
, &tag
); /* tag */
2038 pkt
= unpack_byte (pkt
, &length
); /* length */
2039 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2041 warning (_("ERROR RMT: threadinfo tag mismatch."));
2045 if (tag
== TAG_THREADID
)
2049 warning (_("ERROR RMT: length of threadid is not 16."));
2053 pkt
= unpack_threadid (pkt
, &ref
);
2054 mask
= mask
& ~TAG_THREADID
;
2057 if (tag
== TAG_EXISTS
)
2059 info
->active
= stub_unpack_int (pkt
, length
);
2061 mask
= mask
& ~(TAG_EXISTS
);
2064 warning (_("ERROR RMT: 'exists' length too long."));
2070 if (tag
== TAG_THREADNAME
)
2072 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2073 mask
= mask
& ~TAG_THREADNAME
;
2076 if (tag
== TAG_DISPLAY
)
2078 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2079 mask
= mask
& ~TAG_DISPLAY
;
2082 if (tag
== TAG_MOREDISPLAY
)
2084 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2085 mask
= mask
& ~TAG_MOREDISPLAY
;
2088 warning (_("ERROR RMT: unknown thread info tag."));
2089 break; /* Not a tag we know about. */
2095 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2096 struct gdb_ext_thread_info
*info
)
2098 struct remote_state
*rs
= get_remote_state ();
2101 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2103 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2105 if (rs
->buf
[0] == '\0')
2108 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2113 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2116 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2117 threadref
*nextthread
)
2119 *pkt
++ = 'q'; /* info query packet */
2120 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2121 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2122 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2123 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2128 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2131 parse_threadlist_response (char *pkt
, int result_limit
,
2132 threadref
*original_echo
, threadref
*resultlist
,
2135 struct remote_state
*rs
= get_remote_state ();
2137 int count
, resultcount
, done
;
2140 /* Assume the 'q' and 'M chars have been stripped. */
2141 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2142 /* done parse past here */
2143 pkt
= unpack_byte (pkt
, &count
); /* count field */
2144 pkt
= unpack_nibble (pkt
, &done
);
2145 /* The first threadid is the argument threadid. */
2146 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2147 while ((count
-- > 0) && (pkt
< limit
))
2149 pkt
= unpack_threadid (pkt
, resultlist
++);
2150 if (resultcount
++ >= result_limit
)
2159 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2160 int *done
, int *result_count
, threadref
*threadlist
)
2162 struct remote_state
*rs
= get_remote_state ();
2163 static threadref echo_nextthread
;
2166 /* Trancate result limit to be smaller than the packet size. */
2167 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
2168 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2170 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2172 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2174 if (*rs
->buf
== '\0')
2178 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2181 if (!threadmatch (&echo_nextthread
, nextthread
))
2183 /* FIXME: This is a good reason to drop the packet. */
2184 /* Possably, there is a duplicate response. */
2186 retransmit immediatly - race conditions
2187 retransmit after timeout - yes
2189 wait for packet, then exit
2191 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2192 return 0; /* I choose simply exiting. */
2194 if (*result_count
<= 0)
2198 warning (_("RMT ERROR : failed to get remote thread list."));
2201 return result
; /* break; */
2203 if (*result_count
> result_limit
)
2206 warning (_("RMT ERROR: threadlist response longer than requested."));
2212 /* This is the interface between remote and threads, remotes upper
2215 /* remote_find_new_threads retrieves the thread list and for each
2216 thread in the list, looks up the thread in GDB's internal list,
2217 adding the thread if it does not already exist. This involves
2218 getting partial thread lists from the remote target so, polling the
2219 quit_flag is required. */
2222 /* About this many threadisds fit in a packet. */
2224 #define MAXTHREADLISTRESULTS 32
2227 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2230 int done
, i
, result_count
;
2234 static threadref nextthread
;
2235 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2240 if (loopcount
++ > looplimit
)
2243 warning (_("Remote fetch threadlist -infinite loop-."));
2246 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2247 &done
, &result_count
, resultthreadlist
))
2252 /* Clear for later iterations. */
2254 /* Setup to resume next batch of thread references, set nextthread. */
2255 if (result_count
>= 1)
2256 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2258 while (result_count
--)
2259 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2266 remote_newthread_step (threadref
*ref
, void *context
)
2268 int pid
= ptid_get_pid (inferior_ptid
);
2269 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2271 if (!in_thread_list (ptid
))
2273 return 1; /* continue iterator */
2276 #define CRAZY_MAX_THREADS 1000
2279 remote_current_thread (ptid_t oldpid
)
2281 struct remote_state
*rs
= get_remote_state ();
2284 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2285 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2286 return read_ptid (&rs
->buf
[2], NULL
);
2291 /* Find new threads for info threads command.
2292 * Original version, using John Metzler's thread protocol.
2296 remote_find_new_threads (void)
2298 remote_threadlist_iterator (remote_newthread_step
, 0,
2303 * Find all threads for info threads command.
2304 * Uses new thread protocol contributed by Cisco.
2305 * Falls back and attempts to use the older method (above)
2306 * if the target doesn't respond to the new method.
2310 remote_threads_info (struct target_ops
*ops
)
2312 struct remote_state
*rs
= get_remote_state ();
2316 if (remote_desc
== 0) /* paranoia */
2317 error (_("Command can only be used when connected to the remote target."));
2319 if (use_threadinfo_query
)
2321 putpkt ("qfThreadInfo");
2322 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2324 if (bufp
[0] != '\0') /* q packet recognized */
2326 while (*bufp
++ == 'm') /* reply contains one or more TID */
2330 new_thread
= read_ptid (bufp
, &bufp
);
2331 if (!ptid_equal (new_thread
, null_ptid
))
2333 /* In non-stop mode, we assume new found threads
2334 are running until proven otherwise with a
2335 stop reply. In all-stop, we can only get
2336 here if all threads are stopped. */
2337 int running
= non_stop
? 1 : 0;
2339 remote_notice_new_inferior (new_thread
, running
);
2342 while (*bufp
++ == ','); /* comma-separated list */
2343 putpkt ("qsThreadInfo");
2344 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2351 /* Only qfThreadInfo is supported in non-stop mode. */
2355 /* Else fall back to old method based on jmetzler protocol. */
2356 use_threadinfo_query
= 0;
2357 remote_find_new_threads ();
2362 * Collect a descriptive string about the given thread.
2363 * The target may say anything it wants to about the thread
2364 * (typically info about its blocked / runnable state, name, etc.).
2365 * This string will appear in the info threads display.
2367 * Optional: targets are not required to implement this function.
2371 remote_threads_extra_info (struct thread_info
*tp
)
2373 struct remote_state
*rs
= get_remote_state ();
2377 struct gdb_ext_thread_info threadinfo
;
2378 static char display_buf
[100]; /* arbitrary... */
2379 int n
= 0; /* position in display_buf */
2381 if (remote_desc
== 0) /* paranoia */
2382 internal_error (__FILE__
, __LINE__
,
2383 _("remote_threads_extra_info"));
2385 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2386 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2387 /* This is the main thread which was added by GDB. The remote
2388 server doesn't know about it. */
2391 if (use_threadextra_query
)
2394 char *endb
= rs
->buf
+ get_remote_packet_size ();
2396 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2398 write_ptid (b
, endb
, tp
->ptid
);
2401 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2402 if (rs
->buf
[0] != 0)
2404 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2405 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2406 display_buf
[result
] = '\0';
2411 /* If the above query fails, fall back to the old method. */
2412 use_threadextra_query
= 0;
2413 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2414 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2415 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2416 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2417 if (threadinfo
.active
)
2419 if (*threadinfo
.shortname
)
2420 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2421 " Name: %s,", threadinfo
.shortname
);
2422 if (*threadinfo
.display
)
2423 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2424 " State: %s,", threadinfo
.display
);
2425 if (*threadinfo
.more_display
)
2426 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2427 " Priority: %s", threadinfo
.more_display
);
2431 /* For purely cosmetic reasons, clear up trailing commas. */
2432 if (',' == display_buf
[n
-1])
2433 display_buf
[n
-1] = ' ';
2441 /* Restart the remote side; this is an extended protocol operation. */
2444 extended_remote_restart (void)
2446 struct remote_state
*rs
= get_remote_state ();
2448 /* Send the restart command; for reasons I don't understand the
2449 remote side really expects a number after the "R". */
2450 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2453 remote_fileio_reset ();
2456 /* Clean up connection to a remote debugger. */
2459 remote_close (int quitting
)
2461 if (remote_desc
== NULL
)
2462 return; /* already closed */
2464 /* Make sure we leave stdin registered in the event loop, and we
2465 don't leave the async SIGINT signal handler installed. */
2466 remote_terminal_ours ();
2468 serial_close (remote_desc
);
2471 /* We don't have a connection to the remote stub anymore. Get rid
2472 of all the inferiors and their threads we were controlling. */
2473 discard_all_inferiors ();
2475 /* We're no longer interested in any of these events. */
2476 discard_pending_stop_replies (-1);
2478 if (remote_async_inferior_event_token
)
2479 delete_async_event_handler (&remote_async_inferior_event_token
);
2480 if (remote_async_get_pending_events_token
)
2481 delete_async_event_handler (&remote_async_get_pending_events_token
);
2484 /* Query the remote side for the text, data and bss offsets. */
2489 struct remote_state
*rs
= get_remote_state ();
2492 int lose
, num_segments
= 0, do_sections
, do_segments
;
2493 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2494 struct section_offsets
*offs
;
2495 struct symfile_segment_data
*data
;
2497 if (symfile_objfile
== NULL
)
2500 putpkt ("qOffsets");
2501 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2504 if (buf
[0] == '\000')
2505 return; /* Return silently. Stub doesn't support
2509 warning (_("Remote failure reply: %s"), buf
);
2513 /* Pick up each field in turn. This used to be done with scanf, but
2514 scanf will make trouble if CORE_ADDR size doesn't match
2515 conversion directives correctly. The following code will work
2516 with any size of CORE_ADDR. */
2517 text_addr
= data_addr
= bss_addr
= 0;
2521 if (strncmp (ptr
, "Text=", 5) == 0)
2524 /* Don't use strtol, could lose on big values. */
2525 while (*ptr
&& *ptr
!= ';')
2526 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2528 if (strncmp (ptr
, ";Data=", 6) == 0)
2531 while (*ptr
&& *ptr
!= ';')
2532 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2537 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2540 while (*ptr
&& *ptr
!= ';')
2541 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2543 if (bss_addr
!= data_addr
)
2544 warning (_("Target reported unsupported offsets: %s"), buf
);
2549 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2552 /* Don't use strtol, could lose on big values. */
2553 while (*ptr
&& *ptr
!= ';')
2554 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2557 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2560 while (*ptr
&& *ptr
!= ';')
2561 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2569 error (_("Malformed response to offset query, %s"), buf
);
2570 else if (*ptr
!= '\0')
2571 warning (_("Target reported unsupported offsets: %s"), buf
);
2573 offs
= ((struct section_offsets
*)
2574 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2575 memcpy (offs
, symfile_objfile
->section_offsets
,
2576 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2578 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2579 do_segments
= (data
!= NULL
);
2580 do_sections
= num_segments
== 0;
2582 if (num_segments
> 0)
2584 segments
[0] = text_addr
;
2585 segments
[1] = data_addr
;
2587 /* If we have two segments, we can still try to relocate everything
2588 by assuming that the .text and .data offsets apply to the whole
2589 text and data segments. Convert the offsets given in the packet
2590 to base addresses for symfile_map_offsets_to_segments. */
2591 else if (data
&& data
->num_segments
== 2)
2593 segments
[0] = data
->segment_bases
[0] + text_addr
;
2594 segments
[1] = data
->segment_bases
[1] + data_addr
;
2597 /* If the object file has only one segment, assume that it is text
2598 rather than data; main programs with no writable data are rare,
2599 but programs with no code are useless. Of course the code might
2600 have ended up in the data segment... to detect that we would need
2601 the permissions here. */
2602 else if (data
&& data
->num_segments
== 1)
2604 segments
[0] = data
->segment_bases
[0] + text_addr
;
2607 /* There's no way to relocate by segment. */
2613 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2614 offs
, num_segments
, segments
);
2616 if (ret
== 0 && !do_sections
)
2617 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2624 free_symfile_segment_data (data
);
2628 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2630 /* This is a temporary kludge to force data and bss to use the same offsets
2631 because that's what nlmconv does now. The real solution requires changes
2632 to the stub and remote.c that I don't have time to do right now. */
2634 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2635 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2638 objfile_relocate (symfile_objfile
, offs
);
2641 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
2642 threads we know are stopped already. This is used during the
2643 initial remote connection in non-stop mode --- threads that are
2644 reported as already being stopped are left stopped. */
2647 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
2649 /* If we have a stop reply for this thread, it must be stopped. */
2650 if (peek_stop_reply (thread
->ptid
))
2651 set_stop_requested (thread
->ptid
, 1);
2656 /* Stub for catch_exception. */
2658 struct start_remote_args
2662 /* The current target. */
2663 struct target_ops
*target
;
2665 /* Non-zero if this is an extended-remote target. */
2669 /* Send interrupt_sequence to remote target. */
2671 send_interrupt_sequence ()
2673 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
2674 serial_write (remote_desc
, "\x03", 1);
2675 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
2676 serial_send_break (remote_desc
);
2677 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
2679 serial_send_break (remote_desc
);
2680 serial_write (remote_desc
, "g", 1);
2683 internal_error (__FILE__
, __LINE__
,
2684 _("Invalid value for interrupt_sequence_mode: %s."),
2685 interrupt_sequence_mode
);
2689 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2691 struct start_remote_args
*args
= opaque
;
2692 struct remote_state
*rs
= get_remote_state ();
2693 struct packet_config
*noack_config
;
2694 char *wait_status
= NULL
;
2696 immediate_quit
++; /* Allow user to interrupt it. */
2698 /* Ack any packet which the remote side has already sent. */
2699 serial_write (remote_desc
, "+", 1);
2701 if (interrupt_on_connect
)
2702 send_interrupt_sequence ();
2704 /* The first packet we send to the target is the optional "supported
2705 packets" request. If the target can answer this, it will tell us
2706 which later probes to skip. */
2707 remote_query_supported ();
2709 /* Next, we possibly activate noack mode.
2711 If the QStartNoAckMode packet configuration is set to AUTO,
2712 enable noack mode if the stub reported a wish for it with
2715 If set to TRUE, then enable noack mode even if the stub didn't
2716 report it in qSupported. If the stub doesn't reply OK, the
2717 session ends with an error.
2719 If FALSE, then don't activate noack mode, regardless of what the
2720 stub claimed should be the default with qSupported. */
2722 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2724 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2725 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2726 && noack_config
->support
== PACKET_ENABLE
))
2728 putpkt ("QStartNoAckMode");
2729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2730 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2734 if (args
->extended_p
)
2736 /* Tell the remote that we are using the extended protocol. */
2738 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2741 /* Next, if the target can specify a description, read it. We do
2742 this before anything involving memory or registers. */
2743 target_find_description ();
2745 /* Next, now that we know something about the target, update the
2746 address spaces in the program spaces. */
2747 update_address_spaces ();
2749 /* On OSs where the list of libraries is global to all
2750 processes, we fetch them early. */
2751 if (gdbarch_has_global_solist (target_gdbarch
))
2752 solib_add (NULL
, args
->from_tty
, args
->target
, auto_solib_add
);
2756 if (!rs
->non_stop_aware
)
2757 error (_("Non-stop mode requested, but remote does not support non-stop"));
2759 putpkt ("QNonStop:1");
2760 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2762 if (strcmp (rs
->buf
, "OK") != 0)
2763 error ("Remote refused setting non-stop mode with: %s", rs
->buf
);
2765 /* Find about threads and processes the stub is already
2766 controlling. We default to adding them in the running state.
2767 The '?' query below will then tell us about which threads are
2769 remote_threads_info (args
->target
);
2771 else if (rs
->non_stop_aware
)
2773 /* Don't assume that the stub can operate in all-stop mode.
2774 Request it explicitely. */
2775 putpkt ("QNonStop:0");
2776 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2778 if (strcmp (rs
->buf
, "OK") != 0)
2779 error ("Remote refused setting all-stop mode with: %s", rs
->buf
);
2782 /* Check whether the target is running now. */
2784 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2788 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
2790 if (!args
->extended_p
)
2791 error (_("The target is not running (try extended-remote?)"));
2793 /* We're connected, but not running. Drop out before we
2794 call start_remote. */
2799 /* Save the reply for later. */
2800 wait_status
= alloca (strlen (rs
->buf
) + 1);
2801 strcpy (wait_status
, rs
->buf
);
2804 /* Let the stub know that we want it to return the thread. */
2805 set_continue_thread (minus_one_ptid
);
2807 /* Without this, some commands which require an active target
2808 (such as kill) won't work. This variable serves (at least)
2809 double duty as both the pid of the target process (if it has
2810 such), and as a flag indicating that a target is active.
2811 These functions should be split out into seperate variables,
2812 especially since GDB will someday have a notion of debugging
2813 several processes. */
2814 inferior_ptid
= magic_null_ptid
;
2816 /* Now, if we have thread information, update inferior_ptid. */
2817 inferior_ptid
= remote_current_thread (inferior_ptid
);
2819 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
2821 /* Always add the main thread. */
2822 add_thread_silent (inferior_ptid
);
2824 get_offsets (); /* Get text, data & bss offsets. */
2826 /* If we could not find a description using qXfer, and we know
2827 how to do it some other way, try again. This is not
2828 supported for non-stop; it could be, but it is tricky if
2829 there are no stopped threads when we connect. */
2830 if (remote_read_description_p (args
->target
)
2831 && gdbarch_target_desc (target_gdbarch
) == NULL
)
2833 target_clear_description ();
2834 target_find_description ();
2837 /* Use the previously fetched status. */
2838 gdb_assert (wait_status
!= NULL
);
2839 strcpy (rs
->buf
, wait_status
);
2840 rs
->cached_wait_status
= 1;
2843 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
2847 /* Clear WFI global state. Do this before finding about new
2848 threads and inferiors, and setting the current inferior.
2849 Otherwise we would clear the proceed status of the current
2850 inferior when we want its stop_soon state to be preserved
2851 (see notice_new_inferior). */
2852 init_wait_for_inferior ();
2854 /* In non-stop, we will either get an "OK", meaning that there
2855 are no stopped threads at this time; or, a regular stop
2856 reply. In the latter case, there may be more than one thread
2857 stopped --- we pull them all out using the vStopped
2859 if (strcmp (rs
->buf
, "OK") != 0)
2861 struct stop_reply
*stop_reply
;
2862 struct cleanup
*old_chain
;
2864 stop_reply
= stop_reply_xmalloc ();
2865 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
2867 remote_parse_stop_reply (rs
->buf
, stop_reply
);
2868 discard_cleanups (old_chain
);
2870 /* get_pending_stop_replies acks this one, and gets the rest
2872 pending_stop_reply
= stop_reply
;
2873 remote_get_pending_stop_replies ();
2875 /* Make sure that threads that were stopped remain
2877 iterate_over_threads (set_stop_requested_callback
, NULL
);
2880 if (target_can_async_p ())
2881 target_async (inferior_event_handler
, 0);
2883 if (thread_count () == 0)
2885 if (!args
->extended_p
)
2886 error (_("The target is not running (try extended-remote?)"));
2888 /* We're connected, but not running. Drop out before we
2889 call start_remote. */
2893 /* Let the stub know that we want it to return the thread. */
2895 /* Force the stub to choose a thread. */
2896 set_general_thread (null_ptid
);
2899 inferior_ptid
= remote_current_thread (minus_one_ptid
);
2900 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
2901 error (_("remote didn't report the current thread in non-stop mode"));
2903 get_offsets (); /* Get text, data & bss offsets. */
2905 /* In non-stop mode, any cached wait status will be stored in
2906 the stop reply queue. */
2907 gdb_assert (wait_status
== NULL
);
2910 /* If we connected to a live target, do some additional setup. */
2911 if (target_has_execution
)
2913 if (exec_bfd
) /* No use without an exec file. */
2914 remote_check_symbols (symfile_objfile
);
2917 /* If breakpoints are global, insert them now. */
2918 if (gdbarch_has_global_breakpoints (target_gdbarch
)
2919 && breakpoints_always_inserted_mode ())
2920 insert_breakpoints ();
2923 /* Open a connection to a remote debugger.
2924 NAME is the filename used for communication. */
2927 remote_open (char *name
, int from_tty
)
2929 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2932 /* Open a connection to a remote debugger using the extended
2933 remote gdb protocol. NAME is the filename used for communication. */
2936 extended_remote_open (char *name
, int from_tty
)
2938 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
2941 /* Generic code for opening a connection to a remote target. */
2944 init_all_packet_configs (void)
2947 for (i
= 0; i
< PACKET_MAX
; i
++)
2948 update_packet_config (&remote_protocol_packets
[i
]);
2951 /* Symbol look-up. */
2954 remote_check_symbols (struct objfile
*objfile
)
2956 struct remote_state
*rs
= get_remote_state ();
2957 char *msg
, *reply
, *tmp
;
2958 struct minimal_symbol
*sym
;
2961 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
2964 /* Make sure the remote is pointing at the right process. */
2965 set_general_process ();
2967 /* Allocate a message buffer. We can't reuse the input buffer in RS,
2968 because we need both at the same time. */
2969 msg
= alloca (get_remote_packet_size ());
2971 /* Invite target to request symbol lookups. */
2973 putpkt ("qSymbol::");
2974 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2975 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
2978 while (strncmp (reply
, "qSymbol:", 8) == 0)
2981 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2983 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2985 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
2988 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
2989 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
2991 /* If this is a function address, return the start of code
2992 instead of any data function descriptor. */
2993 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
2997 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
2998 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3002 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3007 static struct serial
*
3008 remote_serial_open (char *name
)
3010 static int udp_warning
= 0;
3012 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3013 of in ser-tcp.c, because it is the remote protocol assuming that the
3014 serial connection is reliable and not the serial connection promising
3016 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3019 The remote protocol may be unreliable over UDP.\n\
3020 Some events may be lost, rendering further debugging impossible."));
3024 return serial_open (name
);
3027 /* This type describes each known response to the qSupported
3029 struct protocol_feature
3031 /* The name of this protocol feature. */
3034 /* The default for this protocol feature. */
3035 enum packet_support default_support
;
3037 /* The function to call when this feature is reported, or after
3038 qSupported processing if the feature is not supported.
3039 The first argument points to this structure. The second
3040 argument indicates whether the packet requested support be
3041 enabled, disabled, or probed (or the default, if this function
3042 is being called at the end of processing and this feature was
3043 not reported). The third argument may be NULL; if not NULL, it
3044 is a NUL-terminated string taken from the packet following
3045 this feature's name and an equals sign. */
3046 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3049 /* The corresponding packet for this feature. Only used if
3050 FUNC is remote_supported_packet. */
3055 remote_supported_packet (const struct protocol_feature
*feature
,
3056 enum packet_support support
,
3057 const char *argument
)
3061 warning (_("Remote qSupported response supplied an unexpected value for"
3062 " \"%s\"."), feature
->name
);
3066 if (remote_protocol_packets
[feature
->packet
].support
3067 == PACKET_SUPPORT_UNKNOWN
)
3068 remote_protocol_packets
[feature
->packet
].support
= support
;
3072 remote_packet_size (const struct protocol_feature
*feature
,
3073 enum packet_support support
, const char *value
)
3075 struct remote_state
*rs
= get_remote_state ();
3080 if (support
!= PACKET_ENABLE
)
3083 if (value
== NULL
|| *value
== '\0')
3085 warning (_("Remote target reported \"%s\" without a size."),
3091 packet_size
= strtol (value
, &value_end
, 16);
3092 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3094 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3095 feature
->name
, value
);
3099 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3101 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3102 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3103 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3106 /* Record the new maximum packet size. */
3107 rs
->explicit_packet_size
= packet_size
;
3111 remote_multi_process_feature (const struct protocol_feature
*feature
,
3112 enum packet_support support
, const char *value
)
3114 struct remote_state
*rs
= get_remote_state ();
3115 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3119 remote_non_stop_feature (const struct protocol_feature
*feature
,
3120 enum packet_support support
, const char *value
)
3122 struct remote_state
*rs
= get_remote_state ();
3123 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3127 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3128 enum packet_support support
,
3131 struct remote_state
*rs
= get_remote_state ();
3132 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3135 static struct protocol_feature remote_protocol_features
[] = {
3136 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3137 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3138 PACKET_qXfer_auxv
},
3139 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3140 PACKET_qXfer_features
},
3141 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3142 PACKET_qXfer_libraries
},
3143 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3144 PACKET_qXfer_memory_map
},
3145 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3146 PACKET_qXfer_spu_read
},
3147 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3148 PACKET_qXfer_spu_write
},
3149 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3150 PACKET_qXfer_osdata
},
3151 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3152 PACKET_QPassSignals
},
3153 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3154 PACKET_QStartNoAckMode
},
3155 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3156 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3157 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3158 PACKET_qXfer_siginfo_read
},
3159 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3160 PACKET_qXfer_siginfo_write
},
3161 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3162 PACKET_ConditionalTracepoints
},
3163 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3165 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3170 remote_query_supported (void)
3172 struct remote_state
*rs
= get_remote_state ();
3175 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3177 /* The packet support flags are handled differently for this packet
3178 than for most others. We treat an error, a disabled packet, and
3179 an empty response identically: any features which must be reported
3180 to be used will be automatically disabled. An empty buffer
3181 accomplishes this, since that is also the representation for a list
3182 containing no features. */
3185 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3188 putpkt ("qSupported:multiprocess+");
3190 putpkt ("qSupported");
3192 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3194 /* If an error occured, warn, but do not return - just reset the
3195 buffer to empty and go on to disable features. */
3196 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3199 warning (_("Remote failure reply: %s"), rs
->buf
);
3204 memset (seen
, 0, sizeof (seen
));
3209 enum packet_support is_supported
;
3210 char *p
, *end
, *name_end
, *value
;
3212 /* First separate out this item from the rest of the packet. If
3213 there's another item after this, we overwrite the separator
3214 (terminated strings are much easier to work with). */
3216 end
= strchr (p
, ';');
3219 end
= p
+ strlen (p
);
3229 warning (_("empty item in \"qSupported\" response"));
3234 name_end
= strchr (p
, '=');
3237 /* This is a name=value entry. */
3238 is_supported
= PACKET_ENABLE
;
3239 value
= name_end
+ 1;
3248 is_supported
= PACKET_ENABLE
;
3252 is_supported
= PACKET_DISABLE
;
3256 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3260 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
3266 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3267 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3269 const struct protocol_feature
*feature
;
3272 feature
= &remote_protocol_features
[i
];
3273 feature
->func (feature
, is_supported
, value
);
3278 /* If we increased the packet size, make sure to increase the global
3279 buffer size also. We delay this until after parsing the entire
3280 qSupported packet, because this is the same buffer we were
3282 if (rs
->buf_size
< rs
->explicit_packet_size
)
3284 rs
->buf_size
= rs
->explicit_packet_size
;
3285 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3288 /* Handle the defaults for unmentioned features. */
3289 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3292 const struct protocol_feature
*feature
;
3294 feature
= &remote_protocol_features
[i
];
3295 feature
->func (feature
, feature
->default_support
, NULL
);
3301 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
3303 struct remote_state
*rs
= get_remote_state ();
3306 error (_("To open a remote debug connection, you need to specify what\n"
3307 "serial device is attached to the remote system\n"
3308 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3310 /* See FIXME above. */
3311 if (!target_async_permitted
)
3312 wait_forever_enabled_p
= 1;
3314 /* If we're connected to a running target, target_preopen will kill it.
3315 But if we're connected to a target system with no running process,
3316 then we will still be connected when it returns. Ask this question
3317 first, before target_preopen has a chance to kill anything. */
3318 if (remote_desc
!= NULL
&& !have_inferiors ())
3321 || query (_("Already connected to a remote target. Disconnect? ")))
3324 error (_("Still connected."));
3327 target_preopen (from_tty
);
3329 unpush_target (target
);
3331 /* This time without a query. If we were connected to an
3332 extended-remote target and target_preopen killed the running
3333 process, we may still be connected. If we are starting "target
3334 remote" now, the extended-remote target will not have been
3335 removed by unpush_target. */
3336 if (remote_desc
!= NULL
&& !have_inferiors ())
3339 /* Make sure we send the passed signals list the next time we resume. */
3340 xfree (last_pass_packet
);
3341 last_pass_packet
= NULL
;
3343 remote_fileio_reset ();
3344 reopen_exec_file ();
3347 remote_desc
= remote_serial_open (name
);
3349 perror_with_name (name
);
3351 if (baud_rate
!= -1)
3353 if (serial_setbaudrate (remote_desc
, baud_rate
))
3355 /* The requested speed could not be set. Error out to
3356 top level after closing remote_desc. Take care to
3357 set remote_desc to NULL to avoid closing remote_desc
3359 serial_close (remote_desc
);
3361 perror_with_name (name
);
3365 serial_raw (remote_desc
);
3367 /* If there is something sitting in the buffer we might take it as a
3368 response to a command, which would be bad. */
3369 serial_flush_input (remote_desc
);
3373 puts_filtered ("Remote debugging using ");
3374 puts_filtered (name
);
3375 puts_filtered ("\n");
3377 push_target (target
); /* Switch to using remote target now. */
3379 /* Register extra event sources in the event loop. */
3380 remote_async_inferior_event_token
3381 = create_async_event_handler (remote_async_inferior_event_handler
,
3383 remote_async_get_pending_events_token
3384 = create_async_event_handler (remote_async_get_pending_events_handler
,
3387 /* Reset the target state; these things will be queried either by
3388 remote_query_supported or as they are needed. */
3389 init_all_packet_configs ();
3390 rs
->cached_wait_status
= 0;
3391 rs
->explicit_packet_size
= 0;
3393 rs
->multi_process_aware
= 0;
3394 rs
->extended
= extended_p
;
3395 rs
->non_stop_aware
= 0;
3396 rs
->waiting_for_stop_reply
= 0;
3398 general_thread
= not_sent_ptid
;
3399 continue_thread
= not_sent_ptid
;
3401 /* Probe for ability to use "ThreadInfo" query, as required. */
3402 use_threadinfo_query
= 1;
3403 use_threadextra_query
= 1;
3405 if (target_async_permitted
)
3407 /* With this target we start out by owning the terminal. */
3408 remote_async_terminal_ours_p
= 1;
3410 /* FIXME: cagney/1999-09-23: During the initial connection it is
3411 assumed that the target is already ready and able to respond to
3412 requests. Unfortunately remote_start_remote() eventually calls
3413 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
3414 around this. Eventually a mechanism that allows
3415 wait_for_inferior() to expect/get timeouts will be
3417 wait_forever_enabled_p
= 0;
3420 /* First delete any symbols previously loaded from shared libraries. */
3421 no_shared_libraries (NULL
, 0);
3424 init_thread_list ();
3426 /* Start the remote connection. If error() or QUIT, discard this
3427 target (we'd otherwise be in an inconsistent state) and then
3428 propogate the error on up the exception chain. This ensures that
3429 the caller doesn't stumble along blindly assuming that the
3430 function succeeded. The CLI doesn't have this problem but other
3431 UI's, such as MI do.
3433 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
3434 this function should return an error indication letting the
3435 caller restore the previous state. Unfortunately the command
3436 ``target remote'' is directly wired to this function making that
3437 impossible. On a positive note, the CLI side of this problem has
3438 been fixed - the function set_cmd_context() makes it possible for
3439 all the ``target ....'' commands to share a common callback
3440 function. See cli-dump.c. */
3442 struct gdb_exception ex
;
3443 struct start_remote_args args
;
3445 args
.from_tty
= from_tty
;
3446 args
.target
= target
;
3447 args
.extended_p
= extended_p
;
3449 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
3452 /* Pop the partially set up target - unless something else did
3453 already before throwing the exception. */
3454 if (remote_desc
!= NULL
)
3456 if (target_async_permitted
)
3457 wait_forever_enabled_p
= 1;
3458 throw_exception (ex
);
3462 if (target_async_permitted
)
3463 wait_forever_enabled_p
= 1;
3466 /* This takes a program previously attached to and detaches it. After
3467 this is done, GDB can be used to debug some other program. We
3468 better not have left any breakpoints in the target program or it'll
3469 die when it hits one. */
3472 remote_detach_1 (char *args
, int from_tty
, int extended
)
3474 int pid
= ptid_get_pid (inferior_ptid
);
3475 struct remote_state
*rs
= get_remote_state ();
3478 error (_("Argument given to \"detach\" when remotely debugging."));
3480 if (!target_has_execution
)
3481 error (_("No process to detach from."));
3483 /* Tell the remote target to detach. */
3484 if (remote_multi_process_p (rs
))
3485 sprintf (rs
->buf
, "D;%x", pid
);
3487 strcpy (rs
->buf
, "D");
3490 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3492 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3494 else if (rs
->buf
[0] == '\0')
3495 error (_("Remote doesn't know how to detach"));
3497 error (_("Can't detach process."));
3501 if (remote_multi_process_p (rs
))
3502 printf_filtered (_("Detached from remote %s.\n"),
3503 target_pid_to_str (pid_to_ptid (pid
)));
3507 puts_filtered (_("Detached from remote process.\n"));
3509 puts_filtered (_("Ending remote debugging.\n"));
3513 discard_pending_stop_replies (pid
);
3514 target_mourn_inferior ();
3518 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3520 remote_detach_1 (args
, from_tty
, 0);
3524 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3526 remote_detach_1 (args
, from_tty
, 1);
3529 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3532 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3535 error (_("Argument given to \"disconnect\" when remotely debugging."));
3537 /* Make sure we unpush even the extended remote targets; mourn
3538 won't do it. So call remote_mourn_1 directly instead of
3539 target_mourn_inferior. */
3540 remote_mourn_1 (target
);
3543 puts_filtered ("Ending remote debugging.\n");
3546 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3547 be chatty about it. */
3550 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3552 struct remote_state
*rs
= get_remote_state ();
3555 char *wait_status
= NULL
;
3558 error_no_arg (_("process-id to attach"));
3561 pid
= strtol (args
, &dummy
, 0);
3562 /* Some targets don't set errno on errors, grrr! */
3563 if (pid
== 0 && args
== dummy
)
3564 error (_("Illegal process-id: %s."), args
);
3566 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3567 error (_("This target does not support attaching to a process"));
3569 sprintf (rs
->buf
, "vAttach;%x", pid
);
3571 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3573 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3576 printf_unfiltered (_("Attached to %s\n"),
3577 target_pid_to_str (pid_to_ptid (pid
)));
3581 /* Save the reply for later. */
3582 wait_status
= alloca (strlen (rs
->buf
) + 1);
3583 strcpy (wait_status
, rs
->buf
);
3585 else if (strcmp (rs
->buf
, "OK") != 0)
3586 error (_("Attaching to %s failed with: %s"),
3587 target_pid_to_str (pid_to_ptid (pid
)),
3590 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3591 error (_("This target does not support attaching to a process"));
3593 error (_("Attaching to %s failed"),
3594 target_pid_to_str (pid_to_ptid (pid
)));
3596 set_current_inferior (remote_add_inferior (pid
, 1));
3598 inferior_ptid
= pid_to_ptid (pid
);
3602 struct thread_info
*thread
;
3604 /* Get list of threads. */
3605 remote_threads_info (target
);
3607 thread
= first_thread_of_process (pid
);
3609 inferior_ptid
= thread
->ptid
;
3611 inferior_ptid
= pid_to_ptid (pid
);
3613 /* Invalidate our notion of the remote current thread. */
3614 record_currthread (minus_one_ptid
);
3618 /* Now, if we have thread information, update inferior_ptid. */
3619 inferior_ptid
= remote_current_thread (inferior_ptid
);
3621 /* Add the main thread to the thread list. */
3622 add_thread_silent (inferior_ptid
);
3625 /* Next, if the target can specify a description, read it. We do
3626 this before anything involving memory or registers. */
3627 target_find_description ();
3631 /* Use the previously fetched status. */
3632 gdb_assert (wait_status
!= NULL
);
3634 if (target_can_async_p ())
3636 struct stop_reply
*stop_reply
;
3637 struct cleanup
*old_chain
;
3639 stop_reply
= stop_reply_xmalloc ();
3640 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3641 remote_parse_stop_reply (wait_status
, stop_reply
);
3642 discard_cleanups (old_chain
);
3643 push_stop_reply (stop_reply
);
3645 target_async (inferior_event_handler
, 0);
3649 gdb_assert (wait_status
!= NULL
);
3650 strcpy (rs
->buf
, wait_status
);
3651 rs
->cached_wait_status
= 1;
3655 gdb_assert (wait_status
== NULL
);
3659 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
3661 extended_remote_attach_1 (ops
, args
, from_tty
);
3664 /* Convert hex digit A to a number. */
3669 if (a
>= '0' && a
<= '9')
3671 else if (a
>= 'a' && a
<= 'f')
3672 return a
- 'a' + 10;
3673 else if (a
>= 'A' && a
<= 'F')
3674 return a
- 'A' + 10;
3676 error (_("Reply contains invalid hex digit %d"), a
);
3680 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
3684 for (i
= 0; i
< count
; i
++)
3686 if (hex
[0] == 0 || hex
[1] == 0)
3688 /* Hex string is short, or of uneven length.
3689 Return the count that has been converted so far. */
3692 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
3698 /* Convert number NIB to a hex digit. */
3706 return 'a' + nib
- 10;
3710 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
3713 /* May use a length, or a nul-terminated string as input. */
3715 count
= strlen ((char *) bin
);
3717 for (i
= 0; i
< count
; i
++)
3719 *hex
++ = tohex ((*bin
>> 4) & 0xf);
3720 *hex
++ = tohex (*bin
++ & 0xf);
3726 /* Check for the availability of vCont. This function should also check
3730 remote_vcont_probe (struct remote_state
*rs
)
3734 strcpy (rs
->buf
, "vCont?");
3736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3739 /* Make sure that the features we assume are supported. */
3740 if (strncmp (buf
, "vCont", 5) == 0)
3743 int support_s
, support_S
, support_c
, support_C
;
3749 rs
->support_vCont_t
= 0;
3750 while (p
&& *p
== ';')
3753 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3755 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3757 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3759 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3761 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3762 rs
->support_vCont_t
= 1;
3764 p
= strchr (p
, ';');
3767 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
3768 BUF will make packet_ok disable the packet. */
3769 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
3773 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
3776 /* Helper function for building "vCont" resumptions. Write a
3777 resumption to P. ENDP points to one-passed-the-end of the buffer
3778 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
3779 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
3780 resumed thread should be single-stepped and/or signalled. If PTID
3781 equals minus_one_ptid, then all threads are resumed; if PTID
3782 represents a process, then all threads of the process are resumed;
3783 the thread to be stepped and/or signalled is given in the global
3787 append_resumption (char *p
, char *endp
,
3788 ptid_t ptid
, int step
, enum target_signal siggnal
)
3790 struct remote_state
*rs
= get_remote_state ();
3792 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3793 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
3795 p
+= xsnprintf (p
, endp
- p
, ";s");
3796 else if (siggnal
!= TARGET_SIGNAL_0
)
3797 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
3799 p
+= xsnprintf (p
, endp
- p
, ";c");
3801 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
3805 /* All (-1) threads of process. */
3806 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
3808 p
+= xsnprintf (p
, endp
- p
, ":");
3809 p
= write_ptid (p
, endp
, nptid
);
3811 else if (!ptid_equal (ptid
, minus_one_ptid
))
3813 p
+= xsnprintf (p
, endp
- p
, ":");
3814 p
= write_ptid (p
, endp
, ptid
);
3820 /* Resume the remote inferior by using a "vCont" packet. The thread
3821 to be resumed is PTID; STEP and SIGGNAL indicate whether the
3822 resumed thread should be single-stepped and/or signalled. If PTID
3823 equals minus_one_ptid, then all threads are resumed; the thread to
3824 be stepped and/or signalled is given in the global INFERIOR_PTID.
3825 This function returns non-zero iff it resumes the inferior.
3827 This function issues a strict subset of all possible vCont commands at the
3831 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3833 struct remote_state
*rs
= get_remote_state ();
3837 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
3838 remote_vcont_probe (rs
);
3840 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
3844 endp
= rs
->buf
+ get_remote_packet_size ();
3846 /* If we could generate a wider range of packets, we'd have to worry
3847 about overflowing BUF. Should there be a generic
3848 "multi-part-packet" packet? */
3850 p
+= xsnprintf (p
, endp
- p
, "vCont");
3852 if (ptid_equal (ptid
, magic_null_ptid
))
3854 /* MAGIC_NULL_PTID means that we don't have any active threads,
3855 so we don't have any TID numbers the inferior will
3856 understand. Make sure to only send forms that do not specify
3858 p
= append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
3860 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
3862 /* Resume all threads (of all processes, or of a single
3863 process), with preference for INFERIOR_PTID. This assumes
3864 inferior_ptid belongs to the set of all threads we are about
3866 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
3868 /* Step inferior_ptid, with or without signal. */
3869 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
3872 /* And continue others without a signal. */
3873 p
= append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
3877 /* Scheduler locking; resume only PTID. */
3878 p
= append_resumption (p
, endp
, ptid
, step
, siggnal
);
3881 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
3886 /* In non-stop, the stub replies to vCont with "OK". The stop
3887 reply will be reported asynchronously by means of a `%Stop'
3889 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3890 if (strcmp (rs
->buf
, "OK") != 0)
3891 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
3897 /* Tell the remote machine to resume. */
3899 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
3901 static int last_sent_step
;
3904 remote_resume (struct target_ops
*ops
,
3905 ptid_t ptid
, int step
, enum target_signal siggnal
)
3907 struct remote_state
*rs
= get_remote_state ();
3910 last_sent_signal
= siggnal
;
3911 last_sent_step
= step
;
3913 /* Update the inferior on signals to silently pass, if they've changed. */
3914 remote_pass_signals ();
3916 /* The vCont packet doesn't need to specify threads via Hc. */
3917 /* No reverse support (yet) for vCont. */
3918 if (execution_direction
!= EXEC_REVERSE
)
3919 if (remote_vcont_resume (ptid
, step
, siggnal
))
3922 /* All other supported resume packets do use Hc, so set the continue
3924 if (ptid_equal (ptid
, minus_one_ptid
))
3925 set_continue_thread (any_thread_ptid
);
3927 set_continue_thread (ptid
);
3930 if (execution_direction
== EXEC_REVERSE
)
3932 /* We don't pass signals to the target in reverse exec mode. */
3933 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
3934 warning (" - Can't pass signal %d to target in reverse: ignored.\n",
3938 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
3939 error (_("Remote reverse-step not supported."));
3941 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
3942 error (_("Remote reverse-continue not supported."));
3944 strcpy (buf
, step
? "bs" : "bc");
3946 else if (siggnal
!= TARGET_SIGNAL_0
)
3948 buf
[0] = step
? 'S' : 'C';
3949 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
3950 buf
[2] = tohex (((int) siggnal
) & 0xf);
3954 strcpy (buf
, step
? "s" : "c");
3959 /* We are about to start executing the inferior, let's register it
3960 with the event loop. NOTE: this is the one place where all the
3961 execution commands end up. We could alternatively do this in each
3962 of the execution commands in infcmd.c. */
3963 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
3964 into infcmd.c in order to allow inferior function calls to work
3965 NOT asynchronously. */
3966 if (target_can_async_p ())
3967 target_async (inferior_event_handler
, 0);
3969 /* We've just told the target to resume. The remote server will
3970 wait for the inferior to stop, and then send a stop reply. In
3971 the mean time, we can't start another command/query ourselves
3972 because the stub wouldn't be ready to process it. This applies
3973 only to the base all-stop protocol, however. In non-stop (which
3974 only supports vCont), the stub replies with an "OK", and is
3975 immediate able to process further serial input. */
3977 rs
->waiting_for_stop_reply
= 1;
3981 /* Set up the signal handler for SIGINT, while the target is
3982 executing, ovewriting the 'regular' SIGINT signal handler. */
3984 initialize_sigint_signal_handler (void)
3986 signal (SIGINT
, handle_remote_sigint
);
3989 /* Signal handler for SIGINT, while the target is executing. */
3991 handle_remote_sigint (int sig
)
3993 signal (sig
, handle_remote_sigint_twice
);
3994 mark_async_signal_handler_wrapper (sigint_remote_token
);
3997 /* Signal handler for SIGINT, installed after SIGINT has already been
3998 sent once. It will take effect the second time that the user sends
4001 handle_remote_sigint_twice (int sig
)
4003 signal (sig
, handle_remote_sigint
);
4004 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4007 /* Perform the real interruption of the target execution, in response
4010 async_remote_interrupt (gdb_client_data arg
)
4013 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4015 target_stop (inferior_ptid
);
4018 /* Perform interrupt, if the first attempt did not succeed. Just give
4019 up on the target alltogether. */
4021 async_remote_interrupt_twice (gdb_client_data arg
)
4024 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4029 /* Reinstall the usual SIGINT handlers, after the target has
4032 cleanup_sigint_signal_handler (void *dummy
)
4034 signal (SIGINT
, handle_sigint
);
4037 /* Send ^C to target to halt it. Target will respond, and send us a
4039 static void (*ofunc
) (int);
4041 /* The command line interface's stop routine. This function is installed
4042 as a signal handler for SIGINT. The first time a user requests a
4043 stop, we call remote_stop to send a break or ^C. If there is no
4044 response from the target (it didn't stop when the user requested it),
4045 we ask the user if he'd like to detach from the target. */
4047 remote_interrupt (int signo
)
4049 /* If this doesn't work, try more severe steps. */
4050 signal (signo
, remote_interrupt_twice
);
4052 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4055 /* The user typed ^C twice. */
4058 remote_interrupt_twice (int signo
)
4060 signal (signo
, ofunc
);
4061 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4062 signal (signo
, remote_interrupt
);
4065 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4066 thread, all threads of a remote process, or all threads of all
4070 remote_stop_ns (ptid_t ptid
)
4072 struct remote_state
*rs
= get_remote_state ();
4074 char *endp
= rs
->buf
+ get_remote_packet_size ();
4076 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4077 remote_vcont_probe (rs
);
4079 if (!rs
->support_vCont_t
)
4080 error (_("Remote server does not support stopping threads"));
4082 if (ptid_equal (ptid
, minus_one_ptid
)
4083 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4084 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4089 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4091 if (ptid_is_pid (ptid
))
4092 /* All (-1) threads of process. */
4093 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4096 /* Small optimization: if we already have a stop reply for
4097 this thread, no use in telling the stub we want this
4099 if (peek_stop_reply (ptid
))
4105 p
= write_ptid (p
, endp
, nptid
);
4108 /* In non-stop, we get an immediate OK reply. The stop reply will
4109 come in asynchronously by notification. */
4111 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4112 if (strcmp (rs
->buf
, "OK") != 0)
4113 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4116 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4117 remote target. It is undefined which thread of which process
4118 reports the stop. */
4121 remote_stop_as (ptid_t ptid
)
4123 struct remote_state
*rs
= get_remote_state ();
4125 /* If the inferior is stopped already, but the core didn't know
4126 about it yet, just ignore the request. The cached wait status
4127 will be collected in remote_wait. */
4128 if (rs
->cached_wait_status
)
4131 /* Send interrupt_sequence to remote target. */
4132 send_interrupt_sequence ();
4135 /* This is the generic stop called via the target vector. When a target
4136 interrupt is requested, either by the command line or the GUI, we
4137 will eventually end up here. */
4140 remote_stop (ptid_t ptid
)
4143 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4146 remote_stop_ns (ptid
);
4148 remote_stop_as (ptid
);
4151 /* Ask the user what to do when an interrupt is received. */
4154 interrupt_query (void)
4156 target_terminal_ours ();
4158 if (target_can_async_p ())
4160 signal (SIGINT
, handle_sigint
);
4161 deprecated_throw_reason (RETURN_QUIT
);
4165 if (query (_("Interrupted while waiting for the program.\n\
4166 Give up (and stop debugging it)? ")))
4169 deprecated_throw_reason (RETURN_QUIT
);
4173 target_terminal_inferior ();
4176 /* Enable/disable target terminal ownership. Most targets can use
4177 terminal groups to control terminal ownership. Remote targets are
4178 different in that explicit transfer of ownership to/from GDB/target
4182 remote_terminal_inferior (void)
4184 if (!target_async_permitted
)
4185 /* Nothing to do. */
4188 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4189 idempotent. The event-loop GDB talking to an asynchronous target
4190 with a synchronous command calls this function from both
4191 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4192 transfer the terminal to the target when it shouldn't this guard
4194 if (!remote_async_terminal_ours_p
)
4196 delete_file_handler (input_fd
);
4197 remote_async_terminal_ours_p
= 0;
4198 initialize_sigint_signal_handler ();
4199 /* NOTE: At this point we could also register our selves as the
4200 recipient of all input. Any characters typed could then be
4201 passed on down to the target. */
4205 remote_terminal_ours (void)
4207 if (!target_async_permitted
)
4208 /* Nothing to do. */
4211 /* See FIXME in remote_terminal_inferior. */
4212 if (remote_async_terminal_ours_p
)
4214 cleanup_sigint_signal_handler (NULL
);
4215 add_file_handler (input_fd
, stdin_event_handler
, 0);
4216 remote_async_terminal_ours_p
= 1;
4220 remote_console_output (char *msg
)
4224 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4227 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4230 fputs_unfiltered (tb
, gdb_stdtarg
);
4232 gdb_flush (gdb_stdtarg
);
4235 typedef struct cached_reg
4238 gdb_byte data
[MAX_REGISTER_SIZE
];
4241 DEF_VEC_O(cached_reg_t
);
4245 struct stop_reply
*next
;
4249 struct target_waitstatus ws
;
4251 VEC(cached_reg_t
) *regcache
;
4253 int stopped_by_watchpoint_p
;
4254 CORE_ADDR watch_data_address
;
4260 /* The list of already fetched and acknowledged stop events. */
4261 static struct stop_reply
*stop_reply_queue
;
4263 static struct stop_reply
*
4264 stop_reply_xmalloc (void)
4266 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4272 stop_reply_xfree (struct stop_reply
*r
)
4276 VEC_free (cached_reg_t
, r
->regcache
);
4281 /* Discard all pending stop replies of inferior PID. If PID is -1,
4282 discard everything. */
4285 discard_pending_stop_replies (int pid
)
4287 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4289 /* Discard the in-flight notification. */
4290 if (pending_stop_reply
!= NULL
4292 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4294 stop_reply_xfree (pending_stop_reply
);
4295 pending_stop_reply
= NULL
;
4298 /* Discard the stop replies we have already pulled with
4300 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4304 || ptid_get_pid (reply
->ptid
) == pid
)
4306 if (reply
== stop_reply_queue
)
4307 stop_reply_queue
= reply
->next
;
4309 prev
->next
= reply
->next
;
4311 stop_reply_xfree (reply
);
4318 /* Cleanup wrapper. */
4321 do_stop_reply_xfree (void *arg
)
4323 struct stop_reply
*r
= arg
;
4324 stop_reply_xfree (r
);
4327 /* Look for a queued stop reply belonging to PTID. If one is found,
4328 remove it from the queue, and return it. Returns NULL if none is
4329 found. If there are still queued events left to process, tell the
4330 event loop to get back to target_wait soon. */
4332 static struct stop_reply
*
4333 queued_stop_reply (ptid_t ptid
)
4335 struct stop_reply
*it
, *prev
;
4336 struct stop_reply head
;
4338 head
.next
= stop_reply_queue
;
4343 if (!ptid_equal (ptid
, minus_one_ptid
))
4344 for (; it
; prev
= it
, it
= it
->next
)
4345 if (ptid_equal (ptid
, it
->ptid
))
4350 prev
->next
= it
->next
;
4354 stop_reply_queue
= head
.next
;
4356 if (stop_reply_queue
)
4357 /* There's still at least an event left. */
4358 mark_async_event_handler (remote_async_inferior_event_token
);
4363 /* Push a fully parsed stop reply in the stop reply queue. Since we
4364 know that we now have at least one queued event left to pass to the
4365 core side, tell the event loop to get back to target_wait soon. */
4368 push_stop_reply (struct stop_reply
*new_event
)
4370 struct stop_reply
*event
;
4372 if (stop_reply_queue
)
4374 for (event
= stop_reply_queue
;
4375 event
&& event
->next
;
4376 event
= event
->next
)
4379 event
->next
= new_event
;
4382 stop_reply_queue
= new_event
;
4384 mark_async_event_handler (remote_async_inferior_event_token
);
4387 /* Returns true if we have a stop reply for PTID. */
4390 peek_stop_reply (ptid_t ptid
)
4392 struct stop_reply
*it
;
4394 for (it
= stop_reply_queue
; it
; it
= it
->next
)
4395 if (ptid_equal (ptid
, it
->ptid
))
4397 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
4404 /* Parse the stop reply in BUF. Either the function succeeds, and the
4405 result is stored in EVENT, or throws an error. */
4408 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
4410 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4414 event
->ptid
= null_ptid
;
4415 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
4416 event
->ws
.value
.integer
= 0;
4417 event
->solibs_changed
= 0;
4418 event
->replay_event
= 0;
4419 event
->stopped_by_watchpoint_p
= 0;
4420 event
->regcache
= NULL
;
4424 case 'T': /* Status with PC, SP, FP, ... */
4425 /* Expedited reply, containing Signal, {regno, reg} repeat. */
4426 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
4428 n... = register number
4429 r... = register contents
4432 p
= &buf
[3]; /* after Txx */
4440 /* If the packet contains a register number, save it in
4441 pnum and set p1 to point to the character following it.
4442 Otherwise p1 points to p. */
4444 /* If this packet is an awatch packet, don't parse the 'a'
4445 as a register number. */
4447 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
4449 /* Read the ``P'' register number. */
4450 pnum
= strtol (p
, &p_temp
, 16);
4456 if (p1
== p
) /* No register number present here. */
4458 p1
= strchr (p
, ':');
4460 error (_("Malformed packet(a) (missing colon): %s\n\
4463 if (strncmp (p
, "thread", p1
- p
) == 0)
4464 event
->ptid
= read_ptid (++p1
, &p
);
4465 else if ((strncmp (p
, "watch", p1
- p
) == 0)
4466 || (strncmp (p
, "rwatch", p1
- p
) == 0)
4467 || (strncmp (p
, "awatch", p1
- p
) == 0))
4469 event
->stopped_by_watchpoint_p
= 1;
4470 p
= unpack_varlen_hex (++p1
, &addr
);
4471 event
->watch_data_address
= (CORE_ADDR
) addr
;
4473 else if (strncmp (p
, "library", p1
- p
) == 0)
4477 while (*p_temp
&& *p_temp
!= ';')
4480 event
->solibs_changed
= 1;
4483 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
4485 /* NO_HISTORY event.
4486 p1 will indicate "begin" or "end", but
4487 it makes no difference for now, so ignore it. */
4488 event
->replay_event
= 1;
4489 p_temp
= strchr (p1
+ 1, ';');
4495 /* Silently skip unknown optional info. */
4496 p_temp
= strchr (p1
+ 1, ';');
4503 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
4504 cached_reg_t cached_reg
;
4509 error (_("Malformed packet(b) (missing colon): %s\n\
4515 error (_("Remote sent bad register number %s: %s\n\
4517 phex_nz (pnum
, 0), p
, buf
);
4519 cached_reg
.num
= reg
->regnum
;
4521 fieldsize
= hex2bin (p
, cached_reg
.data
,
4522 register_size (target_gdbarch
,
4525 if (fieldsize
< register_size (target_gdbarch
,
4527 warning (_("Remote reply is too short: %s"), buf
);
4529 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
4533 error (_("Remote register badly formatted: %s\nhere: %s"),
4538 case 'S': /* Old style status, just signal only. */
4539 if (event
->solibs_changed
)
4540 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
4541 else if (event
->replay_event
)
4542 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
4545 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4546 event
->ws
.value
.sig
= (enum target_signal
)
4547 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
4550 case 'W': /* Target exited. */
4557 /* GDB used to accept only 2 hex chars here. Stubs should
4558 only send more if they detect GDB supports multi-process
4560 p
= unpack_varlen_hex (&buf
[1], &value
);
4564 /* The remote process exited. */
4565 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
4566 event
->ws
.value
.integer
= value
;
4570 /* The remote process exited with a signal. */
4571 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
4572 event
->ws
.value
.sig
= (enum target_signal
) value
;
4575 /* If no process is specified, assume inferior_ptid. */
4576 pid
= ptid_get_pid (inferior_ptid
);
4585 else if (strncmp (p
,
4586 "process:", sizeof ("process:") - 1) == 0)
4589 p
+= sizeof ("process:") - 1;
4590 unpack_varlen_hex (p
, &upid
);
4594 error (_("unknown stop reply packet: %s"), buf
);
4597 error (_("unknown stop reply packet: %s"), buf
);
4598 event
->ptid
= pid_to_ptid (pid
);
4603 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
4604 error (_("No process or thread specified in stop reply: %s"), buf
);
4607 /* When the stub wants to tell GDB about a new stop reply, it sends a
4608 stop notification (%Stop). Those can come it at any time, hence,
4609 we have to make sure that any pending putpkt/getpkt sequence we're
4610 making is finished, before querying the stub for more events with
4611 vStopped. E.g., if we started a vStopped sequence immediatelly
4612 upon receiving the %Stop notification, something like this could
4620 1.6) <-- (registers reply to step #1.3)
4622 Obviously, the reply in step #1.6 would be unexpected to a vStopped
4625 To solve this, whenever we parse a %Stop notification sucessfully,
4626 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
4627 doing whatever we were doing:
4633 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
4634 2.5) <-- (registers reply to step #2.3)
4636 Eventualy after step #2.5, we return to the event loop, which
4637 notices there's an event on the
4638 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
4639 associated callback --- the function below. At this point, we're
4640 always safe to start a vStopped sequence. :
4643 2.7) <-- T05 thread:2
4649 remote_get_pending_stop_replies (void)
4651 struct remote_state
*rs
= get_remote_state ();
4653 if (pending_stop_reply
)
4656 putpkt ("vStopped");
4658 /* Now we can rely on it. */
4659 push_stop_reply (pending_stop_reply
);
4660 pending_stop_reply
= NULL
;
4664 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4665 if (strcmp (rs
->buf
, "OK") == 0)
4669 struct cleanup
*old_chain
;
4670 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
4672 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4673 remote_parse_stop_reply (rs
->buf
, stop_reply
);
4676 putpkt ("vStopped");
4678 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4680 /* Now we can rely on it. */
4681 discard_cleanups (old_chain
);
4682 push_stop_reply (stop_reply
);
4685 /* We got an unknown stop reply. */
4686 do_cleanups (old_chain
);
4693 /* Called when it is decided that STOP_REPLY holds the info of the
4694 event that is to be returned to the core. This function always
4695 destroys STOP_REPLY. */
4698 process_stop_reply (struct stop_reply
*stop_reply
,
4699 struct target_waitstatus
*status
)
4703 *status
= stop_reply
->ws
;
4704 ptid
= stop_reply
->ptid
;
4706 /* If no thread/process was reported by the stub, assume the current
4708 if (ptid_equal (ptid
, null_ptid
))
4709 ptid
= inferior_ptid
;
4711 if (status
->kind
!= TARGET_WAITKIND_EXITED
4712 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
4714 /* Expedited registers. */
4715 if (stop_reply
->regcache
)
4717 struct regcache
*regcache
4718 = get_thread_arch_regcache (ptid
, target_gdbarch
);
4723 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
4725 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
4726 VEC_free (cached_reg_t
, stop_reply
->regcache
);
4729 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
4730 remote_watch_data_address
= stop_reply
->watch_data_address
;
4732 remote_notice_new_inferior (ptid
, 0);
4735 stop_reply_xfree (stop_reply
);
4739 /* The non-stop mode version of target_wait. */
4742 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
4744 struct remote_state
*rs
= get_remote_state ();
4745 struct stop_reply
*stop_reply
;
4748 /* If in non-stop mode, get out of getpkt even if a
4749 notification is received. */
4751 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
4758 case 'E': /* Error of some sort. */
4759 /* We're out of sync with the target now. Did it continue
4760 or not? We can't tell which thread it was in non-stop,
4761 so just ignore this. */
4762 warning (_("Remote failure reply: %s"), rs
->buf
);
4764 case 'O': /* Console output. */
4765 remote_console_output (rs
->buf
+ 1);
4768 warning (_("Invalid remote reply: %s"), rs
->buf
);
4772 /* Acknowledge a pending stop reply that may have arrived in the
4774 if (pending_stop_reply
!= NULL
)
4775 remote_get_pending_stop_replies ();
4777 /* If indeed we noticed a stop reply, we're done. */
4778 stop_reply
= queued_stop_reply (ptid
);
4779 if (stop_reply
!= NULL
)
4780 return process_stop_reply (stop_reply
, status
);
4782 /* Still no event. If we're just polling for an event, then
4783 return to the event loop. */
4784 if (options
& TARGET_WNOHANG
)
4786 status
->kind
= TARGET_WAITKIND_IGNORE
;
4787 return minus_one_ptid
;
4790 /* Otherwise do a blocking wait. */
4791 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
4796 /* Wait until the remote machine stops, then return, storing status in
4797 STATUS just as `wait' would. */
4800 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
4802 struct remote_state
*rs
= get_remote_state ();
4803 ptid_t event_ptid
= null_ptid
;
4805 struct stop_reply
*stop_reply
;
4809 status
->kind
= TARGET_WAITKIND_IGNORE
;
4810 status
->value
.integer
= 0;
4812 stop_reply
= queued_stop_reply (ptid
);
4813 if (stop_reply
!= NULL
)
4814 return process_stop_reply (stop_reply
, status
);
4816 if (rs
->cached_wait_status
)
4817 /* Use the cached wait status, but only once. */
4818 rs
->cached_wait_status
= 0;
4823 if (!target_is_async_p ())
4825 ofunc
= signal (SIGINT
, remote_interrupt
);
4826 /* If the user hit C-c before this packet, or between packets,
4827 pretend that it was hit right here. */
4831 remote_interrupt (SIGINT
);
4835 /* FIXME: cagney/1999-09-27: If we're in async mode we should
4836 _never_ wait for ever -> test on target_is_async_p().
4837 However, before we do that we need to ensure that the caller
4838 knows how to take the target into/out of async mode. */
4839 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
4840 if (!target_is_async_p ())
4841 signal (SIGINT
, ofunc
);
4846 remote_stopped_by_watchpoint_p
= 0;
4848 /* We got something. */
4849 rs
->waiting_for_stop_reply
= 0;
4853 case 'E': /* Error of some sort. */
4854 /* We're out of sync with the target now. Did it continue or
4855 not? Not is more likely, so report a stop. */
4856 warning (_("Remote failure reply: %s"), buf
);
4857 status
->kind
= TARGET_WAITKIND_STOPPED
;
4858 status
->value
.sig
= TARGET_SIGNAL_0
;
4860 case 'F': /* File-I/O request. */
4861 remote_fileio_request (buf
);
4863 case 'T': case 'S': case 'X': case 'W':
4865 struct stop_reply
*stop_reply
;
4866 struct cleanup
*old_chain
;
4868 stop_reply
= stop_reply_xmalloc ();
4869 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4870 remote_parse_stop_reply (buf
, stop_reply
);
4871 discard_cleanups (old_chain
);
4872 event_ptid
= process_stop_reply (stop_reply
, status
);
4875 case 'O': /* Console output. */
4876 remote_console_output (buf
+ 1);
4878 /* The target didn't really stop; keep waiting. */
4879 rs
->waiting_for_stop_reply
= 1;
4883 if (last_sent_signal
!= TARGET_SIGNAL_0
)
4885 /* Zero length reply means that we tried 'S' or 'C' and the
4886 remote system doesn't support it. */
4887 target_terminal_ours_for_output ();
4889 ("Can't send signals to this remote system. %s not sent.\n",
4890 target_signal_to_name (last_sent_signal
));
4891 last_sent_signal
= TARGET_SIGNAL_0
;
4892 target_terminal_inferior ();
4894 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
4895 putpkt ((char *) buf
);
4897 /* We just told the target to resume, so a stop reply is in
4899 rs
->waiting_for_stop_reply
= 1;
4902 /* else fallthrough */
4904 warning (_("Invalid remote reply: %s"), buf
);
4906 rs
->waiting_for_stop_reply
= 1;
4910 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
4912 /* Nothing interesting happened. If we're doing a non-blocking
4913 poll, we're done. Otherwise, go back to waiting. */
4914 if (options
& TARGET_WNOHANG
)
4915 return minus_one_ptid
;
4919 else if (status
->kind
!= TARGET_WAITKIND_EXITED
4920 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
4922 if (!ptid_equal (event_ptid
, null_ptid
))
4923 record_currthread (event_ptid
);
4925 event_ptid
= inferior_ptid
;
4928 /* A process exit. Invalidate our notion of current thread. */
4929 record_currthread (minus_one_ptid
);
4934 /* Wait until the remote machine stops, then return, storing status in
4935 STATUS just as `wait' would. */
4938 remote_wait (struct target_ops
*ops
,
4939 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
4944 event_ptid
= remote_wait_ns (ptid
, status
, options
);
4946 event_ptid
= remote_wait_as (ptid
, status
, options
);
4948 if (target_can_async_p ())
4950 /* If there are are events left in the queue tell the event loop
4952 if (stop_reply_queue
)
4953 mark_async_event_handler (remote_async_inferior_event_token
);
4959 /* Fetch a single register using a 'p' packet. */
4962 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
4964 struct remote_state
*rs
= get_remote_state ();
4966 char regp
[MAX_REGISTER_SIZE
];
4969 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
4972 if (reg
->pnum
== -1)
4977 p
+= hexnumstr (p
, reg
->pnum
);
4980 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4984 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
4988 case PACKET_UNKNOWN
:
4991 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
4992 gdbarch_register_name (get_regcache_arch (regcache
),
4997 /* If this register is unfetchable, tell the regcache. */
5000 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5004 /* Otherwise, parse and supply the value. */
5010 error (_("fetch_register_using_p: early buf termination"));
5012 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5015 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5019 /* Fetch the registers included in the target's 'g' packet. */
5022 send_g_packet (void)
5024 struct remote_state
*rs
= get_remote_state ();
5027 sprintf (rs
->buf
, "g");
5028 remote_send (&rs
->buf
, &rs
->buf_size
);
5030 /* We can get out of synch in various cases. If the first character
5031 in the buffer is not a hex character, assume that has happened
5032 and try to fetch another packet to read. */
5033 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5034 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5035 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5036 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5039 fprintf_unfiltered (gdb_stdlog
,
5040 "Bad register packet; fetching a new packet\n");
5041 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5044 buf_len
= strlen (rs
->buf
);
5046 /* Sanity check the received packet. */
5047 if (buf_len
% 2 != 0)
5048 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5054 process_g_packet (struct regcache
*regcache
)
5056 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5057 struct remote_state
*rs
= get_remote_state ();
5058 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5063 buf_len
= strlen (rs
->buf
);
5065 /* Further sanity checks, with knowledge of the architecture. */
5066 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5067 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5069 /* Save the size of the packet sent to us by the target. It is used
5070 as a heuristic when determining the max size of packets that the
5071 target can safely receive. */
5072 if (rsa
->actual_register_packet_size
== 0)
5073 rsa
->actual_register_packet_size
= buf_len
;
5075 /* If this is smaller than we guessed the 'g' packet would be,
5076 update our records. A 'g' reply that doesn't include a register's
5077 value implies either that the register is not available, or that
5078 the 'p' packet must be used. */
5079 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5081 rsa
->sizeof_g_packet
= buf_len
/ 2;
5083 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5085 if (rsa
->regs
[i
].pnum
== -1)
5088 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5089 rsa
->regs
[i
].in_g_packet
= 0;
5091 rsa
->regs
[i
].in_g_packet
= 1;
5095 regs
= alloca (rsa
->sizeof_g_packet
);
5097 /* Unimplemented registers read as all bits zero. */
5098 memset (regs
, 0, rsa
->sizeof_g_packet
);
5100 /* Reply describes registers byte by byte, each byte encoded as two
5101 hex characters. Suck them all up, then supply them to the
5102 register cacheing/storage mechanism. */
5105 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5107 if (p
[0] == 0 || p
[1] == 0)
5108 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5109 internal_error (__FILE__
, __LINE__
,
5110 "unexpected end of 'g' packet reply");
5112 if (p
[0] == 'x' && p
[1] == 'x')
5113 regs
[i
] = 0; /* 'x' */
5115 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5121 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5123 struct packet_reg
*r
= &rsa
->regs
[i
];
5126 if (r
->offset
* 2 >= strlen (rs
->buf
))
5127 /* This shouldn't happen - we adjusted in_g_packet above. */
5128 internal_error (__FILE__
, __LINE__
,
5129 "unexpected end of 'g' packet reply");
5130 else if (rs
->buf
[r
->offset
* 2] == 'x')
5132 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5133 /* The register isn't available, mark it as such (at
5134 the same time setting the value to zero). */
5135 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5138 regcache_raw_supply (regcache
, r
->regnum
,
5146 fetch_registers_using_g (struct regcache
*regcache
)
5149 process_g_packet (regcache
);
5153 remote_fetch_registers (struct target_ops
*ops
,
5154 struct regcache
*regcache
, int regnum
)
5156 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5159 set_general_thread (inferior_ptid
);
5163 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5164 gdb_assert (reg
!= NULL
);
5166 /* If this register might be in the 'g' packet, try that first -
5167 we are likely to read more than one register. If this is the
5168 first 'g' packet, we might be overly optimistic about its
5169 contents, so fall back to 'p'. */
5170 if (reg
->in_g_packet
)
5172 fetch_registers_using_g (regcache
);
5173 if (reg
->in_g_packet
)
5177 if (fetch_register_using_p (regcache
, reg
))
5180 /* This register is not available. */
5181 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5186 fetch_registers_using_g (regcache
);
5188 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5189 if (!rsa
->regs
[i
].in_g_packet
)
5190 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5192 /* This register is not available. */
5193 regcache_raw_supply (regcache
, i
, NULL
);
5197 /* Prepare to store registers. Since we may send them all (using a
5198 'G' request), we have to read out the ones we don't want to change
5202 remote_prepare_to_store (struct regcache
*regcache
)
5204 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5206 gdb_byte buf
[MAX_REGISTER_SIZE
];
5208 /* Make sure the entire registers array is valid. */
5209 switch (remote_protocol_packets
[PACKET_P
].support
)
5211 case PACKET_DISABLE
:
5212 case PACKET_SUPPORT_UNKNOWN
:
5213 /* Make sure all the necessary registers are cached. */
5214 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5215 if (rsa
->regs
[i
].in_g_packet
)
5216 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5223 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5224 packet was not recognized. */
5227 store_register_using_P (const struct regcache
*regcache
,
5228 struct packet_reg
*reg
)
5230 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5231 struct remote_state
*rs
= get_remote_state ();
5232 /* Try storing a single register. */
5233 char *buf
= rs
->buf
;
5234 gdb_byte regp
[MAX_REGISTER_SIZE
];
5237 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5240 if (reg
->pnum
== -1)
5243 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5244 p
= buf
+ strlen (buf
);
5245 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5246 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5248 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5250 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5255 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5256 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5257 case PACKET_UNKNOWN
:
5260 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5264 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5265 contents of the register cache buffer. FIXME: ignores errors. */
5268 store_registers_using_G (const struct regcache
*regcache
)
5270 struct remote_state
*rs
= get_remote_state ();
5271 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5275 /* Extract all the registers in the regcache copying them into a
5279 regs
= alloca (rsa
->sizeof_g_packet
);
5280 memset (regs
, 0, rsa
->sizeof_g_packet
);
5281 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5283 struct packet_reg
*r
= &rsa
->regs
[i
];
5285 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5289 /* Command describes registers byte by byte,
5290 each byte encoded as two hex characters. */
5293 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5295 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5297 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5298 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5299 error (_("Could not write registers; remote failure reply '%s'"),
5303 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
5304 of the register cache buffer. FIXME: ignores errors. */
5307 remote_store_registers (struct target_ops
*ops
,
5308 struct regcache
*regcache
, int regnum
)
5310 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5313 set_general_thread (inferior_ptid
);
5317 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5318 gdb_assert (reg
!= NULL
);
5320 /* Always prefer to store registers using the 'P' packet if
5321 possible; we often change only a small number of registers.
5322 Sometimes we change a larger number; we'd need help from a
5323 higher layer to know to use 'G'. */
5324 if (store_register_using_P (regcache
, reg
))
5327 /* For now, don't complain if we have no way to write the
5328 register. GDB loses track of unavailable registers too
5329 easily. Some day, this may be an error. We don't have
5330 any way to read the register, either... */
5331 if (!reg
->in_g_packet
)
5334 store_registers_using_G (regcache
);
5338 store_registers_using_G (regcache
);
5340 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5341 if (!rsa
->regs
[i
].in_g_packet
)
5342 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
5343 /* See above for why we do not issue an error here. */
5348 /* Return the number of hex digits in num. */
5351 hexnumlen (ULONGEST num
)
5355 for (i
= 0; num
!= 0; i
++)
5361 /* Set BUF to the minimum number of hex digits representing NUM. */
5364 hexnumstr (char *buf
, ULONGEST num
)
5366 int len
= hexnumlen (num
);
5367 return hexnumnstr (buf
, num
, len
);
5371 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
5374 hexnumnstr (char *buf
, ULONGEST num
, int width
)
5380 for (i
= width
- 1; i
>= 0; i
--)
5382 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
5389 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
5392 remote_address_masked (CORE_ADDR addr
)
5394 int address_size
= remote_address_size
;
5395 /* If "remoteaddresssize" was not set, default to target address size. */
5397 address_size
= gdbarch_addr_bit (target_gdbarch
);
5399 if (address_size
> 0
5400 && address_size
< (sizeof (ULONGEST
) * 8))
5402 /* Only create a mask when that mask can safely be constructed
5403 in a ULONGEST variable. */
5405 mask
= (mask
<< address_size
) - 1;
5411 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
5412 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
5413 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
5414 (which may be more than *OUT_LEN due to escape characters). The
5415 total number of bytes in the output buffer will be at most
5419 remote_escape_output (const gdb_byte
*buffer
, int len
,
5420 gdb_byte
*out_buf
, int *out_len
,
5423 int input_index
, output_index
;
5426 for (input_index
= 0; input_index
< len
; input_index
++)
5428 gdb_byte b
= buffer
[input_index
];
5430 if (b
== '$' || b
== '#' || b
== '}')
5432 /* These must be escaped. */
5433 if (output_index
+ 2 > out_maxlen
)
5435 out_buf
[output_index
++] = '}';
5436 out_buf
[output_index
++] = b
^ 0x20;
5440 if (output_index
+ 1 > out_maxlen
)
5442 out_buf
[output_index
++] = b
;
5446 *out_len
= input_index
;
5447 return output_index
;
5450 /* Convert BUFFER, escaped data LEN bytes long, into binary data
5451 in OUT_BUF. Return the number of bytes written to OUT_BUF.
5452 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
5454 This function reverses remote_escape_output. It allows more
5455 escaped characters than that function does, in particular because
5456 '*' must be escaped to avoid the run-length encoding processing
5457 in reading packets. */
5460 remote_unescape_input (const gdb_byte
*buffer
, int len
,
5461 gdb_byte
*out_buf
, int out_maxlen
)
5463 int input_index
, output_index
;
5468 for (input_index
= 0; input_index
< len
; input_index
++)
5470 gdb_byte b
= buffer
[input_index
];
5472 if (output_index
+ 1 > out_maxlen
)
5474 warning (_("Received too much data from remote target;"
5475 " ignoring overflow."));
5476 return output_index
;
5481 out_buf
[output_index
++] = b
^ 0x20;
5487 out_buf
[output_index
++] = b
;
5491 error (_("Unmatched escape character in target response."));
5493 return output_index
;
5496 /* Determine whether the remote target supports binary downloading.
5497 This is accomplished by sending a no-op memory write of zero length
5498 to the target at the specified address. It does not suffice to send
5499 the whole packet, since many stubs strip the eighth bit and
5500 subsequently compute a wrong checksum, which causes real havoc with
5503 NOTE: This can still lose if the serial line is not eight-bit
5504 clean. In cases like this, the user should clear "remote
5508 check_binary_download (CORE_ADDR addr
)
5510 struct remote_state
*rs
= get_remote_state ();
5512 switch (remote_protocol_packets
[PACKET_X
].support
)
5514 case PACKET_DISABLE
:
5518 case PACKET_SUPPORT_UNKNOWN
:
5524 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5526 p
+= hexnumstr (p
, (ULONGEST
) 0);
5530 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5531 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5533 if (rs
->buf
[0] == '\0')
5536 fprintf_unfiltered (gdb_stdlog
,
5537 "binary downloading NOT suppported by target\n");
5538 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
5543 fprintf_unfiltered (gdb_stdlog
,
5544 "binary downloading suppported by target\n");
5545 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
5552 /* Write memory data directly to the remote machine.
5553 This does not inform the data cache; the data cache uses this.
5554 HEADER is the starting part of the packet.
5555 MEMADDR is the address in the remote memory space.
5556 MYADDR is the address of the buffer in our space.
5557 LEN is the number of bytes.
5558 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
5559 should send data as binary ('X'), or hex-encoded ('M').
5561 The function creates packet of the form
5562 <HEADER><ADDRESS>,<LENGTH>:<DATA>
5564 where encoding of <DATA> is termined by PACKET_FORMAT.
5566 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
5569 Returns the number of bytes transferred, or 0 (setting errno) for
5570 error. Only transfer a single packet. */
5573 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
5574 const gdb_byte
*myaddr
, int len
,
5575 char packet_format
, int use_length
)
5577 struct remote_state
*rs
= get_remote_state ();
5587 if (packet_format
!= 'X' && packet_format
!= 'M')
5588 internal_error (__FILE__
, __LINE__
,
5589 "remote_write_bytes_aux: bad packet format");
5594 payload_size
= get_memory_write_packet_size ();
5596 /* The packet buffer will be large enough for the payload;
5597 get_memory_packet_size ensures this. */
5600 /* Compute the size of the actual payload by subtracting out the
5601 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
5603 payload_size
-= strlen ("$,:#NN");
5605 /* The comma won't be used. */
5607 header_length
= strlen (header
);
5608 payload_size
-= header_length
;
5609 payload_size
-= hexnumlen (memaddr
);
5611 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
5613 strcat (rs
->buf
, header
);
5614 p
= rs
->buf
+ strlen (header
);
5616 /* Compute a best guess of the number of bytes actually transfered. */
5617 if (packet_format
== 'X')
5619 /* Best guess at number of bytes that will fit. */
5620 todo
= min (len
, payload_size
);
5622 payload_size
-= hexnumlen (todo
);
5623 todo
= min (todo
, payload_size
);
5627 /* Num bytes that will fit. */
5628 todo
= min (len
, payload_size
/ 2);
5630 payload_size
-= hexnumlen (todo
);
5631 todo
= min (todo
, payload_size
/ 2);
5635 internal_error (__FILE__
, __LINE__
,
5636 _("minumum packet size too small to write data"));
5638 /* If we already need another packet, then try to align the end
5639 of this packet to a useful boundary. */
5640 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
5641 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
5643 /* Append "<memaddr>". */
5644 memaddr
= remote_address_masked (memaddr
);
5645 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
5652 /* Append <len>. Retain the location/size of <len>. It may need to
5653 be adjusted once the packet body has been created. */
5655 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
5663 /* Append the packet body. */
5664 if (packet_format
== 'X')
5666 /* Binary mode. Send target system values byte by byte, in
5667 increasing byte addresses. Only escape certain critical
5669 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
5672 /* If not all TODO bytes fit, then we'll need another packet. Make
5673 a second try to keep the end of the packet aligned. Don't do
5674 this if the packet is tiny. */
5675 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
5679 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
5681 if (new_nr_bytes
!= nr_bytes
)
5682 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
5687 p
+= payload_length
;
5688 if (use_length
&& nr_bytes
< todo
)
5690 /* Escape chars have filled up the buffer prematurely,
5691 and we have actually sent fewer bytes than planned.
5692 Fix-up the length field of the packet. Use the same
5693 number of characters as before. */
5694 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
5695 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
5700 /* Normal mode: Send target system values byte by byte, in
5701 increasing byte addresses. Each byte is encoded as a two hex
5703 nr_bytes
= bin2hex (myaddr
, p
, todo
);
5707 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5708 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5710 if (rs
->buf
[0] == 'E')
5712 /* There is no correspondance between what the remote protocol
5713 uses for errors and errno codes. We would like a cleaner way
5714 of representing errors (big enough to include errno codes,
5715 bfd_error codes, and others). But for now just return EIO. */
5720 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
5721 fewer bytes than we'd planned. */
5725 /* Write memory data directly to the remote machine.
5726 This does not inform the data cache; the data cache uses this.
5727 MEMADDR is the address in the remote memory space.
5728 MYADDR is the address of the buffer in our space.
5729 LEN is the number of bytes.
5731 Returns number of bytes transferred, or 0 (setting errno) for
5732 error. Only transfer a single packet. */
5735 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
5737 char *packet_format
= 0;
5739 /* Check whether the target supports binary download. */
5740 check_binary_download (memaddr
);
5742 switch (remote_protocol_packets
[PACKET_X
].support
)
5745 packet_format
= "X";
5747 case PACKET_DISABLE
:
5748 packet_format
= "M";
5750 case PACKET_SUPPORT_UNKNOWN
:
5751 internal_error (__FILE__
, __LINE__
,
5752 _("remote_write_bytes: bad internal state"));
5754 internal_error (__FILE__
, __LINE__
, _("bad switch"));
5757 return remote_write_bytes_aux (packet_format
,
5758 memaddr
, myaddr
, len
, packet_format
[0], 1);
5761 /* Read memory data directly from the remote machine.
5762 This does not use the data cache; the data cache uses this.
5763 MEMADDR is the address in the remote memory space.
5764 MYADDR is the address of the buffer in our space.
5765 LEN is the number of bytes.
5767 Returns number of bytes transferred, or 0 for error. */
5769 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
5770 remote targets) shouldn't attempt to read the entire buffer.
5771 Instead it should read a single packet worth of data and then
5772 return the byte size of that packet to the caller. The caller (its
5773 caller and its callers caller ;-) already contains code for
5774 handling partial reads. */
5777 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
5779 struct remote_state
*rs
= get_remote_state ();
5780 int max_buf_size
; /* Max size of packet output buffer. */
5786 max_buf_size
= get_memory_read_packet_size ();
5787 /* The packet buffer will be large enough for the payload;
5788 get_memory_packet_size ensures this. */
5797 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
5799 /* construct "m"<memaddr>","<len>" */
5800 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
5801 memaddr
= remote_address_masked (memaddr
);
5804 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
5806 p
+= hexnumstr (p
, (ULONGEST
) todo
);
5810 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5812 if (rs
->buf
[0] == 'E'
5813 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
5814 && rs
->buf
[3] == '\0')
5816 /* There is no correspondance between what the remote
5817 protocol uses for errors and errno codes. We would like
5818 a cleaner way of representing errors (big enough to
5819 include errno codes, bfd_error codes, and others). But
5820 for now just return EIO. */
5825 /* Reply describes memory byte by byte,
5826 each byte encoded as two hex characters. */
5829 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
5831 /* Reply is short. This means that we were able to read
5832 only part of what we wanted to. */
5833 return i
+ (origlen
- len
);
5843 /* Remote notification handler. */
5846 handle_notification (char *buf
, size_t length
)
5848 if (strncmp (buf
, "Stop:", 5) == 0)
5850 if (pending_stop_reply
)
5851 /* We've already parsed the in-flight stop-reply, but the stub
5852 for some reason thought we didn't, possibly due to timeout
5853 on its side. Just ignore it. */
5857 struct cleanup
*old_chain
;
5858 struct stop_reply
*reply
= stop_reply_xmalloc ();
5859 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
5861 remote_parse_stop_reply (buf
+ 5, reply
);
5863 discard_cleanups (old_chain
);
5865 /* Be careful to only set it after parsing, since an error
5866 may be thrown then. */
5867 pending_stop_reply
= reply
;
5869 /* Notify the event loop there's a stop reply to acknowledge
5870 and that there may be more events to fetch. */
5871 mark_async_event_handler (remote_async_get_pending_events_token
);
5875 /* We ignore notifications we don't recognize, for compatibility
5876 with newer stubs. */
5881 /* Read or write LEN bytes from inferior memory at MEMADDR,
5882 transferring to or from debugger address BUFFER. Write to inferior
5883 if SHOULD_WRITE is nonzero. Returns length of data written or
5884 read; 0 for error. TARGET is unused. */
5887 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
5888 int should_write
, struct mem_attrib
*attrib
,
5889 struct target_ops
*target
)
5893 set_general_thread (inferior_ptid
);
5896 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
5898 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
5903 /* Sends a packet with content determined by the printf format string
5904 FORMAT and the remaining arguments, then gets the reply. Returns
5905 whether the packet was a success, a failure, or unknown. */
5907 static enum packet_result
5908 remote_send_printf (const char *format
, ...)
5910 struct remote_state
*rs
= get_remote_state ();
5911 int max_size
= get_remote_packet_size ();
5914 va_start (ap
, format
);
5917 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
5918 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
5920 if (putpkt (rs
->buf
) < 0)
5921 error (_("Communication problem with target."));
5924 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5926 return packet_check_result (rs
->buf
);
5930 restore_remote_timeout (void *p
)
5932 int value
= *(int *)p
;
5933 remote_timeout
= value
;
5936 /* Flash writing can take quite some time. We'll set
5937 effectively infinite timeout for flash operations.
5938 In future, we'll need to decide on a better approach. */
5939 static const int remote_flash_timeout
= 1000;
5942 remote_flash_erase (struct target_ops
*ops
,
5943 ULONGEST address
, LONGEST length
)
5945 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
5946 int saved_remote_timeout
= remote_timeout
;
5947 enum packet_result ret
;
5949 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
5950 &saved_remote_timeout
);
5951 remote_timeout
= remote_flash_timeout
;
5953 ret
= remote_send_printf ("vFlashErase:%s,%s",
5954 phex (address
, addr_size
),
5958 case PACKET_UNKNOWN
:
5959 error (_("Remote target does not support flash erase"));
5961 error (_("Error erasing flash with vFlashErase packet"));
5966 do_cleanups (back_to
);
5970 remote_flash_write (struct target_ops
*ops
,
5971 ULONGEST address
, LONGEST length
,
5972 const gdb_byte
*data
)
5974 int saved_remote_timeout
= remote_timeout
;
5976 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
5977 &saved_remote_timeout
);
5979 remote_timeout
= remote_flash_timeout
;
5980 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
5981 do_cleanups (back_to
);
5987 remote_flash_done (struct target_ops
*ops
)
5989 int saved_remote_timeout
= remote_timeout
;
5991 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
5992 &saved_remote_timeout
);
5994 remote_timeout
= remote_flash_timeout
;
5995 ret
= remote_send_printf ("vFlashDone");
5996 do_cleanups (back_to
);
6000 case PACKET_UNKNOWN
:
6001 error (_("Remote target does not support vFlashDone"));
6003 error (_("Error finishing flash operation"));
6010 remote_files_info (struct target_ops
*ignore
)
6012 puts_filtered ("Debugging a target over a serial line.\n");
6015 /* Stuff for dealing with the packets which are part of this protocol.
6016 See comment at top of file for details. */
6018 /* Read a single character from the remote end. */
6021 readchar (int timeout
)
6025 ch
= serial_readchar (remote_desc
, timeout
);
6030 switch ((enum serial_rc
) ch
)
6034 error (_("Remote connection closed"));
6037 perror_with_name (_("Remote communication error"));
6039 case SERIAL_TIMEOUT
:
6045 /* Send the command in *BUF to the remote machine, and read the reply
6046 into *BUF. Report an error if we get an error reply. Resize
6047 *BUF using xrealloc if necessary to hold the result, and update
6051 remote_send (char **buf
,
6055 getpkt (buf
, sizeof_buf
, 0);
6057 if ((*buf
)[0] == 'E')
6058 error (_("Remote failure reply: %s"), *buf
);
6061 /* Return a pointer to an xmalloc'ed string representing an escaped
6062 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6063 etc. The caller is responsible for releasing the returned
6067 escape_buffer (const char *buf
, int n
)
6069 struct cleanup
*old_chain
;
6070 struct ui_file
*stb
;
6073 stb
= mem_fileopen ();
6074 old_chain
= make_cleanup_ui_file_delete (stb
);
6076 fputstrn_unfiltered (buf
, n
, 0, stb
);
6077 str
= ui_file_xstrdup (stb
, NULL
);
6078 do_cleanups (old_chain
);
6082 /* Display a null-terminated packet on stdout, for debugging, using C
6086 print_packet (char *buf
)
6088 puts_filtered ("\"");
6089 fputstr_filtered (buf
, '"', gdb_stdout
);
6090 puts_filtered ("\"");
6096 return putpkt_binary (buf
, strlen (buf
));
6099 /* Send a packet to the remote machine, with error checking. The data
6100 of the packet is in BUF. The string in BUF can be at most
6101 get_remote_packet_size () - 5 to account for the $, # and checksum,
6102 and for a possible /0 if we are debugging (remote_debug) and want
6103 to print the sent packet as a string. */
6106 putpkt_binary (char *buf
, int cnt
)
6108 struct remote_state
*rs
= get_remote_state ();
6110 unsigned char csum
= 0;
6111 char *buf2
= alloca (cnt
+ 6);
6117 /* Catch cases like trying to read memory or listing threads while
6118 we're waiting for a stop reply. The remote server wouldn't be
6119 ready to handle this request, so we'd hang and timeout. We don't
6120 have to worry about this in synchronous mode, because in that
6121 case it's not possible to issue a command while the target is
6122 running. This is not a problem in non-stop mode, because in that
6123 case, the stub is always ready to process serial input. */
6124 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6125 error (_("Cannot execute this command while the target is running."));
6127 /* We're sending out a new packet. Make sure we don't look at a
6128 stale cached response. */
6129 rs
->cached_wait_status
= 0;
6131 /* Copy the packet into buffer BUF2, encapsulating it
6132 and giving it a checksum. */
6137 for (i
= 0; i
< cnt
; i
++)
6143 *p
++ = tohex ((csum
>> 4) & 0xf);
6144 *p
++ = tohex (csum
& 0xf);
6146 /* Send it over and over until we get a positive ack. */
6150 int started_error_output
= 0;
6154 struct cleanup
*old_chain
;
6158 str
= escape_buffer (buf2
, p
- buf2
);
6159 old_chain
= make_cleanup (xfree
, str
);
6160 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6161 gdb_flush (gdb_stdlog
);
6162 do_cleanups (old_chain
);
6164 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6165 perror_with_name (_("putpkt: write failed"));
6167 /* If this is a no acks version of the remote protocol, send the
6168 packet and move on. */
6172 /* Read until either a timeout occurs (-2) or '+' is read.
6173 Handle any notification that arrives in the mean time. */
6176 ch
= readchar (remote_timeout
);
6184 case SERIAL_TIMEOUT
:
6187 if (started_error_output
)
6189 putchar_unfiltered ('\n');
6190 started_error_output
= 0;
6199 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6203 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6204 case SERIAL_TIMEOUT
:
6208 break; /* Retransmit buffer. */
6212 fprintf_unfiltered (gdb_stdlog
,
6213 "Packet instead of Ack, ignoring it\n");
6214 /* It's probably an old response sent because an ACK
6215 was lost. Gobble up the packet and ack it so it
6216 doesn't get retransmitted when we resend this
6219 serial_write (remote_desc
, "+", 1);
6220 continue; /* Now, go look for +. */
6227 /* If we got a notification, handle it, and go back to looking
6229 /* We've found the start of a notification. Now
6230 collect the data. */
6231 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6236 struct cleanup
*old_chain
;
6239 str
= escape_buffer (rs
->buf
, val
);
6240 old_chain
= make_cleanup (xfree
, str
);
6241 fprintf_unfiltered (gdb_stdlog
,
6242 " Notification received: %s\n",
6244 do_cleanups (old_chain
);
6246 handle_notification (rs
->buf
, val
);
6247 /* We're in sync now, rewait for the ack. */
6254 if (!started_error_output
)
6256 started_error_output
= 1;
6257 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6259 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6260 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6269 if (!started_error_output
)
6271 started_error_output
= 1;
6272 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6274 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6278 break; /* Here to retransmit. */
6282 /* This is wrong. If doing a long backtrace, the user should be
6283 able to get out next time we call QUIT, without anything as
6284 violent as interrupt_query. If we want to provide a way out of
6285 here without getting to the next QUIT, it should be based on
6286 hitting ^C twice as in remote_wait. */
6297 /* Come here after finding the start of a frame when we expected an
6298 ack. Do our best to discard the rest of this packet. */
6307 c
= readchar (remote_timeout
);
6310 case SERIAL_TIMEOUT
:
6311 /* Nothing we can do. */
6314 /* Discard the two bytes of checksum and stop. */
6315 c
= readchar (remote_timeout
);
6317 c
= readchar (remote_timeout
);
6320 case '*': /* Run length encoding. */
6321 /* Discard the repeat count. */
6322 c
= readchar (remote_timeout
);
6327 /* A regular character. */
6333 /* Come here after finding the start of the frame. Collect the rest
6334 into *BUF, verifying the checksum, length, and handling run-length
6335 compression. NUL terminate the buffer. If there is not enough room,
6336 expand *BUF using xrealloc.
6338 Returns -1 on error, number of characters in buffer (ignoring the
6339 trailing NULL) on success. (could be extended to return one of the
6340 SERIAL status indications). */
6343 read_frame (char **buf_p
,
6350 struct remote_state
*rs
= get_remote_state ();
6357 c
= readchar (remote_timeout
);
6360 case SERIAL_TIMEOUT
:
6362 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
6366 fputs_filtered ("Saw new packet start in middle of old one\n",
6368 return -1; /* Start a new packet, count retries. */
6371 unsigned char pktcsum
;
6377 check_0
= readchar (remote_timeout
);
6379 check_1
= readchar (remote_timeout
);
6381 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
6384 fputs_filtered ("Timeout in checksum, retrying\n",
6388 else if (check_0
< 0 || check_1
< 0)
6391 fputs_filtered ("Communication error in checksum\n",
6396 /* Don't recompute the checksum; with no ack packets we
6397 don't have any way to indicate a packet retransmission
6402 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
6403 if (csum
== pktcsum
)
6408 struct cleanup
*old_chain
;
6411 str
= escape_buffer (buf
, bc
);
6412 old_chain
= make_cleanup (xfree
, str
);
6413 fprintf_unfiltered (gdb_stdlog
,
6415 Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
6416 pktcsum
, csum
, str
);
6417 do_cleanups (old_chain
);
6419 /* Number of characters in buffer ignoring trailing
6423 case '*': /* Run length encoding. */
6428 c
= readchar (remote_timeout
);
6430 repeat
= c
- ' ' + 3; /* Compute repeat count. */
6432 /* The character before ``*'' is repeated. */
6434 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
6436 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
6438 /* Make some more room in the buffer. */
6439 *sizeof_buf
+= repeat
;
6440 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6444 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
6450 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
6454 if (bc
>= *sizeof_buf
- 1)
6456 /* Make some more room in the buffer. */
6458 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6469 /* Read a packet from the remote machine, with error checking, and
6470 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6471 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6472 rather than timing out; this is used (in synchronous mode) to wait
6473 for a target that is is executing user code to stop. */
6474 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
6475 don't have to change all the calls to getpkt to deal with the
6476 return value, because at the moment I don't know what the right
6477 thing to do it for those. */
6485 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
6489 /* Read a packet from the remote machine, with error checking, and
6490 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6491 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6492 rather than timing out; this is used (in synchronous mode) to wait
6493 for a target that is is executing user code to stop. If FOREVER ==
6494 0, this function is allowed to time out gracefully and return an
6495 indication of this to the caller. Otherwise return the number of
6496 bytes read. If EXPECTING_NOTIF, consider receiving a notification
6497 enough reason to return to the caller. */
6500 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
6501 int expecting_notif
)
6503 struct remote_state
*rs
= get_remote_state ();
6509 /* We're reading a new response. Make sure we don't look at a
6510 previously cached response. */
6511 rs
->cached_wait_status
= 0;
6513 strcpy (*buf
, "timeout");
6516 timeout
= watchdog
> 0 ? watchdog
: -1;
6517 else if (expecting_notif
)
6518 timeout
= 0; /* There should already be a char in the buffer. If
6521 timeout
= remote_timeout
;
6525 /* Process any number of notifications, and then return when
6529 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
6531 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
6533 /* This can loop forever if the remote side sends us
6534 characters continuously, but if it pauses, we'll get
6535 SERIAL_TIMEOUT from readchar because of timeout. Then
6536 we'll count that as a retry.
6538 Note that even when forever is set, we will only wait
6539 forever prior to the start of a packet. After that, we
6540 expect characters to arrive at a brisk pace. They should
6541 show up within remote_timeout intervals. */
6543 c
= readchar (timeout
);
6544 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
6546 if (c
== SERIAL_TIMEOUT
)
6548 if (expecting_notif
)
6549 return -1; /* Don't complain, it's normal to not get
6550 anything in this case. */
6552 if (forever
) /* Watchdog went off? Kill the target. */
6556 error (_("Watchdog timeout has expired. Target detached."));
6559 fputs_filtered ("Timed out.\n", gdb_stdlog
);
6563 /* We've found the start of a packet or notification.
6564 Now collect the data. */
6565 val
= read_frame (buf
, sizeof_buf
);
6570 serial_write (remote_desc
, "-", 1);
6573 if (tries
> MAX_TRIES
)
6575 /* We have tried hard enough, and just can't receive the
6576 packet/notification. Give up. */
6577 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
6579 /* Skip the ack char if we're in no-ack mode. */
6580 if (!rs
->noack_mode
)
6581 serial_write (remote_desc
, "+", 1);
6585 /* If we got an ordinary packet, return that to our caller. */
6590 struct cleanup
*old_chain
;
6593 str
= escape_buffer (*buf
, val
);
6594 old_chain
= make_cleanup (xfree
, str
);
6595 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
6596 do_cleanups (old_chain
);
6599 /* Skip the ack char if we're in no-ack mode. */
6600 if (!rs
->noack_mode
)
6601 serial_write (remote_desc
, "+", 1);
6605 /* If we got a notification, handle it, and go back to looking
6609 gdb_assert (c
== '%');
6613 struct cleanup
*old_chain
;
6616 str
= escape_buffer (*buf
, val
);
6617 old_chain
= make_cleanup (xfree
, str
);
6618 fprintf_unfiltered (gdb_stdlog
,
6619 " Notification received: %s\n",
6621 do_cleanups (old_chain
);
6624 handle_notification (*buf
, val
);
6626 /* Notifications require no acknowledgement. */
6628 if (expecting_notif
)
6635 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
6637 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
6641 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
6643 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
6648 remote_kill (struct target_ops
*ops
)
6650 /* Use catch_errors so the user can quit from gdb even when we
6651 aren't on speaking terms with the remote system. */
6652 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
6654 /* Don't wait for it to die. I'm not really sure it matters whether
6655 we do or not. For the existing stubs, kill is a noop. */
6656 target_mourn_inferior ();
6660 remote_vkill (int pid
, struct remote_state
*rs
)
6662 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
6665 /* Tell the remote target to detach. */
6666 sprintf (rs
->buf
, "vKill;%x", pid
);
6668 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6670 if (packet_ok (rs
->buf
,
6671 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
6673 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
6680 extended_remote_kill (struct target_ops
*ops
)
6683 int pid
= ptid_get_pid (inferior_ptid
);
6684 struct remote_state
*rs
= get_remote_state ();
6686 res
= remote_vkill (pid
, rs
);
6687 if (res
== -1 && !remote_multi_process_p (rs
))
6689 /* Don't try 'k' on a multi-process aware stub -- it has no way
6690 to specify the pid. */
6694 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6695 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
6698 /* Don't wait for it to die. I'm not really sure it matters whether
6699 we do or not. For the existing stubs, kill is a noop. */
6705 error (_("Can't kill process"));
6707 target_mourn_inferior ();
6711 remote_mourn (struct target_ops
*ops
)
6713 remote_mourn_1 (ops
);
6716 /* Worker function for remote_mourn. */
6718 remote_mourn_1 (struct target_ops
*target
)
6720 unpush_target (target
);
6722 /* remote_close takes care of doing most of the clean up. */
6723 generic_mourn_inferior ();
6727 extended_remote_mourn_1 (struct target_ops
*target
)
6729 struct remote_state
*rs
= get_remote_state ();
6731 /* In case we got here due to an error, but we're going to stay
6733 rs
->waiting_for_stop_reply
= 0;
6735 /* We're no longer interested in these events. */
6736 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
6738 /* If the current general thread belonged to the process we just
6739 detached from or has exited, the remote side current general
6740 thread becomes undefined. Considering a case like this:
6742 - We just got here due to a detach.
6743 - The process that we're detaching from happens to immediately
6744 report a global breakpoint being hit in non-stop mode, in the
6745 same thread we had selected before.
6746 - GDB attaches to this process again.
6747 - This event happens to be the next event we handle.
6749 GDB would consider that the current general thread didn't need to
6750 be set on the stub side (with Hg), since for all it knew,
6751 GENERAL_THREAD hadn't changed.
6753 Notice that although in all-stop mode, the remote server always
6754 sets the current thread to the thread reporting the stop event,
6755 that doesn't happen in non-stop mode; in non-stop, the stub *must
6756 not* change the current thread when reporting a breakpoint hit,
6757 due to the decoupling of event reporting and event handling.
6759 To keep things simple, we always invalidate our notion of the
6761 record_currthread (minus_one_ptid
);
6763 /* Unlike "target remote", we do not want to unpush the target; then
6764 the next time the user says "run", we won't be connected. */
6766 /* Call common code to mark the inferior as not running. */
6767 generic_mourn_inferior ();
6769 if (!have_inferiors ())
6771 if (!remote_multi_process_p (rs
))
6773 /* Check whether the target is running now - some remote stubs
6774 automatically restart after kill. */
6776 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6778 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
6780 /* Assume that the target has been restarted. Set inferior_ptid
6781 so that bits of core GDB realizes there's something here, e.g.,
6782 so that the user can say "kill" again. */
6783 inferior_ptid
= magic_null_ptid
;
6790 extended_remote_mourn (struct target_ops
*ops
)
6792 extended_remote_mourn_1 (ops
);
6796 extended_remote_run (char *args
)
6798 struct remote_state
*rs
= get_remote_state ();
6801 /* If the user has disabled vRun support, or we have detected that
6802 support is not available, do not try it. */
6803 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
6806 strcpy (rs
->buf
, "vRun;");
6807 len
= strlen (rs
->buf
);
6809 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
6810 error (_("Remote file name too long for run packet"));
6811 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
6813 gdb_assert (args
!= NULL
);
6816 struct cleanup
*back_to
;
6820 argv
= gdb_buildargv (args
);
6821 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
6822 for (i
= 0; argv
[i
] != NULL
; i
++)
6824 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
6825 error (_("Argument list too long for run packet"));
6826 rs
->buf
[len
++] = ';';
6827 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
6829 do_cleanups (back_to
);
6832 rs
->buf
[len
++] = '\0';
6835 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6837 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
6839 /* We have a wait response; we don't need it, though. All is well. */
6842 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
6843 /* It wasn't disabled before, but it is now. */
6847 if (remote_exec_file
[0] == '\0')
6848 error (_("Running the default executable on the remote target failed; "
6849 "try \"set remote exec-file\"?"));
6851 error (_("Running \"%s\" on the remote target failed"),
6856 /* In the extended protocol we want to be able to do things like
6857 "run" and have them basically work as expected. So we need
6858 a special create_inferior function. We support changing the
6859 executable file and the command line arguments, but not the
6863 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
6864 char **env
, int from_tty
)
6866 /* If running asynchronously, register the target file descriptor
6867 with the event loop. */
6868 if (target_can_async_p ())
6869 target_async (inferior_event_handler
, 0);
6871 /* Now restart the remote server. */
6872 if (extended_remote_run (args
) == -1)
6874 /* vRun was not supported. Fail if we need it to do what the
6876 if (remote_exec_file
[0])
6877 error (_("Remote target does not support \"set remote exec-file\""));
6879 error (_("Remote target does not support \"set args\" or run <ARGS>"));
6881 /* Fall back to "R". */
6882 extended_remote_restart ();
6885 if (!have_inferiors ())
6887 /* Clean up from the last time we ran, before we mark the target
6888 running again. This will mark breakpoints uninserted, and
6889 get_offsets may insert breakpoints. */
6890 init_thread_list ();
6891 init_wait_for_inferior ();
6894 /* Now mark the inferior as running before we do anything else. */
6895 inferior_ptid
= magic_null_ptid
;
6897 /* Now, if we have thread information, update inferior_ptid. */
6898 inferior_ptid
= remote_current_thread (inferior_ptid
);
6900 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
6901 add_thread_silent (inferior_ptid
);
6903 /* Get updated offsets, if the stub uses qOffsets. */
6908 extended_remote_create_inferior (struct target_ops
*ops
,
6909 char *exec_file
, char *args
,
6910 char **env
, int from_tty
)
6912 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
6916 /* Insert a breakpoint. On targets that have software breakpoint
6917 support, we ask the remote target to do the work; on targets
6918 which don't, we insert a traditional memory breakpoint. */
6921 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
6922 struct bp_target_info
*bp_tgt
)
6924 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
6925 If it succeeds, then set the support to PACKET_ENABLE. If it
6926 fails, and the user has explicitly requested the Z support then
6927 report an error, otherwise, mark it disabled and go on. */
6929 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
6931 CORE_ADDR addr
= bp_tgt
->placed_address
;
6932 struct remote_state
*rs
;
6936 gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
6938 rs
= get_remote_state ();
6944 addr
= (ULONGEST
) remote_address_masked (addr
);
6945 p
+= hexnumstr (p
, addr
);
6946 sprintf (p
, ",%d", bpsize
);
6949 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6951 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
6956 bp_tgt
->placed_address
= addr
;
6957 bp_tgt
->placed_size
= bpsize
;
6959 case PACKET_UNKNOWN
:
6964 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
6968 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
6969 struct bp_target_info
*bp_tgt
)
6971 CORE_ADDR addr
= bp_tgt
->placed_address
;
6972 struct remote_state
*rs
= get_remote_state ();
6974 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
6982 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
6983 p
+= hexnumstr (p
, addr
);
6984 sprintf (p
, ",%d", bp_tgt
->placed_size
);
6987 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6989 return (rs
->buf
[0] == 'E');
6992 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
6996 watchpoint_to_Z_packet (int type
)
7001 return Z_PACKET_WRITE_WP
;
7004 return Z_PACKET_READ_WP
;
7007 return Z_PACKET_ACCESS_WP
;
7010 internal_error (__FILE__
, __LINE__
,
7011 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7016 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
7018 struct remote_state
*rs
= get_remote_state ();
7020 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7022 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7025 sprintf (rs
->buf
, "Z%x,", packet
);
7026 p
= strchr (rs
->buf
, '\0');
7027 addr
= remote_address_masked (addr
);
7028 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7029 sprintf (p
, ",%x", len
);
7032 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7034 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7037 case PACKET_UNKNOWN
:
7042 internal_error (__FILE__
, __LINE__
,
7043 _("remote_insert_watchpoint: reached end of function"));
7048 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
7050 struct remote_state
*rs
= get_remote_state ();
7052 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7054 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7057 sprintf (rs
->buf
, "z%x,", packet
);
7058 p
= strchr (rs
->buf
, '\0');
7059 addr
= remote_address_masked (addr
);
7060 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7061 sprintf (p
, ",%x", len
);
7063 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7065 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7068 case PACKET_UNKNOWN
:
7073 internal_error (__FILE__
, __LINE__
,
7074 _("remote_remove_watchpoint: reached end of function"));
7078 int remote_hw_watchpoint_limit
= -1;
7079 int remote_hw_breakpoint_limit
= -1;
7082 remote_check_watch_resources (int type
, int cnt
, int ot
)
7084 if (type
== bp_hardware_breakpoint
)
7086 if (remote_hw_breakpoint_limit
== 0)
7088 else if (remote_hw_breakpoint_limit
< 0)
7090 else if (cnt
<= remote_hw_breakpoint_limit
)
7095 if (remote_hw_watchpoint_limit
== 0)
7097 else if (remote_hw_watchpoint_limit
< 0)
7101 else if (cnt
<= remote_hw_watchpoint_limit
)
7108 remote_stopped_by_watchpoint (void)
7110 return remote_stopped_by_watchpoint_p
;
7114 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7117 if (remote_stopped_by_watchpoint ())
7119 *addr_p
= remote_watch_data_address
;
7128 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7129 struct bp_target_info
*bp_tgt
)
7132 struct remote_state
*rs
;
7135 /* The length field should be set to the size of a breakpoint
7136 instruction, even though we aren't inserting one ourselves. */
7138 gdbarch_breakpoint_from_pc
7139 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7141 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7144 rs
= get_remote_state ();
7151 addr
= remote_address_masked (bp_tgt
->placed_address
);
7152 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7153 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7156 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7158 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7161 case PACKET_UNKNOWN
:
7166 internal_error (__FILE__
, __LINE__
,
7167 _("remote_insert_hw_breakpoint: reached end of function"));
7172 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7173 struct bp_target_info
*bp_tgt
)
7176 struct remote_state
*rs
= get_remote_state ();
7179 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7186 addr
= remote_address_masked (bp_tgt
->placed_address
);
7187 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7188 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7191 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7193 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7196 case PACKET_UNKNOWN
:
7201 internal_error (__FILE__
, __LINE__
,
7202 _("remote_remove_hw_breakpoint: reached end of function"));
7205 /* Table used by the crc32 function to calcuate the checksum. */
7207 static unsigned long crc32_table
[256] =
7210 static unsigned long
7211 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
7213 if (!crc32_table
[1])
7215 /* Initialize the CRC table and the decoding table. */
7219 for (i
= 0; i
< 256; i
++)
7221 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7222 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7229 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7235 /* compare-sections command
7237 With no arguments, compares each loadable section in the exec bfd
7238 with the same memory range on the target, and reports mismatches.
7239 Useful for verifying the image on the target against the exec file.
7240 Depends on the target understanding the new "qCRC:" request. */
7242 /* FIXME: cagney/1999-10-26: This command should be broken down into a
7243 target method (target verify memory) and generic version of the
7244 actual command. This will allow other high-level code (especially
7245 generic_load()) to make use of this target functionality. */
7248 compare_sections_command (char *args
, int from_tty
)
7250 struct remote_state
*rs
= get_remote_state ();
7252 unsigned long host_crc
, target_crc
;
7253 struct cleanup
*old_chain
;
7256 const char *sectname
;
7263 error (_("command cannot be used without an exec file"));
7264 if (!current_target
.to_shortname
||
7265 strcmp (current_target
.to_shortname
, "remote") != 0)
7266 error (_("command can only be used with remote target"));
7268 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7270 if (!(s
->flags
& SEC_LOAD
))
7271 continue; /* skip non-loadable section */
7273 size
= bfd_get_section_size (s
);
7275 continue; /* skip zero-length section */
7277 sectname
= bfd_get_section_name (exec_bfd
, s
);
7278 if (args
&& strcmp (args
, sectname
) != 0)
7279 continue; /* not the section selected by user */
7281 matched
= 1; /* do this section */
7283 /* FIXME: assumes lma can fit into long. */
7284 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7285 (long) lma
, (long) size
);
7288 /* Be clever; compute the host_crc before waiting for target
7290 sectdata
= xmalloc (size
);
7291 old_chain
= make_cleanup (xfree
, sectdata
);
7292 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
7293 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
7295 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7296 if (rs
->buf
[0] == 'E')
7297 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
7298 paddress (target_gdbarch
, lma
),
7299 paddress (target_gdbarch
, lma
+ size
));
7300 if (rs
->buf
[0] != 'C')
7301 error (_("remote target does not support this operation"));
7303 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7304 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7306 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
7307 paddress (target_gdbarch
, lma
),
7308 paddress (target_gdbarch
, lma
+ size
));
7309 if (host_crc
== target_crc
)
7310 printf_filtered ("matched.\n");
7313 printf_filtered ("MIS-MATCHED!\n");
7317 do_cleanups (old_chain
);
7320 warning (_("One or more sections of the remote executable does not match\n\
7321 the loaded file\n"));
7322 if (args
&& !matched
)
7323 printf_filtered (_("No loaded section named '%s'.\n"), args
);
7326 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
7327 into remote target. The number of bytes written to the remote
7328 target is returned, or -1 for error. */
7331 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
7332 const char *annex
, const gdb_byte
*writebuf
,
7333 ULONGEST offset
, LONGEST len
,
7334 struct packet_config
*packet
)
7338 struct remote_state
*rs
= get_remote_state ();
7339 int max_size
= get_memory_write_packet_size ();
7341 if (packet
->support
== PACKET_DISABLE
)
7344 /* Insert header. */
7345 i
= snprintf (rs
->buf
, max_size
,
7346 "qXfer:%s:write:%s:%s:",
7347 object_name
, annex
? annex
: "",
7348 phex_nz (offset
, sizeof offset
));
7349 max_size
-= (i
+ 1);
7351 /* Escape as much data as fits into rs->buf. */
7352 buf_len
= remote_escape_output
7353 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
7355 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
7356 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7357 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7360 unpack_varlen_hex (rs
->buf
, &n
);
7364 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
7365 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
7366 number of bytes read is returned, or 0 for EOF, or -1 for error.
7367 The number of bytes read may be less than LEN without indicating an
7368 EOF. PACKET is checked and updated to indicate whether the remote
7369 target supports this object. */
7372 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
7374 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
7375 struct packet_config
*packet
)
7377 static char *finished_object
;
7378 static char *finished_annex
;
7379 static ULONGEST finished_offset
;
7381 struct remote_state
*rs
= get_remote_state ();
7382 LONGEST i
, n
, packet_len
;
7384 if (packet
->support
== PACKET_DISABLE
)
7387 /* Check whether we've cached an end-of-object packet that matches
7389 if (finished_object
)
7391 if (strcmp (object_name
, finished_object
) == 0
7392 && strcmp (annex
? annex
: "", finished_annex
) == 0
7393 && offset
== finished_offset
)
7396 /* Otherwise, we're now reading something different. Discard
7398 xfree (finished_object
);
7399 xfree (finished_annex
);
7400 finished_object
= NULL
;
7401 finished_annex
= NULL
;
7404 /* Request only enough to fit in a single packet. The actual data
7405 may not, since we don't know how much of it will need to be escaped;
7406 the target is free to respond with slightly less data. We subtract
7407 five to account for the response type and the protocol frame. */
7408 n
= min (get_remote_packet_size () - 5, len
);
7409 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
7410 object_name
, annex
? annex
: "",
7411 phex_nz (offset
, sizeof offset
),
7412 phex_nz (n
, sizeof n
));
7413 i
= putpkt (rs
->buf
);
7418 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
7419 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7422 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
7423 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
7425 /* 'm' means there is (or at least might be) more data after this
7426 batch. That does not make sense unless there's at least one byte
7427 of data in this reply. */
7428 if (rs
->buf
[0] == 'm' && packet_len
== 1)
7429 error (_("Remote qXfer reply contained no data."));
7431 /* Got some data. */
7432 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
7434 /* 'l' is an EOF marker, possibly including a final block of data,
7435 or possibly empty. If we have the final block of a non-empty
7436 object, record this fact to bypass a subsequent partial read. */
7437 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
7439 finished_object
= xstrdup (object_name
);
7440 finished_annex
= xstrdup (annex
? annex
: "");
7441 finished_offset
= offset
+ i
;
7448 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
7449 const char *annex
, gdb_byte
*readbuf
,
7450 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
7452 struct remote_state
*rs
;
7457 set_general_thread (inferior_ptid
);
7459 rs
= get_remote_state ();
7461 /* Handle memory using the standard memory routines. */
7462 if (object
== TARGET_OBJECT_MEMORY
)
7467 /* If the remote target is connected but not running, we should
7468 pass this request down to a lower stratum (e.g. the executable
7470 if (!target_has_execution
)
7473 if (writebuf
!= NULL
)
7474 xfered
= remote_write_bytes (offset
, writebuf
, len
);
7476 xfered
= remote_read_bytes (offset
, readbuf
, len
);
7480 else if (xfered
== 0 && errno
== 0)
7486 /* Handle SPU memory using qxfer packets. */
7487 if (object
== TARGET_OBJECT_SPU
)
7490 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
7491 &remote_protocol_packets
7492 [PACKET_qXfer_spu_read
]);
7494 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
7495 &remote_protocol_packets
7496 [PACKET_qXfer_spu_write
]);
7499 /* Handle extra signal info using qxfer packets. */
7500 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
7503 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
7504 &remote_protocol_packets
7505 [PACKET_qXfer_siginfo_read
]);
7507 return remote_write_qxfer (ops
, "siginfo", annex
, writebuf
, offset
, len
,
7508 &remote_protocol_packets
7509 [PACKET_qXfer_siginfo_write
]);
7512 /* Only handle flash writes. */
7513 if (writebuf
!= NULL
)
7519 case TARGET_OBJECT_FLASH
:
7520 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
7524 else if (xfered
== 0 && errno
== 0)
7534 /* Map pre-existing objects onto letters. DO NOT do this for new
7535 objects!!! Instead specify new query packets. */
7538 case TARGET_OBJECT_AVR
:
7542 case TARGET_OBJECT_AUXV
:
7543 gdb_assert (annex
== NULL
);
7544 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
7545 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
7547 case TARGET_OBJECT_AVAILABLE_FEATURES
:
7548 return remote_read_qxfer
7549 (ops
, "features", annex
, readbuf
, offset
, len
,
7550 &remote_protocol_packets
[PACKET_qXfer_features
]);
7552 case TARGET_OBJECT_LIBRARIES
:
7553 return remote_read_qxfer
7554 (ops
, "libraries", annex
, readbuf
, offset
, len
,
7555 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
7557 case TARGET_OBJECT_MEMORY_MAP
:
7558 gdb_assert (annex
== NULL
);
7559 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
7560 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
7562 case TARGET_OBJECT_OSDATA
:
7563 /* Should only get here if we're connected. */
7564 gdb_assert (remote_desc
);
7565 return remote_read_qxfer
7566 (ops
, "osdata", annex
, readbuf
, offset
, len
,
7567 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
7573 /* Note: a zero OFFSET and LEN can be used to query the minimum
7575 if (offset
== 0 && len
== 0)
7576 return (get_remote_packet_size ());
7577 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
7578 large enough let the caller deal with it. */
7579 if (len
< get_remote_packet_size ())
7581 len
= get_remote_packet_size ();
7583 /* Except for querying the minimum buffer size, target must be open. */
7585 error (_("remote query is only available after target open"));
7587 gdb_assert (annex
!= NULL
);
7588 gdb_assert (readbuf
!= NULL
);
7594 /* We used one buffer char for the remote protocol q command and
7595 another for the query type. As the remote protocol encapsulation
7596 uses 4 chars plus one extra in case we are debugging
7597 (remote_debug), we have PBUFZIZ - 7 left to pack the query
7600 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
7602 /* Bad caller may have sent forbidden characters. */
7603 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
7608 gdb_assert (annex
[i
] == '\0');
7610 i
= putpkt (rs
->buf
);
7614 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7615 strcpy ((char *) readbuf
, rs
->buf
);
7617 return strlen ((char *) readbuf
);
7621 remote_search_memory (struct target_ops
* ops
,
7622 CORE_ADDR start_addr
, ULONGEST search_space_len
,
7623 const gdb_byte
*pattern
, ULONGEST pattern_len
,
7624 CORE_ADDR
*found_addrp
)
7626 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
7627 struct remote_state
*rs
= get_remote_state ();
7628 int max_size
= get_memory_write_packet_size ();
7629 struct packet_config
*packet
=
7630 &remote_protocol_packets
[PACKET_qSearch_memory
];
7631 /* number of packet bytes used to encode the pattern,
7632 this could be more than PATTERN_LEN due to escape characters */
7633 int escaped_pattern_len
;
7634 /* amount of pattern that was encodable in the packet */
7635 int used_pattern_len
;
7638 ULONGEST found_addr
;
7640 /* Don't go to the target if we don't have to.
7641 This is done before checking packet->support to avoid the possibility that
7642 a success for this edge case means the facility works in general. */
7643 if (pattern_len
> search_space_len
)
7645 if (pattern_len
== 0)
7647 *found_addrp
= start_addr
;
7651 /* If we already know the packet isn't supported, fall back to the simple
7652 way of searching memory. */
7654 if (packet
->support
== PACKET_DISABLE
)
7656 /* Target doesn't provided special support, fall back and use the
7657 standard support (copy memory and do the search here). */
7658 return simple_search_memory (ops
, start_addr
, search_space_len
,
7659 pattern
, pattern_len
, found_addrp
);
7662 /* Insert header. */
7663 i
= snprintf (rs
->buf
, max_size
,
7664 "qSearch:memory:%s;%s;",
7665 phex_nz (start_addr
, addr_size
),
7666 phex_nz (search_space_len
, sizeof (search_space_len
)));
7667 max_size
-= (i
+ 1);
7669 /* Escape as much data as fits into rs->buf. */
7670 escaped_pattern_len
=
7671 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
7672 &used_pattern_len
, max_size
);
7674 /* Bail if the pattern is too large. */
7675 if (used_pattern_len
!= pattern_len
)
7676 error ("Pattern is too large to transmit to remote target.");
7678 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
7679 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7680 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7682 /* The request may not have worked because the command is not
7683 supported. If so, fall back to the simple way. */
7684 if (packet
->support
== PACKET_DISABLE
)
7686 return simple_search_memory (ops
, start_addr
, search_space_len
,
7687 pattern
, pattern_len
, found_addrp
);
7692 if (rs
->buf
[0] == '0')
7694 else if (rs
->buf
[0] == '1')
7697 if (rs
->buf
[1] != ',')
7698 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
7699 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
7700 *found_addrp
= found_addr
;
7703 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
7709 remote_rcmd (char *command
,
7710 struct ui_file
*outbuf
)
7712 struct remote_state
*rs
= get_remote_state ();
7716 error (_("remote rcmd is only available after target open"));
7718 /* Send a NULL command across as an empty command. */
7719 if (command
== NULL
)
7722 /* The query prefix. */
7723 strcpy (rs
->buf
, "qRcmd,");
7724 p
= strchr (rs
->buf
, '\0');
7726 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
7727 error (_("\"monitor\" command ``%s'' is too long."), command
);
7729 /* Encode the actual command. */
7730 bin2hex ((gdb_byte
*) command
, p
, 0);
7732 if (putpkt (rs
->buf
) < 0)
7733 error (_("Communication problem with target."));
7735 /* get/display the response */
7740 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
7742 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7745 error (_("Target does not support this command."));
7746 if (buf
[0] == 'O' && buf
[1] != 'K')
7748 remote_console_output (buf
+ 1); /* 'O' message from stub. */
7751 if (strcmp (buf
, "OK") == 0)
7753 if (strlen (buf
) == 3 && buf
[0] == 'E'
7754 && isdigit (buf
[1]) && isdigit (buf
[2]))
7756 error (_("Protocol error with Rcmd"));
7758 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
7760 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
7761 fputc_unfiltered (c
, outbuf
);
7767 static VEC(mem_region_s
) *
7768 remote_memory_map (struct target_ops
*ops
)
7770 VEC(mem_region_s
) *result
= NULL
;
7771 char *text
= target_read_stralloc (¤t_target
,
7772 TARGET_OBJECT_MEMORY_MAP
, NULL
);
7776 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
7777 result
= parse_memory_map (text
);
7778 do_cleanups (back_to
);
7785 packet_command (char *args
, int from_tty
)
7787 struct remote_state
*rs
= get_remote_state ();
7790 error (_("command can only be used with remote target"));
7793 error (_("remote-packet command requires packet text as argument"));
7795 puts_filtered ("sending: ");
7796 print_packet (args
);
7797 puts_filtered ("\n");
7800 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7801 puts_filtered ("received: ");
7802 print_packet (rs
->buf
);
7803 puts_filtered ("\n");
7807 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
7809 static void display_thread_info (struct gdb_ext_thread_info
*info
);
7811 static void threadset_test_cmd (char *cmd
, int tty
);
7813 static void threadalive_test (char *cmd
, int tty
);
7815 static void threadlist_test_cmd (char *cmd
, int tty
);
7817 int get_and_display_threadinfo (threadref
*ref
);
7819 static void threadinfo_test_cmd (char *cmd
, int tty
);
7821 static int thread_display_step (threadref
*ref
, void *context
);
7823 static void threadlist_update_test_cmd (char *cmd
, int tty
);
7825 static void init_remote_threadtests (void);
7827 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
7830 threadset_test_cmd (char *cmd
, int tty
)
7832 int sample_thread
= SAMPLE_THREAD
;
7834 printf_filtered (_("Remote threadset test\n"));
7835 set_general_thread (sample_thread
);
7840 threadalive_test (char *cmd
, int tty
)
7842 int sample_thread
= SAMPLE_THREAD
;
7843 int pid
= ptid_get_pid (inferior_ptid
);
7844 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
7846 if (remote_thread_alive (ptid
))
7847 printf_filtered ("PASS: Thread alive test\n");
7849 printf_filtered ("FAIL: Thread alive test\n");
7852 void output_threadid (char *title
, threadref
*ref
);
7855 output_threadid (char *title
, threadref
*ref
)
7859 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
7861 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
7865 threadlist_test_cmd (char *cmd
, int tty
)
7868 threadref nextthread
;
7869 int done
, result_count
;
7870 threadref threadlist
[3];
7872 printf_filtered ("Remote Threadlist test\n");
7873 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
7874 &result_count
, &threadlist
[0]))
7875 printf_filtered ("FAIL: threadlist test\n");
7878 threadref
*scan
= threadlist
;
7879 threadref
*limit
= scan
+ result_count
;
7881 while (scan
< limit
)
7882 output_threadid (" thread ", scan
++);
7887 display_thread_info (struct gdb_ext_thread_info
*info
)
7889 output_threadid ("Threadid: ", &info
->threadid
);
7890 printf_filtered ("Name: %s\n ", info
->shortname
);
7891 printf_filtered ("State: %s\n", info
->display
);
7892 printf_filtered ("other: %s\n\n", info
->more_display
);
7896 get_and_display_threadinfo (threadref
*ref
)
7900 struct gdb_ext_thread_info threadinfo
;
7902 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
7903 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
7904 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
7905 display_thread_info (&threadinfo
);
7910 threadinfo_test_cmd (char *cmd
, int tty
)
7912 int athread
= SAMPLE_THREAD
;
7916 int_to_threadref (&thread
, athread
);
7917 printf_filtered ("Remote Threadinfo test\n");
7918 if (!get_and_display_threadinfo (&thread
))
7919 printf_filtered ("FAIL cannot get thread info\n");
7923 thread_display_step (threadref
*ref
, void *context
)
7925 /* output_threadid(" threadstep ",ref); *//* simple test */
7926 return get_and_display_threadinfo (ref
);
7930 threadlist_update_test_cmd (char *cmd
, int tty
)
7932 printf_filtered ("Remote Threadlist update test\n");
7933 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
7937 init_remote_threadtests (void)
7939 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
7940 Fetch and print the remote list of thread identifiers, one pkt only"));
7941 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
7942 _("Fetch and display info about one thread"));
7943 add_com ("tset", class_obscure
, threadset_test_cmd
,
7944 _("Test setting to a different thread"));
7945 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
7946 _("Iterate through updating all remote thread info"));
7947 add_com ("talive", class_obscure
, threadalive_test
,
7948 _(" Remote thread alive test "));
7953 /* Convert a thread ID to a string. Returns the string in a static
7957 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
7959 static char buf
[64];
7960 struct remote_state
*rs
= get_remote_state ();
7962 if (ptid_is_pid (ptid
))
7964 /* Printing an inferior target id. */
7966 /* When multi-process extensions are off, there's no way in the
7967 remote protocol to know the remote process id, if there's any
7968 at all. There's one exception --- when we're connected with
7969 target extended-remote, and we manually attached to a process
7970 with "attach PID". We don't record anywhere a flag that
7971 allows us to distinguish that case from the case of
7972 connecting with extended-remote and the stub already being
7973 attached to a process, and reporting yes to qAttached, hence
7974 no smart special casing here. */
7975 if (!remote_multi_process_p (rs
))
7977 xsnprintf (buf
, sizeof buf
, "Remote target");
7981 return normal_pid_to_str (ptid
);
7985 if (ptid_equal (magic_null_ptid
, ptid
))
7986 xsnprintf (buf
, sizeof buf
, "Thread <main>");
7987 else if (remote_multi_process_p (rs
))
7988 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
7989 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
7991 xsnprintf (buf
, sizeof buf
, "Thread %ld",
7992 ptid_get_tid (ptid
));
7997 /* Get the address of the thread local variable in OBJFILE which is
7998 stored at OFFSET within the thread local storage for thread PTID. */
8001 remote_get_thread_local_address (struct target_ops
*ops
,
8002 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8004 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8006 struct remote_state
*rs
= get_remote_state ();
8008 char *endp
= rs
->buf
+ get_remote_packet_size ();
8009 enum packet_result result
;
8011 strcpy (p
, "qGetTLSAddr:");
8013 p
= write_ptid (p
, endp
, ptid
);
8015 p
+= hexnumstr (p
, offset
);
8017 p
+= hexnumstr (p
, lm
);
8021 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8022 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8023 if (result
== PACKET_OK
)
8027 unpack_varlen_hex (rs
->buf
, &result
);
8030 else if (result
== PACKET_UNKNOWN
)
8031 throw_error (TLS_GENERIC_ERROR
,
8032 _("Remote target doesn't support qGetTLSAddr packet"));
8034 throw_error (TLS_GENERIC_ERROR
,
8035 _("Remote target failed to process qGetTLSAddr request"));
8038 throw_error (TLS_GENERIC_ERROR
,
8039 _("TLS not supported or disabled on this target"));
8044 /* Support for inferring a target description based on the current
8045 architecture and the size of a 'g' packet. While the 'g' packet
8046 can have any size (since optional registers can be left off the
8047 end), some sizes are easily recognizable given knowledge of the
8048 approximate architecture. */
8050 struct remote_g_packet_guess
8053 const struct target_desc
*tdesc
;
8055 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8056 DEF_VEC_O(remote_g_packet_guess_s
);
8058 struct remote_g_packet_data
8060 VEC(remote_g_packet_guess_s
) *guesses
;
8063 static struct gdbarch_data
*remote_g_packet_data_handle
;
8066 remote_g_packet_data_init (struct obstack
*obstack
)
8068 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8072 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8073 const struct target_desc
*tdesc
)
8075 struct remote_g_packet_data
*data
8076 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8077 struct remote_g_packet_guess new_guess
, *guess
;
8080 gdb_assert (tdesc
!= NULL
);
8083 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8085 if (guess
->bytes
== bytes
)
8086 internal_error (__FILE__
, __LINE__
,
8087 "Duplicate g packet description added for size %d",
8090 new_guess
.bytes
= bytes
;
8091 new_guess
.tdesc
= tdesc
;
8092 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8095 /* Return 1 if remote_read_description would do anything on this target
8096 and architecture, 0 otherwise. */
8099 remote_read_description_p (struct target_ops
*target
)
8101 struct remote_g_packet_data
*data
8102 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8104 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8110 static const struct target_desc
*
8111 remote_read_description (struct target_ops
*target
)
8113 struct remote_g_packet_data
*data
8114 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8116 /* Do not try this during initial connection, when we do not know
8117 whether there is a running but stopped thread. */
8118 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8121 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8123 struct remote_g_packet_guess
*guess
;
8125 int bytes
= send_g_packet ();
8128 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8130 if (guess
->bytes
== bytes
)
8131 return guess
->tdesc
;
8133 /* We discard the g packet. A minor optimization would be to
8134 hold on to it, and fill the register cache once we have selected
8135 an architecture, but it's too tricky to do safely. */
8141 /* Remote file transfer support. This is host-initiated I/O, not
8142 target-initiated; for target-initiated, see remote-fileio.c. */
8144 /* If *LEFT is at least the length of STRING, copy STRING to
8145 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8146 decrease *LEFT. Otherwise raise an error. */
8149 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8151 int len
= strlen (string
);
8154 error (_("Packet too long for target."));
8156 memcpy (*buffer
, string
, len
);
8160 /* NUL-terminate the buffer as a convenience, if there is
8166 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8167 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8168 decrease *LEFT. Otherwise raise an error. */
8171 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8174 if (2 * len
> *left
)
8175 error (_("Packet too long for target."));
8177 bin2hex (bytes
, *buffer
, len
);
8181 /* NUL-terminate the buffer as a convenience, if there is
8187 /* If *LEFT is large enough, convert VALUE to hex and add it to
8188 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8189 decrease *LEFT. Otherwise raise an error. */
8192 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
8194 int len
= hexnumlen (value
);
8197 error (_("Packet too long for target."));
8199 hexnumstr (*buffer
, value
);
8203 /* NUL-terminate the buffer as a convenience, if there is
8209 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8210 value, *REMOTE_ERRNO to the remote error number or zero if none
8211 was included, and *ATTACHMENT to point to the start of the annex
8212 if any. The length of the packet isn't needed here; there may
8213 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8215 Return 0 if the packet could be parsed, -1 if it could not. If
8216 -1 is returned, the other variables may not be initialized. */
8219 remote_hostio_parse_result (char *buffer
, int *retcode
,
8220 int *remote_errno
, char **attachment
)
8227 if (buffer
[0] != 'F')
8231 *retcode
= strtol (&buffer
[1], &p
, 16);
8232 if (errno
!= 0 || p
== &buffer
[1])
8235 /* Check for ",errno". */
8239 *remote_errno
= strtol (p
+ 1, &p2
, 16);
8240 if (errno
!= 0 || p
+ 1 == p2
)
8245 /* Check for ";attachment". If there is no attachment, the
8246 packet should end here. */
8249 *attachment
= p
+ 1;
8252 else if (*p
== '\0')
8258 /* Send a prepared I/O packet to the target and read its response.
8259 The prepared packet is in the global RS->BUF before this function
8260 is called, and the answer is there when we return.
8262 COMMAND_BYTES is the length of the request to send, which may include
8263 binary data. WHICH_PACKET is the packet configuration to check
8264 before attempting a packet. If an error occurs, *REMOTE_ERRNO
8265 is set to the error number and -1 is returned. Otherwise the value
8266 returned by the function is returned.
8268 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
8269 attachment is expected; an error will be reported if there's a
8270 mismatch. If one is found, *ATTACHMENT will be set to point into
8271 the packet buffer and *ATTACHMENT_LEN will be set to the
8272 attachment's length. */
8275 remote_hostio_send_command (int command_bytes
, int which_packet
,
8276 int *remote_errno
, char **attachment
,
8277 int *attachment_len
)
8279 struct remote_state
*rs
= get_remote_state ();
8280 int ret
, bytes_read
;
8281 char *attachment_tmp
;
8284 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
8286 *remote_errno
= FILEIO_ENOSYS
;
8290 putpkt_binary (rs
->buf
, command_bytes
);
8291 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8293 /* If it timed out, something is wrong. Don't try to parse the
8297 *remote_errno
= FILEIO_EINVAL
;
8301 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
8304 *remote_errno
= FILEIO_EINVAL
;
8306 case PACKET_UNKNOWN
:
8307 *remote_errno
= FILEIO_ENOSYS
;
8313 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
8316 *remote_errno
= FILEIO_EINVAL
;
8320 /* Make sure we saw an attachment if and only if we expected one. */
8321 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
8322 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
8324 *remote_errno
= FILEIO_EINVAL
;
8328 /* If an attachment was found, it must point into the packet buffer;
8329 work out how many bytes there were. */
8330 if (attachment_tmp
!= NULL
)
8332 *attachment
= attachment_tmp
;
8333 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
8339 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
8340 remote file descriptor, or -1 if an error occurs (and set
8344 remote_hostio_open (const char *filename
, int flags
, int mode
,
8347 struct remote_state
*rs
= get_remote_state ();
8349 int left
= get_remote_packet_size () - 1;
8351 remote_buffer_add_string (&p
, &left
, "vFile:open:");
8353 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8355 remote_buffer_add_string (&p
, &left
, ",");
8357 remote_buffer_add_int (&p
, &left
, flags
);
8358 remote_buffer_add_string (&p
, &left
, ",");
8360 remote_buffer_add_int (&p
, &left
, mode
);
8362 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
8363 remote_errno
, NULL
, NULL
);
8366 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
8367 Return the number of bytes written, or -1 if an error occurs (and
8368 set *REMOTE_ERRNO). */
8371 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
8372 ULONGEST offset
, int *remote_errno
)
8374 struct remote_state
*rs
= get_remote_state ();
8376 int left
= get_remote_packet_size ();
8379 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
8381 remote_buffer_add_int (&p
, &left
, fd
);
8382 remote_buffer_add_string (&p
, &left
, ",");
8384 remote_buffer_add_int (&p
, &left
, offset
);
8385 remote_buffer_add_string (&p
, &left
, ",");
8387 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
8388 get_remote_packet_size () - (p
- rs
->buf
));
8390 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
8391 remote_errno
, NULL
, NULL
);
8394 /* Read up to LEN bytes FD on the remote target into READ_BUF
8395 Return the number of bytes read, or -1 if an error occurs (and
8396 set *REMOTE_ERRNO). */
8399 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
8400 ULONGEST offset
, int *remote_errno
)
8402 struct remote_state
*rs
= get_remote_state ();
8405 int left
= get_remote_packet_size ();
8406 int ret
, attachment_len
;
8409 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
8411 remote_buffer_add_int (&p
, &left
, fd
);
8412 remote_buffer_add_string (&p
, &left
, ",");
8414 remote_buffer_add_int (&p
, &left
, len
);
8415 remote_buffer_add_string (&p
, &left
, ",");
8417 remote_buffer_add_int (&p
, &left
, offset
);
8419 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
8420 remote_errno
, &attachment
,
8426 read_len
= remote_unescape_input (attachment
, attachment_len
,
8428 if (read_len
!= ret
)
8429 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
8434 /* Close FD on the remote target. Return 0, or -1 if an error occurs
8435 (and set *REMOTE_ERRNO). */
8438 remote_hostio_close (int fd
, int *remote_errno
)
8440 struct remote_state
*rs
= get_remote_state ();
8442 int left
= get_remote_packet_size () - 1;
8444 remote_buffer_add_string (&p
, &left
, "vFile:close:");
8446 remote_buffer_add_int (&p
, &left
, fd
);
8448 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
8449 remote_errno
, NULL
, NULL
);
8452 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
8453 occurs (and set *REMOTE_ERRNO). */
8456 remote_hostio_unlink (const char *filename
, int *remote_errno
)
8458 struct remote_state
*rs
= get_remote_state ();
8460 int left
= get_remote_packet_size () - 1;
8462 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
8464 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8467 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
8468 remote_errno
, NULL
, NULL
);
8472 remote_fileio_errno_to_host (int errnum
)
8496 case FILEIO_ENOTDIR
:
8516 case FILEIO_ENAMETOOLONG
:
8517 return ENAMETOOLONG
;
8523 remote_hostio_error (int errnum
)
8525 int host_error
= remote_fileio_errno_to_host (errnum
);
8527 if (host_error
== -1)
8528 error (_("Unknown remote I/O error %d"), errnum
);
8530 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
8534 remote_hostio_close_cleanup (void *opaque
)
8536 int fd
= *(int *) opaque
;
8539 remote_hostio_close (fd
, &remote_errno
);
8544 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
8546 const char *filename
= bfd_get_filename (abfd
);
8547 int fd
, remote_errno
;
8550 gdb_assert (remote_filename_p (filename
));
8552 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
8555 errno
= remote_fileio_errno_to_host (remote_errno
);
8556 bfd_set_error (bfd_error_system_call
);
8560 stream
= xmalloc (sizeof (int));
8566 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
8568 int fd
= *(int *)stream
;
8573 /* Ignore errors on close; these may happen if the remote
8574 connection was already torn down. */
8575 remote_hostio_close (fd
, &remote_errno
);
8581 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
8582 file_ptr nbytes
, file_ptr offset
)
8584 int fd
= *(int *)stream
;
8586 file_ptr pos
, bytes
;
8589 while (nbytes
> pos
)
8591 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
8592 offset
+ pos
, &remote_errno
);
8594 /* Success, but no bytes, means end-of-file. */
8598 errno
= remote_fileio_errno_to_host (remote_errno
);
8599 bfd_set_error (bfd_error_system_call
);
8610 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
8612 /* FIXME: We should probably implement remote_hostio_stat. */
8613 sb
->st_size
= INT_MAX
;
8618 remote_filename_p (const char *filename
)
8620 return strncmp (filename
, "remote:", 7) == 0;
8624 remote_bfd_open (const char *remote_file
, const char *target
)
8626 return bfd_openr_iovec (remote_file
, target
,
8627 remote_bfd_iovec_open
, NULL
,
8628 remote_bfd_iovec_pread
,
8629 remote_bfd_iovec_close
,
8630 remote_bfd_iovec_stat
);
8634 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
8636 struct cleanup
*back_to
, *close_cleanup
;
8637 int retcode
, fd
, remote_errno
, bytes
, io_size
;
8640 int bytes_in_buffer
;
8645 error (_("command can only be used with remote target"));
8647 file
= fopen (local_file
, "rb");
8649 perror_with_name (local_file
);
8650 back_to
= make_cleanup_fclose (file
);
8652 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
8654 0700, &remote_errno
);
8656 remote_hostio_error (remote_errno
);
8658 /* Send up to this many bytes at once. They won't all fit in the
8659 remote packet limit, so we'll transfer slightly fewer. */
8660 io_size
= get_remote_packet_size ();
8661 buffer
= xmalloc (io_size
);
8662 make_cleanup (xfree
, buffer
);
8664 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
8666 bytes_in_buffer
= 0;
8669 while (bytes_in_buffer
|| !saw_eof
)
8673 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
8678 error (_("Error reading %s."), local_file
);
8681 /* EOF. Unless there is something still in the
8682 buffer from the last iteration, we are done. */
8684 if (bytes_in_buffer
== 0)
8692 bytes
+= bytes_in_buffer
;
8693 bytes_in_buffer
= 0;
8695 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
8698 remote_hostio_error (remote_errno
);
8699 else if (retcode
== 0)
8700 error (_("Remote write of %d bytes returned 0!"), bytes
);
8701 else if (retcode
< bytes
)
8703 /* Short write. Save the rest of the read data for the next
8705 bytes_in_buffer
= bytes
- retcode
;
8706 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
8712 discard_cleanups (close_cleanup
);
8713 if (remote_hostio_close (fd
, &remote_errno
))
8714 remote_hostio_error (remote_errno
);
8717 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
8718 do_cleanups (back_to
);
8722 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
8724 struct cleanup
*back_to
, *close_cleanup
;
8725 int fd
, remote_errno
, bytes
, io_size
;
8731 error (_("command can only be used with remote target"));
8733 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
8735 remote_hostio_error (remote_errno
);
8737 file
= fopen (local_file
, "wb");
8739 perror_with_name (local_file
);
8740 back_to
= make_cleanup_fclose (file
);
8742 /* Send up to this many bytes at once. They won't all fit in the
8743 remote packet limit, so we'll transfer slightly fewer. */
8744 io_size
= get_remote_packet_size ();
8745 buffer
= xmalloc (io_size
);
8746 make_cleanup (xfree
, buffer
);
8748 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
8753 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
8755 /* Success, but no bytes, means end-of-file. */
8758 remote_hostio_error (remote_errno
);
8762 bytes
= fwrite (buffer
, 1, bytes
, file
);
8764 perror_with_name (local_file
);
8767 discard_cleanups (close_cleanup
);
8768 if (remote_hostio_close (fd
, &remote_errno
))
8769 remote_hostio_error (remote_errno
);
8772 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
8773 do_cleanups (back_to
);
8777 remote_file_delete (const char *remote_file
, int from_tty
)
8779 int retcode
, remote_errno
;
8782 error (_("command can only be used with remote target"));
8784 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
8786 remote_hostio_error (remote_errno
);
8789 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
8793 remote_put_command (char *args
, int from_tty
)
8795 struct cleanup
*back_to
;
8799 error_no_arg (_("file to put"));
8801 argv
= gdb_buildargv (args
);
8802 back_to
= make_cleanup_freeargv (argv
);
8803 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
8804 error (_("Invalid parameters to remote put"));
8806 remote_file_put (argv
[0], argv
[1], from_tty
);
8808 do_cleanups (back_to
);
8812 remote_get_command (char *args
, int from_tty
)
8814 struct cleanup
*back_to
;
8818 error_no_arg (_("file to get"));
8820 argv
= gdb_buildargv (args
);
8821 back_to
= make_cleanup_freeargv (argv
);
8822 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
8823 error (_("Invalid parameters to remote get"));
8825 remote_file_get (argv
[0], argv
[1], from_tty
);
8827 do_cleanups (back_to
);
8831 remote_delete_command (char *args
, int from_tty
)
8833 struct cleanup
*back_to
;
8837 error_no_arg (_("file to delete"));
8839 argv
= gdb_buildargv (args
);
8840 back_to
= make_cleanup_freeargv (argv
);
8841 if (argv
[0] == NULL
|| argv
[1] != NULL
)
8842 error (_("Invalid parameters to remote delete"));
8844 remote_file_delete (argv
[0], from_tty
);
8846 do_cleanups (back_to
);
8850 remote_command (char *args
, int from_tty
)
8852 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
8856 remote_can_execute_reverse (void)
8858 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
8859 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
8866 remote_supports_non_stop (void)
8872 remote_supports_multi_process (void)
8874 struct remote_state
*rs
= get_remote_state ();
8875 return remote_multi_process_p (rs
);
8879 remote_supports_cond_tracepoints (void)
8881 struct remote_state
*rs
= get_remote_state ();
8882 return rs
->cond_tracepoints
;
8886 init_remote_ops (void)
8888 remote_ops
.to_shortname
= "remote";
8889 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
8891 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
8892 Specify the serial device it is connected to\n\
8893 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
8894 remote_ops
.to_open
= remote_open
;
8895 remote_ops
.to_close
= remote_close
;
8896 remote_ops
.to_detach
= remote_detach
;
8897 remote_ops
.to_disconnect
= remote_disconnect
;
8898 remote_ops
.to_resume
= remote_resume
;
8899 remote_ops
.to_wait
= remote_wait
;
8900 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
8901 remote_ops
.to_store_registers
= remote_store_registers
;
8902 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
8903 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
8904 remote_ops
.to_files_info
= remote_files_info
;
8905 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
8906 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
8907 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
8908 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
8909 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
8910 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
8911 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
8912 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
8913 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
8914 remote_ops
.to_kill
= remote_kill
;
8915 remote_ops
.to_load
= generic_load
;
8916 remote_ops
.to_mourn_inferior
= remote_mourn
;
8917 remote_ops
.to_thread_alive
= remote_thread_alive
;
8918 remote_ops
.to_find_new_threads
= remote_threads_info
;
8919 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
8920 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
8921 remote_ops
.to_stop
= remote_stop
;
8922 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
8923 remote_ops
.to_rcmd
= remote_rcmd
;
8924 remote_ops
.to_log_command
= serial_log_command
;
8925 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
8926 remote_ops
.to_stratum
= process_stratum
;
8927 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
8928 remote_ops
.to_has_memory
= default_child_has_memory
;
8929 remote_ops
.to_has_stack
= default_child_has_stack
;
8930 remote_ops
.to_has_registers
= default_child_has_registers
;
8931 remote_ops
.to_has_execution
= default_child_has_execution
;
8932 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
8933 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
8934 remote_ops
.to_magic
= OPS_MAGIC
;
8935 remote_ops
.to_memory_map
= remote_memory_map
;
8936 remote_ops
.to_flash_erase
= remote_flash_erase
;
8937 remote_ops
.to_flash_done
= remote_flash_done
;
8938 remote_ops
.to_read_description
= remote_read_description
;
8939 remote_ops
.to_search_memory
= remote_search_memory
;
8940 remote_ops
.to_can_async_p
= remote_can_async_p
;
8941 remote_ops
.to_is_async_p
= remote_is_async_p
;
8942 remote_ops
.to_async
= remote_async
;
8943 remote_ops
.to_async_mask
= remote_async_mask
;
8944 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
8945 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
8946 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
8947 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
8950 /* Set up the extended remote vector by making a copy of the standard
8951 remote vector and adding to it. */
8954 init_extended_remote_ops (void)
8956 extended_remote_ops
= remote_ops
;
8958 extended_remote_ops
.to_shortname
= "extended-remote";
8959 extended_remote_ops
.to_longname
=
8960 "Extended remote serial target in gdb-specific protocol";
8961 extended_remote_ops
.to_doc
=
8962 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
8963 Specify the serial device it is connected to (e.g. /dev/ttya).";
8964 extended_remote_ops
.to_open
= extended_remote_open
;
8965 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
8966 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
8967 extended_remote_ops
.to_detach
= extended_remote_detach
;
8968 extended_remote_ops
.to_attach
= extended_remote_attach
;
8969 extended_remote_ops
.to_kill
= extended_remote_kill
;
8973 remote_can_async_p (void)
8975 if (!target_async_permitted
)
8976 /* We only enable async when the user specifically asks for it. */
8979 /* We're async whenever the serial device is. */
8980 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
8984 remote_is_async_p (void)
8986 if (!target_async_permitted
)
8987 /* We only enable async when the user specifically asks for it. */
8990 /* We're async whenever the serial device is. */
8991 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
8994 /* Pass the SERIAL event on and up to the client. One day this code
8995 will be able to delay notifying the client of an event until the
8996 point where an entire packet has been received. */
8998 static void (*async_client_callback
) (enum inferior_event_type event_type
,
9000 static void *async_client_context
;
9001 static serial_event_ftype remote_async_serial_handler
;
9004 remote_async_serial_handler (struct serial
*scb
, void *context
)
9006 /* Don't propogate error information up to the client. Instead let
9007 the client find out about the error by querying the target. */
9008 async_client_callback (INF_REG_EVENT
, async_client_context
);
9012 remote_async_inferior_event_handler (gdb_client_data data
)
9014 inferior_event_handler (INF_REG_EVENT
, NULL
);
9018 remote_async_get_pending_events_handler (gdb_client_data data
)
9020 remote_get_pending_stop_replies ();
9024 remote_async (void (*callback
) (enum inferior_event_type event_type
,
9025 void *context
), void *context
)
9027 if (remote_async_mask_value
== 0)
9028 internal_error (__FILE__
, __LINE__
,
9029 _("Calling remote_async when async is masked"));
9031 if (callback
!= NULL
)
9033 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
9034 async_client_callback
= callback
;
9035 async_client_context
= context
;
9038 serial_async (remote_desc
, NULL
, NULL
);
9042 remote_async_mask (int new_mask
)
9044 int curr_mask
= remote_async_mask_value
;
9045 remote_async_mask_value
= new_mask
;
9050 set_remote_cmd (char *args
, int from_tty
)
9052 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
9056 show_remote_cmd (char *args
, int from_tty
)
9058 /* We can't just use cmd_show_list here, because we want to skip
9059 the redundant "show remote Z-packet" and the legacy aliases. */
9060 struct cleanup
*showlist_chain
;
9061 struct cmd_list_element
*list
= remote_show_cmdlist
;
9063 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
9064 for (; list
!= NULL
; list
= list
->next
)
9065 if (strcmp (list
->name
, "Z-packet") == 0)
9067 else if (list
->type
== not_set_cmd
)
9068 /* Alias commands are exactly like the original, except they
9069 don't have the normal type. */
9073 struct cleanup
*option_chain
9074 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
9075 ui_out_field_string (uiout
, "name", list
->name
);
9076 ui_out_text (uiout
, ": ");
9077 if (list
->type
== show_cmd
)
9078 do_setshow_command ((char *) NULL
, from_tty
, list
);
9080 cmd_func (list
, NULL
, from_tty
);
9081 /* Close the tuple. */
9082 do_cleanups (option_chain
);
9085 /* Close the tuple. */
9086 do_cleanups (showlist_chain
);
9090 /* Function to be called whenever a new objfile (shlib) is detected. */
9092 remote_new_objfile (struct objfile
*objfile
)
9094 if (remote_desc
!= 0) /* Have a remote connection. */
9095 remote_check_symbols (objfile
);
9099 _initialize_remote (void)
9101 struct remote_state
*rs
;
9102 struct cmd_list_element
*cmd
;
9105 /* architecture specific data */
9106 remote_gdbarch_data_handle
=
9107 gdbarch_data_register_post_init (init_remote_state
);
9108 remote_g_packet_data_handle
=
9109 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
9111 /* Initialize the per-target state. At the moment there is only one
9112 of these, not one per target. Only one target is active at a
9113 time. The default buffer size is unimportant; it will be expanded
9114 whenever a larger buffer is needed. */
9115 rs
= get_remote_state_raw ();
9117 rs
->buf
= xmalloc (rs
->buf_size
);
9120 add_target (&remote_ops
);
9122 init_extended_remote_ops ();
9123 add_target (&extended_remote_ops
);
9125 /* Hook into new objfile notification. */
9126 observer_attach_new_objfile (remote_new_objfile
);
9128 /* Set up signal handlers. */
9129 sigint_remote_token
=
9130 create_async_signal_handler (async_remote_interrupt
, NULL
);
9131 sigint_remote_twice_token
=
9132 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
9135 init_remote_threadtests ();
9138 /* set/show remote ... */
9140 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
9141 Remote protocol specific variables\n\
9142 Configure various remote-protocol specific variables such as\n\
9143 the packets being used"),
9144 &remote_set_cmdlist
, "set remote ",
9145 0 /* allow-unknown */, &setlist
);
9146 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
9147 Remote protocol specific variables\n\
9148 Configure various remote-protocol specific variables such as\n\
9149 the packets being used"),
9150 &remote_show_cmdlist
, "show remote ",
9151 0 /* allow-unknown */, &showlist
);
9153 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
9154 Compare section data on target to the exec file.\n\
9155 Argument is a single section name (default: all loaded sections)."),
9158 add_cmd ("packet", class_maintenance
, packet_command
, _("\
9159 Send an arbitrary packet to a remote target.\n\
9160 maintenance packet TEXT\n\
9161 If GDB is talking to an inferior via the GDB serial protocol, then\n\
9162 this command sends the string TEXT to the inferior, and displays the\n\
9163 response packet. GDB supplies the initial `$' character, and the\n\
9164 terminating `#' character and checksum."),
9167 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
9168 Set whether to send break if interrupted."), _("\
9169 Show whether to send break if interrupted."), _("\
9170 If set, a break, instead of a cntrl-c, is sent to the remote target."),
9171 set_remotebreak
, show_remotebreak
,
9172 &setlist
, &showlist
);
9173 cmd_name
= "remotebreak";
9174 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
9175 deprecate_cmd (cmd
, "set remote interrupt-sequence");
9176 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
9177 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
9178 deprecate_cmd (cmd
, "show remote interrupt-sequence");
9180 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
9181 interrupt_sequence_modes
, &interrupt_sequence_mode
, _("\
9182 Set interrupt sequence to remote target."), _("\
9183 Show interrupt sequence to remote target."), _("\
9184 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
9185 NULL
, show_interrupt_sequence
,
9186 &remote_set_cmdlist
,
9187 &remote_show_cmdlist
);
9189 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
9190 &interrupt_on_connect
, _("\
9191 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
9192 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
9193 If set, interrupt sequence is sent to remote target."),
9195 &remote_set_cmdlist
, &remote_show_cmdlist
);
9197 /* Install commands for configuring memory read/write packets. */
9199 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
9200 Set the maximum number of bytes per memory write packet (deprecated)."),
9202 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
9203 Show the maximum number of bytes per memory write packet (deprecated)."),
9205 add_cmd ("memory-write-packet-size", no_class
,
9206 set_memory_write_packet_size
, _("\
9207 Set the maximum number of bytes per memory-write packet.\n\
9208 Specify the number of bytes in a packet or 0 (zero) for the\n\
9209 default packet size. The actual limit is further reduced\n\
9210 dependent on the target. Specify ``fixed'' to disable the\n\
9211 further restriction and ``limit'' to enable that restriction."),
9212 &remote_set_cmdlist
);
9213 add_cmd ("memory-read-packet-size", no_class
,
9214 set_memory_read_packet_size
, _("\
9215 Set the maximum number of bytes per memory-read packet.\n\
9216 Specify the number of bytes in a packet or 0 (zero) for the\n\
9217 default packet size. The actual limit is further reduced\n\
9218 dependent on the target. Specify ``fixed'' to disable the\n\
9219 further restriction and ``limit'' to enable that restriction."),
9220 &remote_set_cmdlist
);
9221 add_cmd ("memory-write-packet-size", no_class
,
9222 show_memory_write_packet_size
,
9223 _("Show the maximum number of bytes per memory-write packet."),
9224 &remote_show_cmdlist
);
9225 add_cmd ("memory-read-packet-size", no_class
,
9226 show_memory_read_packet_size
,
9227 _("Show the maximum number of bytes per memory-read packet."),
9228 &remote_show_cmdlist
);
9230 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
9231 &remote_hw_watchpoint_limit
, _("\
9232 Set the maximum number of target hardware watchpoints."), _("\
9233 Show the maximum number of target hardware watchpoints."), _("\
9234 Specify a negative limit for unlimited."),
9235 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
9236 &remote_set_cmdlist
, &remote_show_cmdlist
);
9237 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
9238 &remote_hw_breakpoint_limit
, _("\
9239 Set the maximum number of target hardware breakpoints."), _("\
9240 Show the maximum number of target hardware breakpoints."), _("\
9241 Specify a negative limit for unlimited."),
9242 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
9243 &remote_set_cmdlist
, &remote_show_cmdlist
);
9245 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
9246 &remote_address_size
, _("\
9247 Set the maximum size of the address (in bits) in a memory packet."), _("\
9248 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
9250 NULL
, /* FIXME: i18n: */
9251 &setlist
, &showlist
);
9253 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
9254 "X", "binary-download", 1);
9256 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
9257 "vCont", "verbose-resume", 0);
9259 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
9260 "QPassSignals", "pass-signals", 0);
9262 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
9263 "qSymbol", "symbol-lookup", 0);
9265 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
9266 "P", "set-register", 1);
9268 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
9269 "p", "fetch-register", 1);
9271 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
9272 "Z0", "software-breakpoint", 0);
9274 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
9275 "Z1", "hardware-breakpoint", 0);
9277 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
9278 "Z2", "write-watchpoint", 0);
9280 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
9281 "Z3", "read-watchpoint", 0);
9283 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
9284 "Z4", "access-watchpoint", 0);
9286 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
9287 "qXfer:auxv:read", "read-aux-vector", 0);
9289 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
9290 "qXfer:features:read", "target-features", 0);
9292 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
9293 "qXfer:libraries:read", "library-info", 0);
9295 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
9296 "qXfer:memory-map:read", "memory-map", 0);
9298 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
9299 "qXfer:spu:read", "read-spu-object", 0);
9301 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
9302 "qXfer:spu:write", "write-spu-object", 0);
9304 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
9305 "qXfer:osdata:read", "osdata", 0);
9307 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
9308 "qXfer:siginfo:read", "read-siginfo-object", 0);
9310 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
9311 "qXfer:siginfo:write", "write-siginfo-object", 0);
9313 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
9314 "qGetTLSAddr", "get-thread-local-storage-address",
9317 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
9318 "bc", "reverse-continue", 0);
9320 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
9321 "bs", "reverse-step", 0);
9323 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
9324 "qSupported", "supported-packets", 0);
9326 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
9327 "qSearch:memory", "search-memory", 0);
9329 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
9330 "vFile:open", "hostio-open", 0);
9332 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
9333 "vFile:pread", "hostio-pread", 0);
9335 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
9336 "vFile:pwrite", "hostio-pwrite", 0);
9338 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
9339 "vFile:close", "hostio-close", 0);
9341 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
9342 "vFile:unlink", "hostio-unlink", 0);
9344 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
9345 "vAttach", "attach", 0);
9347 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
9350 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
9351 "QStartNoAckMode", "noack", 0);
9353 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
9354 "vKill", "kill", 0);
9356 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
9357 "qAttached", "query-attached", 0);
9359 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
9360 "ConditionalTracepoints", "conditional-tracepoints", 0);
9362 /* Keep the old ``set remote Z-packet ...'' working. Each individual
9363 Z sub-packet has its own set and show commands, but users may
9364 have sets to this variable in their .gdbinit files (or in their
9366 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
9367 &remote_Z_packet_detect
, _("\
9368 Set use of remote protocol `Z' packets"), _("\
9369 Show use of remote protocol `Z' packets "), _("\
9370 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
9372 set_remote_protocol_Z_packet_cmd
,
9373 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
9374 &remote_set_cmdlist
, &remote_show_cmdlist
);
9376 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
9377 Manipulate files on the remote system\n\
9378 Transfer files to and from the remote target system."),
9379 &remote_cmdlist
, "remote ",
9380 0 /* allow-unknown */, &cmdlist
);
9382 add_cmd ("put", class_files
, remote_put_command
,
9383 _("Copy a local file to the remote system."),
9386 add_cmd ("get", class_files
, remote_get_command
,
9387 _("Copy a remote file to the local system."),
9390 add_cmd ("delete", class_files
, remote_delete_command
,
9391 _("Delete a remote file."),
9394 remote_exec_file
= xstrdup ("");
9395 add_setshow_string_noescape_cmd ("exec-file", class_files
,
9396 &remote_exec_file
, _("\
9397 Set the remote pathname for \"run\""), _("\
9398 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
9399 &remote_set_cmdlist
, &remote_show_cmdlist
);
9401 /* Eventually initialize fileio. See fileio.c */
9402 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
9404 /* Take advantage of the fact that the LWP field is not used, to tag
9405 special ptids with it set to != 0. */
9406 magic_null_ptid
= ptid_build (42000, 1, -1);
9407 not_sent_ptid
= ptid_build (42000, 1, -2);
9408 any_thread_ptid
= ptid_build (42000, 1, 0);