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"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* Per-program-space data key. */
79 static const struct program_space_data
*remote_pspace_data
;
81 /* The variable registered as the control variable used by the
82 remote exec-file commands. While the remote exec-file setting is
83 per-program-space, the set/show machinery uses this as the
84 location of the remote exec-file value. */
85 static char *remote_exec_file_var
;
87 /* The size to align memory write packets, when practical. The protocol
88 does not guarantee any alignment, and gdb will generate short
89 writes and unaligned writes, but even as a best-effort attempt this
90 can improve bulk transfers. For instance, if a write is misaligned
91 relative to the target's data bus, the stub may need to make an extra
92 round trip fetching data from the target. This doesn't make a
93 huge difference, but it's easy to do, so we try to be helpful.
95 The alignment chosen is arbitrary; usually data bus width is
96 important here, not the possibly larger cache line size. */
97 enum { REMOTE_ALIGN_WRITES
= 16 };
99 /* Prototypes for local functions. */
100 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
101 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
102 int forever
, int *is_notif
);
104 static void remote_files_info (struct target_ops
*ignore
);
106 static void remote_prepare_to_store (struct target_ops
*self
,
107 struct regcache
*regcache
);
109 static void remote_open_1 (const char *, int, struct target_ops
*,
112 static void remote_close (struct target_ops
*self
);
116 static int remote_vkill (int pid
, struct remote_state
*rs
);
118 static void remote_kill_k (void);
120 static void remote_mourn (struct target_ops
*ops
);
122 static void extended_remote_restart (void);
124 static void remote_send (char **buf
, long *sizeof_buf_p
);
126 static int readchar (int timeout
);
128 static void remote_serial_write (const char *str
, int len
);
130 static void remote_kill (struct target_ops
*ops
);
132 static int remote_can_async_p (struct target_ops
*);
134 static int remote_is_async_p (struct target_ops
*);
136 static void remote_async (struct target_ops
*ops
, int enable
);
138 static void remote_thread_events (struct target_ops
*ops
, int enable
);
140 static void interrupt_query (void);
142 static void set_general_thread (struct ptid ptid
);
143 static void set_continue_thread (struct ptid ptid
);
145 static void get_offsets (void);
147 static void skip_frame (void);
149 static long read_frame (char **buf_p
, long *sizeof_buf
);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void remote_stop (struct target_ops
*self
, ptid_t
);
159 static int stubhex (int ch
);
161 static int hexnumstr (char *, ULONGEST
);
163 static int hexnumnstr (char *, ULONGEST
, int);
165 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
167 static void print_packet (const char *);
169 static void compare_sections_command (char *, int);
171 static void packet_command (char *, int);
173 static int stub_unpack_int (char *buff
, int fieldlength
);
175 static ptid_t
remote_current_thread (ptid_t oldptid
);
177 static int putpkt_binary (const char *buf
, int cnt
);
179 static void check_binary_download (CORE_ADDR addr
);
181 struct packet_config
;
183 static void show_packet_config_cmd (struct packet_config
*config
);
185 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
187 struct cmd_list_element
*c
,
190 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
191 static ptid_t
read_ptid (char *buf
, char **obuf
);
193 static void remote_set_permissions (struct target_ops
*self
);
195 static int remote_get_trace_status (struct target_ops
*self
,
196 struct trace_status
*ts
);
198 static int remote_upload_tracepoints (struct target_ops
*self
,
199 struct uploaded_tp
**utpp
);
201 static int remote_upload_trace_state_variables (struct target_ops
*self
,
202 struct uploaded_tsv
**utsvp
);
204 static void remote_query_supported (void);
206 static void remote_check_symbols (void);
208 void _initialize_remote (void);
211 static void stop_reply_xfree (struct stop_reply
*);
212 static void remote_parse_stop_reply (char *, struct stop_reply
*);
213 static void push_stop_reply (struct stop_reply
*);
214 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
215 static int peek_stop_reply (ptid_t ptid
);
217 struct threads_listing_context
;
218 static void remove_new_fork_children (struct threads_listing_context
*);
220 static void remote_async_inferior_event_handler (gdb_client_data
);
222 static void remote_terminal_ours (struct target_ops
*self
);
224 static int remote_read_description_p (struct target_ops
*target
);
226 static void remote_console_output (char *msg
);
228 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
230 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
232 static void remote_btrace_reset (void);
234 static int stop_reply_queue_length (void);
236 static void readahead_cache_invalidate (void);
238 static void remote_unpush_and_throw (void);
242 static struct cmd_list_element
*remote_cmdlist
;
244 /* For "set remote" and "show remote". */
246 static struct cmd_list_element
*remote_set_cmdlist
;
247 static struct cmd_list_element
*remote_show_cmdlist
;
249 /* Stub vCont actions support.
251 Each field is a boolean flag indicating whether the stub reports
252 support for the corresponding action. */
254 struct vCont_action_support
269 /* Controls whether GDB is willing to use range stepping. */
271 static int use_range_stepping
= 1;
273 #define OPAQUETHREADBYTES 8
275 /* a 64 bit opaque identifier */
276 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
278 /* About this many threadisds fit in a packet. */
280 #define MAXTHREADLISTRESULTS 32
282 /* Data for the vFile:pread readahead cache. */
284 struct readahead_cache
286 /* The file descriptor for the file that is being cached. -1 if the
290 /* The offset into the file that the cache buffer corresponds
294 /* The buffer holding the cache contents. */
296 /* The buffer's size. We try to read as much as fits into a packet
300 /* Cache hit and miss counters. */
305 /* Description of the remote protocol state for the currently
306 connected target. This is per-target state, and independent of the
307 selected architecture. */
311 /* A buffer to use for incoming packets, and its current size. The
312 buffer is grown dynamically for larger incoming packets.
313 Outgoing packets may also be constructed in this buffer.
314 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
315 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
320 /* True if we're going through initial connection setup (finding out
321 about the remote side's threads, relocating symbols, etc.). */
324 /* If we negotiated packet size explicitly (and thus can bypass
325 heuristics for the largest packet size that will not overflow
326 a buffer in the stub), this will be set to that packet size.
327 Otherwise zero, meaning to use the guessed size. */
328 long explicit_packet_size
;
330 /* remote_wait is normally called when the target is running and
331 waits for a stop reply packet. But sometimes we need to call it
332 when the target is already stopped. We can send a "?" packet
333 and have remote_wait read the response. Or, if we already have
334 the response, we can stash it in BUF and tell remote_wait to
335 skip calling getpkt. This flag is set when BUF contains a
336 stop reply packet and the target is not waiting. */
337 int cached_wait_status
;
339 /* True, if in no ack mode. That is, neither GDB nor the stub will
340 expect acks from each other. The connection is assumed to be
344 /* True if we're connected in extended remote mode. */
347 /* True if we resumed the target and we're waiting for the target to
348 stop. In the mean time, we can't start another command/query.
349 The remote server wouldn't be ready to process it, so we'd
350 timeout waiting for a reply that would never come and eventually
351 we'd close the connection. This can happen in asynchronous mode
352 because we allow GDB commands while the target is running. */
353 int waiting_for_stop_reply
;
355 /* The status of the stub support for the various vCont actions. */
356 struct vCont_action_support supports_vCont
;
358 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
359 responded to that. */
362 /* True if we saw a Ctrl-C while reading or writing from/to the
363 remote descriptor. At that point it is not safe to send a remote
364 interrupt packet, so we instead remember we saw the Ctrl-C and
365 process it once we're done with sending/receiving the current
366 packet, which should be shortly. If however that takes too long,
367 and the user presses Ctrl-C again, we offer to disconnect. */
368 int got_ctrlc_during_io
;
370 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
371 remote_open knows that we don't have a file open when the program
373 struct serial
*remote_desc
;
375 /* These are the threads which we last sent to the remote system. The
376 TID member will be -1 for all or -2 for not sent yet. */
377 ptid_t general_thread
;
378 ptid_t continue_thread
;
380 /* This is the traceframe which we last selected on the remote system.
381 It will be -1 if no traceframe is selected. */
382 int remote_traceframe_number
;
384 char *last_pass_packet
;
386 /* The last QProgramSignals packet sent to the target. We bypass
387 sending a new program signals list down to the target if the new
388 packet is exactly the same as the last we sent. IOW, we only let
389 the target know about program signals list changes. */
390 char *last_program_signals_packet
;
392 enum gdb_signal last_sent_signal
;
396 char *finished_object
;
397 char *finished_annex
;
398 ULONGEST finished_offset
;
400 /* Should we try the 'ThreadInfo' query packet?
402 This variable (NOT available to the user: auto-detect only!)
403 determines whether GDB will use the new, simpler "ThreadInfo"
404 query or the older, more complex syntax for thread queries.
405 This is an auto-detect variable (set to true at each connect,
406 and set to false when the target fails to recognize it). */
407 int use_threadinfo_query
;
408 int use_threadextra_query
;
410 threadref echo_nextthread
;
411 threadref nextthread
;
412 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
414 /* The state of remote notification. */
415 struct remote_notif_state
*notif_state
;
417 /* The branch trace configuration. */
418 struct btrace_config btrace_config
;
420 /* The argument to the last "vFile:setfs:" packet we sent, used
421 to avoid sending repeated unnecessary "vFile:setfs:" packets.
422 Initialized to -1 to indicate that no "vFile:setfs:" packet
423 has yet been sent. */
426 /* A readahead cache for vFile:pread. Often, reading a binary
427 involves a sequence of small reads. E.g., when parsing an ELF
428 file. A readahead cache helps mostly the case of remote
429 debugging on a connection with higher latency, due to the
430 request/reply nature of the RSP. We only cache data for a single
431 file descriptor at a time. */
432 struct readahead_cache readahead_cache
;
435 /* Private data that we'll store in (struct thread_info)->private. */
436 struct private_thread_info
442 /* Whether the target stopped for a breakpoint/watchpoint. */
443 enum target_stop_reason stop_reason
;
445 /* This is set to the data address of the access causing the target
446 to stop for a watchpoint. */
447 CORE_ADDR watch_data_address
;
451 free_private_thread_info (struct private_thread_info
*info
)
458 /* This data could be associated with a target, but we do not always
459 have access to the current target when we need it, so for now it is
460 static. This will be fine for as long as only one target is in use
462 static struct remote_state
*remote_state
;
464 static struct remote_state
*
465 get_remote_state_raw (void)
470 /* Allocate a new struct remote_state with xmalloc, initialize it, and
473 static struct remote_state
*
474 new_remote_state (void)
476 struct remote_state
*result
= XCNEW (struct remote_state
);
478 /* The default buffer size is unimportant; it will be expanded
479 whenever a larger buffer is needed. */
480 result
->buf_size
= 400;
481 result
->buf
= (char *) xmalloc (result
->buf_size
);
482 result
->remote_traceframe_number
= -1;
483 result
->last_sent_signal
= GDB_SIGNAL_0
;
489 /* Description of the remote protocol for a given architecture. */
493 long offset
; /* Offset into G packet. */
494 long regnum
; /* GDB's internal register number. */
495 LONGEST pnum
; /* Remote protocol register number. */
496 int in_g_packet
; /* Always part of G packet. */
497 /* long size in bytes; == register_size (target_gdbarch (), regnum);
499 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
503 struct remote_arch_state
505 /* Description of the remote protocol registers. */
506 long sizeof_g_packet
;
508 /* Description of the remote protocol registers indexed by REGNUM
509 (making an array gdbarch_num_regs in size). */
510 struct packet_reg
*regs
;
512 /* This is the size (in chars) of the first response to the ``g''
513 packet. It is used as a heuristic when determining the maximum
514 size of memory-read and memory-write packets. A target will
515 typically only reserve a buffer large enough to hold the ``g''
516 packet. The size does not include packet overhead (headers and
518 long actual_register_packet_size
;
520 /* This is the maximum size (in chars) of a non read/write packet.
521 It is also used as a cap on the size of read/write packets. */
522 long remote_packet_size
;
525 /* Utility: generate error from an incoming stub packet. */
527 trace_error (char *buf
)
530 return; /* not an error msg */
533 case '1': /* malformed packet error */
534 if (*++buf
== '0') /* general case: */
535 error (_("remote.c: error in outgoing packet."));
537 error (_("remote.c: error in outgoing packet at field #%ld."),
538 strtol (buf
, NULL
, 16));
540 error (_("Target returns error code '%s'."), buf
);
544 /* Utility: wait for reply from stub, while accepting "O" packets. */
546 remote_get_noisy_reply (char **buf_p
,
549 do /* Loop on reply from remote stub. */
553 QUIT
; /* Allow user to bail out with ^C. */
554 getpkt (buf_p
, sizeof_buf
, 0);
558 else if (startswith (buf
, "qRelocInsn:"))
561 CORE_ADDR from
, to
, org_to
;
563 int adjusted_size
= 0;
566 p
= buf
+ strlen ("qRelocInsn:");
567 pp
= unpack_varlen_hex (p
, &ul
);
569 error (_("invalid qRelocInsn packet: %s"), buf
);
573 unpack_varlen_hex (p
, &ul
);
580 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
583 CATCH (ex
, RETURN_MASK_ALL
)
585 if (ex
.error
== MEMORY_ERROR
)
587 /* Propagate memory errors silently back to the
588 target. The stub may have limited the range of
589 addresses we can write to, for example. */
593 /* Something unexpectedly bad happened. Be verbose
594 so we can tell what, and propagate the error back
595 to the stub, so it doesn't get stuck waiting for
597 exception_fprintf (gdb_stderr
, ex
,
598 _("warning: relocating instruction: "));
606 adjusted_size
= to
- org_to
;
608 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
612 else if (buf
[0] == 'O' && buf
[1] != 'K')
613 remote_console_output (buf
+ 1); /* 'O' message from stub */
615 return buf
; /* Here's the actual reply. */
620 /* Handle for retreving the remote protocol data from gdbarch. */
621 static struct gdbarch_data
*remote_gdbarch_data_handle
;
623 static struct remote_arch_state
*
624 get_remote_arch_state (void)
626 gdb_assert (target_gdbarch () != NULL
);
627 return ((struct remote_arch_state
*)
628 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
631 /* Fetch the global remote target state. */
633 static struct remote_state
*
634 get_remote_state (void)
636 /* Make sure that the remote architecture state has been
637 initialized, because doing so might reallocate rs->buf. Any
638 function which calls getpkt also needs to be mindful of changes
639 to rs->buf, but this call limits the number of places which run
641 get_remote_arch_state ();
643 return get_remote_state_raw ();
646 /* Cleanup routine for the remote module's pspace data. */
649 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
651 char *remote_exec_file
= (char *) arg
;
653 xfree (remote_exec_file
);
656 /* Fetch the remote exec-file from the current program space. */
659 get_remote_exec_file (void)
661 char *remote_exec_file
;
664 = (char *) program_space_data (current_program_space
,
666 if (remote_exec_file
== NULL
)
669 return remote_exec_file
;
672 /* Set the remote exec file for PSPACE. */
675 set_pspace_remote_exec_file (struct program_space
*pspace
,
676 char *remote_exec_file
)
678 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
681 set_program_space_data (pspace
, remote_pspace_data
,
682 xstrdup (remote_exec_file
));
685 /* The "set/show remote exec-file" set command hook. */
688 set_remote_exec_file (char *ignored
, int from_tty
,
689 struct cmd_list_element
*c
)
691 gdb_assert (remote_exec_file_var
!= NULL
);
692 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
695 /* The "set/show remote exec-file" show command hook. */
698 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
699 struct cmd_list_element
*cmd
, const char *value
)
701 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
705 compare_pnums (const void *lhs_
, const void *rhs_
)
707 const struct packet_reg
* const *lhs
708 = (const struct packet_reg
* const *) lhs_
;
709 const struct packet_reg
* const *rhs
710 = (const struct packet_reg
* const *) rhs_
;
712 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
714 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
721 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
723 int regnum
, num_remote_regs
, offset
;
724 struct packet_reg
**remote_regs
;
726 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
728 struct packet_reg
*r
= ®s
[regnum
];
730 if (register_size (gdbarch
, regnum
) == 0)
731 /* Do not try to fetch zero-sized (placeholder) registers. */
734 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
739 /* Define the g/G packet format as the contents of each register
740 with a remote protocol number, in order of ascending protocol
743 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
744 for (num_remote_regs
= 0, regnum
= 0;
745 regnum
< gdbarch_num_regs (gdbarch
);
747 if (regs
[regnum
].pnum
!= -1)
748 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
750 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
753 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
755 remote_regs
[regnum
]->in_g_packet
= 1;
756 remote_regs
[regnum
]->offset
= offset
;
757 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
763 /* Given the architecture described by GDBARCH, return the remote
764 protocol register's number and the register's offset in the g/G
765 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
766 If the target does not have a mapping for REGNUM, return false,
767 otherwise, return true. */
770 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
771 int *pnum
, int *poffset
)
773 struct packet_reg
*regs
;
774 struct cleanup
*old_chain
;
776 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
778 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
779 old_chain
= make_cleanup (xfree
, regs
);
781 map_regcache_remote_table (gdbarch
, regs
);
783 *pnum
= regs
[regnum
].pnum
;
784 *poffset
= regs
[regnum
].offset
;
786 do_cleanups (old_chain
);
792 init_remote_state (struct gdbarch
*gdbarch
)
794 struct remote_state
*rs
= get_remote_state_raw ();
795 struct remote_arch_state
*rsa
;
797 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
799 /* Use the architecture to build a regnum<->pnum table, which will be
800 1:1 unless a feature set specifies otherwise. */
801 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
802 gdbarch_num_regs (gdbarch
),
805 /* Record the maximum possible size of the g packet - it may turn out
807 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
809 /* Default maximum number of characters in a packet body. Many
810 remote stubs have a hardwired buffer size of 400 bytes
811 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
812 as the maximum packet-size to ensure that the packet and an extra
813 NUL character can always fit in the buffer. This stops GDB
814 trashing stubs that try to squeeze an extra NUL into what is
815 already a full buffer (As of 1999-12-04 that was most stubs). */
816 rsa
->remote_packet_size
= 400 - 1;
818 /* This one is filled in when a ``g'' packet is received. */
819 rsa
->actual_register_packet_size
= 0;
821 /* Should rsa->sizeof_g_packet needs more space than the
822 default, adjust the size accordingly. Remember that each byte is
823 encoded as two characters. 32 is the overhead for the packet
824 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
825 (``$NN:G...#NN'') is a better guess, the below has been padded a
827 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
828 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
830 /* Make sure that the packet buffer is plenty big enough for
831 this architecture. */
832 if (rs
->buf_size
< rsa
->remote_packet_size
)
834 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
835 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
841 /* Return the current allowed size of a remote packet. This is
842 inferred from the current architecture, and should be used to
843 limit the length of outgoing packets. */
845 get_remote_packet_size (void)
847 struct remote_state
*rs
= get_remote_state ();
848 struct remote_arch_state
*rsa
= get_remote_arch_state ();
850 if (rs
->explicit_packet_size
)
851 return rs
->explicit_packet_size
;
853 return rsa
->remote_packet_size
;
856 static struct packet_reg
*
857 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
859 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
863 struct packet_reg
*r
= &rsa
->regs
[regnum
];
865 gdb_assert (r
->regnum
== regnum
);
870 static struct packet_reg
*
871 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
875 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
877 struct packet_reg
*r
= &rsa
->regs
[i
];
885 static struct target_ops remote_ops
;
887 static struct target_ops extended_remote_ops
;
889 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
890 ``forever'' still use the normal timeout mechanism. This is
891 currently used by the ASYNC code to guarentee that target reads
892 during the initial connect always time-out. Once getpkt has been
893 modified to return a timeout indication and, in turn
894 remote_wait()/wait_for_inferior() have gained a timeout parameter
896 static int wait_forever_enabled_p
= 1;
898 /* Allow the user to specify what sequence to send to the remote
899 when he requests a program interruption: Although ^C is usually
900 what remote systems expect (this is the default, here), it is
901 sometimes preferable to send a break. On other systems such
902 as the Linux kernel, a break followed by g, which is Magic SysRq g
903 is required in order to interrupt the execution. */
904 const char interrupt_sequence_control_c
[] = "Ctrl-C";
905 const char interrupt_sequence_break
[] = "BREAK";
906 const char interrupt_sequence_break_g
[] = "BREAK-g";
907 static const char *const interrupt_sequence_modes
[] =
909 interrupt_sequence_control_c
,
910 interrupt_sequence_break
,
911 interrupt_sequence_break_g
,
914 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
917 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
918 struct cmd_list_element
*c
,
921 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
922 fprintf_filtered (file
,
923 _("Send the ASCII ETX character (Ctrl-c) "
924 "to the remote target to interrupt the "
925 "execution of the program.\n"));
926 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
927 fprintf_filtered (file
,
928 _("send a break signal to the remote target "
929 "to interrupt the execution of the program.\n"));
930 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
931 fprintf_filtered (file
,
932 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
933 "the remote target to interrupt the execution "
934 "of Linux kernel.\n"));
936 internal_error (__FILE__
, __LINE__
,
937 _("Invalid value for interrupt_sequence_mode: %s."),
938 interrupt_sequence_mode
);
941 /* This boolean variable specifies whether interrupt_sequence is sent
942 to the remote target when gdb connects to it.
943 This is mostly needed when you debug the Linux kernel: The Linux kernel
944 expects BREAK g which is Magic SysRq g for connecting gdb. */
945 static int interrupt_on_connect
= 0;
947 /* This variable is used to implement the "set/show remotebreak" commands.
948 Since these commands are now deprecated in favor of "set/show remote
949 interrupt-sequence", it no longer has any effect on the code. */
950 static int remote_break
;
953 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
956 interrupt_sequence_mode
= interrupt_sequence_break
;
958 interrupt_sequence_mode
= interrupt_sequence_control_c
;
962 show_remotebreak (struct ui_file
*file
, int from_tty
,
963 struct cmd_list_element
*c
,
968 /* This variable sets the number of bits in an address that are to be
969 sent in a memory ("M" or "m") packet. Normally, after stripping
970 leading zeros, the entire address would be sent. This variable
971 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
972 initial implementation of remote.c restricted the address sent in
973 memory packets to ``host::sizeof long'' bytes - (typically 32
974 bits). Consequently, for 64 bit targets, the upper 32 bits of an
975 address was never sent. Since fixing this bug may cause a break in
976 some remote targets this variable is principly provided to
977 facilitate backward compatibility. */
979 static unsigned int remote_address_size
;
981 /* Temporary to track who currently owns the terminal. See
982 remote_terminal_* for more details. */
984 static int remote_async_terminal_ours_p
;
987 /* User configurable variables for the number of characters in a
988 memory read/write packet. MIN (rsa->remote_packet_size,
989 rsa->sizeof_g_packet) is the default. Some targets need smaller
990 values (fifo overruns, et.al.) and some users need larger values
991 (speed up transfers). The variables ``preferred_*'' (the user
992 request), ``current_*'' (what was actually set) and ``forced_*''
993 (Positive - a soft limit, negative - a hard limit). */
995 struct memory_packet_config
1002 /* The default max memory-write-packet-size. The 16k is historical.
1003 (It came from older GDB's using alloca for buffers and the
1004 knowledge (folklore?) that some hosts don't cope very well with
1005 large alloca calls.) */
1006 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1008 /* The minimum remote packet size for memory transfers. Ensures we
1009 can write at least one byte. */
1010 #define MIN_MEMORY_PACKET_SIZE 20
1012 /* Compute the current size of a read/write packet. Since this makes
1013 use of ``actual_register_packet_size'' the computation is dynamic. */
1016 get_memory_packet_size (struct memory_packet_config
*config
)
1018 struct remote_state
*rs
= get_remote_state ();
1019 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1022 if (config
->fixed_p
)
1024 if (config
->size
<= 0)
1025 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1027 what_they_get
= config
->size
;
1031 what_they_get
= get_remote_packet_size ();
1032 /* Limit the packet to the size specified by the user. */
1033 if (config
->size
> 0
1034 && what_they_get
> config
->size
)
1035 what_they_get
= config
->size
;
1037 /* Limit it to the size of the targets ``g'' response unless we have
1038 permission from the stub to use a larger packet size. */
1039 if (rs
->explicit_packet_size
== 0
1040 && rsa
->actual_register_packet_size
> 0
1041 && what_they_get
> rsa
->actual_register_packet_size
)
1042 what_they_get
= rsa
->actual_register_packet_size
;
1044 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1045 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1047 /* Make sure there is room in the global buffer for this packet
1048 (including its trailing NUL byte). */
1049 if (rs
->buf_size
< what_they_get
+ 1)
1051 rs
->buf_size
= 2 * what_they_get
;
1052 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1055 return what_they_get
;
1058 /* Update the size of a read/write packet. If they user wants
1059 something really big then do a sanity check. */
1062 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1064 int fixed_p
= config
->fixed_p
;
1065 long size
= config
->size
;
1068 error (_("Argument required (integer, `fixed' or `limited')."));
1069 else if (strcmp (args
, "hard") == 0
1070 || strcmp (args
, "fixed") == 0)
1072 else if (strcmp (args
, "soft") == 0
1073 || strcmp (args
, "limit") == 0)
1079 size
= strtoul (args
, &end
, 0);
1081 error (_("Invalid %s (bad syntax)."), config
->name
);
1083 /* Instead of explicitly capping the size of a packet to or
1084 disallowing it, the user is allowed to set the size to
1085 something arbitrarily large. */
1088 /* So that the query shows the correct value. */
1090 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1093 if (fixed_p
&& !config
->fixed_p
)
1095 if (! query (_("The target may not be able to correctly handle a %s\n"
1096 "of %ld bytes. Change the packet size? "),
1097 config
->name
, size
))
1098 error (_("Packet size not changed."));
1100 /* Update the config. */
1101 config
->fixed_p
= fixed_p
;
1102 config
->size
= size
;
1106 show_memory_packet_size (struct memory_packet_config
*config
)
1108 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1109 if (config
->fixed_p
)
1110 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1111 get_memory_packet_size (config
));
1113 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1114 get_memory_packet_size (config
));
1117 static struct memory_packet_config memory_write_packet_config
=
1119 "memory-write-packet-size",
1123 set_memory_write_packet_size (char *args
, int from_tty
)
1125 set_memory_packet_size (args
, &memory_write_packet_config
);
1129 show_memory_write_packet_size (char *args
, int from_tty
)
1131 show_memory_packet_size (&memory_write_packet_config
);
1135 get_memory_write_packet_size (void)
1137 return get_memory_packet_size (&memory_write_packet_config
);
1140 static struct memory_packet_config memory_read_packet_config
=
1142 "memory-read-packet-size",
1146 set_memory_read_packet_size (char *args
, int from_tty
)
1148 set_memory_packet_size (args
, &memory_read_packet_config
);
1152 show_memory_read_packet_size (char *args
, int from_tty
)
1154 show_memory_packet_size (&memory_read_packet_config
);
1158 get_memory_read_packet_size (void)
1160 long size
= get_memory_packet_size (&memory_read_packet_config
);
1162 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1163 extra buffer size argument before the memory read size can be
1164 increased beyond this. */
1165 if (size
> get_remote_packet_size ())
1166 size
= get_remote_packet_size ();
1171 /* Generic configuration support for packets the stub optionally
1172 supports. Allows the user to specify the use of the packet as well
1173 as allowing GDB to auto-detect support in the remote stub. */
1177 PACKET_SUPPORT_UNKNOWN
= 0,
1182 struct packet_config
1187 /* If auto, GDB auto-detects support for this packet or feature,
1188 either through qSupported, or by trying the packet and looking
1189 at the response. If true, GDB assumes the target supports this
1190 packet. If false, the packet is disabled. Configs that don't
1191 have an associated command always have this set to auto. */
1192 enum auto_boolean detect
;
1194 /* Does the target support this packet? */
1195 enum packet_support support
;
1198 /* Analyze a packet's return value and update the packet config
1208 static enum packet_support
packet_config_support (struct packet_config
*config
);
1209 static enum packet_support
packet_support (int packet
);
1212 show_packet_config_cmd (struct packet_config
*config
)
1214 char *support
= "internal-error";
1216 switch (packet_config_support (config
))
1219 support
= "enabled";
1221 case PACKET_DISABLE
:
1222 support
= "disabled";
1224 case PACKET_SUPPORT_UNKNOWN
:
1225 support
= "unknown";
1228 switch (config
->detect
)
1230 case AUTO_BOOLEAN_AUTO
:
1231 printf_filtered (_("Support for the `%s' packet "
1232 "is auto-detected, currently %s.\n"),
1233 config
->name
, support
);
1235 case AUTO_BOOLEAN_TRUE
:
1236 case AUTO_BOOLEAN_FALSE
:
1237 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1238 config
->name
, support
);
1244 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1245 const char *title
, int legacy
)
1251 config
->name
= name
;
1252 config
->title
= title
;
1253 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1255 show_doc
= xstrprintf ("Show current use of remote "
1256 "protocol `%s' (%s) packet",
1258 /* set/show TITLE-packet {auto,on,off} */
1259 cmd_name
= xstrprintf ("%s-packet", title
);
1260 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1261 &config
->detect
, set_doc
,
1262 show_doc
, NULL
, /* help_doc */
1264 show_remote_protocol_packet_cmd
,
1265 &remote_set_cmdlist
, &remote_show_cmdlist
);
1266 /* The command code copies the documentation strings. */
1269 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1274 legacy_name
= xstrprintf ("%s-packet", name
);
1275 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1276 &remote_set_cmdlist
);
1277 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1278 &remote_show_cmdlist
);
1282 static enum packet_result
1283 packet_check_result (const char *buf
)
1287 /* The stub recognized the packet request. Check that the
1288 operation succeeded. */
1290 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1292 /* "Enn" - definitly an error. */
1293 return PACKET_ERROR
;
1295 /* Always treat "E." as an error. This will be used for
1296 more verbose error messages, such as E.memtypes. */
1297 if (buf
[0] == 'E' && buf
[1] == '.')
1298 return PACKET_ERROR
;
1300 /* The packet may or may not be OK. Just assume it is. */
1304 /* The stub does not support the packet. */
1305 return PACKET_UNKNOWN
;
1308 static enum packet_result
1309 packet_ok (const char *buf
, struct packet_config
*config
)
1311 enum packet_result result
;
1313 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1314 && config
->support
== PACKET_DISABLE
)
1315 internal_error (__FILE__
, __LINE__
,
1316 _("packet_ok: attempt to use a disabled packet"));
1318 result
= packet_check_result (buf
);
1323 /* The stub recognized the packet request. */
1324 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1327 fprintf_unfiltered (gdb_stdlog
,
1328 "Packet %s (%s) is supported\n",
1329 config
->name
, config
->title
);
1330 config
->support
= PACKET_ENABLE
;
1333 case PACKET_UNKNOWN
:
1334 /* The stub does not support the packet. */
1335 if (config
->detect
== AUTO_BOOLEAN_AUTO
1336 && config
->support
== PACKET_ENABLE
)
1338 /* If the stub previously indicated that the packet was
1339 supported then there is a protocol error. */
1340 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1341 config
->name
, config
->title
);
1343 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1345 /* The user set it wrong. */
1346 error (_("Enabled packet %s (%s) not recognized by stub"),
1347 config
->name
, config
->title
);
1351 fprintf_unfiltered (gdb_stdlog
,
1352 "Packet %s (%s) is NOT supported\n",
1353 config
->name
, config
->title
);
1354 config
->support
= PACKET_DISABLE
;
1375 PACKET_vFile_pwrite
,
1377 PACKET_vFile_unlink
,
1378 PACKET_vFile_readlink
,
1381 PACKET_qXfer_features
,
1382 PACKET_qXfer_exec_file
,
1383 PACKET_qXfer_libraries
,
1384 PACKET_qXfer_libraries_svr4
,
1385 PACKET_qXfer_memory_map
,
1386 PACKET_qXfer_spu_read
,
1387 PACKET_qXfer_spu_write
,
1388 PACKET_qXfer_osdata
,
1389 PACKET_qXfer_threads
,
1390 PACKET_qXfer_statictrace_read
,
1391 PACKET_qXfer_traceframe_info
,
1397 PACKET_QPassSignals
,
1398 PACKET_QCatchSyscalls
,
1399 PACKET_QProgramSignals
,
1401 PACKET_qSearch_memory
,
1404 PACKET_QStartNoAckMode
,
1406 PACKET_qXfer_siginfo_read
,
1407 PACKET_qXfer_siginfo_write
,
1410 /* Support for conditional tracepoints. */
1411 PACKET_ConditionalTracepoints
,
1413 /* Support for target-side breakpoint conditions. */
1414 PACKET_ConditionalBreakpoints
,
1416 /* Support for target-side breakpoint commands. */
1417 PACKET_BreakpointCommands
,
1419 /* Support for fast tracepoints. */
1420 PACKET_FastTracepoints
,
1422 /* Support for static tracepoints. */
1423 PACKET_StaticTracepoints
,
1425 /* Support for installing tracepoints while a trace experiment is
1427 PACKET_InstallInTrace
,
1431 PACKET_TracepointSource
,
1434 PACKET_QDisableRandomization
,
1436 PACKET_QTBuffer_size
,
1440 PACKET_qXfer_btrace
,
1442 /* Support for the QNonStop packet. */
1445 /* Support for the QThreadEvents packet. */
1446 PACKET_QThreadEvents
,
1448 /* Support for multi-process extensions. */
1449 PACKET_multiprocess_feature
,
1451 /* Support for enabling and disabling tracepoints while a trace
1452 experiment is running. */
1453 PACKET_EnableDisableTracepoints_feature
,
1455 /* Support for collecting strings using the tracenz bytecode. */
1456 PACKET_tracenz_feature
,
1458 /* Support for continuing to run a trace experiment while GDB is
1460 PACKET_DisconnectedTracing_feature
,
1462 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1463 PACKET_augmented_libraries_svr4_read_feature
,
1465 /* Support for the qXfer:btrace-conf:read packet. */
1466 PACKET_qXfer_btrace_conf
,
1468 /* Support for the Qbtrace-conf:bts:size packet. */
1469 PACKET_Qbtrace_conf_bts_size
,
1471 /* Support for swbreak+ feature. */
1472 PACKET_swbreak_feature
,
1474 /* Support for hwbreak+ feature. */
1475 PACKET_hwbreak_feature
,
1477 /* Support for fork events. */
1478 PACKET_fork_event_feature
,
1480 /* Support for vfork events. */
1481 PACKET_vfork_event_feature
,
1483 /* Support for the Qbtrace-conf:pt:size packet. */
1484 PACKET_Qbtrace_conf_pt_size
,
1486 /* Support for exec events. */
1487 PACKET_exec_event_feature
,
1489 /* Support for query supported vCont actions. */
1490 PACKET_vContSupported
,
1492 /* Support remote CTRL-C. */
1495 /* Support TARGET_WAITKIND_NO_RESUMED. */
1501 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1503 /* Returns the packet's corresponding "set remote foo-packet" command
1504 state. See struct packet_config for more details. */
1506 static enum auto_boolean
1507 packet_set_cmd_state (int packet
)
1509 return remote_protocol_packets
[packet
].detect
;
1512 /* Returns whether a given packet or feature is supported. This takes
1513 into account the state of the corresponding "set remote foo-packet"
1514 command, which may be used to bypass auto-detection. */
1516 static enum packet_support
1517 packet_config_support (struct packet_config
*config
)
1519 switch (config
->detect
)
1521 case AUTO_BOOLEAN_TRUE
:
1522 return PACKET_ENABLE
;
1523 case AUTO_BOOLEAN_FALSE
:
1524 return PACKET_DISABLE
;
1525 case AUTO_BOOLEAN_AUTO
:
1526 return config
->support
;
1528 gdb_assert_not_reached (_("bad switch"));
1532 /* Same as packet_config_support, but takes the packet's enum value as
1535 static enum packet_support
1536 packet_support (int packet
)
1538 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1540 return packet_config_support (config
);
1544 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1545 struct cmd_list_element
*c
,
1548 struct packet_config
*packet
;
1550 for (packet
= remote_protocol_packets
;
1551 packet
< &remote_protocol_packets
[PACKET_MAX
];
1554 if (&packet
->detect
== c
->var
)
1556 show_packet_config_cmd (packet
);
1560 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1564 /* Should we try one of the 'Z' requests? */
1568 Z_PACKET_SOFTWARE_BP
,
1569 Z_PACKET_HARDWARE_BP
,
1576 /* For compatibility with older distributions. Provide a ``set remote
1577 Z-packet ...'' command that updates all the Z packet types. */
1579 static enum auto_boolean remote_Z_packet_detect
;
1582 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1583 struct cmd_list_element
*c
)
1587 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1588 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1592 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1593 struct cmd_list_element
*c
,
1598 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1600 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1604 /* Returns true if the multi-process extensions are in effect. */
1607 remote_multi_process_p (struct remote_state
*rs
)
1609 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1612 /* Returns true if fork events are supported. */
1615 remote_fork_event_p (struct remote_state
*rs
)
1617 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1620 /* Returns true if vfork events are supported. */
1623 remote_vfork_event_p (struct remote_state
*rs
)
1625 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1628 /* Returns true if exec events are supported. */
1631 remote_exec_event_p (struct remote_state
*rs
)
1633 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1636 /* Insert fork catchpoint target routine. If fork events are enabled
1637 then return success, nothing more to do. */
1640 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1642 struct remote_state
*rs
= get_remote_state ();
1644 return !remote_fork_event_p (rs
);
1647 /* Remove fork catchpoint target routine. Nothing to do, just
1651 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1656 /* Insert vfork catchpoint target routine. If vfork events are enabled
1657 then return success, nothing more to do. */
1660 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1662 struct remote_state
*rs
= get_remote_state ();
1664 return !remote_vfork_event_p (rs
);
1667 /* Remove vfork catchpoint target routine. Nothing to do, just
1671 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1676 /* Insert exec catchpoint target routine. If exec events are
1677 enabled, just return success. */
1680 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1682 struct remote_state
*rs
= get_remote_state ();
1684 return !remote_exec_event_p (rs
);
1687 /* Remove exec catchpoint target routine. Nothing to do, just
1691 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1697 /* Asynchronous signal handle registered as event loop source for
1698 when we have pending events ready to be passed to the core. */
1700 static struct async_event_handler
*remote_async_inferior_event_token
;
1704 static ptid_t magic_null_ptid
;
1705 static ptid_t not_sent_ptid
;
1706 static ptid_t any_thread_ptid
;
1708 /* Find out if the stub attached to PID (and hence GDB should offer to
1709 detach instead of killing it when bailing out). */
1712 remote_query_attached (int pid
)
1714 struct remote_state
*rs
= get_remote_state ();
1715 size_t size
= get_remote_packet_size ();
1717 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1720 if (remote_multi_process_p (rs
))
1721 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1723 xsnprintf (rs
->buf
, size
, "qAttached");
1726 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1728 switch (packet_ok (rs
->buf
,
1729 &remote_protocol_packets
[PACKET_qAttached
]))
1732 if (strcmp (rs
->buf
, "1") == 0)
1736 warning (_("Remote failure reply: %s"), rs
->buf
);
1738 case PACKET_UNKNOWN
:
1745 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1746 has been invented by GDB, instead of reported by the target. Since
1747 we can be connected to a remote system before before knowing about
1748 any inferior, mark the target with execution when we find the first
1749 inferior. If ATTACHED is 1, then we had just attached to this
1750 inferior. If it is 0, then we just created this inferior. If it
1751 is -1, then try querying the remote stub to find out if it had
1752 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1753 attempt to open this inferior's executable as the main executable
1754 if no main executable is open already. */
1756 static struct inferior
*
1757 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1760 struct inferior
*inf
;
1762 /* Check whether this process we're learning about is to be
1763 considered attached, or if is to be considered to have been
1764 spawned by the stub. */
1766 attached
= remote_query_attached (pid
);
1768 if (gdbarch_has_global_solist (target_gdbarch ()))
1770 /* If the target shares code across all inferiors, then every
1771 attach adds a new inferior. */
1772 inf
= add_inferior (pid
);
1774 /* ... and every inferior is bound to the same program space.
1775 However, each inferior may still have its own address
1777 inf
->aspace
= maybe_new_address_space ();
1778 inf
->pspace
= current_program_space
;
1782 /* In the traditional debugging scenario, there's a 1-1 match
1783 between program/address spaces. We simply bind the inferior
1784 to the program space's address space. */
1785 inf
= current_inferior ();
1786 inferior_appeared (inf
, pid
);
1789 inf
->attach_flag
= attached
;
1790 inf
->fake_pid_p
= fake_pid_p
;
1792 /* If no main executable is currently open then attempt to
1793 open the file that was executed to create this inferior. */
1794 if (try_open_exec
&& get_exec_file (0) == NULL
)
1795 exec_file_locate_attach (pid
, 1);
1800 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1801 according to RUNNING. */
1804 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1806 struct remote_state
*rs
= get_remote_state ();
1808 /* GDB historically didn't pull threads in the initial connection
1809 setup. If the remote target doesn't even have a concept of
1810 threads (e.g., a bare-metal target), even if internally we
1811 consider that a single-threaded target, mentioning a new thread
1812 might be confusing to the user. Be silent then, preserving the
1813 age old behavior. */
1814 if (rs
->starting_up
)
1815 add_thread_silent (ptid
);
1819 set_executing (ptid
, executing
);
1820 set_running (ptid
, running
);
1823 /* Come here when we learn about a thread id from the remote target.
1824 It may be the first time we hear about such thread, so take the
1825 opportunity to add it to GDB's thread list. In case this is the
1826 first time we're noticing its corresponding inferior, add it to
1827 GDB's inferior list as well. EXECUTING indicates whether the
1828 thread is (internally) executing or stopped. */
1831 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1833 /* In non-stop mode, we assume new found threads are (externally)
1834 running until proven otherwise with a stop reply. In all-stop,
1835 we can only get here if all threads are stopped. */
1836 int running
= target_is_non_stop_p () ? 1 : 0;
1838 /* If this is a new thread, add it to GDB's thread list.
1839 If we leave it up to WFI to do this, bad things will happen. */
1841 if (in_thread_list (currthread
) && is_exited (currthread
))
1843 /* We're seeing an event on a thread id we knew had exited.
1844 This has to be a new thread reusing the old id. Add it. */
1845 remote_add_thread (currthread
, running
, executing
);
1849 if (!in_thread_list (currthread
))
1851 struct inferior
*inf
= NULL
;
1852 int pid
= ptid_get_pid (currthread
);
1854 if (ptid_is_pid (inferior_ptid
)
1855 && pid
== ptid_get_pid (inferior_ptid
))
1857 /* inferior_ptid has no thread member yet. This can happen
1858 with the vAttach -> remote_wait,"TAAthread:" path if the
1859 stub doesn't support qC. This is the first stop reported
1860 after an attach, so this is the main thread. Update the
1861 ptid in the thread list. */
1862 if (in_thread_list (pid_to_ptid (pid
)))
1863 thread_change_ptid (inferior_ptid
, currthread
);
1866 remote_add_thread (currthread
, running
, executing
);
1867 inferior_ptid
= currthread
;
1872 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1874 /* inferior_ptid is not set yet. This can happen with the
1875 vRun -> remote_wait,"TAAthread:" path if the stub
1876 doesn't support qC. This is the first stop reported
1877 after an attach, so this is the main thread. Update the
1878 ptid in the thread list. */
1879 thread_change_ptid (inferior_ptid
, currthread
);
1883 /* When connecting to a target remote, or to a target
1884 extended-remote which already was debugging an inferior, we
1885 may not know about it yet. Add it before adding its child
1886 thread, so notifications are emitted in a sensible order. */
1887 if (!in_inferior_list (ptid_get_pid (currthread
)))
1889 struct remote_state
*rs
= get_remote_state ();
1890 int fake_pid_p
= !remote_multi_process_p (rs
);
1892 inf
= remote_add_inferior (fake_pid_p
,
1893 ptid_get_pid (currthread
), -1, 1);
1896 /* This is really a new thread. Add it. */
1897 remote_add_thread (currthread
, running
, executing
);
1899 /* If we found a new inferior, let the common code do whatever
1900 it needs to with it (e.g., read shared libraries, insert
1901 breakpoints), unless we're just setting up an all-stop
1905 struct remote_state
*rs
= get_remote_state ();
1907 if (!rs
->starting_up
)
1908 notice_new_inferior (currthread
, executing
, 0);
1913 /* Return the private thread data, creating it if necessary. */
1915 static struct private_thread_info
*
1916 demand_private_info (ptid_t ptid
)
1918 struct thread_info
*info
= find_thread_ptid (ptid
);
1924 info
->priv
= XNEW (struct private_thread_info
);
1925 info
->private_dtor
= free_private_thread_info
;
1926 info
->priv
->core
= -1;
1927 info
->priv
->extra
= NULL
;
1928 info
->priv
->name
= NULL
;
1934 /* Call this function as a result of
1935 1) A halt indication (T packet) containing a thread id
1936 2) A direct query of currthread
1937 3) Successful execution of set thread */
1940 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1942 rs
->general_thread
= currthread
;
1945 /* If 'QPassSignals' is supported, tell the remote stub what signals
1946 it can simply pass through to the inferior without reporting. */
1949 remote_pass_signals (struct target_ops
*self
,
1950 int numsigs
, unsigned char *pass_signals
)
1952 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1954 char *pass_packet
, *p
;
1956 struct remote_state
*rs
= get_remote_state ();
1958 gdb_assert (numsigs
< 256);
1959 for (i
= 0; i
< numsigs
; i
++)
1961 if (pass_signals
[i
])
1964 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1965 strcpy (pass_packet
, "QPassSignals:");
1966 p
= pass_packet
+ strlen (pass_packet
);
1967 for (i
= 0; i
< numsigs
; i
++)
1969 if (pass_signals
[i
])
1972 *p
++ = tohex (i
>> 4);
1973 *p
++ = tohex (i
& 15);
1982 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1984 putpkt (pass_packet
);
1985 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1986 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1987 if (rs
->last_pass_packet
)
1988 xfree (rs
->last_pass_packet
);
1989 rs
->last_pass_packet
= pass_packet
;
1992 xfree (pass_packet
);
1996 /* If 'QCatchSyscalls' is supported, tell the remote stub
1997 to report syscalls to GDB. */
2000 remote_set_syscall_catchpoint (struct target_ops
*self
,
2001 int pid
, int needed
, int any_count
,
2002 int table_size
, int *table
)
2005 enum packet_result result
;
2008 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2010 /* Not supported. */
2014 if (needed
&& !any_count
)
2018 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2019 for (i
= 0; i
< table_size
; i
++)
2028 fprintf_unfiltered (gdb_stdlog
,
2029 "remote_set_syscall_catchpoint "
2030 "pid %d needed %d any_count %d n_sysno %d\n",
2031 pid
, needed
, any_count
, n_sysno
);
2036 /* Prepare a packet with the sysno list, assuming max 8+1
2037 characters for a sysno. If the resulting packet size is too
2038 big, fallback on the non-selective packet. */
2039 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2041 catch_packet
= (char *) xmalloc (maxpktsz
);
2042 strcpy (catch_packet
, "QCatchSyscalls:1");
2051 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2052 for (i
= 0; i
< table_size
; i
++)
2055 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2058 if (strlen (catch_packet
) > get_remote_packet_size ())
2060 /* catch_packet too big. Fallback to less efficient
2061 non selective mode, with GDB doing the filtering. */
2062 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2066 catch_packet
= xstrdup ("QCatchSyscalls:0");
2069 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2070 struct remote_state
*rs
= get_remote_state ();
2072 putpkt (catch_packet
);
2073 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2074 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2075 do_cleanups (old_chain
);
2076 if (result
== PACKET_OK
)
2083 /* If 'QProgramSignals' is supported, tell the remote stub what
2084 signals it should pass through to the inferior when detaching. */
2087 remote_program_signals (struct target_ops
*self
,
2088 int numsigs
, unsigned char *signals
)
2090 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2094 struct remote_state
*rs
= get_remote_state ();
2096 gdb_assert (numsigs
< 256);
2097 for (i
= 0; i
< numsigs
; i
++)
2102 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2103 strcpy (packet
, "QProgramSignals:");
2104 p
= packet
+ strlen (packet
);
2105 for (i
= 0; i
< numsigs
; i
++)
2107 if (signal_pass_state (i
))
2110 *p
++ = tohex (i
>> 4);
2111 *p
++ = tohex (i
& 15);
2120 if (!rs
->last_program_signals_packet
2121 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2124 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2125 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2126 xfree (rs
->last_program_signals_packet
);
2127 rs
->last_program_signals_packet
= packet
;
2134 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2135 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2136 thread. If GEN is set, set the general thread, if not, then set
2137 the step/continue thread. */
2139 set_thread (struct ptid ptid
, int gen
)
2141 struct remote_state
*rs
= get_remote_state ();
2142 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2143 char *buf
= rs
->buf
;
2144 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2146 if (ptid_equal (state
, ptid
))
2150 *buf
++ = gen
? 'g' : 'c';
2151 if (ptid_equal (ptid
, magic_null_ptid
))
2152 xsnprintf (buf
, endbuf
- buf
, "0");
2153 else if (ptid_equal (ptid
, any_thread_ptid
))
2154 xsnprintf (buf
, endbuf
- buf
, "0");
2155 else if (ptid_equal (ptid
, minus_one_ptid
))
2156 xsnprintf (buf
, endbuf
- buf
, "-1");
2158 write_ptid (buf
, endbuf
, ptid
);
2160 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2162 rs
->general_thread
= ptid
;
2164 rs
->continue_thread
= ptid
;
2168 set_general_thread (struct ptid ptid
)
2170 set_thread (ptid
, 1);
2174 set_continue_thread (struct ptid ptid
)
2176 set_thread (ptid
, 0);
2179 /* Change the remote current process. Which thread within the process
2180 ends up selected isn't important, as long as it is the same process
2181 as what INFERIOR_PTID points to.
2183 This comes from that fact that there is no explicit notion of
2184 "selected process" in the protocol. The selected process for
2185 general operations is the process the selected general thread
2189 set_general_process (void)
2191 struct remote_state
*rs
= get_remote_state ();
2193 /* If the remote can't handle multiple processes, don't bother. */
2194 if (!remote_multi_process_p (rs
))
2197 /* We only need to change the remote current thread if it's pointing
2198 at some other process. */
2199 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2200 set_general_thread (inferior_ptid
);
2204 /* Return nonzero if this is the main thread that we made up ourselves
2205 to model non-threaded targets as single-threaded. */
2208 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2210 if (ptid_equal (ptid
, magic_null_ptid
))
2211 /* The main thread is always alive. */
2214 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2215 /* The main thread is always alive. This can happen after a
2216 vAttach, if the remote side doesn't support
2223 /* Return nonzero if the thread PTID is still alive on the remote
2227 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2229 struct remote_state
*rs
= get_remote_state ();
2232 /* Check if this is a thread that we made up ourselves to model
2233 non-threaded targets as single-threaded. */
2234 if (remote_thread_always_alive (ops
, ptid
))
2238 endp
= rs
->buf
+ get_remote_packet_size ();
2241 write_ptid (p
, endp
, ptid
);
2244 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2245 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2248 /* Return a pointer to a thread name if we know it and NULL otherwise.
2249 The thread_info object owns the memory for the name. */
2252 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2254 if (info
->priv
!= NULL
)
2255 return info
->priv
->name
;
2260 /* About these extended threadlist and threadinfo packets. They are
2261 variable length packets but, the fields within them are often fixed
2262 length. They are redundent enough to send over UDP as is the
2263 remote protocol in general. There is a matching unit test module
2266 /* WARNING: This threadref data structure comes from the remote O.S.,
2267 libstub protocol encoding, and remote.c. It is not particularly
2270 /* Right now, the internal structure is int. We want it to be bigger.
2271 Plan to fix this. */
2273 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2275 /* gdb_ext_thread_info is an internal GDB data structure which is
2276 equivalent to the reply of the remote threadinfo packet. */
2278 struct gdb_ext_thread_info
2280 threadref threadid
; /* External form of thread reference. */
2281 int active
; /* Has state interesting to GDB?
2283 char display
[256]; /* Brief state display, name,
2284 blocked/suspended. */
2285 char shortname
[32]; /* To be used to name threads. */
2286 char more_display
[256]; /* Long info, statistics, queue depth,
2290 /* The volume of remote transfers can be limited by submitting
2291 a mask containing bits specifying the desired information.
2292 Use a union of these values as the 'selection' parameter to
2293 get_thread_info. FIXME: Make these TAG names more thread specific. */
2295 #define TAG_THREADID 1
2296 #define TAG_EXISTS 2
2297 #define TAG_DISPLAY 4
2298 #define TAG_THREADNAME 8
2299 #define TAG_MOREDISPLAY 16
2301 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2303 static char *unpack_nibble (char *buf
, int *val
);
2305 static char *unpack_byte (char *buf
, int *value
);
2307 static char *pack_int (char *buf
, int value
);
2309 static char *unpack_int (char *buf
, int *value
);
2311 static char *unpack_string (char *src
, char *dest
, int length
);
2313 static char *pack_threadid (char *pkt
, threadref
*id
);
2315 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2317 void int_to_threadref (threadref
*id
, int value
);
2319 static int threadref_to_int (threadref
*ref
);
2321 static void copy_threadref (threadref
*dest
, threadref
*src
);
2323 static int threadmatch (threadref
*dest
, threadref
*src
);
2325 static char *pack_threadinfo_request (char *pkt
, int mode
,
2328 static int remote_unpack_thread_info_response (char *pkt
,
2329 threadref
*expectedref
,
2330 struct gdb_ext_thread_info
2334 static int remote_get_threadinfo (threadref
*threadid
,
2335 int fieldset
, /*TAG mask */
2336 struct gdb_ext_thread_info
*info
);
2338 static char *pack_threadlist_request (char *pkt
, int startflag
,
2340 threadref
*nextthread
);
2342 static int parse_threadlist_response (char *pkt
,
2344 threadref
*original_echo
,
2345 threadref
*resultlist
,
2348 static int remote_get_threadlist (int startflag
,
2349 threadref
*nextthread
,
2353 threadref
*threadlist
);
2355 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2357 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2358 void *context
, int looplimit
);
2360 static int remote_newthread_step (threadref
*ref
, void *context
);
2363 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2364 buffer we're allowed to write to. Returns
2365 BUF+CHARACTERS_WRITTEN. */
2368 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2371 struct remote_state
*rs
= get_remote_state ();
2373 if (remote_multi_process_p (rs
))
2375 pid
= ptid_get_pid (ptid
);
2377 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2379 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2381 tid
= ptid_get_lwp (ptid
);
2383 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2385 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2390 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2391 passed the last parsed char. Returns null_ptid on error. */
2394 read_ptid (char *buf
, char **obuf
)
2398 ULONGEST pid
= 0, tid
= 0;
2402 /* Multi-process ptid. */
2403 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2405 error (_("invalid remote ptid: %s"), p
);
2408 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2411 return ptid_build (pid
, tid
, 0);
2414 /* No multi-process. Just a tid. */
2415 pp
= unpack_varlen_hex (p
, &tid
);
2417 /* Return null_ptid when no thread id is found. */
2425 /* Since the stub is not sending a process id, then default to
2426 what's in inferior_ptid, unless it's null at this point. If so,
2427 then since there's no way to know the pid of the reported
2428 threads, use the magic number. */
2429 if (ptid_equal (inferior_ptid
, null_ptid
))
2430 pid
= ptid_get_pid (magic_null_ptid
);
2432 pid
= ptid_get_pid (inferior_ptid
);
2436 return ptid_build (pid
, tid
, 0);
2442 if (ch
>= 'a' && ch
<= 'f')
2443 return ch
- 'a' + 10;
2444 if (ch
>= '0' && ch
<= '9')
2446 if (ch
>= 'A' && ch
<= 'F')
2447 return ch
- 'A' + 10;
2452 stub_unpack_int (char *buff
, int fieldlength
)
2459 nibble
= stubhex (*buff
++);
2463 retval
= retval
<< 4;
2469 unpack_nibble (char *buf
, int *val
)
2471 *val
= fromhex (*buf
++);
2476 unpack_byte (char *buf
, int *value
)
2478 *value
= stub_unpack_int (buf
, 2);
2483 pack_int (char *buf
, int value
)
2485 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2486 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2487 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2488 buf
= pack_hex_byte (buf
, (value
& 0xff));
2493 unpack_int (char *buf
, int *value
)
2495 *value
= stub_unpack_int (buf
, 8);
2499 #if 0 /* Currently unused, uncomment when needed. */
2500 static char *pack_string (char *pkt
, char *string
);
2503 pack_string (char *pkt
, char *string
)
2508 len
= strlen (string
);
2510 len
= 200; /* Bigger than most GDB packets, junk??? */
2511 pkt
= pack_hex_byte (pkt
, len
);
2515 if ((ch
== '\0') || (ch
== '#'))
2516 ch
= '*'; /* Protect encapsulation. */
2521 #endif /* 0 (unused) */
2524 unpack_string (char *src
, char *dest
, int length
)
2533 pack_threadid (char *pkt
, threadref
*id
)
2536 unsigned char *altid
;
2538 altid
= (unsigned char *) id
;
2539 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2541 pkt
= pack_hex_byte (pkt
, *altid
++);
2547 unpack_threadid (char *inbuf
, threadref
*id
)
2550 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2553 altref
= (char *) id
;
2555 while (inbuf
< limit
)
2557 x
= stubhex (*inbuf
++);
2558 y
= stubhex (*inbuf
++);
2559 *altref
++ = (x
<< 4) | y
;
2564 /* Externally, threadrefs are 64 bits but internally, they are still
2565 ints. This is due to a mismatch of specifications. We would like
2566 to use 64bit thread references internally. This is an adapter
2570 int_to_threadref (threadref
*id
, int value
)
2572 unsigned char *scan
;
2574 scan
= (unsigned char *) id
;
2580 *scan
++ = (value
>> 24) & 0xff;
2581 *scan
++ = (value
>> 16) & 0xff;
2582 *scan
++ = (value
>> 8) & 0xff;
2583 *scan
++ = (value
& 0xff);
2587 threadref_to_int (threadref
*ref
)
2590 unsigned char *scan
;
2596 value
= (value
<< 8) | ((*scan
++) & 0xff);
2601 copy_threadref (threadref
*dest
, threadref
*src
)
2604 unsigned char *csrc
, *cdest
;
2606 csrc
= (unsigned char *) src
;
2607 cdest
= (unsigned char *) dest
;
2614 threadmatch (threadref
*dest
, threadref
*src
)
2616 /* Things are broken right now, so just assume we got a match. */
2618 unsigned char *srcp
, *destp
;
2620 srcp
= (char *) src
;
2621 destp
= (char *) dest
;
2625 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2632 threadid:1, # always request threadid
2639 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2642 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2644 *pkt
++ = 'q'; /* Info Query */
2645 *pkt
++ = 'P'; /* process or thread info */
2646 pkt
= pack_int (pkt
, mode
); /* mode */
2647 pkt
= pack_threadid (pkt
, id
); /* threadid */
2648 *pkt
= '\0'; /* terminate */
2652 /* These values tag the fields in a thread info response packet. */
2653 /* Tagging the fields allows us to request specific fields and to
2654 add more fields as time goes by. */
2656 #define TAG_THREADID 1 /* Echo the thread identifier. */
2657 #define TAG_EXISTS 2 /* Is this process defined enough to
2658 fetch registers and its stack? */
2659 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2660 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2661 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2665 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2666 struct gdb_ext_thread_info
*info
)
2668 struct remote_state
*rs
= get_remote_state ();
2672 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2675 /* info->threadid = 0; FIXME: implement zero_threadref. */
2677 info
->display
[0] = '\0';
2678 info
->shortname
[0] = '\0';
2679 info
->more_display
[0] = '\0';
2681 /* Assume the characters indicating the packet type have been
2683 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2684 pkt
= unpack_threadid (pkt
, &ref
);
2687 warning (_("Incomplete response to threadinfo request."));
2688 if (!threadmatch (&ref
, expectedref
))
2689 { /* This is an answer to a different request. */
2690 warning (_("ERROR RMT Thread info mismatch."));
2693 copy_threadref (&info
->threadid
, &ref
);
2695 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2697 /* Packets are terminated with nulls. */
2698 while ((pkt
< limit
) && mask
&& *pkt
)
2700 pkt
= unpack_int (pkt
, &tag
); /* tag */
2701 pkt
= unpack_byte (pkt
, &length
); /* length */
2702 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2704 warning (_("ERROR RMT: threadinfo tag mismatch."));
2708 if (tag
== TAG_THREADID
)
2712 warning (_("ERROR RMT: length of threadid is not 16."));
2716 pkt
= unpack_threadid (pkt
, &ref
);
2717 mask
= mask
& ~TAG_THREADID
;
2720 if (tag
== TAG_EXISTS
)
2722 info
->active
= stub_unpack_int (pkt
, length
);
2724 mask
= mask
& ~(TAG_EXISTS
);
2727 warning (_("ERROR RMT: 'exists' length too long."));
2733 if (tag
== TAG_THREADNAME
)
2735 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2736 mask
= mask
& ~TAG_THREADNAME
;
2739 if (tag
== TAG_DISPLAY
)
2741 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2742 mask
= mask
& ~TAG_DISPLAY
;
2745 if (tag
== TAG_MOREDISPLAY
)
2747 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2748 mask
= mask
& ~TAG_MOREDISPLAY
;
2751 warning (_("ERROR RMT: unknown thread info tag."));
2752 break; /* Not a tag we know about. */
2758 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2759 struct gdb_ext_thread_info
*info
)
2761 struct remote_state
*rs
= get_remote_state ();
2764 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2768 if (rs
->buf
[0] == '\0')
2771 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2776 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2779 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2780 threadref
*nextthread
)
2782 *pkt
++ = 'q'; /* info query packet */
2783 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2784 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2785 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2786 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2791 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2794 parse_threadlist_response (char *pkt
, int result_limit
,
2795 threadref
*original_echo
, threadref
*resultlist
,
2798 struct remote_state
*rs
= get_remote_state ();
2800 int count
, resultcount
, done
;
2803 /* Assume the 'q' and 'M chars have been stripped. */
2804 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2805 /* done parse past here */
2806 pkt
= unpack_byte (pkt
, &count
); /* count field */
2807 pkt
= unpack_nibble (pkt
, &done
);
2808 /* The first threadid is the argument threadid. */
2809 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2810 while ((count
-- > 0) && (pkt
< limit
))
2812 pkt
= unpack_threadid (pkt
, resultlist
++);
2813 if (resultcount
++ >= result_limit
)
2821 /* Fetch the next batch of threads from the remote. Returns -1 if the
2822 qL packet is not supported, 0 on error and 1 on success. */
2825 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2826 int *done
, int *result_count
, threadref
*threadlist
)
2828 struct remote_state
*rs
= get_remote_state ();
2831 /* Trancate result limit to be smaller than the packet size. */
2832 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2833 >= get_remote_packet_size ())
2834 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2836 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2838 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2839 if (*rs
->buf
== '\0')
2841 /* Packet not supported. */
2846 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2847 &rs
->echo_nextthread
, threadlist
, done
);
2849 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2851 /* FIXME: This is a good reason to drop the packet. */
2852 /* Possably, there is a duplicate response. */
2854 retransmit immediatly - race conditions
2855 retransmit after timeout - yes
2857 wait for packet, then exit
2859 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2860 return 0; /* I choose simply exiting. */
2862 if (*result_count
<= 0)
2866 warning (_("RMT ERROR : failed to get remote thread list."));
2869 return result
; /* break; */
2871 if (*result_count
> result_limit
)
2874 warning (_("RMT ERROR: threadlist response longer than requested."));
2880 /* Fetch the list of remote threads, with the qL packet, and call
2881 STEPFUNCTION for each thread found. Stops iterating and returns 1
2882 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2883 STEPFUNCTION returns false. If the packet is not supported,
2887 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2890 struct remote_state
*rs
= get_remote_state ();
2891 int done
, i
, result_count
;
2899 if (loopcount
++ > looplimit
)
2902 warning (_("Remote fetch threadlist -infinite loop-."));
2905 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2906 MAXTHREADLISTRESULTS
,
2907 &done
, &result_count
,
2908 rs
->resultthreadlist
);
2911 /* Clear for later iterations. */
2913 /* Setup to resume next batch of thread references, set nextthread. */
2914 if (result_count
>= 1)
2915 copy_threadref (&rs
->nextthread
,
2916 &rs
->resultthreadlist
[result_count
- 1]);
2918 while (result_count
--)
2920 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2930 /* A thread found on the remote target. */
2932 typedef struct thread_item
2934 /* The thread's PTID. */
2937 /* The thread's extra info. May be NULL. */
2940 /* The thread's name. May be NULL. */
2943 /* The core the thread was running on. -1 if not known. */
2946 DEF_VEC_O(thread_item_t
);
2948 /* Context passed around to the various methods listing remote
2949 threads. As new threads are found, they're added to the ITEMS
2952 struct threads_listing_context
2954 /* The threads found on the remote target. */
2955 VEC (thread_item_t
) *items
;
2958 /* Discard the contents of the constructed thread listing context. */
2961 clear_threads_listing_context (void *p
)
2963 struct threads_listing_context
*context
2964 = (struct threads_listing_context
*) p
;
2966 struct thread_item
*item
;
2968 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2970 xfree (item
->extra
);
2974 VEC_free (thread_item_t
, context
->items
);
2977 /* Remove the thread specified as the related_pid field of WS
2978 from the CONTEXT list. */
2981 threads_listing_context_remove (struct target_waitstatus
*ws
,
2982 struct threads_listing_context
*context
)
2984 struct thread_item
*item
;
2986 ptid_t child_ptid
= ws
->value
.related_pid
;
2988 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2990 if (ptid_equal (item
->ptid
, child_ptid
))
2992 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2999 remote_newthread_step (threadref
*ref
, void *data
)
3001 struct threads_listing_context
*context
3002 = (struct threads_listing_context
*) data
;
3003 struct thread_item item
;
3004 int pid
= ptid_get_pid (inferior_ptid
);
3006 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3011 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3013 return 1; /* continue iterator */
3016 #define CRAZY_MAX_THREADS 1000
3019 remote_current_thread (ptid_t oldpid
)
3021 struct remote_state
*rs
= get_remote_state ();
3024 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3025 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3030 result
= read_ptid (&rs
->buf
[2], &obuf
);
3031 if (*obuf
!= '\0' && remote_debug
)
3032 fprintf_unfiltered (gdb_stdlog
,
3033 "warning: garbage in qC reply\n");
3041 /* List remote threads using the deprecated qL packet. */
3044 remote_get_threads_with_ql (struct target_ops
*ops
,
3045 struct threads_listing_context
*context
)
3047 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3048 CRAZY_MAX_THREADS
) >= 0)
3054 #if defined(HAVE_LIBEXPAT)
3057 start_thread (struct gdb_xml_parser
*parser
,
3058 const struct gdb_xml_element
*element
,
3059 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3061 struct threads_listing_context
*data
3062 = (struct threads_listing_context
*) user_data
;
3064 struct thread_item item
;
3066 struct gdb_xml_value
*attr
;
3068 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3069 item
.ptid
= read_ptid (id
, NULL
);
3071 attr
= xml_find_attribute (attributes
, "core");
3073 item
.core
= *(ULONGEST
*) attr
->value
;
3077 attr
= xml_find_attribute (attributes
, "name");
3078 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3082 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3086 end_thread (struct gdb_xml_parser
*parser
,
3087 const struct gdb_xml_element
*element
,
3088 void *user_data
, const char *body_text
)
3090 struct threads_listing_context
*data
3091 = (struct threads_listing_context
*) user_data
;
3093 if (body_text
&& *body_text
)
3094 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3097 const struct gdb_xml_attribute thread_attributes
[] = {
3098 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3099 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3100 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3101 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3104 const struct gdb_xml_element thread_children
[] = {
3105 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3108 const struct gdb_xml_element threads_children
[] = {
3109 { "thread", thread_attributes
, thread_children
,
3110 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3111 start_thread
, end_thread
},
3112 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3115 const struct gdb_xml_element threads_elements
[] = {
3116 { "threads", NULL
, threads_children
,
3117 GDB_XML_EF_NONE
, NULL
, NULL
},
3118 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3123 /* List remote threads using qXfer:threads:read. */
3126 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3127 struct threads_listing_context
*context
)
3129 #if defined(HAVE_LIBEXPAT)
3130 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3132 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3133 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3135 if (xml
!= NULL
&& *xml
!= '\0')
3137 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3138 threads_elements
, xml
, context
);
3141 do_cleanups (back_to
);
3149 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3152 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3153 struct threads_listing_context
*context
)
3155 struct remote_state
*rs
= get_remote_state ();
3157 if (rs
->use_threadinfo_query
)
3161 putpkt ("qfThreadInfo");
3162 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3164 if (bufp
[0] != '\0') /* q packet recognized */
3166 while (*bufp
++ == 'm') /* reply contains one or more TID */
3170 struct thread_item item
;
3172 item
.ptid
= read_ptid (bufp
, &bufp
);
3177 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3179 while (*bufp
++ == ','); /* comma-separated list */
3180 putpkt ("qsThreadInfo");
3181 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3188 /* Packet not recognized. */
3189 rs
->use_threadinfo_query
= 0;
3196 /* Implement the to_update_thread_list function for the remote
3200 remote_update_thread_list (struct target_ops
*ops
)
3202 struct threads_listing_context context
;
3203 struct cleanup
*old_chain
;
3206 context
.items
= NULL
;
3207 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3209 /* We have a few different mechanisms to fetch the thread list. Try
3210 them all, starting with the most preferred one first, falling
3211 back to older methods. */
3212 if (remote_get_threads_with_qxfer (ops
, &context
)
3213 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3214 || remote_get_threads_with_ql (ops
, &context
))
3217 struct thread_item
*item
;
3218 struct thread_info
*tp
, *tmp
;
3222 if (VEC_empty (thread_item_t
, context
.items
)
3223 && remote_thread_always_alive (ops
, inferior_ptid
))
3225 /* Some targets don't really support threads, but still
3226 reply an (empty) thread list in response to the thread
3227 listing packets, instead of replying "packet not
3228 supported". Exit early so we don't delete the main
3230 do_cleanups (old_chain
);
3234 /* CONTEXT now holds the current thread list on the remote
3235 target end. Delete GDB-side threads no longer found on the
3237 ALL_THREADS_SAFE (tp
, tmp
)
3240 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3243 if (ptid_equal (item
->ptid
, tp
->ptid
))
3247 if (i
== VEC_length (thread_item_t
, context
.items
))
3250 delete_thread (tp
->ptid
);
3254 /* Remove any unreported fork child threads from CONTEXT so
3255 that we don't interfere with follow fork, which is where
3256 creation of such threads is handled. */
3257 remove_new_fork_children (&context
);
3259 /* And now add threads we don't know about yet to our list. */
3261 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3264 if (!ptid_equal (item
->ptid
, null_ptid
))
3266 struct private_thread_info
*info
;
3267 /* In non-stop mode, we assume new found threads are
3268 executing until proven otherwise with a stop reply.
3269 In all-stop, we can only get here if all threads are
3271 int executing
= target_is_non_stop_p () ? 1 : 0;
3273 remote_notice_new_inferior (item
->ptid
, executing
);
3275 info
= demand_private_info (item
->ptid
);
3276 info
->core
= item
->core
;
3277 info
->extra
= item
->extra
;
3279 info
->name
= item
->name
;
3287 /* If no thread listing method is supported, then query whether
3288 each known thread is alive, one by one, with the T packet.
3289 If the target doesn't support threads at all, then this is a
3290 no-op. See remote_thread_alive. */
3294 do_cleanups (old_chain
);
3298 * Collect a descriptive string about the given thread.
3299 * The target may say anything it wants to about the thread
3300 * (typically info about its blocked / runnable state, name, etc.).
3301 * This string will appear in the info threads display.
3303 * Optional: targets are not required to implement this function.
3307 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3309 struct remote_state
*rs
= get_remote_state ();
3313 struct gdb_ext_thread_info threadinfo
;
3314 static char display_buf
[100]; /* arbitrary... */
3315 int n
= 0; /* position in display_buf */
3317 if (rs
->remote_desc
== 0) /* paranoia */
3318 internal_error (__FILE__
, __LINE__
,
3319 _("remote_threads_extra_info"));
3321 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3322 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3323 /* This is the main thread which was added by GDB. The remote
3324 server doesn't know about it. */
3327 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3329 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3331 if (info
&& info
->priv
)
3332 return info
->priv
->extra
;
3337 if (rs
->use_threadextra_query
)
3340 char *endb
= rs
->buf
+ get_remote_packet_size ();
3342 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3344 write_ptid (b
, endb
, tp
->ptid
);
3347 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3348 if (rs
->buf
[0] != 0)
3350 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3351 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3352 display_buf
[result
] = '\0';
3357 /* If the above query fails, fall back to the old method. */
3358 rs
->use_threadextra_query
= 0;
3359 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3360 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3361 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3362 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3363 if (threadinfo
.active
)
3365 if (*threadinfo
.shortname
)
3366 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3367 " Name: %s,", threadinfo
.shortname
);
3368 if (*threadinfo
.display
)
3369 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3370 " State: %s,", threadinfo
.display
);
3371 if (*threadinfo
.more_display
)
3372 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3373 " Priority: %s", threadinfo
.more_display
);
3377 /* For purely cosmetic reasons, clear up trailing commas. */
3378 if (',' == display_buf
[n
-1])
3379 display_buf
[n
-1] = ' ';
3388 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3389 struct static_tracepoint_marker
*marker
)
3391 struct remote_state
*rs
= get_remote_state ();
3394 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3396 p
+= hexnumstr (p
, addr
);
3398 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3402 error (_("Remote failure reply: %s"), p
);
3406 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3413 static VEC(static_tracepoint_marker_p
) *
3414 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3417 struct remote_state
*rs
= get_remote_state ();
3418 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3419 struct static_tracepoint_marker
*marker
= NULL
;
3420 struct cleanup
*old_chain
;
3423 /* Ask for a first packet of static tracepoint marker
3426 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3429 error (_("Remote failure reply: %s"), p
);
3431 old_chain
= make_cleanup (free_current_marker
, &marker
);
3436 marker
= XCNEW (struct static_tracepoint_marker
);
3440 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3442 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3444 VEC_safe_push (static_tracepoint_marker_p
,
3450 release_static_tracepoint_marker (marker
);
3451 memset (marker
, 0, sizeof (*marker
));
3454 while (*p
++ == ','); /* comma-separated list */
3455 /* Ask for another packet of static tracepoint definition. */
3457 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3461 do_cleanups (old_chain
);
3466 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3469 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3471 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3475 /* Restart the remote side; this is an extended protocol operation. */
3478 extended_remote_restart (void)
3480 struct remote_state
*rs
= get_remote_state ();
3482 /* Send the restart command; for reasons I don't understand the
3483 remote side really expects a number after the "R". */
3484 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3487 remote_fileio_reset ();
3490 /* Clean up connection to a remote debugger. */
3493 remote_close (struct target_ops
*self
)
3495 struct remote_state
*rs
= get_remote_state ();
3497 if (rs
->remote_desc
== NULL
)
3498 return; /* already closed */
3500 /* Make sure we leave stdin registered in the event loop. */
3501 remote_terminal_ours (self
);
3503 serial_close (rs
->remote_desc
);
3504 rs
->remote_desc
= NULL
;
3506 /* We don't have a connection to the remote stub anymore. Get rid
3507 of all the inferiors and their threads we were controlling.
3508 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3509 will be unable to find the thread corresponding to (pid, 0, 0). */
3510 inferior_ptid
= null_ptid
;
3511 discard_all_inferiors ();
3513 /* We are closing the remote target, so we should discard
3514 everything of this target. */
3515 discard_pending_stop_replies_in_queue (rs
);
3517 if (remote_async_inferior_event_token
)
3518 delete_async_event_handler (&remote_async_inferior_event_token
);
3520 remote_notif_state_xfree (rs
->notif_state
);
3522 trace_reset_local_state ();
3525 /* Query the remote side for the text, data and bss offsets. */
3530 struct remote_state
*rs
= get_remote_state ();
3533 int lose
, num_segments
= 0, do_sections
, do_segments
;
3534 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3535 struct section_offsets
*offs
;
3536 struct symfile_segment_data
*data
;
3538 if (symfile_objfile
== NULL
)
3541 putpkt ("qOffsets");
3542 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3545 if (buf
[0] == '\000')
3546 return; /* Return silently. Stub doesn't support
3550 warning (_("Remote failure reply: %s"), buf
);
3554 /* Pick up each field in turn. This used to be done with scanf, but
3555 scanf will make trouble if CORE_ADDR size doesn't match
3556 conversion directives correctly. The following code will work
3557 with any size of CORE_ADDR. */
3558 text_addr
= data_addr
= bss_addr
= 0;
3562 if (startswith (ptr
, "Text="))
3565 /* Don't use strtol, could lose on big values. */
3566 while (*ptr
&& *ptr
!= ';')
3567 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3569 if (startswith (ptr
, ";Data="))
3572 while (*ptr
&& *ptr
!= ';')
3573 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3578 if (!lose
&& startswith (ptr
, ";Bss="))
3581 while (*ptr
&& *ptr
!= ';')
3582 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3584 if (bss_addr
!= data_addr
)
3585 warning (_("Target reported unsupported offsets: %s"), buf
);
3590 else if (startswith (ptr
, "TextSeg="))
3593 /* Don't use strtol, could lose on big values. */
3594 while (*ptr
&& *ptr
!= ';')
3595 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3598 if (startswith (ptr
, ";DataSeg="))
3601 while (*ptr
&& *ptr
!= ';')
3602 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3610 error (_("Malformed response to offset query, %s"), buf
);
3611 else if (*ptr
!= '\0')
3612 warning (_("Target reported unsupported offsets: %s"), buf
);
3614 offs
= ((struct section_offsets
*)
3615 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3616 memcpy (offs
, symfile_objfile
->section_offsets
,
3617 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3619 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3620 do_segments
= (data
!= NULL
);
3621 do_sections
= num_segments
== 0;
3623 if (num_segments
> 0)
3625 segments
[0] = text_addr
;
3626 segments
[1] = data_addr
;
3628 /* If we have two segments, we can still try to relocate everything
3629 by assuming that the .text and .data offsets apply to the whole
3630 text and data segments. Convert the offsets given in the packet
3631 to base addresses for symfile_map_offsets_to_segments. */
3632 else if (data
&& data
->num_segments
== 2)
3634 segments
[0] = data
->segment_bases
[0] + text_addr
;
3635 segments
[1] = data
->segment_bases
[1] + data_addr
;
3638 /* If the object file has only one segment, assume that it is text
3639 rather than data; main programs with no writable data are rare,
3640 but programs with no code are useless. Of course the code might
3641 have ended up in the data segment... to detect that we would need
3642 the permissions here. */
3643 else if (data
&& data
->num_segments
== 1)
3645 segments
[0] = data
->segment_bases
[0] + text_addr
;
3648 /* There's no way to relocate by segment. */
3654 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3655 offs
, num_segments
, segments
);
3657 if (ret
== 0 && !do_sections
)
3658 error (_("Can not handle qOffsets TextSeg "
3659 "response with this symbol file"));
3666 free_symfile_segment_data (data
);
3670 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3672 /* This is a temporary kludge to force data and bss to use the
3673 same offsets because that's what nlmconv does now. The real
3674 solution requires changes to the stub and remote.c that I
3675 don't have time to do right now. */
3677 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3678 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3681 objfile_relocate (symfile_objfile
, offs
);
3684 /* Send interrupt_sequence to remote target. */
3686 send_interrupt_sequence (void)
3688 struct remote_state
*rs
= get_remote_state ();
3690 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3691 remote_serial_write ("\x03", 1);
3692 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3693 serial_send_break (rs
->remote_desc
);
3694 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3696 serial_send_break (rs
->remote_desc
);
3697 remote_serial_write ("g", 1);
3700 internal_error (__FILE__
, __LINE__
,
3701 _("Invalid value for interrupt_sequence_mode: %s."),
3702 interrupt_sequence_mode
);
3706 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3707 and extract the PTID. Returns NULL_PTID if not found. */
3710 stop_reply_extract_thread (char *stop_reply
)
3712 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3716 /* Txx r:val ; r:val (...) */
3719 /* Look for "register" named "thread". */
3724 p1
= strchr (p
, ':');
3728 if (strncmp (p
, "thread", p1
- p
) == 0)
3729 return read_ptid (++p1
, &p
);
3731 p1
= strchr (p
, ';');
3743 /* Determine the remote side's current thread. If we have a stop
3744 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3745 "thread" register we can extract the current thread from. If not,
3746 ask the remote which is the current thread with qC. The former
3747 method avoids a roundtrip. */
3750 get_current_thread (char *wait_status
)
3752 ptid_t ptid
= null_ptid
;
3754 /* Note we don't use remote_parse_stop_reply as that makes use of
3755 the target architecture, which we haven't yet fully determined at
3757 if (wait_status
!= NULL
)
3758 ptid
= stop_reply_extract_thread (wait_status
);
3759 if (ptid_equal (ptid
, null_ptid
))
3760 ptid
= remote_current_thread (inferior_ptid
);
3765 /* Query the remote target for which is the current thread/process,
3766 add it to our tables, and update INFERIOR_PTID. The caller is
3767 responsible for setting the state such that the remote end is ready
3768 to return the current thread.
3770 This function is called after handling the '?' or 'vRun' packets,
3771 whose response is a stop reply from which we can also try
3772 extracting the thread. If the target doesn't support the explicit
3773 qC query, we infer the current thread from that stop reply, passed
3774 in in WAIT_STATUS, which may be NULL. */
3777 add_current_inferior_and_thread (char *wait_status
)
3779 struct remote_state
*rs
= get_remote_state ();
3783 inferior_ptid
= null_ptid
;
3785 /* Now, if we have thread information, update inferior_ptid. */
3786 ptid
= get_current_thread (wait_status
);
3788 if (!ptid_equal (ptid
, null_ptid
))
3790 if (!remote_multi_process_p (rs
))
3793 inferior_ptid
= ptid
;
3797 /* Without this, some commands which require an active target
3798 (such as kill) won't work. This variable serves (at least)
3799 double duty as both the pid of the target process (if it has
3800 such), and as a flag indicating that a target is active. */
3801 inferior_ptid
= magic_null_ptid
;
3805 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3807 /* Add the main thread. */
3808 add_thread_silent (inferior_ptid
);
3811 /* Print info about a thread that was found already stopped on
3815 print_one_stopped_thread (struct thread_info
*thread
)
3817 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3819 switch_to_thread (thread
->ptid
);
3820 stop_pc
= get_frame_pc (get_current_frame ());
3821 set_current_sal_from_frame (get_current_frame ());
3823 thread
->suspend
.waitstatus_pending_p
= 0;
3825 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3827 enum gdb_signal sig
= ws
->value
.sig
;
3829 if (signal_print_state (sig
))
3830 observer_notify_signal_received (sig
);
3832 observer_notify_normal_stop (NULL
, 1);
3835 /* Process all initial stop replies the remote side sent in response
3836 to the ? packet. These indicate threads that were already stopped
3837 on initial connection. We mark these threads as stopped and print
3838 their current frame before giving the user the prompt. */
3841 process_initial_stop_replies (int from_tty
)
3843 int pending_stop_replies
= stop_reply_queue_length ();
3844 struct inferior
*inf
;
3845 struct thread_info
*thread
;
3846 struct thread_info
*selected
= NULL
;
3847 struct thread_info
*lowest_stopped
= NULL
;
3848 struct thread_info
*first
= NULL
;
3850 /* Consume the initial pending events. */
3851 while (pending_stop_replies
-- > 0)
3853 ptid_t waiton_ptid
= minus_one_ptid
;
3855 struct target_waitstatus ws
;
3856 int ignore_event
= 0;
3857 struct thread_info
*thread
;
3859 memset (&ws
, 0, sizeof (ws
));
3860 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3862 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3866 case TARGET_WAITKIND_IGNORE
:
3867 case TARGET_WAITKIND_NO_RESUMED
:
3868 case TARGET_WAITKIND_SIGNALLED
:
3869 case TARGET_WAITKIND_EXITED
:
3870 /* We shouldn't see these, but if we do, just ignore. */
3872 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3876 case TARGET_WAITKIND_EXECD
:
3877 xfree (ws
.value
.execd_pathname
);
3886 thread
= find_thread_ptid (event_ptid
);
3888 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3890 enum gdb_signal sig
= ws
.value
.sig
;
3892 /* Stubs traditionally report SIGTRAP as initial signal,
3893 instead of signal 0. Suppress it. */
3894 if (sig
== GDB_SIGNAL_TRAP
)
3896 thread
->suspend
.stop_signal
= sig
;
3900 thread
->suspend
.waitstatus
= ws
;
3902 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3903 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3904 thread
->suspend
.waitstatus_pending_p
= 1;
3906 set_executing (event_ptid
, 0);
3907 set_running (event_ptid
, 0);
3910 /* "Notice" the new inferiors before anything related to
3911 registers/memory. */
3917 inf
->needs_setup
= 1;
3921 thread
= any_live_thread_of_process (inf
->pid
);
3922 notice_new_inferior (thread
->ptid
,
3923 thread
->state
== THREAD_RUNNING
,
3928 /* If all-stop on top of non-stop, pause all threads. Note this
3929 records the threads' stop pc, so must be done after "noticing"
3933 stop_all_threads ();
3935 /* If all threads of an inferior were already stopped, we
3936 haven't setup the inferior yet. */
3942 if (inf
->needs_setup
)
3944 thread
= any_live_thread_of_process (inf
->pid
);
3945 switch_to_thread_no_regs (thread
);
3951 /* Now go over all threads that are stopped, and print their current
3952 frame. If all-stop, then if there's a signalled thread, pick
3954 ALL_NON_EXITED_THREADS (thread
)
3960 set_running (thread
->ptid
, 0);
3961 else if (thread
->state
!= THREAD_STOPPED
)
3964 if (selected
== NULL
3965 && thread
->suspend
.waitstatus_pending_p
)
3968 if (lowest_stopped
== NULL
3969 || thread
->inf
->num
< lowest_stopped
->inf
->num
3970 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
3971 lowest_stopped
= thread
;
3974 print_one_stopped_thread (thread
);
3977 /* In all-stop, we only print the status of one thread, and leave
3978 others with their status pending. */
3983 thread
= lowest_stopped
;
3987 print_one_stopped_thread (thread
);
3990 /* For "info program". */
3991 thread
= inferior_thread ();
3992 if (thread
->state
== THREAD_STOPPED
)
3993 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
3996 /* Start the remote connection and sync state. */
3999 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4001 struct remote_state
*rs
= get_remote_state ();
4002 struct packet_config
*noack_config
;
4003 char *wait_status
= NULL
;
4005 /* Signal other parts that we're going through the initial setup,
4006 and so things may not be stable yet. E.g., we don't try to
4007 install tracepoints until we've relocated symbols. Also, a
4008 Ctrl-C before we're connected and synced up can't interrupt the
4009 target. Instead, it offers to drop the (potentially wedged)
4011 rs
->starting_up
= 1;
4015 if (interrupt_on_connect
)
4016 send_interrupt_sequence ();
4018 /* Ack any packet which the remote side has already sent. */
4019 remote_serial_write ("+", 1);
4021 /* The first packet we send to the target is the optional "supported
4022 packets" request. If the target can answer this, it will tell us
4023 which later probes to skip. */
4024 remote_query_supported ();
4026 /* If the stub wants to get a QAllow, compose one and send it. */
4027 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4028 remote_set_permissions (target
);
4030 /* Next, we possibly activate noack mode.
4032 If the QStartNoAckMode packet configuration is set to AUTO,
4033 enable noack mode if the stub reported a wish for it with
4036 If set to TRUE, then enable noack mode even if the stub didn't
4037 report it in qSupported. If the stub doesn't reply OK, the
4038 session ends with an error.
4040 If FALSE, then don't activate noack mode, regardless of what the
4041 stub claimed should be the default with qSupported. */
4043 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4044 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4046 putpkt ("QStartNoAckMode");
4047 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4048 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4054 /* Tell the remote that we are using the extended protocol. */
4056 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4059 /* Let the target know which signals it is allowed to pass down to
4061 update_signals_program_target ();
4063 /* Next, if the target can specify a description, read it. We do
4064 this before anything involving memory or registers. */
4065 target_find_description ();
4067 /* Next, now that we know something about the target, update the
4068 address spaces in the program spaces. */
4069 update_address_spaces ();
4071 /* On OSs where the list of libraries is global to all
4072 processes, we fetch them early. */
4073 if (gdbarch_has_global_solist (target_gdbarch ()))
4074 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4076 if (target_is_non_stop_p ())
4078 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4079 error (_("Non-stop mode requested, but remote "
4080 "does not support non-stop"));
4082 putpkt ("QNonStop:1");
4083 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4085 if (strcmp (rs
->buf
, "OK") != 0)
4086 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4088 /* Find about threads and processes the stub is already
4089 controlling. We default to adding them in the running state.
4090 The '?' query below will then tell us about which threads are
4092 remote_update_thread_list (target
);
4094 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4096 /* Don't assume that the stub can operate in all-stop mode.
4097 Request it explicitly. */
4098 putpkt ("QNonStop:0");
4099 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4101 if (strcmp (rs
->buf
, "OK") != 0)
4102 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4105 /* Upload TSVs regardless of whether the target is running or not. The
4106 remote stub, such as GDBserver, may have some predefined or builtin
4107 TSVs, even if the target is not running. */
4108 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4110 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4112 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4113 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4116 /* Check whether the target is running now. */
4118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4120 if (!target_is_non_stop_p ())
4122 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4125 error (_("The target is not running (try extended-remote?)"));
4127 /* We're connected, but not running. Drop out before we
4128 call start_remote. */
4129 rs
->starting_up
= 0;
4134 /* Save the reply for later. */
4135 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4136 strcpy (wait_status
, rs
->buf
);
4139 /* Fetch thread list. */
4140 target_update_thread_list ();
4142 /* Let the stub know that we want it to return the thread. */
4143 set_continue_thread (minus_one_ptid
);
4145 if (thread_count () == 0)
4147 /* Target has no concept of threads at all. GDB treats
4148 non-threaded target as single-threaded; add a main
4150 add_current_inferior_and_thread (wait_status
);
4154 /* We have thread information; select the thread the target
4155 says should be current. If we're reconnecting to a
4156 multi-threaded program, this will ideally be the thread
4157 that last reported an event before GDB disconnected. */
4158 inferior_ptid
= get_current_thread (wait_status
);
4159 if (ptid_equal (inferior_ptid
, null_ptid
))
4161 /* Odd... The target was able to list threads, but not
4162 tell us which thread was current (no "thread"
4163 register in T stop reply?). Just pick the first
4164 thread in the thread list then. */
4167 fprintf_unfiltered (gdb_stdlog
,
4168 "warning: couldn't determine remote "
4169 "current thread; picking first in list.\n");
4171 inferior_ptid
= thread_list
->ptid
;
4175 /* init_wait_for_inferior should be called before get_offsets in order
4176 to manage `inserted' flag in bp loc in a correct state.
4177 breakpoint_init_inferior, called from init_wait_for_inferior, set
4178 `inserted' flag to 0, while before breakpoint_re_set, called from
4179 start_remote, set `inserted' flag to 1. In the initialization of
4180 inferior, breakpoint_init_inferior should be called first, and then
4181 breakpoint_re_set can be called. If this order is broken, state of
4182 `inserted' flag is wrong, and cause some problems on breakpoint
4184 init_wait_for_inferior ();
4186 get_offsets (); /* Get text, data & bss offsets. */
4188 /* If we could not find a description using qXfer, and we know
4189 how to do it some other way, try again. This is not
4190 supported for non-stop; it could be, but it is tricky if
4191 there are no stopped threads when we connect. */
4192 if (remote_read_description_p (target
)
4193 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4195 target_clear_description ();
4196 target_find_description ();
4199 /* Use the previously fetched status. */
4200 gdb_assert (wait_status
!= NULL
);
4201 strcpy (rs
->buf
, wait_status
);
4202 rs
->cached_wait_status
= 1;
4204 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4208 /* Clear WFI global state. Do this before finding about new
4209 threads and inferiors, and setting the current inferior.
4210 Otherwise we would clear the proceed status of the current
4211 inferior when we want its stop_soon state to be preserved
4212 (see notice_new_inferior). */
4213 init_wait_for_inferior ();
4215 /* In non-stop, we will either get an "OK", meaning that there
4216 are no stopped threads at this time; or, a regular stop
4217 reply. In the latter case, there may be more than one thread
4218 stopped --- we pull them all out using the vStopped
4220 if (strcmp (rs
->buf
, "OK") != 0)
4222 struct notif_client
*notif
= ¬if_client_stop
;
4224 /* remote_notif_get_pending_replies acks this one, and gets
4226 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4227 = remote_notif_parse (notif
, rs
->buf
);
4228 remote_notif_get_pending_events (notif
);
4231 if (thread_count () == 0)
4234 error (_("The target is not running (try extended-remote?)"));
4236 /* We're connected, but not running. Drop out before we
4237 call start_remote. */
4238 rs
->starting_up
= 0;
4242 /* In non-stop mode, any cached wait status will be stored in
4243 the stop reply queue. */
4244 gdb_assert (wait_status
== NULL
);
4246 /* Report all signals during attach/startup. */
4247 remote_pass_signals (target
, 0, NULL
);
4249 /* If there are already stopped threads, mark them stopped and
4250 report their stops before giving the prompt to the user. */
4251 process_initial_stop_replies (from_tty
);
4253 if (target_can_async_p ())
4257 /* If we connected to a live target, do some additional setup. */
4258 if (target_has_execution
)
4260 if (symfile_objfile
) /* No use without a symbol-file. */
4261 remote_check_symbols ();
4264 /* Possibly the target has been engaged in a trace run started
4265 previously; find out where things are at. */
4266 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4268 struct uploaded_tp
*uploaded_tps
= NULL
;
4270 if (current_trace_status ()->running
)
4271 printf_filtered (_("Trace is already running on the target.\n"));
4273 remote_upload_tracepoints (target
, &uploaded_tps
);
4275 merge_uploaded_tracepoints (&uploaded_tps
);
4278 /* The thread and inferior lists are now synchronized with the
4279 target, our symbols have been relocated, and we're merged the
4280 target's tracepoints with ours. We're done with basic start
4282 rs
->starting_up
= 0;
4284 /* Maybe breakpoints are global and need to be inserted now. */
4285 if (breakpoints_should_be_inserted_now ())
4286 insert_breakpoints ();
4289 /* Open a connection to a remote debugger.
4290 NAME is the filename used for communication. */
4293 remote_open (const char *name
, int from_tty
)
4295 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4298 /* Open a connection to a remote debugger using the extended
4299 remote gdb protocol. NAME is the filename used for communication. */
4302 extended_remote_open (const char *name
, int from_tty
)
4304 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4307 /* Reset all packets back to "unknown support". Called when opening a
4308 new connection to a remote target. */
4311 reset_all_packet_configs_support (void)
4315 for (i
= 0; i
< PACKET_MAX
; i
++)
4316 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4319 /* Initialize all packet configs. */
4322 init_all_packet_configs (void)
4326 for (i
= 0; i
< PACKET_MAX
; i
++)
4328 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4329 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4333 /* Symbol look-up. */
4336 remote_check_symbols (void)
4338 struct remote_state
*rs
= get_remote_state ();
4339 char *msg
, *reply
, *tmp
;
4342 struct cleanup
*old_chain
;
4344 /* The remote side has no concept of inferiors that aren't running
4345 yet, it only knows about running processes. If we're connected
4346 but our current inferior is not running, we should not invite the
4347 remote target to request symbol lookups related to its
4348 (unrelated) current process. */
4349 if (!target_has_execution
)
4352 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4355 /* Make sure the remote is pointing at the right process. Note
4356 there's no way to select "no process". */
4357 set_general_process ();
4359 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4360 because we need both at the same time. */
4361 msg
= (char *) xmalloc (get_remote_packet_size ());
4362 old_chain
= make_cleanup (xfree
, msg
);
4363 reply
= (char *) xmalloc (get_remote_packet_size ());
4364 make_cleanup (free_current_contents
, &reply
);
4365 reply_size
= get_remote_packet_size ();
4367 /* Invite target to request symbol lookups. */
4369 putpkt ("qSymbol::");
4370 getpkt (&reply
, &reply_size
, 0);
4371 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4373 while (startswith (reply
, "qSymbol:"))
4375 struct bound_minimal_symbol sym
;
4378 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4380 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4381 if (sym
.minsym
== NULL
)
4382 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4385 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4386 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4388 /* If this is a function address, return the start of code
4389 instead of any data function descriptor. */
4390 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4394 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4395 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4399 getpkt (&reply
, &reply_size
, 0);
4402 do_cleanups (old_chain
);
4405 static struct serial
*
4406 remote_serial_open (const char *name
)
4408 static int udp_warning
= 0;
4410 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4411 of in ser-tcp.c, because it is the remote protocol assuming that the
4412 serial connection is reliable and not the serial connection promising
4414 if (!udp_warning
&& startswith (name
, "udp:"))
4416 warning (_("The remote protocol may be unreliable over UDP.\n"
4417 "Some events may be lost, rendering further debugging "
4422 return serial_open (name
);
4425 /* Inform the target of our permission settings. The permission flags
4426 work without this, but if the target knows the settings, it can do
4427 a couple things. First, it can add its own check, to catch cases
4428 that somehow manage to get by the permissions checks in target
4429 methods. Second, if the target is wired to disallow particular
4430 settings (for instance, a system in the field that is not set up to
4431 be able to stop at a breakpoint), it can object to any unavailable
4435 remote_set_permissions (struct target_ops
*self
)
4437 struct remote_state
*rs
= get_remote_state ();
4439 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4440 "WriteReg:%x;WriteMem:%x;"
4441 "InsertBreak:%x;InsertTrace:%x;"
4442 "InsertFastTrace:%x;Stop:%x",
4443 may_write_registers
, may_write_memory
,
4444 may_insert_breakpoints
, may_insert_tracepoints
,
4445 may_insert_fast_tracepoints
, may_stop
);
4447 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4449 /* If the target didn't like the packet, warn the user. Do not try
4450 to undo the user's settings, that would just be maddening. */
4451 if (strcmp (rs
->buf
, "OK") != 0)
4452 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4455 /* This type describes each known response to the qSupported
4457 struct protocol_feature
4459 /* The name of this protocol feature. */
4462 /* The default for this protocol feature. */
4463 enum packet_support default_support
;
4465 /* The function to call when this feature is reported, or after
4466 qSupported processing if the feature is not supported.
4467 The first argument points to this structure. The second
4468 argument indicates whether the packet requested support be
4469 enabled, disabled, or probed (or the default, if this function
4470 is being called at the end of processing and this feature was
4471 not reported). The third argument may be NULL; if not NULL, it
4472 is a NUL-terminated string taken from the packet following
4473 this feature's name and an equals sign. */
4474 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4477 /* The corresponding packet for this feature. Only used if
4478 FUNC is remote_supported_packet. */
4483 remote_supported_packet (const struct protocol_feature
*feature
,
4484 enum packet_support support
,
4485 const char *argument
)
4489 warning (_("Remote qSupported response supplied an unexpected value for"
4490 " \"%s\"."), feature
->name
);
4494 remote_protocol_packets
[feature
->packet
].support
= support
;
4498 remote_packet_size (const struct protocol_feature
*feature
,
4499 enum packet_support support
, const char *value
)
4501 struct remote_state
*rs
= get_remote_state ();
4506 if (support
!= PACKET_ENABLE
)
4509 if (value
== NULL
|| *value
== '\0')
4511 warning (_("Remote target reported \"%s\" without a size."),
4517 packet_size
= strtol (value
, &value_end
, 16);
4518 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4520 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4521 feature
->name
, value
);
4525 /* Record the new maximum packet size. */
4526 rs
->explicit_packet_size
= packet_size
;
4529 static const struct protocol_feature remote_protocol_features
[] = {
4530 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4531 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4532 PACKET_qXfer_auxv
},
4533 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4534 PACKET_qXfer_exec_file
},
4535 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4536 PACKET_qXfer_features
},
4537 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4538 PACKET_qXfer_libraries
},
4539 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4540 PACKET_qXfer_libraries_svr4
},
4541 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4542 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4543 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4544 PACKET_qXfer_memory_map
},
4545 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4546 PACKET_qXfer_spu_read
},
4547 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4548 PACKET_qXfer_spu_write
},
4549 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4550 PACKET_qXfer_osdata
},
4551 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4552 PACKET_qXfer_threads
},
4553 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4554 PACKET_qXfer_traceframe_info
},
4555 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4556 PACKET_QPassSignals
},
4557 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4558 PACKET_QCatchSyscalls
},
4559 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4560 PACKET_QProgramSignals
},
4561 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4562 PACKET_QStartNoAckMode
},
4563 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4564 PACKET_multiprocess_feature
},
4565 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4566 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4567 PACKET_qXfer_siginfo_read
},
4568 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4569 PACKET_qXfer_siginfo_write
},
4570 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4571 PACKET_ConditionalTracepoints
},
4572 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4573 PACKET_ConditionalBreakpoints
},
4574 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4575 PACKET_BreakpointCommands
},
4576 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4577 PACKET_FastTracepoints
},
4578 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4579 PACKET_StaticTracepoints
},
4580 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4581 PACKET_InstallInTrace
},
4582 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4583 PACKET_DisconnectedTracing_feature
},
4584 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4586 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4588 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4589 PACKET_TracepointSource
},
4590 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4592 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4593 PACKET_EnableDisableTracepoints_feature
},
4594 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4595 PACKET_qXfer_fdpic
},
4596 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4598 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4599 PACKET_QDisableRandomization
},
4600 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4601 { "QTBuffer:size", PACKET_DISABLE
,
4602 remote_supported_packet
, PACKET_QTBuffer_size
},
4603 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4604 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4605 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4606 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4607 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4608 PACKET_qXfer_btrace
},
4609 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4610 PACKET_qXfer_btrace_conf
},
4611 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4612 PACKET_Qbtrace_conf_bts_size
},
4613 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4614 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4615 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4616 PACKET_fork_event_feature
},
4617 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4618 PACKET_vfork_event_feature
},
4619 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4620 PACKET_exec_event_feature
},
4621 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4622 PACKET_Qbtrace_conf_pt_size
},
4623 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4624 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4625 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4628 static char *remote_support_xml
;
4630 /* Register string appended to "xmlRegisters=" in qSupported query. */
4633 register_remote_support_xml (const char *xml
)
4635 #if defined(HAVE_LIBEXPAT)
4636 if (remote_support_xml
== NULL
)
4637 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4640 char *copy
= xstrdup (remote_support_xml
+ 13);
4641 char *p
= strtok (copy
, ",");
4645 if (strcmp (p
, xml
) == 0)
4652 while ((p
= strtok (NULL
, ",")) != NULL
);
4655 remote_support_xml
= reconcat (remote_support_xml
,
4656 remote_support_xml
, ",", xml
,
4663 remote_query_supported_append (char *msg
, const char *append
)
4666 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4668 return xstrdup (append
);
4672 remote_query_supported (void)
4674 struct remote_state
*rs
= get_remote_state ();
4677 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4679 /* The packet support flags are handled differently for this packet
4680 than for most others. We treat an error, a disabled packet, and
4681 an empty response identically: any features which must be reported
4682 to be used will be automatically disabled. An empty buffer
4683 accomplishes this, since that is also the representation for a list
4684 containing no features. */
4687 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4690 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4692 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4693 q
= remote_query_supported_append (q
, "multiprocess+");
4695 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4696 q
= remote_query_supported_append (q
, "swbreak+");
4697 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4698 q
= remote_query_supported_append (q
, "hwbreak+");
4700 q
= remote_query_supported_append (q
, "qRelocInsn+");
4702 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4703 != AUTO_BOOLEAN_FALSE
)
4704 q
= remote_query_supported_append (q
, "fork-events+");
4705 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4706 != AUTO_BOOLEAN_FALSE
)
4707 q
= remote_query_supported_append (q
, "vfork-events+");
4708 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4709 != AUTO_BOOLEAN_FALSE
)
4710 q
= remote_query_supported_append (q
, "exec-events+");
4712 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4713 q
= remote_query_supported_append (q
, "vContSupported+");
4715 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4716 q
= remote_query_supported_append (q
, "QThreadEvents+");
4718 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4719 q
= remote_query_supported_append (q
, "no-resumed+");
4721 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4722 the qSupported:xmlRegisters=i386 handling. */
4723 if (remote_support_xml
!= NULL
)
4724 q
= remote_query_supported_append (q
, remote_support_xml
);
4726 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4729 do_cleanups (old_chain
);
4731 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4733 /* If an error occured, warn, but do not return - just reset the
4734 buffer to empty and go on to disable features. */
4735 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4738 warning (_("Remote failure reply: %s"), rs
->buf
);
4743 memset (seen
, 0, sizeof (seen
));
4748 enum packet_support is_supported
;
4749 char *p
, *end
, *name_end
, *value
;
4751 /* First separate out this item from the rest of the packet. If
4752 there's another item after this, we overwrite the separator
4753 (terminated strings are much easier to work with). */
4755 end
= strchr (p
, ';');
4758 end
= p
+ strlen (p
);
4768 warning (_("empty item in \"qSupported\" response"));
4773 name_end
= strchr (p
, '=');
4776 /* This is a name=value entry. */
4777 is_supported
= PACKET_ENABLE
;
4778 value
= name_end
+ 1;
4787 is_supported
= PACKET_ENABLE
;
4791 is_supported
= PACKET_DISABLE
;
4795 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4799 warning (_("unrecognized item \"%s\" "
4800 "in \"qSupported\" response"), p
);
4806 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4807 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4809 const struct protocol_feature
*feature
;
4812 feature
= &remote_protocol_features
[i
];
4813 feature
->func (feature
, is_supported
, value
);
4818 /* If we increased the packet size, make sure to increase the global
4819 buffer size also. We delay this until after parsing the entire
4820 qSupported packet, because this is the same buffer we were
4822 if (rs
->buf_size
< rs
->explicit_packet_size
)
4824 rs
->buf_size
= rs
->explicit_packet_size
;
4825 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4828 /* Handle the defaults for unmentioned features. */
4829 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4832 const struct protocol_feature
*feature
;
4834 feature
= &remote_protocol_features
[i
];
4835 feature
->func (feature
, feature
->default_support
, NULL
);
4839 /* Serial QUIT handler for the remote serial descriptor.
4841 Defers handling a Ctrl-C until we're done with the current
4842 command/response packet sequence, unless:
4844 - We're setting up the connection. Don't send a remote interrupt
4845 request, as we're not fully synced yet. Quit immediately
4848 - The target has been resumed in the foreground
4849 (target_terminal_is_ours is false) with a synchronous resume
4850 packet, and we're blocked waiting for the stop reply, thus a
4851 Ctrl-C should be immediately sent to the target.
4853 - We get a second Ctrl-C while still within the same serial read or
4854 write. In that case the serial is seemingly wedged --- offer to
4857 - We see a second Ctrl-C without target response, after having
4858 previously interrupted the target. In that case the target/stub
4859 is probably wedged --- offer to quit/disconnect.
4863 remote_serial_quit_handler (void)
4865 struct remote_state
*rs
= get_remote_state ();
4867 if (check_quit_flag ())
4869 /* If we're starting up, we're not fully synced yet. Quit
4871 if (rs
->starting_up
)
4873 else if (rs
->got_ctrlc_during_io
)
4875 if (query (_("The target is not responding to GDB commands.\n"
4876 "Stop debugging it? ")))
4877 remote_unpush_and_throw ();
4879 /* If ^C has already been sent once, offer to disconnect. */
4880 else if (!target_terminal_is_ours () && rs
->ctrlc_pending_p
)
4882 /* All-stop protocol, and blocked waiting for stop reply. Send
4883 an interrupt request. */
4884 else if (!target_terminal_is_ours () && rs
->waiting_for_stop_reply
)
4885 target_interrupt (inferior_ptid
);
4887 rs
->got_ctrlc_during_io
= 1;
4891 /* Remove any of the remote.c targets from target stack. Upper targets depend
4892 on it so remove them first. */
4895 remote_unpush_target (void)
4897 pop_all_targets_at_and_above (process_stratum
);
4901 remote_unpush_and_throw (void)
4903 remote_unpush_target ();
4904 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
4908 remote_open_1 (const char *name
, int from_tty
,
4909 struct target_ops
*target
, int extended_p
)
4911 struct remote_state
*rs
= get_remote_state ();
4914 error (_("To open a remote debug connection, you need to specify what\n"
4915 "serial device is attached to the remote system\n"
4916 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4918 /* See FIXME above. */
4919 if (!target_async_permitted
)
4920 wait_forever_enabled_p
= 1;
4922 /* If we're connected to a running target, target_preopen will kill it.
4923 Ask this question first, before target_preopen has a chance to kill
4925 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4928 && !query (_("Already connected to a remote target. Disconnect? ")))
4929 error (_("Still connected."));
4932 /* Here the possibly existing remote target gets unpushed. */
4933 target_preopen (from_tty
);
4935 /* Make sure we send the passed signals list the next time we resume. */
4936 xfree (rs
->last_pass_packet
);
4937 rs
->last_pass_packet
= NULL
;
4939 /* Make sure we send the program signals list the next time we
4941 xfree (rs
->last_program_signals_packet
);
4942 rs
->last_program_signals_packet
= NULL
;
4944 remote_fileio_reset ();
4945 reopen_exec_file ();
4948 rs
->remote_desc
= remote_serial_open (name
);
4949 if (!rs
->remote_desc
)
4950 perror_with_name (name
);
4952 if (baud_rate
!= -1)
4954 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4956 /* The requested speed could not be set. Error out to
4957 top level after closing remote_desc. Take care to
4958 set remote_desc to NULL to avoid closing remote_desc
4960 serial_close (rs
->remote_desc
);
4961 rs
->remote_desc
= NULL
;
4962 perror_with_name (name
);
4966 serial_setparity (rs
->remote_desc
, serial_parity
);
4967 serial_raw (rs
->remote_desc
);
4969 /* If there is something sitting in the buffer we might take it as a
4970 response to a command, which would be bad. */
4971 serial_flush_input (rs
->remote_desc
);
4975 puts_filtered ("Remote debugging using ");
4976 puts_filtered (name
);
4977 puts_filtered ("\n");
4979 push_target (target
); /* Switch to using remote target now. */
4981 /* Register extra event sources in the event loop. */
4982 remote_async_inferior_event_token
4983 = create_async_event_handler (remote_async_inferior_event_handler
,
4985 rs
->notif_state
= remote_notif_state_allocate ();
4987 /* Reset the target state; these things will be queried either by
4988 remote_query_supported or as they are needed. */
4989 reset_all_packet_configs_support ();
4990 rs
->cached_wait_status
= 0;
4991 rs
->explicit_packet_size
= 0;
4993 rs
->extended
= extended_p
;
4994 rs
->waiting_for_stop_reply
= 0;
4995 rs
->ctrlc_pending_p
= 0;
4996 rs
->got_ctrlc_during_io
= 0;
4998 rs
->general_thread
= not_sent_ptid
;
4999 rs
->continue_thread
= not_sent_ptid
;
5000 rs
->remote_traceframe_number
= -1;
5002 /* Probe for ability to use "ThreadInfo" query, as required. */
5003 rs
->use_threadinfo_query
= 1;
5004 rs
->use_threadextra_query
= 1;
5006 readahead_cache_invalidate ();
5008 /* Start out by owning the terminal. */
5009 remote_async_terminal_ours_p
= 1;
5011 if (target_async_permitted
)
5013 /* FIXME: cagney/1999-09-23: During the initial connection it is
5014 assumed that the target is already ready and able to respond to
5015 requests. Unfortunately remote_start_remote() eventually calls
5016 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5017 around this. Eventually a mechanism that allows
5018 wait_for_inferior() to expect/get timeouts will be
5020 wait_forever_enabled_p
= 0;
5023 /* First delete any symbols previously loaded from shared libraries. */
5024 no_shared_libraries (NULL
, 0);
5027 init_thread_list ();
5029 /* Start the remote connection. If error() or QUIT, discard this
5030 target (we'd otherwise be in an inconsistent state) and then
5031 propogate the error on up the exception chain. This ensures that
5032 the caller doesn't stumble along blindly assuming that the
5033 function succeeded. The CLI doesn't have this problem but other
5034 UI's, such as MI do.
5036 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5037 this function should return an error indication letting the
5038 caller restore the previous state. Unfortunately the command
5039 ``target remote'' is directly wired to this function making that
5040 impossible. On a positive note, the CLI side of this problem has
5041 been fixed - the function set_cmd_context() makes it possible for
5042 all the ``target ....'' commands to share a common callback
5043 function. See cli-dump.c. */
5048 remote_start_remote (from_tty
, target
, extended_p
);
5050 CATCH (ex
, RETURN_MASK_ALL
)
5052 /* Pop the partially set up target - unless something else did
5053 already before throwing the exception. */
5054 if (rs
->remote_desc
!= NULL
)
5055 remote_unpush_target ();
5056 if (target_async_permitted
)
5057 wait_forever_enabled_p
= 1;
5058 throw_exception (ex
);
5063 remote_btrace_reset ();
5065 if (target_async_permitted
)
5066 wait_forever_enabled_p
= 1;
5069 /* Detach the specified process. */
5072 remote_detach_pid (int pid
)
5074 struct remote_state
*rs
= get_remote_state ();
5076 if (remote_multi_process_p (rs
))
5077 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5079 strcpy (rs
->buf
, "D");
5082 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5084 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5086 else if (rs
->buf
[0] == '\0')
5087 error (_("Remote doesn't know how to detach"));
5089 error (_("Can't detach process."));
5092 /* This detaches a program to which we previously attached, using
5093 inferior_ptid to identify the process. After this is done, GDB
5094 can be used to debug some other program. We better not have left
5095 any breakpoints in the target program or it'll die when it hits
5099 remote_detach_1 (const char *args
, int from_tty
)
5101 int pid
= ptid_get_pid (inferior_ptid
);
5102 struct remote_state
*rs
= get_remote_state ();
5103 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5107 error (_("Argument given to \"detach\" when remotely debugging."));
5109 if (!target_has_execution
)
5110 error (_("No process to detach from."));
5114 char *exec_file
= get_exec_file (0);
5115 if (exec_file
== NULL
)
5117 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
5118 target_pid_to_str (pid_to_ptid (pid
)));
5119 gdb_flush (gdb_stdout
);
5122 /* Tell the remote target to detach. */
5123 remote_detach_pid (pid
);
5125 /* Exit only if this is the only active inferior. */
5126 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5127 puts_filtered (_("Ending remote debugging.\n"));
5129 /* Check to see if we are detaching a fork parent. Note that if we
5130 are detaching a fork child, tp == NULL. */
5131 is_fork_parent
= (tp
!= NULL
5132 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5134 /* If doing detach-on-fork, we don't mourn, because that will delete
5135 breakpoints that should be available for the followed inferior. */
5136 if (!is_fork_parent
)
5137 target_mourn_inferior ();
5140 inferior_ptid
= null_ptid
;
5141 detach_inferior (pid
);
5146 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5148 remote_detach_1 (args
, from_tty
);
5152 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5154 remote_detach_1 (args
, from_tty
);
5157 /* Target follow-fork function for remote targets. On entry, and
5158 at return, the current inferior is the fork parent.
5160 Note that although this is currently only used for extended-remote,
5161 it is named remote_follow_fork in anticipation of using it for the
5162 remote target as well. */
5165 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5168 struct remote_state
*rs
= get_remote_state ();
5169 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5171 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5172 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5174 /* When following the parent and detaching the child, we detach
5175 the child here. For the case of following the child and
5176 detaching the parent, the detach is done in the target-
5177 independent follow fork code in infrun.c. We can't use
5178 target_detach when detaching an unfollowed child because
5179 the client side doesn't know anything about the child. */
5180 if (detach_fork
&& !follow_child
)
5182 /* Detach the fork child. */
5186 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5187 child_pid
= ptid_get_pid (child_ptid
);
5189 remote_detach_pid (child_pid
);
5190 detach_inferior (child_pid
);
5196 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5197 in the program space of the new inferior. On entry and at return the
5198 current inferior is the exec'ing inferior. INF is the new exec'd
5199 inferior, which may be the same as the exec'ing inferior unless
5200 follow-exec-mode is "new". */
5203 remote_follow_exec (struct target_ops
*ops
,
5204 struct inferior
*inf
, char *execd_pathname
)
5206 /* We know that this is a target file name, so if it has the "target:"
5207 prefix we strip it off before saving it in the program space. */
5208 if (is_target_filename (execd_pathname
))
5209 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5211 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5214 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5217 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5220 error (_("Argument given to \"disconnect\" when remotely debugging."));
5222 /* Make sure we unpush even the extended remote targets. Calling
5223 target_mourn_inferior won't unpush, and remote_mourn won't
5224 unpush if there is more than one inferior left. */
5225 unpush_target (target
);
5226 generic_mourn_inferior ();
5229 puts_filtered ("Ending remote debugging.\n");
5232 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5233 be chatty about it. */
5236 extended_remote_attach (struct target_ops
*target
, const char *args
,
5239 struct remote_state
*rs
= get_remote_state ();
5241 char *wait_status
= NULL
;
5243 pid
= parse_pid_to_attach (args
);
5245 /* Remote PID can be freely equal to getpid, do not check it here the same
5246 way as in other targets. */
5248 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5249 error (_("This target does not support attaching to a process"));
5253 char *exec_file
= get_exec_file (0);
5256 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5257 target_pid_to_str (pid_to_ptid (pid
)));
5259 printf_unfiltered (_("Attaching to %s\n"),
5260 target_pid_to_str (pid_to_ptid (pid
)));
5262 gdb_flush (gdb_stdout
);
5265 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5267 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5269 switch (packet_ok (rs
->buf
,
5270 &remote_protocol_packets
[PACKET_vAttach
]))
5273 if (!target_is_non_stop_p ())
5275 /* Save the reply for later. */
5276 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5277 strcpy (wait_status
, rs
->buf
);
5279 else if (strcmp (rs
->buf
, "OK") != 0)
5280 error (_("Attaching to %s failed with: %s"),
5281 target_pid_to_str (pid_to_ptid (pid
)),
5284 case PACKET_UNKNOWN
:
5285 error (_("This target does not support attaching to a process"));
5287 error (_("Attaching to %s failed"),
5288 target_pid_to_str (pid_to_ptid (pid
)));
5291 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5293 inferior_ptid
= pid_to_ptid (pid
);
5295 if (target_is_non_stop_p ())
5297 struct thread_info
*thread
;
5299 /* Get list of threads. */
5300 remote_update_thread_list (target
);
5302 thread
= first_thread_of_process (pid
);
5304 inferior_ptid
= thread
->ptid
;
5306 inferior_ptid
= pid_to_ptid (pid
);
5308 /* Invalidate our notion of the remote current thread. */
5309 record_currthread (rs
, minus_one_ptid
);
5313 /* Now, if we have thread information, update inferior_ptid. */
5314 inferior_ptid
= remote_current_thread (inferior_ptid
);
5316 /* Add the main thread to the thread list. */
5317 add_thread_silent (inferior_ptid
);
5320 /* Next, if the target can specify a description, read it. We do
5321 this before anything involving memory or registers. */
5322 target_find_description ();
5324 if (!target_is_non_stop_p ())
5326 /* Use the previously fetched status. */
5327 gdb_assert (wait_status
!= NULL
);
5329 if (target_can_async_p ())
5331 struct notif_event
*reply
5332 = remote_notif_parse (¬if_client_stop
, wait_status
);
5334 push_stop_reply ((struct stop_reply
*) reply
);
5340 gdb_assert (wait_status
!= NULL
);
5341 strcpy (rs
->buf
, wait_status
);
5342 rs
->cached_wait_status
= 1;
5346 gdb_assert (wait_status
== NULL
);
5349 /* Implementation of the to_post_attach method. */
5352 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5354 /* Get text, data & bss offsets. */
5357 /* In certain cases GDB might not have had the chance to start
5358 symbol lookup up until now. This could happen if the debugged
5359 binary is not using shared libraries, the vsyscall page is not
5360 present (on Linux) and the binary itself hadn't changed since the
5361 debugging process was started. */
5362 if (symfile_objfile
!= NULL
)
5363 remote_check_symbols();
5367 /* Check for the availability of vCont. This function should also check
5371 remote_vcont_probe (struct remote_state
*rs
)
5375 strcpy (rs
->buf
, "vCont?");
5377 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5380 /* Make sure that the features we assume are supported. */
5381 if (startswith (buf
, "vCont"))
5384 int support_c
, support_C
;
5386 rs
->supports_vCont
.s
= 0;
5387 rs
->supports_vCont
.S
= 0;
5390 rs
->supports_vCont
.t
= 0;
5391 rs
->supports_vCont
.r
= 0;
5392 while (p
&& *p
== ';')
5395 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5396 rs
->supports_vCont
.s
= 1;
5397 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5398 rs
->supports_vCont
.S
= 1;
5399 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5401 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5403 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5404 rs
->supports_vCont
.t
= 1;
5405 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5406 rs
->supports_vCont
.r
= 1;
5408 p
= strchr (p
, ';');
5411 /* If c, and C are not all supported, we can't use vCont. Clearing
5412 BUF will make packet_ok disable the packet. */
5413 if (!support_c
|| !support_C
)
5417 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5420 /* Helper function for building "vCont" resumptions. Write a
5421 resumption to P. ENDP points to one-passed-the-end of the buffer
5422 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5423 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5424 resumed thread should be single-stepped and/or signalled. If PTID
5425 equals minus_one_ptid, then all threads are resumed; if PTID
5426 represents a process, then all threads of the process are resumed;
5427 the thread to be stepped and/or signalled is given in the global
5431 append_resumption (char *p
, char *endp
,
5432 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5434 struct remote_state
*rs
= get_remote_state ();
5436 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5437 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5439 /* GDB is willing to range step. */
5440 && use_range_stepping
5441 /* Target supports range stepping. */
5442 && rs
->supports_vCont
.r
5443 /* We don't currently support range stepping multiple
5444 threads with a wildcard (though the protocol allows it,
5445 so stubs shouldn't make an active effort to forbid
5447 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5449 struct thread_info
*tp
;
5451 if (ptid_equal (ptid
, minus_one_ptid
))
5453 /* If we don't know about the target thread's tid, then
5454 we're resuming magic_null_ptid (see caller). */
5455 tp
= find_thread_ptid (magic_null_ptid
);
5458 tp
= find_thread_ptid (ptid
);
5459 gdb_assert (tp
!= NULL
);
5461 if (tp
->control
.may_range_step
)
5463 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5465 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5466 phex_nz (tp
->control
.step_range_start
,
5468 phex_nz (tp
->control
.step_range_end
,
5472 p
+= xsnprintf (p
, endp
- p
, ";s");
5475 p
+= xsnprintf (p
, endp
- p
, ";s");
5476 else if (siggnal
!= GDB_SIGNAL_0
)
5477 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5479 p
+= xsnprintf (p
, endp
- p
, ";c");
5481 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5485 /* All (-1) threads of process. */
5486 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5488 p
+= xsnprintf (p
, endp
- p
, ":");
5489 p
= write_ptid (p
, endp
, nptid
);
5491 else if (!ptid_equal (ptid
, minus_one_ptid
))
5493 p
+= xsnprintf (p
, endp
- p
, ":");
5494 p
= write_ptid (p
, endp
, ptid
);
5500 /* Clear the thread's private info on resume. */
5503 resume_clear_thread_private_info (struct thread_info
*thread
)
5505 if (thread
->priv
!= NULL
)
5507 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5508 thread
->priv
->watch_data_address
= 0;
5512 /* Append a vCont continue-with-signal action for threads that have a
5513 non-zero stop signal. */
5516 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5518 struct thread_info
*thread
;
5520 ALL_NON_EXITED_THREADS (thread
)
5521 if (ptid_match (thread
->ptid
, ptid
)
5522 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5523 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5525 p
= append_resumption (p
, endp
, thread
->ptid
,
5526 0, thread
->suspend
.stop_signal
);
5527 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5528 resume_clear_thread_private_info (thread
);
5534 /* Resume the remote inferior by using a "vCont" packet. The thread
5535 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5536 resumed thread should be single-stepped and/or signalled. If PTID
5537 equals minus_one_ptid, then all threads are resumed; the thread to
5538 be stepped and/or signalled is given in the global INFERIOR_PTID.
5539 This function returns non-zero iff it resumes the inferior.
5541 This function issues a strict subset of all possible vCont commands at the
5545 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5547 struct remote_state
*rs
= get_remote_state ();
5551 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5552 remote_vcont_probe (rs
);
5554 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5558 endp
= rs
->buf
+ get_remote_packet_size ();
5560 /* If we could generate a wider range of packets, we'd have to worry
5561 about overflowing BUF. Should there be a generic
5562 "multi-part-packet" packet? */
5564 p
+= xsnprintf (p
, endp
- p
, "vCont");
5566 if (ptid_equal (ptid
, magic_null_ptid
))
5568 /* MAGIC_NULL_PTID means that we don't have any active threads,
5569 so we don't have any TID numbers the inferior will
5570 understand. Make sure to only send forms that do not specify
5572 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5574 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5576 /* Resume all threads (of all processes, or of a single
5577 process), with preference for INFERIOR_PTID. This assumes
5578 inferior_ptid belongs to the set of all threads we are about
5580 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5582 /* Step inferior_ptid, with or without signal. */
5583 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5586 /* Also pass down any pending signaled resumption for other
5587 threads not the current. */
5588 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5590 /* And continue others without a signal. */
5591 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5595 /* Scheduler locking; resume only PTID. */
5596 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5599 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5602 if (target_is_non_stop_p ())
5604 /* In non-stop, the stub replies to vCont with "OK". The stop
5605 reply will be reported asynchronously by means of a `%Stop'
5607 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5608 if (strcmp (rs
->buf
, "OK") != 0)
5609 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5615 /* Tell the remote machine to resume. */
5618 remote_resume (struct target_ops
*ops
,
5619 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5621 struct remote_state
*rs
= get_remote_state ();
5623 struct thread_info
*thread
;
5625 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5626 (explained in remote-notif.c:handle_notification) so
5627 remote_notif_process is not called. We need find a place where
5628 it is safe to start a 'vNotif' sequence. It is good to do it
5629 before resuming inferior, because inferior was stopped and no RSP
5630 traffic at that moment. */
5631 if (!target_is_non_stop_p ())
5632 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5634 rs
->last_sent_signal
= siggnal
;
5635 rs
->last_sent_step
= step
;
5637 /* The vCont packet doesn't need to specify threads via Hc. */
5638 /* No reverse support (yet) for vCont. */
5639 if (execution_direction
!= EXEC_REVERSE
)
5640 if (remote_vcont_resume (ptid
, step
, siggnal
))
5643 /* All other supported resume packets do use Hc, so set the continue
5645 if (ptid_equal (ptid
, minus_one_ptid
))
5646 set_continue_thread (any_thread_ptid
);
5648 set_continue_thread (ptid
);
5650 ALL_NON_EXITED_THREADS (thread
)
5651 resume_clear_thread_private_info (thread
);
5654 if (execution_direction
== EXEC_REVERSE
)
5656 /* We don't pass signals to the target in reverse exec mode. */
5657 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5658 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5661 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5662 error (_("Remote reverse-step not supported."));
5663 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5664 error (_("Remote reverse-continue not supported."));
5666 strcpy (buf
, step
? "bs" : "bc");
5668 else if (siggnal
!= GDB_SIGNAL_0
)
5670 buf
[0] = step
? 'S' : 'C';
5671 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5672 buf
[2] = tohex (((int) siggnal
) & 0xf);
5676 strcpy (buf
, step
? "s" : "c");
5681 /* We are about to start executing the inferior, let's register it
5682 with the event loop. NOTE: this is the one place where all the
5683 execution commands end up. We could alternatively do this in each
5684 of the execution commands in infcmd.c. */
5685 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5686 into infcmd.c in order to allow inferior function calls to work
5687 NOT asynchronously. */
5688 if (target_can_async_p ())
5691 /* We've just told the target to resume. The remote server will
5692 wait for the inferior to stop, and then send a stop reply. In
5693 the mean time, we can't start another command/query ourselves
5694 because the stub wouldn't be ready to process it. This applies
5695 only to the base all-stop protocol, however. In non-stop (which
5696 only supports vCont), the stub replies with an "OK", and is
5697 immediate able to process further serial input. */
5698 if (!target_is_non_stop_p ())
5699 rs
->waiting_for_stop_reply
= 1;
5703 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5704 thread, all threads of a remote process, or all threads of all
5708 remote_stop_ns (ptid_t ptid
)
5710 struct remote_state
*rs
= get_remote_state ();
5712 char *endp
= rs
->buf
+ get_remote_packet_size ();
5714 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5715 remote_vcont_probe (rs
);
5717 if (!rs
->supports_vCont
.t
)
5718 error (_("Remote server does not support stopping threads"));
5720 if (ptid_equal (ptid
, minus_one_ptid
)
5721 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5722 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5727 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5729 if (ptid_is_pid (ptid
))
5730 /* All (-1) threads of process. */
5731 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5734 /* Small optimization: if we already have a stop reply for
5735 this thread, no use in telling the stub we want this
5737 if (peek_stop_reply (ptid
))
5743 write_ptid (p
, endp
, nptid
);
5746 /* In non-stop, we get an immediate OK reply. The stop reply will
5747 come in asynchronously by notification. */
5749 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5750 if (strcmp (rs
->buf
, "OK") != 0)
5751 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5754 /* All-stop version of target_interrupt. Sends a break or a ^C to
5755 interrupt the remote target. It is undefined which thread of which
5756 process reports the interrupt. */
5759 remote_interrupt_as (void)
5761 struct remote_state
*rs
= get_remote_state ();
5763 rs
->ctrlc_pending_p
= 1;
5765 /* If the inferior is stopped already, but the core didn't know
5766 about it yet, just ignore the request. The cached wait status
5767 will be collected in remote_wait. */
5768 if (rs
->cached_wait_status
)
5771 /* Send interrupt_sequence to remote target. */
5772 send_interrupt_sequence ();
5775 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5776 the remote target. It is undefined which thread of which process
5777 reports the interrupt. Throws an error if the packet is not
5778 supported by the server. */
5781 remote_interrupt_ns (void)
5783 struct remote_state
*rs
= get_remote_state ();
5785 char *endp
= rs
->buf
+ get_remote_packet_size ();
5787 xsnprintf (p
, endp
- p
, "vCtrlC");
5789 /* In non-stop, we get an immediate OK reply. The stop reply will
5790 come in asynchronously by notification. */
5792 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5794 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
5798 case PACKET_UNKNOWN
:
5799 error (_("No support for interrupting the remote target."));
5801 error (_("Interrupting target failed: %s"), rs
->buf
);
5805 /* Implement the to_stop function for the remote targets. */
5808 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5811 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5813 if (target_is_non_stop_p ())
5814 remote_stop_ns (ptid
);
5817 /* We don't currently have a way to transparently pause the
5818 remote target in all-stop mode. Interrupt it instead. */
5819 remote_interrupt_as ();
5823 /* Implement the to_interrupt function for the remote targets. */
5826 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5828 struct remote_state
*rs
= get_remote_state ();
5831 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5833 if (target_is_non_stop_p ())
5834 remote_interrupt_ns ();
5836 remote_interrupt_as ();
5839 /* Implement the to_pass_ctrlc function for the remote targets. */
5842 remote_pass_ctrlc (struct target_ops
*self
)
5844 struct remote_state
*rs
= get_remote_state ();
5847 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
5849 /* If we're starting up, we're not fully synced yet. Quit
5851 if (rs
->starting_up
)
5853 /* If ^C has already been sent once, offer to disconnect. */
5854 else if (rs
->ctrlc_pending_p
)
5857 target_interrupt (inferior_ptid
);
5860 /* Ask the user what to do when an interrupt is received. */
5863 interrupt_query (void)
5865 struct remote_state
*rs
= get_remote_state ();
5867 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5869 if (query (_("The target is not responding to interrupt requests.\n"
5870 "Stop debugging it? ")))
5872 remote_unpush_target ();
5873 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5878 if (query (_("Interrupted while waiting for the program.\n"
5879 "Give up waiting? ")))
5884 /* Enable/disable target terminal ownership. Most targets can use
5885 terminal groups to control terminal ownership. Remote targets are
5886 different in that explicit transfer of ownership to/from GDB/target
5890 remote_terminal_inferior (struct target_ops
*self
)
5892 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5893 idempotent. The event-loop GDB talking to an asynchronous target
5894 with a synchronous command calls this function from both
5895 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5896 transfer the terminal to the target when it shouldn't this guard
5898 if (!remote_async_terminal_ours_p
)
5900 delete_file_handler (input_fd
);
5901 remote_async_terminal_ours_p
= 0;
5902 /* NOTE: At this point we could also register our selves as the
5903 recipient of all input. Any characters typed could then be
5904 passed on down to the target. */
5908 remote_terminal_ours (struct target_ops
*self
)
5910 /* See FIXME in remote_terminal_inferior. */
5911 if (remote_async_terminal_ours_p
)
5913 add_file_handler (input_fd
, stdin_event_handler
, 0);
5914 remote_async_terminal_ours_p
= 1;
5918 remote_console_output (char *msg
)
5922 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5925 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5929 fputs_unfiltered (tb
, gdb_stdtarg
);
5931 gdb_flush (gdb_stdtarg
);
5934 typedef struct cached_reg
5937 gdb_byte data
[MAX_REGISTER_SIZE
];
5940 DEF_VEC_O(cached_reg_t
);
5942 typedef struct stop_reply
5944 struct notif_event base
;
5946 /* The identifier of the thread about this event */
5949 /* The remote state this event is associated with. When the remote
5950 connection, represented by a remote_state object, is closed,
5951 all the associated stop_reply events should be released. */
5952 struct remote_state
*rs
;
5954 struct target_waitstatus ws
;
5956 /* Expedited registers. This makes remote debugging a bit more
5957 efficient for those targets that provide critical registers as
5958 part of their normal status mechanism (as another roundtrip to
5959 fetch them is avoided). */
5960 VEC(cached_reg_t
) *regcache
;
5962 enum target_stop_reason stop_reason
;
5964 CORE_ADDR watch_data_address
;
5969 DECLARE_QUEUE_P (stop_reply_p
);
5970 DEFINE_QUEUE_P (stop_reply_p
);
5971 /* The list of already fetched and acknowledged stop events. This
5972 queue is used for notification Stop, and other notifications
5973 don't need queue for their events, because the notification events
5974 of Stop can't be consumed immediately, so that events should be
5975 queued first, and be consumed by remote_wait_{ns,as} one per
5976 time. Other notifications can consume their events immediately,
5977 so queue is not needed for them. */
5978 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5981 stop_reply_xfree (struct stop_reply
*r
)
5983 notif_event_xfree ((struct notif_event
*) r
);
5986 /* Return the length of the stop reply queue. */
5989 stop_reply_queue_length (void)
5991 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
5995 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5996 struct notif_event
*event
)
5998 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6002 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6003 struct notif_event
*event
)
6005 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6008 putpkt ((char *) self
->ack_command
);
6010 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6011 /* We got an unknown stop reply. */
6012 error (_("Unknown stop reply"));
6014 push_stop_reply (stop_reply
);
6018 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6020 /* We can't get pending events in remote_notif_process for
6021 notification stop, and we have to do this in remote_wait_ns
6022 instead. If we fetch all queued events from stub, remote stub
6023 may exit and we have no chance to process them back in
6025 mark_async_event_handler (remote_async_inferior_event_token
);
6030 stop_reply_dtr (struct notif_event
*event
)
6032 struct stop_reply
*r
= (struct stop_reply
*) event
;
6034 VEC_free (cached_reg_t
, r
->regcache
);
6037 static struct notif_event
*
6038 remote_notif_stop_alloc_reply (void)
6040 /* We cast to a pointer to the "base class". */
6041 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6043 r
->dtr
= stop_reply_dtr
;
6048 /* A client of notification Stop. */
6050 struct notif_client notif_client_stop
=
6054 remote_notif_stop_parse
,
6055 remote_notif_stop_ack
,
6056 remote_notif_stop_can_get_pending_events
,
6057 remote_notif_stop_alloc_reply
,
6061 /* A parameter to pass data in and out. */
6063 struct queue_iter_param
6066 struct stop_reply
*output
;
6069 /* Determine if THREAD is a pending fork parent thread. ARG contains
6070 the pid of the process that owns the threads we want to check, or
6071 -1 if we want to check all threads. */
6074 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6077 if (ws
->kind
== TARGET_WAITKIND_FORKED
6078 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6080 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6087 /* Check whether EVENT is a fork event, and if it is, remove the
6088 fork child from the context list passed in DATA. */
6091 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6092 QUEUE_ITER (stop_reply_p
) *iter
,
6096 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6097 struct threads_listing_context
*context
6098 = (struct threads_listing_context
*) param
->input
;
6100 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6101 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6102 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6103 threads_listing_context_remove (&event
->ws
, context
);
6108 /* If CONTEXT contains any fork child threads that have not been
6109 reported yet, remove them from the CONTEXT list. If such a
6110 thread exists it is because we are stopped at a fork catchpoint
6111 and have not yet called follow_fork, which will set up the
6112 host-side data structures for the new process. */
6115 remove_new_fork_children (struct threads_listing_context
*context
)
6117 struct thread_info
* thread
;
6119 struct notif_client
*notif
= ¬if_client_stop
;
6120 struct queue_iter_param param
;
6122 /* For any threads stopped at a fork event, remove the corresponding
6123 fork child threads from the CONTEXT list. */
6124 ALL_NON_EXITED_THREADS (thread
)
6126 struct target_waitstatus
*ws
;
6128 if (thread
->suspend
.waitstatus_pending_p
)
6129 ws
= &thread
->suspend
.waitstatus
;
6131 ws
= &thread
->pending_follow
;
6133 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6135 threads_listing_context_remove (ws
, context
);
6139 /* Check for any pending fork events (not reported or processed yet)
6140 in process PID and remove those fork child threads from the
6141 CONTEXT list as well. */
6142 remote_notif_get_pending_events (notif
);
6143 param
.input
= context
;
6144 param
.output
= NULL
;
6145 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6146 remove_child_of_pending_fork
, ¶m
);
6149 /* Remove stop replies in the queue if its pid is equal to the given
6153 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6154 QUEUE_ITER (stop_reply_p
) *iter
,
6158 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6159 struct inferior
*inf
= (struct inferior
*) param
->input
;
6161 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6163 stop_reply_xfree (event
);
6164 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6170 /* Discard all pending stop replies of inferior INF. */
6173 discard_pending_stop_replies (struct inferior
*inf
)
6175 struct queue_iter_param param
;
6176 struct stop_reply
*reply
;
6177 struct remote_state
*rs
= get_remote_state ();
6178 struct remote_notif_state
*rns
= rs
->notif_state
;
6180 /* This function can be notified when an inferior exists. When the
6181 target is not remote, the notification state is NULL. */
6182 if (rs
->remote_desc
== NULL
)
6185 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6187 /* Discard the in-flight notification. */
6188 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6190 stop_reply_xfree (reply
);
6191 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6195 param
.output
= NULL
;
6196 /* Discard the stop replies we have already pulled with
6198 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6199 remove_stop_reply_for_inferior
, ¶m
);
6202 /* If its remote state is equal to the given remote state,
6203 remove EVENT from the stop reply queue. */
6206 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6207 QUEUE_ITER (stop_reply_p
) *iter
,
6211 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6212 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6214 if (event
->rs
== rs
)
6216 stop_reply_xfree (event
);
6217 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6223 /* Discard the stop replies for RS in stop_reply_queue. */
6226 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6228 struct queue_iter_param param
;
6231 param
.output
= NULL
;
6232 /* Discard the stop replies we have already pulled with
6234 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6235 remove_stop_reply_of_remote_state
, ¶m
);
6238 /* A parameter to pass data in and out. */
6241 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6242 QUEUE_ITER (stop_reply_p
) *iter
,
6246 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6247 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6249 if (ptid_match (event
->ptid
, *ptid
))
6251 param
->output
= event
;
6252 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6259 /* Remove the first reply in 'stop_reply_queue' which matches
6262 static struct stop_reply
*
6263 remote_notif_remove_queued_reply (ptid_t ptid
)
6265 struct queue_iter_param param
;
6267 param
.input
= &ptid
;
6268 param
.output
= NULL
;
6270 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6271 remote_notif_remove_once_on_match
, ¶m
);
6273 fprintf_unfiltered (gdb_stdlog
,
6274 "notif: discard queued event: 'Stop' in %s\n",
6275 target_pid_to_str (ptid
));
6277 return param
.output
;
6280 /* Look for a queued stop reply belonging to PTID. If one is found,
6281 remove it from the queue, and return it. Returns NULL if none is
6282 found. If there are still queued events left to process, tell the
6283 event loop to get back to target_wait soon. */
6285 static struct stop_reply
*
6286 queued_stop_reply (ptid_t ptid
)
6288 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6290 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6291 /* There's still at least an event left. */
6292 mark_async_event_handler (remote_async_inferior_event_token
);
6297 /* Push a fully parsed stop reply in the stop reply queue. Since we
6298 know that we now have at least one queued event left to pass to the
6299 core side, tell the event loop to get back to target_wait soon. */
6302 push_stop_reply (struct stop_reply
*new_event
)
6304 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6307 fprintf_unfiltered (gdb_stdlog
,
6308 "notif: push 'Stop' %s to queue %d\n",
6309 target_pid_to_str (new_event
->ptid
),
6310 QUEUE_length (stop_reply_p
,
6313 mark_async_event_handler (remote_async_inferior_event_token
);
6317 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6318 QUEUE_ITER (stop_reply_p
) *iter
,
6319 struct stop_reply
*event
,
6322 ptid_t
*ptid
= (ptid_t
*) data
;
6324 return !(ptid_equal (*ptid
, event
->ptid
)
6325 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6328 /* Returns true if we have a stop reply for PTID. */
6331 peek_stop_reply (ptid_t ptid
)
6333 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6334 stop_reply_match_ptid_and_ws
, &ptid
);
6337 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6338 starting with P and ending with PEND matches PREFIX. */
6341 strprefix (const char *p
, const char *pend
, const char *prefix
)
6343 for ( ; p
< pend
; p
++, prefix
++)
6346 return *prefix
== '\0';
6349 /* Parse the stop reply in BUF. Either the function succeeds, and the
6350 result is stored in EVENT, or throws an error. */
6353 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6355 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6360 event
->ptid
= null_ptid
;
6361 event
->rs
= get_remote_state ();
6362 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6363 event
->ws
.value
.integer
= 0;
6364 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6365 event
->regcache
= NULL
;
6370 case 'T': /* Status with PC, SP, FP, ... */
6371 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6372 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6374 n... = register number
6375 r... = register contents
6378 p
= &buf
[3]; /* after Txx */
6384 p1
= strchr (p
, ':');
6386 error (_("Malformed packet(a) (missing colon): %s\n\
6390 error (_("Malformed packet(a) (missing register number): %s\n\
6394 /* Some "registers" are actually extended stop information.
6395 Note if you're adding a new entry here: GDB 7.9 and
6396 earlier assume that all register "numbers" that start
6397 with an hex digit are real register numbers. Make sure
6398 the server only sends such a packet if it knows the
6399 client understands it. */
6401 if (strprefix (p
, p1
, "thread"))
6402 event
->ptid
= read_ptid (++p1
, &p
);
6403 else if (strprefix (p
, p1
, "syscall_entry"))
6407 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6408 p
= unpack_varlen_hex (++p1
, &sysno
);
6409 event
->ws
.value
.syscall_number
= (int) sysno
;
6411 else if (strprefix (p
, p1
, "syscall_return"))
6415 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6416 p
= unpack_varlen_hex (++p1
, &sysno
);
6417 event
->ws
.value
.syscall_number
= (int) sysno
;
6419 else if (strprefix (p
, p1
, "watch")
6420 || strprefix (p
, p1
, "rwatch")
6421 || strprefix (p
, p1
, "awatch"))
6423 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6424 p
= unpack_varlen_hex (++p1
, &addr
);
6425 event
->watch_data_address
= (CORE_ADDR
) addr
;
6427 else if (strprefix (p
, p1
, "swbreak"))
6429 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6431 /* Make sure the stub doesn't forget to indicate support
6433 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6434 error (_("Unexpected swbreak stop reason"));
6436 /* The value part is documented as "must be empty",
6437 though we ignore it, in case we ever decide to make
6438 use of it in a backward compatible way. */
6439 p
= strchrnul (p1
+ 1, ';');
6441 else if (strprefix (p
, p1
, "hwbreak"))
6443 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6445 /* Make sure the stub doesn't forget to indicate support
6447 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6448 error (_("Unexpected hwbreak stop reason"));
6451 p
= strchrnul (p1
+ 1, ';');
6453 else if (strprefix (p
, p1
, "library"))
6455 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6456 p
= strchrnul (p1
+ 1, ';');
6458 else if (strprefix (p
, p1
, "replaylog"))
6460 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6461 /* p1 will indicate "begin" or "end", but it makes
6462 no difference for now, so ignore it. */
6463 p
= strchrnul (p1
+ 1, ';');
6465 else if (strprefix (p
, p1
, "core"))
6469 p
= unpack_varlen_hex (++p1
, &c
);
6472 else if (strprefix (p
, p1
, "fork"))
6474 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6475 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6477 else if (strprefix (p
, p1
, "vfork"))
6479 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6480 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6482 else if (strprefix (p
, p1
, "vforkdone"))
6484 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6485 p
= strchrnul (p1
+ 1, ';');
6487 else if (strprefix (p
, p1
, "exec"))
6490 char pathname
[PATH_MAX
];
6493 /* Determine the length of the execd pathname. */
6494 p
= unpack_varlen_hex (++p1
, &ignored
);
6495 pathlen
= (p
- p1
) / 2;
6497 /* Save the pathname for event reporting and for
6498 the next run command. */
6499 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6500 pathname
[pathlen
] = '\0';
6502 /* This is freed during event handling. */
6503 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6504 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6506 /* Skip the registers included in this packet, since
6507 they may be for an architecture different from the
6508 one used by the original program. */
6511 else if (strprefix (p
, p1
, "create"))
6513 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6514 p
= strchrnul (p1
+ 1, ';');
6523 p
= strchrnul (p1
+ 1, ';');
6528 /* Maybe a real ``P'' register number. */
6529 p_temp
= unpack_varlen_hex (p
, &pnum
);
6530 /* If the first invalid character is the colon, we got a
6531 register number. Otherwise, it's an unknown stop
6535 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6536 cached_reg_t cached_reg
;
6539 error (_("Remote sent bad register number %s: %s\n\
6541 hex_string (pnum
), p
, buf
);
6543 cached_reg
.num
= reg
->regnum
;
6546 fieldsize
= hex2bin (p
, cached_reg
.data
,
6547 register_size (target_gdbarch (),
6550 if (fieldsize
< register_size (target_gdbarch (),
6552 warning (_("Remote reply is too short: %s"), buf
);
6554 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6558 /* Not a number. Silently skip unknown optional
6560 p
= strchrnul (p1
+ 1, ';');
6565 error (_("Remote register badly formatted: %s\nhere: %s"),
6570 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6574 case 'S': /* Old style status, just signal only. */
6578 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6579 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6580 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6581 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6583 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6586 case 'w': /* Thread exited. */
6591 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
6592 p
= unpack_varlen_hex (&buf
[1], &value
);
6593 event
->ws
.value
.integer
= value
;
6595 error (_("stop reply packet badly formatted: %s"), buf
);
6596 event
->ptid
= read_ptid (++p
, NULL
);
6599 case 'W': /* Target exited. */
6606 /* GDB used to accept only 2 hex chars here. Stubs should
6607 only send more if they detect GDB supports multi-process
6609 p
= unpack_varlen_hex (&buf
[1], &value
);
6613 /* The remote process exited. */
6614 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6615 event
->ws
.value
.integer
= value
;
6619 /* The remote process exited with a signal. */
6620 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6621 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6622 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6624 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6627 /* If no process is specified, assume inferior_ptid. */
6628 pid
= ptid_get_pid (inferior_ptid
);
6637 else if (startswith (p
, "process:"))
6641 p
+= sizeof ("process:") - 1;
6642 unpack_varlen_hex (p
, &upid
);
6646 error (_("unknown stop reply packet: %s"), buf
);
6649 error (_("unknown stop reply packet: %s"), buf
);
6650 event
->ptid
= pid_to_ptid (pid
);
6654 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
6655 event
->ptid
= minus_one_ptid
;
6659 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
6660 error (_("No process or thread specified in stop reply: %s"), buf
);
6663 /* When the stub wants to tell GDB about a new notification reply, it
6664 sends a notification (%Stop, for example). Those can come it at
6665 any time, hence, we have to make sure that any pending
6666 putpkt/getpkt sequence we're making is finished, before querying
6667 the stub for more events with the corresponding ack command
6668 (vStopped, for example). E.g., if we started a vStopped sequence
6669 immediately upon receiving the notification, something like this
6677 1.6) <-- (registers reply to step #1.3)
6679 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6682 To solve this, whenever we parse a %Stop notification successfully,
6683 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6684 doing whatever we were doing:
6690 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6691 2.5) <-- (registers reply to step #2.3)
6693 Eventualy after step #2.5, we return to the event loop, which
6694 notices there's an event on the
6695 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6696 associated callback --- the function below. At this point, we're
6697 always safe to start a vStopped sequence. :
6700 2.7) <-- T05 thread:2
6706 remote_notif_get_pending_events (struct notif_client
*nc
)
6708 struct remote_state
*rs
= get_remote_state ();
6710 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6713 fprintf_unfiltered (gdb_stdlog
,
6714 "notif: process: '%s' ack pending event\n",
6718 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6719 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6723 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6724 if (strcmp (rs
->buf
, "OK") == 0)
6727 remote_notif_ack (nc
, rs
->buf
);
6733 fprintf_unfiltered (gdb_stdlog
,
6734 "notif: process: '%s' no pending reply\n",
6739 /* Called when it is decided that STOP_REPLY holds the info of the
6740 event that is to be returned to the core. This function always
6741 destroys STOP_REPLY. */
6744 process_stop_reply (struct stop_reply
*stop_reply
,
6745 struct target_waitstatus
*status
)
6749 *status
= stop_reply
->ws
;
6750 ptid
= stop_reply
->ptid
;
6752 /* If no thread/process was reported by the stub, assume the current
6754 if (ptid_equal (ptid
, null_ptid
))
6755 ptid
= inferior_ptid
;
6757 if (status
->kind
!= TARGET_WAITKIND_EXITED
6758 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
6759 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
6761 struct private_thread_info
*remote_thr
;
6763 /* Expedited registers. */
6764 if (stop_reply
->regcache
)
6766 struct regcache
*regcache
6767 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6772 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6774 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6775 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6778 remote_notice_new_inferior (ptid
, 0);
6779 remote_thr
= demand_private_info (ptid
);
6780 remote_thr
->core
= stop_reply
->core
;
6781 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
6782 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
6785 stop_reply_xfree (stop_reply
);
6789 /* The non-stop mode version of target_wait. */
6792 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6794 struct remote_state
*rs
= get_remote_state ();
6795 struct stop_reply
*stop_reply
;
6799 /* If in non-stop mode, get out of getpkt even if a
6800 notification is received. */
6802 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6803 0 /* forever */, &is_notif
);
6806 if (ret
!= -1 && !is_notif
)
6809 case 'E': /* Error of some sort. */
6810 /* We're out of sync with the target now. Did it continue
6811 or not? We can't tell which thread it was in non-stop,
6812 so just ignore this. */
6813 warning (_("Remote failure reply: %s"), rs
->buf
);
6815 case 'O': /* Console output. */
6816 remote_console_output (rs
->buf
+ 1);
6819 warning (_("Invalid remote reply: %s"), rs
->buf
);
6823 /* Acknowledge a pending stop reply that may have arrived in the
6825 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6826 remote_notif_get_pending_events (¬if_client_stop
);
6828 /* If indeed we noticed a stop reply, we're done. */
6829 stop_reply
= queued_stop_reply (ptid
);
6830 if (stop_reply
!= NULL
)
6831 return process_stop_reply (stop_reply
, status
);
6833 /* Still no event. If we're just polling for an event, then
6834 return to the event loop. */
6835 if (options
& TARGET_WNOHANG
)
6837 status
->kind
= TARGET_WAITKIND_IGNORE
;
6838 return minus_one_ptid
;
6841 /* Otherwise do a blocking wait. */
6842 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6843 1 /* forever */, &is_notif
);
6847 /* Wait until the remote machine stops, then return, storing status in
6848 STATUS just as `wait' would. */
6851 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6853 struct remote_state
*rs
= get_remote_state ();
6854 ptid_t event_ptid
= null_ptid
;
6856 struct stop_reply
*stop_reply
;
6860 status
->kind
= TARGET_WAITKIND_IGNORE
;
6861 status
->value
.integer
= 0;
6863 stop_reply
= queued_stop_reply (ptid
);
6864 if (stop_reply
!= NULL
)
6865 return process_stop_reply (stop_reply
, status
);
6867 if (rs
->cached_wait_status
)
6868 /* Use the cached wait status, but only once. */
6869 rs
->cached_wait_status
= 0;
6874 int forever
= ((options
& TARGET_WNOHANG
) == 0
6875 && wait_forever_enabled_p
);
6877 if (!rs
->waiting_for_stop_reply
)
6879 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6880 return minus_one_ptid
;
6883 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6884 _never_ wait for ever -> test on target_is_async_p().
6885 However, before we do that we need to ensure that the caller
6886 knows how to take the target into/out of async mode. */
6887 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6888 forever
, &is_notif
);
6890 /* GDB gets a notification. Return to core as this event is
6892 if (ret
!= -1 && is_notif
)
6893 return minus_one_ptid
;
6895 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6896 return minus_one_ptid
;
6901 /* Assume that the target has acknowledged Ctrl-C unless we receive
6902 an 'F' or 'O' packet. */
6903 if (buf
[0] != 'F' && buf
[0] != 'O')
6904 rs
->ctrlc_pending_p
= 0;
6908 case 'E': /* Error of some sort. */
6909 /* We're out of sync with the target now. Did it continue or
6910 not? Not is more likely, so report a stop. */
6911 rs
->waiting_for_stop_reply
= 0;
6913 warning (_("Remote failure reply: %s"), buf
);
6914 status
->kind
= TARGET_WAITKIND_STOPPED
;
6915 status
->value
.sig
= GDB_SIGNAL_0
;
6917 case 'F': /* File-I/O request. */
6918 /* GDB may access the inferior memory while handling the File-I/O
6919 request, but we don't want GDB accessing memory while waiting
6920 for a stop reply. See the comments in putpkt_binary. Set
6921 waiting_for_stop_reply to 0 temporarily. */
6922 rs
->waiting_for_stop_reply
= 0;
6923 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6924 rs
->ctrlc_pending_p
= 0;
6925 /* GDB handled the File-I/O request, and the target is running
6926 again. Keep waiting for events. */
6927 rs
->waiting_for_stop_reply
= 1;
6929 case 'N': case 'T': case 'S': case 'X': case 'W':
6931 struct stop_reply
*stop_reply
;
6933 /* There is a stop reply to handle. */
6934 rs
->waiting_for_stop_reply
= 0;
6937 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6940 event_ptid
= process_stop_reply (stop_reply
, status
);
6943 case 'O': /* Console output. */
6944 remote_console_output (buf
+ 1);
6947 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6949 /* Zero length reply means that we tried 'S' or 'C' and the
6950 remote system doesn't support it. */
6951 target_terminal_ours_for_output ();
6953 ("Can't send signals to this remote system. %s not sent.\n",
6954 gdb_signal_to_name (rs
->last_sent_signal
));
6955 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6956 target_terminal_inferior ();
6958 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6959 putpkt ((char *) buf
);
6962 /* else fallthrough */
6964 warning (_("Invalid remote reply: %s"), buf
);
6968 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
6969 return minus_one_ptid
;
6970 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6972 /* Nothing interesting happened. If we're doing a non-blocking
6973 poll, we're done. Otherwise, go back to waiting. */
6974 if (options
& TARGET_WNOHANG
)
6975 return minus_one_ptid
;
6979 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6980 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6982 if (!ptid_equal (event_ptid
, null_ptid
))
6983 record_currthread (rs
, event_ptid
);
6985 event_ptid
= inferior_ptid
;
6988 /* A process exit. Invalidate our notion of current thread. */
6989 record_currthread (rs
, minus_one_ptid
);
6994 /* Wait until the remote machine stops, then return, storing status in
6995 STATUS just as `wait' would. */
6998 remote_wait (struct target_ops
*ops
,
6999 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7003 if (target_is_non_stop_p ())
7004 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7006 event_ptid
= remote_wait_as (ptid
, status
, options
);
7008 if (target_is_async_p ())
7010 /* If there are are events left in the queue tell the event loop
7012 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7013 mark_async_event_handler (remote_async_inferior_event_token
);
7019 /* Fetch a single register using a 'p' packet. */
7022 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7024 struct remote_state
*rs
= get_remote_state ();
7026 char regp
[MAX_REGISTER_SIZE
];
7029 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7032 if (reg
->pnum
== -1)
7037 p
+= hexnumstr (p
, reg
->pnum
);
7040 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7044 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7048 case PACKET_UNKNOWN
:
7051 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7052 gdbarch_register_name (get_regcache_arch (regcache
),
7057 /* If this register is unfetchable, tell the regcache. */
7060 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7064 /* Otherwise, parse and supply the value. */
7070 error (_("fetch_register_using_p: early buf termination"));
7072 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7075 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7079 /* Fetch the registers included in the target's 'g' packet. */
7082 send_g_packet (void)
7084 struct remote_state
*rs
= get_remote_state ();
7087 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7088 remote_send (&rs
->buf
, &rs
->buf_size
);
7090 /* We can get out of synch in various cases. If the first character
7091 in the buffer is not a hex character, assume that has happened
7092 and try to fetch another packet to read. */
7093 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7094 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7095 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7096 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7099 fprintf_unfiltered (gdb_stdlog
,
7100 "Bad register packet; fetching a new packet\n");
7101 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7104 buf_len
= strlen (rs
->buf
);
7106 /* Sanity check the received packet. */
7107 if (buf_len
% 2 != 0)
7108 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7114 process_g_packet (struct regcache
*regcache
)
7116 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7117 struct remote_state
*rs
= get_remote_state ();
7118 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7123 buf_len
= strlen (rs
->buf
);
7125 /* Further sanity checks, with knowledge of the architecture. */
7126 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7127 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7129 /* Save the size of the packet sent to us by the target. It is used
7130 as a heuristic when determining the max size of packets that the
7131 target can safely receive. */
7132 if (rsa
->actual_register_packet_size
== 0)
7133 rsa
->actual_register_packet_size
= buf_len
;
7135 /* If this is smaller than we guessed the 'g' packet would be,
7136 update our records. A 'g' reply that doesn't include a register's
7137 value implies either that the register is not available, or that
7138 the 'p' packet must be used. */
7139 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7141 rsa
->sizeof_g_packet
= buf_len
/ 2;
7143 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7145 if (rsa
->regs
[i
].pnum
== -1)
7148 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7149 rsa
->regs
[i
].in_g_packet
= 0;
7151 rsa
->regs
[i
].in_g_packet
= 1;
7155 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7157 /* Unimplemented registers read as all bits zero. */
7158 memset (regs
, 0, rsa
->sizeof_g_packet
);
7160 /* Reply describes registers byte by byte, each byte encoded as two
7161 hex characters. Suck them all up, then supply them to the
7162 register cacheing/storage mechanism. */
7165 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7167 if (p
[0] == 0 || p
[1] == 0)
7168 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7169 internal_error (__FILE__
, __LINE__
,
7170 _("unexpected end of 'g' packet reply"));
7172 if (p
[0] == 'x' && p
[1] == 'x')
7173 regs
[i
] = 0; /* 'x' */
7175 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7179 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7181 struct packet_reg
*r
= &rsa
->regs
[i
];
7185 if (r
->offset
* 2 >= strlen (rs
->buf
))
7186 /* This shouldn't happen - we adjusted in_g_packet above. */
7187 internal_error (__FILE__
, __LINE__
,
7188 _("unexpected end of 'g' packet reply"));
7189 else if (rs
->buf
[r
->offset
* 2] == 'x')
7191 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7192 /* The register isn't available, mark it as such (at
7193 the same time setting the value to zero). */
7194 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7197 regcache_raw_supply (regcache
, r
->regnum
,
7204 fetch_registers_using_g (struct regcache
*regcache
)
7207 process_g_packet (regcache
);
7210 /* Make the remote selected traceframe match GDB's selected
7214 set_remote_traceframe (void)
7217 struct remote_state
*rs
= get_remote_state ();
7219 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7222 /* Avoid recursion, remote_trace_find calls us again. */
7223 rs
->remote_traceframe_number
= get_traceframe_number ();
7225 newnum
= target_trace_find (tfind_number
,
7226 get_traceframe_number (), 0, 0, NULL
);
7228 /* Should not happen. If it does, all bets are off. */
7229 if (newnum
!= get_traceframe_number ())
7230 warning (_("could not set remote traceframe"));
7234 remote_fetch_registers (struct target_ops
*ops
,
7235 struct regcache
*regcache
, int regnum
)
7237 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7240 set_remote_traceframe ();
7241 set_general_thread (inferior_ptid
);
7245 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7247 gdb_assert (reg
!= NULL
);
7249 /* If this register might be in the 'g' packet, try that first -
7250 we are likely to read more than one register. If this is the
7251 first 'g' packet, we might be overly optimistic about its
7252 contents, so fall back to 'p'. */
7253 if (reg
->in_g_packet
)
7255 fetch_registers_using_g (regcache
);
7256 if (reg
->in_g_packet
)
7260 if (fetch_register_using_p (regcache
, reg
))
7263 /* This register is not available. */
7264 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7269 fetch_registers_using_g (regcache
);
7271 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7272 if (!rsa
->regs
[i
].in_g_packet
)
7273 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7275 /* This register is not available. */
7276 regcache_raw_supply (regcache
, i
, NULL
);
7280 /* Prepare to store registers. Since we may send them all (using a
7281 'G' request), we have to read out the ones we don't want to change
7285 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7287 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7289 gdb_byte buf
[MAX_REGISTER_SIZE
];
7291 /* Make sure the entire registers array is valid. */
7292 switch (packet_support (PACKET_P
))
7294 case PACKET_DISABLE
:
7295 case PACKET_SUPPORT_UNKNOWN
:
7296 /* Make sure all the necessary registers are cached. */
7297 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7298 if (rsa
->regs
[i
].in_g_packet
)
7299 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7306 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7307 packet was not recognized. */
7310 store_register_using_P (const struct regcache
*regcache
,
7311 struct packet_reg
*reg
)
7313 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7314 struct remote_state
*rs
= get_remote_state ();
7315 /* Try storing a single register. */
7316 char *buf
= rs
->buf
;
7317 gdb_byte regp
[MAX_REGISTER_SIZE
];
7320 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7323 if (reg
->pnum
== -1)
7326 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7327 p
= buf
+ strlen (buf
);
7328 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7329 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7331 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7333 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7338 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7339 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7340 case PACKET_UNKNOWN
:
7343 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7347 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7348 contents of the register cache buffer. FIXME: ignores errors. */
7351 store_registers_using_G (const struct regcache
*regcache
)
7353 struct remote_state
*rs
= get_remote_state ();
7354 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7358 /* Extract all the registers in the regcache copying them into a
7363 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7364 memset (regs
, 0, rsa
->sizeof_g_packet
);
7365 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7367 struct packet_reg
*r
= &rsa
->regs
[i
];
7370 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7374 /* Command describes registers byte by byte,
7375 each byte encoded as two hex characters. */
7378 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7380 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7382 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7383 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7384 error (_("Could not write registers; remote failure reply '%s'"),
7388 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7389 of the register cache buffer. FIXME: ignores errors. */
7392 remote_store_registers (struct target_ops
*ops
,
7393 struct regcache
*regcache
, int regnum
)
7395 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7398 set_remote_traceframe ();
7399 set_general_thread (inferior_ptid
);
7403 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7405 gdb_assert (reg
!= NULL
);
7407 /* Always prefer to store registers using the 'P' packet if
7408 possible; we often change only a small number of registers.
7409 Sometimes we change a larger number; we'd need help from a
7410 higher layer to know to use 'G'. */
7411 if (store_register_using_P (regcache
, reg
))
7414 /* For now, don't complain if we have no way to write the
7415 register. GDB loses track of unavailable registers too
7416 easily. Some day, this may be an error. We don't have
7417 any way to read the register, either... */
7418 if (!reg
->in_g_packet
)
7421 store_registers_using_G (regcache
);
7425 store_registers_using_G (regcache
);
7427 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7428 if (!rsa
->regs
[i
].in_g_packet
)
7429 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7430 /* See above for why we do not issue an error here. */
7435 /* Return the number of hex digits in num. */
7438 hexnumlen (ULONGEST num
)
7442 for (i
= 0; num
!= 0; i
++)
7448 /* Set BUF to the minimum number of hex digits representing NUM. */
7451 hexnumstr (char *buf
, ULONGEST num
)
7453 int len
= hexnumlen (num
);
7455 return hexnumnstr (buf
, num
, len
);
7459 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7462 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7468 for (i
= width
- 1; i
>= 0; i
--)
7470 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7477 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7480 remote_address_masked (CORE_ADDR addr
)
7482 unsigned int address_size
= remote_address_size
;
7484 /* If "remoteaddresssize" was not set, default to target address size. */
7486 address_size
= gdbarch_addr_bit (target_gdbarch ());
7488 if (address_size
> 0
7489 && address_size
< (sizeof (ULONGEST
) * 8))
7491 /* Only create a mask when that mask can safely be constructed
7492 in a ULONGEST variable. */
7495 mask
= (mask
<< address_size
) - 1;
7501 /* Determine whether the remote target supports binary downloading.
7502 This is accomplished by sending a no-op memory write of zero length
7503 to the target at the specified address. It does not suffice to send
7504 the whole packet, since many stubs strip the eighth bit and
7505 subsequently compute a wrong checksum, which causes real havoc with
7508 NOTE: This can still lose if the serial line is not eight-bit
7509 clean. In cases like this, the user should clear "remote
7513 check_binary_download (CORE_ADDR addr
)
7515 struct remote_state
*rs
= get_remote_state ();
7517 switch (packet_support (PACKET_X
))
7519 case PACKET_DISABLE
:
7523 case PACKET_SUPPORT_UNKNOWN
:
7529 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7531 p
+= hexnumstr (p
, (ULONGEST
) 0);
7535 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7536 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7538 if (rs
->buf
[0] == '\0')
7541 fprintf_unfiltered (gdb_stdlog
,
7542 "binary downloading NOT "
7543 "supported by target\n");
7544 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7549 fprintf_unfiltered (gdb_stdlog
,
7550 "binary downloading supported by target\n");
7551 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7558 /* Helper function to resize the payload in order to try to get a good
7559 alignment. We try to write an amount of data such that the next write will
7560 start on an address aligned on REMOTE_ALIGN_WRITES. */
7563 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7565 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7568 /* Write memory data directly to the remote machine.
7569 This does not inform the data cache; the data cache uses this.
7570 HEADER is the starting part of the packet.
7571 MEMADDR is the address in the remote memory space.
7572 MYADDR is the address of the buffer in our space.
7573 LEN_UNITS is the number of addressable units to write.
7574 UNIT_SIZE is the length in bytes of an addressable unit.
7575 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7576 should send data as binary ('X'), or hex-encoded ('M').
7578 The function creates packet of the form
7579 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7581 where encoding of <DATA> is terminated by PACKET_FORMAT.
7583 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7586 Return the transferred status, error or OK (an
7587 'enum target_xfer_status' value). Save the number of addressable units
7588 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7590 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7591 exchange between gdb and the stub could look like (?? in place of the
7597 -> $M1000,3:eeeeffffeeee#??
7601 <- eeeeffffeeeedddd */
7603 static enum target_xfer_status
7604 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7605 const gdb_byte
*myaddr
, ULONGEST len_units
,
7606 int unit_size
, ULONGEST
*xfered_len_units
,
7607 char packet_format
, int use_length
)
7609 struct remote_state
*rs
= get_remote_state ();
7615 int payload_capacity_bytes
;
7616 int payload_length_bytes
;
7618 if (packet_format
!= 'X' && packet_format
!= 'M')
7619 internal_error (__FILE__
, __LINE__
,
7620 _("remote_write_bytes_aux: bad packet format"));
7623 return TARGET_XFER_EOF
;
7625 payload_capacity_bytes
= get_memory_write_packet_size ();
7627 /* The packet buffer will be large enough for the payload;
7628 get_memory_packet_size ensures this. */
7631 /* Compute the size of the actual payload by subtracting out the
7632 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7634 payload_capacity_bytes
-= strlen ("$,:#NN");
7636 /* The comma won't be used. */
7637 payload_capacity_bytes
+= 1;
7638 payload_capacity_bytes
-= strlen (header
);
7639 payload_capacity_bytes
-= hexnumlen (memaddr
);
7641 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7643 strcat (rs
->buf
, header
);
7644 p
= rs
->buf
+ strlen (header
);
7646 /* Compute a best guess of the number of bytes actually transfered. */
7647 if (packet_format
== 'X')
7649 /* Best guess at number of bytes that will fit. */
7650 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7652 payload_capacity_bytes
-= hexnumlen (todo_units
);
7653 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7657 /* Number of bytes that will fit. */
7658 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7660 payload_capacity_bytes
-= hexnumlen (todo_units
);
7661 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7664 if (todo_units
<= 0)
7665 internal_error (__FILE__
, __LINE__
,
7666 _("minimum packet size too small to write data"));
7668 /* If we already need another packet, then try to align the end
7669 of this packet to a useful boundary. */
7670 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7671 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7673 /* Append "<memaddr>". */
7674 memaddr
= remote_address_masked (memaddr
);
7675 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7682 /* Append the length and retain its location and size. It may need to be
7683 adjusted once the packet body has been created. */
7685 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7693 /* Append the packet body. */
7694 if (packet_format
== 'X')
7696 /* Binary mode. Send target system values byte by byte, in
7697 increasing byte addresses. Only escape certain critical
7699 payload_length_bytes
=
7700 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7701 &units_written
, payload_capacity_bytes
);
7703 /* If not all TODO units fit, then we'll need another packet. Make
7704 a second try to keep the end of the packet aligned. Don't do
7705 this if the packet is tiny. */
7706 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7710 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7712 if (new_todo_units
!= units_written
)
7713 payload_length_bytes
=
7714 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7715 (gdb_byte
*) p
, &units_written
,
7716 payload_capacity_bytes
);
7719 p
+= payload_length_bytes
;
7720 if (use_length
&& units_written
< todo_units
)
7722 /* Escape chars have filled up the buffer prematurely,
7723 and we have actually sent fewer units than planned.
7724 Fix-up the length field of the packet. Use the same
7725 number of characters as before. */
7726 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7728 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7733 /* Normal mode: Send target system values byte by byte, in
7734 increasing byte addresses. Each byte is encoded as a two hex
7736 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7737 units_written
= todo_units
;
7740 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7741 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7743 if (rs
->buf
[0] == 'E')
7744 return TARGET_XFER_E_IO
;
7746 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7747 send fewer units than we'd planned. */
7748 *xfered_len_units
= (ULONGEST
) units_written
;
7749 return TARGET_XFER_OK
;
7752 /* Write memory data directly to the remote machine.
7753 This does not inform the data cache; the data cache uses this.
7754 MEMADDR is the address in the remote memory space.
7755 MYADDR is the address of the buffer in our space.
7756 LEN is the number of bytes.
7758 Return the transferred status, error or OK (an
7759 'enum target_xfer_status' value). Save the number of bytes
7760 transferred in *XFERED_LEN. Only transfer a single packet. */
7762 static enum target_xfer_status
7763 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7764 int unit_size
, ULONGEST
*xfered_len
)
7766 char *packet_format
= 0;
7768 /* Check whether the target supports binary download. */
7769 check_binary_download (memaddr
);
7771 switch (packet_support (PACKET_X
))
7774 packet_format
= "X";
7776 case PACKET_DISABLE
:
7777 packet_format
= "M";
7779 case PACKET_SUPPORT_UNKNOWN
:
7780 internal_error (__FILE__
, __LINE__
,
7781 _("remote_write_bytes: bad internal state"));
7783 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7786 return remote_write_bytes_aux (packet_format
,
7787 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7788 packet_format
[0], 1);
7791 /* Read memory data directly from the remote machine.
7792 This does not use the data cache; the data cache uses this.
7793 MEMADDR is the address in the remote memory space.
7794 MYADDR is the address of the buffer in our space.
7795 LEN_UNITS is the number of addressable memory units to read..
7796 UNIT_SIZE is the length in bytes of an addressable unit.
7798 Return the transferred status, error or OK (an
7799 'enum target_xfer_status' value). Save the number of bytes
7800 transferred in *XFERED_LEN_UNITS.
7802 See the comment of remote_write_bytes_aux for an example of
7803 memory read/write exchange between gdb and the stub. */
7805 static enum target_xfer_status
7806 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7807 int unit_size
, ULONGEST
*xfered_len_units
)
7809 struct remote_state
*rs
= get_remote_state ();
7810 int buf_size_bytes
; /* Max size of packet output buffer. */
7815 buf_size_bytes
= get_memory_read_packet_size ();
7816 /* The packet buffer will be large enough for the payload;
7817 get_memory_packet_size ensures this. */
7819 /* Number of units that will fit. */
7820 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7822 /* Construct "m"<memaddr>","<len>". */
7823 memaddr
= remote_address_masked (memaddr
);
7826 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7828 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7831 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7832 if (rs
->buf
[0] == 'E'
7833 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7834 && rs
->buf
[3] == '\0')
7835 return TARGET_XFER_E_IO
;
7836 /* Reply describes memory byte by byte, each byte encoded as two hex
7839 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7840 /* Return what we have. Let higher layers handle partial reads. */
7841 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7842 return TARGET_XFER_OK
;
7845 /* Using the set of read-only target sections of remote, read live
7848 For interface/parameters/return description see target.h,
7851 static enum target_xfer_status
7852 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7853 ULONGEST memaddr
, ULONGEST len
,
7854 int unit_size
, ULONGEST
*xfered_len
)
7856 struct target_section
*secp
;
7857 struct target_section_table
*table
;
7859 secp
= target_section_by_addr (ops
, memaddr
);
7861 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7862 secp
->the_bfd_section
)
7865 struct target_section
*p
;
7866 ULONGEST memend
= memaddr
+ len
;
7868 table
= target_get_section_table (ops
);
7870 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7872 if (memaddr
>= p
->addr
)
7874 if (memend
<= p
->endaddr
)
7876 /* Entire transfer is within this section. */
7877 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7880 else if (memaddr
>= p
->endaddr
)
7882 /* This section ends before the transfer starts. */
7887 /* This section overlaps the transfer. Just do half. */
7888 len
= p
->endaddr
- memaddr
;
7889 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7896 return TARGET_XFER_EOF
;
7899 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7900 first if the requested memory is unavailable in traceframe.
7901 Otherwise, fall back to remote_read_bytes_1. */
7903 static enum target_xfer_status
7904 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7905 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7906 ULONGEST
*xfered_len
)
7909 return TARGET_XFER_EOF
;
7911 if (get_traceframe_number () != -1)
7913 VEC(mem_range_s
) *available
;
7915 /* If we fail to get the set of available memory, then the
7916 target does not support querying traceframe info, and so we
7917 attempt reading from the traceframe anyway (assuming the
7918 target implements the old QTro packet then). */
7919 if (traceframe_available_memory (&available
, memaddr
, len
))
7921 struct cleanup
*old_chain
;
7923 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7925 if (VEC_empty (mem_range_s
, available
)
7926 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7928 enum target_xfer_status res
;
7930 /* Don't read into the traceframe's available
7932 if (!VEC_empty (mem_range_s
, available
))
7934 LONGEST oldlen
= len
;
7936 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7937 gdb_assert (len
<= oldlen
);
7940 do_cleanups (old_chain
);
7942 /* This goes through the topmost target again. */
7943 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7944 len
, unit_size
, xfered_len
);
7945 if (res
== TARGET_XFER_OK
)
7946 return TARGET_XFER_OK
;
7949 /* No use trying further, we know some memory starting
7950 at MEMADDR isn't available. */
7952 return TARGET_XFER_UNAVAILABLE
;
7956 /* Don't try to read more than how much is available, in
7957 case the target implements the deprecated QTro packet to
7958 cater for older GDBs (the target's knowledge of read-only
7959 sections may be outdated by now). */
7960 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7962 do_cleanups (old_chain
);
7966 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7971 /* Sends a packet with content determined by the printf format string
7972 FORMAT and the remaining arguments, then gets the reply. Returns
7973 whether the packet was a success, a failure, or unknown. */
7975 static enum packet_result
remote_send_printf (const char *format
, ...)
7976 ATTRIBUTE_PRINTF (1, 2);
7978 static enum packet_result
7979 remote_send_printf (const char *format
, ...)
7981 struct remote_state
*rs
= get_remote_state ();
7982 int max_size
= get_remote_packet_size ();
7985 va_start (ap
, format
);
7988 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7989 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7991 if (putpkt (rs
->buf
) < 0)
7992 error (_("Communication problem with target."));
7995 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7997 return packet_check_result (rs
->buf
);
8001 restore_remote_timeout (void *p
)
8003 int value
= *(int *)p
;
8005 remote_timeout
= value
;
8008 /* Flash writing can take quite some time. We'll set
8009 effectively infinite timeout for flash operations.
8010 In future, we'll need to decide on a better approach. */
8011 static const int remote_flash_timeout
= 1000;
8014 remote_flash_erase (struct target_ops
*ops
,
8015 ULONGEST address
, LONGEST length
)
8017 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8018 int saved_remote_timeout
= remote_timeout
;
8019 enum packet_result ret
;
8020 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8021 &saved_remote_timeout
);
8023 remote_timeout
= remote_flash_timeout
;
8025 ret
= remote_send_printf ("vFlashErase:%s,%s",
8026 phex (address
, addr_size
),
8030 case PACKET_UNKNOWN
:
8031 error (_("Remote target does not support flash erase"));
8033 error (_("Error erasing flash with vFlashErase packet"));
8038 do_cleanups (back_to
);
8041 static enum target_xfer_status
8042 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8043 ULONGEST length
, ULONGEST
*xfered_len
,
8044 const gdb_byte
*data
)
8046 int saved_remote_timeout
= remote_timeout
;
8047 enum target_xfer_status ret
;
8048 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8049 &saved_remote_timeout
);
8051 remote_timeout
= remote_flash_timeout
;
8052 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8054 do_cleanups (back_to
);
8060 remote_flash_done (struct target_ops
*ops
)
8062 int saved_remote_timeout
= remote_timeout
;
8064 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8065 &saved_remote_timeout
);
8067 remote_timeout
= remote_flash_timeout
;
8068 ret
= remote_send_printf ("vFlashDone");
8069 do_cleanups (back_to
);
8073 case PACKET_UNKNOWN
:
8074 error (_("Remote target does not support vFlashDone"));
8076 error (_("Error finishing flash operation"));
8083 remote_files_info (struct target_ops
*ignore
)
8085 puts_filtered ("Debugging a target over a serial line.\n");
8088 /* Stuff for dealing with the packets which are part of this protocol.
8089 See comment at top of file for details. */
8091 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8092 error to higher layers. Called when a serial error is detected.
8093 The exception message is STRING, followed by a colon and a blank,
8094 the system error message for errno at function entry and final dot
8095 for output compatibility with throw_perror_with_name. */
8098 unpush_and_perror (const char *string
)
8100 int saved_errno
= errno
;
8102 remote_unpush_target ();
8103 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8104 safe_strerror (saved_errno
));
8107 /* Read a single character from the remote end. The current quit
8108 handler is overridden to avoid quitting in the middle of packet
8109 sequence, as that would break communication with the remote server.
8110 See remote_serial_quit_handler for more detail. */
8113 readchar (int timeout
)
8116 struct remote_state
*rs
= get_remote_state ();
8117 struct cleanup
*old_chain
;
8119 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8121 rs
->got_ctrlc_during_io
= 0;
8123 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8125 if (rs
->got_ctrlc_during_io
)
8128 do_cleanups (old_chain
);
8133 switch ((enum serial_rc
) ch
)
8136 remote_unpush_target ();
8137 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8140 unpush_and_perror (_("Remote communication error. "
8141 "Target disconnected."));
8143 case SERIAL_TIMEOUT
:
8149 /* Wrapper for serial_write that closes the target and throws if
8150 writing fails. The current quit handler is overridden to avoid
8151 quitting in the middle of packet sequence, as that would break
8152 communication with the remote server. See
8153 remote_serial_quit_handler for more detail. */
8156 remote_serial_write (const char *str
, int len
)
8158 struct remote_state
*rs
= get_remote_state ();
8159 struct cleanup
*old_chain
;
8161 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8163 rs
->got_ctrlc_during_io
= 0;
8165 if (serial_write (rs
->remote_desc
, str
, len
))
8167 unpush_and_perror (_("Remote communication error. "
8168 "Target disconnected."));
8171 if (rs
->got_ctrlc_during_io
)
8174 do_cleanups (old_chain
);
8177 /* Send the command in *BUF to the remote machine, and read the reply
8178 into *BUF. Report an error if we get an error reply. Resize
8179 *BUF using xrealloc if necessary to hold the result, and update
8183 remote_send (char **buf
,
8187 getpkt (buf
, sizeof_buf
, 0);
8189 if ((*buf
)[0] == 'E')
8190 error (_("Remote failure reply: %s"), *buf
);
8193 /* Return a pointer to an xmalloc'ed string representing an escaped
8194 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8195 etc. The caller is responsible for releasing the returned
8199 escape_buffer (const char *buf
, int n
)
8201 struct cleanup
*old_chain
;
8202 struct ui_file
*stb
;
8205 stb
= mem_fileopen ();
8206 old_chain
= make_cleanup_ui_file_delete (stb
);
8208 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8209 str
= ui_file_xstrdup (stb
, NULL
);
8210 do_cleanups (old_chain
);
8214 /* Display a null-terminated packet on stdout, for debugging, using C
8218 print_packet (const char *buf
)
8220 puts_filtered ("\"");
8221 fputstr_filtered (buf
, '"', gdb_stdout
);
8222 puts_filtered ("\"");
8226 putpkt (const char *buf
)
8228 return putpkt_binary (buf
, strlen (buf
));
8231 /* Send a packet to the remote machine, with error checking. The data
8232 of the packet is in BUF. The string in BUF can be at most
8233 get_remote_packet_size () - 5 to account for the $, # and checksum,
8234 and for a possible /0 if we are debugging (remote_debug) and want
8235 to print the sent packet as a string. */
8238 putpkt_binary (const char *buf
, int cnt
)
8240 struct remote_state
*rs
= get_remote_state ();
8242 unsigned char csum
= 0;
8243 char *buf2
= (char *) xmalloc (cnt
+ 6);
8244 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8250 /* Catch cases like trying to read memory or listing threads while
8251 we're waiting for a stop reply. The remote server wouldn't be
8252 ready to handle this request, so we'd hang and timeout. We don't
8253 have to worry about this in synchronous mode, because in that
8254 case it's not possible to issue a command while the target is
8255 running. This is not a problem in non-stop mode, because in that
8256 case, the stub is always ready to process serial input. */
8257 if (!target_is_non_stop_p ()
8258 && target_is_async_p ()
8259 && rs
->waiting_for_stop_reply
)
8261 error (_("Cannot execute this command while the target is running.\n"
8262 "Use the \"interrupt\" command to stop the target\n"
8263 "and then try again."));
8266 /* We're sending out a new packet. Make sure we don't look at a
8267 stale cached response. */
8268 rs
->cached_wait_status
= 0;
8270 /* Copy the packet into buffer BUF2, encapsulating it
8271 and giving it a checksum. */
8276 for (i
= 0; i
< cnt
; i
++)
8282 *p
++ = tohex ((csum
>> 4) & 0xf);
8283 *p
++ = tohex (csum
& 0xf);
8285 /* Send it over and over until we get a positive ack. */
8289 int started_error_output
= 0;
8293 struct cleanup
*old_chain
;
8297 str
= escape_buffer (buf2
, p
- buf2
);
8298 old_chain
= make_cleanup (xfree
, str
);
8299 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8300 gdb_flush (gdb_stdlog
);
8301 do_cleanups (old_chain
);
8303 remote_serial_write (buf2
, p
- buf2
);
8305 /* If this is a no acks version of the remote protocol, send the
8306 packet and move on. */
8310 /* Read until either a timeout occurs (-2) or '+' is read.
8311 Handle any notification that arrives in the mean time. */
8314 ch
= readchar (remote_timeout
);
8322 case SERIAL_TIMEOUT
:
8325 if (started_error_output
)
8327 putchar_unfiltered ('\n');
8328 started_error_output
= 0;
8337 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8338 do_cleanups (old_chain
);
8342 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8344 case SERIAL_TIMEOUT
:
8348 do_cleanups (old_chain
);
8351 break; /* Retransmit buffer. */
8355 fprintf_unfiltered (gdb_stdlog
,
8356 "Packet instead of Ack, ignoring it\n");
8357 /* It's probably an old response sent because an ACK
8358 was lost. Gobble up the packet and ack it so it
8359 doesn't get retransmitted when we resend this
8362 remote_serial_write ("+", 1);
8363 continue; /* Now, go look for +. */
8370 /* If we got a notification, handle it, and go back to looking
8372 /* We've found the start of a notification. Now
8373 collect the data. */
8374 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8379 struct cleanup
*old_chain
;
8382 str
= escape_buffer (rs
->buf
, val
);
8383 old_chain
= make_cleanup (xfree
, str
);
8384 fprintf_unfiltered (gdb_stdlog
,
8385 " Notification received: %s\n",
8387 do_cleanups (old_chain
);
8389 handle_notification (rs
->notif_state
, rs
->buf
);
8390 /* We're in sync now, rewait for the ack. */
8397 if (!started_error_output
)
8399 started_error_output
= 1;
8400 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8402 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8403 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8412 if (!started_error_output
)
8414 started_error_output
= 1;
8415 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8417 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8421 break; /* Here to retransmit. */
8425 /* This is wrong. If doing a long backtrace, the user should be
8426 able to get out next time we call QUIT, without anything as
8427 violent as interrupt_query. If we want to provide a way out of
8428 here without getting to the next QUIT, it should be based on
8429 hitting ^C twice as in remote_wait. */
8438 do_cleanups (old_chain
);
8442 /* Come here after finding the start of a frame when we expected an
8443 ack. Do our best to discard the rest of this packet. */
8452 c
= readchar (remote_timeout
);
8455 case SERIAL_TIMEOUT
:
8456 /* Nothing we can do. */
8459 /* Discard the two bytes of checksum and stop. */
8460 c
= readchar (remote_timeout
);
8462 c
= readchar (remote_timeout
);
8465 case '*': /* Run length encoding. */
8466 /* Discard the repeat count. */
8467 c
= readchar (remote_timeout
);
8472 /* A regular character. */
8478 /* Come here after finding the start of the frame. Collect the rest
8479 into *BUF, verifying the checksum, length, and handling run-length
8480 compression. NUL terminate the buffer. If there is not enough room,
8481 expand *BUF using xrealloc.
8483 Returns -1 on error, number of characters in buffer (ignoring the
8484 trailing NULL) on success. (could be extended to return one of the
8485 SERIAL status indications). */
8488 read_frame (char **buf_p
,
8495 struct remote_state
*rs
= get_remote_state ();
8502 c
= readchar (remote_timeout
);
8505 case SERIAL_TIMEOUT
:
8507 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8511 fputs_filtered ("Saw new packet start in middle of old one\n",
8513 return -1; /* Start a new packet, count retries. */
8516 unsigned char pktcsum
;
8522 check_0
= readchar (remote_timeout
);
8524 check_1
= readchar (remote_timeout
);
8526 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8529 fputs_filtered ("Timeout in checksum, retrying\n",
8533 else if (check_0
< 0 || check_1
< 0)
8536 fputs_filtered ("Communication error in checksum\n",
8541 /* Don't recompute the checksum; with no ack packets we
8542 don't have any way to indicate a packet retransmission
8547 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8548 if (csum
== pktcsum
)
8553 struct cleanup
*old_chain
;
8556 str
= escape_buffer (buf
, bc
);
8557 old_chain
= make_cleanup (xfree
, str
);
8558 fprintf_unfiltered (gdb_stdlog
,
8559 "Bad checksum, sentsum=0x%x, "
8560 "csum=0x%x, buf=%s\n",
8561 pktcsum
, csum
, str
);
8562 do_cleanups (old_chain
);
8564 /* Number of characters in buffer ignoring trailing
8568 case '*': /* Run length encoding. */
8573 c
= readchar (remote_timeout
);
8575 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8577 /* The character before ``*'' is repeated. */
8579 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8581 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8583 /* Make some more room in the buffer. */
8584 *sizeof_buf
+= repeat
;
8585 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8589 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8595 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8599 if (bc
>= *sizeof_buf
- 1)
8601 /* Make some more room in the buffer. */
8603 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8614 /* Read a packet from the remote machine, with error checking, and
8615 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8616 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8617 rather than timing out; this is used (in synchronous mode) to wait
8618 for a target that is is executing user code to stop. */
8619 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8620 don't have to change all the calls to getpkt to deal with the
8621 return value, because at the moment I don't know what the right
8622 thing to do it for those. */
8628 getpkt_sane (buf
, sizeof_buf
, forever
);
8632 /* Read a packet from the remote machine, with error checking, and
8633 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8634 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8635 rather than timing out; this is used (in synchronous mode) to wait
8636 for a target that is is executing user code to stop. If FOREVER ==
8637 0, this function is allowed to time out gracefully and return an
8638 indication of this to the caller. Otherwise return the number of
8639 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8640 enough reason to return to the caller. *IS_NOTIF is an output
8641 boolean that indicates whether *BUF holds a notification or not
8642 (a regular packet). */
8645 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8646 int expecting_notif
, int *is_notif
)
8648 struct remote_state
*rs
= get_remote_state ();
8654 /* We're reading a new response. Make sure we don't look at a
8655 previously cached response. */
8656 rs
->cached_wait_status
= 0;
8658 strcpy (*buf
, "timeout");
8661 timeout
= watchdog
> 0 ? watchdog
: -1;
8662 else if (expecting_notif
)
8663 timeout
= 0; /* There should already be a char in the buffer. If
8666 timeout
= remote_timeout
;
8670 /* Process any number of notifications, and then return when
8674 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8676 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8678 /* This can loop forever if the remote side sends us
8679 characters continuously, but if it pauses, we'll get
8680 SERIAL_TIMEOUT from readchar because of timeout. Then
8681 we'll count that as a retry.
8683 Note that even when forever is set, we will only wait
8684 forever prior to the start of a packet. After that, we
8685 expect characters to arrive at a brisk pace. They should
8686 show up within remote_timeout intervals. */
8688 c
= readchar (timeout
);
8689 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8691 if (c
== SERIAL_TIMEOUT
)
8693 if (expecting_notif
)
8694 return -1; /* Don't complain, it's normal to not get
8695 anything in this case. */
8697 if (forever
) /* Watchdog went off? Kill the target. */
8699 remote_unpush_target ();
8700 throw_error (TARGET_CLOSE_ERROR
,
8701 _("Watchdog timeout has expired. "
8702 "Target detached."));
8705 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8709 /* We've found the start of a packet or notification.
8710 Now collect the data. */
8711 val
= read_frame (buf
, sizeof_buf
);
8716 remote_serial_write ("-", 1);
8719 if (tries
> MAX_TRIES
)
8721 /* We have tried hard enough, and just can't receive the
8722 packet/notification. Give up. */
8723 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8725 /* Skip the ack char if we're in no-ack mode. */
8726 if (!rs
->noack_mode
)
8727 remote_serial_write ("+", 1);
8731 /* If we got an ordinary packet, return that to our caller. */
8736 struct cleanup
*old_chain
;
8739 str
= escape_buffer (*buf
, val
);
8740 old_chain
= make_cleanup (xfree
, str
);
8741 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8742 do_cleanups (old_chain
);
8745 /* Skip the ack char if we're in no-ack mode. */
8746 if (!rs
->noack_mode
)
8747 remote_serial_write ("+", 1);
8748 if (is_notif
!= NULL
)
8753 /* If we got a notification, handle it, and go back to looking
8757 gdb_assert (c
== '%');
8761 struct cleanup
*old_chain
;
8764 str
= escape_buffer (*buf
, val
);
8765 old_chain
= make_cleanup (xfree
, str
);
8766 fprintf_unfiltered (gdb_stdlog
,
8767 " Notification received: %s\n",
8769 do_cleanups (old_chain
);
8771 if (is_notif
!= NULL
)
8774 handle_notification (rs
->notif_state
, *buf
);
8776 /* Notifications require no acknowledgement. */
8778 if (expecting_notif
)
8785 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8787 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8791 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8794 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8798 /* Check whether EVENT is a fork event for the process specified
8799 by the pid passed in DATA, and if it is, kill the fork child. */
8802 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8803 QUEUE_ITER (stop_reply_p
) *iter
,
8807 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8808 int parent_pid
= *(int *) param
->input
;
8810 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8812 struct remote_state
*rs
= get_remote_state ();
8813 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8816 res
= remote_vkill (child_pid
, rs
);
8818 error (_("Can't kill fork child process %d"), child_pid
);
8824 /* Kill any new fork children of process PID that haven't been
8825 processed by follow_fork. */
8828 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8830 struct thread_info
*thread
;
8831 struct notif_client
*notif
= ¬if_client_stop
;
8832 struct queue_iter_param param
;
8834 /* Kill the fork child threads of any threads in process PID
8835 that are stopped at a fork event. */
8836 ALL_NON_EXITED_THREADS (thread
)
8838 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8840 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8842 struct remote_state
*rs
= get_remote_state ();
8843 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8846 res
= remote_vkill (child_pid
, rs
);
8848 error (_("Can't kill fork child process %d"), child_pid
);
8852 /* Check for any pending fork events (not reported or processed yet)
8853 in process PID and kill those fork child threads as well. */
8854 remote_notif_get_pending_events (notif
);
8856 param
.output
= NULL
;
8857 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8858 kill_child_of_pending_fork
, ¶m
);
8862 /* Target hook to kill the current inferior. */
8865 remote_kill (struct target_ops
*ops
)
8868 int pid
= ptid_get_pid (inferior_ptid
);
8869 struct remote_state
*rs
= get_remote_state ();
8871 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
8873 /* If we're stopped while forking and we haven't followed yet,
8874 kill the child task. We need to do this before killing the
8875 parent task because if this is a vfork then the parent will
8877 kill_new_fork_children (pid
, rs
);
8879 res
= remote_vkill (pid
, rs
);
8882 target_mourn_inferior ();
8887 /* If we are in 'target remote' mode and we are killing the only
8888 inferior, then we will tell gdbserver to exit and unpush the
8890 if (res
== -1 && !remote_multi_process_p (rs
)
8891 && number_of_live_inferiors () == 1)
8895 /* We've killed the remote end, we get to mourn it. If we are
8896 not in extended mode, mourning the inferior also unpushes
8897 remote_ops from the target stack, which closes the remote
8899 target_mourn_inferior ();
8904 error (_("Can't kill process"));
8907 /* Send a kill request to the target using the 'vKill' packet. */
8910 remote_vkill (int pid
, struct remote_state
*rs
)
8912 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8915 /* Tell the remote target to detach. */
8916 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8918 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8920 switch (packet_ok (rs
->buf
,
8921 &remote_protocol_packets
[PACKET_vKill
]))
8927 case PACKET_UNKNOWN
:
8930 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8934 /* Send a kill request to the target using the 'k' packet. */
8937 remote_kill_k (void)
8939 /* Catch errors so the user can quit from gdb even when we
8940 aren't on speaking terms with the remote system. */
8945 CATCH (ex
, RETURN_MASK_ERROR
)
8947 if (ex
.error
== TARGET_CLOSE_ERROR
)
8949 /* If we got an (EOF) error that caused the target
8950 to go away, then we're done, that's what we wanted.
8951 "k" is susceptible to cause a premature EOF, given
8952 that the remote server isn't actually required to
8953 reply to "k", and it can happen that it doesn't
8954 even get to reply ACK to the "k". */
8958 /* Otherwise, something went wrong. We didn't actually kill
8959 the target. Just propagate the exception, and let the
8960 user or higher layers decide what to do. */
8961 throw_exception (ex
);
8967 remote_mourn (struct target_ops
*target
)
8969 struct remote_state
*rs
= get_remote_state ();
8971 /* In 'target remote' mode with one inferior, we close the connection. */
8972 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
8974 unpush_target (target
);
8976 /* remote_close takes care of doing most of the clean up. */
8977 generic_mourn_inferior ();
8981 /* In case we got here due to an error, but we're going to stay
8983 rs
->waiting_for_stop_reply
= 0;
8985 /* If the current general thread belonged to the process we just
8986 detached from or has exited, the remote side current general
8987 thread becomes undefined. Considering a case like this:
8989 - We just got here due to a detach.
8990 - The process that we're detaching from happens to immediately
8991 report a global breakpoint being hit in non-stop mode, in the
8992 same thread we had selected before.
8993 - GDB attaches to this process again.
8994 - This event happens to be the next event we handle.
8996 GDB would consider that the current general thread didn't need to
8997 be set on the stub side (with Hg), since for all it knew,
8998 GENERAL_THREAD hadn't changed.
9000 Notice that although in all-stop mode, the remote server always
9001 sets the current thread to the thread reporting the stop event,
9002 that doesn't happen in non-stop mode; in non-stop, the stub *must
9003 not* change the current thread when reporting a breakpoint hit,
9004 due to the decoupling of event reporting and event handling.
9006 To keep things simple, we always invalidate our notion of the
9008 record_currthread (rs
, minus_one_ptid
);
9010 /* Call common code to mark the inferior as not running. */
9011 generic_mourn_inferior ();
9013 if (!have_inferiors ())
9015 if (!remote_multi_process_p (rs
))
9017 /* Check whether the target is running now - some remote stubs
9018 automatically restart after kill. */
9020 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9022 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9024 /* Assume that the target has been restarted. Set
9025 inferior_ptid so that bits of core GDB realizes
9026 there's something here, e.g., so that the user can
9027 say "kill" again. */
9028 inferior_ptid
= magic_null_ptid
;
9035 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9037 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9041 extended_remote_disable_randomization (int val
)
9043 struct remote_state
*rs
= get_remote_state ();
9046 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9049 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9051 error (_("Target does not support QDisableRandomization."));
9052 if (strcmp (reply
, "OK") != 0)
9053 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9057 extended_remote_run (char *args
)
9059 struct remote_state
*rs
= get_remote_state ();
9061 const char *remote_exec_file
= get_remote_exec_file ();
9063 /* If the user has disabled vRun support, or we have detected that
9064 support is not available, do not try it. */
9065 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9068 strcpy (rs
->buf
, "vRun;");
9069 len
= strlen (rs
->buf
);
9071 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9072 error (_("Remote file name too long for run packet"));
9073 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9074 strlen (remote_exec_file
));
9076 gdb_assert (args
!= NULL
);
9079 struct cleanup
*back_to
;
9083 argv
= gdb_buildargv (args
);
9084 back_to
= make_cleanup_freeargv (argv
);
9085 for (i
= 0; argv
[i
] != NULL
; i
++)
9087 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9088 error (_("Argument list too long for run packet"));
9089 rs
->buf
[len
++] = ';';
9090 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9093 do_cleanups (back_to
);
9096 rs
->buf
[len
++] = '\0';
9099 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9101 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9104 /* We have a wait response. All is well. */
9106 case PACKET_UNKNOWN
:
9109 if (remote_exec_file
[0] == '\0')
9110 error (_("Running the default executable on the remote target failed; "
9111 "try \"set remote exec-file\"?"));
9113 error (_("Running \"%s\" on the remote target failed"),
9116 gdb_assert_not_reached (_("bad switch"));
9120 /* In the extended protocol we want to be able to do things like
9121 "run" and have them basically work as expected. So we need
9122 a special create_inferior function. We support changing the
9123 executable file and the command line arguments, but not the
9127 extended_remote_create_inferior (struct target_ops
*ops
,
9128 char *exec_file
, char *args
,
9129 char **env
, int from_tty
)
9133 struct remote_state
*rs
= get_remote_state ();
9134 const char *remote_exec_file
= get_remote_exec_file ();
9136 /* If running asynchronously, register the target file descriptor
9137 with the event loop. */
9138 if (target_can_async_p ())
9141 /* Disable address space randomization if requested (and supported). */
9142 if (extended_remote_supports_disable_randomization (ops
))
9143 extended_remote_disable_randomization (disable_randomization
);
9145 /* Now restart the remote server. */
9146 run_worked
= extended_remote_run (args
) != -1;
9149 /* vRun was not supported. Fail if we need it to do what the
9151 if (remote_exec_file
[0])
9152 error (_("Remote target does not support \"set remote exec-file\""));
9154 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9156 /* Fall back to "R". */
9157 extended_remote_restart ();
9160 if (!have_inferiors ())
9162 /* Clean up from the last time we ran, before we mark the target
9163 running again. This will mark breakpoints uninserted, and
9164 get_offsets may insert breakpoints. */
9165 init_thread_list ();
9166 init_wait_for_inferior ();
9169 /* vRun's success return is a stop reply. */
9170 stop_reply
= run_worked
? rs
->buf
: NULL
;
9171 add_current_inferior_and_thread (stop_reply
);
9173 /* Get updated offsets, if the stub uses qOffsets. */
9178 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9179 the list of conditions (in agent expression bytecode format), if any, the
9180 target needs to evaluate. The output is placed into the packet buffer
9181 started from BUF and ended at BUF_END. */
9184 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9185 struct bp_target_info
*bp_tgt
, char *buf
,
9188 struct agent_expr
*aexpr
= NULL
;
9191 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9194 buf
+= strlen (buf
);
9195 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9198 /* Send conditions to the target and free the vector. */
9200 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9203 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9204 buf
+= strlen (buf
);
9205 for (i
= 0; i
< aexpr
->len
; ++i
)
9206 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9213 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9214 struct bp_target_info
*bp_tgt
, char *buf
)
9216 struct agent_expr
*aexpr
= NULL
;
9219 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9222 buf
+= strlen (buf
);
9224 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9225 buf
+= strlen (buf
);
9227 /* Concatenate all the agent expressions that are commands into the
9230 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9233 sprintf (buf
, "X%x,", aexpr
->len
);
9234 buf
+= strlen (buf
);
9235 for (i
= 0; i
< aexpr
->len
; ++i
)
9236 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9241 /* Insert a breakpoint. On targets that have software breakpoint
9242 support, we ask the remote target to do the work; on targets
9243 which don't, we insert a traditional memory breakpoint. */
9246 remote_insert_breakpoint (struct target_ops
*ops
,
9247 struct gdbarch
*gdbarch
,
9248 struct bp_target_info
*bp_tgt
)
9250 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9251 If it succeeds, then set the support to PACKET_ENABLE. If it
9252 fails, and the user has explicitly requested the Z support then
9253 report an error, otherwise, mark it disabled and go on. */
9255 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9257 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9258 struct remote_state
*rs
;
9262 /* Make sure the remote is pointing at the right process, if
9264 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9265 set_general_process ();
9267 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9269 rs
= get_remote_state ();
9271 endbuf
= rs
->buf
+ get_remote_packet_size ();
9276 addr
= (ULONGEST
) remote_address_masked (addr
);
9277 p
+= hexnumstr (p
, addr
);
9278 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
9280 if (remote_supports_cond_breakpoints (ops
))
9281 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9283 if (remote_can_run_breakpoint_commands (ops
))
9284 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9287 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9289 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9294 bp_tgt
->placed_address
= addr
;
9295 bp_tgt
->placed_size
= bpsize
;
9297 case PACKET_UNKNOWN
:
9302 /* If this breakpoint has target-side commands but this stub doesn't
9303 support Z0 packets, throw error. */
9304 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9305 throw_error (NOT_SUPPORTED_ERROR
, _("\
9306 Target doesn't support breakpoints that have target side commands."));
9308 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9312 remote_remove_breakpoint (struct target_ops
*ops
,
9313 struct gdbarch
*gdbarch
,
9314 struct bp_target_info
*bp_tgt
)
9316 CORE_ADDR addr
= bp_tgt
->placed_address
;
9317 struct remote_state
*rs
= get_remote_state ();
9319 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9322 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9324 /* Make sure the remote is pointing at the right process, if
9326 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9327 set_general_process ();
9333 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9334 p
+= hexnumstr (p
, addr
);
9335 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9338 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9340 return (rs
->buf
[0] == 'E');
9343 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9346 static enum Z_packet_type
9347 watchpoint_to_Z_packet (int type
)
9352 return Z_PACKET_WRITE_WP
;
9355 return Z_PACKET_READ_WP
;
9358 return Z_PACKET_ACCESS_WP
;
9361 internal_error (__FILE__
, __LINE__
,
9362 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9367 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9368 enum target_hw_bp_type type
, struct expression
*cond
)
9370 struct remote_state
*rs
= get_remote_state ();
9371 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9373 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9375 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9378 /* Make sure the remote is pointing at the right process, if
9380 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9381 set_general_process ();
9383 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9384 p
= strchr (rs
->buf
, '\0');
9385 addr
= remote_address_masked (addr
);
9386 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9387 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9390 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9392 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9396 case PACKET_UNKNOWN
:
9401 internal_error (__FILE__
, __LINE__
,
9402 _("remote_insert_watchpoint: reached end of function"));
9406 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9407 CORE_ADDR start
, int length
)
9409 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9411 return diff
< length
;
9416 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9417 enum target_hw_bp_type type
, struct expression
*cond
)
9419 struct remote_state
*rs
= get_remote_state ();
9420 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9422 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9424 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9427 /* Make sure the remote is pointing at the right process, if
9429 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9430 set_general_process ();
9432 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9433 p
= strchr (rs
->buf
, '\0');
9434 addr
= remote_address_masked (addr
);
9435 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9436 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9438 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9440 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9443 case PACKET_UNKNOWN
:
9448 internal_error (__FILE__
, __LINE__
,
9449 _("remote_remove_watchpoint: reached end of function"));
9453 int remote_hw_watchpoint_limit
= -1;
9454 int remote_hw_watchpoint_length_limit
= -1;
9455 int remote_hw_breakpoint_limit
= -1;
9458 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9459 CORE_ADDR addr
, int len
)
9461 if (remote_hw_watchpoint_length_limit
== 0)
9463 else if (remote_hw_watchpoint_length_limit
< 0)
9465 else if (len
<= remote_hw_watchpoint_length_limit
)
9472 remote_check_watch_resources (struct target_ops
*self
,
9473 enum bptype type
, int cnt
, int ot
)
9475 if (type
== bp_hardware_breakpoint
)
9477 if (remote_hw_breakpoint_limit
== 0)
9479 else if (remote_hw_breakpoint_limit
< 0)
9481 else if (cnt
<= remote_hw_breakpoint_limit
)
9486 if (remote_hw_watchpoint_limit
== 0)
9488 else if (remote_hw_watchpoint_limit
< 0)
9492 else if (cnt
<= remote_hw_watchpoint_limit
)
9498 /* The to_stopped_by_sw_breakpoint method of target remote. */
9501 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9503 struct thread_info
*thread
= inferior_thread ();
9505 return (thread
->priv
!= NULL
9506 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9509 /* The to_supports_stopped_by_sw_breakpoint method of target
9513 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9515 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9518 /* The to_stopped_by_hw_breakpoint method of target remote. */
9521 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9523 struct thread_info
*thread
= inferior_thread ();
9525 return (thread
->priv
!= NULL
9526 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9529 /* The to_supports_stopped_by_hw_breakpoint method of target
9533 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9535 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9539 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9541 struct thread_info
*thread
= inferior_thread ();
9543 return (thread
->priv
!= NULL
9544 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9548 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9550 struct thread_info
*thread
= inferior_thread ();
9552 if (thread
->priv
!= NULL
9553 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9555 *addr_p
= thread
->priv
->watch_data_address
;
9564 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9565 struct bp_target_info
*bp_tgt
)
9567 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9568 struct remote_state
*rs
;
9573 /* The length field should be set to the size of a breakpoint
9574 instruction, even though we aren't inserting one ourselves. */
9576 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9578 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9581 /* Make sure the remote is pointing at the right process, if
9583 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9584 set_general_process ();
9586 rs
= get_remote_state ();
9588 endbuf
= rs
->buf
+ get_remote_packet_size ();
9594 addr
= remote_address_masked (addr
);
9595 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9596 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9598 if (remote_supports_cond_breakpoints (self
))
9599 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9601 if (remote_can_run_breakpoint_commands (self
))
9602 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9605 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9607 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9610 if (rs
->buf
[1] == '.')
9612 message
= strchr (rs
->buf
+ 2, '.');
9614 error (_("Remote failure reply: %s"), message
+ 1);
9617 case PACKET_UNKNOWN
:
9620 bp_tgt
->placed_address
= addr
;
9621 bp_tgt
->placed_size
= bpsize
;
9624 internal_error (__FILE__
, __LINE__
,
9625 _("remote_insert_hw_breakpoint: reached end of function"));
9630 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9631 struct bp_target_info
*bp_tgt
)
9634 struct remote_state
*rs
= get_remote_state ();
9636 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9638 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9641 /* Make sure the remote is pointing at the right process, if
9643 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9644 set_general_process ();
9650 addr
= remote_address_masked (bp_tgt
->placed_address
);
9651 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9652 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9655 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9657 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9660 case PACKET_UNKNOWN
:
9665 internal_error (__FILE__
, __LINE__
,
9666 _("remote_remove_hw_breakpoint: reached end of function"));
9669 /* Verify memory using the "qCRC:" request. */
9672 remote_verify_memory (struct target_ops
*ops
,
9673 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9675 struct remote_state
*rs
= get_remote_state ();
9676 unsigned long host_crc
, target_crc
;
9679 /* It doesn't make sense to use qCRC if the remote target is
9680 connected but not running. */
9681 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9683 enum packet_result result
;
9685 /* Make sure the remote is pointing at the right process. */
9686 set_general_process ();
9688 /* FIXME: assumes lma can fit into long. */
9689 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9690 (long) lma
, (long) size
);
9693 /* Be clever; compute the host_crc before waiting for target
9695 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9697 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9699 result
= packet_ok (rs
->buf
,
9700 &remote_protocol_packets
[PACKET_qCRC
]);
9701 if (result
== PACKET_ERROR
)
9703 else if (result
== PACKET_OK
)
9705 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9706 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9708 return (host_crc
== target_crc
);
9712 return simple_verify_memory (ops
, data
, lma
, size
);
9715 /* compare-sections command
9717 With no arguments, compares each loadable section in the exec bfd
9718 with the same memory range on the target, and reports mismatches.
9719 Useful for verifying the image on the target against the exec file. */
9722 compare_sections_command (char *args
, int from_tty
)
9725 struct cleanup
*old_chain
;
9727 const char *sectname
;
9736 error (_("command cannot be used without an exec file"));
9738 /* Make sure the remote is pointing at the right process. */
9739 set_general_process ();
9741 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9747 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9749 if (!(s
->flags
& SEC_LOAD
))
9750 continue; /* Skip non-loadable section. */
9752 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9753 continue; /* Skip writeable sections */
9755 size
= bfd_get_section_size (s
);
9757 continue; /* Skip zero-length section. */
9759 sectname
= bfd_get_section_name (exec_bfd
, s
);
9760 if (args
&& strcmp (args
, sectname
) != 0)
9761 continue; /* Not the section selected by user. */
9763 matched
= 1; /* Do this section. */
9766 sectdata
= (gdb_byte
*) xmalloc (size
);
9767 old_chain
= make_cleanup (xfree
, sectdata
);
9768 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9770 res
= target_verify_memory (sectdata
, lma
, size
);
9773 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9774 paddress (target_gdbarch (), lma
),
9775 paddress (target_gdbarch (), lma
+ size
));
9777 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9778 paddress (target_gdbarch (), lma
),
9779 paddress (target_gdbarch (), lma
+ size
));
9781 printf_filtered ("matched.\n");
9784 printf_filtered ("MIS-MATCHED!\n");
9788 do_cleanups (old_chain
);
9791 warning (_("One or more sections of the target image does not match\n\
9792 the loaded file\n"));
9793 if (args
&& !matched
)
9794 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9797 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9798 into remote target. The number of bytes written to the remote
9799 target is returned, or -1 for error. */
9801 static enum target_xfer_status
9802 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9803 const char *annex
, const gdb_byte
*writebuf
,
9804 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9805 struct packet_config
*packet
)
9809 struct remote_state
*rs
= get_remote_state ();
9810 int max_size
= get_memory_write_packet_size ();
9812 if (packet
->support
== PACKET_DISABLE
)
9813 return TARGET_XFER_E_IO
;
9815 /* Insert header. */
9816 i
= snprintf (rs
->buf
, max_size
,
9817 "qXfer:%s:write:%s:%s:",
9818 object_name
, annex
? annex
: "",
9819 phex_nz (offset
, sizeof offset
));
9820 max_size
-= (i
+ 1);
9822 /* Escape as much data as fits into rs->buf. */
9823 buf_len
= remote_escape_output
9824 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9826 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9827 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9828 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9829 return TARGET_XFER_E_IO
;
9831 unpack_varlen_hex (rs
->buf
, &n
);
9834 return TARGET_XFER_OK
;
9837 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9838 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9839 number of bytes read is returned, or 0 for EOF, or -1 for error.
9840 The number of bytes read may be less than LEN without indicating an
9841 EOF. PACKET is checked and updated to indicate whether the remote
9842 target supports this object. */
9844 static enum target_xfer_status
9845 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9847 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9848 ULONGEST
*xfered_len
,
9849 struct packet_config
*packet
)
9851 struct remote_state
*rs
= get_remote_state ();
9852 LONGEST i
, n
, packet_len
;
9854 if (packet
->support
== PACKET_DISABLE
)
9855 return TARGET_XFER_E_IO
;
9857 /* Check whether we've cached an end-of-object packet that matches
9859 if (rs
->finished_object
)
9861 if (strcmp (object_name
, rs
->finished_object
) == 0
9862 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9863 && offset
== rs
->finished_offset
)
9864 return TARGET_XFER_EOF
;
9867 /* Otherwise, we're now reading something different. Discard
9869 xfree (rs
->finished_object
);
9870 xfree (rs
->finished_annex
);
9871 rs
->finished_object
= NULL
;
9872 rs
->finished_annex
= NULL
;
9875 /* Request only enough to fit in a single packet. The actual data
9876 may not, since we don't know how much of it will need to be escaped;
9877 the target is free to respond with slightly less data. We subtract
9878 five to account for the response type and the protocol frame. */
9879 n
= min (get_remote_packet_size () - 5, len
);
9880 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9881 object_name
, annex
? annex
: "",
9882 phex_nz (offset
, sizeof offset
),
9883 phex_nz (n
, sizeof n
));
9884 i
= putpkt (rs
->buf
);
9886 return TARGET_XFER_E_IO
;
9889 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9890 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9891 return TARGET_XFER_E_IO
;
9893 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9894 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9896 /* 'm' means there is (or at least might be) more data after this
9897 batch. That does not make sense unless there's at least one byte
9898 of data in this reply. */
9899 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9900 error (_("Remote qXfer reply contained no data."));
9902 /* Got some data. */
9903 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9904 packet_len
- 1, readbuf
, n
);
9906 /* 'l' is an EOF marker, possibly including a final block of data,
9907 or possibly empty. If we have the final block of a non-empty
9908 object, record this fact to bypass a subsequent partial read. */
9909 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9911 rs
->finished_object
= xstrdup (object_name
);
9912 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9913 rs
->finished_offset
= offset
+ i
;
9917 return TARGET_XFER_EOF
;
9921 return TARGET_XFER_OK
;
9925 static enum target_xfer_status
9926 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9927 const char *annex
, gdb_byte
*readbuf
,
9928 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9929 ULONGEST
*xfered_len
)
9931 struct remote_state
*rs
;
9935 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9937 set_remote_traceframe ();
9938 set_general_thread (inferior_ptid
);
9940 rs
= get_remote_state ();
9942 /* Handle memory using the standard memory routines. */
9943 if (object
== TARGET_OBJECT_MEMORY
)
9945 /* If the remote target is connected but not running, we should
9946 pass this request down to a lower stratum (e.g. the executable
9948 if (!target_has_execution
)
9949 return TARGET_XFER_EOF
;
9951 if (writebuf
!= NULL
)
9952 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9955 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9959 /* Handle SPU memory using qxfer packets. */
9960 if (object
== TARGET_OBJECT_SPU
)
9963 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9964 xfered_len
, &remote_protocol_packets
9965 [PACKET_qXfer_spu_read
]);
9967 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9968 xfered_len
, &remote_protocol_packets
9969 [PACKET_qXfer_spu_write
]);
9972 /* Handle extra signal info using qxfer packets. */
9973 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9976 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9977 xfered_len
, &remote_protocol_packets
9978 [PACKET_qXfer_siginfo_read
]);
9980 return remote_write_qxfer (ops
, "siginfo", annex
,
9981 writebuf
, offset
, len
, xfered_len
,
9982 &remote_protocol_packets
9983 [PACKET_qXfer_siginfo_write
]);
9986 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9989 return remote_read_qxfer (ops
, "statictrace", annex
,
9990 readbuf
, offset
, len
, xfered_len
,
9991 &remote_protocol_packets
9992 [PACKET_qXfer_statictrace_read
]);
9994 return TARGET_XFER_E_IO
;
9997 /* Only handle flash writes. */
9998 if (writebuf
!= NULL
)
10002 case TARGET_OBJECT_FLASH
:
10003 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10007 return TARGET_XFER_E_IO
;
10011 /* Map pre-existing objects onto letters. DO NOT do this for new
10012 objects!!! Instead specify new query packets. */
10015 case TARGET_OBJECT_AVR
:
10019 case TARGET_OBJECT_AUXV
:
10020 gdb_assert (annex
== NULL
);
10021 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10023 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10025 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10026 return remote_read_qxfer
10027 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10028 &remote_protocol_packets
[PACKET_qXfer_features
]);
10030 case TARGET_OBJECT_LIBRARIES
:
10031 return remote_read_qxfer
10032 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10033 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10035 case TARGET_OBJECT_LIBRARIES_SVR4
:
10036 return remote_read_qxfer
10037 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10038 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10040 case TARGET_OBJECT_MEMORY_MAP
:
10041 gdb_assert (annex
== NULL
);
10042 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10044 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10046 case TARGET_OBJECT_OSDATA
:
10047 /* Should only get here if we're connected. */
10048 gdb_assert (rs
->remote_desc
);
10049 return remote_read_qxfer
10050 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10051 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10053 case TARGET_OBJECT_THREADS
:
10054 gdb_assert (annex
== NULL
);
10055 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10057 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10059 case TARGET_OBJECT_TRACEFRAME_INFO
:
10060 gdb_assert (annex
== NULL
);
10061 return remote_read_qxfer
10062 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10063 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10065 case TARGET_OBJECT_FDPIC
:
10066 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10068 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10070 case TARGET_OBJECT_OPENVMS_UIB
:
10071 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10073 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10075 case TARGET_OBJECT_BTRACE
:
10076 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10078 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10080 case TARGET_OBJECT_BTRACE_CONF
:
10081 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10083 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10085 case TARGET_OBJECT_EXEC_FILE
:
10086 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10088 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10091 return TARGET_XFER_E_IO
;
10094 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10095 large enough let the caller deal with it. */
10096 if (len
< get_remote_packet_size ())
10097 return TARGET_XFER_E_IO
;
10098 len
= get_remote_packet_size ();
10100 /* Except for querying the minimum buffer size, target must be open. */
10101 if (!rs
->remote_desc
)
10102 error (_("remote query is only available after target open"));
10104 gdb_assert (annex
!= NULL
);
10105 gdb_assert (readbuf
!= NULL
);
10109 *p2
++ = query_type
;
10111 /* We used one buffer char for the remote protocol q command and
10112 another for the query type. As the remote protocol encapsulation
10113 uses 4 chars plus one extra in case we are debugging
10114 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10117 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10119 /* Bad caller may have sent forbidden characters. */
10120 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10125 gdb_assert (annex
[i
] == '\0');
10127 i
= putpkt (rs
->buf
);
10129 return TARGET_XFER_E_IO
;
10131 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10132 strcpy ((char *) readbuf
, rs
->buf
);
10134 *xfered_len
= strlen ((char *) readbuf
);
10135 return TARGET_XFER_OK
;
10139 remote_search_memory (struct target_ops
* ops
,
10140 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10141 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10142 CORE_ADDR
*found_addrp
)
10144 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10145 struct remote_state
*rs
= get_remote_state ();
10146 int max_size
= get_memory_write_packet_size ();
10147 struct packet_config
*packet
=
10148 &remote_protocol_packets
[PACKET_qSearch_memory
];
10149 /* Number of packet bytes used to encode the pattern;
10150 this could be more than PATTERN_LEN due to escape characters. */
10151 int escaped_pattern_len
;
10152 /* Amount of pattern that was encodable in the packet. */
10153 int used_pattern_len
;
10156 ULONGEST found_addr
;
10158 /* Don't go to the target if we don't have to.
10159 This is done before checking packet->support to avoid the possibility that
10160 a success for this edge case means the facility works in general. */
10161 if (pattern_len
> search_space_len
)
10163 if (pattern_len
== 0)
10165 *found_addrp
= start_addr
;
10169 /* If we already know the packet isn't supported, fall back to the simple
10170 way of searching memory. */
10172 if (packet_config_support (packet
) == PACKET_DISABLE
)
10174 /* Target doesn't provided special support, fall back and use the
10175 standard support (copy memory and do the search here). */
10176 return simple_search_memory (ops
, start_addr
, search_space_len
,
10177 pattern
, pattern_len
, found_addrp
);
10180 /* Make sure the remote is pointing at the right process. */
10181 set_general_process ();
10183 /* Insert header. */
10184 i
= snprintf (rs
->buf
, max_size
,
10185 "qSearch:memory:%s;%s;",
10186 phex_nz (start_addr
, addr_size
),
10187 phex_nz (search_space_len
, sizeof (search_space_len
)));
10188 max_size
-= (i
+ 1);
10190 /* Escape as much data as fits into rs->buf. */
10191 escaped_pattern_len
=
10192 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10193 &used_pattern_len
, max_size
);
10195 /* Bail if the pattern is too large. */
10196 if (used_pattern_len
!= pattern_len
)
10197 error (_("Pattern is too large to transmit to remote target."));
10199 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10200 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10201 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10203 /* The request may not have worked because the command is not
10204 supported. If so, fall back to the simple way. */
10205 if (packet
->support
== PACKET_DISABLE
)
10207 return simple_search_memory (ops
, start_addr
, search_space_len
,
10208 pattern
, pattern_len
, found_addrp
);
10213 if (rs
->buf
[0] == '0')
10215 else if (rs
->buf
[0] == '1')
10218 if (rs
->buf
[1] != ',')
10219 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10220 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10221 *found_addrp
= found_addr
;
10224 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10230 remote_rcmd (struct target_ops
*self
, const char *command
,
10231 struct ui_file
*outbuf
)
10233 struct remote_state
*rs
= get_remote_state ();
10236 if (!rs
->remote_desc
)
10237 error (_("remote rcmd is only available after target open"));
10239 /* Send a NULL command across as an empty command. */
10240 if (command
== NULL
)
10243 /* The query prefix. */
10244 strcpy (rs
->buf
, "qRcmd,");
10245 p
= strchr (rs
->buf
, '\0');
10247 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10248 > get_remote_packet_size ())
10249 error (_("\"monitor\" command ``%s'' is too long."), command
);
10251 /* Encode the actual command. */
10252 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10254 if (putpkt (rs
->buf
) < 0)
10255 error (_("Communication problem with target."));
10257 /* get/display the response */
10262 /* XXX - see also remote_get_noisy_reply(). */
10263 QUIT
; /* Allow user to bail out with ^C. */
10265 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10267 /* Timeout. Continue to (try to) read responses.
10268 This is better than stopping with an error, assuming the stub
10269 is still executing the (long) monitor command.
10270 If needed, the user can interrupt gdb using C-c, obtaining
10271 an effect similar to stop on timeout. */
10275 if (buf
[0] == '\0')
10276 error (_("Target does not support this command."));
10277 if (buf
[0] == 'O' && buf
[1] != 'K')
10279 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10282 if (strcmp (buf
, "OK") == 0)
10284 if (strlen (buf
) == 3 && buf
[0] == 'E'
10285 && isdigit (buf
[1]) && isdigit (buf
[2]))
10287 error (_("Protocol error with Rcmd"));
10289 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10291 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10293 fputc_unfiltered (c
, outbuf
);
10299 static VEC(mem_region_s
) *
10300 remote_memory_map (struct target_ops
*ops
)
10302 VEC(mem_region_s
) *result
= NULL
;
10303 char *text
= target_read_stralloc (¤t_target
,
10304 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10308 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10310 result
= parse_memory_map (text
);
10311 do_cleanups (back_to
);
10318 packet_command (char *args
, int from_tty
)
10320 struct remote_state
*rs
= get_remote_state ();
10322 if (!rs
->remote_desc
)
10323 error (_("command can only be used with remote target"));
10326 error (_("remote-packet command requires packet text as argument"));
10328 puts_filtered ("sending: ");
10329 print_packet (args
);
10330 puts_filtered ("\n");
10333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10334 puts_filtered ("received: ");
10335 print_packet (rs
->buf
);
10336 puts_filtered ("\n");
10340 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10342 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10344 static void threadset_test_cmd (char *cmd
, int tty
);
10346 static void threadalive_test (char *cmd
, int tty
);
10348 static void threadlist_test_cmd (char *cmd
, int tty
);
10350 int get_and_display_threadinfo (threadref
*ref
);
10352 static void threadinfo_test_cmd (char *cmd
, int tty
);
10354 static int thread_display_step (threadref
*ref
, void *context
);
10356 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10358 static void init_remote_threadtests (void);
10360 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10363 threadset_test_cmd (char *cmd
, int tty
)
10365 int sample_thread
= SAMPLE_THREAD
;
10367 printf_filtered (_("Remote threadset test\n"));
10368 set_general_thread (sample_thread
);
10373 threadalive_test (char *cmd
, int tty
)
10375 int sample_thread
= SAMPLE_THREAD
;
10376 int pid
= ptid_get_pid (inferior_ptid
);
10377 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10379 if (remote_thread_alive (ptid
))
10380 printf_filtered ("PASS: Thread alive test\n");
10382 printf_filtered ("FAIL: Thread alive test\n");
10385 void output_threadid (char *title
, threadref
*ref
);
10388 output_threadid (char *title
, threadref
*ref
)
10392 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10394 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10398 threadlist_test_cmd (char *cmd
, int tty
)
10401 threadref nextthread
;
10402 int done
, result_count
;
10403 threadref threadlist
[3];
10405 printf_filtered ("Remote Threadlist test\n");
10406 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10407 &result_count
, &threadlist
[0]))
10408 printf_filtered ("FAIL: threadlist test\n");
10411 threadref
*scan
= threadlist
;
10412 threadref
*limit
= scan
+ result_count
;
10414 while (scan
< limit
)
10415 output_threadid (" thread ", scan
++);
10420 display_thread_info (struct gdb_ext_thread_info
*info
)
10422 output_threadid ("Threadid: ", &info
->threadid
);
10423 printf_filtered ("Name: %s\n ", info
->shortname
);
10424 printf_filtered ("State: %s\n", info
->display
);
10425 printf_filtered ("other: %s\n\n", info
->more_display
);
10429 get_and_display_threadinfo (threadref
*ref
)
10433 struct gdb_ext_thread_info threadinfo
;
10435 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10436 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10437 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10438 display_thread_info (&threadinfo
);
10443 threadinfo_test_cmd (char *cmd
, int tty
)
10445 int athread
= SAMPLE_THREAD
;
10449 int_to_threadref (&thread
, athread
);
10450 printf_filtered ("Remote Threadinfo test\n");
10451 if (!get_and_display_threadinfo (&thread
))
10452 printf_filtered ("FAIL cannot get thread info\n");
10456 thread_display_step (threadref
*ref
, void *context
)
10458 /* output_threadid(" threadstep ",ref); *//* simple test */
10459 return get_and_display_threadinfo (ref
);
10463 threadlist_update_test_cmd (char *cmd
, int tty
)
10465 printf_filtered ("Remote Threadlist update test\n");
10466 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10470 init_remote_threadtests (void)
10472 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10473 _("Fetch and print the remote list of "
10474 "thread identifiers, one pkt only"));
10475 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10476 _("Fetch and display info about one thread"));
10477 add_com ("tset", class_obscure
, threadset_test_cmd
,
10478 _("Test setting to a different thread"));
10479 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10480 _("Iterate through updating all remote thread info"));
10481 add_com ("talive", class_obscure
, threadalive_test
,
10482 _(" Remote thread alive test "));
10487 /* Convert a thread ID to a string. Returns the string in a static
10491 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10493 static char buf
[64];
10494 struct remote_state
*rs
= get_remote_state ();
10496 if (ptid_equal (ptid
, null_ptid
))
10497 return normal_pid_to_str (ptid
);
10498 else if (ptid_is_pid (ptid
))
10500 /* Printing an inferior target id. */
10502 /* When multi-process extensions are off, there's no way in the
10503 remote protocol to know the remote process id, if there's any
10504 at all. There's one exception --- when we're connected with
10505 target extended-remote, and we manually attached to a process
10506 with "attach PID". We don't record anywhere a flag that
10507 allows us to distinguish that case from the case of
10508 connecting with extended-remote and the stub already being
10509 attached to a process, and reporting yes to qAttached, hence
10510 no smart special casing here. */
10511 if (!remote_multi_process_p (rs
))
10513 xsnprintf (buf
, sizeof buf
, "Remote target");
10517 return normal_pid_to_str (ptid
);
10521 if (ptid_equal (magic_null_ptid
, ptid
))
10522 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10523 else if (remote_multi_process_p (rs
))
10524 if (ptid_get_lwp (ptid
) == 0)
10525 return normal_pid_to_str (ptid
);
10527 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10528 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10530 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10531 ptid_get_lwp (ptid
));
10536 /* Get the address of the thread local variable in OBJFILE which is
10537 stored at OFFSET within the thread local storage for thread PTID. */
10540 remote_get_thread_local_address (struct target_ops
*ops
,
10541 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10543 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10545 struct remote_state
*rs
= get_remote_state ();
10547 char *endp
= rs
->buf
+ get_remote_packet_size ();
10548 enum packet_result result
;
10550 strcpy (p
, "qGetTLSAddr:");
10552 p
= write_ptid (p
, endp
, ptid
);
10554 p
+= hexnumstr (p
, offset
);
10556 p
+= hexnumstr (p
, lm
);
10560 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10561 result
= packet_ok (rs
->buf
,
10562 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10563 if (result
== PACKET_OK
)
10567 unpack_varlen_hex (rs
->buf
, &result
);
10570 else if (result
== PACKET_UNKNOWN
)
10571 throw_error (TLS_GENERIC_ERROR
,
10572 _("Remote target doesn't support qGetTLSAddr packet"));
10574 throw_error (TLS_GENERIC_ERROR
,
10575 _("Remote target failed to process qGetTLSAddr request"));
10578 throw_error (TLS_GENERIC_ERROR
,
10579 _("TLS not supported or disabled on this target"));
10584 /* Provide thread local base, i.e. Thread Information Block address.
10585 Returns 1 if ptid is found and thread_local_base is non zero. */
10588 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10590 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10592 struct remote_state
*rs
= get_remote_state ();
10594 char *endp
= rs
->buf
+ get_remote_packet_size ();
10595 enum packet_result result
;
10597 strcpy (p
, "qGetTIBAddr:");
10599 p
= write_ptid (p
, endp
, ptid
);
10603 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10604 result
= packet_ok (rs
->buf
,
10605 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10606 if (result
== PACKET_OK
)
10610 unpack_varlen_hex (rs
->buf
, &result
);
10612 *addr
= (CORE_ADDR
) result
;
10615 else if (result
== PACKET_UNKNOWN
)
10616 error (_("Remote target doesn't support qGetTIBAddr packet"));
10618 error (_("Remote target failed to process qGetTIBAddr request"));
10621 error (_("qGetTIBAddr not supported or disabled on this target"));
10626 /* Support for inferring a target description based on the current
10627 architecture and the size of a 'g' packet. While the 'g' packet
10628 can have any size (since optional registers can be left off the
10629 end), some sizes are easily recognizable given knowledge of the
10630 approximate architecture. */
10632 struct remote_g_packet_guess
10635 const struct target_desc
*tdesc
;
10637 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10638 DEF_VEC_O(remote_g_packet_guess_s
);
10640 struct remote_g_packet_data
10642 VEC(remote_g_packet_guess_s
) *guesses
;
10645 static struct gdbarch_data
*remote_g_packet_data_handle
;
10648 remote_g_packet_data_init (struct obstack
*obstack
)
10650 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10654 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10655 const struct target_desc
*tdesc
)
10657 struct remote_g_packet_data
*data
10658 = ((struct remote_g_packet_data
*)
10659 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10660 struct remote_g_packet_guess new_guess
, *guess
;
10663 gdb_assert (tdesc
!= NULL
);
10666 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10668 if (guess
->bytes
== bytes
)
10669 internal_error (__FILE__
, __LINE__
,
10670 _("Duplicate g packet description added for size %d"),
10673 new_guess
.bytes
= bytes
;
10674 new_guess
.tdesc
= tdesc
;
10675 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10678 /* Return 1 if remote_read_description would do anything on this target
10679 and architecture, 0 otherwise. */
10682 remote_read_description_p (struct target_ops
*target
)
10684 struct remote_g_packet_data
*data
10685 = ((struct remote_g_packet_data
*)
10686 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10688 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10694 static const struct target_desc
*
10695 remote_read_description (struct target_ops
*target
)
10697 struct remote_g_packet_data
*data
10698 = ((struct remote_g_packet_data
*)
10699 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10701 /* Do not try this during initial connection, when we do not know
10702 whether there is a running but stopped thread. */
10703 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10704 return target
->beneath
->to_read_description (target
->beneath
);
10706 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10708 struct remote_g_packet_guess
*guess
;
10710 int bytes
= send_g_packet ();
10713 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10715 if (guess
->bytes
== bytes
)
10716 return guess
->tdesc
;
10718 /* We discard the g packet. A minor optimization would be to
10719 hold on to it, and fill the register cache once we have selected
10720 an architecture, but it's too tricky to do safely. */
10723 return target
->beneath
->to_read_description (target
->beneath
);
10726 /* Remote file transfer support. This is host-initiated I/O, not
10727 target-initiated; for target-initiated, see remote-fileio.c. */
10729 /* If *LEFT is at least the length of STRING, copy STRING to
10730 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10731 decrease *LEFT. Otherwise raise an error. */
10734 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10736 int len
= strlen (string
);
10739 error (_("Packet too long for target."));
10741 memcpy (*buffer
, string
, len
);
10745 /* NUL-terminate the buffer as a convenience, if there is
10751 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10752 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10753 decrease *LEFT. Otherwise raise an error. */
10756 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10759 if (2 * len
> *left
)
10760 error (_("Packet too long for target."));
10762 bin2hex (bytes
, *buffer
, len
);
10763 *buffer
+= 2 * len
;
10766 /* NUL-terminate the buffer as a convenience, if there is
10772 /* If *LEFT is large enough, convert VALUE to hex and add it to
10773 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10774 decrease *LEFT. Otherwise raise an error. */
10777 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10779 int len
= hexnumlen (value
);
10782 error (_("Packet too long for target."));
10784 hexnumstr (*buffer
, value
);
10788 /* NUL-terminate the buffer as a convenience, if there is
10794 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10795 value, *REMOTE_ERRNO to the remote error number or zero if none
10796 was included, and *ATTACHMENT to point to the start of the annex
10797 if any. The length of the packet isn't needed here; there may
10798 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10800 Return 0 if the packet could be parsed, -1 if it could not. If
10801 -1 is returned, the other variables may not be initialized. */
10804 remote_hostio_parse_result (char *buffer
, int *retcode
,
10805 int *remote_errno
, char **attachment
)
10810 *attachment
= NULL
;
10812 if (buffer
[0] != 'F')
10816 *retcode
= strtol (&buffer
[1], &p
, 16);
10817 if (errno
!= 0 || p
== &buffer
[1])
10820 /* Check for ",errno". */
10824 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10825 if (errno
!= 0 || p
+ 1 == p2
)
10830 /* Check for ";attachment". If there is no attachment, the
10831 packet should end here. */
10834 *attachment
= p
+ 1;
10837 else if (*p
== '\0')
10843 /* Send a prepared I/O packet to the target and read its response.
10844 The prepared packet is in the global RS->BUF before this function
10845 is called, and the answer is there when we return.
10847 COMMAND_BYTES is the length of the request to send, which may include
10848 binary data. WHICH_PACKET is the packet configuration to check
10849 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10850 is set to the error number and -1 is returned. Otherwise the value
10851 returned by the function is returned.
10853 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10854 attachment is expected; an error will be reported if there's a
10855 mismatch. If one is found, *ATTACHMENT will be set to point into
10856 the packet buffer and *ATTACHMENT_LEN will be set to the
10857 attachment's length. */
10860 remote_hostio_send_command (int command_bytes
, int which_packet
,
10861 int *remote_errno
, char **attachment
,
10862 int *attachment_len
)
10864 struct remote_state
*rs
= get_remote_state ();
10865 int ret
, bytes_read
;
10866 char *attachment_tmp
;
10868 if (!rs
->remote_desc
10869 || packet_support (which_packet
) == PACKET_DISABLE
)
10871 *remote_errno
= FILEIO_ENOSYS
;
10875 putpkt_binary (rs
->buf
, command_bytes
);
10876 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10878 /* If it timed out, something is wrong. Don't try to parse the
10880 if (bytes_read
< 0)
10882 *remote_errno
= FILEIO_EINVAL
;
10886 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10889 *remote_errno
= FILEIO_EINVAL
;
10891 case PACKET_UNKNOWN
:
10892 *remote_errno
= FILEIO_ENOSYS
;
10898 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10901 *remote_errno
= FILEIO_EINVAL
;
10905 /* Make sure we saw an attachment if and only if we expected one. */
10906 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10907 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10909 *remote_errno
= FILEIO_EINVAL
;
10913 /* If an attachment was found, it must point into the packet buffer;
10914 work out how many bytes there were. */
10915 if (attachment_tmp
!= NULL
)
10917 *attachment
= attachment_tmp
;
10918 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10924 /* Invalidate the readahead cache. */
10927 readahead_cache_invalidate (void)
10929 struct remote_state
*rs
= get_remote_state ();
10931 rs
->readahead_cache
.fd
= -1;
10934 /* Invalidate the readahead cache if it is holding data for FD. */
10937 readahead_cache_invalidate_fd (int fd
)
10939 struct remote_state
*rs
= get_remote_state ();
10941 if (rs
->readahead_cache
.fd
== fd
)
10942 rs
->readahead_cache
.fd
= -1;
10945 /* Set the filesystem remote_hostio functions that take FILENAME
10946 arguments will use. Return 0 on success, or -1 if an error
10947 occurs (and set *REMOTE_ERRNO). */
10950 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10952 struct remote_state
*rs
= get_remote_state ();
10953 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10955 int left
= get_remote_packet_size () - 1;
10959 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10962 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10965 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10967 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10968 remote_buffer_add_string (&p
, &left
, arg
);
10970 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10971 remote_errno
, NULL
, NULL
);
10973 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10977 rs
->fs_pid
= required_pid
;
10982 /* Implementation of to_fileio_open. */
10985 remote_hostio_open (struct target_ops
*self
,
10986 struct inferior
*inf
, const char *filename
,
10987 int flags
, int mode
, int warn_if_slow
,
10990 struct remote_state
*rs
= get_remote_state ();
10992 int left
= get_remote_packet_size () - 1;
10996 static int warning_issued
= 0;
10998 printf_unfiltered (_("Reading %s from remote target...\n"),
11001 if (!warning_issued
)
11003 warning (_("File transfers from remote targets can be slow."
11004 " Use \"set sysroot\" to access files locally"
11006 warning_issued
= 1;
11010 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11013 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11015 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11016 strlen (filename
));
11017 remote_buffer_add_string (&p
, &left
, ",");
11019 remote_buffer_add_int (&p
, &left
, flags
);
11020 remote_buffer_add_string (&p
, &left
, ",");
11022 remote_buffer_add_int (&p
, &left
, mode
);
11024 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11025 remote_errno
, NULL
, NULL
);
11028 /* Implementation of to_fileio_pwrite. */
11031 remote_hostio_pwrite (struct target_ops
*self
,
11032 int fd
, const gdb_byte
*write_buf
, int len
,
11033 ULONGEST offset
, int *remote_errno
)
11035 struct remote_state
*rs
= get_remote_state ();
11037 int left
= get_remote_packet_size ();
11040 readahead_cache_invalidate_fd (fd
);
11042 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11044 remote_buffer_add_int (&p
, &left
, fd
);
11045 remote_buffer_add_string (&p
, &left
, ",");
11047 remote_buffer_add_int (&p
, &left
, offset
);
11048 remote_buffer_add_string (&p
, &left
, ",");
11050 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11051 get_remote_packet_size () - (p
- rs
->buf
));
11053 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11054 remote_errno
, NULL
, NULL
);
11057 /* Helper for the implementation of to_fileio_pread. Read the file
11058 from the remote side with vFile:pread. */
11061 remote_hostio_pread_vFile (struct target_ops
*self
,
11062 int fd
, gdb_byte
*read_buf
, int len
,
11063 ULONGEST offset
, int *remote_errno
)
11065 struct remote_state
*rs
= get_remote_state ();
11068 int left
= get_remote_packet_size ();
11069 int ret
, attachment_len
;
11072 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11074 remote_buffer_add_int (&p
, &left
, fd
);
11075 remote_buffer_add_string (&p
, &left
, ",");
11077 remote_buffer_add_int (&p
, &left
, len
);
11078 remote_buffer_add_string (&p
, &left
, ",");
11080 remote_buffer_add_int (&p
, &left
, offset
);
11082 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11083 remote_errno
, &attachment
,
11089 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11091 if (read_len
!= ret
)
11092 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11097 /* Serve pread from the readahead cache. Returns number of bytes
11098 read, or 0 if the request can't be served from the cache. */
11101 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11102 int fd
, gdb_byte
*read_buf
, size_t len
,
11105 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11107 if (cache
->fd
== fd
11108 && cache
->offset
<= offset
11109 && offset
< cache
->offset
+ cache
->bufsize
)
11111 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11113 if (offset
+ len
> max
)
11114 len
= max
- offset
;
11116 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11123 /* Implementation of to_fileio_pread. */
11126 remote_hostio_pread (struct target_ops
*self
,
11127 int fd
, gdb_byte
*read_buf
, int len
,
11128 ULONGEST offset
, int *remote_errno
)
11131 struct remote_state
*rs
= get_remote_state ();
11132 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11134 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11137 cache
->hit_count
++;
11140 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11141 pulongest (cache
->hit_count
));
11145 cache
->miss_count
++;
11147 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11148 pulongest (cache
->miss_count
));
11151 cache
->offset
= offset
;
11152 cache
->bufsize
= get_remote_packet_size ();
11153 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11155 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11156 cache
->offset
, remote_errno
);
11159 readahead_cache_invalidate_fd (fd
);
11163 cache
->bufsize
= ret
;
11164 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11167 /* Implementation of to_fileio_close. */
11170 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11172 struct remote_state
*rs
= get_remote_state ();
11174 int left
= get_remote_packet_size () - 1;
11176 readahead_cache_invalidate_fd (fd
);
11178 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11180 remote_buffer_add_int (&p
, &left
, fd
);
11182 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11183 remote_errno
, NULL
, NULL
);
11186 /* Implementation of to_fileio_unlink. */
11189 remote_hostio_unlink (struct target_ops
*self
,
11190 struct inferior
*inf
, const char *filename
,
11193 struct remote_state
*rs
= get_remote_state ();
11195 int left
= get_remote_packet_size () - 1;
11197 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11200 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11202 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11203 strlen (filename
));
11205 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11206 remote_errno
, NULL
, NULL
);
11209 /* Implementation of to_fileio_readlink. */
11212 remote_hostio_readlink (struct target_ops
*self
,
11213 struct inferior
*inf
, const char *filename
,
11216 struct remote_state
*rs
= get_remote_state ();
11219 int left
= get_remote_packet_size ();
11220 int len
, attachment_len
;
11224 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11227 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11229 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11230 strlen (filename
));
11232 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11233 remote_errno
, &attachment
,
11239 ret
= (char *) xmalloc (len
+ 1);
11241 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11242 (gdb_byte
*) ret
, len
);
11243 if (read_len
!= len
)
11244 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11250 /* Implementation of to_fileio_fstat. */
11253 remote_hostio_fstat (struct target_ops
*self
,
11254 int fd
, struct stat
*st
,
11257 struct remote_state
*rs
= get_remote_state ();
11259 int left
= get_remote_packet_size ();
11260 int attachment_len
, ret
;
11262 struct fio_stat fst
;
11265 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11267 remote_buffer_add_int (&p
, &left
, fd
);
11269 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11270 remote_errno
, &attachment
,
11274 if (*remote_errno
!= FILEIO_ENOSYS
)
11277 /* Strictly we should return -1, ENOSYS here, but when
11278 "set sysroot remote:" was implemented in August 2008
11279 BFD's need for a stat function was sidestepped with
11280 this hack. This was not remedied until March 2015
11281 so we retain the previous behavior to avoid breaking
11284 Note that the memset is a March 2015 addition; older
11285 GDBs set st_size *and nothing else* so the structure
11286 would have garbage in all other fields. This might
11287 break something but retaining the previous behavior
11288 here would be just too wrong. */
11290 memset (st
, 0, sizeof (struct stat
));
11291 st
->st_size
= INT_MAX
;
11295 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11296 (gdb_byte
*) &fst
, sizeof (fst
));
11298 if (read_len
!= ret
)
11299 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11301 if (read_len
!= sizeof (fst
))
11302 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11303 read_len
, (int) sizeof (fst
));
11305 remote_fileio_to_host_stat (&fst
, st
);
11310 /* Implementation of to_filesystem_is_local. */
11313 remote_filesystem_is_local (struct target_ops
*self
)
11315 /* Valgrind GDB presents itself as a remote target but works
11316 on the local filesystem: it does not implement remote get
11317 and users are not expected to set a sysroot. To handle
11318 this case we treat the remote filesystem as local if the
11319 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11320 does not support vFile:open. */
11321 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11323 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11325 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11327 int fd
, remote_errno
;
11329 /* Try opening a file to probe support. The supplied
11330 filename is irrelevant, we only care about whether
11331 the stub recognizes the packet or not. */
11332 fd
= remote_hostio_open (self
, NULL
, "just probing",
11333 FILEIO_O_RDONLY
, 0700, 0,
11337 remote_hostio_close (self
, fd
, &remote_errno
);
11339 ps
= packet_support (PACKET_vFile_open
);
11342 if (ps
== PACKET_DISABLE
)
11344 static int warning_issued
= 0;
11346 if (!warning_issued
)
11348 warning (_("remote target does not support file"
11349 " transfer, attempting to access files"
11350 " from local filesystem."));
11351 warning_issued
= 1;
11362 remote_fileio_errno_to_host (int errnum
)
11368 case FILEIO_ENOENT
:
11376 case FILEIO_EACCES
:
11378 case FILEIO_EFAULT
:
11382 case FILEIO_EEXIST
:
11384 case FILEIO_ENODEV
:
11386 case FILEIO_ENOTDIR
:
11388 case FILEIO_EISDIR
:
11390 case FILEIO_EINVAL
:
11392 case FILEIO_ENFILE
:
11394 case FILEIO_EMFILE
:
11398 case FILEIO_ENOSPC
:
11400 case FILEIO_ESPIPE
:
11404 case FILEIO_ENOSYS
:
11406 case FILEIO_ENAMETOOLONG
:
11407 return ENAMETOOLONG
;
11413 remote_hostio_error (int errnum
)
11415 int host_error
= remote_fileio_errno_to_host (errnum
);
11417 if (host_error
== -1)
11418 error (_("Unknown remote I/O error %d"), errnum
);
11420 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11424 remote_hostio_close_cleanup (void *opaque
)
11426 int fd
= *(int *) opaque
;
11429 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11433 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11435 struct cleanup
*back_to
, *close_cleanup
;
11436 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11439 int bytes_in_buffer
;
11442 struct remote_state
*rs
= get_remote_state ();
11444 if (!rs
->remote_desc
)
11445 error (_("command can only be used with remote target"));
11447 file
= gdb_fopen_cloexec (local_file
, "rb");
11449 perror_with_name (local_file
);
11450 back_to
= make_cleanup_fclose (file
);
11452 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11453 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11455 0700, 0, &remote_errno
);
11457 remote_hostio_error (remote_errno
);
11459 /* Send up to this many bytes at once. They won't all fit in the
11460 remote packet limit, so we'll transfer slightly fewer. */
11461 io_size
= get_remote_packet_size ();
11462 buffer
= (gdb_byte
*) xmalloc (io_size
);
11463 make_cleanup (xfree
, buffer
);
11465 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11467 bytes_in_buffer
= 0;
11470 while (bytes_in_buffer
|| !saw_eof
)
11474 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11475 io_size
- bytes_in_buffer
,
11480 error (_("Error reading %s."), local_file
);
11483 /* EOF. Unless there is something still in the
11484 buffer from the last iteration, we are done. */
11486 if (bytes_in_buffer
== 0)
11494 bytes
+= bytes_in_buffer
;
11495 bytes_in_buffer
= 0;
11497 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11499 offset
, &remote_errno
);
11502 remote_hostio_error (remote_errno
);
11503 else if (retcode
== 0)
11504 error (_("Remote write of %d bytes returned 0!"), bytes
);
11505 else if (retcode
< bytes
)
11507 /* Short write. Save the rest of the read data for the next
11509 bytes_in_buffer
= bytes
- retcode
;
11510 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11516 discard_cleanups (close_cleanup
);
11517 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11518 remote_hostio_error (remote_errno
);
11521 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11522 do_cleanups (back_to
);
11526 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11528 struct cleanup
*back_to
, *close_cleanup
;
11529 int fd
, remote_errno
, bytes
, io_size
;
11533 struct remote_state
*rs
= get_remote_state ();
11535 if (!rs
->remote_desc
)
11536 error (_("command can only be used with remote target"));
11538 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11539 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11542 remote_hostio_error (remote_errno
);
11544 file
= gdb_fopen_cloexec (local_file
, "wb");
11546 perror_with_name (local_file
);
11547 back_to
= make_cleanup_fclose (file
);
11549 /* Send up to this many bytes at once. They won't all fit in the
11550 remote packet limit, so we'll transfer slightly fewer. */
11551 io_size
= get_remote_packet_size ();
11552 buffer
= (gdb_byte
*) xmalloc (io_size
);
11553 make_cleanup (xfree
, buffer
);
11555 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11560 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11561 fd
, buffer
, io_size
, offset
, &remote_errno
);
11563 /* Success, but no bytes, means end-of-file. */
11566 remote_hostio_error (remote_errno
);
11570 bytes
= fwrite (buffer
, 1, bytes
, file
);
11572 perror_with_name (local_file
);
11575 discard_cleanups (close_cleanup
);
11576 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11577 remote_hostio_error (remote_errno
);
11580 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11581 do_cleanups (back_to
);
11585 remote_file_delete (const char *remote_file
, int from_tty
)
11587 int retcode
, remote_errno
;
11588 struct remote_state
*rs
= get_remote_state ();
11590 if (!rs
->remote_desc
)
11591 error (_("command can only be used with remote target"));
11593 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11594 NULL
, remote_file
, &remote_errno
);
11596 remote_hostio_error (remote_errno
);
11599 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11603 remote_put_command (char *args
, int from_tty
)
11605 struct cleanup
*back_to
;
11609 error_no_arg (_("file to put"));
11611 argv
= gdb_buildargv (args
);
11612 back_to
= make_cleanup_freeargv (argv
);
11613 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11614 error (_("Invalid parameters to remote put"));
11616 remote_file_put (argv
[0], argv
[1], from_tty
);
11618 do_cleanups (back_to
);
11622 remote_get_command (char *args
, int from_tty
)
11624 struct cleanup
*back_to
;
11628 error_no_arg (_("file to get"));
11630 argv
= gdb_buildargv (args
);
11631 back_to
= make_cleanup_freeargv (argv
);
11632 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11633 error (_("Invalid parameters to remote get"));
11635 remote_file_get (argv
[0], argv
[1], from_tty
);
11637 do_cleanups (back_to
);
11641 remote_delete_command (char *args
, int from_tty
)
11643 struct cleanup
*back_to
;
11647 error_no_arg (_("file to delete"));
11649 argv
= gdb_buildargv (args
);
11650 back_to
= make_cleanup_freeargv (argv
);
11651 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11652 error (_("Invalid parameters to remote delete"));
11654 remote_file_delete (argv
[0], from_tty
);
11656 do_cleanups (back_to
);
11660 remote_command (char *args
, int from_tty
)
11662 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11666 remote_can_execute_reverse (struct target_ops
*self
)
11668 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11669 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11676 remote_supports_non_stop (struct target_ops
*self
)
11682 remote_supports_disable_randomization (struct target_ops
*self
)
11684 /* Only supported in extended mode. */
11689 remote_supports_multi_process (struct target_ops
*self
)
11691 struct remote_state
*rs
= get_remote_state ();
11693 return remote_multi_process_p (rs
);
11697 remote_supports_cond_tracepoints (void)
11699 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11703 remote_supports_cond_breakpoints (struct target_ops
*self
)
11705 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11709 remote_supports_fast_tracepoints (void)
11711 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11715 remote_supports_static_tracepoints (void)
11717 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11721 remote_supports_install_in_trace (void)
11723 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11727 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11729 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11734 remote_supports_string_tracing (struct target_ops
*self
)
11736 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11740 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11742 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11746 remote_trace_init (struct target_ops
*self
)
11749 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11750 if (strcmp (target_buf
, "OK") != 0)
11751 error (_("Target does not support this command."));
11754 static void free_actions_list (char **actions_list
);
11755 static void free_actions_list_cleanup_wrapper (void *);
11757 free_actions_list_cleanup_wrapper (void *al
)
11759 free_actions_list ((char **) al
);
11763 free_actions_list (char **actions_list
)
11767 if (actions_list
== 0)
11770 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11771 xfree (actions_list
[ndx
]);
11773 xfree (actions_list
);
11776 /* Recursive routine to walk through command list including loops, and
11777 download packets for each command. */
11780 remote_download_command_source (int num
, ULONGEST addr
,
11781 struct command_line
*cmds
)
11783 struct remote_state
*rs
= get_remote_state ();
11784 struct command_line
*cmd
;
11786 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11788 QUIT
; /* Allow user to bail out with ^C. */
11789 strcpy (rs
->buf
, "QTDPsrc:");
11790 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11791 rs
->buf
+ strlen (rs
->buf
),
11792 rs
->buf_size
- strlen (rs
->buf
));
11794 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11795 if (strcmp (target_buf
, "OK"))
11796 warning (_("Target does not support source download."));
11798 if (cmd
->control_type
== while_control
11799 || cmd
->control_type
== while_stepping_control
)
11801 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11803 QUIT
; /* Allow user to bail out with ^C. */
11804 strcpy (rs
->buf
, "QTDPsrc:");
11805 encode_source_string (num
, addr
, "cmd", "end",
11806 rs
->buf
+ strlen (rs
->buf
),
11807 rs
->buf_size
- strlen (rs
->buf
));
11809 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11810 if (strcmp (target_buf
, "OK"))
11811 warning (_("Target does not support source download."));
11817 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11819 #define BUF_SIZE 2048
11823 char buf
[BUF_SIZE
];
11824 char **tdp_actions
;
11825 char **stepping_actions
;
11827 struct cleanup
*old_chain
= NULL
;
11828 struct agent_expr
*aexpr
;
11829 struct cleanup
*aexpr_chain
= NULL
;
11831 struct breakpoint
*b
= loc
->owner
;
11832 struct tracepoint
*t
= (struct tracepoint
*) b
;
11834 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11835 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11837 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11840 tpaddr
= loc
->address
;
11841 sprintf_vma (addrbuf
, tpaddr
);
11842 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11843 addrbuf
, /* address */
11844 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11845 t
->step_count
, t
->pass_count
);
11846 /* Fast tracepoints are mostly handled by the target, but we can
11847 tell the target how big of an instruction block should be moved
11849 if (b
->type
== bp_fast_tracepoint
)
11851 /* Only test for support at download time; we may not know
11852 target capabilities at definition time. */
11853 if (remote_supports_fast_tracepoints ())
11855 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11857 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11858 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11860 /* If it passed validation at definition but fails now,
11861 something is very wrong. */
11862 internal_error (__FILE__
, __LINE__
,
11863 _("Fast tracepoint not "
11864 "valid during download"));
11867 /* Fast tracepoints are functionally identical to regular
11868 tracepoints, so don't take lack of support as a reason to
11869 give up on the trace run. */
11870 warning (_("Target does not support fast tracepoints, "
11871 "downloading %d as regular tracepoint"), b
->number
);
11873 else if (b
->type
== bp_static_tracepoint
)
11875 /* Only test for support at download time; we may not know
11876 target capabilities at definition time. */
11877 if (remote_supports_static_tracepoints ())
11879 struct static_tracepoint_marker marker
;
11881 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11882 strcat (buf
, ":S");
11884 error (_("Static tracepoint not valid during download"));
11887 /* Fast tracepoints are functionally identical to regular
11888 tracepoints, so don't take lack of support as a reason
11889 to give up on the trace run. */
11890 error (_("Target does not support static tracepoints"));
11892 /* If the tracepoint has a conditional, make it into an agent
11893 expression and append to the definition. */
11896 /* Only test support at download time, we may not know target
11897 capabilities at definition time. */
11898 if (remote_supports_cond_tracepoints ())
11900 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11901 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11902 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11904 pkt
= buf
+ strlen (buf
);
11905 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11906 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11908 do_cleanups (aexpr_chain
);
11911 warning (_("Target does not support conditional tracepoints, "
11912 "ignoring tp %d cond"), b
->number
);
11915 if (b
->commands
|| *default_collect
)
11918 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11919 if (strcmp (target_buf
, "OK"))
11920 error (_("Target does not support tracepoints."));
11922 /* do_single_steps (t); */
11925 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11927 QUIT
; /* Allow user to bail out with ^C. */
11928 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11929 b
->number
, addrbuf
, /* address */
11931 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11934 remote_get_noisy_reply (&target_buf
,
11936 if (strcmp (target_buf
, "OK"))
11937 error (_("Error on target while setting tracepoints."));
11940 if (stepping_actions
)
11942 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11944 QUIT
; /* Allow user to bail out with ^C. */
11945 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11946 b
->number
, addrbuf
, /* address */
11947 ((ndx
== 0) ? "S" : ""),
11948 stepping_actions
[ndx
],
11949 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11951 remote_get_noisy_reply (&target_buf
,
11953 if (strcmp (target_buf
, "OK"))
11954 error (_("Error on target while setting tracepoints."));
11958 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11960 if (b
->location
!= NULL
)
11962 strcpy (buf
, "QTDPsrc:");
11963 encode_source_string (b
->number
, loc
->address
, "at",
11964 event_location_to_string (b
->location
),
11965 buf
+ strlen (buf
), 2048 - strlen (buf
));
11967 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11968 if (strcmp (target_buf
, "OK"))
11969 warning (_("Target does not support source download."));
11971 if (b
->cond_string
)
11973 strcpy (buf
, "QTDPsrc:");
11974 encode_source_string (b
->number
, loc
->address
,
11975 "cond", b
->cond_string
, buf
+ strlen (buf
),
11976 2048 - strlen (buf
));
11978 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11979 if (strcmp (target_buf
, "OK"))
11980 warning (_("Target does not support source download."));
11982 remote_download_command_source (b
->number
, loc
->address
,
11983 breakpoint_commands (b
));
11986 do_cleanups (old_chain
);
11990 remote_can_download_tracepoint (struct target_ops
*self
)
11992 struct remote_state
*rs
= get_remote_state ();
11993 struct trace_status
*ts
;
11996 /* Don't try to install tracepoints until we've relocated our
11997 symbols, and fetched and merged the target's tracepoint list with
11999 if (rs
->starting_up
)
12002 ts
= current_trace_status ();
12003 status
= remote_get_trace_status (self
, ts
);
12005 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12008 /* If we are in a tracing experiment, but remote stub doesn't support
12009 installing tracepoint in trace, we have to return. */
12010 if (!remote_supports_install_in_trace ())
12018 remote_download_trace_state_variable (struct target_ops
*self
,
12019 struct trace_state_variable
*tsv
)
12021 struct remote_state
*rs
= get_remote_state ();
12024 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12025 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12027 p
= rs
->buf
+ strlen (rs
->buf
);
12028 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12029 error (_("Trace state variable name too long for tsv definition packet"));
12030 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12033 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12034 if (*target_buf
== '\0')
12035 error (_("Target does not support this command."));
12036 if (strcmp (target_buf
, "OK") != 0)
12037 error (_("Error on target while downloading trace state variable."));
12041 remote_enable_tracepoint (struct target_ops
*self
,
12042 struct bp_location
*location
)
12044 struct remote_state
*rs
= get_remote_state ();
12047 sprintf_vma (addr_buf
, location
->address
);
12048 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12049 location
->owner
->number
, addr_buf
);
12051 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12052 if (*rs
->buf
== '\0')
12053 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12054 if (strcmp (rs
->buf
, "OK") != 0)
12055 error (_("Error on target while enabling tracepoint."));
12059 remote_disable_tracepoint (struct target_ops
*self
,
12060 struct bp_location
*location
)
12062 struct remote_state
*rs
= get_remote_state ();
12065 sprintf_vma (addr_buf
, location
->address
);
12066 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12067 location
->owner
->number
, addr_buf
);
12069 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12070 if (*rs
->buf
== '\0')
12071 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12072 if (strcmp (rs
->buf
, "OK") != 0)
12073 error (_("Error on target while disabling tracepoint."));
12077 remote_trace_set_readonly_regions (struct target_ops
*self
)
12081 bfd_size_type size
;
12087 return; /* No information to give. */
12089 strcpy (target_buf
, "QTro");
12090 offset
= strlen (target_buf
);
12091 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12093 char tmp1
[40], tmp2
[40];
12096 if ((s
->flags
& SEC_LOAD
) == 0 ||
12097 /* (s->flags & SEC_CODE) == 0 || */
12098 (s
->flags
& SEC_READONLY
) == 0)
12102 vma
= bfd_get_section_vma (abfd
, s
);
12103 size
= bfd_get_section_size (s
);
12104 sprintf_vma (tmp1
, vma
);
12105 sprintf_vma (tmp2
, vma
+ size
);
12106 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12107 if (offset
+ sec_length
+ 1 > target_buf_size
)
12109 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12111 Too many sections for read-only sections definition packet."));
12114 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12116 offset
+= sec_length
;
12120 putpkt (target_buf
);
12121 getpkt (&target_buf
, &target_buf_size
, 0);
12126 remote_trace_start (struct target_ops
*self
)
12128 putpkt ("QTStart");
12129 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12130 if (*target_buf
== '\0')
12131 error (_("Target does not support this command."));
12132 if (strcmp (target_buf
, "OK") != 0)
12133 error (_("Bogus reply from target: %s"), target_buf
);
12137 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12139 /* Initialize it just to avoid a GCC false warning. */
12141 /* FIXME we need to get register block size some other way. */
12142 extern int trace_regblock_size
;
12143 enum packet_result result
;
12145 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12148 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12150 putpkt ("qTStatus");
12154 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12156 CATCH (ex
, RETURN_MASK_ERROR
)
12158 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12160 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12163 throw_exception (ex
);
12167 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12169 /* If the remote target doesn't do tracing, flag it. */
12170 if (result
== PACKET_UNKNOWN
)
12173 /* We're working with a live target. */
12174 ts
->filename
= NULL
;
12177 error (_("Bogus trace status reply from target: %s"), target_buf
);
12179 /* Function 'parse_trace_status' sets default value of each field of
12180 'ts' at first, so we don't have to do it here. */
12181 parse_trace_status (p
, ts
);
12183 return ts
->running
;
12187 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12188 struct uploaded_tp
*utp
)
12190 struct remote_state
*rs
= get_remote_state ();
12192 struct bp_location
*loc
;
12193 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12194 size_t size
= get_remote_packet_size ();
12198 tp
->base
.hit_count
= 0;
12199 tp
->traceframe_usage
= 0;
12200 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12202 /* If the tracepoint was never downloaded, don't go asking for
12204 if (tp
->number_on_target
== 0)
12206 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12207 phex_nz (loc
->address
, 0));
12209 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12210 if (reply
&& *reply
)
12213 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12219 utp
->hit_count
= 0;
12220 utp
->traceframe_usage
= 0;
12221 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12222 phex_nz (utp
->addr
, 0));
12224 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12225 if (reply
&& *reply
)
12228 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12234 remote_trace_stop (struct target_ops
*self
)
12237 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12238 if (*target_buf
== '\0')
12239 error (_("Target does not support this command."));
12240 if (strcmp (target_buf
, "OK") != 0)
12241 error (_("Bogus reply from target: %s"), target_buf
);
12245 remote_trace_find (struct target_ops
*self
,
12246 enum trace_find_type type
, int num
,
12247 CORE_ADDR addr1
, CORE_ADDR addr2
,
12250 struct remote_state
*rs
= get_remote_state ();
12251 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12253 int target_frameno
= -1, target_tracept
= -1;
12255 /* Lookups other than by absolute frame number depend on the current
12256 trace selected, so make sure it is correct on the remote end
12258 if (type
!= tfind_number
)
12259 set_remote_traceframe ();
12262 strcpy (p
, "QTFrame:");
12263 p
= strchr (p
, '\0');
12267 xsnprintf (p
, endbuf
- p
, "%x", num
);
12270 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12273 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12276 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12277 phex_nz (addr2
, 0));
12279 case tfind_outside
:
12280 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12281 phex_nz (addr2
, 0));
12284 error (_("Unknown trace find type %d"), type
);
12288 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12289 if (*reply
== '\0')
12290 error (_("Target does not support this command."));
12292 while (reply
&& *reply
)
12297 target_frameno
= (int) strtol (p
, &reply
, 16);
12299 error (_("Unable to parse trace frame number"));
12300 /* Don't update our remote traceframe number cache on failure
12301 to select a remote traceframe. */
12302 if (target_frameno
== -1)
12307 target_tracept
= (int) strtol (p
, &reply
, 16);
12309 error (_("Unable to parse tracepoint number"));
12311 case 'O': /* "OK"? */
12312 if (reply
[1] == 'K' && reply
[2] == '\0')
12315 error (_("Bogus reply from target: %s"), reply
);
12318 error (_("Bogus reply from target: %s"), reply
);
12321 *tpp
= target_tracept
;
12323 rs
->remote_traceframe_number
= target_frameno
;
12324 return target_frameno
;
12328 remote_get_trace_state_variable_value (struct target_ops
*self
,
12329 int tsvnum
, LONGEST
*val
)
12331 struct remote_state
*rs
= get_remote_state ();
12335 set_remote_traceframe ();
12337 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12339 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12340 if (reply
&& *reply
)
12344 unpack_varlen_hex (reply
+ 1, &uval
);
12345 *val
= (LONGEST
) uval
;
12353 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12355 struct remote_state
*rs
= get_remote_state ();
12359 strcpy (p
, "QTSave:");
12361 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12362 error (_("Remote file name too long for trace save packet"));
12363 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12366 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12367 if (*reply
== '\0')
12368 error (_("Target does not support this command."));
12369 if (strcmp (reply
, "OK") != 0)
12370 error (_("Bogus reply from target: %s"), reply
);
12374 /* This is basically a memory transfer, but needs to be its own packet
12375 because we don't know how the target actually organizes its trace
12376 memory, plus we want to be able to ask for as much as possible, but
12377 not be unhappy if we don't get as much as we ask for. */
12380 remote_get_raw_trace_data (struct target_ops
*self
,
12381 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12383 struct remote_state
*rs
= get_remote_state ();
12389 strcpy (p
, "qTBuffer:");
12391 p
+= hexnumstr (p
, offset
);
12393 p
+= hexnumstr (p
, len
);
12397 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12398 if (reply
&& *reply
)
12400 /* 'l' by itself means we're at the end of the buffer and
12401 there is nothing more to get. */
12405 /* Convert the reply into binary. Limit the number of bytes to
12406 convert according to our passed-in buffer size, rather than
12407 what was returned in the packet; if the target is
12408 unexpectedly generous and gives us a bigger reply than we
12409 asked for, we don't want to crash. */
12410 rslt
= hex2bin (target_buf
, buf
, len
);
12414 /* Something went wrong, flag as an error. */
12419 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12421 struct remote_state
*rs
= get_remote_state ();
12423 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12427 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12429 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12430 if (*reply
== '\0')
12431 error (_("Target does not support this command."));
12432 if (strcmp (reply
, "OK") != 0)
12433 error (_("Bogus reply from target: %s"), reply
);
12436 warning (_("Target does not support disconnected tracing."));
12440 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12442 struct thread_info
*info
= find_thread_ptid (ptid
);
12444 if (info
&& info
->priv
)
12445 return info
->priv
->core
;
12450 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12452 struct remote_state
*rs
= get_remote_state ();
12455 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12457 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12458 if (*reply
== '\0')
12459 error (_("Target does not support this command."));
12460 if (strcmp (reply
, "OK") != 0)
12461 error (_("Bogus reply from target: %s"), reply
);
12464 static struct traceframe_info
*
12465 remote_traceframe_info (struct target_ops
*self
)
12469 text
= target_read_stralloc (¤t_target
,
12470 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12473 struct traceframe_info
*info
;
12474 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12476 info
= parse_traceframe_info (text
);
12477 do_cleanups (back_to
);
12484 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12485 instruction on which a fast tracepoint may be placed. Returns -1
12486 if the packet is not supported, and 0 if the minimum instruction
12487 length is unknown. */
12490 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12492 struct remote_state
*rs
= get_remote_state ();
12495 /* If we're not debugging a process yet, the IPA can't be
12497 if (!target_has_execution
)
12500 /* Make sure the remote is pointing at the right process. */
12501 set_general_process ();
12503 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12505 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12506 if (*reply
== '\0')
12510 ULONGEST min_insn_len
;
12512 unpack_varlen_hex (reply
, &min_insn_len
);
12514 return (int) min_insn_len
;
12519 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12521 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12523 struct remote_state
*rs
= get_remote_state ();
12524 char *buf
= rs
->buf
;
12525 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12526 enum packet_result result
;
12528 gdb_assert (val
>= 0 || val
== -1);
12529 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12530 /* Send -1 as literal "-1" to avoid host size dependency. */
12534 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12537 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12540 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12541 result
= packet_ok (rs
->buf
,
12542 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12544 if (result
!= PACKET_OK
)
12545 warning (_("Bogus reply from target: %s"), rs
->buf
);
12550 remote_set_trace_notes (struct target_ops
*self
,
12551 const char *user
, const char *notes
,
12552 const char *stop_notes
)
12554 struct remote_state
*rs
= get_remote_state ();
12556 char *buf
= rs
->buf
;
12557 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12560 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12563 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12564 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12570 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12571 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12577 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12578 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12582 /* Ensure the buffer is terminated. */
12586 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12587 if (*reply
== '\0')
12590 if (strcmp (reply
, "OK") != 0)
12591 error (_("Bogus reply from target: %s"), reply
);
12597 remote_use_agent (struct target_ops
*self
, int use
)
12599 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12601 struct remote_state
*rs
= get_remote_state ();
12603 /* If the stub supports QAgent. */
12604 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12606 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12608 if (strcmp (rs
->buf
, "OK") == 0)
12619 remote_can_use_agent (struct target_ops
*self
)
12621 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12624 struct btrace_target_info
12626 /* The ptid of the traced thread. */
12629 /* The obtained branch trace configuration. */
12630 struct btrace_config conf
;
12633 /* Reset our idea of our target's btrace configuration. */
12636 remote_btrace_reset (void)
12638 struct remote_state
*rs
= get_remote_state ();
12640 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12643 /* Check whether the target supports branch tracing. */
12646 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12648 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12650 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12655 case BTRACE_FORMAT_NONE
:
12658 case BTRACE_FORMAT_BTS
:
12659 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12661 case BTRACE_FORMAT_PT
:
12662 /* The trace is decoded on the host. Even if our target supports it,
12663 we still need to have libipt to decode the trace. */
12664 #if defined (HAVE_LIBIPT)
12665 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12666 #else /* !defined (HAVE_LIBIPT) */
12668 #endif /* !defined (HAVE_LIBIPT) */
12671 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12674 /* Synchronize the configuration with the target. */
12677 btrace_sync_conf (const struct btrace_config
*conf
)
12679 struct packet_config
*packet
;
12680 struct remote_state
*rs
;
12681 char *buf
, *pos
, *endbuf
;
12683 rs
= get_remote_state ();
12685 endbuf
= buf
+ get_remote_packet_size ();
12687 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12688 if (packet_config_support (packet
) == PACKET_ENABLE
12689 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12692 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12696 getpkt (&buf
, &rs
->buf_size
, 0);
12698 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12700 if (buf
[0] == 'E' && buf
[1] == '.')
12701 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12703 error (_("Failed to configure the BTS buffer size."));
12706 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12709 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12710 if (packet_config_support (packet
) == PACKET_ENABLE
12711 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12714 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12718 getpkt (&buf
, &rs
->buf_size
, 0);
12720 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12722 if (buf
[0] == 'E' && buf
[1] == '.')
12723 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12725 error (_("Failed to configure the trace buffer size."));
12728 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12732 /* Read the current thread's btrace configuration from the target and
12733 store it into CONF. */
12736 btrace_read_config (struct btrace_config
*conf
)
12740 xml
= target_read_stralloc (¤t_target
,
12741 TARGET_OBJECT_BTRACE_CONF
, "");
12744 struct cleanup
*cleanup
;
12746 cleanup
= make_cleanup (xfree
, xml
);
12747 parse_xml_btrace_conf (conf
, xml
);
12748 do_cleanups (cleanup
);
12752 /* Enable branch tracing. */
12754 static struct btrace_target_info
*
12755 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12756 const struct btrace_config
*conf
)
12758 struct btrace_target_info
*tinfo
= NULL
;
12759 struct packet_config
*packet
= NULL
;
12760 struct remote_state
*rs
= get_remote_state ();
12761 char *buf
= rs
->buf
;
12762 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12764 switch (conf
->format
)
12766 case BTRACE_FORMAT_BTS
:
12767 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12770 case BTRACE_FORMAT_PT
:
12771 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12775 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12776 error (_("Target does not support branch tracing."));
12778 btrace_sync_conf (conf
);
12780 set_general_thread (ptid
);
12782 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12784 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12786 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12788 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12789 error (_("Could not enable branch tracing for %s: %s"),
12790 target_pid_to_str (ptid
), rs
->buf
+ 2);
12792 error (_("Could not enable branch tracing for %s."),
12793 target_pid_to_str (ptid
));
12796 tinfo
= XCNEW (struct btrace_target_info
);
12797 tinfo
->ptid
= ptid
;
12799 /* If we fail to read the configuration, we lose some information, but the
12800 tracing itself is not impacted. */
12803 btrace_read_config (&tinfo
->conf
);
12805 CATCH (err
, RETURN_MASK_ERROR
)
12807 if (err
.message
!= NULL
)
12808 warning ("%s", err
.message
);
12815 /* Disable branch tracing. */
12818 remote_disable_btrace (struct target_ops
*self
,
12819 struct btrace_target_info
*tinfo
)
12821 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12822 struct remote_state
*rs
= get_remote_state ();
12823 char *buf
= rs
->buf
;
12824 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12826 if (packet_config_support (packet
) != PACKET_ENABLE
)
12827 error (_("Target does not support branch tracing."));
12829 set_general_thread (tinfo
->ptid
);
12831 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12835 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12837 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12838 error (_("Could not disable branch tracing for %s: %s"),
12839 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12841 error (_("Could not disable branch tracing for %s."),
12842 target_pid_to_str (tinfo
->ptid
));
12848 /* Teardown branch tracing. */
12851 remote_teardown_btrace (struct target_ops
*self
,
12852 struct btrace_target_info
*tinfo
)
12854 /* We must not talk to the target during teardown. */
12858 /* Read the branch trace. */
12860 static enum btrace_error
12861 remote_read_btrace (struct target_ops
*self
,
12862 struct btrace_data
*btrace
,
12863 struct btrace_target_info
*tinfo
,
12864 enum btrace_read_type type
)
12866 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12867 struct cleanup
*cleanup
;
12871 if (packet_config_support (packet
) != PACKET_ENABLE
)
12872 error (_("Target does not support branch tracing."));
12874 #if !defined(HAVE_LIBEXPAT)
12875 error (_("Cannot process branch tracing result. XML parsing not supported."));
12880 case BTRACE_READ_ALL
:
12883 case BTRACE_READ_NEW
:
12886 case BTRACE_READ_DELTA
:
12890 internal_error (__FILE__
, __LINE__
,
12891 _("Bad branch tracing read type: %u."),
12892 (unsigned int) type
);
12895 xml
= target_read_stralloc (¤t_target
,
12896 TARGET_OBJECT_BTRACE
, annex
);
12898 return BTRACE_ERR_UNKNOWN
;
12900 cleanup
= make_cleanup (xfree
, xml
);
12901 parse_xml_btrace (btrace
, xml
);
12902 do_cleanups (cleanup
);
12904 return BTRACE_ERR_NONE
;
12907 static const struct btrace_config
*
12908 remote_btrace_conf (struct target_ops
*self
,
12909 const struct btrace_target_info
*tinfo
)
12911 return &tinfo
->conf
;
12915 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12917 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12921 /* Implementation of to_load. */
12924 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12926 generic_load (name
, from_tty
);
12929 /* Accepts an integer PID; returns a string representing a file that
12930 can be opened on the remote side to get the symbols for the child
12931 process. Returns NULL if the operation is not supported. */
12934 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12936 static char *filename
= NULL
;
12937 struct inferior
*inf
;
12938 char *annex
= NULL
;
12940 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12943 if (filename
!= NULL
)
12946 inf
= find_inferior_pid (pid
);
12948 internal_error (__FILE__
, __LINE__
,
12949 _("not currently attached to process %d"), pid
);
12951 if (!inf
->fake_pid_p
)
12953 const int annex_size
= 9;
12955 annex
= (char *) alloca (annex_size
);
12956 xsnprintf (annex
, annex_size
, "%x", pid
);
12959 filename
= target_read_stralloc (¤t_target
,
12960 TARGET_OBJECT_EXEC_FILE
, annex
);
12965 /* Implement the to_can_do_single_step target_ops method. */
12968 remote_can_do_single_step (struct target_ops
*ops
)
12970 /* We can only tell whether target supports single step or not by
12971 supported s and S vCont actions if the stub supports vContSupported
12972 feature. If the stub doesn't support vContSupported feature,
12973 we have conservatively to think target doesn't supports single
12975 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
12977 struct remote_state
*rs
= get_remote_state ();
12979 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12980 remote_vcont_probe (rs
);
12982 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
12989 init_remote_ops (void)
12991 remote_ops
.to_shortname
= "remote";
12992 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12993 remote_ops
.to_doc
=
12994 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12995 Specify the serial device it is connected to\n\
12996 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12997 remote_ops
.to_open
= remote_open
;
12998 remote_ops
.to_close
= remote_close
;
12999 remote_ops
.to_detach
= remote_detach
;
13000 remote_ops
.to_disconnect
= remote_disconnect
;
13001 remote_ops
.to_resume
= remote_resume
;
13002 remote_ops
.to_wait
= remote_wait
;
13003 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13004 remote_ops
.to_store_registers
= remote_store_registers
;
13005 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13006 remote_ops
.to_files_info
= remote_files_info
;
13007 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13008 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13009 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13010 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13011 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13012 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13013 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13014 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13015 remote_ops
.to_watchpoint_addr_within_range
=
13016 remote_watchpoint_addr_within_range
;
13017 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13018 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13019 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13020 remote_ops
.to_region_ok_for_hw_watchpoint
13021 = remote_region_ok_for_hw_watchpoint
;
13022 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13023 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13024 remote_ops
.to_kill
= remote_kill
;
13025 remote_ops
.to_load
= remote_load
;
13026 remote_ops
.to_mourn_inferior
= remote_mourn
;
13027 remote_ops
.to_pass_signals
= remote_pass_signals
;
13028 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13029 remote_ops
.to_program_signals
= remote_program_signals
;
13030 remote_ops
.to_thread_alive
= remote_thread_alive
;
13031 remote_ops
.to_thread_name
= remote_thread_name
;
13032 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13033 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13034 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13035 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13036 remote_ops
.to_stop
= remote_stop
;
13037 remote_ops
.to_interrupt
= remote_interrupt
;
13038 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13039 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13040 remote_ops
.to_rcmd
= remote_rcmd
;
13041 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13042 remote_ops
.to_log_command
= serial_log_command
;
13043 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13044 remote_ops
.to_stratum
= process_stratum
;
13045 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13046 remote_ops
.to_has_memory
= default_child_has_memory
;
13047 remote_ops
.to_has_stack
= default_child_has_stack
;
13048 remote_ops
.to_has_registers
= default_child_has_registers
;
13049 remote_ops
.to_has_execution
= default_child_has_execution
;
13050 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13051 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13052 remote_ops
.to_magic
= OPS_MAGIC
;
13053 remote_ops
.to_memory_map
= remote_memory_map
;
13054 remote_ops
.to_flash_erase
= remote_flash_erase
;
13055 remote_ops
.to_flash_done
= remote_flash_done
;
13056 remote_ops
.to_read_description
= remote_read_description
;
13057 remote_ops
.to_search_memory
= remote_search_memory
;
13058 remote_ops
.to_can_async_p
= remote_can_async_p
;
13059 remote_ops
.to_is_async_p
= remote_is_async_p
;
13060 remote_ops
.to_async
= remote_async
;
13061 remote_ops
.to_thread_events
= remote_thread_events
;
13062 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13063 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13064 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13065 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13066 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13067 remote_ops
.to_supports_disable_randomization
13068 = remote_supports_disable_randomization
;
13069 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13070 remote_ops
.to_fileio_open
= remote_hostio_open
;
13071 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13072 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13073 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13074 remote_ops
.to_fileio_close
= remote_hostio_close
;
13075 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13076 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13077 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13078 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13079 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13080 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13081 remote_ops
.to_trace_init
= remote_trace_init
;
13082 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13083 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13084 remote_ops
.to_download_trace_state_variable
13085 = remote_download_trace_state_variable
;
13086 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13087 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13088 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13089 remote_ops
.to_trace_start
= remote_trace_start
;
13090 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13091 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13092 remote_ops
.to_trace_stop
= remote_trace_stop
;
13093 remote_ops
.to_trace_find
= remote_trace_find
;
13094 remote_ops
.to_get_trace_state_variable_value
13095 = remote_get_trace_state_variable_value
;
13096 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13097 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13098 remote_ops
.to_upload_trace_state_variables
13099 = remote_upload_trace_state_variables
;
13100 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13101 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13102 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13103 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13104 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13105 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13106 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13107 remote_ops
.to_verify_memory
= remote_verify_memory
;
13108 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13109 remote_ops
.to_set_permissions
= remote_set_permissions
;
13110 remote_ops
.to_static_tracepoint_marker_at
13111 = remote_static_tracepoint_marker_at
;
13112 remote_ops
.to_static_tracepoint_markers_by_strid
13113 = remote_static_tracepoint_markers_by_strid
;
13114 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13115 remote_ops
.to_use_agent
= remote_use_agent
;
13116 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13117 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13118 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13119 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13120 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13121 remote_ops
.to_read_btrace
= remote_read_btrace
;
13122 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13123 remote_ops
.to_augmented_libraries_svr4_read
=
13124 remote_augmented_libraries_svr4_read
;
13125 remote_ops
.to_follow_fork
= remote_follow_fork
;
13126 remote_ops
.to_follow_exec
= remote_follow_exec
;
13127 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13128 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13129 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13130 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13131 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13132 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13135 /* Set up the extended remote vector by making a copy of the standard
13136 remote vector and adding to it. */
13139 init_extended_remote_ops (void)
13141 extended_remote_ops
= remote_ops
;
13143 extended_remote_ops
.to_shortname
= "extended-remote";
13144 extended_remote_ops
.to_longname
=
13145 "Extended remote serial target in gdb-specific protocol";
13146 extended_remote_ops
.to_doc
=
13147 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13148 Specify the serial device it is connected to (e.g. /dev/ttya).";
13149 extended_remote_ops
.to_open
= extended_remote_open
;
13150 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13151 extended_remote_ops
.to_detach
= extended_remote_detach
;
13152 extended_remote_ops
.to_attach
= extended_remote_attach
;
13153 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13154 extended_remote_ops
.to_supports_disable_randomization
13155 = extended_remote_supports_disable_randomization
;
13159 remote_can_async_p (struct target_ops
*ops
)
13161 struct remote_state
*rs
= get_remote_state ();
13163 if (!target_async_permitted
)
13164 /* We only enable async when the user specifically asks for it. */
13167 /* We're async whenever the serial device is. */
13168 return serial_can_async_p (rs
->remote_desc
);
13172 remote_is_async_p (struct target_ops
*ops
)
13174 struct remote_state
*rs
= get_remote_state ();
13176 if (!target_async_permitted
)
13177 /* We only enable async when the user specifically asks for it. */
13180 /* We're async whenever the serial device is. */
13181 return serial_is_async_p (rs
->remote_desc
);
13184 /* Pass the SERIAL event on and up to the client. One day this code
13185 will be able to delay notifying the client of an event until the
13186 point where an entire packet has been received. */
13188 static serial_event_ftype remote_async_serial_handler
;
13191 remote_async_serial_handler (struct serial
*scb
, void *context
)
13193 /* Don't propogate error information up to the client. Instead let
13194 the client find out about the error by querying the target. */
13195 inferior_event_handler (INF_REG_EVENT
, NULL
);
13199 remote_async_inferior_event_handler (gdb_client_data data
)
13201 inferior_event_handler (INF_REG_EVENT
, NULL
);
13205 remote_async (struct target_ops
*ops
, int enable
)
13207 struct remote_state
*rs
= get_remote_state ();
13211 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13213 /* If there are pending events in the stop reply queue tell the
13214 event loop to process them. */
13215 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13216 mark_async_event_handler (remote_async_inferior_event_token
);
13217 /* For simplicity, below we clear the pending events token
13218 without remembering whether it is marked, so here we always
13219 mark it. If there's actually no pending notification to
13220 process, this ends up being a no-op (other than a spurious
13221 event-loop wakeup). */
13222 if (target_is_non_stop_p ())
13223 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13227 serial_async (rs
->remote_desc
, NULL
, NULL
);
13228 /* If the core is disabling async, it doesn't want to be
13229 disturbed with target events. Clear all async event sources
13231 clear_async_event_handler (remote_async_inferior_event_token
);
13232 if (target_is_non_stop_p ())
13233 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13237 /* Implementation of the to_thread_events method. */
13240 remote_thread_events (struct target_ops
*ops
, int enable
)
13242 struct remote_state
*rs
= get_remote_state ();
13243 size_t size
= get_remote_packet_size ();
13245 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13248 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13250 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13252 switch (packet_ok (rs
->buf
,
13253 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13256 if (strcmp (rs
->buf
, "OK") != 0)
13257 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13260 warning (_("Remote failure reply: %s"), rs
->buf
);
13262 case PACKET_UNKNOWN
:
13268 set_remote_cmd (char *args
, int from_tty
)
13270 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13274 show_remote_cmd (char *args
, int from_tty
)
13276 /* We can't just use cmd_show_list here, because we want to skip
13277 the redundant "show remote Z-packet" and the legacy aliases. */
13278 struct cleanup
*showlist_chain
;
13279 struct cmd_list_element
*list
= remote_show_cmdlist
;
13280 struct ui_out
*uiout
= current_uiout
;
13282 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13283 for (; list
!= NULL
; list
= list
->next
)
13284 if (strcmp (list
->name
, "Z-packet") == 0)
13286 else if (list
->type
== not_set_cmd
)
13287 /* Alias commands are exactly like the original, except they
13288 don't have the normal type. */
13292 struct cleanup
*option_chain
13293 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13295 ui_out_field_string (uiout
, "name", list
->name
);
13296 ui_out_text (uiout
, ": ");
13297 if (list
->type
== show_cmd
)
13298 do_show_command ((char *) NULL
, from_tty
, list
);
13300 cmd_func (list
, NULL
, from_tty
);
13301 /* Close the tuple. */
13302 do_cleanups (option_chain
);
13305 /* Close the tuple. */
13306 do_cleanups (showlist_chain
);
13310 /* Function to be called whenever a new objfile (shlib) is detected. */
13312 remote_new_objfile (struct objfile
*objfile
)
13314 struct remote_state
*rs
= get_remote_state ();
13316 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13317 remote_check_symbols ();
13320 /* Pull all the tracepoints defined on the target and create local
13321 data structures representing them. We don't want to create real
13322 tracepoints yet, we don't want to mess up the user's existing
13326 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13328 struct remote_state
*rs
= get_remote_state ();
13331 /* Ask for a first packet of tracepoint definition. */
13333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13335 while (*p
&& *p
!= 'l')
13337 parse_tracepoint_definition (p
, utpp
);
13338 /* Ask for another packet of tracepoint definition. */
13340 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13347 remote_upload_trace_state_variables (struct target_ops
*self
,
13348 struct uploaded_tsv
**utsvp
)
13350 struct remote_state
*rs
= get_remote_state ();
13353 /* Ask for a first packet of variable definition. */
13355 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13357 while (*p
&& *p
!= 'l')
13359 parse_tsv_definition (p
, utsvp
);
13360 /* Ask for another packet of variable definition. */
13362 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13368 /* The "set/show range-stepping" show hook. */
13371 show_range_stepping (struct ui_file
*file
, int from_tty
,
13372 struct cmd_list_element
*c
,
13375 fprintf_filtered (file
,
13376 _("Debugger's willingness to use range stepping "
13377 "is %s.\n"), value
);
13380 /* The "set/show range-stepping" set hook. */
13383 set_range_stepping (char *ignore_args
, int from_tty
,
13384 struct cmd_list_element
*c
)
13386 struct remote_state
*rs
= get_remote_state ();
13388 /* Whene enabling, check whether range stepping is actually
13389 supported by the target, and warn if not. */
13390 if (use_range_stepping
)
13392 if (rs
->remote_desc
!= NULL
)
13394 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13395 remote_vcont_probe (rs
);
13397 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13398 && rs
->supports_vCont
.r
)
13402 warning (_("Range stepping is not supported by the current target"));
13407 _initialize_remote (void)
13409 struct cmd_list_element
*cmd
;
13410 const char *cmd_name
;
13412 /* architecture specific data */
13413 remote_gdbarch_data_handle
=
13414 gdbarch_data_register_post_init (init_remote_state
);
13415 remote_g_packet_data_handle
=
13416 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13419 = register_program_space_data_with_cleanup (NULL
,
13420 remote_pspace_data_cleanup
);
13422 /* Initialize the per-target state. At the moment there is only one
13423 of these, not one per target. Only one target is active at a
13425 remote_state
= new_remote_state ();
13427 init_remote_ops ();
13428 add_target (&remote_ops
);
13430 init_extended_remote_ops ();
13431 add_target (&extended_remote_ops
);
13433 /* Hook into new objfile notification. */
13434 observer_attach_new_objfile (remote_new_objfile
);
13435 /* We're no longer interested in notification events of an inferior
13437 observer_attach_inferior_exit (discard_pending_stop_replies
);
13440 init_remote_threadtests ();
13443 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13444 /* set/show remote ... */
13446 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13447 Remote protocol specific variables\n\
13448 Configure various remote-protocol specific variables such as\n\
13449 the packets being used"),
13450 &remote_set_cmdlist
, "set remote ",
13451 0 /* allow-unknown */, &setlist
);
13452 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13453 Remote protocol specific variables\n\
13454 Configure various remote-protocol specific variables such as\n\
13455 the packets being used"),
13456 &remote_show_cmdlist
, "show remote ",
13457 0 /* allow-unknown */, &showlist
);
13459 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13460 Compare section data on target to the exec file.\n\
13461 Argument is a single section name (default: all loaded sections).\n\
13462 To compare only read-only loaded sections, specify the -r option."),
13465 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13466 Send an arbitrary packet to a remote target.\n\
13467 maintenance packet TEXT\n\
13468 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13469 this command sends the string TEXT to the inferior, and displays the\n\
13470 response packet. GDB supplies the initial `$' character, and the\n\
13471 terminating `#' character and checksum."),
13474 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13475 Set whether to send break if interrupted."), _("\
13476 Show whether to send break if interrupted."), _("\
13477 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13478 set_remotebreak
, show_remotebreak
,
13479 &setlist
, &showlist
);
13480 cmd_name
= "remotebreak";
13481 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13482 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13483 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13484 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13485 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13487 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13488 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13490 Set interrupt sequence to remote target."), _("\
13491 Show interrupt sequence to remote target."), _("\
13492 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13493 NULL
, show_interrupt_sequence
,
13494 &remote_set_cmdlist
,
13495 &remote_show_cmdlist
);
13497 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13498 &interrupt_on_connect
, _("\
13499 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13500 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13501 If set, interrupt sequence is sent to remote target."),
13503 &remote_set_cmdlist
, &remote_show_cmdlist
);
13505 /* Install commands for configuring memory read/write packets. */
13507 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13508 Set the maximum number of bytes per memory write packet (deprecated)."),
13510 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13511 Show the maximum number of bytes per memory write packet (deprecated)."),
13513 add_cmd ("memory-write-packet-size", no_class
,
13514 set_memory_write_packet_size
, _("\
13515 Set the maximum number of bytes per memory-write packet.\n\
13516 Specify the number of bytes in a packet or 0 (zero) for the\n\
13517 default packet size. The actual limit is further reduced\n\
13518 dependent on the target. Specify ``fixed'' to disable the\n\
13519 further restriction and ``limit'' to enable that restriction."),
13520 &remote_set_cmdlist
);
13521 add_cmd ("memory-read-packet-size", no_class
,
13522 set_memory_read_packet_size
, _("\
13523 Set the maximum number of bytes per memory-read packet.\n\
13524 Specify the number of bytes in a packet or 0 (zero) for the\n\
13525 default packet size. The actual limit is further reduced\n\
13526 dependent on the target. Specify ``fixed'' to disable the\n\
13527 further restriction and ``limit'' to enable that restriction."),
13528 &remote_set_cmdlist
);
13529 add_cmd ("memory-write-packet-size", no_class
,
13530 show_memory_write_packet_size
,
13531 _("Show the maximum number of bytes per memory-write packet."),
13532 &remote_show_cmdlist
);
13533 add_cmd ("memory-read-packet-size", no_class
,
13534 show_memory_read_packet_size
,
13535 _("Show the maximum number of bytes per memory-read packet."),
13536 &remote_show_cmdlist
);
13538 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13539 &remote_hw_watchpoint_limit
, _("\
13540 Set the maximum number of target hardware watchpoints."), _("\
13541 Show the maximum number of target hardware watchpoints."), _("\
13542 Specify a negative limit for unlimited."),
13543 NULL
, NULL
, /* FIXME: i18n: The maximum
13544 number of target hardware
13545 watchpoints is %s. */
13546 &remote_set_cmdlist
, &remote_show_cmdlist
);
13547 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13548 &remote_hw_watchpoint_length_limit
, _("\
13549 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13550 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13551 Specify a negative limit for unlimited."),
13552 NULL
, NULL
, /* FIXME: i18n: The maximum
13553 length (in bytes) of a target
13554 hardware watchpoint is %s. */
13555 &remote_set_cmdlist
, &remote_show_cmdlist
);
13556 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13557 &remote_hw_breakpoint_limit
, _("\
13558 Set the maximum number of target hardware breakpoints."), _("\
13559 Show the maximum number of target hardware breakpoints."), _("\
13560 Specify a negative limit for unlimited."),
13561 NULL
, NULL
, /* FIXME: i18n: The maximum
13562 number of target hardware
13563 breakpoints is %s. */
13564 &remote_set_cmdlist
, &remote_show_cmdlist
);
13566 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13567 &remote_address_size
, _("\
13568 Set the maximum size of the address (in bits) in a memory packet."), _("\
13569 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13571 NULL
, /* FIXME: i18n: */
13572 &setlist
, &showlist
);
13574 init_all_packet_configs ();
13576 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13577 "X", "binary-download", 1);
13579 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13580 "vCont", "verbose-resume", 0);
13582 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13583 "QPassSignals", "pass-signals", 0);
13585 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
13586 "QCatchSyscalls", "catch-syscalls", 0);
13588 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13589 "QProgramSignals", "program-signals", 0);
13591 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13592 "qSymbol", "symbol-lookup", 0);
13594 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13595 "P", "set-register", 1);
13597 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13598 "p", "fetch-register", 1);
13600 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13601 "Z0", "software-breakpoint", 0);
13603 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13604 "Z1", "hardware-breakpoint", 0);
13606 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13607 "Z2", "write-watchpoint", 0);
13609 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13610 "Z3", "read-watchpoint", 0);
13612 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13613 "Z4", "access-watchpoint", 0);
13615 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13616 "qXfer:auxv:read", "read-aux-vector", 0);
13618 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13619 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13621 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13622 "qXfer:features:read", "target-features", 0);
13624 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13625 "qXfer:libraries:read", "library-info", 0);
13627 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13628 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13630 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13631 "qXfer:memory-map:read", "memory-map", 0);
13633 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13634 "qXfer:spu:read", "read-spu-object", 0);
13636 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13637 "qXfer:spu:write", "write-spu-object", 0);
13639 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13640 "qXfer:osdata:read", "osdata", 0);
13642 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13643 "qXfer:threads:read", "threads", 0);
13645 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13646 "qXfer:siginfo:read", "read-siginfo-object", 0);
13648 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13649 "qXfer:siginfo:write", "write-siginfo-object", 0);
13651 add_packet_config_cmd
13652 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13653 "qXfer:traceframe-info:read", "traceframe-info", 0);
13655 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13656 "qXfer:uib:read", "unwind-info-block", 0);
13658 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13659 "qGetTLSAddr", "get-thread-local-storage-address",
13662 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13663 "qGetTIBAddr", "get-thread-information-block-address",
13666 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13667 "bc", "reverse-continue", 0);
13669 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13670 "bs", "reverse-step", 0);
13672 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13673 "qSupported", "supported-packets", 0);
13675 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13676 "qSearch:memory", "search-memory", 0);
13678 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13679 "qTStatus", "trace-status", 0);
13681 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13682 "vFile:setfs", "hostio-setfs", 0);
13684 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13685 "vFile:open", "hostio-open", 0);
13687 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13688 "vFile:pread", "hostio-pread", 0);
13690 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13691 "vFile:pwrite", "hostio-pwrite", 0);
13693 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13694 "vFile:close", "hostio-close", 0);
13696 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13697 "vFile:unlink", "hostio-unlink", 0);
13699 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13700 "vFile:readlink", "hostio-readlink", 0);
13702 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13703 "vFile:fstat", "hostio-fstat", 0);
13705 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13706 "vAttach", "attach", 0);
13708 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13711 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13712 "QStartNoAckMode", "noack", 0);
13714 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13715 "vKill", "kill", 0);
13717 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13718 "qAttached", "query-attached", 0);
13720 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13721 "ConditionalTracepoints",
13722 "conditional-tracepoints", 0);
13724 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13725 "ConditionalBreakpoints",
13726 "conditional-breakpoints", 0);
13728 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13729 "BreakpointCommands",
13730 "breakpoint-commands", 0);
13732 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13733 "FastTracepoints", "fast-tracepoints", 0);
13735 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13736 "TracepointSource", "TracepointSource", 0);
13738 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13739 "QAllow", "allow", 0);
13741 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13742 "StaticTracepoints", "static-tracepoints", 0);
13744 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13745 "InstallInTrace", "install-in-trace", 0);
13747 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13748 "qXfer:statictrace:read", "read-sdata-object", 0);
13750 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13751 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13753 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13754 "QDisableRandomization", "disable-randomization", 0);
13756 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13757 "QAgent", "agent", 0);
13759 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13760 "QTBuffer:size", "trace-buffer-size", 0);
13762 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13763 "Qbtrace:off", "disable-btrace", 0);
13765 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13766 "Qbtrace:bts", "enable-btrace-bts", 0);
13768 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13769 "Qbtrace:pt", "enable-btrace-pt", 0);
13771 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13772 "qXfer:btrace", "read-btrace", 0);
13774 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13775 "qXfer:btrace-conf", "read-btrace-conf", 0);
13777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13778 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13780 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13781 "multiprocess-feature", "multiprocess-feature", 0);
13783 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13784 "swbreak-feature", "swbreak-feature", 0);
13786 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13787 "hwbreak-feature", "hwbreak-feature", 0);
13789 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13790 "fork-event-feature", "fork-event-feature", 0);
13792 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13793 "vfork-event-feature", "vfork-event-feature", 0);
13795 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13796 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13798 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13799 "vContSupported", "verbose-resume-supported", 0);
13801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13802 "exec-event-feature", "exec-event-feature", 0);
13804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
13805 "vCtrlC", "ctrl-c", 0);
13807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
13808 "QThreadEvents", "thread-events", 0);
13810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
13811 "N stop reply", "no-resumed-stop-reply", 0);
13813 /* Assert that we've registered "set remote foo-packet" commands
13814 for all packet configs. */
13818 for (i
= 0; i
< PACKET_MAX
; i
++)
13820 /* Ideally all configs would have a command associated. Some
13821 still don't though. */
13826 case PACKET_QNonStop
:
13827 case PACKET_EnableDisableTracepoints_feature
:
13828 case PACKET_tracenz_feature
:
13829 case PACKET_DisconnectedTracing_feature
:
13830 case PACKET_augmented_libraries_svr4_read_feature
:
13832 /* Additions to this list need to be well justified:
13833 pre-existing packets are OK; new packets are not. */
13841 /* This catches both forgetting to add a config command, and
13842 forgetting to remove a packet from the exception list. */
13843 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13847 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13848 Z sub-packet has its own set and show commands, but users may
13849 have sets to this variable in their .gdbinit files (or in their
13851 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13852 &remote_Z_packet_detect
, _("\
13853 Set use of remote protocol `Z' packets"), _("\
13854 Show use of remote protocol `Z' packets "), _("\
13855 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13857 set_remote_protocol_Z_packet_cmd
,
13858 show_remote_protocol_Z_packet_cmd
,
13859 /* FIXME: i18n: Use of remote protocol
13860 `Z' packets is %s. */
13861 &remote_set_cmdlist
, &remote_show_cmdlist
);
13863 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13864 Manipulate files on the remote system\n\
13865 Transfer files to and from the remote target system."),
13866 &remote_cmdlist
, "remote ",
13867 0 /* allow-unknown */, &cmdlist
);
13869 add_cmd ("put", class_files
, remote_put_command
,
13870 _("Copy a local file to the remote system."),
13873 add_cmd ("get", class_files
, remote_get_command
,
13874 _("Copy a remote file to the local system."),
13877 add_cmd ("delete", class_files
, remote_delete_command
,
13878 _("Delete a remote file."),
13881 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13882 &remote_exec_file_var
, _("\
13883 Set the remote pathname for \"run\""), _("\
13884 Show the remote pathname for \"run\""), NULL
,
13885 set_remote_exec_file
,
13886 show_remote_exec_file
,
13887 &remote_set_cmdlist
,
13888 &remote_show_cmdlist
);
13890 add_setshow_boolean_cmd ("range-stepping", class_run
,
13891 &use_range_stepping
, _("\
13892 Enable or disable range stepping."), _("\
13893 Show whether target-assisted range stepping is enabled."), _("\
13894 If on, and the target supports it, when stepping a source line, GDB\n\
13895 tells the target to step the corresponding range of addresses itself instead\n\
13896 of issuing multiple single-steps. This speeds up source level\n\
13897 stepping. If off, GDB always issues single-steps, even if range\n\
13898 stepping is supported by the target. The default is on."),
13899 set_range_stepping
,
13900 show_range_stepping
,
13904 /* Eventually initialize fileio. See fileio.c */
13905 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13907 /* Take advantage of the fact that the TID field is not used, to tag
13908 special ptids with it set to != 0. */
13909 magic_null_ptid
= ptid_build (42000, -1, 1);
13910 not_sent_ptid
= ptid_build (42000, -2, 1);
13911 any_thread_ptid
= ptid_build (42000, 0, 1);
13913 target_buf_size
= 2048;
13914 target_buf
= (char *) xmalloc (target_buf_size
);