1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
73 #include "record-btrace.h"
75 #include "common/scoped_restore.h"
77 /* Temp hacks for tracepoint encoding migration. */
78 static char *target_buf
;
79 static long target_buf_size
;
81 /* Per-program-space data key. */
82 static const struct program_space_data
*remote_pspace_data
;
84 /* The variable registered as the control variable used by the
85 remote exec-file commands. While the remote exec-file setting is
86 per-program-space, the set/show machinery uses this as the
87 location of the remote exec-file value. */
88 static char *remote_exec_file_var
;
90 /* The size to align memory write packets, when practical. The protocol
91 does not guarantee any alignment, and gdb will generate short
92 writes and unaligned writes, but even as a best-effort attempt this
93 can improve bulk transfers. For instance, if a write is misaligned
94 relative to the target's data bus, the stub may need to make an extra
95 round trip fetching data from the target. This doesn't make a
96 huge difference, but it's easy to do, so we try to be helpful.
98 The alignment chosen is arbitrary; usually data bus width is
99 important here, not the possibly larger cache line size. */
100 enum { REMOTE_ALIGN_WRITES
= 16 };
102 /* Prototypes for local functions. */
103 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
104 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
105 int forever
, int *is_notif
);
107 static void remote_files_info (struct target_ops
*ignore
);
109 static void remote_prepare_to_store (struct target_ops
*self
,
110 struct regcache
*regcache
);
112 static void remote_open_1 (const char *, int, struct target_ops
*,
115 static void remote_close (struct target_ops
*self
);
119 static int remote_vkill (int pid
, struct remote_state
*rs
);
121 static void remote_kill_k (void);
123 static void remote_mourn (struct target_ops
*ops
);
125 static void extended_remote_restart (void);
127 static void remote_send (char **buf
, long *sizeof_buf_p
);
129 static int readchar (int timeout
);
131 static void remote_serial_write (const char *str
, int len
);
133 static void remote_kill (struct target_ops
*ops
);
135 static int remote_can_async_p (struct target_ops
*);
137 static int remote_is_async_p (struct target_ops
*);
139 static void remote_async (struct target_ops
*ops
, int enable
);
141 static void remote_thread_events (struct target_ops
*ops
, int enable
);
143 static void interrupt_query (void);
145 static void set_general_thread (ptid_t ptid
);
146 static void set_continue_thread (ptid_t ptid
);
148 static void get_offsets (void);
150 static void skip_frame (void);
152 static long read_frame (char **buf_p
, long *sizeof_buf
);
154 static int hexnumlen (ULONGEST num
);
156 static void init_remote_ops (void);
158 static void init_extended_remote_ops (void);
160 static void remote_stop (struct target_ops
*self
, ptid_t
);
162 static int stubhex (int ch
);
164 static int hexnumstr (char *, ULONGEST
);
166 static int hexnumnstr (char *, ULONGEST
, int);
168 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
170 static void print_packet (const char *);
172 static void compare_sections_command (char *, int);
174 static void packet_command (char *, int);
176 static int stub_unpack_int (char *buff
, int fieldlength
);
178 static ptid_t
remote_current_thread (ptid_t oldptid
);
180 static int putpkt_binary (const char *buf
, int cnt
);
182 static void check_binary_download (CORE_ADDR addr
);
184 struct packet_config
;
186 static void show_packet_config_cmd (struct packet_config
*config
);
188 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
190 struct cmd_list_element
*c
,
193 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
194 static ptid_t
read_ptid (char *buf
, char **obuf
);
196 static void remote_set_permissions (struct target_ops
*self
);
198 static int remote_get_trace_status (struct target_ops
*self
,
199 struct trace_status
*ts
);
201 static int remote_upload_tracepoints (struct target_ops
*self
,
202 struct uploaded_tp
**utpp
);
204 static int remote_upload_trace_state_variables (struct target_ops
*self
,
205 struct uploaded_tsv
**utsvp
);
207 static void remote_query_supported (void);
209 static void remote_check_symbols (void);
211 void _initialize_remote (void);
214 static void stop_reply_xfree (struct stop_reply
*);
215 static void remote_parse_stop_reply (char *, struct stop_reply
*);
216 static void push_stop_reply (struct stop_reply
*);
217 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
218 static int peek_stop_reply (ptid_t ptid
);
220 struct threads_listing_context
;
221 static void remove_new_fork_children (struct threads_listing_context
*);
223 static void remote_async_inferior_event_handler (gdb_client_data
);
225 static void remote_terminal_ours (struct target_ops
*self
);
227 static int remote_read_description_p (struct target_ops
*target
);
229 static void remote_console_output (char *msg
);
231 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
233 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
235 static void remote_btrace_reset (void);
237 static void remote_btrace_maybe_reopen (void);
239 static int stop_reply_queue_length (void);
241 static void readahead_cache_invalidate (void);
243 static void remote_unpush_and_throw (void);
247 static struct cmd_list_element
*remote_cmdlist
;
249 /* For "set remote" and "show remote". */
251 static struct cmd_list_element
*remote_set_cmdlist
;
252 static struct cmd_list_element
*remote_show_cmdlist
;
254 /* Stub vCont actions support.
256 Each field is a boolean flag indicating whether the stub reports
257 support for the corresponding action. */
259 struct vCont_action_support
274 /* Controls whether GDB is willing to use range stepping. */
276 static int use_range_stepping
= 1;
278 #define OPAQUETHREADBYTES 8
280 /* a 64 bit opaque identifier */
281 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
283 /* About this many threadisds fit in a packet. */
285 #define MAXTHREADLISTRESULTS 32
287 /* The max number of chars in debug output. The rest of chars are
290 #define REMOTE_DEBUG_MAX_CHAR 512
292 /* Data for the vFile:pread readahead cache. */
294 struct readahead_cache
296 /* The file descriptor for the file that is being cached. -1 if the
300 /* The offset into the file that the cache buffer corresponds
304 /* The buffer holding the cache contents. */
306 /* The buffer's size. We try to read as much as fits into a packet
310 /* Cache hit and miss counters. */
315 /* Description of the remote protocol state for the currently
316 connected target. This is per-target state, and independent of the
317 selected architecture. */
321 /* A buffer to use for incoming packets, and its current size. The
322 buffer is grown dynamically for larger incoming packets.
323 Outgoing packets may also be constructed in this buffer.
324 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
325 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
330 /* True if we're going through initial connection setup (finding out
331 about the remote side's threads, relocating symbols, etc.). */
334 /* If we negotiated packet size explicitly (and thus can bypass
335 heuristics for the largest packet size that will not overflow
336 a buffer in the stub), this will be set to that packet size.
337 Otherwise zero, meaning to use the guessed size. */
338 long explicit_packet_size
;
340 /* remote_wait is normally called when the target is running and
341 waits for a stop reply packet. But sometimes we need to call it
342 when the target is already stopped. We can send a "?" packet
343 and have remote_wait read the response. Or, if we already have
344 the response, we can stash it in BUF and tell remote_wait to
345 skip calling getpkt. This flag is set when BUF contains a
346 stop reply packet and the target is not waiting. */
347 int cached_wait_status
;
349 /* True, if in no ack mode. That is, neither GDB nor the stub will
350 expect acks from each other. The connection is assumed to be
354 /* True if we're connected in extended remote mode. */
357 /* True if we resumed the target and we're waiting for the target to
358 stop. In the mean time, we can't start another command/query.
359 The remote server wouldn't be ready to process it, so we'd
360 timeout waiting for a reply that would never come and eventually
361 we'd close the connection. This can happen in asynchronous mode
362 because we allow GDB commands while the target is running. */
363 int waiting_for_stop_reply
;
365 /* The status of the stub support for the various vCont actions. */
366 struct vCont_action_support supports_vCont
;
368 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
369 responded to that. */
372 /* True if we saw a Ctrl-C while reading or writing from/to the
373 remote descriptor. At that point it is not safe to send a remote
374 interrupt packet, so we instead remember we saw the Ctrl-C and
375 process it once we're done with sending/receiving the current
376 packet, which should be shortly. If however that takes too long,
377 and the user presses Ctrl-C again, we offer to disconnect. */
378 int got_ctrlc_during_io
;
380 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
381 remote_open knows that we don't have a file open when the program
383 struct serial
*remote_desc
;
385 /* These are the threads which we last sent to the remote system. The
386 TID member will be -1 for all or -2 for not sent yet. */
387 ptid_t general_thread
;
388 ptid_t continue_thread
;
390 /* This is the traceframe which we last selected on the remote system.
391 It will be -1 if no traceframe is selected. */
392 int remote_traceframe_number
;
394 char *last_pass_packet
;
396 /* The last QProgramSignals packet sent to the target. We bypass
397 sending a new program signals list down to the target if the new
398 packet is exactly the same as the last we sent. IOW, we only let
399 the target know about program signals list changes. */
400 char *last_program_signals_packet
;
402 enum gdb_signal last_sent_signal
;
406 /* The execution direction of the last resume we got. */
407 enum exec_direction_kind last_resume_exec_dir
;
409 char *finished_object
;
410 char *finished_annex
;
411 ULONGEST finished_offset
;
413 /* Should we try the 'ThreadInfo' query packet?
415 This variable (NOT available to the user: auto-detect only!)
416 determines whether GDB will use the new, simpler "ThreadInfo"
417 query or the older, more complex syntax for thread queries.
418 This is an auto-detect variable (set to true at each connect,
419 and set to false when the target fails to recognize it). */
420 int use_threadinfo_query
;
421 int use_threadextra_query
;
423 threadref echo_nextthread
;
424 threadref nextthread
;
425 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
427 /* The state of remote notification. */
428 struct remote_notif_state
*notif_state
;
430 /* The branch trace configuration. */
431 struct btrace_config btrace_config
;
433 /* The argument to the last "vFile:setfs:" packet we sent, used
434 to avoid sending repeated unnecessary "vFile:setfs:" packets.
435 Initialized to -1 to indicate that no "vFile:setfs:" packet
436 has yet been sent. */
439 /* A readahead cache for vFile:pread. Often, reading a binary
440 involves a sequence of small reads. E.g., when parsing an ELF
441 file. A readahead cache helps mostly the case of remote
442 debugging on a connection with higher latency, due to the
443 request/reply nature of the RSP. We only cache data for a single
444 file descriptor at a time. */
445 struct readahead_cache readahead_cache
;
448 /* Private data that we'll store in (struct thread_info)->private. */
449 struct private_thread_info
455 /* Whether the target stopped for a breakpoint/watchpoint. */
456 enum target_stop_reason stop_reason
;
458 /* This is set to the data address of the access causing the target
459 to stop for a watchpoint. */
460 CORE_ADDR watch_data_address
;
462 /* Fields used by the vCont action coalescing implemented in
463 remote_resume / remote_commit_resume. remote_resume stores each
464 thread's last resume request in these fields, so that a later
465 remote_commit_resume knows which is the proper action for this
466 thread to include in the vCont packet. */
468 /* True if the last target_resume call for this thread was a step
469 request, false if a continue request. */
470 int last_resume_step
;
472 /* The signal specified in the last target_resume call for this
474 enum gdb_signal last_resume_sig
;
476 /* Whether this thread was already vCont-resumed on the remote
482 free_private_thread_info (struct private_thread_info
*info
)
489 /* This data could be associated with a target, but we do not always
490 have access to the current target when we need it, so for now it is
491 static. This will be fine for as long as only one target is in use
493 static struct remote_state
*remote_state
;
495 static struct remote_state
*
496 get_remote_state_raw (void)
501 /* Allocate a new struct remote_state with xmalloc, initialize it, and
504 static struct remote_state
*
505 new_remote_state (void)
507 struct remote_state
*result
= XCNEW (struct remote_state
);
509 /* The default buffer size is unimportant; it will be expanded
510 whenever a larger buffer is needed. */
511 result
->buf_size
= 400;
512 result
->buf
= (char *) xmalloc (result
->buf_size
);
513 result
->remote_traceframe_number
= -1;
514 result
->last_sent_signal
= GDB_SIGNAL_0
;
515 result
->last_resume_exec_dir
= EXEC_FORWARD
;
521 /* Description of the remote protocol for a given architecture. */
525 long offset
; /* Offset into G packet. */
526 long regnum
; /* GDB's internal register number. */
527 LONGEST pnum
; /* Remote protocol register number. */
528 int in_g_packet
; /* Always part of G packet. */
529 /* long size in bytes; == register_size (target_gdbarch (), regnum);
531 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
535 struct remote_arch_state
537 /* Description of the remote protocol registers. */
538 long sizeof_g_packet
;
540 /* Description of the remote protocol registers indexed by REGNUM
541 (making an array gdbarch_num_regs in size). */
542 struct packet_reg
*regs
;
544 /* This is the size (in chars) of the first response to the ``g''
545 packet. It is used as a heuristic when determining the maximum
546 size of memory-read and memory-write packets. A target will
547 typically only reserve a buffer large enough to hold the ``g''
548 packet. The size does not include packet overhead (headers and
550 long actual_register_packet_size
;
552 /* This is the maximum size (in chars) of a non read/write packet.
553 It is also used as a cap on the size of read/write packets. */
554 long remote_packet_size
;
557 /* Utility: generate error from an incoming stub packet. */
559 trace_error (char *buf
)
562 return; /* not an error msg */
565 case '1': /* malformed packet error */
566 if (*++buf
== '0') /* general case: */
567 error (_("remote.c: error in outgoing packet."));
569 error (_("remote.c: error in outgoing packet at field #%ld."),
570 strtol (buf
, NULL
, 16));
572 error (_("Target returns error code '%s'."), buf
);
576 /* Utility: wait for reply from stub, while accepting "O" packets. */
578 remote_get_noisy_reply (char **buf_p
,
581 do /* Loop on reply from remote stub. */
585 QUIT
; /* Allow user to bail out with ^C. */
586 getpkt (buf_p
, sizeof_buf
, 0);
590 else if (startswith (buf
, "qRelocInsn:"))
593 CORE_ADDR from
, to
, org_to
;
595 int adjusted_size
= 0;
598 p
= buf
+ strlen ("qRelocInsn:");
599 pp
= unpack_varlen_hex (p
, &ul
);
601 error (_("invalid qRelocInsn packet: %s"), buf
);
605 unpack_varlen_hex (p
, &ul
);
612 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
615 CATCH (ex
, RETURN_MASK_ALL
)
617 if (ex
.error
== MEMORY_ERROR
)
619 /* Propagate memory errors silently back to the
620 target. The stub may have limited the range of
621 addresses we can write to, for example. */
625 /* Something unexpectedly bad happened. Be verbose
626 so we can tell what, and propagate the error back
627 to the stub, so it doesn't get stuck waiting for
629 exception_fprintf (gdb_stderr
, ex
,
630 _("warning: relocating instruction: "));
638 adjusted_size
= to
- org_to
;
640 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
644 else if (buf
[0] == 'O' && buf
[1] != 'K')
645 remote_console_output (buf
+ 1); /* 'O' message from stub */
647 return buf
; /* Here's the actual reply. */
652 /* Handle for retreving the remote protocol data from gdbarch. */
653 static struct gdbarch_data
*remote_gdbarch_data_handle
;
655 static struct remote_arch_state
*
656 get_remote_arch_state (void)
658 gdb_assert (target_gdbarch () != NULL
);
659 return ((struct remote_arch_state
*)
660 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
663 /* Fetch the global remote target state. */
665 static struct remote_state
*
666 get_remote_state (void)
668 /* Make sure that the remote architecture state has been
669 initialized, because doing so might reallocate rs->buf. Any
670 function which calls getpkt also needs to be mindful of changes
671 to rs->buf, but this call limits the number of places which run
673 get_remote_arch_state ();
675 return get_remote_state_raw ();
678 /* Cleanup routine for the remote module's pspace data. */
681 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
683 char *remote_exec_file
= (char *) arg
;
685 xfree (remote_exec_file
);
688 /* Fetch the remote exec-file from the current program space. */
691 get_remote_exec_file (void)
693 char *remote_exec_file
;
696 = (char *) program_space_data (current_program_space
,
698 if (remote_exec_file
== NULL
)
701 return remote_exec_file
;
704 /* Set the remote exec file for PSPACE. */
707 set_pspace_remote_exec_file (struct program_space
*pspace
,
708 char *remote_exec_file
)
710 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
713 set_program_space_data (pspace
, remote_pspace_data
,
714 xstrdup (remote_exec_file
));
717 /* The "set/show remote exec-file" set command hook. */
720 set_remote_exec_file (char *ignored
, int from_tty
,
721 struct cmd_list_element
*c
)
723 gdb_assert (remote_exec_file_var
!= NULL
);
724 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
727 /* The "set/show remote exec-file" show command hook. */
730 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
731 struct cmd_list_element
*cmd
, const char *value
)
733 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
737 compare_pnums (const void *lhs_
, const void *rhs_
)
739 const struct packet_reg
* const *lhs
740 = (const struct packet_reg
* const *) lhs_
;
741 const struct packet_reg
* const *rhs
742 = (const struct packet_reg
* const *) rhs_
;
744 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
746 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
753 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
755 int regnum
, num_remote_regs
, offset
;
756 struct packet_reg
**remote_regs
;
758 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
760 struct packet_reg
*r
= ®s
[regnum
];
762 if (register_size (gdbarch
, regnum
) == 0)
763 /* Do not try to fetch zero-sized (placeholder) registers. */
766 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
771 /* Define the g/G packet format as the contents of each register
772 with a remote protocol number, in order of ascending protocol
775 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
776 for (num_remote_regs
= 0, regnum
= 0;
777 regnum
< gdbarch_num_regs (gdbarch
);
779 if (regs
[regnum
].pnum
!= -1)
780 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
782 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
785 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
787 remote_regs
[regnum
]->in_g_packet
= 1;
788 remote_regs
[regnum
]->offset
= offset
;
789 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
795 /* Given the architecture described by GDBARCH, return the remote
796 protocol register's number and the register's offset in the g/G
797 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
798 If the target does not have a mapping for REGNUM, return false,
799 otherwise, return true. */
802 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
803 int *pnum
, int *poffset
)
805 struct packet_reg
*regs
;
806 struct cleanup
*old_chain
;
808 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
810 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
811 old_chain
= make_cleanup (xfree
, regs
);
813 map_regcache_remote_table (gdbarch
, regs
);
815 *pnum
= regs
[regnum
].pnum
;
816 *poffset
= regs
[regnum
].offset
;
818 do_cleanups (old_chain
);
824 init_remote_state (struct gdbarch
*gdbarch
)
826 struct remote_state
*rs
= get_remote_state_raw ();
827 struct remote_arch_state
*rsa
;
829 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
831 /* Use the architecture to build a regnum<->pnum table, which will be
832 1:1 unless a feature set specifies otherwise. */
833 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
834 gdbarch_num_regs (gdbarch
),
837 /* Record the maximum possible size of the g packet - it may turn out
839 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
841 /* Default maximum number of characters in a packet body. Many
842 remote stubs have a hardwired buffer size of 400 bytes
843 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
844 as the maximum packet-size to ensure that the packet and an extra
845 NUL character can always fit in the buffer. This stops GDB
846 trashing stubs that try to squeeze an extra NUL into what is
847 already a full buffer (As of 1999-12-04 that was most stubs). */
848 rsa
->remote_packet_size
= 400 - 1;
850 /* This one is filled in when a ``g'' packet is received. */
851 rsa
->actual_register_packet_size
= 0;
853 /* Should rsa->sizeof_g_packet needs more space than the
854 default, adjust the size accordingly. Remember that each byte is
855 encoded as two characters. 32 is the overhead for the packet
856 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
857 (``$NN:G...#NN'') is a better guess, the below has been padded a
859 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
860 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
862 /* Make sure that the packet buffer is plenty big enough for
863 this architecture. */
864 if (rs
->buf_size
< rsa
->remote_packet_size
)
866 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
867 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
873 /* Return the current allowed size of a remote packet. This is
874 inferred from the current architecture, and should be used to
875 limit the length of outgoing packets. */
877 get_remote_packet_size (void)
879 struct remote_state
*rs
= get_remote_state ();
880 struct remote_arch_state
*rsa
= get_remote_arch_state ();
882 if (rs
->explicit_packet_size
)
883 return rs
->explicit_packet_size
;
885 return rsa
->remote_packet_size
;
888 static struct packet_reg
*
889 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
891 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
895 struct packet_reg
*r
= &rsa
->regs
[regnum
];
897 gdb_assert (r
->regnum
== regnum
);
902 static struct packet_reg
*
903 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
907 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
909 struct packet_reg
*r
= &rsa
->regs
[i
];
917 static struct target_ops remote_ops
;
919 static struct target_ops extended_remote_ops
;
921 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
922 ``forever'' still use the normal timeout mechanism. This is
923 currently used by the ASYNC code to guarentee that target reads
924 during the initial connect always time-out. Once getpkt has been
925 modified to return a timeout indication and, in turn
926 remote_wait()/wait_for_inferior() have gained a timeout parameter
928 static int wait_forever_enabled_p
= 1;
930 /* Allow the user to specify what sequence to send to the remote
931 when he requests a program interruption: Although ^C is usually
932 what remote systems expect (this is the default, here), it is
933 sometimes preferable to send a break. On other systems such
934 as the Linux kernel, a break followed by g, which is Magic SysRq g
935 is required in order to interrupt the execution. */
936 const char interrupt_sequence_control_c
[] = "Ctrl-C";
937 const char interrupt_sequence_break
[] = "BREAK";
938 const char interrupt_sequence_break_g
[] = "BREAK-g";
939 static const char *const interrupt_sequence_modes
[] =
941 interrupt_sequence_control_c
,
942 interrupt_sequence_break
,
943 interrupt_sequence_break_g
,
946 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
949 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
950 struct cmd_list_element
*c
,
953 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
954 fprintf_filtered (file
,
955 _("Send the ASCII ETX character (Ctrl-c) "
956 "to the remote target to interrupt the "
957 "execution of the program.\n"));
958 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
959 fprintf_filtered (file
,
960 _("send a break signal to the remote target "
961 "to interrupt the execution of the program.\n"));
962 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
963 fprintf_filtered (file
,
964 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
965 "the remote target to interrupt the execution "
966 "of Linux kernel.\n"));
968 internal_error (__FILE__
, __LINE__
,
969 _("Invalid value for interrupt_sequence_mode: %s."),
970 interrupt_sequence_mode
);
973 /* This boolean variable specifies whether interrupt_sequence is sent
974 to the remote target when gdb connects to it.
975 This is mostly needed when you debug the Linux kernel: The Linux kernel
976 expects BREAK g which is Magic SysRq g for connecting gdb. */
977 static int interrupt_on_connect
= 0;
979 /* This variable is used to implement the "set/show remotebreak" commands.
980 Since these commands are now deprecated in favor of "set/show remote
981 interrupt-sequence", it no longer has any effect on the code. */
982 static int remote_break
;
985 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
988 interrupt_sequence_mode
= interrupt_sequence_break
;
990 interrupt_sequence_mode
= interrupt_sequence_control_c
;
994 show_remotebreak (struct ui_file
*file
, int from_tty
,
995 struct cmd_list_element
*c
,
1000 /* This variable sets the number of bits in an address that are to be
1001 sent in a memory ("M" or "m") packet. Normally, after stripping
1002 leading zeros, the entire address would be sent. This variable
1003 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
1004 initial implementation of remote.c restricted the address sent in
1005 memory packets to ``host::sizeof long'' bytes - (typically 32
1006 bits). Consequently, for 64 bit targets, the upper 32 bits of an
1007 address was never sent. Since fixing this bug may cause a break in
1008 some remote targets this variable is principly provided to
1009 facilitate backward compatibility. */
1011 static unsigned int remote_address_size
;
1013 /* Temporary to track who currently owns the terminal. See
1014 remote_terminal_* for more details. */
1016 static int remote_async_terminal_ours_p
;
1019 /* User configurable variables for the number of characters in a
1020 memory read/write packet. MIN (rsa->remote_packet_size,
1021 rsa->sizeof_g_packet) is the default. Some targets need smaller
1022 values (fifo overruns, et.al.) and some users need larger values
1023 (speed up transfers). The variables ``preferred_*'' (the user
1024 request), ``current_*'' (what was actually set) and ``forced_*''
1025 (Positive - a soft limit, negative - a hard limit). */
1027 struct memory_packet_config
1034 /* The default max memory-write-packet-size. The 16k is historical.
1035 (It came from older GDB's using alloca for buffers and the
1036 knowledge (folklore?) that some hosts don't cope very well with
1037 large alloca calls.) */
1038 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1040 /* The minimum remote packet size for memory transfers. Ensures we
1041 can write at least one byte. */
1042 #define MIN_MEMORY_PACKET_SIZE 20
1044 /* Compute the current size of a read/write packet. Since this makes
1045 use of ``actual_register_packet_size'' the computation is dynamic. */
1048 get_memory_packet_size (struct memory_packet_config
*config
)
1050 struct remote_state
*rs
= get_remote_state ();
1051 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1054 if (config
->fixed_p
)
1056 if (config
->size
<= 0)
1057 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1059 what_they_get
= config
->size
;
1063 what_they_get
= get_remote_packet_size ();
1064 /* Limit the packet to the size specified by the user. */
1065 if (config
->size
> 0
1066 && what_they_get
> config
->size
)
1067 what_they_get
= config
->size
;
1069 /* Limit it to the size of the targets ``g'' response unless we have
1070 permission from the stub to use a larger packet size. */
1071 if (rs
->explicit_packet_size
== 0
1072 && rsa
->actual_register_packet_size
> 0
1073 && what_they_get
> rsa
->actual_register_packet_size
)
1074 what_they_get
= rsa
->actual_register_packet_size
;
1076 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1077 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1079 /* Make sure there is room in the global buffer for this packet
1080 (including its trailing NUL byte). */
1081 if (rs
->buf_size
< what_they_get
+ 1)
1083 rs
->buf_size
= 2 * what_they_get
;
1084 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1087 return what_they_get
;
1090 /* Update the size of a read/write packet. If they user wants
1091 something really big then do a sanity check. */
1094 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1096 int fixed_p
= config
->fixed_p
;
1097 long size
= config
->size
;
1100 error (_("Argument required (integer, `fixed' or `limited')."));
1101 else if (strcmp (args
, "hard") == 0
1102 || strcmp (args
, "fixed") == 0)
1104 else if (strcmp (args
, "soft") == 0
1105 || strcmp (args
, "limit") == 0)
1111 size
= strtoul (args
, &end
, 0);
1113 error (_("Invalid %s (bad syntax)."), config
->name
);
1115 /* Instead of explicitly capping the size of a packet to or
1116 disallowing it, the user is allowed to set the size to
1117 something arbitrarily large. */
1120 /* So that the query shows the correct value. */
1122 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1125 if (fixed_p
&& !config
->fixed_p
)
1127 if (! query (_("The target may not be able to correctly handle a %s\n"
1128 "of %ld bytes. Change the packet size? "),
1129 config
->name
, size
))
1130 error (_("Packet size not changed."));
1132 /* Update the config. */
1133 config
->fixed_p
= fixed_p
;
1134 config
->size
= size
;
1138 show_memory_packet_size (struct memory_packet_config
*config
)
1140 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1141 if (config
->fixed_p
)
1142 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1143 get_memory_packet_size (config
));
1145 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1146 get_memory_packet_size (config
));
1149 static struct memory_packet_config memory_write_packet_config
=
1151 "memory-write-packet-size",
1155 set_memory_write_packet_size (char *args
, int from_tty
)
1157 set_memory_packet_size (args
, &memory_write_packet_config
);
1161 show_memory_write_packet_size (char *args
, int from_tty
)
1163 show_memory_packet_size (&memory_write_packet_config
);
1167 get_memory_write_packet_size (void)
1169 return get_memory_packet_size (&memory_write_packet_config
);
1172 static struct memory_packet_config memory_read_packet_config
=
1174 "memory-read-packet-size",
1178 set_memory_read_packet_size (char *args
, int from_tty
)
1180 set_memory_packet_size (args
, &memory_read_packet_config
);
1184 show_memory_read_packet_size (char *args
, int from_tty
)
1186 show_memory_packet_size (&memory_read_packet_config
);
1190 get_memory_read_packet_size (void)
1192 long size
= get_memory_packet_size (&memory_read_packet_config
);
1194 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1195 extra buffer size argument before the memory read size can be
1196 increased beyond this. */
1197 if (size
> get_remote_packet_size ())
1198 size
= get_remote_packet_size ();
1203 /* Generic configuration support for packets the stub optionally
1204 supports. Allows the user to specify the use of the packet as well
1205 as allowing GDB to auto-detect support in the remote stub. */
1209 PACKET_SUPPORT_UNKNOWN
= 0,
1214 struct packet_config
1219 /* If auto, GDB auto-detects support for this packet or feature,
1220 either through qSupported, or by trying the packet and looking
1221 at the response. If true, GDB assumes the target supports this
1222 packet. If false, the packet is disabled. Configs that don't
1223 have an associated command always have this set to auto. */
1224 enum auto_boolean detect
;
1226 /* Does the target support this packet? */
1227 enum packet_support support
;
1230 /* Analyze a packet's return value and update the packet config
1240 static enum packet_support
packet_config_support (struct packet_config
*config
);
1241 static enum packet_support
packet_support (int packet
);
1244 show_packet_config_cmd (struct packet_config
*config
)
1246 const char *support
= "internal-error";
1248 switch (packet_config_support (config
))
1251 support
= "enabled";
1253 case PACKET_DISABLE
:
1254 support
= "disabled";
1256 case PACKET_SUPPORT_UNKNOWN
:
1257 support
= "unknown";
1260 switch (config
->detect
)
1262 case AUTO_BOOLEAN_AUTO
:
1263 printf_filtered (_("Support for the `%s' packet "
1264 "is auto-detected, currently %s.\n"),
1265 config
->name
, support
);
1267 case AUTO_BOOLEAN_TRUE
:
1268 case AUTO_BOOLEAN_FALSE
:
1269 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1270 config
->name
, support
);
1276 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1277 const char *title
, int legacy
)
1283 config
->name
= name
;
1284 config
->title
= title
;
1285 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1287 show_doc
= xstrprintf ("Show current use of remote "
1288 "protocol `%s' (%s) packet",
1290 /* set/show TITLE-packet {auto,on,off} */
1291 cmd_name
= xstrprintf ("%s-packet", title
);
1292 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1293 &config
->detect
, set_doc
,
1294 show_doc
, NULL
, /* help_doc */
1296 show_remote_protocol_packet_cmd
,
1297 &remote_set_cmdlist
, &remote_show_cmdlist
);
1298 /* The command code copies the documentation strings. */
1301 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1306 legacy_name
= xstrprintf ("%s-packet", name
);
1307 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1308 &remote_set_cmdlist
);
1309 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1310 &remote_show_cmdlist
);
1314 static enum packet_result
1315 packet_check_result (const char *buf
)
1319 /* The stub recognized the packet request. Check that the
1320 operation succeeded. */
1322 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1324 /* "Enn" - definitly an error. */
1325 return PACKET_ERROR
;
1327 /* Always treat "E." as an error. This will be used for
1328 more verbose error messages, such as E.memtypes. */
1329 if (buf
[0] == 'E' && buf
[1] == '.')
1330 return PACKET_ERROR
;
1332 /* The packet may or may not be OK. Just assume it is. */
1336 /* The stub does not support the packet. */
1337 return PACKET_UNKNOWN
;
1340 static enum packet_result
1341 packet_ok (const char *buf
, struct packet_config
*config
)
1343 enum packet_result result
;
1345 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1346 && config
->support
== PACKET_DISABLE
)
1347 internal_error (__FILE__
, __LINE__
,
1348 _("packet_ok: attempt to use a disabled packet"));
1350 result
= packet_check_result (buf
);
1355 /* The stub recognized the packet request. */
1356 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1359 fprintf_unfiltered (gdb_stdlog
,
1360 "Packet %s (%s) is supported\n",
1361 config
->name
, config
->title
);
1362 config
->support
= PACKET_ENABLE
;
1365 case PACKET_UNKNOWN
:
1366 /* The stub does not support the packet. */
1367 if (config
->detect
== AUTO_BOOLEAN_AUTO
1368 && config
->support
== PACKET_ENABLE
)
1370 /* If the stub previously indicated that the packet was
1371 supported then there is a protocol error. */
1372 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1373 config
->name
, config
->title
);
1375 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1377 /* The user set it wrong. */
1378 error (_("Enabled packet %s (%s) not recognized by stub"),
1379 config
->name
, config
->title
);
1383 fprintf_unfiltered (gdb_stdlog
,
1384 "Packet %s (%s) is NOT supported\n",
1385 config
->name
, config
->title
);
1386 config
->support
= PACKET_DISABLE
;
1407 PACKET_vFile_pwrite
,
1409 PACKET_vFile_unlink
,
1410 PACKET_vFile_readlink
,
1413 PACKET_qXfer_features
,
1414 PACKET_qXfer_exec_file
,
1415 PACKET_qXfer_libraries
,
1416 PACKET_qXfer_libraries_svr4
,
1417 PACKET_qXfer_memory_map
,
1418 PACKET_qXfer_spu_read
,
1419 PACKET_qXfer_spu_write
,
1420 PACKET_qXfer_osdata
,
1421 PACKET_qXfer_threads
,
1422 PACKET_qXfer_statictrace_read
,
1423 PACKET_qXfer_traceframe_info
,
1429 PACKET_QPassSignals
,
1430 PACKET_QCatchSyscalls
,
1431 PACKET_QProgramSignals
,
1432 PACKET_QStartupWithShell
,
1434 PACKET_qSearch_memory
,
1437 PACKET_QStartNoAckMode
,
1439 PACKET_qXfer_siginfo_read
,
1440 PACKET_qXfer_siginfo_write
,
1443 /* Support for conditional tracepoints. */
1444 PACKET_ConditionalTracepoints
,
1446 /* Support for target-side breakpoint conditions. */
1447 PACKET_ConditionalBreakpoints
,
1449 /* Support for target-side breakpoint commands. */
1450 PACKET_BreakpointCommands
,
1452 /* Support for fast tracepoints. */
1453 PACKET_FastTracepoints
,
1455 /* Support for static tracepoints. */
1456 PACKET_StaticTracepoints
,
1458 /* Support for installing tracepoints while a trace experiment is
1460 PACKET_InstallInTrace
,
1464 PACKET_TracepointSource
,
1467 PACKET_QDisableRandomization
,
1469 PACKET_QTBuffer_size
,
1473 PACKET_qXfer_btrace
,
1475 /* Support for the QNonStop packet. */
1478 /* Support for the QThreadEvents packet. */
1479 PACKET_QThreadEvents
,
1481 /* Support for multi-process extensions. */
1482 PACKET_multiprocess_feature
,
1484 /* Support for enabling and disabling tracepoints while a trace
1485 experiment is running. */
1486 PACKET_EnableDisableTracepoints_feature
,
1488 /* Support for collecting strings using the tracenz bytecode. */
1489 PACKET_tracenz_feature
,
1491 /* Support for continuing to run a trace experiment while GDB is
1493 PACKET_DisconnectedTracing_feature
,
1495 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1496 PACKET_augmented_libraries_svr4_read_feature
,
1498 /* Support for the qXfer:btrace-conf:read packet. */
1499 PACKET_qXfer_btrace_conf
,
1501 /* Support for the Qbtrace-conf:bts:size packet. */
1502 PACKET_Qbtrace_conf_bts_size
,
1504 /* Support for swbreak+ feature. */
1505 PACKET_swbreak_feature
,
1507 /* Support for hwbreak+ feature. */
1508 PACKET_hwbreak_feature
,
1510 /* Support for fork events. */
1511 PACKET_fork_event_feature
,
1513 /* Support for vfork events. */
1514 PACKET_vfork_event_feature
,
1516 /* Support for the Qbtrace-conf:pt:size packet. */
1517 PACKET_Qbtrace_conf_pt_size
,
1519 /* Support for exec events. */
1520 PACKET_exec_event_feature
,
1522 /* Support for query supported vCont actions. */
1523 PACKET_vContSupported
,
1525 /* Support remote CTRL-C. */
1528 /* Support TARGET_WAITKIND_NO_RESUMED. */
1534 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1536 /* Returns the packet's corresponding "set remote foo-packet" command
1537 state. See struct packet_config for more details. */
1539 static enum auto_boolean
1540 packet_set_cmd_state (int packet
)
1542 return remote_protocol_packets
[packet
].detect
;
1545 /* Returns whether a given packet or feature is supported. This takes
1546 into account the state of the corresponding "set remote foo-packet"
1547 command, which may be used to bypass auto-detection. */
1549 static enum packet_support
1550 packet_config_support (struct packet_config
*config
)
1552 switch (config
->detect
)
1554 case AUTO_BOOLEAN_TRUE
:
1555 return PACKET_ENABLE
;
1556 case AUTO_BOOLEAN_FALSE
:
1557 return PACKET_DISABLE
;
1558 case AUTO_BOOLEAN_AUTO
:
1559 return config
->support
;
1561 gdb_assert_not_reached (_("bad switch"));
1565 /* Same as packet_config_support, but takes the packet's enum value as
1568 static enum packet_support
1569 packet_support (int packet
)
1571 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1573 return packet_config_support (config
);
1577 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1578 struct cmd_list_element
*c
,
1581 struct packet_config
*packet
;
1583 for (packet
= remote_protocol_packets
;
1584 packet
< &remote_protocol_packets
[PACKET_MAX
];
1587 if (&packet
->detect
== c
->var
)
1589 show_packet_config_cmd (packet
);
1593 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1597 /* Should we try one of the 'Z' requests? */
1601 Z_PACKET_SOFTWARE_BP
,
1602 Z_PACKET_HARDWARE_BP
,
1609 /* For compatibility with older distributions. Provide a ``set remote
1610 Z-packet ...'' command that updates all the Z packet types. */
1612 static enum auto_boolean remote_Z_packet_detect
;
1615 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1616 struct cmd_list_element
*c
)
1620 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1621 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1625 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1626 struct cmd_list_element
*c
,
1631 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1633 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1637 /* Returns true if the multi-process extensions are in effect. */
1640 remote_multi_process_p (struct remote_state
*rs
)
1642 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1645 /* Returns true if fork events are supported. */
1648 remote_fork_event_p (struct remote_state
*rs
)
1650 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1653 /* Returns true if vfork events are supported. */
1656 remote_vfork_event_p (struct remote_state
*rs
)
1658 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1661 /* Returns true if exec events are supported. */
1664 remote_exec_event_p (struct remote_state
*rs
)
1666 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1669 /* Insert fork catchpoint target routine. If fork events are enabled
1670 then return success, nothing more to do. */
1673 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1675 struct remote_state
*rs
= get_remote_state ();
1677 return !remote_fork_event_p (rs
);
1680 /* Remove fork catchpoint target routine. Nothing to do, just
1684 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1689 /* Insert vfork catchpoint target routine. If vfork events are enabled
1690 then return success, nothing more to do. */
1693 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1695 struct remote_state
*rs
= get_remote_state ();
1697 return !remote_vfork_event_p (rs
);
1700 /* Remove vfork catchpoint target routine. Nothing to do, just
1704 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1709 /* Insert exec catchpoint target routine. If exec events are
1710 enabled, just return success. */
1713 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1715 struct remote_state
*rs
= get_remote_state ();
1717 return !remote_exec_event_p (rs
);
1720 /* Remove exec catchpoint target routine. Nothing to do, just
1724 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1730 /* Asynchronous signal handle registered as event loop source for
1731 when we have pending events ready to be passed to the core. */
1733 static struct async_event_handler
*remote_async_inferior_event_token
;
1737 static ptid_t magic_null_ptid
;
1738 static ptid_t not_sent_ptid
;
1739 static ptid_t any_thread_ptid
;
1741 /* Find out if the stub attached to PID (and hence GDB should offer to
1742 detach instead of killing it when bailing out). */
1745 remote_query_attached (int pid
)
1747 struct remote_state
*rs
= get_remote_state ();
1748 size_t size
= get_remote_packet_size ();
1750 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1753 if (remote_multi_process_p (rs
))
1754 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1756 xsnprintf (rs
->buf
, size
, "qAttached");
1759 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1761 switch (packet_ok (rs
->buf
,
1762 &remote_protocol_packets
[PACKET_qAttached
]))
1765 if (strcmp (rs
->buf
, "1") == 0)
1769 warning (_("Remote failure reply: %s"), rs
->buf
);
1771 case PACKET_UNKNOWN
:
1778 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1779 has been invented by GDB, instead of reported by the target. Since
1780 we can be connected to a remote system before before knowing about
1781 any inferior, mark the target with execution when we find the first
1782 inferior. If ATTACHED is 1, then we had just attached to this
1783 inferior. If it is 0, then we just created this inferior. If it
1784 is -1, then try querying the remote stub to find out if it had
1785 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1786 attempt to open this inferior's executable as the main executable
1787 if no main executable is open already. */
1789 static struct inferior
*
1790 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1793 struct inferior
*inf
;
1795 /* Check whether this process we're learning about is to be
1796 considered attached, or if is to be considered to have been
1797 spawned by the stub. */
1799 attached
= remote_query_attached (pid
);
1801 if (gdbarch_has_global_solist (target_gdbarch ()))
1803 /* If the target shares code across all inferiors, then every
1804 attach adds a new inferior. */
1805 inf
= add_inferior (pid
);
1807 /* ... and every inferior is bound to the same program space.
1808 However, each inferior may still have its own address
1810 inf
->aspace
= maybe_new_address_space ();
1811 inf
->pspace
= current_program_space
;
1815 /* In the traditional debugging scenario, there's a 1-1 match
1816 between program/address spaces. We simply bind the inferior
1817 to the program space's address space. */
1818 inf
= current_inferior ();
1819 inferior_appeared (inf
, pid
);
1822 inf
->attach_flag
= attached
;
1823 inf
->fake_pid_p
= fake_pid_p
;
1825 /* If no main executable is currently open then attempt to
1826 open the file that was executed to create this inferior. */
1827 if (try_open_exec
&& get_exec_file (0) == NULL
)
1828 exec_file_locate_attach (pid
, 0, 1);
1833 static struct private_thread_info
*
1834 get_private_info_thread (struct thread_info
*info
);
1836 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1837 according to RUNNING. */
1840 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1842 struct remote_state
*rs
= get_remote_state ();
1843 struct thread_info
*thread
;
1845 /* GDB historically didn't pull threads in the initial connection
1846 setup. If the remote target doesn't even have a concept of
1847 threads (e.g., a bare-metal target), even if internally we
1848 consider that a single-threaded target, mentioning a new thread
1849 might be confusing to the user. Be silent then, preserving the
1850 age old behavior. */
1851 if (rs
->starting_up
)
1852 thread
= add_thread_silent (ptid
);
1854 thread
= add_thread (ptid
);
1856 get_private_info_thread (thread
)->vcont_resumed
= executing
;
1857 set_executing (ptid
, executing
);
1858 set_running (ptid
, running
);
1861 /* Come here when we learn about a thread id from the remote target.
1862 It may be the first time we hear about such thread, so take the
1863 opportunity to add it to GDB's thread list. In case this is the
1864 first time we're noticing its corresponding inferior, add it to
1865 GDB's inferior list as well. EXECUTING indicates whether the
1866 thread is (internally) executing or stopped. */
1869 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1871 /* In non-stop mode, we assume new found threads are (externally)
1872 running until proven otherwise with a stop reply. In all-stop,
1873 we can only get here if all threads are stopped. */
1874 int running
= target_is_non_stop_p () ? 1 : 0;
1876 /* If this is a new thread, add it to GDB's thread list.
1877 If we leave it up to WFI to do this, bad things will happen. */
1879 if (in_thread_list (currthread
) && is_exited (currthread
))
1881 /* We're seeing an event on a thread id we knew had exited.
1882 This has to be a new thread reusing the old id. Add it. */
1883 remote_add_thread (currthread
, running
, executing
);
1887 if (!in_thread_list (currthread
))
1889 struct inferior
*inf
= NULL
;
1890 int pid
= ptid_get_pid (currthread
);
1892 if (ptid_is_pid (inferior_ptid
)
1893 && pid
== ptid_get_pid (inferior_ptid
))
1895 /* inferior_ptid has no thread member yet. This can happen
1896 with the vAttach -> remote_wait,"TAAthread:" path if the
1897 stub doesn't support qC. This is the first stop reported
1898 after an attach, so this is the main thread. Update the
1899 ptid in the thread list. */
1900 if (in_thread_list (pid_to_ptid (pid
)))
1901 thread_change_ptid (inferior_ptid
, currthread
);
1904 remote_add_thread (currthread
, running
, executing
);
1905 inferior_ptid
= currthread
;
1910 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1912 /* inferior_ptid is not set yet. This can happen with the
1913 vRun -> remote_wait,"TAAthread:" path if the stub
1914 doesn't support qC. This is the first stop reported
1915 after an attach, so this is the main thread. Update the
1916 ptid in the thread list. */
1917 thread_change_ptid (inferior_ptid
, currthread
);
1921 /* When connecting to a target remote, or to a target
1922 extended-remote which already was debugging an inferior, we
1923 may not know about it yet. Add it before adding its child
1924 thread, so notifications are emitted in a sensible order. */
1925 if (!in_inferior_list (ptid_get_pid (currthread
)))
1927 struct remote_state
*rs
= get_remote_state ();
1928 int fake_pid_p
= !remote_multi_process_p (rs
);
1930 inf
= remote_add_inferior (fake_pid_p
,
1931 ptid_get_pid (currthread
), -1, 1);
1934 /* This is really a new thread. Add it. */
1935 remote_add_thread (currthread
, running
, executing
);
1937 /* If we found a new inferior, let the common code do whatever
1938 it needs to with it (e.g., read shared libraries, insert
1939 breakpoints), unless we're just setting up an all-stop
1943 struct remote_state
*rs
= get_remote_state ();
1945 if (!rs
->starting_up
)
1946 notice_new_inferior (currthread
, executing
, 0);
1951 /* Return THREAD's private thread data, creating it if necessary. */
1953 static struct private_thread_info
*
1954 get_private_info_thread (struct thread_info
*thread
)
1956 gdb_assert (thread
!= NULL
);
1958 if (thread
->priv
== NULL
)
1960 struct private_thread_info
*priv
= XNEW (struct private_thread_info
);
1962 thread
->private_dtor
= free_private_thread_info
;
1963 thread
->priv
= priv
;
1969 priv
->last_resume_step
= 0;
1970 priv
->last_resume_sig
= GDB_SIGNAL_0
;
1971 priv
->vcont_resumed
= 0;
1974 return thread
->priv
;
1977 /* Return PTID's private thread data, creating it if necessary. */
1979 static struct private_thread_info
*
1980 get_private_info_ptid (ptid_t ptid
)
1982 struct thread_info
*info
= find_thread_ptid (ptid
);
1984 return get_private_info_thread (info
);
1987 /* Call this function as a result of
1988 1) A halt indication (T packet) containing a thread id
1989 2) A direct query of currthread
1990 3) Successful execution of set thread */
1993 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1995 rs
->general_thread
= currthread
;
1998 /* If 'QPassSignals' is supported, tell the remote stub what signals
1999 it can simply pass through to the inferior without reporting. */
2002 remote_pass_signals (struct target_ops
*self
,
2003 int numsigs
, unsigned char *pass_signals
)
2005 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
2007 char *pass_packet
, *p
;
2009 struct remote_state
*rs
= get_remote_state ();
2011 gdb_assert (numsigs
< 256);
2012 for (i
= 0; i
< numsigs
; i
++)
2014 if (pass_signals
[i
])
2017 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
2018 strcpy (pass_packet
, "QPassSignals:");
2019 p
= pass_packet
+ strlen (pass_packet
);
2020 for (i
= 0; i
< numsigs
; i
++)
2022 if (pass_signals
[i
])
2025 *p
++ = tohex (i
>> 4);
2026 *p
++ = tohex (i
& 15);
2035 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
2037 putpkt (pass_packet
);
2038 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2039 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
2040 if (rs
->last_pass_packet
)
2041 xfree (rs
->last_pass_packet
);
2042 rs
->last_pass_packet
= pass_packet
;
2045 xfree (pass_packet
);
2049 /* If 'QCatchSyscalls' is supported, tell the remote stub
2050 to report syscalls to GDB. */
2053 remote_set_syscall_catchpoint (struct target_ops
*self
,
2054 int pid
, int needed
, int any_count
,
2055 int table_size
, int *table
)
2058 enum packet_result result
;
2061 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2063 /* Not supported. */
2067 if (needed
&& !any_count
)
2071 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2072 for (i
= 0; i
< table_size
; i
++)
2081 fprintf_unfiltered (gdb_stdlog
,
2082 "remote_set_syscall_catchpoint "
2083 "pid %d needed %d any_count %d n_sysno %d\n",
2084 pid
, needed
, any_count
, n_sysno
);
2089 /* Prepare a packet with the sysno list, assuming max 8+1
2090 characters for a sysno. If the resulting packet size is too
2091 big, fallback on the non-selective packet. */
2092 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2094 catch_packet
= (char *) xmalloc (maxpktsz
);
2095 strcpy (catch_packet
, "QCatchSyscalls:1");
2104 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2105 for (i
= 0; i
< table_size
; i
++)
2108 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2111 if (strlen (catch_packet
) > get_remote_packet_size ())
2113 /* catch_packet too big. Fallback to less efficient
2114 non selective mode, with GDB doing the filtering. */
2115 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2119 catch_packet
= xstrdup ("QCatchSyscalls:0");
2122 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2123 struct remote_state
*rs
= get_remote_state ();
2125 putpkt (catch_packet
);
2126 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2127 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2128 do_cleanups (old_chain
);
2129 if (result
== PACKET_OK
)
2136 /* If 'QProgramSignals' is supported, tell the remote stub what
2137 signals it should pass through to the inferior when detaching. */
2140 remote_program_signals (struct target_ops
*self
,
2141 int numsigs
, unsigned char *signals
)
2143 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2147 struct remote_state
*rs
= get_remote_state ();
2149 gdb_assert (numsigs
< 256);
2150 for (i
= 0; i
< numsigs
; i
++)
2155 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2156 strcpy (packet
, "QProgramSignals:");
2157 p
= packet
+ strlen (packet
);
2158 for (i
= 0; i
< numsigs
; i
++)
2160 if (signal_pass_state (i
))
2163 *p
++ = tohex (i
>> 4);
2164 *p
++ = tohex (i
& 15);
2173 if (!rs
->last_program_signals_packet
2174 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2177 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2178 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2179 xfree (rs
->last_program_signals_packet
);
2180 rs
->last_program_signals_packet
= packet
;
2187 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2188 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2189 thread. If GEN is set, set the general thread, if not, then set
2190 the step/continue thread. */
2192 set_thread (ptid_t ptid
, int gen
)
2194 struct remote_state
*rs
= get_remote_state ();
2195 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2196 char *buf
= rs
->buf
;
2197 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2199 if (ptid_equal (state
, ptid
))
2203 *buf
++ = gen
? 'g' : 'c';
2204 if (ptid_equal (ptid
, magic_null_ptid
))
2205 xsnprintf (buf
, endbuf
- buf
, "0");
2206 else if (ptid_equal (ptid
, any_thread_ptid
))
2207 xsnprintf (buf
, endbuf
- buf
, "0");
2208 else if (ptid_equal (ptid
, minus_one_ptid
))
2209 xsnprintf (buf
, endbuf
- buf
, "-1");
2211 write_ptid (buf
, endbuf
, ptid
);
2213 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2215 rs
->general_thread
= ptid
;
2217 rs
->continue_thread
= ptid
;
2221 set_general_thread (ptid_t ptid
)
2223 set_thread (ptid
, 1);
2227 set_continue_thread (ptid_t ptid
)
2229 set_thread (ptid
, 0);
2232 /* Change the remote current process. Which thread within the process
2233 ends up selected isn't important, as long as it is the same process
2234 as what INFERIOR_PTID points to.
2236 This comes from that fact that there is no explicit notion of
2237 "selected process" in the protocol. The selected process for
2238 general operations is the process the selected general thread
2242 set_general_process (void)
2244 struct remote_state
*rs
= get_remote_state ();
2246 /* If the remote can't handle multiple processes, don't bother. */
2247 if (!remote_multi_process_p (rs
))
2250 /* We only need to change the remote current thread if it's pointing
2251 at some other process. */
2252 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2253 set_general_thread (inferior_ptid
);
2257 /* Return nonzero if this is the main thread that we made up ourselves
2258 to model non-threaded targets as single-threaded. */
2261 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2263 if (ptid_equal (ptid
, magic_null_ptid
))
2264 /* The main thread is always alive. */
2267 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2268 /* The main thread is always alive. This can happen after a
2269 vAttach, if the remote side doesn't support
2276 /* Return nonzero if the thread PTID is still alive on the remote
2280 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2282 struct remote_state
*rs
= get_remote_state ();
2285 /* Check if this is a thread that we made up ourselves to model
2286 non-threaded targets as single-threaded. */
2287 if (remote_thread_always_alive (ops
, ptid
))
2291 endp
= rs
->buf
+ get_remote_packet_size ();
2294 write_ptid (p
, endp
, ptid
);
2297 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2298 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2301 /* Return a pointer to a thread name if we know it and NULL otherwise.
2302 The thread_info object owns the memory for the name. */
2305 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2307 if (info
->priv
!= NULL
)
2308 return info
->priv
->name
;
2313 /* About these extended threadlist and threadinfo packets. They are
2314 variable length packets but, the fields within them are often fixed
2315 length. They are redundent enough to send over UDP as is the
2316 remote protocol in general. There is a matching unit test module
2319 /* WARNING: This threadref data structure comes from the remote O.S.,
2320 libstub protocol encoding, and remote.c. It is not particularly
2323 /* Right now, the internal structure is int. We want it to be bigger.
2324 Plan to fix this. */
2326 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2328 /* gdb_ext_thread_info is an internal GDB data structure which is
2329 equivalent to the reply of the remote threadinfo packet. */
2331 struct gdb_ext_thread_info
2333 threadref threadid
; /* External form of thread reference. */
2334 int active
; /* Has state interesting to GDB?
2336 char display
[256]; /* Brief state display, name,
2337 blocked/suspended. */
2338 char shortname
[32]; /* To be used to name threads. */
2339 char more_display
[256]; /* Long info, statistics, queue depth,
2343 /* The volume of remote transfers can be limited by submitting
2344 a mask containing bits specifying the desired information.
2345 Use a union of these values as the 'selection' parameter to
2346 get_thread_info. FIXME: Make these TAG names more thread specific. */
2348 #define TAG_THREADID 1
2349 #define TAG_EXISTS 2
2350 #define TAG_DISPLAY 4
2351 #define TAG_THREADNAME 8
2352 #define TAG_MOREDISPLAY 16
2354 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2356 static char *unpack_nibble (char *buf
, int *val
);
2358 static char *unpack_byte (char *buf
, int *value
);
2360 static char *pack_int (char *buf
, int value
);
2362 static char *unpack_int (char *buf
, int *value
);
2364 static char *unpack_string (char *src
, char *dest
, int length
);
2366 static char *pack_threadid (char *pkt
, threadref
*id
);
2368 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2370 void int_to_threadref (threadref
*id
, int value
);
2372 static int threadref_to_int (threadref
*ref
);
2374 static void copy_threadref (threadref
*dest
, threadref
*src
);
2376 static int threadmatch (threadref
*dest
, threadref
*src
);
2378 static char *pack_threadinfo_request (char *pkt
, int mode
,
2381 static int remote_unpack_thread_info_response (char *pkt
,
2382 threadref
*expectedref
,
2383 struct gdb_ext_thread_info
2387 static int remote_get_threadinfo (threadref
*threadid
,
2388 int fieldset
, /*TAG mask */
2389 struct gdb_ext_thread_info
*info
);
2391 static char *pack_threadlist_request (char *pkt
, int startflag
,
2393 threadref
*nextthread
);
2395 static int parse_threadlist_response (char *pkt
,
2397 threadref
*original_echo
,
2398 threadref
*resultlist
,
2401 static int remote_get_threadlist (int startflag
,
2402 threadref
*nextthread
,
2406 threadref
*threadlist
);
2408 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2410 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2411 void *context
, int looplimit
);
2413 static int remote_newthread_step (threadref
*ref
, void *context
);
2416 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2417 buffer we're allowed to write to. Returns
2418 BUF+CHARACTERS_WRITTEN. */
2421 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2424 struct remote_state
*rs
= get_remote_state ();
2426 if (remote_multi_process_p (rs
))
2428 pid
= ptid_get_pid (ptid
);
2430 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2432 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2434 tid
= ptid_get_lwp (ptid
);
2436 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2438 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2443 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2444 passed the last parsed char. Returns null_ptid on error. */
2447 read_ptid (char *buf
, char **obuf
)
2451 ULONGEST pid
= 0, tid
= 0;
2455 /* Multi-process ptid. */
2456 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2458 error (_("invalid remote ptid: %s"), p
);
2461 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2464 return ptid_build (pid
, tid
, 0);
2467 /* No multi-process. Just a tid. */
2468 pp
= unpack_varlen_hex (p
, &tid
);
2470 /* Return null_ptid when no thread id is found. */
2478 /* Since the stub is not sending a process id, then default to
2479 what's in inferior_ptid, unless it's null at this point. If so,
2480 then since there's no way to know the pid of the reported
2481 threads, use the magic number. */
2482 if (ptid_equal (inferior_ptid
, null_ptid
))
2483 pid
= ptid_get_pid (magic_null_ptid
);
2485 pid
= ptid_get_pid (inferior_ptid
);
2489 return ptid_build (pid
, tid
, 0);
2495 if (ch
>= 'a' && ch
<= 'f')
2496 return ch
- 'a' + 10;
2497 if (ch
>= '0' && ch
<= '9')
2499 if (ch
>= 'A' && ch
<= 'F')
2500 return ch
- 'A' + 10;
2505 stub_unpack_int (char *buff
, int fieldlength
)
2512 nibble
= stubhex (*buff
++);
2516 retval
= retval
<< 4;
2522 unpack_nibble (char *buf
, int *val
)
2524 *val
= fromhex (*buf
++);
2529 unpack_byte (char *buf
, int *value
)
2531 *value
= stub_unpack_int (buf
, 2);
2536 pack_int (char *buf
, int value
)
2538 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2539 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2540 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2541 buf
= pack_hex_byte (buf
, (value
& 0xff));
2546 unpack_int (char *buf
, int *value
)
2548 *value
= stub_unpack_int (buf
, 8);
2552 #if 0 /* Currently unused, uncomment when needed. */
2553 static char *pack_string (char *pkt
, char *string
);
2556 pack_string (char *pkt
, char *string
)
2561 len
= strlen (string
);
2563 len
= 200; /* Bigger than most GDB packets, junk??? */
2564 pkt
= pack_hex_byte (pkt
, len
);
2568 if ((ch
== '\0') || (ch
== '#'))
2569 ch
= '*'; /* Protect encapsulation. */
2574 #endif /* 0 (unused) */
2577 unpack_string (char *src
, char *dest
, int length
)
2586 pack_threadid (char *pkt
, threadref
*id
)
2589 unsigned char *altid
;
2591 altid
= (unsigned char *) id
;
2592 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2594 pkt
= pack_hex_byte (pkt
, *altid
++);
2600 unpack_threadid (char *inbuf
, threadref
*id
)
2603 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2606 altref
= (char *) id
;
2608 while (inbuf
< limit
)
2610 x
= stubhex (*inbuf
++);
2611 y
= stubhex (*inbuf
++);
2612 *altref
++ = (x
<< 4) | y
;
2617 /* Externally, threadrefs are 64 bits but internally, they are still
2618 ints. This is due to a mismatch of specifications. We would like
2619 to use 64bit thread references internally. This is an adapter
2623 int_to_threadref (threadref
*id
, int value
)
2625 unsigned char *scan
;
2627 scan
= (unsigned char *) id
;
2633 *scan
++ = (value
>> 24) & 0xff;
2634 *scan
++ = (value
>> 16) & 0xff;
2635 *scan
++ = (value
>> 8) & 0xff;
2636 *scan
++ = (value
& 0xff);
2640 threadref_to_int (threadref
*ref
)
2643 unsigned char *scan
;
2649 value
= (value
<< 8) | ((*scan
++) & 0xff);
2654 copy_threadref (threadref
*dest
, threadref
*src
)
2657 unsigned char *csrc
, *cdest
;
2659 csrc
= (unsigned char *) src
;
2660 cdest
= (unsigned char *) dest
;
2667 threadmatch (threadref
*dest
, threadref
*src
)
2669 /* Things are broken right now, so just assume we got a match. */
2671 unsigned char *srcp
, *destp
;
2673 srcp
= (char *) src
;
2674 destp
= (char *) dest
;
2678 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2685 threadid:1, # always request threadid
2692 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2695 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2697 *pkt
++ = 'q'; /* Info Query */
2698 *pkt
++ = 'P'; /* process or thread info */
2699 pkt
= pack_int (pkt
, mode
); /* mode */
2700 pkt
= pack_threadid (pkt
, id
); /* threadid */
2701 *pkt
= '\0'; /* terminate */
2705 /* These values tag the fields in a thread info response packet. */
2706 /* Tagging the fields allows us to request specific fields and to
2707 add more fields as time goes by. */
2709 #define TAG_THREADID 1 /* Echo the thread identifier. */
2710 #define TAG_EXISTS 2 /* Is this process defined enough to
2711 fetch registers and its stack? */
2712 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2713 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2714 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2718 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2719 struct gdb_ext_thread_info
*info
)
2721 struct remote_state
*rs
= get_remote_state ();
2725 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2728 /* info->threadid = 0; FIXME: implement zero_threadref. */
2730 info
->display
[0] = '\0';
2731 info
->shortname
[0] = '\0';
2732 info
->more_display
[0] = '\0';
2734 /* Assume the characters indicating the packet type have been
2736 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2737 pkt
= unpack_threadid (pkt
, &ref
);
2740 warning (_("Incomplete response to threadinfo request."));
2741 if (!threadmatch (&ref
, expectedref
))
2742 { /* This is an answer to a different request. */
2743 warning (_("ERROR RMT Thread info mismatch."));
2746 copy_threadref (&info
->threadid
, &ref
);
2748 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2750 /* Packets are terminated with nulls. */
2751 while ((pkt
< limit
) && mask
&& *pkt
)
2753 pkt
= unpack_int (pkt
, &tag
); /* tag */
2754 pkt
= unpack_byte (pkt
, &length
); /* length */
2755 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2757 warning (_("ERROR RMT: threadinfo tag mismatch."));
2761 if (tag
== TAG_THREADID
)
2765 warning (_("ERROR RMT: length of threadid is not 16."));
2769 pkt
= unpack_threadid (pkt
, &ref
);
2770 mask
= mask
& ~TAG_THREADID
;
2773 if (tag
== TAG_EXISTS
)
2775 info
->active
= stub_unpack_int (pkt
, length
);
2777 mask
= mask
& ~(TAG_EXISTS
);
2780 warning (_("ERROR RMT: 'exists' length too long."));
2786 if (tag
== TAG_THREADNAME
)
2788 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2789 mask
= mask
& ~TAG_THREADNAME
;
2792 if (tag
== TAG_DISPLAY
)
2794 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2795 mask
= mask
& ~TAG_DISPLAY
;
2798 if (tag
== TAG_MOREDISPLAY
)
2800 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2801 mask
= mask
& ~TAG_MOREDISPLAY
;
2804 warning (_("ERROR RMT: unknown thread info tag."));
2805 break; /* Not a tag we know about. */
2811 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2812 struct gdb_ext_thread_info
*info
)
2814 struct remote_state
*rs
= get_remote_state ();
2817 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2819 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2821 if (rs
->buf
[0] == '\0')
2824 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2829 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2832 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2833 threadref
*nextthread
)
2835 *pkt
++ = 'q'; /* info query packet */
2836 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2837 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2838 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2839 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2844 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2847 parse_threadlist_response (char *pkt
, int result_limit
,
2848 threadref
*original_echo
, threadref
*resultlist
,
2851 struct remote_state
*rs
= get_remote_state ();
2853 int count
, resultcount
, done
;
2856 /* Assume the 'q' and 'M chars have been stripped. */
2857 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2858 /* done parse past here */
2859 pkt
= unpack_byte (pkt
, &count
); /* count field */
2860 pkt
= unpack_nibble (pkt
, &done
);
2861 /* The first threadid is the argument threadid. */
2862 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2863 while ((count
-- > 0) && (pkt
< limit
))
2865 pkt
= unpack_threadid (pkt
, resultlist
++);
2866 if (resultcount
++ >= result_limit
)
2874 /* Fetch the next batch of threads from the remote. Returns -1 if the
2875 qL packet is not supported, 0 on error and 1 on success. */
2878 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2879 int *done
, int *result_count
, threadref
*threadlist
)
2881 struct remote_state
*rs
= get_remote_state ();
2884 /* Trancate result limit to be smaller than the packet size. */
2885 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2886 >= get_remote_packet_size ())
2887 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2889 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2891 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2892 if (*rs
->buf
== '\0')
2894 /* Packet not supported. */
2899 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2900 &rs
->echo_nextthread
, threadlist
, done
);
2902 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2904 /* FIXME: This is a good reason to drop the packet. */
2905 /* Possably, there is a duplicate response. */
2907 retransmit immediatly - race conditions
2908 retransmit after timeout - yes
2910 wait for packet, then exit
2912 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2913 return 0; /* I choose simply exiting. */
2915 if (*result_count
<= 0)
2919 warning (_("RMT ERROR : failed to get remote thread list."));
2922 return result
; /* break; */
2924 if (*result_count
> result_limit
)
2927 warning (_("RMT ERROR: threadlist response longer than requested."));
2933 /* Fetch the list of remote threads, with the qL packet, and call
2934 STEPFUNCTION for each thread found. Stops iterating and returns 1
2935 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2936 STEPFUNCTION returns false. If the packet is not supported,
2940 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2943 struct remote_state
*rs
= get_remote_state ();
2944 int done
, i
, result_count
;
2952 if (loopcount
++ > looplimit
)
2955 warning (_("Remote fetch threadlist -infinite loop-."));
2958 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2959 MAXTHREADLISTRESULTS
,
2960 &done
, &result_count
,
2961 rs
->resultthreadlist
);
2964 /* Clear for later iterations. */
2966 /* Setup to resume next batch of thread references, set nextthread. */
2967 if (result_count
>= 1)
2968 copy_threadref (&rs
->nextthread
,
2969 &rs
->resultthreadlist
[result_count
- 1]);
2971 while (result_count
--)
2973 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2983 /* A thread found on the remote target. */
2985 typedef struct thread_item
2987 /* The thread's PTID. */
2990 /* The thread's extra info. May be NULL. */
2993 /* The thread's name. May be NULL. */
2996 /* The core the thread was running on. -1 if not known. */
2999 DEF_VEC_O(thread_item_t
);
3001 /* Context passed around to the various methods listing remote
3002 threads. As new threads are found, they're added to the ITEMS
3005 struct threads_listing_context
3007 /* The threads found on the remote target. */
3008 VEC (thread_item_t
) *items
;
3011 /* Discard the contents of the constructed thread listing context. */
3014 clear_threads_listing_context (void *p
)
3016 struct threads_listing_context
*context
3017 = (struct threads_listing_context
*) p
;
3019 struct thread_item
*item
;
3021 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3023 xfree (item
->extra
);
3027 VEC_free (thread_item_t
, context
->items
);
3030 /* Remove the thread specified as the related_pid field of WS
3031 from the CONTEXT list. */
3034 threads_listing_context_remove (struct target_waitstatus
*ws
,
3035 struct threads_listing_context
*context
)
3037 struct thread_item
*item
;
3039 ptid_t child_ptid
= ws
->value
.related_pid
;
3041 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3043 if (ptid_equal (item
->ptid
, child_ptid
))
3045 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
3052 remote_newthread_step (threadref
*ref
, void *data
)
3054 struct threads_listing_context
*context
3055 = (struct threads_listing_context
*) data
;
3056 struct thread_item item
;
3057 int pid
= ptid_get_pid (inferior_ptid
);
3059 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3064 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3066 return 1; /* continue iterator */
3069 #define CRAZY_MAX_THREADS 1000
3072 remote_current_thread (ptid_t oldpid
)
3074 struct remote_state
*rs
= get_remote_state ();
3077 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3078 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3083 result
= read_ptid (&rs
->buf
[2], &obuf
);
3084 if (*obuf
!= '\0' && remote_debug
)
3085 fprintf_unfiltered (gdb_stdlog
,
3086 "warning: garbage in qC reply\n");
3094 /* List remote threads using the deprecated qL packet. */
3097 remote_get_threads_with_ql (struct target_ops
*ops
,
3098 struct threads_listing_context
*context
)
3100 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3101 CRAZY_MAX_THREADS
) >= 0)
3107 #if defined(HAVE_LIBEXPAT)
3110 start_thread (struct gdb_xml_parser
*parser
,
3111 const struct gdb_xml_element
*element
,
3112 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3114 struct threads_listing_context
*data
3115 = (struct threads_listing_context
*) user_data
;
3117 struct thread_item item
;
3119 struct gdb_xml_value
*attr
;
3121 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3122 item
.ptid
= read_ptid (id
, NULL
);
3124 attr
= xml_find_attribute (attributes
, "core");
3126 item
.core
= *(ULONGEST
*) attr
->value
;
3130 attr
= xml_find_attribute (attributes
, "name");
3131 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3135 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3139 end_thread (struct gdb_xml_parser
*parser
,
3140 const struct gdb_xml_element
*element
,
3141 void *user_data
, const char *body_text
)
3143 struct threads_listing_context
*data
3144 = (struct threads_listing_context
*) user_data
;
3146 if (body_text
&& *body_text
)
3147 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3150 const struct gdb_xml_attribute thread_attributes
[] = {
3151 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3152 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3153 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3154 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3157 const struct gdb_xml_element thread_children
[] = {
3158 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3161 const struct gdb_xml_element threads_children
[] = {
3162 { "thread", thread_attributes
, thread_children
,
3163 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3164 start_thread
, end_thread
},
3165 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3168 const struct gdb_xml_element threads_elements
[] = {
3169 { "threads", NULL
, threads_children
,
3170 GDB_XML_EF_NONE
, NULL
, NULL
},
3171 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3176 /* List remote threads using qXfer:threads:read. */
3179 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3180 struct threads_listing_context
*context
)
3182 #if defined(HAVE_LIBEXPAT)
3183 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3185 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3186 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3188 if (xml
!= NULL
&& *xml
!= '\0')
3190 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3191 threads_elements
, xml
, context
);
3194 do_cleanups (back_to
);
3202 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3205 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3206 struct threads_listing_context
*context
)
3208 struct remote_state
*rs
= get_remote_state ();
3210 if (rs
->use_threadinfo_query
)
3214 putpkt ("qfThreadInfo");
3215 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3217 if (bufp
[0] != '\0') /* q packet recognized */
3219 while (*bufp
++ == 'm') /* reply contains one or more TID */
3223 struct thread_item item
;
3225 item
.ptid
= read_ptid (bufp
, &bufp
);
3230 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3232 while (*bufp
++ == ','); /* comma-separated list */
3233 putpkt ("qsThreadInfo");
3234 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3241 /* Packet not recognized. */
3242 rs
->use_threadinfo_query
= 0;
3249 /* Implement the to_update_thread_list function for the remote
3253 remote_update_thread_list (struct target_ops
*ops
)
3255 struct threads_listing_context context
;
3256 struct cleanup
*old_chain
;
3259 context
.items
= NULL
;
3260 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3262 /* We have a few different mechanisms to fetch the thread list. Try
3263 them all, starting with the most preferred one first, falling
3264 back to older methods. */
3265 if (remote_get_threads_with_qxfer (ops
, &context
)
3266 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3267 || remote_get_threads_with_ql (ops
, &context
))
3270 struct thread_item
*item
;
3271 struct thread_info
*tp
, *tmp
;
3275 if (VEC_empty (thread_item_t
, context
.items
)
3276 && remote_thread_always_alive (ops
, inferior_ptid
))
3278 /* Some targets don't really support threads, but still
3279 reply an (empty) thread list in response to the thread
3280 listing packets, instead of replying "packet not
3281 supported". Exit early so we don't delete the main
3283 do_cleanups (old_chain
);
3287 /* CONTEXT now holds the current thread list on the remote
3288 target end. Delete GDB-side threads no longer found on the
3290 ALL_THREADS_SAFE (tp
, tmp
)
3293 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3296 if (ptid_equal (item
->ptid
, tp
->ptid
))
3300 if (i
== VEC_length (thread_item_t
, context
.items
))
3303 delete_thread (tp
->ptid
);
3307 /* Remove any unreported fork child threads from CONTEXT so
3308 that we don't interfere with follow fork, which is where
3309 creation of such threads is handled. */
3310 remove_new_fork_children (&context
);
3312 /* And now add threads we don't know about yet to our list. */
3314 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3317 if (!ptid_equal (item
->ptid
, null_ptid
))
3319 struct private_thread_info
*info
;
3320 /* In non-stop mode, we assume new found threads are
3321 executing until proven otherwise with a stop reply.
3322 In all-stop, we can only get here if all threads are
3324 int executing
= target_is_non_stop_p () ? 1 : 0;
3326 remote_notice_new_inferior (item
->ptid
, executing
);
3328 info
= get_private_info_ptid (item
->ptid
);
3329 info
->core
= item
->core
;
3330 info
->extra
= item
->extra
;
3332 info
->name
= item
->name
;
3340 /* If no thread listing method is supported, then query whether
3341 each known thread is alive, one by one, with the T packet.
3342 If the target doesn't support threads at all, then this is a
3343 no-op. See remote_thread_alive. */
3347 do_cleanups (old_chain
);
3351 * Collect a descriptive string about the given thread.
3352 * The target may say anything it wants to about the thread
3353 * (typically info about its blocked / runnable state, name, etc.).
3354 * This string will appear in the info threads display.
3356 * Optional: targets are not required to implement this function.
3360 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3362 struct remote_state
*rs
= get_remote_state ();
3366 struct gdb_ext_thread_info threadinfo
;
3367 static char display_buf
[100]; /* arbitrary... */
3368 int n
= 0; /* position in display_buf */
3370 if (rs
->remote_desc
== 0) /* paranoia */
3371 internal_error (__FILE__
, __LINE__
,
3372 _("remote_threads_extra_info"));
3374 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3375 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3376 /* This is the main thread which was added by GDB. The remote
3377 server doesn't know about it. */
3380 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3382 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3384 if (info
&& info
->priv
)
3385 return info
->priv
->extra
;
3390 if (rs
->use_threadextra_query
)
3393 char *endb
= rs
->buf
+ get_remote_packet_size ();
3395 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3397 write_ptid (b
, endb
, tp
->ptid
);
3400 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3401 if (rs
->buf
[0] != 0)
3403 n
= std::min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3404 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3405 display_buf
[result
] = '\0';
3410 /* If the above query fails, fall back to the old method. */
3411 rs
->use_threadextra_query
= 0;
3412 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3413 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3414 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3415 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3416 if (threadinfo
.active
)
3418 if (*threadinfo
.shortname
)
3419 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3420 " Name: %s,", threadinfo
.shortname
);
3421 if (*threadinfo
.display
)
3422 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3423 " State: %s,", threadinfo
.display
);
3424 if (*threadinfo
.more_display
)
3425 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3426 " Priority: %s", threadinfo
.more_display
);
3430 /* For purely cosmetic reasons, clear up trailing commas. */
3431 if (',' == display_buf
[n
-1])
3432 display_buf
[n
-1] = ' ';
3441 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3442 struct static_tracepoint_marker
*marker
)
3444 struct remote_state
*rs
= get_remote_state ();
3447 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3449 p
+= hexnumstr (p
, addr
);
3451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3455 error (_("Remote failure reply: %s"), p
);
3459 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3466 static VEC(static_tracepoint_marker_p
) *
3467 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3470 struct remote_state
*rs
= get_remote_state ();
3471 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3472 struct static_tracepoint_marker
*marker
= NULL
;
3473 struct cleanup
*old_chain
;
3476 /* Ask for a first packet of static tracepoint marker
3479 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3482 error (_("Remote failure reply: %s"), p
);
3484 old_chain
= make_cleanup (free_current_marker
, &marker
);
3489 marker
= XCNEW (struct static_tracepoint_marker
);
3493 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3495 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3497 VEC_safe_push (static_tracepoint_marker_p
,
3503 release_static_tracepoint_marker (marker
);
3504 memset (marker
, 0, sizeof (*marker
));
3507 while (*p
++ == ','); /* comma-separated list */
3508 /* Ask for another packet of static tracepoint definition. */
3510 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3514 do_cleanups (old_chain
);
3519 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3522 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3524 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3528 /* Restart the remote side; this is an extended protocol operation. */
3531 extended_remote_restart (void)
3533 struct remote_state
*rs
= get_remote_state ();
3535 /* Send the restart command; for reasons I don't understand the
3536 remote side really expects a number after the "R". */
3537 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3540 remote_fileio_reset ();
3543 /* Clean up connection to a remote debugger. */
3546 remote_close (struct target_ops
*self
)
3548 struct remote_state
*rs
= get_remote_state ();
3550 if (rs
->remote_desc
== NULL
)
3551 return; /* already closed */
3553 /* Make sure we leave stdin registered in the event loop. */
3554 remote_terminal_ours (self
);
3556 serial_close (rs
->remote_desc
);
3557 rs
->remote_desc
= NULL
;
3559 /* We don't have a connection to the remote stub anymore. Get rid
3560 of all the inferiors and their threads we were controlling.
3561 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3562 will be unable to find the thread corresponding to (pid, 0, 0). */
3563 inferior_ptid
= null_ptid
;
3564 discard_all_inferiors ();
3566 /* We are closing the remote target, so we should discard
3567 everything of this target. */
3568 discard_pending_stop_replies_in_queue (rs
);
3570 if (remote_async_inferior_event_token
)
3571 delete_async_event_handler (&remote_async_inferior_event_token
);
3573 remote_notif_state_xfree (rs
->notif_state
);
3575 trace_reset_local_state ();
3578 /* Query the remote side for the text, data and bss offsets. */
3583 struct remote_state
*rs
= get_remote_state ();
3586 int lose
, num_segments
= 0, do_sections
, do_segments
;
3587 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3588 struct section_offsets
*offs
;
3589 struct symfile_segment_data
*data
;
3591 if (symfile_objfile
== NULL
)
3594 putpkt ("qOffsets");
3595 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3598 if (buf
[0] == '\000')
3599 return; /* Return silently. Stub doesn't support
3603 warning (_("Remote failure reply: %s"), buf
);
3607 /* Pick up each field in turn. This used to be done with scanf, but
3608 scanf will make trouble if CORE_ADDR size doesn't match
3609 conversion directives correctly. The following code will work
3610 with any size of CORE_ADDR. */
3611 text_addr
= data_addr
= bss_addr
= 0;
3615 if (startswith (ptr
, "Text="))
3618 /* Don't use strtol, could lose on big values. */
3619 while (*ptr
&& *ptr
!= ';')
3620 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3622 if (startswith (ptr
, ";Data="))
3625 while (*ptr
&& *ptr
!= ';')
3626 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3631 if (!lose
&& startswith (ptr
, ";Bss="))
3634 while (*ptr
&& *ptr
!= ';')
3635 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3637 if (bss_addr
!= data_addr
)
3638 warning (_("Target reported unsupported offsets: %s"), buf
);
3643 else if (startswith (ptr
, "TextSeg="))
3646 /* Don't use strtol, could lose on big values. */
3647 while (*ptr
&& *ptr
!= ';')
3648 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3651 if (startswith (ptr
, ";DataSeg="))
3654 while (*ptr
&& *ptr
!= ';')
3655 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3663 error (_("Malformed response to offset query, %s"), buf
);
3664 else if (*ptr
!= '\0')
3665 warning (_("Target reported unsupported offsets: %s"), buf
);
3667 offs
= ((struct section_offsets
*)
3668 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3669 memcpy (offs
, symfile_objfile
->section_offsets
,
3670 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3672 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3673 do_segments
= (data
!= NULL
);
3674 do_sections
= num_segments
== 0;
3676 if (num_segments
> 0)
3678 segments
[0] = text_addr
;
3679 segments
[1] = data_addr
;
3681 /* If we have two segments, we can still try to relocate everything
3682 by assuming that the .text and .data offsets apply to the whole
3683 text and data segments. Convert the offsets given in the packet
3684 to base addresses for symfile_map_offsets_to_segments. */
3685 else if (data
&& data
->num_segments
== 2)
3687 segments
[0] = data
->segment_bases
[0] + text_addr
;
3688 segments
[1] = data
->segment_bases
[1] + data_addr
;
3691 /* If the object file has only one segment, assume that it is text
3692 rather than data; main programs with no writable data are rare,
3693 but programs with no code are useless. Of course the code might
3694 have ended up in the data segment... to detect that we would need
3695 the permissions here. */
3696 else if (data
&& data
->num_segments
== 1)
3698 segments
[0] = data
->segment_bases
[0] + text_addr
;
3701 /* There's no way to relocate by segment. */
3707 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3708 offs
, num_segments
, segments
);
3710 if (ret
== 0 && !do_sections
)
3711 error (_("Can not handle qOffsets TextSeg "
3712 "response with this symbol file"));
3719 free_symfile_segment_data (data
);
3723 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3725 /* This is a temporary kludge to force data and bss to use the
3726 same offsets because that's what nlmconv does now. The real
3727 solution requires changes to the stub and remote.c that I
3728 don't have time to do right now. */
3730 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3731 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3734 objfile_relocate (symfile_objfile
, offs
);
3737 /* Send interrupt_sequence to remote target. */
3739 send_interrupt_sequence (void)
3741 struct remote_state
*rs
= get_remote_state ();
3743 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3744 remote_serial_write ("\x03", 1);
3745 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3746 serial_send_break (rs
->remote_desc
);
3747 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3749 serial_send_break (rs
->remote_desc
);
3750 remote_serial_write ("g", 1);
3753 internal_error (__FILE__
, __LINE__
,
3754 _("Invalid value for interrupt_sequence_mode: %s."),
3755 interrupt_sequence_mode
);
3759 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3760 and extract the PTID. Returns NULL_PTID if not found. */
3763 stop_reply_extract_thread (char *stop_reply
)
3765 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3769 /* Txx r:val ; r:val (...) */
3772 /* Look for "register" named "thread". */
3777 p1
= strchr (p
, ':');
3781 if (strncmp (p
, "thread", p1
- p
) == 0)
3782 return read_ptid (++p1
, &p
);
3784 p1
= strchr (p
, ';');
3796 /* Determine the remote side's current thread. If we have a stop
3797 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3798 "thread" register we can extract the current thread from. If not,
3799 ask the remote which is the current thread with qC. The former
3800 method avoids a roundtrip. */
3803 get_current_thread (char *wait_status
)
3805 ptid_t ptid
= null_ptid
;
3807 /* Note we don't use remote_parse_stop_reply as that makes use of
3808 the target architecture, which we haven't yet fully determined at
3810 if (wait_status
!= NULL
)
3811 ptid
= stop_reply_extract_thread (wait_status
);
3812 if (ptid_equal (ptid
, null_ptid
))
3813 ptid
= remote_current_thread (inferior_ptid
);
3818 /* Query the remote target for which is the current thread/process,
3819 add it to our tables, and update INFERIOR_PTID. The caller is
3820 responsible for setting the state such that the remote end is ready
3821 to return the current thread.
3823 This function is called after handling the '?' or 'vRun' packets,
3824 whose response is a stop reply from which we can also try
3825 extracting the thread. If the target doesn't support the explicit
3826 qC query, we infer the current thread from that stop reply, passed
3827 in in WAIT_STATUS, which may be NULL. */
3830 add_current_inferior_and_thread (char *wait_status
)
3832 struct remote_state
*rs
= get_remote_state ();
3836 inferior_ptid
= null_ptid
;
3838 /* Now, if we have thread information, update inferior_ptid. */
3839 ptid
= get_current_thread (wait_status
);
3841 if (!ptid_equal (ptid
, null_ptid
))
3843 if (!remote_multi_process_p (rs
))
3846 inferior_ptid
= ptid
;
3850 /* Without this, some commands which require an active target
3851 (such as kill) won't work. This variable serves (at least)
3852 double duty as both the pid of the target process (if it has
3853 such), and as a flag indicating that a target is active. */
3854 inferior_ptid
= magic_null_ptid
;
3858 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3860 /* Add the main thread. */
3861 add_thread_silent (inferior_ptid
);
3864 /* Print info about a thread that was found already stopped on
3868 print_one_stopped_thread (struct thread_info
*thread
)
3870 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3872 switch_to_thread (thread
->ptid
);
3873 stop_pc
= get_frame_pc (get_current_frame ());
3874 set_current_sal_from_frame (get_current_frame ());
3876 thread
->suspend
.waitstatus_pending_p
= 0;
3878 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3880 enum gdb_signal sig
= ws
->value
.sig
;
3882 if (signal_print_state (sig
))
3883 observer_notify_signal_received (sig
);
3885 observer_notify_normal_stop (NULL
, 1);
3888 /* Process all initial stop replies the remote side sent in response
3889 to the ? packet. These indicate threads that were already stopped
3890 on initial connection. We mark these threads as stopped and print
3891 their current frame before giving the user the prompt. */
3894 process_initial_stop_replies (int from_tty
)
3896 int pending_stop_replies
= stop_reply_queue_length ();
3897 struct inferior
*inf
;
3898 struct thread_info
*thread
;
3899 struct thread_info
*selected
= NULL
;
3900 struct thread_info
*lowest_stopped
= NULL
;
3901 struct thread_info
*first
= NULL
;
3903 /* Consume the initial pending events. */
3904 while (pending_stop_replies
-- > 0)
3906 ptid_t waiton_ptid
= minus_one_ptid
;
3908 struct target_waitstatus ws
;
3909 int ignore_event
= 0;
3910 struct thread_info
*thread
;
3912 memset (&ws
, 0, sizeof (ws
));
3913 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3915 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3919 case TARGET_WAITKIND_IGNORE
:
3920 case TARGET_WAITKIND_NO_RESUMED
:
3921 case TARGET_WAITKIND_SIGNALLED
:
3922 case TARGET_WAITKIND_EXITED
:
3923 /* We shouldn't see these, but if we do, just ignore. */
3925 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3929 case TARGET_WAITKIND_EXECD
:
3930 xfree (ws
.value
.execd_pathname
);
3939 thread
= find_thread_ptid (event_ptid
);
3941 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3943 enum gdb_signal sig
= ws
.value
.sig
;
3945 /* Stubs traditionally report SIGTRAP as initial signal,
3946 instead of signal 0. Suppress it. */
3947 if (sig
== GDB_SIGNAL_TRAP
)
3949 thread
->suspend
.stop_signal
= sig
;
3953 thread
->suspend
.waitstatus
= ws
;
3955 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3956 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3957 thread
->suspend
.waitstatus_pending_p
= 1;
3959 set_executing (event_ptid
, 0);
3960 set_running (event_ptid
, 0);
3961 thread
->priv
->vcont_resumed
= 0;
3964 /* "Notice" the new inferiors before anything related to
3965 registers/memory. */
3971 inf
->needs_setup
= 1;
3975 thread
= any_live_thread_of_process (inf
->pid
);
3976 notice_new_inferior (thread
->ptid
,
3977 thread
->state
== THREAD_RUNNING
,
3982 /* If all-stop on top of non-stop, pause all threads. Note this
3983 records the threads' stop pc, so must be done after "noticing"
3987 stop_all_threads ();
3989 /* If all threads of an inferior were already stopped, we
3990 haven't setup the inferior yet. */
3996 if (inf
->needs_setup
)
3998 thread
= any_live_thread_of_process (inf
->pid
);
3999 switch_to_thread_no_regs (thread
);
4005 /* Now go over all threads that are stopped, and print their current
4006 frame. If all-stop, then if there's a signalled thread, pick
4008 ALL_NON_EXITED_THREADS (thread
)
4014 set_running (thread
->ptid
, 0);
4015 else if (thread
->state
!= THREAD_STOPPED
)
4018 if (selected
== NULL
4019 && thread
->suspend
.waitstatus_pending_p
)
4022 if (lowest_stopped
== NULL
4023 || thread
->inf
->num
< lowest_stopped
->inf
->num
4024 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
4025 lowest_stopped
= thread
;
4028 print_one_stopped_thread (thread
);
4031 /* In all-stop, we only print the status of one thread, and leave
4032 others with their status pending. */
4037 thread
= lowest_stopped
;
4041 print_one_stopped_thread (thread
);
4044 /* For "info program". */
4045 thread
= inferior_thread ();
4046 if (thread
->state
== THREAD_STOPPED
)
4047 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4050 /* Start the remote connection and sync state. */
4053 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4055 struct remote_state
*rs
= get_remote_state ();
4056 struct packet_config
*noack_config
;
4057 char *wait_status
= NULL
;
4059 /* Signal other parts that we're going through the initial setup,
4060 and so things may not be stable yet. E.g., we don't try to
4061 install tracepoints until we've relocated symbols. Also, a
4062 Ctrl-C before we're connected and synced up can't interrupt the
4063 target. Instead, it offers to drop the (potentially wedged)
4065 rs
->starting_up
= 1;
4069 if (interrupt_on_connect
)
4070 send_interrupt_sequence ();
4072 /* Ack any packet which the remote side has already sent. */
4073 remote_serial_write ("+", 1);
4075 /* The first packet we send to the target is the optional "supported
4076 packets" request. If the target can answer this, it will tell us
4077 which later probes to skip. */
4078 remote_query_supported ();
4080 /* If the stub wants to get a QAllow, compose one and send it. */
4081 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4082 remote_set_permissions (target
);
4084 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4085 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4086 as a reply to known packet. For packet "vFile:setfs:" it is an
4087 invalid reply and GDB would return error in
4088 remote_hostio_set_filesystem, making remote files access impossible.
4089 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4090 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4092 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4094 putpkt (v_mustreplyempty
);
4095 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4096 if (strcmp (rs
->buf
, "OK") == 0)
4097 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4098 else if (strcmp (rs
->buf
, "") != 0)
4099 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4103 /* Next, we possibly activate noack mode.
4105 If the QStartNoAckMode packet configuration is set to AUTO,
4106 enable noack mode if the stub reported a wish for it with
4109 If set to TRUE, then enable noack mode even if the stub didn't
4110 report it in qSupported. If the stub doesn't reply OK, the
4111 session ends with an error.
4113 If FALSE, then don't activate noack mode, regardless of what the
4114 stub claimed should be the default with qSupported. */
4116 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4117 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4119 putpkt ("QStartNoAckMode");
4120 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4121 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4127 /* Tell the remote that we are using the extended protocol. */
4129 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4132 /* Let the target know which signals it is allowed to pass down to
4134 update_signals_program_target ();
4136 /* Next, if the target can specify a description, read it. We do
4137 this before anything involving memory or registers. */
4138 target_find_description ();
4140 /* Next, now that we know something about the target, update the
4141 address spaces in the program spaces. */
4142 update_address_spaces ();
4144 /* On OSs where the list of libraries is global to all
4145 processes, we fetch them early. */
4146 if (gdbarch_has_global_solist (target_gdbarch ()))
4147 solib_add (NULL
, from_tty
, auto_solib_add
);
4149 if (target_is_non_stop_p ())
4151 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4152 error (_("Non-stop mode requested, but remote "
4153 "does not support non-stop"));
4155 putpkt ("QNonStop:1");
4156 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4158 if (strcmp (rs
->buf
, "OK") != 0)
4159 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4161 /* Find about threads and processes the stub is already
4162 controlling. We default to adding them in the running state.
4163 The '?' query below will then tell us about which threads are
4165 remote_update_thread_list (target
);
4167 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4169 /* Don't assume that the stub can operate in all-stop mode.
4170 Request it explicitly. */
4171 putpkt ("QNonStop:0");
4172 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4174 if (strcmp (rs
->buf
, "OK") != 0)
4175 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4178 /* Upload TSVs regardless of whether the target is running or not. The
4179 remote stub, such as GDBserver, may have some predefined or builtin
4180 TSVs, even if the target is not running. */
4181 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4183 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4185 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4186 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4189 /* Check whether the target is running now. */
4191 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4193 if (!target_is_non_stop_p ())
4195 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4198 error (_("The target is not running (try extended-remote?)"));
4200 /* We're connected, but not running. Drop out before we
4201 call start_remote. */
4202 rs
->starting_up
= 0;
4207 /* Save the reply for later. */
4208 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4209 strcpy (wait_status
, rs
->buf
);
4212 /* Fetch thread list. */
4213 target_update_thread_list ();
4215 /* Let the stub know that we want it to return the thread. */
4216 set_continue_thread (minus_one_ptid
);
4218 if (thread_count () == 0)
4220 /* Target has no concept of threads at all. GDB treats
4221 non-threaded target as single-threaded; add a main
4223 add_current_inferior_and_thread (wait_status
);
4227 /* We have thread information; select the thread the target
4228 says should be current. If we're reconnecting to a
4229 multi-threaded program, this will ideally be the thread
4230 that last reported an event before GDB disconnected. */
4231 inferior_ptid
= get_current_thread (wait_status
);
4232 if (ptid_equal (inferior_ptid
, null_ptid
))
4234 /* Odd... The target was able to list threads, but not
4235 tell us which thread was current (no "thread"
4236 register in T stop reply?). Just pick the first
4237 thread in the thread list then. */
4240 fprintf_unfiltered (gdb_stdlog
,
4241 "warning: couldn't determine remote "
4242 "current thread; picking first in list.\n");
4244 inferior_ptid
= thread_list
->ptid
;
4248 /* init_wait_for_inferior should be called before get_offsets in order
4249 to manage `inserted' flag in bp loc in a correct state.
4250 breakpoint_init_inferior, called from init_wait_for_inferior, set
4251 `inserted' flag to 0, while before breakpoint_re_set, called from
4252 start_remote, set `inserted' flag to 1. In the initialization of
4253 inferior, breakpoint_init_inferior should be called first, and then
4254 breakpoint_re_set can be called. If this order is broken, state of
4255 `inserted' flag is wrong, and cause some problems on breakpoint
4257 init_wait_for_inferior ();
4259 get_offsets (); /* Get text, data & bss offsets. */
4261 /* If we could not find a description using qXfer, and we know
4262 how to do it some other way, try again. This is not
4263 supported for non-stop; it could be, but it is tricky if
4264 there are no stopped threads when we connect. */
4265 if (remote_read_description_p (target
)
4266 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4268 target_clear_description ();
4269 target_find_description ();
4272 /* Use the previously fetched status. */
4273 gdb_assert (wait_status
!= NULL
);
4274 strcpy (rs
->buf
, wait_status
);
4275 rs
->cached_wait_status
= 1;
4277 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4281 /* Clear WFI global state. Do this before finding about new
4282 threads and inferiors, and setting the current inferior.
4283 Otherwise we would clear the proceed status of the current
4284 inferior when we want its stop_soon state to be preserved
4285 (see notice_new_inferior). */
4286 init_wait_for_inferior ();
4288 /* In non-stop, we will either get an "OK", meaning that there
4289 are no stopped threads at this time; or, a regular stop
4290 reply. In the latter case, there may be more than one thread
4291 stopped --- we pull them all out using the vStopped
4293 if (strcmp (rs
->buf
, "OK") != 0)
4295 struct notif_client
*notif
= ¬if_client_stop
;
4297 /* remote_notif_get_pending_replies acks this one, and gets
4299 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4300 = remote_notif_parse (notif
, rs
->buf
);
4301 remote_notif_get_pending_events (notif
);
4304 if (thread_count () == 0)
4307 error (_("The target is not running (try extended-remote?)"));
4309 /* We're connected, but not running. Drop out before we
4310 call start_remote. */
4311 rs
->starting_up
= 0;
4315 /* In non-stop mode, any cached wait status will be stored in
4316 the stop reply queue. */
4317 gdb_assert (wait_status
== NULL
);
4319 /* Report all signals during attach/startup. */
4320 remote_pass_signals (target
, 0, NULL
);
4322 /* If there are already stopped threads, mark them stopped and
4323 report their stops before giving the prompt to the user. */
4324 process_initial_stop_replies (from_tty
);
4326 if (target_can_async_p ())
4330 /* If we connected to a live target, do some additional setup. */
4331 if (target_has_execution
)
4333 if (symfile_objfile
) /* No use without a symbol-file. */
4334 remote_check_symbols ();
4337 /* Possibly the target has been engaged in a trace run started
4338 previously; find out where things are at. */
4339 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4341 struct uploaded_tp
*uploaded_tps
= NULL
;
4343 if (current_trace_status ()->running
)
4344 printf_filtered (_("Trace is already running on the target.\n"));
4346 remote_upload_tracepoints (target
, &uploaded_tps
);
4348 merge_uploaded_tracepoints (&uploaded_tps
);
4351 /* Possibly the target has been engaged in a btrace record started
4352 previously; find out where things are at. */
4353 remote_btrace_maybe_reopen ();
4355 /* The thread and inferior lists are now synchronized with the
4356 target, our symbols have been relocated, and we're merged the
4357 target's tracepoints with ours. We're done with basic start
4359 rs
->starting_up
= 0;
4361 /* Maybe breakpoints are global and need to be inserted now. */
4362 if (breakpoints_should_be_inserted_now ())
4363 insert_breakpoints ();
4366 /* Open a connection to a remote debugger.
4367 NAME is the filename used for communication. */
4370 remote_open (const char *name
, int from_tty
)
4372 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4375 /* Open a connection to a remote debugger using the extended
4376 remote gdb protocol. NAME is the filename used for communication. */
4379 extended_remote_open (const char *name
, int from_tty
)
4381 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4384 /* Reset all packets back to "unknown support". Called when opening a
4385 new connection to a remote target. */
4388 reset_all_packet_configs_support (void)
4392 for (i
= 0; i
< PACKET_MAX
; i
++)
4393 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4396 /* Initialize all packet configs. */
4399 init_all_packet_configs (void)
4403 for (i
= 0; i
< PACKET_MAX
; i
++)
4405 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4406 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4410 /* Symbol look-up. */
4413 remote_check_symbols (void)
4415 struct remote_state
*rs
= get_remote_state ();
4416 char *msg
, *reply
, *tmp
;
4419 struct cleanup
*old_chain
;
4421 /* The remote side has no concept of inferiors that aren't running
4422 yet, it only knows about running processes. If we're connected
4423 but our current inferior is not running, we should not invite the
4424 remote target to request symbol lookups related to its
4425 (unrelated) current process. */
4426 if (!target_has_execution
)
4429 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4432 /* Make sure the remote is pointing at the right process. Note
4433 there's no way to select "no process". */
4434 set_general_process ();
4436 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4437 because we need both at the same time. */
4438 msg
= (char *) xmalloc (get_remote_packet_size ());
4439 old_chain
= make_cleanup (xfree
, msg
);
4440 reply
= (char *) xmalloc (get_remote_packet_size ());
4441 make_cleanup (free_current_contents
, &reply
);
4442 reply_size
= get_remote_packet_size ();
4444 /* Invite target to request symbol lookups. */
4446 putpkt ("qSymbol::");
4447 getpkt (&reply
, &reply_size
, 0);
4448 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4450 while (startswith (reply
, "qSymbol:"))
4452 struct bound_minimal_symbol sym
;
4455 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4457 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4458 if (sym
.minsym
== NULL
)
4459 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4462 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4463 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4465 /* If this is a function address, return the start of code
4466 instead of any data function descriptor. */
4467 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4471 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4472 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4476 getpkt (&reply
, &reply_size
, 0);
4479 do_cleanups (old_chain
);
4482 static struct serial
*
4483 remote_serial_open (const char *name
)
4485 static int udp_warning
= 0;
4487 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4488 of in ser-tcp.c, because it is the remote protocol assuming that the
4489 serial connection is reliable and not the serial connection promising
4491 if (!udp_warning
&& startswith (name
, "udp:"))
4493 warning (_("The remote protocol may be unreliable over UDP.\n"
4494 "Some events may be lost, rendering further debugging "
4499 return serial_open (name
);
4502 /* Inform the target of our permission settings. The permission flags
4503 work without this, but if the target knows the settings, it can do
4504 a couple things. First, it can add its own check, to catch cases
4505 that somehow manage to get by the permissions checks in target
4506 methods. Second, if the target is wired to disallow particular
4507 settings (for instance, a system in the field that is not set up to
4508 be able to stop at a breakpoint), it can object to any unavailable
4512 remote_set_permissions (struct target_ops
*self
)
4514 struct remote_state
*rs
= get_remote_state ();
4516 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4517 "WriteReg:%x;WriteMem:%x;"
4518 "InsertBreak:%x;InsertTrace:%x;"
4519 "InsertFastTrace:%x;Stop:%x",
4520 may_write_registers
, may_write_memory
,
4521 may_insert_breakpoints
, may_insert_tracepoints
,
4522 may_insert_fast_tracepoints
, may_stop
);
4524 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4526 /* If the target didn't like the packet, warn the user. Do not try
4527 to undo the user's settings, that would just be maddening. */
4528 if (strcmp (rs
->buf
, "OK") != 0)
4529 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4532 /* This type describes each known response to the qSupported
4534 struct protocol_feature
4536 /* The name of this protocol feature. */
4539 /* The default for this protocol feature. */
4540 enum packet_support default_support
;
4542 /* The function to call when this feature is reported, or after
4543 qSupported processing if the feature is not supported.
4544 The first argument points to this structure. The second
4545 argument indicates whether the packet requested support be
4546 enabled, disabled, or probed (or the default, if this function
4547 is being called at the end of processing and this feature was
4548 not reported). The third argument may be NULL; if not NULL, it
4549 is a NUL-terminated string taken from the packet following
4550 this feature's name and an equals sign. */
4551 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4554 /* The corresponding packet for this feature. Only used if
4555 FUNC is remote_supported_packet. */
4560 remote_supported_packet (const struct protocol_feature
*feature
,
4561 enum packet_support support
,
4562 const char *argument
)
4566 warning (_("Remote qSupported response supplied an unexpected value for"
4567 " \"%s\"."), feature
->name
);
4571 remote_protocol_packets
[feature
->packet
].support
= support
;
4575 remote_packet_size (const struct protocol_feature
*feature
,
4576 enum packet_support support
, const char *value
)
4578 struct remote_state
*rs
= get_remote_state ();
4583 if (support
!= PACKET_ENABLE
)
4586 if (value
== NULL
|| *value
== '\0')
4588 warning (_("Remote target reported \"%s\" without a size."),
4594 packet_size
= strtol (value
, &value_end
, 16);
4595 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4597 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4598 feature
->name
, value
);
4602 /* Record the new maximum packet size. */
4603 rs
->explicit_packet_size
= packet_size
;
4606 static const struct protocol_feature remote_protocol_features
[] = {
4607 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4608 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4609 PACKET_qXfer_auxv
},
4610 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4611 PACKET_qXfer_exec_file
},
4612 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4613 PACKET_qXfer_features
},
4614 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4615 PACKET_qXfer_libraries
},
4616 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4617 PACKET_qXfer_libraries_svr4
},
4618 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4619 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4620 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4621 PACKET_qXfer_memory_map
},
4622 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4623 PACKET_qXfer_spu_read
},
4624 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4625 PACKET_qXfer_spu_write
},
4626 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4627 PACKET_qXfer_osdata
},
4628 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4629 PACKET_qXfer_threads
},
4630 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4631 PACKET_qXfer_traceframe_info
},
4632 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4633 PACKET_QPassSignals
},
4634 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4635 PACKET_QCatchSyscalls
},
4636 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4637 PACKET_QProgramSignals
},
4638 { "QStartupWithShell", PACKET_DISABLE
, remote_supported_packet
,
4639 PACKET_QStartupWithShell
},
4640 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4641 PACKET_QStartNoAckMode
},
4642 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4643 PACKET_multiprocess_feature
},
4644 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4645 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4646 PACKET_qXfer_siginfo_read
},
4647 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4648 PACKET_qXfer_siginfo_write
},
4649 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4650 PACKET_ConditionalTracepoints
},
4651 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4652 PACKET_ConditionalBreakpoints
},
4653 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4654 PACKET_BreakpointCommands
},
4655 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4656 PACKET_FastTracepoints
},
4657 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4658 PACKET_StaticTracepoints
},
4659 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4660 PACKET_InstallInTrace
},
4661 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4662 PACKET_DisconnectedTracing_feature
},
4663 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4665 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4667 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4668 PACKET_TracepointSource
},
4669 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4671 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4672 PACKET_EnableDisableTracepoints_feature
},
4673 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4674 PACKET_qXfer_fdpic
},
4675 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4677 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4678 PACKET_QDisableRandomization
},
4679 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4680 { "QTBuffer:size", PACKET_DISABLE
,
4681 remote_supported_packet
, PACKET_QTBuffer_size
},
4682 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4683 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4684 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4685 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4686 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4687 PACKET_qXfer_btrace
},
4688 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4689 PACKET_qXfer_btrace_conf
},
4690 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4691 PACKET_Qbtrace_conf_bts_size
},
4692 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4693 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4694 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4695 PACKET_fork_event_feature
},
4696 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4697 PACKET_vfork_event_feature
},
4698 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4699 PACKET_exec_event_feature
},
4700 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4701 PACKET_Qbtrace_conf_pt_size
},
4702 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4703 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4704 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4707 static char *remote_support_xml
;
4709 /* Register string appended to "xmlRegisters=" in qSupported query. */
4712 register_remote_support_xml (const char *xml
)
4714 #if defined(HAVE_LIBEXPAT)
4715 if (remote_support_xml
== NULL
)
4716 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4719 char *copy
= xstrdup (remote_support_xml
+ 13);
4720 char *p
= strtok (copy
, ",");
4724 if (strcmp (p
, xml
) == 0)
4731 while ((p
= strtok (NULL
, ",")) != NULL
);
4734 remote_support_xml
= reconcat (remote_support_xml
,
4735 remote_support_xml
, ",", xml
,
4742 remote_query_supported_append (char *msg
, const char *append
)
4745 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4747 return xstrdup (append
);
4751 remote_query_supported (void)
4753 struct remote_state
*rs
= get_remote_state ();
4756 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4758 /* The packet support flags are handled differently for this packet
4759 than for most others. We treat an error, a disabled packet, and
4760 an empty response identically: any features which must be reported
4761 to be used will be automatically disabled. An empty buffer
4762 accomplishes this, since that is also the representation for a list
4763 containing no features. */
4766 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4769 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4771 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4772 q
= remote_query_supported_append (q
, "multiprocess+");
4774 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4775 q
= remote_query_supported_append (q
, "swbreak+");
4776 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4777 q
= remote_query_supported_append (q
, "hwbreak+");
4779 q
= remote_query_supported_append (q
, "qRelocInsn+");
4781 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4782 != AUTO_BOOLEAN_FALSE
)
4783 q
= remote_query_supported_append (q
, "fork-events+");
4784 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4785 != AUTO_BOOLEAN_FALSE
)
4786 q
= remote_query_supported_append (q
, "vfork-events+");
4787 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4788 != AUTO_BOOLEAN_FALSE
)
4789 q
= remote_query_supported_append (q
, "exec-events+");
4791 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4792 q
= remote_query_supported_append (q
, "vContSupported+");
4794 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4795 q
= remote_query_supported_append (q
, "QThreadEvents+");
4797 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4798 q
= remote_query_supported_append (q
, "no-resumed+");
4800 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4801 the qSupported:xmlRegisters=i386 handling. */
4802 if (remote_support_xml
!= NULL
)
4803 q
= remote_query_supported_append (q
, remote_support_xml
);
4805 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4808 do_cleanups (old_chain
);
4810 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4812 /* If an error occured, warn, but do not return - just reset the
4813 buffer to empty and go on to disable features. */
4814 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4817 warning (_("Remote failure reply: %s"), rs
->buf
);
4822 memset (seen
, 0, sizeof (seen
));
4827 enum packet_support is_supported
;
4828 char *p
, *end
, *name_end
, *value
;
4830 /* First separate out this item from the rest of the packet. If
4831 there's another item after this, we overwrite the separator
4832 (terminated strings are much easier to work with). */
4834 end
= strchr (p
, ';');
4837 end
= p
+ strlen (p
);
4847 warning (_("empty item in \"qSupported\" response"));
4852 name_end
= strchr (p
, '=');
4855 /* This is a name=value entry. */
4856 is_supported
= PACKET_ENABLE
;
4857 value
= name_end
+ 1;
4866 is_supported
= PACKET_ENABLE
;
4870 is_supported
= PACKET_DISABLE
;
4874 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4878 warning (_("unrecognized item \"%s\" "
4879 "in \"qSupported\" response"), p
);
4885 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4886 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4888 const struct protocol_feature
*feature
;
4891 feature
= &remote_protocol_features
[i
];
4892 feature
->func (feature
, is_supported
, value
);
4897 /* If we increased the packet size, make sure to increase the global
4898 buffer size also. We delay this until after parsing the entire
4899 qSupported packet, because this is the same buffer we were
4901 if (rs
->buf_size
< rs
->explicit_packet_size
)
4903 rs
->buf_size
= rs
->explicit_packet_size
;
4904 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4907 /* Handle the defaults for unmentioned features. */
4908 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4911 const struct protocol_feature
*feature
;
4913 feature
= &remote_protocol_features
[i
];
4914 feature
->func (feature
, feature
->default_support
, NULL
);
4918 /* Serial QUIT handler for the remote serial descriptor.
4920 Defers handling a Ctrl-C until we're done with the current
4921 command/response packet sequence, unless:
4923 - We're setting up the connection. Don't send a remote interrupt
4924 request, as we're not fully synced yet. Quit immediately
4927 - The target has been resumed in the foreground
4928 (target_terminal_is_ours is false) with a synchronous resume
4929 packet, and we're blocked waiting for the stop reply, thus a
4930 Ctrl-C should be immediately sent to the target.
4932 - We get a second Ctrl-C while still within the same serial read or
4933 write. In that case the serial is seemingly wedged --- offer to
4936 - We see a second Ctrl-C without target response, after having
4937 previously interrupted the target. In that case the target/stub
4938 is probably wedged --- offer to quit/disconnect.
4942 remote_serial_quit_handler (void)
4944 struct remote_state
*rs
= get_remote_state ();
4946 if (check_quit_flag ())
4948 /* If we're starting up, we're not fully synced yet. Quit
4950 if (rs
->starting_up
)
4952 else if (rs
->got_ctrlc_during_io
)
4954 if (query (_("The target is not responding to GDB commands.\n"
4955 "Stop debugging it? ")))
4956 remote_unpush_and_throw ();
4958 /* If ^C has already been sent once, offer to disconnect. */
4959 else if (!target_terminal_is_ours () && rs
->ctrlc_pending_p
)
4961 /* All-stop protocol, and blocked waiting for stop reply. Send
4962 an interrupt request. */
4963 else if (!target_terminal_is_ours () && rs
->waiting_for_stop_reply
)
4964 target_interrupt (inferior_ptid
);
4966 rs
->got_ctrlc_during_io
= 1;
4970 /* Remove any of the remote.c targets from target stack. Upper targets depend
4971 on it so remove them first. */
4974 remote_unpush_target (void)
4976 pop_all_targets_at_and_above (process_stratum
);
4980 remote_unpush_and_throw (void)
4982 remote_unpush_target ();
4983 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
4987 remote_open_1 (const char *name
, int from_tty
,
4988 struct target_ops
*target
, int extended_p
)
4990 struct remote_state
*rs
= get_remote_state ();
4993 error (_("To open a remote debug connection, you need to specify what\n"
4994 "serial device is attached to the remote system\n"
4995 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4997 /* See FIXME above. */
4998 if (!target_async_permitted
)
4999 wait_forever_enabled_p
= 1;
5001 /* If we're connected to a running target, target_preopen will kill it.
5002 Ask this question first, before target_preopen has a chance to kill
5004 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
5007 && !query (_("Already connected to a remote target. Disconnect? ")))
5008 error (_("Still connected."));
5011 /* Here the possibly existing remote target gets unpushed. */
5012 target_preopen (from_tty
);
5014 /* Make sure we send the passed signals list the next time we resume. */
5015 xfree (rs
->last_pass_packet
);
5016 rs
->last_pass_packet
= NULL
;
5018 /* Make sure we send the program signals list the next time we
5020 xfree (rs
->last_program_signals_packet
);
5021 rs
->last_program_signals_packet
= NULL
;
5023 remote_fileio_reset ();
5024 reopen_exec_file ();
5027 rs
->remote_desc
= remote_serial_open (name
);
5028 if (!rs
->remote_desc
)
5029 perror_with_name (name
);
5031 if (baud_rate
!= -1)
5033 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
5035 /* The requested speed could not be set. Error out to
5036 top level after closing remote_desc. Take care to
5037 set remote_desc to NULL to avoid closing remote_desc
5039 serial_close (rs
->remote_desc
);
5040 rs
->remote_desc
= NULL
;
5041 perror_with_name (name
);
5045 serial_setparity (rs
->remote_desc
, serial_parity
);
5046 serial_raw (rs
->remote_desc
);
5048 /* If there is something sitting in the buffer we might take it as a
5049 response to a command, which would be bad. */
5050 serial_flush_input (rs
->remote_desc
);
5054 puts_filtered ("Remote debugging using ");
5055 puts_filtered (name
);
5056 puts_filtered ("\n");
5058 push_target (target
); /* Switch to using remote target now. */
5060 /* Register extra event sources in the event loop. */
5061 remote_async_inferior_event_token
5062 = create_async_event_handler (remote_async_inferior_event_handler
,
5064 rs
->notif_state
= remote_notif_state_allocate ();
5066 /* Reset the target state; these things will be queried either by
5067 remote_query_supported or as they are needed. */
5068 reset_all_packet_configs_support ();
5069 rs
->cached_wait_status
= 0;
5070 rs
->explicit_packet_size
= 0;
5072 rs
->extended
= extended_p
;
5073 rs
->waiting_for_stop_reply
= 0;
5074 rs
->ctrlc_pending_p
= 0;
5075 rs
->got_ctrlc_during_io
= 0;
5077 rs
->general_thread
= not_sent_ptid
;
5078 rs
->continue_thread
= not_sent_ptid
;
5079 rs
->remote_traceframe_number
= -1;
5081 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5083 /* Probe for ability to use "ThreadInfo" query, as required. */
5084 rs
->use_threadinfo_query
= 1;
5085 rs
->use_threadextra_query
= 1;
5087 readahead_cache_invalidate ();
5089 /* Start out by owning the terminal. */
5090 remote_async_terminal_ours_p
= 1;
5092 if (target_async_permitted
)
5094 /* FIXME: cagney/1999-09-23: During the initial connection it is
5095 assumed that the target is already ready and able to respond to
5096 requests. Unfortunately remote_start_remote() eventually calls
5097 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5098 around this. Eventually a mechanism that allows
5099 wait_for_inferior() to expect/get timeouts will be
5101 wait_forever_enabled_p
= 0;
5104 /* First delete any symbols previously loaded from shared libraries. */
5105 no_shared_libraries (NULL
, 0);
5108 init_thread_list ();
5110 /* Start the remote connection. If error() or QUIT, discard this
5111 target (we'd otherwise be in an inconsistent state) and then
5112 propogate the error on up the exception chain. This ensures that
5113 the caller doesn't stumble along blindly assuming that the
5114 function succeeded. The CLI doesn't have this problem but other
5115 UI's, such as MI do.
5117 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5118 this function should return an error indication letting the
5119 caller restore the previous state. Unfortunately the command
5120 ``target remote'' is directly wired to this function making that
5121 impossible. On a positive note, the CLI side of this problem has
5122 been fixed - the function set_cmd_context() makes it possible for
5123 all the ``target ....'' commands to share a common callback
5124 function. See cli-dump.c. */
5129 remote_start_remote (from_tty
, target
, extended_p
);
5131 CATCH (ex
, RETURN_MASK_ALL
)
5133 /* Pop the partially set up target - unless something else did
5134 already before throwing the exception. */
5135 if (rs
->remote_desc
!= NULL
)
5136 remote_unpush_target ();
5137 if (target_async_permitted
)
5138 wait_forever_enabled_p
= 1;
5139 throw_exception (ex
);
5144 remote_btrace_reset ();
5146 if (target_async_permitted
)
5147 wait_forever_enabled_p
= 1;
5150 /* Detach the specified process. */
5153 remote_detach_pid (int pid
)
5155 struct remote_state
*rs
= get_remote_state ();
5157 if (remote_multi_process_p (rs
))
5158 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5160 strcpy (rs
->buf
, "D");
5163 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5165 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5167 else if (rs
->buf
[0] == '\0')
5168 error (_("Remote doesn't know how to detach"));
5170 error (_("Can't detach process."));
5173 /* This detaches a program to which we previously attached, using
5174 inferior_ptid to identify the process. After this is done, GDB
5175 can be used to debug some other program. We better not have left
5176 any breakpoints in the target program or it'll die when it hits
5180 remote_detach_1 (const char *args
, int from_tty
)
5182 int pid
= ptid_get_pid (inferior_ptid
);
5183 struct remote_state
*rs
= get_remote_state ();
5184 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5188 error (_("Argument given to \"detach\" when remotely debugging."));
5190 if (!target_has_execution
)
5191 error (_("No process to detach from."));
5193 target_announce_detach (from_tty
);
5195 /* Tell the remote target to detach. */
5196 remote_detach_pid (pid
);
5198 /* Exit only if this is the only active inferior. */
5199 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5200 puts_filtered (_("Ending remote debugging.\n"));
5202 /* Check to see if we are detaching a fork parent. Note that if we
5203 are detaching a fork child, tp == NULL. */
5204 is_fork_parent
= (tp
!= NULL
5205 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5207 /* If doing detach-on-fork, we don't mourn, because that will delete
5208 breakpoints that should be available for the followed inferior. */
5209 if (!is_fork_parent
)
5210 target_mourn_inferior (inferior_ptid
);
5213 inferior_ptid
= null_ptid
;
5214 detach_inferior (pid
);
5219 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5221 remote_detach_1 (args
, from_tty
);
5225 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5227 remote_detach_1 (args
, from_tty
);
5230 /* Target follow-fork function for remote targets. On entry, and
5231 at return, the current inferior is the fork parent.
5233 Note that although this is currently only used for extended-remote,
5234 it is named remote_follow_fork in anticipation of using it for the
5235 remote target as well. */
5238 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5241 struct remote_state
*rs
= get_remote_state ();
5242 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5244 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5245 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5247 /* When following the parent and detaching the child, we detach
5248 the child here. For the case of following the child and
5249 detaching the parent, the detach is done in the target-
5250 independent follow fork code in infrun.c. We can't use
5251 target_detach when detaching an unfollowed child because
5252 the client side doesn't know anything about the child. */
5253 if (detach_fork
&& !follow_child
)
5255 /* Detach the fork child. */
5259 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5260 child_pid
= ptid_get_pid (child_ptid
);
5262 remote_detach_pid (child_pid
);
5263 detach_inferior (child_pid
);
5269 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5270 in the program space of the new inferior. On entry and at return the
5271 current inferior is the exec'ing inferior. INF is the new exec'd
5272 inferior, which may be the same as the exec'ing inferior unless
5273 follow-exec-mode is "new". */
5276 remote_follow_exec (struct target_ops
*ops
,
5277 struct inferior
*inf
, char *execd_pathname
)
5279 /* We know that this is a target file name, so if it has the "target:"
5280 prefix we strip it off before saving it in the program space. */
5281 if (is_target_filename (execd_pathname
))
5282 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5284 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5287 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5290 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5293 error (_("Argument given to \"disconnect\" when remotely debugging."));
5295 /* Make sure we unpush even the extended remote targets. Calling
5296 target_mourn_inferior won't unpush, and remote_mourn won't
5297 unpush if there is more than one inferior left. */
5298 unpush_target (target
);
5299 generic_mourn_inferior ();
5302 puts_filtered ("Ending remote debugging.\n");
5305 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5306 be chatty about it. */
5309 extended_remote_attach (struct target_ops
*target
, const char *args
,
5312 struct remote_state
*rs
= get_remote_state ();
5314 char *wait_status
= NULL
;
5316 pid
= parse_pid_to_attach (args
);
5318 /* Remote PID can be freely equal to getpid, do not check it here the same
5319 way as in other targets. */
5321 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5322 error (_("This target does not support attaching to a process"));
5326 char *exec_file
= get_exec_file (0);
5329 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5330 target_pid_to_str (pid_to_ptid (pid
)));
5332 printf_unfiltered (_("Attaching to %s\n"),
5333 target_pid_to_str (pid_to_ptid (pid
)));
5335 gdb_flush (gdb_stdout
);
5338 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5340 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5342 switch (packet_ok (rs
->buf
,
5343 &remote_protocol_packets
[PACKET_vAttach
]))
5346 if (!target_is_non_stop_p ())
5348 /* Save the reply for later. */
5349 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5350 strcpy (wait_status
, rs
->buf
);
5352 else if (strcmp (rs
->buf
, "OK") != 0)
5353 error (_("Attaching to %s failed with: %s"),
5354 target_pid_to_str (pid_to_ptid (pid
)),
5357 case PACKET_UNKNOWN
:
5358 error (_("This target does not support attaching to a process"));
5360 error (_("Attaching to %s failed"),
5361 target_pid_to_str (pid_to_ptid (pid
)));
5364 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5366 inferior_ptid
= pid_to_ptid (pid
);
5368 if (target_is_non_stop_p ())
5370 struct thread_info
*thread
;
5372 /* Get list of threads. */
5373 remote_update_thread_list (target
);
5375 thread
= first_thread_of_process (pid
);
5377 inferior_ptid
= thread
->ptid
;
5379 inferior_ptid
= pid_to_ptid (pid
);
5381 /* Invalidate our notion of the remote current thread. */
5382 record_currthread (rs
, minus_one_ptid
);
5386 /* Now, if we have thread information, update inferior_ptid. */
5387 inferior_ptid
= remote_current_thread (inferior_ptid
);
5389 /* Add the main thread to the thread list. */
5390 add_thread_silent (inferior_ptid
);
5393 /* Next, if the target can specify a description, read it. We do
5394 this before anything involving memory or registers. */
5395 target_find_description ();
5397 if (!target_is_non_stop_p ())
5399 /* Use the previously fetched status. */
5400 gdb_assert (wait_status
!= NULL
);
5402 if (target_can_async_p ())
5404 struct notif_event
*reply
5405 = remote_notif_parse (¬if_client_stop
, wait_status
);
5407 push_stop_reply ((struct stop_reply
*) reply
);
5413 gdb_assert (wait_status
!= NULL
);
5414 strcpy (rs
->buf
, wait_status
);
5415 rs
->cached_wait_status
= 1;
5419 gdb_assert (wait_status
== NULL
);
5422 /* Implementation of the to_post_attach method. */
5425 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5427 /* Get text, data & bss offsets. */
5430 /* In certain cases GDB might not have had the chance to start
5431 symbol lookup up until now. This could happen if the debugged
5432 binary is not using shared libraries, the vsyscall page is not
5433 present (on Linux) and the binary itself hadn't changed since the
5434 debugging process was started. */
5435 if (symfile_objfile
!= NULL
)
5436 remote_check_symbols();
5440 /* Check for the availability of vCont. This function should also check
5444 remote_vcont_probe (struct remote_state
*rs
)
5448 strcpy (rs
->buf
, "vCont?");
5450 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5453 /* Make sure that the features we assume are supported. */
5454 if (startswith (buf
, "vCont"))
5457 int support_c
, support_C
;
5459 rs
->supports_vCont
.s
= 0;
5460 rs
->supports_vCont
.S
= 0;
5463 rs
->supports_vCont
.t
= 0;
5464 rs
->supports_vCont
.r
= 0;
5465 while (p
&& *p
== ';')
5468 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5469 rs
->supports_vCont
.s
= 1;
5470 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5471 rs
->supports_vCont
.S
= 1;
5472 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5474 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5476 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5477 rs
->supports_vCont
.t
= 1;
5478 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5479 rs
->supports_vCont
.r
= 1;
5481 p
= strchr (p
, ';');
5484 /* If c, and C are not all supported, we can't use vCont. Clearing
5485 BUF will make packet_ok disable the packet. */
5486 if (!support_c
|| !support_C
)
5490 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5493 /* Helper function for building "vCont" resumptions. Write a
5494 resumption to P. ENDP points to one-passed-the-end of the buffer
5495 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5496 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5497 resumed thread should be single-stepped and/or signalled. If PTID
5498 equals minus_one_ptid, then all threads are resumed; if PTID
5499 represents a process, then all threads of the process are resumed;
5500 the thread to be stepped and/or signalled is given in the global
5504 append_resumption (char *p
, char *endp
,
5505 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5507 struct remote_state
*rs
= get_remote_state ();
5509 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5510 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5512 /* GDB is willing to range step. */
5513 && use_range_stepping
5514 /* Target supports range stepping. */
5515 && rs
->supports_vCont
.r
5516 /* We don't currently support range stepping multiple
5517 threads with a wildcard (though the protocol allows it,
5518 so stubs shouldn't make an active effort to forbid
5520 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5522 struct thread_info
*tp
;
5524 if (ptid_equal (ptid
, minus_one_ptid
))
5526 /* If we don't know about the target thread's tid, then
5527 we're resuming magic_null_ptid (see caller). */
5528 tp
= find_thread_ptid (magic_null_ptid
);
5531 tp
= find_thread_ptid (ptid
);
5532 gdb_assert (tp
!= NULL
);
5534 if (tp
->control
.may_range_step
)
5536 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5538 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5539 phex_nz (tp
->control
.step_range_start
,
5541 phex_nz (tp
->control
.step_range_end
,
5545 p
+= xsnprintf (p
, endp
- p
, ";s");
5548 p
+= xsnprintf (p
, endp
- p
, ";s");
5549 else if (siggnal
!= GDB_SIGNAL_0
)
5550 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5552 p
+= xsnprintf (p
, endp
- p
, ";c");
5554 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5558 /* All (-1) threads of process. */
5559 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5561 p
+= xsnprintf (p
, endp
- p
, ":");
5562 p
= write_ptid (p
, endp
, nptid
);
5564 else if (!ptid_equal (ptid
, minus_one_ptid
))
5566 p
+= xsnprintf (p
, endp
- p
, ":");
5567 p
= write_ptid (p
, endp
, ptid
);
5573 /* Clear the thread's private info on resume. */
5576 resume_clear_thread_private_info (struct thread_info
*thread
)
5578 if (thread
->priv
!= NULL
)
5580 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5581 thread
->priv
->watch_data_address
= 0;
5585 /* Append a vCont continue-with-signal action for threads that have a
5586 non-zero stop signal. */
5589 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5591 struct thread_info
*thread
;
5593 ALL_NON_EXITED_THREADS (thread
)
5594 if (ptid_match (thread
->ptid
, ptid
)
5595 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5596 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5598 p
= append_resumption (p
, endp
, thread
->ptid
,
5599 0, thread
->suspend
.stop_signal
);
5600 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5601 resume_clear_thread_private_info (thread
);
5607 /* Set the target running, using the packets that use Hc
5611 remote_resume_with_hc (struct target_ops
*ops
,
5612 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5614 struct remote_state
*rs
= get_remote_state ();
5615 struct thread_info
*thread
;
5618 rs
->last_sent_signal
= siggnal
;
5619 rs
->last_sent_step
= step
;
5621 /* The c/s/C/S resume packets use Hc, so set the continue
5623 if (ptid_equal (ptid
, minus_one_ptid
))
5624 set_continue_thread (any_thread_ptid
);
5626 set_continue_thread (ptid
);
5628 ALL_NON_EXITED_THREADS (thread
)
5629 resume_clear_thread_private_info (thread
);
5632 if (execution_direction
== EXEC_REVERSE
)
5634 /* We don't pass signals to the target in reverse exec mode. */
5635 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5636 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5639 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5640 error (_("Remote reverse-step not supported."));
5641 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5642 error (_("Remote reverse-continue not supported."));
5644 strcpy (buf
, step
? "bs" : "bc");
5646 else if (siggnal
!= GDB_SIGNAL_0
)
5648 buf
[0] = step
? 'S' : 'C';
5649 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5650 buf
[2] = tohex (((int) siggnal
) & 0xf);
5654 strcpy (buf
, step
? "s" : "c");
5659 /* Resume the remote inferior by using a "vCont" packet. The thread
5660 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5661 resumed thread should be single-stepped and/or signalled. If PTID
5662 equals minus_one_ptid, then all threads are resumed; the thread to
5663 be stepped and/or signalled is given in the global INFERIOR_PTID.
5664 This function returns non-zero iff it resumes the inferior.
5666 This function issues a strict subset of all possible vCont commands
5670 remote_resume_with_vcont (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5672 struct remote_state
*rs
= get_remote_state ();
5676 /* No reverse execution actions defined for vCont. */
5677 if (execution_direction
== EXEC_REVERSE
)
5680 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5681 remote_vcont_probe (rs
);
5683 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5687 endp
= rs
->buf
+ get_remote_packet_size ();
5689 /* If we could generate a wider range of packets, we'd have to worry
5690 about overflowing BUF. Should there be a generic
5691 "multi-part-packet" packet? */
5693 p
+= xsnprintf (p
, endp
- p
, "vCont");
5695 if (ptid_equal (ptid
, magic_null_ptid
))
5697 /* MAGIC_NULL_PTID means that we don't have any active threads,
5698 so we don't have any TID numbers the inferior will
5699 understand. Make sure to only send forms that do not specify
5701 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5703 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5705 /* Resume all threads (of all processes, or of a single
5706 process), with preference for INFERIOR_PTID. This assumes
5707 inferior_ptid belongs to the set of all threads we are about
5709 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5711 /* Step inferior_ptid, with or without signal. */
5712 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5715 /* Also pass down any pending signaled resumption for other
5716 threads not the current. */
5717 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5719 /* And continue others without a signal. */
5720 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5724 /* Scheduler locking; resume only PTID. */
5725 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5728 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5731 if (target_is_non_stop_p ())
5733 /* In non-stop, the stub replies to vCont with "OK". The stop
5734 reply will be reported asynchronously by means of a `%Stop'
5736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5737 if (strcmp (rs
->buf
, "OK") != 0)
5738 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5744 /* Tell the remote machine to resume. */
5747 remote_resume (struct target_ops
*ops
,
5748 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5750 struct remote_state
*rs
= get_remote_state ();
5752 /* When connected in non-stop mode, the core resumes threads
5753 individually. Resuming remote threads directly in target_resume
5754 would thus result in sending one packet per thread. Instead, to
5755 minimize roundtrip latency, here we just store the resume
5756 request; the actual remote resumption will be done in
5757 target_commit_resume / remote_commit_resume, where we'll be able
5758 to do vCont action coalescing. */
5759 if (target_is_non_stop_p () && execution_direction
!= EXEC_REVERSE
)
5761 struct private_thread_info
*remote_thr
;
5763 if (ptid_equal (minus_one_ptid
, ptid
) || ptid_is_pid (ptid
))
5764 remote_thr
= get_private_info_ptid (inferior_ptid
);
5766 remote_thr
= get_private_info_ptid (ptid
);
5767 remote_thr
->last_resume_step
= step
;
5768 remote_thr
->last_resume_sig
= siggnal
;
5772 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5773 (explained in remote-notif.c:handle_notification) so
5774 remote_notif_process is not called. We need find a place where
5775 it is safe to start a 'vNotif' sequence. It is good to do it
5776 before resuming inferior, because inferior was stopped and no RSP
5777 traffic at that moment. */
5778 if (!target_is_non_stop_p ())
5779 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5781 rs
->last_resume_exec_dir
= execution_direction
;
5783 /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
5784 if (!remote_resume_with_vcont (ptid
, step
, siggnal
))
5785 remote_resume_with_hc (ops
, ptid
, step
, siggnal
);
5787 /* We are about to start executing the inferior, let's register it
5788 with the event loop. NOTE: this is the one place where all the
5789 execution commands end up. We could alternatively do this in each
5790 of the execution commands in infcmd.c. */
5791 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5792 into infcmd.c in order to allow inferior function calls to work
5793 NOT asynchronously. */
5794 if (target_can_async_p ())
5797 /* We've just told the target to resume. The remote server will
5798 wait for the inferior to stop, and then send a stop reply. In
5799 the mean time, we can't start another command/query ourselves
5800 because the stub wouldn't be ready to process it. This applies
5801 only to the base all-stop protocol, however. In non-stop (which
5802 only supports vCont), the stub replies with an "OK", and is
5803 immediate able to process further serial input. */
5804 if (!target_is_non_stop_p ())
5805 rs
->waiting_for_stop_reply
= 1;
5808 static void check_pending_events_prevent_wildcard_vcont
5809 (int *may_global_wildcard_vcont
);
5810 static int is_pending_fork_parent_thread (struct thread_info
*thread
);
5812 /* Private per-inferior info for target remote processes. */
5814 struct private_inferior
5816 /* Whether we can send a wildcard vCont for this process. */
5817 int may_wildcard_vcont
;
5820 /* Structure used to track the construction of a vCont packet in the
5821 outgoing packet buffer. This is used to send multiple vCont
5822 packets if we have more actions than would fit a single packet. */
5824 struct vcont_builder
5826 /* Pointer to the first action. P points here if no action has been
5830 /* Where the next action will be appended. */
5833 /* The end of the buffer. Must never write past this. */
5837 /* Prepare the outgoing buffer for a new vCont packet. */
5840 vcont_builder_restart (struct vcont_builder
*builder
)
5842 struct remote_state
*rs
= get_remote_state ();
5844 builder
->p
= rs
->buf
;
5845 builder
->endp
= rs
->buf
+ get_remote_packet_size ();
5846 builder
->p
+= xsnprintf (builder
->p
, builder
->endp
- builder
->p
, "vCont");
5847 builder
->first_action
= builder
->p
;
5850 /* If the vCont packet being built has any action, send it to the
5854 vcont_builder_flush (struct vcont_builder
*builder
)
5856 struct remote_state
*rs
;
5858 if (builder
->p
== builder
->first_action
)
5861 rs
= get_remote_state ();
5863 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5864 if (strcmp (rs
->buf
, "OK") != 0)
5865 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5868 /* The largest action is range-stepping, with its two addresses. This
5869 is more than sufficient. If a new, bigger action is created, it'll
5870 quickly trigger a failed assertion in append_resumption (and we'll
5872 #define MAX_ACTION_SIZE 200
5874 /* Append a new vCont action in the outgoing packet being built. If
5875 the action doesn't fit the packet along with previous actions, push
5876 what we've got so far to the remote end and start over a new vCont
5877 packet (with the new action). */
5880 vcont_builder_push_action (struct vcont_builder
*builder
,
5881 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5883 char buf
[MAX_ACTION_SIZE
+ 1];
5887 endp
= append_resumption (buf
, buf
+ sizeof (buf
),
5888 ptid
, step
, siggnal
);
5890 /* Check whether this new action would fit in the vCont packet along
5891 with previous actions. If not, send what we've got so far and
5892 start a new vCont packet. */
5894 if (rsize
> builder
->endp
- builder
->p
)
5896 vcont_builder_flush (builder
);
5897 vcont_builder_restart (builder
);
5899 /* Should now fit. */
5900 gdb_assert (rsize
<= builder
->endp
- builder
->p
);
5903 memcpy (builder
->p
, buf
, rsize
);
5904 builder
->p
+= rsize
;
5908 /* to_commit_resume implementation. */
5911 remote_commit_resume (struct target_ops
*ops
)
5913 struct remote_state
*rs
= get_remote_state ();
5914 struct inferior
*inf
;
5915 struct thread_info
*tp
;
5916 int any_process_wildcard
;
5917 int may_global_wildcard_vcont
;
5918 struct vcont_builder vcont_builder
;
5920 /* If connected in all-stop mode, we'd send the remote resume
5921 request directly from remote_resume. Likewise if
5922 reverse-debugging, as there are no defined vCont actions for
5923 reverse execution. */
5924 if (!target_is_non_stop_p () || execution_direction
== EXEC_REVERSE
)
5927 /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
5928 instead of resuming all threads of each process individually.
5929 However, if any thread of a process must remain halted, we can't
5930 send wildcard resumes and must send one action per thread.
5932 Care must be taken to not resume threads/processes the server
5933 side already told us are stopped, but the core doesn't know about
5934 yet, because the events are still in the vStopped notification
5937 #1 => vCont s:p1.1;c
5939 #3 <= %Stopped T05 p1.1
5944 #8 (infrun handles the stop for p1.1 and continues stepping)
5945 #9 => vCont s:p1.1;c
5947 The last vCont above would resume thread p1.2 by mistake, because
5948 the server has no idea that the event for p1.2 had not been
5951 The server side must similarly ignore resume actions for the
5952 thread that has a pending %Stopped notification (and any other
5953 threads with events pending), until GDB acks the notification
5954 with vStopped. Otherwise, e.g., the following case is
5957 #1 => g (or any other packet)
5959 #3 <= %Stopped T05 p1.2
5960 #4 => vCont s:p1.1;c
5963 Above, the server must not resume thread p1.2. GDB can't know
5964 that p1.2 stopped until it acks the %Stopped notification, and
5965 since from GDB's perspective all threads should be running, it
5968 Finally, special care must also be given to handling fork/vfork
5969 events. A (v)fork event actually tells us that two processes
5970 stopped -- the parent and the child. Until we follow the fork,
5971 we must not resume the child. Therefore, if we have a pending
5972 fork follow, we must not send a global wildcard resume action
5973 (vCont;c). We can still send process-wide wildcards though. */
5975 /* Start by assuming a global wildcard (vCont;c) is possible. */
5976 may_global_wildcard_vcont
= 1;
5978 /* And assume every process is individually wildcard-able too. */
5979 ALL_NON_EXITED_INFERIORS (inf
)
5981 if (inf
->priv
== NULL
)
5982 inf
->priv
= XNEW (struct private_inferior
);
5983 inf
->priv
->may_wildcard_vcont
= 1;
5986 /* Check for any pending events (not reported or processed yet) and
5987 disable process and global wildcard resumes appropriately. */
5988 check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont
);
5990 ALL_NON_EXITED_THREADS (tp
)
5992 /* If a thread of a process is not meant to be resumed, then we
5993 can't wildcard that process. */
5996 tp
->inf
->priv
->may_wildcard_vcont
= 0;
5998 /* And if we can't wildcard a process, we can't wildcard
5999 everything either. */
6000 may_global_wildcard_vcont
= 0;
6004 /* If a thread is the parent of an unfollowed fork, then we
6005 can't do a global wildcard, as that would resume the fork
6007 if (is_pending_fork_parent_thread (tp
))
6008 may_global_wildcard_vcont
= 0;
6011 /* Now let's build the vCont packet(s). Actions must be appended
6012 from narrower to wider scopes (thread -> process -> global). If
6013 we end up with too many actions for a single packet vcont_builder
6014 flushes the current vCont packet to the remote side and starts a
6016 vcont_builder_restart (&vcont_builder
);
6018 /* Threads first. */
6019 ALL_NON_EXITED_THREADS (tp
)
6021 struct private_thread_info
*remote_thr
= tp
->priv
;
6023 if (!tp
->executing
|| remote_thr
->vcont_resumed
)
6026 gdb_assert (!thread_is_in_step_over_chain (tp
));
6028 if (!remote_thr
->last_resume_step
6029 && remote_thr
->last_resume_sig
== GDB_SIGNAL_0
6030 && tp
->inf
->priv
->may_wildcard_vcont
)
6032 /* We'll send a wildcard resume instead. */
6033 remote_thr
->vcont_resumed
= 1;
6037 vcont_builder_push_action (&vcont_builder
, tp
->ptid
,
6038 remote_thr
->last_resume_step
,
6039 remote_thr
->last_resume_sig
);
6040 remote_thr
->vcont_resumed
= 1;
6043 /* Now check whether we can send any process-wide wildcard. This is
6044 to avoid sending a global wildcard in the case nothing is
6045 supposed to be resumed. */
6046 any_process_wildcard
= 0;
6048 ALL_NON_EXITED_INFERIORS (inf
)
6050 if (inf
->priv
->may_wildcard_vcont
)
6052 any_process_wildcard
= 1;
6057 if (any_process_wildcard
)
6059 /* If all processes are wildcard-able, then send a single "c"
6060 action, otherwise, send an "all (-1) threads of process"
6061 continue action for each running process, if any. */
6062 if (may_global_wildcard_vcont
)
6064 vcont_builder_push_action (&vcont_builder
, minus_one_ptid
,
6069 ALL_NON_EXITED_INFERIORS (inf
)
6071 if (inf
->priv
->may_wildcard_vcont
)
6073 vcont_builder_push_action (&vcont_builder
,
6074 pid_to_ptid (inf
->pid
),
6081 vcont_builder_flush (&vcont_builder
);
6086 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
6087 thread, all threads of a remote process, or all threads of all
6091 remote_stop_ns (ptid_t ptid
)
6093 struct remote_state
*rs
= get_remote_state ();
6095 char *endp
= rs
->buf
+ get_remote_packet_size ();
6097 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
6098 remote_vcont_probe (rs
);
6100 if (!rs
->supports_vCont
.t
)
6101 error (_("Remote server does not support stopping threads"));
6103 if (ptid_equal (ptid
, minus_one_ptid
)
6104 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
6105 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
6110 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
6112 if (ptid_is_pid (ptid
))
6113 /* All (-1) threads of process. */
6114 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
6117 /* Small optimization: if we already have a stop reply for
6118 this thread, no use in telling the stub we want this
6120 if (peek_stop_reply (ptid
))
6126 write_ptid (p
, endp
, nptid
);
6129 /* In non-stop, we get an immediate OK reply. The stop reply will
6130 come in asynchronously by notification. */
6132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6133 if (strcmp (rs
->buf
, "OK") != 0)
6134 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
6137 /* All-stop version of target_interrupt. Sends a break or a ^C to
6138 interrupt the remote target. It is undefined which thread of which
6139 process reports the interrupt. */
6142 remote_interrupt_as (void)
6144 struct remote_state
*rs
= get_remote_state ();
6146 rs
->ctrlc_pending_p
= 1;
6148 /* If the inferior is stopped already, but the core didn't know
6149 about it yet, just ignore the request. The cached wait status
6150 will be collected in remote_wait. */
6151 if (rs
->cached_wait_status
)
6154 /* Send interrupt_sequence to remote target. */
6155 send_interrupt_sequence ();
6158 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
6159 the remote target. It is undefined which thread of which process
6160 reports the interrupt. Throws an error if the packet is not
6161 supported by the server. */
6164 remote_interrupt_ns (void)
6166 struct remote_state
*rs
= get_remote_state ();
6168 char *endp
= rs
->buf
+ get_remote_packet_size ();
6170 xsnprintf (p
, endp
- p
, "vCtrlC");
6172 /* In non-stop, we get an immediate OK reply. The stop reply will
6173 come in asynchronously by notification. */
6175 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6177 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
6181 case PACKET_UNKNOWN
:
6182 error (_("No support for interrupting the remote target."));
6184 error (_("Interrupting target failed: %s"), rs
->buf
);
6188 /* Implement the to_stop function for the remote targets. */
6191 remote_stop (struct target_ops
*self
, ptid_t ptid
)
6194 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
6196 if (target_is_non_stop_p ())
6197 remote_stop_ns (ptid
);
6200 /* We don't currently have a way to transparently pause the
6201 remote target in all-stop mode. Interrupt it instead. */
6202 remote_interrupt_as ();
6206 /* Implement the to_interrupt function for the remote targets. */
6209 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
6211 struct remote_state
*rs
= get_remote_state ();
6214 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
6216 if (target_is_non_stop_p ())
6217 remote_interrupt_ns ();
6219 remote_interrupt_as ();
6222 /* Implement the to_pass_ctrlc function for the remote targets. */
6225 remote_pass_ctrlc (struct target_ops
*self
)
6227 struct remote_state
*rs
= get_remote_state ();
6230 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
6232 /* If we're starting up, we're not fully synced yet. Quit
6234 if (rs
->starting_up
)
6236 /* If ^C has already been sent once, offer to disconnect. */
6237 else if (rs
->ctrlc_pending_p
)
6240 target_interrupt (inferior_ptid
);
6243 /* Ask the user what to do when an interrupt is received. */
6246 interrupt_query (void)
6248 struct remote_state
*rs
= get_remote_state ();
6250 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
6252 if (query (_("The target is not responding to interrupt requests.\n"
6253 "Stop debugging it? ")))
6255 remote_unpush_target ();
6256 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
6261 if (query (_("Interrupted while waiting for the program.\n"
6262 "Give up waiting? ")))
6267 /* Enable/disable target terminal ownership. Most targets can use
6268 terminal groups to control terminal ownership. Remote targets are
6269 different in that explicit transfer of ownership to/from GDB/target
6273 remote_terminal_inferior (struct target_ops
*self
)
6275 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
6276 idempotent. The event-loop GDB talking to an asynchronous target
6277 with a synchronous command calls this function from both
6278 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
6279 transfer the terminal to the target when it shouldn't this guard
6281 if (!remote_async_terminal_ours_p
)
6283 remote_async_terminal_ours_p
= 0;
6284 /* NOTE: At this point we could also register our selves as the
6285 recipient of all input. Any characters typed could then be
6286 passed on down to the target. */
6290 remote_terminal_ours (struct target_ops
*self
)
6292 /* See FIXME in remote_terminal_inferior. */
6293 if (remote_async_terminal_ours_p
)
6295 remote_async_terminal_ours_p
= 1;
6299 remote_console_output (char *msg
)
6303 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
6306 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
6310 fputs_unfiltered (tb
, gdb_stdtarg
);
6312 gdb_flush (gdb_stdtarg
);
6315 DEF_VEC_O(cached_reg_t
);
6317 typedef struct stop_reply
6319 struct notif_event base
;
6321 /* The identifier of the thread about this event */
6324 /* The remote state this event is associated with. When the remote
6325 connection, represented by a remote_state object, is closed,
6326 all the associated stop_reply events should be released. */
6327 struct remote_state
*rs
;
6329 struct target_waitstatus ws
;
6331 /* Expedited registers. This makes remote debugging a bit more
6332 efficient for those targets that provide critical registers as
6333 part of their normal status mechanism (as another roundtrip to
6334 fetch them is avoided). */
6335 VEC(cached_reg_t
) *regcache
;
6337 enum target_stop_reason stop_reason
;
6339 CORE_ADDR watch_data_address
;
6344 DECLARE_QUEUE_P (stop_reply_p
);
6345 DEFINE_QUEUE_P (stop_reply_p
);
6346 /* The list of already fetched and acknowledged stop events. This
6347 queue is used for notification Stop, and other notifications
6348 don't need queue for their events, because the notification events
6349 of Stop can't be consumed immediately, so that events should be
6350 queued first, and be consumed by remote_wait_{ns,as} one per
6351 time. Other notifications can consume their events immediately,
6352 so queue is not needed for them. */
6353 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6356 stop_reply_xfree (struct stop_reply
*r
)
6358 notif_event_xfree ((struct notif_event
*) r
);
6361 /* Return the length of the stop reply queue. */
6364 stop_reply_queue_length (void)
6366 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6370 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6371 struct notif_event
*event
)
6373 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6377 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6378 struct notif_event
*event
)
6380 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6383 putpkt (self
->ack_command
);
6385 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6386 /* We got an unknown stop reply. */
6387 error (_("Unknown stop reply"));
6389 push_stop_reply (stop_reply
);
6393 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6395 /* We can't get pending events in remote_notif_process for
6396 notification stop, and we have to do this in remote_wait_ns
6397 instead. If we fetch all queued events from stub, remote stub
6398 may exit and we have no chance to process them back in
6400 mark_async_event_handler (remote_async_inferior_event_token
);
6405 stop_reply_dtr (struct notif_event
*event
)
6407 struct stop_reply
*r
= (struct stop_reply
*) event
;
6412 VEC_iterate (cached_reg_t
, r
->regcache
, ix
, reg
);
6416 VEC_free (cached_reg_t
, r
->regcache
);
6419 static struct notif_event
*
6420 remote_notif_stop_alloc_reply (void)
6422 /* We cast to a pointer to the "base class". */
6423 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6425 r
->dtr
= stop_reply_dtr
;
6430 /* A client of notification Stop. */
6432 struct notif_client notif_client_stop
=
6436 remote_notif_stop_parse
,
6437 remote_notif_stop_ack
,
6438 remote_notif_stop_can_get_pending_events
,
6439 remote_notif_stop_alloc_reply
,
6443 /* A parameter to pass data in and out. */
6445 struct queue_iter_param
6448 struct stop_reply
*output
;
6451 /* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
6452 the pid of the process that owns the threads we want to check, or
6453 -1 if we want to check all threads. */
6456 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6459 if (ws
->kind
== TARGET_WAITKIND_FORKED
6460 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6462 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6469 /* Return the thread's pending status used to determine whether the
6470 thread is a fork parent stopped at a fork event. */
6472 static struct target_waitstatus
*
6473 thread_pending_fork_status (struct thread_info
*thread
)
6475 if (thread
->suspend
.waitstatus_pending_p
)
6476 return &thread
->suspend
.waitstatus
;
6478 return &thread
->pending_follow
;
6481 /* Determine if THREAD is a pending fork parent thread. */
6484 is_pending_fork_parent_thread (struct thread_info
*thread
)
6486 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6489 return is_pending_fork_parent (ws
, pid
, thread
->ptid
);
6492 /* Check whether EVENT is a fork event, and if it is, remove the
6493 fork child from the context list passed in DATA. */
6496 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6497 QUEUE_ITER (stop_reply_p
) *iter
,
6501 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6502 struct threads_listing_context
*context
6503 = (struct threads_listing_context
*) param
->input
;
6505 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6506 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6507 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6508 threads_listing_context_remove (&event
->ws
, context
);
6513 /* If CONTEXT contains any fork child threads that have not been
6514 reported yet, remove them from the CONTEXT list. If such a
6515 thread exists it is because we are stopped at a fork catchpoint
6516 and have not yet called follow_fork, which will set up the
6517 host-side data structures for the new process. */
6520 remove_new_fork_children (struct threads_listing_context
*context
)
6522 struct thread_info
* thread
;
6524 struct notif_client
*notif
= ¬if_client_stop
;
6525 struct queue_iter_param param
;
6527 /* For any threads stopped at a fork event, remove the corresponding
6528 fork child threads from the CONTEXT list. */
6529 ALL_NON_EXITED_THREADS (thread
)
6531 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6533 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6535 threads_listing_context_remove (ws
, context
);
6539 /* Check for any pending fork events (not reported or processed yet)
6540 in process PID and remove those fork child threads from the
6541 CONTEXT list as well. */
6542 remote_notif_get_pending_events (notif
);
6543 param
.input
= context
;
6544 param
.output
= NULL
;
6545 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6546 remove_child_of_pending_fork
, ¶m
);
6549 /* Check whether EVENT would prevent a global or process wildcard
6553 check_pending_event_prevents_wildcard_vcont_callback
6554 (QUEUE (stop_reply_p
) *q
,
6555 QUEUE_ITER (stop_reply_p
) *iter
,
6559 struct inferior
*inf
;
6560 int *may_global_wildcard_vcont
= (int *) data
;
6562 if (event
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
6563 || event
->ws
.kind
== TARGET_WAITKIND_NO_HISTORY
)
6566 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6567 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
6568 *may_global_wildcard_vcont
= 0;
6570 inf
= find_inferior_ptid (event
->ptid
);
6572 /* This may be the first time we heard about this process.
6573 Regardless, we must not do a global wildcard resume, otherwise
6574 we'd resume this process too. */
6575 *may_global_wildcard_vcont
= 0;
6577 inf
->priv
->may_wildcard_vcont
= 0;
6582 /* Check whether any event pending in the vStopped queue would prevent
6583 a global or process wildcard vCont action. Clear
6584 *may_global_wildcard if we can't do a global wildcard (vCont;c),
6585 and clear the event inferior's may_wildcard_vcont flag if we can't
6586 do a process-wide wildcard resume (vCont;c:pPID.-1). */
6589 check_pending_events_prevent_wildcard_vcont (int *may_global_wildcard
)
6591 struct notif_client
*notif
= ¬if_client_stop
;
6593 remote_notif_get_pending_events (notif
);
6594 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6595 check_pending_event_prevents_wildcard_vcont_callback
,
6596 may_global_wildcard
);
6599 /* Remove stop replies in the queue if its pid is equal to the given
6603 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6604 QUEUE_ITER (stop_reply_p
) *iter
,
6608 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6609 struct inferior
*inf
= (struct inferior
*) param
->input
;
6611 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6613 stop_reply_xfree (event
);
6614 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6620 /* Discard all pending stop replies of inferior INF. */
6623 discard_pending_stop_replies (struct inferior
*inf
)
6625 struct queue_iter_param param
;
6626 struct stop_reply
*reply
;
6627 struct remote_state
*rs
= get_remote_state ();
6628 struct remote_notif_state
*rns
= rs
->notif_state
;
6630 /* This function can be notified when an inferior exists. When the
6631 target is not remote, the notification state is NULL. */
6632 if (rs
->remote_desc
== NULL
)
6635 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6637 /* Discard the in-flight notification. */
6638 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6640 stop_reply_xfree (reply
);
6641 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6645 param
.output
= NULL
;
6646 /* Discard the stop replies we have already pulled with
6648 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6649 remove_stop_reply_for_inferior
, ¶m
);
6652 /* If its remote state is equal to the given remote state,
6653 remove EVENT from the stop reply queue. */
6656 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6657 QUEUE_ITER (stop_reply_p
) *iter
,
6661 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6662 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6664 if (event
->rs
== rs
)
6666 stop_reply_xfree (event
);
6667 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6673 /* Discard the stop replies for RS in stop_reply_queue. */
6676 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6678 struct queue_iter_param param
;
6681 param
.output
= NULL
;
6682 /* Discard the stop replies we have already pulled with
6684 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6685 remove_stop_reply_of_remote_state
, ¶m
);
6688 /* A parameter to pass data in and out. */
6691 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6692 QUEUE_ITER (stop_reply_p
) *iter
,
6696 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6697 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6699 if (ptid_match (event
->ptid
, *ptid
))
6701 param
->output
= event
;
6702 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6709 /* Remove the first reply in 'stop_reply_queue' which matches
6712 static struct stop_reply
*
6713 remote_notif_remove_queued_reply (ptid_t ptid
)
6715 struct queue_iter_param param
;
6717 param
.input
= &ptid
;
6718 param
.output
= NULL
;
6720 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6721 remote_notif_remove_once_on_match
, ¶m
);
6723 fprintf_unfiltered (gdb_stdlog
,
6724 "notif: discard queued event: 'Stop' in %s\n",
6725 target_pid_to_str (ptid
));
6727 return param
.output
;
6730 /* Look for a queued stop reply belonging to PTID. If one is found,
6731 remove it from the queue, and return it. Returns NULL if none is
6732 found. If there are still queued events left to process, tell the
6733 event loop to get back to target_wait soon. */
6735 static struct stop_reply
*
6736 queued_stop_reply (ptid_t ptid
)
6738 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6740 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6741 /* There's still at least an event left. */
6742 mark_async_event_handler (remote_async_inferior_event_token
);
6747 /* Push a fully parsed stop reply in the stop reply queue. Since we
6748 know that we now have at least one queued event left to pass to the
6749 core side, tell the event loop to get back to target_wait soon. */
6752 push_stop_reply (struct stop_reply
*new_event
)
6754 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6757 fprintf_unfiltered (gdb_stdlog
,
6758 "notif: push 'Stop' %s to queue %d\n",
6759 target_pid_to_str (new_event
->ptid
),
6760 QUEUE_length (stop_reply_p
,
6763 mark_async_event_handler (remote_async_inferior_event_token
);
6767 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6768 QUEUE_ITER (stop_reply_p
) *iter
,
6769 struct stop_reply
*event
,
6772 ptid_t
*ptid
= (ptid_t
*) data
;
6774 return !(ptid_equal (*ptid
, event
->ptid
)
6775 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6778 /* Returns true if we have a stop reply for PTID. */
6781 peek_stop_reply (ptid_t ptid
)
6783 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6784 stop_reply_match_ptid_and_ws
, &ptid
);
6787 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6788 starting with P and ending with PEND matches PREFIX. */
6791 strprefix (const char *p
, const char *pend
, const char *prefix
)
6793 for ( ; p
< pend
; p
++, prefix
++)
6796 return *prefix
== '\0';
6799 /* Parse the stop reply in BUF. Either the function succeeds, and the
6800 result is stored in EVENT, or throws an error. */
6803 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6805 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6810 event
->ptid
= null_ptid
;
6811 event
->rs
= get_remote_state ();
6812 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6813 event
->ws
.value
.integer
= 0;
6814 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6815 event
->regcache
= NULL
;
6820 case 'T': /* Status with PC, SP, FP, ... */
6821 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6822 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6824 n... = register number
6825 r... = register contents
6828 p
= &buf
[3]; /* after Txx */
6834 p1
= strchr (p
, ':');
6836 error (_("Malformed packet(a) (missing colon): %s\n\
6840 error (_("Malformed packet(a) (missing register number): %s\n\
6844 /* Some "registers" are actually extended stop information.
6845 Note if you're adding a new entry here: GDB 7.9 and
6846 earlier assume that all register "numbers" that start
6847 with an hex digit are real register numbers. Make sure
6848 the server only sends such a packet if it knows the
6849 client understands it. */
6851 if (strprefix (p
, p1
, "thread"))
6852 event
->ptid
= read_ptid (++p1
, &p
);
6853 else if (strprefix (p
, p1
, "syscall_entry"))
6857 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6858 p
= unpack_varlen_hex (++p1
, &sysno
);
6859 event
->ws
.value
.syscall_number
= (int) sysno
;
6861 else if (strprefix (p
, p1
, "syscall_return"))
6865 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6866 p
= unpack_varlen_hex (++p1
, &sysno
);
6867 event
->ws
.value
.syscall_number
= (int) sysno
;
6869 else if (strprefix (p
, p1
, "watch")
6870 || strprefix (p
, p1
, "rwatch")
6871 || strprefix (p
, p1
, "awatch"))
6873 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6874 p
= unpack_varlen_hex (++p1
, &addr
);
6875 event
->watch_data_address
= (CORE_ADDR
) addr
;
6877 else if (strprefix (p
, p1
, "swbreak"))
6879 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6881 /* Make sure the stub doesn't forget to indicate support
6883 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6884 error (_("Unexpected swbreak stop reason"));
6886 /* The value part is documented as "must be empty",
6887 though we ignore it, in case we ever decide to make
6888 use of it in a backward compatible way. */
6889 p
= strchrnul (p1
+ 1, ';');
6891 else if (strprefix (p
, p1
, "hwbreak"))
6893 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6895 /* Make sure the stub doesn't forget to indicate support
6897 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6898 error (_("Unexpected hwbreak stop reason"));
6901 p
= strchrnul (p1
+ 1, ';');
6903 else if (strprefix (p
, p1
, "library"))
6905 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6906 p
= strchrnul (p1
+ 1, ';');
6908 else if (strprefix (p
, p1
, "replaylog"))
6910 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6911 /* p1 will indicate "begin" or "end", but it makes
6912 no difference for now, so ignore it. */
6913 p
= strchrnul (p1
+ 1, ';');
6915 else if (strprefix (p
, p1
, "core"))
6919 p
= unpack_varlen_hex (++p1
, &c
);
6922 else if (strprefix (p
, p1
, "fork"))
6924 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6925 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6927 else if (strprefix (p
, p1
, "vfork"))
6929 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6930 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6932 else if (strprefix (p
, p1
, "vforkdone"))
6934 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6935 p
= strchrnul (p1
+ 1, ';');
6937 else if (strprefix (p
, p1
, "exec"))
6940 char pathname
[PATH_MAX
];
6943 /* Determine the length of the execd pathname. */
6944 p
= unpack_varlen_hex (++p1
, &ignored
);
6945 pathlen
= (p
- p1
) / 2;
6947 /* Save the pathname for event reporting and for
6948 the next run command. */
6949 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6950 pathname
[pathlen
] = '\0';
6952 /* This is freed during event handling. */
6953 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6954 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6956 /* Skip the registers included in this packet, since
6957 they may be for an architecture different from the
6958 one used by the original program. */
6961 else if (strprefix (p
, p1
, "create"))
6963 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6964 p
= strchrnul (p1
+ 1, ';');
6973 p
= strchrnul (p1
+ 1, ';');
6978 /* Maybe a real ``P'' register number. */
6979 p_temp
= unpack_varlen_hex (p
, &pnum
);
6980 /* If the first invalid character is the colon, we got a
6981 register number. Otherwise, it's an unknown stop
6985 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6986 cached_reg_t cached_reg
;
6987 struct gdbarch
*gdbarch
= target_gdbarch ();
6990 error (_("Remote sent bad register number %s: %s\n\
6992 hex_string (pnum
), p
, buf
);
6994 cached_reg
.num
= reg
->regnum
;
6995 cached_reg
.data
= (gdb_byte
*)
6996 xmalloc (register_size (gdbarch
, reg
->regnum
));
6999 fieldsize
= hex2bin (p
, cached_reg
.data
,
7000 register_size (gdbarch
, reg
->regnum
));
7002 if (fieldsize
< register_size (gdbarch
, reg
->regnum
))
7003 warning (_("Remote reply is too short: %s"), buf
);
7005 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
7009 /* Not a number. Silently skip unknown optional
7011 p
= strchrnul (p1
+ 1, ';');
7016 error (_("Remote register badly formatted: %s\nhere: %s"),
7021 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
7025 case 'S': /* Old style status, just signal only. */
7029 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
7030 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
7031 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
7032 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
7034 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7037 case 'w': /* Thread exited. */
7042 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
7043 p
= unpack_varlen_hex (&buf
[1], &value
);
7044 event
->ws
.value
.integer
= value
;
7046 error (_("stop reply packet badly formatted: %s"), buf
);
7047 event
->ptid
= read_ptid (++p
, NULL
);
7050 case 'W': /* Target exited. */
7057 /* GDB used to accept only 2 hex chars here. Stubs should
7058 only send more if they detect GDB supports multi-process
7060 p
= unpack_varlen_hex (&buf
[1], &value
);
7064 /* The remote process exited. */
7065 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
7066 event
->ws
.value
.integer
= value
;
7070 /* The remote process exited with a signal. */
7071 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
7072 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
7073 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
7075 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7078 /* If no process is specified, assume inferior_ptid. */
7079 pid
= ptid_get_pid (inferior_ptid
);
7088 else if (startswith (p
, "process:"))
7092 p
+= sizeof ("process:") - 1;
7093 unpack_varlen_hex (p
, &upid
);
7097 error (_("unknown stop reply packet: %s"), buf
);
7100 error (_("unknown stop reply packet: %s"), buf
);
7101 event
->ptid
= pid_to_ptid (pid
);
7105 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
7106 event
->ptid
= minus_one_ptid
;
7110 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
7111 error (_("No process or thread specified in stop reply: %s"), buf
);
7114 /* When the stub wants to tell GDB about a new notification reply, it
7115 sends a notification (%Stop, for example). Those can come it at
7116 any time, hence, we have to make sure that any pending
7117 putpkt/getpkt sequence we're making is finished, before querying
7118 the stub for more events with the corresponding ack command
7119 (vStopped, for example). E.g., if we started a vStopped sequence
7120 immediately upon receiving the notification, something like this
7128 1.6) <-- (registers reply to step #1.3)
7130 Obviously, the reply in step #1.6 would be unexpected to a vStopped
7133 To solve this, whenever we parse a %Stop notification successfully,
7134 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
7135 doing whatever we were doing:
7141 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
7142 2.5) <-- (registers reply to step #2.3)
7144 Eventualy after step #2.5, we return to the event loop, which
7145 notices there's an event on the
7146 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
7147 associated callback --- the function below. At this point, we're
7148 always safe to start a vStopped sequence. :
7151 2.7) <-- T05 thread:2
7157 remote_notif_get_pending_events (struct notif_client
*nc
)
7159 struct remote_state
*rs
= get_remote_state ();
7161 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
7164 fprintf_unfiltered (gdb_stdlog
,
7165 "notif: process: '%s' ack pending event\n",
7169 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
7170 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
7174 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7175 if (strcmp (rs
->buf
, "OK") == 0)
7178 remote_notif_ack (nc
, rs
->buf
);
7184 fprintf_unfiltered (gdb_stdlog
,
7185 "notif: process: '%s' no pending reply\n",
7190 /* Called when it is decided that STOP_REPLY holds the info of the
7191 event that is to be returned to the core. This function always
7192 destroys STOP_REPLY. */
7195 process_stop_reply (struct stop_reply
*stop_reply
,
7196 struct target_waitstatus
*status
)
7200 *status
= stop_reply
->ws
;
7201 ptid
= stop_reply
->ptid
;
7203 /* If no thread/process was reported by the stub, assume the current
7205 if (ptid_equal (ptid
, null_ptid
))
7206 ptid
= inferior_ptid
;
7208 if (status
->kind
!= TARGET_WAITKIND_EXITED
7209 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
7210 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
7212 struct private_thread_info
*remote_thr
;
7214 /* Expedited registers. */
7215 if (stop_reply
->regcache
)
7217 struct regcache
*regcache
7218 = get_thread_arch_regcache (ptid
, target_gdbarch ());
7223 VEC_iterate (cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
7226 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
7230 VEC_free (cached_reg_t
, stop_reply
->regcache
);
7233 remote_notice_new_inferior (ptid
, 0);
7234 remote_thr
= get_private_info_ptid (ptid
);
7235 remote_thr
->core
= stop_reply
->core
;
7236 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
7237 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
7238 remote_thr
->vcont_resumed
= 0;
7241 stop_reply_xfree (stop_reply
);
7245 /* The non-stop mode version of target_wait. */
7248 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7250 struct remote_state
*rs
= get_remote_state ();
7251 struct stop_reply
*stop_reply
;
7255 /* If in non-stop mode, get out of getpkt even if a
7256 notification is received. */
7258 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7259 0 /* forever */, &is_notif
);
7262 if (ret
!= -1 && !is_notif
)
7265 case 'E': /* Error of some sort. */
7266 /* We're out of sync with the target now. Did it continue
7267 or not? We can't tell which thread it was in non-stop,
7268 so just ignore this. */
7269 warning (_("Remote failure reply: %s"), rs
->buf
);
7271 case 'O': /* Console output. */
7272 remote_console_output (rs
->buf
+ 1);
7275 warning (_("Invalid remote reply: %s"), rs
->buf
);
7279 /* Acknowledge a pending stop reply that may have arrived in the
7281 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
7282 remote_notif_get_pending_events (¬if_client_stop
);
7284 /* If indeed we noticed a stop reply, we're done. */
7285 stop_reply
= queued_stop_reply (ptid
);
7286 if (stop_reply
!= NULL
)
7287 return process_stop_reply (stop_reply
, status
);
7289 /* Still no event. If we're just polling for an event, then
7290 return to the event loop. */
7291 if (options
& TARGET_WNOHANG
)
7293 status
->kind
= TARGET_WAITKIND_IGNORE
;
7294 return minus_one_ptid
;
7297 /* Otherwise do a blocking wait. */
7298 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7299 1 /* forever */, &is_notif
);
7303 /* Wait until the remote machine stops, then return, storing status in
7304 STATUS just as `wait' would. */
7307 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7309 struct remote_state
*rs
= get_remote_state ();
7310 ptid_t event_ptid
= null_ptid
;
7312 struct stop_reply
*stop_reply
;
7316 status
->kind
= TARGET_WAITKIND_IGNORE
;
7317 status
->value
.integer
= 0;
7319 stop_reply
= queued_stop_reply (ptid
);
7320 if (stop_reply
!= NULL
)
7321 return process_stop_reply (stop_reply
, status
);
7323 if (rs
->cached_wait_status
)
7324 /* Use the cached wait status, but only once. */
7325 rs
->cached_wait_status
= 0;
7330 int forever
= ((options
& TARGET_WNOHANG
) == 0
7331 && wait_forever_enabled_p
);
7333 if (!rs
->waiting_for_stop_reply
)
7335 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
7336 return minus_one_ptid
;
7339 /* FIXME: cagney/1999-09-27: If we're in async mode we should
7340 _never_ wait for ever -> test on target_is_async_p().
7341 However, before we do that we need to ensure that the caller
7342 knows how to take the target into/out of async mode. */
7343 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7344 forever
, &is_notif
);
7346 /* GDB gets a notification. Return to core as this event is
7348 if (ret
!= -1 && is_notif
)
7349 return minus_one_ptid
;
7351 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
7352 return minus_one_ptid
;
7357 /* Assume that the target has acknowledged Ctrl-C unless we receive
7358 an 'F' or 'O' packet. */
7359 if (buf
[0] != 'F' && buf
[0] != 'O')
7360 rs
->ctrlc_pending_p
= 0;
7364 case 'E': /* Error of some sort. */
7365 /* We're out of sync with the target now. Did it continue or
7366 not? Not is more likely, so report a stop. */
7367 rs
->waiting_for_stop_reply
= 0;
7369 warning (_("Remote failure reply: %s"), buf
);
7370 status
->kind
= TARGET_WAITKIND_STOPPED
;
7371 status
->value
.sig
= GDB_SIGNAL_0
;
7373 case 'F': /* File-I/O request. */
7374 /* GDB may access the inferior memory while handling the File-I/O
7375 request, but we don't want GDB accessing memory while waiting
7376 for a stop reply. See the comments in putpkt_binary. Set
7377 waiting_for_stop_reply to 0 temporarily. */
7378 rs
->waiting_for_stop_reply
= 0;
7379 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
7380 rs
->ctrlc_pending_p
= 0;
7381 /* GDB handled the File-I/O request, and the target is running
7382 again. Keep waiting for events. */
7383 rs
->waiting_for_stop_reply
= 1;
7385 case 'N': case 'T': case 'S': case 'X': case 'W':
7387 struct stop_reply
*stop_reply
;
7389 /* There is a stop reply to handle. */
7390 rs
->waiting_for_stop_reply
= 0;
7393 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
7396 event_ptid
= process_stop_reply (stop_reply
, status
);
7399 case 'O': /* Console output. */
7400 remote_console_output (buf
+ 1);
7403 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7405 /* Zero length reply means that we tried 'S' or 'C' and the
7406 remote system doesn't support it. */
7407 target_terminal_ours_for_output ();
7409 ("Can't send signals to this remote system. %s not sent.\n",
7410 gdb_signal_to_name (rs
->last_sent_signal
));
7411 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7412 target_terminal_inferior ();
7414 strcpy (buf
, rs
->last_sent_step
? "s" : "c");
7418 /* else fallthrough */
7420 warning (_("Invalid remote reply: %s"), buf
);
7424 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7425 return minus_one_ptid
;
7426 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7428 /* Nothing interesting happened. If we're doing a non-blocking
7429 poll, we're done. Otherwise, go back to waiting. */
7430 if (options
& TARGET_WNOHANG
)
7431 return minus_one_ptid
;
7435 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7436 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7438 if (!ptid_equal (event_ptid
, null_ptid
))
7439 record_currthread (rs
, event_ptid
);
7441 event_ptid
= inferior_ptid
;
7444 /* A process exit. Invalidate our notion of current thread. */
7445 record_currthread (rs
, minus_one_ptid
);
7450 /* Wait until the remote machine stops, then return, storing status in
7451 STATUS just as `wait' would. */
7454 remote_wait (struct target_ops
*ops
,
7455 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7459 if (target_is_non_stop_p ())
7460 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7462 event_ptid
= remote_wait_as (ptid
, status
, options
);
7464 if (target_is_async_p ())
7466 /* If there are are events left in the queue tell the event loop
7468 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7469 mark_async_event_handler (remote_async_inferior_event_token
);
7475 /* Fetch a single register using a 'p' packet. */
7478 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7480 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7481 struct remote_state
*rs
= get_remote_state ();
7483 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
7486 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7489 if (reg
->pnum
== -1)
7494 p
+= hexnumstr (p
, reg
->pnum
);
7497 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7501 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7505 case PACKET_UNKNOWN
:
7508 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7509 gdbarch_register_name (get_regcache_arch (regcache
),
7514 /* If this register is unfetchable, tell the regcache. */
7517 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7521 /* Otherwise, parse and supply the value. */
7527 error (_("fetch_register_using_p: early buf termination"));
7529 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7532 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7536 /* Fetch the registers included in the target's 'g' packet. */
7539 send_g_packet (void)
7541 struct remote_state
*rs
= get_remote_state ();
7544 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7545 remote_send (&rs
->buf
, &rs
->buf_size
);
7547 /* We can get out of synch in various cases. If the first character
7548 in the buffer is not a hex character, assume that has happened
7549 and try to fetch another packet to read. */
7550 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7551 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7552 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7553 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7556 fprintf_unfiltered (gdb_stdlog
,
7557 "Bad register packet; fetching a new packet\n");
7558 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7561 buf_len
= strlen (rs
->buf
);
7563 /* Sanity check the received packet. */
7564 if (buf_len
% 2 != 0)
7565 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7571 process_g_packet (struct regcache
*regcache
)
7573 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7574 struct remote_state
*rs
= get_remote_state ();
7575 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7580 buf_len
= strlen (rs
->buf
);
7582 /* Further sanity checks, with knowledge of the architecture. */
7583 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7584 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7586 /* Save the size of the packet sent to us by the target. It is used
7587 as a heuristic when determining the max size of packets that the
7588 target can safely receive. */
7589 if (rsa
->actual_register_packet_size
== 0)
7590 rsa
->actual_register_packet_size
= buf_len
;
7592 /* If this is smaller than we guessed the 'g' packet would be,
7593 update our records. A 'g' reply that doesn't include a register's
7594 value implies either that the register is not available, or that
7595 the 'p' packet must be used. */
7596 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7598 long sizeof_g_packet
= buf_len
/ 2;
7600 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7602 long offset
= rsa
->regs
[i
].offset
;
7603 long reg_size
= register_size (gdbarch
, i
);
7605 if (rsa
->regs
[i
].pnum
== -1)
7608 if (offset
>= sizeof_g_packet
)
7609 rsa
->regs
[i
].in_g_packet
= 0;
7610 else if (offset
+ reg_size
> sizeof_g_packet
)
7611 error (_("Truncated register %d in remote 'g' packet"), i
);
7613 rsa
->regs
[i
].in_g_packet
= 1;
7616 /* Looks valid enough, we can assume this is the correct length
7617 for a 'g' packet. It's important not to adjust
7618 rsa->sizeof_g_packet if we have truncated registers otherwise
7619 this "if" won't be run the next time the method is called
7620 with a packet of the same size and one of the internal errors
7621 below will trigger instead. */
7622 rsa
->sizeof_g_packet
= sizeof_g_packet
;
7625 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7627 /* Unimplemented registers read as all bits zero. */
7628 memset (regs
, 0, rsa
->sizeof_g_packet
);
7630 /* Reply describes registers byte by byte, each byte encoded as two
7631 hex characters. Suck them all up, then supply them to the
7632 register cacheing/storage mechanism. */
7635 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7637 if (p
[0] == 0 || p
[1] == 0)
7638 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7639 internal_error (__FILE__
, __LINE__
,
7640 _("unexpected end of 'g' packet reply"));
7642 if (p
[0] == 'x' && p
[1] == 'x')
7643 regs
[i
] = 0; /* 'x' */
7645 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7649 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7651 struct packet_reg
*r
= &rsa
->regs
[i
];
7652 long reg_size
= register_size (gdbarch
, i
);
7656 if ((r
->offset
+ reg_size
) * 2 > strlen (rs
->buf
))
7657 /* This shouldn't happen - we adjusted in_g_packet above. */
7658 internal_error (__FILE__
, __LINE__
,
7659 _("unexpected end of 'g' packet reply"));
7660 else if (rs
->buf
[r
->offset
* 2] == 'x')
7662 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7663 /* The register isn't available, mark it as such (at
7664 the same time setting the value to zero). */
7665 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7668 regcache_raw_supply (regcache
, r
->regnum
,
7675 fetch_registers_using_g (struct regcache
*regcache
)
7678 process_g_packet (regcache
);
7681 /* Make the remote selected traceframe match GDB's selected
7685 set_remote_traceframe (void)
7688 struct remote_state
*rs
= get_remote_state ();
7690 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7693 /* Avoid recursion, remote_trace_find calls us again. */
7694 rs
->remote_traceframe_number
= get_traceframe_number ();
7696 newnum
= target_trace_find (tfind_number
,
7697 get_traceframe_number (), 0, 0, NULL
);
7699 /* Should not happen. If it does, all bets are off. */
7700 if (newnum
!= get_traceframe_number ())
7701 warning (_("could not set remote traceframe"));
7705 remote_fetch_registers (struct target_ops
*ops
,
7706 struct regcache
*regcache
, int regnum
)
7708 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7711 set_remote_traceframe ();
7712 set_general_thread (regcache_get_ptid (regcache
));
7716 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7718 gdb_assert (reg
!= NULL
);
7720 /* If this register might be in the 'g' packet, try that first -
7721 we are likely to read more than one register. If this is the
7722 first 'g' packet, we might be overly optimistic about its
7723 contents, so fall back to 'p'. */
7724 if (reg
->in_g_packet
)
7726 fetch_registers_using_g (regcache
);
7727 if (reg
->in_g_packet
)
7731 if (fetch_register_using_p (regcache
, reg
))
7734 /* This register is not available. */
7735 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7740 fetch_registers_using_g (regcache
);
7742 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7743 if (!rsa
->regs
[i
].in_g_packet
)
7744 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7746 /* This register is not available. */
7747 regcache_raw_supply (regcache
, i
, NULL
);
7751 /* Prepare to store registers. Since we may send them all (using a
7752 'G' request), we have to read out the ones we don't want to change
7756 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7758 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7761 /* Make sure the entire registers array is valid. */
7762 switch (packet_support (PACKET_P
))
7764 case PACKET_DISABLE
:
7765 case PACKET_SUPPORT_UNKNOWN
:
7766 /* Make sure all the necessary registers are cached. */
7767 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7768 if (rsa
->regs
[i
].in_g_packet
)
7769 regcache_raw_update (regcache
, rsa
->regs
[i
].regnum
);
7776 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7777 packet was not recognized. */
7780 store_register_using_P (const struct regcache
*regcache
,
7781 struct packet_reg
*reg
)
7783 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7784 struct remote_state
*rs
= get_remote_state ();
7785 /* Try storing a single register. */
7786 char *buf
= rs
->buf
;
7787 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
7790 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7793 if (reg
->pnum
== -1)
7796 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7797 p
= buf
+ strlen (buf
);
7798 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7799 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7803 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7808 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7809 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7810 case PACKET_UNKNOWN
:
7813 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7817 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7818 contents of the register cache buffer. FIXME: ignores errors. */
7821 store_registers_using_G (const struct regcache
*regcache
)
7823 struct remote_state
*rs
= get_remote_state ();
7824 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7828 /* Extract all the registers in the regcache copying them into a
7833 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7834 memset (regs
, 0, rsa
->sizeof_g_packet
);
7835 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7837 struct packet_reg
*r
= &rsa
->regs
[i
];
7840 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7844 /* Command describes registers byte by byte,
7845 each byte encoded as two hex characters. */
7848 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7850 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7851 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7852 error (_("Could not write registers; remote failure reply '%s'"),
7856 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7857 of the register cache buffer. FIXME: ignores errors. */
7860 remote_store_registers (struct target_ops
*ops
,
7861 struct regcache
*regcache
, int regnum
)
7863 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7866 set_remote_traceframe ();
7867 set_general_thread (regcache_get_ptid (regcache
));
7871 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7873 gdb_assert (reg
!= NULL
);
7875 /* Always prefer to store registers using the 'P' packet if
7876 possible; we often change only a small number of registers.
7877 Sometimes we change a larger number; we'd need help from a
7878 higher layer to know to use 'G'. */
7879 if (store_register_using_P (regcache
, reg
))
7882 /* For now, don't complain if we have no way to write the
7883 register. GDB loses track of unavailable registers too
7884 easily. Some day, this may be an error. We don't have
7885 any way to read the register, either... */
7886 if (!reg
->in_g_packet
)
7889 store_registers_using_G (regcache
);
7893 store_registers_using_G (regcache
);
7895 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7896 if (!rsa
->regs
[i
].in_g_packet
)
7897 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7898 /* See above for why we do not issue an error here. */
7903 /* Return the number of hex digits in num. */
7906 hexnumlen (ULONGEST num
)
7910 for (i
= 0; num
!= 0; i
++)
7913 return std::max (i
, 1);
7916 /* Set BUF to the minimum number of hex digits representing NUM. */
7919 hexnumstr (char *buf
, ULONGEST num
)
7921 int len
= hexnumlen (num
);
7923 return hexnumnstr (buf
, num
, len
);
7927 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7930 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7936 for (i
= width
- 1; i
>= 0; i
--)
7938 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7945 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7948 remote_address_masked (CORE_ADDR addr
)
7950 unsigned int address_size
= remote_address_size
;
7952 /* If "remoteaddresssize" was not set, default to target address size. */
7954 address_size
= gdbarch_addr_bit (target_gdbarch ());
7956 if (address_size
> 0
7957 && address_size
< (sizeof (ULONGEST
) * 8))
7959 /* Only create a mask when that mask can safely be constructed
7960 in a ULONGEST variable. */
7963 mask
= (mask
<< address_size
) - 1;
7969 /* Determine whether the remote target supports binary downloading.
7970 This is accomplished by sending a no-op memory write of zero length
7971 to the target at the specified address. It does not suffice to send
7972 the whole packet, since many stubs strip the eighth bit and
7973 subsequently compute a wrong checksum, which causes real havoc with
7976 NOTE: This can still lose if the serial line is not eight-bit
7977 clean. In cases like this, the user should clear "remote
7981 check_binary_download (CORE_ADDR addr
)
7983 struct remote_state
*rs
= get_remote_state ();
7985 switch (packet_support (PACKET_X
))
7987 case PACKET_DISABLE
:
7991 case PACKET_SUPPORT_UNKNOWN
:
7997 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7999 p
+= hexnumstr (p
, (ULONGEST
) 0);
8003 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8004 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8006 if (rs
->buf
[0] == '\0')
8009 fprintf_unfiltered (gdb_stdlog
,
8010 "binary downloading NOT "
8011 "supported by target\n");
8012 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
8017 fprintf_unfiltered (gdb_stdlog
,
8018 "binary downloading supported by target\n");
8019 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
8026 /* Helper function to resize the payload in order to try to get a good
8027 alignment. We try to write an amount of data such that the next write will
8028 start on an address aligned on REMOTE_ALIGN_WRITES. */
8031 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
8033 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
8036 /* Write memory data directly to the remote machine.
8037 This does not inform the data cache; the data cache uses this.
8038 HEADER is the starting part of the packet.
8039 MEMADDR is the address in the remote memory space.
8040 MYADDR is the address of the buffer in our space.
8041 LEN_UNITS is the number of addressable units to write.
8042 UNIT_SIZE is the length in bytes of an addressable unit.
8043 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
8044 should send data as binary ('X'), or hex-encoded ('M').
8046 The function creates packet of the form
8047 <HEADER><ADDRESS>,<LENGTH>:<DATA>
8049 where encoding of <DATA> is terminated by PACKET_FORMAT.
8051 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
8054 Return the transferred status, error or OK (an
8055 'enum target_xfer_status' value). Save the number of addressable units
8056 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
8058 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
8059 exchange between gdb and the stub could look like (?? in place of the
8065 -> $M1000,3:eeeeffffeeee#??
8069 <- eeeeffffeeeedddd */
8071 static enum target_xfer_status
8072 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
8073 const gdb_byte
*myaddr
, ULONGEST len_units
,
8074 int unit_size
, ULONGEST
*xfered_len_units
,
8075 char packet_format
, int use_length
)
8077 struct remote_state
*rs
= get_remote_state ();
8083 int payload_capacity_bytes
;
8084 int payload_length_bytes
;
8086 if (packet_format
!= 'X' && packet_format
!= 'M')
8087 internal_error (__FILE__
, __LINE__
,
8088 _("remote_write_bytes_aux: bad packet format"));
8091 return TARGET_XFER_EOF
;
8093 payload_capacity_bytes
= get_memory_write_packet_size ();
8095 /* The packet buffer will be large enough for the payload;
8096 get_memory_packet_size ensures this. */
8099 /* Compute the size of the actual payload by subtracting out the
8100 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
8102 payload_capacity_bytes
-= strlen ("$,:#NN");
8104 /* The comma won't be used. */
8105 payload_capacity_bytes
+= 1;
8106 payload_capacity_bytes
-= strlen (header
);
8107 payload_capacity_bytes
-= hexnumlen (memaddr
);
8109 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
8111 strcat (rs
->buf
, header
);
8112 p
= rs
->buf
+ strlen (header
);
8114 /* Compute a best guess of the number of bytes actually transfered. */
8115 if (packet_format
== 'X')
8117 /* Best guess at number of bytes that will fit. */
8118 todo_units
= std::min (len_units
,
8119 (ULONGEST
) payload_capacity_bytes
/ unit_size
);
8121 payload_capacity_bytes
-= hexnumlen (todo_units
);
8122 todo_units
= std::min (todo_units
, payload_capacity_bytes
/ unit_size
);
8126 /* Number of bytes that will fit. */
8128 = std::min (len_units
,
8129 (ULONGEST
) (payload_capacity_bytes
/ unit_size
) / 2);
8131 payload_capacity_bytes
-= hexnumlen (todo_units
);
8132 todo_units
= std::min (todo_units
,
8133 (payload_capacity_bytes
/ unit_size
) / 2);
8136 if (todo_units
<= 0)
8137 internal_error (__FILE__
, __LINE__
,
8138 _("minimum packet size too small to write data"));
8140 /* If we already need another packet, then try to align the end
8141 of this packet to a useful boundary. */
8142 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
8143 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
8145 /* Append "<memaddr>". */
8146 memaddr
= remote_address_masked (memaddr
);
8147 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8154 /* Append the length and retain its location and size. It may need to be
8155 adjusted once the packet body has been created. */
8157 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
8165 /* Append the packet body. */
8166 if (packet_format
== 'X')
8168 /* Binary mode. Send target system values byte by byte, in
8169 increasing byte addresses. Only escape certain critical
8171 payload_length_bytes
=
8172 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
8173 &units_written
, payload_capacity_bytes
);
8175 /* If not all TODO units fit, then we'll need another packet. Make
8176 a second try to keep the end of the packet aligned. Don't do
8177 this if the packet is tiny. */
8178 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
8182 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
8184 if (new_todo_units
!= units_written
)
8185 payload_length_bytes
=
8186 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
8187 (gdb_byte
*) p
, &units_written
,
8188 payload_capacity_bytes
);
8191 p
+= payload_length_bytes
;
8192 if (use_length
&& units_written
< todo_units
)
8194 /* Escape chars have filled up the buffer prematurely,
8195 and we have actually sent fewer units than planned.
8196 Fix-up the length field of the packet. Use the same
8197 number of characters as before. */
8198 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
8200 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
8205 /* Normal mode: Send target system values byte by byte, in
8206 increasing byte addresses. Each byte is encoded as a two hex
8208 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
8209 units_written
= todo_units
;
8212 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8213 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8215 if (rs
->buf
[0] == 'E')
8216 return TARGET_XFER_E_IO
;
8218 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
8219 send fewer units than we'd planned. */
8220 *xfered_len_units
= (ULONGEST
) units_written
;
8221 return TARGET_XFER_OK
;
8224 /* Write memory data directly to the remote machine.
8225 This does not inform the data cache; the data cache uses this.
8226 MEMADDR is the address in the remote memory space.
8227 MYADDR is the address of the buffer in our space.
8228 LEN is the number of bytes.
8230 Return the transferred status, error or OK (an
8231 'enum target_xfer_status' value). Save the number of bytes
8232 transferred in *XFERED_LEN. Only transfer a single packet. */
8234 static enum target_xfer_status
8235 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
8236 int unit_size
, ULONGEST
*xfered_len
)
8238 const char *packet_format
= NULL
;
8240 /* Check whether the target supports binary download. */
8241 check_binary_download (memaddr
);
8243 switch (packet_support (PACKET_X
))
8246 packet_format
= "X";
8248 case PACKET_DISABLE
:
8249 packet_format
= "M";
8251 case PACKET_SUPPORT_UNKNOWN
:
8252 internal_error (__FILE__
, __LINE__
,
8253 _("remote_write_bytes: bad internal state"));
8255 internal_error (__FILE__
, __LINE__
, _("bad switch"));
8258 return remote_write_bytes_aux (packet_format
,
8259 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
8260 packet_format
[0], 1);
8263 /* Read memory data directly from the remote machine.
8264 This does not use the data cache; the data cache uses this.
8265 MEMADDR is the address in the remote memory space.
8266 MYADDR is the address of the buffer in our space.
8267 LEN_UNITS is the number of addressable memory units to read..
8268 UNIT_SIZE is the length in bytes of an addressable unit.
8270 Return the transferred status, error or OK (an
8271 'enum target_xfer_status' value). Save the number of bytes
8272 transferred in *XFERED_LEN_UNITS.
8274 See the comment of remote_write_bytes_aux for an example of
8275 memory read/write exchange between gdb and the stub. */
8277 static enum target_xfer_status
8278 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
8279 int unit_size
, ULONGEST
*xfered_len_units
)
8281 struct remote_state
*rs
= get_remote_state ();
8282 int buf_size_bytes
; /* Max size of packet output buffer. */
8287 buf_size_bytes
= get_memory_read_packet_size ();
8288 /* The packet buffer will be large enough for the payload;
8289 get_memory_packet_size ensures this. */
8291 /* Number of units that will fit. */
8292 todo_units
= std::min (len_units
,
8293 (ULONGEST
) (buf_size_bytes
/ unit_size
) / 2);
8295 /* Construct "m"<memaddr>","<len>". */
8296 memaddr
= remote_address_masked (memaddr
);
8299 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8301 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
8304 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8305 if (rs
->buf
[0] == 'E'
8306 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
8307 && rs
->buf
[3] == '\0')
8308 return TARGET_XFER_E_IO
;
8309 /* Reply describes memory byte by byte, each byte encoded as two hex
8312 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
8313 /* Return what we have. Let higher layers handle partial reads. */
8314 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
8315 return TARGET_XFER_OK
;
8318 /* Using the set of read-only target sections of remote, read live
8321 For interface/parameters/return description see target.h,
8324 static enum target_xfer_status
8325 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
8326 ULONGEST memaddr
, ULONGEST len
,
8327 int unit_size
, ULONGEST
*xfered_len
)
8329 struct target_section
*secp
;
8330 struct target_section_table
*table
;
8332 secp
= target_section_by_addr (ops
, memaddr
);
8334 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
8335 secp
->the_bfd_section
)
8338 struct target_section
*p
;
8339 ULONGEST memend
= memaddr
+ len
;
8341 table
= target_get_section_table (ops
);
8343 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
8345 if (memaddr
>= p
->addr
)
8347 if (memend
<= p
->endaddr
)
8349 /* Entire transfer is within this section. */
8350 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8353 else if (memaddr
>= p
->endaddr
)
8355 /* This section ends before the transfer starts. */
8360 /* This section overlaps the transfer. Just do half. */
8361 len
= p
->endaddr
- memaddr
;
8362 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8369 return TARGET_XFER_EOF
;
8372 /* Similar to remote_read_bytes_1, but it reads from the remote stub
8373 first if the requested memory is unavailable in traceframe.
8374 Otherwise, fall back to remote_read_bytes_1. */
8376 static enum target_xfer_status
8377 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
8378 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
8379 ULONGEST
*xfered_len
)
8382 return TARGET_XFER_EOF
;
8384 if (get_traceframe_number () != -1)
8386 VEC(mem_range_s
) *available
;
8388 /* If we fail to get the set of available memory, then the
8389 target does not support querying traceframe info, and so we
8390 attempt reading from the traceframe anyway (assuming the
8391 target implements the old QTro packet then). */
8392 if (traceframe_available_memory (&available
, memaddr
, len
))
8394 struct cleanup
*old_chain
;
8396 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
8398 if (VEC_empty (mem_range_s
, available
)
8399 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
8401 enum target_xfer_status res
;
8403 /* Don't read into the traceframe's available
8405 if (!VEC_empty (mem_range_s
, available
))
8407 LONGEST oldlen
= len
;
8409 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
8410 gdb_assert (len
<= oldlen
);
8413 do_cleanups (old_chain
);
8415 /* This goes through the topmost target again. */
8416 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8417 len
, unit_size
, xfered_len
);
8418 if (res
== TARGET_XFER_OK
)
8419 return TARGET_XFER_OK
;
8422 /* No use trying further, we know some memory starting
8423 at MEMADDR isn't available. */
8425 return TARGET_XFER_UNAVAILABLE
;
8429 /* Don't try to read more than how much is available, in
8430 case the target implements the deprecated QTro packet to
8431 cater for older GDBs (the target's knowledge of read-only
8432 sections may be outdated by now). */
8433 len
= VEC_index (mem_range_s
, available
, 0)->length
;
8435 do_cleanups (old_chain
);
8439 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8444 /* Sends a packet with content determined by the printf format string
8445 FORMAT and the remaining arguments, then gets the reply. Returns
8446 whether the packet was a success, a failure, or unknown. */
8448 static enum packet_result
remote_send_printf (const char *format
, ...)
8449 ATTRIBUTE_PRINTF (1, 2);
8451 static enum packet_result
8452 remote_send_printf (const char *format
, ...)
8454 struct remote_state
*rs
= get_remote_state ();
8455 int max_size
= get_remote_packet_size ();
8458 va_start (ap
, format
);
8461 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8462 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8464 if (putpkt (rs
->buf
) < 0)
8465 error (_("Communication problem with target."));
8468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8470 return packet_check_result (rs
->buf
);
8473 /* Flash writing can take quite some time. We'll set
8474 effectively infinite timeout for flash operations.
8475 In future, we'll need to decide on a better approach. */
8476 static const int remote_flash_timeout
= 1000;
8479 remote_flash_erase (struct target_ops
*ops
,
8480 ULONGEST address
, LONGEST length
)
8482 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8483 enum packet_result ret
;
8484 scoped_restore restore_timeout
8485 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8487 ret
= remote_send_printf ("vFlashErase:%s,%s",
8488 phex (address
, addr_size
),
8492 case PACKET_UNKNOWN
:
8493 error (_("Remote target does not support flash erase"));
8495 error (_("Error erasing flash with vFlashErase packet"));
8501 static enum target_xfer_status
8502 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8503 ULONGEST length
, ULONGEST
*xfered_len
,
8504 const gdb_byte
*data
)
8506 scoped_restore restore_timeout
8507 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8508 return remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8513 remote_flash_done (struct target_ops
*ops
)
8517 scoped_restore restore_timeout
8518 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8520 ret
= remote_send_printf ("vFlashDone");
8524 case PACKET_UNKNOWN
:
8525 error (_("Remote target does not support vFlashDone"));
8527 error (_("Error finishing flash operation"));
8534 remote_files_info (struct target_ops
*ignore
)
8536 puts_filtered ("Debugging a target over a serial line.\n");
8539 /* Stuff for dealing with the packets which are part of this protocol.
8540 See comment at top of file for details. */
8542 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8543 error to higher layers. Called when a serial error is detected.
8544 The exception message is STRING, followed by a colon and a blank,
8545 the system error message for errno at function entry and final dot
8546 for output compatibility with throw_perror_with_name. */
8549 unpush_and_perror (const char *string
)
8551 int saved_errno
= errno
;
8553 remote_unpush_target ();
8554 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8555 safe_strerror (saved_errno
));
8558 /* Read a single character from the remote end. The current quit
8559 handler is overridden to avoid quitting in the middle of packet
8560 sequence, as that would break communication with the remote server.
8561 See remote_serial_quit_handler for more detail. */
8564 readchar (int timeout
)
8567 struct remote_state
*rs
= get_remote_state ();
8570 scoped_restore restore_quit
8571 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8573 rs
->got_ctrlc_during_io
= 0;
8575 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8577 if (rs
->got_ctrlc_during_io
)
8584 switch ((enum serial_rc
) ch
)
8587 remote_unpush_target ();
8588 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8591 unpush_and_perror (_("Remote communication error. "
8592 "Target disconnected."));
8594 case SERIAL_TIMEOUT
:
8600 /* Wrapper for serial_write that closes the target and throws if
8601 writing fails. The current quit handler is overridden to avoid
8602 quitting in the middle of packet sequence, as that would break
8603 communication with the remote server. See
8604 remote_serial_quit_handler for more detail. */
8607 remote_serial_write (const char *str
, int len
)
8609 struct remote_state
*rs
= get_remote_state ();
8611 scoped_restore restore_quit
8612 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8614 rs
->got_ctrlc_during_io
= 0;
8616 if (serial_write (rs
->remote_desc
, str
, len
))
8618 unpush_and_perror (_("Remote communication error. "
8619 "Target disconnected."));
8622 if (rs
->got_ctrlc_during_io
)
8626 /* Send the command in *BUF to the remote machine, and read the reply
8627 into *BUF. Report an error if we get an error reply. Resize
8628 *BUF using xrealloc if necessary to hold the result, and update
8632 remote_send (char **buf
,
8636 getpkt (buf
, sizeof_buf
, 0);
8638 if ((*buf
)[0] == 'E')
8639 error (_("Remote failure reply: %s"), *buf
);
8642 /* Return a string representing an escaped version of BUF, of len N.
8643 E.g. \n is converted to \\n, \t to \\t, etc. */
8646 escape_buffer (const char *buf
, int n
)
8650 stb
.putstrn (buf
, n
, '\\');
8651 return std::move (stb
.string ());
8654 /* Display a null-terminated packet on stdout, for debugging, using C
8658 print_packet (const char *buf
)
8660 puts_filtered ("\"");
8661 fputstr_filtered (buf
, '"', gdb_stdout
);
8662 puts_filtered ("\"");
8666 putpkt (const char *buf
)
8668 return putpkt_binary (buf
, strlen (buf
));
8671 /* Send a packet to the remote machine, with error checking. The data
8672 of the packet is in BUF. The string in BUF can be at most
8673 get_remote_packet_size () - 5 to account for the $, # and checksum,
8674 and for a possible /0 if we are debugging (remote_debug) and want
8675 to print the sent packet as a string. */
8678 putpkt_binary (const char *buf
, int cnt
)
8680 struct remote_state
*rs
= get_remote_state ();
8682 unsigned char csum
= 0;
8683 char *buf2
= (char *) xmalloc (cnt
+ 6);
8684 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8690 /* Catch cases like trying to read memory or listing threads while
8691 we're waiting for a stop reply. The remote server wouldn't be
8692 ready to handle this request, so we'd hang and timeout. We don't
8693 have to worry about this in synchronous mode, because in that
8694 case it's not possible to issue a command while the target is
8695 running. This is not a problem in non-stop mode, because in that
8696 case, the stub is always ready to process serial input. */
8697 if (!target_is_non_stop_p ()
8698 && target_is_async_p ()
8699 && rs
->waiting_for_stop_reply
)
8701 error (_("Cannot execute this command while the target is running.\n"
8702 "Use the \"interrupt\" command to stop the target\n"
8703 "and then try again."));
8706 /* We're sending out a new packet. Make sure we don't look at a
8707 stale cached response. */
8708 rs
->cached_wait_status
= 0;
8710 /* Copy the packet into buffer BUF2, encapsulating it
8711 and giving it a checksum. */
8716 for (i
= 0; i
< cnt
; i
++)
8722 *p
++ = tohex ((csum
>> 4) & 0xf);
8723 *p
++ = tohex (csum
& 0xf);
8725 /* Send it over and over until we get a positive ack. */
8729 int started_error_output
= 0;
8735 int len
= (int) (p
- buf2
);
8738 = escape_buffer (buf2
, std::min (len
, REMOTE_DEBUG_MAX_CHAR
));
8740 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s", str
.c_str ());
8742 if (str
.length () > REMOTE_DEBUG_MAX_CHAR
)
8744 fprintf_unfiltered (gdb_stdlog
, "[%zu bytes omitted]",
8745 str
.length () - REMOTE_DEBUG_MAX_CHAR
);
8748 fprintf_unfiltered (gdb_stdlog
, "...");
8750 gdb_flush (gdb_stdlog
);
8752 remote_serial_write (buf2
, p
- buf2
);
8754 /* If this is a no acks version of the remote protocol, send the
8755 packet and move on. */
8759 /* Read until either a timeout occurs (-2) or '+' is read.
8760 Handle any notification that arrives in the mean time. */
8763 ch
= readchar (remote_timeout
);
8771 case SERIAL_TIMEOUT
:
8774 if (started_error_output
)
8776 putchar_unfiltered ('\n');
8777 started_error_output
= 0;
8786 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8787 do_cleanups (old_chain
);
8791 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8793 case SERIAL_TIMEOUT
:
8797 do_cleanups (old_chain
);
8800 break; /* Retransmit buffer. */
8804 fprintf_unfiltered (gdb_stdlog
,
8805 "Packet instead of Ack, ignoring it\n");
8806 /* It's probably an old response sent because an ACK
8807 was lost. Gobble up the packet and ack it so it
8808 doesn't get retransmitted when we resend this
8811 remote_serial_write ("+", 1);
8812 continue; /* Now, go look for +. */
8819 /* If we got a notification, handle it, and go back to looking
8821 /* We've found the start of a notification. Now
8822 collect the data. */
8823 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8828 std::string str
= escape_buffer (rs
->buf
, val
);
8830 fprintf_unfiltered (gdb_stdlog
,
8831 " Notification received: %s\n",
8834 handle_notification (rs
->notif_state
, rs
->buf
);
8835 /* We're in sync now, rewait for the ack. */
8842 if (!started_error_output
)
8844 started_error_output
= 1;
8845 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8847 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8848 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8857 if (!started_error_output
)
8859 started_error_output
= 1;
8860 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8862 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8866 break; /* Here to retransmit. */
8870 /* This is wrong. If doing a long backtrace, the user should be
8871 able to get out next time we call QUIT, without anything as
8872 violent as interrupt_query. If we want to provide a way out of
8873 here without getting to the next QUIT, it should be based on
8874 hitting ^C twice as in remote_wait. */
8883 do_cleanups (old_chain
);
8887 /* Come here after finding the start of a frame when we expected an
8888 ack. Do our best to discard the rest of this packet. */
8897 c
= readchar (remote_timeout
);
8900 case SERIAL_TIMEOUT
:
8901 /* Nothing we can do. */
8904 /* Discard the two bytes of checksum and stop. */
8905 c
= readchar (remote_timeout
);
8907 c
= readchar (remote_timeout
);
8910 case '*': /* Run length encoding. */
8911 /* Discard the repeat count. */
8912 c
= readchar (remote_timeout
);
8917 /* A regular character. */
8923 /* Come here after finding the start of the frame. Collect the rest
8924 into *BUF, verifying the checksum, length, and handling run-length
8925 compression. NUL terminate the buffer. If there is not enough room,
8926 expand *BUF using xrealloc.
8928 Returns -1 on error, number of characters in buffer (ignoring the
8929 trailing NULL) on success. (could be extended to return one of the
8930 SERIAL status indications). */
8933 read_frame (char **buf_p
,
8940 struct remote_state
*rs
= get_remote_state ();
8947 c
= readchar (remote_timeout
);
8950 case SERIAL_TIMEOUT
:
8952 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8956 fputs_filtered ("Saw new packet start in middle of old one\n",
8958 return -1; /* Start a new packet, count retries. */
8961 unsigned char pktcsum
;
8967 check_0
= readchar (remote_timeout
);
8969 check_1
= readchar (remote_timeout
);
8971 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8974 fputs_filtered ("Timeout in checksum, retrying\n",
8978 else if (check_0
< 0 || check_1
< 0)
8981 fputs_filtered ("Communication error in checksum\n",
8986 /* Don't recompute the checksum; with no ack packets we
8987 don't have any way to indicate a packet retransmission
8992 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8993 if (csum
== pktcsum
)
8998 std::string str
= escape_buffer (buf
, bc
);
9000 fprintf_unfiltered (gdb_stdlog
,
9001 "Bad checksum, sentsum=0x%x, "
9002 "csum=0x%x, buf=%s\n",
9003 pktcsum
, csum
, str
.c_str ());
9005 /* Number of characters in buffer ignoring trailing
9009 case '*': /* Run length encoding. */
9014 c
= readchar (remote_timeout
);
9016 repeat
= c
- ' ' + 3; /* Compute repeat count. */
9018 /* The character before ``*'' is repeated. */
9020 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
9022 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
9024 /* Make some more room in the buffer. */
9025 *sizeof_buf
+= repeat
;
9026 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9030 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
9036 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
9040 if (bc
>= *sizeof_buf
- 1)
9042 /* Make some more room in the buffer. */
9044 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9055 /* Read a packet from the remote machine, with error checking, and
9056 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9057 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9058 rather than timing out; this is used (in synchronous mode) to wait
9059 for a target that is is executing user code to stop. */
9060 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
9061 don't have to change all the calls to getpkt to deal with the
9062 return value, because at the moment I don't know what the right
9063 thing to do it for those. */
9069 getpkt_sane (buf
, sizeof_buf
, forever
);
9073 /* Read a packet from the remote machine, with error checking, and
9074 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9075 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9076 rather than timing out; this is used (in synchronous mode) to wait
9077 for a target that is is executing user code to stop. If FOREVER ==
9078 0, this function is allowed to time out gracefully and return an
9079 indication of this to the caller. Otherwise return the number of
9080 bytes read. If EXPECTING_NOTIF, consider receiving a notification
9081 enough reason to return to the caller. *IS_NOTIF is an output
9082 boolean that indicates whether *BUF holds a notification or not
9083 (a regular packet). */
9086 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
9087 int expecting_notif
, int *is_notif
)
9089 struct remote_state
*rs
= get_remote_state ();
9095 /* We're reading a new response. Make sure we don't look at a
9096 previously cached response. */
9097 rs
->cached_wait_status
= 0;
9099 strcpy (*buf
, "timeout");
9102 timeout
= watchdog
> 0 ? watchdog
: -1;
9103 else if (expecting_notif
)
9104 timeout
= 0; /* There should already be a char in the buffer. If
9107 timeout
= remote_timeout
;
9111 /* Process any number of notifications, and then return when
9115 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
9117 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
9119 /* This can loop forever if the remote side sends us
9120 characters continuously, but if it pauses, we'll get
9121 SERIAL_TIMEOUT from readchar because of timeout. Then
9122 we'll count that as a retry.
9124 Note that even when forever is set, we will only wait
9125 forever prior to the start of a packet. After that, we
9126 expect characters to arrive at a brisk pace. They should
9127 show up within remote_timeout intervals. */
9129 c
= readchar (timeout
);
9130 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
9132 if (c
== SERIAL_TIMEOUT
)
9134 if (expecting_notif
)
9135 return -1; /* Don't complain, it's normal to not get
9136 anything in this case. */
9138 if (forever
) /* Watchdog went off? Kill the target. */
9140 remote_unpush_target ();
9141 throw_error (TARGET_CLOSE_ERROR
,
9142 _("Watchdog timeout has expired. "
9143 "Target detached."));
9146 fputs_filtered ("Timed out.\n", gdb_stdlog
);
9150 /* We've found the start of a packet or notification.
9151 Now collect the data. */
9152 val
= read_frame (buf
, sizeof_buf
);
9157 remote_serial_write ("-", 1);
9160 if (tries
> MAX_TRIES
)
9162 /* We have tried hard enough, and just can't receive the
9163 packet/notification. Give up. */
9164 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
9166 /* Skip the ack char if we're in no-ack mode. */
9167 if (!rs
->noack_mode
)
9168 remote_serial_write ("+", 1);
9172 /* If we got an ordinary packet, return that to our caller. */
9178 = escape_buffer (*buf
,
9179 std::min (val
, REMOTE_DEBUG_MAX_CHAR
));
9181 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s",
9184 if (str
.length () > REMOTE_DEBUG_MAX_CHAR
)
9186 fprintf_unfiltered (gdb_stdlog
, "[%zu bytes omitted]",
9187 str
.length () - REMOTE_DEBUG_MAX_CHAR
);
9190 fprintf_unfiltered (gdb_stdlog
, "\n");
9193 /* Skip the ack char if we're in no-ack mode. */
9194 if (!rs
->noack_mode
)
9195 remote_serial_write ("+", 1);
9196 if (is_notif
!= NULL
)
9201 /* If we got a notification, handle it, and go back to looking
9205 gdb_assert (c
== '%');
9209 std::string str
= escape_buffer (*buf
, val
);
9211 fprintf_unfiltered (gdb_stdlog
,
9212 " Notification received: %s\n",
9215 if (is_notif
!= NULL
)
9218 handle_notification (rs
->notif_state
, *buf
);
9220 /* Notifications require no acknowledgement. */
9222 if (expecting_notif
)
9229 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
9231 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
9235 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
9238 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
9242 /* Check whether EVENT is a fork event for the process specified
9243 by the pid passed in DATA, and if it is, kill the fork child. */
9246 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
9247 QUEUE_ITER (stop_reply_p
) *iter
,
9251 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
9252 int parent_pid
= *(int *) param
->input
;
9254 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
9256 struct remote_state
*rs
= get_remote_state ();
9257 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
9260 res
= remote_vkill (child_pid
, rs
);
9262 error (_("Can't kill fork child process %d"), child_pid
);
9268 /* Kill any new fork children of process PID that haven't been
9269 processed by follow_fork. */
9272 kill_new_fork_children (int pid
, struct remote_state
*rs
)
9274 struct thread_info
*thread
;
9275 struct notif_client
*notif
= ¬if_client_stop
;
9276 struct queue_iter_param param
;
9278 /* Kill the fork child threads of any threads in process PID
9279 that are stopped at a fork event. */
9280 ALL_NON_EXITED_THREADS (thread
)
9282 struct target_waitstatus
*ws
= &thread
->pending_follow
;
9284 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
9286 struct remote_state
*rs
= get_remote_state ();
9287 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
9290 res
= remote_vkill (child_pid
, rs
);
9292 error (_("Can't kill fork child process %d"), child_pid
);
9296 /* Check for any pending fork events (not reported or processed yet)
9297 in process PID and kill those fork child threads as well. */
9298 remote_notif_get_pending_events (notif
);
9300 param
.output
= NULL
;
9301 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
9302 kill_child_of_pending_fork
, ¶m
);
9306 /* Target hook to kill the current inferior. */
9309 remote_kill (struct target_ops
*ops
)
9312 int pid
= ptid_get_pid (inferior_ptid
);
9313 struct remote_state
*rs
= get_remote_state ();
9315 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
9317 /* If we're stopped while forking and we haven't followed yet,
9318 kill the child task. We need to do this before killing the
9319 parent task because if this is a vfork then the parent will
9321 kill_new_fork_children (pid
, rs
);
9323 res
= remote_vkill (pid
, rs
);
9326 target_mourn_inferior (inferior_ptid
);
9331 /* If we are in 'target remote' mode and we are killing the only
9332 inferior, then we will tell gdbserver to exit and unpush the
9334 if (res
== -1 && !remote_multi_process_p (rs
)
9335 && number_of_live_inferiors () == 1)
9339 /* We've killed the remote end, we get to mourn it. If we are
9340 not in extended mode, mourning the inferior also unpushes
9341 remote_ops from the target stack, which closes the remote
9343 target_mourn_inferior (inferior_ptid
);
9348 error (_("Can't kill process"));
9351 /* Send a kill request to the target using the 'vKill' packet. */
9354 remote_vkill (int pid
, struct remote_state
*rs
)
9356 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
9359 /* Tell the remote target to detach. */
9360 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
9362 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9364 switch (packet_ok (rs
->buf
,
9365 &remote_protocol_packets
[PACKET_vKill
]))
9371 case PACKET_UNKNOWN
:
9374 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
9378 /* Send a kill request to the target using the 'k' packet. */
9381 remote_kill_k (void)
9383 /* Catch errors so the user can quit from gdb even when we
9384 aren't on speaking terms with the remote system. */
9389 CATCH (ex
, RETURN_MASK_ERROR
)
9391 if (ex
.error
== TARGET_CLOSE_ERROR
)
9393 /* If we got an (EOF) error that caused the target
9394 to go away, then we're done, that's what we wanted.
9395 "k" is susceptible to cause a premature EOF, given
9396 that the remote server isn't actually required to
9397 reply to "k", and it can happen that it doesn't
9398 even get to reply ACK to the "k". */
9402 /* Otherwise, something went wrong. We didn't actually kill
9403 the target. Just propagate the exception, and let the
9404 user or higher layers decide what to do. */
9405 throw_exception (ex
);
9411 remote_mourn (struct target_ops
*target
)
9413 struct remote_state
*rs
= get_remote_state ();
9415 /* In 'target remote' mode with one inferior, we close the connection. */
9416 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9418 unpush_target (target
);
9420 /* remote_close takes care of doing most of the clean up. */
9421 generic_mourn_inferior ();
9425 /* In case we got here due to an error, but we're going to stay
9427 rs
->waiting_for_stop_reply
= 0;
9429 /* If the current general thread belonged to the process we just
9430 detached from or has exited, the remote side current general
9431 thread becomes undefined. Considering a case like this:
9433 - We just got here due to a detach.
9434 - The process that we're detaching from happens to immediately
9435 report a global breakpoint being hit in non-stop mode, in the
9436 same thread we had selected before.
9437 - GDB attaches to this process again.
9438 - This event happens to be the next event we handle.
9440 GDB would consider that the current general thread didn't need to
9441 be set on the stub side (with Hg), since for all it knew,
9442 GENERAL_THREAD hadn't changed.
9444 Notice that although in all-stop mode, the remote server always
9445 sets the current thread to the thread reporting the stop event,
9446 that doesn't happen in non-stop mode; in non-stop, the stub *must
9447 not* change the current thread when reporting a breakpoint hit,
9448 due to the decoupling of event reporting and event handling.
9450 To keep things simple, we always invalidate our notion of the
9452 record_currthread (rs
, minus_one_ptid
);
9454 /* Call common code to mark the inferior as not running. */
9455 generic_mourn_inferior ();
9457 if (!have_inferiors ())
9459 if (!remote_multi_process_p (rs
))
9461 /* Check whether the target is running now - some remote stubs
9462 automatically restart after kill. */
9464 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9466 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9468 /* Assume that the target has been restarted. Set
9469 inferior_ptid so that bits of core GDB realizes
9470 there's something here, e.g., so that the user can
9471 say "kill" again. */
9472 inferior_ptid
= magic_null_ptid
;
9479 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9481 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9485 extended_remote_disable_randomization (int val
)
9487 struct remote_state
*rs
= get_remote_state ();
9490 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9493 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9495 error (_("Target does not support QDisableRandomization."));
9496 if (strcmp (reply
, "OK") != 0)
9497 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9501 extended_remote_run (const std::string
&args
)
9503 struct remote_state
*rs
= get_remote_state ();
9505 const char *remote_exec_file
= get_remote_exec_file ();
9507 /* If the user has disabled vRun support, or we have detected that
9508 support is not available, do not try it. */
9509 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9512 strcpy (rs
->buf
, "vRun;");
9513 len
= strlen (rs
->buf
);
9515 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9516 error (_("Remote file name too long for run packet"));
9517 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9518 strlen (remote_exec_file
));
9524 gdb_argv
argv (args
.c_str ());
9525 for (i
= 0; argv
[i
] != NULL
; i
++)
9527 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9528 error (_("Argument list too long for run packet"));
9529 rs
->buf
[len
++] = ';';
9530 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9535 rs
->buf
[len
++] = '\0';
9538 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9540 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9543 /* We have a wait response. All is well. */
9545 case PACKET_UNKNOWN
:
9548 if (remote_exec_file
[0] == '\0')
9549 error (_("Running the default executable on the remote target failed; "
9550 "try \"set remote exec-file\"?"));
9552 error (_("Running \"%s\" on the remote target failed"),
9555 gdb_assert_not_reached (_("bad switch"));
9559 /* In the extended protocol we want to be able to do things like
9560 "run" and have them basically work as expected. So we need
9561 a special create_inferior function. We support changing the
9562 executable file and the command line arguments, but not the
9566 extended_remote_create_inferior (struct target_ops
*ops
,
9567 const char *exec_file
,
9568 const std::string
&args
,
9569 char **env
, int from_tty
)
9573 struct remote_state
*rs
= get_remote_state ();
9574 const char *remote_exec_file
= get_remote_exec_file ();
9576 /* If running asynchronously, register the target file descriptor
9577 with the event loop. */
9578 if (target_can_async_p ())
9581 /* Disable address space randomization if requested (and supported). */
9582 if (extended_remote_supports_disable_randomization (ops
))
9583 extended_remote_disable_randomization (disable_randomization
);
9585 /* If startup-with-shell is on, we inform gdbserver to start the
9586 remote inferior using a shell. */
9587 if (packet_support (PACKET_QStartupWithShell
) != PACKET_DISABLE
)
9589 xsnprintf (rs
->buf
, get_remote_packet_size (),
9590 "QStartupWithShell:%d", startup_with_shell
? 1 : 0);
9592 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9593 if (strcmp (rs
->buf
, "OK") != 0)
9595 Remote replied unexpectedly while setting startup-with-shell: %s"),
9599 /* Now restart the remote server. */
9600 run_worked
= extended_remote_run (args
) != -1;
9603 /* vRun was not supported. Fail if we need it to do what the
9605 if (remote_exec_file
[0])
9606 error (_("Remote target does not support \"set remote exec-file\""));
9608 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9610 /* Fall back to "R". */
9611 extended_remote_restart ();
9614 if (!have_inferiors ())
9616 /* Clean up from the last time we ran, before we mark the target
9617 running again. This will mark breakpoints uninserted, and
9618 get_offsets may insert breakpoints. */
9619 init_thread_list ();
9620 init_wait_for_inferior ();
9623 /* vRun's success return is a stop reply. */
9624 stop_reply
= run_worked
? rs
->buf
: NULL
;
9625 add_current_inferior_and_thread (stop_reply
);
9627 /* Get updated offsets, if the stub uses qOffsets. */
9632 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9633 the list of conditions (in agent expression bytecode format), if any, the
9634 target needs to evaluate. The output is placed into the packet buffer
9635 started from BUF and ended at BUF_END. */
9638 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9639 struct bp_target_info
*bp_tgt
, char *buf
,
9642 if (bp_tgt
->conditions
.empty ())
9645 buf
+= strlen (buf
);
9646 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9649 /* Send conditions to the target. */
9650 for (agent_expr
*aexpr
: bp_tgt
->conditions
)
9652 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9653 buf
+= strlen (buf
);
9654 for (int i
= 0; i
< aexpr
->len
; ++i
)
9655 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9662 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9663 struct bp_target_info
*bp_tgt
, char *buf
)
9665 if (bp_tgt
->tcommands
.empty ())
9668 buf
+= strlen (buf
);
9670 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9671 buf
+= strlen (buf
);
9673 /* Concatenate all the agent expressions that are commands into the
9675 for (agent_expr
*aexpr
: bp_tgt
->tcommands
)
9677 sprintf (buf
, "X%x,", aexpr
->len
);
9678 buf
+= strlen (buf
);
9679 for (int i
= 0; i
< aexpr
->len
; ++i
)
9680 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9685 /* Insert a breakpoint. On targets that have software breakpoint
9686 support, we ask the remote target to do the work; on targets
9687 which don't, we insert a traditional memory breakpoint. */
9690 remote_insert_breakpoint (struct target_ops
*ops
,
9691 struct gdbarch
*gdbarch
,
9692 struct bp_target_info
*bp_tgt
)
9694 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9695 If it succeeds, then set the support to PACKET_ENABLE. If it
9696 fails, and the user has explicitly requested the Z support then
9697 report an error, otherwise, mark it disabled and go on. */
9699 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9701 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9702 struct remote_state
*rs
;
9706 /* Make sure the remote is pointing at the right process, if
9708 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9709 set_general_process ();
9711 rs
= get_remote_state ();
9713 endbuf
= rs
->buf
+ get_remote_packet_size ();
9718 addr
= (ULONGEST
) remote_address_masked (addr
);
9719 p
+= hexnumstr (p
, addr
);
9720 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9722 if (remote_supports_cond_breakpoints (ops
))
9723 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9725 if (remote_can_run_breakpoint_commands (ops
))
9726 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9731 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9737 case PACKET_UNKNOWN
:
9742 /* If this breakpoint has target-side commands but this stub doesn't
9743 support Z0 packets, throw error. */
9744 if (!bp_tgt
->tcommands
.empty ())
9745 throw_error (NOT_SUPPORTED_ERROR
, _("\
9746 Target doesn't support breakpoints that have target side commands."));
9748 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9752 remote_remove_breakpoint (struct target_ops
*ops
,
9753 struct gdbarch
*gdbarch
,
9754 struct bp_target_info
*bp_tgt
,
9755 enum remove_bp_reason reason
)
9757 CORE_ADDR addr
= bp_tgt
->placed_address
;
9758 struct remote_state
*rs
= get_remote_state ();
9760 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9763 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9765 /* Make sure the remote is pointing at the right process, if
9767 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9768 set_general_process ();
9774 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9775 p
+= hexnumstr (p
, addr
);
9776 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9779 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9781 return (rs
->buf
[0] == 'E');
9784 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
, reason
);
9787 static enum Z_packet_type
9788 watchpoint_to_Z_packet (int type
)
9793 return Z_PACKET_WRITE_WP
;
9796 return Z_PACKET_READ_WP
;
9799 return Z_PACKET_ACCESS_WP
;
9802 internal_error (__FILE__
, __LINE__
,
9803 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9808 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9809 enum target_hw_bp_type type
, struct expression
*cond
)
9811 struct remote_state
*rs
= get_remote_state ();
9812 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9814 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9816 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9819 /* Make sure the remote is pointing at the right process, if
9821 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9822 set_general_process ();
9824 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9825 p
= strchr (rs
->buf
, '\0');
9826 addr
= remote_address_masked (addr
);
9827 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9828 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9831 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9833 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9837 case PACKET_UNKNOWN
:
9842 internal_error (__FILE__
, __LINE__
,
9843 _("remote_insert_watchpoint: reached end of function"));
9847 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9848 CORE_ADDR start
, int length
)
9850 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9852 return diff
< length
;
9857 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9858 enum target_hw_bp_type type
, struct expression
*cond
)
9860 struct remote_state
*rs
= get_remote_state ();
9861 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9863 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9865 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9868 /* Make sure the remote is pointing at the right process, if
9870 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9871 set_general_process ();
9873 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9874 p
= strchr (rs
->buf
, '\0');
9875 addr
= remote_address_masked (addr
);
9876 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9877 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9879 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9881 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9884 case PACKET_UNKNOWN
:
9889 internal_error (__FILE__
, __LINE__
,
9890 _("remote_remove_watchpoint: reached end of function"));
9894 int remote_hw_watchpoint_limit
= -1;
9895 int remote_hw_watchpoint_length_limit
= -1;
9896 int remote_hw_breakpoint_limit
= -1;
9899 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9900 CORE_ADDR addr
, int len
)
9902 if (remote_hw_watchpoint_length_limit
== 0)
9904 else if (remote_hw_watchpoint_length_limit
< 0)
9906 else if (len
<= remote_hw_watchpoint_length_limit
)
9913 remote_check_watch_resources (struct target_ops
*self
,
9914 enum bptype type
, int cnt
, int ot
)
9916 if (type
== bp_hardware_breakpoint
)
9918 if (remote_hw_breakpoint_limit
== 0)
9920 else if (remote_hw_breakpoint_limit
< 0)
9922 else if (cnt
<= remote_hw_breakpoint_limit
)
9927 if (remote_hw_watchpoint_limit
== 0)
9929 else if (remote_hw_watchpoint_limit
< 0)
9933 else if (cnt
<= remote_hw_watchpoint_limit
)
9939 /* The to_stopped_by_sw_breakpoint method of target remote. */
9942 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9944 struct thread_info
*thread
= inferior_thread ();
9946 return (thread
->priv
!= NULL
9947 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9950 /* The to_supports_stopped_by_sw_breakpoint method of target
9954 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9956 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9959 /* The to_stopped_by_hw_breakpoint method of target remote. */
9962 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9964 struct thread_info
*thread
= inferior_thread ();
9966 return (thread
->priv
!= NULL
9967 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9970 /* The to_supports_stopped_by_hw_breakpoint method of target
9974 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9976 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9980 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9982 struct thread_info
*thread
= inferior_thread ();
9984 return (thread
->priv
!= NULL
9985 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9989 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9991 struct thread_info
*thread
= inferior_thread ();
9993 if (thread
->priv
!= NULL
9994 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9996 *addr_p
= thread
->priv
->watch_data_address
;
10005 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10006 struct bp_target_info
*bp_tgt
)
10008 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
10009 struct remote_state
*rs
;
10013 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10016 /* Make sure the remote is pointing at the right process, if
10018 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10019 set_general_process ();
10021 rs
= get_remote_state ();
10023 endbuf
= rs
->buf
+ get_remote_packet_size ();
10029 addr
= remote_address_masked (addr
);
10030 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10031 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10033 if (remote_supports_cond_breakpoints (self
))
10034 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
10036 if (remote_can_run_breakpoint_commands (self
))
10037 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
10040 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10042 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10045 if (rs
->buf
[1] == '.')
10047 message
= strchr (rs
->buf
+ 2, '.');
10049 error (_("Remote failure reply: %s"), message
+ 1);
10052 case PACKET_UNKNOWN
:
10057 internal_error (__FILE__
, __LINE__
,
10058 _("remote_insert_hw_breakpoint: reached end of function"));
10063 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10064 struct bp_target_info
*bp_tgt
)
10067 struct remote_state
*rs
= get_remote_state ();
10069 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10071 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10074 /* Make sure the remote is pointing at the right process, if
10076 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10077 set_general_process ();
10083 addr
= remote_address_masked (bp_tgt
->placed_address
);
10084 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10085 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10088 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10090 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10093 case PACKET_UNKNOWN
:
10098 internal_error (__FILE__
, __LINE__
,
10099 _("remote_remove_hw_breakpoint: reached end of function"));
10102 /* Verify memory using the "qCRC:" request. */
10105 remote_verify_memory (struct target_ops
*ops
,
10106 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
10108 struct remote_state
*rs
= get_remote_state ();
10109 unsigned long host_crc
, target_crc
;
10112 /* It doesn't make sense to use qCRC if the remote target is
10113 connected but not running. */
10114 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
10116 enum packet_result result
;
10118 /* Make sure the remote is pointing at the right process. */
10119 set_general_process ();
10121 /* FIXME: assumes lma can fit into long. */
10122 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
10123 (long) lma
, (long) size
);
10126 /* Be clever; compute the host_crc before waiting for target
10128 host_crc
= xcrc32 (data
, size
, 0xffffffff);
10130 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10132 result
= packet_ok (rs
->buf
,
10133 &remote_protocol_packets
[PACKET_qCRC
]);
10134 if (result
== PACKET_ERROR
)
10136 else if (result
== PACKET_OK
)
10138 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
10139 target_crc
= target_crc
* 16 + fromhex (*tmp
);
10141 return (host_crc
== target_crc
);
10145 return simple_verify_memory (ops
, data
, lma
, size
);
10148 /* compare-sections command
10150 With no arguments, compares each loadable section in the exec bfd
10151 with the same memory range on the target, and reports mismatches.
10152 Useful for verifying the image on the target against the exec file. */
10155 compare_sections_command (char *args
, int from_tty
)
10158 struct cleanup
*old_chain
;
10159 gdb_byte
*sectdata
;
10160 const char *sectname
;
10161 bfd_size_type size
;
10164 int mismatched
= 0;
10169 error (_("command cannot be used without an exec file"));
10171 /* Make sure the remote is pointing at the right process. */
10172 set_general_process ();
10174 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
10180 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10182 if (!(s
->flags
& SEC_LOAD
))
10183 continue; /* Skip non-loadable section. */
10185 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
10186 continue; /* Skip writeable sections */
10188 size
= bfd_get_section_size (s
);
10190 continue; /* Skip zero-length section. */
10192 sectname
= bfd_get_section_name (exec_bfd
, s
);
10193 if (args
&& strcmp (args
, sectname
) != 0)
10194 continue; /* Not the section selected by user. */
10196 matched
= 1; /* Do this section. */
10199 sectdata
= (gdb_byte
*) xmalloc (size
);
10200 old_chain
= make_cleanup (xfree
, sectdata
);
10201 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
10203 res
= target_verify_memory (sectdata
, lma
, size
);
10206 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
10207 paddress (target_gdbarch (), lma
),
10208 paddress (target_gdbarch (), lma
+ size
));
10210 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
10211 paddress (target_gdbarch (), lma
),
10212 paddress (target_gdbarch (), lma
+ size
));
10214 printf_filtered ("matched.\n");
10217 printf_filtered ("MIS-MATCHED!\n");
10221 do_cleanups (old_chain
);
10223 if (mismatched
> 0)
10224 warning (_("One or more sections of the target image does not match\n\
10225 the loaded file\n"));
10226 if (args
&& !matched
)
10227 printf_filtered (_("No loaded section named '%s'.\n"), args
);
10230 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
10231 into remote target. The number of bytes written to the remote
10232 target is returned, or -1 for error. */
10234 static enum target_xfer_status
10235 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
10236 const char *annex
, const gdb_byte
*writebuf
,
10237 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
10238 struct packet_config
*packet
)
10242 struct remote_state
*rs
= get_remote_state ();
10243 int max_size
= get_memory_write_packet_size ();
10245 if (packet
->support
== PACKET_DISABLE
)
10246 return TARGET_XFER_E_IO
;
10248 /* Insert header. */
10249 i
= snprintf (rs
->buf
, max_size
,
10250 "qXfer:%s:write:%s:%s:",
10251 object_name
, annex
? annex
: "",
10252 phex_nz (offset
, sizeof offset
));
10253 max_size
-= (i
+ 1);
10255 /* Escape as much data as fits into rs->buf. */
10256 buf_len
= remote_escape_output
10257 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
10259 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
10260 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10261 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10262 return TARGET_XFER_E_IO
;
10264 unpack_varlen_hex (rs
->buf
, &n
);
10267 return TARGET_XFER_OK
;
10270 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
10271 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
10272 number of bytes read is returned, or 0 for EOF, or -1 for error.
10273 The number of bytes read may be less than LEN without indicating an
10274 EOF. PACKET is checked and updated to indicate whether the remote
10275 target supports this object. */
10277 static enum target_xfer_status
10278 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
10280 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
10281 ULONGEST
*xfered_len
,
10282 struct packet_config
*packet
)
10284 struct remote_state
*rs
= get_remote_state ();
10285 LONGEST i
, n
, packet_len
;
10287 if (packet
->support
== PACKET_DISABLE
)
10288 return TARGET_XFER_E_IO
;
10290 /* Check whether we've cached an end-of-object packet that matches
10292 if (rs
->finished_object
)
10294 if (strcmp (object_name
, rs
->finished_object
) == 0
10295 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
10296 && offset
== rs
->finished_offset
)
10297 return TARGET_XFER_EOF
;
10300 /* Otherwise, we're now reading something different. Discard
10302 xfree (rs
->finished_object
);
10303 xfree (rs
->finished_annex
);
10304 rs
->finished_object
= NULL
;
10305 rs
->finished_annex
= NULL
;
10308 /* Request only enough to fit in a single packet. The actual data
10309 may not, since we don't know how much of it will need to be escaped;
10310 the target is free to respond with slightly less data. We subtract
10311 five to account for the response type and the protocol frame. */
10312 n
= std::min
<LONGEST
> (get_remote_packet_size () - 5, len
);
10313 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
10314 object_name
, annex
? annex
: "",
10315 phex_nz (offset
, sizeof offset
),
10316 phex_nz (n
, sizeof n
));
10317 i
= putpkt (rs
->buf
);
10319 return TARGET_XFER_E_IO
;
10322 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10323 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10324 return TARGET_XFER_E_IO
;
10326 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
10327 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
10329 /* 'm' means there is (or at least might be) more data after this
10330 batch. That does not make sense unless there's at least one byte
10331 of data in this reply. */
10332 if (rs
->buf
[0] == 'm' && packet_len
== 1)
10333 error (_("Remote qXfer reply contained no data."));
10335 /* Got some data. */
10336 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
10337 packet_len
- 1, readbuf
, n
);
10339 /* 'l' is an EOF marker, possibly including a final block of data,
10340 or possibly empty. If we have the final block of a non-empty
10341 object, record this fact to bypass a subsequent partial read. */
10342 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
10344 rs
->finished_object
= xstrdup (object_name
);
10345 rs
->finished_annex
= xstrdup (annex
? annex
: "");
10346 rs
->finished_offset
= offset
+ i
;
10350 return TARGET_XFER_EOF
;
10354 return TARGET_XFER_OK
;
10358 static enum target_xfer_status
10359 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
10360 const char *annex
, gdb_byte
*readbuf
,
10361 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
10362 ULONGEST
*xfered_len
)
10364 struct remote_state
*rs
;
10368 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
10370 set_remote_traceframe ();
10371 set_general_thread (inferior_ptid
);
10373 rs
= get_remote_state ();
10375 /* Handle memory using the standard memory routines. */
10376 if (object
== TARGET_OBJECT_MEMORY
)
10378 /* If the remote target is connected but not running, we should
10379 pass this request down to a lower stratum (e.g. the executable
10381 if (!target_has_execution
)
10382 return TARGET_XFER_EOF
;
10384 if (writebuf
!= NULL
)
10385 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
10388 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
10392 /* Handle SPU memory using qxfer packets. */
10393 if (object
== TARGET_OBJECT_SPU
)
10396 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
10397 xfered_len
, &remote_protocol_packets
10398 [PACKET_qXfer_spu_read
]);
10400 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
10401 xfered_len
, &remote_protocol_packets
10402 [PACKET_qXfer_spu_write
]);
10405 /* Handle extra signal info using qxfer packets. */
10406 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10409 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10410 xfered_len
, &remote_protocol_packets
10411 [PACKET_qXfer_siginfo_read
]);
10413 return remote_write_qxfer (ops
, "siginfo", annex
,
10414 writebuf
, offset
, len
, xfered_len
,
10415 &remote_protocol_packets
10416 [PACKET_qXfer_siginfo_write
]);
10419 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10422 return remote_read_qxfer (ops
, "statictrace", annex
,
10423 readbuf
, offset
, len
, xfered_len
,
10424 &remote_protocol_packets
10425 [PACKET_qXfer_statictrace_read
]);
10427 return TARGET_XFER_E_IO
;
10430 /* Only handle flash writes. */
10431 if (writebuf
!= NULL
)
10435 case TARGET_OBJECT_FLASH
:
10436 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10440 return TARGET_XFER_E_IO
;
10444 /* Map pre-existing objects onto letters. DO NOT do this for new
10445 objects!!! Instead specify new query packets. */
10448 case TARGET_OBJECT_AVR
:
10452 case TARGET_OBJECT_AUXV
:
10453 gdb_assert (annex
== NULL
);
10454 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10456 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10458 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10459 return remote_read_qxfer
10460 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10461 &remote_protocol_packets
[PACKET_qXfer_features
]);
10463 case TARGET_OBJECT_LIBRARIES
:
10464 return remote_read_qxfer
10465 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10466 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10468 case TARGET_OBJECT_LIBRARIES_SVR4
:
10469 return remote_read_qxfer
10470 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10471 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10473 case TARGET_OBJECT_MEMORY_MAP
:
10474 gdb_assert (annex
== NULL
);
10475 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10477 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10479 case TARGET_OBJECT_OSDATA
:
10480 /* Should only get here if we're connected. */
10481 gdb_assert (rs
->remote_desc
);
10482 return remote_read_qxfer
10483 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10484 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10486 case TARGET_OBJECT_THREADS
:
10487 gdb_assert (annex
== NULL
);
10488 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10490 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10492 case TARGET_OBJECT_TRACEFRAME_INFO
:
10493 gdb_assert (annex
== NULL
);
10494 return remote_read_qxfer
10495 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10496 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10498 case TARGET_OBJECT_FDPIC
:
10499 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10501 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10503 case TARGET_OBJECT_OPENVMS_UIB
:
10504 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10506 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10508 case TARGET_OBJECT_BTRACE
:
10509 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10511 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10513 case TARGET_OBJECT_BTRACE_CONF
:
10514 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10516 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10518 case TARGET_OBJECT_EXEC_FILE
:
10519 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10521 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10524 return TARGET_XFER_E_IO
;
10527 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10528 large enough let the caller deal with it. */
10529 if (len
< get_remote_packet_size ())
10530 return TARGET_XFER_E_IO
;
10531 len
= get_remote_packet_size ();
10533 /* Except for querying the minimum buffer size, target must be open. */
10534 if (!rs
->remote_desc
)
10535 error (_("remote query is only available after target open"));
10537 gdb_assert (annex
!= NULL
);
10538 gdb_assert (readbuf
!= NULL
);
10542 *p2
++ = query_type
;
10544 /* We used one buffer char for the remote protocol q command and
10545 another for the query type. As the remote protocol encapsulation
10546 uses 4 chars plus one extra in case we are debugging
10547 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10550 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10552 /* Bad caller may have sent forbidden characters. */
10553 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10558 gdb_assert (annex
[i
] == '\0');
10560 i
= putpkt (rs
->buf
);
10562 return TARGET_XFER_E_IO
;
10564 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10565 strcpy ((char *) readbuf
, rs
->buf
);
10567 *xfered_len
= strlen ((char *) readbuf
);
10568 return TARGET_XFER_OK
;
10571 /* Implementation of to_get_memory_xfer_limit. */
10574 remote_get_memory_xfer_limit (struct target_ops
*ops
)
10576 return get_memory_write_packet_size ();
10580 remote_search_memory (struct target_ops
* ops
,
10581 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10582 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10583 CORE_ADDR
*found_addrp
)
10585 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10586 struct remote_state
*rs
= get_remote_state ();
10587 int max_size
= get_memory_write_packet_size ();
10588 struct packet_config
*packet
=
10589 &remote_protocol_packets
[PACKET_qSearch_memory
];
10590 /* Number of packet bytes used to encode the pattern;
10591 this could be more than PATTERN_LEN due to escape characters. */
10592 int escaped_pattern_len
;
10593 /* Amount of pattern that was encodable in the packet. */
10594 int used_pattern_len
;
10597 ULONGEST found_addr
;
10599 /* Don't go to the target if we don't have to.
10600 This is done before checking packet->support to avoid the possibility that
10601 a success for this edge case means the facility works in general. */
10602 if (pattern_len
> search_space_len
)
10604 if (pattern_len
== 0)
10606 *found_addrp
= start_addr
;
10610 /* If we already know the packet isn't supported, fall back to the simple
10611 way of searching memory. */
10613 if (packet_config_support (packet
) == PACKET_DISABLE
)
10615 /* Target doesn't provided special support, fall back and use the
10616 standard support (copy memory and do the search here). */
10617 return simple_search_memory (ops
, start_addr
, search_space_len
,
10618 pattern
, pattern_len
, found_addrp
);
10621 /* Make sure the remote is pointing at the right process. */
10622 set_general_process ();
10624 /* Insert header. */
10625 i
= snprintf (rs
->buf
, max_size
,
10626 "qSearch:memory:%s;%s;",
10627 phex_nz (start_addr
, addr_size
),
10628 phex_nz (search_space_len
, sizeof (search_space_len
)));
10629 max_size
-= (i
+ 1);
10631 /* Escape as much data as fits into rs->buf. */
10632 escaped_pattern_len
=
10633 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10634 &used_pattern_len
, max_size
);
10636 /* Bail if the pattern is too large. */
10637 if (used_pattern_len
!= pattern_len
)
10638 error (_("Pattern is too large to transmit to remote target."));
10640 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10641 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10642 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10644 /* The request may not have worked because the command is not
10645 supported. If so, fall back to the simple way. */
10646 if (packet
->support
== PACKET_DISABLE
)
10648 return simple_search_memory (ops
, start_addr
, search_space_len
,
10649 pattern
, pattern_len
, found_addrp
);
10654 if (rs
->buf
[0] == '0')
10656 else if (rs
->buf
[0] == '1')
10659 if (rs
->buf
[1] != ',')
10660 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10661 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10662 *found_addrp
= found_addr
;
10665 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10671 remote_rcmd (struct target_ops
*self
, const char *command
,
10672 struct ui_file
*outbuf
)
10674 struct remote_state
*rs
= get_remote_state ();
10677 if (!rs
->remote_desc
)
10678 error (_("remote rcmd is only available after target open"));
10680 /* Send a NULL command across as an empty command. */
10681 if (command
== NULL
)
10684 /* The query prefix. */
10685 strcpy (rs
->buf
, "qRcmd,");
10686 p
= strchr (rs
->buf
, '\0');
10688 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10689 > get_remote_packet_size ())
10690 error (_("\"monitor\" command ``%s'' is too long."), command
);
10692 /* Encode the actual command. */
10693 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10695 if (putpkt (rs
->buf
) < 0)
10696 error (_("Communication problem with target."));
10698 /* get/display the response */
10703 /* XXX - see also remote_get_noisy_reply(). */
10704 QUIT
; /* Allow user to bail out with ^C. */
10706 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10708 /* Timeout. Continue to (try to) read responses.
10709 This is better than stopping with an error, assuming the stub
10710 is still executing the (long) monitor command.
10711 If needed, the user can interrupt gdb using C-c, obtaining
10712 an effect similar to stop on timeout. */
10716 if (buf
[0] == '\0')
10717 error (_("Target does not support this command."));
10718 if (buf
[0] == 'O' && buf
[1] != 'K')
10720 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10723 if (strcmp (buf
, "OK") == 0)
10725 if (strlen (buf
) == 3 && buf
[0] == 'E'
10726 && isdigit (buf
[1]) && isdigit (buf
[2]))
10728 error (_("Protocol error with Rcmd"));
10730 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10732 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10734 fputc_unfiltered (c
, outbuf
);
10740 static VEC(mem_region_s
) *
10741 remote_memory_map (struct target_ops
*ops
)
10743 VEC(mem_region_s
) *result
= NULL
;
10744 char *text
= target_read_stralloc (¤t_target
,
10745 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10749 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10751 result
= parse_memory_map (text
);
10752 do_cleanups (back_to
);
10759 packet_command (char *args
, int from_tty
)
10761 struct remote_state
*rs
= get_remote_state ();
10763 if (!rs
->remote_desc
)
10764 error (_("command can only be used with remote target"));
10767 error (_("remote-packet command requires packet text as argument"));
10769 puts_filtered ("sending: ");
10770 print_packet (args
);
10771 puts_filtered ("\n");
10774 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10775 puts_filtered ("received: ");
10776 print_packet (rs
->buf
);
10777 puts_filtered ("\n");
10781 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10783 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10785 static void threadset_test_cmd (char *cmd
, int tty
);
10787 static void threadalive_test (char *cmd
, int tty
);
10789 static void threadlist_test_cmd (char *cmd
, int tty
);
10791 int get_and_display_threadinfo (threadref
*ref
);
10793 static void threadinfo_test_cmd (char *cmd
, int tty
);
10795 static int thread_display_step (threadref
*ref
, void *context
);
10797 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10799 static void init_remote_threadtests (void);
10801 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10804 threadset_test_cmd (char *cmd
, int tty
)
10806 int sample_thread
= SAMPLE_THREAD
;
10808 printf_filtered (_("Remote threadset test\n"));
10809 set_general_thread (sample_thread
);
10814 threadalive_test (char *cmd
, int tty
)
10816 int sample_thread
= SAMPLE_THREAD
;
10817 int pid
= ptid_get_pid (inferior_ptid
);
10818 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10820 if (remote_thread_alive (ptid
))
10821 printf_filtered ("PASS: Thread alive test\n");
10823 printf_filtered ("FAIL: Thread alive test\n");
10826 void output_threadid (char *title
, threadref
*ref
);
10829 output_threadid (char *title
, threadref
*ref
)
10833 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10835 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10839 threadlist_test_cmd (char *cmd
, int tty
)
10842 threadref nextthread
;
10843 int done
, result_count
;
10844 threadref threadlist
[3];
10846 printf_filtered ("Remote Threadlist test\n");
10847 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10848 &result_count
, &threadlist
[0]))
10849 printf_filtered ("FAIL: threadlist test\n");
10852 threadref
*scan
= threadlist
;
10853 threadref
*limit
= scan
+ result_count
;
10855 while (scan
< limit
)
10856 output_threadid (" thread ", scan
++);
10861 display_thread_info (struct gdb_ext_thread_info
*info
)
10863 output_threadid ("Threadid: ", &info
->threadid
);
10864 printf_filtered ("Name: %s\n ", info
->shortname
);
10865 printf_filtered ("State: %s\n", info
->display
);
10866 printf_filtered ("other: %s\n\n", info
->more_display
);
10870 get_and_display_threadinfo (threadref
*ref
)
10874 struct gdb_ext_thread_info threadinfo
;
10876 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10877 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10878 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10879 display_thread_info (&threadinfo
);
10884 threadinfo_test_cmd (char *cmd
, int tty
)
10886 int athread
= SAMPLE_THREAD
;
10890 int_to_threadref (&thread
, athread
);
10891 printf_filtered ("Remote Threadinfo test\n");
10892 if (!get_and_display_threadinfo (&thread
))
10893 printf_filtered ("FAIL cannot get thread info\n");
10897 thread_display_step (threadref
*ref
, void *context
)
10899 /* output_threadid(" threadstep ",ref); *//* simple test */
10900 return get_and_display_threadinfo (ref
);
10904 threadlist_update_test_cmd (char *cmd
, int tty
)
10906 printf_filtered ("Remote Threadlist update test\n");
10907 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10911 init_remote_threadtests (void)
10913 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10914 _("Fetch and print the remote list of "
10915 "thread identifiers, one pkt only"));
10916 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10917 _("Fetch and display info about one thread"));
10918 add_com ("tset", class_obscure
, threadset_test_cmd
,
10919 _("Test setting to a different thread"));
10920 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10921 _("Iterate through updating all remote thread info"));
10922 add_com ("talive", class_obscure
, threadalive_test
,
10923 _(" Remote thread alive test "));
10928 /* Convert a thread ID to a string. Returns the string in a static
10931 static const char *
10932 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10934 static char buf
[64];
10935 struct remote_state
*rs
= get_remote_state ();
10937 if (ptid_equal (ptid
, null_ptid
))
10938 return normal_pid_to_str (ptid
);
10939 else if (ptid_is_pid (ptid
))
10941 /* Printing an inferior target id. */
10943 /* When multi-process extensions are off, there's no way in the
10944 remote protocol to know the remote process id, if there's any
10945 at all. There's one exception --- when we're connected with
10946 target extended-remote, and we manually attached to a process
10947 with "attach PID". We don't record anywhere a flag that
10948 allows us to distinguish that case from the case of
10949 connecting with extended-remote and the stub already being
10950 attached to a process, and reporting yes to qAttached, hence
10951 no smart special casing here. */
10952 if (!remote_multi_process_p (rs
))
10954 xsnprintf (buf
, sizeof buf
, "Remote target");
10958 return normal_pid_to_str (ptid
);
10962 if (ptid_equal (magic_null_ptid
, ptid
))
10963 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10964 else if (remote_multi_process_p (rs
))
10965 if (ptid_get_lwp (ptid
) == 0)
10966 return normal_pid_to_str (ptid
);
10968 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10969 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10971 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10972 ptid_get_lwp (ptid
));
10977 /* Get the address of the thread local variable in OBJFILE which is
10978 stored at OFFSET within the thread local storage for thread PTID. */
10981 remote_get_thread_local_address (struct target_ops
*ops
,
10982 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10984 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10986 struct remote_state
*rs
= get_remote_state ();
10988 char *endp
= rs
->buf
+ get_remote_packet_size ();
10989 enum packet_result result
;
10991 strcpy (p
, "qGetTLSAddr:");
10993 p
= write_ptid (p
, endp
, ptid
);
10995 p
+= hexnumstr (p
, offset
);
10997 p
+= hexnumstr (p
, lm
);
11001 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11002 result
= packet_ok (rs
->buf
,
11003 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
11004 if (result
== PACKET_OK
)
11008 unpack_varlen_hex (rs
->buf
, &result
);
11011 else if (result
== PACKET_UNKNOWN
)
11012 throw_error (TLS_GENERIC_ERROR
,
11013 _("Remote target doesn't support qGetTLSAddr packet"));
11015 throw_error (TLS_GENERIC_ERROR
,
11016 _("Remote target failed to process qGetTLSAddr request"));
11019 throw_error (TLS_GENERIC_ERROR
,
11020 _("TLS not supported or disabled on this target"));
11025 /* Provide thread local base, i.e. Thread Information Block address.
11026 Returns 1 if ptid is found and thread_local_base is non zero. */
11029 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
11031 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
11033 struct remote_state
*rs
= get_remote_state ();
11035 char *endp
= rs
->buf
+ get_remote_packet_size ();
11036 enum packet_result result
;
11038 strcpy (p
, "qGetTIBAddr:");
11040 p
= write_ptid (p
, endp
, ptid
);
11044 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11045 result
= packet_ok (rs
->buf
,
11046 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
11047 if (result
== PACKET_OK
)
11051 unpack_varlen_hex (rs
->buf
, &result
);
11053 *addr
= (CORE_ADDR
) result
;
11056 else if (result
== PACKET_UNKNOWN
)
11057 error (_("Remote target doesn't support qGetTIBAddr packet"));
11059 error (_("Remote target failed to process qGetTIBAddr request"));
11062 error (_("qGetTIBAddr not supported or disabled on this target"));
11067 /* Support for inferring a target description based on the current
11068 architecture and the size of a 'g' packet. While the 'g' packet
11069 can have any size (since optional registers can be left off the
11070 end), some sizes are easily recognizable given knowledge of the
11071 approximate architecture. */
11073 struct remote_g_packet_guess
11076 const struct target_desc
*tdesc
;
11078 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
11079 DEF_VEC_O(remote_g_packet_guess_s
);
11081 struct remote_g_packet_data
11083 VEC(remote_g_packet_guess_s
) *guesses
;
11086 static struct gdbarch_data
*remote_g_packet_data_handle
;
11089 remote_g_packet_data_init (struct obstack
*obstack
)
11091 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
11095 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
11096 const struct target_desc
*tdesc
)
11098 struct remote_g_packet_data
*data
11099 = ((struct remote_g_packet_data
*)
11100 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
11101 struct remote_g_packet_guess new_guess
, *guess
;
11104 gdb_assert (tdesc
!= NULL
);
11107 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11109 if (guess
->bytes
== bytes
)
11110 internal_error (__FILE__
, __LINE__
,
11111 _("Duplicate g packet description added for size %d"),
11114 new_guess
.bytes
= bytes
;
11115 new_guess
.tdesc
= tdesc
;
11116 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
11119 /* Return 1 if remote_read_description would do anything on this target
11120 and architecture, 0 otherwise. */
11123 remote_read_description_p (struct target_ops
*target
)
11125 struct remote_g_packet_data
*data
11126 = ((struct remote_g_packet_data
*)
11127 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11129 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11135 static const struct target_desc
*
11136 remote_read_description (struct target_ops
*target
)
11138 struct remote_g_packet_data
*data
11139 = ((struct remote_g_packet_data
*)
11140 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11142 /* Do not try this during initial connection, when we do not know
11143 whether there is a running but stopped thread. */
11144 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
11145 return target
->beneath
->to_read_description (target
->beneath
);
11147 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11149 struct remote_g_packet_guess
*guess
;
11151 int bytes
= send_g_packet ();
11154 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11156 if (guess
->bytes
== bytes
)
11157 return guess
->tdesc
;
11159 /* We discard the g packet. A minor optimization would be to
11160 hold on to it, and fill the register cache once we have selected
11161 an architecture, but it's too tricky to do safely. */
11164 return target
->beneath
->to_read_description (target
->beneath
);
11167 /* Remote file transfer support. This is host-initiated I/O, not
11168 target-initiated; for target-initiated, see remote-fileio.c. */
11170 /* If *LEFT is at least the length of STRING, copy STRING to
11171 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11172 decrease *LEFT. Otherwise raise an error. */
11175 remote_buffer_add_string (char **buffer
, int *left
, const char *string
)
11177 int len
= strlen (string
);
11180 error (_("Packet too long for target."));
11182 memcpy (*buffer
, string
, len
);
11186 /* NUL-terminate the buffer as a convenience, if there is
11192 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
11193 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11194 decrease *LEFT. Otherwise raise an error. */
11197 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
11200 if (2 * len
> *left
)
11201 error (_("Packet too long for target."));
11203 bin2hex (bytes
, *buffer
, len
);
11204 *buffer
+= 2 * len
;
11207 /* NUL-terminate the buffer as a convenience, if there is
11213 /* If *LEFT is large enough, convert VALUE to hex and add it to
11214 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11215 decrease *LEFT. Otherwise raise an error. */
11218 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
11220 int len
= hexnumlen (value
);
11223 error (_("Packet too long for target."));
11225 hexnumstr (*buffer
, value
);
11229 /* NUL-terminate the buffer as a convenience, if there is
11235 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
11236 value, *REMOTE_ERRNO to the remote error number or zero if none
11237 was included, and *ATTACHMENT to point to the start of the annex
11238 if any. The length of the packet isn't needed here; there may
11239 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
11241 Return 0 if the packet could be parsed, -1 if it could not. If
11242 -1 is returned, the other variables may not be initialized. */
11245 remote_hostio_parse_result (char *buffer
, int *retcode
,
11246 int *remote_errno
, char **attachment
)
11251 *attachment
= NULL
;
11253 if (buffer
[0] != 'F')
11257 *retcode
= strtol (&buffer
[1], &p
, 16);
11258 if (errno
!= 0 || p
== &buffer
[1])
11261 /* Check for ",errno". */
11265 *remote_errno
= strtol (p
+ 1, &p2
, 16);
11266 if (errno
!= 0 || p
+ 1 == p2
)
11271 /* Check for ";attachment". If there is no attachment, the
11272 packet should end here. */
11275 *attachment
= p
+ 1;
11278 else if (*p
== '\0')
11284 /* Send a prepared I/O packet to the target and read its response.
11285 The prepared packet is in the global RS->BUF before this function
11286 is called, and the answer is there when we return.
11288 COMMAND_BYTES is the length of the request to send, which may include
11289 binary data. WHICH_PACKET is the packet configuration to check
11290 before attempting a packet. If an error occurs, *REMOTE_ERRNO
11291 is set to the error number and -1 is returned. Otherwise the value
11292 returned by the function is returned.
11294 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
11295 attachment is expected; an error will be reported if there's a
11296 mismatch. If one is found, *ATTACHMENT will be set to point into
11297 the packet buffer and *ATTACHMENT_LEN will be set to the
11298 attachment's length. */
11301 remote_hostio_send_command (int command_bytes
, int which_packet
,
11302 int *remote_errno
, char **attachment
,
11303 int *attachment_len
)
11305 struct remote_state
*rs
= get_remote_state ();
11306 int ret
, bytes_read
;
11307 char *attachment_tmp
;
11309 if (!rs
->remote_desc
11310 || packet_support (which_packet
) == PACKET_DISABLE
)
11312 *remote_errno
= FILEIO_ENOSYS
;
11316 putpkt_binary (rs
->buf
, command_bytes
);
11317 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
11319 /* If it timed out, something is wrong. Don't try to parse the
11321 if (bytes_read
< 0)
11323 *remote_errno
= FILEIO_EINVAL
;
11327 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
11330 *remote_errno
= FILEIO_EINVAL
;
11332 case PACKET_UNKNOWN
:
11333 *remote_errno
= FILEIO_ENOSYS
;
11339 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
11342 *remote_errno
= FILEIO_EINVAL
;
11346 /* Make sure we saw an attachment if and only if we expected one. */
11347 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
11348 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
11350 *remote_errno
= FILEIO_EINVAL
;
11354 /* If an attachment was found, it must point into the packet buffer;
11355 work out how many bytes there were. */
11356 if (attachment_tmp
!= NULL
)
11358 *attachment
= attachment_tmp
;
11359 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
11365 /* Invalidate the readahead cache. */
11368 readahead_cache_invalidate (void)
11370 struct remote_state
*rs
= get_remote_state ();
11372 rs
->readahead_cache
.fd
= -1;
11375 /* Invalidate the readahead cache if it is holding data for FD. */
11378 readahead_cache_invalidate_fd (int fd
)
11380 struct remote_state
*rs
= get_remote_state ();
11382 if (rs
->readahead_cache
.fd
== fd
)
11383 rs
->readahead_cache
.fd
= -1;
11386 /* Set the filesystem remote_hostio functions that take FILENAME
11387 arguments will use. Return 0 on success, or -1 if an error
11388 occurs (and set *REMOTE_ERRNO). */
11391 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
11393 struct remote_state
*rs
= get_remote_state ();
11394 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
11396 int left
= get_remote_packet_size () - 1;
11400 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11403 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11406 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11408 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11409 remote_buffer_add_string (&p
, &left
, arg
);
11411 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11412 remote_errno
, NULL
, NULL
);
11414 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11418 rs
->fs_pid
= required_pid
;
11423 /* Implementation of to_fileio_open. */
11426 remote_hostio_open (struct target_ops
*self
,
11427 struct inferior
*inf
, const char *filename
,
11428 int flags
, int mode
, int warn_if_slow
,
11431 struct remote_state
*rs
= get_remote_state ();
11433 int left
= get_remote_packet_size () - 1;
11437 static int warning_issued
= 0;
11439 printf_unfiltered (_("Reading %s from remote target...\n"),
11442 if (!warning_issued
)
11444 warning (_("File transfers from remote targets can be slow."
11445 " Use \"set sysroot\" to access files locally"
11447 warning_issued
= 1;
11451 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11454 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11456 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11457 strlen (filename
));
11458 remote_buffer_add_string (&p
, &left
, ",");
11460 remote_buffer_add_int (&p
, &left
, flags
);
11461 remote_buffer_add_string (&p
, &left
, ",");
11463 remote_buffer_add_int (&p
, &left
, mode
);
11465 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11466 remote_errno
, NULL
, NULL
);
11469 /* Implementation of to_fileio_pwrite. */
11472 remote_hostio_pwrite (struct target_ops
*self
,
11473 int fd
, const gdb_byte
*write_buf
, int len
,
11474 ULONGEST offset
, int *remote_errno
)
11476 struct remote_state
*rs
= get_remote_state ();
11478 int left
= get_remote_packet_size ();
11481 readahead_cache_invalidate_fd (fd
);
11483 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11485 remote_buffer_add_int (&p
, &left
, fd
);
11486 remote_buffer_add_string (&p
, &left
, ",");
11488 remote_buffer_add_int (&p
, &left
, offset
);
11489 remote_buffer_add_string (&p
, &left
, ",");
11491 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11492 get_remote_packet_size () - (p
- rs
->buf
));
11494 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11495 remote_errno
, NULL
, NULL
);
11498 /* Helper for the implementation of to_fileio_pread. Read the file
11499 from the remote side with vFile:pread. */
11502 remote_hostio_pread_vFile (struct target_ops
*self
,
11503 int fd
, gdb_byte
*read_buf
, int len
,
11504 ULONGEST offset
, int *remote_errno
)
11506 struct remote_state
*rs
= get_remote_state ();
11509 int left
= get_remote_packet_size ();
11510 int ret
, attachment_len
;
11513 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11515 remote_buffer_add_int (&p
, &left
, fd
);
11516 remote_buffer_add_string (&p
, &left
, ",");
11518 remote_buffer_add_int (&p
, &left
, len
);
11519 remote_buffer_add_string (&p
, &left
, ",");
11521 remote_buffer_add_int (&p
, &left
, offset
);
11523 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11524 remote_errno
, &attachment
,
11530 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11532 if (read_len
!= ret
)
11533 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11538 /* Serve pread from the readahead cache. Returns number of bytes
11539 read, or 0 if the request can't be served from the cache. */
11542 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11543 int fd
, gdb_byte
*read_buf
, size_t len
,
11546 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11548 if (cache
->fd
== fd
11549 && cache
->offset
<= offset
11550 && offset
< cache
->offset
+ cache
->bufsize
)
11552 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11554 if (offset
+ len
> max
)
11555 len
= max
- offset
;
11557 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11564 /* Implementation of to_fileio_pread. */
11567 remote_hostio_pread (struct target_ops
*self
,
11568 int fd
, gdb_byte
*read_buf
, int len
,
11569 ULONGEST offset
, int *remote_errno
)
11572 struct remote_state
*rs
= get_remote_state ();
11573 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11575 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11578 cache
->hit_count
++;
11581 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11582 pulongest (cache
->hit_count
));
11586 cache
->miss_count
++;
11588 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11589 pulongest (cache
->miss_count
));
11592 cache
->offset
= offset
;
11593 cache
->bufsize
= get_remote_packet_size ();
11594 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11596 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11597 cache
->offset
, remote_errno
);
11600 readahead_cache_invalidate_fd (fd
);
11604 cache
->bufsize
= ret
;
11605 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11608 /* Implementation of to_fileio_close. */
11611 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11613 struct remote_state
*rs
= get_remote_state ();
11615 int left
= get_remote_packet_size () - 1;
11617 readahead_cache_invalidate_fd (fd
);
11619 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11621 remote_buffer_add_int (&p
, &left
, fd
);
11623 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11624 remote_errno
, NULL
, NULL
);
11627 /* Implementation of to_fileio_unlink. */
11630 remote_hostio_unlink (struct target_ops
*self
,
11631 struct inferior
*inf
, const char *filename
,
11634 struct remote_state
*rs
= get_remote_state ();
11636 int left
= get_remote_packet_size () - 1;
11638 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11641 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11643 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11644 strlen (filename
));
11646 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11647 remote_errno
, NULL
, NULL
);
11650 /* Implementation of to_fileio_readlink. */
11653 remote_hostio_readlink (struct target_ops
*self
,
11654 struct inferior
*inf
, const char *filename
,
11657 struct remote_state
*rs
= get_remote_state ();
11660 int left
= get_remote_packet_size ();
11661 int len
, attachment_len
;
11665 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11668 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11670 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11671 strlen (filename
));
11673 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11674 remote_errno
, &attachment
,
11680 ret
= (char *) xmalloc (len
+ 1);
11682 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11683 (gdb_byte
*) ret
, len
);
11684 if (read_len
!= len
)
11685 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11691 /* Implementation of to_fileio_fstat. */
11694 remote_hostio_fstat (struct target_ops
*self
,
11695 int fd
, struct stat
*st
,
11698 struct remote_state
*rs
= get_remote_state ();
11700 int left
= get_remote_packet_size ();
11701 int attachment_len
, ret
;
11703 struct fio_stat fst
;
11706 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11708 remote_buffer_add_int (&p
, &left
, fd
);
11710 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11711 remote_errno
, &attachment
,
11715 if (*remote_errno
!= FILEIO_ENOSYS
)
11718 /* Strictly we should return -1, ENOSYS here, but when
11719 "set sysroot remote:" was implemented in August 2008
11720 BFD's need for a stat function was sidestepped with
11721 this hack. This was not remedied until March 2015
11722 so we retain the previous behavior to avoid breaking
11725 Note that the memset is a March 2015 addition; older
11726 GDBs set st_size *and nothing else* so the structure
11727 would have garbage in all other fields. This might
11728 break something but retaining the previous behavior
11729 here would be just too wrong. */
11731 memset (st
, 0, sizeof (struct stat
));
11732 st
->st_size
= INT_MAX
;
11736 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11737 (gdb_byte
*) &fst
, sizeof (fst
));
11739 if (read_len
!= ret
)
11740 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11742 if (read_len
!= sizeof (fst
))
11743 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11744 read_len
, (int) sizeof (fst
));
11746 remote_fileio_to_host_stat (&fst
, st
);
11751 /* Implementation of to_filesystem_is_local. */
11754 remote_filesystem_is_local (struct target_ops
*self
)
11756 /* Valgrind GDB presents itself as a remote target but works
11757 on the local filesystem: it does not implement remote get
11758 and users are not expected to set a sysroot. To handle
11759 this case we treat the remote filesystem as local if the
11760 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11761 does not support vFile:open. */
11762 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11764 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11766 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11768 int fd
, remote_errno
;
11770 /* Try opening a file to probe support. The supplied
11771 filename is irrelevant, we only care about whether
11772 the stub recognizes the packet or not. */
11773 fd
= remote_hostio_open (self
, NULL
, "just probing",
11774 FILEIO_O_RDONLY
, 0700, 0,
11778 remote_hostio_close (self
, fd
, &remote_errno
);
11780 ps
= packet_support (PACKET_vFile_open
);
11783 if (ps
== PACKET_DISABLE
)
11785 static int warning_issued
= 0;
11787 if (!warning_issued
)
11789 warning (_("remote target does not support file"
11790 " transfer, attempting to access files"
11791 " from local filesystem."));
11792 warning_issued
= 1;
11803 remote_fileio_errno_to_host (int errnum
)
11809 case FILEIO_ENOENT
:
11817 case FILEIO_EACCES
:
11819 case FILEIO_EFAULT
:
11823 case FILEIO_EEXIST
:
11825 case FILEIO_ENODEV
:
11827 case FILEIO_ENOTDIR
:
11829 case FILEIO_EISDIR
:
11831 case FILEIO_EINVAL
:
11833 case FILEIO_ENFILE
:
11835 case FILEIO_EMFILE
:
11839 case FILEIO_ENOSPC
:
11841 case FILEIO_ESPIPE
:
11845 case FILEIO_ENOSYS
:
11847 case FILEIO_ENAMETOOLONG
:
11848 return ENAMETOOLONG
;
11854 remote_hostio_error (int errnum
)
11856 int host_error
= remote_fileio_errno_to_host (errnum
);
11858 if (host_error
== -1)
11859 error (_("Unknown remote I/O error %d"), errnum
);
11861 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11865 remote_hostio_close_cleanup (void *opaque
)
11867 int fd
= *(int *) opaque
;
11870 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11874 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11876 struct cleanup
*back_to
, *close_cleanup
;
11877 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11879 int bytes_in_buffer
;
11882 struct remote_state
*rs
= get_remote_state ();
11884 if (!rs
->remote_desc
)
11885 error (_("command can only be used with remote target"));
11887 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "rb");
11889 perror_with_name (local_file
);
11891 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11892 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11894 0700, 0, &remote_errno
);
11896 remote_hostio_error (remote_errno
);
11898 /* Send up to this many bytes at once. They won't all fit in the
11899 remote packet limit, so we'll transfer slightly fewer. */
11900 io_size
= get_remote_packet_size ();
11901 buffer
= (gdb_byte
*) xmalloc (io_size
);
11902 back_to
= make_cleanup (xfree
, buffer
);
11904 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11906 bytes_in_buffer
= 0;
11909 while (bytes_in_buffer
|| !saw_eof
)
11913 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11914 io_size
- bytes_in_buffer
,
11918 if (ferror (file
.get ()))
11919 error (_("Error reading %s."), local_file
);
11922 /* EOF. Unless there is something still in the
11923 buffer from the last iteration, we are done. */
11925 if (bytes_in_buffer
== 0)
11933 bytes
+= bytes_in_buffer
;
11934 bytes_in_buffer
= 0;
11936 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11938 offset
, &remote_errno
);
11941 remote_hostio_error (remote_errno
);
11942 else if (retcode
== 0)
11943 error (_("Remote write of %d bytes returned 0!"), bytes
);
11944 else if (retcode
< bytes
)
11946 /* Short write. Save the rest of the read data for the next
11948 bytes_in_buffer
= bytes
- retcode
;
11949 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11955 discard_cleanups (close_cleanup
);
11956 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11957 remote_hostio_error (remote_errno
);
11960 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11961 do_cleanups (back_to
);
11965 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11967 struct cleanup
*back_to
, *close_cleanup
;
11968 int fd
, remote_errno
, bytes
, io_size
;
11971 struct remote_state
*rs
= get_remote_state ();
11973 if (!rs
->remote_desc
)
11974 error (_("command can only be used with remote target"));
11976 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11977 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11980 remote_hostio_error (remote_errno
);
11982 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "wb");
11984 perror_with_name (local_file
);
11986 /* Send up to this many bytes at once. They won't all fit in the
11987 remote packet limit, so we'll transfer slightly fewer. */
11988 io_size
= get_remote_packet_size ();
11989 buffer
= (gdb_byte
*) xmalloc (io_size
);
11990 back_to
= make_cleanup (xfree
, buffer
);
11992 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11997 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11998 fd
, buffer
, io_size
, offset
, &remote_errno
);
12000 /* Success, but no bytes, means end-of-file. */
12003 remote_hostio_error (remote_errno
);
12007 bytes
= fwrite (buffer
, 1, bytes
, file
.get ());
12009 perror_with_name (local_file
);
12012 discard_cleanups (close_cleanup
);
12013 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
12014 remote_hostio_error (remote_errno
);
12017 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
12018 do_cleanups (back_to
);
12022 remote_file_delete (const char *remote_file
, int from_tty
)
12024 int retcode
, remote_errno
;
12025 struct remote_state
*rs
= get_remote_state ();
12027 if (!rs
->remote_desc
)
12028 error (_("command can only be used with remote target"));
12030 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
12031 NULL
, remote_file
, &remote_errno
);
12033 remote_hostio_error (remote_errno
);
12036 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
12040 remote_put_command (char *args
, int from_tty
)
12043 error_no_arg (_("file to put"));
12045 gdb_argv
argv (args
);
12046 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12047 error (_("Invalid parameters to remote put"));
12049 remote_file_put (argv
[0], argv
[1], from_tty
);
12053 remote_get_command (char *args
, int from_tty
)
12056 error_no_arg (_("file to get"));
12058 gdb_argv
argv (args
);
12059 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12060 error (_("Invalid parameters to remote get"));
12062 remote_file_get (argv
[0], argv
[1], from_tty
);
12066 remote_delete_command (char *args
, int from_tty
)
12069 error_no_arg (_("file to delete"));
12071 gdb_argv
argv (args
);
12072 if (argv
[0] == NULL
|| argv
[1] != NULL
)
12073 error (_("Invalid parameters to remote delete"));
12075 remote_file_delete (argv
[0], from_tty
);
12079 remote_command (char *args
, int from_tty
)
12081 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
12085 remote_can_execute_reverse (struct target_ops
*self
)
12087 if (packet_support (PACKET_bs
) == PACKET_ENABLE
12088 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
12095 remote_supports_non_stop (struct target_ops
*self
)
12101 remote_supports_disable_randomization (struct target_ops
*self
)
12103 /* Only supported in extended mode. */
12108 remote_supports_multi_process (struct target_ops
*self
)
12110 struct remote_state
*rs
= get_remote_state ();
12112 return remote_multi_process_p (rs
);
12116 remote_supports_cond_tracepoints (void)
12118 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
12122 remote_supports_cond_breakpoints (struct target_ops
*self
)
12124 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
12128 remote_supports_fast_tracepoints (void)
12130 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
12134 remote_supports_static_tracepoints (void)
12136 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
12140 remote_supports_install_in_trace (void)
12142 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
12146 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
12148 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
12153 remote_supports_string_tracing (struct target_ops
*self
)
12155 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
12159 remote_can_run_breakpoint_commands (struct target_ops
*self
)
12161 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
12165 remote_trace_init (struct target_ops
*self
)
12168 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12169 if (strcmp (target_buf
, "OK") != 0)
12170 error (_("Target does not support this command."));
12173 static void free_actions_list (char **actions_list
);
12174 static void free_actions_list_cleanup_wrapper (void *);
12176 free_actions_list_cleanup_wrapper (void *al
)
12178 free_actions_list ((char **) al
);
12182 free_actions_list (char **actions_list
)
12186 if (actions_list
== 0)
12189 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
12190 xfree (actions_list
[ndx
]);
12192 xfree (actions_list
);
12195 /* Recursive routine to walk through command list including loops, and
12196 download packets for each command. */
12199 remote_download_command_source (int num
, ULONGEST addr
,
12200 struct command_line
*cmds
)
12202 struct remote_state
*rs
= get_remote_state ();
12203 struct command_line
*cmd
;
12205 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
12207 QUIT
; /* Allow user to bail out with ^C. */
12208 strcpy (rs
->buf
, "QTDPsrc:");
12209 encode_source_string (num
, addr
, "cmd", cmd
->line
,
12210 rs
->buf
+ strlen (rs
->buf
),
12211 rs
->buf_size
- strlen (rs
->buf
));
12213 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12214 if (strcmp (target_buf
, "OK"))
12215 warning (_("Target does not support source download."));
12217 if (cmd
->control_type
== while_control
12218 || cmd
->control_type
== while_stepping_control
)
12220 remote_download_command_source (num
, addr
, *cmd
->body_list
);
12222 QUIT
; /* Allow user to bail out with ^C. */
12223 strcpy (rs
->buf
, "QTDPsrc:");
12224 encode_source_string (num
, addr
, "cmd", "end",
12225 rs
->buf
+ strlen (rs
->buf
),
12226 rs
->buf_size
- strlen (rs
->buf
));
12228 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12229 if (strcmp (target_buf
, "OK"))
12230 warning (_("Target does not support source download."));
12236 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
12238 #define BUF_SIZE 2048
12242 char buf
[BUF_SIZE
];
12243 char **tdp_actions
;
12244 char **stepping_actions
;
12246 struct cleanup
*old_chain
= NULL
;
12248 struct breakpoint
*b
= loc
->owner
;
12249 struct tracepoint
*t
= (struct tracepoint
*) b
;
12251 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
12252 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
12254 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
12257 tpaddr
= loc
->address
;
12258 sprintf_vma (addrbuf
, tpaddr
);
12259 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
12260 addrbuf
, /* address */
12261 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
12262 t
->step_count
, t
->pass_count
);
12263 /* Fast tracepoints are mostly handled by the target, but we can
12264 tell the target how big of an instruction block should be moved
12266 if (b
->type
== bp_fast_tracepoint
)
12268 /* Only test for support at download time; we may not know
12269 target capabilities at definition time. */
12270 if (remote_supports_fast_tracepoints ())
12272 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
12274 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
12275 gdb_insn_length (loc
->gdbarch
, tpaddr
));
12277 /* If it passed validation at definition but fails now,
12278 something is very wrong. */
12279 internal_error (__FILE__
, __LINE__
,
12280 _("Fast tracepoint not "
12281 "valid during download"));
12284 /* Fast tracepoints are functionally identical to regular
12285 tracepoints, so don't take lack of support as a reason to
12286 give up on the trace run. */
12287 warning (_("Target does not support fast tracepoints, "
12288 "downloading %d as regular tracepoint"), b
->number
);
12290 else if (b
->type
== bp_static_tracepoint
)
12292 /* Only test for support at download time; we may not know
12293 target capabilities at definition time. */
12294 if (remote_supports_static_tracepoints ())
12296 struct static_tracepoint_marker marker
;
12298 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
12299 strcat (buf
, ":S");
12301 error (_("Static tracepoint not valid during download"));
12304 /* Fast tracepoints are functionally identical to regular
12305 tracepoints, so don't take lack of support as a reason
12306 to give up on the trace run. */
12307 error (_("Target does not support static tracepoints"));
12309 /* If the tracepoint has a conditional, make it into an agent
12310 expression and append to the definition. */
12313 /* Only test support at download time, we may not know target
12314 capabilities at definition time. */
12315 if (remote_supports_cond_tracepoints ())
12317 agent_expr_up aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
.get ());
12318 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
12320 pkt
= buf
+ strlen (buf
);
12321 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
12322 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
12326 warning (_("Target does not support conditional tracepoints, "
12327 "ignoring tp %d cond"), b
->number
);
12330 if (b
->commands
|| *default_collect
)
12333 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12334 if (strcmp (target_buf
, "OK"))
12335 error (_("Target does not support tracepoints."));
12337 /* do_single_steps (t); */
12340 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
12342 QUIT
; /* Allow user to bail out with ^C. */
12343 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
12344 b
->number
, addrbuf
, /* address */
12346 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
12349 remote_get_noisy_reply (&target_buf
,
12351 if (strcmp (target_buf
, "OK"))
12352 error (_("Error on target while setting tracepoints."));
12355 if (stepping_actions
)
12357 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
12359 QUIT
; /* Allow user to bail out with ^C. */
12360 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
12361 b
->number
, addrbuf
, /* address */
12362 ((ndx
== 0) ? "S" : ""),
12363 stepping_actions
[ndx
],
12364 (stepping_actions
[ndx
+ 1] ? "-" : ""));
12366 remote_get_noisy_reply (&target_buf
,
12368 if (strcmp (target_buf
, "OK"))
12369 error (_("Error on target while setting tracepoints."));
12373 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
12375 if (b
->location
!= NULL
)
12377 strcpy (buf
, "QTDPsrc:");
12378 encode_source_string (b
->number
, loc
->address
, "at",
12379 event_location_to_string (b
->location
.get ()),
12380 buf
+ strlen (buf
), 2048 - strlen (buf
));
12382 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12383 if (strcmp (target_buf
, "OK"))
12384 warning (_("Target does not support source download."));
12386 if (b
->cond_string
)
12388 strcpy (buf
, "QTDPsrc:");
12389 encode_source_string (b
->number
, loc
->address
,
12390 "cond", b
->cond_string
, buf
+ strlen (buf
),
12391 2048 - strlen (buf
));
12393 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12394 if (strcmp (target_buf
, "OK"))
12395 warning (_("Target does not support source download."));
12397 remote_download_command_source (b
->number
, loc
->address
,
12398 breakpoint_commands (b
));
12401 do_cleanups (old_chain
);
12405 remote_can_download_tracepoint (struct target_ops
*self
)
12407 struct remote_state
*rs
= get_remote_state ();
12408 struct trace_status
*ts
;
12411 /* Don't try to install tracepoints until we've relocated our
12412 symbols, and fetched and merged the target's tracepoint list with
12414 if (rs
->starting_up
)
12417 ts
= current_trace_status ();
12418 status
= remote_get_trace_status (self
, ts
);
12420 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12423 /* If we are in a tracing experiment, but remote stub doesn't support
12424 installing tracepoint in trace, we have to return. */
12425 if (!remote_supports_install_in_trace ())
12433 remote_download_trace_state_variable (struct target_ops
*self
,
12434 struct trace_state_variable
*tsv
)
12436 struct remote_state
*rs
= get_remote_state ();
12439 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12440 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12442 p
= rs
->buf
+ strlen (rs
->buf
);
12443 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12444 error (_("Trace state variable name too long for tsv definition packet"));
12445 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12448 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12449 if (*target_buf
== '\0')
12450 error (_("Target does not support this command."));
12451 if (strcmp (target_buf
, "OK") != 0)
12452 error (_("Error on target while downloading trace state variable."));
12456 remote_enable_tracepoint (struct target_ops
*self
,
12457 struct bp_location
*location
)
12459 struct remote_state
*rs
= get_remote_state ();
12462 sprintf_vma (addr_buf
, location
->address
);
12463 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12464 location
->owner
->number
, addr_buf
);
12466 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12467 if (*rs
->buf
== '\0')
12468 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12469 if (strcmp (rs
->buf
, "OK") != 0)
12470 error (_("Error on target while enabling tracepoint."));
12474 remote_disable_tracepoint (struct target_ops
*self
,
12475 struct bp_location
*location
)
12477 struct remote_state
*rs
= get_remote_state ();
12480 sprintf_vma (addr_buf
, location
->address
);
12481 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12482 location
->owner
->number
, addr_buf
);
12484 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12485 if (*rs
->buf
== '\0')
12486 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12487 if (strcmp (rs
->buf
, "OK") != 0)
12488 error (_("Error on target while disabling tracepoint."));
12492 remote_trace_set_readonly_regions (struct target_ops
*self
)
12496 bfd_size_type size
;
12502 return; /* No information to give. */
12504 strcpy (target_buf
, "QTro");
12505 offset
= strlen (target_buf
);
12506 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12508 char tmp1
[40], tmp2
[40];
12511 if ((s
->flags
& SEC_LOAD
) == 0 ||
12512 /* (s->flags & SEC_CODE) == 0 || */
12513 (s
->flags
& SEC_READONLY
) == 0)
12517 vma
= bfd_get_section_vma (abfd
, s
);
12518 size
= bfd_get_section_size (s
);
12519 sprintf_vma (tmp1
, vma
);
12520 sprintf_vma (tmp2
, vma
+ size
);
12521 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12522 if (offset
+ sec_length
+ 1 > target_buf_size
)
12524 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12526 Too many sections for read-only sections definition packet."));
12529 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12531 offset
+= sec_length
;
12535 putpkt (target_buf
);
12536 getpkt (&target_buf
, &target_buf_size
, 0);
12541 remote_trace_start (struct target_ops
*self
)
12543 putpkt ("QTStart");
12544 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12545 if (*target_buf
== '\0')
12546 error (_("Target does not support this command."));
12547 if (strcmp (target_buf
, "OK") != 0)
12548 error (_("Bogus reply from target: %s"), target_buf
);
12552 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12554 /* Initialize it just to avoid a GCC false warning. */
12556 /* FIXME we need to get register block size some other way. */
12557 extern int trace_regblock_size
;
12558 enum packet_result result
;
12560 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12563 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12565 putpkt ("qTStatus");
12569 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12571 CATCH (ex
, RETURN_MASK_ERROR
)
12573 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12575 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12578 throw_exception (ex
);
12582 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12584 /* If the remote target doesn't do tracing, flag it. */
12585 if (result
== PACKET_UNKNOWN
)
12588 /* We're working with a live target. */
12589 ts
->filename
= NULL
;
12592 error (_("Bogus trace status reply from target: %s"), target_buf
);
12594 /* Function 'parse_trace_status' sets default value of each field of
12595 'ts' at first, so we don't have to do it here. */
12596 parse_trace_status (p
, ts
);
12598 return ts
->running
;
12602 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12603 struct uploaded_tp
*utp
)
12605 struct remote_state
*rs
= get_remote_state ();
12607 struct bp_location
*loc
;
12608 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12609 size_t size
= get_remote_packet_size ();
12614 tp
->traceframe_usage
= 0;
12615 for (loc
= tp
->loc
; loc
; loc
= loc
->next
)
12617 /* If the tracepoint was never downloaded, don't go asking for
12619 if (tp
->number_on_target
== 0)
12621 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12622 phex_nz (loc
->address
, 0));
12624 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12625 if (reply
&& *reply
)
12628 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12634 utp
->hit_count
= 0;
12635 utp
->traceframe_usage
= 0;
12636 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12637 phex_nz (utp
->addr
, 0));
12639 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12640 if (reply
&& *reply
)
12643 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12649 remote_trace_stop (struct target_ops
*self
)
12652 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12653 if (*target_buf
== '\0')
12654 error (_("Target does not support this command."));
12655 if (strcmp (target_buf
, "OK") != 0)
12656 error (_("Bogus reply from target: %s"), target_buf
);
12660 remote_trace_find (struct target_ops
*self
,
12661 enum trace_find_type type
, int num
,
12662 CORE_ADDR addr1
, CORE_ADDR addr2
,
12665 struct remote_state
*rs
= get_remote_state ();
12666 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12668 int target_frameno
= -1, target_tracept
= -1;
12670 /* Lookups other than by absolute frame number depend on the current
12671 trace selected, so make sure it is correct on the remote end
12673 if (type
!= tfind_number
)
12674 set_remote_traceframe ();
12677 strcpy (p
, "QTFrame:");
12678 p
= strchr (p
, '\0');
12682 xsnprintf (p
, endbuf
- p
, "%x", num
);
12685 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12688 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12691 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12692 phex_nz (addr2
, 0));
12694 case tfind_outside
:
12695 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12696 phex_nz (addr2
, 0));
12699 error (_("Unknown trace find type %d"), type
);
12703 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12704 if (*reply
== '\0')
12705 error (_("Target does not support this command."));
12707 while (reply
&& *reply
)
12712 target_frameno
= (int) strtol (p
, &reply
, 16);
12714 error (_("Unable to parse trace frame number"));
12715 /* Don't update our remote traceframe number cache on failure
12716 to select a remote traceframe. */
12717 if (target_frameno
== -1)
12722 target_tracept
= (int) strtol (p
, &reply
, 16);
12724 error (_("Unable to parse tracepoint number"));
12726 case 'O': /* "OK"? */
12727 if (reply
[1] == 'K' && reply
[2] == '\0')
12730 error (_("Bogus reply from target: %s"), reply
);
12733 error (_("Bogus reply from target: %s"), reply
);
12736 *tpp
= target_tracept
;
12738 rs
->remote_traceframe_number
= target_frameno
;
12739 return target_frameno
;
12743 remote_get_trace_state_variable_value (struct target_ops
*self
,
12744 int tsvnum
, LONGEST
*val
)
12746 struct remote_state
*rs
= get_remote_state ();
12750 set_remote_traceframe ();
12752 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12754 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12755 if (reply
&& *reply
)
12759 unpack_varlen_hex (reply
+ 1, &uval
);
12760 *val
= (LONGEST
) uval
;
12768 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12770 struct remote_state
*rs
= get_remote_state ();
12774 strcpy (p
, "QTSave:");
12776 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12777 error (_("Remote file name too long for trace save packet"));
12778 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12781 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12782 if (*reply
== '\0')
12783 error (_("Target does not support this command."));
12784 if (strcmp (reply
, "OK") != 0)
12785 error (_("Bogus reply from target: %s"), reply
);
12789 /* This is basically a memory transfer, but needs to be its own packet
12790 because we don't know how the target actually organizes its trace
12791 memory, plus we want to be able to ask for as much as possible, but
12792 not be unhappy if we don't get as much as we ask for. */
12795 remote_get_raw_trace_data (struct target_ops
*self
,
12796 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12798 struct remote_state
*rs
= get_remote_state ();
12804 strcpy (p
, "qTBuffer:");
12806 p
+= hexnumstr (p
, offset
);
12808 p
+= hexnumstr (p
, len
);
12812 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12813 if (reply
&& *reply
)
12815 /* 'l' by itself means we're at the end of the buffer and
12816 there is nothing more to get. */
12820 /* Convert the reply into binary. Limit the number of bytes to
12821 convert according to our passed-in buffer size, rather than
12822 what was returned in the packet; if the target is
12823 unexpectedly generous and gives us a bigger reply than we
12824 asked for, we don't want to crash. */
12825 rslt
= hex2bin (target_buf
, buf
, len
);
12829 /* Something went wrong, flag as an error. */
12834 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12836 struct remote_state
*rs
= get_remote_state ();
12838 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12842 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12844 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12845 if (*reply
== '\0')
12846 error (_("Target does not support this command."));
12847 if (strcmp (reply
, "OK") != 0)
12848 error (_("Bogus reply from target: %s"), reply
);
12851 warning (_("Target does not support disconnected tracing."));
12855 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12857 struct thread_info
*info
= find_thread_ptid (ptid
);
12859 if (info
&& info
->priv
)
12860 return info
->priv
->core
;
12865 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12867 struct remote_state
*rs
= get_remote_state ();
12870 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12872 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12873 if (*reply
== '\0')
12874 error (_("Target does not support this command."));
12875 if (strcmp (reply
, "OK") != 0)
12876 error (_("Bogus reply from target: %s"), reply
);
12879 static struct traceframe_info
*
12880 remote_traceframe_info (struct target_ops
*self
)
12884 text
= target_read_stralloc (¤t_target
,
12885 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12888 struct traceframe_info
*info
;
12889 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12891 info
= parse_traceframe_info (text
);
12892 do_cleanups (back_to
);
12899 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12900 instruction on which a fast tracepoint may be placed. Returns -1
12901 if the packet is not supported, and 0 if the minimum instruction
12902 length is unknown. */
12905 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12907 struct remote_state
*rs
= get_remote_state ();
12910 /* If we're not debugging a process yet, the IPA can't be
12912 if (!target_has_execution
)
12915 /* Make sure the remote is pointing at the right process. */
12916 set_general_process ();
12918 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12920 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12921 if (*reply
== '\0')
12925 ULONGEST min_insn_len
;
12927 unpack_varlen_hex (reply
, &min_insn_len
);
12929 return (int) min_insn_len
;
12934 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12936 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12938 struct remote_state
*rs
= get_remote_state ();
12939 char *buf
= rs
->buf
;
12940 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12941 enum packet_result result
;
12943 gdb_assert (val
>= 0 || val
== -1);
12944 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12945 /* Send -1 as literal "-1" to avoid host size dependency. */
12949 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12952 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12955 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12956 result
= packet_ok (rs
->buf
,
12957 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12959 if (result
!= PACKET_OK
)
12960 warning (_("Bogus reply from target: %s"), rs
->buf
);
12965 remote_set_trace_notes (struct target_ops
*self
,
12966 const char *user
, const char *notes
,
12967 const char *stop_notes
)
12969 struct remote_state
*rs
= get_remote_state ();
12971 char *buf
= rs
->buf
;
12972 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12975 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12978 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12979 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12985 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12986 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12992 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12993 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12997 /* Ensure the buffer is terminated. */
13001 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
13002 if (*reply
== '\0')
13005 if (strcmp (reply
, "OK") != 0)
13006 error (_("Bogus reply from target: %s"), reply
);
13012 remote_use_agent (struct target_ops
*self
, int use
)
13014 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
13016 struct remote_state
*rs
= get_remote_state ();
13018 /* If the stub supports QAgent. */
13019 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
13021 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13023 if (strcmp (rs
->buf
, "OK") == 0)
13034 remote_can_use_agent (struct target_ops
*self
)
13036 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
13039 struct btrace_target_info
13041 /* The ptid of the traced thread. */
13044 /* The obtained branch trace configuration. */
13045 struct btrace_config conf
;
13048 /* Reset our idea of our target's btrace configuration. */
13051 remote_btrace_reset (void)
13053 struct remote_state
*rs
= get_remote_state ();
13055 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
13058 /* Check whether the target supports branch tracing. */
13061 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
13063 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
13065 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
13070 case BTRACE_FORMAT_NONE
:
13073 case BTRACE_FORMAT_BTS
:
13074 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
13076 case BTRACE_FORMAT_PT
:
13077 /* The trace is decoded on the host. Even if our target supports it,
13078 we still need to have libipt to decode the trace. */
13079 #if defined (HAVE_LIBIPT)
13080 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
13081 #else /* !defined (HAVE_LIBIPT) */
13083 #endif /* !defined (HAVE_LIBIPT) */
13086 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
13089 /* Synchronize the configuration with the target. */
13092 btrace_sync_conf (const struct btrace_config
*conf
)
13094 struct packet_config
*packet
;
13095 struct remote_state
*rs
;
13096 char *buf
, *pos
, *endbuf
;
13098 rs
= get_remote_state ();
13100 endbuf
= buf
+ get_remote_packet_size ();
13102 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
13103 if (packet_config_support (packet
) == PACKET_ENABLE
13104 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
13107 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13111 getpkt (&buf
, &rs
->buf_size
, 0);
13113 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13115 if (buf
[0] == 'E' && buf
[1] == '.')
13116 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
13118 error (_("Failed to configure the BTS buffer size."));
13121 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
13124 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
13125 if (packet_config_support (packet
) == PACKET_ENABLE
13126 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
13129 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13133 getpkt (&buf
, &rs
->buf_size
, 0);
13135 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13137 if (buf
[0] == 'E' && buf
[1] == '.')
13138 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
13140 error (_("Failed to configure the trace buffer size."));
13143 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
13147 /* Read the current thread's btrace configuration from the target and
13148 store it into CONF. */
13151 btrace_read_config (struct btrace_config
*conf
)
13155 xml
= target_read_stralloc (¤t_target
,
13156 TARGET_OBJECT_BTRACE_CONF
, "");
13159 struct cleanup
*cleanup
;
13161 cleanup
= make_cleanup (xfree
, xml
);
13162 parse_xml_btrace_conf (conf
, xml
);
13163 do_cleanups (cleanup
);
13167 /* Maybe reopen target btrace. */
13170 remote_btrace_maybe_reopen (void)
13172 struct remote_state
*rs
= get_remote_state ();
13173 struct thread_info
*tp
;
13174 int btrace_target_pushed
= 0;
13177 scoped_restore_current_thread restore_thread
;
13179 ALL_NON_EXITED_THREADS (tp
)
13181 set_general_thread (tp
->ptid
);
13183 memset (&rs
->btrace_config
, 0x00, sizeof (struct btrace_config
));
13184 btrace_read_config (&rs
->btrace_config
);
13186 if (rs
->btrace_config
.format
== BTRACE_FORMAT_NONE
)
13189 #if !defined (HAVE_LIBIPT)
13190 if (rs
->btrace_config
.format
== BTRACE_FORMAT_PT
)
13195 warning (_("GDB does not support Intel Processor Trace. "
13196 "\"record\" will not work in this session."));
13201 #endif /* !defined (HAVE_LIBIPT) */
13203 /* Push target, once, but before anything else happens. This way our
13204 changes to the threads will be cleaned up by unpushing the target
13205 in case btrace_read_config () throws. */
13206 if (!btrace_target_pushed
)
13208 btrace_target_pushed
= 1;
13209 record_btrace_push_target ();
13210 printf_filtered (_("Target is recording using %s.\n"),
13211 btrace_format_string (rs
->btrace_config
.format
));
13214 tp
->btrace
.target
= XCNEW (struct btrace_target_info
);
13215 tp
->btrace
.target
->ptid
= tp
->ptid
;
13216 tp
->btrace
.target
->conf
= rs
->btrace_config
;
13220 /* Enable branch tracing. */
13222 static struct btrace_target_info
*
13223 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
13224 const struct btrace_config
*conf
)
13226 struct btrace_target_info
*tinfo
= NULL
;
13227 struct packet_config
*packet
= NULL
;
13228 struct remote_state
*rs
= get_remote_state ();
13229 char *buf
= rs
->buf
;
13230 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13232 switch (conf
->format
)
13234 case BTRACE_FORMAT_BTS
:
13235 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
13238 case BTRACE_FORMAT_PT
:
13239 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
13243 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
13244 error (_("Target does not support branch tracing."));
13246 btrace_sync_conf (conf
);
13248 set_general_thread (ptid
);
13250 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13252 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13254 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13256 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13257 error (_("Could not enable branch tracing for %s: %s"),
13258 target_pid_to_str (ptid
), rs
->buf
+ 2);
13260 error (_("Could not enable branch tracing for %s."),
13261 target_pid_to_str (ptid
));
13264 tinfo
= XCNEW (struct btrace_target_info
);
13265 tinfo
->ptid
= ptid
;
13267 /* If we fail to read the configuration, we lose some information, but the
13268 tracing itself is not impacted. */
13271 btrace_read_config (&tinfo
->conf
);
13273 CATCH (err
, RETURN_MASK_ERROR
)
13275 if (err
.message
!= NULL
)
13276 warning ("%s", err
.message
);
13283 /* Disable branch tracing. */
13286 remote_disable_btrace (struct target_ops
*self
,
13287 struct btrace_target_info
*tinfo
)
13289 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
13290 struct remote_state
*rs
= get_remote_state ();
13291 char *buf
= rs
->buf
;
13292 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13294 if (packet_config_support (packet
) != PACKET_ENABLE
)
13295 error (_("Target does not support branch tracing."));
13297 set_general_thread (tinfo
->ptid
);
13299 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13301 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13303 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13305 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13306 error (_("Could not disable branch tracing for %s: %s"),
13307 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
13309 error (_("Could not disable branch tracing for %s."),
13310 target_pid_to_str (tinfo
->ptid
));
13316 /* Teardown branch tracing. */
13319 remote_teardown_btrace (struct target_ops
*self
,
13320 struct btrace_target_info
*tinfo
)
13322 /* We must not talk to the target during teardown. */
13326 /* Read the branch trace. */
13328 static enum btrace_error
13329 remote_read_btrace (struct target_ops
*self
,
13330 struct btrace_data
*btrace
,
13331 struct btrace_target_info
*tinfo
,
13332 enum btrace_read_type type
)
13334 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
13335 struct cleanup
*cleanup
;
13339 if (packet_config_support (packet
) != PACKET_ENABLE
)
13340 error (_("Target does not support branch tracing."));
13342 #if !defined(HAVE_LIBEXPAT)
13343 error (_("Cannot process branch tracing result. XML parsing not supported."));
13348 case BTRACE_READ_ALL
:
13351 case BTRACE_READ_NEW
:
13354 case BTRACE_READ_DELTA
:
13358 internal_error (__FILE__
, __LINE__
,
13359 _("Bad branch tracing read type: %u."),
13360 (unsigned int) type
);
13363 xml
= target_read_stralloc (¤t_target
,
13364 TARGET_OBJECT_BTRACE
, annex
);
13366 return BTRACE_ERR_UNKNOWN
;
13368 cleanup
= make_cleanup (xfree
, xml
);
13369 parse_xml_btrace (btrace
, xml
);
13370 do_cleanups (cleanup
);
13372 return BTRACE_ERR_NONE
;
13375 static const struct btrace_config
*
13376 remote_btrace_conf (struct target_ops
*self
,
13377 const struct btrace_target_info
*tinfo
)
13379 return &tinfo
->conf
;
13383 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
13385 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
13389 /* Implementation of to_load. */
13392 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
13394 generic_load (name
, from_tty
);
13397 /* Accepts an integer PID; returns a string representing a file that
13398 can be opened on the remote side to get the symbols for the child
13399 process. Returns NULL if the operation is not supported. */
13402 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
13404 static char *filename
= NULL
;
13405 struct inferior
*inf
;
13406 char *annex
= NULL
;
13408 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
13411 if (filename
!= NULL
)
13414 inf
= find_inferior_pid (pid
);
13416 internal_error (__FILE__
, __LINE__
,
13417 _("not currently attached to process %d"), pid
);
13419 if (!inf
->fake_pid_p
)
13421 const int annex_size
= 9;
13423 annex
= (char *) alloca (annex_size
);
13424 xsnprintf (annex
, annex_size
, "%x", pid
);
13427 filename
= target_read_stralloc (¤t_target
,
13428 TARGET_OBJECT_EXEC_FILE
, annex
);
13433 /* Implement the to_can_do_single_step target_ops method. */
13436 remote_can_do_single_step (struct target_ops
*ops
)
13438 /* We can only tell whether target supports single step or not by
13439 supported s and S vCont actions if the stub supports vContSupported
13440 feature. If the stub doesn't support vContSupported feature,
13441 we have conservatively to think target doesn't supports single
13443 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13445 struct remote_state
*rs
= get_remote_state ();
13447 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13448 remote_vcont_probe (rs
);
13450 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13456 /* Implementation of the to_execution_direction method for the remote
13459 static enum exec_direction_kind
13460 remote_execution_direction (struct target_ops
*self
)
13462 struct remote_state
*rs
= get_remote_state ();
13464 return rs
->last_resume_exec_dir
;
13468 init_remote_ops (void)
13470 remote_ops
.to_shortname
= "remote";
13471 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13472 remote_ops
.to_doc
=
13473 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13474 Specify the serial device it is connected to\n\
13475 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13476 remote_ops
.to_open
= remote_open
;
13477 remote_ops
.to_close
= remote_close
;
13478 remote_ops
.to_detach
= remote_detach
;
13479 remote_ops
.to_disconnect
= remote_disconnect
;
13480 remote_ops
.to_resume
= remote_resume
;
13481 remote_ops
.to_commit_resume
= remote_commit_resume
;
13482 remote_ops
.to_wait
= remote_wait
;
13483 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13484 remote_ops
.to_store_registers
= remote_store_registers
;
13485 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13486 remote_ops
.to_files_info
= remote_files_info
;
13487 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13488 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13489 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13490 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13491 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13492 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13493 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13494 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13495 remote_ops
.to_watchpoint_addr_within_range
=
13496 remote_watchpoint_addr_within_range
;
13497 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13498 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13499 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13500 remote_ops
.to_region_ok_for_hw_watchpoint
13501 = remote_region_ok_for_hw_watchpoint
;
13502 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13503 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13504 remote_ops
.to_kill
= remote_kill
;
13505 remote_ops
.to_load
= remote_load
;
13506 remote_ops
.to_mourn_inferior
= remote_mourn
;
13507 remote_ops
.to_pass_signals
= remote_pass_signals
;
13508 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13509 remote_ops
.to_program_signals
= remote_program_signals
;
13510 remote_ops
.to_thread_alive
= remote_thread_alive
;
13511 remote_ops
.to_thread_name
= remote_thread_name
;
13512 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13513 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13514 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13515 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13516 remote_ops
.to_stop
= remote_stop
;
13517 remote_ops
.to_interrupt
= remote_interrupt
;
13518 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13519 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13520 remote_ops
.to_get_memory_xfer_limit
= remote_get_memory_xfer_limit
;
13521 remote_ops
.to_rcmd
= remote_rcmd
;
13522 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13523 remote_ops
.to_log_command
= serial_log_command
;
13524 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13525 remote_ops
.to_stratum
= process_stratum
;
13526 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13527 remote_ops
.to_has_memory
= default_child_has_memory
;
13528 remote_ops
.to_has_stack
= default_child_has_stack
;
13529 remote_ops
.to_has_registers
= default_child_has_registers
;
13530 remote_ops
.to_has_execution
= default_child_has_execution
;
13531 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13532 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13533 remote_ops
.to_magic
= OPS_MAGIC
;
13534 remote_ops
.to_memory_map
= remote_memory_map
;
13535 remote_ops
.to_flash_erase
= remote_flash_erase
;
13536 remote_ops
.to_flash_done
= remote_flash_done
;
13537 remote_ops
.to_read_description
= remote_read_description
;
13538 remote_ops
.to_search_memory
= remote_search_memory
;
13539 remote_ops
.to_can_async_p
= remote_can_async_p
;
13540 remote_ops
.to_is_async_p
= remote_is_async_p
;
13541 remote_ops
.to_async
= remote_async
;
13542 remote_ops
.to_thread_events
= remote_thread_events
;
13543 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13544 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13545 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13546 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13547 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13548 remote_ops
.to_supports_disable_randomization
13549 = remote_supports_disable_randomization
;
13550 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13551 remote_ops
.to_fileio_open
= remote_hostio_open
;
13552 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13553 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13554 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13555 remote_ops
.to_fileio_close
= remote_hostio_close
;
13556 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13557 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13558 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13559 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13560 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13561 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13562 remote_ops
.to_trace_init
= remote_trace_init
;
13563 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13564 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13565 remote_ops
.to_download_trace_state_variable
13566 = remote_download_trace_state_variable
;
13567 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13568 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13569 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13570 remote_ops
.to_trace_start
= remote_trace_start
;
13571 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13572 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13573 remote_ops
.to_trace_stop
= remote_trace_stop
;
13574 remote_ops
.to_trace_find
= remote_trace_find
;
13575 remote_ops
.to_get_trace_state_variable_value
13576 = remote_get_trace_state_variable_value
;
13577 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13578 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13579 remote_ops
.to_upload_trace_state_variables
13580 = remote_upload_trace_state_variables
;
13581 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13582 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13583 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13584 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13585 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13586 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13587 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13588 remote_ops
.to_verify_memory
= remote_verify_memory
;
13589 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13590 remote_ops
.to_set_permissions
= remote_set_permissions
;
13591 remote_ops
.to_static_tracepoint_marker_at
13592 = remote_static_tracepoint_marker_at
;
13593 remote_ops
.to_static_tracepoint_markers_by_strid
13594 = remote_static_tracepoint_markers_by_strid
;
13595 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13596 remote_ops
.to_use_agent
= remote_use_agent
;
13597 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13598 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13599 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13600 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13601 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13602 remote_ops
.to_read_btrace
= remote_read_btrace
;
13603 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13604 remote_ops
.to_augmented_libraries_svr4_read
=
13605 remote_augmented_libraries_svr4_read
;
13606 remote_ops
.to_follow_fork
= remote_follow_fork
;
13607 remote_ops
.to_follow_exec
= remote_follow_exec
;
13608 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13609 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13610 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13611 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13612 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13613 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13614 remote_ops
.to_execution_direction
= remote_execution_direction
;
13617 /* Set up the extended remote vector by making a copy of the standard
13618 remote vector and adding to it. */
13621 init_extended_remote_ops (void)
13623 extended_remote_ops
= remote_ops
;
13625 extended_remote_ops
.to_shortname
= "extended-remote";
13626 extended_remote_ops
.to_longname
=
13627 "Extended remote serial target in gdb-specific protocol";
13628 extended_remote_ops
.to_doc
=
13629 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13630 Specify the serial device it is connected to (e.g. /dev/ttya).";
13631 extended_remote_ops
.to_open
= extended_remote_open
;
13632 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13633 extended_remote_ops
.to_detach
= extended_remote_detach
;
13634 extended_remote_ops
.to_attach
= extended_remote_attach
;
13635 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13636 extended_remote_ops
.to_supports_disable_randomization
13637 = extended_remote_supports_disable_randomization
;
13641 remote_can_async_p (struct target_ops
*ops
)
13643 struct remote_state
*rs
= get_remote_state ();
13645 /* We don't go async if the user has explicitly prevented it with the
13646 "maint set target-async" command. */
13647 if (!target_async_permitted
)
13650 /* We're async whenever the serial device is. */
13651 return serial_can_async_p (rs
->remote_desc
);
13655 remote_is_async_p (struct target_ops
*ops
)
13657 struct remote_state
*rs
= get_remote_state ();
13659 if (!target_async_permitted
)
13660 /* We only enable async when the user specifically asks for it. */
13663 /* We're async whenever the serial device is. */
13664 return serial_is_async_p (rs
->remote_desc
);
13667 /* Pass the SERIAL event on and up to the client. One day this code
13668 will be able to delay notifying the client of an event until the
13669 point where an entire packet has been received. */
13671 static serial_event_ftype remote_async_serial_handler
;
13674 remote_async_serial_handler (struct serial
*scb
, void *context
)
13676 /* Don't propogate error information up to the client. Instead let
13677 the client find out about the error by querying the target. */
13678 inferior_event_handler (INF_REG_EVENT
, NULL
);
13682 remote_async_inferior_event_handler (gdb_client_data data
)
13684 inferior_event_handler (INF_REG_EVENT
, NULL
);
13688 remote_async (struct target_ops
*ops
, int enable
)
13690 struct remote_state
*rs
= get_remote_state ();
13694 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13696 /* If there are pending events in the stop reply queue tell the
13697 event loop to process them. */
13698 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13699 mark_async_event_handler (remote_async_inferior_event_token
);
13700 /* For simplicity, below we clear the pending events token
13701 without remembering whether it is marked, so here we always
13702 mark it. If there's actually no pending notification to
13703 process, this ends up being a no-op (other than a spurious
13704 event-loop wakeup). */
13705 if (target_is_non_stop_p ())
13706 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13710 serial_async (rs
->remote_desc
, NULL
, NULL
);
13711 /* If the core is disabling async, it doesn't want to be
13712 disturbed with target events. Clear all async event sources
13714 clear_async_event_handler (remote_async_inferior_event_token
);
13715 if (target_is_non_stop_p ())
13716 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13720 /* Implementation of the to_thread_events method. */
13723 remote_thread_events (struct target_ops
*ops
, int enable
)
13725 struct remote_state
*rs
= get_remote_state ();
13726 size_t size
= get_remote_packet_size ();
13728 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13731 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13733 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13735 switch (packet_ok (rs
->buf
,
13736 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13739 if (strcmp (rs
->buf
, "OK") != 0)
13740 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13743 warning (_("Remote failure reply: %s"), rs
->buf
);
13745 case PACKET_UNKNOWN
:
13751 set_remote_cmd (char *args
, int from_tty
)
13753 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13757 show_remote_cmd (char *args
, int from_tty
)
13759 /* We can't just use cmd_show_list here, because we want to skip
13760 the redundant "show remote Z-packet" and the legacy aliases. */
13761 struct cmd_list_element
*list
= remote_show_cmdlist
;
13762 struct ui_out
*uiout
= current_uiout
;
13764 ui_out_emit_tuple
tuple_emitter (uiout
, "showlist");
13765 for (; list
!= NULL
; list
= list
->next
)
13766 if (strcmp (list
->name
, "Z-packet") == 0)
13768 else if (list
->type
== not_set_cmd
)
13769 /* Alias commands are exactly like the original, except they
13770 don't have the normal type. */
13774 ui_out_emit_tuple
option_emitter (uiout
, "option");
13776 uiout
->field_string ("name", list
->name
);
13777 uiout
->text (": ");
13778 if (list
->type
== show_cmd
)
13779 do_show_command (NULL
, from_tty
, list
);
13781 cmd_func (list
, NULL
, from_tty
);
13786 /* Function to be called whenever a new objfile (shlib) is detected. */
13788 remote_new_objfile (struct objfile
*objfile
)
13790 struct remote_state
*rs
= get_remote_state ();
13792 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13793 remote_check_symbols ();
13796 /* Pull all the tracepoints defined on the target and create local
13797 data structures representing them. We don't want to create real
13798 tracepoints yet, we don't want to mess up the user's existing
13802 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13804 struct remote_state
*rs
= get_remote_state ();
13807 /* Ask for a first packet of tracepoint definition. */
13809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13811 while (*p
&& *p
!= 'l')
13813 parse_tracepoint_definition (p
, utpp
);
13814 /* Ask for another packet of tracepoint definition. */
13816 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13823 remote_upload_trace_state_variables (struct target_ops
*self
,
13824 struct uploaded_tsv
**utsvp
)
13826 struct remote_state
*rs
= get_remote_state ();
13829 /* Ask for a first packet of variable definition. */
13831 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13833 while (*p
&& *p
!= 'l')
13835 parse_tsv_definition (p
, utsvp
);
13836 /* Ask for another packet of variable definition. */
13838 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13844 /* The "set/show range-stepping" show hook. */
13847 show_range_stepping (struct ui_file
*file
, int from_tty
,
13848 struct cmd_list_element
*c
,
13851 fprintf_filtered (file
,
13852 _("Debugger's willingness to use range stepping "
13853 "is %s.\n"), value
);
13856 /* The "set/show range-stepping" set hook. */
13859 set_range_stepping (char *ignore_args
, int from_tty
,
13860 struct cmd_list_element
*c
)
13862 struct remote_state
*rs
= get_remote_state ();
13864 /* Whene enabling, check whether range stepping is actually
13865 supported by the target, and warn if not. */
13866 if (use_range_stepping
)
13868 if (rs
->remote_desc
!= NULL
)
13870 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13871 remote_vcont_probe (rs
);
13873 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13874 && rs
->supports_vCont
.r
)
13878 warning (_("Range stepping is not supported by the current target"));
13883 _initialize_remote (void)
13885 struct cmd_list_element
*cmd
;
13886 const char *cmd_name
;
13888 /* architecture specific data */
13889 remote_gdbarch_data_handle
=
13890 gdbarch_data_register_post_init (init_remote_state
);
13891 remote_g_packet_data_handle
=
13892 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13895 = register_program_space_data_with_cleanup (NULL
,
13896 remote_pspace_data_cleanup
);
13898 /* Initialize the per-target state. At the moment there is only one
13899 of these, not one per target. Only one target is active at a
13901 remote_state
= new_remote_state ();
13903 init_remote_ops ();
13904 add_target (&remote_ops
);
13906 init_extended_remote_ops ();
13907 add_target (&extended_remote_ops
);
13909 /* Hook into new objfile notification. */
13910 observer_attach_new_objfile (remote_new_objfile
);
13911 /* We're no longer interested in notification events of an inferior
13913 observer_attach_inferior_exit (discard_pending_stop_replies
);
13916 init_remote_threadtests ();
13919 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13920 /* set/show remote ... */
13922 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13923 Remote protocol specific variables\n\
13924 Configure various remote-protocol specific variables such as\n\
13925 the packets being used"),
13926 &remote_set_cmdlist
, "set remote ",
13927 0 /* allow-unknown */, &setlist
);
13928 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13929 Remote protocol specific variables\n\
13930 Configure various remote-protocol specific variables such as\n\
13931 the packets being used"),
13932 &remote_show_cmdlist
, "show remote ",
13933 0 /* allow-unknown */, &showlist
);
13935 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13936 Compare section data on target to the exec file.\n\
13937 Argument is a single section name (default: all loaded sections).\n\
13938 To compare only read-only loaded sections, specify the -r option."),
13941 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13942 Send an arbitrary packet to a remote target.\n\
13943 maintenance packet TEXT\n\
13944 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13945 this command sends the string TEXT to the inferior, and displays the\n\
13946 response packet. GDB supplies the initial `$' character, and the\n\
13947 terminating `#' character and checksum."),
13950 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13951 Set whether to send break if interrupted."), _("\
13952 Show whether to send break if interrupted."), _("\
13953 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13954 set_remotebreak
, show_remotebreak
,
13955 &setlist
, &showlist
);
13956 cmd_name
= "remotebreak";
13957 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13958 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13959 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13960 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13961 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13963 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13964 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13966 Set interrupt sequence to remote target."), _("\
13967 Show interrupt sequence to remote target."), _("\
13968 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13969 NULL
, show_interrupt_sequence
,
13970 &remote_set_cmdlist
,
13971 &remote_show_cmdlist
);
13973 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13974 &interrupt_on_connect
, _("\
13975 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13976 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13977 If set, interrupt sequence is sent to remote target."),
13979 &remote_set_cmdlist
, &remote_show_cmdlist
);
13981 /* Install commands for configuring memory read/write packets. */
13983 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13984 Set the maximum number of bytes per memory write packet (deprecated)."),
13986 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13987 Show the maximum number of bytes per memory write packet (deprecated)."),
13989 add_cmd ("memory-write-packet-size", no_class
,
13990 set_memory_write_packet_size
, _("\
13991 Set the maximum number of bytes per memory-write packet.\n\
13992 Specify the number of bytes in a packet or 0 (zero) for the\n\
13993 default packet size. The actual limit is further reduced\n\
13994 dependent on the target. Specify ``fixed'' to disable the\n\
13995 further restriction and ``limit'' to enable that restriction."),
13996 &remote_set_cmdlist
);
13997 add_cmd ("memory-read-packet-size", no_class
,
13998 set_memory_read_packet_size
, _("\
13999 Set the maximum number of bytes per memory-read packet.\n\
14000 Specify the number of bytes in a packet or 0 (zero) for the\n\
14001 default packet size. The actual limit is further reduced\n\
14002 dependent on the target. Specify ``fixed'' to disable the\n\
14003 further restriction and ``limit'' to enable that restriction."),
14004 &remote_set_cmdlist
);
14005 add_cmd ("memory-write-packet-size", no_class
,
14006 show_memory_write_packet_size
,
14007 _("Show the maximum number of bytes per memory-write packet."),
14008 &remote_show_cmdlist
);
14009 add_cmd ("memory-read-packet-size", no_class
,
14010 show_memory_read_packet_size
,
14011 _("Show the maximum number of bytes per memory-read packet."),
14012 &remote_show_cmdlist
);
14014 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
14015 &remote_hw_watchpoint_limit
, _("\
14016 Set the maximum number of target hardware watchpoints."), _("\
14017 Show the maximum number of target hardware watchpoints."), _("\
14018 Specify a negative limit for unlimited."),
14019 NULL
, NULL
, /* FIXME: i18n: The maximum
14020 number of target hardware
14021 watchpoints is %s. */
14022 &remote_set_cmdlist
, &remote_show_cmdlist
);
14023 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
14024 &remote_hw_watchpoint_length_limit
, _("\
14025 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
14026 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
14027 Specify a negative limit for unlimited."),
14028 NULL
, NULL
, /* FIXME: i18n: The maximum
14029 length (in bytes) of a target
14030 hardware watchpoint is %s. */
14031 &remote_set_cmdlist
, &remote_show_cmdlist
);
14032 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
14033 &remote_hw_breakpoint_limit
, _("\
14034 Set the maximum number of target hardware breakpoints."), _("\
14035 Show the maximum number of target hardware breakpoints."), _("\
14036 Specify a negative limit for unlimited."),
14037 NULL
, NULL
, /* FIXME: i18n: The maximum
14038 number of target hardware
14039 breakpoints is %s. */
14040 &remote_set_cmdlist
, &remote_show_cmdlist
);
14042 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
14043 &remote_address_size
, _("\
14044 Set the maximum size of the address (in bits) in a memory packet."), _("\
14045 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
14047 NULL
, /* FIXME: i18n: */
14048 &setlist
, &showlist
);
14050 init_all_packet_configs ();
14052 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
14053 "X", "binary-download", 1);
14055 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
14056 "vCont", "verbose-resume", 0);
14058 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
14059 "QPassSignals", "pass-signals", 0);
14061 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
14062 "QCatchSyscalls", "catch-syscalls", 0);
14064 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
14065 "QProgramSignals", "program-signals", 0);
14067 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartupWithShell
],
14068 "QStartupWithShell", "startup-with-shell", 0);
14070 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
14071 "qSymbol", "symbol-lookup", 0);
14073 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
14074 "P", "set-register", 1);
14076 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
14077 "p", "fetch-register", 1);
14079 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
14080 "Z0", "software-breakpoint", 0);
14082 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
14083 "Z1", "hardware-breakpoint", 0);
14085 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
14086 "Z2", "write-watchpoint", 0);
14088 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
14089 "Z3", "read-watchpoint", 0);
14091 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
14092 "Z4", "access-watchpoint", 0);
14094 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
14095 "qXfer:auxv:read", "read-aux-vector", 0);
14097 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
14098 "qXfer:exec-file:read", "pid-to-exec-file", 0);
14100 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
14101 "qXfer:features:read", "target-features", 0);
14103 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
14104 "qXfer:libraries:read", "library-info", 0);
14106 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
14107 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
14109 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
14110 "qXfer:memory-map:read", "memory-map", 0);
14112 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
14113 "qXfer:spu:read", "read-spu-object", 0);
14115 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
14116 "qXfer:spu:write", "write-spu-object", 0);
14118 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
14119 "qXfer:osdata:read", "osdata", 0);
14121 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
14122 "qXfer:threads:read", "threads", 0);
14124 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
14125 "qXfer:siginfo:read", "read-siginfo-object", 0);
14127 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
14128 "qXfer:siginfo:write", "write-siginfo-object", 0);
14130 add_packet_config_cmd
14131 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
14132 "qXfer:traceframe-info:read", "traceframe-info", 0);
14134 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
14135 "qXfer:uib:read", "unwind-info-block", 0);
14137 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
14138 "qGetTLSAddr", "get-thread-local-storage-address",
14141 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
14142 "qGetTIBAddr", "get-thread-information-block-address",
14145 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
14146 "bc", "reverse-continue", 0);
14148 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
14149 "bs", "reverse-step", 0);
14151 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
14152 "qSupported", "supported-packets", 0);
14154 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
14155 "qSearch:memory", "search-memory", 0);
14157 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
14158 "qTStatus", "trace-status", 0);
14160 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
14161 "vFile:setfs", "hostio-setfs", 0);
14163 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
14164 "vFile:open", "hostio-open", 0);
14166 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
14167 "vFile:pread", "hostio-pread", 0);
14169 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
14170 "vFile:pwrite", "hostio-pwrite", 0);
14172 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
14173 "vFile:close", "hostio-close", 0);
14175 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
14176 "vFile:unlink", "hostio-unlink", 0);
14178 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
14179 "vFile:readlink", "hostio-readlink", 0);
14181 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
14182 "vFile:fstat", "hostio-fstat", 0);
14184 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
14185 "vAttach", "attach", 0);
14187 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
14190 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
14191 "QStartNoAckMode", "noack", 0);
14193 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
14194 "vKill", "kill", 0);
14196 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
14197 "qAttached", "query-attached", 0);
14199 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
14200 "ConditionalTracepoints",
14201 "conditional-tracepoints", 0);
14203 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
14204 "ConditionalBreakpoints",
14205 "conditional-breakpoints", 0);
14207 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
14208 "BreakpointCommands",
14209 "breakpoint-commands", 0);
14211 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
14212 "FastTracepoints", "fast-tracepoints", 0);
14214 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
14215 "TracepointSource", "TracepointSource", 0);
14217 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
14218 "QAllow", "allow", 0);
14220 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
14221 "StaticTracepoints", "static-tracepoints", 0);
14223 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
14224 "InstallInTrace", "install-in-trace", 0);
14226 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
14227 "qXfer:statictrace:read", "read-sdata-object", 0);
14229 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
14230 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
14232 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
14233 "QDisableRandomization", "disable-randomization", 0);
14235 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
14236 "QAgent", "agent", 0);
14238 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
14239 "QTBuffer:size", "trace-buffer-size", 0);
14241 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
14242 "Qbtrace:off", "disable-btrace", 0);
14244 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
14245 "Qbtrace:bts", "enable-btrace-bts", 0);
14247 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
14248 "Qbtrace:pt", "enable-btrace-pt", 0);
14250 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
14251 "qXfer:btrace", "read-btrace", 0);
14253 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
14254 "qXfer:btrace-conf", "read-btrace-conf", 0);
14256 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
14257 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
14259 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
14260 "multiprocess-feature", "multiprocess-feature", 0);
14262 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
14263 "swbreak-feature", "swbreak-feature", 0);
14265 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
14266 "hwbreak-feature", "hwbreak-feature", 0);
14268 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
14269 "fork-event-feature", "fork-event-feature", 0);
14271 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
14272 "vfork-event-feature", "vfork-event-feature", 0);
14274 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
14275 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
14277 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
14278 "vContSupported", "verbose-resume-supported", 0);
14280 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
14281 "exec-event-feature", "exec-event-feature", 0);
14283 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
14284 "vCtrlC", "ctrl-c", 0);
14286 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
14287 "QThreadEvents", "thread-events", 0);
14289 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
14290 "N stop reply", "no-resumed-stop-reply", 0);
14292 /* Assert that we've registered "set remote foo-packet" commands
14293 for all packet configs. */
14297 for (i
= 0; i
< PACKET_MAX
; i
++)
14299 /* Ideally all configs would have a command associated. Some
14300 still don't though. */
14305 case PACKET_QNonStop
:
14306 case PACKET_EnableDisableTracepoints_feature
:
14307 case PACKET_tracenz_feature
:
14308 case PACKET_DisconnectedTracing_feature
:
14309 case PACKET_augmented_libraries_svr4_read_feature
:
14311 /* Additions to this list need to be well justified:
14312 pre-existing packets are OK; new packets are not. */
14320 /* This catches both forgetting to add a config command, and
14321 forgetting to remove a packet from the exception list. */
14322 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
14326 /* Keep the old ``set remote Z-packet ...'' working. Each individual
14327 Z sub-packet has its own set and show commands, but users may
14328 have sets to this variable in their .gdbinit files (or in their
14330 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
14331 &remote_Z_packet_detect
, _("\
14332 Set use of remote protocol `Z' packets"), _("\
14333 Show use of remote protocol `Z' packets "), _("\
14334 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
14336 set_remote_protocol_Z_packet_cmd
,
14337 show_remote_protocol_Z_packet_cmd
,
14338 /* FIXME: i18n: Use of remote protocol
14339 `Z' packets is %s. */
14340 &remote_set_cmdlist
, &remote_show_cmdlist
);
14342 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
14343 Manipulate files on the remote system\n\
14344 Transfer files to and from the remote target system."),
14345 &remote_cmdlist
, "remote ",
14346 0 /* allow-unknown */, &cmdlist
);
14348 add_cmd ("put", class_files
, remote_put_command
,
14349 _("Copy a local file to the remote system."),
14352 add_cmd ("get", class_files
, remote_get_command
,
14353 _("Copy a remote file to the local system."),
14356 add_cmd ("delete", class_files
, remote_delete_command
,
14357 _("Delete a remote file."),
14360 add_setshow_string_noescape_cmd ("exec-file", class_files
,
14361 &remote_exec_file_var
, _("\
14362 Set the remote pathname for \"run\""), _("\
14363 Show the remote pathname for \"run\""), NULL
,
14364 set_remote_exec_file
,
14365 show_remote_exec_file
,
14366 &remote_set_cmdlist
,
14367 &remote_show_cmdlist
);
14369 add_setshow_boolean_cmd ("range-stepping", class_run
,
14370 &use_range_stepping
, _("\
14371 Enable or disable range stepping."), _("\
14372 Show whether target-assisted range stepping is enabled."), _("\
14373 If on, and the target supports it, when stepping a source line, GDB\n\
14374 tells the target to step the corresponding range of addresses itself instead\n\
14375 of issuing multiple single-steps. This speeds up source level\n\
14376 stepping. If off, GDB always issues single-steps, even if range\n\
14377 stepping is supported by the target. The default is on."),
14378 set_range_stepping
,
14379 show_range_stepping
,
14383 /* Eventually initialize fileio. See fileio.c */
14384 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
14386 /* Take advantage of the fact that the TID field is not used, to tag
14387 special ptids with it set to != 0. */
14388 magic_null_ptid
= ptid_build (42000, -1, 1);
14389 not_sent_ptid
= ptid_build (42000, -2, 1);
14390 any_thread_ptid
= ptid_build (42000, 0, 1);
14392 target_buf_size
= 2048;
14393 target_buf
= (char *) xmalloc (target_buf_size
);