GDB (xrefs)
Loading...
Searching...
No Matches
remote.c
Go to the documentation of this file.
1/* Remote target communications for serial-line targets in custom GDB protocol
2
3 Copyright (C) 1988-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20/* See the GDB User Guide for details of the GDB remote protocol. */
21
22#include "defs.h"
23#include <ctype.h>
24#include <fcntl.h>
25#include "inferior.h"
26#include "infrun.h"
27#include "bfd.h"
28#include "symfile.h"
29#include "target.h"
31#include "gdbcmd.h"
32#include "objfiles.h"
33#include "gdbthread.h"
34#include "remote.h"
35#include "remote-notif.h"
36#include "regcache.h"
37#include "value.h"
38#include "observable.h"
39#include "solib.h"
40#include "cli/cli-decode.h"
41#include "cli/cli-setshow.h"
42#include "target-descriptions.h"
43#include "gdb_bfd.h"
44#include "gdbsupport/filestuff.h"
45#include "gdbsupport/rsp-low.h"
46#include "disasm.h"
47#include "location.h"
48
49#include "gdbsupport/gdb_sys_time.h"
50
51#include "gdbsupport/event-loop.h"
52#include "event-top.h"
53#include "inf-loop.h"
54
55#include <signal.h>
56#include "serial.h"
57
58#include "gdbcore.h"
59
60#include "remote-fileio.h"
61#include "gdbsupport/fileio.h"
62#include <sys/stat.h>
63#include "xml-support.h"
64
65#include "memory-map.h"
66
67#include "tracepoint.h"
68#include "ax.h"
69#include "ax-gdb.h"
70#include "gdbsupport/agent.h"
71#include "btrace.h"
72#include "record-btrace.h"
73#include "gdbsupport/scoped_restore.h"
74#include "gdbsupport/environ.h"
75#include "gdbsupport/byte-vector.h"
76#include "gdbsupport/search.h"
77#include <algorithm>
78#include <iterator>
79#include <unordered_map>
80#include "async-event.h"
81#include "gdbsupport/selftest.h"
82
83/* The remote target. */
84
85static const char remote_doc[] = N_("\
86Use a remote computer via a serial line, using a gdb-specific protocol.\n\
87Specify the serial device it is connected to\n\
88(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
89
90/* See remote.h */
91
92bool remote_debug = false;
93
94#define OPAQUETHREADBYTES 8
95
96/* a 64 bit opaque identifier */
97typedef unsigned char threadref[OPAQUETHREADBYTES];
98
101typedef int (*rmt_thread_action) (threadref *ref, void *context);
102struct protocol_feature;
103struct packet_reg;
104
105struct stop_reply;
106typedef std::unique_ptr<stop_reply> stop_reply_up;
107
108/* Generic configuration support for packets the stub optionally
109 supports. Allows the user to specify the use of the packet as well
110 as allowing GDB to auto-detect support in the remote stub. */
111
118
119/* Convert the packet support auto_boolean to a name used for gdb printing. */
120
121static const char *
123{
124 switch (support)
125 {
127 return "on";
129 return "off";
131 return "auto";
132 default:
133 gdb_assert_not_reached ("invalid var_auto_boolean");
134 }
135}
136
137/* Convert the target type (future remote target or currently connected target)
138 to a name used for gdb printing. */
139
140static const char *
141get_target_type_name (bool target_connected)
142{
143 if (target_connected)
144 return _("on the current remote target");
145 else
146 return _("on future remote targets");
147}
148
149/* Analyze a packet's return value and update the packet config
150 accordingly. */
151
158
159/* Enumeration of packets for a remote target. */
160
161enum {
212
213 /* Support for conditional tracepoints. */
215
216 /* Support for target-side breakpoint conditions. */
218
219 /* Support for target-side breakpoint commands. */
221
222 /* Support for fast tracepoints. */
224
225 /* Support for static tracepoints. */
227
228 /* Support for installing tracepoints while a trace experiment is
229 running. */
231
244
245 /* Support for the QNonStop packet. */
247
248 /* Support for the QThreadEvents packet. */
250
251 /* Support for multi-process extensions. */
253
254 /* Support for enabling and disabling tracepoints while a trace
255 experiment is running. */
257
258 /* Support for collecting strings using the tracenz bytecode. */
260
261 /* Support for continuing to run a trace experiment while GDB is
262 disconnected. */
264
265 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
267
268 /* Support for the qXfer:btrace-conf:read packet. */
270
271 /* Support for the Qbtrace-conf:bts:size packet. */
273
274 /* Support for swbreak+ feature. */
276
277 /* Support for hwbreak+ feature. */
279
280 /* Support for fork events. */
282
283 /* Support for vfork events. */
285
286 /* Support for the Qbtrace-conf:pt:size packet. */
288
289 /* Support for exec events. */
291
292 /* Support for query supported vCont actions. */
294
295 /* Support remote CTRL-C. */
297
298 /* Support TARGET_WAITKIND_NO_RESUMED. */
300
301 /* Support for memory tagging, allocation tag fetch/store
302 packets and the tag violation stop replies. */
304
307
309
310/* Stub vCont actions support.
311
312 Each field is a boolean flag indicating whether the stub reports
313 support for the corresponding action. */
314
316{
317 /* vCont;t */
318 bool t = false;
319
320 /* vCont;r */
321 bool r = false;
322
323 /* vCont;s */
324 bool s = false;
325
326 /* vCont;S */
327 bool S = false;
328};
329
330/* About this many threadids fit in a packet. */
331
332#define MAXTHREADLISTRESULTS 32
333
334/* Data for the vFile:pread readahead cache. */
335
337{
338 /* Invalidate the readahead cache. */
339 void invalidate ();
340
341 /* Invalidate the readahead cache if it is holding data for FD. */
342 void invalidate_fd (int fd);
343
344 /* Serve pread from the readahead cache. Returns number of bytes
345 read, or 0 if the request can't be served from the cache. */
346 int pread (int fd, gdb_byte *read_buf, size_t len, ULONGEST offset);
347
348 /* The file descriptor for the file that is being cached. -1 if the
349 cache is invalid. */
350 int fd = -1;
351
352 /* The offset into the file that the cache buffer corresponds
353 to. */
354 ULONGEST offset = 0;
355
356 /* The buffer holding the cache contents. */
357 gdb::byte_vector buf;
358
359 /* Cache hit and miss counters. */
360 ULONGEST hit_count = 0;
361 ULONGEST miss_count = 0;
362};
363
364/* Description of the remote protocol for a given architecture. */
365
367{
368 long offset; /* Offset into G packet. */
369 long regnum; /* GDB's internal register number. */
370 LONGEST pnum; /* Remote protocol register number. */
371 int in_g_packet; /* Always part of G packet. */
372 /* long size in bytes; == register_size (target_gdbarch (), regnum);
373 at present. */
374 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
375 at present. */
376};
377
379{
380 explicit remote_arch_state (struct gdbarch *gdbarch);
381
382 /* Description of the remote protocol registers. */
384
385 /* Description of the remote protocol registers indexed by REGNUM
386 (making an array gdbarch_num_regs in size). */
387 std::unique_ptr<packet_reg[]> regs;
388
389 /* This is the size (in chars) of the first response to the ``g''
390 packet. It is used as a heuristic when determining the maximum
391 size of memory-read and memory-write packets. A target will
392 typically only reserve a buffer large enough to hold the ``g''
393 packet. The size does not include packet overhead (headers and
394 trailers). */
396
397 /* This is the maximum size (in chars) of a non read/write packet.
398 It is also used as a cap on the size of read/write packets. */
400};
401
402/* Description of the remote protocol state for the currently
403 connected target. This is per-target state, and independent of the
404 selected architecture. */
405
407{
408public:
409
410 remote_state ();
411 ~remote_state ();
412
413 /* Get the remote arch state for GDBARCH. */
415
416public: /* data */
417
418 /* A buffer to use for incoming packets, and its current size. The
419 buffer is grown dynamically for larger incoming packets.
420 Outgoing packets may also be constructed in this buffer.
421 The size of the buffer is always at least REMOTE_PACKET_SIZE;
422 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
423 packets. */
424 gdb::char_vector buf;
425
426 /* True if we're going through initial connection setup (finding out
427 about the remote side's threads, relocating symbols, etc.). */
428 bool starting_up = false;
429
430 /* If we negotiated packet size explicitly (and thus can bypass
431 heuristics for the largest packet size that will not overflow
432 a buffer in the stub), this will be set to that packet size.
433 Otherwise zero, meaning to use the guessed size. */
435
436 /* True, if in no ack mode. That is, neither GDB nor the stub will
437 expect acks from each other. The connection is assumed to be
438 reliable. */
439 bool noack_mode = false;
440
441 /* True if we're connected in extended remote mode. */
442 bool extended = false;
443
444 /* True if we resumed the target and we're waiting for the target to
445 stop. In the mean time, we can't start another command/query.
446 The remote server wouldn't be ready to process it, so we'd
447 timeout waiting for a reply that would never come and eventually
448 we'd close the connection. This can happen in asynchronous mode
449 because we allow GDB commands while the target is running. */
451
452 /* The status of the stub support for the various vCont actions. */
454
455 /* True if the user has pressed Ctrl-C, but the target hasn't
456 responded to that. */
457 bool ctrlc_pending_p = false;
458
459 /* True if we saw a Ctrl-C while reading or writing from/to the
460 remote descriptor. At that point it is not safe to send a remote
461 interrupt packet, so we instead remember we saw the Ctrl-C and
462 process it once we're done with sending/receiving the current
463 packet, which should be shortly. If however that takes too long,
464 and the user presses Ctrl-C again, we offer to disconnect. */
466
467 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
468 remote_open knows that we don't have a file open when the program
469 starts. */
470 struct serial *remote_desc = nullptr;
471
472 /* These are the threads which we last sent to the remote system. The
473 TID member will be -1 for all or -2 for not sent yet. */
474 ptid_t general_thread = null_ptid;
475 ptid_t continue_thread = null_ptid;
476
477 /* This is the traceframe which we last selected on the remote system.
478 It will be -1 if no traceframe is selected. */
480
481 char *last_pass_packet = nullptr;
482
483 /* The last QProgramSignals packet sent to the target. We bypass
484 sending a new program signals list down to the target if the new
485 packet is exactly the same as the last we sent. IOW, we only let
486 the target know about program signals list changes. */
488
489 gdb_signal last_sent_signal = GDB_SIGNAL_0;
490
491 bool last_sent_step = false;
492
493 /* The execution direction of the last resume we got. */
495
496 char *finished_object = nullptr;
497 char *finished_annex = nullptr;
498 ULONGEST finished_offset = 0;
499
500 /* Should we try the 'ThreadInfo' query packet?
501
502 This variable (NOT available to the user: auto-detect only!)
503 determines whether GDB will use the new, simpler "ThreadInfo"
504 query or the older, more complex syntax for thread queries.
505 This is an auto-detect variable (set to true at each connect,
506 and set to false when the target fails to recognize it). */
509
513
514 /* The state of remote notification. */
516
517 /* The branch trace configuration. */
519
520 /* The argument to the last "vFile:setfs:" packet we sent, used
521 to avoid sending repeated unnecessary "vFile:setfs:" packets.
522 Initialized to -1 to indicate that no "vFile:setfs:" packet
523 has yet been sent. */
524 int fs_pid = -1;
525
526 /* A readahead cache for vFile:pread. Often, reading a binary
527 involves a sequence of small reads. E.g., when parsing an ELF
528 file. A readahead cache helps mostly the case of remote
529 debugging on a connection with higher latency, due to the
530 request/reply nature of the RSP. We only cache data for a single
531 file descriptor at a time. */
533
534 /* The list of already fetched and acknowledged stop events. This
535 queue is used for notification Stop, and other notifications
536 don't need queue for their events, because the notification
537 events of Stop can't be consumed immediately, so that events
538 should be queued first, and be consumed by remote_wait_{ns,as}
539 one per time. Other notifications can consume their events
540 immediately, so queue is not needed for them. */
541 std::vector<stop_reply_up> stop_reply_queue;
542
543 /* Asynchronous signal handle registered as event loop source for
544 when we have pending events ready to be passed to the core. */
546
547 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
548 ``forever'' still use the normal timeout mechanism. This is
549 currently used by the ASYNC code to guarentee that target reads
550 during the initial connect always time-out. Once getpkt has been
551 modified to return a timeout indication and, in turn
552 remote_wait()/wait_for_inferior() have gained a timeout parameter
553 this can go away. */
555
556private:
557 /* Mapping of remote protocol data for each gdbarch. Usually there
558 is only one entry here, though we may see more with stubs that
559 support multi-process. */
560 std::unordered_map<struct gdbarch *, remote_arch_state>
562};
563
565 "remote",
566 N_("Remote target using gdb-specific protocol"),
568};
569
570/* Description of a remote packet. */
571
573{
574 /* Name of the packet used for gdb output. */
575 const char *name;
576
577 /* Title of the packet, used by the set/show remote name-packet
578 commands to identify the individual packages and gdb output. */
579 const char *title;
580};
581
582/* Configuration of a remote packet. */
583
585{
586 /* If auto, GDB auto-detects support for this packet or feature,
587 either through qSupported, or by trying the packet and looking
588 at the response. If true, GDB assumes the target supports this
589 packet. If false, the packet is disabled. Configs that don't
590 have an associated command always have this set to auto. */
592
593 /* Does the target support this packet? */
595};
596
597/* User configurable variables for the number of characters in a
598 memory read/write packet. MIN (rsa->remote_packet_size,
599 rsa->sizeof_g_packet) is the default. Some targets need smaller
600 values (fifo overruns, et.al.) and some users need larger values
601 (speed up transfers). The variables ``preferred_*'' (the user
602 request), ``current_*'' (what was actually set) and ``forced_*''
603 (Positive - a soft limit, negative - a hard limit). */
604
606{
607 const char *name;
608 long size;
610};
611
612/* These global variables contain the default configuration for every new
613 remote_feature object. */
615{
616 "memory-read-packet-size",
617};
619{
620 "memory-write-packet-size",
621};
622
623/* This global array contains packet descriptions (name and title). */
625/* This global array contains the default configuration for every new
626 per-remote target array. */
628
629/* Description of a remote target's features. It stores the configuration
630 and provides functions to determine supported features of the target. */
631
633{
643 ~remote_features () = default;
644
646
647 /* Returns whether a given packet defined by its enum value is supported. */
648 enum packet_support packet_support (int) const;
649
650 /* Returns the packet's corresponding "set remote foo-packet" command
651 state. See struct packet_config for more details. */
652 enum auto_boolean packet_set_cmd_state (int packet) const
653 { return m_protocol_packets[packet].detect; }
654
655 /* Returns true if the multi-process extensions are in effect. */
658
659 /* Returns true if fork events are supported. */
662
663 /* Returns true if vfork events are supported. */
666
667 /* Returns true if exec events are supported. */
670
671 /* Returns true if memory tagging is supported, false otherwise. */
674
675 /* Reset all packets back to "unknown support". Called when opening a
676 new connection to a remote target. */
678
679/* Check result value in BUF for packet WHICH_PACKET and update the packet's
680 support configuration accordingly. */
681 packet_result packet_ok (const char *buf, const int which_packet);
682 packet_result packet_ok (const gdb::char_vector &buf, const int which_packet);
683
684 /* Configuration of a remote target's memory read packet. */
686 /* Configuration of a remote target's memory write packet. */
688
689 /* The per-remote target array which stores a remote's packet
690 configurations. */
692};
693
695{
696public:
697 remote_target () = default;
698 ~remote_target () override;
699
700 const target_info &info () const override
701 { return remote_target_info; }
702
703 const char *connection_string () override;
704
707
708 /* Open a remote connection. */
709 static void open (const char *, int);
710
711 void close () override;
712
713 void detach (inferior *, int) override;
714 void disconnect (const char *, int) override;
715
716 void commit_resumed () override;
717 void resume (ptid_t, int, enum gdb_signal) override;
718 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
719 bool has_pending_events () override;
720
721 void fetch_registers (struct regcache *, int) override;
722 void store_registers (struct regcache *, int) override;
723 void prepare_to_store (struct regcache *) override;
724
725 int insert_breakpoint (struct gdbarch *, struct bp_target_info *) override;
726
727 int remove_breakpoint (struct gdbarch *, struct bp_target_info *,
728 enum remove_bp_reason) override;
729
730
731 bool stopped_by_sw_breakpoint () override;
732 bool supports_stopped_by_sw_breakpoint () override;
733
734 bool stopped_by_hw_breakpoint () override;
735
736 bool supports_stopped_by_hw_breakpoint () override;
737
738 bool stopped_by_watchpoint () override;
739
740 bool stopped_data_address (CORE_ADDR *) override;
741
742 bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
743
744 int can_use_hw_breakpoint (enum bptype, int, int) override;
745
746 int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
747
748 int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
749
750 int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
751
752 int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
753 struct expression *) override;
754
755 int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
756 struct expression *) override;
757
758 void kill () override;
759
760 void load (const char *, int) override;
761
762 void mourn_inferior () override;
763
764 void pass_signals (gdb::array_view<const unsigned char>) override;
765
766 int set_syscall_catchpoint (int, bool, int,
767 gdb::array_view<const int>) override;
768
769 void program_signals (gdb::array_view<const unsigned char>) override;
770
771 bool thread_alive (ptid_t ptid) override;
772
773 const char *thread_name (struct thread_info *) override;
774
775 void update_thread_list () override;
776
777 std::string pid_to_str (ptid_t) override;
778
779 const char *extra_thread_info (struct thread_info *) override;
780
781 ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
782
783 thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
784 int handle_len,
785 inferior *inf) override;
786
787 gdb::array_view<const gdb_byte> thread_info_to_thread_handle (struct thread_info *tp)
788 override;
789
790 void stop (ptid_t) override;
791
792 void interrupt () override;
793
794 void pass_ctrlc () override;
795
797 const char *annex,
798 gdb_byte *readbuf,
799 const gdb_byte *writebuf,
800 ULONGEST offset, ULONGEST len,
801 ULONGEST *xfered_len) override;
802
803 ULONGEST get_memory_xfer_limit () override;
804
805 void rcmd (const char *command, struct ui_file *output) override;
806
807 const char *pid_to_exec_file (int pid) override;
808
809 void log_command (const char *cmd) override
810 {
811 serial_log_command (this, cmd);
812 }
813
814 CORE_ADDR get_thread_local_address (ptid_t ptid,
815 CORE_ADDR load_module_addr,
816 CORE_ADDR offset) override;
817
818 bool can_execute_reverse () override;
819
820 std::vector<mem_region> memory_map () override;
821
822 void flash_erase (ULONGEST address, LONGEST length) override;
823
824 void flash_done () override;
825
826 const struct target_desc *read_description () override;
827
828 int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
829 const gdb_byte *pattern, ULONGEST pattern_len,
830 CORE_ADDR *found_addrp) override;
831
832 bool can_async_p () override;
833
834 bool is_async_p () override;
835
836 void async (bool) override;
837
838 int async_wait_fd () override;
839
840 void thread_events (int) override;
841
842 int can_do_single_step () override;
843
844 void terminal_inferior () override;
845
846 void terminal_ours () override;
847
848 bool supports_non_stop () override;
849
850 bool supports_multi_process () override;
851
852 bool supports_disable_randomization () override;
853
854 bool filesystem_is_local () override;
855
856
857 int fileio_open (struct inferior *inf, const char *filename,
858 int flags, int mode, int warn_if_slow,
859 fileio_error *target_errno) override;
860
861 int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
862 ULONGEST offset, fileio_error *target_errno) override;
863
864 int fileio_pread (int fd, gdb_byte *read_buf, int len,
865 ULONGEST offset, fileio_error *target_errno) override;
866
867 int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) override;
868
869 int fileio_close (int fd, fileio_error *target_errno) override;
870
871 int fileio_unlink (struct inferior *inf,
872 const char *filename,
873 fileio_error *target_errno) override;
874
875 gdb::optional<std::string>
877 const char *filename,
878 fileio_error *target_errno) override;
879
880 bool supports_enable_disable_tracepoint () override;
881
882 bool supports_string_tracing () override;
883
885
887
889
891
893
894 bool can_run_breakpoint_commands () override;
895
896 void trace_init () override;
897
898 void download_tracepoint (struct bp_location *location) override;
899
900 bool can_download_tracepoint () override;
901
902 void download_trace_state_variable (const trace_state_variable &tsv) override;
903
904 void enable_tracepoint (struct bp_location *location) override;
905
906 void disable_tracepoint (struct bp_location *location) override;
907
908 void trace_set_readonly_regions () override;
909
910 void trace_start () override;
911
912 int get_trace_status (struct trace_status *ts) override;
913
914 void get_tracepoint_status (tracepoint *tp, struct uploaded_tp *utp)
915 override;
916
917 void trace_stop () override;
918
919 int trace_find (enum trace_find_type type, int num,
920 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
921
922 bool get_trace_state_variable_value (int tsv, LONGEST *val) override;
923
924 int save_trace_data (const char *filename) override;
925
926 int upload_tracepoints (struct uploaded_tp **utpp) override;
927
928 int upload_trace_state_variables (struct uploaded_tsv **utsvp) override;
929
930 LONGEST get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len) override;
931
932 int get_min_fast_tracepoint_insn_len () override;
933
934 void set_disconnected_tracing (int val) override;
935
936 void set_circular_trace_buffer (int val) override;
937
938 void set_trace_buffer_size (LONGEST val) override;
939
940 bool set_trace_notes (const char *user, const char *notes,
941 const char *stopnotes) override;
942
943 int core_of_thread (ptid_t ptid) override;
944
945 int verify_memory (const gdb_byte *data,
946 CORE_ADDR memaddr, ULONGEST size) override;
947
948
949 bool get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
950
951 void set_permissions () override;
952
953 bool static_tracepoint_marker_at (CORE_ADDR,
954 struct static_tracepoint_marker *marker)
955 override;
956
957 std::vector<static_tracepoint_marker>
958 static_tracepoint_markers_by_strid (const char *id) override;
959
961
962 bool use_agent (bool use) override;
963 bool can_use_agent () override;
964
965 struct btrace_target_info *
966 enable_btrace (thread_info *tp, const struct btrace_config *conf) override;
967
968 void disable_btrace (struct btrace_target_info *tinfo) override;
969
970 void teardown_btrace (struct btrace_target_info *tinfo) override;
971
972 enum btrace_error read_btrace (struct btrace_data *data,
973 struct btrace_target_info *btinfo,
974 enum btrace_read_type type) override;
975
976 const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
977 bool augmented_libraries_svr4_read () override;
978 void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
979 void follow_exec (inferior *, ptid_t, const char *) override;
980 int insert_fork_catchpoint (int) override;
981 int remove_fork_catchpoint (int) override;
982 int insert_vfork_catchpoint (int) override;
983 int remove_vfork_catchpoint (int) override;
984 int insert_exec_catchpoint (int) override;
985 int remove_exec_catchpoint (int) override;
987
988 bool supports_memory_tagging () override;
989
990 bool fetch_memtags (CORE_ADDR address, size_t len,
991 gdb::byte_vector &tags, int type) override;
992
993 bool store_memtags (CORE_ADDR address, size_t len,
994 const gdb::byte_vector &tags, int type) override;
995
996public: /* Remote specific methods. */
997
998 void remote_download_command_source (int num, ULONGEST addr,
999 struct command_line *cmds);
1000
1001 void remote_file_put (const char *local_file, const char *remote_file,
1002 int from_tty);
1003 void remote_file_get (const char *remote_file, const char *local_file,
1004 int from_tty);
1005 void remote_file_delete (const char *remote_file, int from_tty);
1006
1007 int remote_hostio_pread (int fd, gdb_byte *read_buf, int len,
1008 ULONGEST offset, fileio_error *remote_errno);
1009 int remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len,
1010 ULONGEST offset, fileio_error *remote_errno);
1011 int remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len,
1012 ULONGEST offset, fileio_error *remote_errno);
1013
1014 int remote_hostio_send_command (int command_bytes, int which_packet,
1015 fileio_error *remote_errno, const char **attachment,
1016 int *attachment_len);
1018 fileio_error *remote_errno);
1019 /* We should get rid of this and use fileio_open directly. */
1020 int remote_hostio_open (struct inferior *inf, const char *filename,
1021 int flags, int mode, int warn_if_slow,
1022 fileio_error *remote_errno);
1023 int remote_hostio_close (int fd, fileio_error *remote_errno);
1024
1025 int remote_hostio_unlink (inferior *inf, const char *filename,
1026 fileio_error *remote_errno);
1027
1028 struct remote_state *get_remote_state ();
1029
1030 long get_remote_packet_size (void);
1031 long get_memory_packet_size (struct memory_packet_config *config);
1032
1035
1036 char *append_pending_thread_resumptions (char *p, char *endp,
1037 ptid_t ptid);
1038 static void open_1 (const char *name, int from_tty, int extended_p);
1039 void start_remote (int from_tty, int extended_p);
1040 void remote_detach_1 (struct inferior *inf, int from_tty);
1041
1042 char *append_resumption (char *p, char *endp,
1043 ptid_t ptid, int step, gdb_signal siggnal);
1044 int remote_resume_with_vcont (ptid_t scope_ptid, int step,
1045 gdb_signal siggnal);
1046
1047 thread_info *add_current_inferior_and_thread (const char *wait_status);
1048
1049 ptid_t wait_ns (ptid_t ptid, struct target_waitstatus *status,
1050 target_wait_flags options);
1051 ptid_t wait_as (ptid_t ptid, target_waitstatus *status,
1052 target_wait_flags options);
1053
1056
1058 (const struct target_waitstatus &status);
1059
1060 void remote_notice_new_inferior (ptid_t currthread, bool executing);
1061
1063 void process_initial_stop_replies (int from_tty);
1064
1065 thread_info *remote_add_thread (ptid_t ptid, bool running, bool executing,
1066 bool silent_p);
1067
1068 void btrace_sync_conf (const btrace_config *conf);
1069
1071
1076
1078 (bool *may_global_wildcard_vcont);
1079
1081 struct stop_reply *remote_notif_remove_queued_reply (ptid_t ptid);
1082 struct stop_reply *queued_stop_reply (ptid_t ptid);
1083 int peek_stop_reply (ptid_t ptid);
1084 void remote_parse_stop_reply (const char *buf, stop_reply *event);
1085
1086 void remote_stop_ns (ptid_t ptid);
1087 void remote_interrupt_as ();
1088 void remote_interrupt_ns ();
1089
1090 char *remote_get_noisy_reply ();
1091 int remote_query_attached (int pid);
1092 inferior *remote_add_inferior (bool fake_pid_p, int pid, int attached,
1093 int try_open_exec);
1094
1095 ptid_t remote_current_thread (ptid_t oldpid);
1096 ptid_t get_current_thread (const char *wait_status);
1097
1098 void set_thread (ptid_t ptid, int gen);
1099 void set_general_thread (ptid_t ptid);
1100 void set_continue_thread (ptid_t ptid);
1101 void set_general_process ();
1102
1103 char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
1104
1105 int remote_unpack_thread_info_response (const char *pkt, threadref *expectedref,
1107 int remote_get_threadinfo (threadref *threadid, int fieldset,
1109
1110 int parse_threadlist_response (const char *pkt, int result_limit,
1111 threadref *original_echo,
1112 threadref *resultlist,
1113 int *doneflag);
1114 int remote_get_threadlist (int startflag, threadref *nextthread,
1115 int result_limit, int *done, int *result_count,
1116 threadref *threadlist);
1117
1119 void *context, int looplimit);
1120
1124
1126
1127 void get_offsets ();
1128
1129 void remote_check_symbols ();
1130
1131 void remote_supported_packet (const struct protocol_feature *feature,
1132 enum packet_support support,
1133 const char *argument);
1134
1135 void remote_query_supported ();
1136
1137 void remote_packet_size (const protocol_feature *feature,
1138 packet_support support, const char *value);
1139
1141
1142 void remote_detach_pid (int pid);
1143
1144 void remote_vcont_probe ();
1145
1146 void remote_resume_with_hc (ptid_t ptid, int step,
1147 gdb_signal siggnal);
1148
1150 void interrupt_query ();
1151
1153
1155 packet_reg *reg);
1156 int send_g_packet ();
1157 void process_g_packet (struct regcache *regcache);
1159 int store_register_using_P (const struct regcache *regcache,
1160 packet_reg *reg);
1161 void store_registers_using_G (const struct regcache *regcache);
1162
1163 void set_remote_traceframe ();
1164
1165 void check_binary_download (CORE_ADDR addr);
1166
1167 target_xfer_status remote_write_bytes_aux (const char *header,
1168 CORE_ADDR memaddr,
1169 const gdb_byte *myaddr,
1170 ULONGEST len_units,
1171 int unit_size,
1172 ULONGEST *xfered_len_units,
1173 char packet_format,
1174 int use_length);
1175
1176 target_xfer_status remote_write_bytes (CORE_ADDR memaddr,
1177 const gdb_byte *myaddr, ULONGEST len,
1178 int unit_size, ULONGEST *xfered_len);
1179
1180 target_xfer_status remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr,
1181 ULONGEST len_units,
1182 int unit_size, ULONGEST *xfered_len_units);
1183
1185 ULONGEST memaddr,
1186 ULONGEST len,
1187 int unit_size,
1188 ULONGEST *xfered_len);
1189
1190 target_xfer_status remote_read_bytes (CORE_ADDR memaddr,
1191 gdb_byte *myaddr, ULONGEST len,
1192 int unit_size,
1193 ULONGEST *xfered_len);
1194
1195 packet_result remote_send_printf (const char *format, ...)
1196 ATTRIBUTE_PRINTF (2, 3);
1197
1198 target_xfer_status remote_flash_write (ULONGEST address,
1199 ULONGEST length, ULONGEST *xfered_len,
1200 const gdb_byte *data);
1201
1202 int readchar (int timeout);
1203
1204 void remote_serial_write (const char *str, int len);
1205
1206 int putpkt (const char *buf);
1207 int putpkt_binary (const char *buf, int cnt);
1208
1209 int putpkt (const gdb::char_vector &buf)
1210 {
1211 return putpkt (buf.data ());
1212 }
1213
1214 void skip_frame ();
1215 long read_frame (gdb::char_vector *buf_p);
1216 int getpkt (gdb::char_vector *buf, bool forever = false,
1217 bool *is_notif = nullptr);
1218 int remote_vkill (int pid);
1219 void remote_kill_k ();
1220
1222 int extended_remote_run (const std::string &args);
1223
1224 void send_environment_packet (const char *action,
1225 const char *packet,
1226 const char *value);
1227
1230
1231 target_xfer_status remote_write_qxfer (const char *object_name,
1232 const char *annex,
1233 const gdb_byte *writebuf,
1234 ULONGEST offset, LONGEST len,
1235 ULONGEST *xfered_len,
1236 const unsigned int which_packet);
1237
1238 target_xfer_status remote_read_qxfer (const char *object_name,
1239 const char *annex,
1240 gdb_byte *readbuf, ULONGEST offset,
1241 LONGEST len,
1242 ULONGEST *xfered_len,
1243 const unsigned int which_packet);
1244
1245 void push_stop_reply (struct stop_reply *new_event);
1246
1247 bool vcont_r_supported ();
1248
1250
1251private:
1252
1253 bool start_remote_1 (int from_tty, int extended_p);
1254
1255 /* The remote state. Don't reference this directly. Use the
1256 get_remote_state method instead. */
1258};
1259
1261 "extended-remote",
1262 N_("Extended remote target using gdb-specific protocol"),
1264};
1265
1266/* Set up the extended remote target by extending the standard remote
1267 target and adding to it. */
1268
1270{
1271public:
1272 const target_info &info () const override
1273 { return extended_remote_target_info; }
1274
1275 /* Open an extended-remote connection. */
1276 static void open (const char *, int);
1277
1278 bool can_create_inferior () override { return true; }
1279 void create_inferior (const char *, const std::string &,
1280 char **, int) override;
1281
1282 void detach (inferior *, int) override;
1283
1284 bool can_attach () override { return true; }
1285 void attach (const char *, int) override;
1286
1287 void post_attach (int) override;
1288 bool supports_disable_randomization () override;
1289};
1290
1292{
1293 ~stop_reply ();
1294
1295 /* The identifier of the thread about this event */
1296 ptid_t ptid;
1297
1298 /* The remote state this event is associated with. When the remote
1299 connection, represented by a remote_state object, is closed,
1300 all the associated stop_reply events should be released. */
1302
1304
1305 /* The architecture associated with the expedited registers. */
1307
1308 /* Expedited registers. This makes remote debugging a bit more
1309 efficient for those targets that provide critical registers as
1310 part of their normal status mechanism (as another roundtrip to
1311 fetch them is avoided). */
1312 std::vector<cached_reg_t> regcache;
1313
1315
1317
1318 int core;
1319};
1320
1321/* Return TARGET as a remote_target if it is one, else nullptr. */
1322
1323static remote_target *
1325{
1326 return dynamic_cast<remote_target *> (target);
1327}
1328
1329/* See remote.h. */
1330
1331bool
1333{
1334 return as_remote_target (target) != nullptr;
1335}
1336
1337/* Per-program-space data key. */
1338static const registry<program_space>::key<char, gdb::xfree_deleter<char>>
1340
1341/* The variable registered as the control variable used by the
1342 remote exec-file commands. While the remote exec-file setting is
1343 per-program-space, the set/show machinery uses this as the
1344 location of the remote exec-file value. */
1345static std::string remote_exec_file_var;
1346
1347/* The size to align memory write packets, when practical. The protocol
1348 does not guarantee any alignment, and gdb will generate short
1349 writes and unaligned writes, but even as a best-effort attempt this
1350 can improve bulk transfers. For instance, if a write is misaligned
1351 relative to the target's data bus, the stub may need to make an extra
1352 round trip fetching data from the target. This doesn't make a
1353 huge difference, but it's easy to do, so we try to be helpful.
1354
1355 The alignment chosen is arbitrary; usually data bus width is
1356 important here, not the possibly larger cache line size. */
1358
1359/* Prototypes for local functions. */
1360
1361static int hexnumlen (ULONGEST num);
1362
1363static int stubhex (int ch);
1364
1365static int hexnumstr (char *, ULONGEST);
1366
1367static int hexnumnstr (char *, ULONGEST, int);
1368
1369static CORE_ADDR remote_address_masked (CORE_ADDR);
1370
1371static int stub_unpack_int (const char *buff, int fieldlength);
1372
1373static void set_remote_protocol_packet_cmd (const char *args, int from_tty,
1374 cmd_list_element *c);
1375
1376static void show_packet_config_cmd (ui_file *file,
1377 const unsigned int which_packet,
1378 remote_target *remote);
1379
1380static void show_remote_protocol_packet_cmd (struct ui_file *file,
1381 int from_tty,
1382 struct cmd_list_element *c,
1383 const char *value);
1384
1385static ptid_t read_ptid (const char *buf, const char **obuf);
1386
1387static void remote_async_inferior_event_handler (gdb_client_data);
1388
1389static bool remote_read_description_p (struct target_ops *target);
1390
1391static void remote_console_output (const char *msg);
1392
1393static void remote_btrace_reset (remote_state *rs);
1394
1395static void remote_unpush_and_throw (remote_target *target);
1396
1397/* For "remote". */
1398
1400
1401/* For "set remote" and "show remote". */
1402
1405
1406/* Controls whether GDB is willing to use range stepping. */
1407
1408static bool use_range_stepping = true;
1409
1410/* From the remote target's point of view, each thread is in one of these three
1411 states. */
1413{
1414 /* Not resumed - we haven't been asked to resume this thread. */
1416
1417 /* We have been asked to resume this thread, but haven't sent a vCont action
1418 for it yet. We'll need to consider it next time commit_resume is
1419 called. */
1421
1422 /* We have been asked to resume this thread, and we have sent a vCont action
1423 for it. */
1424 RESUMED,
1425};
1426
1427/* Information about a thread's pending vCont-resume. Used when a thread is in
1428 the remote_resume_state::RESUMED_PENDING_VCONT state. remote_target::resume
1429 stores this information which is then picked up by
1430 remote_target::commit_resume to know which is the proper action for this
1431 thread to include in the vCont packet. */
1433{
1434 /* True if the last resume call for this thread was a step request, false
1435 if a continue request. */
1436 bool step;
1437
1438 /* The signal specified in the last resume call for this thread. */
1439 gdb_signal sig;
1440};
1441
1442/* Private data that we'll store in (struct thread_info)->priv. */
1444{
1445 std::string extra;
1446 std::string name;
1447 int core = -1;
1448
1449 /* Thread handle, perhaps a pthread_t or thread_t value, stored as a
1450 sequence of bytes. */
1451 gdb::byte_vector thread_handle;
1452
1453 /* Whether the target stopped for a breakpoint/watchpoint. */
1455
1456 /* This is set to the data address of the access causing the target
1457 to stop for a watchpoint. */
1458 CORE_ADDR watch_data_address = 0;
1459
1460 /* Get the thread's resume state. */
1462 {
1463 return m_resume_state;
1464 }
1465
1466 /* Put the thread in the NOT_RESUMED state. */
1471
1472 /* Put the thread in the RESUMED_PENDING_VCONT state. */
1479
1480 /* Get the information this thread's pending vCont-resumption.
1481
1482 Must only be called if the thread is in the RESUMED_PENDING_VCONT resume
1483 state. */
1490
1491 /* Put the thread in the VCONT_RESUMED state. */
1493 {
1495 }
1496
1497private:
1498 /* Resume state for this thread. This is used to implement vCont action
1499 coalescing (only when the target operates in non-stop mode).
1500
1501 remote_target::resume moves the thread to the RESUMED_PENDING_VCONT state,
1502 which notes that this thread must be considered in the next commit_resume
1503 call.
1504
1505 remote_target::commit_resume sends a vCont packet with actions for the
1506 threads in the RESUMED_PENDING_VCONT state and moves them to the
1507 VCONT_RESUMED state.
1508
1509 When reporting a stop to the core for a thread, that thread is moved back
1510 to the NOT_RESUMED state. */
1512
1513 /* Extra info used if the thread is in the RESUMED_PENDING_VCONT state. */
1515};
1516
1518 : buf (400)
1519{
1520}
1521
1529
1530/* Utility: generate error from an incoming stub packet. */
1531static void
1532trace_error (char *buf)
1533{
1534 if (*buf++ != 'E')
1535 return; /* not an error msg */
1536 switch (*buf)
1537 {
1538 case '1': /* malformed packet error */
1539 if (*++buf == '0') /* general case: */
1540 error (_("remote.c: error in outgoing packet."));
1541 else
1542 error (_("remote.c: error in outgoing packet at field #%ld."),
1543 strtol (buf, NULL, 16));
1544 default:
1545 error (_("Target returns error code '%s'."), buf);
1546 }
1547}
1548
1549/* Utility: wait for reply from stub, while accepting "O" packets. */
1550
1551char *
1553{
1554 struct remote_state *rs = get_remote_state ();
1555
1556 do /* Loop on reply from remote stub. */
1557 {
1558 char *buf;
1559
1560 QUIT; /* Allow user to bail out with ^C. */
1561 getpkt (&rs->buf);
1562 buf = rs->buf.data ();
1563 if (buf[0] == 'E')
1564 trace_error (buf);
1565 else if (startswith (buf, "qRelocInsn:"))
1566 {
1567 ULONGEST ul;
1568 CORE_ADDR from, to, org_to;
1569 const char *p, *pp;
1570 int adjusted_size = 0;
1571 int relocated = 0;
1572
1573 p = buf + strlen ("qRelocInsn:");
1574 pp = unpack_varlen_hex (p, &ul);
1575 if (*pp != ';')
1576 error (_("invalid qRelocInsn packet: %s"), buf);
1577 from = ul;
1578
1579 p = pp + 1;
1580 unpack_varlen_hex (p, &ul);
1581 to = ul;
1582
1583 org_to = to;
1584
1585 try
1586 {
1588 relocated = 1;
1589 }
1590 catch (const gdb_exception &ex)
1591 {
1592 if (ex.error == MEMORY_ERROR)
1593 {
1594 /* Propagate memory errors silently back to the
1595 target. The stub may have limited the range of
1596 addresses we can write to, for example. */
1597 }
1598 else
1599 {
1600 /* Something unexpectedly bad happened. Be verbose
1601 so we can tell what, and propagate the error back
1602 to the stub, so it doesn't get stuck waiting for
1603 a response. */
1605 _("warning: relocating instruction: "));
1606 }
1607 putpkt ("E01");
1608 }
1609
1610 if (relocated)
1611 {
1612 adjusted_size = to - org_to;
1613
1614 xsnprintf (buf, rs->buf.size (), "qRelocInsn:%x", adjusted_size);
1615 putpkt (buf);
1616 }
1617 }
1618 else if (buf[0] == 'O' && buf[1] != 'K')
1619 remote_console_output (buf + 1); /* 'O' message from stub */
1620 else
1621 return buf; /* Here's the actual reply. */
1622 }
1623 while (1);
1624}
1625
1626struct remote_arch_state *
1628{
1629 remote_arch_state *rsa;
1630
1631 auto it = this->m_arch_states.find (gdbarch);
1632 if (it == this->m_arch_states.end ())
1633 {
1634 auto p = this->m_arch_states.emplace (std::piecewise_construct,
1635 std::forward_as_tuple (gdbarch),
1636 std::forward_as_tuple (gdbarch));
1637 rsa = &p.first->second;
1638
1639 /* Make sure that the packet buffer is plenty big enough for
1640 this architecture. */
1641 if (this->buf.size () < rsa->remote_packet_size)
1642 this->buf.resize (2 * rsa->remote_packet_size);
1643 }
1644 else
1645 rsa = &it->second;
1646
1647 return rsa;
1648}
1649
1650/* Fetch the global remote target state. */
1651
1654{
1655 /* Make sure that the remote architecture state has been
1656 initialized, because doing so might reallocate rs->buf. Any
1657 function which calls getpkt also needs to be mindful of changes
1658 to rs->buf, but this call limits the number of places which run
1659 into trouble. */
1661
1662 return &m_remote_state;
1663}
1664
1665/* Fetch the remote exec-file from the current program space. */
1666
1667static const char *
1669{
1670 char *remote_exec_file;
1671
1672 remote_exec_file = remote_pspace_data.get (current_program_space);
1673 if (remote_exec_file == NULL)
1674 return "";
1675
1676 return remote_exec_file;
1677}
1678
1679/* Set the remote exec file for PSPACE. */
1680
1681static void
1683 const char *remote_exec_file)
1684{
1685 char *old_file = remote_pspace_data.get (pspace);
1686
1687 xfree (old_file);
1688 remote_pspace_data.set (pspace, xstrdup (remote_exec_file));
1689}
1690
1691/* The "set/show remote exec-file" set command hook. */
1692
1693static void
1694set_remote_exec_file (const char *ignored, int from_tty,
1695 struct cmd_list_element *c)
1696{
1698 remote_exec_file_var.c_str ());
1699}
1700
1701/* The "set/show remote exec-file" show command hook. */
1702
1703static void
1704show_remote_exec_file (struct ui_file *file, int from_tty,
1705 struct cmd_list_element *cmd, const char *value)
1706{
1707 gdb_printf (file, "%s\n", get_remote_exec_file ());
1708}
1709
1710static int
1712{
1713 int regnum, num_remote_regs, offset;
1714 struct packet_reg **remote_regs;
1715
1716 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
1717 {
1718 struct packet_reg *r = &regs[regnum];
1719
1720 if (register_size (gdbarch, regnum) == 0)
1721 /* Do not try to fetch zero-sized (placeholder) registers. */
1722 r->pnum = -1;
1723 else
1725
1726 r->regnum = regnum;
1727 }
1728
1729 /* Define the g/G packet format as the contents of each register
1730 with a remote protocol number, in order of ascending protocol
1731 number. */
1732
1733 remote_regs = XALLOCAVEC (struct packet_reg *, gdbarch_num_regs (gdbarch));
1734 for (num_remote_regs = 0, regnum = 0;
1736 regnum++)
1737 if (regs[regnum].pnum != -1)
1738 remote_regs[num_remote_regs++] = &regs[regnum];
1739
1740 std::sort (remote_regs, remote_regs + num_remote_regs,
1741 [] (const packet_reg *a, const packet_reg *b)
1742 { return a->pnum < b->pnum; });
1743
1744 for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
1745 {
1746 remote_regs[regnum]->in_g_packet = 1;
1747 remote_regs[regnum]->offset = offset;
1748 offset += register_size (gdbarch, remote_regs[regnum]->regnum);
1749 }
1750
1751 return offset;
1752}
1753
1754/* Given the architecture described by GDBARCH, return the remote
1755 protocol register's number and the register's offset in the g/G
1756 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
1757 If the target does not have a mapping for REGNUM, return false,
1758 otherwise, return true. */
1759
1760int
1762 int *pnum, int *poffset)
1763{
1764 gdb_assert (regnum < gdbarch_num_regs (gdbarch));
1765
1766 std::vector<packet_reg> regs (gdbarch_num_regs (gdbarch));
1767
1768 map_regcache_remote_table (gdbarch, regs.data ());
1769
1770 *pnum = regs[regnum].pnum;
1771 *poffset = regs[regnum].offset;
1772
1773 return *pnum != -1;
1774}
1775
1777{
1778 /* Use the architecture to build a regnum<->pnum table, which will be
1779 1:1 unless a feature set specifies otherwise. */
1780 this->regs.reset (new packet_reg [gdbarch_num_regs (gdbarch)] ());
1781
1782 /* Record the maximum possible size of the g packet - it may turn out
1783 to be smaller. */
1784 this->sizeof_g_packet
1785 = map_regcache_remote_table (gdbarch, this->regs.get ());
1786
1787 /* Default maximum number of characters in a packet body. Many
1788 remote stubs have a hardwired buffer size of 400 bytes
1789 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
1790 as the maximum packet-size to ensure that the packet and an extra
1791 NUL character can always fit in the buffer. This stops GDB
1792 trashing stubs that try to squeeze an extra NUL into what is
1793 already a full buffer (As of 1999-12-04 that was most stubs). */
1794 this->remote_packet_size = 400 - 1;
1795
1796 /* This one is filled in when a ``g'' packet is received. */
1798
1799 /* Should rsa->sizeof_g_packet needs more space than the
1800 default, adjust the size accordingly. Remember that each byte is
1801 encoded as two characters. 32 is the overhead for the packet
1802 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
1803 (``$NN:G...#NN'') is a better guess, the below has been padded a
1804 little. */
1805 if (this->sizeof_g_packet > ((this->remote_packet_size - 32) / 2))
1806 this->remote_packet_size = (this->sizeof_g_packet * 2 + 32);
1807}
1808
1809/* Get a pointer to the current remote target. If not connected to a
1810 remote target, return NULL. */
1811
1812static remote_target *
1814{
1815 target_ops *proc_target = current_inferior ()->process_target ();
1816 return dynamic_cast<remote_target *> (proc_target);
1817}
1818
1819/* Return the current allowed size of a remote packet. This is
1820 inferred from the current architecture, and should be used to
1821 limit the length of outgoing packets. */
1822long
1824{
1825 struct remote_state *rs = get_remote_state ();
1827
1828 if (rs->explicit_packet_size)
1829 return rs->explicit_packet_size;
1830
1831 return rsa->remote_packet_size;
1832}
1833
1834static struct packet_reg *
1836 long regnum)
1837{
1838 if (regnum < 0 && regnum >= gdbarch_num_regs (gdbarch))
1839 return NULL;
1840 else
1841 {
1842 struct packet_reg *r = &rsa->regs[regnum];
1843
1844 gdb_assert (r->regnum == regnum);
1845 return r;
1846 }
1847}
1848
1849static struct packet_reg *
1851 LONGEST pnum)
1852{
1853 int i;
1854
1855 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
1856 {
1857 struct packet_reg *r = &rsa->regs[i];
1858
1859 if (r->pnum == pnum)
1860 return r;
1861 }
1862 return NULL;
1863}
1864
1865/* Allow the user to specify what sequence to send to the remote
1866 when he requests a program interruption: Although ^C is usually
1867 what remote systems expect (this is the default, here), it is
1868 sometimes preferable to send a break. On other systems such
1869 as the Linux kernel, a break followed by g, which is Magic SysRq g
1870 is required in order to interrupt the execution. */
1871const char interrupt_sequence_control_c[] = "Ctrl-C";
1872const char interrupt_sequence_break[] = "BREAK";
1873const char interrupt_sequence_break_g[] = "BREAK-g";
1874static const char *const interrupt_sequence_modes[] =
1875 {
1879 NULL
1880 };
1882
1883static void
1884show_interrupt_sequence (struct ui_file *file, int from_tty,
1885 struct cmd_list_element *c,
1886 const char *value)
1887{
1889 gdb_printf (file,
1890 _("Send the ASCII ETX character (Ctrl-c) "
1891 "to the remote target to interrupt the "
1892 "execution of the program.\n"));
1894 gdb_printf (file,
1895 _("send a break signal to the remote target "
1896 "to interrupt the execution of the program.\n"));
1898 gdb_printf (file,
1899 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
1900 "the remote target to interrupt the execution "
1901 "of Linux kernel.\n"));
1902 else
1903 internal_error (_("Invalid value for interrupt_sequence_mode: %s."),
1905}
1906
1907/* This boolean variable specifies whether interrupt_sequence is sent
1908 to the remote target when gdb connects to it.
1909 This is mostly needed when you debug the Linux kernel: The Linux kernel
1910 expects BREAK g which is Magic SysRq g for connecting gdb. */
1911static bool interrupt_on_connect = false;
1912
1913/* This variable is used to implement the "set/show remotebreak" commands.
1914 Since these commands are now deprecated in favor of "set/show remote
1915 interrupt-sequence", it no longer has any effect on the code. */
1916static bool remote_break;
1917
1918static void
1919set_remotebreak (const char *args, int from_tty, struct cmd_list_element *c)
1920{
1921 if (remote_break)
1923 else
1925}
1926
1927static void
1928show_remotebreak (struct ui_file *file, int from_tty,
1929 struct cmd_list_element *c,
1930 const char *value)
1931{
1932}
1933
1934/* This variable sets the number of bits in an address that are to be
1935 sent in a memory ("M" or "m") packet. Normally, after stripping
1936 leading zeros, the entire address would be sent. This variable
1937 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
1938 initial implementation of remote.c restricted the address sent in
1939 memory packets to ``host::sizeof long'' bytes - (typically 32
1940 bits). Consequently, for 64 bit targets, the upper 32 bits of an
1941 address was never sent. Since fixing this bug may cause a break in
1942 some remote targets this variable is principally provided to
1943 facilitate backward compatibility. */
1944
1945static unsigned int remote_address_size;
1946
1947
1948/* The default max memory-write-packet-size, when the setting is
1949 "fixed". The 16k is historical. (It came from older GDB's using
1950 alloca for buffers and the knowledge (folklore?) that some hosts
1951 don't cope very well with large alloca calls.) */
1952#define DEFAULT_MAX_MEMORY_PACKET_SIZE_FIXED 16384
1953
1954/* The minimum remote packet size for memory transfers. Ensures we
1955 can write at least one byte. */
1956#define MIN_MEMORY_PACKET_SIZE 20
1957
1958/* Get the memory packet size, assuming it is fixed. */
1959
1960static long
1962{
1963 gdb_assert (config->fixed_p);
1964
1965 if (config->size <= 0)
1967 else
1968 return config->size;
1969}
1970
1971/* Compute the current size of a read/write packet. Since this makes
1972 use of ``actual_register_packet_size'' the computation is dynamic. */
1973
1974long
1976{
1977 struct remote_state *rs = get_remote_state ();
1979
1980 long what_they_get;
1981 if (config->fixed_p)
1982 what_they_get = get_fixed_memory_packet_size (config);
1983 else
1984 {
1985 what_they_get = get_remote_packet_size ();
1986 /* Limit the packet to the size specified by the user. */
1987 if (config->size > 0
1988 && what_they_get > config->size)
1989 what_they_get = config->size;
1990
1991 /* Limit it to the size of the targets ``g'' response unless we have
1992 permission from the stub to use a larger packet size. */
1993 if (rs->explicit_packet_size == 0
1994 && rsa->actual_register_packet_size > 0
1995 && what_they_get > rsa->actual_register_packet_size)
1996 what_they_get = rsa->actual_register_packet_size;
1997 }
1998 if (what_they_get < MIN_MEMORY_PACKET_SIZE)
1999 what_they_get = MIN_MEMORY_PACKET_SIZE;
2000
2001 /* Make sure there is room in the global buffer for this packet
2002 (including its trailing NUL byte). */
2003 if (rs->buf.size () < what_they_get + 1)
2004 rs->buf.resize (2 * what_they_get);
2005
2006 return what_they_get;
2007}
2008
2009/* Update the size of a read/write packet. If they user wants
2010 something really big then do a sanity check. */
2011
2012static void
2013set_memory_packet_size (const char *args, struct memory_packet_config *config,
2014 bool target_connected)
2015{
2016 int fixed_p = config->fixed_p;
2017 long size = config->size;
2018
2019 if (args == NULL)
2020 error (_("Argument required (integer, \"fixed\" or \"limit\")."));
2021 else if (strcmp (args, "hard") == 0
2022 || strcmp (args, "fixed") == 0)
2023 fixed_p = 1;
2024 else if (strcmp (args, "soft") == 0
2025 || strcmp (args, "limit") == 0)
2026 fixed_p = 0;
2027 else
2028 {
2029 char *end;
2030
2031 size = strtoul (args, &end, 0);
2032 if (args == end)
2033 error (_("Invalid %s (bad syntax)."), config->name);
2034
2035 /* Instead of explicitly capping the size of a packet to or
2036 disallowing it, the user is allowed to set the size to
2037 something arbitrarily large. */
2038 }
2039
2040 /* Extra checks? */
2041 if (fixed_p && !config->fixed_p)
2042 {
2043 /* So that the query shows the correct value. */
2044 long query_size = (size <= 0
2046 : size);
2047
2048 if (target_connected
2049 && !query (_("The target may not be able to correctly handle a %s\n"
2050 "of %ld bytes. Change the packet size? "),
2051 config->name, query_size))
2052 error (_("Packet size not changed."));
2053 else if (!target_connected
2054 && !query (_("Future remote targets may not be able to "
2055 "correctly handle a %s\nof %ld bytes. Change the "
2056 "packet size for future remote targets? "),
2057 config->name, query_size))
2058 error (_("Packet size not changed."));
2059 }
2060 /* Update the config. */
2061 config->fixed_p = fixed_p;
2062 config->size = size;
2063
2064 const char *target_type = get_target_type_name (target_connected);
2065 gdb_printf (_("The %s %s is set to \"%s\".\n"), config->name, target_type,
2066 args);
2067
2068}
2069
2070/* Show the memory-read or write-packet size configuration CONFIG of the
2071 target REMOTE. If REMOTE is nullptr, the default configuration for future
2072 remote targets should be passed in CONFIG. */
2073
2074static void
2076{
2077 const char *target_type = get_target_type_name (remote != nullptr);
2078
2079 if (config->size == 0)
2080 gdb_printf (_("The %s %s is 0 (default). "), config->name, target_type);
2081 else
2082 gdb_printf (_("The %s %s is %ld. "), config->name, target_type,
2083 config->size);
2084
2085 if (config->fixed_p)
2086 gdb_printf (_("Packets are fixed at %ld bytes.\n"),
2088 else
2089 {
2090 if (remote != nullptr)
2091 gdb_printf (_("Packets are limited to %ld bytes.\n"),
2092 remote->get_memory_packet_size (config));
2093 else
2094 gdb_puts ("The actual limit will be further reduced "
2095 "dependent on the target.\n");
2096 }
2097}
2098
2099/* Configure the memory-write-packet size of the currently selected target. If
2100 no target is available, the default configuration for future remote targets
2101 is configured. */
2102
2103static void
2104set_memory_write_packet_size (const char *args, int from_tty)
2105{
2107 if (remote != nullptr)
2108 {
2110 (args, &remote->m_features.m_memory_write_packet_config, true);
2111 }
2112 else
2113 {
2115 set_memory_packet_size (args, config, false);
2116 }
2117}
2118
2119/* Display the memory-write-packet size of the currently selected target. If
2120 no target is available, the default configuration for future remote targets
2121 is shown. */
2122
2123static void
2124show_memory_write_packet_size (const char *args, int from_tty)
2125{
2127 if (remote != nullptr)
2129 remote);
2130 else
2132}
2133
2134/* Show the number of hardware watchpoints that can be used. */
2135
2136static void
2137show_hardware_watchpoint_limit (struct ui_file *file, int from_tty,
2138 struct cmd_list_element *c,
2139 const char *value)
2140{
2141 gdb_printf (file, _("The maximum number of target hardware "
2142 "watchpoints is %s.\n"), value);
2143}
2144
2145/* Show the length limit (in bytes) for hardware watchpoints. */
2146
2147static void
2149 struct cmd_list_element *c,
2150 const char *value)
2151{
2152 gdb_printf (file, _("The maximum length (in bytes) of a target "
2153 "hardware watchpoint is %s.\n"), value);
2154}
2155
2156/* Show the number of hardware breakpoints that can be used. */
2157
2158static void
2159show_hardware_breakpoint_limit (struct ui_file *file, int from_tty,
2160 struct cmd_list_element *c,
2161 const char *value)
2162{
2163 gdb_printf (file, _("The maximum number of target hardware "
2164 "breakpoints is %s.\n"), value);
2165}
2166
2167/* Controls the maximum number of characters to display in the debug output
2168 for each remote packet. The remaining characters are omitted. */
2169
2171
2172/* Show the maximum number of characters to display for each remote packet
2173 when remote debugging is enabled. */
2174
2175static void
2176show_remote_packet_max_chars (struct ui_file *file, int from_tty,
2177 struct cmd_list_element *c,
2178 const char *value)
2179{
2180 gdb_printf (file, _("Number of remote packet characters to "
2181 "display is %s.\n"), value);
2182}
2183
2184long
2189
2190/* Configure the memory-read-packet size of the currently selected target. If
2191 no target is available, the default configuration for future remote targets
2192 is adapted. */
2193
2194static void
2195set_memory_read_packet_size (const char *args, int from_tty)
2196{
2198 if (remote != nullptr)
2200 (args, &remote->m_features.m_memory_read_packet_config, true);
2201 else
2202 {
2204 set_memory_packet_size (args, config, false);
2205 }
2206
2207}
2208
2209/* Display the memory-read-packet size of the currently selected target. If
2210 no target is available, the default configuration for future remote targets
2211 is shown. */
2212
2213static void
2214show_memory_read_packet_size (const char *args, int from_tty)
2215{
2217 if (remote != nullptr)
2219 remote);
2220 else
2222}
2223
2224long
2226{
2228
2229 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
2230 extra buffer size argument before the memory read size can be
2231 increased beyond this. */
2234 return size;
2235}
2236
2237static enum packet_support packet_config_support (const packet_config *config);
2238
2239
2240static void
2241set_remote_protocol_packet_cmd (const char *args, int from_tty,
2243{
2245 gdb_assert (c->var.has_value ());
2246
2247 auto *default_config = static_cast<packet_config *> (c->context ());
2248 const int packet_idx = std::distance (remote_protocol_packets,
2249 default_config);
2250
2251 if (packet_idx >= 0 && packet_idx < PACKET_MAX)
2252 {
2253 const char *name = packets_descriptions[packet_idx].name;
2254 const auto_boolean value = c->var->get<auto_boolean> ();
2255 const char *support = get_packet_support_name (value);
2256 const char *target_type = get_target_type_name (remote != nullptr);
2257
2258 if (remote != nullptr)
2259 remote->m_features.m_protocol_packets[packet_idx].detect = value;
2260 else
2261 remote_protocol_packets[packet_idx].detect = value;
2262
2263 gdb_printf (_("Support for the '%s' packet %s is set to \"%s\".\n"), name,
2264 target_type, support);
2265 return;
2266 }
2267
2268 internal_error (_("Could not find config for %s"), c->name);
2269}
2270
2271static void
2272show_packet_config_cmd (ui_file *file, const unsigned int which_packet,
2273 remote_target *remote)
2274{
2275 const char *support = "internal-error";
2276 const char *target_type = get_target_type_name (remote != nullptr);
2277
2278 packet_config *config;
2279 if (remote != nullptr)
2280 config = &remote->m_features.m_protocol_packets[which_packet];
2281 else
2282 config = &remote_protocol_packets[which_packet];
2283
2284 switch (packet_config_support (config))
2285 {
2286 case PACKET_ENABLE:
2287 support = "enabled";
2288 break;
2289 case PACKET_DISABLE:
2290 support = "disabled";
2291 break;
2293 support = "unknown";
2294 break;
2295 }
2296 switch (config->detect)
2297 {
2298 case AUTO_BOOLEAN_AUTO:
2299 gdb_printf (file,
2300 _("Support for the '%s' packet %s is \"auto\", "
2301 "currently %s.\n"),
2302 packets_descriptions[which_packet].name, target_type,
2303 support);
2304 break;
2305 case AUTO_BOOLEAN_TRUE:
2306 case AUTO_BOOLEAN_FALSE:
2307 gdb_printf (file,
2308 _("Support for the '%s' packet %s is \"%s\".\n"),
2309 packets_descriptions[which_packet].name, target_type,
2311 break;
2312 }
2313}
2314
2315static void
2316add_packet_config_cmd (const unsigned int which_packet, const char *name,
2317 const char *title, int legacy)
2318{
2319 packets_descriptions[which_packet].name = name;
2320 packets_descriptions[which_packet].title = title;
2321
2322 packet_config *config = &remote_protocol_packets[which_packet];
2323
2324 gdb::unique_xmalloc_ptr<char> set_doc
2325 = xstrprintf ("Set use of remote protocol `%s' (%s) packet.",
2326 name, title);
2327 gdb::unique_xmalloc_ptr<char> show_doc
2328 = xstrprintf ("Show current use of remote protocol `%s' (%s) packet.",
2329 name, title);
2330 /* set/show TITLE-packet {auto,on,off} */
2331 gdb::unique_xmalloc_ptr<char> cmd_name = xstrprintf ("%s-packet", title);
2333 = add_setshow_auto_boolean_cmd (cmd_name.release (), class_obscure,
2334 &config->detect, set_doc.get (),
2335 show_doc.get (), NULL, /* help_doc */
2339 cmds.show->set_context (config);
2340 cmds.set->set_context (config);
2341
2342 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
2343 if (legacy)
2344 {
2345 /* It's not clear who should take ownership of the LEGACY_NAME string
2346 created below, so, for now, place the string into a static vector
2347 which ensures the strings is released when GDB exits. */
2348 static std::vector<gdb::unique_xmalloc_ptr<char>> legacy_names;
2349 gdb::unique_xmalloc_ptr<char> legacy_name
2350 = xstrprintf ("%s-packet", name);
2351 add_alias_cmd (legacy_name.get (), cmds.set, class_obscure, 0,
2353 add_alias_cmd (legacy_name.get (), cmds.show, class_obscure, 0,
2355 legacy_names.emplace_back (std::move (legacy_name));
2356 }
2357}
2358
2359static enum packet_result
2361{
2362 if (buf[0] != '\0')
2363 {
2364 /* The stub recognized the packet request. Check that the
2365 operation succeeded. */
2366 if (buf[0] == 'E'
2367 && isxdigit (buf[1]) && isxdigit (buf[2])
2368 && buf[3] == '\0')
2369 /* "Enn" - definitely an error. */
2370 return PACKET_ERROR;
2371
2372 /* Always treat "E." as an error. This will be used for
2373 more verbose error messages, such as E.memtypes. */
2374 if (buf[0] == 'E' && buf[1] == '.')
2375 return PACKET_ERROR;
2376
2377 /* The packet may or may not be OK. Just assume it is. */
2378 return PACKET_OK;
2379 }
2380 else
2381 /* The stub does not support the packet. */
2382 return PACKET_UNKNOWN;
2383}
2384
2385static enum packet_result
2386packet_check_result (const gdb::char_vector &buf)
2387{
2388 return packet_check_result (buf.data ());
2389}
2390
2392remote_features::packet_ok (const char *buf, const int which_packet)
2393{
2394 packet_config *config = &m_protocol_packets[which_packet];
2395 packet_description *descr = &packets_descriptions[which_packet];
2396
2397 enum packet_result result;
2398
2399 if (config->detect != AUTO_BOOLEAN_TRUE
2400 && config->support == PACKET_DISABLE)
2401 internal_error (_("packet_ok: attempt to use a disabled packet"));
2402
2403 result = packet_check_result (buf);
2404 switch (result)
2405 {
2406 case PACKET_OK:
2407 case PACKET_ERROR:
2408 /* The stub recognized the packet request. */
2409 if (config->support == PACKET_SUPPORT_UNKNOWN)
2410 {
2411 remote_debug_printf ("Packet %s (%s) is supported",
2412 descr->name, descr->title);
2413 config->support = PACKET_ENABLE;
2414 }
2415 break;
2416 case PACKET_UNKNOWN:
2417 /* The stub does not support the packet. */
2418 if (config->detect == AUTO_BOOLEAN_AUTO
2419 && config->support == PACKET_ENABLE)
2420 {
2421 /* If the stub previously indicated that the packet was
2422 supported then there is a protocol error. */
2423 error (_("Protocol error: %s (%s) conflicting enabled responses."),
2424 descr->name, descr->title);
2425 }
2426 else if (config->detect == AUTO_BOOLEAN_TRUE)
2427 {
2428 /* The user set it wrong. */
2429 error (_("Enabled packet %s (%s) not recognized by stub"),
2430 descr->name, descr->title);
2431 }
2432
2433 remote_debug_printf ("Packet %s (%s) is NOT supported", descr->name,
2434 descr->title);
2435 config->support = PACKET_DISABLE;
2436 break;
2437 }
2438
2439 return result;
2440}
2441
2443remote_features::packet_ok (const gdb::char_vector &buf, const int which_packet)
2444{
2445 return packet_ok (buf.data (), which_packet);
2446}
2447
2448/* Returns whether a given packet or feature is supported. This takes
2449 into account the state of the corresponding "set remote foo-packet"
2450 command, which may be used to bypass auto-detection. */
2451
2452static enum packet_support
2454{
2455 switch (config->detect)
2456 {
2457 case AUTO_BOOLEAN_TRUE:
2458 return PACKET_ENABLE;
2459 case AUTO_BOOLEAN_FALSE:
2460 return PACKET_DISABLE;
2461 case AUTO_BOOLEAN_AUTO:
2462 return config->support;
2463 default:
2464 gdb_assert_not_reached ("bad switch");
2465 }
2466}
2467
2470{
2471 const packet_config *config = &m_protocol_packets[packet];
2472 return packet_config_support (config);
2473}
2474
2475static void
2476show_remote_protocol_packet_cmd (struct ui_file *file, int from_tty,
2477 struct cmd_list_element *c,
2478 const char *value)
2479{
2481 gdb_assert (c->var.has_value ());
2482
2483 auto *default_config = static_cast<packet_config *> (c->context ());
2484 const int packet_idx = std::distance (remote_protocol_packets,
2485 default_config);
2486
2487 if (packet_idx >= 0 && packet_idx < PACKET_MAX)
2488 {
2489 show_packet_config_cmd (file, packet_idx, remote);
2490 return;
2491 }
2492 internal_error (_("Could not find config for %s"), c->name);
2493}
2494
2495/* Should we try one of the 'Z' requests? */
2496
2506
2507/* For compatibility with older distributions. Provide a ``set remote
2508 Z-packet ...'' command that updates all the Z packet types. */
2509
2511
2512static void
2513set_remote_protocol_Z_packet_cmd (const char *args, int from_tty,
2514 struct cmd_list_element *c)
2515{
2517 int i;
2518
2519 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
2520 {
2521 if (remote != nullptr)
2524 else
2526 }
2527
2528 const char *support = get_packet_support_name (remote_Z_packet_detect);
2529 const char *target_type = get_target_type_name (remote != nullptr);
2530 gdb_printf (_("Use of Z packets %s is set to \"%s\".\n"), target_type,
2531 support);
2532
2533}
2534
2535static void
2536show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
2537 struct cmd_list_element *c,
2538 const char *value)
2539{
2541 int i;
2542
2543 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
2544 show_packet_config_cmd (file, PACKET_Z0 + i, remote);
2545}
2546
2547/* Insert fork catchpoint target routine. If fork events are enabled
2548 then return success, nothing more to do. */
2549
2550int
2555
2556/* Remove fork catchpoint target routine. Nothing to do, just
2557 return success. */
2558
2559int
2561{
2562 return 0;
2563}
2564
2565/* Insert vfork catchpoint target routine. If vfork events are enabled
2566 then return success, nothing more to do. */
2567
2568int
2573
2574/* Remove vfork catchpoint target routine. Nothing to do, just
2575 return success. */
2576
2577int
2579{
2580 return 0;
2581}
2582
2583/* Insert exec catchpoint target routine. If exec events are
2584 enabled, just return success. */
2585
2586int
2591
2592/* Remove exec catchpoint target routine. Nothing to do, just
2593 return success. */
2594
2595int
2597{
2598 return 0;
2599}
2600
2601
2602
2603/* Take advantage of the fact that the TID field is not used, to tag
2604 special ptids with it set to != 0. */
2605static const ptid_t magic_null_ptid (42000, -1, 1);
2606static const ptid_t not_sent_ptid (42000, -2, 1);
2607static const ptid_t any_thread_ptid (42000, 0, 1);
2608
2609/* Find out if the stub attached to PID (and hence GDB should offer to
2610 detach instead of killing it when bailing out). */
2611
2612int
2614{
2615 struct remote_state *rs = get_remote_state ();
2616 size_t size = get_remote_packet_size ();
2617
2619 return 0;
2620
2622 xsnprintf (rs->buf.data (), size, "qAttached:%x", pid);
2623 else
2624 xsnprintf (rs->buf.data (), size, "qAttached");
2625
2626 putpkt (rs->buf);
2627 getpkt (&rs->buf);
2628
2630 {
2631 case PACKET_OK:
2632 if (strcmp (rs->buf.data (), "1") == 0)
2633 return 1;
2634 break;
2635 case PACKET_ERROR:
2636 warning (_("Remote failure reply: %s"), rs->buf.data ());
2637 break;
2638 case PACKET_UNKNOWN:
2639 break;
2640 }
2641
2642 return 0;
2643}
2644
2645/* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
2646 has been invented by GDB, instead of reported by the target. Since
2647 we can be connected to a remote system before before knowing about
2648 any inferior, mark the target with execution when we find the first
2649 inferior. If ATTACHED is 1, then we had just attached to this
2650 inferior. If it is 0, then we just created this inferior. If it
2651 is -1, then try querying the remote stub to find out if it had
2652 attached to the inferior or not. If TRY_OPEN_EXEC is true then
2653 attempt to open this inferior's executable as the main executable
2654 if no main executable is open already. */
2655
2656inferior *
2657remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
2658 int try_open_exec)
2659{
2660 struct inferior *inf;
2661
2662 /* Check whether this process we're learning about is to be
2663 considered attached, or if is to be considered to have been
2664 spawned by the stub. */
2665 if (attached == -1)
2666 attached = remote_query_attached (pid);
2667
2669 {
2670 /* If the target shares code across all inferiors, then every
2671 attach adds a new inferior. */
2672 inf = add_inferior (pid);
2673
2674 /* ... and every inferior is bound to the same program space.
2675 However, each inferior may still have its own address
2676 space. */
2677 inf->aspace = maybe_new_address_space ();
2678 inf->pspace = current_program_space;
2679 }
2680 else
2681 {
2682 /* In the traditional debugging scenario, there's a 1-1 match
2683 between program/address spaces. We simply bind the inferior
2684 to the program space's address space. */
2685 inf = current_inferior ();
2686
2687 /* However, if the current inferior is already bound to a
2688 process, find some other empty inferior. */
2689 if (inf->pid != 0)
2690 {
2691 inf = nullptr;
2692 for (inferior *it : all_inferiors ())
2693 if (it->pid == 0)
2694 {
2695 inf = it;
2696 break;
2697 }
2698 }
2699 if (inf == nullptr)
2700 {
2701 /* Since all inferiors were already bound to a process, add
2702 a new inferior. */
2704 }
2706 inf->push_target (this);
2708 }
2709
2710 inf->attach_flag = attached;
2711 inf->fake_pid_p = fake_pid_p;
2712
2713 /* If no main executable is currently open then attempt to
2714 open the file that was executed to create this inferior. */
2715 if (try_open_exec && get_exec_file (0) == NULL)
2717
2718 /* Check for exec file mismatch, and let the user solve it. */
2720
2721 return inf;
2722}
2723
2726 ptid_t ptid);
2727
2728/* Add thread PTID to GDB's thread list. Tag it as executing/running
2729 according to EXECUTING and RUNNING respectively. If SILENT_P (or the
2730 remote_state::starting_up flag) is true then the new thread is added
2731 silently, otherwise the new thread will be announced to the user. */
2732
2734remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing,
2735 bool silent_p)
2736{
2737 struct remote_state *rs = get_remote_state ();
2738 struct thread_info *thread;
2739
2740 /* GDB historically didn't pull threads in the initial connection
2741 setup. If the remote target doesn't even have a concept of
2742 threads (e.g., a bare-metal target), even if internally we
2743 consider that a single-threaded target, mentioning a new thread
2744 might be confusing to the user. Be silent then, preserving the
2745 age old behavior. */
2746 if (rs->starting_up || silent_p)
2747 thread = add_thread_silent (this, ptid);
2748 else
2749 thread = add_thread (this, ptid);
2750
2751 /* We start by assuming threads are resumed. That state then gets updated
2752 when we process a matching stop reply. */
2754
2755 set_executing (this, ptid, executing);
2756 set_running (this, ptid, running);
2757
2758 return thread;
2759}
2760
2761/* Come here when we learn about a thread id from the remote target.
2762 It may be the first time we hear about such thread, so take the
2763 opportunity to add it to GDB's thread list. In case this is the
2764 first time we're noticing its corresponding inferior, add it to
2765 GDB's inferior list as well. EXECUTING indicates whether the
2766 thread is (internally) executing or stopped. */
2767
2768void
2769remote_target::remote_notice_new_inferior (ptid_t currthread, bool executing)
2770{
2771 /* In non-stop mode, we assume new found threads are (externally)
2772 running until proven otherwise with a stop reply. In all-stop,
2773 we can only get here if all threads are stopped. */
2774 bool running = target_is_non_stop_p ();
2775
2776 /* If this is a new thread, add it to GDB's thread list.
2777 If we leave it up to WFI to do this, bad things will happen. */
2778
2779 thread_info *tp = this->find_thread (currthread);
2780 if (tp != NULL && tp->state == THREAD_EXITED)
2781 {
2782 /* We're seeing an event on a thread id we knew had exited.
2783 This has to be a new thread reusing the old id. Add it. */
2784 remote_add_thread (currthread, running, executing, false);
2785 return;
2786 }
2787
2788 if (!in_thread_list (this, currthread))
2789 {
2790 struct inferior *inf = NULL;
2791 int pid = currthread.pid ();
2792
2793 if (inferior_ptid.is_pid ()
2794 && pid == inferior_ptid.pid ())
2795 {
2796 /* inferior_ptid has no thread member yet. This can happen
2797 with the vAttach -> remote_wait,"TAAthread:" path if the
2798 stub doesn't support qC. This is the first stop reported
2799 after an attach, so this is the main thread. Update the
2800 ptid in the thread list. */
2801 if (in_thread_list (this, ptid_t (pid)))
2802 thread_change_ptid (this, inferior_ptid, currthread);
2803 else
2804 {
2805 thread_info *thr
2806 = remote_add_thread (currthread, running, executing, false);
2807 switch_to_thread (thr);
2808 }
2809 return;
2810 }
2811
2813 {
2814 /* inferior_ptid is not set yet. This can happen with the
2815 vRun -> remote_wait,"TAAthread:" path if the stub
2816 doesn't support qC. This is the first stop reported
2817 after an attach, so this is the main thread. Update the
2818 ptid in the thread list. */
2819 thread_change_ptid (this, inferior_ptid, currthread);
2820 return;
2821 }
2822
2823 /* When connecting to a target remote, or to a target
2824 extended-remote which already was debugging an inferior, we
2825 may not know about it yet. Add it before adding its child
2826 thread, so notifications are emitted in a sensible order. */
2827 if (find_inferior_pid (this, currthread.pid ()) == NULL)
2828 {
2829 bool fake_pid_p = !m_features.remote_multi_process_p ();
2830
2831 inf = remote_add_inferior (fake_pid_p,
2832 currthread.pid (), -1, 1);
2833 }
2834
2835 /* This is really a new thread. Add it. */
2836 thread_info *new_thr
2837 = remote_add_thread (currthread, running, executing, false);
2838
2839 /* If we found a new inferior, let the common code do whatever
2840 it needs to with it (e.g., read shared libraries, insert
2841 breakpoints), unless we're just setting up an all-stop
2842 connection. */
2843 if (inf != NULL)
2844 {
2845 struct remote_state *rs = get_remote_state ();
2846
2847 if (!rs->starting_up)
2848 notice_new_inferior (new_thr, executing, 0);
2849 }
2850 }
2851}
2852
2853/* Return THREAD's private thread data, creating it if necessary. */
2854
2855static remote_thread_info *
2857{
2858 gdb_assert (thread != NULL);
2859
2860 if (thread->priv == NULL)
2861 thread->priv.reset (new remote_thread_info);
2862
2863 return gdb::checked_static_cast<remote_thread_info *> (thread->priv.get ());
2864}
2865
2866/* Return PTID's private thread data, creating it if necessary. */
2867
2868static remote_thread_info *
2870{
2871 thread_info *thr = target->find_thread (ptid);
2872 return get_remote_thread_info (thr);
2873}
2874
2875/* Call this function as a result of
2876 1) A halt indication (T packet) containing a thread id
2877 2) A direct query of currthread
2878 3) Successful execution of set thread */
2879
2880static void
2881record_currthread (struct remote_state *rs, ptid_t currthread)
2882{
2883 rs->general_thread = currthread;
2884}
2885
2886/* If 'QPassSignals' is supported, tell the remote stub what signals
2887 it can simply pass through to the inferior without reporting. */
2888
2889void
2890remote_target::pass_signals (gdb::array_view<const unsigned char> pass_signals)
2891{
2893 {
2894 char *pass_packet, *p;
2895 int count = 0;
2896 struct remote_state *rs = get_remote_state ();
2897
2898 gdb_assert (pass_signals.size () < 256);
2899 for (size_t i = 0; i < pass_signals.size (); i++)
2900 {
2901 if (pass_signals[i])
2902 count++;
2903 }
2904 pass_packet = (char *) xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
2905 strcpy (pass_packet, "QPassSignals:");
2906 p = pass_packet + strlen (pass_packet);
2907 for (size_t i = 0; i < pass_signals.size (); i++)
2908 {
2909 if (pass_signals[i])
2910 {
2911 if (i >= 16)
2912 *p++ = tohex (i >> 4);
2913 *p++ = tohex (i & 15);
2914 if (count)
2915 *p++ = ';';
2916 else
2917 break;
2918 count--;
2919 }
2920 }
2921 *p = 0;
2922 if (!rs->last_pass_packet || strcmp (rs->last_pass_packet, pass_packet))
2923 {
2924 putpkt (pass_packet);
2925 getpkt (&rs->buf);
2927 xfree (rs->last_pass_packet);
2928 rs->last_pass_packet = pass_packet;
2929 }
2930 else
2931 xfree (pass_packet);
2932 }
2933}
2934
2935/* If 'QCatchSyscalls' is supported, tell the remote stub
2936 to report syscalls to GDB. */
2937
2938int
2939remote_target::set_syscall_catchpoint (int pid, bool needed, int any_count,
2940 gdb::array_view<const int> syscall_counts)
2941{
2942 const char *catch_packet;
2943 enum packet_result result;
2944 int n_sysno = 0;
2945
2947 {
2948 /* Not supported. */
2949 return 1;
2950 }
2951
2952 if (needed && any_count == 0)
2953 {
2954 /* Count how many syscalls are to be caught. */
2955 for (size_t i = 0; i < syscall_counts.size (); i++)
2956 {
2957 if (syscall_counts[i] != 0)
2958 n_sysno++;
2959 }
2960 }
2961
2962 remote_debug_printf ("pid %d needed %d any_count %d n_sysno %d",
2963 pid, needed, any_count, n_sysno);
2964
2965 std::string built_packet;
2966 if (needed)
2967 {
2968 /* Prepare a packet with the sysno list, assuming max 8+1
2969 characters for a sysno. If the resulting packet size is too
2970 big, fallback on the non-selective packet. */
2971 const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + 1;
2972 built_packet.reserve (maxpktsz);
2973 built_packet = "QCatchSyscalls:1";
2974 if (any_count == 0)
2975 {
2976 /* Add in each syscall to be caught. */
2977 for (size_t i = 0; i < syscall_counts.size (); i++)
2978 {
2979 if (syscall_counts[i] != 0)
2980 string_appendf (built_packet, ";%zx", i);
2981 }
2982 }
2983 if (built_packet.size () > get_remote_packet_size ())
2984 {
2985 /* catch_packet too big. Fallback to less efficient
2986 non selective mode, with GDB doing the filtering. */
2987 catch_packet = "QCatchSyscalls:1";
2988 }
2989 else
2990 catch_packet = built_packet.c_str ();
2991 }
2992 else
2993 catch_packet = "QCatchSyscalls:0";
2994
2995 struct remote_state *rs = get_remote_state ();
2996
2997 putpkt (catch_packet);
2998 getpkt (&rs->buf);
3000 if (result == PACKET_OK)
3001 return 0;
3002 else
3003 return -1;
3004}
3005
3006/* If 'QProgramSignals' is supported, tell the remote stub what
3007 signals it should pass through to the inferior when detaching. */
3008
3009void
3010remote_target::program_signals (gdb::array_view<const unsigned char> signals)
3011{
3013 {
3014 char *packet, *p;
3015 int count = 0;
3016 struct remote_state *rs = get_remote_state ();
3017
3018 gdb_assert (signals.size () < 256);
3019 for (size_t i = 0; i < signals.size (); i++)
3020 {
3021 if (signals[i])
3022 count++;
3023 }
3024 packet = (char *) xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
3025 strcpy (packet, "QProgramSignals:");
3026 p = packet + strlen (packet);
3027 for (size_t i = 0; i < signals.size (); i++)
3028 {
3029 if (signal_pass_state (i))
3030 {
3031 if (i >= 16)
3032 *p++ = tohex (i >> 4);
3033 *p++ = tohex (i & 15);
3034 if (count)
3035 *p++ = ';';
3036 else
3037 break;
3038 count--;
3039 }
3040 }
3041 *p = 0;
3043 || strcmp (rs->last_program_signals_packet, packet) != 0)
3044 {
3045 putpkt (packet);
3046 getpkt (&rs->buf);
3049 rs->last_program_signals_packet = packet;
3050 }
3051 else
3052 xfree (packet);
3053 }
3054}
3055
3056/* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
3057 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
3058 thread. If GEN is set, set the general thread, if not, then set
3059 the step/continue thread. */
3060void
3061remote_target::set_thread (ptid_t ptid, int gen)
3062{
3063 struct remote_state *rs = get_remote_state ();
3064 ptid_t state = gen ? rs->general_thread : rs->continue_thread;
3065 char *buf = rs->buf.data ();
3066 char *endbuf = buf + get_remote_packet_size ();
3067
3068 if (state == ptid)
3069 return;
3070
3071 *buf++ = 'H';
3072 *buf++ = gen ? 'g' : 'c';
3073 if (ptid == magic_null_ptid)
3074 xsnprintf (buf, endbuf - buf, "0");
3075 else if (ptid == any_thread_ptid)
3076 xsnprintf (buf, endbuf - buf, "0");
3077 else if (ptid == minus_one_ptid)
3078 xsnprintf (buf, endbuf - buf, "-1");
3079 else
3080 write_ptid (buf, endbuf, ptid);
3081 putpkt (rs->buf);
3082 getpkt (&rs->buf);
3083 if (gen)
3084 rs->general_thread = ptid;
3085 else
3086 rs->continue_thread = ptid;
3087}
3088
3089void
3091{
3092 set_thread (ptid, 1);
3093}
3094
3095void
3097{
3098 set_thread (ptid, 0);
3099}
3100
3101/* Change the remote current process. Which thread within the process
3102 ends up selected isn't important, as long as it is the same process
3103 as what INFERIOR_PTID points to.
3104
3105 This comes from that fact that there is no explicit notion of
3106 "selected process" in the protocol. The selected process for
3107 general operations is the process the selected general thread
3108 belongs to. */
3109
3110void
3112{
3113 /* If the remote can't handle multiple processes, don't bother. */
3115 return;
3116
3118
3119 /* We only need to change the remote current thread if it's pointing
3120 at some other process. */
3121 if (rs->general_thread.pid () != inferior_ptid.pid ())
3123}
3124
3125
3126/* Return nonzero if this is the main thread that we made up ourselves
3127 to model non-threaded targets as single-threaded. */
3128
3129static int
3131{
3132 if (ptid == magic_null_ptid)
3133 /* The main thread is always alive. */
3134 return 1;
3135
3136 if (ptid.pid () != 0 && ptid.lwp () == 0)
3137 /* The main thread is always alive. This can happen after a
3138 vAttach, if the remote side doesn't support
3139 multi-threading. */
3140 return 1;
3141
3142 return 0;
3143}
3144
3145/* Return nonzero if the thread PTID is still alive on the remote
3146 system. */
3147
3148bool
3150{
3151 struct remote_state *rs = get_remote_state ();
3152 char *p, *endp;
3153
3154 /* Check if this is a thread that we made up ourselves to model
3155 non-threaded targets as single-threaded. */
3156 if (remote_thread_always_alive (ptid))
3157 return 1;
3158
3159 p = rs->buf.data ();
3160 endp = p + get_remote_packet_size ();
3161
3162 *p++ = 'T';
3163 write_ptid (p, endp, ptid);
3164
3165 putpkt (rs->buf);
3166 getpkt (&rs->buf);
3167 return (rs->buf[0] == 'O' && rs->buf[1] == 'K');
3168}
3169
3170/* Return a pointer to a thread name if we know it and NULL otherwise.
3171 The thread_info object owns the memory for the name. */
3172
3173const char *
3175{
3176 if (info->priv != NULL)
3177 {
3178 const std::string &name = get_remote_thread_info (info)->name;
3179 return !name.empty () ? name.c_str () : NULL;
3180 }
3181
3182 return NULL;
3183}
3184
3185/* About these extended threadlist and threadinfo packets. They are
3186 variable length packets but, the fields within them are often fixed
3187 length. They are redundant enough to send over UDP as is the
3188 remote protocol in general. There is a matching unit test module
3189 in libstub. */
3190
3191/* WARNING: This threadref data structure comes from the remote O.S.,
3192 libstub protocol encoding, and remote.c. It is not particularly
3193 changeable. */
3194
3195/* Right now, the internal structure is int. We want it to be bigger.
3196 Plan to fix this. */
3197
3198typedef int gdb_threadref; /* Internal GDB thread reference. */
3199
3200/* gdb_ext_thread_info is an internal GDB data structure which is
3201 equivalent to the reply of the remote threadinfo packet. */
3202
3204 {
3205 threadref threadid; /* External form of thread reference. */
3206 int active; /* Has state interesting to GDB?
3207 regs, stack. */
3208 char display[256]; /* Brief state display, name,
3209 blocked/suspended. */
3210 char shortname[32]; /* To be used to name threads. */
3211 char more_display[256]; /* Long info, statistics, queue depth,
3212 whatever. */
3213 };
3214
3215/* The volume of remote transfers can be limited by submitting
3216 a mask containing bits specifying the desired information.
3217 Use a union of these values as the 'selection' parameter to
3218 get_thread_info. FIXME: Make these TAG names more thread specific. */
3219
3220#define TAG_THREADID 1
3221#define TAG_EXISTS 2
3222#define TAG_DISPLAY 4
3223#define TAG_THREADNAME 8
3224#define TAG_MOREDISPLAY 16
3225
3226#define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
3227
3228static const char *unpack_nibble (const char *buf, int *val);
3229
3230static const char *unpack_byte (const char *buf, int *value);
3231
3232static char *pack_int (char *buf, int value);
3233
3234static const char *unpack_int (const char *buf, int *value);
3235
3236static const char *unpack_string (const char *src, char *dest, int length);
3237
3238static char *pack_threadid (char *pkt, threadref *id);
3239
3240static const char *unpack_threadid (const char *inbuf, threadref *id);
3241
3242void int_to_threadref (threadref *id, int value);
3243
3244static int threadref_to_int (threadref *ref);
3245
3246static void copy_threadref (threadref *dest, threadref *src);
3247
3248static int threadmatch (threadref *dest, threadref *src);
3249
3250static char *pack_threadinfo_request (char *pkt, int mode,
3251 threadref *id);
3252
3253static char *pack_threadlist_request (char *pkt, int startflag,
3254 int threadcount,
3255 threadref *nextthread);
3256
3257static int remote_newthread_step (threadref *ref, void *context);
3258
3259
3260/* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
3261 buffer we're allowed to write to. Returns
3262 BUF+CHARACTERS_WRITTEN. */
3263
3264char *
3265remote_target::write_ptid (char *buf, const char *endbuf, ptid_t ptid)
3266{
3267 int pid, tid;
3268
3270 {
3271 pid = ptid.pid ();
3272 if (pid < 0)
3273 buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
3274 else
3275 buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
3276 }
3277 tid = ptid.lwp ();
3278 if (tid < 0)
3279 buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
3280 else
3281 buf += xsnprintf (buf, endbuf - buf, "%x", tid);
3282
3283 return buf;
3284}
3285
3286/* Extract a PTID from BUF. If non-null, OBUF is set to one past the
3287 last parsed char. Returns null_ptid if no thread id is found, and
3288 throws an error if the thread id has an invalid format. */
3289
3290static ptid_t
3291read_ptid (const char *buf, const char **obuf)
3292{
3293 const char *p = buf;
3294 const char *pp;
3295 ULONGEST pid = 0, tid = 0;
3296
3297 if (*p == 'p')
3298 {
3299 /* Multi-process ptid. */
3300 pp = unpack_varlen_hex (p + 1, &pid);
3301 if (*pp != '.')
3302 error (_("invalid remote ptid: %s"), p);
3303
3304 p = pp;
3305 pp = unpack_varlen_hex (p + 1, &tid);
3306 if (obuf)
3307 *obuf = pp;
3308 return ptid_t (pid, tid);
3309 }
3310
3311 /* No multi-process. Just a tid. */
3312 pp = unpack_varlen_hex (p, &tid);
3313
3314 /* Return null_ptid when no thread id is found. */
3315 if (p == pp)
3316 {
3317 if (obuf)
3318 *obuf = pp;
3319 return null_ptid;
3320 }
3321
3322 /* Since the stub is not sending a process id, default to what's
3323 current_inferior, unless it doesn't have a PID yet. If so,
3324 then since there's no way to know the pid of the reported
3325 threads, use the magic number. */
3327 if (inf->pid == 0)
3328 pid = magic_null_ptid.pid ();
3329 else
3330 pid = inf->pid;
3331
3332 if (obuf)
3333 *obuf = pp;
3334 return ptid_t (pid, tid);
3335}
3336
3337static int
3338stubhex (int ch)
3339{
3340 if (ch >= 'a' && ch <= 'f')
3341 return ch - 'a' + 10;
3342 if (ch >= '0' && ch <= '9')
3343 return ch - '0';
3344 if (ch >= 'A' && ch <= 'F')
3345 return ch - 'A' + 10;
3346 return -1;
3347}
3348
3349static int
3350stub_unpack_int (const char *buff, int fieldlength)
3351{
3352 int nibble;
3353 int retval = 0;
3354
3355 while (fieldlength)
3356 {
3357 nibble = stubhex (*buff++);
3358 retval |= nibble;
3359 fieldlength--;
3360 if (fieldlength)
3361 retval = retval << 4;
3362 }
3363 return retval;
3364}
3365
3366static const char *
3367unpack_nibble (const char *buf, int *val)
3368{
3369 *val = fromhex (*buf++);
3370 return buf;
3371}
3372
3373static const char *
3374unpack_byte (const char *buf, int *value)
3375{
3376 *value = stub_unpack_int (buf, 2);
3377 return buf + 2;
3378}
3379
3380static char *
3381pack_int (char *buf, int value)
3382{
3383 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
3384 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
3385 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
3386 buf = pack_hex_byte (buf, (value & 0xff));
3387 return buf;
3388}
3389
3390static const char *
3391unpack_int (const char *buf, int *value)
3392{
3393 *value = stub_unpack_int (buf, 8);
3394 return buf + 8;
3395}
3396
3397#if 0 /* Currently unused, uncomment when needed. */
3398static char *pack_string (char *pkt, char *string);
3399
3400static char *
3401pack_string (char *pkt, char *string)
3402{
3403 char ch;
3404 int len;
3405
3406 len = strlen (string);
3407 if (len > 200)
3408 len = 200; /* Bigger than most GDB packets, junk??? */
3409 pkt = pack_hex_byte (pkt, len);
3410 while (len-- > 0)
3411 {
3412 ch = *string++;
3413 if ((ch == '\0') || (ch == '#'))
3414 ch = '*'; /* Protect encapsulation. */
3415 *pkt++ = ch;
3416 }
3417 return pkt;
3418}
3419#endif /* 0 (unused) */
3420
3421static const char *
3422unpack_string (const char *src, char *dest, int length)
3423{
3424 while (length--)
3425 *dest++ = *src++;
3426 *dest = '\0';
3427 return src;
3428}
3429
3430static char *
3431pack_threadid (char *pkt, threadref *id)
3432{
3433 char *limit;
3434 unsigned char *altid;
3435
3436 altid = (unsigned char *) id;
3437 limit = pkt + BUF_THREAD_ID_SIZE;
3438 while (pkt < limit)
3439 pkt = pack_hex_byte (pkt, *altid++);
3440 return pkt;
3441}
3442
3443
3444static const char *
3445unpack_threadid (const char *inbuf, threadref *id)
3446{
3447 char *altref;
3448 const char *limit = inbuf + BUF_THREAD_ID_SIZE;
3449 int x, y;
3450
3451 altref = (char *) id;
3452
3453 while (inbuf < limit)
3454 {
3455 x = stubhex (*inbuf++);
3456 y = stubhex (*inbuf++);
3457 *altref++ = (x << 4) | y;
3458 }
3459 return inbuf;
3460}
3461
3462/* Externally, threadrefs are 64 bits but internally, they are still
3463 ints. This is due to a mismatch of specifications. We would like
3464 to use 64bit thread references internally. This is an adapter
3465 function. */
3466
3467void
3469{
3470 unsigned char *scan;
3471
3472 scan = (unsigned char *) id;
3473 {
3474 int i = 4;
3475 while (i--)
3476 *scan++ = 0;
3477 }
3478 *scan++ = (value >> 24) & 0xff;
3479 *scan++ = (value >> 16) & 0xff;
3480 *scan++ = (value >> 8) & 0xff;
3481 *scan++ = (value & 0xff);
3482}
3483
3484static int
3486{
3487 int i, value = 0;
3488 unsigned char *scan;
3489
3490 scan = *ref;
3491 scan += 4;
3492 i = 4;
3493 while (i-- > 0)
3494 value = (value << 8) | ((*scan++) & 0xff);
3495 return value;
3496}
3497
3498static void
3500{
3501 int i;
3502 unsigned char *csrc, *cdest;
3503
3504 csrc = (unsigned char *) src;
3505 cdest = (unsigned char *) dest;
3506 i = 8;
3507 while (i--)
3508 *cdest++ = *csrc++;
3509}
3510
3511static int
3513{
3514 /* Things are broken right now, so just assume we got a match. */
3515#if 0
3516 unsigned char *srcp, *destp;
3517 int i, result;
3518 srcp = (char *) src;
3519 destp = (char *) dest;
3520
3521 result = 1;
3522 while (i-- > 0)
3523 result &= (*srcp++ == *destp++) ? 1 : 0;
3524 return result;
3525#endif
3526 return 1;
3527}
3528
3529/*
3530 threadid:1, # always request threadid
3531 context_exists:2,
3532 display:4,
3533 unique_name:8,
3534 more_display:16
3535 */
3536
3537/* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
3538
3539static char *
3540pack_threadinfo_request (char *pkt, int mode, threadref *id)
3541{
3542 *pkt++ = 'q'; /* Info Query */
3543 *pkt++ = 'P'; /* process or thread info */
3544 pkt = pack_int (pkt, mode); /* mode */
3545 pkt = pack_threadid (pkt, id); /* threadid */
3546 *pkt = '\0'; /* terminate */
3547 return pkt;
3548}
3549
3550/* These values tag the fields in a thread info response packet. */
3551/* Tagging the fields allows us to request specific fields and to
3552 add more fields as time goes by. */
3553
3554#define TAG_THREADID 1 /* Echo the thread identifier. */
3555#define TAG_EXISTS 2 /* Is this process defined enough to
3556 fetch registers and its stack? */
3557#define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
3558#define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
3559#define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
3560 the process. */
3562int
3564 threadref *expectedref,
3565 gdb_ext_thread_info *info)
3566{
3567 struct remote_state *rs = get_remote_state ();
3568 int mask, length;
3569 int tag;
3570 threadref ref;
3571 const char *limit = pkt + rs->buf.size (); /* Plausible parsing limit. */
3572 int retval = 1;
3573
3574 /* info->threadid = 0; FIXME: implement zero_threadref. */
3575 info->active = 0;
3576 info->display[0] = '\0';
3577 info->shortname[0] = '\0';
3578 info->more_display[0] = '\0';
3579
3580 /* Assume the characters indicating the packet type have been
3581 stripped. */
3582 pkt = unpack_int (pkt, &mask); /* arg mask */
3583 pkt = unpack_threadid (pkt, &ref);
3584
3585 if (mask == 0)
3586 warning (_("Incomplete response to threadinfo request."));
3587 if (!threadmatch (&ref, expectedref))
3588 { /* This is an answer to a different request. */
3589 warning (_("ERROR RMT Thread info mismatch."));
3590 return 0;
3591 }
3592 copy_threadref (&info->threadid, &ref);
3593
3594 /* Loop on tagged fields , try to bail if something goes wrong. */
3595
3596 /* Packets are terminated with nulls. */
3597 while ((pkt < limit) && mask && *pkt)
3598 {
3599 pkt = unpack_int (pkt, &tag); /* tag */
3600 pkt = unpack_byte (pkt, &length); /* length */
3601 if (!(tag & mask)) /* Tags out of synch with mask. */
3602 {
3603 warning (_("ERROR RMT: threadinfo tag mismatch."));
3604 retval = 0;
3605 break;
3606 }
3607 if (tag == TAG_THREADID)
3608 {
3609 if (length != 16)
3610 {
3611 warning (_("ERROR RMT: length of threadid is not 16."));
3612 retval = 0;
3613 break;
3614 }
3615 pkt = unpack_threadid (pkt, &ref);
3616 mask = mask & ~TAG_THREADID;
3617 continue;
3618 }
3619 if (tag == TAG_EXISTS)
3620 {
3621 info->active = stub_unpack_int (pkt, length);
3622 pkt += length;
3623 mask = mask & ~(TAG_EXISTS);
3624 if (length > 8)
3625 {
3626 warning (_("ERROR RMT: 'exists' length too long."));
3627 retval = 0;
3628 break;
3629 }
3630 continue;
3631 }
3632 if (tag == TAG_THREADNAME)
3633 {
3634 pkt = unpack_string (pkt, &info->shortname[0], length);
3635 mask = mask & ~TAG_THREADNAME;
3636 continue;
3637 }
3638 if (tag == TAG_DISPLAY)
3639 {
3640 pkt = unpack_string (pkt, &info->display[0], length);
3641 mask = mask & ~TAG_DISPLAY;
3642 continue;
3643 }
3644 if (tag == TAG_MOREDISPLAY)
3645 {
3646 pkt = unpack_string (pkt, &info->more_display[0], length);
3647 mask = mask & ~TAG_MOREDISPLAY;
3648 continue;
3649 }
3650 warning (_("ERROR RMT: unknown thread info tag."));
3651 break; /* Not a tag we know about. */
3652 }
3653 return retval;
3654}
3656int
3658 int fieldset,
3659 gdb_ext_thread_info *info)
3660{
3661 struct remote_state *rs = get_remote_state ();
3662 int result;
3663
3664 pack_threadinfo_request (rs->buf.data (), fieldset, threadid);
3665 putpkt (rs->buf);
3666 getpkt (&rs->buf);
3667
3668 if (rs->buf[0] == '\0')
3669 return 0;
3670
3671 result = remote_unpack_thread_info_response (&rs->buf[2],
3672 threadid, info);
3673 return result;
3674}
3675
3676/* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
3678static char *
3679pack_threadlist_request (char *pkt, int startflag, int threadcount,
3681{
3682 *pkt++ = 'q'; /* info query packet */
3683 *pkt++ = 'L'; /* Process LIST or threadLIST request */
3684 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
3685 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
3686 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
3687 *pkt = '\0';
3688 return pkt;
3689}
3690
3691/* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
3693int
3694remote_target::parse_threadlist_response (const char *pkt, int result_limit,
3695 threadref *original_echo,
3696 threadref *resultlist,
3697 int *doneflag)
3698{
3699 struct remote_state *rs = get_remote_state ();
3700 int count, resultcount, done;
3701
3702 resultcount = 0;
3703 /* Assume the 'q' and 'M chars have been stripped. */
3704 const char *limit = pkt + (rs->buf.size () - BUF_THREAD_ID_SIZE);
3705 /* done parse past here */
3706 pkt = unpack_byte (pkt, &count); /* count field */
3707 pkt = unpack_nibble (pkt, &done);
3708 /* The first threadid is the argument threadid. */
3709 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
3710 while ((count-- > 0) && (pkt < limit))
3711 {
3712 pkt = unpack_threadid (pkt, resultlist++);
3713 if (resultcount++ >= result_limit)
3714 break;
3715 }
3716 if (doneflag)
3717 *doneflag = done;
3718 return resultcount;
3719}
3720
3721/* Fetch the next batch of threads from the remote. Returns -1 if the
3722 qL packet is not supported, 0 on error and 1 on success. */
3724int
3726 int result_limit, int *done, int *result_count,
3727 threadref *threadlist)
3728{
3729 struct remote_state *rs = get_remote_state ();
3730 int result = 1;
3731
3732 /* Truncate result limit to be smaller than the packet size. */
3733 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10)
3735 result_limit = (get_remote_packet_size () / BUF_THREAD_ID_SIZE) - 2;
3736
3737 pack_threadlist_request (rs->buf.data (), startflag, result_limit,
3738 nextthread);
3739 putpkt (rs->buf);
3740 getpkt (&rs->buf);
3741 if (rs->buf[0] == '\0')
3742 {
3743 /* Packet not supported. */
3744 return -1;
3745 }
3746
3747 *result_count =
3748 parse_threadlist_response (&rs->buf[2], result_limit,
3749 &rs->echo_nextthread, threadlist, done);
3750
3751 if (!threadmatch (&rs->echo_nextthread, nextthread))
3752 {
3753 /* FIXME: This is a good reason to drop the packet. */
3754 /* Possibly, there is a duplicate response. */
3755 /* Possibilities :
3756 retransmit immediatly - race conditions
3757 retransmit after timeout - yes
3758 exit
3759 wait for packet, then exit
3760 */
3761 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
3762 return 0; /* I choose simply exiting. */
3763 }
3764 if (*result_count <= 0)
3765 {
3766 if (*done != 1)
3767 {
3768 warning (_("RMT ERROR : failed to get remote thread list."));
3769 result = 0;
3770 }
3771 return result; /* break; */
3772 }
3773 if (*result_count > result_limit)
3774 {
3775 *result_count = 0;
3776 warning (_("RMT ERROR: threadlist response longer than requested."));
3777 return 0;
3778 }
3779 return result;
3780}
3781
3782/* Fetch the list of remote threads, with the qL packet, and call
3783 STEPFUNCTION for each thread found. Stops iterating and returns 1
3784 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
3785 STEPFUNCTION returns false. If the packet is not supported,
3786 returns -1. */
3788int
3790 void *context, int looplimit)
3791{
3792 struct remote_state *rs = get_remote_state ();
3793 int done, i, result_count;
3794 int startflag = 1;
3795 int result = 1;
3796 int loopcount = 0;
3797
3798 done = 0;
3799 while (!done)
3800 {
3801 if (loopcount++ > looplimit)
3802 {
3803 result = 0;
3804 warning (_("Remote fetch threadlist -infinite loop-."));
3805 break;
3806 }
3807 result = remote_get_threadlist (startflag, &rs->nextthread,
3809 &done, &result_count,
3810 rs->resultthreadlist);
3811 if (result <= 0)
3812 break;
3813 /* Clear for later iterations. */
3814 startflag = 0;
3815 /* Setup to resume next batch of thread references, set nextthread. */
3816 if (result_count >= 1)
3818 &rs->resultthreadlist[result_count - 1]);
3819 i = 0;
3820 while (result_count--)
3821 {
3822 if (!(*stepfunction) (&rs->resultthreadlist[i++], context))
3823 {
3824 result = 0;
3825 break;
3826 }
3827 }
3828 }
3829 return result;
3830}
3831
3832/* A thread found on the remote target. */
3833
3835{
3836 explicit thread_item (ptid_t ptid_)
3837 : ptid (ptid_)
3840 thread_item (thread_item &&other) = default;
3842
3845 /* The thread's PTID. */
3846 ptid_t ptid;
3848 /* The thread's extra info. */
3849 std::string extra;
3851 /* The thread's name. */
3852 std::string name;
3854 /* The core the thread was running on. -1 if not known. */
3855 int core = -1;
3857 /* The thread handle associated with the thread. */
3858 gdb::byte_vector thread_handle;
3859};
3860
3861/* Context passed around to the various methods listing remote
3862 threads. As new threads are found, they're added to the ITEMS
3863 vector. */
3864
3866{
3867 /* Return true if this object contains an entry for a thread with ptid
3868 PTID. */
3869
3870 bool contains_thread (ptid_t ptid) const
3871 {
3872 auto match_ptid = [&] (const thread_item &item)
3873 {
3874 return item.ptid == ptid;
3875 };
3876
3877 auto it = std::find_if (this->items.begin (),
3878 this->items.end (),
3879 match_ptid);
3880
3881 return it != this->items.end ();
3882 }
3883
3884 /* Remove the thread with ptid PTID. */
3885
3886 void remove_thread (ptid_t ptid)
3887 {
3888 auto match_ptid = [&] (const thread_item &item)
3889 {
3890 return item.ptid == ptid;
3891 };
3892
3893 auto it = std::remove_if (this->items.begin (),
3894 this->items.end (),
3895 match_ptid);
3896
3897 if (it != this->items.end ())
3898 this->items.erase (it);
3899 }
3901 /* The threads found on the remote target. */
3902 std::vector<thread_item> items;
3903};
3905static int
3906remote_newthread_step (threadref *ref, void *data)
3907{
3908 struct threads_listing_context *context
3909 = (struct threads_listing_context *) data;
3910 int pid = inferior_ptid.pid ();
3911 int lwp = threadref_to_int (ref);
3912 ptid_t ptid (pid, lwp);
3913
3914 context->items.emplace_back (ptid);
3915
3916 return 1; /* continue iterator */
3918
3919#define CRAZY_MAX_THREADS 1000
3921ptid_t
3923{
3924 struct remote_state *rs = get_remote_state ();
3925
3926 putpkt ("qC");
3927 getpkt (&rs->buf);
3928 if (rs->buf[0] == 'Q' && rs->buf[1] == 'C')
3929 {
3930 const char *obuf;
3931 ptid_t result;
3932
3933 result = read_ptid (&rs->buf[2], &obuf);
3934 if (*obuf != '\0')
3935 remote_debug_printf ("warning: garbage in qC reply");
3936
3937 return result;
3938 }
3939 else
3940 return oldpid;
3941}
3942
3943/* List remote threads using the deprecated qL packet. */
3952 return 0;
3953}
3954
3955#if defined(HAVE_LIBEXPAT)
3956
3957static void
3958start_thread (struct gdb_xml_parser *parser,
3959 const struct gdb_xml_element *element,
3960 void *user_data,
3961 std::vector<gdb_xml_value> &attributes)
3962{
3963 struct threads_listing_context *data
3964 = (struct threads_listing_context *) user_data;
3965 struct gdb_xml_value *attr;
3966
3967 char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
3968 ptid_t ptid = read_ptid (id, NULL);
3969
3970 data->items.emplace_back (ptid);
3971 thread_item &item = data->items.back ();
3972
3973 attr = xml_find_attribute (attributes, "core");
3974 if (attr != NULL)
3975 item.core = *(ULONGEST *) attr->value.get ();
3976
3977 attr = xml_find_attribute (attributes, "name");
3978 if (attr != NULL)
3979 item.name = (const char *) attr->value.get ();
3980
3981 attr = xml_find_attribute (attributes, "handle");
3982 if (attr != NULL)
3983 item.thread_handle = hex2bin ((const char *) attr->value.get ());
3984}
3985
3986static void
3987end_thread (struct gdb_xml_parser *parser,
3988 const struct gdb_xml_element *element,
3989 void *user_data, const char *body_text)
3990{
3992 = (struct threads_listing_context *) user_data;
3993
3994 if (body_text != NULL && *body_text != '\0')
3995 data->items.back ().extra = body_text;
3996}
3997
3998const struct gdb_xml_attribute thread_attributes[] = {
3999 { "id", GDB_XML_AF_NONE, NULL, NULL },
4001 { "name", GDB_XML_AF_OPTIONAL, NULL, NULL },
4002 { "handle", GDB_XML_AF_OPTIONAL, NULL, NULL },
4003 { NULL, GDB_XML_AF_NONE, NULL, NULL }
4004};
4005
4006const struct gdb_xml_element thread_children[] = {
4007 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4008};
4009
4010const struct gdb_xml_element threads_children[] = {
4011 { "thread", thread_attributes, thread_children,
4013 start_thread, end_thread },
4014 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4015};
4016
4017const struct gdb_xml_element threads_elements[] = {
4018 { "threads", NULL, threads_children,
4019 GDB_XML_EF_NONE, NULL, NULL },
4020 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4021};
4022
4023#endif
4024
4025/* List remote threads using qXfer:threads:read. */
4027int
4029{
4030#if defined(HAVE_LIBEXPAT)
4032 {
4033 gdb::optional<gdb::char_vector> xml
4035
4036 if (xml && (*xml)[0] != '\0')
4037 {
4038 gdb_xml_parse_quick (_("threads"), "threads.dtd",
4039 threads_elements, xml->data (), context);
4040 }
4041
4042 return 1;
4043 }
4044#endif
4045
4046 return 0;
4047}
4048
4049/* List remote threads using qfThreadInfo/qsThreadInfo. */
4051int
4053{
4054 struct remote_state *rs = get_remote_state ();
4055
4056 if (rs->use_threadinfo_query)
4057 {
4058 const char *bufp;
4059
4060 putpkt ("qfThreadInfo");
4061 getpkt (&rs->buf);
4062 bufp = rs->buf.data ();
4063 if (bufp[0] != '\0') /* q packet recognized */
4064 {
4065 while (*bufp++ == 'm') /* reply contains one or more TID */
4066 {
4067 do
4068 {
4069 ptid_t ptid = read_ptid (bufp, &bufp);
4070 context->items.emplace_back (ptid);
4071 }
4072 while (*bufp++ == ','); /* comma-separated list */
4073 putpkt ("qsThreadInfo");
4074 getpkt (&rs->buf);
4075 bufp = rs->buf.data ();
4076 }
4077 return 1;
4078 }
4079 else
4080 {
4081 /* Packet not recognized. */
4082 rs->use_threadinfo_query = 0;
4083 }
4084 }
4085
4086 return 0;
4087}
4088
4089/* Return true if INF only has one non-exited thread. */
4091static bool
4093{
4094 int count = 0;
4095 for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
4096 if (++count > 1)
4097 break;
4098 return count == 1;
4099}
4100
4101/* Implement the to_update_thread_list function for the remote
4102 targets. */
4104void
4106{
4107 struct threads_listing_context context;
4108 int got_list = 0;
4109
4110 /* We have a few different mechanisms to fetch the thread list. Try
4111 them all, starting with the most preferred one first, falling
4112 back to older methods. */
4113 if (remote_get_threads_with_qxfer (&context)
4115 || remote_get_threads_with_ql (&context))
4116 {
4117 got_list = 1;
4118
4119 if (context.items.empty ()
4121 {
4122 /* Some targets don't really support threads, but still
4123 reply an (empty) thread list in response to the thread
4124 listing packets, instead of replying "packet not
4125 supported". Exit early so we don't delete the main
4126 thread. */
4127 return;
4128 }
4129
4130 /* CONTEXT now holds the current thread list on the remote
4131 target end. Delete GDB-side threads no longer found on the
4132 target. */
4133 for (thread_info *tp : all_threads_safe ())
4134 {
4135 if (tp->inf->process_target () != this)
4136 continue;
4137
4138 if (!context.contains_thread (tp->ptid))
4139 {
4140 /* Do not remove the thread if it is the last thread in
4141 the inferior. This situation happens when we have a
4142 pending exit process status to process. Otherwise we
4143 may end up with a seemingly live inferior (i.e. pid
4144 != 0) that has no threads. */
4145 if (has_single_non_exited_thread (tp->inf))
4146 continue;
4147
4148 /* Not found. */
4149 delete_thread (tp);
4150 }
4151 }
4152
4153 /* Remove any unreported fork child threads from CONTEXT so
4154 that we don't interfere with follow fork, which is where
4155 creation of such threads is handled. */
4156 remove_new_fork_children (&context);
4157
4158 /* And now add threads we don't know about yet to our list. */
4159 for (thread_item &item : context.items)
4160 {
4161 if (item.ptid != null_ptid)
4162 {
4163 /* In non-stop mode, we assume new found threads are
4164 executing until proven otherwise with a stop reply.
4165 In all-stop, we can only get here if all threads are
4166 stopped. */
4167 bool executing = target_is_non_stop_p ();
4168
4169 remote_notice_new_inferior (item.ptid, executing);
4170
4171 thread_info *tp = this->find_thread (item.ptid);
4173 info->core = item.core;
4174 info->extra = std::move (item.extra);
4175 info->name = std::move (item.name);
4176 info->thread_handle = std::move (item.thread_handle);
4177 }
4178 }
4179 }
4180
4181 if (!got_list)
4182 {
4183 /* If no thread listing method is supported, then query whether
4184 each known thread is alive, one by one, with the T packet.
4185 If the target doesn't support threads at all, then this is a
4186 no-op. See remote_thread_alive. */
4187 prune_threads ();
4188 }
4189}
4190
4191/*
4192 * Collect a descriptive string about the given thread.
4193 * The target may say anything it wants to about the thread
4194 * (typically info about its blocked / runnable state, name, etc.).
4195 * This string will appear in the info threads display.
4196 *
4197 * Optional: targets are not required to implement this function.
4198 */
4200const char *
4202{
4203 struct remote_state *rs = get_remote_state ();
4204 int set;
4205 threadref id;
4206 struct gdb_ext_thread_info threadinfo;
4207
4208 if (rs->remote_desc == 0) /* paranoia */
4209 internal_error (_("remote_threads_extra_info"));
4210
4211 if (tp->ptid == magic_null_ptid
4212 || (tp->ptid.pid () != 0 && tp->ptid.lwp () == 0))
4213 /* This is the main thread which was added by GDB. The remote
4214 server doesn't know about it. */
4215 return NULL;
4216
4217 std::string &extra = get_remote_thread_info (tp)->extra;
4218
4219 /* If already have cached info, use it. */
4220 if (!extra.empty ())
4221 return extra.c_str ();
4222
4224 {
4225 /* If we're using qXfer:threads:read, then the extra info is
4226 included in the XML. So if we didn't have anything cached,
4227 it's because there's really no extra info. */
4228 return NULL;
4229 }
4230
4231 if (rs->use_threadextra_query)
4232 {
4233 char *b = rs->buf.data ();
4234 char *endb = b + get_remote_packet_size ();
4235
4236 xsnprintf (b, endb - b, "qThreadExtraInfo,");
4237 b += strlen (b);
4238 write_ptid (b, endb, tp->ptid);
4239
4240 putpkt (rs->buf);
4241 getpkt (&rs->buf);
4242 if (rs->buf[0] != 0)
4243 {
4244 extra.resize (strlen (rs->buf.data ()) / 2);
4245 hex2bin (rs->buf.data (), (gdb_byte *) &extra[0], extra.size ());
4246 return extra.c_str ();
4247 }
4248 }
4249
4250 /* If the above query fails, fall back to the old method. */
4251 rs->use_threadextra_query = 0;
4254 int_to_threadref (&id, tp->ptid.lwp ());
4255 if (remote_get_threadinfo (&id, set, &threadinfo))
4256 if (threadinfo.active)
4257 {
4258 if (*threadinfo.shortname)
4259 string_appendf (extra, " Name: %s", threadinfo.shortname);
4260 if (*threadinfo.display)
4261 {
4262 if (!extra.empty ())
4263 extra += ',';
4264 string_appendf (extra, " State: %s", threadinfo.display);
4265 }
4266 if (*threadinfo.more_display)
4267 {
4268 if (!extra.empty ())
4269 extra += ',';
4270 string_appendf (extra, " Priority: %s", threadinfo.more_display);
4271 }
4272 return extra.c_str ();
4273 }
4274 return NULL;
4275}
4276
4278bool
4280 struct static_tracepoint_marker *marker)
4281{
4282 struct remote_state *rs = get_remote_state ();
4283 char *p = rs->buf.data ();
4284
4285 xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
4286 p += strlen (p);
4287 p += hexnumstr (p, addr);
4288 putpkt (rs->buf);
4289 getpkt (&rs->buf);
4290 p = rs->buf.data ();
4291
4292 if (*p == 'E')
4293 error (_("Remote failure reply: %s"), p);
4294
4295 if (*p++ == 'm')
4296 {
4298 return true;
4299 }
4300
4301 return false;
4302}
4304std::vector<static_tracepoint_marker>
4306{
4307 struct remote_state *rs = get_remote_state ();
4308 std::vector<static_tracepoint_marker> markers;
4309 const char *p;
4311
4312 /* Ask for a first packet of static tracepoint marker
4313 definition. */
4314 putpkt ("qTfSTM");
4315 getpkt (&rs->buf);
4316 p = rs->buf.data ();
4317 if (*p == 'E')
4318 error (_("Remote failure reply: %s"), p);
4319
4320 while (*p++ == 'm')
4321 {
4322 do
4323 {
4325
4326 if (strid == NULL || marker.str_id == strid)
4327 markers.push_back (std::move (marker));
4328 }
4329 while (*p++ == ','); /* comma-separated list */
4330 /* Ask for another packet of static tracepoint definition. */
4331 putpkt ("qTsSTM");
4332 getpkt (&rs->buf);
4333 p = rs->buf.data ();
4334 }
4335
4336 return markers;
4337}
4338
4339
4340/* Implement the to_get_ada_task_ptid function for the remote targets. */
4342ptid_t
4343remote_target::get_ada_task_ptid (long lwp, ULONGEST thread)
4344{
4345 return ptid_t (inferior_ptid.pid (), lwp);
4346}
4347
4348
4349/* Restart the remote side; this is an extended protocol operation. */
4351void
4353{
4354 struct remote_state *rs = get_remote_state ();
4355
4356 /* Send the restart command; for reasons I don't understand the
4357 remote side really expects a number after the "R". */
4358 xsnprintf (rs->buf.data (), get_remote_packet_size (), "R%x", 0);
4359 putpkt (rs->buf);
4360
4362}
4363
4364/* Clean up connection to a remote debugger. */
4366void
4368{
4369 /* Make sure we leave stdin registered in the event loop. */
4370 terminal_ours ();
4371
4373
4374 delete this;
4376
4378{
4379 struct remote_state *rs = get_remote_state ();
4380
4381 /* Check for NULL because we may get here with a partially
4382 constructed target/connection. */
4383 if (rs->remote_desc == nullptr)
4384 return;
4385
4387
4388 /* We are destroying the remote target, so we should discard
4389 everything of this target. */
4391
4394
4395 delete rs->notif_state;
4396}
4397
4398/* Query the remote side for the text, data and bss offsets. */
4400void
4402{
4403 struct remote_state *rs = get_remote_state ();
4404 char *buf;
4405 char *ptr;
4406 int lose, num_segments = 0, do_sections, do_segments;
4407 CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
4408
4410 return;
4411
4412 putpkt ("qOffsets");
4413 getpkt (&rs->buf);
4414 buf = rs->buf.data ();
4415
4416 if (buf[0] == '\000')
4417 return; /* Return silently. Stub doesn't support
4418 this command. */
4419 if (buf[0] == 'E')
4420 {
4421 warning (_("Remote failure reply: %s"), buf);
4422 return;
4423 }
4424
4425 /* Pick up each field in turn. This used to be done with scanf, but
4426 scanf will make trouble if CORE_ADDR size doesn't match
4427 conversion directives correctly. The following code will work
4428 with any size of CORE_ADDR. */
4429 text_addr = data_addr = bss_addr = 0;
4430 ptr = buf;
4431 lose = 0;
4432
4433 if (startswith (ptr, "Text="))
4434 {
4435 ptr += 5;
4436 /* Don't use strtol, could lose on big values. */
4437 while (*ptr && *ptr != ';')
4438 text_addr = (text_addr << 4) + fromhex (*ptr++);
4439
4440 if (startswith (ptr, ";Data="))
4441 {
4442 ptr += 6;
4443 while (*ptr && *ptr != ';')
4444 data_addr = (data_addr << 4) + fromhex (*ptr++);
4445 }
4446 else
4447 lose = 1;
4448
4449 if (!lose && startswith (ptr, ";Bss="))
4450 {
4451 ptr += 5;
4452 while (*ptr && *ptr != ';')
4453 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
4454
4455 if (bss_addr != data_addr)
4456 warning (_("Target reported unsupported offsets: %s"), buf);
4457 }
4458 else
4459 lose = 1;
4460 }
4461 else if (startswith (ptr, "TextSeg="))
4462 {
4463 ptr += 8;
4464 /* Don't use strtol, could lose on big values. */
4465 while (*ptr && *ptr != ';')
4466 text_addr = (text_addr << 4) + fromhex (*ptr++);
4467 num_segments = 1;
4468
4469 if (startswith (ptr, ";DataSeg="))
4470 {
4471 ptr += 9;
4472 while (*ptr && *ptr != ';')
4473 data_addr = (data_addr << 4) + fromhex (*ptr++);
4474 num_segments++;
4475 }
4476 }
4477 else
4478 lose = 1;
4479
4480 if (lose)
4481 error (_("Malformed response to offset query, %s"), buf);
4482 else if (*ptr != '\0')
4483 warning (_("Target reported unsupported offsets: %s"), buf);
4484
4486 section_offsets offs = objf->section_offsets;
4487
4489 do_segments = (data != NULL);
4490 do_sections = num_segments == 0;
4491
4492 if (num_segments > 0)
4493 {
4494 segments[0] = text_addr;
4495 segments[1] = data_addr;
4496 }
4497 /* If we have two segments, we can still try to relocate everything
4498 by assuming that the .text and .data offsets apply to the whole
4499 text and data segments. Convert the offsets given in the packet
4500 to base addresses for symfile_map_offsets_to_segments. */
4501 else if (data != nullptr && data->segments.size () == 2)
4502 {
4503 segments[0] = data->segments[0].base + text_addr;
4504 segments[1] = data->segments[1].base + data_addr;
4505 num_segments = 2;
4506 }
4507 /* If the object file has only one segment, assume that it is text
4508 rather than data; main programs with no writable data are rare,
4509 but programs with no code are useless. Of course the code might
4510 have ended up in the data segment... to detect that we would need
4511 the permissions here. */
4512 else if (data && data->segments.size () == 1)
4513 {
4514 segments[0] = data->segments[0].base + text_addr;
4515 num_segments = 1;
4516 }
4517 /* There's no way to relocate by segment. */
4518 else
4519 do_segments = 0;
4520
4521 if (do_segments)
4522 {
4523 int ret = symfile_map_offsets_to_segments (objf->obfd.get (),
4524 data.get (), offs,
4525 num_segments, segments);
4526
4527 if (ret == 0 && !do_sections)
4528 error (_("Can not handle qOffsets TextSeg "
4529 "response with this symbol file"));
4530
4531 if (ret > 0)
4532 do_sections = 0;
4533 }
4534
4535 if (do_sections)
4536 {
4537 offs[SECT_OFF_TEXT (objf)] = text_addr;
4538
4539 /* This is a temporary kludge to force data and bss to use the
4540 same offsets because that's what nlmconv does now. The real
4541 solution requires changes to the stub and remote.c that I
4542 don't have time to do right now. */
4543
4544 offs[SECT_OFF_DATA (objf)] = data_addr;
4545 offs[SECT_OFF_BSS (objf)] = data_addr;
4546 }
4547
4548 objfile_relocate (objf, offs);
4549}
4550
4551/* Send interrupt_sequence to remote target. */
4553void
4555{
4556 struct remote_state *rs = get_remote_state ();
4557
4559 remote_serial_write ("\x03", 1);
4563 {
4565 remote_serial_write ("g", 1);
4566 }
4567 else
4568 internal_error (_("Invalid value for interrupt_sequence_mode: %s."),
4570}
4571
4572
4573/* If STOP_REPLY is a T stop reply, look for the "thread" register,
4574 and extract the PTID. Returns NULL_PTID if not found. */
4576static ptid_t
4578{
4579 if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
4580 {
4581 const char *p;
4582
4583 /* Txx r:val ; r:val (...) */
4584 p = &stop_reply[3];
4585
4586 /* Look for "register" named "thread". */
4587 while (*p != '\0')
4588 {
4589 const char *p1;
4590
4591 p1 = strchr (p, ':');
4592 if (p1 == NULL)
4593 return null_ptid;
4594
4595 if (strncmp (p, "thread", p1 - p) == 0)
4596 return read_ptid (++p1, &p);
4597
4598 p1 = strchr (p, ';');
4599 if (p1 == NULL)
4600 return null_ptid;
4601 p1++;
4602
4603 p = p1;
4604 }
4605 }
4606
4607 return null_ptid;
4608}
4609
4610/* Determine the remote side's current thread. If we have a stop
4611 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
4612 "thread" register we can extract the current thread from. If not,
4613 ask the remote which is the current thread with qC. The former
4614 method avoids a roundtrip. */
4616ptid_t
4617remote_target::get_current_thread (const char *wait_status)
4618{
4619 ptid_t ptid = null_ptid;
4620
4621 /* Note we don't use remote_parse_stop_reply as that makes use of
4622 the target architecture, which we haven't yet fully determined at
4623 this point. */
4624 if (wait_status != NULL)
4625 ptid = stop_reply_extract_thread (wait_status);
4626 if (ptid == null_ptid)
4628
4629 return ptid;
4630}
4631
4632/* Query the remote target for which is the current thread/process,
4633 add it to our tables, and update INFERIOR_PTID. The caller is
4634 responsible for setting the state such that the remote end is ready
4635 to return the current thread.
4636
4637 This function is called after handling the '?' or 'vRun' packets,
4638 whose response is a stop reply from which we can also try
4639 extracting the thread. If the target doesn't support the explicit
4640 qC query, we infer the current thread from that stop reply, passed
4641 in in WAIT_STATUS, which may be NULL.
4642
4643 The function returns pointer to the main thread of the inferior. */
4646remote_target::add_current_inferior_and_thread (const char *wait_status)
4647{
4648 bool fake_pid_p = false;
4649
4651
4652 /* Now, if we have thread information, update the current thread's
4653 ptid. */
4654 ptid_t curr_ptid = get_current_thread (wait_status);
4655
4656 if (curr_ptid != null_ptid)
4657 {
4659 fake_pid_p = true;
4660 }
4661 else
4662 {
4663 /* Without this, some commands which require an active target
4664 (such as kill) won't work. This variable serves (at least)
4665 double duty as both the pid of the target process (if it has
4666 such), and as a flag indicating that a target is active. */
4667 curr_ptid = magic_null_ptid;
4668 fake_pid_p = true;
4669 }
4670
4671 remote_add_inferior (fake_pid_p, curr_ptid.pid (), -1, 1);
4672
4673 /* Add the main thread and switch to it. Don't try reading
4674 registers yet, since we haven't fetched the target description
4675 yet. */
4676 thread_info *tp = add_thread_silent (this, curr_ptid);
4678
4679 return tp;
4680}
4681
4682/* Print info about a thread that was found already stopped on
4683 connection. */
4685void
4687{
4689
4690 /* If there is a pending waitstatus, use it. If there isn't it's because
4691 the thread's stop was reported with TARGET_WAITKIND_STOPPED / GDB_SIGNAL_0
4692 and process_initial_stop_replies decided it wasn't interesting to save
4693 and report to the core. */
4694 if (thread->has_pending_waitstatus ())
4695 {
4696 ws = thread->pending_waitstatus ();
4697 thread->clear_pending_waitstatus ();
4698 }
4699 else
4700 {
4701 ws.set_stopped (GDB_SIGNAL_0);
4702 }
4703
4704 switch_to_thread (thread);
4707
4708 /* For "info program". */
4709 set_last_target_status (this, thread->ptid, ws);
4710
4711 if (ws.kind () == TARGET_WAITKIND_STOPPED)
4712 {
4713 enum gdb_signal sig = ws.sig ();
4714
4715 if (signal_print_state (sig))
4717 }
4718
4719 notify_normal_stop (nullptr, 1);
4720}
4721
4722/* Process all initial stop replies the remote side sent in response
4723 to the ? packet. These indicate threads that were already stopped
4724 on initial connection. We mark these threads as stopped and print
4725 their current frame before giving the user the prompt. */
4727void
4729{
4730 int pending_stop_replies = stop_reply_queue_length ();
4731 struct thread_info *selected = NULL;
4732 struct thread_info *lowest_stopped = NULL;
4733 struct thread_info *first = NULL;
4734
4735 /* This is only used when the target is non-stop. */
4736 gdb_assert (target_is_non_stop_p ());
4737
4738 /* Consume the initial pending events. */
4739 while (pending_stop_replies-- > 0)
4740 {
4741 ptid_t waiton_ptid = minus_one_ptid;
4742 ptid_t event_ptid;
4743 struct target_waitstatus ws;
4744 int ignore_event = 0;
4745
4746 event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
4747 if (remote_debug)
4748 print_target_wait_results (waiton_ptid, event_ptid, ws);
4749
4750 switch (ws.kind ())
4751 {
4756 /* We shouldn't see these, but if we do, just ignore. */
4757 remote_debug_printf ("event ignored");
4758 ignore_event = 1;
4759 break;
4760
4761 default:
4762 break;
4763 }
4764
4765 if (ignore_event)
4766 continue;
4767
4768 thread_info *evthread = this->find_thread (event_ptid);
4769
4770 if (ws.kind () == TARGET_WAITKIND_STOPPED)
4771 {
4772 enum gdb_signal sig = ws.sig ();
4773
4774 /* Stubs traditionally report SIGTRAP as initial signal,
4775 instead of signal 0. Suppress it. */
4776 if (sig == GDB_SIGNAL_TRAP)
4777 sig = GDB_SIGNAL_0;
4778 evthread->set_stop_signal (sig);
4779 ws.set_stopped (sig);
4780 }
4781
4782 if (ws.kind () != TARGET_WAITKIND_STOPPED
4783 || ws.sig () != GDB_SIGNAL_0)
4784 evthread->set_pending_waitstatus (ws);
4785
4786 set_executing (this, event_ptid, false);
4787 set_running (this, event_ptid, false);
4789 }
4790
4791 /* "Notice" the new inferiors before anything related to
4792 registers/memory. */
4793 for (inferior *inf : all_non_exited_inferiors (this))
4794 {
4795 inf->needs_setup = true;
4796
4797 if (non_stop)
4798 {
4800 notice_new_inferior (thread, thread->state == THREAD_RUNNING,
4801 from_tty);
4802 }
4803 }
4804
4805 /* If all-stop on top of non-stop, pause all threads. Note this
4806 records the threads' stop pc, so must be done after "noticing"
4807 the inferiors. */
4808 if (!non_stop)
4809 {
4810 {
4811 /* At this point, the remote target is not async. It needs to be for
4812 the poll in stop_all_threads to consider events from it, so enable
4813 it temporarily. */
4814 gdb_assert (!this->is_async_p ());
4815 SCOPE_EXIT { target_async (false); };
4816 target_async (true);
4817 stop_all_threads ("remote connect in all-stop");
4818 }
4819
4820 /* If all threads of an inferior were already stopped, we
4821 haven't setup the inferior yet. */
4822 for (inferior *inf : all_non_exited_inferiors (this))
4823 {
4824 if (inf->needs_setup)
4825 {
4827 switch_to_thread_no_regs (thread);
4828 setup_inferior (0);
4829 }
4830 }
4831 }
4832
4833 /* Now go over all threads that are stopped, and print their current
4834 frame. If all-stop, then if there's a signalled thread, pick
4835 that as current. */
4836 for (thread_info *thread : all_non_exited_threads (this))
4837 {
4838 if (first == NULL)
4839 first = thread;
4840
4841 if (!non_stop)
4842 thread->set_running (false);
4843 else if (thread->state != THREAD_STOPPED)
4844 continue;
4845
4846 if (selected == nullptr && thread->has_pending_waitstatus ())
4847 selected = thread;
4848
4849 if (lowest_stopped == NULL
4850 || thread->inf->num < lowest_stopped->inf->num
4851 || thread->per_inf_num < lowest_stopped->per_inf_num)
4852 lowest_stopped = thread;
4853
4854 if (non_stop)
4855 print_one_stopped_thread (thread);
4856 }
4857
4858 /* In all-stop, we only print the status of one thread, and leave
4859 others with their status pending. */
4860 if (!non_stop)
4861 {
4862 thread_info *thread = selected;
4863 if (thread == NULL)
4864 thread = lowest_stopped;
4865 if (thread == NULL)
4866 thread = first;
4867
4868 print_one_stopped_thread (thread);
4869 }
4870}
4871
4872/* Mark a remote_target as starting (by setting the starting_up flag within
4873 its remote_state) for the lifetime of this object. The reference count
4874 on the remote target is temporarily incremented, to prevent the target
4875 being deleted under our feet. */
4876
4878{
4879 /* Constructor, TARGET is the target to be marked as starting, its
4880 reference count will be incremented. */
4882 : m_remote_target (remote_target_ref::new_reference (target)),
4884 { /* Nothing. */ }
4885
4886private:
4887
4888 /* Helper function, set the starting_up flag on TARGET and return an
4889 object which, when it goes out of scope, will restore the previous
4890 value of the starting_up flag. */
4891 static scoped_restore_tmpl<bool>
4893 {
4894 remote_state *rs = target->get_remote_state ();
4895 gdb_assert (!rs->starting_up);
4896 return make_scoped_restore (&rs->starting_up, true);
4897 }
4899 /* A gdb::ref_ptr pointer to a remote_target. */
4900 using remote_target_ref = gdb::ref_ptr<remote_target, target_ops_ref_policy>;
4902 /* A reference to the target on which we are operating. */
4904
4905 /* An object which restores the previous value of the starting_up flag
4906 when it goes out of scope. */
4907 scoped_restore_tmpl<bool> m_restore_starting_up;
4908};
4909
4910/* Helper for remote_target::start_remote, start the remote connection and
4911 sync state. Return true if everything goes OK, otherwise, return false.
4912 This function exists so that the scoped_restore created within it will
4913 expire before we return to remote_target::start_remote. */
4915bool
4916remote_target::start_remote_1 (int from_tty, int extended_p)
4917{
4919
4920 struct remote_state *rs = get_remote_state ();
4921
4922 /* Signal other parts that we're going through the initial setup,
4923 and so things may not be stable yet. E.g., we don't try to
4924 install tracepoints until we've relocated symbols. Also, a
4925 Ctrl-C before we're connected and synced up can't interrupt the
4926 target. Instead, it offers to drop the (potentially wedged)
4927 connection. */
4928 scoped_mark_target_starting target_is_starting (this);
4929
4930 QUIT;
4931
4934
4935 /* Ack any packet which the remote side has already sent. */
4936 remote_serial_write ("+", 1);
4937
4938 /* The first packet we send to the target is the optional "supported
4939 packets" request. If the target can answer this, it will tell us
4940 which later probes to skip. */
4942
4943 /* Check vCont support and set the remote state's vCont_action_support
4944 attribute. */
4946
4947 /* If the stub wants to get a QAllow, compose one and send it. */
4949 set_permissions ();
4950
4951 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4952 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4953 as a reply to known packet. For packet "vFile:setfs:" it is an
4954 invalid reply and GDB would return error in
4955 remote_hostio_set_filesystem, making remote files access impossible.
4956 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4957 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4958 {
4959 const char v_mustreplyempty[] = "vMustReplyEmpty";
4960
4961 putpkt (v_mustreplyempty);
4962 getpkt (&rs->buf);
4963 if (strcmp (rs->buf.data (), "OK") == 0)
4964 {
4967 }
4968 else if (strcmp (rs->buf.data (), "") != 0)
4969 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty,
4970 rs->buf.data ());
4971 }
4972
4973 /* Next, we possibly activate noack mode.
4974
4975 If the QStartNoAckMode packet configuration is set to AUTO,
4976 enable noack mode if the stub reported a wish for it with
4977 qSupported.
4978
4979 If set to TRUE, then enable noack mode even if the stub didn't
4980 report it in qSupported. If the stub doesn't reply OK, the
4981 session ends with an error.
4982
4983 If FALSE, then don't activate noack mode, regardless of what the
4984 stub claimed should be the default with qSupported. */
4985
4987 {
4988 putpkt ("QStartNoAckMode");
4989 getpkt (&rs->buf);
4991 rs->noack_mode = 1;
4992 }
4993
4994 if (extended_p)
4995 {
4996 /* Tell the remote that we are using the extended protocol. */
4997 putpkt ("!");
4998 getpkt (&rs->buf);
4999 }
5000
5001 /* Let the target know which signals it is allowed to pass down to
5002 the program. */
5004
5005 /* Next, if the target can specify a description, read it. We do
5006 this before anything involving memory or registers. */
5008
5009 /* Next, now that we know something about the target, update the
5010 address spaces in the program spaces. */
5012
5013 /* On OSs where the list of libraries is global to all
5014 processes, we fetch them early. */
5016 solib_add (NULL, from_tty, auto_solib_add);
5017
5018 if (target_is_non_stop_p ())
5019 {
5021 error (_("Non-stop mode requested, but remote "
5022 "does not support non-stop"));
5023
5024 putpkt ("QNonStop:1");
5025 getpkt (&rs->buf);
5026
5027 if (strcmp (rs->buf.data (), "OK") != 0)
5028 error (_("Remote refused setting non-stop mode with: %s"),
5029 rs->buf.data ());
5030
5031 /* Find about threads and processes the stub is already
5032 controlling. We default to adding them in the running state.
5033 The '?' query below will then tell us about which threads are
5034 stopped. */
5035 this->update_thread_list ();
5036 }
5038 {
5039 /* Don't assume that the stub can operate in all-stop mode.
5040 Request it explicitly. */
5041 putpkt ("QNonStop:0");
5042 getpkt (&rs->buf);
5043
5044 if (strcmp (rs->buf.data (), "OK") != 0)
5045 error (_("Remote refused setting all-stop mode with: %s"),
5046 rs->buf.data ());
5047 }
5048
5049 /* Upload TSVs regardless of whether the target is running or not. The
5050 remote stub, such as GDBserver, may have some predefined or builtin
5051 TSVs, even if the target is not running. */
5053 {
5054 struct uploaded_tsv *uploaded_tsvs = NULL;
5055
5056 upload_trace_state_variables (&uploaded_tsvs);
5057 merge_uploaded_trace_state_variables (&uploaded_tsvs);
5058 }
5059
5060 /* Check whether the target is running now. */
5061 putpkt ("?");
5062 getpkt (&rs->buf);
5063
5064 if (!target_is_non_stop_p ())
5065 {
5066 char *wait_status = NULL;
5067
5068 if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
5069 {
5070 if (!extended_p)
5071 error (_("The target is not running (try extended-remote?)"));
5072 return false;
5073 }
5074 else
5075 {
5076 /* Save the reply for later. */
5077 wait_status = (char *) alloca (strlen (rs->buf.data ()) + 1);
5078 strcpy (wait_status, rs->buf.data ());
5079 }
5080
5081 /* Fetch thread list. */
5083
5084 /* Let the stub know that we want it to return the thread. */
5085 set_continue_thread (minus_one_ptid);
5086
5087 if (thread_count (this) == 0)
5088 {
5089 /* Target has no concept of threads at all. GDB treats
5090 non-threaded target as single-threaded; add a main
5091 thread. */
5092 thread_info *tp = add_current_inferior_and_thread (wait_status);
5094 }
5095 else
5096 {
5097 /* We have thread information; select the thread the target
5098 says should be current. If we're reconnecting to a
5099 multi-threaded program, this will ideally be the thread
5100 that last reported an event before GDB disconnected. */
5101 ptid_t curr_thread = get_current_thread (wait_status);
5102 if (curr_thread == null_ptid)
5103 {
5104 /* Odd... The target was able to list threads, but not
5105 tell us which thread was current (no "thread"
5106 register in T stop reply?). Just pick the first
5107 thread in the thread list then. */
5108
5109 remote_debug_printf ("warning: couldn't determine remote "
5110 "current thread; picking first in list.");
5111
5112 for (thread_info *tp : all_non_exited_threads (this,
5113 minus_one_ptid))
5114 {
5115 switch_to_thread (tp);
5116 break;
5117 }
5118 }
5119 else
5120 switch_to_thread (this->find_thread (curr_thread));
5121 }
5122
5123 /* init_wait_for_inferior should be called before get_offsets in order
5124 to manage `inserted' flag in bp loc in a correct state.
5125 breakpoint_init_inferior, called from init_wait_for_inferior, set
5126 `inserted' flag to 0, while before breakpoint_re_set, called from
5127 start_remote, set `inserted' flag to 1. In the initialization of
5128 inferior, breakpoint_init_inferior should be called first, and then
5129 breakpoint_re_set can be called. If this order is broken, state of
5130 `inserted' flag is wrong, and cause some problems on breakpoint
5131 manipulation. */
5133
5134 get_offsets (); /* Get text, data & bss offsets. */
5135
5136 /* If we could not find a description using qXfer, and we know
5137 how to do it some other way, try again. This is not
5138 supported for non-stop; it could be, but it is tricky if
5139 there are no stopped threads when we connect. */
5140 if (remote_read_description_p (this)
5141 && gdbarch_target_desc (target_gdbarch ()) == NULL)
5142 {
5145 }
5146
5147 /* Use the previously fetched status. */
5148 gdb_assert (wait_status != NULL);
5149 struct notif_event *reply
5150 = remote_notif_parse (this, &notif_client_stop, wait_status);
5151 push_stop_reply ((struct stop_reply *) reply);
5152
5153 ::start_remote (from_tty); /* Initialize gdb process mechanisms. */
5154 }
5155 else
5156 {
5157 /* Clear WFI global state. Do this before finding about new
5158 threads and inferiors, and setting the current inferior.
5159 Otherwise we would clear the proceed status of the current
5160 inferior when we want its stop_soon state to be preserved
5161 (see notice_new_inferior). */
5163
5164 /* In non-stop, we will either get an "OK", meaning that there
5165 are no stopped threads at this time; or, a regular stop
5166 reply. In the latter case, there may be more than one thread
5167 stopped --- we pull them all out using the vStopped
5168 mechanism. */
5169 if (strcmp (rs->buf.data (), "OK") != 0)
5170 {
5171 const notif_client *notif = &notif_client_stop;
5172
5173 /* remote_notif_get_pending_replies acks this one, and gets
5174 the rest out. */
5176 = remote_notif_parse (this, notif, rs->buf.data ());
5178 }
5179
5180 if (thread_count (this) == 0)
5181 {
5182 if (!extended_p)
5183 error (_("The target is not running (try extended-remote?)"));
5184 return false;
5185 }
5186
5187 /* Report all signals during attach/startup. */
5188 pass_signals ({});
5189
5190 /* If there are already stopped threads, mark them stopped and
5191 report their stops before giving the prompt to the user. */
5193
5194 if (target_can_async_p ())
5195 target_async (true);
5196 }
5197
5198 /* Give the target a chance to look up symbols. */
5199 for (inferior *inf : all_inferiors (this))
5200 {
5201 /* The inferiors that exist at this point were created from what
5202 was found already running on the remote side, so we know they
5203 have execution. */
5204 gdb_assert (this->has_execution (inf));
5205
5206 /* No use without a symbol-file. */
5207 if (inf->pspace->symfile_object_file == nullptr)
5208 continue;
5209
5210 /* Need to switch to a specific thread, because remote_check_symbols
5211 uses INFERIOR_PTID to set the general thread. */
5212 scoped_restore_current_thread restore_thread;
5214 switch_to_thread (thread);
5215 this->remote_check_symbols ();
5216 }
5217
5218 /* Possibly the target has been engaged in a trace run started
5219 previously; find out where things are at. */
5221 {
5222 struct uploaded_tp *uploaded_tps = NULL;
5223
5224 if (current_trace_status ()->running)
5225 gdb_printf (_("Trace is already running on the target.\n"));
5226
5227 upload_tracepoints (&uploaded_tps);
5228
5229 merge_uploaded_tracepoints (&uploaded_tps);
5230 }
5231
5232 /* Possibly the target has been engaged in a btrace record started
5233 previously; find out where things are at. */
5235
5236 return true;
5237}
5238
5239/* Start the remote connection and sync state. */
5241void
5242remote_target::start_remote (int from_tty, int extended_p)
5243{
5244 if (start_remote_1 (from_tty, extended_p)
5247}
5249const char *
5251{
5253
5254 if (rs->remote_desc->name != NULL)
5255 return rs->remote_desc->name;
5256 else
5257 return NULL;
5258}
5259
5260/* Open a connection to a remote debugger.
5261 NAME is the filename used for communication. */
5263void
5264remote_target::open (const char *name, int from_tty)
5265{
5266 open_1 (name, from_tty, 0);
5267}
5268
5269/* Open a connection to a remote debugger using the extended
5270 remote gdb protocol. NAME is the filename used for communication. */
5272void
5273extended_remote_target::open (const char *name, int from_tty)
5274{
5275 open_1 (name, from_tty, 1 /*extended_p */);
5276}
5278void
5280{
5281 int i;
5282
5283 for (i = 0; i < PACKET_MAX; i++)
5285}
5286
5287/* Initialize all packet configs. */
5289static void
5291{
5292 int i;
5293
5294 for (i = 0; i < PACKET_MAX; i++)
5295 {
5298 }
5299}
5300
5301/* Symbol look-up. */
5303void
5305{
5306 char *tmp;
5307 int end;
5308
5309 /* It doesn't make sense to send a qSymbol packet for an inferior that
5310 doesn't have execution, because the remote side doesn't know about
5311 inferiors without execution. */
5312 gdb_assert (target_has_execution ());
5313
5315 return;
5316
5317 /* Make sure the remote is pointing at the right process. Note
5318 there's no way to select "no process". */
5320
5321 /* Allocate a message buffer. We can't reuse the input buffer in RS,
5322 because we need both at the same time. */
5323 gdb::char_vector msg (get_remote_packet_size ());
5324 gdb::char_vector reply (get_remote_packet_size ());
5325
5326 /* Invite target to request symbol lookups. */
5327
5328 putpkt ("qSymbol::");
5329 getpkt (&reply);
5331
5332 while (startswith (reply.data (), "qSymbol:"))
5333 {
5334 struct bound_minimal_symbol sym;
5335
5336 tmp = &reply[8];
5337 end = hex2bin (tmp, reinterpret_cast <gdb_byte *> (msg.data ()),
5338 strlen (tmp) / 2);
5339 msg[end] = '\0';
5340 sym = lookup_minimal_symbol (msg.data (), NULL, NULL);
5341 if (sym.minsym == NULL)
5342 xsnprintf (msg.data (), get_remote_packet_size (), "qSymbol::%s",
5343 &reply[8]);
5344 else
5345 {
5346 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
5347 CORE_ADDR sym_addr = sym.value_address ();
5348
5349 /* If this is a function address, return the start of code
5350 instead of any data function descriptor. */
5352 (target_gdbarch (), sym_addr, current_inferior ()->top_target ());
5353
5354 xsnprintf (msg.data (), get_remote_packet_size (), "qSymbol:%s:%s",
5355 phex_nz (sym_addr, addr_size), &reply[8]);
5356 }
5357
5358 putpkt (msg.data ());
5359 getpkt (&reply);
5360 }
5361}
5363static struct serial *
5364remote_serial_open (const char *name)
5365{
5366 static int udp_warning = 0;
5367
5368 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
5369 of in ser-tcp.c, because it is the remote protocol assuming that the
5370 serial connection is reliable and not the serial connection promising
5371 to be. */
5372 if (!udp_warning && startswith (name, "udp:"))
5373 {
5374 warning (_("The remote protocol may be unreliable over UDP.\n"
5375 "Some events may be lost, rendering further debugging "
5376 "impossible."));
5377 udp_warning = 1;
5378 }
5379
5380 return serial_open (name);
5381}
5382
5383/* Inform the target of our permission settings. The permission flags
5384 work without this, but if the target knows the settings, it can do
5385 a couple things. First, it can add its own check, to catch cases
5386 that somehow manage to get by the permissions checks in target
5387 methods. Second, if the target is wired to disallow particular
5388 settings (for instance, a system in the field that is not set up to
5389 be able to stop at a breakpoint), it can object to any unavailable
5390 permissions. */
5392void
5394{
5395 struct remote_state *rs = get_remote_state ();
5396
5397 xsnprintf (rs->buf.data (), get_remote_packet_size (), "QAllow:"
5398 "WriteReg:%x;WriteMem:%x;"
5399 "InsertBreak:%x;InsertTrace:%x;"
5400 "InsertFastTrace:%x;Stop:%x",
5404 putpkt (rs->buf);
5405 getpkt (&rs->buf);
5406
5407 /* If the target didn't like the packet, warn the user. Do not try
5408 to undo the user's settings, that would just be maddening. */
5409 if (strcmp (rs->buf.data (), "OK") != 0)
5410 warning (_("Remote refused setting permissions with: %s"),
5411 rs->buf.data ());
5412}
5413
5414/* This type describes each known response to the qSupported
5415 packet. */
5416struct protocol_feature
5418 /* The name of this protocol feature. */
5419 const char *name;
5421 /* The default for this protocol feature. */
5423
5424 /* The function to call when this feature is reported, or after
5425 qSupported processing if the feature is not supported.
5426 The first argument points to this structure. The second
5427 argument indicates whether the packet requested support be
5428 enabled, disabled, or probed (or the default, if this function
5429 is being called at the end of processing and this feature was
5430 not reported). The third argument may be NULL; if not NULL, it
5431 is a NUL-terminated string taken from the packet following
5432 this feature's name and an equals sign. */
5433 void (*func) (remote_target *remote, const struct protocol_feature *,
5434 enum packet_support, const char *);
5435
5436 /* The corresponding packet for this feature. Only used if
5437 FUNC is remote_supported_packet. */
5438 int packet;
5439};
5441static void
5443 const struct protocol_feature *feature,
5444 enum packet_support support,
5445 const char *argument)
5446{
5447 if (argument)
5448 {
5449 warning (_("Remote qSupported response supplied an unexpected value for"
5450 " \"%s\"."), feature->name);
5451 return;
5452 }
5453
5454 remote->m_features.m_protocol_packets[feature->packet].support = support;
5455}
5457void
5459 enum packet_support support, const char *value)
5460{
5461 struct remote_state *rs = get_remote_state ();
5462
5463 int packet_size;
5464 char *value_end;
5465
5466 if (support != PACKET_ENABLE)
5467 return;
5468
5469 if (value == NULL || *value == '\0')
5470 {
5471 warning (_("Remote target reported \"%s\" without a size."),
5472 feature->name);
5473 return;
5474 }
5475
5476 errno = 0;
5477 packet_size = strtol (value, &value_end, 16);
5478 if (errno != 0 || *value_end != '\0' || packet_size < 0)
5479 {
5480 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
5481 feature->name, value);
5482 return;
5483 }
5484
5485 /* Record the new maximum packet size. */
5486 rs->explicit_packet_size = packet_size;
5487}
5489static void
5490remote_packet_size (remote_target *remote, const protocol_feature *feature,
5491 enum packet_support support, const char *value)
5492{
5493 remote->remote_packet_size (feature, support, value);
5495
5496static const struct protocol_feature remote_protocol_features[] = {
5497 { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
5498 { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
5500 { "qXfer:exec-file:read", PACKET_DISABLE, remote_supported_packet,
5502 { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
5504 { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
5506 { "qXfer:libraries-svr4:read", PACKET_DISABLE, remote_supported_packet,
5508 { "augmented-libraries-svr4-read", PACKET_DISABLE,
5510 { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
5512 { "qXfer:osdata:read", PACKET_DISABLE, remote_supported_packet,
5514 { "qXfer:threads:read", PACKET_DISABLE, remote_supported_packet,
5516 { "qXfer:traceframe-info:read", PACKET_DISABLE, remote_supported_packet,
5518 { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
5520 { "QCatchSyscalls", PACKET_DISABLE, remote_supported_packet,
5522 { "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
5524 { "QSetWorkingDir", PACKET_DISABLE, remote_supported_packet,
5526 { "QStartupWithShell", PACKET_DISABLE, remote_supported_packet,
5528 { "QEnvironmentHexEncoded", PACKET_DISABLE, remote_supported_packet,
5530 { "QEnvironmentReset", PACKET_DISABLE, remote_supported_packet,
5532 { "QEnvironmentUnset", PACKET_DISABLE, remote_supported_packet,
5534 { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
5536 { "multiprocess", PACKET_DISABLE, remote_supported_packet,
5539 { "qXfer:siginfo:read", PACKET_DISABLE, remote_supported_packet,
5541 { "qXfer:siginfo:write", PACKET_DISABLE, remote_supported_packet,
5543 { "ConditionalTracepoints", PACKET_DISABLE, remote_supported_packet,
5545 { "ConditionalBreakpoints", PACKET_DISABLE, remote_supported_packet,
5547 { "BreakpointCommands", PACKET_DISABLE, remote_supported_packet,
5549 { "FastTracepoints", PACKET_DISABLE, remote_supported_packet,
5551 { "StaticTracepoints", PACKET_DISABLE, remote_supported_packet,
5553 {"InstallInTrace", PACKET_DISABLE, remote_supported_packet,
5555 { "DisconnectedTracing", PACKET_DISABLE, remote_supported_packet,
5557 { "ReverseContinue", PACKET_DISABLE, remote_supported_packet,
5558 PACKET_bc },
5559 { "ReverseStep", PACKET_DISABLE, remote_supported_packet,
5560 PACKET_bs },
5561 { "TracepointSource", PACKET_DISABLE, remote_supported_packet,
5564 PACKET_QAllow },
5565 { "EnableDisableTracepoints", PACKET_DISABLE, remote_supported_packet,
5567 { "qXfer:fdpic:read", PACKET_DISABLE, remote_supported_packet,
5569 { "qXfer:uib:read", PACKET_DISABLE, remote_supported_packet,
5571 { "QDisableRandomization", PACKET_DISABLE, remote_supported_packet,
5574 { "QTBuffer:size", PACKET_DISABLE,
5580 { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
5582 { "qXfer:btrace-conf:read", PACKET_DISABLE, remote_supported_packet,
5584 { "Qbtrace-conf:bts:size", PACKET_DISABLE, remote_supported_packet,
5588 { "fork-events", PACKET_DISABLE, remote_supported_packet,
5590 { "vfork-events", PACKET_DISABLE, remote_supported_packet,
5592 { "exec-events", PACKET_DISABLE, remote_supported_packet,
5594 { "Qbtrace-conf:pt:size", PACKET_DISABLE, remote_supported_packet,
5599 { "memory-tagging", PACKET_DISABLE, remote_supported_packet,
5602
5603static char *remote_support_xml;
5604
5605/* Register string appended to "xmlRegisters=" in qSupported query. */
5607void
5608register_remote_support_xml (const char *xml)
5609{
5610#if defined(HAVE_LIBEXPAT)
5611 if (remote_support_xml == NULL)
5612 remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
5613 else
5614 {
5615 char *copy = xstrdup (remote_support_xml + 13);
5616 char *saveptr;
5617 char *p = strtok_r (copy, ",", &saveptr);
5618
5619 do
5620 {
5621 if (strcmp (p, xml) == 0)
5622 {
5623 /* already there */
5624 xfree (copy);
5625 return;
5626 }
5627 }
5628 while ((p = strtok_r (NULL, ",", &saveptr)) != NULL);
5629 xfree (copy);
5630
5632 remote_support_xml, ",", xml,
5633 (char *) NULL);
5634 }
5635#endif
5636}
5638static void
5639remote_query_supported_append (std::string *msg, const char *append)
5640{
5641 if (!msg->empty ())
5642 msg->append (";");
5643 msg->append (append);
5644}
5646void
5648{
5649 struct remote_state *rs = get_remote_state ();
5650 char *next;
5651 int i;
5652 unsigned char seen [ARRAY_SIZE (remote_protocol_features)];
5653
5654 /* The packet support flags are handled differently for this packet
5655 than for most others. We treat an error, a disabled packet, and
5656 an empty response identically: any features which must be reported
5657 to be used will be automatically disabled. An empty buffer
5658 accomplishes this, since that is also the representation for a list
5659 containing no features. */
5660
5661 rs->buf[0] = 0;
5663 {
5664 std::string q;
5665
5668 remote_query_supported_append (&q, "multiprocess+");
5669
5672 remote_query_supported_append (&q, "swbreak+");
5673
5676 remote_query_supported_append (&q, "hwbreak+");
5677
5678 remote_query_supported_append (&q, "qRelocInsn+");
5679
5682 remote_query_supported_append (&q, "fork-events+");
5683
5686 remote_query_supported_append (&q, "vfork-events+");
5687
5690 remote_query_supported_append (&q, "exec-events+");
5691
5694 remote_query_supported_append (&q, "vContSupported+");
5695
5698 remote_query_supported_append (&q, "QThreadEvents+");
5699
5702 remote_query_supported_append (&q, "no-resumed+");
5703
5706 remote_query_supported_append (&q, "memory-tagging+");
5707
5708 /* Keep this one last to work around a gdbserver <= 7.10 bug in
5709 the qSupported:xmlRegisters=i386 handling. */
5710 if (remote_support_xml != NULL
5712 != PACKET_DISABLE))
5714
5715 q = "qSupported:" + q;
5716 putpkt (q.c_str ());
5717
5718 getpkt (&rs->buf);
5719
5720 /* If an error occurred, warn, but do not return - just reset the
5721 buffer to empty and go on to disable features. */
5723 {
5724 warning (_("Remote failure reply: %s"), rs->buf.data ());
5725 rs->buf[0] = 0;
5726 }
5727 }
5728
5729 memset (seen, 0, sizeof (seen));
5730
5731 next = rs->buf.data ();
5732 while (*next)
5733 {
5734 enum packet_support is_supported;
5735 char *p, *end, *name_end, *value;
5736
5737 /* First separate out this item from the rest of the packet. If
5738 there's another item after this, we overwrite the separator
5739 (terminated strings are much easier to work with). */
5740 p = next;
5741 end = strchr (p, ';');
5742 if (end == NULL)
5743 {
5744 end = p + strlen (p);
5745 next = end;
5746 }
5747 else
5748 {
5749 *end = '\0';
5750 next = end + 1;
5751
5752 if (end == p)
5753 {
5754 warning (_("empty item in \"qSupported\" response"));
5755 continue;
5756 }
5757 }
5758
5759 name_end = strchr (p, '=');
5760 if (name_end)
5761 {
5762 /* This is a name=value entry. */
5763 is_supported = PACKET_ENABLE;
5764 value = name_end + 1;
5765 *name_end = '\0';
5766 }
5767 else
5768 {
5769 value = NULL;
5770 switch (end[-1])
5771 {
5772 case '+':
5773 is_supported = PACKET_ENABLE;
5774 break;
5775
5776 case '-':
5777 is_supported = PACKET_DISABLE;
5778 break;
5779
5780 case '?':
5781 is_supported = PACKET_SUPPORT_UNKNOWN;
5782 break;
5783
5784 default:
5785 warning (_("unrecognized item \"%s\" "
5786 "in \"qSupported\" response"), p);
5787 continue;
5788 }
5789 end[-1] = '\0';
5790 }
5791
5792 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
5793 if (strcmp (remote_protocol_features[i].name, p) == 0)
5794 {
5795 const struct protocol_feature *feature;
5796
5797 seen[i] = 1;
5798 feature = &remote_protocol_features[i];
5799 feature->func (this, feature, is_supported, value);
5800 break;
5801 }
5802 }
5803
5804 /* If we increased the packet size, make sure to increase the global
5805 buffer size also. We delay this until after parsing the entire
5806 qSupported packet, because this is the same buffer we were
5807 parsing. */
5808 if (rs->buf.size () < rs->explicit_packet_size)
5809 rs->buf.resize (rs->explicit_packet_size);
5810
5811 /* Handle the defaults for unmentioned features. */
5812 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
5813 if (!seen[i])
5814 {
5815 const struct protocol_feature *feature;
5816
5817 feature = &remote_protocol_features[i];
5818 feature->func (this, feature, feature->default_support, NULL);
5819 }
5820}
5821
5822/* Serial QUIT handler for the remote serial descriptor.
5823
5824 Defers handling a Ctrl-C until we're done with the current
5825 command/response packet sequence, unless:
5826
5827 - We're setting up the connection. Don't send a remote interrupt
5828 request, as we're not fully synced yet. Quit immediately
5829 instead.
5830
5831 - The target has been resumed in the foreground
5832 (target_terminal::is_ours is false) with a synchronous resume
5833 packet, and we're blocked waiting for the stop reply, thus a
5834 Ctrl-C should be immediately sent to the target.
5835
5836 - We get a second Ctrl-C while still within the same serial read or
5837 write. In that case the serial is seemingly wedged --- offer to
5838 quit/disconnect.
5839
5840 - We see a second Ctrl-C without target response, after having
5841 previously interrupted the target. In that case the target/stub
5842 is probably wedged --- offer to quit/disconnect.
5843*/
5845void
5847{
5848 struct remote_state *rs = get_remote_state ();
5849
5850 if (check_quit_flag ())
5851 {
5852 /* If we're starting up, we're not fully synced yet. Quit
5853 immediately. */
5854 if (rs->starting_up)
5855 quit ();
5856 else if (rs->got_ctrlc_during_io)
5857 {
5858 if (query (_("The target is not responding to GDB commands.\n"
5859 "Stop debugging it? ")))
5861 }
5862 /* If ^C has already been sent once, offer to disconnect. */
5863 else if (!target_terminal::is_ours () && rs->ctrlc_pending_p)
5864 interrupt_query ();
5865 /* All-stop protocol, and blocked waiting for stop reply. Send
5866 an interrupt request. */
5869 else
5870 rs->got_ctrlc_during_io = 1;
5871 }
5872}
5873
5874/* The remote_target that is current while the quit handler is
5875 overridden with remote_serial_quit_handler. */
5878static void
5880{
5882}
5883
5884/* Remove the remote target from the target stack of each inferior
5885 that is using it. Upper targets depend on it so remove them
5886 first. */
5888static void
5890{
5891 /* We have to unpush the target from all inferiors, even those that
5892 aren't running. */
5893 scoped_restore_current_inferior restore_current_inferior;
5894
5895 for (inferior *inf : all_inferiors (target))
5896 {
5898 inf->pop_all_targets_at_and_above (process_stratum);
5900 }
5901
5902 /* Don't rely on target_close doing this when the target is popped
5903 from the last remote inferior above, because something may be
5904 holding a reference to the target higher up on the stack, meaning
5905 target_close won't be called yet. We lost the connection to the
5906 target, so clear these now, otherwise we may later throw
5907 TARGET_CLOSE_ERROR while trying to tell the remote target to
5908 close the file. */
5910}
5912static void
5914{
5915 remote_unpush_target (target);
5916 throw_error (TARGET_CLOSE_ERROR, _("Disconnected from target."));
5917}
5919void
5920remote_target::open_1 (const char *name, int from_tty, int extended_p)
5921{
5922 remote_target *curr_remote = get_current_remote_target ();
5923
5924 if (name == 0)
5925 error (_("To open a remote debug connection, you need to specify what\n"
5926 "serial device is attached to the remote system\n"
5927 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
5928
5929 /* If we're connected to a running target, target_preopen will kill it.
5930 Ask this question first, before target_preopen has a chance to kill
5931 anything. */
5932 if (curr_remote != NULL && !target_has_execution ())
5933 {
5934 if (from_tty
5935 && !query (_("Already connected to a remote target. Disconnect? ")))
5936 error (_("Still connected."));
5937 }
5938
5939 /* Here the possibly existing remote target gets unpushed. */
5940 target_preopen (from_tty);
5941
5944 reread_symbols (from_tty);
5945
5946 remote_target *remote
5947 = (extended_p ? new extended_remote_target () : new remote_target ());
5948 target_ops_up target_holder (remote);
5949
5950 remote_state *rs = remote->get_remote_state ();
5951
5952 /* See FIXME above. */
5954 rs->wait_forever_enabled_p = true;
5955
5957 if (!rs->remote_desc)
5958 perror_with_name (name);
5959
5960 if (baud_rate != -1)
5961 {
5963 {
5964 /* The requested speed could not be set. Error out to
5965 top level after closing remote_desc. Take care to
5966 set remote_desc to NULL to avoid closing remote_desc
5967 more than once. */
5969 rs->remote_desc = NULL;
5970 perror_with_name (name);
5971 }
5972 }
5973
5975 serial_raw (rs->remote_desc);
5976
5977 /* If there is something sitting in the buffer we might take it as a
5978 response to a command, which would be bad. */
5980
5981 if (from_tty)
5982 {
5983 gdb_puts ("Remote debugging using ");
5984 gdb_puts (name);
5985 gdb_puts ("\n");
5986 }
5987
5988 /* Switch to using the remote target now. */
5989 current_inferior ()->push_target (std::move (target_holder));
5990
5991 /* Register extra event sources in the event loop. */
5994 "remote");
5996
5997 /* Reset the target state; these things will be queried either by
5998 remote_query_supported or as they are needed. */
6000 rs->explicit_packet_size = 0;
6001 rs->noack_mode = 0;
6002 rs->extended = extended_p;
6003 rs->waiting_for_stop_reply = 0;
6004 rs->ctrlc_pending_p = 0;
6005 rs->got_ctrlc_during_io = 0;
6006
6009 rs->remote_traceframe_number = -1;
6010
6012
6013 /* Probe for ability to use "ThreadInfo" query, as required. */
6014 rs->use_threadinfo_query = 1;
6015 rs->use_threadextra_query = 1;
6016
6018
6020 {
6021 /* FIXME: cagney/1999-09-23: During the initial connection it is
6022 assumed that the target is already ready and able to respond to
6023 requests. Unfortunately remote_start_remote() eventually calls
6024 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
6025 around this. Eventually a mechanism that allows
6026 wait_for_inferior() to expect/get timeouts will be
6027 implemented. */
6028 rs->wait_forever_enabled_p = false;
6029 }
6030
6031 /* First delete any symbols previously loaded from shared libraries. */
6032 no_shared_libraries (NULL, 0);
6033
6034 /* Start the remote connection. If error() or QUIT, discard this
6035 target (we'd otherwise be in an inconsistent state) and then
6036 propogate the error on up the exception chain. This ensures that
6037 the caller doesn't stumble along blindly assuming that the
6038 function succeeded. The CLI doesn't have this problem but other
6039 UI's, such as MI do.
6040
6041 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
6042 this function should return an error indication letting the
6043 caller restore the previous state. Unfortunately the command
6044 ``target remote'' is directly wired to this function making that
6045 impossible. On a positive note, the CLI side of this problem has
6046 been fixed - the function set_cmd_context() makes it possible for
6047 all the ``target ....'' commands to share a common callback
6048 function. See cli-dump.c. */
6049 {
6050
6051 try
6052 {
6053 remote->start_remote (from_tty, extended_p);
6054 }
6055 catch (const gdb_exception &ex)
6056 {
6057 /* Pop the partially set up target - unless something else did
6058 already before throwing the exception. */
6059 if (ex.error != TARGET_CLOSE_ERROR)
6060 remote_unpush_target (remote);
6061 throw;
6062 }
6063 }
6064
6066
6068 rs->wait_forever_enabled_p = true;
6069}
6070
6071/* Determine if WS represents a fork status. */
6073static bool
6075{
6076 return (kind == TARGET_WAITKIND_FORKED
6077 || kind == TARGET_WAITKIND_VFORKED);
6078}
6079
6080/* Return THREAD's pending status if it is a pending fork parent, else
6081 return nullptr. */
6083static const target_waitstatus *
6085{
6086 const target_waitstatus &ws
6087 = (thread->has_pending_waitstatus ()
6088 ? thread->pending_waitstatus ()
6089 : thread->pending_follow);
6090
6091 if (!is_fork_status (ws.kind ()))
6092 return nullptr;
6093
6094 return &ws;
6095}
6096
6097/* Detach the specified process. */
6099void
6101{
6102 struct remote_state *rs = get_remote_state ();
6103
6104 /* This should not be necessary, but the handling for D;PID in
6105 GDBserver versions prior to 8.2 incorrectly assumes that the
6106 selected process points to the same process we're detaching,
6107 leading to misbehavior (and possibly GDBserver crashing) when it
6108 does not. Since it's easy and cheap, work around it by forcing
6109 GDBserver to select GDB's current process. */
6111
6113 xsnprintf (rs->buf.data (), get_remote_packet_size (), "D;%x", pid);
6114 else
6115 strcpy (rs->buf.data (), "D");
6116
6117 putpkt (rs->buf);
6118 getpkt (&rs->buf);
6119
6120 if (rs->buf[0] == 'O' && rs->buf[1] == 'K')
6121 ;
6122 else if (rs->buf[0] == '\0')
6123 error (_("Remote doesn't know how to detach"));
6124 else
6125 error (_("Can't detach process."));
6126}
6127
6128/* This detaches a program to which we previously attached, using
6129 inferior_ptid to identify the process. After this is done, GDB
6130 can be used to debug some other program. We better not have left
6131 any breakpoints in the target program or it'll die when it hits
6132 one. */
6134void
6136{
6137 int pid = inferior_ptid.pid ();
6138 struct remote_state *rs = get_remote_state ();
6139 int is_fork_parent;
6140
6141 if (!target_has_execution ())
6142 error (_("No process to detach from."));
6143
6144 target_announce_detach (from_tty);
6145
6147 {
6148 /* If we're in breakpoints-always-inserted mode, or the inferior
6149 is running, we have to remove breakpoints before detaching.
6150 We don't do this in common code instead because not all
6151 targets support removing breakpoints while the target is
6152 running. The remote target / gdbserver does, though. */
6154 }
6155
6156 /* Tell the remote target to detach. */
6158
6159 /* Exit only if this is the only active inferior. */
6160 if (from_tty && !rs->extended && number_of_live_inferiors (this) == 1)
6161 gdb_puts (_("Ending remote debugging.\n"));
6162
6163 /* See if any thread of the inferior we are detaching has a pending fork
6164 status. In that case, we must detach from the child resulting from
6165 that fork. */
6166 for (thread_info *thread : inf->non_exited_threads ())
6167 {
6168 const target_waitstatus *ws = thread_pending_fork_status (thread);
6169
6170 if (ws == nullptr)
6171 continue;
6172
6173 remote_detach_pid (ws->child_ptid ().pid ());
6174 }
6175
6176 /* Check also for any pending fork events in the stop reply queue. */
6178 for (stop_reply_up &reply : rs->stop_reply_queue)
6179 {
6180 if (reply->ptid.pid () != pid)
6181 continue;
6182
6183 if (!is_fork_status (reply->ws.kind ()))
6184 continue;
6185
6186 remote_detach_pid (reply->ws.child_ptid ().pid ());
6187 }
6188
6190
6191 /* Check to see if we are detaching a fork parent. Note that if we
6192 are detaching a fork child, tp == NULL. */
6193 is_fork_parent = (tp != NULL
6195
6196 /* If doing detach-on-fork, we don't mourn, because that will delete
6197 breakpoints that should be available for the followed inferior. */
6198 if (!is_fork_parent)
6199 {
6200 /* Save the pid as a string before mourning, since that will
6201 unpush the remote target, and we need the string after. */
6202 std::string infpid = target_pid_to_str (ptid_t (pid));
6203
6206 gdb_printf (_("[Inferior %d (%s) detached]\n"),
6207 inf->num, infpid.c_str ());
6208 }
6209 else
6210 {
6213 }
6214}
6216void
6217remote_target::detach (inferior *inf, int from_tty)
6218{
6219 remote_detach_1 (inf, from_tty);
6220}
6222void
6224{
6225 remote_detach_1 (inf, from_tty);
6226}
6227
6228/* Target follow-fork function for remote targets. On entry, and
6229 at return, the current inferior is the fork parent.
6230
6231 Note that although this is currently only used for extended-remote,
6232 it is named remote_follow_fork in anticipation of using it for the
6233 remote target as well. */
6235void
6236remote_target::follow_fork (inferior *child_inf, ptid_t child_ptid,
6237 target_waitkind fork_kind, bool follow_child,
6238 bool detach_fork)
6239{
6240 process_stratum_target::follow_fork (child_inf, child_ptid,
6241 fork_kind, follow_child, detach_fork);
6242
6243 if ((fork_kind == TARGET_WAITKIND_FORKED
6245 || (fork_kind == TARGET_WAITKIND_VFORKED
6247 {
6248 /* When following the parent and detaching the child, we detach
6249 the child here. For the case of following the child and
6250 detaching the parent, the detach is done in the target-
6251 independent follow fork code in infrun.c. We can't use
6252 target_detach when detaching an unfollowed child because
6253 the client side doesn't know anything about the child. */
6254 if (detach_fork && !follow_child)
6255 {
6256 /* Detach the fork child. */
6257 remote_detach_pid (child_ptid.pid ());
6258 }
6259 }
6260}
6261
6262/* Target follow-exec function for remote targets. Save EXECD_PATHNAME
6263 in the program space of the new inferior. */
6265void
6266remote_target::follow_exec (inferior *follow_inf, ptid_t ptid,
6267 const char *execd_pathname)
6268{
6269 process_stratum_target::follow_exec (follow_inf, ptid, execd_pathname);
6270
6271 /* We know that this is a target file name, so if it has the "target:"
6272 prefix we strip it off before saving it in the program space. */
6273 if (is_target_filename (execd_pathname))
6274 execd_pathname += strlen (TARGET_SYSROOT_PREFIX);
6275
6276 set_pspace_remote_exec_file (follow_inf->pspace, execd_pathname);
6277}
6278
6279/* Same as remote_detach, but don't send the "D" packet; just disconnect. */
6281void
6282remote_target::disconnect (const char *args, int from_tty)
6283{
6284 if (args)
6285 error (_("Argument given to \"disconnect\" when remotely debugging."));
6286
6287 /* Make sure we unpush even the extended remote targets. Calling
6288 target_mourn_inferior won't unpush, and
6289 remote_target::mourn_inferior won't unpush if there is more than
6290 one inferior left. */
6291 remote_unpush_target (this);
6292
6293 if (from_tty)
6294 gdb_puts ("Ending remote debugging.\n");
6295}
6296
6297/* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
6298 be chatty about it. */
6300void
6301extended_remote_target::attach (const char *args, int from_tty)
6302{
6303 struct remote_state *rs = get_remote_state ();
6304 int pid;
6305 char *wait_status = NULL;
6306
6307 pid = parse_pid_to_attach (args);
6308
6309 /* Remote PID can be freely equal to getpid, do not check it here the same
6310 way as in other targets. */
6311
6313 error (_("This target does not support attaching to a process"));
6314
6315 target_announce_attach (from_tty, pid);
6316
6317 xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid);
6318 putpkt (rs->buf);
6319 getpkt (&rs->buf);
6320
6321 switch (m_features.packet_ok (rs->buf, PACKET_vAttach))
6322 {
6323 case PACKET_OK:
6324 if (!target_is_non_stop_p ())
6325 {
6326 /* Save the reply for later. */
6327 wait_status = (char *) alloca (strlen (rs->buf.data ()) + 1);
6328 strcpy (wait_status, rs->buf.data ());
6329 }
6330 else if (strcmp (rs->buf.data (), "OK") != 0)
6331 error (_("Attaching to %s failed with: %s"),
6332 target_pid_to_str (ptid_t (pid)).c_str (),
6333 rs->buf.data ());
6334 break;
6335 case PACKET_UNKNOWN:
6336 error (_("This target does not support attaching to a process"));
6337 default:
6338 error (_("Attaching to %s failed"),
6339 target_pid_to_str (ptid_t (pid)).c_str ());
6340 }
6341
6343
6344 inferior_ptid = ptid_t (pid);
6345
6346 if (target_is_non_stop_p ())
6347 {
6348 /* Get list of threads. */
6350
6352 if (thread != nullptr)
6353 switch_to_thread (thread);
6354
6355 /* Invalidate our notion of the remote current thread. */
6356 record_currthread (rs, minus_one_ptid);
6357 }
6358 else
6359 {
6360 /* Now, if we have thread information, update the main thread's
6361 ptid. */
6362 ptid_t curr_ptid = remote_current_thread (ptid_t (pid));
6363
6364 /* Add the main thread to the thread list. We add the thread
6365 silently in this case (the final true parameter). */
6366 thread_info *thr = remote_add_thread (curr_ptid, true, true, true);
6367
6368 switch_to_thread (thr);
6369 }
6370
6371 /* Next, if the target can specify a description, read it. We do
6372 this before anything involving memory or registers. */
6374
6375 if (!target_is_non_stop_p ())
6376 {
6377 /* Use the previously fetched status. */
6378 gdb_assert (wait_status != NULL);
6379
6380 struct notif_event *reply
6381 = remote_notif_parse (this, &notif_client_stop, wait_status);
6382
6383 push_stop_reply ((struct stop_reply *) reply);
6384 }
6385 else
6386 {
6387 gdb_assert (wait_status == NULL);
6388
6389 gdb_assert (target_can_async_p ());
6390 }
6391}
6392
6393/* Implementation of the to_post_attach method. */
6395void
6397{
6398 /* Get text, data & bss offsets. */
6399 get_offsets ();
6400
6401 /* In certain cases GDB might not have had the chance to start
6402 symbol lookup up until now. This could happen if the debugged
6403 binary is not using shared libraries, the vsyscall page is not
6404 present (on Linux) and the binary itself hadn't changed since the
6405 debugging process was started. */
6408}
6409
6410
6411/* Check for the availability of vCont. This function should also check
6412 the response. */
6414void
6416{
6418 char *buf;
6419
6420 strcpy (rs->buf.data (), "vCont?");
6421 putpkt (rs->buf);
6422 getpkt (&rs->buf);
6423 buf = rs->buf.data ();
6424
6425 /* Make sure that the features we assume are supported. */
6426 if (startswith (buf, "vCont"))
6427 {
6428 char *p = &buf[5];
6429 int support_c, support_C;
6430
6431 rs->supports_vCont.s = 0;
6432 rs->supports_vCont.S = 0;
6433 support_c = 0;
6434 support_C = 0;
6435 rs->supports_vCont.t = 0;
6436 rs->supports_vCont.r = 0;
6437 while (p && *p == ';')
6438 {
6439 p++;
6440 if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0))
6441 rs->supports_vCont.s = 1;
6442 else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0))
6443 rs->supports_vCont.S = 1;
6444 else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0))
6445 support_c = 1;
6446 else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0))
6447 support_C = 1;
6448 else if (*p == 't' && (*(p + 1) == ';' || *(p + 1) == 0))
6449 rs->supports_vCont.t = 1;
6450 else if (*p == 'r' && (*(p + 1) == ';' || *(p + 1) == 0))
6451 rs->supports_vCont.r = 1;
6452
6453 p = strchr (p, ';');
6454 }
6455
6456 /* If c, and C are not all supported, we can't use vCont. Clearing
6457 BUF will make packet_ok disable the packet. */
6458 if (!support_c || !support_C)
6459 buf[0] = 0;
6460 }
6461
6463}
6464
6465/* Helper function for building "vCont" resumptions. Write a
6466 resumption to P. ENDP points to one-passed-the-end of the buffer
6467 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
6468 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
6469 resumed thread should be single-stepped and/or signalled. If PTID
6470 equals minus_one_ptid, then all threads are resumed; if PTID
6471 represents a process, then all threads of the process are
6472 resumed. */
6474char *
6475remote_target::append_resumption (char *p, char *endp,
6476 ptid_t ptid, int step, gdb_signal siggnal)
6477{
6478 struct remote_state *rs = get_remote_state ();
6479
6480 if (step && siggnal != GDB_SIGNAL_0)
6481 p += xsnprintf (p, endp - p, ";S%02x", siggnal);
6482 else if (step
6483 /* GDB is willing to range step. */
6485 /* Target supports range stepping. */
6486 && rs->supports_vCont.r
6487 /* We don't currently support range stepping multiple
6488 threads with a wildcard (though the protocol allows it,
6489 so stubs shouldn't make an active effort to forbid
6490 it). */
6491 && !(m_features.remote_multi_process_p () && ptid.is_pid ()))
6492 {
6493 struct thread_info *tp;
6494
6495 if (ptid == minus_one_ptid)
6496 {
6497 /* If we don't know about the target thread's tid, then
6498 we're resuming magic_null_ptid (see caller). */
6499 tp = this->find_thread (magic_null_ptid);
6500 }
6501 else
6502 tp = this->find_thread (ptid);
6503 gdb_assert (tp != NULL);
6504
6505 if (tp->control.may_range_step)
6506 {
6507 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
6508
6509 p += xsnprintf (p, endp - p, ";r%s,%s",
6510 phex_nz (tp->control.step_range_start,
6511 addr_size),
6512 phex_nz (tp->control.step_range_end,
6513 addr_size));
6514 }
6515 else
6516 p += xsnprintf (p, endp - p, ";s");
6517 }
6518 else if (step)
6519 p += xsnprintf (p, endp - p, ";s");
6520 else if (siggnal != GDB_SIGNAL_0)
6521 p += xsnprintf (p, endp - p, ";C%02x", siggnal);
6522 else
6523 p += xsnprintf (p, endp - p, ";c");
6524
6525 if (m_features.remote_multi_process_p () && ptid.is_pid ())
6526 {
6527 ptid_t nptid;
6528
6529 /* All (-1) threads of process. */
6530 nptid = ptid_t (ptid.pid (), -1);
6531
6532 p += xsnprintf (p, endp - p, ":");
6533 p = write_ptid (p, endp, nptid);
6534 }
6535 else if (ptid != minus_one_ptid)
6536 {
6537 p += xsnprintf (p, endp - p, ":");
6538 p = write_ptid (p, endp, ptid);
6539 }
6540
6541 return p;
6542}
6543
6544/* Clear the thread's private info on resume. */
6546static void
6548{
6549 if (thread->priv != NULL)
6550 {
6552
6554 priv->watch_data_address = 0;
6555 }
6556}
6557
6558/* Append a vCont continue-with-signal action for threads that have a
6559 non-zero stop signal. */
6561char *
6563 ptid_t ptid)
6564{
6565 for (thread_info *thread : all_non_exited_threads (this, ptid))
6566 if (inferior_ptid != thread->ptid
6567 && thread->stop_signal () != GDB_SIGNAL_0)
6568 {
6569 p = append_resumption (p, endp, thread->ptid,
6570 0, thread->stop_signal ());
6571 thread->set_stop_signal (GDB_SIGNAL_0);
6573 }
6574
6575 return p;
6576}
6577
6578/* Set the target running, using the packets that use Hc
6579 (c/s/C/S). */
6581void
6582remote_target::remote_resume_with_hc (ptid_t ptid, int step,
6583 gdb_signal siggnal)
6584{
6585 struct remote_state *rs = get_remote_state ();
6586 char *buf;
6587
6588 rs->last_sent_signal = siggnal;
6589 rs->last_sent_step = step;
6590
6591 /* The c/s/C/S resume packets use Hc, so set the continue
6592 thread. */
6593 if (ptid == minus_one_ptid)
6595 else
6596 set_continue_thread (ptid);
6597
6598 for (thread_info *thread : all_non_exited_threads (this))
6600
6601 buf = rs->buf.data ();
6603 {
6604 /* We don't pass signals to the target in reverse exec mode. */
6605 if (info_verbose && siggnal != GDB_SIGNAL_0)
6606 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
6607 siggnal);
6608
6610 error (_("Remote reverse-step not supported."));
6612 error (_("Remote reverse-continue not supported."));
6613
6614 strcpy (buf, step ? "bs" : "bc");
6615 }
6616 else if (siggnal != GDB_SIGNAL_0)
6617 {
6618 buf[0] = step ? 'S' : 'C';
6619 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
6620 buf[2] = tohex (((int) siggnal) & 0xf);
6621 buf[3] = '\0';
6622 }
6623 else
6624 strcpy (buf, step ? "s" : "c");
6625
6626 putpkt (buf);
6627}
6628
6629/* Resume the remote inferior by using a "vCont" packet. SCOPE_PTID,
6630 STEP, and SIGGNAL have the same meaning as in target_resume. This
6631 function returns non-zero iff it resumes the inferior.
6632
6633 This function issues a strict subset of all possible vCont commands
6634 at the moment. */
6636int
6637remote_target::remote_resume_with_vcont (ptid_t scope_ptid, int step,
6638 enum gdb_signal siggnal)
6639{
6640 struct remote_state *rs = get_remote_state ();
6641 char *p;
6642 char *endp;
6643
6644 /* No reverse execution actions defined for vCont. */
6646 return 0;
6647
6649 return 0;
6650
6651 p = rs->buf.data ();
6652 endp = p + get_remote_packet_size ();
6653
6654 /* If we could generate a wider range of packets, we'd have to worry
6655 about overflowing BUF. Should there be a generic
6656 "multi-part-packet" packet? */
6657
6658 p += xsnprintf (p, endp - p, "vCont");
6659
6660 if (scope_ptid == magic_null_ptid)
6661 {
6662 /* MAGIC_NULL_PTID means that we don't have any active threads,
6663 so we don't have any TID numbers the inferior will
6664 understand. Make sure to only send forms that do not specify
6665 a TID. */
6666 append_resumption (p, endp, minus_one_ptid, step, siggnal);
6667 }
6668 else if (scope_ptid == minus_one_ptid || scope_ptid.is_pid ())
6669 {
6670 /* Resume all threads (of all processes, or of a single
6671 process), with preference for INFERIOR_PTID. This assumes
6672 inferior_ptid belongs to the set of all threads we are about
6673 to resume. */
6674 if (step || siggnal != GDB_SIGNAL_0)
6675 {
6676 /* Step inferior_ptid, with or without signal. */
6677 p = append_resumption (p, endp, inferior_ptid, step, siggnal);
6678 }
6679
6680 /* Also pass down any pending signaled resumption for other
6681 threads not the current. */
6682 p = append_pending_thread_resumptions (p, endp, scope_ptid);
6683
6684 /* And continue others without a signal. */
6685 append_resumption (p, endp, scope_ptid, /*step=*/ 0, GDB_SIGNAL_0);
6686 }
6687 else
6688 {
6689 /* Scheduler locking; resume only SCOPE_PTID. */
6690 append_resumption (p, endp, scope_ptid, step, siggnal);
6691 }
6692
6693 gdb_assert (strlen (rs->buf.data ()) < get_remote_packet_size ());
6694 putpkt (rs->buf);
6695
6696 if (target_is_non_stop_p ())
6697 {
6698 /* In non-stop, the stub replies to vCont with "OK". The stop
6699 reply will be reported asynchronously by means of a `%Stop'
6700 notification. */
6701 getpkt (&rs->buf);
6702 if (strcmp (rs->buf.data (), "OK") != 0)
6703 error (_("Unexpected vCont reply in non-stop mode: %s"),
6704 rs->buf.data ());
6705 }
6706
6707 return 1;
6708}
6709
6710/* Tell the remote machine to resume. */
6712void
6713remote_target::resume (ptid_t scope_ptid, int step, enum gdb_signal siggnal)
6714{
6715 struct remote_state *rs = get_remote_state ();
6716
6717 /* When connected in non-stop mode, the core resumes threads
6718 individually. Resuming remote threads directly in target_resume
6719 would thus result in sending one packet per thread. Instead, to
6720 minimize roundtrip latency, here we just store the resume
6721 request (put the thread in RESUMED_PENDING_VCONT state); the actual remote
6722 resumption will be done in remote_target::commit_resume, where we'll be
6723 able to do vCont action coalescing. */
6725 {
6726 remote_thread_info *remote_thr
6728
6729 /* We don't expect the core to ask to resume an already resumed (from
6730 its point of view) thread. */
6731 gdb_assert (remote_thr->get_resume_state () == resume_state::NOT_RESUMED);
6732
6733 remote_thr->set_resumed_pending_vcont (step, siggnal);
6734
6735 /* There's actually nothing that says that the core can't
6736 request a wildcard resume in non-stop mode, though. It's
6737 just that we know it doesn't currently, so we don't bother
6738 with it. */
6739 gdb_assert (scope_ptid == inferior_ptid);
6740 return;
6741 }
6742
6743 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
6744 (explained in remote-notif.c:handle_notification) so
6745 remote_notif_process is not called. We need find a place where
6746 it is safe to start a 'vNotif' sequence. It is good to do it
6747 before resuming inferior, because inferior was stopped and no RSP
6748 traffic at that moment. */
6749 if (!target_is_non_stop_p ())
6751
6753
6754 /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
6755 if (!remote_resume_with_vcont (scope_ptid, step, siggnal))
6756 remote_resume_with_hc (scope_ptid, step, siggnal);
6757
6758 /* Update resumed state tracked by the remote target. */
6759 for (thread_info *tp : all_non_exited_threads (this, scope_ptid))
6761
6762 /* We've just told the target to resume. The remote server will
6763 wait for the inferior to stop, and then send a stop reply. In
6764 the mean time, we can't start another command/query ourselves
6765 because the stub wouldn't be ready to process it. This applies
6766 only to the base all-stop protocol, however. In non-stop (which
6767 only supports vCont), the stub replies with an "OK", and is
6768 immediate able to process further serial input. */
6769 if (!target_is_non_stop_p ())
6770 rs->waiting_for_stop_reply = 1;
6771}
6772
6773/* Private per-inferior info for target remote processes. */
6774
6775struct remote_inferior : public private_inferior
6777 /* Whether we can send a wildcard vCont for this process. */
6778 bool may_wildcard_vcont = true;
6779};
6780
6781/* Get the remote private inferior data associated to INF. */
6783static remote_inferior *
6785{
6786 if (inf->priv == NULL)
6787 inf->priv.reset (new remote_inferior);
6788
6789 return gdb::checked_static_cast<remote_inferior *> (inf->priv.get ());
6790}
6791
6792/* Class used to track the construction of a vCont packet in the
6793 outgoing packet buffer. This is used to send multiple vCont
6794 packets if we have more actions than would fit a single packet. */
6795
6796class vcont_builder
6798public:
6799 explicit vcont_builder (remote_target *remote)
6800 : m_remote (remote)
6801 {
6802 restart ();
6803 }
6804
6805 void flush ();
6806 void push_action (ptid_t ptid, bool step, gdb_signal siggnal);
6807
6808private:
6809 void restart ();
6811 /* The remote target. */
6813
6814 /* Pointer to the first action. P points here if no action has been
6815 appended yet. */
6816 char *m_first_action;
6818 /* Where the next action will be appended. */
6819 char *m_p;
6821 /* The end of the buffer. Must never write past this. */
6822 char *m_endp;
6823};
6824
6825/* Prepare the outgoing buffer for a new vCont packet. */
6827void
6829{
6830 struct remote_state *rs = m_remote->get_remote_state ();
6831
6832 m_p = rs->buf.data ();
6834 m_p += xsnprintf (m_p, m_endp - m_p, "vCont");
6836}
6837
6838/* If the vCont packet being built has any action, send it to the
6839 remote end. */
6841void
6843{
6844 struct remote_state *rs;
6845
6846 if (m_p == m_first_action)
6847 return;
6848
6849 rs = m_remote->get_remote_state ();
6850 m_remote->putpkt (rs->buf);
6851 m_remote->getpkt (&rs->buf);
6852 if (strcmp (rs->buf.data (), "OK") != 0)
6853 error (_("Unexpected vCont reply in non-stop mode: %s"), rs->buf.data ());
6854}
6855
6856/* The largest action is range-stepping, with its two addresses. This
6857 is more than sufficient. If a new, bigger action is created, it'll
6858 quickly trigger a failed assertion in append_resumption (and we'll
6859 just bump this). */
6860#define MAX_ACTION_SIZE 200
6861
6862/* Append a new vCont action in the outgoing packet being built. If
6863 the action doesn't fit the packet along with previous actions, push
6864 what we've got so far to the remote end and start over a new vCont
6865 packet (with the new action). */
6867void
6868vcont_builder::push_action (ptid_t ptid, bool step, gdb_signal siggnal)
6869{
6870 char buf[MAX_ACTION_SIZE + 1];
6871
6872 char *endp = m_remote->append_resumption (buf, buf + sizeof (buf),
6873 ptid, step, siggnal);
6874
6875 /* Check whether this new action would fit in the vCont packet along
6876 with previous actions. If not, send what we've got so far and
6877 start a new vCont packet. */
6878 size_t rsize = endp - buf;
6879 if (rsize > m_endp - m_p)
6880 {
6881 flush ();
6882 restart ();
6883
6884 /* Should now fit. */
6885 gdb_assert (rsize <= m_endp - m_p);
6886 }
6887
6888 memcpy (m_p, buf, rsize);
6889 m_p += rsize;
6890 *m_p = '\0';
6891}
6892
6893/* to_commit_resume implementation. */
6895void
6897{
6898 /* If connected in all-stop mode, we'd send the remote resume
6899 request directly from remote_resume. Likewise if
6900 reverse-debugging, as there are no defined vCont actions for
6901 reverse execution. */
6903 return;
6904
6905 /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
6906 instead of resuming all threads of each process individually.
6907 However, if any thread of a process must remain halted, we can't
6908 send wildcard resumes and must send one action per thread.
6909
6910 Care must be taken to not resume threads/processes the server
6911 side already told us are stopped, but the core doesn't know about
6912 yet, because the events are still in the vStopped notification
6913 queue. For example:
6914
6915 #1 => vCont s:p1.1;c
6916 #2 <= OK
6917 #3 <= %Stopped T05 p1.1
6918 #4 => vStopped
6919 #5 <= T05 p1.2
6920 #6 => vStopped
6921 #7 <= OK
6922 #8 (infrun handles the stop for p1.1 and continues stepping)
6923 #9 => vCont s:p1.1;c
6924
6925 The last vCont above would resume thread p1.2 by mistake, because
6926 the server has no idea that the event for p1.2 had not been
6927 handled yet.
6928
6929 The server side must similarly ignore resume actions for the
6930 thread that has a pending %Stopped notification (and any other
6931 threads with events pending), until GDB acks the notification
6932 with vStopped. Otherwise, e.g., the following case is
6933 mishandled:
6934
6935 #1 => g (or any other packet)
6936 #2 <= [registers]
6937 #3 <= %Stopped T05 p1.2
6938 #4 => vCont s:p1.1;c
6939 #5 <= OK
6940
6941 Above, the server must not resume thread p1.2. GDB can't know
6942 that p1.2 stopped until it acks the %Stopped notification, and
6943 since from GDB's perspective all threads should be running, it
6944 sends a "c" action.
6945
6946 Finally, special care must also be given to handling fork/vfork
6947 events. A (v)fork event actually tells us that two processes
6948 stopped -- the parent and the child. Until we follow the fork,
6949 we must not resume the child. Therefore, if we have a pending
6950 fork follow, we must not send a global wildcard resume action
6951 (vCont;c). We can still send process-wide wildcards though. */
6952
6953 /* Start by assuming a global wildcard (vCont;c) is possible. */
6954 bool may_global_wildcard_vcont = true;
6955
6956 /* And assume every process is individually wildcard-able too. */
6957 for (inferior *inf : all_non_exited_inferiors (this))
6958 {
6960
6961 priv->may_wildcard_vcont = true;
6962 }
6963
6964 /* Check for any pending events (not reported or processed yet) and
6965 disable process and global wildcard resumes appropriately. */
6966 check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont);
6967
6968 bool any_pending_vcont_resume = false;
6969
6970 for (thread_info *tp : all_non_exited_threads (this))
6971 {
6973
6974 /* If a thread of a process is not meant to be resumed, then we
6975 can't wildcard that process. */
6977 {
6978 get_remote_inferior (tp->inf)->may_wildcard_vcont = false;
6979
6980 /* And if we can't wildcard a process, we can't wildcard
6981 everything either. */
6982 may_global_wildcard_vcont = false;
6983 continue;
6984 }
6985
6987 any_pending_vcont_resume = true;
6988
6989 /* If a thread is the parent of an unfollowed fork, then we
6990 can't do a global wildcard, as that would resume the fork
6991 child. */
6992 if (thread_pending_fork_status (tp) != nullptr)
6993 may_global_wildcard_vcont = false;
6994 }
6995
6996 /* We didn't have any resumed thread pending a vCont resume, so nothing to
6997 do. */
6998 if (!any_pending_vcont_resume)
6999 return;
7000
7001 /* Now let's build the vCont packet(s). Actions must be appended
7002 from narrower to wider scopes (thread -> process -> global). If
7003 we end up with too many actions for a single packet vcont_builder
7004 flushes the current vCont packet to the remote side and starts a
7005 new one. */
7006 struct vcont_builder vcont_builder (this);
7007
7008 /* Threads first. */
7009 for (thread_info *tp : all_non_exited_threads (this))
7010 {
7011 remote_thread_info *remote_thr = get_remote_thread_info (tp);
7012
7013 /* If the thread was previously vCont-resumed, no need to send a specific
7014 action for it. If we didn't receive a resume request for it, don't
7015 send an action for it either. */
7017 continue;
7018
7019 gdb_assert (!thread_is_in_step_over_chain (tp));
7020
7021 /* We should never be commit-resuming a thread that has a stop reply.
7022 Otherwise, we would end up reporting a stop event for a thread while
7023 it is running on the remote target. */
7025 for (const auto &stop_reply : rs->stop_reply_queue)
7026 gdb_assert (stop_reply->ptid != tp->ptid);
7027
7029 = remote_thr->resumed_pending_vcont_info ();
7030
7031 /* Check if we need to send a specific action for this thread. If not,
7032 it will be included in a wildcard resume instead. */
7033 if (info.step || info.sig != GDB_SIGNAL_0
7035 vcont_builder.push_action (tp->ptid, info.step, info.sig);
7036
7037 remote_thr->set_resumed ();
7038 }
7039
7040 /* Now check whether we can send any process-wide wildcard. This is
7041 to avoid sending a global wildcard in the case nothing is
7042 supposed to be resumed. */
7043 bool any_process_wildcard = false;
7044
7045 for (inferior *inf : all_non_exited_inferiors (this))
7046 {
7048 {
7049 any_process_wildcard = true;
7050 break;
7051 }
7052 }
7053
7054 if (any_process_wildcard)
7055 {
7056 /* If all processes are wildcard-able, then send a single "c"
7057 action, otherwise, send an "all (-1) threads of process"
7058 continue action for each running process, if any. */
7059 if (may_global_wildcard_vcont)
7060 {
7061 vcont_builder.push_action (minus_one_ptid,
7062 false, GDB_SIGNAL_0);
7063 }
7064 else
7065 {
7066 for (inferior *inf : all_non_exited_inferiors (this))
7067 {
7069 {
7070 vcont_builder.push_action (ptid_t (inf->pid),
7071 false, GDB_SIGNAL_0);
7072 }
7073 }
7074 }
7075 }
7076
7078}
7079
7080/* Implementation of target_has_pending_events. */
7082bool
7084{
7085 if (target_can_async_p ())
7086 {
7088
7090 return true;
7091
7092 /* Note that BUFCNT can be negative, indicating sticky
7093 error. */
7094 if (rs->remote_desc->bufcnt != 0)
7095 return true;
7096 }
7097 return false;
7098}
7099
7100
7101
7102/* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
7103 thread, all threads of a remote process, or all threads of all
7104 processes. */
7106void
7108{
7109 struct remote_state *rs = get_remote_state ();
7110 char *p = rs->buf.data ();
7111 char *endp = p + get_remote_packet_size ();
7112
7113 /* If any thread that needs to stop was resumed but pending a vCont
7114 resume, generate a phony stop_reply. However, first check
7115 whether the thread wasn't resumed with a signal. Generating a
7116 phony stop in that case would result in losing the signal. */
7117 bool needs_commit = false;
7118 for (thread_info *tp : all_non_exited_threads (this, ptid))
7119 {
7120 remote_thread_info *remote_thr = get_remote_thread_info (tp);
7121
7122 if (remote_thr->get_resume_state ()
7124 {
7126 = remote_thr->resumed_pending_vcont_info ();
7127 if (info.sig != GDB_SIGNAL_0)
7128 {
7129 /* This signal must be forwarded to the inferior. We
7130 could commit-resume just this thread, but its simpler
7131 to just commit-resume everything. */
7132 needs_commit = true;
7133 break;
7134 }
7135 }
7136 }
7137
7138 if (needs_commit)
7139 commit_resumed ();
7140 else
7141 for (thread_info *tp : all_non_exited_threads (this, ptid))
7142 {
7143 remote_thread_info *remote_thr = get_remote_thread_info (tp);
7144
7145 if (remote_thr->get_resume_state ()
7147 {
7148 remote_debug_printf ("Enqueueing phony stop reply for thread pending "
7149 "vCont-resume (%d, %ld, %s)", tp->ptid.pid(),
7150 tp->ptid.lwp (),
7151 pulongest (tp->ptid.tid ()));
7152
7153 /* Check that the thread wasn't resumed with a signal.
7154 Generating a phony stop would result in losing the
7155 signal. */
7157 = remote_thr->resumed_pending_vcont_info ();
7158 gdb_assert (info.sig == GDB_SIGNAL_0);
7159
7160 stop_reply *sr = new stop_reply ();
7161 sr->ptid = tp->ptid;
7162 sr->rs = rs;
7163 sr->ws.set_stopped (GDB_SIGNAL_0);
7164 sr->arch = tp->inf->gdbarch;
7166 sr->watch_data_address = 0;
7167 sr->core = 0;
7168 this->push_stop_reply (sr);
7169
7170 /* Pretend that this thread was actually resumed on the
7171 remote target, then stopped. If we leave it in the
7172 RESUMED_PENDING_VCONT state and the commit_resumed
7173 method is called while the stop reply is still in the
7174 queue, we'll end up reporting a stop event to the core
7175 for that thread while it is running on the remote
7176 target... that would be bad. */
7177 remote_thr->set_resumed ();
7178 }
7179 }
7180
7181 if (!rs->supports_vCont.t)
7182 error (_("Remote server does not support stopping threads"));
7183
7184 if (ptid == minus_one_ptid
7185 || (!m_features.remote_multi_process_p () && ptid.is_pid ()))
7186 p += xsnprintf (p, endp - p, "vCont;t");
7187 else
7188 {
7189 ptid_t nptid;
7190
7191 p += xsnprintf (p, endp - p, "vCont;t:");
7192
7193 if (ptid.is_pid ())
7194 /* All (-1) threads of process. */
7195 nptid = ptid_t (ptid.pid (), -1);
7196 else
7197 {
7198 /* Small optimization: if we already have a stop reply for
7199 this thread, no use in telling the stub we want this
7200 stopped. */
7201 if (peek_stop_reply (ptid))
7202 return;
7203
7204 nptid = ptid;
7205 }
7206
7207 write_ptid (p, endp, nptid);
7208 }
7209
7210 /* In non-stop, we get an immediate OK reply. The stop reply will
7211 come in asynchronously by notification. */
7212 putpkt (rs->buf);
7213 getpkt (&rs->buf);
7214 if (strcmp (rs->buf.data (), "OK") != 0)
7215 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid).c_str (),
7216 rs->buf.data ());
7217}
7218
7219/* All-stop version of target_interrupt. Sends a break or a ^C to
7220 interrupt the remote target. It is undefined which thread of which
7221 process reports the interrupt. */
7223void
7225{
7226 struct remote_state *rs = get_remote_state ();
7227
7228 rs->ctrlc_pending_p = 1;
7229
7230 /* If the inferior is stopped already, but the core didn't know
7231 about it yet, just ignore the request. The pending stop events
7232 will be collected in remote_wait. */
7233 if (stop_reply_queue_length () > 0)
7234 return;
7235
7236 /* Send interrupt_sequence to remote target. */
7238}
7239
7240/* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
7241 the remote target. It is undefined which thread of which process
7242 reports the interrupt. Throws an error if the packet is not
7243 supported by the server. */
7245void
7247{
7248 struct remote_state *rs = get_remote_state ();
7249 char *p = rs->buf.data ();
7250 char *endp = p + get_remote_packet_size ();
7251
7252 xsnprintf (p, endp - p, "vCtrlC");
7253
7254 /* In non-stop, we get an immediate OK reply. The stop reply will
7255 come in asynchronously by notification. */
7256 putpkt (rs->buf);
7257 getpkt (&rs->buf);
7258
7259 switch (m_features.packet_ok (rs->buf, PACKET_vCtrlC))
7260 {
7261 case PACKET_OK:
7262 break;
7263 case PACKET_UNKNOWN:
7264 error (_("No support for interrupting the remote target."));
7265 case PACKET_ERROR:
7266 error (_("Interrupting target failed: %s"), rs->buf.data ());
7267 }
7268}
7269
7270/* Implement the to_stop function for the remote targets. */
7272void
7273remote_target::stop (ptid_t ptid)
7274{
7276
7277 if (target_is_non_stop_p ())
7278 remote_stop_ns (ptid);
7279 else
7280 {
7281 /* We don't currently have a way to transparently pause the
7282 remote target in all-stop mode. Interrupt it instead. */
7284 }
7285}
7286
7287/* Implement the to_interrupt function for the remote targets. */
7289void
7291{
7293
7294 if (target_is_non_stop_p ())
7296 else
7298}
7299
7300/* Implement the to_pass_ctrlc function for the remote targets. */
7302void
7304{
7306
7307 struct remote_state *rs = get_remote_state ();
7308
7309 /* If we're starting up, we're not fully synced yet. Quit
7310 immediately. */
7311 if (rs->starting_up)
7312 quit ();
7313 /* If ^C has already been sent once, offer to disconnect. */
7314 else if (rs->ctrlc_pending_p)
7315 interrupt_query ();
7316 else
7318}
7319
7320/* Ask the user what to do when an interrupt is received. */
7322void
7324{
7325 struct remote_state *rs = get_remote_state ();
7326
7328 {
7329 if (query (_("The target is not responding to interrupt requests.\n"
7330 "Stop debugging it? ")))
7331 {
7332 remote_unpush_target (this);
7333 throw_error (TARGET_CLOSE_ERROR, _("Disconnected from target."));
7334 }
7335 }
7336 else
7337 {
7338 if (query (_("Interrupted while waiting for the program.\n"
7339 "Give up waiting? ")))
7340 quit ();
7341 }
7342}
7343
7344/* Enable/disable target terminal ownership. Most targets can use
7345 terminal groups to control terminal ownership. Remote targets are
7346 different in that explicit transfer of ownership to/from GDB/target
7347 is required. */
7349void
7351{
7352 /* NOTE: At this point we could also register our selves as the
7353 recipient of all input. Any characters typed could then be
7354 passed on down to the target. */
7355}
7359{
7360}
7362static void
7363remote_console_output (const char *msg)
7364{
7365 const char *p;
7366
7367 for (p = msg; p[0] && p[1]; p += 2)
7368 {
7369 char tb[2];
7370 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
7371
7372 tb[0] = c;
7373 tb[1] = 0;
7374 gdb_stdtarg->puts (tb);
7375 }
7376 gdb_stdtarg->flush ();
7377}
7378
7379/* Return the length of the stop reply queue. */
7385 return rs->stop_reply_queue.size ();
7386}
7388static void
7390 const notif_client *self, const char *buf,
7391 struct notif_event *event)
7392{
7393 remote->remote_parse_stop_reply (buf, (struct stop_reply *) event);
7394}
7396static void
7398 const notif_client *self, const char *buf,
7399 struct notif_event *event)
7400{
7401 struct stop_reply *stop_reply = (struct stop_reply *) event;
7402
7403 /* acknowledge */
7404 putpkt (remote, self->ack_command);
7405
7406 /* Kind can be TARGET_WAITKIND_IGNORE if we have meanwhile discarded
7407 the notification. It was left in the queue because we need to
7408 acknowledge it and pull the rest of the notifications out. */
7410 remote->push_stop_reply (stop_reply);
7411}
7413static int
7415 const notif_client *self)
7416{
7417 /* We can't get pending events in remote_notif_process for
7418 notification stop, and we have to do this in remote_wait_ns
7419 instead. If we fetch all queued events from stub, remote stub
7420 may exit and we have no chance to process them back in
7421 remote_wait_ns. */
7422 remote_state *rs = remote->get_remote_state ();
7424 return 0;
7426
7428{
7429 for (cached_reg_t &reg : regcache)
7430 xfree (reg.data);
7431}
7436 return notif_event_up (new struct stop_reply ());
7437}
7438
7439/* A client of notification Stop. */
7440
7442{
7443 "Stop",
7444 "vStopped",
7450};
7451
7452/* If CONTEXT contains any fork child threads that have not been
7453 reported yet, remove them from the CONTEXT list. If such a
7454 thread exists it is because we are stopped at a fork catchpoint
7455 and have not yet called follow_fork, which will set up the
7456 host-side data structures for the new process. */
7458void
7460{
7461 const notif_client *notif = &notif_client_stop;
7462
7463 /* For any threads stopped at a fork event, remove the corresponding
7464 fork child threads from the CONTEXT list. */
7465 for (thread_info *thread : all_non_exited_threads (this))
7466 {
7467 const target_waitstatus *ws = thread_pending_fork_status (thread);
7468
7469 if (ws == nullptr)
7470 continue;
7471
7472 context->remove_thread (ws->child_ptid ());
7473 }
7474
7475 /* Check for any pending fork events (not reported or processed yet)
7476 in process PID and remove those fork child threads from the
7477 CONTEXT list as well. */
7479 for (auto &event : get_remote_state ()->stop_reply_queue)
7480 if (event->ws.kind () == TARGET_WAITKIND_FORKED
7481 || event->ws.kind () == TARGET_WAITKIND_VFORKED)
7482 context->remove_thread (event->ws.child_ptid ());
7483 else if (event->ws.kind () == TARGET_WAITKIND_THREAD_EXITED)
7484 context->remove_thread (event->ptid);
7485}
7486
7487/* Check whether any event pending in the vStopped queue would prevent a
7488 global or process wildcard vCont action. Set *may_global_wildcard to
7489 false if we can't do a global wildcard (vCont;c), and clear the event
7490 inferior's may_wildcard_vcont flag if we can't do a process-wide
7491 wildcard resume (vCont;c:pPID.-1). */
7493void
7495 (bool *may_global_wildcard)
7496{
7497 const notif_client *notif = &notif_client_stop;
7498
7500 for (auto &event : get_remote_state ()->stop_reply_queue)
7501 {
7502 if (event->ws.kind () == TARGET_WAITKIND_NO_RESUMED
7503 || event->ws.kind () == TARGET_WAITKIND_NO_HISTORY)
7504 continue;
7505
7506 if (event->ws.kind () == TARGET_WAITKIND_FORKED
7507 || event->ws.kind () == TARGET_WAITKIND_VFORKED)
7508 *may_global_wildcard = false;
7509
7510 /* This may be the first time we heard about this process.
7511 Regardless, we must not do a global wildcard resume, otherwise
7512 we'd resume this process too. */
7513 *may_global_wildcard = false;
7514 if (event->ptid != null_ptid)
7515 {
7516 inferior *inf = find_inferior_ptid (this, event->ptid);
7517 if (inf != NULL)
7519 }
7520 }
7521}
7522
7523/* Discard all pending stop replies of inferior INF. */
7525void
7527{
7528 struct stop_reply *reply;
7529 struct remote_state *rs = get_remote_state ();
7530 struct remote_notif_state *rns = rs->notif_state;
7531
7532 /* This function can be notified when an inferior exists. When the
7533 target is not remote, the notification state is NULL. */
7534 if (rs->remote_desc == NULL)
7535 return;
7536
7537 reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
7538
7539 /* Discard the in-flight notification. */
7540 if (reply != NULL && reply->ptid.pid () == inf->pid)
7541 {
7542 /* Leave the notification pending, since the server expects that
7543 we acknowledge it with vStopped. But clear its contents, so
7544 that later on when we acknowledge it, we also discard it. */
7546 ("discarding in-flight notification: ptid: %s, ws: %s\n",
7547 reply->ptid.to_string().c_str(),
7548 reply->ws.to_string ().c_str ());
7549 reply->ws.set_ignore ();
7550 }
7551
7552 /* Discard the stop replies we have already pulled with
7553 vStopped. */
7554 auto iter = std::remove_if (rs->stop_reply_queue.begin (),
7555 rs->stop_reply_queue.end (),
7556 [=] (const stop_reply_up &event)
7557 {
7558 return event->ptid.pid () == inf->pid;
7559 });
7560 for (auto it = iter; it != rs->stop_reply_queue.end (); ++it)
7562 ("discarding queued stop reply: ptid: %s, ws: %s\n",
7563 (*it)->ptid.to_string().c_str(),
7564 (*it)->ws.to_string ().c_str ());
7565 rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
7566}
7567
7568/* Discard the stop replies for RS in stop_reply_queue. */
7570void
7572{
7574
7575 /* Discard the stop replies we have already pulled with
7576 vStopped. */
7577 auto iter = std::remove_if (rs->stop_reply_queue.begin (),
7578 rs->stop_reply_queue.end (),
7579 [=] (const stop_reply_up &event)
7580 {
7581 return event->rs == rs;
7582 });
7583 rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
7584}
7585
7586/* Remove the first reply in 'stop_reply_queue' which matches
7587 PTID. */
7589struct stop_reply *
7591{
7593
7594 auto iter = std::find_if (rs->stop_reply_queue.begin (),
7595 rs->stop_reply_queue.end (),
7596 [=] (const stop_reply_up &event)
7597 {
7598 return event->ptid.matches (ptid);
7599 });
7600 struct stop_reply *result;
7601 if (iter == rs->stop_reply_queue.end ())
7602 result = nullptr;
7603 else
7604 {
7605 result = iter->release ();
7606 rs->stop_reply_queue.erase (iter);
7607 }
7608
7609 if (notif_debug)
7611 "notif: discard queued event: 'Stop' in %s\n",
7612 ptid.to_string ().c_str ());
7613
7614 return result;
7615}
7616
7617/* Look for a queued stop reply belonging to PTID. If one is found,
7618 remove it from the queue, and return it. Returns NULL if none is
7619 found. If there are still queued events left to process, tell the
7620 event loop to get back to target_wait soon. */
7622struct stop_reply *
7624{
7627
7628 if (!rs->stop_reply_queue.empty () && target_can_async_p ())
7629 {
7630 /* There's still at least an event left. */
7632 }
7633
7634 return r;
7635}
7636
7637/* Push a fully parsed stop reply in the stop reply queue. Since we
7638 know that we now have at least one queued event left to pass to the
7639 core side, tell the event loop to get back to target_wait soon. */
7641void
7643{
7645 rs->stop_reply_queue.push_back (stop_reply_up (new_event));
7646
7647 if (notif_debug)
7649 "notif: push 'Stop' %s to queue %d\n",
7650 new_event->ptid.to_string ().c_str (),
7651 int (rs->stop_reply_queue.size ()));
7652
7653 /* Mark the pending event queue only if async mode is currently enabled.
7654 If async mode is not currently enabled, then, if it later becomes
7655 enabled, and there are events in this queue, we will mark the event
7656 token at that point, see remote_target::async. */
7657 if (target_is_async_p ())
7659}
7660
7661/* Returns true if we have a stop reply for PTID. */
7663int
7665{
7667 for (auto &event : rs->stop_reply_queue)
7668 if (ptid == event->ptid
7669 && event->ws.kind () == TARGET_WAITKIND_STOPPED)
7670 return 1;
7671 return 0;
7672}
7673
7674/* Helper for remote_parse_stop_reply. Return nonzero if the substring
7675 starting with P and ending with PEND matches PREFIX. */
7677static int
7678strprefix (const char *p, const char *pend, const char *prefix)
7679{
7680 for ( ; p < pend; p++, prefix++)
7681 if (*p != *prefix)
7682 return 0;
7683 return *prefix == '\0';
7684}
7685
7686/* Parse the stop reply in BUF. Either the function succeeds, and the
7687 result is stored in EVENT, or throws an error. */
7689void
7690remote_target::remote_parse_stop_reply (const char *buf, stop_reply *event)
7691{
7692 remote_arch_state *rsa = NULL;
7693 ULONGEST addr;
7694 const char *p;
7695 int skipregs = 0;
7696
7697 event->ptid = null_ptid;
7698 event->rs = get_remote_state ();
7699 event->ws.set_ignore ();
7700 event->stop_reason = TARGET_STOPPED_BY_NO_REASON;
7701 event->regcache.clear ();
7702 event->core = -1;
7703
7704 switch (buf[0])
7705 {
7706 case 'T': /* Status with PC, SP, FP, ... */
7707 /* Expedited reply, containing Signal, {regno, reg} repeat. */
7708 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
7709 ss = signal number
7710 n... = register number
7711 r... = register contents
7712 */
7713
7714 p = &buf[3]; /* after Txx */
7715 while (*p)
7716 {
7717 const char *p1;
7718 int fieldsize;
7719
7720 p1 = strchr (p, ':');
7721 if (p1 == NULL)
7722 error (_("Malformed packet(a) (missing colon): %s\n\
7723Packet: '%s'\n"),
7724 p, buf);
7725 if (p == p1)
7726 error (_("Malformed packet(a) (missing register number): %s\n\
7727Packet: '%s'\n"),
7728 p, buf);
7729
7730 /* Some "registers" are actually extended stop information.
7731 Note if you're adding a new entry here: GDB 7.9 and
7732 earlier assume that all register "numbers" that start
7733 with an hex digit are real register numbers. Make sure
7734 the server only sends such a packet if it knows the
7735 client understands it. */
7736
7737 if (strprefix (p, p1, "thread"))
7738 event->ptid = read_ptid (++p1, &p);
7739 else if (strprefix (p, p1, "syscall_entry"))
7740 {
7741 ULONGEST sysno;
7742
7743 p = unpack_varlen_hex (++p1, &sysno);
7744 event->ws.set_syscall_entry ((int) sysno);
7745 }
7746 else if (strprefix (p, p1, "syscall_return"))
7747 {
7748 ULONGEST sysno;
7749
7750 p = unpack_varlen_hex (++p1, &sysno);
7751 event->ws.set_syscall_return ((int) sysno);
7752 }
7753 else if (strprefix (p, p1, "watch")
7754 || strprefix (p, p1, "rwatch")
7755 || strprefix (p, p1, "awatch"))
7756 {
7757 event->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
7758 p = unpack_varlen_hex (++p1, &addr);
7759 event->watch_data_address = (CORE_ADDR) addr;
7760 }
7761 else if (strprefix (p, p1, "swbreak"))
7762 {
7763 event->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
7764
7765 /* Make sure the stub doesn't forget to indicate support
7766 with qSupported. */
7768 != PACKET_ENABLE)
7769 error (_("Unexpected swbreak stop reason"));
7770
7771 /* The value part is documented as "must be empty",
7772 though we ignore it, in case we ever decide to make
7773 use of it in a backward compatible way. */
7774 p = strchrnul (p1 + 1, ';');
7775 }
7776 else if (strprefix (p, p1, "hwbreak"))
7777 {
7778 event->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
7779
7780 /* Make sure the stub doesn't forget to indicate support
7781 with qSupported. */
7783 != PACKET_ENABLE)
7784 error (_("Unexpected hwbreak stop reason"));
7785
7786 /* See above. */
7787 p = strchrnul (p1 + 1, ';');
7788 }
7789 else if (strprefix (p, p1, "library"))
7790 {
7791 event->ws.set_loaded ();
7792 p = strchrnul (p1 + 1, ';');
7793 }
7794 else if (strprefix (p, p1, "replaylog"))
7795 {
7796 event->ws.set_no_history ();
7797 /* p1 will indicate "begin" or "end", but it makes
7798 no difference for now, so ignore it. */
7799 p = strchrnul (p1 + 1, ';');
7800 }
7801 else if (strprefix (p, p1, "core"))
7802 {
7803 ULONGEST c;
7804
7805 p = unpack_varlen_hex (++p1, &c);
7806 event->core = c;
7807 }
7808 else if (strprefix (p, p1, "fork"))
7809 event->ws.set_forked (read_ptid (++p1, &p));
7810 else if (strprefix (p, p1, "vfork"))
7811 event->ws.set_vforked (read_ptid (++p1, &p));
7812 else if (strprefix (p, p1, "vforkdone"))
7813 {
7814 event->ws.set_vfork_done ();
7815 p = strchrnul (p1 + 1, ';');
7816 }
7817 else if (strprefix (p, p1, "exec"))
7818 {
7819 ULONGEST ignored;
7820 int pathlen;
7821
7822 /* Determine the length of the execd pathname. */
7823 p = unpack_varlen_hex (++p1, &ignored);
7824 pathlen = (p - p1) / 2;
7825
7826 /* Save the pathname for event reporting and for
7827 the next run command. */
7828 gdb::unique_xmalloc_ptr<char> pathname
7829 ((char *) xmalloc (pathlen + 1));
7830 hex2bin (p1, (gdb_byte *) pathname.get (), pathlen);
7831 pathname.get ()[pathlen] = '\0';
7832
7833 /* This is freed during event handling. */
7834 event->ws.set_execd (std::move (pathname));
7835
7836 /* Skip the registers included in this packet, since
7837 they may be for an architecture different from the
7838 one used by the original program. */
7839 skipregs = 1;
7840 }
7841 else if (strprefix (p, p1, "create"))
7842 {
7843 event->ws.set_thread_created ();
7844 p = strchrnul (p1 + 1, ';');
7845 }
7846 else
7847 {
7848 ULONGEST pnum;
7849 const char *p_temp;
7850
7851 if (skipregs)
7852 {
7853 p = strchrnul (p1 + 1, ';');
7854 p++;
7855 continue;
7856 }
7857
7858 /* Maybe a real ``P'' register number. */
7859 p_temp = unpack_varlen_hex (p, &pnum);
7860 /* If the first invalid character is the colon, we got a
7861 register number. Otherwise, it's an unknown stop
7862 reason. */
7863 if (p_temp == p1)
7864 {
7865 /* If we haven't parsed the event's thread yet, find
7866 it now, in order to find the architecture of the
7867 reported expedited registers. */
7868 if (event->ptid == null_ptid)
7869 {
7870 /* If there is no thread-id information then leave
7871 the event->ptid as null_ptid. Later in
7872 process_stop_reply we will pick a suitable
7873 thread. */
7874 const char *thr = strstr (p1 + 1, ";thread:");
7875 if (thr != NULL)
7876 event->ptid = read_ptid (thr + strlen (";thread:"),
7877 NULL);
7878 }
7879
7880 if (rsa == NULL)
7881 {
7882 inferior *inf
7883 = (event->ptid == null_ptid
7884 ? NULL
7885 : find_inferior_ptid (this, event->ptid));
7886 /* If this is the first time we learn anything
7887 about this process, skip the registers
7888 included in this packet, since we don't yet
7889 know which architecture to use to parse them.
7890 We'll determine the architecture later when
7891 we process the stop reply and retrieve the
7892 target description, via
7893 remote_notice_new_inferior ->
7894 post_create_inferior. */
7895 if (inf == NULL)
7896 {
7897 p = strchrnul (p1 + 1, ';');
7898 p++;
7899 continue;
7900 }
7901
7902 event->arch = inf->gdbarch;
7903 rsa = event->rs->get_remote_arch_state (event->arch);
7904 }
7905
7906 packet_reg *reg
7907 = packet_reg_from_pnum (event->arch, rsa, pnum);
7908 cached_reg_t cached_reg;
7909
7910 if (reg == NULL)
7911 error (_("Remote sent bad register number %s: %s\n\
7912Packet: '%s'\n"),
7913 hex_string (pnum), p, buf);
7914
7915 cached_reg.num = reg->regnum;
7916 cached_reg.data = (gdb_byte *)
7917 xmalloc (register_size (event->arch, reg->regnum));
7918
7919 p = p1 + 1;
7920 fieldsize = hex2bin (p, cached_reg.data,
7921 register_size (event->arch, reg->regnum));
7922 p += 2 * fieldsize;
7923 if (fieldsize < register_size (event->arch, reg->regnum))
7924 warning (_("Remote reply is too short: %s"), buf);
7925
7926 event->regcache.push_back (cached_reg);
7927 }
7928 else
7929 {
7930 /* Not a number. Silently skip unknown optional
7931 info. */
7932 p = strchrnul (p1 + 1, ';');
7933 }
7934 }
7935
7936 if (*p != ';')
7937 error (_("Remote register badly formatted: %s\nhere: %s"),
7938 buf, p);
7939 ++p;
7940 }
7941
7942 if (event->ws.kind () != TARGET_WAITKIND_IGNORE)
7943 break;
7944
7945 /* fall through */
7946 case 'S': /* Old style status, just signal only. */
7947 {
7948 int sig;
7949
7950 sig = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
7951 if (GDB_SIGNAL_FIRST <= sig && sig < GDB_SIGNAL_LAST)
7952 event->ws.set_stopped ((enum gdb_signal) sig);
7953 else
7954 event->ws.set_stopped (GDB_SIGNAL_UNKNOWN);
7955 }
7956 break;
7957 case 'w': /* Thread exited. */
7958 {
7959 ULONGEST value;
7960
7961 p = unpack_varlen_hex (&buf[1], &value);
7962 event->ws.set_thread_exited (value);
7963 if (*p != ';')
7964 error (_("stop reply packet badly formatted: %s"), buf);
7965 event->ptid = read_ptid (++p, NULL);
7966 break;
7967 }
7968 case 'W': /* Target exited. */
7969 case 'X':
7970 {
7971 ULONGEST value;
7972
7973 /* GDB used to accept only 2 hex chars here. Stubs should
7974 only send more if they detect GDB supports multi-process
7975 support. */
7976 p = unpack_varlen_hex (&buf[1], &value);
7977
7978 if (buf[0] == 'W')
7979 {
7980 /* The remote process exited. */
7981 event->ws.set_exited (value);
7982 }
7983 else
7984 {
7985 /* The remote process exited with a signal. */
7986 if (GDB_SIGNAL_FIRST <= value && value < GDB_SIGNAL_LAST)
7987 event->ws.set_signalled ((enum gdb_signal) value);
7988 else
7989 event->ws.set_signalled (GDB_SIGNAL_UNKNOWN);
7990 }
7991
7992 /* If no process is specified, return null_ptid, and let the
7993 caller figure out the right process to use. */
7994 int pid = 0;
7995 if (*p == '\0')
7996 ;
7997 else if (*p == ';')
7998 {
7999 p++;
8000
8001 if (*p == '\0')
8002 ;
8003 else if (startswith (p, "process:"))
8004 {
8005 ULONGEST upid;
8006
8007 p += sizeof ("process:") - 1;
8008 unpack_varlen_hex (p, &upid);
8009 pid = upid;
8010 }
8011 else
8012 error (_("unknown stop reply packet: %s"), buf);
8013 }
8014 else
8015 error (_("unknown stop reply packet: %s"), buf);
8016 event->ptid = ptid_t (pid);
8017 }
8018 break;
8019 case 'N':
8020 event->ws.set_no_resumed ();
8021 event->ptid = minus_one_ptid;
8022 break;
8023 }
8024}
8025
8026/* When the stub wants to tell GDB about a new notification reply, it
8027 sends a notification (%Stop, for example). Those can come it at
8028 any time, hence, we have to make sure that any pending
8029 putpkt/getpkt sequence we're making is finished, before querying
8030 the stub for more events with the corresponding ack command
8031 (vStopped, for example). E.g., if we started a vStopped sequence
8032 immediately upon receiving the notification, something like this
8033 could happen:
8034
8035 1.1) --> Hg 1
8036 1.2) <-- OK
8037 1.3) --> g
8038 1.4) <-- %Stop
8039 1.5) --> vStopped
8040 1.6) <-- (registers reply to step #1.3)
8041
8042 Obviously, the reply in step #1.6 would be unexpected to a vStopped
8043 query.
8044
8045 To solve this, whenever we parse a %Stop notification successfully,
8046 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
8047 doing whatever we were doing:
8048
8049 2.1) --> Hg 1
8050 2.2) <-- OK
8051 2.3) --> g
8052 2.4) <-- %Stop
8053 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
8054 2.5) <-- (registers reply to step #2.3)
8055
8056 Eventually after step #2.5, we return to the event loop, which
8057 notices there's an event on the
8058 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
8059 associated callback --- the function below. At this point, we're
8060 always safe to start a vStopped sequence. :
8061
8062 2.6) --> vStopped
8063 2.7) <-- T05 thread:2
8064 2.8) --> vStopped
8065 2.9) --> OK
8066*/
8068void
8070{
8071 struct remote_state *rs = get_remote_state ();
8072
8073 if (rs->notif_state->pending_event[nc->id] != NULL)
8074 {
8075 if (notif_debug)
8077 "notif: process: '%s' ack pending event\n",
8078 nc->name);
8079
8080 /* acknowledge */
8081 nc->ack (this, nc, rs->buf.data (),
8082 rs->notif_state->pending_event[nc->id]);
8083 rs->notif_state->pending_event[nc->id] = NULL;
8084
8085 while (1)
8086 {
8087 getpkt (&rs->buf);
8088 if (strcmp (rs->buf.data (), "OK") == 0)
8089 break;
8090 else
8091 remote_notif_ack (this, nc, rs->buf.data ());
8092 }
8093 }
8094 else
8095 {
8096 if (notif_debug)
8098 "notif: process: '%s' no pending reply\n",
8099 nc->name);
8100 }
8101}
8102
8103/* Wrapper around remote_target::remote_notif_get_pending_events to
8104 avoid having to export the whole remote_target class. */
8106void
8108{
8110}
8111
8112/* Called from process_stop_reply when the stop packet we are responding
8113 to didn't include a process-id or thread-id. STATUS is the stop event
8114 we are responding to.
8115
8116 It is the task of this function to select a suitable thread (or process)
8117 and return its ptid, this is the thread (or process) we will assume the
8118 stop event came from.
8119
8120 In some cases there isn't really any choice about which thread (or
8121 process) is selected, a basic remote with a single process containing a
8122 single thread might choose not to send any process-id or thread-id in
8123 its stop packets, this function will select and return the one and only
8124 thread.
8125
8126 However, if a target supports multiple threads (or processes) and still
8127 doesn't include a thread-id (or process-id) in its stop packet then
8128 first, this is a badly behaving target, and second, we're going to have
8129 to select a thread (or process) at random and use that. This function
8130 will print a warning to the user if it detects that there is the
8131 possibility that GDB is guessing which thread (or process) to
8132 report.
8133
8134 Note that this is called before GDB fetches the updated thread list from the
8135 target. So it's possible for the stop reply to be ambiguous and for GDB to
8136 not realize it. For example, if there's initially one thread, the target
8137 spawns a second thread, and then sends a stop reply without an id that
8138 concerns the first thread. GDB will assume the stop reply is about the
8139 first thread - the only thread it knows about - without printing a warning.
8140 Anyway, if the remote meant for the stop reply to be about the second thread,
8141 then it would be really broken, because GDB doesn't know about that thread
8142 yet. */
8144ptid_t
8146 (const target_waitstatus &status)
8147{
8149
8150 /* Some stop events apply to all threads in an inferior, while others
8151 only apply to a single thread. */
8152 bool process_wide_stop
8153 = (status.kind () == TARGET_WAITKIND_EXITED
8154 || status.kind () == TARGET_WAITKIND_SIGNALLED);
8155
8156 remote_debug_printf ("process_wide_stop = %d", process_wide_stop);
8157
8158 thread_info *first_resumed_thread = nullptr;
8159 bool ambiguous = false;
8160
8161 /* Consider all non-exited threads of the target, find the first resumed
8162 one. */
8163 for (thread_info *thr : all_non_exited_threads (this))
8164 {
8165 remote_thread_info *remote_thr = get_remote_thread_info (thr);
8166
8167 if (remote_thr->get_resume_state () != resume_state::RESUMED)
8168 continue;
8169
8170 if (first_resumed_thread == nullptr)
8171 first_resumed_thread = thr;
8172 else if (!process_wide_stop
8173 || first_resumed_thread->ptid.pid () != thr->ptid.pid ())
8174 ambiguous = true;
8175 }
8176
8177 gdb_assert (first_resumed_thread != nullptr);
8178
8179 remote_debug_printf ("first resumed thread is %s",
8180 pid_to_str (first_resumed_thread->ptid).c_str ());
8181 remote_debug_printf ("is this guess ambiguous? = %d", ambiguous);
8182
8183 /* Warn if the remote target is sending ambiguous stop replies. */
8184 if (ambiguous)
8185 {
8186 static bool warned = false;
8187
8188 if (!warned)
8189 {
8190 /* If you are seeing this warning then the remote target has
8191 stopped without specifying a thread-id, but the target
8192 does have multiple threads (or inferiors), and so GDB is
8193 having to guess which thread stopped.
8194
8195 Examples of what might cause this are the target sending
8196 and 'S' stop packet, or a 'T' stop packet and not
8197 including a thread-id.
8198
8199 Additionally, the target might send a 'W' or 'X packet
8200 without including a process-id, when the target has
8201 multiple running inferiors. */
8202 if (process_wide_stop)
8203 warning (_("multi-inferior target stopped without "
8204 "sending a process-id, using first "
8205 "non-exited inferior"));
8206 else
8207 warning (_("multi-threaded target stopped without "
8208 "sending a thread-id, using first "
8209 "non-exited thread"));
8210 warned = true;
8211 }
8212 }
8213
8214 /* If this is a stop for all threads then don't use a particular threads
8215 ptid, instead create a new ptid where only the pid field is set. */
8216 if (process_wide_stop)
8217 return ptid_t (first_resumed_thread->ptid.pid ());
8218 else
8219 return first_resumed_thread->ptid;
8220}
8221
8222/* Called when it is decided that STOP_REPLY holds the info of the
8223 event that is to be returned to the core. This function always
8224 destroys STOP_REPLY. */
8226ptid_t
8228 struct target_waitstatus *status)
8229{
8230 *status = stop_reply->ws;
8231 ptid_t ptid = stop_reply->ptid;
8232
8233 /* If no thread/process was reported by the stub then select a suitable
8234 thread/process. */
8235 if (ptid == null_ptid)
8237 gdb_assert (ptid != null_ptid);
8238
8239 if (status->kind () != TARGET_WAITKIND_EXITED
8240 && status->kind () != TARGET_WAITKIND_SIGNALLED
8241 && status->kind () != TARGET_WAITKIND_NO_RESUMED)
8242 {
8243 /* Expedited registers. */
8244 if (!stop_reply->regcache.empty ())
8245 {
8246 struct regcache *regcache
8247 = get_thread_arch_regcache (this, ptid, stop_reply->arch);
8248
8249 for (cached_reg_t &reg : stop_reply->regcache)
8250 {
8251 regcache->raw_supply (reg.num, reg.data);
8252 xfree (reg.data);
8253 }
8254
8255 stop_reply->regcache.clear ();
8256 }
8257
8258 remote_notice_new_inferior (ptid, false);
8259 remote_thread_info *remote_thr = get_remote_thread_info (this, ptid);
8260 remote_thr->core = stop_reply->core;
8261 remote_thr->stop_reason = stop_reply->stop_reason;
8263
8264 if (target_is_non_stop_p ())
8265 {
8266 /* If the target works in non-stop mode, a stop-reply indicates that
8267 only this thread stopped. */
8268 remote_thr->set_not_resumed ();
8269 }
8270 else
8271 {
8272 /* If the target works in all-stop mode, a stop-reply indicates that
8273 all the target's threads stopped. */
8274 for (thread_info *tp : all_non_exited_threads (this))
8276 }
8277 }
8278
8279 delete stop_reply;
8280 return ptid;
8281}
8282
8283/* The non-stop mode version of target_wait. */
8285ptid_t
8287 target_wait_flags options)
8288{
8289 struct remote_state *rs = get_remote_state ();
8290 struct stop_reply *stop_reply;
8291 int ret;
8292 bool is_notif = false;
8293
8294 /* If in non-stop mode, get out of getpkt even if a
8295 notification is received. */
8296
8297 ret = getpkt (&rs->buf, false /* forever */, &is_notif);
8298 while (1)
8299 {
8300 if (ret != -1 && !is_notif)
8301 switch (rs->buf[0])
8302 {
8303 case 'E': /* Error of some sort. */
8304 /* We're out of sync with the target now. Did it continue
8305 or not? We can't tell which thread it was in non-stop,
8306 so just ignore this. */
8307 warning (_("Remote failure reply: %s"), rs->buf.data ());
8308 break;
8309 case 'O': /* Console output. */
8310 remote_console_output (&rs->buf[1]);
8311 break;
8312 default:
8313 warning (_("Invalid remote reply: %s"), rs->buf.data ());
8314 break;
8315 }
8316
8317 /* Acknowledge a pending stop reply that may have arrived in the
8318 mean time. */
8321
8322 /* If indeed we noticed a stop reply, we're done. */
8324 if (stop_reply != NULL)
8326
8327 /* Still no event. If we're just polling for an event, then
8328 return to the event loop. */
8329 if (options & TARGET_WNOHANG)
8330 {
8331 status->set_ignore ();
8332 return minus_one_ptid;
8333 }
8334
8335 /* Otherwise do a blocking wait. */
8336 ret = getpkt (&rs->buf, true /* forever */, &is_notif);
8337 }
8338}
8339
8340/* Return the first resumed thread. */
8342static ptid_t
8344{
8345 for (thread_info *tp : all_non_exited_threads (target, minus_one_ptid))
8346 if (tp->resumed ())
8347 return tp->ptid;
8348 return null_ptid;
8349}
8350
8351/* Wait until the remote machine stops, then return, storing status in
8352 STATUS just as `wait' would. */
8354ptid_t
8356 target_wait_flags options)
8357{
8358 struct remote_state *rs = get_remote_state ();
8359 ptid_t event_ptid = null_ptid;
8360 char *buf;
8361 struct stop_reply *stop_reply;
8362
8363 again:
8364
8365 status->set_ignore ();
8366
8368 if (stop_reply != NULL)
8369 {
8370 /* None of the paths that push a stop reply onto the queue should
8371 have set the waiting_for_stop_reply flag. */
8372 gdb_assert (!rs->waiting_for_stop_reply);
8373 event_ptid = process_stop_reply (stop_reply, status);
8374 }
8375 else
8376 {
8377 bool forever = ((options & TARGET_WNOHANG) == 0
8378 && rs->wait_forever_enabled_p);
8379
8380 if (!rs->waiting_for_stop_reply)
8381 {
8382 status->set_no_resumed ();
8383 return minus_one_ptid;
8384 }
8385
8386 /* FIXME: cagney/1999-09-27: If we're in async mode we should
8387 _never_ wait for ever -> test on target_is_async_p().
8388 However, before we do that we need to ensure that the caller
8389 knows how to take the target into/out of async mode. */
8390 bool is_notif;
8391 int ret = getpkt (&rs->buf, forever, &is_notif);
8392
8393 /* GDB gets a notification. Return to core as this event is
8394 not interesting. */
8395 if (ret != -1 && is_notif)
8396 return minus_one_ptid;
8397
8398 if (ret == -1 && (options & TARGET_WNOHANG) != 0)
8399 return minus_one_ptid;
8400
8401 buf = rs->buf.data ();
8402
8403 /* Assume that the target has acknowledged Ctrl-C unless we receive
8404 an 'F' or 'O' packet. */
8405 if (buf[0] != 'F' && buf[0] != 'O')
8406 rs->ctrlc_pending_p = 0;
8407
8408 switch (buf[0])
8409 {
8410 case 'E': /* Error of some sort. */
8411 /* We're out of sync with the target now. Did it continue or
8412 not? Not is more likely, so report a stop. */
8413 rs->waiting_for_stop_reply = 0;
8414
8415 warning (_("Remote failure reply: %s"), buf);
8416 status->set_stopped (GDB_SIGNAL_0);
8417 break;
8418 case 'F': /* File-I/O request. */
8419 /* GDB may access the inferior memory while handling the File-I/O
8420 request, but we don't want GDB accessing memory while waiting
8421 for a stop reply. See the comments in putpkt_binary. Set
8422 waiting_for_stop_reply to 0 temporarily. */
8423 rs->waiting_for_stop_reply = 0;
8424 remote_fileio_request (this, buf, rs->ctrlc_pending_p);
8425 rs->ctrlc_pending_p = 0;
8426 /* GDB handled the File-I/O request, and the target is running
8427 again. Keep waiting for events. */
8428 rs->waiting_for_stop_reply = 1;
8429 break;
8430 case 'N': case 'T': case 'S': case 'X': case 'W':
8431 {
8432 /* There is a stop reply to handle. */
8433 rs->waiting_for_stop_reply = 0;
8434
8436 = (struct stop_reply *) remote_notif_parse (this,
8438 rs->buf.data ());
8439
8440 event_ptid = process_stop_reply (stop_reply, status);
8441 break;
8442 }
8443 case 'O': /* Console output. */
8444 remote_console_output (buf + 1);
8445 break;
8446 case '\0':
8447 if (rs->last_sent_signal != GDB_SIGNAL_0)
8448 {
8449 /* Zero length reply means that we tried 'S' or 'C' and the
8450 remote system doesn't support it. */
8453 ("Can't send signals to this remote system. %s not sent.\n",
8454 gdb_signal_to_name (rs->last_sent_signal));
8455 rs->last_sent_signal = GDB_SIGNAL_0;
8457
8458 strcpy (buf, rs->last_sent_step ? "s" : "c");
8459 putpkt (buf);
8460 break;
8461 }
8462 /* fallthrough */
8463 default:
8464 warning (_("Invalid remote reply: %s"), buf);
8465 break;
8466 }
8467 }
8468
8469 if (status->kind () == TARGET_WAITKIND_NO_RESUMED)
8470 return minus_one_ptid;
8471 else if (status->kind () == TARGET_WAITKIND_IGNORE)
8472 {
8473 /* Nothing interesting happened. If we're doing a non-blocking
8474 poll, we're done. Otherwise, go back to waiting. */
8475 if (options & TARGET_WNOHANG)
8476 return minus_one_ptid;
8477 else
8478 goto again;
8479 }
8480 else if (status->kind () != TARGET_WAITKIND_EXITED
8481 && status->kind () != TARGET_WAITKIND_SIGNALLED)
8482 {
8483 if (event_ptid != null_ptid)
8484 record_currthread (rs, event_ptid);
8485 else
8486 event_ptid = first_remote_resumed_thread (this);
8487 }
8488 else
8489 {
8490 /* A process exit. Invalidate our notion of current thread. */
8491 record_currthread (rs, minus_one_ptid);
8492 /* It's possible that the packet did not include a pid. */
8493 if (event_ptid == null_ptid)
8494 event_ptid = first_remote_resumed_thread (this);
8495 /* EVENT_PTID could still be NULL_PTID. Double-check. */
8496 if (event_ptid == null_ptid)
8497 event_ptid = magic_null_ptid;
8498 }
8499
8500 return event_ptid;
8501}
8502
8503/* Wait until the remote machine stops, then return, storing status in
8504 STATUS just as `wait' would. */
8506ptid_t
8508 target_wait_flags options)
8509{
8511
8513
8514 /* Start by clearing the flag that asks for our wait method to be called,
8515 we'll mark it again at the end if needed. If the target is not in
8516 async mode then the async token should not be marked. */
8517 if (target_is_async_p ())
8519 else
8520 gdb_assert (!async_event_handler_marked
8522
8523 ptid_t event_ptid;
8524
8525 if (target_is_non_stop_p ())
8526 event_ptid = wait_ns (ptid, status, options);
8527 else
8528 event_ptid = wait_as (ptid, status, options);
8529
8530 if (target_is_async_p ())
8531 {
8532 /* If there are events left in the queue, or unacknowledged
8533 notifications, then tell the event loop to call us again. */
8534 if (!rs->stop_reply_queue.empty ()
8535 || rs->notif_state->pending_event[notif_client_stop.id] != nullptr)
8537 }
8538
8539 return event_ptid;
8540}
8541
8542/* Fetch a single register using a 'p' packet. */
8544int
8546 packet_reg *reg)
8547{
8548 struct gdbarch *gdbarch = regcache->arch ();
8549 struct remote_state *rs = get_remote_state ();
8550 char *buf, *p;
8551 gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
8552 int i;
8553
8555 return 0;
8556
8557 if (reg->pnum == -1)
8558 return 0;
8559
8560 p = rs->buf.data ();
8561 *p++ = 'p';
8562 p += hexnumstr (p, reg->pnum);
8563 *p++ = '\0';
8564 putpkt (rs->buf);
8565 getpkt (&rs->buf);
8566
8567 buf = rs->buf.data ();
8568
8569 switch (m_features.packet_ok (rs->buf, PACKET_p))
8570 {
8571 case PACKET_OK:
8572 break;
8573 case PACKET_UNKNOWN:
8574 return 0;
8575 case PACKET_ERROR:
8576 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
8578 reg->regnum),
8579 buf);
8580 }
8581
8582 /* If this register is unfetchable, tell the regcache. */
8583 if (buf[0] == 'x')
8584 {
8585 regcache->raw_supply (reg->regnum, NULL);
8586 return 1;
8587 }
8588
8589 /* Otherwise, parse and supply the value. */
8590 p = buf;
8591 i = 0;
8592 while (p[0] != 0)
8593 {
8594 if (p[1] == 0)
8595 error (_("fetch_register_using_p: early buf termination"));
8596
8597 regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
8598 p += 2;
8599 }
8600 regcache->raw_supply (reg->regnum, regp);
8601 return 1;
8602}
8603
8604/* Fetch the registers included in the target's 'g' packet. */
8606int
8608{
8609 struct remote_state *rs = get_remote_state ();
8610 int buf_len;
8611
8612 xsnprintf (rs->buf.data (), get_remote_packet_size (), "g");
8613 putpkt (rs->buf);
8614 getpkt (&rs->buf);
8616 error (_("Could not read registers; remote failure reply '%s'"),
8617 rs->buf.data ());
8618
8619 /* We can get out of synch in various cases. If the first character
8620 in the buffer is not a hex character, assume that has happened
8621 and try to fetch another packet to read. */
8622 while ((rs->buf[0] < '0' || rs->buf[0] > '9')
8623 && (rs->buf[0] < 'A' || rs->buf[0] > 'F')
8624 && (rs->buf[0] < 'a' || rs->buf[0] > 'f')
8625 && rs->buf[0] != 'x') /* New: unavailable register value. */
8626 {
8627 remote_debug_printf ("Bad register packet; fetching a new packet");
8628 getpkt (&rs->buf);
8629 }
8630
8631 buf_len = strlen (rs->buf.data ());
8632
8633 /* Sanity check the received packet. */
8634 if (buf_len % 2 != 0)
8635 error (_("Remote 'g' packet reply is of odd length: %s"), rs->buf.data ());
8636
8637 return buf_len / 2;
8638}
8640void
8642{
8643 struct gdbarch *gdbarch = regcache->arch ();
8644 struct remote_state *rs = get_remote_state ();
8646 int i, buf_len;
8647 char *p;
8648 char *regs;
8649
8650 buf_len = strlen (rs->buf.data ());
8651
8652 /* Further sanity checks, with knowledge of the architecture. */
8653 if (buf_len > 2 * rsa->sizeof_g_packet)
8654 error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
8655 "bytes): %s"),
8656 rsa->sizeof_g_packet, buf_len / 2,
8657 rs->buf.data ());
8658
8659 /* Save the size of the packet sent to us by the target. It is used
8660 as a heuristic when determining the max size of packets that the
8661 target can safely receive. */
8662 if (rsa->actual_register_packet_size == 0)
8663 rsa->actual_register_packet_size = buf_len;
8664
8665 /* If this is smaller than we guessed the 'g' packet would be,
8666 update our records. A 'g' reply that doesn't include a register's
8667 value implies either that the register is not available, or that
8668 the 'p' packet must be used. */
8669 if (buf_len < 2 * rsa->sizeof_g_packet)
8670 {
8671 long sizeof_g_packet = buf_len / 2;
8672
8673 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
8674 {
8675 long offset = rsa->regs[i].offset;
8676 long reg_size = register_size (gdbarch, i);
8677
8678 if (rsa->regs[i].pnum == -1)
8679 continue;
8680
8681 if (offset >= sizeof_g_packet)
8682 rsa->regs[i].in_g_packet = 0;
8683 else if (offset + reg_size > sizeof_g_packet)
8684 error (_("Truncated register %d in remote 'g' packet"), i);
8685 else
8686 rsa->regs[i].in_g_packet = 1;
8687 }
8688
8689 /* Looks valid enough, we can assume this is the correct length
8690 for a 'g' packet. It's important not to adjust
8691 rsa->sizeof_g_packet if we have truncated registers otherwise
8692 this "if" won't be run the next time the method is called
8693 with a packet of the same size and one of the internal errors
8694 below will trigger instead. */
8695 rsa->sizeof_g_packet = sizeof_g_packet;
8696 }
8697
8698 regs = (char *) alloca (rsa->sizeof_g_packet);
8699
8700 /* Unimplemented registers read as all bits zero. */
8701 memset (regs, 0, rsa->sizeof_g_packet);
8702
8703 /* Reply describes registers byte by byte, each byte encoded as two
8704 hex characters. Suck them all up, then supply them to the
8705 register cacheing/storage mechanism. */
8706
8707 p = rs->buf.data ();
8708 for (i = 0; i < rsa->sizeof_g_packet; i++)
8709 {
8710 if (p[0] == 0 || p[1] == 0)
8711 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
8712 internal_error (_("unexpected end of 'g' packet reply"));
8713
8714 if (p[0] == 'x' && p[1] == 'x')
8715 regs[i] = 0; /* 'x' */
8716 else
8717 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
8718 p += 2;
8719 }
8720
8721 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
8722 {
8723 struct packet_reg *r = &rsa->regs[i];
8724 long reg_size = register_size (gdbarch, i);
8725
8726 if (r->in_g_packet)
8727 {
8728 if ((r->offset + reg_size) * 2 > strlen (rs->buf.data ()))
8729 /* This shouldn't happen - we adjusted in_g_packet above. */
8730 internal_error (_("unexpected end of 'g' packet reply"));
8731 else if (rs->buf[r->offset * 2] == 'x')
8732 {
8733 gdb_assert (r->offset * 2 < strlen (rs->buf.data ()));
8734 /* The register isn't available, mark it as such (at
8735 the same time setting the value to zero). */
8736 regcache->raw_supply (r->regnum, NULL);
8737 }
8738 else
8739 regcache->raw_supply (r->regnum, regs + r->offset);
8740 }
8741 }
8742}
8749}
8750
8751/* Make the remote selected traceframe match GDB's selected
8752 traceframe. */
8754void
8756{
8757 int newnum;
8758 struct remote_state *rs = get_remote_state ();
8759
8761 return;
8762
8763 /* Avoid recursion, remote_trace_find calls us again. */
8765
8767 get_traceframe_number (), 0, 0, NULL);
8768
8769 /* Should not happen. If it does, all bets are off. */
8770 if (newnum != get_traceframe_number ())
8771 warning (_("could not set remote traceframe"));
8772}
8774void
8776{
8777 struct gdbarch *gdbarch = regcache->arch ();
8778 struct remote_state *rs = get_remote_state ();
8780 int i;
8781
8784
8785 if (regnum >= 0)
8786 {
8788
8789 gdb_assert (reg != NULL);
8790
8791 /* If this register might be in the 'g' packet, try that first -
8792 we are likely to read more than one register. If this is the
8793 first 'g' packet, we might be overly optimistic about its
8794 contents, so fall back to 'p'. */
8795 if (reg->in_g_packet)
8796 {
8798 if (reg->in_g_packet)
8799 return;
8800 }
8801
8803 return;
8804
8805 /* This register is not available. */
8806 regcache->raw_supply (reg->regnum, NULL);
8807
8808 return;
8809 }
8810
8812
8813 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
8814 if (!rsa->regs[i].in_g_packet)
8815 if (!fetch_register_using_p (regcache, &rsa->regs[i]))
8816 {
8817 /* This register is not available. */
8818 regcache->raw_supply (i, NULL);
8819 }
8820}
8821
8822/* Prepare to store registers. Since we may send them all (using a
8823 'G' request), we have to read out the ones we don't want to change
8824 first. */
8826void
8828{
8829 struct remote_state *rs = get_remote_state ();
8831 int i;
8832
8833 /* Make sure the entire registers array is valid. */
8835 {
8836 case PACKET_DISABLE:
8838 /* Make sure all the necessary registers are cached. */
8839 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
8840 if (rsa->regs[i].in_g_packet)
8841 regcache->raw_update (rsa->regs[i].regnum);
8842 break;
8843 case PACKET_ENABLE:
8844 break;
8845 }
8846}
8847
8848/* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
8849 packet was not recognized. */
8851int
8853 packet_reg *reg)
8854{
8855 struct gdbarch *gdbarch = regcache->arch ();
8856 struct remote_state *rs = get_remote_state ();
8857 /* Try storing a single register. */
8858 char *buf = rs->buf.data ();
8859 gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
8860 char *p;
8861
8863 return 0;
8864
8865 if (reg->pnum == -1)
8866 return 0;
8867
8868 xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0));
8869 p = buf + strlen (buf);
8870 regcache->raw_collect (reg->regnum, regp);
8871 bin2hex (regp, p, register_size (gdbarch, reg->regnum));
8872 putpkt (rs->buf);
8873 getpkt (&rs->buf);
8874
8875 switch (m_features.packet_ok (rs->buf, PACKET_P))
8876 {
8877 case PACKET_OK:
8878 return 1;
8879 case PACKET_ERROR:
8880 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
8881 gdbarch_register_name (gdbarch, reg->regnum), rs->buf.data ());
8882 case PACKET_UNKNOWN:
8883 return 0;
8884 default:
8885 internal_error (_("Bad result from packet_ok"));
8886 }
8887}
8888
8889/* Store register REGNUM, or all registers if REGNUM == -1, from the
8890 contents of the register cache buffer. FIXME: ignores errors. */
8892void
8894{
8895 struct remote_state *rs = get_remote_state ();
8897 gdb_byte *regs;
8898 char *p;
8899
8900 /* Extract all the registers in the regcache copying them into a
8901 local buffer. */
8902 {
8903 int i;
8904
8905 regs = (gdb_byte *) alloca (rsa->sizeof_g_packet);
8906 memset (regs, 0, rsa->sizeof_g_packet);
8907 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
8908 {
8909 struct packet_reg *r = &rsa->regs[i];
8910
8911 if (r->in_g_packet)
8912 regcache->raw_collect (r->regnum, regs + r->offset);
8913 }
8914 }
8915
8916 /* Command describes registers byte by byte,
8917 each byte encoded as two hex characters. */
8918 p = rs->buf.data ();
8919 *p++ = 'G';
8920 bin2hex (regs, p, rsa->sizeof_g_packet);
8921 putpkt (rs->buf);
8922 getpkt (&rs->buf);
8924 error (_("Could not write registers; remote failure reply '%s'"),
8925 rs->buf.data ());
8926}
8927
8928/* Store register REGNUM, or all registers if REGNUM == -1, from the contents
8929 of the register cache buffer. FIXME: ignores errors. */
8931void
8933{
8934 struct gdbarch *gdbarch = regcache->arch ();
8935 struct remote_state *rs = get_remote_state ();
8937 int i;
8938
8941
8942 if (regnum >= 0)
8943 {
8945
8946 gdb_assert (reg != NULL);
8947
8948 /* Always prefer to store registers using the 'P' packet if
8949 possible; we often change only a small number of registers.
8950 Sometimes we change a larger number; we'd need help from a
8951 higher layer to know to use 'G'. */
8953 return;
8954
8955 /* For now, don't complain if we have no way to write the
8956 register. GDB loses track of unavailable registers too
8957 easily. Some day, this may be an error. We don't have
8958 any way to read the register, either... */
8959 if (!reg->in_g_packet)
8960 return;
8961
8963 return;
8964 }
8965
8967
8968 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
8969 if (!rsa->regs[i].in_g_packet)
8970 if (!store_register_using_P (regcache, &rsa->regs[i]))
8971 /* See above for why we do not issue an error here. */
8972 continue;
8973}
8974
8975
8976/* Return the number of hex digits in num. */
8978static int
8979hexnumlen (ULONGEST num)
8980{
8981 int i;
8982
8983 for (i = 0; num != 0; i++)
8984 num >>= 4;
8985
8986 return std::max (i, 1);
8987}
8988
8989/* Set BUF to the minimum number of hex digits representing NUM. */
8991static int
8992hexnumstr (char *buf, ULONGEST num)
8993{
8994 int len = hexnumlen (num);
8995
8996 return hexnumnstr (buf, num, len);
8997}
8998
8999
9000/* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
9002static int
9003hexnumnstr (char *buf, ULONGEST num, int width)
9004{
9005 int i;
9006
9007 buf[width] = '\0';
9008
9009 for (i = width - 1; i >= 0; i--)
9010 {
9011 buf[i] = "0123456789abcdef"[(num & 0xf)];
9012 num >>= 4;
9013 }
9014
9015 return width;
9016}
9017
9018/* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
9020static CORE_ADDR
9021remote_address_masked (CORE_ADDR addr)
9022{
9023 unsigned int address_size = remote_address_size;
9024
9025 /* If "remoteaddresssize" was not set, default to target address size. */
9026 if (!address_size)
9027 address_size = gdbarch_addr_bit (target_gdbarch ());
9028
9029 if (address_size > 0
9030 && address_size < (sizeof (ULONGEST) * 8))
9031 {
9032 /* Only create a mask when that mask can safely be constructed
9033 in a ULONGEST variable. */
9034 ULONGEST mask = 1;
9035
9036 mask = (mask << address_size) - 1;
9037 addr &= mask;
9038 }
9039 return addr;
9040}
9041
9042/* Determine whether the remote target supports binary downloading.
9043 This is accomplished by sending a no-op memory write of zero length
9044 to the target at the specified address. It does not suffice to send
9045 the whole packet, since many stubs strip the eighth bit and
9046 subsequently compute a wrong checksum, which causes real havoc with
9047 remote_write_bytes.
9048
9049 NOTE: This can still lose if the serial line is not eight-bit
9050 clean. In cases like this, the user should clear "remote
9051 X-packet". */
9053void
9055{
9056 struct remote_state *rs = get_remote_state ();
9057
9059 {
9060 case PACKET_DISABLE:
9061 break;
9062 case PACKET_ENABLE:
9063 break;
9065 {
9066 char *p;
9067
9068 p = rs->buf.data ();
9069 *p++ = 'X';
9070 p += hexnumstr (p, (ULONGEST) addr);
9071 *p++ = ',';
9072 p += hexnumstr (p, (ULONGEST) 0);
9073 *p++ = ':';
9074 *p = '\0';
9075
9076 putpkt_binary (rs->buf.data (), (int) (p - rs->buf.data ()));
9077 getpkt (&rs->buf);
9078
9079 if (rs->buf[0] == '\0')
9080 {
9081 remote_debug_printf ("binary downloading NOT supported by target");
9083 }
9084 else
9085 {
9086 remote_debug_printf ("binary downloading supported by target");
9088 }
9089 break;
9090 }
9091 }
9092}
9093
9094/* Helper function to resize the payload in order to try to get a good
9095 alignment. We try to write an amount of data such that the next write will
9096 start on an address aligned on REMOTE_ALIGN_WRITES. */
9098static int
9099align_for_efficient_write (int todo, CORE_ADDR memaddr)
9100{
9101 return ((memaddr + todo) & ~(REMOTE_ALIGN_WRITES - 1)) - memaddr;
9102}
9103
9104/* Write memory data directly to the remote machine.
9105 This does not inform the data cache; the data cache uses this.
9106 HEADER is the starting part of the packet.
9107 MEMADDR is the address in the remote memory space.
9108 MYADDR is the address of the buffer in our space.
9109 LEN_UNITS is the number of addressable units to write.
9110 UNIT_SIZE is the length in bytes of an addressable unit.
9111 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
9112 should send data as binary ('X'), or hex-encoded ('M').
9113
9114 The function creates packet of the form
9115 <HEADER><ADDRESS>,<LENGTH>:<DATA>
9116
9117 where encoding of <DATA> is terminated by PACKET_FORMAT.
9118
9119 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
9120 are omitted.
9121
9122 Return the transferred status, error or OK (an
9123 'enum target_xfer_status' value). Save the number of addressable units
9124 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
9125
9126 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
9127 exchange between gdb and the stub could look like (?? in place of the
9128 checksum):
9129
9130 -> $m1000,4#??
9131 <- aaaabbbbccccdddd
9132
9133 -> $M1000,3:eeeeffffeeee#??
9134 <- OK
9135
9136 -> $m1000,4#??
9137 <- eeeeffffeeeedddd */
9140remote_target::remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
9141 const gdb_byte *myaddr,
9142 ULONGEST len_units,
9143 int unit_size,
9144 ULONGEST *xfered_len_units,
9145 char packet_format, int use_length)
9146{
9147 struct remote_state *rs = get_remote_state ();
9148 char *p;
9149 char *plen = NULL;
9150 int plenlen = 0;
9151 int todo_units;
9152 int units_written;
9153 int payload_capacity_bytes;
9154 int payload_length_bytes;
9155
9156 if (packet_format != 'X' && packet_format != 'M')
9157 internal_error (_("remote_write_bytes_aux: bad packet format"));
9158
9159 if (len_units == 0)
9160 return TARGET_XFER_EOF;
9161
9162 payload_capacity_bytes = get_memory_write_packet_size ();
9163
9164 /* The packet buffer will be large enough for the payload;
9165 get_memory_packet_size ensures this. */
9166 rs->buf[0] = '\0';
9167
9168 /* Compute the size of the actual payload by subtracting out the
9169 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
9170
9171 payload_capacity_bytes -= strlen ("$,:#NN");
9172 if (!use_length)
9173 /* The comma won't be used. */
9174 payload_capacity_bytes += 1;
9175 payload_capacity_bytes -= strlen (header);
9176 payload_capacity_bytes -= hexnumlen (memaddr);
9177
9178 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
9179
9180 strcat (rs->buf.data (), header);
9181 p = rs->buf.data () + strlen (header);
9182
9183 /* Compute a best guess of the number of bytes actually transfered. */
9184 if (packet_format == 'X')
9185 {
9186 /* Best guess at number of bytes that will fit. */
9187 todo_units = std::min (len_units,
9188 (ULONGEST) payload_capacity_bytes / unit_size);
9189 if (use_length)
9190 payload_capacity_bytes -= hexnumlen (todo_units);
9191 todo_units = std::min (todo_units, payload_capacity_bytes / unit_size);
9192 }
9193 else
9194 {
9195 /* Number of bytes that will fit. */
9196 todo_units
9197 = std::min (len_units,
9198 (ULONGEST) (payload_capacity_bytes / unit_size) / 2);
9199 if (use_length)
9200 payload_capacity_bytes -= hexnumlen (todo_units);
9201 todo_units = std::min (todo_units,
9202 (payload_capacity_bytes / unit_size) / 2);
9203 }
9204
9205 if (todo_units <= 0)
9206 internal_error (_("minimum packet size too small to write data"));
9207
9208 /* If we already need another packet, then try to align the end
9209 of this packet to a useful boundary. */
9210 if (todo_units > 2 * REMOTE_ALIGN_WRITES && todo_units < len_units)
9211 todo_units = align_for_efficient_write (todo_units, memaddr);
9212
9213 /* Append "<memaddr>". */
9214 memaddr = remote_address_masked (memaddr);
9215 p += hexnumstr (p, (ULONGEST) memaddr);
9216
9217 if (use_length)
9218 {
9219 /* Append ",". */
9220 *p++ = ',';
9221
9222 /* Append the length and retain its location and size. It may need to be
9223 adjusted once the packet body has been created. */
9224 plen = p;
9225 plenlen = hexnumstr (p, (ULONGEST) todo_units);
9226 p += plenlen;
9227 }
9228
9229 /* Append ":". */
9230 *p++ = ':';
9231 *p = '\0';
9232
9233 /* Append the packet body. */
9234 if (packet_format == 'X')
9235 {
9236 /* Binary mode. Send target system values byte by byte, in
9237 increasing byte addresses. Only escape certain critical
9238 characters. */
9239 payload_length_bytes =
9240 remote_escape_output (myaddr, todo_units, unit_size, (gdb_byte *) p,
9241 &units_written, payload_capacity_bytes);
9242
9243 /* If not all TODO units fit, then we'll need another packet. Make
9244 a second try to keep the end of the packet aligned. Don't do
9245 this if the packet is tiny. */
9246 if (units_written < todo_units && units_written > 2 * REMOTE_ALIGN_WRITES)
9247 {
9248 int new_todo_units;
9249
9250 new_todo_units = align_for_efficient_write (units_written, memaddr);
9251
9252 if (new_todo_units != units_written)
9253 payload_length_bytes =
9254 remote_escape_output (myaddr, new_todo_units, unit_size,
9255 (gdb_byte *) p, &units_written,
9256 payload_capacity_bytes);
9257 }
9258
9259 p += payload_length_bytes;
9260 if (use_length && units_written < todo_units)
9261 {
9262 /* Escape chars have filled up the buffer prematurely,
9263 and we have actually sent fewer units than planned.
9264 Fix-up the length field of the packet. Use the same
9265 number of characters as before. */
9266 plen += hexnumnstr (plen, (ULONGEST) units_written,
9267 plenlen);
9268 *plen = ':'; /* overwrite \0 from hexnumnstr() */
9269 }
9270 }
9271 else
9272 {
9273 /* Normal mode: Send target system values byte by byte, in
9274 increasing byte addresses. Each byte is encoded as a two hex
9275 value. */
9276 p += 2 * bin2hex (myaddr, p, todo_units * unit_size);
9277 units_written = todo_units;
9278 }
9279
9280 putpkt_binary (rs->buf.data (), (int) (p - rs->buf.data ()));
9281 getpkt (&rs->buf);
9282
9283 if (rs->buf[0] == 'E')
9284 return TARGET_XFER_E_IO;
9285
9286 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
9287 send fewer units than we'd planned. */
9288 *xfered_len_units = (ULONGEST) units_written;
9289 return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
9290}
9291
9292/* Write memory data directly to the remote machine.
9293 This does not inform the data cache; the data cache uses this.
9294 MEMADDR is the address in the remote memory space.
9295 MYADDR is the address of the buffer in our space.
9296 LEN is the number of bytes.
9297
9298 Return the transferred status, error or OK (an
9299 'enum target_xfer_status' value). Save the number of bytes
9300 transferred in *XFERED_LEN. Only transfer a single packet. */
9303remote_target::remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr,
9304 ULONGEST len, int unit_size,
9305 ULONGEST *xfered_len)
9306{
9307 const char *packet_format = NULL;
9308
9309 /* Check whether the target supports binary download. */
9310 check_binary_download (memaddr);
9311
9313 {
9314 case PACKET_ENABLE:
9315 packet_format = "X";
9316 break;
9317 case PACKET_DISABLE:
9318 packet_format = "M";
9319 break;
9321 internal_error (_("remote_write_bytes: bad internal state"));
9322 default:
9323 internal_error (_("bad switch"));
9324 }
9325
9326 return remote_write_bytes_aux (packet_format,
9327 memaddr, myaddr, len, unit_size, xfered_len,
9328 packet_format[0], 1);
9329}
9330
9331/* Read memory data directly from the remote machine.
9332 This does not use the data cache; the data cache uses this.
9333 MEMADDR is the address in the remote memory space.
9334 MYADDR is the address of the buffer in our space.
9335 LEN_UNITS is the number of addressable memory units to read..
9336 UNIT_SIZE is the length in bytes of an addressable unit.
9337
9338 Return the transferred status, error or OK (an
9339 'enum target_xfer_status' value). Save the number of bytes
9340 transferred in *XFERED_LEN_UNITS.
9341
9342 See the comment of remote_write_bytes_aux for an example of
9343 memory read/write exchange between gdb and the stub. */
9346remote_target::remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr,
9347 ULONGEST len_units,
9348 int unit_size, ULONGEST *xfered_len_units)
9349{
9350 struct remote_state *rs = get_remote_state ();
9351 int buf_size_bytes; /* Max size of packet output buffer. */
9352 char *p;
9353 int todo_units;
9354 int decoded_bytes;
9355
9356 buf_size_bytes = get_memory_read_packet_size ();
9357 /* The packet buffer will be large enough for the payload;
9358 get_memory_packet_size ensures this. */
9359
9360 /* Number of units that will fit. */
9361 todo_units = std::min (len_units,
9362 (ULONGEST) (buf_size_bytes / unit_size) / 2);
9363
9364 /* Construct "m"<memaddr>","<len>". */
9365 memaddr = remote_address_masked (memaddr);
9366 p = rs->buf.data ();
9367 *p++ = 'm';
9368 p += hexnumstr (p, (ULONGEST) memaddr);
9369 *p++ = ',';
9370 p += hexnumstr (p, (ULONGEST) todo_units);
9371 *p = '\0';
9372 putpkt (rs->buf);
9373 getpkt (&rs->buf);
9374 if (rs->buf[0] == 'E'
9375 && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
9376 && rs->buf[3] == '\0')
9377 return TARGET_XFER_E_IO;
9378 /* Reply describes memory byte by byte, each byte encoded as two hex
9379 characters. */
9380 p = rs->buf.data ();
9381 decoded_bytes = hex2bin (p, myaddr, todo_units * unit_size);
9382 /* Return what we have. Let higher layers handle partial reads. */
9383 *xfered_len_units = (ULONGEST) (decoded_bytes / unit_size);
9384 return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
9385}
9386
9387/* Using the set of read-only target sections of remote, read live
9388 read-only memory.
9389
9390 For interface/parameters/return description see target.h,
9391 to_xfer_partial. */
9395 ULONGEST memaddr,
9396 ULONGEST len,
9397 int unit_size,
9398 ULONGEST *xfered_len)
9399{
9400 const struct target_section *secp;
9401
9402 secp = target_section_by_addr (this, memaddr);
9403 if (secp != NULL
9404 && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
9405 {
9406 ULONGEST memend = memaddr + len;
9407
9408 const target_section_table *table = target_get_section_table (this);
9409 for (const target_section &p : *table)
9410 {
9411 if (memaddr >= p.addr)
9412 {
9413 if (memend <= p.endaddr)
9414 {
9415 /* Entire transfer is within this section. */
9416 return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
9417 xfered_len);
9418 }
9419 else if (memaddr >= p.endaddr)
9420 {
9421 /* This section ends before the transfer starts. */
9422 continue;
9423 }
9424 else
9425 {
9426 /* This section overlaps the transfer. Just do half. */
9427 len = p.endaddr - memaddr;
9428 return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
9429 xfered_len);
9430 }
9431 }
9432 }
9433 }
9434
9435 return TARGET_XFER_EOF;
9436}
9437
9438/* Similar to remote_read_bytes_1, but it reads from the remote stub
9439 first if the requested memory is unavailable in traceframe.
9440 Otherwise, fall back to remote_read_bytes_1. */
9443remote_target::remote_read_bytes (CORE_ADDR memaddr,
9444 gdb_byte *myaddr, ULONGEST len, int unit_size,
9445 ULONGEST *xfered_len)
9446{
9447 if (len == 0)
9448 return TARGET_XFER_EOF;
9449
9450 if (get_traceframe_number () != -1)
9451 {
9452 std::vector<mem_range> available;
9453
9454 /* If we fail to get the set of available memory, then the
9455 target does not support querying traceframe info, and so we
9456 attempt reading from the traceframe anyway (assuming the
9457 target implements the old QTro packet then). */
9458 if (traceframe_available_memory (&available, memaddr, len))
9459 {
9460 if (available.empty () || available[0].start != memaddr)
9461 {
9462 enum target_xfer_status res;
9463
9464 /* Don't read into the traceframe's available
9465 memory. */
9466 if (!available.empty ())
9467 {
9468 LONGEST oldlen = len;
9469
9470 len = available[0].start - memaddr;
9471 gdb_assert (len <= oldlen);
9472 }
9473
9474 /* This goes through the topmost target again. */
9475 res = remote_xfer_live_readonly_partial (myaddr, memaddr,
9476 len, unit_size, xfered_len);
9477 if (res == TARGET_XFER_OK)
9478 return TARGET_XFER_OK;
9479 else
9480 {
9481 /* No use trying further, we know some memory starting
9482 at MEMADDR isn't available. */
9483 *xfered_len = len;
9484 return (*xfered_len != 0) ?
9486 }
9487 }
9488
9489 /* Don't try to read more than how much is available, in
9490 case the target implements the deprecated QTro packet to
9491 cater for older GDBs (the target's knowledge of read-only
9492 sections may be outdated by now). */
9493 len = available[0].length;
9494 }
9495 }
9496
9497 return remote_read_bytes_1 (memaddr, myaddr, len, unit_size, xfered_len);
9498}
9499
9500
9501
9502/* Sends a packet with content determined by the printf format string
9503 FORMAT and the remaining arguments, then gets the reply. Returns
9504 whether the packet was a success, a failure, or unknown. */
9507remote_target::remote_send_printf (const char *format, ...)
9508{
9509 struct remote_state *rs = get_remote_state ();
9510 int max_size = get_remote_packet_size ();
9511 va_list ap;
9512
9513 va_start (ap, format);
9514
9515 rs->buf[0] = '\0';
9516 int size = vsnprintf (rs->buf.data (), max_size, format, ap);
9517
9518 va_end (ap);
9519
9520 if (size >= max_size)
9521 internal_error (_("Too long remote packet."));
9522
9523 if (putpkt (rs->buf) < 0)
9524 error (_("Communication problem with target."));
9525
9526 rs->buf[0] = '\0';
9527 getpkt (&rs->buf);
9528
9529 return packet_check_result (rs->buf);
9530}
9531
9532/* Flash writing can take quite some time. We'll set
9533 effectively infinite timeout for flash operations.
9534 In future, we'll need to decide on a better approach. */
9535static const int remote_flash_timeout = 1000;
9537void
9538remote_target::flash_erase (ULONGEST address, LONGEST length)
9539{
9540 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
9541 enum packet_result ret;
9542 scoped_restore restore_timeout
9543 = make_scoped_restore (&remote_timeout, remote_flash_timeout);
9544
9545 ret = remote_send_printf ("vFlashErase:%s,%s",
9546 phex (address, addr_size),
9547 phex (length, 4));
9548 switch (ret)
9549 {
9550 case PACKET_UNKNOWN:
9551 error (_("Remote target does not support flash erase"));
9552 case PACKET_ERROR:
9553 error (_("Error erasing flash with vFlashErase packet"));
9554 default:
9555 break;
9556 }
9557}
9560remote_target::remote_flash_write (ULONGEST address,
9561 ULONGEST length, ULONGEST *xfered_len,
9562 const gdb_byte *data)
9563{
9564 scoped_restore restore_timeout
9565 = make_scoped_restore (&remote_timeout, remote_flash_timeout);
9566 return remote_write_bytes_aux ("vFlashWrite:", address, data, length, 1,
9567 xfered_len,'X', 0);
9568}
9570void
9572{
9573 int ret;
9574
9575 scoped_restore restore_timeout
9576 = make_scoped_restore (&remote_timeout, remote_flash_timeout);
9577
9578 ret = remote_send_printf ("vFlashDone");
9579
9580 switch (ret)
9581 {
9582 case PACKET_UNKNOWN:
9583 error (_("Remote target does not support vFlashDone"));
9584 case PACKET_ERROR:
9585 error (_("Error finishing flash operation"));
9586 default:
9587 break;
9588 }
9589}
9590
9591
9592/* Stuff for dealing with the packets which are part of this protocol.
9593 See comment at top of file for details. */
9594
9595/* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
9596 error to higher layers. Called when a serial error is detected.
9597 The exception message is STRING, followed by a colon and a blank,
9598 the system error message for errno at function entry and final dot
9599 for output compatibility with throw_perror_with_name. */
9601static void
9602unpush_and_perror (remote_target *target, const char *string)
9603{
9604 int saved_errno = errno;
9605
9606 remote_unpush_target (target);
9607 throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
9608 safe_strerror (saved_errno));
9609}
9610
9611/* Read a single character from the remote end. The current quit
9612 handler is overridden to avoid quitting in the middle of packet
9613 sequence, as that would break communication with the remote server.
9614 See remote_serial_quit_handler for more detail. */
9616int
9617remote_target::readchar (int timeout)
9618{
9619 int ch;
9620 struct remote_state *rs = get_remote_state ();
9621
9622 {
9623 scoped_restore restore_quit_target
9624 = make_scoped_restore (&curr_quit_handler_target, this);
9625 scoped_restore restore_quit
9626 = make_scoped_restore (&quit_handler, ::remote_serial_quit_handler);
9627
9628 rs->got_ctrlc_during_io = 0;
9629
9630 ch = serial_readchar (rs->remote_desc, timeout);
9631
9632 if (rs->got_ctrlc_during_io)
9633 set_quit_flag ();
9634 }
9635
9636 if (ch >= 0)
9637 return ch;
9638
9639 switch ((enum serial_rc) ch)
9640 {
9641 case SERIAL_EOF:
9642 remote_unpush_target (this);
9643 throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
9644 /* no return */
9645 case SERIAL_ERROR:
9646 unpush_and_perror (this, _("Remote communication error. "
9647 "Target disconnected"));
9648 /* no return */
9649 case SERIAL_TIMEOUT:
9650 break;
9651 }
9652 return ch;
9653}
9654
9655/* Wrapper for serial_write that closes the target and throws if
9656 writing fails. The current quit handler is overridden to avoid
9657 quitting in the middle of packet sequence, as that would break
9658 communication with the remote server. See
9659 remote_serial_quit_handler for more detail. */
9661void
9662remote_target::remote_serial_write (const char *str, int len)
9663{
9664 struct remote_state *rs = get_remote_state ();
9665
9666 scoped_restore restore_quit_target
9667 = make_scoped_restore (&curr_quit_handler_target, this);
9668 scoped_restore restore_quit
9669 = make_scoped_restore (&quit_handler, ::remote_serial_quit_handler);
9670
9671 rs->got_ctrlc_during_io = 0;
9672
9673 if (serial_write (rs->remote_desc, str, len))
9674 {
9675 unpush_and_perror (this, _("Remote communication error. "
9676 "Target disconnected"));
9677 }
9678
9679 if (rs->got_ctrlc_during_io)
9680 set_quit_flag ();
9681}
9682
9683/* Return a string representing an escaped version of BUF, of len N.
9684 E.g. \n is converted to \\n, \t to \\t, etc. */
9686static std::string
9687escape_buffer (const char *buf, int n)
9688{
9689 string_file stb;
9690
9691 stb.putstrn (buf, n, '\\');
9692 return stb.release ();
9693}
9695int
9696remote_target::putpkt (const char *buf)
9697{
9698 return putpkt_binary (buf, strlen (buf));
9699}
9700
9701/* Wrapper around remote_target::putpkt to avoid exporting
9702 remote_target. */
9704int
9705putpkt (remote_target *remote, const char *buf)
9706{
9707 return remote->putpkt (buf);
9708}
9709
9710/* Send a packet to the remote machine, with error checking. The data
9711 of the packet is in BUF. The string in BUF can be at most
9712 get_remote_packet_size () - 5 to account for the $, # and checksum,
9713 and for a possible /0 if we are debugging (remote_debug) and want
9714 to print the sent packet as a string. */
9716int
9717remote_target::putpkt_binary (const char *buf, int cnt)
9718{
9719 struct remote_state *rs = get_remote_state ();
9720 int i;
9721 unsigned char csum = 0;
9722 gdb::def_vector<char> data (cnt + 6);
9723 char *buf2 = data.data ();
9724
9725 int ch;
9726 int tcount = 0;
9727 char *p;
9728
9729 /* Catch cases like trying to read memory or listing threads while
9730 we're waiting for a stop reply. The remote server wouldn't be
9731 ready to handle this request, so we'd hang and timeout. We don't
9732 have to worry about this in synchronous mode, because in that
9733 case it's not possible to issue a command while the target is
9734 running. This is not a problem in non-stop mode, because in that
9735 case, the stub is always ready to process serial input. */
9736 if (!target_is_non_stop_p ()
9737 && target_is_async_p ()
9739 {
9740 error (_("Cannot execute this command while the target is running.\n"
9741 "Use the \"interrupt\" command to stop the target\n"
9742 "and then try again."));
9743 }
9744
9745 /* Copy the packet into buffer BUF2, encapsulating it
9746 and giving it a checksum. */
9747
9748 p = buf2;
9749 *p++ = '$';
9750
9751 for (i = 0; i < cnt; i++)
9752 {
9753 csum += buf[i];
9754 *p++ = buf[i];
9755 }
9756 *p++ = '#';
9757 *p++ = tohex ((csum >> 4) & 0xf);
9758 *p++ = tohex (csum & 0xf);
9759
9760 /* Send it over and over until we get a positive ack. */
9761
9762 while (1)
9763 {
9764 if (remote_debug)
9765 {
9766 *p = '\0';
9767
9768 int len = (int) (p - buf2);
9769 int max_chars;
9770
9772 max_chars = len;
9773 else
9774 max_chars = remote_packet_max_chars;
9775
9776 std::string str
9777 = escape_buffer (buf2, std::min (len, max_chars));
9778
9779 if (len > max_chars)
9781 ("Sending packet: %s [%d bytes omitted]", str.c_str (),
9782 len - max_chars);
9783 else
9784 remote_debug_printf_nofunc ("Sending packet: %s", str.c_str ());
9785 }
9786 remote_serial_write (buf2, p - buf2);
9787
9788 /* If this is a no acks version of the remote protocol, send the
9789 packet and move on. */
9790 if (rs->noack_mode)
9791 break;
9792
9793 /* Read until either a timeout occurs (-2) or '+' is read.
9794 Handle any notification that arrives in the mean time. */
9795 while (1)
9796 {
9797 ch = readchar (remote_timeout);
9798
9799 switch (ch)
9800 {
9801 case '+':
9802 remote_debug_printf_nofunc ("Received Ack");
9803 return 1;
9804 case '-':
9805 remote_debug_printf_nofunc ("Received Nak");
9806 /* FALLTHROUGH */
9807 case SERIAL_TIMEOUT:
9808 tcount++;
9809 if (tcount > 3)
9810 return 0;
9811 break; /* Retransmit buffer. */
9812 case '$':
9813 {
9814 remote_debug_printf ("Packet instead of Ack, ignoring it");
9815 /* It's probably an old response sent because an ACK
9816 was lost. Gobble up the packet and ack it so it
9817 doesn't get retransmitted when we resend this
9818 packet. */
9819 skip_frame ();
9820 remote_serial_write ("+", 1);
9821 continue; /* Now, go look for +. */
9822 }
9823
9824 case '%':
9825 {
9826 int val;
9827
9828 /* If we got a notification, handle it, and go back to looking
9829 for an ack. */
9830 /* We've found the start of a notification. Now
9831 collect the data. */
9832 val = read_frame (&rs->buf);
9833 if (val >= 0)
9834 {
9836 (" Notification received: %s",
9837 escape_buffer (rs->buf.data (), val).c_str ());
9838
9839 handle_notification (rs->notif_state, rs->buf.data ());
9840 /* We're in sync now, rewait for the ack. */
9841 tcount = 0;
9842 }
9843 else
9844 remote_debug_printf_nofunc ("Junk: %c%s", ch & 0177,
9845 rs->buf.data ());
9846 continue;
9847 }
9848 /* fall-through */
9849 default:
9850 remote_debug_printf_nofunc ("Junk: %c%s", ch & 0177,
9851 rs->buf.data ());
9852 continue;
9853 }
9854 break; /* Here to retransmit. */
9855 }
9856
9857#if 0
9858 /* This is wrong. If doing a long backtrace, the user should be
9859 able to get out next time we call QUIT, without anything as
9860 violent as interrupt_query. If we want to provide a way out of
9861 here without getting to the next QUIT, it should be based on
9862 hitting ^C twice as in remote_wait. */
9863 if (quit_flag)
9864 {
9865 quit_flag = 0;
9866 interrupt_query ();
9867 }
9868#endif
9869 }
9870
9871 return 0;
9872}
9873
9874/* Come here after finding the start of a frame when we expected an
9875 ack. Do our best to discard the rest of this packet. */
9877void
9879{
9880 int c;
9881
9882 while (1)
9883 {
9885 switch (c)
9886 {
9887 case SERIAL_TIMEOUT:
9888 /* Nothing we can do. */
9889 return;
9890 case '#':
9891 /* Discard the two bytes of checksum and stop. */
9893 if (c >= 0)
9895
9896 return;
9897 case '*': /* Run length encoding. */
9898 /* Discard the repeat count. */
9900 if (c < 0)
9901 return;
9902 break;
9903 default:
9904 /* A regular character. */
9905 break;
9906 }
9907 }
9908}
9909
9910/* Come here after finding the start of the frame. Collect the rest
9911 into *BUF, verifying the checksum, length, and handling run-length
9912 compression. NUL terminate the buffer. If there is not enough room,
9913 expand *BUF.
9914
9915 Returns -1 on error, number of characters in buffer (ignoring the
9916 trailing NULL) on success. (could be extended to return one of the
9917 SERIAL status indications). */
9919long
9920remote_target::read_frame (gdb::char_vector *buf_p)
9921{
9922 unsigned char csum;
9923 long bc;
9924 int c;
9925 char *buf = buf_p->data ();
9926 struct remote_state *rs = get_remote_state ();
9927
9928 csum = 0;
9929 bc = 0;
9930
9931 while (1)
9932 {
9934 switch (c)
9935 {
9936 case SERIAL_TIMEOUT:
9937 remote_debug_printf ("Timeout in mid-packet, retrying");
9938 return -1;
9939
9940 case '$':
9941 remote_debug_printf ("Saw new packet start in middle of old one");
9942 return -1; /* Start a new packet, count retries. */
9943
9944 case '#':
9945 {
9946 unsigned char pktcsum;
9947 int check_0 = 0;
9948 int check_1 = 0;
9949
9950 buf[bc] = '\0';
9951
9952 check_0 = readchar (remote_timeout);
9953 if (check_0 >= 0)
9954 check_1 = readchar (remote_timeout);
9955
9956 if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
9957 {
9958 remote_debug_printf ("Timeout in checksum, retrying");
9959 return -1;
9960 }
9961 else if (check_0 < 0 || check_1 < 0)
9962 {
9963 remote_debug_printf ("Communication error in checksum");
9964 return -1;
9965 }
9966
9967 /* Don't recompute the checksum; with no ack packets we
9968 don't have any way to indicate a packet retransmission
9969 is necessary. */
9970 if (rs->noack_mode)
9971 return bc;
9972
9973 pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
9974 if (csum == pktcsum)
9975 return bc;
9976
9978 ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s",
9979 pktcsum, csum, escape_buffer (buf, bc).c_str ());
9980
9981 /* Number of characters in buffer ignoring trailing
9982 NULL. */
9983 return -1;
9984 }
9985 case '*': /* Run length encoding. */
9986 {
9987 int repeat;
9988
9989 csum += c;
9991 csum += c;
9992 repeat = c - ' ' + 3; /* Compute repeat count. */
9993
9994 /* The character before ``*'' is repeated. */
9995
9996 if (repeat > 0 && repeat <= 255 && bc > 0)
9997 {
9998 if (bc + repeat - 1 >= buf_p->size () - 1)
9999 {
10000 /* Make some more room in the buffer. */
10001 buf_p->resize (buf_p->size () + repeat);
10002 buf = buf_p->data ();
10003 }
10004
10005 memset (&buf[bc], buf[bc - 1], repeat);
10006 bc += repeat;
10007 continue;
10008 }
10009
10010 buf[bc] = '\0';
10011 gdb_printf (_("Invalid run length encoding: %s\n"), buf);
10012 return -1;
10013 }
10014 default:
10015 if (bc >= buf_p->size () - 1)
10016 {
10017 /* Make some more room in the buffer. */
10018 buf_p->resize (buf_p->size () * 2);
10019 buf = buf_p->data ();
10020 }
10021
10022 buf[bc++] = c;
10023 csum += c;
10024 continue;
10025 }
10026 }
10027}
10028
10029/* Set this to the maximum number of seconds to wait instead of waiting forever
10030 in target_wait(). If this timer times out, then it generates an error and
10031 the command is aborted. This replaces most of the need for timeouts in the
10032 GDB test suite, and makes it possible to distinguish between a hung target
10033 and one with slow communications. */
10034
10035static int watchdog = 0;
10036static void
10037show_watchdog (struct ui_file *file, int from_tty,
10038 struct cmd_list_element *c, const char *value)
10039{
10040 gdb_printf (file, _("Watchdog timer is %s.\n"), value);
10041}
10042
10043/* Read a packet from the remote machine, with error checking, and
10044 store it in *BUF. Resize *BUF if necessary to hold the result. If
10045 FOREVER, wait forever rather than timing out; this is used (in
10046 synchronous mode) to wait for a target that is is executing user
10047 code to stop. If FOREVER == false, this function is allowed to time
10048 out gracefully and return an indication of this to the caller.
10049 Otherwise return the number of bytes read. If IS_NOTIF is not
10050 NULL, then consider receiving a notification enough reason to
10051 return to the caller. In this case, *IS_NOTIF is an output boolean
10052 that indicates whether *BUF holds a notification or not (a regular
10053 packet). */
10055int
10056remote_target::getpkt (gdb::char_vector *buf, bool forever, bool *is_notif)
10057{
10058 struct remote_state *rs = get_remote_state ();
10059 int c;
10060 int tries;
10061 int timeout;
10062 int val = -1;
10063
10064 strcpy (buf->data (), "timeout");
10065
10066 if (forever)
10067 timeout = watchdog > 0 ? watchdog : -1;
10068 else if (is_notif != nullptr)
10069 timeout = 0; /* There should already be a char in the buffer. If
10070 not, bail out. */
10071 else
10072 timeout = remote_timeout;
10073
10074#define MAX_TRIES 3
10075
10076 /* Process any number of notifications, and then return when
10077 we get a packet. */
10078 for (;;)
10079 {
10080 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
10081 times. */
10082 for (tries = 1; tries <= MAX_TRIES; tries++)
10083 {
10084 /* This can loop forever if the remote side sends us
10085 characters continuously, but if it pauses, we'll get
10086 SERIAL_TIMEOUT from readchar because of timeout. Then
10087 we'll count that as a retry.
10088
10089 Note that even when forever is set, we will only wait
10090 forever prior to the start of a packet. After that, we
10091 expect characters to arrive at a brisk pace. They should
10092 show up within remote_timeout intervals. */
10093 do
10094 c = readchar (timeout);
10095 while (c != SERIAL_TIMEOUT && c != '$' && c != '%');
10096
10097 if (c == SERIAL_TIMEOUT)
10098 {
10099 if (is_notif != nullptr)
10100 return -1; /* Don't complain, it's normal to not get
10101 anything in this case. */
10102
10103 if (forever) /* Watchdog went off? Kill the target. */
10104 {
10105 remote_unpush_target (this);
10106 throw_error (TARGET_CLOSE_ERROR,
10107 _("Watchdog timeout has expired. "
10108 "Target detached."));
10109 }
10110
10111 remote_debug_printf ("Timed out.");
10112 }
10113 else
10114 {
10115 /* We've found the start of a packet or notification.
10116 Now collect the data. */
10117 val = read_frame (buf);
10118 if (val >= 0)
10119 break;
10120 }
10121
10122 remote_serial_write ("-", 1);
10123 }
10124
10125 if (tries > MAX_TRIES)
10126 {
10127 /* We have tried hard enough, and just can't receive the
10128 packet/notification. Give up. */
10129 gdb_printf (_("Ignoring packet error, continuing...\n"));
10130
10131 /* Skip the ack char if we're in no-ack mode. */
10132 if (!rs->noack_mode)
10133 remote_serial_write ("+", 1);
10134 return -1;
10135 }
10136
10137 /* If we got an ordinary packet, return that to our caller. */
10138 if (c == '$')
10139 {
10140 if (remote_debug)
10141 {
10142 int max_chars;
10143
10145 max_chars = val;
10146 else
10147 max_chars = remote_packet_max_chars;
10148
10149 std::string str
10150 = escape_buffer (buf->data (),
10151 std::min (val, max_chars));
10152
10153 if (val > max_chars)
10155 ("Packet received: %s [%d bytes omitted]", str.c_str (),
10156 val - max_chars);
10157 else
10158 remote_debug_printf_nofunc ("Packet received: %s",
10159 str.c_str ());
10160 }
10161
10162 /* Skip the ack char if we're in no-ack mode. */
10163 if (!rs->noack_mode)
10164 remote_serial_write ("+", 1);
10165 if (is_notif != NULL)
10166 *is_notif = false;
10167 return val;
10168 }
10169
10170 /* If we got a notification, handle it, and go back to looking
10171 for a packet. */
10172 else
10173 {
10174 gdb_assert (c == '%');
10175
10177 (" Notification received: %s",
10178 escape_buffer (buf->data (), val).c_str ());
10179
10180 if (is_notif != NULL)
10181 *is_notif = true;
10182
10183 handle_notification (rs->notif_state, buf->data ());
10184
10185 /* Notifications require no acknowledgement. */
10186
10187 if (is_notif != nullptr)
10188 return val;
10189 }
10190 }
10191}
10192
10193/* Kill any new fork children of inferior INF that haven't been
10194 processed by follow_fork. */
10196void
10198{
10200 const notif_client *notif = &notif_client_stop;
10201
10202 /* Kill the fork child threads of any threads in inferior INF that are stopped
10203 at a fork event. */
10204 for (thread_info *thread : inf->non_exited_threads ())
10205 {
10206 const target_waitstatus *ws = thread_pending_fork_status (thread);
10207
10208 if (ws == nullptr)
10209 continue;
10210
10211 int child_pid = ws->child_ptid ().pid ();
10212 int res = remote_vkill (child_pid);
10213
10214 if (res != 0)
10215 error (_("Can't kill fork child process %d"), child_pid);
10216 }
10217
10218 /* Check for any pending fork events (not reported or processed yet)
10219 in inferior INF and kill those fork child threads as well. */
10221 for (auto &event : rs->stop_reply_queue)
10222 {
10223 if (event->ptid.pid () != inf->pid)
10224 continue;
10225
10226 if (!is_fork_status (event->ws.kind ()))
10227 continue;
10228
10229 int child_pid = event->ws.child_ptid ().pid ();
10230 int res = remote_vkill (child_pid);
10231
10232 if (res != 0)
10233 error (_("Can't kill fork child process %d"), child_pid);
10234 }
10235}
10236
10237
10238/* Target hook to kill the current inferior. */
10240void
10242{
10243 int res = -1;
10244 inferior *inf = find_inferior_pid (this, inferior_ptid.pid ());
10245
10246 gdb_assert (inf != nullptr);
10247
10249 {
10250 /* If we're stopped while forking and we haven't followed yet,
10251 kill the child task. We need to do this before killing the
10252 parent task because if this is a vfork then the parent will
10253 be sleeping. */
10255
10256 res = remote_vkill (inf->pid);
10257 if (res == 0)
10258 {
10260 return;
10261 }
10262 }
10263
10264 /* If we are in 'target remote' mode and we are killing the only
10265 inferior, then we will tell gdbserver to exit and unpush the
10266 target. */
10267 if (res == -1 && !m_features.remote_multi_process_p ()
10268 && number_of_live_inferiors (this) == 1)
10269 {
10270 remote_kill_k ();
10271
10272 /* We've killed the remote end, we get to mourn it. If we are
10273 not in extended mode, mourning the inferior also unpushes
10274 remote_ops from the target stack, which closes the remote
10275 connection. */
10277
10278 return;
10279 }
10280
10281 error (_("Can't kill process"));
10282}
10283
10284/* Send a kill request to the target using the 'vKill' packet. */
10286int
10288{
10290 return -1;
10291
10293
10294 /* Tell the remote target to detach. */
10295 xsnprintf (rs->buf.data (), get_remote_packet_size (), "vKill;%x", pid);
10296 putpkt (rs->buf);
10297 getpkt (&rs->buf);
10298
10299 switch (m_features.packet_ok (rs->buf, PACKET_vKill))
10300 {
10301 case PACKET_OK:
10302 return 0;
10303 case PACKET_ERROR:
10304 return 1;
10305 case PACKET_UNKNOWN:
10306 return -1;
10307 default:
10308 internal_error (_("Bad result from packet_ok"));
10309 }
10310}
10311
10312/* Send a kill request to the target using the 'k' packet. */
10314void
10316{
10317 /* Catch errors so the user can quit from gdb even when we
10318 aren't on speaking terms with the remote system. */
10319 try
10320 {
10321 putpkt ("k");
10322 }
10323 catch (const gdb_exception_error &ex)
10324 {
10325 if (ex.error == TARGET_CLOSE_ERROR)
10326 {
10327 /* If we got an (EOF) error that caused the target
10328 to go away, then we're done, that's what we wanted.
10329 "k" is susceptible to cause a premature EOF, given
10330 that the remote server isn't actually required to
10331 reply to "k", and it can happen that it doesn't
10332 even get to reply ACK to the "k". */
10333 return;
10334 }
10335
10336 /* Otherwise, something went wrong. We didn't actually kill
10337 the target. Just propagate the exception, and let the
10338 user or higher layers decide what to do. */
10339 throw;
10340 }
10341}
10343void
10345{
10346 struct remote_state *rs = get_remote_state ();
10347
10348 /* We're no longer interested in notification events of an inferior
10349 that exited or was killed/detached. */
10351
10352 /* In 'target remote' mode with one inferior, we close the connection. */
10353 if (!rs->extended && number_of_live_inferiors (this) <= 1)
10354 {
10355 remote_unpush_target (this);
10356 return;
10357 }
10358
10359 /* In case we got here due to an error, but we're going to stay
10360 connected. */
10361 rs->waiting_for_stop_reply = 0;
10362
10363 /* If the current general thread belonged to the process we just
10364 detached from or has exited, the remote side current general
10365 thread becomes undefined. Considering a case like this:
10366
10367 - We just got here due to a detach.
10368 - The process that we're detaching from happens to immediately
10369 report a global breakpoint being hit in non-stop mode, in the
10370 same thread we had selected before.
10371 - GDB attaches to this process again.
10372 - This event happens to be the next event we handle.
10373
10374 GDB would consider that the current general thread didn't need to
10375 be set on the stub side (with Hg), since for all it knew,
10376 GENERAL_THREAD hadn't changed.
10377
10378 Notice that although in all-stop mode, the remote server always
10379 sets the current thread to the thread reporting the stop event,
10380 that doesn't happen in non-stop mode; in non-stop, the stub *must
10381 not* change the current thread when reporting a breakpoint hit,
10382 due to the decoupling of event reporting and event handling.
10383
10384 To keep things simple, we always invalidate our notion of the
10385 current thread. */
10386 record_currthread (rs, minus_one_ptid);
10387
10388 /* Call common code to mark the inferior as not running. */
10390}
10396 == PACKET_ENABLE);
10397}
10399void
10401{
10402 struct remote_state *rs = get_remote_state ();
10403 char *reply;
10404
10405 xsnprintf (rs->buf.data (), get_remote_packet_size (),
10406 "QDisableRandomization:%x", val);
10407 putpkt (rs->buf);
10408 reply = remote_get_noisy_reply ();
10409 if (*reply == '\0')
10410 error (_("Target does not support QDisableRandomization."));
10411 if (strcmp (reply, "OK") != 0)
10412 error (_("Bogus QDisableRandomization reply from target: %s"), reply);
10413}
10415int
10416remote_target::extended_remote_run (const std::string &args)
10417{
10418 struct remote_state *rs = get_remote_state ();
10419 int len;
10420 const char *remote_exec_file = get_remote_exec_file ();
10421
10422 /* If the user has disabled vRun support, or we have detected that
10423 support is not available, do not try it. */
10425 return -1;
10426
10427 strcpy (rs->buf.data (), "vRun;");
10428 len = strlen (rs->buf.data ());
10429
10430 if (strlen (remote_exec_file) * 2 + len >= get_remote_packet_size ())
10431 error (_("Remote file name too long for run packet"));
10432 len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf.data () + len,
10433 strlen (remote_exec_file));
10434
10435 if (!args.empty ())
10436 {
10437 int i;
10438
10439 gdb_argv argv (args.c_str ());
10440 for (i = 0; argv[i] != NULL; i++)
10441 {
10442 if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
10443 error (_("Argument list too long for run packet"));
10444 rs->buf[len++] = ';';
10445 len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf.data () + len,
10446 strlen (argv[i]));
10447 }
10448 }
10449
10450 rs->buf[len++] = '\0';
10451
10452 putpkt (rs->buf);
10453 getpkt (&rs->buf);
10454
10455 switch (m_features.packet_ok (rs->buf, PACKET_vRun))
10456 {
10457 case PACKET_OK:
10458 /* We have a wait response. All is well. */
10459 return 0;
10460 case PACKET_UNKNOWN:
10461 return -1;
10462 case PACKET_ERROR:
10463 if (remote_exec_file[0] == '\0')
10464 error (_("Running the default executable on the remote target failed; "
10465 "try \"set remote exec-file\"?"));
10466 else
10467 error (_("Running \"%s\" on the remote target failed"),
10468 remote_exec_file);
10469 default:
10470 gdb_assert_not_reached ("bad switch");
10471 }
10472}
10473
10474/* Helper function to send set/unset environment packets. ACTION is
10475 either "set" or "unset". PACKET is either "QEnvironmentHexEncoded"
10476 or "QEnvironmentUnsetVariable". VALUE is the variable to be
10477 sent. */
10479void
10480remote_target::send_environment_packet (const char *action,
10481 const char *packet,
10482 const char *value)
10483{
10485
10486 /* Convert the environment variable to an hex string, which
10487 is the best format to be transmitted over the wire. */
10488 std::string encoded_value = bin2hex ((const gdb_byte *) value,
10489 strlen (value));
10490
10491 xsnprintf (rs->buf.data (), get_remote_packet_size (),
10492 "%s:%s", packet, encoded_value.c_str ());
10493
10494 putpkt (rs->buf);
10495 getpkt (&rs->buf);
10496 if (strcmp (rs->buf.data (), "OK") != 0)
10497 warning (_("Unable to %s environment variable '%s' on remote."),
10498 action, value);
10499}
10500
10501/* Helper function to handle the QEnvironment* packets. */
10503void
10505{
10507
10509 {
10510 putpkt ("QEnvironmentReset");
10511 getpkt (&rs->buf);
10512 if (strcmp (rs->buf.data (), "OK") != 0)
10513 warning (_("Unable to reset environment on remote."));
10514 }
10515
10516 gdb_environ *e = &current_inferior ()->environment;
10517
10519 != PACKET_DISABLE)
10520 {
10521 for (const std::string &el : e->user_set_env ())
10522 send_environment_packet ("set", "QEnvironmentHexEncoded",
10523 el.c_str ());
10524 }
10525
10526
10528 for (const std::string &el : e->user_unset_env ())
10529 send_environment_packet ("unset", "QEnvironmentUnset", el.c_str ());
10530}
10531
10532/* Helper function to set the current working directory for the
10533 inferior in the remote target. */
10535void
10537{
10539 {
10540 const std::string &inferior_cwd = current_inferior ()->cwd ();
10542
10543 if (!inferior_cwd.empty ())
10544 {
10545 std::string hexpath
10546 = bin2hex ((const gdb_byte *) inferior_cwd.data (),
10547 inferior_cwd.size ());
10548
10549 xsnprintf (rs->buf.data (), get_remote_packet_size (),
10550 "QSetWorkingDir:%s", hexpath.c_str ());
10551 }
10552 else
10553 {
10554 /* An empty inferior_cwd means that the user wants us to
10555 reset the remote server's inferior's cwd. */
10556 xsnprintf (rs->buf.data (), get_remote_packet_size (),
10557 "QSetWorkingDir:");
10558 }
10559
10560 putpkt (rs->buf);
10561 getpkt (&rs->buf);
10563 error (_("\
10564Remote replied unexpectedly while setting the inferior's working\n\
10565directory: %s"),
10566 rs->buf.data ());
10567
10568 }
10569}
10570
10571/* In the extended protocol we want to be able to do things like
10572 "run" and have them basically work as expected. So we need
10573 a special create_inferior function. We support changing the
10574 executable file and the command line arguments, but not the
10575 environment. */
10577void
10578extended_remote_target::create_inferior (const char *exec_file,
10579 const std::string &args,
10580 char **env, int from_tty)
10581{
10582 int run_worked;
10583 char *stop_reply;
10584 struct remote_state *rs = get_remote_state ();
10585 const char *remote_exec_file = get_remote_exec_file ();
10586
10587 /* If running asynchronously, register the target file descriptor
10588 with the event loop. */
10589 if (target_can_async_p ())
10590 target_async (true);
10591
10592 /* Disable address space randomization if requested (and supported). */
10595
10596 /* If startup-with-shell is on, we inform gdbserver to start the
10597 remote inferior using a shell. */
10599 {
10600 xsnprintf (rs->buf.data (), get_remote_packet_size (),
10601 "QStartupWithShell:%d", startup_with_shell ? 1 : 0);
10602 putpkt (rs->buf);
10603 getpkt (&rs->buf);
10604 if (strcmp (rs->buf.data (), "OK") != 0)
10605 error (_("\
10606Remote replied unexpectedly while setting startup-with-shell: %s"),
10607 rs->buf.data ());
10608 }
10609
10611
10613
10614 /* Now restart the remote server. */
10615 run_worked = extended_remote_run (args) != -1;
10616 if (!run_worked)
10617 {
10618 /* vRun was not supported. Fail if we need it to do what the
10619 user requested. */
10620 if (remote_exec_file[0])
10621 error (_("Remote target does not support \"set remote exec-file\""));
10622 if (!args.empty ())
10623 error (_("Remote target does not support \"set args\" or run ARGS"));
10624
10625 /* Fall back to "R". */
10627 }
10628
10629 /* vRun's success return is a stop reply. */
10630 stop_reply = run_worked ? rs->buf.data () : NULL;
10632
10633 /* Get updated offsets, if the stub uses qOffsets. */
10634 get_offsets ();
10635}
10636
10637
10638/* Given a location's target info BP_TGT and the packet buffer BUF, output
10639 the list of conditions (in agent expression bytecode format), if any, the
10640 target needs to evaluate. The output is placed into the packet buffer
10641 started from BUF and ended at BUF_END. */
10643static int
10645 struct bp_target_info *bp_tgt, char *buf,
10646 char *buf_end)
10647{
10648 if (bp_tgt->conditions.empty ())
10649 return 0;
10650
10651 buf += strlen (buf);
10652 xsnprintf (buf, buf_end - buf, "%s", ";");
10653 buf++;
10654
10655 /* Send conditions to the target. */
10656 for (agent_expr *aexpr : bp_tgt->conditions)
10657 {
10658 xsnprintf (buf, buf_end - buf, "X%x,", (int) aexpr->buf.size ());
10659 buf += strlen (buf);
10660 for (int i = 0; i < aexpr->buf.size (); ++i)
10661 buf = pack_hex_byte (buf, aexpr->buf[i]);
10662 *buf = '\0';
10663 }
10664 return 0;
10665}
10667static void
10669 struct bp_target_info *bp_tgt, char *buf)
10670{
10671 if (bp_tgt->tcommands.empty ())
10672 return;
10673
10674 buf += strlen (buf);
10675
10676 sprintf (buf, ";cmds:%x,", bp_tgt->persist);
10677 buf += strlen (buf);
10678
10679 /* Concatenate all the agent expressions that are commands into the
10680 cmds parameter. */
10681 for (agent_expr *aexpr : bp_tgt->tcommands)
10682 {
10683 sprintf (buf, "X%x,", (int) aexpr->buf.size ());
10684 buf += strlen (buf);
10685 for (int i = 0; i < aexpr->buf.size (); ++i)
10686 buf = pack_hex_byte (buf, aexpr->buf[i]);
10687 *buf = '\0';
10688 }
10689}
10690
10691/* Insert a breakpoint. On targets that have software breakpoint
10692 support, we ask the remote target to do the work; on targets
10693 which don't, we insert a traditional memory breakpoint. */
10695int
10697 struct bp_target_info *bp_tgt)
10698{
10699 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
10700 If it succeeds, then set the support to PACKET_ENABLE. If it
10701 fails, and the user has explicitly requested the Z support then
10702 report an error, otherwise, mark it disabled and go on. */
10703
10705 {
10706 CORE_ADDR addr = bp_tgt->reqstd_address;
10707 struct remote_state *rs;
10708 char *p, *endbuf;
10709
10710 /* Make sure the remote is pointing at the right process, if
10711 necessary. */
10714
10715 rs = get_remote_state ();
10716 p = rs->buf.data ();
10717 endbuf = p + get_remote_packet_size ();
10718
10719 *(p++) = 'Z';
10720 *(p++) = '0';
10721 *(p++) = ',';
10722 addr = (ULONGEST) remote_address_masked (addr);
10723 p += hexnumstr (p, addr);
10724 xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
10725
10727 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
10728
10731
10732 putpkt (rs->buf);
10733 getpkt (&rs->buf);
10734
10735 switch (m_features.packet_ok (rs->buf, PACKET_Z0))
10736 {
10737 case PACKET_ERROR:
10738 return -1;
10739 case PACKET_OK:
10740 return 0;
10741 case PACKET_UNKNOWN:
10742 break;
10743 }
10744 }
10745
10746 /* If this breakpoint has target-side commands but this stub doesn't
10747 support Z0 packets, throw error. */
10748 if (!bp_tgt->tcommands.empty ())
10749 throw_error (NOT_SUPPORTED_ERROR, _("\
10750Target doesn't support breakpoints that have target side commands."));
10751
10752 return memory_insert_breakpoint (this, gdbarch, bp_tgt);
10753}
10755int
10757 struct bp_target_info *bp_tgt,
10758 enum remove_bp_reason reason)
10759{
10760 CORE_ADDR addr = bp_tgt->placed_address;
10761 struct remote_state *rs = get_remote_state ();
10762
10764 {
10765 char *p = rs->buf.data ();
10766 char *endbuf = p + get_remote_packet_size ();
10767
10768 /* Make sure the remote is pointing at the right process, if
10769 necessary. */
10772
10773 *(p++) = 'z';
10774 *(p++) = '0';
10775 *(p++) = ',';
10776
10777 addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
10778 p += hexnumstr (p, addr);
10779 xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
10780
10781 putpkt (rs->buf);
10782 getpkt (&rs->buf);
10783
10784 return (rs->buf[0] == 'E');
10785 }
10786
10787 return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason);
10788}
10790static enum Z_packet_type
10792{
10793 switch (type)
10794 {
10795 case hw_write:
10796 return Z_PACKET_WRITE_WP;
10797 break;
10798 case hw_read:
10799 return Z_PACKET_READ_WP;
10800 break;
10801 case hw_access:
10802 return Z_PACKET_ACCESS_WP;
10803 break;
10804 default:
10805 internal_error (_("hw_bp_to_z: bad watchpoint type %d"), type);
10806 }
10807}
10809int
10810remote_target::insert_watchpoint (CORE_ADDR addr, int len,
10811 enum target_hw_bp_type type, struct expression *cond)
10812{
10813 struct remote_state *rs = get_remote_state ();
10814 char *endbuf = rs->buf.data () + get_remote_packet_size ();
10815 char *p;
10817
10818 if (m_features.packet_support ((to_underlying (PACKET_Z0)
10819 + to_underlying (packet))) == PACKET_DISABLE)
10820 return 1;
10821
10822 /* Make sure the remote is pointing at the right process, if
10823 necessary. */
10826
10827 xsnprintf (rs->buf.data (), endbuf - rs->buf.data (), "Z%x,", packet);
10828 p = strchr (rs->buf.data (), '\0');
10829 addr = remote_address_masked (addr);
10830 p += hexnumstr (p, (ULONGEST) addr);
10831 xsnprintf (p, endbuf - p, ",%x", len);
10832
10833 putpkt (rs->buf);
10834 getpkt (&rs->buf);
10835
10836 switch (m_features.packet_ok (rs->buf, (to_underlying (PACKET_Z0)
10837 + to_underlying (packet))))
10838 {
10839 case PACKET_ERROR:
10840 return -1;
10841 case PACKET_UNKNOWN:
10842 return 1;
10843 case PACKET_OK:
10844 return 0;
10845 }
10846 internal_error (_("remote_insert_watchpoint: reached end of function"));
10847}
10849bool
10851 CORE_ADDR start, int length)
10852{
10853 CORE_ADDR diff = remote_address_masked (addr - start);
10854
10855 return diff < length;
10856}
10857
10859int
10860remote_target::remove_watchpoint (CORE_ADDR addr, int len,
10861 enum target_hw_bp_type type, struct expression *cond)
10862{
10863 struct remote_state *rs = get_remote_state ();
10864 char *endbuf = rs->buf.data () + get_remote_packet_size ();
10865 char *p;
10867
10868 if (m_features.packet_support ((to_underlying (PACKET_Z0)
10869 + to_underlying (packet))) == PACKET_DISABLE)
10870 return -1;
10871
10872 /* Make sure the remote is pointing at the right process, if
10873 necessary. */
10876
10877 xsnprintf (rs->buf.data (), endbuf - rs->buf.data (), "z%x,", packet);
10878 p = strchr (rs->buf.data (), '\0');
10879 addr = remote_address_masked (addr);
10880 p += hexnumstr (p, (ULONGEST) addr);
10881 xsnprintf (p, endbuf - p, ",%x", len);
10882 putpkt (rs->buf);
10883 getpkt (&rs->buf);
10884
10885 switch (m_features.packet_ok (rs->buf, (to_underlying (PACKET_Z0)
10886 + to_underlying (packet))))
10887 {
10888 case PACKET_ERROR:
10889 case PACKET_UNKNOWN:
10890 return -1;
10891 case PACKET_OK:
10892 return 0;
10893 }
10894 internal_error (_("remote_remove_watchpoint: reached end of function"));
10895}
10899static int remote_hw_watchpoint_length_limit = -1;
10900static int remote_hw_breakpoint_limit = -1;
10902int
10903remote_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
10904{
10906 return 0;
10908 return 1;
10909 else if (len <= remote_hw_watchpoint_length_limit)
10910 return 1;
10911 else
10912 return 0;
10913}
10915int
10916remote_target::can_use_hw_breakpoint (enum bptype type, int cnt, int ot)
10917{
10919 {
10921 return 0;
10922 else if (remote_hw_breakpoint_limit < 0)
10923 return 1;
10924 else if (cnt <= remote_hw_breakpoint_limit)
10925 return 1;
10926 }
10927 else
10928 {
10930 return 0;
10931 else if (remote_hw_watchpoint_limit < 0)
10932 return 1;
10933 else if (ot)
10934 return -1;
10935 else if (cnt <= remote_hw_watchpoint_limit)
10936 return 1;
10937 }
10938 return -1;
10939}
10940
10941/* The to_stopped_by_sw_breakpoint method of target remote. */
10943bool
10945{
10946 struct thread_info *thread = inferior_thread ();
10947
10948 return (thread->priv != NULL
10949 && (get_remote_thread_info (thread)->stop_reason
10951}
10952
10953/* The to_supports_stopped_by_sw_breakpoint method of target
10954 remote. */
10960}
10961
10962/* The to_stopped_by_hw_breakpoint method of target remote. */
10964bool
10966{
10967 struct thread_info *thread = inferior_thread ();
10968
10969 return (thread->priv != NULL
10970 && (get_remote_thread_info (thread)->stop_reason
10972}
10973
10974/* The to_supports_stopped_by_hw_breakpoint method of target
10975 remote. */
10981}
10983bool
10985{
10986 struct thread_info *thread = inferior_thread ();
10987
10988 return (thread->priv != NULL
10989 && (get_remote_thread_info (thread)->stop_reason
10991}
10993bool
10994remote_target::stopped_data_address (CORE_ADDR *addr_p)
10995{
10996 struct thread_info *thread = inferior_thread ();
10997
10998 if (thread->priv != NULL
10999 && (get_remote_thread_info (thread)->stop_reason
11001 {
11002 *addr_p = get_remote_thread_info (thread)->watch_data_address;
11003 return true;
11004 }
11005
11006 return false;
11007}
11008
11010int
11012 struct bp_target_info *bp_tgt)
11013{
11014 CORE_ADDR addr = bp_tgt->reqstd_address;
11015 struct remote_state *rs;
11016 char *p, *endbuf;
11017 char *message;
11018
11020 return -1;
11021
11022 /* Make sure the remote is pointing at the right process, if
11023 necessary. */
11026
11027 rs = get_remote_state ();
11028 p = rs->buf.data ();
11029 endbuf = p + get_remote_packet_size ();
11030
11031 *(p++) = 'Z';
11032 *(p++) = '1';
11033 *(p++) = ',';
11034
11035 addr = remote_address_masked (addr);
11036 p += hexnumstr (p, (ULONGEST) addr);
11037 xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
11038
11040 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
11041
11044
11045 putpkt (rs->buf);
11046 getpkt (&rs->buf);
11047
11048 switch (m_features.packet_ok (rs->buf, PACKET_Z1))
11049 {
11050 case PACKET_ERROR:
11051 if (rs->buf[1] == '.')
11052 {
11053 message = strchr (&rs->buf[2], '.');
11054 if (message)
11055 error (_("Remote failure reply: %s"), message + 1);
11056 }
11057 return -1;
11058 case PACKET_UNKNOWN:
11059 return -1;
11060 case PACKET_OK:
11061 return 0;
11062 }
11063 internal_error (_("remote_insert_hw_breakpoint: reached end of function"));
11064}
11065
11067int
11069 struct bp_target_info *bp_tgt)
11070{
11071 CORE_ADDR addr;
11072 struct remote_state *rs = get_remote_state ();
11073 char *p = rs->buf.data ();
11074 char *endbuf = p + get_remote_packet_size ();
11075
11077 return -1;
11078
11079 /* Make sure the remote is pointing at the right process, if
11080 necessary. */
11083
11084 *(p++) = 'z';
11085 *(p++) = '1';
11086 *(p++) = ',';
11087
11088 addr = remote_address_masked (bp_tgt->placed_address);
11089 p += hexnumstr (p, (ULONGEST) addr);
11090 xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
11091
11092 putpkt (rs->buf);
11093 getpkt (&rs->buf);
11094
11095 switch (m_features.packet_ok (rs->buf, PACKET_Z1))
11096 {
11097 case PACKET_ERROR:
11098 case PACKET_UNKNOWN:
11099 return -1;
11100 case PACKET_OK:
11101 return 0;
11102 }
11103 internal_error (_("remote_remove_hw_breakpoint: reached end of function"));
11104}
11105
11106/* Verify memory using the "qCRC:" request. */
11108int
11109remote_target::verify_memory (const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
11110{
11111 struct remote_state *rs = get_remote_state ();
11112 unsigned long host_crc, target_crc;
11113 char *tmp;
11114
11115 /* It doesn't make sense to use qCRC if the remote target is
11116 connected but not running. */
11119 {
11120 enum packet_result result;
11121
11122 /* Make sure the remote is pointing at the right process. */
11124
11125 /* FIXME: assumes lma can fit into long. */
11126 xsnprintf (rs->buf.data (), get_remote_packet_size (), "qCRC:%lx,%lx",
11127 (long) lma, (long) size);
11128 putpkt (rs->buf);
11129
11130 /* Be clever; compute the host_crc before waiting for target
11131 reply. */
11132 host_crc = xcrc32 (data, size, 0xffffffff);
11133
11134 getpkt (&rs->buf);
11135
11136 result = m_features.packet_ok (rs->buf, PACKET_qCRC);
11137 if (result == PACKET_ERROR)
11138 return -1;
11139 else if (result == PACKET_OK)
11140 {
11141 for (target_crc = 0, tmp = &rs->buf[1]; *tmp; tmp++)
11142 target_crc = target_crc * 16 + fromhex (*tmp);
11143
11144 return (host_crc == target_crc);
11145 }
11146 }
11147
11148 return simple_verify_memory (this, data, lma, size);
11149}
11150
11151/* compare-sections command
11152
11153 With no arguments, compares each loadable section in the exec bfd
11154 with the same memory range on the target, and reports mismatches.
11155 Useful for verifying the image on the target against the exec file. */
11157static void
11158compare_sections_command (const char *args, int from_tty)
11159{
11160 asection *s;
11161 const char *sectname;
11162 bfd_size_type size;
11163 bfd_vma lma;
11164 int matched = 0;
11165 int mismatched = 0;
11166 int res;
11167 int read_only = 0;
11168
11170 error (_("command cannot be used without an exec file"));
11171
11172 if (args != NULL && strcmp (args, "-r") == 0)
11173 {
11174 read_only = 1;
11175 args = NULL;
11176 }
11177
11178 for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
11179 {
11180 if (!(s->flags & SEC_LOAD))
11181 continue; /* Skip non-loadable section. */
11182
11183 if (read_only && (s->flags & SEC_READONLY) == 0)
11184 continue; /* Skip writeable sections */
11185
11186 size = bfd_section_size (s);
11187 if (size == 0)
11188 continue; /* Skip zero-length section. */
11189
11190 sectname = bfd_section_name (s);
11191 if (args && strcmp (args, sectname) != 0)
11192 continue; /* Not the section selected by user. */
11193
11194 matched = 1; /* Do this section. */
11195 lma = s->lma;
11196
11197 gdb::byte_vector sectdata (size);
11198 bfd_get_section_contents (current_program_space->exec_bfd (), s,
11199 sectdata.data (), 0, size);
11200
11201 res = target_verify_memory (sectdata.data (), lma, size);
11202
11203 if (res == -1)
11204 error (_("target memory fault, section %s, range %s -- %s"), sectname,
11205 paddress (target_gdbarch (), lma),
11206 paddress (target_gdbarch (), lma + size));
11207
11208 gdb_printf ("Section %s, range %s -- %s: ", sectname,
11209 paddress (target_gdbarch (), lma),
11210 paddress (target_gdbarch (), lma + size));
11211 if (res)
11212 gdb_printf ("matched.\n");
11213 else
11214 {
11215 gdb_printf ("MIS-MATCHED!\n");
11216 mismatched++;
11217 }
11218 }
11219 if (mismatched > 0)
11220 warning (_("One or more sections of the target image does "
11221 "not match the loaded file"));
11222 if (args && !matched)
11223 gdb_printf (_("No loaded section named '%s'.\n"), args);
11224}
11225
11226/* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
11227 into remote target. The number of bytes written to the remote
11228 target is returned, or -1 for error. */
11231remote_target::remote_write_qxfer (const char *object_name,
11232 const char *annex, const gdb_byte *writebuf,
11233 ULONGEST offset, LONGEST len,
11234 ULONGEST *xfered_len,
11235 const unsigned int which_packet)
11236{
11237 int i, buf_len;
11238 ULONGEST n;
11239 struct remote_state *rs = get_remote_state ();
11240 int max_size = get_memory_write_packet_size ();
11241
11242 if (m_features.packet_support (which_packet) == PACKET_DISABLE)
11243 return TARGET_XFER_E_IO;
11244
11245 /* Insert header. */
11246 i = snprintf (rs->buf.data (), max_size,
11247 "qXfer:%s:write:%s:%s:",
11248 object_name, annex ? annex : "",
11249 phex_nz (offset, sizeof offset));
11250 max_size -= (i + 1);
11251
11252 /* Escape as much data as fits into rs->buf. */
11253 buf_len = remote_escape_output
11254 (writebuf, len, 1, (gdb_byte *) rs->buf.data () + i, &max_size, max_size);
11255
11256 if (putpkt_binary (rs->buf.data (), i + buf_len) < 0
11257 || getpkt (&rs->buf) < 0
11258 || m_features.packet_ok (rs->buf, which_packet) != PACKET_OK)
11259 return TARGET_XFER_E_IO;
11260
11261 unpack_varlen_hex (rs->buf.data (), &n);
11262
11263 *xfered_len = n;
11264 return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
11265}
11266
11267/* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
11268 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
11269 number of bytes read is returned, or 0 for EOF, or -1 for error.
11270 The number of bytes read may be less than LEN without indicating an
11271 EOF. PACKET is checked and updated to indicate whether the remote
11272 target supports this object. */
11275remote_target::remote_read_qxfer (const char *object_name,
11276 const char *annex,
11277 gdb_byte *readbuf, ULONGEST offset,
11278 LONGEST len,
11279 ULONGEST *xfered_len,
11280 const unsigned int which_packet)
11281{
11282 struct remote_state *rs = get_remote_state ();
11283 LONGEST i, n, packet_len;
11284
11285 if (m_features.packet_support (which_packet) == PACKET_DISABLE)
11286 return TARGET_XFER_E_IO;
11287
11288 /* Check whether we've cached an end-of-object packet that matches
11289 this request. */
11290 if (rs->finished_object)
11291 {
11292 if (strcmp (object_name, rs->finished_object) == 0
11293 && strcmp (annex ? annex : "", rs->finished_annex) == 0
11294 && offset == rs->finished_offset)
11295 return TARGET_XFER_EOF;
11296
11297
11298 /* Otherwise, we're now reading something different. Discard
11299 the cache. */
11300 xfree (rs->finished_object);
11301 xfree (rs->finished_annex);
11302 rs->finished_object = NULL;
11303 rs->finished_annex = NULL;
11304 }
11305
11306 /* Request only enough to fit in a single packet. The actual data
11307 may not, since we don't know how much of it will need to be escaped;
11308 the target is free to respond with slightly less data. We subtract
11309 five to account for the response type and the protocol frame. */
11310 n = std::min<LONGEST> (get_remote_packet_size () - 5, len);
11311 snprintf (rs->buf.data (), get_remote_packet_size () - 4,
11312 "qXfer:%s:read:%s:%s,%s",
11313 object_name, annex ? annex : "",
11314 phex_nz (offset, sizeof offset),
11315 phex_nz (n, sizeof n));
11316 i = putpkt (rs->buf);
11317 if (i < 0)
11318 return TARGET_XFER_E_IO;
11319
11320 rs->buf[0] = '\0';
11321 packet_len = getpkt (&rs->buf);
11322 if (packet_len < 0
11323 || m_features.packet_ok (rs->buf, which_packet) != PACKET_OK)
11324 return TARGET_XFER_E_IO;
11325
11326 if (rs->buf[0] != 'l' && rs->buf[0] != 'm')
11327 error (_("Unknown remote qXfer reply: %s"), rs->buf.data ());
11328
11329 /* 'm' means there is (or at least might be) more data after this
11330 batch. That does not make sense unless there's at least one byte
11331 of data in this reply. */
11332 if (rs->buf[0] == 'm' && packet_len == 1)
11333 error (_("Remote qXfer reply contained no data."));
11334
11335 /* Got some data. */
11336 i = remote_unescape_input ((gdb_byte *) rs->buf.data () + 1,
11337 packet_len - 1, readbuf, n);
11338
11339 /* 'l' is an EOF marker, possibly including a final block of data,
11340 or possibly empty. If we have the final block of a non-empty
11341 object, record this fact to bypass a subsequent partial read. */
11342 if (rs->buf[0] == 'l' && offset + i > 0)
11343 {
11344 rs->finished_object = xstrdup (object_name);
11345 rs->finished_annex = xstrdup (annex ? annex : "");
11346 rs->finished_offset = offset + i;
11347 }
11348
11349 if (i == 0)
11350 return TARGET_XFER_EOF;
11351 else
11352 {
11353 *xfered_len = i;
11354 return TARGET_XFER_OK;
11355 }
11356}
11360 const char *annex, gdb_byte *readbuf,
11361 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
11362 ULONGEST *xfered_len)
11363{
11364 struct remote_state *rs;
11365 int i;
11366 char *p2;
11367 char query_type;
11369
11372
11373 rs = get_remote_state ();
11374
11375 /* Handle memory using the standard memory routines. */
11376 if (object == TARGET_OBJECT_MEMORY)
11377 {
11378 /* If the remote target is connected but not running, we should
11379 pass this request down to a lower stratum (e.g. the executable
11380 file). */
11381 if (!target_has_execution ())
11382 return TARGET_XFER_EOF;
11383
11384 if (writebuf != NULL)
11385 return remote_write_bytes (offset, writebuf, len, unit_size,
11386 xfered_len);
11387 else
11388 return remote_read_bytes (offset, readbuf, len, unit_size,
11389 xfered_len);
11390 }
11391
11392 /* Handle extra signal info using qxfer packets. */
11393 if (object == TARGET_OBJECT_SIGNAL_INFO)
11394 {
11395 if (readbuf)
11396 return remote_read_qxfer ("siginfo", annex, readbuf, offset, len,
11397 xfered_len, PACKET_qXfer_siginfo_read);
11398 else
11399 return remote_write_qxfer ("siginfo", annex, writebuf, offset, len,
11400 xfered_len, PACKET_qXfer_siginfo_write);
11401 }
11402
11403 if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
11404 {
11405 if (readbuf)
11406 return remote_read_qxfer ("statictrace", annex,
11407 readbuf, offset, len, xfered_len,
11409 else
11410 return TARGET_XFER_E_IO;
11411 }
11412
11413 /* Only handle flash writes. */
11414 if (writebuf != NULL)
11415 {
11416 switch (object)
11417 {
11419 return remote_flash_write (offset, len, xfered_len,
11420 writebuf);
11421
11422 default:
11423 return TARGET_XFER_E_IO;
11424 }
11425 }
11426
11427 /* Map pre-existing objects onto letters. DO NOT do this for new
11428 objects!!! Instead specify new query packets. */
11429 switch (object)
11430 {
11431 case TARGET_OBJECT_AVR:
11432 query_type = 'R';
11433 break;
11434
11435 case TARGET_OBJECT_AUXV:
11436 gdb_assert (annex == NULL);
11437 return remote_read_qxfer
11438 ("auxv", annex, readbuf, offset, len, xfered_len, PACKET_qXfer_auxv);
11439
11441 return remote_read_qxfer
11442 ("features", annex, readbuf, offset, len, xfered_len,
11444
11446 return remote_read_qxfer
11447 ("libraries", annex, readbuf, offset, len, xfered_len,
11449
11451 return remote_read_qxfer
11452 ("libraries-svr4", annex, readbuf, offset, len, xfered_len,
11454
11456 gdb_assert (annex == NULL);
11457 return remote_read_qxfer
11458 ("memory-map", annex, readbuf, offset, len, xfered_len,
11460
11462 /* Should only get here if we're connected. */
11463 gdb_assert (rs->remote_desc);
11464 return remote_read_qxfer
11465 ("osdata", annex, readbuf, offset, len, xfered_len,
11467
11469 gdb_assert (annex == NULL);
11470 return remote_read_qxfer
11471 ("threads", annex, readbuf, offset, len, xfered_len,
11473
11475 gdb_assert (annex == NULL);
11476 return remote_read_qxfer
11477 ("traceframe-info", annex, readbuf, offset, len, xfered_len,
11479
11481 return remote_read_qxfer
11482 ("fdpic", annex, readbuf, offset, len, xfered_len, PACKET_qXfer_fdpic);
11483
11485 return remote_read_qxfer
11486 ("uib", annex, readbuf, offset, len, xfered_len, PACKET_qXfer_uib);
11487
11489 return remote_read_qxfer
11490 ("btrace", annex, readbuf, offset, len, xfered_len,
11492
11494 return remote_read_qxfer
11495 ("btrace-conf", annex, readbuf, offset, len, xfered_len,
11497
11499 return remote_read_qxfer
11500 ("exec-file", annex, readbuf, offset, len, xfered_len,
11502
11503 default:
11504 return TARGET_XFER_E_IO;
11505 }
11506
11507 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
11508 large enough let the caller deal with it. */
11509 if (len < get_remote_packet_size ())
11510 return TARGET_XFER_E_IO;
11511 len = get_remote_packet_size ();
11512
11513 /* Except for querying the minimum buffer size, target must be open. */
11514 if (!rs->remote_desc)
11515 error (_("remote query is only available after target open"));
11516
11517 gdb_assert (annex != NULL);
11518 gdb_assert (readbuf != NULL);
11519
11520 p2 = rs->buf.data ();
11521 *p2++ = 'q';
11522 *p2++ = query_type;
11523
11524 /* We used one buffer char for the remote protocol q command and
11525 another for the query type. As the remote protocol encapsulation
11526 uses 4 chars plus one extra in case we are debugging
11527 (remote_debug), we have PBUFZIZ - 7 left to pack the query
11528 string. */
11529 i = 0;
11530 while (annex[i] && (i < (get_remote_packet_size () - 8)))
11531 {
11532 /* Bad caller may have sent forbidden characters. */
11533 gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
11534 *p2++ = annex[i];
11535 i++;
11536 }
11537 *p2 = '\0';
11538 gdb_assert (annex[i] == '\0');
11539
11540 i = putpkt (rs->buf);
11541 if (i < 0)
11542 return TARGET_XFER_E_IO;
11543
11544 getpkt (&rs->buf);
11545 strcpy ((char *) readbuf, rs->buf.data ());
11546
11547 *xfered_len = strlen ((char *) readbuf);
11548 return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
11549}
11550
11551/* Implementation of to_get_memory_xfer_limit. */
11553ULONGEST
11555{
11557}
11559int
11560remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
11561 const gdb_byte *pattern, ULONGEST pattern_len,
11562 CORE_ADDR *found_addrp)
11563{
11564 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
11565 struct remote_state *rs = get_remote_state ();
11566 int max_size = get_memory_write_packet_size ();
11567
11568 /* Number of packet bytes used to encode the pattern;
11569 this could be more than PATTERN_LEN due to escape characters. */
11570 int escaped_pattern_len;
11571 /* Amount of pattern that was encodable in the packet. */
11572 int used_pattern_len;
11573 int i;
11574 int found;
11575 ULONGEST found_addr;
11576
11577 auto read_memory = [this] (CORE_ADDR addr, gdb_byte *result, size_t len)
11578 {
11579 return (target_read (this, TARGET_OBJECT_MEMORY, NULL, result, addr, len)
11580 == len);
11581 };
11582
11583 /* Don't go to the target if we don't have to. This is done before
11584 checking packet_support to avoid the possibility that a success for this
11585 edge case means the facility works in general. */
11586 if (pattern_len > search_space_len)
11587 return 0;
11588 if (pattern_len == 0)
11589 {
11590 *found_addrp = start_addr;
11591 return 1;
11592 }
11593
11594 /* If we already know the packet isn't supported, fall back to the simple
11595 way of searching memory. */
11596
11598 {
11599 /* Target doesn't provided special support, fall back and use the
11600 standard support (copy memory and do the search here). */
11601 return simple_search_memory (read_memory, start_addr, search_space_len,
11602 pattern, pattern_len, found_addrp);
11603 }
11604
11605 /* Make sure the remote is pointing at the right process. */
11607
11608 /* Insert header. */
11609 i = snprintf (rs->buf.data (), max_size,
11610 "qSearch:memory:%s;%s;",
11611 phex_nz (start_addr, addr_size),
11612 phex_nz (search_space_len, sizeof (search_space_len)));
11613 max_size -= (i + 1);
11614
11615 /* Escape as much data as fits into rs->buf. */
11616 escaped_pattern_len =
11617 remote_escape_output (pattern, pattern_len, 1,
11618 (gdb_byte *) rs->buf.data () + i,
11619 &used_pattern_len, max_size);
11620
11621 /* Bail if the pattern is too large. */
11622 if (used_pattern_len != pattern_len)
11623 error (_("Pattern is too large to transmit to remote target."));
11624
11625 if (putpkt_binary (rs->buf.data (), i + escaped_pattern_len) < 0
11626 || getpkt (&rs->buf) < 0
11628 {
11629 /* The request may not have worked because the command is not
11630 supported. If so, fall back to the simple way. */
11632 {
11633 return simple_search_memory (read_memory, start_addr, search_space_len,
11634 pattern, pattern_len, found_addrp);
11635 }
11636 return -1;
11637 }
11638
11639 if (rs->buf[0] == '0')
11640 found = 0;
11641 else if (rs->buf[0] == '1')
11642 {
11643 found = 1;
11644 if (rs->buf[1] != ',')
11645 error (_("Unknown qSearch:memory reply: %s"), rs->buf.data ());
11646 unpack_varlen_hex (&rs->buf[2], &found_addr);
11647 *found_addrp = found_addr;
11648 }
11649 else
11650 error (_("Unknown qSearch:memory reply: %s"), rs->buf.data ());
11651
11652 return found;
11653}
11655void
11656remote_target::rcmd (const char *command, struct ui_file *outbuf)
11657{
11658 struct remote_state *rs = get_remote_state ();
11659 char *p = rs->buf.data ();
11660
11661 if (!rs->remote_desc)
11662 error (_("remote rcmd is only available after target open"));
11663
11664 /* Send a NULL command across as an empty command. */
11665 if (command == NULL)
11666 command = "";
11667
11668 /* The query prefix. */
11669 strcpy (rs->buf.data (), "qRcmd,");
11670 p = strchr (rs->buf.data (), '\0');
11671
11672 if ((strlen (rs->buf.data ()) + strlen (command) * 2 + 8/*misc*/)
11674 error (_("\"monitor\" command ``%s'' is too long."), command);
11675
11676 /* Encode the actual command. */
11677 bin2hex ((const gdb_byte *) command, p, strlen (command));
11678
11679 if (putpkt (rs->buf) < 0)
11680 error (_("Communication problem with target."));
11681
11682 /* get/display the response */
11683 while (1)
11684 {
11685 char *buf;
11686
11687 /* XXX - see also remote_get_noisy_reply(). */
11688 QUIT; /* Allow user to bail out with ^C. */
11689 rs->buf[0] = '\0';
11690 if (getpkt (&rs->buf) == -1)
11691 {
11692 /* Timeout. Continue to (try to) read responses.
11693 This is better than stopping with an error, assuming the stub
11694 is still executing the (long) monitor command.
11695 If needed, the user can interrupt gdb using C-c, obtaining
11696 an effect similar to stop on timeout. */
11697 continue;
11698 }
11699 buf = rs->buf.data ();
11700 if (buf[0] == '\0')
11701 error (_("Target does not support this command."));
11702 if (buf[0] == 'O' && buf[1] != 'K')
11703 {
11704 remote_console_output (buf + 1); /* 'O' message from stub. */
11705 continue;
11706 }
11707 if (strcmp (buf, "OK") == 0)
11708 break;
11709 if (strlen (buf) == 3 && buf[0] == 'E'
11710 && isxdigit (buf[1]) && isxdigit (buf[2]))
11711 {
11712 error (_("Protocol error with Rcmd"));
11713 }
11714 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
11715 {
11716 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
11717
11718 gdb_putc (c, outbuf);
11719 }
11720 break;
11721 }
11722}
11724std::vector<mem_region>
11726{
11727 std::vector<mem_region> result;
11728 gdb::optional<gdb::char_vector> text
11729 = target_read_stralloc (current_inferior ()->top_target (),
11731
11732 if (text)
11733 result = parse_memory_map (text->data ());
11734
11735 return result;
11736}
11737
11738/* Set of callbacks used to implement the 'maint packet' command. */
11739
11741{
11742 /* Called before the packet is sent. BUF is the packet content before
11743 the protocol specific prefix, suffix, and escaping is added. */
11744
11745 void sending (gdb::array_view<const char> &buf) override
11746 {
11747 gdb_puts ("sending: ");
11748 print_packet (buf);
11749 gdb_puts ("\n");
11750 }
11751
11752 /* Called with BUF, the reply from the remote target. */
11753
11754 void received (gdb::array_view<const char> &buf) override
11755 {
11756 gdb_puts ("received: \"");
11757 print_packet (buf);
11758 gdb_puts ("\"\n");
11759 }
11760
11761private:
11762
11763 /* Print BUF o gdb_stdout. Any non-printable bytes in BUF are printed as
11764 '\x??' with '??' replaced by the hexadecimal value of the byte. */
11766 static void
11767 print_packet (gdb::array_view<const char> &buf)
11768 {
11769 string_file stb;
11770
11771 for (int i = 0; i < buf.size (); ++i)
11772 {
11773 gdb_byte c = buf[i];
11774 if (isprint (c))
11775 gdb_putc (c, &stb);
11776 else
11777 gdb_printf (&stb, "\\x%02x", (unsigned char) c);
11778 }
11779
11780 gdb_puts (stb.string ().c_str ());
11781 }
11782};
11783
11784/* See remote.h. */
11786void
11787send_remote_packet (gdb::array_view<const char> &buf,
11789{
11790 if (buf.size () == 0 || buf.data ()[0] == '\0')
11791 error (_("a remote packet must not be empty"));
11792
11794 if (remote == nullptr)
11795 error (_("packets can only be sent to a remote target"));
11796
11797 callbacks->sending (buf);
11798
11799 remote->putpkt_binary (buf.data (), buf.size ());
11800 remote_state *rs = remote->get_remote_state ();
11801 int bytes = remote->getpkt (&rs->buf);
11802
11803 if (bytes < 0)
11804 error (_("error while fetching packet from remote target"));
11805
11806 gdb::array_view<const char> view (&rs->buf[0], bytes);
11807 callbacks->received (view);
11808}
11809
11810/* Entry point for the 'maint packet' command. */
11812static void
11813cli_packet_command (const char *args, int from_tty)
11814{
11816 gdb::array_view<const char> view
11817 = gdb::make_array_view (args, args == nullptr ? 0 : strlen (args));
11818 send_remote_packet (view, &cb);
11819}
11820
11821#if 0
11822/* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
11823
11824static void display_thread_info (struct gdb_ext_thread_info *info);
11825
11826static void threadset_test_cmd (char *cmd, int tty);
11827
11828static void threadalive_test (char *cmd, int tty);
11829
11830static void threadlist_test_cmd (char *cmd, int tty);
11831
11832int get_and_display_threadinfo (threadref *ref);
11833
11834static void threadinfo_test_cmd (char *cmd, int tty);
11835
11836static int thread_display_step (threadref *ref, void *context);
11837
11838static void threadlist_update_test_cmd (char *cmd, int tty);
11839
11840static void init_remote_threadtests (void);
11841
11842#define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
11843
11844static void
11845threadset_test_cmd (const char *cmd, int tty)
11846{
11847 int sample_thread = SAMPLE_THREAD;
11848
11849 gdb_printf (_("Remote threadset test\n"));
11850 set_general_thread (sample_thread);
11851}
11852
11853
11854static void
11855threadalive_test (const char *cmd, int tty)
11856{
11857 int sample_thread = SAMPLE_THREAD;
11858 int pid = inferior_ptid.pid ();
11859 ptid_t ptid = ptid_t (pid, sample_thread, 0);
11860
11861 if (remote_thread_alive (ptid))
11862 gdb_printf ("PASS: Thread alive test\n");
11863 else
11864 gdb_printf ("FAIL: Thread alive test\n");
11865}
11866
11867void output_threadid (char *title, threadref *ref);
11868
11869void
11870output_threadid (char *title, threadref *ref)
11871{
11872 char hexid[20];
11873
11874 pack_threadid (&hexid[0], ref); /* Convert thread id into hex. */
11875 hexid[16] = 0;
11876 gdb_printf ("%s %s\n", title, (&hexid[0]));
11877}
11878
11879static void
11880threadlist_test_cmd (const char *cmd, int tty)
11881{
11882 int startflag = 1;
11883 threadref nextthread;
11884 int done, result_count;
11885 threadref threadlist[3];
11886
11887 gdb_printf ("Remote Threadlist test\n");
11888 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
11889 &result_count, &threadlist[0]))
11890 gdb_printf ("FAIL: threadlist test\n");
11891 else
11892 {
11893 threadref *scan = threadlist;
11894 threadref *limit = scan + result_count;
11895
11896 while (scan < limit)
11897 output_threadid (" thread ", scan++);
11898 }
11899}
11900
11901void
11902display_thread_info (struct gdb_ext_thread_info *info)
11903{
11904 output_threadid ("Threadid: ", &info->threadid);
11905 gdb_printf ("Name: %s\n ", info->shortname);
11906 gdb_printf ("State: %s\n", info->display);
11907 gdb_printf ("other: %s\n\n", info->more_display);
11908}
11909
11910int
11911get_and_display_threadinfo (threadref *ref)
11912{
11913 int result;
11914 int set;
11915 struct gdb_ext_thread_info threadinfo;
11916
11919 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
11920 display_thread_info (&threadinfo);
11921 return result;
11922}
11923
11924static void
11925threadinfo_test_cmd (const char *cmd, int tty)
11926{
11927 int athread = SAMPLE_THREAD;
11928 threadref thread;
11929 int set;
11930
11931 int_to_threadref (&thread, athread);
11932 gdb_printf ("Remote Threadinfo test\n");
11933 if (!get_and_display_threadinfo (&thread))
11934 gdb_printf ("FAIL cannot get thread info\n");
11935}
11936
11937static int
11938thread_display_step (threadref *ref, void *context)
11939{
11940 /* output_threadid(" threadstep ",ref); *//* simple test */
11941 return get_and_display_threadinfo (ref);
11942}
11943
11944static void
11945threadlist_update_test_cmd (const char *cmd, int tty)
11946{
11947 gdb_printf ("Remote Threadlist update test\n");
11948 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
11949}
11950
11951static void
11952init_remote_threadtests (void)
11953{
11954 add_com ("tlist", class_obscure, threadlist_test_cmd,
11955 _("Fetch and print the remote list of "
11956 "thread identifiers, one pkt only."));
11957 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
11958 _("Fetch and display info about one thread."));
11959 add_com ("tset", class_obscure, threadset_test_cmd,
11960 _("Test setting to a different thread."));
11961 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
11962 _("Iterate through updating all remote thread info."));
11963 add_com ("talive", class_obscure, threadalive_test,
11964 _("Remote thread alive test."));
11965}
11966
11967#endif /* 0 */
11968
11969/* Convert a thread ID to a string. */
11971std::string
11972remote_target::pid_to_str (ptid_t ptid)
11973{
11974 if (ptid == null_ptid)
11975 return normal_pid_to_str (ptid);
11976 else if (ptid.is_pid ())
11977 {
11978 /* Printing an inferior target id. */
11979
11980 /* When multi-process extensions are off, there's no way in the
11981 remote protocol to know the remote process id, if there's any
11982 at all. There's one exception --- when we're connected with
11983 target extended-remote, and we manually attached to a process
11984 with "attach PID". We don't record anywhere a flag that
11985 allows us to distinguish that case from the case of
11986 connecting with extended-remote and the stub already being
11987 attached to a process, and reporting yes to qAttached, hence
11988 no smart special casing here. */
11990 return "Remote target";
11991
11992 return normal_pid_to_str (ptid);
11993 }
11994 else
11995 {
11996 if (magic_null_ptid == ptid)
11997 return "Thread <main>";
11999 if (ptid.lwp () == 0)
12000 return normal_pid_to_str (ptid);
12001 else
12002 return string_printf ("Thread %d.%ld",
12003 ptid.pid (), ptid.lwp ());
12004 else
12005 return string_printf ("Thread %ld", ptid.lwp ());
12006 }
12007}
12008
12009/* Get the address of the thread local variable in OBJFILE which is
12010 stored at OFFSET within the thread local storage for thread PTID. */
12012CORE_ADDR
12013remote_target::get_thread_local_address (ptid_t ptid, CORE_ADDR lm,
12014 CORE_ADDR offset)
12015{
12017 {
12018 struct remote_state *rs = get_remote_state ();
12019 char *p = rs->buf.data ();
12020 char *endp = p + get_remote_packet_size ();
12021 enum packet_result result;
12022
12023 strcpy (p, "qGetTLSAddr:");
12024 p += strlen (p);
12025 p = write_ptid (p, endp, ptid);
12026 *p++ = ',';
12027 p += hexnumstr (p, offset);
12028 *p++ = ',';
12029 p += hexnumstr (p, lm);
12030 *p++ = '\0';
12031
12032 putpkt (rs->buf);
12033 getpkt (&rs->buf);
12035 if (result == PACKET_OK)
12036 {
12037 ULONGEST addr;
12038
12039 unpack_varlen_hex (rs->buf.data (), &addr);
12040 return addr;
12041 }
12042 else if (result == PACKET_UNKNOWN)
12043 throw_error (TLS_GENERIC_ERROR,
12044 _("Remote target doesn't support qGetTLSAddr packet"));
12045 else
12046 throw_error (TLS_GENERIC_ERROR,
12047 _("Remote target failed to process qGetTLSAddr request"));
12048 }
12049 else
12050 throw_error (TLS_GENERIC_ERROR,
12051 _("TLS not supported or disabled on this target"));
12052 /* Not reached. */
12053 return 0;
12054}
12055
12056/* Provide thread local base, i.e. Thread Information Block address.
12057 Returns 1 if ptid is found and thread_local_base is non zero. */
12059bool
12060remote_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
12061{
12063 {
12064 struct remote_state *rs = get_remote_state ();
12065 char *p = rs->buf.data ();
12066 char *endp = p + get_remote_packet_size ();
12067 enum packet_result result;
12068
12069 strcpy (p, "qGetTIBAddr:");
12070 p += strlen (p);
12071 p = write_ptid (p, endp, ptid);
12072 *p++ = '\0';
12073
12074 putpkt (rs->buf);
12075 getpkt (&rs->buf);
12077 if (result == PACKET_OK)
12078 {
12079 ULONGEST val;
12080 unpack_varlen_hex (rs->buf.data (), &val);
12081 if (addr)
12082 *addr = (CORE_ADDR) val;
12083 return true;
12084 }
12085 else if (result == PACKET_UNKNOWN)
12086 error (_("Remote target doesn't support qGetTIBAddr packet"));
12087 else
12088 error (_("Remote target failed to process qGetTIBAddr request"));
12089 }
12090 else
12091 error (_("qGetTIBAddr not supported or disabled on this target"));
12092 /* Not reached. */
12093 return false;
12094}
12095
12096/* Support for inferring a target description based on the current
12097 architecture and the size of a 'g' packet. While the 'g' packet
12098 can have any size (since optional registers can be left off the
12099 end), some sizes are easily recognizable given knowledge of the
12100 approximate architecture. */
12101
12103{
12104 remote_g_packet_guess (int bytes_, const struct target_desc *tdesc_)
12105 : bytes (bytes_),
12106 tdesc (tdesc_)
12107 {
12110 int bytes;
12111 const struct target_desc *tdesc;
12113
12115{
12116 std::vector<remote_g_packet_guess> guesses;
12117};
12122static struct remote_g_packet_data *
12124{
12125 struct remote_g_packet_data *data
12127 if (data == nullptr)
12128 data = remote_g_packet_data_handle.emplace (gdbarch);
12129 return data;
12130}
12132void
12134 const struct target_desc *tdesc)
12135{
12137
12138 gdb_assert (tdesc != NULL);
12139
12140 for (const remote_g_packet_guess &guess : data->guesses)
12141 if (guess.bytes == bytes)
12142 internal_error (_("Duplicate g packet description added for size %d"),
12143 bytes);
12144
12145 data->guesses.emplace_back (bytes, tdesc);
12146}
12147
12148/* Return true if remote_read_description would do anything on this target
12149 and architecture, false otherwise. */
12151static bool
12153{
12155
12156 return !data->guesses.empty ();
12157}
12159const struct target_desc *
12161{
12163
12164 /* Do not try this during initial connection, when we do not know
12165 whether there is a running but stopped thread. */
12166 if (!target_has_execution () || inferior_ptid == null_ptid)
12167 return beneath ()->read_description ();
12168
12169 if (!data->guesses.empty ())
12170 {
12171 int bytes = send_g_packet ();
12172
12173 for (const remote_g_packet_guess &guess : data->guesses)
12174 if (guess.bytes == bytes)
12175 return guess.tdesc;
12176
12177 /* We discard the g packet. A minor optimization would be to
12178 hold on to it, and fill the register cache once we have selected
12179 an architecture, but it's too tricky to do safely. */
12180 }
12181
12182 return beneath ()->read_description ();
12183}
12184
12185/* Remote file transfer support. This is host-initiated I/O, not
12186 target-initiated; for target-initiated, see remote-fileio.c. */
12187
12188/* If *LEFT is at least the length of STRING, copy STRING to
12189 *BUFFER, update *BUFFER to point to the new end of the buffer, and
12190 decrease *LEFT. Otherwise raise an error. */
12192static void
12193remote_buffer_add_string (char **buffer, int *left, const char *string)
12194{
12195 int len = strlen (string);
12196
12197 if (len > *left)
12198 error (_("Packet too long for target."));
12199
12200 memcpy (*buffer, string, len);
12201 *buffer += len;
12202 *left -= len;
12203
12204 /* NUL-terminate the buffer as a convenience, if there is
12205 room. */
12206 if (*left)
12207 **buffer = '\0';
12208}
12209
12210/* If *LEFT is large enough, hex encode LEN bytes from BYTES into
12211 *BUFFER, update *BUFFER to point to the new end of the buffer, and
12212 decrease *LEFT. Otherwise raise an error. */
12214static void
12215remote_buffer_add_bytes (char **buffer, int *left, const gdb_byte *bytes,
12216 int len)
12217{
12218 if (2 * len > *left)
12219 error (_("Packet too long for target."));
12220
12221 bin2hex (bytes, *buffer, len);
12222 *buffer += 2 * len;
12223 *left -= 2 * len;
12224
12225 /* NUL-terminate the buffer as a convenience, if there is
12226 room. */
12227 if (*left)
12228 **buffer = '\0';
12229}
12230
12231/* If *LEFT is large enough, convert VALUE to hex and add it to
12232 *BUFFER, update *BUFFER to point to the new end of the buffer, and
12233 decrease *LEFT. Otherwise raise an error. */
12235static void
12236remote_buffer_add_int (char **buffer, int *left, ULONGEST value)
12237{
12238 int len = hexnumlen (value);
12239
12240 if (len > *left)
12241 error (_("Packet too long for target."));
12242
12243 hexnumstr (*buffer, value);
12244 *buffer += len;
12245 *left -= len;
12246
12247 /* NUL-terminate the buffer as a convenience, if there is
12248 room. */
12249 if (*left)
12250 **buffer = '\0';
12251}
12252
12253/* Parse an I/O result packet from BUFFER. Set RETCODE to the return
12254 value, *REMOTE_ERRNO to the remote error number or FILEIO_SUCCESS if none
12255 was included, and *ATTACHMENT to point to the start of the annex
12256 if any. The length of the packet isn't needed here; there may
12257 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
12258
12259 Return 0 if the packet could be parsed, -1 if it could not. If
12260 -1 is returned, the other variables may not be initialized. */
12262static int
12263remote_hostio_parse_result (const char *buffer, int *retcode,
12264 fileio_error *remote_errno, const char **attachment)
12265{
12266 char *p, *p2;
12267
12268 *remote_errno = FILEIO_SUCCESS;
12269 *attachment = NULL;
12270
12271 if (buffer[0] != 'F')
12272 return -1;
12273
12274 errno = 0;
12275 *retcode = strtol (&buffer[1], &p, 16);
12276 if (errno != 0 || p == &buffer[1])
12277 return -1;
12278
12279 /* Check for ",errno". */
12280 if (*p == ',')
12281 {
12282 errno = 0;
12283 *remote_errno = (fileio_error) strtol (p + 1, &p2, 16);
12284 if (errno != 0 || p + 1 == p2)
12285 return -1;
12286 p = p2;
12287 }
12288
12289 /* Check for ";attachment". If there is no attachment, the
12290 packet should end here. */
12291 if (*p == ';')
12292 {
12293 *attachment = p + 1;
12294 return 0;
12295 }
12296 else if (*p == '\0')
12297 return 0;
12298 else
12299 return -1;
12300}
12301
12302/* Send a prepared I/O packet to the target and read its response.
12303 The prepared packet is in the global RS->BUF before this function
12304 is called, and the answer is there when we return.
12305
12306 COMMAND_BYTES is the length of the request to send, which may include
12307 binary data. WHICH_PACKET is the packet configuration to check
12308 before attempting a packet. If an error occurs, *REMOTE_ERRNO
12309 is set to the error number and -1 is returned. Otherwise the value
12310 returned by the function is returned.
12311
12312 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
12313 attachment is expected; an error will be reported if there's a
12314 mismatch. If one is found, *ATTACHMENT will be set to point into
12315 the packet buffer and *ATTACHMENT_LEN will be set to the
12316 attachment's length. */
12318int
12319remote_target::remote_hostio_send_command (int command_bytes, int which_packet,
12320 fileio_error *remote_errno, const char **attachment,
12321 int *attachment_len)
12322{
12323 struct remote_state *rs = get_remote_state ();
12324 int ret, bytes_read;
12325 const char *attachment_tmp;
12326
12327 if (m_features.packet_support (which_packet) == PACKET_DISABLE)
12328 {
12329 *remote_errno = FILEIO_ENOSYS;
12330 return -1;
12331 }
12332
12333 putpkt_binary (rs->buf.data (), command_bytes);
12334 bytes_read = getpkt (&rs->buf);
12335
12336 /* If it timed out, something is wrong. Don't try to parse the
12337 buffer. */
12338 if (bytes_read < 0)
12339 {
12340 *remote_errno = FILEIO_EINVAL;
12341 return -1;
12342 }
12343
12344 switch (m_features.packet_ok (rs->buf, which_packet))
12345 {
12346 case PACKET_ERROR:
12347 *remote_errno = FILEIO_EINVAL;
12348 return -1;
12349 case PACKET_UNKNOWN:
12350 *remote_errno = FILEIO_ENOSYS;
12351 return -1;
12352 case PACKET_OK:
12353 break;
12354 }
12355
12356 if (remote_hostio_parse_result (rs->buf.data (), &ret, remote_errno,
12357 &attachment_tmp))
12358 {
12359 *remote_errno = FILEIO_EINVAL;
12360 return -1;
12361 }
12362
12363 /* Make sure we saw an attachment if and only if we expected one. */
12364 if ((attachment_tmp == NULL && attachment != NULL)
12365 || (attachment_tmp != NULL && attachment == NULL))
12366 {
12367 *remote_errno = FILEIO_EINVAL;
12368 return -1;
12369 }
12370
12371 /* If an attachment was found, it must point into the packet buffer;
12372 work out how many bytes there were. */
12373 if (attachment_tmp != NULL)
12374 {
12375 *attachment = attachment_tmp;
12376 *attachment_len = bytes_read - (*attachment - rs->buf.data ());
12377 }
12378
12379 return ret;
12380}
12381
12382/* See declaration.h. */
12384void
12386{
12387 this->fd = -1;
12388}
12389
12390/* See declaration.h. */
12392void
12394{
12395 if (this->fd == fd)
12396 this->fd = -1;
12397}
12398
12399/* Set the filesystem remote_hostio functions that take FILENAME
12400 arguments will use. Return 0 on success, or -1 if an error
12401 occurs (and set *REMOTE_ERRNO). */
12403int
12405 fileio_error *remote_errno)
12406{
12407 struct remote_state *rs = get_remote_state ();
12408 int required_pid = (inf == NULL || inf->fake_pid_p) ? 0 : inf->pid;
12409 char *p = rs->buf.data ();
12410 int left = get_remote_packet_size () - 1;
12411 char arg[9];
12412 int ret;
12413
12415 return 0;
12416
12417 if (rs->fs_pid != -1 && required_pid == rs->fs_pid)
12418 return 0;
12419
12420 remote_buffer_add_string (&p, &left, "vFile:setfs:");
12421
12422 xsnprintf (arg, sizeof (arg), "%x", required_pid);
12423 remote_buffer_add_string (&p, &left, arg);
12424
12425 ret = remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_setfs,
12426 remote_errno, NULL, NULL);
12427
12429 return 0;
12430
12431 if (ret == 0)
12432 rs->fs_pid = required_pid;
12433
12434 return ret;
12435}
12436
12437/* Implementation of to_fileio_open. */
12439int
12440remote_target::remote_hostio_open (inferior *inf, const char *filename,
12441 int flags, int mode, int warn_if_slow,
12442 fileio_error *remote_errno)
12443{
12444 struct remote_state *rs = get_remote_state ();
12445 char *p = rs->buf.data ();
12446 int left = get_remote_packet_size () - 1;
12447
12448 if (warn_if_slow)
12449 {
12450 static int warning_issued = 0;
12451
12452 gdb_printf (_("Reading %s from remote target...\n"),
12453 filename);
12454
12455 if (!warning_issued)
12456 {
12457 warning (_("File transfers from remote targets can be slow."
12458 " Use \"set sysroot\" to access files locally"
12459 " instead."));
12460 warning_issued = 1;
12461 }
12462 }
12463
12464 if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
12465 return -1;
12466
12467 remote_buffer_add_string (&p, &left, "vFile:open:");
12468
12469 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
12470 strlen (filename));
12471 remote_buffer_add_string (&p, &left, ",");
12472
12473 remote_buffer_add_int (&p, &left, flags);
12474 remote_buffer_add_string (&p, &left, ",");
12475
12476 remote_buffer_add_int (&p, &left, mode);
12477
12478 return remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_open,
12479 remote_errno, NULL, NULL);
12480}
12482int
12483remote_target::fileio_open (struct inferior *inf, const char *filename,
12484 int flags, int mode, int warn_if_slow,
12485 fileio_error *remote_errno)
12486{
12487 return remote_hostio_open (inf, filename, flags, mode, warn_if_slow,
12488 remote_errno);
12489}
12490
12491/* Implementation of to_fileio_pwrite. */
12493int
12494remote_target::remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len,
12495 ULONGEST offset, fileio_error *remote_errno)
12496{
12497 struct remote_state *rs = get_remote_state ();
12498 char *p = rs->buf.data ();
12499 int left = get_remote_packet_size ();
12500 int out_len;
12501
12503
12504 remote_buffer_add_string (&p, &left, "vFile:pwrite:");
12505
12506 remote_buffer_add_int (&p, &left, fd);
12507 remote_buffer_add_string (&p, &left, ",");
12508
12509 remote_buffer_add_int (&p, &left, offset);
12510 remote_buffer_add_string (&p, &left, ",");
12511
12512 p += remote_escape_output (write_buf, len, 1, (gdb_byte *) p, &out_len,
12514 - (p - rs->buf.data ())));
12515
12516 return remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_pwrite,
12517 remote_errno, NULL, NULL);
12518}
12520int
12521remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
12522 ULONGEST offset, fileio_error *remote_errno)
12523{
12524 return remote_hostio_pwrite (fd, write_buf, len, offset, remote_errno);
12525}
12526
12527/* Helper for the implementation of to_fileio_pread. Read the file
12528 from the remote side with vFile:pread. */
12530int
12531remote_target::remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len,
12532 ULONGEST offset, fileio_error *remote_errno)
12533{
12534 struct remote_state *rs = get_remote_state ();
12535 char *p = rs->buf.data ();
12536 const char *attachment;
12537 int left = get_remote_packet_size ();
12538 int ret, attachment_len;
12539 int read_len;
12540
12541 remote_buffer_add_string (&p, &left, "vFile:pread:");
12542
12543 remote_buffer_add_int (&p, &left, fd);
12544 remote_buffer_add_string (&p, &left, ",");
12545
12546 remote_buffer_add_int (&p, &left, len);
12547 remote_buffer_add_string (&p, &left, ",");
12548
12549 remote_buffer_add_int (&p, &left, offset);
12550
12551 ret = remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_pread,
12552 remote_errno, &attachment,
12553 &attachment_len);
12554
12555 if (ret < 0)
12556 return ret;
12557
12558 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
12559 read_buf, len);
12560 if (read_len != ret)
12561 error (_("Read returned %d, but %d bytes."), ret, (int) read_len);
12562
12563 return ret;
12564}
12565
12566/* See declaration.h. */
12568int
12569readahead_cache::pread (int fd, gdb_byte *read_buf, size_t len,
12570 ULONGEST offset)
12571{
12572 if (this->fd == fd
12573 && this->offset <= offset
12574 && offset < this->offset + this->buf.size ())
12575 {
12576 ULONGEST max = this->offset + this->buf.size ();
12577
12578 if (offset + len > max)
12579 len = max - offset;
12580
12581 memcpy (read_buf, &this->buf[offset - this->offset], len);
12582 return len;
12583 }
12584
12585 return 0;
12586}
12587
12588/* Implementation of to_fileio_pread. */
12590int
12591remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len,
12592 ULONGEST offset, fileio_error *remote_errno)
12593{
12594 int ret;
12595 struct remote_state *rs = get_remote_state ();
12596 readahead_cache *cache = &rs->readahead_cache;
12597
12598 ret = cache->pread (fd, read_buf, len, offset);
12599 if (ret > 0)
12600 {
12601 cache->hit_count++;
12602
12603 remote_debug_printf ("readahead cache hit %s",
12604 pulongest (cache->hit_count));
12605 return ret;
12606 }
12607
12608 cache->miss_count++;
12609
12610 remote_debug_printf ("readahead cache miss %s",
12611 pulongest (cache->miss_count));
12612
12613 cache->fd = fd;
12614 cache->offset = offset;
12615 cache->buf.resize (get_remote_packet_size ());
12616
12617 ret = remote_hostio_pread_vFile (cache->fd, &cache->buf[0],
12618 cache->buf.size (),
12619 cache->offset, remote_errno);
12620 if (ret <= 0)
12621 {
12622 cache->invalidate_fd (fd);
12623 return ret;
12624 }
12625
12626 cache->buf.resize (ret);
12627 return cache->pread (fd, read_buf, len, offset);
12628}
12630int
12631remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len,
12632 ULONGEST offset, fileio_error *remote_errno)
12633{
12634 return remote_hostio_pread (fd, read_buf, len, offset, remote_errno);
12635}
12636
12637/* Implementation of to_fileio_close. */
12639int
12640remote_target::remote_hostio_close (int fd, fileio_error *remote_errno)
12641{
12642 struct remote_state *rs = get_remote_state ();
12643 char *p = rs->buf.data ();
12644 int left = get_remote_packet_size () - 1;
12645
12647
12648 remote_buffer_add_string (&p, &left, "vFile:close:");
12649
12650 remote_buffer_add_int (&p, &left, fd);
12651
12652 return remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_close,
12653 remote_errno, NULL, NULL);
12654}
12656int
12657remote_target::fileio_close (int fd, fileio_error *remote_errno)
12658{
12659 return remote_hostio_close (fd, remote_errno);
12660}
12661
12662/* Implementation of to_fileio_unlink. */
12664int
12665remote_target::remote_hostio_unlink (inferior *inf, const char *filename,
12666 fileio_error *remote_errno)
12667{
12668 struct remote_state *rs = get_remote_state ();
12669 char *p = rs->buf.data ();
12670 int left = get_remote_packet_size () - 1;
12671
12672 if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
12673 return -1;
12674
12675 remote_buffer_add_string (&p, &left, "vFile:unlink:");
12676
12677 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
12678 strlen (filename));
12679
12680 return remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_unlink,
12681 remote_errno, NULL, NULL);
12682}
12684int
12685remote_target::fileio_unlink (struct inferior *inf, const char *filename,
12686 fileio_error *remote_errno)
12687{
12688 return remote_hostio_unlink (inf, filename, remote_errno);
12689}
12690
12691/* Implementation of to_fileio_readlink. */
12693gdb::optional<std::string>
12694remote_target::fileio_readlink (struct inferior *inf, const char *filename,
12695 fileio_error *remote_errno)
12696{
12697 struct remote_state *rs = get_remote_state ();
12698 char *p = rs->buf.data ();
12699 const char *attachment;
12700 int left = get_remote_packet_size ();
12701 int len, attachment_len;
12702 int read_len;
12703
12704 if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
12705 return {};
12706
12707 remote_buffer_add_string (&p, &left, "vFile:readlink:");
12708
12709 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
12710 strlen (filename));
12711
12713 remote_errno, &attachment,
12714 &attachment_len);
12715
12716 if (len < 0)
12717 return {};
12718
12719 std::string ret (len, '\0');
12720
12721 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
12722 (gdb_byte *) &ret[0], len);
12723 if (read_len != len)
12724 error (_("Readlink returned %d, but %d bytes."), len, read_len);
12725
12726 return ret;
12727}
12728
12729/* Implementation of to_fileio_fstat. */
12731int
12732remote_target::fileio_fstat (int fd, struct stat *st, fileio_error *remote_errno)
12733{
12734 struct remote_state *rs = get_remote_state ();
12735 char *p = rs->buf.data ();
12736 int left = get_remote_packet_size ();
12737 int attachment_len, ret;
12738 const char *attachment;
12739 struct fio_stat fst;
12740 int read_len;
12741
12742 remote_buffer_add_string (&p, &left, "vFile:fstat:");
12743
12744 remote_buffer_add_int (&p, &left, fd);
12745
12746 ret = remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_fstat,
12747 remote_errno, &attachment,
12748 &attachment_len);
12749 if (ret < 0)
12750 {
12751 if (*remote_errno != FILEIO_ENOSYS)
12752 return ret;
12753
12754 /* Strictly we should return -1, ENOSYS here, but when
12755 "set sysroot remote:" was implemented in August 2008
12756 BFD's need for a stat function was sidestepped with
12757 this hack. This was not remedied until March 2015
12758 so we retain the previous behavior to avoid breaking
12759 compatibility.
12760
12761 Note that the memset is a March 2015 addition; older
12762 GDBs set st_size *and nothing else* so the structure
12763 would have garbage in all other fields. This might
12764 break something but retaining the previous behavior
12765 here would be just too wrong. */
12766
12767 memset (st, 0, sizeof (struct stat));
12768 st->st_size = INT_MAX;
12769 return 0;
12770 }
12771
12772 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
12773 (gdb_byte *) &fst, sizeof (fst));
12774
12775 if (read_len != ret)
12776 error (_("vFile:fstat returned %d, but %d bytes."), ret, read_len);
12777
12778 if (read_len != sizeof (fst))
12779 error (_("vFile:fstat returned %d bytes, but expecting %d."),
12780 read_len, (int) sizeof (fst));
12781
12782 remote_fileio_to_host_stat (&fst, st);
12783
12784 return 0;
12785}
12786
12787/* Implementation of to_filesystem_is_local. */
12789bool
12791{
12792 /* Valgrind GDB presents itself as a remote target but works
12793 on the local filesystem: it does not implement remote get
12794 and users are not expected to set a sysroot. To handle
12795 this case we treat the remote filesystem as local if the
12796 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
12797 does not support vFile:open. */
12799 {
12801
12802 if (ps == PACKET_SUPPORT_UNKNOWN)
12803 {
12804 int fd;
12805 fileio_error remote_errno;
12806
12807 /* Try opening a file to probe support. The supplied
12808 filename is irrelevant, we only care about whether
12809 the stub recognizes the packet or not. */
12810 fd = remote_hostio_open (NULL, "just probing",
12811 FILEIO_O_RDONLY, 0700, 0,
12812 &remote_errno);
12813
12814 if (fd >= 0)
12815 remote_hostio_close (fd, &remote_errno);
12816
12818 }
12819
12820 if (ps == PACKET_DISABLE)
12821 {
12822 static int warning_issued = 0;
12823
12824 if (!warning_issued)
12825 {
12826 warning (_("remote target does not support file"
12827 " transfer, attempting to access files"
12828 " from local filesystem."));
12829 warning_issued = 1;
12830 }
12831
12832 return true;
12833 }
12834 }
12835
12836 return false;
12837}
12839static char *
12840remote_hostio_error (fileio_error errnum)
12841{
12842 int host_error = fileio_error_to_host (errnum);
12843
12844 if (host_error == -1)
12845 error (_("Unknown remote I/O error %d"), errnum);
12846 else
12847 error (_("Remote I/O error: %s"), safe_strerror (host_error));
12848}
12849
12850/* A RAII wrapper around a remote file descriptor. */
12851
12852class scoped_remote_fd
12854public:
12855 scoped_remote_fd (remote_target *remote, int fd)
12856 : m_remote (remote), m_fd (fd)
12857 {
12859
12861 {
12862 if (m_fd != -1)
12863 {
12864 try
12865 {
12866 fileio_error remote_errno;
12867 m_remote->remote_hostio_close (m_fd, &remote_errno);
12868 }
12869 catch (...)
12870 {
12871 /* Swallow exception before it escapes the dtor. If
12872 something goes wrong, likely the connection is gone,
12873 and there's nothing else that can be done. */
12874 }
12875 }
12877
12880 /* Release ownership of the file descriptor, and return it. */
12881 ATTRIBUTE_UNUSED_RESULT int release () noexcept
12882 {
12883 int fd = m_fd;
12884 m_fd = -1;
12885 return fd;
12886 }
12888 /* Return the owned file descriptor. */
12889 int get () const noexcept
12890 {
12891 return m_fd;
12892 }
12893
12894private:
12895 /* The remote target. */
12898 /* The owned remote I/O file descriptor. */
12899 int m_fd;
12900};
12902void
12903remote_file_put (const char *local_file, const char *remote_file, int from_tty)
12904{
12906
12907 if (remote == nullptr)
12908 error (_("command can only be used with remote target"));
12909
12910 remote->remote_file_put (local_file, remote_file, from_tty);
12911}
12913void
12914remote_target::remote_file_put (const char *local_file, const char *remote_file,
12915 int from_tty)
12916{
12917 int retcode, bytes, io_size;
12918 fileio_error remote_errno;
12919 int bytes_in_buffer;
12920 int saw_eof;
12921 ULONGEST offset;
12922
12923 gdb_file_up file = gdb_fopen_cloexec (local_file, "rb");
12924 if (file == NULL)
12925 perror_with_name (local_file);
12926
12928 (this, remote_hostio_open (NULL,
12929 remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
12930 | FILEIO_O_TRUNC),
12931 0700, 0, &remote_errno));
12932 if (fd.get () == -1)
12933 remote_hostio_error (remote_errno);
12934
12935 /* Send up to this many bytes at once. They won't all fit in the
12936 remote packet limit, so we'll transfer slightly fewer. */
12937 io_size = get_remote_packet_size ();
12938 gdb::byte_vector buffer (io_size);
12939
12940 bytes_in_buffer = 0;
12941 saw_eof = 0;
12942 offset = 0;
12943 while (bytes_in_buffer || !saw_eof)
12944 {
12945 if (!saw_eof)
12946 {
12947 bytes = fread (buffer.data () + bytes_in_buffer, 1,
12948 io_size - bytes_in_buffer,
12949 file.get ());
12950 if (bytes == 0)
12951 {
12952 if (ferror (file.get ()))
12953 error (_("Error reading %s."), local_file);
12954 else
12955 {
12956 /* EOF. Unless there is something still in the
12957 buffer from the last iteration, we are done. */
12958 saw_eof = 1;
12959 if (bytes_in_buffer == 0)
12960 break;
12961 }
12962 }
12963 }
12964 else
12965 bytes = 0;
12966
12967 bytes += bytes_in_buffer;
12968 bytes_in_buffer = 0;
12969
12970 retcode = remote_hostio_pwrite (fd.get (), buffer.data (), bytes,
12971 offset, &remote_errno);
12972
12973 if (retcode < 0)
12974 remote_hostio_error (remote_errno);
12975 else if (retcode == 0)
12976 error (_("Remote write of %d bytes returned 0!"), bytes);
12977 else if (retcode < bytes)
12978 {
12979 /* Short write. Save the rest of the read data for the next
12980 write. */
12981 bytes_in_buffer = bytes - retcode;
12982 memmove (buffer.data (), buffer.data () + retcode, bytes_in_buffer);
12983 }
12984
12985 offset += retcode;
12986 }
12987
12988 if (remote_hostio_close (fd.release (), &remote_errno))
12989 remote_hostio_error (remote_errno);
12990
12991 if (from_tty)
12992 gdb_printf (_("Successfully sent file \"%s\".\n"), local_file);
12993}
12995void
12996remote_file_get (const char *remote_file, const char *local_file, int from_tty)
12997{
12999
13000 if (remote == nullptr)
13001 error (_("command can only be used with remote target"));
13002
13003 remote->remote_file_get (remote_file, local_file, from_tty);
13004}
13006void
13007remote_target::remote_file_get (const char *remote_file, const char *local_file,
13008 int from_tty)
13009{
13010 fileio_error remote_errno;
13011 int bytes, io_size;
13012 ULONGEST offset;
13013
13015 (this, remote_hostio_open (NULL,
13016 remote_file, FILEIO_O_RDONLY, 0, 0,
13017 &remote_errno));
13018 if (fd.get () == -1)
13019 remote_hostio_error (remote_errno);
13020
13021 gdb_file_up file = gdb_fopen_cloexec (local_file, "wb");
13022 if (file == NULL)
13023 perror_with_name (local_file);
13024
13025 /* Send up to this many bytes at once. They won't all fit in the
13026 remote packet limit, so we'll transfer slightly fewer. */
13027 io_size = get_remote_packet_size ();
13028 gdb::byte_vector buffer (io_size);
13029
13030 offset = 0;
13031 while (1)
13032 {
13033 bytes = remote_hostio_pread (fd.get (), buffer.data (), io_size, offset,
13034 &remote_errno);
13035 if (bytes == 0)
13036 /* Success, but no bytes, means end-of-file. */
13037 break;
13038 if (bytes == -1)
13039 remote_hostio_error (remote_errno);
13040
13041 offset += bytes;
13042
13043 bytes = fwrite (buffer.data (), 1, bytes, file.get ());
13044 if (bytes == 0)
13045 perror_with_name (local_file);
13046 }
13047
13048 if (remote_hostio_close (fd.release (), &remote_errno))
13049 remote_hostio_error (remote_errno);
13050
13051 if (from_tty)
13052 gdb_printf (_("Successfully fetched file \"%s\".\n"), remote_file);
13053}
13055void
13056remote_file_delete (const char *remote_file, int from_tty)
13057{
13059
13060 if (remote == nullptr)
13061 error (_("command can only be used with remote target"));
13062
13063 remote->remote_file_delete (remote_file, from_tty);
13064}
13066void
13067remote_target::remote_file_delete (const char *remote_file, int from_tty)
13068{
13069 int retcode;
13070 fileio_error remote_errno;
13071
13072 retcode = remote_hostio_unlink (NULL, remote_file, &remote_errno);
13073 if (retcode == -1)
13074 remote_hostio_error (remote_errno);
13075
13076 if (from_tty)
13077 gdb_printf (_("Successfully deleted file \"%s\".\n"), remote_file);
13078}
13080static void
13081remote_put_command (const char *args, int from_tty)
13082{
13083 if (args == NULL)
13084 error_no_arg (_("file to put"));
13085
13086 gdb_argv argv (args);
13087 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
13088 error (_("Invalid parameters to remote put"));
13089
13090 remote_file_put (argv[0], argv[1], from_tty);
13091}
13093static void
13094remote_get_command (const char *args, int from_tty)
13095{
13096 if (args == NULL)
13097 error_no_arg (_("file to get"));
13098
13099 gdb_argv argv (args);
13100 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
13101 error (_("Invalid parameters to remote get"));
13102
13103 remote_file_get (argv[0], argv[1], from_tty);
13104}
13106static void
13107remote_delete_command (const char *args, int from_tty)
13108{
13109 if (args == NULL)
13110 error_no_arg (_("file to delete"));
13111
13112 gdb_argv argv (args);
13113 if (argv[0] == NULL || argv[1] != NULL)
13114 error (_("Invalid parameters to remote delete"));
13115
13116 remote_file_delete (argv[0], from_tty);
13117}
13119bool
13121{
13124 return true;
13125 else
13126 return false;
13127}
13129bool
13131{
13132 return true;
13133}
13135bool
13137{
13138 /* Only supported in extended mode. */
13139 return false;
13140}
13142bool
13144{
13146}
13152 == PACKET_ENABLE);
13153}
13159 == PACKET_ENABLE);
13160}
13166}
13172}
13178}
13184 == PACKET_ENABLE);
13185}
13191}
13197}
13199void
13201{
13202 struct remote_state *rs = get_remote_state ();
13203
13204 putpkt ("QTinit");
13206 if (strcmp (rs->buf.data (), "OK") != 0)
13207 error (_("Target does not support this command."));
13208}
13209
13210/* Recursive routine to walk through command list including loops, and
13211 download packets for each command. */
13213void
13214remote_target::remote_download_command_source (int num, ULONGEST addr,
13215 struct command_line *cmds)
13216{
13217 struct remote_state *rs = get_remote_state ();
13218 struct command_line *cmd;
13219
13220 for (cmd = cmds; cmd; cmd = cmd->next)
13221 {
13222 QUIT; /* Allow user to bail out with ^C. */
13223 strcpy (rs->buf.data (), "QTDPsrc:");
13224 encode_source_string (num, addr, "cmd", cmd->line,
13225 rs->buf.data () + strlen (rs->buf.data ()),
13226 rs->buf.size () - strlen (rs->buf.data ()));
13227 putpkt (rs->buf);
13229 if (strcmp (rs->buf.data (), "OK"))
13230 warning (_("Target does not support source download."));
13231
13232 if (cmd->control_type == while_control
13234 {
13235 remote_download_command_source (num, addr, cmd->body_list_0.get ());
13236
13237 QUIT; /* Allow user to bail out with ^C. */
13238 strcpy (rs->buf.data (), "QTDPsrc:");
13239 encode_source_string (num, addr, "cmd", "end",
13240 rs->buf.data () + strlen (rs->buf.data ()),
13241 rs->buf.size () - strlen (rs->buf.data ()));
13242 putpkt (rs->buf);
13244 if (strcmp (rs->buf.data (), "OK"))
13245 warning (_("Target does not support source download."));
13246 }
13247 }
13248}
13250void
13252{
13253 CORE_ADDR tpaddr;
13254 char addrbuf[40];
13255 std::vector<std::string> tdp_actions;
13256 std::vector<std::string> stepping_actions;
13257 char *pkt;
13258 struct breakpoint *b = loc->owner;
13259 tracepoint *t = gdb::checked_static_cast<tracepoint *> (b);
13260 struct remote_state *rs = get_remote_state ();
13261 int ret;
13262 const char *err_msg = _("Tracepoint packet too large for target.");
13263 size_t size_left;
13264
13265 /* We use a buffer other than rs->buf because we'll build strings
13266 across multiple statements, and other statements in between could
13267 modify rs->buf. */
13268 gdb::char_vector buf (get_remote_packet_size ());
13269
13270 encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
13271
13272 tpaddr = loc->address;
13273 strcpy (addrbuf, phex (tpaddr, sizeof (CORE_ADDR)));
13274 ret = snprintf (buf.data (), buf.size (), "QTDP:%x:%s:%c:%lx:%x",
13275 b->number, addrbuf, /* address */
13276 (b->enable_state == bp_enabled ? 'E' : 'D'),
13277 t->step_count, t->pass_count);
13278
13279 if (ret < 0 || ret >= buf.size ())
13280 error ("%s", err_msg);
13281
13282 /* Fast tracepoints are mostly handled by the target, but we can
13283 tell the target how big of an instruction block should be moved
13284 around. */
13285 if (b->type == bp_fast_tracepoint)
13286 {
13287 /* Only test for support at download time; we may not know
13288 target capabilities at definition time. */
13290 {
13291 if (gdbarch_fast_tracepoint_valid_at (loc->gdbarch, tpaddr,
13292 NULL))
13293 {
13294 size_left = buf.size () - strlen (buf.data ());
13295 ret = snprintf (buf.data () + strlen (buf.data ()),
13296 size_left, ":F%x",
13297 gdb_insn_length (loc->gdbarch, tpaddr));
13298
13299 if (ret < 0 || ret >= size_left)
13300 error ("%s", err_msg);
13301 }
13302 else
13303 /* If it passed validation at definition but fails now,
13304 something is very wrong. */
13305 internal_error (_("Fast tracepoint not valid during download"));
13306 }
13307 else
13308 /* Fast tracepoints are functionally identical to regular
13309 tracepoints, so don't take lack of support as a reason to
13310 give up on the trace run. */
13311 warning (_("Target does not support fast tracepoints, "
13312 "downloading %d as regular tracepoint"), b->number);
13313 }
13314 else if (b->type == bp_static_tracepoint
13316 {
13317 /* Only test for support at download time; we may not know
13318 target capabilities at definition time. */
13320 {
13321 struct static_tracepoint_marker marker;
13322
13323 if (target_static_tracepoint_marker_at (tpaddr, &marker))
13324 {
13325 size_left = buf.size () - strlen (buf.data ());
13326 ret = snprintf (buf.data () + strlen (buf.data ()),
13327 size_left, ":S");
13328
13329 if (ret < 0 || ret >= size_left)
13330 error ("%s", err_msg);
13331 }
13332 else
13333 error (_("Static tracepoint not valid during download"));
13334 }
13335 else
13336 /* Fast tracepoints are functionally identical to regular
13337 tracepoints, so don't take lack of support as a reason
13338 to give up on the trace run. */
13339 error (_("Target does not support static tracepoints"));
13340 }
13341 /* If the tracepoint has a conditional, make it into an agent
13342 expression and append to the definition. */
13343 if (loc->cond)
13344 {
13345 /* Only test support at download time, we may not know target
13346 capabilities at definition time. */
13348 {
13349 agent_expr_up aexpr = gen_eval_for_expr (tpaddr,
13350 loc->cond.get ());
13351
13352 size_left = buf.size () - strlen (buf.data ());
13353
13354 ret = snprintf (buf.data () + strlen (buf.data ()),
13355 size_left, ":X%x,", (int) aexpr->buf.size ());
13356
13357 if (ret < 0 || ret >= size_left)
13358 error ("%s", err_msg);
13359
13360 size_left = buf.size () - strlen (buf.data ());
13361
13362 /* Two bytes to encode each aexpr byte, plus the terminating
13363 null byte. */
13364 if (aexpr->buf.size () * 2 + 1 > size_left)
13365 error ("%s", err_msg);
13366
13367 pkt = buf.data () + strlen (buf.data ());
13368
13369 for (int ndx = 0; ndx < aexpr->buf.size (); ++ndx)
13370 pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
13371 *pkt = '\0';
13372 }
13373 else
13374 warning (_("Target does not support conditional tracepoints, "
13375 "ignoring tp %d cond"), b->number);
13376 }
13377
13378 if (b->commands || !default_collect.empty ())
13379 {
13380 size_left = buf.size () - strlen (buf.data ());
13381
13382 ret = snprintf (buf.data () + strlen (buf.data ()),
13383 size_left, "-");
13384
13385 if (ret < 0 || ret >= size_left)
13386 error ("%s", err_msg);
13387 }
13388
13389 putpkt (buf.data ());
13391 if (strcmp (rs->buf.data (), "OK"))
13392 error (_("Target does not support tracepoints."));
13393
13394 /* do_single_steps (t); */
13395 for (auto action_it = tdp_actions.begin ();
13396 action_it != tdp_actions.end (); action_it++)
13397 {
13398 QUIT; /* Allow user to bail out with ^C. */
13399
13400 bool has_more = ((action_it + 1) != tdp_actions.end ()
13401 || !stepping_actions.empty ());
13402
13403 ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%c",
13404 b->number, addrbuf, /* address */
13405 action_it->c_str (),
13406 has_more ? '-' : 0);
13407
13408 if (ret < 0 || ret >= buf.size ())
13409 error ("%s", err_msg);
13410
13411 putpkt (buf.data ());
13413 if (strcmp (rs->buf.data (), "OK"))
13414 error (_("Error on target while setting tracepoints."));
13415 }
13416
13417 for (auto action_it = stepping_actions.begin ();
13418 action_it != stepping_actions.end (); action_it++)
13419 {
13420 QUIT; /* Allow user to bail out with ^C. */
13421
13422 bool is_first = action_it == stepping_actions.begin ();
13423 bool has_more = (action_it + 1) != stepping_actions.end ();
13424
13425 ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%s%s",
13426 b->number, addrbuf, /* address */
13427 is_first ? "S" : "",
13428 action_it->c_str (),
13429 has_more ? "-" : "");
13430
13431 if (ret < 0 || ret >= buf.size ())
13432 error ("%s", err_msg);
13433
13434 putpkt (buf.data ());
13436 if (strcmp (rs->buf.data (), "OK"))
13437 error (_("Error on target while setting tracepoints."));
13438 }
13439
13441 {
13442 if (b->locspec != nullptr)
13443 {
13444 ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
13445
13446 if (ret < 0 || ret >= buf.size ())
13447 error ("%s", err_msg);
13448
13449 const char *str = b->locspec->to_string ();
13450 encode_source_string (b->number, loc->address, "at", str,
13451 buf.data () + strlen (buf.data ()),
13452 buf.size () - strlen (buf.data ()));
13453 putpkt (buf.data ());
13455 if (strcmp (rs->buf.data (), "OK"))
13456 warning (_("Target does not support source download."));
13457 }
13458 if (b->cond_string)
13459 {
13460 ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
13461
13462 if (ret < 0 || ret >= buf.size ())
13463 error ("%s", err_msg);
13464
13465 encode_source_string (b->number, loc->address,
13466 "cond", b->cond_string.get (),
13467 buf.data () + strlen (buf.data ()),
13468 buf.size () - strlen (buf.data ()));
13469 putpkt (buf.data ());
13471 if (strcmp (rs->buf.data (), "OK"))
13472 warning (_("Target does not support source download."));
13473 }
13476 }
13477}
13479bool
13481{
13482 struct remote_state *rs = get_remote_state ();
13483 struct trace_status *ts;
13484 int status;
13485
13486 /* Don't try to install tracepoints until we've relocated our
13487 symbols, and fetched and merged the target's tracepoint list with
13488 ours. */
13489 if (rs->starting_up)
13490 return false;
13491
13492 ts = current_trace_status ();
13493 status = get_trace_status (ts);
13494
13495 if (status == -1 || !ts->running_known || !ts->running)
13496 return false;
13497
13498 /* If we are in a tracing experiment, but remote stub doesn't support
13499 installing tracepoint in trace, we have to return. */
13501 return false;
13502
13503 return true;
13504}
13505
13507void
13509{
13510 struct remote_state *rs = get_remote_state ();
13511 char *p;
13512
13513 xsnprintf (rs->buf.data (), get_remote_packet_size (), "QTDV:%x:%s:%x:",
13514 tsv.number, phex ((ULONGEST) tsv.initial_value, 8),
13515 tsv.builtin);
13516 p = rs->buf.data () + strlen (rs->buf.data ());
13517 if ((p - rs->buf.data ()) + tsv.name.length () * 2
13519 error (_("Trace state variable name too long for tsv definition packet"));
13520 p += 2 * bin2hex ((gdb_byte *) (tsv.name.data ()), p, tsv.name.length ());
13521 *p++ = '\0';
13522 putpkt (rs->buf);
13524 if (rs->buf[0] == '\0')
13525 error (_("Target does not support this command."));
13526 if (strcmp (rs->buf.data (), "OK") != 0)
13527 error (_("Error on target while downloading trace state variable."));
13528}
13530void
13532{
13533 struct remote_state *rs = get_remote_state ();
13534
13535 xsnprintf (rs->buf.data (), get_remote_packet_size (), "QTEnable:%x:%s",
13536 location->owner->number,
13537 phex (location->address, sizeof (CORE_ADDR)));
13538 putpkt (rs->buf);
13540 if (rs->buf[0] == '\0')
13541 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
13542 if (strcmp (rs->buf.data (), "OK") != 0)
13543 error (_("Error on target while enabling tracepoint."));
13544}
13546void
13548{
13549 struct remote_state *rs = get_remote_state ();
13550
13551 xsnprintf (rs->buf.data (), get_remote_packet_size (), "QTDisable:%x:%s",
13552 location->owner->number,
13553 phex (location->address, sizeof (CORE_ADDR)));
13554 putpkt (rs->buf);
13556 if (rs->buf[0] == '\0')
13557 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
13558 if (strcmp (rs->buf.data (), "OK") != 0)
13559 error (_("Error on target while disabling tracepoint."));
13560}
13562void
13564{
13565 asection *s;
13566 bfd_size_type size;
13567 bfd_vma vma;
13568 int anysecs = 0;
13569 int offset = 0;
13570 bfd *abfd = current_program_space->exec_bfd ();
13571
13572 if (!abfd)
13573 return; /* No information to give. */
13574
13575 struct remote_state *rs = get_remote_state ();
13576
13577 strcpy (rs->buf.data (), "QTro");
13578 offset = strlen (rs->buf.data ());
13579 for (s = abfd->sections; s; s = s->next)
13580 {
13581 char tmp1[40], tmp2[40];
13582 int sec_length;
13583
13584 if ((s->flags & SEC_LOAD) == 0
13585 /* || (s->flags & SEC_CODE) == 0 */
13586 || (s->flags & SEC_READONLY) == 0)
13587 continue;
13588
13589 anysecs = 1;
13590 vma = bfd_section_vma (s);
13591 size = bfd_section_size (s);
13592 bfd_sprintf_vma (abfd, tmp1, vma);
13593 bfd_sprintf_vma (abfd, tmp2, vma + size);
13594 sec_length = 1 + strlen (tmp1) + 1 + strlen (tmp2);
13595 if (offset + sec_length + 1 > rs->buf.size ())
13596 {
13598 != PACKET_ENABLE)
13599 warning (_("\
13600Too many sections for read-only sections definition packet."));
13601 break;
13602 }
13603 xsnprintf (rs->buf.data () + offset, rs->buf.size () - offset, ":%s,%s",
13604 tmp1, tmp2);
13605 offset += sec_length;
13606 }
13607 if (anysecs)
13608 {
13609 putpkt (rs->buf);
13610 getpkt (&rs->buf);
13611 }
13612}
13614void
13616{
13617 struct remote_state *rs = get_remote_state ();
13618
13619 putpkt ("QTStart");
13621 if (rs->buf[0] == '\0')
13622 error (_("Target does not support this command."));
13623 if (strcmp (rs->buf.data (), "OK") != 0)
13624 error (_("Bogus reply from target: %s"), rs->buf.data ());
13625}
13627int
13629{
13630 /* Initialize it just to avoid a GCC false warning. */
13631 char *p = NULL;
13632 enum packet_result result;
13633 struct remote_state *rs = get_remote_state ();
13634
13636 return -1;
13637
13638 /* FIXME we need to get register block size some other way. */
13641
13642 putpkt ("qTStatus");
13643
13644 try
13645 {
13647 }
13648 catch (const gdb_exception_error &ex)
13649 {
13650 if (ex.error != TARGET_CLOSE_ERROR)
13651 {
13652 exception_fprintf (gdb_stderr, ex, "qTStatus: ");
13653 return -1;
13654 }
13655 throw;
13656 }
13657
13658 result = m_features.packet_ok (p, PACKET_qTStatus);
13659
13660 /* If the remote target doesn't do tracing, flag it. */
13661 if (result == PACKET_UNKNOWN)
13662 return -1;
13663
13664 /* We're working with a live target. */
13665 ts->filename = NULL;
13666
13667 if (*p++ != 'T')
13668 error (_("Bogus trace status reply from target: %s"), rs->buf.data ());
13669
13670 /* Function 'parse_trace_status' sets default value of each field of
13671 'ts' at first, so we don't have to do it here. */
13672 parse_trace_status (p, ts);
13673
13674 return ts->running;
13675}
13677void
13679 struct uploaded_tp *utp)
13680{
13681 struct remote_state *rs = get_remote_state ();
13682 char *reply;
13683 size_t size = get_remote_packet_size ();
13684
13685 if (tp)
13686 {
13687 tp->hit_count = 0;
13688 tp->traceframe_usage = 0;
13689 for (bp_location &loc : tp->locations ())
13690 {
13691 /* If the tracepoint was never downloaded, don't go asking for
13692 any status. */
13693 if (tp->number_on_target == 0)
13694 continue;
13695 xsnprintf (rs->buf.data (), size, "qTP:%x:%s", tp->number_on_target,
13696 phex_nz (loc.address, 0));
13697 putpkt (rs->buf);
13698 reply = remote_get_noisy_reply ();
13699 if (reply && *reply)
13700 {
13701 if (*reply == 'V')
13702 parse_tracepoint_status (reply + 1, tp, utp);
13703 }
13704 }
13705 }
13706 else if (utp)
13707 {
13708 utp->hit_count = 0;
13709 utp->traceframe_usage = 0;
13710 xsnprintf (rs->buf.data (), size, "qTP:%x:%s", utp->number,
13711 phex_nz (utp->addr, 0));
13712 putpkt (rs->buf);
13713 reply = remote_get_noisy_reply ();
13714 if (reply && *reply)
13715 {
13716 if (*reply == 'V')
13717 parse_tracepoint_status (reply + 1, tp, utp);
13718 }
13719 }
13720}
13722void
13724{
13725 struct remote_state *rs = get_remote_state ();
13726
13727 putpkt ("QTStop");
13729 if (rs->buf[0] == '\0')
13730 error (_("Target does not support this command."));
13731 if (strcmp (rs->buf.data (), "OK") != 0)
13732 error (_("Bogus reply from target: %s"), rs->buf.data ());
13733}
13735int
13737 CORE_ADDR addr1, CORE_ADDR addr2,
13738 int *tpp)
13739{
13740 struct remote_state *rs = get_remote_state ();
13741 char *endbuf = rs->buf.data () + get_remote_packet_size ();
13742 char *p, *reply;
13743 int target_frameno = -1, target_tracept = -1;
13744
13745 /* Lookups other than by absolute frame number depend on the current
13746 trace selected, so make sure it is correct on the remote end
13747 first. */
13748 if (type != tfind_number)
13750
13751 p = rs->buf.data ();
13752 strcpy (p, "QTFrame:");
13753 p = strchr (p, '\0');
13754 switch (type)
13755 {
13756 case tfind_number:
13757 xsnprintf (p, endbuf - p, "%x", num);
13758 break;
13759 case tfind_pc:
13760 xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
13761 break;
13762 case tfind_tp:
13763 xsnprintf (p, endbuf - p, "tdp:%x", num);
13764 break;
13765 case tfind_range:
13766 xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
13767 phex_nz (addr2, 0));
13768 break;
13769 case tfind_outside:
13770 xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
13771 phex_nz (addr2, 0));
13772 break;
13773 default:
13774 error (_("Unknown trace find type %d"), type);
13775 }
13776
13777 putpkt (rs->buf);
13778 reply = remote_get_noisy_reply ();
13779 if (*reply == '\0')
13780 error (_("Target does not support this command."));
13781
13782 while (reply && *reply)
13783 switch (*reply)
13784 {
13785 case 'F':
13786 p = ++reply;
13787 target_frameno = (int) strtol (p, &reply, 16);
13788 if (reply == p)
13789 error (_("Unable to parse trace frame number"));
13790 /* Don't update our remote traceframe number cache on failure
13791 to select a remote traceframe. */
13792 if (target_frameno == -1)
13793 return -1;
13794 break;
13795 case 'T':
13796 p = ++reply;
13797 target_tracept = (int) strtol (p, &reply, 16);
13798 if (reply == p)
13799 error (_("Unable to parse tracepoint number"));
13800 break;
13801 case 'O': /* "OK"? */
13802 if (reply[1] == 'K' && reply[2] == '\0')
13803 reply += 2;
13804 else
13805 error (_("Bogus reply from target: %s"), reply);
13806 break;
13807 default:
13808 error (_("Bogus reply from target: %s"), reply);
13809 }
13810 if (tpp)
13811 *tpp = target_tracept;
13812
13813 rs->remote_traceframe_number = target_frameno;
13814 return target_frameno;
13815}
13817bool
13818remote_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
13819{
13820 struct remote_state *rs = get_remote_state ();
13821 char *reply;
13822 ULONGEST uval;
13823
13825
13826 xsnprintf (rs->buf.data (), get_remote_packet_size (), "qTV:%x", tsvnum);
13827 putpkt (rs->buf);
13828 reply = remote_get_noisy_reply ();
13829 if (reply && *reply)
13830 {
13831 if (*reply == 'V')
13832 {
13833 unpack_varlen_hex (reply + 1, &uval);
13834 *val = (LONGEST) uval;
13835 return true;
13836 }
13837 }
13838 return false;
13839}
13841int
13842remote_target::save_trace_data (const char *filename)
13843{
13844 struct remote_state *rs = get_remote_state ();
13845 char *p, *reply;
13846
13847 p = rs->buf.data ();
13848 strcpy (p, "QTSave:");
13849 p += strlen (p);
13850 if ((p - rs->buf.data ()) + strlen (filename) * 2
13852 error (_("Remote file name too long for trace save packet"));
13853 p += 2 * bin2hex ((gdb_byte *) filename, p, strlen (filename));
13854 *p++ = '\0';
13855 putpkt (rs->buf);
13856 reply = remote_get_noisy_reply ();
13857 if (*reply == '\0')
13858 error (_("Target does not support this command."));
13859 if (strcmp (reply, "OK") != 0)
13860 error (_("Bogus reply from target: %s"), reply);
13861 return 0;
13862}
13863
13864/* This is basically a memory transfer, but needs to be its own packet
13865 because we don't know how the target actually organizes its trace
13866 memory, plus we want to be able to ask for as much as possible, but
13867 not be unhappy if we don't get as much as we ask for. */
13869LONGEST
13870remote_target::get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
13871{
13872 struct remote_state *rs = get_remote_state ();
13873 char *reply;
13874 char *p;
13875 int rslt;
13876
13877 p = rs->buf.data ();
13878 strcpy (p, "qTBuffer:");
13879 p += strlen (p);
13880 p += hexnumstr (p, offset);
13881 *p++ = ',';
13882 p += hexnumstr (p, len);
13883 *p++ = '\0';
13884
13885 putpkt (rs->buf);
13886 reply = remote_get_noisy_reply ();
13887 if (reply && *reply)
13888 {
13889 /* 'l' by itself means we're at the end of the buffer and
13890 there is nothing more to get. */
13891 if (*reply == 'l')
13892 return 0;
13893
13894 /* Convert the reply into binary. Limit the number of bytes to
13895 convert according to our passed-in buffer size, rather than
13896 what was returned in the packet; if the target is
13897 unexpectedly generous and gives us a bigger reply than we
13898 asked for, we don't want to crash. */
13899 rslt = hex2bin (reply, buf, len);
13900 return rslt;
13901 }
13902
13903 /* Something went wrong, flag as an error. */
13904 return -1;
13905}
13907void
13909{
13910 struct remote_state *rs = get_remote_state ();
13911
13913 == PACKET_ENABLE)
13914 {
13915 char *reply;
13916
13917 xsnprintf (rs->buf.data (), get_remote_packet_size (),
13918 "QTDisconnected:%x", val);
13919 putpkt (rs->buf);
13920 reply = remote_get_noisy_reply ();
13921 if (*reply == '\0')
13922 error (_("Target does not support this command."));
13923 if (strcmp (reply, "OK") != 0)
13924 error (_("Bogus reply from target: %s"), reply);
13925 }
13926 else if (val)
13927 warning (_("Target does not support disconnected tracing."));
13928}
13930int
13932{
13933 thread_info *info = this->find_thread (ptid);
13934
13935 if (info != NULL && info->priv != NULL)
13937
13938 return -1;
13939}
13941void
13943{
13944 struct remote_state *rs = get_remote_state ();
13945 char *reply;
13946
13947 xsnprintf (rs->buf.data (), get_remote_packet_size (),
13948 "QTBuffer:circular:%x", val);
13949 putpkt (rs->buf);
13950 reply = remote_get_noisy_reply ();
13951 if (*reply == '\0')
13952 error (_("Target does not support this command."));
13953 if (strcmp (reply, "OK") != 0)
13954 error (_("Bogus reply from target: %s"), reply);
13955}
13959{
13960 gdb::optional<gdb::char_vector> text
13961 = target_read_stralloc (current_inferior ()->top_target (),
13963 NULL);
13964 if (text)
13965 return parse_traceframe_info (text->data ());
13966
13967 return NULL;
13968}
13969
13970/* Handle the qTMinFTPILen packet. Returns the minimum length of
13971 instruction on which a fast tracepoint may be placed. Returns -1
13972 if the packet is not supported, and 0 if the minimum instruction
13973 length is unknown. */
13975int
13977{
13978 struct remote_state *rs = get_remote_state ();
13979 char *reply;
13980
13981 /* If we're not debugging a process yet, the IPA can't be
13982 loaded. */
13983 if (!target_has_execution ())
13984 return 0;
13985
13986 /* Make sure the remote is pointing at the right process. */
13988
13989 xsnprintf (rs->buf.data (), get_remote_packet_size (), "qTMinFTPILen");
13990 putpkt (rs->buf);
13991 reply = remote_get_noisy_reply ();
13992 if (*reply == '\0')
13993 return -1;
13994 else
13995 {
13996 ULONGEST min_insn_len;
13997
13998 unpack_varlen_hex (reply, &min_insn_len);
13999
14000 return (int) min_insn_len;
14001 }
14002}
14004void
14006{
14008 {
14009 struct remote_state *rs = get_remote_state ();
14010 char *buf = rs->buf.data ();
14011 char *endbuf = buf + get_remote_packet_size ();
14012 enum packet_result result;
14013
14014 gdb_assert (val >= 0 || val == -1);
14015 buf += xsnprintf (buf, endbuf - buf, "QTBuffer:size:");
14016 /* Send -1 as literal "-1" to avoid host size dependency. */
14017 if (val < 0)
14018 {
14019 *buf++ = '-';
14020 buf += hexnumstr (buf, (ULONGEST) -val);
14021 }
14022 else
14023 buf += hexnumstr (buf, (ULONGEST) val);
14024
14025 putpkt (rs->buf);
14028
14029 if (result != PACKET_OK)
14030 warning (_("Bogus reply from target: %s"), rs->buf.data ());
14031 }
14032}
14034bool
14035remote_target::set_trace_notes (const char *user, const char *notes,
14036 const char *stop_notes)
14037{
14038 struct remote_state *rs = get_remote_state ();
14039 char *reply;
14040 char *buf = rs->buf.data ();
14041 char *endbuf = buf + get_remote_packet_size ();
14042 int nbytes;
14043
14044 buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
14045 if (user)
14046 {
14047 buf += xsnprintf (buf, endbuf - buf, "user:");
14048 nbytes = bin2hex ((gdb_byte *) user, buf, strlen (user));
14049 buf += 2 * nbytes;
14050 *buf++ = ';';
14051 }
14052 if (notes)
14053 {
14054 buf += xsnprintf (buf, endbuf - buf, "notes:");
14055 nbytes = bin2hex ((gdb_byte *) notes, buf, strlen (notes));
14056 buf += 2 * nbytes;
14057 *buf++ = ';';
14058 }
14059 if (stop_notes)
14060 {
14061 buf += xsnprintf (buf, endbuf - buf, "tstop:");
14062 nbytes = bin2hex ((gdb_byte *) stop_notes, buf, strlen (stop_notes));
14063 buf += 2 * nbytes;
14064 *buf++ = ';';
14065 }
14066 /* Ensure the buffer is terminated. */
14067 *buf = '\0';
14068
14069 putpkt (rs->buf);
14070 reply = remote_get_noisy_reply ();
14071 if (*reply == '\0')
14072 return false;
14073
14074 if (strcmp (reply, "OK") != 0)
14075 error (_("Bogus reply from target: %s"), reply);
14076
14077 return true;
14078}
14080bool
14081remote_target::use_agent (bool use)
14082{
14084 {
14085 struct remote_state *rs = get_remote_state ();
14086
14087 /* If the stub supports QAgent. */
14088 xsnprintf (rs->buf.data (), get_remote_packet_size (), "QAgent:%d", use);
14089 putpkt (rs->buf);
14090 getpkt (&rs->buf);
14091
14092 if (strcmp (rs->buf.data (), "OK") == 0)
14093 {
14094 ::use_agent = use;
14095 return true;
14096 }
14097 }
14098
14099 return false;
14100}
14102bool
14104{
14106}
14107
14108#if defined (HAVE_LIBEXPAT)
14109
14110/* Check the btrace document version. */
14111
14112static void
14113check_xml_btrace_version (struct gdb_xml_parser *parser,
14114 const struct gdb_xml_element *element,
14115 void *user_data,
14116 std::vector<gdb_xml_value> &attributes)
14117{
14118 const char *version
14119 = (const char *) xml_find_attribute (attributes, "version")->value.get ();
14120
14121 if (strcmp (version, "1.0") != 0)
14122 gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version);
14123}
14124
14125/* Parse a btrace "block" xml record. */
14126
14127static void
14128parse_xml_btrace_block (struct gdb_xml_parser *parser,
14129 const struct gdb_xml_element *element,
14130 void *user_data,
14131 std::vector<gdb_xml_value> &attributes)
14132{
14133 struct btrace_data *btrace;
14134 ULONGEST *begin, *end;
14135
14136 btrace = (struct btrace_data *) user_data;
14137
14138 switch (btrace->format)
14139 {
14140 case BTRACE_FORMAT_BTS:
14141 break;
14142
14143 case BTRACE_FORMAT_NONE:
14144 btrace->format = BTRACE_FORMAT_BTS;
14145 btrace->variant.bts.blocks = new std::vector<btrace_block>;
14146 break;
14147
14148 default:
14149 gdb_xml_error (parser, _("Btrace format error."));
14150 }
14151
14152 begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
14153 end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
14154 btrace->variant.bts.blocks->emplace_back (*begin, *end);
14155}
14156
14157/* Parse a "raw" xml record. */
14158
14159static void
14160parse_xml_raw (struct gdb_xml_parser *parser, const char *body_text,
14161 gdb_byte **pdata, size_t *psize)
14162{
14163 gdb_byte *bin;
14164 size_t len, size;
14165
14166 len = strlen (body_text);
14167 if (len % 2 != 0)
14168 gdb_xml_error (parser, _("Bad raw data size."));
14169
14170 size = len / 2;
14171
14172 gdb::unique_xmalloc_ptr<gdb_byte> data ((gdb_byte *) xmalloc (size));
14173 bin = data.get ();
14174
14175 /* We use hex encoding - see gdbsupport/rsp-low.h. */
14176 while (len > 0)
14177 {
14178 char hi, lo;
14179
14180 hi = *body_text++;
14181 lo = *body_text++;
14182
14183 if (hi == 0 || lo == 0)
14184 gdb_xml_error (parser, _("Bad hex encoding."));
14185
14186 *bin++ = fromhex (hi) * 16 + fromhex (lo);
14187 len -= 2;
14188 }
14189
14190 *pdata = data.release ();
14191 *psize = size;
14192}
14193
14194/* Parse a btrace pt-config "cpu" xml record. */
14195
14196static void
14197parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser *parser,
14198 const struct gdb_xml_element *element,
14199 void *user_data,
14200 std::vector<gdb_xml_value> &attributes)
14201{
14202 struct btrace_data *btrace;
14203 const char *vendor;
14204 ULONGEST *family, *model, *stepping;
14205
14206 vendor
14207 = (const char *) xml_find_attribute (attributes, "vendor")->value.get ();
14208 family
14209 = (ULONGEST *) xml_find_attribute (attributes, "family")->value.get ();
14210 model
14211 = (ULONGEST *) xml_find_attribute (attributes, "model")->value.get ();
14212 stepping
14213 = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value.get ();
14214
14215 btrace = (struct btrace_data *) user_data;
14216
14217 if (strcmp (vendor, "GenuineIntel") == 0)
14218 btrace->variant.pt.config.cpu.vendor = CV_INTEL;
14219
14220 btrace->variant.pt.config.cpu.family = *family;
14221 btrace->variant.pt.config.cpu.model = *model;
14222 btrace->variant.pt.config.cpu.stepping = *stepping;
14223}
14224
14225/* Parse a btrace pt "raw" xml record. */
14226
14227static void
14228parse_xml_btrace_pt_raw (struct gdb_xml_parser *parser,
14229 const struct gdb_xml_element *element,
14230 void *user_data, const char *body_text)
14231{
14232 struct btrace_data *btrace;
14233
14234 btrace = (struct btrace_data *) user_data;
14235 parse_xml_raw (parser, body_text, &btrace->variant.pt.data,
14236 &btrace->variant.pt.size);
14237}
14238
14239/* Parse a btrace "pt" xml record. */
14240
14241static void
14242parse_xml_btrace_pt (struct gdb_xml_parser *parser,
14243 const struct gdb_xml_element *element,
14244 void *user_data,
14245 std::vector<gdb_xml_value> &attributes)
14246{
14247 struct btrace_data *btrace;
14248
14249 btrace = (struct btrace_data *) user_data;
14250 btrace->format = BTRACE_FORMAT_PT;
14251 btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN;
14252 btrace->variant.pt.data = NULL;
14253 btrace->variant.pt.size = 0;
14254}
14255
14256static const struct gdb_xml_attribute block_attributes[] = {
14257 { "begin", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
14259 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14260};
14261
14262static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes[] = {
14263 { "vendor", GDB_XML_AF_NONE, NULL, NULL },
14264 { "family", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
14265 { "model", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
14266 { "stepping", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
14267 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14268};
14269
14270static const struct gdb_xml_element btrace_pt_config_children[] = {
14271 { "cpu", btrace_pt_config_cpu_attributes, NULL, GDB_XML_EF_OPTIONAL,
14272 parse_xml_btrace_pt_config_cpu, NULL },
14273 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14274};
14275
14276static const struct gdb_xml_element btrace_pt_children[] = {
14277 { "pt-config", NULL, btrace_pt_config_children, GDB_XML_EF_OPTIONAL, NULL,
14278 NULL },
14279 { "raw", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, parse_xml_btrace_pt_raw },
14280 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14281};
14282
14283static const struct gdb_xml_attribute btrace_attributes[] = {
14284 { "version", GDB_XML_AF_NONE, NULL, NULL },
14285 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14286};
14287
14288static const struct gdb_xml_element btrace_children[] = {
14289 { "block", block_attributes, NULL,
14290 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, parse_xml_btrace_block, NULL },
14291 { "pt", NULL, btrace_pt_children, GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt,
14292 NULL },
14293 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14294};
14295
14296static const struct gdb_xml_element btrace_elements[] = {
14297 { "btrace", btrace_attributes, btrace_children, GDB_XML_EF_NONE,
14298 check_xml_btrace_version, NULL },
14299 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14300};
14301
14302#endif /* defined (HAVE_LIBEXPAT) */
14303
14304/* Parse a branch trace xml document XML into DATA. */
14306static void
14307parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
14308{
14309#if defined (HAVE_LIBEXPAT)
14310
14311 int errcode;
14312 btrace_data result;
14313 result.format = BTRACE_FORMAT_NONE;
14314
14315 errcode = gdb_xml_parse_quick (_("btrace"), "btrace.dtd", btrace_elements,
14316 buffer, &result);
14317 if (errcode != 0)
14318 error (_("Error parsing branch trace."));
14319
14320 /* Keep parse results. */
14321 *btrace = std::move (result);
14322
14323#else /* !defined (HAVE_LIBEXPAT) */
14324
14325 error (_("Cannot process branch trace. XML support was disabled at "
14326 "compile time."));
14327
14328#endif /* !defined (HAVE_LIBEXPAT) */
14329}
14330
14331#if defined (HAVE_LIBEXPAT)
14332
14333/* Parse a btrace-conf "bts" xml record. */
14334
14335static void
14336parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
14337 const struct gdb_xml_element *element,
14338 void *user_data,
14339 std::vector<gdb_xml_value> &attributes)
14340{
14341 struct btrace_config *conf;
14342 struct gdb_xml_value *size;
14343
14344 conf = (struct btrace_config *) user_data;
14345 conf->format = BTRACE_FORMAT_BTS;
14346 conf->bts.size = 0;
14347
14349 if (size != NULL)
14350 conf->bts.size = (unsigned int) *(ULONGEST *) size->value.get ();
14351}
14352
14353/* Parse a btrace-conf "pt" xml record. */
14354
14355static void
14356parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
14357 const struct gdb_xml_element *element,
14358 void *user_data,
14359 std::vector<gdb_xml_value> &attributes)
14360{
14361 struct btrace_config *conf;
14362 struct gdb_xml_value *size;
14363
14364 conf = (struct btrace_config *) user_data;
14365 conf->format = BTRACE_FORMAT_PT;
14366 conf->pt.size = 0;
14367
14369 if (size != NULL)
14370 conf->pt.size = (unsigned int) *(ULONGEST *) size->value.get ();
14371}
14372
14373static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = {
14375 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14376};
14377
14378static const struct gdb_xml_attribute btrace_conf_bts_attributes[] = {
14380 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14381};
14382
14383static const struct gdb_xml_element btrace_conf_children[] = {
14384 { "bts", btrace_conf_bts_attributes, NULL, GDB_XML_EF_OPTIONAL,
14385 parse_xml_btrace_conf_bts, NULL },
14386 { "pt", btrace_conf_pt_attributes, NULL, GDB_XML_EF_OPTIONAL,
14387 parse_xml_btrace_conf_pt, NULL },
14388 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14389};
14390
14391static const struct gdb_xml_attribute btrace_conf_attributes[] = {
14392 { "version", GDB_XML_AF_NONE, NULL, NULL },
14393 { NULL, GDB_XML_AF_NONE, NULL, NULL }
14394};
14395
14396static const struct gdb_xml_element btrace_conf_elements[] = {
14397 { "btrace-conf", btrace_conf_attributes, btrace_conf_children,
14398 GDB_XML_EF_NONE, NULL, NULL },
14399 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
14400};
14401
14402#endif /* defined (HAVE_LIBEXPAT) */
14403
14404/* Parse a branch trace configuration xml document XML into CONF. */
14406static void
14407parse_xml_btrace_conf (struct btrace_config *conf, const char *xml)
14408{
14409#if defined (HAVE_LIBEXPAT)
14410
14411 int errcode;
14412 errcode = gdb_xml_parse_quick (_("btrace-conf"), "btrace-conf.dtd",
14413 btrace_conf_elements, xml, conf);
14414 if (errcode != 0)
14415 error (_("Error parsing branch trace configuration."));
14416
14417#else /* !defined (HAVE_LIBEXPAT) */
14418
14419 error (_("Cannot process the branch trace configuration. XML support "
14420 "was disabled at compile time."));
14421
14422#endif /* !defined (HAVE_LIBEXPAT) */
14423}
14424
14425/* Reset our idea of our target's btrace configuration. */
14427static void
14429{
14430 memset (&rs->btrace_config, 0, sizeof (rs->btrace_config));
14431}
14432
14433/* Synchronize the configuration with the target. */
14435void
14436remote_target::btrace_sync_conf (const btrace_config *conf)
14437{
14438 struct remote_state *rs;
14439 char *buf, *pos, *endbuf;
14440
14441 rs = get_remote_state ();
14442 buf = rs->buf.data ();
14443 endbuf = buf + get_remote_packet_size ();
14444
14446 && conf->bts.size != rs->btrace_config.bts.size)
14447 {
14448 pos = buf;
14449 pos += xsnprintf (pos, endbuf - pos, "%s=0x%x",
14451 conf->bts.size);
14452
14453 putpkt (buf);
14454 getpkt (&rs->buf);
14455
14457 == PACKET_ERROR)
14458 {
14459 if (buf[0] == 'E' && buf[1] == '.')
14460 error (_("Failed to configure the BTS buffer size: %s"), buf + 2);
14461 else
14462 error (_("Failed to configure the BTS buffer size."));
14463 }
14464
14465 rs->btrace_config.bts.size = conf->bts.size;
14466 }
14467
14469 && conf->pt.size != rs->btrace_config.pt.size)
14470 {
14471 pos = buf;
14472 pos += xsnprintf (pos, endbuf - pos, "%s=0x%x",
14474 conf->pt.size);
14475
14476 putpkt (buf);
14477 getpkt (&rs->buf);
14478
14480 == PACKET_ERROR)
14481 {
14482 if (buf[0] == 'E' && buf[1] == '.')
14483 error (_("Failed to configure the trace buffer size: %s"), buf + 2);
14484 else
14485 error (_("Failed to configure the trace buffer size."));
14486 }
14487
14488 rs->btrace_config.pt.size = conf->pt.size;
14489 }
14490}
14491
14492/* Read TP's btrace configuration from the target and store it into CONF. */
14494static void
14495btrace_read_config (thread_info *tp, btrace_config *conf)
14496{
14497 /* target_read_stralloc relies on INFERIOR_PTID. */
14498 scoped_restore_current_thread restore_thread;
14499 switch_to_thread (tp);
14500
14501 gdb::optional<gdb::char_vector> xml
14502 = target_read_stralloc (current_inferior ()->top_target (),
14504 if (xml)
14505 parse_xml_btrace_conf (conf, xml->data ());
14506}
14507
14508/* Maybe reopen target btrace. */
14510void
14512{
14513 struct remote_state *rs = get_remote_state ();
14514 int btrace_target_pushed = 0;
14515#if !defined (HAVE_LIBIPT)
14516 int warned = 0;
14517#endif
14518
14519 /* Don't bother walking the entirety of the remote thread list when
14520 we know the feature isn't supported by the remote. */
14522 return;
14523
14524 for (thread_info *tp : all_non_exited_threads (this))
14525 {
14526 memset (&rs->btrace_config, 0x00, sizeof (struct btrace_config));
14528
14529 if (rs->btrace_config.format == BTRACE_FORMAT_NONE)
14530 continue;
14531
14532#if !defined (HAVE_LIBIPT)
14533 if (rs->btrace_config.format == BTRACE_FORMAT_PT)
14534 {
14535 if (!warned)
14536 {
14537 warned = 1;
14538 warning (_("Target is recording using Intel Processor Trace "
14539 "but support was disabled at compile time."));
14540 }
14541
14542 continue;
14543 }
14544#endif /* !defined (HAVE_LIBIPT) */
14545
14546 /* Push target, once, but before anything else happens. This way our
14547 changes to the threads will be cleaned up by unpushing the target
14548 in case btrace_read_config () throws. */
14549 if (!btrace_target_pushed)
14550 {
14551 btrace_target_pushed = 1;
14553 gdb_printf (_("Target is recording using %s.\n"),
14554 btrace_format_string (rs->btrace_config.format));
14555 }
14556
14557 tp->btrace.target
14558 = new btrace_target_info { tp->ptid, rs->btrace_config };
14559 }
14560}
14561
14562/* Enable branch tracing. */
14564struct btrace_target_info *
14566 const struct btrace_config *conf)
14567{
14568 struct packet_config *packet = NULL;
14569 struct remote_state *rs = get_remote_state ();
14570 char *buf = rs->buf.data ();
14571 char *endbuf = buf + get_remote_packet_size ();
14572
14573 unsigned int which_packet;
14574 switch (conf->format)
14575 {
14576 case BTRACE_FORMAT_BTS:
14577 which_packet = PACKET_Qbtrace_bts;
14578 break;
14579 case BTRACE_FORMAT_PT:
14580 which_packet = PACKET_Qbtrace_pt;
14581 break;
14582 default:
14583 internal_error (_("Bad branch btrace format: %u."),
14584 (unsigned int) conf->format);
14585 }
14586
14587 packet = &m_features.m_protocol_packets[which_packet];
14588 if (packet == NULL || packet_config_support (packet) != PACKET_ENABLE)
14589 error (_("Target does not support branch tracing."));
14590
14591 btrace_sync_conf (conf);
14592
14593 ptid_t ptid = tp->ptid;
14594 set_general_thread (ptid);
14595
14596 buf += xsnprintf (buf, endbuf - buf, "%s",
14597 packets_descriptions[which_packet].name);
14598 putpkt (rs->buf);
14599 getpkt (&rs->buf);
14600
14601 if (m_features.packet_ok (rs->buf, which_packet) == PACKET_ERROR)
14602 {
14603 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
14604 error (_("Could not enable branch tracing for %s: %s"),
14605 target_pid_to_str (ptid).c_str (), &rs->buf[2]);
14606 else
14607 error (_("Could not enable branch tracing for %s."),
14608 target_pid_to_str (ptid).c_str ());
14609 }
14610
14611 btrace_target_info *tinfo = new btrace_target_info { ptid };
14612
14613 /* If we fail to read the configuration, we lose some information, but the
14614 tracing itself is not impacted. */
14615 try
14616 {
14617 btrace_read_config (tp, &tinfo->conf);
14618 }
14619 catch (const gdb_exception_error &err)
14620 {
14621 if (err.message != NULL)
14622 warning ("%s", err.what ());
14623 }
14624
14625 return tinfo;
14626}
14627
14628/* Disable branch tracing. */
14630void
14631remote_target::disable_btrace (struct btrace_target_info *tinfo)
14632{
14633 struct remote_state *rs = get_remote_state ();
14634 char *buf = rs->buf.data ();
14635 char *endbuf = buf + get_remote_packet_size ();
14636
14638 error (_("Target does not support branch tracing."));
14639
14640 set_general_thread (tinfo->ptid);
14641
14642 buf += xsnprintf (buf, endbuf - buf, "%s",
14644 putpkt (rs->buf);
14645 getpkt (&rs->buf);
14646
14648 {
14649 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
14650 error (_("Could not disable branch tracing for %s: %s"),
14651 target_pid_to_str (tinfo->ptid).c_str (), &rs->buf[2]);
14652 else
14653 error (_("Could not disable branch tracing for %s."),
14654 target_pid_to_str (tinfo->ptid).c_str ());
14655 }
14656
14657 delete tinfo;
14658}
14659
14660/* Teardown branch tracing. */
14662void
14663remote_target::teardown_btrace (struct btrace_target_info *tinfo)
14664{
14665 /* We must not talk to the target during teardown. */
14666 delete tinfo;
14667}
14668
14669/* Read the branch trace. */
14671enum btrace_error
14672remote_target::read_btrace (struct btrace_data *btrace,
14673 struct btrace_target_info *tinfo,
14674 enum btrace_read_type type)
14675{
14676 const char *annex;
14677
14679 error (_("Target does not support branch tracing."));
14680
14681#if !defined(HAVE_LIBEXPAT)
14682 error (_("Cannot process branch tracing result. XML parsing not supported."));
14683#endif
14684
14685 switch (type)
14686 {
14687 case BTRACE_READ_ALL:
14688 annex = "all";
14689 break;
14690 case BTRACE_READ_NEW:
14691 annex = "new";
14692 break;
14693 case BTRACE_READ_DELTA:
14694 annex = "delta";
14695 break;
14696 default:
14697 internal_error (_("Bad branch tracing read type: %u."),
14698 (unsigned int) type);
14699 }
14700
14701 gdb::optional<gdb::char_vector> xml
14702 = target_read_stralloc (current_inferior ()->top_target (),
14703 TARGET_OBJECT_BTRACE, annex);
14704 if (!xml)
14705 return BTRACE_ERR_UNKNOWN;
14706
14707 parse_xml_btrace (btrace, xml->data ());
14708
14709 return BTRACE_ERR_NONE;
14710}
14712const struct btrace_config *
14713remote_target::btrace_conf (const struct btrace_target_info *tinfo)
14714{
14715 return &tinfo->conf;
14716}
14723 == PACKET_ENABLE);
14724}
14725
14726/* Implementation of to_load. */
14728void
14729remote_target::load (const char *name, int from_tty)
14730{
14731 generic_load (name, from_tty);
14732}
14733
14734/* Accepts an integer PID; returns a string representing a file that
14735 can be opened on the remote side to get the symbols for the child
14736 process. Returns NULL if the operation is not supported. */
14738const char *
14740{
14741 static gdb::optional<gdb::char_vector> filename;
14742 char *annex = NULL;
14743
14745 return NULL;
14746
14747 inferior *inf = find_inferior_pid (this, pid);
14748 if (inf == NULL)
14749 internal_error (_("not currently attached to process %d"), pid);
14750
14751 if (!inf->fake_pid_p)
14752 {
14753 const int annex_size = 9;
14754
14755 annex = (char *) alloca (annex_size);
14756 xsnprintf (annex, annex_size, "%x", pid);
14757 }
14758
14759 filename = target_read_stralloc (current_inferior ()->top_target (),
14761
14762 return filename ? filename->data () : nullptr;
14763}
14764
14765/* Implement the to_can_do_single_step target_ops method. */
14767int
14769{
14770 /* We can only tell whether target supports single step or not by
14771 supported s and S vCont actions if the stub supports vContSupported
14772 feature. If the stub doesn't support vContSupported feature,
14773 we have conservatively to think target doesn't supports single
14774 step. */
14776 {
14777 struct remote_state *rs = get_remote_state ();
14778
14779 return rs->supports_vCont.s && rs->supports_vCont.S;
14780 }
14781 else
14782 return 0;
14783}
14784
14785/* Implementation of the to_execution_direction method for the remote
14786 target. */
14790{
14791 struct remote_state *rs = get_remote_state ();
14792
14793 return rs->last_resume_exec_dir;
14794}
14795
14796/* Return pointer to the thread_info struct which corresponds to
14797 THREAD_HANDLE (having length HANDLE_LEN). */
14800remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
14801 int handle_len,
14802 inferior *inf)
14803{
14804 for (thread_info *tp : all_non_exited_threads (this))
14805 {
14807
14808 if (tp->inf == inf && priv != NULL)
14809 {
14810 if (handle_len != priv->thread_handle.size ())
14811 error (_("Thread handle size mismatch: %d vs %zu (from remote)"),
14812 handle_len, priv->thread_handle.size ());
14813 if (memcmp (thread_handle, priv->thread_handle.data (),
14814 handle_len) == 0)
14815 return tp;
14816 }
14817 }
14818
14819 return NULL;
14820}
14822gdb::array_view<const gdb_byte>
14824{
14826 return priv->thread_handle;
14827}
14829bool
14831{
14832 /* This flag should be checked in the common target.c code. */
14833 gdb_assert (target_async_permitted);
14834
14835 /* We're async whenever the serial device can. */
14836 struct remote_state *rs = get_remote_state ();
14837 return serial_can_async_p (rs->remote_desc);
14838}
14840bool
14842{
14843 /* We're async whenever the serial device is. */
14844 struct remote_state *rs = get_remote_state ();
14845 return serial_is_async_p (rs->remote_desc);
14846}
14847
14848/* Pass the SERIAL event on and up to the client. One day this code
14849 will be able to delay notifying the client of an event until the
14850 point where an entire packet has been received. */
14851
14854static void
14855remote_async_serial_handler (struct serial *scb, void *context)
14856{
14857 /* Don't propogate error information up to the client. Instead let
14858 the client find out about the error by querying the target. */
14860}
14862static void
14863remote_async_inferior_event_handler (gdb_client_data data)
14864{
14866}
14868int
14870{
14871 struct remote_state *rs = get_remote_state ();
14872 return rs->remote_desc->fd;
14873}
14875void
14877{
14878 struct remote_state *rs = get_remote_state ();
14879
14880 if (enable)
14881 {
14883
14884 /* If there are pending events in the stop reply queue tell the
14885 event loop to process them. */
14886 if (!rs->stop_reply_queue.empty ())
14888 /* For simplicity, below we clear the pending events token
14889 without remembering whether it is marked, so here we always
14890 mark it. If there's actually no pending notification to
14891 process, this ends up being a no-op (other than a spurious
14892 event-loop wakeup). */
14893 if (target_is_non_stop_p ())
14895 }
14896 else
14897 {
14898 serial_async (rs->remote_desc, NULL, NULL);
14899 /* If the core is disabling async, it doesn't want to be
14900 disturbed with target events. Clear all async event sources
14901 too. */
14903 if (target_is_non_stop_p ())
14905 }
14906}
14907
14908/* Implementation of the to_thread_events method. */
14910void
14912{
14913 struct remote_state *rs = get_remote_state ();
14914 size_t size = get_remote_packet_size ();
14915
14917 return;
14918
14919 xsnprintf (rs->buf.data (), size, "QThreadEvents:%x", enable ? 1 : 0);
14920 putpkt (rs->buf);
14921 getpkt (&rs->buf);
14922
14924 {
14925 case PACKET_OK:
14926 if (strcmp (rs->buf.data (), "OK") != 0)
14927 error (_("Remote refused setting thread events: %s"), rs->buf.data ());
14928 break;
14929 case PACKET_ERROR:
14930 warning (_("Remote failure reply: %s"), rs->buf.data ());
14931 break;
14932 case PACKET_UNKNOWN:
14933 break;
14934 }
14935}
14937static void
14938show_remote_cmd (const char *args, int from_tty)
14939{
14940 /* We can't just use cmd_show_list here, because we want to skip
14941 the redundant "show remote Z-packet" and the legacy aliases. */
14943 struct ui_out *uiout = current_uiout;
14944
14945 ui_out_emit_tuple tuple_emitter (uiout, "showlist");
14946 for (; list != NULL; list = list->next)
14947 if (strcmp (list->name, "Z-packet") == 0)
14948 continue;
14949 else if (list->type == not_set_cmd)
14950 /* Alias commands are exactly like the original, except they
14951 don't have the normal type. */
14952 continue;
14953 else
14954 {
14955 ui_out_emit_tuple option_emitter (uiout, "option");
14956
14957 uiout->field_string ("name", list->name);
14958 uiout->text (": ");
14959 if (list->type == show_cmd)
14960 do_show_command (NULL, from_tty, list);
14961 else
14962 cmd_func (list, NULL, from_tty);
14963 }
14964}
14965
14966/* Some change happened in PSPACE's objfile list (obfiles added or removed),
14967 offer all inferiors using that program space a change to look up symbols. */
14969static void
14971{
14972 /* The affected program space is possibly shared by multiple inferiors.
14973 Consider sending a qSymbol packet for each of the inferiors using that
14974 program space. */
14975 for (inferior *inf : all_inferiors ())
14976 {
14977 if (inf->pspace != pspace)
14978 continue;
14979
14980 /* Check whether the inferior's process target is a remote target. */
14981 remote_target *remote = as_remote_target (inf->process_target ());
14982 if (remote == nullptr)
14983 continue;
14984
14985 /* When we are attaching or handling a fork child and the shared library
14986 subsystem reads the list of loaded libraries, we receive new objfile
14987 events in between each found library. The libraries are read in an
14988 undefined order, so if we gave the remote side a chance to look up
14989 symbols between each objfile, we might give it an inconsistent picture
14990 of the inferior. It could appear that a library A appears loaded but
14991 a library B does not, even though library A requires library B. That
14992 would present a state that couldn't normally exist in the inferior.
14993
14994 So, skip these events, we'll give the remote a chance to look up
14995 symbols once all the loaded libraries and their symbols are known to
14996 GDB. */
14997 if (inf->in_initial_library_scan)
14998 continue;
14999
15000 if (!remote->has_execution (inf))
15001 continue;
15002
15003 /* Need to switch to a specific thread, because remote_check_symbols will
15004 set the general thread using INFERIOR_PTID.
15005
15006 It's possible to have inferiors with no thread here, because we are
15007 called very early in the connection process, while the inferior is
15008 being set up, before threads are added. Just skip it, start_remote_1
15009 also calls remote_check_symbols when it's done setting things up. */
15011 if (thread != nullptr)
15012 {
15013 scoped_restore_current_thread restore_thread;
15014 switch_to_thread (thread);
15015 remote->remote_check_symbols ();
15016 }
15017 }
15018}
15019
15020/* Function to be called whenever a new objfile (shlib) is detected. */
15022static void
15024{
15026}
15027
15028/* Pull all the tracepoints defined on the target and create local
15029 data structures representing them. We don't want to create real
15030 tracepoints yet, we don't want to mess up the user's existing
15031 collection. */
15033int
15035{
15036 struct remote_state *rs = get_remote_state ();
15037 char *p;
15038
15039 /* Ask for a first packet of tracepoint definition. */
15040 putpkt ("qTfP");
15041 getpkt (&rs->buf);
15042 p = rs->buf.data ();
15043 while (*p && *p != 'l')
15044 {
15046 /* Ask for another packet of tracepoint definition. */
15047 putpkt ("qTsP");
15048 getpkt (&rs->buf);
15049 p = rs->buf.data ();
15050 }
15051 return 0;
15052}
15054int
15056{
15057 struct remote_state *rs = get_remote_state ();
15058 char *p;
15059
15060 /* Ask for a first packet of variable definition. */
15061 putpkt ("qTfV");
15062 getpkt (&rs->buf);
15063 p = rs->buf.data ();
15064 while (*p && *p != 'l')
15065 {
15066 parse_tsv_definition (p, utsvp);
15067 /* Ask for another packet of variable definition. */
15068 putpkt ("qTsV");
15069 getpkt (&rs->buf);
15070 p = rs->buf.data ();
15071 }
15072 return 0;
15073}
15074
15075/* The "set/show range-stepping" show hook. */
15077static void
15078show_range_stepping (struct ui_file *file, int from_tty,
15079 struct cmd_list_element *c,
15080 const char *value)
15081{
15082 gdb_printf (file,
15083 _("Debugger's willingness to use range stepping "
15084 "is %s.\n"), value);
15085}
15086
15087/* Return true if the vCont;r action is supported by the remote
15088 stub. */
15094 && get_remote_state ()->supports_vCont.r);
15095}
15096
15097/* The "set/show range-stepping" set hook. */
15099static void
15100set_range_stepping (const char *ignore_args, int from_tty,
15101 struct cmd_list_element *c)
15102{
15103 /* When enabling, check whether range stepping is actually supported
15104 by the target, and warn if not. */
15106 {
15108 if (remote == NULL
15109 || !remote->vcont_r_supported ())
15110 warning (_("Range stepping is not supported by the current target"));
15111 }
15112}
15114static void
15115show_remote_debug (struct ui_file *file, int from_tty,
15116 struct cmd_list_element *c, const char *value)
15117{
15118 gdb_printf (file, _("Debugging of remote protocol is %s.\n"),
15119 value);
15120}
15122static void
15123show_remote_timeout (struct ui_file *file, int from_tty,
15124 struct cmd_list_element *c, const char *value)
15125{
15126 gdb_printf (file,
15127 _("Timeout limit to wait for target to respond is %s.\n"),
15128 value);
15129}
15130
15131/* Implement the "supports_memory_tagging" target_ops method. */
15137}
15138
15139/* Create the qMemTags packet given ADDRESS, LEN and TYPE. */
15141static void
15142create_fetch_memtags_request (gdb::char_vector &packet, CORE_ADDR address,
15143 size_t len, int type)
15144{
15145 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
15146
15147 std::string request = string_printf ("qMemTags:%s,%s:%s",
15148 phex_nz (address, addr_size),
15149 phex_nz (len, sizeof (len)),
15150 phex_nz (type, sizeof (type)));
15151
15152 strcpy (packet.data (), request.c_str ());
15153}
15154
15155/* Parse the qMemTags packet reply into TAGS.
15156
15157 Return true if successful, false otherwise. */
15159static bool
15160parse_fetch_memtags_reply (const gdb::char_vector &reply,
15161 gdb::byte_vector &tags)
15162{
15163 if (reply.empty () || reply[0] == 'E' || reply[0] != 'm')
15164 return false;
15165
15166 /* Copy the tag data. */
15167 tags = hex2bin (reply.data () + 1);
15168
15169 return true;
15170}
15171
15172/* Create the QMemTags packet given ADDRESS, LEN, TYPE and TAGS. */
15174static void
15175create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address,
15176 size_t len, int type,
15177 const gdb::byte_vector &tags)
15178{
15179 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
15180
15181 /* Put together the main packet, address and length. */
15182 std::string request = string_printf ("QMemTags:%s,%s:%s:",
15183 phex_nz (address, addr_size),
15184 phex_nz (len, sizeof (len)),
15185 phex_nz (type, sizeof (type)));
15186 request += bin2hex (tags.data (), tags.size ());
15187
15188 /* Check if we have exceeded the maximum packet size. */
15189 if (packet.size () < request.length ())
15190 error (_("Contents too big for packet QMemTags."));
15191
15192 strcpy (packet.data (), request.c_str ());
15193}
15194
15195/* Implement the "fetch_memtags" target_ops method. */
15197bool
15198remote_target::fetch_memtags (CORE_ADDR address, size_t len,
15199 gdb::byte_vector &tags, int type)
15200{
15201 /* Make sure the qMemTags packet is supported. */
15203 gdb_assert_not_reached ("remote fetch_memtags called with packet disabled");
15204
15205 struct remote_state *rs = get_remote_state ();
15206
15207 create_fetch_memtags_request (rs->buf, address, len, type);
15208
15209 putpkt (rs->buf);
15210 getpkt (&rs->buf);
15211
15212 return parse_fetch_memtags_reply (rs->buf, tags);
15213}
15214
15215/* Implement the "store_memtags" target_ops method. */
15217bool
15218remote_target::store_memtags (CORE_ADDR address, size_t len,
15219 const gdb::byte_vector &tags, int type)
15220{
15221 /* Make sure the QMemTags packet is supported. */
15223 gdb_assert_not_reached ("remote store_memtags called with packet disabled");
15224
15225 struct remote_state *rs = get_remote_state ();
15226
15227 create_store_memtags_request (rs->buf, address, len, type, tags);
15228
15229 putpkt (rs->buf);
15230 getpkt (&rs->buf);
15231
15232 /* Verify if the request was successful. */
15233 return packet_check_result (rs->buf.data ()) == PACKET_OK;
15234}
15235
15236/* Return true if remote target T is non-stop. */
15238bool
15240{
15241 scoped_restore_current_thread restore_thread;
15243
15244 return target_is_non_stop_p ();
15245}
15246
15247#if GDB_SELF_TEST
15248
15249namespace selftests {
15250
15251static void
15252test_memory_tagging_functions ()
15253{
15254 remote_target remote;
15255
15256 struct packet_config *config
15258
15259 scoped_restore restore_memtag_support_
15260 = make_scoped_restore (&config->support);
15261
15262 /* Test memory tagging packet support. */
15264 SELF_CHECK (remote.supports_memory_tagging () == false);
15265 config->support = PACKET_DISABLE;
15266 SELF_CHECK (remote.supports_memory_tagging () == false);
15267 config->support = PACKET_ENABLE;
15268 SELF_CHECK (remote.supports_memory_tagging () == true);
15269
15270 /* Setup testing. */
15271 gdb::char_vector packet;
15272 gdb::byte_vector tags, bv;
15273 std::string expected, reply;
15274 packet.resize (32000);
15275
15276 /* Test creating a qMemTags request. */
15277
15278 expected = "qMemTags:0,0:0";
15279 create_fetch_memtags_request (packet, 0x0, 0x0, 0);
15280 SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0);
15281
15282 expected = "qMemTags:deadbeef,10:1";
15283 create_fetch_memtags_request (packet, 0xdeadbeef, 16, 1);
15284 SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0);
15285
15286 /* Test parsing a qMemTags reply. */
15287
15288 /* Error reply, tags vector unmodified. */
15289 reply = "E00";
15290 strcpy (packet.data (), reply.c_str ());
15291 tags.resize (0);
15292 SELF_CHECK (parse_fetch_memtags_reply (packet, tags) == false);
15293 SELF_CHECK (tags.size () == 0);
15294
15295 /* Valid reply, tags vector updated. */
15296 tags.resize (0);
15297 bv.resize (0);
15298
15299 for (int i = 0; i < 5; i++)
15300 bv.push_back (i);
15301
15302 reply = "m" + bin2hex (bv.data (), bv.size ());
15303 strcpy (packet.data (), reply.c_str ());
15304
15305 SELF_CHECK (parse_fetch_memtags_reply (packet, tags) == true);
15306 SELF_CHECK (tags.size () == 5);
15307
15308 for (int i = 0; i < 5; i++)
15309 SELF_CHECK (tags[i] == i);
15310
15311 /* Test creating a QMemTags request. */
15312
15313 /* Empty tag data. */
15314 tags.resize (0);
15315 expected = "QMemTags:0,0:0:";
15316 create_store_memtags_request (packet, 0x0, 0x0, 0, tags);
15317 SELF_CHECK (memcmp (packet.data (), expected.c_str (),
15318 expected.length ()) == 0);
15319
15320 /* Non-empty tag data. */
15321 tags.resize (0);
15322 for (int i = 0; i < 5; i++)
15323 tags.push_back (i);
15324 expected = "QMemTags:deadbeef,ff:1:0001020304";
15325 create_store_memtags_request (packet, 0xdeadbeef, 255, 1, tags);
15326 SELF_CHECK (memcmp (packet.data (), expected.c_str (),
15327 expected.length ()) == 0);
15328}
15329
15330} // namespace selftests
15331#endif /* GDB_SELF_TEST */
15332
15334void
15336{
15339
15340 /* Hook into new objfile notification. */
15344
15345#if 0
15346 init_remote_threadtests ();
15347#endif
15348
15349 /* set/show remote ... */
15350
15352Remote protocol specific variables.\n\
15353Configure various remote-protocol specific variables such as\n\
15354the packets being used."),
15356 0 /* allow-unknown */, &setlist);
15358Remote protocol specific variables.\n\
15359Configure various remote-protocol specific variables such as\n\
15360the packets being used."),
15362 0 /* allow-unknown */, &showlist);
15363
15364 add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\
15365Compare section data on target to the exec file.\n\
15366Argument is a single section name (default: all loaded sections).\n\
15367To compare only read-only loaded sections, specify the -r option."),
15368 &cmdlist);
15369
15371Send an arbitrary packet to a remote target.\n\
15372 maintenance packet TEXT\n\
15373If GDB is talking to an inferior via the GDB serial protocol, then\n\
15374this command sends the string TEXT to the inferior, and displays the\n\
15375response packet. GDB supplies the initial `$' character, and the\n\
15376terminating `#' character and checksum."),
15378
15379 set_show_commands remotebreak_cmds
15380 = add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
15381Set whether to send break if interrupted."), _("\
15382Show whether to send break if interrupted."), _("\
15383If set, a break, instead of a cntrl-c, is sent to the remote target."),
15385 &setlist, &showlist);
15386 deprecate_cmd (remotebreak_cmds.set, "set remote interrupt-sequence");
15387 deprecate_cmd (remotebreak_cmds.show, "show remote interrupt-sequence");
15388
15389 add_setshow_enum_cmd ("interrupt-sequence", class_support,
15391 _("\
15392Set interrupt sequence to remote target."), _("\
15393Show interrupt sequence to remote target."), _("\
15394Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
15398
15399 add_setshow_boolean_cmd ("interrupt-on-connect", class_support,
15401Set whether interrupt-sequence is sent to remote target when gdb connects to."), _("\
15402Show whether interrupt-sequence is sent to remote target when gdb connects to."), _("\
15403If set, interrupt sequence is sent to remote target."),
15404 NULL, NULL,
15406
15407 /* Install commands for configuring memory read/write packets. */
15408
15409 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\
15410Set the maximum number of bytes per memory write packet (deprecated)."),
15411 &setlist);
15412 add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\
15413Show the maximum number of bytes per memory write packet (deprecated)."),
15414 &showlist);
15415 add_cmd ("memory-write-packet-size", no_class,
15417Set the maximum number of bytes per memory-write packet.\n\
15418Specify the number of bytes in a packet or 0 (zero) for the\n\
15419default packet size. The actual limit is further reduced\n\
15420dependent on the target. Specify \"fixed\" to disable the\n\
15421further restriction and \"limit\" to enable that restriction."),
15423 add_cmd ("memory-read-packet-size", no_class,
15425Set the maximum number of bytes per memory-read packet.\n\
15426Specify the number of bytes in a packet or 0 (zero) for the\n\
15427default packet size. The actual limit is further reduced\n\
15428dependent on the target. Specify \"fixed\" to disable the\n\
15429further restriction and \"limit\" to enable that restriction."),
15431 add_cmd ("memory-write-packet-size", no_class,
15433 _("Show the maximum number of bytes per memory-write packet."),
15435 add_cmd ("memory-read-packet-size", no_class,
15437 _("Show the maximum number of bytes per memory-read packet."),
15439
15440 add_setshow_zuinteger_unlimited_cmd ("hardware-watchpoint-limit", no_class,
15442Set the maximum number of target hardware watchpoints."), _("\
15443Show the maximum number of target hardware watchpoints."), _("\
15444Specify \"unlimited\" for unlimited hardware watchpoints."),
15448 add_setshow_zuinteger_unlimited_cmd ("hardware-watchpoint-length-limit",
15449 no_class,
15451Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
15452Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
15453Specify \"unlimited\" to allow watchpoints of unlimited size."),
15456 add_setshow_zuinteger_unlimited_cmd ("hardware-breakpoint-limit", no_class,
15458Set the maximum number of target hardware breakpoints."), _("\
15459Show the maximum number of target hardware breakpoints."), _("\
15460Specify \"unlimited\" for unlimited hardware breakpoints."),
15463
15464 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure,
15465 &remote_address_size, _("\
15466Set the maximum size of the address (in bits) in a memory packet."), _("\
15467Show the maximum size of the address (in bits) in a memory packet."), NULL,
15468 NULL,
15469 NULL, /* FIXME: i18n: */
15470 &setlist, &showlist);
15471
15473
15474 add_packet_config_cmd (PACKET_X, "X", "binary-download", 1);
15475
15476 add_packet_config_cmd (PACKET_vCont, "vCont", "verbose-resume", 0);
15477
15478 add_packet_config_cmd (PACKET_QPassSignals, "QPassSignals", "pass-signals",
15479 0);
15480
15482 "catch-syscalls", 0);
15483
15485 "program-signals", 0);
15486
15488 "set-working-dir", 0);
15489
15490 add_packet_config_cmd (PACKET_QStartupWithShell, "QStartupWithShell",
15491 "startup-with-shell", 0);
15492
15493 add_packet_config_cmd (PACKET_QEnvironmentHexEncoded,"QEnvironmentHexEncoded",
15494 "environment-hex-encoded", 0);
15495
15496 add_packet_config_cmd (PACKET_QEnvironmentReset, "QEnvironmentReset",
15497 "environment-reset", 0);
15498
15499 add_packet_config_cmd (PACKET_QEnvironmentUnset, "QEnvironmentUnset",
15500 "environment-unset", 0);
15501
15502 add_packet_config_cmd (PACKET_qSymbol, "qSymbol", "symbol-lookup", 0);
15503
15504 add_packet_config_cmd (PACKET_P, "P", "set-register", 1);
15505
15506 add_packet_config_cmd (PACKET_p, "p", "fetch-register", 1);
15507
15508 add_packet_config_cmd (PACKET_Z0, "Z0", "software-breakpoint", 0);
15509
15510 add_packet_config_cmd (PACKET_Z1, "Z1", "hardware-breakpoint", 0);
15511
15512 add_packet_config_cmd (PACKET_Z2, "Z2", "write-watchpoint", 0);
15513
15514 add_packet_config_cmd (PACKET_Z3, "Z3", "read-watchpoint", 0);
15515
15516 add_packet_config_cmd (PACKET_Z4, "Z4", "access-watchpoint", 0);
15517
15518 add_packet_config_cmd (PACKET_qXfer_auxv, "qXfer:auxv:read",
15519 "read-aux-vector", 0);
15520
15521 add_packet_config_cmd (PACKET_qXfer_exec_file, "qXfer:exec-file:read",
15522 "pid-to-exec-file", 0);
15523
15525 "qXfer:features:read", "target-features", 0);
15526
15527 add_packet_config_cmd (PACKET_qXfer_libraries, "qXfer:libraries:read",
15528 "library-info", 0);
15529
15531 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
15532
15533 add_packet_config_cmd (PACKET_qXfer_memory_map, "qXfer:memory-map:read",
15534 "memory-map", 0);
15535
15536 add_packet_config_cmd (PACKET_qXfer_osdata, "qXfer:osdata:read", "osdata", 0);
15537
15538 add_packet_config_cmd (PACKET_qXfer_threads, "qXfer:threads:read", "threads",
15539 0);
15540
15541 add_packet_config_cmd (PACKET_qXfer_siginfo_read, "qXfer:siginfo:read",
15542 "read-siginfo-object", 0);
15543
15544 add_packet_config_cmd (PACKET_qXfer_siginfo_write, "qXfer:siginfo:write",
15545 "write-siginfo-object", 0);
15546
15548 "qXfer:traceframe-info:read", "traceframe-info", 0);
15549
15550 add_packet_config_cmd (PACKET_qXfer_uib, "qXfer:uib:read",
15551 "unwind-info-block", 0);
15552
15554 "get-thread-local-storage-address", 0);
15555
15557 "get-thread-information-block-address", 0);
15558
15559 add_packet_config_cmd (PACKET_bc, "bc", "reverse-continue", 0);
15560
15561 add_packet_config_cmd (PACKET_bs, "bs", "reverse-step", 0);
15562
15563 add_packet_config_cmd (PACKET_qSupported, "qSupported", "supported-packets",
15564 0);
15565
15567 "search-memory", 0);
15568
15569 add_packet_config_cmd (PACKET_qTStatus, "qTStatus", "trace-status", 0);
15570
15571 add_packet_config_cmd (PACKET_vFile_setfs, "vFile:setfs", "hostio-setfs", 0);
15572
15573 add_packet_config_cmd (PACKET_vFile_open, "vFile:open", "hostio-open", 0);
15574
15575 add_packet_config_cmd (PACKET_vFile_pread, "vFile:pread", "hostio-pread", 0);
15576
15577 add_packet_config_cmd (PACKET_vFile_pwrite, "vFile:pwrite", "hostio-pwrite",
15578 0);
15579
15580 add_packet_config_cmd (PACKET_vFile_close, "vFile:close", "hostio-close", 0);
15581
15582 add_packet_config_cmd (PACKET_vFile_unlink, "vFile:unlink", "hostio-unlink",
15583 0);
15584
15586 "hostio-readlink", 0);
15587
15588 add_packet_config_cmd (PACKET_vFile_fstat, "vFile:fstat", "hostio-fstat", 0);
15589
15590 add_packet_config_cmd (PACKET_vAttach, "vAttach", "attach", 0);
15591
15592 add_packet_config_cmd (PACKET_vRun, "vRun", "run", 0);
15593
15594 add_packet_config_cmd (PACKET_QStartNoAckMode, "QStartNoAckMode", "noack", 0);
15595
15596 add_packet_config_cmd (PACKET_vKill, "vKill", "kill", 0);
15597
15598 add_packet_config_cmd (PACKET_qAttached, "qAttached", "query-attached", 0);
15599
15601 "ConditionalTracepoints", "conditional-tracepoints",
15602 0);
15603
15605 "ConditionalBreakpoints", "conditional-breakpoints",
15606 0);
15607
15608 add_packet_config_cmd (PACKET_BreakpointCommands, "BreakpointCommands",
15609 "breakpoint-commands", 0);
15610
15612 "fast-tracepoints", 0);
15613
15615 "TracepointSource", 0);
15616
15617 add_packet_config_cmd (PACKET_QAllow, "QAllow", "allow", 0);
15618
15619 add_packet_config_cmd (PACKET_StaticTracepoints, "StaticTracepoints",
15620 "static-tracepoints", 0);
15621
15623 "install-in-trace", 0);
15624
15626 "qXfer:statictrace:read", "read-sdata-object", 0);
15627
15628 add_packet_config_cmd (PACKET_qXfer_fdpic, "qXfer:fdpic:read",
15629 "read-fdpic-loadmap", 0);
15630
15631 add_packet_config_cmd (PACKET_QDisableRandomization, "QDisableRandomization",
15632 "disable-randomization", 0);
15633
15634 add_packet_config_cmd (PACKET_QAgent, "QAgent", "agent", 0);
15635
15637 "trace-buffer-size", 0);
15638
15639 add_packet_config_cmd (PACKET_Qbtrace_off, "Qbtrace:off", "disable-btrace",
15640 0);
15641
15642 add_packet_config_cmd (PACKET_Qbtrace_bts, "Qbtrace:bts", "enable-btrace-bts",
15643 0);
15644
15645 add_packet_config_cmd (PACKET_Qbtrace_pt, "Qbtrace:pt", "enable-btrace-pt",
15646 0);
15647
15648 add_packet_config_cmd (PACKET_qXfer_btrace, "qXfer:btrace", "read-btrace", 0);
15649
15650 add_packet_config_cmd (PACKET_qXfer_btrace_conf, "qXfer:btrace-conf",
15651 "read-btrace-conf", 0);
15652
15653 add_packet_config_cmd (PACKET_Qbtrace_conf_bts_size, "Qbtrace-conf:bts:size",
15654 "btrace-conf-bts-size", 0);
15655
15656 add_packet_config_cmd (PACKET_multiprocess_feature, "multiprocess-feature",
15657 "multiprocess-feature", 0);
15658
15660 "swbreak-feature", 0);
15661
15663 "hwbreak-feature", 0);
15664
15665 add_packet_config_cmd (PACKET_fork_event_feature, "fork-event-feature",
15666 "fork-event-feature", 0);
15667
15668 add_packet_config_cmd (PACKET_vfork_event_feature, "vfork-event-feature",
15669 "vfork-event-feature", 0);
15670
15671 add_packet_config_cmd (PACKET_Qbtrace_conf_pt_size, "Qbtrace-conf:pt:size",
15672 "btrace-conf-pt-size", 0);
15673
15675 "verbose-resume-supported", 0);
15676
15677 add_packet_config_cmd (PACKET_exec_event_feature, "exec-event-feature",
15678 "exec-event-feature", 0);
15679
15680 add_packet_config_cmd (PACKET_vCtrlC, "vCtrlC", "ctrl-c", 0);
15681
15682 add_packet_config_cmd (PACKET_QThreadEvents, "QThreadEvents", "thread-events",
15683 0);
15684
15686 "no-resumed-stop-reply", 0);
15687
15689 "memory-tagging-feature", "memory-tagging-feature", 0);
15690
15691 /* Assert that we've registered "set remote foo-packet" commands
15692 for all packet configs. */
15693 {
15694 int i;
15695
15696 for (i = 0; i < PACKET_MAX; i++)
15697 {
15698 /* Ideally all configs would have a command associated. Some
15699 still don't though. */
15700 int excepted;
15701
15702 switch (i)
15703 {
15704 case PACKET_QNonStop:
15709 case PACKET_qCRC:
15710 /* Additions to this list need to be well justified:
15711 pre-existing packets are OK; new packets are not. */
15712 excepted = 1;
15713 break;
15714 default:
15715 excepted = 0;
15716 break;
15717 }
15718
15719 /* This catches both forgetting to add a config command, and
15720 forgetting to remove a packet from the exception list. */
15721 gdb_assert (excepted == (packets_descriptions[i].name == NULL));
15722 }
15723 }
15724
15725 /* Keep the old ``set remote Z-packet ...'' working. Each individual
15726 Z sub-packet has its own set and show commands, but users may
15727 have sets to this variable in their .gdbinit files (or in their
15728 documentation). */
15731Set use of remote protocol `Z' packets."), _("\
15732Show use of remote protocol `Z' packets."), _("\
15733When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
15734packets."),
15737 /* FIXME: i18n: Use of remote protocol
15738 `Z' packets is %s. */
15740
15741 add_basic_prefix_cmd ("remote", class_files, _("\
15742Manipulate files on the remote system.\n\
15743Transfer files to and from the remote target system."),
15745 0 /* allow-unknown */, &cmdlist);
15746
15748 _("Copy a local file to the remote system."),
15750
15752 _("Copy a remote file to the local system."),
15754
15756 _("Delete a remote file."),
15758
15761Set the remote pathname for \"run\"."), _("\
15762Show the remote pathname for \"run\"."), NULL,
15767
15768 add_setshow_boolean_cmd ("range-stepping", class_run,
15769 &use_range_stepping, _("\
15770Enable or disable range stepping."), _("\
15771Show whether target-assisted range stepping is enabled."), _("\
15772If on, and the target supports it, when stepping a source line, GDB\n\
15773tells the target to step the corresponding range of addresses itself instead\n\
15774of issuing multiple single-steps. This speeds up source level\n\
15775stepping. If off, GDB always issues single-steps, even if range\n\
15776stepping is supported by the target. The default is on."),
15779 &setlist,
15780 &showlist);
15781
15783Set watchdog timer."), _("\
15784Show watchdog timer."), _("\
15785When non-zero, this timeout is used instead of waiting forever for a target\n\
15786to finish a low-level step or continue operation. If the specified amount\n\
15787of time passes without a response from the target, an error occurs."),
15788 NULL,
15790 &setlist, &showlist);
15791
15792 add_setshow_zuinteger_unlimited_cmd ("remote-packet-max-chars", no_class,
15794Set the maximum number of characters to display for each remote packet."), _("\
15795Show the maximum number of characters to display for each remote packet."), _("\
15796Specify \"unlimited\" to display all the characters."),
15799
15801 _("Set debugging of remote protocol."),
15802 _("Show debugging of remote protocol."),
15803 _("\
15804When enabled, each packet sent or received with the remote target\n\
15805is displayed."),
15806 NULL,
15809
15811 &remote_timeout, _("\
15812Set timeout limit to wait for target to respond."), _("\
15813Show timeout limit to wait for target to respond."), _("\
15814This value is used to set the time limit for gdb to wait for a response\n\
15815from the target."),
15816 NULL,
15818 &setlist, &showlist);
15819
15820 /* Eventually initialize fileio. See fileio.c */
15822
15823#if GDB_SELF_TEST
15824 selftests::register_test ("remote_memory_tagging",
15825 selftests::test_memory_tagging_functions);
15826#endif
15827}
int regnum
const char *const name
void * xmalloc(YYSIZE_T)
void xfree(void *)
static struct @5 attributes[]
struct gdbarch * target_gdbarch(void)
void mark_async_event_handler(async_event_handler *async_handler_ptr)
async_event_handler * create_async_event_handler(async_event_handler_func *proc, gdb_client_data client_data, const char *name)
void clear_async_event_handler(async_event_handler *async_handler_ptr)
void delete_async_event_handler(async_event_handler **async_handler_ptr)
bool async_event_handler_marked(async_event_handler *handler)
agent_expr_up gen_eval_for_expr(CORE_ADDR scope, struct expression *expr)
Definition ax-gdb.c:2393
std::unique_ptr< agent_expr > agent_expr_up
Definition ax.h:147
int breakpoints_should_be_inserted_now(void)
Definition breakpoint.c:598
struct command_line * breakpoint_commands(struct breakpoint *b)
Definition breakpoint.c:494
void remove_breakpoints_inf(inferior *inf)
void insert_breakpoints(void)
bptype
Definition breakpoint.h:84
@ bp_fast_tracepoint
Definition breakpoint.h:185
@ bp_hardware_breakpoint
Definition breakpoint.h:87
@ bp_static_marker_tracepoint
Definition breakpoint.h:188
@ bp_static_tracepoint
Definition breakpoint.h:186
@ bp_enabled
Definition breakpoint.h:220
remove_bp_reason
Definition breakpoint.h:64
breakpoint * owner
Definition breakpoint.h:345
CORE_ADDR address
Definition breakpoint.h:437
bool supports_disable_randomization() override
Definition remote.c:10391
bool can_attach() override
Definition remote.c:1284
void post_attach(int) override
Definition remote.c:6394
bool can_create_inferior() override
Definition remote.c:1278
void attach(const char *, int) override
Definition remote.c:6299
const target_info & info() const override
Definition remote.c:1272
static void open(const char *, int)
Definition remote.c:5271
void create_inferior(const char *, const std::string &, char **, int) override
Definition remote.c:10576
void detach(inferior *, int) override
Definition remote.c:6221
gdb_environ environment
Definition inferior.h:590
const std::string & cwd() const
Definition inferior.h:550
void push_target(struct target_ops *t)
Definition inferior.h:406
struct process_stratum_target * process_target()
Definition inferior.h:449
int num
Definition inferior.h:557
struct program_space * pspace
Definition inferior.h:582
void follow_fork(inferior *child_inf, ptid_t child_ptid, target_waitkind fork_kind, bool follow_child, bool detach_on_fork) override
thread_info * find_thread(ptid_t ptid)
void follow_exec(inferior *follow_inf, ptid_t ptid, const char *execd_pathname) override
bool has_execution(inferior *inf) override
gdbarch * arch() const
Definition regcache.c:231
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
void raw_update(int regnum) override
Definition regcache.c:586
ptid_t ptid() const
Definition regcache.h:408
void set(unsigned key, void *datum)
Definition registry.h:204
void * get(unsigned key)
Definition registry.h:211
char * last_pass_packet
Definition remote.c:481
gdb_signal last_sent_signal
Definition remote.c:489
char * finished_annex
Definition remote.c:497
int remote_traceframe_number
Definition remote.c:479
threadref resultthreadlist[MAXTHREADLISTRESULTS]
Definition remote.c:512
long explicit_packet_size
Definition remote.c:434
gdb::char_vector buf
Definition remote.c:424
std::unordered_map< struct gdbarch *, remote_arch_state > m_arch_states
Definition remote.c:561
bool wait_forever_enabled_p
Definition remote.c:554
bool last_sent_step
Definition remote.c:491
bool use_threadinfo_query
Definition remote.c:507
ULONGEST finished_offset
Definition remote.c:498
bool use_threadextra_query
Definition remote.c:508
ptid_t general_thread
Definition remote.c:474
char * last_program_signals_packet
Definition remote.c:487
std::vector< stop_reply_up > stop_reply_queue
Definition remote.c:541
vCont_action_support supports_vCont
Definition remote.c:453
exec_direction_kind last_resume_exec_dir
Definition remote.c:494
threadref nextthread
Definition remote.c:511
struct readahead_cache readahead_cache
Definition remote.c:532
struct async_event_handler * remote_async_inferior_event_token
Definition remote.c:545
struct remote_arch_state * get_remote_arch_state(struct gdbarch *gdbarch)
Definition remote.c:1627
bool ctrlc_pending_p
Definition remote.c:457
struct serial * remote_desc
Definition remote.c:470
bool waiting_for_stop_reply
Definition remote.c:450
struct remote_notif_state * notif_state
Definition remote.c:515
threadref echo_nextthread
Definition remote.c:510
bool starting_up
Definition remote.c:428
char * finished_object
Definition remote.c:496
ptid_t continue_thread
Definition remote.c:475
bool extended
Definition remote.c:442
bool noack_mode
Definition remote.c:439
bool got_ctrlc_during_io
Definition remote.c:465
void remote_notif_get_pending_events(const notif_client *nc)
Definition remote.c:8067
struct stop_reply * remote_notif_remove_queued_reply(ptid_t ptid)
Definition remote.c:7588
enum btrace_error read_btrace(struct btrace_data *data, struct btrace_target_info *btinfo, enum btrace_read_type type) override
Definition remote.c:14670
void interrupt_query()
Definition remote.c:7321
void extended_remote_restart()
Definition remote.c:4350
int getpkt(gdb::char_vector *buf, bool forever=false, bool *is_notif=nullptr)
Definition remote.c:10054
const char * thread_name(struct thread_info *) override
Definition remote.c:3174
int remote_hostio_pread(int fd, gdb_byte *read_buf, int len, ULONGEST offset, fileio_error *remote_errno)
Definition remote.c:12589
bool stopped_data_address(CORE_ADDR *) override
Definition remote.c:10992
thread_info * remote_add_thread(ptid_t ptid, bool running, bool executing, bool silent_p)
Definition remote.c:2734
int readchar(int timeout)
Definition remote.c:9615
bool augmented_libraries_svr4_read() override
Definition remote.c:14717
int fileio_pwrite(int fd, const gdb_byte *write_buf, int len, ULONGEST offset, fileio_error *target_errno) override
Definition remote.c:12519
target_xfer_status remote_xfer_live_readonly_partial(gdb_byte *readbuf, ULONGEST memaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition remote.c:9392
void kill_new_fork_children(inferior *inf)
Definition remote.c:10195
bool supports_disable_randomization() override
Definition remote.c:13134
void load(const char *, int) override
Definition remote.c:14727
bool can_run_breakpoint_commands() override
Definition remote.c:13192
void get_offsets()
Definition remote.c:4399
int insert_watchpoint(CORE_ADDR, int, enum target_hw_bp_type, struct expression *) override
Definition remote.c:10808
void discard_pending_stop_replies_in_queue()
Definition remote.c:7569
ptid_t select_thread_for_ambiguous_stop_reply(const struct target_waitstatus &status)
Definition remote.c:8144
int upload_tracepoints(struct uploaded_tp **utpp) override
Definition remote.c:15032
int insert_hw_breakpoint(struct gdbarch *, struct bp_target_info *) override
Definition remote.c:11009
struct remote_state * get_remote_state()
Definition remote.c:1653
void download_tracepoint(struct bp_location *location) override
Definition remote.c:13249
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition remote.c:11357
std::vector< mem_region > memory_map() override
Definition remote.c:11723
void process_initial_stop_replies(int from_tty)
Definition remote.c:4726
void teardown_btrace(struct btrace_target_info *tinfo) override
Definition remote.c:14661
void log_command(const char *cmd) override
Definition remote.c:809
void remote_detach_pid(int pid)
Definition remote.c:6098
bool fetch_memtags(CORE_ADDR address, size_t len, gdb::byte_vector &tags, int type) override
Definition remote.c:15196
void flash_erase(ULONGEST address, LONGEST length) override
Definition remote.c:9536
ptid_t get_ada_task_ptid(long lwp, ULONGEST thread) override
Definition remote.c:4341
bool stopped_by_sw_breakpoint() override
Definition remote.c:10942
int upload_trace_state_variables(struct uploaded_tsv **utsvp) override
Definition remote.c:15053
void trace_init() override
Definition remote.c:13198
int remote_threadlist_iterator(rmt_thread_action stepfunction, void *context, int looplimit)
Definition remote.c:3787
void remote_btrace_maybe_reopen()
Definition remote.c:14509
void get_tracepoint_status(tracepoint *tp, struct uploaded_tp *utp) override
Definition remote.c:13676
char * append_resumption(char *p, char *endp, ptid_t ptid, int step, gdb_signal siggnal)
Definition remote.c:6473
bool get_trace_state_variable_value(int tsv, LONGEST *val) override
Definition remote.c:13816
int fileio_close(int fd, fileio_error *target_errno) override
Definition remote.c:12655
bool is_async_p() override
Definition remote.c:14839
target_xfer_status remote_read_bytes_1(CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len_units, int unit_size, ULONGEST *xfered_len_units)
Definition remote.c:9344
ptid_t wait_ns(ptid_t ptid, struct target_waitstatus *status, target_wait_flags options)
Definition remote.c:8284
void download_trace_state_variable(const trace_state_variable &tsv) override
Definition remote.c:13506
remote_target()=default
void prepare_to_store(struct regcache *) override
Definition remote.c:8825
int verify_memory(const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size) override
Definition remote.c:11107
ptid_t wait_as(ptid_t ptid, target_waitstatus *status, target_wait_flags options)
Definition remote.c:8353
void resume(ptid_t, int, enum gdb_signal) override
Definition remote.c:6711
int remove_watchpoint(CORE_ADDR, int, enum target_hw_bp_type, struct expression *) override
Definition remote.c:10858
int remote_get_threadinfo(threadref *threadid, int fieldset, gdb_ext_thread_info *info)
Definition remote.c:3655
void remote_file_get(const char *remote_file, const char *local_file, int from_tty)
Definition remote.c:13005
void follow_exec(inferior *, ptid_t, const char *) override
Definition remote.c:6264
int fileio_unlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition remote.c:12683
bool start_remote_1(int from_tty, int extended_p)
Definition remote.c:4914
std::vector< static_tracepoint_marker > static_tracepoint_markers_by_strid(const char *id) override
Definition remote.c:4303
bool use_agent(bool use) override
Definition remote.c:14079
void terminal_inferior() override
Definition remote.c:7348
long get_memory_write_packet_size()
Definition remote.c:2185
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
Definition remote.c:8505
void terminal_ours() override
Definition remote.c:7356
bool can_download_tracepoint() override
Definition remote.c:13478
void remote_notice_new_inferior(ptid_t currthread, bool executing)
Definition remote.c:2769
void discard_pending_stop_replies(struct inferior *inf)
Definition remote.c:7524
packet_result remote_send_printf(const char *format,...) ATTRIBUTE_PRINTF(2
Definition remote.c:9505
void disable_btrace(struct btrace_target_info *tinfo) override
Definition remote.c:14629
bool supports_stopped_by_sw_breakpoint() override
Definition remote.c:10955
thread_info * thread_handle_to_thread_info(const gdb_byte *thread_handle, int handle_len, inferior *inf) override
Definition remote.c:14798
void remote_check_symbols()
Definition remote.c:5302
void remote_download_command_source(int num, ULONGEST addr, struct command_line *cmds)
Definition remote.c:13212
bool vcont_r_supported()
Definition remote.c:15089
static void open_1(const char *name, int from_tty, int extended_p)
Definition remote.c:5918
int remote_resume_with_vcont(ptid_t scope_ptid, int step, gdb_signal siggnal)
Definition remote.c:6635
void set_general_process()
Definition remote.c:3111
void remote_interrupt_as()
Definition remote.c:7222
void print_one_stopped_thread(thread_info *thread)
Definition remote.c:4684
void set_thread(ptid_t ptid, int gen)
Definition remote.c:3061
const struct btrace_config * btrace_conf(const struct btrace_target_info *) override
Definition remote.c:14711
int peek_stop_reply(ptid_t ptid)
Definition remote.c:7662
int remote_unpack_thread_info_response(const char *pkt, threadref *expectedref, gdb_ext_thread_info *info)
Definition remote.c:3561
target_xfer_status remote_write_bytes_aux(const char *header, CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len_units, int unit_size, ULONGEST *xfered_len_units, char packet_format, int use_length)
Definition remote.c:9138
packet_result target_xfer_status remote_flash_write(ULONGEST address, ULONGEST length, ULONGEST *xfered_len, const gdb_byte *data)
Definition remote.c:9558
void process_g_packet(struct regcache *regcache)
Definition remote.c:8639
int remove_vfork_catchpoint(int) override
Definition remote.c:2578
int parse_threadlist_response(const char *pkt, int result_limit, threadref *original_echo, threadref *resultlist, int *doneflag)
Definition remote.c:3692
int remote_hostio_pwrite(int fd, const gdb_byte *write_buf, int len, ULONGEST offset, fileio_error *remote_errno)
Definition remote.c:12492
ULONGEST get_memory_xfer_limit() override
Definition remote.c:11552
bool has_pending_events() override
Definition remote.c:7081
bool supports_non_stop() override
Definition remote.c:13128
void remote_detach_1(struct inferior *inf, int from_tty)
Definition remote.c:6133
bool supports_evaluation_of_breakpoint_conditions() override
Definition remote.c:13154
target_xfer_status remote_read_qxfer(const char *object_name, const char *annex, gdb_byte *readbuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len, const unsigned int which_packet)
Definition remote.c:11273
bool supports_stopped_by_hw_breakpoint() override
Definition remote.c:10976
int remote_hostio_pread_vFile(int fd, gdb_byte *read_buf, int len, ULONGEST offset, fileio_error *remote_errno)
Definition remote.c:12529
long get_memory_packet_size(struct memory_packet_config *config)
Definition remote.c:1975
int remove_exec_catchpoint(int) override
Definition remote.c:2596
ptid_t process_stop_reply(struct stop_reply *stop_reply, target_waitstatus *status)
Definition remote.c:8225
gdb::optional< std::string > fileio_readlink(struct inferior *inf, const char *filename, fileio_error *target_errno) override
Definition remote.c:12692
void set_remote_traceframe()
Definition remote.c:8753
thread_control_capabilities get_thread_control_capabilities() override
Definition remote.c:705
void trace_stop() override
Definition remote.c:13721
int fileio_open(struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, fileio_error *target_errno) override
Definition remote.c:12481
void interrupt() override
Definition remote.c:7288
ptid_t remote_current_thread(ptid_t oldpid)
Definition remote.c:3920
int remote_hostio_send_command(int command_bytes, int which_packet, fileio_error *remote_errno, const char **attachment, int *attachment_len)
Definition remote.c:12317
int get_min_fast_tracepoint_insn_len() override
Definition remote.c:13974
int fileio_fstat(int fd, struct stat *sb, fileio_error *target_errno) override
Definition remote.c:12730
void store_registers(struct regcache *, int) override
Definition remote.c:8930
void extended_remote_set_inferior_cwd()
Definition remote.c:10534
int trace_find(enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override
Definition remote.c:13734
struct btrace_target_info * enable_btrace(thread_info *tp, const struct btrace_config *conf) override
Definition remote.c:14563
char * append_pending_thread_resumptions(char *p, char *endp, ptid_t ptid)
Definition remote.c:6560
void kill() override
Definition remote.c:10239
~remote_target() override
Definition remote.c:4375
bool supports_string_tracing() override
Definition remote.c:13186
bool get_tib_address(ptid_t ptid, CORE_ADDR *addr) override
Definition remote.c:12058
static void open(const char *, int)
Definition remote.c:5262
bool stopped_by_watchpoint() override
Definition remote.c:10982
void extended_remote_environment_support()
Definition remote.c:10502
int remote_supports_fast_tracepoints()
Definition remote.c:13161
void pass_ctrlc() override
Definition remote.c:7301
int remote_vkill(int pid)
Definition remote.c:10285
CORE_ADDR get_thread_local_address(ptid_t ptid, CORE_ADDR load_module_addr, CORE_ADDR offset) override
Definition remote.c:12011
int remote_supports_static_tracepoints()
Definition remote.c:13167
int async_wait_fd() override
Definition remote.c:14867
void remote_file_delete(const char *remote_file, int from_tty)
Definition remote.c:13065
int remote_hostio_open(struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, fileio_error *remote_errno)
Definition remote.c:12438
struct stop_reply * queued_stop_reply(ptid_t ptid)
Definition remote.c:7621
inferior * remote_add_inferior(bool fake_pid_p, int pid, int attached, int try_open_exec)
Definition remote.c:2657
void detach(inferior *, int) override
Definition remote.c:6215
void set_circular_trace_buffer(int val) override
Definition remote.c:13940
int region_ok_for_hw_watchpoint(CORE_ADDR, int) override
Definition remote.c:10901
int remote_hostio_unlink(inferior *inf, const char *filename, fileio_error *remote_errno)
Definition remote.c:12663
void mourn_inferior() override
Definition remote.c:10342
void set_trace_buffer_size(LONGEST val) override
Definition remote.c:14003
bool can_use_agent() override
Definition remote.c:14101
int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) override
Definition remote.c:10754
int remote_supports_cond_tracepoints()
Definition remote.c:13147
void remote_supported_packet(const struct protocol_feature *feature, enum packet_support support, const char *argument)
bool supports_multi_process() override
Definition remote.c:13141
int can_use_hw_breakpoint(enum bptype, int, int) override
Definition remote.c:10914
void remote_file_put(const char *local_file, const char *remote_file, int from_tty)
Definition remote.c:12912
bool watchpoint_addr_within_range(CORE_ADDR, CORE_ADDR, int) override
Definition remote.c:10848
bool store_memtags(CORE_ADDR address, size_t len, const gdb::byte_vector &tags, int type) override
Definition remote.c:15216
void store_registers_using_G(const struct regcache *regcache)
Definition remote.c:8891
bool can_execute_reverse() override
Definition remote.c:13118
int remote_get_threads_with_ql(threads_listing_context *context)
Definition remote.c:3944
void disconnect(const char *, int) override
Definition remote.c:6280
int insert_breakpoint(struct gdbarch *, struct bp_target_info *) override
Definition remote.c:10694
void remote_parse_stop_reply(const char *buf, stop_reply *event)
Definition remote.c:7688
int remote_get_threads_with_qxfer(threads_listing_context *context)
Definition remote.c:4026
bool thread_alive(ptid_t ptid) override
Definition remote.c:3149
void disable_tracepoint(struct bp_location *location) override
Definition remote.c:13545
void thread_events(int) override
Definition remote.c:14909
void remote_vcont_probe()
Definition remote.c:6413
void update_thread_list() override
Definition remote.c:4103
remote_features m_features
Definition remote.c:1249
int remote_hostio_close(int fd, fileio_error *remote_errno)
Definition remote.c:12638
bool stopped_by_hw_breakpoint() override
Definition remote.c:10963
void set_disconnected_tracing(int val) override
Definition remote.c:13906
std::string pid_to_str(ptid_t) override
Definition remote.c:11970
void remote_serial_write(const char *str, int len)
Definition remote.c:9660
void remote_serial_quit_handler()
Definition remote.c:5844
LONGEST get_raw_trace_data(gdb_byte *buf, ULONGEST offset, LONGEST len) override
Definition remote.c:13868
char * remote_get_noisy_reply()
Definition remote.c:1552
target_xfer_status remote_write_qxfer(const char *object_name, const char *annex, const gdb_byte *writebuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len, const unsigned int which_packet)
Definition remote.c:11229
int save_trace_data(const char *filename) override
Definition remote.c:13840
int remote_get_threadlist(int startflag, threadref *nextthread, int result_limit, int *done, int *result_count, threadref *threadlist)
Definition remote.c:3723
int can_do_single_step() override
Definition remote.c:14766
const struct target_desc * read_description() override
Definition remote.c:12158
void remote_packet_size(const protocol_feature *feature, packet_support support, const char *value)
Definition remote.c:5456
void remote_kill_k()
Definition remote.c:10313
int remote_supports_install_in_trace()
Definition remote.c:13173
int insert_vfork_catchpoint(int) override
Definition remote.c:2569
void remote_resume_with_hc(ptid_t ptid, int step, gdb_signal siggnal)
Definition remote.c:6580
void check_binary_download(CORE_ADDR addr)
Definition remote.c:9052
int remove_hw_breakpoint(struct gdbarch *, struct bp_target_info *) override
Definition remote.c:11066
void program_signals(gdb::array_view< const unsigned char >) override
Definition remote.c:3010
const char * extra_thread_info(struct thread_info *) override
Definition remote.c:4199
bool set_trace_notes(const char *user, const char *notes, const char *stopnotes) override
Definition remote.c:14033
int insert_exec_catchpoint(int) override
Definition remote.c:2587
bool supports_memory_tagging() override
Definition remote.c:15132
int extended_remote_run(const std::string &args)
Definition remote.c:10414
int core_of_thread(ptid_t ptid) override
Definition remote.c:13929
int send_g_packet()
Definition remote.c:8605
bool can_async_p() override
Definition remote.c:14828
void set_permissions() override
Definition remote.c:5391
int remote_hostio_set_filesystem(struct inferior *inf, fileio_error *remote_errno)
Definition remote.c:12402
int stop_reply_queue_length()
Definition remote.c:7380
int search_memory(CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp) override
Definition remote.c:11558
void start_remote(int from_tty, int extended_p)
Definition remote.c:5240
int remote_get_threads_with_qthreadinfo(threads_listing_context *context)
Definition remote.c:4050
bool static_tracepoint_marker_at(CORE_ADDR, struct static_tracepoint_marker *marker) override
Definition remote.c:4277
bool supports_enable_disable_tracepoint() override
Definition remote.c:13179
void remote_interrupt_ns()
Definition remote.c:7244
void remote_query_supported()
Definition remote.c:5645
bool filesystem_is_local() override
Definition remote.c:12788
void send_interrupt_sequence()
Definition remote.c:4552
int putpkt_binary(const char *buf, int cnt)
Definition remote.c:9715
remote_state m_remote_state
Definition remote.c:1257
long get_memory_read_packet_size()
Definition remote.c:2225
void pass_signals(gdb::array_view< const unsigned char >) override
Definition remote.c:2890
void check_pending_events_prevent_wildcard_vcont(bool *may_global_wildcard_vcont)
Definition remote.c:7493
void send_environment_packet(const char *action, const char *packet, const char *value)
Definition remote.c:10478
void set_continue_thread(ptid_t ptid)
Definition remote.c:3096
void close() override
Definition remote.c:4365
const char * connection_string() override
Definition remote.c:5248
void rcmd(const char *command, struct ui_file *output) override
Definition remote.c:11654
void push_stop_reply(struct stop_reply *new_event)
Definition remote.c:7640
void btrace_sync_conf(const btrace_config *conf)
Definition remote.c:14434
void skip_frame()
Definition remote.c:9876
void remove_new_fork_children(threads_listing_context *context)
Definition remote.c:7457
int fetch_register_using_p(struct regcache *regcache, packet_reg *reg)
Definition remote.c:8543
const char * pid_to_exec_file(int pid) override
Definition remote.c:14737
int store_register_using_P(const struct regcache *regcache, packet_reg *reg)
Definition remote.c:8850
void set_general_thread(ptid_t ptid)
Definition remote.c:3090
enum exec_direction_kind execution_direction() override
Definition remote.c:14787
int get_trace_status(struct trace_status *ts) override
Definition remote.c:13626
int putpkt(const char *buf)
Definition remote.c:9694
target_xfer_status remote_read_bytes(CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition remote.c:9441
ptid_t get_current_thread(const char *wait_status)
Definition remote.c:4615
void fetch_registers(struct regcache *, int) override
Definition remote.c:8773
thread_info * add_current_inferior_and_thread(const char *wait_status)
Definition remote.c:4644
long get_remote_packet_size(void)
Definition remote.c:1823
int remove_fork_catchpoint(int) override
Definition remote.c:2560
void trace_start() override
Definition remote.c:13613
int remote_query_attached(int pid)
Definition remote.c:2613
void trace_set_readonly_regions() override
Definition remote.c:13561
long read_frame(gdb::char_vector *buf_p)
Definition remote.c:9918
void remote_stop_ns(ptid_t ptid)
Definition remote.c:7105
void follow_fork(inferior *, ptid_t, target_waitkind, bool, bool) override
Definition remote.c:6234
int fileio_pread(int fd, gdb_byte *read_buf, int len, ULONGEST offset, fileio_error *target_errno) override
Definition remote.c:12629
int insert_fork_catchpoint(int) override
Definition remote.c:2551
void flash_done() override
Definition remote.c:9569
void async(bool) override
Definition remote.c:14874
const target_info & info() const override
Definition remote.c:700
traceframe_info_up traceframe_info() override
Definition remote.c:13956
void commit_resumed() override
Definition remote.c:6894
target_xfer_status remote_write_bytes(CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition remote.c:9301
gdb::array_view< const gdb_byte > thread_info_to_thread_handle(struct thread_info *tp) override
Definition remote.c:14821
int set_syscall_catchpoint(int, bool, int, gdb::array_view< const int >) override
Definition remote.c:2939
char * write_ptid(char *buf, const char *endbuf, ptid_t ptid)
Definition remote.c:3265
void enable_tracepoint(struct bp_location *location) override
Definition remote.c:13529
void extended_remote_disable_randomization(int val)
Definition remote.c:10398
void fetch_registers_using_g(struct regcache *regcache)
Definition remote.c:8743
remote_target * m_remote
Definition remote.c:12894
scoped_remote_fd(remote_target *remote, int fd)
Definition remote.c:12853
DISABLE_COPY_AND_ASSIGN(scoped_remote_fd)
int get() const noexcept
Definition remote.c:12887
ATTRIBUTE_UNUSED_RESULT int release() noexcept
Definition remote.c:12879
std::string release()
Definition ui-file.h:204
const std::string & string()
Definition ui-file.h:198
static void inferior()
Definition target.c:952
static void ours_for_output()
Definition target.c:1088
static bool is_ours()
Definition target.h:189
void set_pending_waitstatus(const target_waitstatus &ws)
Definition thread.c:408
enum thread_state state
Definition gdbthread.h:339
int per_inf_num
Definition gdbthread.h:298
void set_running(bool running)
Definition thread.c:884
ptid_t ptid
Definition gdbthread.h:259
bool has_pending_waitstatus() const
Definition gdbthread.h:394
void clear_pending_waitstatus()
Definition thread.c:422
struct target_waitstatus pending_follow
Definition gdbthread.h:516
const target_waitstatus & pending_waitstatus() const
Definition gdbthread.h:403
private_thread_info_up priv
Definition gdbthread.h:528
struct inferior * inf
Definition gdbthread.h:301
void set_stop_pc(CORE_ADDR stop_pc)
Definition gdbthread.h:372
void set_stop_signal(gdb_signal sig)
Definition gdbthread.h:431
thread_control_state control
Definition gdbthread.h:343
void putstrn(const char *str, int n, int quoter, bool async_safe=false)
Definition ui-file.c:57
virtual void puts(const char *str)
Definition ui-file.h:76
virtual void flush()
Definition ui-file.h:96
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void text(const char *string)
Definition ui-out.c:566
remote_target * m_remote
Definition remote.c:6810
void restart()
Definition remote.c:6826
vcont_builder(remote_target *remote)
Definition remote.c:6797
void push_action(ptid_t ptid, bool step, gdb_signal siggnal)
Definition remote.c:6866
char * m_p
Definition remote.c:6817
char * m_first_action
Definition remote.c:6814
void flush()
Definition remote.c:6840
char * m_endp
Definition remote.c:6820
struct cmd_list_element * showlist
Definition cli-cmds.c:127
void error_no_arg(const char *why)
Definition cli-cmds.c:206
struct cmd_list_element * cmdlist
Definition cli-cmds.c:87
struct cmd_list_element * setlist
Definition cli-cmds.c:119
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * maintenancelist
Definition cli-cmds.c:143
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition cli-decode.c:294
set_show_commands add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
set_show_commands add_setshow_zuinteger_unlimited_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void cmd_func(struct cmd_list_element *cmd, const char *args, int from_tty)
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:688
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition cli-decode.c:280
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
set_show_commands add_setshow_string_noescape_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:953
set_show_commands add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:752
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:391
set_show_commands add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
@ not_set_cmd
Definition cli-decode.h:37
@ show_cmd
Definition cli-decode.h:39
@ while_stepping_control
Definition cli-script.h:46
@ while_control
Definition cli-script.h:40
void do_show_command(const char *arg, int from_tty, struct cmd_list_element *c)
@ class_obscure
Definition command.h:64
@ class_maintenance
Definition command.h:65
@ class_support
Definition command.h:58
@ class_run
Definition command.h:54
@ class_files
Definition command.h:57
@ no_class
Definition command.h:53
void reopen_exec_file(void)
Definition corefile.c:106
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:238
const char * get_exec_file(int err)
Definition corefile.c:150
void quit(void)
Definition utils.c:634
int check_quit_flag(void)
Definition extension.c:857
quit_handler_ftype * quit_handler
Definition event-top.c:1080
void set_quit_flag(void)
Definition extension.c:833
bool info_verbose
Definition top.c:1941
auto_boolean
Definition defs.h:247
@ AUTO_BOOLEAN_TRUE
Definition defs.h:248
@ AUTO_BOOLEAN_AUTO
Definition defs.h:250
@ AUTO_BOOLEAN_FALSE
Definition defs.h:249
#define QUIT
Definition defs.h:187
std::string gdb_sysroot
Definition main.c:64
int gdb_insn_length(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition disasm.c:1230
void exception_fprintf(struct ui_file *file, const struct gdb_exception &e, const char *prefix,...)
Definition exceptions.c:116
void exec_file_locate_attach(int pid, int defer_bp_reset, int from_tty)
Definition exec.c:314
void validate_exec_file(int from_tty)
Definition exec.c:213
static int quit_flag
Definition extension.c:640
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
frame_info_ptr get_current_frame(void)
Definition frame.c:1670
void set_current_sal_from_frame(frame_info_ptr)
Definition stack.c:921
static void ATTRIBUTE_PRINTF(1, 0)
Definition gdb_bfd.c:1154
int is_target_filename(const char *name)
Definition gdb_bfd.c:207
#define TARGET_SYSROOT_PREFIX
Definition gdb_bfd.h:41
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition gdbarch.c:2173
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1739
int gdbarch_has_global_breakpoints(struct gdbarch *gdbarch)
Definition gdbarch.c:4871
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition gdbarch.c:1930
int gdbarch_fast_tracepoint_valid_at(struct gdbarch *gdbarch, CORE_ADDR addr, std::string *msg)
Definition gdbarch.c:4905
const struct target_desc * gdbarch_target_desc(struct gdbarch *gdbarch)
Definition gdbarch.c:1423
int gdbarch_remote_register_number(struct gdbarch *gdbarch, int regno)
Definition gdbarch.c:2937
int gdbarch_has_global_solist(struct gdbarch *gdbarch)
Definition gdbarch.c:4854
void gdbarch_relocate_instruction(struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from)
Definition gdbarch.c:4265
int gdbarch_addressable_memory_unit_size(struct gdbarch *gdbarch)
Definition gdbarch.c:5300
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition gdbarch.c:3135
struct thread_info * any_live_thread_of_inferior(inferior *inf)
Definition thread.c:663
all_threads_safe_range all_threads_safe()
Definition gdbthread.h:770
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:336
int thread_count(process_stratum_target *proc_target)
Definition thread.c:605
struct thread_info * add_thread_silent(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:296
struct thread_info * first_thread_of_inferior(inferior *inf)
Definition thread.c:639
void delete_thread(thread_info *thread)
Definition thread.c:527
void switch_to_thread_no_regs(struct thread_info *thread)
Definition thread.c:1328
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:753
@ THREAD_STOPPED
Definition gdbthread.h:72
@ THREAD_RUNNING
Definition gdbthread.h:75
@ THREAD_EXITED
Definition gdbthread.h:79
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
Definition thread.c:908
struct thread_info * inferior_thread(void)
Definition thread.c:85
void switch_to_thread(struct thread_info *thr)
Definition thread.c:1360
void set_running(process_stratum_target *targ, ptid_t ptid, bool running)
Definition thread.c:891
void thread_change_ptid(process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid)
Definition thread.c:811
struct thread_info * any_thread_of_inferior(inferior *inf)
Definition thread.c:648
int thread_is_in_step_over_chain(struct thread_info *tp)
Definition thread.c:435
void prune_threads(void)
Definition thread.c:737
bool in_thread_list(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:631
void switch_to_no_thread()
Definition thread.c:1345
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition gnu-nat.c:1789
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1791
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
size_t size
Definition go32-nat.c:239
unsigned available
Definition go32-nat.c:7
void inferior_event_handler(enum inferior_event_type event_type)
Definition inf-loop.c:37
ptid_t inferior_ptid
Definition infcmd.c:74
void setup_inferior(int from_tty)
Definition infcmd.c:2538
void notice_new_inferior(thread_info *thr, bool leave_running, int from_tty)
Definition infcmd.c:2788
void inferior_appeared(struct inferior *inf, int pid)
Definition inferior.c:363
struct inferior * add_inferior_with_spaces(void)
Definition inferior.c:832
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
Definition inferior.c:406
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
Definition inferior.c:389
bool print_inferior_events
Definition inferior.c:47
void detach_inferior(inferior *inf)
Definition inferior.c:340
struct inferior * current_inferior(void)
Definition inferior.c:55
struct inferior * add_inferior(int pid)
Definition inferior.c:218
void switch_to_inferior_no_thread(inferior *inf)
Definition inferior.c:712
int number_of_live_inferiors(process_stratum_target *proc_target)
Definition inferior.c:442
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:821
void generic_mourn_inferior(void)
Definition target.c:3661
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:830
void update_signals_program_target(void)
Definition infrun.c:360
void notify_signal_received(gdb_signal sig)
Definition infrun.c:6360
int signal_print_state(int signo)
Definition infrun.c:9091
static bool detach_fork
Definition infrun.c:185
void set_last_target_status(process_stratum_target *target, ptid_t ptid, const target_waitstatus &status)
Definition infrun.c:4610
void notify_normal_stop(bpstat *bs, int print_frame)
Definition infrun.c:6369
bool non_stop
Definition infrun.c:226
static bool follow_fork()
Definition infrun.c:740
bool disable_randomization
Definition infrun.c:197
int signal_pass_state(int signo)
Definition infrun.c:9097
void stop_all_threads(const char *reason, inferior *inf)
Definition infrun.c:5315
void init_wait_for_inferior(void)
Definition infrun.c:3639
void print_target_wait_results(ptid_t waiton_ptid, ptid_t result_ptid, const struct target_waitstatus &ws)
Definition infrun.c:3783
exec_direction_kind
Definition infrun.h:112
@ EXEC_REVERSE
Definition infrun.h:114
@ EXEC_FORWARD
Definition infrun.h:113
static void scan(growable_macro_buffer *dest, shared_macro_buffer *src, struct macro_name_list *no_loop, const macro_scope &scope)
Definition macroexp.c:1358
struct ui_file * gdb_stdtarg
Definition main.c:80
int memory_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason)
Definition mem-break.c:96
int memory_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition mem-break.c:89
std::vector< mem_region > parse_memory_map(const char *memory_map)
Definition memory-map.c:26
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
observable< struct objfile * > new_objfile
observable< program_space * > all_objfiles_removed
info(Component c)
Definition gdbarch.py:41
void objfile_relocate(struct objfile *objfile, const section_offsets &new_offsets)
Definition objfiles.c:676
#define SECT_OFF_BSS(objfile)
Definition objfiles.h:147
#define SECT_OFF_DATA(objfile)
Definition objfiles.h:129
#define SECT_OFF_TEXT(objfile)
Definition objfiles.h:139
#define prefix(a, b, R, do)
Definition ppc64-tdep.c:52
void switch_to_target_no_thread(process_stratum_target *target)
struct program_space * current_program_space
Definition progspace.c:40
struct address_space * maybe_new_address_space(void)
Definition progspace.c:59
void update_address_spaces(void)
Definition progspace.c:403
int value
Definition py-param.c:79
void record_btrace_push_target(void)
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
struct regcache * get_thread_arch_regcache(process_stratum_target *target, ptid_t ptid, struct gdbarch *gdbarch)
Definition regcache.c:384
void remote_fileio_request(remote_target *remote, char *buf, int ctrlc_pending_p)
void remote_fileio_to_host_stat(struct fio_stat *fst, struct stat *st)
void initialize_remote_fileio(struct cmd_list_element **remote_set_cmdlist, struct cmd_list_element **remote_show_cmdlist)
void remote_fileio_reset(void)
void handle_notification(struct remote_notif_state *state, const char *buf)
struct remote_notif_state * remote_notif_state_allocate(remote_target *remote)
void remote_notif_process(struct remote_notif_state *state, const notif_client *except)
bool notif_debug
void remote_notif_ack(remote_target *remote, const notif_client *nc, const char *buf)
struct notif_event * remote_notif_parse(remote_target *remote, const notif_client *nc, const char *buf)
std::unique_ptr< notif_event > notif_event_up
@ REMOTE_NOTIF_STOP
static void remote_async_inferior_event_handler(gdb_client_data)
Definition remote.c:14861
static packet_config remote_protocol_packets[PACKET_MAX]
Definition remote.c:627
static const struct protocol_feature remote_protocol_features[]
Definition remote.c:5494
static int watchdog
Definition remote.c:10033
bool is_remote_target(process_stratum_target *target)
Definition remote.c:1332
static int remote_packet_max_chars
Definition remote.c:2170
static void record_currthread(struct remote_state *rs, ptid_t currthread)
Definition remote.c:2881
static bool is_fork_status(target_waitkind kind)
Definition remote.c:6072
static int hexnumlen(ULONGEST num)
Definition remote.c:8977
static void show_remote_timeout(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:15121
static void show_remote_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:15113
static int remote_hw_breakpoint_limit
Definition remote.c:10898
static char * pack_threadid(char *pkt, threadref *id)
Definition remote.c:3431
#define TAG_MOREDISPLAY
Definition remote.c:3224
static int hexnumstr(char *, ULONGEST)
Definition remote.c:8990
static int stub_unpack_int(const char *buff, int fieldlength)
Definition remote.c:3350
static void resume_clear_thread_private_info(struct thread_info *thread)
Definition remote.c:6545
static void remote_unpush_and_throw(remote_target *target)
Definition remote.c:5911
static notif_event_up remote_notif_stop_alloc_reply()
Definition remote.c:7432
static void show_watchdog(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:10035
static const registry< gdbarch >::key< struct remote_g_packet_data > remote_g_packet_data_handle
Definition remote.c:12118
static void remote_put_command(const char *args, int from_tty)
Definition remote.c:13079
packet_result
Definition remote.c:153
@ PACKET_ERROR
Definition remote.c:154
@ PACKET_OK
Definition remote.c:155
@ PACKET_UNKNOWN
Definition remote.c:156
static const target_waitstatus * thread_pending_fork_status(struct thread_info *thread)
Definition remote.c:6082
static bool parse_fetch_memtags_reply(const gdb::char_vector &reply, gdb::byte_vector &tags)
Definition remote.c:15158
static void create_store_memtags_request(gdb::char_vector &packet, CORE_ADDR address, size_t len, int type, const gdb::byte_vector &tags)
Definition remote.c:15173
static int align_for_efficient_write(int todo, CORE_ADDR memaddr)
Definition remote.c:9097
static void show_interrupt_sequence(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:1884
static enum Z_packet_type watchpoint_to_Z_packet(int type)
Definition remote.c:10789
static int threadref_to_int(threadref *ref)
Definition remote.c:3485
resume_state
Definition remote.c:1413
#define TAG_EXISTS
Definition remote.c:3221
static const int remote_flash_timeout
Definition remote.c:9533
std::unique_ptr< stop_reply > stop_reply_up
Definition remote.c:106
static void set_remote_exec_file(const char *ignored, int from_tty, struct cmd_list_element *c)
Definition remote.c:1694
static unsigned int remote_address_size
Definition remote.c:1945
static const ptid_t not_sent_ptid(42000, -2, 1)
static void remote_add_target_side_commands(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, char *buf)
Definition remote.c:10666
static void remote_query_supported_append(std::string *msg, const char *append)
Definition remote.c:5637
static void unpush_and_perror(remote_target *target, const char *string)
Definition remote.c:9600
void register_remote_support_xml(const char *xml)
Definition remote.c:5606
static int remote_add_target_side_condition(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, char *buf, char *buf_end)
Definition remote.c:10642
static const char * interrupt_sequence_mode
Definition remote.c:1881
#define BUF_THREAD_ID_SIZE
Definition remote.c:3226
static void remote_objfile_changed_check_symbols(program_space *pspace)
Definition remote.c:14968
static struct packet_reg * packet_reg_from_pnum(struct gdbarch *gdbarch, struct remote_arch_state *rsa, LONGEST pnum)
Definition remote.c:1850
@ REMOTE_ALIGN_WRITES
Definition remote.c:1357
static void remote_get_command(const char *args, int from_tty)
Definition remote.c:13092
unsigned char threadref[OPAQUETHREADBYTES]
Definition remote.c:97
static int remote_thread_always_alive(ptid_t ptid)
Definition remote.c:3130
#define TAG_THREADID
Definition remote.c:3220
static void remote_delete_command(const char *args, int from_tty)
Definition remote.c:13105
void remote_file_delete(const char *remote_file, int from_tty)
Definition remote.c:13054
static const ptid_t any_thread_ptid(42000, 0, 1)
static void trace_error(char *buf)
Definition remote.c:1532
static void init_all_packet_configs(void)
Definition remote.c:5288
static void remote_serial_quit_handler()
Definition remote.c:5877
static long get_fixed_memory_packet_size(struct memory_packet_config *config)
Definition remote.c:1961
static const char * unpack_nibble(const char *buf, int *val)
Definition remote.c:3367
static void show_memory_packet_size(memory_packet_config *config, remote_target *remote)
Definition remote.c:2075
static remote_inferior * get_remote_inferior(inferior *inf)
Definition remote.c:6782
static char * pack_int(char *buf, int value)
Definition remote.c:3381
static remote_target * as_remote_target(process_stratum_target *target)
Definition remote.c:1324
static void remote_buffer_add_string(char **buffer, int *left, const char *string)
Definition remote.c:12191
void send_remote_packet(gdb::array_view< const char > &buf, send_remote_packet_callbacks *callbacks)
Definition remote.c:11785
static memory_packet_config memory_read_packet_config
Definition remote.c:614
static char * remote_support_xml
Definition remote.c:5601
#define MIN_MEMORY_PACKET_SIZE
Definition remote.c:1956
static memory_packet_config memory_write_packet_config
Definition remote.c:618
static void copy_threadref(threadref *dest, threadref *src)
Definition remote.c:3499
static const char * unpack_threadid(const char *inbuf, threadref *id)
Definition remote.c:3445
static const char * unpack_int(const char *buf, int *value)
Definition remote.c:3391
static enum auto_boolean remote_Z_packet_detect
Definition remote.c:2510
static void remote_unpush_target(remote_target *target)
Definition remote.c:5887
static void add_packet_config_cmd(const unsigned int which_packet, const char *name, const char *title, int legacy)
Definition remote.c:2316
static char * remote_hostio_error(fileio_error errnum)
Definition remote.c:12838
static void set_pspace_remote_exec_file(struct program_space *pspace, const char *remote_exec_file)
Definition remote.c:1682
static packet_description packets_descriptions[PACKET_MAX]
Definition remote.c:624
static int strprefix(const char *p, const char *pend, const char *prefix)
Definition remote.c:7676
static void show_hardware_watchpoint_length_limit(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2148
static struct packet_reg * packet_reg_from_regnum(struct gdbarch *gdbarch, struct remote_arch_state *rsa, long regnum)
Definition remote.c:1835
void remote_notif_get_pending_events(remote_target *remote, const notif_client *nc)
Definition remote.c:8105
static int map_regcache_remote_table(struct gdbarch *gdbarch, struct packet_reg *regs)
Definition remote.c:1711
static void show_remote_cmd(const char *args, int from_tty)
Definition remote.c:14936
const notif_client notif_client_stop
Definition remote.c:7439
static int remote_newthread_step(threadref *ref, void *context)
Definition remote.c:3904
static void show_packet_config_cmd(ui_file *file, const unsigned int which_packet, remote_target *remote)
Definition remote.c:2272
static void remote_new_objfile(struct objfile *objfile)
Definition remote.c:15021
#define CRAZY_MAX_THREADS
Definition remote.c:3917
static void show_memory_read_packet_size(const char *args, int from_tty)
Definition remote.c:2214
static void show_remote_exec_file(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
Definition remote.c:1704
static void show_remote_protocol_Z_packet_cmd(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2536
int remote_register_number_and_offset(struct gdbarch *gdbarch, int regnum, int *pnum, int *poffset)
Definition remote.c:1761
static remote_target * get_current_remote_target()
Definition remote.c:1813
static void remote_packet_size(remote_target *remote, const protocol_feature *feature, enum packet_support support, const char *value)
Definition remote.c:5488
#define MAX_ACTION_SIZE
Definition remote.c:6858
static const target_info extended_remote_target_info
Definition remote.c:1260
static void show_remote_protocol_packet_cmd(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2476
static void create_fetch_memtags_request(gdb::char_vector &packet, CORE_ADDR address, size_t len, int type)
Definition remote.c:15140
static int remote_hw_watchpoint_length_limit
Definition remote.c:10897
void remote_file_put(const char *local_file, const char *remote_file, int from_tty)
Definition remote.c:12901
static int stubhex(int ch)
Definition remote.c:3338
static enum packet_support packet_config_support(const packet_config *config)
Definition remote.c:2453
static bool interrupt_on_connect
Definition remote.c:1911
static void compare_sections_command(const char *args, int from_tty)
Definition remote.c:11156
static void show_hardware_watchpoint_limit(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2137
static std::string escape_buffer(const char *buf, int n)
Definition remote.c:9685
static char * pack_threadlist_request(char *pkt, int startflag, int threadcount, threadref *nextthread)
Definition remote.c:3677
static int remote_notif_stop_can_get_pending_events(remote_target *remote, const notif_client *self)
Definition remote.c:7412
const char interrupt_sequence_control_c[]
Definition remote.c:1871
static ptid_t first_remote_resumed_thread(remote_target *target)
Definition remote.c:8341
static const registry< program_space >::key< char, gdb::xfree_deleter< char > > remote_pspace_data
Definition remote.c:1339
static int remote_hw_watchpoint_limit
Definition remote.c:10896
static char * pack_threadinfo_request(char *pkt, int mode, threadref *id)
Definition remote.c:3540
static remote_thread_info * get_remote_thread_info(thread_info *thread)
Definition remote.c:2856
bool remote_debug
Definition remote.c:92
static void remote_notif_stop_ack(remote_target *remote, const notif_client *self, const char *buf, struct notif_event *event)
Definition remote.c:7395
static void parse_xml_btrace_conf(struct btrace_config *conf, const char *xml)
Definition remote.c:14405
static ptid_t stop_reply_extract_thread(const char *stop_reply)
Definition remote.c:4575
static const char * unpack_byte(const char *buf, int *value)
Definition remote.c:3374
static struct cmd_list_element * remote_show_cmdlist
Definition remote.c:1404
static std::string remote_exec_file_var
Definition remote.c:1345
static int threadmatch(threadref *dest, threadref *src)
Definition remote.c:3512
static void set_memory_read_packet_size(const char *args, int from_tty)
Definition remote.c:2195
static const char *const interrupt_sequence_modes[]
Definition remote.c:1874
static void remote_supported_packet(remote_target *remote, const struct protocol_feature *feature, enum packet_support support, const char *argument)
Definition remote.c:5440
const char interrupt_sequence_break_g[]
Definition remote.c:1873
static void parse_xml_btrace(struct btrace_data *btrace, const char *buffer)
Definition remote.c:14305
static void remote_buffer_add_int(char **buffer, int *left, ULONGEST value)
Definition remote.c:12234
void register_remote_g_packet_guess(struct gdbarch *gdbarch, int bytes, const struct target_desc *tdesc)
Definition remote.c:12131
static void show_remotebreak(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:1928
static int hexnumnstr(char *, ULONGEST, int)
Definition remote.c:9001
@ PACKET_qTStatus
Definition remote.c:194
@ PACKET_Z3
Definition remote.c:170
@ PACKET_swbreak_feature
Definition remote.c:275
@ PACKET_exec_event_feature
Definition remote.c:290
@ PACKET_TracepointSource
Definition remote.c:234
@ PACKET_vFile_fstat
Definition remote.c:179
@ PACKET_qXfer_threads
Definition remote.c:187
@ PACKET_qXfer_btrace
Definition remote.c:243
@ PACKET_P
Definition remote.c:165
@ PACKET_qXfer_siginfo_write
Definition remote.c:210
@ PACKET_Qbtrace_off
Definition remote.c:240
@ PACKET_QAllow
Definition remote.c:235
@ PACKET_Z0
Definition remote.c:167
@ PACKET_memory_tagging_feature
Definition remote.c:303
@ PACKET_bc
Definition remote.c:232
@ PACKET_no_resumed
Definition remote.c:299
@ PACKET_vKill
Definition remote.c:208
@ PACKET_QStartupWithShell
Definition remote.c:199
@ PACKET_qXfer_statictrace_read
Definition remote.c:188
@ PACKET_qXfer_features
Definition remote.c:181
@ PACKET_QProgramSignals
Definition remote.c:197
@ PACKET_QEnvironmentHexEncoded
Definition remote.c:200
@ PACKET_Z4
Definition remote.c:171
@ PACKET_InstallInTrace
Definition remote.c:230
@ PACKET_vFile_pwrite
Definition remote.c:175
@ PACKET_qXfer_fdpic
Definition remote.c:236
@ PACKET_vCont
Definition remote.c:162
@ PACKET_qAttached
Definition remote.c:211
@ PACKET_QCatchSyscalls
Definition remote.c:196
@ PACKET_vContSupported
Definition remote.c:293
@ PACKET_EnableDisableTracepoints_feature
Definition remote.c:256
@ PACKET_hwbreak_feature
Definition remote.c:278
@ PACKET_QTBuffer_size
Definition remote.c:239
@ PACKET_vFile_setfs
Definition remote.c:172
@ PACKET_qSymbol
Definition remote.c:164
@ PACKET_QAgent
Definition remote.c:238
@ PACKET_bs
Definition remote.c:233
@ PACKET_qXfer_siginfo_read
Definition remote.c:209
@ PACKET_QThreadEvents
Definition remote.c:249
@ PACKET_vFile_close
Definition remote.c:176
@ PACKET_augmented_libraries_svr4_read_feature
Definition remote.c:266
@ PACKET_qXfer_btrace_conf
Definition remote.c:269
@ PACKET_QEnvironmentReset
Definition remote.c:201
@ PACKET_qCRC
Definition remote.c:203
@ PACKET_StaticTracepoints
Definition remote.c:226
@ PACKET_fork_event_feature
Definition remote.c:281
@ PACKET_ConditionalBreakpoints
Definition remote.c:217
@ PACKET_vRun
Definition remote.c:206
@ PACKET_QPassSignals
Definition remote.c:195
@ PACKET_QEnvironmentUnset
Definition remote.c:202
@ PACKET_qGetTLSAddr
Definition remote.c:192
@ PACKET_vFile_readlink
Definition remote.c:178
@ PACKET_vFile_pread
Definition remote.c:174
@ PACKET_qXfer_memory_map
Definition remote.c:185
@ PACKET_FastTracepoints
Definition remote.c:223
@ PACKET_Z2
Definition remote.c:169
@ PACKET_QDisableRandomization
Definition remote.c:237
@ PACKET_QNonStop
Definition remote.c:246
@ PACKET_MAX
Definition remote.c:305
@ PACKET_vfork_event_feature
Definition remote.c:284
@ PACKET_vFile_open
Definition remote.c:173
@ PACKET_Qbtrace_conf_bts_size
Definition remote.c:272
@ PACKET_tracenz_feature
Definition remote.c:259
@ PACKET_qXfer_traceframe_info
Definition remote.c:189
@ PACKET_multiprocess_feature
Definition remote.c:252
@ PACKET_vAttach
Definition remote.c:205
@ PACKET_ConditionalTracepoints
Definition remote.c:214
@ PACKET_qXfer_exec_file
Definition remote.c:182
@ PACKET_p
Definition remote.c:166
@ PACKET_X
Definition remote.c:163
@ PACKET_vCtrlC
Definition remote.c:296
@ PACKET_qXfer_osdata
Definition remote.c:186
@ PACKET_QSetWorkingDir
Definition remote.c:198
@ PACKET_qSupported
Definition remote.c:193
@ PACKET_qGetTIBAddr
Definition remote.c:191
@ PACKET_qXfer_uib
Definition remote.c:190
@ PACKET_Z1
Definition remote.c:168
@ PACKET_QStartNoAckMode
Definition remote.c:207
@ PACKET_BreakpointCommands
Definition remote.c:220
@ PACKET_qXfer_auxv
Definition remote.c:180
@ PACKET_qSearch_memory
Definition remote.c:204
@ PACKET_DisconnectedTracing_feature
Definition remote.c:263
@ PACKET_Qbtrace_bts
Definition remote.c:241
@ PACKET_qXfer_libraries_svr4
Definition remote.c:184
@ PACKET_qXfer_libraries
Definition remote.c:183
@ PACKET_Qbtrace_conf_pt_size
Definition remote.c:287
@ PACKET_Qbtrace_pt
Definition remote.c:242
@ PACKET_vFile_unlink
Definition remote.c:177
const char interrupt_sequence_break[]
Definition remote.c:1872
Z_packet_type
Definition remote.c:2498
@ Z_PACKET_HARDWARE_BP
Definition remote.c:2500
@ NR_Z_PACKET_TYPES
Definition remote.c:2504
@ Z_PACKET_WRITE_WP
Definition remote.c:2501
@ Z_PACKET_ACCESS_WP
Definition remote.c:2503
@ Z_PACKET_READ_WP
Definition remote.c:2502
@ Z_PACKET_SOFTWARE_BP
Definition remote.c:2499
#define OPAQUETHREADBYTES
Definition remote.c:94
static void set_remotebreak(const char *args, int from_tty, struct cmd_list_element *c)
Definition remote.c:1919
static void set_memory_packet_size(const char *args, struct memory_packet_config *config, bool target_connected)
Definition remote.c:2013
static void remote_buffer_add_bytes(char **buffer, int *left, const gdb_byte *bytes, int len)
Definition remote.c:12213
static remote_target * curr_quit_handler_target
Definition remote.c:5874
static bool has_single_non_exited_thread(inferior *inf)
Definition remote.c:4090
void _initialize_remote()
Definition remote.c:15333
static int remote_hostio_parse_result(const char *buffer, int *retcode, fileio_error *remote_errno, const char **attachment)
Definition remote.c:12261
static void remote_btrace_reset(remote_state *rs)
Definition remote.c:14426
static void show_range_stepping(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:15076
static void show_hardware_breakpoint_limit(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2159
static void btrace_read_config(thread_info *tp, btrace_config *conf)
Definition remote.c:14493
static struct cmd_list_element * remote_cmdlist
Definition remote.c:1399
static struct serial * remote_serial_open(const char *name)
Definition remote.c:5362
static const target_info remote_target_info
Definition remote.c:564
void int_to_threadref(threadref *id, int value)
Definition remote.c:3468
static bool use_range_stepping
Definition remote.c:1408
static const char remote_doc[]
Definition remote.c:85
int gdb_threadref
Definition remote.c:3198
static void set_memory_write_packet_size(const char *args, int from_tty)
Definition remote.c:2104
static void set_remote_protocol_Z_packet_cmd(const char *args, int from_tty, struct cmd_list_element *c)
Definition remote.c:2513
packet_support
Definition remote.c:113
@ PACKET_DISABLE
Definition remote.c:116
@ PACKET_SUPPORT_UNKNOWN
Definition remote.c:114
@ PACKET_ENABLE
Definition remote.c:115
static struct cmd_list_element * remote_set_cmdlist
Definition remote.c:1403
int putpkt(remote_target *remote, const char *buf)
Definition remote.c:9703
void remote_file_get(const char *remote_file, const char *local_file, int from_tty)
Definition remote.c:12994
static void cli_packet_command(const char *args, int from_tty)
Definition remote.c:11811
static const char * get_remote_exec_file(void)
Definition remote.c:1668
#define MAXTHREADLISTRESULTS
Definition remote.c:332
static void set_remote_protocol_packet_cmd(const char *args, int from_tty, cmd_list_element *c)
Definition remote.c:2241
int(* rmt_thread_action)(threadref *ref, void *context)
Definition remote.c:101
static const char * get_target_type_name(bool target_connected)
Definition remote.c:141
#define TAG_DISPLAY
Definition remote.c:3222
static serial_event_ftype remote_async_serial_handler
Definition remote.c:14850
#define DEFAULT_MAX_MEMORY_PACKET_SIZE_FIXED
Definition remote.c:1952
static void remote_notif_stop_parse(remote_target *remote, const notif_client *self, const char *buf, struct notif_event *event)
Definition remote.c:7387
static const char * get_packet_support_name(auto_boolean support)
Definition remote.c:122
static CORE_ADDR remote_address_masked(CORE_ADDR)
Definition remote.c:9019
static enum packet_result packet_check_result(const char *buf)
Definition remote.c:2360
static void show_remote_packet_max_chars(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition remote.c:2176
static ptid_t read_ptid(const char *buf, const char **obuf)
Definition remote.c:3291
static struct remote_g_packet_data * get_g_packet_data(struct gdbarch *gdbarch)
Definition remote.c:12121
static void remote_console_output(const char *msg)
Definition remote.c:7361
static bool remote_break
Definition remote.c:1916
static const ptid_t magic_null_ptid(42000, -1, 1)
static bool remote_read_description_p(struct target_ops *target)
Definition remote.c:12150
bool remote_target_is_non_stop_p(remote_target *t)
Definition remote.c:15237
static const char * unpack_string(const char *src, char *dest, int length)
Definition remote.c:3422
#define MAX_TRIES
static void show_memory_write_packet_size(const char *args, int from_tty)
Definition remote.c:2124
#define TAG_THREADNAME
Definition remote.c:3223
static void set_range_stepping(const char *ignore_args, int from_tty, struct cmd_list_element *c)
Definition remote.c:15098
#define REMOTE_SCOPED_DEBUG_ENTER_EXIT
Definition remote.h:46
#define remote_debug_printf_nofunc(fmt,...)
Definition remote.h:40
#define remote_debug_printf(fmt,...)
Definition remote.h:35
#define enable()
Definition ser-go32.c:239
int serial_send_break(struct serial *scb)
Definition serial.c:475
int serial_setparity(struct serial *scb, int parity)
Definition serial.c:530
int serial_write(struct serial *scb, const void *buf, size_t count)
Definition serial.c:413
void serial_raw(struct serial *scb)
Definition serial.c:484
int baud_rate
Definition serial.c:622
int serial_can_async_p(struct serial *scb)
Definition serial.c:536
void serial_log_command(struct target_ops *self, const char *cmd)
Definition serial.c:127
int serial_readchar(struct serial *scb, int timeout)
Definition serial.c:383
void serial_async(struct serial *scb, serial_event_ftype *handler, void *context)
Definition serial.c:548
int serial_parity
Definition serial.c:634
struct serial * serial_open(const char *name)
Definition serial.c:198
int serial_flush_input(struct serial *scb)
Definition serial.c:469
int serial_setbaudrate(struct serial *scb, int rate)
Definition serial.c:516
int serial_is_async_p(struct serial *scb)
Definition serial.c:542
void serial_close(struct serial *scb)
Definition serial.c:351
void serial_event_ftype(struct serial *scb, void *context)
Definition serial.h:216
serial_rc
Definition serial.h:109
@ SERIAL_EOF
Definition serial.h:115
@ SERIAL_ERROR
Definition serial.h:110
@ SERIAL_TIMEOUT
Definition serial.h:111
void solib_add(const char *pattern, int from_tty, int readsyms)
Definition solib.c:990
void no_shared_libraries(const char *ignored, int from_tty)
Definition solib.c:1284
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
std::vector< agent_expr * > conditions
Definition breakpoint.h:290
std::vector< agent_expr * > tcommands
Definition breakpoint.h:294
CORE_ADDR placed_address
Definition breakpoint.h:266
CORE_ADDR reqstd_address
Definition breakpoint.h:269
counted_command_line commands
Definition breakpoint.h:821
bptype type
Definition breakpoint.h:798
location_spec_up locspec
Definition breakpoint.h:832
bp_location_range locations() const
gdb::unique_xmalloc_ptr< char > cond_string
Definition breakpoint.h:850
enum enable_state enable_state
Definition breakpoint.h:800
gdb_byte * data
Definition regcache.h:183
static void print_packet(gdb::array_view< const char > &buf)
Definition remote.c:11765
void sending(gdb::array_view< const char > &buf) override
Definition remote.c:11743
void received(gdb::array_view< const char > &buf) override
Definition remote.c:11752
gdb::optional< setting > var
Definition cli-decode.h:236
void * context() const
Definition cli-decode.h:109
__extension__ enum cmd_types type
Definition cli-decode.h:168
struct cmd_list_element * next
Definition cli-decode.h:113
const char * name
Definition cli-decode.h:116
void set_context(void *context)
Definition cli-decode.h:103
counted_command_line body_list_0
Definition cli-script.h:102
struct command_line * next
Definition cli-script.h:86
enum command_control_type control_type
Definition cli-script.h:88
char * line
Definition cli-script.h:87
char more_display[256]
Definition remote.c:3211
char display[256]
Definition remote.c:3208
threadref threadid
Definition remote.c:3205
char shortname[32]
Definition remote.c:3210
gdb::unique_xmalloc_ptr< void > value
Definition xml-support.h:78
Definition gnu-nat.c:153
pid_t pid
Definition gnu-nat.c:165
const char * name
Definition remote.c:607
void(* ack)(remote_target *remote, const notif_client *self, const char *buf, struct notif_event *event)
const char * name
const char * ack_command
enum REMOTE_NOTIF_ID id
struct program_space * pspace
Definition objfiles.h:728
gdb_bfd_ref_ptr obfd
Definition objfiles.h:740
::section_offsets section_offsets
Definition objfiles.h:786
enum auto_boolean detect
Definition remote.c:591
enum packet_support support
Definition remote.c:594
const char * title
Definition remote.c:579
const char * name
Definition remote.c:575
long offset
Definition remote.c:368
LONGEST pnum
Definition remote.c:370
long regnum
Definition remote.c:369
int in_g_packet
Definition remote.c:371
bfd * exec_bfd() const
Definition progspace.h:268
struct objfile * symfile_object_file
Definition progspace.h:357
enum packet_support default_support
Definition remote.c:5420
void(* func)(remote_target *remote, const struct protocol_feature *, enum packet_support, const char *)
Definition remote.c:5431
const char * name
Definition remote.c:5417
void invalidate()
Definition remote.c:12383
ULONGEST miss_count
Definition remote.c:361
ULONGEST offset
Definition remote.c:354
int pread(int fd, gdb_byte *read_buf, size_t len, ULONGEST offset)
Definition remote.c:12567
void invalidate_fd(int fd)
Definition remote.c:12391
ULONGEST hit_count
Definition remote.c:360
gdb::byte_vector buf
Definition remote.c:357
std::unique_ptr< packet_reg[]> regs
Definition remote.c:387
remote_arch_state(struct gdbarch *gdbarch)
Definition remote.c:1776
long actual_register_packet_size
Definition remote.c:395
long remote_packet_size
Definition remote.c:399
long sizeof_g_packet
Definition remote.c:383
int remote_vfork_event_p() const
Definition remote.c:664
DISABLE_COPY_AND_ASSIGN(remote_features)
enum packet_support packet_support(int) const
Definition remote.c:2469
packet_config m_protocol_packets[PACKET_MAX]
Definition remote.c:691
memory_packet_config m_memory_read_packet_config
Definition remote.c:685
~remote_features()=default
void reset_all_packet_configs_support()
Definition remote.c:5277
int remote_exec_event_p() const
Definition remote.c:668
packet_result packet_ok(const char *buf, const int which_packet)
Definition remote.c:2392
int remote_fork_event_p() const
Definition remote.c:660
int remote_multi_process_p() const
Definition remote.c:656
memory_packet_config m_memory_write_packet_config
Definition remote.c:687
enum auto_boolean packet_set_cmd_state(int packet) const
Definition remote.c:652
bool remote_memory_tagging_p() const
Definition remote.c:672
std::vector< remote_g_packet_guess > guesses
Definition remote.c:12114
const struct target_desc * tdesc
Definition remote.c:12109
remote_g_packet_guess(int bytes_, const struct target_desc *tdesc_)
Definition remote.c:12102
bool may_wildcard_vcont
Definition remote.c:6776
struct async_event_handler * get_pending_events_token
struct notif_event * pending_event[REMOTE_NOTIF_LAST]
std::string extra
Definition remote.c:1445
const struct resumed_pending_vcont_info & resumed_pending_vcont_info() const
Definition remote.c:1484
gdb::byte_vector thread_handle
Definition remote.c:1451
void set_resumed_pending_vcont(bool step, gdb_signal sig)
Definition remote.c:1473
enum resume_state get_resume_state() const
Definition remote.c:1461
CORE_ADDR watch_data_address
Definition remote.c:1458
std::string name
Definition remote.c:1446
struct resumed_pending_vcont_info m_resumed_pending_vcont_info
Definition remote.c:1514
enum target_stop_reason stop_reason
Definition remote.c:1454
enum resume_state m_resume_state
Definition remote.c:1511
void set_not_resumed()
Definition remote.c:1467
scoped_mark_target_starting(remote_target *target)
Definition remote.c:4879
static scoped_restore_tmpl< bool > set_starting_up_flag(remote_target *target)
Definition remote.c:4890
remote_target_ref m_remote_target
Definition remote.c:4901
gdb::ref_ptr< remote_target, target_ops_ref_policy > remote_target_ref
Definition remote.c:4898
scoped_restore_tmpl< bool > m_restore_starting_up
Definition remote.c:4905
virtual void sending(gdb::array_view< const char > &buf)=0
virtual void received(gdb::array_view< const char > &buf)=0
int bufcnt
Definition serial.h:247
char * name
Definition serial.h:251
int fd
Definition serial.h:238
cmd_list_element * set
Definition command.h:422
cmd_list_element * show
Definition command.h:422
~stop_reply()
Definition remote.c:7425
struct remote_state * rs
Definition remote.c:1301
std::vector< cached_reg_t > regcache
Definition remote.c:1312
gdbarch * arch
Definition remote.c:1306
ptid_t ptid
Definition remote.c:1296
CORE_ADDR watch_data_address
Definition remote.c:1316
struct target_waitstatus ws
Definition remote.c:1303
enum target_stop_reason stop_reason
Definition remote.c:1314
const char * shortname
Definition target.h:426
target_ops * beneath() const
Definition target.c:3041
virtual gdb::array_view< const_gdb_byte > virtual thread_info_to_thread_handle(struct thread_info *) TARGET_DEFAULT_RETURN(gdb voi stop)(ptid_t) TARGET_DEFAULT_IGNORE()
Definition target.h:689
virtual const struct target_desc * read_description() TARGET_DEFAULT_RETURN(NULL)
struct bfd_section * the_bfd_section
target_waitstatus & set_stopped(gdb_signal sig)
Definition waitstatus.h:230
enum gdb_signal sig
Definition waitstatus.h:414
target_waitstatus & set_ignore()
Definition waitstatus.h:307
target_waitkind kind() const
Definition waitstatus.h:345
std::string to_string() const
Definition waitstatus.c:26
CORE_ADDR step_range_start
Definition gdbthread.h:124
CORE_ADDR step_range_end
Definition gdbthread.h:125
std::string name
Definition remote.c:3850
std::string extra
Definition remote.c:3847
DISABLE_COPY_AND_ASSIGN(thread_item)
thread_item & operator=(thread_item &&other)=default
thread_item(ptid_t ptid_)
Definition remote.c:3834
gdb::byte_vector thread_handle
Definition remote.c:3856
ptid_t ptid
Definition remote.c:3844
void remove_thread(ptid_t ptid)
Definition remote.c:3884
std::vector< thread_item > items
Definition remote.c:3900
bool contains_thread(ptid_t ptid) const
Definition remote.c:3868
int running_known
Definition tracepoint.h:99
const char * filename
Definition tracepoint.h:96
long step_count
int number_on_target
ULONGEST traceframe_usage
ULONGEST traceframe_usage
Definition tracepoint.h:201
ULONGEST addr
Definition tracepoint.h:174
Definition value.h:130
bool auto_solib_add
Definition symfile.c:149
void reread_symbols(int from_tty)
Definition symfile.c:2457
void generic_load(const char *args, int from_tty)
Definition symfile.c:2037
symfile_segment_data_up get_symfile_segment_data(bfd *abfd)
Definition symfile.c:3642
int symfile_map_offsets_to_segments(bfd *abfd, const struct symfile_segment_data *data, section_offsets &offsets, int num_segment_bases, const CORE_ADDR *segment_bases)
Definition symfile.c:3668
std::unique_ptr< symfile_segment_data > symfile_segment_data_up
Definition symfile.h:104
std::vector< CORE_ADDR > section_offsets
Definition symtab.h:1669
void target_find_description(void)
void target_clear_description(void)
std::vector< target_section > target_section_table
void target_announce_detach(int from_tty)
Definition target.c:3622
bool target_is_async_p()
Definition target.c:402
void fileio_handles_invalidate_target(target_ops *targ)
Definition target.c:3144
ptid_t target_wait(ptid_t ptid, struct target_waitstatus *status, target_wait_flags options)
Definition target.c:2586
int target_trace_find(trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
Definition target.c:682
void target_async(bool enable)
Definition target.c:4337
gdb::optional< gdb::char_vector > target_read_stralloc(struct target_ops *ops, enum target_object object, const char *annex)
Definition target.c:2321
void target_interrupt()
Definition target.c:3798
bool target_async_permitted
Definition target.c:4356
const struct target_section * target_section_by_addr(struct target_ops *target, CORE_ADDR addr)
Definition target.c:1393
int simple_verify_memory(struct target_ops *ops, const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
Definition target.c:3955
bool target_can_async_p()
Definition target.c:384
bool target_static_tracepoint_marker_at(CORE_ADDR addr, static_tracepoint_marker *marker)
Definition target.c:774
void target_update_thread_list(void)
Definition target.c:3776
bool target_has_execution(inferior *inf)
Definition target.c:201
const target_section_table * target_get_section_table(struct target_ops *target)
Definition target.c:1385
void add_target(const target_info &t, target_open_ftype *func, completer_ftype *completer)
Definition target.c:868
void target_announce_attach(int from_tty, int pid)
Definition target.c:3643
LONGEST target_read(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *buf, ULONGEST offset, LONGEST len)
Definition target.c:1970
bool target_is_non_stop_p()
Definition target.c:4394
std::string target_pid_to_str(ptid_t ptid)
Definition target.c:2623
std::string normal_pid_to_str(ptid_t ptid)
Definition target.c:3693
void target_preopen(int from_tty)
Definition target.c:2495
void target_mourn_inferior(ptid_t ptid)
Definition target.c:2758
int target_verify_memory(const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
Definition target.c:3994
bool may_insert_fast_tracepoints
@ INF_REG_EVENT
Definition target.h:134
target_xfer_status
Definition target.h:219
@ TARGET_XFER_E_IO
Definition target.h:232
@ TARGET_XFER_EOF
Definition target.h:224
@ TARGET_XFER_OK
Definition target.h:221
@ TARGET_XFER_UNAVAILABLE
Definition target.h:227
bool may_write_registers
target_object
Definition target.h:143
@ TARGET_OBJECT_AVR
Definition target.h:145
@ TARGET_OBJECT_THREADS
Definition target.h:189
@ TARGET_OBJECT_AVAILABLE_FEATURES
Definition target.h:174
@ TARGET_OBJECT_FDPIC
Definition target.h:195
@ TARGET_OBJECT_BTRACE
Definition target.h:201
@ TARGET_OBJECT_LIBRARIES_SVR4
Definition target.h:178
@ TARGET_OBJECT_BTRACE_CONF
Definition target.h:203
@ TARGET_OBJECT_TRACEFRAME_INFO
Definition target.h:193
@ TARGET_OBJECT_AUXV
Definition target.h:162
@ TARGET_OBJECT_OSDATA
Definition target.h:184
@ TARGET_OBJECT_SIGNAL_INFO
Definition target.h:187
@ TARGET_OBJECT_OPENVMS_UIB
Definition target.h:199
@ TARGET_OBJECT_MEMORY
Definition target.h:147
@ TARGET_OBJECT_EXEC_FILE
Definition target.h:208
@ TARGET_OBJECT_MEMORY_MAP
Definition target.h:166
@ TARGET_OBJECT_LIBRARIES
Definition target.h:176
@ TARGET_OBJECT_FLASH
Definition target.h:171
@ TARGET_OBJECT_STATIC_TRACE_DATA
Definition target.h:191
bool may_insert_tracepoints
@ process_stratum
Definition target.h:97
thread_control_capabilities
Definition target.h:105
@ tc_schedlock
Definition target.h:107
bool may_insert_breakpoints
int remote_timeout
Definition top.c:195
std::unique_ptr< target_ops, target_ops_deleter > target_ops_up
Definition target.h:1347
bool may_write_memory
bool may_stop
int trace_regblock_size
struct trace_status * current_trace_status(void)
Definition tracepoint.c:175
void parse_trace_status(const char *line, struct trace_status *ts)
void parse_tracepoint_status(const char *p, tracepoint *tp, struct uploaded_tp *utp)
int get_traceframe_number(void)
void encode_actions_rsp(struct bp_location *tloc, std::vector< std::string > *tdp_actions, std::vector< std::string > *stepping_actions)
void parse_tsv_definition(const char *line, struct uploaded_tsv **utsvp)
void trace_reset_local_state(void)
void parse_static_tracepoint_marker_definition(const char *line, const char **pp, static_tracepoint_marker *marker)
int traceframe_available_memory(std::vector< mem_range > *result, CORE_ADDR memaddr, ULONGEST len)
std::string default_collect
Definition tracepoint.c:130
void merge_uploaded_tracepoints(struct uploaded_tp **uploaded_tps)
struct std::unique_ptr< traceframe_info > parse_traceframe_info(const char *tframe_info)
int encode_source_string(int tpnum, ULONGEST addr, const char *srctype, const char *src, char *buf, int buf_size)
void parse_tracepoint_definition(const char *line, struct uploaded_tp **utpp)
void merge_uploaded_trace_state_variables(struct uploaded_tsv **uploaded_tsvs)
std::unique_ptr< traceframe_info > traceframe_info_up
Definition tracepoint.h:40
trace_find_type
Definition tracepoint.h:406
@ tfind_outside
Definition tracepoint.h:411
@ tfind_pc
Definition tracepoint.h:408
@ tfind_number
Definition tracepoint.h:407
@ tfind_range
Definition tracepoint.h:410
@ tfind_tp
Definition tracepoint.h:409
#define current_uiout
Definition ui-out.h:40
int query(const char *ctlstr,...)
Definition utils.c:943
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
void gdb_putc(int c)
Definition utils.c:1862
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
int parse_pid_to_attach(const char *args)
Definition utils.c:3331
#define gdb_stderr
Definition utils.h:187
#define gdb_stdlog
Definition utils.h:190
const char version[]
Definition version.c:2
@ TARGET_WNOHANG
Definition wait.h:32
target_waitkind
Definition waitstatus.h:30
@ TARGET_WAITKIND_NO_RESUMED
Definition waitstatus.h:96
@ TARGET_WAITKIND_THREAD_EXITED
Definition waitstatus.h:102
@ TARGET_WAITKIND_SIGNALLED
Definition waitstatus.h:40
@ TARGET_WAITKIND_STOPPED
Definition waitstatus.h:36
@ TARGET_WAITKIND_EXITED
Definition waitstatus.h:32
@ TARGET_WAITKIND_NO_HISTORY
Definition waitstatus.h:93
@ TARGET_WAITKIND_FORKED
Definition waitstatus.h:49
@ TARGET_WAITKIND_VFORKED
Definition waitstatus.h:53
@ TARGET_WAITKIND_IGNORE
Definition waitstatus.h:89
target_stop_reason
Definition waitstatus.h:428
@ TARGET_STOPPED_BY_SW_BREAKPOINT
Definition waitstatus.h:434
@ TARGET_STOPPED_BY_WATCHPOINT
Definition waitstatus.h:440
@ TARGET_STOPPED_BY_HW_BREAKPOINT
Definition waitstatus.h:437
@ TARGET_STOPPED_BY_NO_REASON
Definition waitstatus.h:431
@ GDB_XML_EF_NONE
@ GDB_XML_EF_REPEATABLE
@ GDB_XML_EF_OPTIONAL
void void gdb_xml_error(struct gdb_xml_parser *parser, const char *format,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF(2
void void struct gdb_xml_value * xml_find_attribute(std::vector< gdb_xml_value > &attributes, const char *name)
int gdb_xml_parse_quick(const char *name, const char *dtd_name, const struct gdb_xml_element *elements, const char *document, void *user_data)
gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest
@ GDB_XML_AF_OPTIONAL
@ GDB_XML_AF_NONE