1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
23 #include "gdb_string.h"
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
39 #include "gdb_assert.h"
42 #include "cli/cli-decode.h"
43 #include "cli/cli-setshow.h"
44 #include "target-descriptions.h"
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 #include "remote-fileio.h"
59 #include "gdb/fileio.h"
61 #include "xml-support.h"
63 #include "memory-map.h"
65 #include "tracepoint.h"
69 /* Temp hacks for tracepoint encoding migration. */
70 static char *target_buf
;
71 static long target_buf_size
;
73 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
74 char ***tdp_actions
, char ***stepping_actions
);
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void cleanup_sigint_signal_handler (void *dummy
);
90 static void initialize_sigint_signal_handler (void);
91 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
92 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
95 static void handle_remote_sigint (int);
96 static void handle_remote_sigint_twice (int);
97 static void async_remote_interrupt (gdb_client_data
);
98 void async_remote_interrupt_twice (gdb_client_data
);
100 static void remote_files_info (struct target_ops
*ignore
);
102 static void remote_prepare_to_store (struct regcache
*regcache
);
104 static void remote_open (char *name
, int from_tty
);
106 static void extended_remote_open (char *name
, int from_tty
);
108 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
110 static void remote_close (int quitting
);
112 static void remote_mourn (struct target_ops
*ops
);
114 static void extended_remote_restart (void);
116 static void extended_remote_mourn (struct target_ops
*);
118 static void remote_mourn_1 (struct target_ops
*);
120 static void remote_send (char **buf
, long *sizeof_buf_p
);
122 static int readchar (int timeout
);
124 static void remote_kill (struct target_ops
*ops
);
126 static int tohex (int nib
);
128 static int remote_can_async_p (void);
130 static int remote_is_async_p (void);
132 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
133 void *context
), void *context
);
135 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
137 static void remote_interrupt (int signo
);
139 static void remote_interrupt_twice (int signo
);
141 static void interrupt_query (void);
143 static void set_general_thread (struct ptid ptid
);
144 static void set_continue_thread (struct ptid ptid
);
146 static void get_offsets (void);
148 static void skip_frame (void);
150 static long read_frame (char **buf_p
, long *sizeof_buf
);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void remote_stop (ptid_t
);
160 static int ishex (int ch
, int *val
);
162 static int stubhex (int ch
);
164 static int hexnumstr (char *, ULONGEST
);
166 static int hexnumnstr (char *, ULONGEST
, int);
168 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
170 static void print_packet (char *);
172 static void compare_sections_command (char *, int);
174 static void packet_command (char *, int);
176 static int stub_unpack_int (char *buff
, int fieldlength
);
178 static ptid_t
remote_current_thread (ptid_t oldptid
);
180 static void remote_find_new_threads (void);
182 static void record_currthread (ptid_t currthread
);
184 static int fromhex (int a
);
186 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
188 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
190 static int putpkt_binary (char *buf
, int cnt
);
192 static void check_binary_download (CORE_ADDR addr
);
194 struct packet_config
;
196 static void show_packet_config_cmd (struct packet_config
*config
);
198 static void update_packet_config (struct packet_config
*config
);
200 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
201 struct cmd_list_element
*c
);
203 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
205 struct cmd_list_element
*c
,
208 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
209 static ptid_t
read_ptid (char *buf
, char **obuf
);
211 static void remote_set_permissions (void);
214 static int remote_get_trace_status (struct trace_status
*ts
);
216 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
218 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
220 static void remote_query_supported (void);
222 static void remote_check_symbols (struct objfile
*objfile
);
224 void _initialize_remote (void);
227 static struct stop_reply
*stop_reply_xmalloc (void);
228 static void stop_reply_xfree (struct stop_reply
*);
229 static void do_stop_reply_xfree (void *arg
);
230 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
231 static void push_stop_reply (struct stop_reply
*);
232 static void remote_get_pending_stop_replies (void);
233 static void discard_pending_stop_replies (int pid
);
234 static int peek_stop_reply (ptid_t ptid
);
236 static void remote_async_inferior_event_handler (gdb_client_data
);
237 static void remote_async_get_pending_events_handler (gdb_client_data
);
239 static void remote_terminal_ours (void);
241 static int remote_read_description_p (struct target_ops
*target
);
243 static void remote_console_output (char *msg
);
245 /* The non-stop remote protocol provisions for one pending stop reply.
246 This is where we keep it until it is acknowledged. */
248 static struct stop_reply
*pending_stop_reply
= NULL
;
252 static struct cmd_list_element
*remote_cmdlist
;
254 /* For "set remote" and "show remote". */
256 static struct cmd_list_element
*remote_set_cmdlist
;
257 static struct cmd_list_element
*remote_show_cmdlist
;
259 /* Description of the remote protocol state for the currently
260 connected target. This is per-target state, and independent of the
261 selected architecture. */
265 /* A buffer to use for incoming packets, and its current size. The
266 buffer is grown dynamically for larger incoming packets.
267 Outgoing packets may also be constructed in this buffer.
268 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
269 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
274 /* If we negotiated packet size explicitly (and thus can bypass
275 heuristics for the largest packet size that will not overflow
276 a buffer in the stub), this will be set to that packet size.
277 Otherwise zero, meaning to use the guessed size. */
278 long explicit_packet_size
;
280 /* remote_wait is normally called when the target is running and
281 waits for a stop reply packet. But sometimes we need to call it
282 when the target is already stopped. We can send a "?" packet
283 and have remote_wait read the response. Or, if we already have
284 the response, we can stash it in BUF and tell remote_wait to
285 skip calling getpkt. This flag is set when BUF contains a
286 stop reply packet and the target is not waiting. */
287 int cached_wait_status
;
289 /* True, if in no ack mode. That is, neither GDB nor the stub will
290 expect acks from each other. The connection is assumed to be
294 /* True if we're connected in extended remote mode. */
297 /* True if the stub reported support for multi-process
299 int multi_process_aware
;
301 /* True if we resumed the target and we're waiting for the target to
302 stop. In the mean time, we can't start another command/query.
303 The remote server wouldn't be ready to process it, so we'd
304 timeout waiting for a reply that would never come and eventually
305 we'd close the connection. This can happen in asynchronous mode
306 because we allow GDB commands while the target is running. */
307 int waiting_for_stop_reply
;
309 /* True if the stub reports support for non-stop mode. */
312 /* True if the stub reports support for vCont;t. */
315 /* True if the stub reports support for conditional tracepoints. */
316 int cond_tracepoints
;
318 /* True if the stub reports support for fast tracepoints. */
319 int fast_tracepoints
;
321 /* True if the stub reports support for static tracepoints. */
322 int static_tracepoints
;
324 /* True if the stub reports support for installing tracepoint while
326 int install_in_trace
;
328 /* True if the stub can continue running a trace while GDB is
330 int disconnected_tracing
;
332 /* True if the stub reports support for enabling and disabling
333 tracepoints while a trace experiment is running. */
334 int enable_disable_tracepoints
;
336 /* True if the stub can collect strings using tracenz bytecode. */
339 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
340 responded to that. */
344 /* Private data that we'll store in (struct thread_info)->private. */
345 struct private_thread_info
352 free_private_thread_info (struct private_thread_info
*info
)
358 /* Returns true if the multi-process extensions are in effect. */
360 remote_multi_process_p (struct remote_state
*rs
)
362 return rs
->multi_process_aware
;
365 /* This data could be associated with a target, but we do not always
366 have access to the current target when we need it, so for now it is
367 static. This will be fine for as long as only one target is in use
369 static struct remote_state remote_state
;
371 static struct remote_state
*
372 get_remote_state_raw (void)
374 return &remote_state
;
377 /* Description of the remote protocol for a given architecture. */
381 long offset
; /* Offset into G packet. */
382 long regnum
; /* GDB's internal register number. */
383 LONGEST pnum
; /* Remote protocol register number. */
384 int in_g_packet
; /* Always part of G packet. */
385 /* long size in bytes; == register_size (target_gdbarch, regnum);
387 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
391 struct remote_arch_state
393 /* Description of the remote protocol registers. */
394 long sizeof_g_packet
;
396 /* Description of the remote protocol registers indexed by REGNUM
397 (making an array gdbarch_num_regs in size). */
398 struct packet_reg
*regs
;
400 /* This is the size (in chars) of the first response to the ``g''
401 packet. It is used as a heuristic when determining the maximum
402 size of memory-read and memory-write packets. A target will
403 typically only reserve a buffer large enough to hold the ``g''
404 packet. The size does not include packet overhead (headers and
406 long actual_register_packet_size
;
408 /* This is the maximum size (in chars) of a non read/write packet.
409 It is also used as a cap on the size of read/write packets. */
410 long remote_packet_size
;
413 long sizeof_pkt
= 2000;
415 /* Utility: generate error from an incoming stub packet. */
417 trace_error (char *buf
)
420 return; /* not an error msg */
423 case '1': /* malformed packet error */
424 if (*++buf
== '0') /* general case: */
425 error (_("remote.c: error in outgoing packet."));
427 error (_("remote.c: error in outgoing packet at field #%ld."),
428 strtol (buf
, NULL
, 16));
430 error (_("trace API error 0x%s."), ++buf
);
432 error (_("Target returns error code '%s'."), buf
);
436 /* Utility: wait for reply from stub, while accepting "O" packets. */
438 remote_get_noisy_reply (char **buf_p
,
441 do /* Loop on reply from remote stub. */
445 QUIT
; /* Allow user to bail out with ^C. */
446 getpkt (buf_p
, sizeof_buf
, 0);
450 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
453 CORE_ADDR from
, to
, org_to
;
455 int adjusted_size
= 0;
456 volatile struct gdb_exception ex
;
458 p
= buf
+ strlen ("qRelocInsn:");
459 pp
= unpack_varlen_hex (p
, &ul
);
461 error (_("invalid qRelocInsn packet: %s"), buf
);
465 unpack_varlen_hex (p
, &ul
);
470 TRY_CATCH (ex
, RETURN_MASK_ALL
)
472 gdbarch_relocate_instruction (target_gdbarch
, &to
, from
);
476 adjusted_size
= to
- org_to
;
478 sprintf (buf
, "qRelocInsn:%x", adjusted_size
);
481 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
483 /* Propagate memory errors silently back to the target.
484 The stub may have limited the range of addresses we
485 can write to, for example. */
490 /* Something unexpectedly bad happened. Be verbose so
491 we can tell what, and propagate the error back to the
492 stub, so it doesn't get stuck waiting for a
494 exception_fprintf (gdb_stderr
, ex
,
495 _("warning: relocating instruction: "));
499 else if (buf
[0] == 'O' && buf
[1] != 'K')
500 remote_console_output (buf
+ 1); /* 'O' message from stub */
502 return buf
; /* Here's the actual reply. */
507 /* Handle for retreving the remote protocol data from gdbarch. */
508 static struct gdbarch_data
*remote_gdbarch_data_handle
;
510 static struct remote_arch_state
*
511 get_remote_arch_state (void)
513 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
516 /* Fetch the global remote target state. */
518 static struct remote_state
*
519 get_remote_state (void)
521 /* Make sure that the remote architecture state has been
522 initialized, because doing so might reallocate rs->buf. Any
523 function which calls getpkt also needs to be mindful of changes
524 to rs->buf, but this call limits the number of places which run
526 get_remote_arch_state ();
528 return get_remote_state_raw ();
532 compare_pnums (const void *lhs_
, const void *rhs_
)
534 const struct packet_reg
* const *lhs
= lhs_
;
535 const struct packet_reg
* const *rhs
= rhs_
;
537 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
539 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
546 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
548 int regnum
, num_remote_regs
, offset
;
549 struct packet_reg
**remote_regs
;
551 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
553 struct packet_reg
*r
= ®s
[regnum
];
555 if (register_size (gdbarch
, regnum
) == 0)
556 /* Do not try to fetch zero-sized (placeholder) registers. */
559 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
564 /* Define the g/G packet format as the contents of each register
565 with a remote protocol number, in order of ascending protocol
568 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
569 * sizeof (struct packet_reg
*));
570 for (num_remote_regs
= 0, regnum
= 0;
571 regnum
< gdbarch_num_regs (gdbarch
);
573 if (regs
[regnum
].pnum
!= -1)
574 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
576 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
579 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
581 remote_regs
[regnum
]->in_g_packet
= 1;
582 remote_regs
[regnum
]->offset
= offset
;
583 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
589 /* Given the architecture described by GDBARCH, return the remote
590 protocol register's number and the register's offset in the g/G
591 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
592 If the target does not have a mapping for REGNUM, return false,
593 otherwise, return true. */
596 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
597 int *pnum
, int *poffset
)
600 struct packet_reg
*regs
;
601 struct cleanup
*old_chain
;
603 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
605 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
606 old_chain
= make_cleanup (xfree
, regs
);
608 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
610 *pnum
= regs
[regnum
].pnum
;
611 *poffset
= regs
[regnum
].offset
;
613 do_cleanups (old_chain
);
619 init_remote_state (struct gdbarch
*gdbarch
)
621 struct remote_state
*rs
= get_remote_state_raw ();
622 struct remote_arch_state
*rsa
;
624 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
626 /* Use the architecture to build a regnum<->pnum table, which will be
627 1:1 unless a feature set specifies otherwise. */
628 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
629 gdbarch_num_regs (gdbarch
),
632 /* Record the maximum possible size of the g packet - it may turn out
634 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
636 /* Default maximum number of characters in a packet body. Many
637 remote stubs have a hardwired buffer size of 400 bytes
638 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
639 as the maximum packet-size to ensure that the packet and an extra
640 NUL character can always fit in the buffer. This stops GDB
641 trashing stubs that try to squeeze an extra NUL into what is
642 already a full buffer (As of 1999-12-04 that was most stubs). */
643 rsa
->remote_packet_size
= 400 - 1;
645 /* This one is filled in when a ``g'' packet is received. */
646 rsa
->actual_register_packet_size
= 0;
648 /* Should rsa->sizeof_g_packet needs more space than the
649 default, adjust the size accordingly. Remember that each byte is
650 encoded as two characters. 32 is the overhead for the packet
651 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
652 (``$NN:G...#NN'') is a better guess, the below has been padded a
654 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
655 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
657 /* Make sure that the packet buffer is plenty big enough for
658 this architecture. */
659 if (rs
->buf_size
< rsa
->remote_packet_size
)
661 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
662 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
668 /* Return the current allowed size of a remote packet. This is
669 inferred from the current architecture, and should be used to
670 limit the length of outgoing packets. */
672 get_remote_packet_size (void)
674 struct remote_state
*rs
= get_remote_state ();
675 struct remote_arch_state
*rsa
= get_remote_arch_state ();
677 if (rs
->explicit_packet_size
)
678 return rs
->explicit_packet_size
;
680 return rsa
->remote_packet_size
;
683 static struct packet_reg
*
684 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
686 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
690 struct packet_reg
*r
= &rsa
->regs
[regnum
];
692 gdb_assert (r
->regnum
== regnum
);
697 static struct packet_reg
*
698 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
702 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
704 struct packet_reg
*r
= &rsa
->regs
[i
];
712 /* FIXME: graces/2002-08-08: These variables should eventually be
713 bound to an instance of the target object (as in gdbarch-tdep()),
714 when such a thing exists. */
716 /* This is set to the data address of the access causing the target
717 to stop for a watchpoint. */
718 static CORE_ADDR remote_watch_data_address
;
720 /* This is non-zero if target stopped for a watchpoint. */
721 static int remote_stopped_by_watchpoint_p
;
723 static struct target_ops remote_ops
;
725 static struct target_ops extended_remote_ops
;
727 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
728 ``forever'' still use the normal timeout mechanism. This is
729 currently used by the ASYNC code to guarentee that target reads
730 during the initial connect always time-out. Once getpkt has been
731 modified to return a timeout indication and, in turn
732 remote_wait()/wait_for_inferior() have gained a timeout parameter
734 static int wait_forever_enabled_p
= 1;
736 /* Allow the user to specify what sequence to send to the remote
737 when he requests a program interruption: Although ^C is usually
738 what remote systems expect (this is the default, here), it is
739 sometimes preferable to send a break. On other systems such
740 as the Linux kernel, a break followed by g, which is Magic SysRq g
741 is required in order to interrupt the execution. */
742 const char interrupt_sequence_control_c
[] = "Ctrl-C";
743 const char interrupt_sequence_break
[] = "BREAK";
744 const char interrupt_sequence_break_g
[] = "BREAK-g";
745 static const char *interrupt_sequence_modes
[] =
747 interrupt_sequence_control_c
,
748 interrupt_sequence_break
,
749 interrupt_sequence_break_g
,
752 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
755 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
756 struct cmd_list_element
*c
,
759 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
760 fprintf_filtered (file
,
761 _("Send the ASCII ETX character (Ctrl-c) "
762 "to the remote target to interrupt the "
763 "execution of the program.\n"));
764 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
765 fprintf_filtered (file
,
766 _("send a break signal to the remote target "
767 "to interrupt the execution of the program.\n"));
768 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
769 fprintf_filtered (file
,
770 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
771 "the remote target to interrupt the execution "
772 "of Linux kernel.\n"));
774 internal_error (__FILE__
, __LINE__
,
775 _("Invalid value for interrupt_sequence_mode: %s."),
776 interrupt_sequence_mode
);
779 /* This boolean variable specifies whether interrupt_sequence is sent
780 to the remote target when gdb connects to it.
781 This is mostly needed when you debug the Linux kernel: The Linux kernel
782 expects BREAK g which is Magic SysRq g for connecting gdb. */
783 static int interrupt_on_connect
= 0;
785 /* This variable is used to implement the "set/show remotebreak" commands.
786 Since these commands are now deprecated in favor of "set/show remote
787 interrupt-sequence", it no longer has any effect on the code. */
788 static int remote_break
;
791 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
794 interrupt_sequence_mode
= interrupt_sequence_break
;
796 interrupt_sequence_mode
= interrupt_sequence_control_c
;
800 show_remotebreak (struct ui_file
*file
, int from_tty
,
801 struct cmd_list_element
*c
,
806 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
807 remote_open knows that we don't have a file open when the program
809 static struct serial
*remote_desc
= NULL
;
811 /* This variable sets the number of bits in an address that are to be
812 sent in a memory ("M" or "m") packet. Normally, after stripping
813 leading zeros, the entire address would be sent. This variable
814 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
815 initial implementation of remote.c restricted the address sent in
816 memory packets to ``host::sizeof long'' bytes - (typically 32
817 bits). Consequently, for 64 bit targets, the upper 32 bits of an
818 address was never sent. Since fixing this bug may cause a break in
819 some remote targets this variable is principly provided to
820 facilitate backward compatibility. */
822 static int remote_address_size
;
824 /* Temporary to track who currently owns the terminal. See
825 remote_terminal_* for more details. */
827 static int remote_async_terminal_ours_p
;
829 /* The executable file to use for "run" on the remote side. */
831 static char *remote_exec_file
= "";
834 /* User configurable variables for the number of characters in a
835 memory read/write packet. MIN (rsa->remote_packet_size,
836 rsa->sizeof_g_packet) is the default. Some targets need smaller
837 values (fifo overruns, et.al.) and some users need larger values
838 (speed up transfers). The variables ``preferred_*'' (the user
839 request), ``current_*'' (what was actually set) and ``forced_*''
840 (Positive - a soft limit, negative - a hard limit). */
842 struct memory_packet_config
849 /* Compute the current size of a read/write packet. Since this makes
850 use of ``actual_register_packet_size'' the computation is dynamic. */
853 get_memory_packet_size (struct memory_packet_config
*config
)
855 struct remote_state
*rs
= get_remote_state ();
856 struct remote_arch_state
*rsa
= get_remote_arch_state ();
858 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
859 law?) that some hosts don't cope very well with large alloca()
860 calls. Eventually the alloca() code will be replaced by calls to
861 xmalloc() and make_cleanups() allowing this restriction to either
862 be lifted or removed. */
863 #ifndef MAX_REMOTE_PACKET_SIZE
864 #define MAX_REMOTE_PACKET_SIZE 16384
866 /* NOTE: 20 ensures we can write at least one byte. */
867 #ifndef MIN_REMOTE_PACKET_SIZE
868 #define MIN_REMOTE_PACKET_SIZE 20
873 if (config
->size
<= 0)
874 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
876 what_they_get
= config
->size
;
880 what_they_get
= get_remote_packet_size ();
881 /* Limit the packet to the size specified by the user. */
883 && what_they_get
> config
->size
)
884 what_they_get
= config
->size
;
886 /* Limit it to the size of the targets ``g'' response unless we have
887 permission from the stub to use a larger packet size. */
888 if (rs
->explicit_packet_size
== 0
889 && rsa
->actual_register_packet_size
> 0
890 && what_they_get
> rsa
->actual_register_packet_size
)
891 what_they_get
= rsa
->actual_register_packet_size
;
893 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
894 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
895 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
896 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
898 /* Make sure there is room in the global buffer for this packet
899 (including its trailing NUL byte). */
900 if (rs
->buf_size
< what_they_get
+ 1)
902 rs
->buf_size
= 2 * what_they_get
;
903 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
906 return what_they_get
;
909 /* Update the size of a read/write packet. If they user wants
910 something really big then do a sanity check. */
913 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
915 int fixed_p
= config
->fixed_p
;
916 long size
= config
->size
;
919 error (_("Argument required (integer, `fixed' or `limited')."));
920 else if (strcmp (args
, "hard") == 0
921 || strcmp (args
, "fixed") == 0)
923 else if (strcmp (args
, "soft") == 0
924 || strcmp (args
, "limit") == 0)
930 size
= strtoul (args
, &end
, 0);
932 error (_("Invalid %s (bad syntax)."), config
->name
);
934 /* Instead of explicitly capping the size of a packet to
935 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
936 instead allowed to set the size to something arbitrarily
938 if (size
> MAX_REMOTE_PACKET_SIZE
)
939 error (_("Invalid %s (too large)."), config
->name
);
943 if (fixed_p
&& !config
->fixed_p
)
945 if (! query (_("The target may not be able to correctly handle a %s\n"
946 "of %ld bytes. Change the packet size? "),
948 error (_("Packet size not changed."));
950 /* Update the config. */
951 config
->fixed_p
= fixed_p
;
956 show_memory_packet_size (struct memory_packet_config
*config
)
958 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
960 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
961 get_memory_packet_size (config
));
963 printf_filtered (_("Packets are limited to %ld bytes.\n"),
964 get_memory_packet_size (config
));
967 static struct memory_packet_config memory_write_packet_config
=
969 "memory-write-packet-size",
973 set_memory_write_packet_size (char *args
, int from_tty
)
975 set_memory_packet_size (args
, &memory_write_packet_config
);
979 show_memory_write_packet_size (char *args
, int from_tty
)
981 show_memory_packet_size (&memory_write_packet_config
);
985 get_memory_write_packet_size (void)
987 return get_memory_packet_size (&memory_write_packet_config
);
990 static struct memory_packet_config memory_read_packet_config
=
992 "memory-read-packet-size",
996 set_memory_read_packet_size (char *args
, int from_tty
)
998 set_memory_packet_size (args
, &memory_read_packet_config
);
1002 show_memory_read_packet_size (char *args
, int from_tty
)
1004 show_memory_packet_size (&memory_read_packet_config
);
1008 get_memory_read_packet_size (void)
1010 long size
= get_memory_packet_size (&memory_read_packet_config
);
1012 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1013 extra buffer size argument before the memory read size can be
1014 increased beyond this. */
1015 if (size
> get_remote_packet_size ())
1016 size
= get_remote_packet_size ();
1021 /* Generic configuration support for packets the stub optionally
1022 supports. Allows the user to specify the use of the packet as well
1023 as allowing GDB to auto-detect support in the remote stub. */
1027 PACKET_SUPPORT_UNKNOWN
= 0,
1032 struct packet_config
1036 enum auto_boolean detect
;
1037 enum packet_support support
;
1040 /* Analyze a packet's return value and update the packet config
1051 update_packet_config (struct packet_config
*config
)
1053 switch (config
->detect
)
1055 case AUTO_BOOLEAN_TRUE
:
1056 config
->support
= PACKET_ENABLE
;
1058 case AUTO_BOOLEAN_FALSE
:
1059 config
->support
= PACKET_DISABLE
;
1061 case AUTO_BOOLEAN_AUTO
:
1062 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1068 show_packet_config_cmd (struct packet_config
*config
)
1070 char *support
= "internal-error";
1072 switch (config
->support
)
1075 support
= "enabled";
1077 case PACKET_DISABLE
:
1078 support
= "disabled";
1080 case PACKET_SUPPORT_UNKNOWN
:
1081 support
= "unknown";
1084 switch (config
->detect
)
1086 case AUTO_BOOLEAN_AUTO
:
1087 printf_filtered (_("Support for the `%s' packet "
1088 "is auto-detected, currently %s.\n"),
1089 config
->name
, support
);
1091 case AUTO_BOOLEAN_TRUE
:
1092 case AUTO_BOOLEAN_FALSE
:
1093 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1094 config
->name
, support
);
1100 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1101 const char *title
, int legacy
)
1107 config
->name
= name
;
1108 config
->title
= title
;
1109 config
->detect
= AUTO_BOOLEAN_AUTO
;
1110 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1111 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1113 show_doc
= xstrprintf ("Show current use of remote "
1114 "protocol `%s' (%s) packet",
1116 /* set/show TITLE-packet {auto,on,off} */
1117 cmd_name
= xstrprintf ("%s-packet", title
);
1118 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1119 &config
->detect
, set_doc
,
1120 show_doc
, NULL
, /* help_doc */
1121 set_remote_protocol_packet_cmd
,
1122 show_remote_protocol_packet_cmd
,
1123 &remote_set_cmdlist
, &remote_show_cmdlist
);
1124 /* The command code copies the documentation strings. */
1127 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1132 legacy_name
= xstrprintf ("%s-packet", name
);
1133 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1134 &remote_set_cmdlist
);
1135 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1136 &remote_show_cmdlist
);
1140 static enum packet_result
1141 packet_check_result (const char *buf
)
1145 /* The stub recognized the packet request. Check that the
1146 operation succeeded. */
1148 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1150 /* "Enn" - definitly an error. */
1151 return PACKET_ERROR
;
1153 /* Always treat "E." as an error. This will be used for
1154 more verbose error messages, such as E.memtypes. */
1155 if (buf
[0] == 'E' && buf
[1] == '.')
1156 return PACKET_ERROR
;
1158 /* The packet may or may not be OK. Just assume it is. */
1162 /* The stub does not support the packet. */
1163 return PACKET_UNKNOWN
;
1166 static enum packet_result
1167 packet_ok (const char *buf
, struct packet_config
*config
)
1169 enum packet_result result
;
1171 result
= packet_check_result (buf
);
1176 /* The stub recognized the packet request. */
1177 switch (config
->support
)
1179 case PACKET_SUPPORT_UNKNOWN
:
1181 fprintf_unfiltered (gdb_stdlog
,
1182 "Packet %s (%s) is supported\n",
1183 config
->name
, config
->title
);
1184 config
->support
= PACKET_ENABLE
;
1186 case PACKET_DISABLE
:
1187 internal_error (__FILE__
, __LINE__
,
1188 _("packet_ok: attempt to use a disabled packet"));
1194 case PACKET_UNKNOWN
:
1195 /* The stub does not support the packet. */
1196 switch (config
->support
)
1199 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1200 /* If the stub previously indicated that the packet was
1201 supported then there is a protocol error.. */
1202 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1203 config
->name
, config
->title
);
1205 /* The user set it wrong. */
1206 error (_("Enabled packet %s (%s) not recognized by stub"),
1207 config
->name
, config
->title
);
1209 case PACKET_SUPPORT_UNKNOWN
:
1211 fprintf_unfiltered (gdb_stdlog
,
1212 "Packet %s (%s) is NOT supported\n",
1213 config
->name
, config
->title
);
1214 config
->support
= PACKET_DISABLE
;
1216 case PACKET_DISABLE
:
1238 PACKET_vFile_pwrite
,
1240 PACKET_vFile_unlink
,
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 (!rs
->extended
|| !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);
3258 struct inferior
*inf
;
3260 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3263 error (_("The target is not running (try extended-remote?)"));
3265 /* We're connected, but not running. Drop out before we
3266 call start_remote. */
3271 /* Save the reply for later. */
3272 wait_status
= alloca (strlen (rs
->buf
) + 1);
3273 strcpy (wait_status
, rs
->buf
);
3276 /* Let the stub know that we want it to return the thread. */
3277 set_continue_thread (minus_one_ptid
);
3279 inferior_ptid
= minus_one_ptid
;
3281 /* Now, if we have thread information, update inferior_ptid. */
3282 ptid
= remote_current_thread (inferior_ptid
);
3283 if (!ptid_equal (ptid
, minus_one_ptid
))
3285 if (ptid_get_pid (ptid
) == -1)
3287 ptid
= ptid_build (ptid_get_pid (magic_null_ptid
),
3288 ptid_get_lwp (ptid
),
3289 ptid_get_tid (ptid
));
3293 inferior_ptid
= ptid
;
3297 /* Without this, some commands which require an active
3298 target (such as kill) won't work. This variable serves
3299 (at least) double duty as both the pid of the target
3300 process (if it has such), and as a flag indicating that a
3301 target is active. These functions should be split out
3302 into seperate variables, especially since GDB will
3303 someday have a notion of debugging several processes. */
3304 inferior_ptid
= magic_null_ptid
;
3308 inf
= remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3309 inf
->fake_pid_p
= fake_pid_p
;
3311 /* Always add the main thread. */
3312 add_thread_silent (inferior_ptid
);
3314 /* init_wait_for_inferior should be called before get_offsets in order
3315 to manage `inserted' flag in bp loc in a correct state.
3316 breakpoint_init_inferior, called from init_wait_for_inferior, set
3317 `inserted' flag to 0, while before breakpoint_re_set, called from
3318 start_remote, set `inserted' flag to 1. In the initialization of
3319 inferior, breakpoint_init_inferior should be called first, and then
3320 breakpoint_re_set can be called. If this order is broken, state of
3321 `inserted' flag is wrong, and cause some problems on breakpoint
3323 init_wait_for_inferior ();
3325 get_offsets (); /* Get text, data & bss offsets. */
3327 /* If we could not find a description using qXfer, and we know
3328 how to do it some other way, try again. This is not
3329 supported for non-stop; it could be, but it is tricky if
3330 there are no stopped threads when we connect. */
3331 if (remote_read_description_p (target
)
3332 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3334 target_clear_description ();
3335 target_find_description ();
3338 /* Use the previously fetched status. */
3339 gdb_assert (wait_status
!= NULL
);
3340 strcpy (rs
->buf
, wait_status
);
3341 rs
->cached_wait_status
= 1;
3344 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3348 /* Clear WFI global state. Do this before finding about new
3349 threads and inferiors, and setting the current inferior.
3350 Otherwise we would clear the proceed status of the current
3351 inferior when we want its stop_soon state to be preserved
3352 (see notice_new_inferior). */
3353 init_wait_for_inferior ();
3355 /* In non-stop, we will either get an "OK", meaning that there
3356 are no stopped threads at this time; or, a regular stop
3357 reply. In the latter case, there may be more than one thread
3358 stopped --- we pull them all out using the vStopped
3360 if (strcmp (rs
->buf
, "OK") != 0)
3362 struct stop_reply
*stop_reply
;
3363 struct cleanup
*old_chain
;
3365 stop_reply
= stop_reply_xmalloc ();
3366 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3368 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3369 discard_cleanups (old_chain
);
3371 /* get_pending_stop_replies acks this one, and gets the rest
3373 pending_stop_reply
= stop_reply
;
3374 remote_get_pending_stop_replies ();
3376 /* Make sure that threads that were stopped remain
3378 iterate_over_threads (set_stop_requested_callback
, NULL
);
3381 if (target_can_async_p ())
3382 target_async (inferior_event_handler
, 0);
3384 if (thread_count () == 0)
3387 error (_("The target is not running (try extended-remote?)"));
3389 /* We're connected, but not running. Drop out before we
3390 call start_remote. */
3394 /* Let the stub know that we want it to return the thread. */
3396 /* Force the stub to choose a thread. */
3397 set_general_thread (null_ptid
);
3400 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3401 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3402 error (_("remote didn't report the current thread in non-stop mode"));
3404 get_offsets (); /* Get text, data & bss offsets. */
3406 /* In non-stop mode, any cached wait status will be stored in
3407 the stop reply queue. */
3408 gdb_assert (wait_status
== NULL
);
3410 /* Report all signals during attach/startup. */
3411 remote_pass_signals (0, NULL
);
3414 /* If we connected to a live target, do some additional setup. */
3415 if (target_has_execution
)
3417 if (exec_bfd
) /* No use without an exec file. */
3418 remote_check_symbols (symfile_objfile
);
3421 /* Possibly the target has been engaged in a trace run started
3422 previously; find out where things are at. */
3423 if (remote_get_trace_status (current_trace_status ()) != -1)
3425 struct uploaded_tp
*uploaded_tps
= NULL
;
3426 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3428 if (current_trace_status ()->running
)
3429 printf_filtered (_("Trace is already running on the target.\n"));
3431 /* Get trace state variables first, they may be checked when
3432 parsing uploaded commands. */
3434 remote_upload_trace_state_variables (&uploaded_tsvs
);
3436 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3438 remote_upload_tracepoints (&uploaded_tps
);
3440 merge_uploaded_tracepoints (&uploaded_tps
);
3443 /* If breakpoints are global, insert them now. */
3444 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3445 && breakpoints_always_inserted_mode ())
3446 insert_breakpoints ();
3449 /* Open a connection to a remote debugger.
3450 NAME is the filename used for communication. */
3453 remote_open (char *name
, int from_tty
)
3455 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3458 /* Open a connection to a remote debugger using the extended
3459 remote gdb protocol. NAME is the filename used for communication. */
3462 extended_remote_open (char *name
, int from_tty
)
3464 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3467 /* Generic code for opening a connection to a remote target. */
3470 init_all_packet_configs (void)
3474 for (i
= 0; i
< PACKET_MAX
; i
++)
3475 update_packet_config (&remote_protocol_packets
[i
]);
3478 /* Symbol look-up. */
3481 remote_check_symbols (struct objfile
*objfile
)
3483 struct remote_state
*rs
= get_remote_state ();
3484 char *msg
, *reply
, *tmp
;
3485 struct minimal_symbol
*sym
;
3488 /* The remote side has no concept of inferiors that aren't running
3489 yet, it only knows about running processes. If we're connected
3490 but our current inferior is not running, we should not invite the
3491 remote target to request symbol lookups related to its
3492 (unrelated) current process. */
3493 if (!target_has_execution
)
3496 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3499 /* Make sure the remote is pointing at the right process. Note
3500 there's no way to select "no process". */
3501 set_general_process ();
3503 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3504 because we need both at the same time. */
3505 msg
= alloca (get_remote_packet_size ());
3507 /* Invite target to request symbol lookups. */
3509 putpkt ("qSymbol::");
3510 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3511 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3514 while (strncmp (reply
, "qSymbol:", 8) == 0)
3517 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3519 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3521 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3524 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3525 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3527 /* If this is a function address, return the start of code
3528 instead of any data function descriptor. */
3529 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3533 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3534 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3538 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3543 static struct serial
*
3544 remote_serial_open (char *name
)
3546 static int udp_warning
= 0;
3548 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3549 of in ser-tcp.c, because it is the remote protocol assuming that the
3550 serial connection is reliable and not the serial connection promising
3552 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3554 warning (_("The remote protocol may be unreliable over UDP.\n"
3555 "Some events may be lost, rendering further debugging "
3560 return serial_open (name
);
3563 /* Inform the target of our permission settings. The permission flags
3564 work without this, but if the target knows the settings, it can do
3565 a couple things. First, it can add its own check, to catch cases
3566 that somehow manage to get by the permissions checks in target
3567 methods. Second, if the target is wired to disallow particular
3568 settings (for instance, a system in the field that is not set up to
3569 be able to stop at a breakpoint), it can object to any unavailable
3573 remote_set_permissions (void)
3575 struct remote_state
*rs
= get_remote_state ();
3577 sprintf (rs
->buf
, "QAllow:"
3578 "WriteReg:%x;WriteMem:%x;"
3579 "InsertBreak:%x;InsertTrace:%x;"
3580 "InsertFastTrace:%x;Stop:%x",
3581 may_write_registers
, may_write_memory
,
3582 may_insert_breakpoints
, may_insert_tracepoints
,
3583 may_insert_fast_tracepoints
, may_stop
);
3585 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3587 /* If the target didn't like the packet, warn the user. Do not try
3588 to undo the user's settings, that would just be maddening. */
3589 if (strcmp (rs
->buf
, "OK") != 0)
3590 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3593 /* This type describes each known response to the qSupported
3595 struct protocol_feature
3597 /* The name of this protocol feature. */
3600 /* The default for this protocol feature. */
3601 enum packet_support default_support
;
3603 /* The function to call when this feature is reported, or after
3604 qSupported processing if the feature is not supported.
3605 The first argument points to this structure. The second
3606 argument indicates whether the packet requested support be
3607 enabled, disabled, or probed (or the default, if this function
3608 is being called at the end of processing and this feature was
3609 not reported). The third argument may be NULL; if not NULL, it
3610 is a NUL-terminated string taken from the packet following
3611 this feature's name and an equals sign. */
3612 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3615 /* The corresponding packet for this feature. Only used if
3616 FUNC is remote_supported_packet. */
3621 remote_supported_packet (const struct protocol_feature
*feature
,
3622 enum packet_support support
,
3623 const char *argument
)
3627 warning (_("Remote qSupported response supplied an unexpected value for"
3628 " \"%s\"."), feature
->name
);
3632 if (remote_protocol_packets
[feature
->packet
].support
3633 == PACKET_SUPPORT_UNKNOWN
)
3634 remote_protocol_packets
[feature
->packet
].support
= support
;
3638 remote_packet_size (const struct protocol_feature
*feature
,
3639 enum packet_support support
, const char *value
)
3641 struct remote_state
*rs
= get_remote_state ();
3646 if (support
!= PACKET_ENABLE
)
3649 if (value
== NULL
|| *value
== '\0')
3651 warning (_("Remote target reported \"%s\" without a size."),
3657 packet_size
= strtol (value
, &value_end
, 16);
3658 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3660 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3661 feature
->name
, value
);
3665 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3667 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3668 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3669 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3672 /* Record the new maximum packet size. */
3673 rs
->explicit_packet_size
= packet_size
;
3677 remote_multi_process_feature (const struct protocol_feature
*feature
,
3678 enum packet_support support
, const char *value
)
3680 struct remote_state
*rs
= get_remote_state ();
3682 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3686 remote_non_stop_feature (const struct protocol_feature
*feature
,
3687 enum packet_support support
, const char *value
)
3689 struct remote_state
*rs
= get_remote_state ();
3691 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3695 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3696 enum packet_support support
,
3699 struct remote_state
*rs
= get_remote_state ();
3701 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3705 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3706 enum packet_support support
,
3709 struct remote_state
*rs
= get_remote_state ();
3711 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3715 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3716 enum packet_support support
,
3719 struct remote_state
*rs
= get_remote_state ();
3721 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3725 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3726 enum packet_support support
,
3729 struct remote_state
*rs
= get_remote_state ();
3731 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3735 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3736 enum packet_support support
,
3739 struct remote_state
*rs
= get_remote_state ();
3741 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3745 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3746 enum packet_support support
,
3749 struct remote_state
*rs
= get_remote_state ();
3751 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3755 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3756 enum packet_support support
,
3759 struct remote_state
*rs
= get_remote_state ();
3761 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3764 static struct protocol_feature remote_protocol_features
[] = {
3765 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3766 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3767 PACKET_qXfer_auxv
},
3768 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3769 PACKET_qXfer_features
},
3770 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3771 PACKET_qXfer_libraries
},
3772 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3773 PACKET_qXfer_libraries_svr4
},
3774 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3775 PACKET_qXfer_memory_map
},
3776 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3777 PACKET_qXfer_spu_read
},
3778 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3779 PACKET_qXfer_spu_write
},
3780 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3781 PACKET_qXfer_osdata
},
3782 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3783 PACKET_qXfer_threads
},
3784 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3785 PACKET_qXfer_traceframe_info
},
3786 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3787 PACKET_QPassSignals
},
3788 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3789 PACKET_QStartNoAckMode
},
3790 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3791 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3792 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3793 PACKET_qXfer_siginfo_read
},
3794 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3795 PACKET_qXfer_siginfo_write
},
3796 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3797 PACKET_ConditionalTracepoints
},
3798 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3799 PACKET_FastTracepoints
},
3800 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3801 PACKET_StaticTracepoints
},
3802 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3803 PACKET_InstallInTrace
},
3804 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3806 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3808 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3810 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3811 PACKET_TracepointSource
},
3812 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3814 { "EnableDisableTracepoints", PACKET_DISABLE
,
3815 remote_enable_disable_tracepoint_feature
, -1 },
3816 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3817 PACKET_qXfer_fdpic
},
3818 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3819 PACKET_QDisableRandomization
},
3820 { "tracenz", PACKET_DISABLE
,
3821 remote_string_tracing_feature
, -1 },
3824 static char *remote_support_xml
;
3826 /* Register string appended to "xmlRegisters=" in qSupported query. */
3829 register_remote_support_xml (const char *xml
)
3831 #if defined(HAVE_LIBEXPAT)
3832 if (remote_support_xml
== NULL
)
3833 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3836 char *copy
= xstrdup (remote_support_xml
+ 13);
3837 char *p
= strtok (copy
, ",");
3841 if (strcmp (p
, xml
) == 0)
3848 while ((p
= strtok (NULL
, ",")) != NULL
);
3851 remote_support_xml
= reconcat (remote_support_xml
,
3852 remote_support_xml
, ",", xml
,
3859 remote_query_supported_append (char *msg
, const char *append
)
3862 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3864 return xstrdup (append
);
3868 remote_query_supported (void)
3870 struct remote_state
*rs
= get_remote_state ();
3873 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3875 /* The packet support flags are handled differently for this packet
3876 than for most others. We treat an error, a disabled packet, and
3877 an empty response identically: any features which must be reported
3878 to be used will be automatically disabled. An empty buffer
3879 accomplishes this, since that is also the representation for a list
3880 containing no features. */
3883 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3886 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3888 q
= remote_query_supported_append (q
, "multiprocess+");
3890 if (remote_support_xml
)
3891 q
= remote_query_supported_append (q
, remote_support_xml
);
3893 q
= remote_query_supported_append (q
, "qRelocInsn+");
3895 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3898 do_cleanups (old_chain
);
3900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3902 /* If an error occured, warn, but do not return - just reset the
3903 buffer to empty and go on to disable features. */
3904 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3907 warning (_("Remote failure reply: %s"), rs
->buf
);
3912 memset (seen
, 0, sizeof (seen
));
3917 enum packet_support is_supported
;
3918 char *p
, *end
, *name_end
, *value
;
3920 /* First separate out this item from the rest of the packet. If
3921 there's another item after this, we overwrite the separator
3922 (terminated strings are much easier to work with). */
3924 end
= strchr (p
, ';');
3927 end
= p
+ strlen (p
);
3937 warning (_("empty item in \"qSupported\" response"));
3942 name_end
= strchr (p
, '=');
3945 /* This is a name=value entry. */
3946 is_supported
= PACKET_ENABLE
;
3947 value
= name_end
+ 1;
3956 is_supported
= PACKET_ENABLE
;
3960 is_supported
= PACKET_DISABLE
;
3964 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3968 warning (_("unrecognized item \"%s\" "
3969 "in \"qSupported\" response"), p
);
3975 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3976 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3978 const struct protocol_feature
*feature
;
3981 feature
= &remote_protocol_features
[i
];
3982 feature
->func (feature
, is_supported
, value
);
3987 /* If we increased the packet size, make sure to increase the global
3988 buffer size also. We delay this until after parsing the entire
3989 qSupported packet, because this is the same buffer we were
3991 if (rs
->buf_size
< rs
->explicit_packet_size
)
3993 rs
->buf_size
= rs
->explicit_packet_size
;
3994 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3997 /* Handle the defaults for unmentioned features. */
3998 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4001 const struct protocol_feature
*feature
;
4003 feature
= &remote_protocol_features
[i
];
4004 feature
->func (feature
, feature
->default_support
, NULL
);
4010 remote_open_1 (char *name
, int from_tty
,
4011 struct target_ops
*target
, int extended_p
)
4013 struct remote_state
*rs
= get_remote_state ();
4016 error (_("To open a remote debug connection, you need to specify what\n"
4017 "serial device is attached to the remote system\n"
4018 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4020 /* See FIXME above. */
4021 if (!target_async_permitted
)
4022 wait_forever_enabled_p
= 1;
4024 /* If we're connected to a running target, target_preopen will kill it.
4025 But if we're connected to a target system with no running process,
4026 then we will still be connected when it returns. Ask this question
4027 first, before target_preopen has a chance to kill anything. */
4028 if (remote_desc
!= NULL
&& !have_inferiors ())
4031 || query (_("Already connected to a remote target. Disconnect? ")))
4034 error (_("Still connected."));
4037 target_preopen (from_tty
);
4039 unpush_target (target
);
4041 /* This time without a query. If we were connected to an
4042 extended-remote target and target_preopen killed the running
4043 process, we may still be connected. If we are starting "target
4044 remote" now, the extended-remote target will not have been
4045 removed by unpush_target. */
4046 if (remote_desc
!= NULL
&& !have_inferiors ())
4049 /* Make sure we send the passed signals list the next time we resume. */
4050 xfree (last_pass_packet
);
4051 last_pass_packet
= NULL
;
4053 remote_fileio_reset ();
4054 reopen_exec_file ();
4057 remote_desc
= remote_serial_open (name
);
4059 perror_with_name (name
);
4061 if (baud_rate
!= -1)
4063 if (serial_setbaudrate (remote_desc
, baud_rate
))
4065 /* The requested speed could not be set. Error out to
4066 top level after closing remote_desc. Take care to
4067 set remote_desc to NULL to avoid closing remote_desc
4069 serial_close (remote_desc
);
4071 perror_with_name (name
);
4075 serial_raw (remote_desc
);
4077 /* If there is something sitting in the buffer we might take it as a
4078 response to a command, which would be bad. */
4079 serial_flush_input (remote_desc
);
4083 puts_filtered ("Remote debugging using ");
4084 puts_filtered (name
);
4085 puts_filtered ("\n");
4087 push_target (target
); /* Switch to using remote target now. */
4089 /* Register extra event sources in the event loop. */
4090 remote_async_inferior_event_token
4091 = create_async_event_handler (remote_async_inferior_event_handler
,
4093 remote_async_get_pending_events_token
4094 = create_async_event_handler (remote_async_get_pending_events_handler
,
4097 /* Reset the target state; these things will be queried either by
4098 remote_query_supported or as they are needed. */
4099 init_all_packet_configs ();
4100 rs
->cached_wait_status
= 0;
4101 rs
->explicit_packet_size
= 0;
4103 rs
->multi_process_aware
= 0;
4104 rs
->extended
= extended_p
;
4105 rs
->non_stop_aware
= 0;
4106 rs
->waiting_for_stop_reply
= 0;
4107 rs
->ctrlc_pending_p
= 0;
4109 general_thread
= not_sent_ptid
;
4110 continue_thread
= not_sent_ptid
;
4111 remote_traceframe_number
= -1;
4113 /* Probe for ability to use "ThreadInfo" query, as required. */
4114 use_threadinfo_query
= 1;
4115 use_threadextra_query
= 1;
4117 if (target_async_permitted
)
4119 /* With this target we start out by owning the terminal. */
4120 remote_async_terminal_ours_p
= 1;
4122 /* FIXME: cagney/1999-09-23: During the initial connection it is
4123 assumed that the target is already ready and able to respond to
4124 requests. Unfortunately remote_start_remote() eventually calls
4125 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4126 around this. Eventually a mechanism that allows
4127 wait_for_inferior() to expect/get timeouts will be
4129 wait_forever_enabled_p
= 0;
4132 /* First delete any symbols previously loaded from shared libraries. */
4133 no_shared_libraries (NULL
, 0);
4136 init_thread_list ();
4138 /* Start the remote connection. If error() or QUIT, discard this
4139 target (we'd otherwise be in an inconsistent state) and then
4140 propogate the error on up the exception chain. This ensures that
4141 the caller doesn't stumble along blindly assuming that the
4142 function succeeded. The CLI doesn't have this problem but other
4143 UI's, such as MI do.
4145 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4146 this function should return an error indication letting the
4147 caller restore the previous state. Unfortunately the command
4148 ``target remote'' is directly wired to this function making that
4149 impossible. On a positive note, the CLI side of this problem has
4150 been fixed - the function set_cmd_context() makes it possible for
4151 all the ``target ....'' commands to share a common callback
4152 function. See cli-dump.c. */
4154 volatile struct gdb_exception ex
;
4156 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4158 remote_start_remote (from_tty
, target
, extended_p
);
4162 /* Pop the partially set up target - unless something else did
4163 already before throwing the exception. */
4164 if (remote_desc
!= NULL
)
4166 if (target_async_permitted
)
4167 wait_forever_enabled_p
= 1;
4168 throw_exception (ex
);
4172 if (target_async_permitted
)
4173 wait_forever_enabled_p
= 1;
4176 /* This takes a program previously attached to and detaches it. After
4177 this is done, GDB can be used to debug some other program. We
4178 better not have left any breakpoints in the target program or it'll
4179 die when it hits one. */
4182 remote_detach_1 (char *args
, int from_tty
, int extended
)
4184 int pid
= ptid_get_pid (inferior_ptid
);
4185 struct remote_state
*rs
= get_remote_state ();
4188 error (_("Argument given to \"detach\" when remotely debugging."));
4190 if (!target_has_execution
)
4191 error (_("No process to detach from."));
4193 /* Tell the remote target to detach. */
4194 if (remote_multi_process_p (rs
))
4195 sprintf (rs
->buf
, "D;%x", pid
);
4197 strcpy (rs
->buf
, "D");
4200 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4202 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4204 else if (rs
->buf
[0] == '\0')
4205 error (_("Remote doesn't know how to detach"));
4207 error (_("Can't detach process."));
4211 if (remote_multi_process_p (rs
))
4212 printf_filtered (_("Detached from remote %s.\n"),
4213 target_pid_to_str (pid_to_ptid (pid
)));
4217 puts_filtered (_("Detached from remote process.\n"));
4219 puts_filtered (_("Ending remote debugging.\n"));
4223 discard_pending_stop_replies (pid
);
4224 target_mourn_inferior ();
4228 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4230 remote_detach_1 (args
, from_tty
, 0);
4234 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4236 remote_detach_1 (args
, from_tty
, 1);
4239 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4242 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4245 error (_("Argument given to \"disconnect\" when remotely debugging."));
4247 /* Make sure we unpush even the extended remote targets; mourn
4248 won't do it. So call remote_mourn_1 directly instead of
4249 target_mourn_inferior. */
4250 remote_mourn_1 (target
);
4253 puts_filtered ("Ending remote debugging.\n");
4256 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4257 be chatty about it. */
4260 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4262 struct remote_state
*rs
= get_remote_state ();
4264 char *wait_status
= NULL
;
4266 pid
= parse_pid_to_attach (args
);
4268 /* Remote PID can be freely equal to getpid, do not check it here the same
4269 way as in other targets. */
4271 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4272 error (_("This target does not support attaching to a process"));
4274 sprintf (rs
->buf
, "vAttach;%x", pid
);
4276 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4278 if (packet_ok (rs
->buf
,
4279 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4282 printf_unfiltered (_("Attached to %s\n"),
4283 target_pid_to_str (pid_to_ptid (pid
)));
4287 /* Save the reply for later. */
4288 wait_status
= alloca (strlen (rs
->buf
) + 1);
4289 strcpy (wait_status
, rs
->buf
);
4291 else if (strcmp (rs
->buf
, "OK") != 0)
4292 error (_("Attaching to %s failed with: %s"),
4293 target_pid_to_str (pid_to_ptid (pid
)),
4296 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4297 error (_("This target does not support attaching to a process"));
4299 error (_("Attaching to %s failed"),
4300 target_pid_to_str (pid_to_ptid (pid
)));
4302 set_current_inferior (remote_add_inferior (pid
, 1));
4304 inferior_ptid
= pid_to_ptid (pid
);
4308 struct thread_info
*thread
;
4310 /* Get list of threads. */
4311 remote_threads_info (target
);
4313 thread
= first_thread_of_process (pid
);
4315 inferior_ptid
= thread
->ptid
;
4317 inferior_ptid
= pid_to_ptid (pid
);
4319 /* Invalidate our notion of the remote current thread. */
4320 record_currthread (minus_one_ptid
);
4324 /* Now, if we have thread information, update inferior_ptid. */
4325 inferior_ptid
= remote_current_thread (inferior_ptid
);
4327 /* Add the main thread to the thread list. */
4328 add_thread_silent (inferior_ptid
);
4331 /* Next, if the target can specify a description, read it. We do
4332 this before anything involving memory or registers. */
4333 target_find_description ();
4337 /* Use the previously fetched status. */
4338 gdb_assert (wait_status
!= NULL
);
4340 if (target_can_async_p ())
4342 struct stop_reply
*stop_reply
;
4343 struct cleanup
*old_chain
;
4345 stop_reply
= stop_reply_xmalloc ();
4346 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4347 remote_parse_stop_reply (wait_status
, stop_reply
);
4348 discard_cleanups (old_chain
);
4349 push_stop_reply (stop_reply
);
4351 target_async (inferior_event_handler
, 0);
4355 gdb_assert (wait_status
!= NULL
);
4356 strcpy (rs
->buf
, wait_status
);
4357 rs
->cached_wait_status
= 1;
4361 gdb_assert (wait_status
== NULL
);
4365 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4367 extended_remote_attach_1 (ops
, args
, from_tty
);
4370 /* Convert hex digit A to a number. */
4375 if (a
>= '0' && a
<= '9')
4377 else if (a
>= 'a' && a
<= 'f')
4378 return a
- 'a' + 10;
4379 else if (a
>= 'A' && a
<= 'F')
4380 return a
- 'A' + 10;
4382 error (_("Reply contains invalid hex digit %d"), a
);
4386 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4390 for (i
= 0; i
< count
; i
++)
4392 if (hex
[0] == 0 || hex
[1] == 0)
4394 /* Hex string is short, or of uneven length.
4395 Return the count that has been converted so far. */
4398 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4404 /* Convert number NIB to a hex digit. */
4412 return 'a' + nib
- 10;
4416 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4420 /* May use a length, or a nul-terminated string as input. */
4422 count
= strlen ((char *) bin
);
4424 for (i
= 0; i
< count
; i
++)
4426 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4427 *hex
++ = tohex (*bin
++ & 0xf);
4433 /* Check for the availability of vCont. This function should also check
4437 remote_vcont_probe (struct remote_state
*rs
)
4441 strcpy (rs
->buf
, "vCont?");
4443 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4446 /* Make sure that the features we assume are supported. */
4447 if (strncmp (buf
, "vCont", 5) == 0)
4450 int support_s
, support_S
, support_c
, support_C
;
4456 rs
->support_vCont_t
= 0;
4457 while (p
&& *p
== ';')
4460 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4462 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4464 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4466 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4468 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4469 rs
->support_vCont_t
= 1;
4471 p
= strchr (p
, ';');
4474 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4475 BUF will make packet_ok disable the packet. */
4476 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4480 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4483 /* Helper function for building "vCont" resumptions. Write a
4484 resumption to P. ENDP points to one-passed-the-end of the buffer
4485 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4486 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4487 resumed thread should be single-stepped and/or signalled. If PTID
4488 equals minus_one_ptid, then all threads are resumed; if PTID
4489 represents a process, then all threads of the process are resumed;
4490 the thread to be stepped and/or signalled is given in the global
4494 append_resumption (char *p
, char *endp
,
4495 ptid_t ptid
, int step
, enum target_signal siggnal
)
4497 struct remote_state
*rs
= get_remote_state ();
4499 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4500 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4502 p
+= xsnprintf (p
, endp
- p
, ";s");
4503 else if (siggnal
!= TARGET_SIGNAL_0
)
4504 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4506 p
+= xsnprintf (p
, endp
- p
, ";c");
4508 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4512 /* All (-1) threads of process. */
4513 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4515 p
+= xsnprintf (p
, endp
- p
, ":");
4516 p
= write_ptid (p
, endp
, nptid
);
4518 else if (!ptid_equal (ptid
, minus_one_ptid
))
4520 p
+= xsnprintf (p
, endp
- p
, ":");
4521 p
= write_ptid (p
, endp
, ptid
);
4527 /* Resume the remote inferior by using a "vCont" packet. The thread
4528 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4529 resumed thread should be single-stepped and/or signalled. If PTID
4530 equals minus_one_ptid, then all threads are resumed; the thread to
4531 be stepped and/or signalled is given in the global INFERIOR_PTID.
4532 This function returns non-zero iff it resumes the inferior.
4534 This function issues a strict subset of all possible vCont commands at the
4538 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4540 struct remote_state
*rs
= get_remote_state ();
4544 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4545 remote_vcont_probe (rs
);
4547 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4551 endp
= rs
->buf
+ get_remote_packet_size ();
4553 /* If we could generate a wider range of packets, we'd have to worry
4554 about overflowing BUF. Should there be a generic
4555 "multi-part-packet" packet? */
4557 p
+= xsnprintf (p
, endp
- p
, "vCont");
4559 if (ptid_equal (ptid
, magic_null_ptid
))
4561 /* MAGIC_NULL_PTID means that we don't have any active threads,
4562 so we don't have any TID numbers the inferior will
4563 understand. Make sure to only send forms that do not specify
4565 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4567 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4569 /* Resume all threads (of all processes, or of a single
4570 process), with preference for INFERIOR_PTID. This assumes
4571 inferior_ptid belongs to the set of all threads we are about
4573 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4575 /* Step inferior_ptid, with or without signal. */
4576 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4579 /* And continue others without a signal. */
4580 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4584 /* Scheduler locking; resume only PTID. */
4585 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4588 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4593 /* In non-stop, the stub replies to vCont with "OK". The stop
4594 reply will be reported asynchronously by means of a `%Stop'
4596 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4597 if (strcmp (rs
->buf
, "OK") != 0)
4598 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4604 /* Tell the remote machine to resume. */
4606 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4608 static int last_sent_step
;
4611 remote_resume (struct target_ops
*ops
,
4612 ptid_t ptid
, int step
, enum target_signal siggnal
)
4614 struct remote_state
*rs
= get_remote_state ();
4617 last_sent_signal
= siggnal
;
4618 last_sent_step
= step
;
4620 /* The vCont packet doesn't need to specify threads via Hc. */
4621 /* No reverse support (yet) for vCont. */
4622 if (execution_direction
!= EXEC_REVERSE
)
4623 if (remote_vcont_resume (ptid
, step
, siggnal
))
4626 /* All other supported resume packets do use Hc, so set the continue
4628 if (ptid_equal (ptid
, minus_one_ptid
))
4629 set_continue_thread (any_thread_ptid
);
4631 set_continue_thread (ptid
);
4634 if (execution_direction
== EXEC_REVERSE
)
4636 /* We don't pass signals to the target in reverse exec mode. */
4637 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4638 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4642 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4643 error (_("Remote reverse-step not supported."));
4645 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4646 error (_("Remote reverse-continue not supported."));
4648 strcpy (buf
, step
? "bs" : "bc");
4650 else if (siggnal
!= TARGET_SIGNAL_0
)
4652 buf
[0] = step
? 'S' : 'C';
4653 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4654 buf
[2] = tohex (((int) siggnal
) & 0xf);
4658 strcpy (buf
, step
? "s" : "c");
4663 /* We are about to start executing the inferior, let's register it
4664 with the event loop. NOTE: this is the one place where all the
4665 execution commands end up. We could alternatively do this in each
4666 of the execution commands in infcmd.c. */
4667 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4668 into infcmd.c in order to allow inferior function calls to work
4669 NOT asynchronously. */
4670 if (target_can_async_p ())
4671 target_async (inferior_event_handler
, 0);
4673 /* We've just told the target to resume. The remote server will
4674 wait for the inferior to stop, and then send a stop reply. In
4675 the mean time, we can't start another command/query ourselves
4676 because the stub wouldn't be ready to process it. This applies
4677 only to the base all-stop protocol, however. In non-stop (which
4678 only supports vCont), the stub replies with an "OK", and is
4679 immediate able to process further serial input. */
4681 rs
->waiting_for_stop_reply
= 1;
4685 /* Set up the signal handler for SIGINT, while the target is
4686 executing, ovewriting the 'regular' SIGINT signal handler. */
4688 initialize_sigint_signal_handler (void)
4690 signal (SIGINT
, handle_remote_sigint
);
4693 /* Signal handler for SIGINT, while the target is executing. */
4695 handle_remote_sigint (int sig
)
4697 signal (sig
, handle_remote_sigint_twice
);
4698 mark_async_signal_handler_wrapper (sigint_remote_token
);
4701 /* Signal handler for SIGINT, installed after SIGINT has already been
4702 sent once. It will take effect the second time that the user sends
4705 handle_remote_sigint_twice (int sig
)
4707 signal (sig
, handle_remote_sigint
);
4708 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4711 /* Perform the real interruption of the target execution, in response
4714 async_remote_interrupt (gdb_client_data arg
)
4717 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4719 target_stop (inferior_ptid
);
4722 /* Perform interrupt, if the first attempt did not succeed. Just give
4723 up on the target alltogether. */
4725 async_remote_interrupt_twice (gdb_client_data arg
)
4728 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4733 /* Reinstall the usual SIGINT handlers, after the target has
4736 cleanup_sigint_signal_handler (void *dummy
)
4738 signal (SIGINT
, handle_sigint
);
4741 /* Send ^C to target to halt it. Target will respond, and send us a
4743 static void (*ofunc
) (int);
4745 /* The command line interface's stop routine. This function is installed
4746 as a signal handler for SIGINT. The first time a user requests a
4747 stop, we call remote_stop to send a break or ^C. If there is no
4748 response from the target (it didn't stop when the user requested it),
4749 we ask the user if he'd like to detach from the target. */
4751 remote_interrupt (int signo
)
4753 /* If this doesn't work, try more severe steps. */
4754 signal (signo
, remote_interrupt_twice
);
4756 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4759 /* The user typed ^C twice. */
4762 remote_interrupt_twice (int signo
)
4764 signal (signo
, ofunc
);
4765 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4766 signal (signo
, remote_interrupt
);
4769 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4770 thread, all threads of a remote process, or all threads of all
4774 remote_stop_ns (ptid_t ptid
)
4776 struct remote_state
*rs
= get_remote_state ();
4778 char *endp
= rs
->buf
+ get_remote_packet_size ();
4780 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4781 remote_vcont_probe (rs
);
4783 if (!rs
->support_vCont_t
)
4784 error (_("Remote server does not support stopping threads"));
4786 if (ptid_equal (ptid
, minus_one_ptid
)
4787 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4788 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4793 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4795 if (ptid_is_pid (ptid
))
4796 /* All (-1) threads of process. */
4797 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4800 /* Small optimization: if we already have a stop reply for
4801 this thread, no use in telling the stub we want this
4803 if (peek_stop_reply (ptid
))
4809 write_ptid (p
, endp
, nptid
);
4812 /* In non-stop, we get an immediate OK reply. The stop reply will
4813 come in asynchronously by notification. */
4815 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4816 if (strcmp (rs
->buf
, "OK") != 0)
4817 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4820 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4821 remote target. It is undefined which thread of which process
4822 reports the stop. */
4825 remote_stop_as (ptid_t ptid
)
4827 struct remote_state
*rs
= get_remote_state ();
4829 rs
->ctrlc_pending_p
= 1;
4831 /* If the inferior is stopped already, but the core didn't know
4832 about it yet, just ignore the request. The cached wait status
4833 will be collected in remote_wait. */
4834 if (rs
->cached_wait_status
)
4837 /* Send interrupt_sequence to remote target. */
4838 send_interrupt_sequence ();
4841 /* This is the generic stop called via the target vector. When a target
4842 interrupt is requested, either by the command line or the GUI, we
4843 will eventually end up here. */
4846 remote_stop (ptid_t ptid
)
4849 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4852 remote_stop_ns (ptid
);
4854 remote_stop_as (ptid
);
4857 /* Ask the user what to do when an interrupt is received. */
4860 interrupt_query (void)
4862 target_terminal_ours ();
4864 if (target_can_async_p ())
4866 signal (SIGINT
, handle_sigint
);
4867 deprecated_throw_reason (RETURN_QUIT
);
4871 if (query (_("Interrupted while waiting for the program.\n\
4872 Give up (and stop debugging it)? ")))
4875 deprecated_throw_reason (RETURN_QUIT
);
4879 target_terminal_inferior ();
4882 /* Enable/disable target terminal ownership. Most targets can use
4883 terminal groups to control terminal ownership. Remote targets are
4884 different in that explicit transfer of ownership to/from GDB/target
4888 remote_terminal_inferior (void)
4890 if (!target_async_permitted
)
4891 /* Nothing to do. */
4894 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4895 idempotent. The event-loop GDB talking to an asynchronous target
4896 with a synchronous command calls this function from both
4897 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4898 transfer the terminal to the target when it shouldn't this guard
4900 if (!remote_async_terminal_ours_p
)
4902 delete_file_handler (input_fd
);
4903 remote_async_terminal_ours_p
= 0;
4904 initialize_sigint_signal_handler ();
4905 /* NOTE: At this point we could also register our selves as the
4906 recipient of all input. Any characters typed could then be
4907 passed on down to the target. */
4911 remote_terminal_ours (void)
4913 if (!target_async_permitted
)
4914 /* Nothing to do. */
4917 /* See FIXME in remote_terminal_inferior. */
4918 if (remote_async_terminal_ours_p
)
4920 cleanup_sigint_signal_handler (NULL
);
4921 add_file_handler (input_fd
, stdin_event_handler
, 0);
4922 remote_async_terminal_ours_p
= 1;
4926 remote_console_output (char *msg
)
4930 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4933 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4937 fputs_unfiltered (tb
, gdb_stdtarg
);
4939 gdb_flush (gdb_stdtarg
);
4942 typedef struct cached_reg
4945 gdb_byte data
[MAX_REGISTER_SIZE
];
4948 DEF_VEC_O(cached_reg_t
);
4952 struct stop_reply
*next
;
4956 struct target_waitstatus ws
;
4958 /* Expedited registers. This makes remote debugging a bit more
4959 efficient for those targets that provide critical registers as
4960 part of their normal status mechanism (as another roundtrip to
4961 fetch them is avoided). */
4962 VEC(cached_reg_t
) *regcache
;
4964 int stopped_by_watchpoint_p
;
4965 CORE_ADDR watch_data_address
;
4973 /* The list of already fetched and acknowledged stop events. */
4974 static struct stop_reply
*stop_reply_queue
;
4976 static struct stop_reply
*
4977 stop_reply_xmalloc (void)
4979 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4986 stop_reply_xfree (struct stop_reply
*r
)
4990 VEC_free (cached_reg_t
, r
->regcache
);
4995 /* Discard all pending stop replies of inferior PID. If PID is -1,
4996 discard everything. */
4999 discard_pending_stop_replies (int pid
)
5001 struct stop_reply
*prev
= NULL
, *reply
, *next
;
5003 /* Discard the in-flight notification. */
5004 if (pending_stop_reply
!= NULL
5006 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
5008 stop_reply_xfree (pending_stop_reply
);
5009 pending_stop_reply
= NULL
;
5012 /* Discard the stop replies we have already pulled with
5014 for (reply
= stop_reply_queue
; reply
; reply
= next
)
5018 || ptid_get_pid (reply
->ptid
) == pid
)
5020 if (reply
== stop_reply_queue
)
5021 stop_reply_queue
= reply
->next
;
5023 prev
->next
= reply
->next
;
5025 stop_reply_xfree (reply
);
5032 /* Cleanup wrapper. */
5035 do_stop_reply_xfree (void *arg
)
5037 struct stop_reply
*r
= arg
;
5039 stop_reply_xfree (r
);
5042 /* Look for a queued stop reply belonging to PTID. If one is found,
5043 remove it from the queue, and return it. Returns NULL if none is
5044 found. If there are still queued events left to process, tell the
5045 event loop to get back to target_wait soon. */
5047 static struct stop_reply
*
5048 queued_stop_reply (ptid_t ptid
)
5050 struct stop_reply
*it
;
5051 struct stop_reply
**it_link
;
5053 it
= stop_reply_queue
;
5054 it_link
= &stop_reply_queue
;
5057 if (ptid_match (it
->ptid
, ptid
))
5059 *it_link
= it
->next
;
5064 it_link
= &it
->next
;
5068 if (stop_reply_queue
)
5069 /* There's still at least an event left. */
5070 mark_async_event_handler (remote_async_inferior_event_token
);
5075 /* Push a fully parsed stop reply in the stop reply queue. Since we
5076 know that we now have at least one queued event left to pass to the
5077 core side, tell the event loop to get back to target_wait soon. */
5080 push_stop_reply (struct stop_reply
*new_event
)
5082 struct stop_reply
*event
;
5084 if (stop_reply_queue
)
5086 for (event
= stop_reply_queue
;
5087 event
&& event
->next
;
5088 event
= event
->next
)
5091 event
->next
= new_event
;
5094 stop_reply_queue
= new_event
;
5096 mark_async_event_handler (remote_async_inferior_event_token
);
5099 /* Returns true if we have a stop reply for PTID. */
5102 peek_stop_reply (ptid_t ptid
)
5104 struct stop_reply
*it
;
5106 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5107 if (ptid_equal (ptid
, it
->ptid
))
5109 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5116 /* Parse the stop reply in BUF. Either the function succeeds, and the
5117 result is stored in EVENT, or throws an error. */
5120 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5122 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5126 event
->ptid
= null_ptid
;
5127 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5128 event
->ws
.value
.integer
= 0;
5129 event
->solibs_changed
= 0;
5130 event
->replay_event
= 0;
5131 event
->stopped_by_watchpoint_p
= 0;
5132 event
->regcache
= NULL
;
5137 case 'T': /* Status with PC, SP, FP, ... */
5138 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5139 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5141 n... = register number
5142 r... = register contents
5145 p
= &buf
[3]; /* after Txx */
5153 /* If the packet contains a register number, save it in
5154 pnum and set p1 to point to the character following it.
5155 Otherwise p1 points to p. */
5157 /* If this packet is an awatch packet, don't parse the 'a'
5158 as a register number. */
5160 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5161 && strncmp (p
, "core", strlen ("core") != 0))
5163 /* Read the ``P'' register number. */
5164 pnum
= strtol (p
, &p_temp
, 16);
5170 if (p1
== p
) /* No register number present here. */
5172 p1
= strchr (p
, ':');
5174 error (_("Malformed packet(a) (missing colon): %s\n\
5177 if (strncmp (p
, "thread", p1
- p
) == 0)
5178 event
->ptid
= read_ptid (++p1
, &p
);
5179 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5180 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5181 || (strncmp (p
, "awatch", p1
- p
) == 0))
5183 event
->stopped_by_watchpoint_p
= 1;
5184 p
= unpack_varlen_hex (++p1
, &addr
);
5185 event
->watch_data_address
= (CORE_ADDR
) addr
;
5187 else if (strncmp (p
, "library", p1
- p
) == 0)
5191 while (*p_temp
&& *p_temp
!= ';')
5194 event
->solibs_changed
= 1;
5197 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5199 /* NO_HISTORY event.
5200 p1 will indicate "begin" or "end", but
5201 it makes no difference for now, so ignore it. */
5202 event
->replay_event
= 1;
5203 p_temp
= strchr (p1
+ 1, ';');
5207 else if (strncmp (p
, "core", p1
- p
) == 0)
5211 p
= unpack_varlen_hex (++p1
, &c
);
5216 /* Silently skip unknown optional info. */
5217 p_temp
= strchr (p1
+ 1, ';');
5224 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5225 cached_reg_t cached_reg
;
5230 error (_("Malformed packet(b) (missing colon): %s\n\
5236 error (_("Remote sent bad register number %s: %s\n\
5238 hex_string (pnum
), p
, buf
);
5240 cached_reg
.num
= reg
->regnum
;
5242 fieldsize
= hex2bin (p
, cached_reg
.data
,
5243 register_size (target_gdbarch
,
5246 if (fieldsize
< register_size (target_gdbarch
,
5248 warning (_("Remote reply is too short: %s"), buf
);
5250 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5254 error (_("Remote register badly formatted: %s\nhere: %s"),
5259 case 'S': /* Old style status, just signal only. */
5260 if (event
->solibs_changed
)
5261 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5262 else if (event
->replay_event
)
5263 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5266 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5267 event
->ws
.value
.sig
= (enum target_signal
)
5268 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5271 case 'W': /* Target exited. */
5278 /* GDB used to accept only 2 hex chars here. Stubs should
5279 only send more if they detect GDB supports multi-process
5281 p
= unpack_varlen_hex (&buf
[1], &value
);
5285 /* The remote process exited. */
5286 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5287 event
->ws
.value
.integer
= value
;
5291 /* The remote process exited with a signal. */
5292 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5293 event
->ws
.value
.sig
= (enum target_signal
) value
;
5296 /* If no process is specified, assume inferior_ptid. */
5297 pid
= ptid_get_pid (inferior_ptid
);
5306 else if (strncmp (p
,
5307 "process:", sizeof ("process:") - 1) == 0)
5311 p
+= sizeof ("process:") - 1;
5312 unpack_varlen_hex (p
, &upid
);
5316 error (_("unknown stop reply packet: %s"), buf
);
5319 error (_("unknown stop reply packet: %s"), buf
);
5320 event
->ptid
= pid_to_ptid (pid
);
5325 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5326 error (_("No process or thread specified in stop reply: %s"), buf
);
5329 /* When the stub wants to tell GDB about a new stop reply, it sends a
5330 stop notification (%Stop). Those can come it at any time, hence,
5331 we have to make sure that any pending putpkt/getpkt sequence we're
5332 making is finished, before querying the stub for more events with
5333 vStopped. E.g., if we started a vStopped sequence immediatelly
5334 upon receiving the %Stop notification, something like this could
5342 1.6) <-- (registers reply to step #1.3)
5344 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5347 To solve this, whenever we parse a %Stop notification sucessfully,
5348 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5349 doing whatever we were doing:
5355 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5356 2.5) <-- (registers reply to step #2.3)
5358 Eventualy after step #2.5, we return to the event loop, which
5359 notices there's an event on the
5360 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5361 associated callback --- the function below. At this point, we're
5362 always safe to start a vStopped sequence. :
5365 2.7) <-- T05 thread:2
5371 remote_get_pending_stop_replies (void)
5373 struct remote_state
*rs
= get_remote_state ();
5375 if (pending_stop_reply
)
5378 putpkt ("vStopped");
5380 /* Now we can rely on it. */
5381 push_stop_reply (pending_stop_reply
);
5382 pending_stop_reply
= NULL
;
5386 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5387 if (strcmp (rs
->buf
, "OK") == 0)
5391 struct cleanup
*old_chain
;
5392 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5394 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5395 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5398 putpkt ("vStopped");
5400 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5402 /* Now we can rely on it. */
5403 discard_cleanups (old_chain
);
5404 push_stop_reply (stop_reply
);
5407 /* We got an unknown stop reply. */
5408 do_cleanups (old_chain
);
5415 /* Called when it is decided that STOP_REPLY holds the info of the
5416 event that is to be returned to the core. This function always
5417 destroys STOP_REPLY. */
5420 process_stop_reply (struct stop_reply
*stop_reply
,
5421 struct target_waitstatus
*status
)
5425 *status
= stop_reply
->ws
;
5426 ptid
= stop_reply
->ptid
;
5428 /* If no thread/process was reported by the stub, assume the current
5430 if (ptid_equal (ptid
, null_ptid
))
5431 ptid
= inferior_ptid
;
5433 if (status
->kind
!= TARGET_WAITKIND_EXITED
5434 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5436 /* Expedited registers. */
5437 if (stop_reply
->regcache
)
5439 struct regcache
*regcache
5440 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5445 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5447 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5448 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5451 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5452 remote_watch_data_address
= stop_reply
->watch_data_address
;
5454 remote_notice_new_inferior (ptid
, 0);
5455 demand_private_info (ptid
)->core
= stop_reply
->core
;
5458 stop_reply_xfree (stop_reply
);
5462 /* The non-stop mode version of target_wait. */
5465 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5467 struct remote_state
*rs
= get_remote_state ();
5468 struct stop_reply
*stop_reply
;
5471 /* If in non-stop mode, get out of getpkt even if a
5472 notification is received. */
5474 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5481 case 'E': /* Error of some sort. */
5482 /* We're out of sync with the target now. Did it continue
5483 or not? We can't tell which thread it was in non-stop,
5484 so just ignore this. */
5485 warning (_("Remote failure reply: %s"), rs
->buf
);
5487 case 'O': /* Console output. */
5488 remote_console_output (rs
->buf
+ 1);
5491 warning (_("Invalid remote reply: %s"), rs
->buf
);
5495 /* Acknowledge a pending stop reply that may have arrived in the
5497 if (pending_stop_reply
!= NULL
)
5498 remote_get_pending_stop_replies ();
5500 /* If indeed we noticed a stop reply, we're done. */
5501 stop_reply
= queued_stop_reply (ptid
);
5502 if (stop_reply
!= NULL
)
5503 return process_stop_reply (stop_reply
, status
);
5505 /* Still no event. If we're just polling for an event, then
5506 return to the event loop. */
5507 if (options
& TARGET_WNOHANG
)
5509 status
->kind
= TARGET_WAITKIND_IGNORE
;
5510 return minus_one_ptid
;
5513 /* Otherwise do a blocking wait. */
5514 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5519 /* Wait until the remote machine stops, then return, storing status in
5520 STATUS just as `wait' would. */
5523 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5525 struct remote_state
*rs
= get_remote_state ();
5526 ptid_t event_ptid
= null_ptid
;
5528 struct stop_reply
*stop_reply
;
5532 status
->kind
= TARGET_WAITKIND_IGNORE
;
5533 status
->value
.integer
= 0;
5535 stop_reply
= queued_stop_reply (ptid
);
5536 if (stop_reply
!= NULL
)
5537 return process_stop_reply (stop_reply
, status
);
5539 if (rs
->cached_wait_status
)
5540 /* Use the cached wait status, but only once. */
5541 rs
->cached_wait_status
= 0;
5546 if (!target_is_async_p ())
5548 ofunc
= signal (SIGINT
, remote_interrupt
);
5549 /* If the user hit C-c before this packet, or between packets,
5550 pretend that it was hit right here. */
5554 remote_interrupt (SIGINT
);
5558 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5559 _never_ wait for ever -> test on target_is_async_p().
5560 However, before we do that we need to ensure that the caller
5561 knows how to take the target into/out of async mode. */
5562 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5563 if (!target_is_async_p ())
5564 signal (SIGINT
, ofunc
);
5569 remote_stopped_by_watchpoint_p
= 0;
5571 /* We got something. */
5572 rs
->waiting_for_stop_reply
= 0;
5574 /* Assume that the target has acknowledged Ctrl-C unless we receive
5575 an 'F' or 'O' packet. */
5576 if (buf
[0] != 'F' && buf
[0] != 'O')
5577 rs
->ctrlc_pending_p
= 0;
5581 case 'E': /* Error of some sort. */
5582 /* We're out of sync with the target now. Did it continue or
5583 not? Not is more likely, so report a stop. */
5584 warning (_("Remote failure reply: %s"), buf
);
5585 status
->kind
= TARGET_WAITKIND_STOPPED
;
5586 status
->value
.sig
= TARGET_SIGNAL_0
;
5588 case 'F': /* File-I/O request. */
5589 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5590 rs
->ctrlc_pending_p
= 0;
5592 case 'T': case 'S': case 'X': case 'W':
5594 struct stop_reply
*stop_reply
;
5595 struct cleanup
*old_chain
;
5597 stop_reply
= stop_reply_xmalloc ();
5598 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5599 remote_parse_stop_reply (buf
, stop_reply
);
5600 discard_cleanups (old_chain
);
5601 event_ptid
= process_stop_reply (stop_reply
, status
);
5604 case 'O': /* Console output. */
5605 remote_console_output (buf
+ 1);
5607 /* The target didn't really stop; keep waiting. */
5608 rs
->waiting_for_stop_reply
= 1;
5612 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5614 /* Zero length reply means that we tried 'S' or 'C' and the
5615 remote system doesn't support it. */
5616 target_terminal_ours_for_output ();
5618 ("Can't send signals to this remote system. %s not sent.\n",
5619 target_signal_to_name (last_sent_signal
));
5620 last_sent_signal
= TARGET_SIGNAL_0
;
5621 target_terminal_inferior ();
5623 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5624 putpkt ((char *) buf
);
5626 /* We just told the target to resume, so a stop reply is in
5628 rs
->waiting_for_stop_reply
= 1;
5631 /* else fallthrough */
5633 warning (_("Invalid remote reply: %s"), buf
);
5635 rs
->waiting_for_stop_reply
= 1;
5639 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5641 /* Nothing interesting happened. If we're doing a non-blocking
5642 poll, we're done. Otherwise, go back to waiting. */
5643 if (options
& TARGET_WNOHANG
)
5644 return minus_one_ptid
;
5648 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5649 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5651 if (!ptid_equal (event_ptid
, null_ptid
))
5652 record_currthread (event_ptid
);
5654 event_ptid
= inferior_ptid
;
5657 /* A process exit. Invalidate our notion of current thread. */
5658 record_currthread (minus_one_ptid
);
5663 /* Wait until the remote machine stops, then return, storing status in
5664 STATUS just as `wait' would. */
5667 remote_wait (struct target_ops
*ops
,
5668 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5673 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5675 event_ptid
= remote_wait_as (ptid
, status
, options
);
5677 if (target_can_async_p ())
5679 /* If there are are events left in the queue tell the event loop
5681 if (stop_reply_queue
)
5682 mark_async_event_handler (remote_async_inferior_event_token
);
5688 /* Fetch a single register using a 'p' packet. */
5691 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5693 struct remote_state
*rs
= get_remote_state ();
5695 char regp
[MAX_REGISTER_SIZE
];
5698 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5701 if (reg
->pnum
== -1)
5706 p
+= hexnumstr (p
, reg
->pnum
);
5709 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5713 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5717 case PACKET_UNKNOWN
:
5720 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5721 gdbarch_register_name (get_regcache_arch (regcache
),
5726 /* If this register is unfetchable, tell the regcache. */
5729 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5733 /* Otherwise, parse and supply the value. */
5739 error (_("fetch_register_using_p: early buf termination"));
5741 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5744 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5748 /* Fetch the registers included in the target's 'g' packet. */
5751 send_g_packet (void)
5753 struct remote_state
*rs
= get_remote_state ();
5756 sprintf (rs
->buf
, "g");
5757 remote_send (&rs
->buf
, &rs
->buf_size
);
5759 /* We can get out of synch in various cases. If the first character
5760 in the buffer is not a hex character, assume that has happened
5761 and try to fetch another packet to read. */
5762 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5763 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5764 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5765 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5768 fprintf_unfiltered (gdb_stdlog
,
5769 "Bad register packet; fetching a new packet\n");
5770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5773 buf_len
= strlen (rs
->buf
);
5775 /* Sanity check the received packet. */
5776 if (buf_len
% 2 != 0)
5777 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5783 process_g_packet (struct regcache
*regcache
)
5785 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5786 struct remote_state
*rs
= get_remote_state ();
5787 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5792 buf_len
= strlen (rs
->buf
);
5794 /* Further sanity checks, with knowledge of the architecture. */
5795 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5796 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5798 /* Save the size of the packet sent to us by the target. It is used
5799 as a heuristic when determining the max size of packets that the
5800 target can safely receive. */
5801 if (rsa
->actual_register_packet_size
== 0)
5802 rsa
->actual_register_packet_size
= buf_len
;
5804 /* If this is smaller than we guessed the 'g' packet would be,
5805 update our records. A 'g' reply that doesn't include a register's
5806 value implies either that the register is not available, or that
5807 the 'p' packet must be used. */
5808 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5810 rsa
->sizeof_g_packet
= buf_len
/ 2;
5812 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5814 if (rsa
->regs
[i
].pnum
== -1)
5817 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5818 rsa
->regs
[i
].in_g_packet
= 0;
5820 rsa
->regs
[i
].in_g_packet
= 1;
5824 regs
= alloca (rsa
->sizeof_g_packet
);
5826 /* Unimplemented registers read as all bits zero. */
5827 memset (regs
, 0, rsa
->sizeof_g_packet
);
5829 /* Reply describes registers byte by byte, each byte encoded as two
5830 hex characters. Suck them all up, then supply them to the
5831 register cacheing/storage mechanism. */
5834 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5836 if (p
[0] == 0 || p
[1] == 0)
5837 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5838 internal_error (__FILE__
, __LINE__
,
5839 _("unexpected end of 'g' packet reply"));
5841 if (p
[0] == 'x' && p
[1] == 'x')
5842 regs
[i
] = 0; /* 'x' */
5844 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5848 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5850 struct packet_reg
*r
= &rsa
->regs
[i
];
5854 if (r
->offset
* 2 >= strlen (rs
->buf
))
5855 /* This shouldn't happen - we adjusted in_g_packet above. */
5856 internal_error (__FILE__
, __LINE__
,
5857 _("unexpected end of 'g' packet reply"));
5858 else if (rs
->buf
[r
->offset
* 2] == 'x')
5860 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5861 /* The register isn't available, mark it as such (at
5862 the same time setting the value to zero). */
5863 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5866 regcache_raw_supply (regcache
, r
->regnum
,
5873 fetch_registers_using_g (struct regcache
*regcache
)
5876 process_g_packet (regcache
);
5879 /* Make the remote selected traceframe match GDB's selected
5883 set_remote_traceframe (void)
5887 if (remote_traceframe_number
== get_traceframe_number ())
5890 /* Avoid recursion, remote_trace_find calls us again. */
5891 remote_traceframe_number
= get_traceframe_number ();
5893 newnum
= target_trace_find (tfind_number
,
5894 get_traceframe_number (), 0, 0, NULL
);
5896 /* Should not happen. If it does, all bets are off. */
5897 if (newnum
!= get_traceframe_number ())
5898 warning (_("could not set remote traceframe"));
5902 remote_fetch_registers (struct target_ops
*ops
,
5903 struct regcache
*regcache
, int regnum
)
5905 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5908 set_remote_traceframe ();
5909 set_general_thread (inferior_ptid
);
5913 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5915 gdb_assert (reg
!= NULL
);
5917 /* If this register might be in the 'g' packet, try that first -
5918 we are likely to read more than one register. If this is the
5919 first 'g' packet, we might be overly optimistic about its
5920 contents, so fall back to 'p'. */
5921 if (reg
->in_g_packet
)
5923 fetch_registers_using_g (regcache
);
5924 if (reg
->in_g_packet
)
5928 if (fetch_register_using_p (regcache
, reg
))
5931 /* This register is not available. */
5932 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5937 fetch_registers_using_g (regcache
);
5939 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5940 if (!rsa
->regs
[i
].in_g_packet
)
5941 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5943 /* This register is not available. */
5944 regcache_raw_supply (regcache
, i
, NULL
);
5948 /* Prepare to store registers. Since we may send them all (using a
5949 'G' request), we have to read out the ones we don't want to change
5953 remote_prepare_to_store (struct regcache
*regcache
)
5955 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5957 gdb_byte buf
[MAX_REGISTER_SIZE
];
5959 /* Make sure the entire registers array is valid. */
5960 switch (remote_protocol_packets
[PACKET_P
].support
)
5962 case PACKET_DISABLE
:
5963 case PACKET_SUPPORT_UNKNOWN
:
5964 /* Make sure all the necessary registers are cached. */
5965 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5966 if (rsa
->regs
[i
].in_g_packet
)
5967 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5974 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5975 packet was not recognized. */
5978 store_register_using_P (const struct regcache
*regcache
,
5979 struct packet_reg
*reg
)
5981 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5982 struct remote_state
*rs
= get_remote_state ();
5983 /* Try storing a single register. */
5984 char *buf
= rs
->buf
;
5985 gdb_byte regp
[MAX_REGISTER_SIZE
];
5988 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5991 if (reg
->pnum
== -1)
5994 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5995 p
= buf
+ strlen (buf
);
5996 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5997 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5999 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6001 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6006 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6007 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6008 case PACKET_UNKNOWN
:
6011 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6015 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6016 contents of the register cache buffer. FIXME: ignores errors. */
6019 store_registers_using_G (const struct regcache
*regcache
)
6021 struct remote_state
*rs
= get_remote_state ();
6022 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6026 /* Extract all the registers in the regcache copying them into a
6031 regs
= alloca (rsa
->sizeof_g_packet
);
6032 memset (regs
, 0, rsa
->sizeof_g_packet
);
6033 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6035 struct packet_reg
*r
= &rsa
->regs
[i
];
6038 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6042 /* Command describes registers byte by byte,
6043 each byte encoded as two hex characters. */
6046 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6048 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6050 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6051 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6052 error (_("Could not write registers; remote failure reply '%s'"),
6056 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6057 of the register cache buffer. FIXME: ignores errors. */
6060 remote_store_registers (struct target_ops
*ops
,
6061 struct regcache
*regcache
, int regnum
)
6063 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6066 set_remote_traceframe ();
6067 set_general_thread (inferior_ptid
);
6071 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6073 gdb_assert (reg
!= NULL
);
6075 /* Always prefer to store registers using the 'P' packet if
6076 possible; we often change only a small number of registers.
6077 Sometimes we change a larger number; we'd need help from a
6078 higher layer to know to use 'G'. */
6079 if (store_register_using_P (regcache
, reg
))
6082 /* For now, don't complain if we have no way to write the
6083 register. GDB loses track of unavailable registers too
6084 easily. Some day, this may be an error. We don't have
6085 any way to read the register, either... */
6086 if (!reg
->in_g_packet
)
6089 store_registers_using_G (regcache
);
6093 store_registers_using_G (regcache
);
6095 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6096 if (!rsa
->regs
[i
].in_g_packet
)
6097 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6098 /* See above for why we do not issue an error here. */
6103 /* Return the number of hex digits in num. */
6106 hexnumlen (ULONGEST num
)
6110 for (i
= 0; num
!= 0; i
++)
6116 /* Set BUF to the minimum number of hex digits representing NUM. */
6119 hexnumstr (char *buf
, ULONGEST num
)
6121 int len
= hexnumlen (num
);
6123 return hexnumnstr (buf
, num
, len
);
6127 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6130 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6136 for (i
= width
- 1; i
>= 0; i
--)
6138 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6145 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6148 remote_address_masked (CORE_ADDR addr
)
6150 int address_size
= remote_address_size
;
6152 /* If "remoteaddresssize" was not set, default to target address size. */
6154 address_size
= gdbarch_addr_bit (target_gdbarch
);
6156 if (address_size
> 0
6157 && address_size
< (sizeof (ULONGEST
) * 8))
6159 /* Only create a mask when that mask can safely be constructed
6160 in a ULONGEST variable. */
6163 mask
= (mask
<< address_size
) - 1;
6169 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6170 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6171 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6172 (which may be more than *OUT_LEN due to escape characters). The
6173 total number of bytes in the output buffer will be at most
6177 remote_escape_output (const gdb_byte
*buffer
, int len
,
6178 gdb_byte
*out_buf
, int *out_len
,
6181 int input_index
, output_index
;
6184 for (input_index
= 0; input_index
< len
; input_index
++)
6186 gdb_byte b
= buffer
[input_index
];
6188 if (b
== '$' || b
== '#' || b
== '}')
6190 /* These must be escaped. */
6191 if (output_index
+ 2 > out_maxlen
)
6193 out_buf
[output_index
++] = '}';
6194 out_buf
[output_index
++] = b
^ 0x20;
6198 if (output_index
+ 1 > out_maxlen
)
6200 out_buf
[output_index
++] = b
;
6204 *out_len
= input_index
;
6205 return output_index
;
6208 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6209 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6210 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6212 This function reverses remote_escape_output. It allows more
6213 escaped characters than that function does, in particular because
6214 '*' must be escaped to avoid the run-length encoding processing
6215 in reading packets. */
6218 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6219 gdb_byte
*out_buf
, int out_maxlen
)
6221 int input_index
, output_index
;
6226 for (input_index
= 0; input_index
< len
; input_index
++)
6228 gdb_byte b
= buffer
[input_index
];
6230 if (output_index
+ 1 > out_maxlen
)
6232 warning (_("Received too much data from remote target;"
6233 " ignoring overflow."));
6234 return output_index
;
6239 out_buf
[output_index
++] = b
^ 0x20;
6245 out_buf
[output_index
++] = b
;
6249 error (_("Unmatched escape character in target response."));
6251 return output_index
;
6254 /* Determine whether the remote target supports binary downloading.
6255 This is accomplished by sending a no-op memory write of zero length
6256 to the target at the specified address. It does not suffice to send
6257 the whole packet, since many stubs strip the eighth bit and
6258 subsequently compute a wrong checksum, which causes real havoc with
6261 NOTE: This can still lose if the serial line is not eight-bit
6262 clean. In cases like this, the user should clear "remote
6266 check_binary_download (CORE_ADDR addr
)
6268 struct remote_state
*rs
= get_remote_state ();
6270 switch (remote_protocol_packets
[PACKET_X
].support
)
6272 case PACKET_DISABLE
:
6276 case PACKET_SUPPORT_UNKNOWN
:
6282 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6284 p
+= hexnumstr (p
, (ULONGEST
) 0);
6288 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6289 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6291 if (rs
->buf
[0] == '\0')
6294 fprintf_unfiltered (gdb_stdlog
,
6295 "binary downloading NOT "
6296 "supported by target\n");
6297 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6302 fprintf_unfiltered (gdb_stdlog
,
6303 "binary downloading supported by target\n");
6304 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6311 /* Write memory data directly to the remote machine.
6312 This does not inform the data cache; the data cache uses this.
6313 HEADER is the starting part of the packet.
6314 MEMADDR is the address in the remote memory space.
6315 MYADDR is the address of the buffer in our space.
6316 LEN is the number of bytes.
6317 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6318 should send data as binary ('X'), or hex-encoded ('M').
6320 The function creates packet of the form
6321 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6323 where encoding of <DATA> is termined by PACKET_FORMAT.
6325 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6328 Returns the number of bytes transferred, or 0 (setting errno) for
6329 error. Only transfer a single packet. */
6332 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6333 const gdb_byte
*myaddr
, int len
,
6334 char packet_format
, int use_length
)
6336 struct remote_state
*rs
= get_remote_state ();
6346 if (packet_format
!= 'X' && packet_format
!= 'M')
6347 internal_error (__FILE__
, __LINE__
,
6348 _("remote_write_bytes_aux: bad packet format"));
6353 payload_size
= get_memory_write_packet_size ();
6355 /* The packet buffer will be large enough for the payload;
6356 get_memory_packet_size ensures this. */
6359 /* Compute the size of the actual payload by subtracting out the
6360 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6362 payload_size
-= strlen ("$,:#NN");
6364 /* The comma won't be used. */
6366 header_length
= strlen (header
);
6367 payload_size
-= header_length
;
6368 payload_size
-= hexnumlen (memaddr
);
6370 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6372 strcat (rs
->buf
, header
);
6373 p
= rs
->buf
+ strlen (header
);
6375 /* Compute a best guess of the number of bytes actually transfered. */
6376 if (packet_format
== 'X')
6378 /* Best guess at number of bytes that will fit. */
6379 todo
= min (len
, payload_size
);
6381 payload_size
-= hexnumlen (todo
);
6382 todo
= min (todo
, payload_size
);
6386 /* Num bytes that will fit. */
6387 todo
= min (len
, payload_size
/ 2);
6389 payload_size
-= hexnumlen (todo
);
6390 todo
= min (todo
, payload_size
/ 2);
6394 internal_error (__FILE__
, __LINE__
,
6395 _("minimum packet size too small to write data"));
6397 /* If we already need another packet, then try to align the end
6398 of this packet to a useful boundary. */
6399 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6400 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6402 /* Append "<memaddr>". */
6403 memaddr
= remote_address_masked (memaddr
);
6404 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6411 /* Append <len>. Retain the location/size of <len>. It may need to
6412 be adjusted once the packet body has been created. */
6414 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6422 /* Append the packet body. */
6423 if (packet_format
== 'X')
6425 /* Binary mode. Send target system values byte by byte, in
6426 increasing byte addresses. Only escape certain critical
6428 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6431 /* If not all TODO bytes fit, then we'll need another packet. Make
6432 a second try to keep the end of the packet aligned. Don't do
6433 this if the packet is tiny. */
6434 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6438 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6440 if (new_nr_bytes
!= nr_bytes
)
6441 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6446 p
+= payload_length
;
6447 if (use_length
&& nr_bytes
< todo
)
6449 /* Escape chars have filled up the buffer prematurely,
6450 and we have actually sent fewer bytes than planned.
6451 Fix-up the length field of the packet. Use the same
6452 number of characters as before. */
6453 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6454 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6459 /* Normal mode: Send target system values byte by byte, in
6460 increasing byte addresses. Each byte is encoded as a two hex
6462 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6466 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6467 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6469 if (rs
->buf
[0] == 'E')
6471 /* There is no correspondance between what the remote protocol
6472 uses for errors and errno codes. We would like a cleaner way
6473 of representing errors (big enough to include errno codes,
6474 bfd_error codes, and others). But for now just return EIO. */
6479 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6480 fewer bytes than we'd planned. */
6484 /* Write memory data directly to the remote machine.
6485 This does not inform the data cache; the data cache uses this.
6486 MEMADDR is the address in the remote memory space.
6487 MYADDR is the address of the buffer in our space.
6488 LEN is the number of bytes.
6490 Returns number of bytes transferred, or 0 (setting errno) for
6491 error. Only transfer a single packet. */
6494 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6496 char *packet_format
= 0;
6498 /* Check whether the target supports binary download. */
6499 check_binary_download (memaddr
);
6501 switch (remote_protocol_packets
[PACKET_X
].support
)
6504 packet_format
= "X";
6506 case PACKET_DISABLE
:
6507 packet_format
= "M";
6509 case PACKET_SUPPORT_UNKNOWN
:
6510 internal_error (__FILE__
, __LINE__
,
6511 _("remote_write_bytes: bad internal state"));
6513 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6516 return remote_write_bytes_aux (packet_format
,
6517 memaddr
, myaddr
, len
, packet_format
[0], 1);
6520 /* Read memory data directly from the remote machine.
6521 This does not use the data cache; the data cache uses this.
6522 MEMADDR is the address in the remote memory space.
6523 MYADDR is the address of the buffer in our space.
6524 LEN is the number of bytes.
6526 Returns number of bytes transferred, or 0 for error. */
6529 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6531 struct remote_state
*rs
= get_remote_state ();
6532 int max_buf_size
; /* Max size of packet output buffer. */
6540 max_buf_size
= get_memory_read_packet_size ();
6541 /* The packet buffer will be large enough for the payload;
6542 get_memory_packet_size ensures this. */
6544 /* Number if bytes that will fit. */
6545 todo
= min (len
, max_buf_size
/ 2);
6547 /* Construct "m"<memaddr>","<len>". */
6548 memaddr
= remote_address_masked (memaddr
);
6551 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6553 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6556 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6557 if (rs
->buf
[0] == 'E'
6558 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6559 && rs
->buf
[3] == '\0')
6561 /* There is no correspondance between what the remote protocol
6562 uses for errors and errno codes. We would like a cleaner way
6563 of representing errors (big enough to include errno codes,
6564 bfd_error codes, and others). But for now just return
6569 /* Reply describes memory byte by byte, each byte encoded as two hex
6572 i
= hex2bin (p
, myaddr
, todo
);
6573 /* Return what we have. Let higher layers handle partial reads. */
6578 /* Remote notification handler. */
6581 handle_notification (char *buf
, size_t length
)
6583 if (strncmp (buf
, "Stop:", 5) == 0)
6585 if (pending_stop_reply
)
6587 /* We've already parsed the in-flight stop-reply, but the
6588 stub for some reason thought we didn't, possibly due to
6589 timeout on its side. Just ignore it. */
6591 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6595 struct cleanup
*old_chain
;
6596 struct stop_reply
*reply
= stop_reply_xmalloc ();
6598 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6600 remote_parse_stop_reply (buf
+ 5, reply
);
6602 discard_cleanups (old_chain
);
6604 /* Be careful to only set it after parsing, since an error
6605 may be thrown then. */
6606 pending_stop_reply
= reply
;
6608 /* Notify the event loop there's a stop reply to acknowledge
6609 and that there may be more events to fetch. */
6610 mark_async_event_handler (remote_async_get_pending_events_token
);
6613 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6617 /* We ignore notifications we don't recognize, for compatibility
6618 with newer stubs. */
6623 /* Read or write LEN bytes from inferior memory at MEMADDR,
6624 transferring to or from debugger address BUFFER. Write to inferior
6625 if SHOULD_WRITE is nonzero. Returns length of data written or
6626 read; 0 for error. TARGET is unused. */
6629 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6630 int should_write
, struct mem_attrib
*attrib
,
6631 struct target_ops
*target
)
6635 set_remote_traceframe ();
6636 set_general_thread (inferior_ptid
);
6639 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6641 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6646 /* Sends a packet with content determined by the printf format string
6647 FORMAT and the remaining arguments, then gets the reply. Returns
6648 whether the packet was a success, a failure, or unknown. */
6650 static enum packet_result
6651 remote_send_printf (const char *format
, ...)
6653 struct remote_state
*rs
= get_remote_state ();
6654 int max_size
= get_remote_packet_size ();
6657 va_start (ap
, format
);
6660 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6661 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6663 if (putpkt (rs
->buf
) < 0)
6664 error (_("Communication problem with target."));
6667 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6669 return packet_check_result (rs
->buf
);
6673 restore_remote_timeout (void *p
)
6675 int value
= *(int *)p
;
6677 remote_timeout
= value
;
6680 /* Flash writing can take quite some time. We'll set
6681 effectively infinite timeout for flash operations.
6682 In future, we'll need to decide on a better approach. */
6683 static const int remote_flash_timeout
= 1000;
6686 remote_flash_erase (struct target_ops
*ops
,
6687 ULONGEST address
, LONGEST length
)
6689 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6690 int saved_remote_timeout
= remote_timeout
;
6691 enum packet_result ret
;
6692 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6693 &saved_remote_timeout
);
6695 remote_timeout
= remote_flash_timeout
;
6697 ret
= remote_send_printf ("vFlashErase:%s,%s",
6698 phex (address
, addr_size
),
6702 case PACKET_UNKNOWN
:
6703 error (_("Remote target does not support flash erase"));
6705 error (_("Error erasing flash with vFlashErase packet"));
6710 do_cleanups (back_to
);
6714 remote_flash_write (struct target_ops
*ops
,
6715 ULONGEST address
, LONGEST length
,
6716 const gdb_byte
*data
)
6718 int saved_remote_timeout
= remote_timeout
;
6720 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6721 &saved_remote_timeout
);
6723 remote_timeout
= remote_flash_timeout
;
6724 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6725 do_cleanups (back_to
);
6731 remote_flash_done (struct target_ops
*ops
)
6733 int saved_remote_timeout
= remote_timeout
;
6735 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6736 &saved_remote_timeout
);
6738 remote_timeout
= remote_flash_timeout
;
6739 ret
= remote_send_printf ("vFlashDone");
6740 do_cleanups (back_to
);
6744 case PACKET_UNKNOWN
:
6745 error (_("Remote target does not support vFlashDone"));
6747 error (_("Error finishing flash operation"));
6754 remote_files_info (struct target_ops
*ignore
)
6756 puts_filtered ("Debugging a target over a serial line.\n");
6759 /* Stuff for dealing with the packets which are part of this protocol.
6760 See comment at top of file for details. */
6762 /* Read a single character from the remote end. */
6765 readchar (int timeout
)
6769 ch
= serial_readchar (remote_desc
, timeout
);
6774 switch ((enum serial_rc
) ch
)
6778 error (_("Remote connection closed"));
6782 perror_with_name (_("Remote communication error. "
6783 "Target disconnected."));
6785 case SERIAL_TIMEOUT
:
6791 /* Send the command in *BUF to the remote machine, and read the reply
6792 into *BUF. Report an error if we get an error reply. Resize
6793 *BUF using xrealloc if necessary to hold the result, and update
6797 remote_send (char **buf
,
6801 getpkt (buf
, sizeof_buf
, 0);
6803 if ((*buf
)[0] == 'E')
6804 error (_("Remote failure reply: %s"), *buf
);
6807 /* Return a pointer to an xmalloc'ed string representing an escaped
6808 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6809 etc. The caller is responsible for releasing the returned
6813 escape_buffer (const char *buf
, int n
)
6815 struct cleanup
*old_chain
;
6816 struct ui_file
*stb
;
6819 stb
= mem_fileopen ();
6820 old_chain
= make_cleanup_ui_file_delete (stb
);
6822 fputstrn_unfiltered (buf
, n
, 0, stb
);
6823 str
= ui_file_xstrdup (stb
, NULL
);
6824 do_cleanups (old_chain
);
6828 /* Display a null-terminated packet on stdout, for debugging, using C
6832 print_packet (char *buf
)
6834 puts_filtered ("\"");
6835 fputstr_filtered (buf
, '"', gdb_stdout
);
6836 puts_filtered ("\"");
6842 return putpkt_binary (buf
, strlen (buf
));
6845 /* Send a packet to the remote machine, with error checking. The data
6846 of the packet is in BUF. The string in BUF can be at most
6847 get_remote_packet_size () - 5 to account for the $, # and checksum,
6848 and for a possible /0 if we are debugging (remote_debug) and want
6849 to print the sent packet as a string. */
6852 putpkt_binary (char *buf
, int cnt
)
6854 struct remote_state
*rs
= get_remote_state ();
6856 unsigned char csum
= 0;
6857 char *buf2
= alloca (cnt
+ 6);
6863 /* Catch cases like trying to read memory or listing threads while
6864 we're waiting for a stop reply. The remote server wouldn't be
6865 ready to handle this request, so we'd hang and timeout. We don't
6866 have to worry about this in synchronous mode, because in that
6867 case it's not possible to issue a command while the target is
6868 running. This is not a problem in non-stop mode, because in that
6869 case, the stub is always ready to process serial input. */
6870 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6871 error (_("Cannot execute this command while the target is running."));
6873 /* We're sending out a new packet. Make sure we don't look at a
6874 stale cached response. */
6875 rs
->cached_wait_status
= 0;
6877 /* Copy the packet into buffer BUF2, encapsulating it
6878 and giving it a checksum. */
6883 for (i
= 0; i
< cnt
; i
++)
6889 *p
++ = tohex ((csum
>> 4) & 0xf);
6890 *p
++ = tohex (csum
& 0xf);
6892 /* Send it over and over until we get a positive ack. */
6896 int started_error_output
= 0;
6900 struct cleanup
*old_chain
;
6904 str
= escape_buffer (buf2
, p
- buf2
);
6905 old_chain
= make_cleanup (xfree
, str
);
6906 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6907 gdb_flush (gdb_stdlog
);
6908 do_cleanups (old_chain
);
6910 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6911 perror_with_name (_("putpkt: write failed"));
6913 /* If this is a no acks version of the remote protocol, send the
6914 packet and move on. */
6918 /* Read until either a timeout occurs (-2) or '+' is read.
6919 Handle any notification that arrives in the mean time. */
6922 ch
= readchar (remote_timeout
);
6930 case SERIAL_TIMEOUT
:
6933 if (started_error_output
)
6935 putchar_unfiltered ('\n');
6936 started_error_output
= 0;
6945 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6949 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6951 case SERIAL_TIMEOUT
:
6955 break; /* Retransmit buffer. */
6959 fprintf_unfiltered (gdb_stdlog
,
6960 "Packet instead of Ack, ignoring it\n");
6961 /* It's probably an old response sent because an ACK
6962 was lost. Gobble up the packet and ack it so it
6963 doesn't get retransmitted when we resend this
6966 serial_write (remote_desc
, "+", 1);
6967 continue; /* Now, go look for +. */
6974 /* If we got a notification, handle it, and go back to looking
6976 /* We've found the start of a notification. Now
6977 collect the data. */
6978 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6983 struct cleanup
*old_chain
;
6986 str
= escape_buffer (rs
->buf
, val
);
6987 old_chain
= make_cleanup (xfree
, str
);
6988 fprintf_unfiltered (gdb_stdlog
,
6989 " Notification received: %s\n",
6991 do_cleanups (old_chain
);
6993 handle_notification (rs
->buf
, val
);
6994 /* We're in sync now, rewait for the ack. */
7001 if (!started_error_output
)
7003 started_error_output
= 1;
7004 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7006 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7007 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7016 if (!started_error_output
)
7018 started_error_output
= 1;
7019 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7021 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7025 break; /* Here to retransmit. */
7029 /* This is wrong. If doing a long backtrace, the user should be
7030 able to get out next time we call QUIT, without anything as
7031 violent as interrupt_query. If we want to provide a way out of
7032 here without getting to the next QUIT, it should be based on
7033 hitting ^C twice as in remote_wait. */
7044 /* Come here after finding the start of a frame when we expected an
7045 ack. Do our best to discard the rest of this packet. */
7054 c
= readchar (remote_timeout
);
7057 case SERIAL_TIMEOUT
:
7058 /* Nothing we can do. */
7061 /* Discard the two bytes of checksum and stop. */
7062 c
= readchar (remote_timeout
);
7064 c
= readchar (remote_timeout
);
7067 case '*': /* Run length encoding. */
7068 /* Discard the repeat count. */
7069 c
= readchar (remote_timeout
);
7074 /* A regular character. */
7080 /* Come here after finding the start of the frame. Collect the rest
7081 into *BUF, verifying the checksum, length, and handling run-length
7082 compression. NUL terminate the buffer. If there is not enough room,
7083 expand *BUF using xrealloc.
7085 Returns -1 on error, number of characters in buffer (ignoring the
7086 trailing NULL) on success. (could be extended to return one of the
7087 SERIAL status indications). */
7090 read_frame (char **buf_p
,
7097 struct remote_state
*rs
= get_remote_state ();
7104 c
= readchar (remote_timeout
);
7107 case SERIAL_TIMEOUT
:
7109 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7113 fputs_filtered ("Saw new packet start in middle of old one\n",
7115 return -1; /* Start a new packet, count retries. */
7118 unsigned char pktcsum
;
7124 check_0
= readchar (remote_timeout
);
7126 check_1
= readchar (remote_timeout
);
7128 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7131 fputs_filtered ("Timeout in checksum, retrying\n",
7135 else if (check_0
< 0 || check_1
< 0)
7138 fputs_filtered ("Communication error in checksum\n",
7143 /* Don't recompute the checksum; with no ack packets we
7144 don't have any way to indicate a packet retransmission
7149 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7150 if (csum
== pktcsum
)
7155 struct cleanup
*old_chain
;
7158 str
= escape_buffer (buf
, bc
);
7159 old_chain
= make_cleanup (xfree
, str
);
7160 fprintf_unfiltered (gdb_stdlog
,
7161 "Bad checksum, sentsum=0x%x, "
7162 "csum=0x%x, buf=%s\n",
7163 pktcsum
, csum
, str
);
7164 do_cleanups (old_chain
);
7166 /* Number of characters in buffer ignoring trailing
7170 case '*': /* Run length encoding. */
7175 c
= readchar (remote_timeout
);
7177 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7179 /* The character before ``*'' is repeated. */
7181 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7183 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7185 /* Make some more room in the buffer. */
7186 *sizeof_buf
+= repeat
;
7187 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7191 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7197 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7201 if (bc
>= *sizeof_buf
- 1)
7203 /* Make some more room in the buffer. */
7205 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7216 /* Read a packet from the remote machine, with error checking, and
7217 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7218 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7219 rather than timing out; this is used (in synchronous mode) to wait
7220 for a target that is is executing user code to stop. */
7221 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7222 don't have to change all the calls to getpkt to deal with the
7223 return value, because at the moment I don't know what the right
7224 thing to do it for those. */
7232 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7236 /* Read a packet from the remote machine, with error checking, and
7237 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7238 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7239 rather than timing out; this is used (in synchronous mode) to wait
7240 for a target that is is executing user code to stop. If FOREVER ==
7241 0, this function is allowed to time out gracefully and return an
7242 indication of this to the caller. Otherwise return the number of
7243 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7244 enough reason to return to the caller. */
7247 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7248 int expecting_notif
)
7250 struct remote_state
*rs
= get_remote_state ();
7256 /* We're reading a new response. Make sure we don't look at a
7257 previously cached response. */
7258 rs
->cached_wait_status
= 0;
7260 strcpy (*buf
, "timeout");
7263 timeout
= watchdog
> 0 ? watchdog
: -1;
7264 else if (expecting_notif
)
7265 timeout
= 0; /* There should already be a char in the buffer. If
7268 timeout
= remote_timeout
;
7272 /* Process any number of notifications, and then return when
7276 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7278 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7280 /* This can loop forever if the remote side sends us
7281 characters continuously, but if it pauses, we'll get
7282 SERIAL_TIMEOUT from readchar because of timeout. Then
7283 we'll count that as a retry.
7285 Note that even when forever is set, we will only wait
7286 forever prior to the start of a packet. After that, we
7287 expect characters to arrive at a brisk pace. They should
7288 show up within remote_timeout intervals. */
7290 c
= readchar (timeout
);
7291 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7293 if (c
== SERIAL_TIMEOUT
)
7295 if (expecting_notif
)
7296 return -1; /* Don't complain, it's normal to not get
7297 anything in this case. */
7299 if (forever
) /* Watchdog went off? Kill the target. */
7303 error (_("Watchdog timeout has expired. Target detached."));
7306 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7310 /* We've found the start of a packet or notification.
7311 Now collect the data. */
7312 val
= read_frame (buf
, sizeof_buf
);
7317 serial_write (remote_desc
, "-", 1);
7320 if (tries
> MAX_TRIES
)
7322 /* We have tried hard enough, and just can't receive the
7323 packet/notification. Give up. */
7324 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7326 /* Skip the ack char if we're in no-ack mode. */
7327 if (!rs
->noack_mode
)
7328 serial_write (remote_desc
, "+", 1);
7332 /* If we got an ordinary packet, return that to our caller. */
7337 struct cleanup
*old_chain
;
7340 str
= escape_buffer (*buf
, val
);
7341 old_chain
= make_cleanup (xfree
, str
);
7342 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7343 do_cleanups (old_chain
);
7346 /* Skip the ack char if we're in no-ack mode. */
7347 if (!rs
->noack_mode
)
7348 serial_write (remote_desc
, "+", 1);
7352 /* If we got a notification, handle it, and go back to looking
7356 gdb_assert (c
== '%');
7360 struct cleanup
*old_chain
;
7363 str
= escape_buffer (*buf
, val
);
7364 old_chain
= make_cleanup (xfree
, str
);
7365 fprintf_unfiltered (gdb_stdlog
,
7366 " Notification received: %s\n",
7368 do_cleanups (old_chain
);
7371 handle_notification (*buf
, val
);
7373 /* Notifications require no acknowledgement. */
7375 if (expecting_notif
)
7382 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7384 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7388 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7390 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7394 /* A helper function that just calls putpkt; for type correctness. */
7397 putpkt_for_catch_errors (void *arg
)
7399 return putpkt (arg
);
7403 remote_kill (struct target_ops
*ops
)
7405 /* Use catch_errors so the user can quit from gdb even when we
7406 aren't on speaking terms with the remote system. */
7407 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7409 /* Don't wait for it to die. I'm not really sure it matters whether
7410 we do or not. For the existing stubs, kill is a noop. */
7411 target_mourn_inferior ();
7415 remote_vkill (int pid
, struct remote_state
*rs
)
7417 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7420 /* Tell the remote target to detach. */
7421 sprintf (rs
->buf
, "vKill;%x", pid
);
7423 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7425 if (packet_ok (rs
->buf
,
7426 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7428 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7435 extended_remote_kill (struct target_ops
*ops
)
7438 int pid
= ptid_get_pid (inferior_ptid
);
7439 struct remote_state
*rs
= get_remote_state ();
7441 res
= remote_vkill (pid
, rs
);
7442 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7444 /* Don't try 'k' on a multi-process aware stub -- it has no way
7445 to specify the pid. */
7449 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7450 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7453 /* Don't wait for it to die. I'm not really sure it matters whether
7454 we do or not. For the existing stubs, kill is a noop. */
7460 error (_("Can't kill process"));
7462 target_mourn_inferior ();
7466 remote_mourn (struct target_ops
*ops
)
7468 remote_mourn_1 (ops
);
7471 /* Worker function for remote_mourn. */
7473 remote_mourn_1 (struct target_ops
*target
)
7475 unpush_target (target
);
7477 /* remote_close takes care of doing most of the clean up. */
7478 generic_mourn_inferior ();
7482 extended_remote_mourn_1 (struct target_ops
*target
)
7484 struct remote_state
*rs
= get_remote_state ();
7486 /* In case we got here due to an error, but we're going to stay
7488 rs
->waiting_for_stop_reply
= 0;
7490 /* We're no longer interested in these events. */
7491 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7493 /* If the current general thread belonged to the process we just
7494 detached from or has exited, the remote side current general
7495 thread becomes undefined. Considering a case like this:
7497 - We just got here due to a detach.
7498 - The process that we're detaching from happens to immediately
7499 report a global breakpoint being hit in non-stop mode, in the
7500 same thread we had selected before.
7501 - GDB attaches to this process again.
7502 - This event happens to be the next event we handle.
7504 GDB would consider that the current general thread didn't need to
7505 be set on the stub side (with Hg), since for all it knew,
7506 GENERAL_THREAD hadn't changed.
7508 Notice that although in all-stop mode, the remote server always
7509 sets the current thread to the thread reporting the stop event,
7510 that doesn't happen in non-stop mode; in non-stop, the stub *must
7511 not* change the current thread when reporting a breakpoint hit,
7512 due to the decoupling of event reporting and event handling.
7514 To keep things simple, we always invalidate our notion of the
7516 record_currthread (minus_one_ptid
);
7518 /* Unlike "target remote", we do not want to unpush the target; then
7519 the next time the user says "run", we won't be connected. */
7521 /* Call common code to mark the inferior as not running. */
7522 generic_mourn_inferior ();
7524 if (!have_inferiors ())
7526 if (!remote_multi_process_p (rs
))
7528 /* Check whether the target is running now - some remote stubs
7529 automatically restart after kill. */
7531 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7533 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7535 /* Assume that the target has been restarted. Set
7536 inferior_ptid so that bits of core GDB realizes
7537 there's something here, e.g., so that the user can
7538 say "kill" again. */
7539 inferior_ptid
= magic_null_ptid
;
7546 extended_remote_mourn (struct target_ops
*ops
)
7548 extended_remote_mourn_1 (ops
);
7552 extended_remote_supports_disable_randomization (void)
7554 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7559 extended_remote_disable_randomization (int val
)
7561 struct remote_state
*rs
= get_remote_state ();
7564 sprintf (rs
->buf
, "QDisableRandomization:%x", val
);
7566 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7568 error (_("Target does not support QDisableRandomization."));
7569 if (strcmp (reply
, "OK") != 0)
7570 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7574 extended_remote_run (char *args
)
7576 struct remote_state
*rs
= get_remote_state ();
7579 /* If the user has disabled vRun support, or we have detected that
7580 support is not available, do not try it. */
7581 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7584 strcpy (rs
->buf
, "vRun;");
7585 len
= strlen (rs
->buf
);
7587 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7588 error (_("Remote file name too long for run packet"));
7589 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7591 gdb_assert (args
!= NULL
);
7594 struct cleanup
*back_to
;
7598 argv
= gdb_buildargv (args
);
7599 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7600 for (i
= 0; argv
[i
] != NULL
; i
++)
7602 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7603 error (_("Argument list too long for run packet"));
7604 rs
->buf
[len
++] = ';';
7605 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7607 do_cleanups (back_to
);
7610 rs
->buf
[len
++] = '\0';
7613 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7615 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7617 /* We have a wait response; we don't need it, though. All is well. */
7620 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7621 /* It wasn't disabled before, but it is now. */
7625 if (remote_exec_file
[0] == '\0')
7626 error (_("Running the default executable on the remote target failed; "
7627 "try \"set remote exec-file\"?"));
7629 error (_("Running \"%s\" on the remote target failed"),
7634 /* In the extended protocol we want to be able to do things like
7635 "run" and have them basically work as expected. So we need
7636 a special create_inferior function. We support changing the
7637 executable file and the command line arguments, but not the
7641 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7642 char **env
, int from_tty
)
7644 /* If running asynchronously, register the target file descriptor
7645 with the event loop. */
7646 if (target_can_async_p ())
7647 target_async (inferior_event_handler
, 0);
7649 /* Disable address space randomization if requested (and supported). */
7650 if (extended_remote_supports_disable_randomization ())
7651 extended_remote_disable_randomization (disable_randomization
);
7653 /* Now restart the remote server. */
7654 if (extended_remote_run (args
) == -1)
7656 /* vRun was not supported. Fail if we need it to do what the
7658 if (remote_exec_file
[0])
7659 error (_("Remote target does not support \"set remote exec-file\""));
7661 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7663 /* Fall back to "R". */
7664 extended_remote_restart ();
7667 if (!have_inferiors ())
7669 /* Clean up from the last time we ran, before we mark the target
7670 running again. This will mark breakpoints uninserted, and
7671 get_offsets may insert breakpoints. */
7672 init_thread_list ();
7673 init_wait_for_inferior ();
7676 /* Now mark the inferior as running before we do anything else. */
7677 inferior_ptid
= magic_null_ptid
;
7679 /* Now, if we have thread information, update inferior_ptid. */
7680 inferior_ptid
= remote_current_thread (inferior_ptid
);
7682 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7683 add_thread_silent (inferior_ptid
);
7685 /* Get updated offsets, if the stub uses qOffsets. */
7690 extended_remote_create_inferior (struct target_ops
*ops
,
7691 char *exec_file
, char *args
,
7692 char **env
, int from_tty
)
7694 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7698 /* Insert a breakpoint. On targets that have software breakpoint
7699 support, we ask the remote target to do the work; on targets
7700 which don't, we insert a traditional memory breakpoint. */
7703 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7704 struct bp_target_info
*bp_tgt
)
7706 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7707 If it succeeds, then set the support to PACKET_ENABLE. If it
7708 fails, and the user has explicitly requested the Z support then
7709 report an error, otherwise, mark it disabled and go on. */
7711 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7713 CORE_ADDR addr
= bp_tgt
->placed_address
;
7714 struct remote_state
*rs
;
7718 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7720 rs
= get_remote_state ();
7726 addr
= (ULONGEST
) remote_address_masked (addr
);
7727 p
+= hexnumstr (p
, addr
);
7728 sprintf (p
, ",%d", bpsize
);
7731 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7733 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7738 bp_tgt
->placed_address
= addr
;
7739 bp_tgt
->placed_size
= bpsize
;
7741 case PACKET_UNKNOWN
:
7746 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7750 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7751 struct bp_target_info
*bp_tgt
)
7753 CORE_ADDR addr
= bp_tgt
->placed_address
;
7754 struct remote_state
*rs
= get_remote_state ();
7756 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7764 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7765 p
+= hexnumstr (p
, addr
);
7766 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7769 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7771 return (rs
->buf
[0] == 'E');
7774 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7778 watchpoint_to_Z_packet (int type
)
7783 return Z_PACKET_WRITE_WP
;
7786 return Z_PACKET_READ_WP
;
7789 return Z_PACKET_ACCESS_WP
;
7792 internal_error (__FILE__
, __LINE__
,
7793 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7798 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7799 struct expression
*cond
)
7801 struct remote_state
*rs
= get_remote_state ();
7803 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7805 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7808 sprintf (rs
->buf
, "Z%x,", packet
);
7809 p
= strchr (rs
->buf
, '\0');
7810 addr
= remote_address_masked (addr
);
7811 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7812 sprintf (p
, ",%x", len
);
7815 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7817 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7821 case PACKET_UNKNOWN
:
7826 internal_error (__FILE__
, __LINE__
,
7827 _("remote_insert_watchpoint: reached end of function"));
7832 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7833 struct expression
*cond
)
7835 struct remote_state
*rs
= get_remote_state ();
7837 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7839 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7842 sprintf (rs
->buf
, "z%x,", packet
);
7843 p
= strchr (rs
->buf
, '\0');
7844 addr
= remote_address_masked (addr
);
7845 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7846 sprintf (p
, ",%x", len
);
7848 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7850 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7853 case PACKET_UNKNOWN
:
7858 internal_error (__FILE__
, __LINE__
,
7859 _("remote_remove_watchpoint: reached end of function"));
7863 int remote_hw_watchpoint_limit
= -1;
7864 int remote_hw_watchpoint_length_limit
= -1;
7865 int remote_hw_breakpoint_limit
= -1;
7868 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
7870 if (remote_hw_watchpoint_length_limit
== 0)
7872 else if (remote_hw_watchpoint_length_limit
< 0)
7874 else if (len
<= remote_hw_watchpoint_length_limit
)
7881 remote_check_watch_resources (int type
, int cnt
, int ot
)
7883 if (type
== bp_hardware_breakpoint
)
7885 if (remote_hw_breakpoint_limit
== 0)
7887 else if (remote_hw_breakpoint_limit
< 0)
7889 else if (cnt
<= remote_hw_breakpoint_limit
)
7894 if (remote_hw_watchpoint_limit
== 0)
7896 else if (remote_hw_watchpoint_limit
< 0)
7900 else if (cnt
<= remote_hw_watchpoint_limit
)
7907 remote_stopped_by_watchpoint (void)
7909 return remote_stopped_by_watchpoint_p
;
7913 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7917 if (remote_stopped_by_watchpoint ())
7919 *addr_p
= remote_watch_data_address
;
7928 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7929 struct bp_target_info
*bp_tgt
)
7932 struct remote_state
*rs
;
7935 /* The length field should be set to the size of a breakpoint
7936 instruction, even though we aren't inserting one ourselves. */
7938 gdbarch_remote_breakpoint_from_pc
7939 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7941 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7944 rs
= get_remote_state ();
7951 addr
= remote_address_masked (bp_tgt
->placed_address
);
7952 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7953 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7956 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7958 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7961 case PACKET_UNKNOWN
:
7966 internal_error (__FILE__
, __LINE__
,
7967 _("remote_insert_hw_breakpoint: reached end of function"));
7972 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7973 struct bp_target_info
*bp_tgt
)
7976 struct remote_state
*rs
= get_remote_state ();
7979 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7986 addr
= remote_address_masked (bp_tgt
->placed_address
);
7987 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7988 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7991 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7993 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7996 case PACKET_UNKNOWN
:
8001 internal_error (__FILE__
, __LINE__
,
8002 _("remote_remove_hw_breakpoint: reached end of function"));
8005 /* Table used by the crc32 function to calcuate the checksum. */
8007 static unsigned long crc32_table
[256] =
8010 static unsigned long
8011 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8013 if (!crc32_table
[1])
8015 /* Initialize the CRC table and the decoding table. */
8019 for (i
= 0; i
< 256; i
++)
8021 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8022 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8029 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8035 /* Verify memory using the "qCRC:" request. */
8038 remote_verify_memory (struct target_ops
*ops
,
8039 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8041 struct remote_state
*rs
= get_remote_state ();
8042 unsigned long host_crc
, target_crc
;
8045 /* FIXME: assumes lma can fit into long. */
8046 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8047 (long) lma
, (long) size
);
8050 /* Be clever; compute the host_crc before waiting for target
8052 host_crc
= crc32 (data
, size
, 0xffffffff);
8054 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8055 if (rs
->buf
[0] == 'E')
8058 if (rs
->buf
[0] != 'C')
8059 error (_("remote target does not support this operation"));
8061 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8062 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8064 return (host_crc
== target_crc
);
8067 /* compare-sections command
8069 With no arguments, compares each loadable section in the exec bfd
8070 with the same memory range on the target, and reports mismatches.
8071 Useful for verifying the image on the target against the exec file. */
8074 compare_sections_command (char *args
, int from_tty
)
8077 struct cleanup
*old_chain
;
8079 const char *sectname
;
8087 error (_("command cannot be used without an exec file"));
8089 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8091 if (!(s
->flags
& SEC_LOAD
))
8092 continue; /* Skip non-loadable section. */
8094 size
= bfd_get_section_size (s
);
8096 continue; /* Skip zero-length section. */
8098 sectname
= bfd_get_section_name (exec_bfd
, s
);
8099 if (args
&& strcmp (args
, sectname
) != 0)
8100 continue; /* Not the section selected by user. */
8102 matched
= 1; /* Do this section. */
8105 sectdata
= xmalloc (size
);
8106 old_chain
= make_cleanup (xfree
, sectdata
);
8107 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8109 res
= target_verify_memory (sectdata
, lma
, size
);
8112 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8113 paddress (target_gdbarch
, lma
),
8114 paddress (target_gdbarch
, lma
+ size
));
8116 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8117 paddress (target_gdbarch
, lma
),
8118 paddress (target_gdbarch
, lma
+ size
));
8120 printf_filtered ("matched.\n");
8123 printf_filtered ("MIS-MATCHED!\n");
8127 do_cleanups (old_chain
);
8130 warning (_("One or more sections of the remote executable does not match\n\
8131 the loaded file\n"));
8132 if (args
&& !matched
)
8133 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8136 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8137 into remote target. The number of bytes written to the remote
8138 target is returned, or -1 for error. */
8141 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8142 const char *annex
, const gdb_byte
*writebuf
,
8143 ULONGEST offset
, LONGEST len
,
8144 struct packet_config
*packet
)
8148 struct remote_state
*rs
= get_remote_state ();
8149 int max_size
= get_memory_write_packet_size ();
8151 if (packet
->support
== PACKET_DISABLE
)
8154 /* Insert header. */
8155 i
= snprintf (rs
->buf
, max_size
,
8156 "qXfer:%s:write:%s:%s:",
8157 object_name
, annex
? annex
: "",
8158 phex_nz (offset
, sizeof offset
));
8159 max_size
-= (i
+ 1);
8161 /* Escape as much data as fits into rs->buf. */
8162 buf_len
= remote_escape_output
8163 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8165 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8166 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8167 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8170 unpack_varlen_hex (rs
->buf
, &n
);
8174 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8175 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8176 number of bytes read is returned, or 0 for EOF, or -1 for error.
8177 The number of bytes read may be less than LEN without indicating an
8178 EOF. PACKET is checked and updated to indicate whether the remote
8179 target supports this object. */
8182 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8184 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8185 struct packet_config
*packet
)
8187 static char *finished_object
;
8188 static char *finished_annex
;
8189 static ULONGEST finished_offset
;
8191 struct remote_state
*rs
= get_remote_state ();
8192 LONGEST i
, n
, packet_len
;
8194 if (packet
->support
== PACKET_DISABLE
)
8197 /* Check whether we've cached an end-of-object packet that matches
8199 if (finished_object
)
8201 if (strcmp (object_name
, finished_object
) == 0
8202 && strcmp (annex
? annex
: "", finished_annex
) == 0
8203 && offset
== finished_offset
)
8206 /* Otherwise, we're now reading something different. Discard
8208 xfree (finished_object
);
8209 xfree (finished_annex
);
8210 finished_object
= NULL
;
8211 finished_annex
= NULL
;
8214 /* Request only enough to fit in a single packet. The actual data
8215 may not, since we don't know how much of it will need to be escaped;
8216 the target is free to respond with slightly less data. We subtract
8217 five to account for the response type and the protocol frame. */
8218 n
= min (get_remote_packet_size () - 5, len
);
8219 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8220 object_name
, annex
? annex
: "",
8221 phex_nz (offset
, sizeof offset
),
8222 phex_nz (n
, sizeof n
));
8223 i
= putpkt (rs
->buf
);
8228 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8229 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8232 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8233 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8235 /* 'm' means there is (or at least might be) more data after this
8236 batch. That does not make sense unless there's at least one byte
8237 of data in this reply. */
8238 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8239 error (_("Remote qXfer reply contained no data."));
8241 /* Got some data. */
8242 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8244 /* 'l' is an EOF marker, possibly including a final block of data,
8245 or possibly empty. If we have the final block of a non-empty
8246 object, record this fact to bypass a subsequent partial read. */
8247 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8249 finished_object
= xstrdup (object_name
);
8250 finished_annex
= xstrdup (annex
? annex
: "");
8251 finished_offset
= offset
+ i
;
8258 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8259 const char *annex
, gdb_byte
*readbuf
,
8260 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8262 struct remote_state
*rs
;
8267 set_remote_traceframe ();
8268 set_general_thread (inferior_ptid
);
8270 rs
= get_remote_state ();
8272 /* Handle memory using the standard memory routines. */
8273 if (object
== TARGET_OBJECT_MEMORY
)
8279 /* If the remote target is connected but not running, we should
8280 pass this request down to a lower stratum (e.g. the executable
8282 if (!target_has_execution
)
8285 if (writebuf
!= NULL
)
8286 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8288 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8292 else if (xfered
== 0 && errno
== 0)
8298 /* Handle SPU memory using qxfer packets. */
8299 if (object
== TARGET_OBJECT_SPU
)
8302 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8303 &remote_protocol_packets
8304 [PACKET_qXfer_spu_read
]);
8306 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8307 &remote_protocol_packets
8308 [PACKET_qXfer_spu_write
]);
8311 /* Handle extra signal info using qxfer packets. */
8312 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8315 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8316 &remote_protocol_packets
8317 [PACKET_qXfer_siginfo_read
]);
8319 return remote_write_qxfer (ops
, "siginfo", annex
,
8320 writebuf
, offset
, len
,
8321 &remote_protocol_packets
8322 [PACKET_qXfer_siginfo_write
]);
8325 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8328 return remote_read_qxfer (ops
, "statictrace", annex
,
8329 readbuf
, offset
, len
,
8330 &remote_protocol_packets
8331 [PACKET_qXfer_statictrace_read
]);
8336 /* Only handle flash writes. */
8337 if (writebuf
!= NULL
)
8343 case TARGET_OBJECT_FLASH
:
8344 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8348 else if (xfered
== 0 && errno
== 0)
8358 /* Map pre-existing objects onto letters. DO NOT do this for new
8359 objects!!! Instead specify new query packets. */
8362 case TARGET_OBJECT_AVR
:
8366 case TARGET_OBJECT_AUXV
:
8367 gdb_assert (annex
== NULL
);
8368 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8369 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8371 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8372 return remote_read_qxfer
8373 (ops
, "features", annex
, readbuf
, offset
, len
,
8374 &remote_protocol_packets
[PACKET_qXfer_features
]);
8376 case TARGET_OBJECT_LIBRARIES
:
8377 return remote_read_qxfer
8378 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8379 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8381 case TARGET_OBJECT_LIBRARIES_SVR4
:
8382 return remote_read_qxfer
8383 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8384 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8386 case TARGET_OBJECT_MEMORY_MAP
:
8387 gdb_assert (annex
== NULL
);
8388 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8389 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8391 case TARGET_OBJECT_OSDATA
:
8392 /* Should only get here if we're connected. */
8393 gdb_assert (remote_desc
);
8394 return remote_read_qxfer
8395 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8396 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8398 case TARGET_OBJECT_THREADS
:
8399 gdb_assert (annex
== NULL
);
8400 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8401 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8403 case TARGET_OBJECT_TRACEFRAME_INFO
:
8404 gdb_assert (annex
== NULL
);
8405 return remote_read_qxfer
8406 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8407 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8409 case TARGET_OBJECT_FDPIC
:
8410 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8411 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8416 /* Note: a zero OFFSET and LEN can be used to query the minimum
8418 if (offset
== 0 && len
== 0)
8419 return (get_remote_packet_size ());
8420 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8421 large enough let the caller deal with it. */
8422 if (len
< get_remote_packet_size ())
8424 len
= get_remote_packet_size ();
8426 /* Except for querying the minimum buffer size, target must be open. */
8428 error (_("remote query is only available after target open"));
8430 gdb_assert (annex
!= NULL
);
8431 gdb_assert (readbuf
!= NULL
);
8437 /* We used one buffer char for the remote protocol q command and
8438 another for the query type. As the remote protocol encapsulation
8439 uses 4 chars plus one extra in case we are debugging
8440 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8443 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8445 /* Bad caller may have sent forbidden characters. */
8446 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8451 gdb_assert (annex
[i
] == '\0');
8453 i
= putpkt (rs
->buf
);
8457 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8458 strcpy ((char *) readbuf
, rs
->buf
);
8460 return strlen ((char *) readbuf
);
8464 remote_search_memory (struct target_ops
* ops
,
8465 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8466 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8467 CORE_ADDR
*found_addrp
)
8469 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8470 struct remote_state
*rs
= get_remote_state ();
8471 int max_size
= get_memory_write_packet_size ();
8472 struct packet_config
*packet
=
8473 &remote_protocol_packets
[PACKET_qSearch_memory
];
8474 /* Number of packet bytes used to encode the pattern;
8475 this could be more than PATTERN_LEN due to escape characters. */
8476 int escaped_pattern_len
;
8477 /* Amount of pattern that was encodable in the packet. */
8478 int used_pattern_len
;
8481 ULONGEST found_addr
;
8483 /* Don't go to the target if we don't have to.
8484 This is done before checking packet->support to avoid the possibility that
8485 a success for this edge case means the facility works in general. */
8486 if (pattern_len
> search_space_len
)
8488 if (pattern_len
== 0)
8490 *found_addrp
= start_addr
;
8494 /* If we already know the packet isn't supported, fall back to the simple
8495 way of searching memory. */
8497 if (packet
->support
== PACKET_DISABLE
)
8499 /* Target doesn't provided special support, fall back and use the
8500 standard support (copy memory and do the search here). */
8501 return simple_search_memory (ops
, start_addr
, search_space_len
,
8502 pattern
, pattern_len
, found_addrp
);
8505 /* Insert header. */
8506 i
= snprintf (rs
->buf
, max_size
,
8507 "qSearch:memory:%s;%s;",
8508 phex_nz (start_addr
, addr_size
),
8509 phex_nz (search_space_len
, sizeof (search_space_len
)));
8510 max_size
-= (i
+ 1);
8512 /* Escape as much data as fits into rs->buf. */
8513 escaped_pattern_len
=
8514 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8515 &used_pattern_len
, max_size
);
8517 /* Bail if the pattern is too large. */
8518 if (used_pattern_len
!= pattern_len
)
8519 error (_("Pattern is too large to transmit to remote target."));
8521 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8522 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8523 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8525 /* The request may not have worked because the command is not
8526 supported. If so, fall back to the simple way. */
8527 if (packet
->support
== PACKET_DISABLE
)
8529 return simple_search_memory (ops
, start_addr
, search_space_len
,
8530 pattern
, pattern_len
, found_addrp
);
8535 if (rs
->buf
[0] == '0')
8537 else if (rs
->buf
[0] == '1')
8540 if (rs
->buf
[1] != ',')
8541 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8542 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8543 *found_addrp
= found_addr
;
8546 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8552 remote_rcmd (char *command
,
8553 struct ui_file
*outbuf
)
8555 struct remote_state
*rs
= get_remote_state ();
8559 error (_("remote rcmd is only available after target open"));
8561 /* Send a NULL command across as an empty command. */
8562 if (command
== NULL
)
8565 /* The query prefix. */
8566 strcpy (rs
->buf
, "qRcmd,");
8567 p
= strchr (rs
->buf
, '\0');
8569 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8570 > get_remote_packet_size ())
8571 error (_("\"monitor\" command ``%s'' is too long."), command
);
8573 /* Encode the actual command. */
8574 bin2hex ((gdb_byte
*) command
, p
, 0);
8576 if (putpkt (rs
->buf
) < 0)
8577 error (_("Communication problem with target."));
8579 /* get/display the response */
8584 /* XXX - see also remote_get_noisy_reply(). */
8586 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8589 error (_("Target does not support this command."));
8590 if (buf
[0] == 'O' && buf
[1] != 'K')
8592 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8595 if (strcmp (buf
, "OK") == 0)
8597 if (strlen (buf
) == 3 && buf
[0] == 'E'
8598 && isdigit (buf
[1]) && isdigit (buf
[2]))
8600 error (_("Protocol error with Rcmd"));
8602 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8604 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8606 fputc_unfiltered (c
, outbuf
);
8612 static VEC(mem_region_s
) *
8613 remote_memory_map (struct target_ops
*ops
)
8615 VEC(mem_region_s
) *result
= NULL
;
8616 char *text
= target_read_stralloc (¤t_target
,
8617 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8621 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8623 result
= parse_memory_map (text
);
8624 do_cleanups (back_to
);
8631 packet_command (char *args
, int from_tty
)
8633 struct remote_state
*rs
= get_remote_state ();
8636 error (_("command can only be used with remote target"));
8639 error (_("remote-packet command requires packet text as argument"));
8641 puts_filtered ("sending: ");
8642 print_packet (args
);
8643 puts_filtered ("\n");
8646 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8647 puts_filtered ("received: ");
8648 print_packet (rs
->buf
);
8649 puts_filtered ("\n");
8653 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8655 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8657 static void threadset_test_cmd (char *cmd
, int tty
);
8659 static void threadalive_test (char *cmd
, int tty
);
8661 static void threadlist_test_cmd (char *cmd
, int tty
);
8663 int get_and_display_threadinfo (threadref
*ref
);
8665 static void threadinfo_test_cmd (char *cmd
, int tty
);
8667 static int thread_display_step (threadref
*ref
, void *context
);
8669 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8671 static void init_remote_threadtests (void);
8673 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8676 threadset_test_cmd (char *cmd
, int tty
)
8678 int sample_thread
= SAMPLE_THREAD
;
8680 printf_filtered (_("Remote threadset test\n"));
8681 set_general_thread (sample_thread
);
8686 threadalive_test (char *cmd
, int tty
)
8688 int sample_thread
= SAMPLE_THREAD
;
8689 int pid
= ptid_get_pid (inferior_ptid
);
8690 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8692 if (remote_thread_alive (ptid
))
8693 printf_filtered ("PASS: Thread alive test\n");
8695 printf_filtered ("FAIL: Thread alive test\n");
8698 void output_threadid (char *title
, threadref
*ref
);
8701 output_threadid (char *title
, threadref
*ref
)
8705 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8707 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8711 threadlist_test_cmd (char *cmd
, int tty
)
8714 threadref nextthread
;
8715 int done
, result_count
;
8716 threadref threadlist
[3];
8718 printf_filtered ("Remote Threadlist test\n");
8719 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8720 &result_count
, &threadlist
[0]))
8721 printf_filtered ("FAIL: threadlist test\n");
8724 threadref
*scan
= threadlist
;
8725 threadref
*limit
= scan
+ result_count
;
8727 while (scan
< limit
)
8728 output_threadid (" thread ", scan
++);
8733 display_thread_info (struct gdb_ext_thread_info
*info
)
8735 output_threadid ("Threadid: ", &info
->threadid
);
8736 printf_filtered ("Name: %s\n ", info
->shortname
);
8737 printf_filtered ("State: %s\n", info
->display
);
8738 printf_filtered ("other: %s\n\n", info
->more_display
);
8742 get_and_display_threadinfo (threadref
*ref
)
8746 struct gdb_ext_thread_info threadinfo
;
8748 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8749 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8750 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8751 display_thread_info (&threadinfo
);
8756 threadinfo_test_cmd (char *cmd
, int tty
)
8758 int athread
= SAMPLE_THREAD
;
8762 int_to_threadref (&thread
, athread
);
8763 printf_filtered ("Remote Threadinfo test\n");
8764 if (!get_and_display_threadinfo (&thread
))
8765 printf_filtered ("FAIL cannot get thread info\n");
8769 thread_display_step (threadref
*ref
, void *context
)
8771 /* output_threadid(" threadstep ",ref); *//* simple test */
8772 return get_and_display_threadinfo (ref
);
8776 threadlist_update_test_cmd (char *cmd
, int tty
)
8778 printf_filtered ("Remote Threadlist update test\n");
8779 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8783 init_remote_threadtests (void)
8785 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8786 _("Fetch and print the remote list of "
8787 "thread identifiers, one pkt only"));
8788 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8789 _("Fetch and display info about one thread"));
8790 add_com ("tset", class_obscure
, threadset_test_cmd
,
8791 _("Test setting to a different thread"));
8792 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8793 _("Iterate through updating all remote thread info"));
8794 add_com ("talive", class_obscure
, threadalive_test
,
8795 _(" Remote thread alive test "));
8800 /* Convert a thread ID to a string. Returns the string in a static
8804 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8806 static char buf
[64];
8807 struct remote_state
*rs
= get_remote_state ();
8809 if (ptid_is_pid (ptid
))
8811 /* Printing an inferior target id. */
8813 /* When multi-process extensions are off, there's no way in the
8814 remote protocol to know the remote process id, if there's any
8815 at all. There's one exception --- when we're connected with
8816 target extended-remote, and we manually attached to a process
8817 with "attach PID". We don't record anywhere a flag that
8818 allows us to distinguish that case from the case of
8819 connecting with extended-remote and the stub already being
8820 attached to a process, and reporting yes to qAttached, hence
8821 no smart special casing here. */
8822 if (!remote_multi_process_p (rs
))
8824 xsnprintf (buf
, sizeof buf
, "Remote target");
8828 return normal_pid_to_str (ptid
);
8832 if (ptid_equal (magic_null_ptid
, ptid
))
8833 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8834 else if (rs
->extended
&& remote_multi_process_p (rs
))
8835 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8836 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8838 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8839 ptid_get_tid (ptid
));
8844 /* Get the address of the thread local variable in OBJFILE which is
8845 stored at OFFSET within the thread local storage for thread PTID. */
8848 remote_get_thread_local_address (struct target_ops
*ops
,
8849 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8851 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8853 struct remote_state
*rs
= get_remote_state ();
8855 char *endp
= rs
->buf
+ get_remote_packet_size ();
8856 enum packet_result result
;
8858 strcpy (p
, "qGetTLSAddr:");
8860 p
= write_ptid (p
, endp
, ptid
);
8862 p
+= hexnumstr (p
, offset
);
8864 p
+= hexnumstr (p
, lm
);
8868 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8869 result
= packet_ok (rs
->buf
,
8870 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8871 if (result
== PACKET_OK
)
8875 unpack_varlen_hex (rs
->buf
, &result
);
8878 else if (result
== PACKET_UNKNOWN
)
8879 throw_error (TLS_GENERIC_ERROR
,
8880 _("Remote target doesn't support qGetTLSAddr packet"));
8882 throw_error (TLS_GENERIC_ERROR
,
8883 _("Remote target failed to process qGetTLSAddr request"));
8886 throw_error (TLS_GENERIC_ERROR
,
8887 _("TLS not supported or disabled on this target"));
8892 /* Provide thread local base, i.e. Thread Information Block address.
8893 Returns 1 if ptid is found and thread_local_base is non zero. */
8896 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8898 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8900 struct remote_state
*rs
= get_remote_state ();
8902 char *endp
= rs
->buf
+ get_remote_packet_size ();
8903 enum packet_result result
;
8905 strcpy (p
, "qGetTIBAddr:");
8907 p
= write_ptid (p
, endp
, ptid
);
8911 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8912 result
= packet_ok (rs
->buf
,
8913 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8914 if (result
== PACKET_OK
)
8918 unpack_varlen_hex (rs
->buf
, &result
);
8920 *addr
= (CORE_ADDR
) result
;
8923 else if (result
== PACKET_UNKNOWN
)
8924 error (_("Remote target doesn't support qGetTIBAddr packet"));
8926 error (_("Remote target failed to process qGetTIBAddr request"));
8929 error (_("qGetTIBAddr not supported or disabled on this target"));
8934 /* Support for inferring a target description based on the current
8935 architecture and the size of a 'g' packet. While the 'g' packet
8936 can have any size (since optional registers can be left off the
8937 end), some sizes are easily recognizable given knowledge of the
8938 approximate architecture. */
8940 struct remote_g_packet_guess
8943 const struct target_desc
*tdesc
;
8945 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8946 DEF_VEC_O(remote_g_packet_guess_s
);
8948 struct remote_g_packet_data
8950 VEC(remote_g_packet_guess_s
) *guesses
;
8953 static struct gdbarch_data
*remote_g_packet_data_handle
;
8956 remote_g_packet_data_init (struct obstack
*obstack
)
8958 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8962 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8963 const struct target_desc
*tdesc
)
8965 struct remote_g_packet_data
*data
8966 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8967 struct remote_g_packet_guess new_guess
, *guess
;
8970 gdb_assert (tdesc
!= NULL
);
8973 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8975 if (guess
->bytes
== bytes
)
8976 internal_error (__FILE__
, __LINE__
,
8977 _("Duplicate g packet description added for size %d"),
8980 new_guess
.bytes
= bytes
;
8981 new_guess
.tdesc
= tdesc
;
8982 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8985 /* Return 1 if remote_read_description would do anything on this target
8986 and architecture, 0 otherwise. */
8989 remote_read_description_p (struct target_ops
*target
)
8991 struct remote_g_packet_data
*data
8992 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8994 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9000 static const struct target_desc
*
9001 remote_read_description (struct target_ops
*target
)
9003 struct remote_g_packet_data
*data
9004 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9006 /* Do not try this during initial connection, when we do not know
9007 whether there is a running but stopped thread. */
9008 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9011 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9013 struct remote_g_packet_guess
*guess
;
9015 int bytes
= send_g_packet ();
9018 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9020 if (guess
->bytes
== bytes
)
9021 return guess
->tdesc
;
9023 /* We discard the g packet. A minor optimization would be to
9024 hold on to it, and fill the register cache once we have selected
9025 an architecture, but it's too tricky to do safely. */
9031 /* Remote file transfer support. This is host-initiated I/O, not
9032 target-initiated; for target-initiated, see remote-fileio.c. */
9034 /* If *LEFT is at least the length of STRING, copy STRING to
9035 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9036 decrease *LEFT. Otherwise raise an error. */
9039 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9041 int len
= strlen (string
);
9044 error (_("Packet too long for target."));
9046 memcpy (*buffer
, string
, len
);
9050 /* NUL-terminate the buffer as a convenience, if there is
9056 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
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_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9064 if (2 * len
> *left
)
9065 error (_("Packet too long for target."));
9067 bin2hex (bytes
, *buffer
, len
);
9071 /* NUL-terminate the buffer as a convenience, if there is
9077 /* If *LEFT is large enough, convert VALUE to hex and add it to
9078 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9079 decrease *LEFT. Otherwise raise an error. */
9082 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9084 int len
= hexnumlen (value
);
9087 error (_("Packet too long for target."));
9089 hexnumstr (*buffer
, value
);
9093 /* NUL-terminate the buffer as a convenience, if there is
9099 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9100 value, *REMOTE_ERRNO to the remote error number or zero if none
9101 was included, and *ATTACHMENT to point to the start of the annex
9102 if any. The length of the packet isn't needed here; there may
9103 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9105 Return 0 if the packet could be parsed, -1 if it could not. If
9106 -1 is returned, the other variables may not be initialized. */
9109 remote_hostio_parse_result (char *buffer
, int *retcode
,
9110 int *remote_errno
, char **attachment
)
9117 if (buffer
[0] != 'F')
9121 *retcode
= strtol (&buffer
[1], &p
, 16);
9122 if (errno
!= 0 || p
== &buffer
[1])
9125 /* Check for ",errno". */
9129 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9130 if (errno
!= 0 || p
+ 1 == p2
)
9135 /* Check for ";attachment". If there is no attachment, the
9136 packet should end here. */
9139 *attachment
= p
+ 1;
9142 else if (*p
== '\0')
9148 /* Send a prepared I/O packet to the target and read its response.
9149 The prepared packet is in the global RS->BUF before this function
9150 is called, and the answer is there when we return.
9152 COMMAND_BYTES is the length of the request to send, which may include
9153 binary data. WHICH_PACKET is the packet configuration to check
9154 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9155 is set to the error number and -1 is returned. Otherwise the value
9156 returned by the function is returned.
9158 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9159 attachment is expected; an error will be reported if there's a
9160 mismatch. If one is found, *ATTACHMENT will be set to point into
9161 the packet buffer and *ATTACHMENT_LEN will be set to the
9162 attachment's length. */
9165 remote_hostio_send_command (int command_bytes
, int which_packet
,
9166 int *remote_errno
, char **attachment
,
9167 int *attachment_len
)
9169 struct remote_state
*rs
= get_remote_state ();
9170 int ret
, bytes_read
;
9171 char *attachment_tmp
;
9174 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9176 *remote_errno
= FILEIO_ENOSYS
;
9180 putpkt_binary (rs
->buf
, command_bytes
);
9181 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9183 /* If it timed out, something is wrong. Don't try to parse the
9187 *remote_errno
= FILEIO_EINVAL
;
9191 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9194 *remote_errno
= FILEIO_EINVAL
;
9196 case PACKET_UNKNOWN
:
9197 *remote_errno
= FILEIO_ENOSYS
;
9203 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9206 *remote_errno
= FILEIO_EINVAL
;
9210 /* Make sure we saw an attachment if and only if we expected one. */
9211 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9212 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9214 *remote_errno
= FILEIO_EINVAL
;
9218 /* If an attachment was found, it must point into the packet buffer;
9219 work out how many bytes there were. */
9220 if (attachment_tmp
!= NULL
)
9222 *attachment
= attachment_tmp
;
9223 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9229 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9230 remote file descriptor, or -1 if an error occurs (and set
9234 remote_hostio_open (const char *filename
, int flags
, int mode
,
9237 struct remote_state
*rs
= get_remote_state ();
9239 int left
= get_remote_packet_size () - 1;
9241 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9243 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9245 remote_buffer_add_string (&p
, &left
, ",");
9247 remote_buffer_add_int (&p
, &left
, flags
);
9248 remote_buffer_add_string (&p
, &left
, ",");
9250 remote_buffer_add_int (&p
, &left
, mode
);
9252 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9253 remote_errno
, NULL
, NULL
);
9256 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9257 Return the number of bytes written, or -1 if an error occurs (and
9258 set *REMOTE_ERRNO). */
9261 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9262 ULONGEST offset
, int *remote_errno
)
9264 struct remote_state
*rs
= get_remote_state ();
9266 int left
= get_remote_packet_size ();
9269 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9271 remote_buffer_add_int (&p
, &left
, fd
);
9272 remote_buffer_add_string (&p
, &left
, ",");
9274 remote_buffer_add_int (&p
, &left
, offset
);
9275 remote_buffer_add_string (&p
, &left
, ",");
9277 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9278 get_remote_packet_size () - (p
- rs
->buf
));
9280 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9281 remote_errno
, NULL
, NULL
);
9284 /* Read up to LEN bytes FD on the remote target into READ_BUF
9285 Return the number of bytes read, or -1 if an error occurs (and
9286 set *REMOTE_ERRNO). */
9289 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9290 ULONGEST offset
, int *remote_errno
)
9292 struct remote_state
*rs
= get_remote_state ();
9295 int left
= get_remote_packet_size ();
9296 int ret
, attachment_len
;
9299 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9301 remote_buffer_add_int (&p
, &left
, fd
);
9302 remote_buffer_add_string (&p
, &left
, ",");
9304 remote_buffer_add_int (&p
, &left
, len
);
9305 remote_buffer_add_string (&p
, &left
, ",");
9307 remote_buffer_add_int (&p
, &left
, offset
);
9309 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9310 remote_errno
, &attachment
,
9316 read_len
= remote_unescape_input (attachment
, attachment_len
,
9318 if (read_len
!= ret
)
9319 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9324 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9325 (and set *REMOTE_ERRNO). */
9328 remote_hostio_close (int fd
, int *remote_errno
)
9330 struct remote_state
*rs
= get_remote_state ();
9332 int left
= get_remote_packet_size () - 1;
9334 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9336 remote_buffer_add_int (&p
, &left
, fd
);
9338 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9339 remote_errno
, NULL
, NULL
);
9342 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9343 occurs (and set *REMOTE_ERRNO). */
9346 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9348 struct remote_state
*rs
= get_remote_state ();
9350 int left
= get_remote_packet_size () - 1;
9352 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9354 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9357 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9358 remote_errno
, NULL
, NULL
);
9362 remote_fileio_errno_to_host (int errnum
)
9386 case FILEIO_ENOTDIR
:
9406 case FILEIO_ENAMETOOLONG
:
9407 return ENAMETOOLONG
;
9413 remote_hostio_error (int errnum
)
9415 int host_error
= remote_fileio_errno_to_host (errnum
);
9417 if (host_error
== -1)
9418 error (_("Unknown remote I/O error %d"), errnum
);
9420 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9424 remote_hostio_close_cleanup (void *opaque
)
9426 int fd
= *(int *) opaque
;
9429 remote_hostio_close (fd
, &remote_errno
);
9434 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9436 const char *filename
= bfd_get_filename (abfd
);
9437 int fd
, remote_errno
;
9440 gdb_assert (remote_filename_p (filename
));
9442 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9445 errno
= remote_fileio_errno_to_host (remote_errno
);
9446 bfd_set_error (bfd_error_system_call
);
9450 stream
= xmalloc (sizeof (int));
9456 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9458 int fd
= *(int *)stream
;
9463 /* Ignore errors on close; these may happen if the remote
9464 connection was already torn down. */
9465 remote_hostio_close (fd
, &remote_errno
);
9471 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9472 file_ptr nbytes
, file_ptr offset
)
9474 int fd
= *(int *)stream
;
9476 file_ptr pos
, bytes
;
9479 while (nbytes
> pos
)
9481 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9482 offset
+ pos
, &remote_errno
);
9484 /* Success, but no bytes, means end-of-file. */
9488 errno
= remote_fileio_errno_to_host (remote_errno
);
9489 bfd_set_error (bfd_error_system_call
);
9500 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9502 /* FIXME: We should probably implement remote_hostio_stat. */
9503 sb
->st_size
= INT_MAX
;
9508 remote_filename_p (const char *filename
)
9510 return strncmp (filename
, "remote:", 7) == 0;
9514 remote_bfd_open (const char *remote_file
, const char *target
)
9516 return bfd_openr_iovec (remote_file
, target
,
9517 remote_bfd_iovec_open
, NULL
,
9518 remote_bfd_iovec_pread
,
9519 remote_bfd_iovec_close
,
9520 remote_bfd_iovec_stat
);
9524 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9526 struct cleanup
*back_to
, *close_cleanup
;
9527 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9530 int bytes_in_buffer
;
9535 error (_("command can only be used with remote target"));
9537 file
= fopen (local_file
, "rb");
9539 perror_with_name (local_file
);
9540 back_to
= make_cleanup_fclose (file
);
9542 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9544 0700, &remote_errno
);
9546 remote_hostio_error (remote_errno
);
9548 /* Send up to this many bytes at once. They won't all fit in the
9549 remote packet limit, so we'll transfer slightly fewer. */
9550 io_size
= get_remote_packet_size ();
9551 buffer
= xmalloc (io_size
);
9552 make_cleanup (xfree
, buffer
);
9554 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9556 bytes_in_buffer
= 0;
9559 while (bytes_in_buffer
|| !saw_eof
)
9563 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9564 io_size
- bytes_in_buffer
,
9569 error (_("Error reading %s."), local_file
);
9572 /* EOF. Unless there is something still in the
9573 buffer from the last iteration, we are done. */
9575 if (bytes_in_buffer
== 0)
9583 bytes
+= bytes_in_buffer
;
9584 bytes_in_buffer
= 0;
9586 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9587 offset
, &remote_errno
);
9590 remote_hostio_error (remote_errno
);
9591 else if (retcode
== 0)
9592 error (_("Remote write of %d bytes returned 0!"), bytes
);
9593 else if (retcode
< bytes
)
9595 /* Short write. Save the rest of the read data for the next
9597 bytes_in_buffer
= bytes
- retcode
;
9598 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9604 discard_cleanups (close_cleanup
);
9605 if (remote_hostio_close (fd
, &remote_errno
))
9606 remote_hostio_error (remote_errno
);
9609 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9610 do_cleanups (back_to
);
9614 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9616 struct cleanup
*back_to
, *close_cleanup
;
9617 int fd
, remote_errno
, bytes
, io_size
;
9623 error (_("command can only be used with remote target"));
9625 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9627 remote_hostio_error (remote_errno
);
9629 file
= fopen (local_file
, "wb");
9631 perror_with_name (local_file
);
9632 back_to
= make_cleanup_fclose (file
);
9634 /* Send up to this many bytes at once. They won't all fit in the
9635 remote packet limit, so we'll transfer slightly fewer. */
9636 io_size
= get_remote_packet_size ();
9637 buffer
= xmalloc (io_size
);
9638 make_cleanup (xfree
, buffer
);
9640 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9645 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9647 /* Success, but no bytes, means end-of-file. */
9650 remote_hostio_error (remote_errno
);
9654 bytes
= fwrite (buffer
, 1, bytes
, file
);
9656 perror_with_name (local_file
);
9659 discard_cleanups (close_cleanup
);
9660 if (remote_hostio_close (fd
, &remote_errno
))
9661 remote_hostio_error (remote_errno
);
9664 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9665 do_cleanups (back_to
);
9669 remote_file_delete (const char *remote_file
, int from_tty
)
9671 int retcode
, remote_errno
;
9674 error (_("command can only be used with remote target"));
9676 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9678 remote_hostio_error (remote_errno
);
9681 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9685 remote_put_command (char *args
, int from_tty
)
9687 struct cleanup
*back_to
;
9691 error_no_arg (_("file to put"));
9693 argv
= gdb_buildargv (args
);
9694 back_to
= make_cleanup_freeargv (argv
);
9695 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9696 error (_("Invalid parameters to remote put"));
9698 remote_file_put (argv
[0], argv
[1], from_tty
);
9700 do_cleanups (back_to
);
9704 remote_get_command (char *args
, int from_tty
)
9706 struct cleanup
*back_to
;
9710 error_no_arg (_("file to get"));
9712 argv
= gdb_buildargv (args
);
9713 back_to
= make_cleanup_freeargv (argv
);
9714 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9715 error (_("Invalid parameters to remote get"));
9717 remote_file_get (argv
[0], argv
[1], from_tty
);
9719 do_cleanups (back_to
);
9723 remote_delete_command (char *args
, int from_tty
)
9725 struct cleanup
*back_to
;
9729 error_no_arg (_("file to delete"));
9731 argv
= gdb_buildargv (args
);
9732 back_to
= make_cleanup_freeargv (argv
);
9733 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9734 error (_("Invalid parameters to remote delete"));
9736 remote_file_delete (argv
[0], from_tty
);
9738 do_cleanups (back_to
);
9742 remote_command (char *args
, int from_tty
)
9744 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9748 remote_can_execute_reverse (void)
9750 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9751 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9758 remote_supports_non_stop (void)
9764 remote_supports_disable_randomization (void)
9766 /* Only supported in extended mode. */
9771 remote_supports_multi_process (void)
9773 struct remote_state
*rs
= get_remote_state ();
9775 /* Only extended-remote handles being attached to multiple
9776 processes, even though plain remote can use the multi-process
9777 thread id extensions, so that GDB knows the target process's
9779 return rs
->extended
&& remote_multi_process_p (rs
);
9783 remote_supports_cond_tracepoints (void)
9785 struct remote_state
*rs
= get_remote_state ();
9787 return rs
->cond_tracepoints
;
9791 remote_supports_fast_tracepoints (void)
9793 struct remote_state
*rs
= get_remote_state ();
9795 return rs
->fast_tracepoints
;
9799 remote_supports_static_tracepoints (void)
9801 struct remote_state
*rs
= get_remote_state ();
9803 return rs
->static_tracepoints
;
9807 remote_supports_install_in_trace (void)
9809 struct remote_state
*rs
= get_remote_state ();
9811 return rs
->install_in_trace
;
9815 remote_supports_enable_disable_tracepoint (void)
9817 struct remote_state
*rs
= get_remote_state ();
9819 return rs
->enable_disable_tracepoints
;
9823 remote_supports_string_tracing (void)
9825 struct remote_state
*rs
= get_remote_state ();
9827 return rs
->string_tracing
;
9831 remote_trace_init (void)
9834 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9835 if (strcmp (target_buf
, "OK") != 0)
9836 error (_("Target does not support this command."));
9839 static void free_actions_list (char **actions_list
);
9840 static void free_actions_list_cleanup_wrapper (void *);
9842 free_actions_list_cleanup_wrapper (void *al
)
9844 free_actions_list (al
);
9848 free_actions_list (char **actions_list
)
9852 if (actions_list
== 0)
9855 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9856 xfree (actions_list
[ndx
]);
9858 xfree (actions_list
);
9861 /* Recursive routine to walk through command list including loops, and
9862 download packets for each command. */
9865 remote_download_command_source (int num
, ULONGEST addr
,
9866 struct command_line
*cmds
)
9868 struct remote_state
*rs
= get_remote_state ();
9869 struct command_line
*cmd
;
9871 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9873 QUIT
; /* Allow user to bail out with ^C. */
9874 strcpy (rs
->buf
, "QTDPsrc:");
9875 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9876 rs
->buf
+ strlen (rs
->buf
),
9877 rs
->buf_size
- strlen (rs
->buf
));
9879 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9880 if (strcmp (target_buf
, "OK"))
9881 warning (_("Target does not support source download."));
9883 if (cmd
->control_type
== while_control
9884 || cmd
->control_type
== while_stepping_control
)
9886 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9888 QUIT
; /* Allow user to bail out with ^C. */
9889 strcpy (rs
->buf
, "QTDPsrc:");
9890 encode_source_string (num
, addr
, "cmd", "end",
9891 rs
->buf
+ strlen (rs
->buf
),
9892 rs
->buf_size
- strlen (rs
->buf
));
9894 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9895 if (strcmp (target_buf
, "OK"))
9896 warning (_("Target does not support source download."));
9902 remote_download_tracepoint (struct bp_location
*loc
)
9909 char **stepping_actions
;
9911 struct cleanup
*old_chain
= NULL
;
9912 struct agent_expr
*aexpr
;
9913 struct cleanup
*aexpr_chain
= NULL
;
9915 struct breakpoint
*b
= loc
->owner
;
9916 struct tracepoint
*t
= (struct tracepoint
*) b
;
9918 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
9919 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9921 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9924 tpaddr
= loc
->address
;
9925 sprintf_vma (addrbuf
, tpaddr
);
9926 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
9927 addrbuf
, /* address */
9928 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
9929 t
->step_count
, t
->pass_count
);
9930 /* Fast tracepoints are mostly handled by the target, but we can
9931 tell the target how big of an instruction block should be moved
9933 if (b
->type
== bp_fast_tracepoint
)
9935 /* Only test for support at download time; we may not know
9936 target capabilities at definition time. */
9937 if (remote_supports_fast_tracepoints ())
9941 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9942 tpaddr
, &isize
, NULL
))
9943 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9945 /* If it passed validation at definition but fails now,
9946 something is very wrong. */
9947 internal_error (__FILE__
, __LINE__
,
9948 _("Fast tracepoint not "
9949 "valid during download"));
9952 /* Fast tracepoints are functionally identical to regular
9953 tracepoints, so don't take lack of support as a reason to
9954 give up on the trace run. */
9955 warning (_("Target does not support fast tracepoints, "
9956 "downloading %d as regular tracepoint"), b
->number
);
9958 else if (b
->type
== bp_static_tracepoint
)
9960 /* Only test for support at download time; we may not know
9961 target capabilities at definition time. */
9962 if (remote_supports_static_tracepoints ())
9964 struct static_tracepoint_marker marker
;
9966 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
9969 error (_("Static tracepoint not valid during download"));
9972 /* Fast tracepoints are functionally identical to regular
9973 tracepoints, so don't take lack of support as a reason
9974 to give up on the trace run. */
9975 error (_("Target does not support static tracepoints"));
9977 /* If the tracepoint has a conditional, make it into an agent
9978 expression and append to the definition. */
9981 /* Only test support at download time, we may not know target
9982 capabilities at definition time. */
9983 if (remote_supports_cond_tracepoints ())
9985 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9986 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9987 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9988 pkt
= buf
+ strlen (buf
);
9989 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9990 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9992 do_cleanups (aexpr_chain
);
9995 warning (_("Target does not support conditional tracepoints, "
9996 "ignoring tp %d cond"), b
->number
);
9999 if (b
->commands
|| *default_collect
)
10002 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10003 if (strcmp (target_buf
, "OK"))
10004 error (_("Target does not support tracepoints."));
10006 /* do_single_steps (t); */
10009 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10011 QUIT
; /* Allow user to bail out with ^C. */
10012 sprintf (buf
, "QTDP:-%x:%s:%s%c",
10013 b
->number
, addrbuf
, /* address */
10015 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10018 remote_get_noisy_reply (&target_buf
,
10020 if (strcmp (target_buf
, "OK"))
10021 error (_("Error on target while setting tracepoints."));
10024 if (stepping_actions
)
10026 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10028 QUIT
; /* Allow user to bail out with ^C. */
10029 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
10030 b
->number
, addrbuf
, /* address */
10031 ((ndx
== 0) ? "S" : ""),
10032 stepping_actions
[ndx
],
10033 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10035 remote_get_noisy_reply (&target_buf
,
10037 if (strcmp (target_buf
, "OK"))
10038 error (_("Error on target while setting tracepoints."));
10042 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10045 if (b
->addr_string
)
10047 strcpy (buf
, "QTDPsrc:");
10048 encode_source_string (b
->number
, loc
->address
,
10049 "at", b
->addr_string
, buf
+ strlen (buf
),
10050 2048 - strlen (buf
));
10053 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10054 if (strcmp (target_buf
, "OK"))
10055 warning (_("Target does not support source download."));
10057 if (b
->cond_string
)
10059 strcpy (buf
, "QTDPsrc:");
10060 encode_source_string (b
->number
, loc
->address
,
10061 "cond", b
->cond_string
, buf
+ strlen (buf
),
10062 2048 - strlen (buf
));
10064 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10065 if (strcmp (target_buf
, "OK"))
10066 warning (_("Target does not support source download."));
10068 remote_download_command_source (b
->number
, loc
->address
,
10069 breakpoint_commands (b
));
10072 do_cleanups (old_chain
);
10076 remote_can_download_tracepoint (void)
10078 struct trace_status
*ts
= current_trace_status ();
10079 int status
= remote_get_trace_status (ts
);
10081 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10084 /* If we are in a tracing experiment, but remote stub doesn't support
10085 installing tracepoint in trace, we have to return. */
10086 if (!remote_supports_install_in_trace ())
10094 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10096 struct remote_state
*rs
= get_remote_state ();
10099 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
10100 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
10101 p
= rs
->buf
+ strlen (rs
->buf
);
10102 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10103 error (_("Trace state variable name too long for tsv definition packet"));
10104 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10107 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10108 if (*target_buf
== '\0')
10109 error (_("Target does not support this command."));
10110 if (strcmp (target_buf
, "OK") != 0)
10111 error (_("Error on target while downloading trace state variable."));
10115 remote_enable_tracepoint (struct bp_location
*location
)
10117 struct remote_state
*rs
= get_remote_state ();
10120 sprintf_vma (addr_buf
, location
->address
);
10121 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
10123 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10124 if (*rs
->buf
== '\0')
10125 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10126 if (strcmp (rs
->buf
, "OK") != 0)
10127 error (_("Error on target while enabling tracepoint."));
10131 remote_disable_tracepoint (struct bp_location
*location
)
10133 struct remote_state
*rs
= get_remote_state ();
10136 sprintf_vma (addr_buf
, location
->address
);
10137 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
10139 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10140 if (*rs
->buf
== '\0')
10141 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10142 if (strcmp (rs
->buf
, "OK") != 0)
10143 error (_("Error on target while disabling tracepoint."));
10147 remote_trace_set_readonly_regions (void)
10150 bfd_size_type size
;
10156 return; /* No information to give. */
10158 strcpy (target_buf
, "QTro");
10159 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10161 char tmp1
[40], tmp2
[40];
10164 if ((s
->flags
& SEC_LOAD
) == 0 ||
10165 /* (s->flags & SEC_CODE) == 0 || */
10166 (s
->flags
& SEC_READONLY
) == 0)
10170 vma
= bfd_get_section_vma (,s
);
10171 size
= bfd_get_section_size (s
);
10172 sprintf_vma (tmp1
, vma
);
10173 sprintf_vma (tmp2
, vma
+ size
);
10174 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10175 if (offset
+ sec_length
+ 1 > target_buf_size
)
10177 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10180 Too many sections for read-only sections definition packet."));
10183 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10184 offset
+= sec_length
;
10188 putpkt (target_buf
);
10189 getpkt (&target_buf
, &target_buf_size
, 0);
10194 remote_trace_start (void)
10196 putpkt ("QTStart");
10197 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10198 if (*target_buf
== '\0')
10199 error (_("Target does not support this command."));
10200 if (strcmp (target_buf
, "OK") != 0)
10201 error (_("Bogus reply from target: %s"), target_buf
);
10205 remote_get_trace_status (struct trace_status
*ts
)
10207 /* Initialize it just to avoid a GCC false warning. */
10209 /* FIXME we need to get register block size some other way. */
10210 extern int trace_regblock_size
;
10211 volatile struct gdb_exception ex
;
10213 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10215 putpkt ("qTStatus");
10217 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10219 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10223 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10227 /* If the remote target doesn't do tracing, flag it. */
10231 /* We're working with a live target. */
10234 /* Set some defaults. */
10235 ts
->running_known
= 0;
10236 ts
->stop_reason
= trace_stop_reason_unknown
;
10237 ts
->traceframe_count
= -1;
10238 ts
->buffer_free
= 0;
10241 error (_("Bogus trace status reply from target: %s"), target_buf
);
10243 parse_trace_status (p
, ts
);
10245 return ts
->running
;
10249 remote_get_tracepoint_status (struct breakpoint
*bp
,
10250 struct uploaded_tp
*utp
)
10252 struct remote_state
*rs
= get_remote_state ();
10254 struct bp_location
*loc
;
10255 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10259 tp
->base
.hit_count
= 0;
10260 tp
->traceframe_usage
= 0;
10261 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10263 /* If the tracepoint was never downloaded, don't go asking for
10265 if (tp
->number_on_target
== 0)
10267 sprintf (rs
->buf
, "qTP:%x:%s", tp
->number_on_target
,
10268 phex_nz (loc
->address
, 0));
10270 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10271 if (reply
&& *reply
)
10274 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10280 utp
->hit_count
= 0;
10281 utp
->traceframe_usage
= 0;
10282 sprintf (rs
->buf
, "qTP:%x:%s", utp
->number
, phex_nz (utp
->addr
, 0));
10284 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10285 if (reply
&& *reply
)
10288 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10294 remote_trace_stop (void)
10297 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10298 if (*target_buf
== '\0')
10299 error (_("Target does not support this command."));
10300 if (strcmp (target_buf
, "OK") != 0)
10301 error (_("Bogus reply from target: %s"), target_buf
);
10305 remote_trace_find (enum trace_find_type type
, int num
,
10306 ULONGEST addr1
, ULONGEST addr2
,
10309 struct remote_state
*rs
= get_remote_state ();
10311 int target_frameno
= -1, target_tracept
= -1;
10313 /* Lookups other than by absolute frame number depend on the current
10314 trace selected, so make sure it is correct on the remote end
10316 if (type
!= tfind_number
)
10317 set_remote_traceframe ();
10320 strcpy (p
, "QTFrame:");
10321 p
= strchr (p
, '\0');
10325 sprintf (p
, "%x", num
);
10328 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10331 sprintf (p
, "tdp:%x", num
);
10334 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10336 case tfind_outside
:
10337 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10340 error (_("Unknown trace find type %d"), type
);
10344 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10345 if (*reply
== '\0')
10346 error (_("Target does not support this command."));
10348 while (reply
&& *reply
)
10353 target_frameno
= (int) strtol (p
, &reply
, 16);
10355 error (_("Unable to parse trace frame number"));
10356 /* Don't update our remote traceframe number cache on failure
10357 to select a remote traceframe. */
10358 if (target_frameno
== -1)
10363 target_tracept
= (int) strtol (p
, &reply
, 16);
10365 error (_("Unable to parse tracepoint number"));
10367 case 'O': /* "OK"? */
10368 if (reply
[1] == 'K' && reply
[2] == '\0')
10371 error (_("Bogus reply from target: %s"), reply
);
10374 error (_("Bogus reply from target: %s"), reply
);
10377 *tpp
= target_tracept
;
10379 remote_traceframe_number
= target_frameno
;
10380 return target_frameno
;
10384 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10386 struct remote_state
*rs
= get_remote_state ();
10390 set_remote_traceframe ();
10392 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10394 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10395 if (reply
&& *reply
)
10399 unpack_varlen_hex (reply
+ 1, &uval
);
10400 *val
= (LONGEST
) uval
;
10408 remote_save_trace_data (const char *filename
)
10410 struct remote_state
*rs
= get_remote_state ();
10414 strcpy (p
, "QTSave:");
10416 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10417 error (_("Remote file name too long for trace save packet"));
10418 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10421 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10422 if (*reply
== '\0')
10423 error (_("Target does not support this command."));
10424 if (strcmp (reply
, "OK") != 0)
10425 error (_("Bogus reply from target: %s"), reply
);
10429 /* This is basically a memory transfer, but needs to be its own packet
10430 because we don't know how the target actually organizes its trace
10431 memory, plus we want to be able to ask for as much as possible, but
10432 not be unhappy if we don't get as much as we ask for. */
10435 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10437 struct remote_state
*rs
= get_remote_state ();
10443 strcpy (p
, "qTBuffer:");
10445 p
+= hexnumstr (p
, offset
);
10447 p
+= hexnumstr (p
, len
);
10451 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10452 if (reply
&& *reply
)
10454 /* 'l' by itself means we're at the end of the buffer and
10455 there is nothing more to get. */
10459 /* Convert the reply into binary. Limit the number of bytes to
10460 convert according to our passed-in buffer size, rather than
10461 what was returned in the packet; if the target is
10462 unexpectedly generous and gives us a bigger reply than we
10463 asked for, we don't want to crash. */
10464 rslt
= hex2bin (target_buf
, buf
, len
);
10468 /* Something went wrong, flag as an error. */
10473 remote_set_disconnected_tracing (int val
)
10475 struct remote_state
*rs
= get_remote_state ();
10477 if (rs
->disconnected_tracing
)
10481 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10483 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10484 if (*reply
== '\0')
10485 error (_("Target does not support this command."));
10486 if (strcmp (reply
, "OK") != 0)
10487 error (_("Bogus reply from target: %s"), reply
);
10490 warning (_("Target does not support disconnected tracing."));
10494 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10496 struct thread_info
*info
= find_thread_ptid (ptid
);
10498 if (info
&& info
->private)
10499 return info
->private->core
;
10504 remote_set_circular_trace_buffer (int val
)
10506 struct remote_state
*rs
= get_remote_state ();
10509 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10511 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10512 if (*reply
== '\0')
10513 error (_("Target does not support this command."));
10514 if (strcmp (reply
, "OK") != 0)
10515 error (_("Bogus reply from target: %s"), reply
);
10518 static struct traceframe_info
*
10519 remote_traceframe_info (void)
10523 text
= target_read_stralloc (¤t_target
,
10524 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10527 struct traceframe_info
*info
;
10528 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10530 info
= parse_traceframe_info (text
);
10531 do_cleanups (back_to
);
10538 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10539 instruction on which a fast tracepoint may be placed. Returns -1
10540 if the packet is not supported, and 0 if the minimum instruction
10541 length is unknown. */
10544 remote_get_min_fast_tracepoint_insn_len (void)
10546 struct remote_state
*rs
= get_remote_state ();
10549 sprintf (rs
->buf
, "qTMinFTPILen");
10551 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10552 if (*reply
== '\0')
10556 ULONGEST min_insn_len
;
10558 unpack_varlen_hex (reply
, &min_insn_len
);
10560 return (int) min_insn_len
;
10565 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10567 struct remote_state
*rs
= get_remote_state ();
10569 char *buf
= rs
->buf
;
10570 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10573 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10576 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10577 nbytes
= bin2hex (user
, buf
, 0);
10583 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10584 nbytes
= bin2hex (notes
, buf
, 0);
10590 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10591 nbytes
= bin2hex (stop_notes
, buf
, 0);
10595 /* Ensure the buffer is terminated. */
10599 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10600 if (*reply
== '\0')
10603 if (strcmp (reply
, "OK") != 0)
10604 error (_("Bogus reply from target: %s"), reply
);
10610 init_remote_ops (void)
10612 remote_ops
.to_shortname
= "remote";
10613 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10614 remote_ops
.to_doc
=
10615 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10616 Specify the serial device it is connected to\n\
10617 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10618 remote_ops
.to_open
= remote_open
;
10619 remote_ops
.to_close
= remote_close
;
10620 remote_ops
.to_detach
= remote_detach
;
10621 remote_ops
.to_disconnect
= remote_disconnect
;
10622 remote_ops
.to_resume
= remote_resume
;
10623 remote_ops
.to_wait
= remote_wait
;
10624 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10625 remote_ops
.to_store_registers
= remote_store_registers
;
10626 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10627 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10628 remote_ops
.to_files_info
= remote_files_info
;
10629 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10630 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10631 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10632 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10633 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10634 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10635 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10636 remote_ops
.to_region_ok_for_hw_watchpoint
10637 = remote_region_ok_for_hw_watchpoint
;
10638 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10639 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10640 remote_ops
.to_kill
= remote_kill
;
10641 remote_ops
.to_load
= generic_load
;
10642 remote_ops
.to_mourn_inferior
= remote_mourn
;
10643 remote_ops
.to_pass_signals
= remote_pass_signals
;
10644 remote_ops
.to_thread_alive
= remote_thread_alive
;
10645 remote_ops
.to_find_new_threads
= remote_threads_info
;
10646 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10647 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10648 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10649 remote_ops
.to_stop
= remote_stop
;
10650 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10651 remote_ops
.to_rcmd
= remote_rcmd
;
10652 remote_ops
.to_log_command
= serial_log_command
;
10653 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10654 remote_ops
.to_stratum
= process_stratum
;
10655 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10656 remote_ops
.to_has_memory
= default_child_has_memory
;
10657 remote_ops
.to_has_stack
= default_child_has_stack
;
10658 remote_ops
.to_has_registers
= default_child_has_registers
;
10659 remote_ops
.to_has_execution
= default_child_has_execution
;
10660 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10661 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10662 remote_ops
.to_magic
= OPS_MAGIC
;
10663 remote_ops
.to_memory_map
= remote_memory_map
;
10664 remote_ops
.to_flash_erase
= remote_flash_erase
;
10665 remote_ops
.to_flash_done
= remote_flash_done
;
10666 remote_ops
.to_read_description
= remote_read_description
;
10667 remote_ops
.to_search_memory
= remote_search_memory
;
10668 remote_ops
.to_can_async_p
= remote_can_async_p
;
10669 remote_ops
.to_is_async_p
= remote_is_async_p
;
10670 remote_ops
.to_async
= remote_async
;
10671 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10672 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10673 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10674 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10675 remote_ops
.to_supports_disable_randomization
10676 = remote_supports_disable_randomization
;
10677 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10678 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
10679 remote_ops
.to_trace_init
= remote_trace_init
;
10680 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10681 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
10682 remote_ops
.to_download_trace_state_variable
10683 = remote_download_trace_state_variable
;
10684 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10685 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10686 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10687 remote_ops
.to_trace_start
= remote_trace_start
;
10688 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10689 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
10690 remote_ops
.to_trace_stop
= remote_trace_stop
;
10691 remote_ops
.to_trace_find
= remote_trace_find
;
10692 remote_ops
.to_get_trace_state_variable_value
10693 = remote_get_trace_state_variable_value
;
10694 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10695 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10696 remote_ops
.to_upload_trace_state_variables
10697 = remote_upload_trace_state_variables
;
10698 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10699 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
10700 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10701 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10702 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
10703 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10704 remote_ops
.to_verify_memory
= remote_verify_memory
;
10705 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10706 remote_ops
.to_set_permissions
= remote_set_permissions
;
10707 remote_ops
.to_static_tracepoint_marker_at
10708 = remote_static_tracepoint_marker_at
;
10709 remote_ops
.to_static_tracepoint_markers_by_strid
10710 = remote_static_tracepoint_markers_by_strid
;
10711 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10714 /* Set up the extended remote vector by making a copy of the standard
10715 remote vector and adding to it. */
10718 init_extended_remote_ops (void)
10720 extended_remote_ops
= remote_ops
;
10722 extended_remote_ops
.to_shortname
= "extended-remote";
10723 extended_remote_ops
.to_longname
=
10724 "Extended remote serial target in gdb-specific protocol";
10725 extended_remote_ops
.to_doc
=
10726 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10727 Specify the serial device it is connected to (e.g. /dev/ttya).";
10728 extended_remote_ops
.to_open
= extended_remote_open
;
10729 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10730 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10731 extended_remote_ops
.to_detach
= extended_remote_detach
;
10732 extended_remote_ops
.to_attach
= extended_remote_attach
;
10733 extended_remote_ops
.to_kill
= extended_remote_kill
;
10734 extended_remote_ops
.to_supports_disable_randomization
10735 = extended_remote_supports_disable_randomization
;
10739 remote_can_async_p (void)
10741 if (!target_async_permitted
)
10742 /* We only enable async when the user specifically asks for it. */
10745 /* We're async whenever the serial device is. */
10746 return serial_can_async_p (remote_desc
);
10750 remote_is_async_p (void)
10752 if (!target_async_permitted
)
10753 /* We only enable async when the user specifically asks for it. */
10756 /* We're async whenever the serial device is. */
10757 return serial_is_async_p (remote_desc
);
10760 /* Pass the SERIAL event on and up to the client. One day this code
10761 will be able to delay notifying the client of an event until the
10762 point where an entire packet has been received. */
10764 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10766 static void *async_client_context
;
10767 static serial_event_ftype remote_async_serial_handler
;
10770 remote_async_serial_handler (struct serial
*scb
, void *context
)
10772 /* Don't propogate error information up to the client. Instead let
10773 the client find out about the error by querying the target. */
10774 async_client_callback (INF_REG_EVENT
, async_client_context
);
10778 remote_async_inferior_event_handler (gdb_client_data data
)
10780 inferior_event_handler (INF_REG_EVENT
, NULL
);
10784 remote_async_get_pending_events_handler (gdb_client_data data
)
10786 remote_get_pending_stop_replies ();
10790 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10791 void *context
), void *context
)
10793 if (callback
!= NULL
)
10795 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10796 async_client_callback
= callback
;
10797 async_client_context
= context
;
10800 serial_async (remote_desc
, NULL
, NULL
);
10804 set_remote_cmd (char *args
, int from_tty
)
10806 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10810 show_remote_cmd (char *args
, int from_tty
)
10812 /* We can't just use cmd_show_list here, because we want to skip
10813 the redundant "show remote Z-packet" and the legacy aliases. */
10814 struct cleanup
*showlist_chain
;
10815 struct cmd_list_element
*list
= remote_show_cmdlist
;
10816 struct ui_out
*uiout
= current_uiout
;
10818 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10819 for (; list
!= NULL
; list
= list
->next
)
10820 if (strcmp (list
->name
, "Z-packet") == 0)
10822 else if (list
->type
== not_set_cmd
)
10823 /* Alias commands are exactly like the original, except they
10824 don't have the normal type. */
10828 struct cleanup
*option_chain
10829 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10831 ui_out_field_string (uiout
, "name", list
->name
);
10832 ui_out_text (uiout
, ": ");
10833 if (list
->type
== show_cmd
)
10834 do_setshow_command ((char *) NULL
, from_tty
, list
);
10836 cmd_func (list
, NULL
, from_tty
);
10837 /* Close the tuple. */
10838 do_cleanups (option_chain
);
10841 /* Close the tuple. */
10842 do_cleanups (showlist_chain
);
10846 /* Function to be called whenever a new objfile (shlib) is detected. */
10848 remote_new_objfile (struct objfile
*objfile
)
10850 if (remote_desc
!= 0) /* Have a remote connection. */
10851 remote_check_symbols (objfile
);
10854 /* Pull all the tracepoints defined on the target and create local
10855 data structures representing them. We don't want to create real
10856 tracepoints yet, we don't want to mess up the user's existing
10860 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10862 struct remote_state
*rs
= get_remote_state ();
10865 /* Ask for a first packet of tracepoint definition. */
10867 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10869 while (*p
&& *p
!= 'l')
10871 parse_tracepoint_definition (p
, utpp
);
10872 /* Ask for another packet of tracepoint definition. */
10874 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10881 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10883 struct remote_state
*rs
= get_remote_state ();
10886 /* Ask for a first packet of variable definition. */
10888 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10890 while (*p
&& *p
!= 'l')
10892 parse_tsv_definition (p
, utsvp
);
10893 /* Ask for another packet of variable definition. */
10895 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10902 _initialize_remote (void)
10904 struct remote_state
*rs
;
10905 struct cmd_list_element
*cmd
;
10908 /* architecture specific data */
10909 remote_gdbarch_data_handle
=
10910 gdbarch_data_register_post_init (init_remote_state
);
10911 remote_g_packet_data_handle
=
10912 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10914 /* Initialize the per-target state. At the moment there is only one
10915 of these, not one per target. Only one target is active at a
10916 time. The default buffer size is unimportant; it will be expanded
10917 whenever a larger buffer is needed. */
10918 rs
= get_remote_state_raw ();
10919 rs
->buf_size
= 400;
10920 rs
->buf
= xmalloc (rs
->buf_size
);
10922 init_remote_ops ();
10923 add_target (&remote_ops
);
10925 init_extended_remote_ops ();
10926 add_target (&extended_remote_ops
);
10928 /* Hook into new objfile notification. */
10929 observer_attach_new_objfile (remote_new_objfile
);
10931 /* Set up signal handlers. */
10932 sigint_remote_token
=
10933 create_async_signal_handler (async_remote_interrupt
, NULL
);
10934 sigint_remote_twice_token
=
10935 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10938 init_remote_threadtests ();
10941 /* set/show remote ... */
10943 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10944 Remote protocol specific variables\n\
10945 Configure various remote-protocol specific variables such as\n\
10946 the packets being used"),
10947 &remote_set_cmdlist
, "set remote ",
10948 0 /* allow-unknown */, &setlist
);
10949 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10950 Remote protocol specific variables\n\
10951 Configure various remote-protocol specific variables such as\n\
10952 the packets being used"),
10953 &remote_show_cmdlist
, "show remote ",
10954 0 /* allow-unknown */, &showlist
);
10956 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10957 Compare section data on target to the exec file.\n\
10958 Argument is a single section name (default: all loaded sections)."),
10961 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10962 Send an arbitrary packet to a remote target.\n\
10963 maintenance packet TEXT\n\
10964 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10965 this command sends the string TEXT to the inferior, and displays the\n\
10966 response packet. GDB supplies the initial `$' character, and the\n\
10967 terminating `#' character and checksum."),
10970 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10971 Set whether to send break if interrupted."), _("\
10972 Show whether to send break if interrupted."), _("\
10973 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10974 set_remotebreak
, show_remotebreak
,
10975 &setlist
, &showlist
);
10976 cmd_name
= "remotebreak";
10977 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10978 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10979 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10980 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10981 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10983 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10984 interrupt_sequence_modes
, &interrupt_sequence_mode
,
10986 Set interrupt sequence to remote target."), _("\
10987 Show interrupt sequence to remote target."), _("\
10988 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10989 NULL
, show_interrupt_sequence
,
10990 &remote_set_cmdlist
,
10991 &remote_show_cmdlist
);
10993 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10994 &interrupt_on_connect
, _("\
10995 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10996 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10997 If set, interrupt sequence is sent to remote target."),
10999 &remote_set_cmdlist
, &remote_show_cmdlist
);
11001 /* Install commands for configuring memory read/write packets. */
11003 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11004 Set the maximum number of bytes per memory write packet (deprecated)."),
11006 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11007 Show the maximum number of bytes per memory write packet (deprecated)."),
11009 add_cmd ("memory-write-packet-size", no_class
,
11010 set_memory_write_packet_size
, _("\
11011 Set the maximum number of bytes per memory-write packet.\n\
11012 Specify the number of bytes in a packet or 0 (zero) for the\n\
11013 default packet size. The actual limit is further reduced\n\
11014 dependent on the target. Specify ``fixed'' to disable the\n\
11015 further restriction and ``limit'' to enable that restriction."),
11016 &remote_set_cmdlist
);
11017 add_cmd ("memory-read-packet-size", no_class
,
11018 set_memory_read_packet_size
, _("\
11019 Set the maximum number of bytes per memory-read packet.\n\
11020 Specify the number of bytes in a packet or 0 (zero) for the\n\
11021 default packet size. The actual limit is further reduced\n\
11022 dependent on the target. Specify ``fixed'' to disable the\n\
11023 further restriction and ``limit'' to enable that restriction."),
11024 &remote_set_cmdlist
);
11025 add_cmd ("memory-write-packet-size", no_class
,
11026 show_memory_write_packet_size
,
11027 _("Show the maximum number of bytes per memory-write packet."),
11028 &remote_show_cmdlist
);
11029 add_cmd ("memory-read-packet-size", no_class
,
11030 show_memory_read_packet_size
,
11031 _("Show the maximum number of bytes per memory-read packet."),
11032 &remote_show_cmdlist
);
11034 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11035 &remote_hw_watchpoint_limit
, _("\
11036 Set the maximum number of target hardware watchpoints."), _("\
11037 Show the maximum number of target hardware watchpoints."), _("\
11038 Specify a negative limit for unlimited."),
11039 NULL
, NULL
, /* FIXME: i18n: The maximum
11040 number of target hardware
11041 watchpoints is %s. */
11042 &remote_set_cmdlist
, &remote_show_cmdlist
);
11043 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11044 &remote_hw_watchpoint_length_limit
, _("\
11045 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11046 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11047 Specify a negative limit for unlimited."),
11048 NULL
, NULL
, /* FIXME: i18n: The maximum
11049 length (in bytes) of a target
11050 hardware watchpoint is %s. */
11051 &remote_set_cmdlist
, &remote_show_cmdlist
);
11052 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11053 &remote_hw_breakpoint_limit
, _("\
11054 Set the maximum number of target hardware breakpoints."), _("\
11055 Show the maximum number of target hardware breakpoints."), _("\
11056 Specify a negative limit for unlimited."),
11057 NULL
, NULL
, /* FIXME: i18n: The maximum
11058 number of target hardware
11059 breakpoints is %s. */
11060 &remote_set_cmdlist
, &remote_show_cmdlist
);
11062 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
11063 &remote_address_size
, _("\
11064 Set the maximum size of the address (in bits) in a memory packet."), _("\
11065 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11067 NULL
, /* FIXME: i18n: */
11068 &setlist
, &showlist
);
11070 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11071 "X", "binary-download", 1);
11073 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11074 "vCont", "verbose-resume", 0);
11076 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11077 "QPassSignals", "pass-signals", 0);
11079 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11080 "qSymbol", "symbol-lookup", 0);
11082 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11083 "P", "set-register", 1);
11085 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11086 "p", "fetch-register", 1);
11088 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11089 "Z0", "software-breakpoint", 0);
11091 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11092 "Z1", "hardware-breakpoint", 0);
11094 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11095 "Z2", "write-watchpoint", 0);
11097 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11098 "Z3", "read-watchpoint", 0);
11100 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11101 "Z4", "access-watchpoint", 0);
11103 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11104 "qXfer:auxv:read", "read-aux-vector", 0);
11106 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11107 "qXfer:features:read", "target-features", 0);
11109 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11110 "qXfer:libraries:read", "library-info", 0);
11112 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11113 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11115 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11116 "qXfer:memory-map:read", "memory-map", 0);
11118 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11119 "qXfer:spu:read", "read-spu-object", 0);
11121 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11122 "qXfer:spu:write", "write-spu-object", 0);
11124 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11125 "qXfer:osdata:read", "osdata", 0);
11127 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11128 "qXfer:threads:read", "threads", 0);
11130 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11131 "qXfer:siginfo:read", "read-siginfo-object", 0);
11133 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11134 "qXfer:siginfo:write", "write-siginfo-object", 0);
11136 add_packet_config_cmd
11137 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11138 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11140 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11141 "qGetTLSAddr", "get-thread-local-storage-address",
11144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11145 "qGetTIBAddr", "get-thread-information-block-address",
11148 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11149 "bc", "reverse-continue", 0);
11151 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11152 "bs", "reverse-step", 0);
11154 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11155 "qSupported", "supported-packets", 0);
11157 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11158 "qSearch:memory", "search-memory", 0);
11160 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11161 "vFile:open", "hostio-open", 0);
11163 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11164 "vFile:pread", "hostio-pread", 0);
11166 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11167 "vFile:pwrite", "hostio-pwrite", 0);
11169 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11170 "vFile:close", "hostio-close", 0);
11172 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11173 "vFile:unlink", "hostio-unlink", 0);
11175 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11176 "vAttach", "attach", 0);
11178 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11181 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11182 "QStartNoAckMode", "noack", 0);
11184 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11185 "vKill", "kill", 0);
11187 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11188 "qAttached", "query-attached", 0);
11190 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11191 "ConditionalTracepoints",
11192 "conditional-tracepoints", 0);
11193 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11194 "FastTracepoints", "fast-tracepoints", 0);
11196 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11197 "TracepointSource", "TracepointSource", 0);
11199 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11200 "QAllow", "allow", 0);
11202 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11203 "StaticTracepoints", "static-tracepoints", 0);
11205 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11206 "InstallInTrace", "install-in-trace", 0);
11208 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11209 "qXfer:statictrace:read", "read-sdata-object", 0);
11211 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11212 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11214 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11215 "QDisableRandomization", "disable-randomization", 0);
11217 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11218 Z sub-packet has its own set and show commands, but users may
11219 have sets to this variable in their .gdbinit files (or in their
11221 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11222 &remote_Z_packet_detect
, _("\
11223 Set use of remote protocol `Z' packets"), _("\
11224 Show use of remote protocol `Z' packets "), _("\
11225 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11227 set_remote_protocol_Z_packet_cmd
,
11228 show_remote_protocol_Z_packet_cmd
,
11229 /* FIXME: i18n: Use of remote protocol
11230 `Z' packets is %s. */
11231 &remote_set_cmdlist
, &remote_show_cmdlist
);
11233 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11234 Manipulate files on the remote system\n\
11235 Transfer files to and from the remote target system."),
11236 &remote_cmdlist
, "remote ",
11237 0 /* allow-unknown */, &cmdlist
);
11239 add_cmd ("put", class_files
, remote_put_command
,
11240 _("Copy a local file to the remote system."),
11243 add_cmd ("get", class_files
, remote_get_command
,
11244 _("Copy a remote file to the local system."),
11247 add_cmd ("delete", class_files
, remote_delete_command
,
11248 _("Delete a remote file."),
11251 remote_exec_file
= xstrdup ("");
11252 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11253 &remote_exec_file
, _("\
11254 Set the remote pathname for \"run\""), _("\
11255 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11256 &remote_set_cmdlist
, &remote_show_cmdlist
);
11258 /* Eventually initialize fileio. See fileio.c */
11259 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11261 /* Take advantage of the fact that the LWP field is not used, to tag
11262 special ptids with it set to != 0. */
11263 magic_null_ptid
= ptid_build (42000, 1, -1);
11264 not_sent_ptid
= ptid_build (42000, 1, -2);
11265 any_thread_ptid
= ptid_build (42000, 1, 0);
11267 target_buf_size
= 2048;
11268 target_buf
= xmalloc (target_buf_size
);