1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2016 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 "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
73 #include "record-btrace.h"
76 /* Temp hacks for tracepoint encoding migration. */
77 static char *target_buf
;
78 static long target_buf_size
;
80 /* Per-program-space data key. */
81 static const struct program_space_data
*remote_pspace_data
;
83 /* The variable registered as the control variable used by the
84 remote exec-file commands. While the remote exec-file setting is
85 per-program-space, the set/show machinery uses this as the
86 location of the remote exec-file value. */
87 static char *remote_exec_file_var
;
89 /* The size to align memory write packets, when practical. The protocol
90 does not guarantee any alignment, and gdb will generate short
91 writes and unaligned writes, but even as a best-effort attempt this
92 can improve bulk transfers. For instance, if a write is misaligned
93 relative to the target's data bus, the stub may need to make an extra
94 round trip fetching data from the target. This doesn't make a
95 huge difference, but it's easy to do, so we try to be helpful.
97 The alignment chosen is arbitrary; usually data bus width is
98 important here, not the possibly larger cache line size. */
99 enum { REMOTE_ALIGN_WRITES
= 16 };
101 /* Prototypes for local functions. */
102 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
103 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
104 int forever
, int *is_notif
);
106 static void remote_files_info (struct target_ops
*ignore
);
108 static void remote_prepare_to_store (struct target_ops
*self
,
109 struct regcache
*regcache
);
111 static void remote_open_1 (const char *, int, struct target_ops
*,
114 static void remote_close (struct target_ops
*self
);
118 static int remote_vkill (int pid
, struct remote_state
*rs
);
120 static void remote_kill_k (void);
122 static void remote_mourn (struct target_ops
*ops
);
124 static void extended_remote_restart (void);
126 static void remote_send (char **buf
, long *sizeof_buf_p
);
128 static int readchar (int timeout
);
130 static void remote_serial_write (const char *str
, int len
);
132 static void remote_kill (struct target_ops
*ops
);
134 static int remote_can_async_p (struct target_ops
*);
136 static int remote_is_async_p (struct target_ops
*);
138 static void remote_async (struct target_ops
*ops
, int enable
);
140 static void remote_thread_events (struct target_ops
*ops
, int enable
);
142 static void interrupt_query (void);
144 static void set_general_thread (struct ptid ptid
);
145 static void set_continue_thread (struct ptid ptid
);
147 static void get_offsets (void);
149 static void skip_frame (void);
151 static long read_frame (char **buf_p
, long *sizeof_buf
);
153 static int hexnumlen (ULONGEST num
);
155 static void init_remote_ops (void);
157 static void init_extended_remote_ops (void);
159 static void remote_stop (struct target_ops
*self
, ptid_t
);
161 static int stubhex (int ch
);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (const char *);
171 static void compare_sections_command (char *, int);
173 static void packet_command (char *, int);
175 static int stub_unpack_int (char *buff
, int fieldlength
);
177 static ptid_t
remote_current_thread (ptid_t oldptid
);
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
);
197 static int remote_get_trace_status (struct target_ops
*self
,
198 struct trace_status
*ts
);
200 static int remote_upload_tracepoints (struct target_ops
*self
,
201 struct uploaded_tp
**utpp
);
203 static int remote_upload_trace_state_variables (struct target_ops
*self
,
204 struct uploaded_tsv
**utsvp
);
206 static void remote_query_supported (void);
208 static void remote_check_symbols (void);
210 void _initialize_remote (void);
213 static void stop_reply_xfree (struct stop_reply
*);
214 static void remote_parse_stop_reply (char *, struct stop_reply
*);
215 static void push_stop_reply (struct stop_reply
*);
216 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
217 static int peek_stop_reply (ptid_t ptid
);
219 struct threads_listing_context
;
220 static void remove_new_fork_children (struct threads_listing_context
*);
222 static void remote_async_inferior_event_handler (gdb_client_data
);
224 static void remote_terminal_ours (struct target_ops
*self
);
226 static int remote_read_description_p (struct target_ops
*target
);
228 static void remote_console_output (char *msg
);
230 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
232 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
234 static void remote_btrace_reset (void);
236 static void remote_btrace_maybe_reopen (void);
238 static int stop_reply_queue_length (void);
240 static void readahead_cache_invalidate (void);
242 static void remote_unpush_and_throw (void);
246 static struct cmd_list_element
*remote_cmdlist
;
248 /* For "set remote" and "show remote". */
250 static struct cmd_list_element
*remote_set_cmdlist
;
251 static struct cmd_list_element
*remote_show_cmdlist
;
253 /* Stub vCont actions support.
255 Each field is a boolean flag indicating whether the stub reports
256 support for the corresponding action. */
258 struct vCont_action_support
273 /* Controls whether GDB is willing to use range stepping. */
275 static int use_range_stepping
= 1;
277 #define OPAQUETHREADBYTES 8
279 /* a 64 bit opaque identifier */
280 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
282 /* About this many threadisds fit in a packet. */
284 #define MAXTHREADLISTRESULTS 32
286 /* Data for the vFile:pread readahead cache. */
288 struct readahead_cache
290 /* The file descriptor for the file that is being cached. -1 if the
294 /* The offset into the file that the cache buffer corresponds
298 /* The buffer holding the cache contents. */
300 /* The buffer's size. We try to read as much as fits into a packet
304 /* Cache hit and miss counters. */
309 /* Description of the remote protocol state for the currently
310 connected target. This is per-target state, and independent of the
311 selected architecture. */
315 /* A buffer to use for incoming packets, and its current size. The
316 buffer is grown dynamically for larger incoming packets.
317 Outgoing packets may also be constructed in this buffer.
318 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
319 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
324 /* True if we're going through initial connection setup (finding out
325 about the remote side's threads, relocating symbols, etc.). */
328 /* If we negotiated packet size explicitly (and thus can bypass
329 heuristics for the largest packet size that will not overflow
330 a buffer in the stub), this will be set to that packet size.
331 Otherwise zero, meaning to use the guessed size. */
332 long explicit_packet_size
;
334 /* remote_wait is normally called when the target is running and
335 waits for a stop reply packet. But sometimes we need to call it
336 when the target is already stopped. We can send a "?" packet
337 and have remote_wait read the response. Or, if we already have
338 the response, we can stash it in BUF and tell remote_wait to
339 skip calling getpkt. This flag is set when BUF contains a
340 stop reply packet and the target is not waiting. */
341 int cached_wait_status
;
343 /* True, if in no ack mode. That is, neither GDB nor the stub will
344 expect acks from each other. The connection is assumed to be
348 /* True if we're connected in extended remote mode. */
351 /* True if we resumed the target and we're waiting for the target to
352 stop. In the mean time, we can't start another command/query.
353 The remote server wouldn't be ready to process it, so we'd
354 timeout waiting for a reply that would never come and eventually
355 we'd close the connection. This can happen in asynchronous mode
356 because we allow GDB commands while the target is running. */
357 int waiting_for_stop_reply
;
359 /* The status of the stub support for the various vCont actions. */
360 struct vCont_action_support supports_vCont
;
362 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
363 responded to that. */
366 /* True if we saw a Ctrl-C while reading or writing from/to the
367 remote descriptor. At that point it is not safe to send a remote
368 interrupt packet, so we instead remember we saw the Ctrl-C and
369 process it once we're done with sending/receiving the current
370 packet, which should be shortly. If however that takes too long,
371 and the user presses Ctrl-C again, we offer to disconnect. */
372 int got_ctrlc_during_io
;
374 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
375 remote_open knows that we don't have a file open when the program
377 struct serial
*remote_desc
;
379 /* These are the threads which we last sent to the remote system. The
380 TID member will be -1 for all or -2 for not sent yet. */
381 ptid_t general_thread
;
382 ptid_t continue_thread
;
384 /* This is the traceframe which we last selected on the remote system.
385 It will be -1 if no traceframe is selected. */
386 int remote_traceframe_number
;
388 char *last_pass_packet
;
390 /* The last QProgramSignals packet sent to the target. We bypass
391 sending a new program signals list down to the target if the new
392 packet is exactly the same as the last we sent. IOW, we only let
393 the target know about program signals list changes. */
394 char *last_program_signals_packet
;
396 enum gdb_signal last_sent_signal
;
400 /* The execution direction of the last resume we got. */
401 enum exec_direction_kind last_resume_exec_dir
;
403 char *finished_object
;
404 char *finished_annex
;
405 ULONGEST finished_offset
;
407 /* Should we try the 'ThreadInfo' query packet?
409 This variable (NOT available to the user: auto-detect only!)
410 determines whether GDB will use the new, simpler "ThreadInfo"
411 query or the older, more complex syntax for thread queries.
412 This is an auto-detect variable (set to true at each connect,
413 and set to false when the target fails to recognize it). */
414 int use_threadinfo_query
;
415 int use_threadextra_query
;
417 threadref echo_nextthread
;
418 threadref nextthread
;
419 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
421 /* The state of remote notification. */
422 struct remote_notif_state
*notif_state
;
424 /* The branch trace configuration. */
425 struct btrace_config btrace_config
;
427 /* The argument to the last "vFile:setfs:" packet we sent, used
428 to avoid sending repeated unnecessary "vFile:setfs:" packets.
429 Initialized to -1 to indicate that no "vFile:setfs:" packet
430 has yet been sent. */
433 /* A readahead cache for vFile:pread. Often, reading a binary
434 involves a sequence of small reads. E.g., when parsing an ELF
435 file. A readahead cache helps mostly the case of remote
436 debugging on a connection with higher latency, due to the
437 request/reply nature of the RSP. We only cache data for a single
438 file descriptor at a time. */
439 struct readahead_cache readahead_cache
;
442 /* Private data that we'll store in (struct thread_info)->private. */
443 struct private_thread_info
449 /* Whether the target stopped for a breakpoint/watchpoint. */
450 enum target_stop_reason stop_reason
;
452 /* This is set to the data address of the access causing the target
453 to stop for a watchpoint. */
454 CORE_ADDR watch_data_address
;
456 /* Fields used by the vCont action coalescing implemented in
457 remote_resume / remote_commit_resume. remote_resume stores each
458 thread's last resume request in these fields, so that a later
459 remote_commit_resume knows which is the proper action for this
460 thread to include in the vCont packet. */
462 /* True if the last target_resume call for this thread was a step
463 request, false if a continue request. */
464 int last_resume_step
;
466 /* The signal specified in the last target_resume call for this
468 enum gdb_signal last_resume_sig
;
470 /* Whether this thread was already vCont-resumed on the remote
476 free_private_thread_info (struct private_thread_info
*info
)
483 /* This data could be associated with a target, but we do not always
484 have access to the current target when we need it, so for now it is
485 static. This will be fine for as long as only one target is in use
487 static struct remote_state
*remote_state
;
489 static struct remote_state
*
490 get_remote_state_raw (void)
495 /* Allocate a new struct remote_state with xmalloc, initialize it, and
498 static struct remote_state
*
499 new_remote_state (void)
501 struct remote_state
*result
= XCNEW (struct remote_state
);
503 /* The default buffer size is unimportant; it will be expanded
504 whenever a larger buffer is needed. */
505 result
->buf_size
= 400;
506 result
->buf
= (char *) xmalloc (result
->buf_size
);
507 result
->remote_traceframe_number
= -1;
508 result
->last_sent_signal
= GDB_SIGNAL_0
;
509 result
->last_resume_exec_dir
= EXEC_FORWARD
;
515 /* Description of the remote protocol for a given architecture. */
519 long offset
; /* Offset into G packet. */
520 long regnum
; /* GDB's internal register number. */
521 LONGEST pnum
; /* Remote protocol register number. */
522 int in_g_packet
; /* Always part of G packet. */
523 /* long size in bytes; == register_size (target_gdbarch (), regnum);
525 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
529 struct remote_arch_state
531 /* Description of the remote protocol registers. */
532 long sizeof_g_packet
;
534 /* Description of the remote protocol registers indexed by REGNUM
535 (making an array gdbarch_num_regs in size). */
536 struct packet_reg
*regs
;
538 /* This is the size (in chars) of the first response to the ``g''
539 packet. It is used as a heuristic when determining the maximum
540 size of memory-read and memory-write packets. A target will
541 typically only reserve a buffer large enough to hold the ``g''
542 packet. The size does not include packet overhead (headers and
544 long actual_register_packet_size
;
546 /* This is the maximum size (in chars) of a non read/write packet.
547 It is also used as a cap on the size of read/write packets. */
548 long remote_packet_size
;
551 /* Utility: generate error from an incoming stub packet. */
553 trace_error (char *buf
)
556 return; /* not an error msg */
559 case '1': /* malformed packet error */
560 if (*++buf
== '0') /* general case: */
561 error (_("remote.c: error in outgoing packet."));
563 error (_("remote.c: error in outgoing packet at field #%ld."),
564 strtol (buf
, NULL
, 16));
566 error (_("Target returns error code '%s'."), buf
);
570 /* Utility: wait for reply from stub, while accepting "O" packets. */
572 remote_get_noisy_reply (char **buf_p
,
575 do /* Loop on reply from remote stub. */
579 QUIT
; /* Allow user to bail out with ^C. */
580 getpkt (buf_p
, sizeof_buf
, 0);
584 else if (startswith (buf
, "qRelocInsn:"))
587 CORE_ADDR from
, to
, org_to
;
589 int adjusted_size
= 0;
592 p
= buf
+ strlen ("qRelocInsn:");
593 pp
= unpack_varlen_hex (p
, &ul
);
595 error (_("invalid qRelocInsn packet: %s"), buf
);
599 unpack_varlen_hex (p
, &ul
);
606 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
609 CATCH (ex
, RETURN_MASK_ALL
)
611 if (ex
.error
== MEMORY_ERROR
)
613 /* Propagate memory errors silently back to the
614 target. The stub may have limited the range of
615 addresses we can write to, for example. */
619 /* Something unexpectedly bad happened. Be verbose
620 so we can tell what, and propagate the error back
621 to the stub, so it doesn't get stuck waiting for
623 exception_fprintf (gdb_stderr
, ex
,
624 _("warning: relocating instruction: "));
632 adjusted_size
= to
- org_to
;
634 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
638 else if (buf
[0] == 'O' && buf
[1] != 'K')
639 remote_console_output (buf
+ 1); /* 'O' message from stub */
641 return buf
; /* Here's the actual reply. */
646 /* Handle for retreving the remote protocol data from gdbarch. */
647 static struct gdbarch_data
*remote_gdbarch_data_handle
;
649 static struct remote_arch_state
*
650 get_remote_arch_state (void)
652 gdb_assert (target_gdbarch () != NULL
);
653 return ((struct remote_arch_state
*)
654 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
657 /* Fetch the global remote target state. */
659 static struct remote_state
*
660 get_remote_state (void)
662 /* Make sure that the remote architecture state has been
663 initialized, because doing so might reallocate rs->buf. Any
664 function which calls getpkt also needs to be mindful of changes
665 to rs->buf, but this call limits the number of places which run
667 get_remote_arch_state ();
669 return get_remote_state_raw ();
672 /* Cleanup routine for the remote module's pspace data. */
675 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
677 char *remote_exec_file
= (char *) arg
;
679 xfree (remote_exec_file
);
682 /* Fetch the remote exec-file from the current program space. */
685 get_remote_exec_file (void)
687 char *remote_exec_file
;
690 = (char *) program_space_data (current_program_space
,
692 if (remote_exec_file
== NULL
)
695 return remote_exec_file
;
698 /* Set the remote exec file for PSPACE. */
701 set_pspace_remote_exec_file (struct program_space
*pspace
,
702 char *remote_exec_file
)
704 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
707 set_program_space_data (pspace
, remote_pspace_data
,
708 xstrdup (remote_exec_file
));
711 /* The "set/show remote exec-file" set command hook. */
714 set_remote_exec_file (char *ignored
, int from_tty
,
715 struct cmd_list_element
*c
)
717 gdb_assert (remote_exec_file_var
!= NULL
);
718 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
721 /* The "set/show remote exec-file" show command hook. */
724 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
725 struct cmd_list_element
*cmd
, const char *value
)
727 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
731 compare_pnums (const void *lhs_
, const void *rhs_
)
733 const struct packet_reg
* const *lhs
734 = (const struct packet_reg
* const *) lhs_
;
735 const struct packet_reg
* const *rhs
736 = (const struct packet_reg
* const *) rhs_
;
738 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
740 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
747 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
749 int regnum
, num_remote_regs
, offset
;
750 struct packet_reg
**remote_regs
;
752 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
754 struct packet_reg
*r
= ®s
[regnum
];
756 if (register_size (gdbarch
, regnum
) == 0)
757 /* Do not try to fetch zero-sized (placeholder) registers. */
760 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
765 /* Define the g/G packet format as the contents of each register
766 with a remote protocol number, in order of ascending protocol
769 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
770 for (num_remote_regs
= 0, regnum
= 0;
771 regnum
< gdbarch_num_regs (gdbarch
);
773 if (regs
[regnum
].pnum
!= -1)
774 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
776 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
779 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
781 remote_regs
[regnum
]->in_g_packet
= 1;
782 remote_regs
[regnum
]->offset
= offset
;
783 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
789 /* Given the architecture described by GDBARCH, return the remote
790 protocol register's number and the register's offset in the g/G
791 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
792 If the target does not have a mapping for REGNUM, return false,
793 otherwise, return true. */
796 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
797 int *pnum
, int *poffset
)
799 struct packet_reg
*regs
;
800 struct cleanup
*old_chain
;
802 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
804 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
805 old_chain
= make_cleanup (xfree
, regs
);
807 map_regcache_remote_table (gdbarch
, regs
);
809 *pnum
= regs
[regnum
].pnum
;
810 *poffset
= regs
[regnum
].offset
;
812 do_cleanups (old_chain
);
818 init_remote_state (struct gdbarch
*gdbarch
)
820 struct remote_state
*rs
= get_remote_state_raw ();
821 struct remote_arch_state
*rsa
;
823 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
825 /* Use the architecture to build a regnum<->pnum table, which will be
826 1:1 unless a feature set specifies otherwise. */
827 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
828 gdbarch_num_regs (gdbarch
),
831 /* Record the maximum possible size of the g packet - it may turn out
833 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
835 /* Default maximum number of characters in a packet body. Many
836 remote stubs have a hardwired buffer size of 400 bytes
837 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
838 as the maximum packet-size to ensure that the packet and an extra
839 NUL character can always fit in the buffer. This stops GDB
840 trashing stubs that try to squeeze an extra NUL into what is
841 already a full buffer (As of 1999-12-04 that was most stubs). */
842 rsa
->remote_packet_size
= 400 - 1;
844 /* This one is filled in when a ``g'' packet is received. */
845 rsa
->actual_register_packet_size
= 0;
847 /* Should rsa->sizeof_g_packet needs more space than the
848 default, adjust the size accordingly. Remember that each byte is
849 encoded as two characters. 32 is the overhead for the packet
850 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
851 (``$NN:G...#NN'') is a better guess, the below has been padded a
853 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
854 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
856 /* Make sure that the packet buffer is plenty big enough for
857 this architecture. */
858 if (rs
->buf_size
< rsa
->remote_packet_size
)
860 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
861 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
867 /* Return the current allowed size of a remote packet. This is
868 inferred from the current architecture, and should be used to
869 limit the length of outgoing packets. */
871 get_remote_packet_size (void)
873 struct remote_state
*rs
= get_remote_state ();
874 struct remote_arch_state
*rsa
= get_remote_arch_state ();
876 if (rs
->explicit_packet_size
)
877 return rs
->explicit_packet_size
;
879 return rsa
->remote_packet_size
;
882 static struct packet_reg
*
883 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
885 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
889 struct packet_reg
*r
= &rsa
->regs
[regnum
];
891 gdb_assert (r
->regnum
== regnum
);
896 static struct packet_reg
*
897 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
901 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
903 struct packet_reg
*r
= &rsa
->regs
[i
];
911 static struct target_ops remote_ops
;
913 static struct target_ops extended_remote_ops
;
915 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
916 ``forever'' still use the normal timeout mechanism. This is
917 currently used by the ASYNC code to guarentee that target reads
918 during the initial connect always time-out. Once getpkt has been
919 modified to return a timeout indication and, in turn
920 remote_wait()/wait_for_inferior() have gained a timeout parameter
922 static int wait_forever_enabled_p
= 1;
924 /* Allow the user to specify what sequence to send to the remote
925 when he requests a program interruption: Although ^C is usually
926 what remote systems expect (this is the default, here), it is
927 sometimes preferable to send a break. On other systems such
928 as the Linux kernel, a break followed by g, which is Magic SysRq g
929 is required in order to interrupt the execution. */
930 const char interrupt_sequence_control_c
[] = "Ctrl-C";
931 const char interrupt_sequence_break
[] = "BREAK";
932 const char interrupt_sequence_break_g
[] = "BREAK-g";
933 static const char *const interrupt_sequence_modes
[] =
935 interrupt_sequence_control_c
,
936 interrupt_sequence_break
,
937 interrupt_sequence_break_g
,
940 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
943 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
944 struct cmd_list_element
*c
,
947 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
948 fprintf_filtered (file
,
949 _("Send the ASCII ETX character (Ctrl-c) "
950 "to the remote target to interrupt the "
951 "execution of the program.\n"));
952 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
953 fprintf_filtered (file
,
954 _("send a break signal to the remote target "
955 "to interrupt the execution of the program.\n"));
956 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
957 fprintf_filtered (file
,
958 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
959 "the remote target to interrupt the execution "
960 "of Linux kernel.\n"));
962 internal_error (__FILE__
, __LINE__
,
963 _("Invalid value for interrupt_sequence_mode: %s."),
964 interrupt_sequence_mode
);
967 /* This boolean variable specifies whether interrupt_sequence is sent
968 to the remote target when gdb connects to it.
969 This is mostly needed when you debug the Linux kernel: The Linux kernel
970 expects BREAK g which is Magic SysRq g for connecting gdb. */
971 static int interrupt_on_connect
= 0;
973 /* This variable is used to implement the "set/show remotebreak" commands.
974 Since these commands are now deprecated in favor of "set/show remote
975 interrupt-sequence", it no longer has any effect on the code. */
976 static int remote_break
;
979 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
982 interrupt_sequence_mode
= interrupt_sequence_break
;
984 interrupt_sequence_mode
= interrupt_sequence_control_c
;
988 show_remotebreak (struct ui_file
*file
, int from_tty
,
989 struct cmd_list_element
*c
,
994 /* This variable sets the number of bits in an address that are to be
995 sent in a memory ("M" or "m") packet. Normally, after stripping
996 leading zeros, the entire address would be sent. This variable
997 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
998 initial implementation of remote.c restricted the address sent in
999 memory packets to ``host::sizeof long'' bytes - (typically 32
1000 bits). Consequently, for 64 bit targets, the upper 32 bits of an
1001 address was never sent. Since fixing this bug may cause a break in
1002 some remote targets this variable is principly provided to
1003 facilitate backward compatibility. */
1005 static unsigned int remote_address_size
;
1007 /* Temporary to track who currently owns the terminal. See
1008 remote_terminal_* for more details. */
1010 static int remote_async_terminal_ours_p
;
1013 /* User configurable variables for the number of characters in a
1014 memory read/write packet. MIN (rsa->remote_packet_size,
1015 rsa->sizeof_g_packet) is the default. Some targets need smaller
1016 values (fifo overruns, et.al.) and some users need larger values
1017 (speed up transfers). The variables ``preferred_*'' (the user
1018 request), ``current_*'' (what was actually set) and ``forced_*''
1019 (Positive - a soft limit, negative - a hard limit). */
1021 struct memory_packet_config
1028 /* The default max memory-write-packet-size. The 16k is historical.
1029 (It came from older GDB's using alloca for buffers and the
1030 knowledge (folklore?) that some hosts don't cope very well with
1031 large alloca calls.) */
1032 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1034 /* The minimum remote packet size for memory transfers. Ensures we
1035 can write at least one byte. */
1036 #define MIN_MEMORY_PACKET_SIZE 20
1038 /* Compute the current size of a read/write packet. Since this makes
1039 use of ``actual_register_packet_size'' the computation is dynamic. */
1042 get_memory_packet_size (struct memory_packet_config
*config
)
1044 struct remote_state
*rs
= get_remote_state ();
1045 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1048 if (config
->fixed_p
)
1050 if (config
->size
<= 0)
1051 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1053 what_they_get
= config
->size
;
1057 what_they_get
= get_remote_packet_size ();
1058 /* Limit the packet to the size specified by the user. */
1059 if (config
->size
> 0
1060 && what_they_get
> config
->size
)
1061 what_they_get
= config
->size
;
1063 /* Limit it to the size of the targets ``g'' response unless we have
1064 permission from the stub to use a larger packet size. */
1065 if (rs
->explicit_packet_size
== 0
1066 && rsa
->actual_register_packet_size
> 0
1067 && what_they_get
> rsa
->actual_register_packet_size
)
1068 what_they_get
= rsa
->actual_register_packet_size
;
1070 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1071 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1073 /* Make sure there is room in the global buffer for this packet
1074 (including its trailing NUL byte). */
1075 if (rs
->buf_size
< what_they_get
+ 1)
1077 rs
->buf_size
= 2 * what_they_get
;
1078 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1081 return what_they_get
;
1084 /* Update the size of a read/write packet. If they user wants
1085 something really big then do a sanity check. */
1088 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1090 int fixed_p
= config
->fixed_p
;
1091 long size
= config
->size
;
1094 error (_("Argument required (integer, `fixed' or `limited')."));
1095 else if (strcmp (args
, "hard") == 0
1096 || strcmp (args
, "fixed") == 0)
1098 else if (strcmp (args
, "soft") == 0
1099 || strcmp (args
, "limit") == 0)
1105 size
= strtoul (args
, &end
, 0);
1107 error (_("Invalid %s (bad syntax)."), config
->name
);
1109 /* Instead of explicitly capping the size of a packet to or
1110 disallowing it, the user is allowed to set the size to
1111 something arbitrarily large. */
1114 /* So that the query shows the correct value. */
1116 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1119 if (fixed_p
&& !config
->fixed_p
)
1121 if (! query (_("The target may not be able to correctly handle a %s\n"
1122 "of %ld bytes. Change the packet size? "),
1123 config
->name
, size
))
1124 error (_("Packet size not changed."));
1126 /* Update the config. */
1127 config
->fixed_p
= fixed_p
;
1128 config
->size
= size
;
1132 show_memory_packet_size (struct memory_packet_config
*config
)
1134 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1135 if (config
->fixed_p
)
1136 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1137 get_memory_packet_size (config
));
1139 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1140 get_memory_packet_size (config
));
1143 static struct memory_packet_config memory_write_packet_config
=
1145 "memory-write-packet-size",
1149 set_memory_write_packet_size (char *args
, int from_tty
)
1151 set_memory_packet_size (args
, &memory_write_packet_config
);
1155 show_memory_write_packet_size (char *args
, int from_tty
)
1157 show_memory_packet_size (&memory_write_packet_config
);
1161 get_memory_write_packet_size (void)
1163 return get_memory_packet_size (&memory_write_packet_config
);
1166 static struct memory_packet_config memory_read_packet_config
=
1168 "memory-read-packet-size",
1172 set_memory_read_packet_size (char *args
, int from_tty
)
1174 set_memory_packet_size (args
, &memory_read_packet_config
);
1178 show_memory_read_packet_size (char *args
, int from_tty
)
1180 show_memory_packet_size (&memory_read_packet_config
);
1184 get_memory_read_packet_size (void)
1186 long size
= get_memory_packet_size (&memory_read_packet_config
);
1188 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1189 extra buffer size argument before the memory read size can be
1190 increased beyond this. */
1191 if (size
> get_remote_packet_size ())
1192 size
= get_remote_packet_size ();
1197 /* Generic configuration support for packets the stub optionally
1198 supports. Allows the user to specify the use of the packet as well
1199 as allowing GDB to auto-detect support in the remote stub. */
1203 PACKET_SUPPORT_UNKNOWN
= 0,
1208 struct packet_config
1213 /* If auto, GDB auto-detects support for this packet or feature,
1214 either through qSupported, or by trying the packet and looking
1215 at the response. If true, GDB assumes the target supports this
1216 packet. If false, the packet is disabled. Configs that don't
1217 have an associated command always have this set to auto. */
1218 enum auto_boolean detect
;
1220 /* Does the target support this packet? */
1221 enum packet_support support
;
1224 /* Analyze a packet's return value and update the packet config
1234 static enum packet_support
packet_config_support (struct packet_config
*config
);
1235 static enum packet_support
packet_support (int packet
);
1238 show_packet_config_cmd (struct packet_config
*config
)
1240 char *support
= "internal-error";
1242 switch (packet_config_support (config
))
1245 support
= "enabled";
1247 case PACKET_DISABLE
:
1248 support
= "disabled";
1250 case PACKET_SUPPORT_UNKNOWN
:
1251 support
= "unknown";
1254 switch (config
->detect
)
1256 case AUTO_BOOLEAN_AUTO
:
1257 printf_filtered (_("Support for the `%s' packet "
1258 "is auto-detected, currently %s.\n"),
1259 config
->name
, support
);
1261 case AUTO_BOOLEAN_TRUE
:
1262 case AUTO_BOOLEAN_FALSE
:
1263 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1264 config
->name
, support
);
1270 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1271 const char *title
, int legacy
)
1277 config
->name
= name
;
1278 config
->title
= title
;
1279 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1281 show_doc
= xstrprintf ("Show current use of remote "
1282 "protocol `%s' (%s) packet",
1284 /* set/show TITLE-packet {auto,on,off} */
1285 cmd_name
= xstrprintf ("%s-packet", title
);
1286 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1287 &config
->detect
, set_doc
,
1288 show_doc
, NULL
, /* help_doc */
1290 show_remote_protocol_packet_cmd
,
1291 &remote_set_cmdlist
, &remote_show_cmdlist
);
1292 /* The command code copies the documentation strings. */
1295 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1300 legacy_name
= xstrprintf ("%s-packet", name
);
1301 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1302 &remote_set_cmdlist
);
1303 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1304 &remote_show_cmdlist
);
1308 static enum packet_result
1309 packet_check_result (const char *buf
)
1313 /* The stub recognized the packet request. Check that the
1314 operation succeeded. */
1316 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1318 /* "Enn" - definitly an error. */
1319 return PACKET_ERROR
;
1321 /* Always treat "E." as an error. This will be used for
1322 more verbose error messages, such as E.memtypes. */
1323 if (buf
[0] == 'E' && buf
[1] == '.')
1324 return PACKET_ERROR
;
1326 /* The packet may or may not be OK. Just assume it is. */
1330 /* The stub does not support the packet. */
1331 return PACKET_UNKNOWN
;
1334 static enum packet_result
1335 packet_ok (const char *buf
, struct packet_config
*config
)
1337 enum packet_result result
;
1339 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1340 && config
->support
== PACKET_DISABLE
)
1341 internal_error (__FILE__
, __LINE__
,
1342 _("packet_ok: attempt to use a disabled packet"));
1344 result
= packet_check_result (buf
);
1349 /* The stub recognized the packet request. */
1350 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1353 fprintf_unfiltered (gdb_stdlog
,
1354 "Packet %s (%s) is supported\n",
1355 config
->name
, config
->title
);
1356 config
->support
= PACKET_ENABLE
;
1359 case PACKET_UNKNOWN
:
1360 /* The stub does not support the packet. */
1361 if (config
->detect
== AUTO_BOOLEAN_AUTO
1362 && config
->support
== PACKET_ENABLE
)
1364 /* If the stub previously indicated that the packet was
1365 supported then there is a protocol error. */
1366 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1367 config
->name
, config
->title
);
1369 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1371 /* The user set it wrong. */
1372 error (_("Enabled packet %s (%s) not recognized by stub"),
1373 config
->name
, config
->title
);
1377 fprintf_unfiltered (gdb_stdlog
,
1378 "Packet %s (%s) is NOT supported\n",
1379 config
->name
, config
->title
);
1380 config
->support
= PACKET_DISABLE
;
1401 PACKET_vFile_pwrite
,
1403 PACKET_vFile_unlink
,
1404 PACKET_vFile_readlink
,
1407 PACKET_qXfer_features
,
1408 PACKET_qXfer_exec_file
,
1409 PACKET_qXfer_libraries
,
1410 PACKET_qXfer_libraries_svr4
,
1411 PACKET_qXfer_memory_map
,
1412 PACKET_qXfer_spu_read
,
1413 PACKET_qXfer_spu_write
,
1414 PACKET_qXfer_osdata
,
1415 PACKET_qXfer_threads
,
1416 PACKET_qXfer_statictrace_read
,
1417 PACKET_qXfer_traceframe_info
,
1423 PACKET_QPassSignals
,
1424 PACKET_QCatchSyscalls
,
1425 PACKET_QProgramSignals
,
1427 PACKET_qSearch_memory
,
1430 PACKET_QStartNoAckMode
,
1432 PACKET_qXfer_siginfo_read
,
1433 PACKET_qXfer_siginfo_write
,
1436 /* Support for conditional tracepoints. */
1437 PACKET_ConditionalTracepoints
,
1439 /* Support for target-side breakpoint conditions. */
1440 PACKET_ConditionalBreakpoints
,
1442 /* Support for target-side breakpoint commands. */
1443 PACKET_BreakpointCommands
,
1445 /* Support for fast tracepoints. */
1446 PACKET_FastTracepoints
,
1448 /* Support for static tracepoints. */
1449 PACKET_StaticTracepoints
,
1451 /* Support for installing tracepoints while a trace experiment is
1453 PACKET_InstallInTrace
,
1457 PACKET_TracepointSource
,
1460 PACKET_QDisableRandomization
,
1462 PACKET_QTBuffer_size
,
1466 PACKET_qXfer_btrace
,
1468 /* Support for the QNonStop packet. */
1471 /* Support for the QThreadEvents packet. */
1472 PACKET_QThreadEvents
,
1474 /* Support for multi-process extensions. */
1475 PACKET_multiprocess_feature
,
1477 /* Support for enabling and disabling tracepoints while a trace
1478 experiment is running. */
1479 PACKET_EnableDisableTracepoints_feature
,
1481 /* Support for collecting strings using the tracenz bytecode. */
1482 PACKET_tracenz_feature
,
1484 /* Support for continuing to run a trace experiment while GDB is
1486 PACKET_DisconnectedTracing_feature
,
1488 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1489 PACKET_augmented_libraries_svr4_read_feature
,
1491 /* Support for the qXfer:btrace-conf:read packet. */
1492 PACKET_qXfer_btrace_conf
,
1494 /* Support for the Qbtrace-conf:bts:size packet. */
1495 PACKET_Qbtrace_conf_bts_size
,
1497 /* Support for swbreak+ feature. */
1498 PACKET_swbreak_feature
,
1500 /* Support for hwbreak+ feature. */
1501 PACKET_hwbreak_feature
,
1503 /* Support for fork events. */
1504 PACKET_fork_event_feature
,
1506 /* Support for vfork events. */
1507 PACKET_vfork_event_feature
,
1509 /* Support for the Qbtrace-conf:pt:size packet. */
1510 PACKET_Qbtrace_conf_pt_size
,
1512 /* Support for exec events. */
1513 PACKET_exec_event_feature
,
1515 /* Support for query supported vCont actions. */
1516 PACKET_vContSupported
,
1518 /* Support remote CTRL-C. */
1521 /* Support TARGET_WAITKIND_NO_RESUMED. */
1527 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1529 /* Returns the packet's corresponding "set remote foo-packet" command
1530 state. See struct packet_config for more details. */
1532 static enum auto_boolean
1533 packet_set_cmd_state (int packet
)
1535 return remote_protocol_packets
[packet
].detect
;
1538 /* Returns whether a given packet or feature is supported. This takes
1539 into account the state of the corresponding "set remote foo-packet"
1540 command, which may be used to bypass auto-detection. */
1542 static enum packet_support
1543 packet_config_support (struct packet_config
*config
)
1545 switch (config
->detect
)
1547 case AUTO_BOOLEAN_TRUE
:
1548 return PACKET_ENABLE
;
1549 case AUTO_BOOLEAN_FALSE
:
1550 return PACKET_DISABLE
;
1551 case AUTO_BOOLEAN_AUTO
:
1552 return config
->support
;
1554 gdb_assert_not_reached (_("bad switch"));
1558 /* Same as packet_config_support, but takes the packet's enum value as
1561 static enum packet_support
1562 packet_support (int packet
)
1564 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1566 return packet_config_support (config
);
1570 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1571 struct cmd_list_element
*c
,
1574 struct packet_config
*packet
;
1576 for (packet
= remote_protocol_packets
;
1577 packet
< &remote_protocol_packets
[PACKET_MAX
];
1580 if (&packet
->detect
== c
->var
)
1582 show_packet_config_cmd (packet
);
1586 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1590 /* Should we try one of the 'Z' requests? */
1594 Z_PACKET_SOFTWARE_BP
,
1595 Z_PACKET_HARDWARE_BP
,
1602 /* For compatibility with older distributions. Provide a ``set remote
1603 Z-packet ...'' command that updates all the Z packet types. */
1605 static enum auto_boolean remote_Z_packet_detect
;
1608 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1609 struct cmd_list_element
*c
)
1613 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1614 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1618 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1619 struct cmd_list_element
*c
,
1624 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1626 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1630 /* Returns true if the multi-process extensions are in effect. */
1633 remote_multi_process_p (struct remote_state
*rs
)
1635 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1638 /* Returns true if fork events are supported. */
1641 remote_fork_event_p (struct remote_state
*rs
)
1643 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1646 /* Returns true if vfork events are supported. */
1649 remote_vfork_event_p (struct remote_state
*rs
)
1651 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1654 /* Returns true if exec events are supported. */
1657 remote_exec_event_p (struct remote_state
*rs
)
1659 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1662 /* Insert fork catchpoint target routine. If fork events are enabled
1663 then return success, nothing more to do. */
1666 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1668 struct remote_state
*rs
= get_remote_state ();
1670 return !remote_fork_event_p (rs
);
1673 /* Remove fork catchpoint target routine. Nothing to do, just
1677 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1682 /* Insert vfork catchpoint target routine. If vfork events are enabled
1683 then return success, nothing more to do. */
1686 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1688 struct remote_state
*rs
= get_remote_state ();
1690 return !remote_vfork_event_p (rs
);
1693 /* Remove vfork catchpoint target routine. Nothing to do, just
1697 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1702 /* Insert exec catchpoint target routine. If exec events are
1703 enabled, just return success. */
1706 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1708 struct remote_state
*rs
= get_remote_state ();
1710 return !remote_exec_event_p (rs
);
1713 /* Remove exec catchpoint target routine. Nothing to do, just
1717 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1723 /* Asynchronous signal handle registered as event loop source for
1724 when we have pending events ready to be passed to the core. */
1726 static struct async_event_handler
*remote_async_inferior_event_token
;
1730 static ptid_t magic_null_ptid
;
1731 static ptid_t not_sent_ptid
;
1732 static ptid_t any_thread_ptid
;
1734 /* Find out if the stub attached to PID (and hence GDB should offer to
1735 detach instead of killing it when bailing out). */
1738 remote_query_attached (int pid
)
1740 struct remote_state
*rs
= get_remote_state ();
1741 size_t size
= get_remote_packet_size ();
1743 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1746 if (remote_multi_process_p (rs
))
1747 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1749 xsnprintf (rs
->buf
, size
, "qAttached");
1752 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1754 switch (packet_ok (rs
->buf
,
1755 &remote_protocol_packets
[PACKET_qAttached
]))
1758 if (strcmp (rs
->buf
, "1") == 0)
1762 warning (_("Remote failure reply: %s"), rs
->buf
);
1764 case PACKET_UNKNOWN
:
1771 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1772 has been invented by GDB, instead of reported by the target. Since
1773 we can be connected to a remote system before before knowing about
1774 any inferior, mark the target with execution when we find the first
1775 inferior. If ATTACHED is 1, then we had just attached to this
1776 inferior. If it is 0, then we just created this inferior. If it
1777 is -1, then try querying the remote stub to find out if it had
1778 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1779 attempt to open this inferior's executable as the main executable
1780 if no main executable is open already. */
1782 static struct inferior
*
1783 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1786 struct inferior
*inf
;
1788 /* Check whether this process we're learning about is to be
1789 considered attached, or if is to be considered to have been
1790 spawned by the stub. */
1792 attached
= remote_query_attached (pid
);
1794 if (gdbarch_has_global_solist (target_gdbarch ()))
1796 /* If the target shares code across all inferiors, then every
1797 attach adds a new inferior. */
1798 inf
= add_inferior (pid
);
1800 /* ... and every inferior is bound to the same program space.
1801 However, each inferior may still have its own address
1803 inf
->aspace
= maybe_new_address_space ();
1804 inf
->pspace
= current_program_space
;
1808 /* In the traditional debugging scenario, there's a 1-1 match
1809 between program/address spaces. We simply bind the inferior
1810 to the program space's address space. */
1811 inf
= current_inferior ();
1812 inferior_appeared (inf
, pid
);
1815 inf
->attach_flag
= attached
;
1816 inf
->fake_pid_p
= fake_pid_p
;
1818 /* If no main executable is currently open then attempt to
1819 open the file that was executed to create this inferior. */
1820 if (try_open_exec
&& get_exec_file (0) == NULL
)
1821 exec_file_locate_attach (pid
, 0, 1);
1826 static struct private_thread_info
*
1827 get_private_info_thread (struct thread_info
*info
);
1829 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1830 according to RUNNING. */
1833 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1835 struct remote_state
*rs
= get_remote_state ();
1836 struct thread_info
*thread
;
1838 /* GDB historically didn't pull threads in the initial connection
1839 setup. If the remote target doesn't even have a concept of
1840 threads (e.g., a bare-metal target), even if internally we
1841 consider that a single-threaded target, mentioning a new thread
1842 might be confusing to the user. Be silent then, preserving the
1843 age old behavior. */
1844 if (rs
->starting_up
)
1845 thread
= add_thread_silent (ptid
);
1847 thread
= add_thread (ptid
);
1849 get_private_info_thread (thread
)->vcont_resumed
= executing
;
1850 set_executing (ptid
, executing
);
1851 set_running (ptid
, running
);
1854 /* Come here when we learn about a thread id from the remote target.
1855 It may be the first time we hear about such thread, so take the
1856 opportunity to add it to GDB's thread list. In case this is the
1857 first time we're noticing its corresponding inferior, add it to
1858 GDB's inferior list as well. EXECUTING indicates whether the
1859 thread is (internally) executing or stopped. */
1862 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1864 /* In non-stop mode, we assume new found threads are (externally)
1865 running until proven otherwise with a stop reply. In all-stop,
1866 we can only get here if all threads are stopped. */
1867 int running
= target_is_non_stop_p () ? 1 : 0;
1869 /* If this is a new thread, add it to GDB's thread list.
1870 If we leave it up to WFI to do this, bad things will happen. */
1872 if (in_thread_list (currthread
) && is_exited (currthread
))
1874 /* We're seeing an event on a thread id we knew had exited.
1875 This has to be a new thread reusing the old id. Add it. */
1876 remote_add_thread (currthread
, running
, executing
);
1880 if (!in_thread_list (currthread
))
1882 struct inferior
*inf
= NULL
;
1883 int pid
= ptid_get_pid (currthread
);
1885 if (ptid_is_pid (inferior_ptid
)
1886 && pid
== ptid_get_pid (inferior_ptid
))
1888 /* inferior_ptid has no thread member yet. This can happen
1889 with the vAttach -> remote_wait,"TAAthread:" path if the
1890 stub doesn't support qC. This is the first stop reported
1891 after an attach, so this is the main thread. Update the
1892 ptid in the thread list. */
1893 if (in_thread_list (pid_to_ptid (pid
)))
1894 thread_change_ptid (inferior_ptid
, currthread
);
1897 remote_add_thread (currthread
, running
, executing
);
1898 inferior_ptid
= currthread
;
1903 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1905 /* inferior_ptid is not set yet. This can happen with the
1906 vRun -> remote_wait,"TAAthread:" path if the stub
1907 doesn't support qC. This is the first stop reported
1908 after an attach, so this is the main thread. Update the
1909 ptid in the thread list. */
1910 thread_change_ptid (inferior_ptid
, currthread
);
1914 /* When connecting to a target remote, or to a target
1915 extended-remote which already was debugging an inferior, we
1916 may not know about it yet. Add it before adding its child
1917 thread, so notifications are emitted in a sensible order. */
1918 if (!in_inferior_list (ptid_get_pid (currthread
)))
1920 struct remote_state
*rs
= get_remote_state ();
1921 int fake_pid_p
= !remote_multi_process_p (rs
);
1923 inf
= remote_add_inferior (fake_pid_p
,
1924 ptid_get_pid (currthread
), -1, 1);
1927 /* This is really a new thread. Add it. */
1928 remote_add_thread (currthread
, running
, executing
);
1930 /* If we found a new inferior, let the common code do whatever
1931 it needs to with it (e.g., read shared libraries, insert
1932 breakpoints), unless we're just setting up an all-stop
1936 struct remote_state
*rs
= get_remote_state ();
1938 if (!rs
->starting_up
)
1939 notice_new_inferior (currthread
, executing
, 0);
1944 /* Return THREAD's private thread data, creating it if necessary. */
1946 static struct private_thread_info
*
1947 get_private_info_thread (struct thread_info
*thread
)
1949 gdb_assert (thread
!= NULL
);
1951 if (thread
->priv
== NULL
)
1953 struct private_thread_info
*priv
= XNEW (struct private_thread_info
);
1955 thread
->private_dtor
= free_private_thread_info
;
1956 thread
->priv
= priv
;
1962 priv
->last_resume_step
= 0;
1963 priv
->last_resume_sig
= GDB_SIGNAL_0
;
1964 priv
->vcont_resumed
= 0;
1967 return thread
->priv
;
1970 /* Return PTID's private thread data, creating it if necessary. */
1972 static struct private_thread_info
*
1973 get_private_info_ptid (ptid_t ptid
)
1975 struct thread_info
*info
= find_thread_ptid (ptid
);
1977 return get_private_info_thread (info
);
1980 /* Call this function as a result of
1981 1) A halt indication (T packet) containing a thread id
1982 2) A direct query of currthread
1983 3) Successful execution of set thread */
1986 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1988 rs
->general_thread
= currthread
;
1991 /* If 'QPassSignals' is supported, tell the remote stub what signals
1992 it can simply pass through to the inferior without reporting. */
1995 remote_pass_signals (struct target_ops
*self
,
1996 int numsigs
, unsigned char *pass_signals
)
1998 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
2000 char *pass_packet
, *p
;
2002 struct remote_state
*rs
= get_remote_state ();
2004 gdb_assert (numsigs
< 256);
2005 for (i
= 0; i
< numsigs
; i
++)
2007 if (pass_signals
[i
])
2010 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
2011 strcpy (pass_packet
, "QPassSignals:");
2012 p
= pass_packet
+ strlen (pass_packet
);
2013 for (i
= 0; i
< numsigs
; i
++)
2015 if (pass_signals
[i
])
2018 *p
++ = tohex (i
>> 4);
2019 *p
++ = tohex (i
& 15);
2028 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
2030 putpkt (pass_packet
);
2031 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2032 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
2033 if (rs
->last_pass_packet
)
2034 xfree (rs
->last_pass_packet
);
2035 rs
->last_pass_packet
= pass_packet
;
2038 xfree (pass_packet
);
2042 /* If 'QCatchSyscalls' is supported, tell the remote stub
2043 to report syscalls to GDB. */
2046 remote_set_syscall_catchpoint (struct target_ops
*self
,
2047 int pid
, int needed
, int any_count
,
2048 int table_size
, int *table
)
2051 enum packet_result result
;
2054 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2056 /* Not supported. */
2060 if (needed
&& !any_count
)
2064 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2065 for (i
= 0; i
< table_size
; i
++)
2074 fprintf_unfiltered (gdb_stdlog
,
2075 "remote_set_syscall_catchpoint "
2076 "pid %d needed %d any_count %d n_sysno %d\n",
2077 pid
, needed
, any_count
, n_sysno
);
2082 /* Prepare a packet with the sysno list, assuming max 8+1
2083 characters for a sysno. If the resulting packet size is too
2084 big, fallback on the non-selective packet. */
2085 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2087 catch_packet
= (char *) xmalloc (maxpktsz
);
2088 strcpy (catch_packet
, "QCatchSyscalls:1");
2097 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2098 for (i
= 0; i
< table_size
; i
++)
2101 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2104 if (strlen (catch_packet
) > get_remote_packet_size ())
2106 /* catch_packet too big. Fallback to less efficient
2107 non selective mode, with GDB doing the filtering. */
2108 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2112 catch_packet
= xstrdup ("QCatchSyscalls:0");
2115 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2116 struct remote_state
*rs
= get_remote_state ();
2118 putpkt (catch_packet
);
2119 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2120 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2121 do_cleanups (old_chain
);
2122 if (result
== PACKET_OK
)
2129 /* If 'QProgramSignals' is supported, tell the remote stub what
2130 signals it should pass through to the inferior when detaching. */
2133 remote_program_signals (struct target_ops
*self
,
2134 int numsigs
, unsigned char *signals
)
2136 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2140 struct remote_state
*rs
= get_remote_state ();
2142 gdb_assert (numsigs
< 256);
2143 for (i
= 0; i
< numsigs
; i
++)
2148 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2149 strcpy (packet
, "QProgramSignals:");
2150 p
= packet
+ strlen (packet
);
2151 for (i
= 0; i
< numsigs
; i
++)
2153 if (signal_pass_state (i
))
2156 *p
++ = tohex (i
>> 4);
2157 *p
++ = tohex (i
& 15);
2166 if (!rs
->last_program_signals_packet
2167 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2170 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2171 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2172 xfree (rs
->last_program_signals_packet
);
2173 rs
->last_program_signals_packet
= packet
;
2180 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2181 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2182 thread. If GEN is set, set the general thread, if not, then set
2183 the step/continue thread. */
2185 set_thread (struct ptid ptid
, int gen
)
2187 struct remote_state
*rs
= get_remote_state ();
2188 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2189 char *buf
= rs
->buf
;
2190 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2192 if (ptid_equal (state
, ptid
))
2196 *buf
++ = gen
? 'g' : 'c';
2197 if (ptid_equal (ptid
, magic_null_ptid
))
2198 xsnprintf (buf
, endbuf
- buf
, "0");
2199 else if (ptid_equal (ptid
, any_thread_ptid
))
2200 xsnprintf (buf
, endbuf
- buf
, "0");
2201 else if (ptid_equal (ptid
, minus_one_ptid
))
2202 xsnprintf (buf
, endbuf
- buf
, "-1");
2204 write_ptid (buf
, endbuf
, ptid
);
2206 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2208 rs
->general_thread
= ptid
;
2210 rs
->continue_thread
= ptid
;
2214 set_general_thread (struct ptid ptid
)
2216 set_thread (ptid
, 1);
2220 set_continue_thread (struct ptid ptid
)
2222 set_thread (ptid
, 0);
2225 /* Change the remote current process. Which thread within the process
2226 ends up selected isn't important, as long as it is the same process
2227 as what INFERIOR_PTID points to.
2229 This comes from that fact that there is no explicit notion of
2230 "selected process" in the protocol. The selected process for
2231 general operations is the process the selected general thread
2235 set_general_process (void)
2237 struct remote_state
*rs
= get_remote_state ();
2239 /* If the remote can't handle multiple processes, don't bother. */
2240 if (!remote_multi_process_p (rs
))
2243 /* We only need to change the remote current thread if it's pointing
2244 at some other process. */
2245 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2246 set_general_thread (inferior_ptid
);
2250 /* Return nonzero if this is the main thread that we made up ourselves
2251 to model non-threaded targets as single-threaded. */
2254 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2256 if (ptid_equal (ptid
, magic_null_ptid
))
2257 /* The main thread is always alive. */
2260 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2261 /* The main thread is always alive. This can happen after a
2262 vAttach, if the remote side doesn't support
2269 /* Return nonzero if the thread PTID is still alive on the remote
2273 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2275 struct remote_state
*rs
= get_remote_state ();
2278 /* Check if this is a thread that we made up ourselves to model
2279 non-threaded targets as single-threaded. */
2280 if (remote_thread_always_alive (ops
, ptid
))
2284 endp
= rs
->buf
+ get_remote_packet_size ();
2287 write_ptid (p
, endp
, ptid
);
2290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2291 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2294 /* Return a pointer to a thread name if we know it and NULL otherwise.
2295 The thread_info object owns the memory for the name. */
2298 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2300 if (info
->priv
!= NULL
)
2301 return info
->priv
->name
;
2306 /* About these extended threadlist and threadinfo packets. They are
2307 variable length packets but, the fields within them are often fixed
2308 length. They are redundent enough to send over UDP as is the
2309 remote protocol in general. There is a matching unit test module
2312 /* WARNING: This threadref data structure comes from the remote O.S.,
2313 libstub protocol encoding, and remote.c. It is not particularly
2316 /* Right now, the internal structure is int. We want it to be bigger.
2317 Plan to fix this. */
2319 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2321 /* gdb_ext_thread_info is an internal GDB data structure which is
2322 equivalent to the reply of the remote threadinfo packet. */
2324 struct gdb_ext_thread_info
2326 threadref threadid
; /* External form of thread reference. */
2327 int active
; /* Has state interesting to GDB?
2329 char display
[256]; /* Brief state display, name,
2330 blocked/suspended. */
2331 char shortname
[32]; /* To be used to name threads. */
2332 char more_display
[256]; /* Long info, statistics, queue depth,
2336 /* The volume of remote transfers can be limited by submitting
2337 a mask containing bits specifying the desired information.
2338 Use a union of these values as the 'selection' parameter to
2339 get_thread_info. FIXME: Make these TAG names more thread specific. */
2341 #define TAG_THREADID 1
2342 #define TAG_EXISTS 2
2343 #define TAG_DISPLAY 4
2344 #define TAG_THREADNAME 8
2345 #define TAG_MOREDISPLAY 16
2347 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2349 static char *unpack_nibble (char *buf
, int *val
);
2351 static char *unpack_byte (char *buf
, int *value
);
2353 static char *pack_int (char *buf
, int value
);
2355 static char *unpack_int (char *buf
, int *value
);
2357 static char *unpack_string (char *src
, char *dest
, int length
);
2359 static char *pack_threadid (char *pkt
, threadref
*id
);
2361 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2363 void int_to_threadref (threadref
*id
, int value
);
2365 static int threadref_to_int (threadref
*ref
);
2367 static void copy_threadref (threadref
*dest
, threadref
*src
);
2369 static int threadmatch (threadref
*dest
, threadref
*src
);
2371 static char *pack_threadinfo_request (char *pkt
, int mode
,
2374 static int remote_unpack_thread_info_response (char *pkt
,
2375 threadref
*expectedref
,
2376 struct gdb_ext_thread_info
2380 static int remote_get_threadinfo (threadref
*threadid
,
2381 int fieldset
, /*TAG mask */
2382 struct gdb_ext_thread_info
*info
);
2384 static char *pack_threadlist_request (char *pkt
, int startflag
,
2386 threadref
*nextthread
);
2388 static int parse_threadlist_response (char *pkt
,
2390 threadref
*original_echo
,
2391 threadref
*resultlist
,
2394 static int remote_get_threadlist (int startflag
,
2395 threadref
*nextthread
,
2399 threadref
*threadlist
);
2401 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2403 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2404 void *context
, int looplimit
);
2406 static int remote_newthread_step (threadref
*ref
, void *context
);
2409 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2410 buffer we're allowed to write to. Returns
2411 BUF+CHARACTERS_WRITTEN. */
2414 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2417 struct remote_state
*rs
= get_remote_state ();
2419 if (remote_multi_process_p (rs
))
2421 pid
= ptid_get_pid (ptid
);
2423 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2425 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2427 tid
= ptid_get_lwp (ptid
);
2429 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2431 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2436 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2437 passed the last parsed char. Returns null_ptid on error. */
2440 read_ptid (char *buf
, char **obuf
)
2444 ULONGEST pid
= 0, tid
= 0;
2448 /* Multi-process ptid. */
2449 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2451 error (_("invalid remote ptid: %s"), p
);
2454 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2457 return ptid_build (pid
, tid
, 0);
2460 /* No multi-process. Just a tid. */
2461 pp
= unpack_varlen_hex (p
, &tid
);
2463 /* Return null_ptid when no thread id is found. */
2471 /* Since the stub is not sending a process id, then default to
2472 what's in inferior_ptid, unless it's null at this point. If so,
2473 then since there's no way to know the pid of the reported
2474 threads, use the magic number. */
2475 if (ptid_equal (inferior_ptid
, null_ptid
))
2476 pid
= ptid_get_pid (magic_null_ptid
);
2478 pid
= ptid_get_pid (inferior_ptid
);
2482 return ptid_build (pid
, tid
, 0);
2488 if (ch
>= 'a' && ch
<= 'f')
2489 return ch
- 'a' + 10;
2490 if (ch
>= '0' && ch
<= '9')
2492 if (ch
>= 'A' && ch
<= 'F')
2493 return ch
- 'A' + 10;
2498 stub_unpack_int (char *buff
, int fieldlength
)
2505 nibble
= stubhex (*buff
++);
2509 retval
= retval
<< 4;
2515 unpack_nibble (char *buf
, int *val
)
2517 *val
= fromhex (*buf
++);
2522 unpack_byte (char *buf
, int *value
)
2524 *value
= stub_unpack_int (buf
, 2);
2529 pack_int (char *buf
, int value
)
2531 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2532 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2533 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2534 buf
= pack_hex_byte (buf
, (value
& 0xff));
2539 unpack_int (char *buf
, int *value
)
2541 *value
= stub_unpack_int (buf
, 8);
2545 #if 0 /* Currently unused, uncomment when needed. */
2546 static char *pack_string (char *pkt
, char *string
);
2549 pack_string (char *pkt
, char *string
)
2554 len
= strlen (string
);
2556 len
= 200; /* Bigger than most GDB packets, junk??? */
2557 pkt
= pack_hex_byte (pkt
, len
);
2561 if ((ch
== '\0') || (ch
== '#'))
2562 ch
= '*'; /* Protect encapsulation. */
2567 #endif /* 0 (unused) */
2570 unpack_string (char *src
, char *dest
, int length
)
2579 pack_threadid (char *pkt
, threadref
*id
)
2582 unsigned char *altid
;
2584 altid
= (unsigned char *) id
;
2585 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2587 pkt
= pack_hex_byte (pkt
, *altid
++);
2593 unpack_threadid (char *inbuf
, threadref
*id
)
2596 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2599 altref
= (char *) id
;
2601 while (inbuf
< limit
)
2603 x
= stubhex (*inbuf
++);
2604 y
= stubhex (*inbuf
++);
2605 *altref
++ = (x
<< 4) | y
;
2610 /* Externally, threadrefs are 64 bits but internally, they are still
2611 ints. This is due to a mismatch of specifications. We would like
2612 to use 64bit thread references internally. This is an adapter
2616 int_to_threadref (threadref
*id
, int value
)
2618 unsigned char *scan
;
2620 scan
= (unsigned char *) id
;
2626 *scan
++ = (value
>> 24) & 0xff;
2627 *scan
++ = (value
>> 16) & 0xff;
2628 *scan
++ = (value
>> 8) & 0xff;
2629 *scan
++ = (value
& 0xff);
2633 threadref_to_int (threadref
*ref
)
2636 unsigned char *scan
;
2642 value
= (value
<< 8) | ((*scan
++) & 0xff);
2647 copy_threadref (threadref
*dest
, threadref
*src
)
2650 unsigned char *csrc
, *cdest
;
2652 csrc
= (unsigned char *) src
;
2653 cdest
= (unsigned char *) dest
;
2660 threadmatch (threadref
*dest
, threadref
*src
)
2662 /* Things are broken right now, so just assume we got a match. */
2664 unsigned char *srcp
, *destp
;
2666 srcp
= (char *) src
;
2667 destp
= (char *) dest
;
2671 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2678 threadid:1, # always request threadid
2685 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2688 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2690 *pkt
++ = 'q'; /* Info Query */
2691 *pkt
++ = 'P'; /* process or thread info */
2692 pkt
= pack_int (pkt
, mode
); /* mode */
2693 pkt
= pack_threadid (pkt
, id
); /* threadid */
2694 *pkt
= '\0'; /* terminate */
2698 /* These values tag the fields in a thread info response packet. */
2699 /* Tagging the fields allows us to request specific fields and to
2700 add more fields as time goes by. */
2702 #define TAG_THREADID 1 /* Echo the thread identifier. */
2703 #define TAG_EXISTS 2 /* Is this process defined enough to
2704 fetch registers and its stack? */
2705 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2706 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2707 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2711 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2712 struct gdb_ext_thread_info
*info
)
2714 struct remote_state
*rs
= get_remote_state ();
2718 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2721 /* info->threadid = 0; FIXME: implement zero_threadref. */
2723 info
->display
[0] = '\0';
2724 info
->shortname
[0] = '\0';
2725 info
->more_display
[0] = '\0';
2727 /* Assume the characters indicating the packet type have been
2729 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2730 pkt
= unpack_threadid (pkt
, &ref
);
2733 warning (_("Incomplete response to threadinfo request."));
2734 if (!threadmatch (&ref
, expectedref
))
2735 { /* This is an answer to a different request. */
2736 warning (_("ERROR RMT Thread info mismatch."));
2739 copy_threadref (&info
->threadid
, &ref
);
2741 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2743 /* Packets are terminated with nulls. */
2744 while ((pkt
< limit
) && mask
&& *pkt
)
2746 pkt
= unpack_int (pkt
, &tag
); /* tag */
2747 pkt
= unpack_byte (pkt
, &length
); /* length */
2748 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2750 warning (_("ERROR RMT: threadinfo tag mismatch."));
2754 if (tag
== TAG_THREADID
)
2758 warning (_("ERROR RMT: length of threadid is not 16."));
2762 pkt
= unpack_threadid (pkt
, &ref
);
2763 mask
= mask
& ~TAG_THREADID
;
2766 if (tag
== TAG_EXISTS
)
2768 info
->active
= stub_unpack_int (pkt
, length
);
2770 mask
= mask
& ~(TAG_EXISTS
);
2773 warning (_("ERROR RMT: 'exists' length too long."));
2779 if (tag
== TAG_THREADNAME
)
2781 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2782 mask
= mask
& ~TAG_THREADNAME
;
2785 if (tag
== TAG_DISPLAY
)
2787 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2788 mask
= mask
& ~TAG_DISPLAY
;
2791 if (tag
== TAG_MOREDISPLAY
)
2793 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2794 mask
= mask
& ~TAG_MOREDISPLAY
;
2797 warning (_("ERROR RMT: unknown thread info tag."));
2798 break; /* Not a tag we know about. */
2804 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2805 struct gdb_ext_thread_info
*info
)
2807 struct remote_state
*rs
= get_remote_state ();
2810 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2812 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2814 if (rs
->buf
[0] == '\0')
2817 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2822 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2825 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2826 threadref
*nextthread
)
2828 *pkt
++ = 'q'; /* info query packet */
2829 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2830 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2831 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2832 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2837 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2840 parse_threadlist_response (char *pkt
, int result_limit
,
2841 threadref
*original_echo
, threadref
*resultlist
,
2844 struct remote_state
*rs
= get_remote_state ();
2846 int count
, resultcount
, done
;
2849 /* Assume the 'q' and 'M chars have been stripped. */
2850 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2851 /* done parse past here */
2852 pkt
= unpack_byte (pkt
, &count
); /* count field */
2853 pkt
= unpack_nibble (pkt
, &done
);
2854 /* The first threadid is the argument threadid. */
2855 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2856 while ((count
-- > 0) && (pkt
< limit
))
2858 pkt
= unpack_threadid (pkt
, resultlist
++);
2859 if (resultcount
++ >= result_limit
)
2867 /* Fetch the next batch of threads from the remote. Returns -1 if the
2868 qL packet is not supported, 0 on error and 1 on success. */
2871 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2872 int *done
, int *result_count
, threadref
*threadlist
)
2874 struct remote_state
*rs
= get_remote_state ();
2877 /* Trancate result limit to be smaller than the packet size. */
2878 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2879 >= get_remote_packet_size ())
2880 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2882 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2884 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2885 if (*rs
->buf
== '\0')
2887 /* Packet not supported. */
2892 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2893 &rs
->echo_nextthread
, threadlist
, done
);
2895 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2897 /* FIXME: This is a good reason to drop the packet. */
2898 /* Possably, there is a duplicate response. */
2900 retransmit immediatly - race conditions
2901 retransmit after timeout - yes
2903 wait for packet, then exit
2905 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2906 return 0; /* I choose simply exiting. */
2908 if (*result_count
<= 0)
2912 warning (_("RMT ERROR : failed to get remote thread list."));
2915 return result
; /* break; */
2917 if (*result_count
> result_limit
)
2920 warning (_("RMT ERROR: threadlist response longer than requested."));
2926 /* Fetch the list of remote threads, with the qL packet, and call
2927 STEPFUNCTION for each thread found. Stops iterating and returns 1
2928 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2929 STEPFUNCTION returns false. If the packet is not supported,
2933 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2936 struct remote_state
*rs
= get_remote_state ();
2937 int done
, i
, result_count
;
2945 if (loopcount
++ > looplimit
)
2948 warning (_("Remote fetch threadlist -infinite loop-."));
2951 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2952 MAXTHREADLISTRESULTS
,
2953 &done
, &result_count
,
2954 rs
->resultthreadlist
);
2957 /* Clear for later iterations. */
2959 /* Setup to resume next batch of thread references, set nextthread. */
2960 if (result_count
>= 1)
2961 copy_threadref (&rs
->nextthread
,
2962 &rs
->resultthreadlist
[result_count
- 1]);
2964 while (result_count
--)
2966 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2976 /* A thread found on the remote target. */
2978 typedef struct thread_item
2980 /* The thread's PTID. */
2983 /* The thread's extra info. May be NULL. */
2986 /* The thread's name. May be NULL. */
2989 /* The core the thread was running on. -1 if not known. */
2992 DEF_VEC_O(thread_item_t
);
2994 /* Context passed around to the various methods listing remote
2995 threads. As new threads are found, they're added to the ITEMS
2998 struct threads_listing_context
3000 /* The threads found on the remote target. */
3001 VEC (thread_item_t
) *items
;
3004 /* Discard the contents of the constructed thread listing context. */
3007 clear_threads_listing_context (void *p
)
3009 struct threads_listing_context
*context
3010 = (struct threads_listing_context
*) p
;
3012 struct thread_item
*item
;
3014 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3016 xfree (item
->extra
);
3020 VEC_free (thread_item_t
, context
->items
);
3023 /* Remove the thread specified as the related_pid field of WS
3024 from the CONTEXT list. */
3027 threads_listing_context_remove (struct target_waitstatus
*ws
,
3028 struct threads_listing_context
*context
)
3030 struct thread_item
*item
;
3032 ptid_t child_ptid
= ws
->value
.related_pid
;
3034 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3036 if (ptid_equal (item
->ptid
, child_ptid
))
3038 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
3045 remote_newthread_step (threadref
*ref
, void *data
)
3047 struct threads_listing_context
*context
3048 = (struct threads_listing_context
*) data
;
3049 struct thread_item item
;
3050 int pid
= ptid_get_pid (inferior_ptid
);
3052 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3057 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3059 return 1; /* continue iterator */
3062 #define CRAZY_MAX_THREADS 1000
3065 remote_current_thread (ptid_t oldpid
)
3067 struct remote_state
*rs
= get_remote_state ();
3070 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3071 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3076 result
= read_ptid (&rs
->buf
[2], &obuf
);
3077 if (*obuf
!= '\0' && remote_debug
)
3078 fprintf_unfiltered (gdb_stdlog
,
3079 "warning: garbage in qC reply\n");
3087 /* List remote threads using the deprecated qL packet. */
3090 remote_get_threads_with_ql (struct target_ops
*ops
,
3091 struct threads_listing_context
*context
)
3093 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3094 CRAZY_MAX_THREADS
) >= 0)
3100 #if defined(HAVE_LIBEXPAT)
3103 start_thread (struct gdb_xml_parser
*parser
,
3104 const struct gdb_xml_element
*element
,
3105 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3107 struct threads_listing_context
*data
3108 = (struct threads_listing_context
*) user_data
;
3110 struct thread_item item
;
3112 struct gdb_xml_value
*attr
;
3114 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3115 item
.ptid
= read_ptid (id
, NULL
);
3117 attr
= xml_find_attribute (attributes
, "core");
3119 item
.core
= *(ULONGEST
*) attr
->value
;
3123 attr
= xml_find_attribute (attributes
, "name");
3124 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3128 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3132 end_thread (struct gdb_xml_parser
*parser
,
3133 const struct gdb_xml_element
*element
,
3134 void *user_data
, const char *body_text
)
3136 struct threads_listing_context
*data
3137 = (struct threads_listing_context
*) user_data
;
3139 if (body_text
&& *body_text
)
3140 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3143 const struct gdb_xml_attribute thread_attributes
[] = {
3144 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3145 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3146 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3147 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3150 const struct gdb_xml_element thread_children
[] = {
3151 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3154 const struct gdb_xml_element threads_children
[] = {
3155 { "thread", thread_attributes
, thread_children
,
3156 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3157 start_thread
, end_thread
},
3158 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3161 const struct gdb_xml_element threads_elements
[] = {
3162 { "threads", NULL
, threads_children
,
3163 GDB_XML_EF_NONE
, NULL
, NULL
},
3164 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3169 /* List remote threads using qXfer:threads:read. */
3172 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3173 struct threads_listing_context
*context
)
3175 #if defined(HAVE_LIBEXPAT)
3176 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3178 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3179 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3181 if (xml
!= NULL
&& *xml
!= '\0')
3183 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3184 threads_elements
, xml
, context
);
3187 do_cleanups (back_to
);
3195 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3198 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3199 struct threads_listing_context
*context
)
3201 struct remote_state
*rs
= get_remote_state ();
3203 if (rs
->use_threadinfo_query
)
3207 putpkt ("qfThreadInfo");
3208 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3210 if (bufp
[0] != '\0') /* q packet recognized */
3212 while (*bufp
++ == 'm') /* reply contains one or more TID */
3216 struct thread_item item
;
3218 item
.ptid
= read_ptid (bufp
, &bufp
);
3223 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3225 while (*bufp
++ == ','); /* comma-separated list */
3226 putpkt ("qsThreadInfo");
3227 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3234 /* Packet not recognized. */
3235 rs
->use_threadinfo_query
= 0;
3242 /* Implement the to_update_thread_list function for the remote
3246 remote_update_thread_list (struct target_ops
*ops
)
3248 struct threads_listing_context context
;
3249 struct cleanup
*old_chain
;
3252 context
.items
= NULL
;
3253 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3255 /* We have a few different mechanisms to fetch the thread list. Try
3256 them all, starting with the most preferred one first, falling
3257 back to older methods. */
3258 if (remote_get_threads_with_qxfer (ops
, &context
)
3259 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3260 || remote_get_threads_with_ql (ops
, &context
))
3263 struct thread_item
*item
;
3264 struct thread_info
*tp
, *tmp
;
3268 if (VEC_empty (thread_item_t
, context
.items
)
3269 && remote_thread_always_alive (ops
, inferior_ptid
))
3271 /* Some targets don't really support threads, but still
3272 reply an (empty) thread list in response to the thread
3273 listing packets, instead of replying "packet not
3274 supported". Exit early so we don't delete the main
3276 do_cleanups (old_chain
);
3280 /* CONTEXT now holds the current thread list on the remote
3281 target end. Delete GDB-side threads no longer found on the
3283 ALL_THREADS_SAFE (tp
, tmp
)
3286 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3289 if (ptid_equal (item
->ptid
, tp
->ptid
))
3293 if (i
== VEC_length (thread_item_t
, context
.items
))
3296 delete_thread (tp
->ptid
);
3300 /* Remove any unreported fork child threads from CONTEXT so
3301 that we don't interfere with follow fork, which is where
3302 creation of such threads is handled. */
3303 remove_new_fork_children (&context
);
3305 /* And now add threads we don't know about yet to our list. */
3307 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3310 if (!ptid_equal (item
->ptid
, null_ptid
))
3312 struct private_thread_info
*info
;
3313 /* In non-stop mode, we assume new found threads are
3314 executing until proven otherwise with a stop reply.
3315 In all-stop, we can only get here if all threads are
3317 int executing
= target_is_non_stop_p () ? 1 : 0;
3319 remote_notice_new_inferior (item
->ptid
, executing
);
3321 info
= get_private_info_ptid (item
->ptid
);
3322 info
->core
= item
->core
;
3323 info
->extra
= item
->extra
;
3325 info
->name
= item
->name
;
3333 /* If no thread listing method is supported, then query whether
3334 each known thread is alive, one by one, with the T packet.
3335 If the target doesn't support threads at all, then this is a
3336 no-op. See remote_thread_alive. */
3340 do_cleanups (old_chain
);
3344 * Collect a descriptive string about the given thread.
3345 * The target may say anything it wants to about the thread
3346 * (typically info about its blocked / runnable state, name, etc.).
3347 * This string will appear in the info threads display.
3349 * Optional: targets are not required to implement this function.
3353 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3355 struct remote_state
*rs
= get_remote_state ();
3359 struct gdb_ext_thread_info threadinfo
;
3360 static char display_buf
[100]; /* arbitrary... */
3361 int n
= 0; /* position in display_buf */
3363 if (rs
->remote_desc
== 0) /* paranoia */
3364 internal_error (__FILE__
, __LINE__
,
3365 _("remote_threads_extra_info"));
3367 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3368 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3369 /* This is the main thread which was added by GDB. The remote
3370 server doesn't know about it. */
3373 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3375 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3377 if (info
&& info
->priv
)
3378 return info
->priv
->extra
;
3383 if (rs
->use_threadextra_query
)
3386 char *endb
= rs
->buf
+ get_remote_packet_size ();
3388 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3390 write_ptid (b
, endb
, tp
->ptid
);
3393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3394 if (rs
->buf
[0] != 0)
3396 n
= std::min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3397 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3398 display_buf
[result
] = '\0';
3403 /* If the above query fails, fall back to the old method. */
3404 rs
->use_threadextra_query
= 0;
3405 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3406 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3407 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3408 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3409 if (threadinfo
.active
)
3411 if (*threadinfo
.shortname
)
3412 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3413 " Name: %s,", threadinfo
.shortname
);
3414 if (*threadinfo
.display
)
3415 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3416 " State: %s,", threadinfo
.display
);
3417 if (*threadinfo
.more_display
)
3418 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3419 " Priority: %s", threadinfo
.more_display
);
3423 /* For purely cosmetic reasons, clear up trailing commas. */
3424 if (',' == display_buf
[n
-1])
3425 display_buf
[n
-1] = ' ';
3434 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3435 struct static_tracepoint_marker
*marker
)
3437 struct remote_state
*rs
= get_remote_state ();
3440 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3442 p
+= hexnumstr (p
, addr
);
3444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3448 error (_("Remote failure reply: %s"), p
);
3452 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3459 static VEC(static_tracepoint_marker_p
) *
3460 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3463 struct remote_state
*rs
= get_remote_state ();
3464 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3465 struct static_tracepoint_marker
*marker
= NULL
;
3466 struct cleanup
*old_chain
;
3469 /* Ask for a first packet of static tracepoint marker
3472 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3475 error (_("Remote failure reply: %s"), p
);
3477 old_chain
= make_cleanup (free_current_marker
, &marker
);
3482 marker
= XCNEW (struct static_tracepoint_marker
);
3486 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3488 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3490 VEC_safe_push (static_tracepoint_marker_p
,
3496 release_static_tracepoint_marker (marker
);
3497 memset (marker
, 0, sizeof (*marker
));
3500 while (*p
++ == ','); /* comma-separated list */
3501 /* Ask for another packet of static tracepoint definition. */
3503 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3507 do_cleanups (old_chain
);
3512 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3515 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3517 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3521 /* Restart the remote side; this is an extended protocol operation. */
3524 extended_remote_restart (void)
3526 struct remote_state
*rs
= get_remote_state ();
3528 /* Send the restart command; for reasons I don't understand the
3529 remote side really expects a number after the "R". */
3530 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3533 remote_fileio_reset ();
3536 /* Clean up connection to a remote debugger. */
3539 remote_close (struct target_ops
*self
)
3541 struct remote_state
*rs
= get_remote_state ();
3543 if (rs
->remote_desc
== NULL
)
3544 return; /* already closed */
3546 /* Make sure we leave stdin registered in the event loop. */
3547 remote_terminal_ours (self
);
3549 serial_close (rs
->remote_desc
);
3550 rs
->remote_desc
= NULL
;
3552 /* We don't have a connection to the remote stub anymore. Get rid
3553 of all the inferiors and their threads we were controlling.
3554 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3555 will be unable to find the thread corresponding to (pid, 0, 0). */
3556 inferior_ptid
= null_ptid
;
3557 discard_all_inferiors ();
3559 /* We are closing the remote target, so we should discard
3560 everything of this target. */
3561 discard_pending_stop_replies_in_queue (rs
);
3563 if (remote_async_inferior_event_token
)
3564 delete_async_event_handler (&remote_async_inferior_event_token
);
3566 remote_notif_state_xfree (rs
->notif_state
);
3568 trace_reset_local_state ();
3571 /* Query the remote side for the text, data and bss offsets. */
3576 struct remote_state
*rs
= get_remote_state ();
3579 int lose
, num_segments
= 0, do_sections
, do_segments
;
3580 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3581 struct section_offsets
*offs
;
3582 struct symfile_segment_data
*data
;
3584 if (symfile_objfile
== NULL
)
3587 putpkt ("qOffsets");
3588 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3591 if (buf
[0] == '\000')
3592 return; /* Return silently. Stub doesn't support
3596 warning (_("Remote failure reply: %s"), buf
);
3600 /* Pick up each field in turn. This used to be done with scanf, but
3601 scanf will make trouble if CORE_ADDR size doesn't match
3602 conversion directives correctly. The following code will work
3603 with any size of CORE_ADDR. */
3604 text_addr
= data_addr
= bss_addr
= 0;
3608 if (startswith (ptr
, "Text="))
3611 /* Don't use strtol, could lose on big values. */
3612 while (*ptr
&& *ptr
!= ';')
3613 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3615 if (startswith (ptr
, ";Data="))
3618 while (*ptr
&& *ptr
!= ';')
3619 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3624 if (!lose
&& startswith (ptr
, ";Bss="))
3627 while (*ptr
&& *ptr
!= ';')
3628 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3630 if (bss_addr
!= data_addr
)
3631 warning (_("Target reported unsupported offsets: %s"), buf
);
3636 else if (startswith (ptr
, "TextSeg="))
3639 /* Don't use strtol, could lose on big values. */
3640 while (*ptr
&& *ptr
!= ';')
3641 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3644 if (startswith (ptr
, ";DataSeg="))
3647 while (*ptr
&& *ptr
!= ';')
3648 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3656 error (_("Malformed response to offset query, %s"), buf
);
3657 else if (*ptr
!= '\0')
3658 warning (_("Target reported unsupported offsets: %s"), buf
);
3660 offs
= ((struct section_offsets
*)
3661 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3662 memcpy (offs
, symfile_objfile
->section_offsets
,
3663 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3665 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3666 do_segments
= (data
!= NULL
);
3667 do_sections
= num_segments
== 0;
3669 if (num_segments
> 0)
3671 segments
[0] = text_addr
;
3672 segments
[1] = data_addr
;
3674 /* If we have two segments, we can still try to relocate everything
3675 by assuming that the .text and .data offsets apply to the whole
3676 text and data segments. Convert the offsets given in the packet
3677 to base addresses for symfile_map_offsets_to_segments. */
3678 else if (data
&& data
->num_segments
== 2)
3680 segments
[0] = data
->segment_bases
[0] + text_addr
;
3681 segments
[1] = data
->segment_bases
[1] + data_addr
;
3684 /* If the object file has only one segment, assume that it is text
3685 rather than data; main programs with no writable data are rare,
3686 but programs with no code are useless. Of course the code might
3687 have ended up in the data segment... to detect that we would need
3688 the permissions here. */
3689 else if (data
&& data
->num_segments
== 1)
3691 segments
[0] = data
->segment_bases
[0] + text_addr
;
3694 /* There's no way to relocate by segment. */
3700 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3701 offs
, num_segments
, segments
);
3703 if (ret
== 0 && !do_sections
)
3704 error (_("Can not handle qOffsets TextSeg "
3705 "response with this symbol file"));
3712 free_symfile_segment_data (data
);
3716 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3718 /* This is a temporary kludge to force data and bss to use the
3719 same offsets because that's what nlmconv does now. The real
3720 solution requires changes to the stub and remote.c that I
3721 don't have time to do right now. */
3723 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3724 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3727 objfile_relocate (symfile_objfile
, offs
);
3730 /* Send interrupt_sequence to remote target. */
3732 send_interrupt_sequence (void)
3734 struct remote_state
*rs
= get_remote_state ();
3736 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3737 remote_serial_write ("\x03", 1);
3738 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3739 serial_send_break (rs
->remote_desc
);
3740 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3742 serial_send_break (rs
->remote_desc
);
3743 remote_serial_write ("g", 1);
3746 internal_error (__FILE__
, __LINE__
,
3747 _("Invalid value for interrupt_sequence_mode: %s."),
3748 interrupt_sequence_mode
);
3752 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3753 and extract the PTID. Returns NULL_PTID if not found. */
3756 stop_reply_extract_thread (char *stop_reply
)
3758 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3762 /* Txx r:val ; r:val (...) */
3765 /* Look for "register" named "thread". */
3770 p1
= strchr (p
, ':');
3774 if (strncmp (p
, "thread", p1
- p
) == 0)
3775 return read_ptid (++p1
, &p
);
3777 p1
= strchr (p
, ';');
3789 /* Determine the remote side's current thread. If we have a stop
3790 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3791 "thread" register we can extract the current thread from. If not,
3792 ask the remote which is the current thread with qC. The former
3793 method avoids a roundtrip. */
3796 get_current_thread (char *wait_status
)
3798 ptid_t ptid
= null_ptid
;
3800 /* Note we don't use remote_parse_stop_reply as that makes use of
3801 the target architecture, which we haven't yet fully determined at
3803 if (wait_status
!= NULL
)
3804 ptid
= stop_reply_extract_thread (wait_status
);
3805 if (ptid_equal (ptid
, null_ptid
))
3806 ptid
= remote_current_thread (inferior_ptid
);
3811 /* Query the remote target for which is the current thread/process,
3812 add it to our tables, and update INFERIOR_PTID. The caller is
3813 responsible for setting the state such that the remote end is ready
3814 to return the current thread.
3816 This function is called after handling the '?' or 'vRun' packets,
3817 whose response is a stop reply from which we can also try
3818 extracting the thread. If the target doesn't support the explicit
3819 qC query, we infer the current thread from that stop reply, passed
3820 in in WAIT_STATUS, which may be NULL. */
3823 add_current_inferior_and_thread (char *wait_status
)
3825 struct remote_state
*rs
= get_remote_state ();
3829 inferior_ptid
= null_ptid
;
3831 /* Now, if we have thread information, update inferior_ptid. */
3832 ptid
= get_current_thread (wait_status
);
3834 if (!ptid_equal (ptid
, null_ptid
))
3836 if (!remote_multi_process_p (rs
))
3839 inferior_ptid
= ptid
;
3843 /* Without this, some commands which require an active target
3844 (such as kill) won't work. This variable serves (at least)
3845 double duty as both the pid of the target process (if it has
3846 such), and as a flag indicating that a target is active. */
3847 inferior_ptid
= magic_null_ptid
;
3851 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3853 /* Add the main thread. */
3854 add_thread_silent (inferior_ptid
);
3857 /* Print info about a thread that was found already stopped on
3861 print_one_stopped_thread (struct thread_info
*thread
)
3863 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3865 switch_to_thread (thread
->ptid
);
3866 stop_pc
= get_frame_pc (get_current_frame ());
3867 set_current_sal_from_frame (get_current_frame ());
3869 thread
->suspend
.waitstatus_pending_p
= 0;
3871 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3873 enum gdb_signal sig
= ws
->value
.sig
;
3875 if (signal_print_state (sig
))
3876 observer_notify_signal_received (sig
);
3878 observer_notify_normal_stop (NULL
, 1);
3881 /* Process all initial stop replies the remote side sent in response
3882 to the ? packet. These indicate threads that were already stopped
3883 on initial connection. We mark these threads as stopped and print
3884 their current frame before giving the user the prompt. */
3887 process_initial_stop_replies (int from_tty
)
3889 int pending_stop_replies
= stop_reply_queue_length ();
3890 struct inferior
*inf
;
3891 struct thread_info
*thread
;
3892 struct thread_info
*selected
= NULL
;
3893 struct thread_info
*lowest_stopped
= NULL
;
3894 struct thread_info
*first
= NULL
;
3896 /* Consume the initial pending events. */
3897 while (pending_stop_replies
-- > 0)
3899 ptid_t waiton_ptid
= minus_one_ptid
;
3901 struct target_waitstatus ws
;
3902 int ignore_event
= 0;
3903 struct thread_info
*thread
;
3905 memset (&ws
, 0, sizeof (ws
));
3906 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3908 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3912 case TARGET_WAITKIND_IGNORE
:
3913 case TARGET_WAITKIND_NO_RESUMED
:
3914 case TARGET_WAITKIND_SIGNALLED
:
3915 case TARGET_WAITKIND_EXITED
:
3916 /* We shouldn't see these, but if we do, just ignore. */
3918 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3922 case TARGET_WAITKIND_EXECD
:
3923 xfree (ws
.value
.execd_pathname
);
3932 thread
= find_thread_ptid (event_ptid
);
3934 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3936 enum gdb_signal sig
= ws
.value
.sig
;
3938 /* Stubs traditionally report SIGTRAP as initial signal,
3939 instead of signal 0. Suppress it. */
3940 if (sig
== GDB_SIGNAL_TRAP
)
3942 thread
->suspend
.stop_signal
= sig
;
3946 thread
->suspend
.waitstatus
= ws
;
3948 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3949 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3950 thread
->suspend
.waitstatus_pending_p
= 1;
3952 set_executing (event_ptid
, 0);
3953 set_running (event_ptid
, 0);
3954 thread
->priv
->vcont_resumed
= 0;
3957 /* "Notice" the new inferiors before anything related to
3958 registers/memory. */
3964 inf
->needs_setup
= 1;
3968 thread
= any_live_thread_of_process (inf
->pid
);
3969 notice_new_inferior (thread
->ptid
,
3970 thread
->state
== THREAD_RUNNING
,
3975 /* If all-stop on top of non-stop, pause all threads. Note this
3976 records the threads' stop pc, so must be done after "noticing"
3980 stop_all_threads ();
3982 /* If all threads of an inferior were already stopped, we
3983 haven't setup the inferior yet. */
3989 if (inf
->needs_setup
)
3991 thread
= any_live_thread_of_process (inf
->pid
);
3992 switch_to_thread_no_regs (thread
);
3998 /* Now go over all threads that are stopped, and print their current
3999 frame. If all-stop, then if there's a signalled thread, pick
4001 ALL_NON_EXITED_THREADS (thread
)
4007 set_running (thread
->ptid
, 0);
4008 else if (thread
->state
!= THREAD_STOPPED
)
4011 if (selected
== NULL
4012 && thread
->suspend
.waitstatus_pending_p
)
4015 if (lowest_stopped
== NULL
4016 || thread
->inf
->num
< lowest_stopped
->inf
->num
4017 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
4018 lowest_stopped
= thread
;
4021 print_one_stopped_thread (thread
);
4024 /* In all-stop, we only print the status of one thread, and leave
4025 others with their status pending. */
4030 thread
= lowest_stopped
;
4034 print_one_stopped_thread (thread
);
4037 /* For "info program". */
4038 thread
= inferior_thread ();
4039 if (thread
->state
== THREAD_STOPPED
)
4040 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4043 /* Start the remote connection and sync state. */
4046 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4048 struct remote_state
*rs
= get_remote_state ();
4049 struct packet_config
*noack_config
;
4050 char *wait_status
= NULL
;
4052 /* Signal other parts that we're going through the initial setup,
4053 and so things may not be stable yet. E.g., we don't try to
4054 install tracepoints until we've relocated symbols. Also, a
4055 Ctrl-C before we're connected and synced up can't interrupt the
4056 target. Instead, it offers to drop the (potentially wedged)
4058 rs
->starting_up
= 1;
4062 if (interrupt_on_connect
)
4063 send_interrupt_sequence ();
4065 /* Ack any packet which the remote side has already sent. */
4066 remote_serial_write ("+", 1);
4068 /* The first packet we send to the target is the optional "supported
4069 packets" request. If the target can answer this, it will tell us
4070 which later probes to skip. */
4071 remote_query_supported ();
4073 /* If the stub wants to get a QAllow, compose one and send it. */
4074 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4075 remote_set_permissions (target
);
4077 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4078 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4079 as a reply to known packet. For packet "vFile:setfs:" it is an
4080 invalid reply and GDB would return error in
4081 remote_hostio_set_filesystem, making remote files access impossible.
4082 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4083 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4085 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4087 putpkt (v_mustreplyempty
);
4088 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4089 if (strcmp (rs
->buf
, "OK") == 0)
4090 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4091 else if (strcmp (rs
->buf
, "") != 0)
4092 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4096 /* Next, we possibly activate noack mode.
4098 If the QStartNoAckMode packet configuration is set to AUTO,
4099 enable noack mode if the stub reported a wish for it with
4102 If set to TRUE, then enable noack mode even if the stub didn't
4103 report it in qSupported. If the stub doesn't reply OK, the
4104 session ends with an error.
4106 If FALSE, then don't activate noack mode, regardless of what the
4107 stub claimed should be the default with qSupported. */
4109 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4110 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4112 putpkt ("QStartNoAckMode");
4113 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4114 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4120 /* Tell the remote that we are using the extended protocol. */
4122 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4125 /* Let the target know which signals it is allowed to pass down to
4127 update_signals_program_target ();
4129 /* Next, if the target can specify a description, read it. We do
4130 this before anything involving memory or registers. */
4131 target_find_description ();
4133 /* Next, now that we know something about the target, update the
4134 address spaces in the program spaces. */
4135 update_address_spaces ();
4137 /* On OSs where the list of libraries is global to all
4138 processes, we fetch them early. */
4139 if (gdbarch_has_global_solist (target_gdbarch ()))
4140 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4142 if (target_is_non_stop_p ())
4144 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4145 error (_("Non-stop mode requested, but remote "
4146 "does not support non-stop"));
4148 putpkt ("QNonStop:1");
4149 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4151 if (strcmp (rs
->buf
, "OK") != 0)
4152 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4154 /* Find about threads and processes the stub is already
4155 controlling. We default to adding them in the running state.
4156 The '?' query below will then tell us about which threads are
4158 remote_update_thread_list (target
);
4160 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4162 /* Don't assume that the stub can operate in all-stop mode.
4163 Request it explicitly. */
4164 putpkt ("QNonStop:0");
4165 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4167 if (strcmp (rs
->buf
, "OK") != 0)
4168 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4171 /* Upload TSVs regardless of whether the target is running or not. The
4172 remote stub, such as GDBserver, may have some predefined or builtin
4173 TSVs, even if the target is not running. */
4174 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4176 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4178 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4179 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4182 /* Check whether the target is running now. */
4184 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4186 if (!target_is_non_stop_p ())
4188 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4191 error (_("The target is not running (try extended-remote?)"));
4193 /* We're connected, but not running. Drop out before we
4194 call start_remote. */
4195 rs
->starting_up
= 0;
4200 /* Save the reply for later. */
4201 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4202 strcpy (wait_status
, rs
->buf
);
4205 /* Fetch thread list. */
4206 target_update_thread_list ();
4208 /* Let the stub know that we want it to return the thread. */
4209 set_continue_thread (minus_one_ptid
);
4211 if (thread_count () == 0)
4213 /* Target has no concept of threads at all. GDB treats
4214 non-threaded target as single-threaded; add a main
4216 add_current_inferior_and_thread (wait_status
);
4220 /* We have thread information; select the thread the target
4221 says should be current. If we're reconnecting to a
4222 multi-threaded program, this will ideally be the thread
4223 that last reported an event before GDB disconnected. */
4224 inferior_ptid
= get_current_thread (wait_status
);
4225 if (ptid_equal (inferior_ptid
, null_ptid
))
4227 /* Odd... The target was able to list threads, but not
4228 tell us which thread was current (no "thread"
4229 register in T stop reply?). Just pick the first
4230 thread in the thread list then. */
4233 fprintf_unfiltered (gdb_stdlog
,
4234 "warning: couldn't determine remote "
4235 "current thread; picking first in list.\n");
4237 inferior_ptid
= thread_list
->ptid
;
4241 /* init_wait_for_inferior should be called before get_offsets in order
4242 to manage `inserted' flag in bp loc in a correct state.
4243 breakpoint_init_inferior, called from init_wait_for_inferior, set
4244 `inserted' flag to 0, while before breakpoint_re_set, called from
4245 start_remote, set `inserted' flag to 1. In the initialization of
4246 inferior, breakpoint_init_inferior should be called first, and then
4247 breakpoint_re_set can be called. If this order is broken, state of
4248 `inserted' flag is wrong, and cause some problems on breakpoint
4250 init_wait_for_inferior ();
4252 get_offsets (); /* Get text, data & bss offsets. */
4254 /* If we could not find a description using qXfer, and we know
4255 how to do it some other way, try again. This is not
4256 supported for non-stop; it could be, but it is tricky if
4257 there are no stopped threads when we connect. */
4258 if (remote_read_description_p (target
)
4259 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4261 target_clear_description ();
4262 target_find_description ();
4265 /* Use the previously fetched status. */
4266 gdb_assert (wait_status
!= NULL
);
4267 strcpy (rs
->buf
, wait_status
);
4268 rs
->cached_wait_status
= 1;
4270 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4274 /* Clear WFI global state. Do this before finding about new
4275 threads and inferiors, and setting the current inferior.
4276 Otherwise we would clear the proceed status of the current
4277 inferior when we want its stop_soon state to be preserved
4278 (see notice_new_inferior). */
4279 init_wait_for_inferior ();
4281 /* In non-stop, we will either get an "OK", meaning that there
4282 are no stopped threads at this time; or, a regular stop
4283 reply. In the latter case, there may be more than one thread
4284 stopped --- we pull them all out using the vStopped
4286 if (strcmp (rs
->buf
, "OK") != 0)
4288 struct notif_client
*notif
= ¬if_client_stop
;
4290 /* remote_notif_get_pending_replies acks this one, and gets
4292 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4293 = remote_notif_parse (notif
, rs
->buf
);
4294 remote_notif_get_pending_events (notif
);
4297 if (thread_count () == 0)
4300 error (_("The target is not running (try extended-remote?)"));
4302 /* We're connected, but not running. Drop out before we
4303 call start_remote. */
4304 rs
->starting_up
= 0;
4308 /* In non-stop mode, any cached wait status will be stored in
4309 the stop reply queue. */
4310 gdb_assert (wait_status
== NULL
);
4312 /* Report all signals during attach/startup. */
4313 remote_pass_signals (target
, 0, NULL
);
4315 /* If there are already stopped threads, mark them stopped and
4316 report their stops before giving the prompt to the user. */
4317 process_initial_stop_replies (from_tty
);
4319 if (target_can_async_p ())
4323 /* If we connected to a live target, do some additional setup. */
4324 if (target_has_execution
)
4326 if (symfile_objfile
) /* No use without a symbol-file. */
4327 remote_check_symbols ();
4330 /* Possibly the target has been engaged in a trace run started
4331 previously; find out where things are at. */
4332 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4334 struct uploaded_tp
*uploaded_tps
= NULL
;
4336 if (current_trace_status ()->running
)
4337 printf_filtered (_("Trace is already running on the target.\n"));
4339 remote_upload_tracepoints (target
, &uploaded_tps
);
4341 merge_uploaded_tracepoints (&uploaded_tps
);
4344 /* Possibly the target has been engaged in a btrace record started
4345 previously; find out where things are at. */
4346 remote_btrace_maybe_reopen ();
4348 /* The thread and inferior lists are now synchronized with the
4349 target, our symbols have been relocated, and we're merged the
4350 target's tracepoints with ours. We're done with basic start
4352 rs
->starting_up
= 0;
4354 /* Maybe breakpoints are global and need to be inserted now. */
4355 if (breakpoints_should_be_inserted_now ())
4356 insert_breakpoints ();
4359 /* Open a connection to a remote debugger.
4360 NAME is the filename used for communication. */
4363 remote_open (const char *name
, int from_tty
)
4365 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4368 /* Open a connection to a remote debugger using the extended
4369 remote gdb protocol. NAME is the filename used for communication. */
4372 extended_remote_open (const char *name
, int from_tty
)
4374 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4377 /* Reset all packets back to "unknown support". Called when opening a
4378 new connection to a remote target. */
4381 reset_all_packet_configs_support (void)
4385 for (i
= 0; i
< PACKET_MAX
; i
++)
4386 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4389 /* Initialize all packet configs. */
4392 init_all_packet_configs (void)
4396 for (i
= 0; i
< PACKET_MAX
; i
++)
4398 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4399 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4403 /* Symbol look-up. */
4406 remote_check_symbols (void)
4408 struct remote_state
*rs
= get_remote_state ();
4409 char *msg
, *reply
, *tmp
;
4412 struct cleanup
*old_chain
;
4414 /* The remote side has no concept of inferiors that aren't running
4415 yet, it only knows about running processes. If we're connected
4416 but our current inferior is not running, we should not invite the
4417 remote target to request symbol lookups related to its
4418 (unrelated) current process. */
4419 if (!target_has_execution
)
4422 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4425 /* Make sure the remote is pointing at the right process. Note
4426 there's no way to select "no process". */
4427 set_general_process ();
4429 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4430 because we need both at the same time. */
4431 msg
= (char *) xmalloc (get_remote_packet_size ());
4432 old_chain
= make_cleanup (xfree
, msg
);
4433 reply
= (char *) xmalloc (get_remote_packet_size ());
4434 make_cleanup (free_current_contents
, &reply
);
4435 reply_size
= get_remote_packet_size ();
4437 /* Invite target to request symbol lookups. */
4439 putpkt ("qSymbol::");
4440 getpkt (&reply
, &reply_size
, 0);
4441 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4443 while (startswith (reply
, "qSymbol:"))
4445 struct bound_minimal_symbol sym
;
4448 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4450 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4451 if (sym
.minsym
== NULL
)
4452 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4455 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4456 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4458 /* If this is a function address, return the start of code
4459 instead of any data function descriptor. */
4460 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4464 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4465 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4469 getpkt (&reply
, &reply_size
, 0);
4472 do_cleanups (old_chain
);
4475 static struct serial
*
4476 remote_serial_open (const char *name
)
4478 static int udp_warning
= 0;
4480 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4481 of in ser-tcp.c, because it is the remote protocol assuming that the
4482 serial connection is reliable and not the serial connection promising
4484 if (!udp_warning
&& startswith (name
, "udp:"))
4486 warning (_("The remote protocol may be unreliable over UDP.\n"
4487 "Some events may be lost, rendering further debugging "
4492 return serial_open (name
);
4495 /* Inform the target of our permission settings. The permission flags
4496 work without this, but if the target knows the settings, it can do
4497 a couple things. First, it can add its own check, to catch cases
4498 that somehow manage to get by the permissions checks in target
4499 methods. Second, if the target is wired to disallow particular
4500 settings (for instance, a system in the field that is not set up to
4501 be able to stop at a breakpoint), it can object to any unavailable
4505 remote_set_permissions (struct target_ops
*self
)
4507 struct remote_state
*rs
= get_remote_state ();
4509 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4510 "WriteReg:%x;WriteMem:%x;"
4511 "InsertBreak:%x;InsertTrace:%x;"
4512 "InsertFastTrace:%x;Stop:%x",
4513 may_write_registers
, may_write_memory
,
4514 may_insert_breakpoints
, may_insert_tracepoints
,
4515 may_insert_fast_tracepoints
, may_stop
);
4517 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4519 /* If the target didn't like the packet, warn the user. Do not try
4520 to undo the user's settings, that would just be maddening. */
4521 if (strcmp (rs
->buf
, "OK") != 0)
4522 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4525 /* This type describes each known response to the qSupported
4527 struct protocol_feature
4529 /* The name of this protocol feature. */
4532 /* The default for this protocol feature. */
4533 enum packet_support default_support
;
4535 /* The function to call when this feature is reported, or after
4536 qSupported processing if the feature is not supported.
4537 The first argument points to this structure. The second
4538 argument indicates whether the packet requested support be
4539 enabled, disabled, or probed (or the default, if this function
4540 is being called at the end of processing and this feature was
4541 not reported). The third argument may be NULL; if not NULL, it
4542 is a NUL-terminated string taken from the packet following
4543 this feature's name and an equals sign. */
4544 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4547 /* The corresponding packet for this feature. Only used if
4548 FUNC is remote_supported_packet. */
4553 remote_supported_packet (const struct protocol_feature
*feature
,
4554 enum packet_support support
,
4555 const char *argument
)
4559 warning (_("Remote qSupported response supplied an unexpected value for"
4560 " \"%s\"."), feature
->name
);
4564 remote_protocol_packets
[feature
->packet
].support
= support
;
4568 remote_packet_size (const struct protocol_feature
*feature
,
4569 enum packet_support support
, const char *value
)
4571 struct remote_state
*rs
= get_remote_state ();
4576 if (support
!= PACKET_ENABLE
)
4579 if (value
== NULL
|| *value
== '\0')
4581 warning (_("Remote target reported \"%s\" without a size."),
4587 packet_size
= strtol (value
, &value_end
, 16);
4588 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4590 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4591 feature
->name
, value
);
4595 /* Record the new maximum packet size. */
4596 rs
->explicit_packet_size
= packet_size
;
4599 static const struct protocol_feature remote_protocol_features
[] = {
4600 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4601 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4602 PACKET_qXfer_auxv
},
4603 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4604 PACKET_qXfer_exec_file
},
4605 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4606 PACKET_qXfer_features
},
4607 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4608 PACKET_qXfer_libraries
},
4609 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4610 PACKET_qXfer_libraries_svr4
},
4611 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4612 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4613 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4614 PACKET_qXfer_memory_map
},
4615 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4616 PACKET_qXfer_spu_read
},
4617 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4618 PACKET_qXfer_spu_write
},
4619 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4620 PACKET_qXfer_osdata
},
4621 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4622 PACKET_qXfer_threads
},
4623 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4624 PACKET_qXfer_traceframe_info
},
4625 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4626 PACKET_QPassSignals
},
4627 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4628 PACKET_QCatchSyscalls
},
4629 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4630 PACKET_QProgramSignals
},
4631 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4632 PACKET_QStartNoAckMode
},
4633 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4634 PACKET_multiprocess_feature
},
4635 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4636 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4637 PACKET_qXfer_siginfo_read
},
4638 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4639 PACKET_qXfer_siginfo_write
},
4640 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4641 PACKET_ConditionalTracepoints
},
4642 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4643 PACKET_ConditionalBreakpoints
},
4644 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4645 PACKET_BreakpointCommands
},
4646 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4647 PACKET_FastTracepoints
},
4648 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4649 PACKET_StaticTracepoints
},
4650 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4651 PACKET_InstallInTrace
},
4652 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4653 PACKET_DisconnectedTracing_feature
},
4654 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4656 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4658 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4659 PACKET_TracepointSource
},
4660 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4662 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4663 PACKET_EnableDisableTracepoints_feature
},
4664 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4665 PACKET_qXfer_fdpic
},
4666 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4668 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4669 PACKET_QDisableRandomization
},
4670 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4671 { "QTBuffer:size", PACKET_DISABLE
,
4672 remote_supported_packet
, PACKET_QTBuffer_size
},
4673 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4674 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4675 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4676 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4677 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4678 PACKET_qXfer_btrace
},
4679 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4680 PACKET_qXfer_btrace_conf
},
4681 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4682 PACKET_Qbtrace_conf_bts_size
},
4683 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4684 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4685 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4686 PACKET_fork_event_feature
},
4687 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4688 PACKET_vfork_event_feature
},
4689 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4690 PACKET_exec_event_feature
},
4691 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4692 PACKET_Qbtrace_conf_pt_size
},
4693 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4694 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4695 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4698 static char *remote_support_xml
;
4700 /* Register string appended to "xmlRegisters=" in qSupported query. */
4703 register_remote_support_xml (const char *xml
)
4705 #if defined(HAVE_LIBEXPAT)
4706 if (remote_support_xml
== NULL
)
4707 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4710 char *copy
= xstrdup (remote_support_xml
+ 13);
4711 char *p
= strtok (copy
, ",");
4715 if (strcmp (p
, xml
) == 0)
4722 while ((p
= strtok (NULL
, ",")) != NULL
);
4725 remote_support_xml
= reconcat (remote_support_xml
,
4726 remote_support_xml
, ",", xml
,
4733 remote_query_supported_append (char *msg
, const char *append
)
4736 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4738 return xstrdup (append
);
4742 remote_query_supported (void)
4744 struct remote_state
*rs
= get_remote_state ();
4747 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4749 /* The packet support flags are handled differently for this packet
4750 than for most others. We treat an error, a disabled packet, and
4751 an empty response identically: any features which must be reported
4752 to be used will be automatically disabled. An empty buffer
4753 accomplishes this, since that is also the representation for a list
4754 containing no features. */
4757 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4760 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4762 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4763 q
= remote_query_supported_append (q
, "multiprocess+");
4765 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4766 q
= remote_query_supported_append (q
, "swbreak+");
4767 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4768 q
= remote_query_supported_append (q
, "hwbreak+");
4770 q
= remote_query_supported_append (q
, "qRelocInsn+");
4772 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4773 != AUTO_BOOLEAN_FALSE
)
4774 q
= remote_query_supported_append (q
, "fork-events+");
4775 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4776 != AUTO_BOOLEAN_FALSE
)
4777 q
= remote_query_supported_append (q
, "vfork-events+");
4778 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4779 != AUTO_BOOLEAN_FALSE
)
4780 q
= remote_query_supported_append (q
, "exec-events+");
4782 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4783 q
= remote_query_supported_append (q
, "vContSupported+");
4785 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4786 q
= remote_query_supported_append (q
, "QThreadEvents+");
4788 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4789 q
= remote_query_supported_append (q
, "no-resumed+");
4791 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4792 the qSupported:xmlRegisters=i386 handling. */
4793 if (remote_support_xml
!= NULL
)
4794 q
= remote_query_supported_append (q
, remote_support_xml
);
4796 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4799 do_cleanups (old_chain
);
4801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4803 /* If an error occured, warn, but do not return - just reset the
4804 buffer to empty and go on to disable features. */
4805 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4808 warning (_("Remote failure reply: %s"), rs
->buf
);
4813 memset (seen
, 0, sizeof (seen
));
4818 enum packet_support is_supported
;
4819 char *p
, *end
, *name_end
, *value
;
4821 /* First separate out this item from the rest of the packet. If
4822 there's another item after this, we overwrite the separator
4823 (terminated strings are much easier to work with). */
4825 end
= strchr (p
, ';');
4828 end
= p
+ strlen (p
);
4838 warning (_("empty item in \"qSupported\" response"));
4843 name_end
= strchr (p
, '=');
4846 /* This is a name=value entry. */
4847 is_supported
= PACKET_ENABLE
;
4848 value
= name_end
+ 1;
4857 is_supported
= PACKET_ENABLE
;
4861 is_supported
= PACKET_DISABLE
;
4865 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4869 warning (_("unrecognized item \"%s\" "
4870 "in \"qSupported\" response"), p
);
4876 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4877 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4879 const struct protocol_feature
*feature
;
4882 feature
= &remote_protocol_features
[i
];
4883 feature
->func (feature
, is_supported
, value
);
4888 /* If we increased the packet size, make sure to increase the global
4889 buffer size also. We delay this until after parsing the entire
4890 qSupported packet, because this is the same buffer we were
4892 if (rs
->buf_size
< rs
->explicit_packet_size
)
4894 rs
->buf_size
= rs
->explicit_packet_size
;
4895 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4898 /* Handle the defaults for unmentioned features. */
4899 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4902 const struct protocol_feature
*feature
;
4904 feature
= &remote_protocol_features
[i
];
4905 feature
->func (feature
, feature
->default_support
, NULL
);
4909 /* Serial QUIT handler for the remote serial descriptor.
4911 Defers handling a Ctrl-C until we're done with the current
4912 command/response packet sequence, unless:
4914 - We're setting up the connection. Don't send a remote interrupt
4915 request, as we're not fully synced yet. Quit immediately
4918 - The target has been resumed in the foreground
4919 (target_terminal_is_ours is false) with a synchronous resume
4920 packet, and we're blocked waiting for the stop reply, thus a
4921 Ctrl-C should be immediately sent to the target.
4923 - We get a second Ctrl-C while still within the same serial read or
4924 write. In that case the serial is seemingly wedged --- offer to
4927 - We see a second Ctrl-C without target response, after having
4928 previously interrupted the target. In that case the target/stub
4929 is probably wedged --- offer to quit/disconnect.
4933 remote_serial_quit_handler (void)
4935 struct remote_state
*rs
= get_remote_state ();
4937 if (check_quit_flag ())
4939 /* If we're starting up, we're not fully synced yet. Quit
4941 if (rs
->starting_up
)
4943 else if (rs
->got_ctrlc_during_io
)
4945 if (query (_("The target is not responding to GDB commands.\n"
4946 "Stop debugging it? ")))
4947 remote_unpush_and_throw ();
4949 /* If ^C has already been sent once, offer to disconnect. */
4950 else if (!target_terminal_is_ours () && rs
->ctrlc_pending_p
)
4952 /* All-stop protocol, and blocked waiting for stop reply. Send
4953 an interrupt request. */
4954 else if (!target_terminal_is_ours () && rs
->waiting_for_stop_reply
)
4955 target_interrupt (inferior_ptid
);
4957 rs
->got_ctrlc_during_io
= 1;
4961 /* Remove any of the remote.c targets from target stack. Upper targets depend
4962 on it so remove them first. */
4965 remote_unpush_target (void)
4967 pop_all_targets_at_and_above (process_stratum
);
4971 remote_unpush_and_throw (void)
4973 remote_unpush_target ();
4974 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
4978 remote_open_1 (const char *name
, int from_tty
,
4979 struct target_ops
*target
, int extended_p
)
4981 struct remote_state
*rs
= get_remote_state ();
4984 error (_("To open a remote debug connection, you need to specify what\n"
4985 "serial device is attached to the remote system\n"
4986 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4988 /* See FIXME above. */
4989 if (!target_async_permitted
)
4990 wait_forever_enabled_p
= 1;
4992 /* If we're connected to a running target, target_preopen will kill it.
4993 Ask this question first, before target_preopen has a chance to kill
4995 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4998 && !query (_("Already connected to a remote target. Disconnect? ")))
4999 error (_("Still connected."));
5002 /* Here the possibly existing remote target gets unpushed. */
5003 target_preopen (from_tty
);
5005 /* Make sure we send the passed signals list the next time we resume. */
5006 xfree (rs
->last_pass_packet
);
5007 rs
->last_pass_packet
= NULL
;
5009 /* Make sure we send the program signals list the next time we
5011 xfree (rs
->last_program_signals_packet
);
5012 rs
->last_program_signals_packet
= NULL
;
5014 remote_fileio_reset ();
5015 reopen_exec_file ();
5018 rs
->remote_desc
= remote_serial_open (name
);
5019 if (!rs
->remote_desc
)
5020 perror_with_name (name
);
5022 if (baud_rate
!= -1)
5024 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
5026 /* The requested speed could not be set. Error out to
5027 top level after closing remote_desc. Take care to
5028 set remote_desc to NULL to avoid closing remote_desc
5030 serial_close (rs
->remote_desc
);
5031 rs
->remote_desc
= NULL
;
5032 perror_with_name (name
);
5036 serial_setparity (rs
->remote_desc
, serial_parity
);
5037 serial_raw (rs
->remote_desc
);
5039 /* If there is something sitting in the buffer we might take it as a
5040 response to a command, which would be bad. */
5041 serial_flush_input (rs
->remote_desc
);
5045 puts_filtered ("Remote debugging using ");
5046 puts_filtered (name
);
5047 puts_filtered ("\n");
5049 push_target (target
); /* Switch to using remote target now. */
5051 /* Register extra event sources in the event loop. */
5052 remote_async_inferior_event_token
5053 = create_async_event_handler (remote_async_inferior_event_handler
,
5055 rs
->notif_state
= remote_notif_state_allocate ();
5057 /* Reset the target state; these things will be queried either by
5058 remote_query_supported or as they are needed. */
5059 reset_all_packet_configs_support ();
5060 rs
->cached_wait_status
= 0;
5061 rs
->explicit_packet_size
= 0;
5063 rs
->extended
= extended_p
;
5064 rs
->waiting_for_stop_reply
= 0;
5065 rs
->ctrlc_pending_p
= 0;
5066 rs
->got_ctrlc_during_io
= 0;
5068 rs
->general_thread
= not_sent_ptid
;
5069 rs
->continue_thread
= not_sent_ptid
;
5070 rs
->remote_traceframe_number
= -1;
5072 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5074 /* Probe for ability to use "ThreadInfo" query, as required. */
5075 rs
->use_threadinfo_query
= 1;
5076 rs
->use_threadextra_query
= 1;
5078 readahead_cache_invalidate ();
5080 /* Start out by owning the terminal. */
5081 remote_async_terminal_ours_p
= 1;
5083 if (target_async_permitted
)
5085 /* FIXME: cagney/1999-09-23: During the initial connection it is
5086 assumed that the target is already ready and able to respond to
5087 requests. Unfortunately remote_start_remote() eventually calls
5088 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5089 around this. Eventually a mechanism that allows
5090 wait_for_inferior() to expect/get timeouts will be
5092 wait_forever_enabled_p
= 0;
5095 /* First delete any symbols previously loaded from shared libraries. */
5096 no_shared_libraries (NULL
, 0);
5099 init_thread_list ();
5101 /* Start the remote connection. If error() or QUIT, discard this
5102 target (we'd otherwise be in an inconsistent state) and then
5103 propogate the error on up the exception chain. This ensures that
5104 the caller doesn't stumble along blindly assuming that the
5105 function succeeded. The CLI doesn't have this problem but other
5106 UI's, such as MI do.
5108 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5109 this function should return an error indication letting the
5110 caller restore the previous state. Unfortunately the command
5111 ``target remote'' is directly wired to this function making that
5112 impossible. On a positive note, the CLI side of this problem has
5113 been fixed - the function set_cmd_context() makes it possible for
5114 all the ``target ....'' commands to share a common callback
5115 function. See cli-dump.c. */
5120 remote_start_remote (from_tty
, target
, extended_p
);
5122 CATCH (ex
, RETURN_MASK_ALL
)
5124 /* Pop the partially set up target - unless something else did
5125 already before throwing the exception. */
5126 if (rs
->remote_desc
!= NULL
)
5127 remote_unpush_target ();
5128 if (target_async_permitted
)
5129 wait_forever_enabled_p
= 1;
5130 throw_exception (ex
);
5135 remote_btrace_reset ();
5137 if (target_async_permitted
)
5138 wait_forever_enabled_p
= 1;
5141 /* Detach the specified process. */
5144 remote_detach_pid (int pid
)
5146 struct remote_state
*rs
= get_remote_state ();
5148 if (remote_multi_process_p (rs
))
5149 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5151 strcpy (rs
->buf
, "D");
5154 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5156 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5158 else if (rs
->buf
[0] == '\0')
5159 error (_("Remote doesn't know how to detach"));
5161 error (_("Can't detach process."));
5164 /* This detaches a program to which we previously attached, using
5165 inferior_ptid to identify the process. After this is done, GDB
5166 can be used to debug some other program. We better not have left
5167 any breakpoints in the target program or it'll die when it hits
5171 remote_detach_1 (const char *args
, int from_tty
)
5173 int pid
= ptid_get_pid (inferior_ptid
);
5174 struct remote_state
*rs
= get_remote_state ();
5175 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5179 error (_("Argument given to \"detach\" when remotely debugging."));
5181 if (!target_has_execution
)
5182 error (_("No process to detach from."));
5184 target_announce_detach (from_tty
);
5186 /* Tell the remote target to detach. */
5187 remote_detach_pid (pid
);
5189 /* Exit only if this is the only active inferior. */
5190 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5191 puts_filtered (_("Ending remote debugging.\n"));
5193 /* Check to see if we are detaching a fork parent. Note that if we
5194 are detaching a fork child, tp == NULL. */
5195 is_fork_parent
= (tp
!= NULL
5196 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5198 /* If doing detach-on-fork, we don't mourn, because that will delete
5199 breakpoints that should be available for the followed inferior. */
5200 if (!is_fork_parent
)
5201 target_mourn_inferior (inferior_ptid
);
5204 inferior_ptid
= null_ptid
;
5205 detach_inferior (pid
);
5210 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5212 remote_detach_1 (args
, from_tty
);
5216 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5218 remote_detach_1 (args
, from_tty
);
5221 /* Target follow-fork function for remote targets. On entry, and
5222 at return, the current inferior is the fork parent.
5224 Note that although this is currently only used for extended-remote,
5225 it is named remote_follow_fork in anticipation of using it for the
5226 remote target as well. */
5229 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5232 struct remote_state
*rs
= get_remote_state ();
5233 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5235 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5236 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5238 /* When following the parent and detaching the child, we detach
5239 the child here. For the case of following the child and
5240 detaching the parent, the detach is done in the target-
5241 independent follow fork code in infrun.c. We can't use
5242 target_detach when detaching an unfollowed child because
5243 the client side doesn't know anything about the child. */
5244 if (detach_fork
&& !follow_child
)
5246 /* Detach the fork child. */
5250 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5251 child_pid
= ptid_get_pid (child_ptid
);
5253 remote_detach_pid (child_pid
);
5254 detach_inferior (child_pid
);
5260 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5261 in the program space of the new inferior. On entry and at return the
5262 current inferior is the exec'ing inferior. INF is the new exec'd
5263 inferior, which may be the same as the exec'ing inferior unless
5264 follow-exec-mode is "new". */
5267 remote_follow_exec (struct target_ops
*ops
,
5268 struct inferior
*inf
, char *execd_pathname
)
5270 /* We know that this is a target file name, so if it has the "target:"
5271 prefix we strip it off before saving it in the program space. */
5272 if (is_target_filename (execd_pathname
))
5273 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5275 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5278 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5281 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5284 error (_("Argument given to \"disconnect\" when remotely debugging."));
5286 /* Make sure we unpush even the extended remote targets. Calling
5287 target_mourn_inferior won't unpush, and remote_mourn won't
5288 unpush if there is more than one inferior left. */
5289 unpush_target (target
);
5290 generic_mourn_inferior ();
5293 puts_filtered ("Ending remote debugging.\n");
5296 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5297 be chatty about it. */
5300 extended_remote_attach (struct target_ops
*target
, const char *args
,
5303 struct remote_state
*rs
= get_remote_state ();
5305 char *wait_status
= NULL
;
5307 pid
= parse_pid_to_attach (args
);
5309 /* Remote PID can be freely equal to getpid, do not check it here the same
5310 way as in other targets. */
5312 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5313 error (_("This target does not support attaching to a process"));
5317 char *exec_file
= get_exec_file (0);
5320 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5321 target_pid_to_str (pid_to_ptid (pid
)));
5323 printf_unfiltered (_("Attaching to %s\n"),
5324 target_pid_to_str (pid_to_ptid (pid
)));
5326 gdb_flush (gdb_stdout
);
5329 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5331 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5333 switch (packet_ok (rs
->buf
,
5334 &remote_protocol_packets
[PACKET_vAttach
]))
5337 if (!target_is_non_stop_p ())
5339 /* Save the reply for later. */
5340 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5341 strcpy (wait_status
, rs
->buf
);
5343 else if (strcmp (rs
->buf
, "OK") != 0)
5344 error (_("Attaching to %s failed with: %s"),
5345 target_pid_to_str (pid_to_ptid (pid
)),
5348 case PACKET_UNKNOWN
:
5349 error (_("This target does not support attaching to a process"));
5351 error (_("Attaching to %s failed"),
5352 target_pid_to_str (pid_to_ptid (pid
)));
5355 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5357 inferior_ptid
= pid_to_ptid (pid
);
5359 if (target_is_non_stop_p ())
5361 struct thread_info
*thread
;
5363 /* Get list of threads. */
5364 remote_update_thread_list (target
);
5366 thread
= first_thread_of_process (pid
);
5368 inferior_ptid
= thread
->ptid
;
5370 inferior_ptid
= pid_to_ptid (pid
);
5372 /* Invalidate our notion of the remote current thread. */
5373 record_currthread (rs
, minus_one_ptid
);
5377 /* Now, if we have thread information, update inferior_ptid. */
5378 inferior_ptid
= remote_current_thread (inferior_ptid
);
5380 /* Add the main thread to the thread list. */
5381 add_thread_silent (inferior_ptid
);
5384 /* Next, if the target can specify a description, read it. We do
5385 this before anything involving memory or registers. */
5386 target_find_description ();
5388 if (!target_is_non_stop_p ())
5390 /* Use the previously fetched status. */
5391 gdb_assert (wait_status
!= NULL
);
5393 if (target_can_async_p ())
5395 struct notif_event
*reply
5396 = remote_notif_parse (¬if_client_stop
, wait_status
);
5398 push_stop_reply ((struct stop_reply
*) reply
);
5404 gdb_assert (wait_status
!= NULL
);
5405 strcpy (rs
->buf
, wait_status
);
5406 rs
->cached_wait_status
= 1;
5410 gdb_assert (wait_status
== NULL
);
5413 /* Implementation of the to_post_attach method. */
5416 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5418 /* Get text, data & bss offsets. */
5421 /* In certain cases GDB might not have had the chance to start
5422 symbol lookup up until now. This could happen if the debugged
5423 binary is not using shared libraries, the vsyscall page is not
5424 present (on Linux) and the binary itself hadn't changed since the
5425 debugging process was started. */
5426 if (symfile_objfile
!= NULL
)
5427 remote_check_symbols();
5431 /* Check for the availability of vCont. This function should also check
5435 remote_vcont_probe (struct remote_state
*rs
)
5439 strcpy (rs
->buf
, "vCont?");
5441 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5444 /* Make sure that the features we assume are supported. */
5445 if (startswith (buf
, "vCont"))
5448 int support_c
, support_C
;
5450 rs
->supports_vCont
.s
= 0;
5451 rs
->supports_vCont
.S
= 0;
5454 rs
->supports_vCont
.t
= 0;
5455 rs
->supports_vCont
.r
= 0;
5456 while (p
&& *p
== ';')
5459 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5460 rs
->supports_vCont
.s
= 1;
5461 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5462 rs
->supports_vCont
.S
= 1;
5463 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5465 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5467 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5468 rs
->supports_vCont
.t
= 1;
5469 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5470 rs
->supports_vCont
.r
= 1;
5472 p
= strchr (p
, ';');
5475 /* If c, and C are not all supported, we can't use vCont. Clearing
5476 BUF will make packet_ok disable the packet. */
5477 if (!support_c
|| !support_C
)
5481 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5484 /* Helper function for building "vCont" resumptions. Write a
5485 resumption to P. ENDP points to one-passed-the-end of the buffer
5486 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5487 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5488 resumed thread should be single-stepped and/or signalled. If PTID
5489 equals minus_one_ptid, then all threads are resumed; if PTID
5490 represents a process, then all threads of the process are resumed;
5491 the thread to be stepped and/or signalled is given in the global
5495 append_resumption (char *p
, char *endp
,
5496 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5498 struct remote_state
*rs
= get_remote_state ();
5500 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5501 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5503 /* GDB is willing to range step. */
5504 && use_range_stepping
5505 /* Target supports range stepping. */
5506 && rs
->supports_vCont
.r
5507 /* We don't currently support range stepping multiple
5508 threads with a wildcard (though the protocol allows it,
5509 so stubs shouldn't make an active effort to forbid
5511 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5513 struct thread_info
*tp
;
5515 if (ptid_equal (ptid
, minus_one_ptid
))
5517 /* If we don't know about the target thread's tid, then
5518 we're resuming magic_null_ptid (see caller). */
5519 tp
= find_thread_ptid (magic_null_ptid
);
5522 tp
= find_thread_ptid (ptid
);
5523 gdb_assert (tp
!= NULL
);
5525 if (tp
->control
.may_range_step
)
5527 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5529 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5530 phex_nz (tp
->control
.step_range_start
,
5532 phex_nz (tp
->control
.step_range_end
,
5536 p
+= xsnprintf (p
, endp
- p
, ";s");
5539 p
+= xsnprintf (p
, endp
- p
, ";s");
5540 else if (siggnal
!= GDB_SIGNAL_0
)
5541 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5543 p
+= xsnprintf (p
, endp
- p
, ";c");
5545 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5549 /* All (-1) threads of process. */
5550 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5552 p
+= xsnprintf (p
, endp
- p
, ":");
5553 p
= write_ptid (p
, endp
, nptid
);
5555 else if (!ptid_equal (ptid
, minus_one_ptid
))
5557 p
+= xsnprintf (p
, endp
- p
, ":");
5558 p
= write_ptid (p
, endp
, ptid
);
5564 /* Clear the thread's private info on resume. */
5567 resume_clear_thread_private_info (struct thread_info
*thread
)
5569 if (thread
->priv
!= NULL
)
5571 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5572 thread
->priv
->watch_data_address
= 0;
5576 /* Append a vCont continue-with-signal action for threads that have a
5577 non-zero stop signal. */
5580 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5582 struct thread_info
*thread
;
5584 ALL_NON_EXITED_THREADS (thread
)
5585 if (ptid_match (thread
->ptid
, ptid
)
5586 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5587 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5589 p
= append_resumption (p
, endp
, thread
->ptid
,
5590 0, thread
->suspend
.stop_signal
);
5591 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5592 resume_clear_thread_private_info (thread
);
5598 /* Set the target running, using the packets that use Hc
5602 remote_resume_with_hc (struct target_ops
*ops
,
5603 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5605 struct remote_state
*rs
= get_remote_state ();
5606 struct thread_info
*thread
;
5609 rs
->last_sent_signal
= siggnal
;
5610 rs
->last_sent_step
= step
;
5612 /* The c/s/C/S resume packets use Hc, so set the continue
5614 if (ptid_equal (ptid
, minus_one_ptid
))
5615 set_continue_thread (any_thread_ptid
);
5617 set_continue_thread (ptid
);
5619 ALL_NON_EXITED_THREADS (thread
)
5620 resume_clear_thread_private_info (thread
);
5623 if (execution_direction
== EXEC_REVERSE
)
5625 /* We don't pass signals to the target in reverse exec mode. */
5626 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5627 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5630 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5631 error (_("Remote reverse-step not supported."));
5632 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5633 error (_("Remote reverse-continue not supported."));
5635 strcpy (buf
, step
? "bs" : "bc");
5637 else if (siggnal
!= GDB_SIGNAL_0
)
5639 buf
[0] = step
? 'S' : 'C';
5640 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5641 buf
[2] = tohex (((int) siggnal
) & 0xf);
5645 strcpy (buf
, step
? "s" : "c");
5650 /* Resume the remote inferior by using a "vCont" packet. The thread
5651 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5652 resumed thread should be single-stepped and/or signalled. If PTID
5653 equals minus_one_ptid, then all threads are resumed; the thread to
5654 be stepped and/or signalled is given in the global INFERIOR_PTID.
5655 This function returns non-zero iff it resumes the inferior.
5657 This function issues a strict subset of all possible vCont commands
5661 remote_resume_with_vcont (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5663 struct remote_state
*rs
= get_remote_state ();
5667 /* No reverse execution actions defined for vCont. */
5668 if (execution_direction
== EXEC_REVERSE
)
5671 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5672 remote_vcont_probe (rs
);
5674 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5678 endp
= rs
->buf
+ get_remote_packet_size ();
5680 /* If we could generate a wider range of packets, we'd have to worry
5681 about overflowing BUF. Should there be a generic
5682 "multi-part-packet" packet? */
5684 p
+= xsnprintf (p
, endp
- p
, "vCont");
5686 if (ptid_equal (ptid
, magic_null_ptid
))
5688 /* MAGIC_NULL_PTID means that we don't have any active threads,
5689 so we don't have any TID numbers the inferior will
5690 understand. Make sure to only send forms that do not specify
5692 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5694 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5696 /* Resume all threads (of all processes, or of a single
5697 process), with preference for INFERIOR_PTID. This assumes
5698 inferior_ptid belongs to the set of all threads we are about
5700 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5702 /* Step inferior_ptid, with or without signal. */
5703 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5706 /* Also pass down any pending signaled resumption for other
5707 threads not the current. */
5708 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5710 /* And continue others without a signal. */
5711 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5715 /* Scheduler locking; resume only PTID. */
5716 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5719 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5722 if (target_is_non_stop_p ())
5724 /* In non-stop, the stub replies to vCont with "OK". The stop
5725 reply will be reported asynchronously by means of a `%Stop'
5727 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5728 if (strcmp (rs
->buf
, "OK") != 0)
5729 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5735 /* Tell the remote machine to resume. */
5738 remote_resume (struct target_ops
*ops
,
5739 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5741 struct remote_state
*rs
= get_remote_state ();
5743 /* When connected in non-stop mode, the core resumes threads
5744 individually. Resuming remote threads directly in target_resume
5745 would thus result in sending one packet per thread. Instead, to
5746 minimize roundtrip latency, here we just store the resume
5747 request; the actual remote resumption will be done in
5748 target_commit_resume / remote_commit_resume, where we'll be able
5749 to do vCont action coalescing. */
5750 if (target_is_non_stop_p () && execution_direction
!= EXEC_REVERSE
)
5752 struct private_thread_info
*remote_thr
;
5754 if (ptid_equal (minus_one_ptid
, ptid
) || ptid_is_pid (ptid
))
5755 remote_thr
= get_private_info_ptid (inferior_ptid
);
5757 remote_thr
= get_private_info_ptid (ptid
);
5758 remote_thr
->last_resume_step
= step
;
5759 remote_thr
->last_resume_sig
= siggnal
;
5763 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5764 (explained in remote-notif.c:handle_notification) so
5765 remote_notif_process is not called. We need find a place where
5766 it is safe to start a 'vNotif' sequence. It is good to do it
5767 before resuming inferior, because inferior was stopped and no RSP
5768 traffic at that moment. */
5769 if (!target_is_non_stop_p ())
5770 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5772 rs
->last_resume_exec_dir
= execution_direction
;
5774 /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
5775 if (!remote_resume_with_vcont (ptid
, step
, siggnal
))
5776 remote_resume_with_hc (ops
, ptid
, step
, siggnal
);
5778 /* We are about to start executing the inferior, let's register it
5779 with the event loop. NOTE: this is the one place where all the
5780 execution commands end up. We could alternatively do this in each
5781 of the execution commands in infcmd.c. */
5782 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5783 into infcmd.c in order to allow inferior function calls to work
5784 NOT asynchronously. */
5785 if (target_can_async_p ())
5788 /* We've just told the target to resume. The remote server will
5789 wait for the inferior to stop, and then send a stop reply. In
5790 the mean time, we can't start another command/query ourselves
5791 because the stub wouldn't be ready to process it. This applies
5792 only to the base all-stop protocol, however. In non-stop (which
5793 only supports vCont), the stub replies with an "OK", and is
5794 immediate able to process further serial input. */
5795 if (!target_is_non_stop_p ())
5796 rs
->waiting_for_stop_reply
= 1;
5799 static void check_pending_events_prevent_wildcard_vcont
5800 (int *may_global_wildcard_vcont
);
5801 static int is_pending_fork_parent_thread (struct thread_info
*thread
);
5803 /* Private per-inferior info for target remote processes. */
5805 struct private_inferior
5807 /* Whether we can send a wildcard vCont for this process. */
5808 int may_wildcard_vcont
;
5811 /* Structure used to track the construction of a vCont packet in the
5812 outgoing packet buffer. This is used to send multiple vCont
5813 packets if we have more actions than would fit a single packet. */
5815 struct vcont_builder
5817 /* Pointer to the first action. P points here if no action has been
5821 /* Where the next action will be appended. */
5824 /* The end of the buffer. Must never write past this. */
5828 /* Prepare the outgoing buffer for a new vCont packet. */
5831 vcont_builder_restart (struct vcont_builder
*builder
)
5833 struct remote_state
*rs
= get_remote_state ();
5835 builder
->p
= rs
->buf
;
5836 builder
->endp
= rs
->buf
+ get_remote_packet_size ();
5837 builder
->p
+= xsnprintf (builder
->p
, builder
->endp
- builder
->p
, "vCont");
5838 builder
->first_action
= builder
->p
;
5841 /* If the vCont packet being built has any action, send it to the
5845 vcont_builder_flush (struct vcont_builder
*builder
)
5847 struct remote_state
*rs
;
5849 if (builder
->p
== builder
->first_action
)
5852 rs
= get_remote_state ();
5854 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5855 if (strcmp (rs
->buf
, "OK") != 0)
5856 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5859 /* The largest action is range-stepping, with its two addresses. This
5860 is more than sufficient. If a new, bigger action is created, it'll
5861 quickly trigger a failed assertion in append_resumption (and we'll
5863 #define MAX_ACTION_SIZE 200
5865 /* Append a new vCont action in the outgoing packet being built. If
5866 the action doesn't fit the packet along with previous actions, push
5867 what we've got so far to the remote end and start over a new vCont
5868 packet (with the new action). */
5871 vcont_builder_push_action (struct vcont_builder
*builder
,
5872 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5874 char buf
[MAX_ACTION_SIZE
+ 1];
5878 endp
= append_resumption (buf
, buf
+ sizeof (buf
),
5879 ptid
, step
, siggnal
);
5881 /* Check whether this new action would fit in the vCont packet along
5882 with previous actions. If not, send what we've got so far and
5883 start a new vCont packet. */
5885 if (rsize
> builder
->endp
- builder
->p
)
5887 vcont_builder_flush (builder
);
5888 vcont_builder_restart (builder
);
5890 /* Should now fit. */
5891 gdb_assert (rsize
<= builder
->endp
- builder
->p
);
5894 memcpy (builder
->p
, buf
, rsize
);
5895 builder
->p
+= rsize
;
5899 /* to_commit_resume implementation. */
5902 remote_commit_resume (struct target_ops
*ops
)
5904 struct remote_state
*rs
= get_remote_state ();
5905 struct inferior
*inf
;
5906 struct thread_info
*tp
;
5907 int any_process_wildcard
;
5908 int may_global_wildcard_vcont
;
5909 struct vcont_builder vcont_builder
;
5911 /* If connected in all-stop mode, we'd send the remote resume
5912 request directly from remote_resume. Likewise if
5913 reverse-debugging, as there are no defined vCont actions for
5914 reverse execution. */
5915 if (!target_is_non_stop_p () || execution_direction
== EXEC_REVERSE
)
5918 /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
5919 instead of resuming all threads of each process individually.
5920 However, if any thread of a process must remain halted, we can't
5921 send wildcard resumes and must send one action per thread.
5923 Care must be taken to not resume threads/processes the server
5924 side already told us are stopped, but the core doesn't know about
5925 yet, because the events are still in the vStopped notification
5928 #1 => vCont s:p1.1;c
5930 #3 <= %Stopped T05 p1.1
5935 #8 (infrun handles the stop for p1.1 and continues stepping)
5936 #9 => vCont s:p1.1;c
5938 The last vCont above would resume thread p1.2 by mistake, because
5939 the server has no idea that the event for p1.2 had not been
5942 The server side must similarly ignore resume actions for the
5943 thread that has a pending %Stopped notification (and any other
5944 threads with events pending), until GDB acks the notification
5945 with vStopped. Otherwise, e.g., the following case is
5948 #1 => g (or any other packet)
5950 #3 <= %Stopped T05 p1.2
5951 #4 => vCont s:p1.1;c
5954 Above, the server must not resume thread p1.2. GDB can't know
5955 that p1.2 stopped until it acks the %Stopped notification, and
5956 since from GDB's perspective all threads should be running, it
5959 Finally, special care must also be given to handling fork/vfork
5960 events. A (v)fork event actually tells us that two processes
5961 stopped -- the parent and the child. Until we follow the fork,
5962 we must not resume the child. Therefore, if we have a pending
5963 fork follow, we must not send a global wildcard resume action
5964 (vCont;c). We can still send process-wide wildcards though. */
5966 /* Start by assuming a global wildcard (vCont;c) is possible. */
5967 may_global_wildcard_vcont
= 1;
5969 /* And assume every process is individually wildcard-able too. */
5970 ALL_NON_EXITED_INFERIORS (inf
)
5972 if (inf
->priv
== NULL
)
5973 inf
->priv
= XNEW (struct private_inferior
);
5974 inf
->priv
->may_wildcard_vcont
= 1;
5977 /* Check for any pending events (not reported or processed yet) and
5978 disable process and global wildcard resumes appropriately. */
5979 check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont
);
5981 ALL_NON_EXITED_THREADS (tp
)
5983 /* If a thread of a process is not meant to be resumed, then we
5984 can't wildcard that process. */
5987 tp
->inf
->priv
->may_wildcard_vcont
= 0;
5989 /* And if we can't wildcard a process, we can't wildcard
5990 everything either. */
5991 may_global_wildcard_vcont
= 0;
5995 /* If a thread is the parent of an unfollowed fork, then we
5996 can't do a global wildcard, as that would resume the fork
5998 if (is_pending_fork_parent_thread (tp
))
5999 may_global_wildcard_vcont
= 0;
6002 /* Now let's build the vCont packet(s). Actions must be appended
6003 from narrower to wider scopes (thread -> process -> global). If
6004 we end up with too many actions for a single packet vcont_builder
6005 flushes the current vCont packet to the remote side and starts a
6007 vcont_builder_restart (&vcont_builder
);
6009 /* Threads first. */
6010 ALL_NON_EXITED_THREADS (tp
)
6012 struct private_thread_info
*remote_thr
= tp
->priv
;
6014 if (!tp
->executing
|| remote_thr
->vcont_resumed
)
6017 gdb_assert (!thread_is_in_step_over_chain (tp
));
6019 if (!remote_thr
->last_resume_step
6020 && remote_thr
->last_resume_sig
== GDB_SIGNAL_0
6021 && tp
->inf
->priv
->may_wildcard_vcont
)
6023 /* We'll send a wildcard resume instead. */
6024 remote_thr
->vcont_resumed
= 1;
6028 vcont_builder_push_action (&vcont_builder
, tp
->ptid
,
6029 remote_thr
->last_resume_step
,
6030 remote_thr
->last_resume_sig
);
6031 remote_thr
->vcont_resumed
= 1;
6034 /* Now check whether we can send any process-wide wildcard. This is
6035 to avoid sending a global wildcard in the case nothing is
6036 supposed to be resumed. */
6037 any_process_wildcard
= 0;
6039 ALL_NON_EXITED_INFERIORS (inf
)
6041 if (inf
->priv
->may_wildcard_vcont
)
6043 any_process_wildcard
= 1;
6048 if (any_process_wildcard
)
6050 /* If all processes are wildcard-able, then send a single "c"
6051 action, otherwise, send an "all (-1) threads of process"
6052 continue action for each running process, if any. */
6053 if (may_global_wildcard_vcont
)
6055 vcont_builder_push_action (&vcont_builder
, minus_one_ptid
,
6060 ALL_NON_EXITED_INFERIORS (inf
)
6062 if (inf
->priv
->may_wildcard_vcont
)
6064 vcont_builder_push_action (&vcont_builder
,
6065 pid_to_ptid (inf
->pid
),
6072 vcont_builder_flush (&vcont_builder
);
6077 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
6078 thread, all threads of a remote process, or all threads of all
6082 remote_stop_ns (ptid_t ptid
)
6084 struct remote_state
*rs
= get_remote_state ();
6086 char *endp
= rs
->buf
+ get_remote_packet_size ();
6088 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
6089 remote_vcont_probe (rs
);
6091 if (!rs
->supports_vCont
.t
)
6092 error (_("Remote server does not support stopping threads"));
6094 if (ptid_equal (ptid
, minus_one_ptid
)
6095 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
6096 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
6101 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
6103 if (ptid_is_pid (ptid
))
6104 /* All (-1) threads of process. */
6105 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
6108 /* Small optimization: if we already have a stop reply for
6109 this thread, no use in telling the stub we want this
6111 if (peek_stop_reply (ptid
))
6117 write_ptid (p
, endp
, nptid
);
6120 /* In non-stop, we get an immediate OK reply. The stop reply will
6121 come in asynchronously by notification. */
6123 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6124 if (strcmp (rs
->buf
, "OK") != 0)
6125 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
6128 /* All-stop version of target_interrupt. Sends a break or a ^C to
6129 interrupt the remote target. It is undefined which thread of which
6130 process reports the interrupt. */
6133 remote_interrupt_as (void)
6135 struct remote_state
*rs
= get_remote_state ();
6137 rs
->ctrlc_pending_p
= 1;
6139 /* If the inferior is stopped already, but the core didn't know
6140 about it yet, just ignore the request. The cached wait status
6141 will be collected in remote_wait. */
6142 if (rs
->cached_wait_status
)
6145 /* Send interrupt_sequence to remote target. */
6146 send_interrupt_sequence ();
6149 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
6150 the remote target. It is undefined which thread of which process
6151 reports the interrupt. Throws an error if the packet is not
6152 supported by the server. */
6155 remote_interrupt_ns (void)
6157 struct remote_state
*rs
= get_remote_state ();
6159 char *endp
= rs
->buf
+ get_remote_packet_size ();
6161 xsnprintf (p
, endp
- p
, "vCtrlC");
6163 /* In non-stop, we get an immediate OK reply. The stop reply will
6164 come in asynchronously by notification. */
6166 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6168 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
6172 case PACKET_UNKNOWN
:
6173 error (_("No support for interrupting the remote target."));
6175 error (_("Interrupting target failed: %s"), rs
->buf
);
6179 /* Implement the to_stop function for the remote targets. */
6182 remote_stop (struct target_ops
*self
, ptid_t ptid
)
6185 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
6187 if (target_is_non_stop_p ())
6188 remote_stop_ns (ptid
);
6191 /* We don't currently have a way to transparently pause the
6192 remote target in all-stop mode. Interrupt it instead. */
6193 remote_interrupt_as ();
6197 /* Implement the to_interrupt function for the remote targets. */
6200 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
6202 struct remote_state
*rs
= get_remote_state ();
6205 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
6207 if (target_is_non_stop_p ())
6208 remote_interrupt_ns ();
6210 remote_interrupt_as ();
6213 /* Implement the to_pass_ctrlc function for the remote targets. */
6216 remote_pass_ctrlc (struct target_ops
*self
)
6218 struct remote_state
*rs
= get_remote_state ();
6221 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
6223 /* If we're starting up, we're not fully synced yet. Quit
6225 if (rs
->starting_up
)
6227 /* If ^C has already been sent once, offer to disconnect. */
6228 else if (rs
->ctrlc_pending_p
)
6231 target_interrupt (inferior_ptid
);
6234 /* Ask the user what to do when an interrupt is received. */
6237 interrupt_query (void)
6239 struct remote_state
*rs
= get_remote_state ();
6241 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
6243 if (query (_("The target is not responding to interrupt requests.\n"
6244 "Stop debugging it? ")))
6246 remote_unpush_target ();
6247 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
6252 if (query (_("Interrupted while waiting for the program.\n"
6253 "Give up waiting? ")))
6258 /* Enable/disable target terminal ownership. Most targets can use
6259 terminal groups to control terminal ownership. Remote targets are
6260 different in that explicit transfer of ownership to/from GDB/target
6264 remote_terminal_inferior (struct target_ops
*self
)
6266 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
6267 idempotent. The event-loop GDB talking to an asynchronous target
6268 with a synchronous command calls this function from both
6269 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
6270 transfer the terminal to the target when it shouldn't this guard
6272 if (!remote_async_terminal_ours_p
)
6274 remote_async_terminal_ours_p
= 0;
6275 /* NOTE: At this point we could also register our selves as the
6276 recipient of all input. Any characters typed could then be
6277 passed on down to the target. */
6281 remote_terminal_ours (struct target_ops
*self
)
6283 /* See FIXME in remote_terminal_inferior. */
6284 if (remote_async_terminal_ours_p
)
6286 remote_async_terminal_ours_p
= 1;
6290 remote_console_output (char *msg
)
6294 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
6297 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
6301 fputs_unfiltered (tb
, gdb_stdtarg
);
6303 gdb_flush (gdb_stdtarg
);
6306 typedef struct cached_reg
6309 gdb_byte data
[MAX_REGISTER_SIZE
];
6312 DEF_VEC_O(cached_reg_t
);
6314 typedef struct stop_reply
6316 struct notif_event base
;
6318 /* The identifier of the thread about this event */
6321 /* The remote state this event is associated with. When the remote
6322 connection, represented by a remote_state object, is closed,
6323 all the associated stop_reply events should be released. */
6324 struct remote_state
*rs
;
6326 struct target_waitstatus ws
;
6328 /* Expedited registers. This makes remote debugging a bit more
6329 efficient for those targets that provide critical registers as
6330 part of their normal status mechanism (as another roundtrip to
6331 fetch them is avoided). */
6332 VEC(cached_reg_t
) *regcache
;
6334 enum target_stop_reason stop_reason
;
6336 CORE_ADDR watch_data_address
;
6341 DECLARE_QUEUE_P (stop_reply_p
);
6342 DEFINE_QUEUE_P (stop_reply_p
);
6343 /* The list of already fetched and acknowledged stop events. This
6344 queue is used for notification Stop, and other notifications
6345 don't need queue for their events, because the notification events
6346 of Stop can't be consumed immediately, so that events should be
6347 queued first, and be consumed by remote_wait_{ns,as} one per
6348 time. Other notifications can consume their events immediately,
6349 so queue is not needed for them. */
6350 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6353 stop_reply_xfree (struct stop_reply
*r
)
6355 notif_event_xfree ((struct notif_event
*) r
);
6358 /* Return the length of the stop reply queue. */
6361 stop_reply_queue_length (void)
6363 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6367 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6368 struct notif_event
*event
)
6370 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6374 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6375 struct notif_event
*event
)
6377 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6380 putpkt (self
->ack_command
);
6382 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6383 /* We got an unknown stop reply. */
6384 error (_("Unknown stop reply"));
6386 push_stop_reply (stop_reply
);
6390 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6392 /* We can't get pending events in remote_notif_process for
6393 notification stop, and we have to do this in remote_wait_ns
6394 instead. If we fetch all queued events from stub, remote stub
6395 may exit and we have no chance to process them back in
6397 mark_async_event_handler (remote_async_inferior_event_token
);
6402 stop_reply_dtr (struct notif_event
*event
)
6404 struct stop_reply
*r
= (struct stop_reply
*) event
;
6406 VEC_free (cached_reg_t
, r
->regcache
);
6409 static struct notif_event
*
6410 remote_notif_stop_alloc_reply (void)
6412 /* We cast to a pointer to the "base class". */
6413 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6415 r
->dtr
= stop_reply_dtr
;
6420 /* A client of notification Stop. */
6422 struct notif_client notif_client_stop
=
6426 remote_notif_stop_parse
,
6427 remote_notif_stop_ack
,
6428 remote_notif_stop_can_get_pending_events
,
6429 remote_notif_stop_alloc_reply
,
6433 /* A parameter to pass data in and out. */
6435 struct queue_iter_param
6438 struct stop_reply
*output
;
6441 /* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
6442 the pid of the process that owns the threads we want to check, or
6443 -1 if we want to check all threads. */
6446 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6449 if (ws
->kind
== TARGET_WAITKIND_FORKED
6450 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6452 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6459 /* Return the thread's pending status used to determine whether the
6460 thread is a fork parent stopped at a fork event. */
6462 static struct target_waitstatus
*
6463 thread_pending_fork_status (struct thread_info
*thread
)
6465 if (thread
->suspend
.waitstatus_pending_p
)
6466 return &thread
->suspend
.waitstatus
;
6468 return &thread
->pending_follow
;
6471 /* Determine if THREAD is a pending fork parent thread. */
6474 is_pending_fork_parent_thread (struct thread_info
*thread
)
6476 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6479 return is_pending_fork_parent (ws
, pid
, thread
->ptid
);
6482 /* Check whether EVENT is a fork event, and if it is, remove the
6483 fork child from the context list passed in DATA. */
6486 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6487 QUEUE_ITER (stop_reply_p
) *iter
,
6491 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6492 struct threads_listing_context
*context
6493 = (struct threads_listing_context
*) param
->input
;
6495 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6496 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6497 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6498 threads_listing_context_remove (&event
->ws
, context
);
6503 /* If CONTEXT contains any fork child threads that have not been
6504 reported yet, remove them from the CONTEXT list. If such a
6505 thread exists it is because we are stopped at a fork catchpoint
6506 and have not yet called follow_fork, which will set up the
6507 host-side data structures for the new process. */
6510 remove_new_fork_children (struct threads_listing_context
*context
)
6512 struct thread_info
* thread
;
6514 struct notif_client
*notif
= ¬if_client_stop
;
6515 struct queue_iter_param param
;
6517 /* For any threads stopped at a fork event, remove the corresponding
6518 fork child threads from the CONTEXT list. */
6519 ALL_NON_EXITED_THREADS (thread
)
6521 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6523 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6525 threads_listing_context_remove (ws
, context
);
6529 /* Check for any pending fork events (not reported or processed yet)
6530 in process PID and remove those fork child threads from the
6531 CONTEXT list as well. */
6532 remote_notif_get_pending_events (notif
);
6533 param
.input
= context
;
6534 param
.output
= NULL
;
6535 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6536 remove_child_of_pending_fork
, ¶m
);
6539 /* Check whether EVENT would prevent a global or process wildcard
6543 check_pending_event_prevents_wildcard_vcont_callback
6544 (QUEUE (stop_reply_p
) *q
,
6545 QUEUE_ITER (stop_reply_p
) *iter
,
6549 struct inferior
*inf
;
6550 int *may_global_wildcard_vcont
= (int *) data
;
6552 if (event
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
6553 || event
->ws
.kind
== TARGET_WAITKIND_NO_HISTORY
)
6556 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6557 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
6558 *may_global_wildcard_vcont
= 0;
6560 inf
= find_inferior_ptid (event
->ptid
);
6562 /* This may be the first time we heard about this process.
6563 Regardless, we must not do a global wildcard resume, otherwise
6564 we'd resume this process too. */
6565 *may_global_wildcard_vcont
= 0;
6567 inf
->priv
->may_wildcard_vcont
= 0;
6572 /* Check whether any event pending in the vStopped queue would prevent
6573 a global or process wildcard vCont action. Clear
6574 *may_global_wildcard if we can't do a global wildcard (vCont;c),
6575 and clear the event inferior's may_wildcard_vcont flag if we can't
6576 do a process-wide wildcard resume (vCont;c:pPID.-1). */
6579 check_pending_events_prevent_wildcard_vcont (int *may_global_wildcard
)
6581 struct notif_client
*notif
= ¬if_client_stop
;
6583 remote_notif_get_pending_events (notif
);
6584 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6585 check_pending_event_prevents_wildcard_vcont_callback
,
6586 may_global_wildcard
);
6589 /* Remove stop replies in the queue if its pid is equal to the given
6593 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6594 QUEUE_ITER (stop_reply_p
) *iter
,
6598 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6599 struct inferior
*inf
= (struct inferior
*) param
->input
;
6601 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6603 stop_reply_xfree (event
);
6604 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6610 /* Discard all pending stop replies of inferior INF. */
6613 discard_pending_stop_replies (struct inferior
*inf
)
6615 struct queue_iter_param param
;
6616 struct stop_reply
*reply
;
6617 struct remote_state
*rs
= get_remote_state ();
6618 struct remote_notif_state
*rns
= rs
->notif_state
;
6620 /* This function can be notified when an inferior exists. When the
6621 target is not remote, the notification state is NULL. */
6622 if (rs
->remote_desc
== NULL
)
6625 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6627 /* Discard the in-flight notification. */
6628 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6630 stop_reply_xfree (reply
);
6631 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6635 param
.output
= NULL
;
6636 /* Discard the stop replies we have already pulled with
6638 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6639 remove_stop_reply_for_inferior
, ¶m
);
6642 /* If its remote state is equal to the given remote state,
6643 remove EVENT from the stop reply queue. */
6646 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6647 QUEUE_ITER (stop_reply_p
) *iter
,
6651 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6652 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6654 if (event
->rs
== rs
)
6656 stop_reply_xfree (event
);
6657 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6663 /* Discard the stop replies for RS in stop_reply_queue. */
6666 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6668 struct queue_iter_param param
;
6671 param
.output
= NULL
;
6672 /* Discard the stop replies we have already pulled with
6674 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6675 remove_stop_reply_of_remote_state
, ¶m
);
6678 /* A parameter to pass data in and out. */
6681 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6682 QUEUE_ITER (stop_reply_p
) *iter
,
6686 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6687 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6689 if (ptid_match (event
->ptid
, *ptid
))
6691 param
->output
= event
;
6692 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6699 /* Remove the first reply in 'stop_reply_queue' which matches
6702 static struct stop_reply
*
6703 remote_notif_remove_queued_reply (ptid_t ptid
)
6705 struct queue_iter_param param
;
6707 param
.input
= &ptid
;
6708 param
.output
= NULL
;
6710 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6711 remote_notif_remove_once_on_match
, ¶m
);
6713 fprintf_unfiltered (gdb_stdlog
,
6714 "notif: discard queued event: 'Stop' in %s\n",
6715 target_pid_to_str (ptid
));
6717 return param
.output
;
6720 /* Look for a queued stop reply belonging to PTID. If one is found,
6721 remove it from the queue, and return it. Returns NULL if none is
6722 found. If there are still queued events left to process, tell the
6723 event loop to get back to target_wait soon. */
6725 static struct stop_reply
*
6726 queued_stop_reply (ptid_t ptid
)
6728 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6730 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6731 /* There's still at least an event left. */
6732 mark_async_event_handler (remote_async_inferior_event_token
);
6737 /* Push a fully parsed stop reply in the stop reply queue. Since we
6738 know that we now have at least one queued event left to pass to the
6739 core side, tell the event loop to get back to target_wait soon. */
6742 push_stop_reply (struct stop_reply
*new_event
)
6744 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6747 fprintf_unfiltered (gdb_stdlog
,
6748 "notif: push 'Stop' %s to queue %d\n",
6749 target_pid_to_str (new_event
->ptid
),
6750 QUEUE_length (stop_reply_p
,
6753 mark_async_event_handler (remote_async_inferior_event_token
);
6757 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6758 QUEUE_ITER (stop_reply_p
) *iter
,
6759 struct stop_reply
*event
,
6762 ptid_t
*ptid
= (ptid_t
*) data
;
6764 return !(ptid_equal (*ptid
, event
->ptid
)
6765 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6768 /* Returns true if we have a stop reply for PTID. */
6771 peek_stop_reply (ptid_t ptid
)
6773 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6774 stop_reply_match_ptid_and_ws
, &ptid
);
6777 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6778 starting with P and ending with PEND matches PREFIX. */
6781 strprefix (const char *p
, const char *pend
, const char *prefix
)
6783 for ( ; p
< pend
; p
++, prefix
++)
6786 return *prefix
== '\0';
6789 /* Parse the stop reply in BUF. Either the function succeeds, and the
6790 result is stored in EVENT, or throws an error. */
6793 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6795 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6800 event
->ptid
= null_ptid
;
6801 event
->rs
= get_remote_state ();
6802 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6803 event
->ws
.value
.integer
= 0;
6804 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6805 event
->regcache
= NULL
;
6810 case 'T': /* Status with PC, SP, FP, ... */
6811 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6812 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6814 n... = register number
6815 r... = register contents
6818 p
= &buf
[3]; /* after Txx */
6824 p1
= strchr (p
, ':');
6826 error (_("Malformed packet(a) (missing colon): %s\n\
6830 error (_("Malformed packet(a) (missing register number): %s\n\
6834 /* Some "registers" are actually extended stop information.
6835 Note if you're adding a new entry here: GDB 7.9 and
6836 earlier assume that all register "numbers" that start
6837 with an hex digit are real register numbers. Make sure
6838 the server only sends such a packet if it knows the
6839 client understands it. */
6841 if (strprefix (p
, p1
, "thread"))
6842 event
->ptid
= read_ptid (++p1
, &p
);
6843 else if (strprefix (p
, p1
, "syscall_entry"))
6847 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6848 p
= unpack_varlen_hex (++p1
, &sysno
);
6849 event
->ws
.value
.syscall_number
= (int) sysno
;
6851 else if (strprefix (p
, p1
, "syscall_return"))
6855 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6856 p
= unpack_varlen_hex (++p1
, &sysno
);
6857 event
->ws
.value
.syscall_number
= (int) sysno
;
6859 else if (strprefix (p
, p1
, "watch")
6860 || strprefix (p
, p1
, "rwatch")
6861 || strprefix (p
, p1
, "awatch"))
6863 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6864 p
= unpack_varlen_hex (++p1
, &addr
);
6865 event
->watch_data_address
= (CORE_ADDR
) addr
;
6867 else if (strprefix (p
, p1
, "swbreak"))
6869 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6871 /* Make sure the stub doesn't forget to indicate support
6873 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6874 error (_("Unexpected swbreak stop reason"));
6876 /* The value part is documented as "must be empty",
6877 though we ignore it, in case we ever decide to make
6878 use of it in a backward compatible way. */
6879 p
= strchrnul (p1
+ 1, ';');
6881 else if (strprefix (p
, p1
, "hwbreak"))
6883 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6885 /* Make sure the stub doesn't forget to indicate support
6887 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6888 error (_("Unexpected hwbreak stop reason"));
6891 p
= strchrnul (p1
+ 1, ';');
6893 else if (strprefix (p
, p1
, "library"))
6895 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6896 p
= strchrnul (p1
+ 1, ';');
6898 else if (strprefix (p
, p1
, "replaylog"))
6900 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6901 /* p1 will indicate "begin" or "end", but it makes
6902 no difference for now, so ignore it. */
6903 p
= strchrnul (p1
+ 1, ';');
6905 else if (strprefix (p
, p1
, "core"))
6909 p
= unpack_varlen_hex (++p1
, &c
);
6912 else if (strprefix (p
, p1
, "fork"))
6914 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6915 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6917 else if (strprefix (p
, p1
, "vfork"))
6919 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6920 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6922 else if (strprefix (p
, p1
, "vforkdone"))
6924 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6925 p
= strchrnul (p1
+ 1, ';');
6927 else if (strprefix (p
, p1
, "exec"))
6930 char pathname
[PATH_MAX
];
6933 /* Determine the length of the execd pathname. */
6934 p
= unpack_varlen_hex (++p1
, &ignored
);
6935 pathlen
= (p
- p1
) / 2;
6937 /* Save the pathname for event reporting and for
6938 the next run command. */
6939 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6940 pathname
[pathlen
] = '\0';
6942 /* This is freed during event handling. */
6943 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6944 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6946 /* Skip the registers included in this packet, since
6947 they may be for an architecture different from the
6948 one used by the original program. */
6951 else if (strprefix (p
, p1
, "create"))
6953 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6954 p
= strchrnul (p1
+ 1, ';');
6963 p
= strchrnul (p1
+ 1, ';');
6968 /* Maybe a real ``P'' register number. */
6969 p_temp
= unpack_varlen_hex (p
, &pnum
);
6970 /* If the first invalid character is the colon, we got a
6971 register number. Otherwise, it's an unknown stop
6975 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6976 cached_reg_t cached_reg
;
6979 error (_("Remote sent bad register number %s: %s\n\
6981 hex_string (pnum
), p
, buf
);
6983 cached_reg
.num
= reg
->regnum
;
6986 fieldsize
= hex2bin (p
, cached_reg
.data
,
6987 register_size (target_gdbarch (),
6990 if (fieldsize
< register_size (target_gdbarch (),
6992 warning (_("Remote reply is too short: %s"), buf
);
6994 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6998 /* Not a number. Silently skip unknown optional
7000 p
= strchrnul (p1
+ 1, ';');
7005 error (_("Remote register badly formatted: %s\nhere: %s"),
7010 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
7014 case 'S': /* Old style status, just signal only. */
7018 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
7019 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
7020 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
7021 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
7023 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7026 case 'w': /* Thread exited. */
7031 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
7032 p
= unpack_varlen_hex (&buf
[1], &value
);
7033 event
->ws
.value
.integer
= value
;
7035 error (_("stop reply packet badly formatted: %s"), buf
);
7036 event
->ptid
= read_ptid (++p
, NULL
);
7039 case 'W': /* Target exited. */
7046 /* GDB used to accept only 2 hex chars here. Stubs should
7047 only send more if they detect GDB supports multi-process
7049 p
= unpack_varlen_hex (&buf
[1], &value
);
7053 /* The remote process exited. */
7054 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
7055 event
->ws
.value
.integer
= value
;
7059 /* The remote process exited with a signal. */
7060 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
7061 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
7062 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
7064 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7067 /* If no process is specified, assume inferior_ptid. */
7068 pid
= ptid_get_pid (inferior_ptid
);
7077 else if (startswith (p
, "process:"))
7081 p
+= sizeof ("process:") - 1;
7082 unpack_varlen_hex (p
, &upid
);
7086 error (_("unknown stop reply packet: %s"), buf
);
7089 error (_("unknown stop reply packet: %s"), buf
);
7090 event
->ptid
= pid_to_ptid (pid
);
7094 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
7095 event
->ptid
= minus_one_ptid
;
7099 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
7100 error (_("No process or thread specified in stop reply: %s"), buf
);
7103 /* When the stub wants to tell GDB about a new notification reply, it
7104 sends a notification (%Stop, for example). Those can come it at
7105 any time, hence, we have to make sure that any pending
7106 putpkt/getpkt sequence we're making is finished, before querying
7107 the stub for more events with the corresponding ack command
7108 (vStopped, for example). E.g., if we started a vStopped sequence
7109 immediately upon receiving the notification, something like this
7117 1.6) <-- (registers reply to step #1.3)
7119 Obviously, the reply in step #1.6 would be unexpected to a vStopped
7122 To solve this, whenever we parse a %Stop notification successfully,
7123 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
7124 doing whatever we were doing:
7130 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
7131 2.5) <-- (registers reply to step #2.3)
7133 Eventualy after step #2.5, we return to the event loop, which
7134 notices there's an event on the
7135 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
7136 associated callback --- the function below. At this point, we're
7137 always safe to start a vStopped sequence. :
7140 2.7) <-- T05 thread:2
7146 remote_notif_get_pending_events (struct notif_client
*nc
)
7148 struct remote_state
*rs
= get_remote_state ();
7150 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
7153 fprintf_unfiltered (gdb_stdlog
,
7154 "notif: process: '%s' ack pending event\n",
7158 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
7159 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
7163 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7164 if (strcmp (rs
->buf
, "OK") == 0)
7167 remote_notif_ack (nc
, rs
->buf
);
7173 fprintf_unfiltered (gdb_stdlog
,
7174 "notif: process: '%s' no pending reply\n",
7179 /* Called when it is decided that STOP_REPLY holds the info of the
7180 event that is to be returned to the core. This function always
7181 destroys STOP_REPLY. */
7184 process_stop_reply (struct stop_reply
*stop_reply
,
7185 struct target_waitstatus
*status
)
7189 *status
= stop_reply
->ws
;
7190 ptid
= stop_reply
->ptid
;
7192 /* If no thread/process was reported by the stub, assume the current
7194 if (ptid_equal (ptid
, null_ptid
))
7195 ptid
= inferior_ptid
;
7197 if (status
->kind
!= TARGET_WAITKIND_EXITED
7198 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
7199 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
7201 struct private_thread_info
*remote_thr
;
7203 /* Expedited registers. */
7204 if (stop_reply
->regcache
)
7206 struct regcache
*regcache
7207 = get_thread_arch_regcache (ptid
, target_gdbarch ());
7212 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
7214 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
7215 VEC_free (cached_reg_t
, stop_reply
->regcache
);
7218 remote_notice_new_inferior (ptid
, 0);
7219 remote_thr
= get_private_info_ptid (ptid
);
7220 remote_thr
->core
= stop_reply
->core
;
7221 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
7222 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
7223 remote_thr
->vcont_resumed
= 0;
7226 stop_reply_xfree (stop_reply
);
7230 /* The non-stop mode version of target_wait. */
7233 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7235 struct remote_state
*rs
= get_remote_state ();
7236 struct stop_reply
*stop_reply
;
7240 /* If in non-stop mode, get out of getpkt even if a
7241 notification is received. */
7243 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7244 0 /* forever */, &is_notif
);
7247 if (ret
!= -1 && !is_notif
)
7250 case 'E': /* Error of some sort. */
7251 /* We're out of sync with the target now. Did it continue
7252 or not? We can't tell which thread it was in non-stop,
7253 so just ignore this. */
7254 warning (_("Remote failure reply: %s"), rs
->buf
);
7256 case 'O': /* Console output. */
7257 remote_console_output (rs
->buf
+ 1);
7260 warning (_("Invalid remote reply: %s"), rs
->buf
);
7264 /* Acknowledge a pending stop reply that may have arrived in the
7266 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
7267 remote_notif_get_pending_events (¬if_client_stop
);
7269 /* If indeed we noticed a stop reply, we're done. */
7270 stop_reply
= queued_stop_reply (ptid
);
7271 if (stop_reply
!= NULL
)
7272 return process_stop_reply (stop_reply
, status
);
7274 /* Still no event. If we're just polling for an event, then
7275 return to the event loop. */
7276 if (options
& TARGET_WNOHANG
)
7278 status
->kind
= TARGET_WAITKIND_IGNORE
;
7279 return minus_one_ptid
;
7282 /* Otherwise do a blocking wait. */
7283 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7284 1 /* forever */, &is_notif
);
7288 /* Wait until the remote machine stops, then return, storing status in
7289 STATUS just as `wait' would. */
7292 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7294 struct remote_state
*rs
= get_remote_state ();
7295 ptid_t event_ptid
= null_ptid
;
7297 struct stop_reply
*stop_reply
;
7301 status
->kind
= TARGET_WAITKIND_IGNORE
;
7302 status
->value
.integer
= 0;
7304 stop_reply
= queued_stop_reply (ptid
);
7305 if (stop_reply
!= NULL
)
7306 return process_stop_reply (stop_reply
, status
);
7308 if (rs
->cached_wait_status
)
7309 /* Use the cached wait status, but only once. */
7310 rs
->cached_wait_status
= 0;
7315 int forever
= ((options
& TARGET_WNOHANG
) == 0
7316 && wait_forever_enabled_p
);
7318 if (!rs
->waiting_for_stop_reply
)
7320 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
7321 return minus_one_ptid
;
7324 /* FIXME: cagney/1999-09-27: If we're in async mode we should
7325 _never_ wait for ever -> test on target_is_async_p().
7326 However, before we do that we need to ensure that the caller
7327 knows how to take the target into/out of async mode. */
7328 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7329 forever
, &is_notif
);
7331 /* GDB gets a notification. Return to core as this event is
7333 if (ret
!= -1 && is_notif
)
7334 return minus_one_ptid
;
7336 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
7337 return minus_one_ptid
;
7342 /* Assume that the target has acknowledged Ctrl-C unless we receive
7343 an 'F' or 'O' packet. */
7344 if (buf
[0] != 'F' && buf
[0] != 'O')
7345 rs
->ctrlc_pending_p
= 0;
7349 case 'E': /* Error of some sort. */
7350 /* We're out of sync with the target now. Did it continue or
7351 not? Not is more likely, so report a stop. */
7352 rs
->waiting_for_stop_reply
= 0;
7354 warning (_("Remote failure reply: %s"), buf
);
7355 status
->kind
= TARGET_WAITKIND_STOPPED
;
7356 status
->value
.sig
= GDB_SIGNAL_0
;
7358 case 'F': /* File-I/O request. */
7359 /* GDB may access the inferior memory while handling the File-I/O
7360 request, but we don't want GDB accessing memory while waiting
7361 for a stop reply. See the comments in putpkt_binary. Set
7362 waiting_for_stop_reply to 0 temporarily. */
7363 rs
->waiting_for_stop_reply
= 0;
7364 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
7365 rs
->ctrlc_pending_p
= 0;
7366 /* GDB handled the File-I/O request, and the target is running
7367 again. Keep waiting for events. */
7368 rs
->waiting_for_stop_reply
= 1;
7370 case 'N': case 'T': case 'S': case 'X': case 'W':
7372 struct stop_reply
*stop_reply
;
7374 /* There is a stop reply to handle. */
7375 rs
->waiting_for_stop_reply
= 0;
7378 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
7381 event_ptid
= process_stop_reply (stop_reply
, status
);
7384 case 'O': /* Console output. */
7385 remote_console_output (buf
+ 1);
7388 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7390 /* Zero length reply means that we tried 'S' or 'C' and the
7391 remote system doesn't support it. */
7392 target_terminal_ours_for_output ();
7394 ("Can't send signals to this remote system. %s not sent.\n",
7395 gdb_signal_to_name (rs
->last_sent_signal
));
7396 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7397 target_terminal_inferior ();
7399 strcpy (buf
, rs
->last_sent_step
? "s" : "c");
7403 /* else fallthrough */
7405 warning (_("Invalid remote reply: %s"), buf
);
7409 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7410 return minus_one_ptid
;
7411 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7413 /* Nothing interesting happened. If we're doing a non-blocking
7414 poll, we're done. Otherwise, go back to waiting. */
7415 if (options
& TARGET_WNOHANG
)
7416 return minus_one_ptid
;
7420 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7421 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7423 if (!ptid_equal (event_ptid
, null_ptid
))
7424 record_currthread (rs
, event_ptid
);
7426 event_ptid
= inferior_ptid
;
7429 /* A process exit. Invalidate our notion of current thread. */
7430 record_currthread (rs
, minus_one_ptid
);
7435 /* Wait until the remote machine stops, then return, storing status in
7436 STATUS just as `wait' would. */
7439 remote_wait (struct target_ops
*ops
,
7440 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7444 if (target_is_non_stop_p ())
7445 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7447 event_ptid
= remote_wait_as (ptid
, status
, options
);
7449 if (target_is_async_p ())
7451 /* If there are are events left in the queue tell the event loop
7453 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7454 mark_async_event_handler (remote_async_inferior_event_token
);
7460 /* Fetch a single register using a 'p' packet. */
7463 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7465 struct remote_state
*rs
= get_remote_state ();
7467 char regp
[MAX_REGISTER_SIZE
];
7470 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7473 if (reg
->pnum
== -1)
7478 p
+= hexnumstr (p
, reg
->pnum
);
7481 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7485 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7489 case PACKET_UNKNOWN
:
7492 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7493 gdbarch_register_name (get_regcache_arch (regcache
),
7498 /* If this register is unfetchable, tell the regcache. */
7501 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7505 /* Otherwise, parse and supply the value. */
7511 error (_("fetch_register_using_p: early buf termination"));
7513 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7516 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7520 /* Fetch the registers included in the target's 'g' packet. */
7523 send_g_packet (void)
7525 struct remote_state
*rs
= get_remote_state ();
7528 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7529 remote_send (&rs
->buf
, &rs
->buf_size
);
7531 /* We can get out of synch in various cases. If the first character
7532 in the buffer is not a hex character, assume that has happened
7533 and try to fetch another packet to read. */
7534 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7535 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7536 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7537 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7540 fprintf_unfiltered (gdb_stdlog
,
7541 "Bad register packet; fetching a new packet\n");
7542 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7545 buf_len
= strlen (rs
->buf
);
7547 /* Sanity check the received packet. */
7548 if (buf_len
% 2 != 0)
7549 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7555 process_g_packet (struct regcache
*regcache
)
7557 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7558 struct remote_state
*rs
= get_remote_state ();
7559 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7564 buf_len
= strlen (rs
->buf
);
7566 /* Further sanity checks, with knowledge of the architecture. */
7567 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7568 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7570 /* Save the size of the packet sent to us by the target. It is used
7571 as a heuristic when determining the max size of packets that the
7572 target can safely receive. */
7573 if (rsa
->actual_register_packet_size
== 0)
7574 rsa
->actual_register_packet_size
= buf_len
;
7576 /* If this is smaller than we guessed the 'g' packet would be,
7577 update our records. A 'g' reply that doesn't include a register's
7578 value implies either that the register is not available, or that
7579 the 'p' packet must be used. */
7580 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7582 rsa
->sizeof_g_packet
= buf_len
/ 2;
7584 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7586 if (rsa
->regs
[i
].pnum
== -1)
7589 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7590 rsa
->regs
[i
].in_g_packet
= 0;
7592 rsa
->regs
[i
].in_g_packet
= 1;
7596 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7598 /* Unimplemented registers read as all bits zero. */
7599 memset (regs
, 0, rsa
->sizeof_g_packet
);
7601 /* Reply describes registers byte by byte, each byte encoded as two
7602 hex characters. Suck them all up, then supply them to the
7603 register cacheing/storage mechanism. */
7606 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7608 if (p
[0] == 0 || p
[1] == 0)
7609 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7610 internal_error (__FILE__
, __LINE__
,
7611 _("unexpected end of 'g' packet reply"));
7613 if (p
[0] == 'x' && p
[1] == 'x')
7614 regs
[i
] = 0; /* 'x' */
7616 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7620 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7622 struct packet_reg
*r
= &rsa
->regs
[i
];
7626 if (r
->offset
* 2 >= strlen (rs
->buf
))
7627 /* This shouldn't happen - we adjusted in_g_packet above. */
7628 internal_error (__FILE__
, __LINE__
,
7629 _("unexpected end of 'g' packet reply"));
7630 else if (rs
->buf
[r
->offset
* 2] == 'x')
7632 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7633 /* The register isn't available, mark it as such (at
7634 the same time setting the value to zero). */
7635 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7638 regcache_raw_supply (regcache
, r
->regnum
,
7645 fetch_registers_using_g (struct regcache
*regcache
)
7648 process_g_packet (regcache
);
7651 /* Make the remote selected traceframe match GDB's selected
7655 set_remote_traceframe (void)
7658 struct remote_state
*rs
= get_remote_state ();
7660 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7663 /* Avoid recursion, remote_trace_find calls us again. */
7664 rs
->remote_traceframe_number
= get_traceframe_number ();
7666 newnum
= target_trace_find (tfind_number
,
7667 get_traceframe_number (), 0, 0, NULL
);
7669 /* Should not happen. If it does, all bets are off. */
7670 if (newnum
!= get_traceframe_number ())
7671 warning (_("could not set remote traceframe"));
7675 remote_fetch_registers (struct target_ops
*ops
,
7676 struct regcache
*regcache
, int regnum
)
7678 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7681 set_remote_traceframe ();
7682 set_general_thread (inferior_ptid
);
7686 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7688 gdb_assert (reg
!= NULL
);
7690 /* If this register might be in the 'g' packet, try that first -
7691 we are likely to read more than one register. If this is the
7692 first 'g' packet, we might be overly optimistic about its
7693 contents, so fall back to 'p'. */
7694 if (reg
->in_g_packet
)
7696 fetch_registers_using_g (regcache
);
7697 if (reg
->in_g_packet
)
7701 if (fetch_register_using_p (regcache
, reg
))
7704 /* This register is not available. */
7705 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7710 fetch_registers_using_g (regcache
);
7712 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7713 if (!rsa
->regs
[i
].in_g_packet
)
7714 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7716 /* This register is not available. */
7717 regcache_raw_supply (regcache
, i
, NULL
);
7721 /* Prepare to store registers. Since we may send them all (using a
7722 'G' request), we have to read out the ones we don't want to change
7726 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7728 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7730 gdb_byte buf
[MAX_REGISTER_SIZE
];
7732 /* Make sure the entire registers array is valid. */
7733 switch (packet_support (PACKET_P
))
7735 case PACKET_DISABLE
:
7736 case PACKET_SUPPORT_UNKNOWN
:
7737 /* Make sure all the necessary registers are cached. */
7738 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7739 if (rsa
->regs
[i
].in_g_packet
)
7740 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7747 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7748 packet was not recognized. */
7751 store_register_using_P (const struct regcache
*regcache
,
7752 struct packet_reg
*reg
)
7754 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7755 struct remote_state
*rs
= get_remote_state ();
7756 /* Try storing a single register. */
7757 char *buf
= rs
->buf
;
7758 gdb_byte regp
[MAX_REGISTER_SIZE
];
7761 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7764 if (reg
->pnum
== -1)
7767 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7768 p
= buf
+ strlen (buf
);
7769 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7770 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7772 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7774 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7779 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7780 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7781 case PACKET_UNKNOWN
:
7784 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7788 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7789 contents of the register cache buffer. FIXME: ignores errors. */
7792 store_registers_using_G (const struct regcache
*regcache
)
7794 struct remote_state
*rs
= get_remote_state ();
7795 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7799 /* Extract all the registers in the regcache copying them into a
7804 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7805 memset (regs
, 0, rsa
->sizeof_g_packet
);
7806 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7808 struct packet_reg
*r
= &rsa
->regs
[i
];
7811 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7815 /* Command describes registers byte by byte,
7816 each byte encoded as two hex characters. */
7819 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7821 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7823 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7824 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7825 error (_("Could not write registers; remote failure reply '%s'"),
7829 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7830 of the register cache buffer. FIXME: ignores errors. */
7833 remote_store_registers (struct target_ops
*ops
,
7834 struct regcache
*regcache
, int regnum
)
7836 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7839 set_remote_traceframe ();
7840 set_general_thread (inferior_ptid
);
7844 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7846 gdb_assert (reg
!= NULL
);
7848 /* Always prefer to store registers using the 'P' packet if
7849 possible; we often change only a small number of registers.
7850 Sometimes we change a larger number; we'd need help from a
7851 higher layer to know to use 'G'. */
7852 if (store_register_using_P (regcache
, reg
))
7855 /* For now, don't complain if we have no way to write the
7856 register. GDB loses track of unavailable registers too
7857 easily. Some day, this may be an error. We don't have
7858 any way to read the register, either... */
7859 if (!reg
->in_g_packet
)
7862 store_registers_using_G (regcache
);
7866 store_registers_using_G (regcache
);
7868 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7869 if (!rsa
->regs
[i
].in_g_packet
)
7870 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7871 /* See above for why we do not issue an error here. */
7876 /* Return the number of hex digits in num. */
7879 hexnumlen (ULONGEST num
)
7883 for (i
= 0; num
!= 0; i
++)
7886 return std::max (i
, 1);
7889 /* Set BUF to the minimum number of hex digits representing NUM. */
7892 hexnumstr (char *buf
, ULONGEST num
)
7894 int len
= hexnumlen (num
);
7896 return hexnumnstr (buf
, num
, len
);
7900 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7903 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7909 for (i
= width
- 1; i
>= 0; i
--)
7911 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7918 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7921 remote_address_masked (CORE_ADDR addr
)
7923 unsigned int address_size
= remote_address_size
;
7925 /* If "remoteaddresssize" was not set, default to target address size. */
7927 address_size
= gdbarch_addr_bit (target_gdbarch ());
7929 if (address_size
> 0
7930 && address_size
< (sizeof (ULONGEST
) * 8))
7932 /* Only create a mask when that mask can safely be constructed
7933 in a ULONGEST variable. */
7936 mask
= (mask
<< address_size
) - 1;
7942 /* Determine whether the remote target supports binary downloading.
7943 This is accomplished by sending a no-op memory write of zero length
7944 to the target at the specified address. It does not suffice to send
7945 the whole packet, since many stubs strip the eighth bit and
7946 subsequently compute a wrong checksum, which causes real havoc with
7949 NOTE: This can still lose if the serial line is not eight-bit
7950 clean. In cases like this, the user should clear "remote
7954 check_binary_download (CORE_ADDR addr
)
7956 struct remote_state
*rs
= get_remote_state ();
7958 switch (packet_support (PACKET_X
))
7960 case PACKET_DISABLE
:
7964 case PACKET_SUPPORT_UNKNOWN
:
7970 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7972 p
+= hexnumstr (p
, (ULONGEST
) 0);
7976 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7977 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7979 if (rs
->buf
[0] == '\0')
7982 fprintf_unfiltered (gdb_stdlog
,
7983 "binary downloading NOT "
7984 "supported by target\n");
7985 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7990 fprintf_unfiltered (gdb_stdlog
,
7991 "binary downloading supported by target\n");
7992 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7999 /* Helper function to resize the payload in order to try to get a good
8000 alignment. We try to write an amount of data such that the next write will
8001 start on an address aligned on REMOTE_ALIGN_WRITES. */
8004 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
8006 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
8009 /* Write memory data directly to the remote machine.
8010 This does not inform the data cache; the data cache uses this.
8011 HEADER is the starting part of the packet.
8012 MEMADDR is the address in the remote memory space.
8013 MYADDR is the address of the buffer in our space.
8014 LEN_UNITS is the number of addressable units to write.
8015 UNIT_SIZE is the length in bytes of an addressable unit.
8016 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
8017 should send data as binary ('X'), or hex-encoded ('M').
8019 The function creates packet of the form
8020 <HEADER><ADDRESS>,<LENGTH>:<DATA>
8022 where encoding of <DATA> is terminated by PACKET_FORMAT.
8024 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
8027 Return the transferred status, error or OK (an
8028 'enum target_xfer_status' value). Save the number of addressable units
8029 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
8031 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
8032 exchange between gdb and the stub could look like (?? in place of the
8038 -> $M1000,3:eeeeffffeeee#??
8042 <- eeeeffffeeeedddd */
8044 static enum target_xfer_status
8045 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
8046 const gdb_byte
*myaddr
, ULONGEST len_units
,
8047 int unit_size
, ULONGEST
*xfered_len_units
,
8048 char packet_format
, int use_length
)
8050 struct remote_state
*rs
= get_remote_state ();
8056 int payload_capacity_bytes
;
8057 int payload_length_bytes
;
8059 if (packet_format
!= 'X' && packet_format
!= 'M')
8060 internal_error (__FILE__
, __LINE__
,
8061 _("remote_write_bytes_aux: bad packet format"));
8064 return TARGET_XFER_EOF
;
8066 payload_capacity_bytes
= get_memory_write_packet_size ();
8068 /* The packet buffer will be large enough for the payload;
8069 get_memory_packet_size ensures this. */
8072 /* Compute the size of the actual payload by subtracting out the
8073 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
8075 payload_capacity_bytes
-= strlen ("$,:#NN");
8077 /* The comma won't be used. */
8078 payload_capacity_bytes
+= 1;
8079 payload_capacity_bytes
-= strlen (header
);
8080 payload_capacity_bytes
-= hexnumlen (memaddr
);
8082 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
8084 strcat (rs
->buf
, header
);
8085 p
= rs
->buf
+ strlen (header
);
8087 /* Compute a best guess of the number of bytes actually transfered. */
8088 if (packet_format
== 'X')
8090 /* Best guess at number of bytes that will fit. */
8091 todo_units
= std::min (len_units
,
8092 (ULONGEST
) payload_capacity_bytes
/ unit_size
);
8094 payload_capacity_bytes
-= hexnumlen (todo_units
);
8095 todo_units
= std::min (todo_units
, payload_capacity_bytes
/ unit_size
);
8099 /* Number of bytes that will fit. */
8101 = std::min (len_units
,
8102 (ULONGEST
) (payload_capacity_bytes
/ unit_size
) / 2);
8104 payload_capacity_bytes
-= hexnumlen (todo_units
);
8105 todo_units
= std::min (todo_units
,
8106 (payload_capacity_bytes
/ unit_size
) / 2);
8109 if (todo_units
<= 0)
8110 internal_error (__FILE__
, __LINE__
,
8111 _("minimum packet size too small to write data"));
8113 /* If we already need another packet, then try to align the end
8114 of this packet to a useful boundary. */
8115 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
8116 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
8118 /* Append "<memaddr>". */
8119 memaddr
= remote_address_masked (memaddr
);
8120 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8127 /* Append the length and retain its location and size. It may need to be
8128 adjusted once the packet body has been created. */
8130 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
8138 /* Append the packet body. */
8139 if (packet_format
== 'X')
8141 /* Binary mode. Send target system values byte by byte, in
8142 increasing byte addresses. Only escape certain critical
8144 payload_length_bytes
=
8145 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
8146 &units_written
, payload_capacity_bytes
);
8148 /* If not all TODO units fit, then we'll need another packet. Make
8149 a second try to keep the end of the packet aligned. Don't do
8150 this if the packet is tiny. */
8151 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
8155 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
8157 if (new_todo_units
!= units_written
)
8158 payload_length_bytes
=
8159 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
8160 (gdb_byte
*) p
, &units_written
,
8161 payload_capacity_bytes
);
8164 p
+= payload_length_bytes
;
8165 if (use_length
&& units_written
< todo_units
)
8167 /* Escape chars have filled up the buffer prematurely,
8168 and we have actually sent fewer units than planned.
8169 Fix-up the length field of the packet. Use the same
8170 number of characters as before. */
8171 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
8173 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
8178 /* Normal mode: Send target system values byte by byte, in
8179 increasing byte addresses. Each byte is encoded as a two hex
8181 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
8182 units_written
= todo_units
;
8185 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8186 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8188 if (rs
->buf
[0] == 'E')
8189 return TARGET_XFER_E_IO
;
8191 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
8192 send fewer units than we'd planned. */
8193 *xfered_len_units
= (ULONGEST
) units_written
;
8194 return TARGET_XFER_OK
;
8197 /* Write memory data directly to the remote machine.
8198 This does not inform the data cache; the data cache uses this.
8199 MEMADDR is the address in the remote memory space.
8200 MYADDR is the address of the buffer in our space.
8201 LEN is the number of bytes.
8203 Return the transferred status, error or OK (an
8204 'enum target_xfer_status' value). Save the number of bytes
8205 transferred in *XFERED_LEN. Only transfer a single packet. */
8207 static enum target_xfer_status
8208 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
8209 int unit_size
, ULONGEST
*xfered_len
)
8211 char *packet_format
= 0;
8213 /* Check whether the target supports binary download. */
8214 check_binary_download (memaddr
);
8216 switch (packet_support (PACKET_X
))
8219 packet_format
= "X";
8221 case PACKET_DISABLE
:
8222 packet_format
= "M";
8224 case PACKET_SUPPORT_UNKNOWN
:
8225 internal_error (__FILE__
, __LINE__
,
8226 _("remote_write_bytes: bad internal state"));
8228 internal_error (__FILE__
, __LINE__
, _("bad switch"));
8231 return remote_write_bytes_aux (packet_format
,
8232 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
8233 packet_format
[0], 1);
8236 /* Read memory data directly from the remote machine.
8237 This does not use the data cache; the data cache uses this.
8238 MEMADDR is the address in the remote memory space.
8239 MYADDR is the address of the buffer in our space.
8240 LEN_UNITS is the number of addressable memory units to read..
8241 UNIT_SIZE is the length in bytes of an addressable unit.
8243 Return the transferred status, error or OK (an
8244 'enum target_xfer_status' value). Save the number of bytes
8245 transferred in *XFERED_LEN_UNITS.
8247 See the comment of remote_write_bytes_aux for an example of
8248 memory read/write exchange between gdb and the stub. */
8250 static enum target_xfer_status
8251 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
8252 int unit_size
, ULONGEST
*xfered_len_units
)
8254 struct remote_state
*rs
= get_remote_state ();
8255 int buf_size_bytes
; /* Max size of packet output buffer. */
8260 buf_size_bytes
= get_memory_read_packet_size ();
8261 /* The packet buffer will be large enough for the payload;
8262 get_memory_packet_size ensures this. */
8264 /* Number of units that will fit. */
8265 todo_units
= std::min (len_units
,
8266 (ULONGEST
) (buf_size_bytes
/ unit_size
) / 2);
8268 /* Construct "m"<memaddr>","<len>". */
8269 memaddr
= remote_address_masked (memaddr
);
8272 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8274 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
8277 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8278 if (rs
->buf
[0] == 'E'
8279 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
8280 && rs
->buf
[3] == '\0')
8281 return TARGET_XFER_E_IO
;
8282 /* Reply describes memory byte by byte, each byte encoded as two hex
8285 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
8286 /* Return what we have. Let higher layers handle partial reads. */
8287 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
8288 return TARGET_XFER_OK
;
8291 /* Using the set of read-only target sections of remote, read live
8294 For interface/parameters/return description see target.h,
8297 static enum target_xfer_status
8298 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
8299 ULONGEST memaddr
, ULONGEST len
,
8300 int unit_size
, ULONGEST
*xfered_len
)
8302 struct target_section
*secp
;
8303 struct target_section_table
*table
;
8305 secp
= target_section_by_addr (ops
, memaddr
);
8307 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
8308 secp
->the_bfd_section
)
8311 struct target_section
*p
;
8312 ULONGEST memend
= memaddr
+ len
;
8314 table
= target_get_section_table (ops
);
8316 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
8318 if (memaddr
>= p
->addr
)
8320 if (memend
<= p
->endaddr
)
8322 /* Entire transfer is within this section. */
8323 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8326 else if (memaddr
>= p
->endaddr
)
8328 /* This section ends before the transfer starts. */
8333 /* This section overlaps the transfer. Just do half. */
8334 len
= p
->endaddr
- memaddr
;
8335 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8342 return TARGET_XFER_EOF
;
8345 /* Similar to remote_read_bytes_1, but it reads from the remote stub
8346 first if the requested memory is unavailable in traceframe.
8347 Otherwise, fall back to remote_read_bytes_1. */
8349 static enum target_xfer_status
8350 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
8351 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
8352 ULONGEST
*xfered_len
)
8355 return TARGET_XFER_EOF
;
8357 if (get_traceframe_number () != -1)
8359 VEC(mem_range_s
) *available
;
8361 /* If we fail to get the set of available memory, then the
8362 target does not support querying traceframe info, and so we
8363 attempt reading from the traceframe anyway (assuming the
8364 target implements the old QTro packet then). */
8365 if (traceframe_available_memory (&available
, memaddr
, len
))
8367 struct cleanup
*old_chain
;
8369 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
8371 if (VEC_empty (mem_range_s
, available
)
8372 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
8374 enum target_xfer_status res
;
8376 /* Don't read into the traceframe's available
8378 if (!VEC_empty (mem_range_s
, available
))
8380 LONGEST oldlen
= len
;
8382 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
8383 gdb_assert (len
<= oldlen
);
8386 do_cleanups (old_chain
);
8388 /* This goes through the topmost target again. */
8389 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8390 len
, unit_size
, xfered_len
);
8391 if (res
== TARGET_XFER_OK
)
8392 return TARGET_XFER_OK
;
8395 /* No use trying further, we know some memory starting
8396 at MEMADDR isn't available. */
8398 return TARGET_XFER_UNAVAILABLE
;
8402 /* Don't try to read more than how much is available, in
8403 case the target implements the deprecated QTro packet to
8404 cater for older GDBs (the target's knowledge of read-only
8405 sections may be outdated by now). */
8406 len
= VEC_index (mem_range_s
, available
, 0)->length
;
8408 do_cleanups (old_chain
);
8412 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8417 /* Sends a packet with content determined by the printf format string
8418 FORMAT and the remaining arguments, then gets the reply. Returns
8419 whether the packet was a success, a failure, or unknown. */
8421 static enum packet_result
remote_send_printf (const char *format
, ...)
8422 ATTRIBUTE_PRINTF (1, 2);
8424 static enum packet_result
8425 remote_send_printf (const char *format
, ...)
8427 struct remote_state
*rs
= get_remote_state ();
8428 int max_size
= get_remote_packet_size ();
8431 va_start (ap
, format
);
8434 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8435 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8437 if (putpkt (rs
->buf
) < 0)
8438 error (_("Communication problem with target."));
8441 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8443 return packet_check_result (rs
->buf
);
8447 restore_remote_timeout (void *p
)
8449 int value
= *(int *)p
;
8451 remote_timeout
= value
;
8454 /* Flash writing can take quite some time. We'll set
8455 effectively infinite timeout for flash operations.
8456 In future, we'll need to decide on a better approach. */
8457 static const int remote_flash_timeout
= 1000;
8460 remote_flash_erase (struct target_ops
*ops
,
8461 ULONGEST address
, LONGEST length
)
8463 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8464 int saved_remote_timeout
= remote_timeout
;
8465 enum packet_result ret
;
8466 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8467 &saved_remote_timeout
);
8469 remote_timeout
= remote_flash_timeout
;
8471 ret
= remote_send_printf ("vFlashErase:%s,%s",
8472 phex (address
, addr_size
),
8476 case PACKET_UNKNOWN
:
8477 error (_("Remote target does not support flash erase"));
8479 error (_("Error erasing flash with vFlashErase packet"));
8484 do_cleanups (back_to
);
8487 static enum target_xfer_status
8488 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8489 ULONGEST length
, ULONGEST
*xfered_len
,
8490 const gdb_byte
*data
)
8492 int saved_remote_timeout
= remote_timeout
;
8493 enum target_xfer_status ret
;
8494 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8495 &saved_remote_timeout
);
8497 remote_timeout
= remote_flash_timeout
;
8498 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8500 do_cleanups (back_to
);
8506 remote_flash_done (struct target_ops
*ops
)
8508 int saved_remote_timeout
= remote_timeout
;
8510 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8511 &saved_remote_timeout
);
8513 remote_timeout
= remote_flash_timeout
;
8514 ret
= remote_send_printf ("vFlashDone");
8515 do_cleanups (back_to
);
8519 case PACKET_UNKNOWN
:
8520 error (_("Remote target does not support vFlashDone"));
8522 error (_("Error finishing flash operation"));
8529 remote_files_info (struct target_ops
*ignore
)
8531 puts_filtered ("Debugging a target over a serial line.\n");
8534 /* Stuff for dealing with the packets which are part of this protocol.
8535 See comment at top of file for details. */
8537 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8538 error to higher layers. Called when a serial error is detected.
8539 The exception message is STRING, followed by a colon and a blank,
8540 the system error message for errno at function entry and final dot
8541 for output compatibility with throw_perror_with_name. */
8544 unpush_and_perror (const char *string
)
8546 int saved_errno
= errno
;
8548 remote_unpush_target ();
8549 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8550 safe_strerror (saved_errno
));
8553 /* Read a single character from the remote end. The current quit
8554 handler is overridden to avoid quitting in the middle of packet
8555 sequence, as that would break communication with the remote server.
8556 See remote_serial_quit_handler for more detail. */
8559 readchar (int timeout
)
8562 struct remote_state
*rs
= get_remote_state ();
8563 struct cleanup
*old_chain
;
8565 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8567 rs
->got_ctrlc_during_io
= 0;
8569 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8571 if (rs
->got_ctrlc_during_io
)
8574 do_cleanups (old_chain
);
8579 switch ((enum serial_rc
) ch
)
8582 remote_unpush_target ();
8583 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8586 unpush_and_perror (_("Remote communication error. "
8587 "Target disconnected."));
8589 case SERIAL_TIMEOUT
:
8595 /* Wrapper for serial_write that closes the target and throws if
8596 writing fails. The current quit handler is overridden to avoid
8597 quitting in the middle of packet sequence, as that would break
8598 communication with the remote server. See
8599 remote_serial_quit_handler for more detail. */
8602 remote_serial_write (const char *str
, int len
)
8604 struct remote_state
*rs
= get_remote_state ();
8605 struct cleanup
*old_chain
;
8607 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8609 rs
->got_ctrlc_during_io
= 0;
8611 if (serial_write (rs
->remote_desc
, str
, len
))
8613 unpush_and_perror (_("Remote communication error. "
8614 "Target disconnected."));
8617 if (rs
->got_ctrlc_during_io
)
8620 do_cleanups (old_chain
);
8623 /* Send the command in *BUF to the remote machine, and read the reply
8624 into *BUF. Report an error if we get an error reply. Resize
8625 *BUF using xrealloc if necessary to hold the result, and update
8629 remote_send (char **buf
,
8633 getpkt (buf
, sizeof_buf
, 0);
8635 if ((*buf
)[0] == 'E')
8636 error (_("Remote failure reply: %s"), *buf
);
8639 /* Return a pointer to an xmalloc'ed string representing an escaped
8640 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8641 etc. The caller is responsible for releasing the returned
8645 escape_buffer (const char *buf
, int n
)
8647 struct cleanup
*old_chain
;
8648 struct ui_file
*stb
;
8651 stb
= mem_fileopen ();
8652 old_chain
= make_cleanup_ui_file_delete (stb
);
8654 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8655 str
= ui_file_xstrdup (stb
, NULL
);
8656 do_cleanups (old_chain
);
8660 /* Display a null-terminated packet on stdout, for debugging, using C
8664 print_packet (const char *buf
)
8666 puts_filtered ("\"");
8667 fputstr_filtered (buf
, '"', gdb_stdout
);
8668 puts_filtered ("\"");
8672 putpkt (const char *buf
)
8674 return putpkt_binary (buf
, strlen (buf
));
8677 /* Send a packet to the remote machine, with error checking. The data
8678 of the packet is in BUF. The string in BUF can be at most
8679 get_remote_packet_size () - 5 to account for the $, # and checksum,
8680 and for a possible /0 if we are debugging (remote_debug) and want
8681 to print the sent packet as a string. */
8684 putpkt_binary (const char *buf
, int cnt
)
8686 struct remote_state
*rs
= get_remote_state ();
8688 unsigned char csum
= 0;
8689 char *buf2
= (char *) xmalloc (cnt
+ 6);
8690 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8696 /* Catch cases like trying to read memory or listing threads while
8697 we're waiting for a stop reply. The remote server wouldn't be
8698 ready to handle this request, so we'd hang and timeout. We don't
8699 have to worry about this in synchronous mode, because in that
8700 case it's not possible to issue a command while the target is
8701 running. This is not a problem in non-stop mode, because in that
8702 case, the stub is always ready to process serial input. */
8703 if (!target_is_non_stop_p ()
8704 && target_is_async_p ()
8705 && rs
->waiting_for_stop_reply
)
8707 error (_("Cannot execute this command while the target is running.\n"
8708 "Use the \"interrupt\" command to stop the target\n"
8709 "and then try again."));
8712 /* We're sending out a new packet. Make sure we don't look at a
8713 stale cached response. */
8714 rs
->cached_wait_status
= 0;
8716 /* Copy the packet into buffer BUF2, encapsulating it
8717 and giving it a checksum. */
8722 for (i
= 0; i
< cnt
; i
++)
8728 *p
++ = tohex ((csum
>> 4) & 0xf);
8729 *p
++ = tohex (csum
& 0xf);
8731 /* Send it over and over until we get a positive ack. */
8735 int started_error_output
= 0;
8739 struct cleanup
*old_chain
;
8743 str
= escape_buffer (buf2
, p
- buf2
);
8744 old_chain
= make_cleanup (xfree
, str
);
8745 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8746 gdb_flush (gdb_stdlog
);
8747 do_cleanups (old_chain
);
8749 remote_serial_write (buf2
, p
- buf2
);
8751 /* If this is a no acks version of the remote protocol, send the
8752 packet and move on. */
8756 /* Read until either a timeout occurs (-2) or '+' is read.
8757 Handle any notification that arrives in the mean time. */
8760 ch
= readchar (remote_timeout
);
8768 case SERIAL_TIMEOUT
:
8771 if (started_error_output
)
8773 putchar_unfiltered ('\n');
8774 started_error_output
= 0;
8783 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8784 do_cleanups (old_chain
);
8788 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8790 case SERIAL_TIMEOUT
:
8794 do_cleanups (old_chain
);
8797 break; /* Retransmit buffer. */
8801 fprintf_unfiltered (gdb_stdlog
,
8802 "Packet instead of Ack, ignoring it\n");
8803 /* It's probably an old response sent because an ACK
8804 was lost. Gobble up the packet and ack it so it
8805 doesn't get retransmitted when we resend this
8808 remote_serial_write ("+", 1);
8809 continue; /* Now, go look for +. */
8816 /* If we got a notification, handle it, and go back to looking
8818 /* We've found the start of a notification. Now
8819 collect the data. */
8820 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8825 struct cleanup
*old_chain
;
8828 str
= escape_buffer (rs
->buf
, val
);
8829 old_chain
= make_cleanup (xfree
, str
);
8830 fprintf_unfiltered (gdb_stdlog
,
8831 " Notification received: %s\n",
8833 do_cleanups (old_chain
);
8835 handle_notification (rs
->notif_state
, rs
->buf
);
8836 /* We're in sync now, rewait for the ack. */
8843 if (!started_error_output
)
8845 started_error_output
= 1;
8846 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8848 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8849 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8858 if (!started_error_output
)
8860 started_error_output
= 1;
8861 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8863 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8867 break; /* Here to retransmit. */
8871 /* This is wrong. If doing a long backtrace, the user should be
8872 able to get out next time we call QUIT, without anything as
8873 violent as interrupt_query. If we want to provide a way out of
8874 here without getting to the next QUIT, it should be based on
8875 hitting ^C twice as in remote_wait. */
8884 do_cleanups (old_chain
);
8888 /* Come here after finding the start of a frame when we expected an
8889 ack. Do our best to discard the rest of this packet. */
8898 c
= readchar (remote_timeout
);
8901 case SERIAL_TIMEOUT
:
8902 /* Nothing we can do. */
8905 /* Discard the two bytes of checksum and stop. */
8906 c
= readchar (remote_timeout
);
8908 c
= readchar (remote_timeout
);
8911 case '*': /* Run length encoding. */
8912 /* Discard the repeat count. */
8913 c
= readchar (remote_timeout
);
8918 /* A regular character. */
8924 /* Come here after finding the start of the frame. Collect the rest
8925 into *BUF, verifying the checksum, length, and handling run-length
8926 compression. NUL terminate the buffer. If there is not enough room,
8927 expand *BUF using xrealloc.
8929 Returns -1 on error, number of characters in buffer (ignoring the
8930 trailing NULL) on success. (could be extended to return one of the
8931 SERIAL status indications). */
8934 read_frame (char **buf_p
,
8941 struct remote_state
*rs
= get_remote_state ();
8948 c
= readchar (remote_timeout
);
8951 case SERIAL_TIMEOUT
:
8953 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8957 fputs_filtered ("Saw new packet start in middle of old one\n",
8959 return -1; /* Start a new packet, count retries. */
8962 unsigned char pktcsum
;
8968 check_0
= readchar (remote_timeout
);
8970 check_1
= readchar (remote_timeout
);
8972 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8975 fputs_filtered ("Timeout in checksum, retrying\n",
8979 else if (check_0
< 0 || check_1
< 0)
8982 fputs_filtered ("Communication error in checksum\n",
8987 /* Don't recompute the checksum; with no ack packets we
8988 don't have any way to indicate a packet retransmission
8993 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8994 if (csum
== pktcsum
)
8999 struct cleanup
*old_chain
;
9002 str
= escape_buffer (buf
, bc
);
9003 old_chain
= make_cleanup (xfree
, str
);
9004 fprintf_unfiltered (gdb_stdlog
,
9005 "Bad checksum, sentsum=0x%x, "
9006 "csum=0x%x, buf=%s\n",
9007 pktcsum
, csum
, str
);
9008 do_cleanups (old_chain
);
9010 /* Number of characters in buffer ignoring trailing
9014 case '*': /* Run length encoding. */
9019 c
= readchar (remote_timeout
);
9021 repeat
= c
- ' ' + 3; /* Compute repeat count. */
9023 /* The character before ``*'' is repeated. */
9025 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
9027 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
9029 /* Make some more room in the buffer. */
9030 *sizeof_buf
+= repeat
;
9031 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9035 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
9041 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
9045 if (bc
>= *sizeof_buf
- 1)
9047 /* Make some more room in the buffer. */
9049 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9060 /* Read a packet from the remote machine, with error checking, and
9061 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9062 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9063 rather than timing out; this is used (in synchronous mode) to wait
9064 for a target that is is executing user code to stop. */
9065 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
9066 don't have to change all the calls to getpkt to deal with the
9067 return value, because at the moment I don't know what the right
9068 thing to do it for those. */
9074 getpkt_sane (buf
, sizeof_buf
, forever
);
9078 /* Read a packet from the remote machine, with error checking, and
9079 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9080 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9081 rather than timing out; this is used (in synchronous mode) to wait
9082 for a target that is is executing user code to stop. If FOREVER ==
9083 0, this function is allowed to time out gracefully and return an
9084 indication of this to the caller. Otherwise return the number of
9085 bytes read. If EXPECTING_NOTIF, consider receiving a notification
9086 enough reason to return to the caller. *IS_NOTIF is an output
9087 boolean that indicates whether *BUF holds a notification or not
9088 (a regular packet). */
9091 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
9092 int expecting_notif
, int *is_notif
)
9094 struct remote_state
*rs
= get_remote_state ();
9100 /* We're reading a new response. Make sure we don't look at a
9101 previously cached response. */
9102 rs
->cached_wait_status
= 0;
9104 strcpy (*buf
, "timeout");
9107 timeout
= watchdog
> 0 ? watchdog
: -1;
9108 else if (expecting_notif
)
9109 timeout
= 0; /* There should already be a char in the buffer. If
9112 timeout
= remote_timeout
;
9116 /* Process any number of notifications, and then return when
9120 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
9122 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
9124 /* This can loop forever if the remote side sends us
9125 characters continuously, but if it pauses, we'll get
9126 SERIAL_TIMEOUT from readchar because of timeout. Then
9127 we'll count that as a retry.
9129 Note that even when forever is set, we will only wait
9130 forever prior to the start of a packet. After that, we
9131 expect characters to arrive at a brisk pace. They should
9132 show up within remote_timeout intervals. */
9134 c
= readchar (timeout
);
9135 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
9137 if (c
== SERIAL_TIMEOUT
)
9139 if (expecting_notif
)
9140 return -1; /* Don't complain, it's normal to not get
9141 anything in this case. */
9143 if (forever
) /* Watchdog went off? Kill the target. */
9145 remote_unpush_target ();
9146 throw_error (TARGET_CLOSE_ERROR
,
9147 _("Watchdog timeout has expired. "
9148 "Target detached."));
9151 fputs_filtered ("Timed out.\n", gdb_stdlog
);
9155 /* We've found the start of a packet or notification.
9156 Now collect the data. */
9157 val
= read_frame (buf
, sizeof_buf
);
9162 remote_serial_write ("-", 1);
9165 if (tries
> MAX_TRIES
)
9167 /* We have tried hard enough, and just can't receive the
9168 packet/notification. Give up. */
9169 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
9171 /* Skip the ack char if we're in no-ack mode. */
9172 if (!rs
->noack_mode
)
9173 remote_serial_write ("+", 1);
9177 /* If we got an ordinary packet, return that to our caller. */
9182 struct cleanup
*old_chain
;
9185 str
= escape_buffer (*buf
, val
);
9186 old_chain
= make_cleanup (xfree
, str
);
9187 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
9188 do_cleanups (old_chain
);
9191 /* Skip the ack char if we're in no-ack mode. */
9192 if (!rs
->noack_mode
)
9193 remote_serial_write ("+", 1);
9194 if (is_notif
!= NULL
)
9199 /* If we got a notification, handle it, and go back to looking
9203 gdb_assert (c
== '%');
9207 struct cleanup
*old_chain
;
9210 str
= escape_buffer (*buf
, val
);
9211 old_chain
= make_cleanup (xfree
, str
);
9212 fprintf_unfiltered (gdb_stdlog
,
9213 " Notification received: %s\n",
9215 do_cleanups (old_chain
);
9217 if (is_notif
!= NULL
)
9220 handle_notification (rs
->notif_state
, *buf
);
9222 /* Notifications require no acknowledgement. */
9224 if (expecting_notif
)
9231 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
9233 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
9237 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
9240 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
9244 /* Check whether EVENT is a fork event for the process specified
9245 by the pid passed in DATA, and if it is, kill the fork child. */
9248 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
9249 QUEUE_ITER (stop_reply_p
) *iter
,
9253 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
9254 int parent_pid
= *(int *) param
->input
;
9256 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
9258 struct remote_state
*rs
= get_remote_state ();
9259 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
9262 res
= remote_vkill (child_pid
, rs
);
9264 error (_("Can't kill fork child process %d"), child_pid
);
9270 /* Kill any new fork children of process PID that haven't been
9271 processed by follow_fork. */
9274 kill_new_fork_children (int pid
, struct remote_state
*rs
)
9276 struct thread_info
*thread
;
9277 struct notif_client
*notif
= ¬if_client_stop
;
9278 struct queue_iter_param param
;
9280 /* Kill the fork child threads of any threads in process PID
9281 that are stopped at a fork event. */
9282 ALL_NON_EXITED_THREADS (thread
)
9284 struct target_waitstatus
*ws
= &thread
->pending_follow
;
9286 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
9288 struct remote_state
*rs
= get_remote_state ();
9289 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
9292 res
= remote_vkill (child_pid
, rs
);
9294 error (_("Can't kill fork child process %d"), child_pid
);
9298 /* Check for any pending fork events (not reported or processed yet)
9299 in process PID and kill those fork child threads as well. */
9300 remote_notif_get_pending_events (notif
);
9302 param
.output
= NULL
;
9303 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
9304 kill_child_of_pending_fork
, ¶m
);
9308 /* Target hook to kill the current inferior. */
9311 remote_kill (struct target_ops
*ops
)
9314 int pid
= ptid_get_pid (inferior_ptid
);
9315 struct remote_state
*rs
= get_remote_state ();
9317 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
9319 /* If we're stopped while forking and we haven't followed yet,
9320 kill the child task. We need to do this before killing the
9321 parent task because if this is a vfork then the parent will
9323 kill_new_fork_children (pid
, rs
);
9325 res
= remote_vkill (pid
, rs
);
9328 target_mourn_inferior (inferior_ptid
);
9333 /* If we are in 'target remote' mode and we are killing the only
9334 inferior, then we will tell gdbserver to exit and unpush the
9336 if (res
== -1 && !remote_multi_process_p (rs
)
9337 && number_of_live_inferiors () == 1)
9341 /* We've killed the remote end, we get to mourn it. If we are
9342 not in extended mode, mourning the inferior also unpushes
9343 remote_ops from the target stack, which closes the remote
9345 target_mourn_inferior (inferior_ptid
);
9350 error (_("Can't kill process"));
9353 /* Send a kill request to the target using the 'vKill' packet. */
9356 remote_vkill (int pid
, struct remote_state
*rs
)
9358 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
9361 /* Tell the remote target to detach. */
9362 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
9364 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9366 switch (packet_ok (rs
->buf
,
9367 &remote_protocol_packets
[PACKET_vKill
]))
9373 case PACKET_UNKNOWN
:
9376 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
9380 /* Send a kill request to the target using the 'k' packet. */
9383 remote_kill_k (void)
9385 /* Catch errors so the user can quit from gdb even when we
9386 aren't on speaking terms with the remote system. */
9391 CATCH (ex
, RETURN_MASK_ERROR
)
9393 if (ex
.error
== TARGET_CLOSE_ERROR
)
9395 /* If we got an (EOF) error that caused the target
9396 to go away, then we're done, that's what we wanted.
9397 "k" is susceptible to cause a premature EOF, given
9398 that the remote server isn't actually required to
9399 reply to "k", and it can happen that it doesn't
9400 even get to reply ACK to the "k". */
9404 /* Otherwise, something went wrong. We didn't actually kill
9405 the target. Just propagate the exception, and let the
9406 user or higher layers decide what to do. */
9407 throw_exception (ex
);
9413 remote_mourn (struct target_ops
*target
)
9415 struct remote_state
*rs
= get_remote_state ();
9417 /* In 'target remote' mode with one inferior, we close the connection. */
9418 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9420 unpush_target (target
);
9422 /* remote_close takes care of doing most of the clean up. */
9423 generic_mourn_inferior ();
9427 /* In case we got here due to an error, but we're going to stay
9429 rs
->waiting_for_stop_reply
= 0;
9431 /* If the current general thread belonged to the process we just
9432 detached from or has exited, the remote side current general
9433 thread becomes undefined. Considering a case like this:
9435 - We just got here due to a detach.
9436 - The process that we're detaching from happens to immediately
9437 report a global breakpoint being hit in non-stop mode, in the
9438 same thread we had selected before.
9439 - GDB attaches to this process again.
9440 - This event happens to be the next event we handle.
9442 GDB would consider that the current general thread didn't need to
9443 be set on the stub side (with Hg), since for all it knew,
9444 GENERAL_THREAD hadn't changed.
9446 Notice that although in all-stop mode, the remote server always
9447 sets the current thread to the thread reporting the stop event,
9448 that doesn't happen in non-stop mode; in non-stop, the stub *must
9449 not* change the current thread when reporting a breakpoint hit,
9450 due to the decoupling of event reporting and event handling.
9452 To keep things simple, we always invalidate our notion of the
9454 record_currthread (rs
, minus_one_ptid
);
9456 /* Call common code to mark the inferior as not running. */
9457 generic_mourn_inferior ();
9459 if (!have_inferiors ())
9461 if (!remote_multi_process_p (rs
))
9463 /* Check whether the target is running now - some remote stubs
9464 automatically restart after kill. */
9466 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9468 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9470 /* Assume that the target has been restarted. Set
9471 inferior_ptid so that bits of core GDB realizes
9472 there's something here, e.g., so that the user can
9473 say "kill" again. */
9474 inferior_ptid
= magic_null_ptid
;
9481 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9483 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9487 extended_remote_disable_randomization (int val
)
9489 struct remote_state
*rs
= get_remote_state ();
9492 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9495 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9497 error (_("Target does not support QDisableRandomization."));
9498 if (strcmp (reply
, "OK") != 0)
9499 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9503 extended_remote_run (char *args
)
9505 struct remote_state
*rs
= get_remote_state ();
9507 const char *remote_exec_file
= get_remote_exec_file ();
9509 /* If the user has disabled vRun support, or we have detected that
9510 support is not available, do not try it. */
9511 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9514 strcpy (rs
->buf
, "vRun;");
9515 len
= strlen (rs
->buf
);
9517 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9518 error (_("Remote file name too long for run packet"));
9519 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9520 strlen (remote_exec_file
));
9522 gdb_assert (args
!= NULL
);
9525 struct cleanup
*back_to
;
9529 argv
= gdb_buildargv (args
);
9530 back_to
= make_cleanup_freeargv (argv
);
9531 for (i
= 0; argv
[i
] != NULL
; i
++)
9533 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9534 error (_("Argument list too long for run packet"));
9535 rs
->buf
[len
++] = ';';
9536 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9539 do_cleanups (back_to
);
9542 rs
->buf
[len
++] = '\0';
9545 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9547 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9550 /* We have a wait response. All is well. */
9552 case PACKET_UNKNOWN
:
9555 if (remote_exec_file
[0] == '\0')
9556 error (_("Running the default executable on the remote target failed; "
9557 "try \"set remote exec-file\"?"));
9559 error (_("Running \"%s\" on the remote target failed"),
9562 gdb_assert_not_reached (_("bad switch"));
9566 /* In the extended protocol we want to be able to do things like
9567 "run" and have them basically work as expected. So we need
9568 a special create_inferior function. We support changing the
9569 executable file and the command line arguments, but not the
9573 extended_remote_create_inferior (struct target_ops
*ops
,
9574 char *exec_file
, char *args
,
9575 char **env
, int from_tty
)
9579 struct remote_state
*rs
= get_remote_state ();
9580 const char *remote_exec_file
= get_remote_exec_file ();
9582 /* If running asynchronously, register the target file descriptor
9583 with the event loop. */
9584 if (target_can_async_p ())
9587 /* Disable address space randomization if requested (and supported). */
9588 if (extended_remote_supports_disable_randomization (ops
))
9589 extended_remote_disable_randomization (disable_randomization
);
9591 /* Now restart the remote server. */
9592 run_worked
= extended_remote_run (args
) != -1;
9595 /* vRun was not supported. Fail if we need it to do what the
9597 if (remote_exec_file
[0])
9598 error (_("Remote target does not support \"set remote exec-file\""));
9600 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9602 /* Fall back to "R". */
9603 extended_remote_restart ();
9606 if (!have_inferiors ())
9608 /* Clean up from the last time we ran, before we mark the target
9609 running again. This will mark breakpoints uninserted, and
9610 get_offsets may insert breakpoints. */
9611 init_thread_list ();
9612 init_wait_for_inferior ();
9615 /* vRun's success return is a stop reply. */
9616 stop_reply
= run_worked
? rs
->buf
: NULL
;
9617 add_current_inferior_and_thread (stop_reply
);
9619 /* Get updated offsets, if the stub uses qOffsets. */
9624 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9625 the list of conditions (in agent expression bytecode format), if any, the
9626 target needs to evaluate. The output is placed into the packet buffer
9627 started from BUF and ended at BUF_END. */
9630 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9631 struct bp_target_info
*bp_tgt
, char *buf
,
9634 struct agent_expr
*aexpr
= NULL
;
9637 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9640 buf
+= strlen (buf
);
9641 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9644 /* Send conditions to the target and free the vector. */
9646 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9649 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9650 buf
+= strlen (buf
);
9651 for (i
= 0; i
< aexpr
->len
; ++i
)
9652 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9659 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9660 struct bp_target_info
*bp_tgt
, char *buf
)
9662 struct agent_expr
*aexpr
= NULL
;
9665 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9668 buf
+= strlen (buf
);
9670 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9671 buf
+= strlen (buf
);
9673 /* Concatenate all the agent expressions that are commands into the
9676 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9679 sprintf (buf
, "X%x,", aexpr
->len
);
9680 buf
+= strlen (buf
);
9681 for (i
= 0; i
< aexpr
->len
; ++i
)
9682 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9687 /* Insert a breakpoint. On targets that have software breakpoint
9688 support, we ask the remote target to do the work; on targets
9689 which don't, we insert a traditional memory breakpoint. */
9692 remote_insert_breakpoint (struct target_ops
*ops
,
9693 struct gdbarch
*gdbarch
,
9694 struct bp_target_info
*bp_tgt
)
9696 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9697 If it succeeds, then set the support to PACKET_ENABLE. If it
9698 fails, and the user has explicitly requested the Z support then
9699 report an error, otherwise, mark it disabled and go on. */
9701 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9703 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9704 struct remote_state
*rs
;
9708 /* Make sure the remote is pointing at the right process, if
9710 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9711 set_general_process ();
9713 rs
= get_remote_state ();
9715 endbuf
= rs
->buf
+ get_remote_packet_size ();
9720 addr
= (ULONGEST
) remote_address_masked (addr
);
9721 p
+= hexnumstr (p
, addr
);
9722 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9724 if (remote_supports_cond_breakpoints (ops
))
9725 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9727 if (remote_can_run_breakpoint_commands (ops
))
9728 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9731 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9733 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9739 case PACKET_UNKNOWN
:
9744 /* If this breakpoint has target-side commands but this stub doesn't
9745 support Z0 packets, throw error. */
9746 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9747 throw_error (NOT_SUPPORTED_ERROR
, _("\
9748 Target doesn't support breakpoints that have target side commands."));
9750 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9754 remote_remove_breakpoint (struct target_ops
*ops
,
9755 struct gdbarch
*gdbarch
,
9756 struct bp_target_info
*bp_tgt
,
9757 enum remove_bp_reason reason
)
9759 CORE_ADDR addr
= bp_tgt
->placed_address
;
9760 struct remote_state
*rs
= get_remote_state ();
9762 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9765 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9767 /* Make sure the remote is pointing at the right process, if
9769 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9770 set_general_process ();
9776 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9777 p
+= hexnumstr (p
, addr
);
9778 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9781 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9783 return (rs
->buf
[0] == 'E');
9786 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
, reason
);
9789 static enum Z_packet_type
9790 watchpoint_to_Z_packet (int type
)
9795 return Z_PACKET_WRITE_WP
;
9798 return Z_PACKET_READ_WP
;
9801 return Z_PACKET_ACCESS_WP
;
9804 internal_error (__FILE__
, __LINE__
,
9805 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9810 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9811 enum target_hw_bp_type type
, struct expression
*cond
)
9813 struct remote_state
*rs
= get_remote_state ();
9814 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9816 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9818 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9821 /* Make sure the remote is pointing at the right process, if
9823 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9824 set_general_process ();
9826 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9827 p
= strchr (rs
->buf
, '\0');
9828 addr
= remote_address_masked (addr
);
9829 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9830 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9835 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9839 case PACKET_UNKNOWN
:
9844 internal_error (__FILE__
, __LINE__
,
9845 _("remote_insert_watchpoint: reached end of function"));
9849 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9850 CORE_ADDR start
, int length
)
9852 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9854 return diff
< length
;
9859 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9860 enum target_hw_bp_type type
, struct expression
*cond
)
9862 struct remote_state
*rs
= get_remote_state ();
9863 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9865 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9867 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9870 /* Make sure the remote is pointing at the right process, if
9872 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9873 set_general_process ();
9875 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9876 p
= strchr (rs
->buf
, '\0');
9877 addr
= remote_address_masked (addr
);
9878 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9879 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9881 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9883 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9886 case PACKET_UNKNOWN
:
9891 internal_error (__FILE__
, __LINE__
,
9892 _("remote_remove_watchpoint: reached end of function"));
9896 int remote_hw_watchpoint_limit
= -1;
9897 int remote_hw_watchpoint_length_limit
= -1;
9898 int remote_hw_breakpoint_limit
= -1;
9901 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9902 CORE_ADDR addr
, int len
)
9904 if (remote_hw_watchpoint_length_limit
== 0)
9906 else if (remote_hw_watchpoint_length_limit
< 0)
9908 else if (len
<= remote_hw_watchpoint_length_limit
)
9915 remote_check_watch_resources (struct target_ops
*self
,
9916 enum bptype type
, int cnt
, int ot
)
9918 if (type
== bp_hardware_breakpoint
)
9920 if (remote_hw_breakpoint_limit
== 0)
9922 else if (remote_hw_breakpoint_limit
< 0)
9924 else if (cnt
<= remote_hw_breakpoint_limit
)
9929 if (remote_hw_watchpoint_limit
== 0)
9931 else if (remote_hw_watchpoint_limit
< 0)
9935 else if (cnt
<= remote_hw_watchpoint_limit
)
9941 /* The to_stopped_by_sw_breakpoint method of target remote. */
9944 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9946 struct thread_info
*thread
= inferior_thread ();
9948 return (thread
->priv
!= NULL
9949 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9952 /* The to_supports_stopped_by_sw_breakpoint method of target
9956 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9958 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9961 /* The to_stopped_by_hw_breakpoint method of target remote. */
9964 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9966 struct thread_info
*thread
= inferior_thread ();
9968 return (thread
->priv
!= NULL
9969 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9972 /* The to_supports_stopped_by_hw_breakpoint method of target
9976 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9978 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9982 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9984 struct thread_info
*thread
= inferior_thread ();
9986 return (thread
->priv
!= NULL
9987 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9991 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9993 struct thread_info
*thread
= inferior_thread ();
9995 if (thread
->priv
!= NULL
9996 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9998 *addr_p
= thread
->priv
->watch_data_address
;
10007 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10008 struct bp_target_info
*bp_tgt
)
10010 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
10011 struct remote_state
*rs
;
10015 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10018 /* Make sure the remote is pointing at the right process, if
10020 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10021 set_general_process ();
10023 rs
= get_remote_state ();
10025 endbuf
= rs
->buf
+ get_remote_packet_size ();
10031 addr
= remote_address_masked (addr
);
10032 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10033 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10035 if (remote_supports_cond_breakpoints (self
))
10036 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
10038 if (remote_can_run_breakpoint_commands (self
))
10039 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
10042 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10044 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10047 if (rs
->buf
[1] == '.')
10049 message
= strchr (rs
->buf
+ 2, '.');
10051 error (_("Remote failure reply: %s"), message
+ 1);
10054 case PACKET_UNKNOWN
:
10059 internal_error (__FILE__
, __LINE__
,
10060 _("remote_insert_hw_breakpoint: reached end of function"));
10065 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10066 struct bp_target_info
*bp_tgt
)
10069 struct remote_state
*rs
= get_remote_state ();
10071 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10073 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10076 /* Make sure the remote is pointing at the right process, if
10078 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10079 set_general_process ();
10085 addr
= remote_address_masked (bp_tgt
->placed_address
);
10086 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10087 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10090 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10092 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10095 case PACKET_UNKNOWN
:
10100 internal_error (__FILE__
, __LINE__
,
10101 _("remote_remove_hw_breakpoint: reached end of function"));
10104 /* Verify memory using the "qCRC:" request. */
10107 remote_verify_memory (struct target_ops
*ops
,
10108 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
10110 struct remote_state
*rs
= get_remote_state ();
10111 unsigned long host_crc
, target_crc
;
10114 /* It doesn't make sense to use qCRC if the remote target is
10115 connected but not running. */
10116 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
10118 enum packet_result result
;
10120 /* Make sure the remote is pointing at the right process. */
10121 set_general_process ();
10123 /* FIXME: assumes lma can fit into long. */
10124 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
10125 (long) lma
, (long) size
);
10128 /* Be clever; compute the host_crc before waiting for target
10130 host_crc
= xcrc32 (data
, size
, 0xffffffff);
10132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10134 result
= packet_ok (rs
->buf
,
10135 &remote_protocol_packets
[PACKET_qCRC
]);
10136 if (result
== PACKET_ERROR
)
10138 else if (result
== PACKET_OK
)
10140 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
10141 target_crc
= target_crc
* 16 + fromhex (*tmp
);
10143 return (host_crc
== target_crc
);
10147 return simple_verify_memory (ops
, data
, lma
, size
);
10150 /* compare-sections command
10152 With no arguments, compares each loadable section in the exec bfd
10153 with the same memory range on the target, and reports mismatches.
10154 Useful for verifying the image on the target against the exec file. */
10157 compare_sections_command (char *args
, int from_tty
)
10160 struct cleanup
*old_chain
;
10161 gdb_byte
*sectdata
;
10162 const char *sectname
;
10163 bfd_size_type size
;
10166 int mismatched
= 0;
10171 error (_("command cannot be used without an exec file"));
10173 /* Make sure the remote is pointing at the right process. */
10174 set_general_process ();
10176 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
10182 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10184 if (!(s
->flags
& SEC_LOAD
))
10185 continue; /* Skip non-loadable section. */
10187 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
10188 continue; /* Skip writeable sections */
10190 size
= bfd_get_section_size (s
);
10192 continue; /* Skip zero-length section. */
10194 sectname
= bfd_get_section_name (exec_bfd
, s
);
10195 if (args
&& strcmp (args
, sectname
) != 0)
10196 continue; /* Not the section selected by user. */
10198 matched
= 1; /* Do this section. */
10201 sectdata
= (gdb_byte
*) xmalloc (size
);
10202 old_chain
= make_cleanup (xfree
, sectdata
);
10203 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
10205 res
= target_verify_memory (sectdata
, lma
, size
);
10208 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
10209 paddress (target_gdbarch (), lma
),
10210 paddress (target_gdbarch (), lma
+ size
));
10212 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
10213 paddress (target_gdbarch (), lma
),
10214 paddress (target_gdbarch (), lma
+ size
));
10216 printf_filtered ("matched.\n");
10219 printf_filtered ("MIS-MATCHED!\n");
10223 do_cleanups (old_chain
);
10225 if (mismatched
> 0)
10226 warning (_("One or more sections of the target image does not match\n\
10227 the loaded file\n"));
10228 if (args
&& !matched
)
10229 printf_filtered (_("No loaded section named '%s'.\n"), args
);
10232 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
10233 into remote target. The number of bytes written to the remote
10234 target is returned, or -1 for error. */
10236 static enum target_xfer_status
10237 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
10238 const char *annex
, const gdb_byte
*writebuf
,
10239 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
10240 struct packet_config
*packet
)
10244 struct remote_state
*rs
= get_remote_state ();
10245 int max_size
= get_memory_write_packet_size ();
10247 if (packet
->support
== PACKET_DISABLE
)
10248 return TARGET_XFER_E_IO
;
10250 /* Insert header. */
10251 i
= snprintf (rs
->buf
, max_size
,
10252 "qXfer:%s:write:%s:%s:",
10253 object_name
, annex
? annex
: "",
10254 phex_nz (offset
, sizeof offset
));
10255 max_size
-= (i
+ 1);
10257 /* Escape as much data as fits into rs->buf. */
10258 buf_len
= remote_escape_output
10259 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
10261 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
10262 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10263 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10264 return TARGET_XFER_E_IO
;
10266 unpack_varlen_hex (rs
->buf
, &n
);
10269 return TARGET_XFER_OK
;
10272 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
10273 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
10274 number of bytes read is returned, or 0 for EOF, or -1 for error.
10275 The number of bytes read may be less than LEN without indicating an
10276 EOF. PACKET is checked and updated to indicate whether the remote
10277 target supports this object. */
10279 static enum target_xfer_status
10280 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
10282 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
10283 ULONGEST
*xfered_len
,
10284 struct packet_config
*packet
)
10286 struct remote_state
*rs
= get_remote_state ();
10287 LONGEST i
, n
, packet_len
;
10289 if (packet
->support
== PACKET_DISABLE
)
10290 return TARGET_XFER_E_IO
;
10292 /* Check whether we've cached an end-of-object packet that matches
10294 if (rs
->finished_object
)
10296 if (strcmp (object_name
, rs
->finished_object
) == 0
10297 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
10298 && offset
== rs
->finished_offset
)
10299 return TARGET_XFER_EOF
;
10302 /* Otherwise, we're now reading something different. Discard
10304 xfree (rs
->finished_object
);
10305 xfree (rs
->finished_annex
);
10306 rs
->finished_object
= NULL
;
10307 rs
->finished_annex
= NULL
;
10310 /* Request only enough to fit in a single packet. The actual data
10311 may not, since we don't know how much of it will need to be escaped;
10312 the target is free to respond with slightly less data. We subtract
10313 five to account for the response type and the protocol frame. */
10314 n
= std::min
<LONGEST
> (get_remote_packet_size () - 5, len
);
10315 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
10316 object_name
, annex
? annex
: "",
10317 phex_nz (offset
, sizeof offset
),
10318 phex_nz (n
, sizeof n
));
10319 i
= putpkt (rs
->buf
);
10321 return TARGET_XFER_E_IO
;
10324 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10325 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10326 return TARGET_XFER_E_IO
;
10328 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
10329 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
10331 /* 'm' means there is (or at least might be) more data after this
10332 batch. That does not make sense unless there's at least one byte
10333 of data in this reply. */
10334 if (rs
->buf
[0] == 'm' && packet_len
== 1)
10335 error (_("Remote qXfer reply contained no data."));
10337 /* Got some data. */
10338 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
10339 packet_len
- 1, readbuf
, n
);
10341 /* 'l' is an EOF marker, possibly including a final block of data,
10342 or possibly empty. If we have the final block of a non-empty
10343 object, record this fact to bypass a subsequent partial read. */
10344 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
10346 rs
->finished_object
= xstrdup (object_name
);
10347 rs
->finished_annex
= xstrdup (annex
? annex
: "");
10348 rs
->finished_offset
= offset
+ i
;
10352 return TARGET_XFER_EOF
;
10356 return TARGET_XFER_OK
;
10360 static enum target_xfer_status
10361 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
10362 const char *annex
, gdb_byte
*readbuf
,
10363 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
10364 ULONGEST
*xfered_len
)
10366 struct remote_state
*rs
;
10370 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
10372 set_remote_traceframe ();
10373 set_general_thread (inferior_ptid
);
10375 rs
= get_remote_state ();
10377 /* Handle memory using the standard memory routines. */
10378 if (object
== TARGET_OBJECT_MEMORY
)
10380 /* If the remote target is connected but not running, we should
10381 pass this request down to a lower stratum (e.g. the executable
10383 if (!target_has_execution
)
10384 return TARGET_XFER_EOF
;
10386 if (writebuf
!= NULL
)
10387 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
10390 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
10394 /* Handle SPU memory using qxfer packets. */
10395 if (object
== TARGET_OBJECT_SPU
)
10398 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
10399 xfered_len
, &remote_protocol_packets
10400 [PACKET_qXfer_spu_read
]);
10402 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
10403 xfered_len
, &remote_protocol_packets
10404 [PACKET_qXfer_spu_write
]);
10407 /* Handle extra signal info using qxfer packets. */
10408 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10411 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10412 xfered_len
, &remote_protocol_packets
10413 [PACKET_qXfer_siginfo_read
]);
10415 return remote_write_qxfer (ops
, "siginfo", annex
,
10416 writebuf
, offset
, len
, xfered_len
,
10417 &remote_protocol_packets
10418 [PACKET_qXfer_siginfo_write
]);
10421 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10424 return remote_read_qxfer (ops
, "statictrace", annex
,
10425 readbuf
, offset
, len
, xfered_len
,
10426 &remote_protocol_packets
10427 [PACKET_qXfer_statictrace_read
]);
10429 return TARGET_XFER_E_IO
;
10432 /* Only handle flash writes. */
10433 if (writebuf
!= NULL
)
10437 case TARGET_OBJECT_FLASH
:
10438 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10442 return TARGET_XFER_E_IO
;
10446 /* Map pre-existing objects onto letters. DO NOT do this for new
10447 objects!!! Instead specify new query packets. */
10450 case TARGET_OBJECT_AVR
:
10454 case TARGET_OBJECT_AUXV
:
10455 gdb_assert (annex
== NULL
);
10456 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10458 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10460 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10461 return remote_read_qxfer
10462 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10463 &remote_protocol_packets
[PACKET_qXfer_features
]);
10465 case TARGET_OBJECT_LIBRARIES
:
10466 return remote_read_qxfer
10467 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10468 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10470 case TARGET_OBJECT_LIBRARIES_SVR4
:
10471 return remote_read_qxfer
10472 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10473 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10475 case TARGET_OBJECT_MEMORY_MAP
:
10476 gdb_assert (annex
== NULL
);
10477 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10479 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10481 case TARGET_OBJECT_OSDATA
:
10482 /* Should only get here if we're connected. */
10483 gdb_assert (rs
->remote_desc
);
10484 return remote_read_qxfer
10485 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10486 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10488 case TARGET_OBJECT_THREADS
:
10489 gdb_assert (annex
== NULL
);
10490 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10492 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10494 case TARGET_OBJECT_TRACEFRAME_INFO
:
10495 gdb_assert (annex
== NULL
);
10496 return remote_read_qxfer
10497 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10498 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10500 case TARGET_OBJECT_FDPIC
:
10501 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10503 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10505 case TARGET_OBJECT_OPENVMS_UIB
:
10506 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10508 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10510 case TARGET_OBJECT_BTRACE
:
10511 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10513 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10515 case TARGET_OBJECT_BTRACE_CONF
:
10516 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10518 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10520 case TARGET_OBJECT_EXEC_FILE
:
10521 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10523 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10526 return TARGET_XFER_E_IO
;
10529 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10530 large enough let the caller deal with it. */
10531 if (len
< get_remote_packet_size ())
10532 return TARGET_XFER_E_IO
;
10533 len
= get_remote_packet_size ();
10535 /* Except for querying the minimum buffer size, target must be open. */
10536 if (!rs
->remote_desc
)
10537 error (_("remote query is only available after target open"));
10539 gdb_assert (annex
!= NULL
);
10540 gdb_assert (readbuf
!= NULL
);
10544 *p2
++ = query_type
;
10546 /* We used one buffer char for the remote protocol q command and
10547 another for the query type. As the remote protocol encapsulation
10548 uses 4 chars plus one extra in case we are debugging
10549 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10552 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10554 /* Bad caller may have sent forbidden characters. */
10555 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10560 gdb_assert (annex
[i
] == '\0');
10562 i
= putpkt (rs
->buf
);
10564 return TARGET_XFER_E_IO
;
10566 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10567 strcpy ((char *) readbuf
, rs
->buf
);
10569 *xfered_len
= strlen ((char *) readbuf
);
10570 return TARGET_XFER_OK
;
10573 /* Implementation of to_get_memory_xfer_limit. */
10576 remote_get_memory_xfer_limit (struct target_ops
*ops
)
10578 return get_memory_write_packet_size ();
10582 remote_search_memory (struct target_ops
* ops
,
10583 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10584 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10585 CORE_ADDR
*found_addrp
)
10587 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10588 struct remote_state
*rs
= get_remote_state ();
10589 int max_size
= get_memory_write_packet_size ();
10590 struct packet_config
*packet
=
10591 &remote_protocol_packets
[PACKET_qSearch_memory
];
10592 /* Number of packet bytes used to encode the pattern;
10593 this could be more than PATTERN_LEN due to escape characters. */
10594 int escaped_pattern_len
;
10595 /* Amount of pattern that was encodable in the packet. */
10596 int used_pattern_len
;
10599 ULONGEST found_addr
;
10601 /* Don't go to the target if we don't have to.
10602 This is done before checking packet->support to avoid the possibility that
10603 a success for this edge case means the facility works in general. */
10604 if (pattern_len
> search_space_len
)
10606 if (pattern_len
== 0)
10608 *found_addrp
= start_addr
;
10612 /* If we already know the packet isn't supported, fall back to the simple
10613 way of searching memory. */
10615 if (packet_config_support (packet
) == PACKET_DISABLE
)
10617 /* Target doesn't provided special support, fall back and use the
10618 standard support (copy memory and do the search here). */
10619 return simple_search_memory (ops
, start_addr
, search_space_len
,
10620 pattern
, pattern_len
, found_addrp
);
10623 /* Make sure the remote is pointing at the right process. */
10624 set_general_process ();
10626 /* Insert header. */
10627 i
= snprintf (rs
->buf
, max_size
,
10628 "qSearch:memory:%s;%s;",
10629 phex_nz (start_addr
, addr_size
),
10630 phex_nz (search_space_len
, sizeof (search_space_len
)));
10631 max_size
-= (i
+ 1);
10633 /* Escape as much data as fits into rs->buf. */
10634 escaped_pattern_len
=
10635 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10636 &used_pattern_len
, max_size
);
10638 /* Bail if the pattern is too large. */
10639 if (used_pattern_len
!= pattern_len
)
10640 error (_("Pattern is too large to transmit to remote target."));
10642 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10643 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10644 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10646 /* The request may not have worked because the command is not
10647 supported. If so, fall back to the simple way. */
10648 if (packet
->support
== PACKET_DISABLE
)
10650 return simple_search_memory (ops
, start_addr
, search_space_len
,
10651 pattern
, pattern_len
, found_addrp
);
10656 if (rs
->buf
[0] == '0')
10658 else if (rs
->buf
[0] == '1')
10661 if (rs
->buf
[1] != ',')
10662 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10663 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10664 *found_addrp
= found_addr
;
10667 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10673 remote_rcmd (struct target_ops
*self
, const char *command
,
10674 struct ui_file
*outbuf
)
10676 struct remote_state
*rs
= get_remote_state ();
10679 if (!rs
->remote_desc
)
10680 error (_("remote rcmd is only available after target open"));
10682 /* Send a NULL command across as an empty command. */
10683 if (command
== NULL
)
10686 /* The query prefix. */
10687 strcpy (rs
->buf
, "qRcmd,");
10688 p
= strchr (rs
->buf
, '\0');
10690 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10691 > get_remote_packet_size ())
10692 error (_("\"monitor\" command ``%s'' is too long."), command
);
10694 /* Encode the actual command. */
10695 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10697 if (putpkt (rs
->buf
) < 0)
10698 error (_("Communication problem with target."));
10700 /* get/display the response */
10705 /* XXX - see also remote_get_noisy_reply(). */
10706 QUIT
; /* Allow user to bail out with ^C. */
10708 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10710 /* Timeout. Continue to (try to) read responses.
10711 This is better than stopping with an error, assuming the stub
10712 is still executing the (long) monitor command.
10713 If needed, the user can interrupt gdb using C-c, obtaining
10714 an effect similar to stop on timeout. */
10718 if (buf
[0] == '\0')
10719 error (_("Target does not support this command."));
10720 if (buf
[0] == 'O' && buf
[1] != 'K')
10722 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10725 if (strcmp (buf
, "OK") == 0)
10727 if (strlen (buf
) == 3 && buf
[0] == 'E'
10728 && isdigit (buf
[1]) && isdigit (buf
[2]))
10730 error (_("Protocol error with Rcmd"));
10732 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10734 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10736 fputc_unfiltered (c
, outbuf
);
10742 static VEC(mem_region_s
) *
10743 remote_memory_map (struct target_ops
*ops
)
10745 VEC(mem_region_s
) *result
= NULL
;
10746 char *text
= target_read_stralloc (¤t_target
,
10747 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10751 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10753 result
= parse_memory_map (text
);
10754 do_cleanups (back_to
);
10761 packet_command (char *args
, int from_tty
)
10763 struct remote_state
*rs
= get_remote_state ();
10765 if (!rs
->remote_desc
)
10766 error (_("command can only be used with remote target"));
10769 error (_("remote-packet command requires packet text as argument"));
10771 puts_filtered ("sending: ");
10772 print_packet (args
);
10773 puts_filtered ("\n");
10776 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10777 puts_filtered ("received: ");
10778 print_packet (rs
->buf
);
10779 puts_filtered ("\n");
10783 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10785 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10787 static void threadset_test_cmd (char *cmd
, int tty
);
10789 static void threadalive_test (char *cmd
, int tty
);
10791 static void threadlist_test_cmd (char *cmd
, int tty
);
10793 int get_and_display_threadinfo (threadref
*ref
);
10795 static void threadinfo_test_cmd (char *cmd
, int tty
);
10797 static int thread_display_step (threadref
*ref
, void *context
);
10799 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10801 static void init_remote_threadtests (void);
10803 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10806 threadset_test_cmd (char *cmd
, int tty
)
10808 int sample_thread
= SAMPLE_THREAD
;
10810 printf_filtered (_("Remote threadset test\n"));
10811 set_general_thread (sample_thread
);
10816 threadalive_test (char *cmd
, int tty
)
10818 int sample_thread
= SAMPLE_THREAD
;
10819 int pid
= ptid_get_pid (inferior_ptid
);
10820 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10822 if (remote_thread_alive (ptid
))
10823 printf_filtered ("PASS: Thread alive test\n");
10825 printf_filtered ("FAIL: Thread alive test\n");
10828 void output_threadid (char *title
, threadref
*ref
);
10831 output_threadid (char *title
, threadref
*ref
)
10835 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10837 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10841 threadlist_test_cmd (char *cmd
, int tty
)
10844 threadref nextthread
;
10845 int done
, result_count
;
10846 threadref threadlist
[3];
10848 printf_filtered ("Remote Threadlist test\n");
10849 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10850 &result_count
, &threadlist
[0]))
10851 printf_filtered ("FAIL: threadlist test\n");
10854 threadref
*scan
= threadlist
;
10855 threadref
*limit
= scan
+ result_count
;
10857 while (scan
< limit
)
10858 output_threadid (" thread ", scan
++);
10863 display_thread_info (struct gdb_ext_thread_info
*info
)
10865 output_threadid ("Threadid: ", &info
->threadid
);
10866 printf_filtered ("Name: %s\n ", info
->shortname
);
10867 printf_filtered ("State: %s\n", info
->display
);
10868 printf_filtered ("other: %s\n\n", info
->more_display
);
10872 get_and_display_threadinfo (threadref
*ref
)
10876 struct gdb_ext_thread_info threadinfo
;
10878 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10879 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10880 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10881 display_thread_info (&threadinfo
);
10886 threadinfo_test_cmd (char *cmd
, int tty
)
10888 int athread
= SAMPLE_THREAD
;
10892 int_to_threadref (&thread
, athread
);
10893 printf_filtered ("Remote Threadinfo test\n");
10894 if (!get_and_display_threadinfo (&thread
))
10895 printf_filtered ("FAIL cannot get thread info\n");
10899 thread_display_step (threadref
*ref
, void *context
)
10901 /* output_threadid(" threadstep ",ref); *//* simple test */
10902 return get_and_display_threadinfo (ref
);
10906 threadlist_update_test_cmd (char *cmd
, int tty
)
10908 printf_filtered ("Remote Threadlist update test\n");
10909 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10913 init_remote_threadtests (void)
10915 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10916 _("Fetch and print the remote list of "
10917 "thread identifiers, one pkt only"));
10918 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10919 _("Fetch and display info about one thread"));
10920 add_com ("tset", class_obscure
, threadset_test_cmd
,
10921 _("Test setting to a different thread"));
10922 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10923 _("Iterate through updating all remote thread info"));
10924 add_com ("talive", class_obscure
, threadalive_test
,
10925 _(" Remote thread alive test "));
10930 /* Convert a thread ID to a string. Returns the string in a static
10934 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10936 static char buf
[64];
10937 struct remote_state
*rs
= get_remote_state ();
10939 if (ptid_equal (ptid
, null_ptid
))
10940 return normal_pid_to_str (ptid
);
10941 else if (ptid_is_pid (ptid
))
10943 /* Printing an inferior target id. */
10945 /* When multi-process extensions are off, there's no way in the
10946 remote protocol to know the remote process id, if there's any
10947 at all. There's one exception --- when we're connected with
10948 target extended-remote, and we manually attached to a process
10949 with "attach PID". We don't record anywhere a flag that
10950 allows us to distinguish that case from the case of
10951 connecting with extended-remote and the stub already being
10952 attached to a process, and reporting yes to qAttached, hence
10953 no smart special casing here. */
10954 if (!remote_multi_process_p (rs
))
10956 xsnprintf (buf
, sizeof buf
, "Remote target");
10960 return normal_pid_to_str (ptid
);
10964 if (ptid_equal (magic_null_ptid
, ptid
))
10965 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10966 else if (remote_multi_process_p (rs
))
10967 if (ptid_get_lwp (ptid
) == 0)
10968 return normal_pid_to_str (ptid
);
10970 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10971 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10973 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10974 ptid_get_lwp (ptid
));
10979 /* Get the address of the thread local variable in OBJFILE which is
10980 stored at OFFSET within the thread local storage for thread PTID. */
10983 remote_get_thread_local_address (struct target_ops
*ops
,
10984 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10986 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10988 struct remote_state
*rs
= get_remote_state ();
10990 char *endp
= rs
->buf
+ get_remote_packet_size ();
10991 enum packet_result result
;
10993 strcpy (p
, "qGetTLSAddr:");
10995 p
= write_ptid (p
, endp
, ptid
);
10997 p
+= hexnumstr (p
, offset
);
10999 p
+= hexnumstr (p
, lm
);
11003 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11004 result
= packet_ok (rs
->buf
,
11005 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
11006 if (result
== PACKET_OK
)
11010 unpack_varlen_hex (rs
->buf
, &result
);
11013 else if (result
== PACKET_UNKNOWN
)
11014 throw_error (TLS_GENERIC_ERROR
,
11015 _("Remote target doesn't support qGetTLSAddr packet"));
11017 throw_error (TLS_GENERIC_ERROR
,
11018 _("Remote target failed to process qGetTLSAddr request"));
11021 throw_error (TLS_GENERIC_ERROR
,
11022 _("TLS not supported or disabled on this target"));
11027 /* Provide thread local base, i.e. Thread Information Block address.
11028 Returns 1 if ptid is found and thread_local_base is non zero. */
11031 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
11033 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
11035 struct remote_state
*rs
= get_remote_state ();
11037 char *endp
= rs
->buf
+ get_remote_packet_size ();
11038 enum packet_result result
;
11040 strcpy (p
, "qGetTIBAddr:");
11042 p
= write_ptid (p
, endp
, ptid
);
11046 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11047 result
= packet_ok (rs
->buf
,
11048 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
11049 if (result
== PACKET_OK
)
11053 unpack_varlen_hex (rs
->buf
, &result
);
11055 *addr
= (CORE_ADDR
) result
;
11058 else if (result
== PACKET_UNKNOWN
)
11059 error (_("Remote target doesn't support qGetTIBAddr packet"));
11061 error (_("Remote target failed to process qGetTIBAddr request"));
11064 error (_("qGetTIBAddr not supported or disabled on this target"));
11069 /* Support for inferring a target description based on the current
11070 architecture and the size of a 'g' packet. While the 'g' packet
11071 can have any size (since optional registers can be left off the
11072 end), some sizes are easily recognizable given knowledge of the
11073 approximate architecture. */
11075 struct remote_g_packet_guess
11078 const struct target_desc
*tdesc
;
11080 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
11081 DEF_VEC_O(remote_g_packet_guess_s
);
11083 struct remote_g_packet_data
11085 VEC(remote_g_packet_guess_s
) *guesses
;
11088 static struct gdbarch_data
*remote_g_packet_data_handle
;
11091 remote_g_packet_data_init (struct obstack
*obstack
)
11093 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
11097 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
11098 const struct target_desc
*tdesc
)
11100 struct remote_g_packet_data
*data
11101 = ((struct remote_g_packet_data
*)
11102 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
11103 struct remote_g_packet_guess new_guess
, *guess
;
11106 gdb_assert (tdesc
!= NULL
);
11109 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11111 if (guess
->bytes
== bytes
)
11112 internal_error (__FILE__
, __LINE__
,
11113 _("Duplicate g packet description added for size %d"),
11116 new_guess
.bytes
= bytes
;
11117 new_guess
.tdesc
= tdesc
;
11118 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
11121 /* Return 1 if remote_read_description would do anything on this target
11122 and architecture, 0 otherwise. */
11125 remote_read_description_p (struct target_ops
*target
)
11127 struct remote_g_packet_data
*data
11128 = ((struct remote_g_packet_data
*)
11129 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11131 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11137 static const struct target_desc
*
11138 remote_read_description (struct target_ops
*target
)
11140 struct remote_g_packet_data
*data
11141 = ((struct remote_g_packet_data
*)
11142 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11144 /* Do not try this during initial connection, when we do not know
11145 whether there is a running but stopped thread. */
11146 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
11147 return target
->beneath
->to_read_description (target
->beneath
);
11149 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11151 struct remote_g_packet_guess
*guess
;
11153 int bytes
= send_g_packet ();
11156 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11158 if (guess
->bytes
== bytes
)
11159 return guess
->tdesc
;
11161 /* We discard the g packet. A minor optimization would be to
11162 hold on to it, and fill the register cache once we have selected
11163 an architecture, but it's too tricky to do safely. */
11166 return target
->beneath
->to_read_description (target
->beneath
);
11169 /* Remote file transfer support. This is host-initiated I/O, not
11170 target-initiated; for target-initiated, see remote-fileio.c. */
11172 /* If *LEFT is at least the length of STRING, copy STRING to
11173 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11174 decrease *LEFT. Otherwise raise an error. */
11177 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
11179 int len
= strlen (string
);
11182 error (_("Packet too long for target."));
11184 memcpy (*buffer
, string
, len
);
11188 /* NUL-terminate the buffer as a convenience, if there is
11194 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
11195 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11196 decrease *LEFT. Otherwise raise an error. */
11199 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
11202 if (2 * len
> *left
)
11203 error (_("Packet too long for target."));
11205 bin2hex (bytes
, *buffer
, len
);
11206 *buffer
+= 2 * len
;
11209 /* NUL-terminate the buffer as a convenience, if there is
11215 /* If *LEFT is large enough, convert VALUE to hex and add it to
11216 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11217 decrease *LEFT. Otherwise raise an error. */
11220 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
11222 int len
= hexnumlen (value
);
11225 error (_("Packet too long for target."));
11227 hexnumstr (*buffer
, value
);
11231 /* NUL-terminate the buffer as a convenience, if there is
11237 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
11238 value, *REMOTE_ERRNO to the remote error number or zero if none
11239 was included, and *ATTACHMENT to point to the start of the annex
11240 if any. The length of the packet isn't needed here; there may
11241 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
11243 Return 0 if the packet could be parsed, -1 if it could not. If
11244 -1 is returned, the other variables may not be initialized. */
11247 remote_hostio_parse_result (char *buffer
, int *retcode
,
11248 int *remote_errno
, char **attachment
)
11253 *attachment
= NULL
;
11255 if (buffer
[0] != 'F')
11259 *retcode
= strtol (&buffer
[1], &p
, 16);
11260 if (errno
!= 0 || p
== &buffer
[1])
11263 /* Check for ",errno". */
11267 *remote_errno
= strtol (p
+ 1, &p2
, 16);
11268 if (errno
!= 0 || p
+ 1 == p2
)
11273 /* Check for ";attachment". If there is no attachment, the
11274 packet should end here. */
11277 *attachment
= p
+ 1;
11280 else if (*p
== '\0')
11286 /* Send a prepared I/O packet to the target and read its response.
11287 The prepared packet is in the global RS->BUF before this function
11288 is called, and the answer is there when we return.
11290 COMMAND_BYTES is the length of the request to send, which may include
11291 binary data. WHICH_PACKET is the packet configuration to check
11292 before attempting a packet. If an error occurs, *REMOTE_ERRNO
11293 is set to the error number and -1 is returned. Otherwise the value
11294 returned by the function is returned.
11296 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
11297 attachment is expected; an error will be reported if there's a
11298 mismatch. If one is found, *ATTACHMENT will be set to point into
11299 the packet buffer and *ATTACHMENT_LEN will be set to the
11300 attachment's length. */
11303 remote_hostio_send_command (int command_bytes
, int which_packet
,
11304 int *remote_errno
, char **attachment
,
11305 int *attachment_len
)
11307 struct remote_state
*rs
= get_remote_state ();
11308 int ret
, bytes_read
;
11309 char *attachment_tmp
;
11311 if (!rs
->remote_desc
11312 || packet_support (which_packet
) == PACKET_DISABLE
)
11314 *remote_errno
= FILEIO_ENOSYS
;
11318 putpkt_binary (rs
->buf
, command_bytes
);
11319 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
11321 /* If it timed out, something is wrong. Don't try to parse the
11323 if (bytes_read
< 0)
11325 *remote_errno
= FILEIO_EINVAL
;
11329 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
11332 *remote_errno
= FILEIO_EINVAL
;
11334 case PACKET_UNKNOWN
:
11335 *remote_errno
= FILEIO_ENOSYS
;
11341 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
11344 *remote_errno
= FILEIO_EINVAL
;
11348 /* Make sure we saw an attachment if and only if we expected one. */
11349 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
11350 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
11352 *remote_errno
= FILEIO_EINVAL
;
11356 /* If an attachment was found, it must point into the packet buffer;
11357 work out how many bytes there were. */
11358 if (attachment_tmp
!= NULL
)
11360 *attachment
= attachment_tmp
;
11361 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
11367 /* Invalidate the readahead cache. */
11370 readahead_cache_invalidate (void)
11372 struct remote_state
*rs
= get_remote_state ();
11374 rs
->readahead_cache
.fd
= -1;
11377 /* Invalidate the readahead cache if it is holding data for FD. */
11380 readahead_cache_invalidate_fd (int fd
)
11382 struct remote_state
*rs
= get_remote_state ();
11384 if (rs
->readahead_cache
.fd
== fd
)
11385 rs
->readahead_cache
.fd
= -1;
11388 /* Set the filesystem remote_hostio functions that take FILENAME
11389 arguments will use. Return 0 on success, or -1 if an error
11390 occurs (and set *REMOTE_ERRNO). */
11393 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
11395 struct remote_state
*rs
= get_remote_state ();
11396 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
11398 int left
= get_remote_packet_size () - 1;
11402 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11405 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11408 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11410 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11411 remote_buffer_add_string (&p
, &left
, arg
);
11413 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11414 remote_errno
, NULL
, NULL
);
11416 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11420 rs
->fs_pid
= required_pid
;
11425 /* Implementation of to_fileio_open. */
11428 remote_hostio_open (struct target_ops
*self
,
11429 struct inferior
*inf
, const char *filename
,
11430 int flags
, int mode
, int warn_if_slow
,
11433 struct remote_state
*rs
= get_remote_state ();
11435 int left
= get_remote_packet_size () - 1;
11439 static int warning_issued
= 0;
11441 printf_unfiltered (_("Reading %s from remote target...\n"),
11444 if (!warning_issued
)
11446 warning (_("File transfers from remote targets can be slow."
11447 " Use \"set sysroot\" to access files locally"
11449 warning_issued
= 1;
11453 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11456 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11458 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11459 strlen (filename
));
11460 remote_buffer_add_string (&p
, &left
, ",");
11462 remote_buffer_add_int (&p
, &left
, flags
);
11463 remote_buffer_add_string (&p
, &left
, ",");
11465 remote_buffer_add_int (&p
, &left
, mode
);
11467 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11468 remote_errno
, NULL
, NULL
);
11471 /* Implementation of to_fileio_pwrite. */
11474 remote_hostio_pwrite (struct target_ops
*self
,
11475 int fd
, const gdb_byte
*write_buf
, int len
,
11476 ULONGEST offset
, int *remote_errno
)
11478 struct remote_state
*rs
= get_remote_state ();
11480 int left
= get_remote_packet_size ();
11483 readahead_cache_invalidate_fd (fd
);
11485 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11487 remote_buffer_add_int (&p
, &left
, fd
);
11488 remote_buffer_add_string (&p
, &left
, ",");
11490 remote_buffer_add_int (&p
, &left
, offset
);
11491 remote_buffer_add_string (&p
, &left
, ",");
11493 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11494 get_remote_packet_size () - (p
- rs
->buf
));
11496 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11497 remote_errno
, NULL
, NULL
);
11500 /* Helper for the implementation of to_fileio_pread. Read the file
11501 from the remote side with vFile:pread. */
11504 remote_hostio_pread_vFile (struct target_ops
*self
,
11505 int fd
, gdb_byte
*read_buf
, int len
,
11506 ULONGEST offset
, int *remote_errno
)
11508 struct remote_state
*rs
= get_remote_state ();
11511 int left
= get_remote_packet_size ();
11512 int ret
, attachment_len
;
11515 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11517 remote_buffer_add_int (&p
, &left
, fd
);
11518 remote_buffer_add_string (&p
, &left
, ",");
11520 remote_buffer_add_int (&p
, &left
, len
);
11521 remote_buffer_add_string (&p
, &left
, ",");
11523 remote_buffer_add_int (&p
, &left
, offset
);
11525 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11526 remote_errno
, &attachment
,
11532 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11534 if (read_len
!= ret
)
11535 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11540 /* Serve pread from the readahead cache. Returns number of bytes
11541 read, or 0 if the request can't be served from the cache. */
11544 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11545 int fd
, gdb_byte
*read_buf
, size_t len
,
11548 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11550 if (cache
->fd
== fd
11551 && cache
->offset
<= offset
11552 && offset
< cache
->offset
+ cache
->bufsize
)
11554 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11556 if (offset
+ len
> max
)
11557 len
= max
- offset
;
11559 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11566 /* Implementation of to_fileio_pread. */
11569 remote_hostio_pread (struct target_ops
*self
,
11570 int fd
, gdb_byte
*read_buf
, int len
,
11571 ULONGEST offset
, int *remote_errno
)
11574 struct remote_state
*rs
= get_remote_state ();
11575 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11577 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11580 cache
->hit_count
++;
11583 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11584 pulongest (cache
->hit_count
));
11588 cache
->miss_count
++;
11590 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11591 pulongest (cache
->miss_count
));
11594 cache
->offset
= offset
;
11595 cache
->bufsize
= get_remote_packet_size ();
11596 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11598 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11599 cache
->offset
, remote_errno
);
11602 readahead_cache_invalidate_fd (fd
);
11606 cache
->bufsize
= ret
;
11607 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11610 /* Implementation of to_fileio_close. */
11613 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11615 struct remote_state
*rs
= get_remote_state ();
11617 int left
= get_remote_packet_size () - 1;
11619 readahead_cache_invalidate_fd (fd
);
11621 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11623 remote_buffer_add_int (&p
, &left
, fd
);
11625 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11626 remote_errno
, NULL
, NULL
);
11629 /* Implementation of to_fileio_unlink. */
11632 remote_hostio_unlink (struct target_ops
*self
,
11633 struct inferior
*inf
, const char *filename
,
11636 struct remote_state
*rs
= get_remote_state ();
11638 int left
= get_remote_packet_size () - 1;
11640 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11643 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11645 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11646 strlen (filename
));
11648 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11649 remote_errno
, NULL
, NULL
);
11652 /* Implementation of to_fileio_readlink. */
11655 remote_hostio_readlink (struct target_ops
*self
,
11656 struct inferior
*inf
, const char *filename
,
11659 struct remote_state
*rs
= get_remote_state ();
11662 int left
= get_remote_packet_size ();
11663 int len
, attachment_len
;
11667 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11670 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11672 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11673 strlen (filename
));
11675 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11676 remote_errno
, &attachment
,
11682 ret
= (char *) xmalloc (len
+ 1);
11684 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11685 (gdb_byte
*) ret
, len
);
11686 if (read_len
!= len
)
11687 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11693 /* Implementation of to_fileio_fstat. */
11696 remote_hostio_fstat (struct target_ops
*self
,
11697 int fd
, struct stat
*st
,
11700 struct remote_state
*rs
= get_remote_state ();
11702 int left
= get_remote_packet_size ();
11703 int attachment_len
, ret
;
11705 struct fio_stat fst
;
11708 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11710 remote_buffer_add_int (&p
, &left
, fd
);
11712 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11713 remote_errno
, &attachment
,
11717 if (*remote_errno
!= FILEIO_ENOSYS
)
11720 /* Strictly we should return -1, ENOSYS here, but when
11721 "set sysroot remote:" was implemented in August 2008
11722 BFD's need for a stat function was sidestepped with
11723 this hack. This was not remedied until March 2015
11724 so we retain the previous behavior to avoid breaking
11727 Note that the memset is a March 2015 addition; older
11728 GDBs set st_size *and nothing else* so the structure
11729 would have garbage in all other fields. This might
11730 break something but retaining the previous behavior
11731 here would be just too wrong. */
11733 memset (st
, 0, sizeof (struct stat
));
11734 st
->st_size
= INT_MAX
;
11738 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11739 (gdb_byte
*) &fst
, sizeof (fst
));
11741 if (read_len
!= ret
)
11742 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11744 if (read_len
!= sizeof (fst
))
11745 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11746 read_len
, (int) sizeof (fst
));
11748 remote_fileio_to_host_stat (&fst
, st
);
11753 /* Implementation of to_filesystem_is_local. */
11756 remote_filesystem_is_local (struct target_ops
*self
)
11758 /* Valgrind GDB presents itself as a remote target but works
11759 on the local filesystem: it does not implement remote get
11760 and users are not expected to set a sysroot. To handle
11761 this case we treat the remote filesystem as local if the
11762 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11763 does not support vFile:open. */
11764 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11766 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11768 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11770 int fd
, remote_errno
;
11772 /* Try opening a file to probe support. The supplied
11773 filename is irrelevant, we only care about whether
11774 the stub recognizes the packet or not. */
11775 fd
= remote_hostio_open (self
, NULL
, "just probing",
11776 FILEIO_O_RDONLY
, 0700, 0,
11780 remote_hostio_close (self
, fd
, &remote_errno
);
11782 ps
= packet_support (PACKET_vFile_open
);
11785 if (ps
== PACKET_DISABLE
)
11787 static int warning_issued
= 0;
11789 if (!warning_issued
)
11791 warning (_("remote target does not support file"
11792 " transfer, attempting to access files"
11793 " from local filesystem."));
11794 warning_issued
= 1;
11805 remote_fileio_errno_to_host (int errnum
)
11811 case FILEIO_ENOENT
:
11819 case FILEIO_EACCES
:
11821 case FILEIO_EFAULT
:
11825 case FILEIO_EEXIST
:
11827 case FILEIO_ENODEV
:
11829 case FILEIO_ENOTDIR
:
11831 case FILEIO_EISDIR
:
11833 case FILEIO_EINVAL
:
11835 case FILEIO_ENFILE
:
11837 case FILEIO_EMFILE
:
11841 case FILEIO_ENOSPC
:
11843 case FILEIO_ESPIPE
:
11847 case FILEIO_ENOSYS
:
11849 case FILEIO_ENAMETOOLONG
:
11850 return ENAMETOOLONG
;
11856 remote_hostio_error (int errnum
)
11858 int host_error
= remote_fileio_errno_to_host (errnum
);
11860 if (host_error
== -1)
11861 error (_("Unknown remote I/O error %d"), errnum
);
11863 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11867 remote_hostio_close_cleanup (void *opaque
)
11869 int fd
= *(int *) opaque
;
11872 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11876 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11878 struct cleanup
*back_to
, *close_cleanup
;
11879 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11882 int bytes_in_buffer
;
11885 struct remote_state
*rs
= get_remote_state ();
11887 if (!rs
->remote_desc
)
11888 error (_("command can only be used with remote target"));
11890 file
= gdb_fopen_cloexec (local_file
, "rb");
11892 perror_with_name (local_file
);
11893 back_to
= make_cleanup_fclose (file
);
11895 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11896 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11898 0700, 0, &remote_errno
);
11900 remote_hostio_error (remote_errno
);
11902 /* Send up to this many bytes at once. They won't all fit in the
11903 remote packet limit, so we'll transfer slightly fewer. */
11904 io_size
= get_remote_packet_size ();
11905 buffer
= (gdb_byte
*) xmalloc (io_size
);
11906 make_cleanup (xfree
, buffer
);
11908 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11910 bytes_in_buffer
= 0;
11913 while (bytes_in_buffer
|| !saw_eof
)
11917 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11918 io_size
- bytes_in_buffer
,
11923 error (_("Error reading %s."), local_file
);
11926 /* EOF. Unless there is something still in the
11927 buffer from the last iteration, we are done. */
11929 if (bytes_in_buffer
== 0)
11937 bytes
+= bytes_in_buffer
;
11938 bytes_in_buffer
= 0;
11940 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11942 offset
, &remote_errno
);
11945 remote_hostio_error (remote_errno
);
11946 else if (retcode
== 0)
11947 error (_("Remote write of %d bytes returned 0!"), bytes
);
11948 else if (retcode
< bytes
)
11950 /* Short write. Save the rest of the read data for the next
11952 bytes_in_buffer
= bytes
- retcode
;
11953 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11959 discard_cleanups (close_cleanup
);
11960 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11961 remote_hostio_error (remote_errno
);
11964 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11965 do_cleanups (back_to
);
11969 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11971 struct cleanup
*back_to
, *close_cleanup
;
11972 int fd
, remote_errno
, bytes
, io_size
;
11976 struct remote_state
*rs
= get_remote_state ();
11978 if (!rs
->remote_desc
)
11979 error (_("command can only be used with remote target"));
11981 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11982 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11985 remote_hostio_error (remote_errno
);
11987 file
= gdb_fopen_cloexec (local_file
, "wb");
11989 perror_with_name (local_file
);
11990 back_to
= make_cleanup_fclose (file
);
11992 /* Send up to this many bytes at once. They won't all fit in the
11993 remote packet limit, so we'll transfer slightly fewer. */
11994 io_size
= get_remote_packet_size ();
11995 buffer
= (gdb_byte
*) xmalloc (io_size
);
11996 make_cleanup (xfree
, buffer
);
11998 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
12003 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
12004 fd
, buffer
, io_size
, offset
, &remote_errno
);
12006 /* Success, but no bytes, means end-of-file. */
12009 remote_hostio_error (remote_errno
);
12013 bytes
= fwrite (buffer
, 1, bytes
, file
);
12015 perror_with_name (local_file
);
12018 discard_cleanups (close_cleanup
);
12019 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
12020 remote_hostio_error (remote_errno
);
12023 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
12024 do_cleanups (back_to
);
12028 remote_file_delete (const char *remote_file
, int from_tty
)
12030 int retcode
, remote_errno
;
12031 struct remote_state
*rs
= get_remote_state ();
12033 if (!rs
->remote_desc
)
12034 error (_("command can only be used with remote target"));
12036 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
12037 NULL
, remote_file
, &remote_errno
);
12039 remote_hostio_error (remote_errno
);
12042 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
12046 remote_put_command (char *args
, int from_tty
)
12048 struct cleanup
*back_to
;
12052 error_no_arg (_("file to put"));
12054 argv
= gdb_buildargv (args
);
12055 back_to
= make_cleanup_freeargv (argv
);
12056 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12057 error (_("Invalid parameters to remote put"));
12059 remote_file_put (argv
[0], argv
[1], from_tty
);
12061 do_cleanups (back_to
);
12065 remote_get_command (char *args
, int from_tty
)
12067 struct cleanup
*back_to
;
12071 error_no_arg (_("file to get"));
12073 argv
= gdb_buildargv (args
);
12074 back_to
= make_cleanup_freeargv (argv
);
12075 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12076 error (_("Invalid parameters to remote get"));
12078 remote_file_get (argv
[0], argv
[1], from_tty
);
12080 do_cleanups (back_to
);
12084 remote_delete_command (char *args
, int from_tty
)
12086 struct cleanup
*back_to
;
12090 error_no_arg (_("file to delete"));
12092 argv
= gdb_buildargv (args
);
12093 back_to
= make_cleanup_freeargv (argv
);
12094 if (argv
[0] == NULL
|| argv
[1] != NULL
)
12095 error (_("Invalid parameters to remote delete"));
12097 remote_file_delete (argv
[0], from_tty
);
12099 do_cleanups (back_to
);
12103 remote_command (char *args
, int from_tty
)
12105 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
12109 remote_can_execute_reverse (struct target_ops
*self
)
12111 if (packet_support (PACKET_bs
) == PACKET_ENABLE
12112 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
12119 remote_supports_non_stop (struct target_ops
*self
)
12125 remote_supports_disable_randomization (struct target_ops
*self
)
12127 /* Only supported in extended mode. */
12132 remote_supports_multi_process (struct target_ops
*self
)
12134 struct remote_state
*rs
= get_remote_state ();
12136 return remote_multi_process_p (rs
);
12140 remote_supports_cond_tracepoints (void)
12142 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
12146 remote_supports_cond_breakpoints (struct target_ops
*self
)
12148 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
12152 remote_supports_fast_tracepoints (void)
12154 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
12158 remote_supports_static_tracepoints (void)
12160 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
12164 remote_supports_install_in_trace (void)
12166 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
12170 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
12172 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
12177 remote_supports_string_tracing (struct target_ops
*self
)
12179 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
12183 remote_can_run_breakpoint_commands (struct target_ops
*self
)
12185 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
12189 remote_trace_init (struct target_ops
*self
)
12192 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12193 if (strcmp (target_buf
, "OK") != 0)
12194 error (_("Target does not support this command."));
12197 static void free_actions_list (char **actions_list
);
12198 static void free_actions_list_cleanup_wrapper (void *);
12200 free_actions_list_cleanup_wrapper (void *al
)
12202 free_actions_list ((char **) al
);
12206 free_actions_list (char **actions_list
)
12210 if (actions_list
== 0)
12213 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
12214 xfree (actions_list
[ndx
]);
12216 xfree (actions_list
);
12219 /* Recursive routine to walk through command list including loops, and
12220 download packets for each command. */
12223 remote_download_command_source (int num
, ULONGEST addr
,
12224 struct command_line
*cmds
)
12226 struct remote_state
*rs
= get_remote_state ();
12227 struct command_line
*cmd
;
12229 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
12231 QUIT
; /* Allow user to bail out with ^C. */
12232 strcpy (rs
->buf
, "QTDPsrc:");
12233 encode_source_string (num
, addr
, "cmd", cmd
->line
,
12234 rs
->buf
+ strlen (rs
->buf
),
12235 rs
->buf_size
- strlen (rs
->buf
));
12237 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12238 if (strcmp (target_buf
, "OK"))
12239 warning (_("Target does not support source download."));
12241 if (cmd
->control_type
== while_control
12242 || cmd
->control_type
== while_stepping_control
)
12244 remote_download_command_source (num
, addr
, *cmd
->body_list
);
12246 QUIT
; /* Allow user to bail out with ^C. */
12247 strcpy (rs
->buf
, "QTDPsrc:");
12248 encode_source_string (num
, addr
, "cmd", "end",
12249 rs
->buf
+ strlen (rs
->buf
),
12250 rs
->buf_size
- strlen (rs
->buf
));
12252 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12253 if (strcmp (target_buf
, "OK"))
12254 warning (_("Target does not support source download."));
12260 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
12262 #define BUF_SIZE 2048
12266 char buf
[BUF_SIZE
];
12267 char **tdp_actions
;
12268 char **stepping_actions
;
12270 struct cleanup
*old_chain
= NULL
;
12271 struct agent_expr
*aexpr
;
12272 struct cleanup
*aexpr_chain
= NULL
;
12274 struct breakpoint
*b
= loc
->owner
;
12275 struct tracepoint
*t
= (struct tracepoint
*) b
;
12277 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
12278 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
12280 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
12283 tpaddr
= loc
->address
;
12284 sprintf_vma (addrbuf
, tpaddr
);
12285 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
12286 addrbuf
, /* address */
12287 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
12288 t
->step_count
, t
->pass_count
);
12289 /* Fast tracepoints are mostly handled by the target, but we can
12290 tell the target how big of an instruction block should be moved
12292 if (b
->type
== bp_fast_tracepoint
)
12294 /* Only test for support at download time; we may not know
12295 target capabilities at definition time. */
12296 if (remote_supports_fast_tracepoints ())
12298 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
12300 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
12301 gdb_insn_length (loc
->gdbarch
, tpaddr
));
12303 /* If it passed validation at definition but fails now,
12304 something is very wrong. */
12305 internal_error (__FILE__
, __LINE__
,
12306 _("Fast tracepoint not "
12307 "valid during download"));
12310 /* Fast tracepoints are functionally identical to regular
12311 tracepoints, so don't take lack of support as a reason to
12312 give up on the trace run. */
12313 warning (_("Target does not support fast tracepoints, "
12314 "downloading %d as regular tracepoint"), b
->number
);
12316 else if (b
->type
== bp_static_tracepoint
)
12318 /* Only test for support at download time; we may not know
12319 target capabilities at definition time. */
12320 if (remote_supports_static_tracepoints ())
12322 struct static_tracepoint_marker marker
;
12324 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
12325 strcat (buf
, ":S");
12327 error (_("Static tracepoint not valid during download"));
12330 /* Fast tracepoints are functionally identical to regular
12331 tracepoints, so don't take lack of support as a reason
12332 to give up on the trace run. */
12333 error (_("Target does not support static tracepoints"));
12335 /* If the tracepoint has a conditional, make it into an agent
12336 expression and append to the definition. */
12339 /* Only test support at download time, we may not know target
12340 capabilities at definition time. */
12341 if (remote_supports_cond_tracepoints ())
12343 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
12344 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
12345 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
12347 pkt
= buf
+ strlen (buf
);
12348 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
12349 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
12351 do_cleanups (aexpr_chain
);
12354 warning (_("Target does not support conditional tracepoints, "
12355 "ignoring tp %d cond"), b
->number
);
12358 if (b
->commands
|| *default_collect
)
12361 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12362 if (strcmp (target_buf
, "OK"))
12363 error (_("Target does not support tracepoints."));
12365 /* do_single_steps (t); */
12368 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
12370 QUIT
; /* Allow user to bail out with ^C. */
12371 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
12372 b
->number
, addrbuf
, /* address */
12374 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
12377 remote_get_noisy_reply (&target_buf
,
12379 if (strcmp (target_buf
, "OK"))
12380 error (_("Error on target while setting tracepoints."));
12383 if (stepping_actions
)
12385 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
12387 QUIT
; /* Allow user to bail out with ^C. */
12388 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
12389 b
->number
, addrbuf
, /* address */
12390 ((ndx
== 0) ? "S" : ""),
12391 stepping_actions
[ndx
],
12392 (stepping_actions
[ndx
+ 1] ? "-" : ""));
12394 remote_get_noisy_reply (&target_buf
,
12396 if (strcmp (target_buf
, "OK"))
12397 error (_("Error on target while setting tracepoints."));
12401 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
12403 if (b
->location
!= NULL
)
12405 strcpy (buf
, "QTDPsrc:");
12406 encode_source_string (b
->number
, loc
->address
, "at",
12407 event_location_to_string (b
->location
),
12408 buf
+ strlen (buf
), 2048 - strlen (buf
));
12410 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12411 if (strcmp (target_buf
, "OK"))
12412 warning (_("Target does not support source download."));
12414 if (b
->cond_string
)
12416 strcpy (buf
, "QTDPsrc:");
12417 encode_source_string (b
->number
, loc
->address
,
12418 "cond", b
->cond_string
, buf
+ strlen (buf
),
12419 2048 - strlen (buf
));
12421 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12422 if (strcmp (target_buf
, "OK"))
12423 warning (_("Target does not support source download."));
12425 remote_download_command_source (b
->number
, loc
->address
,
12426 breakpoint_commands (b
));
12429 do_cleanups (old_chain
);
12433 remote_can_download_tracepoint (struct target_ops
*self
)
12435 struct remote_state
*rs
= get_remote_state ();
12436 struct trace_status
*ts
;
12439 /* Don't try to install tracepoints until we've relocated our
12440 symbols, and fetched and merged the target's tracepoint list with
12442 if (rs
->starting_up
)
12445 ts
= current_trace_status ();
12446 status
= remote_get_trace_status (self
, ts
);
12448 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12451 /* If we are in a tracing experiment, but remote stub doesn't support
12452 installing tracepoint in trace, we have to return. */
12453 if (!remote_supports_install_in_trace ())
12461 remote_download_trace_state_variable (struct target_ops
*self
,
12462 struct trace_state_variable
*tsv
)
12464 struct remote_state
*rs
= get_remote_state ();
12467 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12468 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12470 p
= rs
->buf
+ strlen (rs
->buf
);
12471 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12472 error (_("Trace state variable name too long for tsv definition packet"));
12473 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12476 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12477 if (*target_buf
== '\0')
12478 error (_("Target does not support this command."));
12479 if (strcmp (target_buf
, "OK") != 0)
12480 error (_("Error on target while downloading trace state variable."));
12484 remote_enable_tracepoint (struct target_ops
*self
,
12485 struct bp_location
*location
)
12487 struct remote_state
*rs
= get_remote_state ();
12490 sprintf_vma (addr_buf
, location
->address
);
12491 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12492 location
->owner
->number
, addr_buf
);
12494 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12495 if (*rs
->buf
== '\0')
12496 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12497 if (strcmp (rs
->buf
, "OK") != 0)
12498 error (_("Error on target while enabling tracepoint."));
12502 remote_disable_tracepoint (struct target_ops
*self
,
12503 struct bp_location
*location
)
12505 struct remote_state
*rs
= get_remote_state ();
12508 sprintf_vma (addr_buf
, location
->address
);
12509 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12510 location
->owner
->number
, addr_buf
);
12512 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12513 if (*rs
->buf
== '\0')
12514 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12515 if (strcmp (rs
->buf
, "OK") != 0)
12516 error (_("Error on target while disabling tracepoint."));
12520 remote_trace_set_readonly_regions (struct target_ops
*self
)
12524 bfd_size_type size
;
12530 return; /* No information to give. */
12532 strcpy (target_buf
, "QTro");
12533 offset
= strlen (target_buf
);
12534 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12536 char tmp1
[40], tmp2
[40];
12539 if ((s
->flags
& SEC_LOAD
) == 0 ||
12540 /* (s->flags & SEC_CODE) == 0 || */
12541 (s
->flags
& SEC_READONLY
) == 0)
12545 vma
= bfd_get_section_vma (abfd
, s
);
12546 size
= bfd_get_section_size (s
);
12547 sprintf_vma (tmp1
, vma
);
12548 sprintf_vma (tmp2
, vma
+ size
);
12549 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12550 if (offset
+ sec_length
+ 1 > target_buf_size
)
12552 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12554 Too many sections for read-only sections definition packet."));
12557 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12559 offset
+= sec_length
;
12563 putpkt (target_buf
);
12564 getpkt (&target_buf
, &target_buf_size
, 0);
12569 remote_trace_start (struct target_ops
*self
)
12571 putpkt ("QTStart");
12572 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12573 if (*target_buf
== '\0')
12574 error (_("Target does not support this command."));
12575 if (strcmp (target_buf
, "OK") != 0)
12576 error (_("Bogus reply from target: %s"), target_buf
);
12580 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12582 /* Initialize it just to avoid a GCC false warning. */
12584 /* FIXME we need to get register block size some other way. */
12585 extern int trace_regblock_size
;
12586 enum packet_result result
;
12588 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12591 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12593 putpkt ("qTStatus");
12597 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12599 CATCH (ex
, RETURN_MASK_ERROR
)
12601 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12603 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12606 throw_exception (ex
);
12610 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12612 /* If the remote target doesn't do tracing, flag it. */
12613 if (result
== PACKET_UNKNOWN
)
12616 /* We're working with a live target. */
12617 ts
->filename
= NULL
;
12620 error (_("Bogus trace status reply from target: %s"), target_buf
);
12622 /* Function 'parse_trace_status' sets default value of each field of
12623 'ts' at first, so we don't have to do it here. */
12624 parse_trace_status (p
, ts
);
12626 return ts
->running
;
12630 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12631 struct uploaded_tp
*utp
)
12633 struct remote_state
*rs
= get_remote_state ();
12635 struct bp_location
*loc
;
12636 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12637 size_t size
= get_remote_packet_size ();
12641 tp
->base
.hit_count
= 0;
12642 tp
->traceframe_usage
= 0;
12643 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12645 /* If the tracepoint was never downloaded, don't go asking for
12647 if (tp
->number_on_target
== 0)
12649 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12650 phex_nz (loc
->address
, 0));
12652 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12653 if (reply
&& *reply
)
12656 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12662 utp
->hit_count
= 0;
12663 utp
->traceframe_usage
= 0;
12664 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12665 phex_nz (utp
->addr
, 0));
12667 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12668 if (reply
&& *reply
)
12671 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12677 remote_trace_stop (struct target_ops
*self
)
12680 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12681 if (*target_buf
== '\0')
12682 error (_("Target does not support this command."));
12683 if (strcmp (target_buf
, "OK") != 0)
12684 error (_("Bogus reply from target: %s"), target_buf
);
12688 remote_trace_find (struct target_ops
*self
,
12689 enum trace_find_type type
, int num
,
12690 CORE_ADDR addr1
, CORE_ADDR addr2
,
12693 struct remote_state
*rs
= get_remote_state ();
12694 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12696 int target_frameno
= -1, target_tracept
= -1;
12698 /* Lookups other than by absolute frame number depend on the current
12699 trace selected, so make sure it is correct on the remote end
12701 if (type
!= tfind_number
)
12702 set_remote_traceframe ();
12705 strcpy (p
, "QTFrame:");
12706 p
= strchr (p
, '\0');
12710 xsnprintf (p
, endbuf
- p
, "%x", num
);
12713 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12716 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12719 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12720 phex_nz (addr2
, 0));
12722 case tfind_outside
:
12723 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12724 phex_nz (addr2
, 0));
12727 error (_("Unknown trace find type %d"), type
);
12731 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12732 if (*reply
== '\0')
12733 error (_("Target does not support this command."));
12735 while (reply
&& *reply
)
12740 target_frameno
= (int) strtol (p
, &reply
, 16);
12742 error (_("Unable to parse trace frame number"));
12743 /* Don't update our remote traceframe number cache on failure
12744 to select a remote traceframe. */
12745 if (target_frameno
== -1)
12750 target_tracept
= (int) strtol (p
, &reply
, 16);
12752 error (_("Unable to parse tracepoint number"));
12754 case 'O': /* "OK"? */
12755 if (reply
[1] == 'K' && reply
[2] == '\0')
12758 error (_("Bogus reply from target: %s"), reply
);
12761 error (_("Bogus reply from target: %s"), reply
);
12764 *tpp
= target_tracept
;
12766 rs
->remote_traceframe_number
= target_frameno
;
12767 return target_frameno
;
12771 remote_get_trace_state_variable_value (struct target_ops
*self
,
12772 int tsvnum
, LONGEST
*val
)
12774 struct remote_state
*rs
= get_remote_state ();
12778 set_remote_traceframe ();
12780 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12782 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12783 if (reply
&& *reply
)
12787 unpack_varlen_hex (reply
+ 1, &uval
);
12788 *val
= (LONGEST
) uval
;
12796 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12798 struct remote_state
*rs
= get_remote_state ();
12802 strcpy (p
, "QTSave:");
12804 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12805 error (_("Remote file name too long for trace save packet"));
12806 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12809 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12810 if (*reply
== '\0')
12811 error (_("Target does not support this command."));
12812 if (strcmp (reply
, "OK") != 0)
12813 error (_("Bogus reply from target: %s"), reply
);
12817 /* This is basically a memory transfer, but needs to be its own packet
12818 because we don't know how the target actually organizes its trace
12819 memory, plus we want to be able to ask for as much as possible, but
12820 not be unhappy if we don't get as much as we ask for. */
12823 remote_get_raw_trace_data (struct target_ops
*self
,
12824 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12826 struct remote_state
*rs
= get_remote_state ();
12832 strcpy (p
, "qTBuffer:");
12834 p
+= hexnumstr (p
, offset
);
12836 p
+= hexnumstr (p
, len
);
12840 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12841 if (reply
&& *reply
)
12843 /* 'l' by itself means we're at the end of the buffer and
12844 there is nothing more to get. */
12848 /* Convert the reply into binary. Limit the number of bytes to
12849 convert according to our passed-in buffer size, rather than
12850 what was returned in the packet; if the target is
12851 unexpectedly generous and gives us a bigger reply than we
12852 asked for, we don't want to crash. */
12853 rslt
= hex2bin (target_buf
, buf
, len
);
12857 /* Something went wrong, flag as an error. */
12862 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12864 struct remote_state
*rs
= get_remote_state ();
12866 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12870 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12872 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12873 if (*reply
== '\0')
12874 error (_("Target does not support this command."));
12875 if (strcmp (reply
, "OK") != 0)
12876 error (_("Bogus reply from target: %s"), reply
);
12879 warning (_("Target does not support disconnected tracing."));
12883 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12885 struct thread_info
*info
= find_thread_ptid (ptid
);
12887 if (info
&& info
->priv
)
12888 return info
->priv
->core
;
12893 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12895 struct remote_state
*rs
= get_remote_state ();
12898 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12900 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12901 if (*reply
== '\0')
12902 error (_("Target does not support this command."));
12903 if (strcmp (reply
, "OK") != 0)
12904 error (_("Bogus reply from target: %s"), reply
);
12907 static struct traceframe_info
*
12908 remote_traceframe_info (struct target_ops
*self
)
12912 text
= target_read_stralloc (¤t_target
,
12913 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12916 struct traceframe_info
*info
;
12917 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12919 info
= parse_traceframe_info (text
);
12920 do_cleanups (back_to
);
12927 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12928 instruction on which a fast tracepoint may be placed. Returns -1
12929 if the packet is not supported, and 0 if the minimum instruction
12930 length is unknown. */
12933 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12935 struct remote_state
*rs
= get_remote_state ();
12938 /* If we're not debugging a process yet, the IPA can't be
12940 if (!target_has_execution
)
12943 /* Make sure the remote is pointing at the right process. */
12944 set_general_process ();
12946 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12948 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12949 if (*reply
== '\0')
12953 ULONGEST min_insn_len
;
12955 unpack_varlen_hex (reply
, &min_insn_len
);
12957 return (int) min_insn_len
;
12962 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12964 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12966 struct remote_state
*rs
= get_remote_state ();
12967 char *buf
= rs
->buf
;
12968 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12969 enum packet_result result
;
12971 gdb_assert (val
>= 0 || val
== -1);
12972 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12973 /* Send -1 as literal "-1" to avoid host size dependency. */
12977 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12980 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12983 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12984 result
= packet_ok (rs
->buf
,
12985 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12987 if (result
!= PACKET_OK
)
12988 warning (_("Bogus reply from target: %s"), rs
->buf
);
12993 remote_set_trace_notes (struct target_ops
*self
,
12994 const char *user
, const char *notes
,
12995 const char *stop_notes
)
12997 struct remote_state
*rs
= get_remote_state ();
12999 char *buf
= rs
->buf
;
13000 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13003 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
13006 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
13007 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
13013 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
13014 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
13020 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
13021 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
13025 /* Ensure the buffer is terminated. */
13029 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
13030 if (*reply
== '\0')
13033 if (strcmp (reply
, "OK") != 0)
13034 error (_("Bogus reply from target: %s"), reply
);
13040 remote_use_agent (struct target_ops
*self
, int use
)
13042 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
13044 struct remote_state
*rs
= get_remote_state ();
13046 /* If the stub supports QAgent. */
13047 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
13049 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13051 if (strcmp (rs
->buf
, "OK") == 0)
13062 remote_can_use_agent (struct target_ops
*self
)
13064 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
13067 struct btrace_target_info
13069 /* The ptid of the traced thread. */
13072 /* The obtained branch trace configuration. */
13073 struct btrace_config conf
;
13076 /* Reset our idea of our target's btrace configuration. */
13079 remote_btrace_reset (void)
13081 struct remote_state
*rs
= get_remote_state ();
13083 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
13086 /* Check whether the target supports branch tracing. */
13089 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
13091 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
13093 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
13098 case BTRACE_FORMAT_NONE
:
13101 case BTRACE_FORMAT_BTS
:
13102 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
13104 case BTRACE_FORMAT_PT
:
13105 /* The trace is decoded on the host. Even if our target supports it,
13106 we still need to have libipt to decode the trace. */
13107 #if defined (HAVE_LIBIPT)
13108 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
13109 #else /* !defined (HAVE_LIBIPT) */
13111 #endif /* !defined (HAVE_LIBIPT) */
13114 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
13117 /* Synchronize the configuration with the target. */
13120 btrace_sync_conf (const struct btrace_config
*conf
)
13122 struct packet_config
*packet
;
13123 struct remote_state
*rs
;
13124 char *buf
, *pos
, *endbuf
;
13126 rs
= get_remote_state ();
13128 endbuf
= buf
+ get_remote_packet_size ();
13130 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
13131 if (packet_config_support (packet
) == PACKET_ENABLE
13132 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
13135 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13139 getpkt (&buf
, &rs
->buf_size
, 0);
13141 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13143 if (buf
[0] == 'E' && buf
[1] == '.')
13144 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
13146 error (_("Failed to configure the BTS buffer size."));
13149 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
13152 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
13153 if (packet_config_support (packet
) == PACKET_ENABLE
13154 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
13157 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13161 getpkt (&buf
, &rs
->buf_size
, 0);
13163 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13165 if (buf
[0] == 'E' && buf
[1] == '.')
13166 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
13168 error (_("Failed to configure the trace buffer size."));
13171 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
13175 /* Read the current thread's btrace configuration from the target and
13176 store it into CONF. */
13179 btrace_read_config (struct btrace_config
*conf
)
13183 xml
= target_read_stralloc (¤t_target
,
13184 TARGET_OBJECT_BTRACE_CONF
, "");
13187 struct cleanup
*cleanup
;
13189 cleanup
= make_cleanup (xfree
, xml
);
13190 parse_xml_btrace_conf (conf
, xml
);
13191 do_cleanups (cleanup
);
13195 /* Maybe reopen target btrace. */
13198 remote_btrace_maybe_reopen (void)
13200 struct remote_state
*rs
= get_remote_state ();
13201 struct cleanup
*cleanup
;
13202 struct thread_info
*tp
;
13203 int btrace_target_pushed
= 0;
13206 cleanup
= make_cleanup_restore_current_thread ();
13207 ALL_NON_EXITED_THREADS (tp
)
13209 set_general_thread (tp
->ptid
);
13211 memset (&rs
->btrace_config
, 0x00, sizeof (struct btrace_config
));
13212 btrace_read_config (&rs
->btrace_config
);
13214 if (rs
->btrace_config
.format
== BTRACE_FORMAT_NONE
)
13217 #if !defined (HAVE_LIBIPT)
13218 if (rs
->btrace_config
.format
== BTRACE_FORMAT_PT
)
13223 warning (_("GDB does not support Intel Processor Trace. "
13224 "\"record\" will not work in this session."));
13229 #endif /* !defined (HAVE_LIBIPT) */
13231 /* Push target, once, but before anything else happens. This way our
13232 changes to the threads will be cleaned up by unpushing the target
13233 in case btrace_read_config () throws. */
13234 if (!btrace_target_pushed
)
13236 btrace_target_pushed
= 1;
13237 record_btrace_push_target ();
13238 printf_filtered (_("Target is recording using %s.\n"),
13239 btrace_format_string (rs
->btrace_config
.format
));
13242 tp
->btrace
.target
= XCNEW (struct btrace_target_info
);
13243 tp
->btrace
.target
->ptid
= tp
->ptid
;
13244 tp
->btrace
.target
->conf
= rs
->btrace_config
;
13246 do_cleanups (cleanup
);
13249 /* Enable branch tracing. */
13251 static struct btrace_target_info
*
13252 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
13253 const struct btrace_config
*conf
)
13255 struct btrace_target_info
*tinfo
= NULL
;
13256 struct packet_config
*packet
= NULL
;
13257 struct remote_state
*rs
= get_remote_state ();
13258 char *buf
= rs
->buf
;
13259 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13261 switch (conf
->format
)
13263 case BTRACE_FORMAT_BTS
:
13264 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
13267 case BTRACE_FORMAT_PT
:
13268 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
13272 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
13273 error (_("Target does not support branch tracing."));
13275 btrace_sync_conf (conf
);
13277 set_general_thread (ptid
);
13279 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13281 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13283 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13285 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13286 error (_("Could not enable branch tracing for %s: %s"),
13287 target_pid_to_str (ptid
), rs
->buf
+ 2);
13289 error (_("Could not enable branch tracing for %s."),
13290 target_pid_to_str (ptid
));
13293 tinfo
= XCNEW (struct btrace_target_info
);
13294 tinfo
->ptid
= ptid
;
13296 /* If we fail to read the configuration, we lose some information, but the
13297 tracing itself is not impacted. */
13300 btrace_read_config (&tinfo
->conf
);
13302 CATCH (err
, RETURN_MASK_ERROR
)
13304 if (err
.message
!= NULL
)
13305 warning ("%s", err
.message
);
13312 /* Disable branch tracing. */
13315 remote_disable_btrace (struct target_ops
*self
,
13316 struct btrace_target_info
*tinfo
)
13318 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
13319 struct remote_state
*rs
= get_remote_state ();
13320 char *buf
= rs
->buf
;
13321 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13323 if (packet_config_support (packet
) != PACKET_ENABLE
)
13324 error (_("Target does not support branch tracing."));
13326 set_general_thread (tinfo
->ptid
);
13328 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13330 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13332 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13334 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13335 error (_("Could not disable branch tracing for %s: %s"),
13336 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
13338 error (_("Could not disable branch tracing for %s."),
13339 target_pid_to_str (tinfo
->ptid
));
13345 /* Teardown branch tracing. */
13348 remote_teardown_btrace (struct target_ops
*self
,
13349 struct btrace_target_info
*tinfo
)
13351 /* We must not talk to the target during teardown. */
13355 /* Read the branch trace. */
13357 static enum btrace_error
13358 remote_read_btrace (struct target_ops
*self
,
13359 struct btrace_data
*btrace
,
13360 struct btrace_target_info
*tinfo
,
13361 enum btrace_read_type type
)
13363 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
13364 struct cleanup
*cleanup
;
13368 if (packet_config_support (packet
) != PACKET_ENABLE
)
13369 error (_("Target does not support branch tracing."));
13371 #if !defined(HAVE_LIBEXPAT)
13372 error (_("Cannot process branch tracing result. XML parsing not supported."));
13377 case BTRACE_READ_ALL
:
13380 case BTRACE_READ_NEW
:
13383 case BTRACE_READ_DELTA
:
13387 internal_error (__FILE__
, __LINE__
,
13388 _("Bad branch tracing read type: %u."),
13389 (unsigned int) type
);
13392 xml
= target_read_stralloc (¤t_target
,
13393 TARGET_OBJECT_BTRACE
, annex
);
13395 return BTRACE_ERR_UNKNOWN
;
13397 cleanup
= make_cleanup (xfree
, xml
);
13398 parse_xml_btrace (btrace
, xml
);
13399 do_cleanups (cleanup
);
13401 return BTRACE_ERR_NONE
;
13404 static const struct btrace_config
*
13405 remote_btrace_conf (struct target_ops
*self
,
13406 const struct btrace_target_info
*tinfo
)
13408 return &tinfo
->conf
;
13412 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
13414 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
13418 /* Implementation of to_load. */
13421 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
13423 generic_load (name
, from_tty
);
13426 /* Accepts an integer PID; returns a string representing a file that
13427 can be opened on the remote side to get the symbols for the child
13428 process. Returns NULL if the operation is not supported. */
13431 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
13433 static char *filename
= NULL
;
13434 struct inferior
*inf
;
13435 char *annex
= NULL
;
13437 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
13440 if (filename
!= NULL
)
13443 inf
= find_inferior_pid (pid
);
13445 internal_error (__FILE__
, __LINE__
,
13446 _("not currently attached to process %d"), pid
);
13448 if (!inf
->fake_pid_p
)
13450 const int annex_size
= 9;
13452 annex
= (char *) alloca (annex_size
);
13453 xsnprintf (annex
, annex_size
, "%x", pid
);
13456 filename
= target_read_stralloc (¤t_target
,
13457 TARGET_OBJECT_EXEC_FILE
, annex
);
13462 /* Implement the to_can_do_single_step target_ops method. */
13465 remote_can_do_single_step (struct target_ops
*ops
)
13467 /* We can only tell whether target supports single step or not by
13468 supported s and S vCont actions if the stub supports vContSupported
13469 feature. If the stub doesn't support vContSupported feature,
13470 we have conservatively to think target doesn't supports single
13472 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13474 struct remote_state
*rs
= get_remote_state ();
13476 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13477 remote_vcont_probe (rs
);
13479 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13485 /* Implementation of the to_execution_direction method for the remote
13488 static enum exec_direction_kind
13489 remote_execution_direction (struct target_ops
*self
)
13491 struct remote_state
*rs
= get_remote_state ();
13493 return rs
->last_resume_exec_dir
;
13497 init_remote_ops (void)
13499 remote_ops
.to_shortname
= "remote";
13500 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13501 remote_ops
.to_doc
=
13502 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13503 Specify the serial device it is connected to\n\
13504 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13505 remote_ops
.to_open
= remote_open
;
13506 remote_ops
.to_close
= remote_close
;
13507 remote_ops
.to_detach
= remote_detach
;
13508 remote_ops
.to_disconnect
= remote_disconnect
;
13509 remote_ops
.to_resume
= remote_resume
;
13510 remote_ops
.to_commit_resume
= remote_commit_resume
;
13511 remote_ops
.to_wait
= remote_wait
;
13512 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13513 remote_ops
.to_store_registers
= remote_store_registers
;
13514 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13515 remote_ops
.to_files_info
= remote_files_info
;
13516 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13517 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13518 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13519 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13520 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13521 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13522 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13523 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13524 remote_ops
.to_watchpoint_addr_within_range
=
13525 remote_watchpoint_addr_within_range
;
13526 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13527 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13528 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13529 remote_ops
.to_region_ok_for_hw_watchpoint
13530 = remote_region_ok_for_hw_watchpoint
;
13531 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13532 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13533 remote_ops
.to_kill
= remote_kill
;
13534 remote_ops
.to_load
= remote_load
;
13535 remote_ops
.to_mourn_inferior
= remote_mourn
;
13536 remote_ops
.to_pass_signals
= remote_pass_signals
;
13537 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13538 remote_ops
.to_program_signals
= remote_program_signals
;
13539 remote_ops
.to_thread_alive
= remote_thread_alive
;
13540 remote_ops
.to_thread_name
= remote_thread_name
;
13541 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13542 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13543 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13544 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13545 remote_ops
.to_stop
= remote_stop
;
13546 remote_ops
.to_interrupt
= remote_interrupt
;
13547 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13548 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13549 remote_ops
.to_get_memory_xfer_limit
= remote_get_memory_xfer_limit
;
13550 remote_ops
.to_rcmd
= remote_rcmd
;
13551 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13552 remote_ops
.to_log_command
= serial_log_command
;
13553 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13554 remote_ops
.to_stratum
= process_stratum
;
13555 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13556 remote_ops
.to_has_memory
= default_child_has_memory
;
13557 remote_ops
.to_has_stack
= default_child_has_stack
;
13558 remote_ops
.to_has_registers
= default_child_has_registers
;
13559 remote_ops
.to_has_execution
= default_child_has_execution
;
13560 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13561 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13562 remote_ops
.to_magic
= OPS_MAGIC
;
13563 remote_ops
.to_memory_map
= remote_memory_map
;
13564 remote_ops
.to_flash_erase
= remote_flash_erase
;
13565 remote_ops
.to_flash_done
= remote_flash_done
;
13566 remote_ops
.to_read_description
= remote_read_description
;
13567 remote_ops
.to_search_memory
= remote_search_memory
;
13568 remote_ops
.to_can_async_p
= remote_can_async_p
;
13569 remote_ops
.to_is_async_p
= remote_is_async_p
;
13570 remote_ops
.to_async
= remote_async
;
13571 remote_ops
.to_thread_events
= remote_thread_events
;
13572 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13573 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13574 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13575 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13576 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13577 remote_ops
.to_supports_disable_randomization
13578 = remote_supports_disable_randomization
;
13579 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13580 remote_ops
.to_fileio_open
= remote_hostio_open
;
13581 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13582 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13583 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13584 remote_ops
.to_fileio_close
= remote_hostio_close
;
13585 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13586 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13587 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13588 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13589 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13590 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13591 remote_ops
.to_trace_init
= remote_trace_init
;
13592 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13593 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13594 remote_ops
.to_download_trace_state_variable
13595 = remote_download_trace_state_variable
;
13596 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13597 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13598 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13599 remote_ops
.to_trace_start
= remote_trace_start
;
13600 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13601 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13602 remote_ops
.to_trace_stop
= remote_trace_stop
;
13603 remote_ops
.to_trace_find
= remote_trace_find
;
13604 remote_ops
.to_get_trace_state_variable_value
13605 = remote_get_trace_state_variable_value
;
13606 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13607 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13608 remote_ops
.to_upload_trace_state_variables
13609 = remote_upload_trace_state_variables
;
13610 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13611 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13612 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13613 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13614 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13615 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13616 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13617 remote_ops
.to_verify_memory
= remote_verify_memory
;
13618 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13619 remote_ops
.to_set_permissions
= remote_set_permissions
;
13620 remote_ops
.to_static_tracepoint_marker_at
13621 = remote_static_tracepoint_marker_at
;
13622 remote_ops
.to_static_tracepoint_markers_by_strid
13623 = remote_static_tracepoint_markers_by_strid
;
13624 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13625 remote_ops
.to_use_agent
= remote_use_agent
;
13626 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13627 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13628 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13629 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13630 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13631 remote_ops
.to_read_btrace
= remote_read_btrace
;
13632 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13633 remote_ops
.to_augmented_libraries_svr4_read
=
13634 remote_augmented_libraries_svr4_read
;
13635 remote_ops
.to_follow_fork
= remote_follow_fork
;
13636 remote_ops
.to_follow_exec
= remote_follow_exec
;
13637 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13638 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13639 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13640 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13641 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13642 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13643 remote_ops
.to_execution_direction
= remote_execution_direction
;
13646 /* Set up the extended remote vector by making a copy of the standard
13647 remote vector and adding to it. */
13650 init_extended_remote_ops (void)
13652 extended_remote_ops
= remote_ops
;
13654 extended_remote_ops
.to_shortname
= "extended-remote";
13655 extended_remote_ops
.to_longname
=
13656 "Extended remote serial target in gdb-specific protocol";
13657 extended_remote_ops
.to_doc
=
13658 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13659 Specify the serial device it is connected to (e.g. /dev/ttya).";
13660 extended_remote_ops
.to_open
= extended_remote_open
;
13661 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13662 extended_remote_ops
.to_detach
= extended_remote_detach
;
13663 extended_remote_ops
.to_attach
= extended_remote_attach
;
13664 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13665 extended_remote_ops
.to_supports_disable_randomization
13666 = extended_remote_supports_disable_randomization
;
13670 remote_can_async_p (struct target_ops
*ops
)
13672 struct remote_state
*rs
= get_remote_state ();
13674 if (!target_async_permitted
)
13675 /* We only enable async when the user specifically asks for it. */
13678 /* We're async whenever the serial device is. */
13679 return serial_can_async_p (rs
->remote_desc
);
13683 remote_is_async_p (struct target_ops
*ops
)
13685 struct remote_state
*rs
= get_remote_state ();
13687 if (!target_async_permitted
)
13688 /* We only enable async when the user specifically asks for it. */
13691 /* We're async whenever the serial device is. */
13692 return serial_is_async_p (rs
->remote_desc
);
13695 /* Pass the SERIAL event on and up to the client. One day this code
13696 will be able to delay notifying the client of an event until the
13697 point where an entire packet has been received. */
13699 static serial_event_ftype remote_async_serial_handler
;
13702 remote_async_serial_handler (struct serial
*scb
, void *context
)
13704 /* Don't propogate error information up to the client. Instead let
13705 the client find out about the error by querying the target. */
13706 inferior_event_handler (INF_REG_EVENT
, NULL
);
13710 remote_async_inferior_event_handler (gdb_client_data data
)
13712 inferior_event_handler (INF_REG_EVENT
, NULL
);
13716 remote_async (struct target_ops
*ops
, int enable
)
13718 struct remote_state
*rs
= get_remote_state ();
13722 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13724 /* If there are pending events in the stop reply queue tell the
13725 event loop to process them. */
13726 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13727 mark_async_event_handler (remote_async_inferior_event_token
);
13728 /* For simplicity, below we clear the pending events token
13729 without remembering whether it is marked, so here we always
13730 mark it. If there's actually no pending notification to
13731 process, this ends up being a no-op (other than a spurious
13732 event-loop wakeup). */
13733 if (target_is_non_stop_p ())
13734 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13738 serial_async (rs
->remote_desc
, NULL
, NULL
);
13739 /* If the core is disabling async, it doesn't want to be
13740 disturbed with target events. Clear all async event sources
13742 clear_async_event_handler (remote_async_inferior_event_token
);
13743 if (target_is_non_stop_p ())
13744 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13748 /* Implementation of the to_thread_events method. */
13751 remote_thread_events (struct target_ops
*ops
, int enable
)
13753 struct remote_state
*rs
= get_remote_state ();
13754 size_t size
= get_remote_packet_size ();
13756 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13759 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13763 switch (packet_ok (rs
->buf
,
13764 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13767 if (strcmp (rs
->buf
, "OK") != 0)
13768 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13771 warning (_("Remote failure reply: %s"), rs
->buf
);
13773 case PACKET_UNKNOWN
:
13779 set_remote_cmd (char *args
, int from_tty
)
13781 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13785 show_remote_cmd (char *args
, int from_tty
)
13787 /* We can't just use cmd_show_list here, because we want to skip
13788 the redundant "show remote Z-packet" and the legacy aliases. */
13789 struct cleanup
*showlist_chain
;
13790 struct cmd_list_element
*list
= remote_show_cmdlist
;
13791 struct ui_out
*uiout
= current_uiout
;
13793 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13794 for (; list
!= NULL
; list
= list
->next
)
13795 if (strcmp (list
->name
, "Z-packet") == 0)
13797 else if (list
->type
== not_set_cmd
)
13798 /* Alias commands are exactly like the original, except they
13799 don't have the normal type. */
13803 struct cleanup
*option_chain
13804 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13806 ui_out_field_string (uiout
, "name", list
->name
);
13807 ui_out_text (uiout
, ": ");
13808 if (list
->type
== show_cmd
)
13809 do_show_command (NULL
, from_tty
, list
);
13811 cmd_func (list
, NULL
, from_tty
);
13812 /* Close the tuple. */
13813 do_cleanups (option_chain
);
13816 /* Close the tuple. */
13817 do_cleanups (showlist_chain
);
13821 /* Function to be called whenever a new objfile (shlib) is detected. */
13823 remote_new_objfile (struct objfile
*objfile
)
13825 struct remote_state
*rs
= get_remote_state ();
13827 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13828 remote_check_symbols ();
13831 /* Pull all the tracepoints defined on the target and create local
13832 data structures representing them. We don't want to create real
13833 tracepoints yet, we don't want to mess up the user's existing
13837 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13839 struct remote_state
*rs
= get_remote_state ();
13842 /* Ask for a first packet of tracepoint definition. */
13844 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13846 while (*p
&& *p
!= 'l')
13848 parse_tracepoint_definition (p
, utpp
);
13849 /* Ask for another packet of tracepoint definition. */
13851 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13858 remote_upload_trace_state_variables (struct target_ops
*self
,
13859 struct uploaded_tsv
**utsvp
)
13861 struct remote_state
*rs
= get_remote_state ();
13864 /* Ask for a first packet of variable definition. */
13866 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13868 while (*p
&& *p
!= 'l')
13870 parse_tsv_definition (p
, utsvp
);
13871 /* Ask for another packet of variable definition. */
13873 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13879 /* The "set/show range-stepping" show hook. */
13882 show_range_stepping (struct ui_file
*file
, int from_tty
,
13883 struct cmd_list_element
*c
,
13886 fprintf_filtered (file
,
13887 _("Debugger's willingness to use range stepping "
13888 "is %s.\n"), value
);
13891 /* The "set/show range-stepping" set hook. */
13894 set_range_stepping (char *ignore_args
, int from_tty
,
13895 struct cmd_list_element
*c
)
13897 struct remote_state
*rs
= get_remote_state ();
13899 /* Whene enabling, check whether range stepping is actually
13900 supported by the target, and warn if not. */
13901 if (use_range_stepping
)
13903 if (rs
->remote_desc
!= NULL
)
13905 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13906 remote_vcont_probe (rs
);
13908 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13909 && rs
->supports_vCont
.r
)
13913 warning (_("Range stepping is not supported by the current target"));
13918 _initialize_remote (void)
13920 struct cmd_list_element
*cmd
;
13921 const char *cmd_name
;
13923 /* architecture specific data */
13924 remote_gdbarch_data_handle
=
13925 gdbarch_data_register_post_init (init_remote_state
);
13926 remote_g_packet_data_handle
=
13927 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13930 = register_program_space_data_with_cleanup (NULL
,
13931 remote_pspace_data_cleanup
);
13933 /* Initialize the per-target state. At the moment there is only one
13934 of these, not one per target. Only one target is active at a
13936 remote_state
= new_remote_state ();
13938 init_remote_ops ();
13939 add_target (&remote_ops
);
13941 init_extended_remote_ops ();
13942 add_target (&extended_remote_ops
);
13944 /* Hook into new objfile notification. */
13945 observer_attach_new_objfile (remote_new_objfile
);
13946 /* We're no longer interested in notification events of an inferior
13948 observer_attach_inferior_exit (discard_pending_stop_replies
);
13951 init_remote_threadtests ();
13954 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13955 /* set/show remote ... */
13957 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13958 Remote protocol specific variables\n\
13959 Configure various remote-protocol specific variables such as\n\
13960 the packets being used"),
13961 &remote_set_cmdlist
, "set remote ",
13962 0 /* allow-unknown */, &setlist
);
13963 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13964 Remote protocol specific variables\n\
13965 Configure various remote-protocol specific variables such as\n\
13966 the packets being used"),
13967 &remote_show_cmdlist
, "show remote ",
13968 0 /* allow-unknown */, &showlist
);
13970 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13971 Compare section data on target to the exec file.\n\
13972 Argument is a single section name (default: all loaded sections).\n\
13973 To compare only read-only loaded sections, specify the -r option."),
13976 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13977 Send an arbitrary packet to a remote target.\n\
13978 maintenance packet TEXT\n\
13979 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13980 this command sends the string TEXT to the inferior, and displays the\n\
13981 response packet. GDB supplies the initial `$' character, and the\n\
13982 terminating `#' character and checksum."),
13985 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13986 Set whether to send break if interrupted."), _("\
13987 Show whether to send break if interrupted."), _("\
13988 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13989 set_remotebreak
, show_remotebreak
,
13990 &setlist
, &showlist
);
13991 cmd_name
= "remotebreak";
13992 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13993 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13994 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13995 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13996 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13998 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13999 interrupt_sequence_modes
, &interrupt_sequence_mode
,
14001 Set interrupt sequence to remote target."), _("\
14002 Show interrupt sequence to remote target."), _("\
14003 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
14004 NULL
, show_interrupt_sequence
,
14005 &remote_set_cmdlist
,
14006 &remote_show_cmdlist
);
14008 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
14009 &interrupt_on_connect
, _("\
14010 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14011 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14012 If set, interrupt sequence is sent to remote target."),
14014 &remote_set_cmdlist
, &remote_show_cmdlist
);
14016 /* Install commands for configuring memory read/write packets. */
14018 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
14019 Set the maximum number of bytes per memory write packet (deprecated)."),
14021 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
14022 Show the maximum number of bytes per memory write packet (deprecated)."),
14024 add_cmd ("memory-write-packet-size", no_class
,
14025 set_memory_write_packet_size
, _("\
14026 Set the maximum number of bytes per memory-write packet.\n\
14027 Specify the number of bytes in a packet or 0 (zero) for the\n\
14028 default packet size. The actual limit is further reduced\n\
14029 dependent on the target. Specify ``fixed'' to disable the\n\
14030 further restriction and ``limit'' to enable that restriction."),
14031 &remote_set_cmdlist
);
14032 add_cmd ("memory-read-packet-size", no_class
,
14033 set_memory_read_packet_size
, _("\
14034 Set the maximum number of bytes per memory-read packet.\n\
14035 Specify the number of bytes in a packet or 0 (zero) for the\n\
14036 default packet size. The actual limit is further reduced\n\
14037 dependent on the target. Specify ``fixed'' to disable the\n\
14038 further restriction and ``limit'' to enable that restriction."),
14039 &remote_set_cmdlist
);
14040 add_cmd ("memory-write-packet-size", no_class
,
14041 show_memory_write_packet_size
,
14042 _("Show the maximum number of bytes per memory-write packet."),
14043 &remote_show_cmdlist
);
14044 add_cmd ("memory-read-packet-size", no_class
,
14045 show_memory_read_packet_size
,
14046 _("Show the maximum number of bytes per memory-read packet."),
14047 &remote_show_cmdlist
);
14049 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
14050 &remote_hw_watchpoint_limit
, _("\
14051 Set the maximum number of target hardware watchpoints."), _("\
14052 Show the maximum number of target hardware watchpoints."), _("\
14053 Specify a negative limit for unlimited."),
14054 NULL
, NULL
, /* FIXME: i18n: The maximum
14055 number of target hardware
14056 watchpoints is %s. */
14057 &remote_set_cmdlist
, &remote_show_cmdlist
);
14058 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
14059 &remote_hw_watchpoint_length_limit
, _("\
14060 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
14061 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
14062 Specify a negative limit for unlimited."),
14063 NULL
, NULL
, /* FIXME: i18n: The maximum
14064 length (in bytes) of a target
14065 hardware watchpoint is %s. */
14066 &remote_set_cmdlist
, &remote_show_cmdlist
);
14067 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
14068 &remote_hw_breakpoint_limit
, _("\
14069 Set the maximum number of target hardware breakpoints."), _("\
14070 Show the maximum number of target hardware breakpoints."), _("\
14071 Specify a negative limit for unlimited."),
14072 NULL
, NULL
, /* FIXME: i18n: The maximum
14073 number of target hardware
14074 breakpoints is %s. */
14075 &remote_set_cmdlist
, &remote_show_cmdlist
);
14077 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
14078 &remote_address_size
, _("\
14079 Set the maximum size of the address (in bits) in a memory packet."), _("\
14080 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
14082 NULL
, /* FIXME: i18n: */
14083 &setlist
, &showlist
);
14085 init_all_packet_configs ();
14087 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
14088 "X", "binary-download", 1);
14090 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
14091 "vCont", "verbose-resume", 0);
14093 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
14094 "QPassSignals", "pass-signals", 0);
14096 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
14097 "QCatchSyscalls", "catch-syscalls", 0);
14099 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
14100 "QProgramSignals", "program-signals", 0);
14102 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
14103 "qSymbol", "symbol-lookup", 0);
14105 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
14106 "P", "set-register", 1);
14108 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
14109 "p", "fetch-register", 1);
14111 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
14112 "Z0", "software-breakpoint", 0);
14114 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
14115 "Z1", "hardware-breakpoint", 0);
14117 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
14118 "Z2", "write-watchpoint", 0);
14120 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
14121 "Z3", "read-watchpoint", 0);
14123 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
14124 "Z4", "access-watchpoint", 0);
14126 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
14127 "qXfer:auxv:read", "read-aux-vector", 0);
14129 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
14130 "qXfer:exec-file:read", "pid-to-exec-file", 0);
14132 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
14133 "qXfer:features:read", "target-features", 0);
14135 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
14136 "qXfer:libraries:read", "library-info", 0);
14138 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
14139 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
14141 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
14142 "qXfer:memory-map:read", "memory-map", 0);
14144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
14145 "qXfer:spu:read", "read-spu-object", 0);
14147 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
14148 "qXfer:spu:write", "write-spu-object", 0);
14150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
14151 "qXfer:osdata:read", "osdata", 0);
14153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
14154 "qXfer:threads:read", "threads", 0);
14156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
14157 "qXfer:siginfo:read", "read-siginfo-object", 0);
14159 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
14160 "qXfer:siginfo:write", "write-siginfo-object", 0);
14162 add_packet_config_cmd
14163 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
14164 "qXfer:traceframe-info:read", "traceframe-info", 0);
14166 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
14167 "qXfer:uib:read", "unwind-info-block", 0);
14169 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
14170 "qGetTLSAddr", "get-thread-local-storage-address",
14173 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
14174 "qGetTIBAddr", "get-thread-information-block-address",
14177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
14178 "bc", "reverse-continue", 0);
14180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
14181 "bs", "reverse-step", 0);
14183 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
14184 "qSupported", "supported-packets", 0);
14186 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
14187 "qSearch:memory", "search-memory", 0);
14189 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
14190 "qTStatus", "trace-status", 0);
14192 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
14193 "vFile:setfs", "hostio-setfs", 0);
14195 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
14196 "vFile:open", "hostio-open", 0);
14198 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
14199 "vFile:pread", "hostio-pread", 0);
14201 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
14202 "vFile:pwrite", "hostio-pwrite", 0);
14204 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
14205 "vFile:close", "hostio-close", 0);
14207 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
14208 "vFile:unlink", "hostio-unlink", 0);
14210 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
14211 "vFile:readlink", "hostio-readlink", 0);
14213 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
14214 "vFile:fstat", "hostio-fstat", 0);
14216 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
14217 "vAttach", "attach", 0);
14219 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
14222 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
14223 "QStartNoAckMode", "noack", 0);
14225 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
14226 "vKill", "kill", 0);
14228 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
14229 "qAttached", "query-attached", 0);
14231 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
14232 "ConditionalTracepoints",
14233 "conditional-tracepoints", 0);
14235 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
14236 "ConditionalBreakpoints",
14237 "conditional-breakpoints", 0);
14239 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
14240 "BreakpointCommands",
14241 "breakpoint-commands", 0);
14243 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
14244 "FastTracepoints", "fast-tracepoints", 0);
14246 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
14247 "TracepointSource", "TracepointSource", 0);
14249 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
14250 "QAllow", "allow", 0);
14252 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
14253 "StaticTracepoints", "static-tracepoints", 0);
14255 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
14256 "InstallInTrace", "install-in-trace", 0);
14258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
14259 "qXfer:statictrace:read", "read-sdata-object", 0);
14261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
14262 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
14264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
14265 "QDisableRandomization", "disable-randomization", 0);
14267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
14268 "QAgent", "agent", 0);
14270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
14271 "QTBuffer:size", "trace-buffer-size", 0);
14273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
14274 "Qbtrace:off", "disable-btrace", 0);
14276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
14277 "Qbtrace:bts", "enable-btrace-bts", 0);
14279 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
14280 "Qbtrace:pt", "enable-btrace-pt", 0);
14282 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
14283 "qXfer:btrace", "read-btrace", 0);
14285 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
14286 "qXfer:btrace-conf", "read-btrace-conf", 0);
14288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
14289 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
14291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
14292 "multiprocess-feature", "multiprocess-feature", 0);
14294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
14295 "swbreak-feature", "swbreak-feature", 0);
14297 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
14298 "hwbreak-feature", "hwbreak-feature", 0);
14300 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
14301 "fork-event-feature", "fork-event-feature", 0);
14303 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
14304 "vfork-event-feature", "vfork-event-feature", 0);
14306 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
14307 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
14309 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
14310 "vContSupported", "verbose-resume-supported", 0);
14312 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
14313 "exec-event-feature", "exec-event-feature", 0);
14315 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
14316 "vCtrlC", "ctrl-c", 0);
14318 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
14319 "QThreadEvents", "thread-events", 0);
14321 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
14322 "N stop reply", "no-resumed-stop-reply", 0);
14324 /* Assert that we've registered "set remote foo-packet" commands
14325 for all packet configs. */
14329 for (i
= 0; i
< PACKET_MAX
; i
++)
14331 /* Ideally all configs would have a command associated. Some
14332 still don't though. */
14337 case PACKET_QNonStop
:
14338 case PACKET_EnableDisableTracepoints_feature
:
14339 case PACKET_tracenz_feature
:
14340 case PACKET_DisconnectedTracing_feature
:
14341 case PACKET_augmented_libraries_svr4_read_feature
:
14343 /* Additions to this list need to be well justified:
14344 pre-existing packets are OK; new packets are not. */
14352 /* This catches both forgetting to add a config command, and
14353 forgetting to remove a packet from the exception list. */
14354 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
14358 /* Keep the old ``set remote Z-packet ...'' working. Each individual
14359 Z sub-packet has its own set and show commands, but users may
14360 have sets to this variable in their .gdbinit files (or in their
14362 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
14363 &remote_Z_packet_detect
, _("\
14364 Set use of remote protocol `Z' packets"), _("\
14365 Show use of remote protocol `Z' packets "), _("\
14366 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
14368 set_remote_protocol_Z_packet_cmd
,
14369 show_remote_protocol_Z_packet_cmd
,
14370 /* FIXME: i18n: Use of remote protocol
14371 `Z' packets is %s. */
14372 &remote_set_cmdlist
, &remote_show_cmdlist
);
14374 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
14375 Manipulate files on the remote system\n\
14376 Transfer files to and from the remote target system."),
14377 &remote_cmdlist
, "remote ",
14378 0 /* allow-unknown */, &cmdlist
);
14380 add_cmd ("put", class_files
, remote_put_command
,
14381 _("Copy a local file to the remote system."),
14384 add_cmd ("get", class_files
, remote_get_command
,
14385 _("Copy a remote file to the local system."),
14388 add_cmd ("delete", class_files
, remote_delete_command
,
14389 _("Delete a remote file."),
14392 add_setshow_string_noescape_cmd ("exec-file", class_files
,
14393 &remote_exec_file_var
, _("\
14394 Set the remote pathname for \"run\""), _("\
14395 Show the remote pathname for \"run\""), NULL
,
14396 set_remote_exec_file
,
14397 show_remote_exec_file
,
14398 &remote_set_cmdlist
,
14399 &remote_show_cmdlist
);
14401 add_setshow_boolean_cmd ("range-stepping", class_run
,
14402 &use_range_stepping
, _("\
14403 Enable or disable range stepping."), _("\
14404 Show whether target-assisted range stepping is enabled."), _("\
14405 If on, and the target supports it, when stepping a source line, GDB\n\
14406 tells the target to step the corresponding range of addresses itself instead\n\
14407 of issuing multiple single-steps. This speeds up source level\n\
14408 stepping. If off, GDB always issues single-steps, even if range\n\
14409 stepping is supported by the target. The default is on."),
14410 set_range_stepping
,
14411 show_range_stepping
,
14415 /* Eventually initialize fileio. See fileio.c */
14416 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
14418 /* Take advantage of the fact that the TID field is not used, to tag
14419 special ptids with it set to != 0. */
14420 magic_null_ptid
= ptid_build (42000, -1, 1);
14421 not_sent_ptid
= ptid_build (42000, -2, 1);
14422 any_thread_ptid
= ptid_build (42000, 0, 1);
14424 target_buf_size
= 2048;
14425 target_buf
= (char *) xmalloc (target_buf_size
);