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 /* The execution direction of the last resume we got. */
397 enum exec_direction_kind last_resume_exec_dir
;
399 char *finished_object
;
400 char *finished_annex
;
401 ULONGEST finished_offset
;
403 /* Should we try the 'ThreadInfo' query packet?
405 This variable (NOT available to the user: auto-detect only!)
406 determines whether GDB will use the new, simpler "ThreadInfo"
407 query or the older, more complex syntax for thread queries.
408 This is an auto-detect variable (set to true at each connect,
409 and set to false when the target fails to recognize it). */
410 int use_threadinfo_query
;
411 int use_threadextra_query
;
413 threadref echo_nextthread
;
414 threadref nextthread
;
415 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
417 /* The state of remote notification. */
418 struct remote_notif_state
*notif_state
;
420 /* The branch trace configuration. */
421 struct btrace_config btrace_config
;
423 /* The argument to the last "vFile:setfs:" packet we sent, used
424 to avoid sending repeated unnecessary "vFile:setfs:" packets.
425 Initialized to -1 to indicate that no "vFile:setfs:" packet
426 has yet been sent. */
429 /* A readahead cache for vFile:pread. Often, reading a binary
430 involves a sequence of small reads. E.g., when parsing an ELF
431 file. A readahead cache helps mostly the case of remote
432 debugging on a connection with higher latency, due to the
433 request/reply nature of the RSP. We only cache data for a single
434 file descriptor at a time. */
435 struct readahead_cache readahead_cache
;
438 /* Private data that we'll store in (struct thread_info)->private. */
439 struct private_thread_info
445 /* Whether the target stopped for a breakpoint/watchpoint. */
446 enum target_stop_reason stop_reason
;
448 /* This is set to the data address of the access causing the target
449 to stop for a watchpoint. */
450 CORE_ADDR watch_data_address
;
454 free_private_thread_info (struct private_thread_info
*info
)
461 /* This data could be associated with a target, but we do not always
462 have access to the current target when we need it, so for now it is
463 static. This will be fine for as long as only one target is in use
465 static struct remote_state
*remote_state
;
467 static struct remote_state
*
468 get_remote_state_raw (void)
473 /* Allocate a new struct remote_state with xmalloc, initialize it, and
476 static struct remote_state
*
477 new_remote_state (void)
479 struct remote_state
*result
= XCNEW (struct remote_state
);
481 /* The default buffer size is unimportant; it will be expanded
482 whenever a larger buffer is needed. */
483 result
->buf_size
= 400;
484 result
->buf
= (char *) xmalloc (result
->buf_size
);
485 result
->remote_traceframe_number
= -1;
486 result
->last_sent_signal
= GDB_SIGNAL_0
;
487 result
->last_resume_exec_dir
= EXEC_FORWARD
;
493 /* Description of the remote protocol for a given architecture. */
497 long offset
; /* Offset into G packet. */
498 long regnum
; /* GDB's internal register number. */
499 LONGEST pnum
; /* Remote protocol register number. */
500 int in_g_packet
; /* Always part of G packet. */
501 /* long size in bytes; == register_size (target_gdbarch (), regnum);
503 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
507 struct remote_arch_state
509 /* Description of the remote protocol registers. */
510 long sizeof_g_packet
;
512 /* Description of the remote protocol registers indexed by REGNUM
513 (making an array gdbarch_num_regs in size). */
514 struct packet_reg
*regs
;
516 /* This is the size (in chars) of the first response to the ``g''
517 packet. It is used as a heuristic when determining the maximum
518 size of memory-read and memory-write packets. A target will
519 typically only reserve a buffer large enough to hold the ``g''
520 packet. The size does not include packet overhead (headers and
522 long actual_register_packet_size
;
524 /* This is the maximum size (in chars) of a non read/write packet.
525 It is also used as a cap on the size of read/write packets. */
526 long remote_packet_size
;
529 /* Utility: generate error from an incoming stub packet. */
531 trace_error (char *buf
)
534 return; /* not an error msg */
537 case '1': /* malformed packet error */
538 if (*++buf
== '0') /* general case: */
539 error (_("remote.c: error in outgoing packet."));
541 error (_("remote.c: error in outgoing packet at field #%ld."),
542 strtol (buf
, NULL
, 16));
544 error (_("Target returns error code '%s'."), buf
);
548 /* Utility: wait for reply from stub, while accepting "O" packets. */
550 remote_get_noisy_reply (char **buf_p
,
553 do /* Loop on reply from remote stub. */
557 QUIT
; /* Allow user to bail out with ^C. */
558 getpkt (buf_p
, sizeof_buf
, 0);
562 else if (startswith (buf
, "qRelocInsn:"))
565 CORE_ADDR from
, to
, org_to
;
567 int adjusted_size
= 0;
570 p
= buf
+ strlen ("qRelocInsn:");
571 pp
= unpack_varlen_hex (p
, &ul
);
573 error (_("invalid qRelocInsn packet: %s"), buf
);
577 unpack_varlen_hex (p
, &ul
);
584 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
587 CATCH (ex
, RETURN_MASK_ALL
)
589 if (ex
.error
== MEMORY_ERROR
)
591 /* Propagate memory errors silently back to the
592 target. The stub may have limited the range of
593 addresses we can write to, for example. */
597 /* Something unexpectedly bad happened. Be verbose
598 so we can tell what, and propagate the error back
599 to the stub, so it doesn't get stuck waiting for
601 exception_fprintf (gdb_stderr
, ex
,
602 _("warning: relocating instruction: "));
610 adjusted_size
= to
- org_to
;
612 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
616 else if (buf
[0] == 'O' && buf
[1] != 'K')
617 remote_console_output (buf
+ 1); /* 'O' message from stub */
619 return buf
; /* Here's the actual reply. */
624 /* Handle for retreving the remote protocol data from gdbarch. */
625 static struct gdbarch_data
*remote_gdbarch_data_handle
;
627 static struct remote_arch_state
*
628 get_remote_arch_state (void)
630 gdb_assert (target_gdbarch () != NULL
);
631 return ((struct remote_arch_state
*)
632 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
635 /* Fetch the global remote target state. */
637 static struct remote_state
*
638 get_remote_state (void)
640 /* Make sure that the remote architecture state has been
641 initialized, because doing so might reallocate rs->buf. Any
642 function which calls getpkt also needs to be mindful of changes
643 to rs->buf, but this call limits the number of places which run
645 get_remote_arch_state ();
647 return get_remote_state_raw ();
650 /* Cleanup routine for the remote module's pspace data. */
653 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
655 char *remote_exec_file
= (char *) arg
;
657 xfree (remote_exec_file
);
660 /* Fetch the remote exec-file from the current program space. */
663 get_remote_exec_file (void)
665 char *remote_exec_file
;
668 = (char *) program_space_data (current_program_space
,
670 if (remote_exec_file
== NULL
)
673 return remote_exec_file
;
676 /* Set the remote exec file for PSPACE. */
679 set_pspace_remote_exec_file (struct program_space
*pspace
,
680 char *remote_exec_file
)
682 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
685 set_program_space_data (pspace
, remote_pspace_data
,
686 xstrdup (remote_exec_file
));
689 /* The "set/show remote exec-file" set command hook. */
692 set_remote_exec_file (char *ignored
, int from_tty
,
693 struct cmd_list_element
*c
)
695 gdb_assert (remote_exec_file_var
!= NULL
);
696 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
699 /* The "set/show remote exec-file" show command hook. */
702 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
703 struct cmd_list_element
*cmd
, const char *value
)
705 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
709 compare_pnums (const void *lhs_
, const void *rhs_
)
711 const struct packet_reg
* const *lhs
712 = (const struct packet_reg
* const *) lhs_
;
713 const struct packet_reg
* const *rhs
714 = (const struct packet_reg
* const *) rhs_
;
716 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
718 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
725 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
727 int regnum
, num_remote_regs
, offset
;
728 struct packet_reg
**remote_regs
;
730 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
732 struct packet_reg
*r
= ®s
[regnum
];
734 if (register_size (gdbarch
, regnum
) == 0)
735 /* Do not try to fetch zero-sized (placeholder) registers. */
738 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
743 /* Define the g/G packet format as the contents of each register
744 with a remote protocol number, in order of ascending protocol
747 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
748 for (num_remote_regs
= 0, regnum
= 0;
749 regnum
< gdbarch_num_regs (gdbarch
);
751 if (regs
[regnum
].pnum
!= -1)
752 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
754 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
757 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
759 remote_regs
[regnum
]->in_g_packet
= 1;
760 remote_regs
[regnum
]->offset
= offset
;
761 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
767 /* Given the architecture described by GDBARCH, return the remote
768 protocol register's number and the register's offset in the g/G
769 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
770 If the target does not have a mapping for REGNUM, return false,
771 otherwise, return true. */
774 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
775 int *pnum
, int *poffset
)
777 struct packet_reg
*regs
;
778 struct cleanup
*old_chain
;
780 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
782 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
783 old_chain
= make_cleanup (xfree
, regs
);
785 map_regcache_remote_table (gdbarch
, regs
);
787 *pnum
= regs
[regnum
].pnum
;
788 *poffset
= regs
[regnum
].offset
;
790 do_cleanups (old_chain
);
796 init_remote_state (struct gdbarch
*gdbarch
)
798 struct remote_state
*rs
= get_remote_state_raw ();
799 struct remote_arch_state
*rsa
;
801 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
803 /* Use the architecture to build a regnum<->pnum table, which will be
804 1:1 unless a feature set specifies otherwise. */
805 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
806 gdbarch_num_regs (gdbarch
),
809 /* Record the maximum possible size of the g packet - it may turn out
811 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
813 /* Default maximum number of characters in a packet body. Many
814 remote stubs have a hardwired buffer size of 400 bytes
815 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
816 as the maximum packet-size to ensure that the packet and an extra
817 NUL character can always fit in the buffer. This stops GDB
818 trashing stubs that try to squeeze an extra NUL into what is
819 already a full buffer (As of 1999-12-04 that was most stubs). */
820 rsa
->remote_packet_size
= 400 - 1;
822 /* This one is filled in when a ``g'' packet is received. */
823 rsa
->actual_register_packet_size
= 0;
825 /* Should rsa->sizeof_g_packet needs more space than the
826 default, adjust the size accordingly. Remember that each byte is
827 encoded as two characters. 32 is the overhead for the packet
828 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
829 (``$NN:G...#NN'') is a better guess, the below has been padded a
831 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
832 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
834 /* Make sure that the packet buffer is plenty big enough for
835 this architecture. */
836 if (rs
->buf_size
< rsa
->remote_packet_size
)
838 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
839 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
845 /* Return the current allowed size of a remote packet. This is
846 inferred from the current architecture, and should be used to
847 limit the length of outgoing packets. */
849 get_remote_packet_size (void)
851 struct remote_state
*rs
= get_remote_state ();
852 struct remote_arch_state
*rsa
= get_remote_arch_state ();
854 if (rs
->explicit_packet_size
)
855 return rs
->explicit_packet_size
;
857 return rsa
->remote_packet_size
;
860 static struct packet_reg
*
861 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
863 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
867 struct packet_reg
*r
= &rsa
->regs
[regnum
];
869 gdb_assert (r
->regnum
== regnum
);
874 static struct packet_reg
*
875 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
879 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
881 struct packet_reg
*r
= &rsa
->regs
[i
];
889 static struct target_ops remote_ops
;
891 static struct target_ops extended_remote_ops
;
893 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
894 ``forever'' still use the normal timeout mechanism. This is
895 currently used by the ASYNC code to guarentee that target reads
896 during the initial connect always time-out. Once getpkt has been
897 modified to return a timeout indication and, in turn
898 remote_wait()/wait_for_inferior() have gained a timeout parameter
900 static int wait_forever_enabled_p
= 1;
902 /* Allow the user to specify what sequence to send to the remote
903 when he requests a program interruption: Although ^C is usually
904 what remote systems expect (this is the default, here), it is
905 sometimes preferable to send a break. On other systems such
906 as the Linux kernel, a break followed by g, which is Magic SysRq g
907 is required in order to interrupt the execution. */
908 const char interrupt_sequence_control_c
[] = "Ctrl-C";
909 const char interrupt_sequence_break
[] = "BREAK";
910 const char interrupt_sequence_break_g
[] = "BREAK-g";
911 static const char *const interrupt_sequence_modes
[] =
913 interrupt_sequence_control_c
,
914 interrupt_sequence_break
,
915 interrupt_sequence_break_g
,
918 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
921 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
922 struct cmd_list_element
*c
,
925 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
926 fprintf_filtered (file
,
927 _("Send the ASCII ETX character (Ctrl-c) "
928 "to the remote target to interrupt the "
929 "execution of the program.\n"));
930 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
931 fprintf_filtered (file
,
932 _("send a break signal to the remote target "
933 "to interrupt the execution of the program.\n"));
934 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
935 fprintf_filtered (file
,
936 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
937 "the remote target to interrupt the execution "
938 "of Linux kernel.\n"));
940 internal_error (__FILE__
, __LINE__
,
941 _("Invalid value for interrupt_sequence_mode: %s."),
942 interrupt_sequence_mode
);
945 /* This boolean variable specifies whether interrupt_sequence is sent
946 to the remote target when gdb connects to it.
947 This is mostly needed when you debug the Linux kernel: The Linux kernel
948 expects BREAK g which is Magic SysRq g for connecting gdb. */
949 static int interrupt_on_connect
= 0;
951 /* This variable is used to implement the "set/show remotebreak" commands.
952 Since these commands are now deprecated in favor of "set/show remote
953 interrupt-sequence", it no longer has any effect on the code. */
954 static int remote_break
;
957 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
960 interrupt_sequence_mode
= interrupt_sequence_break
;
962 interrupt_sequence_mode
= interrupt_sequence_control_c
;
966 show_remotebreak (struct ui_file
*file
, int from_tty
,
967 struct cmd_list_element
*c
,
972 /* This variable sets the number of bits in an address that are to be
973 sent in a memory ("M" or "m") packet. Normally, after stripping
974 leading zeros, the entire address would be sent. This variable
975 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
976 initial implementation of remote.c restricted the address sent in
977 memory packets to ``host::sizeof long'' bytes - (typically 32
978 bits). Consequently, for 64 bit targets, the upper 32 bits of an
979 address was never sent. Since fixing this bug may cause a break in
980 some remote targets this variable is principly provided to
981 facilitate backward compatibility. */
983 static unsigned int remote_address_size
;
985 /* Temporary to track who currently owns the terminal. See
986 remote_terminal_* for more details. */
988 static int remote_async_terminal_ours_p
;
991 /* User configurable variables for the number of characters in a
992 memory read/write packet. MIN (rsa->remote_packet_size,
993 rsa->sizeof_g_packet) is the default. Some targets need smaller
994 values (fifo overruns, et.al.) and some users need larger values
995 (speed up transfers). The variables ``preferred_*'' (the user
996 request), ``current_*'' (what was actually set) and ``forced_*''
997 (Positive - a soft limit, negative - a hard limit). */
999 struct memory_packet_config
1006 /* The default max memory-write-packet-size. The 16k is historical.
1007 (It came from older GDB's using alloca for buffers and the
1008 knowledge (folklore?) that some hosts don't cope very well with
1009 large alloca calls.) */
1010 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1012 /* The minimum remote packet size for memory transfers. Ensures we
1013 can write at least one byte. */
1014 #define MIN_MEMORY_PACKET_SIZE 20
1016 /* Compute the current size of a read/write packet. Since this makes
1017 use of ``actual_register_packet_size'' the computation is dynamic. */
1020 get_memory_packet_size (struct memory_packet_config
*config
)
1022 struct remote_state
*rs
= get_remote_state ();
1023 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1026 if (config
->fixed_p
)
1028 if (config
->size
<= 0)
1029 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1031 what_they_get
= config
->size
;
1035 what_they_get
= get_remote_packet_size ();
1036 /* Limit the packet to the size specified by the user. */
1037 if (config
->size
> 0
1038 && what_they_get
> config
->size
)
1039 what_they_get
= config
->size
;
1041 /* Limit it to the size of the targets ``g'' response unless we have
1042 permission from the stub to use a larger packet size. */
1043 if (rs
->explicit_packet_size
== 0
1044 && rsa
->actual_register_packet_size
> 0
1045 && what_they_get
> rsa
->actual_register_packet_size
)
1046 what_they_get
= rsa
->actual_register_packet_size
;
1048 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1049 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1051 /* Make sure there is room in the global buffer for this packet
1052 (including its trailing NUL byte). */
1053 if (rs
->buf_size
< what_they_get
+ 1)
1055 rs
->buf_size
= 2 * what_they_get
;
1056 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1059 return what_they_get
;
1062 /* Update the size of a read/write packet. If they user wants
1063 something really big then do a sanity check. */
1066 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1068 int fixed_p
= config
->fixed_p
;
1069 long size
= config
->size
;
1072 error (_("Argument required (integer, `fixed' or `limited')."));
1073 else if (strcmp (args
, "hard") == 0
1074 || strcmp (args
, "fixed") == 0)
1076 else if (strcmp (args
, "soft") == 0
1077 || strcmp (args
, "limit") == 0)
1083 size
= strtoul (args
, &end
, 0);
1085 error (_("Invalid %s (bad syntax)."), config
->name
);
1087 /* Instead of explicitly capping the size of a packet to or
1088 disallowing it, the user is allowed to set the size to
1089 something arbitrarily large. */
1092 /* So that the query shows the correct value. */
1094 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1097 if (fixed_p
&& !config
->fixed_p
)
1099 if (! query (_("The target may not be able to correctly handle a %s\n"
1100 "of %ld bytes. Change the packet size? "),
1101 config
->name
, size
))
1102 error (_("Packet size not changed."));
1104 /* Update the config. */
1105 config
->fixed_p
= fixed_p
;
1106 config
->size
= size
;
1110 show_memory_packet_size (struct memory_packet_config
*config
)
1112 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1113 if (config
->fixed_p
)
1114 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1115 get_memory_packet_size (config
));
1117 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1118 get_memory_packet_size (config
));
1121 static struct memory_packet_config memory_write_packet_config
=
1123 "memory-write-packet-size",
1127 set_memory_write_packet_size (char *args
, int from_tty
)
1129 set_memory_packet_size (args
, &memory_write_packet_config
);
1133 show_memory_write_packet_size (char *args
, int from_tty
)
1135 show_memory_packet_size (&memory_write_packet_config
);
1139 get_memory_write_packet_size (void)
1141 return get_memory_packet_size (&memory_write_packet_config
);
1144 static struct memory_packet_config memory_read_packet_config
=
1146 "memory-read-packet-size",
1150 set_memory_read_packet_size (char *args
, int from_tty
)
1152 set_memory_packet_size (args
, &memory_read_packet_config
);
1156 show_memory_read_packet_size (char *args
, int from_tty
)
1158 show_memory_packet_size (&memory_read_packet_config
);
1162 get_memory_read_packet_size (void)
1164 long size
= get_memory_packet_size (&memory_read_packet_config
);
1166 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1167 extra buffer size argument before the memory read size can be
1168 increased beyond this. */
1169 if (size
> get_remote_packet_size ())
1170 size
= get_remote_packet_size ();
1175 /* Generic configuration support for packets the stub optionally
1176 supports. Allows the user to specify the use of the packet as well
1177 as allowing GDB to auto-detect support in the remote stub. */
1181 PACKET_SUPPORT_UNKNOWN
= 0,
1186 struct packet_config
1191 /* If auto, GDB auto-detects support for this packet or feature,
1192 either through qSupported, or by trying the packet and looking
1193 at the response. If true, GDB assumes the target supports this
1194 packet. If false, the packet is disabled. Configs that don't
1195 have an associated command always have this set to auto. */
1196 enum auto_boolean detect
;
1198 /* Does the target support this packet? */
1199 enum packet_support support
;
1202 /* Analyze a packet's return value and update the packet config
1212 static enum packet_support
packet_config_support (struct packet_config
*config
);
1213 static enum packet_support
packet_support (int packet
);
1216 show_packet_config_cmd (struct packet_config
*config
)
1218 char *support
= "internal-error";
1220 switch (packet_config_support (config
))
1223 support
= "enabled";
1225 case PACKET_DISABLE
:
1226 support
= "disabled";
1228 case PACKET_SUPPORT_UNKNOWN
:
1229 support
= "unknown";
1232 switch (config
->detect
)
1234 case AUTO_BOOLEAN_AUTO
:
1235 printf_filtered (_("Support for the `%s' packet "
1236 "is auto-detected, currently %s.\n"),
1237 config
->name
, support
);
1239 case AUTO_BOOLEAN_TRUE
:
1240 case AUTO_BOOLEAN_FALSE
:
1241 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1242 config
->name
, support
);
1248 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1249 const char *title
, int legacy
)
1255 config
->name
= name
;
1256 config
->title
= title
;
1257 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1259 show_doc
= xstrprintf ("Show current use of remote "
1260 "protocol `%s' (%s) packet",
1262 /* set/show TITLE-packet {auto,on,off} */
1263 cmd_name
= xstrprintf ("%s-packet", title
);
1264 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1265 &config
->detect
, set_doc
,
1266 show_doc
, NULL
, /* help_doc */
1268 show_remote_protocol_packet_cmd
,
1269 &remote_set_cmdlist
, &remote_show_cmdlist
);
1270 /* The command code copies the documentation strings. */
1273 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1278 legacy_name
= xstrprintf ("%s-packet", name
);
1279 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1280 &remote_set_cmdlist
);
1281 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1282 &remote_show_cmdlist
);
1286 static enum packet_result
1287 packet_check_result (const char *buf
)
1291 /* The stub recognized the packet request. Check that the
1292 operation succeeded. */
1294 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1296 /* "Enn" - definitly an error. */
1297 return PACKET_ERROR
;
1299 /* Always treat "E." as an error. This will be used for
1300 more verbose error messages, such as E.memtypes. */
1301 if (buf
[0] == 'E' && buf
[1] == '.')
1302 return PACKET_ERROR
;
1304 /* The packet may or may not be OK. Just assume it is. */
1308 /* The stub does not support the packet. */
1309 return PACKET_UNKNOWN
;
1312 static enum packet_result
1313 packet_ok (const char *buf
, struct packet_config
*config
)
1315 enum packet_result result
;
1317 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1318 && config
->support
== PACKET_DISABLE
)
1319 internal_error (__FILE__
, __LINE__
,
1320 _("packet_ok: attempt to use a disabled packet"));
1322 result
= packet_check_result (buf
);
1327 /* The stub recognized the packet request. */
1328 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1331 fprintf_unfiltered (gdb_stdlog
,
1332 "Packet %s (%s) is supported\n",
1333 config
->name
, config
->title
);
1334 config
->support
= PACKET_ENABLE
;
1337 case PACKET_UNKNOWN
:
1338 /* The stub does not support the packet. */
1339 if (config
->detect
== AUTO_BOOLEAN_AUTO
1340 && config
->support
== PACKET_ENABLE
)
1342 /* If the stub previously indicated that the packet was
1343 supported then there is a protocol error. */
1344 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1345 config
->name
, config
->title
);
1347 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1349 /* The user set it wrong. */
1350 error (_("Enabled packet %s (%s) not recognized by stub"),
1351 config
->name
, config
->title
);
1355 fprintf_unfiltered (gdb_stdlog
,
1356 "Packet %s (%s) is NOT supported\n",
1357 config
->name
, config
->title
);
1358 config
->support
= PACKET_DISABLE
;
1379 PACKET_vFile_pwrite
,
1381 PACKET_vFile_unlink
,
1382 PACKET_vFile_readlink
,
1385 PACKET_qXfer_features
,
1386 PACKET_qXfer_exec_file
,
1387 PACKET_qXfer_libraries
,
1388 PACKET_qXfer_libraries_svr4
,
1389 PACKET_qXfer_memory_map
,
1390 PACKET_qXfer_spu_read
,
1391 PACKET_qXfer_spu_write
,
1392 PACKET_qXfer_osdata
,
1393 PACKET_qXfer_threads
,
1394 PACKET_qXfer_statictrace_read
,
1395 PACKET_qXfer_traceframe_info
,
1401 PACKET_QPassSignals
,
1402 PACKET_QCatchSyscalls
,
1403 PACKET_QProgramSignals
,
1405 PACKET_qSearch_memory
,
1408 PACKET_QStartNoAckMode
,
1410 PACKET_qXfer_siginfo_read
,
1411 PACKET_qXfer_siginfo_write
,
1414 /* Support for conditional tracepoints. */
1415 PACKET_ConditionalTracepoints
,
1417 /* Support for target-side breakpoint conditions. */
1418 PACKET_ConditionalBreakpoints
,
1420 /* Support for target-side breakpoint commands. */
1421 PACKET_BreakpointCommands
,
1423 /* Support for fast tracepoints. */
1424 PACKET_FastTracepoints
,
1426 /* Support for static tracepoints. */
1427 PACKET_StaticTracepoints
,
1429 /* Support for installing tracepoints while a trace experiment is
1431 PACKET_InstallInTrace
,
1435 PACKET_TracepointSource
,
1438 PACKET_QDisableRandomization
,
1440 PACKET_QTBuffer_size
,
1444 PACKET_qXfer_btrace
,
1446 /* Support for the QNonStop packet. */
1449 /* Support for the QThreadEvents packet. */
1450 PACKET_QThreadEvents
,
1452 /* Support for multi-process extensions. */
1453 PACKET_multiprocess_feature
,
1455 /* Support for enabling and disabling tracepoints while a trace
1456 experiment is running. */
1457 PACKET_EnableDisableTracepoints_feature
,
1459 /* Support for collecting strings using the tracenz bytecode. */
1460 PACKET_tracenz_feature
,
1462 /* Support for continuing to run a trace experiment while GDB is
1464 PACKET_DisconnectedTracing_feature
,
1466 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1467 PACKET_augmented_libraries_svr4_read_feature
,
1469 /* Support for the qXfer:btrace-conf:read packet. */
1470 PACKET_qXfer_btrace_conf
,
1472 /* Support for the Qbtrace-conf:bts:size packet. */
1473 PACKET_Qbtrace_conf_bts_size
,
1475 /* Support for swbreak+ feature. */
1476 PACKET_swbreak_feature
,
1478 /* Support for hwbreak+ feature. */
1479 PACKET_hwbreak_feature
,
1481 /* Support for fork events. */
1482 PACKET_fork_event_feature
,
1484 /* Support for vfork events. */
1485 PACKET_vfork_event_feature
,
1487 /* Support for the Qbtrace-conf:pt:size packet. */
1488 PACKET_Qbtrace_conf_pt_size
,
1490 /* Support for exec events. */
1491 PACKET_exec_event_feature
,
1493 /* Support for query supported vCont actions. */
1494 PACKET_vContSupported
,
1496 /* Support remote CTRL-C. */
1499 /* Support TARGET_WAITKIND_NO_RESUMED. */
1505 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1507 /* Returns the packet's corresponding "set remote foo-packet" command
1508 state. See struct packet_config for more details. */
1510 static enum auto_boolean
1511 packet_set_cmd_state (int packet
)
1513 return remote_protocol_packets
[packet
].detect
;
1516 /* Returns whether a given packet or feature is supported. This takes
1517 into account the state of the corresponding "set remote foo-packet"
1518 command, which may be used to bypass auto-detection. */
1520 static enum packet_support
1521 packet_config_support (struct packet_config
*config
)
1523 switch (config
->detect
)
1525 case AUTO_BOOLEAN_TRUE
:
1526 return PACKET_ENABLE
;
1527 case AUTO_BOOLEAN_FALSE
:
1528 return PACKET_DISABLE
;
1529 case AUTO_BOOLEAN_AUTO
:
1530 return config
->support
;
1532 gdb_assert_not_reached (_("bad switch"));
1536 /* Same as packet_config_support, but takes the packet's enum value as
1539 static enum packet_support
1540 packet_support (int packet
)
1542 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1544 return packet_config_support (config
);
1548 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1549 struct cmd_list_element
*c
,
1552 struct packet_config
*packet
;
1554 for (packet
= remote_protocol_packets
;
1555 packet
< &remote_protocol_packets
[PACKET_MAX
];
1558 if (&packet
->detect
== c
->var
)
1560 show_packet_config_cmd (packet
);
1564 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1568 /* Should we try one of the 'Z' requests? */
1572 Z_PACKET_SOFTWARE_BP
,
1573 Z_PACKET_HARDWARE_BP
,
1580 /* For compatibility with older distributions. Provide a ``set remote
1581 Z-packet ...'' command that updates all the Z packet types. */
1583 static enum auto_boolean remote_Z_packet_detect
;
1586 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1587 struct cmd_list_element
*c
)
1591 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1592 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1596 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1597 struct cmd_list_element
*c
,
1602 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1604 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1608 /* Returns true if the multi-process extensions are in effect. */
1611 remote_multi_process_p (struct remote_state
*rs
)
1613 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1616 /* Returns true if fork events are supported. */
1619 remote_fork_event_p (struct remote_state
*rs
)
1621 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1624 /* Returns true if vfork events are supported. */
1627 remote_vfork_event_p (struct remote_state
*rs
)
1629 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1632 /* Returns true if exec events are supported. */
1635 remote_exec_event_p (struct remote_state
*rs
)
1637 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1640 /* Insert fork catchpoint target routine. If fork events are enabled
1641 then return success, nothing more to do. */
1644 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1646 struct remote_state
*rs
= get_remote_state ();
1648 return !remote_fork_event_p (rs
);
1651 /* Remove fork catchpoint target routine. Nothing to do, just
1655 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1660 /* Insert vfork catchpoint target routine. If vfork events are enabled
1661 then return success, nothing more to do. */
1664 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1666 struct remote_state
*rs
= get_remote_state ();
1668 return !remote_vfork_event_p (rs
);
1671 /* Remove vfork catchpoint target routine. Nothing to do, just
1675 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1680 /* Insert exec catchpoint target routine. If exec events are
1681 enabled, just return success. */
1684 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1686 struct remote_state
*rs
= get_remote_state ();
1688 return !remote_exec_event_p (rs
);
1691 /* Remove exec catchpoint target routine. Nothing to do, just
1695 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1701 /* Asynchronous signal handle registered as event loop source for
1702 when we have pending events ready to be passed to the core. */
1704 static struct async_event_handler
*remote_async_inferior_event_token
;
1708 static ptid_t magic_null_ptid
;
1709 static ptid_t not_sent_ptid
;
1710 static ptid_t any_thread_ptid
;
1712 /* Find out if the stub attached to PID (and hence GDB should offer to
1713 detach instead of killing it when bailing out). */
1716 remote_query_attached (int pid
)
1718 struct remote_state
*rs
= get_remote_state ();
1719 size_t size
= get_remote_packet_size ();
1721 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1724 if (remote_multi_process_p (rs
))
1725 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1727 xsnprintf (rs
->buf
, size
, "qAttached");
1730 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1732 switch (packet_ok (rs
->buf
,
1733 &remote_protocol_packets
[PACKET_qAttached
]))
1736 if (strcmp (rs
->buf
, "1") == 0)
1740 warning (_("Remote failure reply: %s"), rs
->buf
);
1742 case PACKET_UNKNOWN
:
1749 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1750 has been invented by GDB, instead of reported by the target. Since
1751 we can be connected to a remote system before before knowing about
1752 any inferior, mark the target with execution when we find the first
1753 inferior. If ATTACHED is 1, then we had just attached to this
1754 inferior. If it is 0, then we just created this inferior. If it
1755 is -1, then try querying the remote stub to find out if it had
1756 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1757 attempt to open this inferior's executable as the main executable
1758 if no main executable is open already. */
1760 static struct inferior
*
1761 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1764 struct inferior
*inf
;
1766 /* Check whether this process we're learning about is to be
1767 considered attached, or if is to be considered to have been
1768 spawned by the stub. */
1770 attached
= remote_query_attached (pid
);
1772 if (gdbarch_has_global_solist (target_gdbarch ()))
1774 /* If the target shares code across all inferiors, then every
1775 attach adds a new inferior. */
1776 inf
= add_inferior (pid
);
1778 /* ... and every inferior is bound to the same program space.
1779 However, each inferior may still have its own address
1781 inf
->aspace
= maybe_new_address_space ();
1782 inf
->pspace
= current_program_space
;
1786 /* In the traditional debugging scenario, there's a 1-1 match
1787 between program/address spaces. We simply bind the inferior
1788 to the program space's address space. */
1789 inf
= current_inferior ();
1790 inferior_appeared (inf
, pid
);
1793 inf
->attach_flag
= attached
;
1794 inf
->fake_pid_p
= fake_pid_p
;
1796 /* If no main executable is currently open then attempt to
1797 open the file that was executed to create this inferior. */
1798 if (try_open_exec
&& get_exec_file (0) == NULL
)
1799 exec_file_locate_attach (pid
, 1);
1804 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1805 according to RUNNING. */
1808 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1810 struct remote_state
*rs
= get_remote_state ();
1812 /* GDB historically didn't pull threads in the initial connection
1813 setup. If the remote target doesn't even have a concept of
1814 threads (e.g., a bare-metal target), even if internally we
1815 consider that a single-threaded target, mentioning a new thread
1816 might be confusing to the user. Be silent then, preserving the
1817 age old behavior. */
1818 if (rs
->starting_up
)
1819 add_thread_silent (ptid
);
1823 set_executing (ptid
, executing
);
1824 set_running (ptid
, running
);
1827 /* Come here when we learn about a thread id from the remote target.
1828 It may be the first time we hear about such thread, so take the
1829 opportunity to add it to GDB's thread list. In case this is the
1830 first time we're noticing its corresponding inferior, add it to
1831 GDB's inferior list as well. EXECUTING indicates whether the
1832 thread is (internally) executing or stopped. */
1835 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1837 /* In non-stop mode, we assume new found threads are (externally)
1838 running until proven otherwise with a stop reply. In all-stop,
1839 we can only get here if all threads are stopped. */
1840 int running
= target_is_non_stop_p () ? 1 : 0;
1842 /* If this is a new thread, add it to GDB's thread list.
1843 If we leave it up to WFI to do this, bad things will happen. */
1845 if (in_thread_list (currthread
) && is_exited (currthread
))
1847 /* We're seeing an event on a thread id we knew had exited.
1848 This has to be a new thread reusing the old id. Add it. */
1849 remote_add_thread (currthread
, running
, executing
);
1853 if (!in_thread_list (currthread
))
1855 struct inferior
*inf
= NULL
;
1856 int pid
= ptid_get_pid (currthread
);
1858 if (ptid_is_pid (inferior_ptid
)
1859 && pid
== ptid_get_pid (inferior_ptid
))
1861 /* inferior_ptid has no thread member yet. This can happen
1862 with the vAttach -> remote_wait,"TAAthread:" path if the
1863 stub doesn't support qC. This is the first stop reported
1864 after an attach, so this is the main thread. Update the
1865 ptid in the thread list. */
1866 if (in_thread_list (pid_to_ptid (pid
)))
1867 thread_change_ptid (inferior_ptid
, currthread
);
1870 remote_add_thread (currthread
, running
, executing
);
1871 inferior_ptid
= currthread
;
1876 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1878 /* inferior_ptid is not set yet. This can happen with the
1879 vRun -> remote_wait,"TAAthread:" path if the stub
1880 doesn't support qC. This is the first stop reported
1881 after an attach, so this is the main thread. Update the
1882 ptid in the thread list. */
1883 thread_change_ptid (inferior_ptid
, currthread
);
1887 /* When connecting to a target remote, or to a target
1888 extended-remote which already was debugging an inferior, we
1889 may not know about it yet. Add it before adding its child
1890 thread, so notifications are emitted in a sensible order. */
1891 if (!in_inferior_list (ptid_get_pid (currthread
)))
1893 struct remote_state
*rs
= get_remote_state ();
1894 int fake_pid_p
= !remote_multi_process_p (rs
);
1896 inf
= remote_add_inferior (fake_pid_p
,
1897 ptid_get_pid (currthread
), -1, 1);
1900 /* This is really a new thread. Add it. */
1901 remote_add_thread (currthread
, running
, executing
);
1903 /* If we found a new inferior, let the common code do whatever
1904 it needs to with it (e.g., read shared libraries, insert
1905 breakpoints), unless we're just setting up an all-stop
1909 struct remote_state
*rs
= get_remote_state ();
1911 if (!rs
->starting_up
)
1912 notice_new_inferior (currthread
, executing
, 0);
1917 /* Return the private thread data, creating it if necessary. */
1919 static struct private_thread_info
*
1920 demand_private_info (ptid_t ptid
)
1922 struct thread_info
*info
= find_thread_ptid (ptid
);
1928 info
->priv
= XNEW (struct private_thread_info
);
1929 info
->private_dtor
= free_private_thread_info
;
1930 info
->priv
->core
= -1;
1931 info
->priv
->extra
= NULL
;
1932 info
->priv
->name
= NULL
;
1938 /* Call this function as a result of
1939 1) A halt indication (T packet) containing a thread id
1940 2) A direct query of currthread
1941 3) Successful execution of set thread */
1944 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1946 rs
->general_thread
= currthread
;
1949 /* If 'QPassSignals' is supported, tell the remote stub what signals
1950 it can simply pass through to the inferior without reporting. */
1953 remote_pass_signals (struct target_ops
*self
,
1954 int numsigs
, unsigned char *pass_signals
)
1956 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1958 char *pass_packet
, *p
;
1960 struct remote_state
*rs
= get_remote_state ();
1962 gdb_assert (numsigs
< 256);
1963 for (i
= 0; i
< numsigs
; i
++)
1965 if (pass_signals
[i
])
1968 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1969 strcpy (pass_packet
, "QPassSignals:");
1970 p
= pass_packet
+ strlen (pass_packet
);
1971 for (i
= 0; i
< numsigs
; i
++)
1973 if (pass_signals
[i
])
1976 *p
++ = tohex (i
>> 4);
1977 *p
++ = tohex (i
& 15);
1986 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1988 putpkt (pass_packet
);
1989 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1990 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1991 if (rs
->last_pass_packet
)
1992 xfree (rs
->last_pass_packet
);
1993 rs
->last_pass_packet
= pass_packet
;
1996 xfree (pass_packet
);
2000 /* If 'QCatchSyscalls' is supported, tell the remote stub
2001 to report syscalls to GDB. */
2004 remote_set_syscall_catchpoint (struct target_ops
*self
,
2005 int pid
, int needed
, int any_count
,
2006 int table_size
, int *table
)
2009 enum packet_result result
;
2012 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2014 /* Not supported. */
2018 if (needed
&& !any_count
)
2022 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2023 for (i
= 0; i
< table_size
; i
++)
2032 fprintf_unfiltered (gdb_stdlog
,
2033 "remote_set_syscall_catchpoint "
2034 "pid %d needed %d any_count %d n_sysno %d\n",
2035 pid
, needed
, any_count
, n_sysno
);
2040 /* Prepare a packet with the sysno list, assuming max 8+1
2041 characters for a sysno. If the resulting packet size is too
2042 big, fallback on the non-selective packet. */
2043 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2045 catch_packet
= (char *) xmalloc (maxpktsz
);
2046 strcpy (catch_packet
, "QCatchSyscalls:1");
2055 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2056 for (i
= 0; i
< table_size
; i
++)
2059 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2062 if (strlen (catch_packet
) > get_remote_packet_size ())
2064 /* catch_packet too big. Fallback to less efficient
2065 non selective mode, with GDB doing the filtering. */
2066 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2070 catch_packet
= xstrdup ("QCatchSyscalls:0");
2073 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2074 struct remote_state
*rs
= get_remote_state ();
2076 putpkt (catch_packet
);
2077 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2078 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2079 do_cleanups (old_chain
);
2080 if (result
== PACKET_OK
)
2087 /* If 'QProgramSignals' is supported, tell the remote stub what
2088 signals it should pass through to the inferior when detaching. */
2091 remote_program_signals (struct target_ops
*self
,
2092 int numsigs
, unsigned char *signals
)
2094 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2098 struct remote_state
*rs
= get_remote_state ();
2100 gdb_assert (numsigs
< 256);
2101 for (i
= 0; i
< numsigs
; i
++)
2106 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2107 strcpy (packet
, "QProgramSignals:");
2108 p
= packet
+ strlen (packet
);
2109 for (i
= 0; i
< numsigs
; i
++)
2111 if (signal_pass_state (i
))
2114 *p
++ = tohex (i
>> 4);
2115 *p
++ = tohex (i
& 15);
2124 if (!rs
->last_program_signals_packet
2125 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2128 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2129 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2130 xfree (rs
->last_program_signals_packet
);
2131 rs
->last_program_signals_packet
= packet
;
2138 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2139 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2140 thread. If GEN is set, set the general thread, if not, then set
2141 the step/continue thread. */
2143 set_thread (struct ptid ptid
, int gen
)
2145 struct remote_state
*rs
= get_remote_state ();
2146 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2147 char *buf
= rs
->buf
;
2148 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2150 if (ptid_equal (state
, ptid
))
2154 *buf
++ = gen
? 'g' : 'c';
2155 if (ptid_equal (ptid
, magic_null_ptid
))
2156 xsnprintf (buf
, endbuf
- buf
, "0");
2157 else if (ptid_equal (ptid
, any_thread_ptid
))
2158 xsnprintf (buf
, endbuf
- buf
, "0");
2159 else if (ptid_equal (ptid
, minus_one_ptid
))
2160 xsnprintf (buf
, endbuf
- buf
, "-1");
2162 write_ptid (buf
, endbuf
, ptid
);
2164 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2166 rs
->general_thread
= ptid
;
2168 rs
->continue_thread
= ptid
;
2172 set_general_thread (struct ptid ptid
)
2174 set_thread (ptid
, 1);
2178 set_continue_thread (struct ptid ptid
)
2180 set_thread (ptid
, 0);
2183 /* Change the remote current process. Which thread within the process
2184 ends up selected isn't important, as long as it is the same process
2185 as what INFERIOR_PTID points to.
2187 This comes from that fact that there is no explicit notion of
2188 "selected process" in the protocol. The selected process for
2189 general operations is the process the selected general thread
2193 set_general_process (void)
2195 struct remote_state
*rs
= get_remote_state ();
2197 /* If the remote can't handle multiple processes, don't bother. */
2198 if (!remote_multi_process_p (rs
))
2201 /* We only need to change the remote current thread if it's pointing
2202 at some other process. */
2203 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2204 set_general_thread (inferior_ptid
);
2208 /* Return nonzero if this is the main thread that we made up ourselves
2209 to model non-threaded targets as single-threaded. */
2212 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2214 if (ptid_equal (ptid
, magic_null_ptid
))
2215 /* The main thread is always alive. */
2218 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2219 /* The main thread is always alive. This can happen after a
2220 vAttach, if the remote side doesn't support
2227 /* Return nonzero if the thread PTID is still alive on the remote
2231 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2233 struct remote_state
*rs
= get_remote_state ();
2236 /* Check if this is a thread that we made up ourselves to model
2237 non-threaded targets as single-threaded. */
2238 if (remote_thread_always_alive (ops
, ptid
))
2242 endp
= rs
->buf
+ get_remote_packet_size ();
2245 write_ptid (p
, endp
, ptid
);
2248 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2249 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2252 /* Return a pointer to a thread name if we know it and NULL otherwise.
2253 The thread_info object owns the memory for the name. */
2256 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2258 if (info
->priv
!= NULL
)
2259 return info
->priv
->name
;
2264 /* About these extended threadlist and threadinfo packets. They are
2265 variable length packets but, the fields within them are often fixed
2266 length. They are redundent enough to send over UDP as is the
2267 remote protocol in general. There is a matching unit test module
2270 /* WARNING: This threadref data structure comes from the remote O.S.,
2271 libstub protocol encoding, and remote.c. It is not particularly
2274 /* Right now, the internal structure is int. We want it to be bigger.
2275 Plan to fix this. */
2277 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2279 /* gdb_ext_thread_info is an internal GDB data structure which is
2280 equivalent to the reply of the remote threadinfo packet. */
2282 struct gdb_ext_thread_info
2284 threadref threadid
; /* External form of thread reference. */
2285 int active
; /* Has state interesting to GDB?
2287 char display
[256]; /* Brief state display, name,
2288 blocked/suspended. */
2289 char shortname
[32]; /* To be used to name threads. */
2290 char more_display
[256]; /* Long info, statistics, queue depth,
2294 /* The volume of remote transfers can be limited by submitting
2295 a mask containing bits specifying the desired information.
2296 Use a union of these values as the 'selection' parameter to
2297 get_thread_info. FIXME: Make these TAG names more thread specific. */
2299 #define TAG_THREADID 1
2300 #define TAG_EXISTS 2
2301 #define TAG_DISPLAY 4
2302 #define TAG_THREADNAME 8
2303 #define TAG_MOREDISPLAY 16
2305 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2307 static char *unpack_nibble (char *buf
, int *val
);
2309 static char *unpack_byte (char *buf
, int *value
);
2311 static char *pack_int (char *buf
, int value
);
2313 static char *unpack_int (char *buf
, int *value
);
2315 static char *unpack_string (char *src
, char *dest
, int length
);
2317 static char *pack_threadid (char *pkt
, threadref
*id
);
2319 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2321 void int_to_threadref (threadref
*id
, int value
);
2323 static int threadref_to_int (threadref
*ref
);
2325 static void copy_threadref (threadref
*dest
, threadref
*src
);
2327 static int threadmatch (threadref
*dest
, threadref
*src
);
2329 static char *pack_threadinfo_request (char *pkt
, int mode
,
2332 static int remote_unpack_thread_info_response (char *pkt
,
2333 threadref
*expectedref
,
2334 struct gdb_ext_thread_info
2338 static int remote_get_threadinfo (threadref
*threadid
,
2339 int fieldset
, /*TAG mask */
2340 struct gdb_ext_thread_info
*info
);
2342 static char *pack_threadlist_request (char *pkt
, int startflag
,
2344 threadref
*nextthread
);
2346 static int parse_threadlist_response (char *pkt
,
2348 threadref
*original_echo
,
2349 threadref
*resultlist
,
2352 static int remote_get_threadlist (int startflag
,
2353 threadref
*nextthread
,
2357 threadref
*threadlist
);
2359 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2361 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2362 void *context
, int looplimit
);
2364 static int remote_newthread_step (threadref
*ref
, void *context
);
2367 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2368 buffer we're allowed to write to. Returns
2369 BUF+CHARACTERS_WRITTEN. */
2372 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2375 struct remote_state
*rs
= get_remote_state ();
2377 if (remote_multi_process_p (rs
))
2379 pid
= ptid_get_pid (ptid
);
2381 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2383 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2385 tid
= ptid_get_lwp (ptid
);
2387 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2389 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2394 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2395 passed the last parsed char. Returns null_ptid on error. */
2398 read_ptid (char *buf
, char **obuf
)
2402 ULONGEST pid
= 0, tid
= 0;
2406 /* Multi-process ptid. */
2407 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2409 error (_("invalid remote ptid: %s"), p
);
2412 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2415 return ptid_build (pid
, tid
, 0);
2418 /* No multi-process. Just a tid. */
2419 pp
= unpack_varlen_hex (p
, &tid
);
2421 /* Return null_ptid when no thread id is found. */
2429 /* Since the stub is not sending a process id, then default to
2430 what's in inferior_ptid, unless it's null at this point. If so,
2431 then since there's no way to know the pid of the reported
2432 threads, use the magic number. */
2433 if (ptid_equal (inferior_ptid
, null_ptid
))
2434 pid
= ptid_get_pid (magic_null_ptid
);
2436 pid
= ptid_get_pid (inferior_ptid
);
2440 return ptid_build (pid
, tid
, 0);
2446 if (ch
>= 'a' && ch
<= 'f')
2447 return ch
- 'a' + 10;
2448 if (ch
>= '0' && ch
<= '9')
2450 if (ch
>= 'A' && ch
<= 'F')
2451 return ch
- 'A' + 10;
2456 stub_unpack_int (char *buff
, int fieldlength
)
2463 nibble
= stubhex (*buff
++);
2467 retval
= retval
<< 4;
2473 unpack_nibble (char *buf
, int *val
)
2475 *val
= fromhex (*buf
++);
2480 unpack_byte (char *buf
, int *value
)
2482 *value
= stub_unpack_int (buf
, 2);
2487 pack_int (char *buf
, int value
)
2489 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2490 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2491 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2492 buf
= pack_hex_byte (buf
, (value
& 0xff));
2497 unpack_int (char *buf
, int *value
)
2499 *value
= stub_unpack_int (buf
, 8);
2503 #if 0 /* Currently unused, uncomment when needed. */
2504 static char *pack_string (char *pkt
, char *string
);
2507 pack_string (char *pkt
, char *string
)
2512 len
= strlen (string
);
2514 len
= 200; /* Bigger than most GDB packets, junk??? */
2515 pkt
= pack_hex_byte (pkt
, len
);
2519 if ((ch
== '\0') || (ch
== '#'))
2520 ch
= '*'; /* Protect encapsulation. */
2525 #endif /* 0 (unused) */
2528 unpack_string (char *src
, char *dest
, int length
)
2537 pack_threadid (char *pkt
, threadref
*id
)
2540 unsigned char *altid
;
2542 altid
= (unsigned char *) id
;
2543 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2545 pkt
= pack_hex_byte (pkt
, *altid
++);
2551 unpack_threadid (char *inbuf
, threadref
*id
)
2554 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2557 altref
= (char *) id
;
2559 while (inbuf
< limit
)
2561 x
= stubhex (*inbuf
++);
2562 y
= stubhex (*inbuf
++);
2563 *altref
++ = (x
<< 4) | y
;
2568 /* Externally, threadrefs are 64 bits but internally, they are still
2569 ints. This is due to a mismatch of specifications. We would like
2570 to use 64bit thread references internally. This is an adapter
2574 int_to_threadref (threadref
*id
, int value
)
2576 unsigned char *scan
;
2578 scan
= (unsigned char *) id
;
2584 *scan
++ = (value
>> 24) & 0xff;
2585 *scan
++ = (value
>> 16) & 0xff;
2586 *scan
++ = (value
>> 8) & 0xff;
2587 *scan
++ = (value
& 0xff);
2591 threadref_to_int (threadref
*ref
)
2594 unsigned char *scan
;
2600 value
= (value
<< 8) | ((*scan
++) & 0xff);
2605 copy_threadref (threadref
*dest
, threadref
*src
)
2608 unsigned char *csrc
, *cdest
;
2610 csrc
= (unsigned char *) src
;
2611 cdest
= (unsigned char *) dest
;
2618 threadmatch (threadref
*dest
, threadref
*src
)
2620 /* Things are broken right now, so just assume we got a match. */
2622 unsigned char *srcp
, *destp
;
2624 srcp
= (char *) src
;
2625 destp
= (char *) dest
;
2629 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2636 threadid:1, # always request threadid
2643 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2646 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2648 *pkt
++ = 'q'; /* Info Query */
2649 *pkt
++ = 'P'; /* process or thread info */
2650 pkt
= pack_int (pkt
, mode
); /* mode */
2651 pkt
= pack_threadid (pkt
, id
); /* threadid */
2652 *pkt
= '\0'; /* terminate */
2656 /* These values tag the fields in a thread info response packet. */
2657 /* Tagging the fields allows us to request specific fields and to
2658 add more fields as time goes by. */
2660 #define TAG_THREADID 1 /* Echo the thread identifier. */
2661 #define TAG_EXISTS 2 /* Is this process defined enough to
2662 fetch registers and its stack? */
2663 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2664 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2665 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2669 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2670 struct gdb_ext_thread_info
*info
)
2672 struct remote_state
*rs
= get_remote_state ();
2676 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2679 /* info->threadid = 0; FIXME: implement zero_threadref. */
2681 info
->display
[0] = '\0';
2682 info
->shortname
[0] = '\0';
2683 info
->more_display
[0] = '\0';
2685 /* Assume the characters indicating the packet type have been
2687 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2688 pkt
= unpack_threadid (pkt
, &ref
);
2691 warning (_("Incomplete response to threadinfo request."));
2692 if (!threadmatch (&ref
, expectedref
))
2693 { /* This is an answer to a different request. */
2694 warning (_("ERROR RMT Thread info mismatch."));
2697 copy_threadref (&info
->threadid
, &ref
);
2699 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2701 /* Packets are terminated with nulls. */
2702 while ((pkt
< limit
) && mask
&& *pkt
)
2704 pkt
= unpack_int (pkt
, &tag
); /* tag */
2705 pkt
= unpack_byte (pkt
, &length
); /* length */
2706 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2708 warning (_("ERROR RMT: threadinfo tag mismatch."));
2712 if (tag
== TAG_THREADID
)
2716 warning (_("ERROR RMT: length of threadid is not 16."));
2720 pkt
= unpack_threadid (pkt
, &ref
);
2721 mask
= mask
& ~TAG_THREADID
;
2724 if (tag
== TAG_EXISTS
)
2726 info
->active
= stub_unpack_int (pkt
, length
);
2728 mask
= mask
& ~(TAG_EXISTS
);
2731 warning (_("ERROR RMT: 'exists' length too long."));
2737 if (tag
== TAG_THREADNAME
)
2739 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2740 mask
= mask
& ~TAG_THREADNAME
;
2743 if (tag
== TAG_DISPLAY
)
2745 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2746 mask
= mask
& ~TAG_DISPLAY
;
2749 if (tag
== TAG_MOREDISPLAY
)
2751 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2752 mask
= mask
& ~TAG_MOREDISPLAY
;
2755 warning (_("ERROR RMT: unknown thread info tag."));
2756 break; /* Not a tag we know about. */
2762 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2763 struct gdb_ext_thread_info
*info
)
2765 struct remote_state
*rs
= get_remote_state ();
2768 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2772 if (rs
->buf
[0] == '\0')
2775 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2780 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2783 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2784 threadref
*nextthread
)
2786 *pkt
++ = 'q'; /* info query packet */
2787 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2788 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2789 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2790 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2795 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2798 parse_threadlist_response (char *pkt
, int result_limit
,
2799 threadref
*original_echo
, threadref
*resultlist
,
2802 struct remote_state
*rs
= get_remote_state ();
2804 int count
, resultcount
, done
;
2807 /* Assume the 'q' and 'M chars have been stripped. */
2808 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2809 /* done parse past here */
2810 pkt
= unpack_byte (pkt
, &count
); /* count field */
2811 pkt
= unpack_nibble (pkt
, &done
);
2812 /* The first threadid is the argument threadid. */
2813 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2814 while ((count
-- > 0) && (pkt
< limit
))
2816 pkt
= unpack_threadid (pkt
, resultlist
++);
2817 if (resultcount
++ >= result_limit
)
2825 /* Fetch the next batch of threads from the remote. Returns -1 if the
2826 qL packet is not supported, 0 on error and 1 on success. */
2829 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2830 int *done
, int *result_count
, threadref
*threadlist
)
2832 struct remote_state
*rs
= get_remote_state ();
2835 /* Trancate result limit to be smaller than the packet size. */
2836 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2837 >= get_remote_packet_size ())
2838 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2840 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2842 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2843 if (*rs
->buf
== '\0')
2845 /* Packet not supported. */
2850 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2851 &rs
->echo_nextthread
, threadlist
, done
);
2853 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2855 /* FIXME: This is a good reason to drop the packet. */
2856 /* Possably, there is a duplicate response. */
2858 retransmit immediatly - race conditions
2859 retransmit after timeout - yes
2861 wait for packet, then exit
2863 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2864 return 0; /* I choose simply exiting. */
2866 if (*result_count
<= 0)
2870 warning (_("RMT ERROR : failed to get remote thread list."));
2873 return result
; /* break; */
2875 if (*result_count
> result_limit
)
2878 warning (_("RMT ERROR: threadlist response longer than requested."));
2884 /* Fetch the list of remote threads, with the qL packet, and call
2885 STEPFUNCTION for each thread found. Stops iterating and returns 1
2886 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2887 STEPFUNCTION returns false. If the packet is not supported,
2891 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2894 struct remote_state
*rs
= get_remote_state ();
2895 int done
, i
, result_count
;
2903 if (loopcount
++ > looplimit
)
2906 warning (_("Remote fetch threadlist -infinite loop-."));
2909 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2910 MAXTHREADLISTRESULTS
,
2911 &done
, &result_count
,
2912 rs
->resultthreadlist
);
2915 /* Clear for later iterations. */
2917 /* Setup to resume next batch of thread references, set nextthread. */
2918 if (result_count
>= 1)
2919 copy_threadref (&rs
->nextthread
,
2920 &rs
->resultthreadlist
[result_count
- 1]);
2922 while (result_count
--)
2924 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2934 /* A thread found on the remote target. */
2936 typedef struct thread_item
2938 /* The thread's PTID. */
2941 /* The thread's extra info. May be NULL. */
2944 /* The thread's name. May be NULL. */
2947 /* The core the thread was running on. -1 if not known. */
2950 DEF_VEC_O(thread_item_t
);
2952 /* Context passed around to the various methods listing remote
2953 threads. As new threads are found, they're added to the ITEMS
2956 struct threads_listing_context
2958 /* The threads found on the remote target. */
2959 VEC (thread_item_t
) *items
;
2962 /* Discard the contents of the constructed thread listing context. */
2965 clear_threads_listing_context (void *p
)
2967 struct threads_listing_context
*context
2968 = (struct threads_listing_context
*) p
;
2970 struct thread_item
*item
;
2972 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2974 xfree (item
->extra
);
2978 VEC_free (thread_item_t
, context
->items
);
2981 /* Remove the thread specified as the related_pid field of WS
2982 from the CONTEXT list. */
2985 threads_listing_context_remove (struct target_waitstatus
*ws
,
2986 struct threads_listing_context
*context
)
2988 struct thread_item
*item
;
2990 ptid_t child_ptid
= ws
->value
.related_pid
;
2992 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2994 if (ptid_equal (item
->ptid
, child_ptid
))
2996 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
3003 remote_newthread_step (threadref
*ref
, void *data
)
3005 struct threads_listing_context
*context
3006 = (struct threads_listing_context
*) data
;
3007 struct thread_item item
;
3008 int pid
= ptid_get_pid (inferior_ptid
);
3010 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3015 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3017 return 1; /* continue iterator */
3020 #define CRAZY_MAX_THREADS 1000
3023 remote_current_thread (ptid_t oldpid
)
3025 struct remote_state
*rs
= get_remote_state ();
3028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3029 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3034 result
= read_ptid (&rs
->buf
[2], &obuf
);
3035 if (*obuf
!= '\0' && remote_debug
)
3036 fprintf_unfiltered (gdb_stdlog
,
3037 "warning: garbage in qC reply\n");
3045 /* List remote threads using the deprecated qL packet. */
3048 remote_get_threads_with_ql (struct target_ops
*ops
,
3049 struct threads_listing_context
*context
)
3051 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3052 CRAZY_MAX_THREADS
) >= 0)
3058 #if defined(HAVE_LIBEXPAT)
3061 start_thread (struct gdb_xml_parser
*parser
,
3062 const struct gdb_xml_element
*element
,
3063 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3065 struct threads_listing_context
*data
3066 = (struct threads_listing_context
*) user_data
;
3068 struct thread_item item
;
3070 struct gdb_xml_value
*attr
;
3072 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3073 item
.ptid
= read_ptid (id
, NULL
);
3075 attr
= xml_find_attribute (attributes
, "core");
3077 item
.core
= *(ULONGEST
*) attr
->value
;
3081 attr
= xml_find_attribute (attributes
, "name");
3082 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3086 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3090 end_thread (struct gdb_xml_parser
*parser
,
3091 const struct gdb_xml_element
*element
,
3092 void *user_data
, const char *body_text
)
3094 struct threads_listing_context
*data
3095 = (struct threads_listing_context
*) user_data
;
3097 if (body_text
&& *body_text
)
3098 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3101 const struct gdb_xml_attribute thread_attributes
[] = {
3102 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3103 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3104 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3105 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3108 const struct gdb_xml_element thread_children
[] = {
3109 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3112 const struct gdb_xml_element threads_children
[] = {
3113 { "thread", thread_attributes
, thread_children
,
3114 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3115 start_thread
, end_thread
},
3116 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3119 const struct gdb_xml_element threads_elements
[] = {
3120 { "threads", NULL
, threads_children
,
3121 GDB_XML_EF_NONE
, NULL
, NULL
},
3122 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3127 /* List remote threads using qXfer:threads:read. */
3130 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3131 struct threads_listing_context
*context
)
3133 #if defined(HAVE_LIBEXPAT)
3134 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3136 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3137 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3139 if (xml
!= NULL
&& *xml
!= '\0')
3141 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3142 threads_elements
, xml
, context
);
3145 do_cleanups (back_to
);
3153 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3156 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3157 struct threads_listing_context
*context
)
3159 struct remote_state
*rs
= get_remote_state ();
3161 if (rs
->use_threadinfo_query
)
3165 putpkt ("qfThreadInfo");
3166 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3168 if (bufp
[0] != '\0') /* q packet recognized */
3170 while (*bufp
++ == 'm') /* reply contains one or more TID */
3174 struct thread_item item
;
3176 item
.ptid
= read_ptid (bufp
, &bufp
);
3181 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3183 while (*bufp
++ == ','); /* comma-separated list */
3184 putpkt ("qsThreadInfo");
3185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3192 /* Packet not recognized. */
3193 rs
->use_threadinfo_query
= 0;
3200 /* Implement the to_update_thread_list function for the remote
3204 remote_update_thread_list (struct target_ops
*ops
)
3206 struct threads_listing_context context
;
3207 struct cleanup
*old_chain
;
3210 context
.items
= NULL
;
3211 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3213 /* We have a few different mechanisms to fetch the thread list. Try
3214 them all, starting with the most preferred one first, falling
3215 back to older methods. */
3216 if (remote_get_threads_with_qxfer (ops
, &context
)
3217 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3218 || remote_get_threads_with_ql (ops
, &context
))
3221 struct thread_item
*item
;
3222 struct thread_info
*tp
, *tmp
;
3226 if (VEC_empty (thread_item_t
, context
.items
)
3227 && remote_thread_always_alive (ops
, inferior_ptid
))
3229 /* Some targets don't really support threads, but still
3230 reply an (empty) thread list in response to the thread
3231 listing packets, instead of replying "packet not
3232 supported". Exit early so we don't delete the main
3234 do_cleanups (old_chain
);
3238 /* CONTEXT now holds the current thread list on the remote
3239 target end. Delete GDB-side threads no longer found on the
3241 ALL_THREADS_SAFE (tp
, tmp
)
3244 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3247 if (ptid_equal (item
->ptid
, tp
->ptid
))
3251 if (i
== VEC_length (thread_item_t
, context
.items
))
3254 delete_thread (tp
->ptid
);
3258 /* Remove any unreported fork child threads from CONTEXT so
3259 that we don't interfere with follow fork, which is where
3260 creation of such threads is handled. */
3261 remove_new_fork_children (&context
);
3263 /* And now add threads we don't know about yet to our list. */
3265 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3268 if (!ptid_equal (item
->ptid
, null_ptid
))
3270 struct private_thread_info
*info
;
3271 /* In non-stop mode, we assume new found threads are
3272 executing until proven otherwise with a stop reply.
3273 In all-stop, we can only get here if all threads are
3275 int executing
= target_is_non_stop_p () ? 1 : 0;
3277 remote_notice_new_inferior (item
->ptid
, executing
);
3279 info
= demand_private_info (item
->ptid
);
3280 info
->core
= item
->core
;
3281 info
->extra
= item
->extra
;
3283 info
->name
= item
->name
;
3291 /* If no thread listing method is supported, then query whether
3292 each known thread is alive, one by one, with the T packet.
3293 If the target doesn't support threads at all, then this is a
3294 no-op. See remote_thread_alive. */
3298 do_cleanups (old_chain
);
3302 * Collect a descriptive string about the given thread.
3303 * The target may say anything it wants to about the thread
3304 * (typically info about its blocked / runnable state, name, etc.).
3305 * This string will appear in the info threads display.
3307 * Optional: targets are not required to implement this function.
3311 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3313 struct remote_state
*rs
= get_remote_state ();
3317 struct gdb_ext_thread_info threadinfo
;
3318 static char display_buf
[100]; /* arbitrary... */
3319 int n
= 0; /* position in display_buf */
3321 if (rs
->remote_desc
== 0) /* paranoia */
3322 internal_error (__FILE__
, __LINE__
,
3323 _("remote_threads_extra_info"));
3325 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3326 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3327 /* This is the main thread which was added by GDB. The remote
3328 server doesn't know about it. */
3331 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3333 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3335 if (info
&& info
->priv
)
3336 return info
->priv
->extra
;
3341 if (rs
->use_threadextra_query
)
3344 char *endb
= rs
->buf
+ get_remote_packet_size ();
3346 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3348 write_ptid (b
, endb
, tp
->ptid
);
3351 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3352 if (rs
->buf
[0] != 0)
3354 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3355 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3356 display_buf
[result
] = '\0';
3361 /* If the above query fails, fall back to the old method. */
3362 rs
->use_threadextra_query
= 0;
3363 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3364 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3365 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3366 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3367 if (threadinfo
.active
)
3369 if (*threadinfo
.shortname
)
3370 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3371 " Name: %s,", threadinfo
.shortname
);
3372 if (*threadinfo
.display
)
3373 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3374 " State: %s,", threadinfo
.display
);
3375 if (*threadinfo
.more_display
)
3376 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3377 " Priority: %s", threadinfo
.more_display
);
3381 /* For purely cosmetic reasons, clear up trailing commas. */
3382 if (',' == display_buf
[n
-1])
3383 display_buf
[n
-1] = ' ';
3392 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3393 struct static_tracepoint_marker
*marker
)
3395 struct remote_state
*rs
= get_remote_state ();
3398 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3400 p
+= hexnumstr (p
, addr
);
3402 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3406 error (_("Remote failure reply: %s"), p
);
3410 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3417 static VEC(static_tracepoint_marker_p
) *
3418 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3421 struct remote_state
*rs
= get_remote_state ();
3422 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3423 struct static_tracepoint_marker
*marker
= NULL
;
3424 struct cleanup
*old_chain
;
3427 /* Ask for a first packet of static tracepoint marker
3430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3433 error (_("Remote failure reply: %s"), p
);
3435 old_chain
= make_cleanup (free_current_marker
, &marker
);
3440 marker
= XCNEW (struct static_tracepoint_marker
);
3444 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3446 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3448 VEC_safe_push (static_tracepoint_marker_p
,
3454 release_static_tracepoint_marker (marker
);
3455 memset (marker
, 0, sizeof (*marker
));
3458 while (*p
++ == ','); /* comma-separated list */
3459 /* Ask for another packet of static tracepoint definition. */
3461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3465 do_cleanups (old_chain
);
3470 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3473 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3475 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3479 /* Restart the remote side; this is an extended protocol operation. */
3482 extended_remote_restart (void)
3484 struct remote_state
*rs
= get_remote_state ();
3486 /* Send the restart command; for reasons I don't understand the
3487 remote side really expects a number after the "R". */
3488 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3491 remote_fileio_reset ();
3494 /* Clean up connection to a remote debugger. */
3497 remote_close (struct target_ops
*self
)
3499 struct remote_state
*rs
= get_remote_state ();
3501 if (rs
->remote_desc
== NULL
)
3502 return; /* already closed */
3504 /* Make sure we leave stdin registered in the event loop. */
3505 remote_terminal_ours (self
);
3507 serial_close (rs
->remote_desc
);
3508 rs
->remote_desc
= NULL
;
3510 /* We don't have a connection to the remote stub anymore. Get rid
3511 of all the inferiors and their threads we were controlling.
3512 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3513 will be unable to find the thread corresponding to (pid, 0, 0). */
3514 inferior_ptid
= null_ptid
;
3515 discard_all_inferiors ();
3517 /* We are closing the remote target, so we should discard
3518 everything of this target. */
3519 discard_pending_stop_replies_in_queue (rs
);
3521 if (remote_async_inferior_event_token
)
3522 delete_async_event_handler (&remote_async_inferior_event_token
);
3524 remote_notif_state_xfree (rs
->notif_state
);
3526 trace_reset_local_state ();
3529 /* Query the remote side for the text, data and bss offsets. */
3534 struct remote_state
*rs
= get_remote_state ();
3537 int lose
, num_segments
= 0, do_sections
, do_segments
;
3538 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3539 struct section_offsets
*offs
;
3540 struct symfile_segment_data
*data
;
3542 if (symfile_objfile
== NULL
)
3545 putpkt ("qOffsets");
3546 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3549 if (buf
[0] == '\000')
3550 return; /* Return silently. Stub doesn't support
3554 warning (_("Remote failure reply: %s"), buf
);
3558 /* Pick up each field in turn. This used to be done with scanf, but
3559 scanf will make trouble if CORE_ADDR size doesn't match
3560 conversion directives correctly. The following code will work
3561 with any size of CORE_ADDR. */
3562 text_addr
= data_addr
= bss_addr
= 0;
3566 if (startswith (ptr
, "Text="))
3569 /* Don't use strtol, could lose on big values. */
3570 while (*ptr
&& *ptr
!= ';')
3571 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3573 if (startswith (ptr
, ";Data="))
3576 while (*ptr
&& *ptr
!= ';')
3577 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3582 if (!lose
&& startswith (ptr
, ";Bss="))
3585 while (*ptr
&& *ptr
!= ';')
3586 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3588 if (bss_addr
!= data_addr
)
3589 warning (_("Target reported unsupported offsets: %s"), buf
);
3594 else if (startswith (ptr
, "TextSeg="))
3597 /* Don't use strtol, could lose on big values. */
3598 while (*ptr
&& *ptr
!= ';')
3599 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3602 if (startswith (ptr
, ";DataSeg="))
3605 while (*ptr
&& *ptr
!= ';')
3606 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3614 error (_("Malformed response to offset query, %s"), buf
);
3615 else if (*ptr
!= '\0')
3616 warning (_("Target reported unsupported offsets: %s"), buf
);
3618 offs
= ((struct section_offsets
*)
3619 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3620 memcpy (offs
, symfile_objfile
->section_offsets
,
3621 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3623 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3624 do_segments
= (data
!= NULL
);
3625 do_sections
= num_segments
== 0;
3627 if (num_segments
> 0)
3629 segments
[0] = text_addr
;
3630 segments
[1] = data_addr
;
3632 /* If we have two segments, we can still try to relocate everything
3633 by assuming that the .text and .data offsets apply to the whole
3634 text and data segments. Convert the offsets given in the packet
3635 to base addresses for symfile_map_offsets_to_segments. */
3636 else if (data
&& data
->num_segments
== 2)
3638 segments
[0] = data
->segment_bases
[0] + text_addr
;
3639 segments
[1] = data
->segment_bases
[1] + data_addr
;
3642 /* If the object file has only one segment, assume that it is text
3643 rather than data; main programs with no writable data are rare,
3644 but programs with no code are useless. Of course the code might
3645 have ended up in the data segment... to detect that we would need
3646 the permissions here. */
3647 else if (data
&& data
->num_segments
== 1)
3649 segments
[0] = data
->segment_bases
[0] + text_addr
;
3652 /* There's no way to relocate by segment. */
3658 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3659 offs
, num_segments
, segments
);
3661 if (ret
== 0 && !do_sections
)
3662 error (_("Can not handle qOffsets TextSeg "
3663 "response with this symbol file"));
3670 free_symfile_segment_data (data
);
3674 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3676 /* This is a temporary kludge to force data and bss to use the
3677 same offsets because that's what nlmconv does now. The real
3678 solution requires changes to the stub and remote.c that I
3679 don't have time to do right now. */
3681 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3682 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3685 objfile_relocate (symfile_objfile
, offs
);
3688 /* Send interrupt_sequence to remote target. */
3690 send_interrupt_sequence (void)
3692 struct remote_state
*rs
= get_remote_state ();
3694 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3695 remote_serial_write ("\x03", 1);
3696 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3697 serial_send_break (rs
->remote_desc
);
3698 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3700 serial_send_break (rs
->remote_desc
);
3701 remote_serial_write ("g", 1);
3704 internal_error (__FILE__
, __LINE__
,
3705 _("Invalid value for interrupt_sequence_mode: %s."),
3706 interrupt_sequence_mode
);
3710 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3711 and extract the PTID. Returns NULL_PTID if not found. */
3714 stop_reply_extract_thread (char *stop_reply
)
3716 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3720 /* Txx r:val ; r:val (...) */
3723 /* Look for "register" named "thread". */
3728 p1
= strchr (p
, ':');
3732 if (strncmp (p
, "thread", p1
- p
) == 0)
3733 return read_ptid (++p1
, &p
);
3735 p1
= strchr (p
, ';');
3747 /* Determine the remote side's current thread. If we have a stop
3748 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3749 "thread" register we can extract the current thread from. If not,
3750 ask the remote which is the current thread with qC. The former
3751 method avoids a roundtrip. */
3754 get_current_thread (char *wait_status
)
3756 ptid_t ptid
= null_ptid
;
3758 /* Note we don't use remote_parse_stop_reply as that makes use of
3759 the target architecture, which we haven't yet fully determined at
3761 if (wait_status
!= NULL
)
3762 ptid
= stop_reply_extract_thread (wait_status
);
3763 if (ptid_equal (ptid
, null_ptid
))
3764 ptid
= remote_current_thread (inferior_ptid
);
3769 /* Query the remote target for which is the current thread/process,
3770 add it to our tables, and update INFERIOR_PTID. The caller is
3771 responsible for setting the state such that the remote end is ready
3772 to return the current thread.
3774 This function is called after handling the '?' or 'vRun' packets,
3775 whose response is a stop reply from which we can also try
3776 extracting the thread. If the target doesn't support the explicit
3777 qC query, we infer the current thread from that stop reply, passed
3778 in in WAIT_STATUS, which may be NULL. */
3781 add_current_inferior_and_thread (char *wait_status
)
3783 struct remote_state
*rs
= get_remote_state ();
3787 inferior_ptid
= null_ptid
;
3789 /* Now, if we have thread information, update inferior_ptid. */
3790 ptid
= get_current_thread (wait_status
);
3792 if (!ptid_equal (ptid
, null_ptid
))
3794 if (!remote_multi_process_p (rs
))
3797 inferior_ptid
= ptid
;
3801 /* Without this, some commands which require an active target
3802 (such as kill) won't work. This variable serves (at least)
3803 double duty as both the pid of the target process (if it has
3804 such), and as a flag indicating that a target is active. */
3805 inferior_ptid
= magic_null_ptid
;
3809 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3811 /* Add the main thread. */
3812 add_thread_silent (inferior_ptid
);
3815 /* Print info about a thread that was found already stopped on
3819 print_one_stopped_thread (struct thread_info
*thread
)
3821 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3823 switch_to_thread (thread
->ptid
);
3824 stop_pc
= get_frame_pc (get_current_frame ());
3825 set_current_sal_from_frame (get_current_frame ());
3827 thread
->suspend
.waitstatus_pending_p
= 0;
3829 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3831 enum gdb_signal sig
= ws
->value
.sig
;
3833 if (signal_print_state (sig
))
3834 observer_notify_signal_received (sig
);
3836 observer_notify_normal_stop (NULL
, 1);
3839 /* Process all initial stop replies the remote side sent in response
3840 to the ? packet. These indicate threads that were already stopped
3841 on initial connection. We mark these threads as stopped and print
3842 their current frame before giving the user the prompt. */
3845 process_initial_stop_replies (int from_tty
)
3847 int pending_stop_replies
= stop_reply_queue_length ();
3848 struct inferior
*inf
;
3849 struct thread_info
*thread
;
3850 struct thread_info
*selected
= NULL
;
3851 struct thread_info
*lowest_stopped
= NULL
;
3852 struct thread_info
*first
= NULL
;
3854 /* Consume the initial pending events. */
3855 while (pending_stop_replies
-- > 0)
3857 ptid_t waiton_ptid
= minus_one_ptid
;
3859 struct target_waitstatus ws
;
3860 int ignore_event
= 0;
3861 struct thread_info
*thread
;
3863 memset (&ws
, 0, sizeof (ws
));
3864 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3866 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3870 case TARGET_WAITKIND_IGNORE
:
3871 case TARGET_WAITKIND_NO_RESUMED
:
3872 case TARGET_WAITKIND_SIGNALLED
:
3873 case TARGET_WAITKIND_EXITED
:
3874 /* We shouldn't see these, but if we do, just ignore. */
3876 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3880 case TARGET_WAITKIND_EXECD
:
3881 xfree (ws
.value
.execd_pathname
);
3890 thread
= find_thread_ptid (event_ptid
);
3892 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3894 enum gdb_signal sig
= ws
.value
.sig
;
3896 /* Stubs traditionally report SIGTRAP as initial signal,
3897 instead of signal 0. Suppress it. */
3898 if (sig
== GDB_SIGNAL_TRAP
)
3900 thread
->suspend
.stop_signal
= sig
;
3904 thread
->suspend
.waitstatus
= ws
;
3906 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3907 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3908 thread
->suspend
.waitstatus_pending_p
= 1;
3910 set_executing (event_ptid
, 0);
3911 set_running (event_ptid
, 0);
3914 /* "Notice" the new inferiors before anything related to
3915 registers/memory. */
3921 inf
->needs_setup
= 1;
3925 thread
= any_live_thread_of_process (inf
->pid
);
3926 notice_new_inferior (thread
->ptid
,
3927 thread
->state
== THREAD_RUNNING
,
3932 /* If all-stop on top of non-stop, pause all threads. Note this
3933 records the threads' stop pc, so must be done after "noticing"
3937 stop_all_threads ();
3939 /* If all threads of an inferior were already stopped, we
3940 haven't setup the inferior yet. */
3946 if (inf
->needs_setup
)
3948 thread
= any_live_thread_of_process (inf
->pid
);
3949 switch_to_thread_no_regs (thread
);
3955 /* Now go over all threads that are stopped, and print their current
3956 frame. If all-stop, then if there's a signalled thread, pick
3958 ALL_NON_EXITED_THREADS (thread
)
3964 set_running (thread
->ptid
, 0);
3965 else if (thread
->state
!= THREAD_STOPPED
)
3968 if (selected
== NULL
3969 && thread
->suspend
.waitstatus_pending_p
)
3972 if (lowest_stopped
== NULL
3973 || thread
->inf
->num
< lowest_stopped
->inf
->num
3974 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
3975 lowest_stopped
= thread
;
3978 print_one_stopped_thread (thread
);
3981 /* In all-stop, we only print the status of one thread, and leave
3982 others with their status pending. */
3987 thread
= lowest_stopped
;
3991 print_one_stopped_thread (thread
);
3994 /* For "info program". */
3995 thread
= inferior_thread ();
3996 if (thread
->state
== THREAD_STOPPED
)
3997 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4000 /* Start the remote connection and sync state. */
4003 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4005 struct remote_state
*rs
= get_remote_state ();
4006 struct packet_config
*noack_config
;
4007 char *wait_status
= NULL
;
4009 /* Signal other parts that we're going through the initial setup,
4010 and so things may not be stable yet. E.g., we don't try to
4011 install tracepoints until we've relocated symbols. Also, a
4012 Ctrl-C before we're connected and synced up can't interrupt the
4013 target. Instead, it offers to drop the (potentially wedged)
4015 rs
->starting_up
= 1;
4019 if (interrupt_on_connect
)
4020 send_interrupt_sequence ();
4022 /* Ack any packet which the remote side has already sent. */
4023 remote_serial_write ("+", 1);
4025 /* The first packet we send to the target is the optional "supported
4026 packets" request. If the target can answer this, it will tell us
4027 which later probes to skip. */
4028 remote_query_supported ();
4030 /* If the stub wants to get a QAllow, compose one and send it. */
4031 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4032 remote_set_permissions (target
);
4034 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4035 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4036 as a reply to known packet. For packet "vFile:setfs:" it is an
4037 invalid reply and GDB would return error in
4038 remote_hostio_set_filesystem, making remote files access impossible.
4039 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4040 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4042 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4044 putpkt (v_mustreplyempty
);
4045 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4046 if (strcmp (rs
->buf
, "OK") == 0)
4047 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4048 else if (strcmp (rs
->buf
, "") != 0)
4049 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4053 /* Next, we possibly activate noack mode.
4055 If the QStartNoAckMode packet configuration is set to AUTO,
4056 enable noack mode if the stub reported a wish for it with
4059 If set to TRUE, then enable noack mode even if the stub didn't
4060 report it in qSupported. If the stub doesn't reply OK, the
4061 session ends with an error.
4063 If FALSE, then don't activate noack mode, regardless of what the
4064 stub claimed should be the default with qSupported. */
4066 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4067 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4069 putpkt ("QStartNoAckMode");
4070 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4071 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4077 /* Tell the remote that we are using the extended protocol. */
4079 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4082 /* Let the target know which signals it is allowed to pass down to
4084 update_signals_program_target ();
4086 /* Next, if the target can specify a description, read it. We do
4087 this before anything involving memory or registers. */
4088 target_find_description ();
4090 /* Next, now that we know something about the target, update the
4091 address spaces in the program spaces. */
4092 update_address_spaces ();
4094 /* On OSs where the list of libraries is global to all
4095 processes, we fetch them early. */
4096 if (gdbarch_has_global_solist (target_gdbarch ()))
4097 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4099 if (target_is_non_stop_p ())
4101 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4102 error (_("Non-stop mode requested, but remote "
4103 "does not support non-stop"));
4105 putpkt ("QNonStop:1");
4106 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4108 if (strcmp (rs
->buf
, "OK") != 0)
4109 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4111 /* Find about threads and processes the stub is already
4112 controlling. We default to adding them in the running state.
4113 The '?' query below will then tell us about which threads are
4115 remote_update_thread_list (target
);
4117 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4119 /* Don't assume that the stub can operate in all-stop mode.
4120 Request it explicitly. */
4121 putpkt ("QNonStop:0");
4122 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4124 if (strcmp (rs
->buf
, "OK") != 0)
4125 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4128 /* Upload TSVs regardless of whether the target is running or not. The
4129 remote stub, such as GDBserver, may have some predefined or builtin
4130 TSVs, even if the target is not running. */
4131 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4133 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4135 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4136 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4139 /* Check whether the target is running now. */
4141 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4143 if (!target_is_non_stop_p ())
4145 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4148 error (_("The target is not running (try extended-remote?)"));
4150 /* We're connected, but not running. Drop out before we
4151 call start_remote. */
4152 rs
->starting_up
= 0;
4157 /* Save the reply for later. */
4158 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4159 strcpy (wait_status
, rs
->buf
);
4162 /* Fetch thread list. */
4163 target_update_thread_list ();
4165 /* Let the stub know that we want it to return the thread. */
4166 set_continue_thread (minus_one_ptid
);
4168 if (thread_count () == 0)
4170 /* Target has no concept of threads at all. GDB treats
4171 non-threaded target as single-threaded; add a main
4173 add_current_inferior_and_thread (wait_status
);
4177 /* We have thread information; select the thread the target
4178 says should be current. If we're reconnecting to a
4179 multi-threaded program, this will ideally be the thread
4180 that last reported an event before GDB disconnected. */
4181 inferior_ptid
= get_current_thread (wait_status
);
4182 if (ptid_equal (inferior_ptid
, null_ptid
))
4184 /* Odd... The target was able to list threads, but not
4185 tell us which thread was current (no "thread"
4186 register in T stop reply?). Just pick the first
4187 thread in the thread list then. */
4190 fprintf_unfiltered (gdb_stdlog
,
4191 "warning: couldn't determine remote "
4192 "current thread; picking first in list.\n");
4194 inferior_ptid
= thread_list
->ptid
;
4198 /* init_wait_for_inferior should be called before get_offsets in order
4199 to manage `inserted' flag in bp loc in a correct state.
4200 breakpoint_init_inferior, called from init_wait_for_inferior, set
4201 `inserted' flag to 0, while before breakpoint_re_set, called from
4202 start_remote, set `inserted' flag to 1. In the initialization of
4203 inferior, breakpoint_init_inferior should be called first, and then
4204 breakpoint_re_set can be called. If this order is broken, state of
4205 `inserted' flag is wrong, and cause some problems on breakpoint
4207 init_wait_for_inferior ();
4209 get_offsets (); /* Get text, data & bss offsets. */
4211 /* If we could not find a description using qXfer, and we know
4212 how to do it some other way, try again. This is not
4213 supported for non-stop; it could be, but it is tricky if
4214 there are no stopped threads when we connect. */
4215 if (remote_read_description_p (target
)
4216 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4218 target_clear_description ();
4219 target_find_description ();
4222 /* Use the previously fetched status. */
4223 gdb_assert (wait_status
!= NULL
);
4224 strcpy (rs
->buf
, wait_status
);
4225 rs
->cached_wait_status
= 1;
4227 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4231 /* Clear WFI global state. Do this before finding about new
4232 threads and inferiors, and setting the current inferior.
4233 Otherwise we would clear the proceed status of the current
4234 inferior when we want its stop_soon state to be preserved
4235 (see notice_new_inferior). */
4236 init_wait_for_inferior ();
4238 /* In non-stop, we will either get an "OK", meaning that there
4239 are no stopped threads at this time; or, a regular stop
4240 reply. In the latter case, there may be more than one thread
4241 stopped --- we pull them all out using the vStopped
4243 if (strcmp (rs
->buf
, "OK") != 0)
4245 struct notif_client
*notif
= ¬if_client_stop
;
4247 /* remote_notif_get_pending_replies acks this one, and gets
4249 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4250 = remote_notif_parse (notif
, rs
->buf
);
4251 remote_notif_get_pending_events (notif
);
4254 if (thread_count () == 0)
4257 error (_("The target is not running (try extended-remote?)"));
4259 /* We're connected, but not running. Drop out before we
4260 call start_remote. */
4261 rs
->starting_up
= 0;
4265 /* In non-stop mode, any cached wait status will be stored in
4266 the stop reply queue. */
4267 gdb_assert (wait_status
== NULL
);
4269 /* Report all signals during attach/startup. */
4270 remote_pass_signals (target
, 0, NULL
);
4272 /* If there are already stopped threads, mark them stopped and
4273 report their stops before giving the prompt to the user. */
4274 process_initial_stop_replies (from_tty
);
4276 if (target_can_async_p ())
4280 /* If we connected to a live target, do some additional setup. */
4281 if (target_has_execution
)
4283 if (symfile_objfile
) /* No use without a symbol-file. */
4284 remote_check_symbols ();
4287 /* Possibly the target has been engaged in a trace run started
4288 previously; find out where things are at. */
4289 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4291 struct uploaded_tp
*uploaded_tps
= NULL
;
4293 if (current_trace_status ()->running
)
4294 printf_filtered (_("Trace is already running on the target.\n"));
4296 remote_upload_tracepoints (target
, &uploaded_tps
);
4298 merge_uploaded_tracepoints (&uploaded_tps
);
4301 /* The thread and inferior lists are now synchronized with the
4302 target, our symbols have been relocated, and we're merged the
4303 target's tracepoints with ours. We're done with basic start
4305 rs
->starting_up
= 0;
4307 /* Maybe breakpoints are global and need to be inserted now. */
4308 if (breakpoints_should_be_inserted_now ())
4309 insert_breakpoints ();
4312 /* Open a connection to a remote debugger.
4313 NAME is the filename used for communication. */
4316 remote_open (const char *name
, int from_tty
)
4318 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4321 /* Open a connection to a remote debugger using the extended
4322 remote gdb protocol. NAME is the filename used for communication. */
4325 extended_remote_open (const char *name
, int from_tty
)
4327 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4330 /* Reset all packets back to "unknown support". Called when opening a
4331 new connection to a remote target. */
4334 reset_all_packet_configs_support (void)
4338 for (i
= 0; i
< PACKET_MAX
; i
++)
4339 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4342 /* Initialize all packet configs. */
4345 init_all_packet_configs (void)
4349 for (i
= 0; i
< PACKET_MAX
; i
++)
4351 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4352 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4356 /* Symbol look-up. */
4359 remote_check_symbols (void)
4361 struct remote_state
*rs
= get_remote_state ();
4362 char *msg
, *reply
, *tmp
;
4365 struct cleanup
*old_chain
;
4367 /* The remote side has no concept of inferiors that aren't running
4368 yet, it only knows about running processes. If we're connected
4369 but our current inferior is not running, we should not invite the
4370 remote target to request symbol lookups related to its
4371 (unrelated) current process. */
4372 if (!target_has_execution
)
4375 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4378 /* Make sure the remote is pointing at the right process. Note
4379 there's no way to select "no process". */
4380 set_general_process ();
4382 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4383 because we need both at the same time. */
4384 msg
= (char *) xmalloc (get_remote_packet_size ());
4385 old_chain
= make_cleanup (xfree
, msg
);
4386 reply
= (char *) xmalloc (get_remote_packet_size ());
4387 make_cleanup (free_current_contents
, &reply
);
4388 reply_size
= get_remote_packet_size ();
4390 /* Invite target to request symbol lookups. */
4392 putpkt ("qSymbol::");
4393 getpkt (&reply
, &reply_size
, 0);
4394 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4396 while (startswith (reply
, "qSymbol:"))
4398 struct bound_minimal_symbol sym
;
4401 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4403 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4404 if (sym
.minsym
== NULL
)
4405 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4408 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4409 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4411 /* If this is a function address, return the start of code
4412 instead of any data function descriptor. */
4413 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4417 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4418 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4422 getpkt (&reply
, &reply_size
, 0);
4425 do_cleanups (old_chain
);
4428 static struct serial
*
4429 remote_serial_open (const char *name
)
4431 static int udp_warning
= 0;
4433 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4434 of in ser-tcp.c, because it is the remote protocol assuming that the
4435 serial connection is reliable and not the serial connection promising
4437 if (!udp_warning
&& startswith (name
, "udp:"))
4439 warning (_("The remote protocol may be unreliable over UDP.\n"
4440 "Some events may be lost, rendering further debugging "
4445 return serial_open (name
);
4448 /* Inform the target of our permission settings. The permission flags
4449 work without this, but if the target knows the settings, it can do
4450 a couple things. First, it can add its own check, to catch cases
4451 that somehow manage to get by the permissions checks in target
4452 methods. Second, if the target is wired to disallow particular
4453 settings (for instance, a system in the field that is not set up to
4454 be able to stop at a breakpoint), it can object to any unavailable
4458 remote_set_permissions (struct target_ops
*self
)
4460 struct remote_state
*rs
= get_remote_state ();
4462 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4463 "WriteReg:%x;WriteMem:%x;"
4464 "InsertBreak:%x;InsertTrace:%x;"
4465 "InsertFastTrace:%x;Stop:%x",
4466 may_write_registers
, may_write_memory
,
4467 may_insert_breakpoints
, may_insert_tracepoints
,
4468 may_insert_fast_tracepoints
, may_stop
);
4470 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4472 /* If the target didn't like the packet, warn the user. Do not try
4473 to undo the user's settings, that would just be maddening. */
4474 if (strcmp (rs
->buf
, "OK") != 0)
4475 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4478 /* This type describes each known response to the qSupported
4480 struct protocol_feature
4482 /* The name of this protocol feature. */
4485 /* The default for this protocol feature. */
4486 enum packet_support default_support
;
4488 /* The function to call when this feature is reported, or after
4489 qSupported processing if the feature is not supported.
4490 The first argument points to this structure. The second
4491 argument indicates whether the packet requested support be
4492 enabled, disabled, or probed (or the default, if this function
4493 is being called at the end of processing and this feature was
4494 not reported). The third argument may be NULL; if not NULL, it
4495 is a NUL-terminated string taken from the packet following
4496 this feature's name and an equals sign. */
4497 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4500 /* The corresponding packet for this feature. Only used if
4501 FUNC is remote_supported_packet. */
4506 remote_supported_packet (const struct protocol_feature
*feature
,
4507 enum packet_support support
,
4508 const char *argument
)
4512 warning (_("Remote qSupported response supplied an unexpected value for"
4513 " \"%s\"."), feature
->name
);
4517 remote_protocol_packets
[feature
->packet
].support
= support
;
4521 remote_packet_size (const struct protocol_feature
*feature
,
4522 enum packet_support support
, const char *value
)
4524 struct remote_state
*rs
= get_remote_state ();
4529 if (support
!= PACKET_ENABLE
)
4532 if (value
== NULL
|| *value
== '\0')
4534 warning (_("Remote target reported \"%s\" without a size."),
4540 packet_size
= strtol (value
, &value_end
, 16);
4541 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4543 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4544 feature
->name
, value
);
4548 /* Record the new maximum packet size. */
4549 rs
->explicit_packet_size
= packet_size
;
4552 static const struct protocol_feature remote_protocol_features
[] = {
4553 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4554 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4555 PACKET_qXfer_auxv
},
4556 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4557 PACKET_qXfer_exec_file
},
4558 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4559 PACKET_qXfer_features
},
4560 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4561 PACKET_qXfer_libraries
},
4562 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4563 PACKET_qXfer_libraries_svr4
},
4564 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4565 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4566 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4567 PACKET_qXfer_memory_map
},
4568 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4569 PACKET_qXfer_spu_read
},
4570 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4571 PACKET_qXfer_spu_write
},
4572 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4573 PACKET_qXfer_osdata
},
4574 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4575 PACKET_qXfer_threads
},
4576 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4577 PACKET_qXfer_traceframe_info
},
4578 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4579 PACKET_QPassSignals
},
4580 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4581 PACKET_QCatchSyscalls
},
4582 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4583 PACKET_QProgramSignals
},
4584 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4585 PACKET_QStartNoAckMode
},
4586 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4587 PACKET_multiprocess_feature
},
4588 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4589 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4590 PACKET_qXfer_siginfo_read
},
4591 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4592 PACKET_qXfer_siginfo_write
},
4593 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4594 PACKET_ConditionalTracepoints
},
4595 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4596 PACKET_ConditionalBreakpoints
},
4597 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4598 PACKET_BreakpointCommands
},
4599 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4600 PACKET_FastTracepoints
},
4601 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4602 PACKET_StaticTracepoints
},
4603 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4604 PACKET_InstallInTrace
},
4605 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4606 PACKET_DisconnectedTracing_feature
},
4607 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4609 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4611 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4612 PACKET_TracepointSource
},
4613 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4615 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4616 PACKET_EnableDisableTracepoints_feature
},
4617 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4618 PACKET_qXfer_fdpic
},
4619 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4621 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4622 PACKET_QDisableRandomization
},
4623 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4624 { "QTBuffer:size", PACKET_DISABLE
,
4625 remote_supported_packet
, PACKET_QTBuffer_size
},
4626 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4627 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4628 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4629 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4630 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4631 PACKET_qXfer_btrace
},
4632 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4633 PACKET_qXfer_btrace_conf
},
4634 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4635 PACKET_Qbtrace_conf_bts_size
},
4636 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4637 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4638 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4639 PACKET_fork_event_feature
},
4640 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4641 PACKET_vfork_event_feature
},
4642 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4643 PACKET_exec_event_feature
},
4644 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4645 PACKET_Qbtrace_conf_pt_size
},
4646 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4647 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4648 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4651 static char *remote_support_xml
;
4653 /* Register string appended to "xmlRegisters=" in qSupported query. */
4656 register_remote_support_xml (const char *xml
)
4658 #if defined(HAVE_LIBEXPAT)
4659 if (remote_support_xml
== NULL
)
4660 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4663 char *copy
= xstrdup (remote_support_xml
+ 13);
4664 char *p
= strtok (copy
, ",");
4668 if (strcmp (p
, xml
) == 0)
4675 while ((p
= strtok (NULL
, ",")) != NULL
);
4678 remote_support_xml
= reconcat (remote_support_xml
,
4679 remote_support_xml
, ",", xml
,
4686 remote_query_supported_append (char *msg
, const char *append
)
4689 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4691 return xstrdup (append
);
4695 remote_query_supported (void)
4697 struct remote_state
*rs
= get_remote_state ();
4700 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4702 /* The packet support flags are handled differently for this packet
4703 than for most others. We treat an error, a disabled packet, and
4704 an empty response identically: any features which must be reported
4705 to be used will be automatically disabled. An empty buffer
4706 accomplishes this, since that is also the representation for a list
4707 containing no features. */
4710 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4713 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4715 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4716 q
= remote_query_supported_append (q
, "multiprocess+");
4718 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4719 q
= remote_query_supported_append (q
, "swbreak+");
4720 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4721 q
= remote_query_supported_append (q
, "hwbreak+");
4723 q
= remote_query_supported_append (q
, "qRelocInsn+");
4725 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4726 != AUTO_BOOLEAN_FALSE
)
4727 q
= remote_query_supported_append (q
, "fork-events+");
4728 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4729 != AUTO_BOOLEAN_FALSE
)
4730 q
= remote_query_supported_append (q
, "vfork-events+");
4731 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4732 != AUTO_BOOLEAN_FALSE
)
4733 q
= remote_query_supported_append (q
, "exec-events+");
4735 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4736 q
= remote_query_supported_append (q
, "vContSupported+");
4738 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4739 q
= remote_query_supported_append (q
, "QThreadEvents+");
4741 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4742 q
= remote_query_supported_append (q
, "no-resumed+");
4744 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4745 the qSupported:xmlRegisters=i386 handling. */
4746 if (remote_support_xml
!= NULL
)
4747 q
= remote_query_supported_append (q
, remote_support_xml
);
4749 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4752 do_cleanups (old_chain
);
4754 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4756 /* If an error occured, warn, but do not return - just reset the
4757 buffer to empty and go on to disable features. */
4758 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4761 warning (_("Remote failure reply: %s"), rs
->buf
);
4766 memset (seen
, 0, sizeof (seen
));
4771 enum packet_support is_supported
;
4772 char *p
, *end
, *name_end
, *value
;
4774 /* First separate out this item from the rest of the packet. If
4775 there's another item after this, we overwrite the separator
4776 (terminated strings are much easier to work with). */
4778 end
= strchr (p
, ';');
4781 end
= p
+ strlen (p
);
4791 warning (_("empty item in \"qSupported\" response"));
4796 name_end
= strchr (p
, '=');
4799 /* This is a name=value entry. */
4800 is_supported
= PACKET_ENABLE
;
4801 value
= name_end
+ 1;
4810 is_supported
= PACKET_ENABLE
;
4814 is_supported
= PACKET_DISABLE
;
4818 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4822 warning (_("unrecognized item \"%s\" "
4823 "in \"qSupported\" response"), p
);
4829 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4830 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4832 const struct protocol_feature
*feature
;
4835 feature
= &remote_protocol_features
[i
];
4836 feature
->func (feature
, is_supported
, value
);
4841 /* If we increased the packet size, make sure to increase the global
4842 buffer size also. We delay this until after parsing the entire
4843 qSupported packet, because this is the same buffer we were
4845 if (rs
->buf_size
< rs
->explicit_packet_size
)
4847 rs
->buf_size
= rs
->explicit_packet_size
;
4848 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4851 /* Handle the defaults for unmentioned features. */
4852 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4855 const struct protocol_feature
*feature
;
4857 feature
= &remote_protocol_features
[i
];
4858 feature
->func (feature
, feature
->default_support
, NULL
);
4862 /* Serial QUIT handler for the remote serial descriptor.
4864 Defers handling a Ctrl-C until we're done with the current
4865 command/response packet sequence, unless:
4867 - We're setting up the connection. Don't send a remote interrupt
4868 request, as we're not fully synced yet. Quit immediately
4871 - The target has been resumed in the foreground
4872 (target_terminal_is_ours is false) with a synchronous resume
4873 packet, and we're blocked waiting for the stop reply, thus a
4874 Ctrl-C should be immediately sent to the target.
4876 - We get a second Ctrl-C while still within the same serial read or
4877 write. In that case the serial is seemingly wedged --- offer to
4880 - We see a second Ctrl-C without target response, after having
4881 previously interrupted the target. In that case the target/stub
4882 is probably wedged --- offer to quit/disconnect.
4886 remote_serial_quit_handler (void)
4888 struct remote_state
*rs
= get_remote_state ();
4890 if (check_quit_flag ())
4892 /* If we're starting up, we're not fully synced yet. Quit
4894 if (rs
->starting_up
)
4896 else if (rs
->got_ctrlc_during_io
)
4898 if (query (_("The target is not responding to GDB commands.\n"
4899 "Stop debugging it? ")))
4900 remote_unpush_and_throw ();
4902 /* If ^C has already been sent once, offer to disconnect. */
4903 else if (!target_terminal_is_ours () && rs
->ctrlc_pending_p
)
4905 /* All-stop protocol, and blocked waiting for stop reply. Send
4906 an interrupt request. */
4907 else if (!target_terminal_is_ours () && rs
->waiting_for_stop_reply
)
4908 target_interrupt (inferior_ptid
);
4910 rs
->got_ctrlc_during_io
= 1;
4914 /* Remove any of the remote.c targets from target stack. Upper targets depend
4915 on it so remove them first. */
4918 remote_unpush_target (void)
4920 pop_all_targets_at_and_above (process_stratum
);
4924 remote_unpush_and_throw (void)
4926 remote_unpush_target ();
4927 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
4931 remote_open_1 (const char *name
, int from_tty
,
4932 struct target_ops
*target
, int extended_p
)
4934 struct remote_state
*rs
= get_remote_state ();
4937 error (_("To open a remote debug connection, you need to specify what\n"
4938 "serial device is attached to the remote system\n"
4939 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4941 /* See FIXME above. */
4942 if (!target_async_permitted
)
4943 wait_forever_enabled_p
= 1;
4945 /* If we're connected to a running target, target_preopen will kill it.
4946 Ask this question first, before target_preopen has a chance to kill
4948 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4951 && !query (_("Already connected to a remote target. Disconnect? ")))
4952 error (_("Still connected."));
4955 /* Here the possibly existing remote target gets unpushed. */
4956 target_preopen (from_tty
);
4958 /* Make sure we send the passed signals list the next time we resume. */
4959 xfree (rs
->last_pass_packet
);
4960 rs
->last_pass_packet
= NULL
;
4962 /* Make sure we send the program signals list the next time we
4964 xfree (rs
->last_program_signals_packet
);
4965 rs
->last_program_signals_packet
= NULL
;
4967 remote_fileio_reset ();
4968 reopen_exec_file ();
4971 rs
->remote_desc
= remote_serial_open (name
);
4972 if (!rs
->remote_desc
)
4973 perror_with_name (name
);
4975 if (baud_rate
!= -1)
4977 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4979 /* The requested speed could not be set. Error out to
4980 top level after closing remote_desc. Take care to
4981 set remote_desc to NULL to avoid closing remote_desc
4983 serial_close (rs
->remote_desc
);
4984 rs
->remote_desc
= NULL
;
4985 perror_with_name (name
);
4989 serial_setparity (rs
->remote_desc
, serial_parity
);
4990 serial_raw (rs
->remote_desc
);
4992 /* If there is something sitting in the buffer we might take it as a
4993 response to a command, which would be bad. */
4994 serial_flush_input (rs
->remote_desc
);
4998 puts_filtered ("Remote debugging using ");
4999 puts_filtered (name
);
5000 puts_filtered ("\n");
5002 push_target (target
); /* Switch to using remote target now. */
5004 /* Register extra event sources in the event loop. */
5005 remote_async_inferior_event_token
5006 = create_async_event_handler (remote_async_inferior_event_handler
,
5008 rs
->notif_state
= remote_notif_state_allocate ();
5010 /* Reset the target state; these things will be queried either by
5011 remote_query_supported or as they are needed. */
5012 reset_all_packet_configs_support ();
5013 rs
->cached_wait_status
= 0;
5014 rs
->explicit_packet_size
= 0;
5016 rs
->extended
= extended_p
;
5017 rs
->waiting_for_stop_reply
= 0;
5018 rs
->ctrlc_pending_p
= 0;
5019 rs
->got_ctrlc_during_io
= 0;
5021 rs
->general_thread
= not_sent_ptid
;
5022 rs
->continue_thread
= not_sent_ptid
;
5023 rs
->remote_traceframe_number
= -1;
5025 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5027 /* Probe for ability to use "ThreadInfo" query, as required. */
5028 rs
->use_threadinfo_query
= 1;
5029 rs
->use_threadextra_query
= 1;
5031 readahead_cache_invalidate ();
5033 /* Start out by owning the terminal. */
5034 remote_async_terminal_ours_p
= 1;
5036 if (target_async_permitted
)
5038 /* FIXME: cagney/1999-09-23: During the initial connection it is
5039 assumed that the target is already ready and able to respond to
5040 requests. Unfortunately remote_start_remote() eventually calls
5041 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5042 around this. Eventually a mechanism that allows
5043 wait_for_inferior() to expect/get timeouts will be
5045 wait_forever_enabled_p
= 0;
5048 /* First delete any symbols previously loaded from shared libraries. */
5049 no_shared_libraries (NULL
, 0);
5052 init_thread_list ();
5054 /* Start the remote connection. If error() or QUIT, discard this
5055 target (we'd otherwise be in an inconsistent state) and then
5056 propogate the error on up the exception chain. This ensures that
5057 the caller doesn't stumble along blindly assuming that the
5058 function succeeded. The CLI doesn't have this problem but other
5059 UI's, such as MI do.
5061 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5062 this function should return an error indication letting the
5063 caller restore the previous state. Unfortunately the command
5064 ``target remote'' is directly wired to this function making that
5065 impossible. On a positive note, the CLI side of this problem has
5066 been fixed - the function set_cmd_context() makes it possible for
5067 all the ``target ....'' commands to share a common callback
5068 function. See cli-dump.c. */
5073 remote_start_remote (from_tty
, target
, extended_p
);
5075 CATCH (ex
, RETURN_MASK_ALL
)
5077 /* Pop the partially set up target - unless something else did
5078 already before throwing the exception. */
5079 if (rs
->remote_desc
!= NULL
)
5080 remote_unpush_target ();
5081 if (target_async_permitted
)
5082 wait_forever_enabled_p
= 1;
5083 throw_exception (ex
);
5088 remote_btrace_reset ();
5090 if (target_async_permitted
)
5091 wait_forever_enabled_p
= 1;
5094 /* Detach the specified process. */
5097 remote_detach_pid (int pid
)
5099 struct remote_state
*rs
= get_remote_state ();
5101 if (remote_multi_process_p (rs
))
5102 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5104 strcpy (rs
->buf
, "D");
5107 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5109 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5111 else if (rs
->buf
[0] == '\0')
5112 error (_("Remote doesn't know how to detach"));
5114 error (_("Can't detach process."));
5117 /* This detaches a program to which we previously attached, using
5118 inferior_ptid to identify the process. After this is done, GDB
5119 can be used to debug some other program. We better not have left
5120 any breakpoints in the target program or it'll die when it hits
5124 remote_detach_1 (const char *args
, int from_tty
)
5126 int pid
= ptid_get_pid (inferior_ptid
);
5127 struct remote_state
*rs
= get_remote_state ();
5128 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5132 error (_("Argument given to \"detach\" when remotely debugging."));
5134 if (!target_has_execution
)
5135 error (_("No process to detach from."));
5137 target_announce_detach (from_tty
);
5139 /* Tell the remote target to detach. */
5140 remote_detach_pid (pid
);
5142 /* Exit only if this is the only active inferior. */
5143 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5144 puts_filtered (_("Ending remote debugging.\n"));
5146 /* Check to see if we are detaching a fork parent. Note that if we
5147 are detaching a fork child, tp == NULL. */
5148 is_fork_parent
= (tp
!= NULL
5149 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5151 /* If doing detach-on-fork, we don't mourn, because that will delete
5152 breakpoints that should be available for the followed inferior. */
5153 if (!is_fork_parent
)
5154 target_mourn_inferior ();
5157 inferior_ptid
= null_ptid
;
5158 detach_inferior (pid
);
5163 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5165 remote_detach_1 (args
, from_tty
);
5169 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5171 remote_detach_1 (args
, from_tty
);
5174 /* Target follow-fork function for remote targets. On entry, and
5175 at return, the current inferior is the fork parent.
5177 Note that although this is currently only used for extended-remote,
5178 it is named remote_follow_fork in anticipation of using it for the
5179 remote target as well. */
5182 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5185 struct remote_state
*rs
= get_remote_state ();
5186 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5188 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5189 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5191 /* When following the parent and detaching the child, we detach
5192 the child here. For the case of following the child and
5193 detaching the parent, the detach is done in the target-
5194 independent follow fork code in infrun.c. We can't use
5195 target_detach when detaching an unfollowed child because
5196 the client side doesn't know anything about the child. */
5197 if (detach_fork
&& !follow_child
)
5199 /* Detach the fork child. */
5203 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5204 child_pid
= ptid_get_pid (child_ptid
);
5206 remote_detach_pid (child_pid
);
5207 detach_inferior (child_pid
);
5213 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5214 in the program space of the new inferior. On entry and at return the
5215 current inferior is the exec'ing inferior. INF is the new exec'd
5216 inferior, which may be the same as the exec'ing inferior unless
5217 follow-exec-mode is "new". */
5220 remote_follow_exec (struct target_ops
*ops
,
5221 struct inferior
*inf
, char *execd_pathname
)
5223 /* We know that this is a target file name, so if it has the "target:"
5224 prefix we strip it off before saving it in the program space. */
5225 if (is_target_filename (execd_pathname
))
5226 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5228 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5231 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5234 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5237 error (_("Argument given to \"disconnect\" when remotely debugging."));
5239 /* Make sure we unpush even the extended remote targets. Calling
5240 target_mourn_inferior won't unpush, and remote_mourn won't
5241 unpush if there is more than one inferior left. */
5242 unpush_target (target
);
5243 generic_mourn_inferior ();
5246 puts_filtered ("Ending remote debugging.\n");
5249 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5250 be chatty about it. */
5253 extended_remote_attach (struct target_ops
*target
, const char *args
,
5256 struct remote_state
*rs
= get_remote_state ();
5258 char *wait_status
= NULL
;
5260 pid
= parse_pid_to_attach (args
);
5262 /* Remote PID can be freely equal to getpid, do not check it here the same
5263 way as in other targets. */
5265 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5266 error (_("This target does not support attaching to a process"));
5270 char *exec_file
= get_exec_file (0);
5273 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5274 target_pid_to_str (pid_to_ptid (pid
)));
5276 printf_unfiltered (_("Attaching to %s\n"),
5277 target_pid_to_str (pid_to_ptid (pid
)));
5279 gdb_flush (gdb_stdout
);
5282 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5284 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5286 switch (packet_ok (rs
->buf
,
5287 &remote_protocol_packets
[PACKET_vAttach
]))
5290 if (!target_is_non_stop_p ())
5292 /* Save the reply for later. */
5293 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5294 strcpy (wait_status
, rs
->buf
);
5296 else if (strcmp (rs
->buf
, "OK") != 0)
5297 error (_("Attaching to %s failed with: %s"),
5298 target_pid_to_str (pid_to_ptid (pid
)),
5301 case PACKET_UNKNOWN
:
5302 error (_("This target does not support attaching to a process"));
5304 error (_("Attaching to %s failed"),
5305 target_pid_to_str (pid_to_ptid (pid
)));
5308 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5310 inferior_ptid
= pid_to_ptid (pid
);
5312 if (target_is_non_stop_p ())
5314 struct thread_info
*thread
;
5316 /* Get list of threads. */
5317 remote_update_thread_list (target
);
5319 thread
= first_thread_of_process (pid
);
5321 inferior_ptid
= thread
->ptid
;
5323 inferior_ptid
= pid_to_ptid (pid
);
5325 /* Invalidate our notion of the remote current thread. */
5326 record_currthread (rs
, minus_one_ptid
);
5330 /* Now, if we have thread information, update inferior_ptid. */
5331 inferior_ptid
= remote_current_thread (inferior_ptid
);
5333 /* Add the main thread to the thread list. */
5334 add_thread_silent (inferior_ptid
);
5337 /* Next, if the target can specify a description, read it. We do
5338 this before anything involving memory or registers. */
5339 target_find_description ();
5341 if (!target_is_non_stop_p ())
5343 /* Use the previously fetched status. */
5344 gdb_assert (wait_status
!= NULL
);
5346 if (target_can_async_p ())
5348 struct notif_event
*reply
5349 = remote_notif_parse (¬if_client_stop
, wait_status
);
5351 push_stop_reply ((struct stop_reply
*) reply
);
5357 gdb_assert (wait_status
!= NULL
);
5358 strcpy (rs
->buf
, wait_status
);
5359 rs
->cached_wait_status
= 1;
5363 gdb_assert (wait_status
== NULL
);
5366 /* Implementation of the to_post_attach method. */
5369 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5371 /* Get text, data & bss offsets. */
5374 /* In certain cases GDB might not have had the chance to start
5375 symbol lookup up until now. This could happen if the debugged
5376 binary is not using shared libraries, the vsyscall page is not
5377 present (on Linux) and the binary itself hadn't changed since the
5378 debugging process was started. */
5379 if (symfile_objfile
!= NULL
)
5380 remote_check_symbols();
5384 /* Check for the availability of vCont. This function should also check
5388 remote_vcont_probe (struct remote_state
*rs
)
5392 strcpy (rs
->buf
, "vCont?");
5394 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5397 /* Make sure that the features we assume are supported. */
5398 if (startswith (buf
, "vCont"))
5401 int support_c
, support_C
;
5403 rs
->supports_vCont
.s
= 0;
5404 rs
->supports_vCont
.S
= 0;
5407 rs
->supports_vCont
.t
= 0;
5408 rs
->supports_vCont
.r
= 0;
5409 while (p
&& *p
== ';')
5412 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5413 rs
->supports_vCont
.s
= 1;
5414 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5415 rs
->supports_vCont
.S
= 1;
5416 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5418 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5420 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5421 rs
->supports_vCont
.t
= 1;
5422 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5423 rs
->supports_vCont
.r
= 1;
5425 p
= strchr (p
, ';');
5428 /* If c, and C are not all supported, we can't use vCont. Clearing
5429 BUF will make packet_ok disable the packet. */
5430 if (!support_c
|| !support_C
)
5434 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5437 /* Helper function for building "vCont" resumptions. Write a
5438 resumption to P. ENDP points to one-passed-the-end of the buffer
5439 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5440 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5441 resumed thread should be single-stepped and/or signalled. If PTID
5442 equals minus_one_ptid, then all threads are resumed; if PTID
5443 represents a process, then all threads of the process are resumed;
5444 the thread to be stepped and/or signalled is given in the global
5448 append_resumption (char *p
, char *endp
,
5449 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5451 struct remote_state
*rs
= get_remote_state ();
5453 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5454 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5456 /* GDB is willing to range step. */
5457 && use_range_stepping
5458 /* Target supports range stepping. */
5459 && rs
->supports_vCont
.r
5460 /* We don't currently support range stepping multiple
5461 threads with a wildcard (though the protocol allows it,
5462 so stubs shouldn't make an active effort to forbid
5464 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5466 struct thread_info
*tp
;
5468 if (ptid_equal (ptid
, minus_one_ptid
))
5470 /* If we don't know about the target thread's tid, then
5471 we're resuming magic_null_ptid (see caller). */
5472 tp
= find_thread_ptid (magic_null_ptid
);
5475 tp
= find_thread_ptid (ptid
);
5476 gdb_assert (tp
!= NULL
);
5478 if (tp
->control
.may_range_step
)
5480 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5482 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5483 phex_nz (tp
->control
.step_range_start
,
5485 phex_nz (tp
->control
.step_range_end
,
5489 p
+= xsnprintf (p
, endp
- p
, ";s");
5492 p
+= xsnprintf (p
, endp
- p
, ";s");
5493 else if (siggnal
!= GDB_SIGNAL_0
)
5494 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5496 p
+= xsnprintf (p
, endp
- p
, ";c");
5498 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5502 /* All (-1) threads of process. */
5503 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5505 p
+= xsnprintf (p
, endp
- p
, ":");
5506 p
= write_ptid (p
, endp
, nptid
);
5508 else if (!ptid_equal (ptid
, minus_one_ptid
))
5510 p
+= xsnprintf (p
, endp
- p
, ":");
5511 p
= write_ptid (p
, endp
, ptid
);
5517 /* Clear the thread's private info on resume. */
5520 resume_clear_thread_private_info (struct thread_info
*thread
)
5522 if (thread
->priv
!= NULL
)
5524 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5525 thread
->priv
->watch_data_address
= 0;
5529 /* Append a vCont continue-with-signal action for threads that have a
5530 non-zero stop signal. */
5533 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5535 struct thread_info
*thread
;
5537 ALL_NON_EXITED_THREADS (thread
)
5538 if (ptid_match (thread
->ptid
, ptid
)
5539 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5540 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5542 p
= append_resumption (p
, endp
, thread
->ptid
,
5543 0, thread
->suspend
.stop_signal
);
5544 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5545 resume_clear_thread_private_info (thread
);
5551 /* Resume the remote inferior by using a "vCont" packet. The thread
5552 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5553 resumed thread should be single-stepped and/or signalled. If PTID
5554 equals minus_one_ptid, then all threads are resumed; the thread to
5555 be stepped and/or signalled is given in the global INFERIOR_PTID.
5556 This function returns non-zero iff it resumes the inferior.
5558 This function issues a strict subset of all possible vCont commands at the
5562 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5564 struct remote_state
*rs
= get_remote_state ();
5568 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5569 remote_vcont_probe (rs
);
5571 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5575 endp
= rs
->buf
+ get_remote_packet_size ();
5577 /* If we could generate a wider range of packets, we'd have to worry
5578 about overflowing BUF. Should there be a generic
5579 "multi-part-packet" packet? */
5581 p
+= xsnprintf (p
, endp
- p
, "vCont");
5583 if (ptid_equal (ptid
, magic_null_ptid
))
5585 /* MAGIC_NULL_PTID means that we don't have any active threads,
5586 so we don't have any TID numbers the inferior will
5587 understand. Make sure to only send forms that do not specify
5589 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5591 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5593 /* Resume all threads (of all processes, or of a single
5594 process), with preference for INFERIOR_PTID. This assumes
5595 inferior_ptid belongs to the set of all threads we are about
5597 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5599 /* Step inferior_ptid, with or without signal. */
5600 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5603 /* Also pass down any pending signaled resumption for other
5604 threads not the current. */
5605 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5607 /* And continue others without a signal. */
5608 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5612 /* Scheduler locking; resume only PTID. */
5613 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5616 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5619 if (target_is_non_stop_p ())
5621 /* In non-stop, the stub replies to vCont with "OK". The stop
5622 reply will be reported asynchronously by means of a `%Stop'
5624 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5625 if (strcmp (rs
->buf
, "OK") != 0)
5626 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5632 /* Tell the remote machine to resume. */
5635 remote_resume (struct target_ops
*ops
,
5636 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5638 struct remote_state
*rs
= get_remote_state ();
5640 struct thread_info
*thread
;
5642 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5643 (explained in remote-notif.c:handle_notification) so
5644 remote_notif_process is not called. We need find a place where
5645 it is safe to start a 'vNotif' sequence. It is good to do it
5646 before resuming inferior, because inferior was stopped and no RSP
5647 traffic at that moment. */
5648 if (!target_is_non_stop_p ())
5649 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5651 rs
->last_sent_signal
= siggnal
;
5652 rs
->last_sent_step
= step
;
5654 rs
->last_resume_exec_dir
= execution_direction
;
5656 /* The vCont packet doesn't need to specify threads via Hc. */
5657 /* No reverse support (yet) for vCont. */
5658 if (execution_direction
!= EXEC_REVERSE
)
5659 if (remote_vcont_resume (ptid
, step
, siggnal
))
5662 /* All other supported resume packets do use Hc, so set the continue
5664 if (ptid_equal (ptid
, minus_one_ptid
))
5665 set_continue_thread (any_thread_ptid
);
5667 set_continue_thread (ptid
);
5669 ALL_NON_EXITED_THREADS (thread
)
5670 resume_clear_thread_private_info (thread
);
5673 if (execution_direction
== EXEC_REVERSE
)
5675 /* We don't pass signals to the target in reverse exec mode. */
5676 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5677 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5680 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5681 error (_("Remote reverse-step not supported."));
5682 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5683 error (_("Remote reverse-continue not supported."));
5685 strcpy (buf
, step
? "bs" : "bc");
5687 else if (siggnal
!= GDB_SIGNAL_0
)
5689 buf
[0] = step
? 'S' : 'C';
5690 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5691 buf
[2] = tohex (((int) siggnal
) & 0xf);
5695 strcpy (buf
, step
? "s" : "c");
5700 /* We are about to start executing the inferior, let's register it
5701 with the event loop. NOTE: this is the one place where all the
5702 execution commands end up. We could alternatively do this in each
5703 of the execution commands in infcmd.c. */
5704 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5705 into infcmd.c in order to allow inferior function calls to work
5706 NOT asynchronously. */
5707 if (target_can_async_p ())
5710 /* We've just told the target to resume. The remote server will
5711 wait for the inferior to stop, and then send a stop reply. In
5712 the mean time, we can't start another command/query ourselves
5713 because the stub wouldn't be ready to process it. This applies
5714 only to the base all-stop protocol, however. In non-stop (which
5715 only supports vCont), the stub replies with an "OK", and is
5716 immediate able to process further serial input. */
5717 if (!target_is_non_stop_p ())
5718 rs
->waiting_for_stop_reply
= 1;
5722 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5723 thread, all threads of a remote process, or all threads of all
5727 remote_stop_ns (ptid_t ptid
)
5729 struct remote_state
*rs
= get_remote_state ();
5731 char *endp
= rs
->buf
+ get_remote_packet_size ();
5733 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5734 remote_vcont_probe (rs
);
5736 if (!rs
->supports_vCont
.t
)
5737 error (_("Remote server does not support stopping threads"));
5739 if (ptid_equal (ptid
, minus_one_ptid
)
5740 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5741 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5746 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5748 if (ptid_is_pid (ptid
))
5749 /* All (-1) threads of process. */
5750 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5753 /* Small optimization: if we already have a stop reply for
5754 this thread, no use in telling the stub we want this
5756 if (peek_stop_reply (ptid
))
5762 write_ptid (p
, endp
, nptid
);
5765 /* In non-stop, we get an immediate OK reply. The stop reply will
5766 come in asynchronously by notification. */
5768 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5769 if (strcmp (rs
->buf
, "OK") != 0)
5770 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5773 /* All-stop version of target_interrupt. Sends a break or a ^C to
5774 interrupt the remote target. It is undefined which thread of which
5775 process reports the interrupt. */
5778 remote_interrupt_as (void)
5780 struct remote_state
*rs
= get_remote_state ();
5782 rs
->ctrlc_pending_p
= 1;
5784 /* If the inferior is stopped already, but the core didn't know
5785 about it yet, just ignore the request. The cached wait status
5786 will be collected in remote_wait. */
5787 if (rs
->cached_wait_status
)
5790 /* Send interrupt_sequence to remote target. */
5791 send_interrupt_sequence ();
5794 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5795 the remote target. It is undefined which thread of which process
5796 reports the interrupt. Throws an error if the packet is not
5797 supported by the server. */
5800 remote_interrupt_ns (void)
5802 struct remote_state
*rs
= get_remote_state ();
5804 char *endp
= rs
->buf
+ get_remote_packet_size ();
5806 xsnprintf (p
, endp
- p
, "vCtrlC");
5808 /* In non-stop, we get an immediate OK reply. The stop reply will
5809 come in asynchronously by notification. */
5811 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5813 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
5817 case PACKET_UNKNOWN
:
5818 error (_("No support for interrupting the remote target."));
5820 error (_("Interrupting target failed: %s"), rs
->buf
);
5824 /* Implement the to_stop function for the remote targets. */
5827 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5830 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5832 if (target_is_non_stop_p ())
5833 remote_stop_ns (ptid
);
5836 /* We don't currently have a way to transparently pause the
5837 remote target in all-stop mode. Interrupt it instead. */
5838 remote_interrupt_as ();
5842 /* Implement the to_interrupt function for the remote targets. */
5845 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5847 struct remote_state
*rs
= get_remote_state ();
5850 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5852 if (target_is_non_stop_p ())
5853 remote_interrupt_ns ();
5855 remote_interrupt_as ();
5858 /* Implement the to_pass_ctrlc function for the remote targets. */
5861 remote_pass_ctrlc (struct target_ops
*self
)
5863 struct remote_state
*rs
= get_remote_state ();
5866 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
5868 /* If we're starting up, we're not fully synced yet. Quit
5870 if (rs
->starting_up
)
5872 /* If ^C has already been sent once, offer to disconnect. */
5873 else if (rs
->ctrlc_pending_p
)
5876 target_interrupt (inferior_ptid
);
5879 /* Ask the user what to do when an interrupt is received. */
5882 interrupt_query (void)
5884 struct remote_state
*rs
= get_remote_state ();
5886 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5888 if (query (_("The target is not responding to interrupt requests.\n"
5889 "Stop debugging it? ")))
5891 remote_unpush_target ();
5892 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5897 if (query (_("Interrupted while waiting for the program.\n"
5898 "Give up waiting? ")))
5903 /* Enable/disable target terminal ownership. Most targets can use
5904 terminal groups to control terminal ownership. Remote targets are
5905 different in that explicit transfer of ownership to/from GDB/target
5909 remote_terminal_inferior (struct target_ops
*self
)
5911 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5912 idempotent. The event-loop GDB talking to an asynchronous target
5913 with a synchronous command calls this function from both
5914 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5915 transfer the terminal to the target when it shouldn't this guard
5917 if (!remote_async_terminal_ours_p
)
5919 remote_async_terminal_ours_p
= 0;
5920 /* NOTE: At this point we could also register our selves as the
5921 recipient of all input. Any characters typed could then be
5922 passed on down to the target. */
5926 remote_terminal_ours (struct target_ops
*self
)
5928 /* See FIXME in remote_terminal_inferior. */
5929 if (remote_async_terminal_ours_p
)
5931 remote_async_terminal_ours_p
= 1;
5935 remote_console_output (char *msg
)
5939 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5942 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5946 fputs_unfiltered (tb
, gdb_stdtarg
);
5948 gdb_flush (gdb_stdtarg
);
5951 typedef struct cached_reg
5954 gdb_byte data
[MAX_REGISTER_SIZE
];
5957 DEF_VEC_O(cached_reg_t
);
5959 typedef struct stop_reply
5961 struct notif_event base
;
5963 /* The identifier of the thread about this event */
5966 /* The remote state this event is associated with. When the remote
5967 connection, represented by a remote_state object, is closed,
5968 all the associated stop_reply events should be released. */
5969 struct remote_state
*rs
;
5971 struct target_waitstatus ws
;
5973 /* Expedited registers. This makes remote debugging a bit more
5974 efficient for those targets that provide critical registers as
5975 part of their normal status mechanism (as another roundtrip to
5976 fetch them is avoided). */
5977 VEC(cached_reg_t
) *regcache
;
5979 enum target_stop_reason stop_reason
;
5981 CORE_ADDR watch_data_address
;
5986 DECLARE_QUEUE_P (stop_reply_p
);
5987 DEFINE_QUEUE_P (stop_reply_p
);
5988 /* The list of already fetched and acknowledged stop events. This
5989 queue is used for notification Stop, and other notifications
5990 don't need queue for their events, because the notification events
5991 of Stop can't be consumed immediately, so that events should be
5992 queued first, and be consumed by remote_wait_{ns,as} one per
5993 time. Other notifications can consume their events immediately,
5994 so queue is not needed for them. */
5995 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5998 stop_reply_xfree (struct stop_reply
*r
)
6000 notif_event_xfree ((struct notif_event
*) r
);
6003 /* Return the length of the stop reply queue. */
6006 stop_reply_queue_length (void)
6008 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6012 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6013 struct notif_event
*event
)
6015 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6019 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6020 struct notif_event
*event
)
6022 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6025 putpkt ((char *) self
->ack_command
);
6027 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6028 /* We got an unknown stop reply. */
6029 error (_("Unknown stop reply"));
6031 push_stop_reply (stop_reply
);
6035 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6037 /* We can't get pending events in remote_notif_process for
6038 notification stop, and we have to do this in remote_wait_ns
6039 instead. If we fetch all queued events from stub, remote stub
6040 may exit and we have no chance to process them back in
6042 mark_async_event_handler (remote_async_inferior_event_token
);
6047 stop_reply_dtr (struct notif_event
*event
)
6049 struct stop_reply
*r
= (struct stop_reply
*) event
;
6051 VEC_free (cached_reg_t
, r
->regcache
);
6054 static struct notif_event
*
6055 remote_notif_stop_alloc_reply (void)
6057 /* We cast to a pointer to the "base class". */
6058 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6060 r
->dtr
= stop_reply_dtr
;
6065 /* A client of notification Stop. */
6067 struct notif_client notif_client_stop
=
6071 remote_notif_stop_parse
,
6072 remote_notif_stop_ack
,
6073 remote_notif_stop_can_get_pending_events
,
6074 remote_notif_stop_alloc_reply
,
6078 /* A parameter to pass data in and out. */
6080 struct queue_iter_param
6083 struct stop_reply
*output
;
6086 /* Determine if THREAD is a pending fork parent thread. ARG contains
6087 the pid of the process that owns the threads we want to check, or
6088 -1 if we want to check all threads. */
6091 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6094 if (ws
->kind
== TARGET_WAITKIND_FORKED
6095 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6097 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6104 /* Check whether EVENT is a fork event, and if it is, remove the
6105 fork child from the context list passed in DATA. */
6108 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6109 QUEUE_ITER (stop_reply_p
) *iter
,
6113 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6114 struct threads_listing_context
*context
6115 = (struct threads_listing_context
*) param
->input
;
6117 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6118 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6119 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6120 threads_listing_context_remove (&event
->ws
, context
);
6125 /* If CONTEXT contains any fork child threads that have not been
6126 reported yet, remove them from the CONTEXT list. If such a
6127 thread exists it is because we are stopped at a fork catchpoint
6128 and have not yet called follow_fork, which will set up the
6129 host-side data structures for the new process. */
6132 remove_new_fork_children (struct threads_listing_context
*context
)
6134 struct thread_info
* thread
;
6136 struct notif_client
*notif
= ¬if_client_stop
;
6137 struct queue_iter_param param
;
6139 /* For any threads stopped at a fork event, remove the corresponding
6140 fork child threads from the CONTEXT list. */
6141 ALL_NON_EXITED_THREADS (thread
)
6143 struct target_waitstatus
*ws
;
6145 if (thread
->suspend
.waitstatus_pending_p
)
6146 ws
= &thread
->suspend
.waitstatus
;
6148 ws
= &thread
->pending_follow
;
6150 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6152 threads_listing_context_remove (ws
, context
);
6156 /* Check for any pending fork events (not reported or processed yet)
6157 in process PID and remove those fork child threads from the
6158 CONTEXT list as well. */
6159 remote_notif_get_pending_events (notif
);
6160 param
.input
= context
;
6161 param
.output
= NULL
;
6162 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6163 remove_child_of_pending_fork
, ¶m
);
6166 /* Remove stop replies in the queue if its pid is equal to the given
6170 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6171 QUEUE_ITER (stop_reply_p
) *iter
,
6175 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6176 struct inferior
*inf
= (struct inferior
*) param
->input
;
6178 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6180 stop_reply_xfree (event
);
6181 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6187 /* Discard all pending stop replies of inferior INF. */
6190 discard_pending_stop_replies (struct inferior
*inf
)
6192 struct queue_iter_param param
;
6193 struct stop_reply
*reply
;
6194 struct remote_state
*rs
= get_remote_state ();
6195 struct remote_notif_state
*rns
= rs
->notif_state
;
6197 /* This function can be notified when an inferior exists. When the
6198 target is not remote, the notification state is NULL. */
6199 if (rs
->remote_desc
== NULL
)
6202 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6204 /* Discard the in-flight notification. */
6205 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6207 stop_reply_xfree (reply
);
6208 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6212 param
.output
= NULL
;
6213 /* Discard the stop replies we have already pulled with
6215 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6216 remove_stop_reply_for_inferior
, ¶m
);
6219 /* If its remote state is equal to the given remote state,
6220 remove EVENT from the stop reply queue. */
6223 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6224 QUEUE_ITER (stop_reply_p
) *iter
,
6228 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6229 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6231 if (event
->rs
== rs
)
6233 stop_reply_xfree (event
);
6234 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6240 /* Discard the stop replies for RS in stop_reply_queue. */
6243 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6245 struct queue_iter_param param
;
6248 param
.output
= NULL
;
6249 /* Discard the stop replies we have already pulled with
6251 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6252 remove_stop_reply_of_remote_state
, ¶m
);
6255 /* A parameter to pass data in and out. */
6258 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6259 QUEUE_ITER (stop_reply_p
) *iter
,
6263 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6264 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6266 if (ptid_match (event
->ptid
, *ptid
))
6268 param
->output
= event
;
6269 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6276 /* Remove the first reply in 'stop_reply_queue' which matches
6279 static struct stop_reply
*
6280 remote_notif_remove_queued_reply (ptid_t ptid
)
6282 struct queue_iter_param param
;
6284 param
.input
= &ptid
;
6285 param
.output
= NULL
;
6287 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6288 remote_notif_remove_once_on_match
, ¶m
);
6290 fprintf_unfiltered (gdb_stdlog
,
6291 "notif: discard queued event: 'Stop' in %s\n",
6292 target_pid_to_str (ptid
));
6294 return param
.output
;
6297 /* Look for a queued stop reply belonging to PTID. If one is found,
6298 remove it from the queue, and return it. Returns NULL if none is
6299 found. If there are still queued events left to process, tell the
6300 event loop to get back to target_wait soon. */
6302 static struct stop_reply
*
6303 queued_stop_reply (ptid_t ptid
)
6305 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6307 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6308 /* There's still at least an event left. */
6309 mark_async_event_handler (remote_async_inferior_event_token
);
6314 /* Push a fully parsed stop reply in the stop reply queue. Since we
6315 know that we now have at least one queued event left to pass to the
6316 core side, tell the event loop to get back to target_wait soon. */
6319 push_stop_reply (struct stop_reply
*new_event
)
6321 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6324 fprintf_unfiltered (gdb_stdlog
,
6325 "notif: push 'Stop' %s to queue %d\n",
6326 target_pid_to_str (new_event
->ptid
),
6327 QUEUE_length (stop_reply_p
,
6330 mark_async_event_handler (remote_async_inferior_event_token
);
6334 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6335 QUEUE_ITER (stop_reply_p
) *iter
,
6336 struct stop_reply
*event
,
6339 ptid_t
*ptid
= (ptid_t
*) data
;
6341 return !(ptid_equal (*ptid
, event
->ptid
)
6342 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6345 /* Returns true if we have a stop reply for PTID. */
6348 peek_stop_reply (ptid_t ptid
)
6350 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6351 stop_reply_match_ptid_and_ws
, &ptid
);
6354 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6355 starting with P and ending with PEND matches PREFIX. */
6358 strprefix (const char *p
, const char *pend
, const char *prefix
)
6360 for ( ; p
< pend
; p
++, prefix
++)
6363 return *prefix
== '\0';
6366 /* Parse the stop reply in BUF. Either the function succeeds, and the
6367 result is stored in EVENT, or throws an error. */
6370 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6372 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6377 event
->ptid
= null_ptid
;
6378 event
->rs
= get_remote_state ();
6379 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6380 event
->ws
.value
.integer
= 0;
6381 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6382 event
->regcache
= NULL
;
6387 case 'T': /* Status with PC, SP, FP, ... */
6388 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6389 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6391 n... = register number
6392 r... = register contents
6395 p
= &buf
[3]; /* after Txx */
6401 p1
= strchr (p
, ':');
6403 error (_("Malformed packet(a) (missing colon): %s\n\
6407 error (_("Malformed packet(a) (missing register number): %s\n\
6411 /* Some "registers" are actually extended stop information.
6412 Note if you're adding a new entry here: GDB 7.9 and
6413 earlier assume that all register "numbers" that start
6414 with an hex digit are real register numbers. Make sure
6415 the server only sends such a packet if it knows the
6416 client understands it. */
6418 if (strprefix (p
, p1
, "thread"))
6419 event
->ptid
= read_ptid (++p1
, &p
);
6420 else if (strprefix (p
, p1
, "syscall_entry"))
6424 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6425 p
= unpack_varlen_hex (++p1
, &sysno
);
6426 event
->ws
.value
.syscall_number
= (int) sysno
;
6428 else if (strprefix (p
, p1
, "syscall_return"))
6432 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6433 p
= unpack_varlen_hex (++p1
, &sysno
);
6434 event
->ws
.value
.syscall_number
= (int) sysno
;
6436 else if (strprefix (p
, p1
, "watch")
6437 || strprefix (p
, p1
, "rwatch")
6438 || strprefix (p
, p1
, "awatch"))
6440 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6441 p
= unpack_varlen_hex (++p1
, &addr
);
6442 event
->watch_data_address
= (CORE_ADDR
) addr
;
6444 else if (strprefix (p
, p1
, "swbreak"))
6446 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6448 /* Make sure the stub doesn't forget to indicate support
6450 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6451 error (_("Unexpected swbreak stop reason"));
6453 /* The value part is documented as "must be empty",
6454 though we ignore it, in case we ever decide to make
6455 use of it in a backward compatible way. */
6456 p
= strchrnul (p1
+ 1, ';');
6458 else if (strprefix (p
, p1
, "hwbreak"))
6460 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6462 /* Make sure the stub doesn't forget to indicate support
6464 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6465 error (_("Unexpected hwbreak stop reason"));
6468 p
= strchrnul (p1
+ 1, ';');
6470 else if (strprefix (p
, p1
, "library"))
6472 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6473 p
= strchrnul (p1
+ 1, ';');
6475 else if (strprefix (p
, p1
, "replaylog"))
6477 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6478 /* p1 will indicate "begin" or "end", but it makes
6479 no difference for now, so ignore it. */
6480 p
= strchrnul (p1
+ 1, ';');
6482 else if (strprefix (p
, p1
, "core"))
6486 p
= unpack_varlen_hex (++p1
, &c
);
6489 else if (strprefix (p
, p1
, "fork"))
6491 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6492 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6494 else if (strprefix (p
, p1
, "vfork"))
6496 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6497 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6499 else if (strprefix (p
, p1
, "vforkdone"))
6501 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6502 p
= strchrnul (p1
+ 1, ';');
6504 else if (strprefix (p
, p1
, "exec"))
6507 char pathname
[PATH_MAX
];
6510 /* Determine the length of the execd pathname. */
6511 p
= unpack_varlen_hex (++p1
, &ignored
);
6512 pathlen
= (p
- p1
) / 2;
6514 /* Save the pathname for event reporting and for
6515 the next run command. */
6516 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6517 pathname
[pathlen
] = '\0';
6519 /* This is freed during event handling. */
6520 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6521 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6523 /* Skip the registers included in this packet, since
6524 they may be for an architecture different from the
6525 one used by the original program. */
6528 else if (strprefix (p
, p1
, "create"))
6530 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6531 p
= strchrnul (p1
+ 1, ';');
6540 p
= strchrnul (p1
+ 1, ';');
6545 /* Maybe a real ``P'' register number. */
6546 p_temp
= unpack_varlen_hex (p
, &pnum
);
6547 /* If the first invalid character is the colon, we got a
6548 register number. Otherwise, it's an unknown stop
6552 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6553 cached_reg_t cached_reg
;
6556 error (_("Remote sent bad register number %s: %s\n\
6558 hex_string (pnum
), p
, buf
);
6560 cached_reg
.num
= reg
->regnum
;
6563 fieldsize
= hex2bin (p
, cached_reg
.data
,
6564 register_size (target_gdbarch (),
6567 if (fieldsize
< register_size (target_gdbarch (),
6569 warning (_("Remote reply is too short: %s"), buf
);
6571 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6575 /* Not a number. Silently skip unknown optional
6577 p
= strchrnul (p1
+ 1, ';');
6582 error (_("Remote register badly formatted: %s\nhere: %s"),
6587 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6591 case 'S': /* Old style status, just signal only. */
6595 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6596 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6597 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6598 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6600 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6603 case 'w': /* Thread exited. */
6608 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
6609 p
= unpack_varlen_hex (&buf
[1], &value
);
6610 event
->ws
.value
.integer
= value
;
6612 error (_("stop reply packet badly formatted: %s"), buf
);
6613 event
->ptid
= read_ptid (++p
, NULL
);
6616 case 'W': /* Target exited. */
6623 /* GDB used to accept only 2 hex chars here. Stubs should
6624 only send more if they detect GDB supports multi-process
6626 p
= unpack_varlen_hex (&buf
[1], &value
);
6630 /* The remote process exited. */
6631 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6632 event
->ws
.value
.integer
= value
;
6636 /* The remote process exited with a signal. */
6637 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6638 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6639 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6641 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6644 /* If no process is specified, assume inferior_ptid. */
6645 pid
= ptid_get_pid (inferior_ptid
);
6654 else if (startswith (p
, "process:"))
6658 p
+= sizeof ("process:") - 1;
6659 unpack_varlen_hex (p
, &upid
);
6663 error (_("unknown stop reply packet: %s"), buf
);
6666 error (_("unknown stop reply packet: %s"), buf
);
6667 event
->ptid
= pid_to_ptid (pid
);
6671 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
6672 event
->ptid
= minus_one_ptid
;
6676 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
6677 error (_("No process or thread specified in stop reply: %s"), buf
);
6680 /* When the stub wants to tell GDB about a new notification reply, it
6681 sends a notification (%Stop, for example). Those can come it at
6682 any time, hence, we have to make sure that any pending
6683 putpkt/getpkt sequence we're making is finished, before querying
6684 the stub for more events with the corresponding ack command
6685 (vStopped, for example). E.g., if we started a vStopped sequence
6686 immediately upon receiving the notification, something like this
6694 1.6) <-- (registers reply to step #1.3)
6696 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6699 To solve this, whenever we parse a %Stop notification successfully,
6700 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6701 doing whatever we were doing:
6707 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6708 2.5) <-- (registers reply to step #2.3)
6710 Eventualy after step #2.5, we return to the event loop, which
6711 notices there's an event on the
6712 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6713 associated callback --- the function below. At this point, we're
6714 always safe to start a vStopped sequence. :
6717 2.7) <-- T05 thread:2
6723 remote_notif_get_pending_events (struct notif_client
*nc
)
6725 struct remote_state
*rs
= get_remote_state ();
6727 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6730 fprintf_unfiltered (gdb_stdlog
,
6731 "notif: process: '%s' ack pending event\n",
6735 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6736 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6740 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6741 if (strcmp (rs
->buf
, "OK") == 0)
6744 remote_notif_ack (nc
, rs
->buf
);
6750 fprintf_unfiltered (gdb_stdlog
,
6751 "notif: process: '%s' no pending reply\n",
6756 /* Called when it is decided that STOP_REPLY holds the info of the
6757 event that is to be returned to the core. This function always
6758 destroys STOP_REPLY. */
6761 process_stop_reply (struct stop_reply
*stop_reply
,
6762 struct target_waitstatus
*status
)
6766 *status
= stop_reply
->ws
;
6767 ptid
= stop_reply
->ptid
;
6769 /* If no thread/process was reported by the stub, assume the current
6771 if (ptid_equal (ptid
, null_ptid
))
6772 ptid
= inferior_ptid
;
6774 if (status
->kind
!= TARGET_WAITKIND_EXITED
6775 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
6776 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
6778 struct private_thread_info
*remote_thr
;
6780 /* Expedited registers. */
6781 if (stop_reply
->regcache
)
6783 struct regcache
*regcache
6784 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6789 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6791 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6792 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6795 remote_notice_new_inferior (ptid
, 0);
6796 remote_thr
= demand_private_info (ptid
);
6797 remote_thr
->core
= stop_reply
->core
;
6798 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
6799 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
6802 stop_reply_xfree (stop_reply
);
6806 /* The non-stop mode version of target_wait. */
6809 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6811 struct remote_state
*rs
= get_remote_state ();
6812 struct stop_reply
*stop_reply
;
6816 /* If in non-stop mode, get out of getpkt even if a
6817 notification is received. */
6819 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6820 0 /* forever */, &is_notif
);
6823 if (ret
!= -1 && !is_notif
)
6826 case 'E': /* Error of some sort. */
6827 /* We're out of sync with the target now. Did it continue
6828 or not? We can't tell which thread it was in non-stop,
6829 so just ignore this. */
6830 warning (_("Remote failure reply: %s"), rs
->buf
);
6832 case 'O': /* Console output. */
6833 remote_console_output (rs
->buf
+ 1);
6836 warning (_("Invalid remote reply: %s"), rs
->buf
);
6840 /* Acknowledge a pending stop reply that may have arrived in the
6842 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6843 remote_notif_get_pending_events (¬if_client_stop
);
6845 /* If indeed we noticed a stop reply, we're done. */
6846 stop_reply
= queued_stop_reply (ptid
);
6847 if (stop_reply
!= NULL
)
6848 return process_stop_reply (stop_reply
, status
);
6850 /* Still no event. If we're just polling for an event, then
6851 return to the event loop. */
6852 if (options
& TARGET_WNOHANG
)
6854 status
->kind
= TARGET_WAITKIND_IGNORE
;
6855 return minus_one_ptid
;
6858 /* Otherwise do a blocking wait. */
6859 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6860 1 /* forever */, &is_notif
);
6864 /* Wait until the remote machine stops, then return, storing status in
6865 STATUS just as `wait' would. */
6868 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6870 struct remote_state
*rs
= get_remote_state ();
6871 ptid_t event_ptid
= null_ptid
;
6873 struct stop_reply
*stop_reply
;
6877 status
->kind
= TARGET_WAITKIND_IGNORE
;
6878 status
->value
.integer
= 0;
6880 stop_reply
= queued_stop_reply (ptid
);
6881 if (stop_reply
!= NULL
)
6882 return process_stop_reply (stop_reply
, status
);
6884 if (rs
->cached_wait_status
)
6885 /* Use the cached wait status, but only once. */
6886 rs
->cached_wait_status
= 0;
6891 int forever
= ((options
& TARGET_WNOHANG
) == 0
6892 && wait_forever_enabled_p
);
6894 if (!rs
->waiting_for_stop_reply
)
6896 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6897 return minus_one_ptid
;
6900 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6901 _never_ wait for ever -> test on target_is_async_p().
6902 However, before we do that we need to ensure that the caller
6903 knows how to take the target into/out of async mode. */
6904 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6905 forever
, &is_notif
);
6907 /* GDB gets a notification. Return to core as this event is
6909 if (ret
!= -1 && is_notif
)
6910 return minus_one_ptid
;
6912 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6913 return minus_one_ptid
;
6918 /* Assume that the target has acknowledged Ctrl-C unless we receive
6919 an 'F' or 'O' packet. */
6920 if (buf
[0] != 'F' && buf
[0] != 'O')
6921 rs
->ctrlc_pending_p
= 0;
6925 case 'E': /* Error of some sort. */
6926 /* We're out of sync with the target now. Did it continue or
6927 not? Not is more likely, so report a stop. */
6928 rs
->waiting_for_stop_reply
= 0;
6930 warning (_("Remote failure reply: %s"), buf
);
6931 status
->kind
= TARGET_WAITKIND_STOPPED
;
6932 status
->value
.sig
= GDB_SIGNAL_0
;
6934 case 'F': /* File-I/O request. */
6935 /* GDB may access the inferior memory while handling the File-I/O
6936 request, but we don't want GDB accessing memory while waiting
6937 for a stop reply. See the comments in putpkt_binary. Set
6938 waiting_for_stop_reply to 0 temporarily. */
6939 rs
->waiting_for_stop_reply
= 0;
6940 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6941 rs
->ctrlc_pending_p
= 0;
6942 /* GDB handled the File-I/O request, and the target is running
6943 again. Keep waiting for events. */
6944 rs
->waiting_for_stop_reply
= 1;
6946 case 'N': case 'T': case 'S': case 'X': case 'W':
6948 struct stop_reply
*stop_reply
;
6950 /* There is a stop reply to handle. */
6951 rs
->waiting_for_stop_reply
= 0;
6954 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6957 event_ptid
= process_stop_reply (stop_reply
, status
);
6960 case 'O': /* Console output. */
6961 remote_console_output (buf
+ 1);
6964 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6966 /* Zero length reply means that we tried 'S' or 'C' and the
6967 remote system doesn't support it. */
6968 target_terminal_ours_for_output ();
6970 ("Can't send signals to this remote system. %s not sent.\n",
6971 gdb_signal_to_name (rs
->last_sent_signal
));
6972 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6973 target_terminal_inferior ();
6975 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6976 putpkt ((char *) buf
);
6979 /* else fallthrough */
6981 warning (_("Invalid remote reply: %s"), buf
);
6985 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
6986 return minus_one_ptid
;
6987 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6989 /* Nothing interesting happened. If we're doing a non-blocking
6990 poll, we're done. Otherwise, go back to waiting. */
6991 if (options
& TARGET_WNOHANG
)
6992 return minus_one_ptid
;
6996 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6997 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6999 if (!ptid_equal (event_ptid
, null_ptid
))
7000 record_currthread (rs
, event_ptid
);
7002 event_ptid
= inferior_ptid
;
7005 /* A process exit. Invalidate our notion of current thread. */
7006 record_currthread (rs
, minus_one_ptid
);
7011 /* Wait until the remote machine stops, then return, storing status in
7012 STATUS just as `wait' would. */
7015 remote_wait (struct target_ops
*ops
,
7016 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7020 if (target_is_non_stop_p ())
7021 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7023 event_ptid
= remote_wait_as (ptid
, status
, options
);
7025 if (target_is_async_p ())
7027 /* If there are are events left in the queue tell the event loop
7029 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7030 mark_async_event_handler (remote_async_inferior_event_token
);
7036 /* Fetch a single register using a 'p' packet. */
7039 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7041 struct remote_state
*rs
= get_remote_state ();
7043 char regp
[MAX_REGISTER_SIZE
];
7046 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7049 if (reg
->pnum
== -1)
7054 p
+= hexnumstr (p
, reg
->pnum
);
7057 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7061 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7065 case PACKET_UNKNOWN
:
7068 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7069 gdbarch_register_name (get_regcache_arch (regcache
),
7074 /* If this register is unfetchable, tell the regcache. */
7077 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7081 /* Otherwise, parse and supply the value. */
7087 error (_("fetch_register_using_p: early buf termination"));
7089 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7092 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7096 /* Fetch the registers included in the target's 'g' packet. */
7099 send_g_packet (void)
7101 struct remote_state
*rs
= get_remote_state ();
7104 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7105 remote_send (&rs
->buf
, &rs
->buf_size
);
7107 /* We can get out of synch in various cases. If the first character
7108 in the buffer is not a hex character, assume that has happened
7109 and try to fetch another packet to read. */
7110 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7111 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7112 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7113 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7116 fprintf_unfiltered (gdb_stdlog
,
7117 "Bad register packet; fetching a new packet\n");
7118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7121 buf_len
= strlen (rs
->buf
);
7123 /* Sanity check the received packet. */
7124 if (buf_len
% 2 != 0)
7125 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7131 process_g_packet (struct regcache
*regcache
)
7133 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7134 struct remote_state
*rs
= get_remote_state ();
7135 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7140 buf_len
= strlen (rs
->buf
);
7142 /* Further sanity checks, with knowledge of the architecture. */
7143 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7144 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7146 /* Save the size of the packet sent to us by the target. It is used
7147 as a heuristic when determining the max size of packets that the
7148 target can safely receive. */
7149 if (rsa
->actual_register_packet_size
== 0)
7150 rsa
->actual_register_packet_size
= buf_len
;
7152 /* If this is smaller than we guessed the 'g' packet would be,
7153 update our records. A 'g' reply that doesn't include a register's
7154 value implies either that the register is not available, or that
7155 the 'p' packet must be used. */
7156 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7158 rsa
->sizeof_g_packet
= buf_len
/ 2;
7160 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7162 if (rsa
->regs
[i
].pnum
== -1)
7165 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7166 rsa
->regs
[i
].in_g_packet
= 0;
7168 rsa
->regs
[i
].in_g_packet
= 1;
7172 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7174 /* Unimplemented registers read as all bits zero. */
7175 memset (regs
, 0, rsa
->sizeof_g_packet
);
7177 /* Reply describes registers byte by byte, each byte encoded as two
7178 hex characters. Suck them all up, then supply them to the
7179 register cacheing/storage mechanism. */
7182 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7184 if (p
[0] == 0 || p
[1] == 0)
7185 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7186 internal_error (__FILE__
, __LINE__
,
7187 _("unexpected end of 'g' packet reply"));
7189 if (p
[0] == 'x' && p
[1] == 'x')
7190 regs
[i
] = 0; /* 'x' */
7192 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7196 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7198 struct packet_reg
*r
= &rsa
->regs
[i
];
7202 if (r
->offset
* 2 >= strlen (rs
->buf
))
7203 /* This shouldn't happen - we adjusted in_g_packet above. */
7204 internal_error (__FILE__
, __LINE__
,
7205 _("unexpected end of 'g' packet reply"));
7206 else if (rs
->buf
[r
->offset
* 2] == 'x')
7208 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7209 /* The register isn't available, mark it as such (at
7210 the same time setting the value to zero). */
7211 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7214 regcache_raw_supply (regcache
, r
->regnum
,
7221 fetch_registers_using_g (struct regcache
*regcache
)
7224 process_g_packet (regcache
);
7227 /* Make the remote selected traceframe match GDB's selected
7231 set_remote_traceframe (void)
7234 struct remote_state
*rs
= get_remote_state ();
7236 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7239 /* Avoid recursion, remote_trace_find calls us again. */
7240 rs
->remote_traceframe_number
= get_traceframe_number ();
7242 newnum
= target_trace_find (tfind_number
,
7243 get_traceframe_number (), 0, 0, NULL
);
7245 /* Should not happen. If it does, all bets are off. */
7246 if (newnum
!= get_traceframe_number ())
7247 warning (_("could not set remote traceframe"));
7251 remote_fetch_registers (struct target_ops
*ops
,
7252 struct regcache
*regcache
, int regnum
)
7254 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7257 set_remote_traceframe ();
7258 set_general_thread (inferior_ptid
);
7262 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7264 gdb_assert (reg
!= NULL
);
7266 /* If this register might be in the 'g' packet, try that first -
7267 we are likely to read more than one register. If this is the
7268 first 'g' packet, we might be overly optimistic about its
7269 contents, so fall back to 'p'. */
7270 if (reg
->in_g_packet
)
7272 fetch_registers_using_g (regcache
);
7273 if (reg
->in_g_packet
)
7277 if (fetch_register_using_p (regcache
, reg
))
7280 /* This register is not available. */
7281 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7286 fetch_registers_using_g (regcache
);
7288 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7289 if (!rsa
->regs
[i
].in_g_packet
)
7290 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7292 /* This register is not available. */
7293 regcache_raw_supply (regcache
, i
, NULL
);
7297 /* Prepare to store registers. Since we may send them all (using a
7298 'G' request), we have to read out the ones we don't want to change
7302 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7304 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7306 gdb_byte buf
[MAX_REGISTER_SIZE
];
7308 /* Make sure the entire registers array is valid. */
7309 switch (packet_support (PACKET_P
))
7311 case PACKET_DISABLE
:
7312 case PACKET_SUPPORT_UNKNOWN
:
7313 /* Make sure all the necessary registers are cached. */
7314 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7315 if (rsa
->regs
[i
].in_g_packet
)
7316 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7323 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7324 packet was not recognized. */
7327 store_register_using_P (const struct regcache
*regcache
,
7328 struct packet_reg
*reg
)
7330 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7331 struct remote_state
*rs
= get_remote_state ();
7332 /* Try storing a single register. */
7333 char *buf
= rs
->buf
;
7334 gdb_byte regp
[MAX_REGISTER_SIZE
];
7337 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7340 if (reg
->pnum
== -1)
7343 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7344 p
= buf
+ strlen (buf
);
7345 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7346 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7348 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7350 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7355 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7356 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7357 case PACKET_UNKNOWN
:
7360 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7364 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7365 contents of the register cache buffer. FIXME: ignores errors. */
7368 store_registers_using_G (const struct regcache
*regcache
)
7370 struct remote_state
*rs
= get_remote_state ();
7371 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7375 /* Extract all the registers in the regcache copying them into a
7380 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7381 memset (regs
, 0, rsa
->sizeof_g_packet
);
7382 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7384 struct packet_reg
*r
= &rsa
->regs
[i
];
7387 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7391 /* Command describes registers byte by byte,
7392 each byte encoded as two hex characters. */
7395 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7397 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7399 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7400 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7401 error (_("Could not write registers; remote failure reply '%s'"),
7405 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7406 of the register cache buffer. FIXME: ignores errors. */
7409 remote_store_registers (struct target_ops
*ops
,
7410 struct regcache
*regcache
, int regnum
)
7412 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7415 set_remote_traceframe ();
7416 set_general_thread (inferior_ptid
);
7420 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7422 gdb_assert (reg
!= NULL
);
7424 /* Always prefer to store registers using the 'P' packet if
7425 possible; we often change only a small number of registers.
7426 Sometimes we change a larger number; we'd need help from a
7427 higher layer to know to use 'G'. */
7428 if (store_register_using_P (regcache
, reg
))
7431 /* For now, don't complain if we have no way to write the
7432 register. GDB loses track of unavailable registers too
7433 easily. Some day, this may be an error. We don't have
7434 any way to read the register, either... */
7435 if (!reg
->in_g_packet
)
7438 store_registers_using_G (regcache
);
7442 store_registers_using_G (regcache
);
7444 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7445 if (!rsa
->regs
[i
].in_g_packet
)
7446 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7447 /* See above for why we do not issue an error here. */
7452 /* Return the number of hex digits in num. */
7455 hexnumlen (ULONGEST num
)
7459 for (i
= 0; num
!= 0; i
++)
7465 /* Set BUF to the minimum number of hex digits representing NUM. */
7468 hexnumstr (char *buf
, ULONGEST num
)
7470 int len
= hexnumlen (num
);
7472 return hexnumnstr (buf
, num
, len
);
7476 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7479 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7485 for (i
= width
- 1; i
>= 0; i
--)
7487 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7494 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7497 remote_address_masked (CORE_ADDR addr
)
7499 unsigned int address_size
= remote_address_size
;
7501 /* If "remoteaddresssize" was not set, default to target address size. */
7503 address_size
= gdbarch_addr_bit (target_gdbarch ());
7505 if (address_size
> 0
7506 && address_size
< (sizeof (ULONGEST
) * 8))
7508 /* Only create a mask when that mask can safely be constructed
7509 in a ULONGEST variable. */
7512 mask
= (mask
<< address_size
) - 1;
7518 /* Determine whether the remote target supports binary downloading.
7519 This is accomplished by sending a no-op memory write of zero length
7520 to the target at the specified address. It does not suffice to send
7521 the whole packet, since many stubs strip the eighth bit and
7522 subsequently compute a wrong checksum, which causes real havoc with
7525 NOTE: This can still lose if the serial line is not eight-bit
7526 clean. In cases like this, the user should clear "remote
7530 check_binary_download (CORE_ADDR addr
)
7532 struct remote_state
*rs
= get_remote_state ();
7534 switch (packet_support (PACKET_X
))
7536 case PACKET_DISABLE
:
7540 case PACKET_SUPPORT_UNKNOWN
:
7546 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7548 p
+= hexnumstr (p
, (ULONGEST
) 0);
7552 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7553 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7555 if (rs
->buf
[0] == '\0')
7558 fprintf_unfiltered (gdb_stdlog
,
7559 "binary downloading NOT "
7560 "supported by target\n");
7561 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7566 fprintf_unfiltered (gdb_stdlog
,
7567 "binary downloading supported by target\n");
7568 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7575 /* Helper function to resize the payload in order to try to get a good
7576 alignment. We try to write an amount of data such that the next write will
7577 start on an address aligned on REMOTE_ALIGN_WRITES. */
7580 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7582 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7585 /* Write memory data directly to the remote machine.
7586 This does not inform the data cache; the data cache uses this.
7587 HEADER is the starting part of the packet.
7588 MEMADDR is the address in the remote memory space.
7589 MYADDR is the address of the buffer in our space.
7590 LEN_UNITS is the number of addressable units to write.
7591 UNIT_SIZE is the length in bytes of an addressable unit.
7592 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7593 should send data as binary ('X'), or hex-encoded ('M').
7595 The function creates packet of the form
7596 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7598 where encoding of <DATA> is terminated by PACKET_FORMAT.
7600 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7603 Return the transferred status, error or OK (an
7604 'enum target_xfer_status' value). Save the number of addressable units
7605 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7607 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7608 exchange between gdb and the stub could look like (?? in place of the
7614 -> $M1000,3:eeeeffffeeee#??
7618 <- eeeeffffeeeedddd */
7620 static enum target_xfer_status
7621 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7622 const gdb_byte
*myaddr
, ULONGEST len_units
,
7623 int unit_size
, ULONGEST
*xfered_len_units
,
7624 char packet_format
, int use_length
)
7626 struct remote_state
*rs
= get_remote_state ();
7632 int payload_capacity_bytes
;
7633 int payload_length_bytes
;
7635 if (packet_format
!= 'X' && packet_format
!= 'M')
7636 internal_error (__FILE__
, __LINE__
,
7637 _("remote_write_bytes_aux: bad packet format"));
7640 return TARGET_XFER_EOF
;
7642 payload_capacity_bytes
= get_memory_write_packet_size ();
7644 /* The packet buffer will be large enough for the payload;
7645 get_memory_packet_size ensures this. */
7648 /* Compute the size of the actual payload by subtracting out the
7649 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7651 payload_capacity_bytes
-= strlen ("$,:#NN");
7653 /* The comma won't be used. */
7654 payload_capacity_bytes
+= 1;
7655 payload_capacity_bytes
-= strlen (header
);
7656 payload_capacity_bytes
-= hexnumlen (memaddr
);
7658 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7660 strcat (rs
->buf
, header
);
7661 p
= rs
->buf
+ strlen (header
);
7663 /* Compute a best guess of the number of bytes actually transfered. */
7664 if (packet_format
== 'X')
7666 /* Best guess at number of bytes that will fit. */
7667 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7669 payload_capacity_bytes
-= hexnumlen (todo_units
);
7670 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7674 /* Number of bytes that will fit. */
7675 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7677 payload_capacity_bytes
-= hexnumlen (todo_units
);
7678 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7681 if (todo_units
<= 0)
7682 internal_error (__FILE__
, __LINE__
,
7683 _("minimum packet size too small to write data"));
7685 /* If we already need another packet, then try to align the end
7686 of this packet to a useful boundary. */
7687 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7688 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7690 /* Append "<memaddr>". */
7691 memaddr
= remote_address_masked (memaddr
);
7692 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7699 /* Append the length and retain its location and size. It may need to be
7700 adjusted once the packet body has been created. */
7702 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7710 /* Append the packet body. */
7711 if (packet_format
== 'X')
7713 /* Binary mode. Send target system values byte by byte, in
7714 increasing byte addresses. Only escape certain critical
7716 payload_length_bytes
=
7717 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7718 &units_written
, payload_capacity_bytes
);
7720 /* If not all TODO units fit, then we'll need another packet. Make
7721 a second try to keep the end of the packet aligned. Don't do
7722 this if the packet is tiny. */
7723 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7727 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7729 if (new_todo_units
!= units_written
)
7730 payload_length_bytes
=
7731 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7732 (gdb_byte
*) p
, &units_written
,
7733 payload_capacity_bytes
);
7736 p
+= payload_length_bytes
;
7737 if (use_length
&& units_written
< todo_units
)
7739 /* Escape chars have filled up the buffer prematurely,
7740 and we have actually sent fewer units than planned.
7741 Fix-up the length field of the packet. Use the same
7742 number of characters as before. */
7743 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7745 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7750 /* Normal mode: Send target system values byte by byte, in
7751 increasing byte addresses. Each byte is encoded as a two hex
7753 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7754 units_written
= todo_units
;
7757 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7758 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7760 if (rs
->buf
[0] == 'E')
7761 return TARGET_XFER_E_IO
;
7763 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7764 send fewer units than we'd planned. */
7765 *xfered_len_units
= (ULONGEST
) units_written
;
7766 return TARGET_XFER_OK
;
7769 /* Write memory data directly to the remote machine.
7770 This does not inform the data cache; the data cache uses this.
7771 MEMADDR is the address in the remote memory space.
7772 MYADDR is the address of the buffer in our space.
7773 LEN is the number of bytes.
7775 Return the transferred status, error or OK (an
7776 'enum target_xfer_status' value). Save the number of bytes
7777 transferred in *XFERED_LEN. Only transfer a single packet. */
7779 static enum target_xfer_status
7780 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7781 int unit_size
, ULONGEST
*xfered_len
)
7783 char *packet_format
= 0;
7785 /* Check whether the target supports binary download. */
7786 check_binary_download (memaddr
);
7788 switch (packet_support (PACKET_X
))
7791 packet_format
= "X";
7793 case PACKET_DISABLE
:
7794 packet_format
= "M";
7796 case PACKET_SUPPORT_UNKNOWN
:
7797 internal_error (__FILE__
, __LINE__
,
7798 _("remote_write_bytes: bad internal state"));
7800 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7803 return remote_write_bytes_aux (packet_format
,
7804 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7805 packet_format
[0], 1);
7808 /* Read memory data directly from the remote machine.
7809 This does not use the data cache; the data cache uses this.
7810 MEMADDR is the address in the remote memory space.
7811 MYADDR is the address of the buffer in our space.
7812 LEN_UNITS is the number of addressable memory units to read..
7813 UNIT_SIZE is the length in bytes of an addressable unit.
7815 Return the transferred status, error or OK (an
7816 'enum target_xfer_status' value). Save the number of bytes
7817 transferred in *XFERED_LEN_UNITS.
7819 See the comment of remote_write_bytes_aux for an example of
7820 memory read/write exchange between gdb and the stub. */
7822 static enum target_xfer_status
7823 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7824 int unit_size
, ULONGEST
*xfered_len_units
)
7826 struct remote_state
*rs
= get_remote_state ();
7827 int buf_size_bytes
; /* Max size of packet output buffer. */
7832 buf_size_bytes
= get_memory_read_packet_size ();
7833 /* The packet buffer will be large enough for the payload;
7834 get_memory_packet_size ensures this. */
7836 /* Number of units that will fit. */
7837 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7839 /* Construct "m"<memaddr>","<len>". */
7840 memaddr
= remote_address_masked (memaddr
);
7843 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7845 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7848 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7849 if (rs
->buf
[0] == 'E'
7850 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7851 && rs
->buf
[3] == '\0')
7852 return TARGET_XFER_E_IO
;
7853 /* Reply describes memory byte by byte, each byte encoded as two hex
7856 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7857 /* Return what we have. Let higher layers handle partial reads. */
7858 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7859 return TARGET_XFER_OK
;
7862 /* Using the set of read-only target sections of remote, read live
7865 For interface/parameters/return description see target.h,
7868 static enum target_xfer_status
7869 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7870 ULONGEST memaddr
, ULONGEST len
,
7871 int unit_size
, ULONGEST
*xfered_len
)
7873 struct target_section
*secp
;
7874 struct target_section_table
*table
;
7876 secp
= target_section_by_addr (ops
, memaddr
);
7878 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7879 secp
->the_bfd_section
)
7882 struct target_section
*p
;
7883 ULONGEST memend
= memaddr
+ len
;
7885 table
= target_get_section_table (ops
);
7887 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7889 if (memaddr
>= p
->addr
)
7891 if (memend
<= p
->endaddr
)
7893 /* Entire transfer is within this section. */
7894 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7897 else if (memaddr
>= p
->endaddr
)
7899 /* This section ends before the transfer starts. */
7904 /* This section overlaps the transfer. Just do half. */
7905 len
= p
->endaddr
- memaddr
;
7906 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7913 return TARGET_XFER_EOF
;
7916 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7917 first if the requested memory is unavailable in traceframe.
7918 Otherwise, fall back to remote_read_bytes_1. */
7920 static enum target_xfer_status
7921 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7922 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7923 ULONGEST
*xfered_len
)
7926 return TARGET_XFER_EOF
;
7928 if (get_traceframe_number () != -1)
7930 VEC(mem_range_s
) *available
;
7932 /* If we fail to get the set of available memory, then the
7933 target does not support querying traceframe info, and so we
7934 attempt reading from the traceframe anyway (assuming the
7935 target implements the old QTro packet then). */
7936 if (traceframe_available_memory (&available
, memaddr
, len
))
7938 struct cleanup
*old_chain
;
7940 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7942 if (VEC_empty (mem_range_s
, available
)
7943 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7945 enum target_xfer_status res
;
7947 /* Don't read into the traceframe's available
7949 if (!VEC_empty (mem_range_s
, available
))
7951 LONGEST oldlen
= len
;
7953 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7954 gdb_assert (len
<= oldlen
);
7957 do_cleanups (old_chain
);
7959 /* This goes through the topmost target again. */
7960 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7961 len
, unit_size
, xfered_len
);
7962 if (res
== TARGET_XFER_OK
)
7963 return TARGET_XFER_OK
;
7966 /* No use trying further, we know some memory starting
7967 at MEMADDR isn't available. */
7969 return TARGET_XFER_UNAVAILABLE
;
7973 /* Don't try to read more than how much is available, in
7974 case the target implements the deprecated QTro packet to
7975 cater for older GDBs (the target's knowledge of read-only
7976 sections may be outdated by now). */
7977 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7979 do_cleanups (old_chain
);
7983 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7988 /* Sends a packet with content determined by the printf format string
7989 FORMAT and the remaining arguments, then gets the reply. Returns
7990 whether the packet was a success, a failure, or unknown. */
7992 static enum packet_result
remote_send_printf (const char *format
, ...)
7993 ATTRIBUTE_PRINTF (1, 2);
7995 static enum packet_result
7996 remote_send_printf (const char *format
, ...)
7998 struct remote_state
*rs
= get_remote_state ();
7999 int max_size
= get_remote_packet_size ();
8002 va_start (ap
, format
);
8005 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8006 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8008 if (putpkt (rs
->buf
) < 0)
8009 error (_("Communication problem with target."));
8012 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8014 return packet_check_result (rs
->buf
);
8018 restore_remote_timeout (void *p
)
8020 int value
= *(int *)p
;
8022 remote_timeout
= value
;
8025 /* Flash writing can take quite some time. We'll set
8026 effectively infinite timeout for flash operations.
8027 In future, we'll need to decide on a better approach. */
8028 static const int remote_flash_timeout
= 1000;
8031 remote_flash_erase (struct target_ops
*ops
,
8032 ULONGEST address
, LONGEST length
)
8034 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8035 int saved_remote_timeout
= remote_timeout
;
8036 enum packet_result ret
;
8037 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8038 &saved_remote_timeout
);
8040 remote_timeout
= remote_flash_timeout
;
8042 ret
= remote_send_printf ("vFlashErase:%s,%s",
8043 phex (address
, addr_size
),
8047 case PACKET_UNKNOWN
:
8048 error (_("Remote target does not support flash erase"));
8050 error (_("Error erasing flash with vFlashErase packet"));
8055 do_cleanups (back_to
);
8058 static enum target_xfer_status
8059 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8060 ULONGEST length
, ULONGEST
*xfered_len
,
8061 const gdb_byte
*data
)
8063 int saved_remote_timeout
= remote_timeout
;
8064 enum target_xfer_status ret
;
8065 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8066 &saved_remote_timeout
);
8068 remote_timeout
= remote_flash_timeout
;
8069 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8071 do_cleanups (back_to
);
8077 remote_flash_done (struct target_ops
*ops
)
8079 int saved_remote_timeout
= remote_timeout
;
8081 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8082 &saved_remote_timeout
);
8084 remote_timeout
= remote_flash_timeout
;
8085 ret
= remote_send_printf ("vFlashDone");
8086 do_cleanups (back_to
);
8090 case PACKET_UNKNOWN
:
8091 error (_("Remote target does not support vFlashDone"));
8093 error (_("Error finishing flash operation"));
8100 remote_files_info (struct target_ops
*ignore
)
8102 puts_filtered ("Debugging a target over a serial line.\n");
8105 /* Stuff for dealing with the packets which are part of this protocol.
8106 See comment at top of file for details. */
8108 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8109 error to higher layers. Called when a serial error is detected.
8110 The exception message is STRING, followed by a colon and a blank,
8111 the system error message for errno at function entry and final dot
8112 for output compatibility with throw_perror_with_name. */
8115 unpush_and_perror (const char *string
)
8117 int saved_errno
= errno
;
8119 remote_unpush_target ();
8120 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8121 safe_strerror (saved_errno
));
8124 /* Read a single character from the remote end. The current quit
8125 handler is overridden to avoid quitting in the middle of packet
8126 sequence, as that would break communication with the remote server.
8127 See remote_serial_quit_handler for more detail. */
8130 readchar (int timeout
)
8133 struct remote_state
*rs
= get_remote_state ();
8134 struct cleanup
*old_chain
;
8136 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8138 rs
->got_ctrlc_during_io
= 0;
8140 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8142 if (rs
->got_ctrlc_during_io
)
8145 do_cleanups (old_chain
);
8150 switch ((enum serial_rc
) ch
)
8153 remote_unpush_target ();
8154 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8157 unpush_and_perror (_("Remote communication error. "
8158 "Target disconnected."));
8160 case SERIAL_TIMEOUT
:
8166 /* Wrapper for serial_write that closes the target and throws if
8167 writing fails. The current quit handler is overridden to avoid
8168 quitting in the middle of packet sequence, as that would break
8169 communication with the remote server. See
8170 remote_serial_quit_handler for more detail. */
8173 remote_serial_write (const char *str
, int len
)
8175 struct remote_state
*rs
= get_remote_state ();
8176 struct cleanup
*old_chain
;
8178 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8180 rs
->got_ctrlc_during_io
= 0;
8182 if (serial_write (rs
->remote_desc
, str
, len
))
8184 unpush_and_perror (_("Remote communication error. "
8185 "Target disconnected."));
8188 if (rs
->got_ctrlc_during_io
)
8191 do_cleanups (old_chain
);
8194 /* Send the command in *BUF to the remote machine, and read the reply
8195 into *BUF. Report an error if we get an error reply. Resize
8196 *BUF using xrealloc if necessary to hold the result, and update
8200 remote_send (char **buf
,
8204 getpkt (buf
, sizeof_buf
, 0);
8206 if ((*buf
)[0] == 'E')
8207 error (_("Remote failure reply: %s"), *buf
);
8210 /* Return a pointer to an xmalloc'ed string representing an escaped
8211 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8212 etc. The caller is responsible for releasing the returned
8216 escape_buffer (const char *buf
, int n
)
8218 struct cleanup
*old_chain
;
8219 struct ui_file
*stb
;
8222 stb
= mem_fileopen ();
8223 old_chain
= make_cleanup_ui_file_delete (stb
);
8225 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8226 str
= ui_file_xstrdup (stb
, NULL
);
8227 do_cleanups (old_chain
);
8231 /* Display a null-terminated packet on stdout, for debugging, using C
8235 print_packet (const char *buf
)
8237 puts_filtered ("\"");
8238 fputstr_filtered (buf
, '"', gdb_stdout
);
8239 puts_filtered ("\"");
8243 putpkt (const char *buf
)
8245 return putpkt_binary (buf
, strlen (buf
));
8248 /* Send a packet to the remote machine, with error checking. The data
8249 of the packet is in BUF. The string in BUF can be at most
8250 get_remote_packet_size () - 5 to account for the $, # and checksum,
8251 and for a possible /0 if we are debugging (remote_debug) and want
8252 to print the sent packet as a string. */
8255 putpkt_binary (const char *buf
, int cnt
)
8257 struct remote_state
*rs
= get_remote_state ();
8259 unsigned char csum
= 0;
8260 char *buf2
= (char *) xmalloc (cnt
+ 6);
8261 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8267 /* Catch cases like trying to read memory or listing threads while
8268 we're waiting for a stop reply. The remote server wouldn't be
8269 ready to handle this request, so we'd hang and timeout. We don't
8270 have to worry about this in synchronous mode, because in that
8271 case it's not possible to issue a command while the target is
8272 running. This is not a problem in non-stop mode, because in that
8273 case, the stub is always ready to process serial input. */
8274 if (!target_is_non_stop_p ()
8275 && target_is_async_p ()
8276 && rs
->waiting_for_stop_reply
)
8278 error (_("Cannot execute this command while the target is running.\n"
8279 "Use the \"interrupt\" command to stop the target\n"
8280 "and then try again."));
8283 /* We're sending out a new packet. Make sure we don't look at a
8284 stale cached response. */
8285 rs
->cached_wait_status
= 0;
8287 /* Copy the packet into buffer BUF2, encapsulating it
8288 and giving it a checksum. */
8293 for (i
= 0; i
< cnt
; i
++)
8299 *p
++ = tohex ((csum
>> 4) & 0xf);
8300 *p
++ = tohex (csum
& 0xf);
8302 /* Send it over and over until we get a positive ack. */
8306 int started_error_output
= 0;
8310 struct cleanup
*old_chain
;
8314 str
= escape_buffer (buf2
, p
- buf2
);
8315 old_chain
= make_cleanup (xfree
, str
);
8316 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8317 gdb_flush (gdb_stdlog
);
8318 do_cleanups (old_chain
);
8320 remote_serial_write (buf2
, p
- buf2
);
8322 /* If this is a no acks version of the remote protocol, send the
8323 packet and move on. */
8327 /* Read until either a timeout occurs (-2) or '+' is read.
8328 Handle any notification that arrives in the mean time. */
8331 ch
= readchar (remote_timeout
);
8339 case SERIAL_TIMEOUT
:
8342 if (started_error_output
)
8344 putchar_unfiltered ('\n');
8345 started_error_output
= 0;
8354 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8355 do_cleanups (old_chain
);
8359 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8361 case SERIAL_TIMEOUT
:
8365 do_cleanups (old_chain
);
8368 break; /* Retransmit buffer. */
8372 fprintf_unfiltered (gdb_stdlog
,
8373 "Packet instead of Ack, ignoring it\n");
8374 /* It's probably an old response sent because an ACK
8375 was lost. Gobble up the packet and ack it so it
8376 doesn't get retransmitted when we resend this
8379 remote_serial_write ("+", 1);
8380 continue; /* Now, go look for +. */
8387 /* If we got a notification, handle it, and go back to looking
8389 /* We've found the start of a notification. Now
8390 collect the data. */
8391 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8396 struct cleanup
*old_chain
;
8399 str
= escape_buffer (rs
->buf
, val
);
8400 old_chain
= make_cleanup (xfree
, str
);
8401 fprintf_unfiltered (gdb_stdlog
,
8402 " Notification received: %s\n",
8404 do_cleanups (old_chain
);
8406 handle_notification (rs
->notif_state
, rs
->buf
);
8407 /* We're in sync now, rewait for the ack. */
8414 if (!started_error_output
)
8416 started_error_output
= 1;
8417 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8419 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8420 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8429 if (!started_error_output
)
8431 started_error_output
= 1;
8432 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8434 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8438 break; /* Here to retransmit. */
8442 /* This is wrong. If doing a long backtrace, the user should be
8443 able to get out next time we call QUIT, without anything as
8444 violent as interrupt_query. If we want to provide a way out of
8445 here without getting to the next QUIT, it should be based on
8446 hitting ^C twice as in remote_wait. */
8455 do_cleanups (old_chain
);
8459 /* Come here after finding the start of a frame when we expected an
8460 ack. Do our best to discard the rest of this packet. */
8469 c
= readchar (remote_timeout
);
8472 case SERIAL_TIMEOUT
:
8473 /* Nothing we can do. */
8476 /* Discard the two bytes of checksum and stop. */
8477 c
= readchar (remote_timeout
);
8479 c
= readchar (remote_timeout
);
8482 case '*': /* Run length encoding. */
8483 /* Discard the repeat count. */
8484 c
= readchar (remote_timeout
);
8489 /* A regular character. */
8495 /* Come here after finding the start of the frame. Collect the rest
8496 into *BUF, verifying the checksum, length, and handling run-length
8497 compression. NUL terminate the buffer. If there is not enough room,
8498 expand *BUF using xrealloc.
8500 Returns -1 on error, number of characters in buffer (ignoring the
8501 trailing NULL) on success. (could be extended to return one of the
8502 SERIAL status indications). */
8505 read_frame (char **buf_p
,
8512 struct remote_state
*rs
= get_remote_state ();
8519 c
= readchar (remote_timeout
);
8522 case SERIAL_TIMEOUT
:
8524 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8528 fputs_filtered ("Saw new packet start in middle of old one\n",
8530 return -1; /* Start a new packet, count retries. */
8533 unsigned char pktcsum
;
8539 check_0
= readchar (remote_timeout
);
8541 check_1
= readchar (remote_timeout
);
8543 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8546 fputs_filtered ("Timeout in checksum, retrying\n",
8550 else if (check_0
< 0 || check_1
< 0)
8553 fputs_filtered ("Communication error in checksum\n",
8558 /* Don't recompute the checksum; with no ack packets we
8559 don't have any way to indicate a packet retransmission
8564 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8565 if (csum
== pktcsum
)
8570 struct cleanup
*old_chain
;
8573 str
= escape_buffer (buf
, bc
);
8574 old_chain
= make_cleanup (xfree
, str
);
8575 fprintf_unfiltered (gdb_stdlog
,
8576 "Bad checksum, sentsum=0x%x, "
8577 "csum=0x%x, buf=%s\n",
8578 pktcsum
, csum
, str
);
8579 do_cleanups (old_chain
);
8581 /* Number of characters in buffer ignoring trailing
8585 case '*': /* Run length encoding. */
8590 c
= readchar (remote_timeout
);
8592 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8594 /* The character before ``*'' is repeated. */
8596 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8598 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8600 /* Make some more room in the buffer. */
8601 *sizeof_buf
+= repeat
;
8602 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8606 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8612 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8616 if (bc
>= *sizeof_buf
- 1)
8618 /* Make some more room in the buffer. */
8620 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8631 /* Read a packet from the remote machine, with error checking, and
8632 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8633 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8634 rather than timing out; this is used (in synchronous mode) to wait
8635 for a target that is is executing user code to stop. */
8636 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8637 don't have to change all the calls to getpkt to deal with the
8638 return value, because at the moment I don't know what the right
8639 thing to do it for those. */
8645 getpkt_sane (buf
, sizeof_buf
, forever
);
8649 /* Read a packet from the remote machine, with error checking, and
8650 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8651 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8652 rather than timing out; this is used (in synchronous mode) to wait
8653 for a target that is is executing user code to stop. If FOREVER ==
8654 0, this function is allowed to time out gracefully and return an
8655 indication of this to the caller. Otherwise return the number of
8656 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8657 enough reason to return to the caller. *IS_NOTIF is an output
8658 boolean that indicates whether *BUF holds a notification or not
8659 (a regular packet). */
8662 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8663 int expecting_notif
, int *is_notif
)
8665 struct remote_state
*rs
= get_remote_state ();
8671 /* We're reading a new response. Make sure we don't look at a
8672 previously cached response. */
8673 rs
->cached_wait_status
= 0;
8675 strcpy (*buf
, "timeout");
8678 timeout
= watchdog
> 0 ? watchdog
: -1;
8679 else if (expecting_notif
)
8680 timeout
= 0; /* There should already be a char in the buffer. If
8683 timeout
= remote_timeout
;
8687 /* Process any number of notifications, and then return when
8691 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8693 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8695 /* This can loop forever if the remote side sends us
8696 characters continuously, but if it pauses, we'll get
8697 SERIAL_TIMEOUT from readchar because of timeout. Then
8698 we'll count that as a retry.
8700 Note that even when forever is set, we will only wait
8701 forever prior to the start of a packet. After that, we
8702 expect characters to arrive at a brisk pace. They should
8703 show up within remote_timeout intervals. */
8705 c
= readchar (timeout
);
8706 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8708 if (c
== SERIAL_TIMEOUT
)
8710 if (expecting_notif
)
8711 return -1; /* Don't complain, it's normal to not get
8712 anything in this case. */
8714 if (forever
) /* Watchdog went off? Kill the target. */
8716 remote_unpush_target ();
8717 throw_error (TARGET_CLOSE_ERROR
,
8718 _("Watchdog timeout has expired. "
8719 "Target detached."));
8722 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8726 /* We've found the start of a packet or notification.
8727 Now collect the data. */
8728 val
= read_frame (buf
, sizeof_buf
);
8733 remote_serial_write ("-", 1);
8736 if (tries
> MAX_TRIES
)
8738 /* We have tried hard enough, and just can't receive the
8739 packet/notification. Give up. */
8740 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8742 /* Skip the ack char if we're in no-ack mode. */
8743 if (!rs
->noack_mode
)
8744 remote_serial_write ("+", 1);
8748 /* If we got an ordinary packet, return that to our caller. */
8753 struct cleanup
*old_chain
;
8756 str
= escape_buffer (*buf
, val
);
8757 old_chain
= make_cleanup (xfree
, str
);
8758 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8759 do_cleanups (old_chain
);
8762 /* Skip the ack char if we're in no-ack mode. */
8763 if (!rs
->noack_mode
)
8764 remote_serial_write ("+", 1);
8765 if (is_notif
!= NULL
)
8770 /* If we got a notification, handle it, and go back to looking
8774 gdb_assert (c
== '%');
8778 struct cleanup
*old_chain
;
8781 str
= escape_buffer (*buf
, val
);
8782 old_chain
= make_cleanup (xfree
, str
);
8783 fprintf_unfiltered (gdb_stdlog
,
8784 " Notification received: %s\n",
8786 do_cleanups (old_chain
);
8788 if (is_notif
!= NULL
)
8791 handle_notification (rs
->notif_state
, *buf
);
8793 /* Notifications require no acknowledgement. */
8795 if (expecting_notif
)
8802 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8804 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8808 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8811 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8815 /* Check whether EVENT is a fork event for the process specified
8816 by the pid passed in DATA, and if it is, kill the fork child. */
8819 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8820 QUEUE_ITER (stop_reply_p
) *iter
,
8824 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8825 int parent_pid
= *(int *) param
->input
;
8827 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8829 struct remote_state
*rs
= get_remote_state ();
8830 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8833 res
= remote_vkill (child_pid
, rs
);
8835 error (_("Can't kill fork child process %d"), child_pid
);
8841 /* Kill any new fork children of process PID that haven't been
8842 processed by follow_fork. */
8845 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8847 struct thread_info
*thread
;
8848 struct notif_client
*notif
= ¬if_client_stop
;
8849 struct queue_iter_param param
;
8851 /* Kill the fork child threads of any threads in process PID
8852 that are stopped at a fork event. */
8853 ALL_NON_EXITED_THREADS (thread
)
8855 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8857 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8859 struct remote_state
*rs
= get_remote_state ();
8860 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8863 res
= remote_vkill (child_pid
, rs
);
8865 error (_("Can't kill fork child process %d"), child_pid
);
8869 /* Check for any pending fork events (not reported or processed yet)
8870 in process PID and kill those fork child threads as well. */
8871 remote_notif_get_pending_events (notif
);
8873 param
.output
= NULL
;
8874 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8875 kill_child_of_pending_fork
, ¶m
);
8879 /* Target hook to kill the current inferior. */
8882 remote_kill (struct target_ops
*ops
)
8885 int pid
= ptid_get_pid (inferior_ptid
);
8886 struct remote_state
*rs
= get_remote_state ();
8888 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
8890 /* If we're stopped while forking and we haven't followed yet,
8891 kill the child task. We need to do this before killing the
8892 parent task because if this is a vfork then the parent will
8894 kill_new_fork_children (pid
, rs
);
8896 res
= remote_vkill (pid
, rs
);
8899 target_mourn_inferior ();
8904 /* If we are in 'target remote' mode and we are killing the only
8905 inferior, then we will tell gdbserver to exit and unpush the
8907 if (res
== -1 && !remote_multi_process_p (rs
)
8908 && number_of_live_inferiors () == 1)
8912 /* We've killed the remote end, we get to mourn it. If we are
8913 not in extended mode, mourning the inferior also unpushes
8914 remote_ops from the target stack, which closes the remote
8916 target_mourn_inferior ();
8921 error (_("Can't kill process"));
8924 /* Send a kill request to the target using the 'vKill' packet. */
8927 remote_vkill (int pid
, struct remote_state
*rs
)
8929 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8932 /* Tell the remote target to detach. */
8933 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8935 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8937 switch (packet_ok (rs
->buf
,
8938 &remote_protocol_packets
[PACKET_vKill
]))
8944 case PACKET_UNKNOWN
:
8947 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8951 /* Send a kill request to the target using the 'k' packet. */
8954 remote_kill_k (void)
8956 /* Catch errors so the user can quit from gdb even when we
8957 aren't on speaking terms with the remote system. */
8962 CATCH (ex
, RETURN_MASK_ERROR
)
8964 if (ex
.error
== TARGET_CLOSE_ERROR
)
8966 /* If we got an (EOF) error that caused the target
8967 to go away, then we're done, that's what we wanted.
8968 "k" is susceptible to cause a premature EOF, given
8969 that the remote server isn't actually required to
8970 reply to "k", and it can happen that it doesn't
8971 even get to reply ACK to the "k". */
8975 /* Otherwise, something went wrong. We didn't actually kill
8976 the target. Just propagate the exception, and let the
8977 user or higher layers decide what to do. */
8978 throw_exception (ex
);
8984 remote_mourn (struct target_ops
*target
)
8986 struct remote_state
*rs
= get_remote_state ();
8988 /* In 'target remote' mode with one inferior, we close the connection. */
8989 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
8991 unpush_target (target
);
8993 /* remote_close takes care of doing most of the clean up. */
8994 generic_mourn_inferior ();
8998 /* In case we got here due to an error, but we're going to stay
9000 rs
->waiting_for_stop_reply
= 0;
9002 /* If the current general thread belonged to the process we just
9003 detached from or has exited, the remote side current general
9004 thread becomes undefined. Considering a case like this:
9006 - We just got here due to a detach.
9007 - The process that we're detaching from happens to immediately
9008 report a global breakpoint being hit in non-stop mode, in the
9009 same thread we had selected before.
9010 - GDB attaches to this process again.
9011 - This event happens to be the next event we handle.
9013 GDB would consider that the current general thread didn't need to
9014 be set on the stub side (with Hg), since for all it knew,
9015 GENERAL_THREAD hadn't changed.
9017 Notice that although in all-stop mode, the remote server always
9018 sets the current thread to the thread reporting the stop event,
9019 that doesn't happen in non-stop mode; in non-stop, the stub *must
9020 not* change the current thread when reporting a breakpoint hit,
9021 due to the decoupling of event reporting and event handling.
9023 To keep things simple, we always invalidate our notion of the
9025 record_currthread (rs
, minus_one_ptid
);
9027 /* Call common code to mark the inferior as not running. */
9028 generic_mourn_inferior ();
9030 if (!have_inferiors ())
9032 if (!remote_multi_process_p (rs
))
9034 /* Check whether the target is running now - some remote stubs
9035 automatically restart after kill. */
9037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9039 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9041 /* Assume that the target has been restarted. Set
9042 inferior_ptid so that bits of core GDB realizes
9043 there's something here, e.g., so that the user can
9044 say "kill" again. */
9045 inferior_ptid
= magic_null_ptid
;
9052 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9054 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9058 extended_remote_disable_randomization (int val
)
9060 struct remote_state
*rs
= get_remote_state ();
9063 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9066 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9068 error (_("Target does not support QDisableRandomization."));
9069 if (strcmp (reply
, "OK") != 0)
9070 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9074 extended_remote_run (char *args
)
9076 struct remote_state
*rs
= get_remote_state ();
9078 const char *remote_exec_file
= get_remote_exec_file ();
9080 /* If the user has disabled vRun support, or we have detected that
9081 support is not available, do not try it. */
9082 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9085 strcpy (rs
->buf
, "vRun;");
9086 len
= strlen (rs
->buf
);
9088 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9089 error (_("Remote file name too long for run packet"));
9090 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9091 strlen (remote_exec_file
));
9093 gdb_assert (args
!= NULL
);
9096 struct cleanup
*back_to
;
9100 argv
= gdb_buildargv (args
);
9101 back_to
= make_cleanup_freeargv (argv
);
9102 for (i
= 0; argv
[i
] != NULL
; i
++)
9104 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9105 error (_("Argument list too long for run packet"));
9106 rs
->buf
[len
++] = ';';
9107 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9110 do_cleanups (back_to
);
9113 rs
->buf
[len
++] = '\0';
9116 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9118 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9121 /* We have a wait response. All is well. */
9123 case PACKET_UNKNOWN
:
9126 if (remote_exec_file
[0] == '\0')
9127 error (_("Running the default executable on the remote target failed; "
9128 "try \"set remote exec-file\"?"));
9130 error (_("Running \"%s\" on the remote target failed"),
9133 gdb_assert_not_reached (_("bad switch"));
9137 /* In the extended protocol we want to be able to do things like
9138 "run" and have them basically work as expected. So we need
9139 a special create_inferior function. We support changing the
9140 executable file and the command line arguments, but not the
9144 extended_remote_create_inferior (struct target_ops
*ops
,
9145 char *exec_file
, char *args
,
9146 char **env
, int from_tty
)
9150 struct remote_state
*rs
= get_remote_state ();
9151 const char *remote_exec_file
= get_remote_exec_file ();
9153 /* If running asynchronously, register the target file descriptor
9154 with the event loop. */
9155 if (target_can_async_p ())
9158 /* Disable address space randomization if requested (and supported). */
9159 if (extended_remote_supports_disable_randomization (ops
))
9160 extended_remote_disable_randomization (disable_randomization
);
9162 /* Now restart the remote server. */
9163 run_worked
= extended_remote_run (args
) != -1;
9166 /* vRun was not supported. Fail if we need it to do what the
9168 if (remote_exec_file
[0])
9169 error (_("Remote target does not support \"set remote exec-file\""));
9171 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9173 /* Fall back to "R". */
9174 extended_remote_restart ();
9177 if (!have_inferiors ())
9179 /* Clean up from the last time we ran, before we mark the target
9180 running again. This will mark breakpoints uninserted, and
9181 get_offsets may insert breakpoints. */
9182 init_thread_list ();
9183 init_wait_for_inferior ();
9186 /* vRun's success return is a stop reply. */
9187 stop_reply
= run_worked
? rs
->buf
: NULL
;
9188 add_current_inferior_and_thread (stop_reply
);
9190 /* Get updated offsets, if the stub uses qOffsets. */
9195 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9196 the list of conditions (in agent expression bytecode format), if any, the
9197 target needs to evaluate. The output is placed into the packet buffer
9198 started from BUF and ended at BUF_END. */
9201 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9202 struct bp_target_info
*bp_tgt
, char *buf
,
9205 struct agent_expr
*aexpr
= NULL
;
9208 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9211 buf
+= strlen (buf
);
9212 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9215 /* Send conditions to the target and free the vector. */
9217 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9220 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9221 buf
+= strlen (buf
);
9222 for (i
= 0; i
< aexpr
->len
; ++i
)
9223 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9230 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9231 struct bp_target_info
*bp_tgt
, char *buf
)
9233 struct agent_expr
*aexpr
= NULL
;
9236 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9239 buf
+= strlen (buf
);
9241 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9242 buf
+= strlen (buf
);
9244 /* Concatenate all the agent expressions that are commands into the
9247 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9250 sprintf (buf
, "X%x,", aexpr
->len
);
9251 buf
+= strlen (buf
);
9252 for (i
= 0; i
< aexpr
->len
; ++i
)
9253 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9258 /* Insert a breakpoint. On targets that have software breakpoint
9259 support, we ask the remote target to do the work; on targets
9260 which don't, we insert a traditional memory breakpoint. */
9263 remote_insert_breakpoint (struct target_ops
*ops
,
9264 struct gdbarch
*gdbarch
,
9265 struct bp_target_info
*bp_tgt
)
9267 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9268 If it succeeds, then set the support to PACKET_ENABLE. If it
9269 fails, and the user has explicitly requested the Z support then
9270 report an error, otherwise, mark it disabled and go on. */
9272 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9274 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9275 struct remote_state
*rs
;
9279 /* Make sure the remote is pointing at the right process, if
9281 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9282 set_general_process ();
9284 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9286 rs
= get_remote_state ();
9288 endbuf
= rs
->buf
+ get_remote_packet_size ();
9293 addr
= (ULONGEST
) remote_address_masked (addr
);
9294 p
+= hexnumstr (p
, addr
);
9295 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
9297 if (remote_supports_cond_breakpoints (ops
))
9298 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9300 if (remote_can_run_breakpoint_commands (ops
))
9301 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9304 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9306 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9311 bp_tgt
->placed_address
= addr
;
9312 bp_tgt
->placed_size
= bpsize
;
9314 case PACKET_UNKNOWN
:
9319 /* If this breakpoint has target-side commands but this stub doesn't
9320 support Z0 packets, throw error. */
9321 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9322 throw_error (NOT_SUPPORTED_ERROR
, _("\
9323 Target doesn't support breakpoints that have target side commands."));
9325 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9329 remote_remove_breakpoint (struct target_ops
*ops
,
9330 struct gdbarch
*gdbarch
,
9331 struct bp_target_info
*bp_tgt
)
9333 CORE_ADDR addr
= bp_tgt
->placed_address
;
9334 struct remote_state
*rs
= get_remote_state ();
9336 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9339 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9341 /* Make sure the remote is pointing at the right process, if
9343 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9344 set_general_process ();
9350 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9351 p
+= hexnumstr (p
, addr
);
9352 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9355 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9357 return (rs
->buf
[0] == 'E');
9360 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9363 static enum Z_packet_type
9364 watchpoint_to_Z_packet (int type
)
9369 return Z_PACKET_WRITE_WP
;
9372 return Z_PACKET_READ_WP
;
9375 return Z_PACKET_ACCESS_WP
;
9378 internal_error (__FILE__
, __LINE__
,
9379 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9384 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9385 enum target_hw_bp_type type
, struct expression
*cond
)
9387 struct remote_state
*rs
= get_remote_state ();
9388 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9390 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9392 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9395 /* Make sure the remote is pointing at the right process, if
9397 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9398 set_general_process ();
9400 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9401 p
= strchr (rs
->buf
, '\0');
9402 addr
= remote_address_masked (addr
);
9403 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9404 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9407 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9409 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9413 case PACKET_UNKNOWN
:
9418 internal_error (__FILE__
, __LINE__
,
9419 _("remote_insert_watchpoint: reached end of function"));
9423 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9424 CORE_ADDR start
, int length
)
9426 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9428 return diff
< length
;
9433 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9434 enum target_hw_bp_type type
, struct expression
*cond
)
9436 struct remote_state
*rs
= get_remote_state ();
9437 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9439 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9441 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9444 /* Make sure the remote is pointing at the right process, if
9446 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9447 set_general_process ();
9449 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9450 p
= strchr (rs
->buf
, '\0');
9451 addr
= remote_address_masked (addr
);
9452 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9453 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9455 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9457 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9460 case PACKET_UNKNOWN
:
9465 internal_error (__FILE__
, __LINE__
,
9466 _("remote_remove_watchpoint: reached end of function"));
9470 int remote_hw_watchpoint_limit
= -1;
9471 int remote_hw_watchpoint_length_limit
= -1;
9472 int remote_hw_breakpoint_limit
= -1;
9475 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9476 CORE_ADDR addr
, int len
)
9478 if (remote_hw_watchpoint_length_limit
== 0)
9480 else if (remote_hw_watchpoint_length_limit
< 0)
9482 else if (len
<= remote_hw_watchpoint_length_limit
)
9489 remote_check_watch_resources (struct target_ops
*self
,
9490 enum bptype type
, int cnt
, int ot
)
9492 if (type
== bp_hardware_breakpoint
)
9494 if (remote_hw_breakpoint_limit
== 0)
9496 else if (remote_hw_breakpoint_limit
< 0)
9498 else if (cnt
<= remote_hw_breakpoint_limit
)
9503 if (remote_hw_watchpoint_limit
== 0)
9505 else if (remote_hw_watchpoint_limit
< 0)
9509 else if (cnt
<= remote_hw_watchpoint_limit
)
9515 /* The to_stopped_by_sw_breakpoint method of target remote. */
9518 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9520 struct thread_info
*thread
= inferior_thread ();
9522 return (thread
->priv
!= NULL
9523 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9526 /* The to_supports_stopped_by_sw_breakpoint method of target
9530 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9532 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9535 /* The to_stopped_by_hw_breakpoint method of target remote. */
9538 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9540 struct thread_info
*thread
= inferior_thread ();
9542 return (thread
->priv
!= NULL
9543 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9546 /* The to_supports_stopped_by_hw_breakpoint method of target
9550 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9552 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9556 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9558 struct thread_info
*thread
= inferior_thread ();
9560 return (thread
->priv
!= NULL
9561 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9565 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9567 struct thread_info
*thread
= inferior_thread ();
9569 if (thread
->priv
!= NULL
9570 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9572 *addr_p
= thread
->priv
->watch_data_address
;
9581 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9582 struct bp_target_info
*bp_tgt
)
9584 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9585 struct remote_state
*rs
;
9590 /* The length field should be set to the size of a breakpoint
9591 instruction, even though we aren't inserting one ourselves. */
9593 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9595 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9598 /* Make sure the remote is pointing at the right process, if
9600 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9601 set_general_process ();
9603 rs
= get_remote_state ();
9605 endbuf
= rs
->buf
+ get_remote_packet_size ();
9611 addr
= remote_address_masked (addr
);
9612 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9613 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9615 if (remote_supports_cond_breakpoints (self
))
9616 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9618 if (remote_can_run_breakpoint_commands (self
))
9619 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9622 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9624 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9627 if (rs
->buf
[1] == '.')
9629 message
= strchr (rs
->buf
+ 2, '.');
9631 error (_("Remote failure reply: %s"), message
+ 1);
9634 case PACKET_UNKNOWN
:
9637 bp_tgt
->placed_address
= addr
;
9638 bp_tgt
->placed_size
= bpsize
;
9641 internal_error (__FILE__
, __LINE__
,
9642 _("remote_insert_hw_breakpoint: reached end of function"));
9647 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9648 struct bp_target_info
*bp_tgt
)
9651 struct remote_state
*rs
= get_remote_state ();
9653 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9655 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9658 /* Make sure the remote is pointing at the right process, if
9660 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9661 set_general_process ();
9667 addr
= remote_address_masked (bp_tgt
->placed_address
);
9668 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9669 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9672 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9674 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9677 case PACKET_UNKNOWN
:
9682 internal_error (__FILE__
, __LINE__
,
9683 _("remote_remove_hw_breakpoint: reached end of function"));
9686 /* Verify memory using the "qCRC:" request. */
9689 remote_verify_memory (struct target_ops
*ops
,
9690 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9692 struct remote_state
*rs
= get_remote_state ();
9693 unsigned long host_crc
, target_crc
;
9696 /* It doesn't make sense to use qCRC if the remote target is
9697 connected but not running. */
9698 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9700 enum packet_result result
;
9702 /* Make sure the remote is pointing at the right process. */
9703 set_general_process ();
9705 /* FIXME: assumes lma can fit into long. */
9706 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9707 (long) lma
, (long) size
);
9710 /* Be clever; compute the host_crc before waiting for target
9712 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9714 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9716 result
= packet_ok (rs
->buf
,
9717 &remote_protocol_packets
[PACKET_qCRC
]);
9718 if (result
== PACKET_ERROR
)
9720 else if (result
== PACKET_OK
)
9722 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9723 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9725 return (host_crc
== target_crc
);
9729 return simple_verify_memory (ops
, data
, lma
, size
);
9732 /* compare-sections command
9734 With no arguments, compares each loadable section in the exec bfd
9735 with the same memory range on the target, and reports mismatches.
9736 Useful for verifying the image on the target against the exec file. */
9739 compare_sections_command (char *args
, int from_tty
)
9742 struct cleanup
*old_chain
;
9744 const char *sectname
;
9753 error (_("command cannot be used without an exec file"));
9755 /* Make sure the remote is pointing at the right process. */
9756 set_general_process ();
9758 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9764 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9766 if (!(s
->flags
& SEC_LOAD
))
9767 continue; /* Skip non-loadable section. */
9769 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9770 continue; /* Skip writeable sections */
9772 size
= bfd_get_section_size (s
);
9774 continue; /* Skip zero-length section. */
9776 sectname
= bfd_get_section_name (exec_bfd
, s
);
9777 if (args
&& strcmp (args
, sectname
) != 0)
9778 continue; /* Not the section selected by user. */
9780 matched
= 1; /* Do this section. */
9783 sectdata
= (gdb_byte
*) xmalloc (size
);
9784 old_chain
= make_cleanup (xfree
, sectdata
);
9785 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9787 res
= target_verify_memory (sectdata
, lma
, size
);
9790 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9791 paddress (target_gdbarch (), lma
),
9792 paddress (target_gdbarch (), lma
+ size
));
9794 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9795 paddress (target_gdbarch (), lma
),
9796 paddress (target_gdbarch (), lma
+ size
));
9798 printf_filtered ("matched.\n");
9801 printf_filtered ("MIS-MATCHED!\n");
9805 do_cleanups (old_chain
);
9808 warning (_("One or more sections of the target image does not match\n\
9809 the loaded file\n"));
9810 if (args
&& !matched
)
9811 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9814 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9815 into remote target. The number of bytes written to the remote
9816 target is returned, or -1 for error. */
9818 static enum target_xfer_status
9819 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9820 const char *annex
, const gdb_byte
*writebuf
,
9821 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9822 struct packet_config
*packet
)
9826 struct remote_state
*rs
= get_remote_state ();
9827 int max_size
= get_memory_write_packet_size ();
9829 if (packet
->support
== PACKET_DISABLE
)
9830 return TARGET_XFER_E_IO
;
9832 /* Insert header. */
9833 i
= snprintf (rs
->buf
, max_size
,
9834 "qXfer:%s:write:%s:%s:",
9835 object_name
, annex
? annex
: "",
9836 phex_nz (offset
, sizeof offset
));
9837 max_size
-= (i
+ 1);
9839 /* Escape as much data as fits into rs->buf. */
9840 buf_len
= remote_escape_output
9841 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9843 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9844 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9845 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9846 return TARGET_XFER_E_IO
;
9848 unpack_varlen_hex (rs
->buf
, &n
);
9851 return TARGET_XFER_OK
;
9854 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9855 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9856 number of bytes read is returned, or 0 for EOF, or -1 for error.
9857 The number of bytes read may be less than LEN without indicating an
9858 EOF. PACKET is checked and updated to indicate whether the remote
9859 target supports this object. */
9861 static enum target_xfer_status
9862 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9864 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9865 ULONGEST
*xfered_len
,
9866 struct packet_config
*packet
)
9868 struct remote_state
*rs
= get_remote_state ();
9869 LONGEST i
, n
, packet_len
;
9871 if (packet
->support
== PACKET_DISABLE
)
9872 return TARGET_XFER_E_IO
;
9874 /* Check whether we've cached an end-of-object packet that matches
9876 if (rs
->finished_object
)
9878 if (strcmp (object_name
, rs
->finished_object
) == 0
9879 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9880 && offset
== rs
->finished_offset
)
9881 return TARGET_XFER_EOF
;
9884 /* Otherwise, we're now reading something different. Discard
9886 xfree (rs
->finished_object
);
9887 xfree (rs
->finished_annex
);
9888 rs
->finished_object
= NULL
;
9889 rs
->finished_annex
= NULL
;
9892 /* Request only enough to fit in a single packet. The actual data
9893 may not, since we don't know how much of it will need to be escaped;
9894 the target is free to respond with slightly less data. We subtract
9895 five to account for the response type and the protocol frame. */
9896 n
= min (get_remote_packet_size () - 5, len
);
9897 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9898 object_name
, annex
? annex
: "",
9899 phex_nz (offset
, sizeof offset
),
9900 phex_nz (n
, sizeof n
));
9901 i
= putpkt (rs
->buf
);
9903 return TARGET_XFER_E_IO
;
9906 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9907 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9908 return TARGET_XFER_E_IO
;
9910 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9911 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9913 /* 'm' means there is (or at least might be) more data after this
9914 batch. That does not make sense unless there's at least one byte
9915 of data in this reply. */
9916 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9917 error (_("Remote qXfer reply contained no data."));
9919 /* Got some data. */
9920 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9921 packet_len
- 1, readbuf
, n
);
9923 /* 'l' is an EOF marker, possibly including a final block of data,
9924 or possibly empty. If we have the final block of a non-empty
9925 object, record this fact to bypass a subsequent partial read. */
9926 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9928 rs
->finished_object
= xstrdup (object_name
);
9929 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9930 rs
->finished_offset
= offset
+ i
;
9934 return TARGET_XFER_EOF
;
9938 return TARGET_XFER_OK
;
9942 static enum target_xfer_status
9943 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9944 const char *annex
, gdb_byte
*readbuf
,
9945 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9946 ULONGEST
*xfered_len
)
9948 struct remote_state
*rs
;
9952 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9954 set_remote_traceframe ();
9955 set_general_thread (inferior_ptid
);
9957 rs
= get_remote_state ();
9959 /* Handle memory using the standard memory routines. */
9960 if (object
== TARGET_OBJECT_MEMORY
)
9962 /* If the remote target is connected but not running, we should
9963 pass this request down to a lower stratum (e.g. the executable
9965 if (!target_has_execution
)
9966 return TARGET_XFER_EOF
;
9968 if (writebuf
!= NULL
)
9969 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9972 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9976 /* Handle SPU memory using qxfer packets. */
9977 if (object
== TARGET_OBJECT_SPU
)
9980 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9981 xfered_len
, &remote_protocol_packets
9982 [PACKET_qXfer_spu_read
]);
9984 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9985 xfered_len
, &remote_protocol_packets
9986 [PACKET_qXfer_spu_write
]);
9989 /* Handle extra signal info using qxfer packets. */
9990 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9993 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9994 xfered_len
, &remote_protocol_packets
9995 [PACKET_qXfer_siginfo_read
]);
9997 return remote_write_qxfer (ops
, "siginfo", annex
,
9998 writebuf
, offset
, len
, xfered_len
,
9999 &remote_protocol_packets
10000 [PACKET_qXfer_siginfo_write
]);
10003 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10006 return remote_read_qxfer (ops
, "statictrace", annex
,
10007 readbuf
, offset
, len
, xfered_len
,
10008 &remote_protocol_packets
10009 [PACKET_qXfer_statictrace_read
]);
10011 return TARGET_XFER_E_IO
;
10014 /* Only handle flash writes. */
10015 if (writebuf
!= NULL
)
10019 case TARGET_OBJECT_FLASH
:
10020 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10024 return TARGET_XFER_E_IO
;
10028 /* Map pre-existing objects onto letters. DO NOT do this for new
10029 objects!!! Instead specify new query packets. */
10032 case TARGET_OBJECT_AVR
:
10036 case TARGET_OBJECT_AUXV
:
10037 gdb_assert (annex
== NULL
);
10038 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10040 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10042 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10043 return remote_read_qxfer
10044 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10045 &remote_protocol_packets
[PACKET_qXfer_features
]);
10047 case TARGET_OBJECT_LIBRARIES
:
10048 return remote_read_qxfer
10049 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10050 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10052 case TARGET_OBJECT_LIBRARIES_SVR4
:
10053 return remote_read_qxfer
10054 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10055 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10057 case TARGET_OBJECT_MEMORY_MAP
:
10058 gdb_assert (annex
== NULL
);
10059 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10061 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10063 case TARGET_OBJECT_OSDATA
:
10064 /* Should only get here if we're connected. */
10065 gdb_assert (rs
->remote_desc
);
10066 return remote_read_qxfer
10067 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10068 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10070 case TARGET_OBJECT_THREADS
:
10071 gdb_assert (annex
== NULL
);
10072 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10074 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10076 case TARGET_OBJECT_TRACEFRAME_INFO
:
10077 gdb_assert (annex
== NULL
);
10078 return remote_read_qxfer
10079 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10080 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10082 case TARGET_OBJECT_FDPIC
:
10083 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10085 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10087 case TARGET_OBJECT_OPENVMS_UIB
:
10088 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10090 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10092 case TARGET_OBJECT_BTRACE
:
10093 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10095 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10097 case TARGET_OBJECT_BTRACE_CONF
:
10098 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10100 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10102 case TARGET_OBJECT_EXEC_FILE
:
10103 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10105 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10108 return TARGET_XFER_E_IO
;
10111 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10112 large enough let the caller deal with it. */
10113 if (len
< get_remote_packet_size ())
10114 return TARGET_XFER_E_IO
;
10115 len
= get_remote_packet_size ();
10117 /* Except for querying the minimum buffer size, target must be open. */
10118 if (!rs
->remote_desc
)
10119 error (_("remote query is only available after target open"));
10121 gdb_assert (annex
!= NULL
);
10122 gdb_assert (readbuf
!= NULL
);
10126 *p2
++ = query_type
;
10128 /* We used one buffer char for the remote protocol q command and
10129 another for the query type. As the remote protocol encapsulation
10130 uses 4 chars plus one extra in case we are debugging
10131 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10134 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10136 /* Bad caller may have sent forbidden characters. */
10137 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10142 gdb_assert (annex
[i
] == '\0');
10144 i
= putpkt (rs
->buf
);
10146 return TARGET_XFER_E_IO
;
10148 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10149 strcpy ((char *) readbuf
, rs
->buf
);
10151 *xfered_len
= strlen ((char *) readbuf
);
10152 return TARGET_XFER_OK
;
10155 /* Implementation of to_get_memory_xfer_limit. */
10158 remote_get_memory_xfer_limit (struct target_ops
*ops
)
10160 return get_memory_write_packet_size ();
10164 remote_search_memory (struct target_ops
* ops
,
10165 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10166 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10167 CORE_ADDR
*found_addrp
)
10169 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10170 struct remote_state
*rs
= get_remote_state ();
10171 int max_size
= get_memory_write_packet_size ();
10172 struct packet_config
*packet
=
10173 &remote_protocol_packets
[PACKET_qSearch_memory
];
10174 /* Number of packet bytes used to encode the pattern;
10175 this could be more than PATTERN_LEN due to escape characters. */
10176 int escaped_pattern_len
;
10177 /* Amount of pattern that was encodable in the packet. */
10178 int used_pattern_len
;
10181 ULONGEST found_addr
;
10183 /* Don't go to the target if we don't have to.
10184 This is done before checking packet->support to avoid the possibility that
10185 a success for this edge case means the facility works in general. */
10186 if (pattern_len
> search_space_len
)
10188 if (pattern_len
== 0)
10190 *found_addrp
= start_addr
;
10194 /* If we already know the packet isn't supported, fall back to the simple
10195 way of searching memory. */
10197 if (packet_config_support (packet
) == PACKET_DISABLE
)
10199 /* Target doesn't provided special support, fall back and use the
10200 standard support (copy memory and do the search here). */
10201 return simple_search_memory (ops
, start_addr
, search_space_len
,
10202 pattern
, pattern_len
, found_addrp
);
10205 /* Make sure the remote is pointing at the right process. */
10206 set_general_process ();
10208 /* Insert header. */
10209 i
= snprintf (rs
->buf
, max_size
,
10210 "qSearch:memory:%s;%s;",
10211 phex_nz (start_addr
, addr_size
),
10212 phex_nz (search_space_len
, sizeof (search_space_len
)));
10213 max_size
-= (i
+ 1);
10215 /* Escape as much data as fits into rs->buf. */
10216 escaped_pattern_len
=
10217 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10218 &used_pattern_len
, max_size
);
10220 /* Bail if the pattern is too large. */
10221 if (used_pattern_len
!= pattern_len
)
10222 error (_("Pattern is too large to transmit to remote target."));
10224 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10225 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10226 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10228 /* The request may not have worked because the command is not
10229 supported. If so, fall back to the simple way. */
10230 if (packet
->support
== PACKET_DISABLE
)
10232 return simple_search_memory (ops
, start_addr
, search_space_len
,
10233 pattern
, pattern_len
, found_addrp
);
10238 if (rs
->buf
[0] == '0')
10240 else if (rs
->buf
[0] == '1')
10243 if (rs
->buf
[1] != ',')
10244 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10245 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10246 *found_addrp
= found_addr
;
10249 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10255 remote_rcmd (struct target_ops
*self
, const char *command
,
10256 struct ui_file
*outbuf
)
10258 struct remote_state
*rs
= get_remote_state ();
10261 if (!rs
->remote_desc
)
10262 error (_("remote rcmd is only available after target open"));
10264 /* Send a NULL command across as an empty command. */
10265 if (command
== NULL
)
10268 /* The query prefix. */
10269 strcpy (rs
->buf
, "qRcmd,");
10270 p
= strchr (rs
->buf
, '\0');
10272 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10273 > get_remote_packet_size ())
10274 error (_("\"monitor\" command ``%s'' is too long."), command
);
10276 /* Encode the actual command. */
10277 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10279 if (putpkt (rs
->buf
) < 0)
10280 error (_("Communication problem with target."));
10282 /* get/display the response */
10287 /* XXX - see also remote_get_noisy_reply(). */
10288 QUIT
; /* Allow user to bail out with ^C. */
10290 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10292 /* Timeout. Continue to (try to) read responses.
10293 This is better than stopping with an error, assuming the stub
10294 is still executing the (long) monitor command.
10295 If needed, the user can interrupt gdb using C-c, obtaining
10296 an effect similar to stop on timeout. */
10300 if (buf
[0] == '\0')
10301 error (_("Target does not support this command."));
10302 if (buf
[0] == 'O' && buf
[1] != 'K')
10304 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10307 if (strcmp (buf
, "OK") == 0)
10309 if (strlen (buf
) == 3 && buf
[0] == 'E'
10310 && isdigit (buf
[1]) && isdigit (buf
[2]))
10312 error (_("Protocol error with Rcmd"));
10314 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10316 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10318 fputc_unfiltered (c
, outbuf
);
10324 static VEC(mem_region_s
) *
10325 remote_memory_map (struct target_ops
*ops
)
10327 VEC(mem_region_s
) *result
= NULL
;
10328 char *text
= target_read_stralloc (¤t_target
,
10329 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10333 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10335 result
= parse_memory_map (text
);
10336 do_cleanups (back_to
);
10343 packet_command (char *args
, int from_tty
)
10345 struct remote_state
*rs
= get_remote_state ();
10347 if (!rs
->remote_desc
)
10348 error (_("command can only be used with remote target"));
10351 error (_("remote-packet command requires packet text as argument"));
10353 puts_filtered ("sending: ");
10354 print_packet (args
);
10355 puts_filtered ("\n");
10358 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10359 puts_filtered ("received: ");
10360 print_packet (rs
->buf
);
10361 puts_filtered ("\n");
10365 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10367 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10369 static void threadset_test_cmd (char *cmd
, int tty
);
10371 static void threadalive_test (char *cmd
, int tty
);
10373 static void threadlist_test_cmd (char *cmd
, int tty
);
10375 int get_and_display_threadinfo (threadref
*ref
);
10377 static void threadinfo_test_cmd (char *cmd
, int tty
);
10379 static int thread_display_step (threadref
*ref
, void *context
);
10381 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10383 static void init_remote_threadtests (void);
10385 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10388 threadset_test_cmd (char *cmd
, int tty
)
10390 int sample_thread
= SAMPLE_THREAD
;
10392 printf_filtered (_("Remote threadset test\n"));
10393 set_general_thread (sample_thread
);
10398 threadalive_test (char *cmd
, int tty
)
10400 int sample_thread
= SAMPLE_THREAD
;
10401 int pid
= ptid_get_pid (inferior_ptid
);
10402 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10404 if (remote_thread_alive (ptid
))
10405 printf_filtered ("PASS: Thread alive test\n");
10407 printf_filtered ("FAIL: Thread alive test\n");
10410 void output_threadid (char *title
, threadref
*ref
);
10413 output_threadid (char *title
, threadref
*ref
)
10417 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10419 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10423 threadlist_test_cmd (char *cmd
, int tty
)
10426 threadref nextthread
;
10427 int done
, result_count
;
10428 threadref threadlist
[3];
10430 printf_filtered ("Remote Threadlist test\n");
10431 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10432 &result_count
, &threadlist
[0]))
10433 printf_filtered ("FAIL: threadlist test\n");
10436 threadref
*scan
= threadlist
;
10437 threadref
*limit
= scan
+ result_count
;
10439 while (scan
< limit
)
10440 output_threadid (" thread ", scan
++);
10445 display_thread_info (struct gdb_ext_thread_info
*info
)
10447 output_threadid ("Threadid: ", &info
->threadid
);
10448 printf_filtered ("Name: %s\n ", info
->shortname
);
10449 printf_filtered ("State: %s\n", info
->display
);
10450 printf_filtered ("other: %s\n\n", info
->more_display
);
10454 get_and_display_threadinfo (threadref
*ref
)
10458 struct gdb_ext_thread_info threadinfo
;
10460 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10461 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10462 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10463 display_thread_info (&threadinfo
);
10468 threadinfo_test_cmd (char *cmd
, int tty
)
10470 int athread
= SAMPLE_THREAD
;
10474 int_to_threadref (&thread
, athread
);
10475 printf_filtered ("Remote Threadinfo test\n");
10476 if (!get_and_display_threadinfo (&thread
))
10477 printf_filtered ("FAIL cannot get thread info\n");
10481 thread_display_step (threadref
*ref
, void *context
)
10483 /* output_threadid(" threadstep ",ref); *//* simple test */
10484 return get_and_display_threadinfo (ref
);
10488 threadlist_update_test_cmd (char *cmd
, int tty
)
10490 printf_filtered ("Remote Threadlist update test\n");
10491 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10495 init_remote_threadtests (void)
10497 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10498 _("Fetch and print the remote list of "
10499 "thread identifiers, one pkt only"));
10500 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10501 _("Fetch and display info about one thread"));
10502 add_com ("tset", class_obscure
, threadset_test_cmd
,
10503 _("Test setting to a different thread"));
10504 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10505 _("Iterate through updating all remote thread info"));
10506 add_com ("talive", class_obscure
, threadalive_test
,
10507 _(" Remote thread alive test "));
10512 /* Convert a thread ID to a string. Returns the string in a static
10516 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10518 static char buf
[64];
10519 struct remote_state
*rs
= get_remote_state ();
10521 if (ptid_equal (ptid
, null_ptid
))
10522 return normal_pid_to_str (ptid
);
10523 else if (ptid_is_pid (ptid
))
10525 /* Printing an inferior target id. */
10527 /* When multi-process extensions are off, there's no way in the
10528 remote protocol to know the remote process id, if there's any
10529 at all. There's one exception --- when we're connected with
10530 target extended-remote, and we manually attached to a process
10531 with "attach PID". We don't record anywhere a flag that
10532 allows us to distinguish that case from the case of
10533 connecting with extended-remote and the stub already being
10534 attached to a process, and reporting yes to qAttached, hence
10535 no smart special casing here. */
10536 if (!remote_multi_process_p (rs
))
10538 xsnprintf (buf
, sizeof buf
, "Remote target");
10542 return normal_pid_to_str (ptid
);
10546 if (ptid_equal (magic_null_ptid
, ptid
))
10547 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10548 else if (remote_multi_process_p (rs
))
10549 if (ptid_get_lwp (ptid
) == 0)
10550 return normal_pid_to_str (ptid
);
10552 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10553 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10555 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10556 ptid_get_lwp (ptid
));
10561 /* Get the address of the thread local variable in OBJFILE which is
10562 stored at OFFSET within the thread local storage for thread PTID. */
10565 remote_get_thread_local_address (struct target_ops
*ops
,
10566 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10568 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10570 struct remote_state
*rs
= get_remote_state ();
10572 char *endp
= rs
->buf
+ get_remote_packet_size ();
10573 enum packet_result result
;
10575 strcpy (p
, "qGetTLSAddr:");
10577 p
= write_ptid (p
, endp
, ptid
);
10579 p
+= hexnumstr (p
, offset
);
10581 p
+= hexnumstr (p
, lm
);
10585 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10586 result
= packet_ok (rs
->buf
,
10587 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10588 if (result
== PACKET_OK
)
10592 unpack_varlen_hex (rs
->buf
, &result
);
10595 else if (result
== PACKET_UNKNOWN
)
10596 throw_error (TLS_GENERIC_ERROR
,
10597 _("Remote target doesn't support qGetTLSAddr packet"));
10599 throw_error (TLS_GENERIC_ERROR
,
10600 _("Remote target failed to process qGetTLSAddr request"));
10603 throw_error (TLS_GENERIC_ERROR
,
10604 _("TLS not supported or disabled on this target"));
10609 /* Provide thread local base, i.e. Thread Information Block address.
10610 Returns 1 if ptid is found and thread_local_base is non zero. */
10613 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10615 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10617 struct remote_state
*rs
= get_remote_state ();
10619 char *endp
= rs
->buf
+ get_remote_packet_size ();
10620 enum packet_result result
;
10622 strcpy (p
, "qGetTIBAddr:");
10624 p
= write_ptid (p
, endp
, ptid
);
10628 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10629 result
= packet_ok (rs
->buf
,
10630 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10631 if (result
== PACKET_OK
)
10635 unpack_varlen_hex (rs
->buf
, &result
);
10637 *addr
= (CORE_ADDR
) result
;
10640 else if (result
== PACKET_UNKNOWN
)
10641 error (_("Remote target doesn't support qGetTIBAddr packet"));
10643 error (_("Remote target failed to process qGetTIBAddr request"));
10646 error (_("qGetTIBAddr not supported or disabled on this target"));
10651 /* Support for inferring a target description based on the current
10652 architecture and the size of a 'g' packet. While the 'g' packet
10653 can have any size (since optional registers can be left off the
10654 end), some sizes are easily recognizable given knowledge of the
10655 approximate architecture. */
10657 struct remote_g_packet_guess
10660 const struct target_desc
*tdesc
;
10662 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10663 DEF_VEC_O(remote_g_packet_guess_s
);
10665 struct remote_g_packet_data
10667 VEC(remote_g_packet_guess_s
) *guesses
;
10670 static struct gdbarch_data
*remote_g_packet_data_handle
;
10673 remote_g_packet_data_init (struct obstack
*obstack
)
10675 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10679 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10680 const struct target_desc
*tdesc
)
10682 struct remote_g_packet_data
*data
10683 = ((struct remote_g_packet_data
*)
10684 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10685 struct remote_g_packet_guess new_guess
, *guess
;
10688 gdb_assert (tdesc
!= NULL
);
10691 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10693 if (guess
->bytes
== bytes
)
10694 internal_error (__FILE__
, __LINE__
,
10695 _("Duplicate g packet description added for size %d"),
10698 new_guess
.bytes
= bytes
;
10699 new_guess
.tdesc
= tdesc
;
10700 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10703 /* Return 1 if remote_read_description would do anything on this target
10704 and architecture, 0 otherwise. */
10707 remote_read_description_p (struct target_ops
*target
)
10709 struct remote_g_packet_data
*data
10710 = ((struct remote_g_packet_data
*)
10711 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10713 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10719 static const struct target_desc
*
10720 remote_read_description (struct target_ops
*target
)
10722 struct remote_g_packet_data
*data
10723 = ((struct remote_g_packet_data
*)
10724 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10726 /* Do not try this during initial connection, when we do not know
10727 whether there is a running but stopped thread. */
10728 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10729 return target
->beneath
->to_read_description (target
->beneath
);
10731 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10733 struct remote_g_packet_guess
*guess
;
10735 int bytes
= send_g_packet ();
10738 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10740 if (guess
->bytes
== bytes
)
10741 return guess
->tdesc
;
10743 /* We discard the g packet. A minor optimization would be to
10744 hold on to it, and fill the register cache once we have selected
10745 an architecture, but it's too tricky to do safely. */
10748 return target
->beneath
->to_read_description (target
->beneath
);
10751 /* Remote file transfer support. This is host-initiated I/O, not
10752 target-initiated; for target-initiated, see remote-fileio.c. */
10754 /* If *LEFT is at least the length of STRING, copy STRING to
10755 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10756 decrease *LEFT. Otherwise raise an error. */
10759 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10761 int len
= strlen (string
);
10764 error (_("Packet too long for target."));
10766 memcpy (*buffer
, string
, len
);
10770 /* NUL-terminate the buffer as a convenience, if there is
10776 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10777 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10778 decrease *LEFT. Otherwise raise an error. */
10781 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10784 if (2 * len
> *left
)
10785 error (_("Packet too long for target."));
10787 bin2hex (bytes
, *buffer
, len
);
10788 *buffer
+= 2 * len
;
10791 /* NUL-terminate the buffer as a convenience, if there is
10797 /* If *LEFT is large enough, convert VALUE to hex and add it to
10798 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10799 decrease *LEFT. Otherwise raise an error. */
10802 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10804 int len
= hexnumlen (value
);
10807 error (_("Packet too long for target."));
10809 hexnumstr (*buffer
, value
);
10813 /* NUL-terminate the buffer as a convenience, if there is
10819 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10820 value, *REMOTE_ERRNO to the remote error number or zero if none
10821 was included, and *ATTACHMENT to point to the start of the annex
10822 if any. The length of the packet isn't needed here; there may
10823 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10825 Return 0 if the packet could be parsed, -1 if it could not. If
10826 -1 is returned, the other variables may not be initialized. */
10829 remote_hostio_parse_result (char *buffer
, int *retcode
,
10830 int *remote_errno
, char **attachment
)
10835 *attachment
= NULL
;
10837 if (buffer
[0] != 'F')
10841 *retcode
= strtol (&buffer
[1], &p
, 16);
10842 if (errno
!= 0 || p
== &buffer
[1])
10845 /* Check for ",errno". */
10849 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10850 if (errno
!= 0 || p
+ 1 == p2
)
10855 /* Check for ";attachment". If there is no attachment, the
10856 packet should end here. */
10859 *attachment
= p
+ 1;
10862 else if (*p
== '\0')
10868 /* Send a prepared I/O packet to the target and read its response.
10869 The prepared packet is in the global RS->BUF before this function
10870 is called, and the answer is there when we return.
10872 COMMAND_BYTES is the length of the request to send, which may include
10873 binary data. WHICH_PACKET is the packet configuration to check
10874 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10875 is set to the error number and -1 is returned. Otherwise the value
10876 returned by the function is returned.
10878 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10879 attachment is expected; an error will be reported if there's a
10880 mismatch. If one is found, *ATTACHMENT will be set to point into
10881 the packet buffer and *ATTACHMENT_LEN will be set to the
10882 attachment's length. */
10885 remote_hostio_send_command (int command_bytes
, int which_packet
,
10886 int *remote_errno
, char **attachment
,
10887 int *attachment_len
)
10889 struct remote_state
*rs
= get_remote_state ();
10890 int ret
, bytes_read
;
10891 char *attachment_tmp
;
10893 if (!rs
->remote_desc
10894 || packet_support (which_packet
) == PACKET_DISABLE
)
10896 *remote_errno
= FILEIO_ENOSYS
;
10900 putpkt_binary (rs
->buf
, command_bytes
);
10901 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10903 /* If it timed out, something is wrong. Don't try to parse the
10905 if (bytes_read
< 0)
10907 *remote_errno
= FILEIO_EINVAL
;
10911 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10914 *remote_errno
= FILEIO_EINVAL
;
10916 case PACKET_UNKNOWN
:
10917 *remote_errno
= FILEIO_ENOSYS
;
10923 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10926 *remote_errno
= FILEIO_EINVAL
;
10930 /* Make sure we saw an attachment if and only if we expected one. */
10931 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10932 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10934 *remote_errno
= FILEIO_EINVAL
;
10938 /* If an attachment was found, it must point into the packet buffer;
10939 work out how many bytes there were. */
10940 if (attachment_tmp
!= NULL
)
10942 *attachment
= attachment_tmp
;
10943 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10949 /* Invalidate the readahead cache. */
10952 readahead_cache_invalidate (void)
10954 struct remote_state
*rs
= get_remote_state ();
10956 rs
->readahead_cache
.fd
= -1;
10959 /* Invalidate the readahead cache if it is holding data for FD. */
10962 readahead_cache_invalidate_fd (int fd
)
10964 struct remote_state
*rs
= get_remote_state ();
10966 if (rs
->readahead_cache
.fd
== fd
)
10967 rs
->readahead_cache
.fd
= -1;
10970 /* Set the filesystem remote_hostio functions that take FILENAME
10971 arguments will use. Return 0 on success, or -1 if an error
10972 occurs (and set *REMOTE_ERRNO). */
10975 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10977 struct remote_state
*rs
= get_remote_state ();
10978 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10980 int left
= get_remote_packet_size () - 1;
10984 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10987 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10990 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10992 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10993 remote_buffer_add_string (&p
, &left
, arg
);
10995 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10996 remote_errno
, NULL
, NULL
);
10998 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11002 rs
->fs_pid
= required_pid
;
11007 /* Implementation of to_fileio_open. */
11010 remote_hostio_open (struct target_ops
*self
,
11011 struct inferior
*inf
, const char *filename
,
11012 int flags
, int mode
, int warn_if_slow
,
11015 struct remote_state
*rs
= get_remote_state ();
11017 int left
= get_remote_packet_size () - 1;
11021 static int warning_issued
= 0;
11023 printf_unfiltered (_("Reading %s from remote target...\n"),
11026 if (!warning_issued
)
11028 warning (_("File transfers from remote targets can be slow."
11029 " Use \"set sysroot\" to access files locally"
11031 warning_issued
= 1;
11035 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11038 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11040 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11041 strlen (filename
));
11042 remote_buffer_add_string (&p
, &left
, ",");
11044 remote_buffer_add_int (&p
, &left
, flags
);
11045 remote_buffer_add_string (&p
, &left
, ",");
11047 remote_buffer_add_int (&p
, &left
, mode
);
11049 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11050 remote_errno
, NULL
, NULL
);
11053 /* Implementation of to_fileio_pwrite. */
11056 remote_hostio_pwrite (struct target_ops
*self
,
11057 int fd
, const gdb_byte
*write_buf
, int len
,
11058 ULONGEST offset
, int *remote_errno
)
11060 struct remote_state
*rs
= get_remote_state ();
11062 int left
= get_remote_packet_size ();
11065 readahead_cache_invalidate_fd (fd
);
11067 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11069 remote_buffer_add_int (&p
, &left
, fd
);
11070 remote_buffer_add_string (&p
, &left
, ",");
11072 remote_buffer_add_int (&p
, &left
, offset
);
11073 remote_buffer_add_string (&p
, &left
, ",");
11075 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11076 get_remote_packet_size () - (p
- rs
->buf
));
11078 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11079 remote_errno
, NULL
, NULL
);
11082 /* Helper for the implementation of to_fileio_pread. Read the file
11083 from the remote side with vFile:pread. */
11086 remote_hostio_pread_vFile (struct target_ops
*self
,
11087 int fd
, gdb_byte
*read_buf
, int len
,
11088 ULONGEST offset
, int *remote_errno
)
11090 struct remote_state
*rs
= get_remote_state ();
11093 int left
= get_remote_packet_size ();
11094 int ret
, attachment_len
;
11097 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11099 remote_buffer_add_int (&p
, &left
, fd
);
11100 remote_buffer_add_string (&p
, &left
, ",");
11102 remote_buffer_add_int (&p
, &left
, len
);
11103 remote_buffer_add_string (&p
, &left
, ",");
11105 remote_buffer_add_int (&p
, &left
, offset
);
11107 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11108 remote_errno
, &attachment
,
11114 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11116 if (read_len
!= ret
)
11117 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11122 /* Serve pread from the readahead cache. Returns number of bytes
11123 read, or 0 if the request can't be served from the cache. */
11126 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11127 int fd
, gdb_byte
*read_buf
, size_t len
,
11130 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11132 if (cache
->fd
== fd
11133 && cache
->offset
<= offset
11134 && offset
< cache
->offset
+ cache
->bufsize
)
11136 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11138 if (offset
+ len
> max
)
11139 len
= max
- offset
;
11141 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11148 /* Implementation of to_fileio_pread. */
11151 remote_hostio_pread (struct target_ops
*self
,
11152 int fd
, gdb_byte
*read_buf
, int len
,
11153 ULONGEST offset
, int *remote_errno
)
11156 struct remote_state
*rs
= get_remote_state ();
11157 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11159 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11162 cache
->hit_count
++;
11165 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11166 pulongest (cache
->hit_count
));
11170 cache
->miss_count
++;
11172 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11173 pulongest (cache
->miss_count
));
11176 cache
->offset
= offset
;
11177 cache
->bufsize
= get_remote_packet_size ();
11178 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11180 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11181 cache
->offset
, remote_errno
);
11184 readahead_cache_invalidate_fd (fd
);
11188 cache
->bufsize
= ret
;
11189 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11192 /* Implementation of to_fileio_close. */
11195 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11197 struct remote_state
*rs
= get_remote_state ();
11199 int left
= get_remote_packet_size () - 1;
11201 readahead_cache_invalidate_fd (fd
);
11203 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11205 remote_buffer_add_int (&p
, &left
, fd
);
11207 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11208 remote_errno
, NULL
, NULL
);
11211 /* Implementation of to_fileio_unlink. */
11214 remote_hostio_unlink (struct target_ops
*self
,
11215 struct inferior
*inf
, const char *filename
,
11218 struct remote_state
*rs
= get_remote_state ();
11220 int left
= get_remote_packet_size () - 1;
11222 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11225 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11227 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11228 strlen (filename
));
11230 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11231 remote_errno
, NULL
, NULL
);
11234 /* Implementation of to_fileio_readlink. */
11237 remote_hostio_readlink (struct target_ops
*self
,
11238 struct inferior
*inf
, const char *filename
,
11241 struct remote_state
*rs
= get_remote_state ();
11244 int left
= get_remote_packet_size ();
11245 int len
, attachment_len
;
11249 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11252 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11254 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11255 strlen (filename
));
11257 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11258 remote_errno
, &attachment
,
11264 ret
= (char *) xmalloc (len
+ 1);
11266 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11267 (gdb_byte
*) ret
, len
);
11268 if (read_len
!= len
)
11269 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11275 /* Implementation of to_fileio_fstat. */
11278 remote_hostio_fstat (struct target_ops
*self
,
11279 int fd
, struct stat
*st
,
11282 struct remote_state
*rs
= get_remote_state ();
11284 int left
= get_remote_packet_size ();
11285 int attachment_len
, ret
;
11287 struct fio_stat fst
;
11290 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11292 remote_buffer_add_int (&p
, &left
, fd
);
11294 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11295 remote_errno
, &attachment
,
11299 if (*remote_errno
!= FILEIO_ENOSYS
)
11302 /* Strictly we should return -1, ENOSYS here, but when
11303 "set sysroot remote:" was implemented in August 2008
11304 BFD's need for a stat function was sidestepped with
11305 this hack. This was not remedied until March 2015
11306 so we retain the previous behavior to avoid breaking
11309 Note that the memset is a March 2015 addition; older
11310 GDBs set st_size *and nothing else* so the structure
11311 would have garbage in all other fields. This might
11312 break something but retaining the previous behavior
11313 here would be just too wrong. */
11315 memset (st
, 0, sizeof (struct stat
));
11316 st
->st_size
= INT_MAX
;
11320 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11321 (gdb_byte
*) &fst
, sizeof (fst
));
11323 if (read_len
!= ret
)
11324 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11326 if (read_len
!= sizeof (fst
))
11327 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11328 read_len
, (int) sizeof (fst
));
11330 remote_fileio_to_host_stat (&fst
, st
);
11335 /* Implementation of to_filesystem_is_local. */
11338 remote_filesystem_is_local (struct target_ops
*self
)
11340 /* Valgrind GDB presents itself as a remote target but works
11341 on the local filesystem: it does not implement remote get
11342 and users are not expected to set a sysroot. To handle
11343 this case we treat the remote filesystem as local if the
11344 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11345 does not support vFile:open. */
11346 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11348 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11350 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11352 int fd
, remote_errno
;
11354 /* Try opening a file to probe support. The supplied
11355 filename is irrelevant, we only care about whether
11356 the stub recognizes the packet or not. */
11357 fd
= remote_hostio_open (self
, NULL
, "just probing",
11358 FILEIO_O_RDONLY
, 0700, 0,
11362 remote_hostio_close (self
, fd
, &remote_errno
);
11364 ps
= packet_support (PACKET_vFile_open
);
11367 if (ps
== PACKET_DISABLE
)
11369 static int warning_issued
= 0;
11371 if (!warning_issued
)
11373 warning (_("remote target does not support file"
11374 " transfer, attempting to access files"
11375 " from local filesystem."));
11376 warning_issued
= 1;
11387 remote_fileio_errno_to_host (int errnum
)
11393 case FILEIO_ENOENT
:
11401 case FILEIO_EACCES
:
11403 case FILEIO_EFAULT
:
11407 case FILEIO_EEXIST
:
11409 case FILEIO_ENODEV
:
11411 case FILEIO_ENOTDIR
:
11413 case FILEIO_EISDIR
:
11415 case FILEIO_EINVAL
:
11417 case FILEIO_ENFILE
:
11419 case FILEIO_EMFILE
:
11423 case FILEIO_ENOSPC
:
11425 case FILEIO_ESPIPE
:
11429 case FILEIO_ENOSYS
:
11431 case FILEIO_ENAMETOOLONG
:
11432 return ENAMETOOLONG
;
11438 remote_hostio_error (int errnum
)
11440 int host_error
= remote_fileio_errno_to_host (errnum
);
11442 if (host_error
== -1)
11443 error (_("Unknown remote I/O error %d"), errnum
);
11445 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11449 remote_hostio_close_cleanup (void *opaque
)
11451 int fd
= *(int *) opaque
;
11454 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11458 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11460 struct cleanup
*back_to
, *close_cleanup
;
11461 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11464 int bytes_in_buffer
;
11467 struct remote_state
*rs
= get_remote_state ();
11469 if (!rs
->remote_desc
)
11470 error (_("command can only be used with remote target"));
11472 file
= gdb_fopen_cloexec (local_file
, "rb");
11474 perror_with_name (local_file
);
11475 back_to
= make_cleanup_fclose (file
);
11477 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11478 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11480 0700, 0, &remote_errno
);
11482 remote_hostio_error (remote_errno
);
11484 /* Send up to this many bytes at once. They won't all fit in the
11485 remote packet limit, so we'll transfer slightly fewer. */
11486 io_size
= get_remote_packet_size ();
11487 buffer
= (gdb_byte
*) xmalloc (io_size
);
11488 make_cleanup (xfree
, buffer
);
11490 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11492 bytes_in_buffer
= 0;
11495 while (bytes_in_buffer
|| !saw_eof
)
11499 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11500 io_size
- bytes_in_buffer
,
11505 error (_("Error reading %s."), local_file
);
11508 /* EOF. Unless there is something still in the
11509 buffer from the last iteration, we are done. */
11511 if (bytes_in_buffer
== 0)
11519 bytes
+= bytes_in_buffer
;
11520 bytes_in_buffer
= 0;
11522 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11524 offset
, &remote_errno
);
11527 remote_hostio_error (remote_errno
);
11528 else if (retcode
== 0)
11529 error (_("Remote write of %d bytes returned 0!"), bytes
);
11530 else if (retcode
< bytes
)
11532 /* Short write. Save the rest of the read data for the next
11534 bytes_in_buffer
= bytes
- retcode
;
11535 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11541 discard_cleanups (close_cleanup
);
11542 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11543 remote_hostio_error (remote_errno
);
11546 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11547 do_cleanups (back_to
);
11551 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11553 struct cleanup
*back_to
, *close_cleanup
;
11554 int fd
, remote_errno
, bytes
, io_size
;
11558 struct remote_state
*rs
= get_remote_state ();
11560 if (!rs
->remote_desc
)
11561 error (_("command can only be used with remote target"));
11563 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11564 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11567 remote_hostio_error (remote_errno
);
11569 file
= gdb_fopen_cloexec (local_file
, "wb");
11571 perror_with_name (local_file
);
11572 back_to
= make_cleanup_fclose (file
);
11574 /* Send up to this many bytes at once. They won't all fit in the
11575 remote packet limit, so we'll transfer slightly fewer. */
11576 io_size
= get_remote_packet_size ();
11577 buffer
= (gdb_byte
*) xmalloc (io_size
);
11578 make_cleanup (xfree
, buffer
);
11580 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11585 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11586 fd
, buffer
, io_size
, offset
, &remote_errno
);
11588 /* Success, but no bytes, means end-of-file. */
11591 remote_hostio_error (remote_errno
);
11595 bytes
= fwrite (buffer
, 1, bytes
, file
);
11597 perror_with_name (local_file
);
11600 discard_cleanups (close_cleanup
);
11601 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11602 remote_hostio_error (remote_errno
);
11605 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11606 do_cleanups (back_to
);
11610 remote_file_delete (const char *remote_file
, int from_tty
)
11612 int retcode
, remote_errno
;
11613 struct remote_state
*rs
= get_remote_state ();
11615 if (!rs
->remote_desc
)
11616 error (_("command can only be used with remote target"));
11618 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11619 NULL
, remote_file
, &remote_errno
);
11621 remote_hostio_error (remote_errno
);
11624 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11628 remote_put_command (char *args
, int from_tty
)
11630 struct cleanup
*back_to
;
11634 error_no_arg (_("file to put"));
11636 argv
= gdb_buildargv (args
);
11637 back_to
= make_cleanup_freeargv (argv
);
11638 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11639 error (_("Invalid parameters to remote put"));
11641 remote_file_put (argv
[0], argv
[1], from_tty
);
11643 do_cleanups (back_to
);
11647 remote_get_command (char *args
, int from_tty
)
11649 struct cleanup
*back_to
;
11653 error_no_arg (_("file to get"));
11655 argv
= gdb_buildargv (args
);
11656 back_to
= make_cleanup_freeargv (argv
);
11657 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11658 error (_("Invalid parameters to remote get"));
11660 remote_file_get (argv
[0], argv
[1], from_tty
);
11662 do_cleanups (back_to
);
11666 remote_delete_command (char *args
, int from_tty
)
11668 struct cleanup
*back_to
;
11672 error_no_arg (_("file to delete"));
11674 argv
= gdb_buildargv (args
);
11675 back_to
= make_cleanup_freeargv (argv
);
11676 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11677 error (_("Invalid parameters to remote delete"));
11679 remote_file_delete (argv
[0], from_tty
);
11681 do_cleanups (back_to
);
11685 remote_command (char *args
, int from_tty
)
11687 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11691 remote_can_execute_reverse (struct target_ops
*self
)
11693 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11694 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11701 remote_supports_non_stop (struct target_ops
*self
)
11707 remote_supports_disable_randomization (struct target_ops
*self
)
11709 /* Only supported in extended mode. */
11714 remote_supports_multi_process (struct target_ops
*self
)
11716 struct remote_state
*rs
= get_remote_state ();
11718 return remote_multi_process_p (rs
);
11722 remote_supports_cond_tracepoints (void)
11724 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11728 remote_supports_cond_breakpoints (struct target_ops
*self
)
11730 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11734 remote_supports_fast_tracepoints (void)
11736 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11740 remote_supports_static_tracepoints (void)
11742 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11746 remote_supports_install_in_trace (void)
11748 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11752 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11754 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11759 remote_supports_string_tracing (struct target_ops
*self
)
11761 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11765 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11767 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11771 remote_trace_init (struct target_ops
*self
)
11774 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11775 if (strcmp (target_buf
, "OK") != 0)
11776 error (_("Target does not support this command."));
11779 static void free_actions_list (char **actions_list
);
11780 static void free_actions_list_cleanup_wrapper (void *);
11782 free_actions_list_cleanup_wrapper (void *al
)
11784 free_actions_list ((char **) al
);
11788 free_actions_list (char **actions_list
)
11792 if (actions_list
== 0)
11795 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11796 xfree (actions_list
[ndx
]);
11798 xfree (actions_list
);
11801 /* Recursive routine to walk through command list including loops, and
11802 download packets for each command. */
11805 remote_download_command_source (int num
, ULONGEST addr
,
11806 struct command_line
*cmds
)
11808 struct remote_state
*rs
= get_remote_state ();
11809 struct command_line
*cmd
;
11811 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11813 QUIT
; /* Allow user to bail out with ^C. */
11814 strcpy (rs
->buf
, "QTDPsrc:");
11815 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11816 rs
->buf
+ strlen (rs
->buf
),
11817 rs
->buf_size
- strlen (rs
->buf
));
11819 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11820 if (strcmp (target_buf
, "OK"))
11821 warning (_("Target does not support source download."));
11823 if (cmd
->control_type
== while_control
11824 || cmd
->control_type
== while_stepping_control
)
11826 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11828 QUIT
; /* Allow user to bail out with ^C. */
11829 strcpy (rs
->buf
, "QTDPsrc:");
11830 encode_source_string (num
, addr
, "cmd", "end",
11831 rs
->buf
+ strlen (rs
->buf
),
11832 rs
->buf_size
- strlen (rs
->buf
));
11834 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11835 if (strcmp (target_buf
, "OK"))
11836 warning (_("Target does not support source download."));
11842 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11844 #define BUF_SIZE 2048
11848 char buf
[BUF_SIZE
];
11849 char **tdp_actions
;
11850 char **stepping_actions
;
11852 struct cleanup
*old_chain
= NULL
;
11853 struct agent_expr
*aexpr
;
11854 struct cleanup
*aexpr_chain
= NULL
;
11856 struct breakpoint
*b
= loc
->owner
;
11857 struct tracepoint
*t
= (struct tracepoint
*) b
;
11859 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11860 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11862 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11865 tpaddr
= loc
->address
;
11866 sprintf_vma (addrbuf
, tpaddr
);
11867 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11868 addrbuf
, /* address */
11869 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11870 t
->step_count
, t
->pass_count
);
11871 /* Fast tracepoints are mostly handled by the target, but we can
11872 tell the target how big of an instruction block should be moved
11874 if (b
->type
== bp_fast_tracepoint
)
11876 /* Only test for support at download time; we may not know
11877 target capabilities at definition time. */
11878 if (remote_supports_fast_tracepoints ())
11880 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11882 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11883 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11885 /* If it passed validation at definition but fails now,
11886 something is very wrong. */
11887 internal_error (__FILE__
, __LINE__
,
11888 _("Fast tracepoint not "
11889 "valid during download"));
11892 /* Fast tracepoints are functionally identical to regular
11893 tracepoints, so don't take lack of support as a reason to
11894 give up on the trace run. */
11895 warning (_("Target does not support fast tracepoints, "
11896 "downloading %d as regular tracepoint"), b
->number
);
11898 else if (b
->type
== bp_static_tracepoint
)
11900 /* Only test for support at download time; we may not know
11901 target capabilities at definition time. */
11902 if (remote_supports_static_tracepoints ())
11904 struct static_tracepoint_marker marker
;
11906 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11907 strcat (buf
, ":S");
11909 error (_("Static tracepoint not valid during download"));
11912 /* Fast tracepoints are functionally identical to regular
11913 tracepoints, so don't take lack of support as a reason
11914 to give up on the trace run. */
11915 error (_("Target does not support static tracepoints"));
11917 /* If the tracepoint has a conditional, make it into an agent
11918 expression and append to the definition. */
11921 /* Only test support at download time, we may not know target
11922 capabilities at definition time. */
11923 if (remote_supports_cond_tracepoints ())
11925 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11926 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11927 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11929 pkt
= buf
+ strlen (buf
);
11930 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11931 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11933 do_cleanups (aexpr_chain
);
11936 warning (_("Target does not support conditional tracepoints, "
11937 "ignoring tp %d cond"), b
->number
);
11940 if (b
->commands
|| *default_collect
)
11943 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11944 if (strcmp (target_buf
, "OK"))
11945 error (_("Target does not support tracepoints."));
11947 /* do_single_steps (t); */
11950 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11952 QUIT
; /* Allow user to bail out with ^C. */
11953 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11954 b
->number
, addrbuf
, /* address */
11956 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11959 remote_get_noisy_reply (&target_buf
,
11961 if (strcmp (target_buf
, "OK"))
11962 error (_("Error on target while setting tracepoints."));
11965 if (stepping_actions
)
11967 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11969 QUIT
; /* Allow user to bail out with ^C. */
11970 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11971 b
->number
, addrbuf
, /* address */
11972 ((ndx
== 0) ? "S" : ""),
11973 stepping_actions
[ndx
],
11974 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11976 remote_get_noisy_reply (&target_buf
,
11978 if (strcmp (target_buf
, "OK"))
11979 error (_("Error on target while setting tracepoints."));
11983 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11985 if (b
->location
!= NULL
)
11987 strcpy (buf
, "QTDPsrc:");
11988 encode_source_string (b
->number
, loc
->address
, "at",
11989 event_location_to_string (b
->location
),
11990 buf
+ strlen (buf
), 2048 - strlen (buf
));
11992 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11993 if (strcmp (target_buf
, "OK"))
11994 warning (_("Target does not support source download."));
11996 if (b
->cond_string
)
11998 strcpy (buf
, "QTDPsrc:");
11999 encode_source_string (b
->number
, loc
->address
,
12000 "cond", b
->cond_string
, buf
+ strlen (buf
),
12001 2048 - strlen (buf
));
12003 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12004 if (strcmp (target_buf
, "OK"))
12005 warning (_("Target does not support source download."));
12007 remote_download_command_source (b
->number
, loc
->address
,
12008 breakpoint_commands (b
));
12011 do_cleanups (old_chain
);
12015 remote_can_download_tracepoint (struct target_ops
*self
)
12017 struct remote_state
*rs
= get_remote_state ();
12018 struct trace_status
*ts
;
12021 /* Don't try to install tracepoints until we've relocated our
12022 symbols, and fetched and merged the target's tracepoint list with
12024 if (rs
->starting_up
)
12027 ts
= current_trace_status ();
12028 status
= remote_get_trace_status (self
, ts
);
12030 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12033 /* If we are in a tracing experiment, but remote stub doesn't support
12034 installing tracepoint in trace, we have to return. */
12035 if (!remote_supports_install_in_trace ())
12043 remote_download_trace_state_variable (struct target_ops
*self
,
12044 struct trace_state_variable
*tsv
)
12046 struct remote_state
*rs
= get_remote_state ();
12049 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12050 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12052 p
= rs
->buf
+ strlen (rs
->buf
);
12053 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12054 error (_("Trace state variable name too long for tsv definition packet"));
12055 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12058 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12059 if (*target_buf
== '\0')
12060 error (_("Target does not support this command."));
12061 if (strcmp (target_buf
, "OK") != 0)
12062 error (_("Error on target while downloading trace state variable."));
12066 remote_enable_tracepoint (struct target_ops
*self
,
12067 struct bp_location
*location
)
12069 struct remote_state
*rs
= get_remote_state ();
12072 sprintf_vma (addr_buf
, location
->address
);
12073 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12074 location
->owner
->number
, addr_buf
);
12076 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12077 if (*rs
->buf
== '\0')
12078 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12079 if (strcmp (rs
->buf
, "OK") != 0)
12080 error (_("Error on target while enabling tracepoint."));
12084 remote_disable_tracepoint (struct target_ops
*self
,
12085 struct bp_location
*location
)
12087 struct remote_state
*rs
= get_remote_state ();
12090 sprintf_vma (addr_buf
, location
->address
);
12091 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12092 location
->owner
->number
, addr_buf
);
12094 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12095 if (*rs
->buf
== '\0')
12096 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12097 if (strcmp (rs
->buf
, "OK") != 0)
12098 error (_("Error on target while disabling tracepoint."));
12102 remote_trace_set_readonly_regions (struct target_ops
*self
)
12106 bfd_size_type size
;
12112 return; /* No information to give. */
12114 strcpy (target_buf
, "QTro");
12115 offset
= strlen (target_buf
);
12116 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12118 char tmp1
[40], tmp2
[40];
12121 if ((s
->flags
& SEC_LOAD
) == 0 ||
12122 /* (s->flags & SEC_CODE) == 0 || */
12123 (s
->flags
& SEC_READONLY
) == 0)
12127 vma
= bfd_get_section_vma (abfd
, s
);
12128 size
= bfd_get_section_size (s
);
12129 sprintf_vma (tmp1
, vma
);
12130 sprintf_vma (tmp2
, vma
+ size
);
12131 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12132 if (offset
+ sec_length
+ 1 > target_buf_size
)
12134 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12136 Too many sections for read-only sections definition packet."));
12139 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12141 offset
+= sec_length
;
12145 putpkt (target_buf
);
12146 getpkt (&target_buf
, &target_buf_size
, 0);
12151 remote_trace_start (struct target_ops
*self
)
12153 putpkt ("QTStart");
12154 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12155 if (*target_buf
== '\0')
12156 error (_("Target does not support this command."));
12157 if (strcmp (target_buf
, "OK") != 0)
12158 error (_("Bogus reply from target: %s"), target_buf
);
12162 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12164 /* Initialize it just to avoid a GCC false warning. */
12166 /* FIXME we need to get register block size some other way. */
12167 extern int trace_regblock_size
;
12168 enum packet_result result
;
12170 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12173 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12175 putpkt ("qTStatus");
12179 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12181 CATCH (ex
, RETURN_MASK_ERROR
)
12183 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12185 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12188 throw_exception (ex
);
12192 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12194 /* If the remote target doesn't do tracing, flag it. */
12195 if (result
== PACKET_UNKNOWN
)
12198 /* We're working with a live target. */
12199 ts
->filename
= NULL
;
12202 error (_("Bogus trace status reply from target: %s"), target_buf
);
12204 /* Function 'parse_trace_status' sets default value of each field of
12205 'ts' at first, so we don't have to do it here. */
12206 parse_trace_status (p
, ts
);
12208 return ts
->running
;
12212 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12213 struct uploaded_tp
*utp
)
12215 struct remote_state
*rs
= get_remote_state ();
12217 struct bp_location
*loc
;
12218 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12219 size_t size
= get_remote_packet_size ();
12223 tp
->base
.hit_count
= 0;
12224 tp
->traceframe_usage
= 0;
12225 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12227 /* If the tracepoint was never downloaded, don't go asking for
12229 if (tp
->number_on_target
== 0)
12231 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12232 phex_nz (loc
->address
, 0));
12234 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12235 if (reply
&& *reply
)
12238 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12244 utp
->hit_count
= 0;
12245 utp
->traceframe_usage
= 0;
12246 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12247 phex_nz (utp
->addr
, 0));
12249 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12250 if (reply
&& *reply
)
12253 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12259 remote_trace_stop (struct target_ops
*self
)
12262 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12263 if (*target_buf
== '\0')
12264 error (_("Target does not support this command."));
12265 if (strcmp (target_buf
, "OK") != 0)
12266 error (_("Bogus reply from target: %s"), target_buf
);
12270 remote_trace_find (struct target_ops
*self
,
12271 enum trace_find_type type
, int num
,
12272 CORE_ADDR addr1
, CORE_ADDR addr2
,
12275 struct remote_state
*rs
= get_remote_state ();
12276 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12278 int target_frameno
= -1, target_tracept
= -1;
12280 /* Lookups other than by absolute frame number depend on the current
12281 trace selected, so make sure it is correct on the remote end
12283 if (type
!= tfind_number
)
12284 set_remote_traceframe ();
12287 strcpy (p
, "QTFrame:");
12288 p
= strchr (p
, '\0');
12292 xsnprintf (p
, endbuf
- p
, "%x", num
);
12295 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12298 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12301 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12302 phex_nz (addr2
, 0));
12304 case tfind_outside
:
12305 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12306 phex_nz (addr2
, 0));
12309 error (_("Unknown trace find type %d"), type
);
12313 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12314 if (*reply
== '\0')
12315 error (_("Target does not support this command."));
12317 while (reply
&& *reply
)
12322 target_frameno
= (int) strtol (p
, &reply
, 16);
12324 error (_("Unable to parse trace frame number"));
12325 /* Don't update our remote traceframe number cache on failure
12326 to select a remote traceframe. */
12327 if (target_frameno
== -1)
12332 target_tracept
= (int) strtol (p
, &reply
, 16);
12334 error (_("Unable to parse tracepoint number"));
12336 case 'O': /* "OK"? */
12337 if (reply
[1] == 'K' && reply
[2] == '\0')
12340 error (_("Bogus reply from target: %s"), reply
);
12343 error (_("Bogus reply from target: %s"), reply
);
12346 *tpp
= target_tracept
;
12348 rs
->remote_traceframe_number
= target_frameno
;
12349 return target_frameno
;
12353 remote_get_trace_state_variable_value (struct target_ops
*self
,
12354 int tsvnum
, LONGEST
*val
)
12356 struct remote_state
*rs
= get_remote_state ();
12360 set_remote_traceframe ();
12362 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12364 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12365 if (reply
&& *reply
)
12369 unpack_varlen_hex (reply
+ 1, &uval
);
12370 *val
= (LONGEST
) uval
;
12378 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12380 struct remote_state
*rs
= get_remote_state ();
12384 strcpy (p
, "QTSave:");
12386 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12387 error (_("Remote file name too long for trace save packet"));
12388 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12391 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12392 if (*reply
== '\0')
12393 error (_("Target does not support this command."));
12394 if (strcmp (reply
, "OK") != 0)
12395 error (_("Bogus reply from target: %s"), reply
);
12399 /* This is basically a memory transfer, but needs to be its own packet
12400 because we don't know how the target actually organizes its trace
12401 memory, plus we want to be able to ask for as much as possible, but
12402 not be unhappy if we don't get as much as we ask for. */
12405 remote_get_raw_trace_data (struct target_ops
*self
,
12406 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12408 struct remote_state
*rs
= get_remote_state ();
12414 strcpy (p
, "qTBuffer:");
12416 p
+= hexnumstr (p
, offset
);
12418 p
+= hexnumstr (p
, len
);
12422 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12423 if (reply
&& *reply
)
12425 /* 'l' by itself means we're at the end of the buffer and
12426 there is nothing more to get. */
12430 /* Convert the reply into binary. Limit the number of bytes to
12431 convert according to our passed-in buffer size, rather than
12432 what was returned in the packet; if the target is
12433 unexpectedly generous and gives us a bigger reply than we
12434 asked for, we don't want to crash. */
12435 rslt
= hex2bin (target_buf
, buf
, len
);
12439 /* Something went wrong, flag as an error. */
12444 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12446 struct remote_state
*rs
= get_remote_state ();
12448 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12452 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12454 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12455 if (*reply
== '\0')
12456 error (_("Target does not support this command."));
12457 if (strcmp (reply
, "OK") != 0)
12458 error (_("Bogus reply from target: %s"), reply
);
12461 warning (_("Target does not support disconnected tracing."));
12465 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12467 struct thread_info
*info
= find_thread_ptid (ptid
);
12469 if (info
&& info
->priv
)
12470 return info
->priv
->core
;
12475 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12477 struct remote_state
*rs
= get_remote_state ();
12480 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12482 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12483 if (*reply
== '\0')
12484 error (_("Target does not support this command."));
12485 if (strcmp (reply
, "OK") != 0)
12486 error (_("Bogus reply from target: %s"), reply
);
12489 static struct traceframe_info
*
12490 remote_traceframe_info (struct target_ops
*self
)
12494 text
= target_read_stralloc (¤t_target
,
12495 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12498 struct traceframe_info
*info
;
12499 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12501 info
= parse_traceframe_info (text
);
12502 do_cleanups (back_to
);
12509 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12510 instruction on which a fast tracepoint may be placed. Returns -1
12511 if the packet is not supported, and 0 if the minimum instruction
12512 length is unknown. */
12515 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12517 struct remote_state
*rs
= get_remote_state ();
12520 /* If we're not debugging a process yet, the IPA can't be
12522 if (!target_has_execution
)
12525 /* Make sure the remote is pointing at the right process. */
12526 set_general_process ();
12528 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12530 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12531 if (*reply
== '\0')
12535 ULONGEST min_insn_len
;
12537 unpack_varlen_hex (reply
, &min_insn_len
);
12539 return (int) min_insn_len
;
12544 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12546 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12548 struct remote_state
*rs
= get_remote_state ();
12549 char *buf
= rs
->buf
;
12550 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12551 enum packet_result result
;
12553 gdb_assert (val
>= 0 || val
== -1);
12554 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12555 /* Send -1 as literal "-1" to avoid host size dependency. */
12559 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12562 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12565 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12566 result
= packet_ok (rs
->buf
,
12567 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12569 if (result
!= PACKET_OK
)
12570 warning (_("Bogus reply from target: %s"), rs
->buf
);
12575 remote_set_trace_notes (struct target_ops
*self
,
12576 const char *user
, const char *notes
,
12577 const char *stop_notes
)
12579 struct remote_state
*rs
= get_remote_state ();
12581 char *buf
= rs
->buf
;
12582 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12585 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12588 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12589 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12595 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12596 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12602 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12603 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12607 /* Ensure the buffer is terminated. */
12611 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12612 if (*reply
== '\0')
12615 if (strcmp (reply
, "OK") != 0)
12616 error (_("Bogus reply from target: %s"), reply
);
12622 remote_use_agent (struct target_ops
*self
, int use
)
12624 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12626 struct remote_state
*rs
= get_remote_state ();
12628 /* If the stub supports QAgent. */
12629 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12631 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12633 if (strcmp (rs
->buf
, "OK") == 0)
12644 remote_can_use_agent (struct target_ops
*self
)
12646 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12649 struct btrace_target_info
12651 /* The ptid of the traced thread. */
12654 /* The obtained branch trace configuration. */
12655 struct btrace_config conf
;
12658 /* Reset our idea of our target's btrace configuration. */
12661 remote_btrace_reset (void)
12663 struct remote_state
*rs
= get_remote_state ();
12665 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12668 /* Check whether the target supports branch tracing. */
12671 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12673 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12675 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12680 case BTRACE_FORMAT_NONE
:
12683 case BTRACE_FORMAT_BTS
:
12684 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12686 case BTRACE_FORMAT_PT
:
12687 /* The trace is decoded on the host. Even if our target supports it,
12688 we still need to have libipt to decode the trace. */
12689 #if defined (HAVE_LIBIPT)
12690 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12691 #else /* !defined (HAVE_LIBIPT) */
12693 #endif /* !defined (HAVE_LIBIPT) */
12696 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12699 /* Synchronize the configuration with the target. */
12702 btrace_sync_conf (const struct btrace_config
*conf
)
12704 struct packet_config
*packet
;
12705 struct remote_state
*rs
;
12706 char *buf
, *pos
, *endbuf
;
12708 rs
= get_remote_state ();
12710 endbuf
= buf
+ get_remote_packet_size ();
12712 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12713 if (packet_config_support (packet
) == PACKET_ENABLE
12714 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12717 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12721 getpkt (&buf
, &rs
->buf_size
, 0);
12723 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12725 if (buf
[0] == 'E' && buf
[1] == '.')
12726 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12728 error (_("Failed to configure the BTS buffer size."));
12731 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12734 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12735 if (packet_config_support (packet
) == PACKET_ENABLE
12736 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12739 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12743 getpkt (&buf
, &rs
->buf_size
, 0);
12745 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12747 if (buf
[0] == 'E' && buf
[1] == '.')
12748 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12750 error (_("Failed to configure the trace buffer size."));
12753 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12757 /* Read the current thread's btrace configuration from the target and
12758 store it into CONF. */
12761 btrace_read_config (struct btrace_config
*conf
)
12765 xml
= target_read_stralloc (¤t_target
,
12766 TARGET_OBJECT_BTRACE_CONF
, "");
12769 struct cleanup
*cleanup
;
12771 cleanup
= make_cleanup (xfree
, xml
);
12772 parse_xml_btrace_conf (conf
, xml
);
12773 do_cleanups (cleanup
);
12777 /* Enable branch tracing. */
12779 static struct btrace_target_info
*
12780 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12781 const struct btrace_config
*conf
)
12783 struct btrace_target_info
*tinfo
= NULL
;
12784 struct packet_config
*packet
= NULL
;
12785 struct remote_state
*rs
= get_remote_state ();
12786 char *buf
= rs
->buf
;
12787 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12789 switch (conf
->format
)
12791 case BTRACE_FORMAT_BTS
:
12792 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12795 case BTRACE_FORMAT_PT
:
12796 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12800 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12801 error (_("Target does not support branch tracing."));
12803 btrace_sync_conf (conf
);
12805 set_general_thread (ptid
);
12807 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12811 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12813 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12814 error (_("Could not enable branch tracing for %s: %s"),
12815 target_pid_to_str (ptid
), rs
->buf
+ 2);
12817 error (_("Could not enable branch tracing for %s."),
12818 target_pid_to_str (ptid
));
12821 tinfo
= XCNEW (struct btrace_target_info
);
12822 tinfo
->ptid
= ptid
;
12824 /* If we fail to read the configuration, we lose some information, but the
12825 tracing itself is not impacted. */
12828 btrace_read_config (&tinfo
->conf
);
12830 CATCH (err
, RETURN_MASK_ERROR
)
12832 if (err
.message
!= NULL
)
12833 warning ("%s", err
.message
);
12840 /* Disable branch tracing. */
12843 remote_disable_btrace (struct target_ops
*self
,
12844 struct btrace_target_info
*tinfo
)
12846 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12847 struct remote_state
*rs
= get_remote_state ();
12848 char *buf
= rs
->buf
;
12849 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12851 if (packet_config_support (packet
) != PACKET_ENABLE
)
12852 error (_("Target does not support branch tracing."));
12854 set_general_thread (tinfo
->ptid
);
12856 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12858 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12860 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12862 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12863 error (_("Could not disable branch tracing for %s: %s"),
12864 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12866 error (_("Could not disable branch tracing for %s."),
12867 target_pid_to_str (tinfo
->ptid
));
12873 /* Teardown branch tracing. */
12876 remote_teardown_btrace (struct target_ops
*self
,
12877 struct btrace_target_info
*tinfo
)
12879 /* We must not talk to the target during teardown. */
12883 /* Read the branch trace. */
12885 static enum btrace_error
12886 remote_read_btrace (struct target_ops
*self
,
12887 struct btrace_data
*btrace
,
12888 struct btrace_target_info
*tinfo
,
12889 enum btrace_read_type type
)
12891 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12892 struct cleanup
*cleanup
;
12896 if (packet_config_support (packet
) != PACKET_ENABLE
)
12897 error (_("Target does not support branch tracing."));
12899 #if !defined(HAVE_LIBEXPAT)
12900 error (_("Cannot process branch tracing result. XML parsing not supported."));
12905 case BTRACE_READ_ALL
:
12908 case BTRACE_READ_NEW
:
12911 case BTRACE_READ_DELTA
:
12915 internal_error (__FILE__
, __LINE__
,
12916 _("Bad branch tracing read type: %u."),
12917 (unsigned int) type
);
12920 xml
= target_read_stralloc (¤t_target
,
12921 TARGET_OBJECT_BTRACE
, annex
);
12923 return BTRACE_ERR_UNKNOWN
;
12925 cleanup
= make_cleanup (xfree
, xml
);
12926 parse_xml_btrace (btrace
, xml
);
12927 do_cleanups (cleanup
);
12929 return BTRACE_ERR_NONE
;
12932 static const struct btrace_config
*
12933 remote_btrace_conf (struct target_ops
*self
,
12934 const struct btrace_target_info
*tinfo
)
12936 return &tinfo
->conf
;
12940 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12942 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12946 /* Implementation of to_load. */
12949 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12951 generic_load (name
, from_tty
);
12954 /* Accepts an integer PID; returns a string representing a file that
12955 can be opened on the remote side to get the symbols for the child
12956 process. Returns NULL if the operation is not supported. */
12959 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12961 static char *filename
= NULL
;
12962 struct inferior
*inf
;
12963 char *annex
= NULL
;
12965 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12968 if (filename
!= NULL
)
12971 inf
= find_inferior_pid (pid
);
12973 internal_error (__FILE__
, __LINE__
,
12974 _("not currently attached to process %d"), pid
);
12976 if (!inf
->fake_pid_p
)
12978 const int annex_size
= 9;
12980 annex
= (char *) alloca (annex_size
);
12981 xsnprintf (annex
, annex_size
, "%x", pid
);
12984 filename
= target_read_stralloc (¤t_target
,
12985 TARGET_OBJECT_EXEC_FILE
, annex
);
12990 /* Implement the to_can_do_single_step target_ops method. */
12993 remote_can_do_single_step (struct target_ops
*ops
)
12995 /* We can only tell whether target supports single step or not by
12996 supported s and S vCont actions if the stub supports vContSupported
12997 feature. If the stub doesn't support vContSupported feature,
12998 we have conservatively to think target doesn't supports single
13000 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13002 struct remote_state
*rs
= get_remote_state ();
13004 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13005 remote_vcont_probe (rs
);
13007 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13013 /* Implementation of the to_execution_direction method for the remote
13016 static enum exec_direction_kind
13017 remote_execution_direction (struct target_ops
*self
)
13019 struct remote_state
*rs
= get_remote_state ();
13021 return rs
->last_resume_exec_dir
;
13025 init_remote_ops (void)
13027 remote_ops
.to_shortname
= "remote";
13028 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13029 remote_ops
.to_doc
=
13030 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13031 Specify the serial device it is connected to\n\
13032 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13033 remote_ops
.to_open
= remote_open
;
13034 remote_ops
.to_close
= remote_close
;
13035 remote_ops
.to_detach
= remote_detach
;
13036 remote_ops
.to_disconnect
= remote_disconnect
;
13037 remote_ops
.to_resume
= remote_resume
;
13038 remote_ops
.to_wait
= remote_wait
;
13039 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13040 remote_ops
.to_store_registers
= remote_store_registers
;
13041 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13042 remote_ops
.to_files_info
= remote_files_info
;
13043 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13044 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13045 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13046 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13047 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13048 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13049 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13050 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13051 remote_ops
.to_watchpoint_addr_within_range
=
13052 remote_watchpoint_addr_within_range
;
13053 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13054 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13055 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13056 remote_ops
.to_region_ok_for_hw_watchpoint
13057 = remote_region_ok_for_hw_watchpoint
;
13058 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13059 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13060 remote_ops
.to_kill
= remote_kill
;
13061 remote_ops
.to_load
= remote_load
;
13062 remote_ops
.to_mourn_inferior
= remote_mourn
;
13063 remote_ops
.to_pass_signals
= remote_pass_signals
;
13064 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13065 remote_ops
.to_program_signals
= remote_program_signals
;
13066 remote_ops
.to_thread_alive
= remote_thread_alive
;
13067 remote_ops
.to_thread_name
= remote_thread_name
;
13068 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13069 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13070 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13071 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13072 remote_ops
.to_stop
= remote_stop
;
13073 remote_ops
.to_interrupt
= remote_interrupt
;
13074 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13075 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13076 remote_ops
.to_get_memory_xfer_limit
= remote_get_memory_xfer_limit
;
13077 remote_ops
.to_rcmd
= remote_rcmd
;
13078 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13079 remote_ops
.to_log_command
= serial_log_command
;
13080 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13081 remote_ops
.to_stratum
= process_stratum
;
13082 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13083 remote_ops
.to_has_memory
= default_child_has_memory
;
13084 remote_ops
.to_has_stack
= default_child_has_stack
;
13085 remote_ops
.to_has_registers
= default_child_has_registers
;
13086 remote_ops
.to_has_execution
= default_child_has_execution
;
13087 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13088 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13089 remote_ops
.to_magic
= OPS_MAGIC
;
13090 remote_ops
.to_memory_map
= remote_memory_map
;
13091 remote_ops
.to_flash_erase
= remote_flash_erase
;
13092 remote_ops
.to_flash_done
= remote_flash_done
;
13093 remote_ops
.to_read_description
= remote_read_description
;
13094 remote_ops
.to_search_memory
= remote_search_memory
;
13095 remote_ops
.to_can_async_p
= remote_can_async_p
;
13096 remote_ops
.to_is_async_p
= remote_is_async_p
;
13097 remote_ops
.to_async
= remote_async
;
13098 remote_ops
.to_thread_events
= remote_thread_events
;
13099 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13100 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13101 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13102 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13103 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13104 remote_ops
.to_supports_disable_randomization
13105 = remote_supports_disable_randomization
;
13106 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13107 remote_ops
.to_fileio_open
= remote_hostio_open
;
13108 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13109 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13110 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13111 remote_ops
.to_fileio_close
= remote_hostio_close
;
13112 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13113 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13114 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13115 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13116 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13117 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13118 remote_ops
.to_trace_init
= remote_trace_init
;
13119 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13120 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13121 remote_ops
.to_download_trace_state_variable
13122 = remote_download_trace_state_variable
;
13123 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13124 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13125 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13126 remote_ops
.to_trace_start
= remote_trace_start
;
13127 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13128 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13129 remote_ops
.to_trace_stop
= remote_trace_stop
;
13130 remote_ops
.to_trace_find
= remote_trace_find
;
13131 remote_ops
.to_get_trace_state_variable_value
13132 = remote_get_trace_state_variable_value
;
13133 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13134 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13135 remote_ops
.to_upload_trace_state_variables
13136 = remote_upload_trace_state_variables
;
13137 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13138 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13139 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13140 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13141 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13142 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13143 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13144 remote_ops
.to_verify_memory
= remote_verify_memory
;
13145 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13146 remote_ops
.to_set_permissions
= remote_set_permissions
;
13147 remote_ops
.to_static_tracepoint_marker_at
13148 = remote_static_tracepoint_marker_at
;
13149 remote_ops
.to_static_tracepoint_markers_by_strid
13150 = remote_static_tracepoint_markers_by_strid
;
13151 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13152 remote_ops
.to_use_agent
= remote_use_agent
;
13153 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13154 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13155 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13156 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13157 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13158 remote_ops
.to_read_btrace
= remote_read_btrace
;
13159 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13160 remote_ops
.to_augmented_libraries_svr4_read
=
13161 remote_augmented_libraries_svr4_read
;
13162 remote_ops
.to_follow_fork
= remote_follow_fork
;
13163 remote_ops
.to_follow_exec
= remote_follow_exec
;
13164 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13165 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13166 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13167 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13168 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13169 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13170 remote_ops
.to_execution_direction
= remote_execution_direction
;
13173 /* Set up the extended remote vector by making a copy of the standard
13174 remote vector and adding to it. */
13177 init_extended_remote_ops (void)
13179 extended_remote_ops
= remote_ops
;
13181 extended_remote_ops
.to_shortname
= "extended-remote";
13182 extended_remote_ops
.to_longname
=
13183 "Extended remote serial target in gdb-specific protocol";
13184 extended_remote_ops
.to_doc
=
13185 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13186 Specify the serial device it is connected to (e.g. /dev/ttya).";
13187 extended_remote_ops
.to_open
= extended_remote_open
;
13188 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13189 extended_remote_ops
.to_detach
= extended_remote_detach
;
13190 extended_remote_ops
.to_attach
= extended_remote_attach
;
13191 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13192 extended_remote_ops
.to_supports_disable_randomization
13193 = extended_remote_supports_disable_randomization
;
13197 remote_can_async_p (struct target_ops
*ops
)
13199 struct remote_state
*rs
= get_remote_state ();
13201 if (!target_async_permitted
)
13202 /* We only enable async when the user specifically asks for it. */
13205 /* We're async whenever the serial device is. */
13206 return serial_can_async_p (rs
->remote_desc
);
13210 remote_is_async_p (struct target_ops
*ops
)
13212 struct remote_state
*rs
= get_remote_state ();
13214 if (!target_async_permitted
)
13215 /* We only enable async when the user specifically asks for it. */
13218 /* We're async whenever the serial device is. */
13219 return serial_is_async_p (rs
->remote_desc
);
13222 /* Pass the SERIAL event on and up to the client. One day this code
13223 will be able to delay notifying the client of an event until the
13224 point where an entire packet has been received. */
13226 static serial_event_ftype remote_async_serial_handler
;
13229 remote_async_serial_handler (struct serial
*scb
, void *context
)
13231 /* Don't propogate error information up to the client. Instead let
13232 the client find out about the error by querying the target. */
13233 inferior_event_handler (INF_REG_EVENT
, NULL
);
13237 remote_async_inferior_event_handler (gdb_client_data data
)
13239 inferior_event_handler (INF_REG_EVENT
, NULL
);
13243 remote_async (struct target_ops
*ops
, int enable
)
13245 struct remote_state
*rs
= get_remote_state ();
13249 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13251 /* If there are pending events in the stop reply queue tell the
13252 event loop to process them. */
13253 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13254 mark_async_event_handler (remote_async_inferior_event_token
);
13255 /* For simplicity, below we clear the pending events token
13256 without remembering whether it is marked, so here we always
13257 mark it. If there's actually no pending notification to
13258 process, this ends up being a no-op (other than a spurious
13259 event-loop wakeup). */
13260 if (target_is_non_stop_p ())
13261 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13265 serial_async (rs
->remote_desc
, NULL
, NULL
);
13266 /* If the core is disabling async, it doesn't want to be
13267 disturbed with target events. Clear all async event sources
13269 clear_async_event_handler (remote_async_inferior_event_token
);
13270 if (target_is_non_stop_p ())
13271 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13275 /* Implementation of the to_thread_events method. */
13278 remote_thread_events (struct target_ops
*ops
, int enable
)
13280 struct remote_state
*rs
= get_remote_state ();
13281 size_t size
= get_remote_packet_size ();
13283 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13286 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13288 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13290 switch (packet_ok (rs
->buf
,
13291 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13294 if (strcmp (rs
->buf
, "OK") != 0)
13295 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13298 warning (_("Remote failure reply: %s"), rs
->buf
);
13300 case PACKET_UNKNOWN
:
13306 set_remote_cmd (char *args
, int from_tty
)
13308 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13312 show_remote_cmd (char *args
, int from_tty
)
13314 /* We can't just use cmd_show_list here, because we want to skip
13315 the redundant "show remote Z-packet" and the legacy aliases. */
13316 struct cleanup
*showlist_chain
;
13317 struct cmd_list_element
*list
= remote_show_cmdlist
;
13318 struct ui_out
*uiout
= current_uiout
;
13320 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13321 for (; list
!= NULL
; list
= list
->next
)
13322 if (strcmp (list
->name
, "Z-packet") == 0)
13324 else if (list
->type
== not_set_cmd
)
13325 /* Alias commands are exactly like the original, except they
13326 don't have the normal type. */
13330 struct cleanup
*option_chain
13331 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13333 ui_out_field_string (uiout
, "name", list
->name
);
13334 ui_out_text (uiout
, ": ");
13335 if (list
->type
== show_cmd
)
13336 do_show_command ((char *) NULL
, from_tty
, list
);
13338 cmd_func (list
, NULL
, from_tty
);
13339 /* Close the tuple. */
13340 do_cleanups (option_chain
);
13343 /* Close the tuple. */
13344 do_cleanups (showlist_chain
);
13348 /* Function to be called whenever a new objfile (shlib) is detected. */
13350 remote_new_objfile (struct objfile
*objfile
)
13352 struct remote_state
*rs
= get_remote_state ();
13354 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13355 remote_check_symbols ();
13358 /* Pull all the tracepoints defined on the target and create local
13359 data structures representing them. We don't want to create real
13360 tracepoints yet, we don't want to mess up the user's existing
13364 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13366 struct remote_state
*rs
= get_remote_state ();
13369 /* Ask for a first packet of tracepoint definition. */
13371 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13373 while (*p
&& *p
!= 'l')
13375 parse_tracepoint_definition (p
, utpp
);
13376 /* Ask for another packet of tracepoint definition. */
13378 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13385 remote_upload_trace_state_variables (struct target_ops
*self
,
13386 struct uploaded_tsv
**utsvp
)
13388 struct remote_state
*rs
= get_remote_state ();
13391 /* Ask for a first packet of variable definition. */
13393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13395 while (*p
&& *p
!= 'l')
13397 parse_tsv_definition (p
, utsvp
);
13398 /* Ask for another packet of variable definition. */
13400 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13406 /* The "set/show range-stepping" show hook. */
13409 show_range_stepping (struct ui_file
*file
, int from_tty
,
13410 struct cmd_list_element
*c
,
13413 fprintf_filtered (file
,
13414 _("Debugger's willingness to use range stepping "
13415 "is %s.\n"), value
);
13418 /* The "set/show range-stepping" set hook. */
13421 set_range_stepping (char *ignore_args
, int from_tty
,
13422 struct cmd_list_element
*c
)
13424 struct remote_state
*rs
= get_remote_state ();
13426 /* Whene enabling, check whether range stepping is actually
13427 supported by the target, and warn if not. */
13428 if (use_range_stepping
)
13430 if (rs
->remote_desc
!= NULL
)
13432 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13433 remote_vcont_probe (rs
);
13435 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13436 && rs
->supports_vCont
.r
)
13440 warning (_("Range stepping is not supported by the current target"));
13445 _initialize_remote (void)
13447 struct cmd_list_element
*cmd
;
13448 const char *cmd_name
;
13450 /* architecture specific data */
13451 remote_gdbarch_data_handle
=
13452 gdbarch_data_register_post_init (init_remote_state
);
13453 remote_g_packet_data_handle
=
13454 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13457 = register_program_space_data_with_cleanup (NULL
,
13458 remote_pspace_data_cleanup
);
13460 /* Initialize the per-target state. At the moment there is only one
13461 of these, not one per target. Only one target is active at a
13463 remote_state
= new_remote_state ();
13465 init_remote_ops ();
13466 add_target (&remote_ops
);
13468 init_extended_remote_ops ();
13469 add_target (&extended_remote_ops
);
13471 /* Hook into new objfile notification. */
13472 observer_attach_new_objfile (remote_new_objfile
);
13473 /* We're no longer interested in notification events of an inferior
13475 observer_attach_inferior_exit (discard_pending_stop_replies
);
13478 init_remote_threadtests ();
13481 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13482 /* set/show remote ... */
13484 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13485 Remote protocol specific variables\n\
13486 Configure various remote-protocol specific variables such as\n\
13487 the packets being used"),
13488 &remote_set_cmdlist
, "set remote ",
13489 0 /* allow-unknown */, &setlist
);
13490 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13491 Remote protocol specific variables\n\
13492 Configure various remote-protocol specific variables such as\n\
13493 the packets being used"),
13494 &remote_show_cmdlist
, "show remote ",
13495 0 /* allow-unknown */, &showlist
);
13497 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13498 Compare section data on target to the exec file.\n\
13499 Argument is a single section name (default: all loaded sections).\n\
13500 To compare only read-only loaded sections, specify the -r option."),
13503 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13504 Send an arbitrary packet to a remote target.\n\
13505 maintenance packet TEXT\n\
13506 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13507 this command sends the string TEXT to the inferior, and displays the\n\
13508 response packet. GDB supplies the initial `$' character, and the\n\
13509 terminating `#' character and checksum."),
13512 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13513 Set whether to send break if interrupted."), _("\
13514 Show whether to send break if interrupted."), _("\
13515 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13516 set_remotebreak
, show_remotebreak
,
13517 &setlist
, &showlist
);
13518 cmd_name
= "remotebreak";
13519 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13520 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13521 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13522 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13523 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13525 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13526 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13528 Set interrupt sequence to remote target."), _("\
13529 Show interrupt sequence to remote target."), _("\
13530 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13531 NULL
, show_interrupt_sequence
,
13532 &remote_set_cmdlist
,
13533 &remote_show_cmdlist
);
13535 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13536 &interrupt_on_connect
, _("\
13537 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13538 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13539 If set, interrupt sequence is sent to remote target."),
13541 &remote_set_cmdlist
, &remote_show_cmdlist
);
13543 /* Install commands for configuring memory read/write packets. */
13545 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13546 Set the maximum number of bytes per memory write packet (deprecated)."),
13548 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13549 Show the maximum number of bytes per memory write packet (deprecated)."),
13551 add_cmd ("memory-write-packet-size", no_class
,
13552 set_memory_write_packet_size
, _("\
13553 Set the maximum number of bytes per memory-write packet.\n\
13554 Specify the number of bytes in a packet or 0 (zero) for the\n\
13555 default packet size. The actual limit is further reduced\n\
13556 dependent on the target. Specify ``fixed'' to disable the\n\
13557 further restriction and ``limit'' to enable that restriction."),
13558 &remote_set_cmdlist
);
13559 add_cmd ("memory-read-packet-size", no_class
,
13560 set_memory_read_packet_size
, _("\
13561 Set the maximum number of bytes per memory-read packet.\n\
13562 Specify the number of bytes in a packet or 0 (zero) for the\n\
13563 default packet size. The actual limit is further reduced\n\
13564 dependent on the target. Specify ``fixed'' to disable the\n\
13565 further restriction and ``limit'' to enable that restriction."),
13566 &remote_set_cmdlist
);
13567 add_cmd ("memory-write-packet-size", no_class
,
13568 show_memory_write_packet_size
,
13569 _("Show the maximum number of bytes per memory-write packet."),
13570 &remote_show_cmdlist
);
13571 add_cmd ("memory-read-packet-size", no_class
,
13572 show_memory_read_packet_size
,
13573 _("Show the maximum number of bytes per memory-read packet."),
13574 &remote_show_cmdlist
);
13576 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13577 &remote_hw_watchpoint_limit
, _("\
13578 Set the maximum number of target hardware watchpoints."), _("\
13579 Show the maximum number of target hardware watchpoints."), _("\
13580 Specify a negative limit for unlimited."),
13581 NULL
, NULL
, /* FIXME: i18n: The maximum
13582 number of target hardware
13583 watchpoints is %s. */
13584 &remote_set_cmdlist
, &remote_show_cmdlist
);
13585 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13586 &remote_hw_watchpoint_length_limit
, _("\
13587 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13588 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13589 Specify a negative limit for unlimited."),
13590 NULL
, NULL
, /* FIXME: i18n: The maximum
13591 length (in bytes) of a target
13592 hardware watchpoint is %s. */
13593 &remote_set_cmdlist
, &remote_show_cmdlist
);
13594 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13595 &remote_hw_breakpoint_limit
, _("\
13596 Set the maximum number of target hardware breakpoints."), _("\
13597 Show the maximum number of target hardware breakpoints."), _("\
13598 Specify a negative limit for unlimited."),
13599 NULL
, NULL
, /* FIXME: i18n: The maximum
13600 number of target hardware
13601 breakpoints is %s. */
13602 &remote_set_cmdlist
, &remote_show_cmdlist
);
13604 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13605 &remote_address_size
, _("\
13606 Set the maximum size of the address (in bits) in a memory packet."), _("\
13607 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13609 NULL
, /* FIXME: i18n: */
13610 &setlist
, &showlist
);
13612 init_all_packet_configs ();
13614 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13615 "X", "binary-download", 1);
13617 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13618 "vCont", "verbose-resume", 0);
13620 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13621 "QPassSignals", "pass-signals", 0);
13623 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
13624 "QCatchSyscalls", "catch-syscalls", 0);
13626 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13627 "QProgramSignals", "program-signals", 0);
13629 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13630 "qSymbol", "symbol-lookup", 0);
13632 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13633 "P", "set-register", 1);
13635 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13636 "p", "fetch-register", 1);
13638 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13639 "Z0", "software-breakpoint", 0);
13641 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13642 "Z1", "hardware-breakpoint", 0);
13644 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13645 "Z2", "write-watchpoint", 0);
13647 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13648 "Z3", "read-watchpoint", 0);
13650 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13651 "Z4", "access-watchpoint", 0);
13653 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13654 "qXfer:auxv:read", "read-aux-vector", 0);
13656 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13657 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13659 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13660 "qXfer:features:read", "target-features", 0);
13662 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13663 "qXfer:libraries:read", "library-info", 0);
13665 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13666 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13668 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13669 "qXfer:memory-map:read", "memory-map", 0);
13671 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13672 "qXfer:spu:read", "read-spu-object", 0);
13674 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13675 "qXfer:spu:write", "write-spu-object", 0);
13677 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13678 "qXfer:osdata:read", "osdata", 0);
13680 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13681 "qXfer:threads:read", "threads", 0);
13683 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13684 "qXfer:siginfo:read", "read-siginfo-object", 0);
13686 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13687 "qXfer:siginfo:write", "write-siginfo-object", 0);
13689 add_packet_config_cmd
13690 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13691 "qXfer:traceframe-info:read", "traceframe-info", 0);
13693 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13694 "qXfer:uib:read", "unwind-info-block", 0);
13696 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13697 "qGetTLSAddr", "get-thread-local-storage-address",
13700 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13701 "qGetTIBAddr", "get-thread-information-block-address",
13704 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13705 "bc", "reverse-continue", 0);
13707 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13708 "bs", "reverse-step", 0);
13710 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13711 "qSupported", "supported-packets", 0);
13713 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13714 "qSearch:memory", "search-memory", 0);
13716 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13717 "qTStatus", "trace-status", 0);
13719 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13720 "vFile:setfs", "hostio-setfs", 0);
13722 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13723 "vFile:open", "hostio-open", 0);
13725 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13726 "vFile:pread", "hostio-pread", 0);
13728 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13729 "vFile:pwrite", "hostio-pwrite", 0);
13731 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13732 "vFile:close", "hostio-close", 0);
13734 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13735 "vFile:unlink", "hostio-unlink", 0);
13737 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13738 "vFile:readlink", "hostio-readlink", 0);
13740 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13741 "vFile:fstat", "hostio-fstat", 0);
13743 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13744 "vAttach", "attach", 0);
13746 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13749 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13750 "QStartNoAckMode", "noack", 0);
13752 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13753 "vKill", "kill", 0);
13755 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13756 "qAttached", "query-attached", 0);
13758 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13759 "ConditionalTracepoints",
13760 "conditional-tracepoints", 0);
13762 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13763 "ConditionalBreakpoints",
13764 "conditional-breakpoints", 0);
13766 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13767 "BreakpointCommands",
13768 "breakpoint-commands", 0);
13770 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13771 "FastTracepoints", "fast-tracepoints", 0);
13773 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13774 "TracepointSource", "TracepointSource", 0);
13776 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13777 "QAllow", "allow", 0);
13779 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13780 "StaticTracepoints", "static-tracepoints", 0);
13782 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13783 "InstallInTrace", "install-in-trace", 0);
13785 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13786 "qXfer:statictrace:read", "read-sdata-object", 0);
13788 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13789 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13791 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13792 "QDisableRandomization", "disable-randomization", 0);
13794 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13795 "QAgent", "agent", 0);
13797 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13798 "QTBuffer:size", "trace-buffer-size", 0);
13800 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13801 "Qbtrace:off", "disable-btrace", 0);
13803 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13804 "Qbtrace:bts", "enable-btrace-bts", 0);
13806 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13807 "Qbtrace:pt", "enable-btrace-pt", 0);
13809 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13810 "qXfer:btrace", "read-btrace", 0);
13812 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13813 "qXfer:btrace-conf", "read-btrace-conf", 0);
13815 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13816 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13818 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13819 "multiprocess-feature", "multiprocess-feature", 0);
13821 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13822 "swbreak-feature", "swbreak-feature", 0);
13824 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13825 "hwbreak-feature", "hwbreak-feature", 0);
13827 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13828 "fork-event-feature", "fork-event-feature", 0);
13830 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13831 "vfork-event-feature", "vfork-event-feature", 0);
13833 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13834 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13836 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13837 "vContSupported", "verbose-resume-supported", 0);
13839 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13840 "exec-event-feature", "exec-event-feature", 0);
13842 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
13843 "vCtrlC", "ctrl-c", 0);
13845 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
13846 "QThreadEvents", "thread-events", 0);
13848 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
13849 "N stop reply", "no-resumed-stop-reply", 0);
13851 /* Assert that we've registered "set remote foo-packet" commands
13852 for all packet configs. */
13856 for (i
= 0; i
< PACKET_MAX
; i
++)
13858 /* Ideally all configs would have a command associated. Some
13859 still don't though. */
13864 case PACKET_QNonStop
:
13865 case PACKET_EnableDisableTracepoints_feature
:
13866 case PACKET_tracenz_feature
:
13867 case PACKET_DisconnectedTracing_feature
:
13868 case PACKET_augmented_libraries_svr4_read_feature
:
13870 /* Additions to this list need to be well justified:
13871 pre-existing packets are OK; new packets are not. */
13879 /* This catches both forgetting to add a config command, and
13880 forgetting to remove a packet from the exception list. */
13881 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13885 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13886 Z sub-packet has its own set and show commands, but users may
13887 have sets to this variable in their .gdbinit files (or in their
13889 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13890 &remote_Z_packet_detect
, _("\
13891 Set use of remote protocol `Z' packets"), _("\
13892 Show use of remote protocol `Z' packets "), _("\
13893 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13895 set_remote_protocol_Z_packet_cmd
,
13896 show_remote_protocol_Z_packet_cmd
,
13897 /* FIXME: i18n: Use of remote protocol
13898 `Z' packets is %s. */
13899 &remote_set_cmdlist
, &remote_show_cmdlist
);
13901 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13902 Manipulate files on the remote system\n\
13903 Transfer files to and from the remote target system."),
13904 &remote_cmdlist
, "remote ",
13905 0 /* allow-unknown */, &cmdlist
);
13907 add_cmd ("put", class_files
, remote_put_command
,
13908 _("Copy a local file to the remote system."),
13911 add_cmd ("get", class_files
, remote_get_command
,
13912 _("Copy a remote file to the local system."),
13915 add_cmd ("delete", class_files
, remote_delete_command
,
13916 _("Delete a remote file."),
13919 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13920 &remote_exec_file_var
, _("\
13921 Set the remote pathname for \"run\""), _("\
13922 Show the remote pathname for \"run\""), NULL
,
13923 set_remote_exec_file
,
13924 show_remote_exec_file
,
13925 &remote_set_cmdlist
,
13926 &remote_show_cmdlist
);
13928 add_setshow_boolean_cmd ("range-stepping", class_run
,
13929 &use_range_stepping
, _("\
13930 Enable or disable range stepping."), _("\
13931 Show whether target-assisted range stepping is enabled."), _("\
13932 If on, and the target supports it, when stepping a source line, GDB\n\
13933 tells the target to step the corresponding range of addresses itself instead\n\
13934 of issuing multiple single-steps. This speeds up source level\n\
13935 stepping. If off, GDB always issues single-steps, even if range\n\
13936 stepping is supported by the target. The default is on."),
13937 set_range_stepping
,
13938 show_range_stepping
,
13942 /* Eventually initialize fileio. See fileio.c */
13943 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13945 /* Take advantage of the fact that the TID field is not used, to tag
13946 special ptids with it set to != 0. */
13947 magic_null_ptid
= ptid_build (42000, -1, 1);
13948 not_sent_ptid
= ptid_build (42000, -2, 1);
13949 any_thread_ptid
= ptid_build (42000, 0, 1);
13951 target_buf_size
= 2048;
13952 target_buf
= (char *) xmalloc (target_buf_size
);