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
->extended
&& 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
,
1242 PACKET_qXfer_features
,
1243 PACKET_qXfer_libraries
,
1244 PACKET_qXfer_libraries_svr4
,
1245 PACKET_qXfer_memory_map
,
1246 PACKET_qXfer_spu_read
,
1247 PACKET_qXfer_spu_write
,
1248 PACKET_qXfer_osdata
,
1249 PACKET_qXfer_threads
,
1250 PACKET_qXfer_statictrace_read
,
1251 PACKET_qXfer_traceframe_info
,
1255 PACKET_QPassSignals
,
1256 PACKET_qSearch_memory
,
1259 PACKET_QStartNoAckMode
,
1261 PACKET_qXfer_siginfo_read
,
1262 PACKET_qXfer_siginfo_write
,
1264 PACKET_ConditionalTracepoints
,
1265 PACKET_FastTracepoints
,
1266 PACKET_StaticTracepoints
,
1267 PACKET_InstallInTrace
,
1270 PACKET_TracepointSource
,
1273 PACKET_QDisableRandomization
,
1277 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1280 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1281 struct cmd_list_element
*c
)
1283 struct packet_config
*packet
;
1285 for (packet
= remote_protocol_packets
;
1286 packet
< &remote_protocol_packets
[PACKET_MAX
];
1289 if (&packet
->detect
== c
->var
)
1291 update_packet_config (packet
);
1295 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1300 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1301 struct cmd_list_element
*c
,
1304 struct packet_config
*packet
;
1306 for (packet
= remote_protocol_packets
;
1307 packet
< &remote_protocol_packets
[PACKET_MAX
];
1310 if (&packet
->detect
== c
->var
)
1312 show_packet_config_cmd (packet
);
1316 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1320 /* Should we try one of the 'Z' requests? */
1324 Z_PACKET_SOFTWARE_BP
,
1325 Z_PACKET_HARDWARE_BP
,
1332 /* For compatibility with older distributions. Provide a ``set remote
1333 Z-packet ...'' command that updates all the Z packet types. */
1335 static enum auto_boolean remote_Z_packet_detect
;
1338 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1339 struct cmd_list_element
*c
)
1343 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1345 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1346 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1351 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1352 struct cmd_list_element
*c
,
1357 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1359 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1363 /* Should we try the 'ThreadInfo' query packet?
1365 This variable (NOT available to the user: auto-detect only!)
1366 determines whether GDB will use the new, simpler "ThreadInfo"
1367 query or the older, more complex syntax for thread queries.
1368 This is an auto-detect variable (set to true at each connect,
1369 and set to false when the target fails to recognize it). */
1371 static int use_threadinfo_query
;
1372 static int use_threadextra_query
;
1374 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1375 static struct async_signal_handler
*sigint_remote_twice_token
;
1376 static struct async_signal_handler
*sigint_remote_token
;
1379 /* Asynchronous signal handle registered as event loop source for
1380 when we have pending events ready to be passed to the core. */
1382 static struct async_event_handler
*remote_async_inferior_event_token
;
1384 /* Asynchronous signal handle registered as event loop source for when
1385 the remote sent us a %Stop notification. The registered callback
1386 will do a vStopped sequence to pull the rest of the events out of
1387 the remote side into our event queue. */
1389 static struct async_event_handler
*remote_async_get_pending_events_token
;
1392 static ptid_t magic_null_ptid
;
1393 static ptid_t not_sent_ptid
;
1394 static ptid_t any_thread_ptid
;
1396 /* These are the threads which we last sent to the remote system. The
1397 TID member will be -1 for all or -2 for not sent yet. */
1399 static ptid_t general_thread
;
1400 static ptid_t continue_thread
;
1402 /* This the traceframe which we last selected on the remote system.
1403 It will be -1 if no traceframe is selected. */
1404 static int remote_traceframe_number
= -1;
1406 /* Find out if the stub attached to PID (and hence GDB should offer to
1407 detach instead of killing it when bailing out). */
1410 remote_query_attached (int pid
)
1412 struct remote_state
*rs
= get_remote_state ();
1414 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1417 if (remote_multi_process_p (rs
))
1418 sprintf (rs
->buf
, "qAttached:%x", pid
);
1420 sprintf (rs
->buf
, "qAttached");
1423 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1425 switch (packet_ok (rs
->buf
,
1426 &remote_protocol_packets
[PACKET_qAttached
]))
1429 if (strcmp (rs
->buf
, "1") == 0)
1433 warning (_("Remote failure reply: %s"), rs
->buf
);
1435 case PACKET_UNKNOWN
:
1442 /* Add PID to GDB's inferior table. Since we can be connected to a
1443 remote system before before knowing about any inferior, mark the
1444 target with execution when we find the first inferior. If ATTACHED
1445 is 1, then we had just attached to this inferior. If it is 0, then
1446 we just created this inferior. If it is -1, then try querying the
1447 remote stub to find out if it had attached to the inferior or
1450 static struct inferior
*
1451 remote_add_inferior (int pid
, int attached
)
1453 struct inferior
*inf
;
1455 /* Check whether this process we're learning about is to be
1456 considered attached, or if is to be considered to have been
1457 spawned by the stub. */
1459 attached
= remote_query_attached (pid
);
1461 if (gdbarch_has_global_solist (target_gdbarch
))
1463 /* If the target shares code across all inferiors, then every
1464 attach adds a new inferior. */
1465 inf
= add_inferior (pid
);
1467 /* ... and every inferior is bound to the same program space.
1468 However, each inferior may still have its own address
1470 inf
->aspace
= maybe_new_address_space ();
1471 inf
->pspace
= current_program_space
;
1475 /* In the traditional debugging scenario, there's a 1-1 match
1476 between program/address spaces. We simply bind the inferior
1477 to the program space's address space. */
1478 inf
= current_inferior ();
1479 inferior_appeared (inf
, pid
);
1482 inf
->attach_flag
= attached
;
1487 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1488 according to RUNNING. */
1491 remote_add_thread (ptid_t ptid
, int running
)
1495 set_executing (ptid
, running
);
1496 set_running (ptid
, running
);
1499 /* Come here when we learn about a thread id from the remote target.
1500 It may be the first time we hear about such thread, so take the
1501 opportunity to add it to GDB's thread list. In case this is the
1502 first time we're noticing its corresponding inferior, add it to
1503 GDB's inferior list as well. */
1506 remote_notice_new_inferior (ptid_t currthread
, int running
)
1508 /* If this is a new thread, add it to GDB's thread list.
1509 If we leave it up to WFI to do this, bad things will happen. */
1511 if (in_thread_list (currthread
) && is_exited (currthread
))
1513 /* We're seeing an event on a thread id we knew had exited.
1514 This has to be a new thread reusing the old id. Add it. */
1515 remote_add_thread (currthread
, running
);
1519 if (!in_thread_list (currthread
))
1521 struct inferior
*inf
= NULL
;
1522 int pid
= ptid_get_pid (currthread
);
1524 if (ptid_is_pid (inferior_ptid
)
1525 && pid
== ptid_get_pid (inferior_ptid
))
1527 /* inferior_ptid has no thread member yet. This can happen
1528 with the vAttach -> remote_wait,"TAAthread:" path if the
1529 stub doesn't support qC. This is the first stop reported
1530 after an attach, so this is the main thread. Update the
1531 ptid in the thread list. */
1532 if (in_thread_list (pid_to_ptid (pid
)))
1533 thread_change_ptid (inferior_ptid
, currthread
);
1536 remote_add_thread (currthread
, running
);
1537 inferior_ptid
= currthread
;
1542 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1544 /* inferior_ptid is not set yet. This can happen with the
1545 vRun -> remote_wait,"TAAthread:" path if the stub
1546 doesn't support qC. This is the first stop reported
1547 after an attach, so this is the main thread. Update the
1548 ptid in the thread list. */
1549 thread_change_ptid (inferior_ptid
, currthread
);
1553 /* When connecting to a target remote, or to a target
1554 extended-remote which already was debugging an inferior, we
1555 may not know about it yet. Add it before adding its child
1556 thread, so notifications are emitted in a sensible order. */
1557 if (!in_inferior_list (ptid_get_pid (currthread
)))
1558 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1560 /* This is really a new thread. Add it. */
1561 remote_add_thread (currthread
, running
);
1563 /* If we found a new inferior, let the common code do whatever
1564 it needs to with it (e.g., read shared libraries, insert
1567 notice_new_inferior (currthread
, running
, 0);
1571 /* Return the private thread data, creating it if necessary. */
1573 struct private_thread_info
*
1574 demand_private_info (ptid_t ptid
)
1576 struct thread_info
*info
= find_thread_ptid (ptid
);
1582 info
->private = xmalloc (sizeof (*(info
->private)));
1583 info
->private_dtor
= free_private_thread_info
;
1584 info
->private->core
= -1;
1585 info
->private->extra
= 0;
1588 return info
->private;
1591 /* Call this function as a result of
1592 1) A halt indication (T packet) containing a thread id
1593 2) A direct query of currthread
1594 3) Successful execution of set thread */
1597 record_currthread (ptid_t currthread
)
1599 general_thread
= currthread
;
1602 static char *last_pass_packet
;
1604 /* If 'QPassSignals' is supported, tell the remote stub what signals
1605 it can simply pass through to the inferior without reporting. */
1608 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1610 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1612 char *pass_packet
, *p
;
1615 gdb_assert (numsigs
< 256);
1616 for (i
= 0; i
< numsigs
; i
++)
1618 if (pass_signals
[i
])
1621 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1622 strcpy (pass_packet
, "QPassSignals:");
1623 p
= pass_packet
+ strlen (pass_packet
);
1624 for (i
= 0; i
< numsigs
; i
++)
1626 if (pass_signals
[i
])
1629 *p
++ = tohex (i
>> 4);
1630 *p
++ = tohex (i
& 15);
1639 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1641 struct remote_state
*rs
= get_remote_state ();
1642 char *buf
= rs
->buf
;
1644 putpkt (pass_packet
);
1645 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1646 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1647 if (last_pass_packet
)
1648 xfree (last_pass_packet
);
1649 last_pass_packet
= pass_packet
;
1652 xfree (pass_packet
);
1656 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1657 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1658 thread. If GEN is set, set the general thread, if not, then set
1659 the step/continue thread. */
1661 set_thread (struct ptid ptid
, int gen
)
1663 struct remote_state
*rs
= get_remote_state ();
1664 ptid_t state
= gen
? general_thread
: continue_thread
;
1665 char *buf
= rs
->buf
;
1666 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1668 if (ptid_equal (state
, ptid
))
1672 *buf
++ = gen
? 'g' : 'c';
1673 if (ptid_equal (ptid
, magic_null_ptid
))
1674 xsnprintf (buf
, endbuf
- buf
, "0");
1675 else if (ptid_equal (ptid
, any_thread_ptid
))
1676 xsnprintf (buf
, endbuf
- buf
, "0");
1677 else if (ptid_equal (ptid
, minus_one_ptid
))
1678 xsnprintf (buf
, endbuf
- buf
, "-1");
1680 write_ptid (buf
, endbuf
, ptid
);
1682 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1684 general_thread
= ptid
;
1686 continue_thread
= ptid
;
1690 set_general_thread (struct ptid ptid
)
1692 set_thread (ptid
, 1);
1696 set_continue_thread (struct ptid ptid
)
1698 set_thread (ptid
, 0);
1701 /* Change the remote current process. Which thread within the process
1702 ends up selected isn't important, as long as it is the same process
1703 as what INFERIOR_PTID points to.
1705 This comes from that fact that there is no explicit notion of
1706 "selected process" in the protocol. The selected process for
1707 general operations is the process the selected general thread
1711 set_general_process (void)
1713 struct remote_state
*rs
= get_remote_state ();
1715 /* If the remote can't handle multiple processes, don't bother. */
1716 if (!remote_multi_process_p (rs
))
1719 /* We only need to change the remote current thread if it's pointing
1720 at some other process. */
1721 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1722 set_general_thread (inferior_ptid
);
1726 /* Return nonzero if the thread PTID is still alive on the remote
1730 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1732 struct remote_state
*rs
= get_remote_state ();
1735 if (ptid_equal (ptid
, magic_null_ptid
))
1736 /* The main thread is always alive. */
1739 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1740 /* The main thread is always alive. This can happen after a
1741 vAttach, if the remote side doesn't support
1746 endp
= rs
->buf
+ get_remote_packet_size ();
1749 write_ptid (p
, endp
, ptid
);
1752 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1753 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1756 /* About these extended threadlist and threadinfo packets. They are
1757 variable length packets but, the fields within them are often fixed
1758 length. They are redundent enough to send over UDP as is the
1759 remote protocol in general. There is a matching unit test module
1762 #define OPAQUETHREADBYTES 8
1764 /* a 64 bit opaque identifier */
1765 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1767 /* WARNING: This threadref data structure comes from the remote O.S.,
1768 libstub protocol encoding, and remote.c. It is not particularly
1771 /* Right now, the internal structure is int. We want it to be bigger.
1772 Plan to fix this. */
1774 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1776 /* gdb_ext_thread_info is an internal GDB data structure which is
1777 equivalent to the reply of the remote threadinfo packet. */
1779 struct gdb_ext_thread_info
1781 threadref threadid
; /* External form of thread reference. */
1782 int active
; /* Has state interesting to GDB?
1784 char display
[256]; /* Brief state display, name,
1785 blocked/suspended. */
1786 char shortname
[32]; /* To be used to name threads. */
1787 char more_display
[256]; /* Long info, statistics, queue depth,
1791 /* The volume of remote transfers can be limited by submitting
1792 a mask containing bits specifying the desired information.
1793 Use a union of these values as the 'selection' parameter to
1794 get_thread_info. FIXME: Make these TAG names more thread specific. */
1796 #define TAG_THREADID 1
1797 #define TAG_EXISTS 2
1798 #define TAG_DISPLAY 4
1799 #define TAG_THREADNAME 8
1800 #define TAG_MOREDISPLAY 16
1802 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1804 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1806 static char *unpack_nibble (char *buf
, int *val
);
1808 static char *pack_nibble (char *buf
, int nibble
);
1810 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1812 static char *unpack_byte (char *buf
, int *value
);
1814 static char *pack_int (char *buf
, int value
);
1816 static char *unpack_int (char *buf
, int *value
);
1818 static char *unpack_string (char *src
, char *dest
, int length
);
1820 static char *pack_threadid (char *pkt
, threadref
*id
);
1822 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1824 void int_to_threadref (threadref
*id
, int value
);
1826 static int threadref_to_int (threadref
*ref
);
1828 static void copy_threadref (threadref
*dest
, threadref
*src
);
1830 static int threadmatch (threadref
*dest
, threadref
*src
);
1832 static char *pack_threadinfo_request (char *pkt
, int mode
,
1835 static int remote_unpack_thread_info_response (char *pkt
,
1836 threadref
*expectedref
,
1837 struct gdb_ext_thread_info
1841 static int remote_get_threadinfo (threadref
*threadid
,
1842 int fieldset
, /*TAG mask */
1843 struct gdb_ext_thread_info
*info
);
1845 static char *pack_threadlist_request (char *pkt
, int startflag
,
1847 threadref
*nextthread
);
1849 static int parse_threadlist_response (char *pkt
,
1851 threadref
*original_echo
,
1852 threadref
*resultlist
,
1855 static int remote_get_threadlist (int startflag
,
1856 threadref
*nextthread
,
1860 threadref
*threadlist
);
1862 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1864 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1865 void *context
, int looplimit
);
1867 static int remote_newthread_step (threadref
*ref
, void *context
);
1870 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1871 buffer we're allowed to write to. Returns
1872 BUF+CHARACTERS_WRITTEN. */
1875 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1878 struct remote_state
*rs
= get_remote_state ();
1880 if (remote_multi_process_p (rs
))
1882 pid
= ptid_get_pid (ptid
);
1884 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1886 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1888 tid
= ptid_get_tid (ptid
);
1890 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1892 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1897 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1898 passed the last parsed char. Returns null_ptid on error. */
1901 read_ptid (char *buf
, char **obuf
)
1905 ULONGEST pid
= 0, tid
= 0;
1909 /* Multi-process ptid. */
1910 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1912 error (_("invalid remote ptid: %s"), p
);
1915 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1918 return ptid_build (pid
, 0, tid
);
1921 /* No multi-process. Just a tid. */
1922 pp
= unpack_varlen_hex (p
, &tid
);
1924 /* Since the stub is not sending a process id, then default to
1925 what's in inferior_ptid, unless it's null at this point. If so,
1926 then since there's no way to know the pid of the reported
1927 threads, use the magic number. */
1928 if (ptid_equal (inferior_ptid
, null_ptid
))
1929 pid
= ptid_get_pid (magic_null_ptid
);
1931 pid
= ptid_get_pid (inferior_ptid
);
1935 return ptid_build (pid
, 0, tid
);
1938 /* Encode 64 bits in 16 chars of hex. */
1940 static const char hexchars
[] = "0123456789abcdef";
1943 ishex (int ch
, int *val
)
1945 if ((ch
>= 'a') && (ch
<= 'f'))
1947 *val
= ch
- 'a' + 10;
1950 if ((ch
>= 'A') && (ch
<= 'F'))
1952 *val
= ch
- 'A' + 10;
1955 if ((ch
>= '0') && (ch
<= '9'))
1966 if (ch
>= 'a' && ch
<= 'f')
1967 return ch
- 'a' + 10;
1968 if (ch
>= '0' && ch
<= '9')
1970 if (ch
>= 'A' && ch
<= 'F')
1971 return ch
- 'A' + 10;
1976 stub_unpack_int (char *buff
, int fieldlength
)
1983 nibble
= stubhex (*buff
++);
1987 retval
= retval
<< 4;
1993 unpack_varlen_hex (char *buff
, /* packet to parse */
1997 ULONGEST retval
= 0;
1999 while (ishex (*buff
, &nibble
))
2002 retval
= retval
<< 4;
2003 retval
|= nibble
& 0x0f;
2010 unpack_nibble (char *buf
, int *val
)
2012 *val
= fromhex (*buf
++);
2017 pack_nibble (char *buf
, int nibble
)
2019 *buf
++ = hexchars
[(nibble
& 0x0f)];
2024 pack_hex_byte (char *pkt
, int byte
)
2026 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2027 *pkt
++ = hexchars
[(byte
& 0xf)];
2032 unpack_byte (char *buf
, int *value
)
2034 *value
= stub_unpack_int (buf
, 2);
2039 pack_int (char *buf
, int value
)
2041 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2042 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2043 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2044 buf
= pack_hex_byte (buf
, (value
& 0xff));
2049 unpack_int (char *buf
, int *value
)
2051 *value
= stub_unpack_int (buf
, 8);
2055 #if 0 /* Currently unused, uncomment when needed. */
2056 static char *pack_string (char *pkt
, char *string
);
2059 pack_string (char *pkt
, char *string
)
2064 len
= strlen (string
);
2066 len
= 200; /* Bigger than most GDB packets, junk??? */
2067 pkt
= pack_hex_byte (pkt
, len
);
2071 if ((ch
== '\0') || (ch
== '#'))
2072 ch
= '*'; /* Protect encapsulation. */
2077 #endif /* 0 (unused) */
2080 unpack_string (char *src
, char *dest
, int length
)
2089 pack_threadid (char *pkt
, threadref
*id
)
2092 unsigned char *altid
;
2094 altid
= (unsigned char *) id
;
2095 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2097 pkt
= pack_hex_byte (pkt
, *altid
++);
2103 unpack_threadid (char *inbuf
, threadref
*id
)
2106 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2109 altref
= (char *) id
;
2111 while (inbuf
< limit
)
2113 x
= stubhex (*inbuf
++);
2114 y
= stubhex (*inbuf
++);
2115 *altref
++ = (x
<< 4) | y
;
2120 /* Externally, threadrefs are 64 bits but internally, they are still
2121 ints. This is due to a mismatch of specifications. We would like
2122 to use 64bit thread references internally. This is an adapter
2126 int_to_threadref (threadref
*id
, int value
)
2128 unsigned char *scan
;
2130 scan
= (unsigned char *) id
;
2136 *scan
++ = (value
>> 24) & 0xff;
2137 *scan
++ = (value
>> 16) & 0xff;
2138 *scan
++ = (value
>> 8) & 0xff;
2139 *scan
++ = (value
& 0xff);
2143 threadref_to_int (threadref
*ref
)
2146 unsigned char *scan
;
2152 value
= (value
<< 8) | ((*scan
++) & 0xff);
2157 copy_threadref (threadref
*dest
, threadref
*src
)
2160 unsigned char *csrc
, *cdest
;
2162 csrc
= (unsigned char *) src
;
2163 cdest
= (unsigned char *) dest
;
2170 threadmatch (threadref
*dest
, threadref
*src
)
2172 /* Things are broken right now, so just assume we got a match. */
2174 unsigned char *srcp
, *destp
;
2176 srcp
= (char *) src
;
2177 destp
= (char *) dest
;
2181 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2188 threadid:1, # always request threadid
2195 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2198 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2200 *pkt
++ = 'q'; /* Info Query */
2201 *pkt
++ = 'P'; /* process or thread info */
2202 pkt
= pack_int (pkt
, mode
); /* mode */
2203 pkt
= pack_threadid (pkt
, id
); /* threadid */
2204 *pkt
= '\0'; /* terminate */
2208 /* These values tag the fields in a thread info response packet. */
2209 /* Tagging the fields allows us to request specific fields and to
2210 add more fields as time goes by. */
2212 #define TAG_THREADID 1 /* Echo the thread identifier. */
2213 #define TAG_EXISTS 2 /* Is this process defined enough to
2214 fetch registers and its stack? */
2215 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2216 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2217 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2221 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2222 struct gdb_ext_thread_info
*info
)
2224 struct remote_state
*rs
= get_remote_state ();
2228 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2231 /* info->threadid = 0; FIXME: implement zero_threadref. */
2233 info
->display
[0] = '\0';
2234 info
->shortname
[0] = '\0';
2235 info
->more_display
[0] = '\0';
2237 /* Assume the characters indicating the packet type have been
2239 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2240 pkt
= unpack_threadid (pkt
, &ref
);
2243 warning (_("Incomplete response to threadinfo request."));
2244 if (!threadmatch (&ref
, expectedref
))
2245 { /* This is an answer to a different request. */
2246 warning (_("ERROR RMT Thread info mismatch."));
2249 copy_threadref (&info
->threadid
, &ref
);
2251 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2253 /* Packets are terminated with nulls. */
2254 while ((pkt
< limit
) && mask
&& *pkt
)
2256 pkt
= unpack_int (pkt
, &tag
); /* tag */
2257 pkt
= unpack_byte (pkt
, &length
); /* length */
2258 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2260 warning (_("ERROR RMT: threadinfo tag mismatch."));
2264 if (tag
== TAG_THREADID
)
2268 warning (_("ERROR RMT: length of threadid is not 16."));
2272 pkt
= unpack_threadid (pkt
, &ref
);
2273 mask
= mask
& ~TAG_THREADID
;
2276 if (tag
== TAG_EXISTS
)
2278 info
->active
= stub_unpack_int (pkt
, length
);
2280 mask
= mask
& ~(TAG_EXISTS
);
2283 warning (_("ERROR RMT: 'exists' length too long."));
2289 if (tag
== TAG_THREADNAME
)
2291 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2292 mask
= mask
& ~TAG_THREADNAME
;
2295 if (tag
== TAG_DISPLAY
)
2297 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2298 mask
= mask
& ~TAG_DISPLAY
;
2301 if (tag
== TAG_MOREDISPLAY
)
2303 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2304 mask
= mask
& ~TAG_MOREDISPLAY
;
2307 warning (_("ERROR RMT: unknown thread info tag."));
2308 break; /* Not a tag we know about. */
2314 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2315 struct gdb_ext_thread_info
*info
)
2317 struct remote_state
*rs
= get_remote_state ();
2320 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2322 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2324 if (rs
->buf
[0] == '\0')
2327 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2332 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2335 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2336 threadref
*nextthread
)
2338 *pkt
++ = 'q'; /* info query packet */
2339 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2340 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2341 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2342 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2347 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2350 parse_threadlist_response (char *pkt
, int result_limit
,
2351 threadref
*original_echo
, threadref
*resultlist
,
2354 struct remote_state
*rs
= get_remote_state ();
2356 int count
, resultcount
, done
;
2359 /* Assume the 'q' and 'M chars have been stripped. */
2360 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2361 /* done parse past here */
2362 pkt
= unpack_byte (pkt
, &count
); /* count field */
2363 pkt
= unpack_nibble (pkt
, &done
);
2364 /* The first threadid is the argument threadid. */
2365 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2366 while ((count
-- > 0) && (pkt
< limit
))
2368 pkt
= unpack_threadid (pkt
, resultlist
++);
2369 if (resultcount
++ >= result_limit
)
2378 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2379 int *done
, int *result_count
, threadref
*threadlist
)
2381 struct remote_state
*rs
= get_remote_state ();
2382 static threadref echo_nextthread
;
2385 /* Trancate result limit to be smaller than the packet size. */
2386 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2387 >= get_remote_packet_size ())
2388 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2390 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2392 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2394 if (*rs
->buf
== '\0')
2398 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2401 if (!threadmatch (&echo_nextthread
, nextthread
))
2403 /* FIXME: This is a good reason to drop the packet. */
2404 /* Possably, there is a duplicate response. */
2406 retransmit immediatly - race conditions
2407 retransmit after timeout - yes
2409 wait for packet, then exit
2411 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2412 return 0; /* I choose simply exiting. */
2414 if (*result_count
<= 0)
2418 warning (_("RMT ERROR : failed to get remote thread list."));
2421 return result
; /* break; */
2423 if (*result_count
> result_limit
)
2426 warning (_("RMT ERROR: threadlist response longer than requested."));
2432 /* This is the interface between remote and threads, remotes upper
2435 /* remote_find_new_threads retrieves the thread list and for each
2436 thread in the list, looks up the thread in GDB's internal list,
2437 adding the thread if it does not already exist. This involves
2438 getting partial thread lists from the remote target so, polling the
2439 quit_flag is required. */
2442 /* About this many threadisds fit in a packet. */
2444 #define MAXTHREADLISTRESULTS 32
2447 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2450 int done
, i
, result_count
;
2454 static threadref nextthread
;
2455 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2460 if (loopcount
++ > looplimit
)
2463 warning (_("Remote fetch threadlist -infinite loop-."));
2466 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2467 &done
, &result_count
, resultthreadlist
))
2472 /* Clear for later iterations. */
2474 /* Setup to resume next batch of thread references, set nextthread. */
2475 if (result_count
>= 1)
2476 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2478 while (result_count
--)
2479 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2486 remote_newthread_step (threadref
*ref
, void *context
)
2488 int pid
= ptid_get_pid (inferior_ptid
);
2489 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2491 if (!in_thread_list (ptid
))
2493 return 1; /* continue iterator */
2496 #define CRAZY_MAX_THREADS 1000
2499 remote_current_thread (ptid_t oldpid
)
2501 struct remote_state
*rs
= get_remote_state ();
2504 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2505 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2506 return read_ptid (&rs
->buf
[2], NULL
);
2511 /* Find new threads for info threads command.
2512 * Original version, using John Metzler's thread protocol.
2516 remote_find_new_threads (void)
2518 remote_threadlist_iterator (remote_newthread_step
, 0,
2522 #if defined(HAVE_LIBEXPAT)
2524 typedef struct thread_item
2530 DEF_VEC_O(thread_item_t
);
2532 struct threads_parsing_context
2534 VEC (thread_item_t
) *items
;
2538 start_thread (struct gdb_xml_parser
*parser
,
2539 const struct gdb_xml_element
*element
,
2540 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2542 struct threads_parsing_context
*data
= user_data
;
2544 struct thread_item item
;
2546 struct gdb_xml_value
*attr
;
2548 id
= xml_find_attribute (attributes
, "id")->value
;
2549 item
.ptid
= read_ptid (id
, NULL
);
2551 attr
= xml_find_attribute (attributes
, "core");
2553 item
.core
= *(ULONGEST
*) attr
->value
;
2559 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2563 end_thread (struct gdb_xml_parser
*parser
,
2564 const struct gdb_xml_element
*element
,
2565 void *user_data
, const char *body_text
)
2567 struct threads_parsing_context
*data
= user_data
;
2569 if (body_text
&& *body_text
)
2570 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2573 const struct gdb_xml_attribute thread_attributes
[] = {
2574 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2575 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2576 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2579 const struct gdb_xml_element thread_children
[] = {
2580 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2583 const struct gdb_xml_element threads_children
[] = {
2584 { "thread", thread_attributes
, thread_children
,
2585 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2586 start_thread
, end_thread
},
2587 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2590 const struct gdb_xml_element threads_elements
[] = {
2591 { "threads", NULL
, threads_children
,
2592 GDB_XML_EF_NONE
, NULL
, NULL
},
2593 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2596 /* Discard the contents of the constructed thread info context. */
2599 clear_threads_parsing_context (void *p
)
2601 struct threads_parsing_context
*context
= p
;
2603 struct thread_item
*item
;
2605 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2606 xfree (item
->extra
);
2608 VEC_free (thread_item_t
, context
->items
);
2614 * Find all threads for info threads command.
2615 * Uses new thread protocol contributed by Cisco.
2616 * Falls back and attempts to use the older method (above)
2617 * if the target doesn't respond to the new method.
2621 remote_threads_info (struct target_ops
*ops
)
2623 struct remote_state
*rs
= get_remote_state ();
2627 if (remote_desc
== 0) /* paranoia */
2628 error (_("Command can only be used when connected to the remote target."));
2630 #if defined(HAVE_LIBEXPAT)
2631 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2633 char *xml
= target_read_stralloc (¤t_target
,
2634 TARGET_OBJECT_THREADS
, NULL
);
2636 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2640 struct threads_parsing_context context
;
2642 context
.items
= NULL
;
2643 make_cleanup (clear_threads_parsing_context
, &context
);
2645 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2646 threads_elements
, xml
, &context
) == 0)
2649 struct thread_item
*item
;
2652 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2655 if (!ptid_equal (item
->ptid
, null_ptid
))
2657 struct private_thread_info
*info
;
2658 /* In non-stop mode, we assume new found threads
2659 are running until proven otherwise with a
2660 stop reply. In all-stop, we can only get
2661 here if all threads are stopped. */
2662 int running
= non_stop
? 1 : 0;
2664 remote_notice_new_inferior (item
->ptid
, running
);
2666 info
= demand_private_info (item
->ptid
);
2667 info
->core
= item
->core
;
2668 info
->extra
= item
->extra
;
2675 do_cleanups (back_to
);
2680 if (use_threadinfo_query
)
2682 putpkt ("qfThreadInfo");
2683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2685 if (bufp
[0] != '\0') /* q packet recognized */
2687 while (*bufp
++ == 'm') /* reply contains one or more TID */
2691 new_thread
= read_ptid (bufp
, &bufp
);
2692 if (!ptid_equal (new_thread
, null_ptid
))
2694 /* In non-stop mode, we assume new found threads
2695 are running until proven otherwise with a
2696 stop reply. In all-stop, we can only get
2697 here if all threads are stopped. */
2698 int running
= non_stop
? 1 : 0;
2700 remote_notice_new_inferior (new_thread
, running
);
2703 while (*bufp
++ == ','); /* comma-separated list */
2704 putpkt ("qsThreadInfo");
2705 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2712 /* Only qfThreadInfo is supported in non-stop mode. */
2716 /* Else fall back to old method based on jmetzler protocol. */
2717 use_threadinfo_query
= 0;
2718 remote_find_new_threads ();
2723 * Collect a descriptive string about the given thread.
2724 * The target may say anything it wants to about the thread
2725 * (typically info about its blocked / runnable state, name, etc.).
2726 * This string will appear in the info threads display.
2728 * Optional: targets are not required to implement this function.
2732 remote_threads_extra_info (struct thread_info
*tp
)
2734 struct remote_state
*rs
= get_remote_state ();
2738 struct gdb_ext_thread_info threadinfo
;
2739 static char display_buf
[100]; /* arbitrary... */
2740 int n
= 0; /* position in display_buf */
2742 if (remote_desc
== 0) /* paranoia */
2743 internal_error (__FILE__
, __LINE__
,
2744 _("remote_threads_extra_info"));
2746 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2747 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2748 /* This is the main thread which was added by GDB. The remote
2749 server doesn't know about it. */
2752 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2754 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2756 if (info
&& info
->private)
2757 return info
->private->extra
;
2762 if (use_threadextra_query
)
2765 char *endb
= rs
->buf
+ get_remote_packet_size ();
2767 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2769 write_ptid (b
, endb
, tp
->ptid
);
2772 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2773 if (rs
->buf
[0] != 0)
2775 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2776 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2777 display_buf
[result
] = '\0';
2782 /* If the above query fails, fall back to the old method. */
2783 use_threadextra_query
= 0;
2784 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2785 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2786 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2787 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2788 if (threadinfo
.active
)
2790 if (*threadinfo
.shortname
)
2791 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2792 " Name: %s,", threadinfo
.shortname
);
2793 if (*threadinfo
.display
)
2794 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2795 " State: %s,", threadinfo
.display
);
2796 if (*threadinfo
.more_display
)
2797 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2798 " Priority: %s", threadinfo
.more_display
);
2802 /* For purely cosmetic reasons, clear up trailing commas. */
2803 if (',' == display_buf
[n
-1])
2804 display_buf
[n
-1] = ' ';
2813 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2814 struct static_tracepoint_marker
*marker
)
2816 struct remote_state
*rs
= get_remote_state ();
2819 sprintf (p
, "qTSTMat:");
2821 p
+= hexnumstr (p
, addr
);
2823 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2827 error (_("Remote failure reply: %s"), p
);
2831 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2839 free_current_marker (void *arg
)
2841 struct static_tracepoint_marker
**marker_p
= arg
;
2843 if (*marker_p
!= NULL
)
2845 release_static_tracepoint_marker (*marker_p
);
2852 static VEC(static_tracepoint_marker_p
) *
2853 remote_static_tracepoint_markers_by_strid (const char *strid
)
2855 struct remote_state
*rs
= get_remote_state ();
2856 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2857 struct static_tracepoint_marker
*marker
= NULL
;
2858 struct cleanup
*old_chain
;
2861 /* Ask for a first packet of static tracepoint marker
2864 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2867 error (_("Remote failure reply: %s"), p
);
2869 old_chain
= make_cleanup (free_current_marker
, &marker
);
2874 marker
= XCNEW (struct static_tracepoint_marker
);
2878 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2880 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2882 VEC_safe_push (static_tracepoint_marker_p
,
2888 release_static_tracepoint_marker (marker
);
2889 memset (marker
, 0, sizeof (*marker
));
2892 while (*p
++ == ','); /* comma-separated list */
2893 /* Ask for another packet of static tracepoint definition. */
2895 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2899 do_cleanups (old_chain
);
2904 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2907 remote_get_ada_task_ptid (long lwp
, long thread
)
2909 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2913 /* Restart the remote side; this is an extended protocol operation. */
2916 extended_remote_restart (void)
2918 struct remote_state
*rs
= get_remote_state ();
2920 /* Send the restart command; for reasons I don't understand the
2921 remote side really expects a number after the "R". */
2922 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2925 remote_fileio_reset ();
2928 /* Clean up connection to a remote debugger. */
2931 remote_close (int quitting
)
2933 if (remote_desc
== NULL
)
2934 return; /* already closed */
2936 /* Make sure we leave stdin registered in the event loop, and we
2937 don't leave the async SIGINT signal handler installed. */
2938 remote_terminal_ours ();
2940 serial_close (remote_desc
);
2943 /* We don't have a connection to the remote stub anymore. Get rid
2944 of all the inferiors and their threads we were controlling.
2945 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
2946 will be unable to find the thread corresponding to (pid, 0, 0). */
2947 inferior_ptid
= null_ptid
;
2948 discard_all_inferiors ();
2950 /* We're no longer interested in any of these events. */
2951 discard_pending_stop_replies (-1);
2953 if (remote_async_inferior_event_token
)
2954 delete_async_event_handler (&remote_async_inferior_event_token
);
2955 if (remote_async_get_pending_events_token
)
2956 delete_async_event_handler (&remote_async_get_pending_events_token
);
2959 /* Query the remote side for the text, data and bss offsets. */
2964 struct remote_state
*rs
= get_remote_state ();
2967 int lose
, num_segments
= 0, do_sections
, do_segments
;
2968 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2969 struct section_offsets
*offs
;
2970 struct symfile_segment_data
*data
;
2972 if (symfile_objfile
== NULL
)
2975 putpkt ("qOffsets");
2976 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2979 if (buf
[0] == '\000')
2980 return; /* Return silently. Stub doesn't support
2984 warning (_("Remote failure reply: %s"), buf
);
2988 /* Pick up each field in turn. This used to be done with scanf, but
2989 scanf will make trouble if CORE_ADDR size doesn't match
2990 conversion directives correctly. The following code will work
2991 with any size of CORE_ADDR. */
2992 text_addr
= data_addr
= bss_addr
= 0;
2996 if (strncmp (ptr
, "Text=", 5) == 0)
2999 /* Don't use strtol, could lose on big values. */
3000 while (*ptr
&& *ptr
!= ';')
3001 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3003 if (strncmp (ptr
, ";Data=", 6) == 0)
3006 while (*ptr
&& *ptr
!= ';')
3007 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3012 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3015 while (*ptr
&& *ptr
!= ';')
3016 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3018 if (bss_addr
!= data_addr
)
3019 warning (_("Target reported unsupported offsets: %s"), buf
);
3024 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3027 /* Don't use strtol, could lose on big values. */
3028 while (*ptr
&& *ptr
!= ';')
3029 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3032 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3035 while (*ptr
&& *ptr
!= ';')
3036 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3044 error (_("Malformed response to offset query, %s"), buf
);
3045 else if (*ptr
!= '\0')
3046 warning (_("Target reported unsupported offsets: %s"), buf
);
3048 offs
= ((struct section_offsets
*)
3049 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3050 memcpy (offs
, symfile_objfile
->section_offsets
,
3051 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3053 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3054 do_segments
= (data
!= NULL
);
3055 do_sections
= num_segments
== 0;
3057 if (num_segments
> 0)
3059 segments
[0] = text_addr
;
3060 segments
[1] = data_addr
;
3062 /* If we have two segments, we can still try to relocate everything
3063 by assuming that the .text and .data offsets apply to the whole
3064 text and data segments. Convert the offsets given in the packet
3065 to base addresses for symfile_map_offsets_to_segments. */
3066 else if (data
&& data
->num_segments
== 2)
3068 segments
[0] = data
->segment_bases
[0] + text_addr
;
3069 segments
[1] = data
->segment_bases
[1] + data_addr
;
3072 /* If the object file has only one segment, assume that it is text
3073 rather than data; main programs with no writable data are rare,
3074 but programs with no code are useless. Of course the code might
3075 have ended up in the data segment... to detect that we would need
3076 the permissions here. */
3077 else if (data
&& data
->num_segments
== 1)
3079 segments
[0] = data
->segment_bases
[0] + text_addr
;
3082 /* There's no way to relocate by segment. */
3088 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3089 offs
, num_segments
, segments
);
3091 if (ret
== 0 && !do_sections
)
3092 error (_("Can not handle qOffsets TextSeg "
3093 "response with this symbol file"));
3100 free_symfile_segment_data (data
);
3104 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3106 /* This is a temporary kludge to force data and bss to use the
3107 same offsets because that's what nlmconv does now. The real
3108 solution requires changes to the stub and remote.c that I
3109 don't have time to do right now. */
3111 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3112 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3115 objfile_relocate (symfile_objfile
, offs
);
3118 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3119 threads we know are stopped already. This is used during the
3120 initial remote connection in non-stop mode --- threads that are
3121 reported as already being stopped are left stopped. */
3124 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3126 /* If we have a stop reply for this thread, it must be stopped. */
3127 if (peek_stop_reply (thread
->ptid
))
3128 set_stop_requested (thread
->ptid
, 1);
3133 /* Send interrupt_sequence to remote target. */
3135 send_interrupt_sequence (void)
3137 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3138 serial_write (remote_desc
, "\x03", 1);
3139 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3140 serial_send_break (remote_desc
);
3141 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3143 serial_send_break (remote_desc
);
3144 serial_write (remote_desc
, "g", 1);
3147 internal_error (__FILE__
, __LINE__
,
3148 _("Invalid value for interrupt_sequence_mode: %s."),
3149 interrupt_sequence_mode
);
3153 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3155 struct remote_state
*rs
= get_remote_state ();
3156 struct packet_config
*noack_config
;
3157 char *wait_status
= NULL
;
3159 immediate_quit
++; /* Allow user to interrupt it. */
3161 if (interrupt_on_connect
)
3162 send_interrupt_sequence ();
3164 /* Ack any packet which the remote side has already sent. */
3165 serial_write (remote_desc
, "+", 1);
3167 /* The first packet we send to the target is the optional "supported
3168 packets" request. If the target can answer this, it will tell us
3169 which later probes to skip. */
3170 remote_query_supported ();
3172 /* If the stub wants to get a QAllow, compose one and send it. */
3173 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3174 remote_set_permissions ();
3176 /* Next, we possibly activate noack mode.
3178 If the QStartNoAckMode packet configuration is set to AUTO,
3179 enable noack mode if the stub reported a wish for it with
3182 If set to TRUE, then enable noack mode even if the stub didn't
3183 report it in qSupported. If the stub doesn't reply OK, the
3184 session ends with an error.
3186 If FALSE, then don't activate noack mode, regardless of what the
3187 stub claimed should be the default with qSupported. */
3189 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3191 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3192 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3193 && noack_config
->support
== PACKET_ENABLE
))
3195 putpkt ("QStartNoAckMode");
3196 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3197 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3203 /* Tell the remote that we are using the extended protocol. */
3205 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3208 /* Next, if the target can specify a description, read it. We do
3209 this before anything involving memory or registers. */
3210 target_find_description ();
3212 /* Next, now that we know something about the target, update the
3213 address spaces in the program spaces. */
3214 update_address_spaces ();
3216 /* On OSs where the list of libraries is global to all
3217 processes, we fetch them early. */
3218 if (gdbarch_has_global_solist (target_gdbarch
))
3219 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3223 if (!rs
->non_stop_aware
)
3224 error (_("Non-stop mode requested, but remote "
3225 "does not support non-stop"));
3227 putpkt ("QNonStop:1");
3228 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3230 if (strcmp (rs
->buf
, "OK") != 0)
3231 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3233 /* Find about threads and processes the stub is already
3234 controlling. We default to adding them in the running state.
3235 The '?' query below will then tell us about which threads are
3237 remote_threads_info (target
);
3239 else if (rs
->non_stop_aware
)
3241 /* Don't assume that the stub can operate in all-stop mode.
3242 Request it explicitely. */
3243 putpkt ("QNonStop:0");
3244 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3246 if (strcmp (rs
->buf
, "OK") != 0)
3247 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3250 /* Check whether the target is running now. */
3252 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3256 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3259 error (_("The target is not running (try extended-remote?)"));
3261 /* We're connected, but not running. Drop out before we
3262 call start_remote. */
3267 /* Save the reply for later. */
3268 wait_status
= alloca (strlen (rs
->buf
) + 1);
3269 strcpy (wait_status
, rs
->buf
);
3272 /* Let the stub know that we want it to return the thread. */
3273 set_continue_thread (minus_one_ptid
);
3275 /* Without this, some commands which require an active target
3276 (such as kill) won't work. This variable serves (at least)
3277 double duty as both the pid of the target process (if it has
3278 such), and as a flag indicating that a target is active.
3279 These functions should be split out into seperate variables,
3280 especially since GDB will someday have a notion of debugging
3281 several processes. */
3282 inferior_ptid
= magic_null_ptid
;
3284 /* Now, if we have thread information, update inferior_ptid. */
3285 inferior_ptid
= remote_current_thread (inferior_ptid
);
3287 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3289 /* Always add the main thread. */
3290 add_thread_silent (inferior_ptid
);
3292 /* init_wait_for_inferior should be called before get_offsets in order
3293 to manage `inserted' flag in bp loc in a correct state.
3294 breakpoint_init_inferior, called from init_wait_for_inferior, set
3295 `inserted' flag to 0, while before breakpoint_re_set, called from
3296 start_remote, set `inserted' flag to 1. In the initialization of
3297 inferior, breakpoint_init_inferior should be called first, and then
3298 breakpoint_re_set can be called. If this order is broken, state of
3299 `inserted' flag is wrong, and cause some problems on breakpoint
3301 init_wait_for_inferior ();
3303 get_offsets (); /* Get text, data & bss offsets. */
3305 /* If we could not find a description using qXfer, and we know
3306 how to do it some other way, try again. This is not
3307 supported for non-stop; it could be, but it is tricky if
3308 there are no stopped threads when we connect. */
3309 if (remote_read_description_p (target
)
3310 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3312 target_clear_description ();
3313 target_find_description ();
3316 /* Use the previously fetched status. */
3317 gdb_assert (wait_status
!= NULL
);
3318 strcpy (rs
->buf
, wait_status
);
3319 rs
->cached_wait_status
= 1;
3322 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3326 /* Clear WFI global state. Do this before finding about new
3327 threads and inferiors, and setting the current inferior.
3328 Otherwise we would clear the proceed status of the current
3329 inferior when we want its stop_soon state to be preserved
3330 (see notice_new_inferior). */
3331 init_wait_for_inferior ();
3333 /* In non-stop, we will either get an "OK", meaning that there
3334 are no stopped threads at this time; or, a regular stop
3335 reply. In the latter case, there may be more than one thread
3336 stopped --- we pull them all out using the vStopped
3338 if (strcmp (rs
->buf
, "OK") != 0)
3340 struct stop_reply
*stop_reply
;
3341 struct cleanup
*old_chain
;
3343 stop_reply
= stop_reply_xmalloc ();
3344 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3346 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3347 discard_cleanups (old_chain
);
3349 /* get_pending_stop_replies acks this one, and gets the rest
3351 pending_stop_reply
= stop_reply
;
3352 remote_get_pending_stop_replies ();
3354 /* Make sure that threads that were stopped remain
3356 iterate_over_threads (set_stop_requested_callback
, NULL
);
3359 if (target_can_async_p ())
3360 target_async (inferior_event_handler
, 0);
3362 if (thread_count () == 0)
3365 error (_("The target is not running (try extended-remote?)"));
3367 /* We're connected, but not running. Drop out before we
3368 call start_remote. */
3372 /* Let the stub know that we want it to return the thread. */
3374 /* Force the stub to choose a thread. */
3375 set_general_thread (null_ptid
);
3378 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3379 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3380 error (_("remote didn't report the current thread in non-stop mode"));
3382 get_offsets (); /* Get text, data & bss offsets. */
3384 /* In non-stop mode, any cached wait status will be stored in
3385 the stop reply queue. */
3386 gdb_assert (wait_status
== NULL
);
3388 /* Report all signals during attach/startup. */
3389 remote_pass_signals (0, NULL
);
3392 /* If we connected to a live target, do some additional setup. */
3393 if (target_has_execution
)
3395 if (exec_bfd
) /* No use without an exec file. */
3396 remote_check_symbols (symfile_objfile
);
3399 /* Possibly the target has been engaged in a trace run started
3400 previously; find out where things are at. */
3401 if (remote_get_trace_status (current_trace_status ()) != -1)
3403 struct uploaded_tp
*uploaded_tps
= NULL
;
3404 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3406 if (current_trace_status ()->running
)
3407 printf_filtered (_("Trace is already running on the target.\n"));
3409 /* Get trace state variables first, they may be checked when
3410 parsing uploaded commands. */
3412 remote_upload_trace_state_variables (&uploaded_tsvs
);
3414 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3416 remote_upload_tracepoints (&uploaded_tps
);
3418 merge_uploaded_tracepoints (&uploaded_tps
);
3421 /* If breakpoints are global, insert them now. */
3422 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3423 && breakpoints_always_inserted_mode ())
3424 insert_breakpoints ();
3427 /* Open a connection to a remote debugger.
3428 NAME is the filename used for communication. */
3431 remote_open (char *name
, int from_tty
)
3433 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3436 /* Open a connection to a remote debugger using the extended
3437 remote gdb protocol. NAME is the filename used for communication. */
3440 extended_remote_open (char *name
, int from_tty
)
3442 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3445 /* Generic code for opening a connection to a remote target. */
3448 init_all_packet_configs (void)
3452 for (i
= 0; i
< PACKET_MAX
; i
++)
3453 update_packet_config (&remote_protocol_packets
[i
]);
3456 /* Symbol look-up. */
3459 remote_check_symbols (struct objfile
*objfile
)
3461 struct remote_state
*rs
= get_remote_state ();
3462 char *msg
, *reply
, *tmp
;
3463 struct minimal_symbol
*sym
;
3466 /* The remote side has no concept of inferiors that aren't running
3467 yet, it only knows about running processes. If we're connected
3468 but our current inferior is not running, we should not invite the
3469 remote target to request symbol lookups related to its
3470 (unrelated) current process. */
3471 if (!target_has_execution
)
3474 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3477 /* Make sure the remote is pointing at the right process. Note
3478 there's no way to select "no process". */
3479 set_general_process ();
3481 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3482 because we need both at the same time. */
3483 msg
= alloca (get_remote_packet_size ());
3485 /* Invite target to request symbol lookups. */
3487 putpkt ("qSymbol::");
3488 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3489 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3492 while (strncmp (reply
, "qSymbol:", 8) == 0)
3495 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3497 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3499 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3502 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3503 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3505 /* If this is a function address, return the start of code
3506 instead of any data function descriptor. */
3507 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3511 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3512 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3516 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3521 static struct serial
*
3522 remote_serial_open (char *name
)
3524 static int udp_warning
= 0;
3526 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3527 of in ser-tcp.c, because it is the remote protocol assuming that the
3528 serial connection is reliable and not the serial connection promising
3530 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3532 warning (_("The remote protocol may be unreliable over UDP.\n"
3533 "Some events may be lost, rendering further debugging "
3538 return serial_open (name
);
3541 /* Inform the target of our permission settings. The permission flags
3542 work without this, but if the target knows the settings, it can do
3543 a couple things. First, it can add its own check, to catch cases
3544 that somehow manage to get by the permissions checks in target
3545 methods. Second, if the target is wired to disallow particular
3546 settings (for instance, a system in the field that is not set up to
3547 be able to stop at a breakpoint), it can object to any unavailable
3551 remote_set_permissions (void)
3553 struct remote_state
*rs
= get_remote_state ();
3555 sprintf (rs
->buf
, "QAllow:"
3556 "WriteReg:%x;WriteMem:%x;"
3557 "InsertBreak:%x;InsertTrace:%x;"
3558 "InsertFastTrace:%x;Stop:%x",
3559 may_write_registers
, may_write_memory
,
3560 may_insert_breakpoints
, may_insert_tracepoints
,
3561 may_insert_fast_tracepoints
, may_stop
);
3563 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3565 /* If the target didn't like the packet, warn the user. Do not try
3566 to undo the user's settings, that would just be maddening. */
3567 if (strcmp (rs
->buf
, "OK") != 0)
3568 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3571 /* This type describes each known response to the qSupported
3573 struct protocol_feature
3575 /* The name of this protocol feature. */
3578 /* The default for this protocol feature. */
3579 enum packet_support default_support
;
3581 /* The function to call when this feature is reported, or after
3582 qSupported processing if the feature is not supported.
3583 The first argument points to this structure. The second
3584 argument indicates whether the packet requested support be
3585 enabled, disabled, or probed (or the default, if this function
3586 is being called at the end of processing and this feature was
3587 not reported). The third argument may be NULL; if not NULL, it
3588 is a NUL-terminated string taken from the packet following
3589 this feature's name and an equals sign. */
3590 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3593 /* The corresponding packet for this feature. Only used if
3594 FUNC is remote_supported_packet. */
3599 remote_supported_packet (const struct protocol_feature
*feature
,
3600 enum packet_support support
,
3601 const char *argument
)
3605 warning (_("Remote qSupported response supplied an unexpected value for"
3606 " \"%s\"."), feature
->name
);
3610 if (remote_protocol_packets
[feature
->packet
].support
3611 == PACKET_SUPPORT_UNKNOWN
)
3612 remote_protocol_packets
[feature
->packet
].support
= support
;
3616 remote_packet_size (const struct protocol_feature
*feature
,
3617 enum packet_support support
, const char *value
)
3619 struct remote_state
*rs
= get_remote_state ();
3624 if (support
!= PACKET_ENABLE
)
3627 if (value
== NULL
|| *value
== '\0')
3629 warning (_("Remote target reported \"%s\" without a size."),
3635 packet_size
= strtol (value
, &value_end
, 16);
3636 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3638 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3639 feature
->name
, value
);
3643 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3645 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3646 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3647 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3650 /* Record the new maximum packet size. */
3651 rs
->explicit_packet_size
= packet_size
;
3655 remote_multi_process_feature (const struct protocol_feature
*feature
,
3656 enum packet_support support
, const char *value
)
3658 struct remote_state
*rs
= get_remote_state ();
3660 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3664 remote_non_stop_feature (const struct protocol_feature
*feature
,
3665 enum packet_support support
, const char *value
)
3667 struct remote_state
*rs
= get_remote_state ();
3669 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3673 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3674 enum packet_support support
,
3677 struct remote_state
*rs
= get_remote_state ();
3679 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3683 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3684 enum packet_support support
,
3687 struct remote_state
*rs
= get_remote_state ();
3689 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3693 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3694 enum packet_support support
,
3697 struct remote_state
*rs
= get_remote_state ();
3699 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3703 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3704 enum packet_support support
,
3707 struct remote_state
*rs
= get_remote_state ();
3709 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3713 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3714 enum packet_support support
,
3717 struct remote_state
*rs
= get_remote_state ();
3719 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3723 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3724 enum packet_support support
,
3727 struct remote_state
*rs
= get_remote_state ();
3729 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3733 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3734 enum packet_support support
,
3737 struct remote_state
*rs
= get_remote_state ();
3739 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3742 static struct protocol_feature remote_protocol_features
[] = {
3743 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3744 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3745 PACKET_qXfer_auxv
},
3746 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3747 PACKET_qXfer_features
},
3748 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3749 PACKET_qXfer_libraries
},
3750 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3751 PACKET_qXfer_libraries_svr4
},
3752 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3753 PACKET_qXfer_memory_map
},
3754 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3755 PACKET_qXfer_spu_read
},
3756 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3757 PACKET_qXfer_spu_write
},
3758 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3759 PACKET_qXfer_osdata
},
3760 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3761 PACKET_qXfer_threads
},
3762 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3763 PACKET_qXfer_traceframe_info
},
3764 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3765 PACKET_QPassSignals
},
3766 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3767 PACKET_QStartNoAckMode
},
3768 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3769 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3770 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3771 PACKET_qXfer_siginfo_read
},
3772 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3773 PACKET_qXfer_siginfo_write
},
3774 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3775 PACKET_ConditionalTracepoints
},
3776 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3777 PACKET_FastTracepoints
},
3778 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3779 PACKET_StaticTracepoints
},
3780 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3781 PACKET_InstallInTrace
},
3782 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3784 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3786 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3788 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3789 PACKET_TracepointSource
},
3790 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3792 { "EnableDisableTracepoints", PACKET_DISABLE
,
3793 remote_enable_disable_tracepoint_feature
, -1 },
3794 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3795 PACKET_qXfer_fdpic
},
3796 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3797 PACKET_QDisableRandomization
},
3798 { "tracenz", PACKET_DISABLE
,
3799 remote_string_tracing_feature
, -1 },
3802 static char *remote_support_xml
;
3804 /* Register string appended to "xmlRegisters=" in qSupported query. */
3807 register_remote_support_xml (const char *xml
)
3809 #if defined(HAVE_LIBEXPAT)
3810 if (remote_support_xml
== NULL
)
3811 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3814 char *copy
= xstrdup (remote_support_xml
+ 13);
3815 char *p
= strtok (copy
, ",");
3819 if (strcmp (p
, xml
) == 0)
3826 while ((p
= strtok (NULL
, ",")) != NULL
);
3829 remote_support_xml
= reconcat (remote_support_xml
,
3830 remote_support_xml
, ",", xml
,
3837 remote_query_supported_append (char *msg
, const char *append
)
3840 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3842 return xstrdup (append
);
3846 remote_query_supported (void)
3848 struct remote_state
*rs
= get_remote_state ();
3851 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3853 /* The packet support flags are handled differently for this packet
3854 than for most others. We treat an error, a disabled packet, and
3855 an empty response identically: any features which must be reported
3856 to be used will be automatically disabled. An empty buffer
3857 accomplishes this, since that is also the representation for a list
3858 containing no features. */
3861 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3864 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3867 q
= remote_query_supported_append (q
, "multiprocess+");
3869 if (remote_support_xml
)
3870 q
= remote_query_supported_append (q
, remote_support_xml
);
3872 q
= remote_query_supported_append (q
, "qRelocInsn+");
3874 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3877 do_cleanups (old_chain
);
3879 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3881 /* If an error occured, warn, but do not return - just reset the
3882 buffer to empty and go on to disable features. */
3883 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3886 warning (_("Remote failure reply: %s"), rs
->buf
);
3891 memset (seen
, 0, sizeof (seen
));
3896 enum packet_support is_supported
;
3897 char *p
, *end
, *name_end
, *value
;
3899 /* First separate out this item from the rest of the packet. If
3900 there's another item after this, we overwrite the separator
3901 (terminated strings are much easier to work with). */
3903 end
= strchr (p
, ';');
3906 end
= p
+ strlen (p
);
3916 warning (_("empty item in \"qSupported\" response"));
3921 name_end
= strchr (p
, '=');
3924 /* This is a name=value entry. */
3925 is_supported
= PACKET_ENABLE
;
3926 value
= name_end
+ 1;
3935 is_supported
= PACKET_ENABLE
;
3939 is_supported
= PACKET_DISABLE
;
3943 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3947 warning (_("unrecognized item \"%s\" "
3948 "in \"qSupported\" response"), p
);
3954 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3955 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3957 const struct protocol_feature
*feature
;
3960 feature
= &remote_protocol_features
[i
];
3961 feature
->func (feature
, is_supported
, value
);
3966 /* If we increased the packet size, make sure to increase the global
3967 buffer size also. We delay this until after parsing the entire
3968 qSupported packet, because this is the same buffer we were
3970 if (rs
->buf_size
< rs
->explicit_packet_size
)
3972 rs
->buf_size
= rs
->explicit_packet_size
;
3973 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3976 /* Handle the defaults for unmentioned features. */
3977 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3980 const struct protocol_feature
*feature
;
3982 feature
= &remote_protocol_features
[i
];
3983 feature
->func (feature
, feature
->default_support
, NULL
);
3989 remote_open_1 (char *name
, int from_tty
,
3990 struct target_ops
*target
, int extended_p
)
3992 struct remote_state
*rs
= get_remote_state ();
3995 error (_("To open a remote debug connection, you need to specify what\n"
3996 "serial device is attached to the remote system\n"
3997 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3999 /* See FIXME above. */
4000 if (!target_async_permitted
)
4001 wait_forever_enabled_p
= 1;
4003 /* If we're connected to a running target, target_preopen will kill it.
4004 But if we're connected to a target system with no running process,
4005 then we will still be connected when it returns. Ask this question
4006 first, before target_preopen has a chance to kill anything. */
4007 if (remote_desc
!= NULL
&& !have_inferiors ())
4010 || query (_("Already connected to a remote target. Disconnect? ")))
4013 error (_("Still connected."));
4016 target_preopen (from_tty
);
4018 unpush_target (target
);
4020 /* This time without a query. If we were connected to an
4021 extended-remote target and target_preopen killed the running
4022 process, we may still be connected. If we are starting "target
4023 remote" now, the extended-remote target will not have been
4024 removed by unpush_target. */
4025 if (remote_desc
!= NULL
&& !have_inferiors ())
4028 /* Make sure we send the passed signals list the next time we resume. */
4029 xfree (last_pass_packet
);
4030 last_pass_packet
= NULL
;
4032 remote_fileio_reset ();
4033 reopen_exec_file ();
4036 remote_desc
= remote_serial_open (name
);
4038 perror_with_name (name
);
4040 if (baud_rate
!= -1)
4042 if (serial_setbaudrate (remote_desc
, baud_rate
))
4044 /* The requested speed could not be set. Error out to
4045 top level after closing remote_desc. Take care to
4046 set remote_desc to NULL to avoid closing remote_desc
4048 serial_close (remote_desc
);
4050 perror_with_name (name
);
4054 serial_raw (remote_desc
);
4056 /* If there is something sitting in the buffer we might take it as a
4057 response to a command, which would be bad. */
4058 serial_flush_input (remote_desc
);
4062 puts_filtered ("Remote debugging using ");
4063 puts_filtered (name
);
4064 puts_filtered ("\n");
4066 push_target (target
); /* Switch to using remote target now. */
4068 /* Register extra event sources in the event loop. */
4069 remote_async_inferior_event_token
4070 = create_async_event_handler (remote_async_inferior_event_handler
,
4072 remote_async_get_pending_events_token
4073 = create_async_event_handler (remote_async_get_pending_events_handler
,
4076 /* Reset the target state; these things will be queried either by
4077 remote_query_supported or as they are needed. */
4078 init_all_packet_configs ();
4079 rs
->cached_wait_status
= 0;
4080 rs
->explicit_packet_size
= 0;
4082 rs
->multi_process_aware
= 0;
4083 rs
->extended
= extended_p
;
4084 rs
->non_stop_aware
= 0;
4085 rs
->waiting_for_stop_reply
= 0;
4086 rs
->ctrlc_pending_p
= 0;
4088 general_thread
= not_sent_ptid
;
4089 continue_thread
= not_sent_ptid
;
4090 remote_traceframe_number
= -1;
4092 /* Probe for ability to use "ThreadInfo" query, as required. */
4093 use_threadinfo_query
= 1;
4094 use_threadextra_query
= 1;
4096 if (target_async_permitted
)
4098 /* With this target we start out by owning the terminal. */
4099 remote_async_terminal_ours_p
= 1;
4101 /* FIXME: cagney/1999-09-23: During the initial connection it is
4102 assumed that the target is already ready and able to respond to
4103 requests. Unfortunately remote_start_remote() eventually calls
4104 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4105 around this. Eventually a mechanism that allows
4106 wait_for_inferior() to expect/get timeouts will be
4108 wait_forever_enabled_p
= 0;
4111 /* First delete any symbols previously loaded from shared libraries. */
4112 no_shared_libraries (NULL
, 0);
4115 init_thread_list ();
4117 /* Start the remote connection. If error() or QUIT, discard this
4118 target (we'd otherwise be in an inconsistent state) and then
4119 propogate the error on up the exception chain. This ensures that
4120 the caller doesn't stumble along blindly assuming that the
4121 function succeeded. The CLI doesn't have this problem but other
4122 UI's, such as MI do.
4124 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4125 this function should return an error indication letting the
4126 caller restore the previous state. Unfortunately the command
4127 ``target remote'' is directly wired to this function making that
4128 impossible. On a positive note, the CLI side of this problem has
4129 been fixed - the function set_cmd_context() makes it possible for
4130 all the ``target ....'' commands to share a common callback
4131 function. See cli-dump.c. */
4133 volatile struct gdb_exception ex
;
4135 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4137 remote_start_remote (from_tty
, target
, extended_p
);
4141 /* Pop the partially set up target - unless something else did
4142 already before throwing the exception. */
4143 if (remote_desc
!= NULL
)
4145 if (target_async_permitted
)
4146 wait_forever_enabled_p
= 1;
4147 throw_exception (ex
);
4151 if (target_async_permitted
)
4152 wait_forever_enabled_p
= 1;
4155 /* This takes a program previously attached to and detaches it. After
4156 this is done, GDB can be used to debug some other program. We
4157 better not have left any breakpoints in the target program or it'll
4158 die when it hits one. */
4161 remote_detach_1 (char *args
, int from_tty
, int extended
)
4163 int pid
= ptid_get_pid (inferior_ptid
);
4164 struct remote_state
*rs
= get_remote_state ();
4167 error (_("Argument given to \"detach\" when remotely debugging."));
4169 if (!target_has_execution
)
4170 error (_("No process to detach from."));
4172 /* Tell the remote target to detach. */
4173 if (remote_multi_process_p (rs
))
4174 sprintf (rs
->buf
, "D;%x", pid
);
4176 strcpy (rs
->buf
, "D");
4179 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4181 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4183 else if (rs
->buf
[0] == '\0')
4184 error (_("Remote doesn't know how to detach"));
4186 error (_("Can't detach process."));
4190 if (remote_multi_process_p (rs
))
4191 printf_filtered (_("Detached from remote %s.\n"),
4192 target_pid_to_str (pid_to_ptid (pid
)));
4196 puts_filtered (_("Detached from remote process.\n"));
4198 puts_filtered (_("Ending remote debugging.\n"));
4202 discard_pending_stop_replies (pid
);
4203 target_mourn_inferior ();
4207 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4209 remote_detach_1 (args
, from_tty
, 0);
4213 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4215 remote_detach_1 (args
, from_tty
, 1);
4218 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4221 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4224 error (_("Argument given to \"disconnect\" when remotely debugging."));
4226 /* Make sure we unpush even the extended remote targets; mourn
4227 won't do it. So call remote_mourn_1 directly instead of
4228 target_mourn_inferior. */
4229 remote_mourn_1 (target
);
4232 puts_filtered ("Ending remote debugging.\n");
4235 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4236 be chatty about it. */
4239 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4241 struct remote_state
*rs
= get_remote_state ();
4243 char *wait_status
= NULL
;
4245 pid
= parse_pid_to_attach (args
);
4247 /* Remote PID can be freely equal to getpid, do not check it here the same
4248 way as in other targets. */
4250 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4251 error (_("This target does not support attaching to a process"));
4253 sprintf (rs
->buf
, "vAttach;%x", pid
);
4255 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4257 if (packet_ok (rs
->buf
,
4258 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4261 printf_unfiltered (_("Attached to %s\n"),
4262 target_pid_to_str (pid_to_ptid (pid
)));
4266 /* Save the reply for later. */
4267 wait_status
= alloca (strlen (rs
->buf
) + 1);
4268 strcpy (wait_status
, rs
->buf
);
4270 else if (strcmp (rs
->buf
, "OK") != 0)
4271 error (_("Attaching to %s failed with: %s"),
4272 target_pid_to_str (pid_to_ptid (pid
)),
4275 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4276 error (_("This target does not support attaching to a process"));
4278 error (_("Attaching to %s failed"),
4279 target_pid_to_str (pid_to_ptid (pid
)));
4281 set_current_inferior (remote_add_inferior (pid
, 1));
4283 inferior_ptid
= pid_to_ptid (pid
);
4287 struct thread_info
*thread
;
4289 /* Get list of threads. */
4290 remote_threads_info (target
);
4292 thread
= first_thread_of_process (pid
);
4294 inferior_ptid
= thread
->ptid
;
4296 inferior_ptid
= pid_to_ptid (pid
);
4298 /* Invalidate our notion of the remote current thread. */
4299 record_currthread (minus_one_ptid
);
4303 /* Now, if we have thread information, update inferior_ptid. */
4304 inferior_ptid
= remote_current_thread (inferior_ptid
);
4306 /* Add the main thread to the thread list. */
4307 add_thread_silent (inferior_ptid
);
4310 /* Next, if the target can specify a description, read it. We do
4311 this before anything involving memory or registers. */
4312 target_find_description ();
4316 /* Use the previously fetched status. */
4317 gdb_assert (wait_status
!= NULL
);
4319 if (target_can_async_p ())
4321 struct stop_reply
*stop_reply
;
4322 struct cleanup
*old_chain
;
4324 stop_reply
= stop_reply_xmalloc ();
4325 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4326 remote_parse_stop_reply (wait_status
, stop_reply
);
4327 discard_cleanups (old_chain
);
4328 push_stop_reply (stop_reply
);
4330 target_async (inferior_event_handler
, 0);
4334 gdb_assert (wait_status
!= NULL
);
4335 strcpy (rs
->buf
, wait_status
);
4336 rs
->cached_wait_status
= 1;
4340 gdb_assert (wait_status
== NULL
);
4344 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4346 extended_remote_attach_1 (ops
, args
, from_tty
);
4349 /* Convert hex digit A to a number. */
4354 if (a
>= '0' && a
<= '9')
4356 else if (a
>= 'a' && a
<= 'f')
4357 return a
- 'a' + 10;
4358 else if (a
>= 'A' && a
<= 'F')
4359 return a
- 'A' + 10;
4361 error (_("Reply contains invalid hex digit %d"), a
);
4365 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4369 for (i
= 0; i
< count
; i
++)
4371 if (hex
[0] == 0 || hex
[1] == 0)
4373 /* Hex string is short, or of uneven length.
4374 Return the count that has been converted so far. */
4377 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4383 /* Convert number NIB to a hex digit. */
4391 return 'a' + nib
- 10;
4395 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4399 /* May use a length, or a nul-terminated string as input. */
4401 count
= strlen ((char *) bin
);
4403 for (i
= 0; i
< count
; i
++)
4405 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4406 *hex
++ = tohex (*bin
++ & 0xf);
4412 /* Check for the availability of vCont. This function should also check
4416 remote_vcont_probe (struct remote_state
*rs
)
4420 strcpy (rs
->buf
, "vCont?");
4422 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4425 /* Make sure that the features we assume are supported. */
4426 if (strncmp (buf
, "vCont", 5) == 0)
4429 int support_s
, support_S
, support_c
, support_C
;
4435 rs
->support_vCont_t
= 0;
4436 while (p
&& *p
== ';')
4439 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4441 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4443 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4445 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4447 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4448 rs
->support_vCont_t
= 1;
4450 p
= strchr (p
, ';');
4453 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4454 BUF will make packet_ok disable the packet. */
4455 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4459 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4462 /* Helper function for building "vCont" resumptions. Write a
4463 resumption to P. ENDP points to one-passed-the-end of the buffer
4464 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4465 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4466 resumed thread should be single-stepped and/or signalled. If PTID
4467 equals minus_one_ptid, then all threads are resumed; if PTID
4468 represents a process, then all threads of the process are resumed;
4469 the thread to be stepped and/or signalled is given in the global
4473 append_resumption (char *p
, char *endp
,
4474 ptid_t ptid
, int step
, enum target_signal siggnal
)
4476 struct remote_state
*rs
= get_remote_state ();
4478 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4479 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4481 p
+= xsnprintf (p
, endp
- p
, ";s");
4482 else if (siggnal
!= TARGET_SIGNAL_0
)
4483 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4485 p
+= xsnprintf (p
, endp
- p
, ";c");
4487 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4491 /* All (-1) threads of process. */
4492 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4494 p
+= xsnprintf (p
, endp
- p
, ":");
4495 p
= write_ptid (p
, endp
, nptid
);
4497 else if (!ptid_equal (ptid
, minus_one_ptid
))
4499 p
+= xsnprintf (p
, endp
- p
, ":");
4500 p
= write_ptid (p
, endp
, ptid
);
4506 /* Resume the remote inferior by using a "vCont" packet. The thread
4507 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4508 resumed thread should be single-stepped and/or signalled. If PTID
4509 equals minus_one_ptid, then all threads are resumed; the thread to
4510 be stepped and/or signalled is given in the global INFERIOR_PTID.
4511 This function returns non-zero iff it resumes the inferior.
4513 This function issues a strict subset of all possible vCont commands at the
4517 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4519 struct remote_state
*rs
= get_remote_state ();
4523 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4524 remote_vcont_probe (rs
);
4526 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4530 endp
= rs
->buf
+ get_remote_packet_size ();
4532 /* If we could generate a wider range of packets, we'd have to worry
4533 about overflowing BUF. Should there be a generic
4534 "multi-part-packet" packet? */
4536 p
+= xsnprintf (p
, endp
- p
, "vCont");
4538 if (ptid_equal (ptid
, magic_null_ptid
))
4540 /* MAGIC_NULL_PTID means that we don't have any active threads,
4541 so we don't have any TID numbers the inferior will
4542 understand. Make sure to only send forms that do not specify
4544 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4546 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4548 /* Resume all threads (of all processes, or of a single
4549 process), with preference for INFERIOR_PTID. This assumes
4550 inferior_ptid belongs to the set of all threads we are about
4552 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4554 /* Step inferior_ptid, with or without signal. */
4555 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4558 /* And continue others without a signal. */
4559 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4563 /* Scheduler locking; resume only PTID. */
4564 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4567 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4572 /* In non-stop, the stub replies to vCont with "OK". The stop
4573 reply will be reported asynchronously by means of a `%Stop'
4575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4576 if (strcmp (rs
->buf
, "OK") != 0)
4577 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4583 /* Tell the remote machine to resume. */
4585 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4587 static int last_sent_step
;
4590 remote_resume (struct target_ops
*ops
,
4591 ptid_t ptid
, int step
, enum target_signal siggnal
)
4593 struct remote_state
*rs
= get_remote_state ();
4596 last_sent_signal
= siggnal
;
4597 last_sent_step
= step
;
4599 /* The vCont packet doesn't need to specify threads via Hc. */
4600 /* No reverse support (yet) for vCont. */
4601 if (execution_direction
!= EXEC_REVERSE
)
4602 if (remote_vcont_resume (ptid
, step
, siggnal
))
4605 /* All other supported resume packets do use Hc, so set the continue
4607 if (ptid_equal (ptid
, minus_one_ptid
))
4608 set_continue_thread (any_thread_ptid
);
4610 set_continue_thread (ptid
);
4613 if (execution_direction
== EXEC_REVERSE
)
4615 /* We don't pass signals to the target in reverse exec mode. */
4616 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4617 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4621 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4622 error (_("Remote reverse-step not supported."));
4624 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4625 error (_("Remote reverse-continue not supported."));
4627 strcpy (buf
, step
? "bs" : "bc");
4629 else if (siggnal
!= TARGET_SIGNAL_0
)
4631 buf
[0] = step
? 'S' : 'C';
4632 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4633 buf
[2] = tohex (((int) siggnal
) & 0xf);
4637 strcpy (buf
, step
? "s" : "c");
4642 /* We are about to start executing the inferior, let's register it
4643 with the event loop. NOTE: this is the one place where all the
4644 execution commands end up. We could alternatively do this in each
4645 of the execution commands in infcmd.c. */
4646 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4647 into infcmd.c in order to allow inferior function calls to work
4648 NOT asynchronously. */
4649 if (target_can_async_p ())
4650 target_async (inferior_event_handler
, 0);
4652 /* We've just told the target to resume. The remote server will
4653 wait for the inferior to stop, and then send a stop reply. In
4654 the mean time, we can't start another command/query ourselves
4655 because the stub wouldn't be ready to process it. This applies
4656 only to the base all-stop protocol, however. In non-stop (which
4657 only supports vCont), the stub replies with an "OK", and is
4658 immediate able to process further serial input. */
4660 rs
->waiting_for_stop_reply
= 1;
4664 /* Set up the signal handler for SIGINT, while the target is
4665 executing, ovewriting the 'regular' SIGINT signal handler. */
4667 initialize_sigint_signal_handler (void)
4669 signal (SIGINT
, handle_remote_sigint
);
4672 /* Signal handler for SIGINT, while the target is executing. */
4674 handle_remote_sigint (int sig
)
4676 signal (sig
, handle_remote_sigint_twice
);
4677 mark_async_signal_handler_wrapper (sigint_remote_token
);
4680 /* Signal handler for SIGINT, installed after SIGINT has already been
4681 sent once. It will take effect the second time that the user sends
4684 handle_remote_sigint_twice (int sig
)
4686 signal (sig
, handle_remote_sigint
);
4687 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4690 /* Perform the real interruption of the target execution, in response
4693 async_remote_interrupt (gdb_client_data arg
)
4696 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4698 target_stop (inferior_ptid
);
4701 /* Perform interrupt, if the first attempt did not succeed. Just give
4702 up on the target alltogether. */
4704 async_remote_interrupt_twice (gdb_client_data arg
)
4707 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4712 /* Reinstall the usual SIGINT handlers, after the target has
4715 cleanup_sigint_signal_handler (void *dummy
)
4717 signal (SIGINT
, handle_sigint
);
4720 /* Send ^C to target to halt it. Target will respond, and send us a
4722 static void (*ofunc
) (int);
4724 /* The command line interface's stop routine. This function is installed
4725 as a signal handler for SIGINT. The first time a user requests a
4726 stop, we call remote_stop to send a break or ^C. If there is no
4727 response from the target (it didn't stop when the user requested it),
4728 we ask the user if he'd like to detach from the target. */
4730 remote_interrupt (int signo
)
4732 /* If this doesn't work, try more severe steps. */
4733 signal (signo
, remote_interrupt_twice
);
4735 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4738 /* The user typed ^C twice. */
4741 remote_interrupt_twice (int signo
)
4743 signal (signo
, ofunc
);
4744 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4745 signal (signo
, remote_interrupt
);
4748 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4749 thread, all threads of a remote process, or all threads of all
4753 remote_stop_ns (ptid_t ptid
)
4755 struct remote_state
*rs
= get_remote_state ();
4757 char *endp
= rs
->buf
+ get_remote_packet_size ();
4759 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4760 remote_vcont_probe (rs
);
4762 if (!rs
->support_vCont_t
)
4763 error (_("Remote server does not support stopping threads"));
4765 if (ptid_equal (ptid
, minus_one_ptid
)
4766 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4767 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4772 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4774 if (ptid_is_pid (ptid
))
4775 /* All (-1) threads of process. */
4776 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4779 /* Small optimization: if we already have a stop reply for
4780 this thread, no use in telling the stub we want this
4782 if (peek_stop_reply (ptid
))
4788 write_ptid (p
, endp
, nptid
);
4791 /* In non-stop, we get an immediate OK reply. The stop reply will
4792 come in asynchronously by notification. */
4794 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4795 if (strcmp (rs
->buf
, "OK") != 0)
4796 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4799 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4800 remote target. It is undefined which thread of which process
4801 reports the stop. */
4804 remote_stop_as (ptid_t ptid
)
4806 struct remote_state
*rs
= get_remote_state ();
4808 rs
->ctrlc_pending_p
= 1;
4810 /* If the inferior is stopped already, but the core didn't know
4811 about it yet, just ignore the request. The cached wait status
4812 will be collected in remote_wait. */
4813 if (rs
->cached_wait_status
)
4816 /* Send interrupt_sequence to remote target. */
4817 send_interrupt_sequence ();
4820 /* This is the generic stop called via the target vector. When a target
4821 interrupt is requested, either by the command line or the GUI, we
4822 will eventually end up here. */
4825 remote_stop (ptid_t ptid
)
4828 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4831 remote_stop_ns (ptid
);
4833 remote_stop_as (ptid
);
4836 /* Ask the user what to do when an interrupt is received. */
4839 interrupt_query (void)
4841 target_terminal_ours ();
4843 if (target_can_async_p ())
4845 signal (SIGINT
, handle_sigint
);
4846 deprecated_throw_reason (RETURN_QUIT
);
4850 if (query (_("Interrupted while waiting for the program.\n\
4851 Give up (and stop debugging it)? ")))
4854 deprecated_throw_reason (RETURN_QUIT
);
4858 target_terminal_inferior ();
4861 /* Enable/disable target terminal ownership. Most targets can use
4862 terminal groups to control terminal ownership. Remote targets are
4863 different in that explicit transfer of ownership to/from GDB/target
4867 remote_terminal_inferior (void)
4869 if (!target_async_permitted
)
4870 /* Nothing to do. */
4873 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4874 idempotent. The event-loop GDB talking to an asynchronous target
4875 with a synchronous command calls this function from both
4876 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4877 transfer the terminal to the target when it shouldn't this guard
4879 if (!remote_async_terminal_ours_p
)
4881 delete_file_handler (input_fd
);
4882 remote_async_terminal_ours_p
= 0;
4883 initialize_sigint_signal_handler ();
4884 /* NOTE: At this point we could also register our selves as the
4885 recipient of all input. Any characters typed could then be
4886 passed on down to the target. */
4890 remote_terminal_ours (void)
4892 if (!target_async_permitted
)
4893 /* Nothing to do. */
4896 /* See FIXME in remote_terminal_inferior. */
4897 if (remote_async_terminal_ours_p
)
4899 cleanup_sigint_signal_handler (NULL
);
4900 add_file_handler (input_fd
, stdin_event_handler
, 0);
4901 remote_async_terminal_ours_p
= 1;
4905 remote_console_output (char *msg
)
4909 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4912 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4916 fputs_unfiltered (tb
, gdb_stdtarg
);
4918 gdb_flush (gdb_stdtarg
);
4921 typedef struct cached_reg
4924 gdb_byte data
[MAX_REGISTER_SIZE
];
4927 DEF_VEC_O(cached_reg_t
);
4931 struct stop_reply
*next
;
4935 struct target_waitstatus ws
;
4937 /* Expedited registers. This makes remote debugging a bit more
4938 efficient for those targets that provide critical registers as
4939 part of their normal status mechanism (as another roundtrip to
4940 fetch them is avoided). */
4941 VEC(cached_reg_t
) *regcache
;
4943 int stopped_by_watchpoint_p
;
4944 CORE_ADDR watch_data_address
;
4952 /* The list of already fetched and acknowledged stop events. */
4953 static struct stop_reply
*stop_reply_queue
;
4955 static struct stop_reply
*
4956 stop_reply_xmalloc (void)
4958 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4965 stop_reply_xfree (struct stop_reply
*r
)
4969 VEC_free (cached_reg_t
, r
->regcache
);
4974 /* Discard all pending stop replies of inferior PID. If PID is -1,
4975 discard everything. */
4978 discard_pending_stop_replies (int pid
)
4980 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4982 /* Discard the in-flight notification. */
4983 if (pending_stop_reply
!= NULL
4985 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4987 stop_reply_xfree (pending_stop_reply
);
4988 pending_stop_reply
= NULL
;
4991 /* Discard the stop replies we have already pulled with
4993 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4997 || ptid_get_pid (reply
->ptid
) == pid
)
4999 if (reply
== stop_reply_queue
)
5000 stop_reply_queue
= reply
->next
;
5002 prev
->next
= reply
->next
;
5004 stop_reply_xfree (reply
);
5011 /* Cleanup wrapper. */
5014 do_stop_reply_xfree (void *arg
)
5016 struct stop_reply
*r
= arg
;
5018 stop_reply_xfree (r
);
5021 /* Look for a queued stop reply belonging to PTID. If one is found,
5022 remove it from the queue, and return it. Returns NULL if none is
5023 found. If there are still queued events left to process, tell the
5024 event loop to get back to target_wait soon. */
5026 static struct stop_reply
*
5027 queued_stop_reply (ptid_t ptid
)
5029 struct stop_reply
*it
;
5030 struct stop_reply
**it_link
;
5032 it
= stop_reply_queue
;
5033 it_link
= &stop_reply_queue
;
5036 if (ptid_match (it
->ptid
, ptid
))
5038 *it_link
= it
->next
;
5043 it_link
= &it
->next
;
5047 if (stop_reply_queue
)
5048 /* There's still at least an event left. */
5049 mark_async_event_handler (remote_async_inferior_event_token
);
5054 /* Push a fully parsed stop reply in the stop reply queue. Since we
5055 know that we now have at least one queued event left to pass to the
5056 core side, tell the event loop to get back to target_wait soon. */
5059 push_stop_reply (struct stop_reply
*new_event
)
5061 struct stop_reply
*event
;
5063 if (stop_reply_queue
)
5065 for (event
= stop_reply_queue
;
5066 event
&& event
->next
;
5067 event
= event
->next
)
5070 event
->next
= new_event
;
5073 stop_reply_queue
= new_event
;
5075 mark_async_event_handler (remote_async_inferior_event_token
);
5078 /* Returns true if we have a stop reply for PTID. */
5081 peek_stop_reply (ptid_t ptid
)
5083 struct stop_reply
*it
;
5085 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5086 if (ptid_equal (ptid
, it
->ptid
))
5088 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5095 /* Parse the stop reply in BUF. Either the function succeeds, and the
5096 result is stored in EVENT, or throws an error. */
5099 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5101 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5105 event
->ptid
= null_ptid
;
5106 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5107 event
->ws
.value
.integer
= 0;
5108 event
->solibs_changed
= 0;
5109 event
->replay_event
= 0;
5110 event
->stopped_by_watchpoint_p
= 0;
5111 event
->regcache
= NULL
;
5116 case 'T': /* Status with PC, SP, FP, ... */
5117 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5118 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5120 n... = register number
5121 r... = register contents
5124 p
= &buf
[3]; /* after Txx */
5132 /* If the packet contains a register number, save it in
5133 pnum and set p1 to point to the character following it.
5134 Otherwise p1 points to p. */
5136 /* If this packet is an awatch packet, don't parse the 'a'
5137 as a register number. */
5139 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5140 && strncmp (p
, "core", strlen ("core") != 0))
5142 /* Read the ``P'' register number. */
5143 pnum
= strtol (p
, &p_temp
, 16);
5149 if (p1
== p
) /* No register number present here. */
5151 p1
= strchr (p
, ':');
5153 error (_("Malformed packet(a) (missing colon): %s\n\
5156 if (strncmp (p
, "thread", p1
- p
) == 0)
5157 event
->ptid
= read_ptid (++p1
, &p
);
5158 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5159 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5160 || (strncmp (p
, "awatch", p1
- p
) == 0))
5162 event
->stopped_by_watchpoint_p
= 1;
5163 p
= unpack_varlen_hex (++p1
, &addr
);
5164 event
->watch_data_address
= (CORE_ADDR
) addr
;
5166 else if (strncmp (p
, "library", p1
- p
) == 0)
5170 while (*p_temp
&& *p_temp
!= ';')
5173 event
->solibs_changed
= 1;
5176 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5178 /* NO_HISTORY event.
5179 p1 will indicate "begin" or "end", but
5180 it makes no difference for now, so ignore it. */
5181 event
->replay_event
= 1;
5182 p_temp
= strchr (p1
+ 1, ';');
5186 else if (strncmp (p
, "core", p1
- p
) == 0)
5190 p
= unpack_varlen_hex (++p1
, &c
);
5195 /* Silently skip unknown optional info. */
5196 p_temp
= strchr (p1
+ 1, ';');
5203 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5204 cached_reg_t cached_reg
;
5209 error (_("Malformed packet(b) (missing colon): %s\n\
5215 error (_("Remote sent bad register number %s: %s\n\
5217 hex_string (pnum
), p
, buf
);
5219 cached_reg
.num
= reg
->regnum
;
5221 fieldsize
= hex2bin (p
, cached_reg
.data
,
5222 register_size (target_gdbarch
,
5225 if (fieldsize
< register_size (target_gdbarch
,
5227 warning (_("Remote reply is too short: %s"), buf
);
5229 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5233 error (_("Remote register badly formatted: %s\nhere: %s"),
5238 case 'S': /* Old style status, just signal only. */
5239 if (event
->solibs_changed
)
5240 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5241 else if (event
->replay_event
)
5242 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5245 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5246 event
->ws
.value
.sig
= (enum target_signal
)
5247 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5250 case 'W': /* Target exited. */
5257 /* GDB used to accept only 2 hex chars here. Stubs should
5258 only send more if they detect GDB supports multi-process
5260 p
= unpack_varlen_hex (&buf
[1], &value
);
5264 /* The remote process exited. */
5265 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5266 event
->ws
.value
.integer
= value
;
5270 /* The remote process exited with a signal. */
5271 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5272 event
->ws
.value
.sig
= (enum target_signal
) value
;
5275 /* If no process is specified, assume inferior_ptid. */
5276 pid
= ptid_get_pid (inferior_ptid
);
5285 else if (strncmp (p
,
5286 "process:", sizeof ("process:") - 1) == 0)
5290 p
+= sizeof ("process:") - 1;
5291 unpack_varlen_hex (p
, &upid
);
5295 error (_("unknown stop reply packet: %s"), buf
);
5298 error (_("unknown stop reply packet: %s"), buf
);
5299 event
->ptid
= pid_to_ptid (pid
);
5304 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5305 error (_("No process or thread specified in stop reply: %s"), buf
);
5308 /* When the stub wants to tell GDB about a new stop reply, it sends a
5309 stop notification (%Stop). Those can come it at any time, hence,
5310 we have to make sure that any pending putpkt/getpkt sequence we're
5311 making is finished, before querying the stub for more events with
5312 vStopped. E.g., if we started a vStopped sequence immediatelly
5313 upon receiving the %Stop notification, something like this could
5321 1.6) <-- (registers reply to step #1.3)
5323 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5326 To solve this, whenever we parse a %Stop notification sucessfully,
5327 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5328 doing whatever we were doing:
5334 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5335 2.5) <-- (registers reply to step #2.3)
5337 Eventualy after step #2.5, we return to the event loop, which
5338 notices there's an event on the
5339 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5340 associated callback --- the function below. At this point, we're
5341 always safe to start a vStopped sequence. :
5344 2.7) <-- T05 thread:2
5350 remote_get_pending_stop_replies (void)
5352 struct remote_state
*rs
= get_remote_state ();
5354 if (pending_stop_reply
)
5357 putpkt ("vStopped");
5359 /* Now we can rely on it. */
5360 push_stop_reply (pending_stop_reply
);
5361 pending_stop_reply
= NULL
;
5365 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5366 if (strcmp (rs
->buf
, "OK") == 0)
5370 struct cleanup
*old_chain
;
5371 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5373 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5374 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5377 putpkt ("vStopped");
5379 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5381 /* Now we can rely on it. */
5382 discard_cleanups (old_chain
);
5383 push_stop_reply (stop_reply
);
5386 /* We got an unknown stop reply. */
5387 do_cleanups (old_chain
);
5394 /* Called when it is decided that STOP_REPLY holds the info of the
5395 event that is to be returned to the core. This function always
5396 destroys STOP_REPLY. */
5399 process_stop_reply (struct stop_reply
*stop_reply
,
5400 struct target_waitstatus
*status
)
5404 *status
= stop_reply
->ws
;
5405 ptid
= stop_reply
->ptid
;
5407 /* If no thread/process was reported by the stub, assume the current
5409 if (ptid_equal (ptid
, null_ptid
))
5410 ptid
= inferior_ptid
;
5412 if (status
->kind
!= TARGET_WAITKIND_EXITED
5413 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5415 /* Expedited registers. */
5416 if (stop_reply
->regcache
)
5418 struct regcache
*regcache
5419 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5424 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5426 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5427 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5430 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5431 remote_watch_data_address
= stop_reply
->watch_data_address
;
5433 remote_notice_new_inferior (ptid
, 0);
5434 demand_private_info (ptid
)->core
= stop_reply
->core
;
5437 stop_reply_xfree (stop_reply
);
5441 /* The non-stop mode version of target_wait. */
5444 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5446 struct remote_state
*rs
= get_remote_state ();
5447 struct stop_reply
*stop_reply
;
5450 /* If in non-stop mode, get out of getpkt even if a
5451 notification is received. */
5453 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5460 case 'E': /* Error of some sort. */
5461 /* We're out of sync with the target now. Did it continue
5462 or not? We can't tell which thread it was in non-stop,
5463 so just ignore this. */
5464 warning (_("Remote failure reply: %s"), rs
->buf
);
5466 case 'O': /* Console output. */
5467 remote_console_output (rs
->buf
+ 1);
5470 warning (_("Invalid remote reply: %s"), rs
->buf
);
5474 /* Acknowledge a pending stop reply that may have arrived in the
5476 if (pending_stop_reply
!= NULL
)
5477 remote_get_pending_stop_replies ();
5479 /* If indeed we noticed a stop reply, we're done. */
5480 stop_reply
= queued_stop_reply (ptid
);
5481 if (stop_reply
!= NULL
)
5482 return process_stop_reply (stop_reply
, status
);
5484 /* Still no event. If we're just polling for an event, then
5485 return to the event loop. */
5486 if (options
& TARGET_WNOHANG
)
5488 status
->kind
= TARGET_WAITKIND_IGNORE
;
5489 return minus_one_ptid
;
5492 /* Otherwise do a blocking wait. */
5493 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5498 /* Wait until the remote machine stops, then return, storing status in
5499 STATUS just as `wait' would. */
5502 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5504 struct remote_state
*rs
= get_remote_state ();
5505 ptid_t event_ptid
= null_ptid
;
5507 struct stop_reply
*stop_reply
;
5511 status
->kind
= TARGET_WAITKIND_IGNORE
;
5512 status
->value
.integer
= 0;
5514 stop_reply
= queued_stop_reply (ptid
);
5515 if (stop_reply
!= NULL
)
5516 return process_stop_reply (stop_reply
, status
);
5518 if (rs
->cached_wait_status
)
5519 /* Use the cached wait status, but only once. */
5520 rs
->cached_wait_status
= 0;
5525 if (!target_is_async_p ())
5527 ofunc
= signal (SIGINT
, remote_interrupt
);
5528 /* If the user hit C-c before this packet, or between packets,
5529 pretend that it was hit right here. */
5533 remote_interrupt (SIGINT
);
5537 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5538 _never_ wait for ever -> test on target_is_async_p().
5539 However, before we do that we need to ensure that the caller
5540 knows how to take the target into/out of async mode. */
5541 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5542 if (!target_is_async_p ())
5543 signal (SIGINT
, ofunc
);
5548 remote_stopped_by_watchpoint_p
= 0;
5550 /* We got something. */
5551 rs
->waiting_for_stop_reply
= 0;
5553 /* Assume that the target has acknowledged Ctrl-C unless we receive
5554 an 'F' or 'O' packet. */
5555 if (buf
[0] != 'F' && buf
[0] != 'O')
5556 rs
->ctrlc_pending_p
= 0;
5560 case 'E': /* Error of some sort. */
5561 /* We're out of sync with the target now. Did it continue or
5562 not? Not is more likely, so report a stop. */
5563 warning (_("Remote failure reply: %s"), buf
);
5564 status
->kind
= TARGET_WAITKIND_STOPPED
;
5565 status
->value
.sig
= TARGET_SIGNAL_0
;
5567 case 'F': /* File-I/O request. */
5568 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5569 rs
->ctrlc_pending_p
= 0;
5571 case 'T': case 'S': case 'X': case 'W':
5573 struct stop_reply
*stop_reply
;
5574 struct cleanup
*old_chain
;
5576 stop_reply
= stop_reply_xmalloc ();
5577 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5578 remote_parse_stop_reply (buf
, stop_reply
);
5579 discard_cleanups (old_chain
);
5580 event_ptid
= process_stop_reply (stop_reply
, status
);
5583 case 'O': /* Console output. */
5584 remote_console_output (buf
+ 1);
5586 /* The target didn't really stop; keep waiting. */
5587 rs
->waiting_for_stop_reply
= 1;
5591 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5593 /* Zero length reply means that we tried 'S' or 'C' and the
5594 remote system doesn't support it. */
5595 target_terminal_ours_for_output ();
5597 ("Can't send signals to this remote system. %s not sent.\n",
5598 target_signal_to_name (last_sent_signal
));
5599 last_sent_signal
= TARGET_SIGNAL_0
;
5600 target_terminal_inferior ();
5602 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5603 putpkt ((char *) buf
);
5605 /* We just told the target to resume, so a stop reply is in
5607 rs
->waiting_for_stop_reply
= 1;
5610 /* else fallthrough */
5612 warning (_("Invalid remote reply: %s"), buf
);
5614 rs
->waiting_for_stop_reply
= 1;
5618 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5620 /* Nothing interesting happened. If we're doing a non-blocking
5621 poll, we're done. Otherwise, go back to waiting. */
5622 if (options
& TARGET_WNOHANG
)
5623 return minus_one_ptid
;
5627 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5628 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5630 if (!ptid_equal (event_ptid
, null_ptid
))
5631 record_currthread (event_ptid
);
5633 event_ptid
= inferior_ptid
;
5636 /* A process exit. Invalidate our notion of current thread. */
5637 record_currthread (minus_one_ptid
);
5642 /* Wait until the remote machine stops, then return, storing status in
5643 STATUS just as `wait' would. */
5646 remote_wait (struct target_ops
*ops
,
5647 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5652 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5654 event_ptid
= remote_wait_as (ptid
, status
, options
);
5656 if (target_can_async_p ())
5658 /* If there are are events left in the queue tell the event loop
5660 if (stop_reply_queue
)
5661 mark_async_event_handler (remote_async_inferior_event_token
);
5667 /* Fetch a single register using a 'p' packet. */
5670 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5672 struct remote_state
*rs
= get_remote_state ();
5674 char regp
[MAX_REGISTER_SIZE
];
5677 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5680 if (reg
->pnum
== -1)
5685 p
+= hexnumstr (p
, reg
->pnum
);
5688 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5692 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5696 case PACKET_UNKNOWN
:
5699 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5700 gdbarch_register_name (get_regcache_arch (regcache
),
5705 /* If this register is unfetchable, tell the regcache. */
5708 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5712 /* Otherwise, parse and supply the value. */
5718 error (_("fetch_register_using_p: early buf termination"));
5720 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5723 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5727 /* Fetch the registers included in the target's 'g' packet. */
5730 send_g_packet (void)
5732 struct remote_state
*rs
= get_remote_state ();
5735 sprintf (rs
->buf
, "g");
5736 remote_send (&rs
->buf
, &rs
->buf_size
);
5738 /* We can get out of synch in various cases. If the first character
5739 in the buffer is not a hex character, assume that has happened
5740 and try to fetch another packet to read. */
5741 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5742 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5743 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5744 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5747 fprintf_unfiltered (gdb_stdlog
,
5748 "Bad register packet; fetching a new packet\n");
5749 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5752 buf_len
= strlen (rs
->buf
);
5754 /* Sanity check the received packet. */
5755 if (buf_len
% 2 != 0)
5756 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5762 process_g_packet (struct regcache
*regcache
)
5764 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5765 struct remote_state
*rs
= get_remote_state ();
5766 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5771 buf_len
= strlen (rs
->buf
);
5773 /* Further sanity checks, with knowledge of the architecture. */
5774 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5775 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5777 /* Save the size of the packet sent to us by the target. It is used
5778 as a heuristic when determining the max size of packets that the
5779 target can safely receive. */
5780 if (rsa
->actual_register_packet_size
== 0)
5781 rsa
->actual_register_packet_size
= buf_len
;
5783 /* If this is smaller than we guessed the 'g' packet would be,
5784 update our records. A 'g' reply that doesn't include a register's
5785 value implies either that the register is not available, or that
5786 the 'p' packet must be used. */
5787 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5789 rsa
->sizeof_g_packet
= buf_len
/ 2;
5791 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5793 if (rsa
->regs
[i
].pnum
== -1)
5796 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5797 rsa
->regs
[i
].in_g_packet
= 0;
5799 rsa
->regs
[i
].in_g_packet
= 1;
5803 regs
= alloca (rsa
->sizeof_g_packet
);
5805 /* Unimplemented registers read as all bits zero. */
5806 memset (regs
, 0, rsa
->sizeof_g_packet
);
5808 /* Reply describes registers byte by byte, each byte encoded as two
5809 hex characters. Suck them all up, then supply them to the
5810 register cacheing/storage mechanism. */
5813 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5815 if (p
[0] == 0 || p
[1] == 0)
5816 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5817 internal_error (__FILE__
, __LINE__
,
5818 _("unexpected end of 'g' packet reply"));
5820 if (p
[0] == 'x' && p
[1] == 'x')
5821 regs
[i
] = 0; /* 'x' */
5823 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5827 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5829 struct packet_reg
*r
= &rsa
->regs
[i
];
5833 if (r
->offset
* 2 >= strlen (rs
->buf
))
5834 /* This shouldn't happen - we adjusted in_g_packet above. */
5835 internal_error (__FILE__
, __LINE__
,
5836 _("unexpected end of 'g' packet reply"));
5837 else if (rs
->buf
[r
->offset
* 2] == 'x')
5839 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5840 /* The register isn't available, mark it as such (at
5841 the same time setting the value to zero). */
5842 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5845 regcache_raw_supply (regcache
, r
->regnum
,
5852 fetch_registers_using_g (struct regcache
*regcache
)
5855 process_g_packet (regcache
);
5858 /* Make the remote selected traceframe match GDB's selected
5862 set_remote_traceframe (void)
5866 if (remote_traceframe_number
== get_traceframe_number ())
5869 /* Avoid recursion, remote_trace_find calls us again. */
5870 remote_traceframe_number
= get_traceframe_number ();
5872 newnum
= target_trace_find (tfind_number
,
5873 get_traceframe_number (), 0, 0, NULL
);
5875 /* Should not happen. If it does, all bets are off. */
5876 if (newnum
!= get_traceframe_number ())
5877 warning (_("could not set remote traceframe"));
5881 remote_fetch_registers (struct target_ops
*ops
,
5882 struct regcache
*regcache
, int regnum
)
5884 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5887 set_remote_traceframe ();
5888 set_general_thread (inferior_ptid
);
5892 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5894 gdb_assert (reg
!= NULL
);
5896 /* If this register might be in the 'g' packet, try that first -
5897 we are likely to read more than one register. If this is the
5898 first 'g' packet, we might be overly optimistic about its
5899 contents, so fall back to 'p'. */
5900 if (reg
->in_g_packet
)
5902 fetch_registers_using_g (regcache
);
5903 if (reg
->in_g_packet
)
5907 if (fetch_register_using_p (regcache
, reg
))
5910 /* This register is not available. */
5911 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5916 fetch_registers_using_g (regcache
);
5918 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5919 if (!rsa
->regs
[i
].in_g_packet
)
5920 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5922 /* This register is not available. */
5923 regcache_raw_supply (regcache
, i
, NULL
);
5927 /* Prepare to store registers. Since we may send them all (using a
5928 'G' request), we have to read out the ones we don't want to change
5932 remote_prepare_to_store (struct regcache
*regcache
)
5934 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5936 gdb_byte buf
[MAX_REGISTER_SIZE
];
5938 /* Make sure the entire registers array is valid. */
5939 switch (remote_protocol_packets
[PACKET_P
].support
)
5941 case PACKET_DISABLE
:
5942 case PACKET_SUPPORT_UNKNOWN
:
5943 /* Make sure all the necessary registers are cached. */
5944 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5945 if (rsa
->regs
[i
].in_g_packet
)
5946 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5953 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5954 packet was not recognized. */
5957 store_register_using_P (const struct regcache
*regcache
,
5958 struct packet_reg
*reg
)
5960 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5961 struct remote_state
*rs
= get_remote_state ();
5962 /* Try storing a single register. */
5963 char *buf
= rs
->buf
;
5964 gdb_byte regp
[MAX_REGISTER_SIZE
];
5967 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5970 if (reg
->pnum
== -1)
5973 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5974 p
= buf
+ strlen (buf
);
5975 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5976 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5978 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5980 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5985 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5986 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5987 case PACKET_UNKNOWN
:
5990 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5994 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5995 contents of the register cache buffer. FIXME: ignores errors. */
5998 store_registers_using_G (const struct regcache
*regcache
)
6000 struct remote_state
*rs
= get_remote_state ();
6001 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6005 /* Extract all the registers in the regcache copying them into a
6010 regs
= alloca (rsa
->sizeof_g_packet
);
6011 memset (regs
, 0, rsa
->sizeof_g_packet
);
6012 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6014 struct packet_reg
*r
= &rsa
->regs
[i
];
6017 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6021 /* Command describes registers byte by byte,
6022 each byte encoded as two hex characters. */
6025 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6027 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6029 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6030 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6031 error (_("Could not write registers; remote failure reply '%s'"),
6035 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6036 of the register cache buffer. FIXME: ignores errors. */
6039 remote_store_registers (struct target_ops
*ops
,
6040 struct regcache
*regcache
, int regnum
)
6042 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6045 set_remote_traceframe ();
6046 set_general_thread (inferior_ptid
);
6050 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6052 gdb_assert (reg
!= NULL
);
6054 /* Always prefer to store registers using the 'P' packet if
6055 possible; we often change only a small number of registers.
6056 Sometimes we change a larger number; we'd need help from a
6057 higher layer to know to use 'G'. */
6058 if (store_register_using_P (regcache
, reg
))
6061 /* For now, don't complain if we have no way to write the
6062 register. GDB loses track of unavailable registers too
6063 easily. Some day, this may be an error. We don't have
6064 any way to read the register, either... */
6065 if (!reg
->in_g_packet
)
6068 store_registers_using_G (regcache
);
6072 store_registers_using_G (regcache
);
6074 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6075 if (!rsa
->regs
[i
].in_g_packet
)
6076 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6077 /* See above for why we do not issue an error here. */
6082 /* Return the number of hex digits in num. */
6085 hexnumlen (ULONGEST num
)
6089 for (i
= 0; num
!= 0; i
++)
6095 /* Set BUF to the minimum number of hex digits representing NUM. */
6098 hexnumstr (char *buf
, ULONGEST num
)
6100 int len
= hexnumlen (num
);
6102 return hexnumnstr (buf
, num
, len
);
6106 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6109 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6115 for (i
= width
- 1; i
>= 0; i
--)
6117 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6124 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6127 remote_address_masked (CORE_ADDR addr
)
6129 int address_size
= remote_address_size
;
6131 /* If "remoteaddresssize" was not set, default to target address size. */
6133 address_size
= gdbarch_addr_bit (target_gdbarch
);
6135 if (address_size
> 0
6136 && address_size
< (sizeof (ULONGEST
) * 8))
6138 /* Only create a mask when that mask can safely be constructed
6139 in a ULONGEST variable. */
6142 mask
= (mask
<< address_size
) - 1;
6148 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6149 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6150 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6151 (which may be more than *OUT_LEN due to escape characters). The
6152 total number of bytes in the output buffer will be at most
6156 remote_escape_output (const gdb_byte
*buffer
, int len
,
6157 gdb_byte
*out_buf
, int *out_len
,
6160 int input_index
, output_index
;
6163 for (input_index
= 0; input_index
< len
; input_index
++)
6165 gdb_byte b
= buffer
[input_index
];
6167 if (b
== '$' || b
== '#' || b
== '}')
6169 /* These must be escaped. */
6170 if (output_index
+ 2 > out_maxlen
)
6172 out_buf
[output_index
++] = '}';
6173 out_buf
[output_index
++] = b
^ 0x20;
6177 if (output_index
+ 1 > out_maxlen
)
6179 out_buf
[output_index
++] = b
;
6183 *out_len
= input_index
;
6184 return output_index
;
6187 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6188 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6189 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6191 This function reverses remote_escape_output. It allows more
6192 escaped characters than that function does, in particular because
6193 '*' must be escaped to avoid the run-length encoding processing
6194 in reading packets. */
6197 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6198 gdb_byte
*out_buf
, int out_maxlen
)
6200 int input_index
, output_index
;
6205 for (input_index
= 0; input_index
< len
; input_index
++)
6207 gdb_byte b
= buffer
[input_index
];
6209 if (output_index
+ 1 > out_maxlen
)
6211 warning (_("Received too much data from remote target;"
6212 " ignoring overflow."));
6213 return output_index
;
6218 out_buf
[output_index
++] = b
^ 0x20;
6224 out_buf
[output_index
++] = b
;
6228 error (_("Unmatched escape character in target response."));
6230 return output_index
;
6233 /* Determine whether the remote target supports binary downloading.
6234 This is accomplished by sending a no-op memory write of zero length
6235 to the target at the specified address. It does not suffice to send
6236 the whole packet, since many stubs strip the eighth bit and
6237 subsequently compute a wrong checksum, which causes real havoc with
6240 NOTE: This can still lose if the serial line is not eight-bit
6241 clean. In cases like this, the user should clear "remote
6245 check_binary_download (CORE_ADDR addr
)
6247 struct remote_state
*rs
= get_remote_state ();
6249 switch (remote_protocol_packets
[PACKET_X
].support
)
6251 case PACKET_DISABLE
:
6255 case PACKET_SUPPORT_UNKNOWN
:
6261 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6263 p
+= hexnumstr (p
, (ULONGEST
) 0);
6267 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6268 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6270 if (rs
->buf
[0] == '\0')
6273 fprintf_unfiltered (gdb_stdlog
,
6274 "binary downloading NOT "
6275 "supported by target\n");
6276 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6281 fprintf_unfiltered (gdb_stdlog
,
6282 "binary downloading supported by target\n");
6283 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6290 /* Write memory data directly to the remote machine.
6291 This does not inform the data cache; the data cache uses this.
6292 HEADER is the starting part of the packet.
6293 MEMADDR is the address in the remote memory space.
6294 MYADDR is the address of the buffer in our space.
6295 LEN is the number of bytes.
6296 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6297 should send data as binary ('X'), or hex-encoded ('M').
6299 The function creates packet of the form
6300 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6302 where encoding of <DATA> is termined by PACKET_FORMAT.
6304 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6307 Returns the number of bytes transferred, or 0 (setting errno) for
6308 error. Only transfer a single packet. */
6311 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6312 const gdb_byte
*myaddr
, int len
,
6313 char packet_format
, int use_length
)
6315 struct remote_state
*rs
= get_remote_state ();
6325 if (packet_format
!= 'X' && packet_format
!= 'M')
6326 internal_error (__FILE__
, __LINE__
,
6327 _("remote_write_bytes_aux: bad packet format"));
6332 payload_size
= get_memory_write_packet_size ();
6334 /* The packet buffer will be large enough for the payload;
6335 get_memory_packet_size ensures this. */
6338 /* Compute the size of the actual payload by subtracting out the
6339 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6341 payload_size
-= strlen ("$,:#NN");
6343 /* The comma won't be used. */
6345 header_length
= strlen (header
);
6346 payload_size
-= header_length
;
6347 payload_size
-= hexnumlen (memaddr
);
6349 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6351 strcat (rs
->buf
, header
);
6352 p
= rs
->buf
+ strlen (header
);
6354 /* Compute a best guess of the number of bytes actually transfered. */
6355 if (packet_format
== 'X')
6357 /* Best guess at number of bytes that will fit. */
6358 todo
= min (len
, payload_size
);
6360 payload_size
-= hexnumlen (todo
);
6361 todo
= min (todo
, payload_size
);
6365 /* Num bytes that will fit. */
6366 todo
= min (len
, payload_size
/ 2);
6368 payload_size
-= hexnumlen (todo
);
6369 todo
= min (todo
, payload_size
/ 2);
6373 internal_error (__FILE__
, __LINE__
,
6374 _("minimum packet size too small to write data"));
6376 /* If we already need another packet, then try to align the end
6377 of this packet to a useful boundary. */
6378 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6379 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6381 /* Append "<memaddr>". */
6382 memaddr
= remote_address_masked (memaddr
);
6383 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6390 /* Append <len>. Retain the location/size of <len>. It may need to
6391 be adjusted once the packet body has been created. */
6393 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6401 /* Append the packet body. */
6402 if (packet_format
== 'X')
6404 /* Binary mode. Send target system values byte by byte, in
6405 increasing byte addresses. Only escape certain critical
6407 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6410 /* If not all TODO bytes fit, then we'll need another packet. Make
6411 a second try to keep the end of the packet aligned. Don't do
6412 this if the packet is tiny. */
6413 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6417 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6419 if (new_nr_bytes
!= nr_bytes
)
6420 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6425 p
+= payload_length
;
6426 if (use_length
&& nr_bytes
< todo
)
6428 /* Escape chars have filled up the buffer prematurely,
6429 and we have actually sent fewer bytes than planned.
6430 Fix-up the length field of the packet. Use the same
6431 number of characters as before. */
6432 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6433 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6438 /* Normal mode: Send target system values byte by byte, in
6439 increasing byte addresses. Each byte is encoded as a two hex
6441 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6445 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6446 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6448 if (rs
->buf
[0] == 'E')
6450 /* There is no correspondance between what the remote protocol
6451 uses for errors and errno codes. We would like a cleaner way
6452 of representing errors (big enough to include errno codes,
6453 bfd_error codes, and others). But for now just return EIO. */
6458 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6459 fewer bytes than we'd planned. */
6463 /* Write memory data directly to the remote machine.
6464 This does not inform the data cache; the data cache uses this.
6465 MEMADDR is the address in the remote memory space.
6466 MYADDR is the address of the buffer in our space.
6467 LEN is the number of bytes.
6469 Returns number of bytes transferred, or 0 (setting errno) for
6470 error. Only transfer a single packet. */
6473 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6475 char *packet_format
= 0;
6477 /* Check whether the target supports binary download. */
6478 check_binary_download (memaddr
);
6480 switch (remote_protocol_packets
[PACKET_X
].support
)
6483 packet_format
= "X";
6485 case PACKET_DISABLE
:
6486 packet_format
= "M";
6488 case PACKET_SUPPORT_UNKNOWN
:
6489 internal_error (__FILE__
, __LINE__
,
6490 _("remote_write_bytes: bad internal state"));
6492 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6495 return remote_write_bytes_aux (packet_format
,
6496 memaddr
, myaddr
, len
, packet_format
[0], 1);
6499 /* Read memory data directly from the remote machine.
6500 This does not use the data cache; the data cache uses this.
6501 MEMADDR is the address in the remote memory space.
6502 MYADDR is the address of the buffer in our space.
6503 LEN is the number of bytes.
6505 Returns number of bytes transferred, or 0 for error. */
6508 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6510 struct remote_state
*rs
= get_remote_state ();
6511 int max_buf_size
; /* Max size of packet output buffer. */
6519 max_buf_size
= get_memory_read_packet_size ();
6520 /* The packet buffer will be large enough for the payload;
6521 get_memory_packet_size ensures this. */
6523 /* Number if bytes that will fit. */
6524 todo
= min (len
, max_buf_size
/ 2);
6526 /* Construct "m"<memaddr>","<len>". */
6527 memaddr
= remote_address_masked (memaddr
);
6530 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6532 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6535 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6536 if (rs
->buf
[0] == 'E'
6537 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6538 && rs
->buf
[3] == '\0')
6540 /* There is no correspondance between what the remote protocol
6541 uses for errors and errno codes. We would like a cleaner way
6542 of representing errors (big enough to include errno codes,
6543 bfd_error codes, and others). But for now just return
6548 /* Reply describes memory byte by byte, each byte encoded as two hex
6551 i
= hex2bin (p
, myaddr
, todo
);
6552 /* Return what we have. Let higher layers handle partial reads. */
6557 /* Remote notification handler. */
6560 handle_notification (char *buf
, size_t length
)
6562 if (strncmp (buf
, "Stop:", 5) == 0)
6564 if (pending_stop_reply
)
6566 /* We've already parsed the in-flight stop-reply, but the
6567 stub for some reason thought we didn't, possibly due to
6568 timeout on its side. Just ignore it. */
6570 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6574 struct cleanup
*old_chain
;
6575 struct stop_reply
*reply
= stop_reply_xmalloc ();
6577 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6579 remote_parse_stop_reply (buf
+ 5, reply
);
6581 discard_cleanups (old_chain
);
6583 /* Be careful to only set it after parsing, since an error
6584 may be thrown then. */
6585 pending_stop_reply
= reply
;
6587 /* Notify the event loop there's a stop reply to acknowledge
6588 and that there may be more events to fetch. */
6589 mark_async_event_handler (remote_async_get_pending_events_token
);
6592 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6596 /* We ignore notifications we don't recognize, for compatibility
6597 with newer stubs. */
6602 /* Read or write LEN bytes from inferior memory at MEMADDR,
6603 transferring to or from debugger address BUFFER. Write to inferior
6604 if SHOULD_WRITE is nonzero. Returns length of data written or
6605 read; 0 for error. TARGET is unused. */
6608 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6609 int should_write
, struct mem_attrib
*attrib
,
6610 struct target_ops
*target
)
6614 set_remote_traceframe ();
6615 set_general_thread (inferior_ptid
);
6618 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6620 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6625 /* Sends a packet with content determined by the printf format string
6626 FORMAT and the remaining arguments, then gets the reply. Returns
6627 whether the packet was a success, a failure, or unknown. */
6629 static enum packet_result
6630 remote_send_printf (const char *format
, ...)
6632 struct remote_state
*rs
= get_remote_state ();
6633 int max_size
= get_remote_packet_size ();
6636 va_start (ap
, format
);
6639 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6640 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6642 if (putpkt (rs
->buf
) < 0)
6643 error (_("Communication problem with target."));
6646 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6648 return packet_check_result (rs
->buf
);
6652 restore_remote_timeout (void *p
)
6654 int value
= *(int *)p
;
6656 remote_timeout
= value
;
6659 /* Flash writing can take quite some time. We'll set
6660 effectively infinite timeout for flash operations.
6661 In future, we'll need to decide on a better approach. */
6662 static const int remote_flash_timeout
= 1000;
6665 remote_flash_erase (struct target_ops
*ops
,
6666 ULONGEST address
, LONGEST length
)
6668 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6669 int saved_remote_timeout
= remote_timeout
;
6670 enum packet_result ret
;
6671 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6672 &saved_remote_timeout
);
6674 remote_timeout
= remote_flash_timeout
;
6676 ret
= remote_send_printf ("vFlashErase:%s,%s",
6677 phex (address
, addr_size
),
6681 case PACKET_UNKNOWN
:
6682 error (_("Remote target does not support flash erase"));
6684 error (_("Error erasing flash with vFlashErase packet"));
6689 do_cleanups (back_to
);
6693 remote_flash_write (struct target_ops
*ops
,
6694 ULONGEST address
, LONGEST length
,
6695 const gdb_byte
*data
)
6697 int saved_remote_timeout
= remote_timeout
;
6699 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6700 &saved_remote_timeout
);
6702 remote_timeout
= remote_flash_timeout
;
6703 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6704 do_cleanups (back_to
);
6710 remote_flash_done (struct target_ops
*ops
)
6712 int saved_remote_timeout
= remote_timeout
;
6714 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6715 &saved_remote_timeout
);
6717 remote_timeout
= remote_flash_timeout
;
6718 ret
= remote_send_printf ("vFlashDone");
6719 do_cleanups (back_to
);
6723 case PACKET_UNKNOWN
:
6724 error (_("Remote target does not support vFlashDone"));
6726 error (_("Error finishing flash operation"));
6733 remote_files_info (struct target_ops
*ignore
)
6735 puts_filtered ("Debugging a target over a serial line.\n");
6738 /* Stuff for dealing with the packets which are part of this protocol.
6739 See comment at top of file for details. */
6741 /* Read a single character from the remote end. */
6744 readchar (int timeout
)
6748 ch
= serial_readchar (remote_desc
, timeout
);
6753 switch ((enum serial_rc
) ch
)
6757 error (_("Remote connection closed"));
6761 perror_with_name (_("Remote communication error. "
6762 "Target disconnected."));
6764 case SERIAL_TIMEOUT
:
6770 /* Send the command in *BUF to the remote machine, and read the reply
6771 into *BUF. Report an error if we get an error reply. Resize
6772 *BUF using xrealloc if necessary to hold the result, and update
6776 remote_send (char **buf
,
6780 getpkt (buf
, sizeof_buf
, 0);
6782 if ((*buf
)[0] == 'E')
6783 error (_("Remote failure reply: %s"), *buf
);
6786 /* Return a pointer to an xmalloc'ed string representing an escaped
6787 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6788 etc. The caller is responsible for releasing the returned
6792 escape_buffer (const char *buf
, int n
)
6794 struct cleanup
*old_chain
;
6795 struct ui_file
*stb
;
6798 stb
= mem_fileopen ();
6799 old_chain
= make_cleanup_ui_file_delete (stb
);
6801 fputstrn_unfiltered (buf
, n
, 0, stb
);
6802 str
= ui_file_xstrdup (stb
, NULL
);
6803 do_cleanups (old_chain
);
6807 /* Display a null-terminated packet on stdout, for debugging, using C
6811 print_packet (char *buf
)
6813 puts_filtered ("\"");
6814 fputstr_filtered (buf
, '"', gdb_stdout
);
6815 puts_filtered ("\"");
6821 return putpkt_binary (buf
, strlen (buf
));
6824 /* Send a packet to the remote machine, with error checking. The data
6825 of the packet is in BUF. The string in BUF can be at most
6826 get_remote_packet_size () - 5 to account for the $, # and checksum,
6827 and for a possible /0 if we are debugging (remote_debug) and want
6828 to print the sent packet as a string. */
6831 putpkt_binary (char *buf
, int cnt
)
6833 struct remote_state
*rs
= get_remote_state ();
6835 unsigned char csum
= 0;
6836 char *buf2
= alloca (cnt
+ 6);
6842 /* Catch cases like trying to read memory or listing threads while
6843 we're waiting for a stop reply. The remote server wouldn't be
6844 ready to handle this request, so we'd hang and timeout. We don't
6845 have to worry about this in synchronous mode, because in that
6846 case it's not possible to issue a command while the target is
6847 running. This is not a problem in non-stop mode, because in that
6848 case, the stub is always ready to process serial input. */
6849 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6850 error (_("Cannot execute this command while the target is running."));
6852 /* We're sending out a new packet. Make sure we don't look at a
6853 stale cached response. */
6854 rs
->cached_wait_status
= 0;
6856 /* Copy the packet into buffer BUF2, encapsulating it
6857 and giving it a checksum. */
6862 for (i
= 0; i
< cnt
; i
++)
6868 *p
++ = tohex ((csum
>> 4) & 0xf);
6869 *p
++ = tohex (csum
& 0xf);
6871 /* Send it over and over until we get a positive ack. */
6875 int started_error_output
= 0;
6879 struct cleanup
*old_chain
;
6883 str
= escape_buffer (buf2
, p
- buf2
);
6884 old_chain
= make_cleanup (xfree
, str
);
6885 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6886 gdb_flush (gdb_stdlog
);
6887 do_cleanups (old_chain
);
6889 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6890 perror_with_name (_("putpkt: write failed"));
6892 /* If this is a no acks version of the remote protocol, send the
6893 packet and move on. */
6897 /* Read until either a timeout occurs (-2) or '+' is read.
6898 Handle any notification that arrives in the mean time. */
6901 ch
= readchar (remote_timeout
);
6909 case SERIAL_TIMEOUT
:
6912 if (started_error_output
)
6914 putchar_unfiltered ('\n');
6915 started_error_output
= 0;
6924 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6928 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6930 case SERIAL_TIMEOUT
:
6934 break; /* Retransmit buffer. */
6938 fprintf_unfiltered (gdb_stdlog
,
6939 "Packet instead of Ack, ignoring it\n");
6940 /* It's probably an old response sent because an ACK
6941 was lost. Gobble up the packet and ack it so it
6942 doesn't get retransmitted when we resend this
6945 serial_write (remote_desc
, "+", 1);
6946 continue; /* Now, go look for +. */
6953 /* If we got a notification, handle it, and go back to looking
6955 /* We've found the start of a notification. Now
6956 collect the data. */
6957 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6962 struct cleanup
*old_chain
;
6965 str
= escape_buffer (rs
->buf
, val
);
6966 old_chain
= make_cleanup (xfree
, str
);
6967 fprintf_unfiltered (gdb_stdlog
,
6968 " Notification received: %s\n",
6970 do_cleanups (old_chain
);
6972 handle_notification (rs
->buf
, val
);
6973 /* We're in sync now, rewait for the ack. */
6980 if (!started_error_output
)
6982 started_error_output
= 1;
6983 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6985 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6986 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6995 if (!started_error_output
)
6997 started_error_output
= 1;
6998 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7000 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7004 break; /* Here to retransmit. */
7008 /* This is wrong. If doing a long backtrace, the user should be
7009 able to get out next time we call QUIT, without anything as
7010 violent as interrupt_query. If we want to provide a way out of
7011 here without getting to the next QUIT, it should be based on
7012 hitting ^C twice as in remote_wait. */
7023 /* Come here after finding the start of a frame when we expected an
7024 ack. Do our best to discard the rest of this packet. */
7033 c
= readchar (remote_timeout
);
7036 case SERIAL_TIMEOUT
:
7037 /* Nothing we can do. */
7040 /* Discard the two bytes of checksum and stop. */
7041 c
= readchar (remote_timeout
);
7043 c
= readchar (remote_timeout
);
7046 case '*': /* Run length encoding. */
7047 /* Discard the repeat count. */
7048 c
= readchar (remote_timeout
);
7053 /* A regular character. */
7059 /* Come here after finding the start of the frame. Collect the rest
7060 into *BUF, verifying the checksum, length, and handling run-length
7061 compression. NUL terminate the buffer. If there is not enough room,
7062 expand *BUF using xrealloc.
7064 Returns -1 on error, number of characters in buffer (ignoring the
7065 trailing NULL) on success. (could be extended to return one of the
7066 SERIAL status indications). */
7069 read_frame (char **buf_p
,
7076 struct remote_state
*rs
= get_remote_state ();
7083 c
= readchar (remote_timeout
);
7086 case SERIAL_TIMEOUT
:
7088 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7092 fputs_filtered ("Saw new packet start in middle of old one\n",
7094 return -1; /* Start a new packet, count retries. */
7097 unsigned char pktcsum
;
7103 check_0
= readchar (remote_timeout
);
7105 check_1
= readchar (remote_timeout
);
7107 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7110 fputs_filtered ("Timeout in checksum, retrying\n",
7114 else if (check_0
< 0 || check_1
< 0)
7117 fputs_filtered ("Communication error in checksum\n",
7122 /* Don't recompute the checksum; with no ack packets we
7123 don't have any way to indicate a packet retransmission
7128 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7129 if (csum
== pktcsum
)
7134 struct cleanup
*old_chain
;
7137 str
= escape_buffer (buf
, bc
);
7138 old_chain
= make_cleanup (xfree
, str
);
7139 fprintf_unfiltered (gdb_stdlog
,
7140 "Bad checksum, sentsum=0x%x, "
7141 "csum=0x%x, buf=%s\n",
7142 pktcsum
, csum
, str
);
7143 do_cleanups (old_chain
);
7145 /* Number of characters in buffer ignoring trailing
7149 case '*': /* Run length encoding. */
7154 c
= readchar (remote_timeout
);
7156 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7158 /* The character before ``*'' is repeated. */
7160 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7162 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7164 /* Make some more room in the buffer. */
7165 *sizeof_buf
+= repeat
;
7166 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7170 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7176 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7180 if (bc
>= *sizeof_buf
- 1)
7182 /* Make some more room in the buffer. */
7184 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7195 /* Read a packet from the remote machine, with error checking, and
7196 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7197 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7198 rather than timing out; this is used (in synchronous mode) to wait
7199 for a target that is is executing user code to stop. */
7200 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7201 don't have to change all the calls to getpkt to deal with the
7202 return value, because at the moment I don't know what the right
7203 thing to do it for those. */
7211 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7215 /* Read a packet from the remote machine, with error checking, and
7216 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7217 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7218 rather than timing out; this is used (in synchronous mode) to wait
7219 for a target that is is executing user code to stop. If FOREVER ==
7220 0, this function is allowed to time out gracefully and return an
7221 indication of this to the caller. Otherwise return the number of
7222 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7223 enough reason to return to the caller. */
7226 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7227 int expecting_notif
)
7229 struct remote_state
*rs
= get_remote_state ();
7235 /* We're reading a new response. Make sure we don't look at a
7236 previously cached response. */
7237 rs
->cached_wait_status
= 0;
7239 strcpy (*buf
, "timeout");
7242 timeout
= watchdog
> 0 ? watchdog
: -1;
7243 else if (expecting_notif
)
7244 timeout
= 0; /* There should already be a char in the buffer. If
7247 timeout
= remote_timeout
;
7251 /* Process any number of notifications, and then return when
7255 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7257 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7259 /* This can loop forever if the remote side sends us
7260 characters continuously, but if it pauses, we'll get
7261 SERIAL_TIMEOUT from readchar because of timeout. Then
7262 we'll count that as a retry.
7264 Note that even when forever is set, we will only wait
7265 forever prior to the start of a packet. After that, we
7266 expect characters to arrive at a brisk pace. They should
7267 show up within remote_timeout intervals. */
7269 c
= readchar (timeout
);
7270 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7272 if (c
== SERIAL_TIMEOUT
)
7274 if (expecting_notif
)
7275 return -1; /* Don't complain, it's normal to not get
7276 anything in this case. */
7278 if (forever
) /* Watchdog went off? Kill the target. */
7282 error (_("Watchdog timeout has expired. Target detached."));
7285 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7289 /* We've found the start of a packet or notification.
7290 Now collect the data. */
7291 val
= read_frame (buf
, sizeof_buf
);
7296 serial_write (remote_desc
, "-", 1);
7299 if (tries
> MAX_TRIES
)
7301 /* We have tried hard enough, and just can't receive the
7302 packet/notification. Give up. */
7303 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7305 /* Skip the ack char if we're in no-ack mode. */
7306 if (!rs
->noack_mode
)
7307 serial_write (remote_desc
, "+", 1);
7311 /* If we got an ordinary packet, return that to our caller. */
7316 struct cleanup
*old_chain
;
7319 str
= escape_buffer (*buf
, val
);
7320 old_chain
= make_cleanup (xfree
, str
);
7321 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7322 do_cleanups (old_chain
);
7325 /* Skip the ack char if we're in no-ack mode. */
7326 if (!rs
->noack_mode
)
7327 serial_write (remote_desc
, "+", 1);
7331 /* If we got a notification, handle it, and go back to looking
7335 gdb_assert (c
== '%');
7339 struct cleanup
*old_chain
;
7342 str
= escape_buffer (*buf
, val
);
7343 old_chain
= make_cleanup (xfree
, str
);
7344 fprintf_unfiltered (gdb_stdlog
,
7345 " Notification received: %s\n",
7347 do_cleanups (old_chain
);
7350 handle_notification (*buf
, val
);
7352 /* Notifications require no acknowledgement. */
7354 if (expecting_notif
)
7361 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7363 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7367 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7369 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7373 /* A helper function that just calls putpkt; for type correctness. */
7376 putpkt_for_catch_errors (void *arg
)
7378 return putpkt (arg
);
7382 remote_kill (struct target_ops
*ops
)
7384 /* Use catch_errors so the user can quit from gdb even when we
7385 aren't on speaking terms with the remote system. */
7386 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7388 /* Don't wait for it to die. I'm not really sure it matters whether
7389 we do or not. For the existing stubs, kill is a noop. */
7390 target_mourn_inferior ();
7394 remote_vkill (int pid
, struct remote_state
*rs
)
7396 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7399 /* Tell the remote target to detach. */
7400 sprintf (rs
->buf
, "vKill;%x", pid
);
7402 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7404 if (packet_ok (rs
->buf
,
7405 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7407 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7414 extended_remote_kill (struct target_ops
*ops
)
7417 int pid
= ptid_get_pid (inferior_ptid
);
7418 struct remote_state
*rs
= get_remote_state ();
7420 res
= remote_vkill (pid
, rs
);
7421 if (res
== -1 && !remote_multi_process_p (rs
))
7423 /* Don't try 'k' on a multi-process aware stub -- it has no way
7424 to specify the pid. */
7428 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7429 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7432 /* Don't wait for it to die. I'm not really sure it matters whether
7433 we do or not. For the existing stubs, kill is a noop. */
7439 error (_("Can't kill process"));
7441 target_mourn_inferior ();
7445 remote_mourn (struct target_ops
*ops
)
7447 remote_mourn_1 (ops
);
7450 /* Worker function for remote_mourn. */
7452 remote_mourn_1 (struct target_ops
*target
)
7454 unpush_target (target
);
7456 /* remote_close takes care of doing most of the clean up. */
7457 generic_mourn_inferior ();
7461 extended_remote_mourn_1 (struct target_ops
*target
)
7463 struct remote_state
*rs
= get_remote_state ();
7465 /* In case we got here due to an error, but we're going to stay
7467 rs
->waiting_for_stop_reply
= 0;
7469 /* We're no longer interested in these events. */
7470 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7472 /* If the current general thread belonged to the process we just
7473 detached from or has exited, the remote side current general
7474 thread becomes undefined. Considering a case like this:
7476 - We just got here due to a detach.
7477 - The process that we're detaching from happens to immediately
7478 report a global breakpoint being hit in non-stop mode, in the
7479 same thread we had selected before.
7480 - GDB attaches to this process again.
7481 - This event happens to be the next event we handle.
7483 GDB would consider that the current general thread didn't need to
7484 be set on the stub side (with Hg), since for all it knew,
7485 GENERAL_THREAD hadn't changed.
7487 Notice that although in all-stop mode, the remote server always
7488 sets the current thread to the thread reporting the stop event,
7489 that doesn't happen in non-stop mode; in non-stop, the stub *must
7490 not* change the current thread when reporting a breakpoint hit,
7491 due to the decoupling of event reporting and event handling.
7493 To keep things simple, we always invalidate our notion of the
7495 record_currthread (minus_one_ptid
);
7497 /* Unlike "target remote", we do not want to unpush the target; then
7498 the next time the user says "run", we won't be connected. */
7500 /* Call common code to mark the inferior as not running. */
7501 generic_mourn_inferior ();
7503 if (!have_inferiors ())
7505 if (!remote_multi_process_p (rs
))
7507 /* Check whether the target is running now - some remote stubs
7508 automatically restart after kill. */
7510 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7512 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7514 /* Assume that the target has been restarted. Set
7515 inferior_ptid so that bits of core GDB realizes
7516 there's something here, e.g., so that the user can
7517 say "kill" again. */
7518 inferior_ptid
= magic_null_ptid
;
7525 extended_remote_mourn (struct target_ops
*ops
)
7527 extended_remote_mourn_1 (ops
);
7531 extended_remote_supports_disable_randomization (void)
7533 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7538 extended_remote_disable_randomization (int val
)
7540 struct remote_state
*rs
= get_remote_state ();
7543 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7545 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7547 error (_("Target does not support QDisableRandomization."));
7548 if (strcmp (reply
, "OK") != 0)
7549 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7553 extended_remote_run (char *args
)
7555 struct remote_state
*rs
= get_remote_state ();
7558 /* If the user has disabled vRun support, or we have detected that
7559 support is not available, do not try it. */
7560 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7563 strcpy (rs
->buf
, "vRun;");
7564 len
= strlen (rs
->buf
);
7566 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7567 error (_("Remote file name too long for run packet"));
7568 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7570 gdb_assert (args
!= NULL
);
7573 struct cleanup
*back_to
;
7577 argv
= gdb_buildargv (args
);
7578 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7579 for (i
= 0; argv
[i
] != NULL
; i
++)
7581 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7582 error (_("Argument list too long for run packet"));
7583 rs
->buf
[len
++] = ';';
7584 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7586 do_cleanups (back_to
);
7589 rs
->buf
[len
++] = '\0';
7592 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7594 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7596 /* We have a wait response; we don't need it, though. All is well. */
7599 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7600 /* It wasn't disabled before, but it is now. */
7604 if (remote_exec_file
[0] == '\0')
7605 error (_("Running the default executable on the remote target failed; "
7606 "try \"set remote exec-file\"?"));
7608 error (_("Running \"%s\" on the remote target failed"),
7613 /* In the extended protocol we want to be able to do things like
7614 "run" and have them basically work as expected. So we need
7615 a special create_inferior function. We support changing the
7616 executable file and the command line arguments, but not the
7620 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7621 char **env
, int from_tty
)
7623 /* If running asynchronously, register the target file descriptor
7624 with the event loop. */
7625 if (target_can_async_p ())
7626 target_async (inferior_event_handler
, 0);
7628 /* Disable address space randomization if requested (and supported). */
7629 if (extended_remote_supports_disable_randomization ())
7630 extended_remote_disable_randomization (disable_randomization
);
7632 /* Now restart the remote server. */
7633 if (extended_remote_run (args
) == -1)
7635 /* vRun was not supported. Fail if we need it to do what the
7637 if (remote_exec_file
[0])
7638 error (_("Remote target does not support \"set remote exec-file\""));
7640 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7642 /* Fall back to "R". */
7643 extended_remote_restart ();
7646 if (!have_inferiors ())
7648 /* Clean up from the last time we ran, before we mark the target
7649 running again. This will mark breakpoints uninserted, and
7650 get_offsets may insert breakpoints. */
7651 init_thread_list ();
7652 init_wait_for_inferior ();
7655 /* Now mark the inferior as running before we do anything else. */
7656 inferior_ptid
= magic_null_ptid
;
7658 /* Now, if we have thread information, update inferior_ptid. */
7659 inferior_ptid
= remote_current_thread (inferior_ptid
);
7661 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7662 add_thread_silent (inferior_ptid
);
7664 /* Get updated offsets, if the stub uses qOffsets. */
7669 extended_remote_create_inferior (struct target_ops
*ops
,
7670 char *exec_file
, char *args
,
7671 char **env
, int from_tty
)
7673 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7677 /* Insert a breakpoint. On targets that have software breakpoint
7678 support, we ask the remote target to do the work; on targets
7679 which don't, we insert a traditional memory breakpoint. */
7682 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7683 struct bp_target_info
*bp_tgt
)
7685 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7686 If it succeeds, then set the support to PACKET_ENABLE. If it
7687 fails, and the user has explicitly requested the Z support then
7688 report an error, otherwise, mark it disabled and go on. */
7690 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7692 CORE_ADDR addr
= bp_tgt
->placed_address
;
7693 struct remote_state
*rs
;
7697 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7699 rs
= get_remote_state ();
7705 addr
= (ULONGEST
) remote_address_masked (addr
);
7706 p
+= hexnumstr (p
, addr
);
7707 sprintf (p
, ",%d", bpsize
);
7710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7712 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7717 bp_tgt
->placed_address
= addr
;
7718 bp_tgt
->placed_size
= bpsize
;
7720 case PACKET_UNKNOWN
:
7725 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7729 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7730 struct bp_target_info
*bp_tgt
)
7732 CORE_ADDR addr
= bp_tgt
->placed_address
;
7733 struct remote_state
*rs
= get_remote_state ();
7735 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7743 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7744 p
+= hexnumstr (p
, addr
);
7745 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7750 return (rs
->buf
[0] == 'E');
7753 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7757 watchpoint_to_Z_packet (int type
)
7762 return Z_PACKET_WRITE_WP
;
7765 return Z_PACKET_READ_WP
;
7768 return Z_PACKET_ACCESS_WP
;
7771 internal_error (__FILE__
, __LINE__
,
7772 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7777 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7778 struct expression
*cond
)
7780 struct remote_state
*rs
= get_remote_state ();
7782 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7784 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7787 sprintf (rs
->buf
, "Z%x,", packet
);
7788 p
= strchr (rs
->buf
, '\0');
7789 addr
= remote_address_masked (addr
);
7790 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7791 sprintf (p
, ",%x", len
);
7794 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7796 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7800 case PACKET_UNKNOWN
:
7805 internal_error (__FILE__
, __LINE__
,
7806 _("remote_insert_watchpoint: reached end of function"));
7811 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7812 struct expression
*cond
)
7814 struct remote_state
*rs
= get_remote_state ();
7816 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7818 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7821 sprintf (rs
->buf
, "z%x,", packet
);
7822 p
= strchr (rs
->buf
, '\0');
7823 addr
= remote_address_masked (addr
);
7824 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7825 sprintf (p
, ",%x", len
);
7827 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7829 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7832 case PACKET_UNKNOWN
:
7837 internal_error (__FILE__
, __LINE__
,
7838 _("remote_remove_watchpoint: reached end of function"));
7842 int remote_hw_watchpoint_limit
= -1;
7843 int remote_hw_watchpoint_length_limit
= -1;
7844 int remote_hw_breakpoint_limit
= -1;
7847 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7849 if (remote_hw_watchpoint_length_limit
== 0)
7851 else if (remote_hw_watchpoint_length_limit
< 0)
7853 else if (len
<= remote_hw_watchpoint_length_limit
)
7860 remote_check_watch_resources (int type
, int cnt
, int ot
)
7862 if (type
== bp_hardware_breakpoint
)
7864 if (remote_hw_breakpoint_limit
== 0)
7866 else if (remote_hw_breakpoint_limit
< 0)
7868 else if (cnt
<= remote_hw_breakpoint_limit
)
7873 if (remote_hw_watchpoint_limit
== 0)
7875 else if (remote_hw_watchpoint_limit
< 0)
7879 else if (cnt
<= remote_hw_watchpoint_limit
)
7886 remote_stopped_by_watchpoint (void)
7888 return remote_stopped_by_watchpoint_p
;
7892 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7896 if (remote_stopped_by_watchpoint ())
7898 *addr_p
= remote_watch_data_address
;
7907 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7908 struct bp_target_info
*bp_tgt
)
7911 struct remote_state
*rs
;
7914 /* The length field should be set to the size of a breakpoint
7915 instruction, even though we aren't inserting one ourselves. */
7917 gdbarch_remote_breakpoint_from_pc
7918 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7920 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7923 rs
= get_remote_state ();
7930 addr
= remote_address_masked (bp_tgt
->placed_address
);
7931 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7932 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7935 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7937 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7940 case PACKET_UNKNOWN
:
7945 internal_error (__FILE__
, __LINE__
,
7946 _("remote_insert_hw_breakpoint: reached end of function"));
7951 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7952 struct bp_target_info
*bp_tgt
)
7955 struct remote_state
*rs
= get_remote_state ();
7958 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7965 addr
= remote_address_masked (bp_tgt
->placed_address
);
7966 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7967 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7972 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7975 case PACKET_UNKNOWN
:
7980 internal_error (__FILE__
, __LINE__
,
7981 _("remote_remove_hw_breakpoint: reached end of function"));
7984 /* Table used by the crc32 function to calcuate the checksum. */
7986 static unsigned long crc32_table
[256] =
7989 static unsigned long
7990 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7992 if (!crc32_table
[1])
7994 /* Initialize the CRC table and the decoding table. */
7998 for (i
= 0; i
< 256; i
++)
8000 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8001 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8008 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8014 /* Verify memory using the "qCRC:" request. */
8017 remote_verify_memory (struct target_ops
*ops
,
8018 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8020 struct remote_state
*rs
= get_remote_state ();
8021 unsigned long host_crc
, target_crc
;
8024 /* FIXME: assumes lma can fit into long. */
8025 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8026 (long) lma
, (long) size
);
8029 /* Be clever; compute the host_crc before waiting for target
8031 host_crc
= crc32 (data
, size
, 0xffffffff);
8033 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8034 if (rs
->buf
[0] == 'E')
8037 if (rs
->buf
[0] != 'C')
8038 error (_("remote target does not support this operation"));
8040 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8041 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8043 return (host_crc
== target_crc
);
8046 /* compare-sections command
8048 With no arguments, compares each loadable section in the exec bfd
8049 with the same memory range on the target, and reports mismatches.
8050 Useful for verifying the image on the target against the exec file. */
8053 compare_sections_command (char *args
, int from_tty
)
8056 struct cleanup
*old_chain
;
8058 const char *sectname
;
8066 error (_("command cannot be used without an exec file"));
8068 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8070 if (!(s
->flags
& SEC_LOAD
))
8071 continue; /* Skip non-loadable section. */
8073 size
= bfd_get_section_size (s
);
8075 continue; /* Skip zero-length section. */
8077 sectname
= bfd_get_section_name (exec_bfd
, s
);
8078 if (args
&& strcmp (args
, sectname
) != 0)
8079 continue; /* Not the section selected by user. */
8081 matched
= 1; /* Do this section. */
8084 sectdata
= xmalloc (size
);
8085 old_chain
= make_cleanup (xfree
, sectdata
);
8086 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8088 res
= target_verify_memory (sectdata
, lma
, size
);
8091 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8092 paddress (target_gdbarch
, lma
),
8093 paddress (target_gdbarch
, lma
+ size
));
8095 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8096 paddress (target_gdbarch
, lma
),
8097 paddress (target_gdbarch
, lma
+ size
));
8099 printf_filtered ("matched.\n");
8102 printf_filtered ("MIS-MATCHED!\n");
8106 do_cleanups (old_chain
);
8109 warning (_("One or more sections of the remote executable does not match\n\
8110 the loaded file\n"));
8111 if (args
&& !matched
)
8112 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8115 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8116 into remote target. The number of bytes written to the remote
8117 target is returned, or -1 for error. */
8120 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8121 const char *annex
, const gdb_byte
*writebuf
,
8122 ULONGEST offset
, LONGEST len
,
8123 struct packet_config
*packet
)
8127 struct remote_state
*rs
= get_remote_state ();
8128 int max_size
= get_memory_write_packet_size ();
8130 if (packet
->support
== PACKET_DISABLE
)
8133 /* Insert header. */
8134 i
= snprintf (rs
->buf
, max_size
,
8135 "qXfer:%s:write:%s:%s:",
8136 object_name
, annex
? annex
: "",
8137 phex_nz (offset
, sizeof offset
));
8138 max_size
-= (i
+ 1);
8140 /* Escape as much data as fits into rs->buf. */
8141 buf_len
= remote_escape_output
8142 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8144 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8145 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8146 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8149 unpack_varlen_hex (rs
->buf
, &n
);
8153 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8154 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8155 number of bytes read is returned, or 0 for EOF, or -1 for error.
8156 The number of bytes read may be less than LEN without indicating an
8157 EOF. PACKET is checked and updated to indicate whether the remote
8158 target supports this object. */
8161 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8163 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8164 struct packet_config
*packet
)
8166 static char *finished_object
;
8167 static char *finished_annex
;
8168 static ULONGEST finished_offset
;
8170 struct remote_state
*rs
= get_remote_state ();
8171 LONGEST i
, n
, packet_len
;
8173 if (packet
->support
== PACKET_DISABLE
)
8176 /* Check whether we've cached an end-of-object packet that matches
8178 if (finished_object
)
8180 if (strcmp (object_name
, finished_object
) == 0
8181 && strcmp (annex
? annex
: "", finished_annex
) == 0
8182 && offset
== finished_offset
)
8185 /* Otherwise, we're now reading something different. Discard
8187 xfree (finished_object
);
8188 xfree (finished_annex
);
8189 finished_object
= NULL
;
8190 finished_annex
= NULL
;
8193 /* Request only enough to fit in a single packet. The actual data
8194 may not, since we don't know how much of it will need to be escaped;
8195 the target is free to respond with slightly less data. We subtract
8196 five to account for the response type and the protocol frame. */
8197 n
= min (get_remote_packet_size () - 5, len
);
8198 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8199 object_name
, annex
? annex
: "",
8200 phex_nz (offset
, sizeof offset
),
8201 phex_nz (n
, sizeof n
));
8202 i
= putpkt (rs
->buf
);
8207 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8208 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8211 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8212 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8214 /* 'm' means there is (or at least might be) more data after this
8215 batch. That does not make sense unless there's at least one byte
8216 of data in this reply. */
8217 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8218 error (_("Remote qXfer reply contained no data."));
8220 /* Got some data. */
8221 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8223 /* 'l' is an EOF marker, possibly including a final block of data,
8224 or possibly empty. If we have the final block of a non-empty
8225 object, record this fact to bypass a subsequent partial read. */
8226 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8228 finished_object
= xstrdup (object_name
);
8229 finished_annex
= xstrdup (annex
? annex
: "");
8230 finished_offset
= offset
+ i
;
8237 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8238 const char *annex
, gdb_byte
*readbuf
,
8239 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8241 struct remote_state
*rs
;
8246 set_remote_traceframe ();
8247 set_general_thread (inferior_ptid
);
8249 rs
= get_remote_state ();
8251 /* Handle memory using the standard memory routines. */
8252 if (object
== TARGET_OBJECT_MEMORY
)
8258 /* If the remote target is connected but not running, we should
8259 pass this request down to a lower stratum (e.g. the executable
8261 if (!target_has_execution
)
8264 if (writebuf
!= NULL
)
8265 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8267 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8271 else if (xfered
== 0 && errno
== 0)
8277 /* Handle SPU memory using qxfer packets. */
8278 if (object
== TARGET_OBJECT_SPU
)
8281 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8282 &remote_protocol_packets
8283 [PACKET_qXfer_spu_read
]);
8285 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8286 &remote_protocol_packets
8287 [PACKET_qXfer_spu_write
]);
8290 /* Handle extra signal info using qxfer packets. */
8291 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8294 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8295 &remote_protocol_packets
8296 [PACKET_qXfer_siginfo_read
]);
8298 return remote_write_qxfer (ops
, "siginfo", annex
,
8299 writebuf
, offset
, len
,
8300 &remote_protocol_packets
8301 [PACKET_qXfer_siginfo_write
]);
8304 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8307 return remote_read_qxfer (ops
, "statictrace", annex
,
8308 readbuf
, offset
, len
,
8309 &remote_protocol_packets
8310 [PACKET_qXfer_statictrace_read
]);
8315 /* Only handle flash writes. */
8316 if (writebuf
!= NULL
)
8322 case TARGET_OBJECT_FLASH
:
8323 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8327 else if (xfered
== 0 && errno
== 0)
8337 /* Map pre-existing objects onto letters. DO NOT do this for new
8338 objects!!! Instead specify new query packets. */
8341 case TARGET_OBJECT_AVR
:
8345 case TARGET_OBJECT_AUXV
:
8346 gdb_assert (annex
== NULL
);
8347 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8348 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8350 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8351 return remote_read_qxfer
8352 (ops
, "features", annex
, readbuf
, offset
, len
,
8353 &remote_protocol_packets
[PACKET_qXfer_features
]);
8355 case TARGET_OBJECT_LIBRARIES
:
8356 return remote_read_qxfer
8357 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8358 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8360 case TARGET_OBJECT_LIBRARIES_SVR4
:
8361 return remote_read_qxfer
8362 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8363 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8365 case TARGET_OBJECT_MEMORY_MAP
:
8366 gdb_assert (annex
== NULL
);
8367 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8368 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8370 case TARGET_OBJECT_OSDATA
:
8371 /* Should only get here if we're connected. */
8372 gdb_assert (remote_desc
);
8373 return remote_read_qxfer
8374 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8375 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8377 case TARGET_OBJECT_THREADS
:
8378 gdb_assert (annex
== NULL
);
8379 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8380 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8382 case TARGET_OBJECT_TRACEFRAME_INFO
:
8383 gdb_assert (annex
== NULL
);
8384 return remote_read_qxfer
8385 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8386 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8388 case TARGET_OBJECT_FDPIC
:
8389 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8390 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8395 /* Note: a zero OFFSET and LEN can be used to query the minimum
8397 if (offset
== 0 && len
== 0)
8398 return (get_remote_packet_size ());
8399 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8400 large enough let the caller deal with it. */
8401 if (len
< get_remote_packet_size ())
8403 len
= get_remote_packet_size ();
8405 /* Except for querying the minimum buffer size, target must be open. */
8407 error (_("remote query is only available after target open"));
8409 gdb_assert (annex
!= NULL
);
8410 gdb_assert (readbuf
!= NULL
);
8416 /* We used one buffer char for the remote protocol q command and
8417 another for the query type. As the remote protocol encapsulation
8418 uses 4 chars plus one extra in case we are debugging
8419 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8422 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8424 /* Bad caller may have sent forbidden characters. */
8425 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8430 gdb_assert (annex
[i
] == '\0');
8432 i
= putpkt (rs
->buf
);
8436 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8437 strcpy ((char *) readbuf
, rs
->buf
);
8439 return strlen ((char *) readbuf
);
8443 remote_search_memory (struct target_ops
* ops
,
8444 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8445 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8446 CORE_ADDR
*found_addrp
)
8448 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8449 struct remote_state
*rs
= get_remote_state ();
8450 int max_size
= get_memory_write_packet_size ();
8451 struct packet_config
*packet
=
8452 &remote_protocol_packets
[PACKET_qSearch_memory
];
8453 /* Number of packet bytes used to encode the pattern;
8454 this could be more than PATTERN_LEN due to escape characters. */
8455 int escaped_pattern_len
;
8456 /* Amount of pattern that was encodable in the packet. */
8457 int used_pattern_len
;
8460 ULONGEST found_addr
;
8462 /* Don't go to the target if we don't have to.
8463 This is done before checking packet->support to avoid the possibility that
8464 a success for this edge case means the facility works in general. */
8465 if (pattern_len
> search_space_len
)
8467 if (pattern_len
== 0)
8469 *found_addrp
= start_addr
;
8473 /* If we already know the packet isn't supported, fall back to the simple
8474 way of searching memory. */
8476 if (packet
->support
== PACKET_DISABLE
)
8478 /* Target doesn't provided special support, fall back and use the
8479 standard support (copy memory and do the search here). */
8480 return simple_search_memory (ops
, start_addr
, search_space_len
,
8481 pattern
, pattern_len
, found_addrp
);
8484 /* Insert header. */
8485 i
= snprintf (rs
->buf
, max_size
,
8486 "qSearch:memory:%s;%s;",
8487 phex_nz (start_addr
, addr_size
),
8488 phex_nz (search_space_len
, sizeof (search_space_len
)));
8489 max_size
-= (i
+ 1);
8491 /* Escape as much data as fits into rs->buf. */
8492 escaped_pattern_len
=
8493 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8494 &used_pattern_len
, max_size
);
8496 /* Bail if the pattern is too large. */
8497 if (used_pattern_len
!= pattern_len
)
8498 error (_("Pattern is too large to transmit to remote target."));
8500 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8501 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8502 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8504 /* The request may not have worked because the command is not
8505 supported. If so, fall back to the simple way. */
8506 if (packet
->support
== PACKET_DISABLE
)
8508 return simple_search_memory (ops
, start_addr
, search_space_len
,
8509 pattern
, pattern_len
, found_addrp
);
8514 if (rs
->buf
[0] == '0')
8516 else if (rs
->buf
[0] == '1')
8519 if (rs
->buf
[1] != ',')
8520 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8521 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8522 *found_addrp
= found_addr
;
8525 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8531 remote_rcmd (char *command
,
8532 struct ui_file
*outbuf
)
8534 struct remote_state
*rs
= get_remote_state ();
8538 error (_("remote rcmd is only available after target open"));
8540 /* Send a NULL command across as an empty command. */
8541 if (command
== NULL
)
8544 /* The query prefix. */
8545 strcpy (rs
->buf
, "qRcmd,");
8546 p
= strchr (rs
->buf
, '\0');
8548 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8549 > get_remote_packet_size ())
8550 error (_("\"monitor\" command ``%s'' is too long."), command
);
8552 /* Encode the actual command. */
8553 bin2hex ((gdb_byte
*) command
, p
, 0);
8555 if (putpkt (rs
->buf
) < 0)
8556 error (_("Communication problem with target."));
8558 /* get/display the response */
8563 /* XXX - see also remote_get_noisy_reply(). */
8565 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8568 error (_("Target does not support this command."));
8569 if (buf
[0] == 'O' && buf
[1] != 'K')
8571 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8574 if (strcmp (buf
, "OK") == 0)
8576 if (strlen (buf
) == 3 && buf
[0] == 'E'
8577 && isdigit (buf
[1]) && isdigit (buf
[2]))
8579 error (_("Protocol error with Rcmd"));
8581 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8583 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8585 fputc_unfiltered (c
, outbuf
);
8591 static VEC(mem_region_s
) *
8592 remote_memory_map (struct target_ops
*ops
)
8594 VEC(mem_region_s
) *result
= NULL
;
8595 char *text
= target_read_stralloc (¤t_target
,
8596 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8600 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8602 result
= parse_memory_map (text
);
8603 do_cleanups (back_to
);
8610 packet_command (char *args
, int from_tty
)
8612 struct remote_state
*rs
= get_remote_state ();
8615 error (_("command can only be used with remote target"));
8618 error (_("remote-packet command requires packet text as argument"));
8620 puts_filtered ("sending: ");
8621 print_packet (args
);
8622 puts_filtered ("\n");
8625 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8626 puts_filtered ("received: ");
8627 print_packet (rs
->buf
);
8628 puts_filtered ("\n");
8632 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8634 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8636 static void threadset_test_cmd (char *cmd
, int tty
);
8638 static void threadalive_test (char *cmd
, int tty
);
8640 static void threadlist_test_cmd (char *cmd
, int tty
);
8642 int get_and_display_threadinfo (threadref
*ref
);
8644 static void threadinfo_test_cmd (char *cmd
, int tty
);
8646 static int thread_display_step (threadref
*ref
, void *context
);
8648 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8650 static void init_remote_threadtests (void);
8652 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8655 threadset_test_cmd (char *cmd
, int tty
)
8657 int sample_thread
= SAMPLE_THREAD
;
8659 printf_filtered (_("Remote threadset test\n"));
8660 set_general_thread (sample_thread
);
8665 threadalive_test (char *cmd
, int tty
)
8667 int sample_thread
= SAMPLE_THREAD
;
8668 int pid
= ptid_get_pid (inferior_ptid
);
8669 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8671 if (remote_thread_alive (ptid
))
8672 printf_filtered ("PASS: Thread alive test\n");
8674 printf_filtered ("FAIL: Thread alive test\n");
8677 void output_threadid (char *title
, threadref
*ref
);
8680 output_threadid (char *title
, threadref
*ref
)
8684 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8686 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8690 threadlist_test_cmd (char *cmd
, int tty
)
8693 threadref nextthread
;
8694 int done
, result_count
;
8695 threadref threadlist
[3];
8697 printf_filtered ("Remote Threadlist test\n");
8698 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8699 &result_count
, &threadlist
[0]))
8700 printf_filtered ("FAIL: threadlist test\n");
8703 threadref
*scan
= threadlist
;
8704 threadref
*limit
= scan
+ result_count
;
8706 while (scan
< limit
)
8707 output_threadid (" thread ", scan
++);
8712 display_thread_info (struct gdb_ext_thread_info
*info
)
8714 output_threadid ("Threadid: ", &info
->threadid
);
8715 printf_filtered ("Name: %s\n ", info
->shortname
);
8716 printf_filtered ("State: %s\n", info
->display
);
8717 printf_filtered ("other: %s\n\n", info
->more_display
);
8721 get_and_display_threadinfo (threadref
*ref
)
8725 struct gdb_ext_thread_info threadinfo
;
8727 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8728 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8729 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8730 display_thread_info (&threadinfo
);
8735 threadinfo_test_cmd (char *cmd
, int tty
)
8737 int athread
= SAMPLE_THREAD
;
8741 int_to_threadref (&thread
, athread
);
8742 printf_filtered ("Remote Threadinfo test\n");
8743 if (!get_and_display_threadinfo (&thread
))
8744 printf_filtered ("FAIL cannot get thread info\n");
8748 thread_display_step (threadref
*ref
, void *context
)
8750 /* output_threadid(" threadstep ",ref); *//* simple test */
8751 return get_and_display_threadinfo (ref
);
8755 threadlist_update_test_cmd (char *cmd
, int tty
)
8757 printf_filtered ("Remote Threadlist update test\n");
8758 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8762 init_remote_threadtests (void)
8764 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8765 _("Fetch and print the remote list of "
8766 "thread identifiers, one pkt only"));
8767 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8768 _("Fetch and display info about one thread"));
8769 add_com ("tset", class_obscure
, threadset_test_cmd
,
8770 _("Test setting to a different thread"));
8771 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8772 _("Iterate through updating all remote thread info"));
8773 add_com ("talive", class_obscure
, threadalive_test
,
8774 _(" Remote thread alive test "));
8779 /* Convert a thread ID to a string. Returns the string in a static
8783 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8785 static char buf
[64];
8786 struct remote_state
*rs
= get_remote_state ();
8788 if (ptid_is_pid (ptid
))
8790 /* Printing an inferior target id. */
8792 /* When multi-process extensions are off, there's no way in the
8793 remote protocol to know the remote process id, if there's any
8794 at all. There's one exception --- when we're connected with
8795 target extended-remote, and we manually attached to a process
8796 with "attach PID". We don't record anywhere a flag that
8797 allows us to distinguish that case from the case of
8798 connecting with extended-remote and the stub already being
8799 attached to a process, and reporting yes to qAttached, hence
8800 no smart special casing here. */
8801 if (!remote_multi_process_p (rs
))
8803 xsnprintf (buf
, sizeof buf
, "Remote target");
8807 return normal_pid_to_str (ptid
);
8811 if (ptid_equal (magic_null_ptid
, ptid
))
8812 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8813 else if (remote_multi_process_p (rs
))
8814 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8815 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8817 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8818 ptid_get_tid (ptid
));
8823 /* Get the address of the thread local variable in OBJFILE which is
8824 stored at OFFSET within the thread local storage for thread PTID. */
8827 remote_get_thread_local_address (struct target_ops
*ops
,
8828 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8830 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8832 struct remote_state
*rs
= get_remote_state ();
8834 char *endp
= rs
->buf
+ get_remote_packet_size ();
8835 enum packet_result result
;
8837 strcpy (p
, "qGetTLSAddr:");
8839 p
= write_ptid (p
, endp
, ptid
);
8841 p
+= hexnumstr (p
, offset
);
8843 p
+= hexnumstr (p
, lm
);
8847 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8848 result
= packet_ok (rs
->buf
,
8849 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8850 if (result
== PACKET_OK
)
8854 unpack_varlen_hex (rs
->buf
, &result
);
8857 else if (result
== PACKET_UNKNOWN
)
8858 throw_error (TLS_GENERIC_ERROR
,
8859 _("Remote target doesn't support qGetTLSAddr packet"));
8861 throw_error (TLS_GENERIC_ERROR
,
8862 _("Remote target failed to process qGetTLSAddr request"));
8865 throw_error (TLS_GENERIC_ERROR
,
8866 _("TLS not supported or disabled on this target"));
8871 /* Provide thread local base, i.e. Thread Information Block address.
8872 Returns 1 if ptid is found and thread_local_base is non zero. */
8875 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8877 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8879 struct remote_state
*rs
= get_remote_state ();
8881 char *endp
= rs
->buf
+ get_remote_packet_size ();
8882 enum packet_result result
;
8884 strcpy (p
, "qGetTIBAddr:");
8886 p
= write_ptid (p
, endp
, ptid
);
8890 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8891 result
= packet_ok (rs
->buf
,
8892 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8893 if (result
== PACKET_OK
)
8897 unpack_varlen_hex (rs
->buf
, &result
);
8899 *addr
= (CORE_ADDR
) result
;
8902 else if (result
== PACKET_UNKNOWN
)
8903 error (_("Remote target doesn't support qGetTIBAddr packet"));
8905 error (_("Remote target failed to process qGetTIBAddr request"));
8908 error (_("qGetTIBAddr not supported or disabled on this target"));
8913 /* Support for inferring a target description based on the current
8914 architecture and the size of a 'g' packet. While the 'g' packet
8915 can have any size (since optional registers can be left off the
8916 end), some sizes are easily recognizable given knowledge of the
8917 approximate architecture. */
8919 struct remote_g_packet_guess
8922 const struct target_desc
*tdesc
;
8924 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8925 DEF_VEC_O(remote_g_packet_guess_s
);
8927 struct remote_g_packet_data
8929 VEC(remote_g_packet_guess_s
) *guesses
;
8932 static struct gdbarch_data
*remote_g_packet_data_handle
;
8935 remote_g_packet_data_init (struct obstack
*obstack
)
8937 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8941 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8942 const struct target_desc
*tdesc
)
8944 struct remote_g_packet_data
*data
8945 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8946 struct remote_g_packet_guess new_guess
, *guess
;
8949 gdb_assert (tdesc
!= NULL
);
8952 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8954 if (guess
->bytes
== bytes
)
8955 internal_error (__FILE__
, __LINE__
,
8956 _("Duplicate g packet description added for size %d"),
8959 new_guess
.bytes
= bytes
;
8960 new_guess
.tdesc
= tdesc
;
8961 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8964 /* Return 1 if remote_read_description would do anything on this target
8965 and architecture, 0 otherwise. */
8968 remote_read_description_p (struct target_ops
*target
)
8970 struct remote_g_packet_data
*data
8971 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8973 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8979 static const struct target_desc
*
8980 remote_read_description (struct target_ops
*target
)
8982 struct remote_g_packet_data
*data
8983 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8985 /* Do not try this during initial connection, when we do not know
8986 whether there is a running but stopped thread. */
8987 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8990 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8992 struct remote_g_packet_guess
*guess
;
8994 int bytes
= send_g_packet ();
8997 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8999 if (guess
->bytes
== bytes
)
9000 return guess
->tdesc
;
9002 /* We discard the g packet. A minor optimization would be to
9003 hold on to it, and fill the register cache once we have selected
9004 an architecture, but it's too tricky to do safely. */
9010 /* Remote file transfer support. This is host-initiated I/O, not
9011 target-initiated; for target-initiated, see remote-fileio.c. */
9013 /* If *LEFT is at least the length of STRING, copy STRING to
9014 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9015 decrease *LEFT. Otherwise raise an error. */
9018 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9020 int len
= strlen (string
);
9023 error (_("Packet too long for target."));
9025 memcpy (*buffer
, string
, len
);
9029 /* NUL-terminate the buffer as a convenience, if there is
9035 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
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_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9043 if (2 * len
> *left
)
9044 error (_("Packet too long for target."));
9046 bin2hex (bytes
, *buffer
, len
);
9050 /* NUL-terminate the buffer as a convenience, if there is
9056 /* If *LEFT is large enough, convert VALUE to hex and add it to
9057 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9058 decrease *LEFT. Otherwise raise an error. */
9061 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9063 int len
= hexnumlen (value
);
9066 error (_("Packet too long for target."));
9068 hexnumstr (*buffer
, value
);
9072 /* NUL-terminate the buffer as a convenience, if there is
9078 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9079 value, *REMOTE_ERRNO to the remote error number or zero if none
9080 was included, and *ATTACHMENT to point to the start of the annex
9081 if any. The length of the packet isn't needed here; there may
9082 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9084 Return 0 if the packet could be parsed, -1 if it could not. If
9085 -1 is returned, the other variables may not be initialized. */
9088 remote_hostio_parse_result (char *buffer
, int *retcode
,
9089 int *remote_errno
, char **attachment
)
9096 if (buffer
[0] != 'F')
9100 *retcode
= strtol (&buffer
[1], &p
, 16);
9101 if (errno
!= 0 || p
== &buffer
[1])
9104 /* Check for ",errno". */
9108 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9109 if (errno
!= 0 || p
+ 1 == p2
)
9114 /* Check for ";attachment". If there is no attachment, the
9115 packet should end here. */
9118 *attachment
= p
+ 1;
9121 else if (*p
== '\0')
9127 /* Send a prepared I/O packet to the target and read its response.
9128 The prepared packet is in the global RS->BUF before this function
9129 is called, and the answer is there when we return.
9131 COMMAND_BYTES is the length of the request to send, which may include
9132 binary data. WHICH_PACKET is the packet configuration to check
9133 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9134 is set to the error number and -1 is returned. Otherwise the value
9135 returned by the function is returned.
9137 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9138 attachment is expected; an error will be reported if there's a
9139 mismatch. If one is found, *ATTACHMENT will be set to point into
9140 the packet buffer and *ATTACHMENT_LEN will be set to the
9141 attachment's length. */
9144 remote_hostio_send_command (int command_bytes
, int which_packet
,
9145 int *remote_errno
, char **attachment
,
9146 int *attachment_len
)
9148 struct remote_state
*rs
= get_remote_state ();
9149 int ret
, bytes_read
;
9150 char *attachment_tmp
;
9153 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9155 *remote_errno
= FILEIO_ENOSYS
;
9159 putpkt_binary (rs
->buf
, command_bytes
);
9160 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9162 /* If it timed out, something is wrong. Don't try to parse the
9166 *remote_errno
= FILEIO_EINVAL
;
9170 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9173 *remote_errno
= FILEIO_EINVAL
;
9175 case PACKET_UNKNOWN
:
9176 *remote_errno
= FILEIO_ENOSYS
;
9182 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9185 *remote_errno
= FILEIO_EINVAL
;
9189 /* Make sure we saw an attachment if and only if we expected one. */
9190 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9191 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9193 *remote_errno
= FILEIO_EINVAL
;
9197 /* If an attachment was found, it must point into the packet buffer;
9198 work out how many bytes there were. */
9199 if (attachment_tmp
!= NULL
)
9201 *attachment
= attachment_tmp
;
9202 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9208 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9209 remote file descriptor, or -1 if an error occurs (and set
9213 remote_hostio_open (const char *filename
, int flags
, int mode
,
9216 struct remote_state
*rs
= get_remote_state ();
9218 int left
= get_remote_packet_size () - 1;
9220 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9222 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9224 remote_buffer_add_string (&p
, &left
, ",");
9226 remote_buffer_add_int (&p
, &left
, flags
);
9227 remote_buffer_add_string (&p
, &left
, ",");
9229 remote_buffer_add_int (&p
, &left
, mode
);
9231 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9232 remote_errno
, NULL
, NULL
);
9235 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9236 Return the number of bytes written, or -1 if an error occurs (and
9237 set *REMOTE_ERRNO). */
9240 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9241 ULONGEST offset
, int *remote_errno
)
9243 struct remote_state
*rs
= get_remote_state ();
9245 int left
= get_remote_packet_size ();
9248 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9250 remote_buffer_add_int (&p
, &left
, fd
);
9251 remote_buffer_add_string (&p
, &left
, ",");
9253 remote_buffer_add_int (&p
, &left
, offset
);
9254 remote_buffer_add_string (&p
, &left
, ",");
9256 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9257 get_remote_packet_size () - (p
- rs
->buf
));
9259 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9260 remote_errno
, NULL
, NULL
);
9263 /* Read up to LEN bytes FD on the remote target into READ_BUF
9264 Return the number of bytes read, or -1 if an error occurs (and
9265 set *REMOTE_ERRNO). */
9268 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9269 ULONGEST offset
, int *remote_errno
)
9271 struct remote_state
*rs
= get_remote_state ();
9274 int left
= get_remote_packet_size ();
9275 int ret
, attachment_len
;
9278 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9280 remote_buffer_add_int (&p
, &left
, fd
);
9281 remote_buffer_add_string (&p
, &left
, ",");
9283 remote_buffer_add_int (&p
, &left
, len
);
9284 remote_buffer_add_string (&p
, &left
, ",");
9286 remote_buffer_add_int (&p
, &left
, offset
);
9288 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9289 remote_errno
, &attachment
,
9295 read_len
= remote_unescape_input (attachment
, attachment_len
,
9297 if (read_len
!= ret
)
9298 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9303 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9304 (and set *REMOTE_ERRNO). */
9307 remote_hostio_close (int fd
, int *remote_errno
)
9309 struct remote_state
*rs
= get_remote_state ();
9311 int left
= get_remote_packet_size () - 1;
9313 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9315 remote_buffer_add_int (&p
, &left
, fd
);
9317 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9318 remote_errno
, NULL
, NULL
);
9321 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9322 occurs (and set *REMOTE_ERRNO). */
9325 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9327 struct remote_state
*rs
= get_remote_state ();
9329 int left
= get_remote_packet_size () - 1;
9331 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9333 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9336 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9337 remote_errno
, NULL
, NULL
);
9341 remote_fileio_errno_to_host (int errnum
)
9365 case FILEIO_ENOTDIR
:
9385 case FILEIO_ENAMETOOLONG
:
9386 return ENAMETOOLONG
;
9392 remote_hostio_error (int errnum
)
9394 int host_error
= remote_fileio_errno_to_host (errnum
);
9396 if (host_error
== -1)
9397 error (_("Unknown remote I/O error %d"), errnum
);
9399 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9403 remote_hostio_close_cleanup (void *opaque
)
9405 int fd
= *(int *) opaque
;
9408 remote_hostio_close (fd
, &remote_errno
);
9413 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9415 const char *filename
= bfd_get_filename (abfd
);
9416 int fd
, remote_errno
;
9419 gdb_assert (remote_filename_p (filename
));
9421 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9424 errno
= remote_fileio_errno_to_host (remote_errno
);
9425 bfd_set_error (bfd_error_system_call
);
9429 stream
= xmalloc (sizeof (int));
9435 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9437 int fd
= *(int *)stream
;
9442 /* Ignore errors on close; these may happen if the remote
9443 connection was already torn down. */
9444 remote_hostio_close (fd
, &remote_errno
);
9450 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9451 file_ptr nbytes
, file_ptr offset
)
9453 int fd
= *(int *)stream
;
9455 file_ptr pos
, bytes
;
9458 while (nbytes
> pos
)
9460 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9461 offset
+ pos
, &remote_errno
);
9463 /* Success, but no bytes, means end-of-file. */
9467 errno
= remote_fileio_errno_to_host (remote_errno
);
9468 bfd_set_error (bfd_error_system_call
);
9479 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9481 /* FIXME: We should probably implement remote_hostio_stat. */
9482 sb
->st_size
= INT_MAX
;
9487 remote_filename_p (const char *filename
)
9489 return strncmp (filename
, "remote:", 7) == 0;
9493 remote_bfd_open (const char *remote_file
, const char *target
)
9495 return bfd_openr_iovec (remote_file
, target
,
9496 remote_bfd_iovec_open
, NULL
,
9497 remote_bfd_iovec_pread
,
9498 remote_bfd_iovec_close
,
9499 remote_bfd_iovec_stat
);
9503 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9505 struct cleanup
*back_to
, *close_cleanup
;
9506 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9509 int bytes_in_buffer
;
9514 error (_("command can only be used with remote target"));
9516 file
= fopen (local_file
, "rb");
9518 perror_with_name (local_file
);
9519 back_to
= make_cleanup_fclose (file
);
9521 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9523 0700, &remote_errno
);
9525 remote_hostio_error (remote_errno
);
9527 /* Send up to this many bytes at once. They won't all fit in the
9528 remote packet limit, so we'll transfer slightly fewer. */
9529 io_size
= get_remote_packet_size ();
9530 buffer
= xmalloc (io_size
);
9531 make_cleanup (xfree
, buffer
);
9533 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9535 bytes_in_buffer
= 0;
9538 while (bytes_in_buffer
|| !saw_eof
)
9542 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9543 io_size
- bytes_in_buffer
,
9548 error (_("Error reading %s."), local_file
);
9551 /* EOF. Unless there is something still in the
9552 buffer from the last iteration, we are done. */
9554 if (bytes_in_buffer
== 0)
9562 bytes
+= bytes_in_buffer
;
9563 bytes_in_buffer
= 0;
9565 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9566 offset
, &remote_errno
);
9569 remote_hostio_error (remote_errno
);
9570 else if (retcode
== 0)
9571 error (_("Remote write of %d bytes returned 0!"), bytes
);
9572 else if (retcode
< bytes
)
9574 /* Short write. Save the rest of the read data for the next
9576 bytes_in_buffer
= bytes
- retcode
;
9577 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9583 discard_cleanups (close_cleanup
);
9584 if (remote_hostio_close (fd
, &remote_errno
))
9585 remote_hostio_error (remote_errno
);
9588 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9589 do_cleanups (back_to
);
9593 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9595 struct cleanup
*back_to
, *close_cleanup
;
9596 int fd
, remote_errno
, bytes
, io_size
;
9602 error (_("command can only be used with remote target"));
9604 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9606 remote_hostio_error (remote_errno
);
9608 file
= fopen (local_file
, "wb");
9610 perror_with_name (local_file
);
9611 back_to
= make_cleanup_fclose (file
);
9613 /* Send up to this many bytes at once. They won't all fit in the
9614 remote packet limit, so we'll transfer slightly fewer. */
9615 io_size
= get_remote_packet_size ();
9616 buffer
= xmalloc (io_size
);
9617 make_cleanup (xfree
, buffer
);
9619 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9624 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9626 /* Success, but no bytes, means end-of-file. */
9629 remote_hostio_error (remote_errno
);
9633 bytes
= fwrite (buffer
, 1, bytes
, file
);
9635 perror_with_name (local_file
);
9638 discard_cleanups (close_cleanup
);
9639 if (remote_hostio_close (fd
, &remote_errno
))
9640 remote_hostio_error (remote_errno
);
9643 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9644 do_cleanups (back_to
);
9648 remote_file_delete (const char *remote_file
, int from_tty
)
9650 int retcode
, remote_errno
;
9653 error (_("command can only be used with remote target"));
9655 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9657 remote_hostio_error (remote_errno
);
9660 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9664 remote_put_command (char *args
, int from_tty
)
9666 struct cleanup
*back_to
;
9670 error_no_arg (_("file to put"));
9672 argv
= gdb_buildargv (args
);
9673 back_to
= make_cleanup_freeargv (argv
);
9674 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9675 error (_("Invalid parameters to remote put"));
9677 remote_file_put (argv
[0], argv
[1], from_tty
);
9679 do_cleanups (back_to
);
9683 remote_get_command (char *args
, int from_tty
)
9685 struct cleanup
*back_to
;
9689 error_no_arg (_("file to get"));
9691 argv
= gdb_buildargv (args
);
9692 back_to
= make_cleanup_freeargv (argv
);
9693 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9694 error (_("Invalid parameters to remote get"));
9696 remote_file_get (argv
[0], argv
[1], from_tty
);
9698 do_cleanups (back_to
);
9702 remote_delete_command (char *args
, int from_tty
)
9704 struct cleanup
*back_to
;
9708 error_no_arg (_("file to delete"));
9710 argv
= gdb_buildargv (args
);
9711 back_to
= make_cleanup_freeargv (argv
);
9712 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9713 error (_("Invalid parameters to remote delete"));
9715 remote_file_delete (argv
[0], from_tty
);
9717 do_cleanups (back_to
);
9721 remote_command (char *args
, int from_tty
)
9723 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9727 remote_can_execute_reverse (void)
9729 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9730 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9737 remote_supports_non_stop (void)
9743 remote_supports_disable_randomization (void)
9745 /* Only supported in extended mode. */
9750 remote_supports_multi_process (void)
9752 struct remote_state
*rs
= get_remote_state ();
9754 return remote_multi_process_p (rs
);
9758 remote_supports_cond_tracepoints (void)
9760 struct remote_state
*rs
= get_remote_state ();
9762 return rs
->cond_tracepoints
;
9766 remote_supports_fast_tracepoints (void)
9768 struct remote_state
*rs
= get_remote_state ();
9770 return rs
->fast_tracepoints
;
9774 remote_supports_static_tracepoints (void)
9776 struct remote_state
*rs
= get_remote_state ();
9778 return rs
->static_tracepoints
;
9782 remote_supports_install_in_trace (void)
9784 struct remote_state
*rs
= get_remote_state ();
9786 return rs
->install_in_trace
;
9790 remote_supports_enable_disable_tracepoint (void)
9792 struct remote_state
*rs
= get_remote_state ();
9794 return rs
->enable_disable_tracepoints
;
9798 remote_supports_string_tracing (void)
9800 struct remote_state
*rs
= get_remote_state ();
9802 return rs
->string_tracing
;
9806 remote_trace_init (void)
9809 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9810 if (strcmp (target_buf
, "OK") != 0)
9811 error (_("Target does not support this command."));
9814 static void free_actions_list (char **actions_list
);
9815 static void free_actions_list_cleanup_wrapper (void *);
9817 free_actions_list_cleanup_wrapper (void *al
)
9819 free_actions_list (al
);
9823 free_actions_list (char **actions_list
)
9827 if (actions_list
== 0)
9830 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9831 xfree (actions_list
[ndx
]);
9833 xfree (actions_list
);
9836 /* Recursive routine to walk through command list including loops, and
9837 download packets for each command. */
9840 remote_download_command_source (int num
, ULONGEST addr
,
9841 struct command_line
*cmds
)
9843 struct remote_state
*rs
= get_remote_state ();
9844 struct command_line
*cmd
;
9846 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9848 QUIT
; /* Allow user to bail out with ^C. */
9849 strcpy (rs
->buf
, "QTDPsrc:");
9850 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9851 rs
->buf
+ strlen (rs
->buf
),
9852 rs
->buf_size
- strlen (rs
->buf
));
9854 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9855 if (strcmp (target_buf
, "OK"))
9856 warning (_("Target does not support source download."));
9858 if (cmd
->control_type
== while_control
9859 || cmd
->control_type
== while_stepping_control
)
9861 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9863 QUIT
; /* Allow user to bail out with ^C. */
9864 strcpy (rs
->buf
, "QTDPsrc:");
9865 encode_source_string (num
, addr
, "cmd", "end",
9866 rs
->buf
+ strlen (rs
->buf
),
9867 rs
->buf_size
- strlen (rs
->buf
));
9869 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9870 if (strcmp (target_buf
, "OK"))
9871 warning (_("Target does not support source download."));
9877 remote_download_tracepoint (struct bp_location
*loc
)
9884 char **stepping_actions
;
9886 struct cleanup
*old_chain
= NULL
;
9887 struct agent_expr
*aexpr
;
9888 struct cleanup
*aexpr_chain
= NULL
;
9890 struct breakpoint
*b
= loc
->owner
;
9891 struct tracepoint
*t
= (struct tracepoint
*) b
;
9893 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9894 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9896 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9899 tpaddr
= loc
->address
;
9900 sprintf_vma (addrbuf
, tpaddr
);
9901 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9902 addrbuf
, /* address */
9903 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9904 t
->step_count
, t
->pass_count
);
9905 /* Fast tracepoints are mostly handled by the target, but we can
9906 tell the target how big of an instruction block should be moved
9908 if (b
->type
== bp_fast_tracepoint
)
9910 /* Only test for support at download time; we may not know
9911 target capabilities at definition time. */
9912 if (remote_supports_fast_tracepoints ())
9916 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9917 tpaddr
, &isize
, NULL
))
9918 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9920 /* If it passed validation at definition but fails now,
9921 something is very wrong. */
9922 internal_error (__FILE__
, __LINE__
,
9923 _("Fast tracepoint not "
9924 "valid during download"));
9927 /* Fast tracepoints are functionally identical to regular
9928 tracepoints, so don't take lack of support as a reason to
9929 give up on the trace run. */
9930 warning (_("Target does not support fast tracepoints, "
9931 "downloading %d as regular tracepoint"), b
->number
);
9933 else if (b
->type
== bp_static_tracepoint
)
9935 /* Only test for support at download time; we may not know
9936 target capabilities at definition time. */
9937 if (remote_supports_static_tracepoints ())
9939 struct static_tracepoint_marker marker
;
9941 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
9944 error (_("Static tracepoint not valid during download"));
9947 /* Fast tracepoints are functionally identical to regular
9948 tracepoints, so don't take lack of support as a reason
9949 to give up on the trace run. */
9950 error (_("Target does not support static tracepoints"));
9952 /* If the tracepoint has a conditional, make it into an agent
9953 expression and append to the definition. */
9956 /* Only test support at download time, we may not know target
9957 capabilities at definition time. */
9958 if (remote_supports_cond_tracepoints ())
9960 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9961 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9962 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9963 pkt
= buf
+ strlen (buf
);
9964 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9965 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9967 do_cleanups (aexpr_chain
);
9970 warning (_("Target does not support conditional tracepoints, "
9971 "ignoring tp %d cond"), b
->number
);
9974 if (b
->commands
|| *default_collect
)
9977 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9978 if (strcmp (target_buf
, "OK"))
9979 error (_("Target does not support tracepoints."));
9981 /* do_single_steps (t); */
9984 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9986 QUIT
; /* Allow user to bail out with ^C. */
9987 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9988 b
->number
, addrbuf
, /* address */
9990 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9993 remote_get_noisy_reply (&target_buf
,
9995 if (strcmp (target_buf
, "OK"))
9996 error (_("Error on target while setting tracepoints."));
9999 if (stepping_actions
)
10001 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10003 QUIT
; /* Allow user to bail out with ^C. */
10004 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
10005 b
->number
, addrbuf
, /* address */
10006 ((ndx
== 0) ? "S" : ""),
10007 stepping_actions
[ndx
],
10008 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10010 remote_get_noisy_reply (&target_buf
,
10012 if (strcmp (target_buf
, "OK"))
10013 error (_("Error on target while setting tracepoints."));
10017 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10020 if (b
->addr_string
)
10022 strcpy (buf
, "QTDPsrc:");
10023 encode_source_string (b
->number
, loc
->address
,
10024 "at", b
->addr_string
, buf
+ strlen (buf
),
10025 2048 - strlen (buf
));
10028 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10029 if (strcmp (target_buf
, "OK"))
10030 warning (_("Target does not support source download."));
10032 if (b
->cond_string
)
10034 strcpy (buf
, "QTDPsrc:");
10035 encode_source_string (b
->number
, loc
->address
,
10036 "cond", b
->cond_string
, buf
+ strlen (buf
),
10037 2048 - strlen (buf
));
10039 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10040 if (strcmp (target_buf
, "OK"))
10041 warning (_("Target does not support source download."));
10043 remote_download_command_source (b
->number
, loc
->address
,
10044 breakpoint_commands (b
));
10047 do_cleanups (old_chain
);
10051 remote_can_download_tracepoint (void)
10053 struct trace_status
*ts
= current_trace_status ();
10054 int status
= remote_get_trace_status (ts
);
10056 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10059 /* If we are in a tracing experiment, but remote stub doesn't support
10060 installing tracepoint in trace, we have to return. */
10061 if (!remote_supports_install_in_trace ())
10069 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10071 struct remote_state
*rs
= get_remote_state ();
10074 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10075 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10076 p
= rs
->buf
+ strlen (rs
->buf
);
10077 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10078 error (_("Trace state variable name too long for tsv definition packet"));
10079 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10082 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10083 if (*target_buf
== '\0')
10084 error (_("Target does not support this command."));
10085 if (strcmp (target_buf
, "OK") != 0)
10086 error (_("Error on target while downloading trace state variable."));
10090 remote_enable_tracepoint (struct bp_location
*location
)
10092 struct remote_state
*rs
= get_remote_state ();
10095 sprintf_vma (addr_buf
, location
->address
);
10096 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10098 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10099 if (*rs
->buf
== '\0')
10100 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10101 if (strcmp (rs
->buf
, "OK") != 0)
10102 error (_("Error on target while enabling tracepoint."));
10106 remote_disable_tracepoint (struct bp_location
*location
)
10108 struct remote_state
*rs
= get_remote_state ();
10111 sprintf_vma (addr_buf
, location
->address
);
10112 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10114 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10115 if (*rs
->buf
== '\0')
10116 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10117 if (strcmp (rs
->buf
, "OK") != 0)
10118 error (_("Error on target while disabling tracepoint."));
10122 remote_trace_set_readonly_regions (void)
10125 bfd_size_type size
;
10131 return; /* No information to give. */
10133 strcpy (target_buf
, "QTro");
10134 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10136 char tmp1
[40], tmp2
[40];
10139 if ((s
->flags
& SEC_LOAD
) == 0 ||
10140 /* (s->flags & SEC_CODE) == 0 || */
10141 (s
->flags
& SEC_READONLY
) == 0)
10145 vma
= bfd_get_section_vma (,s
);
10146 size
= bfd_get_section_size (s
);
10147 sprintf_vma (tmp1
, vma
);
10148 sprintf_vma (tmp2
, vma
+ size
);
10149 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10150 if (offset
+ sec_length
+ 1 > target_buf_size
)
10152 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10155 Too many sections for read-only sections definition packet."));
10158 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10159 offset
+= sec_length
;
10163 putpkt (target_buf
);
10164 getpkt (&target_buf
, &target_buf_size
, 0);
10169 remote_trace_start (void)
10171 putpkt ("QTStart");
10172 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10173 if (*target_buf
== '\0')
10174 error (_("Target does not support this command."));
10175 if (strcmp (target_buf
, "OK") != 0)
10176 error (_("Bogus reply from target: %s"), target_buf
);
10180 remote_get_trace_status (struct trace_status
*ts
)
10182 /* Initialize it just to avoid a GCC false warning. */
10184 /* FIXME we need to get register block size some other way. */
10185 extern int trace_regblock_size
;
10186 volatile struct gdb_exception ex
;
10188 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10190 putpkt ("qTStatus");
10192 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10194 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10198 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10202 /* If the remote target doesn't do tracing, flag it. */
10206 /* We're working with a live target. */
10209 /* Set some defaults. */
10210 ts
->running_known
= 0;
10211 ts
->stop_reason
= trace_stop_reason_unknown
;
10212 ts
->traceframe_count
= -1;
10213 ts
->buffer_free
= 0;
10216 error (_("Bogus trace status reply from target: %s"), target_buf
);
10218 parse_trace_status (p
, ts
);
10220 return ts
->running
;
10224 remote_get_tracepoint_status (struct breakpoint
*bp
,
10225 struct uploaded_tp
*utp
)
10227 struct remote_state
*rs
= get_remote_state ();
10229 struct bp_location
*loc
;
10230 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10234 tp
->base
.hit_count
= 0;
10235 tp
->traceframe_usage
= 0;
10236 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10238 /* If the tracepoint was never downloaded, don't go asking for
10240 if (tp
->number_on_target
== 0)
10242 sprintf (rs
->buf
, "qTP:%x:%s", tp
->number_on_target
,
10243 phex_nz (loc
->address
, 0));
10245 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10246 if (reply
&& *reply
)
10249 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10255 utp
->hit_count
= 0;
10256 utp
->traceframe_usage
= 0;
10257 sprintf (rs
->buf
, "qTP:%x:%s", utp
->number
, phex_nz (utp
->addr
, 0));
10259 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10260 if (reply
&& *reply
)
10263 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10269 remote_trace_stop (void)
10272 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10273 if (*target_buf
== '\0')
10274 error (_("Target does not support this command."));
10275 if (strcmp (target_buf
, "OK") != 0)
10276 error (_("Bogus reply from target: %s"), target_buf
);
10280 remote_trace_find (enum trace_find_type type
, int num
,
10281 ULONGEST addr1
, ULONGEST addr2
,
10284 struct remote_state
*rs
= get_remote_state ();
10286 int target_frameno
= -1, target_tracept
= -1;
10288 /* Lookups other than by absolute frame number depend on the current
10289 trace selected, so make sure it is correct on the remote end
10291 if (type
!= tfind_number
)
10292 set_remote_traceframe ();
10295 strcpy (p
, "QTFrame:");
10296 p
= strchr (p
, '\0');
10300 sprintf (p
, "%x", num
);
10303 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10306 sprintf (p
, "tdp:%x", num
);
10309 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10311 case tfind_outside
:
10312 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10315 error (_("Unknown trace find type %d"), type
);
10319 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10320 if (*reply
== '\0')
10321 error (_("Target does not support this command."));
10323 while (reply
&& *reply
)
10328 target_frameno
= (int) strtol (p
, &reply
, 16);
10330 error (_("Unable to parse trace frame number"));
10331 /* Don't update our remote traceframe number cache on failure
10332 to select a remote traceframe. */
10333 if (target_frameno
== -1)
10338 target_tracept
= (int) strtol (p
, &reply
, 16);
10340 error (_("Unable to parse tracepoint number"));
10342 case 'O': /* "OK"? */
10343 if (reply
[1] == 'K' && reply
[2] == '\0')
10346 error (_("Bogus reply from target: %s"), reply
);
10349 error (_("Bogus reply from target: %s"), reply
);
10352 *tpp
= target_tracept
;
10354 remote_traceframe_number
= target_frameno
;
10355 return target_frameno
;
10359 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10361 struct remote_state
*rs
= get_remote_state ();
10365 set_remote_traceframe ();
10367 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10369 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10370 if (reply
&& *reply
)
10374 unpack_varlen_hex (reply
+ 1, &uval
);
10375 *val
= (LONGEST
) uval
;
10383 remote_save_trace_data (const char *filename
)
10385 struct remote_state
*rs
= get_remote_state ();
10389 strcpy (p
, "QTSave:");
10391 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10392 error (_("Remote file name too long for trace save packet"));
10393 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10396 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10397 if (*reply
== '\0')
10398 error (_("Target does not support this command."));
10399 if (strcmp (reply
, "OK") != 0)
10400 error (_("Bogus reply from target: %s"), reply
);
10404 /* This is basically a memory transfer, but needs to be its own packet
10405 because we don't know how the target actually organizes its trace
10406 memory, plus we want to be able to ask for as much as possible, but
10407 not be unhappy if we don't get as much as we ask for. */
10410 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10412 struct remote_state
*rs
= get_remote_state ();
10418 strcpy (p
, "qTBuffer:");
10420 p
+= hexnumstr (p
, offset
);
10422 p
+= hexnumstr (p
, len
);
10426 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10427 if (reply
&& *reply
)
10429 /* 'l' by itself means we're at the end of the buffer and
10430 there is nothing more to get. */
10434 /* Convert the reply into binary. Limit the number of bytes to
10435 convert according to our passed-in buffer size, rather than
10436 what was returned in the packet; if the target is
10437 unexpectedly generous and gives us a bigger reply than we
10438 asked for, we don't want to crash. */
10439 rslt
= hex2bin (target_buf
, buf
, len
);
10443 /* Something went wrong, flag as an error. */
10448 remote_set_disconnected_tracing (int val
)
10450 struct remote_state
*rs
= get_remote_state ();
10452 if (rs
->disconnected_tracing
)
10456 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10458 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10459 if (*reply
== '\0')
10460 error (_("Target does not support this command."));
10461 if (strcmp (reply
, "OK") != 0)
10462 error (_("Bogus reply from target: %s"), reply
);
10465 warning (_("Target does not support disconnected tracing."));
10469 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10471 struct thread_info
*info
= find_thread_ptid (ptid
);
10473 if (info
&& info
->private)
10474 return info
->private->core
;
10479 remote_set_circular_trace_buffer (int val
)
10481 struct remote_state
*rs
= get_remote_state ();
10484 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10486 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10487 if (*reply
== '\0')
10488 error (_("Target does not support this command."));
10489 if (strcmp (reply
, "OK") != 0)
10490 error (_("Bogus reply from target: %s"), reply
);
10493 static struct traceframe_info
*
10494 remote_traceframe_info (void)
10498 text
= target_read_stralloc (¤t_target
,
10499 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10502 struct traceframe_info
*info
;
10503 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10505 info
= parse_traceframe_info (text
);
10506 do_cleanups (back_to
);
10513 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10514 instruction on which a fast tracepoint may be placed. Returns -1
10515 if the packet is not supported, and 0 if the minimum instruction
10516 length is unknown. */
10519 remote_get_min_fast_tracepoint_insn_len (void)
10521 struct remote_state
*rs
= get_remote_state ();
10524 sprintf (rs
->buf
, "qTMinFTPILen");
10526 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10527 if (*reply
== '\0')
10531 ULONGEST min_insn_len
;
10533 unpack_varlen_hex (reply
, &min_insn_len
);
10535 return (int) min_insn_len
;
10540 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10542 struct remote_state
*rs
= get_remote_state ();
10544 char *buf
= rs
->buf
;
10545 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10548 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10551 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10552 nbytes
= bin2hex (user
, buf
, 0);
10558 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10559 nbytes
= bin2hex (notes
, buf
, 0);
10565 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10566 nbytes
= bin2hex (stop_notes
, buf
, 0);
10570 /* Ensure the buffer is terminated. */
10574 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10575 if (*reply
== '\0')
10578 if (strcmp (reply
, "OK") != 0)
10579 error (_("Bogus reply from target: %s"), reply
);
10585 init_remote_ops (void)
10587 remote_ops
.to_shortname
= "remote";
10588 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10589 remote_ops
.to_doc
=
10590 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10591 Specify the serial device it is connected to\n\
10592 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10593 remote_ops
.to_open
= remote_open
;
10594 remote_ops
.to_close
= remote_close
;
10595 remote_ops
.to_detach
= remote_detach
;
10596 remote_ops
.to_disconnect
= remote_disconnect
;
10597 remote_ops
.to_resume
= remote_resume
;
10598 remote_ops
.to_wait
= remote_wait
;
10599 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10600 remote_ops
.to_store_registers
= remote_store_registers
;
10601 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10602 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10603 remote_ops
.to_files_info
= remote_files_info
;
10604 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10605 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10606 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10607 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10608 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10609 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10610 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10611 remote_ops
.to_region_ok_for_hw_watchpoint
10612 = remote_region_ok_for_hw_watchpoint
;
10613 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10614 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10615 remote_ops
.to_kill
= remote_kill
;
10616 remote_ops
.to_load
= generic_load
;
10617 remote_ops
.to_mourn_inferior
= remote_mourn
;
10618 remote_ops
.to_pass_signals
= remote_pass_signals
;
10619 remote_ops
.to_thread_alive
= remote_thread_alive
;
10620 remote_ops
.to_find_new_threads
= remote_threads_info
;
10621 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10622 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10623 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10624 remote_ops
.to_stop
= remote_stop
;
10625 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10626 remote_ops
.to_rcmd
= remote_rcmd
;
10627 remote_ops
.to_log_command
= serial_log_command
;
10628 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10629 remote_ops
.to_stratum
= process_stratum
;
10630 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10631 remote_ops
.to_has_memory
= default_child_has_memory
;
10632 remote_ops
.to_has_stack
= default_child_has_stack
;
10633 remote_ops
.to_has_registers
= default_child_has_registers
;
10634 remote_ops
.to_has_execution
= default_child_has_execution
;
10635 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10636 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10637 remote_ops
.to_magic
= OPS_MAGIC
;
10638 remote_ops
.to_memory_map
= remote_memory_map
;
10639 remote_ops
.to_flash_erase
= remote_flash_erase
;
10640 remote_ops
.to_flash_done
= remote_flash_done
;
10641 remote_ops
.to_read_description
= remote_read_description
;
10642 remote_ops
.to_search_memory
= remote_search_memory
;
10643 remote_ops
.to_can_async_p
= remote_can_async_p
;
10644 remote_ops
.to_is_async_p
= remote_is_async_p
;
10645 remote_ops
.to_async
= remote_async
;
10646 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10647 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10648 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10649 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10650 remote_ops
.to_supports_disable_randomization
10651 = remote_supports_disable_randomization
;
10652 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10653 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10654 remote_ops
.to_trace_init
= remote_trace_init
;
10655 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10656 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10657 remote_ops
.to_download_trace_state_variable
10658 = remote_download_trace_state_variable
;
10659 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10660 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10661 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10662 remote_ops
.to_trace_start
= remote_trace_start
;
10663 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10664 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
10665 remote_ops
.to_trace_stop
= remote_trace_stop
;
10666 remote_ops
.to_trace_find
= remote_trace_find
;
10667 remote_ops
.to_get_trace_state_variable_value
10668 = remote_get_trace_state_variable_value
;
10669 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10670 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10671 remote_ops
.to_upload_trace_state_variables
10672 = remote_upload_trace_state_variables
;
10673 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10674 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10675 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10676 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10677 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
10678 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10679 remote_ops
.to_verify_memory
= remote_verify_memory
;
10680 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10681 remote_ops
.to_set_permissions
= remote_set_permissions
;
10682 remote_ops
.to_static_tracepoint_marker_at
10683 = remote_static_tracepoint_marker_at
;
10684 remote_ops
.to_static_tracepoint_markers_by_strid
10685 = remote_static_tracepoint_markers_by_strid
;
10686 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10689 /* Set up the extended remote vector by making a copy of the standard
10690 remote vector and adding to it. */
10693 init_extended_remote_ops (void)
10695 extended_remote_ops
= remote_ops
;
10697 extended_remote_ops
.to_shortname
= "extended-remote";
10698 extended_remote_ops
.to_longname
=
10699 "Extended remote serial target in gdb-specific protocol";
10700 extended_remote_ops
.to_doc
=
10701 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10702 Specify the serial device it is connected to (e.g. /dev/ttya).";
10703 extended_remote_ops
.to_open
= extended_remote_open
;
10704 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10705 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10706 extended_remote_ops
.to_detach
= extended_remote_detach
;
10707 extended_remote_ops
.to_attach
= extended_remote_attach
;
10708 extended_remote_ops
.to_kill
= extended_remote_kill
;
10709 extended_remote_ops
.to_supports_disable_randomization
10710 = extended_remote_supports_disable_randomization
;
10714 remote_can_async_p (void)
10716 if (!target_async_permitted
)
10717 /* We only enable async when the user specifically asks for it. */
10720 /* We're async whenever the serial device is. */
10721 return serial_can_async_p (remote_desc
);
10725 remote_is_async_p (void)
10727 if (!target_async_permitted
)
10728 /* We only enable async when the user specifically asks for it. */
10731 /* We're async whenever the serial device is. */
10732 return serial_is_async_p (remote_desc
);
10735 /* Pass the SERIAL event on and up to the client. One day this code
10736 will be able to delay notifying the client of an event until the
10737 point where an entire packet has been received. */
10739 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10741 static void *async_client_context
;
10742 static serial_event_ftype remote_async_serial_handler
;
10745 remote_async_serial_handler (struct serial
*scb
, void *context
)
10747 /* Don't propogate error information up to the client. Instead let
10748 the client find out about the error by querying the target. */
10749 async_client_callback (INF_REG_EVENT
, async_client_context
);
10753 remote_async_inferior_event_handler (gdb_client_data data
)
10755 inferior_event_handler (INF_REG_EVENT
, NULL
);
10759 remote_async_get_pending_events_handler (gdb_client_data data
)
10761 remote_get_pending_stop_replies ();
10765 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10766 void *context
), void *context
)
10768 if (callback
!= NULL
)
10770 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10771 async_client_callback
= callback
;
10772 async_client_context
= context
;
10775 serial_async (remote_desc
, NULL
, NULL
);
10779 set_remote_cmd (char *args
, int from_tty
)
10781 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10785 show_remote_cmd (char *args
, int from_tty
)
10787 /* We can't just use cmd_show_list here, because we want to skip
10788 the redundant "show remote Z-packet" and the legacy aliases. */
10789 struct cleanup
*showlist_chain
;
10790 struct cmd_list_element
*list
= remote_show_cmdlist
;
10791 struct ui_out
*uiout
= current_uiout
;
10793 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10794 for (; list
!= NULL
; list
= list
->next
)
10795 if (strcmp (list
->name
, "Z-packet") == 0)
10797 else if (list
->type
== not_set_cmd
)
10798 /* Alias commands are exactly like the original, except they
10799 don't have the normal type. */
10803 struct cleanup
*option_chain
10804 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10806 ui_out_field_string (uiout
, "name", list
->name
);
10807 ui_out_text (uiout
, ": ");
10808 if (list
->type
== show_cmd
)
10809 do_setshow_command ((char *) NULL
, from_tty
, list
);
10811 cmd_func (list
, NULL
, from_tty
);
10812 /* Close the tuple. */
10813 do_cleanups (option_chain
);
10816 /* Close the tuple. */
10817 do_cleanups (showlist_chain
);
10821 /* Function to be called whenever a new objfile (shlib) is detected. */
10823 remote_new_objfile (struct objfile
*objfile
)
10825 if (remote_desc
!= 0) /* Have a remote connection. */
10826 remote_check_symbols (objfile
);
10829 /* Pull all the tracepoints defined on the target and create local
10830 data structures representing them. We don't want to create real
10831 tracepoints yet, we don't want to mess up the user's existing
10835 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10837 struct remote_state
*rs
= get_remote_state ();
10840 /* Ask for a first packet of tracepoint definition. */
10842 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10844 while (*p
&& *p
!= 'l')
10846 parse_tracepoint_definition (p
, utpp
);
10847 /* Ask for another packet of tracepoint definition. */
10849 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10856 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10858 struct remote_state
*rs
= get_remote_state ();
10861 /* Ask for a first packet of variable definition. */
10863 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10865 while (*p
&& *p
!= 'l')
10867 parse_tsv_definition (p
, utsvp
);
10868 /* Ask for another packet of variable definition. */
10870 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10877 _initialize_remote (void)
10879 struct remote_state
*rs
;
10880 struct cmd_list_element
*cmd
;
10883 /* architecture specific data */
10884 remote_gdbarch_data_handle
=
10885 gdbarch_data_register_post_init (init_remote_state
);
10886 remote_g_packet_data_handle
=
10887 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10889 /* Initialize the per-target state. At the moment there is only one
10890 of these, not one per target. Only one target is active at a
10891 time. The default buffer size is unimportant; it will be expanded
10892 whenever a larger buffer is needed. */
10893 rs
= get_remote_state_raw ();
10894 rs
->buf_size
= 400;
10895 rs
->buf
= xmalloc (rs
->buf_size
);
10897 init_remote_ops ();
10898 add_target (&remote_ops
);
10900 init_extended_remote_ops ();
10901 add_target (&extended_remote_ops
);
10903 /* Hook into new objfile notification. */
10904 observer_attach_new_objfile (remote_new_objfile
);
10906 /* Set up signal handlers. */
10907 sigint_remote_token
=
10908 create_async_signal_handler (async_remote_interrupt
, NULL
);
10909 sigint_remote_twice_token
=
10910 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10913 init_remote_threadtests ();
10916 /* set/show remote ... */
10918 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10919 Remote protocol specific variables\n\
10920 Configure various remote-protocol specific variables such as\n\
10921 the packets being used"),
10922 &remote_set_cmdlist
, "set remote ",
10923 0 /* allow-unknown */, &setlist
);
10924 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10925 Remote protocol specific variables\n\
10926 Configure various remote-protocol specific variables such as\n\
10927 the packets being used"),
10928 &remote_show_cmdlist
, "show remote ",
10929 0 /* allow-unknown */, &showlist
);
10931 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10932 Compare section data on target to the exec file.\n\
10933 Argument is a single section name (default: all loaded sections)."),
10936 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10937 Send an arbitrary packet to a remote target.\n\
10938 maintenance packet TEXT\n\
10939 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10940 this command sends the string TEXT to the inferior, and displays the\n\
10941 response packet. GDB supplies the initial `$' character, and the\n\
10942 terminating `#' character and checksum."),
10945 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10946 Set whether to send break if interrupted."), _("\
10947 Show whether to send break if interrupted."), _("\
10948 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10949 set_remotebreak
, show_remotebreak
,
10950 &setlist
, &showlist
);
10951 cmd_name
= "remotebreak";
10952 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10953 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10954 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10955 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10956 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10958 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10959 interrupt_sequence_modes
, &interrupt_sequence_mode
,
10961 Set interrupt sequence to remote target."), _("\
10962 Show interrupt sequence to remote target."), _("\
10963 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10964 NULL
, show_interrupt_sequence
,
10965 &remote_set_cmdlist
,
10966 &remote_show_cmdlist
);
10968 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10969 &interrupt_on_connect
, _("\
10970 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10971 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10972 If set, interrupt sequence is sent to remote target."),
10974 &remote_set_cmdlist
, &remote_show_cmdlist
);
10976 /* Install commands for configuring memory read/write packets. */
10978 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10979 Set the maximum number of bytes per memory write packet (deprecated)."),
10981 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10982 Show the maximum number of bytes per memory write packet (deprecated)."),
10984 add_cmd ("memory-write-packet-size", no_class
,
10985 set_memory_write_packet_size
, _("\
10986 Set the maximum number of bytes per memory-write packet.\n\
10987 Specify the number of bytes in a packet or 0 (zero) for the\n\
10988 default packet size. The actual limit is further reduced\n\
10989 dependent on the target. Specify ``fixed'' to disable the\n\
10990 further restriction and ``limit'' to enable that restriction."),
10991 &remote_set_cmdlist
);
10992 add_cmd ("memory-read-packet-size", no_class
,
10993 set_memory_read_packet_size
, _("\
10994 Set the maximum number of bytes per memory-read packet.\n\
10995 Specify the number of bytes in a packet or 0 (zero) for the\n\
10996 default packet size. The actual limit is further reduced\n\
10997 dependent on the target. Specify ``fixed'' to disable the\n\
10998 further restriction and ``limit'' to enable that restriction."),
10999 &remote_set_cmdlist
);
11000 add_cmd ("memory-write-packet-size", no_class
,
11001 show_memory_write_packet_size
,
11002 _("Show the maximum number of bytes per memory-write packet."),
11003 &remote_show_cmdlist
);
11004 add_cmd ("memory-read-packet-size", no_class
,
11005 show_memory_read_packet_size
,
11006 _("Show the maximum number of bytes per memory-read packet."),
11007 &remote_show_cmdlist
);
11009 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11010 &remote_hw_watchpoint_limit
, _("\
11011 Set the maximum number of target hardware watchpoints."), _("\
11012 Show the maximum number of target hardware watchpoints."), _("\
11013 Specify a negative limit for unlimited."),
11014 NULL
, NULL
, /* FIXME: i18n: The maximum
11015 number of target hardware
11016 watchpoints is %s. */
11017 &remote_set_cmdlist
, &remote_show_cmdlist
);
11018 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11019 &remote_hw_watchpoint_length_limit
, _("\
11020 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11021 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11022 Specify a negative limit for unlimited."),
11023 NULL
, NULL
, /* FIXME: i18n: The maximum
11024 length (in bytes) of a target
11025 hardware watchpoint is %s. */
11026 &remote_set_cmdlist
, &remote_show_cmdlist
);
11027 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11028 &remote_hw_breakpoint_limit
, _("\
11029 Set the maximum number of target hardware breakpoints."), _("\
11030 Show the maximum number of target hardware breakpoints."), _("\
11031 Specify a negative limit for unlimited."),
11032 NULL
, NULL
, /* FIXME: i18n: The maximum
11033 number of target hardware
11034 breakpoints is %s. */
11035 &remote_set_cmdlist
, &remote_show_cmdlist
);
11037 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
11038 &remote_address_size
, _("\
11039 Set the maximum size of the address (in bits) in a memory packet."), _("\
11040 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11042 NULL
, /* FIXME: i18n: */
11043 &setlist
, &showlist
);
11045 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11046 "X", "binary-download", 1);
11048 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11049 "vCont", "verbose-resume", 0);
11051 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11052 "QPassSignals", "pass-signals", 0);
11054 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11055 "qSymbol", "symbol-lookup", 0);
11057 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11058 "P", "set-register", 1);
11060 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11061 "p", "fetch-register", 1);
11063 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11064 "Z0", "software-breakpoint", 0);
11066 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11067 "Z1", "hardware-breakpoint", 0);
11069 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11070 "Z2", "write-watchpoint", 0);
11072 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11073 "Z3", "read-watchpoint", 0);
11075 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11076 "Z4", "access-watchpoint", 0);
11078 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11079 "qXfer:auxv:read", "read-aux-vector", 0);
11081 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11082 "qXfer:features:read", "target-features", 0);
11084 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11085 "qXfer:libraries:read", "library-info", 0);
11087 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11088 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11090 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11091 "qXfer:memory-map:read", "memory-map", 0);
11093 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11094 "qXfer:spu:read", "read-spu-object", 0);
11096 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11097 "qXfer:spu:write", "write-spu-object", 0);
11099 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11100 "qXfer:osdata:read", "osdata", 0);
11102 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11103 "qXfer:threads:read", "threads", 0);
11105 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11106 "qXfer:siginfo:read", "read-siginfo-object", 0);
11108 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11109 "qXfer:siginfo:write", "write-siginfo-object", 0);
11111 add_packet_config_cmd
11112 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11113 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11115 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11116 "qGetTLSAddr", "get-thread-local-storage-address",
11119 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11120 "qGetTIBAddr", "get-thread-information-block-address",
11123 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11124 "bc", "reverse-continue", 0);
11126 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11127 "bs", "reverse-step", 0);
11129 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11130 "qSupported", "supported-packets", 0);
11132 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11133 "qSearch:memory", "search-memory", 0);
11135 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11136 "vFile:open", "hostio-open", 0);
11138 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11139 "vFile:pread", "hostio-pread", 0);
11141 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11142 "vFile:pwrite", "hostio-pwrite", 0);
11144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11145 "vFile:close", "hostio-close", 0);
11147 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11148 "vFile:unlink", "hostio-unlink", 0);
11150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11151 "vAttach", "attach", 0);
11153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11157 "QStartNoAckMode", "noack", 0);
11159 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11160 "vKill", "kill", 0);
11162 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11163 "qAttached", "query-attached", 0);
11165 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11166 "ConditionalTracepoints",
11167 "conditional-tracepoints", 0);
11168 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11169 "FastTracepoints", "fast-tracepoints", 0);
11171 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11172 "TracepointSource", "TracepointSource", 0);
11174 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11175 "QAllow", "allow", 0);
11177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11178 "StaticTracepoints", "static-tracepoints", 0);
11180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11181 "InstallInTrace", "install-in-trace", 0);
11183 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11184 "qXfer:statictrace:read", "read-sdata-object", 0);
11186 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11187 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11189 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11190 "QDisableRandomization", "disable-randomization", 0);
11192 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11193 Z sub-packet has its own set and show commands, but users may
11194 have sets to this variable in their .gdbinit files (or in their
11196 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11197 &remote_Z_packet_detect
, _("\
11198 Set use of remote protocol `Z' packets"), _("\
11199 Show use of remote protocol `Z' packets "), _("\
11200 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11202 set_remote_protocol_Z_packet_cmd
,
11203 show_remote_protocol_Z_packet_cmd
,
11204 /* FIXME: i18n: Use of remote protocol
11205 `Z' packets is %s. */
11206 &remote_set_cmdlist
, &remote_show_cmdlist
);
11208 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11209 Manipulate files on the remote system\n\
11210 Transfer files to and from the remote target system."),
11211 &remote_cmdlist
, "remote ",
11212 0 /* allow-unknown */, &cmdlist
);
11214 add_cmd ("put", class_files
, remote_put_command
,
11215 _("Copy a local file to the remote system."),
11218 add_cmd ("get", class_files
, remote_get_command
,
11219 _("Copy a remote file to the local system."),
11222 add_cmd ("delete", class_files
, remote_delete_command
,
11223 _("Delete a remote file."),
11226 remote_exec_file
= xstrdup ("");
11227 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11228 &remote_exec_file
, _("\
11229 Set the remote pathname for \"run\""), _("\
11230 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11231 &remote_set_cmdlist
, &remote_show_cmdlist
);
11233 /* Eventually initialize fileio. See fileio.c */
11234 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11236 /* Take advantage of the fact that the LWP field is not used, to tag
11237 special ptids with it set to != 0. */
11238 magic_null_ptid
= ptid_build (42000, 1, -1);
11239 not_sent_ptid
= ptid_build (42000, 1, -2);
11240 any_thread_ptid
= ptid_build (42000, 1, 0);
11242 target_buf_size
= 2048;
11243 target_buf
= xmalloc (target_buf_size
);