1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
31 #include "exceptions.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-setshow.h"
46 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
71 /* Temp hacks for tracepoint encoding migration. */
72 static char *target_buf
;
73 static long target_buf_size
;
75 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
76 char ***tdp_actions
, char ***stepping_actions
);
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void cleanup_sigint_signal_handler (void *dummy
);
92 static void initialize_sigint_signal_handler (void);
93 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
94 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
97 static void handle_remote_sigint (int);
98 static void handle_remote_sigint_twice (int);
99 static void async_remote_interrupt (gdb_client_data
);
100 void async_remote_interrupt_twice (gdb_client_data
);
102 static void remote_files_info (struct target_ops
*ignore
);
104 static void remote_prepare_to_store (struct regcache
*regcache
);
106 static void remote_open (char *name
, int from_tty
);
108 static void extended_remote_open (char *name
, int from_tty
);
110 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
112 static void remote_close (int quitting
);
114 static void remote_mourn (struct target_ops
*ops
);
116 static void extended_remote_restart (void);
118 static void extended_remote_mourn (struct target_ops
*);
120 static void remote_mourn_1 (struct target_ops
*);
122 static void remote_send (char **buf
, long *sizeof_buf_p
);
124 static int readchar (int timeout
);
126 static void remote_kill (struct target_ops
*ops
);
128 static int tohex (int nib
);
130 static int remote_can_async_p (void);
132 static int remote_is_async_p (void);
134 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
135 void *context
), void *context
);
137 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
139 static void remote_interrupt (int signo
);
141 static void remote_interrupt_twice (int signo
);
143 static void interrupt_query (void);
145 static void set_general_thread (struct ptid ptid
);
146 static void set_continue_thread (struct ptid ptid
);
148 static void get_offsets (void);
150 static void skip_frame (void);
152 static long read_frame (char **buf_p
, long *sizeof_buf
);
154 static int hexnumlen (ULONGEST num
);
156 static void init_remote_ops (void);
158 static void init_extended_remote_ops (void);
160 static void remote_stop (ptid_t
);
162 static int ishex (int ch
, int *val
);
164 static int stubhex (int ch
);
166 static int hexnumstr (char *, ULONGEST
);
168 static int hexnumnstr (char *, ULONGEST
, int);
170 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
172 static void print_packet (char *);
174 static void compare_sections_command (char *, int);
176 static void packet_command (char *, int);
178 static int stub_unpack_int (char *buff
, int fieldlength
);
180 static ptid_t
remote_current_thread (ptid_t oldptid
);
182 static void remote_find_new_threads (void);
184 static void record_currthread (ptid_t currthread
);
186 static int fromhex (int a
);
188 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
190 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
192 static int putpkt_binary (char *buf
, int cnt
);
194 static void check_binary_download (CORE_ADDR addr
);
196 struct packet_config
;
198 static void show_packet_config_cmd (struct packet_config
*config
);
200 static void update_packet_config (struct packet_config
*config
);
202 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
203 struct cmd_list_element
*c
);
205 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
207 struct cmd_list_element
*c
,
210 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
211 static ptid_t
read_ptid (char *buf
, char **obuf
);
213 static void remote_set_permissions (void);
216 static int remote_get_trace_status (struct trace_status
*ts
);
218 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
220 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
222 static void remote_query_supported (void);
224 static void remote_check_symbols (struct objfile
*objfile
);
226 void _initialize_remote (void);
229 static struct stop_reply
*stop_reply_xmalloc (void);
230 static void stop_reply_xfree (struct stop_reply
*);
231 static void do_stop_reply_xfree (void *arg
);
232 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
233 static void push_stop_reply (struct stop_reply
*);
234 static void remote_get_pending_stop_replies (void);
235 static void discard_pending_stop_replies (int pid
);
236 static int peek_stop_reply (ptid_t ptid
);
238 static void remote_async_inferior_event_handler (gdb_client_data
);
239 static void remote_async_get_pending_events_handler (gdb_client_data
);
241 static void remote_terminal_ours (void);
243 static int remote_read_description_p (struct target_ops
*target
);
245 static void remote_console_output (char *msg
);
247 /* The non-stop remote protocol provisions for one pending stop reply.
248 This is where we keep it until it is acknowledged. */
250 static struct stop_reply
*pending_stop_reply
= NULL
;
254 static struct cmd_list_element
*remote_cmdlist
;
256 /* For "set remote" and "show remote". */
258 static struct cmd_list_element
*remote_set_cmdlist
;
259 static struct cmd_list_element
*remote_show_cmdlist
;
261 /* Description of the remote protocol state for the currently
262 connected target. This is per-target state, and independent of the
263 selected architecture. */
267 /* A buffer to use for incoming packets, and its current size. The
268 buffer is grown dynamically for larger incoming packets.
269 Outgoing packets may also be constructed in this buffer.
270 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
271 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
276 /* If we negotiated packet size explicitly (and thus can bypass
277 heuristics for the largest packet size that will not overflow
278 a buffer in the stub), this will be set to that packet size.
279 Otherwise zero, meaning to use the guessed size. */
280 long explicit_packet_size
;
282 /* remote_wait is normally called when the target is running and
283 waits for a stop reply packet. But sometimes we need to call it
284 when the target is already stopped. We can send a "?" packet
285 and have remote_wait read the response. Or, if we already have
286 the response, we can stash it in BUF and tell remote_wait to
287 skip calling getpkt. This flag is set when BUF contains a
288 stop reply packet and the target is not waiting. */
289 int cached_wait_status
;
291 /* True, if in no ack mode. That is, neither GDB nor the stub will
292 expect acks from each other. The connection is assumed to be
296 /* True if we're connected in extended remote mode. */
299 /* True if the stub reported support for multi-process
301 int multi_process_aware
;
303 /* True if we resumed the target and we're waiting for the target to
304 stop. In the mean time, we can't start another command/query.
305 The remote server wouldn't be ready to process it, so we'd
306 timeout waiting for a reply that would never come and eventually
307 we'd close the connection. This can happen in asynchronous mode
308 because we allow GDB commands while the target is running. */
309 int waiting_for_stop_reply
;
311 /* True if the stub reports support for non-stop mode. */
314 /* True if the stub reports support for vCont;t. */
317 /* True if the stub reports support for conditional tracepoints. */
318 int cond_tracepoints
;
320 /* True if the stub reports support for fast tracepoints. */
321 int fast_tracepoints
;
323 /* True if the stub reports support for static tracepoints. */
324 int static_tracepoints
;
326 /* True if the stub can continue running a trace while GDB is
328 int disconnected_tracing
;
330 /* True if the stub reports support for enabling and disabling
331 tracepoints while a trace experiment is running. */
332 int enable_disable_tracepoints
;
334 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
335 responded to that. */
339 /* Private data that we'll store in (struct thread_info)->private. */
340 struct private_thread_info
347 free_private_thread_info (struct private_thread_info
*info
)
353 /* Returns true if the multi-process extensions are in effect. */
355 remote_multi_process_p (struct remote_state
*rs
)
357 return rs
->extended
&& rs
->multi_process_aware
;
360 /* This data could be associated with a target, but we do not always
361 have access to the current target when we need it, so for now it is
362 static. This will be fine for as long as only one target is in use
364 static struct remote_state remote_state
;
366 static struct remote_state
*
367 get_remote_state_raw (void)
369 return &remote_state
;
372 /* Description of the remote protocol for a given architecture. */
376 long offset
; /* Offset into G packet. */
377 long regnum
; /* GDB's internal register number. */
378 LONGEST pnum
; /* Remote protocol register number. */
379 int in_g_packet
; /* Always part of G packet. */
380 /* long size in bytes; == register_size (target_gdbarch, regnum);
382 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
386 struct remote_arch_state
388 /* Description of the remote protocol registers. */
389 long sizeof_g_packet
;
391 /* Description of the remote protocol registers indexed by REGNUM
392 (making an array gdbarch_num_regs in size). */
393 struct packet_reg
*regs
;
395 /* This is the size (in chars) of the first response to the ``g''
396 packet. It is used as a heuristic when determining the maximum
397 size of memory-read and memory-write packets. A target will
398 typically only reserve a buffer large enough to hold the ``g''
399 packet. The size does not include packet overhead (headers and
401 long actual_register_packet_size
;
403 /* This is the maximum size (in chars) of a non read/write packet.
404 It is also used as a cap on the size of read/write packets. */
405 long remote_packet_size
;
408 long sizeof_pkt
= 2000;
410 /* Utility: generate error from an incoming stub packet. */
412 trace_error (char *buf
)
415 return; /* not an error msg */
418 case '1': /* malformed packet error */
419 if (*++buf
== '0') /* general case: */
420 error (_("remote.c: error in outgoing packet."));
422 error (_("remote.c: error in outgoing packet at field #%ld."),
423 strtol (buf
, NULL
, 16));
425 error (_("trace API error 0x%s."), ++buf
);
427 error (_("Target returns error code '%s'."), buf
);
431 /* Utility: wait for reply from stub, while accepting "O" packets. */
433 remote_get_noisy_reply (char **buf_p
,
436 do /* Loop on reply from remote stub. */
440 QUIT
; /* Allow user to bail out with ^C. */
441 getpkt (buf_p
, sizeof_buf
, 0);
445 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
448 CORE_ADDR from
, to
, org_to
;
450 int adjusted_size
= 0;
451 volatile struct gdb_exception ex
;
453 p
= buf
+ strlen ("qRelocInsn:");
454 pp
= unpack_varlen_hex (p
, &ul
);
456 error (_("invalid qRelocInsn packet: %s"), buf
);
460 unpack_varlen_hex (p
, &ul
);
465 TRY_CATCH (ex
, RETURN_MASK_ALL
)
467 gdbarch_relocate_instruction (target_gdbarch
, &to
, from
);
471 adjusted_size
= to
- org_to
;
473 sprintf (buf
, "qRelocInsn:%x", adjusted_size
);
476 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
478 /* Propagate memory errors silently back to the target.
479 The stub may have limited the range of addresses we
480 can write to, for example. */
485 /* Something unexpectedly bad happened. Be verbose so
486 we can tell what, and propagate the error back to the
487 stub, so it doesn't get stuck waiting for a
489 exception_fprintf (gdb_stderr
, ex
,
490 _("warning: relocating instruction: "));
494 else if (buf
[0] == 'O' && buf
[1] != 'K')
495 remote_console_output (buf
+ 1); /* 'O' message from stub */
497 return buf
; /* Here's the actual reply. */
502 /* Handle for retreving the remote protocol data from gdbarch. */
503 static struct gdbarch_data
*remote_gdbarch_data_handle
;
505 static struct remote_arch_state
*
506 get_remote_arch_state (void)
508 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
511 /* Fetch the global remote target state. */
513 static struct remote_state
*
514 get_remote_state (void)
516 /* Make sure that the remote architecture state has been
517 initialized, because doing so might reallocate rs->buf. Any
518 function which calls getpkt also needs to be mindful of changes
519 to rs->buf, but this call limits the number of places which run
521 get_remote_arch_state ();
523 return get_remote_state_raw ();
527 compare_pnums (const void *lhs_
, const void *rhs_
)
529 const struct packet_reg
* const *lhs
= lhs_
;
530 const struct packet_reg
* const *rhs
= rhs_
;
532 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
534 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
541 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
543 int regnum
, num_remote_regs
, offset
;
544 struct packet_reg
**remote_regs
;
546 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
548 struct packet_reg
*r
= ®s
[regnum
];
550 if (register_size (gdbarch
, regnum
) == 0)
551 /* Do not try to fetch zero-sized (placeholder) registers. */
554 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
559 /* Define the g/G packet format as the contents of each register
560 with a remote protocol number, in order of ascending protocol
563 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
564 * sizeof (struct packet_reg
*));
565 for (num_remote_regs
= 0, regnum
= 0;
566 regnum
< gdbarch_num_regs (gdbarch
);
568 if (regs
[regnum
].pnum
!= -1)
569 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
571 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
574 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
576 remote_regs
[regnum
]->in_g_packet
= 1;
577 remote_regs
[regnum
]->offset
= offset
;
578 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
584 /* Given the architecture described by GDBARCH, return the remote
585 protocol register's number and the register's offset in the g/G
586 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
587 If the target does not have a mapping for REGNUM, return false,
588 otherwise, return true. */
591 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
592 int *pnum
, int *poffset
)
595 struct packet_reg
*regs
;
596 struct cleanup
*old_chain
;
598 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
600 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
601 old_chain
= make_cleanup (xfree
, regs
);
603 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
605 *pnum
= regs
[regnum
].pnum
;
606 *poffset
= regs
[regnum
].offset
;
608 do_cleanups (old_chain
);
614 init_remote_state (struct gdbarch
*gdbarch
)
616 struct remote_state
*rs
= get_remote_state_raw ();
617 struct remote_arch_state
*rsa
;
619 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
621 /* Use the architecture to build a regnum<->pnum table, which will be
622 1:1 unless a feature set specifies otherwise. */
623 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
624 gdbarch_num_regs (gdbarch
),
627 /* Record the maximum possible size of the g packet - it may turn out
629 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
631 /* Default maximum number of characters in a packet body. Many
632 remote stubs have a hardwired buffer size of 400 bytes
633 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
634 as the maximum packet-size to ensure that the packet and an extra
635 NUL character can always fit in the buffer. This stops GDB
636 trashing stubs that try to squeeze an extra NUL into what is
637 already a full buffer (As of 1999-12-04 that was most stubs). */
638 rsa
->remote_packet_size
= 400 - 1;
640 /* This one is filled in when a ``g'' packet is received. */
641 rsa
->actual_register_packet_size
= 0;
643 /* Should rsa->sizeof_g_packet needs more space than the
644 default, adjust the size accordingly. Remember that each byte is
645 encoded as two characters. 32 is the overhead for the packet
646 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
647 (``$NN:G...#NN'') is a better guess, the below has been padded a
649 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
650 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
652 /* Make sure that the packet buffer is plenty big enough for
653 this architecture. */
654 if (rs
->buf_size
< rsa
->remote_packet_size
)
656 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
657 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
663 /* Return the current allowed size of a remote packet. This is
664 inferred from the current architecture, and should be used to
665 limit the length of outgoing packets. */
667 get_remote_packet_size (void)
669 struct remote_state
*rs
= get_remote_state ();
670 struct remote_arch_state
*rsa
= get_remote_arch_state ();
672 if (rs
->explicit_packet_size
)
673 return rs
->explicit_packet_size
;
675 return rsa
->remote_packet_size
;
678 static struct packet_reg
*
679 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
681 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
685 struct packet_reg
*r
= &rsa
->regs
[regnum
];
687 gdb_assert (r
->regnum
== regnum
);
692 static struct packet_reg
*
693 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
697 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
699 struct packet_reg
*r
= &rsa
->regs
[i
];
707 /* FIXME: graces/2002-08-08: These variables should eventually be
708 bound to an instance of the target object (as in gdbarch-tdep()),
709 when such a thing exists. */
711 /* This is set to the data address of the access causing the target
712 to stop for a watchpoint. */
713 static CORE_ADDR remote_watch_data_address
;
715 /* This is non-zero if target stopped for a watchpoint. */
716 static int remote_stopped_by_watchpoint_p
;
718 static struct target_ops remote_ops
;
720 static struct target_ops extended_remote_ops
;
722 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
723 ``forever'' still use the normal timeout mechanism. This is
724 currently used by the ASYNC code to guarentee that target reads
725 during the initial connect always time-out. Once getpkt has been
726 modified to return a timeout indication and, in turn
727 remote_wait()/wait_for_inferior() have gained a timeout parameter
729 static int wait_forever_enabled_p
= 1;
731 /* Allow the user to specify what sequence to send to the remote
732 when he requests a program interruption: Although ^C is usually
733 what remote systems expect (this is the default, here), it is
734 sometimes preferable to send a break. On other systems such
735 as the Linux kernel, a break followed by g, which is Magic SysRq g
736 is required in order to interrupt the execution. */
737 const char interrupt_sequence_control_c
[] = "Ctrl-C";
738 const char interrupt_sequence_break
[] = "BREAK";
739 const char interrupt_sequence_break_g
[] = "BREAK-g";
740 static const char *interrupt_sequence_modes
[] =
742 interrupt_sequence_control_c
,
743 interrupt_sequence_break
,
744 interrupt_sequence_break_g
,
747 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
750 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
751 struct cmd_list_element
*c
,
754 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
755 fprintf_filtered (file
,
756 _("Send the ASCII ETX character (Ctrl-c) "
757 "to the remote target to interrupt the "
758 "execution of the program.\n"));
759 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
760 fprintf_filtered (file
,
761 _("send a break signal to the remote target "
762 "to interrupt the execution of the program.\n"));
763 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
764 fprintf_filtered (file
,
765 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
766 "the remote target to interrupt the execution "
767 "of Linux kernel.\n"));
769 internal_error (__FILE__
, __LINE__
,
770 _("Invalid value for interrupt_sequence_mode: %s."),
771 interrupt_sequence_mode
);
774 /* This boolean variable specifies whether interrupt_sequence is sent
775 to the remote target when gdb connects to it.
776 This is mostly needed when you debug the Linux kernel: The Linux kernel
777 expects BREAK g which is Magic SysRq g for connecting gdb. */
778 static int interrupt_on_connect
= 0;
780 /* This variable is used to implement the "set/show remotebreak" commands.
781 Since these commands are now deprecated in favor of "set/show remote
782 interrupt-sequence", it no longer has any effect on the code. */
783 static int remote_break
;
786 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
789 interrupt_sequence_mode
= interrupt_sequence_break
;
791 interrupt_sequence_mode
= interrupt_sequence_control_c
;
795 show_remotebreak (struct ui_file
*file
, int from_tty
,
796 struct cmd_list_element
*c
,
801 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
802 remote_open knows that we don't have a file open when the program
804 static struct serial
*remote_desc
= NULL
;
806 /* This variable sets the number of bits in an address that are to be
807 sent in a memory ("M" or "m") packet. Normally, after stripping
808 leading zeros, the entire address would be sent. This variable
809 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
810 initial implementation of remote.c restricted the address sent in
811 memory packets to ``host::sizeof long'' bytes - (typically 32
812 bits). Consequently, for 64 bit targets, the upper 32 bits of an
813 address was never sent. Since fixing this bug may cause a break in
814 some remote targets this variable is principly provided to
815 facilitate backward compatibility. */
817 static int remote_address_size
;
819 /* Temporary to track who currently owns the terminal. See
820 remote_terminal_* for more details. */
822 static int remote_async_terminal_ours_p
;
824 /* The executable file to use for "run" on the remote side. */
826 static char *remote_exec_file
= "";
829 /* User configurable variables for the number of characters in a
830 memory read/write packet. MIN (rsa->remote_packet_size,
831 rsa->sizeof_g_packet) is the default. Some targets need smaller
832 values (fifo overruns, et.al.) and some users need larger values
833 (speed up transfers). The variables ``preferred_*'' (the user
834 request), ``current_*'' (what was actually set) and ``forced_*''
835 (Positive - a soft limit, negative - a hard limit). */
837 struct memory_packet_config
844 /* Compute the current size of a read/write packet. Since this makes
845 use of ``actual_register_packet_size'' the computation is dynamic. */
848 get_memory_packet_size (struct memory_packet_config
*config
)
850 struct remote_state
*rs
= get_remote_state ();
851 struct remote_arch_state
*rsa
= get_remote_arch_state ();
853 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
854 law?) that some hosts don't cope very well with large alloca()
855 calls. Eventually the alloca() code will be replaced by calls to
856 xmalloc() and make_cleanups() allowing this restriction to either
857 be lifted or removed. */
858 #ifndef MAX_REMOTE_PACKET_SIZE
859 #define MAX_REMOTE_PACKET_SIZE 16384
861 /* NOTE: 20 ensures we can write at least one byte. */
862 #ifndef MIN_REMOTE_PACKET_SIZE
863 #define MIN_REMOTE_PACKET_SIZE 20
868 if (config
->size
<= 0)
869 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
871 what_they_get
= config
->size
;
875 what_they_get
= get_remote_packet_size ();
876 /* Limit the packet to the size specified by the user. */
878 && what_they_get
> config
->size
)
879 what_they_get
= config
->size
;
881 /* Limit it to the size of the targets ``g'' response unless we have
882 permission from the stub to use a larger packet size. */
883 if (rs
->explicit_packet_size
== 0
884 && rsa
->actual_register_packet_size
> 0
885 && what_they_get
> rsa
->actual_register_packet_size
)
886 what_they_get
= rsa
->actual_register_packet_size
;
888 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
889 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
890 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
891 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
893 /* Make sure there is room in the global buffer for this packet
894 (including its trailing NUL byte). */
895 if (rs
->buf_size
< what_they_get
+ 1)
897 rs
->buf_size
= 2 * what_they_get
;
898 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
901 return what_they_get
;
904 /* Update the size of a read/write packet. If they user wants
905 something really big then do a sanity check. */
908 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
910 int fixed_p
= config
->fixed_p
;
911 long size
= config
->size
;
914 error (_("Argument required (integer, `fixed' or `limited')."));
915 else if (strcmp (args
, "hard") == 0
916 || strcmp (args
, "fixed") == 0)
918 else if (strcmp (args
, "soft") == 0
919 || strcmp (args
, "limit") == 0)
925 size
= strtoul (args
, &end
, 0);
927 error (_("Invalid %s (bad syntax)."), config
->name
);
929 /* Instead of explicitly capping the size of a packet to
930 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
931 instead allowed to set the size to something arbitrarily
933 if (size
> MAX_REMOTE_PACKET_SIZE
)
934 error (_("Invalid %s (too large)."), config
->name
);
938 if (fixed_p
&& !config
->fixed_p
)
940 if (! query (_("The target may not be able to correctly handle a %s\n"
941 "of %ld bytes. Change the packet size? "),
943 error (_("Packet size not changed."));
945 /* Update the config. */
946 config
->fixed_p
= fixed_p
;
951 show_memory_packet_size (struct memory_packet_config
*config
)
953 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
955 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
956 get_memory_packet_size (config
));
958 printf_filtered (_("Packets are limited to %ld bytes.\n"),
959 get_memory_packet_size (config
));
962 static struct memory_packet_config memory_write_packet_config
=
964 "memory-write-packet-size",
968 set_memory_write_packet_size (char *args
, int from_tty
)
970 set_memory_packet_size (args
, &memory_write_packet_config
);
974 show_memory_write_packet_size (char *args
, int from_tty
)
976 show_memory_packet_size (&memory_write_packet_config
);
980 get_memory_write_packet_size (void)
982 return get_memory_packet_size (&memory_write_packet_config
);
985 static struct memory_packet_config memory_read_packet_config
=
987 "memory-read-packet-size",
991 set_memory_read_packet_size (char *args
, int from_tty
)
993 set_memory_packet_size (args
, &memory_read_packet_config
);
997 show_memory_read_packet_size (char *args
, int from_tty
)
999 show_memory_packet_size (&memory_read_packet_config
);
1003 get_memory_read_packet_size (void)
1005 long size
= get_memory_packet_size (&memory_read_packet_config
);
1007 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1008 extra buffer size argument before the memory read size can be
1009 increased beyond this. */
1010 if (size
> get_remote_packet_size ())
1011 size
= get_remote_packet_size ();
1016 /* Generic configuration support for packets the stub optionally
1017 supports. Allows the user to specify the use of the packet as well
1018 as allowing GDB to auto-detect support in the remote stub. */
1022 PACKET_SUPPORT_UNKNOWN
= 0,
1027 struct packet_config
1031 enum auto_boolean detect
;
1032 enum packet_support support
;
1035 /* Analyze a packet's return value and update the packet config
1046 update_packet_config (struct packet_config
*config
)
1048 switch (config
->detect
)
1050 case AUTO_BOOLEAN_TRUE
:
1051 config
->support
= PACKET_ENABLE
;
1053 case AUTO_BOOLEAN_FALSE
:
1054 config
->support
= PACKET_DISABLE
;
1056 case AUTO_BOOLEAN_AUTO
:
1057 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1063 show_packet_config_cmd (struct packet_config
*config
)
1065 char *support
= "internal-error";
1067 switch (config
->support
)
1070 support
= "enabled";
1072 case PACKET_DISABLE
:
1073 support
= "disabled";
1075 case PACKET_SUPPORT_UNKNOWN
:
1076 support
= "unknown";
1079 switch (config
->detect
)
1081 case AUTO_BOOLEAN_AUTO
:
1082 printf_filtered (_("Support for the `%s' packet "
1083 "is auto-detected, currently %s.\n"),
1084 config
->name
, support
);
1086 case AUTO_BOOLEAN_TRUE
:
1087 case AUTO_BOOLEAN_FALSE
:
1088 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1089 config
->name
, support
);
1095 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1096 const char *title
, int legacy
)
1102 config
->name
= name
;
1103 config
->title
= title
;
1104 config
->detect
= AUTO_BOOLEAN_AUTO
;
1105 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1106 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1108 show_doc
= xstrprintf ("Show current use of remote "
1109 "protocol `%s' (%s) packet",
1111 /* set/show TITLE-packet {auto,on,off} */
1112 cmd_name
= xstrprintf ("%s-packet", title
);
1113 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1114 &config
->detect
, set_doc
,
1115 show_doc
, NULL
, /* help_doc */
1116 set_remote_protocol_packet_cmd
,
1117 show_remote_protocol_packet_cmd
,
1118 &remote_set_cmdlist
, &remote_show_cmdlist
);
1119 /* The command code copies the documentation strings. */
1122 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1127 legacy_name
= xstrprintf ("%s-packet", name
);
1128 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1129 &remote_set_cmdlist
);
1130 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1131 &remote_show_cmdlist
);
1135 static enum packet_result
1136 packet_check_result (const char *buf
)
1140 /* The stub recognized the packet request. Check that the
1141 operation succeeded. */
1143 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1145 /* "Enn" - definitly an error. */
1146 return PACKET_ERROR
;
1148 /* Always treat "E." as an error. This will be used for
1149 more verbose error messages, such as E.memtypes. */
1150 if (buf
[0] == 'E' && buf
[1] == '.')
1151 return PACKET_ERROR
;
1153 /* The packet may or may not be OK. Just assume it is. */
1157 /* The stub does not support the packet. */
1158 return PACKET_UNKNOWN
;
1161 static enum packet_result
1162 packet_ok (const char *buf
, struct packet_config
*config
)
1164 enum packet_result result
;
1166 result
= packet_check_result (buf
);
1171 /* The stub recognized the packet request. */
1172 switch (config
->support
)
1174 case PACKET_SUPPORT_UNKNOWN
:
1176 fprintf_unfiltered (gdb_stdlog
,
1177 "Packet %s (%s) is supported\n",
1178 config
->name
, config
->title
);
1179 config
->support
= PACKET_ENABLE
;
1181 case PACKET_DISABLE
:
1182 internal_error (__FILE__
, __LINE__
,
1183 _("packet_ok: attempt to use a disabled packet"));
1189 case PACKET_UNKNOWN
:
1190 /* The stub does not support the packet. */
1191 switch (config
->support
)
1194 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1195 /* If the stub previously indicated that the packet was
1196 supported then there is a protocol error.. */
1197 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1198 config
->name
, config
->title
);
1200 /* The user set it wrong. */
1201 error (_("Enabled packet %s (%s) not recognized by stub"),
1202 config
->name
, config
->title
);
1204 case PACKET_SUPPORT_UNKNOWN
:
1206 fprintf_unfiltered (gdb_stdlog
,
1207 "Packet %s (%s) is NOT supported\n",
1208 config
->name
, config
->title
);
1209 config
->support
= PACKET_DISABLE
;
1211 case PACKET_DISABLE
:
1233 PACKET_vFile_pwrite
,
1235 PACKET_vFile_unlink
,
1237 PACKET_qXfer_features
,
1238 PACKET_qXfer_libraries
,
1239 PACKET_qXfer_memory_map
,
1240 PACKET_qXfer_spu_read
,
1241 PACKET_qXfer_spu_write
,
1242 PACKET_qXfer_osdata
,
1243 PACKET_qXfer_threads
,
1244 PACKET_qXfer_statictrace_read
,
1245 PACKET_qXfer_traceframe_info
,
1249 PACKET_QPassSignals
,
1250 PACKET_qSearch_memory
,
1253 PACKET_QStartNoAckMode
,
1255 PACKET_qXfer_siginfo_read
,
1256 PACKET_qXfer_siginfo_write
,
1258 PACKET_ConditionalTracepoints
,
1259 PACKET_FastTracepoints
,
1260 PACKET_StaticTracepoints
,
1263 PACKET_TracepointSource
,
1268 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1271 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1272 struct cmd_list_element
*c
)
1274 struct packet_config
*packet
;
1276 for (packet
= remote_protocol_packets
;
1277 packet
< &remote_protocol_packets
[PACKET_MAX
];
1280 if (&packet
->detect
== c
->var
)
1282 update_packet_config (packet
);
1286 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1291 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1292 struct cmd_list_element
*c
,
1295 struct packet_config
*packet
;
1297 for (packet
= remote_protocol_packets
;
1298 packet
< &remote_protocol_packets
[PACKET_MAX
];
1301 if (&packet
->detect
== c
->var
)
1303 show_packet_config_cmd (packet
);
1307 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1311 /* Should we try one of the 'Z' requests? */
1315 Z_PACKET_SOFTWARE_BP
,
1316 Z_PACKET_HARDWARE_BP
,
1323 /* For compatibility with older distributions. Provide a ``set remote
1324 Z-packet ...'' command that updates all the Z packet types. */
1326 static enum auto_boolean remote_Z_packet_detect
;
1329 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1330 struct cmd_list_element
*c
)
1334 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1336 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1337 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1342 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1343 struct cmd_list_element
*c
,
1348 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1350 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1354 /* Should we try the 'ThreadInfo' query packet?
1356 This variable (NOT available to the user: auto-detect only!)
1357 determines whether GDB will use the new, simpler "ThreadInfo"
1358 query or the older, more complex syntax for thread queries.
1359 This is an auto-detect variable (set to true at each connect,
1360 and set to false when the target fails to recognize it). */
1362 static int use_threadinfo_query
;
1363 static int use_threadextra_query
;
1365 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1366 static struct async_signal_handler
*sigint_remote_twice_token
;
1367 static struct async_signal_handler
*sigint_remote_token
;
1370 /* Asynchronous signal handle registered as event loop source for
1371 when we have pending events ready to be passed to the core. */
1373 static struct async_event_handler
*remote_async_inferior_event_token
;
1375 /* Asynchronous signal handle registered as event loop source for when
1376 the remote sent us a %Stop notification. The registered callback
1377 will do a vStopped sequence to pull the rest of the events out of
1378 the remote side into our event queue. */
1380 static struct async_event_handler
*remote_async_get_pending_events_token
;
1383 static ptid_t magic_null_ptid
;
1384 static ptid_t not_sent_ptid
;
1385 static ptid_t any_thread_ptid
;
1387 /* These are the threads which we last sent to the remote system. The
1388 TID member will be -1 for all or -2 for not sent yet. */
1390 static ptid_t general_thread
;
1391 static ptid_t continue_thread
;
1393 /* This the traceframe which we last selected on the remote system.
1394 It will be -1 if no traceframe is selected. */
1395 static int remote_traceframe_number
= -1;
1397 /* Find out if the stub attached to PID (and hence GDB should offer to
1398 detach instead of killing it when bailing out). */
1401 remote_query_attached (int pid
)
1403 struct remote_state
*rs
= get_remote_state ();
1405 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1408 if (remote_multi_process_p (rs
))
1409 sprintf (rs
->buf
, "qAttached:%x", pid
);
1411 sprintf (rs
->buf
, "qAttached");
1414 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1416 switch (packet_ok (rs
->buf
,
1417 &remote_protocol_packets
[PACKET_qAttached
]))
1420 if (strcmp (rs
->buf
, "1") == 0)
1424 warning (_("Remote failure reply: %s"), rs
->buf
);
1426 case PACKET_UNKNOWN
:
1433 /* Add PID to GDB's inferior table. Since we can be connected to a
1434 remote system before before knowing about any inferior, mark the
1435 target with execution when we find the first inferior. If ATTACHED
1436 is 1, then we had just attached to this inferior. If it is 0, then
1437 we just created this inferior. If it is -1, then try querying the
1438 remote stub to find out if it had attached to the inferior or
1441 static struct inferior
*
1442 remote_add_inferior (int pid
, int attached
)
1444 struct inferior
*inf
;
1446 /* Check whether this process we're learning about is to be
1447 considered attached, or if is to be considered to have been
1448 spawned by the stub. */
1450 attached
= remote_query_attached (pid
);
1452 if (gdbarch_has_global_solist (target_gdbarch
))
1454 /* If the target shares code across all inferiors, then every
1455 attach adds a new inferior. */
1456 inf
= add_inferior (pid
);
1458 /* ... and every inferior is bound to the same program space.
1459 However, each inferior may still have its own address
1461 inf
->aspace
= maybe_new_address_space ();
1462 inf
->pspace
= current_program_space
;
1466 /* In the traditional debugging scenario, there's a 1-1 match
1467 between program/address spaces. We simply bind the inferior
1468 to the program space's address space. */
1469 inf
= current_inferior ();
1470 inferior_appeared (inf
, pid
);
1473 inf
->attach_flag
= attached
;
1478 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1479 according to RUNNING. */
1482 remote_add_thread (ptid_t ptid
, int running
)
1486 set_executing (ptid
, running
);
1487 set_running (ptid
, running
);
1490 /* Come here when we learn about a thread id from the remote target.
1491 It may be the first time we hear about such thread, so take the
1492 opportunity to add it to GDB's thread list. In case this is the
1493 first time we're noticing its corresponding inferior, add it to
1494 GDB's inferior list as well. */
1497 remote_notice_new_inferior (ptid_t currthread
, int running
)
1499 /* If this is a new thread, add it to GDB's thread list.
1500 If we leave it up to WFI to do this, bad things will happen. */
1502 if (in_thread_list (currthread
) && is_exited (currthread
))
1504 /* We're seeing an event on a thread id we knew had exited.
1505 This has to be a new thread reusing the old id. Add it. */
1506 remote_add_thread (currthread
, running
);
1510 if (!in_thread_list (currthread
))
1512 struct inferior
*inf
= NULL
;
1513 int pid
= ptid_get_pid (currthread
);
1515 if (ptid_is_pid (inferior_ptid
)
1516 && pid
== ptid_get_pid (inferior_ptid
))
1518 /* inferior_ptid has no thread member yet. This can happen
1519 with the vAttach -> remote_wait,"TAAthread:" path if the
1520 stub doesn't support qC. This is the first stop reported
1521 after an attach, so this is the main thread. Update the
1522 ptid in the thread list. */
1523 if (in_thread_list (pid_to_ptid (pid
)))
1524 thread_change_ptid (inferior_ptid
, currthread
);
1527 remote_add_thread (currthread
, running
);
1528 inferior_ptid
= currthread
;
1533 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1535 /* inferior_ptid is not set yet. This can happen with the
1536 vRun -> remote_wait,"TAAthread:" path if the stub
1537 doesn't support qC. This is the first stop reported
1538 after an attach, so this is the main thread. Update the
1539 ptid in the thread list. */
1540 thread_change_ptid (inferior_ptid
, currthread
);
1544 /* When connecting to a target remote, or to a target
1545 extended-remote which already was debugging an inferior, we
1546 may not know about it yet. Add it before adding its child
1547 thread, so notifications are emitted in a sensible order. */
1548 if (!in_inferior_list (ptid_get_pid (currthread
)))
1549 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1551 /* This is really a new thread. Add it. */
1552 remote_add_thread (currthread
, running
);
1554 /* If we found a new inferior, let the common code do whatever
1555 it needs to with it (e.g., read shared libraries, insert
1558 notice_new_inferior (currthread
, running
, 0);
1562 /* Return the private thread data, creating it if necessary. */
1564 struct private_thread_info
*
1565 demand_private_info (ptid_t ptid
)
1567 struct thread_info
*info
= find_thread_ptid (ptid
);
1573 info
->private = xmalloc (sizeof (*(info
->private)));
1574 info
->private_dtor
= free_private_thread_info
;
1575 info
->private->core
= -1;
1576 info
->private->extra
= 0;
1579 return info
->private;
1582 /* Call this function as a result of
1583 1) A halt indication (T packet) containing a thread id
1584 2) A direct query of currthread
1585 3) Successful execution of set thread */
1588 record_currthread (ptid_t currthread
)
1590 general_thread
= currthread
;
1593 static char *last_pass_packet
;
1595 /* If 'QPassSignals' is supported, tell the remote stub what signals
1596 it can simply pass through to the inferior without reporting. */
1599 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1601 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1603 char *pass_packet
, *p
;
1606 gdb_assert (numsigs
< 256);
1607 for (i
= 0; i
< numsigs
; i
++)
1609 if (pass_signals
[i
])
1612 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1613 strcpy (pass_packet
, "QPassSignals:");
1614 p
= pass_packet
+ strlen (pass_packet
);
1615 for (i
= 0; i
< numsigs
; i
++)
1617 if (pass_signals
[i
])
1620 *p
++ = tohex (i
>> 4);
1621 *p
++ = tohex (i
& 15);
1630 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1632 struct remote_state
*rs
= get_remote_state ();
1633 char *buf
= rs
->buf
;
1635 putpkt (pass_packet
);
1636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1637 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1638 if (last_pass_packet
)
1639 xfree (last_pass_packet
);
1640 last_pass_packet
= pass_packet
;
1643 xfree (pass_packet
);
1647 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1648 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1649 thread. If GEN is set, set the general thread, if not, then set
1650 the step/continue thread. */
1652 set_thread (struct ptid ptid
, int gen
)
1654 struct remote_state
*rs
= get_remote_state ();
1655 ptid_t state
= gen
? general_thread
: continue_thread
;
1656 char *buf
= rs
->buf
;
1657 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1659 if (ptid_equal (state
, ptid
))
1663 *buf
++ = gen
? 'g' : 'c';
1664 if (ptid_equal (ptid
, magic_null_ptid
))
1665 xsnprintf (buf
, endbuf
- buf
, "0");
1666 else if (ptid_equal (ptid
, any_thread_ptid
))
1667 xsnprintf (buf
, endbuf
- buf
, "0");
1668 else if (ptid_equal (ptid
, minus_one_ptid
))
1669 xsnprintf (buf
, endbuf
- buf
, "-1");
1671 write_ptid (buf
, endbuf
, ptid
);
1673 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1675 general_thread
= ptid
;
1677 continue_thread
= ptid
;
1681 set_general_thread (struct ptid ptid
)
1683 set_thread (ptid
, 1);
1687 set_continue_thread (struct ptid ptid
)
1689 set_thread (ptid
, 0);
1692 /* Change the remote current process. Which thread within the process
1693 ends up selected isn't important, as long as it is the same process
1694 as what INFERIOR_PTID points to.
1696 This comes from that fact that there is no explicit notion of
1697 "selected process" in the protocol. The selected process for
1698 general operations is the process the selected general thread
1702 set_general_process (void)
1704 struct remote_state
*rs
= get_remote_state ();
1706 /* If the remote can't handle multiple processes, don't bother. */
1707 if (!remote_multi_process_p (rs
))
1710 /* We only need to change the remote current thread if it's pointing
1711 at some other process. */
1712 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1713 set_general_thread (inferior_ptid
);
1717 /* Return nonzero if the thread PTID is still alive on the remote
1721 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1723 struct remote_state
*rs
= get_remote_state ();
1726 if (ptid_equal (ptid
, magic_null_ptid
))
1727 /* The main thread is always alive. */
1730 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1731 /* The main thread is always alive. This can happen after a
1732 vAttach, if the remote side doesn't support
1737 endp
= rs
->buf
+ get_remote_packet_size ();
1740 write_ptid (p
, endp
, ptid
);
1743 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1744 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1747 /* About these extended threadlist and threadinfo packets. They are
1748 variable length packets but, the fields within them are often fixed
1749 length. They are redundent enough to send over UDP as is the
1750 remote protocol in general. There is a matching unit test module
1753 #define OPAQUETHREADBYTES 8
1755 /* a 64 bit opaque identifier */
1756 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1758 /* WARNING: This threadref data structure comes from the remote O.S.,
1759 libstub protocol encoding, and remote.c. It is not particularly
1762 /* Right now, the internal structure is int. We want it to be bigger.
1763 Plan to fix this. */
1765 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1767 /* gdb_ext_thread_info is an internal GDB data structure which is
1768 equivalent to the reply of the remote threadinfo packet. */
1770 struct gdb_ext_thread_info
1772 threadref threadid
; /* External form of thread reference. */
1773 int active
; /* Has state interesting to GDB?
1775 char display
[256]; /* Brief state display, name,
1776 blocked/suspended. */
1777 char shortname
[32]; /* To be used to name threads. */
1778 char more_display
[256]; /* Long info, statistics, queue depth,
1782 /* The volume of remote transfers can be limited by submitting
1783 a mask containing bits specifying the desired information.
1784 Use a union of these values as the 'selection' parameter to
1785 get_thread_info. FIXME: Make these TAG names more thread specific. */
1787 #define TAG_THREADID 1
1788 #define TAG_EXISTS 2
1789 #define TAG_DISPLAY 4
1790 #define TAG_THREADNAME 8
1791 #define TAG_MOREDISPLAY 16
1793 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1795 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1797 static char *unpack_nibble (char *buf
, int *val
);
1799 static char *pack_nibble (char *buf
, int nibble
);
1801 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1803 static char *unpack_byte (char *buf
, int *value
);
1805 static char *pack_int (char *buf
, int value
);
1807 static char *unpack_int (char *buf
, int *value
);
1809 static char *unpack_string (char *src
, char *dest
, int length
);
1811 static char *pack_threadid (char *pkt
, threadref
*id
);
1813 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1815 void int_to_threadref (threadref
*id
, int value
);
1817 static int threadref_to_int (threadref
*ref
);
1819 static void copy_threadref (threadref
*dest
, threadref
*src
);
1821 static int threadmatch (threadref
*dest
, threadref
*src
);
1823 static char *pack_threadinfo_request (char *pkt
, int mode
,
1826 static int remote_unpack_thread_info_response (char *pkt
,
1827 threadref
*expectedref
,
1828 struct gdb_ext_thread_info
1832 static int remote_get_threadinfo (threadref
*threadid
,
1833 int fieldset
, /*TAG mask */
1834 struct gdb_ext_thread_info
*info
);
1836 static char *pack_threadlist_request (char *pkt
, int startflag
,
1838 threadref
*nextthread
);
1840 static int parse_threadlist_response (char *pkt
,
1842 threadref
*original_echo
,
1843 threadref
*resultlist
,
1846 static int remote_get_threadlist (int startflag
,
1847 threadref
*nextthread
,
1851 threadref
*threadlist
);
1853 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1855 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1856 void *context
, int looplimit
);
1858 static int remote_newthread_step (threadref
*ref
, void *context
);
1861 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1862 buffer we're allowed to write to. Returns
1863 BUF+CHARACTERS_WRITTEN. */
1866 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1869 struct remote_state
*rs
= get_remote_state ();
1871 if (remote_multi_process_p (rs
))
1873 pid
= ptid_get_pid (ptid
);
1875 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1877 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1879 tid
= ptid_get_tid (ptid
);
1881 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1883 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1888 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1889 passed the last parsed char. Returns null_ptid on error. */
1892 read_ptid (char *buf
, char **obuf
)
1896 ULONGEST pid
= 0, tid
= 0;
1900 /* Multi-process ptid. */
1901 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1903 error (_("invalid remote ptid: %s"), p
);
1906 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1909 return ptid_build (pid
, 0, tid
);
1912 /* No multi-process. Just a tid. */
1913 pp
= unpack_varlen_hex (p
, &tid
);
1915 /* Since the stub is not sending a process id, then default to
1916 what's in inferior_ptid, unless it's null at this point. If so,
1917 then since there's no way to know the pid of the reported
1918 threads, use the magic number. */
1919 if (ptid_equal (inferior_ptid
, null_ptid
))
1920 pid
= ptid_get_pid (magic_null_ptid
);
1922 pid
= ptid_get_pid (inferior_ptid
);
1926 return ptid_build (pid
, 0, tid
);
1929 /* Encode 64 bits in 16 chars of hex. */
1931 static const char hexchars
[] = "0123456789abcdef";
1934 ishex (int ch
, int *val
)
1936 if ((ch
>= 'a') && (ch
<= 'f'))
1938 *val
= ch
- 'a' + 10;
1941 if ((ch
>= 'A') && (ch
<= 'F'))
1943 *val
= ch
- 'A' + 10;
1946 if ((ch
>= '0') && (ch
<= '9'))
1957 if (ch
>= 'a' && ch
<= 'f')
1958 return ch
- 'a' + 10;
1959 if (ch
>= '0' && ch
<= '9')
1961 if (ch
>= 'A' && ch
<= 'F')
1962 return ch
- 'A' + 10;
1967 stub_unpack_int (char *buff
, int fieldlength
)
1974 nibble
= stubhex (*buff
++);
1978 retval
= retval
<< 4;
1984 unpack_varlen_hex (char *buff
, /* packet to parse */
1988 ULONGEST retval
= 0;
1990 while (ishex (*buff
, &nibble
))
1993 retval
= retval
<< 4;
1994 retval
|= nibble
& 0x0f;
2001 unpack_nibble (char *buf
, int *val
)
2003 *val
= fromhex (*buf
++);
2008 pack_nibble (char *buf
, int nibble
)
2010 *buf
++ = hexchars
[(nibble
& 0x0f)];
2015 pack_hex_byte (char *pkt
, int byte
)
2017 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2018 *pkt
++ = hexchars
[(byte
& 0xf)];
2023 unpack_byte (char *buf
, int *value
)
2025 *value
= stub_unpack_int (buf
, 2);
2030 pack_int (char *buf
, int value
)
2032 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2033 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2034 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2035 buf
= pack_hex_byte (buf
, (value
& 0xff));
2040 unpack_int (char *buf
, int *value
)
2042 *value
= stub_unpack_int (buf
, 8);
2046 #if 0 /* Currently unused, uncomment when needed. */
2047 static char *pack_string (char *pkt
, char *string
);
2050 pack_string (char *pkt
, char *string
)
2055 len
= strlen (string
);
2057 len
= 200; /* Bigger than most GDB packets, junk??? */
2058 pkt
= pack_hex_byte (pkt
, len
);
2062 if ((ch
== '\0') || (ch
== '#'))
2063 ch
= '*'; /* Protect encapsulation. */
2068 #endif /* 0 (unused) */
2071 unpack_string (char *src
, char *dest
, int length
)
2080 pack_threadid (char *pkt
, threadref
*id
)
2083 unsigned char *altid
;
2085 altid
= (unsigned char *) id
;
2086 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2088 pkt
= pack_hex_byte (pkt
, *altid
++);
2094 unpack_threadid (char *inbuf
, threadref
*id
)
2097 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2100 altref
= (char *) id
;
2102 while (inbuf
< limit
)
2104 x
= stubhex (*inbuf
++);
2105 y
= stubhex (*inbuf
++);
2106 *altref
++ = (x
<< 4) | y
;
2111 /* Externally, threadrefs are 64 bits but internally, they are still
2112 ints. This is due to a mismatch of specifications. We would like
2113 to use 64bit thread references internally. This is an adapter
2117 int_to_threadref (threadref
*id
, int value
)
2119 unsigned char *scan
;
2121 scan
= (unsigned char *) id
;
2127 *scan
++ = (value
>> 24) & 0xff;
2128 *scan
++ = (value
>> 16) & 0xff;
2129 *scan
++ = (value
>> 8) & 0xff;
2130 *scan
++ = (value
& 0xff);
2134 threadref_to_int (threadref
*ref
)
2137 unsigned char *scan
;
2143 value
= (value
<< 8) | ((*scan
++) & 0xff);
2148 copy_threadref (threadref
*dest
, threadref
*src
)
2151 unsigned char *csrc
, *cdest
;
2153 csrc
= (unsigned char *) src
;
2154 cdest
= (unsigned char *) dest
;
2161 threadmatch (threadref
*dest
, threadref
*src
)
2163 /* Things are broken right now, so just assume we got a match. */
2165 unsigned char *srcp
, *destp
;
2167 srcp
= (char *) src
;
2168 destp
= (char *) dest
;
2172 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2179 threadid:1, # always request threadid
2186 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2189 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2191 *pkt
++ = 'q'; /* Info Query */
2192 *pkt
++ = 'P'; /* process or thread info */
2193 pkt
= pack_int (pkt
, mode
); /* mode */
2194 pkt
= pack_threadid (pkt
, id
); /* threadid */
2195 *pkt
= '\0'; /* terminate */
2199 /* These values tag the fields in a thread info response packet. */
2200 /* Tagging the fields allows us to request specific fields and to
2201 add more fields as time goes by. */
2203 #define TAG_THREADID 1 /* Echo the thread identifier. */
2204 #define TAG_EXISTS 2 /* Is this process defined enough to
2205 fetch registers and its stack? */
2206 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2207 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2208 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2212 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2213 struct gdb_ext_thread_info
*info
)
2215 struct remote_state
*rs
= get_remote_state ();
2219 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2222 /* info->threadid = 0; FIXME: implement zero_threadref. */
2224 info
->display
[0] = '\0';
2225 info
->shortname
[0] = '\0';
2226 info
->more_display
[0] = '\0';
2228 /* Assume the characters indicating the packet type have been
2230 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2231 pkt
= unpack_threadid (pkt
, &ref
);
2234 warning (_("Incomplete response to threadinfo request."));
2235 if (!threadmatch (&ref
, expectedref
))
2236 { /* This is an answer to a different request. */
2237 warning (_("ERROR RMT Thread info mismatch."));
2240 copy_threadref (&info
->threadid
, &ref
);
2242 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2244 /* Packets are terminated with nulls. */
2245 while ((pkt
< limit
) && mask
&& *pkt
)
2247 pkt
= unpack_int (pkt
, &tag
); /* tag */
2248 pkt
= unpack_byte (pkt
, &length
); /* length */
2249 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2251 warning (_("ERROR RMT: threadinfo tag mismatch."));
2255 if (tag
== TAG_THREADID
)
2259 warning (_("ERROR RMT: length of threadid is not 16."));
2263 pkt
= unpack_threadid (pkt
, &ref
);
2264 mask
= mask
& ~TAG_THREADID
;
2267 if (tag
== TAG_EXISTS
)
2269 info
->active
= stub_unpack_int (pkt
, length
);
2271 mask
= mask
& ~(TAG_EXISTS
);
2274 warning (_("ERROR RMT: 'exists' length too long."));
2280 if (tag
== TAG_THREADNAME
)
2282 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2283 mask
= mask
& ~TAG_THREADNAME
;
2286 if (tag
== TAG_DISPLAY
)
2288 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2289 mask
= mask
& ~TAG_DISPLAY
;
2292 if (tag
== TAG_MOREDISPLAY
)
2294 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2295 mask
= mask
& ~TAG_MOREDISPLAY
;
2298 warning (_("ERROR RMT: unknown thread info tag."));
2299 break; /* Not a tag we know about. */
2305 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2306 struct gdb_ext_thread_info
*info
)
2308 struct remote_state
*rs
= get_remote_state ();
2311 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2313 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2315 if (rs
->buf
[0] == '\0')
2318 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2323 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2326 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2327 threadref
*nextthread
)
2329 *pkt
++ = 'q'; /* info query packet */
2330 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2331 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2332 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2333 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2338 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2341 parse_threadlist_response (char *pkt
, int result_limit
,
2342 threadref
*original_echo
, threadref
*resultlist
,
2345 struct remote_state
*rs
= get_remote_state ();
2347 int count
, resultcount
, done
;
2350 /* Assume the 'q' and 'M chars have been stripped. */
2351 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2352 /* done parse past here */
2353 pkt
= unpack_byte (pkt
, &count
); /* count field */
2354 pkt
= unpack_nibble (pkt
, &done
);
2355 /* The first threadid is the argument threadid. */
2356 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2357 while ((count
-- > 0) && (pkt
< limit
))
2359 pkt
= unpack_threadid (pkt
, resultlist
++);
2360 if (resultcount
++ >= result_limit
)
2369 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2370 int *done
, int *result_count
, threadref
*threadlist
)
2372 struct remote_state
*rs
= get_remote_state ();
2373 static threadref echo_nextthread
;
2376 /* Trancate result limit to be smaller than the packet size. */
2377 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2378 >= get_remote_packet_size ())
2379 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2381 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2383 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2385 if (*rs
->buf
== '\0')
2389 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2392 if (!threadmatch (&echo_nextthread
, nextthread
))
2394 /* FIXME: This is a good reason to drop the packet. */
2395 /* Possably, there is a duplicate response. */
2397 retransmit immediatly - race conditions
2398 retransmit after timeout - yes
2400 wait for packet, then exit
2402 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2403 return 0; /* I choose simply exiting. */
2405 if (*result_count
<= 0)
2409 warning (_("RMT ERROR : failed to get remote thread list."));
2412 return result
; /* break; */
2414 if (*result_count
> result_limit
)
2417 warning (_("RMT ERROR: threadlist response longer than requested."));
2423 /* This is the interface between remote and threads, remotes upper
2426 /* remote_find_new_threads retrieves the thread list and for each
2427 thread in the list, looks up the thread in GDB's internal list,
2428 adding the thread if it does not already exist. This involves
2429 getting partial thread lists from the remote target so, polling the
2430 quit_flag is required. */
2433 /* About this many threadisds fit in a packet. */
2435 #define MAXTHREADLISTRESULTS 32
2438 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2441 int done
, i
, result_count
;
2445 static threadref nextthread
;
2446 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2451 if (loopcount
++ > looplimit
)
2454 warning (_("Remote fetch threadlist -infinite loop-."));
2457 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2458 &done
, &result_count
, resultthreadlist
))
2463 /* Clear for later iterations. */
2465 /* Setup to resume next batch of thread references, set nextthread. */
2466 if (result_count
>= 1)
2467 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2469 while (result_count
--)
2470 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2477 remote_newthread_step (threadref
*ref
, void *context
)
2479 int pid
= ptid_get_pid (inferior_ptid
);
2480 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2482 if (!in_thread_list (ptid
))
2484 return 1; /* continue iterator */
2487 #define CRAZY_MAX_THREADS 1000
2490 remote_current_thread (ptid_t oldpid
)
2492 struct remote_state
*rs
= get_remote_state ();
2495 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2496 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2497 return read_ptid (&rs
->buf
[2], NULL
);
2502 /* Find new threads for info threads command.
2503 * Original version, using John Metzler's thread protocol.
2507 remote_find_new_threads (void)
2509 remote_threadlist_iterator (remote_newthread_step
, 0,
2513 #if defined(HAVE_LIBEXPAT)
2515 typedef struct thread_item
2521 DEF_VEC_O(thread_item_t
);
2523 struct threads_parsing_context
2525 VEC (thread_item_t
) *items
;
2529 start_thread (struct gdb_xml_parser
*parser
,
2530 const struct gdb_xml_element
*element
,
2531 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2533 struct threads_parsing_context
*data
= user_data
;
2535 struct thread_item item
;
2537 struct gdb_xml_value
*attr
;
2539 id
= xml_find_attribute (attributes
, "id")->value
;
2540 item
.ptid
= read_ptid (id
, NULL
);
2542 attr
= xml_find_attribute (attributes
, "core");
2544 item
.core
= *(ULONGEST
*) attr
->value
;
2550 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2554 end_thread (struct gdb_xml_parser
*parser
,
2555 const struct gdb_xml_element
*element
,
2556 void *user_data
, const char *body_text
)
2558 struct threads_parsing_context
*data
= user_data
;
2560 if (body_text
&& *body_text
)
2561 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2564 const struct gdb_xml_attribute thread_attributes
[] = {
2565 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2566 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2567 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2570 const struct gdb_xml_element thread_children
[] = {
2571 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2574 const struct gdb_xml_element threads_children
[] = {
2575 { "thread", thread_attributes
, thread_children
,
2576 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2577 start_thread
, end_thread
},
2578 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2581 const struct gdb_xml_element threads_elements
[] = {
2582 { "threads", NULL
, threads_children
,
2583 GDB_XML_EF_NONE
, NULL
, NULL
},
2584 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2587 /* Discard the contents of the constructed thread info context. */
2590 clear_threads_parsing_context (void *p
)
2592 struct threads_parsing_context
*context
= p
;
2594 struct thread_item
*item
;
2596 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2597 xfree (item
->extra
);
2599 VEC_free (thread_item_t
, context
->items
);
2605 * Find all threads for info threads command.
2606 * Uses new thread protocol contributed by Cisco.
2607 * Falls back and attempts to use the older method (above)
2608 * if the target doesn't respond to the new method.
2612 remote_threads_info (struct target_ops
*ops
)
2614 struct remote_state
*rs
= get_remote_state ();
2618 if (remote_desc
== 0) /* paranoia */
2619 error (_("Command can only be used when connected to the remote target."));
2621 #if defined(HAVE_LIBEXPAT)
2622 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2624 char *xml
= target_read_stralloc (¤t_target
,
2625 TARGET_OBJECT_THREADS
, NULL
);
2627 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2631 struct threads_parsing_context context
;
2633 context
.items
= NULL
;
2634 make_cleanup (clear_threads_parsing_context
, &context
);
2636 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2637 threads_elements
, xml
, &context
) == 0)
2640 struct thread_item
*item
;
2643 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2646 if (!ptid_equal (item
->ptid
, null_ptid
))
2648 struct private_thread_info
*info
;
2649 /* In non-stop mode, we assume new found threads
2650 are running until proven otherwise with a
2651 stop reply. In all-stop, we can only get
2652 here if all threads are stopped. */
2653 int running
= non_stop
? 1 : 0;
2655 remote_notice_new_inferior (item
->ptid
, running
);
2657 info
= demand_private_info (item
->ptid
);
2658 info
->core
= item
->core
;
2659 info
->extra
= item
->extra
;
2666 do_cleanups (back_to
);
2671 if (use_threadinfo_query
)
2673 putpkt ("qfThreadInfo");
2674 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2676 if (bufp
[0] != '\0') /* q packet recognized */
2678 while (*bufp
++ == 'm') /* reply contains one or more TID */
2682 new_thread
= read_ptid (bufp
, &bufp
);
2683 if (!ptid_equal (new_thread
, null_ptid
))
2685 /* In non-stop mode, we assume new found threads
2686 are running until proven otherwise with a
2687 stop reply. In all-stop, we can only get
2688 here if all threads are stopped. */
2689 int running
= non_stop
? 1 : 0;
2691 remote_notice_new_inferior (new_thread
, running
);
2694 while (*bufp
++ == ','); /* comma-separated list */
2695 putpkt ("qsThreadInfo");
2696 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2703 /* Only qfThreadInfo is supported in non-stop mode. */
2707 /* Else fall back to old method based on jmetzler protocol. */
2708 use_threadinfo_query
= 0;
2709 remote_find_new_threads ();
2714 * Collect a descriptive string about the given thread.
2715 * The target may say anything it wants to about the thread
2716 * (typically info about its blocked / runnable state, name, etc.).
2717 * This string will appear in the info threads display.
2719 * Optional: targets are not required to implement this function.
2723 remote_threads_extra_info (struct thread_info
*tp
)
2725 struct remote_state
*rs
= get_remote_state ();
2729 struct gdb_ext_thread_info threadinfo
;
2730 static char display_buf
[100]; /* arbitrary... */
2731 int n
= 0; /* position in display_buf */
2733 if (remote_desc
== 0) /* paranoia */
2734 internal_error (__FILE__
, __LINE__
,
2735 _("remote_threads_extra_info"));
2737 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2738 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2739 /* This is the main thread which was added by GDB. The remote
2740 server doesn't know about it. */
2743 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2745 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2747 if (info
&& info
->private)
2748 return info
->private->extra
;
2753 if (use_threadextra_query
)
2756 char *endb
= rs
->buf
+ get_remote_packet_size ();
2758 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2760 write_ptid (b
, endb
, tp
->ptid
);
2763 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2764 if (rs
->buf
[0] != 0)
2766 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2767 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2768 display_buf
[result
] = '\0';
2773 /* If the above query fails, fall back to the old method. */
2774 use_threadextra_query
= 0;
2775 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2776 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2777 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2778 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2779 if (threadinfo
.active
)
2781 if (*threadinfo
.shortname
)
2782 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2783 " Name: %s,", threadinfo
.shortname
);
2784 if (*threadinfo
.display
)
2785 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2786 " State: %s,", threadinfo
.display
);
2787 if (*threadinfo
.more_display
)
2788 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2789 " Priority: %s", threadinfo
.more_display
);
2793 /* For purely cosmetic reasons, clear up trailing commas. */
2794 if (',' == display_buf
[n
-1])
2795 display_buf
[n
-1] = ' ';
2804 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2805 struct static_tracepoint_marker
*marker
)
2807 struct remote_state
*rs
= get_remote_state ();
2810 sprintf (p
, "qTSTMat:");
2812 p
+= hexnumstr (p
, addr
);
2814 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2818 error (_("Remote failure reply: %s"), p
);
2822 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2830 free_current_marker (void *arg
)
2832 struct static_tracepoint_marker
**marker_p
= arg
;
2834 if (*marker_p
!= NULL
)
2836 release_static_tracepoint_marker (*marker_p
);
2843 static VEC(static_tracepoint_marker_p
) *
2844 remote_static_tracepoint_markers_by_strid (const char *strid
)
2846 struct remote_state
*rs
= get_remote_state ();
2847 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2848 struct static_tracepoint_marker
*marker
= NULL
;
2849 struct cleanup
*old_chain
;
2852 /* Ask for a first packet of static tracepoint marker
2855 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2858 error (_("Remote failure reply: %s"), p
);
2860 old_chain
= make_cleanup (free_current_marker
, &marker
);
2865 marker
= XCNEW (struct static_tracepoint_marker
);
2869 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2871 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2873 VEC_safe_push (static_tracepoint_marker_p
,
2879 release_static_tracepoint_marker (marker
);
2880 memset (marker
, 0, sizeof (*marker
));
2883 while (*p
++ == ','); /* comma-separated list */
2884 /* Ask for another packet of static tracepoint definition. */
2886 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2890 do_cleanups (old_chain
);
2895 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2898 remote_get_ada_task_ptid (long lwp
, long thread
)
2900 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2904 /* Restart the remote side; this is an extended protocol operation. */
2907 extended_remote_restart (void)
2909 struct remote_state
*rs
= get_remote_state ();
2911 /* Send the restart command; for reasons I don't understand the
2912 remote side really expects a number after the "R". */
2913 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2916 remote_fileio_reset ();
2919 /* Clean up connection to a remote debugger. */
2922 remote_close (int quitting
)
2924 if (remote_desc
== NULL
)
2925 return; /* already closed */
2927 /* Make sure we leave stdin registered in the event loop, and we
2928 don't leave the async SIGINT signal handler installed. */
2929 remote_terminal_ours ();
2931 serial_close (remote_desc
);
2934 /* We don't have a connection to the remote stub anymore. Get rid
2935 of all the inferiors and their threads we were controlling.
2936 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
2937 will be unable to find the thread corresponding to (pid, 0, 0). */
2938 inferior_ptid
= null_ptid
;
2939 discard_all_inferiors ();
2941 /* We're no longer interested in any of these events. */
2942 discard_pending_stop_replies (-1);
2944 if (remote_async_inferior_event_token
)
2945 delete_async_event_handler (&remote_async_inferior_event_token
);
2946 if (remote_async_get_pending_events_token
)
2947 delete_async_event_handler (&remote_async_get_pending_events_token
);
2950 /* Query the remote side for the text, data and bss offsets. */
2955 struct remote_state
*rs
= get_remote_state ();
2958 int lose
, num_segments
= 0, do_sections
, do_segments
;
2959 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2960 struct section_offsets
*offs
;
2961 struct symfile_segment_data
*data
;
2963 if (symfile_objfile
== NULL
)
2966 putpkt ("qOffsets");
2967 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2970 if (buf
[0] == '\000')
2971 return; /* Return silently. Stub doesn't support
2975 warning (_("Remote failure reply: %s"), buf
);
2979 /* Pick up each field in turn. This used to be done with scanf, but
2980 scanf will make trouble if CORE_ADDR size doesn't match
2981 conversion directives correctly. The following code will work
2982 with any size of CORE_ADDR. */
2983 text_addr
= data_addr
= bss_addr
= 0;
2987 if (strncmp (ptr
, "Text=", 5) == 0)
2990 /* Don't use strtol, could lose on big values. */
2991 while (*ptr
&& *ptr
!= ';')
2992 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2994 if (strncmp (ptr
, ";Data=", 6) == 0)
2997 while (*ptr
&& *ptr
!= ';')
2998 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3003 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3006 while (*ptr
&& *ptr
!= ';')
3007 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3009 if (bss_addr
!= data_addr
)
3010 warning (_("Target reported unsupported offsets: %s"), buf
);
3015 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3018 /* Don't use strtol, could lose on big values. */
3019 while (*ptr
&& *ptr
!= ';')
3020 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3023 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3026 while (*ptr
&& *ptr
!= ';')
3027 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3035 error (_("Malformed response to offset query, %s"), buf
);
3036 else if (*ptr
!= '\0')
3037 warning (_("Target reported unsupported offsets: %s"), buf
);
3039 offs
= ((struct section_offsets
*)
3040 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3041 memcpy (offs
, symfile_objfile
->section_offsets
,
3042 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3044 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3045 do_segments
= (data
!= NULL
);
3046 do_sections
= num_segments
== 0;
3048 if (num_segments
> 0)
3050 segments
[0] = text_addr
;
3051 segments
[1] = data_addr
;
3053 /* If we have two segments, we can still try to relocate everything
3054 by assuming that the .text and .data offsets apply to the whole
3055 text and data segments. Convert the offsets given in the packet
3056 to base addresses for symfile_map_offsets_to_segments. */
3057 else if (data
&& data
->num_segments
== 2)
3059 segments
[0] = data
->segment_bases
[0] + text_addr
;
3060 segments
[1] = data
->segment_bases
[1] + data_addr
;
3063 /* If the object file has only one segment, assume that it is text
3064 rather than data; main programs with no writable data are rare,
3065 but programs with no code are useless. Of course the code might
3066 have ended up in the data segment... to detect that we would need
3067 the permissions here. */
3068 else if (data
&& data
->num_segments
== 1)
3070 segments
[0] = data
->segment_bases
[0] + text_addr
;
3073 /* There's no way to relocate by segment. */
3079 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3080 offs
, num_segments
, segments
);
3082 if (ret
== 0 && !do_sections
)
3083 error (_("Can not handle qOffsets TextSeg "
3084 "response with this symbol file"));
3091 free_symfile_segment_data (data
);
3095 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3097 /* This is a temporary kludge to force data and bss to use the
3098 same offsets because that's what nlmconv does now. The real
3099 solution requires changes to the stub and remote.c that I
3100 don't have time to do right now. */
3102 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3103 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3106 objfile_relocate (symfile_objfile
, offs
);
3109 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3110 threads we know are stopped already. This is used during the
3111 initial remote connection in non-stop mode --- threads that are
3112 reported as already being stopped are left stopped. */
3115 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3117 /* If we have a stop reply for this thread, it must be stopped. */
3118 if (peek_stop_reply (thread
->ptid
))
3119 set_stop_requested (thread
->ptid
, 1);
3124 /* Send interrupt_sequence to remote target. */
3126 send_interrupt_sequence (void)
3128 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3129 serial_write (remote_desc
, "\x03", 1);
3130 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3131 serial_send_break (remote_desc
);
3132 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3134 serial_send_break (remote_desc
);
3135 serial_write (remote_desc
, "g", 1);
3138 internal_error (__FILE__
, __LINE__
,
3139 _("Invalid value for interrupt_sequence_mode: %s."),
3140 interrupt_sequence_mode
);
3144 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3146 struct remote_state
*rs
= get_remote_state ();
3147 struct packet_config
*noack_config
;
3148 char *wait_status
= NULL
;
3150 volatile struct gdb_exception ex
;
3152 immediate_quit
++; /* Allow user to interrupt it. */
3154 if (interrupt_on_connect
)
3155 send_interrupt_sequence ();
3157 /* Ack any packet which the remote side has already sent. */
3158 serial_write (remote_desc
, "+", 1);
3160 /* The first packet we send to the target is the optional "supported
3161 packets" request. If the target can answer this, it will tell us
3162 which later probes to skip. */
3163 remote_query_supported ();
3165 /* If the stub wants to get a QAllow, compose one and send it. */
3166 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3167 remote_set_permissions ();
3169 /* Next, we possibly activate noack mode.
3171 If the QStartNoAckMode packet configuration is set to AUTO,
3172 enable noack mode if the stub reported a wish for it with
3175 If set to TRUE, then enable noack mode even if the stub didn't
3176 report it in qSupported. If the stub doesn't reply OK, the
3177 session ends with an error.
3179 If FALSE, then don't activate noack mode, regardless of what the
3180 stub claimed should be the default with qSupported. */
3182 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3184 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3185 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3186 && noack_config
->support
== PACKET_ENABLE
))
3188 putpkt ("QStartNoAckMode");
3189 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3190 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3196 /* Tell the remote that we are using the extended protocol. */
3198 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3201 /* Next, if the target can specify a description, read it. We do
3202 this before anything involving memory or registers. */
3203 target_find_description ();
3205 /* Next, now that we know something about the target, update the
3206 address spaces in the program spaces. */
3207 update_address_spaces ();
3209 /* On OSs where the list of libraries is global to all
3210 processes, we fetch them early. */
3211 if (gdbarch_has_global_solist (target_gdbarch
))
3212 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3216 if (!rs
->non_stop_aware
)
3217 error (_("Non-stop mode requested, but remote "
3218 "does not support non-stop"));
3220 putpkt ("QNonStop:1");
3221 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3223 if (strcmp (rs
->buf
, "OK") != 0)
3224 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3226 /* Find about threads and processes the stub is already
3227 controlling. We default to adding them in the running state.
3228 The '?' query below will then tell us about which threads are
3230 remote_threads_info (target
);
3232 else if (rs
->non_stop_aware
)
3234 /* Don't assume that the stub can operate in all-stop mode.
3235 Request it explicitely. */
3236 putpkt ("QNonStop:0");
3237 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3239 if (strcmp (rs
->buf
, "OK") != 0)
3240 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3243 /* Check whether the target is running now. */
3245 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3249 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3252 error (_("The target is not running (try extended-remote?)"));
3254 /* We're connected, but not running. Drop out before we
3255 call start_remote. */
3260 /* Save the reply for later. */
3261 wait_status
= alloca (strlen (rs
->buf
) + 1);
3262 strcpy (wait_status
, rs
->buf
);
3265 /* Let the stub know that we want it to return the thread. */
3266 set_continue_thread (minus_one_ptid
);
3268 /* Without this, some commands which require an active target
3269 (such as kill) won't work. This variable serves (at least)
3270 double duty as both the pid of the target process (if it has
3271 such), and as a flag indicating that a target is active.
3272 These functions should be split out into seperate variables,
3273 especially since GDB will someday have a notion of debugging
3274 several processes. */
3275 inferior_ptid
= magic_null_ptid
;
3277 /* Now, if we have thread information, update inferior_ptid. */
3278 inferior_ptid
= remote_current_thread (inferior_ptid
);
3280 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3282 /* Always add the main thread. */
3283 add_thread_silent (inferior_ptid
);
3285 /* init_wait_for_inferior should be called before get_offsets in order
3286 to manage `inserted' flag in bp loc in a correct state.
3287 breakpoint_init_inferior, called from init_wait_for_inferior, set
3288 `inserted' flag to 0, while before breakpoint_re_set, called from
3289 start_remote, set `inserted' flag to 1. In the initialization of
3290 inferior, breakpoint_init_inferior should be called first, and then
3291 breakpoint_re_set can be called. If this order is broken, state of
3292 `inserted' flag is wrong, and cause some problems on breakpoint
3294 init_wait_for_inferior ();
3296 get_offsets (); /* Get text, data & bss offsets. */
3298 /* If we could not find a description using qXfer, and we know
3299 how to do it some other way, try again. This is not
3300 supported for non-stop; it could be, but it is tricky if
3301 there are no stopped threads when we connect. */
3302 if (remote_read_description_p (target
)
3303 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3305 target_clear_description ();
3306 target_find_description ();
3309 /* Use the previously fetched status. */
3310 gdb_assert (wait_status
!= NULL
);
3311 strcpy (rs
->buf
, wait_status
);
3312 rs
->cached_wait_status
= 1;
3315 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3319 /* Clear WFI global state. Do this before finding about new
3320 threads and inferiors, and setting the current inferior.
3321 Otherwise we would clear the proceed status of the current
3322 inferior when we want its stop_soon state to be preserved
3323 (see notice_new_inferior). */
3324 init_wait_for_inferior ();
3326 /* In non-stop, we will either get an "OK", meaning that there
3327 are no stopped threads at this time; or, a regular stop
3328 reply. In the latter case, there may be more than one thread
3329 stopped --- we pull them all out using the vStopped
3331 if (strcmp (rs
->buf
, "OK") != 0)
3333 struct stop_reply
*stop_reply
;
3334 struct cleanup
*old_chain
;
3336 stop_reply
= stop_reply_xmalloc ();
3337 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3339 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3340 discard_cleanups (old_chain
);
3342 /* get_pending_stop_replies acks this one, and gets the rest
3344 pending_stop_reply
= stop_reply
;
3345 remote_get_pending_stop_replies ();
3347 /* Make sure that threads that were stopped remain
3349 iterate_over_threads (set_stop_requested_callback
, NULL
);
3352 if (target_can_async_p ())
3353 target_async (inferior_event_handler
, 0);
3355 if (thread_count () == 0)
3358 error (_("The target is not running (try extended-remote?)"));
3360 /* We're connected, but not running. Drop out before we
3361 call start_remote. */
3365 /* Let the stub know that we want it to return the thread. */
3367 /* Force the stub to choose a thread. */
3368 set_general_thread (null_ptid
);
3371 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3372 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3373 error (_("remote didn't report the current thread in non-stop mode"));
3375 get_offsets (); /* Get text, data & bss offsets. */
3377 /* In non-stop mode, any cached wait status will be stored in
3378 the stop reply queue. */
3379 gdb_assert (wait_status
== NULL
);
3381 /* Report all signals during attach/startup. */
3382 remote_pass_signals (0, NULL
);
3385 /* If we connected to a live target, do some additional setup. */
3386 if (target_has_execution
)
3388 if (exec_bfd
) /* No use without an exec file. */
3389 remote_check_symbols (symfile_objfile
);
3392 /* Possibly the target has been engaged in a trace run started
3393 previously; find out where things are at. */
3394 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
3396 ret
= remote_get_trace_status (current_trace_status ());
3400 warning (_("%s"), ex
.message
);
3405 struct uploaded_tp
*uploaded_tps
= NULL
;
3406 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3408 if (current_trace_status ()->running
)
3409 printf_filtered (_("Trace is already running on the target.\n"));
3411 /* Get trace state variables first, they may be checked when
3412 parsing uploaded commands. */
3414 remote_upload_trace_state_variables (&uploaded_tsvs
);
3416 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3418 remote_upload_tracepoints (&uploaded_tps
);
3420 merge_uploaded_tracepoints (&uploaded_tps
);
3423 /* If breakpoints are global, insert them now. */
3424 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3425 && breakpoints_always_inserted_mode ())
3426 insert_breakpoints ();
3429 /* Open a connection to a remote debugger.
3430 NAME is the filename used for communication. */
3433 remote_open (char *name
, int from_tty
)
3435 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3438 /* Open a connection to a remote debugger using the extended
3439 remote gdb protocol. NAME is the filename used for communication. */
3442 extended_remote_open (char *name
, int from_tty
)
3444 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3447 /* Generic code for opening a connection to a remote target. */
3450 init_all_packet_configs (void)
3454 for (i
= 0; i
< PACKET_MAX
; i
++)
3455 update_packet_config (&remote_protocol_packets
[i
]);
3458 /* Symbol look-up. */
3461 remote_check_symbols (struct objfile
*objfile
)
3463 struct remote_state
*rs
= get_remote_state ();
3464 char *msg
, *reply
, *tmp
;
3465 struct minimal_symbol
*sym
;
3468 /* The remote side has no concept of inferiors that aren't running
3469 yet, it only knows about running processes. If we're connected
3470 but our current inferior is not running, we should not invite the
3471 remote target to request symbol lookups related to its
3472 (unrelated) current process. */
3473 if (!target_has_execution
)
3476 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3479 /* Make sure the remote is pointing at the right process. Note
3480 there's no way to select "no process". */
3481 set_general_process ();
3483 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3484 because we need both at the same time. */
3485 msg
= alloca (get_remote_packet_size ());
3487 /* Invite target to request symbol lookups. */
3489 putpkt ("qSymbol::");
3490 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3491 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3494 while (strncmp (reply
, "qSymbol:", 8) == 0)
3497 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3499 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3501 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3504 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3505 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3507 /* If this is a function address, return the start of code
3508 instead of any data function descriptor. */
3509 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3513 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3514 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3518 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3523 static struct serial
*
3524 remote_serial_open (char *name
)
3526 static int udp_warning
= 0;
3528 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3529 of in ser-tcp.c, because it is the remote protocol assuming that the
3530 serial connection is reliable and not the serial connection promising
3532 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3534 warning (_("The remote protocol may be unreliable over UDP.\n"
3535 "Some events may be lost, rendering further debugging "
3540 return serial_open (name
);
3543 /* Inform the target of our permission settings. The permission flags
3544 work without this, but if the target knows the settings, it can do
3545 a couple things. First, it can add its own check, to catch cases
3546 that somehow manage to get by the permissions checks in target
3547 methods. Second, if the target is wired to disallow particular
3548 settings (for instance, a system in the field that is not set up to
3549 be able to stop at a breakpoint), it can object to any unavailable
3553 remote_set_permissions (void)
3555 struct remote_state
*rs
= get_remote_state ();
3557 sprintf (rs
->buf
, "QAllow:"
3558 "WriteReg:%x;WriteMem:%x;"
3559 "InsertBreak:%x;InsertTrace:%x;"
3560 "InsertFastTrace:%x;Stop:%x",
3561 may_write_registers
, may_write_memory
,
3562 may_insert_breakpoints
, may_insert_tracepoints
,
3563 may_insert_fast_tracepoints
, may_stop
);
3565 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3567 /* If the target didn't like the packet, warn the user. Do not try
3568 to undo the user's settings, that would just be maddening. */
3569 if (strcmp (rs
->buf
, "OK") != 0)
3570 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3573 /* This type describes each known response to the qSupported
3575 struct protocol_feature
3577 /* The name of this protocol feature. */
3580 /* The default for this protocol feature. */
3581 enum packet_support default_support
;
3583 /* The function to call when this feature is reported, or after
3584 qSupported processing if the feature is not supported.
3585 The first argument points to this structure. The second
3586 argument indicates whether the packet requested support be
3587 enabled, disabled, or probed (or the default, if this function
3588 is being called at the end of processing and this feature was
3589 not reported). The third argument may be NULL; if not NULL, it
3590 is a NUL-terminated string taken from the packet following
3591 this feature's name and an equals sign. */
3592 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3595 /* The corresponding packet for this feature. Only used if
3596 FUNC is remote_supported_packet. */
3601 remote_supported_packet (const struct protocol_feature
*feature
,
3602 enum packet_support support
,
3603 const char *argument
)
3607 warning (_("Remote qSupported response supplied an unexpected value for"
3608 " \"%s\"."), feature
->name
);
3612 if (remote_protocol_packets
[feature
->packet
].support
3613 == PACKET_SUPPORT_UNKNOWN
)
3614 remote_protocol_packets
[feature
->packet
].support
= support
;
3618 remote_packet_size (const struct protocol_feature
*feature
,
3619 enum packet_support support
, const char *value
)
3621 struct remote_state
*rs
= get_remote_state ();
3626 if (support
!= PACKET_ENABLE
)
3629 if (value
== NULL
|| *value
== '\0')
3631 warning (_("Remote target reported \"%s\" without a size."),
3637 packet_size
= strtol (value
, &value_end
, 16);
3638 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3640 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3641 feature
->name
, value
);
3645 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3647 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3648 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3649 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3652 /* Record the new maximum packet size. */
3653 rs
->explicit_packet_size
= packet_size
;
3657 remote_multi_process_feature (const struct protocol_feature
*feature
,
3658 enum packet_support support
, const char *value
)
3660 struct remote_state
*rs
= get_remote_state ();
3662 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3666 remote_non_stop_feature (const struct protocol_feature
*feature
,
3667 enum packet_support support
, const char *value
)
3669 struct remote_state
*rs
= get_remote_state ();
3671 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3675 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3676 enum packet_support support
,
3679 struct remote_state
*rs
= get_remote_state ();
3681 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3685 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3686 enum packet_support support
,
3689 struct remote_state
*rs
= get_remote_state ();
3691 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3695 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3696 enum packet_support support
,
3699 struct remote_state
*rs
= get_remote_state ();
3701 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3705 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3706 enum packet_support support
,
3709 struct remote_state
*rs
= get_remote_state ();
3711 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3715 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3716 enum packet_support support
,
3719 struct remote_state
*rs
= get_remote_state ();
3721 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3724 static struct protocol_feature remote_protocol_features
[] = {
3725 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3726 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3727 PACKET_qXfer_auxv
},
3728 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3729 PACKET_qXfer_features
},
3730 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3731 PACKET_qXfer_libraries
},
3732 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3733 PACKET_qXfer_memory_map
},
3734 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3735 PACKET_qXfer_spu_read
},
3736 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3737 PACKET_qXfer_spu_write
},
3738 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3739 PACKET_qXfer_osdata
},
3740 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3741 PACKET_qXfer_threads
},
3742 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3743 PACKET_qXfer_traceframe_info
},
3744 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3745 PACKET_QPassSignals
},
3746 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3747 PACKET_QStartNoAckMode
},
3748 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3749 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3750 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3751 PACKET_qXfer_siginfo_read
},
3752 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3753 PACKET_qXfer_siginfo_write
},
3754 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3755 PACKET_ConditionalTracepoints
},
3756 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3757 PACKET_FastTracepoints
},
3758 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3759 PACKET_StaticTracepoints
},
3760 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3762 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3764 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3766 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3767 PACKET_TracepointSource
},
3768 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3770 { "EnableDisableTracepoints", PACKET_DISABLE
,
3771 remote_enable_disable_tracepoint_feature
, -1 },
3774 static char *remote_support_xml
;
3776 /* Register string appended to "xmlRegisters=" in qSupported query. */
3779 register_remote_support_xml (const char *xml
)
3781 #if defined(HAVE_LIBEXPAT)
3782 if (remote_support_xml
== NULL
)
3783 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3786 char *copy
= xstrdup (remote_support_xml
+ 13);
3787 char *p
= strtok (copy
, ",");
3791 if (strcmp (p
, xml
) == 0)
3798 while ((p
= strtok (NULL
, ",")) != NULL
);
3801 remote_support_xml
= reconcat (remote_support_xml
,
3802 remote_support_xml
, ",", xml
,
3809 remote_query_supported_append (char *msg
, const char *append
)
3812 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3814 return xstrdup (append
);
3818 remote_query_supported (void)
3820 struct remote_state
*rs
= get_remote_state ();
3823 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3825 /* The packet support flags are handled differently for this packet
3826 than for most others. We treat an error, a disabled packet, and
3827 an empty response identically: any features which must be reported
3828 to be used will be automatically disabled. An empty buffer
3829 accomplishes this, since that is also the representation for a list
3830 containing no features. */
3833 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3836 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
3839 q
= remote_query_supported_append (q
, "multiprocess+");
3841 if (remote_support_xml
)
3842 q
= remote_query_supported_append (q
, remote_support_xml
);
3844 q
= remote_query_supported_append (q
, "qRelocInsn+");
3846 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
3849 do_cleanups (old_chain
);
3851 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3853 /* If an error occured, warn, but do not return - just reset the
3854 buffer to empty and go on to disable features. */
3855 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3858 warning (_("Remote failure reply: %s"), rs
->buf
);
3863 memset (seen
, 0, sizeof (seen
));
3868 enum packet_support is_supported
;
3869 char *p
, *end
, *name_end
, *value
;
3871 /* First separate out this item from the rest of the packet. If
3872 there's another item after this, we overwrite the separator
3873 (terminated strings are much easier to work with). */
3875 end
= strchr (p
, ';');
3878 end
= p
+ strlen (p
);
3888 warning (_("empty item in \"qSupported\" response"));
3893 name_end
= strchr (p
, '=');
3896 /* This is a name=value entry. */
3897 is_supported
= PACKET_ENABLE
;
3898 value
= name_end
+ 1;
3907 is_supported
= PACKET_ENABLE
;
3911 is_supported
= PACKET_DISABLE
;
3915 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3919 warning (_("unrecognized item \"%s\" "
3920 "in \"qSupported\" response"), p
);
3926 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3927 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3929 const struct protocol_feature
*feature
;
3932 feature
= &remote_protocol_features
[i
];
3933 feature
->func (feature
, is_supported
, value
);
3938 /* If we increased the packet size, make sure to increase the global
3939 buffer size also. We delay this until after parsing the entire
3940 qSupported packet, because this is the same buffer we were
3942 if (rs
->buf_size
< rs
->explicit_packet_size
)
3944 rs
->buf_size
= rs
->explicit_packet_size
;
3945 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3948 /* Handle the defaults for unmentioned features. */
3949 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3952 const struct protocol_feature
*feature
;
3954 feature
= &remote_protocol_features
[i
];
3955 feature
->func (feature
, feature
->default_support
, NULL
);
3961 remote_open_1 (char *name
, int from_tty
,
3962 struct target_ops
*target
, int extended_p
)
3964 struct remote_state
*rs
= get_remote_state ();
3967 error (_("To open a remote debug connection, you need to specify what\n"
3968 "serial device is attached to the remote system\n"
3969 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3971 /* See FIXME above. */
3972 if (!target_async_permitted
)
3973 wait_forever_enabled_p
= 1;
3975 /* If we're connected to a running target, target_preopen will kill it.
3976 But if we're connected to a target system with no running process,
3977 then we will still be connected when it returns. Ask this question
3978 first, before target_preopen has a chance to kill anything. */
3979 if (remote_desc
!= NULL
&& !have_inferiors ())
3982 || query (_("Already connected to a remote target. Disconnect? ")))
3985 error (_("Still connected."));
3988 target_preopen (from_tty
);
3990 unpush_target (target
);
3992 /* This time without a query. If we were connected to an
3993 extended-remote target and target_preopen killed the running
3994 process, we may still be connected. If we are starting "target
3995 remote" now, the extended-remote target will not have been
3996 removed by unpush_target. */
3997 if (remote_desc
!= NULL
&& !have_inferiors ())
4000 /* Make sure we send the passed signals list the next time we resume. */
4001 xfree (last_pass_packet
);
4002 last_pass_packet
= NULL
;
4004 remote_fileio_reset ();
4005 reopen_exec_file ();
4008 remote_desc
= remote_serial_open (name
);
4010 perror_with_name (name
);
4012 if (baud_rate
!= -1)
4014 if (serial_setbaudrate (remote_desc
, baud_rate
))
4016 /* The requested speed could not be set. Error out to
4017 top level after closing remote_desc. Take care to
4018 set remote_desc to NULL to avoid closing remote_desc
4020 serial_close (remote_desc
);
4022 perror_with_name (name
);
4026 serial_raw (remote_desc
);
4028 /* If there is something sitting in the buffer we might take it as a
4029 response to a command, which would be bad. */
4030 serial_flush_input (remote_desc
);
4034 puts_filtered ("Remote debugging using ");
4035 puts_filtered (name
);
4036 puts_filtered ("\n");
4038 push_target (target
); /* Switch to using remote target now. */
4040 /* Register extra event sources in the event loop. */
4041 remote_async_inferior_event_token
4042 = create_async_event_handler (remote_async_inferior_event_handler
,
4044 remote_async_get_pending_events_token
4045 = create_async_event_handler (remote_async_get_pending_events_handler
,
4048 /* Reset the target state; these things will be queried either by
4049 remote_query_supported or as they are needed. */
4050 init_all_packet_configs ();
4051 rs
->cached_wait_status
= 0;
4052 rs
->explicit_packet_size
= 0;
4054 rs
->multi_process_aware
= 0;
4055 rs
->extended
= extended_p
;
4056 rs
->non_stop_aware
= 0;
4057 rs
->waiting_for_stop_reply
= 0;
4058 rs
->ctrlc_pending_p
= 0;
4060 general_thread
= not_sent_ptid
;
4061 continue_thread
= not_sent_ptid
;
4062 remote_traceframe_number
= -1;
4064 /* Probe for ability to use "ThreadInfo" query, as required. */
4065 use_threadinfo_query
= 1;
4066 use_threadextra_query
= 1;
4068 if (target_async_permitted
)
4070 /* With this target we start out by owning the terminal. */
4071 remote_async_terminal_ours_p
= 1;
4073 /* FIXME: cagney/1999-09-23: During the initial connection it is
4074 assumed that the target is already ready and able to respond to
4075 requests. Unfortunately remote_start_remote() eventually calls
4076 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4077 around this. Eventually a mechanism that allows
4078 wait_for_inferior() to expect/get timeouts will be
4080 wait_forever_enabled_p
= 0;
4083 /* First delete any symbols previously loaded from shared libraries. */
4084 no_shared_libraries (NULL
, 0);
4087 init_thread_list ();
4089 /* Start the remote connection. If error() or QUIT, discard this
4090 target (we'd otherwise be in an inconsistent state) and then
4091 propogate the error on up the exception chain. This ensures that
4092 the caller doesn't stumble along blindly assuming that the
4093 function succeeded. The CLI doesn't have this problem but other
4094 UI's, such as MI do.
4096 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4097 this function should return an error indication letting the
4098 caller restore the previous state. Unfortunately the command
4099 ``target remote'' is directly wired to this function making that
4100 impossible. On a positive note, the CLI side of this problem has
4101 been fixed - the function set_cmd_context() makes it possible for
4102 all the ``target ....'' commands to share a common callback
4103 function. See cli-dump.c. */
4105 volatile struct gdb_exception ex
;
4107 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4109 remote_start_remote (from_tty
, target
, extended_p
);
4113 /* Pop the partially set up target - unless something else did
4114 already before throwing the exception. */
4115 if (remote_desc
!= NULL
)
4117 if (target_async_permitted
)
4118 wait_forever_enabled_p
= 1;
4119 throw_exception (ex
);
4123 if (target_async_permitted
)
4124 wait_forever_enabled_p
= 1;
4127 /* This takes a program previously attached to and detaches it. After
4128 this is done, GDB can be used to debug some other program. We
4129 better not have left any breakpoints in the target program or it'll
4130 die when it hits one. */
4133 remote_detach_1 (char *args
, int from_tty
, int extended
)
4135 int pid
= ptid_get_pid (inferior_ptid
);
4136 struct remote_state
*rs
= get_remote_state ();
4139 error (_("Argument given to \"detach\" when remotely debugging."));
4141 if (!target_has_execution
)
4142 error (_("No process to detach from."));
4144 /* Tell the remote target to detach. */
4145 if (remote_multi_process_p (rs
))
4146 sprintf (rs
->buf
, "D;%x", pid
);
4148 strcpy (rs
->buf
, "D");
4151 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4153 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4155 else if (rs
->buf
[0] == '\0')
4156 error (_("Remote doesn't know how to detach"));
4158 error (_("Can't detach process."));
4162 if (remote_multi_process_p (rs
))
4163 printf_filtered (_("Detached from remote %s.\n"),
4164 target_pid_to_str (pid_to_ptid (pid
)));
4168 puts_filtered (_("Detached from remote process.\n"));
4170 puts_filtered (_("Ending remote debugging.\n"));
4174 discard_pending_stop_replies (pid
);
4175 target_mourn_inferior ();
4179 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4181 remote_detach_1 (args
, from_tty
, 0);
4185 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4187 remote_detach_1 (args
, from_tty
, 1);
4190 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4193 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4196 error (_("Argument given to \"disconnect\" when remotely debugging."));
4198 /* Make sure we unpush even the extended remote targets; mourn
4199 won't do it. So call remote_mourn_1 directly instead of
4200 target_mourn_inferior. */
4201 remote_mourn_1 (target
);
4204 puts_filtered ("Ending remote debugging.\n");
4207 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4208 be chatty about it. */
4211 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4213 struct remote_state
*rs
= get_remote_state ();
4215 char *wait_status
= NULL
;
4217 pid
= parse_pid_to_attach (args
);
4219 /* Remote PID can be freely equal to getpid, do not check it here the same
4220 way as in other targets. */
4222 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4223 error (_("This target does not support attaching to a process"));
4225 sprintf (rs
->buf
, "vAttach;%x", pid
);
4227 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4229 if (packet_ok (rs
->buf
,
4230 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4233 printf_unfiltered (_("Attached to %s\n"),
4234 target_pid_to_str (pid_to_ptid (pid
)));
4238 /* Save the reply for later. */
4239 wait_status
= alloca (strlen (rs
->buf
) + 1);
4240 strcpy (wait_status
, rs
->buf
);
4242 else if (strcmp (rs
->buf
, "OK") != 0)
4243 error (_("Attaching to %s failed with: %s"),
4244 target_pid_to_str (pid_to_ptid (pid
)),
4247 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4248 error (_("This target does not support attaching to a process"));
4250 error (_("Attaching to %s failed"),
4251 target_pid_to_str (pid_to_ptid (pid
)));
4253 set_current_inferior (remote_add_inferior (pid
, 1));
4255 inferior_ptid
= pid_to_ptid (pid
);
4259 struct thread_info
*thread
;
4261 /* Get list of threads. */
4262 remote_threads_info (target
);
4264 thread
= first_thread_of_process (pid
);
4266 inferior_ptid
= thread
->ptid
;
4268 inferior_ptid
= pid_to_ptid (pid
);
4270 /* Invalidate our notion of the remote current thread. */
4271 record_currthread (minus_one_ptid
);
4275 /* Now, if we have thread information, update inferior_ptid. */
4276 inferior_ptid
= remote_current_thread (inferior_ptid
);
4278 /* Add the main thread to the thread list. */
4279 add_thread_silent (inferior_ptid
);
4282 /* Next, if the target can specify a description, read it. We do
4283 this before anything involving memory or registers. */
4284 target_find_description ();
4288 /* Use the previously fetched status. */
4289 gdb_assert (wait_status
!= NULL
);
4291 if (target_can_async_p ())
4293 struct stop_reply
*stop_reply
;
4294 struct cleanup
*old_chain
;
4296 stop_reply
= stop_reply_xmalloc ();
4297 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4298 remote_parse_stop_reply (wait_status
, stop_reply
);
4299 discard_cleanups (old_chain
);
4300 push_stop_reply (stop_reply
);
4302 target_async (inferior_event_handler
, 0);
4306 gdb_assert (wait_status
!= NULL
);
4307 strcpy (rs
->buf
, wait_status
);
4308 rs
->cached_wait_status
= 1;
4312 gdb_assert (wait_status
== NULL
);
4316 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4318 extended_remote_attach_1 (ops
, args
, from_tty
);
4321 /* Convert hex digit A to a number. */
4326 if (a
>= '0' && a
<= '9')
4328 else if (a
>= 'a' && a
<= 'f')
4329 return a
- 'a' + 10;
4330 else if (a
>= 'A' && a
<= 'F')
4331 return a
- 'A' + 10;
4333 error (_("Reply contains invalid hex digit %d"), a
);
4337 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4341 for (i
= 0; i
< count
; i
++)
4343 if (hex
[0] == 0 || hex
[1] == 0)
4345 /* Hex string is short, or of uneven length.
4346 Return the count that has been converted so far. */
4349 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4355 /* Convert number NIB to a hex digit. */
4363 return 'a' + nib
- 10;
4367 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4371 /* May use a length, or a nul-terminated string as input. */
4373 count
= strlen ((char *) bin
);
4375 for (i
= 0; i
< count
; i
++)
4377 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4378 *hex
++ = tohex (*bin
++ & 0xf);
4384 /* Check for the availability of vCont. This function should also check
4388 remote_vcont_probe (struct remote_state
*rs
)
4392 strcpy (rs
->buf
, "vCont?");
4394 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4397 /* Make sure that the features we assume are supported. */
4398 if (strncmp (buf
, "vCont", 5) == 0)
4401 int support_s
, support_S
, support_c
, support_C
;
4407 rs
->support_vCont_t
= 0;
4408 while (p
&& *p
== ';')
4411 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4413 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4415 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4417 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4419 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4420 rs
->support_vCont_t
= 1;
4422 p
= strchr (p
, ';');
4425 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4426 BUF will make packet_ok disable the packet. */
4427 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4431 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4434 /* Helper function for building "vCont" resumptions. Write a
4435 resumption to P. ENDP points to one-passed-the-end of the buffer
4436 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4437 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4438 resumed thread should be single-stepped and/or signalled. If PTID
4439 equals minus_one_ptid, then all threads are resumed; if PTID
4440 represents a process, then all threads of the process are resumed;
4441 the thread to be stepped and/or signalled is given in the global
4445 append_resumption (char *p
, char *endp
,
4446 ptid_t ptid
, int step
, enum target_signal siggnal
)
4448 struct remote_state
*rs
= get_remote_state ();
4450 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4451 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4453 p
+= xsnprintf (p
, endp
- p
, ";s");
4454 else if (siggnal
!= TARGET_SIGNAL_0
)
4455 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4457 p
+= xsnprintf (p
, endp
- p
, ";c");
4459 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4463 /* All (-1) threads of process. */
4464 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4466 p
+= xsnprintf (p
, endp
- p
, ":");
4467 p
= write_ptid (p
, endp
, nptid
);
4469 else if (!ptid_equal (ptid
, minus_one_ptid
))
4471 p
+= xsnprintf (p
, endp
- p
, ":");
4472 p
= write_ptid (p
, endp
, ptid
);
4478 /* Resume the remote inferior by using a "vCont" packet. The thread
4479 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4480 resumed thread should be single-stepped and/or signalled. If PTID
4481 equals minus_one_ptid, then all threads are resumed; the thread to
4482 be stepped and/or signalled is given in the global INFERIOR_PTID.
4483 This function returns non-zero iff it resumes the inferior.
4485 This function issues a strict subset of all possible vCont commands at the
4489 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4491 struct remote_state
*rs
= get_remote_state ();
4495 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4496 remote_vcont_probe (rs
);
4498 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4502 endp
= rs
->buf
+ get_remote_packet_size ();
4504 /* If we could generate a wider range of packets, we'd have to worry
4505 about overflowing BUF. Should there be a generic
4506 "multi-part-packet" packet? */
4508 p
+= xsnprintf (p
, endp
- p
, "vCont");
4510 if (ptid_equal (ptid
, magic_null_ptid
))
4512 /* MAGIC_NULL_PTID means that we don't have any active threads,
4513 so we don't have any TID numbers the inferior will
4514 understand. Make sure to only send forms that do not specify
4516 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4518 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4520 /* Resume all threads (of all processes, or of a single
4521 process), with preference for INFERIOR_PTID. This assumes
4522 inferior_ptid belongs to the set of all threads we are about
4524 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4526 /* Step inferior_ptid, with or without signal. */
4527 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4530 /* And continue others without a signal. */
4531 append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4535 /* Scheduler locking; resume only PTID. */
4536 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4539 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4544 /* In non-stop, the stub replies to vCont with "OK". The stop
4545 reply will be reported asynchronously by means of a `%Stop'
4547 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4548 if (strcmp (rs
->buf
, "OK") != 0)
4549 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4555 /* Tell the remote machine to resume. */
4557 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4559 static int last_sent_step
;
4562 remote_resume (struct target_ops
*ops
,
4563 ptid_t ptid
, int step
, enum target_signal siggnal
)
4565 struct remote_state
*rs
= get_remote_state ();
4568 last_sent_signal
= siggnal
;
4569 last_sent_step
= step
;
4571 /* The vCont packet doesn't need to specify threads via Hc. */
4572 /* No reverse support (yet) for vCont. */
4573 if (execution_direction
!= EXEC_REVERSE
)
4574 if (remote_vcont_resume (ptid
, step
, siggnal
))
4577 /* All other supported resume packets do use Hc, so set the continue
4579 if (ptid_equal (ptid
, minus_one_ptid
))
4580 set_continue_thread (any_thread_ptid
);
4582 set_continue_thread (ptid
);
4585 if (execution_direction
== EXEC_REVERSE
)
4587 /* We don't pass signals to the target in reverse exec mode. */
4588 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4589 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4593 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4594 error (_("Remote reverse-step not supported."));
4596 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4597 error (_("Remote reverse-continue not supported."));
4599 strcpy (buf
, step
? "bs" : "bc");
4601 else if (siggnal
!= TARGET_SIGNAL_0
)
4603 buf
[0] = step
? 'S' : 'C';
4604 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4605 buf
[2] = tohex (((int) siggnal
) & 0xf);
4609 strcpy (buf
, step
? "s" : "c");
4614 /* We are about to start executing the inferior, let's register it
4615 with the event loop. NOTE: this is the one place where all the
4616 execution commands end up. We could alternatively do this in each
4617 of the execution commands in infcmd.c. */
4618 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4619 into infcmd.c in order to allow inferior function calls to work
4620 NOT asynchronously. */
4621 if (target_can_async_p ())
4622 target_async (inferior_event_handler
, 0);
4624 /* We've just told the target to resume. The remote server will
4625 wait for the inferior to stop, and then send a stop reply. In
4626 the mean time, we can't start another command/query ourselves
4627 because the stub wouldn't be ready to process it. This applies
4628 only to the base all-stop protocol, however. In non-stop (which
4629 only supports vCont), the stub replies with an "OK", and is
4630 immediate able to process further serial input. */
4632 rs
->waiting_for_stop_reply
= 1;
4636 /* Set up the signal handler for SIGINT, while the target is
4637 executing, ovewriting the 'regular' SIGINT signal handler. */
4639 initialize_sigint_signal_handler (void)
4641 signal (SIGINT
, handle_remote_sigint
);
4644 /* Signal handler for SIGINT, while the target is executing. */
4646 handle_remote_sigint (int sig
)
4648 signal (sig
, handle_remote_sigint_twice
);
4649 mark_async_signal_handler_wrapper (sigint_remote_token
);
4652 /* Signal handler for SIGINT, installed after SIGINT has already been
4653 sent once. It will take effect the second time that the user sends
4656 handle_remote_sigint_twice (int sig
)
4658 signal (sig
, handle_remote_sigint
);
4659 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4662 /* Perform the real interruption of the target execution, in response
4665 async_remote_interrupt (gdb_client_data arg
)
4668 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4670 target_stop (inferior_ptid
);
4673 /* Perform interrupt, if the first attempt did not succeed. Just give
4674 up on the target alltogether. */
4676 async_remote_interrupt_twice (gdb_client_data arg
)
4679 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4684 /* Reinstall the usual SIGINT handlers, after the target has
4687 cleanup_sigint_signal_handler (void *dummy
)
4689 signal (SIGINT
, handle_sigint
);
4692 /* Send ^C to target to halt it. Target will respond, and send us a
4694 static void (*ofunc
) (int);
4696 /* The command line interface's stop routine. This function is installed
4697 as a signal handler for SIGINT. The first time a user requests a
4698 stop, we call remote_stop to send a break or ^C. If there is no
4699 response from the target (it didn't stop when the user requested it),
4700 we ask the user if he'd like to detach from the target. */
4702 remote_interrupt (int signo
)
4704 /* If this doesn't work, try more severe steps. */
4705 signal (signo
, remote_interrupt_twice
);
4707 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4710 /* The user typed ^C twice. */
4713 remote_interrupt_twice (int signo
)
4715 signal (signo
, ofunc
);
4716 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4717 signal (signo
, remote_interrupt
);
4720 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4721 thread, all threads of a remote process, or all threads of all
4725 remote_stop_ns (ptid_t ptid
)
4727 struct remote_state
*rs
= get_remote_state ();
4729 char *endp
= rs
->buf
+ get_remote_packet_size ();
4731 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4732 remote_vcont_probe (rs
);
4734 if (!rs
->support_vCont_t
)
4735 error (_("Remote server does not support stopping threads"));
4737 if (ptid_equal (ptid
, minus_one_ptid
)
4738 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4739 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4744 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4746 if (ptid_is_pid (ptid
))
4747 /* All (-1) threads of process. */
4748 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4751 /* Small optimization: if we already have a stop reply for
4752 this thread, no use in telling the stub we want this
4754 if (peek_stop_reply (ptid
))
4760 write_ptid (p
, endp
, nptid
);
4763 /* In non-stop, we get an immediate OK reply. The stop reply will
4764 come in asynchronously by notification. */
4766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4767 if (strcmp (rs
->buf
, "OK") != 0)
4768 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4771 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4772 remote target. It is undefined which thread of which process
4773 reports the stop. */
4776 remote_stop_as (ptid_t ptid
)
4778 struct remote_state
*rs
= get_remote_state ();
4780 rs
->ctrlc_pending_p
= 1;
4782 /* If the inferior is stopped already, but the core didn't know
4783 about it yet, just ignore the request. The cached wait status
4784 will be collected in remote_wait. */
4785 if (rs
->cached_wait_status
)
4788 /* Send interrupt_sequence to remote target. */
4789 send_interrupt_sequence ();
4792 /* This is the generic stop called via the target vector. When a target
4793 interrupt is requested, either by the command line or the GUI, we
4794 will eventually end up here. */
4797 remote_stop (ptid_t ptid
)
4800 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4803 remote_stop_ns (ptid
);
4805 remote_stop_as (ptid
);
4808 /* Ask the user what to do when an interrupt is received. */
4811 interrupt_query (void)
4813 target_terminal_ours ();
4815 if (target_can_async_p ())
4817 signal (SIGINT
, handle_sigint
);
4818 deprecated_throw_reason (RETURN_QUIT
);
4822 if (query (_("Interrupted while waiting for the program.\n\
4823 Give up (and stop debugging it)? ")))
4826 deprecated_throw_reason (RETURN_QUIT
);
4830 target_terminal_inferior ();
4833 /* Enable/disable target terminal ownership. Most targets can use
4834 terminal groups to control terminal ownership. Remote targets are
4835 different in that explicit transfer of ownership to/from GDB/target
4839 remote_terminal_inferior (void)
4841 if (!target_async_permitted
)
4842 /* Nothing to do. */
4845 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4846 idempotent. The event-loop GDB talking to an asynchronous target
4847 with a synchronous command calls this function from both
4848 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4849 transfer the terminal to the target when it shouldn't this guard
4851 if (!remote_async_terminal_ours_p
)
4853 delete_file_handler (input_fd
);
4854 remote_async_terminal_ours_p
= 0;
4855 initialize_sigint_signal_handler ();
4856 /* NOTE: At this point we could also register our selves as the
4857 recipient of all input. Any characters typed could then be
4858 passed on down to the target. */
4862 remote_terminal_ours (void)
4864 if (!target_async_permitted
)
4865 /* Nothing to do. */
4868 /* See FIXME in remote_terminal_inferior. */
4869 if (remote_async_terminal_ours_p
)
4871 cleanup_sigint_signal_handler (NULL
);
4872 add_file_handler (input_fd
, stdin_event_handler
, 0);
4873 remote_async_terminal_ours_p
= 1;
4877 remote_console_output (char *msg
)
4881 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4884 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4888 fputs_unfiltered (tb
, gdb_stdtarg
);
4890 gdb_flush (gdb_stdtarg
);
4893 typedef struct cached_reg
4896 gdb_byte data
[MAX_REGISTER_SIZE
];
4899 DEF_VEC_O(cached_reg_t
);
4903 struct stop_reply
*next
;
4907 struct target_waitstatus ws
;
4909 VEC(cached_reg_t
) *regcache
;
4911 int stopped_by_watchpoint_p
;
4912 CORE_ADDR watch_data_address
;
4920 /* The list of already fetched and acknowledged stop events. */
4921 static struct stop_reply
*stop_reply_queue
;
4923 static struct stop_reply
*
4924 stop_reply_xmalloc (void)
4926 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4933 stop_reply_xfree (struct stop_reply
*r
)
4937 VEC_free (cached_reg_t
, r
->regcache
);
4942 /* Discard all pending stop replies of inferior PID. If PID is -1,
4943 discard everything. */
4946 discard_pending_stop_replies (int pid
)
4948 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4950 /* Discard the in-flight notification. */
4951 if (pending_stop_reply
!= NULL
4953 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4955 stop_reply_xfree (pending_stop_reply
);
4956 pending_stop_reply
= NULL
;
4959 /* Discard the stop replies we have already pulled with
4961 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4965 || ptid_get_pid (reply
->ptid
) == pid
)
4967 if (reply
== stop_reply_queue
)
4968 stop_reply_queue
= reply
->next
;
4970 prev
->next
= reply
->next
;
4972 stop_reply_xfree (reply
);
4979 /* Cleanup wrapper. */
4982 do_stop_reply_xfree (void *arg
)
4984 struct stop_reply
*r
= arg
;
4986 stop_reply_xfree (r
);
4989 /* Look for a queued stop reply belonging to PTID. If one is found,
4990 remove it from the queue, and return it. Returns NULL if none is
4991 found. If there are still queued events left to process, tell the
4992 event loop to get back to target_wait soon. */
4994 static struct stop_reply
*
4995 queued_stop_reply (ptid_t ptid
)
4997 struct stop_reply
*it
;
4998 struct stop_reply
**it_link
;
5000 it
= stop_reply_queue
;
5001 it_link
= &stop_reply_queue
;
5004 if (ptid_match (it
->ptid
, ptid
))
5006 *it_link
= it
->next
;
5011 it_link
= &it
->next
;
5015 if (stop_reply_queue
)
5016 /* There's still at least an event left. */
5017 mark_async_event_handler (remote_async_inferior_event_token
);
5022 /* Push a fully parsed stop reply in the stop reply queue. Since we
5023 know that we now have at least one queued event left to pass to the
5024 core side, tell the event loop to get back to target_wait soon. */
5027 push_stop_reply (struct stop_reply
*new_event
)
5029 struct stop_reply
*event
;
5031 if (stop_reply_queue
)
5033 for (event
= stop_reply_queue
;
5034 event
&& event
->next
;
5035 event
= event
->next
)
5038 event
->next
= new_event
;
5041 stop_reply_queue
= new_event
;
5043 mark_async_event_handler (remote_async_inferior_event_token
);
5046 /* Returns true if we have a stop reply for PTID. */
5049 peek_stop_reply (ptid_t ptid
)
5051 struct stop_reply
*it
;
5053 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5054 if (ptid_equal (ptid
, it
->ptid
))
5056 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5063 /* Parse the stop reply in BUF. Either the function succeeds, and the
5064 result is stored in EVENT, or throws an error. */
5067 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5069 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5073 event
->ptid
= null_ptid
;
5074 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5075 event
->ws
.value
.integer
= 0;
5076 event
->solibs_changed
= 0;
5077 event
->replay_event
= 0;
5078 event
->stopped_by_watchpoint_p
= 0;
5079 event
->regcache
= NULL
;
5084 case 'T': /* Status with PC, SP, FP, ... */
5085 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5086 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5088 n... = register number
5089 r... = register contents
5092 p
= &buf
[3]; /* after Txx */
5100 /* If the packet contains a register number, save it in
5101 pnum and set p1 to point to the character following it.
5102 Otherwise p1 points to p. */
5104 /* If this packet is an awatch packet, don't parse the 'a'
5105 as a register number. */
5107 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5108 && strncmp (p
, "core", strlen ("core") != 0))
5110 /* Read the ``P'' register number. */
5111 pnum
= strtol (p
, &p_temp
, 16);
5117 if (p1
== p
) /* No register number present here. */
5119 p1
= strchr (p
, ':');
5121 error (_("Malformed packet(a) (missing colon): %s\n\
5124 if (strncmp (p
, "thread", p1
- p
) == 0)
5125 event
->ptid
= read_ptid (++p1
, &p
);
5126 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5127 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5128 || (strncmp (p
, "awatch", p1
- p
) == 0))
5130 event
->stopped_by_watchpoint_p
= 1;
5131 p
= unpack_varlen_hex (++p1
, &addr
);
5132 event
->watch_data_address
= (CORE_ADDR
) addr
;
5134 else if (strncmp (p
, "library", p1
- p
) == 0)
5138 while (*p_temp
&& *p_temp
!= ';')
5141 event
->solibs_changed
= 1;
5144 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5146 /* NO_HISTORY event.
5147 p1 will indicate "begin" or "end", but
5148 it makes no difference for now, so ignore it. */
5149 event
->replay_event
= 1;
5150 p_temp
= strchr (p1
+ 1, ';');
5154 else if (strncmp (p
, "core", p1
- p
) == 0)
5158 p
= unpack_varlen_hex (++p1
, &c
);
5163 /* Silently skip unknown optional info. */
5164 p_temp
= strchr (p1
+ 1, ';');
5171 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5172 cached_reg_t cached_reg
;
5177 error (_("Malformed packet(b) (missing colon): %s\n\
5183 error (_("Remote sent bad register number %s: %s\n\
5185 hex_string (pnum
), p
, buf
);
5187 cached_reg
.num
= reg
->regnum
;
5189 fieldsize
= hex2bin (p
, cached_reg
.data
,
5190 register_size (target_gdbarch
,
5193 if (fieldsize
< register_size (target_gdbarch
,
5195 warning (_("Remote reply is too short: %s"), buf
);
5197 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5201 error (_("Remote register badly formatted: %s\nhere: %s"),
5206 case 'S': /* Old style status, just signal only. */
5207 if (event
->solibs_changed
)
5208 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5209 else if (event
->replay_event
)
5210 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5213 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5214 event
->ws
.value
.sig
= (enum target_signal
)
5215 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5218 case 'W': /* Target exited. */
5225 /* GDB used to accept only 2 hex chars here. Stubs should
5226 only send more if they detect GDB supports multi-process
5228 p
= unpack_varlen_hex (&buf
[1], &value
);
5232 /* The remote process exited. */
5233 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5234 event
->ws
.value
.integer
= value
;
5238 /* The remote process exited with a signal. */
5239 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5240 event
->ws
.value
.sig
= (enum target_signal
) value
;
5243 /* If no process is specified, assume inferior_ptid. */
5244 pid
= ptid_get_pid (inferior_ptid
);
5253 else if (strncmp (p
,
5254 "process:", sizeof ("process:") - 1) == 0)
5258 p
+= sizeof ("process:") - 1;
5259 unpack_varlen_hex (p
, &upid
);
5263 error (_("unknown stop reply packet: %s"), buf
);
5266 error (_("unknown stop reply packet: %s"), buf
);
5267 event
->ptid
= pid_to_ptid (pid
);
5272 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5273 error (_("No process or thread specified in stop reply: %s"), buf
);
5276 /* When the stub wants to tell GDB about a new stop reply, it sends a
5277 stop notification (%Stop). Those can come it at any time, hence,
5278 we have to make sure that any pending putpkt/getpkt sequence we're
5279 making is finished, before querying the stub for more events with
5280 vStopped. E.g., if we started a vStopped sequence immediatelly
5281 upon receiving the %Stop notification, something like this could
5289 1.6) <-- (registers reply to step #1.3)
5291 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5294 To solve this, whenever we parse a %Stop notification sucessfully,
5295 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5296 doing whatever we were doing:
5302 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5303 2.5) <-- (registers reply to step #2.3)
5305 Eventualy after step #2.5, we return to the event loop, which
5306 notices there's an event on the
5307 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5308 associated callback --- the function below. At this point, we're
5309 always safe to start a vStopped sequence. :
5312 2.7) <-- T05 thread:2
5318 remote_get_pending_stop_replies (void)
5320 struct remote_state
*rs
= get_remote_state ();
5322 if (pending_stop_reply
)
5325 putpkt ("vStopped");
5327 /* Now we can rely on it. */
5328 push_stop_reply (pending_stop_reply
);
5329 pending_stop_reply
= NULL
;
5333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5334 if (strcmp (rs
->buf
, "OK") == 0)
5338 struct cleanup
*old_chain
;
5339 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5341 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5342 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5345 putpkt ("vStopped");
5347 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5349 /* Now we can rely on it. */
5350 discard_cleanups (old_chain
);
5351 push_stop_reply (stop_reply
);
5354 /* We got an unknown stop reply. */
5355 do_cleanups (old_chain
);
5362 /* Called when it is decided that STOP_REPLY holds the info of the
5363 event that is to be returned to the core. This function always
5364 destroys STOP_REPLY. */
5367 process_stop_reply (struct stop_reply
*stop_reply
,
5368 struct target_waitstatus
*status
)
5372 *status
= stop_reply
->ws
;
5373 ptid
= stop_reply
->ptid
;
5375 /* If no thread/process was reported by the stub, assume the current
5377 if (ptid_equal (ptid
, null_ptid
))
5378 ptid
= inferior_ptid
;
5380 if (status
->kind
!= TARGET_WAITKIND_EXITED
5381 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5383 /* Expedited registers. */
5384 if (stop_reply
->regcache
)
5386 struct regcache
*regcache
5387 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5392 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5394 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5395 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5398 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5399 remote_watch_data_address
= stop_reply
->watch_data_address
;
5401 remote_notice_new_inferior (ptid
, 0);
5402 demand_private_info (ptid
)->core
= stop_reply
->core
;
5405 stop_reply_xfree (stop_reply
);
5409 /* The non-stop mode version of target_wait. */
5412 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5414 struct remote_state
*rs
= get_remote_state ();
5415 struct stop_reply
*stop_reply
;
5418 /* If in non-stop mode, get out of getpkt even if a
5419 notification is received. */
5421 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5428 case 'E': /* Error of some sort. */
5429 /* We're out of sync with the target now. Did it continue
5430 or not? We can't tell which thread it was in non-stop,
5431 so just ignore this. */
5432 warning (_("Remote failure reply: %s"), rs
->buf
);
5434 case 'O': /* Console output. */
5435 remote_console_output (rs
->buf
+ 1);
5438 warning (_("Invalid remote reply: %s"), rs
->buf
);
5442 /* Acknowledge a pending stop reply that may have arrived in the
5444 if (pending_stop_reply
!= NULL
)
5445 remote_get_pending_stop_replies ();
5447 /* If indeed we noticed a stop reply, we're done. */
5448 stop_reply
= queued_stop_reply (ptid
);
5449 if (stop_reply
!= NULL
)
5450 return process_stop_reply (stop_reply
, status
);
5452 /* Still no event. If we're just polling for an event, then
5453 return to the event loop. */
5454 if (options
& TARGET_WNOHANG
)
5456 status
->kind
= TARGET_WAITKIND_IGNORE
;
5457 return minus_one_ptid
;
5460 /* Otherwise do a blocking wait. */
5461 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5466 /* Wait until the remote machine stops, then return, storing status in
5467 STATUS just as `wait' would. */
5470 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5472 struct remote_state
*rs
= get_remote_state ();
5473 ptid_t event_ptid
= null_ptid
;
5475 struct stop_reply
*stop_reply
;
5479 status
->kind
= TARGET_WAITKIND_IGNORE
;
5480 status
->value
.integer
= 0;
5482 stop_reply
= queued_stop_reply (ptid
);
5483 if (stop_reply
!= NULL
)
5484 return process_stop_reply (stop_reply
, status
);
5486 if (rs
->cached_wait_status
)
5487 /* Use the cached wait status, but only once. */
5488 rs
->cached_wait_status
= 0;
5493 if (!target_is_async_p ())
5495 ofunc
= signal (SIGINT
, remote_interrupt
);
5496 /* If the user hit C-c before this packet, or between packets,
5497 pretend that it was hit right here. */
5501 remote_interrupt (SIGINT
);
5505 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5506 _never_ wait for ever -> test on target_is_async_p().
5507 However, before we do that we need to ensure that the caller
5508 knows how to take the target into/out of async mode. */
5509 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5510 if (!target_is_async_p ())
5511 signal (SIGINT
, ofunc
);
5516 remote_stopped_by_watchpoint_p
= 0;
5518 /* We got something. */
5519 rs
->waiting_for_stop_reply
= 0;
5521 /* Assume that the target has acknowledged Ctrl-C unless we receive
5522 an 'F' or 'O' packet. */
5523 if (buf
[0] != 'F' && buf
[0] != 'O')
5524 rs
->ctrlc_pending_p
= 0;
5528 case 'E': /* Error of some sort. */
5529 /* We're out of sync with the target now. Did it continue or
5530 not? Not is more likely, so report a stop. */
5531 warning (_("Remote failure reply: %s"), buf
);
5532 status
->kind
= TARGET_WAITKIND_STOPPED
;
5533 status
->value
.sig
= TARGET_SIGNAL_0
;
5535 case 'F': /* File-I/O request. */
5536 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5537 rs
->ctrlc_pending_p
= 0;
5539 case 'T': case 'S': case 'X': case 'W':
5541 struct stop_reply
*stop_reply
;
5542 struct cleanup
*old_chain
;
5544 stop_reply
= stop_reply_xmalloc ();
5545 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5546 remote_parse_stop_reply (buf
, stop_reply
);
5547 discard_cleanups (old_chain
);
5548 event_ptid
= process_stop_reply (stop_reply
, status
);
5551 case 'O': /* Console output. */
5552 remote_console_output (buf
+ 1);
5554 /* The target didn't really stop; keep waiting. */
5555 rs
->waiting_for_stop_reply
= 1;
5559 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5561 /* Zero length reply means that we tried 'S' or 'C' and the
5562 remote system doesn't support it. */
5563 target_terminal_ours_for_output ();
5565 ("Can't send signals to this remote system. %s not sent.\n",
5566 target_signal_to_name (last_sent_signal
));
5567 last_sent_signal
= TARGET_SIGNAL_0
;
5568 target_terminal_inferior ();
5570 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5571 putpkt ((char *) buf
);
5573 /* We just told the target to resume, so a stop reply is in
5575 rs
->waiting_for_stop_reply
= 1;
5578 /* else fallthrough */
5580 warning (_("Invalid remote reply: %s"), buf
);
5582 rs
->waiting_for_stop_reply
= 1;
5586 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5588 /* Nothing interesting happened. If we're doing a non-blocking
5589 poll, we're done. Otherwise, go back to waiting. */
5590 if (options
& TARGET_WNOHANG
)
5591 return minus_one_ptid
;
5595 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5596 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5598 if (!ptid_equal (event_ptid
, null_ptid
))
5599 record_currthread (event_ptid
);
5601 event_ptid
= inferior_ptid
;
5604 /* A process exit. Invalidate our notion of current thread. */
5605 record_currthread (minus_one_ptid
);
5610 /* Wait until the remote machine stops, then return, storing status in
5611 STATUS just as `wait' would. */
5614 remote_wait (struct target_ops
*ops
,
5615 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5620 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5622 event_ptid
= remote_wait_as (ptid
, status
, options
);
5624 if (target_can_async_p ())
5626 /* If there are are events left in the queue tell the event loop
5628 if (stop_reply_queue
)
5629 mark_async_event_handler (remote_async_inferior_event_token
);
5635 /* Fetch a single register using a 'p' packet. */
5638 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5640 struct remote_state
*rs
= get_remote_state ();
5642 char regp
[MAX_REGISTER_SIZE
];
5645 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5648 if (reg
->pnum
== -1)
5653 p
+= hexnumstr (p
, reg
->pnum
);
5656 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5660 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5664 case PACKET_UNKNOWN
:
5667 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5668 gdbarch_register_name (get_regcache_arch (regcache
),
5673 /* If this register is unfetchable, tell the regcache. */
5676 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5680 /* Otherwise, parse and supply the value. */
5686 error (_("fetch_register_using_p: early buf termination"));
5688 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5691 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5695 /* Fetch the registers included in the target's 'g' packet. */
5698 send_g_packet (void)
5700 struct remote_state
*rs
= get_remote_state ();
5703 sprintf (rs
->buf
, "g");
5704 remote_send (&rs
->buf
, &rs
->buf_size
);
5706 /* We can get out of synch in various cases. If the first character
5707 in the buffer is not a hex character, assume that has happened
5708 and try to fetch another packet to read. */
5709 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5710 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5711 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5712 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5715 fprintf_unfiltered (gdb_stdlog
,
5716 "Bad register packet; fetching a new packet\n");
5717 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5720 buf_len
= strlen (rs
->buf
);
5722 /* Sanity check the received packet. */
5723 if (buf_len
% 2 != 0)
5724 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5730 process_g_packet (struct regcache
*regcache
)
5732 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5733 struct remote_state
*rs
= get_remote_state ();
5734 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5739 buf_len
= strlen (rs
->buf
);
5741 /* Further sanity checks, with knowledge of the architecture. */
5742 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5743 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5745 /* Save the size of the packet sent to us by the target. It is used
5746 as a heuristic when determining the max size of packets that the
5747 target can safely receive. */
5748 if (rsa
->actual_register_packet_size
== 0)
5749 rsa
->actual_register_packet_size
= buf_len
;
5751 /* If this is smaller than we guessed the 'g' packet would be,
5752 update our records. A 'g' reply that doesn't include a register's
5753 value implies either that the register is not available, or that
5754 the 'p' packet must be used. */
5755 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5757 rsa
->sizeof_g_packet
= buf_len
/ 2;
5759 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5761 if (rsa
->regs
[i
].pnum
== -1)
5764 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5765 rsa
->regs
[i
].in_g_packet
= 0;
5767 rsa
->regs
[i
].in_g_packet
= 1;
5771 regs
= alloca (rsa
->sizeof_g_packet
);
5773 /* Unimplemented registers read as all bits zero. */
5774 memset (regs
, 0, rsa
->sizeof_g_packet
);
5776 /* Reply describes registers byte by byte, each byte encoded as two
5777 hex characters. Suck them all up, then supply them to the
5778 register cacheing/storage mechanism. */
5781 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5783 if (p
[0] == 0 || p
[1] == 0)
5784 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5785 internal_error (__FILE__
, __LINE__
,
5786 _("unexpected end of 'g' packet reply"));
5788 if (p
[0] == 'x' && p
[1] == 'x')
5789 regs
[i
] = 0; /* 'x' */
5791 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5795 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5797 struct packet_reg
*r
= &rsa
->regs
[i
];
5801 if (r
->offset
* 2 >= strlen (rs
->buf
))
5802 /* This shouldn't happen - we adjusted in_g_packet above. */
5803 internal_error (__FILE__
, __LINE__
,
5804 _("unexpected end of 'g' packet reply"));
5805 else if (rs
->buf
[r
->offset
* 2] == 'x')
5807 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5808 /* The register isn't available, mark it as such (at
5809 the same time setting the value to zero). */
5810 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5813 regcache_raw_supply (regcache
, r
->regnum
,
5820 fetch_registers_using_g (struct regcache
*regcache
)
5823 process_g_packet (regcache
);
5826 /* Make the remote selected traceframe match GDB's selected
5830 set_remote_traceframe (void)
5834 if (remote_traceframe_number
== get_traceframe_number ())
5837 /* Avoid recursion, remote_trace_find calls us again. */
5838 remote_traceframe_number
= get_traceframe_number ();
5840 newnum
= target_trace_find (tfind_number
,
5841 get_traceframe_number (), 0, 0, NULL
);
5843 /* Should not happen. If it does, all bets are off. */
5844 if (newnum
!= get_traceframe_number ())
5845 warning (_("could not set remote traceframe"));
5849 remote_fetch_registers (struct target_ops
*ops
,
5850 struct regcache
*regcache
, int regnum
)
5852 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5855 set_remote_traceframe ();
5856 set_general_thread (inferior_ptid
);
5860 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5862 gdb_assert (reg
!= NULL
);
5864 /* If this register might be in the 'g' packet, try that first -
5865 we are likely to read more than one register. If this is the
5866 first 'g' packet, we might be overly optimistic about its
5867 contents, so fall back to 'p'. */
5868 if (reg
->in_g_packet
)
5870 fetch_registers_using_g (regcache
);
5871 if (reg
->in_g_packet
)
5875 if (fetch_register_using_p (regcache
, reg
))
5878 /* This register is not available. */
5879 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5884 fetch_registers_using_g (regcache
);
5886 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5887 if (!rsa
->regs
[i
].in_g_packet
)
5888 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5890 /* This register is not available. */
5891 regcache_raw_supply (regcache
, i
, NULL
);
5895 /* Prepare to store registers. Since we may send them all (using a
5896 'G' request), we have to read out the ones we don't want to change
5900 remote_prepare_to_store (struct regcache
*regcache
)
5902 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5904 gdb_byte buf
[MAX_REGISTER_SIZE
];
5906 /* Make sure the entire registers array is valid. */
5907 switch (remote_protocol_packets
[PACKET_P
].support
)
5909 case PACKET_DISABLE
:
5910 case PACKET_SUPPORT_UNKNOWN
:
5911 /* Make sure all the necessary registers are cached. */
5912 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5913 if (rsa
->regs
[i
].in_g_packet
)
5914 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5921 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5922 packet was not recognized. */
5925 store_register_using_P (const struct regcache
*regcache
,
5926 struct packet_reg
*reg
)
5928 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5929 struct remote_state
*rs
= get_remote_state ();
5930 /* Try storing a single register. */
5931 char *buf
= rs
->buf
;
5932 gdb_byte regp
[MAX_REGISTER_SIZE
];
5935 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5938 if (reg
->pnum
== -1)
5941 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5942 p
= buf
+ strlen (buf
);
5943 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5944 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5946 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5948 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5953 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5954 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5955 case PACKET_UNKNOWN
:
5958 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5962 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5963 contents of the register cache buffer. FIXME: ignores errors. */
5966 store_registers_using_G (const struct regcache
*regcache
)
5968 struct remote_state
*rs
= get_remote_state ();
5969 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5973 /* Extract all the registers in the regcache copying them into a
5978 regs
= alloca (rsa
->sizeof_g_packet
);
5979 memset (regs
, 0, rsa
->sizeof_g_packet
);
5980 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5982 struct packet_reg
*r
= &rsa
->regs
[i
];
5985 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5989 /* Command describes registers byte by byte,
5990 each byte encoded as two hex characters. */
5993 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5995 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5997 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5998 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5999 error (_("Could not write registers; remote failure reply '%s'"),
6003 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6004 of the register cache buffer. FIXME: ignores errors. */
6007 remote_store_registers (struct target_ops
*ops
,
6008 struct regcache
*regcache
, int regnum
)
6010 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6013 set_remote_traceframe ();
6014 set_general_thread (inferior_ptid
);
6018 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6020 gdb_assert (reg
!= NULL
);
6022 /* Always prefer to store registers using the 'P' packet if
6023 possible; we often change only a small number of registers.
6024 Sometimes we change a larger number; we'd need help from a
6025 higher layer to know to use 'G'. */
6026 if (store_register_using_P (regcache
, reg
))
6029 /* For now, don't complain if we have no way to write the
6030 register. GDB loses track of unavailable registers too
6031 easily. Some day, this may be an error. We don't have
6032 any way to read the register, either... */
6033 if (!reg
->in_g_packet
)
6036 store_registers_using_G (regcache
);
6040 store_registers_using_G (regcache
);
6042 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6043 if (!rsa
->regs
[i
].in_g_packet
)
6044 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6045 /* See above for why we do not issue an error here. */
6050 /* Return the number of hex digits in num. */
6053 hexnumlen (ULONGEST num
)
6057 for (i
= 0; num
!= 0; i
++)
6063 /* Set BUF to the minimum number of hex digits representing NUM. */
6066 hexnumstr (char *buf
, ULONGEST num
)
6068 int len
= hexnumlen (num
);
6070 return hexnumnstr (buf
, num
, len
);
6074 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6077 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6083 for (i
= width
- 1; i
>= 0; i
--)
6085 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6092 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6095 remote_address_masked (CORE_ADDR addr
)
6097 int address_size
= remote_address_size
;
6099 /* If "remoteaddresssize" was not set, default to target address size. */
6101 address_size
= gdbarch_addr_bit (target_gdbarch
);
6103 if (address_size
> 0
6104 && address_size
< (sizeof (ULONGEST
) * 8))
6106 /* Only create a mask when that mask can safely be constructed
6107 in a ULONGEST variable. */
6110 mask
= (mask
<< address_size
) - 1;
6116 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6117 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6118 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6119 (which may be more than *OUT_LEN due to escape characters). The
6120 total number of bytes in the output buffer will be at most
6124 remote_escape_output (const gdb_byte
*buffer
, int len
,
6125 gdb_byte
*out_buf
, int *out_len
,
6128 int input_index
, output_index
;
6131 for (input_index
= 0; input_index
< len
; input_index
++)
6133 gdb_byte b
= buffer
[input_index
];
6135 if (b
== '$' || b
== '#' || b
== '}')
6137 /* These must be escaped. */
6138 if (output_index
+ 2 > out_maxlen
)
6140 out_buf
[output_index
++] = '}';
6141 out_buf
[output_index
++] = b
^ 0x20;
6145 if (output_index
+ 1 > out_maxlen
)
6147 out_buf
[output_index
++] = b
;
6151 *out_len
= input_index
;
6152 return output_index
;
6155 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6156 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6157 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6159 This function reverses remote_escape_output. It allows more
6160 escaped characters than that function does, in particular because
6161 '*' must be escaped to avoid the run-length encoding processing
6162 in reading packets. */
6165 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6166 gdb_byte
*out_buf
, int out_maxlen
)
6168 int input_index
, output_index
;
6173 for (input_index
= 0; input_index
< len
; input_index
++)
6175 gdb_byte b
= buffer
[input_index
];
6177 if (output_index
+ 1 > out_maxlen
)
6179 warning (_("Received too much data from remote target;"
6180 " ignoring overflow."));
6181 return output_index
;
6186 out_buf
[output_index
++] = b
^ 0x20;
6192 out_buf
[output_index
++] = b
;
6196 error (_("Unmatched escape character in target response."));
6198 return output_index
;
6201 /* Determine whether the remote target supports binary downloading.
6202 This is accomplished by sending a no-op memory write of zero length
6203 to the target at the specified address. It does not suffice to send
6204 the whole packet, since many stubs strip the eighth bit and
6205 subsequently compute a wrong checksum, which causes real havoc with
6208 NOTE: This can still lose if the serial line is not eight-bit
6209 clean. In cases like this, the user should clear "remote
6213 check_binary_download (CORE_ADDR addr
)
6215 struct remote_state
*rs
= get_remote_state ();
6217 switch (remote_protocol_packets
[PACKET_X
].support
)
6219 case PACKET_DISABLE
:
6223 case PACKET_SUPPORT_UNKNOWN
:
6229 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6231 p
+= hexnumstr (p
, (ULONGEST
) 0);
6235 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6236 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6238 if (rs
->buf
[0] == '\0')
6241 fprintf_unfiltered (gdb_stdlog
,
6242 "binary downloading NOT "
6243 "supported by target\n");
6244 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6249 fprintf_unfiltered (gdb_stdlog
,
6250 "binary downloading supported by target\n");
6251 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6258 /* Write memory data directly to the remote machine.
6259 This does not inform the data cache; the data cache uses this.
6260 HEADER is the starting part of the packet.
6261 MEMADDR is the address in the remote memory space.
6262 MYADDR is the address of the buffer in our space.
6263 LEN is the number of bytes.
6264 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6265 should send data as binary ('X'), or hex-encoded ('M').
6267 The function creates packet of the form
6268 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6270 where encoding of <DATA> is termined by PACKET_FORMAT.
6272 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6275 Returns the number of bytes transferred, or 0 (setting errno) for
6276 error. Only transfer a single packet. */
6279 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6280 const gdb_byte
*myaddr
, int len
,
6281 char packet_format
, int use_length
)
6283 struct remote_state
*rs
= get_remote_state ();
6293 if (packet_format
!= 'X' && packet_format
!= 'M')
6294 internal_error (__FILE__
, __LINE__
,
6295 _("remote_write_bytes_aux: bad packet format"));
6300 payload_size
= get_memory_write_packet_size ();
6302 /* The packet buffer will be large enough for the payload;
6303 get_memory_packet_size ensures this. */
6306 /* Compute the size of the actual payload by subtracting out the
6307 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6309 payload_size
-= strlen ("$,:#NN");
6311 /* The comma won't be used. */
6313 header_length
= strlen (header
);
6314 payload_size
-= header_length
;
6315 payload_size
-= hexnumlen (memaddr
);
6317 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6319 strcat (rs
->buf
, header
);
6320 p
= rs
->buf
+ strlen (header
);
6322 /* Compute a best guess of the number of bytes actually transfered. */
6323 if (packet_format
== 'X')
6325 /* Best guess at number of bytes that will fit. */
6326 todo
= min (len
, payload_size
);
6328 payload_size
-= hexnumlen (todo
);
6329 todo
= min (todo
, payload_size
);
6333 /* Num bytes that will fit. */
6334 todo
= min (len
, payload_size
/ 2);
6336 payload_size
-= hexnumlen (todo
);
6337 todo
= min (todo
, payload_size
/ 2);
6341 internal_error (__FILE__
, __LINE__
,
6342 _("minumum packet size too small to write data"));
6344 /* If we already need another packet, then try to align the end
6345 of this packet to a useful boundary. */
6346 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6347 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6349 /* Append "<memaddr>". */
6350 memaddr
= remote_address_masked (memaddr
);
6351 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6358 /* Append <len>. Retain the location/size of <len>. It may need to
6359 be adjusted once the packet body has been created. */
6361 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6369 /* Append the packet body. */
6370 if (packet_format
== 'X')
6372 /* Binary mode. Send target system values byte by byte, in
6373 increasing byte addresses. Only escape certain critical
6375 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6378 /* If not all TODO bytes fit, then we'll need another packet. Make
6379 a second try to keep the end of the packet aligned. Don't do
6380 this if the packet is tiny. */
6381 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6385 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6387 if (new_nr_bytes
!= nr_bytes
)
6388 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6393 p
+= payload_length
;
6394 if (use_length
&& nr_bytes
< todo
)
6396 /* Escape chars have filled up the buffer prematurely,
6397 and we have actually sent fewer bytes than planned.
6398 Fix-up the length field of the packet. Use the same
6399 number of characters as before. */
6400 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6401 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6406 /* Normal mode: Send target system values byte by byte, in
6407 increasing byte addresses. Each byte is encoded as a two hex
6409 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6413 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6414 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6416 if (rs
->buf
[0] == 'E')
6418 /* There is no correspondance between what the remote protocol
6419 uses for errors and errno codes. We would like a cleaner way
6420 of representing errors (big enough to include errno codes,
6421 bfd_error codes, and others). But for now just return EIO. */
6426 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6427 fewer bytes than we'd planned. */
6431 /* Write memory data directly to the remote machine.
6432 This does not inform the data cache; the data cache uses this.
6433 MEMADDR is the address in the remote memory space.
6434 MYADDR is the address of the buffer in our space.
6435 LEN is the number of bytes.
6437 Returns number of bytes transferred, or 0 (setting errno) for
6438 error. Only transfer a single packet. */
6441 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6443 char *packet_format
= 0;
6445 /* Check whether the target supports binary download. */
6446 check_binary_download (memaddr
);
6448 switch (remote_protocol_packets
[PACKET_X
].support
)
6451 packet_format
= "X";
6453 case PACKET_DISABLE
:
6454 packet_format
= "M";
6456 case PACKET_SUPPORT_UNKNOWN
:
6457 internal_error (__FILE__
, __LINE__
,
6458 _("remote_write_bytes: bad internal state"));
6460 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6463 return remote_write_bytes_aux (packet_format
,
6464 memaddr
, myaddr
, len
, packet_format
[0], 1);
6467 /* Read memory data directly from the remote machine.
6468 This does not use the data cache; the data cache uses this.
6469 MEMADDR is the address in the remote memory space.
6470 MYADDR is the address of the buffer in our space.
6471 LEN is the number of bytes.
6473 Returns number of bytes transferred, or 0 for error. */
6476 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6478 struct remote_state
*rs
= get_remote_state ();
6479 int max_buf_size
; /* Max size of packet output buffer. */
6487 max_buf_size
= get_memory_read_packet_size ();
6488 /* The packet buffer will be large enough for the payload;
6489 get_memory_packet_size ensures this. */
6491 /* Number if bytes that will fit. */
6492 todo
= min (len
, max_buf_size
/ 2);
6494 /* Construct "m"<memaddr>","<len>". */
6495 memaddr
= remote_address_masked (memaddr
);
6498 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6500 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6503 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6504 if (rs
->buf
[0] == 'E'
6505 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6506 && rs
->buf
[3] == '\0')
6508 /* There is no correspondance between what the remote protocol
6509 uses for errors and errno codes. We would like a cleaner way
6510 of representing errors (big enough to include errno codes,
6511 bfd_error codes, and others). But for now just return
6516 /* Reply describes memory byte by byte, each byte encoded as two hex
6519 i
= hex2bin (p
, myaddr
, todo
);
6520 /* Return what we have. Let higher layers handle partial reads. */
6525 /* Remote notification handler. */
6528 handle_notification (char *buf
, size_t length
)
6530 if (strncmp (buf
, "Stop:", 5) == 0)
6532 if (pending_stop_reply
)
6534 /* We've already parsed the in-flight stop-reply, but the
6535 stub for some reason thought we didn't, possibly due to
6536 timeout on its side. Just ignore it. */
6538 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6542 struct cleanup
*old_chain
;
6543 struct stop_reply
*reply
= stop_reply_xmalloc ();
6545 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6547 remote_parse_stop_reply (buf
+ 5, reply
);
6549 discard_cleanups (old_chain
);
6551 /* Be careful to only set it after parsing, since an error
6552 may be thrown then. */
6553 pending_stop_reply
= reply
;
6555 /* Notify the event loop there's a stop reply to acknowledge
6556 and that there may be more events to fetch. */
6557 mark_async_event_handler (remote_async_get_pending_events_token
);
6560 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6564 /* We ignore notifications we don't recognize, for compatibility
6565 with newer stubs. */
6570 /* Read or write LEN bytes from inferior memory at MEMADDR,
6571 transferring to or from debugger address BUFFER. Write to inferior
6572 if SHOULD_WRITE is nonzero. Returns length of data written or
6573 read; 0 for error. TARGET is unused. */
6576 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6577 int should_write
, struct mem_attrib
*attrib
,
6578 struct target_ops
*target
)
6582 set_remote_traceframe ();
6583 set_general_thread (inferior_ptid
);
6586 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6588 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6593 /* Sends a packet with content determined by the printf format string
6594 FORMAT and the remaining arguments, then gets the reply. Returns
6595 whether the packet was a success, a failure, or unknown. */
6597 static enum packet_result
6598 remote_send_printf (const char *format
, ...)
6600 struct remote_state
*rs
= get_remote_state ();
6601 int max_size
= get_remote_packet_size ();
6604 va_start (ap
, format
);
6607 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6608 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6610 if (putpkt (rs
->buf
) < 0)
6611 error (_("Communication problem with target."));
6614 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6616 return packet_check_result (rs
->buf
);
6620 restore_remote_timeout (void *p
)
6622 int value
= *(int *)p
;
6624 remote_timeout
= value
;
6627 /* Flash writing can take quite some time. We'll set
6628 effectively infinite timeout for flash operations.
6629 In future, we'll need to decide on a better approach. */
6630 static const int remote_flash_timeout
= 1000;
6633 remote_flash_erase (struct target_ops
*ops
,
6634 ULONGEST address
, LONGEST length
)
6636 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6637 int saved_remote_timeout
= remote_timeout
;
6638 enum packet_result ret
;
6639 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6640 &saved_remote_timeout
);
6642 remote_timeout
= remote_flash_timeout
;
6644 ret
= remote_send_printf ("vFlashErase:%s,%s",
6645 phex (address
, addr_size
),
6649 case PACKET_UNKNOWN
:
6650 error (_("Remote target does not support flash erase"));
6652 error (_("Error erasing flash with vFlashErase packet"));
6657 do_cleanups (back_to
);
6661 remote_flash_write (struct target_ops
*ops
,
6662 ULONGEST address
, LONGEST length
,
6663 const gdb_byte
*data
)
6665 int saved_remote_timeout
= remote_timeout
;
6667 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6668 &saved_remote_timeout
);
6670 remote_timeout
= remote_flash_timeout
;
6671 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6672 do_cleanups (back_to
);
6678 remote_flash_done (struct target_ops
*ops
)
6680 int saved_remote_timeout
= remote_timeout
;
6682 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6683 &saved_remote_timeout
);
6685 remote_timeout
= remote_flash_timeout
;
6686 ret
= remote_send_printf ("vFlashDone");
6687 do_cleanups (back_to
);
6691 case PACKET_UNKNOWN
:
6692 error (_("Remote target does not support vFlashDone"));
6694 error (_("Error finishing flash operation"));
6701 remote_files_info (struct target_ops
*ignore
)
6703 puts_filtered ("Debugging a target over a serial line.\n");
6706 /* Stuff for dealing with the packets which are part of this protocol.
6707 See comment at top of file for details. */
6709 /* Read a single character from the remote end. */
6712 readchar (int timeout
)
6716 ch
= serial_readchar (remote_desc
, timeout
);
6721 switch ((enum serial_rc
) ch
)
6725 error (_("Remote connection closed"));
6729 perror_with_name (_("Remote communication error. "
6730 "Target disconnected."));
6732 case SERIAL_TIMEOUT
:
6738 /* Send the command in *BUF to the remote machine, and read the reply
6739 into *BUF. Report an error if we get an error reply. Resize
6740 *BUF using xrealloc if necessary to hold the result, and update
6744 remote_send (char **buf
,
6748 getpkt (buf
, sizeof_buf
, 0);
6750 if ((*buf
)[0] == 'E')
6751 error (_("Remote failure reply: %s"), *buf
);
6754 /* Return a pointer to an xmalloc'ed string representing an escaped
6755 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6756 etc. The caller is responsible for releasing the returned
6760 escape_buffer (const char *buf
, int n
)
6762 struct cleanup
*old_chain
;
6763 struct ui_file
*stb
;
6766 stb
= mem_fileopen ();
6767 old_chain
= make_cleanup_ui_file_delete (stb
);
6769 fputstrn_unfiltered (buf
, n
, 0, stb
);
6770 str
= ui_file_xstrdup (stb
, NULL
);
6771 do_cleanups (old_chain
);
6775 /* Display a null-terminated packet on stdout, for debugging, using C
6779 print_packet (char *buf
)
6781 puts_filtered ("\"");
6782 fputstr_filtered (buf
, '"', gdb_stdout
);
6783 puts_filtered ("\"");
6789 return putpkt_binary (buf
, strlen (buf
));
6792 /* Send a packet to the remote machine, with error checking. The data
6793 of the packet is in BUF. The string in BUF can be at most
6794 get_remote_packet_size () - 5 to account for the $, # and checksum,
6795 and for a possible /0 if we are debugging (remote_debug) and want
6796 to print the sent packet as a string. */
6799 putpkt_binary (char *buf
, int cnt
)
6801 struct remote_state
*rs
= get_remote_state ();
6803 unsigned char csum
= 0;
6804 char *buf2
= alloca (cnt
+ 6);
6810 /* Catch cases like trying to read memory or listing threads while
6811 we're waiting for a stop reply. The remote server wouldn't be
6812 ready to handle this request, so we'd hang and timeout. We don't
6813 have to worry about this in synchronous mode, because in that
6814 case it's not possible to issue a command while the target is
6815 running. This is not a problem in non-stop mode, because in that
6816 case, the stub is always ready to process serial input. */
6817 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6818 error (_("Cannot execute this command while the target is running."));
6820 /* We're sending out a new packet. Make sure we don't look at a
6821 stale cached response. */
6822 rs
->cached_wait_status
= 0;
6824 /* Copy the packet into buffer BUF2, encapsulating it
6825 and giving it a checksum. */
6830 for (i
= 0; i
< cnt
; i
++)
6836 *p
++ = tohex ((csum
>> 4) & 0xf);
6837 *p
++ = tohex (csum
& 0xf);
6839 /* Send it over and over until we get a positive ack. */
6843 int started_error_output
= 0;
6847 struct cleanup
*old_chain
;
6851 str
= escape_buffer (buf2
, p
- buf2
);
6852 old_chain
= make_cleanup (xfree
, str
);
6853 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6854 gdb_flush (gdb_stdlog
);
6855 do_cleanups (old_chain
);
6857 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6858 perror_with_name (_("putpkt: write failed"));
6860 /* If this is a no acks version of the remote protocol, send the
6861 packet and move on. */
6865 /* Read until either a timeout occurs (-2) or '+' is read.
6866 Handle any notification that arrives in the mean time. */
6869 ch
= readchar (remote_timeout
);
6877 case SERIAL_TIMEOUT
:
6880 if (started_error_output
)
6882 putchar_unfiltered ('\n');
6883 started_error_output
= 0;
6892 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6896 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6898 case SERIAL_TIMEOUT
:
6902 break; /* Retransmit buffer. */
6906 fprintf_unfiltered (gdb_stdlog
,
6907 "Packet instead of Ack, ignoring it\n");
6908 /* It's probably an old response sent because an ACK
6909 was lost. Gobble up the packet and ack it so it
6910 doesn't get retransmitted when we resend this
6913 serial_write (remote_desc
, "+", 1);
6914 continue; /* Now, go look for +. */
6921 /* If we got a notification, handle it, and go back to looking
6923 /* We've found the start of a notification. Now
6924 collect the data. */
6925 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6930 struct cleanup
*old_chain
;
6933 str
= escape_buffer (rs
->buf
, val
);
6934 old_chain
= make_cleanup (xfree
, str
);
6935 fprintf_unfiltered (gdb_stdlog
,
6936 " Notification received: %s\n",
6938 do_cleanups (old_chain
);
6940 handle_notification (rs
->buf
, val
);
6941 /* We're in sync now, rewait for the ack. */
6948 if (!started_error_output
)
6950 started_error_output
= 1;
6951 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6953 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6954 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6963 if (!started_error_output
)
6965 started_error_output
= 1;
6966 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6968 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6972 break; /* Here to retransmit. */
6976 /* This is wrong. If doing a long backtrace, the user should be
6977 able to get out next time we call QUIT, without anything as
6978 violent as interrupt_query. If we want to provide a way out of
6979 here without getting to the next QUIT, it should be based on
6980 hitting ^C twice as in remote_wait. */
6991 /* Come here after finding the start of a frame when we expected an
6992 ack. Do our best to discard the rest of this packet. */
7001 c
= readchar (remote_timeout
);
7004 case SERIAL_TIMEOUT
:
7005 /* Nothing we can do. */
7008 /* Discard the two bytes of checksum and stop. */
7009 c
= readchar (remote_timeout
);
7011 c
= readchar (remote_timeout
);
7014 case '*': /* Run length encoding. */
7015 /* Discard the repeat count. */
7016 c
= readchar (remote_timeout
);
7021 /* A regular character. */
7027 /* Come here after finding the start of the frame. Collect the rest
7028 into *BUF, verifying the checksum, length, and handling run-length
7029 compression. NUL terminate the buffer. If there is not enough room,
7030 expand *BUF using xrealloc.
7032 Returns -1 on error, number of characters in buffer (ignoring the
7033 trailing NULL) on success. (could be extended to return one of the
7034 SERIAL status indications). */
7037 read_frame (char **buf_p
,
7044 struct remote_state
*rs
= get_remote_state ();
7051 c
= readchar (remote_timeout
);
7054 case SERIAL_TIMEOUT
:
7056 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7060 fputs_filtered ("Saw new packet start in middle of old one\n",
7062 return -1; /* Start a new packet, count retries. */
7065 unsigned char pktcsum
;
7071 check_0
= readchar (remote_timeout
);
7073 check_1
= readchar (remote_timeout
);
7075 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7078 fputs_filtered ("Timeout in checksum, retrying\n",
7082 else if (check_0
< 0 || check_1
< 0)
7085 fputs_filtered ("Communication error in checksum\n",
7090 /* Don't recompute the checksum; with no ack packets we
7091 don't have any way to indicate a packet retransmission
7096 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7097 if (csum
== pktcsum
)
7102 struct cleanup
*old_chain
;
7105 str
= escape_buffer (buf
, bc
);
7106 old_chain
= make_cleanup (xfree
, str
);
7107 fprintf_unfiltered (gdb_stdlog
,
7108 "Bad checksum, sentsum=0x%x, "
7109 "csum=0x%x, buf=%s\n",
7110 pktcsum
, csum
, str
);
7111 do_cleanups (old_chain
);
7113 /* Number of characters in buffer ignoring trailing
7117 case '*': /* Run length encoding. */
7122 c
= readchar (remote_timeout
);
7124 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7126 /* The character before ``*'' is repeated. */
7128 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7130 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7132 /* Make some more room in the buffer. */
7133 *sizeof_buf
+= repeat
;
7134 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7138 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7144 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7148 if (bc
>= *sizeof_buf
- 1)
7150 /* Make some more room in the buffer. */
7152 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7163 /* Read a packet from the remote machine, with error checking, and
7164 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7165 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7166 rather than timing out; this is used (in synchronous mode) to wait
7167 for a target that is is executing user code to stop. */
7168 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7169 don't have to change all the calls to getpkt to deal with the
7170 return value, because at the moment I don't know what the right
7171 thing to do it for those. */
7179 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7183 /* Read a packet from the remote machine, with error checking, and
7184 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7185 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7186 rather than timing out; this is used (in synchronous mode) to wait
7187 for a target that is is executing user code to stop. If FOREVER ==
7188 0, this function is allowed to time out gracefully and return an
7189 indication of this to the caller. Otherwise return the number of
7190 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7191 enough reason to return to the caller. */
7194 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7195 int expecting_notif
)
7197 struct remote_state
*rs
= get_remote_state ();
7203 /* We're reading a new response. Make sure we don't look at a
7204 previously cached response. */
7205 rs
->cached_wait_status
= 0;
7207 strcpy (*buf
, "timeout");
7210 timeout
= watchdog
> 0 ? watchdog
: -1;
7211 else if (expecting_notif
)
7212 timeout
= 0; /* There should already be a char in the buffer. If
7215 timeout
= remote_timeout
;
7219 /* Process any number of notifications, and then return when
7223 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7225 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7227 /* This can loop forever if the remote side sends us
7228 characters continuously, but if it pauses, we'll get
7229 SERIAL_TIMEOUT from readchar because of timeout. Then
7230 we'll count that as a retry.
7232 Note that even when forever is set, we will only wait
7233 forever prior to the start of a packet. After that, we
7234 expect characters to arrive at a brisk pace. They should
7235 show up within remote_timeout intervals. */
7237 c
= readchar (timeout
);
7238 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7240 if (c
== SERIAL_TIMEOUT
)
7242 if (expecting_notif
)
7243 return -1; /* Don't complain, it's normal to not get
7244 anything in this case. */
7246 if (forever
) /* Watchdog went off? Kill the target. */
7250 error (_("Watchdog timeout has expired. Target detached."));
7253 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7257 /* We've found the start of a packet or notification.
7258 Now collect the data. */
7259 val
= read_frame (buf
, sizeof_buf
);
7264 serial_write (remote_desc
, "-", 1);
7267 if (tries
> MAX_TRIES
)
7269 /* We have tried hard enough, and just can't receive the
7270 packet/notification. Give up. */
7271 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7273 /* Skip the ack char if we're in no-ack mode. */
7274 if (!rs
->noack_mode
)
7275 serial_write (remote_desc
, "+", 1);
7279 /* If we got an ordinary packet, return that to our caller. */
7284 struct cleanup
*old_chain
;
7287 str
= escape_buffer (*buf
, val
);
7288 old_chain
= make_cleanup (xfree
, str
);
7289 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7290 do_cleanups (old_chain
);
7293 /* Skip the ack char if we're in no-ack mode. */
7294 if (!rs
->noack_mode
)
7295 serial_write (remote_desc
, "+", 1);
7299 /* If we got a notification, handle it, and go back to looking
7303 gdb_assert (c
== '%');
7307 struct cleanup
*old_chain
;
7310 str
= escape_buffer (*buf
, val
);
7311 old_chain
= make_cleanup (xfree
, str
);
7312 fprintf_unfiltered (gdb_stdlog
,
7313 " Notification received: %s\n",
7315 do_cleanups (old_chain
);
7318 handle_notification (*buf
, val
);
7320 /* Notifications require no acknowledgement. */
7322 if (expecting_notif
)
7329 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7331 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7335 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7337 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7342 remote_kill (struct target_ops
*ops
)
7344 /* Use catch_errors so the user can quit from gdb even when we
7345 aren't on speaking terms with the remote system. */
7346 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
7348 /* Don't wait for it to die. I'm not really sure it matters whether
7349 we do or not. For the existing stubs, kill is a noop. */
7350 target_mourn_inferior ();
7354 remote_vkill (int pid
, struct remote_state
*rs
)
7356 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7359 /* Tell the remote target to detach. */
7360 sprintf (rs
->buf
, "vKill;%x", pid
);
7362 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7364 if (packet_ok (rs
->buf
,
7365 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7367 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7374 extended_remote_kill (struct target_ops
*ops
)
7377 int pid
= ptid_get_pid (inferior_ptid
);
7378 struct remote_state
*rs
= get_remote_state ();
7380 res
= remote_vkill (pid
, rs
);
7381 if (res
== -1 && !remote_multi_process_p (rs
))
7383 /* Don't try 'k' on a multi-process aware stub -- it has no way
7384 to specify the pid. */
7388 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7389 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7392 /* Don't wait for it to die. I'm not really sure it matters whether
7393 we do or not. For the existing stubs, kill is a noop. */
7399 error (_("Can't kill process"));
7401 target_mourn_inferior ();
7405 remote_mourn (struct target_ops
*ops
)
7407 remote_mourn_1 (ops
);
7410 /* Worker function for remote_mourn. */
7412 remote_mourn_1 (struct target_ops
*target
)
7414 unpush_target (target
);
7416 /* remote_close takes care of doing most of the clean up. */
7417 generic_mourn_inferior ();
7421 extended_remote_mourn_1 (struct target_ops
*target
)
7423 struct remote_state
*rs
= get_remote_state ();
7425 /* In case we got here due to an error, but we're going to stay
7427 rs
->waiting_for_stop_reply
= 0;
7429 /* We're no longer interested in these events. */
7430 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7432 /* If the current general thread belonged to the process we just
7433 detached from or has exited, the remote side current general
7434 thread becomes undefined. Considering a case like this:
7436 - We just got here due to a detach.
7437 - The process that we're detaching from happens to immediately
7438 report a global breakpoint being hit in non-stop mode, in the
7439 same thread we had selected before.
7440 - GDB attaches to this process again.
7441 - This event happens to be the next event we handle.
7443 GDB would consider that the current general thread didn't need to
7444 be set on the stub side (with Hg), since for all it knew,
7445 GENERAL_THREAD hadn't changed.
7447 Notice that although in all-stop mode, the remote server always
7448 sets the current thread to the thread reporting the stop event,
7449 that doesn't happen in non-stop mode; in non-stop, the stub *must
7450 not* change the current thread when reporting a breakpoint hit,
7451 due to the decoupling of event reporting and event handling.
7453 To keep things simple, we always invalidate our notion of the
7455 record_currthread (minus_one_ptid
);
7457 /* Unlike "target remote", we do not want to unpush the target; then
7458 the next time the user says "run", we won't be connected. */
7460 /* Call common code to mark the inferior as not running. */
7461 generic_mourn_inferior ();
7463 if (!have_inferiors ())
7465 if (!remote_multi_process_p (rs
))
7467 /* Check whether the target is running now - some remote stubs
7468 automatically restart after kill. */
7470 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7472 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7474 /* Assume that the target has been restarted. Set
7475 inferior_ptid so that bits of core GDB realizes
7476 there's something here, e.g., so that the user can
7477 say "kill" again. */
7478 inferior_ptid
= magic_null_ptid
;
7485 extended_remote_mourn (struct target_ops
*ops
)
7487 extended_remote_mourn_1 (ops
);
7491 extended_remote_run (char *args
)
7493 struct remote_state
*rs
= get_remote_state ();
7496 /* If the user has disabled vRun support, or we have detected that
7497 support is not available, do not try it. */
7498 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7501 strcpy (rs
->buf
, "vRun;");
7502 len
= strlen (rs
->buf
);
7504 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7505 error (_("Remote file name too long for run packet"));
7506 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7508 gdb_assert (args
!= NULL
);
7511 struct cleanup
*back_to
;
7515 argv
= gdb_buildargv (args
);
7516 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7517 for (i
= 0; argv
[i
] != NULL
; i
++)
7519 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7520 error (_("Argument list too long for run packet"));
7521 rs
->buf
[len
++] = ';';
7522 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7524 do_cleanups (back_to
);
7527 rs
->buf
[len
++] = '\0';
7530 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7532 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7534 /* We have a wait response; we don't need it, though. All is well. */
7537 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7538 /* It wasn't disabled before, but it is now. */
7542 if (remote_exec_file
[0] == '\0')
7543 error (_("Running the default executable on the remote target failed; "
7544 "try \"set remote exec-file\"?"));
7546 error (_("Running \"%s\" on the remote target failed"),
7551 /* In the extended protocol we want to be able to do things like
7552 "run" and have them basically work as expected. So we need
7553 a special create_inferior function. We support changing the
7554 executable file and the command line arguments, but not the
7558 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7559 char **env
, int from_tty
)
7561 /* If running asynchronously, register the target file descriptor
7562 with the event loop. */
7563 if (target_can_async_p ())
7564 target_async (inferior_event_handler
, 0);
7566 /* Now restart the remote server. */
7567 if (extended_remote_run (args
) == -1)
7569 /* vRun was not supported. Fail if we need it to do what the
7571 if (remote_exec_file
[0])
7572 error (_("Remote target does not support \"set remote exec-file\""));
7574 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7576 /* Fall back to "R". */
7577 extended_remote_restart ();
7580 if (!have_inferiors ())
7582 /* Clean up from the last time we ran, before we mark the target
7583 running again. This will mark breakpoints uninserted, and
7584 get_offsets may insert breakpoints. */
7585 init_thread_list ();
7586 init_wait_for_inferior ();
7589 /* Now mark the inferior as running before we do anything else. */
7590 inferior_ptid
= magic_null_ptid
;
7592 /* Now, if we have thread information, update inferior_ptid. */
7593 inferior_ptid
= remote_current_thread (inferior_ptid
);
7595 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7596 add_thread_silent (inferior_ptid
);
7598 /* Get updated offsets, if the stub uses qOffsets. */
7603 extended_remote_create_inferior (struct target_ops
*ops
,
7604 char *exec_file
, char *args
,
7605 char **env
, int from_tty
)
7607 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7611 /* Insert a breakpoint. On targets that have software breakpoint
7612 support, we ask the remote target to do the work; on targets
7613 which don't, we insert a traditional memory breakpoint. */
7616 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7617 struct bp_target_info
*bp_tgt
)
7619 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7620 If it succeeds, then set the support to PACKET_ENABLE. If it
7621 fails, and the user has explicitly requested the Z support then
7622 report an error, otherwise, mark it disabled and go on. */
7624 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7626 CORE_ADDR addr
= bp_tgt
->placed_address
;
7627 struct remote_state
*rs
;
7631 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7633 rs
= get_remote_state ();
7639 addr
= (ULONGEST
) remote_address_masked (addr
);
7640 p
+= hexnumstr (p
, addr
);
7641 sprintf (p
, ",%d", bpsize
);
7644 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7646 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7651 bp_tgt
->placed_address
= addr
;
7652 bp_tgt
->placed_size
= bpsize
;
7654 case PACKET_UNKNOWN
:
7659 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7663 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7664 struct bp_target_info
*bp_tgt
)
7666 CORE_ADDR addr
= bp_tgt
->placed_address
;
7667 struct remote_state
*rs
= get_remote_state ();
7669 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7677 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7678 p
+= hexnumstr (p
, addr
);
7679 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7682 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7684 return (rs
->buf
[0] == 'E');
7687 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7691 watchpoint_to_Z_packet (int type
)
7696 return Z_PACKET_WRITE_WP
;
7699 return Z_PACKET_READ_WP
;
7702 return Z_PACKET_ACCESS_WP
;
7705 internal_error (__FILE__
, __LINE__
,
7706 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7711 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
7712 struct expression
*cond
)
7714 struct remote_state
*rs
= get_remote_state ();
7716 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7718 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7721 sprintf (rs
->buf
, "Z%x,", packet
);
7722 p
= strchr (rs
->buf
, '\0');
7723 addr
= remote_address_masked (addr
);
7724 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7725 sprintf (p
, ",%x", len
);
7728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7730 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7734 case PACKET_UNKNOWN
:
7739 internal_error (__FILE__
, __LINE__
,
7740 _("remote_insert_watchpoint: reached end of function"));
7745 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
7746 struct expression
*cond
)
7748 struct remote_state
*rs
= get_remote_state ();
7750 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7752 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7755 sprintf (rs
->buf
, "z%x,", packet
);
7756 p
= strchr (rs
->buf
, '\0');
7757 addr
= remote_address_masked (addr
);
7758 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7759 sprintf (p
, ",%x", len
);
7761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7763 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7766 case PACKET_UNKNOWN
:
7771 internal_error (__FILE__
, __LINE__
,
7772 _("remote_remove_watchpoint: reached end of function"));
7776 int remote_hw_watchpoint_limit
= -1;
7777 int remote_hw_breakpoint_limit
= -1;
7780 remote_check_watch_resources (int type
, int cnt
, int ot
)
7782 if (type
== bp_hardware_breakpoint
)
7784 if (remote_hw_breakpoint_limit
== 0)
7786 else if (remote_hw_breakpoint_limit
< 0)
7788 else if (cnt
<= remote_hw_breakpoint_limit
)
7793 if (remote_hw_watchpoint_limit
== 0)
7795 else if (remote_hw_watchpoint_limit
< 0)
7799 else if (cnt
<= remote_hw_watchpoint_limit
)
7806 remote_stopped_by_watchpoint (void)
7808 return remote_stopped_by_watchpoint_p
;
7812 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7816 if (remote_stopped_by_watchpoint ())
7818 *addr_p
= remote_watch_data_address
;
7827 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7828 struct bp_target_info
*bp_tgt
)
7831 struct remote_state
*rs
;
7834 /* The length field should be set to the size of a breakpoint
7835 instruction, even though we aren't inserting one ourselves. */
7837 gdbarch_remote_breakpoint_from_pc
7838 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7840 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7843 rs
= get_remote_state ();
7850 addr
= remote_address_masked (bp_tgt
->placed_address
);
7851 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7852 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7855 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7857 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7860 case PACKET_UNKNOWN
:
7865 internal_error (__FILE__
, __LINE__
,
7866 _("remote_insert_hw_breakpoint: reached end of function"));
7871 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7872 struct bp_target_info
*bp_tgt
)
7875 struct remote_state
*rs
= get_remote_state ();
7878 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7885 addr
= remote_address_masked (bp_tgt
->placed_address
);
7886 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7887 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7890 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7892 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7895 case PACKET_UNKNOWN
:
7900 internal_error (__FILE__
, __LINE__
,
7901 _("remote_remove_hw_breakpoint: reached end of function"));
7904 /* Table used by the crc32 function to calcuate the checksum. */
7906 static unsigned long crc32_table
[256] =
7909 static unsigned long
7910 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
7912 if (!crc32_table
[1])
7914 /* Initialize the CRC table and the decoding table. */
7918 for (i
= 0; i
< 256; i
++)
7920 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7921 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7928 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7934 /* Verify memory using the "qCRC:" request. */
7937 remote_verify_memory (struct target_ops
*ops
,
7938 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
7940 struct remote_state
*rs
= get_remote_state ();
7941 unsigned long host_crc
, target_crc
;
7944 /* FIXME: assumes lma can fit into long. */
7945 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7946 (long) lma
, (long) size
);
7949 /* Be clever; compute the host_crc before waiting for target
7951 host_crc
= crc32 (data
, size
, 0xffffffff);
7953 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7954 if (rs
->buf
[0] == 'E')
7957 if (rs
->buf
[0] != 'C')
7958 error (_("remote target does not support this operation"));
7960 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7961 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7963 return (host_crc
== target_crc
);
7966 /* compare-sections command
7968 With no arguments, compares each loadable section in the exec bfd
7969 with the same memory range on the target, and reports mismatches.
7970 Useful for verifying the image on the target against the exec file. */
7973 compare_sections_command (char *args
, int from_tty
)
7976 struct cleanup
*old_chain
;
7978 const char *sectname
;
7986 error (_("command cannot be used without an exec file"));
7988 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7990 if (!(s
->flags
& SEC_LOAD
))
7991 continue; /* Skip non-loadable section. */
7993 size
= bfd_get_section_size (s
);
7995 continue; /* Skip zero-length section. */
7997 sectname
= bfd_get_section_name (exec_bfd
, s
);
7998 if (args
&& strcmp (args
, sectname
) != 0)
7999 continue; /* Not the section selected by user. */
8001 matched
= 1; /* Do this section. */
8004 sectdata
= xmalloc (size
);
8005 old_chain
= make_cleanup (xfree
, sectdata
);
8006 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8008 res
= target_verify_memory (sectdata
, lma
, size
);
8011 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8012 paddress (target_gdbarch
, lma
),
8013 paddress (target_gdbarch
, lma
+ size
));
8015 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8016 paddress (target_gdbarch
, lma
),
8017 paddress (target_gdbarch
, lma
+ size
));
8019 printf_filtered ("matched.\n");
8022 printf_filtered ("MIS-MATCHED!\n");
8026 do_cleanups (old_chain
);
8029 warning (_("One or more sections of the remote executable does not match\n\
8030 the loaded file\n"));
8031 if (args
&& !matched
)
8032 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8035 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8036 into remote target. The number of bytes written to the remote
8037 target is returned, or -1 for error. */
8040 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8041 const char *annex
, const gdb_byte
*writebuf
,
8042 ULONGEST offset
, LONGEST len
,
8043 struct packet_config
*packet
)
8047 struct remote_state
*rs
= get_remote_state ();
8048 int max_size
= get_memory_write_packet_size ();
8050 if (packet
->support
== PACKET_DISABLE
)
8053 /* Insert header. */
8054 i
= snprintf (rs
->buf
, max_size
,
8055 "qXfer:%s:write:%s:%s:",
8056 object_name
, annex
? annex
: "",
8057 phex_nz (offset
, sizeof offset
));
8058 max_size
-= (i
+ 1);
8060 /* Escape as much data as fits into rs->buf. */
8061 buf_len
= remote_escape_output
8062 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8064 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8065 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8066 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8069 unpack_varlen_hex (rs
->buf
, &n
);
8073 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8074 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8075 number of bytes read is returned, or 0 for EOF, or -1 for error.
8076 The number of bytes read may be less than LEN without indicating an
8077 EOF. PACKET is checked and updated to indicate whether the remote
8078 target supports this object. */
8081 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8083 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8084 struct packet_config
*packet
)
8086 static char *finished_object
;
8087 static char *finished_annex
;
8088 static ULONGEST finished_offset
;
8090 struct remote_state
*rs
= get_remote_state ();
8091 LONGEST i
, n
, packet_len
;
8093 if (packet
->support
== PACKET_DISABLE
)
8096 /* Check whether we've cached an end-of-object packet that matches
8098 if (finished_object
)
8100 if (strcmp (object_name
, finished_object
) == 0
8101 && strcmp (annex
? annex
: "", finished_annex
) == 0
8102 && offset
== finished_offset
)
8105 /* Otherwise, we're now reading something different. Discard
8107 xfree (finished_object
);
8108 xfree (finished_annex
);
8109 finished_object
= NULL
;
8110 finished_annex
= NULL
;
8113 /* Request only enough to fit in a single packet. The actual data
8114 may not, since we don't know how much of it will need to be escaped;
8115 the target is free to respond with slightly less data. We subtract
8116 five to account for the response type and the protocol frame. */
8117 n
= min (get_remote_packet_size () - 5, len
);
8118 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8119 object_name
, annex
? annex
: "",
8120 phex_nz (offset
, sizeof offset
),
8121 phex_nz (n
, sizeof n
));
8122 i
= putpkt (rs
->buf
);
8127 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8128 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8131 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8132 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8134 /* 'm' means there is (or at least might be) more data after this
8135 batch. That does not make sense unless there's at least one byte
8136 of data in this reply. */
8137 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8138 error (_("Remote qXfer reply contained no data."));
8140 /* Got some data. */
8141 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8143 /* 'l' is an EOF marker, possibly including a final block of data,
8144 or possibly empty. If we have the final block of a non-empty
8145 object, record this fact to bypass a subsequent partial read. */
8146 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8148 finished_object
= xstrdup (object_name
);
8149 finished_annex
= xstrdup (annex
? annex
: "");
8150 finished_offset
= offset
+ i
;
8157 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8158 const char *annex
, gdb_byte
*readbuf
,
8159 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8161 struct remote_state
*rs
;
8166 set_remote_traceframe ();
8167 set_general_thread (inferior_ptid
);
8169 rs
= get_remote_state ();
8171 /* Handle memory using the standard memory routines. */
8172 if (object
== TARGET_OBJECT_MEMORY
)
8178 /* If the remote target is connected but not running, we should
8179 pass this request down to a lower stratum (e.g. the executable
8181 if (!target_has_execution
)
8184 if (writebuf
!= NULL
)
8185 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8187 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8191 else if (xfered
== 0 && errno
== 0)
8197 /* Handle SPU memory using qxfer packets. */
8198 if (object
== TARGET_OBJECT_SPU
)
8201 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8202 &remote_protocol_packets
8203 [PACKET_qXfer_spu_read
]);
8205 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8206 &remote_protocol_packets
8207 [PACKET_qXfer_spu_write
]);
8210 /* Handle extra signal info using qxfer packets. */
8211 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8214 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8215 &remote_protocol_packets
8216 [PACKET_qXfer_siginfo_read
]);
8218 return remote_write_qxfer (ops
, "siginfo", annex
,
8219 writebuf
, offset
, len
,
8220 &remote_protocol_packets
8221 [PACKET_qXfer_siginfo_write
]);
8224 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8227 return remote_read_qxfer (ops
, "statictrace", annex
,
8228 readbuf
, offset
, len
,
8229 &remote_protocol_packets
8230 [PACKET_qXfer_statictrace_read
]);
8235 /* Only handle flash writes. */
8236 if (writebuf
!= NULL
)
8242 case TARGET_OBJECT_FLASH
:
8243 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8247 else if (xfered
== 0 && errno
== 0)
8257 /* Map pre-existing objects onto letters. DO NOT do this for new
8258 objects!!! Instead specify new query packets. */
8261 case TARGET_OBJECT_AVR
:
8265 case TARGET_OBJECT_AUXV
:
8266 gdb_assert (annex
== NULL
);
8267 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8268 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8270 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8271 return remote_read_qxfer
8272 (ops
, "features", annex
, readbuf
, offset
, len
,
8273 &remote_protocol_packets
[PACKET_qXfer_features
]);
8275 case TARGET_OBJECT_LIBRARIES
:
8276 return remote_read_qxfer
8277 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8278 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8280 case TARGET_OBJECT_MEMORY_MAP
:
8281 gdb_assert (annex
== NULL
);
8282 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8283 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8285 case TARGET_OBJECT_OSDATA
:
8286 /* Should only get here if we're connected. */
8287 gdb_assert (remote_desc
);
8288 return remote_read_qxfer
8289 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8290 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8292 case TARGET_OBJECT_THREADS
:
8293 gdb_assert (annex
== NULL
);
8294 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8295 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8297 case TARGET_OBJECT_TRACEFRAME_INFO
:
8298 gdb_assert (annex
== NULL
);
8299 return remote_read_qxfer
8300 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8301 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8306 /* Note: a zero OFFSET and LEN can be used to query the minimum
8308 if (offset
== 0 && len
== 0)
8309 return (get_remote_packet_size ());
8310 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8311 large enough let the caller deal with it. */
8312 if (len
< get_remote_packet_size ())
8314 len
= get_remote_packet_size ();
8316 /* Except for querying the minimum buffer size, target must be open. */
8318 error (_("remote query is only available after target open"));
8320 gdb_assert (annex
!= NULL
);
8321 gdb_assert (readbuf
!= NULL
);
8327 /* We used one buffer char for the remote protocol q command and
8328 another for the query type. As the remote protocol encapsulation
8329 uses 4 chars plus one extra in case we are debugging
8330 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8333 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8335 /* Bad caller may have sent forbidden characters. */
8336 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8341 gdb_assert (annex
[i
] == '\0');
8343 i
= putpkt (rs
->buf
);
8347 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8348 strcpy ((char *) readbuf
, rs
->buf
);
8350 return strlen ((char *) readbuf
);
8354 remote_search_memory (struct target_ops
* ops
,
8355 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8356 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8357 CORE_ADDR
*found_addrp
)
8359 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8360 struct remote_state
*rs
= get_remote_state ();
8361 int max_size
= get_memory_write_packet_size ();
8362 struct packet_config
*packet
=
8363 &remote_protocol_packets
[PACKET_qSearch_memory
];
8364 /* Number of packet bytes used to encode the pattern;
8365 this could be more than PATTERN_LEN due to escape characters. */
8366 int escaped_pattern_len
;
8367 /* Amount of pattern that was encodable in the packet. */
8368 int used_pattern_len
;
8371 ULONGEST found_addr
;
8373 /* Don't go to the target if we don't have to.
8374 This is done before checking packet->support to avoid the possibility that
8375 a success for this edge case means the facility works in general. */
8376 if (pattern_len
> search_space_len
)
8378 if (pattern_len
== 0)
8380 *found_addrp
= start_addr
;
8384 /* If we already know the packet isn't supported, fall back to the simple
8385 way of searching memory. */
8387 if (packet
->support
== PACKET_DISABLE
)
8389 /* Target doesn't provided special support, fall back and use the
8390 standard support (copy memory and do the search here). */
8391 return simple_search_memory (ops
, start_addr
, search_space_len
,
8392 pattern
, pattern_len
, found_addrp
);
8395 /* Insert header. */
8396 i
= snprintf (rs
->buf
, max_size
,
8397 "qSearch:memory:%s;%s;",
8398 phex_nz (start_addr
, addr_size
),
8399 phex_nz (search_space_len
, sizeof (search_space_len
)));
8400 max_size
-= (i
+ 1);
8402 /* Escape as much data as fits into rs->buf. */
8403 escaped_pattern_len
=
8404 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8405 &used_pattern_len
, max_size
);
8407 /* Bail if the pattern is too large. */
8408 if (used_pattern_len
!= pattern_len
)
8409 error (_("Pattern is too large to transmit to remote target."));
8411 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8412 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8413 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8415 /* The request may not have worked because the command is not
8416 supported. If so, fall back to the simple way. */
8417 if (packet
->support
== PACKET_DISABLE
)
8419 return simple_search_memory (ops
, start_addr
, search_space_len
,
8420 pattern
, pattern_len
, found_addrp
);
8425 if (rs
->buf
[0] == '0')
8427 else if (rs
->buf
[0] == '1')
8430 if (rs
->buf
[1] != ',')
8431 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8432 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8433 *found_addrp
= found_addr
;
8436 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8442 remote_rcmd (char *command
,
8443 struct ui_file
*outbuf
)
8445 struct remote_state
*rs
= get_remote_state ();
8449 error (_("remote rcmd is only available after target open"));
8451 /* Send a NULL command across as an empty command. */
8452 if (command
== NULL
)
8455 /* The query prefix. */
8456 strcpy (rs
->buf
, "qRcmd,");
8457 p
= strchr (rs
->buf
, '\0');
8459 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8460 > get_remote_packet_size ())
8461 error (_("\"monitor\" command ``%s'' is too long."), command
);
8463 /* Encode the actual command. */
8464 bin2hex ((gdb_byte
*) command
, p
, 0);
8466 if (putpkt (rs
->buf
) < 0)
8467 error (_("Communication problem with target."));
8469 /* get/display the response */
8474 /* XXX - see also remote_get_noisy_reply(). */
8476 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8479 error (_("Target does not support this command."));
8480 if (buf
[0] == 'O' && buf
[1] != 'K')
8482 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8485 if (strcmp (buf
, "OK") == 0)
8487 if (strlen (buf
) == 3 && buf
[0] == 'E'
8488 && isdigit (buf
[1]) && isdigit (buf
[2]))
8490 error (_("Protocol error with Rcmd"));
8492 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8494 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8496 fputc_unfiltered (c
, outbuf
);
8502 static VEC(mem_region_s
) *
8503 remote_memory_map (struct target_ops
*ops
)
8505 VEC(mem_region_s
) *result
= NULL
;
8506 char *text
= target_read_stralloc (¤t_target
,
8507 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8511 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8513 result
= parse_memory_map (text
);
8514 do_cleanups (back_to
);
8521 packet_command (char *args
, int from_tty
)
8523 struct remote_state
*rs
= get_remote_state ();
8526 error (_("command can only be used with remote target"));
8529 error (_("remote-packet command requires packet text as argument"));
8531 puts_filtered ("sending: ");
8532 print_packet (args
);
8533 puts_filtered ("\n");
8536 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8537 puts_filtered ("received: ");
8538 print_packet (rs
->buf
);
8539 puts_filtered ("\n");
8543 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8545 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8547 static void threadset_test_cmd (char *cmd
, int tty
);
8549 static void threadalive_test (char *cmd
, int tty
);
8551 static void threadlist_test_cmd (char *cmd
, int tty
);
8553 int get_and_display_threadinfo (threadref
*ref
);
8555 static void threadinfo_test_cmd (char *cmd
, int tty
);
8557 static int thread_display_step (threadref
*ref
, void *context
);
8559 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8561 static void init_remote_threadtests (void);
8563 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8566 threadset_test_cmd (char *cmd
, int tty
)
8568 int sample_thread
= SAMPLE_THREAD
;
8570 printf_filtered (_("Remote threadset test\n"));
8571 set_general_thread (sample_thread
);
8576 threadalive_test (char *cmd
, int tty
)
8578 int sample_thread
= SAMPLE_THREAD
;
8579 int pid
= ptid_get_pid (inferior_ptid
);
8580 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8582 if (remote_thread_alive (ptid
))
8583 printf_filtered ("PASS: Thread alive test\n");
8585 printf_filtered ("FAIL: Thread alive test\n");
8588 void output_threadid (char *title
, threadref
*ref
);
8591 output_threadid (char *title
, threadref
*ref
)
8595 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8597 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8601 threadlist_test_cmd (char *cmd
, int tty
)
8604 threadref nextthread
;
8605 int done
, result_count
;
8606 threadref threadlist
[3];
8608 printf_filtered ("Remote Threadlist test\n");
8609 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8610 &result_count
, &threadlist
[0]))
8611 printf_filtered ("FAIL: threadlist test\n");
8614 threadref
*scan
= threadlist
;
8615 threadref
*limit
= scan
+ result_count
;
8617 while (scan
< limit
)
8618 output_threadid (" thread ", scan
++);
8623 display_thread_info (struct gdb_ext_thread_info
*info
)
8625 output_threadid ("Threadid: ", &info
->threadid
);
8626 printf_filtered ("Name: %s\n ", info
->shortname
);
8627 printf_filtered ("State: %s\n", info
->display
);
8628 printf_filtered ("other: %s\n\n", info
->more_display
);
8632 get_and_display_threadinfo (threadref
*ref
)
8636 struct gdb_ext_thread_info threadinfo
;
8638 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8639 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8640 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8641 display_thread_info (&threadinfo
);
8646 threadinfo_test_cmd (char *cmd
, int tty
)
8648 int athread
= SAMPLE_THREAD
;
8652 int_to_threadref (&thread
, athread
);
8653 printf_filtered ("Remote Threadinfo test\n");
8654 if (!get_and_display_threadinfo (&thread
))
8655 printf_filtered ("FAIL cannot get thread info\n");
8659 thread_display_step (threadref
*ref
, void *context
)
8661 /* output_threadid(" threadstep ",ref); *//* simple test */
8662 return get_and_display_threadinfo (ref
);
8666 threadlist_update_test_cmd (char *cmd
, int tty
)
8668 printf_filtered ("Remote Threadlist update test\n");
8669 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8673 init_remote_threadtests (void)
8675 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
8676 _("Fetch and print the remote list of "
8677 "thread identifiers, one pkt only"));
8678 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8679 _("Fetch and display info about one thread"));
8680 add_com ("tset", class_obscure
, threadset_test_cmd
,
8681 _("Test setting to a different thread"));
8682 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8683 _("Iterate through updating all remote thread info"));
8684 add_com ("talive", class_obscure
, threadalive_test
,
8685 _(" Remote thread alive test "));
8690 /* Convert a thread ID to a string. Returns the string in a static
8694 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8696 static char buf
[64];
8697 struct remote_state
*rs
= get_remote_state ();
8699 if (ptid_is_pid (ptid
))
8701 /* Printing an inferior target id. */
8703 /* When multi-process extensions are off, there's no way in the
8704 remote protocol to know the remote process id, if there's any
8705 at all. There's one exception --- when we're connected with
8706 target extended-remote, and we manually attached to a process
8707 with "attach PID". We don't record anywhere a flag that
8708 allows us to distinguish that case from the case of
8709 connecting with extended-remote and the stub already being
8710 attached to a process, and reporting yes to qAttached, hence
8711 no smart special casing here. */
8712 if (!remote_multi_process_p (rs
))
8714 xsnprintf (buf
, sizeof buf
, "Remote target");
8718 return normal_pid_to_str (ptid
);
8722 if (ptid_equal (magic_null_ptid
, ptid
))
8723 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8724 else if (remote_multi_process_p (rs
))
8725 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8726 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8728 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8729 ptid_get_tid (ptid
));
8734 /* Get the address of the thread local variable in OBJFILE which is
8735 stored at OFFSET within the thread local storage for thread PTID. */
8738 remote_get_thread_local_address (struct target_ops
*ops
,
8739 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8741 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8743 struct remote_state
*rs
= get_remote_state ();
8745 char *endp
= rs
->buf
+ get_remote_packet_size ();
8746 enum packet_result result
;
8748 strcpy (p
, "qGetTLSAddr:");
8750 p
= write_ptid (p
, endp
, ptid
);
8752 p
+= hexnumstr (p
, offset
);
8754 p
+= hexnumstr (p
, lm
);
8758 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8759 result
= packet_ok (rs
->buf
,
8760 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8761 if (result
== PACKET_OK
)
8765 unpack_varlen_hex (rs
->buf
, &result
);
8768 else if (result
== PACKET_UNKNOWN
)
8769 throw_error (TLS_GENERIC_ERROR
,
8770 _("Remote target doesn't support qGetTLSAddr packet"));
8772 throw_error (TLS_GENERIC_ERROR
,
8773 _("Remote target failed to process qGetTLSAddr request"));
8776 throw_error (TLS_GENERIC_ERROR
,
8777 _("TLS not supported or disabled on this target"));
8782 /* Provide thread local base, i.e. Thread Information Block address.
8783 Returns 1 if ptid is found and thread_local_base is non zero. */
8786 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
8788 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
8790 struct remote_state
*rs
= get_remote_state ();
8792 char *endp
= rs
->buf
+ get_remote_packet_size ();
8793 enum packet_result result
;
8795 strcpy (p
, "qGetTIBAddr:");
8797 p
= write_ptid (p
, endp
, ptid
);
8801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8802 result
= packet_ok (rs
->buf
,
8803 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
8804 if (result
== PACKET_OK
)
8808 unpack_varlen_hex (rs
->buf
, &result
);
8810 *addr
= (CORE_ADDR
) result
;
8813 else if (result
== PACKET_UNKNOWN
)
8814 error (_("Remote target doesn't support qGetTIBAddr packet"));
8816 error (_("Remote target failed to process qGetTIBAddr request"));
8819 error (_("qGetTIBAddr not supported or disabled on this target"));
8824 /* Support for inferring a target description based on the current
8825 architecture and the size of a 'g' packet. While the 'g' packet
8826 can have any size (since optional registers can be left off the
8827 end), some sizes are easily recognizable given knowledge of the
8828 approximate architecture. */
8830 struct remote_g_packet_guess
8833 const struct target_desc
*tdesc
;
8835 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8836 DEF_VEC_O(remote_g_packet_guess_s
);
8838 struct remote_g_packet_data
8840 VEC(remote_g_packet_guess_s
) *guesses
;
8843 static struct gdbarch_data
*remote_g_packet_data_handle
;
8846 remote_g_packet_data_init (struct obstack
*obstack
)
8848 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8852 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8853 const struct target_desc
*tdesc
)
8855 struct remote_g_packet_data
*data
8856 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8857 struct remote_g_packet_guess new_guess
, *guess
;
8860 gdb_assert (tdesc
!= NULL
);
8863 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8865 if (guess
->bytes
== bytes
)
8866 internal_error (__FILE__
, __LINE__
,
8867 _("Duplicate g packet description added for size %d"),
8870 new_guess
.bytes
= bytes
;
8871 new_guess
.tdesc
= tdesc
;
8872 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8875 /* Return 1 if remote_read_description would do anything on this target
8876 and architecture, 0 otherwise. */
8879 remote_read_description_p (struct target_ops
*target
)
8881 struct remote_g_packet_data
*data
8882 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8884 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8890 static const struct target_desc
*
8891 remote_read_description (struct target_ops
*target
)
8893 struct remote_g_packet_data
*data
8894 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8896 /* Do not try this during initial connection, when we do not know
8897 whether there is a running but stopped thread. */
8898 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8901 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8903 struct remote_g_packet_guess
*guess
;
8905 int bytes
= send_g_packet ();
8908 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8910 if (guess
->bytes
== bytes
)
8911 return guess
->tdesc
;
8913 /* We discard the g packet. A minor optimization would be to
8914 hold on to it, and fill the register cache once we have selected
8915 an architecture, but it's too tricky to do safely. */
8921 /* Remote file transfer support. This is host-initiated I/O, not
8922 target-initiated; for target-initiated, see remote-fileio.c. */
8924 /* If *LEFT is at least the length of STRING, copy STRING to
8925 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8926 decrease *LEFT. Otherwise raise an error. */
8929 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8931 int len
= strlen (string
);
8934 error (_("Packet too long for target."));
8936 memcpy (*buffer
, string
, len
);
8940 /* NUL-terminate the buffer as a convenience, if there is
8946 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8947 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8948 decrease *LEFT. Otherwise raise an error. */
8951 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8954 if (2 * len
> *left
)
8955 error (_("Packet too long for target."));
8957 bin2hex (bytes
, *buffer
, len
);
8961 /* NUL-terminate the buffer as a convenience, if there is
8967 /* If *LEFT is large enough, convert VALUE to hex and add it to
8968 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8969 decrease *LEFT. Otherwise raise an error. */
8972 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
8974 int len
= hexnumlen (value
);
8977 error (_("Packet too long for target."));
8979 hexnumstr (*buffer
, value
);
8983 /* NUL-terminate the buffer as a convenience, if there is
8989 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8990 value, *REMOTE_ERRNO to the remote error number or zero if none
8991 was included, and *ATTACHMENT to point to the start of the annex
8992 if any. The length of the packet isn't needed here; there may
8993 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8995 Return 0 if the packet could be parsed, -1 if it could not. If
8996 -1 is returned, the other variables may not be initialized. */
8999 remote_hostio_parse_result (char *buffer
, int *retcode
,
9000 int *remote_errno
, char **attachment
)
9007 if (buffer
[0] != 'F')
9011 *retcode
= strtol (&buffer
[1], &p
, 16);
9012 if (errno
!= 0 || p
== &buffer
[1])
9015 /* Check for ",errno". */
9019 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9020 if (errno
!= 0 || p
+ 1 == p2
)
9025 /* Check for ";attachment". If there is no attachment, the
9026 packet should end here. */
9029 *attachment
= p
+ 1;
9032 else if (*p
== '\0')
9038 /* Send a prepared I/O packet to the target and read its response.
9039 The prepared packet is in the global RS->BUF before this function
9040 is called, and the answer is there when we return.
9042 COMMAND_BYTES is the length of the request to send, which may include
9043 binary data. WHICH_PACKET is the packet configuration to check
9044 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9045 is set to the error number and -1 is returned. Otherwise the value
9046 returned by the function is returned.
9048 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9049 attachment is expected; an error will be reported if there's a
9050 mismatch. If one is found, *ATTACHMENT will be set to point into
9051 the packet buffer and *ATTACHMENT_LEN will be set to the
9052 attachment's length. */
9055 remote_hostio_send_command (int command_bytes
, int which_packet
,
9056 int *remote_errno
, char **attachment
,
9057 int *attachment_len
)
9059 struct remote_state
*rs
= get_remote_state ();
9060 int ret
, bytes_read
;
9061 char *attachment_tmp
;
9064 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9066 *remote_errno
= FILEIO_ENOSYS
;
9070 putpkt_binary (rs
->buf
, command_bytes
);
9071 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9073 /* If it timed out, something is wrong. Don't try to parse the
9077 *remote_errno
= FILEIO_EINVAL
;
9081 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9084 *remote_errno
= FILEIO_EINVAL
;
9086 case PACKET_UNKNOWN
:
9087 *remote_errno
= FILEIO_ENOSYS
;
9093 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9096 *remote_errno
= FILEIO_EINVAL
;
9100 /* Make sure we saw an attachment if and only if we expected one. */
9101 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9102 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9104 *remote_errno
= FILEIO_EINVAL
;
9108 /* If an attachment was found, it must point into the packet buffer;
9109 work out how many bytes there were. */
9110 if (attachment_tmp
!= NULL
)
9112 *attachment
= attachment_tmp
;
9113 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9119 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9120 remote file descriptor, or -1 if an error occurs (and set
9124 remote_hostio_open (const char *filename
, int flags
, int mode
,
9127 struct remote_state
*rs
= get_remote_state ();
9129 int left
= get_remote_packet_size () - 1;
9131 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9133 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9135 remote_buffer_add_string (&p
, &left
, ",");
9137 remote_buffer_add_int (&p
, &left
, flags
);
9138 remote_buffer_add_string (&p
, &left
, ",");
9140 remote_buffer_add_int (&p
, &left
, mode
);
9142 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9143 remote_errno
, NULL
, NULL
);
9146 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9147 Return the number of bytes written, or -1 if an error occurs (and
9148 set *REMOTE_ERRNO). */
9151 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9152 ULONGEST offset
, int *remote_errno
)
9154 struct remote_state
*rs
= get_remote_state ();
9156 int left
= get_remote_packet_size ();
9159 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9161 remote_buffer_add_int (&p
, &left
, fd
);
9162 remote_buffer_add_string (&p
, &left
, ",");
9164 remote_buffer_add_int (&p
, &left
, offset
);
9165 remote_buffer_add_string (&p
, &left
, ",");
9167 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9168 get_remote_packet_size () - (p
- rs
->buf
));
9170 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9171 remote_errno
, NULL
, NULL
);
9174 /* Read up to LEN bytes FD on the remote target into READ_BUF
9175 Return the number of bytes read, or -1 if an error occurs (and
9176 set *REMOTE_ERRNO). */
9179 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9180 ULONGEST offset
, int *remote_errno
)
9182 struct remote_state
*rs
= get_remote_state ();
9185 int left
= get_remote_packet_size ();
9186 int ret
, attachment_len
;
9189 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9191 remote_buffer_add_int (&p
, &left
, fd
);
9192 remote_buffer_add_string (&p
, &left
, ",");
9194 remote_buffer_add_int (&p
, &left
, len
);
9195 remote_buffer_add_string (&p
, &left
, ",");
9197 remote_buffer_add_int (&p
, &left
, offset
);
9199 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9200 remote_errno
, &attachment
,
9206 read_len
= remote_unescape_input (attachment
, attachment_len
,
9208 if (read_len
!= ret
)
9209 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9214 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9215 (and set *REMOTE_ERRNO). */
9218 remote_hostio_close (int fd
, int *remote_errno
)
9220 struct remote_state
*rs
= get_remote_state ();
9222 int left
= get_remote_packet_size () - 1;
9224 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9226 remote_buffer_add_int (&p
, &left
, fd
);
9228 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9229 remote_errno
, NULL
, NULL
);
9232 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9233 occurs (and set *REMOTE_ERRNO). */
9236 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9238 struct remote_state
*rs
= get_remote_state ();
9240 int left
= get_remote_packet_size () - 1;
9242 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9244 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9247 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9248 remote_errno
, NULL
, NULL
);
9252 remote_fileio_errno_to_host (int errnum
)
9276 case FILEIO_ENOTDIR
:
9296 case FILEIO_ENAMETOOLONG
:
9297 return ENAMETOOLONG
;
9303 remote_hostio_error (int errnum
)
9305 int host_error
= remote_fileio_errno_to_host (errnum
);
9307 if (host_error
== -1)
9308 error (_("Unknown remote I/O error %d"), errnum
);
9310 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9314 remote_hostio_close_cleanup (void *opaque
)
9316 int fd
= *(int *) opaque
;
9319 remote_hostio_close (fd
, &remote_errno
);
9324 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9326 const char *filename
= bfd_get_filename (abfd
);
9327 int fd
, remote_errno
;
9330 gdb_assert (remote_filename_p (filename
));
9332 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9335 errno
= remote_fileio_errno_to_host (remote_errno
);
9336 bfd_set_error (bfd_error_system_call
);
9340 stream
= xmalloc (sizeof (int));
9346 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9348 int fd
= *(int *)stream
;
9353 /* Ignore errors on close; these may happen if the remote
9354 connection was already torn down. */
9355 remote_hostio_close (fd
, &remote_errno
);
9361 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9362 file_ptr nbytes
, file_ptr offset
)
9364 int fd
= *(int *)stream
;
9366 file_ptr pos
, bytes
;
9369 while (nbytes
> pos
)
9371 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9372 offset
+ pos
, &remote_errno
);
9374 /* Success, but no bytes, means end-of-file. */
9378 errno
= remote_fileio_errno_to_host (remote_errno
);
9379 bfd_set_error (bfd_error_system_call
);
9390 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9392 /* FIXME: We should probably implement remote_hostio_stat. */
9393 sb
->st_size
= INT_MAX
;
9398 remote_filename_p (const char *filename
)
9400 return strncmp (filename
, "remote:", 7) == 0;
9404 remote_bfd_open (const char *remote_file
, const char *target
)
9406 return bfd_openr_iovec (remote_file
, target
,
9407 remote_bfd_iovec_open
, NULL
,
9408 remote_bfd_iovec_pread
,
9409 remote_bfd_iovec_close
,
9410 remote_bfd_iovec_stat
);
9414 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9416 struct cleanup
*back_to
, *close_cleanup
;
9417 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9420 int bytes_in_buffer
;
9425 error (_("command can only be used with remote target"));
9427 file
= fopen (local_file
, "rb");
9429 perror_with_name (local_file
);
9430 back_to
= make_cleanup_fclose (file
);
9432 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9434 0700, &remote_errno
);
9436 remote_hostio_error (remote_errno
);
9438 /* Send up to this many bytes at once. They won't all fit in the
9439 remote packet limit, so we'll transfer slightly fewer. */
9440 io_size
= get_remote_packet_size ();
9441 buffer
= xmalloc (io_size
);
9442 make_cleanup (xfree
, buffer
);
9444 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9446 bytes_in_buffer
= 0;
9449 while (bytes_in_buffer
|| !saw_eof
)
9453 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9454 io_size
- bytes_in_buffer
,
9459 error (_("Error reading %s."), local_file
);
9462 /* EOF. Unless there is something still in the
9463 buffer from the last iteration, we are done. */
9465 if (bytes_in_buffer
== 0)
9473 bytes
+= bytes_in_buffer
;
9474 bytes_in_buffer
= 0;
9476 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9477 offset
, &remote_errno
);
9480 remote_hostio_error (remote_errno
);
9481 else if (retcode
== 0)
9482 error (_("Remote write of %d bytes returned 0!"), bytes
);
9483 else if (retcode
< bytes
)
9485 /* Short write. Save the rest of the read data for the next
9487 bytes_in_buffer
= bytes
- retcode
;
9488 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9494 discard_cleanups (close_cleanup
);
9495 if (remote_hostio_close (fd
, &remote_errno
))
9496 remote_hostio_error (remote_errno
);
9499 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9500 do_cleanups (back_to
);
9504 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9506 struct cleanup
*back_to
, *close_cleanup
;
9507 int fd
, remote_errno
, bytes
, io_size
;
9513 error (_("command can only be used with remote target"));
9515 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9517 remote_hostio_error (remote_errno
);
9519 file
= fopen (local_file
, "wb");
9521 perror_with_name (local_file
);
9522 back_to
= make_cleanup_fclose (file
);
9524 /* Send up to this many bytes at once. They won't all fit in the
9525 remote packet limit, so we'll transfer slightly fewer. */
9526 io_size
= get_remote_packet_size ();
9527 buffer
= xmalloc (io_size
);
9528 make_cleanup (xfree
, buffer
);
9530 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9535 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9537 /* Success, but no bytes, means end-of-file. */
9540 remote_hostio_error (remote_errno
);
9544 bytes
= fwrite (buffer
, 1, bytes
, file
);
9546 perror_with_name (local_file
);
9549 discard_cleanups (close_cleanup
);
9550 if (remote_hostio_close (fd
, &remote_errno
))
9551 remote_hostio_error (remote_errno
);
9554 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9555 do_cleanups (back_to
);
9559 remote_file_delete (const char *remote_file
, int from_tty
)
9561 int retcode
, remote_errno
;
9564 error (_("command can only be used with remote target"));
9566 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9568 remote_hostio_error (remote_errno
);
9571 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9575 remote_put_command (char *args
, int from_tty
)
9577 struct cleanup
*back_to
;
9581 error_no_arg (_("file to put"));
9583 argv
= gdb_buildargv (args
);
9584 back_to
= make_cleanup_freeargv (argv
);
9585 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9586 error (_("Invalid parameters to remote put"));
9588 remote_file_put (argv
[0], argv
[1], from_tty
);
9590 do_cleanups (back_to
);
9594 remote_get_command (char *args
, int from_tty
)
9596 struct cleanup
*back_to
;
9600 error_no_arg (_("file to get"));
9602 argv
= gdb_buildargv (args
);
9603 back_to
= make_cleanup_freeargv (argv
);
9604 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9605 error (_("Invalid parameters to remote get"));
9607 remote_file_get (argv
[0], argv
[1], from_tty
);
9609 do_cleanups (back_to
);
9613 remote_delete_command (char *args
, int from_tty
)
9615 struct cleanup
*back_to
;
9619 error_no_arg (_("file to delete"));
9621 argv
= gdb_buildargv (args
);
9622 back_to
= make_cleanup_freeargv (argv
);
9623 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9624 error (_("Invalid parameters to remote delete"));
9626 remote_file_delete (argv
[0], from_tty
);
9628 do_cleanups (back_to
);
9632 remote_command (char *args
, int from_tty
)
9634 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9638 remote_can_execute_reverse (void)
9640 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9641 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9648 remote_supports_non_stop (void)
9654 remote_supports_multi_process (void)
9656 struct remote_state
*rs
= get_remote_state ();
9658 return remote_multi_process_p (rs
);
9662 remote_supports_cond_tracepoints (void)
9664 struct remote_state
*rs
= get_remote_state ();
9666 return rs
->cond_tracepoints
;
9670 remote_supports_fast_tracepoints (void)
9672 struct remote_state
*rs
= get_remote_state ();
9674 return rs
->fast_tracepoints
;
9678 remote_supports_static_tracepoints (void)
9680 struct remote_state
*rs
= get_remote_state ();
9682 return rs
->static_tracepoints
;
9686 remote_supports_enable_disable_tracepoint (void)
9688 struct remote_state
*rs
= get_remote_state ();
9690 return rs
->enable_disable_tracepoints
;
9694 remote_trace_init (void)
9697 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9698 if (strcmp (target_buf
, "OK") != 0)
9699 error (_("Target does not support this command."));
9702 static void free_actions_list (char **actions_list
);
9703 static void free_actions_list_cleanup_wrapper (void *);
9705 free_actions_list_cleanup_wrapper (void *al
)
9707 free_actions_list (al
);
9711 free_actions_list (char **actions_list
)
9715 if (actions_list
== 0)
9718 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9719 xfree (actions_list
[ndx
]);
9721 xfree (actions_list
);
9724 /* Recursive routine to walk through command list including loops, and
9725 download packets for each command. */
9728 remote_download_command_source (int num
, ULONGEST addr
,
9729 struct command_line
*cmds
)
9731 struct remote_state
*rs
= get_remote_state ();
9732 struct command_line
*cmd
;
9734 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
9736 QUIT
; /* Allow user to bail out with ^C. */
9737 strcpy (rs
->buf
, "QTDPsrc:");
9738 encode_source_string (num
, addr
, "cmd", cmd
->line
,
9739 rs
->buf
+ strlen (rs
->buf
),
9740 rs
->buf_size
- strlen (rs
->buf
));
9742 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9743 if (strcmp (target_buf
, "OK"))
9744 warning (_("Target does not support source download."));
9746 if (cmd
->control_type
== while_control
9747 || cmd
->control_type
== while_stepping_control
)
9749 remote_download_command_source (num
, addr
, *cmd
->body_list
);
9751 QUIT
; /* Allow user to bail out with ^C. */
9752 strcpy (rs
->buf
, "QTDPsrc:");
9753 encode_source_string (num
, addr
, "cmd", "end",
9754 rs
->buf
+ strlen (rs
->buf
),
9755 rs
->buf_size
- strlen (rs
->buf
));
9757 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9758 if (strcmp (target_buf
, "OK"))
9759 warning (_("Target does not support source download."));
9765 remote_download_tracepoint (struct breakpoint
*t
)
9767 struct bp_location
*loc
;
9772 char **stepping_actions
;
9774 struct cleanup
*old_chain
= NULL
;
9775 struct agent_expr
*aexpr
;
9776 struct cleanup
*aexpr_chain
= NULL
;
9779 /* Iterate over all the tracepoint locations. It's up to the target to
9780 notice multiple tracepoint packets with the same number but different
9781 addresses, and treat them as multiple locations. */
9782 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
9784 encode_actions (t
, loc
, &tdp_actions
, &stepping_actions
);
9785 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9787 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
9790 tpaddr
= loc
->address
;
9791 sprintf_vma (addrbuf
, tpaddr
);
9792 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
9793 addrbuf
, /* address */
9794 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
9795 t
->step_count
, t
->pass_count
);
9796 /* Fast tracepoints are mostly handled by the target, but we can
9797 tell the target how big of an instruction block should be moved
9799 if (t
->type
== bp_fast_tracepoint
)
9801 /* Only test for support at download time; we may not know
9802 target capabilities at definition time. */
9803 if (remote_supports_fast_tracepoints ())
9807 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9808 tpaddr
, &isize
, NULL
))
9809 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9811 /* If it passed validation at definition but fails now,
9812 something is very wrong. */
9813 internal_error (__FILE__
, __LINE__
,
9814 _("Fast tracepoint not "
9815 "valid during download"));
9818 /* Fast tracepoints are functionally identical to regular
9819 tracepoints, so don't take lack of support as a reason to
9820 give up on the trace run. */
9821 warning (_("Target does not support fast tracepoints, "
9822 "downloading %d as regular tracepoint"), t
->number
);
9824 else if (t
->type
== bp_static_tracepoint
)
9826 /* Only test for support at download time; we may not know
9827 target capabilities at definition time. */
9828 if (remote_supports_static_tracepoints ())
9830 struct static_tracepoint_marker marker
;
9832 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
9835 error (_("Static tracepoint not valid during download"));
9838 /* Fast tracepoints are functionally identical to regular
9839 tracepoints, so don't take lack of support as a reason
9840 to give up on the trace run. */
9841 error (_("Target does not support static tracepoints"));
9843 /* If the tracepoint has a conditional, make it into an agent
9844 expression and append to the definition. */
9847 /* Only test support at download time, we may not know target
9848 capabilities at definition time. */
9849 if (remote_supports_cond_tracepoints ())
9851 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
9852 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9853 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9854 pkt
= buf
+ strlen (buf
);
9855 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9856 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9858 do_cleanups (aexpr_chain
);
9861 warning (_("Target does not support conditional tracepoints, "
9862 "ignoring tp %d cond"), t
->number
);
9865 if (t
->commands
|| *default_collect
)
9868 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9869 if (strcmp (target_buf
, "OK"))
9870 error (_("Target does not support tracepoints."));
9872 /* do_single_steps (t); */
9875 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9877 QUIT
; /* Allow user to bail out with ^C. */
9878 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9879 t
->number
, addrbuf
, /* address */
9881 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9884 remote_get_noisy_reply (&target_buf
,
9886 if (strcmp (target_buf
, "OK"))
9887 error (_("Error on target while setting tracepoints."));
9890 if (stepping_actions
)
9892 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9894 QUIT
; /* Allow user to bail out with ^C. */
9895 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9896 t
->number
, addrbuf
, /* address */
9897 ((ndx
== 0) ? "S" : ""),
9898 stepping_actions
[ndx
],
9899 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9901 remote_get_noisy_reply (&target_buf
,
9903 if (strcmp (target_buf
, "OK"))
9904 error (_("Error on target while setting tracepoints."));
9908 if (remote_protocol_packets
[PACKET_TracepointSource
].support
9913 strcpy (buf
, "QTDPsrc:");
9914 encode_source_string (t
->number
, loc
->address
,
9915 "at", t
->addr_string
, buf
+ strlen (buf
),
9916 2048 - strlen (buf
));
9919 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9920 if (strcmp (target_buf
, "OK"))
9921 warning (_("Target does not support source download."));
9925 strcpy (buf
, "QTDPsrc:");
9926 encode_source_string (t
->number
, loc
->address
,
9927 "cond", t
->cond_string
, buf
+ strlen (buf
),
9928 2048 - strlen (buf
));
9930 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9931 if (strcmp (target_buf
, "OK"))
9932 warning (_("Target does not support source download."));
9934 remote_download_command_source (t
->number
, loc
->address
,
9935 breakpoint_commands (t
));
9938 do_cleanups (old_chain
);
9943 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
9945 struct remote_state
*rs
= get_remote_state ();
9948 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
9949 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
9950 p
= rs
->buf
+ strlen (rs
->buf
);
9951 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
9952 error (_("Trace state variable name too long for tsv definition packet"));
9953 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
9956 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9957 if (*target_buf
== '\0')
9958 error (_("Target does not support this command."));
9959 if (strcmp (target_buf
, "OK") != 0)
9960 error (_("Error on target while downloading trace state variable."));
9964 remote_enable_tracepoint (struct bp_location
*location
)
9966 struct remote_state
*rs
= get_remote_state ();
9969 sprintf_vma (addr_buf
, location
->address
);
9970 sprintf (rs
->buf
, "QTEnable:%x:%s", location
->owner
->number
, addr_buf
);
9972 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
9973 if (*rs
->buf
== '\0')
9974 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
9975 if (strcmp (rs
->buf
, "OK") != 0)
9976 error (_("Error on target while enabling tracepoint."));
9980 remote_disable_tracepoint (struct bp_location
*location
)
9982 struct remote_state
*rs
= get_remote_state ();
9985 sprintf_vma (addr_buf
, location
->address
);
9986 sprintf (rs
->buf
, "QTDisable:%x:%s", location
->owner
->number
, addr_buf
);
9988 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
9989 if (*rs
->buf
== '\0')
9990 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
9991 if (strcmp (rs
->buf
, "OK") != 0)
9992 error (_("Error on target while disabling tracepoint."));
9996 remote_trace_set_readonly_regions (void)
10005 return; /* No information to give. */
10007 strcpy (target_buf
, "QTro");
10008 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10010 char tmp1
[40], tmp2
[40];
10013 if ((s
->flags
& SEC_LOAD
) == 0 ||
10014 /* (s->flags & SEC_CODE) == 0 || */
10015 (s
->flags
& SEC_READONLY
) == 0)
10019 vma
= bfd_get_section_vma (,s
);
10020 size
= bfd_get_section_size (s
);
10021 sprintf_vma (tmp1
, vma
);
10022 sprintf_vma (tmp2
, vma
+ size
);
10023 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10024 if (offset
+ sec_length
+ 1 > target_buf_size
)
10026 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10029 Too many sections for read-only sections definition packet."));
10032 sprintf (target_buf
+ offset
, ":%s,%s", tmp1
, tmp2
);
10033 offset
+= sec_length
;
10037 putpkt (target_buf
);
10038 getpkt (&target_buf
, &target_buf_size
, 0);
10043 remote_trace_start (void)
10045 putpkt ("QTStart");
10046 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10047 if (*target_buf
== '\0')
10048 error (_("Target does not support this command."));
10049 if (strcmp (target_buf
, "OK") != 0)
10050 error (_("Bogus reply from target: %s"), target_buf
);
10054 remote_get_trace_status (struct trace_status
*ts
)
10057 /* FIXME we need to get register block size some other way. */
10058 extern int trace_regblock_size
;
10060 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10062 putpkt ("qTStatus");
10063 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10065 /* If the remote target doesn't do tracing, flag it. */
10069 /* We're working with a live target. */
10072 /* Set some defaults. */
10073 ts
->running_known
= 0;
10074 ts
->stop_reason
= trace_stop_reason_unknown
;
10075 ts
->traceframe_count
= -1;
10076 ts
->buffer_free
= 0;
10079 error (_("Bogus trace status reply from target: %s"), target_buf
);
10081 parse_trace_status (p
, ts
);
10083 return ts
->running
;
10087 remote_trace_stop (void)
10090 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10091 if (*target_buf
== '\0')
10092 error (_("Target does not support this command."));
10093 if (strcmp (target_buf
, "OK") != 0)
10094 error (_("Bogus reply from target: %s"), target_buf
);
10098 remote_trace_find (enum trace_find_type type
, int num
,
10099 ULONGEST addr1
, ULONGEST addr2
,
10102 struct remote_state
*rs
= get_remote_state ();
10104 int target_frameno
= -1, target_tracept
= -1;
10106 /* Lookups other than by absolute frame number depend on the current
10107 trace selected, so make sure it is correct on the remote end
10109 if (type
!= tfind_number
)
10110 set_remote_traceframe ();
10113 strcpy (p
, "QTFrame:");
10114 p
= strchr (p
, '\0');
10118 sprintf (p
, "%x", num
);
10121 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
10124 sprintf (p
, "tdp:%x", num
);
10127 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10129 case tfind_outside
:
10130 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
10133 error (_("Unknown trace find type %d"), type
);
10137 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10138 if (*reply
== '\0')
10139 error (_("Target does not support this command."));
10141 while (reply
&& *reply
)
10146 target_frameno
= (int) strtol (p
, &reply
, 16);
10148 error (_("Unable to parse trace frame number"));
10149 /* Don't update our remote traceframe number cache on failure
10150 to select a remote traceframe. */
10151 if (target_frameno
== -1)
10156 target_tracept
= (int) strtol (p
, &reply
, 16);
10158 error (_("Unable to parse tracepoint number"));
10160 case 'O': /* "OK"? */
10161 if (reply
[1] == 'K' && reply
[2] == '\0')
10164 error (_("Bogus reply from target: %s"), reply
);
10167 error (_("Bogus reply from target: %s"), reply
);
10170 *tpp
= target_tracept
;
10172 remote_traceframe_number
= target_frameno
;
10173 return target_frameno
;
10177 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10179 struct remote_state
*rs
= get_remote_state ();
10183 set_remote_traceframe ();
10185 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
10187 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10188 if (reply
&& *reply
)
10192 unpack_varlen_hex (reply
+ 1, &uval
);
10193 *val
= (LONGEST
) uval
;
10201 remote_save_trace_data (const char *filename
)
10203 struct remote_state
*rs
= get_remote_state ();
10207 strcpy (p
, "QTSave:");
10209 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10210 error (_("Remote file name too long for trace save packet"));
10211 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10214 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10215 if (*reply
!= '\0')
10216 error (_("Target does not support this command."));
10217 if (strcmp (reply
, "OK") != 0)
10218 error (_("Bogus reply from target: %s"), reply
);
10222 /* This is basically a memory transfer, but needs to be its own packet
10223 because we don't know how the target actually organizes its trace
10224 memory, plus we want to be able to ask for as much as possible, but
10225 not be unhappy if we don't get as much as we ask for. */
10228 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10230 struct remote_state
*rs
= get_remote_state ();
10236 strcpy (p
, "qTBuffer:");
10238 p
+= hexnumstr (p
, offset
);
10240 p
+= hexnumstr (p
, len
);
10244 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10245 if (reply
&& *reply
)
10247 /* 'l' by itself means we're at the end of the buffer and
10248 there is nothing more to get. */
10252 /* Convert the reply into binary. Limit the number of bytes to
10253 convert according to our passed-in buffer size, rather than
10254 what was returned in the packet; if the target is
10255 unexpectedly generous and gives us a bigger reply than we
10256 asked for, we don't want to crash. */
10257 rslt
= hex2bin (target_buf
, buf
, len
);
10261 /* Something went wrong, flag as an error. */
10266 remote_set_disconnected_tracing (int val
)
10268 struct remote_state
*rs
= get_remote_state ();
10270 if (rs
->disconnected_tracing
)
10274 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
10276 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10277 if (*reply
== '\0')
10278 error (_("Target does not support this command."));
10279 if (strcmp (reply
, "OK") != 0)
10280 error (_("Bogus reply from target: %s"), reply
);
10283 warning (_("Target does not support disconnected tracing."));
10287 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10289 struct thread_info
*info
= find_thread_ptid (ptid
);
10291 if (info
&& info
->private)
10292 return info
->private->core
;
10297 remote_set_circular_trace_buffer (int val
)
10299 struct remote_state
*rs
= get_remote_state ();
10302 sprintf (rs
->buf
, "QTBuffer:circular:%x", val
);
10304 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10305 if (*reply
== '\0')
10306 error (_("Target does not support this command."));
10307 if (strcmp (reply
, "OK") != 0)
10308 error (_("Bogus reply from target: %s"), reply
);
10311 static struct traceframe_info
*
10312 remote_traceframe_info (void)
10316 text
= target_read_stralloc (¤t_target
,
10317 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10320 struct traceframe_info
*info
;
10321 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10323 info
= parse_traceframe_info (text
);
10324 do_cleanups (back_to
);
10332 init_remote_ops (void)
10334 remote_ops
.to_shortname
= "remote";
10335 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
10336 remote_ops
.to_doc
=
10337 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10338 Specify the serial device it is connected to\n\
10339 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
10340 remote_ops
.to_open
= remote_open
;
10341 remote_ops
.to_close
= remote_close
;
10342 remote_ops
.to_detach
= remote_detach
;
10343 remote_ops
.to_disconnect
= remote_disconnect
;
10344 remote_ops
.to_resume
= remote_resume
;
10345 remote_ops
.to_wait
= remote_wait
;
10346 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
10347 remote_ops
.to_store_registers
= remote_store_registers
;
10348 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
10349 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
10350 remote_ops
.to_files_info
= remote_files_info
;
10351 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
10352 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
10353 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
10354 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
10355 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
10356 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
10357 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
10358 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
10359 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
10360 remote_ops
.to_kill
= remote_kill
;
10361 remote_ops
.to_load
= generic_load
;
10362 remote_ops
.to_mourn_inferior
= remote_mourn
;
10363 remote_ops
.to_pass_signals
= remote_pass_signals
;
10364 remote_ops
.to_thread_alive
= remote_thread_alive
;
10365 remote_ops
.to_find_new_threads
= remote_threads_info
;
10366 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
10367 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
10368 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
10369 remote_ops
.to_stop
= remote_stop
;
10370 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
10371 remote_ops
.to_rcmd
= remote_rcmd
;
10372 remote_ops
.to_log_command
= serial_log_command
;
10373 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
10374 remote_ops
.to_stratum
= process_stratum
;
10375 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
10376 remote_ops
.to_has_memory
= default_child_has_memory
;
10377 remote_ops
.to_has_stack
= default_child_has_stack
;
10378 remote_ops
.to_has_registers
= default_child_has_registers
;
10379 remote_ops
.to_has_execution
= default_child_has_execution
;
10380 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
10381 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
10382 remote_ops
.to_magic
= OPS_MAGIC
;
10383 remote_ops
.to_memory_map
= remote_memory_map
;
10384 remote_ops
.to_flash_erase
= remote_flash_erase
;
10385 remote_ops
.to_flash_done
= remote_flash_done
;
10386 remote_ops
.to_read_description
= remote_read_description
;
10387 remote_ops
.to_search_memory
= remote_search_memory
;
10388 remote_ops
.to_can_async_p
= remote_can_async_p
;
10389 remote_ops
.to_is_async_p
= remote_is_async_p
;
10390 remote_ops
.to_async
= remote_async
;
10391 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
10392 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
10393 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
10394 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
10395 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
10396 remote_ops
.to_trace_init
= remote_trace_init
;
10397 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
10398 remote_ops
.to_download_trace_state_variable
10399 = remote_download_trace_state_variable
;
10400 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
10401 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
10402 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
10403 remote_ops
.to_trace_start
= remote_trace_start
;
10404 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
10405 remote_ops
.to_trace_stop
= remote_trace_stop
;
10406 remote_ops
.to_trace_find
= remote_trace_find
;
10407 remote_ops
.to_get_trace_state_variable_value
10408 = remote_get_trace_state_variable_value
;
10409 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
10410 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
10411 remote_ops
.to_upload_trace_state_variables
10412 = remote_upload_trace_state_variables
;
10413 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
10414 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
10415 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
10416 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
10417 remote_ops
.to_verify_memory
= remote_verify_memory
;
10418 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
10419 remote_ops
.to_set_permissions
= remote_set_permissions
;
10420 remote_ops
.to_static_tracepoint_marker_at
10421 = remote_static_tracepoint_marker_at
;
10422 remote_ops
.to_static_tracepoint_markers_by_strid
10423 = remote_static_tracepoint_markers_by_strid
;
10424 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
10427 /* Set up the extended remote vector by making a copy of the standard
10428 remote vector and adding to it. */
10431 init_extended_remote_ops (void)
10433 extended_remote_ops
= remote_ops
;
10435 extended_remote_ops
.to_shortname
= "extended-remote";
10436 extended_remote_ops
.to_longname
=
10437 "Extended remote serial target in gdb-specific protocol";
10438 extended_remote_ops
.to_doc
=
10439 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
10440 Specify the serial device it is connected to (e.g. /dev/ttya).";
10441 extended_remote_ops
.to_open
= extended_remote_open
;
10442 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
10443 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
10444 extended_remote_ops
.to_detach
= extended_remote_detach
;
10445 extended_remote_ops
.to_attach
= extended_remote_attach
;
10446 extended_remote_ops
.to_kill
= extended_remote_kill
;
10450 remote_can_async_p (void)
10452 if (!target_async_permitted
)
10453 /* We only enable async when the user specifically asks for it. */
10456 /* We're async whenever the serial device is. */
10457 return serial_can_async_p (remote_desc
);
10461 remote_is_async_p (void)
10463 if (!target_async_permitted
)
10464 /* We only enable async when the user specifically asks for it. */
10467 /* We're async whenever the serial device is. */
10468 return serial_is_async_p (remote_desc
);
10471 /* Pass the SERIAL event on and up to the client. One day this code
10472 will be able to delay notifying the client of an event until the
10473 point where an entire packet has been received. */
10475 static void (*async_client_callback
) (enum inferior_event_type event_type
,
10477 static void *async_client_context
;
10478 static serial_event_ftype remote_async_serial_handler
;
10481 remote_async_serial_handler (struct serial
*scb
, void *context
)
10483 /* Don't propogate error information up to the client. Instead let
10484 the client find out about the error by querying the target. */
10485 async_client_callback (INF_REG_EVENT
, async_client_context
);
10489 remote_async_inferior_event_handler (gdb_client_data data
)
10491 inferior_event_handler (INF_REG_EVENT
, NULL
);
10495 remote_async_get_pending_events_handler (gdb_client_data data
)
10497 remote_get_pending_stop_replies ();
10501 remote_async (void (*callback
) (enum inferior_event_type event_type
,
10502 void *context
), void *context
)
10504 if (callback
!= NULL
)
10506 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
10507 async_client_callback
= callback
;
10508 async_client_context
= context
;
10511 serial_async (remote_desc
, NULL
, NULL
);
10515 set_remote_cmd (char *args
, int from_tty
)
10517 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
10521 show_remote_cmd (char *args
, int from_tty
)
10523 /* We can't just use cmd_show_list here, because we want to skip
10524 the redundant "show remote Z-packet" and the legacy aliases. */
10525 struct cleanup
*showlist_chain
;
10526 struct cmd_list_element
*list
= remote_show_cmdlist
;
10528 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
10529 for (; list
!= NULL
; list
= list
->next
)
10530 if (strcmp (list
->name
, "Z-packet") == 0)
10532 else if (list
->type
== not_set_cmd
)
10533 /* Alias commands are exactly like the original, except they
10534 don't have the normal type. */
10538 struct cleanup
*option_chain
10539 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
10541 ui_out_field_string (uiout
, "name", list
->name
);
10542 ui_out_text (uiout
, ": ");
10543 if (list
->type
== show_cmd
)
10544 do_setshow_command ((char *) NULL
, from_tty
, list
);
10546 cmd_func (list
, NULL
, from_tty
);
10547 /* Close the tuple. */
10548 do_cleanups (option_chain
);
10551 /* Close the tuple. */
10552 do_cleanups (showlist_chain
);
10556 /* Function to be called whenever a new objfile (shlib) is detected. */
10558 remote_new_objfile (struct objfile
*objfile
)
10560 if (remote_desc
!= 0) /* Have a remote connection. */
10561 remote_check_symbols (objfile
);
10564 /* Pull all the tracepoints defined on the target and create local
10565 data structures representing them. We don't want to create real
10566 tracepoints yet, we don't want to mess up the user's existing
10570 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
10572 struct remote_state
*rs
= get_remote_state ();
10575 /* Ask for a first packet of tracepoint definition. */
10577 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10579 while (*p
&& *p
!= 'l')
10581 parse_tracepoint_definition (p
, utpp
);
10582 /* Ask for another packet of tracepoint definition. */
10584 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10591 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
10593 struct remote_state
*rs
= get_remote_state ();
10596 /* Ask for a first packet of variable definition. */
10598 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10600 while (*p
&& *p
!= 'l')
10602 parse_tsv_definition (p
, utsvp
);
10603 /* Ask for another packet of variable definition. */
10605 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10612 _initialize_remote (void)
10614 struct remote_state
*rs
;
10615 struct cmd_list_element
*cmd
;
10618 /* architecture specific data */
10619 remote_gdbarch_data_handle
=
10620 gdbarch_data_register_post_init (init_remote_state
);
10621 remote_g_packet_data_handle
=
10622 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
10624 /* Initialize the per-target state. At the moment there is only one
10625 of these, not one per target. Only one target is active at a
10626 time. The default buffer size is unimportant; it will be expanded
10627 whenever a larger buffer is needed. */
10628 rs
= get_remote_state_raw ();
10629 rs
->buf_size
= 400;
10630 rs
->buf
= xmalloc (rs
->buf_size
);
10632 init_remote_ops ();
10633 add_target (&remote_ops
);
10635 init_extended_remote_ops ();
10636 add_target (&extended_remote_ops
);
10638 /* Hook into new objfile notification. */
10639 observer_attach_new_objfile (remote_new_objfile
);
10641 /* Set up signal handlers. */
10642 sigint_remote_token
=
10643 create_async_signal_handler (async_remote_interrupt
, NULL
);
10644 sigint_remote_twice_token
=
10645 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
10648 init_remote_threadtests ();
10651 /* set/show remote ... */
10653 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
10654 Remote protocol specific variables\n\
10655 Configure various remote-protocol specific variables such as\n\
10656 the packets being used"),
10657 &remote_set_cmdlist
, "set remote ",
10658 0 /* allow-unknown */, &setlist
);
10659 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
10660 Remote protocol specific variables\n\
10661 Configure various remote-protocol specific variables such as\n\
10662 the packets being used"),
10663 &remote_show_cmdlist
, "show remote ",
10664 0 /* allow-unknown */, &showlist
);
10666 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
10667 Compare section data on target to the exec file.\n\
10668 Argument is a single section name (default: all loaded sections)."),
10671 add_cmd ("packet", class_maintenance
, packet_command
, _("\
10672 Send an arbitrary packet to a remote target.\n\
10673 maintenance packet TEXT\n\
10674 If GDB is talking to an inferior via the GDB serial protocol, then\n\
10675 this command sends the string TEXT to the inferior, and displays the\n\
10676 response packet. GDB supplies the initial `$' character, and the\n\
10677 terminating `#' character and checksum."),
10680 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
10681 Set whether to send break if interrupted."), _("\
10682 Show whether to send break if interrupted."), _("\
10683 If set, a break, instead of a cntrl-c, is sent to the remote target."),
10684 set_remotebreak
, show_remotebreak
,
10685 &setlist
, &showlist
);
10686 cmd_name
= "remotebreak";
10687 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
10688 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10689 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10690 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10691 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10693 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10694 interrupt_sequence_modes
, &interrupt_sequence_mode
,
10696 Set interrupt sequence to remote target."), _("\
10697 Show interrupt sequence to remote target."), _("\
10698 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10699 NULL
, show_interrupt_sequence
,
10700 &remote_set_cmdlist
,
10701 &remote_show_cmdlist
);
10703 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10704 &interrupt_on_connect
, _("\
10705 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10706 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10707 If set, interrupt sequence is sent to remote target."),
10709 &remote_set_cmdlist
, &remote_show_cmdlist
);
10711 /* Install commands for configuring memory read/write packets. */
10713 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10714 Set the maximum number of bytes per memory write packet (deprecated)."),
10716 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10717 Show the maximum number of bytes per memory write packet (deprecated)."),
10719 add_cmd ("memory-write-packet-size", no_class
,
10720 set_memory_write_packet_size
, _("\
10721 Set the maximum number of bytes per memory-write packet.\n\
10722 Specify the number of bytes in a packet or 0 (zero) for the\n\
10723 default packet size. The actual limit is further reduced\n\
10724 dependent on the target. Specify ``fixed'' to disable the\n\
10725 further restriction and ``limit'' to enable that restriction."),
10726 &remote_set_cmdlist
);
10727 add_cmd ("memory-read-packet-size", no_class
,
10728 set_memory_read_packet_size
, _("\
10729 Set the maximum number of bytes per memory-read packet.\n\
10730 Specify the number of bytes in a packet or 0 (zero) for the\n\
10731 default packet size. The actual limit is further reduced\n\
10732 dependent on the target. Specify ``fixed'' to disable the\n\
10733 further restriction and ``limit'' to enable that restriction."),
10734 &remote_set_cmdlist
);
10735 add_cmd ("memory-write-packet-size", no_class
,
10736 show_memory_write_packet_size
,
10737 _("Show the maximum number of bytes per memory-write packet."),
10738 &remote_show_cmdlist
);
10739 add_cmd ("memory-read-packet-size", no_class
,
10740 show_memory_read_packet_size
,
10741 _("Show the maximum number of bytes per memory-read packet."),
10742 &remote_show_cmdlist
);
10744 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10745 &remote_hw_watchpoint_limit
, _("\
10746 Set the maximum number of target hardware watchpoints."), _("\
10747 Show the maximum number of target hardware watchpoints."), _("\
10748 Specify a negative limit for unlimited."),
10749 NULL
, NULL
, /* FIXME: i18n: The maximum
10750 number of target hardware
10751 watchpoints is %s. */
10752 &remote_set_cmdlist
, &remote_show_cmdlist
);
10753 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10754 &remote_hw_breakpoint_limit
, _("\
10755 Set the maximum number of target hardware breakpoints."), _("\
10756 Show the maximum number of target hardware breakpoints."), _("\
10757 Specify a negative limit for unlimited."),
10758 NULL
, NULL
, /* FIXME: i18n: The maximum
10759 number of target hardware
10760 breakpoints is %s. */
10761 &remote_set_cmdlist
, &remote_show_cmdlist
);
10763 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10764 &remote_address_size
, _("\
10765 Set the maximum size of the address (in bits) in a memory packet."), _("\
10766 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10768 NULL
, /* FIXME: i18n: */
10769 &setlist
, &showlist
);
10771 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10772 "X", "binary-download", 1);
10774 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10775 "vCont", "verbose-resume", 0);
10777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10778 "QPassSignals", "pass-signals", 0);
10780 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10781 "qSymbol", "symbol-lookup", 0);
10783 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10784 "P", "set-register", 1);
10786 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10787 "p", "fetch-register", 1);
10789 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10790 "Z0", "software-breakpoint", 0);
10792 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10793 "Z1", "hardware-breakpoint", 0);
10795 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10796 "Z2", "write-watchpoint", 0);
10798 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10799 "Z3", "read-watchpoint", 0);
10801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10802 "Z4", "access-watchpoint", 0);
10804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10805 "qXfer:auxv:read", "read-aux-vector", 0);
10807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10808 "qXfer:features:read", "target-features", 0);
10810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10811 "qXfer:libraries:read", "library-info", 0);
10813 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10814 "qXfer:memory-map:read", "memory-map", 0);
10816 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10817 "qXfer:spu:read", "read-spu-object", 0);
10819 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10820 "qXfer:spu:write", "write-spu-object", 0);
10822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10823 "qXfer:osdata:read", "osdata", 0);
10825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10826 "qXfer:threads:read", "threads", 0);
10828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10829 "qXfer:siginfo:read", "read-siginfo-object", 0);
10831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
10832 "qXfer:siginfo:write", "write-siginfo-object", 0);
10834 add_packet_config_cmd
10835 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
10836 "qXfer:trace-frame-info:read", "traceframe-info", 0);
10838 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
10839 "qGetTLSAddr", "get-thread-local-storage-address",
10842 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
10843 "qGetTIBAddr", "get-thread-information-block-address",
10846 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
10847 "bc", "reverse-continue", 0);
10849 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
10850 "bs", "reverse-step", 0);
10852 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
10853 "qSupported", "supported-packets", 0);
10855 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
10856 "qSearch:memory", "search-memory", 0);
10858 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
10859 "vFile:open", "hostio-open", 0);
10861 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
10862 "vFile:pread", "hostio-pread", 0);
10864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
10865 "vFile:pwrite", "hostio-pwrite", 0);
10867 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
10868 "vFile:close", "hostio-close", 0);
10870 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
10871 "vFile:unlink", "hostio-unlink", 0);
10873 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
10874 "vAttach", "attach", 0);
10876 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
10879 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
10880 "QStartNoAckMode", "noack", 0);
10882 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
10883 "vKill", "kill", 0);
10885 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
10886 "qAttached", "query-attached", 0);
10888 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
10889 "ConditionalTracepoints",
10890 "conditional-tracepoints", 0);
10891 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
10892 "FastTracepoints", "fast-tracepoints", 0);
10894 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
10895 "TracepointSource", "TracepointSource", 0);
10897 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
10898 "QAllow", "allow", 0);
10900 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
10901 "StaticTracepoints", "static-tracepoints", 0);
10903 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
10904 "qXfer:statictrace:read", "read-sdata-object", 0);
10906 /* Keep the old ``set remote Z-packet ...'' working. Each individual
10907 Z sub-packet has its own set and show commands, but users may
10908 have sets to this variable in their .gdbinit files (or in their
10910 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
10911 &remote_Z_packet_detect
, _("\
10912 Set use of remote protocol `Z' packets"), _("\
10913 Show use of remote protocol `Z' packets "), _("\
10914 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
10916 set_remote_protocol_Z_packet_cmd
,
10917 show_remote_protocol_Z_packet_cmd
,
10918 /* FIXME: i18n: Use of remote protocol
10919 `Z' packets is %s. */
10920 &remote_set_cmdlist
, &remote_show_cmdlist
);
10922 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
10923 Manipulate files on the remote system\n\
10924 Transfer files to and from the remote target system."),
10925 &remote_cmdlist
, "remote ",
10926 0 /* allow-unknown */, &cmdlist
);
10928 add_cmd ("put", class_files
, remote_put_command
,
10929 _("Copy a local file to the remote system."),
10932 add_cmd ("get", class_files
, remote_get_command
,
10933 _("Copy a remote file to the local system."),
10936 add_cmd ("delete", class_files
, remote_delete_command
,
10937 _("Delete a remote file."),
10940 remote_exec_file
= xstrdup ("");
10941 add_setshow_string_noescape_cmd ("exec-file", class_files
,
10942 &remote_exec_file
, _("\
10943 Set the remote pathname for \"run\""), _("\
10944 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
10945 &remote_set_cmdlist
, &remote_show_cmdlist
);
10947 /* Eventually initialize fileio. See fileio.c */
10948 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
10950 /* Take advantage of the fact that the LWP field is not used, to tag
10951 special ptids with it set to != 0. */
10952 magic_null_ptid
= ptid_build (42000, 1, -1);
10953 not_sent_ptid
= ptid_build (42000, 1, -2);
10954 any_thread_ptid
= ptid_build (42000, 1, 0);
10956 target_buf_size
= 2048;
10957 target_buf
= xmalloc (target_buf_size
);