1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* Per-program-space data key. */
79 static const struct program_space_data
*remote_pspace_data
;
81 /* The variable registered as the control variable used by the
82 remote exec-file commands. While the remote exec-file setting is
83 per-program-space, the set/show machinery uses this as the
84 location of the remote exec-file value. */
85 static char *remote_exec_file_var
;
87 /* The size to align memory write packets, when practical. The protocol
88 does not guarantee any alignment, and gdb will generate short
89 writes and unaligned writes, but even as a best-effort attempt this
90 can improve bulk transfers. For instance, if a write is misaligned
91 relative to the target's data bus, the stub may need to make an extra
92 round trip fetching data from the target. This doesn't make a
93 huge difference, but it's easy to do, so we try to be helpful.
95 The alignment chosen is arbitrary; usually data bus width is
96 important here, not the possibly larger cache line size. */
97 enum { REMOTE_ALIGN_WRITES
= 16 };
99 /* Prototypes for local functions. */
100 static void async_cleanup_sigint_signal_handler (void *dummy
);
101 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
102 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
103 int forever
, int *is_notif
);
105 static void async_handle_remote_sigint (int);
106 static void async_handle_remote_sigint_twice (int);
108 static void remote_files_info (struct target_ops
*ignore
);
110 static void remote_prepare_to_store (struct target_ops
*self
,
111 struct regcache
*regcache
);
113 static void remote_open_1 (const char *, int, struct target_ops
*,
116 static void remote_close (struct target_ops
*self
);
120 static int remote_vkill (int pid
, struct remote_state
*rs
);
122 static void remote_kill_k (void);
124 static void remote_mourn (struct target_ops
*ops
);
126 static void extended_remote_restart (void);
128 static void remote_send (char **buf
, long *sizeof_buf_p
);
130 static int readchar (int timeout
);
132 static void remote_serial_write (const char *str
, int len
);
134 static void remote_kill (struct target_ops
*ops
);
136 static int remote_can_async_p (struct target_ops
*);
138 static int remote_is_async_p (struct target_ops
*);
140 static void remote_async (struct target_ops
*ops
, int enable
);
142 static void remote_thread_events (struct target_ops
*ops
, int enable
);
144 static void sync_remote_interrupt_twice (int signo
);
146 static void interrupt_query (void);
148 static void set_general_thread (struct ptid ptid
);
149 static void set_continue_thread (struct ptid ptid
);
151 static void get_offsets (void);
153 static void skip_frame (void);
155 static long read_frame (char **buf_p
, long *sizeof_buf
);
157 static int hexnumlen (ULONGEST num
);
159 static void init_remote_ops (void);
161 static void init_extended_remote_ops (void);
163 static void remote_stop (struct target_ops
*self
, ptid_t
);
165 static int stubhex (int ch
);
167 static int hexnumstr (char *, ULONGEST
);
169 static int hexnumnstr (char *, ULONGEST
, int);
171 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
173 static void print_packet (const char *);
175 static void compare_sections_command (char *, int);
177 static void packet_command (char *, int);
179 static int stub_unpack_int (char *buff
, int fieldlength
);
181 static ptid_t
remote_current_thread (ptid_t oldptid
);
183 static int putpkt_binary (const char *buf
, int cnt
);
185 static void check_binary_download (CORE_ADDR addr
);
187 struct packet_config
;
189 static void show_packet_config_cmd (struct packet_config
*config
);
191 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
193 struct cmd_list_element
*c
,
196 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
197 static ptid_t
read_ptid (char *buf
, char **obuf
);
199 static void remote_set_permissions (struct target_ops
*self
);
201 static int remote_get_trace_status (struct target_ops
*self
,
202 struct trace_status
*ts
);
204 static int remote_upload_tracepoints (struct target_ops
*self
,
205 struct uploaded_tp
**utpp
);
207 static int remote_upload_trace_state_variables (struct target_ops
*self
,
208 struct uploaded_tsv
**utsvp
);
210 static void remote_query_supported (void);
212 static void remote_check_symbols (void);
214 void _initialize_remote (void);
217 static void stop_reply_xfree (struct stop_reply
*);
218 static void remote_parse_stop_reply (char *, struct stop_reply
*);
219 static void push_stop_reply (struct stop_reply
*);
220 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
221 static int peek_stop_reply (ptid_t ptid
);
223 struct threads_listing_context
;
224 static void remove_new_fork_children (struct threads_listing_context
*);
226 static void remote_async_inferior_event_handler (gdb_client_data
);
228 static void remote_terminal_ours (struct target_ops
*self
);
230 static int remote_read_description_p (struct target_ops
*target
);
232 static void remote_console_output (char *msg
);
234 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
236 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
238 static void remote_btrace_reset (void);
240 static int stop_reply_queue_length (void);
242 static void readahead_cache_invalidate (void);
246 static struct cmd_list_element
*remote_cmdlist
;
248 /* For "set remote" and "show remote". */
250 static struct cmd_list_element
*remote_set_cmdlist
;
251 static struct cmd_list_element
*remote_show_cmdlist
;
253 /* Stub vCont actions support.
255 Each field is a boolean flag indicating whether the stub reports
256 support for the corresponding action. */
258 struct vCont_action_support
273 /* Controls whether GDB is willing to use range stepping. */
275 static int use_range_stepping
= 1;
277 #define OPAQUETHREADBYTES 8
279 /* a 64 bit opaque identifier */
280 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
282 /* About this many threadisds fit in a packet. */
284 #define MAXTHREADLISTRESULTS 32
286 /* Data for the vFile:pread readahead cache. */
288 struct readahead_cache
290 /* The file descriptor for the file that is being cached. -1 if the
294 /* The offset into the file that the cache buffer corresponds
298 /* The buffer holding the cache contents. */
300 /* The buffer's size. We try to read as much as fits into a packet
304 /* Cache hit and miss counters. */
309 /* Description of the remote protocol state for the currently
310 connected target. This is per-target state, and independent of the
311 selected architecture. */
315 /* A buffer to use for incoming packets, and its current size. The
316 buffer is grown dynamically for larger incoming packets.
317 Outgoing packets may also be constructed in this buffer.
318 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
319 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
324 /* True if we're going through initial connection setup (finding out
325 about the remote side's threads, relocating symbols, etc.). */
328 /* If we negotiated packet size explicitly (and thus can bypass
329 heuristics for the largest packet size that will not overflow
330 a buffer in the stub), this will be set to that packet size.
331 Otherwise zero, meaning to use the guessed size. */
332 long explicit_packet_size
;
334 /* remote_wait is normally called when the target is running and
335 waits for a stop reply packet. But sometimes we need to call it
336 when the target is already stopped. We can send a "?" packet
337 and have remote_wait read the response. Or, if we already have
338 the response, we can stash it in BUF and tell remote_wait to
339 skip calling getpkt. This flag is set when BUF contains a
340 stop reply packet and the target is not waiting. */
341 int cached_wait_status
;
343 /* True, if in no ack mode. That is, neither GDB nor the stub will
344 expect acks from each other. The connection is assumed to be
348 /* True if we're connected in extended remote mode. */
351 /* True if we resumed the target and we're waiting for the target to
352 stop. In the mean time, we can't start another command/query.
353 The remote server wouldn't be ready to process it, so we'd
354 timeout waiting for a reply that would never come and eventually
355 we'd close the connection. This can happen in asynchronous mode
356 because we allow GDB commands while the target is running. */
357 int waiting_for_stop_reply
;
359 /* The status of the stub support for the various vCont actions. */
360 struct vCont_action_support supports_vCont
;
362 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
363 responded to that. */
366 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
367 remote_open knows that we don't have a file open when the program
369 struct serial
*remote_desc
;
371 /* These are the threads which we last sent to the remote system. The
372 TID member will be -1 for all or -2 for not sent yet. */
373 ptid_t general_thread
;
374 ptid_t continue_thread
;
376 /* This is the traceframe which we last selected on the remote system.
377 It will be -1 if no traceframe is selected. */
378 int remote_traceframe_number
;
380 char *last_pass_packet
;
382 /* The last QProgramSignals packet sent to the target. We bypass
383 sending a new program signals list down to the target if the new
384 packet is exactly the same as the last we sent. IOW, we only let
385 the target know about program signals list changes. */
386 char *last_program_signals_packet
;
388 enum gdb_signal last_sent_signal
;
392 char *finished_object
;
393 char *finished_annex
;
394 ULONGEST finished_offset
;
396 /* Should we try the 'ThreadInfo' query packet?
398 This variable (NOT available to the user: auto-detect only!)
399 determines whether GDB will use the new, simpler "ThreadInfo"
400 query or the older, more complex syntax for thread queries.
401 This is an auto-detect variable (set to true at each connect,
402 and set to false when the target fails to recognize it). */
403 int use_threadinfo_query
;
404 int use_threadextra_query
;
406 threadref echo_nextthread
;
407 threadref nextthread
;
408 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
410 /* The state of remote notification. */
411 struct remote_notif_state
*notif_state
;
413 /* The branch trace configuration. */
414 struct btrace_config btrace_config
;
416 /* The argument to the last "vFile:setfs:" packet we sent, used
417 to avoid sending repeated unnecessary "vFile:setfs:" packets.
418 Initialized to -1 to indicate that no "vFile:setfs:" packet
419 has yet been sent. */
422 /* A readahead cache for vFile:pread. Often, reading a binary
423 involves a sequence of small reads. E.g., when parsing an ELF
424 file. A readahead cache helps mostly the case of remote
425 debugging on a connection with higher latency, due to the
426 request/reply nature of the RSP. We only cache data for a single
427 file descriptor at a time. */
428 struct readahead_cache readahead_cache
;
431 /* Private data that we'll store in (struct thread_info)->private. */
432 struct private_thread_info
438 /* Whether the target stopped for a breakpoint/watchpoint. */
439 enum target_stop_reason stop_reason
;
441 /* This is set to the data address of the access causing the target
442 to stop for a watchpoint. */
443 CORE_ADDR watch_data_address
;
447 free_private_thread_info (struct private_thread_info
*info
)
454 /* This data could be associated with a target, but we do not always
455 have access to the current target when we need it, so for now it is
456 static. This will be fine for as long as only one target is in use
458 static struct remote_state
*remote_state
;
460 static struct remote_state
*
461 get_remote_state_raw (void)
466 /* Allocate a new struct remote_state with xmalloc, initialize it, and
469 static struct remote_state
*
470 new_remote_state (void)
472 struct remote_state
*result
= XCNEW (struct remote_state
);
474 /* The default buffer size is unimportant; it will be expanded
475 whenever a larger buffer is needed. */
476 result
->buf_size
= 400;
477 result
->buf
= (char *) xmalloc (result
->buf_size
);
478 result
->remote_traceframe_number
= -1;
479 result
->last_sent_signal
= GDB_SIGNAL_0
;
485 /* Description of the remote protocol for a given architecture. */
489 long offset
; /* Offset into G packet. */
490 long regnum
; /* GDB's internal register number. */
491 LONGEST pnum
; /* Remote protocol register number. */
492 int in_g_packet
; /* Always part of G packet. */
493 /* long size in bytes; == register_size (target_gdbarch (), regnum);
495 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
499 struct remote_arch_state
501 /* Description of the remote protocol registers. */
502 long sizeof_g_packet
;
504 /* Description of the remote protocol registers indexed by REGNUM
505 (making an array gdbarch_num_regs in size). */
506 struct packet_reg
*regs
;
508 /* This is the size (in chars) of the first response to the ``g''
509 packet. It is used as a heuristic when determining the maximum
510 size of memory-read and memory-write packets. A target will
511 typically only reserve a buffer large enough to hold the ``g''
512 packet. The size does not include packet overhead (headers and
514 long actual_register_packet_size
;
516 /* This is the maximum size (in chars) of a non read/write packet.
517 It is also used as a cap on the size of read/write packets. */
518 long remote_packet_size
;
521 /* Utility: generate error from an incoming stub packet. */
523 trace_error (char *buf
)
526 return; /* not an error msg */
529 case '1': /* malformed packet error */
530 if (*++buf
== '0') /* general case: */
531 error (_("remote.c: error in outgoing packet."));
533 error (_("remote.c: error in outgoing packet at field #%ld."),
534 strtol (buf
, NULL
, 16));
536 error (_("Target returns error code '%s'."), buf
);
540 /* Utility: wait for reply from stub, while accepting "O" packets. */
542 remote_get_noisy_reply (char **buf_p
,
545 do /* Loop on reply from remote stub. */
549 QUIT
; /* Allow user to bail out with ^C. */
550 getpkt (buf_p
, sizeof_buf
, 0);
554 else if (startswith (buf
, "qRelocInsn:"))
557 CORE_ADDR from
, to
, org_to
;
559 int adjusted_size
= 0;
562 p
= buf
+ strlen ("qRelocInsn:");
563 pp
= unpack_varlen_hex (p
, &ul
);
565 error (_("invalid qRelocInsn packet: %s"), buf
);
569 unpack_varlen_hex (p
, &ul
);
576 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
579 CATCH (ex
, RETURN_MASK_ALL
)
581 if (ex
.error
== MEMORY_ERROR
)
583 /* Propagate memory errors silently back to the
584 target. The stub may have limited the range of
585 addresses we can write to, for example. */
589 /* Something unexpectedly bad happened. Be verbose
590 so we can tell what, and propagate the error back
591 to the stub, so it doesn't get stuck waiting for
593 exception_fprintf (gdb_stderr
, ex
,
594 _("warning: relocating instruction: "));
602 adjusted_size
= to
- org_to
;
604 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
608 else if (buf
[0] == 'O' && buf
[1] != 'K')
609 remote_console_output (buf
+ 1); /* 'O' message from stub */
611 return buf
; /* Here's the actual reply. */
616 /* Handle for retreving the remote protocol data from gdbarch. */
617 static struct gdbarch_data
*remote_gdbarch_data_handle
;
619 static struct remote_arch_state
*
620 get_remote_arch_state (void)
622 gdb_assert (target_gdbarch () != NULL
);
623 return ((struct remote_arch_state
*)
624 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
627 /* Fetch the global remote target state. */
629 static struct remote_state
*
630 get_remote_state (void)
632 /* Make sure that the remote architecture state has been
633 initialized, because doing so might reallocate rs->buf. Any
634 function which calls getpkt also needs to be mindful of changes
635 to rs->buf, but this call limits the number of places which run
637 get_remote_arch_state ();
639 return get_remote_state_raw ();
642 /* Cleanup routine for the remote module's pspace data. */
645 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
647 char *remote_exec_file
= (char *) arg
;
649 xfree (remote_exec_file
);
652 /* Fetch the remote exec-file from the current program space. */
655 get_remote_exec_file (void)
657 char *remote_exec_file
;
660 = (char *) program_space_data (current_program_space
,
662 if (remote_exec_file
== NULL
)
665 return remote_exec_file
;
668 /* Set the remote exec file for PSPACE. */
671 set_pspace_remote_exec_file (struct program_space
*pspace
,
672 char *remote_exec_file
)
674 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
677 set_program_space_data (pspace
, remote_pspace_data
,
678 xstrdup (remote_exec_file
));
681 /* The "set/show remote exec-file" set command hook. */
684 set_remote_exec_file (char *ignored
, int from_tty
,
685 struct cmd_list_element
*c
)
687 gdb_assert (remote_exec_file_var
!= NULL
);
688 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
691 /* The "set/show remote exec-file" show command hook. */
694 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
695 struct cmd_list_element
*cmd
, const char *value
)
697 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
701 compare_pnums (const void *lhs_
, const void *rhs_
)
703 const struct packet_reg
* const *lhs
704 = (const struct packet_reg
* const *) lhs_
;
705 const struct packet_reg
* const *rhs
706 = (const struct packet_reg
* const *) rhs_
;
708 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
710 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
717 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
719 int regnum
, num_remote_regs
, offset
;
720 struct packet_reg
**remote_regs
;
722 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
724 struct packet_reg
*r
= ®s
[regnum
];
726 if (register_size (gdbarch
, regnum
) == 0)
727 /* Do not try to fetch zero-sized (placeholder) registers. */
730 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
735 /* Define the g/G packet format as the contents of each register
736 with a remote protocol number, in order of ascending protocol
739 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
740 for (num_remote_regs
= 0, regnum
= 0;
741 regnum
< gdbarch_num_regs (gdbarch
);
743 if (regs
[regnum
].pnum
!= -1)
744 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
746 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
749 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
751 remote_regs
[regnum
]->in_g_packet
= 1;
752 remote_regs
[regnum
]->offset
= offset
;
753 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
759 /* Given the architecture described by GDBARCH, return the remote
760 protocol register's number and the register's offset in the g/G
761 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
762 If the target does not have a mapping for REGNUM, return false,
763 otherwise, return true. */
766 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
767 int *pnum
, int *poffset
)
769 struct packet_reg
*regs
;
770 struct cleanup
*old_chain
;
772 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
774 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
775 old_chain
= make_cleanup (xfree
, regs
);
777 map_regcache_remote_table (gdbarch
, regs
);
779 *pnum
= regs
[regnum
].pnum
;
780 *poffset
= regs
[regnum
].offset
;
782 do_cleanups (old_chain
);
788 init_remote_state (struct gdbarch
*gdbarch
)
790 struct remote_state
*rs
= get_remote_state_raw ();
791 struct remote_arch_state
*rsa
;
793 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
795 /* Use the architecture to build a regnum<->pnum table, which will be
796 1:1 unless a feature set specifies otherwise. */
797 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
798 gdbarch_num_regs (gdbarch
),
801 /* Record the maximum possible size of the g packet - it may turn out
803 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
805 /* Default maximum number of characters in a packet body. Many
806 remote stubs have a hardwired buffer size of 400 bytes
807 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
808 as the maximum packet-size to ensure that the packet and an extra
809 NUL character can always fit in the buffer. This stops GDB
810 trashing stubs that try to squeeze an extra NUL into what is
811 already a full buffer (As of 1999-12-04 that was most stubs). */
812 rsa
->remote_packet_size
= 400 - 1;
814 /* This one is filled in when a ``g'' packet is received. */
815 rsa
->actual_register_packet_size
= 0;
817 /* Should rsa->sizeof_g_packet needs more space than the
818 default, adjust the size accordingly. Remember that each byte is
819 encoded as two characters. 32 is the overhead for the packet
820 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
821 (``$NN:G...#NN'') is a better guess, the below has been padded a
823 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
824 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
826 /* Make sure that the packet buffer is plenty big enough for
827 this architecture. */
828 if (rs
->buf_size
< rsa
->remote_packet_size
)
830 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
831 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
837 /* Return the current allowed size of a remote packet. This is
838 inferred from the current architecture, and should be used to
839 limit the length of outgoing packets. */
841 get_remote_packet_size (void)
843 struct remote_state
*rs
= get_remote_state ();
844 struct remote_arch_state
*rsa
= get_remote_arch_state ();
846 if (rs
->explicit_packet_size
)
847 return rs
->explicit_packet_size
;
849 return rsa
->remote_packet_size
;
852 static struct packet_reg
*
853 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
855 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
859 struct packet_reg
*r
= &rsa
->regs
[regnum
];
861 gdb_assert (r
->regnum
== regnum
);
866 static struct packet_reg
*
867 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
871 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
873 struct packet_reg
*r
= &rsa
->regs
[i
];
881 static struct target_ops remote_ops
;
883 static struct target_ops extended_remote_ops
;
885 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
886 ``forever'' still use the normal timeout mechanism. This is
887 currently used by the ASYNC code to guarentee that target reads
888 during the initial connect always time-out. Once getpkt has been
889 modified to return a timeout indication and, in turn
890 remote_wait()/wait_for_inferior() have gained a timeout parameter
892 static int wait_forever_enabled_p
= 1;
894 /* Allow the user to specify what sequence to send to the remote
895 when he requests a program interruption: Although ^C is usually
896 what remote systems expect (this is the default, here), it is
897 sometimes preferable to send a break. On other systems such
898 as the Linux kernel, a break followed by g, which is Magic SysRq g
899 is required in order to interrupt the execution. */
900 const char interrupt_sequence_control_c
[] = "Ctrl-C";
901 const char interrupt_sequence_break
[] = "BREAK";
902 const char interrupt_sequence_break_g
[] = "BREAK-g";
903 static const char *const interrupt_sequence_modes
[] =
905 interrupt_sequence_control_c
,
906 interrupt_sequence_break
,
907 interrupt_sequence_break_g
,
910 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
913 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
914 struct cmd_list_element
*c
,
917 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
918 fprintf_filtered (file
,
919 _("Send the ASCII ETX character (Ctrl-c) "
920 "to the remote target to interrupt the "
921 "execution of the program.\n"));
922 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
923 fprintf_filtered (file
,
924 _("send a break signal to the remote target "
925 "to interrupt the execution of the program.\n"));
926 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
927 fprintf_filtered (file
,
928 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
929 "the remote target to interrupt the execution "
930 "of Linux kernel.\n"));
932 internal_error (__FILE__
, __LINE__
,
933 _("Invalid value for interrupt_sequence_mode: %s."),
934 interrupt_sequence_mode
);
937 /* This boolean variable specifies whether interrupt_sequence is sent
938 to the remote target when gdb connects to it.
939 This is mostly needed when you debug the Linux kernel: The Linux kernel
940 expects BREAK g which is Magic SysRq g for connecting gdb. */
941 static int interrupt_on_connect
= 0;
943 /* This variable is used to implement the "set/show remotebreak" commands.
944 Since these commands are now deprecated in favor of "set/show remote
945 interrupt-sequence", it no longer has any effect on the code. */
946 static int remote_break
;
949 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
952 interrupt_sequence_mode
= interrupt_sequence_break
;
954 interrupt_sequence_mode
= interrupt_sequence_control_c
;
958 show_remotebreak (struct ui_file
*file
, int from_tty
,
959 struct cmd_list_element
*c
,
964 /* This variable sets the number of bits in an address that are to be
965 sent in a memory ("M" or "m") packet. Normally, after stripping
966 leading zeros, the entire address would be sent. This variable
967 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
968 initial implementation of remote.c restricted the address sent in
969 memory packets to ``host::sizeof long'' bytes - (typically 32
970 bits). Consequently, for 64 bit targets, the upper 32 bits of an
971 address was never sent. Since fixing this bug may cause a break in
972 some remote targets this variable is principly provided to
973 facilitate backward compatibility. */
975 static unsigned int remote_address_size
;
977 /* Temporary to track who currently owns the terminal. See
978 remote_terminal_* for more details. */
980 static int remote_async_terminal_ours_p
;
983 /* User configurable variables for the number of characters in a
984 memory read/write packet. MIN (rsa->remote_packet_size,
985 rsa->sizeof_g_packet) is the default. Some targets need smaller
986 values (fifo overruns, et.al.) and some users need larger values
987 (speed up transfers). The variables ``preferred_*'' (the user
988 request), ``current_*'' (what was actually set) and ``forced_*''
989 (Positive - a soft limit, negative - a hard limit). */
991 struct memory_packet_config
998 /* The default max memory-write-packet-size. The 16k is historical.
999 (It came from older GDB's using alloca for buffers and the
1000 knowledge (folklore?) that some hosts don't cope very well with
1001 large alloca calls.) */
1002 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1004 /* The minimum remote packet size for memory transfers. Ensures we
1005 can write at least one byte. */
1006 #define MIN_MEMORY_PACKET_SIZE 20
1008 /* Compute the current size of a read/write packet. Since this makes
1009 use of ``actual_register_packet_size'' the computation is dynamic. */
1012 get_memory_packet_size (struct memory_packet_config
*config
)
1014 struct remote_state
*rs
= get_remote_state ();
1015 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1018 if (config
->fixed_p
)
1020 if (config
->size
<= 0)
1021 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1023 what_they_get
= config
->size
;
1027 what_they_get
= get_remote_packet_size ();
1028 /* Limit the packet to the size specified by the user. */
1029 if (config
->size
> 0
1030 && what_they_get
> config
->size
)
1031 what_they_get
= config
->size
;
1033 /* Limit it to the size of the targets ``g'' response unless we have
1034 permission from the stub to use a larger packet size. */
1035 if (rs
->explicit_packet_size
== 0
1036 && rsa
->actual_register_packet_size
> 0
1037 && what_they_get
> rsa
->actual_register_packet_size
)
1038 what_they_get
= rsa
->actual_register_packet_size
;
1040 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1041 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1043 /* Make sure there is room in the global buffer for this packet
1044 (including its trailing NUL byte). */
1045 if (rs
->buf_size
< what_they_get
+ 1)
1047 rs
->buf_size
= 2 * what_they_get
;
1048 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1051 return what_they_get
;
1054 /* Update the size of a read/write packet. If they user wants
1055 something really big then do a sanity check. */
1058 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1060 int fixed_p
= config
->fixed_p
;
1061 long size
= config
->size
;
1064 error (_("Argument required (integer, `fixed' or `limited')."));
1065 else if (strcmp (args
, "hard") == 0
1066 || strcmp (args
, "fixed") == 0)
1068 else if (strcmp (args
, "soft") == 0
1069 || strcmp (args
, "limit") == 0)
1075 size
= strtoul (args
, &end
, 0);
1077 error (_("Invalid %s (bad syntax)."), config
->name
);
1079 /* Instead of explicitly capping the size of a packet to or
1080 disallowing it, the user is allowed to set the size to
1081 something arbitrarily large. */
1084 /* So that the query shows the correct value. */
1086 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1089 if (fixed_p
&& !config
->fixed_p
)
1091 if (! query (_("The target may not be able to correctly handle a %s\n"
1092 "of %ld bytes. Change the packet size? "),
1093 config
->name
, size
))
1094 error (_("Packet size not changed."));
1096 /* Update the config. */
1097 config
->fixed_p
= fixed_p
;
1098 config
->size
= size
;
1102 show_memory_packet_size (struct memory_packet_config
*config
)
1104 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1105 if (config
->fixed_p
)
1106 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1107 get_memory_packet_size (config
));
1109 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1110 get_memory_packet_size (config
));
1113 static struct memory_packet_config memory_write_packet_config
=
1115 "memory-write-packet-size",
1119 set_memory_write_packet_size (char *args
, int from_tty
)
1121 set_memory_packet_size (args
, &memory_write_packet_config
);
1125 show_memory_write_packet_size (char *args
, int from_tty
)
1127 show_memory_packet_size (&memory_write_packet_config
);
1131 get_memory_write_packet_size (void)
1133 return get_memory_packet_size (&memory_write_packet_config
);
1136 static struct memory_packet_config memory_read_packet_config
=
1138 "memory-read-packet-size",
1142 set_memory_read_packet_size (char *args
, int from_tty
)
1144 set_memory_packet_size (args
, &memory_read_packet_config
);
1148 show_memory_read_packet_size (char *args
, int from_tty
)
1150 show_memory_packet_size (&memory_read_packet_config
);
1154 get_memory_read_packet_size (void)
1156 long size
= get_memory_packet_size (&memory_read_packet_config
);
1158 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1159 extra buffer size argument before the memory read size can be
1160 increased beyond this. */
1161 if (size
> get_remote_packet_size ())
1162 size
= get_remote_packet_size ();
1167 /* Generic configuration support for packets the stub optionally
1168 supports. Allows the user to specify the use of the packet as well
1169 as allowing GDB to auto-detect support in the remote stub. */
1173 PACKET_SUPPORT_UNKNOWN
= 0,
1178 struct packet_config
1183 /* If auto, GDB auto-detects support for this packet or feature,
1184 either through qSupported, or by trying the packet and looking
1185 at the response. If true, GDB assumes the target supports this
1186 packet. If false, the packet is disabled. Configs that don't
1187 have an associated command always have this set to auto. */
1188 enum auto_boolean detect
;
1190 /* Does the target support this packet? */
1191 enum packet_support support
;
1194 /* Analyze a packet's return value and update the packet config
1204 static enum packet_support
packet_config_support (struct packet_config
*config
);
1205 static enum packet_support
packet_support (int packet
);
1208 show_packet_config_cmd (struct packet_config
*config
)
1210 char *support
= "internal-error";
1212 switch (packet_config_support (config
))
1215 support
= "enabled";
1217 case PACKET_DISABLE
:
1218 support
= "disabled";
1220 case PACKET_SUPPORT_UNKNOWN
:
1221 support
= "unknown";
1224 switch (config
->detect
)
1226 case AUTO_BOOLEAN_AUTO
:
1227 printf_filtered (_("Support for the `%s' packet "
1228 "is auto-detected, currently %s.\n"),
1229 config
->name
, support
);
1231 case AUTO_BOOLEAN_TRUE
:
1232 case AUTO_BOOLEAN_FALSE
:
1233 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1234 config
->name
, support
);
1240 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1241 const char *title
, int legacy
)
1247 config
->name
= name
;
1248 config
->title
= title
;
1249 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1251 show_doc
= xstrprintf ("Show current use of remote "
1252 "protocol `%s' (%s) packet",
1254 /* set/show TITLE-packet {auto,on,off} */
1255 cmd_name
= xstrprintf ("%s-packet", title
);
1256 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1257 &config
->detect
, set_doc
,
1258 show_doc
, NULL
, /* help_doc */
1260 show_remote_protocol_packet_cmd
,
1261 &remote_set_cmdlist
, &remote_show_cmdlist
);
1262 /* The command code copies the documentation strings. */
1265 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1270 legacy_name
= xstrprintf ("%s-packet", name
);
1271 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1272 &remote_set_cmdlist
);
1273 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1274 &remote_show_cmdlist
);
1278 static enum packet_result
1279 packet_check_result (const char *buf
)
1283 /* The stub recognized the packet request. Check that the
1284 operation succeeded. */
1286 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1288 /* "Enn" - definitly an error. */
1289 return PACKET_ERROR
;
1291 /* Always treat "E." as an error. This will be used for
1292 more verbose error messages, such as E.memtypes. */
1293 if (buf
[0] == 'E' && buf
[1] == '.')
1294 return PACKET_ERROR
;
1296 /* The packet may or may not be OK. Just assume it is. */
1300 /* The stub does not support the packet. */
1301 return PACKET_UNKNOWN
;
1304 static enum packet_result
1305 packet_ok (const char *buf
, struct packet_config
*config
)
1307 enum packet_result result
;
1309 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1310 && config
->support
== PACKET_DISABLE
)
1311 internal_error (__FILE__
, __LINE__
,
1312 _("packet_ok: attempt to use a disabled packet"));
1314 result
= packet_check_result (buf
);
1319 /* The stub recognized the packet request. */
1320 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1323 fprintf_unfiltered (gdb_stdlog
,
1324 "Packet %s (%s) is supported\n",
1325 config
->name
, config
->title
);
1326 config
->support
= PACKET_ENABLE
;
1329 case PACKET_UNKNOWN
:
1330 /* The stub does not support the packet. */
1331 if (config
->detect
== AUTO_BOOLEAN_AUTO
1332 && config
->support
== PACKET_ENABLE
)
1334 /* If the stub previously indicated that the packet was
1335 supported then there is a protocol error. */
1336 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1337 config
->name
, config
->title
);
1339 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1341 /* The user set it wrong. */
1342 error (_("Enabled packet %s (%s) not recognized by stub"),
1343 config
->name
, config
->title
);
1347 fprintf_unfiltered (gdb_stdlog
,
1348 "Packet %s (%s) is NOT supported\n",
1349 config
->name
, config
->title
);
1350 config
->support
= PACKET_DISABLE
;
1371 PACKET_vFile_pwrite
,
1373 PACKET_vFile_unlink
,
1374 PACKET_vFile_readlink
,
1377 PACKET_qXfer_features
,
1378 PACKET_qXfer_exec_file
,
1379 PACKET_qXfer_libraries
,
1380 PACKET_qXfer_libraries_svr4
,
1381 PACKET_qXfer_memory_map
,
1382 PACKET_qXfer_spu_read
,
1383 PACKET_qXfer_spu_write
,
1384 PACKET_qXfer_osdata
,
1385 PACKET_qXfer_threads
,
1386 PACKET_qXfer_statictrace_read
,
1387 PACKET_qXfer_traceframe_info
,
1393 PACKET_QPassSignals
,
1394 PACKET_QCatchSyscalls
,
1395 PACKET_QProgramSignals
,
1397 PACKET_qSearch_memory
,
1400 PACKET_QStartNoAckMode
,
1402 PACKET_qXfer_siginfo_read
,
1403 PACKET_qXfer_siginfo_write
,
1406 /* Support for conditional tracepoints. */
1407 PACKET_ConditionalTracepoints
,
1409 /* Support for target-side breakpoint conditions. */
1410 PACKET_ConditionalBreakpoints
,
1412 /* Support for target-side breakpoint commands. */
1413 PACKET_BreakpointCommands
,
1415 /* Support for fast tracepoints. */
1416 PACKET_FastTracepoints
,
1418 /* Support for static tracepoints. */
1419 PACKET_StaticTracepoints
,
1421 /* Support for installing tracepoints while a trace experiment is
1423 PACKET_InstallInTrace
,
1427 PACKET_TracepointSource
,
1430 PACKET_QDisableRandomization
,
1432 PACKET_QTBuffer_size
,
1436 PACKET_qXfer_btrace
,
1438 /* Support for the QNonStop packet. */
1441 /* Support for the QThreadEvents packet. */
1442 PACKET_QThreadEvents
,
1444 /* Support for multi-process extensions. */
1445 PACKET_multiprocess_feature
,
1447 /* Support for enabling and disabling tracepoints while a trace
1448 experiment is running. */
1449 PACKET_EnableDisableTracepoints_feature
,
1451 /* Support for collecting strings using the tracenz bytecode. */
1452 PACKET_tracenz_feature
,
1454 /* Support for continuing to run a trace experiment while GDB is
1456 PACKET_DisconnectedTracing_feature
,
1458 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1459 PACKET_augmented_libraries_svr4_read_feature
,
1461 /* Support for the qXfer:btrace-conf:read packet. */
1462 PACKET_qXfer_btrace_conf
,
1464 /* Support for the Qbtrace-conf:bts:size packet. */
1465 PACKET_Qbtrace_conf_bts_size
,
1467 /* Support for swbreak+ feature. */
1468 PACKET_swbreak_feature
,
1470 /* Support for hwbreak+ feature. */
1471 PACKET_hwbreak_feature
,
1473 /* Support for fork events. */
1474 PACKET_fork_event_feature
,
1476 /* Support for vfork events. */
1477 PACKET_vfork_event_feature
,
1479 /* Support for the Qbtrace-conf:pt:size packet. */
1480 PACKET_Qbtrace_conf_pt_size
,
1482 /* Support for exec events. */
1483 PACKET_exec_event_feature
,
1485 /* Support for query supported vCont actions. */
1486 PACKET_vContSupported
,
1488 /* Support remote CTRL-C. */
1491 /* Support TARGET_WAITKIND_NO_RESUMED. */
1497 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1499 /* Returns the packet's corresponding "set remote foo-packet" command
1500 state. See struct packet_config for more details. */
1502 static enum auto_boolean
1503 packet_set_cmd_state (int packet
)
1505 return remote_protocol_packets
[packet
].detect
;
1508 /* Returns whether a given packet or feature is supported. This takes
1509 into account the state of the corresponding "set remote foo-packet"
1510 command, which may be used to bypass auto-detection. */
1512 static enum packet_support
1513 packet_config_support (struct packet_config
*config
)
1515 switch (config
->detect
)
1517 case AUTO_BOOLEAN_TRUE
:
1518 return PACKET_ENABLE
;
1519 case AUTO_BOOLEAN_FALSE
:
1520 return PACKET_DISABLE
;
1521 case AUTO_BOOLEAN_AUTO
:
1522 return config
->support
;
1524 gdb_assert_not_reached (_("bad switch"));
1528 /* Same as packet_config_support, but takes the packet's enum value as
1531 static enum packet_support
1532 packet_support (int packet
)
1534 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1536 return packet_config_support (config
);
1540 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1541 struct cmd_list_element
*c
,
1544 struct packet_config
*packet
;
1546 for (packet
= remote_protocol_packets
;
1547 packet
< &remote_protocol_packets
[PACKET_MAX
];
1550 if (&packet
->detect
== c
->var
)
1552 show_packet_config_cmd (packet
);
1556 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1560 /* Should we try one of the 'Z' requests? */
1564 Z_PACKET_SOFTWARE_BP
,
1565 Z_PACKET_HARDWARE_BP
,
1572 /* For compatibility with older distributions. Provide a ``set remote
1573 Z-packet ...'' command that updates all the Z packet types. */
1575 static enum auto_boolean remote_Z_packet_detect
;
1578 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1579 struct cmd_list_element
*c
)
1583 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1584 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1588 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1589 struct cmd_list_element
*c
,
1594 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1596 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1600 /* Returns true if the multi-process extensions are in effect. */
1603 remote_multi_process_p (struct remote_state
*rs
)
1605 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1608 /* Returns true if fork events are supported. */
1611 remote_fork_event_p (struct remote_state
*rs
)
1613 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1616 /* Returns true if vfork events are supported. */
1619 remote_vfork_event_p (struct remote_state
*rs
)
1621 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1624 /* Returns true if exec events are supported. */
1627 remote_exec_event_p (struct remote_state
*rs
)
1629 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1632 /* Insert fork catchpoint target routine. If fork events are enabled
1633 then return success, nothing more to do. */
1636 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1638 struct remote_state
*rs
= get_remote_state ();
1640 return !remote_fork_event_p (rs
);
1643 /* Remove fork catchpoint target routine. Nothing to do, just
1647 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1652 /* Insert vfork catchpoint target routine. If vfork events are enabled
1653 then return success, nothing more to do. */
1656 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1658 struct remote_state
*rs
= get_remote_state ();
1660 return !remote_vfork_event_p (rs
);
1663 /* Remove vfork catchpoint target routine. Nothing to do, just
1667 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1672 /* Insert exec catchpoint target routine. If exec events are
1673 enabled, just return success. */
1676 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1678 struct remote_state
*rs
= get_remote_state ();
1680 return !remote_exec_event_p (rs
);
1683 /* Remove exec catchpoint target routine. Nothing to do, just
1687 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1692 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1693 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1694 static struct async_signal_handler
*async_sigint_remote_token
;
1697 /* Asynchronous signal handle registered as event loop source for
1698 when we have pending events ready to be passed to the core. */
1700 static struct async_event_handler
*remote_async_inferior_event_token
;
1704 static ptid_t magic_null_ptid
;
1705 static ptid_t not_sent_ptid
;
1706 static ptid_t any_thread_ptid
;
1708 /* Find out if the stub attached to PID (and hence GDB should offer to
1709 detach instead of killing it when bailing out). */
1712 remote_query_attached (int pid
)
1714 struct remote_state
*rs
= get_remote_state ();
1715 size_t size
= get_remote_packet_size ();
1717 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1720 if (remote_multi_process_p (rs
))
1721 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1723 xsnprintf (rs
->buf
, size
, "qAttached");
1726 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1728 switch (packet_ok (rs
->buf
,
1729 &remote_protocol_packets
[PACKET_qAttached
]))
1732 if (strcmp (rs
->buf
, "1") == 0)
1736 warning (_("Remote failure reply: %s"), rs
->buf
);
1738 case PACKET_UNKNOWN
:
1745 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1746 has been invented by GDB, instead of reported by the target. Since
1747 we can be connected to a remote system before before knowing about
1748 any inferior, mark the target with execution when we find the first
1749 inferior. If ATTACHED is 1, then we had just attached to this
1750 inferior. If it is 0, then we just created this inferior. If it
1751 is -1, then try querying the remote stub to find out if it had
1752 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1753 attempt to open this inferior's executable as the main executable
1754 if no main executable is open already. */
1756 static struct inferior
*
1757 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1760 struct inferior
*inf
;
1762 /* Check whether this process we're learning about is to be
1763 considered attached, or if is to be considered to have been
1764 spawned by the stub. */
1766 attached
= remote_query_attached (pid
);
1768 if (gdbarch_has_global_solist (target_gdbarch ()))
1770 /* If the target shares code across all inferiors, then every
1771 attach adds a new inferior. */
1772 inf
= add_inferior (pid
);
1774 /* ... and every inferior is bound to the same program space.
1775 However, each inferior may still have its own address
1777 inf
->aspace
= maybe_new_address_space ();
1778 inf
->pspace
= current_program_space
;
1782 /* In the traditional debugging scenario, there's a 1-1 match
1783 between program/address spaces. We simply bind the inferior
1784 to the program space's address space. */
1785 inf
= current_inferior ();
1786 inferior_appeared (inf
, pid
);
1789 inf
->attach_flag
= attached
;
1790 inf
->fake_pid_p
= fake_pid_p
;
1792 /* If no main executable is currently open then attempt to
1793 open the file that was executed to create this inferior. */
1794 if (try_open_exec
&& get_exec_file (0) == NULL
)
1795 exec_file_locate_attach (pid
, 1);
1800 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1801 according to RUNNING. */
1804 remote_add_thread (ptid_t ptid
, int running
)
1806 struct remote_state
*rs
= get_remote_state ();
1808 /* GDB historically didn't pull threads in the initial connection
1809 setup. If the remote target doesn't even have a concept of
1810 threads (e.g., a bare-metal target), even if internally we
1811 consider that a single-threaded target, mentioning a new thread
1812 might be confusing to the user. Be silent then, preserving the
1813 age old behavior. */
1814 if (rs
->starting_up
)
1815 add_thread_silent (ptid
);
1819 set_executing (ptid
, running
);
1820 set_running (ptid
, running
);
1823 /* Come here when we learn about a thread id from the remote target.
1824 It may be the first time we hear about such thread, so take the
1825 opportunity to add it to GDB's thread list. In case this is the
1826 first time we're noticing its corresponding inferior, add it to
1827 GDB's inferior list as well. */
1830 remote_notice_new_inferior (ptid_t currthread
, int running
)
1832 /* If this is a new thread, add it to GDB's thread list.
1833 If we leave it up to WFI to do this, bad things will happen. */
1835 if (in_thread_list (currthread
) && is_exited (currthread
))
1837 /* We're seeing an event on a thread id we knew had exited.
1838 This has to be a new thread reusing the old id. Add it. */
1839 remote_add_thread (currthread
, running
);
1843 if (!in_thread_list (currthread
))
1845 struct inferior
*inf
= NULL
;
1846 int pid
= ptid_get_pid (currthread
);
1848 if (ptid_is_pid (inferior_ptid
)
1849 && pid
== ptid_get_pid (inferior_ptid
))
1851 /* inferior_ptid has no thread member yet. This can happen
1852 with the vAttach -> remote_wait,"TAAthread:" path if the
1853 stub doesn't support qC. This is the first stop reported
1854 after an attach, so this is the main thread. Update the
1855 ptid in the thread list. */
1856 if (in_thread_list (pid_to_ptid (pid
)))
1857 thread_change_ptid (inferior_ptid
, currthread
);
1860 remote_add_thread (currthread
, running
);
1861 inferior_ptid
= currthread
;
1866 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1868 /* inferior_ptid is not set yet. This can happen with the
1869 vRun -> remote_wait,"TAAthread:" path if the stub
1870 doesn't support qC. This is the first stop reported
1871 after an attach, so this is the main thread. Update the
1872 ptid in the thread list. */
1873 thread_change_ptid (inferior_ptid
, currthread
);
1877 /* When connecting to a target remote, or to a target
1878 extended-remote which already was debugging an inferior, we
1879 may not know about it yet. Add it before adding its child
1880 thread, so notifications are emitted in a sensible order. */
1881 if (!in_inferior_list (ptid_get_pid (currthread
)))
1883 struct remote_state
*rs
= get_remote_state ();
1884 int fake_pid_p
= !remote_multi_process_p (rs
);
1886 inf
= remote_add_inferior (fake_pid_p
,
1887 ptid_get_pid (currthread
), -1, 1);
1890 /* This is really a new thread. Add it. */
1891 remote_add_thread (currthread
, running
);
1893 /* If we found a new inferior, let the common code do whatever
1894 it needs to with it (e.g., read shared libraries, insert
1895 breakpoints), unless we're just setting up an all-stop
1899 struct remote_state
*rs
= get_remote_state ();
1901 if (!rs
->starting_up
)
1902 notice_new_inferior (currthread
, running
, 0);
1907 /* Return the private thread data, creating it if necessary. */
1909 static struct private_thread_info
*
1910 demand_private_info (ptid_t ptid
)
1912 struct thread_info
*info
= find_thread_ptid (ptid
);
1918 info
->priv
= XNEW (struct private_thread_info
);
1919 info
->private_dtor
= free_private_thread_info
;
1920 info
->priv
->core
= -1;
1921 info
->priv
->extra
= NULL
;
1922 info
->priv
->name
= NULL
;
1928 /* Call this function as a result of
1929 1) A halt indication (T packet) containing a thread id
1930 2) A direct query of currthread
1931 3) Successful execution of set thread */
1934 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1936 rs
->general_thread
= currthread
;
1939 /* If 'QPassSignals' is supported, tell the remote stub what signals
1940 it can simply pass through to the inferior without reporting. */
1943 remote_pass_signals (struct target_ops
*self
,
1944 int numsigs
, unsigned char *pass_signals
)
1946 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1948 char *pass_packet
, *p
;
1950 struct remote_state
*rs
= get_remote_state ();
1952 gdb_assert (numsigs
< 256);
1953 for (i
= 0; i
< numsigs
; i
++)
1955 if (pass_signals
[i
])
1958 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1959 strcpy (pass_packet
, "QPassSignals:");
1960 p
= pass_packet
+ strlen (pass_packet
);
1961 for (i
= 0; i
< numsigs
; i
++)
1963 if (pass_signals
[i
])
1966 *p
++ = tohex (i
>> 4);
1967 *p
++ = tohex (i
& 15);
1976 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1978 putpkt (pass_packet
);
1979 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1980 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1981 if (rs
->last_pass_packet
)
1982 xfree (rs
->last_pass_packet
);
1983 rs
->last_pass_packet
= pass_packet
;
1986 xfree (pass_packet
);
1990 /* If 'QCatchSyscalls' is supported, tell the remote stub
1991 to report syscalls to GDB. */
1994 remote_set_syscall_catchpoint (struct target_ops
*self
,
1995 int pid
, int needed
, int any_count
,
1996 int table_size
, int *table
)
1999 enum packet_result result
;
2002 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2004 /* Not supported. */
2008 if (needed
&& !any_count
)
2012 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2013 for (i
= 0; i
< table_size
; i
++)
2022 fprintf_unfiltered (gdb_stdlog
,
2023 "remote_set_syscall_catchpoint "
2024 "pid %d needed %d any_count %d n_sysno %d\n",
2025 pid
, needed
, any_count
, n_sysno
);
2030 /* Prepare a packet with the sysno list, assuming max 8+1
2031 characters for a sysno. If the resulting packet size is too
2032 big, fallback on the non-selective packet. */
2033 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2035 catch_packet
= (char *) xmalloc (maxpktsz
);
2036 strcpy (catch_packet
, "QCatchSyscalls:1");
2045 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2046 for (i
= 0; i
< table_size
; i
++)
2049 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2052 if (strlen (catch_packet
) > get_remote_packet_size ())
2054 /* catch_packet too big. Fallback to less efficient
2055 non selective mode, with GDB doing the filtering. */
2056 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2060 catch_packet
= xstrdup ("QCatchSyscalls:0");
2063 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2064 struct remote_state
*rs
= get_remote_state ();
2066 putpkt (catch_packet
);
2067 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2068 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2069 do_cleanups (old_chain
);
2070 if (result
== PACKET_OK
)
2077 /* If 'QProgramSignals' is supported, tell the remote stub what
2078 signals it should pass through to the inferior when detaching. */
2081 remote_program_signals (struct target_ops
*self
,
2082 int numsigs
, unsigned char *signals
)
2084 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2088 struct remote_state
*rs
= get_remote_state ();
2090 gdb_assert (numsigs
< 256);
2091 for (i
= 0; i
< numsigs
; i
++)
2096 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2097 strcpy (packet
, "QProgramSignals:");
2098 p
= packet
+ strlen (packet
);
2099 for (i
= 0; i
< numsigs
; i
++)
2101 if (signal_pass_state (i
))
2104 *p
++ = tohex (i
>> 4);
2105 *p
++ = tohex (i
& 15);
2114 if (!rs
->last_program_signals_packet
2115 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2119 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2120 xfree (rs
->last_program_signals_packet
);
2121 rs
->last_program_signals_packet
= packet
;
2128 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2129 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2130 thread. If GEN is set, set the general thread, if not, then set
2131 the step/continue thread. */
2133 set_thread (struct ptid ptid
, int gen
)
2135 struct remote_state
*rs
= get_remote_state ();
2136 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2137 char *buf
= rs
->buf
;
2138 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2140 if (ptid_equal (state
, ptid
))
2144 *buf
++ = gen
? 'g' : 'c';
2145 if (ptid_equal (ptid
, magic_null_ptid
))
2146 xsnprintf (buf
, endbuf
- buf
, "0");
2147 else if (ptid_equal (ptid
, any_thread_ptid
))
2148 xsnprintf (buf
, endbuf
- buf
, "0");
2149 else if (ptid_equal (ptid
, minus_one_ptid
))
2150 xsnprintf (buf
, endbuf
- buf
, "-1");
2152 write_ptid (buf
, endbuf
, ptid
);
2154 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2156 rs
->general_thread
= ptid
;
2158 rs
->continue_thread
= ptid
;
2162 set_general_thread (struct ptid ptid
)
2164 set_thread (ptid
, 1);
2168 set_continue_thread (struct ptid ptid
)
2170 set_thread (ptid
, 0);
2173 /* Change the remote current process. Which thread within the process
2174 ends up selected isn't important, as long as it is the same process
2175 as what INFERIOR_PTID points to.
2177 This comes from that fact that there is no explicit notion of
2178 "selected process" in the protocol. The selected process for
2179 general operations is the process the selected general thread
2183 set_general_process (void)
2185 struct remote_state
*rs
= get_remote_state ();
2187 /* If the remote can't handle multiple processes, don't bother. */
2188 if (!remote_multi_process_p (rs
))
2191 /* We only need to change the remote current thread if it's pointing
2192 at some other process. */
2193 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2194 set_general_thread (inferior_ptid
);
2198 /* Return nonzero if this is the main thread that we made up ourselves
2199 to model non-threaded targets as single-threaded. */
2202 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2204 if (ptid_equal (ptid
, magic_null_ptid
))
2205 /* The main thread is always alive. */
2208 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2209 /* The main thread is always alive. This can happen after a
2210 vAttach, if the remote side doesn't support
2217 /* Return nonzero if the thread PTID is still alive on the remote
2221 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2223 struct remote_state
*rs
= get_remote_state ();
2226 /* Check if this is a thread that we made up ourselves to model
2227 non-threaded targets as single-threaded. */
2228 if (remote_thread_always_alive (ops
, ptid
))
2232 endp
= rs
->buf
+ get_remote_packet_size ();
2235 write_ptid (p
, endp
, ptid
);
2238 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2239 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2242 /* Return a pointer to a thread name if we know it and NULL otherwise.
2243 The thread_info object owns the memory for the name. */
2246 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2248 if (info
->priv
!= NULL
)
2249 return info
->priv
->name
;
2254 /* About these extended threadlist and threadinfo packets. They are
2255 variable length packets but, the fields within them are often fixed
2256 length. They are redundent enough to send over UDP as is the
2257 remote protocol in general. There is a matching unit test module
2260 /* WARNING: This threadref data structure comes from the remote O.S.,
2261 libstub protocol encoding, and remote.c. It is not particularly
2264 /* Right now, the internal structure is int. We want it to be bigger.
2265 Plan to fix this. */
2267 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2269 /* gdb_ext_thread_info is an internal GDB data structure which is
2270 equivalent to the reply of the remote threadinfo packet. */
2272 struct gdb_ext_thread_info
2274 threadref threadid
; /* External form of thread reference. */
2275 int active
; /* Has state interesting to GDB?
2277 char display
[256]; /* Brief state display, name,
2278 blocked/suspended. */
2279 char shortname
[32]; /* To be used to name threads. */
2280 char more_display
[256]; /* Long info, statistics, queue depth,
2284 /* The volume of remote transfers can be limited by submitting
2285 a mask containing bits specifying the desired information.
2286 Use a union of these values as the 'selection' parameter to
2287 get_thread_info. FIXME: Make these TAG names more thread specific. */
2289 #define TAG_THREADID 1
2290 #define TAG_EXISTS 2
2291 #define TAG_DISPLAY 4
2292 #define TAG_THREADNAME 8
2293 #define TAG_MOREDISPLAY 16
2295 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2297 static char *unpack_nibble (char *buf
, int *val
);
2299 static char *unpack_byte (char *buf
, int *value
);
2301 static char *pack_int (char *buf
, int value
);
2303 static char *unpack_int (char *buf
, int *value
);
2305 static char *unpack_string (char *src
, char *dest
, int length
);
2307 static char *pack_threadid (char *pkt
, threadref
*id
);
2309 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2311 void int_to_threadref (threadref
*id
, int value
);
2313 static int threadref_to_int (threadref
*ref
);
2315 static void copy_threadref (threadref
*dest
, threadref
*src
);
2317 static int threadmatch (threadref
*dest
, threadref
*src
);
2319 static char *pack_threadinfo_request (char *pkt
, int mode
,
2322 static int remote_unpack_thread_info_response (char *pkt
,
2323 threadref
*expectedref
,
2324 struct gdb_ext_thread_info
2328 static int remote_get_threadinfo (threadref
*threadid
,
2329 int fieldset
, /*TAG mask */
2330 struct gdb_ext_thread_info
*info
);
2332 static char *pack_threadlist_request (char *pkt
, int startflag
,
2334 threadref
*nextthread
);
2336 static int parse_threadlist_response (char *pkt
,
2338 threadref
*original_echo
,
2339 threadref
*resultlist
,
2342 static int remote_get_threadlist (int startflag
,
2343 threadref
*nextthread
,
2347 threadref
*threadlist
);
2349 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2351 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2352 void *context
, int looplimit
);
2354 static int remote_newthread_step (threadref
*ref
, void *context
);
2357 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2358 buffer we're allowed to write to. Returns
2359 BUF+CHARACTERS_WRITTEN. */
2362 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2365 struct remote_state
*rs
= get_remote_state ();
2367 if (remote_multi_process_p (rs
))
2369 pid
= ptid_get_pid (ptid
);
2371 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2373 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2375 tid
= ptid_get_lwp (ptid
);
2377 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2379 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2384 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2385 passed the last parsed char. Returns null_ptid on error. */
2388 read_ptid (char *buf
, char **obuf
)
2392 ULONGEST pid
= 0, tid
= 0;
2396 /* Multi-process ptid. */
2397 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2399 error (_("invalid remote ptid: %s"), p
);
2402 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2405 return ptid_build (pid
, tid
, 0);
2408 /* No multi-process. Just a tid. */
2409 pp
= unpack_varlen_hex (p
, &tid
);
2411 /* Return null_ptid when no thread id is found. */
2419 /* Since the stub is not sending a process id, then default to
2420 what's in inferior_ptid, unless it's null at this point. If so,
2421 then since there's no way to know the pid of the reported
2422 threads, use the magic number. */
2423 if (ptid_equal (inferior_ptid
, null_ptid
))
2424 pid
= ptid_get_pid (magic_null_ptid
);
2426 pid
= ptid_get_pid (inferior_ptid
);
2430 return ptid_build (pid
, tid
, 0);
2436 if (ch
>= 'a' && ch
<= 'f')
2437 return ch
- 'a' + 10;
2438 if (ch
>= '0' && ch
<= '9')
2440 if (ch
>= 'A' && ch
<= 'F')
2441 return ch
- 'A' + 10;
2446 stub_unpack_int (char *buff
, int fieldlength
)
2453 nibble
= stubhex (*buff
++);
2457 retval
= retval
<< 4;
2463 unpack_nibble (char *buf
, int *val
)
2465 *val
= fromhex (*buf
++);
2470 unpack_byte (char *buf
, int *value
)
2472 *value
= stub_unpack_int (buf
, 2);
2477 pack_int (char *buf
, int value
)
2479 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2480 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2481 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2482 buf
= pack_hex_byte (buf
, (value
& 0xff));
2487 unpack_int (char *buf
, int *value
)
2489 *value
= stub_unpack_int (buf
, 8);
2493 #if 0 /* Currently unused, uncomment when needed. */
2494 static char *pack_string (char *pkt
, char *string
);
2497 pack_string (char *pkt
, char *string
)
2502 len
= strlen (string
);
2504 len
= 200; /* Bigger than most GDB packets, junk??? */
2505 pkt
= pack_hex_byte (pkt
, len
);
2509 if ((ch
== '\0') || (ch
== '#'))
2510 ch
= '*'; /* Protect encapsulation. */
2515 #endif /* 0 (unused) */
2518 unpack_string (char *src
, char *dest
, int length
)
2527 pack_threadid (char *pkt
, threadref
*id
)
2530 unsigned char *altid
;
2532 altid
= (unsigned char *) id
;
2533 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2535 pkt
= pack_hex_byte (pkt
, *altid
++);
2541 unpack_threadid (char *inbuf
, threadref
*id
)
2544 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2547 altref
= (char *) id
;
2549 while (inbuf
< limit
)
2551 x
= stubhex (*inbuf
++);
2552 y
= stubhex (*inbuf
++);
2553 *altref
++ = (x
<< 4) | y
;
2558 /* Externally, threadrefs are 64 bits but internally, they are still
2559 ints. This is due to a mismatch of specifications. We would like
2560 to use 64bit thread references internally. This is an adapter
2564 int_to_threadref (threadref
*id
, int value
)
2566 unsigned char *scan
;
2568 scan
= (unsigned char *) id
;
2574 *scan
++ = (value
>> 24) & 0xff;
2575 *scan
++ = (value
>> 16) & 0xff;
2576 *scan
++ = (value
>> 8) & 0xff;
2577 *scan
++ = (value
& 0xff);
2581 threadref_to_int (threadref
*ref
)
2584 unsigned char *scan
;
2590 value
= (value
<< 8) | ((*scan
++) & 0xff);
2595 copy_threadref (threadref
*dest
, threadref
*src
)
2598 unsigned char *csrc
, *cdest
;
2600 csrc
= (unsigned char *) src
;
2601 cdest
= (unsigned char *) dest
;
2608 threadmatch (threadref
*dest
, threadref
*src
)
2610 /* Things are broken right now, so just assume we got a match. */
2612 unsigned char *srcp
, *destp
;
2614 srcp
= (char *) src
;
2615 destp
= (char *) dest
;
2619 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2626 threadid:1, # always request threadid
2633 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2636 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2638 *pkt
++ = 'q'; /* Info Query */
2639 *pkt
++ = 'P'; /* process or thread info */
2640 pkt
= pack_int (pkt
, mode
); /* mode */
2641 pkt
= pack_threadid (pkt
, id
); /* threadid */
2642 *pkt
= '\0'; /* terminate */
2646 /* These values tag the fields in a thread info response packet. */
2647 /* Tagging the fields allows us to request specific fields and to
2648 add more fields as time goes by. */
2650 #define TAG_THREADID 1 /* Echo the thread identifier. */
2651 #define TAG_EXISTS 2 /* Is this process defined enough to
2652 fetch registers and its stack? */
2653 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2654 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2655 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2659 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2660 struct gdb_ext_thread_info
*info
)
2662 struct remote_state
*rs
= get_remote_state ();
2666 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2669 /* info->threadid = 0; FIXME: implement zero_threadref. */
2671 info
->display
[0] = '\0';
2672 info
->shortname
[0] = '\0';
2673 info
->more_display
[0] = '\0';
2675 /* Assume the characters indicating the packet type have been
2677 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2678 pkt
= unpack_threadid (pkt
, &ref
);
2681 warning (_("Incomplete response to threadinfo request."));
2682 if (!threadmatch (&ref
, expectedref
))
2683 { /* This is an answer to a different request. */
2684 warning (_("ERROR RMT Thread info mismatch."));
2687 copy_threadref (&info
->threadid
, &ref
);
2689 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2691 /* Packets are terminated with nulls. */
2692 while ((pkt
< limit
) && mask
&& *pkt
)
2694 pkt
= unpack_int (pkt
, &tag
); /* tag */
2695 pkt
= unpack_byte (pkt
, &length
); /* length */
2696 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2698 warning (_("ERROR RMT: threadinfo tag mismatch."));
2702 if (tag
== TAG_THREADID
)
2706 warning (_("ERROR RMT: length of threadid is not 16."));
2710 pkt
= unpack_threadid (pkt
, &ref
);
2711 mask
= mask
& ~TAG_THREADID
;
2714 if (tag
== TAG_EXISTS
)
2716 info
->active
= stub_unpack_int (pkt
, length
);
2718 mask
= mask
& ~(TAG_EXISTS
);
2721 warning (_("ERROR RMT: 'exists' length too long."));
2727 if (tag
== TAG_THREADNAME
)
2729 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2730 mask
= mask
& ~TAG_THREADNAME
;
2733 if (tag
== TAG_DISPLAY
)
2735 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2736 mask
= mask
& ~TAG_DISPLAY
;
2739 if (tag
== TAG_MOREDISPLAY
)
2741 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2742 mask
= mask
& ~TAG_MOREDISPLAY
;
2745 warning (_("ERROR RMT: unknown thread info tag."));
2746 break; /* Not a tag we know about. */
2752 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2753 struct gdb_ext_thread_info
*info
)
2755 struct remote_state
*rs
= get_remote_state ();
2758 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2760 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2762 if (rs
->buf
[0] == '\0')
2765 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2770 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2773 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2774 threadref
*nextthread
)
2776 *pkt
++ = 'q'; /* info query packet */
2777 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2778 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2779 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2780 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2785 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2788 parse_threadlist_response (char *pkt
, int result_limit
,
2789 threadref
*original_echo
, threadref
*resultlist
,
2792 struct remote_state
*rs
= get_remote_state ();
2794 int count
, resultcount
, done
;
2797 /* Assume the 'q' and 'M chars have been stripped. */
2798 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2799 /* done parse past here */
2800 pkt
= unpack_byte (pkt
, &count
); /* count field */
2801 pkt
= unpack_nibble (pkt
, &done
);
2802 /* The first threadid is the argument threadid. */
2803 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2804 while ((count
-- > 0) && (pkt
< limit
))
2806 pkt
= unpack_threadid (pkt
, resultlist
++);
2807 if (resultcount
++ >= result_limit
)
2815 /* Fetch the next batch of threads from the remote. Returns -1 if the
2816 qL packet is not supported, 0 on error and 1 on success. */
2819 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2820 int *done
, int *result_count
, threadref
*threadlist
)
2822 struct remote_state
*rs
= get_remote_state ();
2825 /* Trancate result limit to be smaller than the packet size. */
2826 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2827 >= get_remote_packet_size ())
2828 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2830 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2832 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2833 if (*rs
->buf
== '\0')
2835 /* Packet not supported. */
2840 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2841 &rs
->echo_nextthread
, threadlist
, done
);
2843 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2845 /* FIXME: This is a good reason to drop the packet. */
2846 /* Possably, there is a duplicate response. */
2848 retransmit immediatly - race conditions
2849 retransmit after timeout - yes
2851 wait for packet, then exit
2853 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2854 return 0; /* I choose simply exiting. */
2856 if (*result_count
<= 0)
2860 warning (_("RMT ERROR : failed to get remote thread list."));
2863 return result
; /* break; */
2865 if (*result_count
> result_limit
)
2868 warning (_("RMT ERROR: threadlist response longer than requested."));
2874 /* Fetch the list of remote threads, with the qL packet, and call
2875 STEPFUNCTION for each thread found. Stops iterating and returns 1
2876 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2877 STEPFUNCTION returns false. If the packet is not supported,
2881 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2884 struct remote_state
*rs
= get_remote_state ();
2885 int done
, i
, result_count
;
2893 if (loopcount
++ > looplimit
)
2896 warning (_("Remote fetch threadlist -infinite loop-."));
2899 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2900 MAXTHREADLISTRESULTS
,
2901 &done
, &result_count
,
2902 rs
->resultthreadlist
);
2905 /* Clear for later iterations. */
2907 /* Setup to resume next batch of thread references, set nextthread. */
2908 if (result_count
>= 1)
2909 copy_threadref (&rs
->nextthread
,
2910 &rs
->resultthreadlist
[result_count
- 1]);
2912 while (result_count
--)
2914 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2924 /* A thread found on the remote target. */
2926 typedef struct thread_item
2928 /* The thread's PTID. */
2931 /* The thread's extra info. May be NULL. */
2934 /* The thread's name. May be NULL. */
2937 /* The core the thread was running on. -1 if not known. */
2940 DEF_VEC_O(thread_item_t
);
2942 /* Context passed around to the various methods listing remote
2943 threads. As new threads are found, they're added to the ITEMS
2946 struct threads_listing_context
2948 /* The threads found on the remote target. */
2949 VEC (thread_item_t
) *items
;
2952 /* Discard the contents of the constructed thread listing context. */
2955 clear_threads_listing_context (void *p
)
2957 struct threads_listing_context
*context
2958 = (struct threads_listing_context
*) p
;
2960 struct thread_item
*item
;
2962 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2964 xfree (item
->extra
);
2968 VEC_free (thread_item_t
, context
->items
);
2971 /* Remove the thread specified as the related_pid field of WS
2972 from the CONTEXT list. */
2975 threads_listing_context_remove (struct target_waitstatus
*ws
,
2976 struct threads_listing_context
*context
)
2978 struct thread_item
*item
;
2980 ptid_t child_ptid
= ws
->value
.related_pid
;
2982 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2984 if (ptid_equal (item
->ptid
, child_ptid
))
2986 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2993 remote_newthread_step (threadref
*ref
, void *data
)
2995 struct threads_listing_context
*context
2996 = (struct threads_listing_context
*) data
;
2997 struct thread_item item
;
2998 int pid
= ptid_get_pid (inferior_ptid
);
3000 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3005 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3007 return 1; /* continue iterator */
3010 #define CRAZY_MAX_THREADS 1000
3013 remote_current_thread (ptid_t oldpid
)
3015 struct remote_state
*rs
= get_remote_state ();
3018 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3019 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3024 result
= read_ptid (&rs
->buf
[2], &obuf
);
3025 if (*obuf
!= '\0' && remote_debug
)
3026 fprintf_unfiltered (gdb_stdlog
,
3027 "warning: garbage in qC reply\n");
3035 /* List remote threads using the deprecated qL packet. */
3038 remote_get_threads_with_ql (struct target_ops
*ops
,
3039 struct threads_listing_context
*context
)
3041 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3042 CRAZY_MAX_THREADS
) >= 0)
3048 #if defined(HAVE_LIBEXPAT)
3051 start_thread (struct gdb_xml_parser
*parser
,
3052 const struct gdb_xml_element
*element
,
3053 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3055 struct threads_listing_context
*data
3056 = (struct threads_listing_context
*) user_data
;
3058 struct thread_item item
;
3060 struct gdb_xml_value
*attr
;
3062 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3063 item
.ptid
= read_ptid (id
, NULL
);
3065 attr
= xml_find_attribute (attributes
, "core");
3067 item
.core
= *(ULONGEST
*) attr
->value
;
3071 attr
= xml_find_attribute (attributes
, "name");
3072 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3076 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3080 end_thread (struct gdb_xml_parser
*parser
,
3081 const struct gdb_xml_element
*element
,
3082 void *user_data
, const char *body_text
)
3084 struct threads_listing_context
*data
3085 = (struct threads_listing_context
*) user_data
;
3087 if (body_text
&& *body_text
)
3088 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3091 const struct gdb_xml_attribute thread_attributes
[] = {
3092 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3093 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3094 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3095 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3098 const struct gdb_xml_element thread_children
[] = {
3099 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3102 const struct gdb_xml_element threads_children
[] = {
3103 { "thread", thread_attributes
, thread_children
,
3104 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3105 start_thread
, end_thread
},
3106 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3109 const struct gdb_xml_element threads_elements
[] = {
3110 { "threads", NULL
, threads_children
,
3111 GDB_XML_EF_NONE
, NULL
, NULL
},
3112 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3117 /* List remote threads using qXfer:threads:read. */
3120 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3121 struct threads_listing_context
*context
)
3123 #if defined(HAVE_LIBEXPAT)
3124 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3126 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3127 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3129 if (xml
!= NULL
&& *xml
!= '\0')
3131 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3132 threads_elements
, xml
, context
);
3135 do_cleanups (back_to
);
3143 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3146 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3147 struct threads_listing_context
*context
)
3149 struct remote_state
*rs
= get_remote_state ();
3151 if (rs
->use_threadinfo_query
)
3155 putpkt ("qfThreadInfo");
3156 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3158 if (bufp
[0] != '\0') /* q packet recognized */
3160 while (*bufp
++ == 'm') /* reply contains one or more TID */
3164 struct thread_item item
;
3166 item
.ptid
= read_ptid (bufp
, &bufp
);
3171 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3173 while (*bufp
++ == ','); /* comma-separated list */
3174 putpkt ("qsThreadInfo");
3175 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3182 /* Packet not recognized. */
3183 rs
->use_threadinfo_query
= 0;
3190 /* Implement the to_update_thread_list function for the remote
3194 remote_update_thread_list (struct target_ops
*ops
)
3196 struct threads_listing_context context
;
3197 struct cleanup
*old_chain
;
3200 context
.items
= NULL
;
3201 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3203 /* We have a few different mechanisms to fetch the thread list. Try
3204 them all, starting with the most preferred one first, falling
3205 back to older methods. */
3206 if (remote_get_threads_with_qxfer (ops
, &context
)
3207 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3208 || remote_get_threads_with_ql (ops
, &context
))
3211 struct thread_item
*item
;
3212 struct thread_info
*tp
, *tmp
;
3216 if (VEC_empty (thread_item_t
, context
.items
)
3217 && remote_thread_always_alive (ops
, inferior_ptid
))
3219 /* Some targets don't really support threads, but still
3220 reply an (empty) thread list in response to the thread
3221 listing packets, instead of replying "packet not
3222 supported". Exit early so we don't delete the main
3224 do_cleanups (old_chain
);
3228 /* CONTEXT now holds the current thread list on the remote
3229 target end. Delete GDB-side threads no longer found on the
3231 ALL_THREADS_SAFE (tp
, tmp
)
3234 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3237 if (ptid_equal (item
->ptid
, tp
->ptid
))
3241 if (i
== VEC_length (thread_item_t
, context
.items
))
3244 delete_thread (tp
->ptid
);
3248 /* Remove any unreported fork child threads from CONTEXT so
3249 that we don't interfere with follow fork, which is where
3250 creation of such threads is handled. */
3251 remove_new_fork_children (&context
);
3253 /* And now add threads we don't know about yet to our list. */
3255 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3258 if (!ptid_equal (item
->ptid
, null_ptid
))
3260 struct private_thread_info
*info
;
3261 /* In non-stop mode, we assume new found threads are
3262 running until proven otherwise with a stop reply. In
3263 all-stop, we can only get here if all threads are
3265 int running
= target_is_non_stop_p () ? 1 : 0;
3267 remote_notice_new_inferior (item
->ptid
, running
);
3269 info
= demand_private_info (item
->ptid
);
3270 info
->core
= item
->core
;
3271 info
->extra
= item
->extra
;
3273 info
->name
= item
->name
;
3281 /* If no thread listing method is supported, then query whether
3282 each known thread is alive, one by one, with the T packet.
3283 If the target doesn't support threads at all, then this is a
3284 no-op. See remote_thread_alive. */
3288 do_cleanups (old_chain
);
3292 * Collect a descriptive string about the given thread.
3293 * The target may say anything it wants to about the thread
3294 * (typically info about its blocked / runnable state, name, etc.).
3295 * This string will appear in the info threads display.
3297 * Optional: targets are not required to implement this function.
3301 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3303 struct remote_state
*rs
= get_remote_state ();
3307 struct gdb_ext_thread_info threadinfo
;
3308 static char display_buf
[100]; /* arbitrary... */
3309 int n
= 0; /* position in display_buf */
3311 if (rs
->remote_desc
== 0) /* paranoia */
3312 internal_error (__FILE__
, __LINE__
,
3313 _("remote_threads_extra_info"));
3315 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3316 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3317 /* This is the main thread which was added by GDB. The remote
3318 server doesn't know about it. */
3321 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3323 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3325 if (info
&& info
->priv
)
3326 return info
->priv
->extra
;
3331 if (rs
->use_threadextra_query
)
3334 char *endb
= rs
->buf
+ get_remote_packet_size ();
3336 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3338 write_ptid (b
, endb
, tp
->ptid
);
3341 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3342 if (rs
->buf
[0] != 0)
3344 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3345 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3346 display_buf
[result
] = '\0';
3351 /* If the above query fails, fall back to the old method. */
3352 rs
->use_threadextra_query
= 0;
3353 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3354 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3355 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3356 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3357 if (threadinfo
.active
)
3359 if (*threadinfo
.shortname
)
3360 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3361 " Name: %s,", threadinfo
.shortname
);
3362 if (*threadinfo
.display
)
3363 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3364 " State: %s,", threadinfo
.display
);
3365 if (*threadinfo
.more_display
)
3366 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3367 " Priority: %s", threadinfo
.more_display
);
3371 /* For purely cosmetic reasons, clear up trailing commas. */
3372 if (',' == display_buf
[n
-1])
3373 display_buf
[n
-1] = ' ';
3382 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3383 struct static_tracepoint_marker
*marker
)
3385 struct remote_state
*rs
= get_remote_state ();
3388 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3390 p
+= hexnumstr (p
, addr
);
3392 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3396 error (_("Remote failure reply: %s"), p
);
3400 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3407 static VEC(static_tracepoint_marker_p
) *
3408 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3411 struct remote_state
*rs
= get_remote_state ();
3412 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3413 struct static_tracepoint_marker
*marker
= NULL
;
3414 struct cleanup
*old_chain
;
3417 /* Ask for a first packet of static tracepoint marker
3420 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3423 error (_("Remote failure reply: %s"), p
);
3425 old_chain
= make_cleanup (free_current_marker
, &marker
);
3430 marker
= XCNEW (struct static_tracepoint_marker
);
3434 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3436 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3438 VEC_safe_push (static_tracepoint_marker_p
,
3444 release_static_tracepoint_marker (marker
);
3445 memset (marker
, 0, sizeof (*marker
));
3448 while (*p
++ == ','); /* comma-separated list */
3449 /* Ask for another packet of static tracepoint definition. */
3451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3455 do_cleanups (old_chain
);
3460 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3463 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3465 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3469 /* Restart the remote side; this is an extended protocol operation. */
3472 extended_remote_restart (void)
3474 struct remote_state
*rs
= get_remote_state ();
3476 /* Send the restart command; for reasons I don't understand the
3477 remote side really expects a number after the "R". */
3478 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3481 remote_fileio_reset ();
3484 /* Clean up connection to a remote debugger. */
3487 remote_close (struct target_ops
*self
)
3489 struct remote_state
*rs
= get_remote_state ();
3491 if (rs
->remote_desc
== NULL
)
3492 return; /* already closed */
3494 /* Make sure we leave stdin registered in the event loop, and we
3495 don't leave the async SIGINT signal handler installed. */
3496 remote_terminal_ours (self
);
3498 serial_close (rs
->remote_desc
);
3499 rs
->remote_desc
= NULL
;
3501 /* We don't have a connection to the remote stub anymore. Get rid
3502 of all the inferiors and their threads we were controlling.
3503 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3504 will be unable to find the thread corresponding to (pid, 0, 0). */
3505 inferior_ptid
= null_ptid
;
3506 discard_all_inferiors ();
3508 /* We are closing the remote target, so we should discard
3509 everything of this target. */
3510 discard_pending_stop_replies_in_queue (rs
);
3512 if (remote_async_inferior_event_token
)
3513 delete_async_event_handler (&remote_async_inferior_event_token
);
3515 remote_notif_state_xfree (rs
->notif_state
);
3517 trace_reset_local_state ();
3520 /* Query the remote side for the text, data and bss offsets. */
3525 struct remote_state
*rs
= get_remote_state ();
3528 int lose
, num_segments
= 0, do_sections
, do_segments
;
3529 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3530 struct section_offsets
*offs
;
3531 struct symfile_segment_data
*data
;
3533 if (symfile_objfile
== NULL
)
3536 putpkt ("qOffsets");
3537 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3540 if (buf
[0] == '\000')
3541 return; /* Return silently. Stub doesn't support
3545 warning (_("Remote failure reply: %s"), buf
);
3549 /* Pick up each field in turn. This used to be done with scanf, but
3550 scanf will make trouble if CORE_ADDR size doesn't match
3551 conversion directives correctly. The following code will work
3552 with any size of CORE_ADDR. */
3553 text_addr
= data_addr
= bss_addr
= 0;
3557 if (startswith (ptr
, "Text="))
3560 /* Don't use strtol, could lose on big values. */
3561 while (*ptr
&& *ptr
!= ';')
3562 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3564 if (startswith (ptr
, ";Data="))
3567 while (*ptr
&& *ptr
!= ';')
3568 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3573 if (!lose
&& startswith (ptr
, ";Bss="))
3576 while (*ptr
&& *ptr
!= ';')
3577 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3579 if (bss_addr
!= data_addr
)
3580 warning (_("Target reported unsupported offsets: %s"), buf
);
3585 else if (startswith (ptr
, "TextSeg="))
3588 /* Don't use strtol, could lose on big values. */
3589 while (*ptr
&& *ptr
!= ';')
3590 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3593 if (startswith (ptr
, ";DataSeg="))
3596 while (*ptr
&& *ptr
!= ';')
3597 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3605 error (_("Malformed response to offset query, %s"), buf
);
3606 else if (*ptr
!= '\0')
3607 warning (_("Target reported unsupported offsets: %s"), buf
);
3609 offs
= ((struct section_offsets
*)
3610 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3611 memcpy (offs
, symfile_objfile
->section_offsets
,
3612 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3614 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3615 do_segments
= (data
!= NULL
);
3616 do_sections
= num_segments
== 0;
3618 if (num_segments
> 0)
3620 segments
[0] = text_addr
;
3621 segments
[1] = data_addr
;
3623 /* If we have two segments, we can still try to relocate everything
3624 by assuming that the .text and .data offsets apply to the whole
3625 text and data segments. Convert the offsets given in the packet
3626 to base addresses for symfile_map_offsets_to_segments. */
3627 else if (data
&& data
->num_segments
== 2)
3629 segments
[0] = data
->segment_bases
[0] + text_addr
;
3630 segments
[1] = data
->segment_bases
[1] + data_addr
;
3633 /* If the object file has only one segment, assume that it is text
3634 rather than data; main programs with no writable data are rare,
3635 but programs with no code are useless. Of course the code might
3636 have ended up in the data segment... to detect that we would need
3637 the permissions here. */
3638 else if (data
&& data
->num_segments
== 1)
3640 segments
[0] = data
->segment_bases
[0] + text_addr
;
3643 /* There's no way to relocate by segment. */
3649 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3650 offs
, num_segments
, segments
);
3652 if (ret
== 0 && !do_sections
)
3653 error (_("Can not handle qOffsets TextSeg "
3654 "response with this symbol file"));
3661 free_symfile_segment_data (data
);
3665 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3667 /* This is a temporary kludge to force data and bss to use the
3668 same offsets because that's what nlmconv does now. The real
3669 solution requires changes to the stub and remote.c that I
3670 don't have time to do right now. */
3672 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3673 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3676 objfile_relocate (symfile_objfile
, offs
);
3679 /* Send interrupt_sequence to remote target. */
3681 send_interrupt_sequence (void)
3683 struct remote_state
*rs
= get_remote_state ();
3685 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3686 remote_serial_write ("\x03", 1);
3687 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3688 serial_send_break (rs
->remote_desc
);
3689 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3691 serial_send_break (rs
->remote_desc
);
3692 remote_serial_write ("g", 1);
3695 internal_error (__FILE__
, __LINE__
,
3696 _("Invalid value for interrupt_sequence_mode: %s."),
3697 interrupt_sequence_mode
);
3701 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3702 and extract the PTID. Returns NULL_PTID if not found. */
3705 stop_reply_extract_thread (char *stop_reply
)
3707 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3711 /* Txx r:val ; r:val (...) */
3714 /* Look for "register" named "thread". */
3719 p1
= strchr (p
, ':');
3723 if (strncmp (p
, "thread", p1
- p
) == 0)
3724 return read_ptid (++p1
, &p
);
3726 p1
= strchr (p
, ';');
3738 /* Determine the remote side's current thread. If we have a stop
3739 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3740 "thread" register we can extract the current thread from. If not,
3741 ask the remote which is the current thread with qC. The former
3742 method avoids a roundtrip. */
3745 get_current_thread (char *wait_status
)
3747 ptid_t ptid
= null_ptid
;
3749 /* Note we don't use remote_parse_stop_reply as that makes use of
3750 the target architecture, which we haven't yet fully determined at
3752 if (wait_status
!= NULL
)
3753 ptid
= stop_reply_extract_thread (wait_status
);
3754 if (ptid_equal (ptid
, null_ptid
))
3755 ptid
= remote_current_thread (inferior_ptid
);
3760 /* Query the remote target for which is the current thread/process,
3761 add it to our tables, and update INFERIOR_PTID. The caller is
3762 responsible for setting the state such that the remote end is ready
3763 to return the current thread.
3765 This function is called after handling the '?' or 'vRun' packets,
3766 whose response is a stop reply from which we can also try
3767 extracting the thread. If the target doesn't support the explicit
3768 qC query, we infer the current thread from that stop reply, passed
3769 in in WAIT_STATUS, which may be NULL. */
3772 add_current_inferior_and_thread (char *wait_status
)
3774 struct remote_state
*rs
= get_remote_state ();
3778 inferior_ptid
= null_ptid
;
3780 /* Now, if we have thread information, update inferior_ptid. */
3781 ptid
= get_current_thread (wait_status
);
3783 if (!ptid_equal (ptid
, null_ptid
))
3785 if (!remote_multi_process_p (rs
))
3788 inferior_ptid
= ptid
;
3792 /* Without this, some commands which require an active target
3793 (such as kill) won't work. This variable serves (at least)
3794 double duty as both the pid of the target process (if it has
3795 such), and as a flag indicating that a target is active. */
3796 inferior_ptid
= magic_null_ptid
;
3800 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3802 /* Add the main thread. */
3803 add_thread_silent (inferior_ptid
);
3806 /* Print info about a thread that was found already stopped on
3810 print_one_stopped_thread (struct thread_info
*thread
)
3812 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3814 switch_to_thread (thread
->ptid
);
3815 stop_pc
= get_frame_pc (get_current_frame ());
3816 set_current_sal_from_frame (get_current_frame ());
3818 thread
->suspend
.waitstatus_pending_p
= 0;
3820 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3822 enum gdb_signal sig
= ws
->value
.sig
;
3824 if (signal_print_state (sig
))
3825 observer_notify_signal_received (sig
);
3827 observer_notify_normal_stop (NULL
, 1);
3830 /* Process all initial stop replies the remote side sent in response
3831 to the ? packet. These indicate threads that were already stopped
3832 on initial connection. We mark these threads as stopped and print
3833 their current frame before giving the user the prompt. */
3836 process_initial_stop_replies (int from_tty
)
3838 int pending_stop_replies
= stop_reply_queue_length ();
3839 struct inferior
*inf
;
3840 struct thread_info
*thread
;
3841 struct thread_info
*selected
= NULL
;
3842 struct thread_info
*lowest_stopped
= NULL
;
3843 struct thread_info
*first
= NULL
;
3845 /* Consume the initial pending events. */
3846 while (pending_stop_replies
-- > 0)
3848 ptid_t waiton_ptid
= minus_one_ptid
;
3850 struct target_waitstatus ws
;
3851 int ignore_event
= 0;
3852 struct thread_info
*thread
;
3854 memset (&ws
, 0, sizeof (ws
));
3855 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3857 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3861 case TARGET_WAITKIND_IGNORE
:
3862 case TARGET_WAITKIND_NO_RESUMED
:
3863 case TARGET_WAITKIND_SIGNALLED
:
3864 case TARGET_WAITKIND_EXITED
:
3865 /* We shouldn't see these, but if we do, just ignore. */
3867 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3871 case TARGET_WAITKIND_EXECD
:
3872 xfree (ws
.value
.execd_pathname
);
3881 thread
= find_thread_ptid (event_ptid
);
3883 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3885 enum gdb_signal sig
= ws
.value
.sig
;
3887 /* Stubs traditionally report SIGTRAP as initial signal,
3888 instead of signal 0. Suppress it. */
3889 if (sig
== GDB_SIGNAL_TRAP
)
3891 thread
->suspend
.stop_signal
= sig
;
3895 thread
->suspend
.waitstatus
= ws
;
3897 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3898 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3899 thread
->suspend
.waitstatus_pending_p
= 1;
3901 set_executing (event_ptid
, 0);
3902 set_running (event_ptid
, 0);
3905 /* "Notice" the new inferiors before anything related to
3906 registers/memory. */
3912 inf
->needs_setup
= 1;
3916 thread
= any_live_thread_of_process (inf
->pid
);
3917 notice_new_inferior (thread
->ptid
,
3918 thread
->state
== THREAD_RUNNING
,
3923 /* If all-stop on top of non-stop, pause all threads. Note this
3924 records the threads' stop pc, so must be done after "noticing"
3928 stop_all_threads ();
3930 /* If all threads of an inferior were already stopped, we
3931 haven't setup the inferior yet. */
3937 if (inf
->needs_setup
)
3939 thread
= any_live_thread_of_process (inf
->pid
);
3940 switch_to_thread_no_regs (thread
);
3946 /* Now go over all threads that are stopped, and print their current
3947 frame. If all-stop, then if there's a signalled thread, pick
3949 ALL_NON_EXITED_THREADS (thread
)
3955 set_running (thread
->ptid
, 0);
3956 else if (thread
->state
!= THREAD_STOPPED
)
3959 if (selected
== NULL
3960 && thread
->suspend
.waitstatus_pending_p
)
3963 if (lowest_stopped
== NULL
3964 || thread
->inf
->num
< lowest_stopped
->inf
->num
3965 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
3966 lowest_stopped
= thread
;
3969 print_one_stopped_thread (thread
);
3972 /* In all-stop, we only print the status of one thread, and leave
3973 others with their status pending. */
3978 thread
= lowest_stopped
;
3982 print_one_stopped_thread (thread
);
3985 /* For "info program". */
3986 thread
= inferior_thread ();
3987 if (thread
->state
== THREAD_STOPPED
)
3988 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
3992 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3994 struct remote_state
*rs
= get_remote_state ();
3995 struct packet_config
*noack_config
;
3996 char *wait_status
= NULL
;
3998 immediate_quit
++; /* Allow user to interrupt it. */
4001 if (interrupt_on_connect
)
4002 send_interrupt_sequence ();
4004 /* Ack any packet which the remote side has already sent. */
4005 serial_write (rs
->remote_desc
, "+", 1);
4007 /* Signal other parts that we're going through the initial setup,
4008 and so things may not be stable yet. */
4009 rs
->starting_up
= 1;
4011 /* The first packet we send to the target is the optional "supported
4012 packets" request. If the target can answer this, it will tell us
4013 which later probes to skip. */
4014 remote_query_supported ();
4016 /* If the stub wants to get a QAllow, compose one and send it. */
4017 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4018 remote_set_permissions (target
);
4020 /* Next, we possibly activate noack mode.
4022 If the QStartNoAckMode packet configuration is set to AUTO,
4023 enable noack mode if the stub reported a wish for it with
4026 If set to TRUE, then enable noack mode even if the stub didn't
4027 report it in qSupported. If the stub doesn't reply OK, the
4028 session ends with an error.
4030 If FALSE, then don't activate noack mode, regardless of what the
4031 stub claimed should be the default with qSupported. */
4033 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4034 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4036 putpkt ("QStartNoAckMode");
4037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4038 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4044 /* Tell the remote that we are using the extended protocol. */
4046 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4049 /* Let the target know which signals it is allowed to pass down to
4051 update_signals_program_target ();
4053 /* Next, if the target can specify a description, read it. We do
4054 this before anything involving memory or registers. */
4055 target_find_description ();
4057 /* Next, now that we know something about the target, update the
4058 address spaces in the program spaces. */
4059 update_address_spaces ();
4061 /* On OSs where the list of libraries is global to all
4062 processes, we fetch them early. */
4063 if (gdbarch_has_global_solist (target_gdbarch ()))
4064 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4066 if (target_is_non_stop_p ())
4068 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4069 error (_("Non-stop mode requested, but remote "
4070 "does not support non-stop"));
4072 putpkt ("QNonStop:1");
4073 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4075 if (strcmp (rs
->buf
, "OK") != 0)
4076 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4078 /* Find about threads and processes the stub is already
4079 controlling. We default to adding them in the running state.
4080 The '?' query below will then tell us about which threads are
4082 remote_update_thread_list (target
);
4084 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4086 /* Don't assume that the stub can operate in all-stop mode.
4087 Request it explicitly. */
4088 putpkt ("QNonStop:0");
4089 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4091 if (strcmp (rs
->buf
, "OK") != 0)
4092 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4095 /* Upload TSVs regardless of whether the target is running or not. The
4096 remote stub, such as GDBserver, may have some predefined or builtin
4097 TSVs, even if the target is not running. */
4098 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4100 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4102 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4103 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4106 /* Check whether the target is running now. */
4108 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4110 if (!target_is_non_stop_p ())
4112 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4115 error (_("The target is not running (try extended-remote?)"));
4117 /* We're connected, but not running. Drop out before we
4118 call start_remote. */
4119 rs
->starting_up
= 0;
4124 /* Save the reply for later. */
4125 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4126 strcpy (wait_status
, rs
->buf
);
4129 /* Fetch thread list. */
4130 target_update_thread_list ();
4132 /* Let the stub know that we want it to return the thread. */
4133 set_continue_thread (minus_one_ptid
);
4135 if (thread_count () == 0)
4137 /* Target has no concept of threads at all. GDB treats
4138 non-threaded target as single-threaded; add a main
4140 add_current_inferior_and_thread (wait_status
);
4144 /* We have thread information; select the thread the target
4145 says should be current. If we're reconnecting to a
4146 multi-threaded program, this will ideally be the thread
4147 that last reported an event before GDB disconnected. */
4148 inferior_ptid
= get_current_thread (wait_status
);
4149 if (ptid_equal (inferior_ptid
, null_ptid
))
4151 /* Odd... The target was able to list threads, but not
4152 tell us which thread was current (no "thread"
4153 register in T stop reply?). Just pick the first
4154 thread in the thread list then. */
4157 fprintf_unfiltered (gdb_stdlog
,
4158 "warning: couldn't determine remote "
4159 "current thread; picking first in list.\n");
4161 inferior_ptid
= thread_list
->ptid
;
4165 /* init_wait_for_inferior should be called before get_offsets in order
4166 to manage `inserted' flag in bp loc in a correct state.
4167 breakpoint_init_inferior, called from init_wait_for_inferior, set
4168 `inserted' flag to 0, while before breakpoint_re_set, called from
4169 start_remote, set `inserted' flag to 1. In the initialization of
4170 inferior, breakpoint_init_inferior should be called first, and then
4171 breakpoint_re_set can be called. If this order is broken, state of
4172 `inserted' flag is wrong, and cause some problems on breakpoint
4174 init_wait_for_inferior ();
4176 get_offsets (); /* Get text, data & bss offsets. */
4178 /* If we could not find a description using qXfer, and we know
4179 how to do it some other way, try again. This is not
4180 supported for non-stop; it could be, but it is tricky if
4181 there are no stopped threads when we connect. */
4182 if (remote_read_description_p (target
)
4183 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4185 target_clear_description ();
4186 target_find_description ();
4189 /* Use the previously fetched status. */
4190 gdb_assert (wait_status
!= NULL
);
4191 strcpy (rs
->buf
, wait_status
);
4192 rs
->cached_wait_status
= 1;
4195 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4199 /* Clear WFI global state. Do this before finding about new
4200 threads and inferiors, and setting the current inferior.
4201 Otherwise we would clear the proceed status of the current
4202 inferior when we want its stop_soon state to be preserved
4203 (see notice_new_inferior). */
4204 init_wait_for_inferior ();
4206 /* In non-stop, we will either get an "OK", meaning that there
4207 are no stopped threads at this time; or, a regular stop
4208 reply. In the latter case, there may be more than one thread
4209 stopped --- we pull them all out using the vStopped
4211 if (strcmp (rs
->buf
, "OK") != 0)
4213 struct notif_client
*notif
= ¬if_client_stop
;
4215 /* remote_notif_get_pending_replies acks this one, and gets
4217 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4218 = remote_notif_parse (notif
, rs
->buf
);
4219 remote_notif_get_pending_events (notif
);
4222 if (thread_count () == 0)
4225 error (_("The target is not running (try extended-remote?)"));
4227 /* We're connected, but not running. Drop out before we
4228 call start_remote. */
4229 rs
->starting_up
= 0;
4233 /* In non-stop mode, any cached wait status will be stored in
4234 the stop reply queue. */
4235 gdb_assert (wait_status
== NULL
);
4237 /* Report all signals during attach/startup. */
4238 remote_pass_signals (target
, 0, NULL
);
4240 /* If there are already stopped threads, mark them stopped and
4241 report their stops before giving the prompt to the user. */
4242 process_initial_stop_replies (from_tty
);
4244 if (target_can_async_p ())
4248 /* If we connected to a live target, do some additional setup. */
4249 if (target_has_execution
)
4251 if (symfile_objfile
) /* No use without a symbol-file. */
4252 remote_check_symbols ();
4255 /* Possibly the target has been engaged in a trace run started
4256 previously; find out where things are at. */
4257 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4259 struct uploaded_tp
*uploaded_tps
= NULL
;
4261 if (current_trace_status ()->running
)
4262 printf_filtered (_("Trace is already running on the target.\n"));
4264 remote_upload_tracepoints (target
, &uploaded_tps
);
4266 merge_uploaded_tracepoints (&uploaded_tps
);
4269 /* The thread and inferior lists are now synchronized with the
4270 target, our symbols have been relocated, and we're merged the
4271 target's tracepoints with ours. We're done with basic start
4273 rs
->starting_up
= 0;
4275 /* Maybe breakpoints are global and need to be inserted now. */
4276 if (breakpoints_should_be_inserted_now ())
4277 insert_breakpoints ();
4280 /* Open a connection to a remote debugger.
4281 NAME is the filename used for communication. */
4284 remote_open (const char *name
, int from_tty
)
4286 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4289 /* Open a connection to a remote debugger using the extended
4290 remote gdb protocol. NAME is the filename used for communication. */
4293 extended_remote_open (const char *name
, int from_tty
)
4295 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4298 /* Reset all packets back to "unknown support". Called when opening a
4299 new connection to a remote target. */
4302 reset_all_packet_configs_support (void)
4306 for (i
= 0; i
< PACKET_MAX
; i
++)
4307 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4310 /* Initialize all packet configs. */
4313 init_all_packet_configs (void)
4317 for (i
= 0; i
< PACKET_MAX
; i
++)
4319 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4320 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4324 /* Symbol look-up. */
4327 remote_check_symbols (void)
4329 struct remote_state
*rs
= get_remote_state ();
4330 char *msg
, *reply
, *tmp
;
4332 struct cleanup
*old_chain
;
4334 /* The remote side has no concept of inferiors that aren't running
4335 yet, it only knows about running processes. If we're connected
4336 but our current inferior is not running, we should not invite the
4337 remote target to request symbol lookups related to its
4338 (unrelated) current process. */
4339 if (!target_has_execution
)
4342 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4345 /* Make sure the remote is pointing at the right process. Note
4346 there's no way to select "no process". */
4347 set_general_process ();
4349 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4350 because we need both at the same time. */
4351 msg
= (char *) xmalloc (get_remote_packet_size ());
4352 old_chain
= make_cleanup (xfree
, msg
);
4354 /* Invite target to request symbol lookups. */
4356 putpkt ("qSymbol::");
4357 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4358 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
4361 while (startswith (reply
, "qSymbol:"))
4363 struct bound_minimal_symbol sym
;
4366 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4368 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4369 if (sym
.minsym
== NULL
)
4370 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4373 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4374 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4376 /* If this is a function address, return the start of code
4377 instead of any data function descriptor. */
4378 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4382 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4383 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4387 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4391 do_cleanups (old_chain
);
4394 static struct serial
*
4395 remote_serial_open (const char *name
)
4397 static int udp_warning
= 0;
4399 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4400 of in ser-tcp.c, because it is the remote protocol assuming that the
4401 serial connection is reliable and not the serial connection promising
4403 if (!udp_warning
&& startswith (name
, "udp:"))
4405 warning (_("The remote protocol may be unreliable over UDP.\n"
4406 "Some events may be lost, rendering further debugging "
4411 return serial_open (name
);
4414 /* Inform the target of our permission settings. The permission flags
4415 work without this, but if the target knows the settings, it can do
4416 a couple things. First, it can add its own check, to catch cases
4417 that somehow manage to get by the permissions checks in target
4418 methods. Second, if the target is wired to disallow particular
4419 settings (for instance, a system in the field that is not set up to
4420 be able to stop at a breakpoint), it can object to any unavailable
4424 remote_set_permissions (struct target_ops
*self
)
4426 struct remote_state
*rs
= get_remote_state ();
4428 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4429 "WriteReg:%x;WriteMem:%x;"
4430 "InsertBreak:%x;InsertTrace:%x;"
4431 "InsertFastTrace:%x;Stop:%x",
4432 may_write_registers
, may_write_memory
,
4433 may_insert_breakpoints
, may_insert_tracepoints
,
4434 may_insert_fast_tracepoints
, may_stop
);
4436 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4438 /* If the target didn't like the packet, warn the user. Do not try
4439 to undo the user's settings, that would just be maddening. */
4440 if (strcmp (rs
->buf
, "OK") != 0)
4441 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4444 /* This type describes each known response to the qSupported
4446 struct protocol_feature
4448 /* The name of this protocol feature. */
4451 /* The default for this protocol feature. */
4452 enum packet_support default_support
;
4454 /* The function to call when this feature is reported, or after
4455 qSupported processing if the feature is not supported.
4456 The first argument points to this structure. The second
4457 argument indicates whether the packet requested support be
4458 enabled, disabled, or probed (or the default, if this function
4459 is being called at the end of processing and this feature was
4460 not reported). The third argument may be NULL; if not NULL, it
4461 is a NUL-terminated string taken from the packet following
4462 this feature's name and an equals sign. */
4463 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4466 /* The corresponding packet for this feature. Only used if
4467 FUNC is remote_supported_packet. */
4472 remote_supported_packet (const struct protocol_feature
*feature
,
4473 enum packet_support support
,
4474 const char *argument
)
4478 warning (_("Remote qSupported response supplied an unexpected value for"
4479 " \"%s\"."), feature
->name
);
4483 remote_protocol_packets
[feature
->packet
].support
= support
;
4487 remote_packet_size (const struct protocol_feature
*feature
,
4488 enum packet_support support
, const char *value
)
4490 struct remote_state
*rs
= get_remote_state ();
4495 if (support
!= PACKET_ENABLE
)
4498 if (value
== NULL
|| *value
== '\0')
4500 warning (_("Remote target reported \"%s\" without a size."),
4506 packet_size
= strtol (value
, &value_end
, 16);
4507 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4509 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4510 feature
->name
, value
);
4514 /* Record the new maximum packet size. */
4515 rs
->explicit_packet_size
= packet_size
;
4518 static const struct protocol_feature remote_protocol_features
[] = {
4519 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4520 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4521 PACKET_qXfer_auxv
},
4522 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4523 PACKET_qXfer_exec_file
},
4524 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4525 PACKET_qXfer_features
},
4526 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4527 PACKET_qXfer_libraries
},
4528 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4529 PACKET_qXfer_libraries_svr4
},
4530 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4531 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4532 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4533 PACKET_qXfer_memory_map
},
4534 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4535 PACKET_qXfer_spu_read
},
4536 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4537 PACKET_qXfer_spu_write
},
4538 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4539 PACKET_qXfer_osdata
},
4540 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4541 PACKET_qXfer_threads
},
4542 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4543 PACKET_qXfer_traceframe_info
},
4544 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4545 PACKET_QPassSignals
},
4546 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4547 PACKET_QCatchSyscalls
},
4548 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4549 PACKET_QProgramSignals
},
4550 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4551 PACKET_QStartNoAckMode
},
4552 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4553 PACKET_multiprocess_feature
},
4554 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4555 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4556 PACKET_qXfer_siginfo_read
},
4557 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4558 PACKET_qXfer_siginfo_write
},
4559 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4560 PACKET_ConditionalTracepoints
},
4561 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4562 PACKET_ConditionalBreakpoints
},
4563 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4564 PACKET_BreakpointCommands
},
4565 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4566 PACKET_FastTracepoints
},
4567 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4568 PACKET_StaticTracepoints
},
4569 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4570 PACKET_InstallInTrace
},
4571 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4572 PACKET_DisconnectedTracing_feature
},
4573 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4575 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4577 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4578 PACKET_TracepointSource
},
4579 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4581 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4582 PACKET_EnableDisableTracepoints_feature
},
4583 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4584 PACKET_qXfer_fdpic
},
4585 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4587 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4588 PACKET_QDisableRandomization
},
4589 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4590 { "QTBuffer:size", PACKET_DISABLE
,
4591 remote_supported_packet
, PACKET_QTBuffer_size
},
4592 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4593 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4594 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4595 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4596 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4597 PACKET_qXfer_btrace
},
4598 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4599 PACKET_qXfer_btrace_conf
},
4600 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4601 PACKET_Qbtrace_conf_bts_size
},
4602 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4603 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4604 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4605 PACKET_fork_event_feature
},
4606 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4607 PACKET_vfork_event_feature
},
4608 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4609 PACKET_exec_event_feature
},
4610 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4611 PACKET_Qbtrace_conf_pt_size
},
4612 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4613 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4614 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4617 static char *remote_support_xml
;
4619 /* Register string appended to "xmlRegisters=" in qSupported query. */
4622 register_remote_support_xml (const char *xml
)
4624 #if defined(HAVE_LIBEXPAT)
4625 if (remote_support_xml
== NULL
)
4626 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4629 char *copy
= xstrdup (remote_support_xml
+ 13);
4630 char *p
= strtok (copy
, ",");
4634 if (strcmp (p
, xml
) == 0)
4641 while ((p
= strtok (NULL
, ",")) != NULL
);
4644 remote_support_xml
= reconcat (remote_support_xml
,
4645 remote_support_xml
, ",", xml
,
4652 remote_query_supported_append (char *msg
, const char *append
)
4655 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4657 return xstrdup (append
);
4661 remote_query_supported (void)
4663 struct remote_state
*rs
= get_remote_state ();
4666 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4668 /* The packet support flags are handled differently for this packet
4669 than for most others. We treat an error, a disabled packet, and
4670 an empty response identically: any features which must be reported
4671 to be used will be automatically disabled. An empty buffer
4672 accomplishes this, since that is also the representation for a list
4673 containing no features. */
4676 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4679 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4681 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4682 q
= remote_query_supported_append (q
, "multiprocess+");
4684 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4685 q
= remote_query_supported_append (q
, "swbreak+");
4686 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4687 q
= remote_query_supported_append (q
, "hwbreak+");
4689 q
= remote_query_supported_append (q
, "qRelocInsn+");
4691 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4692 != AUTO_BOOLEAN_FALSE
)
4693 q
= remote_query_supported_append (q
, "fork-events+");
4694 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4695 != AUTO_BOOLEAN_FALSE
)
4696 q
= remote_query_supported_append (q
, "vfork-events+");
4697 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4698 != AUTO_BOOLEAN_FALSE
)
4699 q
= remote_query_supported_append (q
, "exec-events+");
4701 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4702 q
= remote_query_supported_append (q
, "vContSupported+");
4704 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4705 q
= remote_query_supported_append (q
, "QThreadEvents+");
4707 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4708 q
= remote_query_supported_append (q
, "no-resumed+");
4710 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4711 the qSupported:xmlRegisters=i386 handling. */
4712 if (remote_support_xml
!= NULL
)
4713 q
= remote_query_supported_append (q
, remote_support_xml
);
4715 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4718 do_cleanups (old_chain
);
4720 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4722 /* If an error occured, warn, but do not return - just reset the
4723 buffer to empty and go on to disable features. */
4724 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4727 warning (_("Remote failure reply: %s"), rs
->buf
);
4732 memset (seen
, 0, sizeof (seen
));
4737 enum packet_support is_supported
;
4738 char *p
, *end
, *name_end
, *value
;
4740 /* First separate out this item from the rest of the packet. If
4741 there's another item after this, we overwrite the separator
4742 (terminated strings are much easier to work with). */
4744 end
= strchr (p
, ';');
4747 end
= p
+ strlen (p
);
4757 warning (_("empty item in \"qSupported\" response"));
4762 name_end
= strchr (p
, '=');
4765 /* This is a name=value entry. */
4766 is_supported
= PACKET_ENABLE
;
4767 value
= name_end
+ 1;
4776 is_supported
= PACKET_ENABLE
;
4780 is_supported
= PACKET_DISABLE
;
4784 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4788 warning (_("unrecognized item \"%s\" "
4789 "in \"qSupported\" response"), p
);
4795 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4796 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4798 const struct protocol_feature
*feature
;
4801 feature
= &remote_protocol_features
[i
];
4802 feature
->func (feature
, is_supported
, value
);
4807 /* If we increased the packet size, make sure to increase the global
4808 buffer size also. We delay this until after parsing the entire
4809 qSupported packet, because this is the same buffer we were
4811 if (rs
->buf_size
< rs
->explicit_packet_size
)
4813 rs
->buf_size
= rs
->explicit_packet_size
;
4814 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4817 /* Handle the defaults for unmentioned features. */
4818 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4821 const struct protocol_feature
*feature
;
4823 feature
= &remote_protocol_features
[i
];
4824 feature
->func (feature
, feature
->default_support
, NULL
);
4828 /* Remove any of the remote.c targets from target stack. Upper targets depend
4829 on it so remove them first. */
4832 remote_unpush_target (void)
4834 pop_all_targets_at_and_above (process_stratum
);
4838 remote_open_1 (const char *name
, int from_tty
,
4839 struct target_ops
*target
, int extended_p
)
4841 struct remote_state
*rs
= get_remote_state ();
4844 error (_("To open a remote debug connection, you need to specify what\n"
4845 "serial device is attached to the remote system\n"
4846 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4848 /* See FIXME above. */
4849 if (!target_async_permitted
)
4850 wait_forever_enabled_p
= 1;
4852 /* If we're connected to a running target, target_preopen will kill it.
4853 Ask this question first, before target_preopen has a chance to kill
4855 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4858 && !query (_("Already connected to a remote target. Disconnect? ")))
4859 error (_("Still connected."));
4862 /* Here the possibly existing remote target gets unpushed. */
4863 target_preopen (from_tty
);
4865 /* Make sure we send the passed signals list the next time we resume. */
4866 xfree (rs
->last_pass_packet
);
4867 rs
->last_pass_packet
= NULL
;
4869 /* Make sure we send the program signals list the next time we
4871 xfree (rs
->last_program_signals_packet
);
4872 rs
->last_program_signals_packet
= NULL
;
4874 remote_fileio_reset ();
4875 reopen_exec_file ();
4878 rs
->remote_desc
= remote_serial_open (name
);
4879 if (!rs
->remote_desc
)
4880 perror_with_name (name
);
4882 if (baud_rate
!= -1)
4884 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4886 /* The requested speed could not be set. Error out to
4887 top level after closing remote_desc. Take care to
4888 set remote_desc to NULL to avoid closing remote_desc
4890 serial_close (rs
->remote_desc
);
4891 rs
->remote_desc
= NULL
;
4892 perror_with_name (name
);
4896 serial_setparity (rs
->remote_desc
, serial_parity
);
4897 serial_raw (rs
->remote_desc
);
4899 /* If there is something sitting in the buffer we might take it as a
4900 response to a command, which would be bad. */
4901 serial_flush_input (rs
->remote_desc
);
4905 puts_filtered ("Remote debugging using ");
4906 puts_filtered (name
);
4907 puts_filtered ("\n");
4909 push_target (target
); /* Switch to using remote target now. */
4911 /* Register extra event sources in the event loop. */
4912 remote_async_inferior_event_token
4913 = create_async_event_handler (remote_async_inferior_event_handler
,
4915 rs
->notif_state
= remote_notif_state_allocate ();
4917 /* Reset the target state; these things will be queried either by
4918 remote_query_supported or as they are needed. */
4919 reset_all_packet_configs_support ();
4920 rs
->cached_wait_status
= 0;
4921 rs
->explicit_packet_size
= 0;
4923 rs
->extended
= extended_p
;
4924 rs
->waiting_for_stop_reply
= 0;
4925 rs
->ctrlc_pending_p
= 0;
4927 rs
->general_thread
= not_sent_ptid
;
4928 rs
->continue_thread
= not_sent_ptid
;
4929 rs
->remote_traceframe_number
= -1;
4931 /* Probe for ability to use "ThreadInfo" query, as required. */
4932 rs
->use_threadinfo_query
= 1;
4933 rs
->use_threadextra_query
= 1;
4935 readahead_cache_invalidate ();
4937 if (target_async_permitted
)
4939 /* With this target we start out by owning the terminal. */
4940 remote_async_terminal_ours_p
= 1;
4942 /* FIXME: cagney/1999-09-23: During the initial connection it is
4943 assumed that the target is already ready and able to respond to
4944 requests. Unfortunately remote_start_remote() eventually calls
4945 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4946 around this. Eventually a mechanism that allows
4947 wait_for_inferior() to expect/get timeouts will be
4949 wait_forever_enabled_p
= 0;
4952 /* First delete any symbols previously loaded from shared libraries. */
4953 no_shared_libraries (NULL
, 0);
4956 init_thread_list ();
4958 /* Start the remote connection. If error() or QUIT, discard this
4959 target (we'd otherwise be in an inconsistent state) and then
4960 propogate the error on up the exception chain. This ensures that
4961 the caller doesn't stumble along blindly assuming that the
4962 function succeeded. The CLI doesn't have this problem but other
4963 UI's, such as MI do.
4965 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4966 this function should return an error indication letting the
4967 caller restore the previous state. Unfortunately the command
4968 ``target remote'' is directly wired to this function making that
4969 impossible. On a positive note, the CLI side of this problem has
4970 been fixed - the function set_cmd_context() makes it possible for
4971 all the ``target ....'' commands to share a common callback
4972 function. See cli-dump.c. */
4977 remote_start_remote (from_tty
, target
, extended_p
);
4979 CATCH (ex
, RETURN_MASK_ALL
)
4981 /* Pop the partially set up target - unless something else did
4982 already before throwing the exception. */
4983 if (rs
->remote_desc
!= NULL
)
4984 remote_unpush_target ();
4985 if (target_async_permitted
)
4986 wait_forever_enabled_p
= 1;
4987 throw_exception (ex
);
4992 remote_btrace_reset ();
4994 if (target_async_permitted
)
4995 wait_forever_enabled_p
= 1;
4998 /* Detach the specified process. */
5001 remote_detach_pid (int pid
)
5003 struct remote_state
*rs
= get_remote_state ();
5005 if (remote_multi_process_p (rs
))
5006 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5008 strcpy (rs
->buf
, "D");
5011 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5013 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5015 else if (rs
->buf
[0] == '\0')
5016 error (_("Remote doesn't know how to detach"));
5018 error (_("Can't detach process."));
5021 /* This detaches a program to which we previously attached, using
5022 inferior_ptid to identify the process. After this is done, GDB
5023 can be used to debug some other program. We better not have left
5024 any breakpoints in the target program or it'll die when it hits
5028 remote_detach_1 (const char *args
, int from_tty
)
5030 int pid
= ptid_get_pid (inferior_ptid
);
5031 struct remote_state
*rs
= get_remote_state ();
5032 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5036 error (_("Argument given to \"detach\" when remotely debugging."));
5038 if (!target_has_execution
)
5039 error (_("No process to detach from."));
5043 char *exec_file
= get_exec_file (0);
5044 if (exec_file
== NULL
)
5046 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
5047 target_pid_to_str (pid_to_ptid (pid
)));
5048 gdb_flush (gdb_stdout
);
5051 /* Tell the remote target to detach. */
5052 remote_detach_pid (pid
);
5054 /* Exit only if this is the only active inferior. */
5055 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5056 puts_filtered (_("Ending remote debugging.\n"));
5058 /* Check to see if we are detaching a fork parent. Note that if we
5059 are detaching a fork child, tp == NULL. */
5060 is_fork_parent
= (tp
!= NULL
5061 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5063 /* If doing detach-on-fork, we don't mourn, because that will delete
5064 breakpoints that should be available for the followed inferior. */
5065 if (!is_fork_parent
)
5066 target_mourn_inferior ();
5069 inferior_ptid
= null_ptid
;
5070 detach_inferior (pid
);
5075 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5077 remote_detach_1 (args
, from_tty
);
5081 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5083 remote_detach_1 (args
, from_tty
);
5086 /* Target follow-fork function for remote targets. On entry, and
5087 at return, the current inferior is the fork parent.
5089 Note that although this is currently only used for extended-remote,
5090 it is named remote_follow_fork in anticipation of using it for the
5091 remote target as well. */
5094 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5097 struct remote_state
*rs
= get_remote_state ();
5098 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5100 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5101 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5103 /* When following the parent and detaching the child, we detach
5104 the child here. For the case of following the child and
5105 detaching the parent, the detach is done in the target-
5106 independent follow fork code in infrun.c. We can't use
5107 target_detach when detaching an unfollowed child because
5108 the client side doesn't know anything about the child. */
5109 if (detach_fork
&& !follow_child
)
5111 /* Detach the fork child. */
5115 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5116 child_pid
= ptid_get_pid (child_ptid
);
5118 remote_detach_pid (child_pid
);
5119 detach_inferior (child_pid
);
5125 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5126 in the program space of the new inferior. On entry and at return the
5127 current inferior is the exec'ing inferior. INF is the new exec'd
5128 inferior, which may be the same as the exec'ing inferior unless
5129 follow-exec-mode is "new". */
5132 remote_follow_exec (struct target_ops
*ops
,
5133 struct inferior
*inf
, char *execd_pathname
)
5135 /* We know that this is a target file name, so if it has the "target:"
5136 prefix we strip it off before saving it in the program space. */
5137 if (is_target_filename (execd_pathname
))
5138 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5140 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5143 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5146 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5149 error (_("Argument given to \"disconnect\" when remotely debugging."));
5151 /* Make sure we unpush even the extended remote targets. Calling
5152 target_mourn_inferior won't unpush, and remote_mourn won't
5153 unpush if there is more than one inferior left. */
5154 unpush_target (target
);
5155 generic_mourn_inferior ();
5158 puts_filtered ("Ending remote debugging.\n");
5161 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5162 be chatty about it. */
5165 extended_remote_attach (struct target_ops
*target
, const char *args
,
5168 struct remote_state
*rs
= get_remote_state ();
5170 char *wait_status
= NULL
;
5172 pid
= parse_pid_to_attach (args
);
5174 /* Remote PID can be freely equal to getpid, do not check it here the same
5175 way as in other targets. */
5177 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5178 error (_("This target does not support attaching to a process"));
5182 char *exec_file
= get_exec_file (0);
5185 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5186 target_pid_to_str (pid_to_ptid (pid
)));
5188 printf_unfiltered (_("Attaching to %s\n"),
5189 target_pid_to_str (pid_to_ptid (pid
)));
5191 gdb_flush (gdb_stdout
);
5194 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5196 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5198 switch (packet_ok (rs
->buf
,
5199 &remote_protocol_packets
[PACKET_vAttach
]))
5202 if (!target_is_non_stop_p ())
5204 /* Save the reply for later. */
5205 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5206 strcpy (wait_status
, rs
->buf
);
5208 else if (strcmp (rs
->buf
, "OK") != 0)
5209 error (_("Attaching to %s failed with: %s"),
5210 target_pid_to_str (pid_to_ptid (pid
)),
5213 case PACKET_UNKNOWN
:
5214 error (_("This target does not support attaching to a process"));
5216 error (_("Attaching to %s failed"),
5217 target_pid_to_str (pid_to_ptid (pid
)));
5220 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5222 inferior_ptid
= pid_to_ptid (pid
);
5224 if (target_is_non_stop_p ())
5226 struct thread_info
*thread
;
5228 /* Get list of threads. */
5229 remote_update_thread_list (target
);
5231 thread
= first_thread_of_process (pid
);
5233 inferior_ptid
= thread
->ptid
;
5235 inferior_ptid
= pid_to_ptid (pid
);
5237 /* Invalidate our notion of the remote current thread. */
5238 record_currthread (rs
, minus_one_ptid
);
5242 /* Now, if we have thread information, update inferior_ptid. */
5243 inferior_ptid
= remote_current_thread (inferior_ptid
);
5245 /* Add the main thread to the thread list. */
5246 add_thread_silent (inferior_ptid
);
5249 /* Next, if the target can specify a description, read it. We do
5250 this before anything involving memory or registers. */
5251 target_find_description ();
5253 if (!target_is_non_stop_p ())
5255 /* Use the previously fetched status. */
5256 gdb_assert (wait_status
!= NULL
);
5258 if (target_can_async_p ())
5260 struct notif_event
*reply
5261 = remote_notif_parse (¬if_client_stop
, wait_status
);
5263 push_stop_reply ((struct stop_reply
*) reply
);
5269 gdb_assert (wait_status
!= NULL
);
5270 strcpy (rs
->buf
, wait_status
);
5271 rs
->cached_wait_status
= 1;
5275 gdb_assert (wait_status
== NULL
);
5278 /* Implementation of the to_post_attach method. */
5281 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5283 /* Get text, data & bss offsets. */
5286 /* In certain cases GDB might not have had the chance to start
5287 symbol lookup up until now. This could happen if the debugged
5288 binary is not using shared libraries, the vsyscall page is not
5289 present (on Linux) and the binary itself hadn't changed since the
5290 debugging process was started. */
5291 if (symfile_objfile
!= NULL
)
5292 remote_check_symbols();
5296 /* Check for the availability of vCont. This function should also check
5300 remote_vcont_probe (struct remote_state
*rs
)
5304 strcpy (rs
->buf
, "vCont?");
5306 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5309 /* Make sure that the features we assume are supported. */
5310 if (startswith (buf
, "vCont"))
5313 int support_c
, support_C
;
5315 rs
->supports_vCont
.s
= 0;
5316 rs
->supports_vCont
.S
= 0;
5319 rs
->supports_vCont
.t
= 0;
5320 rs
->supports_vCont
.r
= 0;
5321 while (p
&& *p
== ';')
5324 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5325 rs
->supports_vCont
.s
= 1;
5326 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5327 rs
->supports_vCont
.S
= 1;
5328 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5330 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5332 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5333 rs
->supports_vCont
.t
= 1;
5334 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5335 rs
->supports_vCont
.r
= 1;
5337 p
= strchr (p
, ';');
5340 /* If c, and C are not all supported, we can't use vCont. Clearing
5341 BUF will make packet_ok disable the packet. */
5342 if (!support_c
|| !support_C
)
5346 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5349 /* Helper function for building "vCont" resumptions. Write a
5350 resumption to P. ENDP points to one-passed-the-end of the buffer
5351 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5352 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5353 resumed thread should be single-stepped and/or signalled. If PTID
5354 equals minus_one_ptid, then all threads are resumed; if PTID
5355 represents a process, then all threads of the process are resumed;
5356 the thread to be stepped and/or signalled is given in the global
5360 append_resumption (char *p
, char *endp
,
5361 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5363 struct remote_state
*rs
= get_remote_state ();
5365 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5366 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5368 /* GDB is willing to range step. */
5369 && use_range_stepping
5370 /* Target supports range stepping. */
5371 && rs
->supports_vCont
.r
5372 /* We don't currently support range stepping multiple
5373 threads with a wildcard (though the protocol allows it,
5374 so stubs shouldn't make an active effort to forbid
5376 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5378 struct thread_info
*tp
;
5380 if (ptid_equal (ptid
, minus_one_ptid
))
5382 /* If we don't know about the target thread's tid, then
5383 we're resuming magic_null_ptid (see caller). */
5384 tp
= find_thread_ptid (magic_null_ptid
);
5387 tp
= find_thread_ptid (ptid
);
5388 gdb_assert (tp
!= NULL
);
5390 if (tp
->control
.may_range_step
)
5392 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5394 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5395 phex_nz (tp
->control
.step_range_start
,
5397 phex_nz (tp
->control
.step_range_end
,
5401 p
+= xsnprintf (p
, endp
- p
, ";s");
5404 p
+= xsnprintf (p
, endp
- p
, ";s");
5405 else if (siggnal
!= GDB_SIGNAL_0
)
5406 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5408 p
+= xsnprintf (p
, endp
- p
, ";c");
5410 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5414 /* All (-1) threads of process. */
5415 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5417 p
+= xsnprintf (p
, endp
- p
, ":");
5418 p
= write_ptid (p
, endp
, nptid
);
5420 else if (!ptid_equal (ptid
, minus_one_ptid
))
5422 p
+= xsnprintf (p
, endp
- p
, ":");
5423 p
= write_ptid (p
, endp
, ptid
);
5429 /* Clear the thread's private info on resume. */
5432 resume_clear_thread_private_info (struct thread_info
*thread
)
5434 if (thread
->priv
!= NULL
)
5436 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5437 thread
->priv
->watch_data_address
= 0;
5441 /* Append a vCont continue-with-signal action for threads that have a
5442 non-zero stop signal. */
5445 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5447 struct thread_info
*thread
;
5449 ALL_NON_EXITED_THREADS (thread
)
5450 if (ptid_match (thread
->ptid
, ptid
)
5451 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5452 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5454 p
= append_resumption (p
, endp
, thread
->ptid
,
5455 0, thread
->suspend
.stop_signal
);
5456 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5457 resume_clear_thread_private_info (thread
);
5463 /* Resume the remote inferior by using a "vCont" packet. The thread
5464 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5465 resumed thread should be single-stepped and/or signalled. If PTID
5466 equals minus_one_ptid, then all threads are resumed; the thread to
5467 be stepped and/or signalled is given in the global INFERIOR_PTID.
5468 This function returns non-zero iff it resumes the inferior.
5470 This function issues a strict subset of all possible vCont commands at the
5474 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5476 struct remote_state
*rs
= get_remote_state ();
5480 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5481 remote_vcont_probe (rs
);
5483 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5487 endp
= rs
->buf
+ get_remote_packet_size ();
5489 /* If we could generate a wider range of packets, we'd have to worry
5490 about overflowing BUF. Should there be a generic
5491 "multi-part-packet" packet? */
5493 p
+= xsnprintf (p
, endp
- p
, "vCont");
5495 if (ptid_equal (ptid
, magic_null_ptid
))
5497 /* MAGIC_NULL_PTID means that we don't have any active threads,
5498 so we don't have any TID numbers the inferior will
5499 understand. Make sure to only send forms that do not specify
5501 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5503 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5505 /* Resume all threads (of all processes, or of a single
5506 process), with preference for INFERIOR_PTID. This assumes
5507 inferior_ptid belongs to the set of all threads we are about
5509 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5511 /* Step inferior_ptid, with or without signal. */
5512 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5515 /* Also pass down any pending signaled resumption for other
5516 threads not the current. */
5517 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5519 /* And continue others without a signal. */
5520 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5524 /* Scheduler locking; resume only PTID. */
5525 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5528 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5531 if (target_is_non_stop_p ())
5533 /* In non-stop, the stub replies to vCont with "OK". The stop
5534 reply will be reported asynchronously by means of a `%Stop'
5536 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5537 if (strcmp (rs
->buf
, "OK") != 0)
5538 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5544 /* Tell the remote machine to resume. */
5547 remote_resume (struct target_ops
*ops
,
5548 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5550 struct remote_state
*rs
= get_remote_state ();
5552 struct thread_info
*thread
;
5554 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5555 (explained in remote-notif.c:handle_notification) so
5556 remote_notif_process is not called. We need find a place where
5557 it is safe to start a 'vNotif' sequence. It is good to do it
5558 before resuming inferior, because inferior was stopped and no RSP
5559 traffic at that moment. */
5560 if (!target_is_non_stop_p ())
5561 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5563 rs
->last_sent_signal
= siggnal
;
5564 rs
->last_sent_step
= step
;
5566 /* The vCont packet doesn't need to specify threads via Hc. */
5567 /* No reverse support (yet) for vCont. */
5568 if (execution_direction
!= EXEC_REVERSE
)
5569 if (remote_vcont_resume (ptid
, step
, siggnal
))
5572 /* All other supported resume packets do use Hc, so set the continue
5574 if (ptid_equal (ptid
, minus_one_ptid
))
5575 set_continue_thread (any_thread_ptid
);
5577 set_continue_thread (ptid
);
5579 ALL_NON_EXITED_THREADS (thread
)
5580 resume_clear_thread_private_info (thread
);
5583 if (execution_direction
== EXEC_REVERSE
)
5585 /* We don't pass signals to the target in reverse exec mode. */
5586 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5587 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5590 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5591 error (_("Remote reverse-step not supported."));
5592 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5593 error (_("Remote reverse-continue not supported."));
5595 strcpy (buf
, step
? "bs" : "bc");
5597 else if (siggnal
!= GDB_SIGNAL_0
)
5599 buf
[0] = step
? 'S' : 'C';
5600 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5601 buf
[2] = tohex (((int) siggnal
) & 0xf);
5605 strcpy (buf
, step
? "s" : "c");
5610 /* We are about to start executing the inferior, let's register it
5611 with the event loop. NOTE: this is the one place where all the
5612 execution commands end up. We could alternatively do this in each
5613 of the execution commands in infcmd.c. */
5614 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5615 into infcmd.c in order to allow inferior function calls to work
5616 NOT asynchronously. */
5617 if (target_can_async_p ())
5620 /* We've just told the target to resume. The remote server will
5621 wait for the inferior to stop, and then send a stop reply. In
5622 the mean time, we can't start another command/query ourselves
5623 because the stub wouldn't be ready to process it. This applies
5624 only to the base all-stop protocol, however. In non-stop (which
5625 only supports vCont), the stub replies with an "OK", and is
5626 immediate able to process further serial input. */
5627 if (!target_is_non_stop_p ())
5628 rs
->waiting_for_stop_reply
= 1;
5632 /* Set up the signal handler for SIGINT, while the target is
5633 executing, ovewriting the 'regular' SIGINT signal handler. */
5635 async_initialize_sigint_signal_handler (void)
5637 signal (SIGINT
, async_handle_remote_sigint
);
5640 /* Signal handler for SIGINT, while the target is executing. */
5642 async_handle_remote_sigint (int sig
)
5644 signal (sig
, async_handle_remote_sigint_twice
);
5645 /* Note we need to go through gdb_call_async_signal_handler in order
5646 to wake up the event loop on Windows. */
5647 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5650 /* Signal handler for SIGINT, installed after SIGINT has already been
5651 sent once. It will take effect the second time that the user sends
5654 async_handle_remote_sigint_twice (int sig
)
5656 signal (sig
, async_handle_remote_sigint
);
5657 /* See note in async_handle_remote_sigint. */
5658 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5661 /* Implementation of to_check_pending_interrupt. */
5664 remote_check_pending_interrupt (struct target_ops
*self
)
5666 struct async_signal_handler
*token
= async_sigint_remote_twice_token
;
5668 if (async_signal_handler_is_marked (token
))
5670 clear_async_signal_handler (token
);
5671 call_async_signal_handler (token
);
5675 /* Perform the real interruption of the target execution, in response
5678 async_remote_interrupt (gdb_client_data arg
)
5681 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5683 target_interrupt (inferior_ptid
);
5686 /* Perform interrupt, if the first attempt did not succeed. Just give
5687 up on the target alltogether. */
5689 async_remote_interrupt_twice (gdb_client_data arg
)
5692 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5697 /* Reinstall the usual SIGINT handlers, after the target has
5700 async_cleanup_sigint_signal_handler (void *dummy
)
5702 signal (SIGINT
, handle_sigint
);
5705 /* Send ^C to target to halt it. Target will respond, and send us a
5707 static void (*ofunc
) (int);
5709 /* The command line interface's interrupt routine. This function is installed
5710 as a signal handler for SIGINT. The first time a user requests an
5711 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5712 response from the target (it didn't stop when the user requested it),
5713 we ask the user if he'd like to detach from the target. */
5716 sync_remote_interrupt (int signo
)
5718 /* If this doesn't work, try more severe steps. */
5719 signal (signo
, sync_remote_interrupt_twice
);
5721 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5724 /* The user typed ^C twice. */
5727 sync_remote_interrupt_twice (int signo
)
5729 signal (signo
, ofunc
);
5730 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5731 signal (signo
, sync_remote_interrupt
);
5734 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5735 thread, all threads of a remote process, or all threads of all
5739 remote_stop_ns (ptid_t ptid
)
5741 struct remote_state
*rs
= get_remote_state ();
5743 char *endp
= rs
->buf
+ get_remote_packet_size ();
5745 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5746 remote_vcont_probe (rs
);
5748 if (!rs
->supports_vCont
.t
)
5749 error (_("Remote server does not support stopping threads"));
5751 if (ptid_equal (ptid
, minus_one_ptid
)
5752 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5753 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5758 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5760 if (ptid_is_pid (ptid
))
5761 /* All (-1) threads of process. */
5762 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5765 /* Small optimization: if we already have a stop reply for
5766 this thread, no use in telling the stub we want this
5768 if (peek_stop_reply (ptid
))
5774 write_ptid (p
, endp
, nptid
);
5777 /* In non-stop, we get an immediate OK reply. The stop reply will
5778 come in asynchronously by notification. */
5780 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5781 if (strcmp (rs
->buf
, "OK") != 0)
5782 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5785 /* All-stop version of target_interrupt. Sends a break or a ^C to
5786 interrupt the remote target. It is undefined which thread of which
5787 process reports the interrupt. */
5790 remote_interrupt_as (void)
5792 struct remote_state
*rs
= get_remote_state ();
5794 rs
->ctrlc_pending_p
= 1;
5796 /* If the inferior is stopped already, but the core didn't know
5797 about it yet, just ignore the request. The cached wait status
5798 will be collected in remote_wait. */
5799 if (rs
->cached_wait_status
)
5802 /* Send interrupt_sequence to remote target. */
5803 send_interrupt_sequence ();
5806 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5807 the remote target. It is undefined which thread of which process
5808 reports the interrupt. Returns true if the packet is supported by
5809 the server, false otherwise. */
5812 remote_interrupt_ns (void)
5814 struct remote_state
*rs
= get_remote_state ();
5816 char *endp
= rs
->buf
+ get_remote_packet_size ();
5818 xsnprintf (p
, endp
- p
, "vCtrlC");
5820 /* In non-stop, we get an immediate OK reply. The stop reply will
5821 come in asynchronously by notification. */
5823 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5825 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
5829 case PACKET_UNKNOWN
:
5832 error (_("Interrupting target failed: %s"), rs
->buf
);
5838 /* Implement the to_stop function for the remote targets. */
5841 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5844 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5846 if (target_is_non_stop_p ())
5847 remote_stop_ns (ptid
);
5850 /* We don't currently have a way to transparently pause the
5851 remote target in all-stop mode. Interrupt it instead. */
5852 remote_interrupt_as ();
5856 /* Implement the to_interrupt function for the remote targets. */
5859 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5862 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5866 /* In non-stop mode, we always stop with no signal instead. */
5867 remote_stop_ns (ptid
);
5871 /* In all-stop, we emulate ^C-ing the remote target's
5873 if (target_is_non_stop_p ())
5875 if (!remote_interrupt_ns ())
5877 /* No support for ^C-ing the remote target. Stop it
5878 (with no signal) instead. */
5879 remote_stop_ns (ptid
);
5883 remote_interrupt_as ();
5887 /* Ask the user what to do when an interrupt is received. */
5890 interrupt_query (void)
5892 struct remote_state
*rs
= get_remote_state ();
5893 struct cleanup
*old_chain
;
5895 old_chain
= make_cleanup_restore_target_terminal ();
5896 target_terminal_ours ();
5898 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5900 if (query (_("The target is not responding to interrupt requests.\n"
5901 "Stop debugging it? ")))
5903 remote_unpush_target ();
5904 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5909 if (query (_("Interrupted while waiting for the program.\n"
5910 "Give up waiting? ")))
5914 do_cleanups (old_chain
);
5917 /* Enable/disable target terminal ownership. Most targets can use
5918 terminal groups to control terminal ownership. Remote targets are
5919 different in that explicit transfer of ownership to/from GDB/target
5923 remote_terminal_inferior (struct target_ops
*self
)
5925 if (!target_async_permitted
)
5926 /* Nothing to do. */
5929 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5930 idempotent. The event-loop GDB talking to an asynchronous target
5931 with a synchronous command calls this function from both
5932 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5933 transfer the terminal to the target when it shouldn't this guard
5935 if (!remote_async_terminal_ours_p
)
5937 delete_file_handler (input_fd
);
5938 remote_async_terminal_ours_p
= 0;
5939 async_initialize_sigint_signal_handler ();
5940 /* NOTE: At this point we could also register our selves as the
5941 recipient of all input. Any characters typed could then be
5942 passed on down to the target. */
5946 remote_terminal_ours (struct target_ops
*self
)
5948 if (!target_async_permitted
)
5949 /* Nothing to do. */
5952 /* See FIXME in remote_terminal_inferior. */
5953 if (remote_async_terminal_ours_p
)
5955 async_cleanup_sigint_signal_handler (NULL
);
5956 add_file_handler (input_fd
, stdin_event_handler
, 0);
5957 remote_async_terminal_ours_p
= 1;
5961 remote_console_output (char *msg
)
5965 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5968 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5972 fputs_unfiltered (tb
, gdb_stdtarg
);
5974 gdb_flush (gdb_stdtarg
);
5977 typedef struct cached_reg
5980 gdb_byte data
[MAX_REGISTER_SIZE
];
5983 DEF_VEC_O(cached_reg_t
);
5985 typedef struct stop_reply
5987 struct notif_event base
;
5989 /* The identifier of the thread about this event */
5992 /* The remote state this event is associated with. When the remote
5993 connection, represented by a remote_state object, is closed,
5994 all the associated stop_reply events should be released. */
5995 struct remote_state
*rs
;
5997 struct target_waitstatus ws
;
5999 /* Expedited registers. This makes remote debugging a bit more
6000 efficient for those targets that provide critical registers as
6001 part of their normal status mechanism (as another roundtrip to
6002 fetch them is avoided). */
6003 VEC(cached_reg_t
) *regcache
;
6005 enum target_stop_reason stop_reason
;
6007 CORE_ADDR watch_data_address
;
6012 DECLARE_QUEUE_P (stop_reply_p
);
6013 DEFINE_QUEUE_P (stop_reply_p
);
6014 /* The list of already fetched and acknowledged stop events. This
6015 queue is used for notification Stop, and other notifications
6016 don't need queue for their events, because the notification events
6017 of Stop can't be consumed immediately, so that events should be
6018 queued first, and be consumed by remote_wait_{ns,as} one per
6019 time. Other notifications can consume their events immediately,
6020 so queue is not needed for them. */
6021 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6024 stop_reply_xfree (struct stop_reply
*r
)
6026 notif_event_xfree ((struct notif_event
*) r
);
6029 /* Return the length of the stop reply queue. */
6032 stop_reply_queue_length (void)
6034 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6038 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6039 struct notif_event
*event
)
6041 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6045 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6046 struct notif_event
*event
)
6048 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6051 putpkt ((char *) self
->ack_command
);
6053 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6054 /* We got an unknown stop reply. */
6055 error (_("Unknown stop reply"));
6057 push_stop_reply (stop_reply
);
6061 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6063 /* We can't get pending events in remote_notif_process for
6064 notification stop, and we have to do this in remote_wait_ns
6065 instead. If we fetch all queued events from stub, remote stub
6066 may exit and we have no chance to process them back in
6068 mark_async_event_handler (remote_async_inferior_event_token
);
6073 stop_reply_dtr (struct notif_event
*event
)
6075 struct stop_reply
*r
= (struct stop_reply
*) event
;
6077 VEC_free (cached_reg_t
, r
->regcache
);
6080 static struct notif_event
*
6081 remote_notif_stop_alloc_reply (void)
6083 /* We cast to a pointer to the "base class". */
6084 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6086 r
->dtr
= stop_reply_dtr
;
6091 /* A client of notification Stop. */
6093 struct notif_client notif_client_stop
=
6097 remote_notif_stop_parse
,
6098 remote_notif_stop_ack
,
6099 remote_notif_stop_can_get_pending_events
,
6100 remote_notif_stop_alloc_reply
,
6104 /* A parameter to pass data in and out. */
6106 struct queue_iter_param
6109 struct stop_reply
*output
;
6112 /* Determine if THREAD is a pending fork parent thread. ARG contains
6113 the pid of the process that owns the threads we want to check, or
6114 -1 if we want to check all threads. */
6117 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6120 if (ws
->kind
== TARGET_WAITKIND_FORKED
6121 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6123 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6130 /* Check whether EVENT is a fork event, and if it is, remove the
6131 fork child from the context list passed in DATA. */
6134 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6135 QUEUE_ITER (stop_reply_p
) *iter
,
6139 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6140 struct threads_listing_context
*context
6141 = (struct threads_listing_context
*) param
->input
;
6143 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6144 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6145 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6146 threads_listing_context_remove (&event
->ws
, context
);
6151 /* If CONTEXT contains any fork child threads that have not been
6152 reported yet, remove them from the CONTEXT list. If such a
6153 thread exists it is because we are stopped at a fork catchpoint
6154 and have not yet called follow_fork, which will set up the
6155 host-side data structures for the new process. */
6158 remove_new_fork_children (struct threads_listing_context
*context
)
6160 struct thread_info
* thread
;
6162 struct notif_client
*notif
= ¬if_client_stop
;
6163 struct queue_iter_param param
;
6165 /* For any threads stopped at a fork event, remove the corresponding
6166 fork child threads from the CONTEXT list. */
6167 ALL_NON_EXITED_THREADS (thread
)
6169 struct target_waitstatus
*ws
;
6171 if (thread
->suspend
.waitstatus_pending_p
)
6172 ws
= &thread
->suspend
.waitstatus
;
6174 ws
= &thread
->pending_follow
;
6176 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6178 threads_listing_context_remove (ws
, context
);
6182 /* Check for any pending fork events (not reported or processed yet)
6183 in process PID and remove those fork child threads from the
6184 CONTEXT list as well. */
6185 remote_notif_get_pending_events (notif
);
6186 param
.input
= context
;
6187 param
.output
= NULL
;
6188 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6189 remove_child_of_pending_fork
, ¶m
);
6192 /* Remove stop replies in the queue if its pid is equal to the given
6196 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6197 QUEUE_ITER (stop_reply_p
) *iter
,
6201 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6202 struct inferior
*inf
= (struct inferior
*) param
->input
;
6204 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6206 stop_reply_xfree (event
);
6207 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6213 /* Discard all pending stop replies of inferior INF. */
6216 discard_pending_stop_replies (struct inferior
*inf
)
6218 struct queue_iter_param param
;
6219 struct stop_reply
*reply
;
6220 struct remote_state
*rs
= get_remote_state ();
6221 struct remote_notif_state
*rns
= rs
->notif_state
;
6223 /* This function can be notified when an inferior exists. When the
6224 target is not remote, the notification state is NULL. */
6225 if (rs
->remote_desc
== NULL
)
6228 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6230 /* Discard the in-flight notification. */
6231 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6233 stop_reply_xfree (reply
);
6234 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6238 param
.output
= NULL
;
6239 /* Discard the stop replies we have already pulled with
6241 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6242 remove_stop_reply_for_inferior
, ¶m
);
6245 /* If its remote state is equal to the given remote state,
6246 remove EVENT from the stop reply queue. */
6249 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6250 QUEUE_ITER (stop_reply_p
) *iter
,
6254 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6255 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6257 if (event
->rs
== rs
)
6259 stop_reply_xfree (event
);
6260 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6266 /* Discard the stop replies for RS in stop_reply_queue. */
6269 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6271 struct queue_iter_param param
;
6274 param
.output
= NULL
;
6275 /* Discard the stop replies we have already pulled with
6277 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6278 remove_stop_reply_of_remote_state
, ¶m
);
6281 /* A parameter to pass data in and out. */
6284 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6285 QUEUE_ITER (stop_reply_p
) *iter
,
6289 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6290 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6292 if (ptid_match (event
->ptid
, *ptid
))
6294 param
->output
= event
;
6295 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6302 /* Remove the first reply in 'stop_reply_queue' which matches
6305 static struct stop_reply
*
6306 remote_notif_remove_queued_reply (ptid_t ptid
)
6308 struct queue_iter_param param
;
6310 param
.input
= &ptid
;
6311 param
.output
= NULL
;
6313 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6314 remote_notif_remove_once_on_match
, ¶m
);
6316 fprintf_unfiltered (gdb_stdlog
,
6317 "notif: discard queued event: 'Stop' in %s\n",
6318 target_pid_to_str (ptid
));
6320 return param
.output
;
6323 /* Look for a queued stop reply belonging to PTID. If one is found,
6324 remove it from the queue, and return it. Returns NULL if none is
6325 found. If there are still queued events left to process, tell the
6326 event loop to get back to target_wait soon. */
6328 static struct stop_reply
*
6329 queued_stop_reply (ptid_t ptid
)
6331 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6333 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6334 /* There's still at least an event left. */
6335 mark_async_event_handler (remote_async_inferior_event_token
);
6340 /* Push a fully parsed stop reply in the stop reply queue. Since we
6341 know that we now have at least one queued event left to pass to the
6342 core side, tell the event loop to get back to target_wait soon. */
6345 push_stop_reply (struct stop_reply
*new_event
)
6347 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6350 fprintf_unfiltered (gdb_stdlog
,
6351 "notif: push 'Stop' %s to queue %d\n",
6352 target_pid_to_str (new_event
->ptid
),
6353 QUEUE_length (stop_reply_p
,
6356 mark_async_event_handler (remote_async_inferior_event_token
);
6360 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6361 QUEUE_ITER (stop_reply_p
) *iter
,
6362 struct stop_reply
*event
,
6365 ptid_t
*ptid
= (ptid_t
*) data
;
6367 return !(ptid_equal (*ptid
, event
->ptid
)
6368 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6371 /* Returns true if we have a stop reply for PTID. */
6374 peek_stop_reply (ptid_t ptid
)
6376 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6377 stop_reply_match_ptid_and_ws
, &ptid
);
6380 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6381 starting with P and ending with PEND matches PREFIX. */
6384 strprefix (const char *p
, const char *pend
, const char *prefix
)
6386 for ( ; p
< pend
; p
++, prefix
++)
6389 return *prefix
== '\0';
6392 /* Parse the stop reply in BUF. Either the function succeeds, and the
6393 result is stored in EVENT, or throws an error. */
6396 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6398 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6403 event
->ptid
= null_ptid
;
6404 event
->rs
= get_remote_state ();
6405 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6406 event
->ws
.value
.integer
= 0;
6407 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6408 event
->regcache
= NULL
;
6413 case 'T': /* Status with PC, SP, FP, ... */
6414 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6415 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6417 n... = register number
6418 r... = register contents
6421 p
= &buf
[3]; /* after Txx */
6427 p1
= strchr (p
, ':');
6429 error (_("Malformed packet(a) (missing colon): %s\n\
6433 error (_("Malformed packet(a) (missing register number): %s\n\
6437 /* Some "registers" are actually extended stop information.
6438 Note if you're adding a new entry here: GDB 7.9 and
6439 earlier assume that all register "numbers" that start
6440 with an hex digit are real register numbers. Make sure
6441 the server only sends such a packet if it knows the
6442 client understands it. */
6444 if (strprefix (p
, p1
, "thread"))
6445 event
->ptid
= read_ptid (++p1
, &p
);
6446 else if (strprefix (p
, p1
, "syscall_entry"))
6450 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6451 p
= unpack_varlen_hex (++p1
, &sysno
);
6452 event
->ws
.value
.syscall_number
= (int) sysno
;
6454 else if (strprefix (p
, p1
, "syscall_return"))
6458 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6459 p
= unpack_varlen_hex (++p1
, &sysno
);
6460 event
->ws
.value
.syscall_number
= (int) sysno
;
6462 else if (strprefix (p
, p1
, "watch")
6463 || strprefix (p
, p1
, "rwatch")
6464 || strprefix (p
, p1
, "awatch"))
6466 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6467 p
= unpack_varlen_hex (++p1
, &addr
);
6468 event
->watch_data_address
= (CORE_ADDR
) addr
;
6470 else if (strprefix (p
, p1
, "swbreak"))
6472 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6474 /* Make sure the stub doesn't forget to indicate support
6476 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6477 error (_("Unexpected swbreak stop reason"));
6479 /* The value part is documented as "must be empty",
6480 though we ignore it, in case we ever decide to make
6481 use of it in a backward compatible way. */
6482 p
= strchrnul (p1
+ 1, ';');
6484 else if (strprefix (p
, p1
, "hwbreak"))
6486 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6488 /* Make sure the stub doesn't forget to indicate support
6490 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6491 error (_("Unexpected hwbreak stop reason"));
6494 p
= strchrnul (p1
+ 1, ';');
6496 else if (strprefix (p
, p1
, "library"))
6498 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6499 p
= strchrnul (p1
+ 1, ';');
6501 else if (strprefix (p
, p1
, "replaylog"))
6503 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6504 /* p1 will indicate "begin" or "end", but it makes
6505 no difference for now, so ignore it. */
6506 p
= strchrnul (p1
+ 1, ';');
6508 else if (strprefix (p
, p1
, "core"))
6512 p
= unpack_varlen_hex (++p1
, &c
);
6515 else if (strprefix (p
, p1
, "fork"))
6517 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6518 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6520 else if (strprefix (p
, p1
, "vfork"))
6522 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6523 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6525 else if (strprefix (p
, p1
, "vforkdone"))
6527 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6528 p
= strchrnul (p1
+ 1, ';');
6530 else if (strprefix (p
, p1
, "exec"))
6533 char pathname
[PATH_MAX
];
6536 /* Determine the length of the execd pathname. */
6537 p
= unpack_varlen_hex (++p1
, &ignored
);
6538 pathlen
= (p
- p1
) / 2;
6540 /* Save the pathname for event reporting and for
6541 the next run command. */
6542 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6543 pathname
[pathlen
] = '\0';
6545 /* This is freed during event handling. */
6546 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6547 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6549 /* Skip the registers included in this packet, since
6550 they may be for an architecture different from the
6551 one used by the original program. */
6554 else if (strprefix (p
, p1
, "create"))
6556 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6557 p
= strchrnul (p1
+ 1, ';');
6566 p
= strchrnul (p1
+ 1, ';');
6571 /* Maybe a real ``P'' register number. */
6572 p_temp
= unpack_varlen_hex (p
, &pnum
);
6573 /* If the first invalid character is the colon, we got a
6574 register number. Otherwise, it's an unknown stop
6578 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6579 cached_reg_t cached_reg
;
6582 error (_("Remote sent bad register number %s: %s\n\
6584 hex_string (pnum
), p
, buf
);
6586 cached_reg
.num
= reg
->regnum
;
6589 fieldsize
= hex2bin (p
, cached_reg
.data
,
6590 register_size (target_gdbarch (),
6593 if (fieldsize
< register_size (target_gdbarch (),
6595 warning (_("Remote reply is too short: %s"), buf
);
6597 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6601 /* Not a number. Silently skip unknown optional
6603 p
= strchrnul (p1
+ 1, ';');
6608 error (_("Remote register badly formatted: %s\nhere: %s"),
6613 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6617 case 'S': /* Old style status, just signal only. */
6621 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6622 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6623 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6624 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6626 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6629 case 'w': /* Thread exited. */
6634 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
6635 p
= unpack_varlen_hex (&buf
[1], &value
);
6636 event
->ws
.value
.integer
= value
;
6638 error (_("stop reply packet badly formatted: %s"), buf
);
6639 event
->ptid
= read_ptid (++p
, NULL
);
6642 case 'W': /* Target exited. */
6649 /* GDB used to accept only 2 hex chars here. Stubs should
6650 only send more if they detect GDB supports multi-process
6652 p
= unpack_varlen_hex (&buf
[1], &value
);
6656 /* The remote process exited. */
6657 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6658 event
->ws
.value
.integer
= value
;
6662 /* The remote process exited with a signal. */
6663 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6664 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6665 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6667 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6670 /* If no process is specified, assume inferior_ptid. */
6671 pid
= ptid_get_pid (inferior_ptid
);
6680 else if (startswith (p
, "process:"))
6684 p
+= sizeof ("process:") - 1;
6685 unpack_varlen_hex (p
, &upid
);
6689 error (_("unknown stop reply packet: %s"), buf
);
6692 error (_("unknown stop reply packet: %s"), buf
);
6693 event
->ptid
= pid_to_ptid (pid
);
6697 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
6698 event
->ptid
= minus_one_ptid
;
6702 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
6703 error (_("No process or thread specified in stop reply: %s"), buf
);
6706 /* When the stub wants to tell GDB about a new notification reply, it
6707 sends a notification (%Stop, for example). Those can come it at
6708 any time, hence, we have to make sure that any pending
6709 putpkt/getpkt sequence we're making is finished, before querying
6710 the stub for more events with the corresponding ack command
6711 (vStopped, for example). E.g., if we started a vStopped sequence
6712 immediately upon receiving the notification, something like this
6720 1.6) <-- (registers reply to step #1.3)
6722 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6725 To solve this, whenever we parse a %Stop notification successfully,
6726 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6727 doing whatever we were doing:
6733 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6734 2.5) <-- (registers reply to step #2.3)
6736 Eventualy after step #2.5, we return to the event loop, which
6737 notices there's an event on the
6738 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6739 associated callback --- the function below. At this point, we're
6740 always safe to start a vStopped sequence. :
6743 2.7) <-- T05 thread:2
6749 remote_notif_get_pending_events (struct notif_client
*nc
)
6751 struct remote_state
*rs
= get_remote_state ();
6753 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6756 fprintf_unfiltered (gdb_stdlog
,
6757 "notif: process: '%s' ack pending event\n",
6761 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6762 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6767 if (strcmp (rs
->buf
, "OK") == 0)
6770 remote_notif_ack (nc
, rs
->buf
);
6776 fprintf_unfiltered (gdb_stdlog
,
6777 "notif: process: '%s' no pending reply\n",
6782 /* Called when it is decided that STOP_REPLY holds the info of the
6783 event that is to be returned to the core. This function always
6784 destroys STOP_REPLY. */
6787 process_stop_reply (struct stop_reply
*stop_reply
,
6788 struct target_waitstatus
*status
)
6792 *status
= stop_reply
->ws
;
6793 ptid
= stop_reply
->ptid
;
6795 /* If no thread/process was reported by the stub, assume the current
6797 if (ptid_equal (ptid
, null_ptid
))
6798 ptid
= inferior_ptid
;
6800 if (status
->kind
!= TARGET_WAITKIND_EXITED
6801 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
6802 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
6804 struct private_thread_info
*remote_thr
;
6806 /* Expedited registers. */
6807 if (stop_reply
->regcache
)
6809 struct regcache
*regcache
6810 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6815 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6817 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6818 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6821 remote_notice_new_inferior (ptid
, 0);
6822 remote_thr
= demand_private_info (ptid
);
6823 remote_thr
->core
= stop_reply
->core
;
6824 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
6825 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
6828 stop_reply_xfree (stop_reply
);
6832 /* The non-stop mode version of target_wait. */
6835 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6837 struct remote_state
*rs
= get_remote_state ();
6838 struct stop_reply
*stop_reply
;
6842 /* If in non-stop mode, get out of getpkt even if a
6843 notification is received. */
6845 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6846 0 /* forever */, &is_notif
);
6849 if (ret
!= -1 && !is_notif
)
6852 case 'E': /* Error of some sort. */
6853 /* We're out of sync with the target now. Did it continue
6854 or not? We can't tell which thread it was in non-stop,
6855 so just ignore this. */
6856 warning (_("Remote failure reply: %s"), rs
->buf
);
6858 case 'O': /* Console output. */
6859 remote_console_output (rs
->buf
+ 1);
6862 warning (_("Invalid remote reply: %s"), rs
->buf
);
6866 /* Acknowledge a pending stop reply that may have arrived in the
6868 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6869 remote_notif_get_pending_events (¬if_client_stop
);
6871 /* If indeed we noticed a stop reply, we're done. */
6872 stop_reply
= queued_stop_reply (ptid
);
6873 if (stop_reply
!= NULL
)
6874 return process_stop_reply (stop_reply
, status
);
6876 /* Still no event. If we're just polling for an event, then
6877 return to the event loop. */
6878 if (options
& TARGET_WNOHANG
)
6880 status
->kind
= TARGET_WAITKIND_IGNORE
;
6881 return minus_one_ptid
;
6884 /* Otherwise do a blocking wait. */
6885 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6886 1 /* forever */, &is_notif
);
6890 /* Wait until the remote machine stops, then return, storing status in
6891 STATUS just as `wait' would. */
6894 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6896 struct remote_state
*rs
= get_remote_state ();
6897 ptid_t event_ptid
= null_ptid
;
6899 struct stop_reply
*stop_reply
;
6903 status
->kind
= TARGET_WAITKIND_IGNORE
;
6904 status
->value
.integer
= 0;
6906 stop_reply
= queued_stop_reply (ptid
);
6907 if (stop_reply
!= NULL
)
6908 return process_stop_reply (stop_reply
, status
);
6910 if (rs
->cached_wait_status
)
6911 /* Use the cached wait status, but only once. */
6912 rs
->cached_wait_status
= 0;
6917 int forever
= ((options
& TARGET_WNOHANG
) == 0
6918 && wait_forever_enabled_p
);
6920 if (!rs
->waiting_for_stop_reply
)
6922 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6923 return minus_one_ptid
;
6926 if (!target_is_async_p ())
6928 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6929 /* If the user hit C-c before this packet, or between packets,
6930 pretend that it was hit right here. */
6931 if (check_quit_flag ())
6934 sync_remote_interrupt (SIGINT
);
6938 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6939 _never_ wait for ever -> test on target_is_async_p().
6940 However, before we do that we need to ensure that the caller
6941 knows how to take the target into/out of async mode. */
6942 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6943 forever
, &is_notif
);
6945 if (!target_is_async_p ())
6946 signal (SIGINT
, ofunc
);
6948 /* GDB gets a notification. Return to core as this event is
6950 if (ret
!= -1 && is_notif
)
6951 return minus_one_ptid
;
6953 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6954 return minus_one_ptid
;
6959 /* Assume that the target has acknowledged Ctrl-C unless we receive
6960 an 'F' or 'O' packet. */
6961 if (buf
[0] != 'F' && buf
[0] != 'O')
6962 rs
->ctrlc_pending_p
= 0;
6966 case 'E': /* Error of some sort. */
6967 /* We're out of sync with the target now. Did it continue or
6968 not? Not is more likely, so report a stop. */
6969 rs
->waiting_for_stop_reply
= 0;
6971 warning (_("Remote failure reply: %s"), buf
);
6972 status
->kind
= TARGET_WAITKIND_STOPPED
;
6973 status
->value
.sig
= GDB_SIGNAL_0
;
6975 case 'F': /* File-I/O request. */
6976 /* GDB may access the inferior memory while handling the File-I/O
6977 request, but we don't want GDB accessing memory while waiting
6978 for a stop reply. See the comments in putpkt_binary. Set
6979 waiting_for_stop_reply to 0 temporarily. */
6980 rs
->waiting_for_stop_reply
= 0;
6981 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6982 rs
->ctrlc_pending_p
= 0;
6983 /* GDB handled the File-I/O request, and the target is running
6984 again. Keep waiting for events. */
6985 rs
->waiting_for_stop_reply
= 1;
6987 case 'N': case 'T': case 'S': case 'X': case 'W':
6989 struct stop_reply
*stop_reply
;
6991 /* There is a stop reply to handle. */
6992 rs
->waiting_for_stop_reply
= 0;
6995 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6998 event_ptid
= process_stop_reply (stop_reply
, status
);
7001 case 'O': /* Console output. */
7002 remote_console_output (buf
+ 1);
7005 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7007 /* Zero length reply means that we tried 'S' or 'C' and the
7008 remote system doesn't support it. */
7009 target_terminal_ours_for_output ();
7011 ("Can't send signals to this remote system. %s not sent.\n",
7012 gdb_signal_to_name (rs
->last_sent_signal
));
7013 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7014 target_terminal_inferior ();
7016 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
7017 putpkt ((char *) buf
);
7020 /* else fallthrough */
7022 warning (_("Invalid remote reply: %s"), buf
);
7026 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7027 return minus_one_ptid
;
7028 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7030 /* Nothing interesting happened. If we're doing a non-blocking
7031 poll, we're done. Otherwise, go back to waiting. */
7032 if (options
& TARGET_WNOHANG
)
7033 return minus_one_ptid
;
7037 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7038 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7040 if (!ptid_equal (event_ptid
, null_ptid
))
7041 record_currthread (rs
, event_ptid
);
7043 event_ptid
= inferior_ptid
;
7046 /* A process exit. Invalidate our notion of current thread. */
7047 record_currthread (rs
, minus_one_ptid
);
7052 /* Wait until the remote machine stops, then return, storing status in
7053 STATUS just as `wait' would. */
7056 remote_wait (struct target_ops
*ops
,
7057 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7061 if (target_is_non_stop_p ())
7062 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7064 event_ptid
= remote_wait_as (ptid
, status
, options
);
7066 if (target_is_async_p ())
7068 /* If there are are events left in the queue tell the event loop
7070 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7071 mark_async_event_handler (remote_async_inferior_event_token
);
7077 /* Fetch a single register using a 'p' packet. */
7080 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7082 struct remote_state
*rs
= get_remote_state ();
7084 char regp
[MAX_REGISTER_SIZE
];
7087 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7090 if (reg
->pnum
== -1)
7095 p
+= hexnumstr (p
, reg
->pnum
);
7098 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7102 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7106 case PACKET_UNKNOWN
:
7109 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7110 gdbarch_register_name (get_regcache_arch (regcache
),
7115 /* If this register is unfetchable, tell the regcache. */
7118 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7122 /* Otherwise, parse and supply the value. */
7128 error (_("fetch_register_using_p: early buf termination"));
7130 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7133 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7137 /* Fetch the registers included in the target's 'g' packet. */
7140 send_g_packet (void)
7142 struct remote_state
*rs
= get_remote_state ();
7145 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7146 remote_send (&rs
->buf
, &rs
->buf_size
);
7148 /* We can get out of synch in various cases. If the first character
7149 in the buffer is not a hex character, assume that has happened
7150 and try to fetch another packet to read. */
7151 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7152 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7153 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7154 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7157 fprintf_unfiltered (gdb_stdlog
,
7158 "Bad register packet; fetching a new packet\n");
7159 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7162 buf_len
= strlen (rs
->buf
);
7164 /* Sanity check the received packet. */
7165 if (buf_len
% 2 != 0)
7166 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7172 process_g_packet (struct regcache
*regcache
)
7174 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7175 struct remote_state
*rs
= get_remote_state ();
7176 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7181 buf_len
= strlen (rs
->buf
);
7183 /* Further sanity checks, with knowledge of the architecture. */
7184 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7185 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7187 /* Save the size of the packet sent to us by the target. It is used
7188 as a heuristic when determining the max size of packets that the
7189 target can safely receive. */
7190 if (rsa
->actual_register_packet_size
== 0)
7191 rsa
->actual_register_packet_size
= buf_len
;
7193 /* If this is smaller than we guessed the 'g' packet would be,
7194 update our records. A 'g' reply that doesn't include a register's
7195 value implies either that the register is not available, or that
7196 the 'p' packet must be used. */
7197 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7199 rsa
->sizeof_g_packet
= buf_len
/ 2;
7201 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7203 if (rsa
->regs
[i
].pnum
== -1)
7206 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7207 rsa
->regs
[i
].in_g_packet
= 0;
7209 rsa
->regs
[i
].in_g_packet
= 1;
7213 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7215 /* Unimplemented registers read as all bits zero. */
7216 memset (regs
, 0, rsa
->sizeof_g_packet
);
7218 /* Reply describes registers byte by byte, each byte encoded as two
7219 hex characters. Suck them all up, then supply them to the
7220 register cacheing/storage mechanism. */
7223 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7225 if (p
[0] == 0 || p
[1] == 0)
7226 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7227 internal_error (__FILE__
, __LINE__
,
7228 _("unexpected end of 'g' packet reply"));
7230 if (p
[0] == 'x' && p
[1] == 'x')
7231 regs
[i
] = 0; /* 'x' */
7233 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7237 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7239 struct packet_reg
*r
= &rsa
->regs
[i
];
7243 if (r
->offset
* 2 >= strlen (rs
->buf
))
7244 /* This shouldn't happen - we adjusted in_g_packet above. */
7245 internal_error (__FILE__
, __LINE__
,
7246 _("unexpected end of 'g' packet reply"));
7247 else if (rs
->buf
[r
->offset
* 2] == 'x')
7249 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7250 /* The register isn't available, mark it as such (at
7251 the same time setting the value to zero). */
7252 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7255 regcache_raw_supply (regcache
, r
->regnum
,
7262 fetch_registers_using_g (struct regcache
*regcache
)
7265 process_g_packet (regcache
);
7268 /* Make the remote selected traceframe match GDB's selected
7272 set_remote_traceframe (void)
7275 struct remote_state
*rs
= get_remote_state ();
7277 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7280 /* Avoid recursion, remote_trace_find calls us again. */
7281 rs
->remote_traceframe_number
= get_traceframe_number ();
7283 newnum
= target_trace_find (tfind_number
,
7284 get_traceframe_number (), 0, 0, NULL
);
7286 /* Should not happen. If it does, all bets are off. */
7287 if (newnum
!= get_traceframe_number ())
7288 warning (_("could not set remote traceframe"));
7292 remote_fetch_registers (struct target_ops
*ops
,
7293 struct regcache
*regcache
, int regnum
)
7295 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7298 set_remote_traceframe ();
7299 set_general_thread (inferior_ptid
);
7303 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7305 gdb_assert (reg
!= NULL
);
7307 /* If this register might be in the 'g' packet, try that first -
7308 we are likely to read more than one register. If this is the
7309 first 'g' packet, we might be overly optimistic about its
7310 contents, so fall back to 'p'. */
7311 if (reg
->in_g_packet
)
7313 fetch_registers_using_g (regcache
);
7314 if (reg
->in_g_packet
)
7318 if (fetch_register_using_p (regcache
, reg
))
7321 /* This register is not available. */
7322 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7327 fetch_registers_using_g (regcache
);
7329 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7330 if (!rsa
->regs
[i
].in_g_packet
)
7331 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7333 /* This register is not available. */
7334 regcache_raw_supply (regcache
, i
, NULL
);
7338 /* Prepare to store registers. Since we may send them all (using a
7339 'G' request), we have to read out the ones we don't want to change
7343 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7345 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7347 gdb_byte buf
[MAX_REGISTER_SIZE
];
7349 /* Make sure the entire registers array is valid. */
7350 switch (packet_support (PACKET_P
))
7352 case PACKET_DISABLE
:
7353 case PACKET_SUPPORT_UNKNOWN
:
7354 /* Make sure all the necessary registers are cached. */
7355 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7356 if (rsa
->regs
[i
].in_g_packet
)
7357 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7364 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7365 packet was not recognized. */
7368 store_register_using_P (const struct regcache
*regcache
,
7369 struct packet_reg
*reg
)
7371 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7372 struct remote_state
*rs
= get_remote_state ();
7373 /* Try storing a single register. */
7374 char *buf
= rs
->buf
;
7375 gdb_byte regp
[MAX_REGISTER_SIZE
];
7378 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7381 if (reg
->pnum
== -1)
7384 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7385 p
= buf
+ strlen (buf
);
7386 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7387 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7389 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7391 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7396 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7397 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7398 case PACKET_UNKNOWN
:
7401 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7405 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7406 contents of the register cache buffer. FIXME: ignores errors. */
7409 store_registers_using_G (const struct regcache
*regcache
)
7411 struct remote_state
*rs
= get_remote_state ();
7412 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7416 /* Extract all the registers in the regcache copying them into a
7421 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7422 memset (regs
, 0, rsa
->sizeof_g_packet
);
7423 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7425 struct packet_reg
*r
= &rsa
->regs
[i
];
7428 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7432 /* Command describes registers byte by byte,
7433 each byte encoded as two hex characters. */
7436 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7438 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7440 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7441 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7442 error (_("Could not write registers; remote failure reply '%s'"),
7446 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7447 of the register cache buffer. FIXME: ignores errors. */
7450 remote_store_registers (struct target_ops
*ops
,
7451 struct regcache
*regcache
, int regnum
)
7453 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7456 set_remote_traceframe ();
7457 set_general_thread (inferior_ptid
);
7461 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7463 gdb_assert (reg
!= NULL
);
7465 /* Always prefer to store registers using the 'P' packet if
7466 possible; we often change only a small number of registers.
7467 Sometimes we change a larger number; we'd need help from a
7468 higher layer to know to use 'G'. */
7469 if (store_register_using_P (regcache
, reg
))
7472 /* For now, don't complain if we have no way to write the
7473 register. GDB loses track of unavailable registers too
7474 easily. Some day, this may be an error. We don't have
7475 any way to read the register, either... */
7476 if (!reg
->in_g_packet
)
7479 store_registers_using_G (regcache
);
7483 store_registers_using_G (regcache
);
7485 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7486 if (!rsa
->regs
[i
].in_g_packet
)
7487 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7488 /* See above for why we do not issue an error here. */
7493 /* Return the number of hex digits in num. */
7496 hexnumlen (ULONGEST num
)
7500 for (i
= 0; num
!= 0; i
++)
7506 /* Set BUF to the minimum number of hex digits representing NUM. */
7509 hexnumstr (char *buf
, ULONGEST num
)
7511 int len
= hexnumlen (num
);
7513 return hexnumnstr (buf
, num
, len
);
7517 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7520 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7526 for (i
= width
- 1; i
>= 0; i
--)
7528 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7535 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7538 remote_address_masked (CORE_ADDR addr
)
7540 unsigned int address_size
= remote_address_size
;
7542 /* If "remoteaddresssize" was not set, default to target address size. */
7544 address_size
= gdbarch_addr_bit (target_gdbarch ());
7546 if (address_size
> 0
7547 && address_size
< (sizeof (ULONGEST
) * 8))
7549 /* Only create a mask when that mask can safely be constructed
7550 in a ULONGEST variable. */
7553 mask
= (mask
<< address_size
) - 1;
7559 /* Determine whether the remote target supports binary downloading.
7560 This is accomplished by sending a no-op memory write of zero length
7561 to the target at the specified address. It does not suffice to send
7562 the whole packet, since many stubs strip the eighth bit and
7563 subsequently compute a wrong checksum, which causes real havoc with
7566 NOTE: This can still lose if the serial line is not eight-bit
7567 clean. In cases like this, the user should clear "remote
7571 check_binary_download (CORE_ADDR addr
)
7573 struct remote_state
*rs
= get_remote_state ();
7575 switch (packet_support (PACKET_X
))
7577 case PACKET_DISABLE
:
7581 case PACKET_SUPPORT_UNKNOWN
:
7587 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7589 p
+= hexnumstr (p
, (ULONGEST
) 0);
7593 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7594 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7596 if (rs
->buf
[0] == '\0')
7599 fprintf_unfiltered (gdb_stdlog
,
7600 "binary downloading NOT "
7601 "supported by target\n");
7602 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7607 fprintf_unfiltered (gdb_stdlog
,
7608 "binary downloading supported by target\n");
7609 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7616 /* Helper function to resize the payload in order to try to get a good
7617 alignment. We try to write an amount of data such that the next write will
7618 start on an address aligned on REMOTE_ALIGN_WRITES. */
7621 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7623 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7626 /* Write memory data directly to the remote machine.
7627 This does not inform the data cache; the data cache uses this.
7628 HEADER is the starting part of the packet.
7629 MEMADDR is the address in the remote memory space.
7630 MYADDR is the address of the buffer in our space.
7631 LEN_UNITS is the number of addressable units to write.
7632 UNIT_SIZE is the length in bytes of an addressable unit.
7633 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7634 should send data as binary ('X'), or hex-encoded ('M').
7636 The function creates packet of the form
7637 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7639 where encoding of <DATA> is terminated by PACKET_FORMAT.
7641 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7644 Return the transferred status, error or OK (an
7645 'enum target_xfer_status' value). Save the number of addressable units
7646 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7648 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7649 exchange between gdb and the stub could look like (?? in place of the
7655 -> $M1000,3:eeeeffffeeee#??
7659 <- eeeeffffeeeedddd */
7661 static enum target_xfer_status
7662 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7663 const gdb_byte
*myaddr
, ULONGEST len_units
,
7664 int unit_size
, ULONGEST
*xfered_len_units
,
7665 char packet_format
, int use_length
)
7667 struct remote_state
*rs
= get_remote_state ();
7673 int payload_capacity_bytes
;
7674 int payload_length_bytes
;
7676 if (packet_format
!= 'X' && packet_format
!= 'M')
7677 internal_error (__FILE__
, __LINE__
,
7678 _("remote_write_bytes_aux: bad packet format"));
7681 return TARGET_XFER_EOF
;
7683 payload_capacity_bytes
= get_memory_write_packet_size ();
7685 /* The packet buffer will be large enough for the payload;
7686 get_memory_packet_size ensures this. */
7689 /* Compute the size of the actual payload by subtracting out the
7690 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7692 payload_capacity_bytes
-= strlen ("$,:#NN");
7694 /* The comma won't be used. */
7695 payload_capacity_bytes
+= 1;
7696 payload_capacity_bytes
-= strlen (header
);
7697 payload_capacity_bytes
-= hexnumlen (memaddr
);
7699 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7701 strcat (rs
->buf
, header
);
7702 p
= rs
->buf
+ strlen (header
);
7704 /* Compute a best guess of the number of bytes actually transfered. */
7705 if (packet_format
== 'X')
7707 /* Best guess at number of bytes that will fit. */
7708 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7710 payload_capacity_bytes
-= hexnumlen (todo_units
);
7711 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7715 /* Number of bytes that will fit. */
7716 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7718 payload_capacity_bytes
-= hexnumlen (todo_units
);
7719 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7722 if (todo_units
<= 0)
7723 internal_error (__FILE__
, __LINE__
,
7724 _("minimum packet size too small to write data"));
7726 /* If we already need another packet, then try to align the end
7727 of this packet to a useful boundary. */
7728 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7729 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7731 /* Append "<memaddr>". */
7732 memaddr
= remote_address_masked (memaddr
);
7733 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7740 /* Append the length and retain its location and size. It may need to be
7741 adjusted once the packet body has been created. */
7743 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7751 /* Append the packet body. */
7752 if (packet_format
== 'X')
7754 /* Binary mode. Send target system values byte by byte, in
7755 increasing byte addresses. Only escape certain critical
7757 payload_length_bytes
=
7758 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7759 &units_written
, payload_capacity_bytes
);
7761 /* If not all TODO units fit, then we'll need another packet. Make
7762 a second try to keep the end of the packet aligned. Don't do
7763 this if the packet is tiny. */
7764 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7768 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7770 if (new_todo_units
!= units_written
)
7771 payload_length_bytes
=
7772 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7773 (gdb_byte
*) p
, &units_written
,
7774 payload_capacity_bytes
);
7777 p
+= payload_length_bytes
;
7778 if (use_length
&& units_written
< todo_units
)
7780 /* Escape chars have filled up the buffer prematurely,
7781 and we have actually sent fewer units than planned.
7782 Fix-up the length field of the packet. Use the same
7783 number of characters as before. */
7784 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7786 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7791 /* Normal mode: Send target system values byte by byte, in
7792 increasing byte addresses. Each byte is encoded as a two hex
7794 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7795 units_written
= todo_units
;
7798 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7799 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7801 if (rs
->buf
[0] == 'E')
7802 return TARGET_XFER_E_IO
;
7804 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7805 send fewer units than we'd planned. */
7806 *xfered_len_units
= (ULONGEST
) units_written
;
7807 return TARGET_XFER_OK
;
7810 /* Write memory data directly to the remote machine.
7811 This does not inform the data cache; the data cache uses this.
7812 MEMADDR is the address in the remote memory space.
7813 MYADDR is the address of the buffer in our space.
7814 LEN is the number of bytes.
7816 Return the transferred status, error or OK (an
7817 'enum target_xfer_status' value). Save the number of bytes
7818 transferred in *XFERED_LEN. Only transfer a single packet. */
7820 static enum target_xfer_status
7821 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7822 int unit_size
, ULONGEST
*xfered_len
)
7824 char *packet_format
= 0;
7826 /* Check whether the target supports binary download. */
7827 check_binary_download (memaddr
);
7829 switch (packet_support (PACKET_X
))
7832 packet_format
= "X";
7834 case PACKET_DISABLE
:
7835 packet_format
= "M";
7837 case PACKET_SUPPORT_UNKNOWN
:
7838 internal_error (__FILE__
, __LINE__
,
7839 _("remote_write_bytes: bad internal state"));
7841 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7844 return remote_write_bytes_aux (packet_format
,
7845 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7846 packet_format
[0], 1);
7849 /* Read memory data directly from the remote machine.
7850 This does not use the data cache; the data cache uses this.
7851 MEMADDR is the address in the remote memory space.
7852 MYADDR is the address of the buffer in our space.
7853 LEN_UNITS is the number of addressable memory units to read..
7854 UNIT_SIZE is the length in bytes of an addressable unit.
7856 Return the transferred status, error or OK (an
7857 'enum target_xfer_status' value). Save the number of bytes
7858 transferred in *XFERED_LEN_UNITS.
7860 See the comment of remote_write_bytes_aux for an example of
7861 memory read/write exchange between gdb and the stub. */
7863 static enum target_xfer_status
7864 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7865 int unit_size
, ULONGEST
*xfered_len_units
)
7867 struct remote_state
*rs
= get_remote_state ();
7868 int buf_size_bytes
; /* Max size of packet output buffer. */
7873 buf_size_bytes
= get_memory_read_packet_size ();
7874 /* The packet buffer will be large enough for the payload;
7875 get_memory_packet_size ensures this. */
7877 /* Number of units that will fit. */
7878 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7880 /* Construct "m"<memaddr>","<len>". */
7881 memaddr
= remote_address_masked (memaddr
);
7884 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7886 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7889 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7890 if (rs
->buf
[0] == 'E'
7891 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7892 && rs
->buf
[3] == '\0')
7893 return TARGET_XFER_E_IO
;
7894 /* Reply describes memory byte by byte, each byte encoded as two hex
7897 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7898 /* Return what we have. Let higher layers handle partial reads. */
7899 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7900 return TARGET_XFER_OK
;
7903 /* Using the set of read-only target sections of remote, read live
7906 For interface/parameters/return description see target.h,
7909 static enum target_xfer_status
7910 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7911 ULONGEST memaddr
, ULONGEST len
,
7912 int unit_size
, ULONGEST
*xfered_len
)
7914 struct target_section
*secp
;
7915 struct target_section_table
*table
;
7917 secp
= target_section_by_addr (ops
, memaddr
);
7919 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7920 secp
->the_bfd_section
)
7923 struct target_section
*p
;
7924 ULONGEST memend
= memaddr
+ len
;
7926 table
= target_get_section_table (ops
);
7928 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7930 if (memaddr
>= p
->addr
)
7932 if (memend
<= p
->endaddr
)
7934 /* Entire transfer is within this section. */
7935 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7938 else if (memaddr
>= p
->endaddr
)
7940 /* This section ends before the transfer starts. */
7945 /* This section overlaps the transfer. Just do half. */
7946 len
= p
->endaddr
- memaddr
;
7947 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7954 return TARGET_XFER_EOF
;
7957 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7958 first if the requested memory is unavailable in traceframe.
7959 Otherwise, fall back to remote_read_bytes_1. */
7961 static enum target_xfer_status
7962 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7963 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7964 ULONGEST
*xfered_len
)
7967 return TARGET_XFER_EOF
;
7969 if (get_traceframe_number () != -1)
7971 VEC(mem_range_s
) *available
;
7973 /* If we fail to get the set of available memory, then the
7974 target does not support querying traceframe info, and so we
7975 attempt reading from the traceframe anyway (assuming the
7976 target implements the old QTro packet then). */
7977 if (traceframe_available_memory (&available
, memaddr
, len
))
7979 struct cleanup
*old_chain
;
7981 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7983 if (VEC_empty (mem_range_s
, available
)
7984 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7986 enum target_xfer_status res
;
7988 /* Don't read into the traceframe's available
7990 if (!VEC_empty (mem_range_s
, available
))
7992 LONGEST oldlen
= len
;
7994 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7995 gdb_assert (len
<= oldlen
);
7998 do_cleanups (old_chain
);
8000 /* This goes through the topmost target again. */
8001 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8002 len
, unit_size
, xfered_len
);
8003 if (res
== TARGET_XFER_OK
)
8004 return TARGET_XFER_OK
;
8007 /* No use trying further, we know some memory starting
8008 at MEMADDR isn't available. */
8010 return TARGET_XFER_UNAVAILABLE
;
8014 /* Don't try to read more than how much is available, in
8015 case the target implements the deprecated QTro packet to
8016 cater for older GDBs (the target's knowledge of read-only
8017 sections may be outdated by now). */
8018 len
= VEC_index (mem_range_s
, available
, 0)->length
;
8020 do_cleanups (old_chain
);
8024 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8029 /* Sends a packet with content determined by the printf format string
8030 FORMAT and the remaining arguments, then gets the reply. Returns
8031 whether the packet was a success, a failure, or unknown. */
8033 static enum packet_result
remote_send_printf (const char *format
, ...)
8034 ATTRIBUTE_PRINTF (1, 2);
8036 static enum packet_result
8037 remote_send_printf (const char *format
, ...)
8039 struct remote_state
*rs
= get_remote_state ();
8040 int max_size
= get_remote_packet_size ();
8043 va_start (ap
, format
);
8046 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8047 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8049 if (putpkt (rs
->buf
) < 0)
8050 error (_("Communication problem with target."));
8053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8055 return packet_check_result (rs
->buf
);
8059 restore_remote_timeout (void *p
)
8061 int value
= *(int *)p
;
8063 remote_timeout
= value
;
8066 /* Flash writing can take quite some time. We'll set
8067 effectively infinite timeout for flash operations.
8068 In future, we'll need to decide on a better approach. */
8069 static const int remote_flash_timeout
= 1000;
8072 remote_flash_erase (struct target_ops
*ops
,
8073 ULONGEST address
, LONGEST length
)
8075 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8076 int saved_remote_timeout
= remote_timeout
;
8077 enum packet_result ret
;
8078 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8079 &saved_remote_timeout
);
8081 remote_timeout
= remote_flash_timeout
;
8083 ret
= remote_send_printf ("vFlashErase:%s,%s",
8084 phex (address
, addr_size
),
8088 case PACKET_UNKNOWN
:
8089 error (_("Remote target does not support flash erase"));
8091 error (_("Error erasing flash with vFlashErase packet"));
8096 do_cleanups (back_to
);
8099 static enum target_xfer_status
8100 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8101 ULONGEST length
, ULONGEST
*xfered_len
,
8102 const gdb_byte
*data
)
8104 int saved_remote_timeout
= remote_timeout
;
8105 enum target_xfer_status ret
;
8106 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8107 &saved_remote_timeout
);
8109 remote_timeout
= remote_flash_timeout
;
8110 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8112 do_cleanups (back_to
);
8118 remote_flash_done (struct target_ops
*ops
)
8120 int saved_remote_timeout
= remote_timeout
;
8122 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8123 &saved_remote_timeout
);
8125 remote_timeout
= remote_flash_timeout
;
8126 ret
= remote_send_printf ("vFlashDone");
8127 do_cleanups (back_to
);
8131 case PACKET_UNKNOWN
:
8132 error (_("Remote target does not support vFlashDone"));
8134 error (_("Error finishing flash operation"));
8141 remote_files_info (struct target_ops
*ignore
)
8143 puts_filtered ("Debugging a target over a serial line.\n");
8146 /* Stuff for dealing with the packets which are part of this protocol.
8147 See comment at top of file for details. */
8149 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8150 error to higher layers. Called when a serial error is detected.
8151 The exception message is STRING, followed by a colon and a blank,
8152 the system error message for errno at function entry and final dot
8153 for output compatibility with throw_perror_with_name. */
8156 unpush_and_perror (const char *string
)
8158 int saved_errno
= errno
;
8160 remote_unpush_target ();
8161 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8162 safe_strerror (saved_errno
));
8165 /* Read a single character from the remote end. */
8168 readchar (int timeout
)
8171 struct remote_state
*rs
= get_remote_state ();
8173 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8178 switch ((enum serial_rc
) ch
)
8181 remote_unpush_target ();
8182 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8185 unpush_and_perror (_("Remote communication error. "
8186 "Target disconnected."));
8188 case SERIAL_TIMEOUT
:
8194 /* Wrapper for serial_write that closes the target and throws if
8198 remote_serial_write (const char *str
, int len
)
8200 struct remote_state
*rs
= get_remote_state ();
8202 if (serial_write (rs
->remote_desc
, str
, len
))
8204 unpush_and_perror (_("Remote communication error. "
8205 "Target disconnected."));
8209 /* Send the command in *BUF to the remote machine, and read the reply
8210 into *BUF. Report an error if we get an error reply. Resize
8211 *BUF using xrealloc if necessary to hold the result, and update
8215 remote_send (char **buf
,
8219 getpkt (buf
, sizeof_buf
, 0);
8221 if ((*buf
)[0] == 'E')
8222 error (_("Remote failure reply: %s"), *buf
);
8225 /* Return a pointer to an xmalloc'ed string representing an escaped
8226 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8227 etc. The caller is responsible for releasing the returned
8231 escape_buffer (const char *buf
, int n
)
8233 struct cleanup
*old_chain
;
8234 struct ui_file
*stb
;
8237 stb
= mem_fileopen ();
8238 old_chain
= make_cleanup_ui_file_delete (stb
);
8240 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8241 str
= ui_file_xstrdup (stb
, NULL
);
8242 do_cleanups (old_chain
);
8246 /* Display a null-terminated packet on stdout, for debugging, using C
8250 print_packet (const char *buf
)
8252 puts_filtered ("\"");
8253 fputstr_filtered (buf
, '"', gdb_stdout
);
8254 puts_filtered ("\"");
8258 putpkt (const char *buf
)
8260 return putpkt_binary (buf
, strlen (buf
));
8263 /* Send a packet to the remote machine, with error checking. The data
8264 of the packet is in BUF. The string in BUF can be at most
8265 get_remote_packet_size () - 5 to account for the $, # and checksum,
8266 and for a possible /0 if we are debugging (remote_debug) and want
8267 to print the sent packet as a string. */
8270 putpkt_binary (const char *buf
, int cnt
)
8272 struct remote_state
*rs
= get_remote_state ();
8274 unsigned char csum
= 0;
8275 char *buf2
= (char *) xmalloc (cnt
+ 6);
8276 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8282 /* Catch cases like trying to read memory or listing threads while
8283 we're waiting for a stop reply. The remote server wouldn't be
8284 ready to handle this request, so we'd hang and timeout. We don't
8285 have to worry about this in synchronous mode, because in that
8286 case it's not possible to issue a command while the target is
8287 running. This is not a problem in non-stop mode, because in that
8288 case, the stub is always ready to process serial input. */
8289 if (!target_is_non_stop_p ()
8290 && target_is_async_p ()
8291 && rs
->waiting_for_stop_reply
)
8293 error (_("Cannot execute this command while the target is running.\n"
8294 "Use the \"interrupt\" command to stop the target\n"
8295 "and then try again."));
8298 /* We're sending out a new packet. Make sure we don't look at a
8299 stale cached response. */
8300 rs
->cached_wait_status
= 0;
8302 /* Copy the packet into buffer BUF2, encapsulating it
8303 and giving it a checksum. */
8308 for (i
= 0; i
< cnt
; i
++)
8314 *p
++ = tohex ((csum
>> 4) & 0xf);
8315 *p
++ = tohex (csum
& 0xf);
8317 /* Send it over and over until we get a positive ack. */
8321 int started_error_output
= 0;
8325 struct cleanup
*old_chain
;
8329 str
= escape_buffer (buf2
, p
- buf2
);
8330 old_chain
= make_cleanup (xfree
, str
);
8331 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8332 gdb_flush (gdb_stdlog
);
8333 do_cleanups (old_chain
);
8335 remote_serial_write (buf2
, p
- buf2
);
8337 /* If this is a no acks version of the remote protocol, send the
8338 packet and move on. */
8342 /* Read until either a timeout occurs (-2) or '+' is read.
8343 Handle any notification that arrives in the mean time. */
8346 ch
= readchar (remote_timeout
);
8354 case SERIAL_TIMEOUT
:
8357 if (started_error_output
)
8359 putchar_unfiltered ('\n');
8360 started_error_output
= 0;
8369 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8370 do_cleanups (old_chain
);
8374 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8376 case SERIAL_TIMEOUT
:
8380 do_cleanups (old_chain
);
8383 break; /* Retransmit buffer. */
8387 fprintf_unfiltered (gdb_stdlog
,
8388 "Packet instead of Ack, ignoring it\n");
8389 /* It's probably an old response sent because an ACK
8390 was lost. Gobble up the packet and ack it so it
8391 doesn't get retransmitted when we resend this
8394 remote_serial_write ("+", 1);
8395 continue; /* Now, go look for +. */
8402 /* If we got a notification, handle it, and go back to looking
8404 /* We've found the start of a notification. Now
8405 collect the data. */
8406 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8411 struct cleanup
*old_chain
;
8414 str
= escape_buffer (rs
->buf
, val
);
8415 old_chain
= make_cleanup (xfree
, str
);
8416 fprintf_unfiltered (gdb_stdlog
,
8417 " Notification received: %s\n",
8419 do_cleanups (old_chain
);
8421 handle_notification (rs
->notif_state
, rs
->buf
);
8422 /* We're in sync now, rewait for the ack. */
8429 if (!started_error_output
)
8431 started_error_output
= 1;
8432 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8434 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8435 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8444 if (!started_error_output
)
8446 started_error_output
= 1;
8447 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8449 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8453 break; /* Here to retransmit. */
8457 /* This is wrong. If doing a long backtrace, the user should be
8458 able to get out next time we call QUIT, without anything as
8459 violent as interrupt_query. If we want to provide a way out of
8460 here without getting to the next QUIT, it should be based on
8461 hitting ^C twice as in remote_wait. */
8470 do_cleanups (old_chain
);
8474 /* Come here after finding the start of a frame when we expected an
8475 ack. Do our best to discard the rest of this packet. */
8484 c
= readchar (remote_timeout
);
8487 case SERIAL_TIMEOUT
:
8488 /* Nothing we can do. */
8491 /* Discard the two bytes of checksum and stop. */
8492 c
= readchar (remote_timeout
);
8494 c
= readchar (remote_timeout
);
8497 case '*': /* Run length encoding. */
8498 /* Discard the repeat count. */
8499 c
= readchar (remote_timeout
);
8504 /* A regular character. */
8510 /* Come here after finding the start of the frame. Collect the rest
8511 into *BUF, verifying the checksum, length, and handling run-length
8512 compression. NUL terminate the buffer. If there is not enough room,
8513 expand *BUF using xrealloc.
8515 Returns -1 on error, number of characters in buffer (ignoring the
8516 trailing NULL) on success. (could be extended to return one of the
8517 SERIAL status indications). */
8520 read_frame (char **buf_p
,
8527 struct remote_state
*rs
= get_remote_state ();
8534 c
= readchar (remote_timeout
);
8537 case SERIAL_TIMEOUT
:
8539 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8543 fputs_filtered ("Saw new packet start in middle of old one\n",
8545 return -1; /* Start a new packet, count retries. */
8548 unsigned char pktcsum
;
8554 check_0
= readchar (remote_timeout
);
8556 check_1
= readchar (remote_timeout
);
8558 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8561 fputs_filtered ("Timeout in checksum, retrying\n",
8565 else if (check_0
< 0 || check_1
< 0)
8568 fputs_filtered ("Communication error in checksum\n",
8573 /* Don't recompute the checksum; with no ack packets we
8574 don't have any way to indicate a packet retransmission
8579 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8580 if (csum
== pktcsum
)
8585 struct cleanup
*old_chain
;
8588 str
= escape_buffer (buf
, bc
);
8589 old_chain
= make_cleanup (xfree
, str
);
8590 fprintf_unfiltered (gdb_stdlog
,
8591 "Bad checksum, sentsum=0x%x, "
8592 "csum=0x%x, buf=%s\n",
8593 pktcsum
, csum
, str
);
8594 do_cleanups (old_chain
);
8596 /* Number of characters in buffer ignoring trailing
8600 case '*': /* Run length encoding. */
8605 c
= readchar (remote_timeout
);
8607 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8609 /* The character before ``*'' is repeated. */
8611 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8613 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8615 /* Make some more room in the buffer. */
8616 *sizeof_buf
+= repeat
;
8617 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8621 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8627 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8631 if (bc
>= *sizeof_buf
- 1)
8633 /* Make some more room in the buffer. */
8635 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8646 /* Read a packet from the remote machine, with error checking, and
8647 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8648 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8649 rather than timing out; this is used (in synchronous mode) to wait
8650 for a target that is is executing user code to stop. */
8651 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8652 don't have to change all the calls to getpkt to deal with the
8653 return value, because at the moment I don't know what the right
8654 thing to do it for those. */
8660 getpkt_sane (buf
, sizeof_buf
, forever
);
8664 /* Read a packet from the remote machine, with error checking, and
8665 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8666 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8667 rather than timing out; this is used (in synchronous mode) to wait
8668 for a target that is is executing user code to stop. If FOREVER ==
8669 0, this function is allowed to time out gracefully and return an
8670 indication of this to the caller. Otherwise return the number of
8671 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8672 enough reason to return to the caller. *IS_NOTIF is an output
8673 boolean that indicates whether *BUF holds a notification or not
8674 (a regular packet). */
8677 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8678 int expecting_notif
, int *is_notif
)
8680 struct remote_state
*rs
= get_remote_state ();
8686 /* We're reading a new response. Make sure we don't look at a
8687 previously cached response. */
8688 rs
->cached_wait_status
= 0;
8690 strcpy (*buf
, "timeout");
8693 timeout
= watchdog
> 0 ? watchdog
: -1;
8694 else if (expecting_notif
)
8695 timeout
= 0; /* There should already be a char in the buffer. If
8698 timeout
= remote_timeout
;
8702 /* Process any number of notifications, and then return when
8706 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8708 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8710 /* This can loop forever if the remote side sends us
8711 characters continuously, but if it pauses, we'll get
8712 SERIAL_TIMEOUT from readchar because of timeout. Then
8713 we'll count that as a retry.
8715 Note that even when forever is set, we will only wait
8716 forever prior to the start of a packet. After that, we
8717 expect characters to arrive at a brisk pace. They should
8718 show up within remote_timeout intervals. */
8720 c
= readchar (timeout
);
8721 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8723 if (c
== SERIAL_TIMEOUT
)
8725 if (expecting_notif
)
8726 return -1; /* Don't complain, it's normal to not get
8727 anything in this case. */
8729 if (forever
) /* Watchdog went off? Kill the target. */
8732 remote_unpush_target ();
8733 throw_error (TARGET_CLOSE_ERROR
,
8734 _("Watchdog timeout has expired. "
8735 "Target detached."));
8738 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8742 /* We've found the start of a packet or notification.
8743 Now collect the data. */
8744 val
= read_frame (buf
, sizeof_buf
);
8749 remote_serial_write ("-", 1);
8752 if (tries
> MAX_TRIES
)
8754 /* We have tried hard enough, and just can't receive the
8755 packet/notification. Give up. */
8756 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8758 /* Skip the ack char if we're in no-ack mode. */
8759 if (!rs
->noack_mode
)
8760 remote_serial_write ("+", 1);
8764 /* If we got an ordinary packet, return that to our caller. */
8769 struct cleanup
*old_chain
;
8772 str
= escape_buffer (*buf
, val
);
8773 old_chain
= make_cleanup (xfree
, str
);
8774 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8775 do_cleanups (old_chain
);
8778 /* Skip the ack char if we're in no-ack mode. */
8779 if (!rs
->noack_mode
)
8780 remote_serial_write ("+", 1);
8781 if (is_notif
!= NULL
)
8786 /* If we got a notification, handle it, and go back to looking
8790 gdb_assert (c
== '%');
8794 struct cleanup
*old_chain
;
8797 str
= escape_buffer (*buf
, val
);
8798 old_chain
= make_cleanup (xfree
, str
);
8799 fprintf_unfiltered (gdb_stdlog
,
8800 " Notification received: %s\n",
8802 do_cleanups (old_chain
);
8804 if (is_notif
!= NULL
)
8807 handle_notification (rs
->notif_state
, *buf
);
8809 /* Notifications require no acknowledgement. */
8811 if (expecting_notif
)
8818 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8820 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8824 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8827 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8831 /* Check whether EVENT is a fork event for the process specified
8832 by the pid passed in DATA, and if it is, kill the fork child. */
8835 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8836 QUEUE_ITER (stop_reply_p
) *iter
,
8840 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8841 int parent_pid
= *(int *) param
->input
;
8843 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8845 struct remote_state
*rs
= get_remote_state ();
8846 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8849 res
= remote_vkill (child_pid
, rs
);
8851 error (_("Can't kill fork child process %d"), child_pid
);
8857 /* Kill any new fork children of process PID that haven't been
8858 processed by follow_fork. */
8861 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8863 struct thread_info
*thread
;
8864 struct notif_client
*notif
= ¬if_client_stop
;
8865 struct queue_iter_param param
;
8867 /* Kill the fork child threads of any threads in process PID
8868 that are stopped at a fork event. */
8869 ALL_NON_EXITED_THREADS (thread
)
8871 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8873 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8875 struct remote_state
*rs
= get_remote_state ();
8876 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8879 res
= remote_vkill (child_pid
, rs
);
8881 error (_("Can't kill fork child process %d"), child_pid
);
8885 /* Check for any pending fork events (not reported or processed yet)
8886 in process PID and kill those fork child threads as well. */
8887 remote_notif_get_pending_events (notif
);
8889 param
.output
= NULL
;
8890 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8891 kill_child_of_pending_fork
, ¶m
);
8895 /* Target hook to kill the current inferior. */
8898 remote_kill (struct target_ops
*ops
)
8901 int pid
= ptid_get_pid (inferior_ptid
);
8902 struct remote_state
*rs
= get_remote_state ();
8904 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
8906 /* If we're stopped while forking and we haven't followed yet,
8907 kill the child task. We need to do this before killing the
8908 parent task because if this is a vfork then the parent will
8910 kill_new_fork_children (pid
, rs
);
8912 res
= remote_vkill (pid
, rs
);
8915 target_mourn_inferior ();
8920 /* If we are in 'target remote' mode and we are killing the only
8921 inferior, then we will tell gdbserver to exit and unpush the
8923 if (res
== -1 && !remote_multi_process_p (rs
)
8924 && number_of_live_inferiors () == 1)
8928 /* We've killed the remote end, we get to mourn it. If we are
8929 not in extended mode, mourning the inferior also unpushes
8930 remote_ops from the target stack, which closes the remote
8932 target_mourn_inferior ();
8937 error (_("Can't kill process"));
8940 /* Send a kill request to the target using the 'vKill' packet. */
8943 remote_vkill (int pid
, struct remote_state
*rs
)
8945 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8948 /* Tell the remote target to detach. */
8949 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8951 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8953 switch (packet_ok (rs
->buf
,
8954 &remote_protocol_packets
[PACKET_vKill
]))
8960 case PACKET_UNKNOWN
:
8963 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8967 /* Send a kill request to the target using the 'k' packet. */
8970 remote_kill_k (void)
8972 /* Catch errors so the user can quit from gdb even when we
8973 aren't on speaking terms with the remote system. */
8978 CATCH (ex
, RETURN_MASK_ERROR
)
8980 if (ex
.error
== TARGET_CLOSE_ERROR
)
8982 /* If we got an (EOF) error that caused the target
8983 to go away, then we're done, that's what we wanted.
8984 "k" is susceptible to cause a premature EOF, given
8985 that the remote server isn't actually required to
8986 reply to "k", and it can happen that it doesn't
8987 even get to reply ACK to the "k". */
8991 /* Otherwise, something went wrong. We didn't actually kill
8992 the target. Just propagate the exception, and let the
8993 user or higher layers decide what to do. */
8994 throw_exception (ex
);
9000 remote_mourn (struct target_ops
*target
)
9002 struct remote_state
*rs
= get_remote_state ();
9004 /* In 'target remote' mode with one inferior, we close the connection. */
9005 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9007 unpush_target (target
);
9009 /* remote_close takes care of doing most of the clean up. */
9010 generic_mourn_inferior ();
9014 /* In case we got here due to an error, but we're going to stay
9016 rs
->waiting_for_stop_reply
= 0;
9018 /* If the current general thread belonged to the process we just
9019 detached from or has exited, the remote side current general
9020 thread becomes undefined. Considering a case like this:
9022 - We just got here due to a detach.
9023 - The process that we're detaching from happens to immediately
9024 report a global breakpoint being hit in non-stop mode, in the
9025 same thread we had selected before.
9026 - GDB attaches to this process again.
9027 - This event happens to be the next event we handle.
9029 GDB would consider that the current general thread didn't need to
9030 be set on the stub side (with Hg), since for all it knew,
9031 GENERAL_THREAD hadn't changed.
9033 Notice that although in all-stop mode, the remote server always
9034 sets the current thread to the thread reporting the stop event,
9035 that doesn't happen in non-stop mode; in non-stop, the stub *must
9036 not* change the current thread when reporting a breakpoint hit,
9037 due to the decoupling of event reporting and event handling.
9039 To keep things simple, we always invalidate our notion of the
9041 record_currthread (rs
, minus_one_ptid
);
9043 /* Call common code to mark the inferior as not running. */
9044 generic_mourn_inferior ();
9046 if (!have_inferiors ())
9048 if (!remote_multi_process_p (rs
))
9050 /* Check whether the target is running now - some remote stubs
9051 automatically restart after kill. */
9053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9055 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9057 /* Assume that the target has been restarted. Set
9058 inferior_ptid so that bits of core GDB realizes
9059 there's something here, e.g., so that the user can
9060 say "kill" again. */
9061 inferior_ptid
= magic_null_ptid
;
9068 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9070 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9074 extended_remote_disable_randomization (int val
)
9076 struct remote_state
*rs
= get_remote_state ();
9079 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9082 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9084 error (_("Target does not support QDisableRandomization."));
9085 if (strcmp (reply
, "OK") != 0)
9086 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9090 extended_remote_run (char *args
)
9092 struct remote_state
*rs
= get_remote_state ();
9094 const char *remote_exec_file
= get_remote_exec_file ();
9096 /* If the user has disabled vRun support, or we have detected that
9097 support is not available, do not try it. */
9098 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9101 strcpy (rs
->buf
, "vRun;");
9102 len
= strlen (rs
->buf
);
9104 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9105 error (_("Remote file name too long for run packet"));
9106 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9107 strlen (remote_exec_file
));
9109 gdb_assert (args
!= NULL
);
9112 struct cleanup
*back_to
;
9116 argv
= gdb_buildargv (args
);
9117 back_to
= make_cleanup_freeargv (argv
);
9118 for (i
= 0; argv
[i
] != NULL
; i
++)
9120 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9121 error (_("Argument list too long for run packet"));
9122 rs
->buf
[len
++] = ';';
9123 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9126 do_cleanups (back_to
);
9129 rs
->buf
[len
++] = '\0';
9132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9134 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9137 /* We have a wait response. All is well. */
9139 case PACKET_UNKNOWN
:
9142 if (remote_exec_file
[0] == '\0')
9143 error (_("Running the default executable on the remote target failed; "
9144 "try \"set remote exec-file\"?"));
9146 error (_("Running \"%s\" on the remote target failed"),
9149 gdb_assert_not_reached (_("bad switch"));
9153 /* In the extended protocol we want to be able to do things like
9154 "run" and have them basically work as expected. So we need
9155 a special create_inferior function. We support changing the
9156 executable file and the command line arguments, but not the
9160 extended_remote_create_inferior (struct target_ops
*ops
,
9161 char *exec_file
, char *args
,
9162 char **env
, int from_tty
)
9166 struct remote_state
*rs
= get_remote_state ();
9167 const char *remote_exec_file
= get_remote_exec_file ();
9169 /* If running asynchronously, register the target file descriptor
9170 with the event loop. */
9171 if (target_can_async_p ())
9174 /* Disable address space randomization if requested (and supported). */
9175 if (extended_remote_supports_disable_randomization (ops
))
9176 extended_remote_disable_randomization (disable_randomization
);
9178 /* Now restart the remote server. */
9179 run_worked
= extended_remote_run (args
) != -1;
9182 /* vRun was not supported. Fail if we need it to do what the
9184 if (remote_exec_file
[0])
9185 error (_("Remote target does not support \"set remote exec-file\""));
9187 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9189 /* Fall back to "R". */
9190 extended_remote_restart ();
9193 if (!have_inferiors ())
9195 /* Clean up from the last time we ran, before we mark the target
9196 running again. This will mark breakpoints uninserted, and
9197 get_offsets may insert breakpoints. */
9198 init_thread_list ();
9199 init_wait_for_inferior ();
9202 /* vRun's success return is a stop reply. */
9203 stop_reply
= run_worked
? rs
->buf
: NULL
;
9204 add_current_inferior_and_thread (stop_reply
);
9206 /* Get updated offsets, if the stub uses qOffsets. */
9211 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9212 the list of conditions (in agent expression bytecode format), if any, the
9213 target needs to evaluate. The output is placed into the packet buffer
9214 started from BUF and ended at BUF_END. */
9217 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9218 struct bp_target_info
*bp_tgt
, char *buf
,
9221 struct agent_expr
*aexpr
= NULL
;
9224 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9227 buf
+= strlen (buf
);
9228 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9231 /* Send conditions to the target and free the vector. */
9233 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9236 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9237 buf
+= strlen (buf
);
9238 for (i
= 0; i
< aexpr
->len
; ++i
)
9239 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9246 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9247 struct bp_target_info
*bp_tgt
, char *buf
)
9249 struct agent_expr
*aexpr
= NULL
;
9252 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9255 buf
+= strlen (buf
);
9257 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9258 buf
+= strlen (buf
);
9260 /* Concatenate all the agent expressions that are commands into the
9263 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9266 sprintf (buf
, "X%x,", aexpr
->len
);
9267 buf
+= strlen (buf
);
9268 for (i
= 0; i
< aexpr
->len
; ++i
)
9269 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9274 /* Insert a breakpoint. On targets that have software breakpoint
9275 support, we ask the remote target to do the work; on targets
9276 which don't, we insert a traditional memory breakpoint. */
9279 remote_insert_breakpoint (struct target_ops
*ops
,
9280 struct gdbarch
*gdbarch
,
9281 struct bp_target_info
*bp_tgt
)
9283 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9284 If it succeeds, then set the support to PACKET_ENABLE. If it
9285 fails, and the user has explicitly requested the Z support then
9286 report an error, otherwise, mark it disabled and go on. */
9288 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9290 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9291 struct remote_state
*rs
;
9295 /* Make sure the remote is pointing at the right process, if
9297 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9298 set_general_process ();
9300 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9302 rs
= get_remote_state ();
9304 endbuf
= rs
->buf
+ get_remote_packet_size ();
9309 addr
= (ULONGEST
) remote_address_masked (addr
);
9310 p
+= hexnumstr (p
, addr
);
9311 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
9313 if (remote_supports_cond_breakpoints (ops
))
9314 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9316 if (remote_can_run_breakpoint_commands (ops
))
9317 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9320 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9322 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9327 bp_tgt
->placed_address
= addr
;
9328 bp_tgt
->placed_size
= bpsize
;
9330 case PACKET_UNKNOWN
:
9335 /* If this breakpoint has target-side commands but this stub doesn't
9336 support Z0 packets, throw error. */
9337 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9338 throw_error (NOT_SUPPORTED_ERROR
, _("\
9339 Target doesn't support breakpoints that have target side commands."));
9341 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9345 remote_remove_breakpoint (struct target_ops
*ops
,
9346 struct gdbarch
*gdbarch
,
9347 struct bp_target_info
*bp_tgt
)
9349 CORE_ADDR addr
= bp_tgt
->placed_address
;
9350 struct remote_state
*rs
= get_remote_state ();
9352 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9355 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9357 /* Make sure the remote is pointing at the right process, if
9359 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9360 set_general_process ();
9366 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9367 p
+= hexnumstr (p
, addr
);
9368 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9371 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9373 return (rs
->buf
[0] == 'E');
9376 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9379 static enum Z_packet_type
9380 watchpoint_to_Z_packet (int type
)
9385 return Z_PACKET_WRITE_WP
;
9388 return Z_PACKET_READ_WP
;
9391 return Z_PACKET_ACCESS_WP
;
9394 internal_error (__FILE__
, __LINE__
,
9395 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9400 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9401 enum target_hw_bp_type type
, struct expression
*cond
)
9403 struct remote_state
*rs
= get_remote_state ();
9404 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9406 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9408 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9411 /* Make sure the remote is pointing at the right process, if
9413 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9414 set_general_process ();
9416 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9417 p
= strchr (rs
->buf
, '\0');
9418 addr
= remote_address_masked (addr
);
9419 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9420 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9423 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9425 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9429 case PACKET_UNKNOWN
:
9434 internal_error (__FILE__
, __LINE__
,
9435 _("remote_insert_watchpoint: reached end of function"));
9439 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9440 CORE_ADDR start
, int length
)
9442 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9444 return diff
< length
;
9449 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9450 enum target_hw_bp_type type
, struct expression
*cond
)
9452 struct remote_state
*rs
= get_remote_state ();
9453 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9455 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9457 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9460 /* Make sure the remote is pointing at the right process, if
9462 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9463 set_general_process ();
9465 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9466 p
= strchr (rs
->buf
, '\0');
9467 addr
= remote_address_masked (addr
);
9468 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9469 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9471 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9473 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9476 case PACKET_UNKNOWN
:
9481 internal_error (__FILE__
, __LINE__
,
9482 _("remote_remove_watchpoint: reached end of function"));
9486 int remote_hw_watchpoint_limit
= -1;
9487 int remote_hw_watchpoint_length_limit
= -1;
9488 int remote_hw_breakpoint_limit
= -1;
9491 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9492 CORE_ADDR addr
, int len
)
9494 if (remote_hw_watchpoint_length_limit
== 0)
9496 else if (remote_hw_watchpoint_length_limit
< 0)
9498 else if (len
<= remote_hw_watchpoint_length_limit
)
9505 remote_check_watch_resources (struct target_ops
*self
,
9506 enum bptype type
, int cnt
, int ot
)
9508 if (type
== bp_hardware_breakpoint
)
9510 if (remote_hw_breakpoint_limit
== 0)
9512 else if (remote_hw_breakpoint_limit
< 0)
9514 else if (cnt
<= remote_hw_breakpoint_limit
)
9519 if (remote_hw_watchpoint_limit
== 0)
9521 else if (remote_hw_watchpoint_limit
< 0)
9525 else if (cnt
<= remote_hw_watchpoint_limit
)
9531 /* The to_stopped_by_sw_breakpoint method of target remote. */
9534 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9536 struct thread_info
*thread
= inferior_thread ();
9538 return (thread
->priv
!= NULL
9539 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9542 /* The to_supports_stopped_by_sw_breakpoint method of target
9546 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9548 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9551 /* The to_stopped_by_hw_breakpoint method of target remote. */
9554 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9556 struct thread_info
*thread
= inferior_thread ();
9558 return (thread
->priv
!= NULL
9559 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9562 /* The to_supports_stopped_by_hw_breakpoint method of target
9566 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9568 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9572 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9574 struct thread_info
*thread
= inferior_thread ();
9576 return (thread
->priv
!= NULL
9577 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9581 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9583 struct thread_info
*thread
= inferior_thread ();
9585 if (thread
->priv
!= NULL
9586 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9588 *addr_p
= thread
->priv
->watch_data_address
;
9597 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9598 struct bp_target_info
*bp_tgt
)
9600 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9601 struct remote_state
*rs
;
9606 /* The length field should be set to the size of a breakpoint
9607 instruction, even though we aren't inserting one ourselves. */
9609 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9611 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9614 /* Make sure the remote is pointing at the right process, if
9616 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9617 set_general_process ();
9619 rs
= get_remote_state ();
9621 endbuf
= rs
->buf
+ get_remote_packet_size ();
9627 addr
= remote_address_masked (addr
);
9628 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9629 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9631 if (remote_supports_cond_breakpoints (self
))
9632 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9634 if (remote_can_run_breakpoint_commands (self
))
9635 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9638 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9640 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9643 if (rs
->buf
[1] == '.')
9645 message
= strchr (rs
->buf
+ 2, '.');
9647 error (_("Remote failure reply: %s"), message
+ 1);
9650 case PACKET_UNKNOWN
:
9653 bp_tgt
->placed_address
= addr
;
9654 bp_tgt
->placed_size
= bpsize
;
9657 internal_error (__FILE__
, __LINE__
,
9658 _("remote_insert_hw_breakpoint: reached end of function"));
9663 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9664 struct bp_target_info
*bp_tgt
)
9667 struct remote_state
*rs
= get_remote_state ();
9669 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9671 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9674 /* Make sure the remote is pointing at the right process, if
9676 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9677 set_general_process ();
9683 addr
= remote_address_masked (bp_tgt
->placed_address
);
9684 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9685 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9688 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9690 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9693 case PACKET_UNKNOWN
:
9698 internal_error (__FILE__
, __LINE__
,
9699 _("remote_remove_hw_breakpoint: reached end of function"));
9702 /* Verify memory using the "qCRC:" request. */
9705 remote_verify_memory (struct target_ops
*ops
,
9706 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9708 struct remote_state
*rs
= get_remote_state ();
9709 unsigned long host_crc
, target_crc
;
9712 /* It doesn't make sense to use qCRC if the remote target is
9713 connected but not running. */
9714 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9716 enum packet_result result
;
9718 /* Make sure the remote is pointing at the right process. */
9719 set_general_process ();
9721 /* FIXME: assumes lma can fit into long. */
9722 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9723 (long) lma
, (long) size
);
9726 /* Be clever; compute the host_crc before waiting for target
9728 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9730 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9732 result
= packet_ok (rs
->buf
,
9733 &remote_protocol_packets
[PACKET_qCRC
]);
9734 if (result
== PACKET_ERROR
)
9736 else if (result
== PACKET_OK
)
9738 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9739 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9741 return (host_crc
== target_crc
);
9745 return simple_verify_memory (ops
, data
, lma
, size
);
9748 /* compare-sections command
9750 With no arguments, compares each loadable section in the exec bfd
9751 with the same memory range on the target, and reports mismatches.
9752 Useful for verifying the image on the target against the exec file. */
9755 compare_sections_command (char *args
, int from_tty
)
9758 struct cleanup
*old_chain
;
9760 const char *sectname
;
9769 error (_("command cannot be used without an exec file"));
9771 /* Make sure the remote is pointing at the right process. */
9772 set_general_process ();
9774 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9780 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9782 if (!(s
->flags
& SEC_LOAD
))
9783 continue; /* Skip non-loadable section. */
9785 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9786 continue; /* Skip writeable sections */
9788 size
= bfd_get_section_size (s
);
9790 continue; /* Skip zero-length section. */
9792 sectname
= bfd_get_section_name (exec_bfd
, s
);
9793 if (args
&& strcmp (args
, sectname
) != 0)
9794 continue; /* Not the section selected by user. */
9796 matched
= 1; /* Do this section. */
9799 sectdata
= (gdb_byte
*) xmalloc (size
);
9800 old_chain
= make_cleanup (xfree
, sectdata
);
9801 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9803 res
= target_verify_memory (sectdata
, lma
, size
);
9806 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9807 paddress (target_gdbarch (), lma
),
9808 paddress (target_gdbarch (), lma
+ size
));
9810 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9811 paddress (target_gdbarch (), lma
),
9812 paddress (target_gdbarch (), lma
+ size
));
9814 printf_filtered ("matched.\n");
9817 printf_filtered ("MIS-MATCHED!\n");
9821 do_cleanups (old_chain
);
9824 warning (_("One or more sections of the target image does not match\n\
9825 the loaded file\n"));
9826 if (args
&& !matched
)
9827 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9830 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9831 into remote target. The number of bytes written to the remote
9832 target is returned, or -1 for error. */
9834 static enum target_xfer_status
9835 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9836 const char *annex
, const gdb_byte
*writebuf
,
9837 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9838 struct packet_config
*packet
)
9842 struct remote_state
*rs
= get_remote_state ();
9843 int max_size
= get_memory_write_packet_size ();
9845 if (packet
->support
== PACKET_DISABLE
)
9846 return TARGET_XFER_E_IO
;
9848 /* Insert header. */
9849 i
= snprintf (rs
->buf
, max_size
,
9850 "qXfer:%s:write:%s:%s:",
9851 object_name
, annex
? annex
: "",
9852 phex_nz (offset
, sizeof offset
));
9853 max_size
-= (i
+ 1);
9855 /* Escape as much data as fits into rs->buf. */
9856 buf_len
= remote_escape_output
9857 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9859 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9860 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9861 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9862 return TARGET_XFER_E_IO
;
9864 unpack_varlen_hex (rs
->buf
, &n
);
9867 return TARGET_XFER_OK
;
9870 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9871 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9872 number of bytes read is returned, or 0 for EOF, or -1 for error.
9873 The number of bytes read may be less than LEN without indicating an
9874 EOF. PACKET is checked and updated to indicate whether the remote
9875 target supports this object. */
9877 static enum target_xfer_status
9878 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9880 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9881 ULONGEST
*xfered_len
,
9882 struct packet_config
*packet
)
9884 struct remote_state
*rs
= get_remote_state ();
9885 LONGEST i
, n
, packet_len
;
9887 if (packet
->support
== PACKET_DISABLE
)
9888 return TARGET_XFER_E_IO
;
9890 /* Check whether we've cached an end-of-object packet that matches
9892 if (rs
->finished_object
)
9894 if (strcmp (object_name
, rs
->finished_object
) == 0
9895 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9896 && offset
== rs
->finished_offset
)
9897 return TARGET_XFER_EOF
;
9900 /* Otherwise, we're now reading something different. Discard
9902 xfree (rs
->finished_object
);
9903 xfree (rs
->finished_annex
);
9904 rs
->finished_object
= NULL
;
9905 rs
->finished_annex
= NULL
;
9908 /* Request only enough to fit in a single packet. The actual data
9909 may not, since we don't know how much of it will need to be escaped;
9910 the target is free to respond with slightly less data. We subtract
9911 five to account for the response type and the protocol frame. */
9912 n
= min (get_remote_packet_size () - 5, len
);
9913 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9914 object_name
, annex
? annex
: "",
9915 phex_nz (offset
, sizeof offset
),
9916 phex_nz (n
, sizeof n
));
9917 i
= putpkt (rs
->buf
);
9919 return TARGET_XFER_E_IO
;
9922 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9923 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9924 return TARGET_XFER_E_IO
;
9926 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9927 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9929 /* 'm' means there is (or at least might be) more data after this
9930 batch. That does not make sense unless there's at least one byte
9931 of data in this reply. */
9932 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9933 error (_("Remote qXfer reply contained no data."));
9935 /* Got some data. */
9936 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9937 packet_len
- 1, readbuf
, n
);
9939 /* 'l' is an EOF marker, possibly including a final block of data,
9940 or possibly empty. If we have the final block of a non-empty
9941 object, record this fact to bypass a subsequent partial read. */
9942 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9944 rs
->finished_object
= xstrdup (object_name
);
9945 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9946 rs
->finished_offset
= offset
+ i
;
9950 return TARGET_XFER_EOF
;
9954 return TARGET_XFER_OK
;
9958 static enum target_xfer_status
9959 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9960 const char *annex
, gdb_byte
*readbuf
,
9961 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9962 ULONGEST
*xfered_len
)
9964 struct remote_state
*rs
;
9968 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9970 set_remote_traceframe ();
9971 set_general_thread (inferior_ptid
);
9973 rs
= get_remote_state ();
9975 /* Handle memory using the standard memory routines. */
9976 if (object
== TARGET_OBJECT_MEMORY
)
9978 /* If the remote target is connected but not running, we should
9979 pass this request down to a lower stratum (e.g. the executable
9981 if (!target_has_execution
)
9982 return TARGET_XFER_EOF
;
9984 if (writebuf
!= NULL
)
9985 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9988 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9992 /* Handle SPU memory using qxfer packets. */
9993 if (object
== TARGET_OBJECT_SPU
)
9996 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9997 xfered_len
, &remote_protocol_packets
9998 [PACKET_qXfer_spu_read
]);
10000 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
10001 xfered_len
, &remote_protocol_packets
10002 [PACKET_qXfer_spu_write
]);
10005 /* Handle extra signal info using qxfer packets. */
10006 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10009 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10010 xfered_len
, &remote_protocol_packets
10011 [PACKET_qXfer_siginfo_read
]);
10013 return remote_write_qxfer (ops
, "siginfo", annex
,
10014 writebuf
, offset
, len
, xfered_len
,
10015 &remote_protocol_packets
10016 [PACKET_qXfer_siginfo_write
]);
10019 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10022 return remote_read_qxfer (ops
, "statictrace", annex
,
10023 readbuf
, offset
, len
, xfered_len
,
10024 &remote_protocol_packets
10025 [PACKET_qXfer_statictrace_read
]);
10027 return TARGET_XFER_E_IO
;
10030 /* Only handle flash writes. */
10031 if (writebuf
!= NULL
)
10035 case TARGET_OBJECT_FLASH
:
10036 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10040 return TARGET_XFER_E_IO
;
10044 /* Map pre-existing objects onto letters. DO NOT do this for new
10045 objects!!! Instead specify new query packets. */
10048 case TARGET_OBJECT_AVR
:
10052 case TARGET_OBJECT_AUXV
:
10053 gdb_assert (annex
== NULL
);
10054 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10056 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10058 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10059 return remote_read_qxfer
10060 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10061 &remote_protocol_packets
[PACKET_qXfer_features
]);
10063 case TARGET_OBJECT_LIBRARIES
:
10064 return remote_read_qxfer
10065 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10066 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10068 case TARGET_OBJECT_LIBRARIES_SVR4
:
10069 return remote_read_qxfer
10070 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10071 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10073 case TARGET_OBJECT_MEMORY_MAP
:
10074 gdb_assert (annex
== NULL
);
10075 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10077 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10079 case TARGET_OBJECT_OSDATA
:
10080 /* Should only get here if we're connected. */
10081 gdb_assert (rs
->remote_desc
);
10082 return remote_read_qxfer
10083 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10084 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10086 case TARGET_OBJECT_THREADS
:
10087 gdb_assert (annex
== NULL
);
10088 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10090 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10092 case TARGET_OBJECT_TRACEFRAME_INFO
:
10093 gdb_assert (annex
== NULL
);
10094 return remote_read_qxfer
10095 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10096 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10098 case TARGET_OBJECT_FDPIC
:
10099 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10101 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10103 case TARGET_OBJECT_OPENVMS_UIB
:
10104 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10106 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10108 case TARGET_OBJECT_BTRACE
:
10109 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10111 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10113 case TARGET_OBJECT_BTRACE_CONF
:
10114 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10116 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10118 case TARGET_OBJECT_EXEC_FILE
:
10119 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10121 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10124 return TARGET_XFER_E_IO
;
10127 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10128 large enough let the caller deal with it. */
10129 if (len
< get_remote_packet_size ())
10130 return TARGET_XFER_E_IO
;
10131 len
= get_remote_packet_size ();
10133 /* Except for querying the minimum buffer size, target must be open. */
10134 if (!rs
->remote_desc
)
10135 error (_("remote query is only available after target open"));
10137 gdb_assert (annex
!= NULL
);
10138 gdb_assert (readbuf
!= NULL
);
10142 *p2
++ = query_type
;
10144 /* We used one buffer char for the remote protocol q command and
10145 another for the query type. As the remote protocol encapsulation
10146 uses 4 chars plus one extra in case we are debugging
10147 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10150 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10152 /* Bad caller may have sent forbidden characters. */
10153 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10158 gdb_assert (annex
[i
] == '\0');
10160 i
= putpkt (rs
->buf
);
10162 return TARGET_XFER_E_IO
;
10164 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10165 strcpy ((char *) readbuf
, rs
->buf
);
10167 *xfered_len
= strlen ((char *) readbuf
);
10168 return TARGET_XFER_OK
;
10172 remote_search_memory (struct target_ops
* ops
,
10173 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10174 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10175 CORE_ADDR
*found_addrp
)
10177 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10178 struct remote_state
*rs
= get_remote_state ();
10179 int max_size
= get_memory_write_packet_size ();
10180 struct packet_config
*packet
=
10181 &remote_protocol_packets
[PACKET_qSearch_memory
];
10182 /* Number of packet bytes used to encode the pattern;
10183 this could be more than PATTERN_LEN due to escape characters. */
10184 int escaped_pattern_len
;
10185 /* Amount of pattern that was encodable in the packet. */
10186 int used_pattern_len
;
10189 ULONGEST found_addr
;
10191 /* Don't go to the target if we don't have to.
10192 This is done before checking packet->support to avoid the possibility that
10193 a success for this edge case means the facility works in general. */
10194 if (pattern_len
> search_space_len
)
10196 if (pattern_len
== 0)
10198 *found_addrp
= start_addr
;
10202 /* If we already know the packet isn't supported, fall back to the simple
10203 way of searching memory. */
10205 if (packet_config_support (packet
) == PACKET_DISABLE
)
10207 /* Target doesn't provided special support, fall back and use the
10208 standard support (copy memory and do the search here). */
10209 return simple_search_memory (ops
, start_addr
, search_space_len
,
10210 pattern
, pattern_len
, found_addrp
);
10213 /* Make sure the remote is pointing at the right process. */
10214 set_general_process ();
10216 /* Insert header. */
10217 i
= snprintf (rs
->buf
, max_size
,
10218 "qSearch:memory:%s;%s;",
10219 phex_nz (start_addr
, addr_size
),
10220 phex_nz (search_space_len
, sizeof (search_space_len
)));
10221 max_size
-= (i
+ 1);
10223 /* Escape as much data as fits into rs->buf. */
10224 escaped_pattern_len
=
10225 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10226 &used_pattern_len
, max_size
);
10228 /* Bail if the pattern is too large. */
10229 if (used_pattern_len
!= pattern_len
)
10230 error (_("Pattern is too large to transmit to remote target."));
10232 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10233 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10234 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10236 /* The request may not have worked because the command is not
10237 supported. If so, fall back to the simple way. */
10238 if (packet
->support
== PACKET_DISABLE
)
10240 return simple_search_memory (ops
, start_addr
, search_space_len
,
10241 pattern
, pattern_len
, found_addrp
);
10246 if (rs
->buf
[0] == '0')
10248 else if (rs
->buf
[0] == '1')
10251 if (rs
->buf
[1] != ',')
10252 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10253 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10254 *found_addrp
= found_addr
;
10257 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10263 remote_rcmd (struct target_ops
*self
, const char *command
,
10264 struct ui_file
*outbuf
)
10266 struct remote_state
*rs
= get_remote_state ();
10269 if (!rs
->remote_desc
)
10270 error (_("remote rcmd is only available after target open"));
10272 /* Send a NULL command across as an empty command. */
10273 if (command
== NULL
)
10276 /* The query prefix. */
10277 strcpy (rs
->buf
, "qRcmd,");
10278 p
= strchr (rs
->buf
, '\0');
10280 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10281 > get_remote_packet_size ())
10282 error (_("\"monitor\" command ``%s'' is too long."), command
);
10284 /* Encode the actual command. */
10285 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10287 if (putpkt (rs
->buf
) < 0)
10288 error (_("Communication problem with target."));
10290 /* get/display the response */
10295 /* XXX - see also remote_get_noisy_reply(). */
10296 QUIT
; /* Allow user to bail out with ^C. */
10298 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10300 /* Timeout. Continue to (try to) read responses.
10301 This is better than stopping with an error, assuming the stub
10302 is still executing the (long) monitor command.
10303 If needed, the user can interrupt gdb using C-c, obtaining
10304 an effect similar to stop on timeout. */
10308 if (buf
[0] == '\0')
10309 error (_("Target does not support this command."));
10310 if (buf
[0] == 'O' && buf
[1] != 'K')
10312 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10315 if (strcmp (buf
, "OK") == 0)
10317 if (strlen (buf
) == 3 && buf
[0] == 'E'
10318 && isdigit (buf
[1]) && isdigit (buf
[2]))
10320 error (_("Protocol error with Rcmd"));
10322 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10324 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10326 fputc_unfiltered (c
, outbuf
);
10332 static VEC(mem_region_s
) *
10333 remote_memory_map (struct target_ops
*ops
)
10335 VEC(mem_region_s
) *result
= NULL
;
10336 char *text
= target_read_stralloc (¤t_target
,
10337 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10341 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10343 result
= parse_memory_map (text
);
10344 do_cleanups (back_to
);
10351 packet_command (char *args
, int from_tty
)
10353 struct remote_state
*rs
= get_remote_state ();
10355 if (!rs
->remote_desc
)
10356 error (_("command can only be used with remote target"));
10359 error (_("remote-packet command requires packet text as argument"));
10361 puts_filtered ("sending: ");
10362 print_packet (args
);
10363 puts_filtered ("\n");
10366 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10367 puts_filtered ("received: ");
10368 print_packet (rs
->buf
);
10369 puts_filtered ("\n");
10373 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10375 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10377 static void threadset_test_cmd (char *cmd
, int tty
);
10379 static void threadalive_test (char *cmd
, int tty
);
10381 static void threadlist_test_cmd (char *cmd
, int tty
);
10383 int get_and_display_threadinfo (threadref
*ref
);
10385 static void threadinfo_test_cmd (char *cmd
, int tty
);
10387 static int thread_display_step (threadref
*ref
, void *context
);
10389 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10391 static void init_remote_threadtests (void);
10393 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10396 threadset_test_cmd (char *cmd
, int tty
)
10398 int sample_thread
= SAMPLE_THREAD
;
10400 printf_filtered (_("Remote threadset test\n"));
10401 set_general_thread (sample_thread
);
10406 threadalive_test (char *cmd
, int tty
)
10408 int sample_thread
= SAMPLE_THREAD
;
10409 int pid
= ptid_get_pid (inferior_ptid
);
10410 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10412 if (remote_thread_alive (ptid
))
10413 printf_filtered ("PASS: Thread alive test\n");
10415 printf_filtered ("FAIL: Thread alive test\n");
10418 void output_threadid (char *title
, threadref
*ref
);
10421 output_threadid (char *title
, threadref
*ref
)
10425 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10427 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10431 threadlist_test_cmd (char *cmd
, int tty
)
10434 threadref nextthread
;
10435 int done
, result_count
;
10436 threadref threadlist
[3];
10438 printf_filtered ("Remote Threadlist test\n");
10439 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10440 &result_count
, &threadlist
[0]))
10441 printf_filtered ("FAIL: threadlist test\n");
10444 threadref
*scan
= threadlist
;
10445 threadref
*limit
= scan
+ result_count
;
10447 while (scan
< limit
)
10448 output_threadid (" thread ", scan
++);
10453 display_thread_info (struct gdb_ext_thread_info
*info
)
10455 output_threadid ("Threadid: ", &info
->threadid
);
10456 printf_filtered ("Name: %s\n ", info
->shortname
);
10457 printf_filtered ("State: %s\n", info
->display
);
10458 printf_filtered ("other: %s\n\n", info
->more_display
);
10462 get_and_display_threadinfo (threadref
*ref
)
10466 struct gdb_ext_thread_info threadinfo
;
10468 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10469 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10470 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10471 display_thread_info (&threadinfo
);
10476 threadinfo_test_cmd (char *cmd
, int tty
)
10478 int athread
= SAMPLE_THREAD
;
10482 int_to_threadref (&thread
, athread
);
10483 printf_filtered ("Remote Threadinfo test\n");
10484 if (!get_and_display_threadinfo (&thread
))
10485 printf_filtered ("FAIL cannot get thread info\n");
10489 thread_display_step (threadref
*ref
, void *context
)
10491 /* output_threadid(" threadstep ",ref); *//* simple test */
10492 return get_and_display_threadinfo (ref
);
10496 threadlist_update_test_cmd (char *cmd
, int tty
)
10498 printf_filtered ("Remote Threadlist update test\n");
10499 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10503 init_remote_threadtests (void)
10505 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10506 _("Fetch and print the remote list of "
10507 "thread identifiers, one pkt only"));
10508 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10509 _("Fetch and display info about one thread"));
10510 add_com ("tset", class_obscure
, threadset_test_cmd
,
10511 _("Test setting to a different thread"));
10512 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10513 _("Iterate through updating all remote thread info"));
10514 add_com ("talive", class_obscure
, threadalive_test
,
10515 _(" Remote thread alive test "));
10520 /* Convert a thread ID to a string. Returns the string in a static
10524 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10526 static char buf
[64];
10527 struct remote_state
*rs
= get_remote_state ();
10529 if (ptid_equal (ptid
, null_ptid
))
10530 return normal_pid_to_str (ptid
);
10531 else if (ptid_is_pid (ptid
))
10533 /* Printing an inferior target id. */
10535 /* When multi-process extensions are off, there's no way in the
10536 remote protocol to know the remote process id, if there's any
10537 at all. There's one exception --- when we're connected with
10538 target extended-remote, and we manually attached to a process
10539 with "attach PID". We don't record anywhere a flag that
10540 allows us to distinguish that case from the case of
10541 connecting with extended-remote and the stub already being
10542 attached to a process, and reporting yes to qAttached, hence
10543 no smart special casing here. */
10544 if (!remote_multi_process_p (rs
))
10546 xsnprintf (buf
, sizeof buf
, "Remote target");
10550 return normal_pid_to_str (ptid
);
10554 if (ptid_equal (magic_null_ptid
, ptid
))
10555 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10556 else if (remote_multi_process_p (rs
))
10557 if (ptid_get_lwp (ptid
) == 0)
10558 return normal_pid_to_str (ptid
);
10560 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10561 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10563 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10564 ptid_get_lwp (ptid
));
10569 /* Get the address of the thread local variable in OBJFILE which is
10570 stored at OFFSET within the thread local storage for thread PTID. */
10573 remote_get_thread_local_address (struct target_ops
*ops
,
10574 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10576 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10578 struct remote_state
*rs
= get_remote_state ();
10580 char *endp
= rs
->buf
+ get_remote_packet_size ();
10581 enum packet_result result
;
10583 strcpy (p
, "qGetTLSAddr:");
10585 p
= write_ptid (p
, endp
, ptid
);
10587 p
+= hexnumstr (p
, offset
);
10589 p
+= hexnumstr (p
, lm
);
10593 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10594 result
= packet_ok (rs
->buf
,
10595 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10596 if (result
== PACKET_OK
)
10600 unpack_varlen_hex (rs
->buf
, &result
);
10603 else if (result
== PACKET_UNKNOWN
)
10604 throw_error (TLS_GENERIC_ERROR
,
10605 _("Remote target doesn't support qGetTLSAddr packet"));
10607 throw_error (TLS_GENERIC_ERROR
,
10608 _("Remote target failed to process qGetTLSAddr request"));
10611 throw_error (TLS_GENERIC_ERROR
,
10612 _("TLS not supported or disabled on this target"));
10617 /* Provide thread local base, i.e. Thread Information Block address.
10618 Returns 1 if ptid is found and thread_local_base is non zero. */
10621 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10623 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10625 struct remote_state
*rs
= get_remote_state ();
10627 char *endp
= rs
->buf
+ get_remote_packet_size ();
10628 enum packet_result result
;
10630 strcpy (p
, "qGetTIBAddr:");
10632 p
= write_ptid (p
, endp
, ptid
);
10636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10637 result
= packet_ok (rs
->buf
,
10638 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10639 if (result
== PACKET_OK
)
10643 unpack_varlen_hex (rs
->buf
, &result
);
10645 *addr
= (CORE_ADDR
) result
;
10648 else if (result
== PACKET_UNKNOWN
)
10649 error (_("Remote target doesn't support qGetTIBAddr packet"));
10651 error (_("Remote target failed to process qGetTIBAddr request"));
10654 error (_("qGetTIBAddr not supported or disabled on this target"));
10659 /* Support for inferring a target description based on the current
10660 architecture and the size of a 'g' packet. While the 'g' packet
10661 can have any size (since optional registers can be left off the
10662 end), some sizes are easily recognizable given knowledge of the
10663 approximate architecture. */
10665 struct remote_g_packet_guess
10668 const struct target_desc
*tdesc
;
10670 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10671 DEF_VEC_O(remote_g_packet_guess_s
);
10673 struct remote_g_packet_data
10675 VEC(remote_g_packet_guess_s
) *guesses
;
10678 static struct gdbarch_data
*remote_g_packet_data_handle
;
10681 remote_g_packet_data_init (struct obstack
*obstack
)
10683 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10687 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10688 const struct target_desc
*tdesc
)
10690 struct remote_g_packet_data
*data
10691 = ((struct remote_g_packet_data
*)
10692 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10693 struct remote_g_packet_guess new_guess
, *guess
;
10696 gdb_assert (tdesc
!= NULL
);
10699 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10701 if (guess
->bytes
== bytes
)
10702 internal_error (__FILE__
, __LINE__
,
10703 _("Duplicate g packet description added for size %d"),
10706 new_guess
.bytes
= bytes
;
10707 new_guess
.tdesc
= tdesc
;
10708 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10711 /* Return 1 if remote_read_description would do anything on this target
10712 and architecture, 0 otherwise. */
10715 remote_read_description_p (struct target_ops
*target
)
10717 struct remote_g_packet_data
*data
10718 = ((struct remote_g_packet_data
*)
10719 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10721 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10727 static const struct target_desc
*
10728 remote_read_description (struct target_ops
*target
)
10730 struct remote_g_packet_data
*data
10731 = ((struct remote_g_packet_data
*)
10732 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10734 /* Do not try this during initial connection, when we do not know
10735 whether there is a running but stopped thread. */
10736 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10737 return target
->beneath
->to_read_description (target
->beneath
);
10739 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10741 struct remote_g_packet_guess
*guess
;
10743 int bytes
= send_g_packet ();
10746 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10748 if (guess
->bytes
== bytes
)
10749 return guess
->tdesc
;
10751 /* We discard the g packet. A minor optimization would be to
10752 hold on to it, and fill the register cache once we have selected
10753 an architecture, but it's too tricky to do safely. */
10756 return target
->beneath
->to_read_description (target
->beneath
);
10759 /* Remote file transfer support. This is host-initiated I/O, not
10760 target-initiated; for target-initiated, see remote-fileio.c. */
10762 /* If *LEFT is at least the length of STRING, copy STRING to
10763 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10764 decrease *LEFT. Otherwise raise an error. */
10767 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10769 int len
= strlen (string
);
10772 error (_("Packet too long for target."));
10774 memcpy (*buffer
, string
, len
);
10778 /* NUL-terminate the buffer as a convenience, if there is
10784 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10785 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10786 decrease *LEFT. Otherwise raise an error. */
10789 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10792 if (2 * len
> *left
)
10793 error (_("Packet too long for target."));
10795 bin2hex (bytes
, *buffer
, len
);
10796 *buffer
+= 2 * len
;
10799 /* NUL-terminate the buffer as a convenience, if there is
10805 /* If *LEFT is large enough, convert VALUE to hex and add it to
10806 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10807 decrease *LEFT. Otherwise raise an error. */
10810 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10812 int len
= hexnumlen (value
);
10815 error (_("Packet too long for target."));
10817 hexnumstr (*buffer
, value
);
10821 /* NUL-terminate the buffer as a convenience, if there is
10827 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10828 value, *REMOTE_ERRNO to the remote error number or zero if none
10829 was included, and *ATTACHMENT to point to the start of the annex
10830 if any. The length of the packet isn't needed here; there may
10831 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10833 Return 0 if the packet could be parsed, -1 if it could not. If
10834 -1 is returned, the other variables may not be initialized. */
10837 remote_hostio_parse_result (char *buffer
, int *retcode
,
10838 int *remote_errno
, char **attachment
)
10843 *attachment
= NULL
;
10845 if (buffer
[0] != 'F')
10849 *retcode
= strtol (&buffer
[1], &p
, 16);
10850 if (errno
!= 0 || p
== &buffer
[1])
10853 /* Check for ",errno". */
10857 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10858 if (errno
!= 0 || p
+ 1 == p2
)
10863 /* Check for ";attachment". If there is no attachment, the
10864 packet should end here. */
10867 *attachment
= p
+ 1;
10870 else if (*p
== '\0')
10876 /* Send a prepared I/O packet to the target and read its response.
10877 The prepared packet is in the global RS->BUF before this function
10878 is called, and the answer is there when we return.
10880 COMMAND_BYTES is the length of the request to send, which may include
10881 binary data. WHICH_PACKET is the packet configuration to check
10882 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10883 is set to the error number and -1 is returned. Otherwise the value
10884 returned by the function is returned.
10886 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10887 attachment is expected; an error will be reported if there's a
10888 mismatch. If one is found, *ATTACHMENT will be set to point into
10889 the packet buffer and *ATTACHMENT_LEN will be set to the
10890 attachment's length. */
10893 remote_hostio_send_command (int command_bytes
, int which_packet
,
10894 int *remote_errno
, char **attachment
,
10895 int *attachment_len
)
10897 struct remote_state
*rs
= get_remote_state ();
10898 int ret
, bytes_read
;
10899 char *attachment_tmp
;
10901 if (!rs
->remote_desc
10902 || packet_support (which_packet
) == PACKET_DISABLE
)
10904 *remote_errno
= FILEIO_ENOSYS
;
10908 putpkt_binary (rs
->buf
, command_bytes
);
10909 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10911 /* If it timed out, something is wrong. Don't try to parse the
10913 if (bytes_read
< 0)
10915 *remote_errno
= FILEIO_EINVAL
;
10919 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10922 *remote_errno
= FILEIO_EINVAL
;
10924 case PACKET_UNKNOWN
:
10925 *remote_errno
= FILEIO_ENOSYS
;
10931 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10934 *remote_errno
= FILEIO_EINVAL
;
10938 /* Make sure we saw an attachment if and only if we expected one. */
10939 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10940 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10942 *remote_errno
= FILEIO_EINVAL
;
10946 /* If an attachment was found, it must point into the packet buffer;
10947 work out how many bytes there were. */
10948 if (attachment_tmp
!= NULL
)
10950 *attachment
= attachment_tmp
;
10951 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10957 /* Invalidate the readahead cache. */
10960 readahead_cache_invalidate (void)
10962 struct remote_state
*rs
= get_remote_state ();
10964 rs
->readahead_cache
.fd
= -1;
10967 /* Invalidate the readahead cache if it is holding data for FD. */
10970 readahead_cache_invalidate_fd (int fd
)
10972 struct remote_state
*rs
= get_remote_state ();
10974 if (rs
->readahead_cache
.fd
== fd
)
10975 rs
->readahead_cache
.fd
= -1;
10978 /* Set the filesystem remote_hostio functions that take FILENAME
10979 arguments will use. Return 0 on success, or -1 if an error
10980 occurs (and set *REMOTE_ERRNO). */
10983 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10985 struct remote_state
*rs
= get_remote_state ();
10986 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10988 int left
= get_remote_packet_size () - 1;
10992 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10995 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10998 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11000 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11001 remote_buffer_add_string (&p
, &left
, arg
);
11003 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11004 remote_errno
, NULL
, NULL
);
11006 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11010 rs
->fs_pid
= required_pid
;
11015 /* Implementation of to_fileio_open. */
11018 remote_hostio_open (struct target_ops
*self
,
11019 struct inferior
*inf
, const char *filename
,
11020 int flags
, int mode
, int warn_if_slow
,
11023 struct remote_state
*rs
= get_remote_state ();
11025 int left
= get_remote_packet_size () - 1;
11029 static int warning_issued
= 0;
11031 printf_unfiltered (_("Reading %s from remote target...\n"),
11034 if (!warning_issued
)
11036 warning (_("File transfers from remote targets can be slow."
11037 " Use \"set sysroot\" to access files locally"
11039 warning_issued
= 1;
11043 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11046 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11048 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11049 strlen (filename
));
11050 remote_buffer_add_string (&p
, &left
, ",");
11052 remote_buffer_add_int (&p
, &left
, flags
);
11053 remote_buffer_add_string (&p
, &left
, ",");
11055 remote_buffer_add_int (&p
, &left
, mode
);
11057 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11058 remote_errno
, NULL
, NULL
);
11061 /* Implementation of to_fileio_pwrite. */
11064 remote_hostio_pwrite (struct target_ops
*self
,
11065 int fd
, const gdb_byte
*write_buf
, int len
,
11066 ULONGEST offset
, int *remote_errno
)
11068 struct remote_state
*rs
= get_remote_state ();
11070 int left
= get_remote_packet_size ();
11073 readahead_cache_invalidate_fd (fd
);
11075 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11077 remote_buffer_add_int (&p
, &left
, fd
);
11078 remote_buffer_add_string (&p
, &left
, ",");
11080 remote_buffer_add_int (&p
, &left
, offset
);
11081 remote_buffer_add_string (&p
, &left
, ",");
11083 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11084 get_remote_packet_size () - (p
- rs
->buf
));
11086 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11087 remote_errno
, NULL
, NULL
);
11090 /* Helper for the implementation of to_fileio_pread. Read the file
11091 from the remote side with vFile:pread. */
11094 remote_hostio_pread_vFile (struct target_ops
*self
,
11095 int fd
, gdb_byte
*read_buf
, int len
,
11096 ULONGEST offset
, int *remote_errno
)
11098 struct remote_state
*rs
= get_remote_state ();
11101 int left
= get_remote_packet_size ();
11102 int ret
, attachment_len
;
11105 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11107 remote_buffer_add_int (&p
, &left
, fd
);
11108 remote_buffer_add_string (&p
, &left
, ",");
11110 remote_buffer_add_int (&p
, &left
, len
);
11111 remote_buffer_add_string (&p
, &left
, ",");
11113 remote_buffer_add_int (&p
, &left
, offset
);
11115 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11116 remote_errno
, &attachment
,
11122 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11124 if (read_len
!= ret
)
11125 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11130 /* Serve pread from the readahead cache. Returns number of bytes
11131 read, or 0 if the request can't be served from the cache. */
11134 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11135 int fd
, gdb_byte
*read_buf
, size_t len
,
11138 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11140 if (cache
->fd
== fd
11141 && cache
->offset
<= offset
11142 && offset
< cache
->offset
+ cache
->bufsize
)
11144 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11146 if (offset
+ len
> max
)
11147 len
= max
- offset
;
11149 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11156 /* Implementation of to_fileio_pread. */
11159 remote_hostio_pread (struct target_ops
*self
,
11160 int fd
, gdb_byte
*read_buf
, int len
,
11161 ULONGEST offset
, int *remote_errno
)
11164 struct remote_state
*rs
= get_remote_state ();
11165 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11167 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11170 cache
->hit_count
++;
11173 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11174 pulongest (cache
->hit_count
));
11178 cache
->miss_count
++;
11180 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11181 pulongest (cache
->miss_count
));
11184 cache
->offset
= offset
;
11185 cache
->bufsize
= get_remote_packet_size ();
11186 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11188 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11189 cache
->offset
, remote_errno
);
11192 readahead_cache_invalidate_fd (fd
);
11196 cache
->bufsize
= ret
;
11197 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11200 /* Implementation of to_fileio_close. */
11203 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11205 struct remote_state
*rs
= get_remote_state ();
11207 int left
= get_remote_packet_size () - 1;
11209 readahead_cache_invalidate_fd (fd
);
11211 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11213 remote_buffer_add_int (&p
, &left
, fd
);
11215 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11216 remote_errno
, NULL
, NULL
);
11219 /* Implementation of to_fileio_unlink. */
11222 remote_hostio_unlink (struct target_ops
*self
,
11223 struct inferior
*inf
, const char *filename
,
11226 struct remote_state
*rs
= get_remote_state ();
11228 int left
= get_remote_packet_size () - 1;
11230 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11233 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11235 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11236 strlen (filename
));
11238 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11239 remote_errno
, NULL
, NULL
);
11242 /* Implementation of to_fileio_readlink. */
11245 remote_hostio_readlink (struct target_ops
*self
,
11246 struct inferior
*inf
, const char *filename
,
11249 struct remote_state
*rs
= get_remote_state ();
11252 int left
= get_remote_packet_size ();
11253 int len
, attachment_len
;
11257 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11260 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11262 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11263 strlen (filename
));
11265 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11266 remote_errno
, &attachment
,
11272 ret
= (char *) xmalloc (len
+ 1);
11274 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11275 (gdb_byte
*) ret
, len
);
11276 if (read_len
!= len
)
11277 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11283 /* Implementation of to_fileio_fstat. */
11286 remote_hostio_fstat (struct target_ops
*self
,
11287 int fd
, struct stat
*st
,
11290 struct remote_state
*rs
= get_remote_state ();
11292 int left
= get_remote_packet_size ();
11293 int attachment_len
, ret
;
11295 struct fio_stat fst
;
11298 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11300 remote_buffer_add_int (&p
, &left
, fd
);
11302 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11303 remote_errno
, &attachment
,
11307 if (*remote_errno
!= FILEIO_ENOSYS
)
11310 /* Strictly we should return -1, ENOSYS here, but when
11311 "set sysroot remote:" was implemented in August 2008
11312 BFD's need for a stat function was sidestepped with
11313 this hack. This was not remedied until March 2015
11314 so we retain the previous behavior to avoid breaking
11317 Note that the memset is a March 2015 addition; older
11318 GDBs set st_size *and nothing else* so the structure
11319 would have garbage in all other fields. This might
11320 break something but retaining the previous behavior
11321 here would be just too wrong. */
11323 memset (st
, 0, sizeof (struct stat
));
11324 st
->st_size
= INT_MAX
;
11328 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11329 (gdb_byte
*) &fst
, sizeof (fst
));
11331 if (read_len
!= ret
)
11332 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11334 if (read_len
!= sizeof (fst
))
11335 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11336 read_len
, (int) sizeof (fst
));
11338 remote_fileio_to_host_stat (&fst
, st
);
11343 /* Implementation of to_filesystem_is_local. */
11346 remote_filesystem_is_local (struct target_ops
*self
)
11348 /* Valgrind GDB presents itself as a remote target but works
11349 on the local filesystem: it does not implement remote get
11350 and users are not expected to set a sysroot. To handle
11351 this case we treat the remote filesystem as local if the
11352 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11353 does not support vFile:open. */
11354 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11356 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11358 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11360 int fd
, remote_errno
;
11362 /* Try opening a file to probe support. The supplied
11363 filename is irrelevant, we only care about whether
11364 the stub recognizes the packet or not. */
11365 fd
= remote_hostio_open (self
, NULL
, "just probing",
11366 FILEIO_O_RDONLY
, 0700, 0,
11370 remote_hostio_close (self
, fd
, &remote_errno
);
11372 ps
= packet_support (PACKET_vFile_open
);
11375 if (ps
== PACKET_DISABLE
)
11377 static int warning_issued
= 0;
11379 if (!warning_issued
)
11381 warning (_("remote target does not support file"
11382 " transfer, attempting to access files"
11383 " from local filesystem."));
11384 warning_issued
= 1;
11395 remote_fileio_errno_to_host (int errnum
)
11401 case FILEIO_ENOENT
:
11409 case FILEIO_EACCES
:
11411 case FILEIO_EFAULT
:
11415 case FILEIO_EEXIST
:
11417 case FILEIO_ENODEV
:
11419 case FILEIO_ENOTDIR
:
11421 case FILEIO_EISDIR
:
11423 case FILEIO_EINVAL
:
11425 case FILEIO_ENFILE
:
11427 case FILEIO_EMFILE
:
11431 case FILEIO_ENOSPC
:
11433 case FILEIO_ESPIPE
:
11437 case FILEIO_ENOSYS
:
11439 case FILEIO_ENAMETOOLONG
:
11440 return ENAMETOOLONG
;
11446 remote_hostio_error (int errnum
)
11448 int host_error
= remote_fileio_errno_to_host (errnum
);
11450 if (host_error
== -1)
11451 error (_("Unknown remote I/O error %d"), errnum
);
11453 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11457 remote_hostio_close_cleanup (void *opaque
)
11459 int fd
= *(int *) opaque
;
11462 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11466 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11468 struct cleanup
*back_to
, *close_cleanup
;
11469 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11472 int bytes_in_buffer
;
11475 struct remote_state
*rs
= get_remote_state ();
11477 if (!rs
->remote_desc
)
11478 error (_("command can only be used with remote target"));
11480 file
= gdb_fopen_cloexec (local_file
, "rb");
11482 perror_with_name (local_file
);
11483 back_to
= make_cleanup_fclose (file
);
11485 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11486 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11488 0700, 0, &remote_errno
);
11490 remote_hostio_error (remote_errno
);
11492 /* Send up to this many bytes at once. They won't all fit in the
11493 remote packet limit, so we'll transfer slightly fewer. */
11494 io_size
= get_remote_packet_size ();
11495 buffer
= (gdb_byte
*) xmalloc (io_size
);
11496 make_cleanup (xfree
, buffer
);
11498 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11500 bytes_in_buffer
= 0;
11503 while (bytes_in_buffer
|| !saw_eof
)
11507 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11508 io_size
- bytes_in_buffer
,
11513 error (_("Error reading %s."), local_file
);
11516 /* EOF. Unless there is something still in the
11517 buffer from the last iteration, we are done. */
11519 if (bytes_in_buffer
== 0)
11527 bytes
+= bytes_in_buffer
;
11528 bytes_in_buffer
= 0;
11530 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11532 offset
, &remote_errno
);
11535 remote_hostio_error (remote_errno
);
11536 else if (retcode
== 0)
11537 error (_("Remote write of %d bytes returned 0!"), bytes
);
11538 else if (retcode
< bytes
)
11540 /* Short write. Save the rest of the read data for the next
11542 bytes_in_buffer
= bytes
- retcode
;
11543 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11549 discard_cleanups (close_cleanup
);
11550 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11551 remote_hostio_error (remote_errno
);
11554 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11555 do_cleanups (back_to
);
11559 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11561 struct cleanup
*back_to
, *close_cleanup
;
11562 int fd
, remote_errno
, bytes
, io_size
;
11566 struct remote_state
*rs
= get_remote_state ();
11568 if (!rs
->remote_desc
)
11569 error (_("command can only be used with remote target"));
11571 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11572 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11575 remote_hostio_error (remote_errno
);
11577 file
= gdb_fopen_cloexec (local_file
, "wb");
11579 perror_with_name (local_file
);
11580 back_to
= make_cleanup_fclose (file
);
11582 /* Send up to this many bytes at once. They won't all fit in the
11583 remote packet limit, so we'll transfer slightly fewer. */
11584 io_size
= get_remote_packet_size ();
11585 buffer
= (gdb_byte
*) xmalloc (io_size
);
11586 make_cleanup (xfree
, buffer
);
11588 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11593 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11594 fd
, buffer
, io_size
, offset
, &remote_errno
);
11596 /* Success, but no bytes, means end-of-file. */
11599 remote_hostio_error (remote_errno
);
11603 bytes
= fwrite (buffer
, 1, bytes
, file
);
11605 perror_with_name (local_file
);
11608 discard_cleanups (close_cleanup
);
11609 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11610 remote_hostio_error (remote_errno
);
11613 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11614 do_cleanups (back_to
);
11618 remote_file_delete (const char *remote_file
, int from_tty
)
11620 int retcode
, remote_errno
;
11621 struct remote_state
*rs
= get_remote_state ();
11623 if (!rs
->remote_desc
)
11624 error (_("command can only be used with remote target"));
11626 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11627 NULL
, remote_file
, &remote_errno
);
11629 remote_hostio_error (remote_errno
);
11632 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11636 remote_put_command (char *args
, int from_tty
)
11638 struct cleanup
*back_to
;
11642 error_no_arg (_("file to put"));
11644 argv
= gdb_buildargv (args
);
11645 back_to
= make_cleanup_freeargv (argv
);
11646 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11647 error (_("Invalid parameters to remote put"));
11649 remote_file_put (argv
[0], argv
[1], from_tty
);
11651 do_cleanups (back_to
);
11655 remote_get_command (char *args
, int from_tty
)
11657 struct cleanup
*back_to
;
11661 error_no_arg (_("file to get"));
11663 argv
= gdb_buildargv (args
);
11664 back_to
= make_cleanup_freeargv (argv
);
11665 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11666 error (_("Invalid parameters to remote get"));
11668 remote_file_get (argv
[0], argv
[1], from_tty
);
11670 do_cleanups (back_to
);
11674 remote_delete_command (char *args
, int from_tty
)
11676 struct cleanup
*back_to
;
11680 error_no_arg (_("file to delete"));
11682 argv
= gdb_buildargv (args
);
11683 back_to
= make_cleanup_freeargv (argv
);
11684 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11685 error (_("Invalid parameters to remote delete"));
11687 remote_file_delete (argv
[0], from_tty
);
11689 do_cleanups (back_to
);
11693 remote_command (char *args
, int from_tty
)
11695 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11699 remote_can_execute_reverse (struct target_ops
*self
)
11701 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11702 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11709 remote_supports_non_stop (struct target_ops
*self
)
11715 remote_supports_disable_randomization (struct target_ops
*self
)
11717 /* Only supported in extended mode. */
11722 remote_supports_multi_process (struct target_ops
*self
)
11724 struct remote_state
*rs
= get_remote_state ();
11726 return remote_multi_process_p (rs
);
11730 remote_supports_cond_tracepoints (void)
11732 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11736 remote_supports_cond_breakpoints (struct target_ops
*self
)
11738 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11742 remote_supports_fast_tracepoints (void)
11744 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11748 remote_supports_static_tracepoints (void)
11750 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11754 remote_supports_install_in_trace (void)
11756 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11760 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11762 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11767 remote_supports_string_tracing (struct target_ops
*self
)
11769 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11773 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11775 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11779 remote_trace_init (struct target_ops
*self
)
11782 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11783 if (strcmp (target_buf
, "OK") != 0)
11784 error (_("Target does not support this command."));
11787 static void free_actions_list (char **actions_list
);
11788 static void free_actions_list_cleanup_wrapper (void *);
11790 free_actions_list_cleanup_wrapper (void *al
)
11792 free_actions_list ((char **) al
);
11796 free_actions_list (char **actions_list
)
11800 if (actions_list
== 0)
11803 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11804 xfree (actions_list
[ndx
]);
11806 xfree (actions_list
);
11809 /* Recursive routine to walk through command list including loops, and
11810 download packets for each command. */
11813 remote_download_command_source (int num
, ULONGEST addr
,
11814 struct command_line
*cmds
)
11816 struct remote_state
*rs
= get_remote_state ();
11817 struct command_line
*cmd
;
11819 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11821 QUIT
; /* Allow user to bail out with ^C. */
11822 strcpy (rs
->buf
, "QTDPsrc:");
11823 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11824 rs
->buf
+ strlen (rs
->buf
),
11825 rs
->buf_size
- strlen (rs
->buf
));
11827 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11828 if (strcmp (target_buf
, "OK"))
11829 warning (_("Target does not support source download."));
11831 if (cmd
->control_type
== while_control
11832 || cmd
->control_type
== while_stepping_control
)
11834 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11836 QUIT
; /* Allow user to bail out with ^C. */
11837 strcpy (rs
->buf
, "QTDPsrc:");
11838 encode_source_string (num
, addr
, "cmd", "end",
11839 rs
->buf
+ strlen (rs
->buf
),
11840 rs
->buf_size
- strlen (rs
->buf
));
11842 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11843 if (strcmp (target_buf
, "OK"))
11844 warning (_("Target does not support source download."));
11850 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11852 #define BUF_SIZE 2048
11856 char buf
[BUF_SIZE
];
11857 char **tdp_actions
;
11858 char **stepping_actions
;
11860 struct cleanup
*old_chain
= NULL
;
11861 struct agent_expr
*aexpr
;
11862 struct cleanup
*aexpr_chain
= NULL
;
11864 struct breakpoint
*b
= loc
->owner
;
11865 struct tracepoint
*t
= (struct tracepoint
*) b
;
11867 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11868 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11870 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11873 tpaddr
= loc
->address
;
11874 sprintf_vma (addrbuf
, tpaddr
);
11875 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11876 addrbuf
, /* address */
11877 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11878 t
->step_count
, t
->pass_count
);
11879 /* Fast tracepoints are mostly handled by the target, but we can
11880 tell the target how big of an instruction block should be moved
11882 if (b
->type
== bp_fast_tracepoint
)
11884 /* Only test for support at download time; we may not know
11885 target capabilities at definition time. */
11886 if (remote_supports_fast_tracepoints ())
11888 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11890 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11891 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11893 /* If it passed validation at definition but fails now,
11894 something is very wrong. */
11895 internal_error (__FILE__
, __LINE__
,
11896 _("Fast tracepoint not "
11897 "valid during download"));
11900 /* Fast tracepoints are functionally identical to regular
11901 tracepoints, so don't take lack of support as a reason to
11902 give up on the trace run. */
11903 warning (_("Target does not support fast tracepoints, "
11904 "downloading %d as regular tracepoint"), b
->number
);
11906 else if (b
->type
== bp_static_tracepoint
)
11908 /* Only test for support at download time; we may not know
11909 target capabilities at definition time. */
11910 if (remote_supports_static_tracepoints ())
11912 struct static_tracepoint_marker marker
;
11914 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11915 strcat (buf
, ":S");
11917 error (_("Static tracepoint not valid during download"));
11920 /* Fast tracepoints are functionally identical to regular
11921 tracepoints, so don't take lack of support as a reason
11922 to give up on the trace run. */
11923 error (_("Target does not support static tracepoints"));
11925 /* If the tracepoint has a conditional, make it into an agent
11926 expression and append to the definition. */
11929 /* Only test support at download time, we may not know target
11930 capabilities at definition time. */
11931 if (remote_supports_cond_tracepoints ())
11933 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11934 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11935 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11937 pkt
= buf
+ strlen (buf
);
11938 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11939 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11941 do_cleanups (aexpr_chain
);
11944 warning (_("Target does not support conditional tracepoints, "
11945 "ignoring tp %d cond"), b
->number
);
11948 if (b
->commands
|| *default_collect
)
11951 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11952 if (strcmp (target_buf
, "OK"))
11953 error (_("Target does not support tracepoints."));
11955 /* do_single_steps (t); */
11958 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11960 QUIT
; /* Allow user to bail out with ^C. */
11961 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11962 b
->number
, addrbuf
, /* address */
11964 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11967 remote_get_noisy_reply (&target_buf
,
11969 if (strcmp (target_buf
, "OK"))
11970 error (_("Error on target while setting tracepoints."));
11973 if (stepping_actions
)
11975 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11977 QUIT
; /* Allow user to bail out with ^C. */
11978 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11979 b
->number
, addrbuf
, /* address */
11980 ((ndx
== 0) ? "S" : ""),
11981 stepping_actions
[ndx
],
11982 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11984 remote_get_noisy_reply (&target_buf
,
11986 if (strcmp (target_buf
, "OK"))
11987 error (_("Error on target while setting tracepoints."));
11991 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11993 if (b
->location
!= NULL
)
11995 strcpy (buf
, "QTDPsrc:");
11996 encode_source_string (b
->number
, loc
->address
, "at",
11997 event_location_to_string (b
->location
),
11998 buf
+ strlen (buf
), 2048 - strlen (buf
));
12000 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12001 if (strcmp (target_buf
, "OK"))
12002 warning (_("Target does not support source download."));
12004 if (b
->cond_string
)
12006 strcpy (buf
, "QTDPsrc:");
12007 encode_source_string (b
->number
, loc
->address
,
12008 "cond", b
->cond_string
, buf
+ strlen (buf
),
12009 2048 - strlen (buf
));
12011 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12012 if (strcmp (target_buf
, "OK"))
12013 warning (_("Target does not support source download."));
12015 remote_download_command_source (b
->number
, loc
->address
,
12016 breakpoint_commands (b
));
12019 do_cleanups (old_chain
);
12023 remote_can_download_tracepoint (struct target_ops
*self
)
12025 struct remote_state
*rs
= get_remote_state ();
12026 struct trace_status
*ts
;
12029 /* Don't try to install tracepoints until we've relocated our
12030 symbols, and fetched and merged the target's tracepoint list with
12032 if (rs
->starting_up
)
12035 ts
= current_trace_status ();
12036 status
= remote_get_trace_status (self
, ts
);
12038 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12041 /* If we are in a tracing experiment, but remote stub doesn't support
12042 installing tracepoint in trace, we have to return. */
12043 if (!remote_supports_install_in_trace ())
12051 remote_download_trace_state_variable (struct target_ops
*self
,
12052 struct trace_state_variable
*tsv
)
12054 struct remote_state
*rs
= get_remote_state ();
12057 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12058 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12060 p
= rs
->buf
+ strlen (rs
->buf
);
12061 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12062 error (_("Trace state variable name too long for tsv definition packet"));
12063 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12066 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12067 if (*target_buf
== '\0')
12068 error (_("Target does not support this command."));
12069 if (strcmp (target_buf
, "OK") != 0)
12070 error (_("Error on target while downloading trace state variable."));
12074 remote_enable_tracepoint (struct target_ops
*self
,
12075 struct bp_location
*location
)
12077 struct remote_state
*rs
= get_remote_state ();
12080 sprintf_vma (addr_buf
, location
->address
);
12081 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12082 location
->owner
->number
, addr_buf
);
12084 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12085 if (*rs
->buf
== '\0')
12086 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12087 if (strcmp (rs
->buf
, "OK") != 0)
12088 error (_("Error on target while enabling tracepoint."));
12092 remote_disable_tracepoint (struct target_ops
*self
,
12093 struct bp_location
*location
)
12095 struct remote_state
*rs
= get_remote_state ();
12098 sprintf_vma (addr_buf
, location
->address
);
12099 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12100 location
->owner
->number
, addr_buf
);
12102 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12103 if (*rs
->buf
== '\0')
12104 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12105 if (strcmp (rs
->buf
, "OK") != 0)
12106 error (_("Error on target while disabling tracepoint."));
12110 remote_trace_set_readonly_regions (struct target_ops
*self
)
12114 bfd_size_type size
;
12120 return; /* No information to give. */
12122 strcpy (target_buf
, "QTro");
12123 offset
= strlen (target_buf
);
12124 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12126 char tmp1
[40], tmp2
[40];
12129 if ((s
->flags
& SEC_LOAD
) == 0 ||
12130 /* (s->flags & SEC_CODE) == 0 || */
12131 (s
->flags
& SEC_READONLY
) == 0)
12135 vma
= bfd_get_section_vma (abfd
, s
);
12136 size
= bfd_get_section_size (s
);
12137 sprintf_vma (tmp1
, vma
);
12138 sprintf_vma (tmp2
, vma
+ size
);
12139 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12140 if (offset
+ sec_length
+ 1 > target_buf_size
)
12142 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12144 Too many sections for read-only sections definition packet."));
12147 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12149 offset
+= sec_length
;
12153 putpkt (target_buf
);
12154 getpkt (&target_buf
, &target_buf_size
, 0);
12159 remote_trace_start (struct target_ops
*self
)
12161 putpkt ("QTStart");
12162 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12163 if (*target_buf
== '\0')
12164 error (_("Target does not support this command."));
12165 if (strcmp (target_buf
, "OK") != 0)
12166 error (_("Bogus reply from target: %s"), target_buf
);
12170 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12172 /* Initialize it just to avoid a GCC false warning. */
12174 /* FIXME we need to get register block size some other way. */
12175 extern int trace_regblock_size
;
12176 enum packet_result result
;
12178 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12181 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12183 putpkt ("qTStatus");
12187 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12189 CATCH (ex
, RETURN_MASK_ERROR
)
12191 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12193 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12196 throw_exception (ex
);
12200 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12202 /* If the remote target doesn't do tracing, flag it. */
12203 if (result
== PACKET_UNKNOWN
)
12206 /* We're working with a live target. */
12207 ts
->filename
= NULL
;
12210 error (_("Bogus trace status reply from target: %s"), target_buf
);
12212 /* Function 'parse_trace_status' sets default value of each field of
12213 'ts' at first, so we don't have to do it here. */
12214 parse_trace_status (p
, ts
);
12216 return ts
->running
;
12220 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12221 struct uploaded_tp
*utp
)
12223 struct remote_state
*rs
= get_remote_state ();
12225 struct bp_location
*loc
;
12226 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12227 size_t size
= get_remote_packet_size ();
12231 tp
->base
.hit_count
= 0;
12232 tp
->traceframe_usage
= 0;
12233 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12235 /* If the tracepoint was never downloaded, don't go asking for
12237 if (tp
->number_on_target
== 0)
12239 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12240 phex_nz (loc
->address
, 0));
12242 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12243 if (reply
&& *reply
)
12246 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12252 utp
->hit_count
= 0;
12253 utp
->traceframe_usage
= 0;
12254 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12255 phex_nz (utp
->addr
, 0));
12257 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12258 if (reply
&& *reply
)
12261 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12267 remote_trace_stop (struct target_ops
*self
)
12270 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12271 if (*target_buf
== '\0')
12272 error (_("Target does not support this command."));
12273 if (strcmp (target_buf
, "OK") != 0)
12274 error (_("Bogus reply from target: %s"), target_buf
);
12278 remote_trace_find (struct target_ops
*self
,
12279 enum trace_find_type type
, int num
,
12280 CORE_ADDR addr1
, CORE_ADDR addr2
,
12283 struct remote_state
*rs
= get_remote_state ();
12284 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12286 int target_frameno
= -1, target_tracept
= -1;
12288 /* Lookups other than by absolute frame number depend on the current
12289 trace selected, so make sure it is correct on the remote end
12291 if (type
!= tfind_number
)
12292 set_remote_traceframe ();
12295 strcpy (p
, "QTFrame:");
12296 p
= strchr (p
, '\0');
12300 xsnprintf (p
, endbuf
- p
, "%x", num
);
12303 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12306 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12309 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12310 phex_nz (addr2
, 0));
12312 case tfind_outside
:
12313 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12314 phex_nz (addr2
, 0));
12317 error (_("Unknown trace find type %d"), type
);
12321 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12322 if (*reply
== '\0')
12323 error (_("Target does not support this command."));
12325 while (reply
&& *reply
)
12330 target_frameno
= (int) strtol (p
, &reply
, 16);
12332 error (_("Unable to parse trace frame number"));
12333 /* Don't update our remote traceframe number cache on failure
12334 to select a remote traceframe. */
12335 if (target_frameno
== -1)
12340 target_tracept
= (int) strtol (p
, &reply
, 16);
12342 error (_("Unable to parse tracepoint number"));
12344 case 'O': /* "OK"? */
12345 if (reply
[1] == 'K' && reply
[2] == '\0')
12348 error (_("Bogus reply from target: %s"), reply
);
12351 error (_("Bogus reply from target: %s"), reply
);
12354 *tpp
= target_tracept
;
12356 rs
->remote_traceframe_number
= target_frameno
;
12357 return target_frameno
;
12361 remote_get_trace_state_variable_value (struct target_ops
*self
,
12362 int tsvnum
, LONGEST
*val
)
12364 struct remote_state
*rs
= get_remote_state ();
12368 set_remote_traceframe ();
12370 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12372 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12373 if (reply
&& *reply
)
12377 unpack_varlen_hex (reply
+ 1, &uval
);
12378 *val
= (LONGEST
) uval
;
12386 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12388 struct remote_state
*rs
= get_remote_state ();
12392 strcpy (p
, "QTSave:");
12394 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12395 error (_("Remote file name too long for trace save packet"));
12396 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12399 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12400 if (*reply
== '\0')
12401 error (_("Target does not support this command."));
12402 if (strcmp (reply
, "OK") != 0)
12403 error (_("Bogus reply from target: %s"), reply
);
12407 /* This is basically a memory transfer, but needs to be its own packet
12408 because we don't know how the target actually organizes its trace
12409 memory, plus we want to be able to ask for as much as possible, but
12410 not be unhappy if we don't get as much as we ask for. */
12413 remote_get_raw_trace_data (struct target_ops
*self
,
12414 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12416 struct remote_state
*rs
= get_remote_state ();
12422 strcpy (p
, "qTBuffer:");
12424 p
+= hexnumstr (p
, offset
);
12426 p
+= hexnumstr (p
, len
);
12430 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12431 if (reply
&& *reply
)
12433 /* 'l' by itself means we're at the end of the buffer and
12434 there is nothing more to get. */
12438 /* Convert the reply into binary. Limit the number of bytes to
12439 convert according to our passed-in buffer size, rather than
12440 what was returned in the packet; if the target is
12441 unexpectedly generous and gives us a bigger reply than we
12442 asked for, we don't want to crash. */
12443 rslt
= hex2bin (target_buf
, buf
, len
);
12447 /* Something went wrong, flag as an error. */
12452 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12454 struct remote_state
*rs
= get_remote_state ();
12456 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12460 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12462 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12463 if (*reply
== '\0')
12464 error (_("Target does not support this command."));
12465 if (strcmp (reply
, "OK") != 0)
12466 error (_("Bogus reply from target: %s"), reply
);
12469 warning (_("Target does not support disconnected tracing."));
12473 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12475 struct thread_info
*info
= find_thread_ptid (ptid
);
12477 if (info
&& info
->priv
)
12478 return info
->priv
->core
;
12483 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12485 struct remote_state
*rs
= get_remote_state ();
12488 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12490 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12491 if (*reply
== '\0')
12492 error (_("Target does not support this command."));
12493 if (strcmp (reply
, "OK") != 0)
12494 error (_("Bogus reply from target: %s"), reply
);
12497 static struct traceframe_info
*
12498 remote_traceframe_info (struct target_ops
*self
)
12502 text
= target_read_stralloc (¤t_target
,
12503 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12506 struct traceframe_info
*info
;
12507 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12509 info
= parse_traceframe_info (text
);
12510 do_cleanups (back_to
);
12517 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12518 instruction on which a fast tracepoint may be placed. Returns -1
12519 if the packet is not supported, and 0 if the minimum instruction
12520 length is unknown. */
12523 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12525 struct remote_state
*rs
= get_remote_state ();
12528 /* If we're not debugging a process yet, the IPA can't be
12530 if (!target_has_execution
)
12533 /* Make sure the remote is pointing at the right process. */
12534 set_general_process ();
12536 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12538 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12539 if (*reply
== '\0')
12543 ULONGEST min_insn_len
;
12545 unpack_varlen_hex (reply
, &min_insn_len
);
12547 return (int) min_insn_len
;
12552 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12554 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12556 struct remote_state
*rs
= get_remote_state ();
12557 char *buf
= rs
->buf
;
12558 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12559 enum packet_result result
;
12561 gdb_assert (val
>= 0 || val
== -1);
12562 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12563 /* Send -1 as literal "-1" to avoid host size dependency. */
12567 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12570 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12573 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12574 result
= packet_ok (rs
->buf
,
12575 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12577 if (result
!= PACKET_OK
)
12578 warning (_("Bogus reply from target: %s"), rs
->buf
);
12583 remote_set_trace_notes (struct target_ops
*self
,
12584 const char *user
, const char *notes
,
12585 const char *stop_notes
)
12587 struct remote_state
*rs
= get_remote_state ();
12589 char *buf
= rs
->buf
;
12590 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12593 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12596 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12597 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12603 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12604 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12610 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12611 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12615 /* Ensure the buffer is terminated. */
12619 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12620 if (*reply
== '\0')
12623 if (strcmp (reply
, "OK") != 0)
12624 error (_("Bogus reply from target: %s"), reply
);
12630 remote_use_agent (struct target_ops
*self
, int use
)
12632 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12634 struct remote_state
*rs
= get_remote_state ();
12636 /* If the stub supports QAgent. */
12637 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12639 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12641 if (strcmp (rs
->buf
, "OK") == 0)
12652 remote_can_use_agent (struct target_ops
*self
)
12654 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12657 struct btrace_target_info
12659 /* The ptid of the traced thread. */
12662 /* The obtained branch trace configuration. */
12663 struct btrace_config conf
;
12666 /* Reset our idea of our target's btrace configuration. */
12669 remote_btrace_reset (void)
12671 struct remote_state
*rs
= get_remote_state ();
12673 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12676 /* Check whether the target supports branch tracing. */
12679 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12681 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12683 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12688 case BTRACE_FORMAT_NONE
:
12691 case BTRACE_FORMAT_BTS
:
12692 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12694 case BTRACE_FORMAT_PT
:
12695 /* The trace is decoded on the host. Even if our target supports it,
12696 we still need to have libipt to decode the trace. */
12697 #if defined (HAVE_LIBIPT)
12698 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12699 #else /* !defined (HAVE_LIBIPT) */
12701 #endif /* !defined (HAVE_LIBIPT) */
12704 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12707 /* Synchronize the configuration with the target. */
12710 btrace_sync_conf (const struct btrace_config
*conf
)
12712 struct packet_config
*packet
;
12713 struct remote_state
*rs
;
12714 char *buf
, *pos
, *endbuf
;
12716 rs
= get_remote_state ();
12718 endbuf
= buf
+ get_remote_packet_size ();
12720 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12721 if (packet_config_support (packet
) == PACKET_ENABLE
12722 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12725 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12729 getpkt (&buf
, &rs
->buf_size
, 0);
12731 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12733 if (buf
[0] == 'E' && buf
[1] == '.')
12734 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12736 error (_("Failed to configure the BTS buffer size."));
12739 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12742 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12743 if (packet_config_support (packet
) == PACKET_ENABLE
12744 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12747 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12751 getpkt (&buf
, &rs
->buf_size
, 0);
12753 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12755 if (buf
[0] == 'E' && buf
[1] == '.')
12756 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12758 error (_("Failed to configure the trace buffer size."));
12761 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12765 /* Read the current thread's btrace configuration from the target and
12766 store it into CONF. */
12769 btrace_read_config (struct btrace_config
*conf
)
12773 xml
= target_read_stralloc (¤t_target
,
12774 TARGET_OBJECT_BTRACE_CONF
, "");
12777 struct cleanup
*cleanup
;
12779 cleanup
= make_cleanup (xfree
, xml
);
12780 parse_xml_btrace_conf (conf
, xml
);
12781 do_cleanups (cleanup
);
12785 /* Enable branch tracing. */
12787 static struct btrace_target_info
*
12788 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12789 const struct btrace_config
*conf
)
12791 struct btrace_target_info
*tinfo
= NULL
;
12792 struct packet_config
*packet
= NULL
;
12793 struct remote_state
*rs
= get_remote_state ();
12794 char *buf
= rs
->buf
;
12795 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12797 switch (conf
->format
)
12799 case BTRACE_FORMAT_BTS
:
12800 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12803 case BTRACE_FORMAT_PT
:
12804 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12808 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12809 error (_("Target does not support branch tracing."));
12811 btrace_sync_conf (conf
);
12813 set_general_thread (ptid
);
12815 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12817 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12819 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12821 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12822 error (_("Could not enable branch tracing for %s: %s"),
12823 target_pid_to_str (ptid
), rs
->buf
+ 2);
12825 error (_("Could not enable branch tracing for %s."),
12826 target_pid_to_str (ptid
));
12829 tinfo
= XCNEW (struct btrace_target_info
);
12830 tinfo
->ptid
= ptid
;
12832 /* If we fail to read the configuration, we lose some information, but the
12833 tracing itself is not impacted. */
12836 btrace_read_config (&tinfo
->conf
);
12838 CATCH (err
, RETURN_MASK_ERROR
)
12840 if (err
.message
!= NULL
)
12841 warning ("%s", err
.message
);
12848 /* Disable branch tracing. */
12851 remote_disable_btrace (struct target_ops
*self
,
12852 struct btrace_target_info
*tinfo
)
12854 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12855 struct remote_state
*rs
= get_remote_state ();
12856 char *buf
= rs
->buf
;
12857 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12859 if (packet_config_support (packet
) != PACKET_ENABLE
)
12860 error (_("Target does not support branch tracing."));
12862 set_general_thread (tinfo
->ptid
);
12864 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12866 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12868 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12870 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12871 error (_("Could not disable branch tracing for %s: %s"),
12872 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12874 error (_("Could not disable branch tracing for %s."),
12875 target_pid_to_str (tinfo
->ptid
));
12881 /* Teardown branch tracing. */
12884 remote_teardown_btrace (struct target_ops
*self
,
12885 struct btrace_target_info
*tinfo
)
12887 /* We must not talk to the target during teardown. */
12891 /* Read the branch trace. */
12893 static enum btrace_error
12894 remote_read_btrace (struct target_ops
*self
,
12895 struct btrace_data
*btrace
,
12896 struct btrace_target_info
*tinfo
,
12897 enum btrace_read_type type
)
12899 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12900 struct cleanup
*cleanup
;
12904 if (packet_config_support (packet
) != PACKET_ENABLE
)
12905 error (_("Target does not support branch tracing."));
12907 #if !defined(HAVE_LIBEXPAT)
12908 error (_("Cannot process branch tracing result. XML parsing not supported."));
12913 case BTRACE_READ_ALL
:
12916 case BTRACE_READ_NEW
:
12919 case BTRACE_READ_DELTA
:
12923 internal_error (__FILE__
, __LINE__
,
12924 _("Bad branch tracing read type: %u."),
12925 (unsigned int) type
);
12928 xml
= target_read_stralloc (¤t_target
,
12929 TARGET_OBJECT_BTRACE
, annex
);
12931 return BTRACE_ERR_UNKNOWN
;
12933 cleanup
= make_cleanup (xfree
, xml
);
12934 parse_xml_btrace (btrace
, xml
);
12935 do_cleanups (cleanup
);
12937 return BTRACE_ERR_NONE
;
12940 static const struct btrace_config
*
12941 remote_btrace_conf (struct target_ops
*self
,
12942 const struct btrace_target_info
*tinfo
)
12944 return &tinfo
->conf
;
12948 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12950 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12954 /* Implementation of to_load. */
12957 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12959 generic_load (name
, from_tty
);
12962 /* Accepts an integer PID; returns a string representing a file that
12963 can be opened on the remote side to get the symbols for the child
12964 process. Returns NULL if the operation is not supported. */
12967 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12969 static char *filename
= NULL
;
12970 struct inferior
*inf
;
12971 char *annex
= NULL
;
12973 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12976 if (filename
!= NULL
)
12979 inf
= find_inferior_pid (pid
);
12981 internal_error (__FILE__
, __LINE__
,
12982 _("not currently attached to process %d"), pid
);
12984 if (!inf
->fake_pid_p
)
12986 const int annex_size
= 9;
12988 annex
= (char *) alloca (annex_size
);
12989 xsnprintf (annex
, annex_size
, "%x", pid
);
12992 filename
= target_read_stralloc (¤t_target
,
12993 TARGET_OBJECT_EXEC_FILE
, annex
);
12998 /* Implement the to_can_do_single_step target_ops method. */
13001 remote_can_do_single_step (struct target_ops
*ops
)
13003 /* We can only tell whether target supports single step or not by
13004 supported s and S vCont actions if the stub supports vContSupported
13005 feature. If the stub doesn't support vContSupported feature,
13006 we have conservatively to think target doesn't supports single
13008 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13010 struct remote_state
*rs
= get_remote_state ();
13012 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13013 remote_vcont_probe (rs
);
13015 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13022 init_remote_ops (void)
13024 remote_ops
.to_shortname
= "remote";
13025 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13026 remote_ops
.to_doc
=
13027 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13028 Specify the serial device it is connected to\n\
13029 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13030 remote_ops
.to_open
= remote_open
;
13031 remote_ops
.to_close
= remote_close
;
13032 remote_ops
.to_detach
= remote_detach
;
13033 remote_ops
.to_disconnect
= remote_disconnect
;
13034 remote_ops
.to_resume
= remote_resume
;
13035 remote_ops
.to_wait
= remote_wait
;
13036 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13037 remote_ops
.to_store_registers
= remote_store_registers
;
13038 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13039 remote_ops
.to_files_info
= remote_files_info
;
13040 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13041 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13042 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13043 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13044 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13045 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13046 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13047 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13048 remote_ops
.to_watchpoint_addr_within_range
=
13049 remote_watchpoint_addr_within_range
;
13050 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13051 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13052 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13053 remote_ops
.to_region_ok_for_hw_watchpoint
13054 = remote_region_ok_for_hw_watchpoint
;
13055 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13056 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13057 remote_ops
.to_kill
= remote_kill
;
13058 remote_ops
.to_load
= remote_load
;
13059 remote_ops
.to_mourn_inferior
= remote_mourn
;
13060 remote_ops
.to_pass_signals
= remote_pass_signals
;
13061 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13062 remote_ops
.to_program_signals
= remote_program_signals
;
13063 remote_ops
.to_thread_alive
= remote_thread_alive
;
13064 remote_ops
.to_thread_name
= remote_thread_name
;
13065 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13066 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13067 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13068 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13069 remote_ops
.to_stop
= remote_stop
;
13070 remote_ops
.to_interrupt
= remote_interrupt
;
13071 remote_ops
.to_check_pending_interrupt
= remote_check_pending_interrupt
;
13072 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13073 remote_ops
.to_rcmd
= remote_rcmd
;
13074 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13075 remote_ops
.to_log_command
= serial_log_command
;
13076 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13077 remote_ops
.to_stratum
= process_stratum
;
13078 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13079 remote_ops
.to_has_memory
= default_child_has_memory
;
13080 remote_ops
.to_has_stack
= default_child_has_stack
;
13081 remote_ops
.to_has_registers
= default_child_has_registers
;
13082 remote_ops
.to_has_execution
= default_child_has_execution
;
13083 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13084 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13085 remote_ops
.to_magic
= OPS_MAGIC
;
13086 remote_ops
.to_memory_map
= remote_memory_map
;
13087 remote_ops
.to_flash_erase
= remote_flash_erase
;
13088 remote_ops
.to_flash_done
= remote_flash_done
;
13089 remote_ops
.to_read_description
= remote_read_description
;
13090 remote_ops
.to_search_memory
= remote_search_memory
;
13091 remote_ops
.to_can_async_p
= remote_can_async_p
;
13092 remote_ops
.to_is_async_p
= remote_is_async_p
;
13093 remote_ops
.to_async
= remote_async
;
13094 remote_ops
.to_thread_events
= remote_thread_events
;
13095 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13096 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13097 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13098 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13099 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13100 remote_ops
.to_supports_disable_randomization
13101 = remote_supports_disable_randomization
;
13102 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13103 remote_ops
.to_fileio_open
= remote_hostio_open
;
13104 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13105 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13106 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13107 remote_ops
.to_fileio_close
= remote_hostio_close
;
13108 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13109 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13110 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13111 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13112 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13113 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13114 remote_ops
.to_trace_init
= remote_trace_init
;
13115 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13116 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13117 remote_ops
.to_download_trace_state_variable
13118 = remote_download_trace_state_variable
;
13119 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13120 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13121 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13122 remote_ops
.to_trace_start
= remote_trace_start
;
13123 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13124 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13125 remote_ops
.to_trace_stop
= remote_trace_stop
;
13126 remote_ops
.to_trace_find
= remote_trace_find
;
13127 remote_ops
.to_get_trace_state_variable_value
13128 = remote_get_trace_state_variable_value
;
13129 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13130 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13131 remote_ops
.to_upload_trace_state_variables
13132 = remote_upload_trace_state_variables
;
13133 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13134 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13135 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13136 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13137 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13138 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13139 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13140 remote_ops
.to_verify_memory
= remote_verify_memory
;
13141 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13142 remote_ops
.to_set_permissions
= remote_set_permissions
;
13143 remote_ops
.to_static_tracepoint_marker_at
13144 = remote_static_tracepoint_marker_at
;
13145 remote_ops
.to_static_tracepoint_markers_by_strid
13146 = remote_static_tracepoint_markers_by_strid
;
13147 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13148 remote_ops
.to_use_agent
= remote_use_agent
;
13149 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13150 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13151 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13152 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13153 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13154 remote_ops
.to_read_btrace
= remote_read_btrace
;
13155 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13156 remote_ops
.to_augmented_libraries_svr4_read
=
13157 remote_augmented_libraries_svr4_read
;
13158 remote_ops
.to_follow_fork
= remote_follow_fork
;
13159 remote_ops
.to_follow_exec
= remote_follow_exec
;
13160 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13161 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13162 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13163 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13164 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13165 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13168 /* Set up the extended remote vector by making a copy of the standard
13169 remote vector and adding to it. */
13172 init_extended_remote_ops (void)
13174 extended_remote_ops
= remote_ops
;
13176 extended_remote_ops
.to_shortname
= "extended-remote";
13177 extended_remote_ops
.to_longname
=
13178 "Extended remote serial target in gdb-specific protocol";
13179 extended_remote_ops
.to_doc
=
13180 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13181 Specify the serial device it is connected to (e.g. /dev/ttya).";
13182 extended_remote_ops
.to_open
= extended_remote_open
;
13183 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13184 extended_remote_ops
.to_detach
= extended_remote_detach
;
13185 extended_remote_ops
.to_attach
= extended_remote_attach
;
13186 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13187 extended_remote_ops
.to_supports_disable_randomization
13188 = extended_remote_supports_disable_randomization
;
13192 remote_can_async_p (struct target_ops
*ops
)
13194 struct remote_state
*rs
= get_remote_state ();
13196 if (!target_async_permitted
)
13197 /* We only enable async when the user specifically asks for it. */
13200 /* We're async whenever the serial device is. */
13201 return serial_can_async_p (rs
->remote_desc
);
13205 remote_is_async_p (struct target_ops
*ops
)
13207 struct remote_state
*rs
= get_remote_state ();
13209 if (!target_async_permitted
)
13210 /* We only enable async when the user specifically asks for it. */
13213 /* We're async whenever the serial device is. */
13214 return serial_is_async_p (rs
->remote_desc
);
13217 /* Pass the SERIAL event on and up to the client. One day this code
13218 will be able to delay notifying the client of an event until the
13219 point where an entire packet has been received. */
13221 static serial_event_ftype remote_async_serial_handler
;
13224 remote_async_serial_handler (struct serial
*scb
, void *context
)
13226 /* Don't propogate error information up to the client. Instead let
13227 the client find out about the error by querying the target. */
13228 inferior_event_handler (INF_REG_EVENT
, NULL
);
13232 remote_async_inferior_event_handler (gdb_client_data data
)
13234 inferior_event_handler (INF_REG_EVENT
, NULL
);
13238 remote_async (struct target_ops
*ops
, int enable
)
13240 struct remote_state
*rs
= get_remote_state ();
13244 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13246 /* If there are pending events in the stop reply queue tell the
13247 event loop to process them. */
13248 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13249 mark_async_event_handler (remote_async_inferior_event_token
);
13250 /* For simplicity, below we clear the pending events token
13251 without remembering whether it is marked, so here we always
13252 mark it. If there's actually no pending notification to
13253 process, this ends up being a no-op (other than a spurious
13254 event-loop wakeup). */
13255 if (target_is_non_stop_p ())
13256 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13260 serial_async (rs
->remote_desc
, NULL
, NULL
);
13261 /* If the core is disabling async, it doesn't want to be
13262 disturbed with target events. Clear all async event sources
13264 clear_async_event_handler (remote_async_inferior_event_token
);
13265 if (target_is_non_stop_p ())
13266 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13270 /* Implementation of the to_thread_events method. */
13273 remote_thread_events (struct target_ops
*ops
, int enable
)
13275 struct remote_state
*rs
= get_remote_state ();
13276 size_t size
= get_remote_packet_size ();
13278 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13281 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13283 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13285 switch (packet_ok (rs
->buf
,
13286 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13289 if (strcmp (rs
->buf
, "OK") != 0)
13290 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13293 warning (_("Remote failure reply: %s"), rs
->buf
);
13295 case PACKET_UNKNOWN
:
13301 set_remote_cmd (char *args
, int from_tty
)
13303 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13307 show_remote_cmd (char *args
, int from_tty
)
13309 /* We can't just use cmd_show_list here, because we want to skip
13310 the redundant "show remote Z-packet" and the legacy aliases. */
13311 struct cleanup
*showlist_chain
;
13312 struct cmd_list_element
*list
= remote_show_cmdlist
;
13313 struct ui_out
*uiout
= current_uiout
;
13315 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13316 for (; list
!= NULL
; list
= list
->next
)
13317 if (strcmp (list
->name
, "Z-packet") == 0)
13319 else if (list
->type
== not_set_cmd
)
13320 /* Alias commands are exactly like the original, except they
13321 don't have the normal type. */
13325 struct cleanup
*option_chain
13326 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13328 ui_out_field_string (uiout
, "name", list
->name
);
13329 ui_out_text (uiout
, ": ");
13330 if (list
->type
== show_cmd
)
13331 do_show_command ((char *) NULL
, from_tty
, list
);
13333 cmd_func (list
, NULL
, from_tty
);
13334 /* Close the tuple. */
13335 do_cleanups (option_chain
);
13338 /* Close the tuple. */
13339 do_cleanups (showlist_chain
);
13343 /* Function to be called whenever a new objfile (shlib) is detected. */
13345 remote_new_objfile (struct objfile
*objfile
)
13347 struct remote_state
*rs
= get_remote_state ();
13349 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13350 remote_check_symbols ();
13353 /* Pull all the tracepoints defined on the target and create local
13354 data structures representing them. We don't want to create real
13355 tracepoints yet, we don't want to mess up the user's existing
13359 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13361 struct remote_state
*rs
= get_remote_state ();
13364 /* Ask for a first packet of tracepoint definition. */
13366 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13368 while (*p
&& *p
!= 'l')
13370 parse_tracepoint_definition (p
, utpp
);
13371 /* Ask for another packet of tracepoint definition. */
13373 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13380 remote_upload_trace_state_variables (struct target_ops
*self
,
13381 struct uploaded_tsv
**utsvp
)
13383 struct remote_state
*rs
= get_remote_state ();
13386 /* Ask for a first packet of variable definition. */
13388 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13390 while (*p
&& *p
!= 'l')
13392 parse_tsv_definition (p
, utsvp
);
13393 /* Ask for another packet of variable definition. */
13395 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13401 /* The "set/show range-stepping" show hook. */
13404 show_range_stepping (struct ui_file
*file
, int from_tty
,
13405 struct cmd_list_element
*c
,
13408 fprintf_filtered (file
,
13409 _("Debugger's willingness to use range stepping "
13410 "is %s.\n"), value
);
13413 /* The "set/show range-stepping" set hook. */
13416 set_range_stepping (char *ignore_args
, int from_tty
,
13417 struct cmd_list_element
*c
)
13419 struct remote_state
*rs
= get_remote_state ();
13421 /* Whene enabling, check whether range stepping is actually
13422 supported by the target, and warn if not. */
13423 if (use_range_stepping
)
13425 if (rs
->remote_desc
!= NULL
)
13427 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13428 remote_vcont_probe (rs
);
13430 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13431 && rs
->supports_vCont
.r
)
13435 warning (_("Range stepping is not supported by the current target"));
13440 _initialize_remote (void)
13442 struct cmd_list_element
*cmd
;
13443 const char *cmd_name
;
13445 /* architecture specific data */
13446 remote_gdbarch_data_handle
=
13447 gdbarch_data_register_post_init (init_remote_state
);
13448 remote_g_packet_data_handle
=
13449 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13452 = register_program_space_data_with_cleanup (NULL
,
13453 remote_pspace_data_cleanup
);
13455 /* Initialize the per-target state. At the moment there is only one
13456 of these, not one per target. Only one target is active at a
13458 remote_state
= new_remote_state ();
13460 init_remote_ops ();
13461 add_target (&remote_ops
);
13463 init_extended_remote_ops ();
13464 add_target (&extended_remote_ops
);
13466 /* Hook into new objfile notification. */
13467 observer_attach_new_objfile (remote_new_objfile
);
13468 /* We're no longer interested in notification events of an inferior
13470 observer_attach_inferior_exit (discard_pending_stop_replies
);
13472 /* Set up signal handlers. */
13473 async_sigint_remote_token
=
13474 create_async_signal_handler (async_remote_interrupt
, NULL
);
13475 async_sigint_remote_twice_token
=
13476 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
13479 init_remote_threadtests ();
13482 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13483 /* set/show remote ... */
13485 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13486 Remote protocol specific variables\n\
13487 Configure various remote-protocol specific variables such as\n\
13488 the packets being used"),
13489 &remote_set_cmdlist
, "set remote ",
13490 0 /* allow-unknown */, &setlist
);
13491 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13492 Remote protocol specific variables\n\
13493 Configure various remote-protocol specific variables such as\n\
13494 the packets being used"),
13495 &remote_show_cmdlist
, "show remote ",
13496 0 /* allow-unknown */, &showlist
);
13498 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13499 Compare section data on target to the exec file.\n\
13500 Argument is a single section name (default: all loaded sections).\n\
13501 To compare only read-only loaded sections, specify the -r option."),
13504 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13505 Send an arbitrary packet to a remote target.\n\
13506 maintenance packet TEXT\n\
13507 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13508 this command sends the string TEXT to the inferior, and displays the\n\
13509 response packet. GDB supplies the initial `$' character, and the\n\
13510 terminating `#' character and checksum."),
13513 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13514 Set whether to send break if interrupted."), _("\
13515 Show whether to send break if interrupted."), _("\
13516 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13517 set_remotebreak
, show_remotebreak
,
13518 &setlist
, &showlist
);
13519 cmd_name
= "remotebreak";
13520 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13521 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13522 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13523 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13524 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13526 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13527 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13529 Set interrupt sequence to remote target."), _("\
13530 Show interrupt sequence to remote target."), _("\
13531 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13532 NULL
, show_interrupt_sequence
,
13533 &remote_set_cmdlist
,
13534 &remote_show_cmdlist
);
13536 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13537 &interrupt_on_connect
, _("\
13538 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13539 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13540 If set, interrupt sequence is sent to remote target."),
13542 &remote_set_cmdlist
, &remote_show_cmdlist
);
13544 /* Install commands for configuring memory read/write packets. */
13546 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13547 Set the maximum number of bytes per memory write packet (deprecated)."),
13549 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13550 Show the maximum number of bytes per memory write packet (deprecated)."),
13552 add_cmd ("memory-write-packet-size", no_class
,
13553 set_memory_write_packet_size
, _("\
13554 Set the maximum number of bytes per memory-write packet.\n\
13555 Specify the number of bytes in a packet or 0 (zero) for the\n\
13556 default packet size. The actual limit is further reduced\n\
13557 dependent on the target. Specify ``fixed'' to disable the\n\
13558 further restriction and ``limit'' to enable that restriction."),
13559 &remote_set_cmdlist
);
13560 add_cmd ("memory-read-packet-size", no_class
,
13561 set_memory_read_packet_size
, _("\
13562 Set the maximum number of bytes per memory-read packet.\n\
13563 Specify the number of bytes in a packet or 0 (zero) for the\n\
13564 default packet size. The actual limit is further reduced\n\
13565 dependent on the target. Specify ``fixed'' to disable the\n\
13566 further restriction and ``limit'' to enable that restriction."),
13567 &remote_set_cmdlist
);
13568 add_cmd ("memory-write-packet-size", no_class
,
13569 show_memory_write_packet_size
,
13570 _("Show the maximum number of bytes per memory-write packet."),
13571 &remote_show_cmdlist
);
13572 add_cmd ("memory-read-packet-size", no_class
,
13573 show_memory_read_packet_size
,
13574 _("Show the maximum number of bytes per memory-read packet."),
13575 &remote_show_cmdlist
);
13577 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13578 &remote_hw_watchpoint_limit
, _("\
13579 Set the maximum number of target hardware watchpoints."), _("\
13580 Show the maximum number of target hardware watchpoints."), _("\
13581 Specify a negative limit for unlimited."),
13582 NULL
, NULL
, /* FIXME: i18n: The maximum
13583 number of target hardware
13584 watchpoints is %s. */
13585 &remote_set_cmdlist
, &remote_show_cmdlist
);
13586 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13587 &remote_hw_watchpoint_length_limit
, _("\
13588 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13589 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13590 Specify a negative limit for unlimited."),
13591 NULL
, NULL
, /* FIXME: i18n: The maximum
13592 length (in bytes) of a target
13593 hardware watchpoint is %s. */
13594 &remote_set_cmdlist
, &remote_show_cmdlist
);
13595 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13596 &remote_hw_breakpoint_limit
, _("\
13597 Set the maximum number of target hardware breakpoints."), _("\
13598 Show the maximum number of target hardware breakpoints."), _("\
13599 Specify a negative limit for unlimited."),
13600 NULL
, NULL
, /* FIXME: i18n: The maximum
13601 number of target hardware
13602 breakpoints is %s. */
13603 &remote_set_cmdlist
, &remote_show_cmdlist
);
13605 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13606 &remote_address_size
, _("\
13607 Set the maximum size of the address (in bits) in a memory packet."), _("\
13608 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13610 NULL
, /* FIXME: i18n: */
13611 &setlist
, &showlist
);
13613 init_all_packet_configs ();
13615 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13616 "X", "binary-download", 1);
13618 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13619 "vCont", "verbose-resume", 0);
13621 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13622 "QPassSignals", "pass-signals", 0);
13624 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
13625 "QCatchSyscalls", "catch-syscalls", 0);
13627 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13628 "QProgramSignals", "program-signals", 0);
13630 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13631 "qSymbol", "symbol-lookup", 0);
13633 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13634 "P", "set-register", 1);
13636 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13637 "p", "fetch-register", 1);
13639 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13640 "Z0", "software-breakpoint", 0);
13642 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13643 "Z1", "hardware-breakpoint", 0);
13645 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13646 "Z2", "write-watchpoint", 0);
13648 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13649 "Z3", "read-watchpoint", 0);
13651 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13652 "Z4", "access-watchpoint", 0);
13654 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13655 "qXfer:auxv:read", "read-aux-vector", 0);
13657 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13658 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13660 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13661 "qXfer:features:read", "target-features", 0);
13663 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13664 "qXfer:libraries:read", "library-info", 0);
13666 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13667 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13669 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13670 "qXfer:memory-map:read", "memory-map", 0);
13672 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13673 "qXfer:spu:read", "read-spu-object", 0);
13675 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13676 "qXfer:spu:write", "write-spu-object", 0);
13678 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13679 "qXfer:osdata:read", "osdata", 0);
13681 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13682 "qXfer:threads:read", "threads", 0);
13684 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13685 "qXfer:siginfo:read", "read-siginfo-object", 0);
13687 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13688 "qXfer:siginfo:write", "write-siginfo-object", 0);
13690 add_packet_config_cmd
13691 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13692 "qXfer:traceframe-info:read", "traceframe-info", 0);
13694 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13695 "qXfer:uib:read", "unwind-info-block", 0);
13697 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13698 "qGetTLSAddr", "get-thread-local-storage-address",
13701 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13702 "qGetTIBAddr", "get-thread-information-block-address",
13705 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13706 "bc", "reverse-continue", 0);
13708 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13709 "bs", "reverse-step", 0);
13711 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13712 "qSupported", "supported-packets", 0);
13714 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13715 "qSearch:memory", "search-memory", 0);
13717 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13718 "qTStatus", "trace-status", 0);
13720 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13721 "vFile:setfs", "hostio-setfs", 0);
13723 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13724 "vFile:open", "hostio-open", 0);
13726 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13727 "vFile:pread", "hostio-pread", 0);
13729 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13730 "vFile:pwrite", "hostio-pwrite", 0);
13732 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13733 "vFile:close", "hostio-close", 0);
13735 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13736 "vFile:unlink", "hostio-unlink", 0);
13738 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13739 "vFile:readlink", "hostio-readlink", 0);
13741 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13742 "vFile:fstat", "hostio-fstat", 0);
13744 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13745 "vAttach", "attach", 0);
13747 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13750 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13751 "QStartNoAckMode", "noack", 0);
13753 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13754 "vKill", "kill", 0);
13756 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13757 "qAttached", "query-attached", 0);
13759 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13760 "ConditionalTracepoints",
13761 "conditional-tracepoints", 0);
13763 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13764 "ConditionalBreakpoints",
13765 "conditional-breakpoints", 0);
13767 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13768 "BreakpointCommands",
13769 "breakpoint-commands", 0);
13771 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13772 "FastTracepoints", "fast-tracepoints", 0);
13774 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13775 "TracepointSource", "TracepointSource", 0);
13777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13778 "QAllow", "allow", 0);
13780 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13781 "StaticTracepoints", "static-tracepoints", 0);
13783 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13784 "InstallInTrace", "install-in-trace", 0);
13786 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13787 "qXfer:statictrace:read", "read-sdata-object", 0);
13789 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13790 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13792 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13793 "QDisableRandomization", "disable-randomization", 0);
13795 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13796 "QAgent", "agent", 0);
13798 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13799 "QTBuffer:size", "trace-buffer-size", 0);
13801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13802 "Qbtrace:off", "disable-btrace", 0);
13804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13805 "Qbtrace:bts", "enable-btrace-bts", 0);
13807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13808 "Qbtrace:pt", "enable-btrace-pt", 0);
13810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13811 "qXfer:btrace", "read-btrace", 0);
13813 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13814 "qXfer:btrace-conf", "read-btrace-conf", 0);
13816 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13817 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13819 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13820 "multiprocess-feature", "multiprocess-feature", 0);
13822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13823 "swbreak-feature", "swbreak-feature", 0);
13825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13826 "hwbreak-feature", "hwbreak-feature", 0);
13828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13829 "fork-event-feature", "fork-event-feature", 0);
13831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13832 "vfork-event-feature", "vfork-event-feature", 0);
13834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13835 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13837 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13838 "vContSupported", "verbose-resume-supported", 0);
13840 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13841 "exec-event-feature", "exec-event-feature", 0);
13843 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
13844 "vCtrlC", "ctrl-c", 0);
13846 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
13847 "QThreadEvents", "thread-events", 0);
13849 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
13850 "N stop reply", "no-resumed-stop-reply", 0);
13852 /* Assert that we've registered "set remote foo-packet" commands
13853 for all packet configs. */
13857 for (i
= 0; i
< PACKET_MAX
; i
++)
13859 /* Ideally all configs would have a command associated. Some
13860 still don't though. */
13865 case PACKET_QNonStop
:
13866 case PACKET_EnableDisableTracepoints_feature
:
13867 case PACKET_tracenz_feature
:
13868 case PACKET_DisconnectedTracing_feature
:
13869 case PACKET_augmented_libraries_svr4_read_feature
:
13871 /* Additions to this list need to be well justified:
13872 pre-existing packets are OK; new packets are not. */
13880 /* This catches both forgetting to add a config command, and
13881 forgetting to remove a packet from the exception list. */
13882 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13886 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13887 Z sub-packet has its own set and show commands, but users may
13888 have sets to this variable in their .gdbinit files (or in their
13890 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13891 &remote_Z_packet_detect
, _("\
13892 Set use of remote protocol `Z' packets"), _("\
13893 Show use of remote protocol `Z' packets "), _("\
13894 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13896 set_remote_protocol_Z_packet_cmd
,
13897 show_remote_protocol_Z_packet_cmd
,
13898 /* FIXME: i18n: Use of remote protocol
13899 `Z' packets is %s. */
13900 &remote_set_cmdlist
, &remote_show_cmdlist
);
13902 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13903 Manipulate files on the remote system\n\
13904 Transfer files to and from the remote target system."),
13905 &remote_cmdlist
, "remote ",
13906 0 /* allow-unknown */, &cmdlist
);
13908 add_cmd ("put", class_files
, remote_put_command
,
13909 _("Copy a local file to the remote system."),
13912 add_cmd ("get", class_files
, remote_get_command
,
13913 _("Copy a remote file to the local system."),
13916 add_cmd ("delete", class_files
, remote_delete_command
,
13917 _("Delete a remote file."),
13920 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13921 &remote_exec_file_var
, _("\
13922 Set the remote pathname for \"run\""), _("\
13923 Show the remote pathname for \"run\""), NULL
,
13924 set_remote_exec_file
,
13925 show_remote_exec_file
,
13926 &remote_set_cmdlist
,
13927 &remote_show_cmdlist
);
13929 add_setshow_boolean_cmd ("range-stepping", class_run
,
13930 &use_range_stepping
, _("\
13931 Enable or disable range stepping."), _("\
13932 Show whether target-assisted range stepping is enabled."), _("\
13933 If on, and the target supports it, when stepping a source line, GDB\n\
13934 tells the target to step the corresponding range of addresses itself instead\n\
13935 of issuing multiple single-steps. This speeds up source level\n\
13936 stepping. If off, GDB always issues single-steps, even if range\n\
13937 stepping is supported by the target. The default is on."),
13938 set_range_stepping
,
13939 show_range_stepping
,
13943 /* Eventually initialize fileio. See fileio.c */
13944 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13946 /* Take advantage of the fact that the TID field is not used, to tag
13947 special ptids with it set to != 0. */
13948 magic_null_ptid
= ptid_build (42000, -1, 1);
13949 not_sent_ptid
= ptid_build (42000, -2, 1);
13950 any_thread_ptid
= ptid_build (42000, 0, 1);
13952 target_buf_size
= 2048;
13953 target_buf
= (char *) xmalloc (target_buf_size
);