1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
23 #include "gdb_string.h"
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
39 #include "gdb_assert.h"
42 #include "cli/cli-decode.h"
43 #include "cli/cli-setshow.h"
44 #include "target-descriptions.h"
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 #include "remote-fileio.h"
59 #include "gdb/fileio.h"
61 #include "xml-support.h"
63 #include "memory-map.h"
65 #include "tracepoint.h"
69 /* Temp hacks for tracepoint encoding migration. */
70 static char *target_buf
;
71 static long target_buf_size
;
73 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
74 char ***tdp_actions
, char ***stepping_actions
);
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void cleanup_sigint_signal_handler (void *dummy
);
90 static void initialize_sigint_signal_handler (void);
91 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
92 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
95 static void handle_remote_sigint (int);
96 static void handle_remote_sigint_twice (int);
97 static void async_remote_interrupt (gdb_client_data
);
98 void async_remote_interrupt_twice (gdb_client_data
);
100 static void remote_files_info (struct target_ops
*ignore
);
102 static void remote_prepare_to_store (struct regcache
*regcache
);
104 static void remote_open (char *name
, int from_tty
);
106 static void extended_remote_open (char *name
, int from_tty
);
108 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
110 static void remote_close (int quitting
);
112 static void remote_mourn (struct target_ops
*ops
);
114 static void extended_remote_restart (void);
116 static void extended_remote_mourn (struct target_ops
*);
118 static void remote_mourn_1 (struct target_ops
*);
120 static void remote_send (char **buf
, long *sizeof_buf_p
);
122 static int readchar (int timeout
);
124 static void remote_kill (struct target_ops
*ops
);
126 static int tohex (int nib
);
128 static int remote_can_async_p (void);
130 static int remote_is_async_p (void);
132 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
133 void *context
), void *context
);
135 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
137 static void remote_interrupt (int signo
);
139 static void remote_interrupt_twice (int signo
);
141 static void interrupt_query (void);
143 static void set_general_thread (struct ptid ptid
);
144 static void set_continue_thread (struct ptid ptid
);
146 static void get_offsets (void);
148 static void skip_frame (void);
150 static long read_frame (char **buf_p
, long *sizeof_buf
);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void remote_stop (ptid_t
);
160 static int ishex (int ch
, int *val
);
162 static int stubhex (int ch
);
164 static int hexnumstr (char *, ULONGEST
);
166 static int hexnumnstr (char *, ULONGEST
, int);
168 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
170 static void print_packet (char *);
172 static void compare_sections_command (char *, int);
174 static void packet_command (char *, int);
176 static int stub_unpack_int (char *buff
, int fieldlength
);
178 static ptid_t
remote_current_thread (ptid_t oldptid
);
180 static void remote_find_new_threads (void);
182 static void record_currthread (ptid_t currthread
);
184 static int fromhex (int a
);
186 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
188 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
190 static int putpkt_binary (char *buf
, int cnt
);
192 static void check_binary_download (CORE_ADDR addr
);
194 struct packet_config
;
196 static void show_packet_config_cmd (struct packet_config
*config
);
198 static void update_packet_config (struct packet_config
*config
);
200 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
201 struct cmd_list_element
*c
);
203 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
205 struct cmd_list_element
*c
,
208 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
209 static ptid_t
read_ptid (char *buf
, char **obuf
);
211 static void remote_set_permissions (void);
214 static int remote_get_trace_status (struct trace_status
*ts
);
216 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
218 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
220 static void remote_query_supported (void);
222 static void remote_check_symbols (struct objfile
*objfile
);
224 void _initialize_remote (void);
227 static struct stop_reply
*stop_reply_xmalloc (void);
228 static void stop_reply_xfree (struct stop_reply
*);
229 static void do_stop_reply_xfree (void *arg
);
230 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
231 static void push_stop_reply (struct stop_reply
*);
232 static void remote_get_pending_stop_replies (void);
233 static void discard_pending_stop_replies (int pid
);
234 static int peek_stop_reply (ptid_t ptid
);
236 static void remote_async_inferior_event_handler (gdb_client_data
);
237 static void remote_async_get_pending_events_handler (gdb_client_data
);
239 static void remote_terminal_ours (void);
241 static int remote_read_description_p (struct target_ops
*target
);
243 static void remote_console_output (char *msg
);
245 /* The non-stop remote protocol provisions for one pending stop reply.
246 This is where we keep it until it is acknowledged. */
248 static struct stop_reply
*pending_stop_reply
= NULL
;
252 static struct cmd_list_element
*remote_cmdlist
;
254 /* For "set remote" and "show remote". */
256 static struct cmd_list_element
*remote_set_cmdlist
;
257 static struct cmd_list_element
*remote_show_cmdlist
;
259 /* Description of the remote protocol state for the currently
260 connected target. This is per-target state, and independent of the
261 selected architecture. */
265 /* A buffer to use for incoming packets, and its current size. The
266 buffer is grown dynamically for larger incoming packets.
267 Outgoing packets may also be constructed in this buffer.
268 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
269 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
274 /* If we negotiated packet size explicitly (and thus can bypass
275 heuristics for the largest packet size that will not overflow
276 a buffer in the stub), this will be set to that packet size.
277 Otherwise zero, meaning to use the guessed size. */
278 long explicit_packet_size
;
280 /* remote_wait is normally called when the target is running and
281 waits for a stop reply packet. But sometimes we need to call it
282 when the target is already stopped. We can send a "?" packet
283 and have remote_wait read the response. Or, if we already have
284 the response, we can stash it in BUF and tell remote_wait to
285 skip calling getpkt. This flag is set when BUF contains a
286 stop reply packet and the target is not waiting. */
287 int cached_wait_status
;
289 /* True, if in no ack mode. That is, neither GDB nor the stub will
290 expect acks from each other. The connection is assumed to be
294 /* True if we're connected in extended remote mode. */
297 /* True if the stub reported support for multi-process
299 int multi_process_aware
;
301 /* True if we resumed the target and we're waiting for the target to
302 stop. In the mean time, we can't start another command/query.
303 The remote server wouldn't be ready to process it, so we'd
304 timeout waiting for a reply that would never come and eventually
305 we'd close the connection. This can happen in asynchronous mode
306 because we allow GDB commands while the target is running. */
307 int waiting_for_stop_reply
;
309 /* True if the stub reports support for non-stop mode. */
312 /* True if the stub reports support for vCont;t. */
315 /* True if the stub reports support for conditional tracepoints. */
316 int cond_tracepoints
;
318 /* True if the stub reports support for fast tracepoints. */
319 int fast_tracepoints
;
321 /* True if the stub reports support for static tracepoints. */
322 int static_tracepoints
;
324 /* True if the stub reports support for installing tracepoint while
326 int install_in_trace
;
328 /* True if the stub can continue running a trace while GDB is
330 int disconnected_tracing
;
332 /* True if the stub reports support for enabling and disabling
333 tracepoints while a trace experiment is running. */
334 int enable_disable_tracepoints
;
336 /* True if the stub can collect strings using tracenz bytecode. */
339 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
340 responded to that. */
344 /* Private data that we'll store in (struct thread_info)->private. */
345 struct private_thread_info
352 free_private_thread_info (struct private_thread_info
*info
)
358 /* Returns true if the multi-process extensions are in effect. */
360 remote_multi_process_p (struct remote_state
*rs
)
362 return rs
->multi_process_aware
;
365 /* This data could be associated with a target, but we do not always
366 have access to the current target when we need it, so for now it is
367 static. This will be fine for as long as only one target is in use
369 static struct remote_state remote_state
;
371 static struct remote_state
*
372 get_remote_state_raw (void)
374 return &remote_state
;
377 /* Description of the remote protocol for a given architecture. */
381 long offset
; /* Offset into G packet. */
382 long regnum
; /* GDB's internal register number. */
383 LONGEST pnum
; /* Remote protocol register number. */
384 int in_g_packet
; /* Always part of G packet. */
385 /* long size in bytes; == register_size (target_gdbarch, regnum);
387 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
391 struct remote_arch_state
393 /* Description of the remote protocol registers. */
394 long sizeof_g_packet
;
396 /* Description of the remote protocol registers indexed by REGNUM
397 (making an array gdbarch_num_regs in size). */
398 struct packet_reg
*regs
;
400 /* This is the size (in chars) of the first response to the ``g''
401 packet. It is used as a heuristic when determining the maximum
402 size of memory-read and memory-write packets. A target will
403 typically only reserve a buffer large enough to hold the ``g''
404 packet. The size does not include packet overhead (headers and
406 long actual_register_packet_size
;
408 /* This is the maximum size (in chars) of a non read/write packet.
409 It is also used as a cap on the size of read/write packets. */
410 long remote_packet_size
;
413 long sizeof_pkt
= 2000;
415 /* Utility: generate error from an incoming stub packet. */
417 trace_error (char *buf
)
420 return; /* not an error msg */
423 case '1': /* malformed packet error */
424 if (*++buf
== '0') /* general case: */
425 error (_("remote.c: error in outgoing packet."));
427 error (_("remote.c: error in outgoing packet at field #%ld."),
428 strtol (buf
, NULL
, 16));
430 error (_("trace API error 0x%s."), ++buf
);
432 error (_("Target returns error code '%s'."), buf
);
436 /* Utility: wait for reply from stub, while accepting "O" packets. */
438 remote_get_noisy_reply (char **buf_p
,
441 do /* Loop on reply from remote stub. */
445 QUIT
; /* Allow user to bail out with ^C. */
446 getpkt (buf_p
, sizeof_buf
, 0);
450 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
453 CORE_ADDR from
, to
, org_to
;
455 int adjusted_size
= 0;
456 volatile struct gdb_exception ex
;
458 p
= buf
+ strlen ("qRelocInsn:");
459 pp
= unpack_varlen_hex (p
, &ul
);
461 error (_("invalid qRelocInsn packet: %s"), buf
);
465 unpack_varlen_hex (p
, &ul
);
470 TRY_CATCH (ex
, RETURN_MASK_ALL
)
472 gdbarch_relocate_instruction (target_gdbarch
, &to
, from
);
476 adjusted_size
= to
- org_to
;
478 sprintf (buf
, "qRelocInsn:%x", adjusted_size
);
481 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
483 /* Propagate memory errors silently back to the target.
484 The stub may have limited the range of addresses we
485 can write to, for example. */
490 /* Something unexpectedly bad happened. Be verbose so
491 we can tell what, and propagate the error back to the
492 stub, so it doesn't get stuck waiting for a
494 exception_fprintf (gdb_stderr
, ex
,
495 _("warning: relocating instruction: "));
499 else if (buf
[0] == 'O' && buf
[1] != 'K')
500 remote_console_output (buf
+ 1); /* 'O' message from stub */
502 return buf
; /* Here's the actual reply. */
507 /* Handle for retreving the remote protocol data from gdbarch. */
508 static struct gdbarch_data
*remote_gdbarch_data_handle
;
510 static struct remote_arch_state
*
511 get_remote_arch_state (void)
513 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
516 /* Fetch the global remote target state. */
518 static struct remote_state
*
519 get_remote_state (void)
521 /* Make sure that the remote architecture state has been
522 initialized, because doing so might reallocate rs->buf. Any
523 function which calls getpkt also needs to be mindful of changes
524 to rs->buf, but this call limits the number of places which run
526 get_remote_arch_state ();
528 return get_remote_state_raw ();
532 compare_pnums (const void *lhs_
, const void *rhs_
)
534 const struct packet_reg
* const *lhs
= lhs_
;
535 const struct packet_reg
* const *rhs
= rhs_
;
537 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
539 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
546 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
548 int regnum
, num_remote_regs
, offset
;
549 struct packet_reg
**remote_regs
;
551 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
553 struct packet_reg
*r
= ®s
[regnum
];
555 if (register_size (gdbarch
, regnum
) == 0)
556 /* Do not try to fetch zero-sized (placeholder) registers. */
559 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
564 /* Define the g/G packet format as the contents of each register
565 with a remote protocol number, in order of ascending protocol
568 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
569 * sizeof (struct packet_reg
*));
570 for (num_remote_regs
= 0, regnum
= 0;
571 regnum
< gdbarch_num_regs (gdbarch
);
573 if (regs
[regnum
].pnum
!= -1)
574 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
576 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
579 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
581 remote_regs
[regnum
]->in_g_packet
= 1;
582 remote_regs
[regnum
]->offset
= offset
;
583 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
589 /* Given the architecture described by GDBARCH, return the remote
590 protocol register's number and the register's offset in the g/G
591 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
592 If the target does not have a mapping for REGNUM, return false,
593 otherwise, return true. */
596 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
597 int *pnum
, int *poffset
)
600 struct packet_reg
*regs
;
601 struct cleanup
*old_chain
;
603 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
605 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
606 old_chain
= make_cleanup (xfree
, regs
);
608 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
610 *pnum
= regs
[regnum
].pnum
;
611 *poffset
= regs
[regnum
].offset
;
613 do_cleanups (old_chain
);
619 init_remote_state (struct gdbarch
*gdbarch
)
621 struct remote_state
*rs
= get_remote_state_raw ();
622 struct remote_arch_state
*rsa
;
624 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
626 /* Use the architecture to build a regnum<->pnum table, which will be
627 1:1 unless a feature set specifies otherwise. */
628 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
629 gdbarch_num_regs (gdbarch
),
632 /* Record the maximum possible size of the g packet - it may turn out
634 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
636 /* Default maximum number of characters in a packet body. Many
637 remote stubs have a hardwired buffer size of 400 bytes
638 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
639 as the maximum packet-size to ensure that the packet and an extra
640 NUL character can always fit in the buffer. This stops GDB
641 trashing stubs that try to squeeze an extra NUL into what is
642 already a full buffer (As of 1999-12-04 that was most stubs). */
643 rsa
->remote_packet_size
= 400 - 1;
645 /* This one is filled in when a ``g'' packet is received. */
646 rsa
->actual_register_packet_size
= 0;
648 /* Should rsa->sizeof_g_packet needs more space than the
649 default, adjust the size accordingly. Remember that each byte is
650 encoded as two characters. 32 is the overhead for the packet
651 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
652 (``$NN:G...#NN'') is a better guess, the below has been padded a
654 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
655 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
657 /* Make sure that the packet buffer is plenty big enough for
658 this architecture. */
659 if (rs
->buf_size
< rsa
->remote_packet_size
)
661 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
662 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
668 /* Return the current allowed size of a remote packet. This is
669 inferred from the current architecture, and should be used to
670 limit the length of outgoing packets. */
672 get_remote_packet_size (void)
674 struct remote_state
*rs
= get_remote_state ();
675 struct remote_arch_state
*rsa
= get_remote_arch_state ();
677 if (rs
->explicit_packet_size
)
678 return rs
->explicit_packet_size
;
680 return rsa
->remote_packet_size
;
683 static struct packet_reg
*
684 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
686 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
690 struct packet_reg
*r
= &rsa
->regs
[regnum
];
692 gdb_assert (r
->regnum
== regnum
);
697 static struct packet_reg
*
698 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
702 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
704 struct packet_reg
*r
= &rsa
->regs
[i
];
712 /* FIXME: graces/2002-08-08: These variables should eventually be
713 bound to an instance of the target object (as in gdbarch-tdep()),
714 when such a thing exists. */
716 /* This is set to the data address of the access causing the target
717 to stop for a watchpoint. */
718 static CORE_ADDR remote_watch_data_address
;
720 /* This is non-zero if target stopped for a watchpoint. */
721 static int remote_stopped_by_watchpoint_p
;
723 static struct target_ops remote_ops
;
725 static struct target_ops extended_remote_ops
;
727 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
728 ``forever'' still use the normal timeout mechanism. This is
729 currently used by the ASYNC code to guarentee that target reads
730 during the initial connect always time-out. Once getpkt has been
731 modified to return a timeout indication and, in turn
732 remote_wait()/wait_for_inferior() have gained a timeout parameter
734 static int wait_forever_enabled_p
= 1;
736 /* Allow the user to specify what sequence to send to the remote
737 when he requests a program interruption: Although ^C is usually
738 what remote systems expect (this is the default, here), it is
739 sometimes preferable to send a break. On other systems such
740 as the Linux kernel, a break followed by g, which is Magic SysRq g
741 is required in order to interrupt the execution. */
742 const char interrupt_sequence_control_c
[] = "Ctrl-C";
743 const char interrupt_sequence_break
[] = "BREAK";
744 const char interrupt_sequence_break_g
[] = "BREAK-g";
745 static const char *const interrupt_sequence_modes
[] =
747 interrupt_sequence_control_c
,
748 interrupt_sequence_break
,
749 interrupt_sequence_break_g
,
752 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
755 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
756 struct cmd_list_element
*c
,
759 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
760 fprintf_filtered (file
,
761 _("Send the ASCII ETX character (Ctrl-c) "
762 "to the remote target to interrupt the "
763 "execution of the program.\n"));
764 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
765 fprintf_filtered (file
,
766 _("send a break signal to the remote target "
767 "to interrupt the execution of the program.\n"));
768 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
769 fprintf_filtered (file
,
770 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
771 "the remote target to interrupt the execution "
772 "of Linux kernel.\n"));
774 internal_error (__FILE__
, __LINE__
,
775 _("Invalid value for interrupt_sequence_mode: %s."),
776 interrupt_sequence_mode
);
779 /* This boolean variable specifies whether interrupt_sequence is sent
780 to the remote target when gdb connects to it.
781 This is mostly needed when you debug the Linux kernel: The Linux kernel
782 expects BREAK g which is Magic SysRq g for connecting gdb. */
783 static int interrupt_on_connect
= 0;
785 /* This variable is used to implement the "set/show remotebreak" commands.
786 Since these commands are now deprecated in favor of "set/show remote
787 interrupt-sequence", it no longer has any effect on the code. */
788 static int remote_break
;
791 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
794 interrupt_sequence_mode
= interrupt_sequence_break
;
796 interrupt_sequence_mode
= interrupt_sequence_control_c
;
800 show_remotebreak (struct ui_file
*file
, int from_tty
,
801 struct cmd_list_element
*c
,
806 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
807 remote_open knows that we don't have a file open when the program
809 static struct serial
*remote_desc
= NULL
;
811 /* This variable sets the number of bits in an address that are to be
812 sent in a memory ("M" or "m") packet. Normally, after stripping
813 leading zeros, the entire address would be sent. This variable
814 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
815 initial implementation of remote.c restricted the address sent in
816 memory packets to ``host::sizeof long'' bytes - (typically 32
817 bits). Consequently, for 64 bit targets, the upper 32 bits of an
818 address was never sent. Since fixing this bug may cause a break in
819 some remote targets this variable is principly provided to
820 facilitate backward compatibility. */
822 static int remote_address_size
;
824 /* Temporary to track who currently owns the terminal. See
825 remote_terminal_* for more details. */
827 static int remote_async_terminal_ours_p
;
829 /* The executable file to use for "run" on the remote side. */
831 static char *remote_exec_file
= "";
834 /* User configurable variables for the number of characters in a
835 memory read/write packet. MIN (rsa->remote_packet_size,
836 rsa->sizeof_g_packet) is the default. Some targets need smaller
837 values (fifo overruns, et.al.) and some users need larger values
838 (speed up transfers). The variables ``preferred_*'' (the user
839 request), ``current_*'' (what was actually set) and ``forced_*''
840 (Positive - a soft limit, negative - a hard limit). */
842 struct memory_packet_config
849 /* Compute the current size of a read/write packet. Since this makes
850 use of ``actual_register_packet_size'' the computation is dynamic. */
853 get_memory_packet_size (struct memory_packet_config
*config
)
855 struct remote_state
*rs
= get_remote_state ();
856 struct remote_arch_state
*rsa
= get_remote_arch_state ();
858 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
859 law?) that some hosts don't cope very well with large alloca()
860 calls. Eventually the alloca() code will be replaced by calls to
861 xmalloc() and make_cleanups() allowing this restriction to either
862 be lifted or removed. */
863 #ifndef MAX_REMOTE_PACKET_SIZE
864 #define MAX_REMOTE_PACKET_SIZE 16384
866 /* NOTE: 20 ensures we can write at least one byte. */
867 #ifndef MIN_REMOTE_PACKET_SIZE
868 #define MIN_REMOTE_PACKET_SIZE 20
873 if (config
->size
<= 0)
874 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
876 what_they_get
= config
->size
;
880 what_they_get
= get_remote_packet_size ();
881 /* Limit the packet to the size specified by the user. */
883 && what_they_get
> config
->size
)
884 what_they_get
= config
->size
;
886 /* Limit it to the size of the targets ``g'' response unless we have
887 permission from the stub to use a larger packet size. */
888 if (rs
->explicit_packet_size
== 0
889 && rsa
->actual_register_packet_size
> 0
890 && what_they_get
> rsa
->actual_register_packet_size
)
891 what_they_get
= rsa
->actual_register_packet_size
;
893 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
894 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
895 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
896 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
898 /* Make sure there is room in the global buffer for this packet
899 (including its trailing NUL byte). */
900 if (rs
->buf_size
< what_they_get
+ 1)
902 rs
->buf_size
= 2 * what_they_get
;
903 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
906 return what_they_get
;
909 /* Update the size of a read/write packet. If they user wants
910 something really big then do a sanity check. */
913 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
915 int fixed_p
= config
->fixed_p
;
916 long size
= config
->size
;
919 error (_("Argument required (integer, `fixed' or `limited')."));
920 else if (strcmp (args
, "hard") == 0
921 || strcmp (args
, "fixed") == 0)
923 else if (strcmp (args
, "soft") == 0
924 || strcmp (args
, "limit") == 0)
930 size
= strtoul (args
, &end
, 0);
932 error (_("Invalid %s (bad syntax)."), config
->name
);
934 /* Instead of explicitly capping the size of a packet to
935 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
936 instead allowed to set the size to something arbitrarily
938 if (size
> MAX_REMOTE_PACKET_SIZE
)
939 error (_("Invalid %s (too large)."), config
->name
);
943 if (fixed_p
&& !config
->fixed_p
)
945 if (! query (_("The target may not be able to correctly handle a %s\n"
946 "of %ld bytes. Change the packet size? "),
948 error (_("Packet size not changed."));
950 /* Update the config. */
951 config
->fixed_p
= fixed_p
;
956 show_memory_packet_size (struct memory_packet_config
*config
)
958 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
960 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
961 get_memory_packet_size (config
));
963 printf_filtered (_("Packets are limited to %ld bytes.\n"),
964 get_memory_packet_size (config
));
967 static struct memory_packet_config memory_write_packet_config
=
969 "memory-write-packet-size",
973 set_memory_write_packet_size (char *args
, int from_tty
)
975 set_memory_packet_size (args
, &memory_write_packet_config
);
979 show_memory_write_packet_size (char *args
, int from_tty
)
981 show_memory_packet_size (&memory_write_packet_config
);
985 get_memory_write_packet_size (void)
987 return get_memory_packet_size (&memory_write_packet_config
);
990 static struct memory_packet_config memory_read_packet_config
=
992 "memory-read-packet-size",
996 set_memory_read_packet_size (char *args
, int from_tty
)
998 set_memory_packet_size (args
, &memory_read_packet_config
);
1002 show_memory_read_packet_size (char *args
, int from_tty
)
1004 show_memory_packet_size (&memory_read_packet_config
);
1008 get_memory_read_packet_size (void)
1010 long size
= get_memory_packet_size (&memory_read_packet_config
);
1012 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1013 extra buffer size argument before the memory read size can be
1014 increased beyond this. */
1015 if (size
> get_remote_packet_size ())
1016 size
= get_remote_packet_size ();
1021 /* Generic configuration support for packets the stub optionally
1022 supports. Allows the user to specify the use of the packet as well
1023 as allowing GDB to auto-detect support in the remote stub. */
1027 PACKET_SUPPORT_UNKNOWN
= 0,
1032 struct packet_config
1036 enum auto_boolean detect
;
1037 enum packet_support support
;
1040 /* Analyze a packet's return value and update the packet config
1051 update_packet_config (struct packet_config
*config
)
1053 switch (config
->detect
)
1055 case AUTO_BOOLEAN_TRUE
:
1056 config
->support
= PACKET_ENABLE
;
1058 case AUTO_BOOLEAN_FALSE
:
1059 config
->support
= PACKET_DISABLE
;
1061 case AUTO_BOOLEAN_AUTO
:
1062 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1068 show_packet_config_cmd (struct packet_config
*config
)
1070 char *support
= "internal-error";
1072 switch (config
->support
)
1075 support
= "enabled";
1077 case PACKET_DISABLE
:
1078 support
= "disabled";
1080 case PACKET_SUPPORT_UNKNOWN
:
1081 support
= "unknown";
1084 switch (config
->detect
)
1086 case AUTO_BOOLEAN_AUTO
:
1087 printf_filtered (_("Support for the `%s' packet "
1088 "is auto-detected, currently %s.\n"),
1089 config
->name
, support
);
1091 case AUTO_BOOLEAN_TRUE
:
1092 case AUTO_BOOLEAN_FALSE
:
1093 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1094 config
->name
, support
);
1100 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1101 const char *title
, int legacy
)
1107 config
->name
= name
;
1108 config
->title
= title
;
1109 config
->detect
= AUTO_BOOLEAN_AUTO
;
1110 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1111 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1113 show_doc
= xstrprintf ("Show current use of remote "
1114 "protocol `%s' (%s) packet",
1116 /* set/show TITLE-packet {auto,on,off} */
1117 cmd_name
= xstrprintf ("%s-packet", title
);
1118 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1119 &config
->detect
, set_doc
,
1120 show_doc
, NULL
, /* help_doc */
1121 set_remote_protocol_packet_cmd
,
1122 show_remote_protocol_packet_cmd
,
1123 &remote_set_cmdlist
, &remote_show_cmdlist
);
1124 /* The command code copies the documentation strings. */
1127 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1132 legacy_name
= xstrprintf ("%s-packet", name
);
1133 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1134 &remote_set_cmdlist
);
1135 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1136 &remote_show_cmdlist
);
1140 static enum packet_result
1141 packet_check_result (const char *buf
)
1145 /* The stub recognized the packet request. Check that the
1146 operation succeeded. */
1148 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1150 /* "Enn" - definitly an error. */
1151 return PACKET_ERROR
;
1153 /* Always treat "E." as an error. This will be used for
1154 more verbose error messages, such as E.memtypes. */
1155 if (buf
[0] == 'E' && buf
[1] == '.')
1156 return PACKET_ERROR
;
1158 /* The packet may or may not be OK. Just assume it is. */
1162 /* The stub does not support the packet. */
1163 return PACKET_UNKNOWN
;
1166 static enum packet_result
1167 packet_ok (const char *buf
, struct packet_config
*config
)
1169 enum packet_result result
;
1171 result
= packet_check_result (buf
);
1176 /* The stub recognized the packet request. */
1177 switch (config
->support
)
1179 case PACKET_SUPPORT_UNKNOWN
:
1181 fprintf_unfiltered (gdb_stdlog
,
1182 "Packet %s (%s) is supported\n",
1183 config
->name
, config
->title
);
1184 config
->support
= PACKET_ENABLE
;
1186 case PACKET_DISABLE
:
1187 internal_error (__FILE__
, __LINE__
,
1188 _("packet_ok: attempt to use a disabled packet"));
1194 case PACKET_UNKNOWN
:
1195 /* The stub does not support the packet. */
1196 switch (config
->support
)
1199 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1200 /* If the stub previously indicated that the packet was
1201 supported then there is a protocol error.. */
1202 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1203 config
->name
, config
->title
);
1205 /* The user set it wrong. */
1206 error (_("Enabled packet %s (%s) not recognized by stub"),
1207 config
->name
, config
->title
);
1209 case PACKET_SUPPORT_UNKNOWN
:
1211 fprintf_unfiltered (gdb_stdlog
,
1212 "Packet %s (%s) is NOT supported\n",
1213 config
->name
, config
->title
);
1214 config
->support
= PACKET_DISABLE
;
1216 case PACKET_DISABLE
:
1238 PACKET_vFile_pwrite
,
1240 PACKET_vFile_unlink
,
1241 PACKET_vFile_readlink
,
1243 PACKET_qXfer_features
,
1244 PACKET_qXfer_libraries
,
1245 PACKET_qXfer_libraries_svr4
,
1246 PACKET_qXfer_memory_map
,
1247 PACKET_qXfer_spu_read
,
1248 PACKET_qXfer_spu_write
,
1249 PACKET_qXfer_osdata
,
1250 PACKET_qXfer_threads
,
1251 PACKET_qXfer_statictrace_read
,
1252 PACKET_qXfer_traceframe_info
,
1256 PACKET_QPassSignals
,
1257 PACKET_qSearch_memory
,
1260 PACKET_QStartNoAckMode
,
1262 PACKET_qXfer_siginfo_read
,
1263 PACKET_qXfer_siginfo_write
,
1265 PACKET_ConditionalTracepoints
,
1266 PACKET_FastTracepoints
,
1267 PACKET_StaticTracepoints
,
1268 PACKET_InstallInTrace
,
1271 PACKET_TracepointSource
,
1274 PACKET_QDisableRandomization
,
1278 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1281 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1282 struct cmd_list_element
*c
)
1284 struct packet_config
*packet
;
1286 for (packet
= remote_protocol_packets
;
1287 packet
< &remote_protocol_packets
[PACKET_MAX
];
1290 if (&packet
->detect
== c
->var
)
1292 update_packet_config (packet
);
1296 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1301 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1302 struct cmd_list_element
*c
,
1305 struct packet_config
*packet
;
1307 for (packet
= remote_protocol_packets
;
1308 packet
< &remote_protocol_packets
[PACKET_MAX
];
1311 if (&packet
->detect
== c
->var
)
1313 show_packet_config_cmd (packet
);
1317 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1321 /* Should we try one of the 'Z' requests? */
1325 Z_PACKET_SOFTWARE_BP
,
1326 Z_PACKET_HARDWARE_BP
,
1333 /* For compatibility with older distributions. Provide a ``set remote
1334 Z-packet ...'' command that updates all the Z packet types. */
1336 static enum auto_boolean remote_Z_packet_detect
;
1339 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1340 struct cmd_list_element
*c
)
1344 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1346 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1347 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1352 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1353 struct cmd_list_element
*c
,
1358 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1360 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1364 /* Should we try the 'ThreadInfo' query packet?
1366 This variable (NOT available to the user: auto-detect only!)
1367 determines whether GDB will use the new, simpler "ThreadInfo"
1368 query or the older, more complex syntax for thread queries.
1369 This is an auto-detect variable (set to true at each connect,
1370 and set to false when the target fails to recognize it). */
1372 static int use_threadinfo_query
;
1373 static int use_threadextra_query
;
1375 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1376 static struct async_signal_handler
*sigint_remote_twice_token
;
1377 static struct async_signal_handler
*sigint_remote_token
;
1380 /* Asynchronous signal handle registered as event loop source for
1381 when we have pending events ready to be passed to the core. */
1383 static struct async_event_handler
*remote_async_inferior_event_token
;
1385 /* Asynchronous signal handle registered as event loop source for when
1386 the remote sent us a %Stop notification. The registered callback
1387 will do a vStopped sequence to pull the rest of the events out of
1388 the remote side into our event queue. */
1390 static struct async_event_handler
*remote_async_get_pending_events_token
;
1393 static ptid_t magic_null_ptid
;
1394 static ptid_t not_sent_ptid
;
1395 static ptid_t any_thread_ptid
;
1397 /* These are the threads which we last sent to the remote system. The
1398 TID member will be -1 for all or -2 for not sent yet. */
1400 static ptid_t general_thread
;
1401 static ptid_t continue_thread
;
1403 /* This the traceframe which we last selected on the remote system.
1404 It will be -1 if no traceframe is selected. */
1405 static int remote_traceframe_number
= -1;
1407 /* Find out if the stub attached to PID (and hence GDB should offer to
1408 detach instead of killing it when bailing out). */
1411 remote_query_attached (int pid
)
1413 struct remote_state
*rs
= get_remote_state ();
1415 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1418 if (remote_multi_process_p (rs
))
1419 sprintf (rs
->buf
, "qAttached:%x", pid
);
1421 sprintf (rs
->buf
, "qAttached");
1424 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1426 switch (packet_ok (rs
->buf
,
1427 &remote_protocol_packets
[PACKET_qAttached
]))
1430 if (strcmp (rs
->buf
, "1") == 0)
1434 warning (_("Remote failure reply: %s"), rs
->buf
);
1436 case PACKET_UNKNOWN
:
1443 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1444 has been invented by GDB, instead of reported by the target. Since
1445 we can be connected to a remote system before before knowing about
1446 any inferior, mark the target with execution when we find the first
1447 inferior. If ATTACHED is 1, then we had just attached to this
1448 inferior. If it is 0, then we just created this inferior. If it
1449 is -1, then try querying the remote stub to find out if it had
1450 attached to the inferior or not. */
1452 static struct inferior
*
1453 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1455 struct inferior
*inf
;
1457 /* Check whether this process we're learning about is to be
1458 considered attached, or if is to be considered to have been
1459 spawned by the stub. */
1461 attached
= remote_query_attached (pid
);
1463 if (gdbarch_has_global_solist (target_gdbarch
))
1465 /* If the target shares code across all inferiors, then every
1466 attach adds a new inferior. */
1467 inf
= add_inferior (pid
);
1469 /* ... and every inferior is bound to the same program space.
1470 However, each inferior may still have its own address
1472 inf
->aspace
= maybe_new_address_space ();
1473 inf
->pspace
= current_program_space
;
1477 /* In the traditional debugging scenario, there's a 1-1 match
1478 between program/address spaces. We simply bind the inferior
1479 to the program space's address space. */
1480 inf
= current_inferior ();
1481 inferior_appeared (inf
, pid
);
1484 inf
->attach_flag
= attached
;
1485 inf
->fake_pid_p
= fake_pid_p
;
1490 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1491 according to RUNNING. */
1494 remote_add_thread (ptid_t ptid
, int running
)
1498 set_executing (ptid
, running
);
1499 set_running (ptid
, running
);
1502 /* Come here when we learn about a thread id from the remote target.
1503 It may be the first time we hear about such thread, so take the
1504 opportunity to add it to GDB's thread list. In case this is the
1505 first time we're noticing its corresponding inferior, add it to
1506 GDB's inferior list as well. */
1509 remote_notice_new_inferior (ptid_t currthread
, int running
)
1511 /* If this is a new thread, add it to GDB's thread list.
1512 If we leave it up to WFI to do this, bad things will happen. */
1514 if (in_thread_list (currthread
) && is_exited (currthread
))
1516 /* We're seeing an event on a thread id we knew had exited.
1517 This has to be a new thread reusing the old id. Add it. */
1518 remote_add_thread (currthread
, running
);
1522 if (!in_thread_list (currthread
))
1524 struct inferior
*inf
= NULL
;
1525 int pid
= ptid_get_pid (currthread
);
1527 if (ptid_is_pid (inferior_ptid
)
1528 && pid
== ptid_get_pid (inferior_ptid
))
1530 /* inferior_ptid has no thread member yet. This can happen
1531 with the vAttach -> remote_wait,"TAAthread:" path if the
1532 stub doesn't support qC. This is the first stop reported
1533 after an attach, so this is the main thread. Update the
1534 ptid in the thread list. */
1535 if (in_thread_list (pid_to_ptid (pid
)))
1536 thread_change_ptid (inferior_ptid
, currthread
);
1539 remote_add_thread (currthread
, running
);
1540 inferior_ptid
= currthread
;
1545 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1547 /* inferior_ptid is not set yet. This can happen with the
1548 vRun -> remote_wait,"TAAthread:" path if the stub
1549 doesn't support qC. This is the first stop reported
1550 after an attach, so this is the main thread. Update the
1551 ptid in the thread list. */
1552 thread_change_ptid (inferior_ptid
, currthread
);
1556 /* When connecting to a target remote, or to a target
1557 extended-remote which already was debugging an inferior, we
1558 may not know about it yet. Add it before adding its child
1559 thread, so notifications are emitted in a sensible order. */
1560 if (!in_inferior_list (ptid_get_pid (currthread
)))
1562 struct remote_state
*rs
= get_remote_state ();
1563 int fake_pid_p
= !remote_multi_process_p (rs
);
1565 inf
= remote_add_inferior (fake_pid_p
,
1566 ptid_get_pid (currthread
), -1);
1569 /* This is really a new thread. Add it. */
1570 remote_add_thread (currthread
, running
);
1572 /* If we found a new inferior, let the common code do whatever
1573 it needs to with it (e.g., read shared libraries, insert
1576 notice_new_inferior (currthread
, running
, 0);
1580 /* Return the private thread data, creating it if necessary. */
1582 struct private_thread_info
*
1583 demand_private_info (ptid_t ptid
)
1585 struct thread_info
*info
= find_thread_ptid (ptid
);
1591 info
->private = xmalloc (sizeof (*(info
->private)));
1592 info
->private_dtor
= free_private_thread_info
;
1593 info
->private->core
= -1;
1594 info
->private->extra
= 0;
1597 return info
->private;
1600 /* Call this function as a result of
1601 1) A halt indication (T packet) containing a thread id
1602 2) A direct query of currthread
1603 3) Successful execution of set thread */
1606 record_currthread (ptid_t currthread
)
1608 general_thread
= currthread
;
1611 static char *last_pass_packet
;
1613 /* If 'QPassSignals' is supported, tell the remote stub what signals
1614 it can simply pass through to the inferior without reporting. */
1617 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1619 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1621 char *pass_packet
, *p
;
1624 gdb_assert (numsigs
< 256);
1625 for (i
= 0; i
< numsigs
; i
++)
1627 if (pass_signals
[i
])
1630 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1631 strcpy (pass_packet
, "QPassSignals:");
1632 p
= pass_packet
+ strlen (pass_packet
);
1633 for (i
= 0; i
< numsigs
; i
++)
1635 if (pass_signals
[i
])
1638 *p
++ = tohex (i
>> 4);
1639 *p
++ = tohex (i
& 15);
1648 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1650 struct remote_state
*rs
= get_remote_state ();
1651 char *buf
= rs
->buf
;
1653 putpkt (pass_packet
);
1654 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1655 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1656 if (last_pass_packet
)
1657 xfree (last_pass_packet
);
1658 last_pass_packet
= pass_packet
;
1661 xfree (pass_packet
);
1665 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1666 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1667 thread. If GEN is set, set the general thread, if not, then set
1668 the step/continue thread. */
1670 set_thread (struct ptid ptid
, int gen
)
1672 struct remote_state
*rs
= get_remote_state ();
1673 ptid_t state
= gen
? general_thread
: continue_thread
;
1674 char *buf
= rs
->buf
;
1675 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1677 if (ptid_equal (state
, ptid
))
1681 *buf
++ = gen
? 'g' : 'c';
1682 if (ptid_equal (ptid
, magic_null_ptid
))
1683 xsnprintf (buf
, endbuf
- buf
, "0");
1684 else if (ptid_equal (ptid
, any_thread_ptid
))
1685 xsnprintf (buf
, endbuf
- buf
, "0");
1686 else if (ptid_equal (ptid
, minus_one_ptid
))
1687 xsnprintf (buf
, endbuf
- buf
, "-1");
1689 write_ptid (buf
, endbuf
, ptid
);
1691 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1693 general_thread
= ptid
;
1695 continue_thread
= ptid
;
1699 set_general_thread (struct ptid ptid
)
1701 set_thread (ptid
, 1);
1705 set_continue_thread (struct ptid ptid
)
1707 set_thread (ptid
, 0);
1710 /* Change the remote current process. Which thread within the process
1711 ends up selected isn't important, as long as it is the same process
1712 as what INFERIOR_PTID points to.
1714 This comes from that fact that there is no explicit notion of
1715 "selected process" in the protocol. The selected process for
1716 general operations is the process the selected general thread
1720 set_general_process (void)
1722 struct remote_state
*rs
= get_remote_state ();
1724 /* If the remote can't handle multiple processes, don't bother. */
1725 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1728 /* We only need to change the remote current thread if it's pointing
1729 at some other process. */
1730 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1731 set_general_thread (inferior_ptid
);
1735 /* Return nonzero if the thread PTID is still alive on the remote
1739 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1741 struct remote_state
*rs
= get_remote_state ();
1744 if (ptid_equal (ptid
, magic_null_ptid
))
1745 /* The main thread is always alive. */
1748 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1749 /* The main thread is always alive. This can happen after a
1750 vAttach, if the remote side doesn't support
1755 endp
= rs
->buf
+ get_remote_packet_size ();
1758 write_ptid (p
, endp
, ptid
);
1761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1762 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1765 /* About these extended threadlist and threadinfo packets. They are
1766 variable length packets but, the fields within them are often fixed
1767 length. They are redundent enough to send over UDP as is the
1768 remote protocol in general. There is a matching unit test module
1771 #define OPAQUETHREADBYTES 8
1773 /* a 64 bit opaque identifier */
1774 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1776 /* WARNING: This threadref data structure comes from the remote O.S.,
1777 libstub protocol encoding, and remote.c. It is not particularly
1780 /* Right now, the internal structure is int. We want it to be bigger.
1781 Plan to fix this. */
1783 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1785 /* gdb_ext_thread_info is an internal GDB data structure which is
1786 equivalent to the reply of the remote threadinfo packet. */
1788 struct gdb_ext_thread_info
1790 threadref threadid
; /* External form of thread reference. */
1791 int active
; /* Has state interesting to GDB?
1793 char display
[256]; /* Brief state display, name,
1794 blocked/suspended. */
1795 char shortname
[32]; /* To be used to name threads. */
1796 char more_display
[256]; /* Long info, statistics, queue depth,
1800 /* The volume of remote transfers can be limited by submitting
1801 a mask containing bits specifying the desired information.
1802 Use a union of these values as the 'selection' parameter to
1803 get_thread_info. FIXME: Make these TAG names more thread specific. */
1805 #define TAG_THREADID 1
1806 #define TAG_EXISTS 2
1807 #define TAG_DISPLAY 4
1808 #define TAG_THREADNAME 8
1809 #define TAG_MOREDISPLAY 16
1811 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1813 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1815 static char *unpack_nibble (char *buf
, int *val
);
1817 static char *pack_nibble (char *buf
, int nibble
);
1819 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1821 static char *unpack_byte (char *buf
, int *value
);
1823 static char *pack_int (char *buf
, int value
);
1825 static char *unpack_int (char *buf
, int *value
);
1827 static char *unpack_string (char *src
, char *dest
, int length
);
1829 static char *pack_threadid (char *pkt
, threadref
*id
);
1831 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1833 void int_to_threadref (threadref
*id
, int value
);
1835 static int threadref_to_int (threadref
*ref
);
1837 static void copy_threadref (threadref
*dest
, threadref
*src
);
1839 static int threadmatch (threadref
*dest
, threadref
*src
);
1841 static char *pack_threadinfo_request (char *pkt
, int mode
,
1844 static int remote_unpack_thread_info_response (char *pkt
,
1845 threadref
*expectedref
,
1846 struct gdb_ext_thread_info
1850 static int remote_get_threadinfo (threadref
*threadid
,
1851 int fieldset
, /*TAG mask */
1852 struct gdb_ext_thread_info
*info
);
1854 static char *pack_threadlist_request (char *pkt
, int startflag
,
1856 threadref
*nextthread
);
1858 static int parse_threadlist_response (char *pkt
,
1860 threadref
*original_echo
,
1861 threadref
*resultlist
,
1864 static int remote_get_threadlist (int startflag
,
1865 threadref
*nextthread
,
1869 threadref
*threadlist
);
1871 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1873 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1874 void *context
, int looplimit
);
1876 static int remote_newthread_step (threadref
*ref
, void *context
);
1879 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1880 buffer we're allowed to write to. Returns
1881 BUF+CHARACTERS_WRITTEN. */
1884 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1887 struct remote_state
*rs
= get_remote_state ();
1889 if (remote_multi_process_p (rs
))
1891 pid
= ptid_get_pid (ptid
);
1893 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1895 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1897 tid
= ptid_get_tid (ptid
);
1899 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1901 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1906 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1907 passed the last parsed char. Returns null_ptid on error. */
1910 read_ptid (char *buf
, char **obuf
)
1914 ULONGEST pid
= 0, tid
= 0;
1918 /* Multi-process ptid. */
1919 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1921 error (_("invalid remote ptid: %s"), p
);
1924 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1927 return ptid_build (pid
, 0, tid
);
1930 /* No multi-process. Just a tid. */
1931 pp
= unpack_varlen_hex (p
, &tid
);
1933 /* Since the stub is not sending a process id, then default to
1934 what's in inferior_ptid, unless it's null at this point. If so,
1935 then since there's no way to know the pid of the reported
1936 threads, use the magic number. */
1937 if (ptid_equal (inferior_ptid
, null_ptid
))
1938 pid
= ptid_get_pid (magic_null_ptid
);
1940 pid
= ptid_get_pid (inferior_ptid
);
1944 return ptid_build (pid
, 0, tid
);
1947 /* Encode 64 bits in 16 chars of hex. */
1949 static const char hexchars
[] = "0123456789abcdef";
1952 ishex (int ch
, int *val
)
1954 if ((ch
>= 'a') && (ch
<= 'f'))
1956 *val
= ch
- 'a' + 10;
1959 if ((ch
>= 'A') && (ch
<= 'F'))
1961 *val
= ch
- 'A' + 10;
1964 if ((ch
>= '0') && (ch
<= '9'))
1975 if (ch
>= 'a' && ch
<= 'f')
1976 return ch
- 'a' + 10;
1977 if (ch
>= '0' && ch
<= '9')
1979 if (ch
>= 'A' && ch
<= 'F')
1980 return ch
- 'A' + 10;
1985 stub_unpack_int (char *buff
, int fieldlength
)
1992 nibble
= stubhex (*buff
++);
1996 retval
= retval
<< 4;
2002 unpack_varlen_hex (char *buff
, /* packet to parse */
2006 ULONGEST retval
= 0;
2008 while (ishex (*buff
, &nibble
))
2011 retval
= retval
<< 4;
2012 retval
|= nibble
& 0x0f;
2019 unpack_nibble (char *buf
, int *val
)
2021 *val
= fromhex (*buf
++);
2026 pack_nibble (char *buf
, int nibble
)
2028 *buf
++ = hexchars
[(nibble
& 0x0f)];
2033 pack_hex_byte (char *pkt
, int byte
)
2035 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2036 *pkt
++ = hexchars
[(byte
& 0xf)];
2041 unpack_byte (char *buf
, int *value
)
2043 *value
= stub_unpack_int (buf
, 2);
2048 pack_int (char *buf
, int value
)
2050 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2051 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2052 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2053 buf
= pack_hex_byte (buf
, (value
& 0xff));
2058 unpack_int (char *buf
, int *value
)
2060 *value
= stub_unpack_int (buf
, 8);
2064 #if 0 /* Currently unused, uncomment when needed. */
2065 static char *pack_string (char *pkt
, char *string
);
2068 pack_string (char *pkt
, char *string
)
2073 len
= strlen (string
);
2075 len
= 200; /* Bigger than most GDB packets, junk??? */
2076 pkt
= pack_hex_byte (pkt
, len
);
2080 if ((ch
== '\0') || (ch
== '#'))
2081 ch
= '*'; /* Protect encapsulation. */
2086 #endif /* 0 (unused) */
2089 unpack_string (char *src
, char *dest
, int length
)
2098 pack_threadid (char *pkt
, threadref
*id
)
2101 unsigned char *altid
;
2103 altid
= (unsigned char *) id
;
2104 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2106 pkt
= pack_hex_byte (pkt
, *altid
++);
2112 unpack_threadid (char *inbuf
, threadref
*id
)
2115 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2118 altref
= (char *) id
;
2120 while (inbuf
< limit
)
2122 x
= stubhex (*inbuf
++);
2123 y
= stubhex (*inbuf
++);
2124 *altref
++ = (x
<< 4) | y
;
2129 /* Externally, threadrefs are 64 bits but internally, they are still
2130 ints. This is due to a mismatch of specifications. We would like
2131 to use 64bit thread references internally. This is an adapter
2135 int_to_threadref (threadref
*id
, int value
)
2137 unsigned char *scan
;
2139 scan
= (unsigned char *) id
;
2145 *scan
++ = (value
>> 24) & 0xff;
2146 *scan
++ = (value
>> 16) & 0xff;
2147 *scan
++ = (value
>> 8) & 0xff;
2148 *scan
++ = (value
& 0xff);
2152 threadref_to_int (threadref
*ref
)
2155 unsigned char *scan
;
2161 value
= (value
<< 8) | ((*scan
++) & 0xff);
2166 copy_threadref (threadref
*dest
, threadref
*src
)
2169 unsigned char *csrc
, *cdest
;
2171 csrc
= (unsigned char *) src
;
2172 cdest
= (unsigned char *) dest
;
2179 threadmatch (threadref
*dest
, threadref
*src
)
2181 /* Things are broken right now, so just assume we got a match. */
2183 unsigned char *srcp
, *destp
;
2185 srcp
= (char *) src
;
2186 destp
= (char *) dest
;
2190 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2197 threadid:1, # always request threadid
2204 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2207 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2209 *pkt
++ = 'q'; /* Info Query */
2210 *pkt
++ = 'P'; /* process or thread info */
2211 pkt
= pack_int (pkt
, mode
); /* mode */
2212 pkt
= pack_threadid (pkt
, id
); /* threadid */
2213 *pkt
= '\0'; /* terminate */
2217 /* These values tag the fields in a thread info response packet. */
2218 /* Tagging the fields allows us to request specific fields and to
2219 add more fields as time goes by. */
2221 #define TAG_THREADID 1 /* Echo the thread identifier. */
2222 #define TAG_EXISTS 2 /* Is this process defined enough to
2223 fetch registers and its stack? */
2224 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2225 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2226 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2230 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2231 struct gdb_ext_thread_info
*info
)
2233 struct remote_state
*rs
= get_remote_state ();
2237 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2240 /* info->threadid = 0; FIXME: implement zero_threadref. */
2242 info
->display
[0] = '\0';
2243 info
->shortname
[0] = '\0';
2244 info
->more_display
[0] = '\0';
2246 /* Assume the characters indicating the packet type have been
2248 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2249 pkt
= unpack_threadid (pkt
, &ref
);
2252 warning (_("Incomplete response to threadinfo request."));
2253 if (!threadmatch (&ref
, expectedref
))
2254 { /* This is an answer to a different request. */
2255 warning (_("ERROR RMT Thread info mismatch."));
2258 copy_threadref (&info
->threadid
, &ref
);
2260 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2262 /* Packets are terminated with nulls. */
2263 while ((pkt
< limit
) && mask
&& *pkt
)
2265 pkt
= unpack_int (pkt
, &tag
); /* tag */
2266 pkt
= unpack_byte (pkt
, &length
); /* length */
2267 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2269 warning (_("ERROR RMT: threadinfo tag mismatch."));
2273 if (tag
== TAG_THREADID
)
2277 warning (_("ERROR RMT: length of threadid is not 16."));
2281 pkt
= unpack_threadid (pkt
, &ref
);
2282 mask
= mask
& ~TAG_THREADID
;
2285 if (tag
== TAG_EXISTS
)
2287 info
->active
= stub_unpack_int (pkt
, length
);
2289 mask
= mask
& ~(TAG_EXISTS
);
2292 warning (_("ERROR RMT: 'exists' length too long."));
2298 if (tag
== TAG_THREADNAME
)
2300 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2301 mask
= mask
& ~TAG_THREADNAME
;
2304 if (tag
== TAG_DISPLAY
)
2306 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2307 mask
= mask
& ~TAG_DISPLAY
;
2310 if (tag
== TAG_MOREDISPLAY
)
2312 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2313 mask
= mask
& ~TAG_MOREDISPLAY
;
2316 warning (_("ERROR RMT: unknown thread info tag."));
2317 break; /* Not a tag we know about. */
2323 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2324 struct gdb_ext_thread_info
*info
)
2326 struct remote_state
*rs
= get_remote_state ();
2329 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2331 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2333 if (rs
->buf
[0] == '\0')
2336 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2341 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2344 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2345 threadref
*nextthread
)
2347 *pkt
++ = 'q'; /* info query packet */
2348 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2349 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2350 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2351 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2356 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2359 parse_threadlist_response (char *pkt
, int result_limit
,
2360 threadref
*original_echo
, threadref
*resultlist
,
2363 struct remote_state
*rs
= get_remote_state ();
2365 int count
, resultcount
, done
;
2368 /* Assume the 'q' and 'M chars have been stripped. */
2369 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2370 /* done parse past here */
2371 pkt
= unpack_byte (pkt
, &count
); /* count field */
2372 pkt
= unpack_nibble (pkt
, &done
);
2373 /* The first threadid is the argument threadid. */
2374 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2375 while ((count
-- > 0) && (pkt
< limit
))
2377 pkt
= unpack_threadid (pkt
, resultlist
++);
2378 if (resultcount
++ >= result_limit
)
2387 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2388 int *done
, int *result_count
, threadref
*threadlist
)
2390 struct remote_state
*rs
= get_remote_state ();
2391 static threadref echo_nextthread
;
2394 /* Trancate result limit to be smaller than the packet size. */
2395 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2396 >= get_remote_packet_size ())
2397 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2399 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2401 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2403 if (*rs
->buf
== '\0')
2407 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2410 if (!threadmatch (&echo_nextthread
, nextthread
))
2412 /* FIXME: This is a good reason to drop the packet. */
2413 /* Possably, there is a duplicate response. */
2415 retransmit immediatly - race conditions
2416 retransmit after timeout - yes
2418 wait for packet, then exit
2420 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2421 return 0; /* I choose simply exiting. */
2423 if (*result_count
<= 0)
2427 warning (_("RMT ERROR : failed to get remote thread list."));
2430 return result
; /* break; */
2432 if (*result_count
> result_limit
)
2435 warning (_("RMT ERROR: threadlist response longer than requested."));
2441 /* This is the interface between remote and threads, remotes upper
2444 /* remote_find_new_threads retrieves the thread list and for each
2445 thread in the list, looks up the thread in GDB's internal list,
2446 adding the thread if it does not already exist. This involves
2447 getting partial thread lists from the remote target so, polling the
2448 quit_flag is required. */
2451 /* About this many threadisds fit in a packet. */
2453 #define MAXTHREADLISTRESULTS 32
2456 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2459 int done
, i
, result_count
;
2463 static threadref nextthread
;
2464 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2469 if (loopcount
++ > looplimit
)
2472 warning (_("Remote fetch threadlist -infinite loop-."));
2475 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2476 &done
, &result_count
, resultthreadlist
))
2481 /* Clear for later iterations. */
2483 /* Setup to resume next batch of thread references, set nextthread. */
2484 if (result_count
>= 1)
2485 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2487 while (result_count
--)
2488 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2495 remote_newthread_step (threadref
*ref
, void *context
)
2497 int pid
= ptid_get_pid (inferior_ptid
);
2498 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2500 if (!in_thread_list (ptid
))
2502 return 1; /* continue iterator */
2505 #define CRAZY_MAX_THREADS 1000
2508 remote_current_thread (ptid_t oldpid
)
2510 struct remote_state
*rs
= get_remote_state ();
2513 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2514 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2515 return read_ptid (&rs
->buf
[2], NULL
);
2520 /* Find new threads for info threads command.
2521 * Original version, using John Metzler's thread protocol.
2525 remote_find_new_threads (void)
2527 remote_threadlist_iterator (remote_newthread_step
, 0,
2531 #if defined(HAVE_LIBEXPAT)
2533 typedef struct thread_item
2539 DEF_VEC_O(thread_item_t
);
2541 struct threads_parsing_context
2543 VEC (thread_item_t
) *items
;
2547 start_thread (struct gdb_xml_parser
*parser
,
2548 const struct gdb_xml_element
*element
,
2549 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2551 struct threads_parsing_context
*data
= user_data
;
2553 struct thread_item item
;
2555 struct gdb_xml_value
*attr
;
2557 id
= xml_find_attribute (attributes
, "id")->value
;
2558 item
.ptid
= read_ptid (id
, NULL
);
2560 attr
= xml_find_attribute (attributes
, "core");
2562 item
.core
= *(ULONGEST
*) attr
->value
;
2568 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2572 end_thread (struct gdb_xml_parser
*parser
,
2573 const struct gdb_xml_element
*element
,
2574 void *user_data
, const char *body_text
)
2576 struct threads_parsing_context
*data
= user_data
;
2578 if (body_text
&& *body_text
)
2579 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2582 const struct gdb_xml_attribute thread_attributes
[] = {
2583 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2584 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2585 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2588 const struct gdb_xml_element thread_children
[] = {
2589 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2592 const struct gdb_xml_element threads_children
[] = {
2593 { "thread", thread_attributes
, thread_children
,
2594 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2595 start_thread
, end_thread
},
2596 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2599 const struct gdb_xml_element threads_elements
[] = {
2600 { "threads", NULL
, threads_children
,
2601 GDB_XML_EF_NONE
, NULL
, NULL
},
2602 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2605 /* Discard the contents of the constructed thread info context. */
2608 clear_threads_parsing_context (void *p
)
2610 struct threads_parsing_context
*context
= p
;
2612 struct thread_item
*item
;
2614 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2615 xfree (item
->extra
);
2617 VEC_free (thread_item_t
, context
->items
);
2623 * Find all threads for info threads command.
2624 * Uses new thread protocol contributed by Cisco.
2625 * Falls back and attempts to use the older method (above)
2626 * if the target doesn't respond to the new method.
2630 remote_threads_info (struct target_ops
*ops
)
2632 struct remote_state
*rs
= get_remote_state ();
2636 if (remote_desc
== 0) /* paranoia */
2637 error (_("Command can only be used when connected to the remote target."));
2639 #if defined(HAVE_LIBEXPAT)
2640 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2642 char *xml
= target_read_stralloc (¤t_target
,
2643 TARGET_OBJECT_THREADS
, NULL
);
2645 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2649 struct threads_parsing_context context
;
2651 context
.items
= NULL
;
2652 make_cleanup (clear_threads_parsing_context
, &context
);
2654 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2655 threads_elements
, xml
, &context
) == 0)
2658 struct thread_item
*item
;
2661 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2664 if (!ptid_equal (item
->ptid
, null_ptid
))
2666 struct private_thread_info
*info
;
2667 /* In non-stop mode, we assume new found threads
2668 are running until proven otherwise with a
2669 stop reply. In all-stop, we can only get
2670 here if all threads are stopped. */
2671 int running
= non_stop
? 1 : 0;
2673 remote_notice_new_inferior (item
->ptid
, running
);
2675 info
= demand_private_info (item
->ptid
);
2676 info
->core
= item
->core
;
2677 info
->extra
= item
->extra
;
2684 do_cleanups (back_to
);
2689 if (use_threadinfo_query
)
2691 putpkt ("qfThreadInfo");
2692 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2694 if (bufp
[0] != '\0') /* q packet recognized */
2696 while (*bufp
++ == 'm') /* reply contains one or more TID */
2700 new_thread
= read_ptid (bufp
, &bufp
);
2701 if (!ptid_equal (new_thread
, null_ptid
))
2703 /* In non-stop mode, we assume new found threads
2704 are running until proven otherwise with a
2705 stop reply. In all-stop, we can only get
2706 here if all threads are stopped. */
2707 int running
= non_stop
? 1 : 0;
2709 remote_notice_new_inferior (new_thread
, running
);
2712 while (*bufp
++ == ','); /* comma-separated list */
2713 putpkt ("qsThreadInfo");
2714 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2721 /* Only qfThreadInfo is supported in non-stop mode. */
2725 /* Else fall back to old method based on jmetzler protocol. */
2726 use_threadinfo_query
= 0;
2727 remote_find_new_threads ();
2732 * Collect a descriptive string about the given thread.
2733 * The target may say anything it wants to about the thread
2734 * (typically info about its blocked / runnable state, name, etc.).
2735 * This string will appear in the info threads display.
2737 * Optional: targets are not required to implement this function.
2741 remote_threads_extra_info (struct thread_info
*tp
)
2743 struct remote_state
*rs
= get_remote_state ();
2747 struct gdb_ext_thread_info threadinfo
;
2748 static char display_buf
[100]; /* arbitrary... */
2749 int n
= 0; /* position in display_buf */
2751 if (remote_desc
== 0) /* paranoia */
2752 internal_error (__FILE__
, __LINE__
,
2753 _("remote_threads_extra_info"));
2755 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2756 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2757 /* This is the main thread which was added by GDB. The remote
2758 server doesn't know about it. */
2761 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2763 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2765 if (info
&& info
->private)
2766 return info
->private->extra
;
2771 if (use_threadextra_query
)
2774 char *endb
= rs
->buf
+ get_remote_packet_size ();
2776 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2778 write_ptid (b
, endb
, tp
->ptid
);
2781 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2782 if (rs
->buf
[0] != 0)
2784 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2785 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2786 display_buf
[result
] = '\0';
2791 /* If the above query fails, fall back to the old method. */
2792 use_threadextra_query
= 0;
2793 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2794 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2795 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2796 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2797 if (threadinfo
.active
)
2799 if (*threadinfo
.shortname
)
2800 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2801 " Name: %s,", threadinfo
.shortname
);
2802 if (*threadinfo
.display
)
2803 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2804 " State: %s,", threadinfo
.display
);
2805 if (*threadinfo
.more_display
)
2806 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2807 " Priority: %s", threadinfo
.more_display
);
2811 /* For purely cosmetic reasons, clear up trailing commas. */
2812 if (',' == display_buf
[n
-1])
2813 display_buf
[n
-1] = ' ';
2822 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2823 struct static_tracepoint_marker
*marker
)
2825 struct remote_state
*rs
= get_remote_state ();
2828 sprintf (p
, "qTSTMat:");
2830 p
+= hexnumstr (p
, addr
);
2832 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2836 error (_("Remote failure reply: %s"), p
);
2840 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2848 free_current_marker (void *arg
)
2850 struct static_tracepoint_marker
**marker_p
= arg
;
2852 if (*marker_p
!= NULL
)
2854 release_static_tracepoint_marker (*marker_p
);
2861 static VEC(static_tracepoint_marker_p
) *
2862 remote_static_tracepoint_markers_by_strid (const char *strid
)
2864 struct remote_state
*rs
= get_remote_state ();
2865 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2866 struct static_tracepoint_marker
*marker
= NULL
;
2867 struct cleanup
*old_chain
;
2870 /* Ask for a first packet of static tracepoint marker
2873 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2876 error (_("Remote failure reply: %s"), p
);
2878 old_chain
= make_cleanup (free_current_marker
, &marker
);
2883 marker
= XCNEW (struct static_tracepoint_marker
);
2887 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2889 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2891 VEC_safe_push (static_tracepoint_marker_p
,
2897 release_static_tracepoint_marker (marker
);
2898 memset (marker
, 0, sizeof (*marker
));
2901 while (*p
++ == ','); /* comma-separated list */
2902 /* Ask for another packet of static tracepoint definition. */
2904 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2908 do_cleanups (old_chain
);
2913 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2916 remote_get_ada_task_ptid (long lwp
, long thread
)
2918 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2922 /* Restart the remote side; this is an extended protocol operation. */
2925 extended_remote_restart (void)
2927 struct remote_state
*rs
= get_remote_state ();
2929 /* Send the restart command; for reasons I don't understand the
2930 remote side really expects a number after the "R". */
2931 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2934 remote_fileio_reset ();
2937 /* Clean up connection to a remote debugger. */
2940 remote_close (int quitting
)
2942 if (remote_desc
== NULL
)
2943 return; /* already closed */
2945 /* Make sure we leave stdin registered in the event loop, and we
2946 don't leave the async SIGINT signal handler installed. */
2947 remote_terminal_ours ();
2949 serial_close (remote_desc
);
2952 /* We don't have a connection to the remote stub anymore. Get rid
2953 of all the inferiors and their threads we were controlling.
2954 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
2955 will be unable to find the thread corresponding to (pid, 0, 0). */
2956 inferior_ptid
= null_ptid
;
2957 discard_all_inferiors ();
2959 /* We're no longer interested in any of these events. */
2960 discard_pending_stop_replies (-1);
2962 if (remote_async_inferior_event_token
)
2963 delete_async_event_handler (&remote_async_inferior_event_token
);
2964 if (remote_async_get_pending_events_token
)
2965 delete_async_event_handler (&remote_async_get_pending_events_token
);
2968 /* Query the remote side for the text, data and bss offsets. */
2973 struct remote_state
*rs
= get_remote_state ();
2976 int lose
, num_segments
= 0, do_sections
, do_segments
;
2977 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2978 struct section_offsets
*offs
;
2979 struct symfile_segment_data
*data
;
2981 if (symfile_objfile
== NULL
)
2984 putpkt ("qOffsets");
2985 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2988 if (buf
[0] == '\000')
2989 return; /* Return silently. Stub doesn't support
2993 warning (_("Remote failure reply: %s"), buf
);
2997 /* Pick up each field in turn. This used to be done with scanf, but
2998 scanf will make trouble if CORE_ADDR size doesn't match
2999 conversion directives correctly. The following code will work
3000 with any size of CORE_ADDR. */
3001 text_addr
= data_addr
= bss_addr
= 0;
3005 if (strncmp (ptr
, "Text=", 5) == 0)
3008 /* Don't use strtol, could lose on big values. */
3009 while (*ptr
&& *ptr
!= ';')
3010 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3012 if (strncmp (ptr
, ";Data=", 6) == 0)
3015 while (*ptr
&& *ptr
!= ';')
3016 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3021 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3024 while (*ptr
&& *ptr
!= ';')
3025 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3027 if (bss_addr
!= data_addr
)
3028 warning (_("Target reported unsupported offsets: %s"), buf
);
3033 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3036 /* Don't use strtol, could lose on big values. */
3037 while (*ptr
&& *ptr
!= ';')
3038 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3041 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3044 while (*ptr
&& *ptr
!= ';')
3045 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3053 error (_("Malformed response to offset query, %s"), buf
);
3054 else if (*ptr
!= '\0')
3055 warning (_("Target reported unsupported offsets: %s"), buf
);
3057 offs
= ((struct section_offsets
*)
3058 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3059 memcpy (offs
, symfile_objfile
->section_offsets
,
3060 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3062 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3063 do_segments
= (data
!= NULL
);
3064 do_sections
= num_segments
== 0;
3066 if (num_segments
> 0)
3068 segments
[0] = text_addr
;
3069 segments
[1] = data_addr
;
3071 /* If we have two segments, we can still try to relocate everything
3072 by assuming that the .text and .data offsets apply to the whole
3073 text and data segments. Convert the offsets given in the packet
3074 to base addresses for symfile_map_offsets_to_segments. */
3075 else if (data
&& data
->num_segments
== 2)
3077 segments
[0] = data
->segment_bases
[0] + text_addr
;
3078 segments
[1] = data
->segment_bases
[1] + data_addr
;
3081 /* If the object file has only one segment, assume that it is text
3082 rather than data; main programs with no writable data are rare,
3083 but programs with no code are useless. Of course the code might
3084 have ended up in the data segment... to detect that we would need
3085 the permissions here. */
3086 else if (data
&& data
->num_segments
== 1)
3088 segments
[0] = data
->segment_bases
[0] + text_addr
;
3091 /* There's no way to relocate by segment. */
3097 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3098 offs
, num_segments
, segments
);
3100 if (ret
== 0 && !do_sections
)
3101 error (_("Can not handle qOffsets TextSeg "
3102 "response with this symbol file"));
3109 free_symfile_segment_data (data
);
3113 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3115 /* This is a temporary kludge to force data and bss to use the
3116 same offsets because that's what nlmconv does now. The real
3117 solution requires changes to the stub and remote.c that I
3118 don't have time to do right now. */
3120 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3121 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3124 objfile_relocate (symfile_objfile
, offs
);
3127 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3128 threads we know are stopped already. This is used during the
3129 initial remote connection in non-stop mode --- threads that are
3130 reported as already being stopped are left stopped. */
3133 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3135 /* If we have a stop reply for this thread, it must be stopped. */
3136 if (peek_stop_reply (thread
->ptid
))
3137 set_stop_requested (thread
->ptid
, 1);
3142 /* Send interrupt_sequence to remote target. */
3144 send_interrupt_sequence (void)
3146 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3147 serial_write (remote_desc
, "\x03", 1);
3148 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3149 serial_send_break (remote_desc
);
3150 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3152 serial_send_break (remote_desc
);
3153 serial_write (remote_desc
, "g", 1);
3156 internal_error (__FILE__
, __LINE__
,
3157 _("Invalid value for interrupt_sequence_mode: %s."),
3158 interrupt_sequence_mode
);
3161 /* Query the remote target for which is the current thread/process,
3162 add it to our tables, and update INFERIOR_PTID. The caller is
3163 responsible for setting the state such that the remote end is ready
3164 to return the current thread. */
3167 add_current_inferior_and_thread (void)
3169 struct remote_state
*rs
= get_remote_state ();
3173 inferior_ptid
= null_ptid
;
3175 /* Now, if we have thread information, update inferior_ptid. */
3176 ptid
= remote_current_thread (inferior_ptid
);
3177 if (!ptid_equal (ptid
, null_ptid
))
3179 if (!remote_multi_process_p (rs
))
3182 inferior_ptid
= ptid
;
3186 /* Without this, some commands which require an active target
3187 (such as kill) won't work. This variable serves (at least)
3188 double duty as both the pid of the target process (if it has
3189 such), and as a flag indicating that a target is active. */
3190 inferior_ptid
= magic_null_ptid
;
3194 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3196 /* Add the main thread. */
3197 add_thread_silent (inferior_ptid
);
3201 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3203 struct remote_state
*rs
= get_remote_state ();
3204 struct packet_config
*noack_config
;
3205 char *wait_status
= NULL
;
3207 immediate_quit
++; /* Allow user to interrupt it. */
3209 if (interrupt_on_connect
)
3210 send_interrupt_sequence ();
3212 /* Ack any packet which the remote side has already sent. */
3213 serial_write (remote_desc
, "+", 1);
3215 /* The first packet we send to the target is the optional "supported
3216 packets" request. If the target can answer this, it will tell us
3217 which later probes to skip. */
3218 remote_query_supported ();
3220 /* If the stub wants to get a QAllow, compose one and send it. */
3221 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3222 remote_set_permissions ();
3224 /* Next, we possibly activate noack mode.
3226 If the QStartNoAckMode packet configuration is set to AUTO,
3227 enable noack mode if the stub reported a wish for it with
3230 If set to TRUE, then enable noack mode even if the stub didn't
3231 report it in qSupported. If the stub doesn't reply OK, the
3232 session ends with an error.
3234 If FALSE, then don't activate noack mode, regardless of what the
3235 stub claimed should be the default with qSupported. */
3237 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3239 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3240 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3241 && noack_config
->support
== PACKET_ENABLE
))
3243 putpkt ("QStartNoAckMode");
3244 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3245 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3251 /* Tell the remote that we are using the extended protocol. */
3253 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3256 /* Next, if the target can specify a description, read it. We do
3257 this before anything involving memory or registers. */
3258 target_find_description ();
3260 /* Next, now that we know something about the target, update the
3261 address spaces in the program spaces. */
3262 update_address_spaces ();
3264 /* On OSs where the list of libraries is global to all
3265 processes, we fetch them early. */
3266 if (gdbarch_has_global_solist (target_gdbarch
))
3267 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3271 if (!rs
->non_stop_aware
)
3272 error (_("Non-stop mode requested, but remote "
3273 "does not support non-stop"));
3275 putpkt ("QNonStop:1");
3276 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3278 if (strcmp (rs
->buf
, "OK") != 0)
3279 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3281 /* Find about threads and processes the stub is already
3282 controlling. We default to adding them in the running state.
3283 The '?' query below will then tell us about which threads are
3285 remote_threads_info (target
);
3287 else if (rs
->non_stop_aware
)
3289 /* Don't assume that the stub can operate in all-stop mode.
3290 Request it explicitely. */
3291 putpkt ("QNonStop:0");
3292 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3294 if (strcmp (rs
->buf
, "OK") != 0)
3295 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3298 /* Check whether the target is running now. */
3300 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3306 struct inferior
*inf
;
3308 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3311 error (_("The target is not running (try extended-remote?)"));
3313 /* We're connected, but not running. Drop out before we
3314 call start_remote. */
3319 /* Save the reply for later. */
3320 wait_status
= alloca (strlen (rs
->buf
) + 1);
3321 strcpy (wait_status
, rs
->buf
);
3324 /* Let the stub know that we want it to return the thread. */
3325 set_continue_thread (minus_one_ptid
);
3327 add_current_inferior_and_thread ();
3329 /* init_wait_for_inferior should be called before get_offsets in order
3330 to manage `inserted' flag in bp loc in a correct state.
3331 breakpoint_init_inferior, called from init_wait_for_inferior, set
3332 `inserted' flag to 0, while before breakpoint_re_set, called from
3333 start_remote, set `inserted' flag to 1. In the initialization of
3334 inferior, breakpoint_init_inferior should be called first, and then
3335 breakpoint_re_set can be called. If this order is broken, state of
3336 `inserted' flag is wrong, and cause some problems on breakpoint
3338 init_wait_for_inferior ();
3340 get_offsets (); /* Get text, data & bss offsets. */
3342 /* If we could not find a description using qXfer, and we know
3343 how to do it some other way, try again. This is not
3344 supported for non-stop; it could be, but it is tricky if
3345 there are no stopped threads when we connect. */
3346 if (remote_read_description_p (target
)
3347 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3349 target_clear_description ();
3350 target_find_description ();
3353 /* Use the previously fetched status. */
3354 gdb_assert (wait_status
!= NULL
);
3355 strcpy (rs
->buf
, wait_status
);
3356 rs
->cached_wait_status
= 1;
3359 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3363 /* Clear WFI global state. Do this before finding about new
3364 threads and inferiors, and setting the current inferior.
3365 Otherwise we would clear the proceed status of the current
3366 inferior when we want its stop_soon state to be preserved
3367 (see notice_new_inferior). */
3368 init_wait_for_inferior ();
3370 /* In non-stop, we will either get an "OK", meaning that there
3371 are no stopped threads at this time; or, a regular stop
3372 reply. In the latter case, there may be more than one thread
3373 stopped --- we pull them all out using the vStopped
3375 if (strcmp (rs
->buf
, "OK") != 0)
3377 struct stop_reply
*stop_reply
;
3378 struct cleanup
*old_chain
;
3380 stop_reply
= stop_reply_xmalloc ();
3381 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3383 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3384 discard_cleanups (old_chain
);
3386 /* get_pending_stop_replies acks this one, and gets the rest
3388 pending_stop_reply
= stop_reply
;
3389 remote_get_pending_stop_replies ();
3391 /* Make sure that threads that were stopped remain
3393 iterate_over_threads (set_stop_requested_callback
, NULL
);
3396 if (target_can_async_p ())
3397 target_async (inferior_event_handler
, 0);
3399 if (thread_count () == 0)
3402 error (_("The target is not running (try extended-remote?)"));
3404 /* We're connected, but not running. Drop out before we
3405 call start_remote. */
3409 /* Let the stub know that we want it to return the thread. */
3411 /* Force the stub to choose a thread. */
3412 set_general_thread (null_ptid
);
3415 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3416 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3417 error (_("remote didn't report the current thread in non-stop mode"));
3419 get_offsets (); /* Get text, data & bss offsets. */
3421 /* In non-stop mode, any cached wait status will be stored in
3422 the stop reply queue. */
3423 gdb_assert (wait_status
== NULL
);
3425 /* Report all signals during attach/startup. */
3426 remote_pass_signals (0, NULL
);
3429 /* If we connected to a live target, do some additional setup. */
3430 if (target_has_execution
)
3432 if (exec_bfd
) /* No use without an exec file. */
3433 remote_check_symbols (symfile_objfile
);
3436 /* Possibly the target has been engaged in a trace run started
3437 previously; find out where things are at. */
3438 if (remote_get_trace_status (current_trace_status ()) != -1)
3440 struct uploaded_tp
*uploaded_tps
= NULL
;
3441 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3443 if (current_trace_status ()->running
)
3444 printf_filtered (_("Trace is already running on the target.\n"));
3446 /* Get trace state variables first, they may be checked when
3447 parsing uploaded commands. */
3449 remote_upload_trace_state_variables (&uploaded_tsvs
);
3451 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3453 remote_upload_tracepoints (&uploaded_tps
);
3455 merge_uploaded_tracepoints (&uploaded_tps
);
3458 /* If breakpoints are global, insert them now. */
3459 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3460 && breakpoints_always_inserted_mode ())
3461 insert_breakpoints ();
3464 /* Open a connection to a remote debugger.
3465 NAME is the filename used for communication. */
3468 remote_open (char *name
, int from_tty
)
3470 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3473 /* Open a connection to a remote debugger using the extended
3474 remote gdb protocol. NAME is the filename used for communication. */
3477 extended_remote_open (char *name
, int from_tty
)
3479 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3482 /* Generic code for opening a connection to a remote target. */
3485 init_all_packet_configs (void)
3489 for (i
= 0; i
< PACKET_MAX
; i
++)
3490 update_packet_config (&remote_protocol_packets
[i
]);
3493 /* Symbol look-up. */
3496 remote_check_symbols (struct objfile
*objfile
)
3498 struct remote_state
*rs
= get_remote_state ();
3499 char *msg
, *reply
, *tmp
;
3500 struct minimal_symbol
*sym
;
3503 /* The remote side has no concept of inferiors that aren't running
3504 yet, it only knows about running processes. If we're connected
3505 but our current inferior is not running, we should not invite the
3506 remote target to request symbol lookups related to its
3507 (unrelated) current process. */
3508 if (!target_has_execution
)
3511 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3514 /* Make sure the remote is pointing at the right process. Note
3515 there's no way to select "no process". */
3516 set_general_process ();
3518 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3519 because we need both at the same time. */
3520 msg
= alloca (get_remote_packet_size ());
3522 /* Invite target to request symbol lookups. */
3524 putpkt ("qSymbol::");
3525 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3526 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3529 while (strncmp (reply
, "qSymbol:", 8) == 0)
3532 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3534 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3536 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3539 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3540 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3542 /* If this is a function address, return the start of code
3543 instead of any data function descriptor. */
3544 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3548 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3549 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3553 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3558 static struct serial
*
3559 remote_serial_open (char *name
)
3561 static int udp_warning
= 0;
3563 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3564 of in ser-tcp.c, because it is the remote protocol assuming that the
3565 serial connection is reliable and not the serial connection promising
3567 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3569 warning (_("The remote protocol may be unreliable over UDP.\n"
3570 "Some events may be lost, rendering further debugging "
3575 return serial_open (name
);
3578 /* Inform the target of our permission settings. The permission flags
3579 work without this, but if the target knows the settings, it can do
3580 a couple things. First, it can add its own check, to catch cases
3581 that somehow manage to get by the permissions checks in target
3582 methods. Second, if the target is wired to disallow particular
3583 settings (for instance, a system in the field that is not set up to
3584 be able to stop at a breakpoint), it can object to any unavailable
3588 remote_set_permissions (void)
3590 struct remote_state
*rs
= get_remote_state ();
3592 sprintf (rs
->buf
, "QAllow:"
3593 "WriteReg:%x;WriteMem:%x;"
3594 "InsertBreak:%x;InsertTrace:%x;"
3595 "InsertFastTrace:%x;Stop:%x",
3596 may_write_registers
, may_write_memory
,
3597 may_insert_breakpoints
, may_insert_tracepoints
,
3598 may_insert_fast_tracepoints
, may_stop
);
3600 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3602 /* If the target didn't like the packet, warn the user. Do not try
3603 to undo the user's settings, that would just be maddening. */
3604 if (strcmp (rs
->buf
, "OK") != 0)
3605 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3608 /* This type describes each known response to the qSupported
3610 struct protocol_feature
3612 /* The name of this protocol feature. */
3615 /* The default for this protocol feature. */
3616 enum packet_support default_support
;
3618 /* The function to call when this feature is reported, or after
3619 qSupported processing if the feature is not supported.
3620 The first argument points to this structure. The second
3621 argument indicates whether the packet requested support be
3622 enabled, disabled, or probed (or the default, if this function
3623 is being called at the end of processing and this feature was
3624 not reported). The third argument may be NULL; if not NULL, it
3625 is a NUL-terminated string taken from the packet following
3626 this feature's name and an equals sign. */
3627 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3630 /* The corresponding packet for this feature. Only used if
3631 FUNC is remote_supported_packet. */
3636 remote_supported_packet (const struct protocol_feature
*feature
,
3637 enum packet_support support
,
3638 const char *argument
)
3642 warning (_("Remote qSupported response supplied an unexpected value for"
3643 " \"%s\"."), feature
->name
);
3647 if (remote_protocol_packets
[feature
->packet
].support
3648 == PACKET_SUPPORT_UNKNOWN
)
3649 remote_protocol_packets
[feature
->packet
].support
= support
;
3653 remote_packet_size (const struct protocol_feature
*feature
,
3654 enum packet_support support
, const char *value
)
3656 struct remote_state
*rs
= get_remote_state ();
3661 if (support
!= PACKET_ENABLE
)
3664 if (value
== NULL
|| *value
== '\0')
3666 warning (_("Remote target reported \"%s\" without a size."),
3672 packet_size
= strtol (value
, &value_end
, 16);
3673 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3675 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3676 feature
->name
, value
);
3680 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3682 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3683 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3684 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3687 /* Record the new maximum packet size. */
3688 rs
->explicit_packet_size
= packet_size
;
3692 remote_multi_process_feature (const struct protocol_feature
*feature
,
3693 enum packet_support support
, const char *value
)
3695 struct remote_state
*rs
= get_remote_state ();
3697 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3701 remote_non_stop_feature (const struct protocol_feature
*feature
,
3702 enum packet_support support
, const char *value
)
3704 struct remote_state
*rs
= get_remote_state ();
3706 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3710 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3711 enum packet_support support
,
3714 struct remote_state
*rs
= get_remote_state ();
3716 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3720 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3721 enum packet_support support
,
3724 struct remote_state
*rs
= get_remote_state ();
3726 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3730 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3731 enum packet_support support
,
3734 struct remote_state
*rs
= get_remote_state ();
3736 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3740 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3741 enum packet_support support
,
3744 struct remote_state
*rs
= get_remote_state ();
3746 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3750 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3751 enum packet_support support
,
3754 struct remote_state
*rs
= get_remote_state ();
3756 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3760 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3761 enum packet_support support
,
3764 struct remote_state
*rs
= get_remote_state ();
3766 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3770 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3771 enum packet_support support
,
3774 struct remote_state
*rs
= get_remote_state ();
3776 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3779 static struct protocol_feature remote_protocol_features
[] = {
3780 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3781 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3782 PACKET_qXfer_auxv
},
3783 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3784 PACKET_qXfer_features
},
3785 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3786 PACKET_qXfer_libraries
},
3787 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3788 PACKET_qXfer_libraries_svr4
},
3789 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3790 PACKET_qXfer_memory_map
},
3791 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3792 PACKET_qXfer_spu_read
},
3793 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3794 PACKET_qXfer_spu_write
},
3795 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3796 PACKET_qXfer_osdata
},
3797 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3798 PACKET_qXfer_threads
},
3799 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3800 PACKET_qXfer_traceframe_info
},
3801 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3802 PACKET_QPassSignals
},
3803 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3804 PACKET_QStartNoAckMode
},
3805 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3806 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3807 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3808 PACKET_qXfer_siginfo_read
},
3809 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3810 PACKET_qXfer_siginfo_write
},
3811 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3812 PACKET_ConditionalTracepoints
},
3813 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3814 PACKET_FastTracepoints
},
3815 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3816 PACKET_StaticTracepoints
},
3817 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3818 PACKET_InstallInTrace
},
3819 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3821 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3823 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3825 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3826 PACKET_TracepointSource
},
3827 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3829 { "EnableDisableTracepoints", PACKET_DISABLE
,
3830 remote_enable_disable_tracepoint_feature
, -1 },
3831 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3832 PACKET_qXfer_fdpic
},
3833 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3834 PACKET_QDisableRandomization
},
3835 { "tracenz", PACKET_DISABLE
,
3836 remote_string_tracing_feature
, -1 },
3839 static char *remote_support_xml
;
3841 /* Register string appended to "xmlRegisters=" in qSupported query. */
3844 register_remote_support_xml (const char *xml
)
3846 #if defined(HAVE_LIBEXPAT)
3847 if (remote_support_xml
== NULL
)
3848 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3851 char *copy
= xstrdup (remote_support_xml
+ 13);
3852 char *p
= strtok (copy
, ",");
3856 if (strcmp (p
, xml
) == 0)
3863 while ((p
= strtok (NULL
, ",")) != NULL
);
3866 remote_support_xml
= reconcat (remote_support_xml
,
3867 remote_support_xml
, ",", xml
,
3874 remote_query_supported_append (char *msg
, const char *append
)
3877 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3879 return xstrdup (append
);
3883 remote_query_supported (void)
3885 struct remote_state
*rs
= get_remote_state ();
3888 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3890 /* The packet support flags are handled differently for this packet
3891 than for most others. We treat an error, a disabled packet, and
3892 an empty response identically: any features which must be reported
3893 to be used will be automatically disabled. An empty buffer
3894 accomplishes this, since that is also the representation for a list
3895 containing no features. */
3898 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3901 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3903 q
= remote_query_supported_append (q
, "multiprocess+");
3905 if (remote_support_xml
)
3906 q
= remote_query_supported_append (q
, remote_support_xml
);
3908 q
= remote_query_supported_append (q
, "qRelocInsn+");
3910 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3913 do_cleanups (old_chain
);
3915 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3917 /* If an error occured, warn, but do not return - just reset the
3918 buffer to empty and go on to disable features. */
3919 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3922 warning (_("Remote failure reply: %s"), rs
->buf
);
3927 memset (seen
, 0, sizeof (seen
));
3932 enum packet_support is_supported
;
3933 char *p
, *end
, *name_end
, *value
;
3935 /* First separate out this item from the rest of the packet. If
3936 there's another item after this, we overwrite the separator
3937 (terminated strings are much easier to work with). */
3939 end
= strchr (p
, ';');
3942 end
= p
+ strlen (p
);
3952 warning (_("empty item in \"qSupported\" response"));
3957 name_end
= strchr (p
, '=');
3960 /* This is a name=value entry. */
3961 is_supported
= PACKET_ENABLE
;
3962 value
= name_end
+ 1;
3971 is_supported
= PACKET_ENABLE
;
3975 is_supported
= PACKET_DISABLE
;
3979 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3983 warning (_("unrecognized item \"%s\" "
3984 "in \"qSupported\" response"), p
);
3990 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3991 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3993 const struct protocol_feature
*feature
;
3996 feature
= &remote_protocol_features
[i
];
3997 feature
->func (feature
, is_supported
, value
);
4002 /* If we increased the packet size, make sure to increase the global
4003 buffer size also. We delay this until after parsing the entire
4004 qSupported packet, because this is the same buffer we were
4006 if (rs
->buf_size
< rs
->explicit_packet_size
)
4008 rs
->buf_size
= rs
->explicit_packet_size
;
4009 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4012 /* Handle the defaults for unmentioned features. */
4013 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4016 const struct protocol_feature
*feature
;
4018 feature
= &remote_protocol_features
[i
];
4019 feature
->func (feature
, feature
->default_support
, NULL
);
4025 remote_open_1 (char *name
, int from_tty
,
4026 struct target_ops
*target
, int extended_p
)
4028 struct remote_state
*rs
= get_remote_state ();
4031 error (_("To open a remote debug connection, you need to specify what\n"
4032 "serial device is attached to the remote system\n"
4033 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4035 /* See FIXME above. */
4036 if (!target_async_permitted
)
4037 wait_forever_enabled_p
= 1;
4039 /* If we're connected to a running target, target_preopen will kill it.
4040 But if we're connected to a target system with no running process,
4041 then we will still be connected when it returns. Ask this question
4042 first, before target_preopen has a chance to kill anything. */
4043 if (remote_desc
!= NULL
&& !have_inferiors ())
4046 || query (_("Already connected to a remote target. Disconnect? ")))
4049 error (_("Still connected."));
4052 target_preopen (from_tty
);
4054 unpush_target (target
);
4056 /* This time without a query. If we were connected to an
4057 extended-remote target and target_preopen killed the running
4058 process, we may still be connected. If we are starting "target
4059 remote" now, the extended-remote target will not have been
4060 removed by unpush_target. */
4061 if (remote_desc
!= NULL
&& !have_inferiors ())
4064 /* Make sure we send the passed signals list the next time we resume. */
4065 xfree (last_pass_packet
);
4066 last_pass_packet
= NULL
;
4068 remote_fileio_reset ();
4069 reopen_exec_file ();
4072 remote_desc
= remote_serial_open (name
);
4074 perror_with_name (name
);
4076 if (baud_rate
!= -1)
4078 if (serial_setbaudrate (remote_desc
, baud_rate
))
4080 /* The requested speed could not be set. Error out to
4081 top level after closing remote_desc. Take care to
4082 set remote_desc to NULL to avoid closing remote_desc
4084 serial_close (remote_desc
);
4086 perror_with_name (name
);
4090 serial_raw (remote_desc
);
4092 /* If there is something sitting in the buffer we might take it as a
4093 response to a command, which would be bad. */
4094 serial_flush_input (remote_desc
);
4098 puts_filtered ("Remote debugging using ");
4099 puts_filtered (name
);
4100 puts_filtered ("\n");
4102 push_target (target
); /* Switch to using remote target now. */
4104 /* Register extra event sources in the event loop. */
4105 remote_async_inferior_event_token
4106 = create_async_event_handler (remote_async_inferior_event_handler
,
4108 remote_async_get_pending_events_token
4109 = create_async_event_handler (remote_async_get_pending_events_handler
,
4112 /* Reset the target state; these things will be queried either by
4113 remote_query_supported or as they are needed. */
4114 init_all_packet_configs ();
4115 rs
->cached_wait_status
= 0;
4116 rs
->explicit_packet_size
= 0;
4118 rs
->multi_process_aware
= 0;
4119 rs
->extended
= extended_p
;
4120 rs
->non_stop_aware
= 0;
4121 rs
->waiting_for_stop_reply
= 0;
4122 rs
->ctrlc_pending_p
= 0;
4124 general_thread
= not_sent_ptid
;
4125 continue_thread
= not_sent_ptid
;
4126 remote_traceframe_number
= -1;
4128 /* Probe for ability to use "ThreadInfo" query, as required. */
4129 use_threadinfo_query
= 1;
4130 use_threadextra_query
= 1;
4132 if (target_async_permitted
)
4134 /* With this target we start out by owning the terminal. */
4135 remote_async_terminal_ours_p
= 1;
4137 /* FIXME: cagney/1999-09-23: During the initial connection it is
4138 assumed that the target is already ready and able to respond to
4139 requests. Unfortunately remote_start_remote() eventually calls
4140 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4141 around this. Eventually a mechanism that allows
4142 wait_for_inferior() to expect/get timeouts will be
4144 wait_forever_enabled_p
= 0;
4147 /* First delete any symbols previously loaded from shared libraries. */
4148 no_shared_libraries (NULL
, 0);
4151 init_thread_list ();
4153 /* Start the remote connection. If error() or QUIT, discard this
4154 target (we'd otherwise be in an inconsistent state) and then
4155 propogate the error on up the exception chain. This ensures that
4156 the caller doesn't stumble along blindly assuming that the
4157 function succeeded. The CLI doesn't have this problem but other
4158 UI's, such as MI do.
4160 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4161 this function should return an error indication letting the
4162 caller restore the previous state. Unfortunately the command
4163 ``target remote'' is directly wired to this function making that
4164 impossible. On a positive note, the CLI side of this problem has
4165 been fixed - the function set_cmd_context() makes it possible for
4166 all the ``target ....'' commands to share a common callback
4167 function. See cli-dump.c. */
4169 volatile struct gdb_exception ex
;
4171 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4173 remote_start_remote (from_tty
, target
, extended_p
);
4177 /* Pop the partially set up target - unless something else did
4178 already before throwing the exception. */
4179 if (remote_desc
!= NULL
)
4181 if (target_async_permitted
)
4182 wait_forever_enabled_p
= 1;
4183 throw_exception (ex
);
4187 if (target_async_permitted
)
4188 wait_forever_enabled_p
= 1;
4191 /* This takes a program previously attached to and detaches it. After
4192 this is done, GDB can be used to debug some other program. We
4193 better not have left any breakpoints in the target program or it'll
4194 die when it hits one. */
4197 remote_detach_1 (char *args
, int from_tty
, int extended
)
4199 int pid
= ptid_get_pid (inferior_ptid
);
4200 struct remote_state
*rs
= get_remote_state ();
4203 error (_("Argument given to \"detach\" when remotely debugging."));
4205 if (!target_has_execution
)
4206 error (_("No process to detach from."));
4210 char *exec_file
= get_exec_file (0);
4211 if (exec_file
== NULL
)
4213 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4214 target_pid_to_str (pid_to_ptid (pid
)));
4215 gdb_flush (gdb_stdout
);
4218 /* Tell the remote target to detach. */
4219 if (remote_multi_process_p (rs
))
4220 sprintf (rs
->buf
, "D;%x", pid
);
4222 strcpy (rs
->buf
, "D");
4225 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4227 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4229 else if (rs
->buf
[0] == '\0')
4230 error (_("Remote doesn't know how to detach"));
4232 error (_("Can't detach process."));
4234 if (from_tty
&& !extended
)
4235 puts_filtered (_("Ending remote debugging.\n"));
4237 discard_pending_stop_replies (pid
);
4238 target_mourn_inferior ();
4242 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4244 remote_detach_1 (args
, from_tty
, 0);
4248 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4250 remote_detach_1 (args
, from_tty
, 1);
4253 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4256 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4259 error (_("Argument given to \"disconnect\" when remotely debugging."));
4261 /* Make sure we unpush even the extended remote targets; mourn
4262 won't do it. So call remote_mourn_1 directly instead of
4263 target_mourn_inferior. */
4264 remote_mourn_1 (target
);
4267 puts_filtered ("Ending remote debugging.\n");
4270 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4271 be chatty about it. */
4274 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4276 struct remote_state
*rs
= get_remote_state ();
4278 char *wait_status
= NULL
;
4280 pid
= parse_pid_to_attach (args
);
4282 /* Remote PID can be freely equal to getpid, do not check it here the same
4283 way as in other targets. */
4285 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4286 error (_("This target does not support attaching to a process"));
4290 char *exec_file
= get_exec_file (0);
4293 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4294 target_pid_to_str (pid_to_ptid (pid
)));
4296 printf_unfiltered (_("Attaching to %s\n"),
4297 target_pid_to_str (pid_to_ptid (pid
)));
4299 gdb_flush (gdb_stdout
);
4302 sprintf (rs
->buf
, "vAttach;%x", pid
);
4304 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4306 if (packet_ok (rs
->buf
,
4307 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4311 /* Save the reply for later. */
4312 wait_status
= alloca (strlen (rs
->buf
) + 1);
4313 strcpy (wait_status
, rs
->buf
);
4315 else if (strcmp (rs
->buf
, "OK") != 0)
4316 error (_("Attaching to %s failed with: %s"),
4317 target_pid_to_str (pid_to_ptid (pid
)),
4320 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4321 error (_("This target does not support attaching to a process"));
4323 error (_("Attaching to %s failed"),
4324 target_pid_to_str (pid_to_ptid (pid
)));
4326 set_current_inferior (remote_add_inferior (0, pid
, 1));
4328 inferior_ptid
= pid_to_ptid (pid
);
4332 struct thread_info
*thread
;
4334 /* Get list of threads. */
4335 remote_threads_info (target
);
4337 thread
= first_thread_of_process (pid
);
4339 inferior_ptid
= thread
->ptid
;
4341 inferior_ptid
= pid_to_ptid (pid
);
4343 /* Invalidate our notion of the remote current thread. */
4344 record_currthread (minus_one_ptid
);
4348 /* Now, if we have thread information, update inferior_ptid. */
4349 inferior_ptid
= remote_current_thread (inferior_ptid
);
4351 /* Add the main thread to the thread list. */
4352 add_thread_silent (inferior_ptid
);
4355 /* Next, if the target can specify a description, read it. We do
4356 this before anything involving memory or registers. */
4357 target_find_description ();
4361 /* Use the previously fetched status. */
4362 gdb_assert (wait_status
!= NULL
);
4364 if (target_can_async_p ())
4366 struct stop_reply
*stop_reply
;
4367 struct cleanup
*old_chain
;
4369 stop_reply
= stop_reply_xmalloc ();
4370 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4371 remote_parse_stop_reply (wait_status
, stop_reply
);
4372 discard_cleanups (old_chain
);
4373 push_stop_reply (stop_reply
);
4375 target_async (inferior_event_handler
, 0);
4379 gdb_assert (wait_status
!= NULL
);
4380 strcpy (rs
->buf
, wait_status
);
4381 rs
->cached_wait_status
= 1;
4385 gdb_assert (wait_status
== NULL
);
4389 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4391 extended_remote_attach_1 (ops
, args
, from_tty
);
4394 /* Convert hex digit A to a number. */
4399 if (a
>= '0' && a
<= '9')
4401 else if (a
>= 'a' && a
<= 'f')
4402 return a
- 'a' + 10;
4403 else if (a
>= 'A' && a
<= 'F')
4404 return a
- 'A' + 10;
4406 error (_("Reply contains invalid hex digit %d"), a
);
4410 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4414 for (i
= 0; i
< count
; i
++)
4416 if (hex
[0] == 0 || hex
[1] == 0)
4418 /* Hex string is short, or of uneven length.
4419 Return the count that has been converted so far. */
4422 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4428 /* Convert number NIB to a hex digit. */
4436 return 'a' + nib
- 10;
4440 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4444 /* May use a length, or a nul-terminated string as input. */
4446 count
= strlen ((char *) bin
);
4448 for (i
= 0; i
< count
; i
++)
4450 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4451 *hex
++ = tohex (*bin
++ & 0xf);
4457 /* Check for the availability of vCont. This function should also check
4461 remote_vcont_probe (struct remote_state
*rs
)
4465 strcpy (rs
->buf
, "vCont?");
4467 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4470 /* Make sure that the features we assume are supported. */
4471 if (strncmp (buf
, "vCont", 5) == 0)
4474 int support_s
, support_S
, support_c
, support_C
;
4480 rs
->support_vCont_t
= 0;
4481 while (p
&& *p
== ';')
4484 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4486 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4488 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4490 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4492 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4493 rs
->support_vCont_t
= 1;
4495 p
= strchr (p
, ';');
4498 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4499 BUF will make packet_ok disable the packet. */
4500 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4504 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4507 /* Helper function for building "vCont" resumptions. Write a
4508 resumption to P. ENDP points to one-passed-the-end of the buffer
4509 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4510 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4511 resumed thread should be single-stepped and/or signalled. If PTID
4512 equals minus_one_ptid, then all threads are resumed; if PTID
4513 represents a process, then all threads of the process are resumed;
4514 the thread to be stepped and/or signalled is given in the global
4518 append_resumption (char *p
, char *endp
,
4519 ptid_t ptid
, int step
, enum target_signal siggnal
)
4521 struct remote_state
*rs
= get_remote_state ();
4523 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4524 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4526 p
+= xsnprintf (p
, endp
- p
, ";s");
4527 else if (siggnal
!= TARGET_SIGNAL_0
)
4528 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4530 p
+= xsnprintf (p
, endp
- p
, ";c");
4532 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4536 /* All (-1) threads of process. */
4537 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4539 p
+= xsnprintf (p
, endp
- p
, ":");
4540 p
= write_ptid (p
, endp
, nptid
);
4542 else if (!ptid_equal (ptid
, minus_one_ptid
))
4544 p
+= xsnprintf (p
, endp
- p
, ":");
4545 p
= write_ptid (p
, endp
, ptid
);
4551 /* Resume the remote inferior by using a "vCont" packet. The thread
4552 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4553 resumed thread should be single-stepped and/or signalled. If PTID
4554 equals minus_one_ptid, then all threads are resumed; the thread to
4555 be stepped and/or signalled is given in the global INFERIOR_PTID.
4556 This function returns non-zero iff it resumes the inferior.
4558 This function issues a strict subset of all possible vCont commands at the
4562 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4564 struct remote_state
*rs
= get_remote_state ();
4568 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4569 remote_vcont_probe (rs
);
4571 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4575 endp
= rs
->buf
+ get_remote_packet_size ();
4577 /* If we could generate a wider range of packets, we'd have to worry
4578 about overflowing BUF. Should there be a generic
4579 "multi-part-packet" packet? */
4581 p
+= xsnprintf (p
, endp
- p
, "vCont");
4583 if (ptid_equal (ptid
, magic_null_ptid
))
4585 /* MAGIC_NULL_PTID means that we don't have any active threads,
4586 so we don't have any TID numbers the inferior will
4587 understand. Make sure to only send forms that do not specify
4589 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4591 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4593 /* Resume all threads (of all processes, or of a single
4594 process), with preference for INFERIOR_PTID. This assumes
4595 inferior_ptid belongs to the set of all threads we are about
4597 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4599 /* Step inferior_ptid, with or without signal. */
4600 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4603 /* And continue others without a signal. */
4604 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4608 /* Scheduler locking; resume only PTID. */
4609 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4612 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4617 /* In non-stop, the stub replies to vCont with "OK". The stop
4618 reply will be reported asynchronously by means of a `%Stop'
4620 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4621 if (strcmp (rs
->buf
, "OK") != 0)
4622 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4628 /* Tell the remote machine to resume. */
4630 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4632 static int last_sent_step
;
4635 remote_resume (struct target_ops
*ops
,
4636 ptid_t ptid
, int step
, enum target_signal siggnal
)
4638 struct remote_state
*rs
= get_remote_state ();
4641 last_sent_signal
= siggnal
;
4642 last_sent_step
= step
;
4644 /* The vCont packet doesn't need to specify threads via Hc. */
4645 /* No reverse support (yet) for vCont. */
4646 if (execution_direction
!= EXEC_REVERSE
)
4647 if (remote_vcont_resume (ptid
, step
, siggnal
))
4650 /* All other supported resume packets do use Hc, so set the continue
4652 if (ptid_equal (ptid
, minus_one_ptid
))
4653 set_continue_thread (any_thread_ptid
);
4655 set_continue_thread (ptid
);
4658 if (execution_direction
== EXEC_REVERSE
)
4660 /* We don't pass signals to the target in reverse exec mode. */
4661 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4662 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4666 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4667 error (_("Remote reverse-step not supported."));
4669 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4670 error (_("Remote reverse-continue not supported."));
4672 strcpy (buf
, step
? "bs" : "bc");
4674 else if (siggnal
!= TARGET_SIGNAL_0
)
4676 buf
[0] = step
? 'S' : 'C';
4677 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4678 buf
[2] = tohex (((int) siggnal
) & 0xf);
4682 strcpy (buf
, step
? "s" : "c");
4687 /* We are about to start executing the inferior, let's register it
4688 with the event loop. NOTE: this is the one place where all the
4689 execution commands end up. We could alternatively do this in each
4690 of the execution commands in infcmd.c. */
4691 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4692 into infcmd.c in order to allow inferior function calls to work
4693 NOT asynchronously. */
4694 if (target_can_async_p ())
4695 target_async (inferior_event_handler
, 0);
4697 /* We've just told the target to resume. The remote server will
4698 wait for the inferior to stop, and then send a stop reply. In
4699 the mean time, we can't start another command/query ourselves
4700 because the stub wouldn't be ready to process it. This applies
4701 only to the base all-stop protocol, however. In non-stop (which
4702 only supports vCont), the stub replies with an "OK", and is
4703 immediate able to process further serial input. */
4705 rs
->waiting_for_stop_reply
= 1;
4709 /* Set up the signal handler for SIGINT, while the target is
4710 executing, ovewriting the 'regular' SIGINT signal handler. */
4712 initialize_sigint_signal_handler (void)
4714 signal (SIGINT
, handle_remote_sigint
);
4717 /* Signal handler for SIGINT, while the target is executing. */
4719 handle_remote_sigint (int sig
)
4721 signal (sig
, handle_remote_sigint_twice
);
4722 mark_async_signal_handler_wrapper (sigint_remote_token
);
4725 /* Signal handler for SIGINT, installed after SIGINT has already been
4726 sent once. It will take effect the second time that the user sends
4729 handle_remote_sigint_twice (int sig
)
4731 signal (sig
, handle_remote_sigint
);
4732 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4735 /* Perform the real interruption of the target execution, in response
4738 async_remote_interrupt (gdb_client_data arg
)
4741 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4743 target_stop (inferior_ptid
);
4746 /* Perform interrupt, if the first attempt did not succeed. Just give
4747 up on the target alltogether. */
4749 async_remote_interrupt_twice (gdb_client_data arg
)
4752 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4757 /* Reinstall the usual SIGINT handlers, after the target has
4760 cleanup_sigint_signal_handler (void *dummy
)
4762 signal (SIGINT
, handle_sigint
);
4765 /* Send ^C to target to halt it. Target will respond, and send us a
4767 static void (*ofunc
) (int);
4769 /* The command line interface's stop routine. This function is installed
4770 as a signal handler for SIGINT. The first time a user requests a
4771 stop, we call remote_stop to send a break or ^C. If there is no
4772 response from the target (it didn't stop when the user requested it),
4773 we ask the user if he'd like to detach from the target. */
4775 remote_interrupt (int signo
)
4777 /* If this doesn't work, try more severe steps. */
4778 signal (signo
, remote_interrupt_twice
);
4780 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4783 /* The user typed ^C twice. */
4786 remote_interrupt_twice (int signo
)
4788 signal (signo
, ofunc
);
4789 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4790 signal (signo
, remote_interrupt
);
4793 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4794 thread, all threads of a remote process, or all threads of all
4798 remote_stop_ns (ptid_t ptid
)
4800 struct remote_state
*rs
= get_remote_state ();
4802 char *endp
= rs
->buf
+ get_remote_packet_size ();
4804 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4805 remote_vcont_probe (rs
);
4807 if (!rs
->support_vCont_t
)
4808 error (_("Remote server does not support stopping threads"));
4810 if (ptid_equal (ptid
, minus_one_ptid
)
4811 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4812 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4817 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4819 if (ptid_is_pid (ptid
))
4820 /* All (-1) threads of process. */
4821 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4824 /* Small optimization: if we already have a stop reply for
4825 this thread, no use in telling the stub we want this
4827 if (peek_stop_reply (ptid
))
4833 write_ptid (p
, endp
, nptid
);
4836 /* In non-stop, we get an immediate OK reply. The stop reply will
4837 come in asynchronously by notification. */
4839 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4840 if (strcmp (rs
->buf
, "OK") != 0)
4841 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4844 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4845 remote target. It is undefined which thread of which process
4846 reports the stop. */
4849 remote_stop_as (ptid_t ptid
)
4851 struct remote_state
*rs
= get_remote_state ();
4853 rs
->ctrlc_pending_p
= 1;
4855 /* If the inferior is stopped already, but the core didn't know
4856 about it yet, just ignore the request. The cached wait status
4857 will be collected in remote_wait. */
4858 if (rs
->cached_wait_status
)
4861 /* Send interrupt_sequence to remote target. */
4862 send_interrupt_sequence ();
4865 /* This is the generic stop called via the target vector. When a target
4866 interrupt is requested, either by the command line or the GUI, we
4867 will eventually end up here. */
4870 remote_stop (ptid_t ptid
)
4873 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4876 remote_stop_ns (ptid
);
4878 remote_stop_as (ptid
);
4881 /* Ask the user what to do when an interrupt is received. */
4884 interrupt_query (void)
4886 target_terminal_ours ();
4888 if (target_can_async_p ())
4890 signal (SIGINT
, handle_sigint
);
4891 deprecated_throw_reason (RETURN_QUIT
);
4895 if (query (_("Interrupted while waiting for the program.\n\
4896 Give up (and stop debugging it)? ")))
4899 deprecated_throw_reason (RETURN_QUIT
);
4903 target_terminal_inferior ();
4906 /* Enable/disable target terminal ownership. Most targets can use
4907 terminal groups to control terminal ownership. Remote targets are
4908 different in that explicit transfer of ownership to/from GDB/target
4912 remote_terminal_inferior (void)
4914 if (!target_async_permitted
)
4915 /* Nothing to do. */
4918 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4919 idempotent. The event-loop GDB talking to an asynchronous target
4920 with a synchronous command calls this function from both
4921 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4922 transfer the terminal to the target when it shouldn't this guard
4924 if (!remote_async_terminal_ours_p
)
4926 delete_file_handler (input_fd
);
4927 remote_async_terminal_ours_p
= 0;
4928 initialize_sigint_signal_handler ();
4929 /* NOTE: At this point we could also register our selves as the
4930 recipient of all input. Any characters typed could then be
4931 passed on down to the target. */
4935 remote_terminal_ours (void)
4937 if (!target_async_permitted
)
4938 /* Nothing to do. */
4941 /* See FIXME in remote_terminal_inferior. */
4942 if (remote_async_terminal_ours_p
)
4944 cleanup_sigint_signal_handler (NULL
);
4945 add_file_handler (input_fd
, stdin_event_handler
, 0);
4946 remote_async_terminal_ours_p
= 1;
4950 remote_console_output (char *msg
)
4954 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4957 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4961 fputs_unfiltered (tb
, gdb_stdtarg
);
4963 gdb_flush (gdb_stdtarg
);
4966 typedef struct cached_reg
4969 gdb_byte data
[MAX_REGISTER_SIZE
];
4972 DEF_VEC_O(cached_reg_t
);
4976 struct stop_reply
*next
;
4980 struct target_waitstatus ws
;
4982 /* Expedited registers. This makes remote debugging a bit more
4983 efficient for those targets that provide critical registers as
4984 part of their normal status mechanism (as another roundtrip to
4985 fetch them is avoided). */
4986 VEC(cached_reg_t
) *regcache
;
4988 int stopped_by_watchpoint_p
;
4989 CORE_ADDR watch_data_address
;
4997 /* The list of already fetched and acknowledged stop events. */
4998 static struct stop_reply
*stop_reply_queue
;
5000 static struct stop_reply
*
5001 stop_reply_xmalloc (void)
5003 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
5010 stop_reply_xfree (struct stop_reply
*r
)
5014 VEC_free (cached_reg_t
, r
->regcache
);
5019 /* Discard all pending stop replies of inferior PID. If PID is -1,
5020 discard everything. */
5023 discard_pending_stop_replies (int pid
)
5025 struct stop_reply
*prev
= NULL
, *reply
, *next
;
5027 /* Discard the in-flight notification. */
5028 if (pending_stop_reply
!= NULL
5030 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
5032 stop_reply_xfree (pending_stop_reply
);
5033 pending_stop_reply
= NULL
;
5036 /* Discard the stop replies we have already pulled with
5038 for (reply
= stop_reply_queue
; reply
; reply
= next
)
5042 || ptid_get_pid (reply
->ptid
) == pid
)
5044 if (reply
== stop_reply_queue
)
5045 stop_reply_queue
= reply
->next
;
5047 prev
->next
= reply
->next
;
5049 stop_reply_xfree (reply
);
5056 /* Cleanup wrapper. */
5059 do_stop_reply_xfree (void *arg
)
5061 struct stop_reply
*r
= arg
;
5063 stop_reply_xfree (r
);
5066 /* Look for a queued stop reply belonging to PTID. If one is found,
5067 remove it from the queue, and return it. Returns NULL if none is
5068 found. If there are still queued events left to process, tell the
5069 event loop to get back to target_wait soon. */
5071 static struct stop_reply
*
5072 queued_stop_reply (ptid_t ptid
)
5074 struct stop_reply
*it
;
5075 struct stop_reply
**it_link
;
5077 it
= stop_reply_queue
;
5078 it_link
= &stop_reply_queue
;
5081 if (ptid_match (it
->ptid
, ptid
))
5083 *it_link
= it
->next
;
5088 it_link
= &it
->next
;
5092 if (stop_reply_queue
)
5093 /* There's still at least an event left. */
5094 mark_async_event_handler (remote_async_inferior_event_token
);
5099 /* Push a fully parsed stop reply in the stop reply queue. Since we
5100 know that we now have at least one queued event left to pass to the
5101 core side, tell the event loop to get back to target_wait soon. */
5104 push_stop_reply (struct stop_reply
*new_event
)
5106 struct stop_reply
*event
;
5108 if (stop_reply_queue
)
5110 for (event
= stop_reply_queue
;
5111 event
&& event
->next
;
5112 event
= event
->next
)
5115 event
->next
= new_event
;
5118 stop_reply_queue
= new_event
;
5120 mark_async_event_handler (remote_async_inferior_event_token
);
5123 /* Returns true if we have a stop reply for PTID. */
5126 peek_stop_reply (ptid_t ptid
)
5128 struct stop_reply
*it
;
5130 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5131 if (ptid_equal (ptid
, it
->ptid
))
5133 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5140 /* Parse the stop reply in BUF. Either the function succeeds, and the
5141 result is stored in EVENT, or throws an error. */
5144 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5146 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5150 event
->ptid
= null_ptid
;
5151 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5152 event
->ws
.value
.integer
= 0;
5153 event
->solibs_changed
= 0;
5154 event
->replay_event
= 0;
5155 event
->stopped_by_watchpoint_p
= 0;
5156 event
->regcache
= NULL
;
5161 case 'T': /* Status with PC, SP, FP, ... */
5162 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5163 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5165 n... = register number
5166 r... = register contents
5169 p
= &buf
[3]; /* after Txx */
5177 /* If the packet contains a register number, save it in
5178 pnum and set p1 to point to the character following it.
5179 Otherwise p1 points to p. */
5181 /* If this packet is an awatch packet, don't parse the 'a'
5182 as a register number. */
5184 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5185 && strncmp (p
, "core", strlen ("core") != 0))
5187 /* Read the ``P'' register number. */
5188 pnum
= strtol (p
, &p_temp
, 16);
5194 if (p1
== p
) /* No register number present here. */
5196 p1
= strchr (p
, ':');
5198 error (_("Malformed packet(a) (missing colon): %s\n\
5201 if (strncmp (p
, "thread", p1
- p
) == 0)
5202 event
->ptid
= read_ptid (++p1
, &p
);
5203 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5204 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5205 || (strncmp (p
, "awatch", p1
- p
) == 0))
5207 event
->stopped_by_watchpoint_p
= 1;
5208 p
= unpack_varlen_hex (++p1
, &addr
);
5209 event
->watch_data_address
= (CORE_ADDR
) addr
;
5211 else if (strncmp (p
, "library", p1
- p
) == 0)
5215 while (*p_temp
&& *p_temp
!= ';')
5218 event
->solibs_changed
= 1;
5221 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5223 /* NO_HISTORY event.
5224 p1 will indicate "begin" or "end", but
5225 it makes no difference for now, so ignore it. */
5226 event
->replay_event
= 1;
5227 p_temp
= strchr (p1
+ 1, ';');
5231 else if (strncmp (p
, "core", p1
- p
) == 0)
5235 p
= unpack_varlen_hex (++p1
, &c
);
5240 /* Silently skip unknown optional info. */
5241 p_temp
= strchr (p1
+ 1, ';');
5248 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5249 cached_reg_t cached_reg
;
5254 error (_("Malformed packet(b) (missing colon): %s\n\
5260 error (_("Remote sent bad register number %s: %s\n\
5262 hex_string (pnum
), p
, buf
);
5264 cached_reg
.num
= reg
->regnum
;
5266 fieldsize
= hex2bin (p
, cached_reg
.data
,
5267 register_size (target_gdbarch
,
5270 if (fieldsize
< register_size (target_gdbarch
,
5272 warning (_("Remote reply is too short: %s"), buf
);
5274 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5278 error (_("Remote register badly formatted: %s\nhere: %s"),
5283 case 'S': /* Old style status, just signal only. */
5284 if (event
->solibs_changed
)
5285 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5286 else if (event
->replay_event
)
5287 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5290 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5291 event
->ws
.value
.sig
= (enum target_signal
)
5292 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5295 case 'W': /* Target exited. */
5302 /* GDB used to accept only 2 hex chars here. Stubs should
5303 only send more if they detect GDB supports multi-process
5305 p
= unpack_varlen_hex (&buf
[1], &value
);
5309 /* The remote process exited. */
5310 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5311 event
->ws
.value
.integer
= value
;
5315 /* The remote process exited with a signal. */
5316 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5317 event
->ws
.value
.sig
= (enum target_signal
) value
;
5320 /* If no process is specified, assume inferior_ptid. */
5321 pid
= ptid_get_pid (inferior_ptid
);
5330 else if (strncmp (p
,
5331 "process:", sizeof ("process:") - 1) == 0)
5335 p
+= sizeof ("process:") - 1;
5336 unpack_varlen_hex (p
, &upid
);
5340 error (_("unknown stop reply packet: %s"), buf
);
5343 error (_("unknown stop reply packet: %s"), buf
);
5344 event
->ptid
= pid_to_ptid (pid
);
5349 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5350 error (_("No process or thread specified in stop reply: %s"), buf
);
5353 /* When the stub wants to tell GDB about a new stop reply, it sends a
5354 stop notification (%Stop). Those can come it at any time, hence,
5355 we have to make sure that any pending putpkt/getpkt sequence we're
5356 making is finished, before querying the stub for more events with
5357 vStopped. E.g., if we started a vStopped sequence immediatelly
5358 upon receiving the %Stop notification, something like this could
5366 1.6) <-- (registers reply to step #1.3)
5368 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5371 To solve this, whenever we parse a %Stop notification sucessfully,
5372 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5373 doing whatever we were doing:
5379 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5380 2.5) <-- (registers reply to step #2.3)
5382 Eventualy after step #2.5, we return to the event loop, which
5383 notices there's an event on the
5384 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5385 associated callback --- the function below. At this point, we're
5386 always safe to start a vStopped sequence. :
5389 2.7) <-- T05 thread:2
5395 remote_get_pending_stop_replies (void)
5397 struct remote_state
*rs
= get_remote_state ();
5399 if (pending_stop_reply
)
5402 putpkt ("vStopped");
5404 /* Now we can rely on it. */
5405 push_stop_reply (pending_stop_reply
);
5406 pending_stop_reply
= NULL
;
5410 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5411 if (strcmp (rs
->buf
, "OK") == 0)
5415 struct cleanup
*old_chain
;
5416 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5418 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5419 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5422 putpkt ("vStopped");
5424 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5426 /* Now we can rely on it. */
5427 discard_cleanups (old_chain
);
5428 push_stop_reply (stop_reply
);
5431 /* We got an unknown stop reply. */
5432 do_cleanups (old_chain
);
5439 /* Called when it is decided that STOP_REPLY holds the info of the
5440 event that is to be returned to the core. This function always
5441 destroys STOP_REPLY. */
5444 process_stop_reply (struct stop_reply
*stop_reply
,
5445 struct target_waitstatus
*status
)
5449 *status
= stop_reply
->ws
;
5450 ptid
= stop_reply
->ptid
;
5452 /* If no thread/process was reported by the stub, assume the current
5454 if (ptid_equal (ptid
, null_ptid
))
5455 ptid
= inferior_ptid
;
5457 if (status
->kind
!= TARGET_WAITKIND_EXITED
5458 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5460 /* Expedited registers. */
5461 if (stop_reply
->regcache
)
5463 struct regcache
*regcache
5464 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5469 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5471 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5472 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5475 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5476 remote_watch_data_address
= stop_reply
->watch_data_address
;
5478 remote_notice_new_inferior (ptid
, 0);
5479 demand_private_info (ptid
)->core
= stop_reply
->core
;
5482 stop_reply_xfree (stop_reply
);
5486 /* The non-stop mode version of target_wait. */
5489 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5491 struct remote_state
*rs
= get_remote_state ();
5492 struct stop_reply
*stop_reply
;
5495 /* If in non-stop mode, get out of getpkt even if a
5496 notification is received. */
5498 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5505 case 'E': /* Error of some sort. */
5506 /* We're out of sync with the target now. Did it continue
5507 or not? We can't tell which thread it was in non-stop,
5508 so just ignore this. */
5509 warning (_("Remote failure reply: %s"), rs
->buf
);
5511 case 'O': /* Console output. */
5512 remote_console_output (rs
->buf
+ 1);
5515 warning (_("Invalid remote reply: %s"), rs
->buf
);
5519 /* Acknowledge a pending stop reply that may have arrived in the
5521 if (pending_stop_reply
!= NULL
)
5522 remote_get_pending_stop_replies ();
5524 /* If indeed we noticed a stop reply, we're done. */
5525 stop_reply
= queued_stop_reply (ptid
);
5526 if (stop_reply
!= NULL
)
5527 return process_stop_reply (stop_reply
, status
);
5529 /* Still no event. If we're just polling for an event, then
5530 return to the event loop. */
5531 if (options
& TARGET_WNOHANG
)
5533 status
->kind
= TARGET_WAITKIND_IGNORE
;
5534 return minus_one_ptid
;
5537 /* Otherwise do a blocking wait. */
5538 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5543 /* Wait until the remote machine stops, then return, storing status in
5544 STATUS just as `wait' would. */
5547 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5549 struct remote_state
*rs
= get_remote_state ();
5550 ptid_t event_ptid
= null_ptid
;
5552 struct stop_reply
*stop_reply
;
5556 status
->kind
= TARGET_WAITKIND_IGNORE
;
5557 status
->value
.integer
= 0;
5559 stop_reply
= queued_stop_reply (ptid
);
5560 if (stop_reply
!= NULL
)
5561 return process_stop_reply (stop_reply
, status
);
5563 if (rs
->cached_wait_status
)
5564 /* Use the cached wait status, but only once. */
5565 rs
->cached_wait_status
= 0;
5570 if (!target_is_async_p ())
5572 ofunc
= signal (SIGINT
, remote_interrupt
);
5573 /* If the user hit C-c before this packet, or between packets,
5574 pretend that it was hit right here. */
5578 remote_interrupt (SIGINT
);
5582 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5583 _never_ wait for ever -> test on target_is_async_p().
5584 However, before we do that we need to ensure that the caller
5585 knows how to take the target into/out of async mode. */
5586 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5587 if (!target_is_async_p ())
5588 signal (SIGINT
, ofunc
);
5593 remote_stopped_by_watchpoint_p
= 0;
5595 /* We got something. */
5596 rs
->waiting_for_stop_reply
= 0;
5598 /* Assume that the target has acknowledged Ctrl-C unless we receive
5599 an 'F' or 'O' packet. */
5600 if (buf
[0] != 'F' && buf
[0] != 'O')
5601 rs
->ctrlc_pending_p
= 0;
5605 case 'E': /* Error of some sort. */
5606 /* We're out of sync with the target now. Did it continue or
5607 not? Not is more likely, so report a stop. */
5608 warning (_("Remote failure reply: %s"), buf
);
5609 status
->kind
= TARGET_WAITKIND_STOPPED
;
5610 status
->value
.sig
= TARGET_SIGNAL_0
;
5612 case 'F': /* File-I/O request. */
5613 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5614 rs
->ctrlc_pending_p
= 0;
5616 case 'T': case 'S': case 'X': case 'W':
5618 struct stop_reply
*stop_reply
;
5619 struct cleanup
*old_chain
;
5621 stop_reply
= stop_reply_xmalloc ();
5622 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5623 remote_parse_stop_reply (buf
, stop_reply
);
5624 discard_cleanups (old_chain
);
5625 event_ptid
= process_stop_reply (stop_reply
, status
);
5628 case 'O': /* Console output. */
5629 remote_console_output (buf
+ 1);
5631 /* The target didn't really stop; keep waiting. */
5632 rs
->waiting_for_stop_reply
= 1;
5636 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5638 /* Zero length reply means that we tried 'S' or 'C' and the
5639 remote system doesn't support it. */
5640 target_terminal_ours_for_output ();
5642 ("Can't send signals to this remote system. %s not sent.\n",
5643 target_signal_to_name (last_sent_signal
));
5644 last_sent_signal
= TARGET_SIGNAL_0
;
5645 target_terminal_inferior ();
5647 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5648 putpkt ((char *) buf
);
5650 /* We just told the target to resume, so a stop reply is in
5652 rs
->waiting_for_stop_reply
= 1;
5655 /* else fallthrough */
5657 warning (_("Invalid remote reply: %s"), buf
);
5659 rs
->waiting_for_stop_reply
= 1;
5663 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5665 /* Nothing interesting happened. If we're doing a non-blocking
5666 poll, we're done. Otherwise, go back to waiting. */
5667 if (options
& TARGET_WNOHANG
)
5668 return minus_one_ptid
;
5672 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5673 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5675 if (!ptid_equal (event_ptid
, null_ptid
))
5676 record_currthread (event_ptid
);
5678 event_ptid
= inferior_ptid
;
5681 /* A process exit. Invalidate our notion of current thread. */
5682 record_currthread (minus_one_ptid
);
5687 /* Wait until the remote machine stops, then return, storing status in
5688 STATUS just as `wait' would. */
5691 remote_wait (struct target_ops
*ops
,
5692 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5697 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5699 event_ptid
= remote_wait_as (ptid
, status
, options
);
5701 if (target_can_async_p ())
5703 /* If there are are events left in the queue tell the event loop
5705 if (stop_reply_queue
)
5706 mark_async_event_handler (remote_async_inferior_event_token
);
5712 /* Fetch a single register using a 'p' packet. */
5715 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5717 struct remote_state
*rs
= get_remote_state ();
5719 char regp
[MAX_REGISTER_SIZE
];
5722 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5725 if (reg
->pnum
== -1)
5730 p
+= hexnumstr (p
, reg
->pnum
);
5733 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5737 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5741 case PACKET_UNKNOWN
:
5744 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5745 gdbarch_register_name (get_regcache_arch (regcache
),
5750 /* If this register is unfetchable, tell the regcache. */
5753 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5757 /* Otherwise, parse and supply the value. */
5763 error (_("fetch_register_using_p: early buf termination"));
5765 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5768 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5772 /* Fetch the registers included in the target's 'g' packet. */
5775 send_g_packet (void)
5777 struct remote_state
*rs
= get_remote_state ();
5780 sprintf (rs
->buf
, "g");
5781 remote_send (&rs
->buf
, &rs
->buf_size
);
5783 /* We can get out of synch in various cases. If the first character
5784 in the buffer is not a hex character, assume that has happened
5785 and try to fetch another packet to read. */
5786 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5787 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5788 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5789 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5792 fprintf_unfiltered (gdb_stdlog
,
5793 "Bad register packet; fetching a new packet\n");
5794 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5797 buf_len
= strlen (rs
->buf
);
5799 /* Sanity check the received packet. */
5800 if (buf_len
% 2 != 0)
5801 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5807 process_g_packet (struct regcache
*regcache
)
5809 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5810 struct remote_state
*rs
= get_remote_state ();
5811 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5816 buf_len
= strlen (rs
->buf
);
5818 /* Further sanity checks, with knowledge of the architecture. */
5819 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5820 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5822 /* Save the size of the packet sent to us by the target. It is used
5823 as a heuristic when determining the max size of packets that the
5824 target can safely receive. */
5825 if (rsa
->actual_register_packet_size
== 0)
5826 rsa
->actual_register_packet_size
= buf_len
;
5828 /* If this is smaller than we guessed the 'g' packet would be,
5829 update our records. A 'g' reply that doesn't include a register's
5830 value implies either that the register is not available, or that
5831 the 'p' packet must be used. */
5832 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5834 rsa
->sizeof_g_packet
= buf_len
/ 2;
5836 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5838 if (rsa
->regs
[i
].pnum
== -1)
5841 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5842 rsa
->regs
[i
].in_g_packet
= 0;
5844 rsa
->regs
[i
].in_g_packet
= 1;
5848 regs
= alloca (rsa
->sizeof_g_packet
);
5850 /* Unimplemented registers read as all bits zero. */
5851 memset (regs
, 0, rsa
->sizeof_g_packet
);
5853 /* Reply describes registers byte by byte, each byte encoded as two
5854 hex characters. Suck them all up, then supply them to the
5855 register cacheing/storage mechanism. */
5858 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5860 if (p
[0] == 0 || p
[1] == 0)
5861 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5862 internal_error (__FILE__
, __LINE__
,
5863 _("unexpected end of 'g' packet reply"));
5865 if (p
[0] == 'x' && p
[1] == 'x')
5866 regs
[i
] = 0; /* 'x' */
5868 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5872 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5874 struct packet_reg
*r
= &rsa
->regs
[i
];
5878 if (r
->offset
* 2 >= strlen (rs
->buf
))
5879 /* This shouldn't happen - we adjusted in_g_packet above. */
5880 internal_error (__FILE__
, __LINE__
,
5881 _("unexpected end of 'g' packet reply"));
5882 else if (rs
->buf
[r
->offset
* 2] == 'x')
5884 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5885 /* The register isn't available, mark it as such (at
5886 the same time setting the value to zero). */
5887 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5890 regcache_raw_supply (regcache
, r
->regnum
,
5897 fetch_registers_using_g (struct regcache
*regcache
)
5900 process_g_packet (regcache
);
5903 /* Make the remote selected traceframe match GDB's selected
5907 set_remote_traceframe (void)
5911 if (remote_traceframe_number
== get_traceframe_number ())
5914 /* Avoid recursion, remote_trace_find calls us again. */
5915 remote_traceframe_number
= get_traceframe_number ();
5917 newnum
= target_trace_find (tfind_number
,
5918 get_traceframe_number (), 0, 0, NULL
);
5920 /* Should not happen. If it does, all bets are off. */
5921 if (newnum
!= get_traceframe_number ())
5922 warning (_("could not set remote traceframe"));
5926 remote_fetch_registers (struct target_ops
*ops
,
5927 struct regcache
*regcache
, int regnum
)
5929 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5932 set_remote_traceframe ();
5933 set_general_thread (inferior_ptid
);
5937 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5939 gdb_assert (reg
!= NULL
);
5941 /* If this register might be in the 'g' packet, try that first -
5942 we are likely to read more than one register. If this is the
5943 first 'g' packet, we might be overly optimistic about its
5944 contents, so fall back to 'p'. */
5945 if (reg
->in_g_packet
)
5947 fetch_registers_using_g (regcache
);
5948 if (reg
->in_g_packet
)
5952 if (fetch_register_using_p (regcache
, reg
))
5955 /* This register is not available. */
5956 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5961 fetch_registers_using_g (regcache
);
5963 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5964 if (!rsa
->regs
[i
].in_g_packet
)
5965 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5967 /* This register is not available. */
5968 regcache_raw_supply (regcache
, i
, NULL
);
5972 /* Prepare to store registers. Since we may send them all (using a
5973 'G' request), we have to read out the ones we don't want to change
5977 remote_prepare_to_store (struct regcache
*regcache
)
5979 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5981 gdb_byte buf
[MAX_REGISTER_SIZE
];
5983 /* Make sure the entire registers array is valid. */
5984 switch (remote_protocol_packets
[PACKET_P
].support
)
5986 case PACKET_DISABLE
:
5987 case PACKET_SUPPORT_UNKNOWN
:
5988 /* Make sure all the necessary registers are cached. */
5989 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5990 if (rsa
->regs
[i
].in_g_packet
)
5991 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5998 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5999 packet was not recognized. */
6002 store_register_using_P (const struct regcache
*regcache
,
6003 struct packet_reg
*reg
)
6005 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6006 struct remote_state
*rs
= get_remote_state ();
6007 /* Try storing a single register. */
6008 char *buf
= rs
->buf
;
6009 gdb_byte regp
[MAX_REGISTER_SIZE
];
6012 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6015 if (reg
->pnum
== -1)
6018 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6019 p
= buf
+ strlen (buf
);
6020 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6021 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6023 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6025 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6030 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6031 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6032 case PACKET_UNKNOWN
:
6035 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6039 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6040 contents of the register cache buffer. FIXME: ignores errors. */
6043 store_registers_using_G (const struct regcache
*regcache
)
6045 struct remote_state
*rs
= get_remote_state ();
6046 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6050 /* Extract all the registers in the regcache copying them into a
6055 regs
= alloca (rsa
->sizeof_g_packet
);
6056 memset (regs
, 0, rsa
->sizeof_g_packet
);
6057 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6059 struct packet_reg
*r
= &rsa
->regs
[i
];
6062 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6066 /* Command describes registers byte by byte,
6067 each byte encoded as two hex characters. */
6070 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6072 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6074 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6075 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6076 error (_("Could not write registers; remote failure reply '%s'"),
6080 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6081 of the register cache buffer. FIXME: ignores errors. */
6084 remote_store_registers (struct target_ops
*ops
,
6085 struct regcache
*regcache
, int regnum
)
6087 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6090 set_remote_traceframe ();
6091 set_general_thread (inferior_ptid
);
6095 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6097 gdb_assert (reg
!= NULL
);
6099 /* Always prefer to store registers using the 'P' packet if
6100 possible; we often change only a small number of registers.
6101 Sometimes we change a larger number; we'd need help from a
6102 higher layer to know to use 'G'. */
6103 if (store_register_using_P (regcache
, reg
))
6106 /* For now, don't complain if we have no way to write the
6107 register. GDB loses track of unavailable registers too
6108 easily. Some day, this may be an error. We don't have
6109 any way to read the register, either... */
6110 if (!reg
->in_g_packet
)
6113 store_registers_using_G (regcache
);
6117 store_registers_using_G (regcache
);
6119 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6120 if (!rsa
->regs
[i
].in_g_packet
)
6121 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6122 /* See above for why we do not issue an error here. */
6127 /* Return the number of hex digits in num. */
6130 hexnumlen (ULONGEST num
)
6134 for (i
= 0; num
!= 0; i
++)
6140 /* Set BUF to the minimum number of hex digits representing NUM. */
6143 hexnumstr (char *buf
, ULONGEST num
)
6145 int len
= hexnumlen (num
);
6147 return hexnumnstr (buf
, num
, len
);
6151 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6154 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6160 for (i
= width
- 1; i
>= 0; i
--)
6162 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6169 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6172 remote_address_masked (CORE_ADDR addr
)
6174 int address_size
= remote_address_size
;
6176 /* If "remoteaddresssize" was not set, default to target address size. */
6178 address_size
= gdbarch_addr_bit (target_gdbarch
);
6180 if (address_size
> 0
6181 && address_size
< (sizeof (ULONGEST
) * 8))
6183 /* Only create a mask when that mask can safely be constructed
6184 in a ULONGEST variable. */
6187 mask
= (mask
<< address_size
) - 1;
6193 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6194 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6195 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6196 (which may be more than *OUT_LEN due to escape characters). The
6197 total number of bytes in the output buffer will be at most
6201 remote_escape_output (const gdb_byte
*buffer
, int len
,
6202 gdb_byte
*out_buf
, int *out_len
,
6205 int input_index
, output_index
;
6208 for (input_index
= 0; input_index
< len
; input_index
++)
6210 gdb_byte b
= buffer
[input_index
];
6212 if (b
== '$' || b
== '#' || b
== '}')
6214 /* These must be escaped. */
6215 if (output_index
+ 2 > out_maxlen
)
6217 out_buf
[output_index
++] = '}';
6218 out_buf
[output_index
++] = b
^ 0x20;
6222 if (output_index
+ 1 > out_maxlen
)
6224 out_buf
[output_index
++] = b
;
6228 *out_len
= input_index
;
6229 return output_index
;
6232 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6233 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6234 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6236 This function reverses remote_escape_output. It allows more
6237 escaped characters than that function does, in particular because
6238 '*' must be escaped to avoid the run-length encoding processing
6239 in reading packets. */
6242 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6243 gdb_byte
*out_buf
, int out_maxlen
)
6245 int input_index
, output_index
;
6250 for (input_index
= 0; input_index
< len
; input_index
++)
6252 gdb_byte b
= buffer
[input_index
];
6254 if (output_index
+ 1 > out_maxlen
)
6256 warning (_("Received too much data from remote target;"
6257 " ignoring overflow."));
6258 return output_index
;
6263 out_buf
[output_index
++] = b
^ 0x20;
6269 out_buf
[output_index
++] = b
;
6273 error (_("Unmatched escape character in target response."));
6275 return output_index
;
6278 /* Determine whether the remote target supports binary downloading.
6279 This is accomplished by sending a no-op memory write of zero length
6280 to the target at the specified address. It does not suffice to send
6281 the whole packet, since many stubs strip the eighth bit and
6282 subsequently compute a wrong checksum, which causes real havoc with
6285 NOTE: This can still lose if the serial line is not eight-bit
6286 clean. In cases like this, the user should clear "remote
6290 check_binary_download (CORE_ADDR addr
)
6292 struct remote_state
*rs
= get_remote_state ();
6294 switch (remote_protocol_packets
[PACKET_X
].support
)
6296 case PACKET_DISABLE
:
6300 case PACKET_SUPPORT_UNKNOWN
:
6306 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6308 p
+= hexnumstr (p
, (ULONGEST
) 0);
6312 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6313 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6315 if (rs
->buf
[0] == '\0')
6318 fprintf_unfiltered (gdb_stdlog
,
6319 "binary downloading NOT "
6320 "supported by target\n");
6321 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6326 fprintf_unfiltered (gdb_stdlog
,
6327 "binary downloading supported by target\n");
6328 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6335 /* Write memory data directly to the remote machine.
6336 This does not inform the data cache; the data cache uses this.
6337 HEADER is the starting part of the packet.
6338 MEMADDR is the address in the remote memory space.
6339 MYADDR is the address of the buffer in our space.
6340 LEN is the number of bytes.
6341 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6342 should send data as binary ('X'), or hex-encoded ('M').
6344 The function creates packet of the form
6345 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6347 where encoding of <DATA> is termined by PACKET_FORMAT.
6349 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6352 Returns the number of bytes transferred, or 0 (setting errno) for
6353 error. Only transfer a single packet. */
6356 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6357 const gdb_byte
*myaddr
, int len
,
6358 char packet_format
, int use_length
)
6360 struct remote_state
*rs
= get_remote_state ();
6370 if (packet_format
!= 'X' && packet_format
!= 'M')
6371 internal_error (__FILE__
, __LINE__
,
6372 _("remote_write_bytes_aux: bad packet format"));
6377 payload_size
= get_memory_write_packet_size ();
6379 /* The packet buffer will be large enough for the payload;
6380 get_memory_packet_size ensures this. */
6383 /* Compute the size of the actual payload by subtracting out the
6384 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6386 payload_size
-= strlen ("$,:#NN");
6388 /* The comma won't be used. */
6390 header_length
= strlen (header
);
6391 payload_size
-= header_length
;
6392 payload_size
-= hexnumlen (memaddr
);
6394 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6396 strcat (rs
->buf
, header
);
6397 p
= rs
->buf
+ strlen (header
);
6399 /* Compute a best guess of the number of bytes actually transfered. */
6400 if (packet_format
== 'X')
6402 /* Best guess at number of bytes that will fit. */
6403 todo
= min (len
, payload_size
);
6405 payload_size
-= hexnumlen (todo
);
6406 todo
= min (todo
, payload_size
);
6410 /* Num bytes that will fit. */
6411 todo
= min (len
, payload_size
/ 2);
6413 payload_size
-= hexnumlen (todo
);
6414 todo
= min (todo
, payload_size
/ 2);
6418 internal_error (__FILE__
, __LINE__
,
6419 _("minimum packet size too small to write data"));
6421 /* If we already need another packet, then try to align the end
6422 of this packet to a useful boundary. */
6423 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6424 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6426 /* Append "<memaddr>". */
6427 memaddr
= remote_address_masked (memaddr
);
6428 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6435 /* Append <len>. Retain the location/size of <len>. It may need to
6436 be adjusted once the packet body has been created. */
6438 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6446 /* Append the packet body. */
6447 if (packet_format
== 'X')
6449 /* Binary mode. Send target system values byte by byte, in
6450 increasing byte addresses. Only escape certain critical
6452 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6455 /* If not all TODO bytes fit, then we'll need another packet. Make
6456 a second try to keep the end of the packet aligned. Don't do
6457 this if the packet is tiny. */
6458 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6462 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6464 if (new_nr_bytes
!= nr_bytes
)
6465 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6470 p
+= payload_length
;
6471 if (use_length
&& nr_bytes
< todo
)
6473 /* Escape chars have filled up the buffer prematurely,
6474 and we have actually sent fewer bytes than planned.
6475 Fix-up the length field of the packet. Use the same
6476 number of characters as before. */
6477 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6478 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6483 /* Normal mode: Send target system values byte by byte, in
6484 increasing byte addresses. Each byte is encoded as a two hex
6486 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6490 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6491 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6493 if (rs
->buf
[0] == 'E')
6495 /* There is no correspondance between what the remote protocol
6496 uses for errors and errno codes. We would like a cleaner way
6497 of representing errors (big enough to include errno codes,
6498 bfd_error codes, and others). But for now just return EIO. */
6503 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6504 fewer bytes than we'd planned. */
6508 /* Write memory data directly to the remote machine.
6509 This does not inform the data cache; the data cache uses this.
6510 MEMADDR is the address in the remote memory space.
6511 MYADDR is the address of the buffer in our space.
6512 LEN is the number of bytes.
6514 Returns number of bytes transferred, or 0 (setting errno) for
6515 error. Only transfer a single packet. */
6518 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6520 char *packet_format
= 0;
6522 /* Check whether the target supports binary download. */
6523 check_binary_download (memaddr
);
6525 switch (remote_protocol_packets
[PACKET_X
].support
)
6528 packet_format
= "X";
6530 case PACKET_DISABLE
:
6531 packet_format
= "M";
6533 case PACKET_SUPPORT_UNKNOWN
:
6534 internal_error (__FILE__
, __LINE__
,
6535 _("remote_write_bytes: bad internal state"));
6537 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6540 return remote_write_bytes_aux (packet_format
,
6541 memaddr
, myaddr
, len
, packet_format
[0], 1);
6544 /* Read memory data directly from the remote machine.
6545 This does not use the data cache; the data cache uses this.
6546 MEMADDR is the address in the remote memory space.
6547 MYADDR is the address of the buffer in our space.
6548 LEN is the number of bytes.
6550 Returns number of bytes transferred, or 0 for error. */
6553 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6555 struct remote_state
*rs
= get_remote_state ();
6556 int max_buf_size
; /* Max size of packet output buffer. */
6564 max_buf_size
= get_memory_read_packet_size ();
6565 /* The packet buffer will be large enough for the payload;
6566 get_memory_packet_size ensures this. */
6568 /* Number if bytes that will fit. */
6569 todo
= min (len
, max_buf_size
/ 2);
6571 /* Construct "m"<memaddr>","<len>". */
6572 memaddr
= remote_address_masked (memaddr
);
6575 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6577 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6580 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6581 if (rs
->buf
[0] == 'E'
6582 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6583 && rs
->buf
[3] == '\0')
6585 /* There is no correspondance between what the remote protocol
6586 uses for errors and errno codes. We would like a cleaner way
6587 of representing errors (big enough to include errno codes,
6588 bfd_error codes, and others). But for now just return
6593 /* Reply describes memory byte by byte, each byte encoded as two hex
6596 i
= hex2bin (p
, myaddr
, todo
);
6597 /* Return what we have. Let higher layers handle partial reads. */
6602 /* Remote notification handler. */
6605 handle_notification (char *buf
, size_t length
)
6607 if (strncmp (buf
, "Stop:", 5) == 0)
6609 if (pending_stop_reply
)
6611 /* We've already parsed the in-flight stop-reply, but the
6612 stub for some reason thought we didn't, possibly due to
6613 timeout on its side. Just ignore it. */
6615 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6619 struct cleanup
*old_chain
;
6620 struct stop_reply
*reply
= stop_reply_xmalloc ();
6622 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6624 remote_parse_stop_reply (buf
+ 5, reply
);
6626 discard_cleanups (old_chain
);
6628 /* Be careful to only set it after parsing, since an error
6629 may be thrown then. */
6630 pending_stop_reply
= reply
;
6632 /* Notify the event loop there's a stop reply to acknowledge
6633 and that there may be more events to fetch. */
6634 mark_async_event_handler (remote_async_get_pending_events_token
);
6637 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6641 /* We ignore notifications we don't recognize, for compatibility
6642 with newer stubs. */
6647 /* Read or write LEN bytes from inferior memory at MEMADDR,
6648 transferring to or from debugger address BUFFER. Write to inferior
6649 if SHOULD_WRITE is nonzero. Returns length of data written or
6650 read; 0 for error. TARGET is unused. */
6653 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6654 int should_write
, struct mem_attrib
*attrib
,
6655 struct target_ops
*target
)
6659 set_remote_traceframe ();
6660 set_general_thread (inferior_ptid
);
6663 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6665 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6670 /* Sends a packet with content determined by the printf format string
6671 FORMAT and the remaining arguments, then gets the reply. Returns
6672 whether the packet was a success, a failure, or unknown. */
6674 static enum packet_result
6675 remote_send_printf (const char *format
, ...)
6677 struct remote_state
*rs
= get_remote_state ();
6678 int max_size
= get_remote_packet_size ();
6681 va_start (ap
, format
);
6684 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6685 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6687 if (putpkt (rs
->buf
) < 0)
6688 error (_("Communication problem with target."));
6691 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6693 return packet_check_result (rs
->buf
);
6697 restore_remote_timeout (void *p
)
6699 int value
= *(int *)p
;
6701 remote_timeout
= value
;
6704 /* Flash writing can take quite some time. We'll set
6705 effectively infinite timeout for flash operations.
6706 In future, we'll need to decide on a better approach. */
6707 static const int remote_flash_timeout
= 1000;
6710 remote_flash_erase (struct target_ops
*ops
,
6711 ULONGEST address
, LONGEST length
)
6713 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6714 int saved_remote_timeout
= remote_timeout
;
6715 enum packet_result ret
;
6716 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6717 &saved_remote_timeout
);
6719 remote_timeout
= remote_flash_timeout
;
6721 ret
= remote_send_printf ("vFlashErase:%s,%s",
6722 phex (address
, addr_size
),
6726 case PACKET_UNKNOWN
:
6727 error (_("Remote target does not support flash erase"));
6729 error (_("Error erasing flash with vFlashErase packet"));
6734 do_cleanups (back_to
);
6738 remote_flash_write (struct target_ops
*ops
,
6739 ULONGEST address
, LONGEST length
,
6740 const gdb_byte
*data
)
6742 int saved_remote_timeout
= remote_timeout
;
6744 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6745 &saved_remote_timeout
);
6747 remote_timeout
= remote_flash_timeout
;
6748 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6749 do_cleanups (back_to
);
6755 remote_flash_done (struct target_ops
*ops
)
6757 int saved_remote_timeout
= remote_timeout
;
6759 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6760 &saved_remote_timeout
);
6762 remote_timeout
= remote_flash_timeout
;
6763 ret
= remote_send_printf ("vFlashDone");
6764 do_cleanups (back_to
);
6768 case PACKET_UNKNOWN
:
6769 error (_("Remote target does not support vFlashDone"));
6771 error (_("Error finishing flash operation"));
6778 remote_files_info (struct target_ops
*ignore
)
6780 puts_filtered ("Debugging a target over a serial line.\n");
6783 /* Stuff for dealing with the packets which are part of this protocol.
6784 See comment at top of file for details. */
6786 /* Read a single character from the remote end. */
6789 readchar (int timeout
)
6793 ch
= serial_readchar (remote_desc
, timeout
);
6798 switch ((enum serial_rc
) ch
)
6802 error (_("Remote connection closed"));
6806 perror_with_name (_("Remote communication error. "
6807 "Target disconnected."));
6809 case SERIAL_TIMEOUT
:
6815 /* Send the command in *BUF to the remote machine, and read the reply
6816 into *BUF. Report an error if we get an error reply. Resize
6817 *BUF using xrealloc if necessary to hold the result, and update
6821 remote_send (char **buf
,
6825 getpkt (buf
, sizeof_buf
, 0);
6827 if ((*buf
)[0] == 'E')
6828 error (_("Remote failure reply: %s"), *buf
);
6831 /* Return a pointer to an xmalloc'ed string representing an escaped
6832 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6833 etc. The caller is responsible for releasing the returned
6837 escape_buffer (const char *buf
, int n
)
6839 struct cleanup
*old_chain
;
6840 struct ui_file
*stb
;
6843 stb
= mem_fileopen ();
6844 old_chain
= make_cleanup_ui_file_delete (stb
);
6846 fputstrn_unfiltered (buf
, n
, 0, stb
);
6847 str
= ui_file_xstrdup (stb
, NULL
);
6848 do_cleanups (old_chain
);
6852 /* Display a null-terminated packet on stdout, for debugging, using C
6856 print_packet (char *buf
)
6858 puts_filtered ("\"");
6859 fputstr_filtered (buf
, '"', gdb_stdout
);
6860 puts_filtered ("\"");
6866 return putpkt_binary (buf
, strlen (buf
));
6869 /* Send a packet to the remote machine, with error checking. The data
6870 of the packet is in BUF. The string in BUF can be at most
6871 get_remote_packet_size () - 5 to account for the $, # and checksum,
6872 and for a possible /0 if we are debugging (remote_debug) and want
6873 to print the sent packet as a string. */
6876 putpkt_binary (char *buf
, int cnt
)
6878 struct remote_state
*rs
= get_remote_state ();
6880 unsigned char csum
= 0;
6881 char *buf2
= alloca (cnt
+ 6);
6887 /* Catch cases like trying to read memory or listing threads while
6888 we're waiting for a stop reply. The remote server wouldn't be
6889 ready to handle this request, so we'd hang and timeout. We don't
6890 have to worry about this in synchronous mode, because in that
6891 case it's not possible to issue a command while the target is
6892 running. This is not a problem in non-stop mode, because in that
6893 case, the stub is always ready to process serial input. */
6894 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6895 error (_("Cannot execute this command while the target is running."));
6897 /* We're sending out a new packet. Make sure we don't look at a
6898 stale cached response. */
6899 rs
->cached_wait_status
= 0;
6901 /* Copy the packet into buffer BUF2, encapsulating it
6902 and giving it a checksum. */
6907 for (i
= 0; i
< cnt
; i
++)
6913 *p
++ = tohex ((csum
>> 4) & 0xf);
6914 *p
++ = tohex (csum
& 0xf);
6916 /* Send it over and over until we get a positive ack. */
6920 int started_error_output
= 0;
6924 struct cleanup
*old_chain
;
6928 str
= escape_buffer (buf2
, p
- buf2
);
6929 old_chain
= make_cleanup (xfree
, str
);
6930 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6931 gdb_flush (gdb_stdlog
);
6932 do_cleanups (old_chain
);
6934 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6935 perror_with_name (_("putpkt: write failed"));
6937 /* If this is a no acks version of the remote protocol, send the
6938 packet and move on. */
6942 /* Read until either a timeout occurs (-2) or '+' is read.
6943 Handle any notification that arrives in the mean time. */
6946 ch
= readchar (remote_timeout
);
6954 case SERIAL_TIMEOUT
:
6957 if (started_error_output
)
6959 putchar_unfiltered ('\n');
6960 started_error_output
= 0;
6969 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6973 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6975 case SERIAL_TIMEOUT
:
6979 break; /* Retransmit buffer. */
6983 fprintf_unfiltered (gdb_stdlog
,
6984 "Packet instead of Ack, ignoring it\n");
6985 /* It's probably an old response sent because an ACK
6986 was lost. Gobble up the packet and ack it so it
6987 doesn't get retransmitted when we resend this
6990 serial_write (remote_desc
, "+", 1);
6991 continue; /* Now, go look for +. */
6998 /* If we got a notification, handle it, and go back to looking
7000 /* We've found the start of a notification. Now
7001 collect the data. */
7002 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7007 struct cleanup
*old_chain
;
7010 str
= escape_buffer (rs
->buf
, val
);
7011 old_chain
= make_cleanup (xfree
, str
);
7012 fprintf_unfiltered (gdb_stdlog
,
7013 " Notification received: %s\n",
7015 do_cleanups (old_chain
);
7017 handle_notification (rs
->buf
, val
);
7018 /* We're in sync now, rewait for the ack. */
7025 if (!started_error_output
)
7027 started_error_output
= 1;
7028 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7030 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7031 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7040 if (!started_error_output
)
7042 started_error_output
= 1;
7043 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7045 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7049 break; /* Here to retransmit. */
7053 /* This is wrong. If doing a long backtrace, the user should be
7054 able to get out next time we call QUIT, without anything as
7055 violent as interrupt_query. If we want to provide a way out of
7056 here without getting to the next QUIT, it should be based on
7057 hitting ^C twice as in remote_wait. */
7068 /* Come here after finding the start of a frame when we expected an
7069 ack. Do our best to discard the rest of this packet. */
7078 c
= readchar (remote_timeout
);
7081 case SERIAL_TIMEOUT
:
7082 /* Nothing we can do. */
7085 /* Discard the two bytes of checksum and stop. */
7086 c
= readchar (remote_timeout
);
7088 c
= readchar (remote_timeout
);
7091 case '*': /* Run length encoding. */
7092 /* Discard the repeat count. */
7093 c
= readchar (remote_timeout
);
7098 /* A regular character. */
7104 /* Come here after finding the start of the frame. Collect the rest
7105 into *BUF, verifying the checksum, length, and handling run-length
7106 compression. NUL terminate the buffer. If there is not enough room,
7107 expand *BUF using xrealloc.
7109 Returns -1 on error, number of characters in buffer (ignoring the
7110 trailing NULL) on success. (could be extended to return one of the
7111 SERIAL status indications). */
7114 read_frame (char **buf_p
,
7121 struct remote_state
*rs
= get_remote_state ();
7128 c
= readchar (remote_timeout
);
7131 case SERIAL_TIMEOUT
:
7133 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7137 fputs_filtered ("Saw new packet start in middle of old one\n",
7139 return -1; /* Start a new packet, count retries. */
7142 unsigned char pktcsum
;
7148 check_0
= readchar (remote_timeout
);
7150 check_1
= readchar (remote_timeout
);
7152 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7155 fputs_filtered ("Timeout in checksum, retrying\n",
7159 else if (check_0
< 0 || check_1
< 0)
7162 fputs_filtered ("Communication error in checksum\n",
7167 /* Don't recompute the checksum; with no ack packets we
7168 don't have any way to indicate a packet retransmission
7173 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7174 if (csum
== pktcsum
)
7179 struct cleanup
*old_chain
;
7182 str
= escape_buffer (buf
, bc
);
7183 old_chain
= make_cleanup (xfree
, str
);
7184 fprintf_unfiltered (gdb_stdlog
,
7185 "Bad checksum, sentsum=0x%x, "
7186 "csum=0x%x, buf=%s\n",
7187 pktcsum
, csum
, str
);
7188 do_cleanups (old_chain
);
7190 /* Number of characters in buffer ignoring trailing
7194 case '*': /* Run length encoding. */
7199 c
= readchar (remote_timeout
);
7201 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7203 /* The character before ``*'' is repeated. */
7205 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7207 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7209 /* Make some more room in the buffer. */
7210 *sizeof_buf
+= repeat
;
7211 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7215 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7221 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7225 if (bc
>= *sizeof_buf
- 1)
7227 /* Make some more room in the buffer. */
7229 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7240 /* Read a packet from the remote machine, with error checking, and
7241 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7242 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7243 rather than timing out; this is used (in synchronous mode) to wait
7244 for a target that is is executing user code to stop. */
7245 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7246 don't have to change all the calls to getpkt to deal with the
7247 return value, because at the moment I don't know what the right
7248 thing to do it for those. */
7256 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7260 /* Read a packet from the remote machine, with error checking, and
7261 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7262 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7263 rather than timing out; this is used (in synchronous mode) to wait
7264 for a target that is is executing user code to stop. If FOREVER ==
7265 0, this function is allowed to time out gracefully and return an
7266 indication of this to the caller. Otherwise return the number of
7267 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7268 enough reason to return to the caller. */
7271 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7272 int expecting_notif
)
7274 struct remote_state
*rs
= get_remote_state ();
7280 /* We're reading a new response. Make sure we don't look at a
7281 previously cached response. */
7282 rs
->cached_wait_status
= 0;
7284 strcpy (*buf
, "timeout");
7287 timeout
= watchdog
> 0 ? watchdog
: -1;
7288 else if (expecting_notif
)
7289 timeout
= 0; /* There should already be a char in the buffer. If
7292 timeout
= remote_timeout
;
7296 /* Process any number of notifications, and then return when
7300 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7302 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7304 /* This can loop forever if the remote side sends us
7305 characters continuously, but if it pauses, we'll get
7306 SERIAL_TIMEOUT from readchar because of timeout. Then
7307 we'll count that as a retry.
7309 Note that even when forever is set, we will only wait
7310 forever prior to the start of a packet. After that, we
7311 expect characters to arrive at a brisk pace. They should
7312 show up within remote_timeout intervals. */
7314 c
= readchar (timeout
);
7315 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7317 if (c
== SERIAL_TIMEOUT
)
7319 if (expecting_notif
)
7320 return -1; /* Don't complain, it's normal to not get
7321 anything in this case. */
7323 if (forever
) /* Watchdog went off? Kill the target. */
7327 error (_("Watchdog timeout has expired. Target detached."));
7330 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7334 /* We've found the start of a packet or notification.
7335 Now collect the data. */
7336 val
= read_frame (buf
, sizeof_buf
);
7341 serial_write (remote_desc
, "-", 1);
7344 if (tries
> MAX_TRIES
)
7346 /* We have tried hard enough, and just can't receive the
7347 packet/notification. Give up. */
7348 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7350 /* Skip the ack char if we're in no-ack mode. */
7351 if (!rs
->noack_mode
)
7352 serial_write (remote_desc
, "+", 1);
7356 /* If we got an ordinary packet, return that to our caller. */
7361 struct cleanup
*old_chain
;
7364 str
= escape_buffer (*buf
, val
);
7365 old_chain
= make_cleanup (xfree
, str
);
7366 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7367 do_cleanups (old_chain
);
7370 /* Skip the ack char if we're in no-ack mode. */
7371 if (!rs
->noack_mode
)
7372 serial_write (remote_desc
, "+", 1);
7376 /* If we got a notification, handle it, and go back to looking
7380 gdb_assert (c
== '%');
7384 struct cleanup
*old_chain
;
7387 str
= escape_buffer (*buf
, val
);
7388 old_chain
= make_cleanup (xfree
, str
);
7389 fprintf_unfiltered (gdb_stdlog
,
7390 " Notification received: %s\n",
7392 do_cleanups (old_chain
);
7395 handle_notification (*buf
, val
);
7397 /* Notifications require no acknowledgement. */
7399 if (expecting_notif
)
7406 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7408 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7412 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7414 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7418 /* A helper function that just calls putpkt; for type correctness. */
7421 putpkt_for_catch_errors (void *arg
)
7423 return putpkt (arg
);
7427 remote_kill (struct target_ops
*ops
)
7429 /* Use catch_errors so the user can quit from gdb even when we
7430 aren't on speaking terms with the remote system. */
7431 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7433 /* Don't wait for it to die. I'm not really sure it matters whether
7434 we do or not. For the existing stubs, kill is a noop. */
7435 target_mourn_inferior ();
7439 remote_vkill (int pid
, struct remote_state
*rs
)
7441 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7444 /* Tell the remote target to detach. */
7445 sprintf (rs
->buf
, "vKill;%x", pid
);
7447 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7449 if (packet_ok (rs
->buf
,
7450 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7452 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7459 extended_remote_kill (struct target_ops
*ops
)
7462 int pid
= ptid_get_pid (inferior_ptid
);
7463 struct remote_state
*rs
= get_remote_state ();
7465 res
= remote_vkill (pid
, rs
);
7466 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7468 /* Don't try 'k' on a multi-process aware stub -- it has no way
7469 to specify the pid. */
7473 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7474 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7477 /* Don't wait for it to die. I'm not really sure it matters whether
7478 we do or not. For the existing stubs, kill is a noop. */
7484 error (_("Can't kill process"));
7486 target_mourn_inferior ();
7490 remote_mourn (struct target_ops
*ops
)
7492 remote_mourn_1 (ops
);
7495 /* Worker function for remote_mourn. */
7497 remote_mourn_1 (struct target_ops
*target
)
7499 unpush_target (target
);
7501 /* remote_close takes care of doing most of the clean up. */
7502 generic_mourn_inferior ();
7506 extended_remote_mourn_1 (struct target_ops
*target
)
7508 struct remote_state
*rs
= get_remote_state ();
7510 /* In case we got here due to an error, but we're going to stay
7512 rs
->waiting_for_stop_reply
= 0;
7514 /* We're no longer interested in these events. */
7515 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7517 /* If the current general thread belonged to the process we just
7518 detached from or has exited, the remote side current general
7519 thread becomes undefined. Considering a case like this:
7521 - We just got here due to a detach.
7522 - The process that we're detaching from happens to immediately
7523 report a global breakpoint being hit in non-stop mode, in the
7524 same thread we had selected before.
7525 - GDB attaches to this process again.
7526 - This event happens to be the next event we handle.
7528 GDB would consider that the current general thread didn't need to
7529 be set on the stub side (with Hg), since for all it knew,
7530 GENERAL_THREAD hadn't changed.
7532 Notice that although in all-stop mode, the remote server always
7533 sets the current thread to the thread reporting the stop event,
7534 that doesn't happen in non-stop mode; in non-stop, the stub *must
7535 not* change the current thread when reporting a breakpoint hit,
7536 due to the decoupling of event reporting and event handling.
7538 To keep things simple, we always invalidate our notion of the
7540 record_currthread (minus_one_ptid
);
7542 /* Unlike "target remote", we do not want to unpush the target; then
7543 the next time the user says "run", we won't be connected. */
7545 /* Call common code to mark the inferior as not running. */
7546 generic_mourn_inferior ();
7548 if (!have_inferiors ())
7550 if (!remote_multi_process_p (rs
))
7552 /* Check whether the target is running now - some remote stubs
7553 automatically restart after kill. */
7555 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7557 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7559 /* Assume that the target has been restarted. Set
7560 inferior_ptid so that bits of core GDB realizes
7561 there's something here, e.g., so that the user can
7562 say "kill" again. */
7563 inferior_ptid
= magic_null_ptid
;
7570 extended_remote_mourn (struct target_ops
*ops
)
7572 extended_remote_mourn_1 (ops
);
7576 extended_remote_supports_disable_randomization (void)
7578 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7583 extended_remote_disable_randomization (int val
)
7585 struct remote_state
*rs
= get_remote_state ();
7588 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7590 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7592 error (_("Target does not support QDisableRandomization."));
7593 if (strcmp (reply
, "OK") != 0)
7594 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7598 extended_remote_run (char *args
)
7600 struct remote_state
*rs
= get_remote_state ();
7603 /* If the user has disabled vRun support, or we have detected that
7604 support is not available, do not try it. */
7605 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7608 strcpy (rs
->buf
, "vRun;");
7609 len
= strlen (rs
->buf
);
7611 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7612 error (_("Remote file name too long for run packet"));
7613 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7615 gdb_assert (args
!= NULL
);
7618 struct cleanup
*back_to
;
7622 argv
= gdb_buildargv (args
);
7623 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7624 for (i
= 0; argv
[i
] != NULL
; i
++)
7626 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7627 error (_("Argument list too long for run packet"));
7628 rs
->buf
[len
++] = ';';
7629 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7631 do_cleanups (back_to
);
7634 rs
->buf
[len
++] = '\0';
7637 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7639 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7641 /* We have a wait response; we don't need it, though. All is well. */
7644 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7645 /* It wasn't disabled before, but it is now. */
7649 if (remote_exec_file
[0] == '\0')
7650 error (_("Running the default executable on the remote target failed; "
7651 "try \"set remote exec-file\"?"));
7653 error (_("Running \"%s\" on the remote target failed"),
7658 /* In the extended protocol we want to be able to do things like
7659 "run" and have them basically work as expected. So we need
7660 a special create_inferior function. We support changing the
7661 executable file and the command line arguments, but not the
7665 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7666 char **env
, int from_tty
)
7668 /* If running asynchronously, register the target file descriptor
7669 with the event loop. */
7670 if (target_can_async_p ())
7671 target_async (inferior_event_handler
, 0);
7673 /* Disable address space randomization if requested (and supported). */
7674 if (extended_remote_supports_disable_randomization ())
7675 extended_remote_disable_randomization (disable_randomization
);
7677 /* Now restart the remote server. */
7678 if (extended_remote_run (args
) == -1)
7680 /* vRun was not supported. Fail if we need it to do what the
7682 if (remote_exec_file
[0])
7683 error (_("Remote target does not support \"set remote exec-file\""));
7685 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7687 /* Fall back to "R". */
7688 extended_remote_restart ();
7691 if (!have_inferiors ())
7693 /* Clean up from the last time we ran, before we mark the target
7694 running again. This will mark breakpoints uninserted, and
7695 get_offsets may insert breakpoints. */
7696 init_thread_list ();
7697 init_wait_for_inferior ();
7700 add_current_inferior_and_thread ();
7702 /* Get updated offsets, if the stub uses qOffsets. */
7707 extended_remote_create_inferior (struct target_ops
*ops
,
7708 char *exec_file
, char *args
,
7709 char **env
, int from_tty
)
7711 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7715 /* Insert a breakpoint. On targets that have software breakpoint
7716 support, we ask the remote target to do the work; on targets
7717 which don't, we insert a traditional memory breakpoint. */
7720 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7721 struct bp_target_info
*bp_tgt
)
7723 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7724 If it succeeds, then set the support to PACKET_ENABLE. If it
7725 fails, and the user has explicitly requested the Z support then
7726 report an error, otherwise, mark it disabled and go on. */
7728 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7730 CORE_ADDR addr
= bp_tgt
->placed_address
;
7731 struct remote_state
*rs
;
7735 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7737 rs
= get_remote_state ();
7743 addr
= (ULONGEST
) remote_address_masked (addr
);
7744 p
+= hexnumstr (p
, addr
);
7745 sprintf (p
, ",%d", bpsize
);
7748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7750 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7755 bp_tgt
->placed_address
= addr
;
7756 bp_tgt
->placed_size
= bpsize
;
7758 case PACKET_UNKNOWN
:
7763 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7767 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7768 struct bp_target_info
*bp_tgt
)
7770 CORE_ADDR addr
= bp_tgt
->placed_address
;
7771 struct remote_state
*rs
= get_remote_state ();
7773 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7781 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7782 p
+= hexnumstr (p
, addr
);
7783 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7786 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7788 return (rs
->buf
[0] == 'E');
7791 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7795 watchpoint_to_Z_packet (int type
)
7800 return Z_PACKET_WRITE_WP
;
7803 return Z_PACKET_READ_WP
;
7806 return Z_PACKET_ACCESS_WP
;
7809 internal_error (__FILE__
, __LINE__
,
7810 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7815 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7816 struct expression
*cond
)
7818 struct remote_state
*rs
= get_remote_state ();
7820 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7822 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7825 sprintf (rs
->buf
, "Z%x,", packet
);
7826 p
= strchr (rs
->buf
, '\0');
7827 addr
= remote_address_masked (addr
);
7828 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7829 sprintf (p
, ",%x", len
);
7832 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7834 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7838 case PACKET_UNKNOWN
:
7843 internal_error (__FILE__
, __LINE__
,
7844 _("remote_insert_watchpoint: reached end of function"));
7849 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7850 struct expression
*cond
)
7852 struct remote_state
*rs
= get_remote_state ();
7854 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7856 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7859 sprintf (rs
->buf
, "z%x,", packet
);
7860 p
= strchr (rs
->buf
, '\0');
7861 addr
= remote_address_masked (addr
);
7862 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7863 sprintf (p
, ",%x", len
);
7865 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7867 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7870 case PACKET_UNKNOWN
:
7875 internal_error (__FILE__
, __LINE__
,
7876 _("remote_remove_watchpoint: reached end of function"));
7880 int remote_hw_watchpoint_limit
= -1;
7881 int remote_hw_watchpoint_length_limit
= -1;
7882 int remote_hw_breakpoint_limit
= -1;
7885 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7887 if (remote_hw_watchpoint_length_limit
== 0)
7889 else if (remote_hw_watchpoint_length_limit
< 0)
7891 else if (len
<= remote_hw_watchpoint_length_limit
)
7898 remote_check_watch_resources (int type
, int cnt
, int ot
)
7900 if (type
== bp_hardware_breakpoint
)
7902 if (remote_hw_breakpoint_limit
== 0)
7904 else if (remote_hw_breakpoint_limit
< 0)
7906 else if (cnt
<= remote_hw_breakpoint_limit
)
7911 if (remote_hw_watchpoint_limit
== 0)
7913 else if (remote_hw_watchpoint_limit
< 0)
7917 else if (cnt
<= remote_hw_watchpoint_limit
)
7924 remote_stopped_by_watchpoint (void)
7926 return remote_stopped_by_watchpoint_p
;
7930 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7934 if (remote_stopped_by_watchpoint ())
7936 *addr_p
= remote_watch_data_address
;
7945 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7946 struct bp_target_info
*bp_tgt
)
7949 struct remote_state
*rs
;
7952 /* The length field should be set to the size of a breakpoint
7953 instruction, even though we aren't inserting one ourselves. */
7955 gdbarch_remote_breakpoint_from_pc
7956 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7958 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7961 rs
= get_remote_state ();
7968 addr
= remote_address_masked (bp_tgt
->placed_address
);
7969 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7970 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7973 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7975 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7978 case PACKET_UNKNOWN
:
7983 internal_error (__FILE__
, __LINE__
,
7984 _("remote_insert_hw_breakpoint: reached end of function"));
7989 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7990 struct bp_target_info
*bp_tgt
)
7993 struct remote_state
*rs
= get_remote_state ();
7996 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8003 addr
= remote_address_masked (bp_tgt
->placed_address
);
8004 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8005 sprintf (p
, ",%x", bp_tgt
->placed_size
);
8008 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8010 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8013 case PACKET_UNKNOWN
:
8018 internal_error (__FILE__
, __LINE__
,
8019 _("remote_remove_hw_breakpoint: reached end of function"));
8022 /* Table used by the crc32 function to calcuate the checksum. */
8024 static unsigned long crc32_table
[256] =
8027 static unsigned long
8028 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8030 if (!crc32_table
[1])
8032 /* Initialize the CRC table and the decoding table. */
8036 for (i
= 0; i
< 256; i
++)
8038 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8039 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8046 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8052 /* Verify memory using the "qCRC:" request. */
8055 remote_verify_memory (struct target_ops
*ops
,
8056 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8058 struct remote_state
*rs
= get_remote_state ();
8059 unsigned long host_crc
, target_crc
;
8062 /* FIXME: assumes lma can fit into long. */
8063 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8064 (long) lma
, (long) size
);
8067 /* Be clever; compute the host_crc before waiting for target
8069 host_crc
= crc32 (data
, size
, 0xffffffff);
8071 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8072 if (rs
->buf
[0] == 'E')
8075 if (rs
->buf
[0] != 'C')
8076 error (_("remote target does not support this operation"));
8078 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8079 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8081 return (host_crc
== target_crc
);
8084 /* compare-sections command
8086 With no arguments, compares each loadable section in the exec bfd
8087 with the same memory range on the target, and reports mismatches.
8088 Useful for verifying the image on the target against the exec file. */
8091 compare_sections_command (char *args
, int from_tty
)
8094 struct cleanup
*old_chain
;
8096 const char *sectname
;
8104 error (_("command cannot be used without an exec file"));
8106 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8108 if (!(s
->flags
& SEC_LOAD
))
8109 continue; /* Skip non-loadable section. */
8111 size
= bfd_get_section_size (s
);
8113 continue; /* Skip zero-length section. */
8115 sectname
= bfd_get_section_name (exec_bfd
, s
);
8116 if (args
&& strcmp (args
, sectname
) != 0)
8117 continue; /* Not the section selected by user. */
8119 matched
= 1; /* Do this section. */
8122 sectdata
= xmalloc (size
);
8123 old_chain
= make_cleanup (xfree
, sectdata
);
8124 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8126 res
= target_verify_memory (sectdata
, lma
, size
);
8129 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8130 paddress (target_gdbarch
, lma
),
8131 paddress (target_gdbarch
, lma
+ size
));
8133 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8134 paddress (target_gdbarch
, lma
),
8135 paddress (target_gdbarch
, lma
+ size
));
8137 printf_filtered ("matched.\n");
8140 printf_filtered ("MIS-MATCHED!\n");
8144 do_cleanups (old_chain
);
8147 warning (_("One or more sections of the remote executable does not match\n\
8148 the loaded file\n"));
8149 if (args
&& !matched
)
8150 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8153 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8154 into remote target. The number of bytes written to the remote
8155 target is returned, or -1 for error. */
8158 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8159 const char *annex
, const gdb_byte
*writebuf
,
8160 ULONGEST offset
, LONGEST len
,
8161 struct packet_config
*packet
)
8165 struct remote_state
*rs
= get_remote_state ();
8166 int max_size
= get_memory_write_packet_size ();
8168 if (packet
->support
== PACKET_DISABLE
)
8171 /* Insert header. */
8172 i
= snprintf (rs
->buf
, max_size
,
8173 "qXfer:%s:write:%s:%s:",
8174 object_name
, annex
? annex
: "",
8175 phex_nz (offset
, sizeof offset
));
8176 max_size
-= (i
+ 1);
8178 /* Escape as much data as fits into rs->buf. */
8179 buf_len
= remote_escape_output
8180 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8182 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8183 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8184 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8187 unpack_varlen_hex (rs
->buf
, &n
);
8191 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8192 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8193 number of bytes read is returned, or 0 for EOF, or -1 for error.
8194 The number of bytes read may be less than LEN without indicating an
8195 EOF. PACKET is checked and updated to indicate whether the remote
8196 target supports this object. */
8199 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8201 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8202 struct packet_config
*packet
)
8204 static char *finished_object
;
8205 static char *finished_annex
;
8206 static ULONGEST finished_offset
;
8208 struct remote_state
*rs
= get_remote_state ();
8209 LONGEST i
, n
, packet_len
;
8211 if (packet
->support
== PACKET_DISABLE
)
8214 /* Check whether we've cached an end-of-object packet that matches
8216 if (finished_object
)
8218 if (strcmp (object_name
, finished_object
) == 0
8219 && strcmp (annex
? annex
: "", finished_annex
) == 0
8220 && offset
== finished_offset
)
8223 /* Otherwise, we're now reading something different. Discard
8225 xfree (finished_object
);
8226 xfree (finished_annex
);
8227 finished_object
= NULL
;
8228 finished_annex
= NULL
;
8231 /* Request only enough to fit in a single packet. The actual data
8232 may not, since we don't know how much of it will need to be escaped;
8233 the target is free to respond with slightly less data. We subtract
8234 five to account for the response type and the protocol frame. */
8235 n
= min (get_remote_packet_size () - 5, len
);
8236 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8237 object_name
, annex
? annex
: "",
8238 phex_nz (offset
, sizeof offset
),
8239 phex_nz (n
, sizeof n
));
8240 i
= putpkt (rs
->buf
);
8245 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8246 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8249 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8250 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8252 /* 'm' means there is (or at least might be) more data after this
8253 batch. That does not make sense unless there's at least one byte
8254 of data in this reply. */
8255 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8256 error (_("Remote qXfer reply contained no data."));
8258 /* Got some data. */
8259 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8261 /* 'l' is an EOF marker, possibly including a final block of data,
8262 or possibly empty. If we have the final block of a non-empty
8263 object, record this fact to bypass a subsequent partial read. */
8264 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8266 finished_object
= xstrdup (object_name
);
8267 finished_annex
= xstrdup (annex
? annex
: "");
8268 finished_offset
= offset
+ i
;
8275 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8276 const char *annex
, gdb_byte
*readbuf
,
8277 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8279 struct remote_state
*rs
;
8284 set_remote_traceframe ();
8285 set_general_thread (inferior_ptid
);
8287 rs
= get_remote_state ();
8289 /* Handle memory using the standard memory routines. */
8290 if (object
== TARGET_OBJECT_MEMORY
)
8296 /* If the remote target is connected but not running, we should
8297 pass this request down to a lower stratum (e.g. the executable
8299 if (!target_has_execution
)
8302 if (writebuf
!= NULL
)
8303 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8305 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8309 else if (xfered
== 0 && errno
== 0)
8315 /* Handle SPU memory using qxfer packets. */
8316 if (object
== TARGET_OBJECT_SPU
)
8319 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8320 &remote_protocol_packets
8321 [PACKET_qXfer_spu_read
]);
8323 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8324 &remote_protocol_packets
8325 [PACKET_qXfer_spu_write
]);
8328 /* Handle extra signal info using qxfer packets. */
8329 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8332 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8333 &remote_protocol_packets
8334 [PACKET_qXfer_siginfo_read
]);
8336 return remote_write_qxfer (ops
, "siginfo", annex
,
8337 writebuf
, offset
, len
,
8338 &remote_protocol_packets
8339 [PACKET_qXfer_siginfo_write
]);
8342 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8345 return remote_read_qxfer (ops
, "statictrace", annex
,
8346 readbuf
, offset
, len
,
8347 &remote_protocol_packets
8348 [PACKET_qXfer_statictrace_read
]);
8353 /* Only handle flash writes. */
8354 if (writebuf
!= NULL
)
8360 case TARGET_OBJECT_FLASH
:
8361 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8365 else if (xfered
== 0 && errno
== 0)
8375 /* Map pre-existing objects onto letters. DO NOT do this for new
8376 objects!!! Instead specify new query packets. */
8379 case TARGET_OBJECT_AVR
:
8383 case TARGET_OBJECT_AUXV
:
8384 gdb_assert (annex
== NULL
);
8385 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8386 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8388 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8389 return remote_read_qxfer
8390 (ops
, "features", annex
, readbuf
, offset
, len
,
8391 &remote_protocol_packets
[PACKET_qXfer_features
]);
8393 case TARGET_OBJECT_LIBRARIES
:
8394 return remote_read_qxfer
8395 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8396 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8398 case TARGET_OBJECT_LIBRARIES_SVR4
:
8399 return remote_read_qxfer
8400 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8401 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8403 case TARGET_OBJECT_MEMORY_MAP
:
8404 gdb_assert (annex
== NULL
);
8405 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8406 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8408 case TARGET_OBJECT_OSDATA
:
8409 /* Should only get here if we're connected. */
8410 gdb_assert (remote_desc
);
8411 return remote_read_qxfer
8412 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8413 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8415 case TARGET_OBJECT_THREADS
:
8416 gdb_assert (annex
== NULL
);
8417 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8418 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8420 case TARGET_OBJECT_TRACEFRAME_INFO
:
8421 gdb_assert (annex
== NULL
);
8422 return remote_read_qxfer
8423 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8424 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8426 case TARGET_OBJECT_FDPIC
:
8427 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8428 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8433 /* Note: a zero OFFSET and LEN can be used to query the minimum
8435 if (offset
== 0 && len
== 0)
8436 return (get_remote_packet_size ());
8437 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8438 large enough let the caller deal with it. */
8439 if (len
< get_remote_packet_size ())
8441 len
= get_remote_packet_size ();
8443 /* Except for querying the minimum buffer size, target must be open. */
8445 error (_("remote query is only available after target open"));
8447 gdb_assert (annex
!= NULL
);
8448 gdb_assert (readbuf
!= NULL
);
8454 /* We used one buffer char for the remote protocol q command and
8455 another for the query type. As the remote protocol encapsulation
8456 uses 4 chars plus one extra in case we are debugging
8457 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8460 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8462 /* Bad caller may have sent forbidden characters. */
8463 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8468 gdb_assert (annex
[i
] == '\0');
8470 i
= putpkt (rs
->buf
);
8474 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8475 strcpy ((char *) readbuf
, rs
->buf
);
8477 return strlen ((char *) readbuf
);
8481 remote_search_memory (struct target_ops
* ops
,
8482 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8483 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8484 CORE_ADDR
*found_addrp
)
8486 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8487 struct remote_state
*rs
= get_remote_state ();
8488 int max_size
= get_memory_write_packet_size ();
8489 struct packet_config
*packet
=
8490 &remote_protocol_packets
[PACKET_qSearch_memory
];
8491 /* Number of packet bytes used to encode the pattern;
8492 this could be more than PATTERN_LEN due to escape characters. */
8493 int escaped_pattern_len
;
8494 /* Amount of pattern that was encodable in the packet. */
8495 int used_pattern_len
;
8498 ULONGEST found_addr
;
8500 /* Don't go to the target if we don't have to.
8501 This is done before checking packet->support to avoid the possibility that
8502 a success for this edge case means the facility works in general. */
8503 if (pattern_len
> search_space_len
)
8505 if (pattern_len
== 0)
8507 *found_addrp
= start_addr
;
8511 /* If we already know the packet isn't supported, fall back to the simple
8512 way of searching memory. */
8514 if (packet
->support
== PACKET_DISABLE
)
8516 /* Target doesn't provided special support, fall back and use the
8517 standard support (copy memory and do the search here). */
8518 return simple_search_memory (ops
, start_addr
, search_space_len
,
8519 pattern
, pattern_len
, found_addrp
);
8522 /* Insert header. */
8523 i
= snprintf (rs
->buf
, max_size
,
8524 "qSearch:memory:%s;%s;",
8525 phex_nz (start_addr
, addr_size
),
8526 phex_nz (search_space_len
, sizeof (search_space_len
)));
8527 max_size
-= (i
+ 1);
8529 /* Escape as much data as fits into rs->buf. */
8530 escaped_pattern_len
=
8531 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8532 &used_pattern_len
, max_size
);
8534 /* Bail if the pattern is too large. */
8535 if (used_pattern_len
!= pattern_len
)
8536 error (_("Pattern is too large to transmit to remote target."));
8538 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8539 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8540 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8542 /* The request may not have worked because the command is not
8543 supported. If so, fall back to the simple way. */
8544 if (packet
->support
== PACKET_DISABLE
)
8546 return simple_search_memory (ops
, start_addr
, search_space_len
,
8547 pattern
, pattern_len
, found_addrp
);
8552 if (rs
->buf
[0] == '0')
8554 else if (rs
->buf
[0] == '1')
8557 if (rs
->buf
[1] != ',')
8558 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8559 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8560 *found_addrp
= found_addr
;
8563 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8569 remote_rcmd (char *command
,
8570 struct ui_file
*outbuf
)
8572 struct remote_state
*rs
= get_remote_state ();
8576 error (_("remote rcmd is only available after target open"));
8578 /* Send a NULL command across as an empty command. */
8579 if (command
== NULL
)
8582 /* The query prefix. */
8583 strcpy (rs
->buf
, "qRcmd,");
8584 p
= strchr (rs
->buf
, '\0');
8586 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8587 > get_remote_packet_size ())
8588 error (_("\"monitor\" command ``%s'' is too long."), command
);
8590 /* Encode the actual command. */
8591 bin2hex ((gdb_byte
*) command
, p
, 0);
8593 if (putpkt (rs
->buf
) < 0)
8594 error (_("Communication problem with target."));
8596 /* get/display the response */
8601 /* XXX - see also remote_get_noisy_reply(). */
8602 QUIT
; /* Allow user to bail out with ^C. */
8604 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
8606 /* Timeout. Continue to (try to) read responses.
8607 This is better than stopping with an error, assuming the stub
8608 is still executing the (long) monitor command.
8609 If needed, the user can interrupt gdb using C-c, obtaining
8610 an effect similar to stop on timeout. */
8615 error (_("Target does not support this command."));
8616 if (buf
[0] == 'O' && buf
[1] != 'K')
8618 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8621 if (strcmp (buf
, "OK") == 0)
8623 if (strlen (buf
) == 3 && buf
[0] == 'E'
8624 && isdigit (buf
[1]) && isdigit (buf
[2]))
8626 error (_("Protocol error with Rcmd"));
8628 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8630 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8632 fputc_unfiltered (c
, outbuf
);
8638 static VEC(mem_region_s
) *
8639 remote_memory_map (struct target_ops
*ops
)
8641 VEC(mem_region_s
) *result
= NULL
;
8642 char *text
= target_read_stralloc (¤t_target
,
8643 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8647 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8649 result
= parse_memory_map (text
);
8650 do_cleanups (back_to
);
8657 packet_command (char *args
, int from_tty
)
8659 struct remote_state
*rs
= get_remote_state ();
8662 error (_("command can only be used with remote target"));
8665 error (_("remote-packet command requires packet text as argument"));
8667 puts_filtered ("sending: ");
8668 print_packet (args
);
8669 puts_filtered ("\n");
8672 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8673 puts_filtered ("received: ");
8674 print_packet (rs
->buf
);
8675 puts_filtered ("\n");
8679 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8681 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8683 static void threadset_test_cmd (char *cmd
, int tty
);
8685 static void threadalive_test (char *cmd
, int tty
);
8687 static void threadlist_test_cmd (char *cmd
, int tty
);
8689 int get_and_display_threadinfo (threadref
*ref
);
8691 static void threadinfo_test_cmd (char *cmd
, int tty
);
8693 static int thread_display_step (threadref
*ref
, void *context
);
8695 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8697 static void init_remote_threadtests (void);
8699 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8702 threadset_test_cmd (char *cmd
, int tty
)
8704 int sample_thread
= SAMPLE_THREAD
;
8706 printf_filtered (_("Remote threadset test\n"));
8707 set_general_thread (sample_thread
);
8712 threadalive_test (char *cmd
, int tty
)
8714 int sample_thread
= SAMPLE_THREAD
;
8715 int pid
= ptid_get_pid (inferior_ptid
);
8716 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8718 if (remote_thread_alive (ptid
))
8719 printf_filtered ("PASS: Thread alive test\n");
8721 printf_filtered ("FAIL: Thread alive test\n");
8724 void output_threadid (char *title
, threadref
*ref
);
8727 output_threadid (char *title
, threadref
*ref
)
8731 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8733 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8737 threadlist_test_cmd (char *cmd
, int tty
)
8740 threadref nextthread
;
8741 int done
, result_count
;
8742 threadref threadlist
[3];
8744 printf_filtered ("Remote Threadlist test\n");
8745 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8746 &result_count
, &threadlist
[0]))
8747 printf_filtered ("FAIL: threadlist test\n");
8750 threadref
*scan
= threadlist
;
8751 threadref
*limit
= scan
+ result_count
;
8753 while (scan
< limit
)
8754 output_threadid (" thread ", scan
++);
8759 display_thread_info (struct gdb_ext_thread_info
*info
)
8761 output_threadid ("Threadid: ", &info
->threadid
);
8762 printf_filtered ("Name: %s\n ", info
->shortname
);
8763 printf_filtered ("State: %s\n", info
->display
);
8764 printf_filtered ("other: %s\n\n", info
->more_display
);
8768 get_and_display_threadinfo (threadref
*ref
)
8772 struct gdb_ext_thread_info threadinfo
;
8774 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8775 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8776 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8777 display_thread_info (&threadinfo
);
8782 threadinfo_test_cmd (char *cmd
, int tty
)
8784 int athread
= SAMPLE_THREAD
;
8788 int_to_threadref (&thread
, athread
);
8789 printf_filtered ("Remote Threadinfo test\n");
8790 if (!get_and_display_threadinfo (&thread
))
8791 printf_filtered ("FAIL cannot get thread info\n");
8795 thread_display_step (threadref
*ref
, void *context
)
8797 /* output_threadid(" threadstep ",ref); *//* simple test */
8798 return get_and_display_threadinfo (ref
);
8802 threadlist_update_test_cmd (char *cmd
, int tty
)
8804 printf_filtered ("Remote Threadlist update test\n");
8805 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8809 init_remote_threadtests (void)
8811 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8812 _("Fetch and print the remote list of "
8813 "thread identifiers, one pkt only"));
8814 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8815 _("Fetch and display info about one thread"));
8816 add_com ("tset", class_obscure
, threadset_test_cmd
,
8817 _("Test setting to a different thread"));
8818 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8819 _("Iterate through updating all remote thread info"));
8820 add_com ("talive", class_obscure
, threadalive_test
,
8821 _(" Remote thread alive test "));
8826 /* Convert a thread ID to a string. Returns the string in a static
8830 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8832 static char buf
[64];
8833 struct remote_state
*rs
= get_remote_state ();
8835 if (ptid_equal (ptid
, null_ptid
))
8836 return normal_pid_to_str (ptid
);
8837 else if (ptid_is_pid (ptid
))
8839 /* Printing an inferior target id. */
8841 /* When multi-process extensions are off, there's no way in the
8842 remote protocol to know the remote process id, if there's any
8843 at all. There's one exception --- when we're connected with
8844 target extended-remote, and we manually attached to a process
8845 with "attach PID". We don't record anywhere a flag that
8846 allows us to distinguish that case from the case of
8847 connecting with extended-remote and the stub already being
8848 attached to a process, and reporting yes to qAttached, hence
8849 no smart special casing here. */
8850 if (!remote_multi_process_p (rs
))
8852 xsnprintf (buf
, sizeof buf
, "Remote target");
8856 return normal_pid_to_str (ptid
);
8860 if (ptid_equal (magic_null_ptid
, ptid
))
8861 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8862 else if (rs
->extended
&& remote_multi_process_p (rs
))
8863 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8864 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8866 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8867 ptid_get_tid (ptid
));
8872 /* Get the address of the thread local variable in OBJFILE which is
8873 stored at OFFSET within the thread local storage for thread PTID. */
8876 remote_get_thread_local_address (struct target_ops
*ops
,
8877 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8879 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8881 struct remote_state
*rs
= get_remote_state ();
8883 char *endp
= rs
->buf
+ get_remote_packet_size ();
8884 enum packet_result result
;
8886 strcpy (p
, "qGetTLSAddr:");
8888 p
= write_ptid (p
, endp
, ptid
);
8890 p
+= hexnumstr (p
, offset
);
8892 p
+= hexnumstr (p
, lm
);
8896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8897 result
= packet_ok (rs
->buf
,
8898 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8899 if (result
== PACKET_OK
)
8903 unpack_varlen_hex (rs
->buf
, &result
);
8906 else if (result
== PACKET_UNKNOWN
)
8907 throw_error (TLS_GENERIC_ERROR
,
8908 _("Remote target doesn't support qGetTLSAddr packet"));
8910 throw_error (TLS_GENERIC_ERROR
,
8911 _("Remote target failed to process qGetTLSAddr request"));
8914 throw_error (TLS_GENERIC_ERROR
,
8915 _("TLS not supported or disabled on this target"));
8920 /* Provide thread local base, i.e. Thread Information Block address.
8921 Returns 1 if ptid is found and thread_local_base is non zero. */
8924 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8926 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8928 struct remote_state
*rs
= get_remote_state ();
8930 char *endp
= rs
->buf
+ get_remote_packet_size ();
8931 enum packet_result result
;
8933 strcpy (p
, "qGetTIBAddr:");
8935 p
= write_ptid (p
, endp
, ptid
);
8939 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8940 result
= packet_ok (rs
->buf
,
8941 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8942 if (result
== PACKET_OK
)
8946 unpack_varlen_hex (rs
->buf
, &result
);
8948 *addr
= (CORE_ADDR
) result
;
8951 else if (result
== PACKET_UNKNOWN
)
8952 error (_("Remote target doesn't support qGetTIBAddr packet"));
8954 error (_("Remote target failed to process qGetTIBAddr request"));
8957 error (_("qGetTIBAddr not supported or disabled on this target"));
8962 /* Support for inferring a target description based on the current
8963 architecture and the size of a 'g' packet. While the 'g' packet
8964 can have any size (since optional registers can be left off the
8965 end), some sizes are easily recognizable given knowledge of the
8966 approximate architecture. */
8968 struct remote_g_packet_guess
8971 const struct target_desc
*tdesc
;
8973 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8974 DEF_VEC_O(remote_g_packet_guess_s
);
8976 struct remote_g_packet_data
8978 VEC(remote_g_packet_guess_s
) *guesses
;
8981 static struct gdbarch_data
*remote_g_packet_data_handle
;
8984 remote_g_packet_data_init (struct obstack
*obstack
)
8986 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8990 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8991 const struct target_desc
*tdesc
)
8993 struct remote_g_packet_data
*data
8994 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8995 struct remote_g_packet_guess new_guess
, *guess
;
8998 gdb_assert (tdesc
!= NULL
);
9001 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9003 if (guess
->bytes
== bytes
)
9004 internal_error (__FILE__
, __LINE__
,
9005 _("Duplicate g packet description added for size %d"),
9008 new_guess
.bytes
= bytes
;
9009 new_guess
.tdesc
= tdesc
;
9010 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9013 /* Return 1 if remote_read_description would do anything on this target
9014 and architecture, 0 otherwise. */
9017 remote_read_description_p (struct target_ops
*target
)
9019 struct remote_g_packet_data
*data
9020 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9022 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9028 static const struct target_desc
*
9029 remote_read_description (struct target_ops
*target
)
9031 struct remote_g_packet_data
*data
9032 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9034 /* Do not try this during initial connection, when we do not know
9035 whether there is a running but stopped thread. */
9036 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9039 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9041 struct remote_g_packet_guess
*guess
;
9043 int bytes
= send_g_packet ();
9046 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9048 if (guess
->bytes
== bytes
)
9049 return guess
->tdesc
;
9051 /* We discard the g packet. A minor optimization would be to
9052 hold on to it, and fill the register cache once we have selected
9053 an architecture, but it's too tricky to do safely. */
9059 /* Remote file transfer support. This is host-initiated I/O, not
9060 target-initiated; for target-initiated, see remote-fileio.c. */
9062 /* If *LEFT is at least the length of STRING, copy STRING to
9063 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9064 decrease *LEFT. Otherwise raise an error. */
9067 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9069 int len
= strlen (string
);
9072 error (_("Packet too long for target."));
9074 memcpy (*buffer
, string
, len
);
9078 /* NUL-terminate the buffer as a convenience, if there is
9084 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9085 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9086 decrease *LEFT. Otherwise raise an error. */
9089 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9092 if (2 * len
> *left
)
9093 error (_("Packet too long for target."));
9095 bin2hex (bytes
, *buffer
, len
);
9099 /* NUL-terminate the buffer as a convenience, if there is
9105 /* If *LEFT is large enough, convert VALUE to hex and add it to
9106 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9107 decrease *LEFT. Otherwise raise an error. */
9110 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9112 int len
= hexnumlen (value
);
9115 error (_("Packet too long for target."));
9117 hexnumstr (*buffer
, value
);
9121 /* NUL-terminate the buffer as a convenience, if there is
9127 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9128 value, *REMOTE_ERRNO to the remote error number or zero if none
9129 was included, and *ATTACHMENT to point to the start of the annex
9130 if any. The length of the packet isn't needed here; there may
9131 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9133 Return 0 if the packet could be parsed, -1 if it could not. If
9134 -1 is returned, the other variables may not be initialized. */
9137 remote_hostio_parse_result (char *buffer
, int *retcode
,
9138 int *remote_errno
, char **attachment
)
9145 if (buffer
[0] != 'F')
9149 *retcode
= strtol (&buffer
[1], &p
, 16);
9150 if (errno
!= 0 || p
== &buffer
[1])
9153 /* Check for ",errno". */
9157 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9158 if (errno
!= 0 || p
+ 1 == p2
)
9163 /* Check for ";attachment". If there is no attachment, the
9164 packet should end here. */
9167 *attachment
= p
+ 1;
9170 else if (*p
== '\0')
9176 /* Send a prepared I/O packet to the target and read its response.
9177 The prepared packet is in the global RS->BUF before this function
9178 is called, and the answer is there when we return.
9180 COMMAND_BYTES is the length of the request to send, which may include
9181 binary data. WHICH_PACKET is the packet configuration to check
9182 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9183 is set to the error number and -1 is returned. Otherwise the value
9184 returned by the function is returned.
9186 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9187 attachment is expected; an error will be reported if there's a
9188 mismatch. If one is found, *ATTACHMENT will be set to point into
9189 the packet buffer and *ATTACHMENT_LEN will be set to the
9190 attachment's length. */
9193 remote_hostio_send_command (int command_bytes
, int which_packet
,
9194 int *remote_errno
, char **attachment
,
9195 int *attachment_len
)
9197 struct remote_state
*rs
= get_remote_state ();
9198 int ret
, bytes_read
;
9199 char *attachment_tmp
;
9202 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9204 *remote_errno
= FILEIO_ENOSYS
;
9208 putpkt_binary (rs
->buf
, command_bytes
);
9209 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9211 /* If it timed out, something is wrong. Don't try to parse the
9215 *remote_errno
= FILEIO_EINVAL
;
9219 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9222 *remote_errno
= FILEIO_EINVAL
;
9224 case PACKET_UNKNOWN
:
9225 *remote_errno
= FILEIO_ENOSYS
;
9231 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9234 *remote_errno
= FILEIO_EINVAL
;
9238 /* Make sure we saw an attachment if and only if we expected one. */
9239 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9240 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9242 *remote_errno
= FILEIO_EINVAL
;
9246 /* If an attachment was found, it must point into the packet buffer;
9247 work out how many bytes there were. */
9248 if (attachment_tmp
!= NULL
)
9250 *attachment
= attachment_tmp
;
9251 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9257 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9258 remote file descriptor, or -1 if an error occurs (and set
9262 remote_hostio_open (const char *filename
, int flags
, int mode
,
9265 struct remote_state
*rs
= get_remote_state ();
9267 int left
= get_remote_packet_size () - 1;
9269 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9271 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9273 remote_buffer_add_string (&p
, &left
, ",");
9275 remote_buffer_add_int (&p
, &left
, flags
);
9276 remote_buffer_add_string (&p
, &left
, ",");
9278 remote_buffer_add_int (&p
, &left
, mode
);
9280 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9281 remote_errno
, NULL
, NULL
);
9284 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9285 Return the number of bytes written, or -1 if an error occurs (and
9286 set *REMOTE_ERRNO). */
9289 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9290 ULONGEST offset
, int *remote_errno
)
9292 struct remote_state
*rs
= get_remote_state ();
9294 int left
= get_remote_packet_size ();
9297 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9299 remote_buffer_add_int (&p
, &left
, fd
);
9300 remote_buffer_add_string (&p
, &left
, ",");
9302 remote_buffer_add_int (&p
, &left
, offset
);
9303 remote_buffer_add_string (&p
, &left
, ",");
9305 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9306 get_remote_packet_size () - (p
- rs
->buf
));
9308 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9309 remote_errno
, NULL
, NULL
);
9312 /* Read up to LEN bytes FD on the remote target into READ_BUF
9313 Return the number of bytes read, or -1 if an error occurs (and
9314 set *REMOTE_ERRNO). */
9317 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9318 ULONGEST offset
, int *remote_errno
)
9320 struct remote_state
*rs
= get_remote_state ();
9323 int left
= get_remote_packet_size ();
9324 int ret
, attachment_len
;
9327 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9329 remote_buffer_add_int (&p
, &left
, fd
);
9330 remote_buffer_add_string (&p
, &left
, ",");
9332 remote_buffer_add_int (&p
, &left
, len
);
9333 remote_buffer_add_string (&p
, &left
, ",");
9335 remote_buffer_add_int (&p
, &left
, offset
);
9337 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9338 remote_errno
, &attachment
,
9344 read_len
= remote_unescape_input (attachment
, attachment_len
,
9346 if (read_len
!= ret
)
9347 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9352 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9353 (and set *REMOTE_ERRNO). */
9356 remote_hostio_close (int fd
, int *remote_errno
)
9358 struct remote_state
*rs
= get_remote_state ();
9360 int left
= get_remote_packet_size () - 1;
9362 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9364 remote_buffer_add_int (&p
, &left
, fd
);
9366 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9367 remote_errno
, NULL
, NULL
);
9370 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9371 occurs (and set *REMOTE_ERRNO). */
9374 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9376 struct remote_state
*rs
= get_remote_state ();
9378 int left
= get_remote_packet_size () - 1;
9380 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9382 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9385 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9386 remote_errno
, NULL
, NULL
);
9389 /* Read value of symbolic link FILENAME on the remote target. Return
9390 a null-terminated string allocated via xmalloc, or NULL if an error
9391 occurs (and set *REMOTE_ERRNO). */
9394 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9396 struct remote_state
*rs
= get_remote_state ();
9399 int left
= get_remote_packet_size ();
9400 int len
, attachment_len
;
9404 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9406 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9409 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9410 remote_errno
, &attachment
,
9416 ret
= xmalloc (len
+ 1);
9418 read_len
= remote_unescape_input (attachment
, attachment_len
,
9420 if (read_len
!= len
)
9421 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9428 remote_fileio_errno_to_host (int errnum
)
9452 case FILEIO_ENOTDIR
:
9472 case FILEIO_ENAMETOOLONG
:
9473 return ENAMETOOLONG
;
9479 remote_hostio_error (int errnum
)
9481 int host_error
= remote_fileio_errno_to_host (errnum
);
9483 if (host_error
== -1)
9484 error (_("Unknown remote I/O error %d"), errnum
);
9486 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9490 remote_hostio_close_cleanup (void *opaque
)
9492 int fd
= *(int *) opaque
;
9495 remote_hostio_close (fd
, &remote_errno
);
9500 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9502 const char *filename
= bfd_get_filename (abfd
);
9503 int fd
, remote_errno
;
9506 gdb_assert (remote_filename_p (filename
));
9508 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9511 errno
= remote_fileio_errno_to_host (remote_errno
);
9512 bfd_set_error (bfd_error_system_call
);
9516 stream
= xmalloc (sizeof (int));
9522 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9524 int fd
= *(int *)stream
;
9529 /* Ignore errors on close; these may happen if the remote
9530 connection was already torn down. */
9531 remote_hostio_close (fd
, &remote_errno
);
9537 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9538 file_ptr nbytes
, file_ptr offset
)
9540 int fd
= *(int *)stream
;
9542 file_ptr pos
, bytes
;
9545 while (nbytes
> pos
)
9547 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9548 offset
+ pos
, &remote_errno
);
9550 /* Success, but no bytes, means end-of-file. */
9554 errno
= remote_fileio_errno_to_host (remote_errno
);
9555 bfd_set_error (bfd_error_system_call
);
9566 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9568 /* FIXME: We should probably implement remote_hostio_stat. */
9569 sb
->st_size
= INT_MAX
;
9574 remote_filename_p (const char *filename
)
9576 return strncmp (filename
, "remote:", 7) == 0;
9580 remote_bfd_open (const char *remote_file
, const char *target
)
9582 return bfd_openr_iovec (remote_file
, target
,
9583 remote_bfd_iovec_open
, NULL
,
9584 remote_bfd_iovec_pread
,
9585 remote_bfd_iovec_close
,
9586 remote_bfd_iovec_stat
);
9590 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9592 struct cleanup
*back_to
, *close_cleanup
;
9593 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9596 int bytes_in_buffer
;
9601 error (_("command can only be used with remote target"));
9603 file
= fopen (local_file
, "rb");
9605 perror_with_name (local_file
);
9606 back_to
= make_cleanup_fclose (file
);
9608 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9610 0700, &remote_errno
);
9612 remote_hostio_error (remote_errno
);
9614 /* Send up to this many bytes at once. They won't all fit in the
9615 remote packet limit, so we'll transfer slightly fewer. */
9616 io_size
= get_remote_packet_size ();
9617 buffer
= xmalloc (io_size
);
9618 make_cleanup (xfree
, buffer
);
9620 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9622 bytes_in_buffer
= 0;
9625 while (bytes_in_buffer
|| !saw_eof
)
9629 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9630 io_size
- bytes_in_buffer
,
9635 error (_("Error reading %s."), local_file
);
9638 /* EOF. Unless there is something still in the
9639 buffer from the last iteration, we are done. */
9641 if (bytes_in_buffer
== 0)
9649 bytes
+= bytes_in_buffer
;
9650 bytes_in_buffer
= 0;
9652 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9653 offset
, &remote_errno
);
9656 remote_hostio_error (remote_errno
);
9657 else if (retcode
== 0)
9658 error (_("Remote write of %d bytes returned 0!"), bytes
);
9659 else if (retcode
< bytes
)
9661 /* Short write. Save the rest of the read data for the next
9663 bytes_in_buffer
= bytes
- retcode
;
9664 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9670 discard_cleanups (close_cleanup
);
9671 if (remote_hostio_close (fd
, &remote_errno
))
9672 remote_hostio_error (remote_errno
);
9675 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9676 do_cleanups (back_to
);
9680 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9682 struct cleanup
*back_to
, *close_cleanup
;
9683 int fd
, remote_errno
, bytes
, io_size
;
9689 error (_("command can only be used with remote target"));
9691 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9693 remote_hostio_error (remote_errno
);
9695 file
= fopen (local_file
, "wb");
9697 perror_with_name (local_file
);
9698 back_to
= make_cleanup_fclose (file
);
9700 /* Send up to this many bytes at once. They won't all fit in the
9701 remote packet limit, so we'll transfer slightly fewer. */
9702 io_size
= get_remote_packet_size ();
9703 buffer
= xmalloc (io_size
);
9704 make_cleanup (xfree
, buffer
);
9706 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9711 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9713 /* Success, but no bytes, means end-of-file. */
9716 remote_hostio_error (remote_errno
);
9720 bytes
= fwrite (buffer
, 1, bytes
, file
);
9722 perror_with_name (local_file
);
9725 discard_cleanups (close_cleanup
);
9726 if (remote_hostio_close (fd
, &remote_errno
))
9727 remote_hostio_error (remote_errno
);
9730 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9731 do_cleanups (back_to
);
9735 remote_file_delete (const char *remote_file
, int from_tty
)
9737 int retcode
, remote_errno
;
9740 error (_("command can only be used with remote target"));
9742 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9744 remote_hostio_error (remote_errno
);
9747 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9751 remote_put_command (char *args
, int from_tty
)
9753 struct cleanup
*back_to
;
9757 error_no_arg (_("file to put"));
9759 argv
= gdb_buildargv (args
);
9760 back_to
= make_cleanup_freeargv (argv
);
9761 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9762 error (_("Invalid parameters to remote put"));
9764 remote_file_put (argv
[0], argv
[1], from_tty
);
9766 do_cleanups (back_to
);
9770 remote_get_command (char *args
, int from_tty
)
9772 struct cleanup
*back_to
;
9776 error_no_arg (_("file to get"));
9778 argv
= gdb_buildargv (args
);
9779 back_to
= make_cleanup_freeargv (argv
);
9780 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9781 error (_("Invalid parameters to remote get"));
9783 remote_file_get (argv
[0], argv
[1], from_tty
);
9785 do_cleanups (back_to
);
9789 remote_delete_command (char *args
, int from_tty
)
9791 struct cleanup
*back_to
;
9795 error_no_arg (_("file to delete"));
9797 argv
= gdb_buildargv (args
);
9798 back_to
= make_cleanup_freeargv (argv
);
9799 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9800 error (_("Invalid parameters to remote delete"));
9802 remote_file_delete (argv
[0], from_tty
);
9804 do_cleanups (back_to
);
9808 remote_command (char *args
, int from_tty
)
9810 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9814 remote_can_execute_reverse (void)
9816 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9817 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9824 remote_supports_non_stop (void)
9830 remote_supports_disable_randomization (void)
9832 /* Only supported in extended mode. */
9837 remote_supports_multi_process (void)
9839 struct remote_state
*rs
= get_remote_state ();
9841 /* Only extended-remote handles being attached to multiple
9842 processes, even though plain remote can use the multi-process
9843 thread id extensions, so that GDB knows the target process's
9845 return rs
->extended
&& remote_multi_process_p (rs
);
9849 remote_supports_cond_tracepoints (void)
9851 struct remote_state
*rs
= get_remote_state ();
9853 return rs
->cond_tracepoints
;
9857 remote_supports_fast_tracepoints (void)
9859 struct remote_state
*rs
= get_remote_state ();
9861 return rs
->fast_tracepoints
;
9865 remote_supports_static_tracepoints (void)
9867 struct remote_state
*rs
= get_remote_state ();
9869 return rs
->static_tracepoints
;
9873 remote_supports_install_in_trace (void)
9875 struct remote_state
*rs
= get_remote_state ();
9877 return rs
->install_in_trace
;
9881 remote_supports_enable_disable_tracepoint (void)
9883 struct remote_state
*rs
= get_remote_state ();
9885 return rs
->enable_disable_tracepoints
;
9889 remote_supports_string_tracing (void)
9891 struct remote_state
*rs
= get_remote_state ();
9893 return rs
->string_tracing
;
9897 remote_trace_init (void)
9900 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9901 if (strcmp (target_buf
, "OK") != 0)
9902 error (_("Target does not support this command."));
9905 static void free_actions_list (char **actions_list
);
9906 static void free_actions_list_cleanup_wrapper (void *);
9908 free_actions_list_cleanup_wrapper (void *al
)
9910 free_actions_list (al
);
9914 free_actions_list (char **actions_list
)
9918 if (actions_list
== 0)
9921 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9922 xfree (actions_list
[ndx
]);
9924 xfree (actions_list
);
9927 /* Recursive routine to walk through command list including loops, and
9928 download packets for each command. */
9931 remote_download_command_source (int num
, ULONGEST addr
,
9932 struct command_line
*cmds
)
9934 struct remote_state
*rs
= get_remote_state ();
9935 struct command_line
*cmd
;
9937 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9939 QUIT
; /* Allow user to bail out with ^C. */
9940 strcpy (rs
->buf
, "QTDPsrc:");
9941 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9942 rs
->buf
+ strlen (rs
->buf
),
9943 rs
->buf_size
- strlen (rs
->buf
));
9945 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9946 if (strcmp (target_buf
, "OK"))
9947 warning (_("Target does not support source download."));
9949 if (cmd
->control_type
== while_control
9950 || cmd
->control_type
== while_stepping_control
)
9952 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9954 QUIT
; /* Allow user to bail out with ^C. */
9955 strcpy (rs
->buf
, "QTDPsrc:");
9956 encode_source_string (num
, addr
, "cmd", "end",
9957 rs
->buf
+ strlen (rs
->buf
),
9958 rs
->buf_size
- strlen (rs
->buf
));
9960 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9961 if (strcmp (target_buf
, "OK"))
9962 warning (_("Target does not support source download."));
9968 remote_download_tracepoint (struct bp_location
*loc
)
9975 char **stepping_actions
;
9977 struct cleanup
*old_chain
= NULL
;
9978 struct agent_expr
*aexpr
;
9979 struct cleanup
*aexpr_chain
= NULL
;
9981 struct breakpoint
*b
= loc
->owner
;
9982 struct tracepoint
*t
= (struct tracepoint
*) b
;
9984 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9985 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9987 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9990 tpaddr
= loc
->address
;
9991 sprintf_vma (addrbuf
, tpaddr
);
9992 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9993 addrbuf
, /* address */
9994 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9995 t
->step_count
, t
->pass_count
);
9996 /* Fast tracepoints are mostly handled by the target, but we can
9997 tell the target how big of an instruction block should be moved
9999 if (b
->type
== bp_fast_tracepoint
)
10001 /* Only test for support at download time; we may not know
10002 target capabilities at definition time. */
10003 if (remote_supports_fast_tracepoints ())
10007 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
10008 tpaddr
, &isize
, NULL
))
10009 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
10011 /* If it passed validation at definition but fails now,
10012 something is very wrong. */
10013 internal_error (__FILE__
, __LINE__
,
10014 _("Fast tracepoint not "
10015 "valid during download"));
10018 /* Fast tracepoints are functionally identical to regular
10019 tracepoints, so don't take lack of support as a reason to
10020 give up on the trace run. */
10021 warning (_("Target does not support fast tracepoints, "
10022 "downloading %d as regular tracepoint"), b
->number
);
10024 else if (b
->type
== bp_static_tracepoint
)
10026 /* Only test for support at download time; we may not know
10027 target capabilities at definition time. */
10028 if (remote_supports_static_tracepoints ())
10030 struct static_tracepoint_marker marker
;
10032 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10033 strcat (buf
, ":S");
10035 error (_("Static tracepoint not valid during download"));
10038 /* Fast tracepoints are functionally identical to regular
10039 tracepoints, so don't take lack of support as a reason
10040 to give up on the trace run. */
10041 error (_("Target does not support static tracepoints"));
10043 /* If the tracepoint has a conditional, make it into an agent
10044 expression and append to the definition. */
10047 /* Only test support at download time, we may not know target
10048 capabilities at definition time. */
10049 if (remote_supports_cond_tracepoints ())
10051 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10052 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10053 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
10054 pkt
= buf
+ strlen (buf
);
10055 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10056 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10058 do_cleanups (aexpr_chain
);
10061 warning (_("Target does not support conditional tracepoints, "
10062 "ignoring tp %d cond"), b
->number
);
10065 if (b
->commands
|| *default_collect
)
10068 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10069 if (strcmp (target_buf
, "OK"))
10070 error (_("Target does not support tracepoints."));
10072 /* do_single_steps (t); */
10075 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10077 QUIT
; /* Allow user to bail out with ^C. */
10078 sprintf (buf
, "QTDP:-%x:%s:%s%c",
10079 b
->number
, addrbuf
, /* address */
10081 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10084 remote_get_noisy_reply (&target_buf
,
10086 if (strcmp (target_buf
, "OK"))
10087 error (_("Error on target while setting tracepoints."));
10090 if (stepping_actions
)
10092 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10094 QUIT
; /* Allow user to bail out with ^C. */
10095 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
10096 b
->number
, addrbuf
, /* address */
10097 ((ndx
== 0) ? "S" : ""),
10098 stepping_actions
[ndx
],
10099 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10101 remote_get_noisy_reply (&target_buf
,
10103 if (strcmp (target_buf
, "OK"))
10104 error (_("Error on target while setting tracepoints."));
10108 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10111 if (b
->addr_string
)
10113 strcpy (buf
, "QTDPsrc:");
10114 encode_source_string (b
->number
, loc
->address
,
10115 "at", b
->addr_string
, buf
+ strlen (buf
),
10116 2048 - strlen (buf
));
10119 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10120 if (strcmp (target_buf
, "OK"))
10121 warning (_("Target does not support source download."));
10123 if (b
->cond_string
)
10125 strcpy (buf
, "QTDPsrc:");
10126 encode_source_string (b
->number
, loc
->address
,
10127 "cond", b
->cond_string
, buf
+ strlen (buf
),
10128 2048 - strlen (buf
));
10130 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10131 if (strcmp (target_buf
, "OK"))
10132 warning (_("Target does not support source download."));
10134 remote_download_command_source (b
->number
, loc
->address
,
10135 breakpoint_commands (b
));
10138 do_cleanups (old_chain
);
10142 remote_can_download_tracepoint (void)
10144 struct trace_status
*ts
= current_trace_status ();
10145 int status
= remote_get_trace_status (ts
);
10147 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10150 /* If we are in a tracing experiment, but remote stub doesn't support
10151 installing tracepoint in trace, we have to return. */
10152 if (!remote_supports_install_in_trace ())
10160 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10162 struct remote_state
*rs
= get_remote_state ();
10165 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10166 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10167 p
= rs
->buf
+ strlen (rs
->buf
);
10168 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10169 error (_("Trace state variable name too long for tsv definition packet"));
10170 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10173 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10174 if (*target_buf
== '\0')
10175 error (_("Target does not support this command."));
10176 if (strcmp (target_buf
, "OK") != 0)
10177 error (_("Error on target while downloading trace state variable."));
10181 remote_enable_tracepoint (struct bp_location
*location
)
10183 struct remote_state
*rs
= get_remote_state ();
10186 sprintf_vma (addr_buf
, location
->address
);
10187 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10189 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10190 if (*rs
->buf
== '\0')
10191 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10192 if (strcmp (rs
->buf
, "OK") != 0)
10193 error (_("Error on target while enabling tracepoint."));
10197 remote_disable_tracepoint (struct bp_location
*location
)
10199 struct remote_state
*rs
= get_remote_state ();
10202 sprintf_vma (addr_buf
, location
->address
);
10203 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10205 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10206 if (*rs
->buf
== '\0')
10207 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10208 if (strcmp (rs
->buf
, "OK") != 0)
10209 error (_("Error on target while disabling tracepoint."));
10213 remote_trace_set_readonly_regions (void)
10216 bfd_size_type size
;
10222 return; /* No information to give. */
10224 strcpy (target_buf
, "QTro");
10225 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10227 char tmp1
[40], tmp2
[40];
10230 if ((s
->flags
& SEC_LOAD
) == 0 ||
10231 /* (s->flags & SEC_CODE) == 0 || */
10232 (s
->flags
& SEC_READONLY
) == 0)
10236 vma
= bfd_get_section_vma (,s
);
10237 size
= bfd_get_section_size (s
);
10238 sprintf_vma (tmp1
, vma
);
10239 sprintf_vma (tmp2
, vma
+ size
);
10240 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10241 if (offset
+ sec_length
+ 1 > target_buf_size
)
10243 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10246 Too many sections for read-only sections definition packet."));
10249 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10250 offset
+= sec_length
;
10254 putpkt (target_buf
);
10255 getpkt (&target_buf
, &target_buf_size
, 0);
10260 remote_trace_start (void)
10262 putpkt ("QTStart");
10263 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10264 if (*target_buf
== '\0')
10265 error (_("Target does not support this command."));
10266 if (strcmp (target_buf
, "OK") != 0)
10267 error (_("Bogus reply from target: %s"), target_buf
);
10271 remote_get_trace_status (struct trace_status
*ts
)
10273 /* Initialize it just to avoid a GCC false warning. */
10275 /* FIXME we need to get register block size some other way. */
10276 extern int trace_regblock_size
;
10277 volatile struct gdb_exception ex
;
10279 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10281 putpkt ("qTStatus");
10283 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10285 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10289 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10293 /* If the remote target doesn't do tracing, flag it. */
10297 /* We're working with a live target. */
10300 /* Set some defaults. */
10301 ts
->running_known
= 0;
10302 ts
->stop_reason
= trace_stop_reason_unknown
;
10303 ts
->traceframe_count
= -1;
10304 ts
->buffer_free
= 0;
10307 error (_("Bogus trace status reply from target: %s"), target_buf
);
10309 parse_trace_status (p
, ts
);
10311 return ts
->running
;
10315 remote_get_tracepoint_status (struct breakpoint
*bp
,
10316 struct uploaded_tp
*utp
)
10318 struct remote_state
*rs
= get_remote_state ();
10320 struct bp_location
*loc
;
10321 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10325 tp
->base
.hit_count
= 0;
10326 tp
->traceframe_usage
= 0;
10327 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10329 /* If the tracepoint was never downloaded, don't go asking for
10331 if (tp
->number_on_target
== 0)
10333 sprintf (rs
->buf
, "qTP:%x:%s", tp
->number_on_target
,
10334 phex_nz (loc
->address
, 0));
10336 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10337 if (reply
&& *reply
)
10340 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10346 utp
->hit_count
= 0;
10347 utp
->traceframe_usage
= 0;
10348 sprintf (rs
->buf
, "qTP:%x:%s", utp
->number
, phex_nz (utp
->addr
, 0));
10350 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10351 if (reply
&& *reply
)
10354 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10360 remote_trace_stop (void)
10363 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10364 if (*target_buf
== '\0')
10365 error (_("Target does not support this command."));
10366 if (strcmp (target_buf
, "OK") != 0)
10367 error (_("Bogus reply from target: %s"), target_buf
);
10371 remote_trace_find (enum trace_find_type type
, int num
,
10372 ULONGEST addr1
, ULONGEST addr2
,
10375 struct remote_state
*rs
= get_remote_state ();
10377 int target_frameno
= -1, target_tracept
= -1;
10379 /* Lookups other than by absolute frame number depend on the current
10380 trace selected, so make sure it is correct on the remote end
10382 if (type
!= tfind_number
)
10383 set_remote_traceframe ();
10386 strcpy (p
, "QTFrame:");
10387 p
= strchr (p
, '\0');
10391 sprintf (p
, "%x", num
);
10394 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10397 sprintf (p
, "tdp:%x", num
);
10400 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10402 case tfind_outside
:
10403 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10406 error (_("Unknown trace find type %d"), type
);
10410 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10411 if (*reply
== '\0')
10412 error (_("Target does not support this command."));
10414 while (reply
&& *reply
)
10419 target_frameno
= (int) strtol (p
, &reply
, 16);
10421 error (_("Unable to parse trace frame number"));
10422 /* Don't update our remote traceframe number cache on failure
10423 to select a remote traceframe. */
10424 if (target_frameno
== -1)
10429 target_tracept
= (int) strtol (p
, &reply
, 16);
10431 error (_("Unable to parse tracepoint number"));
10433 case 'O': /* "OK"? */
10434 if (reply
[1] == 'K' && reply
[2] == '\0')
10437 error (_("Bogus reply from target: %s"), reply
);
10440 error (_("Bogus reply from target: %s"), reply
);
10443 *tpp
= target_tracept
;
10445 remote_traceframe_number
= target_frameno
;
10446 return target_frameno
;
10450 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10452 struct remote_state
*rs
= get_remote_state ();
10456 set_remote_traceframe ();
10458 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10460 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10461 if (reply
&& *reply
)
10465 unpack_varlen_hex (reply
+ 1, &uval
);
10466 *val
= (LONGEST
) uval
;
10474 remote_save_trace_data (const char *filename
)
10476 struct remote_state
*rs
= get_remote_state ();
10480 strcpy (p
, "QTSave:");
10482 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10483 error (_("Remote file name too long for trace save packet"));
10484 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10487 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10488 if (*reply
== '\0')
10489 error (_("Target does not support this command."));
10490 if (strcmp (reply
, "OK") != 0)
10491 error (_("Bogus reply from target: %s"), reply
);
10495 /* This is basically a memory transfer, but needs to be its own packet
10496 because we don't know how the target actually organizes its trace
10497 memory, plus we want to be able to ask for as much as possible, but
10498 not be unhappy if we don't get as much as we ask for. */
10501 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10503 struct remote_state
*rs
= get_remote_state ();
10509 strcpy (p
, "qTBuffer:");
10511 p
+= hexnumstr (p
, offset
);
10513 p
+= hexnumstr (p
, len
);
10517 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10518 if (reply
&& *reply
)
10520 /* 'l' by itself means we're at the end of the buffer and
10521 there is nothing more to get. */
10525 /* Convert the reply into binary. Limit the number of bytes to
10526 convert according to our passed-in buffer size, rather than
10527 what was returned in the packet; if the target is
10528 unexpectedly generous and gives us a bigger reply than we
10529 asked for, we don't want to crash. */
10530 rslt
= hex2bin (target_buf
, buf
, len
);
10534 /* Something went wrong, flag as an error. */
10539 remote_set_disconnected_tracing (int val
)
10541 struct remote_state
*rs
= get_remote_state ();
10543 if (rs
->disconnected_tracing
)
10547 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10549 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10550 if (*reply
== '\0')
10551 error (_("Target does not support this command."));
10552 if (strcmp (reply
, "OK") != 0)
10553 error (_("Bogus reply from target: %s"), reply
);
10556 warning (_("Target does not support disconnected tracing."));
10560 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10562 struct thread_info
*info
= find_thread_ptid (ptid
);
10564 if (info
&& info
->private)
10565 return info
->private->core
;
10570 remote_set_circular_trace_buffer (int val
)
10572 struct remote_state
*rs
= get_remote_state ();
10575 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10577 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10578 if (*reply
== '\0')
10579 error (_("Target does not support this command."));
10580 if (strcmp (reply
, "OK") != 0)
10581 error (_("Bogus reply from target: %s"), reply
);
10584 static struct traceframe_info
*
10585 remote_traceframe_info (void)
10589 text
= target_read_stralloc (¤t_target
,
10590 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10593 struct traceframe_info
*info
;
10594 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10596 info
= parse_traceframe_info (text
);
10597 do_cleanups (back_to
);
10604 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10605 instruction on which a fast tracepoint may be placed. Returns -1
10606 if the packet is not supported, and 0 if the minimum instruction
10607 length is unknown. */
10610 remote_get_min_fast_tracepoint_insn_len (void)
10612 struct remote_state
*rs
= get_remote_state ();
10615 /* If we're not debugging a process yet, the IPA can't be
10617 if (!target_has_execution
)
10620 /* Make sure the remote is pointing at the right process. */
10621 set_general_process ();
10623 sprintf (rs
->buf
, "qTMinFTPILen");
10625 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10626 if (*reply
== '\0')
10630 ULONGEST min_insn_len
;
10632 unpack_varlen_hex (reply
, &min_insn_len
);
10634 return (int) min_insn_len
;
10639 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10641 struct remote_state
*rs
= get_remote_state ();
10643 char *buf
= rs
->buf
;
10644 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10647 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10650 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10651 nbytes
= bin2hex (user
, buf
, 0);
10657 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10658 nbytes
= bin2hex (notes
, buf
, 0);
10664 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10665 nbytes
= bin2hex (stop_notes
, buf
, 0);
10669 /* Ensure the buffer is terminated. */
10673 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10674 if (*reply
== '\0')
10677 if (strcmp (reply
, "OK") != 0)
10678 error (_("Bogus reply from target: %s"), reply
);
10684 init_remote_ops (void)
10686 remote_ops
.to_shortname
= "remote";
10687 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10688 remote_ops
.to_doc
=
10689 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10690 Specify the serial device it is connected to\n\
10691 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10692 remote_ops
.to_open
= remote_open
;
10693 remote_ops
.to_close
= remote_close
;
10694 remote_ops
.to_detach
= remote_detach
;
10695 remote_ops
.to_disconnect
= remote_disconnect
;
10696 remote_ops
.to_resume
= remote_resume
;
10697 remote_ops
.to_wait
= remote_wait
;
10698 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10699 remote_ops
.to_store_registers
= remote_store_registers
;
10700 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10701 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10702 remote_ops
.to_files_info
= remote_files_info
;
10703 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10704 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10705 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10706 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10707 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10708 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10709 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10710 remote_ops
.to_region_ok_for_hw_watchpoint
10711 = remote_region_ok_for_hw_watchpoint
;
10712 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10713 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10714 remote_ops
.to_kill
= remote_kill
;
10715 remote_ops
.to_load
= generic_load
;
10716 remote_ops
.to_mourn_inferior
= remote_mourn
;
10717 remote_ops
.to_pass_signals
= remote_pass_signals
;
10718 remote_ops
.to_thread_alive
= remote_thread_alive
;
10719 remote_ops
.to_find_new_threads
= remote_threads_info
;
10720 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10721 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10722 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10723 remote_ops
.to_stop
= remote_stop
;
10724 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10725 remote_ops
.to_rcmd
= remote_rcmd
;
10726 remote_ops
.to_log_command
= serial_log_command
;
10727 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10728 remote_ops
.to_stratum
= process_stratum
;
10729 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10730 remote_ops
.to_has_memory
= default_child_has_memory
;
10731 remote_ops
.to_has_stack
= default_child_has_stack
;
10732 remote_ops
.to_has_registers
= default_child_has_registers
;
10733 remote_ops
.to_has_execution
= default_child_has_execution
;
10734 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10735 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10736 remote_ops
.to_magic
= OPS_MAGIC
;
10737 remote_ops
.to_memory_map
= remote_memory_map
;
10738 remote_ops
.to_flash_erase
= remote_flash_erase
;
10739 remote_ops
.to_flash_done
= remote_flash_done
;
10740 remote_ops
.to_read_description
= remote_read_description
;
10741 remote_ops
.to_search_memory
= remote_search_memory
;
10742 remote_ops
.to_can_async_p
= remote_can_async_p
;
10743 remote_ops
.to_is_async_p
= remote_is_async_p
;
10744 remote_ops
.to_async
= remote_async
;
10745 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10746 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10747 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10748 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10749 remote_ops
.to_supports_disable_randomization
10750 = remote_supports_disable_randomization
;
10751 remote_ops
.to_fileio_open
= remote_hostio_open
;
10752 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
10753 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
10754 remote_ops
.to_fileio_close
= remote_hostio_close
;
10755 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
10756 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
10757 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10758 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10759 remote_ops
.to_trace_init
= remote_trace_init
;
10760 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10761 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10762 remote_ops
.to_download_trace_state_variable
10763 = remote_download_trace_state_variable
;
10764 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10765 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10766 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10767 remote_ops
.to_trace_start
= remote_trace_start
;
10768 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10769 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
10770 remote_ops
.to_trace_stop
= remote_trace_stop
;
10771 remote_ops
.to_trace_find
= remote_trace_find
;
10772 remote_ops
.to_get_trace_state_variable_value
10773 = remote_get_trace_state_variable_value
;
10774 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10775 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10776 remote_ops
.to_upload_trace_state_variables
10777 = remote_upload_trace_state_variables
;
10778 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10779 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10780 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10781 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10782 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
10783 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10784 remote_ops
.to_verify_memory
= remote_verify_memory
;
10785 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10786 remote_ops
.to_set_permissions
= remote_set_permissions
;
10787 remote_ops
.to_static_tracepoint_marker_at
10788 = remote_static_tracepoint_marker_at
;
10789 remote_ops
.to_static_tracepoint_markers_by_strid
10790 = remote_static_tracepoint_markers_by_strid
;
10791 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10794 /* Set up the extended remote vector by making a copy of the standard
10795 remote vector and adding to it. */
10798 init_extended_remote_ops (void)
10800 extended_remote_ops
= remote_ops
;
10802 extended_remote_ops
.to_shortname
= "extended-remote";
10803 extended_remote_ops
.to_longname
=
10804 "Extended remote serial target in gdb-specific protocol";
10805 extended_remote_ops
.to_doc
=
10806 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10807 Specify the serial device it is connected to (e.g. /dev/ttya).";
10808 extended_remote_ops
.to_open
= extended_remote_open
;
10809 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10810 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10811 extended_remote_ops
.to_detach
= extended_remote_detach
;
10812 extended_remote_ops
.to_attach
= extended_remote_attach
;
10813 extended_remote_ops
.to_kill
= extended_remote_kill
;
10814 extended_remote_ops
.to_supports_disable_randomization
10815 = extended_remote_supports_disable_randomization
;
10819 remote_can_async_p (void)
10821 if (!target_async_permitted
)
10822 /* We only enable async when the user specifically asks for it. */
10825 /* We're async whenever the serial device is. */
10826 return serial_can_async_p (remote_desc
);
10830 remote_is_async_p (void)
10832 if (!target_async_permitted
)
10833 /* We only enable async when the user specifically asks for it. */
10836 /* We're async whenever the serial device is. */
10837 return serial_is_async_p (remote_desc
);
10840 /* Pass the SERIAL event on and up to the client. One day this code
10841 will be able to delay notifying the client of an event until the
10842 point where an entire packet has been received. */
10844 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10846 static void *async_client_context
;
10847 static serial_event_ftype remote_async_serial_handler
;
10850 remote_async_serial_handler (struct serial
*scb
, void *context
)
10852 /* Don't propogate error information up to the client. Instead let
10853 the client find out about the error by querying the target. */
10854 async_client_callback (INF_REG_EVENT
, async_client_context
);
10858 remote_async_inferior_event_handler (gdb_client_data data
)
10860 inferior_event_handler (INF_REG_EVENT
, NULL
);
10864 remote_async_get_pending_events_handler (gdb_client_data data
)
10866 remote_get_pending_stop_replies ();
10870 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10871 void *context
), void *context
)
10873 if (callback
!= NULL
)
10875 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10876 async_client_callback
= callback
;
10877 async_client_context
= context
;
10880 serial_async (remote_desc
, NULL
, NULL
);
10884 set_remote_cmd (char *args
, int from_tty
)
10886 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10890 show_remote_cmd (char *args
, int from_tty
)
10892 /* We can't just use cmd_show_list here, because we want to skip
10893 the redundant "show remote Z-packet" and the legacy aliases. */
10894 struct cleanup
*showlist_chain
;
10895 struct cmd_list_element
*list
= remote_show_cmdlist
;
10896 struct ui_out
*uiout
= current_uiout
;
10898 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10899 for (; list
!= NULL
; list
= list
->next
)
10900 if (strcmp (list
->name
, "Z-packet") == 0)
10902 else if (list
->type
== not_set_cmd
)
10903 /* Alias commands are exactly like the original, except they
10904 don't have the normal type. */
10908 struct cleanup
*option_chain
10909 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10911 ui_out_field_string (uiout
, "name", list
->name
);
10912 ui_out_text (uiout
, ": ");
10913 if (list
->type
== show_cmd
)
10914 do_setshow_command ((char *) NULL
, from_tty
, list
);
10916 cmd_func (list
, NULL
, from_tty
);
10917 /* Close the tuple. */
10918 do_cleanups (option_chain
);
10921 /* Close the tuple. */
10922 do_cleanups (showlist_chain
);
10926 /* Function to be called whenever a new objfile (shlib) is detected. */
10928 remote_new_objfile (struct objfile
*objfile
)
10930 if (remote_desc
!= 0) /* Have a remote connection. */
10931 remote_check_symbols (objfile
);
10934 /* Pull all the tracepoints defined on the target and create local
10935 data structures representing them. We don't want to create real
10936 tracepoints yet, we don't want to mess up the user's existing
10940 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10942 struct remote_state
*rs
= get_remote_state ();
10945 /* Ask for a first packet of tracepoint definition. */
10947 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10949 while (*p
&& *p
!= 'l')
10951 parse_tracepoint_definition (p
, utpp
);
10952 /* Ask for another packet of tracepoint definition. */
10954 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10961 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10963 struct remote_state
*rs
= get_remote_state ();
10966 /* Ask for a first packet of variable definition. */
10968 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10970 while (*p
&& *p
!= 'l')
10972 parse_tsv_definition (p
, utsvp
);
10973 /* Ask for another packet of variable definition. */
10975 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10982 _initialize_remote (void)
10984 struct remote_state
*rs
;
10985 struct cmd_list_element
*cmd
;
10988 /* architecture specific data */
10989 remote_gdbarch_data_handle
=
10990 gdbarch_data_register_post_init (init_remote_state
);
10991 remote_g_packet_data_handle
=
10992 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10994 /* Initialize the per-target state. At the moment there is only one
10995 of these, not one per target. Only one target is active at a
10996 time. The default buffer size is unimportant; it will be expanded
10997 whenever a larger buffer is needed. */
10998 rs
= get_remote_state_raw ();
10999 rs
->buf_size
= 400;
11000 rs
->buf
= xmalloc (rs
->buf_size
);
11002 init_remote_ops ();
11003 add_target (&remote_ops
);
11005 init_extended_remote_ops ();
11006 add_target (&extended_remote_ops
);
11008 /* Hook into new objfile notification. */
11009 observer_attach_new_objfile (remote_new_objfile
);
11011 /* Set up signal handlers. */
11012 sigint_remote_token
=
11013 create_async_signal_handler (async_remote_interrupt
, NULL
);
11014 sigint_remote_twice_token
=
11015 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11018 init_remote_threadtests ();
11021 /* set/show remote ... */
11023 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11024 Remote protocol specific variables\n\
11025 Configure various remote-protocol specific variables such as\n\
11026 the packets being used"),
11027 &remote_set_cmdlist
, "set remote ",
11028 0 /* allow-unknown */, &setlist
);
11029 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11030 Remote protocol specific variables\n\
11031 Configure various remote-protocol specific variables such as\n\
11032 the packets being used"),
11033 &remote_show_cmdlist
, "show remote ",
11034 0 /* allow-unknown */, &showlist
);
11036 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11037 Compare section data on target to the exec file.\n\
11038 Argument is a single section name (default: all loaded sections)."),
11041 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11042 Send an arbitrary packet to a remote target.\n\
11043 maintenance packet TEXT\n\
11044 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11045 this command sends the string TEXT to the inferior, and displays the\n\
11046 response packet. GDB supplies the initial `$' character, and the\n\
11047 terminating `#' character and checksum."),
11050 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11051 Set whether to send break if interrupted."), _("\
11052 Show whether to send break if interrupted."), _("\
11053 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11054 set_remotebreak
, show_remotebreak
,
11055 &setlist
, &showlist
);
11056 cmd_name
= "remotebreak";
11057 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11058 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11059 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11060 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11061 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11063 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11064 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11066 Set interrupt sequence to remote target."), _("\
11067 Show interrupt sequence to remote target."), _("\
11068 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11069 NULL
, show_interrupt_sequence
,
11070 &remote_set_cmdlist
,
11071 &remote_show_cmdlist
);
11073 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11074 &interrupt_on_connect
, _("\
11075 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11076 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11077 If set, interrupt sequence is sent to remote target."),
11079 &remote_set_cmdlist
, &remote_show_cmdlist
);
11081 /* Install commands for configuring memory read/write packets. */
11083 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11084 Set the maximum number of bytes per memory write packet (deprecated)."),
11086 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11087 Show the maximum number of bytes per memory write packet (deprecated)."),
11089 add_cmd ("memory-write-packet-size", no_class
,
11090 set_memory_write_packet_size
, _("\
11091 Set the maximum number of bytes per memory-write packet.\n\
11092 Specify the number of bytes in a packet or 0 (zero) for the\n\
11093 default packet size. The actual limit is further reduced\n\
11094 dependent on the target. Specify ``fixed'' to disable the\n\
11095 further restriction and ``limit'' to enable that restriction."),
11096 &remote_set_cmdlist
);
11097 add_cmd ("memory-read-packet-size", no_class
,
11098 set_memory_read_packet_size
, _("\
11099 Set the maximum number of bytes per memory-read packet.\n\
11100 Specify the number of bytes in a packet or 0 (zero) for the\n\
11101 default packet size. The actual limit is further reduced\n\
11102 dependent on the target. Specify ``fixed'' to disable the\n\
11103 further restriction and ``limit'' to enable that restriction."),
11104 &remote_set_cmdlist
);
11105 add_cmd ("memory-write-packet-size", no_class
,
11106 show_memory_write_packet_size
,
11107 _("Show the maximum number of bytes per memory-write packet."),
11108 &remote_show_cmdlist
);
11109 add_cmd ("memory-read-packet-size", no_class
,
11110 show_memory_read_packet_size
,
11111 _("Show the maximum number of bytes per memory-read packet."),
11112 &remote_show_cmdlist
);
11114 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11115 &remote_hw_watchpoint_limit
, _("\
11116 Set the maximum number of target hardware watchpoints."), _("\
11117 Show the maximum number of target hardware watchpoints."), _("\
11118 Specify a negative limit for unlimited."),
11119 NULL
, NULL
, /* FIXME: i18n: The maximum
11120 number of target hardware
11121 watchpoints is %s. */
11122 &remote_set_cmdlist
, &remote_show_cmdlist
);
11123 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11124 &remote_hw_watchpoint_length_limit
, _("\
11125 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11126 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11127 Specify a negative limit for unlimited."),
11128 NULL
, NULL
, /* FIXME: i18n: The maximum
11129 length (in bytes) of a target
11130 hardware watchpoint is %s. */
11131 &remote_set_cmdlist
, &remote_show_cmdlist
);
11132 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11133 &remote_hw_breakpoint_limit
, _("\
11134 Set the maximum number of target hardware breakpoints."), _("\
11135 Show the maximum number of target hardware breakpoints."), _("\
11136 Specify a negative limit for unlimited."),
11137 NULL
, NULL
, /* FIXME: i18n: The maximum
11138 number of target hardware
11139 breakpoints is %s. */
11140 &remote_set_cmdlist
, &remote_show_cmdlist
);
11142 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
11143 &remote_address_size
, _("\
11144 Set the maximum size of the address (in bits) in a memory packet."), _("\
11145 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11147 NULL
, /* FIXME: i18n: */
11148 &setlist
, &showlist
);
11150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11151 "X", "binary-download", 1);
11153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11154 "vCont", "verbose-resume", 0);
11156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11157 "QPassSignals", "pass-signals", 0);
11159 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11160 "qSymbol", "symbol-lookup", 0);
11162 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11163 "P", "set-register", 1);
11165 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11166 "p", "fetch-register", 1);
11168 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11169 "Z0", "software-breakpoint", 0);
11171 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11172 "Z1", "hardware-breakpoint", 0);
11174 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11175 "Z2", "write-watchpoint", 0);
11177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11178 "Z3", "read-watchpoint", 0);
11180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11181 "Z4", "access-watchpoint", 0);
11183 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11184 "qXfer:auxv:read", "read-aux-vector", 0);
11186 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11187 "qXfer:features:read", "target-features", 0);
11189 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11190 "qXfer:libraries:read", "library-info", 0);
11192 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11193 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11195 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11196 "qXfer:memory-map:read", "memory-map", 0);
11198 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11199 "qXfer:spu:read", "read-spu-object", 0);
11201 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11202 "qXfer:spu:write", "write-spu-object", 0);
11204 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11205 "qXfer:osdata:read", "osdata", 0);
11207 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11208 "qXfer:threads:read", "threads", 0);
11210 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11211 "qXfer:siginfo:read", "read-siginfo-object", 0);
11213 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11214 "qXfer:siginfo:write", "write-siginfo-object", 0);
11216 add_packet_config_cmd
11217 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11218 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11220 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11221 "qGetTLSAddr", "get-thread-local-storage-address",
11224 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11225 "qGetTIBAddr", "get-thread-information-block-address",
11228 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11229 "bc", "reverse-continue", 0);
11231 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11232 "bs", "reverse-step", 0);
11234 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11235 "qSupported", "supported-packets", 0);
11237 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11238 "qSearch:memory", "search-memory", 0);
11240 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11241 "vFile:open", "hostio-open", 0);
11243 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11244 "vFile:pread", "hostio-pread", 0);
11246 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11247 "vFile:pwrite", "hostio-pwrite", 0);
11249 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11250 "vFile:close", "hostio-close", 0);
11252 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11253 "vFile:unlink", "hostio-unlink", 0);
11255 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11256 "vFile:readlink", "hostio-readlink", 0);
11258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11259 "vAttach", "attach", 0);
11261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11265 "QStartNoAckMode", "noack", 0);
11267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11268 "vKill", "kill", 0);
11270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11271 "qAttached", "query-attached", 0);
11273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11274 "ConditionalTracepoints",
11275 "conditional-tracepoints", 0);
11276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11277 "FastTracepoints", "fast-tracepoints", 0);
11279 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11280 "TracepointSource", "TracepointSource", 0);
11282 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11283 "QAllow", "allow", 0);
11285 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11286 "StaticTracepoints", "static-tracepoints", 0);
11288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11289 "InstallInTrace", "install-in-trace", 0);
11291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11292 "qXfer:statictrace:read", "read-sdata-object", 0);
11294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11295 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11297 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11298 "QDisableRandomization", "disable-randomization", 0);
11300 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11301 Z sub-packet has its own set and show commands, but users may
11302 have sets to this variable in their .gdbinit files (or in their
11304 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11305 &remote_Z_packet_detect
, _("\
11306 Set use of remote protocol `Z' packets"), _("\
11307 Show use of remote protocol `Z' packets "), _("\
11308 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11310 set_remote_protocol_Z_packet_cmd
,
11311 show_remote_protocol_Z_packet_cmd
,
11312 /* FIXME: i18n: Use of remote protocol
11313 `Z' packets is %s. */
11314 &remote_set_cmdlist
, &remote_show_cmdlist
);
11316 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11317 Manipulate files on the remote system\n\
11318 Transfer files to and from the remote target system."),
11319 &remote_cmdlist
, "remote ",
11320 0 /* allow-unknown */, &cmdlist
);
11322 add_cmd ("put", class_files
, remote_put_command
,
11323 _("Copy a local file to the remote system."),
11326 add_cmd ("get", class_files
, remote_get_command
,
11327 _("Copy a remote file to the local system."),
11330 add_cmd ("delete", class_files
, remote_delete_command
,
11331 _("Delete a remote file."),
11334 remote_exec_file
= xstrdup ("");
11335 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11336 &remote_exec_file
, _("\
11337 Set the remote pathname for \"run\""), _("\
11338 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11339 &remote_set_cmdlist
, &remote_show_cmdlist
);
11341 /* Eventually initialize fileio. See fileio.c */
11342 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11344 /* Take advantage of the fact that the LWP field is not used, to tag
11345 special ptids with it set to != 0. */
11346 magic_null_ptid
= ptid_build (42000, 1, -1);
11347 not_sent_ptid
= ptid_build (42000, 1, -2);
11348 any_thread_ptid
= ptid_build (42000, 1, 0);
11350 target_buf_size
= 2048;
11351 target_buf
= xmalloc (target_buf_size
);