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 *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. Since we can be connected to a
1444 remote system before before knowing about any inferior, mark the
1445 target with execution when we find the first inferior. If ATTACHED
1446 is 1, then we had just attached to this inferior. If it is 0, then
1447 we just created this inferior. If it is -1, then try querying the
1448 remote stub to find out if it had attached to the inferior or
1451 static struct inferior
*
1452 remote_add_inferior (int pid
, int attached
)
1454 struct inferior
*inf
;
1456 /* Check whether this process we're learning about is to be
1457 considered attached, or if is to be considered to have been
1458 spawned by the stub. */
1460 attached
= remote_query_attached (pid
);
1462 if (gdbarch_has_global_solist (target_gdbarch
))
1464 /* If the target shares code across all inferiors, then every
1465 attach adds a new inferior. */
1466 inf
= add_inferior (pid
);
1468 /* ... and every inferior is bound to the same program space.
1469 However, each inferior may still have its own address
1471 inf
->aspace
= maybe_new_address_space ();
1472 inf
->pspace
= current_program_space
;
1476 /* In the traditional debugging scenario, there's a 1-1 match
1477 between program/address spaces. We simply bind the inferior
1478 to the program space's address space. */
1479 inf
= current_inferior ();
1480 inferior_appeared (inf
, pid
);
1483 inf
->attach_flag
= attached
;
1488 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1489 according to RUNNING. */
1492 remote_add_thread (ptid_t ptid
, int running
)
1496 set_executing (ptid
, running
);
1497 set_running (ptid
, running
);
1500 /* Come here when we learn about a thread id from the remote target.
1501 It may be the first time we hear about such thread, so take the
1502 opportunity to add it to GDB's thread list. In case this is the
1503 first time we're noticing its corresponding inferior, add it to
1504 GDB's inferior list as well. */
1507 remote_notice_new_inferior (ptid_t currthread
, int running
)
1509 /* If this is a new thread, add it to GDB's thread list.
1510 If we leave it up to WFI to do this, bad things will happen. */
1512 if (in_thread_list (currthread
) && is_exited (currthread
))
1514 /* We're seeing an event on a thread id we knew had exited.
1515 This has to be a new thread reusing the old id. Add it. */
1516 remote_add_thread (currthread
, running
);
1520 if (!in_thread_list (currthread
))
1522 struct inferior
*inf
= NULL
;
1523 int pid
= ptid_get_pid (currthread
);
1525 if (ptid_is_pid (inferior_ptid
)
1526 && pid
== ptid_get_pid (inferior_ptid
))
1528 /* inferior_ptid has no thread member yet. This can happen
1529 with the vAttach -> remote_wait,"TAAthread:" path if the
1530 stub doesn't support qC. This is the first stop reported
1531 after an attach, so this is the main thread. Update the
1532 ptid in the thread list. */
1533 if (in_thread_list (pid_to_ptid (pid
)))
1534 thread_change_ptid (inferior_ptid
, currthread
);
1537 remote_add_thread (currthread
, running
);
1538 inferior_ptid
= currthread
;
1543 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1545 /* inferior_ptid is not set yet. This can happen with the
1546 vRun -> remote_wait,"TAAthread:" path if the stub
1547 doesn't support qC. This is the first stop reported
1548 after an attach, so this is the main thread. Update the
1549 ptid in the thread list. */
1550 thread_change_ptid (inferior_ptid
, currthread
);
1554 /* When connecting to a target remote, or to a target
1555 extended-remote which already was debugging an inferior, we
1556 may not know about it yet. Add it before adding its child
1557 thread, so notifications are emitted in a sensible order. */
1558 if (!in_inferior_list (ptid_get_pid (currthread
)))
1559 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1561 /* This is really a new thread. Add it. */
1562 remote_add_thread (currthread
, running
);
1564 /* If we found a new inferior, let the common code do whatever
1565 it needs to with it (e.g., read shared libraries, insert
1568 notice_new_inferior (currthread
, running
, 0);
1572 /* Return the private thread data, creating it if necessary. */
1574 struct private_thread_info
*
1575 demand_private_info (ptid_t ptid
)
1577 struct thread_info
*info
= find_thread_ptid (ptid
);
1583 info
->private = xmalloc (sizeof (*(info
->private)));
1584 info
->private_dtor
= free_private_thread_info
;
1585 info
->private->core
= -1;
1586 info
->private->extra
= 0;
1589 return info
->private;
1592 /* Call this function as a result of
1593 1) A halt indication (T packet) containing a thread id
1594 2) A direct query of currthread
1595 3) Successful execution of set thread */
1598 record_currthread (ptid_t currthread
)
1600 general_thread
= currthread
;
1603 static char *last_pass_packet
;
1605 /* If 'QPassSignals' is supported, tell the remote stub what signals
1606 it can simply pass through to the inferior without reporting. */
1609 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1611 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1613 char *pass_packet
, *p
;
1616 gdb_assert (numsigs
< 256);
1617 for (i
= 0; i
< numsigs
; i
++)
1619 if (pass_signals
[i
])
1622 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1623 strcpy (pass_packet
, "QPassSignals:");
1624 p
= pass_packet
+ strlen (pass_packet
);
1625 for (i
= 0; i
< numsigs
; i
++)
1627 if (pass_signals
[i
])
1630 *p
++ = tohex (i
>> 4);
1631 *p
++ = tohex (i
& 15);
1640 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1642 struct remote_state
*rs
= get_remote_state ();
1643 char *buf
= rs
->buf
;
1645 putpkt (pass_packet
);
1646 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1647 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1648 if (last_pass_packet
)
1649 xfree (last_pass_packet
);
1650 last_pass_packet
= pass_packet
;
1653 xfree (pass_packet
);
1657 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1658 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1659 thread. If GEN is set, set the general thread, if not, then set
1660 the step/continue thread. */
1662 set_thread (struct ptid ptid
, int gen
)
1664 struct remote_state
*rs
= get_remote_state ();
1665 ptid_t state
= gen
? general_thread
: continue_thread
;
1666 char *buf
= rs
->buf
;
1667 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1669 if (ptid_equal (state
, ptid
))
1673 *buf
++ = gen
? 'g' : 'c';
1674 if (ptid_equal (ptid
, magic_null_ptid
))
1675 xsnprintf (buf
, endbuf
- buf
, "0");
1676 else if (ptid_equal (ptid
, any_thread_ptid
))
1677 xsnprintf (buf
, endbuf
- buf
, "0");
1678 else if (ptid_equal (ptid
, minus_one_ptid
))
1679 xsnprintf (buf
, endbuf
- buf
, "-1");
1681 write_ptid (buf
, endbuf
, ptid
);
1683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1685 general_thread
= ptid
;
1687 continue_thread
= ptid
;
1691 set_general_thread (struct ptid ptid
)
1693 set_thread (ptid
, 1);
1697 set_continue_thread (struct ptid ptid
)
1699 set_thread (ptid
, 0);
1702 /* Change the remote current process. Which thread within the process
1703 ends up selected isn't important, as long as it is the same process
1704 as what INFERIOR_PTID points to.
1706 This comes from that fact that there is no explicit notion of
1707 "selected process" in the protocol. The selected process for
1708 general operations is the process the selected general thread
1712 set_general_process (void)
1714 struct remote_state
*rs
= get_remote_state ();
1716 /* If the remote can't handle multiple processes, don't bother. */
1717 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1720 /* We only need to change the remote current thread if it's pointing
1721 at some other process. */
1722 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1723 set_general_thread (inferior_ptid
);
1727 /* Return nonzero if the thread PTID is still alive on the remote
1731 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1733 struct remote_state
*rs
= get_remote_state ();
1736 if (ptid_equal (ptid
, magic_null_ptid
))
1737 /* The main thread is always alive. */
1740 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1741 /* The main thread is always alive. This can happen after a
1742 vAttach, if the remote side doesn't support
1747 endp
= rs
->buf
+ get_remote_packet_size ();
1750 write_ptid (p
, endp
, ptid
);
1753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1754 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1757 /* About these extended threadlist and threadinfo packets. They are
1758 variable length packets but, the fields within them are often fixed
1759 length. They are redundent enough to send over UDP as is the
1760 remote protocol in general. There is a matching unit test module
1763 #define OPAQUETHREADBYTES 8
1765 /* a 64 bit opaque identifier */
1766 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1768 /* WARNING: This threadref data structure comes from the remote O.S.,
1769 libstub protocol encoding, and remote.c. It is not particularly
1772 /* Right now, the internal structure is int. We want it to be bigger.
1773 Plan to fix this. */
1775 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1777 /* gdb_ext_thread_info is an internal GDB data structure which is
1778 equivalent to the reply of the remote threadinfo packet. */
1780 struct gdb_ext_thread_info
1782 threadref threadid
; /* External form of thread reference. */
1783 int active
; /* Has state interesting to GDB?
1785 char display
[256]; /* Brief state display, name,
1786 blocked/suspended. */
1787 char shortname
[32]; /* To be used to name threads. */
1788 char more_display
[256]; /* Long info, statistics, queue depth,
1792 /* The volume of remote transfers can be limited by submitting
1793 a mask containing bits specifying the desired information.
1794 Use a union of these values as the 'selection' parameter to
1795 get_thread_info. FIXME: Make these TAG names more thread specific. */
1797 #define TAG_THREADID 1
1798 #define TAG_EXISTS 2
1799 #define TAG_DISPLAY 4
1800 #define TAG_THREADNAME 8
1801 #define TAG_MOREDISPLAY 16
1803 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1805 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1807 static char *unpack_nibble (char *buf
, int *val
);
1809 static char *pack_nibble (char *buf
, int nibble
);
1811 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1813 static char *unpack_byte (char *buf
, int *value
);
1815 static char *pack_int (char *buf
, int value
);
1817 static char *unpack_int (char *buf
, int *value
);
1819 static char *unpack_string (char *src
, char *dest
, int length
);
1821 static char *pack_threadid (char *pkt
, threadref
*id
);
1823 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1825 void int_to_threadref (threadref
*id
, int value
);
1827 static int threadref_to_int (threadref
*ref
);
1829 static void copy_threadref (threadref
*dest
, threadref
*src
);
1831 static int threadmatch (threadref
*dest
, threadref
*src
);
1833 static char *pack_threadinfo_request (char *pkt
, int mode
,
1836 static int remote_unpack_thread_info_response (char *pkt
,
1837 threadref
*expectedref
,
1838 struct gdb_ext_thread_info
1842 static int remote_get_threadinfo (threadref
*threadid
,
1843 int fieldset
, /*TAG mask */
1844 struct gdb_ext_thread_info
*info
);
1846 static char *pack_threadlist_request (char *pkt
, int startflag
,
1848 threadref
*nextthread
);
1850 static int parse_threadlist_response (char *pkt
,
1852 threadref
*original_echo
,
1853 threadref
*resultlist
,
1856 static int remote_get_threadlist (int startflag
,
1857 threadref
*nextthread
,
1861 threadref
*threadlist
);
1863 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1865 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1866 void *context
, int looplimit
);
1868 static int remote_newthread_step (threadref
*ref
, void *context
);
1871 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1872 buffer we're allowed to write to. Returns
1873 BUF+CHARACTERS_WRITTEN. */
1876 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1879 struct remote_state
*rs
= get_remote_state ();
1881 if (remote_multi_process_p (rs
))
1883 pid
= ptid_get_pid (ptid
);
1885 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1887 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1889 tid
= ptid_get_tid (ptid
);
1891 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1893 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1898 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1899 passed the last parsed char. Returns null_ptid on error. */
1902 read_ptid (char *buf
, char **obuf
)
1906 ULONGEST pid
= 0, tid
= 0;
1910 /* Multi-process ptid. */
1911 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1913 error (_("invalid remote ptid: %s"), p
);
1916 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1919 return ptid_build (pid
, 0, tid
);
1922 /* No multi-process. Just a tid. */
1923 pp
= unpack_varlen_hex (p
, &tid
);
1925 /* Since the stub is not sending a process id, then default to
1926 what's in inferior_ptid, unless it's null at this point. If so,
1927 then since there's no way to know the pid of the reported
1928 threads, use the magic number. */
1929 if (ptid_equal (inferior_ptid
, null_ptid
))
1930 pid
= ptid_get_pid (magic_null_ptid
);
1932 pid
= ptid_get_pid (inferior_ptid
);
1936 return ptid_build (pid
, 0, tid
);
1939 /* Encode 64 bits in 16 chars of hex. */
1941 static const char hexchars
[] = "0123456789abcdef";
1944 ishex (int ch
, int *val
)
1946 if ((ch
>= 'a') && (ch
<= 'f'))
1948 *val
= ch
- 'a' + 10;
1951 if ((ch
>= 'A') && (ch
<= 'F'))
1953 *val
= ch
- 'A' + 10;
1956 if ((ch
>= '0') && (ch
<= '9'))
1967 if (ch
>= 'a' && ch
<= 'f')
1968 return ch
- 'a' + 10;
1969 if (ch
>= '0' && ch
<= '9')
1971 if (ch
>= 'A' && ch
<= 'F')
1972 return ch
- 'A' + 10;
1977 stub_unpack_int (char *buff
, int fieldlength
)
1984 nibble
= stubhex (*buff
++);
1988 retval
= retval
<< 4;
1994 unpack_varlen_hex (char *buff
, /* packet to parse */
1998 ULONGEST retval
= 0;
2000 while (ishex (*buff
, &nibble
))
2003 retval
= retval
<< 4;
2004 retval
|= nibble
& 0x0f;
2011 unpack_nibble (char *buf
, int *val
)
2013 *val
= fromhex (*buf
++);
2018 pack_nibble (char *buf
, int nibble
)
2020 *buf
++ = hexchars
[(nibble
& 0x0f)];
2025 pack_hex_byte (char *pkt
, int byte
)
2027 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2028 *pkt
++ = hexchars
[(byte
& 0xf)];
2033 unpack_byte (char *buf
, int *value
)
2035 *value
= stub_unpack_int (buf
, 2);
2040 pack_int (char *buf
, int value
)
2042 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2043 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2044 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2045 buf
= pack_hex_byte (buf
, (value
& 0xff));
2050 unpack_int (char *buf
, int *value
)
2052 *value
= stub_unpack_int (buf
, 8);
2056 #if 0 /* Currently unused, uncomment when needed. */
2057 static char *pack_string (char *pkt
, char *string
);
2060 pack_string (char *pkt
, char *string
)
2065 len
= strlen (string
);
2067 len
= 200; /* Bigger than most GDB packets, junk??? */
2068 pkt
= pack_hex_byte (pkt
, len
);
2072 if ((ch
== '\0') || (ch
== '#'))
2073 ch
= '*'; /* Protect encapsulation. */
2078 #endif /* 0 (unused) */
2081 unpack_string (char *src
, char *dest
, int length
)
2090 pack_threadid (char *pkt
, threadref
*id
)
2093 unsigned char *altid
;
2095 altid
= (unsigned char *) id
;
2096 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2098 pkt
= pack_hex_byte (pkt
, *altid
++);
2104 unpack_threadid (char *inbuf
, threadref
*id
)
2107 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2110 altref
= (char *) id
;
2112 while (inbuf
< limit
)
2114 x
= stubhex (*inbuf
++);
2115 y
= stubhex (*inbuf
++);
2116 *altref
++ = (x
<< 4) | y
;
2121 /* Externally, threadrefs are 64 bits but internally, they are still
2122 ints. This is due to a mismatch of specifications. We would like
2123 to use 64bit thread references internally. This is an adapter
2127 int_to_threadref (threadref
*id
, int value
)
2129 unsigned char *scan
;
2131 scan
= (unsigned char *) id
;
2137 *scan
++ = (value
>> 24) & 0xff;
2138 *scan
++ = (value
>> 16) & 0xff;
2139 *scan
++ = (value
>> 8) & 0xff;
2140 *scan
++ = (value
& 0xff);
2144 threadref_to_int (threadref
*ref
)
2147 unsigned char *scan
;
2153 value
= (value
<< 8) | ((*scan
++) & 0xff);
2158 copy_threadref (threadref
*dest
, threadref
*src
)
2161 unsigned char *csrc
, *cdest
;
2163 csrc
= (unsigned char *) src
;
2164 cdest
= (unsigned char *) dest
;
2171 threadmatch (threadref
*dest
, threadref
*src
)
2173 /* Things are broken right now, so just assume we got a match. */
2175 unsigned char *srcp
, *destp
;
2177 srcp
= (char *) src
;
2178 destp
= (char *) dest
;
2182 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2189 threadid:1, # always request threadid
2196 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2199 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2201 *pkt
++ = 'q'; /* Info Query */
2202 *pkt
++ = 'P'; /* process or thread info */
2203 pkt
= pack_int (pkt
, mode
); /* mode */
2204 pkt
= pack_threadid (pkt
, id
); /* threadid */
2205 *pkt
= '\0'; /* terminate */
2209 /* These values tag the fields in a thread info response packet. */
2210 /* Tagging the fields allows us to request specific fields and to
2211 add more fields as time goes by. */
2213 #define TAG_THREADID 1 /* Echo the thread identifier. */
2214 #define TAG_EXISTS 2 /* Is this process defined enough to
2215 fetch registers and its stack? */
2216 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2217 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2218 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2222 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2223 struct gdb_ext_thread_info
*info
)
2225 struct remote_state
*rs
= get_remote_state ();
2229 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2232 /* info->threadid = 0; FIXME: implement zero_threadref. */
2234 info
->display
[0] = '\0';
2235 info
->shortname
[0] = '\0';
2236 info
->more_display
[0] = '\0';
2238 /* Assume the characters indicating the packet type have been
2240 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2241 pkt
= unpack_threadid (pkt
, &ref
);
2244 warning (_("Incomplete response to threadinfo request."));
2245 if (!threadmatch (&ref
, expectedref
))
2246 { /* This is an answer to a different request. */
2247 warning (_("ERROR RMT Thread info mismatch."));
2250 copy_threadref (&info
->threadid
, &ref
);
2252 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2254 /* Packets are terminated with nulls. */
2255 while ((pkt
< limit
) && mask
&& *pkt
)
2257 pkt
= unpack_int (pkt
, &tag
); /* tag */
2258 pkt
= unpack_byte (pkt
, &length
); /* length */
2259 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2261 warning (_("ERROR RMT: threadinfo tag mismatch."));
2265 if (tag
== TAG_THREADID
)
2269 warning (_("ERROR RMT: length of threadid is not 16."));
2273 pkt
= unpack_threadid (pkt
, &ref
);
2274 mask
= mask
& ~TAG_THREADID
;
2277 if (tag
== TAG_EXISTS
)
2279 info
->active
= stub_unpack_int (pkt
, length
);
2281 mask
= mask
& ~(TAG_EXISTS
);
2284 warning (_("ERROR RMT: 'exists' length too long."));
2290 if (tag
== TAG_THREADNAME
)
2292 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2293 mask
= mask
& ~TAG_THREADNAME
;
2296 if (tag
== TAG_DISPLAY
)
2298 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2299 mask
= mask
& ~TAG_DISPLAY
;
2302 if (tag
== TAG_MOREDISPLAY
)
2304 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2305 mask
= mask
& ~TAG_MOREDISPLAY
;
2308 warning (_("ERROR RMT: unknown thread info tag."));
2309 break; /* Not a tag we know about. */
2315 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2316 struct gdb_ext_thread_info
*info
)
2318 struct remote_state
*rs
= get_remote_state ();
2321 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2323 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2325 if (rs
->buf
[0] == '\0')
2328 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2333 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2336 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2337 threadref
*nextthread
)
2339 *pkt
++ = 'q'; /* info query packet */
2340 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2341 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2342 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2343 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2348 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2351 parse_threadlist_response (char *pkt
, int result_limit
,
2352 threadref
*original_echo
, threadref
*resultlist
,
2355 struct remote_state
*rs
= get_remote_state ();
2357 int count
, resultcount
, done
;
2360 /* Assume the 'q' and 'M chars have been stripped. */
2361 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2362 /* done parse past here */
2363 pkt
= unpack_byte (pkt
, &count
); /* count field */
2364 pkt
= unpack_nibble (pkt
, &done
);
2365 /* The first threadid is the argument threadid. */
2366 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2367 while ((count
-- > 0) && (pkt
< limit
))
2369 pkt
= unpack_threadid (pkt
, resultlist
++);
2370 if (resultcount
++ >= result_limit
)
2379 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2380 int *done
, int *result_count
, threadref
*threadlist
)
2382 struct remote_state
*rs
= get_remote_state ();
2383 static threadref echo_nextthread
;
2386 /* Trancate result limit to be smaller than the packet size. */
2387 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2388 >= get_remote_packet_size ())
2389 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2391 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2395 if (*rs
->buf
== '\0')
2399 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2402 if (!threadmatch (&echo_nextthread
, nextthread
))
2404 /* FIXME: This is a good reason to drop the packet. */
2405 /* Possably, there is a duplicate response. */
2407 retransmit immediatly - race conditions
2408 retransmit after timeout - yes
2410 wait for packet, then exit
2412 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2413 return 0; /* I choose simply exiting. */
2415 if (*result_count
<= 0)
2419 warning (_("RMT ERROR : failed to get remote thread list."));
2422 return result
; /* break; */
2424 if (*result_count
> result_limit
)
2427 warning (_("RMT ERROR: threadlist response longer than requested."));
2433 /* This is the interface between remote and threads, remotes upper
2436 /* remote_find_new_threads retrieves the thread list and for each
2437 thread in the list, looks up the thread in GDB's internal list,
2438 adding the thread if it does not already exist. This involves
2439 getting partial thread lists from the remote target so, polling the
2440 quit_flag is required. */
2443 /* About this many threadisds fit in a packet. */
2445 #define MAXTHREADLISTRESULTS 32
2448 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2451 int done
, i
, result_count
;
2455 static threadref nextthread
;
2456 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2461 if (loopcount
++ > looplimit
)
2464 warning (_("Remote fetch threadlist -infinite loop-."));
2467 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2468 &done
, &result_count
, resultthreadlist
))
2473 /* Clear for later iterations. */
2475 /* Setup to resume next batch of thread references, set nextthread. */
2476 if (result_count
>= 1)
2477 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2479 while (result_count
--)
2480 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2487 remote_newthread_step (threadref
*ref
, void *context
)
2489 int pid
= ptid_get_pid (inferior_ptid
);
2490 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2492 if (!in_thread_list (ptid
))
2494 return 1; /* continue iterator */
2497 #define CRAZY_MAX_THREADS 1000
2500 remote_current_thread (ptid_t oldpid
)
2502 struct remote_state
*rs
= get_remote_state ();
2505 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2506 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2507 return read_ptid (&rs
->buf
[2], NULL
);
2512 /* Find new threads for info threads command.
2513 * Original version, using John Metzler's thread protocol.
2517 remote_find_new_threads (void)
2519 remote_threadlist_iterator (remote_newthread_step
, 0,
2523 #if defined(HAVE_LIBEXPAT)
2525 typedef struct thread_item
2531 DEF_VEC_O(thread_item_t
);
2533 struct threads_parsing_context
2535 VEC (thread_item_t
) *items
;
2539 start_thread (struct gdb_xml_parser
*parser
,
2540 const struct gdb_xml_element
*element
,
2541 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2543 struct threads_parsing_context
*data
= user_data
;
2545 struct thread_item item
;
2547 struct gdb_xml_value
*attr
;
2549 id
= xml_find_attribute (attributes
, "id")->value
;
2550 item
.ptid
= read_ptid (id
, NULL
);
2552 attr
= xml_find_attribute (attributes
, "core");
2554 item
.core
= *(ULONGEST
*) attr
->value
;
2560 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2564 end_thread (struct gdb_xml_parser
*parser
,
2565 const struct gdb_xml_element
*element
,
2566 void *user_data
, const char *body_text
)
2568 struct threads_parsing_context
*data
= user_data
;
2570 if (body_text
&& *body_text
)
2571 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2574 const struct gdb_xml_attribute thread_attributes
[] = {
2575 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2576 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2577 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2580 const struct gdb_xml_element thread_children
[] = {
2581 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2584 const struct gdb_xml_element threads_children
[] = {
2585 { "thread", thread_attributes
, thread_children
,
2586 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2587 start_thread
, end_thread
},
2588 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2591 const struct gdb_xml_element threads_elements
[] = {
2592 { "threads", NULL
, threads_children
,
2593 GDB_XML_EF_NONE
, NULL
, NULL
},
2594 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2597 /* Discard the contents of the constructed thread info context. */
2600 clear_threads_parsing_context (void *p
)
2602 struct threads_parsing_context
*context
= p
;
2604 struct thread_item
*item
;
2606 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2607 xfree (item
->extra
);
2609 VEC_free (thread_item_t
, context
->items
);
2615 * Find all threads for info threads command.
2616 * Uses new thread protocol contributed by Cisco.
2617 * Falls back and attempts to use the older method (above)
2618 * if the target doesn't respond to the new method.
2622 remote_threads_info (struct target_ops
*ops
)
2624 struct remote_state
*rs
= get_remote_state ();
2628 if (remote_desc
== 0) /* paranoia */
2629 error (_("Command can only be used when connected to the remote target."));
2631 #if defined(HAVE_LIBEXPAT)
2632 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2634 char *xml
= target_read_stralloc (¤t_target
,
2635 TARGET_OBJECT_THREADS
, NULL
);
2637 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2641 struct threads_parsing_context context
;
2643 context
.items
= NULL
;
2644 make_cleanup (clear_threads_parsing_context
, &context
);
2646 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2647 threads_elements
, xml
, &context
) == 0)
2650 struct thread_item
*item
;
2653 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2656 if (!ptid_equal (item
->ptid
, null_ptid
))
2658 struct private_thread_info
*info
;
2659 /* In non-stop mode, we assume new found threads
2660 are running until proven otherwise with a
2661 stop reply. In all-stop, we can only get
2662 here if all threads are stopped. */
2663 int running
= non_stop
? 1 : 0;
2665 remote_notice_new_inferior (item
->ptid
, running
);
2667 info
= demand_private_info (item
->ptid
);
2668 info
->core
= item
->core
;
2669 info
->extra
= item
->extra
;
2676 do_cleanups (back_to
);
2681 if (use_threadinfo_query
)
2683 putpkt ("qfThreadInfo");
2684 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2686 if (bufp
[0] != '\0') /* q packet recognized */
2688 while (*bufp
++ == 'm') /* reply contains one or more TID */
2692 new_thread
= read_ptid (bufp
, &bufp
);
2693 if (!ptid_equal (new_thread
, null_ptid
))
2695 /* In non-stop mode, we assume new found threads
2696 are running until proven otherwise with a
2697 stop reply. In all-stop, we can only get
2698 here if all threads are stopped. */
2699 int running
= non_stop
? 1 : 0;
2701 remote_notice_new_inferior (new_thread
, running
);
2704 while (*bufp
++ == ','); /* comma-separated list */
2705 putpkt ("qsThreadInfo");
2706 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2713 /* Only qfThreadInfo is supported in non-stop mode. */
2717 /* Else fall back to old method based on jmetzler protocol. */
2718 use_threadinfo_query
= 0;
2719 remote_find_new_threads ();
2724 * Collect a descriptive string about the given thread.
2725 * The target may say anything it wants to about the thread
2726 * (typically info about its blocked / runnable state, name, etc.).
2727 * This string will appear in the info threads display.
2729 * Optional: targets are not required to implement this function.
2733 remote_threads_extra_info (struct thread_info
*tp
)
2735 struct remote_state
*rs
= get_remote_state ();
2739 struct gdb_ext_thread_info threadinfo
;
2740 static char display_buf
[100]; /* arbitrary... */
2741 int n
= 0; /* position in display_buf */
2743 if (remote_desc
== 0) /* paranoia */
2744 internal_error (__FILE__
, __LINE__
,
2745 _("remote_threads_extra_info"));
2747 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2748 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2749 /* This is the main thread which was added by GDB. The remote
2750 server doesn't know about it. */
2753 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2755 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2757 if (info
&& info
->private)
2758 return info
->private->extra
;
2763 if (use_threadextra_query
)
2766 char *endb
= rs
->buf
+ get_remote_packet_size ();
2768 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2770 write_ptid (b
, endb
, tp
->ptid
);
2773 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2774 if (rs
->buf
[0] != 0)
2776 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2777 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2778 display_buf
[result
] = '\0';
2783 /* If the above query fails, fall back to the old method. */
2784 use_threadextra_query
= 0;
2785 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2786 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2787 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2788 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2789 if (threadinfo
.active
)
2791 if (*threadinfo
.shortname
)
2792 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2793 " Name: %s,", threadinfo
.shortname
);
2794 if (*threadinfo
.display
)
2795 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2796 " State: %s,", threadinfo
.display
);
2797 if (*threadinfo
.more_display
)
2798 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2799 " Priority: %s", threadinfo
.more_display
);
2803 /* For purely cosmetic reasons, clear up trailing commas. */
2804 if (',' == display_buf
[n
-1])
2805 display_buf
[n
-1] = ' ';
2814 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2815 struct static_tracepoint_marker
*marker
)
2817 struct remote_state
*rs
= get_remote_state ();
2820 sprintf (p
, "qTSTMat:");
2822 p
+= hexnumstr (p
, addr
);
2824 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2828 error (_("Remote failure reply: %s"), p
);
2832 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2840 free_current_marker (void *arg
)
2842 struct static_tracepoint_marker
**marker_p
= arg
;
2844 if (*marker_p
!= NULL
)
2846 release_static_tracepoint_marker (*marker_p
);
2853 static VEC(static_tracepoint_marker_p
) *
2854 remote_static_tracepoint_markers_by_strid (const char *strid
)
2856 struct remote_state
*rs
= get_remote_state ();
2857 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2858 struct static_tracepoint_marker
*marker
= NULL
;
2859 struct cleanup
*old_chain
;
2862 /* Ask for a first packet of static tracepoint marker
2865 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2868 error (_("Remote failure reply: %s"), p
);
2870 old_chain
= make_cleanup (free_current_marker
, &marker
);
2875 marker
= XCNEW (struct static_tracepoint_marker
);
2879 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2881 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2883 VEC_safe_push (static_tracepoint_marker_p
,
2889 release_static_tracepoint_marker (marker
);
2890 memset (marker
, 0, sizeof (*marker
));
2893 while (*p
++ == ','); /* comma-separated list */
2894 /* Ask for another packet of static tracepoint definition. */
2896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2900 do_cleanups (old_chain
);
2905 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2908 remote_get_ada_task_ptid (long lwp
, long thread
)
2910 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2914 /* Restart the remote side; this is an extended protocol operation. */
2917 extended_remote_restart (void)
2919 struct remote_state
*rs
= get_remote_state ();
2921 /* Send the restart command; for reasons I don't understand the
2922 remote side really expects a number after the "R". */
2923 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2926 remote_fileio_reset ();
2929 /* Clean up connection to a remote debugger. */
2932 remote_close (int quitting
)
2934 if (remote_desc
== NULL
)
2935 return; /* already closed */
2937 /* Make sure we leave stdin registered in the event loop, and we
2938 don't leave the async SIGINT signal handler installed. */
2939 remote_terminal_ours ();
2941 serial_close (remote_desc
);
2944 /* We don't have a connection to the remote stub anymore. Get rid
2945 of all the inferiors and their threads we were controlling.
2946 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
2947 will be unable to find the thread corresponding to (pid, 0, 0). */
2948 inferior_ptid
= null_ptid
;
2949 discard_all_inferiors ();
2951 /* We're no longer interested in any of these events. */
2952 discard_pending_stop_replies (-1);
2954 if (remote_async_inferior_event_token
)
2955 delete_async_event_handler (&remote_async_inferior_event_token
);
2956 if (remote_async_get_pending_events_token
)
2957 delete_async_event_handler (&remote_async_get_pending_events_token
);
2960 /* Query the remote side for the text, data and bss offsets. */
2965 struct remote_state
*rs
= get_remote_state ();
2968 int lose
, num_segments
= 0, do_sections
, do_segments
;
2969 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2970 struct section_offsets
*offs
;
2971 struct symfile_segment_data
*data
;
2973 if (symfile_objfile
== NULL
)
2976 putpkt ("qOffsets");
2977 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2980 if (buf
[0] == '\000')
2981 return; /* Return silently. Stub doesn't support
2985 warning (_("Remote failure reply: %s"), buf
);
2989 /* Pick up each field in turn. This used to be done with scanf, but
2990 scanf will make trouble if CORE_ADDR size doesn't match
2991 conversion directives correctly. The following code will work
2992 with any size of CORE_ADDR. */
2993 text_addr
= data_addr
= bss_addr
= 0;
2997 if (strncmp (ptr
, "Text=", 5) == 0)
3000 /* Don't use strtol, could lose on big values. */
3001 while (*ptr
&& *ptr
!= ';')
3002 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3004 if (strncmp (ptr
, ";Data=", 6) == 0)
3007 while (*ptr
&& *ptr
!= ';')
3008 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3013 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3016 while (*ptr
&& *ptr
!= ';')
3017 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3019 if (bss_addr
!= data_addr
)
3020 warning (_("Target reported unsupported offsets: %s"), buf
);
3025 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3028 /* Don't use strtol, could lose on big values. */
3029 while (*ptr
&& *ptr
!= ';')
3030 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3033 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3036 while (*ptr
&& *ptr
!= ';')
3037 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3045 error (_("Malformed response to offset query, %s"), buf
);
3046 else if (*ptr
!= '\0')
3047 warning (_("Target reported unsupported offsets: %s"), buf
);
3049 offs
= ((struct section_offsets
*)
3050 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3051 memcpy (offs
, symfile_objfile
->section_offsets
,
3052 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3054 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3055 do_segments
= (data
!= NULL
);
3056 do_sections
= num_segments
== 0;
3058 if (num_segments
> 0)
3060 segments
[0] = text_addr
;
3061 segments
[1] = data_addr
;
3063 /* If we have two segments, we can still try to relocate everything
3064 by assuming that the .text and .data offsets apply to the whole
3065 text and data segments. Convert the offsets given in the packet
3066 to base addresses for symfile_map_offsets_to_segments. */
3067 else if (data
&& data
->num_segments
== 2)
3069 segments
[0] = data
->segment_bases
[0] + text_addr
;
3070 segments
[1] = data
->segment_bases
[1] + data_addr
;
3073 /* If the object file has only one segment, assume that it is text
3074 rather than data; main programs with no writable data are rare,
3075 but programs with no code are useless. Of course the code might
3076 have ended up in the data segment... to detect that we would need
3077 the permissions here. */
3078 else if (data
&& data
->num_segments
== 1)
3080 segments
[0] = data
->segment_bases
[0] + text_addr
;
3083 /* There's no way to relocate by segment. */
3089 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3090 offs
, num_segments
, segments
);
3092 if (ret
== 0 && !do_sections
)
3093 error (_("Can not handle qOffsets TextSeg "
3094 "response with this symbol file"));
3101 free_symfile_segment_data (data
);
3105 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3107 /* This is a temporary kludge to force data and bss to use the
3108 same offsets because that's what nlmconv does now. The real
3109 solution requires changes to the stub and remote.c that I
3110 don't have time to do right now. */
3112 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3113 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3116 objfile_relocate (symfile_objfile
, offs
);
3119 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3120 threads we know are stopped already. This is used during the
3121 initial remote connection in non-stop mode --- threads that are
3122 reported as already being stopped are left stopped. */
3125 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3127 /* If we have a stop reply for this thread, it must be stopped. */
3128 if (peek_stop_reply (thread
->ptid
))
3129 set_stop_requested (thread
->ptid
, 1);
3134 /* Send interrupt_sequence to remote target. */
3136 send_interrupt_sequence (void)
3138 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3139 serial_write (remote_desc
, "\x03", 1);
3140 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3141 serial_send_break (remote_desc
);
3142 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3144 serial_send_break (remote_desc
);
3145 serial_write (remote_desc
, "g", 1);
3148 internal_error (__FILE__
, __LINE__
,
3149 _("Invalid value for interrupt_sequence_mode: %s."),
3150 interrupt_sequence_mode
);
3154 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3156 struct remote_state
*rs
= get_remote_state ();
3157 struct packet_config
*noack_config
;
3158 char *wait_status
= NULL
;
3160 immediate_quit
++; /* Allow user to interrupt it. */
3162 if (interrupt_on_connect
)
3163 send_interrupt_sequence ();
3165 /* Ack any packet which the remote side has already sent. */
3166 serial_write (remote_desc
, "+", 1);
3168 /* The first packet we send to the target is the optional "supported
3169 packets" request. If the target can answer this, it will tell us
3170 which later probes to skip. */
3171 remote_query_supported ();
3173 /* If the stub wants to get a QAllow, compose one and send it. */
3174 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3175 remote_set_permissions ();
3177 /* Next, we possibly activate noack mode.
3179 If the QStartNoAckMode packet configuration is set to AUTO,
3180 enable noack mode if the stub reported a wish for it with
3183 If set to TRUE, then enable noack mode even if the stub didn't
3184 report it in qSupported. If the stub doesn't reply OK, the
3185 session ends with an error.
3187 If FALSE, then don't activate noack mode, regardless of what the
3188 stub claimed should be the default with qSupported. */
3190 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3192 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3193 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3194 && noack_config
->support
== PACKET_ENABLE
))
3196 putpkt ("QStartNoAckMode");
3197 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3198 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3204 /* Tell the remote that we are using the extended protocol. */
3206 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3209 /* Next, if the target can specify a description, read it. We do
3210 this before anything involving memory or registers. */
3211 target_find_description ();
3213 /* Next, now that we know something about the target, update the
3214 address spaces in the program spaces. */
3215 update_address_spaces ();
3217 /* On OSs where the list of libraries is global to all
3218 processes, we fetch them early. */
3219 if (gdbarch_has_global_solist (target_gdbarch
))
3220 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3224 if (!rs
->non_stop_aware
)
3225 error (_("Non-stop mode requested, but remote "
3226 "does not support non-stop"));
3228 putpkt ("QNonStop:1");
3229 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3231 if (strcmp (rs
->buf
, "OK") != 0)
3232 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3234 /* Find about threads and processes the stub is already
3235 controlling. We default to adding them in the running state.
3236 The '?' query below will then tell us about which threads are
3238 remote_threads_info (target
);
3240 else if (rs
->non_stop_aware
)
3242 /* Don't assume that the stub can operate in all-stop mode.
3243 Request it explicitely. */
3244 putpkt ("QNonStop:0");
3245 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3247 if (strcmp (rs
->buf
, "OK") != 0)
3248 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3251 /* Check whether the target is running now. */
3253 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3259 struct inferior
*inf
;
3261 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3264 error (_("The target is not running (try extended-remote?)"));
3266 /* We're connected, but not running. Drop out before we
3267 call start_remote. */
3272 /* Save the reply for later. */
3273 wait_status
= alloca (strlen (rs
->buf
) + 1);
3274 strcpy (wait_status
, rs
->buf
);
3277 /* Let the stub know that we want it to return the thread. */
3278 set_continue_thread (minus_one_ptid
);
3280 inferior_ptid
= minus_one_ptid
;
3282 /* Now, if we have thread information, update inferior_ptid. */
3283 ptid
= remote_current_thread (inferior_ptid
);
3284 if (!ptid_equal (ptid
, minus_one_ptid
))
3286 if (ptid_get_pid (ptid
) == -1)
3288 ptid
= ptid_build (ptid_get_pid (magic_null_ptid
),
3289 ptid_get_lwp (ptid
),
3290 ptid_get_tid (ptid
));
3294 inferior_ptid
= ptid
;
3298 /* Without this, some commands which require an active
3299 target (such as kill) won't work. This variable serves
3300 (at least) double duty as both the pid of the target
3301 process (if it has such), and as a flag indicating that a
3302 target is active. These functions should be split out
3303 into seperate variables, especially since GDB will
3304 someday have a notion of debugging several processes. */
3305 inferior_ptid
= magic_null_ptid
;
3309 inf
= remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3310 inf
->fake_pid_p
= fake_pid_p
;
3312 /* Always add the main thread. */
3313 add_thread_silent (inferior_ptid
);
3315 /* init_wait_for_inferior should be called before get_offsets in order
3316 to manage `inserted' flag in bp loc in a correct state.
3317 breakpoint_init_inferior, called from init_wait_for_inferior, set
3318 `inserted' flag to 0, while before breakpoint_re_set, called from
3319 start_remote, set `inserted' flag to 1. In the initialization of
3320 inferior, breakpoint_init_inferior should be called first, and then
3321 breakpoint_re_set can be called. If this order is broken, state of
3322 `inserted' flag is wrong, and cause some problems on breakpoint
3324 init_wait_for_inferior ();
3326 get_offsets (); /* Get text, data & bss offsets. */
3328 /* If we could not find a description using qXfer, and we know
3329 how to do it some other way, try again. This is not
3330 supported for non-stop; it could be, but it is tricky if
3331 there are no stopped threads when we connect. */
3332 if (remote_read_description_p (target
)
3333 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3335 target_clear_description ();
3336 target_find_description ();
3339 /* Use the previously fetched status. */
3340 gdb_assert (wait_status
!= NULL
);
3341 strcpy (rs
->buf
, wait_status
);
3342 rs
->cached_wait_status
= 1;
3345 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3349 /* Clear WFI global state. Do this before finding about new
3350 threads and inferiors, and setting the current inferior.
3351 Otherwise we would clear the proceed status of the current
3352 inferior when we want its stop_soon state to be preserved
3353 (see notice_new_inferior). */
3354 init_wait_for_inferior ();
3356 /* In non-stop, we will either get an "OK", meaning that there
3357 are no stopped threads at this time; or, a regular stop
3358 reply. In the latter case, there may be more than one thread
3359 stopped --- we pull them all out using the vStopped
3361 if (strcmp (rs
->buf
, "OK") != 0)
3363 struct stop_reply
*stop_reply
;
3364 struct cleanup
*old_chain
;
3366 stop_reply
= stop_reply_xmalloc ();
3367 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3369 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3370 discard_cleanups (old_chain
);
3372 /* get_pending_stop_replies acks this one, and gets the rest
3374 pending_stop_reply
= stop_reply
;
3375 remote_get_pending_stop_replies ();
3377 /* Make sure that threads that were stopped remain
3379 iterate_over_threads (set_stop_requested_callback
, NULL
);
3382 if (target_can_async_p ())
3383 target_async (inferior_event_handler
, 0);
3385 if (thread_count () == 0)
3388 error (_("The target is not running (try extended-remote?)"));
3390 /* We're connected, but not running. Drop out before we
3391 call start_remote. */
3395 /* Let the stub know that we want it to return the thread. */
3397 /* Force the stub to choose a thread. */
3398 set_general_thread (null_ptid
);
3401 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3402 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3403 error (_("remote didn't report the current thread in non-stop mode"));
3405 get_offsets (); /* Get text, data & bss offsets. */
3407 /* In non-stop mode, any cached wait status will be stored in
3408 the stop reply queue. */
3409 gdb_assert (wait_status
== NULL
);
3411 /* Report all signals during attach/startup. */
3412 remote_pass_signals (0, NULL
);
3415 /* If we connected to a live target, do some additional setup. */
3416 if (target_has_execution
)
3418 if (exec_bfd
) /* No use without an exec file. */
3419 remote_check_symbols (symfile_objfile
);
3422 /* Possibly the target has been engaged in a trace run started
3423 previously; find out where things are at. */
3424 if (remote_get_trace_status (current_trace_status ()) != -1)
3426 struct uploaded_tp
*uploaded_tps
= NULL
;
3427 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3429 if (current_trace_status ()->running
)
3430 printf_filtered (_("Trace is already running on the target.\n"));
3432 /* Get trace state variables first, they may be checked when
3433 parsing uploaded commands. */
3435 remote_upload_trace_state_variables (&uploaded_tsvs
);
3437 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3439 remote_upload_tracepoints (&uploaded_tps
);
3441 merge_uploaded_tracepoints (&uploaded_tps
);
3444 /* If breakpoints are global, insert them now. */
3445 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3446 && breakpoints_always_inserted_mode ())
3447 insert_breakpoints ();
3450 /* Open a connection to a remote debugger.
3451 NAME is the filename used for communication. */
3454 remote_open (char *name
, int from_tty
)
3456 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3459 /* Open a connection to a remote debugger using the extended
3460 remote gdb protocol. NAME is the filename used for communication. */
3463 extended_remote_open (char *name
, int from_tty
)
3465 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3468 /* Generic code for opening a connection to a remote target. */
3471 init_all_packet_configs (void)
3475 for (i
= 0; i
< PACKET_MAX
; i
++)
3476 update_packet_config (&remote_protocol_packets
[i
]);
3479 /* Symbol look-up. */
3482 remote_check_symbols (struct objfile
*objfile
)
3484 struct remote_state
*rs
= get_remote_state ();
3485 char *msg
, *reply
, *tmp
;
3486 struct minimal_symbol
*sym
;
3489 /* The remote side has no concept of inferiors that aren't running
3490 yet, it only knows about running processes. If we're connected
3491 but our current inferior is not running, we should not invite the
3492 remote target to request symbol lookups related to its
3493 (unrelated) current process. */
3494 if (!target_has_execution
)
3497 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3500 /* Make sure the remote is pointing at the right process. Note
3501 there's no way to select "no process". */
3502 set_general_process ();
3504 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3505 because we need both at the same time. */
3506 msg
= alloca (get_remote_packet_size ());
3508 /* Invite target to request symbol lookups. */
3510 putpkt ("qSymbol::");
3511 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3512 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3515 while (strncmp (reply
, "qSymbol:", 8) == 0)
3518 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3520 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3522 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3525 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3526 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3528 /* If this is a function address, return the start of code
3529 instead of any data function descriptor. */
3530 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3534 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3535 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3539 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3544 static struct serial
*
3545 remote_serial_open (char *name
)
3547 static int udp_warning
= 0;
3549 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3550 of in ser-tcp.c, because it is the remote protocol assuming that the
3551 serial connection is reliable and not the serial connection promising
3553 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3555 warning (_("The remote protocol may be unreliable over UDP.\n"
3556 "Some events may be lost, rendering further debugging "
3561 return serial_open (name
);
3564 /* Inform the target of our permission settings. The permission flags
3565 work without this, but if the target knows the settings, it can do
3566 a couple things. First, it can add its own check, to catch cases
3567 that somehow manage to get by the permissions checks in target
3568 methods. Second, if the target is wired to disallow particular
3569 settings (for instance, a system in the field that is not set up to
3570 be able to stop at a breakpoint), it can object to any unavailable
3574 remote_set_permissions (void)
3576 struct remote_state
*rs
= get_remote_state ();
3578 sprintf (rs
->buf
, "QAllow:"
3579 "WriteReg:%x;WriteMem:%x;"
3580 "InsertBreak:%x;InsertTrace:%x;"
3581 "InsertFastTrace:%x;Stop:%x",
3582 may_write_registers
, may_write_memory
,
3583 may_insert_breakpoints
, may_insert_tracepoints
,
3584 may_insert_fast_tracepoints
, may_stop
);
3586 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3588 /* If the target didn't like the packet, warn the user. Do not try
3589 to undo the user's settings, that would just be maddening. */
3590 if (strcmp (rs
->buf
, "OK") != 0)
3591 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3594 /* This type describes each known response to the qSupported
3596 struct protocol_feature
3598 /* The name of this protocol feature. */
3601 /* The default for this protocol feature. */
3602 enum packet_support default_support
;
3604 /* The function to call when this feature is reported, or after
3605 qSupported processing if the feature is not supported.
3606 The first argument points to this structure. The second
3607 argument indicates whether the packet requested support be
3608 enabled, disabled, or probed (or the default, if this function
3609 is being called at the end of processing and this feature was
3610 not reported). The third argument may be NULL; if not NULL, it
3611 is a NUL-terminated string taken from the packet following
3612 this feature's name and an equals sign. */
3613 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3616 /* The corresponding packet for this feature. Only used if
3617 FUNC is remote_supported_packet. */
3622 remote_supported_packet (const struct protocol_feature
*feature
,
3623 enum packet_support support
,
3624 const char *argument
)
3628 warning (_("Remote qSupported response supplied an unexpected value for"
3629 " \"%s\"."), feature
->name
);
3633 if (remote_protocol_packets
[feature
->packet
].support
3634 == PACKET_SUPPORT_UNKNOWN
)
3635 remote_protocol_packets
[feature
->packet
].support
= support
;
3639 remote_packet_size (const struct protocol_feature
*feature
,
3640 enum packet_support support
, const char *value
)
3642 struct remote_state
*rs
= get_remote_state ();
3647 if (support
!= PACKET_ENABLE
)
3650 if (value
== NULL
|| *value
== '\0')
3652 warning (_("Remote target reported \"%s\" without a size."),
3658 packet_size
= strtol (value
, &value_end
, 16);
3659 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3661 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3662 feature
->name
, value
);
3666 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3668 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3669 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3670 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3673 /* Record the new maximum packet size. */
3674 rs
->explicit_packet_size
= packet_size
;
3678 remote_multi_process_feature (const struct protocol_feature
*feature
,
3679 enum packet_support support
, const char *value
)
3681 struct remote_state
*rs
= get_remote_state ();
3683 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3687 remote_non_stop_feature (const struct protocol_feature
*feature
,
3688 enum packet_support support
, const char *value
)
3690 struct remote_state
*rs
= get_remote_state ();
3692 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3696 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3697 enum packet_support support
,
3700 struct remote_state
*rs
= get_remote_state ();
3702 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3706 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3707 enum packet_support support
,
3710 struct remote_state
*rs
= get_remote_state ();
3712 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3716 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3717 enum packet_support support
,
3720 struct remote_state
*rs
= get_remote_state ();
3722 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3726 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3727 enum packet_support support
,
3730 struct remote_state
*rs
= get_remote_state ();
3732 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3736 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3737 enum packet_support support
,
3740 struct remote_state
*rs
= get_remote_state ();
3742 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3746 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3747 enum packet_support support
,
3750 struct remote_state
*rs
= get_remote_state ();
3752 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3756 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3757 enum packet_support support
,
3760 struct remote_state
*rs
= get_remote_state ();
3762 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3765 static struct protocol_feature remote_protocol_features
[] = {
3766 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3767 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3768 PACKET_qXfer_auxv
},
3769 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3770 PACKET_qXfer_features
},
3771 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3772 PACKET_qXfer_libraries
},
3773 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3774 PACKET_qXfer_libraries_svr4
},
3775 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3776 PACKET_qXfer_memory_map
},
3777 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3778 PACKET_qXfer_spu_read
},
3779 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3780 PACKET_qXfer_spu_write
},
3781 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3782 PACKET_qXfer_osdata
},
3783 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3784 PACKET_qXfer_threads
},
3785 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3786 PACKET_qXfer_traceframe_info
},
3787 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3788 PACKET_QPassSignals
},
3789 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3790 PACKET_QStartNoAckMode
},
3791 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3792 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3793 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3794 PACKET_qXfer_siginfo_read
},
3795 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3796 PACKET_qXfer_siginfo_write
},
3797 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3798 PACKET_ConditionalTracepoints
},
3799 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3800 PACKET_FastTracepoints
},
3801 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3802 PACKET_StaticTracepoints
},
3803 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3804 PACKET_InstallInTrace
},
3805 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3807 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3809 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3811 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3812 PACKET_TracepointSource
},
3813 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3815 { "EnableDisableTracepoints", PACKET_DISABLE
,
3816 remote_enable_disable_tracepoint_feature
, -1 },
3817 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3818 PACKET_qXfer_fdpic
},
3819 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3820 PACKET_QDisableRandomization
},
3821 { "tracenz", PACKET_DISABLE
,
3822 remote_string_tracing_feature
, -1 },
3825 static char *remote_support_xml
;
3827 /* Register string appended to "xmlRegisters=" in qSupported query. */
3830 register_remote_support_xml (const char *xml
)
3832 #if defined(HAVE_LIBEXPAT)
3833 if (remote_support_xml
== NULL
)
3834 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3837 char *copy
= xstrdup (remote_support_xml
+ 13);
3838 char *p
= strtok (copy
, ",");
3842 if (strcmp (p
, xml
) == 0)
3849 while ((p
= strtok (NULL
, ",")) != NULL
);
3852 remote_support_xml
= reconcat (remote_support_xml
,
3853 remote_support_xml
, ",", xml
,
3860 remote_query_supported_append (char *msg
, const char *append
)
3863 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3865 return xstrdup (append
);
3869 remote_query_supported (void)
3871 struct remote_state
*rs
= get_remote_state ();
3874 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3876 /* The packet support flags are handled differently for this packet
3877 than for most others. We treat an error, a disabled packet, and
3878 an empty response identically: any features which must be reported
3879 to be used will be automatically disabled. An empty buffer
3880 accomplishes this, since that is also the representation for a list
3881 containing no features. */
3884 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3887 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3889 q
= remote_query_supported_append (q
, "multiprocess+");
3891 if (remote_support_xml
)
3892 q
= remote_query_supported_append (q
, remote_support_xml
);
3894 q
= remote_query_supported_append (q
, "qRelocInsn+");
3896 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3899 do_cleanups (old_chain
);
3901 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3903 /* If an error occured, warn, but do not return - just reset the
3904 buffer to empty and go on to disable features. */
3905 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3908 warning (_("Remote failure reply: %s"), rs
->buf
);
3913 memset (seen
, 0, sizeof (seen
));
3918 enum packet_support is_supported
;
3919 char *p
, *end
, *name_end
, *value
;
3921 /* First separate out this item from the rest of the packet. If
3922 there's another item after this, we overwrite the separator
3923 (terminated strings are much easier to work with). */
3925 end
= strchr (p
, ';');
3928 end
= p
+ strlen (p
);
3938 warning (_("empty item in \"qSupported\" response"));
3943 name_end
= strchr (p
, '=');
3946 /* This is a name=value entry. */
3947 is_supported
= PACKET_ENABLE
;
3948 value
= name_end
+ 1;
3957 is_supported
= PACKET_ENABLE
;
3961 is_supported
= PACKET_DISABLE
;
3965 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3969 warning (_("unrecognized item \"%s\" "
3970 "in \"qSupported\" response"), p
);
3976 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3977 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3979 const struct protocol_feature
*feature
;
3982 feature
= &remote_protocol_features
[i
];
3983 feature
->func (feature
, is_supported
, value
);
3988 /* If we increased the packet size, make sure to increase the global
3989 buffer size also. We delay this until after parsing the entire
3990 qSupported packet, because this is the same buffer we were
3992 if (rs
->buf_size
< rs
->explicit_packet_size
)
3994 rs
->buf_size
= rs
->explicit_packet_size
;
3995 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3998 /* Handle the defaults for unmentioned features. */
3999 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4002 const struct protocol_feature
*feature
;
4004 feature
= &remote_protocol_features
[i
];
4005 feature
->func (feature
, feature
->default_support
, NULL
);
4011 remote_open_1 (char *name
, int from_tty
,
4012 struct target_ops
*target
, int extended_p
)
4014 struct remote_state
*rs
= get_remote_state ();
4017 error (_("To open a remote debug connection, you need to specify what\n"
4018 "serial device is attached to the remote system\n"
4019 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4021 /* See FIXME above. */
4022 if (!target_async_permitted
)
4023 wait_forever_enabled_p
= 1;
4025 /* If we're connected to a running target, target_preopen will kill it.
4026 But if we're connected to a target system with no running process,
4027 then we will still be connected when it returns. Ask this question
4028 first, before target_preopen has a chance to kill anything. */
4029 if (remote_desc
!= NULL
&& !have_inferiors ())
4032 || query (_("Already connected to a remote target. Disconnect? ")))
4035 error (_("Still connected."));
4038 target_preopen (from_tty
);
4040 unpush_target (target
);
4042 /* This time without a query. If we were connected to an
4043 extended-remote target and target_preopen killed the running
4044 process, we may still be connected. If we are starting "target
4045 remote" now, the extended-remote target will not have been
4046 removed by unpush_target. */
4047 if (remote_desc
!= NULL
&& !have_inferiors ())
4050 /* Make sure we send the passed signals list the next time we resume. */
4051 xfree (last_pass_packet
);
4052 last_pass_packet
= NULL
;
4054 remote_fileio_reset ();
4055 reopen_exec_file ();
4058 remote_desc
= remote_serial_open (name
);
4060 perror_with_name (name
);
4062 if (baud_rate
!= -1)
4064 if (serial_setbaudrate (remote_desc
, baud_rate
))
4066 /* The requested speed could not be set. Error out to
4067 top level after closing remote_desc. Take care to
4068 set remote_desc to NULL to avoid closing remote_desc
4070 serial_close (remote_desc
);
4072 perror_with_name (name
);
4076 serial_raw (remote_desc
);
4078 /* If there is something sitting in the buffer we might take it as a
4079 response to a command, which would be bad. */
4080 serial_flush_input (remote_desc
);
4084 puts_filtered ("Remote debugging using ");
4085 puts_filtered (name
);
4086 puts_filtered ("\n");
4088 push_target (target
); /* Switch to using remote target now. */
4090 /* Register extra event sources in the event loop. */
4091 remote_async_inferior_event_token
4092 = create_async_event_handler (remote_async_inferior_event_handler
,
4094 remote_async_get_pending_events_token
4095 = create_async_event_handler (remote_async_get_pending_events_handler
,
4098 /* Reset the target state; these things will be queried either by
4099 remote_query_supported or as they are needed. */
4100 init_all_packet_configs ();
4101 rs
->cached_wait_status
= 0;
4102 rs
->explicit_packet_size
= 0;
4104 rs
->multi_process_aware
= 0;
4105 rs
->extended
= extended_p
;
4106 rs
->non_stop_aware
= 0;
4107 rs
->waiting_for_stop_reply
= 0;
4108 rs
->ctrlc_pending_p
= 0;
4110 general_thread
= not_sent_ptid
;
4111 continue_thread
= not_sent_ptid
;
4112 remote_traceframe_number
= -1;
4114 /* Probe for ability to use "ThreadInfo" query, as required. */
4115 use_threadinfo_query
= 1;
4116 use_threadextra_query
= 1;
4118 if (target_async_permitted
)
4120 /* With this target we start out by owning the terminal. */
4121 remote_async_terminal_ours_p
= 1;
4123 /* FIXME: cagney/1999-09-23: During the initial connection it is
4124 assumed that the target is already ready and able to respond to
4125 requests. Unfortunately remote_start_remote() eventually calls
4126 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4127 around this. Eventually a mechanism that allows
4128 wait_for_inferior() to expect/get timeouts will be
4130 wait_forever_enabled_p
= 0;
4133 /* First delete any symbols previously loaded from shared libraries. */
4134 no_shared_libraries (NULL
, 0);
4137 init_thread_list ();
4139 /* Start the remote connection. If error() or QUIT, discard this
4140 target (we'd otherwise be in an inconsistent state) and then
4141 propogate the error on up the exception chain. This ensures that
4142 the caller doesn't stumble along blindly assuming that the
4143 function succeeded. The CLI doesn't have this problem but other
4144 UI's, such as MI do.
4146 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4147 this function should return an error indication letting the
4148 caller restore the previous state. Unfortunately the command
4149 ``target remote'' is directly wired to this function making that
4150 impossible. On a positive note, the CLI side of this problem has
4151 been fixed - the function set_cmd_context() makes it possible for
4152 all the ``target ....'' commands to share a common callback
4153 function. See cli-dump.c. */
4155 volatile struct gdb_exception ex
;
4157 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4159 remote_start_remote (from_tty
, target
, extended_p
);
4163 /* Pop the partially set up target - unless something else did
4164 already before throwing the exception. */
4165 if (remote_desc
!= NULL
)
4167 if (target_async_permitted
)
4168 wait_forever_enabled_p
= 1;
4169 throw_exception (ex
);
4173 if (target_async_permitted
)
4174 wait_forever_enabled_p
= 1;
4177 /* This takes a program previously attached to and detaches it. After
4178 this is done, GDB can be used to debug some other program. We
4179 better not have left any breakpoints in the target program or it'll
4180 die when it hits one. */
4183 remote_detach_1 (char *args
, int from_tty
, int extended
)
4185 int pid
= ptid_get_pid (inferior_ptid
);
4186 struct remote_state
*rs
= get_remote_state ();
4189 error (_("Argument given to \"detach\" when remotely debugging."));
4191 if (!target_has_execution
)
4192 error (_("No process to detach from."));
4194 /* Tell the remote target to detach. */
4195 if (remote_multi_process_p (rs
))
4196 sprintf (rs
->buf
, "D;%x", pid
);
4198 strcpy (rs
->buf
, "D");
4201 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4203 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4205 else if (rs
->buf
[0] == '\0')
4206 error (_("Remote doesn't know how to detach"));
4208 error (_("Can't detach process."));
4212 if (remote_multi_process_p (rs
))
4213 printf_filtered (_("Detached from remote %s.\n"),
4214 target_pid_to_str (pid_to_ptid (pid
)));
4218 puts_filtered (_("Detached from remote process.\n"));
4220 puts_filtered (_("Ending remote debugging.\n"));
4224 discard_pending_stop_replies (pid
);
4225 target_mourn_inferior ();
4229 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4231 remote_detach_1 (args
, from_tty
, 0);
4235 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4237 remote_detach_1 (args
, from_tty
, 1);
4240 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4243 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4246 error (_("Argument given to \"disconnect\" when remotely debugging."));
4248 /* Make sure we unpush even the extended remote targets; mourn
4249 won't do it. So call remote_mourn_1 directly instead of
4250 target_mourn_inferior. */
4251 remote_mourn_1 (target
);
4254 puts_filtered ("Ending remote debugging.\n");
4257 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4258 be chatty about it. */
4261 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4263 struct remote_state
*rs
= get_remote_state ();
4265 char *wait_status
= NULL
;
4267 pid
= parse_pid_to_attach (args
);
4269 /* Remote PID can be freely equal to getpid, do not check it here the same
4270 way as in other targets. */
4272 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4273 error (_("This target does not support attaching to a process"));
4275 sprintf (rs
->buf
, "vAttach;%x", pid
);
4277 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4279 if (packet_ok (rs
->buf
,
4280 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4283 printf_unfiltered (_("Attached to %s\n"),
4284 target_pid_to_str (pid_to_ptid (pid
)));
4288 /* Save the reply for later. */
4289 wait_status
= alloca (strlen (rs
->buf
) + 1);
4290 strcpy (wait_status
, rs
->buf
);
4292 else if (strcmp (rs
->buf
, "OK") != 0)
4293 error (_("Attaching to %s failed with: %s"),
4294 target_pid_to_str (pid_to_ptid (pid
)),
4297 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4298 error (_("This target does not support attaching to a process"));
4300 error (_("Attaching to %s failed"),
4301 target_pid_to_str (pid_to_ptid (pid
)));
4303 set_current_inferior (remote_add_inferior (pid
, 1));
4305 inferior_ptid
= pid_to_ptid (pid
);
4309 struct thread_info
*thread
;
4311 /* Get list of threads. */
4312 remote_threads_info (target
);
4314 thread
= first_thread_of_process (pid
);
4316 inferior_ptid
= thread
->ptid
;
4318 inferior_ptid
= pid_to_ptid (pid
);
4320 /* Invalidate our notion of the remote current thread. */
4321 record_currthread (minus_one_ptid
);
4325 /* Now, if we have thread information, update inferior_ptid. */
4326 inferior_ptid
= remote_current_thread (inferior_ptid
);
4328 /* Add the main thread to the thread list. */
4329 add_thread_silent (inferior_ptid
);
4332 /* Next, if the target can specify a description, read it. We do
4333 this before anything involving memory or registers. */
4334 target_find_description ();
4338 /* Use the previously fetched status. */
4339 gdb_assert (wait_status
!= NULL
);
4341 if (target_can_async_p ())
4343 struct stop_reply
*stop_reply
;
4344 struct cleanup
*old_chain
;
4346 stop_reply
= stop_reply_xmalloc ();
4347 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4348 remote_parse_stop_reply (wait_status
, stop_reply
);
4349 discard_cleanups (old_chain
);
4350 push_stop_reply (stop_reply
);
4352 target_async (inferior_event_handler
, 0);
4356 gdb_assert (wait_status
!= NULL
);
4357 strcpy (rs
->buf
, wait_status
);
4358 rs
->cached_wait_status
= 1;
4362 gdb_assert (wait_status
== NULL
);
4366 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4368 extended_remote_attach_1 (ops
, args
, from_tty
);
4371 /* Convert hex digit A to a number. */
4376 if (a
>= '0' && a
<= '9')
4378 else if (a
>= 'a' && a
<= 'f')
4379 return a
- 'a' + 10;
4380 else if (a
>= 'A' && a
<= 'F')
4381 return a
- 'A' + 10;
4383 error (_("Reply contains invalid hex digit %d"), a
);
4387 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4391 for (i
= 0; i
< count
; i
++)
4393 if (hex
[0] == 0 || hex
[1] == 0)
4395 /* Hex string is short, or of uneven length.
4396 Return the count that has been converted so far. */
4399 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4405 /* Convert number NIB to a hex digit. */
4413 return 'a' + nib
- 10;
4417 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4421 /* May use a length, or a nul-terminated string as input. */
4423 count
= strlen ((char *) bin
);
4425 for (i
= 0; i
< count
; i
++)
4427 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4428 *hex
++ = tohex (*bin
++ & 0xf);
4434 /* Check for the availability of vCont. This function should also check
4438 remote_vcont_probe (struct remote_state
*rs
)
4442 strcpy (rs
->buf
, "vCont?");
4444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4447 /* Make sure that the features we assume are supported. */
4448 if (strncmp (buf
, "vCont", 5) == 0)
4451 int support_s
, support_S
, support_c
, support_C
;
4457 rs
->support_vCont_t
= 0;
4458 while (p
&& *p
== ';')
4461 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4463 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4465 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4467 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4469 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4470 rs
->support_vCont_t
= 1;
4472 p
= strchr (p
, ';');
4475 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4476 BUF will make packet_ok disable the packet. */
4477 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4481 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4484 /* Helper function for building "vCont" resumptions. Write a
4485 resumption to P. ENDP points to one-passed-the-end of the buffer
4486 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4487 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4488 resumed thread should be single-stepped and/or signalled. If PTID
4489 equals minus_one_ptid, then all threads are resumed; if PTID
4490 represents a process, then all threads of the process are resumed;
4491 the thread to be stepped and/or signalled is given in the global
4495 append_resumption (char *p
, char *endp
,
4496 ptid_t ptid
, int step
, enum target_signal siggnal
)
4498 struct remote_state
*rs
= get_remote_state ();
4500 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4501 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4503 p
+= xsnprintf (p
, endp
- p
, ";s");
4504 else if (siggnal
!= TARGET_SIGNAL_0
)
4505 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4507 p
+= xsnprintf (p
, endp
- p
, ";c");
4509 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4513 /* All (-1) threads of process. */
4514 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4516 p
+= xsnprintf (p
, endp
- p
, ":");
4517 p
= write_ptid (p
, endp
, nptid
);
4519 else if (!ptid_equal (ptid
, minus_one_ptid
))
4521 p
+= xsnprintf (p
, endp
- p
, ":");
4522 p
= write_ptid (p
, endp
, ptid
);
4528 /* Resume the remote inferior by using a "vCont" packet. The thread
4529 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4530 resumed thread should be single-stepped and/or signalled. If PTID
4531 equals minus_one_ptid, then all threads are resumed; the thread to
4532 be stepped and/or signalled is given in the global INFERIOR_PTID.
4533 This function returns non-zero iff it resumes the inferior.
4535 This function issues a strict subset of all possible vCont commands at the
4539 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4541 struct remote_state
*rs
= get_remote_state ();
4545 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4546 remote_vcont_probe (rs
);
4548 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4552 endp
= rs
->buf
+ get_remote_packet_size ();
4554 /* If we could generate a wider range of packets, we'd have to worry
4555 about overflowing BUF. Should there be a generic
4556 "multi-part-packet" packet? */
4558 p
+= xsnprintf (p
, endp
- p
, "vCont");
4560 if (ptid_equal (ptid
, magic_null_ptid
))
4562 /* MAGIC_NULL_PTID means that we don't have any active threads,
4563 so we don't have any TID numbers the inferior will
4564 understand. Make sure to only send forms that do not specify
4566 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4568 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4570 /* Resume all threads (of all processes, or of a single
4571 process), with preference for INFERIOR_PTID. This assumes
4572 inferior_ptid belongs to the set of all threads we are about
4574 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4576 /* Step inferior_ptid, with or without signal. */
4577 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4580 /* And continue others without a signal. */
4581 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4585 /* Scheduler locking; resume only PTID. */
4586 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4589 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4594 /* In non-stop, the stub replies to vCont with "OK". The stop
4595 reply will be reported asynchronously by means of a `%Stop'
4597 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4598 if (strcmp (rs
->buf
, "OK") != 0)
4599 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4605 /* Tell the remote machine to resume. */
4607 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4609 static int last_sent_step
;
4612 remote_resume (struct target_ops
*ops
,
4613 ptid_t ptid
, int step
, enum target_signal siggnal
)
4615 struct remote_state
*rs
= get_remote_state ();
4618 last_sent_signal
= siggnal
;
4619 last_sent_step
= step
;
4621 /* The vCont packet doesn't need to specify threads via Hc. */
4622 /* No reverse support (yet) for vCont. */
4623 if (execution_direction
!= EXEC_REVERSE
)
4624 if (remote_vcont_resume (ptid
, step
, siggnal
))
4627 /* All other supported resume packets do use Hc, so set the continue
4629 if (ptid_equal (ptid
, minus_one_ptid
))
4630 set_continue_thread (any_thread_ptid
);
4632 set_continue_thread (ptid
);
4635 if (execution_direction
== EXEC_REVERSE
)
4637 /* We don't pass signals to the target in reverse exec mode. */
4638 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4639 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4643 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4644 error (_("Remote reverse-step not supported."));
4646 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4647 error (_("Remote reverse-continue not supported."));
4649 strcpy (buf
, step
? "bs" : "bc");
4651 else if (siggnal
!= TARGET_SIGNAL_0
)
4653 buf
[0] = step
? 'S' : 'C';
4654 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4655 buf
[2] = tohex (((int) siggnal
) & 0xf);
4659 strcpy (buf
, step
? "s" : "c");
4664 /* We are about to start executing the inferior, let's register it
4665 with the event loop. NOTE: this is the one place where all the
4666 execution commands end up. We could alternatively do this in each
4667 of the execution commands in infcmd.c. */
4668 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4669 into infcmd.c in order to allow inferior function calls to work
4670 NOT asynchronously. */
4671 if (target_can_async_p ())
4672 target_async (inferior_event_handler
, 0);
4674 /* We've just told the target to resume. The remote server will
4675 wait for the inferior to stop, and then send a stop reply. In
4676 the mean time, we can't start another command/query ourselves
4677 because the stub wouldn't be ready to process it. This applies
4678 only to the base all-stop protocol, however. In non-stop (which
4679 only supports vCont), the stub replies with an "OK", and is
4680 immediate able to process further serial input. */
4682 rs
->waiting_for_stop_reply
= 1;
4686 /* Set up the signal handler for SIGINT, while the target is
4687 executing, ovewriting the 'regular' SIGINT signal handler. */
4689 initialize_sigint_signal_handler (void)
4691 signal (SIGINT
, handle_remote_sigint
);
4694 /* Signal handler for SIGINT, while the target is executing. */
4696 handle_remote_sigint (int sig
)
4698 signal (sig
, handle_remote_sigint_twice
);
4699 mark_async_signal_handler_wrapper (sigint_remote_token
);
4702 /* Signal handler for SIGINT, installed after SIGINT has already been
4703 sent once. It will take effect the second time that the user sends
4706 handle_remote_sigint_twice (int sig
)
4708 signal (sig
, handle_remote_sigint
);
4709 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4712 /* Perform the real interruption of the target execution, in response
4715 async_remote_interrupt (gdb_client_data arg
)
4718 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4720 target_stop (inferior_ptid
);
4723 /* Perform interrupt, if the first attempt did not succeed. Just give
4724 up on the target alltogether. */
4726 async_remote_interrupt_twice (gdb_client_data arg
)
4729 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4734 /* Reinstall the usual SIGINT handlers, after the target has
4737 cleanup_sigint_signal_handler (void *dummy
)
4739 signal (SIGINT
, handle_sigint
);
4742 /* Send ^C to target to halt it. Target will respond, and send us a
4744 static void (*ofunc
) (int);
4746 /* The command line interface's stop routine. This function is installed
4747 as a signal handler for SIGINT. The first time a user requests a
4748 stop, we call remote_stop to send a break or ^C. If there is no
4749 response from the target (it didn't stop when the user requested it),
4750 we ask the user if he'd like to detach from the target. */
4752 remote_interrupt (int signo
)
4754 /* If this doesn't work, try more severe steps. */
4755 signal (signo
, remote_interrupt_twice
);
4757 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4760 /* The user typed ^C twice. */
4763 remote_interrupt_twice (int signo
)
4765 signal (signo
, ofunc
);
4766 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4767 signal (signo
, remote_interrupt
);
4770 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4771 thread, all threads of a remote process, or all threads of all
4775 remote_stop_ns (ptid_t ptid
)
4777 struct remote_state
*rs
= get_remote_state ();
4779 char *endp
= rs
->buf
+ get_remote_packet_size ();
4781 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4782 remote_vcont_probe (rs
);
4784 if (!rs
->support_vCont_t
)
4785 error (_("Remote server does not support stopping threads"));
4787 if (ptid_equal (ptid
, minus_one_ptid
)
4788 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4789 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4794 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4796 if (ptid_is_pid (ptid
))
4797 /* All (-1) threads of process. */
4798 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4801 /* Small optimization: if we already have a stop reply for
4802 this thread, no use in telling the stub we want this
4804 if (peek_stop_reply (ptid
))
4810 write_ptid (p
, endp
, nptid
);
4813 /* In non-stop, we get an immediate OK reply. The stop reply will
4814 come in asynchronously by notification. */
4816 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4817 if (strcmp (rs
->buf
, "OK") != 0)
4818 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4821 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4822 remote target. It is undefined which thread of which process
4823 reports the stop. */
4826 remote_stop_as (ptid_t ptid
)
4828 struct remote_state
*rs
= get_remote_state ();
4830 rs
->ctrlc_pending_p
= 1;
4832 /* If the inferior is stopped already, but the core didn't know
4833 about it yet, just ignore the request. The cached wait status
4834 will be collected in remote_wait. */
4835 if (rs
->cached_wait_status
)
4838 /* Send interrupt_sequence to remote target. */
4839 send_interrupt_sequence ();
4842 /* This is the generic stop called via the target vector. When a target
4843 interrupt is requested, either by the command line or the GUI, we
4844 will eventually end up here. */
4847 remote_stop (ptid_t ptid
)
4850 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4853 remote_stop_ns (ptid
);
4855 remote_stop_as (ptid
);
4858 /* Ask the user what to do when an interrupt is received. */
4861 interrupt_query (void)
4863 target_terminal_ours ();
4865 if (target_can_async_p ())
4867 signal (SIGINT
, handle_sigint
);
4868 deprecated_throw_reason (RETURN_QUIT
);
4872 if (query (_("Interrupted while waiting for the program.\n\
4873 Give up (and stop debugging it)? ")))
4876 deprecated_throw_reason (RETURN_QUIT
);
4880 target_terminal_inferior ();
4883 /* Enable/disable target terminal ownership. Most targets can use
4884 terminal groups to control terminal ownership. Remote targets are
4885 different in that explicit transfer of ownership to/from GDB/target
4889 remote_terminal_inferior (void)
4891 if (!target_async_permitted
)
4892 /* Nothing to do. */
4895 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4896 idempotent. The event-loop GDB talking to an asynchronous target
4897 with a synchronous command calls this function from both
4898 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4899 transfer the terminal to the target when it shouldn't this guard
4901 if (!remote_async_terminal_ours_p
)
4903 delete_file_handler (input_fd
);
4904 remote_async_terminal_ours_p
= 0;
4905 initialize_sigint_signal_handler ();
4906 /* NOTE: At this point we could also register our selves as the
4907 recipient of all input. Any characters typed could then be
4908 passed on down to the target. */
4912 remote_terminal_ours (void)
4914 if (!target_async_permitted
)
4915 /* Nothing to do. */
4918 /* See FIXME in remote_terminal_inferior. */
4919 if (remote_async_terminal_ours_p
)
4921 cleanup_sigint_signal_handler (NULL
);
4922 add_file_handler (input_fd
, stdin_event_handler
, 0);
4923 remote_async_terminal_ours_p
= 1;
4927 remote_console_output (char *msg
)
4931 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4934 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4938 fputs_unfiltered (tb
, gdb_stdtarg
);
4940 gdb_flush (gdb_stdtarg
);
4943 typedef struct cached_reg
4946 gdb_byte data
[MAX_REGISTER_SIZE
];
4949 DEF_VEC_O(cached_reg_t
);
4953 struct stop_reply
*next
;
4957 struct target_waitstatus ws
;
4959 /* Expedited registers. This makes remote debugging a bit more
4960 efficient for those targets that provide critical registers as
4961 part of their normal status mechanism (as another roundtrip to
4962 fetch them is avoided). */
4963 VEC(cached_reg_t
) *regcache
;
4965 int stopped_by_watchpoint_p
;
4966 CORE_ADDR watch_data_address
;
4974 /* The list of already fetched and acknowledged stop events. */
4975 static struct stop_reply
*stop_reply_queue
;
4977 static struct stop_reply
*
4978 stop_reply_xmalloc (void)
4980 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4987 stop_reply_xfree (struct stop_reply
*r
)
4991 VEC_free (cached_reg_t
, r
->regcache
);
4996 /* Discard all pending stop replies of inferior PID. If PID is -1,
4997 discard everything. */
5000 discard_pending_stop_replies (int pid
)
5002 struct stop_reply
*prev
= NULL
, *reply
, *next
;
5004 /* Discard the in-flight notification. */
5005 if (pending_stop_reply
!= NULL
5007 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
5009 stop_reply_xfree (pending_stop_reply
);
5010 pending_stop_reply
= NULL
;
5013 /* Discard the stop replies we have already pulled with
5015 for (reply
= stop_reply_queue
; reply
; reply
= next
)
5019 || ptid_get_pid (reply
->ptid
) == pid
)
5021 if (reply
== stop_reply_queue
)
5022 stop_reply_queue
= reply
->next
;
5024 prev
->next
= reply
->next
;
5026 stop_reply_xfree (reply
);
5033 /* Cleanup wrapper. */
5036 do_stop_reply_xfree (void *arg
)
5038 struct stop_reply
*r
= arg
;
5040 stop_reply_xfree (r
);
5043 /* Look for a queued stop reply belonging to PTID. If one is found,
5044 remove it from the queue, and return it. Returns NULL if none is
5045 found. If there are still queued events left to process, tell the
5046 event loop to get back to target_wait soon. */
5048 static struct stop_reply
*
5049 queued_stop_reply (ptid_t ptid
)
5051 struct stop_reply
*it
;
5052 struct stop_reply
**it_link
;
5054 it
= stop_reply_queue
;
5055 it_link
= &stop_reply_queue
;
5058 if (ptid_match (it
->ptid
, ptid
))
5060 *it_link
= it
->next
;
5065 it_link
= &it
->next
;
5069 if (stop_reply_queue
)
5070 /* There's still at least an event left. */
5071 mark_async_event_handler (remote_async_inferior_event_token
);
5076 /* Push a fully parsed stop reply in the stop reply queue. Since we
5077 know that we now have at least one queued event left to pass to the
5078 core side, tell the event loop to get back to target_wait soon. */
5081 push_stop_reply (struct stop_reply
*new_event
)
5083 struct stop_reply
*event
;
5085 if (stop_reply_queue
)
5087 for (event
= stop_reply_queue
;
5088 event
&& event
->next
;
5089 event
= event
->next
)
5092 event
->next
= new_event
;
5095 stop_reply_queue
= new_event
;
5097 mark_async_event_handler (remote_async_inferior_event_token
);
5100 /* Returns true if we have a stop reply for PTID. */
5103 peek_stop_reply (ptid_t ptid
)
5105 struct stop_reply
*it
;
5107 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5108 if (ptid_equal (ptid
, it
->ptid
))
5110 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5117 /* Parse the stop reply in BUF. Either the function succeeds, and the
5118 result is stored in EVENT, or throws an error. */
5121 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5123 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5127 event
->ptid
= null_ptid
;
5128 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5129 event
->ws
.value
.integer
= 0;
5130 event
->solibs_changed
= 0;
5131 event
->replay_event
= 0;
5132 event
->stopped_by_watchpoint_p
= 0;
5133 event
->regcache
= NULL
;
5138 case 'T': /* Status with PC, SP, FP, ... */
5139 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5140 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5142 n... = register number
5143 r... = register contents
5146 p
= &buf
[3]; /* after Txx */
5154 /* If the packet contains a register number, save it in
5155 pnum and set p1 to point to the character following it.
5156 Otherwise p1 points to p. */
5158 /* If this packet is an awatch packet, don't parse the 'a'
5159 as a register number. */
5161 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5162 && strncmp (p
, "core", strlen ("core") != 0))
5164 /* Read the ``P'' register number. */
5165 pnum
= strtol (p
, &p_temp
, 16);
5171 if (p1
== p
) /* No register number present here. */
5173 p1
= strchr (p
, ':');
5175 error (_("Malformed packet(a) (missing colon): %s\n\
5178 if (strncmp (p
, "thread", p1
- p
) == 0)
5179 event
->ptid
= read_ptid (++p1
, &p
);
5180 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5181 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5182 || (strncmp (p
, "awatch", p1
- p
) == 0))
5184 event
->stopped_by_watchpoint_p
= 1;
5185 p
= unpack_varlen_hex (++p1
, &addr
);
5186 event
->watch_data_address
= (CORE_ADDR
) addr
;
5188 else if (strncmp (p
, "library", p1
- p
) == 0)
5192 while (*p_temp
&& *p_temp
!= ';')
5195 event
->solibs_changed
= 1;
5198 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5200 /* NO_HISTORY event.
5201 p1 will indicate "begin" or "end", but
5202 it makes no difference for now, so ignore it. */
5203 event
->replay_event
= 1;
5204 p_temp
= strchr (p1
+ 1, ';');
5208 else if (strncmp (p
, "core", p1
- p
) == 0)
5212 p
= unpack_varlen_hex (++p1
, &c
);
5217 /* Silently skip unknown optional info. */
5218 p_temp
= strchr (p1
+ 1, ';');
5225 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5226 cached_reg_t cached_reg
;
5231 error (_("Malformed packet(b) (missing colon): %s\n\
5237 error (_("Remote sent bad register number %s: %s\n\
5239 hex_string (pnum
), p
, buf
);
5241 cached_reg
.num
= reg
->regnum
;
5243 fieldsize
= hex2bin (p
, cached_reg
.data
,
5244 register_size (target_gdbarch
,
5247 if (fieldsize
< register_size (target_gdbarch
,
5249 warning (_("Remote reply is too short: %s"), buf
);
5251 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5255 error (_("Remote register badly formatted: %s\nhere: %s"),
5260 case 'S': /* Old style status, just signal only. */
5261 if (event
->solibs_changed
)
5262 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5263 else if (event
->replay_event
)
5264 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5267 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5268 event
->ws
.value
.sig
= (enum target_signal
)
5269 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5272 case 'W': /* Target exited. */
5279 /* GDB used to accept only 2 hex chars here. Stubs should
5280 only send more if they detect GDB supports multi-process
5282 p
= unpack_varlen_hex (&buf
[1], &value
);
5286 /* The remote process exited. */
5287 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5288 event
->ws
.value
.integer
= value
;
5292 /* The remote process exited with a signal. */
5293 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5294 event
->ws
.value
.sig
= (enum target_signal
) value
;
5297 /* If no process is specified, assume inferior_ptid. */
5298 pid
= ptid_get_pid (inferior_ptid
);
5307 else if (strncmp (p
,
5308 "process:", sizeof ("process:") - 1) == 0)
5312 p
+= sizeof ("process:") - 1;
5313 unpack_varlen_hex (p
, &upid
);
5317 error (_("unknown stop reply packet: %s"), buf
);
5320 error (_("unknown stop reply packet: %s"), buf
);
5321 event
->ptid
= pid_to_ptid (pid
);
5326 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5327 error (_("No process or thread specified in stop reply: %s"), buf
);
5330 /* When the stub wants to tell GDB about a new stop reply, it sends a
5331 stop notification (%Stop). Those can come it at any time, hence,
5332 we have to make sure that any pending putpkt/getpkt sequence we're
5333 making is finished, before querying the stub for more events with
5334 vStopped. E.g., if we started a vStopped sequence immediatelly
5335 upon receiving the %Stop notification, something like this could
5343 1.6) <-- (registers reply to step #1.3)
5345 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5348 To solve this, whenever we parse a %Stop notification sucessfully,
5349 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5350 doing whatever we were doing:
5356 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5357 2.5) <-- (registers reply to step #2.3)
5359 Eventualy after step #2.5, we return to the event loop, which
5360 notices there's an event on the
5361 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5362 associated callback --- the function below. At this point, we're
5363 always safe to start a vStopped sequence. :
5366 2.7) <-- T05 thread:2
5372 remote_get_pending_stop_replies (void)
5374 struct remote_state
*rs
= get_remote_state ();
5376 if (pending_stop_reply
)
5379 putpkt ("vStopped");
5381 /* Now we can rely on it. */
5382 push_stop_reply (pending_stop_reply
);
5383 pending_stop_reply
= NULL
;
5387 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5388 if (strcmp (rs
->buf
, "OK") == 0)
5392 struct cleanup
*old_chain
;
5393 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5395 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5396 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5399 putpkt ("vStopped");
5401 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5403 /* Now we can rely on it. */
5404 discard_cleanups (old_chain
);
5405 push_stop_reply (stop_reply
);
5408 /* We got an unknown stop reply. */
5409 do_cleanups (old_chain
);
5416 /* Called when it is decided that STOP_REPLY holds the info of the
5417 event that is to be returned to the core. This function always
5418 destroys STOP_REPLY. */
5421 process_stop_reply (struct stop_reply
*stop_reply
,
5422 struct target_waitstatus
*status
)
5426 *status
= stop_reply
->ws
;
5427 ptid
= stop_reply
->ptid
;
5429 /* If no thread/process was reported by the stub, assume the current
5431 if (ptid_equal (ptid
, null_ptid
))
5432 ptid
= inferior_ptid
;
5434 if (status
->kind
!= TARGET_WAITKIND_EXITED
5435 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5437 /* Expedited registers. */
5438 if (stop_reply
->regcache
)
5440 struct regcache
*regcache
5441 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5446 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5448 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5449 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5452 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5453 remote_watch_data_address
= stop_reply
->watch_data_address
;
5455 remote_notice_new_inferior (ptid
, 0);
5456 demand_private_info (ptid
)->core
= stop_reply
->core
;
5459 stop_reply_xfree (stop_reply
);
5463 /* The non-stop mode version of target_wait. */
5466 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5468 struct remote_state
*rs
= get_remote_state ();
5469 struct stop_reply
*stop_reply
;
5472 /* If in non-stop mode, get out of getpkt even if a
5473 notification is received. */
5475 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5482 case 'E': /* Error of some sort. */
5483 /* We're out of sync with the target now. Did it continue
5484 or not? We can't tell which thread it was in non-stop,
5485 so just ignore this. */
5486 warning (_("Remote failure reply: %s"), rs
->buf
);
5488 case 'O': /* Console output. */
5489 remote_console_output (rs
->buf
+ 1);
5492 warning (_("Invalid remote reply: %s"), rs
->buf
);
5496 /* Acknowledge a pending stop reply that may have arrived in the
5498 if (pending_stop_reply
!= NULL
)
5499 remote_get_pending_stop_replies ();
5501 /* If indeed we noticed a stop reply, we're done. */
5502 stop_reply
= queued_stop_reply (ptid
);
5503 if (stop_reply
!= NULL
)
5504 return process_stop_reply (stop_reply
, status
);
5506 /* Still no event. If we're just polling for an event, then
5507 return to the event loop. */
5508 if (options
& TARGET_WNOHANG
)
5510 status
->kind
= TARGET_WAITKIND_IGNORE
;
5511 return minus_one_ptid
;
5514 /* Otherwise do a blocking wait. */
5515 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5520 /* Wait until the remote machine stops, then return, storing status in
5521 STATUS just as `wait' would. */
5524 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5526 struct remote_state
*rs
= get_remote_state ();
5527 ptid_t event_ptid
= null_ptid
;
5529 struct stop_reply
*stop_reply
;
5533 status
->kind
= TARGET_WAITKIND_IGNORE
;
5534 status
->value
.integer
= 0;
5536 stop_reply
= queued_stop_reply (ptid
);
5537 if (stop_reply
!= NULL
)
5538 return process_stop_reply (stop_reply
, status
);
5540 if (rs
->cached_wait_status
)
5541 /* Use the cached wait status, but only once. */
5542 rs
->cached_wait_status
= 0;
5547 if (!target_is_async_p ())
5549 ofunc
= signal (SIGINT
, remote_interrupt
);
5550 /* If the user hit C-c before this packet, or between packets,
5551 pretend that it was hit right here. */
5555 remote_interrupt (SIGINT
);
5559 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5560 _never_ wait for ever -> test on target_is_async_p().
5561 However, before we do that we need to ensure that the caller
5562 knows how to take the target into/out of async mode. */
5563 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5564 if (!target_is_async_p ())
5565 signal (SIGINT
, ofunc
);
5570 remote_stopped_by_watchpoint_p
= 0;
5572 /* We got something. */
5573 rs
->waiting_for_stop_reply
= 0;
5575 /* Assume that the target has acknowledged Ctrl-C unless we receive
5576 an 'F' or 'O' packet. */
5577 if (buf
[0] != 'F' && buf
[0] != 'O')
5578 rs
->ctrlc_pending_p
= 0;
5582 case 'E': /* Error of some sort. */
5583 /* We're out of sync with the target now. Did it continue or
5584 not? Not is more likely, so report a stop. */
5585 warning (_("Remote failure reply: %s"), buf
);
5586 status
->kind
= TARGET_WAITKIND_STOPPED
;
5587 status
->value
.sig
= TARGET_SIGNAL_0
;
5589 case 'F': /* File-I/O request. */
5590 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5591 rs
->ctrlc_pending_p
= 0;
5593 case 'T': case 'S': case 'X': case 'W':
5595 struct stop_reply
*stop_reply
;
5596 struct cleanup
*old_chain
;
5598 stop_reply
= stop_reply_xmalloc ();
5599 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5600 remote_parse_stop_reply (buf
, stop_reply
);
5601 discard_cleanups (old_chain
);
5602 event_ptid
= process_stop_reply (stop_reply
, status
);
5605 case 'O': /* Console output. */
5606 remote_console_output (buf
+ 1);
5608 /* The target didn't really stop; keep waiting. */
5609 rs
->waiting_for_stop_reply
= 1;
5613 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5615 /* Zero length reply means that we tried 'S' or 'C' and the
5616 remote system doesn't support it. */
5617 target_terminal_ours_for_output ();
5619 ("Can't send signals to this remote system. %s not sent.\n",
5620 target_signal_to_name (last_sent_signal
));
5621 last_sent_signal
= TARGET_SIGNAL_0
;
5622 target_terminal_inferior ();
5624 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5625 putpkt ((char *) buf
);
5627 /* We just told the target to resume, so a stop reply is in
5629 rs
->waiting_for_stop_reply
= 1;
5632 /* else fallthrough */
5634 warning (_("Invalid remote reply: %s"), buf
);
5636 rs
->waiting_for_stop_reply
= 1;
5640 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5642 /* Nothing interesting happened. If we're doing a non-blocking
5643 poll, we're done. Otherwise, go back to waiting. */
5644 if (options
& TARGET_WNOHANG
)
5645 return minus_one_ptid
;
5649 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5650 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5652 if (!ptid_equal (event_ptid
, null_ptid
))
5653 record_currthread (event_ptid
);
5655 event_ptid
= inferior_ptid
;
5658 /* A process exit. Invalidate our notion of current thread. */
5659 record_currthread (minus_one_ptid
);
5664 /* Wait until the remote machine stops, then return, storing status in
5665 STATUS just as `wait' would. */
5668 remote_wait (struct target_ops
*ops
,
5669 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5674 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5676 event_ptid
= remote_wait_as (ptid
, status
, options
);
5678 if (target_can_async_p ())
5680 /* If there are are events left in the queue tell the event loop
5682 if (stop_reply_queue
)
5683 mark_async_event_handler (remote_async_inferior_event_token
);
5689 /* Fetch a single register using a 'p' packet. */
5692 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5694 struct remote_state
*rs
= get_remote_state ();
5696 char regp
[MAX_REGISTER_SIZE
];
5699 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5702 if (reg
->pnum
== -1)
5707 p
+= hexnumstr (p
, reg
->pnum
);
5710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5714 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5718 case PACKET_UNKNOWN
:
5721 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5722 gdbarch_register_name (get_regcache_arch (regcache
),
5727 /* If this register is unfetchable, tell the regcache. */
5730 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5734 /* Otherwise, parse and supply the value. */
5740 error (_("fetch_register_using_p: early buf termination"));
5742 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5745 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5749 /* Fetch the registers included in the target's 'g' packet. */
5752 send_g_packet (void)
5754 struct remote_state
*rs
= get_remote_state ();
5757 sprintf (rs
->buf
, "g");
5758 remote_send (&rs
->buf
, &rs
->buf_size
);
5760 /* We can get out of synch in various cases. If the first character
5761 in the buffer is not a hex character, assume that has happened
5762 and try to fetch another packet to read. */
5763 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5764 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5765 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5766 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5769 fprintf_unfiltered (gdb_stdlog
,
5770 "Bad register packet; fetching a new packet\n");
5771 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5774 buf_len
= strlen (rs
->buf
);
5776 /* Sanity check the received packet. */
5777 if (buf_len
% 2 != 0)
5778 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5784 process_g_packet (struct regcache
*regcache
)
5786 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5787 struct remote_state
*rs
= get_remote_state ();
5788 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5793 buf_len
= strlen (rs
->buf
);
5795 /* Further sanity checks, with knowledge of the architecture. */
5796 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5797 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5799 /* Save the size of the packet sent to us by the target. It is used
5800 as a heuristic when determining the max size of packets that the
5801 target can safely receive. */
5802 if (rsa
->actual_register_packet_size
== 0)
5803 rsa
->actual_register_packet_size
= buf_len
;
5805 /* If this is smaller than we guessed the 'g' packet would be,
5806 update our records. A 'g' reply that doesn't include a register's
5807 value implies either that the register is not available, or that
5808 the 'p' packet must be used. */
5809 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5811 rsa
->sizeof_g_packet
= buf_len
/ 2;
5813 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5815 if (rsa
->regs
[i
].pnum
== -1)
5818 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5819 rsa
->regs
[i
].in_g_packet
= 0;
5821 rsa
->regs
[i
].in_g_packet
= 1;
5825 regs
= alloca (rsa
->sizeof_g_packet
);
5827 /* Unimplemented registers read as all bits zero. */
5828 memset (regs
, 0, rsa
->sizeof_g_packet
);
5830 /* Reply describes registers byte by byte, each byte encoded as two
5831 hex characters. Suck them all up, then supply them to the
5832 register cacheing/storage mechanism. */
5835 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5837 if (p
[0] == 0 || p
[1] == 0)
5838 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5839 internal_error (__FILE__
, __LINE__
,
5840 _("unexpected end of 'g' packet reply"));
5842 if (p
[0] == 'x' && p
[1] == 'x')
5843 regs
[i
] = 0; /* 'x' */
5845 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5849 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5851 struct packet_reg
*r
= &rsa
->regs
[i
];
5855 if (r
->offset
* 2 >= strlen (rs
->buf
))
5856 /* This shouldn't happen - we adjusted in_g_packet above. */
5857 internal_error (__FILE__
, __LINE__
,
5858 _("unexpected end of 'g' packet reply"));
5859 else if (rs
->buf
[r
->offset
* 2] == 'x')
5861 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5862 /* The register isn't available, mark it as such (at
5863 the same time setting the value to zero). */
5864 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5867 regcache_raw_supply (regcache
, r
->regnum
,
5874 fetch_registers_using_g (struct regcache
*regcache
)
5877 process_g_packet (regcache
);
5880 /* Make the remote selected traceframe match GDB's selected
5884 set_remote_traceframe (void)
5888 if (remote_traceframe_number
== get_traceframe_number ())
5891 /* Avoid recursion, remote_trace_find calls us again. */
5892 remote_traceframe_number
= get_traceframe_number ();
5894 newnum
= target_trace_find (tfind_number
,
5895 get_traceframe_number (), 0, 0, NULL
);
5897 /* Should not happen. If it does, all bets are off. */
5898 if (newnum
!= get_traceframe_number ())
5899 warning (_("could not set remote traceframe"));
5903 remote_fetch_registers (struct target_ops
*ops
,
5904 struct regcache
*regcache
, int regnum
)
5906 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5909 set_remote_traceframe ();
5910 set_general_thread (inferior_ptid
);
5914 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5916 gdb_assert (reg
!= NULL
);
5918 /* If this register might be in the 'g' packet, try that first -
5919 we are likely to read more than one register. If this is the
5920 first 'g' packet, we might be overly optimistic about its
5921 contents, so fall back to 'p'. */
5922 if (reg
->in_g_packet
)
5924 fetch_registers_using_g (regcache
);
5925 if (reg
->in_g_packet
)
5929 if (fetch_register_using_p (regcache
, reg
))
5932 /* This register is not available. */
5933 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5938 fetch_registers_using_g (regcache
);
5940 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5941 if (!rsa
->regs
[i
].in_g_packet
)
5942 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5944 /* This register is not available. */
5945 regcache_raw_supply (regcache
, i
, NULL
);
5949 /* Prepare to store registers. Since we may send them all (using a
5950 'G' request), we have to read out the ones we don't want to change
5954 remote_prepare_to_store (struct regcache
*regcache
)
5956 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5958 gdb_byte buf
[MAX_REGISTER_SIZE
];
5960 /* Make sure the entire registers array is valid. */
5961 switch (remote_protocol_packets
[PACKET_P
].support
)
5963 case PACKET_DISABLE
:
5964 case PACKET_SUPPORT_UNKNOWN
:
5965 /* Make sure all the necessary registers are cached. */
5966 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5967 if (rsa
->regs
[i
].in_g_packet
)
5968 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5975 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5976 packet was not recognized. */
5979 store_register_using_P (const struct regcache
*regcache
,
5980 struct packet_reg
*reg
)
5982 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5983 struct remote_state
*rs
= get_remote_state ();
5984 /* Try storing a single register. */
5985 char *buf
= rs
->buf
;
5986 gdb_byte regp
[MAX_REGISTER_SIZE
];
5989 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5992 if (reg
->pnum
== -1)
5995 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5996 p
= buf
+ strlen (buf
);
5997 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5998 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6000 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6002 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6007 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6008 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6009 case PACKET_UNKNOWN
:
6012 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6016 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6017 contents of the register cache buffer. FIXME: ignores errors. */
6020 store_registers_using_G (const struct regcache
*regcache
)
6022 struct remote_state
*rs
= get_remote_state ();
6023 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6027 /* Extract all the registers in the regcache copying them into a
6032 regs
= alloca (rsa
->sizeof_g_packet
);
6033 memset (regs
, 0, rsa
->sizeof_g_packet
);
6034 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6036 struct packet_reg
*r
= &rsa
->regs
[i
];
6039 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6043 /* Command describes registers byte by byte,
6044 each byte encoded as two hex characters. */
6047 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6049 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6051 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6052 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6053 error (_("Could not write registers; remote failure reply '%s'"),
6057 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6058 of the register cache buffer. FIXME: ignores errors. */
6061 remote_store_registers (struct target_ops
*ops
,
6062 struct regcache
*regcache
, int regnum
)
6064 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6067 set_remote_traceframe ();
6068 set_general_thread (inferior_ptid
);
6072 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6074 gdb_assert (reg
!= NULL
);
6076 /* Always prefer to store registers using the 'P' packet if
6077 possible; we often change only a small number of registers.
6078 Sometimes we change a larger number; we'd need help from a
6079 higher layer to know to use 'G'. */
6080 if (store_register_using_P (regcache
, reg
))
6083 /* For now, don't complain if we have no way to write the
6084 register. GDB loses track of unavailable registers too
6085 easily. Some day, this may be an error. We don't have
6086 any way to read the register, either... */
6087 if (!reg
->in_g_packet
)
6090 store_registers_using_G (regcache
);
6094 store_registers_using_G (regcache
);
6096 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6097 if (!rsa
->regs
[i
].in_g_packet
)
6098 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6099 /* See above for why we do not issue an error here. */
6104 /* Return the number of hex digits in num. */
6107 hexnumlen (ULONGEST num
)
6111 for (i
= 0; num
!= 0; i
++)
6117 /* Set BUF to the minimum number of hex digits representing NUM. */
6120 hexnumstr (char *buf
, ULONGEST num
)
6122 int len
= hexnumlen (num
);
6124 return hexnumnstr (buf
, num
, len
);
6128 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6131 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6137 for (i
= width
- 1; i
>= 0; i
--)
6139 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6146 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6149 remote_address_masked (CORE_ADDR addr
)
6151 int address_size
= remote_address_size
;
6153 /* If "remoteaddresssize" was not set, default to target address size. */
6155 address_size
= gdbarch_addr_bit (target_gdbarch
);
6157 if (address_size
> 0
6158 && address_size
< (sizeof (ULONGEST
) * 8))
6160 /* Only create a mask when that mask can safely be constructed
6161 in a ULONGEST variable. */
6164 mask
= (mask
<< address_size
) - 1;
6170 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6171 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6172 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6173 (which may be more than *OUT_LEN due to escape characters). The
6174 total number of bytes in the output buffer will be at most
6178 remote_escape_output (const gdb_byte
*buffer
, int len
,
6179 gdb_byte
*out_buf
, int *out_len
,
6182 int input_index
, output_index
;
6185 for (input_index
= 0; input_index
< len
; input_index
++)
6187 gdb_byte b
= buffer
[input_index
];
6189 if (b
== '$' || b
== '#' || b
== '}')
6191 /* These must be escaped. */
6192 if (output_index
+ 2 > out_maxlen
)
6194 out_buf
[output_index
++] = '}';
6195 out_buf
[output_index
++] = b
^ 0x20;
6199 if (output_index
+ 1 > out_maxlen
)
6201 out_buf
[output_index
++] = b
;
6205 *out_len
= input_index
;
6206 return output_index
;
6209 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6210 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6211 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6213 This function reverses remote_escape_output. It allows more
6214 escaped characters than that function does, in particular because
6215 '*' must be escaped to avoid the run-length encoding processing
6216 in reading packets. */
6219 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6220 gdb_byte
*out_buf
, int out_maxlen
)
6222 int input_index
, output_index
;
6227 for (input_index
= 0; input_index
< len
; input_index
++)
6229 gdb_byte b
= buffer
[input_index
];
6231 if (output_index
+ 1 > out_maxlen
)
6233 warning (_("Received too much data from remote target;"
6234 " ignoring overflow."));
6235 return output_index
;
6240 out_buf
[output_index
++] = b
^ 0x20;
6246 out_buf
[output_index
++] = b
;
6250 error (_("Unmatched escape character in target response."));
6252 return output_index
;
6255 /* Determine whether the remote target supports binary downloading.
6256 This is accomplished by sending a no-op memory write of zero length
6257 to the target at the specified address. It does not suffice to send
6258 the whole packet, since many stubs strip the eighth bit and
6259 subsequently compute a wrong checksum, which causes real havoc with
6262 NOTE: This can still lose if the serial line is not eight-bit
6263 clean. In cases like this, the user should clear "remote
6267 check_binary_download (CORE_ADDR addr
)
6269 struct remote_state
*rs
= get_remote_state ();
6271 switch (remote_protocol_packets
[PACKET_X
].support
)
6273 case PACKET_DISABLE
:
6277 case PACKET_SUPPORT_UNKNOWN
:
6283 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6285 p
+= hexnumstr (p
, (ULONGEST
) 0);
6289 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6292 if (rs
->buf
[0] == '\0')
6295 fprintf_unfiltered (gdb_stdlog
,
6296 "binary downloading NOT "
6297 "supported by target\n");
6298 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6303 fprintf_unfiltered (gdb_stdlog
,
6304 "binary downloading supported by target\n");
6305 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6312 /* Write memory data directly to the remote machine.
6313 This does not inform the data cache; the data cache uses this.
6314 HEADER is the starting part of the packet.
6315 MEMADDR is the address in the remote memory space.
6316 MYADDR is the address of the buffer in our space.
6317 LEN is the number of bytes.
6318 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6319 should send data as binary ('X'), or hex-encoded ('M').
6321 The function creates packet of the form
6322 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6324 where encoding of <DATA> is termined by PACKET_FORMAT.
6326 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6329 Returns the number of bytes transferred, or 0 (setting errno) for
6330 error. Only transfer a single packet. */
6333 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6334 const gdb_byte
*myaddr
, int len
,
6335 char packet_format
, int use_length
)
6337 struct remote_state
*rs
= get_remote_state ();
6347 if (packet_format
!= 'X' && packet_format
!= 'M')
6348 internal_error (__FILE__
, __LINE__
,
6349 _("remote_write_bytes_aux: bad packet format"));
6354 payload_size
= get_memory_write_packet_size ();
6356 /* The packet buffer will be large enough for the payload;
6357 get_memory_packet_size ensures this. */
6360 /* Compute the size of the actual payload by subtracting out the
6361 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6363 payload_size
-= strlen ("$,:#NN");
6365 /* The comma won't be used. */
6367 header_length
= strlen (header
);
6368 payload_size
-= header_length
;
6369 payload_size
-= hexnumlen (memaddr
);
6371 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6373 strcat (rs
->buf
, header
);
6374 p
= rs
->buf
+ strlen (header
);
6376 /* Compute a best guess of the number of bytes actually transfered. */
6377 if (packet_format
== 'X')
6379 /* Best guess at number of bytes that will fit. */
6380 todo
= min (len
, payload_size
);
6382 payload_size
-= hexnumlen (todo
);
6383 todo
= min (todo
, payload_size
);
6387 /* Num bytes that will fit. */
6388 todo
= min (len
, payload_size
/ 2);
6390 payload_size
-= hexnumlen (todo
);
6391 todo
= min (todo
, payload_size
/ 2);
6395 internal_error (__FILE__
, __LINE__
,
6396 _("minimum packet size too small to write data"));
6398 /* If we already need another packet, then try to align the end
6399 of this packet to a useful boundary. */
6400 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6401 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6403 /* Append "<memaddr>". */
6404 memaddr
= remote_address_masked (memaddr
);
6405 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6412 /* Append <len>. Retain the location/size of <len>. It may need to
6413 be adjusted once the packet body has been created. */
6415 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6423 /* Append the packet body. */
6424 if (packet_format
== 'X')
6426 /* Binary mode. Send target system values byte by byte, in
6427 increasing byte addresses. Only escape certain critical
6429 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6432 /* If not all TODO bytes fit, then we'll need another packet. Make
6433 a second try to keep the end of the packet aligned. Don't do
6434 this if the packet is tiny. */
6435 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6439 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6441 if (new_nr_bytes
!= nr_bytes
)
6442 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6447 p
+= payload_length
;
6448 if (use_length
&& nr_bytes
< todo
)
6450 /* Escape chars have filled up the buffer prematurely,
6451 and we have actually sent fewer bytes than planned.
6452 Fix-up the length field of the packet. Use the same
6453 number of characters as before. */
6454 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6455 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6460 /* Normal mode: Send target system values byte by byte, in
6461 increasing byte addresses. Each byte is encoded as a two hex
6463 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6467 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6470 if (rs
->buf
[0] == 'E')
6472 /* There is no correspondance between what the remote protocol
6473 uses for errors and errno codes. We would like a cleaner way
6474 of representing errors (big enough to include errno codes,
6475 bfd_error codes, and others). But for now just return EIO. */
6480 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6481 fewer bytes than we'd planned. */
6485 /* Write memory data directly to the remote machine.
6486 This does not inform the data cache; the data cache uses this.
6487 MEMADDR is the address in the remote memory space.
6488 MYADDR is the address of the buffer in our space.
6489 LEN is the number of bytes.
6491 Returns number of bytes transferred, or 0 (setting errno) for
6492 error. Only transfer a single packet. */
6495 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6497 char *packet_format
= 0;
6499 /* Check whether the target supports binary download. */
6500 check_binary_download (memaddr
);
6502 switch (remote_protocol_packets
[PACKET_X
].support
)
6505 packet_format
= "X";
6507 case PACKET_DISABLE
:
6508 packet_format
= "M";
6510 case PACKET_SUPPORT_UNKNOWN
:
6511 internal_error (__FILE__
, __LINE__
,
6512 _("remote_write_bytes: bad internal state"));
6514 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6517 return remote_write_bytes_aux (packet_format
,
6518 memaddr
, myaddr
, len
, packet_format
[0], 1);
6521 /* Read memory data directly from the remote machine.
6522 This does not use the data cache; the data cache uses this.
6523 MEMADDR is the address in the remote memory space.
6524 MYADDR is the address of the buffer in our space.
6525 LEN is the number of bytes.
6527 Returns number of bytes transferred, or 0 for error. */
6530 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6532 struct remote_state
*rs
= get_remote_state ();
6533 int max_buf_size
; /* Max size of packet output buffer. */
6541 max_buf_size
= get_memory_read_packet_size ();
6542 /* The packet buffer will be large enough for the payload;
6543 get_memory_packet_size ensures this. */
6545 /* Number if bytes that will fit. */
6546 todo
= min (len
, max_buf_size
/ 2);
6548 /* Construct "m"<memaddr>","<len>". */
6549 memaddr
= remote_address_masked (memaddr
);
6552 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6554 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6557 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6558 if (rs
->buf
[0] == 'E'
6559 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6560 && rs
->buf
[3] == '\0')
6562 /* There is no correspondance between what the remote protocol
6563 uses for errors and errno codes. We would like a cleaner way
6564 of representing errors (big enough to include errno codes,
6565 bfd_error codes, and others). But for now just return
6570 /* Reply describes memory byte by byte, each byte encoded as two hex
6573 i
= hex2bin (p
, myaddr
, todo
);
6574 /* Return what we have. Let higher layers handle partial reads. */
6579 /* Remote notification handler. */
6582 handle_notification (char *buf
, size_t length
)
6584 if (strncmp (buf
, "Stop:", 5) == 0)
6586 if (pending_stop_reply
)
6588 /* We've already parsed the in-flight stop-reply, but the
6589 stub for some reason thought we didn't, possibly due to
6590 timeout on its side. Just ignore it. */
6592 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6596 struct cleanup
*old_chain
;
6597 struct stop_reply
*reply
= stop_reply_xmalloc ();
6599 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6601 remote_parse_stop_reply (buf
+ 5, reply
);
6603 discard_cleanups (old_chain
);
6605 /* Be careful to only set it after parsing, since an error
6606 may be thrown then. */
6607 pending_stop_reply
= reply
;
6609 /* Notify the event loop there's a stop reply to acknowledge
6610 and that there may be more events to fetch. */
6611 mark_async_event_handler (remote_async_get_pending_events_token
);
6614 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6618 /* We ignore notifications we don't recognize, for compatibility
6619 with newer stubs. */
6624 /* Read or write LEN bytes from inferior memory at MEMADDR,
6625 transferring to or from debugger address BUFFER. Write to inferior
6626 if SHOULD_WRITE is nonzero. Returns length of data written or
6627 read; 0 for error. TARGET is unused. */
6630 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6631 int should_write
, struct mem_attrib
*attrib
,
6632 struct target_ops
*target
)
6636 set_remote_traceframe ();
6637 set_general_thread (inferior_ptid
);
6640 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6642 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6647 /* Sends a packet with content determined by the printf format string
6648 FORMAT and the remaining arguments, then gets the reply. Returns
6649 whether the packet was a success, a failure, or unknown. */
6651 static enum packet_result
6652 remote_send_printf (const char *format
, ...)
6654 struct remote_state
*rs
= get_remote_state ();
6655 int max_size
= get_remote_packet_size ();
6658 va_start (ap
, format
);
6661 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6662 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6664 if (putpkt (rs
->buf
) < 0)
6665 error (_("Communication problem with target."));
6668 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6670 return packet_check_result (rs
->buf
);
6674 restore_remote_timeout (void *p
)
6676 int value
= *(int *)p
;
6678 remote_timeout
= value
;
6681 /* Flash writing can take quite some time. We'll set
6682 effectively infinite timeout for flash operations.
6683 In future, we'll need to decide on a better approach. */
6684 static const int remote_flash_timeout
= 1000;
6687 remote_flash_erase (struct target_ops
*ops
,
6688 ULONGEST address
, LONGEST length
)
6690 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6691 int saved_remote_timeout
= remote_timeout
;
6692 enum packet_result ret
;
6693 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6694 &saved_remote_timeout
);
6696 remote_timeout
= remote_flash_timeout
;
6698 ret
= remote_send_printf ("vFlashErase:%s,%s",
6699 phex (address
, addr_size
),
6703 case PACKET_UNKNOWN
:
6704 error (_("Remote target does not support flash erase"));
6706 error (_("Error erasing flash with vFlashErase packet"));
6711 do_cleanups (back_to
);
6715 remote_flash_write (struct target_ops
*ops
,
6716 ULONGEST address
, LONGEST length
,
6717 const gdb_byte
*data
)
6719 int saved_remote_timeout
= remote_timeout
;
6721 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6722 &saved_remote_timeout
);
6724 remote_timeout
= remote_flash_timeout
;
6725 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6726 do_cleanups (back_to
);
6732 remote_flash_done (struct target_ops
*ops
)
6734 int saved_remote_timeout
= remote_timeout
;
6736 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6737 &saved_remote_timeout
);
6739 remote_timeout
= remote_flash_timeout
;
6740 ret
= remote_send_printf ("vFlashDone");
6741 do_cleanups (back_to
);
6745 case PACKET_UNKNOWN
:
6746 error (_("Remote target does not support vFlashDone"));
6748 error (_("Error finishing flash operation"));
6755 remote_files_info (struct target_ops
*ignore
)
6757 puts_filtered ("Debugging a target over a serial line.\n");
6760 /* Stuff for dealing with the packets which are part of this protocol.
6761 See comment at top of file for details. */
6763 /* Read a single character from the remote end. */
6766 readchar (int timeout
)
6770 ch
= serial_readchar (remote_desc
, timeout
);
6775 switch ((enum serial_rc
) ch
)
6779 error (_("Remote connection closed"));
6783 perror_with_name (_("Remote communication error. "
6784 "Target disconnected."));
6786 case SERIAL_TIMEOUT
:
6792 /* Send the command in *BUF to the remote machine, and read the reply
6793 into *BUF. Report an error if we get an error reply. Resize
6794 *BUF using xrealloc if necessary to hold the result, and update
6798 remote_send (char **buf
,
6802 getpkt (buf
, sizeof_buf
, 0);
6804 if ((*buf
)[0] == 'E')
6805 error (_("Remote failure reply: %s"), *buf
);
6808 /* Return a pointer to an xmalloc'ed string representing an escaped
6809 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6810 etc. The caller is responsible for releasing the returned
6814 escape_buffer (const char *buf
, int n
)
6816 struct cleanup
*old_chain
;
6817 struct ui_file
*stb
;
6820 stb
= mem_fileopen ();
6821 old_chain
= make_cleanup_ui_file_delete (stb
);
6823 fputstrn_unfiltered (buf
, n
, 0, stb
);
6824 str
= ui_file_xstrdup (stb
, NULL
);
6825 do_cleanups (old_chain
);
6829 /* Display a null-terminated packet on stdout, for debugging, using C
6833 print_packet (char *buf
)
6835 puts_filtered ("\"");
6836 fputstr_filtered (buf
, '"', gdb_stdout
);
6837 puts_filtered ("\"");
6843 return putpkt_binary (buf
, strlen (buf
));
6846 /* Send a packet to the remote machine, with error checking. The data
6847 of the packet is in BUF. The string in BUF can be at most
6848 get_remote_packet_size () - 5 to account for the $, # and checksum,
6849 and for a possible /0 if we are debugging (remote_debug) and want
6850 to print the sent packet as a string. */
6853 putpkt_binary (char *buf
, int cnt
)
6855 struct remote_state
*rs
= get_remote_state ();
6857 unsigned char csum
= 0;
6858 char *buf2
= alloca (cnt
+ 6);
6864 /* Catch cases like trying to read memory or listing threads while
6865 we're waiting for a stop reply. The remote server wouldn't be
6866 ready to handle this request, so we'd hang and timeout. We don't
6867 have to worry about this in synchronous mode, because in that
6868 case it's not possible to issue a command while the target is
6869 running. This is not a problem in non-stop mode, because in that
6870 case, the stub is always ready to process serial input. */
6871 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6872 error (_("Cannot execute this command while the target is running."));
6874 /* We're sending out a new packet. Make sure we don't look at a
6875 stale cached response. */
6876 rs
->cached_wait_status
= 0;
6878 /* Copy the packet into buffer BUF2, encapsulating it
6879 and giving it a checksum. */
6884 for (i
= 0; i
< cnt
; i
++)
6890 *p
++ = tohex ((csum
>> 4) & 0xf);
6891 *p
++ = tohex (csum
& 0xf);
6893 /* Send it over and over until we get a positive ack. */
6897 int started_error_output
= 0;
6901 struct cleanup
*old_chain
;
6905 str
= escape_buffer (buf2
, p
- buf2
);
6906 old_chain
= make_cleanup (xfree
, str
);
6907 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6908 gdb_flush (gdb_stdlog
);
6909 do_cleanups (old_chain
);
6911 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6912 perror_with_name (_("putpkt: write failed"));
6914 /* If this is a no acks version of the remote protocol, send the
6915 packet and move on. */
6919 /* Read until either a timeout occurs (-2) or '+' is read.
6920 Handle any notification that arrives in the mean time. */
6923 ch
= readchar (remote_timeout
);
6931 case SERIAL_TIMEOUT
:
6934 if (started_error_output
)
6936 putchar_unfiltered ('\n');
6937 started_error_output
= 0;
6946 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6950 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6952 case SERIAL_TIMEOUT
:
6956 break; /* Retransmit buffer. */
6960 fprintf_unfiltered (gdb_stdlog
,
6961 "Packet instead of Ack, ignoring it\n");
6962 /* It's probably an old response sent because an ACK
6963 was lost. Gobble up the packet and ack it so it
6964 doesn't get retransmitted when we resend this
6967 serial_write (remote_desc
, "+", 1);
6968 continue; /* Now, go look for +. */
6975 /* If we got a notification, handle it, and go back to looking
6977 /* We've found the start of a notification. Now
6978 collect the data. */
6979 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6984 struct cleanup
*old_chain
;
6987 str
= escape_buffer (rs
->buf
, val
);
6988 old_chain
= make_cleanup (xfree
, str
);
6989 fprintf_unfiltered (gdb_stdlog
,
6990 " Notification received: %s\n",
6992 do_cleanups (old_chain
);
6994 handle_notification (rs
->buf
, val
);
6995 /* We're in sync now, rewait for the ack. */
7002 if (!started_error_output
)
7004 started_error_output
= 1;
7005 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7007 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7008 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7017 if (!started_error_output
)
7019 started_error_output
= 1;
7020 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7022 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7026 break; /* Here to retransmit. */
7030 /* This is wrong. If doing a long backtrace, the user should be
7031 able to get out next time we call QUIT, without anything as
7032 violent as interrupt_query. If we want to provide a way out of
7033 here without getting to the next QUIT, it should be based on
7034 hitting ^C twice as in remote_wait. */
7045 /* Come here after finding the start of a frame when we expected an
7046 ack. Do our best to discard the rest of this packet. */
7055 c
= readchar (remote_timeout
);
7058 case SERIAL_TIMEOUT
:
7059 /* Nothing we can do. */
7062 /* Discard the two bytes of checksum and stop. */
7063 c
= readchar (remote_timeout
);
7065 c
= readchar (remote_timeout
);
7068 case '*': /* Run length encoding. */
7069 /* Discard the repeat count. */
7070 c
= readchar (remote_timeout
);
7075 /* A regular character. */
7081 /* Come here after finding the start of the frame. Collect the rest
7082 into *BUF, verifying the checksum, length, and handling run-length
7083 compression. NUL terminate the buffer. If there is not enough room,
7084 expand *BUF using xrealloc.
7086 Returns -1 on error, number of characters in buffer (ignoring the
7087 trailing NULL) on success. (could be extended to return one of the
7088 SERIAL status indications). */
7091 read_frame (char **buf_p
,
7098 struct remote_state
*rs
= get_remote_state ();
7105 c
= readchar (remote_timeout
);
7108 case SERIAL_TIMEOUT
:
7110 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7114 fputs_filtered ("Saw new packet start in middle of old one\n",
7116 return -1; /* Start a new packet, count retries. */
7119 unsigned char pktcsum
;
7125 check_0
= readchar (remote_timeout
);
7127 check_1
= readchar (remote_timeout
);
7129 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7132 fputs_filtered ("Timeout in checksum, retrying\n",
7136 else if (check_0
< 0 || check_1
< 0)
7139 fputs_filtered ("Communication error in checksum\n",
7144 /* Don't recompute the checksum; with no ack packets we
7145 don't have any way to indicate a packet retransmission
7150 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7151 if (csum
== pktcsum
)
7156 struct cleanup
*old_chain
;
7159 str
= escape_buffer (buf
, bc
);
7160 old_chain
= make_cleanup (xfree
, str
);
7161 fprintf_unfiltered (gdb_stdlog
,
7162 "Bad checksum, sentsum=0x%x, "
7163 "csum=0x%x, buf=%s\n",
7164 pktcsum
, csum
, str
);
7165 do_cleanups (old_chain
);
7167 /* Number of characters in buffer ignoring trailing
7171 case '*': /* Run length encoding. */
7176 c
= readchar (remote_timeout
);
7178 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7180 /* The character before ``*'' is repeated. */
7182 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7184 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7186 /* Make some more room in the buffer. */
7187 *sizeof_buf
+= repeat
;
7188 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7192 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7198 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7202 if (bc
>= *sizeof_buf
- 1)
7204 /* Make some more room in the buffer. */
7206 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7217 /* Read a packet from the remote machine, with error checking, and
7218 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7219 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7220 rather than timing out; this is used (in synchronous mode) to wait
7221 for a target that is is executing user code to stop. */
7222 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7223 don't have to change all the calls to getpkt to deal with the
7224 return value, because at the moment I don't know what the right
7225 thing to do it for those. */
7233 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7237 /* Read a packet from the remote machine, with error checking, and
7238 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7239 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7240 rather than timing out; this is used (in synchronous mode) to wait
7241 for a target that is is executing user code to stop. If FOREVER ==
7242 0, this function is allowed to time out gracefully and return an
7243 indication of this to the caller. Otherwise return the number of
7244 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7245 enough reason to return to the caller. */
7248 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7249 int expecting_notif
)
7251 struct remote_state
*rs
= get_remote_state ();
7257 /* We're reading a new response. Make sure we don't look at a
7258 previously cached response. */
7259 rs
->cached_wait_status
= 0;
7261 strcpy (*buf
, "timeout");
7264 timeout
= watchdog
> 0 ? watchdog
: -1;
7265 else if (expecting_notif
)
7266 timeout
= 0; /* There should already be a char in the buffer. If
7269 timeout
= remote_timeout
;
7273 /* Process any number of notifications, and then return when
7277 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7279 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7281 /* This can loop forever if the remote side sends us
7282 characters continuously, but if it pauses, we'll get
7283 SERIAL_TIMEOUT from readchar because of timeout. Then
7284 we'll count that as a retry.
7286 Note that even when forever is set, we will only wait
7287 forever prior to the start of a packet. After that, we
7288 expect characters to arrive at a brisk pace. They should
7289 show up within remote_timeout intervals. */
7291 c
= readchar (timeout
);
7292 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7294 if (c
== SERIAL_TIMEOUT
)
7296 if (expecting_notif
)
7297 return -1; /* Don't complain, it's normal to not get
7298 anything in this case. */
7300 if (forever
) /* Watchdog went off? Kill the target. */
7304 error (_("Watchdog timeout has expired. Target detached."));
7307 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7311 /* We've found the start of a packet or notification.
7312 Now collect the data. */
7313 val
= read_frame (buf
, sizeof_buf
);
7318 serial_write (remote_desc
, "-", 1);
7321 if (tries
> MAX_TRIES
)
7323 /* We have tried hard enough, and just can't receive the
7324 packet/notification. Give up. */
7325 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7327 /* Skip the ack char if we're in no-ack mode. */
7328 if (!rs
->noack_mode
)
7329 serial_write (remote_desc
, "+", 1);
7333 /* If we got an ordinary packet, return that to our caller. */
7338 struct cleanup
*old_chain
;
7341 str
= escape_buffer (*buf
, val
);
7342 old_chain
= make_cleanup (xfree
, str
);
7343 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7344 do_cleanups (old_chain
);
7347 /* Skip the ack char if we're in no-ack mode. */
7348 if (!rs
->noack_mode
)
7349 serial_write (remote_desc
, "+", 1);
7353 /* If we got a notification, handle it, and go back to looking
7357 gdb_assert (c
== '%');
7361 struct cleanup
*old_chain
;
7364 str
= escape_buffer (*buf
, val
);
7365 old_chain
= make_cleanup (xfree
, str
);
7366 fprintf_unfiltered (gdb_stdlog
,
7367 " Notification received: %s\n",
7369 do_cleanups (old_chain
);
7372 handle_notification (*buf
, val
);
7374 /* Notifications require no acknowledgement. */
7376 if (expecting_notif
)
7383 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7385 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7389 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7391 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7395 /* A helper function that just calls putpkt; for type correctness. */
7398 putpkt_for_catch_errors (void *arg
)
7400 return putpkt (arg
);
7404 remote_kill (struct target_ops
*ops
)
7406 /* Use catch_errors so the user can quit from gdb even when we
7407 aren't on speaking terms with the remote system. */
7408 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7410 /* Don't wait for it to die. I'm not really sure it matters whether
7411 we do or not. For the existing stubs, kill is a noop. */
7412 target_mourn_inferior ();
7416 remote_vkill (int pid
, struct remote_state
*rs
)
7418 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7421 /* Tell the remote target to detach. */
7422 sprintf (rs
->buf
, "vKill;%x", pid
);
7424 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7426 if (packet_ok (rs
->buf
,
7427 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7429 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7436 extended_remote_kill (struct target_ops
*ops
)
7439 int pid
= ptid_get_pid (inferior_ptid
);
7440 struct remote_state
*rs
= get_remote_state ();
7442 res
= remote_vkill (pid
, rs
);
7443 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7445 /* Don't try 'k' on a multi-process aware stub -- it has no way
7446 to specify the pid. */
7450 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7451 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7454 /* Don't wait for it to die. I'm not really sure it matters whether
7455 we do or not. For the existing stubs, kill is a noop. */
7461 error (_("Can't kill process"));
7463 target_mourn_inferior ();
7467 remote_mourn (struct target_ops
*ops
)
7469 remote_mourn_1 (ops
);
7472 /* Worker function for remote_mourn. */
7474 remote_mourn_1 (struct target_ops
*target
)
7476 unpush_target (target
);
7478 /* remote_close takes care of doing most of the clean up. */
7479 generic_mourn_inferior ();
7483 extended_remote_mourn_1 (struct target_ops
*target
)
7485 struct remote_state
*rs
= get_remote_state ();
7487 /* In case we got here due to an error, but we're going to stay
7489 rs
->waiting_for_stop_reply
= 0;
7491 /* We're no longer interested in these events. */
7492 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7494 /* If the current general thread belonged to the process we just
7495 detached from or has exited, the remote side current general
7496 thread becomes undefined. Considering a case like this:
7498 - We just got here due to a detach.
7499 - The process that we're detaching from happens to immediately
7500 report a global breakpoint being hit in non-stop mode, in the
7501 same thread we had selected before.
7502 - GDB attaches to this process again.
7503 - This event happens to be the next event we handle.
7505 GDB would consider that the current general thread didn't need to
7506 be set on the stub side (with Hg), since for all it knew,
7507 GENERAL_THREAD hadn't changed.
7509 Notice that although in all-stop mode, the remote server always
7510 sets the current thread to the thread reporting the stop event,
7511 that doesn't happen in non-stop mode; in non-stop, the stub *must
7512 not* change the current thread when reporting a breakpoint hit,
7513 due to the decoupling of event reporting and event handling.
7515 To keep things simple, we always invalidate our notion of the
7517 record_currthread (minus_one_ptid
);
7519 /* Unlike "target remote", we do not want to unpush the target; then
7520 the next time the user says "run", we won't be connected. */
7522 /* Call common code to mark the inferior as not running. */
7523 generic_mourn_inferior ();
7525 if (!have_inferiors ())
7527 if (!remote_multi_process_p (rs
))
7529 /* Check whether the target is running now - some remote stubs
7530 automatically restart after kill. */
7532 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7534 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7536 /* Assume that the target has been restarted. Set
7537 inferior_ptid so that bits of core GDB realizes
7538 there's something here, e.g., so that the user can
7539 say "kill" again. */
7540 inferior_ptid
= magic_null_ptid
;
7547 extended_remote_mourn (struct target_ops
*ops
)
7549 extended_remote_mourn_1 (ops
);
7553 extended_remote_supports_disable_randomization (void)
7555 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7560 extended_remote_disable_randomization (int val
)
7562 struct remote_state
*rs
= get_remote_state ();
7565 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7567 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7569 error (_("Target does not support QDisableRandomization."));
7570 if (strcmp (reply
, "OK") != 0)
7571 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7575 extended_remote_run (char *args
)
7577 struct remote_state
*rs
= get_remote_state ();
7580 /* If the user has disabled vRun support, or we have detected that
7581 support is not available, do not try it. */
7582 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7585 strcpy (rs
->buf
, "vRun;");
7586 len
= strlen (rs
->buf
);
7588 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7589 error (_("Remote file name too long for run packet"));
7590 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7592 gdb_assert (args
!= NULL
);
7595 struct cleanup
*back_to
;
7599 argv
= gdb_buildargv (args
);
7600 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7601 for (i
= 0; argv
[i
] != NULL
; i
++)
7603 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7604 error (_("Argument list too long for run packet"));
7605 rs
->buf
[len
++] = ';';
7606 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7608 do_cleanups (back_to
);
7611 rs
->buf
[len
++] = '\0';
7614 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7616 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7618 /* We have a wait response; we don't need it, though. All is well. */
7621 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7622 /* It wasn't disabled before, but it is now. */
7626 if (remote_exec_file
[0] == '\0')
7627 error (_("Running the default executable on the remote target failed; "
7628 "try \"set remote exec-file\"?"));
7630 error (_("Running \"%s\" on the remote target failed"),
7635 /* In the extended protocol we want to be able to do things like
7636 "run" and have them basically work as expected. So we need
7637 a special create_inferior function. We support changing the
7638 executable file and the command line arguments, but not the
7642 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7643 char **env
, int from_tty
)
7645 /* If running asynchronously, register the target file descriptor
7646 with the event loop. */
7647 if (target_can_async_p ())
7648 target_async (inferior_event_handler
, 0);
7650 /* Disable address space randomization if requested (and supported). */
7651 if (extended_remote_supports_disable_randomization ())
7652 extended_remote_disable_randomization (disable_randomization
);
7654 /* Now restart the remote server. */
7655 if (extended_remote_run (args
) == -1)
7657 /* vRun was not supported. Fail if we need it to do what the
7659 if (remote_exec_file
[0])
7660 error (_("Remote target does not support \"set remote exec-file\""));
7662 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7664 /* Fall back to "R". */
7665 extended_remote_restart ();
7668 if (!have_inferiors ())
7670 /* Clean up from the last time we ran, before we mark the target
7671 running again. This will mark breakpoints uninserted, and
7672 get_offsets may insert breakpoints. */
7673 init_thread_list ();
7674 init_wait_for_inferior ();
7677 /* Now mark the inferior as running before we do anything else. */
7678 inferior_ptid
= magic_null_ptid
;
7680 /* Now, if we have thread information, update inferior_ptid. */
7681 inferior_ptid
= remote_current_thread (inferior_ptid
);
7683 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7684 add_thread_silent (inferior_ptid
);
7686 /* Get updated offsets, if the stub uses qOffsets. */
7691 extended_remote_create_inferior (struct target_ops
*ops
,
7692 char *exec_file
, char *args
,
7693 char **env
, int from_tty
)
7695 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7699 /* Insert a breakpoint. On targets that have software breakpoint
7700 support, we ask the remote target to do the work; on targets
7701 which don't, we insert a traditional memory breakpoint. */
7704 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7705 struct bp_target_info
*bp_tgt
)
7707 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7708 If it succeeds, then set the support to PACKET_ENABLE. If it
7709 fails, and the user has explicitly requested the Z support then
7710 report an error, otherwise, mark it disabled and go on. */
7712 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7714 CORE_ADDR addr
= bp_tgt
->placed_address
;
7715 struct remote_state
*rs
;
7719 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7721 rs
= get_remote_state ();
7727 addr
= (ULONGEST
) remote_address_masked (addr
);
7728 p
+= hexnumstr (p
, addr
);
7729 sprintf (p
, ",%d", bpsize
);
7732 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7734 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7739 bp_tgt
->placed_address
= addr
;
7740 bp_tgt
->placed_size
= bpsize
;
7742 case PACKET_UNKNOWN
:
7747 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7751 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7752 struct bp_target_info
*bp_tgt
)
7754 CORE_ADDR addr
= bp_tgt
->placed_address
;
7755 struct remote_state
*rs
= get_remote_state ();
7757 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7765 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7766 p
+= hexnumstr (p
, addr
);
7767 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7772 return (rs
->buf
[0] == 'E');
7775 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7779 watchpoint_to_Z_packet (int type
)
7784 return Z_PACKET_WRITE_WP
;
7787 return Z_PACKET_READ_WP
;
7790 return Z_PACKET_ACCESS_WP
;
7793 internal_error (__FILE__
, __LINE__
,
7794 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7799 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7800 struct expression
*cond
)
7802 struct remote_state
*rs
= get_remote_state ();
7804 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7806 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7809 sprintf (rs
->buf
, "Z%x,", packet
);
7810 p
= strchr (rs
->buf
, '\0');
7811 addr
= remote_address_masked (addr
);
7812 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7813 sprintf (p
, ",%x", len
);
7816 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7818 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7822 case PACKET_UNKNOWN
:
7827 internal_error (__FILE__
, __LINE__
,
7828 _("remote_insert_watchpoint: reached end of function"));
7833 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7834 struct expression
*cond
)
7836 struct remote_state
*rs
= get_remote_state ();
7838 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7840 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7843 sprintf (rs
->buf
, "z%x,", packet
);
7844 p
= strchr (rs
->buf
, '\0');
7845 addr
= remote_address_masked (addr
);
7846 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7847 sprintf (p
, ",%x", len
);
7849 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7851 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7854 case PACKET_UNKNOWN
:
7859 internal_error (__FILE__
, __LINE__
,
7860 _("remote_remove_watchpoint: reached end of function"));
7864 int remote_hw_watchpoint_limit
= -1;
7865 int remote_hw_watchpoint_length_limit
= -1;
7866 int remote_hw_breakpoint_limit
= -1;
7869 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7871 if (remote_hw_watchpoint_length_limit
== 0)
7873 else if (remote_hw_watchpoint_length_limit
< 0)
7875 else if (len
<= remote_hw_watchpoint_length_limit
)
7882 remote_check_watch_resources (int type
, int cnt
, int ot
)
7884 if (type
== bp_hardware_breakpoint
)
7886 if (remote_hw_breakpoint_limit
== 0)
7888 else if (remote_hw_breakpoint_limit
< 0)
7890 else if (cnt
<= remote_hw_breakpoint_limit
)
7895 if (remote_hw_watchpoint_limit
== 0)
7897 else if (remote_hw_watchpoint_limit
< 0)
7901 else if (cnt
<= remote_hw_watchpoint_limit
)
7908 remote_stopped_by_watchpoint (void)
7910 return remote_stopped_by_watchpoint_p
;
7914 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7918 if (remote_stopped_by_watchpoint ())
7920 *addr_p
= remote_watch_data_address
;
7929 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7930 struct bp_target_info
*bp_tgt
)
7933 struct remote_state
*rs
;
7936 /* The length field should be set to the size of a breakpoint
7937 instruction, even though we aren't inserting one ourselves. */
7939 gdbarch_remote_breakpoint_from_pc
7940 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7942 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7945 rs
= get_remote_state ();
7952 addr
= remote_address_masked (bp_tgt
->placed_address
);
7953 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7954 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7957 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7959 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7962 case PACKET_UNKNOWN
:
7967 internal_error (__FILE__
, __LINE__
,
7968 _("remote_insert_hw_breakpoint: reached end of function"));
7973 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7974 struct bp_target_info
*bp_tgt
)
7977 struct remote_state
*rs
= get_remote_state ();
7980 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7987 addr
= remote_address_masked (bp_tgt
->placed_address
);
7988 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7989 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7992 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7994 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7997 case PACKET_UNKNOWN
:
8002 internal_error (__FILE__
, __LINE__
,
8003 _("remote_remove_hw_breakpoint: reached end of function"));
8006 /* Table used by the crc32 function to calcuate the checksum. */
8008 static unsigned long crc32_table
[256] =
8011 static unsigned long
8012 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8014 if (!crc32_table
[1])
8016 /* Initialize the CRC table and the decoding table. */
8020 for (i
= 0; i
< 256; i
++)
8022 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8023 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8030 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8036 /* Verify memory using the "qCRC:" request. */
8039 remote_verify_memory (struct target_ops
*ops
,
8040 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8042 struct remote_state
*rs
= get_remote_state ();
8043 unsigned long host_crc
, target_crc
;
8046 /* FIXME: assumes lma can fit into long. */
8047 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8048 (long) lma
, (long) size
);
8051 /* Be clever; compute the host_crc before waiting for target
8053 host_crc
= crc32 (data
, size
, 0xffffffff);
8055 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8056 if (rs
->buf
[0] == 'E')
8059 if (rs
->buf
[0] != 'C')
8060 error (_("remote target does not support this operation"));
8062 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8063 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8065 return (host_crc
== target_crc
);
8068 /* compare-sections command
8070 With no arguments, compares each loadable section in the exec bfd
8071 with the same memory range on the target, and reports mismatches.
8072 Useful for verifying the image on the target against the exec file. */
8075 compare_sections_command (char *args
, int from_tty
)
8078 struct cleanup
*old_chain
;
8080 const char *sectname
;
8088 error (_("command cannot be used without an exec file"));
8090 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8092 if (!(s
->flags
& SEC_LOAD
))
8093 continue; /* Skip non-loadable section. */
8095 size
= bfd_get_section_size (s
);
8097 continue; /* Skip zero-length section. */
8099 sectname
= bfd_get_section_name (exec_bfd
, s
);
8100 if (args
&& strcmp (args
, sectname
) != 0)
8101 continue; /* Not the section selected by user. */
8103 matched
= 1; /* Do this section. */
8106 sectdata
= xmalloc (size
);
8107 old_chain
= make_cleanup (xfree
, sectdata
);
8108 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8110 res
= target_verify_memory (sectdata
, lma
, size
);
8113 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8114 paddress (target_gdbarch
, lma
),
8115 paddress (target_gdbarch
, lma
+ size
));
8117 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8118 paddress (target_gdbarch
, lma
),
8119 paddress (target_gdbarch
, lma
+ size
));
8121 printf_filtered ("matched.\n");
8124 printf_filtered ("MIS-MATCHED!\n");
8128 do_cleanups (old_chain
);
8131 warning (_("One or more sections of the remote executable does not match\n\
8132 the loaded file\n"));
8133 if (args
&& !matched
)
8134 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8137 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8138 into remote target. The number of bytes written to the remote
8139 target is returned, or -1 for error. */
8142 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8143 const char *annex
, const gdb_byte
*writebuf
,
8144 ULONGEST offset
, LONGEST len
,
8145 struct packet_config
*packet
)
8149 struct remote_state
*rs
= get_remote_state ();
8150 int max_size
= get_memory_write_packet_size ();
8152 if (packet
->support
== PACKET_DISABLE
)
8155 /* Insert header. */
8156 i
= snprintf (rs
->buf
, max_size
,
8157 "qXfer:%s:write:%s:%s:",
8158 object_name
, annex
? annex
: "",
8159 phex_nz (offset
, sizeof offset
));
8160 max_size
-= (i
+ 1);
8162 /* Escape as much data as fits into rs->buf. */
8163 buf_len
= remote_escape_output
8164 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8166 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8167 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8168 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8171 unpack_varlen_hex (rs
->buf
, &n
);
8175 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8176 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8177 number of bytes read is returned, or 0 for EOF, or -1 for error.
8178 The number of bytes read may be less than LEN without indicating an
8179 EOF. PACKET is checked and updated to indicate whether the remote
8180 target supports this object. */
8183 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8185 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8186 struct packet_config
*packet
)
8188 static char *finished_object
;
8189 static char *finished_annex
;
8190 static ULONGEST finished_offset
;
8192 struct remote_state
*rs
= get_remote_state ();
8193 LONGEST i
, n
, packet_len
;
8195 if (packet
->support
== PACKET_DISABLE
)
8198 /* Check whether we've cached an end-of-object packet that matches
8200 if (finished_object
)
8202 if (strcmp (object_name
, finished_object
) == 0
8203 && strcmp (annex
? annex
: "", finished_annex
) == 0
8204 && offset
== finished_offset
)
8207 /* Otherwise, we're now reading something different. Discard
8209 xfree (finished_object
);
8210 xfree (finished_annex
);
8211 finished_object
= NULL
;
8212 finished_annex
= NULL
;
8215 /* Request only enough to fit in a single packet. The actual data
8216 may not, since we don't know how much of it will need to be escaped;
8217 the target is free to respond with slightly less data. We subtract
8218 five to account for the response type and the protocol frame. */
8219 n
= min (get_remote_packet_size () - 5, len
);
8220 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8221 object_name
, annex
? annex
: "",
8222 phex_nz (offset
, sizeof offset
),
8223 phex_nz (n
, sizeof n
));
8224 i
= putpkt (rs
->buf
);
8229 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8230 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8233 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8234 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8236 /* 'm' means there is (or at least might be) more data after this
8237 batch. That does not make sense unless there's at least one byte
8238 of data in this reply. */
8239 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8240 error (_("Remote qXfer reply contained no data."));
8242 /* Got some data. */
8243 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8245 /* 'l' is an EOF marker, possibly including a final block of data,
8246 or possibly empty. If we have the final block of a non-empty
8247 object, record this fact to bypass a subsequent partial read. */
8248 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8250 finished_object
= xstrdup (object_name
);
8251 finished_annex
= xstrdup (annex
? annex
: "");
8252 finished_offset
= offset
+ i
;
8259 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8260 const char *annex
, gdb_byte
*readbuf
,
8261 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8263 struct remote_state
*rs
;
8268 set_remote_traceframe ();
8269 set_general_thread (inferior_ptid
);
8271 rs
= get_remote_state ();
8273 /* Handle memory using the standard memory routines. */
8274 if (object
== TARGET_OBJECT_MEMORY
)
8280 /* If the remote target is connected but not running, we should
8281 pass this request down to a lower stratum (e.g. the executable
8283 if (!target_has_execution
)
8286 if (writebuf
!= NULL
)
8287 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8289 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8293 else if (xfered
== 0 && errno
== 0)
8299 /* Handle SPU memory using qxfer packets. */
8300 if (object
== TARGET_OBJECT_SPU
)
8303 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8304 &remote_protocol_packets
8305 [PACKET_qXfer_spu_read
]);
8307 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8308 &remote_protocol_packets
8309 [PACKET_qXfer_spu_write
]);
8312 /* Handle extra signal info using qxfer packets. */
8313 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8316 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8317 &remote_protocol_packets
8318 [PACKET_qXfer_siginfo_read
]);
8320 return remote_write_qxfer (ops
, "siginfo", annex
,
8321 writebuf
, offset
, len
,
8322 &remote_protocol_packets
8323 [PACKET_qXfer_siginfo_write
]);
8326 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8329 return remote_read_qxfer (ops
, "statictrace", annex
,
8330 readbuf
, offset
, len
,
8331 &remote_protocol_packets
8332 [PACKET_qXfer_statictrace_read
]);
8337 /* Only handle flash writes. */
8338 if (writebuf
!= NULL
)
8344 case TARGET_OBJECT_FLASH
:
8345 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8349 else if (xfered
== 0 && errno
== 0)
8359 /* Map pre-existing objects onto letters. DO NOT do this for new
8360 objects!!! Instead specify new query packets. */
8363 case TARGET_OBJECT_AVR
:
8367 case TARGET_OBJECT_AUXV
:
8368 gdb_assert (annex
== NULL
);
8369 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8370 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8372 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8373 return remote_read_qxfer
8374 (ops
, "features", annex
, readbuf
, offset
, len
,
8375 &remote_protocol_packets
[PACKET_qXfer_features
]);
8377 case TARGET_OBJECT_LIBRARIES
:
8378 return remote_read_qxfer
8379 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8380 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8382 case TARGET_OBJECT_LIBRARIES_SVR4
:
8383 return remote_read_qxfer
8384 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8385 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8387 case TARGET_OBJECT_MEMORY_MAP
:
8388 gdb_assert (annex
== NULL
);
8389 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8390 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8392 case TARGET_OBJECT_OSDATA
:
8393 /* Should only get here if we're connected. */
8394 gdb_assert (remote_desc
);
8395 return remote_read_qxfer
8396 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8397 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8399 case TARGET_OBJECT_THREADS
:
8400 gdb_assert (annex
== NULL
);
8401 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8402 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8404 case TARGET_OBJECT_TRACEFRAME_INFO
:
8405 gdb_assert (annex
== NULL
);
8406 return remote_read_qxfer
8407 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8408 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8410 case TARGET_OBJECT_FDPIC
:
8411 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8412 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8417 /* Note: a zero OFFSET and LEN can be used to query the minimum
8419 if (offset
== 0 && len
== 0)
8420 return (get_remote_packet_size ());
8421 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8422 large enough let the caller deal with it. */
8423 if (len
< get_remote_packet_size ())
8425 len
= get_remote_packet_size ();
8427 /* Except for querying the minimum buffer size, target must be open. */
8429 error (_("remote query is only available after target open"));
8431 gdb_assert (annex
!= NULL
);
8432 gdb_assert (readbuf
!= NULL
);
8438 /* We used one buffer char for the remote protocol q command and
8439 another for the query type. As the remote protocol encapsulation
8440 uses 4 chars plus one extra in case we are debugging
8441 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8444 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8446 /* Bad caller may have sent forbidden characters. */
8447 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8452 gdb_assert (annex
[i
] == '\0');
8454 i
= putpkt (rs
->buf
);
8458 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8459 strcpy ((char *) readbuf
, rs
->buf
);
8461 return strlen ((char *) readbuf
);
8465 remote_search_memory (struct target_ops
* ops
,
8466 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8467 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8468 CORE_ADDR
*found_addrp
)
8470 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8471 struct remote_state
*rs
= get_remote_state ();
8472 int max_size
= get_memory_write_packet_size ();
8473 struct packet_config
*packet
=
8474 &remote_protocol_packets
[PACKET_qSearch_memory
];
8475 /* Number of packet bytes used to encode the pattern;
8476 this could be more than PATTERN_LEN due to escape characters. */
8477 int escaped_pattern_len
;
8478 /* Amount of pattern that was encodable in the packet. */
8479 int used_pattern_len
;
8482 ULONGEST found_addr
;
8484 /* Don't go to the target if we don't have to.
8485 This is done before checking packet->support to avoid the possibility that
8486 a success for this edge case means the facility works in general. */
8487 if (pattern_len
> search_space_len
)
8489 if (pattern_len
== 0)
8491 *found_addrp
= start_addr
;
8495 /* If we already know the packet isn't supported, fall back to the simple
8496 way of searching memory. */
8498 if (packet
->support
== PACKET_DISABLE
)
8500 /* Target doesn't provided special support, fall back and use the
8501 standard support (copy memory and do the search here). */
8502 return simple_search_memory (ops
, start_addr
, search_space_len
,
8503 pattern
, pattern_len
, found_addrp
);
8506 /* Insert header. */
8507 i
= snprintf (rs
->buf
, max_size
,
8508 "qSearch:memory:%s;%s;",
8509 phex_nz (start_addr
, addr_size
),
8510 phex_nz (search_space_len
, sizeof (search_space_len
)));
8511 max_size
-= (i
+ 1);
8513 /* Escape as much data as fits into rs->buf. */
8514 escaped_pattern_len
=
8515 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8516 &used_pattern_len
, max_size
);
8518 /* Bail if the pattern is too large. */
8519 if (used_pattern_len
!= pattern_len
)
8520 error (_("Pattern is too large to transmit to remote target."));
8522 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8523 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8524 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8526 /* The request may not have worked because the command is not
8527 supported. If so, fall back to the simple way. */
8528 if (packet
->support
== PACKET_DISABLE
)
8530 return simple_search_memory (ops
, start_addr
, search_space_len
,
8531 pattern
, pattern_len
, found_addrp
);
8536 if (rs
->buf
[0] == '0')
8538 else if (rs
->buf
[0] == '1')
8541 if (rs
->buf
[1] != ',')
8542 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8543 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8544 *found_addrp
= found_addr
;
8547 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8553 remote_rcmd (char *command
,
8554 struct ui_file
*outbuf
)
8556 struct remote_state
*rs
= get_remote_state ();
8560 error (_("remote rcmd is only available after target open"));
8562 /* Send a NULL command across as an empty command. */
8563 if (command
== NULL
)
8566 /* The query prefix. */
8567 strcpy (rs
->buf
, "qRcmd,");
8568 p
= strchr (rs
->buf
, '\0');
8570 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8571 > get_remote_packet_size ())
8572 error (_("\"monitor\" command ``%s'' is too long."), command
);
8574 /* Encode the actual command. */
8575 bin2hex ((gdb_byte
*) command
, p
, 0);
8577 if (putpkt (rs
->buf
) < 0)
8578 error (_("Communication problem with target."));
8580 /* get/display the response */
8585 /* XXX - see also remote_get_noisy_reply(). */
8587 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8590 error (_("Target does not support this command."));
8591 if (buf
[0] == 'O' && buf
[1] != 'K')
8593 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8596 if (strcmp (buf
, "OK") == 0)
8598 if (strlen (buf
) == 3 && buf
[0] == 'E'
8599 && isdigit (buf
[1]) && isdigit (buf
[2]))
8601 error (_("Protocol error with Rcmd"));
8603 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8605 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8607 fputc_unfiltered (c
, outbuf
);
8613 static VEC(mem_region_s
) *
8614 remote_memory_map (struct target_ops
*ops
)
8616 VEC(mem_region_s
) *result
= NULL
;
8617 char *text
= target_read_stralloc (¤t_target
,
8618 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8622 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8624 result
= parse_memory_map (text
);
8625 do_cleanups (back_to
);
8632 packet_command (char *args
, int from_tty
)
8634 struct remote_state
*rs
= get_remote_state ();
8637 error (_("command can only be used with remote target"));
8640 error (_("remote-packet command requires packet text as argument"));
8642 puts_filtered ("sending: ");
8643 print_packet (args
);
8644 puts_filtered ("\n");
8647 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8648 puts_filtered ("received: ");
8649 print_packet (rs
->buf
);
8650 puts_filtered ("\n");
8654 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8656 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8658 static void threadset_test_cmd (char *cmd
, int tty
);
8660 static void threadalive_test (char *cmd
, int tty
);
8662 static void threadlist_test_cmd (char *cmd
, int tty
);
8664 int get_and_display_threadinfo (threadref
*ref
);
8666 static void threadinfo_test_cmd (char *cmd
, int tty
);
8668 static int thread_display_step (threadref
*ref
, void *context
);
8670 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8672 static void init_remote_threadtests (void);
8674 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8677 threadset_test_cmd (char *cmd
, int tty
)
8679 int sample_thread
= SAMPLE_THREAD
;
8681 printf_filtered (_("Remote threadset test\n"));
8682 set_general_thread (sample_thread
);
8687 threadalive_test (char *cmd
, int tty
)
8689 int sample_thread
= SAMPLE_THREAD
;
8690 int pid
= ptid_get_pid (inferior_ptid
);
8691 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8693 if (remote_thread_alive (ptid
))
8694 printf_filtered ("PASS: Thread alive test\n");
8696 printf_filtered ("FAIL: Thread alive test\n");
8699 void output_threadid (char *title
, threadref
*ref
);
8702 output_threadid (char *title
, threadref
*ref
)
8706 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8708 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8712 threadlist_test_cmd (char *cmd
, int tty
)
8715 threadref nextthread
;
8716 int done
, result_count
;
8717 threadref threadlist
[3];
8719 printf_filtered ("Remote Threadlist test\n");
8720 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8721 &result_count
, &threadlist
[0]))
8722 printf_filtered ("FAIL: threadlist test\n");
8725 threadref
*scan
= threadlist
;
8726 threadref
*limit
= scan
+ result_count
;
8728 while (scan
< limit
)
8729 output_threadid (" thread ", scan
++);
8734 display_thread_info (struct gdb_ext_thread_info
*info
)
8736 output_threadid ("Threadid: ", &info
->threadid
);
8737 printf_filtered ("Name: %s\n ", info
->shortname
);
8738 printf_filtered ("State: %s\n", info
->display
);
8739 printf_filtered ("other: %s\n\n", info
->more_display
);
8743 get_and_display_threadinfo (threadref
*ref
)
8747 struct gdb_ext_thread_info threadinfo
;
8749 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8750 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8751 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8752 display_thread_info (&threadinfo
);
8757 threadinfo_test_cmd (char *cmd
, int tty
)
8759 int athread
= SAMPLE_THREAD
;
8763 int_to_threadref (&thread
, athread
);
8764 printf_filtered ("Remote Threadinfo test\n");
8765 if (!get_and_display_threadinfo (&thread
))
8766 printf_filtered ("FAIL cannot get thread info\n");
8770 thread_display_step (threadref
*ref
, void *context
)
8772 /* output_threadid(" threadstep ",ref); *//* simple test */
8773 return get_and_display_threadinfo (ref
);
8777 threadlist_update_test_cmd (char *cmd
, int tty
)
8779 printf_filtered ("Remote Threadlist update test\n");
8780 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8784 init_remote_threadtests (void)
8786 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8787 _("Fetch and print the remote list of "
8788 "thread identifiers, one pkt only"));
8789 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8790 _("Fetch and display info about one thread"));
8791 add_com ("tset", class_obscure
, threadset_test_cmd
,
8792 _("Test setting to a different thread"));
8793 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8794 _("Iterate through updating all remote thread info"));
8795 add_com ("talive", class_obscure
, threadalive_test
,
8796 _(" Remote thread alive test "));
8801 /* Convert a thread ID to a string. Returns the string in a static
8805 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8807 static char buf
[64];
8808 struct remote_state
*rs
= get_remote_state ();
8810 if (ptid_is_pid (ptid
))
8812 /* Printing an inferior target id. */
8814 /* When multi-process extensions are off, there's no way in the
8815 remote protocol to know the remote process id, if there's any
8816 at all. There's one exception --- when we're connected with
8817 target extended-remote, and we manually attached to a process
8818 with "attach PID". We don't record anywhere a flag that
8819 allows us to distinguish that case from the case of
8820 connecting with extended-remote and the stub already being
8821 attached to a process, and reporting yes to qAttached, hence
8822 no smart special casing here. */
8823 if (!remote_multi_process_p (rs
))
8825 xsnprintf (buf
, sizeof buf
, "Remote target");
8829 return normal_pid_to_str (ptid
);
8833 if (ptid_equal (magic_null_ptid
, ptid
))
8834 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8835 else if (rs
->extended
&& remote_multi_process_p (rs
))
8836 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8837 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8839 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8840 ptid_get_tid (ptid
));
8845 /* Get the address of the thread local variable in OBJFILE which is
8846 stored at OFFSET within the thread local storage for thread PTID. */
8849 remote_get_thread_local_address (struct target_ops
*ops
,
8850 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8852 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8854 struct remote_state
*rs
= get_remote_state ();
8856 char *endp
= rs
->buf
+ get_remote_packet_size ();
8857 enum packet_result result
;
8859 strcpy (p
, "qGetTLSAddr:");
8861 p
= write_ptid (p
, endp
, ptid
);
8863 p
+= hexnumstr (p
, offset
);
8865 p
+= hexnumstr (p
, lm
);
8869 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8870 result
= packet_ok (rs
->buf
,
8871 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8872 if (result
== PACKET_OK
)
8876 unpack_varlen_hex (rs
->buf
, &result
);
8879 else if (result
== PACKET_UNKNOWN
)
8880 throw_error (TLS_GENERIC_ERROR
,
8881 _("Remote target doesn't support qGetTLSAddr packet"));
8883 throw_error (TLS_GENERIC_ERROR
,
8884 _("Remote target failed to process qGetTLSAddr request"));
8887 throw_error (TLS_GENERIC_ERROR
,
8888 _("TLS not supported or disabled on this target"));
8893 /* Provide thread local base, i.e. Thread Information Block address.
8894 Returns 1 if ptid is found and thread_local_base is non zero. */
8897 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8899 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8901 struct remote_state
*rs
= get_remote_state ();
8903 char *endp
= rs
->buf
+ get_remote_packet_size ();
8904 enum packet_result result
;
8906 strcpy (p
, "qGetTIBAddr:");
8908 p
= write_ptid (p
, endp
, ptid
);
8912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8913 result
= packet_ok (rs
->buf
,
8914 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8915 if (result
== PACKET_OK
)
8919 unpack_varlen_hex (rs
->buf
, &result
);
8921 *addr
= (CORE_ADDR
) result
;
8924 else if (result
== PACKET_UNKNOWN
)
8925 error (_("Remote target doesn't support qGetTIBAddr packet"));
8927 error (_("Remote target failed to process qGetTIBAddr request"));
8930 error (_("qGetTIBAddr not supported or disabled on this target"));
8935 /* Support for inferring a target description based on the current
8936 architecture and the size of a 'g' packet. While the 'g' packet
8937 can have any size (since optional registers can be left off the
8938 end), some sizes are easily recognizable given knowledge of the
8939 approximate architecture. */
8941 struct remote_g_packet_guess
8944 const struct target_desc
*tdesc
;
8946 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8947 DEF_VEC_O(remote_g_packet_guess_s
);
8949 struct remote_g_packet_data
8951 VEC(remote_g_packet_guess_s
) *guesses
;
8954 static struct gdbarch_data
*remote_g_packet_data_handle
;
8957 remote_g_packet_data_init (struct obstack
*obstack
)
8959 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8963 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8964 const struct target_desc
*tdesc
)
8966 struct remote_g_packet_data
*data
8967 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8968 struct remote_g_packet_guess new_guess
, *guess
;
8971 gdb_assert (tdesc
!= NULL
);
8974 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8976 if (guess
->bytes
== bytes
)
8977 internal_error (__FILE__
, __LINE__
,
8978 _("Duplicate g packet description added for size %d"),
8981 new_guess
.bytes
= bytes
;
8982 new_guess
.tdesc
= tdesc
;
8983 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8986 /* Return 1 if remote_read_description would do anything on this target
8987 and architecture, 0 otherwise. */
8990 remote_read_description_p (struct target_ops
*target
)
8992 struct remote_g_packet_data
*data
8993 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8995 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9001 static const struct target_desc
*
9002 remote_read_description (struct target_ops
*target
)
9004 struct remote_g_packet_data
*data
9005 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9007 /* Do not try this during initial connection, when we do not know
9008 whether there is a running but stopped thread. */
9009 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9012 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9014 struct remote_g_packet_guess
*guess
;
9016 int bytes
= send_g_packet ();
9019 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9021 if (guess
->bytes
== bytes
)
9022 return guess
->tdesc
;
9024 /* We discard the g packet. A minor optimization would be to
9025 hold on to it, and fill the register cache once we have selected
9026 an architecture, but it's too tricky to do safely. */
9032 /* Remote file transfer support. This is host-initiated I/O, not
9033 target-initiated; for target-initiated, see remote-fileio.c. */
9035 /* If *LEFT is at least the length of STRING, copy STRING to
9036 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9037 decrease *LEFT. Otherwise raise an error. */
9040 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9042 int len
= strlen (string
);
9045 error (_("Packet too long for target."));
9047 memcpy (*buffer
, string
, len
);
9051 /* NUL-terminate the buffer as a convenience, if there is
9057 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9058 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9059 decrease *LEFT. Otherwise raise an error. */
9062 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9065 if (2 * len
> *left
)
9066 error (_("Packet too long for target."));
9068 bin2hex (bytes
, *buffer
, len
);
9072 /* NUL-terminate the buffer as a convenience, if there is
9078 /* If *LEFT is large enough, convert VALUE to hex and add it to
9079 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9080 decrease *LEFT. Otherwise raise an error. */
9083 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9085 int len
= hexnumlen (value
);
9088 error (_("Packet too long for target."));
9090 hexnumstr (*buffer
, value
);
9094 /* NUL-terminate the buffer as a convenience, if there is
9100 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9101 value, *REMOTE_ERRNO to the remote error number or zero if none
9102 was included, and *ATTACHMENT to point to the start of the annex
9103 if any. The length of the packet isn't needed here; there may
9104 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9106 Return 0 if the packet could be parsed, -1 if it could not. If
9107 -1 is returned, the other variables may not be initialized. */
9110 remote_hostio_parse_result (char *buffer
, int *retcode
,
9111 int *remote_errno
, char **attachment
)
9118 if (buffer
[0] != 'F')
9122 *retcode
= strtol (&buffer
[1], &p
, 16);
9123 if (errno
!= 0 || p
== &buffer
[1])
9126 /* Check for ",errno". */
9130 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9131 if (errno
!= 0 || p
+ 1 == p2
)
9136 /* Check for ";attachment". If there is no attachment, the
9137 packet should end here. */
9140 *attachment
= p
+ 1;
9143 else if (*p
== '\0')
9149 /* Send a prepared I/O packet to the target and read its response.
9150 The prepared packet is in the global RS->BUF before this function
9151 is called, and the answer is there when we return.
9153 COMMAND_BYTES is the length of the request to send, which may include
9154 binary data. WHICH_PACKET is the packet configuration to check
9155 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9156 is set to the error number and -1 is returned. Otherwise the value
9157 returned by the function is returned.
9159 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9160 attachment is expected; an error will be reported if there's a
9161 mismatch. If one is found, *ATTACHMENT will be set to point into
9162 the packet buffer and *ATTACHMENT_LEN will be set to the
9163 attachment's length. */
9166 remote_hostio_send_command (int command_bytes
, int which_packet
,
9167 int *remote_errno
, char **attachment
,
9168 int *attachment_len
)
9170 struct remote_state
*rs
= get_remote_state ();
9171 int ret
, bytes_read
;
9172 char *attachment_tmp
;
9175 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9177 *remote_errno
= FILEIO_ENOSYS
;
9181 putpkt_binary (rs
->buf
, command_bytes
);
9182 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9184 /* If it timed out, something is wrong. Don't try to parse the
9188 *remote_errno
= FILEIO_EINVAL
;
9192 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9195 *remote_errno
= FILEIO_EINVAL
;
9197 case PACKET_UNKNOWN
:
9198 *remote_errno
= FILEIO_ENOSYS
;
9204 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9207 *remote_errno
= FILEIO_EINVAL
;
9211 /* Make sure we saw an attachment if and only if we expected one. */
9212 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9213 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9215 *remote_errno
= FILEIO_EINVAL
;
9219 /* If an attachment was found, it must point into the packet buffer;
9220 work out how many bytes there were. */
9221 if (attachment_tmp
!= NULL
)
9223 *attachment
= attachment_tmp
;
9224 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9230 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9231 remote file descriptor, or -1 if an error occurs (and set
9235 remote_hostio_open (const char *filename
, int flags
, int mode
,
9238 struct remote_state
*rs
= get_remote_state ();
9240 int left
= get_remote_packet_size () - 1;
9242 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9244 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9246 remote_buffer_add_string (&p
, &left
, ",");
9248 remote_buffer_add_int (&p
, &left
, flags
);
9249 remote_buffer_add_string (&p
, &left
, ",");
9251 remote_buffer_add_int (&p
, &left
, mode
);
9253 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9254 remote_errno
, NULL
, NULL
);
9257 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9258 Return the number of bytes written, or -1 if an error occurs (and
9259 set *REMOTE_ERRNO). */
9262 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9263 ULONGEST offset
, int *remote_errno
)
9265 struct remote_state
*rs
= get_remote_state ();
9267 int left
= get_remote_packet_size ();
9270 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9272 remote_buffer_add_int (&p
, &left
, fd
);
9273 remote_buffer_add_string (&p
, &left
, ",");
9275 remote_buffer_add_int (&p
, &left
, offset
);
9276 remote_buffer_add_string (&p
, &left
, ",");
9278 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9279 get_remote_packet_size () - (p
- rs
->buf
));
9281 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9282 remote_errno
, NULL
, NULL
);
9285 /* Read up to LEN bytes FD on the remote target into READ_BUF
9286 Return the number of bytes read, or -1 if an error occurs (and
9287 set *REMOTE_ERRNO). */
9290 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9291 ULONGEST offset
, int *remote_errno
)
9293 struct remote_state
*rs
= get_remote_state ();
9296 int left
= get_remote_packet_size ();
9297 int ret
, attachment_len
;
9300 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9302 remote_buffer_add_int (&p
, &left
, fd
);
9303 remote_buffer_add_string (&p
, &left
, ",");
9305 remote_buffer_add_int (&p
, &left
, len
);
9306 remote_buffer_add_string (&p
, &left
, ",");
9308 remote_buffer_add_int (&p
, &left
, offset
);
9310 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9311 remote_errno
, &attachment
,
9317 read_len
= remote_unescape_input (attachment
, attachment_len
,
9319 if (read_len
!= ret
)
9320 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9325 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9326 (and set *REMOTE_ERRNO). */
9329 remote_hostio_close (int fd
, int *remote_errno
)
9331 struct remote_state
*rs
= get_remote_state ();
9333 int left
= get_remote_packet_size () - 1;
9335 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9337 remote_buffer_add_int (&p
, &left
, fd
);
9339 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9340 remote_errno
, NULL
, NULL
);
9343 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9344 occurs (and set *REMOTE_ERRNO). */
9347 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9349 struct remote_state
*rs
= get_remote_state ();
9351 int left
= get_remote_packet_size () - 1;
9353 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9355 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9358 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9359 remote_errno
, NULL
, NULL
);
9362 /* Read value of symbolic link FILENAME on the remote target. Return
9363 a null-terminated string allocated via xmalloc, or NULL if an error
9364 occurs (and set *REMOTE_ERRNO). */
9367 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9369 struct remote_state
*rs
= get_remote_state ();
9372 int left
= get_remote_packet_size ();
9373 int len
, attachment_len
;
9377 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9379 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9382 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9383 remote_errno
, &attachment
,
9389 ret
= xmalloc (len
+ 1);
9391 read_len
= remote_unescape_input (attachment
, attachment_len
,
9393 if (read_len
!= len
)
9394 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9401 remote_fileio_errno_to_host (int errnum
)
9425 case FILEIO_ENOTDIR
:
9445 case FILEIO_ENAMETOOLONG
:
9446 return ENAMETOOLONG
;
9452 remote_hostio_error (int errnum
)
9454 int host_error
= remote_fileio_errno_to_host (errnum
);
9456 if (host_error
== -1)
9457 error (_("Unknown remote I/O error %d"), errnum
);
9459 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9463 remote_hostio_close_cleanup (void *opaque
)
9465 int fd
= *(int *) opaque
;
9468 remote_hostio_close (fd
, &remote_errno
);
9473 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9475 const char *filename
= bfd_get_filename (abfd
);
9476 int fd
, remote_errno
;
9479 gdb_assert (remote_filename_p (filename
));
9481 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9484 errno
= remote_fileio_errno_to_host (remote_errno
);
9485 bfd_set_error (bfd_error_system_call
);
9489 stream
= xmalloc (sizeof (int));
9495 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9497 int fd
= *(int *)stream
;
9502 /* Ignore errors on close; these may happen if the remote
9503 connection was already torn down. */
9504 remote_hostio_close (fd
, &remote_errno
);
9510 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9511 file_ptr nbytes
, file_ptr offset
)
9513 int fd
= *(int *)stream
;
9515 file_ptr pos
, bytes
;
9518 while (nbytes
> pos
)
9520 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9521 offset
+ pos
, &remote_errno
);
9523 /* Success, but no bytes, means end-of-file. */
9527 errno
= remote_fileio_errno_to_host (remote_errno
);
9528 bfd_set_error (bfd_error_system_call
);
9539 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9541 /* FIXME: We should probably implement remote_hostio_stat. */
9542 sb
->st_size
= INT_MAX
;
9547 remote_filename_p (const char *filename
)
9549 return strncmp (filename
, "remote:", 7) == 0;
9553 remote_bfd_open (const char *remote_file
, const char *target
)
9555 return bfd_openr_iovec (remote_file
, target
,
9556 remote_bfd_iovec_open
, NULL
,
9557 remote_bfd_iovec_pread
,
9558 remote_bfd_iovec_close
,
9559 remote_bfd_iovec_stat
);
9563 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9565 struct cleanup
*back_to
, *close_cleanup
;
9566 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9569 int bytes_in_buffer
;
9574 error (_("command can only be used with remote target"));
9576 file
= fopen (local_file
, "rb");
9578 perror_with_name (local_file
);
9579 back_to
= make_cleanup_fclose (file
);
9581 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9583 0700, &remote_errno
);
9585 remote_hostio_error (remote_errno
);
9587 /* Send up to this many bytes at once. They won't all fit in the
9588 remote packet limit, so we'll transfer slightly fewer. */
9589 io_size
= get_remote_packet_size ();
9590 buffer
= xmalloc (io_size
);
9591 make_cleanup (xfree
, buffer
);
9593 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9595 bytes_in_buffer
= 0;
9598 while (bytes_in_buffer
|| !saw_eof
)
9602 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9603 io_size
- bytes_in_buffer
,
9608 error (_("Error reading %s."), local_file
);
9611 /* EOF. Unless there is something still in the
9612 buffer from the last iteration, we are done. */
9614 if (bytes_in_buffer
== 0)
9622 bytes
+= bytes_in_buffer
;
9623 bytes_in_buffer
= 0;
9625 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9626 offset
, &remote_errno
);
9629 remote_hostio_error (remote_errno
);
9630 else if (retcode
== 0)
9631 error (_("Remote write of %d bytes returned 0!"), bytes
);
9632 else if (retcode
< bytes
)
9634 /* Short write. Save the rest of the read data for the next
9636 bytes_in_buffer
= bytes
- retcode
;
9637 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9643 discard_cleanups (close_cleanup
);
9644 if (remote_hostio_close (fd
, &remote_errno
))
9645 remote_hostio_error (remote_errno
);
9648 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9649 do_cleanups (back_to
);
9653 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9655 struct cleanup
*back_to
, *close_cleanup
;
9656 int fd
, remote_errno
, bytes
, io_size
;
9662 error (_("command can only be used with remote target"));
9664 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9666 remote_hostio_error (remote_errno
);
9668 file
= fopen (local_file
, "wb");
9670 perror_with_name (local_file
);
9671 back_to
= make_cleanup_fclose (file
);
9673 /* Send up to this many bytes at once. They won't all fit in the
9674 remote packet limit, so we'll transfer slightly fewer. */
9675 io_size
= get_remote_packet_size ();
9676 buffer
= xmalloc (io_size
);
9677 make_cleanup (xfree
, buffer
);
9679 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9684 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9686 /* Success, but no bytes, means end-of-file. */
9689 remote_hostio_error (remote_errno
);
9693 bytes
= fwrite (buffer
, 1, bytes
, file
);
9695 perror_with_name (local_file
);
9698 discard_cleanups (close_cleanup
);
9699 if (remote_hostio_close (fd
, &remote_errno
))
9700 remote_hostio_error (remote_errno
);
9703 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9704 do_cleanups (back_to
);
9708 remote_file_delete (const char *remote_file
, int from_tty
)
9710 int retcode
, remote_errno
;
9713 error (_("command can only be used with remote target"));
9715 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9717 remote_hostio_error (remote_errno
);
9720 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9724 remote_put_command (char *args
, int from_tty
)
9726 struct cleanup
*back_to
;
9730 error_no_arg (_("file to put"));
9732 argv
= gdb_buildargv (args
);
9733 back_to
= make_cleanup_freeargv (argv
);
9734 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9735 error (_("Invalid parameters to remote put"));
9737 remote_file_put (argv
[0], argv
[1], from_tty
);
9739 do_cleanups (back_to
);
9743 remote_get_command (char *args
, int from_tty
)
9745 struct cleanup
*back_to
;
9749 error_no_arg (_("file to get"));
9751 argv
= gdb_buildargv (args
);
9752 back_to
= make_cleanup_freeargv (argv
);
9753 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9754 error (_("Invalid parameters to remote get"));
9756 remote_file_get (argv
[0], argv
[1], from_tty
);
9758 do_cleanups (back_to
);
9762 remote_delete_command (char *args
, int from_tty
)
9764 struct cleanup
*back_to
;
9768 error_no_arg (_("file to delete"));
9770 argv
= gdb_buildargv (args
);
9771 back_to
= make_cleanup_freeargv (argv
);
9772 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9773 error (_("Invalid parameters to remote delete"));
9775 remote_file_delete (argv
[0], from_tty
);
9777 do_cleanups (back_to
);
9781 remote_command (char *args
, int from_tty
)
9783 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9787 remote_can_execute_reverse (void)
9789 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9790 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9797 remote_supports_non_stop (void)
9803 remote_supports_disable_randomization (void)
9805 /* Only supported in extended mode. */
9810 remote_supports_multi_process (void)
9812 struct remote_state
*rs
= get_remote_state ();
9814 /* Only extended-remote handles being attached to multiple
9815 processes, even though plain remote can use the multi-process
9816 thread id extensions, so that GDB knows the target process's
9818 return rs
->extended
&& remote_multi_process_p (rs
);
9822 remote_supports_cond_tracepoints (void)
9824 struct remote_state
*rs
= get_remote_state ();
9826 return rs
->cond_tracepoints
;
9830 remote_supports_fast_tracepoints (void)
9832 struct remote_state
*rs
= get_remote_state ();
9834 return rs
->fast_tracepoints
;
9838 remote_supports_static_tracepoints (void)
9840 struct remote_state
*rs
= get_remote_state ();
9842 return rs
->static_tracepoints
;
9846 remote_supports_install_in_trace (void)
9848 struct remote_state
*rs
= get_remote_state ();
9850 return rs
->install_in_trace
;
9854 remote_supports_enable_disable_tracepoint (void)
9856 struct remote_state
*rs
= get_remote_state ();
9858 return rs
->enable_disable_tracepoints
;
9862 remote_supports_string_tracing (void)
9864 struct remote_state
*rs
= get_remote_state ();
9866 return rs
->string_tracing
;
9870 remote_trace_init (void)
9873 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9874 if (strcmp (target_buf
, "OK") != 0)
9875 error (_("Target does not support this command."));
9878 static void free_actions_list (char **actions_list
);
9879 static void free_actions_list_cleanup_wrapper (void *);
9881 free_actions_list_cleanup_wrapper (void *al
)
9883 free_actions_list (al
);
9887 free_actions_list (char **actions_list
)
9891 if (actions_list
== 0)
9894 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9895 xfree (actions_list
[ndx
]);
9897 xfree (actions_list
);
9900 /* Recursive routine to walk through command list including loops, and
9901 download packets for each command. */
9904 remote_download_command_source (int num
, ULONGEST addr
,
9905 struct command_line
*cmds
)
9907 struct remote_state
*rs
= get_remote_state ();
9908 struct command_line
*cmd
;
9910 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9912 QUIT
; /* Allow user to bail out with ^C. */
9913 strcpy (rs
->buf
, "QTDPsrc:");
9914 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9915 rs
->buf
+ strlen (rs
->buf
),
9916 rs
->buf_size
- strlen (rs
->buf
));
9918 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9919 if (strcmp (target_buf
, "OK"))
9920 warning (_("Target does not support source download."));
9922 if (cmd
->control_type
== while_control
9923 || cmd
->control_type
== while_stepping_control
)
9925 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9927 QUIT
; /* Allow user to bail out with ^C. */
9928 strcpy (rs
->buf
, "QTDPsrc:");
9929 encode_source_string (num
, addr
, "cmd", "end",
9930 rs
->buf
+ strlen (rs
->buf
),
9931 rs
->buf_size
- strlen (rs
->buf
));
9933 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9934 if (strcmp (target_buf
, "OK"))
9935 warning (_("Target does not support source download."));
9941 remote_download_tracepoint (struct bp_location
*loc
)
9948 char **stepping_actions
;
9950 struct cleanup
*old_chain
= NULL
;
9951 struct agent_expr
*aexpr
;
9952 struct cleanup
*aexpr_chain
= NULL
;
9954 struct breakpoint
*b
= loc
->owner
;
9955 struct tracepoint
*t
= (struct tracepoint
*) b
;
9957 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9958 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9960 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9963 tpaddr
= loc
->address
;
9964 sprintf_vma (addrbuf
, tpaddr
);
9965 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9966 addrbuf
, /* address */
9967 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9968 t
->step_count
, t
->pass_count
);
9969 /* Fast tracepoints are mostly handled by the target, but we can
9970 tell the target how big of an instruction block should be moved
9972 if (b
->type
== bp_fast_tracepoint
)
9974 /* Only test for support at download time; we may not know
9975 target capabilities at definition time. */
9976 if (remote_supports_fast_tracepoints ())
9980 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9981 tpaddr
, &isize
, NULL
))
9982 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9984 /* If it passed validation at definition but fails now,
9985 something is very wrong. */
9986 internal_error (__FILE__
, __LINE__
,
9987 _("Fast tracepoint not "
9988 "valid during download"));
9991 /* Fast tracepoints are functionally identical to regular
9992 tracepoints, so don't take lack of support as a reason to
9993 give up on the trace run. */
9994 warning (_("Target does not support fast tracepoints, "
9995 "downloading %d as regular tracepoint"), b
->number
);
9997 else if (b
->type
== bp_static_tracepoint
)
9999 /* Only test for support at download time; we may not know
10000 target capabilities at definition time. */
10001 if (remote_supports_static_tracepoints ())
10003 struct static_tracepoint_marker marker
;
10005 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10006 strcat (buf
, ":S");
10008 error (_("Static tracepoint not valid during download"));
10011 /* Fast tracepoints are functionally identical to regular
10012 tracepoints, so don't take lack of support as a reason
10013 to give up on the trace run. */
10014 error (_("Target does not support static tracepoints"));
10016 /* If the tracepoint has a conditional, make it into an agent
10017 expression and append to the definition. */
10020 /* Only test support at download time, we may not know target
10021 capabilities at definition time. */
10022 if (remote_supports_cond_tracepoints ())
10024 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10025 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10026 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
10027 pkt
= buf
+ strlen (buf
);
10028 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10029 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10031 do_cleanups (aexpr_chain
);
10034 warning (_("Target does not support conditional tracepoints, "
10035 "ignoring tp %d cond"), b
->number
);
10038 if (b
->commands
|| *default_collect
)
10041 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10042 if (strcmp (target_buf
, "OK"))
10043 error (_("Target does not support tracepoints."));
10045 /* do_single_steps (t); */
10048 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10050 QUIT
; /* Allow user to bail out with ^C. */
10051 sprintf (buf
, "QTDP:-%x:%s:%s%c",
10052 b
->number
, addrbuf
, /* address */
10054 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10057 remote_get_noisy_reply (&target_buf
,
10059 if (strcmp (target_buf
, "OK"))
10060 error (_("Error on target while setting tracepoints."));
10063 if (stepping_actions
)
10065 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10067 QUIT
; /* Allow user to bail out with ^C. */
10068 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
10069 b
->number
, addrbuf
, /* address */
10070 ((ndx
== 0) ? "S" : ""),
10071 stepping_actions
[ndx
],
10072 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10074 remote_get_noisy_reply (&target_buf
,
10076 if (strcmp (target_buf
, "OK"))
10077 error (_("Error on target while setting tracepoints."));
10081 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10084 if (b
->addr_string
)
10086 strcpy (buf
, "QTDPsrc:");
10087 encode_source_string (b
->number
, loc
->address
,
10088 "at", b
->addr_string
, buf
+ strlen (buf
),
10089 2048 - strlen (buf
));
10092 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10093 if (strcmp (target_buf
, "OK"))
10094 warning (_("Target does not support source download."));
10096 if (b
->cond_string
)
10098 strcpy (buf
, "QTDPsrc:");
10099 encode_source_string (b
->number
, loc
->address
,
10100 "cond", b
->cond_string
, buf
+ strlen (buf
),
10101 2048 - strlen (buf
));
10103 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10104 if (strcmp (target_buf
, "OK"))
10105 warning (_("Target does not support source download."));
10107 remote_download_command_source (b
->number
, loc
->address
,
10108 breakpoint_commands (b
));
10111 do_cleanups (old_chain
);
10115 remote_can_download_tracepoint (void)
10117 struct trace_status
*ts
= current_trace_status ();
10118 int status
= remote_get_trace_status (ts
);
10120 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10123 /* If we are in a tracing experiment, but remote stub doesn't support
10124 installing tracepoint in trace, we have to return. */
10125 if (!remote_supports_install_in_trace ())
10133 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10135 struct remote_state
*rs
= get_remote_state ();
10138 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10139 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10140 p
= rs
->buf
+ strlen (rs
->buf
);
10141 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10142 error (_("Trace state variable name too long for tsv definition packet"));
10143 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10146 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10147 if (*target_buf
== '\0')
10148 error (_("Target does not support this command."));
10149 if (strcmp (target_buf
, "OK") != 0)
10150 error (_("Error on target while downloading trace state variable."));
10154 remote_enable_tracepoint (struct bp_location
*location
)
10156 struct remote_state
*rs
= get_remote_state ();
10159 sprintf_vma (addr_buf
, location
->address
);
10160 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10162 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10163 if (*rs
->buf
== '\0')
10164 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10165 if (strcmp (rs
->buf
, "OK") != 0)
10166 error (_("Error on target while enabling tracepoint."));
10170 remote_disable_tracepoint (struct bp_location
*location
)
10172 struct remote_state
*rs
= get_remote_state ();
10175 sprintf_vma (addr_buf
, location
->address
);
10176 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10178 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10179 if (*rs
->buf
== '\0')
10180 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10181 if (strcmp (rs
->buf
, "OK") != 0)
10182 error (_("Error on target while disabling tracepoint."));
10186 remote_trace_set_readonly_regions (void)
10189 bfd_size_type size
;
10195 return; /* No information to give. */
10197 strcpy (target_buf
, "QTro");
10198 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10200 char tmp1
[40], tmp2
[40];
10203 if ((s
->flags
& SEC_LOAD
) == 0 ||
10204 /* (s->flags & SEC_CODE) == 0 || */
10205 (s
->flags
& SEC_READONLY
) == 0)
10209 vma
= bfd_get_section_vma (,s
);
10210 size
= bfd_get_section_size (s
);
10211 sprintf_vma (tmp1
, vma
);
10212 sprintf_vma (tmp2
, vma
+ size
);
10213 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10214 if (offset
+ sec_length
+ 1 > target_buf_size
)
10216 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10219 Too many sections for read-only sections definition packet."));
10222 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10223 offset
+= sec_length
;
10227 putpkt (target_buf
);
10228 getpkt (&target_buf
, &target_buf_size
, 0);
10233 remote_trace_start (void)
10235 putpkt ("QTStart");
10236 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10237 if (*target_buf
== '\0')
10238 error (_("Target does not support this command."));
10239 if (strcmp (target_buf
, "OK") != 0)
10240 error (_("Bogus reply from target: %s"), target_buf
);
10244 remote_get_trace_status (struct trace_status
*ts
)
10246 /* Initialize it just to avoid a GCC false warning. */
10248 /* FIXME we need to get register block size some other way. */
10249 extern int trace_regblock_size
;
10250 volatile struct gdb_exception ex
;
10252 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10254 putpkt ("qTStatus");
10256 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10258 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10262 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10266 /* If the remote target doesn't do tracing, flag it. */
10270 /* We're working with a live target. */
10273 /* Set some defaults. */
10274 ts
->running_known
= 0;
10275 ts
->stop_reason
= trace_stop_reason_unknown
;
10276 ts
->traceframe_count
= -1;
10277 ts
->buffer_free
= 0;
10280 error (_("Bogus trace status reply from target: %s"), target_buf
);
10282 parse_trace_status (p
, ts
);
10284 return ts
->running
;
10288 remote_get_tracepoint_status (struct breakpoint
*bp
,
10289 struct uploaded_tp
*utp
)
10291 struct remote_state
*rs
= get_remote_state ();
10293 struct bp_location
*loc
;
10294 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10298 tp
->base
.hit_count
= 0;
10299 tp
->traceframe_usage
= 0;
10300 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10302 /* If the tracepoint was never downloaded, don't go asking for
10304 if (tp
->number_on_target
== 0)
10306 sprintf (rs
->buf
, "qTP:%x:%s", tp
->number_on_target
,
10307 phex_nz (loc
->address
, 0));
10309 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10310 if (reply
&& *reply
)
10313 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10319 utp
->hit_count
= 0;
10320 utp
->traceframe_usage
= 0;
10321 sprintf (rs
->buf
, "qTP:%x:%s", utp
->number
, phex_nz (utp
->addr
, 0));
10323 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10324 if (reply
&& *reply
)
10327 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10333 remote_trace_stop (void)
10336 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10337 if (*target_buf
== '\0')
10338 error (_("Target does not support this command."));
10339 if (strcmp (target_buf
, "OK") != 0)
10340 error (_("Bogus reply from target: %s"), target_buf
);
10344 remote_trace_find (enum trace_find_type type
, int num
,
10345 ULONGEST addr1
, ULONGEST addr2
,
10348 struct remote_state
*rs
= get_remote_state ();
10350 int target_frameno
= -1, target_tracept
= -1;
10352 /* Lookups other than by absolute frame number depend on the current
10353 trace selected, so make sure it is correct on the remote end
10355 if (type
!= tfind_number
)
10356 set_remote_traceframe ();
10359 strcpy (p
, "QTFrame:");
10360 p
= strchr (p
, '\0');
10364 sprintf (p
, "%x", num
);
10367 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10370 sprintf (p
, "tdp:%x", num
);
10373 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10375 case tfind_outside
:
10376 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10379 error (_("Unknown trace find type %d"), type
);
10383 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10384 if (*reply
== '\0')
10385 error (_("Target does not support this command."));
10387 while (reply
&& *reply
)
10392 target_frameno
= (int) strtol (p
, &reply
, 16);
10394 error (_("Unable to parse trace frame number"));
10395 /* Don't update our remote traceframe number cache on failure
10396 to select a remote traceframe. */
10397 if (target_frameno
== -1)
10402 target_tracept
= (int) strtol (p
, &reply
, 16);
10404 error (_("Unable to parse tracepoint number"));
10406 case 'O': /* "OK"? */
10407 if (reply
[1] == 'K' && reply
[2] == '\0')
10410 error (_("Bogus reply from target: %s"), reply
);
10413 error (_("Bogus reply from target: %s"), reply
);
10416 *tpp
= target_tracept
;
10418 remote_traceframe_number
= target_frameno
;
10419 return target_frameno
;
10423 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10425 struct remote_state
*rs
= get_remote_state ();
10429 set_remote_traceframe ();
10431 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10433 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10434 if (reply
&& *reply
)
10438 unpack_varlen_hex (reply
+ 1, &uval
);
10439 *val
= (LONGEST
) uval
;
10447 remote_save_trace_data (const char *filename
)
10449 struct remote_state
*rs
= get_remote_state ();
10453 strcpy (p
, "QTSave:");
10455 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10456 error (_("Remote file name too long for trace save packet"));
10457 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10460 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10461 if (*reply
== '\0')
10462 error (_("Target does not support this command."));
10463 if (strcmp (reply
, "OK") != 0)
10464 error (_("Bogus reply from target: %s"), reply
);
10468 /* This is basically a memory transfer, but needs to be its own packet
10469 because we don't know how the target actually organizes its trace
10470 memory, plus we want to be able to ask for as much as possible, but
10471 not be unhappy if we don't get as much as we ask for. */
10474 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10476 struct remote_state
*rs
= get_remote_state ();
10482 strcpy (p
, "qTBuffer:");
10484 p
+= hexnumstr (p
, offset
);
10486 p
+= hexnumstr (p
, len
);
10490 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10491 if (reply
&& *reply
)
10493 /* 'l' by itself means we're at the end of the buffer and
10494 there is nothing more to get. */
10498 /* Convert the reply into binary. Limit the number of bytes to
10499 convert according to our passed-in buffer size, rather than
10500 what was returned in the packet; if the target is
10501 unexpectedly generous and gives us a bigger reply than we
10502 asked for, we don't want to crash. */
10503 rslt
= hex2bin (target_buf
, buf
, len
);
10507 /* Something went wrong, flag as an error. */
10512 remote_set_disconnected_tracing (int val
)
10514 struct remote_state
*rs
= get_remote_state ();
10516 if (rs
->disconnected_tracing
)
10520 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10522 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10523 if (*reply
== '\0')
10524 error (_("Target does not support this command."));
10525 if (strcmp (reply
, "OK") != 0)
10526 error (_("Bogus reply from target: %s"), reply
);
10529 warning (_("Target does not support disconnected tracing."));
10533 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10535 struct thread_info
*info
= find_thread_ptid (ptid
);
10537 if (info
&& info
->private)
10538 return info
->private->core
;
10543 remote_set_circular_trace_buffer (int val
)
10545 struct remote_state
*rs
= get_remote_state ();
10548 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10550 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10551 if (*reply
== '\0')
10552 error (_("Target does not support this command."));
10553 if (strcmp (reply
, "OK") != 0)
10554 error (_("Bogus reply from target: %s"), reply
);
10557 static struct traceframe_info
*
10558 remote_traceframe_info (void)
10562 text
= target_read_stralloc (¤t_target
,
10563 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10566 struct traceframe_info
*info
;
10567 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10569 info
= parse_traceframe_info (text
);
10570 do_cleanups (back_to
);
10577 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10578 instruction on which a fast tracepoint may be placed. Returns -1
10579 if the packet is not supported, and 0 if the minimum instruction
10580 length is unknown. */
10583 remote_get_min_fast_tracepoint_insn_len (void)
10585 struct remote_state
*rs
= get_remote_state ();
10588 sprintf (rs
->buf
, "qTMinFTPILen");
10590 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10591 if (*reply
== '\0')
10595 ULONGEST min_insn_len
;
10597 unpack_varlen_hex (reply
, &min_insn_len
);
10599 return (int) min_insn_len
;
10604 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10606 struct remote_state
*rs
= get_remote_state ();
10608 char *buf
= rs
->buf
;
10609 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10612 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10615 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10616 nbytes
= bin2hex (user
, buf
, 0);
10622 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10623 nbytes
= bin2hex (notes
, buf
, 0);
10629 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10630 nbytes
= bin2hex (stop_notes
, buf
, 0);
10634 /* Ensure the buffer is terminated. */
10638 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10639 if (*reply
== '\0')
10642 if (strcmp (reply
, "OK") != 0)
10643 error (_("Bogus reply from target: %s"), reply
);
10649 init_remote_ops (void)
10651 remote_ops
.to_shortname
= "remote";
10652 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10653 remote_ops
.to_doc
=
10654 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10655 Specify the serial device it is connected to\n\
10656 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10657 remote_ops
.to_open
= remote_open
;
10658 remote_ops
.to_close
= remote_close
;
10659 remote_ops
.to_detach
= remote_detach
;
10660 remote_ops
.to_disconnect
= remote_disconnect
;
10661 remote_ops
.to_resume
= remote_resume
;
10662 remote_ops
.to_wait
= remote_wait
;
10663 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10664 remote_ops
.to_store_registers
= remote_store_registers
;
10665 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10666 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10667 remote_ops
.to_files_info
= remote_files_info
;
10668 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10669 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10670 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10671 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10672 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10673 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10674 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10675 remote_ops
.to_region_ok_for_hw_watchpoint
10676 = remote_region_ok_for_hw_watchpoint
;
10677 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10678 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10679 remote_ops
.to_kill
= remote_kill
;
10680 remote_ops
.to_load
= generic_load
;
10681 remote_ops
.to_mourn_inferior
= remote_mourn
;
10682 remote_ops
.to_pass_signals
= remote_pass_signals
;
10683 remote_ops
.to_thread_alive
= remote_thread_alive
;
10684 remote_ops
.to_find_new_threads
= remote_threads_info
;
10685 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10686 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10687 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10688 remote_ops
.to_stop
= remote_stop
;
10689 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10690 remote_ops
.to_rcmd
= remote_rcmd
;
10691 remote_ops
.to_log_command
= serial_log_command
;
10692 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10693 remote_ops
.to_stratum
= process_stratum
;
10694 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10695 remote_ops
.to_has_memory
= default_child_has_memory
;
10696 remote_ops
.to_has_stack
= default_child_has_stack
;
10697 remote_ops
.to_has_registers
= default_child_has_registers
;
10698 remote_ops
.to_has_execution
= default_child_has_execution
;
10699 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10700 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10701 remote_ops
.to_magic
= OPS_MAGIC
;
10702 remote_ops
.to_memory_map
= remote_memory_map
;
10703 remote_ops
.to_flash_erase
= remote_flash_erase
;
10704 remote_ops
.to_flash_done
= remote_flash_done
;
10705 remote_ops
.to_read_description
= remote_read_description
;
10706 remote_ops
.to_search_memory
= remote_search_memory
;
10707 remote_ops
.to_can_async_p
= remote_can_async_p
;
10708 remote_ops
.to_is_async_p
= remote_is_async_p
;
10709 remote_ops
.to_async
= remote_async
;
10710 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10711 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10712 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10713 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10714 remote_ops
.to_supports_disable_randomization
10715 = remote_supports_disable_randomization
;
10716 remote_ops
.to_fileio_open
= remote_hostio_open
;
10717 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
10718 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
10719 remote_ops
.to_fileio_close
= remote_hostio_close
;
10720 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
10721 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
10722 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10723 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10724 remote_ops
.to_trace_init
= remote_trace_init
;
10725 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10726 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10727 remote_ops
.to_download_trace_state_variable
10728 = remote_download_trace_state_variable
;
10729 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10730 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10731 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10732 remote_ops
.to_trace_start
= remote_trace_start
;
10733 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10734 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
10735 remote_ops
.to_trace_stop
= remote_trace_stop
;
10736 remote_ops
.to_trace_find
= remote_trace_find
;
10737 remote_ops
.to_get_trace_state_variable_value
10738 = remote_get_trace_state_variable_value
;
10739 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10740 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10741 remote_ops
.to_upload_trace_state_variables
10742 = remote_upload_trace_state_variables
;
10743 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10744 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10745 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10746 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10747 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
10748 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10749 remote_ops
.to_verify_memory
= remote_verify_memory
;
10750 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10751 remote_ops
.to_set_permissions
= remote_set_permissions
;
10752 remote_ops
.to_static_tracepoint_marker_at
10753 = remote_static_tracepoint_marker_at
;
10754 remote_ops
.to_static_tracepoint_markers_by_strid
10755 = remote_static_tracepoint_markers_by_strid
;
10756 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10759 /* Set up the extended remote vector by making a copy of the standard
10760 remote vector and adding to it. */
10763 init_extended_remote_ops (void)
10765 extended_remote_ops
= remote_ops
;
10767 extended_remote_ops
.to_shortname
= "extended-remote";
10768 extended_remote_ops
.to_longname
=
10769 "Extended remote serial target in gdb-specific protocol";
10770 extended_remote_ops
.to_doc
=
10771 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10772 Specify the serial device it is connected to (e.g. /dev/ttya).";
10773 extended_remote_ops
.to_open
= extended_remote_open
;
10774 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10775 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10776 extended_remote_ops
.to_detach
= extended_remote_detach
;
10777 extended_remote_ops
.to_attach
= extended_remote_attach
;
10778 extended_remote_ops
.to_kill
= extended_remote_kill
;
10779 extended_remote_ops
.to_supports_disable_randomization
10780 = extended_remote_supports_disable_randomization
;
10784 remote_can_async_p (void)
10786 if (!target_async_permitted
)
10787 /* We only enable async when the user specifically asks for it. */
10790 /* We're async whenever the serial device is. */
10791 return serial_can_async_p (remote_desc
);
10795 remote_is_async_p (void)
10797 if (!target_async_permitted
)
10798 /* We only enable async when the user specifically asks for it. */
10801 /* We're async whenever the serial device is. */
10802 return serial_is_async_p (remote_desc
);
10805 /* Pass the SERIAL event on and up to the client. One day this code
10806 will be able to delay notifying the client of an event until the
10807 point where an entire packet has been received. */
10809 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10811 static void *async_client_context
;
10812 static serial_event_ftype remote_async_serial_handler
;
10815 remote_async_serial_handler (struct serial
*scb
, void *context
)
10817 /* Don't propogate error information up to the client. Instead let
10818 the client find out about the error by querying the target. */
10819 async_client_callback (INF_REG_EVENT
, async_client_context
);
10823 remote_async_inferior_event_handler (gdb_client_data data
)
10825 inferior_event_handler (INF_REG_EVENT
, NULL
);
10829 remote_async_get_pending_events_handler (gdb_client_data data
)
10831 remote_get_pending_stop_replies ();
10835 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10836 void *context
), void *context
)
10838 if (callback
!= NULL
)
10840 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10841 async_client_callback
= callback
;
10842 async_client_context
= context
;
10845 serial_async (remote_desc
, NULL
, NULL
);
10849 set_remote_cmd (char *args
, int from_tty
)
10851 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10855 show_remote_cmd (char *args
, int from_tty
)
10857 /* We can't just use cmd_show_list here, because we want to skip
10858 the redundant "show remote Z-packet" and the legacy aliases. */
10859 struct cleanup
*showlist_chain
;
10860 struct cmd_list_element
*list
= remote_show_cmdlist
;
10861 struct ui_out
*uiout
= current_uiout
;
10863 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10864 for (; list
!= NULL
; list
= list
->next
)
10865 if (strcmp (list
->name
, "Z-packet") == 0)
10867 else if (list
->type
== not_set_cmd
)
10868 /* Alias commands are exactly like the original, except they
10869 don't have the normal type. */
10873 struct cleanup
*option_chain
10874 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10876 ui_out_field_string (uiout
, "name", list
->name
);
10877 ui_out_text (uiout
, ": ");
10878 if (list
->type
== show_cmd
)
10879 do_setshow_command ((char *) NULL
, from_tty
, list
);
10881 cmd_func (list
, NULL
, from_tty
);
10882 /* Close the tuple. */
10883 do_cleanups (option_chain
);
10886 /* Close the tuple. */
10887 do_cleanups (showlist_chain
);
10891 /* Function to be called whenever a new objfile (shlib) is detected. */
10893 remote_new_objfile (struct objfile
*objfile
)
10895 if (remote_desc
!= 0) /* Have a remote connection. */
10896 remote_check_symbols (objfile
);
10899 /* Pull all the tracepoints defined on the target and create local
10900 data structures representing them. We don't want to create real
10901 tracepoints yet, we don't want to mess up the user's existing
10905 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10907 struct remote_state
*rs
= get_remote_state ();
10910 /* Ask for a first packet of tracepoint definition. */
10912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10914 while (*p
&& *p
!= 'l')
10916 parse_tracepoint_definition (p
, utpp
);
10917 /* Ask for another packet of tracepoint definition. */
10919 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10926 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10928 struct remote_state
*rs
= get_remote_state ();
10931 /* Ask for a first packet of variable definition. */
10933 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10935 while (*p
&& *p
!= 'l')
10937 parse_tsv_definition (p
, utsvp
);
10938 /* Ask for another packet of variable definition. */
10940 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10947 _initialize_remote (void)
10949 struct remote_state
*rs
;
10950 struct cmd_list_element
*cmd
;
10953 /* architecture specific data */
10954 remote_gdbarch_data_handle
=
10955 gdbarch_data_register_post_init (init_remote_state
);
10956 remote_g_packet_data_handle
=
10957 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10959 /* Initialize the per-target state. At the moment there is only one
10960 of these, not one per target. Only one target is active at a
10961 time. The default buffer size is unimportant; it will be expanded
10962 whenever a larger buffer is needed. */
10963 rs
= get_remote_state_raw ();
10964 rs
->buf_size
= 400;
10965 rs
->buf
= xmalloc (rs
->buf_size
);
10967 init_remote_ops ();
10968 add_target (&remote_ops
);
10970 init_extended_remote_ops ();
10971 add_target (&extended_remote_ops
);
10973 /* Hook into new objfile notification. */
10974 observer_attach_new_objfile (remote_new_objfile
);
10976 /* Set up signal handlers. */
10977 sigint_remote_token
=
10978 create_async_signal_handler (async_remote_interrupt
, NULL
);
10979 sigint_remote_twice_token
=
10980 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10983 init_remote_threadtests ();
10986 /* set/show remote ... */
10988 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10989 Remote protocol specific variables\n\
10990 Configure various remote-protocol specific variables such as\n\
10991 the packets being used"),
10992 &remote_set_cmdlist
, "set remote ",
10993 0 /* allow-unknown */, &setlist
);
10994 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10995 Remote protocol specific variables\n\
10996 Configure various remote-protocol specific variables such as\n\
10997 the packets being used"),
10998 &remote_show_cmdlist
, "show remote ",
10999 0 /* allow-unknown */, &showlist
);
11001 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11002 Compare section data on target to the exec file.\n\
11003 Argument is a single section name (default: all loaded sections)."),
11006 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11007 Send an arbitrary packet to a remote target.\n\
11008 maintenance packet TEXT\n\
11009 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11010 this command sends the string TEXT to the inferior, and displays the\n\
11011 response packet. GDB supplies the initial `$' character, and the\n\
11012 terminating `#' character and checksum."),
11015 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11016 Set whether to send break if interrupted."), _("\
11017 Show whether to send break if interrupted."), _("\
11018 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11019 set_remotebreak
, show_remotebreak
,
11020 &setlist
, &showlist
);
11021 cmd_name
= "remotebreak";
11022 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11023 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11024 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11025 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11026 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11028 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11029 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11031 Set interrupt sequence to remote target."), _("\
11032 Show interrupt sequence to remote target."), _("\
11033 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11034 NULL
, show_interrupt_sequence
,
11035 &remote_set_cmdlist
,
11036 &remote_show_cmdlist
);
11038 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11039 &interrupt_on_connect
, _("\
11040 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11041 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11042 If set, interrupt sequence is sent to remote target."),
11044 &remote_set_cmdlist
, &remote_show_cmdlist
);
11046 /* Install commands for configuring memory read/write packets. */
11048 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11049 Set the maximum number of bytes per memory write packet (deprecated)."),
11051 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11052 Show the maximum number of bytes per memory write packet (deprecated)."),
11054 add_cmd ("memory-write-packet-size", no_class
,
11055 set_memory_write_packet_size
, _("\
11056 Set the maximum number of bytes per memory-write packet.\n\
11057 Specify the number of bytes in a packet or 0 (zero) for the\n\
11058 default packet size. The actual limit is further reduced\n\
11059 dependent on the target. Specify ``fixed'' to disable the\n\
11060 further restriction and ``limit'' to enable that restriction."),
11061 &remote_set_cmdlist
);
11062 add_cmd ("memory-read-packet-size", no_class
,
11063 set_memory_read_packet_size
, _("\
11064 Set the maximum number of bytes per memory-read packet.\n\
11065 Specify the number of bytes in a packet or 0 (zero) for the\n\
11066 default packet size. The actual limit is further reduced\n\
11067 dependent on the target. Specify ``fixed'' to disable the\n\
11068 further restriction and ``limit'' to enable that restriction."),
11069 &remote_set_cmdlist
);
11070 add_cmd ("memory-write-packet-size", no_class
,
11071 show_memory_write_packet_size
,
11072 _("Show the maximum number of bytes per memory-write packet."),
11073 &remote_show_cmdlist
);
11074 add_cmd ("memory-read-packet-size", no_class
,
11075 show_memory_read_packet_size
,
11076 _("Show the maximum number of bytes per memory-read packet."),
11077 &remote_show_cmdlist
);
11079 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11080 &remote_hw_watchpoint_limit
, _("\
11081 Set the maximum number of target hardware watchpoints."), _("\
11082 Show the maximum number of target hardware watchpoints."), _("\
11083 Specify a negative limit for unlimited."),
11084 NULL
, NULL
, /* FIXME: i18n: The maximum
11085 number of target hardware
11086 watchpoints is %s. */
11087 &remote_set_cmdlist
, &remote_show_cmdlist
);
11088 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11089 &remote_hw_watchpoint_length_limit
, _("\
11090 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11091 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11092 Specify a negative limit for unlimited."),
11093 NULL
, NULL
, /* FIXME: i18n: The maximum
11094 length (in bytes) of a target
11095 hardware watchpoint is %s. */
11096 &remote_set_cmdlist
, &remote_show_cmdlist
);
11097 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11098 &remote_hw_breakpoint_limit
, _("\
11099 Set the maximum number of target hardware breakpoints."), _("\
11100 Show the maximum number of target hardware breakpoints."), _("\
11101 Specify a negative limit for unlimited."),
11102 NULL
, NULL
, /* FIXME: i18n: The maximum
11103 number of target hardware
11104 breakpoints is %s. */
11105 &remote_set_cmdlist
, &remote_show_cmdlist
);
11107 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
11108 &remote_address_size
, _("\
11109 Set the maximum size of the address (in bits) in a memory packet."), _("\
11110 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11112 NULL
, /* FIXME: i18n: */
11113 &setlist
, &showlist
);
11115 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11116 "X", "binary-download", 1);
11118 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11119 "vCont", "verbose-resume", 0);
11121 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11122 "QPassSignals", "pass-signals", 0);
11124 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11125 "qSymbol", "symbol-lookup", 0);
11127 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11128 "P", "set-register", 1);
11130 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11131 "p", "fetch-register", 1);
11133 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11134 "Z0", "software-breakpoint", 0);
11136 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11137 "Z1", "hardware-breakpoint", 0);
11139 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11140 "Z2", "write-watchpoint", 0);
11142 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11143 "Z3", "read-watchpoint", 0);
11145 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11146 "Z4", "access-watchpoint", 0);
11148 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11149 "qXfer:auxv:read", "read-aux-vector", 0);
11151 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11152 "qXfer:features:read", "target-features", 0);
11154 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11155 "qXfer:libraries:read", "library-info", 0);
11157 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11158 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11160 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11161 "qXfer:memory-map:read", "memory-map", 0);
11163 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11164 "qXfer:spu:read", "read-spu-object", 0);
11166 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11167 "qXfer:spu:write", "write-spu-object", 0);
11169 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11170 "qXfer:osdata:read", "osdata", 0);
11172 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11173 "qXfer:threads:read", "threads", 0);
11175 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11176 "qXfer:siginfo:read", "read-siginfo-object", 0);
11178 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11179 "qXfer:siginfo:write", "write-siginfo-object", 0);
11181 add_packet_config_cmd
11182 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11183 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11185 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11186 "qGetTLSAddr", "get-thread-local-storage-address",
11189 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11190 "qGetTIBAddr", "get-thread-information-block-address",
11193 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11194 "bc", "reverse-continue", 0);
11196 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11197 "bs", "reverse-step", 0);
11199 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11200 "qSupported", "supported-packets", 0);
11202 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11203 "qSearch:memory", "search-memory", 0);
11205 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11206 "vFile:open", "hostio-open", 0);
11208 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11209 "vFile:pread", "hostio-pread", 0);
11211 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11212 "vFile:pwrite", "hostio-pwrite", 0);
11214 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11215 "vFile:close", "hostio-close", 0);
11217 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11218 "vFile:unlink", "hostio-unlink", 0);
11220 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11221 "vFile:readlink", "hostio-readlink", 0);
11223 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11224 "vAttach", "attach", 0);
11226 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11229 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11230 "QStartNoAckMode", "noack", 0);
11232 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11233 "vKill", "kill", 0);
11235 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11236 "qAttached", "query-attached", 0);
11238 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11239 "ConditionalTracepoints",
11240 "conditional-tracepoints", 0);
11241 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11242 "FastTracepoints", "fast-tracepoints", 0);
11244 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11245 "TracepointSource", "TracepointSource", 0);
11247 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11248 "QAllow", "allow", 0);
11250 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11251 "StaticTracepoints", "static-tracepoints", 0);
11253 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11254 "InstallInTrace", "install-in-trace", 0);
11256 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11257 "qXfer:statictrace:read", "read-sdata-object", 0);
11259 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11260 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11262 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11263 "QDisableRandomization", "disable-randomization", 0);
11265 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11266 Z sub-packet has its own set and show commands, but users may
11267 have sets to this variable in their .gdbinit files (or in their
11269 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11270 &remote_Z_packet_detect
, _("\
11271 Set use of remote protocol `Z' packets"), _("\
11272 Show use of remote protocol `Z' packets "), _("\
11273 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11275 set_remote_protocol_Z_packet_cmd
,
11276 show_remote_protocol_Z_packet_cmd
,
11277 /* FIXME: i18n: Use of remote protocol
11278 `Z' packets is %s. */
11279 &remote_set_cmdlist
, &remote_show_cmdlist
);
11281 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11282 Manipulate files on the remote system\n\
11283 Transfer files to and from the remote target system."),
11284 &remote_cmdlist
, "remote ",
11285 0 /* allow-unknown */, &cmdlist
);
11287 add_cmd ("put", class_files
, remote_put_command
,
11288 _("Copy a local file to the remote system."),
11291 add_cmd ("get", class_files
, remote_get_command
,
11292 _("Copy a remote file to the local system."),
11295 add_cmd ("delete", class_files
, remote_delete_command
,
11296 _("Delete a remote file."),
11299 remote_exec_file
= xstrdup ("");
11300 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11301 &remote_exec_file
, _("\
11302 Set the remote pathname for \"run\""), _("\
11303 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11304 &remote_set_cmdlist
, &remote_show_cmdlist
);
11306 /* Eventually initialize fileio. See fileio.c */
11307 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11309 /* Take advantage of the fact that the LWP field is not used, to tag
11310 special ptids with it set to != 0. */
11311 magic_null_ptid
= ptid_build (42000, 1, -1);
11312 not_sent_ptid
= ptid_build (42000, 1, -2);
11313 any_thread_ptid
= ptid_build (42000, 1, 0);
11315 target_buf_size
= 2048;
11316 target_buf
= xmalloc (target_buf_size
);