1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 #include "exceptions.h"
32 /*#include "terminal.h" */
35 #include "gdb-stabs.h"
36 #include "gdbthread.h"
38 #include "remote-notif.h"
41 #include "gdb_assert.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-setshow.h"
46 #include "target-descriptions.h"
48 #include "filestuff.h"
53 #include "event-loop.h"
54 #include "event-top.h"
60 #include "gdbcore.h" /* for exec_bfd */
62 #include "remote-fileio.h"
63 #include "gdb/fileio.h"
65 #include "xml-support.h"
67 #include "memory-map.h"
69 #include "tracepoint.h"
75 /* Temp hacks for tracepoint encoding migration. */
76 static char *target_buf
;
77 static long target_buf_size
;
79 /* The size to align memory write packets, when practical. The protocol
80 does not guarantee any alignment, and gdb will generate short
81 writes and unaligned writes, but even as a best-effort attempt this
82 can improve bulk transfers. For instance, if a write is misaligned
83 relative to the target's data bus, the stub may need to make an extra
84 round trip fetching data from the target. This doesn't make a
85 huge difference, but it's easy to do, so we try to be helpful.
87 The alignment chosen is arbitrary; usually data bus width is
88 important here, not the possibly larger cache line size. */
89 enum { REMOTE_ALIGN_WRITES
= 16 };
91 /* Prototypes for local functions. */
92 static void async_cleanup_sigint_signal_handler (void *dummy
);
93 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
94 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
95 int forever
, int *is_notif
);
97 static void async_handle_remote_sigint (int);
98 static void async_handle_remote_sigint_twice (int);
100 static void remote_files_info (struct target_ops
*ignore
);
102 static void remote_prepare_to_store (struct target_ops
*self
,
103 struct regcache
*regcache
);
105 static void remote_open (char *name
, int from_tty
);
107 static void extended_remote_open (char *name
, int from_tty
);
109 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
111 static void remote_close (struct target_ops
*self
);
113 static void remote_mourn (struct target_ops
*ops
);
115 static void extended_remote_restart (void);
117 static void extended_remote_mourn (struct target_ops
*);
119 static void remote_mourn_1 (struct target_ops
*);
121 static void remote_send (char **buf
, long *sizeof_buf_p
);
123 static int readchar (int timeout
);
125 static void remote_serial_write (const char *str
, int len
);
127 static void remote_kill (struct target_ops
*ops
);
129 static int remote_can_async_p (struct target_ops
*);
131 static int remote_is_async_p (struct target_ops
*);
133 static void remote_async (struct target_ops
*ops
,
134 void (*callback
) (enum inferior_event_type event_type
,
138 static void sync_remote_interrupt_twice (int signo
);
140 static void interrupt_query (void);
142 static void set_general_thread (struct ptid ptid
);
143 static void set_continue_thread (struct ptid ptid
);
145 static void get_offsets (void);
147 static void skip_frame (void);
149 static long read_frame (char **buf_p
, long *sizeof_buf
);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void remote_stop (struct target_ops
*self
, ptid_t
);
159 static int stubhex (int ch
);
161 static int hexnumstr (char *, ULONGEST
);
163 static int hexnumnstr (char *, ULONGEST
, int);
165 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
167 static void print_packet (const char *);
169 static void compare_sections_command (char *, int);
171 static void packet_command (char *, int);
173 static int stub_unpack_int (char *buff
, int fieldlength
);
175 static ptid_t
remote_current_thread (ptid_t oldptid
);
177 static void remote_find_new_threads (void);
179 static int putpkt_binary (const char *buf
, int cnt
);
181 static void check_binary_download (CORE_ADDR addr
);
183 struct packet_config
;
185 static void show_packet_config_cmd (struct packet_config
*config
);
187 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
189 struct cmd_list_element
*c
,
192 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
193 static ptid_t
read_ptid (char *buf
, char **obuf
);
195 static void remote_set_permissions (struct target_ops
*self
);
198 static int remote_get_trace_status (struct target_ops
*self
,
199 struct trace_status
*ts
);
201 static int remote_upload_tracepoints (struct target_ops
*self
,
202 struct uploaded_tp
**utpp
);
204 static int remote_upload_trace_state_variables (struct target_ops
*self
,
205 struct uploaded_tsv
**utsvp
);
207 static void remote_query_supported (void);
209 static void remote_check_symbols (void);
211 void _initialize_remote (void);
214 static void stop_reply_xfree (struct stop_reply
*);
215 static void remote_parse_stop_reply (char *, struct stop_reply
*);
216 static void push_stop_reply (struct stop_reply
*);
217 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
218 static int peek_stop_reply (ptid_t ptid
);
220 static void remote_async_inferior_event_handler (gdb_client_data
);
222 static void remote_terminal_ours (struct target_ops
*self
);
224 static int remote_read_description_p (struct target_ops
*target
);
226 static void remote_console_output (char *msg
);
228 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
230 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
234 static struct cmd_list_element
*remote_cmdlist
;
236 /* For "set remote" and "show remote". */
238 static struct cmd_list_element
*remote_set_cmdlist
;
239 static struct cmd_list_element
*remote_show_cmdlist
;
241 /* Stub vCont actions support.
243 Each field is a boolean flag indicating whether the stub reports
244 support for the corresponding action. */
246 struct vCont_action_support
255 /* Controls whether GDB is willing to use range stepping. */
257 static int use_range_stepping
= 1;
259 #define OPAQUETHREADBYTES 8
261 /* a 64 bit opaque identifier */
262 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
264 /* About this many threadisds fit in a packet. */
266 #define MAXTHREADLISTRESULTS 32
268 /* Description of the remote protocol state for the currently
269 connected target. This is per-target state, and independent of the
270 selected architecture. */
274 /* A buffer to use for incoming packets, and its current size. The
275 buffer is grown dynamically for larger incoming packets.
276 Outgoing packets may also be constructed in this buffer.
277 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
278 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
283 /* True if we're going through initial connection setup (finding out
284 about the remote side's threads, relocating symbols, etc.). */
287 /* If we negotiated packet size explicitly (and thus can bypass
288 heuristics for the largest packet size that will not overflow
289 a buffer in the stub), this will be set to that packet size.
290 Otherwise zero, meaning to use the guessed size. */
291 long explicit_packet_size
;
293 /* remote_wait is normally called when the target is running and
294 waits for a stop reply packet. But sometimes we need to call it
295 when the target is already stopped. We can send a "?" packet
296 and have remote_wait read the response. Or, if we already have
297 the response, we can stash it in BUF and tell remote_wait to
298 skip calling getpkt. This flag is set when BUF contains a
299 stop reply packet and the target is not waiting. */
300 int cached_wait_status
;
302 /* True, if in no ack mode. That is, neither GDB nor the stub will
303 expect acks from each other. The connection is assumed to be
307 /* True if we're connected in extended remote mode. */
310 /* True if we resumed the target and we're waiting for the target to
311 stop. In the mean time, we can't start another command/query.
312 The remote server wouldn't be ready to process it, so we'd
313 timeout waiting for a reply that would never come and eventually
314 we'd close the connection. This can happen in asynchronous mode
315 because we allow GDB commands while the target is running. */
316 int waiting_for_stop_reply
;
318 /* The status of the stub support for the various vCont actions. */
319 struct vCont_action_support supports_vCont
;
321 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
322 responded to that. */
325 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
326 remote_open knows that we don't have a file open when the program
328 struct serial
*remote_desc
;
330 /* These are the threads which we last sent to the remote system. The
331 TID member will be -1 for all or -2 for not sent yet. */
332 ptid_t general_thread
;
333 ptid_t continue_thread
;
335 /* This is the traceframe which we last selected on the remote system.
336 It will be -1 if no traceframe is selected. */
337 int remote_traceframe_number
;
339 char *last_pass_packet
;
341 /* The last QProgramSignals packet sent to the target. We bypass
342 sending a new program signals list down to the target if the new
343 packet is exactly the same as the last we sent. IOW, we only let
344 the target know about program signals list changes. */
345 char *last_program_signals_packet
;
347 enum gdb_signal last_sent_signal
;
351 char *finished_object
;
352 char *finished_annex
;
353 ULONGEST finished_offset
;
355 /* Should we try the 'ThreadInfo' query packet?
357 This variable (NOT available to the user: auto-detect only!)
358 determines whether GDB will use the new, simpler "ThreadInfo"
359 query or the older, more complex syntax for thread queries.
360 This is an auto-detect variable (set to true at each connect,
361 and set to false when the target fails to recognize it). */
362 int use_threadinfo_query
;
363 int use_threadextra_query
;
365 void (*async_client_callback
) (enum inferior_event_type event_type
,
367 void *async_client_context
;
369 /* This is set to the data address of the access causing the target
370 to stop for a watchpoint. */
371 CORE_ADDR remote_watch_data_address
;
373 /* This is non-zero if target stopped for a watchpoint. */
374 int remote_stopped_by_watchpoint_p
;
376 threadref echo_nextthread
;
377 threadref nextthread
;
378 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
380 /* The state of remote notification. */
381 struct remote_notif_state
*notif_state
;
384 /* Private data that we'll store in (struct thread_info)->private. */
385 struct private_thread_info
392 free_private_thread_info (struct private_thread_info
*info
)
398 /* This data could be associated with a target, but we do not always
399 have access to the current target when we need it, so for now it is
400 static. This will be fine for as long as only one target is in use
402 static struct remote_state
*remote_state
;
404 static struct remote_state
*
405 get_remote_state_raw (void)
410 /* Allocate a new struct remote_state with xmalloc, initialize it, and
413 static struct remote_state
*
414 new_remote_state (void)
416 struct remote_state
*result
= XCNEW (struct remote_state
);
418 /* The default buffer size is unimportant; it will be expanded
419 whenever a larger buffer is needed. */
420 result
->buf_size
= 400;
421 result
->buf
= xmalloc (result
->buf_size
);
422 result
->remote_traceframe_number
= -1;
423 result
->last_sent_signal
= GDB_SIGNAL_0
;
428 /* Description of the remote protocol for a given architecture. */
432 long offset
; /* Offset into G packet. */
433 long regnum
; /* GDB's internal register number. */
434 LONGEST pnum
; /* Remote protocol register number. */
435 int in_g_packet
; /* Always part of G packet. */
436 /* long size in bytes; == register_size (target_gdbarch (), regnum);
438 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
442 struct remote_arch_state
444 /* Description of the remote protocol registers. */
445 long sizeof_g_packet
;
447 /* Description of the remote protocol registers indexed by REGNUM
448 (making an array gdbarch_num_regs in size). */
449 struct packet_reg
*regs
;
451 /* This is the size (in chars) of the first response to the ``g''
452 packet. It is used as a heuristic when determining the maximum
453 size of memory-read and memory-write packets. A target will
454 typically only reserve a buffer large enough to hold the ``g''
455 packet. The size does not include packet overhead (headers and
457 long actual_register_packet_size
;
459 /* This is the maximum size (in chars) of a non read/write packet.
460 It is also used as a cap on the size of read/write packets. */
461 long remote_packet_size
;
464 /* Utility: generate error from an incoming stub packet. */
466 trace_error (char *buf
)
469 return; /* not an error msg */
472 case '1': /* malformed packet error */
473 if (*++buf
== '0') /* general case: */
474 error (_("remote.c: error in outgoing packet."));
476 error (_("remote.c: error in outgoing packet at field #%ld."),
477 strtol (buf
, NULL
, 16));
479 error (_("Target returns error code '%s'."), buf
);
483 /* Utility: wait for reply from stub, while accepting "O" packets. */
485 remote_get_noisy_reply (char **buf_p
,
488 do /* Loop on reply from remote stub. */
492 QUIT
; /* Allow user to bail out with ^C. */
493 getpkt (buf_p
, sizeof_buf
, 0);
497 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
500 CORE_ADDR from
, to
, org_to
;
502 int adjusted_size
= 0;
503 volatile struct gdb_exception ex
;
505 p
= buf
+ strlen ("qRelocInsn:");
506 pp
= unpack_varlen_hex (p
, &ul
);
508 error (_("invalid qRelocInsn packet: %s"), buf
);
512 unpack_varlen_hex (p
, &ul
);
517 TRY_CATCH (ex
, RETURN_MASK_ALL
)
519 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
523 adjusted_size
= to
- org_to
;
525 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
528 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
530 /* Propagate memory errors silently back to the target.
531 The stub may have limited the range of addresses we
532 can write to, for example. */
537 /* Something unexpectedly bad happened. Be verbose so
538 we can tell what, and propagate the error back to the
539 stub, so it doesn't get stuck waiting for a
541 exception_fprintf (gdb_stderr
, ex
,
542 _("warning: relocating instruction: "));
546 else if (buf
[0] == 'O' && buf
[1] != 'K')
547 remote_console_output (buf
+ 1); /* 'O' message from stub */
549 return buf
; /* Here's the actual reply. */
554 /* Handle for retreving the remote protocol data from gdbarch. */
555 static struct gdbarch_data
*remote_gdbarch_data_handle
;
557 static struct remote_arch_state
*
558 get_remote_arch_state (void)
560 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
563 /* Fetch the global remote target state. */
565 static struct remote_state
*
566 get_remote_state (void)
568 /* Make sure that the remote architecture state has been
569 initialized, because doing so might reallocate rs->buf. Any
570 function which calls getpkt also needs to be mindful of changes
571 to rs->buf, but this call limits the number of places which run
573 get_remote_arch_state ();
575 return get_remote_state_raw ();
579 compare_pnums (const void *lhs_
, const void *rhs_
)
581 const struct packet_reg
* const *lhs
= lhs_
;
582 const struct packet_reg
* const *rhs
= rhs_
;
584 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
586 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
593 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
595 int regnum
, num_remote_regs
, offset
;
596 struct packet_reg
**remote_regs
;
598 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
600 struct packet_reg
*r
= ®s
[regnum
];
602 if (register_size (gdbarch
, regnum
) == 0)
603 /* Do not try to fetch zero-sized (placeholder) registers. */
606 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
611 /* Define the g/G packet format as the contents of each register
612 with a remote protocol number, in order of ascending protocol
615 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
616 * sizeof (struct packet_reg
*));
617 for (num_remote_regs
= 0, regnum
= 0;
618 regnum
< gdbarch_num_regs (gdbarch
);
620 if (regs
[regnum
].pnum
!= -1)
621 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
623 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
626 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
628 remote_regs
[regnum
]->in_g_packet
= 1;
629 remote_regs
[regnum
]->offset
= offset
;
630 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
636 /* Given the architecture described by GDBARCH, return the remote
637 protocol register's number and the register's offset in the g/G
638 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
639 If the target does not have a mapping for REGNUM, return false,
640 otherwise, return true. */
643 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
644 int *pnum
, int *poffset
)
647 struct packet_reg
*regs
;
648 struct cleanup
*old_chain
;
650 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
652 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
653 old_chain
= make_cleanup (xfree
, regs
);
655 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
657 *pnum
= regs
[regnum
].pnum
;
658 *poffset
= regs
[regnum
].offset
;
660 do_cleanups (old_chain
);
666 init_remote_state (struct gdbarch
*gdbarch
)
668 struct remote_state
*rs
= get_remote_state_raw ();
669 struct remote_arch_state
*rsa
;
671 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
673 /* Use the architecture to build a regnum<->pnum table, which will be
674 1:1 unless a feature set specifies otherwise. */
675 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
676 gdbarch_num_regs (gdbarch
),
679 /* Record the maximum possible size of the g packet - it may turn out
681 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
683 /* Default maximum number of characters in a packet body. Many
684 remote stubs have a hardwired buffer size of 400 bytes
685 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
686 as the maximum packet-size to ensure that the packet and an extra
687 NUL character can always fit in the buffer. This stops GDB
688 trashing stubs that try to squeeze an extra NUL into what is
689 already a full buffer (As of 1999-12-04 that was most stubs). */
690 rsa
->remote_packet_size
= 400 - 1;
692 /* This one is filled in when a ``g'' packet is received. */
693 rsa
->actual_register_packet_size
= 0;
695 /* Should rsa->sizeof_g_packet needs more space than the
696 default, adjust the size accordingly. Remember that each byte is
697 encoded as two characters. 32 is the overhead for the packet
698 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
699 (``$NN:G...#NN'') is a better guess, the below has been padded a
701 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
702 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
704 /* Make sure that the packet buffer is plenty big enough for
705 this architecture. */
706 if (rs
->buf_size
< rsa
->remote_packet_size
)
708 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
709 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
715 /* Return the current allowed size of a remote packet. This is
716 inferred from the current architecture, and should be used to
717 limit the length of outgoing packets. */
719 get_remote_packet_size (void)
721 struct remote_state
*rs
= get_remote_state ();
722 struct remote_arch_state
*rsa
= get_remote_arch_state ();
724 if (rs
->explicit_packet_size
)
725 return rs
->explicit_packet_size
;
727 return rsa
->remote_packet_size
;
730 static struct packet_reg
*
731 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
733 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
737 struct packet_reg
*r
= &rsa
->regs
[regnum
];
739 gdb_assert (r
->regnum
== regnum
);
744 static struct packet_reg
*
745 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
749 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
751 struct packet_reg
*r
= &rsa
->regs
[i
];
759 static struct target_ops remote_ops
;
761 static struct target_ops extended_remote_ops
;
763 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
764 ``forever'' still use the normal timeout mechanism. This is
765 currently used by the ASYNC code to guarentee that target reads
766 during the initial connect always time-out. Once getpkt has been
767 modified to return a timeout indication and, in turn
768 remote_wait()/wait_for_inferior() have gained a timeout parameter
770 static int wait_forever_enabled_p
= 1;
772 /* Allow the user to specify what sequence to send to the remote
773 when he requests a program interruption: Although ^C is usually
774 what remote systems expect (this is the default, here), it is
775 sometimes preferable to send a break. On other systems such
776 as the Linux kernel, a break followed by g, which is Magic SysRq g
777 is required in order to interrupt the execution. */
778 const char interrupt_sequence_control_c
[] = "Ctrl-C";
779 const char interrupt_sequence_break
[] = "BREAK";
780 const char interrupt_sequence_break_g
[] = "BREAK-g";
781 static const char *const interrupt_sequence_modes
[] =
783 interrupt_sequence_control_c
,
784 interrupt_sequence_break
,
785 interrupt_sequence_break_g
,
788 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
791 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
792 struct cmd_list_element
*c
,
795 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
796 fprintf_filtered (file
,
797 _("Send the ASCII ETX character (Ctrl-c) "
798 "to the remote target to interrupt the "
799 "execution of the program.\n"));
800 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
801 fprintf_filtered (file
,
802 _("send a break signal to the remote target "
803 "to interrupt the execution of the program.\n"));
804 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
805 fprintf_filtered (file
,
806 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
807 "the remote target to interrupt the execution "
808 "of Linux kernel.\n"));
810 internal_error (__FILE__
, __LINE__
,
811 _("Invalid value for interrupt_sequence_mode: %s."),
812 interrupt_sequence_mode
);
815 /* This boolean variable specifies whether interrupt_sequence is sent
816 to the remote target when gdb connects to it.
817 This is mostly needed when you debug the Linux kernel: The Linux kernel
818 expects BREAK g which is Magic SysRq g for connecting gdb. */
819 static int interrupt_on_connect
= 0;
821 /* This variable is used to implement the "set/show remotebreak" commands.
822 Since these commands are now deprecated in favor of "set/show remote
823 interrupt-sequence", it no longer has any effect on the code. */
824 static int remote_break
;
827 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
830 interrupt_sequence_mode
= interrupt_sequence_break
;
832 interrupt_sequence_mode
= interrupt_sequence_control_c
;
836 show_remotebreak (struct ui_file
*file
, int from_tty
,
837 struct cmd_list_element
*c
,
842 /* This variable sets the number of bits in an address that are to be
843 sent in a memory ("M" or "m") packet. Normally, after stripping
844 leading zeros, the entire address would be sent. This variable
845 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
846 initial implementation of remote.c restricted the address sent in
847 memory packets to ``host::sizeof long'' bytes - (typically 32
848 bits). Consequently, for 64 bit targets, the upper 32 bits of an
849 address was never sent. Since fixing this bug may cause a break in
850 some remote targets this variable is principly provided to
851 facilitate backward compatibility. */
853 static unsigned int remote_address_size
;
855 /* Temporary to track who currently owns the terminal. See
856 remote_terminal_* for more details. */
858 static int remote_async_terminal_ours_p
;
860 /* The executable file to use for "run" on the remote side. */
862 static char *remote_exec_file
= "";
865 /* User configurable variables for the number of characters in a
866 memory read/write packet. MIN (rsa->remote_packet_size,
867 rsa->sizeof_g_packet) is the default. Some targets need smaller
868 values (fifo overruns, et.al.) and some users need larger values
869 (speed up transfers). The variables ``preferred_*'' (the user
870 request), ``current_*'' (what was actually set) and ``forced_*''
871 (Positive - a soft limit, negative - a hard limit). */
873 struct memory_packet_config
880 /* Compute the current size of a read/write packet. Since this makes
881 use of ``actual_register_packet_size'' the computation is dynamic. */
884 get_memory_packet_size (struct memory_packet_config
*config
)
886 struct remote_state
*rs
= get_remote_state ();
887 struct remote_arch_state
*rsa
= get_remote_arch_state ();
889 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
890 law?) that some hosts don't cope very well with large alloca()
891 calls. Eventually the alloca() code will be replaced by calls to
892 xmalloc() and make_cleanups() allowing this restriction to either
893 be lifted or removed. */
894 #ifndef MAX_REMOTE_PACKET_SIZE
895 #define MAX_REMOTE_PACKET_SIZE 16384
897 /* NOTE: 20 ensures we can write at least one byte. */
898 #ifndef MIN_REMOTE_PACKET_SIZE
899 #define MIN_REMOTE_PACKET_SIZE 20
904 if (config
->size
<= 0)
905 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
907 what_they_get
= config
->size
;
911 what_they_get
= get_remote_packet_size ();
912 /* Limit the packet to the size specified by the user. */
914 && what_they_get
> config
->size
)
915 what_they_get
= config
->size
;
917 /* Limit it to the size of the targets ``g'' response unless we have
918 permission from the stub to use a larger packet size. */
919 if (rs
->explicit_packet_size
== 0
920 && rsa
->actual_register_packet_size
> 0
921 && what_they_get
> rsa
->actual_register_packet_size
)
922 what_they_get
= rsa
->actual_register_packet_size
;
924 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
925 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
926 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
927 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
929 /* Make sure there is room in the global buffer for this packet
930 (including its trailing NUL byte). */
931 if (rs
->buf_size
< what_they_get
+ 1)
933 rs
->buf_size
= 2 * what_they_get
;
934 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
937 return what_they_get
;
940 /* Update the size of a read/write packet. If they user wants
941 something really big then do a sanity check. */
944 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
946 int fixed_p
= config
->fixed_p
;
947 long size
= config
->size
;
950 error (_("Argument required (integer, `fixed' or `limited')."));
951 else if (strcmp (args
, "hard") == 0
952 || strcmp (args
, "fixed") == 0)
954 else if (strcmp (args
, "soft") == 0
955 || strcmp (args
, "limit") == 0)
961 size
= strtoul (args
, &end
, 0);
963 error (_("Invalid %s (bad syntax)."), config
->name
);
965 /* Instead of explicitly capping the size of a packet to
966 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
967 instead allowed to set the size to something arbitrarily
969 if (size
> MAX_REMOTE_PACKET_SIZE
)
970 error (_("Invalid %s (too large)."), config
->name
);
974 if (fixed_p
&& !config
->fixed_p
)
976 if (! query (_("The target may not be able to correctly handle a %s\n"
977 "of %ld bytes. Change the packet size? "),
979 error (_("Packet size not changed."));
981 /* Update the config. */
982 config
->fixed_p
= fixed_p
;
987 show_memory_packet_size (struct memory_packet_config
*config
)
989 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
991 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
992 get_memory_packet_size (config
));
994 printf_filtered (_("Packets are limited to %ld bytes.\n"),
995 get_memory_packet_size (config
));
998 static struct memory_packet_config memory_write_packet_config
=
1000 "memory-write-packet-size",
1004 set_memory_write_packet_size (char *args
, int from_tty
)
1006 set_memory_packet_size (args
, &memory_write_packet_config
);
1010 show_memory_write_packet_size (char *args
, int from_tty
)
1012 show_memory_packet_size (&memory_write_packet_config
);
1016 get_memory_write_packet_size (void)
1018 return get_memory_packet_size (&memory_write_packet_config
);
1021 static struct memory_packet_config memory_read_packet_config
=
1023 "memory-read-packet-size",
1027 set_memory_read_packet_size (char *args
, int from_tty
)
1029 set_memory_packet_size (args
, &memory_read_packet_config
);
1033 show_memory_read_packet_size (char *args
, int from_tty
)
1035 show_memory_packet_size (&memory_read_packet_config
);
1039 get_memory_read_packet_size (void)
1041 long size
= get_memory_packet_size (&memory_read_packet_config
);
1043 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1044 extra buffer size argument before the memory read size can be
1045 increased beyond this. */
1046 if (size
> get_remote_packet_size ())
1047 size
= get_remote_packet_size ();
1052 /* Generic configuration support for packets the stub optionally
1053 supports. Allows the user to specify the use of the packet as well
1054 as allowing GDB to auto-detect support in the remote stub. */
1058 PACKET_SUPPORT_UNKNOWN
= 0,
1063 struct packet_config
1068 /* If auto, GDB auto-detects support for this packet or feature,
1069 either through qSupported, or by trying the packet and looking
1070 at the response. If true, GDB assumes the target supports this
1071 packet. If false, the packet is disabled. Configs that don't
1072 have an associated command always have this set to auto. */
1073 enum auto_boolean detect
;
1075 /* Does the target support this packet? */
1076 enum packet_support support
;
1079 /* Analyze a packet's return value and update the packet config
1089 static enum packet_support
packet_config_support (struct packet_config
*config
);
1090 static enum packet_support
packet_support (int packet
);
1093 show_packet_config_cmd (struct packet_config
*config
)
1095 char *support
= "internal-error";
1097 switch (packet_config_support (config
))
1100 support
= "enabled";
1102 case PACKET_DISABLE
:
1103 support
= "disabled";
1105 case PACKET_SUPPORT_UNKNOWN
:
1106 support
= "unknown";
1109 switch (config
->detect
)
1111 case AUTO_BOOLEAN_AUTO
:
1112 printf_filtered (_("Support for the `%s' packet "
1113 "is auto-detected, currently %s.\n"),
1114 config
->name
, support
);
1116 case AUTO_BOOLEAN_TRUE
:
1117 case AUTO_BOOLEAN_FALSE
:
1118 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1119 config
->name
, support
);
1125 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1126 const char *title
, int legacy
)
1132 config
->name
= name
;
1133 config
->title
= title
;
1134 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1136 show_doc
= xstrprintf ("Show current use of remote "
1137 "protocol `%s' (%s) packet",
1139 /* set/show TITLE-packet {auto,on,off} */
1140 cmd_name
= xstrprintf ("%s-packet", title
);
1141 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1142 &config
->detect
, set_doc
,
1143 show_doc
, NULL
, /* help_doc */
1145 show_remote_protocol_packet_cmd
,
1146 &remote_set_cmdlist
, &remote_show_cmdlist
);
1147 /* The command code copies the documentation strings. */
1150 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1155 legacy_name
= xstrprintf ("%s-packet", name
);
1156 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1157 &remote_set_cmdlist
);
1158 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1159 &remote_show_cmdlist
);
1163 static enum packet_result
1164 packet_check_result (const char *buf
)
1168 /* The stub recognized the packet request. Check that the
1169 operation succeeded. */
1171 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1173 /* "Enn" - definitly an error. */
1174 return PACKET_ERROR
;
1176 /* Always treat "E." as an error. This will be used for
1177 more verbose error messages, such as E.memtypes. */
1178 if (buf
[0] == 'E' && buf
[1] == '.')
1179 return PACKET_ERROR
;
1181 /* The packet may or may not be OK. Just assume it is. */
1185 /* The stub does not support the packet. */
1186 return PACKET_UNKNOWN
;
1189 static enum packet_result
1190 packet_ok (const char *buf
, struct packet_config
*config
)
1192 enum packet_result result
;
1194 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1195 && config
->support
== PACKET_DISABLE
)
1196 internal_error (__FILE__
, __LINE__
,
1197 _("packet_ok: attempt to use a disabled packet"));
1199 result
= packet_check_result (buf
);
1204 /* The stub recognized the packet request. */
1205 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1208 fprintf_unfiltered (gdb_stdlog
,
1209 "Packet %s (%s) is supported\n",
1210 config
->name
, config
->title
);
1211 config
->support
= PACKET_ENABLE
;
1214 case PACKET_UNKNOWN
:
1215 /* The stub does not support the packet. */
1216 if (config
->detect
== AUTO_BOOLEAN_AUTO
1217 && config
->support
== PACKET_ENABLE
)
1219 /* If the stub previously indicated that the packet was
1220 supported then there is a protocol error. */
1221 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1222 config
->name
, config
->title
);
1224 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1226 /* The user set it wrong. */
1227 error (_("Enabled packet %s (%s) not recognized by stub"),
1228 config
->name
, config
->title
);
1232 fprintf_unfiltered (gdb_stdlog
,
1233 "Packet %s (%s) is NOT supported\n",
1234 config
->name
, config
->title
);
1235 config
->support
= PACKET_DISABLE
;
1255 PACKET_vFile_pwrite
,
1257 PACKET_vFile_unlink
,
1258 PACKET_vFile_readlink
,
1260 PACKET_qXfer_features
,
1261 PACKET_qXfer_libraries
,
1262 PACKET_qXfer_libraries_svr4
,
1263 PACKET_qXfer_memory_map
,
1264 PACKET_qXfer_spu_read
,
1265 PACKET_qXfer_spu_write
,
1266 PACKET_qXfer_osdata
,
1267 PACKET_qXfer_threads
,
1268 PACKET_qXfer_statictrace_read
,
1269 PACKET_qXfer_traceframe_info
,
1275 PACKET_QPassSignals
,
1276 PACKET_QProgramSignals
,
1278 PACKET_qSearch_memory
,
1281 PACKET_QStartNoAckMode
,
1283 PACKET_qXfer_siginfo_read
,
1284 PACKET_qXfer_siginfo_write
,
1287 /* Support for conditional tracepoints. */
1288 PACKET_ConditionalTracepoints
,
1290 /* Support for target-side breakpoint conditions. */
1291 PACKET_ConditionalBreakpoints
,
1293 /* Support for target-side breakpoint commands. */
1294 PACKET_BreakpointCommands
,
1296 /* Support for fast tracepoints. */
1297 PACKET_FastTracepoints
,
1299 /* Support for static tracepoints. */
1300 PACKET_StaticTracepoints
,
1302 /* Support for installing tracepoints while a trace experiment is
1304 PACKET_InstallInTrace
,
1308 PACKET_TracepointSource
,
1311 PACKET_QDisableRandomization
,
1313 PACKET_QTBuffer_size
,
1316 PACKET_qXfer_btrace
,
1318 /* Support for the QNonStop packet. */
1321 /* Support for multi-process extensions. */
1322 PACKET_multiprocess_feature
,
1324 /* Support for enabling and disabling tracepoints while a trace
1325 experiment is running. */
1326 PACKET_EnableDisableTracepoints_feature
,
1328 /* Support for collecting strings using the tracenz bytecode. */
1329 PACKET_tracenz_feature
,
1331 /* Support for continuing to run a trace experiment while GDB is
1333 PACKET_DisconnectedTracing_feature
,
1335 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1336 PACKET_augmented_libraries_svr4_read_feature
,
1341 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1343 /* Returns whether a given packet or feature is supported. This takes
1344 into account the state of the corresponding "set remote foo-packet"
1345 command, which may be used to bypass auto-detection. */
1347 static enum packet_support
1348 packet_config_support (struct packet_config
*config
)
1350 switch (config
->detect
)
1352 case AUTO_BOOLEAN_TRUE
:
1353 return PACKET_ENABLE
;
1354 case AUTO_BOOLEAN_FALSE
:
1355 return PACKET_DISABLE
;
1356 case AUTO_BOOLEAN_AUTO
:
1357 return config
->support
;
1359 gdb_assert_not_reached (_("bad switch"));
1363 /* Same as packet_config_support, but takes the packet's enum value as
1366 static enum packet_support
1367 packet_support (int packet
)
1369 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1371 return packet_config_support (config
);
1375 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1376 struct cmd_list_element
*c
,
1379 struct packet_config
*packet
;
1381 for (packet
= remote_protocol_packets
;
1382 packet
< &remote_protocol_packets
[PACKET_MAX
];
1385 if (&packet
->detect
== c
->var
)
1387 show_packet_config_cmd (packet
);
1391 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1395 /* Should we try one of the 'Z' requests? */
1399 Z_PACKET_SOFTWARE_BP
,
1400 Z_PACKET_HARDWARE_BP
,
1407 /* For compatibility with older distributions. Provide a ``set remote
1408 Z-packet ...'' command that updates all the Z packet types. */
1410 static enum auto_boolean remote_Z_packet_detect
;
1413 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1414 struct cmd_list_element
*c
)
1418 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1419 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1423 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1424 struct cmd_list_element
*c
,
1429 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1431 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1435 /* Returns true if the multi-process extensions are in effect. */
1438 remote_multi_process_p (struct remote_state
*rs
)
1440 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1443 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1444 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1445 static struct async_signal_handler
*async_sigint_remote_token
;
1448 /* Asynchronous signal handle registered as event loop source for
1449 when we have pending events ready to be passed to the core. */
1451 static struct async_event_handler
*remote_async_inferior_event_token
;
1455 static ptid_t magic_null_ptid
;
1456 static ptid_t not_sent_ptid
;
1457 static ptid_t any_thread_ptid
;
1459 /* Find out if the stub attached to PID (and hence GDB should offer to
1460 detach instead of killing it when bailing out). */
1463 remote_query_attached (int pid
)
1465 struct remote_state
*rs
= get_remote_state ();
1466 size_t size
= get_remote_packet_size ();
1468 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1471 if (remote_multi_process_p (rs
))
1472 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1474 xsnprintf (rs
->buf
, size
, "qAttached");
1477 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1479 switch (packet_ok (rs
->buf
,
1480 &remote_protocol_packets
[PACKET_qAttached
]))
1483 if (strcmp (rs
->buf
, "1") == 0)
1487 warning (_("Remote failure reply: %s"), rs
->buf
);
1489 case PACKET_UNKNOWN
:
1496 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1497 has been invented by GDB, instead of reported by the target. Since
1498 we can be connected to a remote system before before knowing about
1499 any inferior, mark the target with execution when we find the first
1500 inferior. If ATTACHED is 1, then we had just attached to this
1501 inferior. If it is 0, then we just created this inferior. If it
1502 is -1, then try querying the remote stub to find out if it had
1503 attached to the inferior or not. */
1505 static struct inferior
*
1506 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1508 struct inferior
*inf
;
1510 /* Check whether this process we're learning about is to be
1511 considered attached, or if is to be considered to have been
1512 spawned by the stub. */
1514 attached
= remote_query_attached (pid
);
1516 if (gdbarch_has_global_solist (target_gdbarch ()))
1518 /* If the target shares code across all inferiors, then every
1519 attach adds a new inferior. */
1520 inf
= add_inferior (pid
);
1522 /* ... and every inferior is bound to the same program space.
1523 However, each inferior may still have its own address
1525 inf
->aspace
= maybe_new_address_space ();
1526 inf
->pspace
= current_program_space
;
1530 /* In the traditional debugging scenario, there's a 1-1 match
1531 between program/address spaces. We simply bind the inferior
1532 to the program space's address space. */
1533 inf
= current_inferior ();
1534 inferior_appeared (inf
, pid
);
1537 inf
->attach_flag
= attached
;
1538 inf
->fake_pid_p
= fake_pid_p
;
1543 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1544 according to RUNNING. */
1547 remote_add_thread (ptid_t ptid
, int running
)
1549 struct remote_state
*rs
= get_remote_state ();
1551 /* GDB historically didn't pull threads in the initial connection
1552 setup. If the remote target doesn't even have a concept of
1553 threads (e.g., a bare-metal target), even if internally we
1554 consider that a single-threaded target, mentioning a new thread
1555 might be confusing to the user. Be silent then, preserving the
1556 age old behavior. */
1557 if (rs
->starting_up
)
1558 add_thread_silent (ptid
);
1562 set_executing (ptid
, running
);
1563 set_running (ptid
, running
);
1566 /* Come here when we learn about a thread id from the remote target.
1567 It may be the first time we hear about such thread, so take the
1568 opportunity to add it to GDB's thread list. In case this is the
1569 first time we're noticing its corresponding inferior, add it to
1570 GDB's inferior list as well. */
1573 remote_notice_new_inferior (ptid_t currthread
, int running
)
1575 /* If this is a new thread, add it to GDB's thread list.
1576 If we leave it up to WFI to do this, bad things will happen. */
1578 if (in_thread_list (currthread
) && is_exited (currthread
))
1580 /* We're seeing an event on a thread id we knew had exited.
1581 This has to be a new thread reusing the old id. Add it. */
1582 remote_add_thread (currthread
, running
);
1586 if (!in_thread_list (currthread
))
1588 struct inferior
*inf
= NULL
;
1589 int pid
= ptid_get_pid (currthread
);
1591 if (ptid_is_pid (inferior_ptid
)
1592 && pid
== ptid_get_pid (inferior_ptid
))
1594 /* inferior_ptid has no thread member yet. This can happen
1595 with the vAttach -> remote_wait,"TAAthread:" path if the
1596 stub doesn't support qC. This is the first stop reported
1597 after an attach, so this is the main thread. Update the
1598 ptid in the thread list. */
1599 if (in_thread_list (pid_to_ptid (pid
)))
1600 thread_change_ptid (inferior_ptid
, currthread
);
1603 remote_add_thread (currthread
, running
);
1604 inferior_ptid
= currthread
;
1609 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1611 /* inferior_ptid is not set yet. This can happen with the
1612 vRun -> remote_wait,"TAAthread:" path if the stub
1613 doesn't support qC. This is the first stop reported
1614 after an attach, so this is the main thread. Update the
1615 ptid in the thread list. */
1616 thread_change_ptid (inferior_ptid
, currthread
);
1620 /* When connecting to a target remote, or to a target
1621 extended-remote which already was debugging an inferior, we
1622 may not know about it yet. Add it before adding its child
1623 thread, so notifications are emitted in a sensible order. */
1624 if (!in_inferior_list (ptid_get_pid (currthread
)))
1626 struct remote_state
*rs
= get_remote_state ();
1627 int fake_pid_p
= !remote_multi_process_p (rs
);
1629 inf
= remote_add_inferior (fake_pid_p
,
1630 ptid_get_pid (currthread
), -1);
1633 /* This is really a new thread. Add it. */
1634 remote_add_thread (currthread
, running
);
1636 /* If we found a new inferior, let the common code do whatever
1637 it needs to with it (e.g., read shared libraries, insert
1638 breakpoints), unless we're just setting up an all-stop
1642 struct remote_state
*rs
= get_remote_state ();
1644 if (non_stop
|| !rs
->starting_up
)
1645 notice_new_inferior (currthread
, running
, 0);
1650 /* Return the private thread data, creating it if necessary. */
1652 static struct private_thread_info
*
1653 demand_private_info (ptid_t ptid
)
1655 struct thread_info
*info
= find_thread_ptid (ptid
);
1661 info
->private = xmalloc (sizeof (*(info
->private)));
1662 info
->private_dtor
= free_private_thread_info
;
1663 info
->private->core
= -1;
1664 info
->private->extra
= 0;
1667 return info
->private;
1670 /* Call this function as a result of
1671 1) A halt indication (T packet) containing a thread id
1672 2) A direct query of currthread
1673 3) Successful execution of set thread */
1676 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1678 rs
->general_thread
= currthread
;
1681 /* If 'QPassSignals' is supported, tell the remote stub what signals
1682 it can simply pass through to the inferior without reporting. */
1685 remote_pass_signals (struct target_ops
*self
,
1686 int numsigs
, unsigned char *pass_signals
)
1688 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1690 char *pass_packet
, *p
;
1692 struct remote_state
*rs
= get_remote_state ();
1694 gdb_assert (numsigs
< 256);
1695 for (i
= 0; i
< numsigs
; i
++)
1697 if (pass_signals
[i
])
1700 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1701 strcpy (pass_packet
, "QPassSignals:");
1702 p
= pass_packet
+ strlen (pass_packet
);
1703 for (i
= 0; i
< numsigs
; i
++)
1705 if (pass_signals
[i
])
1708 *p
++ = tohex (i
>> 4);
1709 *p
++ = tohex (i
& 15);
1718 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1720 putpkt (pass_packet
);
1721 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1722 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1723 if (rs
->last_pass_packet
)
1724 xfree (rs
->last_pass_packet
);
1725 rs
->last_pass_packet
= pass_packet
;
1728 xfree (pass_packet
);
1732 /* If 'QProgramSignals' is supported, tell the remote stub what
1733 signals it should pass through to the inferior when detaching. */
1736 remote_program_signals (struct target_ops
*self
,
1737 int numsigs
, unsigned char *signals
)
1739 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1743 struct remote_state
*rs
= get_remote_state ();
1745 gdb_assert (numsigs
< 256);
1746 for (i
= 0; i
< numsigs
; i
++)
1751 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1752 strcpy (packet
, "QProgramSignals:");
1753 p
= packet
+ strlen (packet
);
1754 for (i
= 0; i
< numsigs
; i
++)
1756 if (signal_pass_state (i
))
1759 *p
++ = tohex (i
>> 4);
1760 *p
++ = tohex (i
& 15);
1769 if (!rs
->last_program_signals_packet
1770 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1773 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1774 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1775 xfree (rs
->last_program_signals_packet
);
1776 rs
->last_program_signals_packet
= packet
;
1783 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1784 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1785 thread. If GEN is set, set the general thread, if not, then set
1786 the step/continue thread. */
1788 set_thread (struct ptid ptid
, int gen
)
1790 struct remote_state
*rs
= get_remote_state ();
1791 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1792 char *buf
= rs
->buf
;
1793 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1795 if (ptid_equal (state
, ptid
))
1799 *buf
++ = gen
? 'g' : 'c';
1800 if (ptid_equal (ptid
, magic_null_ptid
))
1801 xsnprintf (buf
, endbuf
- buf
, "0");
1802 else if (ptid_equal (ptid
, any_thread_ptid
))
1803 xsnprintf (buf
, endbuf
- buf
, "0");
1804 else if (ptid_equal (ptid
, minus_one_ptid
))
1805 xsnprintf (buf
, endbuf
- buf
, "-1");
1807 write_ptid (buf
, endbuf
, ptid
);
1809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1811 rs
->general_thread
= ptid
;
1813 rs
->continue_thread
= ptid
;
1817 set_general_thread (struct ptid ptid
)
1819 set_thread (ptid
, 1);
1823 set_continue_thread (struct ptid ptid
)
1825 set_thread (ptid
, 0);
1828 /* Change the remote current process. Which thread within the process
1829 ends up selected isn't important, as long as it is the same process
1830 as what INFERIOR_PTID points to.
1832 This comes from that fact that there is no explicit notion of
1833 "selected process" in the protocol. The selected process for
1834 general operations is the process the selected general thread
1838 set_general_process (void)
1840 struct remote_state
*rs
= get_remote_state ();
1842 /* If the remote can't handle multiple processes, don't bother. */
1843 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1846 /* We only need to change the remote current thread if it's pointing
1847 at some other process. */
1848 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1849 set_general_thread (inferior_ptid
);
1853 /* Return nonzero if the thread PTID is still alive on the remote
1857 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1859 struct remote_state
*rs
= get_remote_state ();
1862 if (ptid_equal (ptid
, magic_null_ptid
))
1863 /* The main thread is always alive. */
1866 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1867 /* The main thread is always alive. This can happen after a
1868 vAttach, if the remote side doesn't support
1873 endp
= rs
->buf
+ get_remote_packet_size ();
1876 write_ptid (p
, endp
, ptid
);
1879 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1880 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1883 /* About these extended threadlist and threadinfo packets. They are
1884 variable length packets but, the fields within them are often fixed
1885 length. They are redundent enough to send over UDP as is the
1886 remote protocol in general. There is a matching unit test module
1889 /* WARNING: This threadref data structure comes from the remote O.S.,
1890 libstub protocol encoding, and remote.c. It is not particularly
1893 /* Right now, the internal structure is int. We want it to be bigger.
1894 Plan to fix this. */
1896 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1898 /* gdb_ext_thread_info is an internal GDB data structure which is
1899 equivalent to the reply of the remote threadinfo packet. */
1901 struct gdb_ext_thread_info
1903 threadref threadid
; /* External form of thread reference. */
1904 int active
; /* Has state interesting to GDB?
1906 char display
[256]; /* Brief state display, name,
1907 blocked/suspended. */
1908 char shortname
[32]; /* To be used to name threads. */
1909 char more_display
[256]; /* Long info, statistics, queue depth,
1913 /* The volume of remote transfers can be limited by submitting
1914 a mask containing bits specifying the desired information.
1915 Use a union of these values as the 'selection' parameter to
1916 get_thread_info. FIXME: Make these TAG names more thread specific. */
1918 #define TAG_THREADID 1
1919 #define TAG_EXISTS 2
1920 #define TAG_DISPLAY 4
1921 #define TAG_THREADNAME 8
1922 #define TAG_MOREDISPLAY 16
1924 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1926 static char *unpack_nibble (char *buf
, int *val
);
1928 static char *unpack_byte (char *buf
, int *value
);
1930 static char *pack_int (char *buf
, int value
);
1932 static char *unpack_int (char *buf
, int *value
);
1934 static char *unpack_string (char *src
, char *dest
, int length
);
1936 static char *pack_threadid (char *pkt
, threadref
*id
);
1938 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1940 void int_to_threadref (threadref
*id
, int value
);
1942 static int threadref_to_int (threadref
*ref
);
1944 static void copy_threadref (threadref
*dest
, threadref
*src
);
1946 static int threadmatch (threadref
*dest
, threadref
*src
);
1948 static char *pack_threadinfo_request (char *pkt
, int mode
,
1951 static int remote_unpack_thread_info_response (char *pkt
,
1952 threadref
*expectedref
,
1953 struct gdb_ext_thread_info
1957 static int remote_get_threadinfo (threadref
*threadid
,
1958 int fieldset
, /*TAG mask */
1959 struct gdb_ext_thread_info
*info
);
1961 static char *pack_threadlist_request (char *pkt
, int startflag
,
1963 threadref
*nextthread
);
1965 static int parse_threadlist_response (char *pkt
,
1967 threadref
*original_echo
,
1968 threadref
*resultlist
,
1971 static int remote_get_threadlist (int startflag
,
1972 threadref
*nextthread
,
1976 threadref
*threadlist
);
1978 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1980 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1981 void *context
, int looplimit
);
1983 static int remote_newthread_step (threadref
*ref
, void *context
);
1986 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1987 buffer we're allowed to write to. Returns
1988 BUF+CHARACTERS_WRITTEN. */
1991 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1994 struct remote_state
*rs
= get_remote_state ();
1996 if (remote_multi_process_p (rs
))
1998 pid
= ptid_get_pid (ptid
);
2000 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2002 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2004 tid
= ptid_get_lwp (ptid
);
2006 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2008 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2013 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2014 passed the last parsed char. Returns null_ptid on error. */
2017 read_ptid (char *buf
, char **obuf
)
2021 ULONGEST pid
= 0, tid
= 0;
2025 /* Multi-process ptid. */
2026 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2028 error (_("invalid remote ptid: %s"), p
);
2031 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2034 return ptid_build (pid
, tid
, 0);
2037 /* No multi-process. Just a tid. */
2038 pp
= unpack_varlen_hex (p
, &tid
);
2040 /* Since the stub is not sending a process id, then default to
2041 what's in inferior_ptid, unless it's null at this point. If so,
2042 then since there's no way to know the pid of the reported
2043 threads, use the magic number. */
2044 if (ptid_equal (inferior_ptid
, null_ptid
))
2045 pid
= ptid_get_pid (magic_null_ptid
);
2047 pid
= ptid_get_pid (inferior_ptid
);
2051 return ptid_build (pid
, tid
, 0);
2057 if (ch
>= 'a' && ch
<= 'f')
2058 return ch
- 'a' + 10;
2059 if (ch
>= '0' && ch
<= '9')
2061 if (ch
>= 'A' && ch
<= 'F')
2062 return ch
- 'A' + 10;
2067 stub_unpack_int (char *buff
, int fieldlength
)
2074 nibble
= stubhex (*buff
++);
2078 retval
= retval
<< 4;
2084 unpack_nibble (char *buf
, int *val
)
2086 *val
= fromhex (*buf
++);
2091 unpack_byte (char *buf
, int *value
)
2093 *value
= stub_unpack_int (buf
, 2);
2098 pack_int (char *buf
, int value
)
2100 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2101 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2102 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2103 buf
= pack_hex_byte (buf
, (value
& 0xff));
2108 unpack_int (char *buf
, int *value
)
2110 *value
= stub_unpack_int (buf
, 8);
2114 #if 0 /* Currently unused, uncomment when needed. */
2115 static char *pack_string (char *pkt
, char *string
);
2118 pack_string (char *pkt
, char *string
)
2123 len
= strlen (string
);
2125 len
= 200; /* Bigger than most GDB packets, junk??? */
2126 pkt
= pack_hex_byte (pkt
, len
);
2130 if ((ch
== '\0') || (ch
== '#'))
2131 ch
= '*'; /* Protect encapsulation. */
2136 #endif /* 0 (unused) */
2139 unpack_string (char *src
, char *dest
, int length
)
2148 pack_threadid (char *pkt
, threadref
*id
)
2151 unsigned char *altid
;
2153 altid
= (unsigned char *) id
;
2154 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2156 pkt
= pack_hex_byte (pkt
, *altid
++);
2162 unpack_threadid (char *inbuf
, threadref
*id
)
2165 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2168 altref
= (char *) id
;
2170 while (inbuf
< limit
)
2172 x
= stubhex (*inbuf
++);
2173 y
= stubhex (*inbuf
++);
2174 *altref
++ = (x
<< 4) | y
;
2179 /* Externally, threadrefs are 64 bits but internally, they are still
2180 ints. This is due to a mismatch of specifications. We would like
2181 to use 64bit thread references internally. This is an adapter
2185 int_to_threadref (threadref
*id
, int value
)
2187 unsigned char *scan
;
2189 scan
= (unsigned char *) id
;
2195 *scan
++ = (value
>> 24) & 0xff;
2196 *scan
++ = (value
>> 16) & 0xff;
2197 *scan
++ = (value
>> 8) & 0xff;
2198 *scan
++ = (value
& 0xff);
2202 threadref_to_int (threadref
*ref
)
2205 unsigned char *scan
;
2211 value
= (value
<< 8) | ((*scan
++) & 0xff);
2216 copy_threadref (threadref
*dest
, threadref
*src
)
2219 unsigned char *csrc
, *cdest
;
2221 csrc
= (unsigned char *) src
;
2222 cdest
= (unsigned char *) dest
;
2229 threadmatch (threadref
*dest
, threadref
*src
)
2231 /* Things are broken right now, so just assume we got a match. */
2233 unsigned char *srcp
, *destp
;
2235 srcp
= (char *) src
;
2236 destp
= (char *) dest
;
2240 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2247 threadid:1, # always request threadid
2254 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2257 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2259 *pkt
++ = 'q'; /* Info Query */
2260 *pkt
++ = 'P'; /* process or thread info */
2261 pkt
= pack_int (pkt
, mode
); /* mode */
2262 pkt
= pack_threadid (pkt
, id
); /* threadid */
2263 *pkt
= '\0'; /* terminate */
2267 /* These values tag the fields in a thread info response packet. */
2268 /* Tagging the fields allows us to request specific fields and to
2269 add more fields as time goes by. */
2271 #define TAG_THREADID 1 /* Echo the thread identifier. */
2272 #define TAG_EXISTS 2 /* Is this process defined enough to
2273 fetch registers and its stack? */
2274 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2275 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2276 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2280 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2281 struct gdb_ext_thread_info
*info
)
2283 struct remote_state
*rs
= get_remote_state ();
2287 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2290 /* info->threadid = 0; FIXME: implement zero_threadref. */
2292 info
->display
[0] = '\0';
2293 info
->shortname
[0] = '\0';
2294 info
->more_display
[0] = '\0';
2296 /* Assume the characters indicating the packet type have been
2298 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2299 pkt
= unpack_threadid (pkt
, &ref
);
2302 warning (_("Incomplete response to threadinfo request."));
2303 if (!threadmatch (&ref
, expectedref
))
2304 { /* This is an answer to a different request. */
2305 warning (_("ERROR RMT Thread info mismatch."));
2308 copy_threadref (&info
->threadid
, &ref
);
2310 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2312 /* Packets are terminated with nulls. */
2313 while ((pkt
< limit
) && mask
&& *pkt
)
2315 pkt
= unpack_int (pkt
, &tag
); /* tag */
2316 pkt
= unpack_byte (pkt
, &length
); /* length */
2317 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2319 warning (_("ERROR RMT: threadinfo tag mismatch."));
2323 if (tag
== TAG_THREADID
)
2327 warning (_("ERROR RMT: length of threadid is not 16."));
2331 pkt
= unpack_threadid (pkt
, &ref
);
2332 mask
= mask
& ~TAG_THREADID
;
2335 if (tag
== TAG_EXISTS
)
2337 info
->active
= stub_unpack_int (pkt
, length
);
2339 mask
= mask
& ~(TAG_EXISTS
);
2342 warning (_("ERROR RMT: 'exists' length too long."));
2348 if (tag
== TAG_THREADNAME
)
2350 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2351 mask
= mask
& ~TAG_THREADNAME
;
2354 if (tag
== TAG_DISPLAY
)
2356 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2357 mask
= mask
& ~TAG_DISPLAY
;
2360 if (tag
== TAG_MOREDISPLAY
)
2362 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2363 mask
= mask
& ~TAG_MOREDISPLAY
;
2366 warning (_("ERROR RMT: unknown thread info tag."));
2367 break; /* Not a tag we know about. */
2373 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2374 struct gdb_ext_thread_info
*info
)
2376 struct remote_state
*rs
= get_remote_state ();
2379 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2381 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2383 if (rs
->buf
[0] == '\0')
2386 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2391 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2394 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2395 threadref
*nextthread
)
2397 *pkt
++ = 'q'; /* info query packet */
2398 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2399 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2400 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2401 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2406 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2409 parse_threadlist_response (char *pkt
, int result_limit
,
2410 threadref
*original_echo
, threadref
*resultlist
,
2413 struct remote_state
*rs
= get_remote_state ();
2415 int count
, resultcount
, done
;
2418 /* Assume the 'q' and 'M chars have been stripped. */
2419 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2420 /* done parse past here */
2421 pkt
= unpack_byte (pkt
, &count
); /* count field */
2422 pkt
= unpack_nibble (pkt
, &done
);
2423 /* The first threadid is the argument threadid. */
2424 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2425 while ((count
-- > 0) && (pkt
< limit
))
2427 pkt
= unpack_threadid (pkt
, resultlist
++);
2428 if (resultcount
++ >= result_limit
)
2437 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2438 int *done
, int *result_count
, threadref
*threadlist
)
2440 struct remote_state
*rs
= get_remote_state ();
2443 /* Trancate result limit to be smaller than the packet size. */
2444 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2445 >= get_remote_packet_size ())
2446 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2448 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2450 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2452 if (*rs
->buf
== '\0')
2456 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2457 &rs
->echo_nextthread
, threadlist
, done
);
2459 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2461 /* FIXME: This is a good reason to drop the packet. */
2462 /* Possably, there is a duplicate response. */
2464 retransmit immediatly - race conditions
2465 retransmit after timeout - yes
2467 wait for packet, then exit
2469 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2470 return 0; /* I choose simply exiting. */
2472 if (*result_count
<= 0)
2476 warning (_("RMT ERROR : failed to get remote thread list."));
2479 return result
; /* break; */
2481 if (*result_count
> result_limit
)
2484 warning (_("RMT ERROR: threadlist response longer than requested."));
2490 /* This is the interface between remote and threads, remotes upper
2493 /* remote_find_new_threads retrieves the thread list and for each
2494 thread in the list, looks up the thread in GDB's internal list,
2495 adding the thread if it does not already exist. This involves
2496 getting partial thread lists from the remote target so, polling the
2497 quit_flag is required. */
2501 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2504 struct remote_state
*rs
= get_remote_state ();
2505 int done
, i
, result_count
;
2513 if (loopcount
++ > looplimit
)
2516 warning (_("Remote fetch threadlist -infinite loop-."));
2519 if (!remote_get_threadlist (startflag
, &rs
->nextthread
,
2520 MAXTHREADLISTRESULTS
,
2521 &done
, &result_count
, rs
->resultthreadlist
))
2526 /* Clear for later iterations. */
2528 /* Setup to resume next batch of thread references, set nextthread. */
2529 if (result_count
>= 1)
2530 copy_threadref (&rs
->nextthread
,
2531 &rs
->resultthreadlist
[result_count
- 1]);
2533 while (result_count
--)
2534 if (!(result
= (*stepfunction
) (&rs
->resultthreadlist
[i
++], context
)))
2541 remote_newthread_step (threadref
*ref
, void *context
)
2543 int pid
= ptid_get_pid (inferior_ptid
);
2544 ptid_t ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2546 if (!in_thread_list (ptid
))
2548 return 1; /* continue iterator */
2551 #define CRAZY_MAX_THREADS 1000
2554 remote_current_thread (ptid_t oldpid
)
2556 struct remote_state
*rs
= get_remote_state ();
2559 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2560 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2561 return read_ptid (&rs
->buf
[2], NULL
);
2566 /* Find new threads for info threads command.
2567 * Original version, using John Metzler's thread protocol.
2571 remote_find_new_threads (void)
2573 remote_threadlist_iterator (remote_newthread_step
, 0,
2577 #if defined(HAVE_LIBEXPAT)
2579 typedef struct thread_item
2585 DEF_VEC_O(thread_item_t
);
2587 struct threads_parsing_context
2589 VEC (thread_item_t
) *items
;
2593 start_thread (struct gdb_xml_parser
*parser
,
2594 const struct gdb_xml_element
*element
,
2595 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2597 struct threads_parsing_context
*data
= user_data
;
2599 struct thread_item item
;
2601 struct gdb_xml_value
*attr
;
2603 id
= xml_find_attribute (attributes
, "id")->value
;
2604 item
.ptid
= read_ptid (id
, NULL
);
2606 attr
= xml_find_attribute (attributes
, "core");
2608 item
.core
= *(ULONGEST
*) attr
->value
;
2614 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2618 end_thread (struct gdb_xml_parser
*parser
,
2619 const struct gdb_xml_element
*element
,
2620 void *user_data
, const char *body_text
)
2622 struct threads_parsing_context
*data
= user_data
;
2624 if (body_text
&& *body_text
)
2625 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2628 const struct gdb_xml_attribute thread_attributes
[] = {
2629 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2630 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2631 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2634 const struct gdb_xml_element thread_children
[] = {
2635 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2638 const struct gdb_xml_element threads_children
[] = {
2639 { "thread", thread_attributes
, thread_children
,
2640 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2641 start_thread
, end_thread
},
2642 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2645 const struct gdb_xml_element threads_elements
[] = {
2646 { "threads", NULL
, threads_children
,
2647 GDB_XML_EF_NONE
, NULL
, NULL
},
2648 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2651 /* Discard the contents of the constructed thread info context. */
2654 clear_threads_parsing_context (void *p
)
2656 struct threads_parsing_context
*context
= p
;
2658 struct thread_item
*item
;
2660 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2661 xfree (item
->extra
);
2663 VEC_free (thread_item_t
, context
->items
);
2669 * Find all threads for info threads command.
2670 * Uses new thread protocol contributed by Cisco.
2671 * Falls back and attempts to use the older method (above)
2672 * if the target doesn't respond to the new method.
2676 remote_threads_info (struct target_ops
*ops
)
2678 struct remote_state
*rs
= get_remote_state ();
2682 if (rs
->remote_desc
== 0) /* paranoia */
2683 error (_("Command can only be used when connected to the remote target."));
2685 #if defined(HAVE_LIBEXPAT)
2686 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2688 char *xml
= target_read_stralloc (¤t_target
,
2689 TARGET_OBJECT_THREADS
, NULL
);
2691 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2695 struct threads_parsing_context context
;
2697 context
.items
= NULL
;
2698 make_cleanup (clear_threads_parsing_context
, &context
);
2700 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2701 threads_elements
, xml
, &context
) == 0)
2704 struct thread_item
*item
;
2707 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2710 if (!ptid_equal (item
->ptid
, null_ptid
))
2712 struct private_thread_info
*info
;
2713 /* In non-stop mode, we assume new found threads
2714 are running until proven otherwise with a
2715 stop reply. In all-stop, we can only get
2716 here if all threads are stopped. */
2717 int running
= non_stop
? 1 : 0;
2719 remote_notice_new_inferior (item
->ptid
, running
);
2721 info
= demand_private_info (item
->ptid
);
2722 info
->core
= item
->core
;
2723 info
->extra
= item
->extra
;
2730 do_cleanups (back_to
);
2735 if (rs
->use_threadinfo_query
)
2737 putpkt ("qfThreadInfo");
2738 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2740 if (bufp
[0] != '\0') /* q packet recognized */
2742 struct cleanup
*old_chain
;
2745 /* remote_notice_new_inferior (in the loop below) may make
2746 new RSP calls, which clobber rs->buf. Work with a
2748 bufp
= saved_reply
= xstrdup (rs
->buf
);
2749 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2751 while (*bufp
++ == 'm') /* reply contains one or more TID */
2755 new_thread
= read_ptid (bufp
, &bufp
);
2756 if (!ptid_equal (new_thread
, null_ptid
))
2758 /* In non-stop mode, we assume new found threads
2759 are running until proven otherwise with a
2760 stop reply. In all-stop, we can only get
2761 here if all threads are stopped. */
2762 int running
= non_stop
? 1 : 0;
2764 remote_notice_new_inferior (new_thread
, running
);
2767 while (*bufp
++ == ','); /* comma-separated list */
2768 free_current_contents (&saved_reply
);
2769 putpkt ("qsThreadInfo");
2770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2771 bufp
= saved_reply
= xstrdup (rs
->buf
);
2773 do_cleanups (old_chain
);
2778 /* Only qfThreadInfo is supported in non-stop mode. */
2782 /* Else fall back to old method based on jmetzler protocol. */
2783 rs
->use_threadinfo_query
= 0;
2784 remote_find_new_threads ();
2789 * Collect a descriptive string about the given thread.
2790 * The target may say anything it wants to about the thread
2791 * (typically info about its blocked / runnable state, name, etc.).
2792 * This string will appear in the info threads display.
2794 * Optional: targets are not required to implement this function.
2798 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
2800 struct remote_state
*rs
= get_remote_state ();
2804 struct gdb_ext_thread_info threadinfo
;
2805 static char display_buf
[100]; /* arbitrary... */
2806 int n
= 0; /* position in display_buf */
2808 if (rs
->remote_desc
== 0) /* paranoia */
2809 internal_error (__FILE__
, __LINE__
,
2810 _("remote_threads_extra_info"));
2812 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2813 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
2814 /* This is the main thread which was added by GDB. The remote
2815 server doesn't know about it. */
2818 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2820 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2822 if (info
&& info
->private)
2823 return info
->private->extra
;
2828 if (rs
->use_threadextra_query
)
2831 char *endb
= rs
->buf
+ get_remote_packet_size ();
2833 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2835 write_ptid (b
, endb
, tp
->ptid
);
2838 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2839 if (rs
->buf
[0] != 0)
2841 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2842 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2843 display_buf
[result
] = '\0';
2848 /* If the above query fails, fall back to the old method. */
2849 rs
->use_threadextra_query
= 0;
2850 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2851 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2852 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
2853 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2854 if (threadinfo
.active
)
2856 if (*threadinfo
.shortname
)
2857 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2858 " Name: %s,", threadinfo
.shortname
);
2859 if (*threadinfo
.display
)
2860 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2861 " State: %s,", threadinfo
.display
);
2862 if (*threadinfo
.more_display
)
2863 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2864 " Priority: %s", threadinfo
.more_display
);
2868 /* For purely cosmetic reasons, clear up trailing commas. */
2869 if (',' == display_buf
[n
-1])
2870 display_buf
[n
-1] = ' ';
2879 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
2880 struct static_tracepoint_marker
*marker
)
2882 struct remote_state
*rs
= get_remote_state ();
2885 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2887 p
+= hexnumstr (p
, addr
);
2889 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2893 error (_("Remote failure reply: %s"), p
);
2897 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2904 static VEC(static_tracepoint_marker_p
) *
2905 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
2908 struct remote_state
*rs
= get_remote_state ();
2909 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2910 struct static_tracepoint_marker
*marker
= NULL
;
2911 struct cleanup
*old_chain
;
2914 /* Ask for a first packet of static tracepoint marker
2917 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2920 error (_("Remote failure reply: %s"), p
);
2922 old_chain
= make_cleanup (free_current_marker
, &marker
);
2927 marker
= XCNEW (struct static_tracepoint_marker
);
2931 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2933 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2935 VEC_safe_push (static_tracepoint_marker_p
,
2941 release_static_tracepoint_marker (marker
);
2942 memset (marker
, 0, sizeof (*marker
));
2945 while (*p
++ == ','); /* comma-separated list */
2946 /* Ask for another packet of static tracepoint definition. */
2948 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2952 do_cleanups (old_chain
);
2957 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2960 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
2962 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
2966 /* Restart the remote side; this is an extended protocol operation. */
2969 extended_remote_restart (void)
2971 struct remote_state
*rs
= get_remote_state ();
2973 /* Send the restart command; for reasons I don't understand the
2974 remote side really expects a number after the "R". */
2975 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2978 remote_fileio_reset ();
2981 /* Clean up connection to a remote debugger. */
2984 remote_close (struct target_ops
*self
)
2986 struct remote_state
*rs
= get_remote_state ();
2988 if (rs
->remote_desc
== NULL
)
2989 return; /* already closed */
2991 /* Make sure we leave stdin registered in the event loop, and we
2992 don't leave the async SIGINT signal handler installed. */
2993 remote_terminal_ours (self
);
2995 serial_close (rs
->remote_desc
);
2996 rs
->remote_desc
= NULL
;
2998 /* We don't have a connection to the remote stub anymore. Get rid
2999 of all the inferiors and their threads we were controlling.
3000 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3001 will be unable to find the thread corresponding to (pid, 0, 0). */
3002 inferior_ptid
= null_ptid
;
3003 discard_all_inferiors ();
3005 /* We are closing the remote target, so we should discard
3006 everything of this target. */
3007 discard_pending_stop_replies_in_queue (rs
);
3009 if (remote_async_inferior_event_token
)
3010 delete_async_event_handler (&remote_async_inferior_event_token
);
3012 remote_notif_state_xfree (rs
->notif_state
);
3014 trace_reset_local_state ();
3017 /* Query the remote side for the text, data and bss offsets. */
3022 struct remote_state
*rs
= get_remote_state ();
3025 int lose
, num_segments
= 0, do_sections
, do_segments
;
3026 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3027 struct section_offsets
*offs
;
3028 struct symfile_segment_data
*data
;
3030 if (symfile_objfile
== NULL
)
3033 putpkt ("qOffsets");
3034 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3037 if (buf
[0] == '\000')
3038 return; /* Return silently. Stub doesn't support
3042 warning (_("Remote failure reply: %s"), buf
);
3046 /* Pick up each field in turn. This used to be done with scanf, but
3047 scanf will make trouble if CORE_ADDR size doesn't match
3048 conversion directives correctly. The following code will work
3049 with any size of CORE_ADDR. */
3050 text_addr
= data_addr
= bss_addr
= 0;
3054 if (strncmp (ptr
, "Text=", 5) == 0)
3057 /* Don't use strtol, could lose on big values. */
3058 while (*ptr
&& *ptr
!= ';')
3059 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3061 if (strncmp (ptr
, ";Data=", 6) == 0)
3064 while (*ptr
&& *ptr
!= ';')
3065 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3070 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3073 while (*ptr
&& *ptr
!= ';')
3074 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3076 if (bss_addr
!= data_addr
)
3077 warning (_("Target reported unsupported offsets: %s"), buf
);
3082 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3085 /* Don't use strtol, could lose on big values. */
3086 while (*ptr
&& *ptr
!= ';')
3087 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3090 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3093 while (*ptr
&& *ptr
!= ';')
3094 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3102 error (_("Malformed response to offset query, %s"), buf
);
3103 else if (*ptr
!= '\0')
3104 warning (_("Target reported unsupported offsets: %s"), buf
);
3106 offs
= ((struct section_offsets
*)
3107 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3108 memcpy (offs
, symfile_objfile
->section_offsets
,
3109 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3111 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3112 do_segments
= (data
!= NULL
);
3113 do_sections
= num_segments
== 0;
3115 if (num_segments
> 0)
3117 segments
[0] = text_addr
;
3118 segments
[1] = data_addr
;
3120 /* If we have two segments, we can still try to relocate everything
3121 by assuming that the .text and .data offsets apply to the whole
3122 text and data segments. Convert the offsets given in the packet
3123 to base addresses for symfile_map_offsets_to_segments. */
3124 else if (data
&& data
->num_segments
== 2)
3126 segments
[0] = data
->segment_bases
[0] + text_addr
;
3127 segments
[1] = data
->segment_bases
[1] + data_addr
;
3130 /* If the object file has only one segment, assume that it is text
3131 rather than data; main programs with no writable data are rare,
3132 but programs with no code are useless. Of course the code might
3133 have ended up in the data segment... to detect that we would need
3134 the permissions here. */
3135 else if (data
&& data
->num_segments
== 1)
3137 segments
[0] = data
->segment_bases
[0] + text_addr
;
3140 /* There's no way to relocate by segment. */
3146 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3147 offs
, num_segments
, segments
);
3149 if (ret
== 0 && !do_sections
)
3150 error (_("Can not handle qOffsets TextSeg "
3151 "response with this symbol file"));
3158 free_symfile_segment_data (data
);
3162 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3164 /* This is a temporary kludge to force data and bss to use the
3165 same offsets because that's what nlmconv does now. The real
3166 solution requires changes to the stub and remote.c that I
3167 don't have time to do right now. */
3169 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3170 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3173 objfile_relocate (symfile_objfile
, offs
);
3176 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3177 threads we know are stopped already. This is used during the
3178 initial remote connection in non-stop mode --- threads that are
3179 reported as already being stopped are left stopped. */
3182 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3184 /* If we have a stop reply for this thread, it must be stopped. */
3185 if (peek_stop_reply (thread
->ptid
))
3186 set_stop_requested (thread
->ptid
, 1);
3191 /* Send interrupt_sequence to remote target. */
3193 send_interrupt_sequence (void)
3195 struct remote_state
*rs
= get_remote_state ();
3197 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3198 remote_serial_write ("\x03", 1);
3199 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3200 serial_send_break (rs
->remote_desc
);
3201 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3203 serial_send_break (rs
->remote_desc
);
3204 remote_serial_write ("g", 1);
3207 internal_error (__FILE__
, __LINE__
,
3208 _("Invalid value for interrupt_sequence_mode: %s."),
3209 interrupt_sequence_mode
);
3213 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3214 and extract the PTID. Returns NULL_PTID if not found. */
3217 stop_reply_extract_thread (char *stop_reply
)
3219 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3223 /* Txx r:val ; r:val (...) */
3226 /* Look for "register" named "thread". */
3231 p1
= strchr (p
, ':');
3235 if (strncmp (p
, "thread", p1
- p
) == 0)
3236 return read_ptid (++p1
, &p
);
3238 p1
= strchr (p
, ';');
3250 /* Determine the remote side's current thread. If we have a stop
3251 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3252 "thread" register we can extract the current thread from. If not,
3253 ask the remote which is the current thread with qC. The former
3254 method avoids a roundtrip. */
3257 get_current_thread (char *wait_status
)
3261 /* Note we don't use remote_parse_stop_reply as that makes use of
3262 the target architecture, which we haven't yet fully determined at
3264 if (wait_status
!= NULL
)
3265 ptid
= stop_reply_extract_thread (wait_status
);
3266 if (ptid_equal (ptid
, null_ptid
))
3267 ptid
= remote_current_thread (inferior_ptid
);
3272 /* Query the remote target for which is the current thread/process,
3273 add it to our tables, and update INFERIOR_PTID. The caller is
3274 responsible for setting the state such that the remote end is ready
3275 to return the current thread.
3277 This function is called after handling the '?' or 'vRun' packets,
3278 whose response is a stop reply from which we can also try
3279 extracting the thread. If the target doesn't support the explicit
3280 qC query, we infer the current thread from that stop reply, passed
3281 in in WAIT_STATUS, which may be NULL. */
3284 add_current_inferior_and_thread (char *wait_status
)
3286 struct remote_state
*rs
= get_remote_state ();
3288 ptid_t ptid
= null_ptid
;
3290 inferior_ptid
= null_ptid
;
3292 /* Now, if we have thread information, update inferior_ptid. */
3293 ptid
= get_current_thread (wait_status
);
3295 if (!ptid_equal (ptid
, null_ptid
))
3297 if (!remote_multi_process_p (rs
))
3300 inferior_ptid
= ptid
;
3304 /* Without this, some commands which require an active target
3305 (such as kill) won't work. This variable serves (at least)
3306 double duty as both the pid of the target process (if it has
3307 such), and as a flag indicating that a target is active. */
3308 inferior_ptid
= magic_null_ptid
;
3312 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3314 /* Add the main thread. */
3315 add_thread_silent (inferior_ptid
);
3319 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3321 struct remote_state
*rs
= get_remote_state ();
3322 struct packet_config
*noack_config
;
3323 char *wait_status
= NULL
;
3325 immediate_quit
++; /* Allow user to interrupt it. */
3328 if (interrupt_on_connect
)
3329 send_interrupt_sequence ();
3331 /* Ack any packet which the remote side has already sent. */
3332 serial_write (rs
->remote_desc
, "+", 1);
3334 /* Signal other parts that we're going through the initial setup,
3335 and so things may not be stable yet. */
3336 rs
->starting_up
= 1;
3338 /* The first packet we send to the target is the optional "supported
3339 packets" request. If the target can answer this, it will tell us
3340 which later probes to skip. */
3341 remote_query_supported ();
3343 /* If the stub wants to get a QAllow, compose one and send it. */
3344 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3345 remote_set_permissions (target
);
3347 /* Next, we possibly activate noack mode.
3349 If the QStartNoAckMode packet configuration is set to AUTO,
3350 enable noack mode if the stub reported a wish for it with
3353 If set to TRUE, then enable noack mode even if the stub didn't
3354 report it in qSupported. If the stub doesn't reply OK, the
3355 session ends with an error.
3357 If FALSE, then don't activate noack mode, regardless of what the
3358 stub claimed should be the default with qSupported. */
3360 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3361 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3363 putpkt ("QStartNoAckMode");
3364 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3365 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3371 /* Tell the remote that we are using the extended protocol. */
3373 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3376 /* Let the target know which signals it is allowed to pass down to
3378 update_signals_program_target ();
3380 /* Next, if the target can specify a description, read it. We do
3381 this before anything involving memory or registers. */
3382 target_find_description ();
3384 /* Next, now that we know something about the target, update the
3385 address spaces in the program spaces. */
3386 update_address_spaces ();
3388 /* On OSs where the list of libraries is global to all
3389 processes, we fetch them early. */
3390 if (gdbarch_has_global_solist (target_gdbarch ()))
3391 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3395 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3396 error (_("Non-stop mode requested, but remote "
3397 "does not support non-stop"));
3399 putpkt ("QNonStop:1");
3400 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3402 if (strcmp (rs
->buf
, "OK") != 0)
3403 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3405 /* Find about threads and processes the stub is already
3406 controlling. We default to adding them in the running state.
3407 The '?' query below will then tell us about which threads are
3409 remote_threads_info (target
);
3411 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3413 /* Don't assume that the stub can operate in all-stop mode.
3414 Request it explicitly. */
3415 putpkt ("QNonStop:0");
3416 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3418 if (strcmp (rs
->buf
, "OK") != 0)
3419 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3422 /* Upload TSVs regardless of whether the target is running or not. The
3423 remote stub, such as GDBserver, may have some predefined or builtin
3424 TSVs, even if the target is not running. */
3425 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3427 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3429 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3430 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3433 /* Check whether the target is running now. */
3435 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3441 struct inferior
*inf
;
3443 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3446 error (_("The target is not running (try extended-remote?)"));
3448 /* We're connected, but not running. Drop out before we
3449 call start_remote. */
3450 rs
->starting_up
= 0;
3455 /* Save the reply for later. */
3456 wait_status
= alloca (strlen (rs
->buf
) + 1);
3457 strcpy (wait_status
, rs
->buf
);
3460 /* Fetch thread list. */
3461 target_find_new_threads ();
3463 /* Let the stub know that we want it to return the thread. */
3464 set_continue_thread (minus_one_ptid
);
3466 if (thread_count () == 0)
3468 /* Target has no concept of threads at all. GDB treats
3469 non-threaded target as single-threaded; add a main
3471 add_current_inferior_and_thread (wait_status
);
3475 /* We have thread information; select the thread the target
3476 says should be current. If we're reconnecting to a
3477 multi-threaded program, this will ideally be the thread
3478 that last reported an event before GDB disconnected. */
3479 inferior_ptid
= get_current_thread (wait_status
);
3480 if (ptid_equal (inferior_ptid
, null_ptid
))
3482 /* Odd... The target was able to list threads, but not
3483 tell us which thread was current (no "thread"
3484 register in T stop reply?). Just pick the first
3485 thread in the thread list then. */
3486 inferior_ptid
= thread_list
->ptid
;
3490 /* init_wait_for_inferior should be called before get_offsets in order
3491 to manage `inserted' flag in bp loc in a correct state.
3492 breakpoint_init_inferior, called from init_wait_for_inferior, set
3493 `inserted' flag to 0, while before breakpoint_re_set, called from
3494 start_remote, set `inserted' flag to 1. In the initialization of
3495 inferior, breakpoint_init_inferior should be called first, and then
3496 breakpoint_re_set can be called. If this order is broken, state of
3497 `inserted' flag is wrong, and cause some problems on breakpoint
3499 init_wait_for_inferior ();
3501 get_offsets (); /* Get text, data & bss offsets. */
3503 /* If we could not find a description using qXfer, and we know
3504 how to do it some other way, try again. This is not
3505 supported for non-stop; it could be, but it is tricky if
3506 there are no stopped threads when we connect. */
3507 if (remote_read_description_p (target
)
3508 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3510 target_clear_description ();
3511 target_find_description ();
3514 /* Use the previously fetched status. */
3515 gdb_assert (wait_status
!= NULL
);
3516 strcpy (rs
->buf
, wait_status
);
3517 rs
->cached_wait_status
= 1;
3520 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3524 /* Clear WFI global state. Do this before finding about new
3525 threads and inferiors, and setting the current inferior.
3526 Otherwise we would clear the proceed status of the current
3527 inferior when we want its stop_soon state to be preserved
3528 (see notice_new_inferior). */
3529 init_wait_for_inferior ();
3531 /* In non-stop, we will either get an "OK", meaning that there
3532 are no stopped threads at this time; or, a regular stop
3533 reply. In the latter case, there may be more than one thread
3534 stopped --- we pull them all out using the vStopped
3536 if (strcmp (rs
->buf
, "OK") != 0)
3538 struct notif_client
*notif
= ¬if_client_stop
;
3540 /* remote_notif_get_pending_replies acks this one, and gets
3542 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3543 = remote_notif_parse (notif
, rs
->buf
);
3544 remote_notif_get_pending_events (notif
);
3546 /* Make sure that threads that were stopped remain
3548 iterate_over_threads (set_stop_requested_callback
, NULL
);
3551 if (target_can_async_p ())
3552 target_async (inferior_event_handler
, 0);
3554 if (thread_count () == 0)
3557 error (_("The target is not running (try extended-remote?)"));
3559 /* We're connected, but not running. Drop out before we
3560 call start_remote. */
3561 rs
->starting_up
= 0;
3565 /* Let the stub know that we want it to return the thread. */
3567 /* Force the stub to choose a thread. */
3568 set_general_thread (null_ptid
);
3571 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3572 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3573 error (_("remote didn't report the current thread in non-stop mode"));
3575 get_offsets (); /* Get text, data & bss offsets. */
3577 /* In non-stop mode, any cached wait status will be stored in
3578 the stop reply queue. */
3579 gdb_assert (wait_status
== NULL
);
3581 /* Report all signals during attach/startup. */
3582 remote_pass_signals (target
, 0, NULL
);
3585 /* If we connected to a live target, do some additional setup. */
3586 if (target_has_execution
)
3588 if (symfile_objfile
) /* No use without a symbol-file. */
3589 remote_check_symbols ();
3592 /* Possibly the target has been engaged in a trace run started
3593 previously; find out where things are at. */
3594 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3596 struct uploaded_tp
*uploaded_tps
= NULL
;
3598 if (current_trace_status ()->running
)
3599 printf_filtered (_("Trace is already running on the target.\n"));
3601 remote_upload_tracepoints (target
, &uploaded_tps
);
3603 merge_uploaded_tracepoints (&uploaded_tps
);
3606 /* The thread and inferior lists are now synchronized with the
3607 target, our symbols have been relocated, and we're merged the
3608 target's tracepoints with ours. We're done with basic start
3610 rs
->starting_up
= 0;
3612 /* If breakpoints are global, insert them now. */
3613 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3614 && breakpoints_always_inserted_mode ())
3615 insert_breakpoints ();
3618 /* Open a connection to a remote debugger.
3619 NAME is the filename used for communication. */
3622 remote_open (char *name
, int from_tty
)
3624 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3627 /* Open a connection to a remote debugger using the extended
3628 remote gdb protocol. NAME is the filename used for communication. */
3631 extended_remote_open (char *name
, int from_tty
)
3633 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3636 /* Reset all packets back to "unknown support". Called when opening a
3637 new connection to a remote target. */
3640 reset_all_packet_configs_support (void)
3644 for (i
= 0; i
< PACKET_MAX
; i
++)
3645 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3648 /* Initialize all packet configs. */
3651 init_all_packet_configs (void)
3655 for (i
= 0; i
< PACKET_MAX
; i
++)
3657 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3658 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3662 /* Symbol look-up. */
3665 remote_check_symbols (void)
3667 struct remote_state
*rs
= get_remote_state ();
3668 char *msg
, *reply
, *tmp
;
3669 struct bound_minimal_symbol sym
;
3672 /* The remote side has no concept of inferiors that aren't running
3673 yet, it only knows about running processes. If we're connected
3674 but our current inferior is not running, we should not invite the
3675 remote target to request symbol lookups related to its
3676 (unrelated) current process. */
3677 if (!target_has_execution
)
3680 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3683 /* Make sure the remote is pointing at the right process. Note
3684 there's no way to select "no process". */
3685 set_general_process ();
3687 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3688 because we need both at the same time. */
3689 msg
= alloca (get_remote_packet_size ());
3691 /* Invite target to request symbol lookups. */
3693 putpkt ("qSymbol::");
3694 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3695 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3698 while (strncmp (reply
, "qSymbol:", 8) == 0)
3700 struct bound_minimal_symbol sym
;
3703 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3705 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3706 if (sym
.minsym
== NULL
)
3707 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3710 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3711 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3713 /* If this is a function address, return the start of code
3714 instead of any data function descriptor. */
3715 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3719 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3720 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3724 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3729 static struct serial
*
3730 remote_serial_open (const char *name
)
3732 static int udp_warning
= 0;
3734 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3735 of in ser-tcp.c, because it is the remote protocol assuming that the
3736 serial connection is reliable and not the serial connection promising
3738 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3740 warning (_("The remote protocol may be unreliable over UDP.\n"
3741 "Some events may be lost, rendering further debugging "
3746 return serial_open (name
);
3749 /* Inform the target of our permission settings. The permission flags
3750 work without this, but if the target knows the settings, it can do
3751 a couple things. First, it can add its own check, to catch cases
3752 that somehow manage to get by the permissions checks in target
3753 methods. Second, if the target is wired to disallow particular
3754 settings (for instance, a system in the field that is not set up to
3755 be able to stop at a breakpoint), it can object to any unavailable
3759 remote_set_permissions (struct target_ops
*self
)
3761 struct remote_state
*rs
= get_remote_state ();
3763 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3764 "WriteReg:%x;WriteMem:%x;"
3765 "InsertBreak:%x;InsertTrace:%x;"
3766 "InsertFastTrace:%x;Stop:%x",
3767 may_write_registers
, may_write_memory
,
3768 may_insert_breakpoints
, may_insert_tracepoints
,
3769 may_insert_fast_tracepoints
, may_stop
);
3771 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3773 /* If the target didn't like the packet, warn the user. Do not try
3774 to undo the user's settings, that would just be maddening. */
3775 if (strcmp (rs
->buf
, "OK") != 0)
3776 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3779 /* This type describes each known response to the qSupported
3781 struct protocol_feature
3783 /* The name of this protocol feature. */
3786 /* The default for this protocol feature. */
3787 enum packet_support default_support
;
3789 /* The function to call when this feature is reported, or after
3790 qSupported processing if the feature is not supported.
3791 The first argument points to this structure. The second
3792 argument indicates whether the packet requested support be
3793 enabled, disabled, or probed (or the default, if this function
3794 is being called at the end of processing and this feature was
3795 not reported). The third argument may be NULL; if not NULL, it
3796 is a NUL-terminated string taken from the packet following
3797 this feature's name and an equals sign. */
3798 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3801 /* The corresponding packet for this feature. Only used if
3802 FUNC is remote_supported_packet. */
3807 remote_supported_packet (const struct protocol_feature
*feature
,
3808 enum packet_support support
,
3809 const char *argument
)
3813 warning (_("Remote qSupported response supplied an unexpected value for"
3814 " \"%s\"."), feature
->name
);
3818 remote_protocol_packets
[feature
->packet
].support
= support
;
3822 remote_packet_size (const struct protocol_feature
*feature
,
3823 enum packet_support support
, const char *value
)
3825 struct remote_state
*rs
= get_remote_state ();
3830 if (support
!= PACKET_ENABLE
)
3833 if (value
== NULL
|| *value
== '\0')
3835 warning (_("Remote target reported \"%s\" without a size."),
3841 packet_size
= strtol (value
, &value_end
, 16);
3842 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3844 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3845 feature
->name
, value
);
3849 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3851 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3852 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3853 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3856 /* Record the new maximum packet size. */
3857 rs
->explicit_packet_size
= packet_size
;
3860 static const struct protocol_feature remote_protocol_features
[] = {
3861 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3862 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3863 PACKET_qXfer_auxv
},
3864 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3865 PACKET_qXfer_features
},
3866 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3867 PACKET_qXfer_libraries
},
3868 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3869 PACKET_qXfer_libraries_svr4
},
3870 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
3871 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
3872 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3873 PACKET_qXfer_memory_map
},
3874 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3875 PACKET_qXfer_spu_read
},
3876 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3877 PACKET_qXfer_spu_write
},
3878 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3879 PACKET_qXfer_osdata
},
3880 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3881 PACKET_qXfer_threads
},
3882 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3883 PACKET_qXfer_traceframe_info
},
3884 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3885 PACKET_QPassSignals
},
3886 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3887 PACKET_QProgramSignals
},
3888 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3889 PACKET_QStartNoAckMode
},
3890 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
3891 PACKET_multiprocess_feature
},
3892 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
3893 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3894 PACKET_qXfer_siginfo_read
},
3895 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3896 PACKET_qXfer_siginfo_write
},
3897 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
3898 PACKET_ConditionalTracepoints
},
3899 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
3900 PACKET_ConditionalBreakpoints
},
3901 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
3902 PACKET_BreakpointCommands
},
3903 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
3904 PACKET_FastTracepoints
},
3905 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
3906 PACKET_StaticTracepoints
},
3907 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
3908 PACKET_InstallInTrace
},
3909 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
3910 PACKET_DisconnectedTracing_feature
},
3911 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3913 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3915 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3916 PACKET_TracepointSource
},
3917 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3919 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
3920 PACKET_EnableDisableTracepoints_feature
},
3921 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3922 PACKET_qXfer_fdpic
},
3923 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3925 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3926 PACKET_QDisableRandomization
},
3927 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3928 { "QTBuffer:size", PACKET_DISABLE
,
3929 remote_supported_packet
, PACKET_QTBuffer_size
},
3930 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
3931 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
3932 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
3933 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
3934 PACKET_qXfer_btrace
}
3937 static char *remote_support_xml
;
3939 /* Register string appended to "xmlRegisters=" in qSupported query. */
3942 register_remote_support_xml (const char *xml
)
3944 #if defined(HAVE_LIBEXPAT)
3945 if (remote_support_xml
== NULL
)
3946 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3949 char *copy
= xstrdup (remote_support_xml
+ 13);
3950 char *p
= strtok (copy
, ",");
3954 if (strcmp (p
, xml
) == 0)
3961 while ((p
= strtok (NULL
, ",")) != NULL
);
3964 remote_support_xml
= reconcat (remote_support_xml
,
3965 remote_support_xml
, ",", xml
,
3972 remote_query_supported_append (char *msg
, const char *append
)
3975 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3977 return xstrdup (append
);
3981 remote_query_supported (void)
3983 struct remote_state
*rs
= get_remote_state ();
3986 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3988 /* The packet support flags are handled differently for this packet
3989 than for most others. We treat an error, a disabled packet, and
3990 an empty response identically: any features which must be reported
3991 to be used will be automatically disabled. An empty buffer
3992 accomplishes this, since that is also the representation for a list
3993 containing no features. */
3996 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
3999 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4001 q
= remote_query_supported_append (q
, "multiprocess+");
4003 if (remote_support_xml
)
4004 q
= remote_query_supported_append (q
, remote_support_xml
);
4006 q
= remote_query_supported_append (q
, "qRelocInsn+");
4008 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4011 do_cleanups (old_chain
);
4013 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4015 /* If an error occured, warn, but do not return - just reset the
4016 buffer to empty and go on to disable features. */
4017 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4020 warning (_("Remote failure reply: %s"), rs
->buf
);
4025 memset (seen
, 0, sizeof (seen
));
4030 enum packet_support is_supported
;
4031 char *p
, *end
, *name_end
, *value
;
4033 /* First separate out this item from the rest of the packet. If
4034 there's another item after this, we overwrite the separator
4035 (terminated strings are much easier to work with). */
4037 end
= strchr (p
, ';');
4040 end
= p
+ strlen (p
);
4050 warning (_("empty item in \"qSupported\" response"));
4055 name_end
= strchr (p
, '=');
4058 /* This is a name=value entry. */
4059 is_supported
= PACKET_ENABLE
;
4060 value
= name_end
+ 1;
4069 is_supported
= PACKET_ENABLE
;
4073 is_supported
= PACKET_DISABLE
;
4077 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4081 warning (_("unrecognized item \"%s\" "
4082 "in \"qSupported\" response"), p
);
4088 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4089 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4091 const struct protocol_feature
*feature
;
4094 feature
= &remote_protocol_features
[i
];
4095 feature
->func (feature
, is_supported
, value
);
4100 /* If we increased the packet size, make sure to increase the global
4101 buffer size also. We delay this until after parsing the entire
4102 qSupported packet, because this is the same buffer we were
4104 if (rs
->buf_size
< rs
->explicit_packet_size
)
4106 rs
->buf_size
= rs
->explicit_packet_size
;
4107 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4110 /* Handle the defaults for unmentioned features. */
4111 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4114 const struct protocol_feature
*feature
;
4116 feature
= &remote_protocol_features
[i
];
4117 feature
->func (feature
, feature
->default_support
, NULL
);
4121 /* Remove any of the remote.c targets from target stack. Upper targets depend
4122 on it so remove them first. */
4125 remote_unpush_target (void)
4127 pop_all_targets_above (process_stratum
- 1);
4131 remote_open_1 (char *name
, int from_tty
,
4132 struct target_ops
*target
, int extended_p
)
4134 struct remote_state
*rs
= get_remote_state ();
4137 error (_("To open a remote debug connection, you need to specify what\n"
4138 "serial device is attached to the remote system\n"
4139 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4141 /* See FIXME above. */
4142 if (!target_async_permitted
)
4143 wait_forever_enabled_p
= 1;
4145 /* If we're connected to a running target, target_preopen will kill it.
4146 Ask this question first, before target_preopen has a chance to kill
4148 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4151 && !query (_("Already connected to a remote target. Disconnect? ")))
4152 error (_("Still connected."));
4155 /* Here the possibly existing remote target gets unpushed. */
4156 target_preopen (from_tty
);
4158 /* Make sure we send the passed signals list the next time we resume. */
4159 xfree (rs
->last_pass_packet
);
4160 rs
->last_pass_packet
= NULL
;
4162 /* Make sure we send the program signals list the next time we
4164 xfree (rs
->last_program_signals_packet
);
4165 rs
->last_program_signals_packet
= NULL
;
4167 remote_fileio_reset ();
4168 reopen_exec_file ();
4171 rs
->remote_desc
= remote_serial_open (name
);
4172 if (!rs
->remote_desc
)
4173 perror_with_name (name
);
4175 if (baud_rate
!= -1)
4177 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4179 /* The requested speed could not be set. Error out to
4180 top level after closing remote_desc. Take care to
4181 set remote_desc to NULL to avoid closing remote_desc
4183 serial_close (rs
->remote_desc
);
4184 rs
->remote_desc
= NULL
;
4185 perror_with_name (name
);
4189 serial_raw (rs
->remote_desc
);
4191 /* If there is something sitting in the buffer we might take it as a
4192 response to a command, which would be bad. */
4193 serial_flush_input (rs
->remote_desc
);
4197 puts_filtered ("Remote debugging using ");
4198 puts_filtered (name
);
4199 puts_filtered ("\n");
4201 push_target (target
); /* Switch to using remote target now. */
4203 /* Register extra event sources in the event loop. */
4204 remote_async_inferior_event_token
4205 = create_async_event_handler (remote_async_inferior_event_handler
,
4207 rs
->notif_state
= remote_notif_state_allocate ();
4209 /* Reset the target state; these things will be queried either by
4210 remote_query_supported or as they are needed. */
4211 reset_all_packet_configs_support ();
4212 rs
->cached_wait_status
= 0;
4213 rs
->explicit_packet_size
= 0;
4215 rs
->extended
= extended_p
;
4216 rs
->waiting_for_stop_reply
= 0;
4217 rs
->ctrlc_pending_p
= 0;
4219 rs
->general_thread
= not_sent_ptid
;
4220 rs
->continue_thread
= not_sent_ptid
;
4221 rs
->remote_traceframe_number
= -1;
4223 /* Probe for ability to use "ThreadInfo" query, as required. */
4224 rs
->use_threadinfo_query
= 1;
4225 rs
->use_threadextra_query
= 1;
4227 if (target_async_permitted
)
4229 /* With this target we start out by owning the terminal. */
4230 remote_async_terminal_ours_p
= 1;
4232 /* FIXME: cagney/1999-09-23: During the initial connection it is
4233 assumed that the target is already ready and able to respond to
4234 requests. Unfortunately remote_start_remote() eventually calls
4235 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4236 around this. Eventually a mechanism that allows
4237 wait_for_inferior() to expect/get timeouts will be
4239 wait_forever_enabled_p
= 0;
4242 /* First delete any symbols previously loaded from shared libraries. */
4243 no_shared_libraries (NULL
, 0);
4246 init_thread_list ();
4248 /* Start the remote connection. If error() or QUIT, discard this
4249 target (we'd otherwise be in an inconsistent state) and then
4250 propogate the error on up the exception chain. This ensures that
4251 the caller doesn't stumble along blindly assuming that the
4252 function succeeded. The CLI doesn't have this problem but other
4253 UI's, such as MI do.
4255 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4256 this function should return an error indication letting the
4257 caller restore the previous state. Unfortunately the command
4258 ``target remote'' is directly wired to this function making that
4259 impossible. On a positive note, the CLI side of this problem has
4260 been fixed - the function set_cmd_context() makes it possible for
4261 all the ``target ....'' commands to share a common callback
4262 function. See cli-dump.c. */
4264 volatile struct gdb_exception ex
;
4266 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4268 remote_start_remote (from_tty
, target
, extended_p
);
4272 /* Pop the partially set up target - unless something else did
4273 already before throwing the exception. */
4274 if (rs
->remote_desc
!= NULL
)
4275 remote_unpush_target ();
4276 if (target_async_permitted
)
4277 wait_forever_enabled_p
= 1;
4278 throw_exception (ex
);
4282 if (target_async_permitted
)
4283 wait_forever_enabled_p
= 1;
4286 /* This takes a program previously attached to and detaches it. After
4287 this is done, GDB can be used to debug some other program. We
4288 better not have left any breakpoints in the target program or it'll
4289 die when it hits one. */
4292 remote_detach_1 (const char *args
, int from_tty
, int extended
)
4294 int pid
= ptid_get_pid (inferior_ptid
);
4295 struct remote_state
*rs
= get_remote_state ();
4298 error (_("Argument given to \"detach\" when remotely debugging."));
4300 if (!target_has_execution
)
4301 error (_("No process to detach from."));
4305 char *exec_file
= get_exec_file (0);
4306 if (exec_file
== NULL
)
4308 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4309 target_pid_to_str (pid_to_ptid (pid
)));
4310 gdb_flush (gdb_stdout
);
4313 /* Tell the remote target to detach. */
4314 if (remote_multi_process_p (rs
))
4315 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4317 strcpy (rs
->buf
, "D");
4320 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4322 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4324 else if (rs
->buf
[0] == '\0')
4325 error (_("Remote doesn't know how to detach"));
4327 error (_("Can't detach process."));
4329 if (from_tty
&& !extended
)
4330 puts_filtered (_("Ending remote debugging.\n"));
4332 target_mourn_inferior ();
4336 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4338 remote_detach_1 (args
, from_tty
, 0);
4342 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4344 remote_detach_1 (args
, from_tty
, 1);
4347 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4350 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4353 error (_("Argument given to \"disconnect\" when remotely debugging."));
4355 /* Make sure we unpush even the extended remote targets; mourn
4356 won't do it. So call remote_mourn_1 directly instead of
4357 target_mourn_inferior. */
4358 remote_mourn_1 (target
);
4361 puts_filtered ("Ending remote debugging.\n");
4364 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4365 be chatty about it. */
4368 extended_remote_attach_1 (struct target_ops
*target
, const char *args
,
4371 struct remote_state
*rs
= get_remote_state ();
4373 char *wait_status
= NULL
;
4375 pid
= parse_pid_to_attach (args
);
4377 /* Remote PID can be freely equal to getpid, do not check it here the same
4378 way as in other targets. */
4380 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4381 error (_("This target does not support attaching to a process"));
4385 char *exec_file
= get_exec_file (0);
4388 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4389 target_pid_to_str (pid_to_ptid (pid
)));
4391 printf_unfiltered (_("Attaching to %s\n"),
4392 target_pid_to_str (pid_to_ptid (pid
)));
4394 gdb_flush (gdb_stdout
);
4397 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4399 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4401 switch (packet_ok (rs
->buf
,
4402 &remote_protocol_packets
[PACKET_vAttach
]))
4407 /* Save the reply for later. */
4408 wait_status
= alloca (strlen (rs
->buf
) + 1);
4409 strcpy (wait_status
, rs
->buf
);
4411 else if (strcmp (rs
->buf
, "OK") != 0)
4412 error (_("Attaching to %s failed with: %s"),
4413 target_pid_to_str (pid_to_ptid (pid
)),
4416 case PACKET_UNKNOWN
:
4417 error (_("This target does not support attaching to a process"));
4419 error (_("Attaching to %s failed"),
4420 target_pid_to_str (pid_to_ptid (pid
)));
4423 set_current_inferior (remote_add_inferior (0, pid
, 1));
4425 inferior_ptid
= pid_to_ptid (pid
);
4429 struct thread_info
*thread
;
4431 /* Get list of threads. */
4432 remote_threads_info (target
);
4434 thread
= first_thread_of_process (pid
);
4436 inferior_ptid
= thread
->ptid
;
4438 inferior_ptid
= pid_to_ptid (pid
);
4440 /* Invalidate our notion of the remote current thread. */
4441 record_currthread (rs
, minus_one_ptid
);
4445 /* Now, if we have thread information, update inferior_ptid. */
4446 inferior_ptid
= remote_current_thread (inferior_ptid
);
4448 /* Add the main thread to the thread list. */
4449 add_thread_silent (inferior_ptid
);
4452 /* Next, if the target can specify a description, read it. We do
4453 this before anything involving memory or registers. */
4454 target_find_description ();
4458 /* Use the previously fetched status. */
4459 gdb_assert (wait_status
!= NULL
);
4461 if (target_can_async_p ())
4463 struct notif_event
*reply
4464 = remote_notif_parse (¬if_client_stop
, wait_status
);
4466 push_stop_reply ((struct stop_reply
*) reply
);
4468 target_async (inferior_event_handler
, 0);
4472 gdb_assert (wait_status
!= NULL
);
4473 strcpy (rs
->buf
, wait_status
);
4474 rs
->cached_wait_status
= 1;
4478 gdb_assert (wait_status
== NULL
);
4482 extended_remote_attach (struct target_ops
*ops
, const char *args
, int from_tty
)
4484 extended_remote_attach_1 (ops
, args
, from_tty
);
4487 /* Implementation of the to_post_attach method. */
4490 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4492 /* In certain cases GDB might not have had the chance to start
4493 symbol lookup up until now. This could happen if the debugged
4494 binary is not using shared libraries, the vsyscall page is not
4495 present (on Linux) and the binary itself hadn't changed since the
4496 debugging process was started. */
4497 if (symfile_objfile
!= NULL
)
4498 remote_check_symbols();
4502 /* Check for the availability of vCont. This function should also check
4506 remote_vcont_probe (struct remote_state
*rs
)
4510 strcpy (rs
->buf
, "vCont?");
4512 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4515 /* Make sure that the features we assume are supported. */
4516 if (strncmp (buf
, "vCont", 5) == 0)
4519 int support_s
, support_S
, support_c
, support_C
;
4525 rs
->supports_vCont
.t
= 0;
4526 rs
->supports_vCont
.r
= 0;
4527 while (p
&& *p
== ';')
4530 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4532 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4534 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4536 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4538 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4539 rs
->supports_vCont
.t
= 1;
4540 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4541 rs
->supports_vCont
.r
= 1;
4543 p
= strchr (p
, ';');
4546 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4547 BUF will make packet_ok disable the packet. */
4548 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4552 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4555 /* Helper function for building "vCont" resumptions. Write a
4556 resumption to P. ENDP points to one-passed-the-end of the buffer
4557 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4558 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4559 resumed thread should be single-stepped and/or signalled. If PTID
4560 equals minus_one_ptid, then all threads are resumed; if PTID
4561 represents a process, then all threads of the process are resumed;
4562 the thread to be stepped and/or signalled is given in the global
4566 append_resumption (char *p
, char *endp
,
4567 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4569 struct remote_state
*rs
= get_remote_state ();
4571 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4572 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4574 /* GDB is willing to range step. */
4575 && use_range_stepping
4576 /* Target supports range stepping. */
4577 && rs
->supports_vCont
.r
4578 /* We don't currently support range stepping multiple
4579 threads with a wildcard (though the protocol allows it,
4580 so stubs shouldn't make an active effort to forbid
4582 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4584 struct thread_info
*tp
;
4586 if (ptid_equal (ptid
, minus_one_ptid
))
4588 /* If we don't know about the target thread's tid, then
4589 we're resuming magic_null_ptid (see caller). */
4590 tp
= find_thread_ptid (magic_null_ptid
);
4593 tp
= find_thread_ptid (ptid
);
4594 gdb_assert (tp
!= NULL
);
4596 if (tp
->control
.may_range_step
)
4598 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4600 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4601 phex_nz (tp
->control
.step_range_start
,
4603 phex_nz (tp
->control
.step_range_end
,
4607 p
+= xsnprintf (p
, endp
- p
, ";s");
4610 p
+= xsnprintf (p
, endp
- p
, ";s");
4611 else if (siggnal
!= GDB_SIGNAL_0
)
4612 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4614 p
+= xsnprintf (p
, endp
- p
, ";c");
4616 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4620 /* All (-1) threads of process. */
4621 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4623 p
+= xsnprintf (p
, endp
- p
, ":");
4624 p
= write_ptid (p
, endp
, nptid
);
4626 else if (!ptid_equal (ptid
, minus_one_ptid
))
4628 p
+= xsnprintf (p
, endp
- p
, ":");
4629 p
= write_ptid (p
, endp
, ptid
);
4635 /* Append a vCont continue-with-signal action for threads that have a
4636 non-zero stop signal. */
4639 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4641 struct thread_info
*thread
;
4643 ALL_NON_EXITED_THREADS (thread
)
4644 if (ptid_match (thread
->ptid
, ptid
)
4645 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4646 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4648 p
= append_resumption (p
, endp
, thread
->ptid
,
4649 0, thread
->suspend
.stop_signal
);
4650 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4656 /* Resume the remote inferior by using a "vCont" packet. The thread
4657 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4658 resumed thread should be single-stepped and/or signalled. If PTID
4659 equals minus_one_ptid, then all threads are resumed; the thread to
4660 be stepped and/or signalled is given in the global INFERIOR_PTID.
4661 This function returns non-zero iff it resumes the inferior.
4663 This function issues a strict subset of all possible vCont commands at the
4667 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4669 struct remote_state
*rs
= get_remote_state ();
4673 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
4674 remote_vcont_probe (rs
);
4676 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
4680 endp
= rs
->buf
+ get_remote_packet_size ();
4682 /* If we could generate a wider range of packets, we'd have to worry
4683 about overflowing BUF. Should there be a generic
4684 "multi-part-packet" packet? */
4686 p
+= xsnprintf (p
, endp
- p
, "vCont");
4688 if (ptid_equal (ptid
, magic_null_ptid
))
4690 /* MAGIC_NULL_PTID means that we don't have any active threads,
4691 so we don't have any TID numbers the inferior will
4692 understand. Make sure to only send forms that do not specify
4694 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4696 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4698 /* Resume all threads (of all processes, or of a single
4699 process), with preference for INFERIOR_PTID. This assumes
4700 inferior_ptid belongs to the set of all threads we are about
4702 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4704 /* Step inferior_ptid, with or without signal. */
4705 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4708 /* Also pass down any pending signaled resumption for other
4709 threads not the current. */
4710 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4712 /* And continue others without a signal. */
4713 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4717 /* Scheduler locking; resume only PTID. */
4718 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4721 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4726 /* In non-stop, the stub replies to vCont with "OK". The stop
4727 reply will be reported asynchronously by means of a `%Stop'
4729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4730 if (strcmp (rs
->buf
, "OK") != 0)
4731 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4737 /* Tell the remote machine to resume. */
4740 remote_resume (struct target_ops
*ops
,
4741 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4743 struct remote_state
*rs
= get_remote_state ();
4746 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4747 (explained in remote-notif.c:handle_notification) so
4748 remote_notif_process is not called. We need find a place where
4749 it is safe to start a 'vNotif' sequence. It is good to do it
4750 before resuming inferior, because inferior was stopped and no RSP
4751 traffic at that moment. */
4753 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
4755 rs
->last_sent_signal
= siggnal
;
4756 rs
->last_sent_step
= step
;
4758 /* The vCont packet doesn't need to specify threads via Hc. */
4759 /* No reverse support (yet) for vCont. */
4760 if (execution_direction
!= EXEC_REVERSE
)
4761 if (remote_vcont_resume (ptid
, step
, siggnal
))
4764 /* All other supported resume packets do use Hc, so set the continue
4766 if (ptid_equal (ptid
, minus_one_ptid
))
4767 set_continue_thread (any_thread_ptid
);
4769 set_continue_thread (ptid
);
4772 if (execution_direction
== EXEC_REVERSE
)
4774 /* We don't pass signals to the target in reverse exec mode. */
4775 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4776 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4779 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
4780 error (_("Remote reverse-step not supported."));
4781 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
4782 error (_("Remote reverse-continue not supported."));
4784 strcpy (buf
, step
? "bs" : "bc");
4786 else if (siggnal
!= GDB_SIGNAL_0
)
4788 buf
[0] = step
? 'S' : 'C';
4789 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4790 buf
[2] = tohex (((int) siggnal
) & 0xf);
4794 strcpy (buf
, step
? "s" : "c");
4799 /* We are about to start executing the inferior, let's register it
4800 with the event loop. NOTE: this is the one place where all the
4801 execution commands end up. We could alternatively do this in each
4802 of the execution commands in infcmd.c. */
4803 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4804 into infcmd.c in order to allow inferior function calls to work
4805 NOT asynchronously. */
4806 if (target_can_async_p ())
4807 target_async (inferior_event_handler
, 0);
4809 /* We've just told the target to resume. The remote server will
4810 wait for the inferior to stop, and then send a stop reply. In
4811 the mean time, we can't start another command/query ourselves
4812 because the stub wouldn't be ready to process it. This applies
4813 only to the base all-stop protocol, however. In non-stop (which
4814 only supports vCont), the stub replies with an "OK", and is
4815 immediate able to process further serial input. */
4817 rs
->waiting_for_stop_reply
= 1;
4821 /* Set up the signal handler for SIGINT, while the target is
4822 executing, ovewriting the 'regular' SIGINT signal handler. */
4824 async_initialize_sigint_signal_handler (void)
4826 signal (SIGINT
, async_handle_remote_sigint
);
4829 /* Signal handler for SIGINT, while the target is executing. */
4831 async_handle_remote_sigint (int sig
)
4833 signal (sig
, async_handle_remote_sigint_twice
);
4834 /* Note we need to go through gdb_call_async_signal_handler in order
4835 to wake up the event loop on Windows. */
4836 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
4839 /* Signal handler for SIGINT, installed after SIGINT has already been
4840 sent once. It will take effect the second time that the user sends
4843 async_handle_remote_sigint_twice (int sig
)
4845 signal (sig
, async_handle_remote_sigint
);
4846 /* See note in async_handle_remote_sigint. */
4847 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
4850 /* Perform the real interruption of the target execution, in response
4853 async_remote_interrupt (gdb_client_data arg
)
4856 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4858 target_stop (inferior_ptid
);
4861 /* Perform interrupt, if the first attempt did not succeed. Just give
4862 up on the target alltogether. */
4864 async_remote_interrupt_twice (gdb_client_data arg
)
4867 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4872 /* Reinstall the usual SIGINT handlers, after the target has
4875 async_cleanup_sigint_signal_handler (void *dummy
)
4877 signal (SIGINT
, handle_sigint
);
4880 /* Send ^C to target to halt it. Target will respond, and send us a
4882 static void (*ofunc
) (int);
4884 /* The command line interface's stop routine. This function is installed
4885 as a signal handler for SIGINT. The first time a user requests a
4886 stop, we call remote_stop to send a break or ^C. If there is no
4887 response from the target (it didn't stop when the user requested it),
4888 we ask the user if he'd like to detach from the target. */
4890 sync_remote_interrupt (int signo
)
4892 /* If this doesn't work, try more severe steps. */
4893 signal (signo
, sync_remote_interrupt_twice
);
4895 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
4898 /* The user typed ^C twice. */
4901 sync_remote_interrupt_twice (int signo
)
4903 signal (signo
, ofunc
);
4904 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
4905 signal (signo
, sync_remote_interrupt
);
4908 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4909 thread, all threads of a remote process, or all threads of all
4913 remote_stop_ns (ptid_t ptid
)
4915 struct remote_state
*rs
= get_remote_state ();
4917 char *endp
= rs
->buf
+ get_remote_packet_size ();
4919 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
4920 remote_vcont_probe (rs
);
4922 if (!rs
->supports_vCont
.t
)
4923 error (_("Remote server does not support stopping threads"));
4925 if (ptid_equal (ptid
, minus_one_ptid
)
4926 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4927 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4932 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4934 if (ptid_is_pid (ptid
))
4935 /* All (-1) threads of process. */
4936 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4939 /* Small optimization: if we already have a stop reply for
4940 this thread, no use in telling the stub we want this
4942 if (peek_stop_reply (ptid
))
4948 write_ptid (p
, endp
, nptid
);
4951 /* In non-stop, we get an immediate OK reply. The stop reply will
4952 come in asynchronously by notification. */
4954 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4955 if (strcmp (rs
->buf
, "OK") != 0)
4956 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4959 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4960 remote target. It is undefined which thread of which process
4961 reports the stop. */
4964 remote_stop_as (ptid_t ptid
)
4966 struct remote_state
*rs
= get_remote_state ();
4968 rs
->ctrlc_pending_p
= 1;
4970 /* If the inferior is stopped already, but the core didn't know
4971 about it yet, just ignore the request. The cached wait status
4972 will be collected in remote_wait. */
4973 if (rs
->cached_wait_status
)
4976 /* Send interrupt_sequence to remote target. */
4977 send_interrupt_sequence ();
4980 /* This is the generic stop called via the target vector. When a target
4981 interrupt is requested, either by the command line or the GUI, we
4982 will eventually end up here. */
4985 remote_stop (struct target_ops
*self
, ptid_t ptid
)
4988 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4991 remote_stop_ns (ptid
);
4993 remote_stop_as (ptid
);
4996 /* Ask the user what to do when an interrupt is received. */
4999 interrupt_query (void)
5001 target_terminal_ours ();
5003 if (target_can_async_p ())
5005 signal (SIGINT
, handle_sigint
);
5010 if (query (_("Interrupted while waiting for the program.\n\
5011 Give up (and stop debugging it)? ")))
5013 remote_unpush_target ();
5018 target_terminal_inferior ();
5021 /* Enable/disable target terminal ownership. Most targets can use
5022 terminal groups to control terminal ownership. Remote targets are
5023 different in that explicit transfer of ownership to/from GDB/target
5027 remote_terminal_inferior (struct target_ops
*self
)
5029 if (!target_async_permitted
)
5030 /* Nothing to do. */
5033 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5034 idempotent. The event-loop GDB talking to an asynchronous target
5035 with a synchronous command calls this function from both
5036 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5037 transfer the terminal to the target when it shouldn't this guard
5039 if (!remote_async_terminal_ours_p
)
5041 delete_file_handler (input_fd
);
5042 remote_async_terminal_ours_p
= 0;
5043 async_initialize_sigint_signal_handler ();
5044 /* NOTE: At this point we could also register our selves as the
5045 recipient of all input. Any characters typed could then be
5046 passed on down to the target. */
5050 remote_terminal_ours (struct target_ops
*self
)
5052 if (!target_async_permitted
)
5053 /* Nothing to do. */
5056 /* See FIXME in remote_terminal_inferior. */
5057 if (remote_async_terminal_ours_p
)
5059 async_cleanup_sigint_signal_handler (NULL
);
5060 add_file_handler (input_fd
, stdin_event_handler
, 0);
5061 remote_async_terminal_ours_p
= 1;
5065 remote_console_output (char *msg
)
5069 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5072 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5076 fputs_unfiltered (tb
, gdb_stdtarg
);
5078 gdb_flush (gdb_stdtarg
);
5081 typedef struct cached_reg
5084 gdb_byte data
[MAX_REGISTER_SIZE
];
5087 DEF_VEC_O(cached_reg_t
);
5089 typedef struct stop_reply
5091 struct notif_event base
;
5093 /* The identifier of the thread about this event */
5096 /* The remote state this event is associated with. When the remote
5097 connection, represented by a remote_state object, is closed,
5098 all the associated stop_reply events should be released. */
5099 struct remote_state
*rs
;
5101 struct target_waitstatus ws
;
5103 /* Expedited registers. This makes remote debugging a bit more
5104 efficient for those targets that provide critical registers as
5105 part of their normal status mechanism (as another roundtrip to
5106 fetch them is avoided). */
5107 VEC(cached_reg_t
) *regcache
;
5109 int stopped_by_watchpoint_p
;
5110 CORE_ADDR watch_data_address
;
5115 DECLARE_QUEUE_P (stop_reply_p
);
5116 DEFINE_QUEUE_P (stop_reply_p
);
5117 /* The list of already fetched and acknowledged stop events. This
5118 queue is used for notification Stop, and other notifications
5119 don't need queue for their events, because the notification events
5120 of Stop can't be consumed immediately, so that events should be
5121 queued first, and be consumed by remote_wait_{ns,as} one per
5122 time. Other notifications can consume their events immediately,
5123 so queue is not needed for them. */
5124 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5127 stop_reply_xfree (struct stop_reply
*r
)
5129 notif_event_xfree ((struct notif_event
*) r
);
5133 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5134 struct notif_event
*event
)
5136 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5140 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5141 struct notif_event
*event
)
5143 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5146 putpkt ((char *) self
->ack_command
);
5148 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5149 /* We got an unknown stop reply. */
5150 error (_("Unknown stop reply"));
5152 push_stop_reply (stop_reply
);
5156 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5158 /* We can't get pending events in remote_notif_process for
5159 notification stop, and we have to do this in remote_wait_ns
5160 instead. If we fetch all queued events from stub, remote stub
5161 may exit and we have no chance to process them back in
5163 mark_async_event_handler (remote_async_inferior_event_token
);
5168 stop_reply_dtr (struct notif_event
*event
)
5170 struct stop_reply
*r
= (struct stop_reply
*) event
;
5172 VEC_free (cached_reg_t
, r
->regcache
);
5175 static struct notif_event
*
5176 remote_notif_stop_alloc_reply (void)
5178 struct notif_event
*r
5179 = (struct notif_event
*) XNEW (struct stop_reply
);
5181 r
->dtr
= stop_reply_dtr
;
5186 /* A client of notification Stop. */
5188 struct notif_client notif_client_stop
=
5192 remote_notif_stop_parse
,
5193 remote_notif_stop_ack
,
5194 remote_notif_stop_can_get_pending_events
,
5195 remote_notif_stop_alloc_reply
,
5199 /* A parameter to pass data in and out. */
5201 struct queue_iter_param
5204 struct stop_reply
*output
;
5207 /* Remove stop replies in the queue if its pid is equal to the given
5211 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5212 QUEUE_ITER (stop_reply_p
) *iter
,
5216 struct queue_iter_param
*param
= data
;
5217 struct inferior
*inf
= param
->input
;
5219 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5221 stop_reply_xfree (event
);
5222 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5228 /* Discard all pending stop replies of inferior INF. */
5231 discard_pending_stop_replies (struct inferior
*inf
)
5234 struct queue_iter_param param
;
5235 struct stop_reply
*reply
;
5236 struct remote_state
*rs
= get_remote_state ();
5237 struct remote_notif_state
*rns
= rs
->notif_state
;
5239 /* This function can be notified when an inferior exists. When the
5240 target is not remote, the notification state is NULL. */
5241 if (rs
->remote_desc
== NULL
)
5244 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5246 /* Discard the in-flight notification. */
5247 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5249 stop_reply_xfree (reply
);
5250 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5254 param
.output
= NULL
;
5255 /* Discard the stop replies we have already pulled with
5257 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5258 remove_stop_reply_for_inferior
, ¶m
);
5261 /* If its remote state is equal to the given remote state,
5262 remove EVENT from the stop reply queue. */
5265 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5266 QUEUE_ITER (stop_reply_p
) *iter
,
5270 struct queue_iter_param
*param
= data
;
5271 struct remote_state
*rs
= param
->input
;
5273 if (event
->rs
== rs
)
5275 stop_reply_xfree (event
);
5276 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5282 /* Discard the stop replies for RS in stop_reply_queue. */
5285 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5287 struct queue_iter_param param
;
5290 param
.output
= NULL
;
5291 /* Discard the stop replies we have already pulled with
5293 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5294 remove_stop_reply_of_remote_state
, ¶m
);
5297 /* A parameter to pass data in and out. */
5300 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5301 QUEUE_ITER (stop_reply_p
) *iter
,
5305 struct queue_iter_param
*param
= data
;
5306 ptid_t
*ptid
= param
->input
;
5308 if (ptid_match (event
->ptid
, *ptid
))
5310 param
->output
= event
;
5311 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5318 /* Remove the first reply in 'stop_reply_queue' which matches
5321 static struct stop_reply
*
5322 remote_notif_remove_queued_reply (ptid_t ptid
)
5324 struct queue_iter_param param
;
5326 param
.input
= &ptid
;
5327 param
.output
= NULL
;
5329 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5330 remote_notif_remove_once_on_match
, ¶m
);
5332 fprintf_unfiltered (gdb_stdlog
,
5333 "notif: discard queued event: 'Stop' in %s\n",
5334 target_pid_to_str (ptid
));
5336 return param
.output
;
5339 /* Look for a queued stop reply belonging to PTID. If one is found,
5340 remove it from the queue, and return it. Returns NULL if none is
5341 found. If there are still queued events left to process, tell the
5342 event loop to get back to target_wait soon. */
5344 static struct stop_reply
*
5345 queued_stop_reply (ptid_t ptid
)
5347 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5349 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5350 /* There's still at least an event left. */
5351 mark_async_event_handler (remote_async_inferior_event_token
);
5356 /* Push a fully parsed stop reply in the stop reply queue. Since we
5357 know that we now have at least one queued event left to pass to the
5358 core side, tell the event loop to get back to target_wait soon. */
5361 push_stop_reply (struct stop_reply
*new_event
)
5363 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5366 fprintf_unfiltered (gdb_stdlog
,
5367 "notif: push 'Stop' %s to queue %d\n",
5368 target_pid_to_str (new_event
->ptid
),
5369 QUEUE_length (stop_reply_p
,
5372 mark_async_event_handler (remote_async_inferior_event_token
);
5376 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5377 QUEUE_ITER (stop_reply_p
) *iter
,
5378 struct stop_reply
*event
,
5381 ptid_t
*ptid
= data
;
5383 return !(ptid_equal (*ptid
, event
->ptid
)
5384 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5387 /* Returns true if we have a stop reply for PTID. */
5390 peek_stop_reply (ptid_t ptid
)
5392 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5393 stop_reply_match_ptid_and_ws
, &ptid
);
5396 /* Parse the stop reply in BUF. Either the function succeeds, and the
5397 result is stored in EVENT, or throws an error. */
5400 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5402 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5406 event
->ptid
= null_ptid
;
5407 event
->rs
= get_remote_state ();
5408 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5409 event
->ws
.value
.integer
= 0;
5410 event
->stopped_by_watchpoint_p
= 0;
5411 event
->regcache
= NULL
;
5416 case 'T': /* Status with PC, SP, FP, ... */
5417 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5418 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5420 n... = register number
5421 r... = register contents
5424 p
= &buf
[3]; /* after Txx */
5432 /* If the packet contains a register number, save it in
5433 pnum and set p1 to point to the character following it.
5434 Otherwise p1 points to p. */
5436 /* If this packet is an awatch packet, don't parse the 'a'
5437 as a register number. */
5439 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5440 && strncmp (p
, "core", strlen ("core") != 0))
5442 /* Read the ``P'' register number. */
5443 pnum
= strtol (p
, &p_temp
, 16);
5449 if (p1
== p
) /* No register number present here. */
5451 p1
= strchr (p
, ':');
5453 error (_("Malformed packet(a) (missing colon): %s\n\
5456 if (strncmp (p
, "thread", p1
- p
) == 0)
5457 event
->ptid
= read_ptid (++p1
, &p
);
5458 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5459 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5460 || (strncmp (p
, "awatch", p1
- p
) == 0))
5462 event
->stopped_by_watchpoint_p
= 1;
5463 p
= unpack_varlen_hex (++p1
, &addr
);
5464 event
->watch_data_address
= (CORE_ADDR
) addr
;
5466 else if (strncmp (p
, "library", p1
- p
) == 0)
5470 while (*p_temp
&& *p_temp
!= ';')
5473 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5476 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5478 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5479 /* p1 will indicate "begin" or "end", but it makes
5480 no difference for now, so ignore it. */
5481 p_temp
= strchr (p1
+ 1, ';');
5485 else if (strncmp (p
, "core", p1
- p
) == 0)
5489 p
= unpack_varlen_hex (++p1
, &c
);
5494 /* Silently skip unknown optional info. */
5495 p_temp
= strchr (p1
+ 1, ';');
5502 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5503 cached_reg_t cached_reg
;
5508 error (_("Malformed packet(b) (missing colon): %s\n\
5514 error (_("Remote sent bad register number %s: %s\n\
5516 hex_string (pnum
), p
, buf
);
5518 cached_reg
.num
= reg
->regnum
;
5520 fieldsize
= hex2bin (p
, cached_reg
.data
,
5521 register_size (target_gdbarch (),
5524 if (fieldsize
< register_size (target_gdbarch (),
5526 warning (_("Remote reply is too short: %s"), buf
);
5528 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5532 error (_("Remote register badly formatted: %s\nhere: %s"),
5537 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5541 case 'S': /* Old style status, just signal only. */
5545 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5546 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5547 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5548 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5550 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5553 case 'W': /* Target exited. */
5560 /* GDB used to accept only 2 hex chars here. Stubs should
5561 only send more if they detect GDB supports multi-process
5563 p
= unpack_varlen_hex (&buf
[1], &value
);
5567 /* The remote process exited. */
5568 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5569 event
->ws
.value
.integer
= value
;
5573 /* The remote process exited with a signal. */
5574 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5575 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
5576 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5578 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5581 /* If no process is specified, assume inferior_ptid. */
5582 pid
= ptid_get_pid (inferior_ptid
);
5591 else if (strncmp (p
,
5592 "process:", sizeof ("process:") - 1) == 0)
5596 p
+= sizeof ("process:") - 1;
5597 unpack_varlen_hex (p
, &upid
);
5601 error (_("unknown stop reply packet: %s"), buf
);
5604 error (_("unknown stop reply packet: %s"), buf
);
5605 event
->ptid
= pid_to_ptid (pid
);
5610 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5611 error (_("No process or thread specified in stop reply: %s"), buf
);
5614 /* When the stub wants to tell GDB about a new notification reply, it
5615 sends a notification (%Stop, for example). Those can come it at
5616 any time, hence, we have to make sure that any pending
5617 putpkt/getpkt sequence we're making is finished, before querying
5618 the stub for more events with the corresponding ack command
5619 (vStopped, for example). E.g., if we started a vStopped sequence
5620 immediately upon receiving the notification, something like this
5628 1.6) <-- (registers reply to step #1.3)
5630 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5633 To solve this, whenever we parse a %Stop notification successfully,
5634 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5635 doing whatever we were doing:
5641 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5642 2.5) <-- (registers reply to step #2.3)
5644 Eventualy after step #2.5, we return to the event loop, which
5645 notices there's an event on the
5646 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5647 associated callback --- the function below. At this point, we're
5648 always safe to start a vStopped sequence. :
5651 2.7) <-- T05 thread:2
5657 remote_notif_get_pending_events (struct notif_client
*nc
)
5659 struct remote_state
*rs
= get_remote_state ();
5661 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
5664 fprintf_unfiltered (gdb_stdlog
,
5665 "notif: process: '%s' ack pending event\n",
5669 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
5670 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
5674 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5675 if (strcmp (rs
->buf
, "OK") == 0)
5678 remote_notif_ack (nc
, rs
->buf
);
5684 fprintf_unfiltered (gdb_stdlog
,
5685 "notif: process: '%s' no pending reply\n",
5690 /* Called when it is decided that STOP_REPLY holds the info of the
5691 event that is to be returned to the core. This function always
5692 destroys STOP_REPLY. */
5695 process_stop_reply (struct stop_reply
*stop_reply
,
5696 struct target_waitstatus
*status
)
5700 *status
= stop_reply
->ws
;
5701 ptid
= stop_reply
->ptid
;
5703 /* If no thread/process was reported by the stub, assume the current
5705 if (ptid_equal (ptid
, null_ptid
))
5706 ptid
= inferior_ptid
;
5708 if (status
->kind
!= TARGET_WAITKIND_EXITED
5709 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5711 struct remote_state
*rs
= get_remote_state ();
5713 /* Expedited registers. */
5714 if (stop_reply
->regcache
)
5716 struct regcache
*regcache
5717 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5722 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5724 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5725 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5728 rs
->remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5729 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
5731 remote_notice_new_inferior (ptid
, 0);
5732 demand_private_info (ptid
)->core
= stop_reply
->core
;
5735 stop_reply_xfree (stop_reply
);
5739 /* The non-stop mode version of target_wait. */
5742 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5744 struct remote_state
*rs
= get_remote_state ();
5745 struct stop_reply
*stop_reply
;
5749 /* If in non-stop mode, get out of getpkt even if a
5750 notification is received. */
5752 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5753 0 /* forever */, &is_notif
);
5756 if (ret
!= -1 && !is_notif
)
5759 case 'E': /* Error of some sort. */
5760 /* We're out of sync with the target now. Did it continue
5761 or not? We can't tell which thread it was in non-stop,
5762 so just ignore this. */
5763 warning (_("Remote failure reply: %s"), rs
->buf
);
5765 case 'O': /* Console output. */
5766 remote_console_output (rs
->buf
+ 1);
5769 warning (_("Invalid remote reply: %s"), rs
->buf
);
5773 /* Acknowledge a pending stop reply that may have arrived in the
5775 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
5776 remote_notif_get_pending_events (¬if_client_stop
);
5778 /* If indeed we noticed a stop reply, we're done. */
5779 stop_reply
= queued_stop_reply (ptid
);
5780 if (stop_reply
!= NULL
)
5781 return process_stop_reply (stop_reply
, status
);
5783 /* Still no event. If we're just polling for an event, then
5784 return to the event loop. */
5785 if (options
& TARGET_WNOHANG
)
5787 status
->kind
= TARGET_WAITKIND_IGNORE
;
5788 return minus_one_ptid
;
5791 /* Otherwise do a blocking wait. */
5792 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5793 1 /* forever */, &is_notif
);
5797 /* Wait until the remote machine stops, then return, storing status in
5798 STATUS just as `wait' would. */
5801 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5803 struct remote_state
*rs
= get_remote_state ();
5804 ptid_t event_ptid
= null_ptid
;
5806 struct stop_reply
*stop_reply
;
5810 status
->kind
= TARGET_WAITKIND_IGNORE
;
5811 status
->value
.integer
= 0;
5813 stop_reply
= queued_stop_reply (ptid
);
5814 if (stop_reply
!= NULL
)
5815 return process_stop_reply (stop_reply
, status
);
5817 if (rs
->cached_wait_status
)
5818 /* Use the cached wait status, but only once. */
5819 rs
->cached_wait_status
= 0;
5825 if (!target_is_async_p ())
5827 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
5828 /* If the user hit C-c before this packet, or between packets,
5829 pretend that it was hit right here. */
5830 if (check_quit_flag ())
5833 sync_remote_interrupt (SIGINT
);
5837 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5838 _never_ wait for ever -> test on target_is_async_p().
5839 However, before we do that we need to ensure that the caller
5840 knows how to take the target into/out of async mode. */
5841 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5842 wait_forever_enabled_p
, &is_notif
);
5844 if (!target_is_async_p ())
5845 signal (SIGINT
, ofunc
);
5847 /* GDB gets a notification. Return to core as this event is
5849 if (ret
!= -1 && is_notif
)
5850 return minus_one_ptid
;
5855 rs
->remote_stopped_by_watchpoint_p
= 0;
5857 /* We got something. */
5858 rs
->waiting_for_stop_reply
= 0;
5860 /* Assume that the target has acknowledged Ctrl-C unless we receive
5861 an 'F' or 'O' packet. */
5862 if (buf
[0] != 'F' && buf
[0] != 'O')
5863 rs
->ctrlc_pending_p
= 0;
5867 case 'E': /* Error of some sort. */
5868 /* We're out of sync with the target now. Did it continue or
5869 not? Not is more likely, so report a stop. */
5870 warning (_("Remote failure reply: %s"), buf
);
5871 status
->kind
= TARGET_WAITKIND_STOPPED
;
5872 status
->value
.sig
= GDB_SIGNAL_0
;
5874 case 'F': /* File-I/O request. */
5875 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5876 rs
->ctrlc_pending_p
= 0;
5878 case 'T': case 'S': case 'X': case 'W':
5880 struct stop_reply
*stop_reply
5881 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
5884 event_ptid
= process_stop_reply (stop_reply
, status
);
5887 case 'O': /* Console output. */
5888 remote_console_output (buf
+ 1);
5890 /* The target didn't really stop; keep waiting. */
5891 rs
->waiting_for_stop_reply
= 1;
5895 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
5897 /* Zero length reply means that we tried 'S' or 'C' and the
5898 remote system doesn't support it. */
5899 target_terminal_ours_for_output ();
5901 ("Can't send signals to this remote system. %s not sent.\n",
5902 gdb_signal_to_name (rs
->last_sent_signal
));
5903 rs
->last_sent_signal
= GDB_SIGNAL_0
;
5904 target_terminal_inferior ();
5906 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
5907 putpkt ((char *) buf
);
5909 /* We just told the target to resume, so a stop reply is in
5911 rs
->waiting_for_stop_reply
= 1;
5914 /* else fallthrough */
5916 warning (_("Invalid remote reply: %s"), buf
);
5918 rs
->waiting_for_stop_reply
= 1;
5922 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5924 /* Nothing interesting happened. If we're doing a non-blocking
5925 poll, we're done. Otherwise, go back to waiting. */
5926 if (options
& TARGET_WNOHANG
)
5927 return minus_one_ptid
;
5931 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5932 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5934 if (!ptid_equal (event_ptid
, null_ptid
))
5935 record_currthread (rs
, event_ptid
);
5937 event_ptid
= inferior_ptid
;
5940 /* A process exit. Invalidate our notion of current thread. */
5941 record_currthread (rs
, minus_one_ptid
);
5946 /* Wait until the remote machine stops, then return, storing status in
5947 STATUS just as `wait' would. */
5950 remote_wait (struct target_ops
*ops
,
5951 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5956 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5958 event_ptid
= remote_wait_as (ptid
, status
, options
);
5960 if (target_can_async_p ())
5962 /* If there are are events left in the queue tell the event loop
5964 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5965 mark_async_event_handler (remote_async_inferior_event_token
);
5971 /* Fetch a single register using a 'p' packet. */
5974 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5976 struct remote_state
*rs
= get_remote_state ();
5978 char regp
[MAX_REGISTER_SIZE
];
5981 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
5984 if (reg
->pnum
== -1)
5989 p
+= hexnumstr (p
, reg
->pnum
);
5992 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5996 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6000 case PACKET_UNKNOWN
:
6003 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6004 gdbarch_register_name (get_regcache_arch (regcache
),
6009 /* If this register is unfetchable, tell the regcache. */
6012 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6016 /* Otherwise, parse and supply the value. */
6022 error (_("fetch_register_using_p: early buf termination"));
6024 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6027 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6031 /* Fetch the registers included in the target's 'g' packet. */
6034 send_g_packet (void)
6036 struct remote_state
*rs
= get_remote_state ();
6039 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6040 remote_send (&rs
->buf
, &rs
->buf_size
);
6042 /* We can get out of synch in various cases. If the first character
6043 in the buffer is not a hex character, assume that has happened
6044 and try to fetch another packet to read. */
6045 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6046 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6047 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6048 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6051 fprintf_unfiltered (gdb_stdlog
,
6052 "Bad register packet; fetching a new packet\n");
6053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6056 buf_len
= strlen (rs
->buf
);
6058 /* Sanity check the received packet. */
6059 if (buf_len
% 2 != 0)
6060 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6066 process_g_packet (struct regcache
*regcache
)
6068 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6069 struct remote_state
*rs
= get_remote_state ();
6070 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6075 buf_len
= strlen (rs
->buf
);
6077 /* Further sanity checks, with knowledge of the architecture. */
6078 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6079 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6081 /* Save the size of the packet sent to us by the target. It is used
6082 as a heuristic when determining the max size of packets that the
6083 target can safely receive. */
6084 if (rsa
->actual_register_packet_size
== 0)
6085 rsa
->actual_register_packet_size
= buf_len
;
6087 /* If this is smaller than we guessed the 'g' packet would be,
6088 update our records. A 'g' reply that doesn't include a register's
6089 value implies either that the register is not available, or that
6090 the 'p' packet must be used. */
6091 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6093 rsa
->sizeof_g_packet
= buf_len
/ 2;
6095 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6097 if (rsa
->regs
[i
].pnum
== -1)
6100 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6101 rsa
->regs
[i
].in_g_packet
= 0;
6103 rsa
->regs
[i
].in_g_packet
= 1;
6107 regs
= alloca (rsa
->sizeof_g_packet
);
6109 /* Unimplemented registers read as all bits zero. */
6110 memset (regs
, 0, rsa
->sizeof_g_packet
);
6112 /* Reply describes registers byte by byte, each byte encoded as two
6113 hex characters. Suck them all up, then supply them to the
6114 register cacheing/storage mechanism. */
6117 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6119 if (p
[0] == 0 || p
[1] == 0)
6120 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6121 internal_error (__FILE__
, __LINE__
,
6122 _("unexpected end of 'g' packet reply"));
6124 if (p
[0] == 'x' && p
[1] == 'x')
6125 regs
[i
] = 0; /* 'x' */
6127 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6131 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6133 struct packet_reg
*r
= &rsa
->regs
[i
];
6137 if (r
->offset
* 2 >= strlen (rs
->buf
))
6138 /* This shouldn't happen - we adjusted in_g_packet above. */
6139 internal_error (__FILE__
, __LINE__
,
6140 _("unexpected end of 'g' packet reply"));
6141 else if (rs
->buf
[r
->offset
* 2] == 'x')
6143 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6144 /* The register isn't available, mark it as such (at
6145 the same time setting the value to zero). */
6146 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6149 regcache_raw_supply (regcache
, r
->regnum
,
6156 fetch_registers_using_g (struct regcache
*regcache
)
6159 process_g_packet (regcache
);
6162 /* Make the remote selected traceframe match GDB's selected
6166 set_remote_traceframe (void)
6169 struct remote_state
*rs
= get_remote_state ();
6171 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6174 /* Avoid recursion, remote_trace_find calls us again. */
6175 rs
->remote_traceframe_number
= get_traceframe_number ();
6177 newnum
= target_trace_find (tfind_number
,
6178 get_traceframe_number (), 0, 0, NULL
);
6180 /* Should not happen. If it does, all bets are off. */
6181 if (newnum
!= get_traceframe_number ())
6182 warning (_("could not set remote traceframe"));
6186 remote_fetch_registers (struct target_ops
*ops
,
6187 struct regcache
*regcache
, int regnum
)
6189 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6192 set_remote_traceframe ();
6193 set_general_thread (inferior_ptid
);
6197 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6199 gdb_assert (reg
!= NULL
);
6201 /* If this register might be in the 'g' packet, try that first -
6202 we are likely to read more than one register. If this is the
6203 first 'g' packet, we might be overly optimistic about its
6204 contents, so fall back to 'p'. */
6205 if (reg
->in_g_packet
)
6207 fetch_registers_using_g (regcache
);
6208 if (reg
->in_g_packet
)
6212 if (fetch_register_using_p (regcache
, reg
))
6215 /* This register is not available. */
6216 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6221 fetch_registers_using_g (regcache
);
6223 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6224 if (!rsa
->regs
[i
].in_g_packet
)
6225 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6227 /* This register is not available. */
6228 regcache_raw_supply (regcache
, i
, NULL
);
6232 /* Prepare to store registers. Since we may send them all (using a
6233 'G' request), we have to read out the ones we don't want to change
6237 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6239 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6241 gdb_byte buf
[MAX_REGISTER_SIZE
];
6243 /* Make sure the entire registers array is valid. */
6244 switch (packet_support (PACKET_P
))
6246 case PACKET_DISABLE
:
6247 case PACKET_SUPPORT_UNKNOWN
:
6248 /* Make sure all the necessary registers are cached. */
6249 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6250 if (rsa
->regs
[i
].in_g_packet
)
6251 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6258 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6259 packet was not recognized. */
6262 store_register_using_P (const struct regcache
*regcache
,
6263 struct packet_reg
*reg
)
6265 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6266 struct remote_state
*rs
= get_remote_state ();
6267 /* Try storing a single register. */
6268 char *buf
= rs
->buf
;
6269 gdb_byte regp
[MAX_REGISTER_SIZE
];
6272 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6275 if (reg
->pnum
== -1)
6278 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6279 p
= buf
+ strlen (buf
);
6280 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6281 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6283 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6285 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6290 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6291 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6292 case PACKET_UNKNOWN
:
6295 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6299 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6300 contents of the register cache buffer. FIXME: ignores errors. */
6303 store_registers_using_G (const struct regcache
*regcache
)
6305 struct remote_state
*rs
= get_remote_state ();
6306 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6310 /* Extract all the registers in the regcache copying them into a
6315 regs
= alloca (rsa
->sizeof_g_packet
);
6316 memset (regs
, 0, rsa
->sizeof_g_packet
);
6317 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6319 struct packet_reg
*r
= &rsa
->regs
[i
];
6322 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6326 /* Command describes registers byte by byte,
6327 each byte encoded as two hex characters. */
6330 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6332 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6334 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6335 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6336 error (_("Could not write registers; remote failure reply '%s'"),
6340 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6341 of the register cache buffer. FIXME: ignores errors. */
6344 remote_store_registers (struct target_ops
*ops
,
6345 struct regcache
*regcache
, int regnum
)
6347 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6350 set_remote_traceframe ();
6351 set_general_thread (inferior_ptid
);
6355 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6357 gdb_assert (reg
!= NULL
);
6359 /* Always prefer to store registers using the 'P' packet if
6360 possible; we often change only a small number of registers.
6361 Sometimes we change a larger number; we'd need help from a
6362 higher layer to know to use 'G'. */
6363 if (store_register_using_P (regcache
, reg
))
6366 /* For now, don't complain if we have no way to write the
6367 register. GDB loses track of unavailable registers too
6368 easily. Some day, this may be an error. We don't have
6369 any way to read the register, either... */
6370 if (!reg
->in_g_packet
)
6373 store_registers_using_G (regcache
);
6377 store_registers_using_G (regcache
);
6379 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6380 if (!rsa
->regs
[i
].in_g_packet
)
6381 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6382 /* See above for why we do not issue an error here. */
6387 /* Return the number of hex digits in num. */
6390 hexnumlen (ULONGEST num
)
6394 for (i
= 0; num
!= 0; i
++)
6400 /* Set BUF to the minimum number of hex digits representing NUM. */
6403 hexnumstr (char *buf
, ULONGEST num
)
6405 int len
= hexnumlen (num
);
6407 return hexnumnstr (buf
, num
, len
);
6411 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6414 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6420 for (i
= width
- 1; i
>= 0; i
--)
6422 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6429 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6432 remote_address_masked (CORE_ADDR addr
)
6434 unsigned int address_size
= remote_address_size
;
6436 /* If "remoteaddresssize" was not set, default to target address size. */
6438 address_size
= gdbarch_addr_bit (target_gdbarch ());
6440 if (address_size
> 0
6441 && address_size
< (sizeof (ULONGEST
) * 8))
6443 /* Only create a mask when that mask can safely be constructed
6444 in a ULONGEST variable. */
6447 mask
= (mask
<< address_size
) - 1;
6453 /* Determine whether the remote target supports binary downloading.
6454 This is accomplished by sending a no-op memory write of zero length
6455 to the target at the specified address. It does not suffice to send
6456 the whole packet, since many stubs strip the eighth bit and
6457 subsequently compute a wrong checksum, which causes real havoc with
6460 NOTE: This can still lose if the serial line is not eight-bit
6461 clean. In cases like this, the user should clear "remote
6465 check_binary_download (CORE_ADDR addr
)
6467 struct remote_state
*rs
= get_remote_state ();
6469 switch (packet_support (PACKET_X
))
6471 case PACKET_DISABLE
:
6475 case PACKET_SUPPORT_UNKNOWN
:
6481 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6483 p
+= hexnumstr (p
, (ULONGEST
) 0);
6487 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6488 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6490 if (rs
->buf
[0] == '\0')
6493 fprintf_unfiltered (gdb_stdlog
,
6494 "binary downloading NOT "
6495 "supported by target\n");
6496 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6501 fprintf_unfiltered (gdb_stdlog
,
6502 "binary downloading supported by target\n");
6503 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6510 /* Write memory data directly to the remote machine.
6511 This does not inform the data cache; the data cache uses this.
6512 HEADER is the starting part of the packet.
6513 MEMADDR is the address in the remote memory space.
6514 MYADDR is the address of the buffer in our space.
6515 LEN is the number of bytes.
6516 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6517 should send data as binary ('X'), or hex-encoded ('M').
6519 The function creates packet of the form
6520 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6522 where encoding of <DATA> is termined by PACKET_FORMAT.
6524 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6527 Return the transferred status, error or OK (an
6528 'enum target_xfer_status' value). Save the number of bytes
6529 transferred in *XFERED_LEN. Only transfer a single packet. */
6531 static enum target_xfer_status
6532 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6533 const gdb_byte
*myaddr
, ULONGEST len
,
6534 ULONGEST
*xfered_len
, char packet_format
,
6537 struct remote_state
*rs
= get_remote_state ();
6547 if (packet_format
!= 'X' && packet_format
!= 'M')
6548 internal_error (__FILE__
, __LINE__
,
6549 _("remote_write_bytes_aux: bad packet format"));
6552 return TARGET_XFER_EOF
;
6554 payload_size
= get_memory_write_packet_size ();
6556 /* The packet buffer will be large enough for the payload;
6557 get_memory_packet_size ensures this. */
6560 /* Compute the size of the actual payload by subtracting out the
6561 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6563 payload_size
-= strlen ("$,:#NN");
6565 /* The comma won't be used. */
6567 header_length
= strlen (header
);
6568 payload_size
-= header_length
;
6569 payload_size
-= hexnumlen (memaddr
);
6571 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6573 strcat (rs
->buf
, header
);
6574 p
= rs
->buf
+ strlen (header
);
6576 /* Compute a best guess of the number of bytes actually transfered. */
6577 if (packet_format
== 'X')
6579 /* Best guess at number of bytes that will fit. */
6580 todo
= min (len
, payload_size
);
6582 payload_size
-= hexnumlen (todo
);
6583 todo
= min (todo
, payload_size
);
6587 /* Num bytes that will fit. */
6588 todo
= min (len
, payload_size
/ 2);
6590 payload_size
-= hexnumlen (todo
);
6591 todo
= min (todo
, payload_size
/ 2);
6595 internal_error (__FILE__
, __LINE__
,
6596 _("minimum packet size too small to write data"));
6598 /* If we already need another packet, then try to align the end
6599 of this packet to a useful boundary. */
6600 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6601 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6603 /* Append "<memaddr>". */
6604 memaddr
= remote_address_masked (memaddr
);
6605 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6612 /* Append <len>. Retain the location/size of <len>. It may need to
6613 be adjusted once the packet body has been created. */
6615 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6623 /* Append the packet body. */
6624 if (packet_format
== 'X')
6626 /* Binary mode. Send target system values byte by byte, in
6627 increasing byte addresses. Only escape certain critical
6629 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6630 &nr_bytes
, payload_size
);
6632 /* If not all TODO bytes fit, then we'll need another packet. Make
6633 a second try to keep the end of the packet aligned. Don't do
6634 this if the packet is tiny. */
6635 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6639 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6641 if (new_nr_bytes
!= nr_bytes
)
6642 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6643 (gdb_byte
*) p
, &nr_bytes
,
6647 p
+= payload_length
;
6648 if (use_length
&& nr_bytes
< todo
)
6650 /* Escape chars have filled up the buffer prematurely,
6651 and we have actually sent fewer bytes than planned.
6652 Fix-up the length field of the packet. Use the same
6653 number of characters as before. */
6654 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6655 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6660 /* Normal mode: Send target system values byte by byte, in
6661 increasing byte addresses. Each byte is encoded as a two hex
6663 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6667 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6668 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6670 if (rs
->buf
[0] == 'E')
6671 return TARGET_XFER_E_IO
;
6673 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6674 fewer bytes than we'd planned. */
6675 *xfered_len
= (ULONGEST
) nr_bytes
;
6676 return TARGET_XFER_OK
;
6679 /* Write memory data directly to the remote machine.
6680 This does not inform the data cache; the data cache uses this.
6681 MEMADDR is the address in the remote memory space.
6682 MYADDR is the address of the buffer in our space.
6683 LEN is the number of bytes.
6685 Return the transferred status, error or OK (an
6686 'enum target_xfer_status' value). Save the number of bytes
6687 transferred in *XFERED_LEN. Only transfer a single packet. */
6689 static enum target_xfer_status
6690 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
6691 ULONGEST
*xfered_len
)
6693 char *packet_format
= 0;
6695 /* Check whether the target supports binary download. */
6696 check_binary_download (memaddr
);
6698 switch (packet_support (PACKET_X
))
6701 packet_format
= "X";
6703 case PACKET_DISABLE
:
6704 packet_format
= "M";
6706 case PACKET_SUPPORT_UNKNOWN
:
6707 internal_error (__FILE__
, __LINE__
,
6708 _("remote_write_bytes: bad internal state"));
6710 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6713 return remote_write_bytes_aux (packet_format
,
6714 memaddr
, myaddr
, len
, xfered_len
,
6715 packet_format
[0], 1);
6718 /* Read memory data directly from the remote machine.
6719 This does not use the data cache; the data cache uses this.
6720 MEMADDR is the address in the remote memory space.
6721 MYADDR is the address of the buffer in our space.
6722 LEN is the number of bytes.
6724 Return the transferred status, error or OK (an
6725 'enum target_xfer_status' value). Save the number of bytes
6726 transferred in *XFERED_LEN. */
6728 static enum target_xfer_status
6729 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len
,
6730 ULONGEST
*xfered_len
)
6732 struct remote_state
*rs
= get_remote_state ();
6733 int max_buf_size
; /* Max size of packet output buffer. */
6738 max_buf_size
= get_memory_read_packet_size ();
6739 /* The packet buffer will be large enough for the payload;
6740 get_memory_packet_size ensures this. */
6742 /* Number if bytes that will fit. */
6743 todo
= min (len
, max_buf_size
/ 2);
6745 /* Construct "m"<memaddr>","<len>". */
6746 memaddr
= remote_address_masked (memaddr
);
6749 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6751 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6754 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6755 if (rs
->buf
[0] == 'E'
6756 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6757 && rs
->buf
[3] == '\0')
6758 return TARGET_XFER_E_IO
;
6759 /* Reply describes memory byte by byte, each byte encoded as two hex
6762 i
= hex2bin (p
, myaddr
, todo
);
6763 /* Return what we have. Let higher layers handle partial reads. */
6764 *xfered_len
= (ULONGEST
) i
;
6765 return TARGET_XFER_OK
;
6768 /* Using the set of read-only target sections of remote, read live
6771 For interface/parameters/return description see target.h,
6774 static enum target_xfer_status
6775 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
6776 ULONGEST memaddr
, ULONGEST len
,
6777 ULONGEST
*xfered_len
)
6779 struct target_section
*secp
;
6780 struct target_section_table
*table
;
6782 secp
= target_section_by_addr (ops
, memaddr
);
6784 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
6785 secp
->the_bfd_section
)
6788 struct target_section
*p
;
6789 ULONGEST memend
= memaddr
+ len
;
6791 table
= target_get_section_table (ops
);
6793 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
6795 if (memaddr
>= p
->addr
)
6797 if (memend
<= p
->endaddr
)
6799 /* Entire transfer is within this section. */
6800 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
6803 else if (memaddr
>= p
->endaddr
)
6805 /* This section ends before the transfer starts. */
6810 /* This section overlaps the transfer. Just do half. */
6811 len
= p
->endaddr
- memaddr
;
6812 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
6819 return TARGET_XFER_EOF
;
6822 /* Similar to remote_read_bytes_1, but it reads from the remote stub
6823 first if the requested memory is unavailable in traceframe.
6824 Otherwise, fall back to remote_read_bytes_1. */
6826 static enum target_xfer_status
6827 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
6828 gdb_byte
*myaddr
, ULONGEST len
, ULONGEST
*xfered_len
)
6833 if (get_traceframe_number () != -1)
6835 VEC(mem_range_s
) *available
;
6837 /* If we fail to get the set of available memory, then the
6838 target does not support querying traceframe info, and so we
6839 attempt reading from the traceframe anyway (assuming the
6840 target implements the old QTro packet then). */
6841 if (traceframe_available_memory (&available
, memaddr
, len
))
6843 struct cleanup
*old_chain
;
6845 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
6847 if (VEC_empty (mem_range_s
, available
)
6848 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
6850 enum target_xfer_status res
;
6852 /* Don't read into the traceframe's available
6854 if (!VEC_empty (mem_range_s
, available
))
6856 LONGEST oldlen
= len
;
6858 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
6859 gdb_assert (len
<= oldlen
);
6862 do_cleanups (old_chain
);
6864 /* This goes through the topmost target again. */
6865 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
6867 if (res
== TARGET_XFER_OK
)
6868 return TARGET_XFER_OK
;
6871 /* No use trying further, we know some memory starting
6872 at MEMADDR isn't available. */
6874 return TARGET_XFER_UNAVAILABLE
;
6878 /* Don't try to read more than how much is available, in
6879 case the target implements the deprecated QTro packet to
6880 cater for older GDBs (the target's knowledge of read-only
6881 sections may be outdated by now). */
6882 len
= VEC_index (mem_range_s
, available
, 0)->length
;
6884 do_cleanups (old_chain
);
6888 return remote_read_bytes_1 (memaddr
, myaddr
, len
, xfered_len
);
6893 /* Sends a packet with content determined by the printf format string
6894 FORMAT and the remaining arguments, then gets the reply. Returns
6895 whether the packet was a success, a failure, or unknown. */
6897 static enum packet_result
6898 remote_send_printf (const char *format
, ...)
6900 struct remote_state
*rs
= get_remote_state ();
6901 int max_size
= get_remote_packet_size ();
6904 va_start (ap
, format
);
6907 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6908 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6910 if (putpkt (rs
->buf
) < 0)
6911 error (_("Communication problem with target."));
6914 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6916 return packet_check_result (rs
->buf
);
6920 restore_remote_timeout (void *p
)
6922 int value
= *(int *)p
;
6924 remote_timeout
= value
;
6927 /* Flash writing can take quite some time. We'll set
6928 effectively infinite timeout for flash operations.
6929 In future, we'll need to decide on a better approach. */
6930 static const int remote_flash_timeout
= 1000;
6933 remote_flash_erase (struct target_ops
*ops
,
6934 ULONGEST address
, LONGEST length
)
6936 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
6937 int saved_remote_timeout
= remote_timeout
;
6938 enum packet_result ret
;
6939 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6940 &saved_remote_timeout
);
6942 remote_timeout
= remote_flash_timeout
;
6944 ret
= remote_send_printf ("vFlashErase:%s,%s",
6945 phex (address
, addr_size
),
6949 case PACKET_UNKNOWN
:
6950 error (_("Remote target does not support flash erase"));
6952 error (_("Error erasing flash with vFlashErase packet"));
6957 do_cleanups (back_to
);
6960 static enum target_xfer_status
6961 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
6962 ULONGEST length
, ULONGEST
*xfered_len
,
6963 const gdb_byte
*data
)
6965 int saved_remote_timeout
= remote_timeout
;
6966 enum target_xfer_status ret
;
6967 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6968 &saved_remote_timeout
);
6970 remote_timeout
= remote_flash_timeout
;
6971 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
,
6973 do_cleanups (back_to
);
6979 remote_flash_done (struct target_ops
*ops
)
6981 int saved_remote_timeout
= remote_timeout
;
6983 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6984 &saved_remote_timeout
);
6986 remote_timeout
= remote_flash_timeout
;
6987 ret
= remote_send_printf ("vFlashDone");
6988 do_cleanups (back_to
);
6992 case PACKET_UNKNOWN
:
6993 error (_("Remote target does not support vFlashDone"));
6995 error (_("Error finishing flash operation"));
7002 remote_files_info (struct target_ops
*ignore
)
7004 puts_filtered ("Debugging a target over a serial line.\n");
7007 /* Stuff for dealing with the packets which are part of this protocol.
7008 See comment at top of file for details. */
7010 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7011 error to higher layers. Called when a serial error is detected.
7012 The exception message is STRING, followed by a colon and a blank,
7013 the system error message for errno at function entry and final dot
7014 for output compatibility with throw_perror_with_name. */
7017 unpush_and_perror (const char *string
)
7019 int saved_errno
= errno
;
7021 remote_unpush_target ();
7022 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7023 safe_strerror (saved_errno
));
7026 /* Read a single character from the remote end. */
7029 readchar (int timeout
)
7032 struct remote_state
*rs
= get_remote_state ();
7034 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7039 switch ((enum serial_rc
) ch
)
7042 remote_unpush_target ();
7043 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7046 unpush_and_perror (_("Remote communication error. "
7047 "Target disconnected."));
7049 case SERIAL_TIMEOUT
:
7055 /* Wrapper for serial_write that closes the target and throws if
7059 remote_serial_write (const char *str
, int len
)
7061 struct remote_state
*rs
= get_remote_state ();
7063 if (serial_write (rs
->remote_desc
, str
, len
))
7065 unpush_and_perror (_("Remote communication error. "
7066 "Target disconnected."));
7070 /* Send the command in *BUF to the remote machine, and read the reply
7071 into *BUF. Report an error if we get an error reply. Resize
7072 *BUF using xrealloc if necessary to hold the result, and update
7076 remote_send (char **buf
,
7080 getpkt (buf
, sizeof_buf
, 0);
7082 if ((*buf
)[0] == 'E')
7083 error (_("Remote failure reply: %s"), *buf
);
7086 /* Return a pointer to an xmalloc'ed string representing an escaped
7087 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7088 etc. The caller is responsible for releasing the returned
7092 escape_buffer (const char *buf
, int n
)
7094 struct cleanup
*old_chain
;
7095 struct ui_file
*stb
;
7098 stb
= mem_fileopen ();
7099 old_chain
= make_cleanup_ui_file_delete (stb
);
7101 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7102 str
= ui_file_xstrdup (stb
, NULL
);
7103 do_cleanups (old_chain
);
7107 /* Display a null-terminated packet on stdout, for debugging, using C
7111 print_packet (const char *buf
)
7113 puts_filtered ("\"");
7114 fputstr_filtered (buf
, '"', gdb_stdout
);
7115 puts_filtered ("\"");
7119 putpkt (const char *buf
)
7121 return putpkt_binary (buf
, strlen (buf
));
7124 /* Send a packet to the remote machine, with error checking. The data
7125 of the packet is in BUF. The string in BUF can be at most
7126 get_remote_packet_size () - 5 to account for the $, # and checksum,
7127 and for a possible /0 if we are debugging (remote_debug) and want
7128 to print the sent packet as a string. */
7131 putpkt_binary (const char *buf
, int cnt
)
7133 struct remote_state
*rs
= get_remote_state ();
7135 unsigned char csum
= 0;
7136 char *buf2
= alloca (cnt
+ 6);
7143 /* Catch cases like trying to read memory or listing threads while
7144 we're waiting for a stop reply. The remote server wouldn't be
7145 ready to handle this request, so we'd hang and timeout. We don't
7146 have to worry about this in synchronous mode, because in that
7147 case it's not possible to issue a command while the target is
7148 running. This is not a problem in non-stop mode, because in that
7149 case, the stub is always ready to process serial input. */
7150 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7152 error (_("Cannot execute this command while the target is running.\n"
7153 "Use the \"interrupt\" command to stop the target\n"
7154 "and then try again."));
7157 /* We're sending out a new packet. Make sure we don't look at a
7158 stale cached response. */
7159 rs
->cached_wait_status
= 0;
7161 /* Copy the packet into buffer BUF2, encapsulating it
7162 and giving it a checksum. */
7167 for (i
= 0; i
< cnt
; i
++)
7173 *p
++ = tohex ((csum
>> 4) & 0xf);
7174 *p
++ = tohex (csum
& 0xf);
7176 /* Send it over and over until we get a positive ack. */
7180 int started_error_output
= 0;
7184 struct cleanup
*old_chain
;
7188 str
= escape_buffer (buf2
, p
- buf2
);
7189 old_chain
= make_cleanup (xfree
, str
);
7190 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7191 gdb_flush (gdb_stdlog
);
7192 do_cleanups (old_chain
);
7194 remote_serial_write (buf2
, p
- buf2
);
7196 /* If this is a no acks version of the remote protocol, send the
7197 packet and move on. */
7201 /* Read until either a timeout occurs (-2) or '+' is read.
7202 Handle any notification that arrives in the mean time. */
7205 ch
= readchar (remote_timeout
);
7213 case SERIAL_TIMEOUT
:
7216 if (started_error_output
)
7218 putchar_unfiltered ('\n');
7219 started_error_output
= 0;
7228 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7232 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7234 case SERIAL_TIMEOUT
:
7238 break; /* Retransmit buffer. */
7242 fprintf_unfiltered (gdb_stdlog
,
7243 "Packet instead of Ack, ignoring it\n");
7244 /* It's probably an old response sent because an ACK
7245 was lost. Gobble up the packet and ack it so it
7246 doesn't get retransmitted when we resend this
7249 remote_serial_write ("+", 1);
7250 continue; /* Now, go look for +. */
7257 /* If we got a notification, handle it, and go back to looking
7259 /* We've found the start of a notification. Now
7260 collect the data. */
7261 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7266 struct cleanup
*old_chain
;
7269 str
= escape_buffer (rs
->buf
, val
);
7270 old_chain
= make_cleanup (xfree
, str
);
7271 fprintf_unfiltered (gdb_stdlog
,
7272 " Notification received: %s\n",
7274 do_cleanups (old_chain
);
7276 handle_notification (rs
->notif_state
, rs
->buf
);
7277 /* We're in sync now, rewait for the ack. */
7284 if (!started_error_output
)
7286 started_error_output
= 1;
7287 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7289 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7290 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7299 if (!started_error_output
)
7301 started_error_output
= 1;
7302 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7304 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7308 break; /* Here to retransmit. */
7312 /* This is wrong. If doing a long backtrace, the user should be
7313 able to get out next time we call QUIT, without anything as
7314 violent as interrupt_query. If we want to provide a way out of
7315 here without getting to the next QUIT, it should be based on
7316 hitting ^C twice as in remote_wait. */
7327 /* Come here after finding the start of a frame when we expected an
7328 ack. Do our best to discard the rest of this packet. */
7337 c
= readchar (remote_timeout
);
7340 case SERIAL_TIMEOUT
:
7341 /* Nothing we can do. */
7344 /* Discard the two bytes of checksum and stop. */
7345 c
= readchar (remote_timeout
);
7347 c
= readchar (remote_timeout
);
7350 case '*': /* Run length encoding. */
7351 /* Discard the repeat count. */
7352 c
= readchar (remote_timeout
);
7357 /* A regular character. */
7363 /* Come here after finding the start of the frame. Collect the rest
7364 into *BUF, verifying the checksum, length, and handling run-length
7365 compression. NUL terminate the buffer. If there is not enough room,
7366 expand *BUF using xrealloc.
7368 Returns -1 on error, number of characters in buffer (ignoring the
7369 trailing NULL) on success. (could be extended to return one of the
7370 SERIAL status indications). */
7373 read_frame (char **buf_p
,
7380 struct remote_state
*rs
= get_remote_state ();
7387 c
= readchar (remote_timeout
);
7390 case SERIAL_TIMEOUT
:
7392 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7396 fputs_filtered ("Saw new packet start in middle of old one\n",
7398 return -1; /* Start a new packet, count retries. */
7401 unsigned char pktcsum
;
7407 check_0
= readchar (remote_timeout
);
7409 check_1
= readchar (remote_timeout
);
7411 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7414 fputs_filtered ("Timeout in checksum, retrying\n",
7418 else if (check_0
< 0 || check_1
< 0)
7421 fputs_filtered ("Communication error in checksum\n",
7426 /* Don't recompute the checksum; with no ack packets we
7427 don't have any way to indicate a packet retransmission
7432 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7433 if (csum
== pktcsum
)
7438 struct cleanup
*old_chain
;
7441 str
= escape_buffer (buf
, bc
);
7442 old_chain
= make_cleanup (xfree
, str
);
7443 fprintf_unfiltered (gdb_stdlog
,
7444 "Bad checksum, sentsum=0x%x, "
7445 "csum=0x%x, buf=%s\n",
7446 pktcsum
, csum
, str
);
7447 do_cleanups (old_chain
);
7449 /* Number of characters in buffer ignoring trailing
7453 case '*': /* Run length encoding. */
7458 c
= readchar (remote_timeout
);
7460 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7462 /* The character before ``*'' is repeated. */
7464 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7466 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7468 /* Make some more room in the buffer. */
7469 *sizeof_buf
+= repeat
;
7470 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7474 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7480 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7484 if (bc
>= *sizeof_buf
- 1)
7486 /* Make some more room in the buffer. */
7488 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7499 /* Read a packet from the remote machine, with error checking, and
7500 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7501 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7502 rather than timing out; this is used (in synchronous mode) to wait
7503 for a target that is is executing user code to stop. */
7504 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7505 don't have to change all the calls to getpkt to deal with the
7506 return value, because at the moment I don't know what the right
7507 thing to do it for those. */
7515 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7519 /* Read a packet from the remote machine, with error checking, and
7520 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7521 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7522 rather than timing out; this is used (in synchronous mode) to wait
7523 for a target that is is executing user code to stop. If FOREVER ==
7524 0, this function is allowed to time out gracefully and return an
7525 indication of this to the caller. Otherwise return the number of
7526 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7527 enough reason to return to the caller. *IS_NOTIF is an output
7528 boolean that indicates whether *BUF holds a notification or not
7529 (a regular packet). */
7532 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7533 int expecting_notif
, int *is_notif
)
7535 struct remote_state
*rs
= get_remote_state ();
7541 /* We're reading a new response. Make sure we don't look at a
7542 previously cached response. */
7543 rs
->cached_wait_status
= 0;
7545 strcpy (*buf
, "timeout");
7548 timeout
= watchdog
> 0 ? watchdog
: -1;
7549 else if (expecting_notif
)
7550 timeout
= 0; /* There should already be a char in the buffer. If
7553 timeout
= remote_timeout
;
7557 /* Process any number of notifications, and then return when
7561 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7563 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7565 /* This can loop forever if the remote side sends us
7566 characters continuously, but if it pauses, we'll get
7567 SERIAL_TIMEOUT from readchar because of timeout. Then
7568 we'll count that as a retry.
7570 Note that even when forever is set, we will only wait
7571 forever prior to the start of a packet. After that, we
7572 expect characters to arrive at a brisk pace. They should
7573 show up within remote_timeout intervals. */
7575 c
= readchar (timeout
);
7576 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7578 if (c
== SERIAL_TIMEOUT
)
7580 if (expecting_notif
)
7581 return -1; /* Don't complain, it's normal to not get
7582 anything in this case. */
7584 if (forever
) /* Watchdog went off? Kill the target. */
7587 remote_unpush_target ();
7588 throw_error (TARGET_CLOSE_ERROR
,
7589 _("Watchdog timeout has expired. "
7590 "Target detached."));
7593 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7597 /* We've found the start of a packet or notification.
7598 Now collect the data. */
7599 val
= read_frame (buf
, sizeof_buf
);
7604 remote_serial_write ("-", 1);
7607 if (tries
> MAX_TRIES
)
7609 /* We have tried hard enough, and just can't receive the
7610 packet/notification. Give up. */
7611 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7613 /* Skip the ack char if we're in no-ack mode. */
7614 if (!rs
->noack_mode
)
7615 remote_serial_write ("+", 1);
7619 /* If we got an ordinary packet, return that to our caller. */
7624 struct cleanup
*old_chain
;
7627 str
= escape_buffer (*buf
, val
);
7628 old_chain
= make_cleanup (xfree
, str
);
7629 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7630 do_cleanups (old_chain
);
7633 /* Skip the ack char if we're in no-ack mode. */
7634 if (!rs
->noack_mode
)
7635 remote_serial_write ("+", 1);
7636 if (is_notif
!= NULL
)
7641 /* If we got a notification, handle it, and go back to looking
7645 gdb_assert (c
== '%');
7649 struct cleanup
*old_chain
;
7652 str
= escape_buffer (*buf
, val
);
7653 old_chain
= make_cleanup (xfree
, str
);
7654 fprintf_unfiltered (gdb_stdlog
,
7655 " Notification received: %s\n",
7657 do_cleanups (old_chain
);
7659 if (is_notif
!= NULL
)
7662 handle_notification (rs
->notif_state
, *buf
);
7664 /* Notifications require no acknowledgement. */
7666 if (expecting_notif
)
7673 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7675 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7679 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7682 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7688 remote_kill (struct target_ops
*ops
)
7690 volatile struct gdb_exception ex
;
7692 /* Catch errors so the user can quit from gdb even when we
7693 aren't on speaking terms with the remote system. */
7694 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
7700 if (ex
.error
== TARGET_CLOSE_ERROR
)
7702 /* If we got an (EOF) error that caused the target
7703 to go away, then we're done, that's what we wanted.
7704 "k" is susceptible to cause a premature EOF, given
7705 that the remote server isn't actually required to
7706 reply to "k", and it can happen that it doesn't
7707 even get to reply ACK to the "k". */
7711 /* Otherwise, something went wrong. We didn't actually kill
7712 the target. Just propagate the exception, and let the
7713 user or higher layers decide what to do. */
7714 throw_exception (ex
);
7717 /* We've killed the remote end, we get to mourn it. Since this is
7718 target remote, single-process, mourning the inferior also
7719 unpushes remote_ops. */
7720 target_mourn_inferior ();
7724 remote_vkill (int pid
, struct remote_state
*rs
)
7726 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
7729 /* Tell the remote target to detach. */
7730 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7732 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7734 switch (packet_ok (rs
->buf
,
7735 &remote_protocol_packets
[PACKET_vKill
]))
7741 case PACKET_UNKNOWN
:
7744 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7749 extended_remote_kill (struct target_ops
*ops
)
7752 int pid
= ptid_get_pid (inferior_ptid
);
7753 struct remote_state
*rs
= get_remote_state ();
7755 res
= remote_vkill (pid
, rs
);
7756 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7758 /* Don't try 'k' on a multi-process aware stub -- it has no way
7759 to specify the pid. */
7763 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7764 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7767 /* Don't wait for it to die. I'm not really sure it matters whether
7768 we do or not. For the existing stubs, kill is a noop. */
7774 error (_("Can't kill process"));
7776 target_mourn_inferior ();
7780 remote_mourn (struct target_ops
*ops
)
7782 remote_mourn_1 (ops
);
7785 /* Worker function for remote_mourn. */
7787 remote_mourn_1 (struct target_ops
*target
)
7789 unpush_target (target
);
7791 /* remote_close takes care of doing most of the clean up. */
7792 generic_mourn_inferior ();
7796 extended_remote_mourn_1 (struct target_ops
*target
)
7798 struct remote_state
*rs
= get_remote_state ();
7800 /* In case we got here due to an error, but we're going to stay
7802 rs
->waiting_for_stop_reply
= 0;
7804 /* If the current general thread belonged to the process we just
7805 detached from or has exited, the remote side current general
7806 thread becomes undefined. Considering a case like this:
7808 - We just got here due to a detach.
7809 - The process that we're detaching from happens to immediately
7810 report a global breakpoint being hit in non-stop mode, in the
7811 same thread we had selected before.
7812 - GDB attaches to this process again.
7813 - This event happens to be the next event we handle.
7815 GDB would consider that the current general thread didn't need to
7816 be set on the stub side (with Hg), since for all it knew,
7817 GENERAL_THREAD hadn't changed.
7819 Notice that although in all-stop mode, the remote server always
7820 sets the current thread to the thread reporting the stop event,
7821 that doesn't happen in non-stop mode; in non-stop, the stub *must
7822 not* change the current thread when reporting a breakpoint hit,
7823 due to the decoupling of event reporting and event handling.
7825 To keep things simple, we always invalidate our notion of the
7827 record_currthread (rs
, minus_one_ptid
);
7829 /* Unlike "target remote", we do not want to unpush the target; then
7830 the next time the user says "run", we won't be connected. */
7832 /* Call common code to mark the inferior as not running. */
7833 generic_mourn_inferior ();
7835 if (!have_inferiors ())
7837 if (!remote_multi_process_p (rs
))
7839 /* Check whether the target is running now - some remote stubs
7840 automatically restart after kill. */
7842 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7844 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7846 /* Assume that the target has been restarted. Set
7847 inferior_ptid so that bits of core GDB realizes
7848 there's something here, e.g., so that the user can
7849 say "kill" again. */
7850 inferior_ptid
= magic_null_ptid
;
7857 extended_remote_mourn (struct target_ops
*ops
)
7859 extended_remote_mourn_1 (ops
);
7863 extended_remote_supports_disable_randomization (struct target_ops
*self
)
7865 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
7869 extended_remote_disable_randomization (int val
)
7871 struct remote_state
*rs
= get_remote_state ();
7874 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7877 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7879 error (_("Target does not support QDisableRandomization."));
7880 if (strcmp (reply
, "OK") != 0)
7881 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7885 extended_remote_run (char *args
)
7887 struct remote_state
*rs
= get_remote_state ();
7890 /* If the user has disabled vRun support, or we have detected that
7891 support is not available, do not try it. */
7892 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
7895 strcpy (rs
->buf
, "vRun;");
7896 len
= strlen (rs
->buf
);
7898 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7899 error (_("Remote file name too long for run packet"));
7900 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
7901 strlen (remote_exec_file
));
7903 gdb_assert (args
!= NULL
);
7906 struct cleanup
*back_to
;
7910 argv
= gdb_buildargv (args
);
7911 back_to
= make_cleanup_freeargv (argv
);
7912 for (i
= 0; argv
[i
] != NULL
; i
++)
7914 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7915 error (_("Argument list too long for run packet"));
7916 rs
->buf
[len
++] = ';';
7917 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
7920 do_cleanups (back_to
);
7923 rs
->buf
[len
++] = '\0';
7926 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7928 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
7931 /* We have a wait response. All is well. */
7933 case PACKET_UNKNOWN
:
7936 if (remote_exec_file
[0] == '\0')
7937 error (_("Running the default executable on the remote target failed; "
7938 "try \"set remote exec-file\"?"));
7940 error (_("Running \"%s\" on the remote target failed"),
7943 gdb_assert_not_reached (_("bad switch"));
7947 /* In the extended protocol we want to be able to do things like
7948 "run" and have them basically work as expected. So we need
7949 a special create_inferior function. We support changing the
7950 executable file and the command line arguments, but not the
7954 extended_remote_create_inferior (struct target_ops
*ops
,
7955 char *exec_file
, char *args
,
7956 char **env
, int from_tty
)
7960 struct remote_state
*rs
= get_remote_state ();
7962 /* If running asynchronously, register the target file descriptor
7963 with the event loop. */
7964 if (target_can_async_p ())
7965 target_async (inferior_event_handler
, 0);
7967 /* Disable address space randomization if requested (and supported). */
7968 if (extended_remote_supports_disable_randomization (ops
))
7969 extended_remote_disable_randomization (disable_randomization
);
7971 /* Now restart the remote server. */
7972 run_worked
= extended_remote_run (args
) != -1;
7975 /* vRun was not supported. Fail if we need it to do what the
7977 if (remote_exec_file
[0])
7978 error (_("Remote target does not support \"set remote exec-file\""));
7980 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7982 /* Fall back to "R". */
7983 extended_remote_restart ();
7986 if (!have_inferiors ())
7988 /* Clean up from the last time we ran, before we mark the target
7989 running again. This will mark breakpoints uninserted, and
7990 get_offsets may insert breakpoints. */
7991 init_thread_list ();
7992 init_wait_for_inferior ();
7995 /* vRun's success return is a stop reply. */
7996 stop_reply
= run_worked
? rs
->buf
: NULL
;
7997 add_current_inferior_and_thread (stop_reply
);
7999 /* Get updated offsets, if the stub uses qOffsets. */
8004 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8005 the list of conditions (in agent expression bytecode format), if any, the
8006 target needs to evaluate. The output is placed into the packet buffer
8007 started from BUF and ended at BUF_END. */
8010 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8011 struct bp_target_info
*bp_tgt
, char *buf
,
8014 struct agent_expr
*aexpr
= NULL
;
8017 char *buf_start
= buf
;
8019 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8022 buf
+= strlen (buf
);
8023 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8026 /* Send conditions to the target and free the vector. */
8028 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8031 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8032 buf
+= strlen (buf
);
8033 for (i
= 0; i
< aexpr
->len
; ++i
)
8034 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8041 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8042 struct bp_target_info
*bp_tgt
, char *buf
)
8044 struct agent_expr
*aexpr
= NULL
;
8047 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8050 buf
+= strlen (buf
);
8052 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8053 buf
+= strlen (buf
);
8055 /* Concatenate all the agent expressions that are commands into the
8058 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8061 sprintf (buf
, "X%x,", aexpr
->len
);
8062 buf
+= strlen (buf
);
8063 for (i
= 0; i
< aexpr
->len
; ++i
)
8064 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8069 /* Insert a breakpoint. On targets that have software breakpoint
8070 support, we ask the remote target to do the work; on targets
8071 which don't, we insert a traditional memory breakpoint. */
8074 remote_insert_breakpoint (struct target_ops
*ops
,
8075 struct gdbarch
*gdbarch
,
8076 struct bp_target_info
*bp_tgt
)
8078 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8079 If it succeeds, then set the support to PACKET_ENABLE. If it
8080 fails, and the user has explicitly requested the Z support then
8081 report an error, otherwise, mark it disabled and go on. */
8083 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8085 CORE_ADDR addr
= bp_tgt
->placed_address
;
8086 struct remote_state
*rs
;
8089 struct condition_list
*cond
= NULL
;
8091 /* Make sure the remote is pointing at the right process, if
8093 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8094 set_general_process ();
8096 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8098 rs
= get_remote_state ();
8100 endbuf
= rs
->buf
+ get_remote_packet_size ();
8105 addr
= (ULONGEST
) remote_address_masked (addr
);
8106 p
+= hexnumstr (p
, addr
);
8107 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8109 if (remote_supports_cond_breakpoints (ops
))
8110 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8112 if (remote_can_run_breakpoint_commands (ops
))
8113 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8116 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8118 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8123 bp_tgt
->placed_address
= addr
;
8124 bp_tgt
->placed_size
= bpsize
;
8126 case PACKET_UNKNOWN
:
8131 /* If this breakpoint has target-side commands but this stub doesn't
8132 support Z0 packets, throw error. */
8133 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8134 throw_error (NOT_SUPPORTED_ERROR
, _("\
8135 Target doesn't support breakpoints that have target side commands."));
8137 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8141 remote_remove_breakpoint (struct target_ops
*ops
,
8142 struct gdbarch
*gdbarch
,
8143 struct bp_target_info
*bp_tgt
)
8145 CORE_ADDR addr
= bp_tgt
->placed_address
;
8146 struct remote_state
*rs
= get_remote_state ();
8148 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8151 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8153 /* Make sure the remote is pointing at the right process, if
8155 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8156 set_general_process ();
8162 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8163 p
+= hexnumstr (p
, addr
);
8164 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8167 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8169 return (rs
->buf
[0] == 'E');
8172 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8176 watchpoint_to_Z_packet (int type
)
8181 return Z_PACKET_WRITE_WP
;
8184 return Z_PACKET_READ_WP
;
8187 return Z_PACKET_ACCESS_WP
;
8190 internal_error (__FILE__
, __LINE__
,
8191 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8196 remote_insert_watchpoint (struct target_ops
*self
,
8197 CORE_ADDR addr
, int len
, int type
,
8198 struct expression
*cond
)
8200 struct remote_state
*rs
= get_remote_state ();
8201 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8203 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8205 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8208 /* Make sure the remote is pointing at the right process, if
8210 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8211 set_general_process ();
8213 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8214 p
= strchr (rs
->buf
, '\0');
8215 addr
= remote_address_masked (addr
);
8216 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8217 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8220 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8222 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8226 case PACKET_UNKNOWN
:
8231 internal_error (__FILE__
, __LINE__
,
8232 _("remote_insert_watchpoint: reached end of function"));
8236 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8237 CORE_ADDR start
, int length
)
8239 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8241 return diff
< length
;
8246 remote_remove_watchpoint (struct target_ops
*self
,
8247 CORE_ADDR addr
, int len
, int type
,
8248 struct expression
*cond
)
8250 struct remote_state
*rs
= get_remote_state ();
8251 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8253 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8255 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8258 /* Make sure the remote is pointing at the right process, if
8260 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8261 set_general_process ();
8263 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8264 p
= strchr (rs
->buf
, '\0');
8265 addr
= remote_address_masked (addr
);
8266 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8267 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8269 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8271 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8274 case PACKET_UNKNOWN
:
8279 internal_error (__FILE__
, __LINE__
,
8280 _("remote_remove_watchpoint: reached end of function"));
8284 int remote_hw_watchpoint_limit
= -1;
8285 int remote_hw_watchpoint_length_limit
= -1;
8286 int remote_hw_breakpoint_limit
= -1;
8289 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8290 CORE_ADDR addr
, int len
)
8292 if (remote_hw_watchpoint_length_limit
== 0)
8294 else if (remote_hw_watchpoint_length_limit
< 0)
8296 else if (len
<= remote_hw_watchpoint_length_limit
)
8303 remote_check_watch_resources (struct target_ops
*self
,
8304 int type
, int cnt
, int ot
)
8306 if (type
== bp_hardware_breakpoint
)
8308 if (remote_hw_breakpoint_limit
== 0)
8310 else if (remote_hw_breakpoint_limit
< 0)
8312 else if (cnt
<= remote_hw_breakpoint_limit
)
8317 if (remote_hw_watchpoint_limit
== 0)
8319 else if (remote_hw_watchpoint_limit
< 0)
8323 else if (cnt
<= remote_hw_watchpoint_limit
)
8330 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8332 struct remote_state
*rs
= get_remote_state ();
8334 return rs
->remote_stopped_by_watchpoint_p
;
8338 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8340 struct remote_state
*rs
= get_remote_state ();
8343 if (remote_stopped_by_watchpoint (target
))
8345 *addr_p
= rs
->remote_watch_data_address
;
8354 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8355 struct bp_target_info
*bp_tgt
)
8358 struct remote_state
*rs
;
8362 /* The length field should be set to the size of a breakpoint
8363 instruction, even though we aren't inserting one ourselves. */
8365 gdbarch_remote_breakpoint_from_pc
8366 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8368 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8371 /* Make sure the remote is pointing at the right process, if
8373 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8374 set_general_process ();
8376 rs
= get_remote_state ();
8378 endbuf
= rs
->buf
+ get_remote_packet_size ();
8384 addr
= remote_address_masked (bp_tgt
->placed_address
);
8385 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8386 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8388 if (remote_supports_cond_breakpoints (self
))
8389 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8391 if (remote_can_run_breakpoint_commands (self
))
8392 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8395 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8397 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8400 if (rs
->buf
[1] == '.')
8402 message
= strchr (rs
->buf
+ 2, '.');
8404 error (_("Remote failure reply: %s"), message
+ 1);
8407 case PACKET_UNKNOWN
:
8412 internal_error (__FILE__
, __LINE__
,
8413 _("remote_insert_hw_breakpoint: reached end of function"));
8418 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8419 struct bp_target_info
*bp_tgt
)
8422 struct remote_state
*rs
= get_remote_state ();
8424 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8426 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8429 /* Make sure the remote is pointing at the right process, if
8431 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8432 set_general_process ();
8438 addr
= remote_address_masked (bp_tgt
->placed_address
);
8439 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8440 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8443 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8445 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8448 case PACKET_UNKNOWN
:
8453 internal_error (__FILE__
, __LINE__
,
8454 _("remote_remove_hw_breakpoint: reached end of function"));
8457 /* Verify memory using the "qCRC:" request. */
8460 remote_verify_memory (struct target_ops
*ops
,
8461 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8463 struct remote_state
*rs
= get_remote_state ();
8464 unsigned long host_crc
, target_crc
;
8467 /* It doesn't make sense to use qCRC if the remote target is
8468 connected but not running. */
8469 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
8471 enum packet_result result
;
8473 /* Make sure the remote is pointing at the right process. */
8474 set_general_process ();
8476 /* FIXME: assumes lma can fit into long. */
8477 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8478 (long) lma
, (long) size
);
8481 /* Be clever; compute the host_crc before waiting for target
8483 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8485 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8487 result
= packet_ok (rs
->buf
,
8488 &remote_protocol_packets
[PACKET_qCRC
]);
8489 if (result
== PACKET_ERROR
)
8491 else if (result
== PACKET_OK
)
8493 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8494 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8496 return (host_crc
== target_crc
);
8500 return simple_verify_memory (ops
, data
, lma
, size
);
8503 /* compare-sections command
8505 With no arguments, compares each loadable section in the exec bfd
8506 with the same memory range on the target, and reports mismatches.
8507 Useful for verifying the image on the target against the exec file. */
8510 compare_sections_command (char *args
, int from_tty
)
8513 struct cleanup
*old_chain
;
8515 const char *sectname
;
8524 error (_("command cannot be used without an exec file"));
8526 /* Make sure the remote is pointing at the right process. */
8527 set_general_process ();
8529 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
8535 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8537 if (!(s
->flags
& SEC_LOAD
))
8538 continue; /* Skip non-loadable section. */
8540 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
8541 continue; /* Skip writeable sections */
8543 size
= bfd_get_section_size (s
);
8545 continue; /* Skip zero-length section. */
8547 sectname
= bfd_get_section_name (exec_bfd
, s
);
8548 if (args
&& strcmp (args
, sectname
) != 0)
8549 continue; /* Not the section selected by user. */
8551 matched
= 1; /* Do this section. */
8554 sectdata
= xmalloc (size
);
8555 old_chain
= make_cleanup (xfree
, sectdata
);
8556 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8558 res
= target_verify_memory (sectdata
, lma
, size
);
8561 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8562 paddress (target_gdbarch (), lma
),
8563 paddress (target_gdbarch (), lma
+ size
));
8565 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8566 paddress (target_gdbarch (), lma
),
8567 paddress (target_gdbarch (), lma
+ size
));
8569 printf_filtered ("matched.\n");
8572 printf_filtered ("MIS-MATCHED!\n");
8576 do_cleanups (old_chain
);
8579 warning (_("One or more sections of the target image does not match\n\
8580 the loaded file\n"));
8581 if (args
&& !matched
)
8582 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8585 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8586 into remote target. The number of bytes written to the remote
8587 target is returned, or -1 for error. */
8589 static enum target_xfer_status
8590 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8591 const char *annex
, const gdb_byte
*writebuf
,
8592 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
8593 struct packet_config
*packet
)
8597 struct remote_state
*rs
= get_remote_state ();
8598 int max_size
= get_memory_write_packet_size ();
8600 if (packet
->support
== PACKET_DISABLE
)
8601 return TARGET_XFER_E_IO
;
8603 /* Insert header. */
8604 i
= snprintf (rs
->buf
, max_size
,
8605 "qXfer:%s:write:%s:%s:",
8606 object_name
, annex
? annex
: "",
8607 phex_nz (offset
, sizeof offset
));
8608 max_size
-= (i
+ 1);
8610 /* Escape as much data as fits into rs->buf. */
8611 buf_len
= remote_escape_output
8612 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8614 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8615 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8616 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8617 return TARGET_XFER_E_IO
;
8619 unpack_varlen_hex (rs
->buf
, &n
);
8622 return TARGET_XFER_OK
;
8625 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8626 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8627 number of bytes read is returned, or 0 for EOF, or -1 for error.
8628 The number of bytes read may be less than LEN without indicating an
8629 EOF. PACKET is checked and updated to indicate whether the remote
8630 target supports this object. */
8632 static enum target_xfer_status
8633 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8635 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8636 ULONGEST
*xfered_len
,
8637 struct packet_config
*packet
)
8639 struct remote_state
*rs
= get_remote_state ();
8640 LONGEST i
, n
, packet_len
;
8642 if (packet
->support
== PACKET_DISABLE
)
8643 return TARGET_XFER_E_IO
;
8645 /* Check whether we've cached an end-of-object packet that matches
8647 if (rs
->finished_object
)
8649 if (strcmp (object_name
, rs
->finished_object
) == 0
8650 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8651 && offset
== rs
->finished_offset
)
8652 return TARGET_XFER_EOF
;
8655 /* Otherwise, we're now reading something different. Discard
8657 xfree (rs
->finished_object
);
8658 xfree (rs
->finished_annex
);
8659 rs
->finished_object
= NULL
;
8660 rs
->finished_annex
= NULL
;
8663 /* Request only enough to fit in a single packet. The actual data
8664 may not, since we don't know how much of it will need to be escaped;
8665 the target is free to respond with slightly less data. We subtract
8666 five to account for the response type and the protocol frame. */
8667 n
= min (get_remote_packet_size () - 5, len
);
8668 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8669 object_name
, annex
? annex
: "",
8670 phex_nz (offset
, sizeof offset
),
8671 phex_nz (n
, sizeof n
));
8672 i
= putpkt (rs
->buf
);
8674 return TARGET_XFER_E_IO
;
8677 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8678 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8679 return TARGET_XFER_E_IO
;
8681 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8682 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8684 /* 'm' means there is (or at least might be) more data after this
8685 batch. That does not make sense unless there's at least one byte
8686 of data in this reply. */
8687 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8688 error (_("Remote qXfer reply contained no data."));
8690 /* Got some data. */
8691 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8692 packet_len
- 1, readbuf
, n
);
8694 /* 'l' is an EOF marker, possibly including a final block of data,
8695 or possibly empty. If we have the final block of a non-empty
8696 object, record this fact to bypass a subsequent partial read. */
8697 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8699 rs
->finished_object
= xstrdup (object_name
);
8700 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8701 rs
->finished_offset
= offset
+ i
;
8705 return TARGET_XFER_EOF
;
8709 return TARGET_XFER_OK
;
8713 static enum target_xfer_status
8714 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8715 const char *annex
, gdb_byte
*readbuf
,
8716 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
8717 ULONGEST
*xfered_len
)
8719 struct remote_state
*rs
;
8724 set_remote_traceframe ();
8725 set_general_thread (inferior_ptid
);
8727 rs
= get_remote_state ();
8729 /* Handle memory using the standard memory routines. */
8730 if (object
== TARGET_OBJECT_MEMORY
)
8732 /* If the remote target is connected but not running, we should
8733 pass this request down to a lower stratum (e.g. the executable
8735 if (!target_has_execution
)
8736 return TARGET_XFER_EOF
;
8738 if (writebuf
!= NULL
)
8739 return remote_write_bytes (offset
, writebuf
, len
, xfered_len
);
8741 return remote_read_bytes (ops
, offset
, readbuf
, len
, xfered_len
);
8744 /* Handle SPU memory using qxfer packets. */
8745 if (object
== TARGET_OBJECT_SPU
)
8748 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8749 xfered_len
, &remote_protocol_packets
8750 [PACKET_qXfer_spu_read
]);
8752 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8753 xfered_len
, &remote_protocol_packets
8754 [PACKET_qXfer_spu_write
]);
8757 /* Handle extra signal info using qxfer packets. */
8758 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8761 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8762 xfered_len
, &remote_protocol_packets
8763 [PACKET_qXfer_siginfo_read
]);
8765 return remote_write_qxfer (ops
, "siginfo", annex
,
8766 writebuf
, offset
, len
, xfered_len
,
8767 &remote_protocol_packets
8768 [PACKET_qXfer_siginfo_write
]);
8771 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8774 return remote_read_qxfer (ops
, "statictrace", annex
,
8775 readbuf
, offset
, len
, xfered_len
,
8776 &remote_protocol_packets
8777 [PACKET_qXfer_statictrace_read
]);
8779 return TARGET_XFER_E_IO
;
8782 /* Only handle flash writes. */
8783 if (writebuf
!= NULL
)
8789 case TARGET_OBJECT_FLASH
:
8790 return remote_flash_write (ops
, offset
, len
, xfered_len
,
8794 return TARGET_XFER_E_IO
;
8798 /* Map pre-existing objects onto letters. DO NOT do this for new
8799 objects!!! Instead specify new query packets. */
8802 case TARGET_OBJECT_AVR
:
8806 case TARGET_OBJECT_AUXV
:
8807 gdb_assert (annex
== NULL
);
8808 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8810 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8812 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8813 return remote_read_qxfer
8814 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
8815 &remote_protocol_packets
[PACKET_qXfer_features
]);
8817 case TARGET_OBJECT_LIBRARIES
:
8818 return remote_read_qxfer
8819 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
8820 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8822 case TARGET_OBJECT_LIBRARIES_SVR4
:
8823 return remote_read_qxfer
8824 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
8825 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8827 case TARGET_OBJECT_MEMORY_MAP
:
8828 gdb_assert (annex
== NULL
);
8829 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8831 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8833 case TARGET_OBJECT_OSDATA
:
8834 /* Should only get here if we're connected. */
8835 gdb_assert (rs
->remote_desc
);
8836 return remote_read_qxfer
8837 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
8838 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8840 case TARGET_OBJECT_THREADS
:
8841 gdb_assert (annex
== NULL
);
8842 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8844 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8846 case TARGET_OBJECT_TRACEFRAME_INFO
:
8847 gdb_assert (annex
== NULL
);
8848 return remote_read_qxfer
8849 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
8850 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8852 case TARGET_OBJECT_FDPIC
:
8853 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8855 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8857 case TARGET_OBJECT_OPENVMS_UIB
:
8858 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8860 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8862 case TARGET_OBJECT_BTRACE
:
8863 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
8865 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
8868 return TARGET_XFER_E_IO
;
8871 /* Note: a zero OFFSET and LEN can be used to query the minimum
8873 if (offset
== 0 && len
== 0)
8874 return (get_remote_packet_size ());
8875 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8876 large enough let the caller deal with it. */
8877 if (len
< get_remote_packet_size ())
8878 return TARGET_XFER_E_IO
;
8879 len
= get_remote_packet_size ();
8881 /* Except for querying the minimum buffer size, target must be open. */
8882 if (!rs
->remote_desc
)
8883 error (_("remote query is only available after target open"));
8885 gdb_assert (annex
!= NULL
);
8886 gdb_assert (readbuf
!= NULL
);
8892 /* We used one buffer char for the remote protocol q command and
8893 another for the query type. As the remote protocol encapsulation
8894 uses 4 chars plus one extra in case we are debugging
8895 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8898 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8900 /* Bad caller may have sent forbidden characters. */
8901 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8906 gdb_assert (annex
[i
] == '\0');
8908 i
= putpkt (rs
->buf
);
8910 return TARGET_XFER_E_IO
;
8912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8913 strcpy ((char *) readbuf
, rs
->buf
);
8915 *xfered_len
= strlen ((char *) readbuf
);
8916 return TARGET_XFER_OK
;
8920 remote_search_memory (struct target_ops
* ops
,
8921 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8922 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8923 CORE_ADDR
*found_addrp
)
8925 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8926 struct remote_state
*rs
= get_remote_state ();
8927 int max_size
= get_memory_write_packet_size ();
8928 struct packet_config
*packet
=
8929 &remote_protocol_packets
[PACKET_qSearch_memory
];
8930 /* Number of packet bytes used to encode the pattern;
8931 this could be more than PATTERN_LEN due to escape characters. */
8932 int escaped_pattern_len
;
8933 /* Amount of pattern that was encodable in the packet. */
8934 int used_pattern_len
;
8937 ULONGEST found_addr
;
8939 /* Don't go to the target if we don't have to.
8940 This is done before checking packet->support to avoid the possibility that
8941 a success for this edge case means the facility works in general. */
8942 if (pattern_len
> search_space_len
)
8944 if (pattern_len
== 0)
8946 *found_addrp
= start_addr
;
8950 /* If we already know the packet isn't supported, fall back to the simple
8951 way of searching memory. */
8953 if (packet_config_support (packet
) == PACKET_DISABLE
)
8955 /* Target doesn't provided special support, fall back and use the
8956 standard support (copy memory and do the search here). */
8957 return simple_search_memory (ops
, start_addr
, search_space_len
,
8958 pattern
, pattern_len
, found_addrp
);
8961 /* Make sure the remote is pointing at the right process. */
8962 set_general_process ();
8964 /* Insert header. */
8965 i
= snprintf (rs
->buf
, max_size
,
8966 "qSearch:memory:%s;%s;",
8967 phex_nz (start_addr
, addr_size
),
8968 phex_nz (search_space_len
, sizeof (search_space_len
)));
8969 max_size
-= (i
+ 1);
8971 /* Escape as much data as fits into rs->buf. */
8972 escaped_pattern_len
=
8973 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
8974 &used_pattern_len
, max_size
);
8976 /* Bail if the pattern is too large. */
8977 if (used_pattern_len
!= pattern_len
)
8978 error (_("Pattern is too large to transmit to remote target."));
8980 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8981 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8982 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8984 /* The request may not have worked because the command is not
8985 supported. If so, fall back to the simple way. */
8986 if (packet
->support
== PACKET_DISABLE
)
8988 return simple_search_memory (ops
, start_addr
, search_space_len
,
8989 pattern
, pattern_len
, found_addrp
);
8994 if (rs
->buf
[0] == '0')
8996 else if (rs
->buf
[0] == '1')
8999 if (rs
->buf
[1] != ',')
9000 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9001 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9002 *found_addrp
= found_addr
;
9005 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9011 remote_rcmd (struct target_ops
*self
, const char *command
,
9012 struct ui_file
*outbuf
)
9014 struct remote_state
*rs
= get_remote_state ();
9017 if (!rs
->remote_desc
)
9018 error (_("remote rcmd is only available after target open"));
9020 /* Send a NULL command across as an empty command. */
9021 if (command
== NULL
)
9024 /* The query prefix. */
9025 strcpy (rs
->buf
, "qRcmd,");
9026 p
= strchr (rs
->buf
, '\0');
9028 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9029 > get_remote_packet_size ())
9030 error (_("\"monitor\" command ``%s'' is too long."), command
);
9032 /* Encode the actual command. */
9033 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9035 if (putpkt (rs
->buf
) < 0)
9036 error (_("Communication problem with target."));
9038 /* get/display the response */
9043 /* XXX - see also remote_get_noisy_reply(). */
9044 QUIT
; /* Allow user to bail out with ^C. */
9046 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9048 /* Timeout. Continue to (try to) read responses.
9049 This is better than stopping with an error, assuming the stub
9050 is still executing the (long) monitor command.
9051 If needed, the user can interrupt gdb using C-c, obtaining
9052 an effect similar to stop on timeout. */
9057 error (_("Target does not support this command."));
9058 if (buf
[0] == 'O' && buf
[1] != 'K')
9060 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9063 if (strcmp (buf
, "OK") == 0)
9065 if (strlen (buf
) == 3 && buf
[0] == 'E'
9066 && isdigit (buf
[1]) && isdigit (buf
[2]))
9068 error (_("Protocol error with Rcmd"));
9070 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9072 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9074 fputc_unfiltered (c
, outbuf
);
9080 static VEC(mem_region_s
) *
9081 remote_memory_map (struct target_ops
*ops
)
9083 VEC(mem_region_s
) *result
= NULL
;
9084 char *text
= target_read_stralloc (¤t_target
,
9085 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9089 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9091 result
= parse_memory_map (text
);
9092 do_cleanups (back_to
);
9099 packet_command (char *args
, int from_tty
)
9101 struct remote_state
*rs
= get_remote_state ();
9103 if (!rs
->remote_desc
)
9104 error (_("command can only be used with remote target"));
9107 error (_("remote-packet command requires packet text as argument"));
9109 puts_filtered ("sending: ");
9110 print_packet (args
);
9111 puts_filtered ("\n");
9114 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9115 puts_filtered ("received: ");
9116 print_packet (rs
->buf
);
9117 puts_filtered ("\n");
9121 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9123 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9125 static void threadset_test_cmd (char *cmd
, int tty
);
9127 static void threadalive_test (char *cmd
, int tty
);
9129 static void threadlist_test_cmd (char *cmd
, int tty
);
9131 int get_and_display_threadinfo (threadref
*ref
);
9133 static void threadinfo_test_cmd (char *cmd
, int tty
);
9135 static int thread_display_step (threadref
*ref
, void *context
);
9137 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9139 static void init_remote_threadtests (void);
9141 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9144 threadset_test_cmd (char *cmd
, int tty
)
9146 int sample_thread
= SAMPLE_THREAD
;
9148 printf_filtered (_("Remote threadset test\n"));
9149 set_general_thread (sample_thread
);
9154 threadalive_test (char *cmd
, int tty
)
9156 int sample_thread
= SAMPLE_THREAD
;
9157 int pid
= ptid_get_pid (inferior_ptid
);
9158 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9160 if (remote_thread_alive (ptid
))
9161 printf_filtered ("PASS: Thread alive test\n");
9163 printf_filtered ("FAIL: Thread alive test\n");
9166 void output_threadid (char *title
, threadref
*ref
);
9169 output_threadid (char *title
, threadref
*ref
)
9173 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9175 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9179 threadlist_test_cmd (char *cmd
, int tty
)
9182 threadref nextthread
;
9183 int done
, result_count
;
9184 threadref threadlist
[3];
9186 printf_filtered ("Remote Threadlist test\n");
9187 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9188 &result_count
, &threadlist
[0]))
9189 printf_filtered ("FAIL: threadlist test\n");
9192 threadref
*scan
= threadlist
;
9193 threadref
*limit
= scan
+ result_count
;
9195 while (scan
< limit
)
9196 output_threadid (" thread ", scan
++);
9201 display_thread_info (struct gdb_ext_thread_info
*info
)
9203 output_threadid ("Threadid: ", &info
->threadid
);
9204 printf_filtered ("Name: %s\n ", info
->shortname
);
9205 printf_filtered ("State: %s\n", info
->display
);
9206 printf_filtered ("other: %s\n\n", info
->more_display
);
9210 get_and_display_threadinfo (threadref
*ref
)
9214 struct gdb_ext_thread_info threadinfo
;
9216 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9217 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9218 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9219 display_thread_info (&threadinfo
);
9224 threadinfo_test_cmd (char *cmd
, int tty
)
9226 int athread
= SAMPLE_THREAD
;
9230 int_to_threadref (&thread
, athread
);
9231 printf_filtered ("Remote Threadinfo test\n");
9232 if (!get_and_display_threadinfo (&thread
))
9233 printf_filtered ("FAIL cannot get thread info\n");
9237 thread_display_step (threadref
*ref
, void *context
)
9239 /* output_threadid(" threadstep ",ref); *//* simple test */
9240 return get_and_display_threadinfo (ref
);
9244 threadlist_update_test_cmd (char *cmd
, int tty
)
9246 printf_filtered ("Remote Threadlist update test\n");
9247 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9251 init_remote_threadtests (void)
9253 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9254 _("Fetch and print the remote list of "
9255 "thread identifiers, one pkt only"));
9256 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9257 _("Fetch and display info about one thread"));
9258 add_com ("tset", class_obscure
, threadset_test_cmd
,
9259 _("Test setting to a different thread"));
9260 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9261 _("Iterate through updating all remote thread info"));
9262 add_com ("talive", class_obscure
, threadalive_test
,
9263 _(" Remote thread alive test "));
9268 /* Convert a thread ID to a string. Returns the string in a static
9272 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9274 static char buf
[64];
9275 struct remote_state
*rs
= get_remote_state ();
9277 if (ptid_equal (ptid
, null_ptid
))
9278 return normal_pid_to_str (ptid
);
9279 else if (ptid_is_pid (ptid
))
9281 /* Printing an inferior target id. */
9283 /* When multi-process extensions are off, there's no way in the
9284 remote protocol to know the remote process id, if there's any
9285 at all. There's one exception --- when we're connected with
9286 target extended-remote, and we manually attached to a process
9287 with "attach PID". We don't record anywhere a flag that
9288 allows us to distinguish that case from the case of
9289 connecting with extended-remote and the stub already being
9290 attached to a process, and reporting yes to qAttached, hence
9291 no smart special casing here. */
9292 if (!remote_multi_process_p (rs
))
9294 xsnprintf (buf
, sizeof buf
, "Remote target");
9298 return normal_pid_to_str (ptid
);
9302 if (ptid_equal (magic_null_ptid
, ptid
))
9303 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9304 else if (rs
->extended
&& remote_multi_process_p (rs
))
9305 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9306 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9308 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9309 ptid_get_lwp (ptid
));
9314 /* Get the address of the thread local variable in OBJFILE which is
9315 stored at OFFSET within the thread local storage for thread PTID. */
9318 remote_get_thread_local_address (struct target_ops
*ops
,
9319 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9321 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9323 struct remote_state
*rs
= get_remote_state ();
9325 char *endp
= rs
->buf
+ get_remote_packet_size ();
9326 enum packet_result result
;
9328 strcpy (p
, "qGetTLSAddr:");
9330 p
= write_ptid (p
, endp
, ptid
);
9332 p
+= hexnumstr (p
, offset
);
9334 p
+= hexnumstr (p
, lm
);
9338 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9339 result
= packet_ok (rs
->buf
,
9340 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9341 if (result
== PACKET_OK
)
9345 unpack_varlen_hex (rs
->buf
, &result
);
9348 else if (result
== PACKET_UNKNOWN
)
9349 throw_error (TLS_GENERIC_ERROR
,
9350 _("Remote target doesn't support qGetTLSAddr packet"));
9352 throw_error (TLS_GENERIC_ERROR
,
9353 _("Remote target failed to process qGetTLSAddr request"));
9356 throw_error (TLS_GENERIC_ERROR
,
9357 _("TLS not supported or disabled on this target"));
9362 /* Provide thread local base, i.e. Thread Information Block address.
9363 Returns 1 if ptid is found and thread_local_base is non zero. */
9366 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9368 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9370 struct remote_state
*rs
= get_remote_state ();
9372 char *endp
= rs
->buf
+ get_remote_packet_size ();
9373 enum packet_result result
;
9375 strcpy (p
, "qGetTIBAddr:");
9377 p
= write_ptid (p
, endp
, ptid
);
9381 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9382 result
= packet_ok (rs
->buf
,
9383 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9384 if (result
== PACKET_OK
)
9388 unpack_varlen_hex (rs
->buf
, &result
);
9390 *addr
= (CORE_ADDR
) result
;
9393 else if (result
== PACKET_UNKNOWN
)
9394 error (_("Remote target doesn't support qGetTIBAddr packet"));
9396 error (_("Remote target failed to process qGetTIBAddr request"));
9399 error (_("qGetTIBAddr not supported or disabled on this target"));
9404 /* Support for inferring a target description based on the current
9405 architecture and the size of a 'g' packet. While the 'g' packet
9406 can have any size (since optional registers can be left off the
9407 end), some sizes are easily recognizable given knowledge of the
9408 approximate architecture. */
9410 struct remote_g_packet_guess
9413 const struct target_desc
*tdesc
;
9415 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9416 DEF_VEC_O(remote_g_packet_guess_s
);
9418 struct remote_g_packet_data
9420 VEC(remote_g_packet_guess_s
) *guesses
;
9423 static struct gdbarch_data
*remote_g_packet_data_handle
;
9426 remote_g_packet_data_init (struct obstack
*obstack
)
9428 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9432 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9433 const struct target_desc
*tdesc
)
9435 struct remote_g_packet_data
*data
9436 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9437 struct remote_g_packet_guess new_guess
, *guess
;
9440 gdb_assert (tdesc
!= NULL
);
9443 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9445 if (guess
->bytes
== bytes
)
9446 internal_error (__FILE__
, __LINE__
,
9447 _("Duplicate g packet description added for size %d"),
9450 new_guess
.bytes
= bytes
;
9451 new_guess
.tdesc
= tdesc
;
9452 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9455 /* Return 1 if remote_read_description would do anything on this target
9456 and architecture, 0 otherwise. */
9459 remote_read_description_p (struct target_ops
*target
)
9461 struct remote_g_packet_data
*data
9462 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9464 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9470 static const struct target_desc
*
9471 remote_read_description (struct target_ops
*target
)
9473 struct remote_g_packet_data
*data
9474 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9476 /* Do not try this during initial connection, when we do not know
9477 whether there is a running but stopped thread. */
9478 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9479 return target
->beneath
->to_read_description (target
->beneath
);
9481 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9483 struct remote_g_packet_guess
*guess
;
9485 int bytes
= send_g_packet ();
9488 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9490 if (guess
->bytes
== bytes
)
9491 return guess
->tdesc
;
9493 /* We discard the g packet. A minor optimization would be to
9494 hold on to it, and fill the register cache once we have selected
9495 an architecture, but it's too tricky to do safely. */
9498 return target
->beneath
->to_read_description (target
->beneath
);
9501 /* Remote file transfer support. This is host-initiated I/O, not
9502 target-initiated; for target-initiated, see remote-fileio.c. */
9504 /* If *LEFT is at least the length of STRING, copy STRING to
9505 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9506 decrease *LEFT. Otherwise raise an error. */
9509 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9511 int len
= strlen (string
);
9514 error (_("Packet too long for target."));
9516 memcpy (*buffer
, string
, len
);
9520 /* NUL-terminate the buffer as a convenience, if there is
9526 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9527 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9528 decrease *LEFT. Otherwise raise an error. */
9531 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9534 if (2 * len
> *left
)
9535 error (_("Packet too long for target."));
9537 bin2hex (bytes
, *buffer
, len
);
9541 /* NUL-terminate the buffer as a convenience, if there is
9547 /* If *LEFT is large enough, convert VALUE to hex and add it to
9548 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9549 decrease *LEFT. Otherwise raise an error. */
9552 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9554 int len
= hexnumlen (value
);
9557 error (_("Packet too long for target."));
9559 hexnumstr (*buffer
, value
);
9563 /* NUL-terminate the buffer as a convenience, if there is
9569 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9570 value, *REMOTE_ERRNO to the remote error number or zero if none
9571 was included, and *ATTACHMENT to point to the start of the annex
9572 if any. The length of the packet isn't needed here; there may
9573 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9575 Return 0 if the packet could be parsed, -1 if it could not. If
9576 -1 is returned, the other variables may not be initialized. */
9579 remote_hostio_parse_result (char *buffer
, int *retcode
,
9580 int *remote_errno
, char **attachment
)
9587 if (buffer
[0] != 'F')
9591 *retcode
= strtol (&buffer
[1], &p
, 16);
9592 if (errno
!= 0 || p
== &buffer
[1])
9595 /* Check for ",errno". */
9599 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9600 if (errno
!= 0 || p
+ 1 == p2
)
9605 /* Check for ";attachment". If there is no attachment, the
9606 packet should end here. */
9609 *attachment
= p
+ 1;
9612 else if (*p
== '\0')
9618 /* Send a prepared I/O packet to the target and read its response.
9619 The prepared packet is in the global RS->BUF before this function
9620 is called, and the answer is there when we return.
9622 COMMAND_BYTES is the length of the request to send, which may include
9623 binary data. WHICH_PACKET is the packet configuration to check
9624 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9625 is set to the error number and -1 is returned. Otherwise the value
9626 returned by the function is returned.
9628 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9629 attachment is expected; an error will be reported if there's a
9630 mismatch. If one is found, *ATTACHMENT will be set to point into
9631 the packet buffer and *ATTACHMENT_LEN will be set to the
9632 attachment's length. */
9635 remote_hostio_send_command (int command_bytes
, int which_packet
,
9636 int *remote_errno
, char **attachment
,
9637 int *attachment_len
)
9639 struct remote_state
*rs
= get_remote_state ();
9640 int ret
, bytes_read
;
9641 char *attachment_tmp
;
9643 if (!rs
->remote_desc
9644 || packet_support (which_packet
) == PACKET_DISABLE
)
9646 *remote_errno
= FILEIO_ENOSYS
;
9650 putpkt_binary (rs
->buf
, command_bytes
);
9651 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9653 /* If it timed out, something is wrong. Don't try to parse the
9657 *remote_errno
= FILEIO_EINVAL
;
9661 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9664 *remote_errno
= FILEIO_EINVAL
;
9666 case PACKET_UNKNOWN
:
9667 *remote_errno
= FILEIO_ENOSYS
;
9673 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9676 *remote_errno
= FILEIO_EINVAL
;
9680 /* Make sure we saw an attachment if and only if we expected one. */
9681 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9682 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9684 *remote_errno
= FILEIO_EINVAL
;
9688 /* If an attachment was found, it must point into the packet buffer;
9689 work out how many bytes there were. */
9690 if (attachment_tmp
!= NULL
)
9692 *attachment
= attachment_tmp
;
9693 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9699 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9700 remote file descriptor, or -1 if an error occurs (and set
9704 remote_hostio_open (struct target_ops
*self
,
9705 const char *filename
, int flags
, int mode
,
9708 struct remote_state
*rs
= get_remote_state ();
9710 int left
= get_remote_packet_size () - 1;
9712 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9714 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9716 remote_buffer_add_string (&p
, &left
, ",");
9718 remote_buffer_add_int (&p
, &left
, flags
);
9719 remote_buffer_add_string (&p
, &left
, ",");
9721 remote_buffer_add_int (&p
, &left
, mode
);
9723 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9724 remote_errno
, NULL
, NULL
);
9727 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9728 Return the number of bytes written, or -1 if an error occurs (and
9729 set *REMOTE_ERRNO). */
9732 remote_hostio_pwrite (struct target_ops
*self
,
9733 int fd
, const gdb_byte
*write_buf
, int len
,
9734 ULONGEST offset
, int *remote_errno
)
9736 struct remote_state
*rs
= get_remote_state ();
9738 int left
= get_remote_packet_size ();
9741 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9743 remote_buffer_add_int (&p
, &left
, fd
);
9744 remote_buffer_add_string (&p
, &left
, ",");
9746 remote_buffer_add_int (&p
, &left
, offset
);
9747 remote_buffer_add_string (&p
, &left
, ",");
9749 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9750 get_remote_packet_size () - (p
- rs
->buf
));
9752 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9753 remote_errno
, NULL
, NULL
);
9756 /* Read up to LEN bytes FD on the remote target into READ_BUF
9757 Return the number of bytes read, or -1 if an error occurs (and
9758 set *REMOTE_ERRNO). */
9761 remote_hostio_pread (struct target_ops
*self
,
9762 int fd
, gdb_byte
*read_buf
, int len
,
9763 ULONGEST offset
, int *remote_errno
)
9765 struct remote_state
*rs
= get_remote_state ();
9768 int left
= get_remote_packet_size ();
9769 int ret
, attachment_len
;
9772 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9774 remote_buffer_add_int (&p
, &left
, fd
);
9775 remote_buffer_add_string (&p
, &left
, ",");
9777 remote_buffer_add_int (&p
, &left
, len
);
9778 remote_buffer_add_string (&p
, &left
, ",");
9780 remote_buffer_add_int (&p
, &left
, offset
);
9782 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9783 remote_errno
, &attachment
,
9789 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9791 if (read_len
!= ret
)
9792 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9797 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9798 (and set *REMOTE_ERRNO). */
9801 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
9803 struct remote_state
*rs
= get_remote_state ();
9805 int left
= get_remote_packet_size () - 1;
9807 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9809 remote_buffer_add_int (&p
, &left
, fd
);
9811 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9812 remote_errno
, NULL
, NULL
);
9815 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9816 occurs (and set *REMOTE_ERRNO). */
9819 remote_hostio_unlink (struct target_ops
*self
,
9820 const char *filename
, int *remote_errno
)
9822 struct remote_state
*rs
= get_remote_state ();
9824 int left
= get_remote_packet_size () - 1;
9826 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9828 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9831 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9832 remote_errno
, NULL
, NULL
);
9835 /* Read value of symbolic link FILENAME on the remote target. Return
9836 a null-terminated string allocated via xmalloc, or NULL if an error
9837 occurs (and set *REMOTE_ERRNO). */
9840 remote_hostio_readlink (struct target_ops
*self
,
9841 const char *filename
, int *remote_errno
)
9843 struct remote_state
*rs
= get_remote_state ();
9846 int left
= get_remote_packet_size ();
9847 int len
, attachment_len
;
9851 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9853 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9856 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9857 remote_errno
, &attachment
,
9863 ret
= xmalloc (len
+ 1);
9865 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9866 (gdb_byte
*) ret
, len
);
9867 if (read_len
!= len
)
9868 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9875 remote_fileio_errno_to_host (int errnum
)
9899 case FILEIO_ENOTDIR
:
9919 case FILEIO_ENAMETOOLONG
:
9920 return ENAMETOOLONG
;
9926 remote_hostio_error (int errnum
)
9928 int host_error
= remote_fileio_errno_to_host (errnum
);
9930 if (host_error
== -1)
9931 error (_("Unknown remote I/O error %d"), errnum
);
9933 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9937 remote_hostio_close_cleanup (void *opaque
)
9939 int fd
= *(int *) opaque
;
9942 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
9947 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9949 const char *filename
= bfd_get_filename (abfd
);
9950 int fd
, remote_errno
;
9953 gdb_assert (remote_filename_p (filename
));
9955 fd
= remote_hostio_open (find_target_at (process_stratum
),
9956 filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9959 errno
= remote_fileio_errno_to_host (remote_errno
);
9960 bfd_set_error (bfd_error_system_call
);
9964 stream
= xmalloc (sizeof (int));
9970 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9972 int fd
= *(int *)stream
;
9977 /* Ignore errors on close; these may happen if the remote
9978 connection was already torn down. */
9979 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
9981 /* Zero means success. */
9986 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9987 file_ptr nbytes
, file_ptr offset
)
9989 int fd
= *(int *)stream
;
9991 file_ptr pos
, bytes
;
9994 while (nbytes
> pos
)
9996 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
9997 fd
, (gdb_byte
*) buf
+ pos
, nbytes
- pos
,
9998 offset
+ pos
, &remote_errno
);
10000 /* Success, but no bytes, means end-of-file. */
10004 errno
= remote_fileio_errno_to_host (remote_errno
);
10005 bfd_set_error (bfd_error_system_call
);
10016 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
10018 /* FIXME: We should probably implement remote_hostio_stat. */
10019 sb
->st_size
= INT_MAX
;
10024 remote_filename_p (const char *filename
)
10026 return strncmp (filename
,
10027 REMOTE_SYSROOT_PREFIX
,
10028 sizeof (REMOTE_SYSROOT_PREFIX
) - 1) == 0;
10032 remote_bfd_open (const char *remote_file
, const char *target
)
10034 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
10035 remote_bfd_iovec_open
, NULL
,
10036 remote_bfd_iovec_pread
,
10037 remote_bfd_iovec_close
,
10038 remote_bfd_iovec_stat
);
10044 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10046 struct cleanup
*back_to
, *close_cleanup
;
10047 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10050 int bytes_in_buffer
;
10053 struct remote_state
*rs
= get_remote_state ();
10055 if (!rs
->remote_desc
)
10056 error (_("command can only be used with remote target"));
10058 file
= gdb_fopen_cloexec (local_file
, "rb");
10060 perror_with_name (local_file
);
10061 back_to
= make_cleanup_fclose (file
);
10063 fd
= remote_hostio_open (find_target_at (process_stratum
),
10064 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10066 0700, &remote_errno
);
10068 remote_hostio_error (remote_errno
);
10070 /* Send up to this many bytes at once. They won't all fit in the
10071 remote packet limit, so we'll transfer slightly fewer. */
10072 io_size
= get_remote_packet_size ();
10073 buffer
= xmalloc (io_size
);
10074 make_cleanup (xfree
, buffer
);
10076 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10078 bytes_in_buffer
= 0;
10081 while (bytes_in_buffer
|| !saw_eof
)
10085 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10086 io_size
- bytes_in_buffer
,
10091 error (_("Error reading %s."), local_file
);
10094 /* EOF. Unless there is something still in the
10095 buffer from the last iteration, we are done. */
10097 if (bytes_in_buffer
== 0)
10105 bytes
+= bytes_in_buffer
;
10106 bytes_in_buffer
= 0;
10108 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10110 offset
, &remote_errno
);
10113 remote_hostio_error (remote_errno
);
10114 else if (retcode
== 0)
10115 error (_("Remote write of %d bytes returned 0!"), bytes
);
10116 else if (retcode
< bytes
)
10118 /* Short write. Save the rest of the read data for the next
10120 bytes_in_buffer
= bytes
- retcode
;
10121 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10127 discard_cleanups (close_cleanup
);
10128 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10129 remote_hostio_error (remote_errno
);
10132 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10133 do_cleanups (back_to
);
10137 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10139 struct cleanup
*back_to
, *close_cleanup
;
10140 int fd
, remote_errno
, bytes
, io_size
;
10144 struct remote_state
*rs
= get_remote_state ();
10146 if (!rs
->remote_desc
)
10147 error (_("command can only be used with remote target"));
10149 fd
= remote_hostio_open (find_target_at (process_stratum
),
10150 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10152 remote_hostio_error (remote_errno
);
10154 file
= gdb_fopen_cloexec (local_file
, "wb");
10156 perror_with_name (local_file
);
10157 back_to
= make_cleanup_fclose (file
);
10159 /* Send up to this many bytes at once. They won't all fit in the
10160 remote packet limit, so we'll transfer slightly fewer. */
10161 io_size
= get_remote_packet_size ();
10162 buffer
= xmalloc (io_size
);
10163 make_cleanup (xfree
, buffer
);
10165 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10170 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10171 fd
, buffer
, io_size
, offset
, &remote_errno
);
10173 /* Success, but no bytes, means end-of-file. */
10176 remote_hostio_error (remote_errno
);
10180 bytes
= fwrite (buffer
, 1, bytes
, file
);
10182 perror_with_name (local_file
);
10185 discard_cleanups (close_cleanup
);
10186 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10187 remote_hostio_error (remote_errno
);
10190 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10191 do_cleanups (back_to
);
10195 remote_file_delete (const char *remote_file
, int from_tty
)
10197 int retcode
, remote_errno
;
10198 struct remote_state
*rs
= get_remote_state ();
10200 if (!rs
->remote_desc
)
10201 error (_("command can only be used with remote target"));
10203 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10204 remote_file
, &remote_errno
);
10206 remote_hostio_error (remote_errno
);
10209 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10213 remote_put_command (char *args
, int from_tty
)
10215 struct cleanup
*back_to
;
10219 error_no_arg (_("file to put"));
10221 argv
= gdb_buildargv (args
);
10222 back_to
= make_cleanup_freeargv (argv
);
10223 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10224 error (_("Invalid parameters to remote put"));
10226 remote_file_put (argv
[0], argv
[1], from_tty
);
10228 do_cleanups (back_to
);
10232 remote_get_command (char *args
, int from_tty
)
10234 struct cleanup
*back_to
;
10238 error_no_arg (_("file to get"));
10240 argv
= gdb_buildargv (args
);
10241 back_to
= make_cleanup_freeargv (argv
);
10242 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10243 error (_("Invalid parameters to remote get"));
10245 remote_file_get (argv
[0], argv
[1], from_tty
);
10247 do_cleanups (back_to
);
10251 remote_delete_command (char *args
, int from_tty
)
10253 struct cleanup
*back_to
;
10257 error_no_arg (_("file to delete"));
10259 argv
= gdb_buildargv (args
);
10260 back_to
= make_cleanup_freeargv (argv
);
10261 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10262 error (_("Invalid parameters to remote delete"));
10264 remote_file_delete (argv
[0], from_tty
);
10266 do_cleanups (back_to
);
10270 remote_command (char *args
, int from_tty
)
10272 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10276 remote_can_execute_reverse (struct target_ops
*self
)
10278 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10279 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10286 remote_supports_non_stop (struct target_ops
*self
)
10292 remote_supports_disable_randomization (struct target_ops
*self
)
10294 /* Only supported in extended mode. */
10299 remote_supports_multi_process (struct target_ops
*self
)
10301 struct remote_state
*rs
= get_remote_state ();
10303 /* Only extended-remote handles being attached to multiple
10304 processes, even though plain remote can use the multi-process
10305 thread id extensions, so that GDB knows the target process's
10307 return rs
->extended
&& remote_multi_process_p (rs
);
10311 remote_supports_cond_tracepoints (void)
10313 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10317 remote_supports_cond_breakpoints (struct target_ops
*self
)
10319 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10323 remote_supports_fast_tracepoints (void)
10325 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
10329 remote_supports_static_tracepoints (void)
10331 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
10335 remote_supports_install_in_trace (void)
10337 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
10341 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
10343 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
10348 remote_supports_string_tracing (struct target_ops
*self
)
10350 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
10354 remote_can_run_breakpoint_commands (struct target_ops
*self
)
10356 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
10360 remote_trace_init (struct target_ops
*self
)
10363 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10364 if (strcmp (target_buf
, "OK") != 0)
10365 error (_("Target does not support this command."));
10368 static void free_actions_list (char **actions_list
);
10369 static void free_actions_list_cleanup_wrapper (void *);
10371 free_actions_list_cleanup_wrapper (void *al
)
10373 free_actions_list (al
);
10377 free_actions_list (char **actions_list
)
10381 if (actions_list
== 0)
10384 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10385 xfree (actions_list
[ndx
]);
10387 xfree (actions_list
);
10390 /* Recursive routine to walk through command list including loops, and
10391 download packets for each command. */
10394 remote_download_command_source (int num
, ULONGEST addr
,
10395 struct command_line
*cmds
)
10397 struct remote_state
*rs
= get_remote_state ();
10398 struct command_line
*cmd
;
10400 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10402 QUIT
; /* Allow user to bail out with ^C. */
10403 strcpy (rs
->buf
, "QTDPsrc:");
10404 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10405 rs
->buf
+ strlen (rs
->buf
),
10406 rs
->buf_size
- strlen (rs
->buf
));
10408 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10409 if (strcmp (target_buf
, "OK"))
10410 warning (_("Target does not support source download."));
10412 if (cmd
->control_type
== while_control
10413 || cmd
->control_type
== while_stepping_control
)
10415 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10417 QUIT
; /* Allow user to bail out with ^C. */
10418 strcpy (rs
->buf
, "QTDPsrc:");
10419 encode_source_string (num
, addr
, "cmd", "end",
10420 rs
->buf
+ strlen (rs
->buf
),
10421 rs
->buf_size
- strlen (rs
->buf
));
10423 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10424 if (strcmp (target_buf
, "OK"))
10425 warning (_("Target does not support source download."));
10431 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
10433 #define BUF_SIZE 2048
10437 char buf
[BUF_SIZE
];
10438 char **tdp_actions
;
10439 char **stepping_actions
;
10441 struct cleanup
*old_chain
= NULL
;
10442 struct agent_expr
*aexpr
;
10443 struct cleanup
*aexpr_chain
= NULL
;
10445 struct breakpoint
*b
= loc
->owner
;
10446 struct tracepoint
*t
= (struct tracepoint
*) b
;
10448 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10449 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10451 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10454 tpaddr
= loc
->address
;
10455 sprintf_vma (addrbuf
, tpaddr
);
10456 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10457 addrbuf
, /* address */
10458 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10459 t
->step_count
, t
->pass_count
);
10460 /* Fast tracepoints are mostly handled by the target, but we can
10461 tell the target how big of an instruction block should be moved
10463 if (b
->type
== bp_fast_tracepoint
)
10465 /* Only test for support at download time; we may not know
10466 target capabilities at definition time. */
10467 if (remote_supports_fast_tracepoints ())
10471 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10472 tpaddr
, &isize
, NULL
))
10473 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10476 /* If it passed validation at definition but fails now,
10477 something is very wrong. */
10478 internal_error (__FILE__
, __LINE__
,
10479 _("Fast tracepoint not "
10480 "valid during download"));
10483 /* Fast tracepoints are functionally identical to regular
10484 tracepoints, so don't take lack of support as a reason to
10485 give up on the trace run. */
10486 warning (_("Target does not support fast tracepoints, "
10487 "downloading %d as regular tracepoint"), b
->number
);
10489 else if (b
->type
== bp_static_tracepoint
)
10491 /* Only test for support at download time; we may not know
10492 target capabilities at definition time. */
10493 if (remote_supports_static_tracepoints ())
10495 struct static_tracepoint_marker marker
;
10497 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10498 strcat (buf
, ":S");
10500 error (_("Static tracepoint not valid during download"));
10503 /* Fast tracepoints are functionally identical to regular
10504 tracepoints, so don't take lack of support as a reason
10505 to give up on the trace run. */
10506 error (_("Target does not support static tracepoints"));
10508 /* If the tracepoint has a conditional, make it into an agent
10509 expression and append to the definition. */
10512 /* Only test support at download time, we may not know target
10513 capabilities at definition time. */
10514 if (remote_supports_cond_tracepoints ())
10516 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10517 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10518 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10520 pkt
= buf
+ strlen (buf
);
10521 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10522 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10524 do_cleanups (aexpr_chain
);
10527 warning (_("Target does not support conditional tracepoints, "
10528 "ignoring tp %d cond"), b
->number
);
10531 if (b
->commands
|| *default_collect
)
10534 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10535 if (strcmp (target_buf
, "OK"))
10536 error (_("Target does not support tracepoints."));
10538 /* do_single_steps (t); */
10541 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10543 QUIT
; /* Allow user to bail out with ^C. */
10544 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10545 b
->number
, addrbuf
, /* address */
10547 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10550 remote_get_noisy_reply (&target_buf
,
10552 if (strcmp (target_buf
, "OK"))
10553 error (_("Error on target while setting tracepoints."));
10556 if (stepping_actions
)
10558 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10560 QUIT
; /* Allow user to bail out with ^C. */
10561 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10562 b
->number
, addrbuf
, /* address */
10563 ((ndx
== 0) ? "S" : ""),
10564 stepping_actions
[ndx
],
10565 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10567 remote_get_noisy_reply (&target_buf
,
10569 if (strcmp (target_buf
, "OK"))
10570 error (_("Error on target while setting tracepoints."));
10574 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
10576 if (b
->addr_string
)
10578 strcpy (buf
, "QTDPsrc:");
10579 encode_source_string (b
->number
, loc
->address
,
10580 "at", b
->addr_string
, buf
+ strlen (buf
),
10581 2048 - strlen (buf
));
10584 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10585 if (strcmp (target_buf
, "OK"))
10586 warning (_("Target does not support source download."));
10588 if (b
->cond_string
)
10590 strcpy (buf
, "QTDPsrc:");
10591 encode_source_string (b
->number
, loc
->address
,
10592 "cond", b
->cond_string
, buf
+ strlen (buf
),
10593 2048 - strlen (buf
));
10595 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10596 if (strcmp (target_buf
, "OK"))
10597 warning (_("Target does not support source download."));
10599 remote_download_command_source (b
->number
, loc
->address
,
10600 breakpoint_commands (b
));
10603 do_cleanups (old_chain
);
10607 remote_can_download_tracepoint (struct target_ops
*self
)
10609 struct remote_state
*rs
= get_remote_state ();
10610 struct trace_status
*ts
;
10613 /* Don't try to install tracepoints until we've relocated our
10614 symbols, and fetched and merged the target's tracepoint list with
10616 if (rs
->starting_up
)
10619 ts
= current_trace_status ();
10620 status
= remote_get_trace_status (self
, ts
);
10622 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10625 /* If we are in a tracing experiment, but remote stub doesn't support
10626 installing tracepoint in trace, we have to return. */
10627 if (!remote_supports_install_in_trace ())
10635 remote_download_trace_state_variable (struct target_ops
*self
,
10636 struct trace_state_variable
*tsv
)
10638 struct remote_state
*rs
= get_remote_state ();
10641 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10642 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10644 p
= rs
->buf
+ strlen (rs
->buf
);
10645 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10646 error (_("Trace state variable name too long for tsv definition packet"));
10647 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
10650 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10651 if (*target_buf
== '\0')
10652 error (_("Target does not support this command."));
10653 if (strcmp (target_buf
, "OK") != 0)
10654 error (_("Error on target while downloading trace state variable."));
10658 remote_enable_tracepoint (struct target_ops
*self
,
10659 struct bp_location
*location
)
10661 struct remote_state
*rs
= get_remote_state ();
10664 sprintf_vma (addr_buf
, location
->address
);
10665 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10666 location
->owner
->number
, addr_buf
);
10668 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10669 if (*rs
->buf
== '\0')
10670 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10671 if (strcmp (rs
->buf
, "OK") != 0)
10672 error (_("Error on target while enabling tracepoint."));
10676 remote_disable_tracepoint (struct target_ops
*self
,
10677 struct bp_location
*location
)
10679 struct remote_state
*rs
= get_remote_state ();
10682 sprintf_vma (addr_buf
, location
->address
);
10683 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10684 location
->owner
->number
, addr_buf
);
10686 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10687 if (*rs
->buf
== '\0')
10688 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10689 if (strcmp (rs
->buf
, "OK") != 0)
10690 error (_("Error on target while disabling tracepoint."));
10694 remote_trace_set_readonly_regions (struct target_ops
*self
)
10698 bfd_size_type size
;
10704 return; /* No information to give. */
10706 strcpy (target_buf
, "QTro");
10707 offset
= strlen (target_buf
);
10708 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10710 char tmp1
[40], tmp2
[40];
10713 if ((s
->flags
& SEC_LOAD
) == 0 ||
10714 /* (s->flags & SEC_CODE) == 0 || */
10715 (s
->flags
& SEC_READONLY
) == 0)
10719 vma
= bfd_get_section_vma (abfd
, s
);
10720 size
= bfd_get_section_size (s
);
10721 sprintf_vma (tmp1
, vma
);
10722 sprintf_vma (tmp2
, vma
+ size
);
10723 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10724 if (offset
+ sec_length
+ 1 > target_buf_size
)
10726 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
10728 Too many sections for read-only sections definition packet."));
10731 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10733 offset
+= sec_length
;
10737 putpkt (target_buf
);
10738 getpkt (&target_buf
, &target_buf_size
, 0);
10743 remote_trace_start (struct target_ops
*self
)
10745 putpkt ("QTStart");
10746 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10747 if (*target_buf
== '\0')
10748 error (_("Target does not support this command."));
10749 if (strcmp (target_buf
, "OK") != 0)
10750 error (_("Bogus reply from target: %s"), target_buf
);
10754 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
10756 /* Initialize it just to avoid a GCC false warning. */
10758 /* FIXME we need to get register block size some other way. */
10759 extern int trace_regblock_size
;
10760 volatile struct gdb_exception ex
;
10761 enum packet_result result
;
10763 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
10766 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10768 putpkt ("qTStatus");
10770 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10772 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10776 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10778 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10781 throw_exception (ex
);
10784 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10786 /* If the remote target doesn't do tracing, flag it. */
10787 if (result
== PACKET_UNKNOWN
)
10790 /* We're working with a live target. */
10791 ts
->filename
= NULL
;
10794 error (_("Bogus trace status reply from target: %s"), target_buf
);
10796 /* Function 'parse_trace_status' sets default value of each field of
10797 'ts' at first, so we don't have to do it here. */
10798 parse_trace_status (p
, ts
);
10800 return ts
->running
;
10804 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
10805 struct uploaded_tp
*utp
)
10807 struct remote_state
*rs
= get_remote_state ();
10809 struct bp_location
*loc
;
10810 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10811 size_t size
= get_remote_packet_size ();
10815 tp
->base
.hit_count
= 0;
10816 tp
->traceframe_usage
= 0;
10817 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10819 /* If the tracepoint was never downloaded, don't go asking for
10821 if (tp
->number_on_target
== 0)
10823 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10824 phex_nz (loc
->address
, 0));
10826 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10827 if (reply
&& *reply
)
10830 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10836 utp
->hit_count
= 0;
10837 utp
->traceframe_usage
= 0;
10838 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10839 phex_nz (utp
->addr
, 0));
10841 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10842 if (reply
&& *reply
)
10845 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10851 remote_trace_stop (struct target_ops
*self
)
10854 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10855 if (*target_buf
== '\0')
10856 error (_("Target does not support this command."));
10857 if (strcmp (target_buf
, "OK") != 0)
10858 error (_("Bogus reply from target: %s"), target_buf
);
10862 remote_trace_find (struct target_ops
*self
,
10863 enum trace_find_type type
, int num
,
10864 CORE_ADDR addr1
, CORE_ADDR addr2
,
10867 struct remote_state
*rs
= get_remote_state ();
10868 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10870 int target_frameno
= -1, target_tracept
= -1;
10872 /* Lookups other than by absolute frame number depend on the current
10873 trace selected, so make sure it is correct on the remote end
10875 if (type
!= tfind_number
)
10876 set_remote_traceframe ();
10879 strcpy (p
, "QTFrame:");
10880 p
= strchr (p
, '\0');
10884 xsnprintf (p
, endbuf
- p
, "%x", num
);
10887 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10890 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10893 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10894 phex_nz (addr2
, 0));
10896 case tfind_outside
:
10897 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10898 phex_nz (addr2
, 0));
10901 error (_("Unknown trace find type %d"), type
);
10905 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
10906 if (*reply
== '\0')
10907 error (_("Target does not support this command."));
10909 while (reply
&& *reply
)
10914 target_frameno
= (int) strtol (p
, &reply
, 16);
10916 error (_("Unable to parse trace frame number"));
10917 /* Don't update our remote traceframe number cache on failure
10918 to select a remote traceframe. */
10919 if (target_frameno
== -1)
10924 target_tracept
= (int) strtol (p
, &reply
, 16);
10926 error (_("Unable to parse tracepoint number"));
10928 case 'O': /* "OK"? */
10929 if (reply
[1] == 'K' && reply
[2] == '\0')
10932 error (_("Bogus reply from target: %s"), reply
);
10935 error (_("Bogus reply from target: %s"), reply
);
10938 *tpp
= target_tracept
;
10940 rs
->remote_traceframe_number
= target_frameno
;
10941 return target_frameno
;
10945 remote_get_trace_state_variable_value (struct target_ops
*self
,
10946 int tsvnum
, LONGEST
*val
)
10948 struct remote_state
*rs
= get_remote_state ();
10952 set_remote_traceframe ();
10954 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10956 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10957 if (reply
&& *reply
)
10961 unpack_varlen_hex (reply
+ 1, &uval
);
10962 *val
= (LONGEST
) uval
;
10970 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
10972 struct remote_state
*rs
= get_remote_state ();
10976 strcpy (p
, "QTSave:");
10978 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10979 error (_("Remote file name too long for trace save packet"));
10980 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
10983 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10984 if (*reply
== '\0')
10985 error (_("Target does not support this command."));
10986 if (strcmp (reply
, "OK") != 0)
10987 error (_("Bogus reply from target: %s"), reply
);
10991 /* This is basically a memory transfer, but needs to be its own packet
10992 because we don't know how the target actually organizes its trace
10993 memory, plus we want to be able to ask for as much as possible, but
10994 not be unhappy if we don't get as much as we ask for. */
10997 remote_get_raw_trace_data (struct target_ops
*self
,
10998 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11000 struct remote_state
*rs
= get_remote_state ();
11006 strcpy (p
, "qTBuffer:");
11008 p
+= hexnumstr (p
, offset
);
11010 p
+= hexnumstr (p
, len
);
11014 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11015 if (reply
&& *reply
)
11017 /* 'l' by itself means we're at the end of the buffer and
11018 there is nothing more to get. */
11022 /* Convert the reply into binary. Limit the number of bytes to
11023 convert according to our passed-in buffer size, rather than
11024 what was returned in the packet; if the target is
11025 unexpectedly generous and gives us a bigger reply than we
11026 asked for, we don't want to crash. */
11027 rslt
= hex2bin (target_buf
, buf
, len
);
11031 /* Something went wrong, flag as an error. */
11036 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11038 struct remote_state
*rs
= get_remote_state ();
11040 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11044 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11046 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11047 if (*reply
== '\0')
11048 error (_("Target does not support this command."));
11049 if (strcmp (reply
, "OK") != 0)
11050 error (_("Bogus reply from target: %s"), reply
);
11053 warning (_("Target does not support disconnected tracing."));
11057 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11059 struct thread_info
*info
= find_thread_ptid (ptid
);
11061 if (info
&& info
->private)
11062 return info
->private->core
;
11067 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11069 struct remote_state
*rs
= get_remote_state ();
11072 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11074 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11075 if (*reply
== '\0')
11076 error (_("Target does not support this command."));
11077 if (strcmp (reply
, "OK") != 0)
11078 error (_("Bogus reply from target: %s"), reply
);
11081 static struct traceframe_info
*
11082 remote_traceframe_info (struct target_ops
*self
)
11086 text
= target_read_stralloc (¤t_target
,
11087 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11090 struct traceframe_info
*info
;
11091 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11093 info
= parse_traceframe_info (text
);
11094 do_cleanups (back_to
);
11101 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11102 instruction on which a fast tracepoint may be placed. Returns -1
11103 if the packet is not supported, and 0 if the minimum instruction
11104 length is unknown. */
11107 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11109 struct remote_state
*rs
= get_remote_state ();
11112 /* If we're not debugging a process yet, the IPA can't be
11114 if (!target_has_execution
)
11117 /* Make sure the remote is pointing at the right process. */
11118 set_general_process ();
11120 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11122 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11123 if (*reply
== '\0')
11127 ULONGEST min_insn_len
;
11129 unpack_varlen_hex (reply
, &min_insn_len
);
11131 return (int) min_insn_len
;
11136 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11138 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11140 struct remote_state
*rs
= get_remote_state ();
11141 char *buf
= rs
->buf
;
11142 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11143 enum packet_result result
;
11145 gdb_assert (val
>= 0 || val
== -1);
11146 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11147 /* Send -1 as literal "-1" to avoid host size dependency. */
11151 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11154 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11157 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11158 result
= packet_ok (rs
->buf
,
11159 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11161 if (result
!= PACKET_OK
)
11162 warning (_("Bogus reply from target: %s"), rs
->buf
);
11167 remote_set_trace_notes (struct target_ops
*self
,
11168 const char *user
, const char *notes
,
11169 const char *stop_notes
)
11171 struct remote_state
*rs
= get_remote_state ();
11173 char *buf
= rs
->buf
;
11174 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11177 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11180 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11181 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11187 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11188 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11194 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11195 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11199 /* Ensure the buffer is terminated. */
11203 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11204 if (*reply
== '\0')
11207 if (strcmp (reply
, "OK") != 0)
11208 error (_("Bogus reply from target: %s"), reply
);
11214 remote_use_agent (struct target_ops
*self
, int use
)
11216 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11218 struct remote_state
*rs
= get_remote_state ();
11220 /* If the stub supports QAgent. */
11221 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11223 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11225 if (strcmp (rs
->buf
, "OK") == 0)
11236 remote_can_use_agent (struct target_ops
*self
)
11238 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11241 struct btrace_target_info
11243 /* The ptid of the traced thread. */
11247 /* Check whether the target supports branch tracing. */
11250 remote_supports_btrace (struct target_ops
*self
)
11252 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11254 if (packet_support (PACKET_Qbtrace_bts
) != PACKET_ENABLE
)
11256 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11262 /* Enable branch tracing. */
11264 static struct btrace_target_info
*
11265 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
)
11267 struct btrace_target_info
*tinfo
= NULL
;
11268 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11269 struct remote_state
*rs
= get_remote_state ();
11270 char *buf
= rs
->buf
;
11271 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11273 if (packet_config_support (packet
) != PACKET_ENABLE
)
11274 error (_("Target does not support branch tracing."));
11276 set_general_thread (ptid
);
11278 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11280 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11282 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11284 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11285 error (_("Could not enable branch tracing for %s: %s"),
11286 target_pid_to_str (ptid
), rs
->buf
+ 2);
11288 error (_("Could not enable branch tracing for %s."),
11289 target_pid_to_str (ptid
));
11292 tinfo
= xzalloc (sizeof (*tinfo
));
11293 tinfo
->ptid
= ptid
;
11298 /* Disable branch tracing. */
11301 remote_disable_btrace (struct target_ops
*self
,
11302 struct btrace_target_info
*tinfo
)
11304 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11305 struct remote_state
*rs
= get_remote_state ();
11306 char *buf
= rs
->buf
;
11307 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11309 if (packet_config_support (packet
) != PACKET_ENABLE
)
11310 error (_("Target does not support branch tracing."));
11312 set_general_thread (tinfo
->ptid
);
11314 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11316 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11318 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11320 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11321 error (_("Could not disable branch tracing for %s: %s"),
11322 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11324 error (_("Could not disable branch tracing for %s."),
11325 target_pid_to_str (tinfo
->ptid
));
11331 /* Teardown branch tracing. */
11334 remote_teardown_btrace (struct target_ops
*self
,
11335 struct btrace_target_info
*tinfo
)
11337 /* We must not talk to the target during teardown. */
11341 /* Read the branch trace. */
11343 static enum btrace_error
11344 remote_read_btrace (struct target_ops
*self
,
11345 VEC (btrace_block_s
) **btrace
,
11346 struct btrace_target_info
*tinfo
,
11347 enum btrace_read_type type
)
11349 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11350 struct remote_state
*rs
= get_remote_state ();
11351 struct cleanup
*cleanup
;
11355 if (packet_config_support (packet
) != PACKET_ENABLE
)
11356 error (_("Target does not support branch tracing."));
11358 #if !defined(HAVE_LIBEXPAT)
11359 error (_("Cannot process branch tracing result. XML parsing not supported."));
11364 case BTRACE_READ_ALL
:
11367 case BTRACE_READ_NEW
:
11370 case BTRACE_READ_DELTA
:
11374 internal_error (__FILE__
, __LINE__
,
11375 _("Bad branch tracing read type: %u."),
11376 (unsigned int) type
);
11379 xml
= target_read_stralloc (¤t_target
,
11380 TARGET_OBJECT_BTRACE
, annex
);
11382 return BTRACE_ERR_UNKNOWN
;
11384 cleanup
= make_cleanup (xfree
, xml
);
11385 *btrace
= parse_xml_btrace (xml
);
11386 do_cleanups (cleanup
);
11388 return BTRACE_ERR_NONE
;
11392 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
11394 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
11398 /* Implementation of to_load. */
11401 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
11403 generic_load (name
, from_tty
);
11407 init_remote_ops (void)
11409 remote_ops
.to_shortname
= "remote";
11410 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11411 remote_ops
.to_doc
=
11412 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11413 Specify the serial device it is connected to\n\
11414 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11415 remote_ops
.to_open
= remote_open
;
11416 remote_ops
.to_close
= remote_close
;
11417 remote_ops
.to_detach
= remote_detach
;
11418 remote_ops
.to_disconnect
= remote_disconnect
;
11419 remote_ops
.to_resume
= remote_resume
;
11420 remote_ops
.to_wait
= remote_wait
;
11421 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11422 remote_ops
.to_store_registers
= remote_store_registers
;
11423 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11424 remote_ops
.to_files_info
= remote_files_info
;
11425 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11426 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11427 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11428 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11429 remote_ops
.to_watchpoint_addr_within_range
=
11430 remote_watchpoint_addr_within_range
;
11431 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11432 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11433 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11434 remote_ops
.to_region_ok_for_hw_watchpoint
11435 = remote_region_ok_for_hw_watchpoint
;
11436 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11437 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11438 remote_ops
.to_kill
= remote_kill
;
11439 remote_ops
.to_load
= remote_load
;
11440 remote_ops
.to_mourn_inferior
= remote_mourn
;
11441 remote_ops
.to_pass_signals
= remote_pass_signals
;
11442 remote_ops
.to_program_signals
= remote_program_signals
;
11443 remote_ops
.to_thread_alive
= remote_thread_alive
;
11444 remote_ops
.to_find_new_threads
= remote_threads_info
;
11445 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11446 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11447 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11448 remote_ops
.to_stop
= remote_stop
;
11449 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11450 remote_ops
.to_rcmd
= remote_rcmd
;
11451 remote_ops
.to_log_command
= serial_log_command
;
11452 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11453 remote_ops
.to_stratum
= process_stratum
;
11454 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11455 remote_ops
.to_has_memory
= default_child_has_memory
;
11456 remote_ops
.to_has_stack
= default_child_has_stack
;
11457 remote_ops
.to_has_registers
= default_child_has_registers
;
11458 remote_ops
.to_has_execution
= default_child_has_execution
;
11459 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11460 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11461 remote_ops
.to_magic
= OPS_MAGIC
;
11462 remote_ops
.to_memory_map
= remote_memory_map
;
11463 remote_ops
.to_flash_erase
= remote_flash_erase
;
11464 remote_ops
.to_flash_done
= remote_flash_done
;
11465 remote_ops
.to_read_description
= remote_read_description
;
11466 remote_ops
.to_search_memory
= remote_search_memory
;
11467 remote_ops
.to_can_async_p
= remote_can_async_p
;
11468 remote_ops
.to_is_async_p
= remote_is_async_p
;
11469 remote_ops
.to_async
= remote_async
;
11470 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11471 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11472 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11473 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11474 remote_ops
.to_supports_disable_randomization
11475 = remote_supports_disable_randomization
;
11476 remote_ops
.to_fileio_open
= remote_hostio_open
;
11477 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11478 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11479 remote_ops
.to_fileio_close
= remote_hostio_close
;
11480 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11481 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11482 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11483 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11484 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11485 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11486 remote_ops
.to_trace_init
= remote_trace_init
;
11487 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11488 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11489 remote_ops
.to_download_trace_state_variable
11490 = remote_download_trace_state_variable
;
11491 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11492 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11493 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11494 remote_ops
.to_trace_start
= remote_trace_start
;
11495 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11496 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11497 remote_ops
.to_trace_stop
= remote_trace_stop
;
11498 remote_ops
.to_trace_find
= remote_trace_find
;
11499 remote_ops
.to_get_trace_state_variable_value
11500 = remote_get_trace_state_variable_value
;
11501 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11502 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11503 remote_ops
.to_upload_trace_state_variables
11504 = remote_upload_trace_state_variables
;
11505 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11506 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11507 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11508 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11509 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11510 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11511 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11512 remote_ops
.to_verify_memory
= remote_verify_memory
;
11513 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11514 remote_ops
.to_set_permissions
= remote_set_permissions
;
11515 remote_ops
.to_static_tracepoint_marker_at
11516 = remote_static_tracepoint_marker_at
;
11517 remote_ops
.to_static_tracepoint_markers_by_strid
11518 = remote_static_tracepoint_markers_by_strid
;
11519 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11520 remote_ops
.to_use_agent
= remote_use_agent
;
11521 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11522 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11523 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11524 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11525 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11526 remote_ops
.to_read_btrace
= remote_read_btrace
;
11527 remote_ops
.to_augmented_libraries_svr4_read
=
11528 remote_augmented_libraries_svr4_read
;
11531 /* Set up the extended remote vector by making a copy of the standard
11532 remote vector and adding to it. */
11535 init_extended_remote_ops (void)
11537 extended_remote_ops
= remote_ops
;
11539 extended_remote_ops
.to_shortname
= "extended-remote";
11540 extended_remote_ops
.to_longname
=
11541 "Extended remote serial target in gdb-specific protocol";
11542 extended_remote_ops
.to_doc
=
11543 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11544 Specify the serial device it is connected to (e.g. /dev/ttya).";
11545 extended_remote_ops
.to_open
= extended_remote_open
;
11546 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11547 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11548 extended_remote_ops
.to_detach
= extended_remote_detach
;
11549 extended_remote_ops
.to_attach
= extended_remote_attach
;
11550 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
11551 extended_remote_ops
.to_kill
= extended_remote_kill
;
11552 extended_remote_ops
.to_supports_disable_randomization
11553 = extended_remote_supports_disable_randomization
;
11557 remote_can_async_p (struct target_ops
*ops
)
11559 struct remote_state
*rs
= get_remote_state ();
11561 if (!target_async_permitted
)
11562 /* We only enable async when the user specifically asks for it. */
11565 /* We're async whenever the serial device is. */
11566 return serial_can_async_p (rs
->remote_desc
);
11570 remote_is_async_p (struct target_ops
*ops
)
11572 struct remote_state
*rs
= get_remote_state ();
11574 if (!target_async_permitted
)
11575 /* We only enable async when the user specifically asks for it. */
11578 /* We're async whenever the serial device is. */
11579 return serial_is_async_p (rs
->remote_desc
);
11582 /* Pass the SERIAL event on and up to the client. One day this code
11583 will be able to delay notifying the client of an event until the
11584 point where an entire packet has been received. */
11586 static serial_event_ftype remote_async_serial_handler
;
11589 remote_async_serial_handler (struct serial
*scb
, void *context
)
11591 struct remote_state
*rs
= context
;
11593 /* Don't propogate error information up to the client. Instead let
11594 the client find out about the error by querying the target. */
11595 rs
->async_client_callback (INF_REG_EVENT
, rs
->async_client_context
);
11599 remote_async_inferior_event_handler (gdb_client_data data
)
11601 inferior_event_handler (INF_REG_EVENT
, NULL
);
11605 remote_async (struct target_ops
*ops
,
11606 void (*callback
) (enum inferior_event_type event_type
,
11610 struct remote_state
*rs
= get_remote_state ();
11612 if (callback
!= NULL
)
11614 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
11615 rs
->async_client_callback
= callback
;
11616 rs
->async_client_context
= context
;
11619 serial_async (rs
->remote_desc
, NULL
, NULL
);
11623 set_remote_cmd (char *args
, int from_tty
)
11625 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
11629 show_remote_cmd (char *args
, int from_tty
)
11631 /* We can't just use cmd_show_list here, because we want to skip
11632 the redundant "show remote Z-packet" and the legacy aliases. */
11633 struct cleanup
*showlist_chain
;
11634 struct cmd_list_element
*list
= remote_show_cmdlist
;
11635 struct ui_out
*uiout
= current_uiout
;
11637 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11638 for (; list
!= NULL
; list
= list
->next
)
11639 if (strcmp (list
->name
, "Z-packet") == 0)
11641 else if (list
->type
== not_set_cmd
)
11642 /* Alias commands are exactly like the original, except they
11643 don't have the normal type. */
11647 struct cleanup
*option_chain
11648 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11650 ui_out_field_string (uiout
, "name", list
->name
);
11651 ui_out_text (uiout
, ": ");
11652 if (list
->type
== show_cmd
)
11653 do_show_command ((char *) NULL
, from_tty
, list
);
11655 cmd_func (list
, NULL
, from_tty
);
11656 /* Close the tuple. */
11657 do_cleanups (option_chain
);
11660 /* Close the tuple. */
11661 do_cleanups (showlist_chain
);
11665 /* Function to be called whenever a new objfile (shlib) is detected. */
11667 remote_new_objfile (struct objfile
*objfile
)
11669 struct remote_state
*rs
= get_remote_state ();
11671 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11672 remote_check_symbols ();
11675 /* Pull all the tracepoints defined on the target and create local
11676 data structures representing them. We don't want to create real
11677 tracepoints yet, we don't want to mess up the user's existing
11681 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
11683 struct remote_state
*rs
= get_remote_state ();
11686 /* Ask for a first packet of tracepoint definition. */
11688 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11690 while (*p
&& *p
!= 'l')
11692 parse_tracepoint_definition (p
, utpp
);
11693 /* Ask for another packet of tracepoint definition. */
11695 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11702 remote_upload_trace_state_variables (struct target_ops
*self
,
11703 struct uploaded_tsv
**utsvp
)
11705 struct remote_state
*rs
= get_remote_state ();
11708 /* Ask for a first packet of variable definition. */
11710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11712 while (*p
&& *p
!= 'l')
11714 parse_tsv_definition (p
, utsvp
);
11715 /* Ask for another packet of variable definition. */
11717 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11723 /* The "set/show range-stepping" show hook. */
11726 show_range_stepping (struct ui_file
*file
, int from_tty
,
11727 struct cmd_list_element
*c
,
11730 fprintf_filtered (file
,
11731 _("Debugger's willingness to use range stepping "
11732 "is %s.\n"), value
);
11735 /* The "set/show range-stepping" set hook. */
11738 set_range_stepping (char *ignore_args
, int from_tty
,
11739 struct cmd_list_element
*c
)
11741 struct remote_state
*rs
= get_remote_state ();
11743 /* Whene enabling, check whether range stepping is actually
11744 supported by the target, and warn if not. */
11745 if (use_range_stepping
)
11747 if (rs
->remote_desc
!= NULL
)
11749 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
11750 remote_vcont_probe (rs
);
11752 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
11753 && rs
->supports_vCont
.r
)
11757 warning (_("Range stepping is not supported by the current target"));
11762 _initialize_remote (void)
11764 struct remote_state
*rs
;
11765 struct cmd_list_element
*cmd
;
11766 const char *cmd_name
;
11768 /* architecture specific data */
11769 remote_gdbarch_data_handle
=
11770 gdbarch_data_register_post_init (init_remote_state
);
11771 remote_g_packet_data_handle
=
11772 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11774 /* Initialize the per-target state. At the moment there is only one
11775 of these, not one per target. Only one target is active at a
11777 remote_state
= new_remote_state ();
11779 init_remote_ops ();
11780 add_target (&remote_ops
);
11782 init_extended_remote_ops ();
11783 add_target (&extended_remote_ops
);
11785 /* Hook into new objfile notification. */
11786 observer_attach_new_objfile (remote_new_objfile
);
11787 /* We're no longer interested in notification events of an inferior
11789 observer_attach_inferior_exit (discard_pending_stop_replies
);
11791 /* Set up signal handlers. */
11792 async_sigint_remote_token
=
11793 create_async_signal_handler (async_remote_interrupt
, NULL
);
11794 async_sigint_remote_twice_token
=
11795 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11798 init_remote_threadtests ();
11801 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11802 /* set/show remote ... */
11804 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11805 Remote protocol specific variables\n\
11806 Configure various remote-protocol specific variables such as\n\
11807 the packets being used"),
11808 &remote_set_cmdlist
, "set remote ",
11809 0 /* allow-unknown */, &setlist
);
11810 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11811 Remote protocol specific variables\n\
11812 Configure various remote-protocol specific variables such as\n\
11813 the packets being used"),
11814 &remote_show_cmdlist
, "show remote ",
11815 0 /* allow-unknown */, &showlist
);
11817 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11818 Compare section data on target to the exec file.\n\
11819 Argument is a single section name (default: all loaded sections).\n\
11820 To compare only read-only loaded sections, specify the -r option."),
11823 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11824 Send an arbitrary packet to a remote target.\n\
11825 maintenance packet TEXT\n\
11826 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11827 this command sends the string TEXT to the inferior, and displays the\n\
11828 response packet. GDB supplies the initial `$' character, and the\n\
11829 terminating `#' character and checksum."),
11832 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11833 Set whether to send break if interrupted."), _("\
11834 Show whether to send break if interrupted."), _("\
11835 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11836 set_remotebreak
, show_remotebreak
,
11837 &setlist
, &showlist
);
11838 cmd_name
= "remotebreak";
11839 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11840 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11841 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11842 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11843 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11845 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11846 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11848 Set interrupt sequence to remote target."), _("\
11849 Show interrupt sequence to remote target."), _("\
11850 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11851 NULL
, show_interrupt_sequence
,
11852 &remote_set_cmdlist
,
11853 &remote_show_cmdlist
);
11855 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11856 &interrupt_on_connect
, _("\
11857 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11858 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11859 If set, interrupt sequence is sent to remote target."),
11861 &remote_set_cmdlist
, &remote_show_cmdlist
);
11863 /* Install commands for configuring memory read/write packets. */
11865 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11866 Set the maximum number of bytes per memory write packet (deprecated)."),
11868 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11869 Show the maximum number of bytes per memory write packet (deprecated)."),
11871 add_cmd ("memory-write-packet-size", no_class
,
11872 set_memory_write_packet_size
, _("\
11873 Set the maximum number of bytes per memory-write packet.\n\
11874 Specify the number of bytes in a packet or 0 (zero) for the\n\
11875 default packet size. The actual limit is further reduced\n\
11876 dependent on the target. Specify ``fixed'' to disable the\n\
11877 further restriction and ``limit'' to enable that restriction."),
11878 &remote_set_cmdlist
);
11879 add_cmd ("memory-read-packet-size", no_class
,
11880 set_memory_read_packet_size
, _("\
11881 Set the maximum number of bytes per memory-read packet.\n\
11882 Specify the number of bytes in a packet or 0 (zero) for the\n\
11883 default packet size. The actual limit is further reduced\n\
11884 dependent on the target. Specify ``fixed'' to disable the\n\
11885 further restriction and ``limit'' to enable that restriction."),
11886 &remote_set_cmdlist
);
11887 add_cmd ("memory-write-packet-size", no_class
,
11888 show_memory_write_packet_size
,
11889 _("Show the maximum number of bytes per memory-write packet."),
11890 &remote_show_cmdlist
);
11891 add_cmd ("memory-read-packet-size", no_class
,
11892 show_memory_read_packet_size
,
11893 _("Show the maximum number of bytes per memory-read packet."),
11894 &remote_show_cmdlist
);
11896 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11897 &remote_hw_watchpoint_limit
, _("\
11898 Set the maximum number of target hardware watchpoints."), _("\
11899 Show the maximum number of target hardware watchpoints."), _("\
11900 Specify a negative limit for unlimited."),
11901 NULL
, NULL
, /* FIXME: i18n: The maximum
11902 number of target hardware
11903 watchpoints is %s. */
11904 &remote_set_cmdlist
, &remote_show_cmdlist
);
11905 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11906 &remote_hw_watchpoint_length_limit
, _("\
11907 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11908 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11909 Specify a negative limit for unlimited."),
11910 NULL
, NULL
, /* FIXME: i18n: The maximum
11911 length (in bytes) of a target
11912 hardware watchpoint is %s. */
11913 &remote_set_cmdlist
, &remote_show_cmdlist
);
11914 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11915 &remote_hw_breakpoint_limit
, _("\
11916 Set the maximum number of target hardware breakpoints."), _("\
11917 Show the maximum number of target hardware breakpoints."), _("\
11918 Specify a negative limit for unlimited."),
11919 NULL
, NULL
, /* FIXME: i18n: The maximum
11920 number of target hardware
11921 breakpoints is %s. */
11922 &remote_set_cmdlist
, &remote_show_cmdlist
);
11924 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
11925 &remote_address_size
, _("\
11926 Set the maximum size of the address (in bits) in a memory packet."), _("\
11927 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11929 NULL
, /* FIXME: i18n: */
11930 &setlist
, &showlist
);
11932 init_all_packet_configs ();
11934 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11935 "X", "binary-download", 1);
11937 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11938 "vCont", "verbose-resume", 0);
11940 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11941 "QPassSignals", "pass-signals", 0);
11943 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11944 "QProgramSignals", "program-signals", 0);
11946 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11947 "qSymbol", "symbol-lookup", 0);
11949 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11950 "P", "set-register", 1);
11952 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11953 "p", "fetch-register", 1);
11955 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11956 "Z0", "software-breakpoint", 0);
11958 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11959 "Z1", "hardware-breakpoint", 0);
11961 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11962 "Z2", "write-watchpoint", 0);
11964 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11965 "Z3", "read-watchpoint", 0);
11967 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11968 "Z4", "access-watchpoint", 0);
11970 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11971 "qXfer:auxv:read", "read-aux-vector", 0);
11973 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11974 "qXfer:features:read", "target-features", 0);
11976 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11977 "qXfer:libraries:read", "library-info", 0);
11979 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11980 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11982 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11983 "qXfer:memory-map:read", "memory-map", 0);
11985 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11986 "qXfer:spu:read", "read-spu-object", 0);
11988 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11989 "qXfer:spu:write", "write-spu-object", 0);
11991 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11992 "qXfer:osdata:read", "osdata", 0);
11994 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11995 "qXfer:threads:read", "threads", 0);
11997 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11998 "qXfer:siginfo:read", "read-siginfo-object", 0);
12000 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12001 "qXfer:siginfo:write", "write-siginfo-object", 0);
12003 add_packet_config_cmd
12004 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12005 "qXfer:traceframe-info:read", "traceframe-info", 0);
12007 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12008 "qXfer:uib:read", "unwind-info-block", 0);
12010 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12011 "qGetTLSAddr", "get-thread-local-storage-address",
12014 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12015 "qGetTIBAddr", "get-thread-information-block-address",
12018 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12019 "bc", "reverse-continue", 0);
12021 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12022 "bs", "reverse-step", 0);
12024 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12025 "qSupported", "supported-packets", 0);
12027 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12028 "qSearch:memory", "search-memory", 0);
12030 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12031 "qTStatus", "trace-status", 0);
12033 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12034 "vFile:open", "hostio-open", 0);
12036 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12037 "vFile:pread", "hostio-pread", 0);
12039 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12040 "vFile:pwrite", "hostio-pwrite", 0);
12042 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12043 "vFile:close", "hostio-close", 0);
12045 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12046 "vFile:unlink", "hostio-unlink", 0);
12048 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12049 "vFile:readlink", "hostio-readlink", 0);
12051 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12052 "vAttach", "attach", 0);
12054 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12057 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12058 "QStartNoAckMode", "noack", 0);
12060 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12061 "vKill", "kill", 0);
12063 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12064 "qAttached", "query-attached", 0);
12066 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12067 "ConditionalTracepoints",
12068 "conditional-tracepoints", 0);
12070 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12071 "ConditionalBreakpoints",
12072 "conditional-breakpoints", 0);
12074 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12075 "BreakpointCommands",
12076 "breakpoint-commands", 0);
12078 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12079 "FastTracepoints", "fast-tracepoints", 0);
12081 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12082 "TracepointSource", "TracepointSource", 0);
12084 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12085 "QAllow", "allow", 0);
12087 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12088 "StaticTracepoints", "static-tracepoints", 0);
12090 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12091 "InstallInTrace", "install-in-trace", 0);
12093 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12094 "qXfer:statictrace:read", "read-sdata-object", 0);
12096 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12097 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12099 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12100 "QDisableRandomization", "disable-randomization", 0);
12102 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12103 "QAgent", "agent", 0);
12105 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12106 "QTBuffer:size", "trace-buffer-size", 0);
12108 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12109 "Qbtrace:off", "disable-btrace", 0);
12111 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12112 "Qbtrace:bts", "enable-btrace", 0);
12114 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12115 "qXfer:btrace", "read-btrace", 0);
12117 /* Assert that we've registered commands for all packet configs. */
12121 for (i
= 0; i
< PACKET_MAX
; i
++)
12123 /* Ideally all configs would have a command associated. Some
12124 still don't though. */
12129 case PACKET_QNonStop
:
12130 case PACKET_multiprocess_feature
:
12131 case PACKET_EnableDisableTracepoints_feature
:
12132 case PACKET_tracenz_feature
:
12133 case PACKET_DisconnectedTracing_feature
:
12134 case PACKET_augmented_libraries_svr4_read_feature
:
12136 /* Additions to this list need to be well justified:
12137 pre-existing packets are OK; new packets are not. */
12145 /* This catches both forgetting to add a config command, and
12146 forgetting to remove a packet from the exception list. */
12147 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
12151 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12152 Z sub-packet has its own set and show commands, but users may
12153 have sets to this variable in their .gdbinit files (or in their
12155 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12156 &remote_Z_packet_detect
, _("\
12157 Set use of remote protocol `Z' packets"), _("\
12158 Show use of remote protocol `Z' packets "), _("\
12159 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12161 set_remote_protocol_Z_packet_cmd
,
12162 show_remote_protocol_Z_packet_cmd
,
12163 /* FIXME: i18n: Use of remote protocol
12164 `Z' packets is %s. */
12165 &remote_set_cmdlist
, &remote_show_cmdlist
);
12167 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12168 Manipulate files on the remote system\n\
12169 Transfer files to and from the remote target system."),
12170 &remote_cmdlist
, "remote ",
12171 0 /* allow-unknown */, &cmdlist
);
12173 add_cmd ("put", class_files
, remote_put_command
,
12174 _("Copy a local file to the remote system."),
12177 add_cmd ("get", class_files
, remote_get_command
,
12178 _("Copy a remote file to the local system."),
12181 add_cmd ("delete", class_files
, remote_delete_command
,
12182 _("Delete a remote file."),
12185 remote_exec_file
= xstrdup ("");
12186 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12187 &remote_exec_file
, _("\
12188 Set the remote pathname for \"run\""), _("\
12189 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12190 &remote_set_cmdlist
, &remote_show_cmdlist
);
12192 add_setshow_boolean_cmd ("range-stepping", class_run
,
12193 &use_range_stepping
, _("\
12194 Enable or disable range stepping."), _("\
12195 Show whether target-assisted range stepping is enabled."), _("\
12196 If on, and the target supports it, when stepping a source line, GDB\n\
12197 tells the target to step the corresponding range of addresses itself instead\n\
12198 of issuing multiple single-steps. This speeds up source level\n\
12199 stepping. If off, GDB always issues single-steps, even if range\n\
12200 stepping is supported by the target. The default is on."),
12201 set_range_stepping
,
12202 show_range_stepping
,
12206 /* Eventually initialize fileio. See fileio.c */
12207 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12209 /* Take advantage of the fact that the TID field is not used, to tag
12210 special ptids with it set to != 0. */
12211 magic_null_ptid
= ptid_build (42000, -1, 1);
12212 not_sent_ptid
= ptid_build (42000, -2, 1);
12213 any_thread_ptid
= ptid_build (42000, 0, 1);
12215 target_buf_size
= 2048;
12216 target_buf
= xmalloc (target_buf_size
);