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
, int executing
)
1806 struct remote_state
*rs
= get_remote_state ();
1808 /* GDB historically didn't pull threads in the initial connection
1809 setup. If the remote target doesn't even have a concept of
1810 threads (e.g., a bare-metal target), even if internally we
1811 consider that a single-threaded target, mentioning a new thread
1812 might be confusing to the user. Be silent then, preserving the
1813 age old behavior. */
1814 if (rs
->starting_up
)
1815 add_thread_silent (ptid
);
1819 set_executing (ptid
, executing
);
1820 set_running (ptid
, running
);
1823 /* Come here when we learn about a thread id from the remote target.
1824 It may be the first time we hear about such thread, so take the
1825 opportunity to add it to GDB's thread list. In case this is the
1826 first time we're noticing its corresponding inferior, add it to
1827 GDB's inferior list as well. EXECUTING indicates whether the
1828 thread is (internally) executing or stopped. */
1831 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1833 /* In non-stop mode, we assume new found threads are (externally)
1834 running until proven otherwise with a stop reply. In all-stop,
1835 we can only get here if all threads are stopped. */
1836 int running
= target_is_non_stop_p () ? 1 : 0;
1838 /* If this is a new thread, add it to GDB's thread list.
1839 If we leave it up to WFI to do this, bad things will happen. */
1841 if (in_thread_list (currthread
) && is_exited (currthread
))
1843 /* We're seeing an event on a thread id we knew had exited.
1844 This has to be a new thread reusing the old id. Add it. */
1845 remote_add_thread (currthread
, running
, executing
);
1849 if (!in_thread_list (currthread
))
1851 struct inferior
*inf
= NULL
;
1852 int pid
= ptid_get_pid (currthread
);
1854 if (ptid_is_pid (inferior_ptid
)
1855 && pid
== ptid_get_pid (inferior_ptid
))
1857 /* inferior_ptid has no thread member yet. This can happen
1858 with the vAttach -> remote_wait,"TAAthread:" path if the
1859 stub doesn't support qC. This is the first stop reported
1860 after an attach, so this is the main thread. Update the
1861 ptid in the thread list. */
1862 if (in_thread_list (pid_to_ptid (pid
)))
1863 thread_change_ptid (inferior_ptid
, currthread
);
1866 remote_add_thread (currthread
, running
, executing
);
1867 inferior_ptid
= currthread
;
1872 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1874 /* inferior_ptid is not set yet. This can happen with the
1875 vRun -> remote_wait,"TAAthread:" path if the stub
1876 doesn't support qC. This is the first stop reported
1877 after an attach, so this is the main thread. Update the
1878 ptid in the thread list. */
1879 thread_change_ptid (inferior_ptid
, currthread
);
1883 /* When connecting to a target remote, or to a target
1884 extended-remote which already was debugging an inferior, we
1885 may not know about it yet. Add it before adding its child
1886 thread, so notifications are emitted in a sensible order. */
1887 if (!in_inferior_list (ptid_get_pid (currthread
)))
1889 struct remote_state
*rs
= get_remote_state ();
1890 int fake_pid_p
= !remote_multi_process_p (rs
);
1892 inf
= remote_add_inferior (fake_pid_p
,
1893 ptid_get_pid (currthread
), -1, 1);
1896 /* This is really a new thread. Add it. */
1897 remote_add_thread (currthread
, running
, executing
);
1899 /* If we found a new inferior, let the common code do whatever
1900 it needs to with it (e.g., read shared libraries, insert
1901 breakpoints), unless we're just setting up an all-stop
1905 struct remote_state
*rs
= get_remote_state ();
1907 if (!rs
->starting_up
)
1908 notice_new_inferior (currthread
, executing
, 0);
1913 /* Return the private thread data, creating it if necessary. */
1915 static struct private_thread_info
*
1916 demand_private_info (ptid_t ptid
)
1918 struct thread_info
*info
= find_thread_ptid (ptid
);
1924 info
->priv
= XNEW (struct private_thread_info
);
1925 info
->private_dtor
= free_private_thread_info
;
1926 info
->priv
->core
= -1;
1927 info
->priv
->extra
= NULL
;
1928 info
->priv
->name
= NULL
;
1934 /* Call this function as a result of
1935 1) A halt indication (T packet) containing a thread id
1936 2) A direct query of currthread
1937 3) Successful execution of set thread */
1940 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1942 rs
->general_thread
= currthread
;
1945 /* If 'QPassSignals' is supported, tell the remote stub what signals
1946 it can simply pass through to the inferior without reporting. */
1949 remote_pass_signals (struct target_ops
*self
,
1950 int numsigs
, unsigned char *pass_signals
)
1952 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1954 char *pass_packet
, *p
;
1956 struct remote_state
*rs
= get_remote_state ();
1958 gdb_assert (numsigs
< 256);
1959 for (i
= 0; i
< numsigs
; i
++)
1961 if (pass_signals
[i
])
1964 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1965 strcpy (pass_packet
, "QPassSignals:");
1966 p
= pass_packet
+ strlen (pass_packet
);
1967 for (i
= 0; i
< numsigs
; i
++)
1969 if (pass_signals
[i
])
1972 *p
++ = tohex (i
>> 4);
1973 *p
++ = tohex (i
& 15);
1982 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1984 putpkt (pass_packet
);
1985 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1986 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1987 if (rs
->last_pass_packet
)
1988 xfree (rs
->last_pass_packet
);
1989 rs
->last_pass_packet
= pass_packet
;
1992 xfree (pass_packet
);
1996 /* If 'QCatchSyscalls' is supported, tell the remote stub
1997 to report syscalls to GDB. */
2000 remote_set_syscall_catchpoint (struct target_ops
*self
,
2001 int pid
, int needed
, int any_count
,
2002 int table_size
, int *table
)
2005 enum packet_result result
;
2008 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2010 /* Not supported. */
2014 if (needed
&& !any_count
)
2018 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2019 for (i
= 0; i
< table_size
; i
++)
2028 fprintf_unfiltered (gdb_stdlog
,
2029 "remote_set_syscall_catchpoint "
2030 "pid %d needed %d any_count %d n_sysno %d\n",
2031 pid
, needed
, any_count
, n_sysno
);
2036 /* Prepare a packet with the sysno list, assuming max 8+1
2037 characters for a sysno. If the resulting packet size is too
2038 big, fallback on the non-selective packet. */
2039 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2041 catch_packet
= (char *) xmalloc (maxpktsz
);
2042 strcpy (catch_packet
, "QCatchSyscalls:1");
2051 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2052 for (i
= 0; i
< table_size
; i
++)
2055 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2058 if (strlen (catch_packet
) > get_remote_packet_size ())
2060 /* catch_packet too big. Fallback to less efficient
2061 non selective mode, with GDB doing the filtering. */
2062 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2066 catch_packet
= xstrdup ("QCatchSyscalls:0");
2069 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2070 struct remote_state
*rs
= get_remote_state ();
2072 putpkt (catch_packet
);
2073 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2074 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2075 do_cleanups (old_chain
);
2076 if (result
== PACKET_OK
)
2083 /* If 'QProgramSignals' is supported, tell the remote stub what
2084 signals it should pass through to the inferior when detaching. */
2087 remote_program_signals (struct target_ops
*self
,
2088 int numsigs
, unsigned char *signals
)
2090 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2094 struct remote_state
*rs
= get_remote_state ();
2096 gdb_assert (numsigs
< 256);
2097 for (i
= 0; i
< numsigs
; i
++)
2102 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2103 strcpy (packet
, "QProgramSignals:");
2104 p
= packet
+ strlen (packet
);
2105 for (i
= 0; i
< numsigs
; i
++)
2107 if (signal_pass_state (i
))
2110 *p
++ = tohex (i
>> 4);
2111 *p
++ = tohex (i
& 15);
2120 if (!rs
->last_program_signals_packet
2121 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2124 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2125 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2126 xfree (rs
->last_program_signals_packet
);
2127 rs
->last_program_signals_packet
= packet
;
2134 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2135 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2136 thread. If GEN is set, set the general thread, if not, then set
2137 the step/continue thread. */
2139 set_thread (struct ptid ptid
, int gen
)
2141 struct remote_state
*rs
= get_remote_state ();
2142 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2143 char *buf
= rs
->buf
;
2144 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2146 if (ptid_equal (state
, ptid
))
2150 *buf
++ = gen
? 'g' : 'c';
2151 if (ptid_equal (ptid
, magic_null_ptid
))
2152 xsnprintf (buf
, endbuf
- buf
, "0");
2153 else if (ptid_equal (ptid
, any_thread_ptid
))
2154 xsnprintf (buf
, endbuf
- buf
, "0");
2155 else if (ptid_equal (ptid
, minus_one_ptid
))
2156 xsnprintf (buf
, endbuf
- buf
, "-1");
2158 write_ptid (buf
, endbuf
, ptid
);
2160 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2162 rs
->general_thread
= ptid
;
2164 rs
->continue_thread
= ptid
;
2168 set_general_thread (struct ptid ptid
)
2170 set_thread (ptid
, 1);
2174 set_continue_thread (struct ptid ptid
)
2176 set_thread (ptid
, 0);
2179 /* Change the remote current process. Which thread within the process
2180 ends up selected isn't important, as long as it is the same process
2181 as what INFERIOR_PTID points to.
2183 This comes from that fact that there is no explicit notion of
2184 "selected process" in the protocol. The selected process for
2185 general operations is the process the selected general thread
2189 set_general_process (void)
2191 struct remote_state
*rs
= get_remote_state ();
2193 /* If the remote can't handle multiple processes, don't bother. */
2194 if (!remote_multi_process_p (rs
))
2197 /* We only need to change the remote current thread if it's pointing
2198 at some other process. */
2199 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2200 set_general_thread (inferior_ptid
);
2204 /* Return nonzero if this is the main thread that we made up ourselves
2205 to model non-threaded targets as single-threaded. */
2208 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2210 if (ptid_equal (ptid
, magic_null_ptid
))
2211 /* The main thread is always alive. */
2214 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2215 /* The main thread is always alive. This can happen after a
2216 vAttach, if the remote side doesn't support
2223 /* Return nonzero if the thread PTID is still alive on the remote
2227 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2229 struct remote_state
*rs
= get_remote_state ();
2232 /* Check if this is a thread that we made up ourselves to model
2233 non-threaded targets as single-threaded. */
2234 if (remote_thread_always_alive (ops
, ptid
))
2238 endp
= rs
->buf
+ get_remote_packet_size ();
2241 write_ptid (p
, endp
, ptid
);
2244 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2245 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2248 /* Return a pointer to a thread name if we know it and NULL otherwise.
2249 The thread_info object owns the memory for the name. */
2252 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2254 if (info
->priv
!= NULL
)
2255 return info
->priv
->name
;
2260 /* About these extended threadlist and threadinfo packets. They are
2261 variable length packets but, the fields within them are often fixed
2262 length. They are redundent enough to send over UDP as is the
2263 remote protocol in general. There is a matching unit test module
2266 /* WARNING: This threadref data structure comes from the remote O.S.,
2267 libstub protocol encoding, and remote.c. It is not particularly
2270 /* Right now, the internal structure is int. We want it to be bigger.
2271 Plan to fix this. */
2273 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2275 /* gdb_ext_thread_info is an internal GDB data structure which is
2276 equivalent to the reply of the remote threadinfo packet. */
2278 struct gdb_ext_thread_info
2280 threadref threadid
; /* External form of thread reference. */
2281 int active
; /* Has state interesting to GDB?
2283 char display
[256]; /* Brief state display, name,
2284 blocked/suspended. */
2285 char shortname
[32]; /* To be used to name threads. */
2286 char more_display
[256]; /* Long info, statistics, queue depth,
2290 /* The volume of remote transfers can be limited by submitting
2291 a mask containing bits specifying the desired information.
2292 Use a union of these values as the 'selection' parameter to
2293 get_thread_info. FIXME: Make these TAG names more thread specific. */
2295 #define TAG_THREADID 1
2296 #define TAG_EXISTS 2
2297 #define TAG_DISPLAY 4
2298 #define TAG_THREADNAME 8
2299 #define TAG_MOREDISPLAY 16
2301 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2303 static char *unpack_nibble (char *buf
, int *val
);
2305 static char *unpack_byte (char *buf
, int *value
);
2307 static char *pack_int (char *buf
, int value
);
2309 static char *unpack_int (char *buf
, int *value
);
2311 static char *unpack_string (char *src
, char *dest
, int length
);
2313 static char *pack_threadid (char *pkt
, threadref
*id
);
2315 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2317 void int_to_threadref (threadref
*id
, int value
);
2319 static int threadref_to_int (threadref
*ref
);
2321 static void copy_threadref (threadref
*dest
, threadref
*src
);
2323 static int threadmatch (threadref
*dest
, threadref
*src
);
2325 static char *pack_threadinfo_request (char *pkt
, int mode
,
2328 static int remote_unpack_thread_info_response (char *pkt
,
2329 threadref
*expectedref
,
2330 struct gdb_ext_thread_info
2334 static int remote_get_threadinfo (threadref
*threadid
,
2335 int fieldset
, /*TAG mask */
2336 struct gdb_ext_thread_info
*info
);
2338 static char *pack_threadlist_request (char *pkt
, int startflag
,
2340 threadref
*nextthread
);
2342 static int parse_threadlist_response (char *pkt
,
2344 threadref
*original_echo
,
2345 threadref
*resultlist
,
2348 static int remote_get_threadlist (int startflag
,
2349 threadref
*nextthread
,
2353 threadref
*threadlist
);
2355 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2357 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2358 void *context
, int looplimit
);
2360 static int remote_newthread_step (threadref
*ref
, void *context
);
2363 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2364 buffer we're allowed to write to. Returns
2365 BUF+CHARACTERS_WRITTEN. */
2368 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2371 struct remote_state
*rs
= get_remote_state ();
2373 if (remote_multi_process_p (rs
))
2375 pid
= ptid_get_pid (ptid
);
2377 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2379 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2381 tid
= ptid_get_lwp (ptid
);
2383 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2385 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2390 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2391 passed the last parsed char. Returns null_ptid on error. */
2394 read_ptid (char *buf
, char **obuf
)
2398 ULONGEST pid
= 0, tid
= 0;
2402 /* Multi-process ptid. */
2403 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2405 error (_("invalid remote ptid: %s"), p
);
2408 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2411 return ptid_build (pid
, tid
, 0);
2414 /* No multi-process. Just a tid. */
2415 pp
= unpack_varlen_hex (p
, &tid
);
2417 /* Return null_ptid when no thread id is found. */
2425 /* Since the stub is not sending a process id, then default to
2426 what's in inferior_ptid, unless it's null at this point. If so,
2427 then since there's no way to know the pid of the reported
2428 threads, use the magic number. */
2429 if (ptid_equal (inferior_ptid
, null_ptid
))
2430 pid
= ptid_get_pid (magic_null_ptid
);
2432 pid
= ptid_get_pid (inferior_ptid
);
2436 return ptid_build (pid
, tid
, 0);
2442 if (ch
>= 'a' && ch
<= 'f')
2443 return ch
- 'a' + 10;
2444 if (ch
>= '0' && ch
<= '9')
2446 if (ch
>= 'A' && ch
<= 'F')
2447 return ch
- 'A' + 10;
2452 stub_unpack_int (char *buff
, int fieldlength
)
2459 nibble
= stubhex (*buff
++);
2463 retval
= retval
<< 4;
2469 unpack_nibble (char *buf
, int *val
)
2471 *val
= fromhex (*buf
++);
2476 unpack_byte (char *buf
, int *value
)
2478 *value
= stub_unpack_int (buf
, 2);
2483 pack_int (char *buf
, int value
)
2485 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2486 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2487 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2488 buf
= pack_hex_byte (buf
, (value
& 0xff));
2493 unpack_int (char *buf
, int *value
)
2495 *value
= stub_unpack_int (buf
, 8);
2499 #if 0 /* Currently unused, uncomment when needed. */
2500 static char *pack_string (char *pkt
, char *string
);
2503 pack_string (char *pkt
, char *string
)
2508 len
= strlen (string
);
2510 len
= 200; /* Bigger than most GDB packets, junk??? */
2511 pkt
= pack_hex_byte (pkt
, len
);
2515 if ((ch
== '\0') || (ch
== '#'))
2516 ch
= '*'; /* Protect encapsulation. */
2521 #endif /* 0 (unused) */
2524 unpack_string (char *src
, char *dest
, int length
)
2533 pack_threadid (char *pkt
, threadref
*id
)
2536 unsigned char *altid
;
2538 altid
= (unsigned char *) id
;
2539 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2541 pkt
= pack_hex_byte (pkt
, *altid
++);
2547 unpack_threadid (char *inbuf
, threadref
*id
)
2550 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2553 altref
= (char *) id
;
2555 while (inbuf
< limit
)
2557 x
= stubhex (*inbuf
++);
2558 y
= stubhex (*inbuf
++);
2559 *altref
++ = (x
<< 4) | y
;
2564 /* Externally, threadrefs are 64 bits but internally, they are still
2565 ints. This is due to a mismatch of specifications. We would like
2566 to use 64bit thread references internally. This is an adapter
2570 int_to_threadref (threadref
*id
, int value
)
2572 unsigned char *scan
;
2574 scan
= (unsigned char *) id
;
2580 *scan
++ = (value
>> 24) & 0xff;
2581 *scan
++ = (value
>> 16) & 0xff;
2582 *scan
++ = (value
>> 8) & 0xff;
2583 *scan
++ = (value
& 0xff);
2587 threadref_to_int (threadref
*ref
)
2590 unsigned char *scan
;
2596 value
= (value
<< 8) | ((*scan
++) & 0xff);
2601 copy_threadref (threadref
*dest
, threadref
*src
)
2604 unsigned char *csrc
, *cdest
;
2606 csrc
= (unsigned char *) src
;
2607 cdest
= (unsigned char *) dest
;
2614 threadmatch (threadref
*dest
, threadref
*src
)
2616 /* Things are broken right now, so just assume we got a match. */
2618 unsigned char *srcp
, *destp
;
2620 srcp
= (char *) src
;
2621 destp
= (char *) dest
;
2625 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2632 threadid:1, # always request threadid
2639 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2642 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2644 *pkt
++ = 'q'; /* Info Query */
2645 *pkt
++ = 'P'; /* process or thread info */
2646 pkt
= pack_int (pkt
, mode
); /* mode */
2647 pkt
= pack_threadid (pkt
, id
); /* threadid */
2648 *pkt
= '\0'; /* terminate */
2652 /* These values tag the fields in a thread info response packet. */
2653 /* Tagging the fields allows us to request specific fields and to
2654 add more fields as time goes by. */
2656 #define TAG_THREADID 1 /* Echo the thread identifier. */
2657 #define TAG_EXISTS 2 /* Is this process defined enough to
2658 fetch registers and its stack? */
2659 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2660 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2661 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2665 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2666 struct gdb_ext_thread_info
*info
)
2668 struct remote_state
*rs
= get_remote_state ();
2672 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2675 /* info->threadid = 0; FIXME: implement zero_threadref. */
2677 info
->display
[0] = '\0';
2678 info
->shortname
[0] = '\0';
2679 info
->more_display
[0] = '\0';
2681 /* Assume the characters indicating the packet type have been
2683 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2684 pkt
= unpack_threadid (pkt
, &ref
);
2687 warning (_("Incomplete response to threadinfo request."));
2688 if (!threadmatch (&ref
, expectedref
))
2689 { /* This is an answer to a different request. */
2690 warning (_("ERROR RMT Thread info mismatch."));
2693 copy_threadref (&info
->threadid
, &ref
);
2695 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2697 /* Packets are terminated with nulls. */
2698 while ((pkt
< limit
) && mask
&& *pkt
)
2700 pkt
= unpack_int (pkt
, &tag
); /* tag */
2701 pkt
= unpack_byte (pkt
, &length
); /* length */
2702 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2704 warning (_("ERROR RMT: threadinfo tag mismatch."));
2708 if (tag
== TAG_THREADID
)
2712 warning (_("ERROR RMT: length of threadid is not 16."));
2716 pkt
= unpack_threadid (pkt
, &ref
);
2717 mask
= mask
& ~TAG_THREADID
;
2720 if (tag
== TAG_EXISTS
)
2722 info
->active
= stub_unpack_int (pkt
, length
);
2724 mask
= mask
& ~(TAG_EXISTS
);
2727 warning (_("ERROR RMT: 'exists' length too long."));
2733 if (tag
== TAG_THREADNAME
)
2735 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2736 mask
= mask
& ~TAG_THREADNAME
;
2739 if (tag
== TAG_DISPLAY
)
2741 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2742 mask
= mask
& ~TAG_DISPLAY
;
2745 if (tag
== TAG_MOREDISPLAY
)
2747 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2748 mask
= mask
& ~TAG_MOREDISPLAY
;
2751 warning (_("ERROR RMT: unknown thread info tag."));
2752 break; /* Not a tag we know about. */
2758 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2759 struct gdb_ext_thread_info
*info
)
2761 struct remote_state
*rs
= get_remote_state ();
2764 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2768 if (rs
->buf
[0] == '\0')
2771 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2776 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2779 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2780 threadref
*nextthread
)
2782 *pkt
++ = 'q'; /* info query packet */
2783 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2784 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2785 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2786 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2791 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2794 parse_threadlist_response (char *pkt
, int result_limit
,
2795 threadref
*original_echo
, threadref
*resultlist
,
2798 struct remote_state
*rs
= get_remote_state ();
2800 int count
, resultcount
, done
;
2803 /* Assume the 'q' and 'M chars have been stripped. */
2804 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2805 /* done parse past here */
2806 pkt
= unpack_byte (pkt
, &count
); /* count field */
2807 pkt
= unpack_nibble (pkt
, &done
);
2808 /* The first threadid is the argument threadid. */
2809 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2810 while ((count
-- > 0) && (pkt
< limit
))
2812 pkt
= unpack_threadid (pkt
, resultlist
++);
2813 if (resultcount
++ >= result_limit
)
2821 /* Fetch the next batch of threads from the remote. Returns -1 if the
2822 qL packet is not supported, 0 on error and 1 on success. */
2825 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2826 int *done
, int *result_count
, threadref
*threadlist
)
2828 struct remote_state
*rs
= get_remote_state ();
2831 /* Trancate result limit to be smaller than the packet size. */
2832 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2833 >= get_remote_packet_size ())
2834 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2836 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2838 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2839 if (*rs
->buf
== '\0')
2841 /* Packet not supported. */
2846 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2847 &rs
->echo_nextthread
, threadlist
, done
);
2849 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2851 /* FIXME: This is a good reason to drop the packet. */
2852 /* Possably, there is a duplicate response. */
2854 retransmit immediatly - race conditions
2855 retransmit after timeout - yes
2857 wait for packet, then exit
2859 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2860 return 0; /* I choose simply exiting. */
2862 if (*result_count
<= 0)
2866 warning (_("RMT ERROR : failed to get remote thread list."));
2869 return result
; /* break; */
2871 if (*result_count
> result_limit
)
2874 warning (_("RMT ERROR: threadlist response longer than requested."));
2880 /* Fetch the list of remote threads, with the qL packet, and call
2881 STEPFUNCTION for each thread found. Stops iterating and returns 1
2882 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2883 STEPFUNCTION returns false. If the packet is not supported,
2887 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2890 struct remote_state
*rs
= get_remote_state ();
2891 int done
, i
, result_count
;
2899 if (loopcount
++ > looplimit
)
2902 warning (_("Remote fetch threadlist -infinite loop-."));
2905 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2906 MAXTHREADLISTRESULTS
,
2907 &done
, &result_count
,
2908 rs
->resultthreadlist
);
2911 /* Clear for later iterations. */
2913 /* Setup to resume next batch of thread references, set nextthread. */
2914 if (result_count
>= 1)
2915 copy_threadref (&rs
->nextthread
,
2916 &rs
->resultthreadlist
[result_count
- 1]);
2918 while (result_count
--)
2920 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2930 /* A thread found on the remote target. */
2932 typedef struct thread_item
2934 /* The thread's PTID. */
2937 /* The thread's extra info. May be NULL. */
2940 /* The thread's name. May be NULL. */
2943 /* The core the thread was running on. -1 if not known. */
2946 DEF_VEC_O(thread_item_t
);
2948 /* Context passed around to the various methods listing remote
2949 threads. As new threads are found, they're added to the ITEMS
2952 struct threads_listing_context
2954 /* The threads found on the remote target. */
2955 VEC (thread_item_t
) *items
;
2958 /* Discard the contents of the constructed thread listing context. */
2961 clear_threads_listing_context (void *p
)
2963 struct threads_listing_context
*context
2964 = (struct threads_listing_context
*) p
;
2966 struct thread_item
*item
;
2968 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2970 xfree (item
->extra
);
2974 VEC_free (thread_item_t
, context
->items
);
2977 /* Remove the thread specified as the related_pid field of WS
2978 from the CONTEXT list. */
2981 threads_listing_context_remove (struct target_waitstatus
*ws
,
2982 struct threads_listing_context
*context
)
2984 struct thread_item
*item
;
2986 ptid_t child_ptid
= ws
->value
.related_pid
;
2988 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2990 if (ptid_equal (item
->ptid
, child_ptid
))
2992 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2999 remote_newthread_step (threadref
*ref
, void *data
)
3001 struct threads_listing_context
*context
3002 = (struct threads_listing_context
*) data
;
3003 struct thread_item item
;
3004 int pid
= ptid_get_pid (inferior_ptid
);
3006 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3011 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3013 return 1; /* continue iterator */
3016 #define CRAZY_MAX_THREADS 1000
3019 remote_current_thread (ptid_t oldpid
)
3021 struct remote_state
*rs
= get_remote_state ();
3024 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3025 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3030 result
= read_ptid (&rs
->buf
[2], &obuf
);
3031 if (*obuf
!= '\0' && remote_debug
)
3032 fprintf_unfiltered (gdb_stdlog
,
3033 "warning: garbage in qC reply\n");
3041 /* List remote threads using the deprecated qL packet. */
3044 remote_get_threads_with_ql (struct target_ops
*ops
,
3045 struct threads_listing_context
*context
)
3047 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3048 CRAZY_MAX_THREADS
) >= 0)
3054 #if defined(HAVE_LIBEXPAT)
3057 start_thread (struct gdb_xml_parser
*parser
,
3058 const struct gdb_xml_element
*element
,
3059 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3061 struct threads_listing_context
*data
3062 = (struct threads_listing_context
*) user_data
;
3064 struct thread_item item
;
3066 struct gdb_xml_value
*attr
;
3068 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3069 item
.ptid
= read_ptid (id
, NULL
);
3071 attr
= xml_find_attribute (attributes
, "core");
3073 item
.core
= *(ULONGEST
*) attr
->value
;
3077 attr
= xml_find_attribute (attributes
, "name");
3078 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3082 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3086 end_thread (struct gdb_xml_parser
*parser
,
3087 const struct gdb_xml_element
*element
,
3088 void *user_data
, const char *body_text
)
3090 struct threads_listing_context
*data
3091 = (struct threads_listing_context
*) user_data
;
3093 if (body_text
&& *body_text
)
3094 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3097 const struct gdb_xml_attribute thread_attributes
[] = {
3098 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3099 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3100 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3101 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3104 const struct gdb_xml_element thread_children
[] = {
3105 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3108 const struct gdb_xml_element threads_children
[] = {
3109 { "thread", thread_attributes
, thread_children
,
3110 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3111 start_thread
, end_thread
},
3112 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3115 const struct gdb_xml_element threads_elements
[] = {
3116 { "threads", NULL
, threads_children
,
3117 GDB_XML_EF_NONE
, NULL
, NULL
},
3118 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3123 /* List remote threads using qXfer:threads:read. */
3126 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3127 struct threads_listing_context
*context
)
3129 #if defined(HAVE_LIBEXPAT)
3130 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3132 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3133 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3135 if (xml
!= NULL
&& *xml
!= '\0')
3137 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3138 threads_elements
, xml
, context
);
3141 do_cleanups (back_to
);
3149 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3152 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3153 struct threads_listing_context
*context
)
3155 struct remote_state
*rs
= get_remote_state ();
3157 if (rs
->use_threadinfo_query
)
3161 putpkt ("qfThreadInfo");
3162 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3164 if (bufp
[0] != '\0') /* q packet recognized */
3166 while (*bufp
++ == 'm') /* reply contains one or more TID */
3170 struct thread_item item
;
3172 item
.ptid
= read_ptid (bufp
, &bufp
);
3177 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3179 while (*bufp
++ == ','); /* comma-separated list */
3180 putpkt ("qsThreadInfo");
3181 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3188 /* Packet not recognized. */
3189 rs
->use_threadinfo_query
= 0;
3196 /* Implement the to_update_thread_list function for the remote
3200 remote_update_thread_list (struct target_ops
*ops
)
3202 struct threads_listing_context context
;
3203 struct cleanup
*old_chain
;
3206 context
.items
= NULL
;
3207 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3209 /* We have a few different mechanisms to fetch the thread list. Try
3210 them all, starting with the most preferred one first, falling
3211 back to older methods. */
3212 if (remote_get_threads_with_qxfer (ops
, &context
)
3213 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3214 || remote_get_threads_with_ql (ops
, &context
))
3217 struct thread_item
*item
;
3218 struct thread_info
*tp
, *tmp
;
3222 if (VEC_empty (thread_item_t
, context
.items
)
3223 && remote_thread_always_alive (ops
, inferior_ptid
))
3225 /* Some targets don't really support threads, but still
3226 reply an (empty) thread list in response to the thread
3227 listing packets, instead of replying "packet not
3228 supported". Exit early so we don't delete the main
3230 do_cleanups (old_chain
);
3234 /* CONTEXT now holds the current thread list on the remote
3235 target end. Delete GDB-side threads no longer found on the
3237 ALL_THREADS_SAFE (tp
, tmp
)
3240 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3243 if (ptid_equal (item
->ptid
, tp
->ptid
))
3247 if (i
== VEC_length (thread_item_t
, context
.items
))
3250 delete_thread (tp
->ptid
);
3254 /* Remove any unreported fork child threads from CONTEXT so
3255 that we don't interfere with follow fork, which is where
3256 creation of such threads is handled. */
3257 remove_new_fork_children (&context
);
3259 /* And now add threads we don't know about yet to our list. */
3261 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3264 if (!ptid_equal (item
->ptid
, null_ptid
))
3266 struct private_thread_info
*info
;
3267 /* In non-stop mode, we assume new found threads are
3268 executing until proven otherwise with a stop reply.
3269 In all-stop, we can only get here if all threads are
3271 int executing
= target_is_non_stop_p () ? 1 : 0;
3273 remote_notice_new_inferior (item
->ptid
, executing
);
3275 info
= demand_private_info (item
->ptid
);
3276 info
->core
= item
->core
;
3277 info
->extra
= item
->extra
;
3279 info
->name
= item
->name
;
3287 /* If no thread listing method is supported, then query whether
3288 each known thread is alive, one by one, with the T packet.
3289 If the target doesn't support threads at all, then this is a
3290 no-op. See remote_thread_alive. */
3294 do_cleanups (old_chain
);
3298 * Collect a descriptive string about the given thread.
3299 * The target may say anything it wants to about the thread
3300 * (typically info about its blocked / runnable state, name, etc.).
3301 * This string will appear in the info threads display.
3303 * Optional: targets are not required to implement this function.
3307 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3309 struct remote_state
*rs
= get_remote_state ();
3313 struct gdb_ext_thread_info threadinfo
;
3314 static char display_buf
[100]; /* arbitrary... */
3315 int n
= 0; /* position in display_buf */
3317 if (rs
->remote_desc
== 0) /* paranoia */
3318 internal_error (__FILE__
, __LINE__
,
3319 _("remote_threads_extra_info"));
3321 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3322 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3323 /* This is the main thread which was added by GDB. The remote
3324 server doesn't know about it. */
3327 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3329 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3331 if (info
&& info
->priv
)
3332 return info
->priv
->extra
;
3337 if (rs
->use_threadextra_query
)
3340 char *endb
= rs
->buf
+ get_remote_packet_size ();
3342 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3344 write_ptid (b
, endb
, tp
->ptid
);
3347 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3348 if (rs
->buf
[0] != 0)
3350 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3351 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3352 display_buf
[result
] = '\0';
3357 /* If the above query fails, fall back to the old method. */
3358 rs
->use_threadextra_query
= 0;
3359 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3360 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3361 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3362 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3363 if (threadinfo
.active
)
3365 if (*threadinfo
.shortname
)
3366 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3367 " Name: %s,", threadinfo
.shortname
);
3368 if (*threadinfo
.display
)
3369 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3370 " State: %s,", threadinfo
.display
);
3371 if (*threadinfo
.more_display
)
3372 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3373 " Priority: %s", threadinfo
.more_display
);
3377 /* For purely cosmetic reasons, clear up trailing commas. */
3378 if (',' == display_buf
[n
-1])
3379 display_buf
[n
-1] = ' ';
3388 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3389 struct static_tracepoint_marker
*marker
)
3391 struct remote_state
*rs
= get_remote_state ();
3394 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3396 p
+= hexnumstr (p
, addr
);
3398 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3402 error (_("Remote failure reply: %s"), p
);
3406 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3413 static VEC(static_tracepoint_marker_p
) *
3414 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3417 struct remote_state
*rs
= get_remote_state ();
3418 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3419 struct static_tracepoint_marker
*marker
= NULL
;
3420 struct cleanup
*old_chain
;
3423 /* Ask for a first packet of static tracepoint marker
3426 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3429 error (_("Remote failure reply: %s"), p
);
3431 old_chain
= make_cleanup (free_current_marker
, &marker
);
3436 marker
= XCNEW (struct static_tracepoint_marker
);
3440 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3442 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3444 VEC_safe_push (static_tracepoint_marker_p
,
3450 release_static_tracepoint_marker (marker
);
3451 memset (marker
, 0, sizeof (*marker
));
3454 while (*p
++ == ','); /* comma-separated list */
3455 /* Ask for another packet of static tracepoint definition. */
3457 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3461 do_cleanups (old_chain
);
3466 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3469 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3471 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3475 /* Restart the remote side; this is an extended protocol operation. */
3478 extended_remote_restart (void)
3480 struct remote_state
*rs
= get_remote_state ();
3482 /* Send the restart command; for reasons I don't understand the
3483 remote side really expects a number after the "R". */
3484 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3487 remote_fileio_reset ();
3490 /* Clean up connection to a remote debugger. */
3493 remote_close (struct target_ops
*self
)
3495 struct remote_state
*rs
= get_remote_state ();
3497 if (rs
->remote_desc
== NULL
)
3498 return; /* already closed */
3500 /* Make sure we leave stdin registered in the event loop, and we
3501 don't leave the async SIGINT signal handler installed. */
3502 remote_terminal_ours (self
);
3504 serial_close (rs
->remote_desc
);
3505 rs
->remote_desc
= NULL
;
3507 /* We don't have a connection to the remote stub anymore. Get rid
3508 of all the inferiors and their threads we were controlling.
3509 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3510 will be unable to find the thread corresponding to (pid, 0, 0). */
3511 inferior_ptid
= null_ptid
;
3512 discard_all_inferiors ();
3514 /* We are closing the remote target, so we should discard
3515 everything of this target. */
3516 discard_pending_stop_replies_in_queue (rs
);
3518 if (remote_async_inferior_event_token
)
3519 delete_async_event_handler (&remote_async_inferior_event_token
);
3521 remote_notif_state_xfree (rs
->notif_state
);
3523 trace_reset_local_state ();
3526 /* Query the remote side for the text, data and bss offsets. */
3531 struct remote_state
*rs
= get_remote_state ();
3534 int lose
, num_segments
= 0, do_sections
, do_segments
;
3535 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3536 struct section_offsets
*offs
;
3537 struct symfile_segment_data
*data
;
3539 if (symfile_objfile
== NULL
)
3542 putpkt ("qOffsets");
3543 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3546 if (buf
[0] == '\000')
3547 return; /* Return silently. Stub doesn't support
3551 warning (_("Remote failure reply: %s"), buf
);
3555 /* Pick up each field in turn. This used to be done with scanf, but
3556 scanf will make trouble if CORE_ADDR size doesn't match
3557 conversion directives correctly. The following code will work
3558 with any size of CORE_ADDR. */
3559 text_addr
= data_addr
= bss_addr
= 0;
3563 if (startswith (ptr
, "Text="))
3566 /* Don't use strtol, could lose on big values. */
3567 while (*ptr
&& *ptr
!= ';')
3568 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3570 if (startswith (ptr
, ";Data="))
3573 while (*ptr
&& *ptr
!= ';')
3574 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3579 if (!lose
&& startswith (ptr
, ";Bss="))
3582 while (*ptr
&& *ptr
!= ';')
3583 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3585 if (bss_addr
!= data_addr
)
3586 warning (_("Target reported unsupported offsets: %s"), buf
);
3591 else if (startswith (ptr
, "TextSeg="))
3594 /* Don't use strtol, could lose on big values. */
3595 while (*ptr
&& *ptr
!= ';')
3596 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3599 if (startswith (ptr
, ";DataSeg="))
3602 while (*ptr
&& *ptr
!= ';')
3603 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3611 error (_("Malformed response to offset query, %s"), buf
);
3612 else if (*ptr
!= '\0')
3613 warning (_("Target reported unsupported offsets: %s"), buf
);
3615 offs
= ((struct section_offsets
*)
3616 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3617 memcpy (offs
, symfile_objfile
->section_offsets
,
3618 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3620 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3621 do_segments
= (data
!= NULL
);
3622 do_sections
= num_segments
== 0;
3624 if (num_segments
> 0)
3626 segments
[0] = text_addr
;
3627 segments
[1] = data_addr
;
3629 /* If we have two segments, we can still try to relocate everything
3630 by assuming that the .text and .data offsets apply to the whole
3631 text and data segments. Convert the offsets given in the packet
3632 to base addresses for symfile_map_offsets_to_segments. */
3633 else if (data
&& data
->num_segments
== 2)
3635 segments
[0] = data
->segment_bases
[0] + text_addr
;
3636 segments
[1] = data
->segment_bases
[1] + data_addr
;
3639 /* If the object file has only one segment, assume that it is text
3640 rather than data; main programs with no writable data are rare,
3641 but programs with no code are useless. Of course the code might
3642 have ended up in the data segment... to detect that we would need
3643 the permissions here. */
3644 else if (data
&& data
->num_segments
== 1)
3646 segments
[0] = data
->segment_bases
[0] + text_addr
;
3649 /* There's no way to relocate by segment. */
3655 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3656 offs
, num_segments
, segments
);
3658 if (ret
== 0 && !do_sections
)
3659 error (_("Can not handle qOffsets TextSeg "
3660 "response with this symbol file"));
3667 free_symfile_segment_data (data
);
3671 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3673 /* This is a temporary kludge to force data and bss to use the
3674 same offsets because that's what nlmconv does now. The real
3675 solution requires changes to the stub and remote.c that I
3676 don't have time to do right now. */
3678 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3679 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3682 objfile_relocate (symfile_objfile
, offs
);
3685 /* Send interrupt_sequence to remote target. */
3687 send_interrupt_sequence (void)
3689 struct remote_state
*rs
= get_remote_state ();
3691 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3692 remote_serial_write ("\x03", 1);
3693 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3694 serial_send_break (rs
->remote_desc
);
3695 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3697 serial_send_break (rs
->remote_desc
);
3698 remote_serial_write ("g", 1);
3701 internal_error (__FILE__
, __LINE__
,
3702 _("Invalid value for interrupt_sequence_mode: %s."),
3703 interrupt_sequence_mode
);
3707 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3708 and extract the PTID. Returns NULL_PTID if not found. */
3711 stop_reply_extract_thread (char *stop_reply
)
3713 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3717 /* Txx r:val ; r:val (...) */
3720 /* Look for "register" named "thread". */
3725 p1
= strchr (p
, ':');
3729 if (strncmp (p
, "thread", p1
- p
) == 0)
3730 return read_ptid (++p1
, &p
);
3732 p1
= strchr (p
, ';');
3744 /* Determine the remote side's current thread. If we have a stop
3745 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3746 "thread" register we can extract the current thread from. If not,
3747 ask the remote which is the current thread with qC. The former
3748 method avoids a roundtrip. */
3751 get_current_thread (char *wait_status
)
3753 ptid_t ptid
= null_ptid
;
3755 /* Note we don't use remote_parse_stop_reply as that makes use of
3756 the target architecture, which we haven't yet fully determined at
3758 if (wait_status
!= NULL
)
3759 ptid
= stop_reply_extract_thread (wait_status
);
3760 if (ptid_equal (ptid
, null_ptid
))
3761 ptid
= remote_current_thread (inferior_ptid
);
3766 /* Query the remote target for which is the current thread/process,
3767 add it to our tables, and update INFERIOR_PTID. The caller is
3768 responsible for setting the state such that the remote end is ready
3769 to return the current thread.
3771 This function is called after handling the '?' or 'vRun' packets,
3772 whose response is a stop reply from which we can also try
3773 extracting the thread. If the target doesn't support the explicit
3774 qC query, we infer the current thread from that stop reply, passed
3775 in in WAIT_STATUS, which may be NULL. */
3778 add_current_inferior_and_thread (char *wait_status
)
3780 struct remote_state
*rs
= get_remote_state ();
3784 inferior_ptid
= null_ptid
;
3786 /* Now, if we have thread information, update inferior_ptid. */
3787 ptid
= get_current_thread (wait_status
);
3789 if (!ptid_equal (ptid
, null_ptid
))
3791 if (!remote_multi_process_p (rs
))
3794 inferior_ptid
= ptid
;
3798 /* Without this, some commands which require an active target
3799 (such as kill) won't work. This variable serves (at least)
3800 double duty as both the pid of the target process (if it has
3801 such), and as a flag indicating that a target is active. */
3802 inferior_ptid
= magic_null_ptid
;
3806 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3808 /* Add the main thread. */
3809 add_thread_silent (inferior_ptid
);
3812 /* Print info about a thread that was found already stopped on
3816 print_one_stopped_thread (struct thread_info
*thread
)
3818 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3820 switch_to_thread (thread
->ptid
);
3821 stop_pc
= get_frame_pc (get_current_frame ());
3822 set_current_sal_from_frame (get_current_frame ());
3824 thread
->suspend
.waitstatus_pending_p
= 0;
3826 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3828 enum gdb_signal sig
= ws
->value
.sig
;
3830 if (signal_print_state (sig
))
3831 observer_notify_signal_received (sig
);
3833 observer_notify_normal_stop (NULL
, 1);
3836 /* Process all initial stop replies the remote side sent in response
3837 to the ? packet. These indicate threads that were already stopped
3838 on initial connection. We mark these threads as stopped and print
3839 their current frame before giving the user the prompt. */
3842 process_initial_stop_replies (int from_tty
)
3844 int pending_stop_replies
= stop_reply_queue_length ();
3845 struct inferior
*inf
;
3846 struct thread_info
*thread
;
3847 struct thread_info
*selected
= NULL
;
3848 struct thread_info
*lowest_stopped
= NULL
;
3849 struct thread_info
*first
= NULL
;
3851 /* Consume the initial pending events. */
3852 while (pending_stop_replies
-- > 0)
3854 ptid_t waiton_ptid
= minus_one_ptid
;
3856 struct target_waitstatus ws
;
3857 int ignore_event
= 0;
3858 struct thread_info
*thread
;
3860 memset (&ws
, 0, sizeof (ws
));
3861 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3863 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3867 case TARGET_WAITKIND_IGNORE
:
3868 case TARGET_WAITKIND_NO_RESUMED
:
3869 case TARGET_WAITKIND_SIGNALLED
:
3870 case TARGET_WAITKIND_EXITED
:
3871 /* We shouldn't see these, but if we do, just ignore. */
3873 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3877 case TARGET_WAITKIND_EXECD
:
3878 xfree (ws
.value
.execd_pathname
);
3887 thread
= find_thread_ptid (event_ptid
);
3889 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3891 enum gdb_signal sig
= ws
.value
.sig
;
3893 /* Stubs traditionally report SIGTRAP as initial signal,
3894 instead of signal 0. Suppress it. */
3895 if (sig
== GDB_SIGNAL_TRAP
)
3897 thread
->suspend
.stop_signal
= sig
;
3901 thread
->suspend
.waitstatus
= ws
;
3903 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3904 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3905 thread
->suspend
.waitstatus_pending_p
= 1;
3907 set_executing (event_ptid
, 0);
3908 set_running (event_ptid
, 0);
3911 /* "Notice" the new inferiors before anything related to
3912 registers/memory. */
3918 inf
->needs_setup
= 1;
3922 thread
= any_live_thread_of_process (inf
->pid
);
3923 notice_new_inferior (thread
->ptid
,
3924 thread
->state
== THREAD_RUNNING
,
3929 /* If all-stop on top of non-stop, pause all threads. Note this
3930 records the threads' stop pc, so must be done after "noticing"
3934 stop_all_threads ();
3936 /* If all threads of an inferior were already stopped, we
3937 haven't setup the inferior yet. */
3943 if (inf
->needs_setup
)
3945 thread
= any_live_thread_of_process (inf
->pid
);
3946 switch_to_thread_no_regs (thread
);
3952 /* Now go over all threads that are stopped, and print their current
3953 frame. If all-stop, then if there's a signalled thread, pick
3955 ALL_NON_EXITED_THREADS (thread
)
3961 set_running (thread
->ptid
, 0);
3962 else if (thread
->state
!= THREAD_STOPPED
)
3965 if (selected
== NULL
3966 && thread
->suspend
.waitstatus_pending_p
)
3969 if (lowest_stopped
== NULL
3970 || thread
->inf
->num
< lowest_stopped
->inf
->num
3971 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
3972 lowest_stopped
= thread
;
3975 print_one_stopped_thread (thread
);
3978 /* In all-stop, we only print the status of one thread, and leave
3979 others with their status pending. */
3984 thread
= lowest_stopped
;
3988 print_one_stopped_thread (thread
);
3991 /* For "info program". */
3992 thread
= inferior_thread ();
3993 if (thread
->state
== THREAD_STOPPED
)
3994 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
3998 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4000 struct remote_state
*rs
= get_remote_state ();
4001 struct packet_config
*noack_config
;
4002 char *wait_status
= NULL
;
4004 immediate_quit
++; /* Allow user to interrupt it. */
4007 if (interrupt_on_connect
)
4008 send_interrupt_sequence ();
4010 /* Ack any packet which the remote side has already sent. */
4011 serial_write (rs
->remote_desc
, "+", 1);
4013 /* Signal other parts that we're going through the initial setup,
4014 and so things may not be stable yet. */
4015 rs
->starting_up
= 1;
4017 /* The first packet we send to the target is the optional "supported
4018 packets" request. If the target can answer this, it will tell us
4019 which later probes to skip. */
4020 remote_query_supported ();
4022 /* If the stub wants to get a QAllow, compose one and send it. */
4023 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4024 remote_set_permissions (target
);
4026 /* Next, we possibly activate noack mode.
4028 If the QStartNoAckMode packet configuration is set to AUTO,
4029 enable noack mode if the stub reported a wish for it with
4032 If set to TRUE, then enable noack mode even if the stub didn't
4033 report it in qSupported. If the stub doesn't reply OK, the
4034 session ends with an error.
4036 If FALSE, then don't activate noack mode, regardless of what the
4037 stub claimed should be the default with qSupported. */
4039 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4040 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4042 putpkt ("QStartNoAckMode");
4043 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4044 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4050 /* Tell the remote that we are using the extended protocol. */
4052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4055 /* Let the target know which signals it is allowed to pass down to
4057 update_signals_program_target ();
4059 /* Next, if the target can specify a description, read it. We do
4060 this before anything involving memory or registers. */
4061 target_find_description ();
4063 /* Next, now that we know something about the target, update the
4064 address spaces in the program spaces. */
4065 update_address_spaces ();
4067 /* On OSs where the list of libraries is global to all
4068 processes, we fetch them early. */
4069 if (gdbarch_has_global_solist (target_gdbarch ()))
4070 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4072 if (target_is_non_stop_p ())
4074 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4075 error (_("Non-stop mode requested, but remote "
4076 "does not support non-stop"));
4078 putpkt ("QNonStop:1");
4079 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4081 if (strcmp (rs
->buf
, "OK") != 0)
4082 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4084 /* Find about threads and processes the stub is already
4085 controlling. We default to adding them in the running state.
4086 The '?' query below will then tell us about which threads are
4088 remote_update_thread_list (target
);
4090 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4092 /* Don't assume that the stub can operate in all-stop mode.
4093 Request it explicitly. */
4094 putpkt ("QNonStop:0");
4095 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4097 if (strcmp (rs
->buf
, "OK") != 0)
4098 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4101 /* Upload TSVs regardless of whether the target is running or not. The
4102 remote stub, such as GDBserver, may have some predefined or builtin
4103 TSVs, even if the target is not running. */
4104 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4106 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4108 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4109 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4112 /* Check whether the target is running now. */
4114 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4116 if (!target_is_non_stop_p ())
4118 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4121 error (_("The target is not running (try extended-remote?)"));
4123 /* We're connected, but not running. Drop out before we
4124 call start_remote. */
4125 rs
->starting_up
= 0;
4130 /* Save the reply for later. */
4131 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4132 strcpy (wait_status
, rs
->buf
);
4135 /* Fetch thread list. */
4136 target_update_thread_list ();
4138 /* Let the stub know that we want it to return the thread. */
4139 set_continue_thread (minus_one_ptid
);
4141 if (thread_count () == 0)
4143 /* Target has no concept of threads at all. GDB treats
4144 non-threaded target as single-threaded; add a main
4146 add_current_inferior_and_thread (wait_status
);
4150 /* We have thread information; select the thread the target
4151 says should be current. If we're reconnecting to a
4152 multi-threaded program, this will ideally be the thread
4153 that last reported an event before GDB disconnected. */
4154 inferior_ptid
= get_current_thread (wait_status
);
4155 if (ptid_equal (inferior_ptid
, null_ptid
))
4157 /* Odd... The target was able to list threads, but not
4158 tell us which thread was current (no "thread"
4159 register in T stop reply?). Just pick the first
4160 thread in the thread list then. */
4163 fprintf_unfiltered (gdb_stdlog
,
4164 "warning: couldn't determine remote "
4165 "current thread; picking first in list.\n");
4167 inferior_ptid
= thread_list
->ptid
;
4171 /* init_wait_for_inferior should be called before get_offsets in order
4172 to manage `inserted' flag in bp loc in a correct state.
4173 breakpoint_init_inferior, called from init_wait_for_inferior, set
4174 `inserted' flag to 0, while before breakpoint_re_set, called from
4175 start_remote, set `inserted' flag to 1. In the initialization of
4176 inferior, breakpoint_init_inferior should be called first, and then
4177 breakpoint_re_set can be called. If this order is broken, state of
4178 `inserted' flag is wrong, and cause some problems on breakpoint
4180 init_wait_for_inferior ();
4182 get_offsets (); /* Get text, data & bss offsets. */
4184 /* If we could not find a description using qXfer, and we know
4185 how to do it some other way, try again. This is not
4186 supported for non-stop; it could be, but it is tricky if
4187 there are no stopped threads when we connect. */
4188 if (remote_read_description_p (target
)
4189 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4191 target_clear_description ();
4192 target_find_description ();
4195 /* Use the previously fetched status. */
4196 gdb_assert (wait_status
!= NULL
);
4197 strcpy (rs
->buf
, wait_status
);
4198 rs
->cached_wait_status
= 1;
4201 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4205 /* Clear WFI global state. Do this before finding about new
4206 threads and inferiors, and setting the current inferior.
4207 Otherwise we would clear the proceed status of the current
4208 inferior when we want its stop_soon state to be preserved
4209 (see notice_new_inferior). */
4210 init_wait_for_inferior ();
4212 /* In non-stop, we will either get an "OK", meaning that there
4213 are no stopped threads at this time; or, a regular stop
4214 reply. In the latter case, there may be more than one thread
4215 stopped --- we pull them all out using the vStopped
4217 if (strcmp (rs
->buf
, "OK") != 0)
4219 struct notif_client
*notif
= ¬if_client_stop
;
4221 /* remote_notif_get_pending_replies acks this one, and gets
4223 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4224 = remote_notif_parse (notif
, rs
->buf
);
4225 remote_notif_get_pending_events (notif
);
4228 if (thread_count () == 0)
4231 error (_("The target is not running (try extended-remote?)"));
4233 /* We're connected, but not running. Drop out before we
4234 call start_remote. */
4235 rs
->starting_up
= 0;
4239 /* In non-stop mode, any cached wait status will be stored in
4240 the stop reply queue. */
4241 gdb_assert (wait_status
== NULL
);
4243 /* Report all signals during attach/startup. */
4244 remote_pass_signals (target
, 0, NULL
);
4246 /* If there are already stopped threads, mark them stopped and
4247 report their stops before giving the prompt to the user. */
4248 process_initial_stop_replies (from_tty
);
4250 if (target_can_async_p ())
4254 /* If we connected to a live target, do some additional setup. */
4255 if (target_has_execution
)
4257 if (symfile_objfile
) /* No use without a symbol-file. */
4258 remote_check_symbols ();
4261 /* Possibly the target has been engaged in a trace run started
4262 previously; find out where things are at. */
4263 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4265 struct uploaded_tp
*uploaded_tps
= NULL
;
4267 if (current_trace_status ()->running
)
4268 printf_filtered (_("Trace is already running on the target.\n"));
4270 remote_upload_tracepoints (target
, &uploaded_tps
);
4272 merge_uploaded_tracepoints (&uploaded_tps
);
4275 /* The thread and inferior lists are now synchronized with the
4276 target, our symbols have been relocated, and we're merged the
4277 target's tracepoints with ours. We're done with basic start
4279 rs
->starting_up
= 0;
4281 /* Maybe breakpoints are global and need to be inserted now. */
4282 if (breakpoints_should_be_inserted_now ())
4283 insert_breakpoints ();
4286 /* Open a connection to a remote debugger.
4287 NAME is the filename used for communication. */
4290 remote_open (const char *name
, int from_tty
)
4292 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4295 /* Open a connection to a remote debugger using the extended
4296 remote gdb protocol. NAME is the filename used for communication. */
4299 extended_remote_open (const char *name
, int from_tty
)
4301 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4304 /* Reset all packets back to "unknown support". Called when opening a
4305 new connection to a remote target. */
4308 reset_all_packet_configs_support (void)
4312 for (i
= 0; i
< PACKET_MAX
; i
++)
4313 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4316 /* Initialize all packet configs. */
4319 init_all_packet_configs (void)
4323 for (i
= 0; i
< PACKET_MAX
; i
++)
4325 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4326 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4330 /* Symbol look-up. */
4333 remote_check_symbols (void)
4335 struct remote_state
*rs
= get_remote_state ();
4336 char *msg
, *reply
, *tmp
;
4339 struct cleanup
*old_chain
;
4341 /* The remote side has no concept of inferiors that aren't running
4342 yet, it only knows about running processes. If we're connected
4343 but our current inferior is not running, we should not invite the
4344 remote target to request symbol lookups related to its
4345 (unrelated) current process. */
4346 if (!target_has_execution
)
4349 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4352 /* Make sure the remote is pointing at the right process. Note
4353 there's no way to select "no process". */
4354 set_general_process ();
4356 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4357 because we need both at the same time. */
4358 msg
= (char *) xmalloc (get_remote_packet_size ());
4359 old_chain
= make_cleanup (xfree
, msg
);
4360 reply
= (char *) xmalloc (get_remote_packet_size ());
4361 make_cleanup (free_current_contents
, &reply
);
4362 reply_size
= get_remote_packet_size ();
4364 /* Invite target to request symbol lookups. */
4366 putpkt ("qSymbol::");
4367 getpkt (&reply
, &reply_size
, 0);
4368 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4370 while (startswith (reply
, "qSymbol:"))
4372 struct bound_minimal_symbol sym
;
4375 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4377 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4378 if (sym
.minsym
== NULL
)
4379 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4382 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4383 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4385 /* If this is a function address, return the start of code
4386 instead of any data function descriptor. */
4387 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4391 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4392 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4396 getpkt (&reply
, &reply_size
, 0);
4399 do_cleanups (old_chain
);
4402 static struct serial
*
4403 remote_serial_open (const char *name
)
4405 static int udp_warning
= 0;
4407 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4408 of in ser-tcp.c, because it is the remote protocol assuming that the
4409 serial connection is reliable and not the serial connection promising
4411 if (!udp_warning
&& startswith (name
, "udp:"))
4413 warning (_("The remote protocol may be unreliable over UDP.\n"
4414 "Some events may be lost, rendering further debugging "
4419 return serial_open (name
);
4422 /* Inform the target of our permission settings. The permission flags
4423 work without this, but if the target knows the settings, it can do
4424 a couple things. First, it can add its own check, to catch cases
4425 that somehow manage to get by the permissions checks in target
4426 methods. Second, if the target is wired to disallow particular
4427 settings (for instance, a system in the field that is not set up to
4428 be able to stop at a breakpoint), it can object to any unavailable
4432 remote_set_permissions (struct target_ops
*self
)
4434 struct remote_state
*rs
= get_remote_state ();
4436 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4437 "WriteReg:%x;WriteMem:%x;"
4438 "InsertBreak:%x;InsertTrace:%x;"
4439 "InsertFastTrace:%x;Stop:%x",
4440 may_write_registers
, may_write_memory
,
4441 may_insert_breakpoints
, may_insert_tracepoints
,
4442 may_insert_fast_tracepoints
, may_stop
);
4444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4446 /* If the target didn't like the packet, warn the user. Do not try
4447 to undo the user's settings, that would just be maddening. */
4448 if (strcmp (rs
->buf
, "OK") != 0)
4449 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4452 /* This type describes each known response to the qSupported
4454 struct protocol_feature
4456 /* The name of this protocol feature. */
4459 /* The default for this protocol feature. */
4460 enum packet_support default_support
;
4462 /* The function to call when this feature is reported, or after
4463 qSupported processing if the feature is not supported.
4464 The first argument points to this structure. The second
4465 argument indicates whether the packet requested support be
4466 enabled, disabled, or probed (or the default, if this function
4467 is being called at the end of processing and this feature was
4468 not reported). The third argument may be NULL; if not NULL, it
4469 is a NUL-terminated string taken from the packet following
4470 this feature's name and an equals sign. */
4471 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4474 /* The corresponding packet for this feature. Only used if
4475 FUNC is remote_supported_packet. */
4480 remote_supported_packet (const struct protocol_feature
*feature
,
4481 enum packet_support support
,
4482 const char *argument
)
4486 warning (_("Remote qSupported response supplied an unexpected value for"
4487 " \"%s\"."), feature
->name
);
4491 remote_protocol_packets
[feature
->packet
].support
= support
;
4495 remote_packet_size (const struct protocol_feature
*feature
,
4496 enum packet_support support
, const char *value
)
4498 struct remote_state
*rs
= get_remote_state ();
4503 if (support
!= PACKET_ENABLE
)
4506 if (value
== NULL
|| *value
== '\0')
4508 warning (_("Remote target reported \"%s\" without a size."),
4514 packet_size
= strtol (value
, &value_end
, 16);
4515 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4517 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4518 feature
->name
, value
);
4522 /* Record the new maximum packet size. */
4523 rs
->explicit_packet_size
= packet_size
;
4526 static const struct protocol_feature remote_protocol_features
[] = {
4527 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4528 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4529 PACKET_qXfer_auxv
},
4530 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4531 PACKET_qXfer_exec_file
},
4532 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4533 PACKET_qXfer_features
},
4534 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4535 PACKET_qXfer_libraries
},
4536 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4537 PACKET_qXfer_libraries_svr4
},
4538 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4539 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4540 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4541 PACKET_qXfer_memory_map
},
4542 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4543 PACKET_qXfer_spu_read
},
4544 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4545 PACKET_qXfer_spu_write
},
4546 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4547 PACKET_qXfer_osdata
},
4548 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4549 PACKET_qXfer_threads
},
4550 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4551 PACKET_qXfer_traceframe_info
},
4552 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4553 PACKET_QPassSignals
},
4554 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4555 PACKET_QCatchSyscalls
},
4556 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4557 PACKET_QProgramSignals
},
4558 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4559 PACKET_QStartNoAckMode
},
4560 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4561 PACKET_multiprocess_feature
},
4562 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4563 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4564 PACKET_qXfer_siginfo_read
},
4565 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4566 PACKET_qXfer_siginfo_write
},
4567 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4568 PACKET_ConditionalTracepoints
},
4569 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4570 PACKET_ConditionalBreakpoints
},
4571 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4572 PACKET_BreakpointCommands
},
4573 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4574 PACKET_FastTracepoints
},
4575 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4576 PACKET_StaticTracepoints
},
4577 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4578 PACKET_InstallInTrace
},
4579 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4580 PACKET_DisconnectedTracing_feature
},
4581 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4583 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4585 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4586 PACKET_TracepointSource
},
4587 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4589 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4590 PACKET_EnableDisableTracepoints_feature
},
4591 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4592 PACKET_qXfer_fdpic
},
4593 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4595 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4596 PACKET_QDisableRandomization
},
4597 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4598 { "QTBuffer:size", PACKET_DISABLE
,
4599 remote_supported_packet
, PACKET_QTBuffer_size
},
4600 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4601 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4602 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4603 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4604 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4605 PACKET_qXfer_btrace
},
4606 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4607 PACKET_qXfer_btrace_conf
},
4608 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4609 PACKET_Qbtrace_conf_bts_size
},
4610 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4611 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4612 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4613 PACKET_fork_event_feature
},
4614 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4615 PACKET_vfork_event_feature
},
4616 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4617 PACKET_exec_event_feature
},
4618 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4619 PACKET_Qbtrace_conf_pt_size
},
4620 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4621 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4622 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4625 static char *remote_support_xml
;
4627 /* Register string appended to "xmlRegisters=" in qSupported query. */
4630 register_remote_support_xml (const char *xml
)
4632 #if defined(HAVE_LIBEXPAT)
4633 if (remote_support_xml
== NULL
)
4634 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4637 char *copy
= xstrdup (remote_support_xml
+ 13);
4638 char *p
= strtok (copy
, ",");
4642 if (strcmp (p
, xml
) == 0)
4649 while ((p
= strtok (NULL
, ",")) != NULL
);
4652 remote_support_xml
= reconcat (remote_support_xml
,
4653 remote_support_xml
, ",", xml
,
4660 remote_query_supported_append (char *msg
, const char *append
)
4663 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4665 return xstrdup (append
);
4669 remote_query_supported (void)
4671 struct remote_state
*rs
= get_remote_state ();
4674 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4676 /* The packet support flags are handled differently for this packet
4677 than for most others. We treat an error, a disabled packet, and
4678 an empty response identically: any features which must be reported
4679 to be used will be automatically disabled. An empty buffer
4680 accomplishes this, since that is also the representation for a list
4681 containing no features. */
4684 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4687 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4689 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4690 q
= remote_query_supported_append (q
, "multiprocess+");
4692 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4693 q
= remote_query_supported_append (q
, "swbreak+");
4694 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4695 q
= remote_query_supported_append (q
, "hwbreak+");
4697 q
= remote_query_supported_append (q
, "qRelocInsn+");
4699 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4700 != AUTO_BOOLEAN_FALSE
)
4701 q
= remote_query_supported_append (q
, "fork-events+");
4702 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4703 != AUTO_BOOLEAN_FALSE
)
4704 q
= remote_query_supported_append (q
, "vfork-events+");
4705 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4706 != AUTO_BOOLEAN_FALSE
)
4707 q
= remote_query_supported_append (q
, "exec-events+");
4709 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4710 q
= remote_query_supported_append (q
, "vContSupported+");
4712 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4713 q
= remote_query_supported_append (q
, "QThreadEvents+");
4715 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4716 q
= remote_query_supported_append (q
, "no-resumed+");
4718 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4719 the qSupported:xmlRegisters=i386 handling. */
4720 if (remote_support_xml
!= NULL
)
4721 q
= remote_query_supported_append (q
, remote_support_xml
);
4723 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4726 do_cleanups (old_chain
);
4728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4730 /* If an error occured, warn, but do not return - just reset the
4731 buffer to empty and go on to disable features. */
4732 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4735 warning (_("Remote failure reply: %s"), rs
->buf
);
4740 memset (seen
, 0, sizeof (seen
));
4745 enum packet_support is_supported
;
4746 char *p
, *end
, *name_end
, *value
;
4748 /* First separate out this item from the rest of the packet. If
4749 there's another item after this, we overwrite the separator
4750 (terminated strings are much easier to work with). */
4752 end
= strchr (p
, ';');
4755 end
= p
+ strlen (p
);
4765 warning (_("empty item in \"qSupported\" response"));
4770 name_end
= strchr (p
, '=');
4773 /* This is a name=value entry. */
4774 is_supported
= PACKET_ENABLE
;
4775 value
= name_end
+ 1;
4784 is_supported
= PACKET_ENABLE
;
4788 is_supported
= PACKET_DISABLE
;
4792 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4796 warning (_("unrecognized item \"%s\" "
4797 "in \"qSupported\" response"), p
);
4803 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4804 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4806 const struct protocol_feature
*feature
;
4809 feature
= &remote_protocol_features
[i
];
4810 feature
->func (feature
, is_supported
, value
);
4815 /* If we increased the packet size, make sure to increase the global
4816 buffer size also. We delay this until after parsing the entire
4817 qSupported packet, because this is the same buffer we were
4819 if (rs
->buf_size
< rs
->explicit_packet_size
)
4821 rs
->buf_size
= rs
->explicit_packet_size
;
4822 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4825 /* Handle the defaults for unmentioned features. */
4826 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4829 const struct protocol_feature
*feature
;
4831 feature
= &remote_protocol_features
[i
];
4832 feature
->func (feature
, feature
->default_support
, NULL
);
4836 /* Remove any of the remote.c targets from target stack. Upper targets depend
4837 on it so remove them first. */
4840 remote_unpush_target (void)
4842 pop_all_targets_at_and_above (process_stratum
);
4846 remote_open_1 (const char *name
, int from_tty
,
4847 struct target_ops
*target
, int extended_p
)
4849 struct remote_state
*rs
= get_remote_state ();
4852 error (_("To open a remote debug connection, you need to specify what\n"
4853 "serial device is attached to the remote system\n"
4854 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4856 /* See FIXME above. */
4857 if (!target_async_permitted
)
4858 wait_forever_enabled_p
= 1;
4860 /* If we're connected to a running target, target_preopen will kill it.
4861 Ask this question first, before target_preopen has a chance to kill
4863 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4866 && !query (_("Already connected to a remote target. Disconnect? ")))
4867 error (_("Still connected."));
4870 /* Here the possibly existing remote target gets unpushed. */
4871 target_preopen (from_tty
);
4873 /* Make sure we send the passed signals list the next time we resume. */
4874 xfree (rs
->last_pass_packet
);
4875 rs
->last_pass_packet
= NULL
;
4877 /* Make sure we send the program signals list the next time we
4879 xfree (rs
->last_program_signals_packet
);
4880 rs
->last_program_signals_packet
= NULL
;
4882 remote_fileio_reset ();
4883 reopen_exec_file ();
4886 rs
->remote_desc
= remote_serial_open (name
);
4887 if (!rs
->remote_desc
)
4888 perror_with_name (name
);
4890 if (baud_rate
!= -1)
4892 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4894 /* The requested speed could not be set. Error out to
4895 top level after closing remote_desc. Take care to
4896 set remote_desc to NULL to avoid closing remote_desc
4898 serial_close (rs
->remote_desc
);
4899 rs
->remote_desc
= NULL
;
4900 perror_with_name (name
);
4904 serial_setparity (rs
->remote_desc
, serial_parity
);
4905 serial_raw (rs
->remote_desc
);
4907 /* If there is something sitting in the buffer we might take it as a
4908 response to a command, which would be bad. */
4909 serial_flush_input (rs
->remote_desc
);
4913 puts_filtered ("Remote debugging using ");
4914 puts_filtered (name
);
4915 puts_filtered ("\n");
4917 push_target (target
); /* Switch to using remote target now. */
4919 /* Register extra event sources in the event loop. */
4920 remote_async_inferior_event_token
4921 = create_async_event_handler (remote_async_inferior_event_handler
,
4923 rs
->notif_state
= remote_notif_state_allocate ();
4925 /* Reset the target state; these things will be queried either by
4926 remote_query_supported or as they are needed. */
4927 reset_all_packet_configs_support ();
4928 rs
->cached_wait_status
= 0;
4929 rs
->explicit_packet_size
= 0;
4931 rs
->extended
= extended_p
;
4932 rs
->waiting_for_stop_reply
= 0;
4933 rs
->ctrlc_pending_p
= 0;
4935 rs
->general_thread
= not_sent_ptid
;
4936 rs
->continue_thread
= not_sent_ptid
;
4937 rs
->remote_traceframe_number
= -1;
4939 /* Probe for ability to use "ThreadInfo" query, as required. */
4940 rs
->use_threadinfo_query
= 1;
4941 rs
->use_threadextra_query
= 1;
4943 readahead_cache_invalidate ();
4945 if (target_async_permitted
)
4947 /* With this target we start out by owning the terminal. */
4948 remote_async_terminal_ours_p
= 1;
4950 /* FIXME: cagney/1999-09-23: During the initial connection it is
4951 assumed that the target is already ready and able to respond to
4952 requests. Unfortunately remote_start_remote() eventually calls
4953 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4954 around this. Eventually a mechanism that allows
4955 wait_for_inferior() to expect/get timeouts will be
4957 wait_forever_enabled_p
= 0;
4960 /* First delete any symbols previously loaded from shared libraries. */
4961 no_shared_libraries (NULL
, 0);
4964 init_thread_list ();
4966 /* Start the remote connection. If error() or QUIT, discard this
4967 target (we'd otherwise be in an inconsistent state) and then
4968 propogate the error on up the exception chain. This ensures that
4969 the caller doesn't stumble along blindly assuming that the
4970 function succeeded. The CLI doesn't have this problem but other
4971 UI's, such as MI do.
4973 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4974 this function should return an error indication letting the
4975 caller restore the previous state. Unfortunately the command
4976 ``target remote'' is directly wired to this function making that
4977 impossible. On a positive note, the CLI side of this problem has
4978 been fixed - the function set_cmd_context() makes it possible for
4979 all the ``target ....'' commands to share a common callback
4980 function. See cli-dump.c. */
4985 remote_start_remote (from_tty
, target
, extended_p
);
4987 CATCH (ex
, RETURN_MASK_ALL
)
4989 /* Pop the partially set up target - unless something else did
4990 already before throwing the exception. */
4991 if (rs
->remote_desc
!= NULL
)
4992 remote_unpush_target ();
4993 if (target_async_permitted
)
4994 wait_forever_enabled_p
= 1;
4995 throw_exception (ex
);
5000 remote_btrace_reset ();
5002 if (target_async_permitted
)
5003 wait_forever_enabled_p
= 1;
5006 /* Detach the specified process. */
5009 remote_detach_pid (int pid
)
5011 struct remote_state
*rs
= get_remote_state ();
5013 if (remote_multi_process_p (rs
))
5014 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5016 strcpy (rs
->buf
, "D");
5019 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5021 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5023 else if (rs
->buf
[0] == '\0')
5024 error (_("Remote doesn't know how to detach"));
5026 error (_("Can't detach process."));
5029 /* This detaches a program to which we previously attached, using
5030 inferior_ptid to identify the process. After this is done, GDB
5031 can be used to debug some other program. We better not have left
5032 any breakpoints in the target program or it'll die when it hits
5036 remote_detach_1 (const char *args
, int from_tty
)
5038 int pid
= ptid_get_pid (inferior_ptid
);
5039 struct remote_state
*rs
= get_remote_state ();
5040 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5044 error (_("Argument given to \"detach\" when remotely debugging."));
5046 if (!target_has_execution
)
5047 error (_("No process to detach from."));
5051 char *exec_file
= get_exec_file (0);
5052 if (exec_file
== NULL
)
5054 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
5055 target_pid_to_str (pid_to_ptid (pid
)));
5056 gdb_flush (gdb_stdout
);
5059 /* Tell the remote target to detach. */
5060 remote_detach_pid (pid
);
5062 /* Exit only if this is the only active inferior. */
5063 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5064 puts_filtered (_("Ending remote debugging.\n"));
5066 /* Check to see if we are detaching a fork parent. Note that if we
5067 are detaching a fork child, tp == NULL. */
5068 is_fork_parent
= (tp
!= NULL
5069 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5071 /* If doing detach-on-fork, we don't mourn, because that will delete
5072 breakpoints that should be available for the followed inferior. */
5073 if (!is_fork_parent
)
5074 target_mourn_inferior ();
5077 inferior_ptid
= null_ptid
;
5078 detach_inferior (pid
);
5083 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5085 remote_detach_1 (args
, from_tty
);
5089 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5091 remote_detach_1 (args
, from_tty
);
5094 /* Target follow-fork function for remote targets. On entry, and
5095 at return, the current inferior is the fork parent.
5097 Note that although this is currently only used for extended-remote,
5098 it is named remote_follow_fork in anticipation of using it for the
5099 remote target as well. */
5102 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5105 struct remote_state
*rs
= get_remote_state ();
5106 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5108 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5109 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5111 /* When following the parent and detaching the child, we detach
5112 the child here. For the case of following the child and
5113 detaching the parent, the detach is done in the target-
5114 independent follow fork code in infrun.c. We can't use
5115 target_detach when detaching an unfollowed child because
5116 the client side doesn't know anything about the child. */
5117 if (detach_fork
&& !follow_child
)
5119 /* Detach the fork child. */
5123 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5124 child_pid
= ptid_get_pid (child_ptid
);
5126 remote_detach_pid (child_pid
);
5127 detach_inferior (child_pid
);
5133 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5134 in the program space of the new inferior. On entry and at return the
5135 current inferior is the exec'ing inferior. INF is the new exec'd
5136 inferior, which may be the same as the exec'ing inferior unless
5137 follow-exec-mode is "new". */
5140 remote_follow_exec (struct target_ops
*ops
,
5141 struct inferior
*inf
, char *execd_pathname
)
5143 /* We know that this is a target file name, so if it has the "target:"
5144 prefix we strip it off before saving it in the program space. */
5145 if (is_target_filename (execd_pathname
))
5146 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5148 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5151 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5154 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5157 error (_("Argument given to \"disconnect\" when remotely debugging."));
5159 /* Make sure we unpush even the extended remote targets. Calling
5160 target_mourn_inferior won't unpush, and remote_mourn won't
5161 unpush if there is more than one inferior left. */
5162 unpush_target (target
);
5163 generic_mourn_inferior ();
5166 puts_filtered ("Ending remote debugging.\n");
5169 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5170 be chatty about it. */
5173 extended_remote_attach (struct target_ops
*target
, const char *args
,
5176 struct remote_state
*rs
= get_remote_state ();
5178 char *wait_status
= NULL
;
5180 pid
= parse_pid_to_attach (args
);
5182 /* Remote PID can be freely equal to getpid, do not check it here the same
5183 way as in other targets. */
5185 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5186 error (_("This target does not support attaching to a process"));
5190 char *exec_file
= get_exec_file (0);
5193 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5194 target_pid_to_str (pid_to_ptid (pid
)));
5196 printf_unfiltered (_("Attaching to %s\n"),
5197 target_pid_to_str (pid_to_ptid (pid
)));
5199 gdb_flush (gdb_stdout
);
5202 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5204 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5206 switch (packet_ok (rs
->buf
,
5207 &remote_protocol_packets
[PACKET_vAttach
]))
5210 if (!target_is_non_stop_p ())
5212 /* Save the reply for later. */
5213 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5214 strcpy (wait_status
, rs
->buf
);
5216 else if (strcmp (rs
->buf
, "OK") != 0)
5217 error (_("Attaching to %s failed with: %s"),
5218 target_pid_to_str (pid_to_ptid (pid
)),
5221 case PACKET_UNKNOWN
:
5222 error (_("This target does not support attaching to a process"));
5224 error (_("Attaching to %s failed"),
5225 target_pid_to_str (pid_to_ptid (pid
)));
5228 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5230 inferior_ptid
= pid_to_ptid (pid
);
5232 if (target_is_non_stop_p ())
5234 struct thread_info
*thread
;
5236 /* Get list of threads. */
5237 remote_update_thread_list (target
);
5239 thread
= first_thread_of_process (pid
);
5241 inferior_ptid
= thread
->ptid
;
5243 inferior_ptid
= pid_to_ptid (pid
);
5245 /* Invalidate our notion of the remote current thread. */
5246 record_currthread (rs
, minus_one_ptid
);
5250 /* Now, if we have thread information, update inferior_ptid. */
5251 inferior_ptid
= remote_current_thread (inferior_ptid
);
5253 /* Add the main thread to the thread list. */
5254 add_thread_silent (inferior_ptid
);
5257 /* Next, if the target can specify a description, read it. We do
5258 this before anything involving memory or registers. */
5259 target_find_description ();
5261 if (!target_is_non_stop_p ())
5263 /* Use the previously fetched status. */
5264 gdb_assert (wait_status
!= NULL
);
5266 if (target_can_async_p ())
5268 struct notif_event
*reply
5269 = remote_notif_parse (¬if_client_stop
, wait_status
);
5271 push_stop_reply ((struct stop_reply
*) reply
);
5277 gdb_assert (wait_status
!= NULL
);
5278 strcpy (rs
->buf
, wait_status
);
5279 rs
->cached_wait_status
= 1;
5283 gdb_assert (wait_status
== NULL
);
5286 /* Implementation of the to_post_attach method. */
5289 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5291 /* Get text, data & bss offsets. */
5294 /* In certain cases GDB might not have had the chance to start
5295 symbol lookup up until now. This could happen if the debugged
5296 binary is not using shared libraries, the vsyscall page is not
5297 present (on Linux) and the binary itself hadn't changed since the
5298 debugging process was started. */
5299 if (symfile_objfile
!= NULL
)
5300 remote_check_symbols();
5304 /* Check for the availability of vCont. This function should also check
5308 remote_vcont_probe (struct remote_state
*rs
)
5312 strcpy (rs
->buf
, "vCont?");
5314 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5317 /* Make sure that the features we assume are supported. */
5318 if (startswith (buf
, "vCont"))
5321 int support_c
, support_C
;
5323 rs
->supports_vCont
.s
= 0;
5324 rs
->supports_vCont
.S
= 0;
5327 rs
->supports_vCont
.t
= 0;
5328 rs
->supports_vCont
.r
= 0;
5329 while (p
&& *p
== ';')
5332 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5333 rs
->supports_vCont
.s
= 1;
5334 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5335 rs
->supports_vCont
.S
= 1;
5336 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5338 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5340 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5341 rs
->supports_vCont
.t
= 1;
5342 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5343 rs
->supports_vCont
.r
= 1;
5345 p
= strchr (p
, ';');
5348 /* If c, and C are not all supported, we can't use vCont. Clearing
5349 BUF will make packet_ok disable the packet. */
5350 if (!support_c
|| !support_C
)
5354 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5357 /* Helper function for building "vCont" resumptions. Write a
5358 resumption to P. ENDP points to one-passed-the-end of the buffer
5359 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5360 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5361 resumed thread should be single-stepped and/or signalled. If PTID
5362 equals minus_one_ptid, then all threads are resumed; if PTID
5363 represents a process, then all threads of the process are resumed;
5364 the thread to be stepped and/or signalled is given in the global
5368 append_resumption (char *p
, char *endp
,
5369 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5371 struct remote_state
*rs
= get_remote_state ();
5373 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5374 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5376 /* GDB is willing to range step. */
5377 && use_range_stepping
5378 /* Target supports range stepping. */
5379 && rs
->supports_vCont
.r
5380 /* We don't currently support range stepping multiple
5381 threads with a wildcard (though the protocol allows it,
5382 so stubs shouldn't make an active effort to forbid
5384 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5386 struct thread_info
*tp
;
5388 if (ptid_equal (ptid
, minus_one_ptid
))
5390 /* If we don't know about the target thread's tid, then
5391 we're resuming magic_null_ptid (see caller). */
5392 tp
= find_thread_ptid (magic_null_ptid
);
5395 tp
= find_thread_ptid (ptid
);
5396 gdb_assert (tp
!= NULL
);
5398 if (tp
->control
.may_range_step
)
5400 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5402 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5403 phex_nz (tp
->control
.step_range_start
,
5405 phex_nz (tp
->control
.step_range_end
,
5409 p
+= xsnprintf (p
, endp
- p
, ";s");
5412 p
+= xsnprintf (p
, endp
- p
, ";s");
5413 else if (siggnal
!= GDB_SIGNAL_0
)
5414 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5416 p
+= xsnprintf (p
, endp
- p
, ";c");
5418 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5422 /* All (-1) threads of process. */
5423 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5425 p
+= xsnprintf (p
, endp
- p
, ":");
5426 p
= write_ptid (p
, endp
, nptid
);
5428 else if (!ptid_equal (ptid
, minus_one_ptid
))
5430 p
+= xsnprintf (p
, endp
- p
, ":");
5431 p
= write_ptid (p
, endp
, ptid
);
5437 /* Clear the thread's private info on resume. */
5440 resume_clear_thread_private_info (struct thread_info
*thread
)
5442 if (thread
->priv
!= NULL
)
5444 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5445 thread
->priv
->watch_data_address
= 0;
5449 /* Append a vCont continue-with-signal action for threads that have a
5450 non-zero stop signal. */
5453 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5455 struct thread_info
*thread
;
5457 ALL_NON_EXITED_THREADS (thread
)
5458 if (ptid_match (thread
->ptid
, ptid
)
5459 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5460 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5462 p
= append_resumption (p
, endp
, thread
->ptid
,
5463 0, thread
->suspend
.stop_signal
);
5464 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5465 resume_clear_thread_private_info (thread
);
5471 /* Resume the remote inferior by using a "vCont" packet. The thread
5472 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5473 resumed thread should be single-stepped and/or signalled. If PTID
5474 equals minus_one_ptid, then all threads are resumed; the thread to
5475 be stepped and/or signalled is given in the global INFERIOR_PTID.
5476 This function returns non-zero iff it resumes the inferior.
5478 This function issues a strict subset of all possible vCont commands at the
5482 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5484 struct remote_state
*rs
= get_remote_state ();
5488 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5489 remote_vcont_probe (rs
);
5491 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5495 endp
= rs
->buf
+ get_remote_packet_size ();
5497 /* If we could generate a wider range of packets, we'd have to worry
5498 about overflowing BUF. Should there be a generic
5499 "multi-part-packet" packet? */
5501 p
+= xsnprintf (p
, endp
- p
, "vCont");
5503 if (ptid_equal (ptid
, magic_null_ptid
))
5505 /* MAGIC_NULL_PTID means that we don't have any active threads,
5506 so we don't have any TID numbers the inferior will
5507 understand. Make sure to only send forms that do not specify
5509 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5511 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5513 /* Resume all threads (of all processes, or of a single
5514 process), with preference for INFERIOR_PTID. This assumes
5515 inferior_ptid belongs to the set of all threads we are about
5517 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5519 /* Step inferior_ptid, with or without signal. */
5520 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5523 /* Also pass down any pending signaled resumption for other
5524 threads not the current. */
5525 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5527 /* And continue others without a signal. */
5528 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5532 /* Scheduler locking; resume only PTID. */
5533 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5536 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5539 if (target_is_non_stop_p ())
5541 /* In non-stop, the stub replies to vCont with "OK". The stop
5542 reply will be reported asynchronously by means of a `%Stop'
5544 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5545 if (strcmp (rs
->buf
, "OK") != 0)
5546 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5552 /* Tell the remote machine to resume. */
5555 remote_resume (struct target_ops
*ops
,
5556 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5558 struct remote_state
*rs
= get_remote_state ();
5560 struct thread_info
*thread
;
5562 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5563 (explained in remote-notif.c:handle_notification) so
5564 remote_notif_process is not called. We need find a place where
5565 it is safe to start a 'vNotif' sequence. It is good to do it
5566 before resuming inferior, because inferior was stopped and no RSP
5567 traffic at that moment. */
5568 if (!target_is_non_stop_p ())
5569 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5571 rs
->last_sent_signal
= siggnal
;
5572 rs
->last_sent_step
= step
;
5574 /* The vCont packet doesn't need to specify threads via Hc. */
5575 /* No reverse support (yet) for vCont. */
5576 if (execution_direction
!= EXEC_REVERSE
)
5577 if (remote_vcont_resume (ptid
, step
, siggnal
))
5580 /* All other supported resume packets do use Hc, so set the continue
5582 if (ptid_equal (ptid
, minus_one_ptid
))
5583 set_continue_thread (any_thread_ptid
);
5585 set_continue_thread (ptid
);
5587 ALL_NON_EXITED_THREADS (thread
)
5588 resume_clear_thread_private_info (thread
);
5591 if (execution_direction
== EXEC_REVERSE
)
5593 /* We don't pass signals to the target in reverse exec mode. */
5594 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5595 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5598 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5599 error (_("Remote reverse-step not supported."));
5600 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5601 error (_("Remote reverse-continue not supported."));
5603 strcpy (buf
, step
? "bs" : "bc");
5605 else if (siggnal
!= GDB_SIGNAL_0
)
5607 buf
[0] = step
? 'S' : 'C';
5608 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5609 buf
[2] = tohex (((int) siggnal
) & 0xf);
5613 strcpy (buf
, step
? "s" : "c");
5618 /* We are about to start executing the inferior, let's register it
5619 with the event loop. NOTE: this is the one place where all the
5620 execution commands end up. We could alternatively do this in each
5621 of the execution commands in infcmd.c. */
5622 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5623 into infcmd.c in order to allow inferior function calls to work
5624 NOT asynchronously. */
5625 if (target_can_async_p ())
5628 /* We've just told the target to resume. The remote server will
5629 wait for the inferior to stop, and then send a stop reply. In
5630 the mean time, we can't start another command/query ourselves
5631 because the stub wouldn't be ready to process it. This applies
5632 only to the base all-stop protocol, however. In non-stop (which
5633 only supports vCont), the stub replies with an "OK", and is
5634 immediate able to process further serial input. */
5635 if (!target_is_non_stop_p ())
5636 rs
->waiting_for_stop_reply
= 1;
5640 /* Set up the signal handler for SIGINT, while the target is
5641 executing, ovewriting the 'regular' SIGINT signal handler. */
5643 async_initialize_sigint_signal_handler (void)
5645 signal (SIGINT
, async_handle_remote_sigint
);
5648 /* Signal handler for SIGINT, while the target is executing. */
5650 async_handle_remote_sigint (int sig
)
5652 signal (sig
, async_handle_remote_sigint_twice
);
5653 /* Note we need to go through gdb_call_async_signal_handler in order
5654 to wake up the event loop on Windows. */
5655 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5658 /* Signal handler for SIGINT, installed after SIGINT has already been
5659 sent once. It will take effect the second time that the user sends
5662 async_handle_remote_sigint_twice (int sig
)
5664 signal (sig
, async_handle_remote_sigint
);
5665 /* See note in async_handle_remote_sigint. */
5666 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5669 /* Implementation of to_check_pending_interrupt. */
5672 remote_check_pending_interrupt (struct target_ops
*self
)
5674 struct async_signal_handler
*token
= async_sigint_remote_twice_token
;
5676 if (async_signal_handler_is_marked (token
))
5678 clear_async_signal_handler (token
);
5679 call_async_signal_handler (token
);
5683 /* Perform the real interruption of the target execution, in response
5686 async_remote_interrupt (gdb_client_data arg
)
5689 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5691 target_interrupt (inferior_ptid
);
5694 /* Perform interrupt, if the first attempt did not succeed. Just give
5695 up on the target alltogether. */
5697 async_remote_interrupt_twice (gdb_client_data arg
)
5700 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5705 /* Reinstall the usual SIGINT handlers, after the target has
5708 async_cleanup_sigint_signal_handler (void *dummy
)
5710 signal (SIGINT
, handle_sigint
);
5713 /* Send ^C to target to halt it. Target will respond, and send us a
5715 static void (*ofunc
) (int);
5717 /* The command line interface's interrupt routine. This function is installed
5718 as a signal handler for SIGINT. The first time a user requests an
5719 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5720 response from the target (it didn't stop when the user requested it),
5721 we ask the user if he'd like to detach from the target. */
5724 sync_remote_interrupt (int signo
)
5726 /* If this doesn't work, try more severe steps. */
5727 signal (signo
, sync_remote_interrupt_twice
);
5729 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5732 /* The user typed ^C twice. */
5735 sync_remote_interrupt_twice (int signo
)
5737 signal (signo
, ofunc
);
5738 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5739 signal (signo
, sync_remote_interrupt
);
5742 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5743 thread, all threads of a remote process, or all threads of all
5747 remote_stop_ns (ptid_t ptid
)
5749 struct remote_state
*rs
= get_remote_state ();
5751 char *endp
= rs
->buf
+ get_remote_packet_size ();
5753 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5754 remote_vcont_probe (rs
);
5756 if (!rs
->supports_vCont
.t
)
5757 error (_("Remote server does not support stopping threads"));
5759 if (ptid_equal (ptid
, minus_one_ptid
)
5760 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5761 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5766 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5768 if (ptid_is_pid (ptid
))
5769 /* All (-1) threads of process. */
5770 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5773 /* Small optimization: if we already have a stop reply for
5774 this thread, no use in telling the stub we want this
5776 if (peek_stop_reply (ptid
))
5782 write_ptid (p
, endp
, nptid
);
5785 /* In non-stop, we get an immediate OK reply. The stop reply will
5786 come in asynchronously by notification. */
5788 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5789 if (strcmp (rs
->buf
, "OK") != 0)
5790 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5793 /* All-stop version of target_interrupt. Sends a break or a ^C to
5794 interrupt the remote target. It is undefined which thread of which
5795 process reports the interrupt. */
5798 remote_interrupt_as (void)
5800 struct remote_state
*rs
= get_remote_state ();
5802 rs
->ctrlc_pending_p
= 1;
5804 /* If the inferior is stopped already, but the core didn't know
5805 about it yet, just ignore the request. The cached wait status
5806 will be collected in remote_wait. */
5807 if (rs
->cached_wait_status
)
5810 /* Send interrupt_sequence to remote target. */
5811 send_interrupt_sequence ();
5814 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5815 the remote target. It is undefined which thread of which process
5816 reports the interrupt. Throws an error if the packet is not
5817 supported by the server. */
5820 remote_interrupt_ns (void)
5822 struct remote_state
*rs
= get_remote_state ();
5824 char *endp
= rs
->buf
+ get_remote_packet_size ();
5826 xsnprintf (p
, endp
- p
, "vCtrlC");
5828 /* In non-stop, we get an immediate OK reply. The stop reply will
5829 come in asynchronously by notification. */
5831 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5833 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
5837 case PACKET_UNKNOWN
:
5838 error (_("No support for interrupting the remote target."));
5840 error (_("Interrupting target failed: %s"), rs
->buf
);
5844 /* Implement the to_stop function for the remote targets. */
5847 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5850 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5852 if (target_is_non_stop_p ())
5853 remote_stop_ns (ptid
);
5856 /* We don't currently have a way to transparently pause the
5857 remote target in all-stop mode. Interrupt it instead. */
5858 remote_interrupt_as ();
5862 /* Implement the to_interrupt function for the remote targets. */
5865 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5867 struct remote_state
*rs
= get_remote_state ();
5870 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5872 if (target_is_non_stop_p ())
5873 remote_interrupt_ns ();
5875 remote_interrupt_as ();
5878 /* Implement the to_pass_ctrlc function for the remote targets. */
5881 remote_pass_ctrlc (struct target_ops
*self
)
5883 struct remote_state
*rs
= get_remote_state ();
5886 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
5888 /* If we're starting up, we're not fully synced yet. Quit
5890 if (rs
->starting_up
)
5892 /* If ^C has already been sent once, offer to disconnect. */
5893 else if (rs
->ctrlc_pending_p
)
5896 target_interrupt (inferior_ptid
);
5899 /* Ask the user what to do when an interrupt is received. */
5902 interrupt_query (void)
5904 struct remote_state
*rs
= get_remote_state ();
5905 struct cleanup
*old_chain
;
5907 old_chain
= make_cleanup_restore_target_terminal ();
5908 target_terminal_ours ();
5910 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5912 if (query (_("The target is not responding to interrupt requests.\n"
5913 "Stop debugging it? ")))
5915 remote_unpush_target ();
5916 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5921 if (query (_("Interrupted while waiting for the program.\n"
5922 "Give up waiting? ")))
5926 do_cleanups (old_chain
);
5929 /* Enable/disable target terminal ownership. Most targets can use
5930 terminal groups to control terminal ownership. Remote targets are
5931 different in that explicit transfer of ownership to/from GDB/target
5935 remote_terminal_inferior (struct target_ops
*self
)
5937 if (!target_async_permitted
)
5938 /* Nothing to do. */
5941 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5942 idempotent. The event-loop GDB talking to an asynchronous target
5943 with a synchronous command calls this function from both
5944 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5945 transfer the terminal to the target when it shouldn't this guard
5947 if (!remote_async_terminal_ours_p
)
5949 delete_file_handler (input_fd
);
5950 remote_async_terminal_ours_p
= 0;
5951 async_initialize_sigint_signal_handler ();
5952 /* NOTE: At this point we could also register our selves as the
5953 recipient of all input. Any characters typed could then be
5954 passed on down to the target. */
5958 remote_terminal_ours (struct target_ops
*self
)
5960 if (!target_async_permitted
)
5961 /* Nothing to do. */
5964 /* See FIXME in remote_terminal_inferior. */
5965 if (remote_async_terminal_ours_p
)
5967 async_cleanup_sigint_signal_handler (NULL
);
5968 add_file_handler (input_fd
, stdin_event_handler
, 0);
5969 remote_async_terminal_ours_p
= 1;
5973 remote_console_output (char *msg
)
5977 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5980 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5984 fputs_unfiltered (tb
, gdb_stdtarg
);
5986 gdb_flush (gdb_stdtarg
);
5989 typedef struct cached_reg
5992 gdb_byte data
[MAX_REGISTER_SIZE
];
5995 DEF_VEC_O(cached_reg_t
);
5997 typedef struct stop_reply
5999 struct notif_event base
;
6001 /* The identifier of the thread about this event */
6004 /* The remote state this event is associated with. When the remote
6005 connection, represented by a remote_state object, is closed,
6006 all the associated stop_reply events should be released. */
6007 struct remote_state
*rs
;
6009 struct target_waitstatus ws
;
6011 /* Expedited registers. This makes remote debugging a bit more
6012 efficient for those targets that provide critical registers as
6013 part of their normal status mechanism (as another roundtrip to
6014 fetch them is avoided). */
6015 VEC(cached_reg_t
) *regcache
;
6017 enum target_stop_reason stop_reason
;
6019 CORE_ADDR watch_data_address
;
6024 DECLARE_QUEUE_P (stop_reply_p
);
6025 DEFINE_QUEUE_P (stop_reply_p
);
6026 /* The list of already fetched and acknowledged stop events. This
6027 queue is used for notification Stop, and other notifications
6028 don't need queue for their events, because the notification events
6029 of Stop can't be consumed immediately, so that events should be
6030 queued first, and be consumed by remote_wait_{ns,as} one per
6031 time. Other notifications can consume their events immediately,
6032 so queue is not needed for them. */
6033 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6036 stop_reply_xfree (struct stop_reply
*r
)
6038 notif_event_xfree ((struct notif_event
*) r
);
6041 /* Return the length of the stop reply queue. */
6044 stop_reply_queue_length (void)
6046 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6050 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6051 struct notif_event
*event
)
6053 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6057 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6058 struct notif_event
*event
)
6060 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6063 putpkt ((char *) self
->ack_command
);
6065 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6066 /* We got an unknown stop reply. */
6067 error (_("Unknown stop reply"));
6069 push_stop_reply (stop_reply
);
6073 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6075 /* We can't get pending events in remote_notif_process for
6076 notification stop, and we have to do this in remote_wait_ns
6077 instead. If we fetch all queued events from stub, remote stub
6078 may exit and we have no chance to process them back in
6080 mark_async_event_handler (remote_async_inferior_event_token
);
6085 stop_reply_dtr (struct notif_event
*event
)
6087 struct stop_reply
*r
= (struct stop_reply
*) event
;
6089 VEC_free (cached_reg_t
, r
->regcache
);
6092 static struct notif_event
*
6093 remote_notif_stop_alloc_reply (void)
6095 /* We cast to a pointer to the "base class". */
6096 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6098 r
->dtr
= stop_reply_dtr
;
6103 /* A client of notification Stop. */
6105 struct notif_client notif_client_stop
=
6109 remote_notif_stop_parse
,
6110 remote_notif_stop_ack
,
6111 remote_notif_stop_can_get_pending_events
,
6112 remote_notif_stop_alloc_reply
,
6116 /* A parameter to pass data in and out. */
6118 struct queue_iter_param
6121 struct stop_reply
*output
;
6124 /* Determine if THREAD is a pending fork parent thread. ARG contains
6125 the pid of the process that owns the threads we want to check, or
6126 -1 if we want to check all threads. */
6129 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6132 if (ws
->kind
== TARGET_WAITKIND_FORKED
6133 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6135 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6142 /* Check whether EVENT is a fork event, and if it is, remove the
6143 fork child from the context list passed in DATA. */
6146 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6147 QUEUE_ITER (stop_reply_p
) *iter
,
6151 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6152 struct threads_listing_context
*context
6153 = (struct threads_listing_context
*) param
->input
;
6155 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6156 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6157 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6158 threads_listing_context_remove (&event
->ws
, context
);
6163 /* If CONTEXT contains any fork child threads that have not been
6164 reported yet, remove them from the CONTEXT list. If such a
6165 thread exists it is because we are stopped at a fork catchpoint
6166 and have not yet called follow_fork, which will set up the
6167 host-side data structures for the new process. */
6170 remove_new_fork_children (struct threads_listing_context
*context
)
6172 struct thread_info
* thread
;
6174 struct notif_client
*notif
= ¬if_client_stop
;
6175 struct queue_iter_param param
;
6177 /* For any threads stopped at a fork event, remove the corresponding
6178 fork child threads from the CONTEXT list. */
6179 ALL_NON_EXITED_THREADS (thread
)
6181 struct target_waitstatus
*ws
;
6183 if (thread
->suspend
.waitstatus_pending_p
)
6184 ws
= &thread
->suspend
.waitstatus
;
6186 ws
= &thread
->pending_follow
;
6188 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6190 threads_listing_context_remove (ws
, context
);
6194 /* Check for any pending fork events (not reported or processed yet)
6195 in process PID and remove those fork child threads from the
6196 CONTEXT list as well. */
6197 remote_notif_get_pending_events (notif
);
6198 param
.input
= context
;
6199 param
.output
= NULL
;
6200 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6201 remove_child_of_pending_fork
, ¶m
);
6204 /* Remove stop replies in the queue if its pid is equal to the given
6208 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6209 QUEUE_ITER (stop_reply_p
) *iter
,
6213 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6214 struct inferior
*inf
= (struct inferior
*) param
->input
;
6216 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6218 stop_reply_xfree (event
);
6219 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6225 /* Discard all pending stop replies of inferior INF. */
6228 discard_pending_stop_replies (struct inferior
*inf
)
6230 struct queue_iter_param param
;
6231 struct stop_reply
*reply
;
6232 struct remote_state
*rs
= get_remote_state ();
6233 struct remote_notif_state
*rns
= rs
->notif_state
;
6235 /* This function can be notified when an inferior exists. When the
6236 target is not remote, the notification state is NULL. */
6237 if (rs
->remote_desc
== NULL
)
6240 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6242 /* Discard the in-flight notification. */
6243 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6245 stop_reply_xfree (reply
);
6246 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6250 param
.output
= NULL
;
6251 /* Discard the stop replies we have already pulled with
6253 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6254 remove_stop_reply_for_inferior
, ¶m
);
6257 /* If its remote state is equal to the given remote state,
6258 remove EVENT from the stop reply queue. */
6261 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6262 QUEUE_ITER (stop_reply_p
) *iter
,
6266 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6267 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6269 if (event
->rs
== rs
)
6271 stop_reply_xfree (event
);
6272 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6278 /* Discard the stop replies for RS in stop_reply_queue. */
6281 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6283 struct queue_iter_param param
;
6286 param
.output
= NULL
;
6287 /* Discard the stop replies we have already pulled with
6289 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6290 remove_stop_reply_of_remote_state
, ¶m
);
6293 /* A parameter to pass data in and out. */
6296 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6297 QUEUE_ITER (stop_reply_p
) *iter
,
6301 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6302 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6304 if (ptid_match (event
->ptid
, *ptid
))
6306 param
->output
= event
;
6307 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6314 /* Remove the first reply in 'stop_reply_queue' which matches
6317 static struct stop_reply
*
6318 remote_notif_remove_queued_reply (ptid_t ptid
)
6320 struct queue_iter_param param
;
6322 param
.input
= &ptid
;
6323 param
.output
= NULL
;
6325 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6326 remote_notif_remove_once_on_match
, ¶m
);
6328 fprintf_unfiltered (gdb_stdlog
,
6329 "notif: discard queued event: 'Stop' in %s\n",
6330 target_pid_to_str (ptid
));
6332 return param
.output
;
6335 /* Look for a queued stop reply belonging to PTID. If one is found,
6336 remove it from the queue, and return it. Returns NULL if none is
6337 found. If there are still queued events left to process, tell the
6338 event loop to get back to target_wait soon. */
6340 static struct stop_reply
*
6341 queued_stop_reply (ptid_t ptid
)
6343 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6345 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6346 /* There's still at least an event left. */
6347 mark_async_event_handler (remote_async_inferior_event_token
);
6352 /* Push a fully parsed stop reply in the stop reply queue. Since we
6353 know that we now have at least one queued event left to pass to the
6354 core side, tell the event loop to get back to target_wait soon. */
6357 push_stop_reply (struct stop_reply
*new_event
)
6359 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6362 fprintf_unfiltered (gdb_stdlog
,
6363 "notif: push 'Stop' %s to queue %d\n",
6364 target_pid_to_str (new_event
->ptid
),
6365 QUEUE_length (stop_reply_p
,
6368 mark_async_event_handler (remote_async_inferior_event_token
);
6372 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6373 QUEUE_ITER (stop_reply_p
) *iter
,
6374 struct stop_reply
*event
,
6377 ptid_t
*ptid
= (ptid_t
*) data
;
6379 return !(ptid_equal (*ptid
, event
->ptid
)
6380 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6383 /* Returns true if we have a stop reply for PTID. */
6386 peek_stop_reply (ptid_t ptid
)
6388 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6389 stop_reply_match_ptid_and_ws
, &ptid
);
6392 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6393 starting with P and ending with PEND matches PREFIX. */
6396 strprefix (const char *p
, const char *pend
, const char *prefix
)
6398 for ( ; p
< pend
; p
++, prefix
++)
6401 return *prefix
== '\0';
6404 /* Parse the stop reply in BUF. Either the function succeeds, and the
6405 result is stored in EVENT, or throws an error. */
6408 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6410 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6415 event
->ptid
= null_ptid
;
6416 event
->rs
= get_remote_state ();
6417 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6418 event
->ws
.value
.integer
= 0;
6419 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6420 event
->regcache
= NULL
;
6425 case 'T': /* Status with PC, SP, FP, ... */
6426 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6427 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6429 n... = register number
6430 r... = register contents
6433 p
= &buf
[3]; /* after Txx */
6439 p1
= strchr (p
, ':');
6441 error (_("Malformed packet(a) (missing colon): %s\n\
6445 error (_("Malformed packet(a) (missing register number): %s\n\
6449 /* Some "registers" are actually extended stop information.
6450 Note if you're adding a new entry here: GDB 7.9 and
6451 earlier assume that all register "numbers" that start
6452 with an hex digit are real register numbers. Make sure
6453 the server only sends such a packet if it knows the
6454 client understands it. */
6456 if (strprefix (p
, p1
, "thread"))
6457 event
->ptid
= read_ptid (++p1
, &p
);
6458 else if (strprefix (p
, p1
, "syscall_entry"))
6462 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6463 p
= unpack_varlen_hex (++p1
, &sysno
);
6464 event
->ws
.value
.syscall_number
= (int) sysno
;
6466 else if (strprefix (p
, p1
, "syscall_return"))
6470 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6471 p
= unpack_varlen_hex (++p1
, &sysno
);
6472 event
->ws
.value
.syscall_number
= (int) sysno
;
6474 else if (strprefix (p
, p1
, "watch")
6475 || strprefix (p
, p1
, "rwatch")
6476 || strprefix (p
, p1
, "awatch"))
6478 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6479 p
= unpack_varlen_hex (++p1
, &addr
);
6480 event
->watch_data_address
= (CORE_ADDR
) addr
;
6482 else if (strprefix (p
, p1
, "swbreak"))
6484 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6486 /* Make sure the stub doesn't forget to indicate support
6488 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6489 error (_("Unexpected swbreak stop reason"));
6491 /* The value part is documented as "must be empty",
6492 though we ignore it, in case we ever decide to make
6493 use of it in a backward compatible way. */
6494 p
= strchrnul (p1
+ 1, ';');
6496 else if (strprefix (p
, p1
, "hwbreak"))
6498 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6500 /* Make sure the stub doesn't forget to indicate support
6502 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6503 error (_("Unexpected hwbreak stop reason"));
6506 p
= strchrnul (p1
+ 1, ';');
6508 else if (strprefix (p
, p1
, "library"))
6510 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6511 p
= strchrnul (p1
+ 1, ';');
6513 else if (strprefix (p
, p1
, "replaylog"))
6515 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6516 /* p1 will indicate "begin" or "end", but it makes
6517 no difference for now, so ignore it. */
6518 p
= strchrnul (p1
+ 1, ';');
6520 else if (strprefix (p
, p1
, "core"))
6524 p
= unpack_varlen_hex (++p1
, &c
);
6527 else if (strprefix (p
, p1
, "fork"))
6529 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6530 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6532 else if (strprefix (p
, p1
, "vfork"))
6534 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6535 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6537 else if (strprefix (p
, p1
, "vforkdone"))
6539 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6540 p
= strchrnul (p1
+ 1, ';');
6542 else if (strprefix (p
, p1
, "exec"))
6545 char pathname
[PATH_MAX
];
6548 /* Determine the length of the execd pathname. */
6549 p
= unpack_varlen_hex (++p1
, &ignored
);
6550 pathlen
= (p
- p1
) / 2;
6552 /* Save the pathname for event reporting and for
6553 the next run command. */
6554 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6555 pathname
[pathlen
] = '\0';
6557 /* This is freed during event handling. */
6558 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6559 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6561 /* Skip the registers included in this packet, since
6562 they may be for an architecture different from the
6563 one used by the original program. */
6566 else if (strprefix (p
, p1
, "create"))
6568 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6569 p
= strchrnul (p1
+ 1, ';');
6578 p
= strchrnul (p1
+ 1, ';');
6583 /* Maybe a real ``P'' register number. */
6584 p_temp
= unpack_varlen_hex (p
, &pnum
);
6585 /* If the first invalid character is the colon, we got a
6586 register number. Otherwise, it's an unknown stop
6590 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6591 cached_reg_t cached_reg
;
6594 error (_("Remote sent bad register number %s: %s\n\
6596 hex_string (pnum
), p
, buf
);
6598 cached_reg
.num
= reg
->regnum
;
6601 fieldsize
= hex2bin (p
, cached_reg
.data
,
6602 register_size (target_gdbarch (),
6605 if (fieldsize
< register_size (target_gdbarch (),
6607 warning (_("Remote reply is too short: %s"), buf
);
6609 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6613 /* Not a number. Silently skip unknown optional
6615 p
= strchrnul (p1
+ 1, ';');
6620 error (_("Remote register badly formatted: %s\nhere: %s"),
6625 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6629 case 'S': /* Old style status, just signal only. */
6633 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6634 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6635 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6636 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6638 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6641 case 'w': /* Thread exited. */
6646 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
6647 p
= unpack_varlen_hex (&buf
[1], &value
);
6648 event
->ws
.value
.integer
= value
;
6650 error (_("stop reply packet badly formatted: %s"), buf
);
6651 event
->ptid
= read_ptid (++p
, NULL
);
6654 case 'W': /* Target exited. */
6661 /* GDB used to accept only 2 hex chars here. Stubs should
6662 only send more if they detect GDB supports multi-process
6664 p
= unpack_varlen_hex (&buf
[1], &value
);
6668 /* The remote process exited. */
6669 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6670 event
->ws
.value
.integer
= value
;
6674 /* The remote process exited with a signal. */
6675 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6676 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6677 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6679 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6682 /* If no process is specified, assume inferior_ptid. */
6683 pid
= ptid_get_pid (inferior_ptid
);
6692 else if (startswith (p
, "process:"))
6696 p
+= sizeof ("process:") - 1;
6697 unpack_varlen_hex (p
, &upid
);
6701 error (_("unknown stop reply packet: %s"), buf
);
6704 error (_("unknown stop reply packet: %s"), buf
);
6705 event
->ptid
= pid_to_ptid (pid
);
6709 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
6710 event
->ptid
= minus_one_ptid
;
6714 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
6715 error (_("No process or thread specified in stop reply: %s"), buf
);
6718 /* When the stub wants to tell GDB about a new notification reply, it
6719 sends a notification (%Stop, for example). Those can come it at
6720 any time, hence, we have to make sure that any pending
6721 putpkt/getpkt sequence we're making is finished, before querying
6722 the stub for more events with the corresponding ack command
6723 (vStopped, for example). E.g., if we started a vStopped sequence
6724 immediately upon receiving the notification, something like this
6732 1.6) <-- (registers reply to step #1.3)
6734 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6737 To solve this, whenever we parse a %Stop notification successfully,
6738 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6739 doing whatever we were doing:
6745 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6746 2.5) <-- (registers reply to step #2.3)
6748 Eventualy after step #2.5, we return to the event loop, which
6749 notices there's an event on the
6750 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6751 associated callback --- the function below. At this point, we're
6752 always safe to start a vStopped sequence. :
6755 2.7) <-- T05 thread:2
6761 remote_notif_get_pending_events (struct notif_client
*nc
)
6763 struct remote_state
*rs
= get_remote_state ();
6765 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6768 fprintf_unfiltered (gdb_stdlog
,
6769 "notif: process: '%s' ack pending event\n",
6773 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6774 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6778 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6779 if (strcmp (rs
->buf
, "OK") == 0)
6782 remote_notif_ack (nc
, rs
->buf
);
6788 fprintf_unfiltered (gdb_stdlog
,
6789 "notif: process: '%s' no pending reply\n",
6794 /* Called when it is decided that STOP_REPLY holds the info of the
6795 event that is to be returned to the core. This function always
6796 destroys STOP_REPLY. */
6799 process_stop_reply (struct stop_reply
*stop_reply
,
6800 struct target_waitstatus
*status
)
6804 *status
= stop_reply
->ws
;
6805 ptid
= stop_reply
->ptid
;
6807 /* If no thread/process was reported by the stub, assume the current
6809 if (ptid_equal (ptid
, null_ptid
))
6810 ptid
= inferior_ptid
;
6812 if (status
->kind
!= TARGET_WAITKIND_EXITED
6813 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
6814 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
6816 struct private_thread_info
*remote_thr
;
6818 /* Expedited registers. */
6819 if (stop_reply
->regcache
)
6821 struct regcache
*regcache
6822 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6827 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6829 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6830 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6833 remote_notice_new_inferior (ptid
, 0);
6834 remote_thr
= demand_private_info (ptid
);
6835 remote_thr
->core
= stop_reply
->core
;
6836 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
6837 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
6840 stop_reply_xfree (stop_reply
);
6844 /* The non-stop mode version of target_wait. */
6847 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6849 struct remote_state
*rs
= get_remote_state ();
6850 struct stop_reply
*stop_reply
;
6854 /* If in non-stop mode, get out of getpkt even if a
6855 notification is received. */
6857 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6858 0 /* forever */, &is_notif
);
6861 if (ret
!= -1 && !is_notif
)
6864 case 'E': /* Error of some sort. */
6865 /* We're out of sync with the target now. Did it continue
6866 or not? We can't tell which thread it was in non-stop,
6867 so just ignore this. */
6868 warning (_("Remote failure reply: %s"), rs
->buf
);
6870 case 'O': /* Console output. */
6871 remote_console_output (rs
->buf
+ 1);
6874 warning (_("Invalid remote reply: %s"), rs
->buf
);
6878 /* Acknowledge a pending stop reply that may have arrived in the
6880 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6881 remote_notif_get_pending_events (¬if_client_stop
);
6883 /* If indeed we noticed a stop reply, we're done. */
6884 stop_reply
= queued_stop_reply (ptid
);
6885 if (stop_reply
!= NULL
)
6886 return process_stop_reply (stop_reply
, status
);
6888 /* Still no event. If we're just polling for an event, then
6889 return to the event loop. */
6890 if (options
& TARGET_WNOHANG
)
6892 status
->kind
= TARGET_WAITKIND_IGNORE
;
6893 return minus_one_ptid
;
6896 /* Otherwise do a blocking wait. */
6897 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6898 1 /* forever */, &is_notif
);
6902 /* Wait until the remote machine stops, then return, storing status in
6903 STATUS just as `wait' would. */
6906 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6908 struct remote_state
*rs
= get_remote_state ();
6909 ptid_t event_ptid
= null_ptid
;
6911 struct stop_reply
*stop_reply
;
6915 status
->kind
= TARGET_WAITKIND_IGNORE
;
6916 status
->value
.integer
= 0;
6918 stop_reply
= queued_stop_reply (ptid
);
6919 if (stop_reply
!= NULL
)
6920 return process_stop_reply (stop_reply
, status
);
6922 if (rs
->cached_wait_status
)
6923 /* Use the cached wait status, but only once. */
6924 rs
->cached_wait_status
= 0;
6929 int forever
= ((options
& TARGET_WNOHANG
) == 0
6930 && wait_forever_enabled_p
);
6932 if (!rs
->waiting_for_stop_reply
)
6934 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6935 return minus_one_ptid
;
6938 if (!target_is_async_p ())
6940 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6941 /* If the user hit C-c before this packet, or between packets,
6942 pretend that it was hit right here. */
6943 if (check_quit_flag ())
6944 sync_remote_interrupt (SIGINT
);
6947 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6948 _never_ wait for ever -> test on target_is_async_p().
6949 However, before we do that we need to ensure that the caller
6950 knows how to take the target into/out of async mode. */
6951 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6952 forever
, &is_notif
);
6954 if (!target_is_async_p ())
6955 signal (SIGINT
, ofunc
);
6957 /* GDB gets a notification. Return to core as this event is
6959 if (ret
!= -1 && is_notif
)
6960 return minus_one_ptid
;
6962 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6963 return minus_one_ptid
;
6968 /* Assume that the target has acknowledged Ctrl-C unless we receive
6969 an 'F' or 'O' packet. */
6970 if (buf
[0] != 'F' && buf
[0] != 'O')
6971 rs
->ctrlc_pending_p
= 0;
6975 case 'E': /* Error of some sort. */
6976 /* We're out of sync with the target now. Did it continue or
6977 not? Not is more likely, so report a stop. */
6978 rs
->waiting_for_stop_reply
= 0;
6980 warning (_("Remote failure reply: %s"), buf
);
6981 status
->kind
= TARGET_WAITKIND_STOPPED
;
6982 status
->value
.sig
= GDB_SIGNAL_0
;
6984 case 'F': /* File-I/O request. */
6985 /* GDB may access the inferior memory while handling the File-I/O
6986 request, but we don't want GDB accessing memory while waiting
6987 for a stop reply. See the comments in putpkt_binary. Set
6988 waiting_for_stop_reply to 0 temporarily. */
6989 rs
->waiting_for_stop_reply
= 0;
6990 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6991 rs
->ctrlc_pending_p
= 0;
6992 /* GDB handled the File-I/O request, and the target is running
6993 again. Keep waiting for events. */
6994 rs
->waiting_for_stop_reply
= 1;
6996 case 'N': case 'T': case 'S': case 'X': case 'W':
6998 struct stop_reply
*stop_reply
;
7000 /* There is a stop reply to handle. */
7001 rs
->waiting_for_stop_reply
= 0;
7004 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
7007 event_ptid
= process_stop_reply (stop_reply
, status
);
7010 case 'O': /* Console output. */
7011 remote_console_output (buf
+ 1);
7014 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7016 /* Zero length reply means that we tried 'S' or 'C' and the
7017 remote system doesn't support it. */
7018 target_terminal_ours_for_output ();
7020 ("Can't send signals to this remote system. %s not sent.\n",
7021 gdb_signal_to_name (rs
->last_sent_signal
));
7022 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7023 target_terminal_inferior ();
7025 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
7026 putpkt ((char *) buf
);
7029 /* else fallthrough */
7031 warning (_("Invalid remote reply: %s"), buf
);
7035 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7036 return minus_one_ptid
;
7037 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7039 /* Nothing interesting happened. If we're doing a non-blocking
7040 poll, we're done. Otherwise, go back to waiting. */
7041 if (options
& TARGET_WNOHANG
)
7042 return minus_one_ptid
;
7046 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7047 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7049 if (!ptid_equal (event_ptid
, null_ptid
))
7050 record_currthread (rs
, event_ptid
);
7052 event_ptid
= inferior_ptid
;
7055 /* A process exit. Invalidate our notion of current thread. */
7056 record_currthread (rs
, minus_one_ptid
);
7061 /* Wait until the remote machine stops, then return, storing status in
7062 STATUS just as `wait' would. */
7065 remote_wait (struct target_ops
*ops
,
7066 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7070 if (target_is_non_stop_p ())
7071 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7073 event_ptid
= remote_wait_as (ptid
, status
, options
);
7075 if (target_is_async_p ())
7077 /* If there are are events left in the queue tell the event loop
7079 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7080 mark_async_event_handler (remote_async_inferior_event_token
);
7086 /* Fetch a single register using a 'p' packet. */
7089 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7091 struct remote_state
*rs
= get_remote_state ();
7093 char regp
[MAX_REGISTER_SIZE
];
7096 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7099 if (reg
->pnum
== -1)
7104 p
+= hexnumstr (p
, reg
->pnum
);
7107 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7111 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7115 case PACKET_UNKNOWN
:
7118 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7119 gdbarch_register_name (get_regcache_arch (regcache
),
7124 /* If this register is unfetchable, tell the regcache. */
7127 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7131 /* Otherwise, parse and supply the value. */
7137 error (_("fetch_register_using_p: early buf termination"));
7139 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7142 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7146 /* Fetch the registers included in the target's 'g' packet. */
7149 send_g_packet (void)
7151 struct remote_state
*rs
= get_remote_state ();
7154 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7155 remote_send (&rs
->buf
, &rs
->buf_size
);
7157 /* We can get out of synch in various cases. If the first character
7158 in the buffer is not a hex character, assume that has happened
7159 and try to fetch another packet to read. */
7160 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7161 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7162 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7163 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7166 fprintf_unfiltered (gdb_stdlog
,
7167 "Bad register packet; fetching a new packet\n");
7168 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7171 buf_len
= strlen (rs
->buf
);
7173 /* Sanity check the received packet. */
7174 if (buf_len
% 2 != 0)
7175 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7181 process_g_packet (struct regcache
*regcache
)
7183 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7184 struct remote_state
*rs
= get_remote_state ();
7185 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7190 buf_len
= strlen (rs
->buf
);
7192 /* Further sanity checks, with knowledge of the architecture. */
7193 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7194 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7196 /* Save the size of the packet sent to us by the target. It is used
7197 as a heuristic when determining the max size of packets that the
7198 target can safely receive. */
7199 if (rsa
->actual_register_packet_size
== 0)
7200 rsa
->actual_register_packet_size
= buf_len
;
7202 /* If this is smaller than we guessed the 'g' packet would be,
7203 update our records. A 'g' reply that doesn't include a register's
7204 value implies either that the register is not available, or that
7205 the 'p' packet must be used. */
7206 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7208 rsa
->sizeof_g_packet
= buf_len
/ 2;
7210 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7212 if (rsa
->regs
[i
].pnum
== -1)
7215 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7216 rsa
->regs
[i
].in_g_packet
= 0;
7218 rsa
->regs
[i
].in_g_packet
= 1;
7222 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7224 /* Unimplemented registers read as all bits zero. */
7225 memset (regs
, 0, rsa
->sizeof_g_packet
);
7227 /* Reply describes registers byte by byte, each byte encoded as two
7228 hex characters. Suck them all up, then supply them to the
7229 register cacheing/storage mechanism. */
7232 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7234 if (p
[0] == 0 || p
[1] == 0)
7235 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7236 internal_error (__FILE__
, __LINE__
,
7237 _("unexpected end of 'g' packet reply"));
7239 if (p
[0] == 'x' && p
[1] == 'x')
7240 regs
[i
] = 0; /* 'x' */
7242 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7246 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7248 struct packet_reg
*r
= &rsa
->regs
[i
];
7252 if (r
->offset
* 2 >= strlen (rs
->buf
))
7253 /* This shouldn't happen - we adjusted in_g_packet above. */
7254 internal_error (__FILE__
, __LINE__
,
7255 _("unexpected end of 'g' packet reply"));
7256 else if (rs
->buf
[r
->offset
* 2] == 'x')
7258 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7259 /* The register isn't available, mark it as such (at
7260 the same time setting the value to zero). */
7261 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7264 regcache_raw_supply (regcache
, r
->regnum
,
7271 fetch_registers_using_g (struct regcache
*regcache
)
7274 process_g_packet (regcache
);
7277 /* Make the remote selected traceframe match GDB's selected
7281 set_remote_traceframe (void)
7284 struct remote_state
*rs
= get_remote_state ();
7286 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7289 /* Avoid recursion, remote_trace_find calls us again. */
7290 rs
->remote_traceframe_number
= get_traceframe_number ();
7292 newnum
= target_trace_find (tfind_number
,
7293 get_traceframe_number (), 0, 0, NULL
);
7295 /* Should not happen. If it does, all bets are off. */
7296 if (newnum
!= get_traceframe_number ())
7297 warning (_("could not set remote traceframe"));
7301 remote_fetch_registers (struct target_ops
*ops
,
7302 struct regcache
*regcache
, int regnum
)
7304 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7307 set_remote_traceframe ();
7308 set_general_thread (inferior_ptid
);
7312 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7314 gdb_assert (reg
!= NULL
);
7316 /* If this register might be in the 'g' packet, try that first -
7317 we are likely to read more than one register. If this is the
7318 first 'g' packet, we might be overly optimistic about its
7319 contents, so fall back to 'p'. */
7320 if (reg
->in_g_packet
)
7322 fetch_registers_using_g (regcache
);
7323 if (reg
->in_g_packet
)
7327 if (fetch_register_using_p (regcache
, reg
))
7330 /* This register is not available. */
7331 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7336 fetch_registers_using_g (regcache
);
7338 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7339 if (!rsa
->regs
[i
].in_g_packet
)
7340 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7342 /* This register is not available. */
7343 regcache_raw_supply (regcache
, i
, NULL
);
7347 /* Prepare to store registers. Since we may send them all (using a
7348 'G' request), we have to read out the ones we don't want to change
7352 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7354 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7356 gdb_byte buf
[MAX_REGISTER_SIZE
];
7358 /* Make sure the entire registers array is valid. */
7359 switch (packet_support (PACKET_P
))
7361 case PACKET_DISABLE
:
7362 case PACKET_SUPPORT_UNKNOWN
:
7363 /* Make sure all the necessary registers are cached. */
7364 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7365 if (rsa
->regs
[i
].in_g_packet
)
7366 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7373 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7374 packet was not recognized. */
7377 store_register_using_P (const struct regcache
*regcache
,
7378 struct packet_reg
*reg
)
7380 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7381 struct remote_state
*rs
= get_remote_state ();
7382 /* Try storing a single register. */
7383 char *buf
= rs
->buf
;
7384 gdb_byte regp
[MAX_REGISTER_SIZE
];
7387 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7390 if (reg
->pnum
== -1)
7393 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7394 p
= buf
+ strlen (buf
);
7395 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7396 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7398 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7400 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7405 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7406 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7407 case PACKET_UNKNOWN
:
7410 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7414 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7415 contents of the register cache buffer. FIXME: ignores errors. */
7418 store_registers_using_G (const struct regcache
*regcache
)
7420 struct remote_state
*rs
= get_remote_state ();
7421 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7425 /* Extract all the registers in the regcache copying them into a
7430 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7431 memset (regs
, 0, rsa
->sizeof_g_packet
);
7432 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7434 struct packet_reg
*r
= &rsa
->regs
[i
];
7437 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7441 /* Command describes registers byte by byte,
7442 each byte encoded as two hex characters. */
7445 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7447 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7449 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7450 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7451 error (_("Could not write registers; remote failure reply '%s'"),
7455 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7456 of the register cache buffer. FIXME: ignores errors. */
7459 remote_store_registers (struct target_ops
*ops
,
7460 struct regcache
*regcache
, int regnum
)
7462 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7465 set_remote_traceframe ();
7466 set_general_thread (inferior_ptid
);
7470 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7472 gdb_assert (reg
!= NULL
);
7474 /* Always prefer to store registers using the 'P' packet if
7475 possible; we often change only a small number of registers.
7476 Sometimes we change a larger number; we'd need help from a
7477 higher layer to know to use 'G'. */
7478 if (store_register_using_P (regcache
, reg
))
7481 /* For now, don't complain if we have no way to write the
7482 register. GDB loses track of unavailable registers too
7483 easily. Some day, this may be an error. We don't have
7484 any way to read the register, either... */
7485 if (!reg
->in_g_packet
)
7488 store_registers_using_G (regcache
);
7492 store_registers_using_G (regcache
);
7494 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7495 if (!rsa
->regs
[i
].in_g_packet
)
7496 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7497 /* See above for why we do not issue an error here. */
7502 /* Return the number of hex digits in num. */
7505 hexnumlen (ULONGEST num
)
7509 for (i
= 0; num
!= 0; i
++)
7515 /* Set BUF to the minimum number of hex digits representing NUM. */
7518 hexnumstr (char *buf
, ULONGEST num
)
7520 int len
= hexnumlen (num
);
7522 return hexnumnstr (buf
, num
, len
);
7526 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7529 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7535 for (i
= width
- 1; i
>= 0; i
--)
7537 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7544 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7547 remote_address_masked (CORE_ADDR addr
)
7549 unsigned int address_size
= remote_address_size
;
7551 /* If "remoteaddresssize" was not set, default to target address size. */
7553 address_size
= gdbarch_addr_bit (target_gdbarch ());
7555 if (address_size
> 0
7556 && address_size
< (sizeof (ULONGEST
) * 8))
7558 /* Only create a mask when that mask can safely be constructed
7559 in a ULONGEST variable. */
7562 mask
= (mask
<< address_size
) - 1;
7568 /* Determine whether the remote target supports binary downloading.
7569 This is accomplished by sending a no-op memory write of zero length
7570 to the target at the specified address. It does not suffice to send
7571 the whole packet, since many stubs strip the eighth bit and
7572 subsequently compute a wrong checksum, which causes real havoc with
7575 NOTE: This can still lose if the serial line is not eight-bit
7576 clean. In cases like this, the user should clear "remote
7580 check_binary_download (CORE_ADDR addr
)
7582 struct remote_state
*rs
= get_remote_state ();
7584 switch (packet_support (PACKET_X
))
7586 case PACKET_DISABLE
:
7590 case PACKET_SUPPORT_UNKNOWN
:
7596 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7598 p
+= hexnumstr (p
, (ULONGEST
) 0);
7602 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7603 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7605 if (rs
->buf
[0] == '\0')
7608 fprintf_unfiltered (gdb_stdlog
,
7609 "binary downloading NOT "
7610 "supported by target\n");
7611 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7616 fprintf_unfiltered (gdb_stdlog
,
7617 "binary downloading supported by target\n");
7618 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7625 /* Helper function to resize the payload in order to try to get a good
7626 alignment. We try to write an amount of data such that the next write will
7627 start on an address aligned on REMOTE_ALIGN_WRITES. */
7630 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7632 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7635 /* Write memory data directly to the remote machine.
7636 This does not inform the data cache; the data cache uses this.
7637 HEADER is the starting part of the packet.
7638 MEMADDR is the address in the remote memory space.
7639 MYADDR is the address of the buffer in our space.
7640 LEN_UNITS is the number of addressable units to write.
7641 UNIT_SIZE is the length in bytes of an addressable unit.
7642 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7643 should send data as binary ('X'), or hex-encoded ('M').
7645 The function creates packet of the form
7646 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7648 where encoding of <DATA> is terminated by PACKET_FORMAT.
7650 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7653 Return the transferred status, error or OK (an
7654 'enum target_xfer_status' value). Save the number of addressable units
7655 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7657 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7658 exchange between gdb and the stub could look like (?? in place of the
7664 -> $M1000,3:eeeeffffeeee#??
7668 <- eeeeffffeeeedddd */
7670 static enum target_xfer_status
7671 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7672 const gdb_byte
*myaddr
, ULONGEST len_units
,
7673 int unit_size
, ULONGEST
*xfered_len_units
,
7674 char packet_format
, int use_length
)
7676 struct remote_state
*rs
= get_remote_state ();
7682 int payload_capacity_bytes
;
7683 int payload_length_bytes
;
7685 if (packet_format
!= 'X' && packet_format
!= 'M')
7686 internal_error (__FILE__
, __LINE__
,
7687 _("remote_write_bytes_aux: bad packet format"));
7690 return TARGET_XFER_EOF
;
7692 payload_capacity_bytes
= get_memory_write_packet_size ();
7694 /* The packet buffer will be large enough for the payload;
7695 get_memory_packet_size ensures this. */
7698 /* Compute the size of the actual payload by subtracting out the
7699 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7701 payload_capacity_bytes
-= strlen ("$,:#NN");
7703 /* The comma won't be used. */
7704 payload_capacity_bytes
+= 1;
7705 payload_capacity_bytes
-= strlen (header
);
7706 payload_capacity_bytes
-= hexnumlen (memaddr
);
7708 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7710 strcat (rs
->buf
, header
);
7711 p
= rs
->buf
+ strlen (header
);
7713 /* Compute a best guess of the number of bytes actually transfered. */
7714 if (packet_format
== 'X')
7716 /* Best guess at number of bytes that will fit. */
7717 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7719 payload_capacity_bytes
-= hexnumlen (todo_units
);
7720 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7724 /* Number of bytes that will fit. */
7725 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7727 payload_capacity_bytes
-= hexnumlen (todo_units
);
7728 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7731 if (todo_units
<= 0)
7732 internal_error (__FILE__
, __LINE__
,
7733 _("minimum packet size too small to write data"));
7735 /* If we already need another packet, then try to align the end
7736 of this packet to a useful boundary. */
7737 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7738 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7740 /* Append "<memaddr>". */
7741 memaddr
= remote_address_masked (memaddr
);
7742 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7749 /* Append the length and retain its location and size. It may need to be
7750 adjusted once the packet body has been created. */
7752 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7760 /* Append the packet body. */
7761 if (packet_format
== 'X')
7763 /* Binary mode. Send target system values byte by byte, in
7764 increasing byte addresses. Only escape certain critical
7766 payload_length_bytes
=
7767 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7768 &units_written
, payload_capacity_bytes
);
7770 /* If not all TODO units fit, then we'll need another packet. Make
7771 a second try to keep the end of the packet aligned. Don't do
7772 this if the packet is tiny. */
7773 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7777 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7779 if (new_todo_units
!= units_written
)
7780 payload_length_bytes
=
7781 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7782 (gdb_byte
*) p
, &units_written
,
7783 payload_capacity_bytes
);
7786 p
+= payload_length_bytes
;
7787 if (use_length
&& units_written
< todo_units
)
7789 /* Escape chars have filled up the buffer prematurely,
7790 and we have actually sent fewer units than planned.
7791 Fix-up the length field of the packet. Use the same
7792 number of characters as before. */
7793 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7795 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7800 /* Normal mode: Send target system values byte by byte, in
7801 increasing byte addresses. Each byte is encoded as a two hex
7803 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7804 units_written
= todo_units
;
7807 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7808 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7810 if (rs
->buf
[0] == 'E')
7811 return TARGET_XFER_E_IO
;
7813 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7814 send fewer units than we'd planned. */
7815 *xfered_len_units
= (ULONGEST
) units_written
;
7816 return TARGET_XFER_OK
;
7819 /* Write memory data directly to the remote machine.
7820 This does not inform the data cache; the data cache uses this.
7821 MEMADDR is the address in the remote memory space.
7822 MYADDR is the address of the buffer in our space.
7823 LEN is the number of bytes.
7825 Return the transferred status, error or OK (an
7826 'enum target_xfer_status' value). Save the number of bytes
7827 transferred in *XFERED_LEN. Only transfer a single packet. */
7829 static enum target_xfer_status
7830 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7831 int unit_size
, ULONGEST
*xfered_len
)
7833 char *packet_format
= 0;
7835 /* Check whether the target supports binary download. */
7836 check_binary_download (memaddr
);
7838 switch (packet_support (PACKET_X
))
7841 packet_format
= "X";
7843 case PACKET_DISABLE
:
7844 packet_format
= "M";
7846 case PACKET_SUPPORT_UNKNOWN
:
7847 internal_error (__FILE__
, __LINE__
,
7848 _("remote_write_bytes: bad internal state"));
7850 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7853 return remote_write_bytes_aux (packet_format
,
7854 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7855 packet_format
[0], 1);
7858 /* Read memory data directly from the remote machine.
7859 This does not use the data cache; the data cache uses this.
7860 MEMADDR is the address in the remote memory space.
7861 MYADDR is the address of the buffer in our space.
7862 LEN_UNITS is the number of addressable memory units to read..
7863 UNIT_SIZE is the length in bytes of an addressable unit.
7865 Return the transferred status, error or OK (an
7866 'enum target_xfer_status' value). Save the number of bytes
7867 transferred in *XFERED_LEN_UNITS.
7869 See the comment of remote_write_bytes_aux for an example of
7870 memory read/write exchange between gdb and the stub. */
7872 static enum target_xfer_status
7873 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7874 int unit_size
, ULONGEST
*xfered_len_units
)
7876 struct remote_state
*rs
= get_remote_state ();
7877 int buf_size_bytes
; /* Max size of packet output buffer. */
7882 buf_size_bytes
= get_memory_read_packet_size ();
7883 /* The packet buffer will be large enough for the payload;
7884 get_memory_packet_size ensures this. */
7886 /* Number of units that will fit. */
7887 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7889 /* Construct "m"<memaddr>","<len>". */
7890 memaddr
= remote_address_masked (memaddr
);
7893 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7895 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7898 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7899 if (rs
->buf
[0] == 'E'
7900 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7901 && rs
->buf
[3] == '\0')
7902 return TARGET_XFER_E_IO
;
7903 /* Reply describes memory byte by byte, each byte encoded as two hex
7906 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7907 /* Return what we have. Let higher layers handle partial reads. */
7908 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7909 return TARGET_XFER_OK
;
7912 /* Using the set of read-only target sections of remote, read live
7915 For interface/parameters/return description see target.h,
7918 static enum target_xfer_status
7919 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7920 ULONGEST memaddr
, ULONGEST len
,
7921 int unit_size
, ULONGEST
*xfered_len
)
7923 struct target_section
*secp
;
7924 struct target_section_table
*table
;
7926 secp
= target_section_by_addr (ops
, memaddr
);
7928 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7929 secp
->the_bfd_section
)
7932 struct target_section
*p
;
7933 ULONGEST memend
= memaddr
+ len
;
7935 table
= target_get_section_table (ops
);
7937 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7939 if (memaddr
>= p
->addr
)
7941 if (memend
<= p
->endaddr
)
7943 /* Entire transfer is within this section. */
7944 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7947 else if (memaddr
>= p
->endaddr
)
7949 /* This section ends before the transfer starts. */
7954 /* This section overlaps the transfer. Just do half. */
7955 len
= p
->endaddr
- memaddr
;
7956 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7963 return TARGET_XFER_EOF
;
7966 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7967 first if the requested memory is unavailable in traceframe.
7968 Otherwise, fall back to remote_read_bytes_1. */
7970 static enum target_xfer_status
7971 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7972 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7973 ULONGEST
*xfered_len
)
7976 return TARGET_XFER_EOF
;
7978 if (get_traceframe_number () != -1)
7980 VEC(mem_range_s
) *available
;
7982 /* If we fail to get the set of available memory, then the
7983 target does not support querying traceframe info, and so we
7984 attempt reading from the traceframe anyway (assuming the
7985 target implements the old QTro packet then). */
7986 if (traceframe_available_memory (&available
, memaddr
, len
))
7988 struct cleanup
*old_chain
;
7990 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7992 if (VEC_empty (mem_range_s
, available
)
7993 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7995 enum target_xfer_status res
;
7997 /* Don't read into the traceframe's available
7999 if (!VEC_empty (mem_range_s
, available
))
8001 LONGEST oldlen
= len
;
8003 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
8004 gdb_assert (len
<= oldlen
);
8007 do_cleanups (old_chain
);
8009 /* This goes through the topmost target again. */
8010 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8011 len
, unit_size
, xfered_len
);
8012 if (res
== TARGET_XFER_OK
)
8013 return TARGET_XFER_OK
;
8016 /* No use trying further, we know some memory starting
8017 at MEMADDR isn't available. */
8019 return TARGET_XFER_UNAVAILABLE
;
8023 /* Don't try to read more than how much is available, in
8024 case the target implements the deprecated QTro packet to
8025 cater for older GDBs (the target's knowledge of read-only
8026 sections may be outdated by now). */
8027 len
= VEC_index (mem_range_s
, available
, 0)->length
;
8029 do_cleanups (old_chain
);
8033 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8038 /* Sends a packet with content determined by the printf format string
8039 FORMAT and the remaining arguments, then gets the reply. Returns
8040 whether the packet was a success, a failure, or unknown. */
8042 static enum packet_result
remote_send_printf (const char *format
, ...)
8043 ATTRIBUTE_PRINTF (1, 2);
8045 static enum packet_result
8046 remote_send_printf (const char *format
, ...)
8048 struct remote_state
*rs
= get_remote_state ();
8049 int max_size
= get_remote_packet_size ();
8052 va_start (ap
, format
);
8055 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8056 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8058 if (putpkt (rs
->buf
) < 0)
8059 error (_("Communication problem with target."));
8062 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8064 return packet_check_result (rs
->buf
);
8068 restore_remote_timeout (void *p
)
8070 int value
= *(int *)p
;
8072 remote_timeout
= value
;
8075 /* Flash writing can take quite some time. We'll set
8076 effectively infinite timeout for flash operations.
8077 In future, we'll need to decide on a better approach. */
8078 static const int remote_flash_timeout
= 1000;
8081 remote_flash_erase (struct target_ops
*ops
,
8082 ULONGEST address
, LONGEST length
)
8084 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8085 int saved_remote_timeout
= remote_timeout
;
8086 enum packet_result ret
;
8087 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8088 &saved_remote_timeout
);
8090 remote_timeout
= remote_flash_timeout
;
8092 ret
= remote_send_printf ("vFlashErase:%s,%s",
8093 phex (address
, addr_size
),
8097 case PACKET_UNKNOWN
:
8098 error (_("Remote target does not support flash erase"));
8100 error (_("Error erasing flash with vFlashErase packet"));
8105 do_cleanups (back_to
);
8108 static enum target_xfer_status
8109 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8110 ULONGEST length
, ULONGEST
*xfered_len
,
8111 const gdb_byte
*data
)
8113 int saved_remote_timeout
= remote_timeout
;
8114 enum target_xfer_status ret
;
8115 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8116 &saved_remote_timeout
);
8118 remote_timeout
= remote_flash_timeout
;
8119 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8121 do_cleanups (back_to
);
8127 remote_flash_done (struct target_ops
*ops
)
8129 int saved_remote_timeout
= remote_timeout
;
8131 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8132 &saved_remote_timeout
);
8134 remote_timeout
= remote_flash_timeout
;
8135 ret
= remote_send_printf ("vFlashDone");
8136 do_cleanups (back_to
);
8140 case PACKET_UNKNOWN
:
8141 error (_("Remote target does not support vFlashDone"));
8143 error (_("Error finishing flash operation"));
8150 remote_files_info (struct target_ops
*ignore
)
8152 puts_filtered ("Debugging a target over a serial line.\n");
8155 /* Stuff for dealing with the packets which are part of this protocol.
8156 See comment at top of file for details. */
8158 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8159 error to higher layers. Called when a serial error is detected.
8160 The exception message is STRING, followed by a colon and a blank,
8161 the system error message for errno at function entry and final dot
8162 for output compatibility with throw_perror_with_name. */
8165 unpush_and_perror (const char *string
)
8167 int saved_errno
= errno
;
8169 remote_unpush_target ();
8170 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8171 safe_strerror (saved_errno
));
8174 /* Read a single character from the remote end. */
8177 readchar (int timeout
)
8180 struct remote_state
*rs
= get_remote_state ();
8182 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8187 switch ((enum serial_rc
) ch
)
8190 remote_unpush_target ();
8191 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8194 unpush_and_perror (_("Remote communication error. "
8195 "Target disconnected."));
8197 case SERIAL_TIMEOUT
:
8203 /* Wrapper for serial_write that closes the target and throws if
8207 remote_serial_write (const char *str
, int len
)
8209 struct remote_state
*rs
= get_remote_state ();
8211 if (serial_write (rs
->remote_desc
, str
, len
))
8213 unpush_and_perror (_("Remote communication error. "
8214 "Target disconnected."));
8218 /* Send the command in *BUF to the remote machine, and read the reply
8219 into *BUF. Report an error if we get an error reply. Resize
8220 *BUF using xrealloc if necessary to hold the result, and update
8224 remote_send (char **buf
,
8228 getpkt (buf
, sizeof_buf
, 0);
8230 if ((*buf
)[0] == 'E')
8231 error (_("Remote failure reply: %s"), *buf
);
8234 /* Return a pointer to an xmalloc'ed string representing an escaped
8235 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8236 etc. The caller is responsible for releasing the returned
8240 escape_buffer (const char *buf
, int n
)
8242 struct cleanup
*old_chain
;
8243 struct ui_file
*stb
;
8246 stb
= mem_fileopen ();
8247 old_chain
= make_cleanup_ui_file_delete (stb
);
8249 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8250 str
= ui_file_xstrdup (stb
, NULL
);
8251 do_cleanups (old_chain
);
8255 /* Display a null-terminated packet on stdout, for debugging, using C
8259 print_packet (const char *buf
)
8261 puts_filtered ("\"");
8262 fputstr_filtered (buf
, '"', gdb_stdout
);
8263 puts_filtered ("\"");
8267 putpkt (const char *buf
)
8269 return putpkt_binary (buf
, strlen (buf
));
8272 /* Send a packet to the remote machine, with error checking. The data
8273 of the packet is in BUF. The string in BUF can be at most
8274 get_remote_packet_size () - 5 to account for the $, # and checksum,
8275 and for a possible /0 if we are debugging (remote_debug) and want
8276 to print the sent packet as a string. */
8279 putpkt_binary (const char *buf
, int cnt
)
8281 struct remote_state
*rs
= get_remote_state ();
8283 unsigned char csum
= 0;
8284 char *buf2
= (char *) xmalloc (cnt
+ 6);
8285 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8291 /* Catch cases like trying to read memory or listing threads while
8292 we're waiting for a stop reply. The remote server wouldn't be
8293 ready to handle this request, so we'd hang and timeout. We don't
8294 have to worry about this in synchronous mode, because in that
8295 case it's not possible to issue a command while the target is
8296 running. This is not a problem in non-stop mode, because in that
8297 case, the stub is always ready to process serial input. */
8298 if (!target_is_non_stop_p ()
8299 && target_is_async_p ()
8300 && rs
->waiting_for_stop_reply
)
8302 error (_("Cannot execute this command while the target is running.\n"
8303 "Use the \"interrupt\" command to stop the target\n"
8304 "and then try again."));
8307 /* We're sending out a new packet. Make sure we don't look at a
8308 stale cached response. */
8309 rs
->cached_wait_status
= 0;
8311 /* Copy the packet into buffer BUF2, encapsulating it
8312 and giving it a checksum. */
8317 for (i
= 0; i
< cnt
; i
++)
8323 *p
++ = tohex ((csum
>> 4) & 0xf);
8324 *p
++ = tohex (csum
& 0xf);
8326 /* Send it over and over until we get a positive ack. */
8330 int started_error_output
= 0;
8334 struct cleanup
*old_chain
;
8338 str
= escape_buffer (buf2
, p
- buf2
);
8339 old_chain
= make_cleanup (xfree
, str
);
8340 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8341 gdb_flush (gdb_stdlog
);
8342 do_cleanups (old_chain
);
8344 remote_serial_write (buf2
, p
- buf2
);
8346 /* If this is a no acks version of the remote protocol, send the
8347 packet and move on. */
8351 /* Read until either a timeout occurs (-2) or '+' is read.
8352 Handle any notification that arrives in the mean time. */
8355 ch
= readchar (remote_timeout
);
8363 case SERIAL_TIMEOUT
:
8366 if (started_error_output
)
8368 putchar_unfiltered ('\n');
8369 started_error_output
= 0;
8378 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8379 do_cleanups (old_chain
);
8383 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8385 case SERIAL_TIMEOUT
:
8389 do_cleanups (old_chain
);
8392 break; /* Retransmit buffer. */
8396 fprintf_unfiltered (gdb_stdlog
,
8397 "Packet instead of Ack, ignoring it\n");
8398 /* It's probably an old response sent because an ACK
8399 was lost. Gobble up the packet and ack it so it
8400 doesn't get retransmitted when we resend this
8403 remote_serial_write ("+", 1);
8404 continue; /* Now, go look for +. */
8411 /* If we got a notification, handle it, and go back to looking
8413 /* We've found the start of a notification. Now
8414 collect the data. */
8415 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8420 struct cleanup
*old_chain
;
8423 str
= escape_buffer (rs
->buf
, val
);
8424 old_chain
= make_cleanup (xfree
, str
);
8425 fprintf_unfiltered (gdb_stdlog
,
8426 " Notification received: %s\n",
8428 do_cleanups (old_chain
);
8430 handle_notification (rs
->notif_state
, rs
->buf
);
8431 /* We're in sync now, rewait for the ack. */
8438 if (!started_error_output
)
8440 started_error_output
= 1;
8441 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8443 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8444 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8453 if (!started_error_output
)
8455 started_error_output
= 1;
8456 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8458 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8462 break; /* Here to retransmit. */
8466 /* This is wrong. If doing a long backtrace, the user should be
8467 able to get out next time we call QUIT, without anything as
8468 violent as interrupt_query. If we want to provide a way out of
8469 here without getting to the next QUIT, it should be based on
8470 hitting ^C twice as in remote_wait. */
8479 do_cleanups (old_chain
);
8483 /* Come here after finding the start of a frame when we expected an
8484 ack. Do our best to discard the rest of this packet. */
8493 c
= readchar (remote_timeout
);
8496 case SERIAL_TIMEOUT
:
8497 /* Nothing we can do. */
8500 /* Discard the two bytes of checksum and stop. */
8501 c
= readchar (remote_timeout
);
8503 c
= readchar (remote_timeout
);
8506 case '*': /* Run length encoding. */
8507 /* Discard the repeat count. */
8508 c
= readchar (remote_timeout
);
8513 /* A regular character. */
8519 /* Come here after finding the start of the frame. Collect the rest
8520 into *BUF, verifying the checksum, length, and handling run-length
8521 compression. NUL terminate the buffer. If there is not enough room,
8522 expand *BUF using xrealloc.
8524 Returns -1 on error, number of characters in buffer (ignoring the
8525 trailing NULL) on success. (could be extended to return one of the
8526 SERIAL status indications). */
8529 read_frame (char **buf_p
,
8536 struct remote_state
*rs
= get_remote_state ();
8543 c
= readchar (remote_timeout
);
8546 case SERIAL_TIMEOUT
:
8548 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8552 fputs_filtered ("Saw new packet start in middle of old one\n",
8554 return -1; /* Start a new packet, count retries. */
8557 unsigned char pktcsum
;
8563 check_0
= readchar (remote_timeout
);
8565 check_1
= readchar (remote_timeout
);
8567 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8570 fputs_filtered ("Timeout in checksum, retrying\n",
8574 else if (check_0
< 0 || check_1
< 0)
8577 fputs_filtered ("Communication error in checksum\n",
8582 /* Don't recompute the checksum; with no ack packets we
8583 don't have any way to indicate a packet retransmission
8588 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8589 if (csum
== pktcsum
)
8594 struct cleanup
*old_chain
;
8597 str
= escape_buffer (buf
, bc
);
8598 old_chain
= make_cleanup (xfree
, str
);
8599 fprintf_unfiltered (gdb_stdlog
,
8600 "Bad checksum, sentsum=0x%x, "
8601 "csum=0x%x, buf=%s\n",
8602 pktcsum
, csum
, str
);
8603 do_cleanups (old_chain
);
8605 /* Number of characters in buffer ignoring trailing
8609 case '*': /* Run length encoding. */
8614 c
= readchar (remote_timeout
);
8616 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8618 /* The character before ``*'' is repeated. */
8620 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8622 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8624 /* Make some more room in the buffer. */
8625 *sizeof_buf
+= repeat
;
8626 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8630 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8636 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8640 if (bc
>= *sizeof_buf
- 1)
8642 /* Make some more room in the buffer. */
8644 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8655 /* Read a packet from the remote machine, with error checking, and
8656 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8657 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8658 rather than timing out; this is used (in synchronous mode) to wait
8659 for a target that is is executing user code to stop. */
8660 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8661 don't have to change all the calls to getpkt to deal with the
8662 return value, because at the moment I don't know what the right
8663 thing to do it for those. */
8669 getpkt_sane (buf
, sizeof_buf
, forever
);
8673 /* Read a packet from the remote machine, with error checking, and
8674 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8675 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8676 rather than timing out; this is used (in synchronous mode) to wait
8677 for a target that is is executing user code to stop. If FOREVER ==
8678 0, this function is allowed to time out gracefully and return an
8679 indication of this to the caller. Otherwise return the number of
8680 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8681 enough reason to return to the caller. *IS_NOTIF is an output
8682 boolean that indicates whether *BUF holds a notification or not
8683 (a regular packet). */
8686 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8687 int expecting_notif
, int *is_notif
)
8689 struct remote_state
*rs
= get_remote_state ();
8695 /* We're reading a new response. Make sure we don't look at a
8696 previously cached response. */
8697 rs
->cached_wait_status
= 0;
8699 strcpy (*buf
, "timeout");
8702 timeout
= watchdog
> 0 ? watchdog
: -1;
8703 else if (expecting_notif
)
8704 timeout
= 0; /* There should already be a char in the buffer. If
8707 timeout
= remote_timeout
;
8711 /* Process any number of notifications, and then return when
8715 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8717 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8719 /* This can loop forever if the remote side sends us
8720 characters continuously, but if it pauses, we'll get
8721 SERIAL_TIMEOUT from readchar because of timeout. Then
8722 we'll count that as a retry.
8724 Note that even when forever is set, we will only wait
8725 forever prior to the start of a packet. After that, we
8726 expect characters to arrive at a brisk pace. They should
8727 show up within remote_timeout intervals. */
8729 c
= readchar (timeout
);
8730 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8732 if (c
== SERIAL_TIMEOUT
)
8734 if (expecting_notif
)
8735 return -1; /* Don't complain, it's normal to not get
8736 anything in this case. */
8738 if (forever
) /* Watchdog went off? Kill the target. */
8741 remote_unpush_target ();
8742 throw_error (TARGET_CLOSE_ERROR
,
8743 _("Watchdog timeout has expired. "
8744 "Target detached."));
8747 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8751 /* We've found the start of a packet or notification.
8752 Now collect the data. */
8753 val
= read_frame (buf
, sizeof_buf
);
8758 remote_serial_write ("-", 1);
8761 if (tries
> MAX_TRIES
)
8763 /* We have tried hard enough, and just can't receive the
8764 packet/notification. Give up. */
8765 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8767 /* Skip the ack char if we're in no-ack mode. */
8768 if (!rs
->noack_mode
)
8769 remote_serial_write ("+", 1);
8773 /* If we got an ordinary packet, return that to our caller. */
8778 struct cleanup
*old_chain
;
8781 str
= escape_buffer (*buf
, val
);
8782 old_chain
= make_cleanup (xfree
, str
);
8783 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8784 do_cleanups (old_chain
);
8787 /* Skip the ack char if we're in no-ack mode. */
8788 if (!rs
->noack_mode
)
8789 remote_serial_write ("+", 1);
8790 if (is_notif
!= NULL
)
8795 /* If we got a notification, handle it, and go back to looking
8799 gdb_assert (c
== '%');
8803 struct cleanup
*old_chain
;
8806 str
= escape_buffer (*buf
, val
);
8807 old_chain
= make_cleanup (xfree
, str
);
8808 fprintf_unfiltered (gdb_stdlog
,
8809 " Notification received: %s\n",
8811 do_cleanups (old_chain
);
8813 if (is_notif
!= NULL
)
8816 handle_notification (rs
->notif_state
, *buf
);
8818 /* Notifications require no acknowledgement. */
8820 if (expecting_notif
)
8827 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8829 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8833 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8836 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8840 /* Check whether EVENT is a fork event for the process specified
8841 by the pid passed in DATA, and if it is, kill the fork child. */
8844 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8845 QUEUE_ITER (stop_reply_p
) *iter
,
8849 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8850 int parent_pid
= *(int *) param
->input
;
8852 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8854 struct remote_state
*rs
= get_remote_state ();
8855 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8858 res
= remote_vkill (child_pid
, rs
);
8860 error (_("Can't kill fork child process %d"), child_pid
);
8866 /* Kill any new fork children of process PID that haven't been
8867 processed by follow_fork. */
8870 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8872 struct thread_info
*thread
;
8873 struct notif_client
*notif
= ¬if_client_stop
;
8874 struct queue_iter_param param
;
8876 /* Kill the fork child threads of any threads in process PID
8877 that are stopped at a fork event. */
8878 ALL_NON_EXITED_THREADS (thread
)
8880 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8882 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8884 struct remote_state
*rs
= get_remote_state ();
8885 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8888 res
= remote_vkill (child_pid
, rs
);
8890 error (_("Can't kill fork child process %d"), child_pid
);
8894 /* Check for any pending fork events (not reported or processed yet)
8895 in process PID and kill those fork child threads as well. */
8896 remote_notif_get_pending_events (notif
);
8898 param
.output
= NULL
;
8899 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8900 kill_child_of_pending_fork
, ¶m
);
8904 /* Target hook to kill the current inferior. */
8907 remote_kill (struct target_ops
*ops
)
8910 int pid
= ptid_get_pid (inferior_ptid
);
8911 struct remote_state
*rs
= get_remote_state ();
8913 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
8915 /* If we're stopped while forking and we haven't followed yet,
8916 kill the child task. We need to do this before killing the
8917 parent task because if this is a vfork then the parent will
8919 kill_new_fork_children (pid
, rs
);
8921 res
= remote_vkill (pid
, rs
);
8924 target_mourn_inferior ();
8929 /* If we are in 'target remote' mode and we are killing the only
8930 inferior, then we will tell gdbserver to exit and unpush the
8932 if (res
== -1 && !remote_multi_process_p (rs
)
8933 && number_of_live_inferiors () == 1)
8937 /* We've killed the remote end, we get to mourn it. If we are
8938 not in extended mode, mourning the inferior also unpushes
8939 remote_ops from the target stack, which closes the remote
8941 target_mourn_inferior ();
8946 error (_("Can't kill process"));
8949 /* Send a kill request to the target using the 'vKill' packet. */
8952 remote_vkill (int pid
, struct remote_state
*rs
)
8954 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8957 /* Tell the remote target to detach. */
8958 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8960 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8962 switch (packet_ok (rs
->buf
,
8963 &remote_protocol_packets
[PACKET_vKill
]))
8969 case PACKET_UNKNOWN
:
8972 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8976 /* Send a kill request to the target using the 'k' packet. */
8979 remote_kill_k (void)
8981 /* Catch errors so the user can quit from gdb even when we
8982 aren't on speaking terms with the remote system. */
8987 CATCH (ex
, RETURN_MASK_ERROR
)
8989 if (ex
.error
== TARGET_CLOSE_ERROR
)
8991 /* If we got an (EOF) error that caused the target
8992 to go away, then we're done, that's what we wanted.
8993 "k" is susceptible to cause a premature EOF, given
8994 that the remote server isn't actually required to
8995 reply to "k", and it can happen that it doesn't
8996 even get to reply ACK to the "k". */
9000 /* Otherwise, something went wrong. We didn't actually kill
9001 the target. Just propagate the exception, and let the
9002 user or higher layers decide what to do. */
9003 throw_exception (ex
);
9009 remote_mourn (struct target_ops
*target
)
9011 struct remote_state
*rs
= get_remote_state ();
9013 /* In 'target remote' mode with one inferior, we close the connection. */
9014 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9016 unpush_target (target
);
9018 /* remote_close takes care of doing most of the clean up. */
9019 generic_mourn_inferior ();
9023 /* In case we got here due to an error, but we're going to stay
9025 rs
->waiting_for_stop_reply
= 0;
9027 /* If the current general thread belonged to the process we just
9028 detached from or has exited, the remote side current general
9029 thread becomes undefined. Considering a case like this:
9031 - We just got here due to a detach.
9032 - The process that we're detaching from happens to immediately
9033 report a global breakpoint being hit in non-stop mode, in the
9034 same thread we had selected before.
9035 - GDB attaches to this process again.
9036 - This event happens to be the next event we handle.
9038 GDB would consider that the current general thread didn't need to
9039 be set on the stub side (with Hg), since for all it knew,
9040 GENERAL_THREAD hadn't changed.
9042 Notice that although in all-stop mode, the remote server always
9043 sets the current thread to the thread reporting the stop event,
9044 that doesn't happen in non-stop mode; in non-stop, the stub *must
9045 not* change the current thread when reporting a breakpoint hit,
9046 due to the decoupling of event reporting and event handling.
9048 To keep things simple, we always invalidate our notion of the
9050 record_currthread (rs
, minus_one_ptid
);
9052 /* Call common code to mark the inferior as not running. */
9053 generic_mourn_inferior ();
9055 if (!have_inferiors ())
9057 if (!remote_multi_process_p (rs
))
9059 /* Check whether the target is running now - some remote stubs
9060 automatically restart after kill. */
9062 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9064 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9066 /* Assume that the target has been restarted. Set
9067 inferior_ptid so that bits of core GDB realizes
9068 there's something here, e.g., so that the user can
9069 say "kill" again. */
9070 inferior_ptid
= magic_null_ptid
;
9077 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9079 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9083 extended_remote_disable_randomization (int val
)
9085 struct remote_state
*rs
= get_remote_state ();
9088 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9091 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9093 error (_("Target does not support QDisableRandomization."));
9094 if (strcmp (reply
, "OK") != 0)
9095 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9099 extended_remote_run (char *args
)
9101 struct remote_state
*rs
= get_remote_state ();
9103 const char *remote_exec_file
= get_remote_exec_file ();
9105 /* If the user has disabled vRun support, or we have detected that
9106 support is not available, do not try it. */
9107 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9110 strcpy (rs
->buf
, "vRun;");
9111 len
= strlen (rs
->buf
);
9113 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9114 error (_("Remote file name too long for run packet"));
9115 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9116 strlen (remote_exec_file
));
9118 gdb_assert (args
!= NULL
);
9121 struct cleanup
*back_to
;
9125 argv
= gdb_buildargv (args
);
9126 back_to
= make_cleanup_freeargv (argv
);
9127 for (i
= 0; argv
[i
] != NULL
; i
++)
9129 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9130 error (_("Argument list too long for run packet"));
9131 rs
->buf
[len
++] = ';';
9132 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9135 do_cleanups (back_to
);
9138 rs
->buf
[len
++] = '\0';
9141 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9143 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9146 /* We have a wait response. All is well. */
9148 case PACKET_UNKNOWN
:
9151 if (remote_exec_file
[0] == '\0')
9152 error (_("Running the default executable on the remote target failed; "
9153 "try \"set remote exec-file\"?"));
9155 error (_("Running \"%s\" on the remote target failed"),
9158 gdb_assert_not_reached (_("bad switch"));
9162 /* In the extended protocol we want to be able to do things like
9163 "run" and have them basically work as expected. So we need
9164 a special create_inferior function. We support changing the
9165 executable file and the command line arguments, but not the
9169 extended_remote_create_inferior (struct target_ops
*ops
,
9170 char *exec_file
, char *args
,
9171 char **env
, int from_tty
)
9175 struct remote_state
*rs
= get_remote_state ();
9176 const char *remote_exec_file
= get_remote_exec_file ();
9178 /* If running asynchronously, register the target file descriptor
9179 with the event loop. */
9180 if (target_can_async_p ())
9183 /* Disable address space randomization if requested (and supported). */
9184 if (extended_remote_supports_disable_randomization (ops
))
9185 extended_remote_disable_randomization (disable_randomization
);
9187 /* Now restart the remote server. */
9188 run_worked
= extended_remote_run (args
) != -1;
9191 /* vRun was not supported. Fail if we need it to do what the
9193 if (remote_exec_file
[0])
9194 error (_("Remote target does not support \"set remote exec-file\""));
9196 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9198 /* Fall back to "R". */
9199 extended_remote_restart ();
9202 if (!have_inferiors ())
9204 /* Clean up from the last time we ran, before we mark the target
9205 running again. This will mark breakpoints uninserted, and
9206 get_offsets may insert breakpoints. */
9207 init_thread_list ();
9208 init_wait_for_inferior ();
9211 /* vRun's success return is a stop reply. */
9212 stop_reply
= run_worked
? rs
->buf
: NULL
;
9213 add_current_inferior_and_thread (stop_reply
);
9215 /* Get updated offsets, if the stub uses qOffsets. */
9220 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9221 the list of conditions (in agent expression bytecode format), if any, the
9222 target needs to evaluate. The output is placed into the packet buffer
9223 started from BUF and ended at BUF_END. */
9226 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9227 struct bp_target_info
*bp_tgt
, char *buf
,
9230 struct agent_expr
*aexpr
= NULL
;
9233 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9236 buf
+= strlen (buf
);
9237 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9240 /* Send conditions to the target and free the vector. */
9242 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9245 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9246 buf
+= strlen (buf
);
9247 for (i
= 0; i
< aexpr
->len
; ++i
)
9248 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9255 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9256 struct bp_target_info
*bp_tgt
, char *buf
)
9258 struct agent_expr
*aexpr
= NULL
;
9261 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9264 buf
+= strlen (buf
);
9266 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9267 buf
+= strlen (buf
);
9269 /* Concatenate all the agent expressions that are commands into the
9272 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9275 sprintf (buf
, "X%x,", aexpr
->len
);
9276 buf
+= strlen (buf
);
9277 for (i
= 0; i
< aexpr
->len
; ++i
)
9278 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9283 /* Insert a breakpoint. On targets that have software breakpoint
9284 support, we ask the remote target to do the work; on targets
9285 which don't, we insert a traditional memory breakpoint. */
9288 remote_insert_breakpoint (struct target_ops
*ops
,
9289 struct gdbarch
*gdbarch
,
9290 struct bp_target_info
*bp_tgt
)
9292 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9293 If it succeeds, then set the support to PACKET_ENABLE. If it
9294 fails, and the user has explicitly requested the Z support then
9295 report an error, otherwise, mark it disabled and go on. */
9297 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9299 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9300 struct remote_state
*rs
;
9304 /* Make sure the remote is pointing at the right process, if
9306 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9307 set_general_process ();
9309 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9311 rs
= get_remote_state ();
9313 endbuf
= rs
->buf
+ get_remote_packet_size ();
9318 addr
= (ULONGEST
) remote_address_masked (addr
);
9319 p
+= hexnumstr (p
, addr
);
9320 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
9322 if (remote_supports_cond_breakpoints (ops
))
9323 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9325 if (remote_can_run_breakpoint_commands (ops
))
9326 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9329 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9331 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9336 bp_tgt
->placed_address
= addr
;
9337 bp_tgt
->placed_size
= bpsize
;
9339 case PACKET_UNKNOWN
:
9344 /* If this breakpoint has target-side commands but this stub doesn't
9345 support Z0 packets, throw error. */
9346 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9347 throw_error (NOT_SUPPORTED_ERROR
, _("\
9348 Target doesn't support breakpoints that have target side commands."));
9350 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9354 remote_remove_breakpoint (struct target_ops
*ops
,
9355 struct gdbarch
*gdbarch
,
9356 struct bp_target_info
*bp_tgt
)
9358 CORE_ADDR addr
= bp_tgt
->placed_address
;
9359 struct remote_state
*rs
= get_remote_state ();
9361 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9364 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9366 /* Make sure the remote is pointing at the right process, if
9368 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9369 set_general_process ();
9375 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9376 p
+= hexnumstr (p
, addr
);
9377 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9380 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9382 return (rs
->buf
[0] == 'E');
9385 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9388 static enum Z_packet_type
9389 watchpoint_to_Z_packet (int type
)
9394 return Z_PACKET_WRITE_WP
;
9397 return Z_PACKET_READ_WP
;
9400 return Z_PACKET_ACCESS_WP
;
9403 internal_error (__FILE__
, __LINE__
,
9404 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9409 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9410 enum target_hw_bp_type type
, struct expression
*cond
)
9412 struct remote_state
*rs
= get_remote_state ();
9413 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9415 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9417 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9420 /* Make sure the remote is pointing at the right process, if
9422 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9423 set_general_process ();
9425 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9426 p
= strchr (rs
->buf
, '\0');
9427 addr
= remote_address_masked (addr
);
9428 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9429 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9432 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9434 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9438 case PACKET_UNKNOWN
:
9443 internal_error (__FILE__
, __LINE__
,
9444 _("remote_insert_watchpoint: reached end of function"));
9448 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9449 CORE_ADDR start
, int length
)
9451 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9453 return diff
< length
;
9458 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9459 enum target_hw_bp_type type
, struct expression
*cond
)
9461 struct remote_state
*rs
= get_remote_state ();
9462 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9464 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9466 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9469 /* Make sure the remote is pointing at the right process, if
9471 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9472 set_general_process ();
9474 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9475 p
= strchr (rs
->buf
, '\0');
9476 addr
= remote_address_masked (addr
);
9477 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9478 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9480 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9482 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9485 case PACKET_UNKNOWN
:
9490 internal_error (__FILE__
, __LINE__
,
9491 _("remote_remove_watchpoint: reached end of function"));
9495 int remote_hw_watchpoint_limit
= -1;
9496 int remote_hw_watchpoint_length_limit
= -1;
9497 int remote_hw_breakpoint_limit
= -1;
9500 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9501 CORE_ADDR addr
, int len
)
9503 if (remote_hw_watchpoint_length_limit
== 0)
9505 else if (remote_hw_watchpoint_length_limit
< 0)
9507 else if (len
<= remote_hw_watchpoint_length_limit
)
9514 remote_check_watch_resources (struct target_ops
*self
,
9515 enum bptype type
, int cnt
, int ot
)
9517 if (type
== bp_hardware_breakpoint
)
9519 if (remote_hw_breakpoint_limit
== 0)
9521 else if (remote_hw_breakpoint_limit
< 0)
9523 else if (cnt
<= remote_hw_breakpoint_limit
)
9528 if (remote_hw_watchpoint_limit
== 0)
9530 else if (remote_hw_watchpoint_limit
< 0)
9534 else if (cnt
<= remote_hw_watchpoint_limit
)
9540 /* The to_stopped_by_sw_breakpoint method of target remote. */
9543 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9545 struct thread_info
*thread
= inferior_thread ();
9547 return (thread
->priv
!= NULL
9548 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9551 /* The to_supports_stopped_by_sw_breakpoint method of target
9555 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9557 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9560 /* The to_stopped_by_hw_breakpoint method of target remote. */
9563 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9565 struct thread_info
*thread
= inferior_thread ();
9567 return (thread
->priv
!= NULL
9568 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9571 /* The to_supports_stopped_by_hw_breakpoint method of target
9575 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9577 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9581 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9583 struct thread_info
*thread
= inferior_thread ();
9585 return (thread
->priv
!= NULL
9586 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9590 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9592 struct thread_info
*thread
= inferior_thread ();
9594 if (thread
->priv
!= NULL
9595 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9597 *addr_p
= thread
->priv
->watch_data_address
;
9606 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9607 struct bp_target_info
*bp_tgt
)
9609 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9610 struct remote_state
*rs
;
9615 /* The length field should be set to the size of a breakpoint
9616 instruction, even though we aren't inserting one ourselves. */
9618 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9620 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9623 /* Make sure the remote is pointing at the right process, if
9625 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9626 set_general_process ();
9628 rs
= get_remote_state ();
9630 endbuf
= rs
->buf
+ get_remote_packet_size ();
9636 addr
= remote_address_masked (addr
);
9637 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9638 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9640 if (remote_supports_cond_breakpoints (self
))
9641 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9643 if (remote_can_run_breakpoint_commands (self
))
9644 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9647 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9649 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9652 if (rs
->buf
[1] == '.')
9654 message
= strchr (rs
->buf
+ 2, '.');
9656 error (_("Remote failure reply: %s"), message
+ 1);
9659 case PACKET_UNKNOWN
:
9662 bp_tgt
->placed_address
= addr
;
9663 bp_tgt
->placed_size
= bpsize
;
9666 internal_error (__FILE__
, __LINE__
,
9667 _("remote_insert_hw_breakpoint: reached end of function"));
9672 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9673 struct bp_target_info
*bp_tgt
)
9676 struct remote_state
*rs
= get_remote_state ();
9678 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9680 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9683 /* Make sure the remote is pointing at the right process, if
9685 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9686 set_general_process ();
9692 addr
= remote_address_masked (bp_tgt
->placed_address
);
9693 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9694 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9697 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9699 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9702 case PACKET_UNKNOWN
:
9707 internal_error (__FILE__
, __LINE__
,
9708 _("remote_remove_hw_breakpoint: reached end of function"));
9711 /* Verify memory using the "qCRC:" request. */
9714 remote_verify_memory (struct target_ops
*ops
,
9715 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9717 struct remote_state
*rs
= get_remote_state ();
9718 unsigned long host_crc
, target_crc
;
9721 /* It doesn't make sense to use qCRC if the remote target is
9722 connected but not running. */
9723 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9725 enum packet_result result
;
9727 /* Make sure the remote is pointing at the right process. */
9728 set_general_process ();
9730 /* FIXME: assumes lma can fit into long. */
9731 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9732 (long) lma
, (long) size
);
9735 /* Be clever; compute the host_crc before waiting for target
9737 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9739 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9741 result
= packet_ok (rs
->buf
,
9742 &remote_protocol_packets
[PACKET_qCRC
]);
9743 if (result
== PACKET_ERROR
)
9745 else if (result
== PACKET_OK
)
9747 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9748 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9750 return (host_crc
== target_crc
);
9754 return simple_verify_memory (ops
, data
, lma
, size
);
9757 /* compare-sections command
9759 With no arguments, compares each loadable section in the exec bfd
9760 with the same memory range on the target, and reports mismatches.
9761 Useful for verifying the image on the target against the exec file. */
9764 compare_sections_command (char *args
, int from_tty
)
9767 struct cleanup
*old_chain
;
9769 const char *sectname
;
9778 error (_("command cannot be used without an exec file"));
9780 /* Make sure the remote is pointing at the right process. */
9781 set_general_process ();
9783 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9789 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9791 if (!(s
->flags
& SEC_LOAD
))
9792 continue; /* Skip non-loadable section. */
9794 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9795 continue; /* Skip writeable sections */
9797 size
= bfd_get_section_size (s
);
9799 continue; /* Skip zero-length section. */
9801 sectname
= bfd_get_section_name (exec_bfd
, s
);
9802 if (args
&& strcmp (args
, sectname
) != 0)
9803 continue; /* Not the section selected by user. */
9805 matched
= 1; /* Do this section. */
9808 sectdata
= (gdb_byte
*) xmalloc (size
);
9809 old_chain
= make_cleanup (xfree
, sectdata
);
9810 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9812 res
= target_verify_memory (sectdata
, lma
, size
);
9815 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9816 paddress (target_gdbarch (), lma
),
9817 paddress (target_gdbarch (), lma
+ size
));
9819 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9820 paddress (target_gdbarch (), lma
),
9821 paddress (target_gdbarch (), lma
+ size
));
9823 printf_filtered ("matched.\n");
9826 printf_filtered ("MIS-MATCHED!\n");
9830 do_cleanups (old_chain
);
9833 warning (_("One or more sections of the target image does not match\n\
9834 the loaded file\n"));
9835 if (args
&& !matched
)
9836 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9839 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9840 into remote target. The number of bytes written to the remote
9841 target is returned, or -1 for error. */
9843 static enum target_xfer_status
9844 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9845 const char *annex
, const gdb_byte
*writebuf
,
9846 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9847 struct packet_config
*packet
)
9851 struct remote_state
*rs
= get_remote_state ();
9852 int max_size
= get_memory_write_packet_size ();
9854 if (packet
->support
== PACKET_DISABLE
)
9855 return TARGET_XFER_E_IO
;
9857 /* Insert header. */
9858 i
= snprintf (rs
->buf
, max_size
,
9859 "qXfer:%s:write:%s:%s:",
9860 object_name
, annex
? annex
: "",
9861 phex_nz (offset
, sizeof offset
));
9862 max_size
-= (i
+ 1);
9864 /* Escape as much data as fits into rs->buf. */
9865 buf_len
= remote_escape_output
9866 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9868 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9869 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9870 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9871 return TARGET_XFER_E_IO
;
9873 unpack_varlen_hex (rs
->buf
, &n
);
9876 return TARGET_XFER_OK
;
9879 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9880 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9881 number of bytes read is returned, or 0 for EOF, or -1 for error.
9882 The number of bytes read may be less than LEN without indicating an
9883 EOF. PACKET is checked and updated to indicate whether the remote
9884 target supports this object. */
9886 static enum target_xfer_status
9887 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9889 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9890 ULONGEST
*xfered_len
,
9891 struct packet_config
*packet
)
9893 struct remote_state
*rs
= get_remote_state ();
9894 LONGEST i
, n
, packet_len
;
9896 if (packet
->support
== PACKET_DISABLE
)
9897 return TARGET_XFER_E_IO
;
9899 /* Check whether we've cached an end-of-object packet that matches
9901 if (rs
->finished_object
)
9903 if (strcmp (object_name
, rs
->finished_object
) == 0
9904 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9905 && offset
== rs
->finished_offset
)
9906 return TARGET_XFER_EOF
;
9909 /* Otherwise, we're now reading something different. Discard
9911 xfree (rs
->finished_object
);
9912 xfree (rs
->finished_annex
);
9913 rs
->finished_object
= NULL
;
9914 rs
->finished_annex
= NULL
;
9917 /* Request only enough to fit in a single packet. The actual data
9918 may not, since we don't know how much of it will need to be escaped;
9919 the target is free to respond with slightly less data. We subtract
9920 five to account for the response type and the protocol frame. */
9921 n
= min (get_remote_packet_size () - 5, len
);
9922 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9923 object_name
, annex
? annex
: "",
9924 phex_nz (offset
, sizeof offset
),
9925 phex_nz (n
, sizeof n
));
9926 i
= putpkt (rs
->buf
);
9928 return TARGET_XFER_E_IO
;
9931 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9932 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9933 return TARGET_XFER_E_IO
;
9935 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9936 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9938 /* 'm' means there is (or at least might be) more data after this
9939 batch. That does not make sense unless there's at least one byte
9940 of data in this reply. */
9941 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9942 error (_("Remote qXfer reply contained no data."));
9944 /* Got some data. */
9945 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9946 packet_len
- 1, readbuf
, n
);
9948 /* 'l' is an EOF marker, possibly including a final block of data,
9949 or possibly empty. If we have the final block of a non-empty
9950 object, record this fact to bypass a subsequent partial read. */
9951 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9953 rs
->finished_object
= xstrdup (object_name
);
9954 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9955 rs
->finished_offset
= offset
+ i
;
9959 return TARGET_XFER_EOF
;
9963 return TARGET_XFER_OK
;
9967 static enum target_xfer_status
9968 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9969 const char *annex
, gdb_byte
*readbuf
,
9970 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9971 ULONGEST
*xfered_len
)
9973 struct remote_state
*rs
;
9977 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9979 set_remote_traceframe ();
9980 set_general_thread (inferior_ptid
);
9982 rs
= get_remote_state ();
9984 /* Handle memory using the standard memory routines. */
9985 if (object
== TARGET_OBJECT_MEMORY
)
9987 /* If the remote target is connected but not running, we should
9988 pass this request down to a lower stratum (e.g. the executable
9990 if (!target_has_execution
)
9991 return TARGET_XFER_EOF
;
9993 if (writebuf
!= NULL
)
9994 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9997 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
10001 /* Handle SPU memory using qxfer packets. */
10002 if (object
== TARGET_OBJECT_SPU
)
10005 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
10006 xfered_len
, &remote_protocol_packets
10007 [PACKET_qXfer_spu_read
]);
10009 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
10010 xfered_len
, &remote_protocol_packets
10011 [PACKET_qXfer_spu_write
]);
10014 /* Handle extra signal info using qxfer packets. */
10015 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10018 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10019 xfered_len
, &remote_protocol_packets
10020 [PACKET_qXfer_siginfo_read
]);
10022 return remote_write_qxfer (ops
, "siginfo", annex
,
10023 writebuf
, offset
, len
, xfered_len
,
10024 &remote_protocol_packets
10025 [PACKET_qXfer_siginfo_write
]);
10028 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10031 return remote_read_qxfer (ops
, "statictrace", annex
,
10032 readbuf
, offset
, len
, xfered_len
,
10033 &remote_protocol_packets
10034 [PACKET_qXfer_statictrace_read
]);
10036 return TARGET_XFER_E_IO
;
10039 /* Only handle flash writes. */
10040 if (writebuf
!= NULL
)
10044 case TARGET_OBJECT_FLASH
:
10045 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10049 return TARGET_XFER_E_IO
;
10053 /* Map pre-existing objects onto letters. DO NOT do this for new
10054 objects!!! Instead specify new query packets. */
10057 case TARGET_OBJECT_AVR
:
10061 case TARGET_OBJECT_AUXV
:
10062 gdb_assert (annex
== NULL
);
10063 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10065 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10067 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10068 return remote_read_qxfer
10069 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10070 &remote_protocol_packets
[PACKET_qXfer_features
]);
10072 case TARGET_OBJECT_LIBRARIES
:
10073 return remote_read_qxfer
10074 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10075 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10077 case TARGET_OBJECT_LIBRARIES_SVR4
:
10078 return remote_read_qxfer
10079 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10080 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10082 case TARGET_OBJECT_MEMORY_MAP
:
10083 gdb_assert (annex
== NULL
);
10084 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10086 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10088 case TARGET_OBJECT_OSDATA
:
10089 /* Should only get here if we're connected. */
10090 gdb_assert (rs
->remote_desc
);
10091 return remote_read_qxfer
10092 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10093 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10095 case TARGET_OBJECT_THREADS
:
10096 gdb_assert (annex
== NULL
);
10097 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10099 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10101 case TARGET_OBJECT_TRACEFRAME_INFO
:
10102 gdb_assert (annex
== NULL
);
10103 return remote_read_qxfer
10104 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10105 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10107 case TARGET_OBJECT_FDPIC
:
10108 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10110 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10112 case TARGET_OBJECT_OPENVMS_UIB
:
10113 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10115 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10117 case TARGET_OBJECT_BTRACE
:
10118 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10120 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10122 case TARGET_OBJECT_BTRACE_CONF
:
10123 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10125 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10127 case TARGET_OBJECT_EXEC_FILE
:
10128 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10130 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10133 return TARGET_XFER_E_IO
;
10136 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10137 large enough let the caller deal with it. */
10138 if (len
< get_remote_packet_size ())
10139 return TARGET_XFER_E_IO
;
10140 len
= get_remote_packet_size ();
10142 /* Except for querying the minimum buffer size, target must be open. */
10143 if (!rs
->remote_desc
)
10144 error (_("remote query is only available after target open"));
10146 gdb_assert (annex
!= NULL
);
10147 gdb_assert (readbuf
!= NULL
);
10151 *p2
++ = query_type
;
10153 /* We used one buffer char for the remote protocol q command and
10154 another for the query type. As the remote protocol encapsulation
10155 uses 4 chars plus one extra in case we are debugging
10156 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10159 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10161 /* Bad caller may have sent forbidden characters. */
10162 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10167 gdb_assert (annex
[i
] == '\0');
10169 i
= putpkt (rs
->buf
);
10171 return TARGET_XFER_E_IO
;
10173 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10174 strcpy ((char *) readbuf
, rs
->buf
);
10176 *xfered_len
= strlen ((char *) readbuf
);
10177 return TARGET_XFER_OK
;
10181 remote_search_memory (struct target_ops
* ops
,
10182 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10183 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10184 CORE_ADDR
*found_addrp
)
10186 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10187 struct remote_state
*rs
= get_remote_state ();
10188 int max_size
= get_memory_write_packet_size ();
10189 struct packet_config
*packet
=
10190 &remote_protocol_packets
[PACKET_qSearch_memory
];
10191 /* Number of packet bytes used to encode the pattern;
10192 this could be more than PATTERN_LEN due to escape characters. */
10193 int escaped_pattern_len
;
10194 /* Amount of pattern that was encodable in the packet. */
10195 int used_pattern_len
;
10198 ULONGEST found_addr
;
10200 /* Don't go to the target if we don't have to.
10201 This is done before checking packet->support to avoid the possibility that
10202 a success for this edge case means the facility works in general. */
10203 if (pattern_len
> search_space_len
)
10205 if (pattern_len
== 0)
10207 *found_addrp
= start_addr
;
10211 /* If we already know the packet isn't supported, fall back to the simple
10212 way of searching memory. */
10214 if (packet_config_support (packet
) == PACKET_DISABLE
)
10216 /* Target doesn't provided special support, fall back and use the
10217 standard support (copy memory and do the search here). */
10218 return simple_search_memory (ops
, start_addr
, search_space_len
,
10219 pattern
, pattern_len
, found_addrp
);
10222 /* Make sure the remote is pointing at the right process. */
10223 set_general_process ();
10225 /* Insert header. */
10226 i
= snprintf (rs
->buf
, max_size
,
10227 "qSearch:memory:%s;%s;",
10228 phex_nz (start_addr
, addr_size
),
10229 phex_nz (search_space_len
, sizeof (search_space_len
)));
10230 max_size
-= (i
+ 1);
10232 /* Escape as much data as fits into rs->buf. */
10233 escaped_pattern_len
=
10234 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10235 &used_pattern_len
, max_size
);
10237 /* Bail if the pattern is too large. */
10238 if (used_pattern_len
!= pattern_len
)
10239 error (_("Pattern is too large to transmit to remote target."));
10241 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10242 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10243 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10245 /* The request may not have worked because the command is not
10246 supported. If so, fall back to the simple way. */
10247 if (packet
->support
== PACKET_DISABLE
)
10249 return simple_search_memory (ops
, start_addr
, search_space_len
,
10250 pattern
, pattern_len
, found_addrp
);
10255 if (rs
->buf
[0] == '0')
10257 else if (rs
->buf
[0] == '1')
10260 if (rs
->buf
[1] != ',')
10261 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10262 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10263 *found_addrp
= found_addr
;
10266 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10272 remote_rcmd (struct target_ops
*self
, const char *command
,
10273 struct ui_file
*outbuf
)
10275 struct remote_state
*rs
= get_remote_state ();
10278 if (!rs
->remote_desc
)
10279 error (_("remote rcmd is only available after target open"));
10281 /* Send a NULL command across as an empty command. */
10282 if (command
== NULL
)
10285 /* The query prefix. */
10286 strcpy (rs
->buf
, "qRcmd,");
10287 p
= strchr (rs
->buf
, '\0');
10289 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10290 > get_remote_packet_size ())
10291 error (_("\"monitor\" command ``%s'' is too long."), command
);
10293 /* Encode the actual command. */
10294 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10296 if (putpkt (rs
->buf
) < 0)
10297 error (_("Communication problem with target."));
10299 /* get/display the response */
10304 /* XXX - see also remote_get_noisy_reply(). */
10305 QUIT
; /* Allow user to bail out with ^C. */
10307 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10309 /* Timeout. Continue to (try to) read responses.
10310 This is better than stopping with an error, assuming the stub
10311 is still executing the (long) monitor command.
10312 If needed, the user can interrupt gdb using C-c, obtaining
10313 an effect similar to stop on timeout. */
10317 if (buf
[0] == '\0')
10318 error (_("Target does not support this command."));
10319 if (buf
[0] == 'O' && buf
[1] != 'K')
10321 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10324 if (strcmp (buf
, "OK") == 0)
10326 if (strlen (buf
) == 3 && buf
[0] == 'E'
10327 && isdigit (buf
[1]) && isdigit (buf
[2]))
10329 error (_("Protocol error with Rcmd"));
10331 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10333 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10335 fputc_unfiltered (c
, outbuf
);
10341 static VEC(mem_region_s
) *
10342 remote_memory_map (struct target_ops
*ops
)
10344 VEC(mem_region_s
) *result
= NULL
;
10345 char *text
= target_read_stralloc (¤t_target
,
10346 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10350 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10352 result
= parse_memory_map (text
);
10353 do_cleanups (back_to
);
10360 packet_command (char *args
, int from_tty
)
10362 struct remote_state
*rs
= get_remote_state ();
10364 if (!rs
->remote_desc
)
10365 error (_("command can only be used with remote target"));
10368 error (_("remote-packet command requires packet text as argument"));
10370 puts_filtered ("sending: ");
10371 print_packet (args
);
10372 puts_filtered ("\n");
10375 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10376 puts_filtered ("received: ");
10377 print_packet (rs
->buf
);
10378 puts_filtered ("\n");
10382 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10384 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10386 static void threadset_test_cmd (char *cmd
, int tty
);
10388 static void threadalive_test (char *cmd
, int tty
);
10390 static void threadlist_test_cmd (char *cmd
, int tty
);
10392 int get_and_display_threadinfo (threadref
*ref
);
10394 static void threadinfo_test_cmd (char *cmd
, int tty
);
10396 static int thread_display_step (threadref
*ref
, void *context
);
10398 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10400 static void init_remote_threadtests (void);
10402 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10405 threadset_test_cmd (char *cmd
, int tty
)
10407 int sample_thread
= SAMPLE_THREAD
;
10409 printf_filtered (_("Remote threadset test\n"));
10410 set_general_thread (sample_thread
);
10415 threadalive_test (char *cmd
, int tty
)
10417 int sample_thread
= SAMPLE_THREAD
;
10418 int pid
= ptid_get_pid (inferior_ptid
);
10419 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10421 if (remote_thread_alive (ptid
))
10422 printf_filtered ("PASS: Thread alive test\n");
10424 printf_filtered ("FAIL: Thread alive test\n");
10427 void output_threadid (char *title
, threadref
*ref
);
10430 output_threadid (char *title
, threadref
*ref
)
10434 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10436 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10440 threadlist_test_cmd (char *cmd
, int tty
)
10443 threadref nextthread
;
10444 int done
, result_count
;
10445 threadref threadlist
[3];
10447 printf_filtered ("Remote Threadlist test\n");
10448 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10449 &result_count
, &threadlist
[0]))
10450 printf_filtered ("FAIL: threadlist test\n");
10453 threadref
*scan
= threadlist
;
10454 threadref
*limit
= scan
+ result_count
;
10456 while (scan
< limit
)
10457 output_threadid (" thread ", scan
++);
10462 display_thread_info (struct gdb_ext_thread_info
*info
)
10464 output_threadid ("Threadid: ", &info
->threadid
);
10465 printf_filtered ("Name: %s\n ", info
->shortname
);
10466 printf_filtered ("State: %s\n", info
->display
);
10467 printf_filtered ("other: %s\n\n", info
->more_display
);
10471 get_and_display_threadinfo (threadref
*ref
)
10475 struct gdb_ext_thread_info threadinfo
;
10477 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10478 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10479 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10480 display_thread_info (&threadinfo
);
10485 threadinfo_test_cmd (char *cmd
, int tty
)
10487 int athread
= SAMPLE_THREAD
;
10491 int_to_threadref (&thread
, athread
);
10492 printf_filtered ("Remote Threadinfo test\n");
10493 if (!get_and_display_threadinfo (&thread
))
10494 printf_filtered ("FAIL cannot get thread info\n");
10498 thread_display_step (threadref
*ref
, void *context
)
10500 /* output_threadid(" threadstep ",ref); *//* simple test */
10501 return get_and_display_threadinfo (ref
);
10505 threadlist_update_test_cmd (char *cmd
, int tty
)
10507 printf_filtered ("Remote Threadlist update test\n");
10508 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10512 init_remote_threadtests (void)
10514 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10515 _("Fetch and print the remote list of "
10516 "thread identifiers, one pkt only"));
10517 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10518 _("Fetch and display info about one thread"));
10519 add_com ("tset", class_obscure
, threadset_test_cmd
,
10520 _("Test setting to a different thread"));
10521 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10522 _("Iterate through updating all remote thread info"));
10523 add_com ("talive", class_obscure
, threadalive_test
,
10524 _(" Remote thread alive test "));
10529 /* Convert a thread ID to a string. Returns the string in a static
10533 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10535 static char buf
[64];
10536 struct remote_state
*rs
= get_remote_state ();
10538 if (ptid_equal (ptid
, null_ptid
))
10539 return normal_pid_to_str (ptid
);
10540 else if (ptid_is_pid (ptid
))
10542 /* Printing an inferior target id. */
10544 /* When multi-process extensions are off, there's no way in the
10545 remote protocol to know the remote process id, if there's any
10546 at all. There's one exception --- when we're connected with
10547 target extended-remote, and we manually attached to a process
10548 with "attach PID". We don't record anywhere a flag that
10549 allows us to distinguish that case from the case of
10550 connecting with extended-remote and the stub already being
10551 attached to a process, and reporting yes to qAttached, hence
10552 no smart special casing here. */
10553 if (!remote_multi_process_p (rs
))
10555 xsnprintf (buf
, sizeof buf
, "Remote target");
10559 return normal_pid_to_str (ptid
);
10563 if (ptid_equal (magic_null_ptid
, ptid
))
10564 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10565 else if (remote_multi_process_p (rs
))
10566 if (ptid_get_lwp (ptid
) == 0)
10567 return normal_pid_to_str (ptid
);
10569 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10570 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10572 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10573 ptid_get_lwp (ptid
));
10578 /* Get the address of the thread local variable in OBJFILE which is
10579 stored at OFFSET within the thread local storage for thread PTID. */
10582 remote_get_thread_local_address (struct target_ops
*ops
,
10583 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10585 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10587 struct remote_state
*rs
= get_remote_state ();
10589 char *endp
= rs
->buf
+ get_remote_packet_size ();
10590 enum packet_result result
;
10592 strcpy (p
, "qGetTLSAddr:");
10594 p
= write_ptid (p
, endp
, ptid
);
10596 p
+= hexnumstr (p
, offset
);
10598 p
+= hexnumstr (p
, lm
);
10602 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10603 result
= packet_ok (rs
->buf
,
10604 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10605 if (result
== PACKET_OK
)
10609 unpack_varlen_hex (rs
->buf
, &result
);
10612 else if (result
== PACKET_UNKNOWN
)
10613 throw_error (TLS_GENERIC_ERROR
,
10614 _("Remote target doesn't support qGetTLSAddr packet"));
10616 throw_error (TLS_GENERIC_ERROR
,
10617 _("Remote target failed to process qGetTLSAddr request"));
10620 throw_error (TLS_GENERIC_ERROR
,
10621 _("TLS not supported or disabled on this target"));
10626 /* Provide thread local base, i.e. Thread Information Block address.
10627 Returns 1 if ptid is found and thread_local_base is non zero. */
10630 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10632 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10634 struct remote_state
*rs
= get_remote_state ();
10636 char *endp
= rs
->buf
+ get_remote_packet_size ();
10637 enum packet_result result
;
10639 strcpy (p
, "qGetTIBAddr:");
10641 p
= write_ptid (p
, endp
, ptid
);
10645 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10646 result
= packet_ok (rs
->buf
,
10647 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10648 if (result
== PACKET_OK
)
10652 unpack_varlen_hex (rs
->buf
, &result
);
10654 *addr
= (CORE_ADDR
) result
;
10657 else if (result
== PACKET_UNKNOWN
)
10658 error (_("Remote target doesn't support qGetTIBAddr packet"));
10660 error (_("Remote target failed to process qGetTIBAddr request"));
10663 error (_("qGetTIBAddr not supported or disabled on this target"));
10668 /* Support for inferring a target description based on the current
10669 architecture and the size of a 'g' packet. While the 'g' packet
10670 can have any size (since optional registers can be left off the
10671 end), some sizes are easily recognizable given knowledge of the
10672 approximate architecture. */
10674 struct remote_g_packet_guess
10677 const struct target_desc
*tdesc
;
10679 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10680 DEF_VEC_O(remote_g_packet_guess_s
);
10682 struct remote_g_packet_data
10684 VEC(remote_g_packet_guess_s
) *guesses
;
10687 static struct gdbarch_data
*remote_g_packet_data_handle
;
10690 remote_g_packet_data_init (struct obstack
*obstack
)
10692 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10696 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10697 const struct target_desc
*tdesc
)
10699 struct remote_g_packet_data
*data
10700 = ((struct remote_g_packet_data
*)
10701 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10702 struct remote_g_packet_guess new_guess
, *guess
;
10705 gdb_assert (tdesc
!= NULL
);
10708 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10710 if (guess
->bytes
== bytes
)
10711 internal_error (__FILE__
, __LINE__
,
10712 _("Duplicate g packet description added for size %d"),
10715 new_guess
.bytes
= bytes
;
10716 new_guess
.tdesc
= tdesc
;
10717 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10720 /* Return 1 if remote_read_description would do anything on this target
10721 and architecture, 0 otherwise. */
10724 remote_read_description_p (struct target_ops
*target
)
10726 struct remote_g_packet_data
*data
10727 = ((struct remote_g_packet_data
*)
10728 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10730 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10736 static const struct target_desc
*
10737 remote_read_description (struct target_ops
*target
)
10739 struct remote_g_packet_data
*data
10740 = ((struct remote_g_packet_data
*)
10741 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10743 /* Do not try this during initial connection, when we do not know
10744 whether there is a running but stopped thread. */
10745 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10746 return target
->beneath
->to_read_description (target
->beneath
);
10748 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10750 struct remote_g_packet_guess
*guess
;
10752 int bytes
= send_g_packet ();
10755 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10757 if (guess
->bytes
== bytes
)
10758 return guess
->tdesc
;
10760 /* We discard the g packet. A minor optimization would be to
10761 hold on to it, and fill the register cache once we have selected
10762 an architecture, but it's too tricky to do safely. */
10765 return target
->beneath
->to_read_description (target
->beneath
);
10768 /* Remote file transfer support. This is host-initiated I/O, not
10769 target-initiated; for target-initiated, see remote-fileio.c. */
10771 /* If *LEFT is at least the length of STRING, copy STRING to
10772 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10773 decrease *LEFT. Otherwise raise an error. */
10776 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10778 int len
= strlen (string
);
10781 error (_("Packet too long for target."));
10783 memcpy (*buffer
, string
, len
);
10787 /* NUL-terminate the buffer as a convenience, if there is
10793 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10794 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10795 decrease *LEFT. Otherwise raise an error. */
10798 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10801 if (2 * len
> *left
)
10802 error (_("Packet too long for target."));
10804 bin2hex (bytes
, *buffer
, len
);
10805 *buffer
+= 2 * len
;
10808 /* NUL-terminate the buffer as a convenience, if there is
10814 /* If *LEFT is large enough, convert VALUE to hex and add it to
10815 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10816 decrease *LEFT. Otherwise raise an error. */
10819 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10821 int len
= hexnumlen (value
);
10824 error (_("Packet too long for target."));
10826 hexnumstr (*buffer
, value
);
10830 /* NUL-terminate the buffer as a convenience, if there is
10836 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10837 value, *REMOTE_ERRNO to the remote error number or zero if none
10838 was included, and *ATTACHMENT to point to the start of the annex
10839 if any. The length of the packet isn't needed here; there may
10840 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10842 Return 0 if the packet could be parsed, -1 if it could not. If
10843 -1 is returned, the other variables may not be initialized. */
10846 remote_hostio_parse_result (char *buffer
, int *retcode
,
10847 int *remote_errno
, char **attachment
)
10852 *attachment
= NULL
;
10854 if (buffer
[0] != 'F')
10858 *retcode
= strtol (&buffer
[1], &p
, 16);
10859 if (errno
!= 0 || p
== &buffer
[1])
10862 /* Check for ",errno". */
10866 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10867 if (errno
!= 0 || p
+ 1 == p2
)
10872 /* Check for ";attachment". If there is no attachment, the
10873 packet should end here. */
10876 *attachment
= p
+ 1;
10879 else if (*p
== '\0')
10885 /* Send a prepared I/O packet to the target and read its response.
10886 The prepared packet is in the global RS->BUF before this function
10887 is called, and the answer is there when we return.
10889 COMMAND_BYTES is the length of the request to send, which may include
10890 binary data. WHICH_PACKET is the packet configuration to check
10891 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10892 is set to the error number and -1 is returned. Otherwise the value
10893 returned by the function is returned.
10895 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10896 attachment is expected; an error will be reported if there's a
10897 mismatch. If one is found, *ATTACHMENT will be set to point into
10898 the packet buffer and *ATTACHMENT_LEN will be set to the
10899 attachment's length. */
10902 remote_hostio_send_command (int command_bytes
, int which_packet
,
10903 int *remote_errno
, char **attachment
,
10904 int *attachment_len
)
10906 struct remote_state
*rs
= get_remote_state ();
10907 int ret
, bytes_read
;
10908 char *attachment_tmp
;
10910 if (!rs
->remote_desc
10911 || packet_support (which_packet
) == PACKET_DISABLE
)
10913 *remote_errno
= FILEIO_ENOSYS
;
10917 putpkt_binary (rs
->buf
, command_bytes
);
10918 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10920 /* If it timed out, something is wrong. Don't try to parse the
10922 if (bytes_read
< 0)
10924 *remote_errno
= FILEIO_EINVAL
;
10928 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10931 *remote_errno
= FILEIO_EINVAL
;
10933 case PACKET_UNKNOWN
:
10934 *remote_errno
= FILEIO_ENOSYS
;
10940 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10943 *remote_errno
= FILEIO_EINVAL
;
10947 /* Make sure we saw an attachment if and only if we expected one. */
10948 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10949 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10951 *remote_errno
= FILEIO_EINVAL
;
10955 /* If an attachment was found, it must point into the packet buffer;
10956 work out how many bytes there were. */
10957 if (attachment_tmp
!= NULL
)
10959 *attachment
= attachment_tmp
;
10960 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10966 /* Invalidate the readahead cache. */
10969 readahead_cache_invalidate (void)
10971 struct remote_state
*rs
= get_remote_state ();
10973 rs
->readahead_cache
.fd
= -1;
10976 /* Invalidate the readahead cache if it is holding data for FD. */
10979 readahead_cache_invalidate_fd (int fd
)
10981 struct remote_state
*rs
= get_remote_state ();
10983 if (rs
->readahead_cache
.fd
== fd
)
10984 rs
->readahead_cache
.fd
= -1;
10987 /* Set the filesystem remote_hostio functions that take FILENAME
10988 arguments will use. Return 0 on success, or -1 if an error
10989 occurs (and set *REMOTE_ERRNO). */
10992 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10994 struct remote_state
*rs
= get_remote_state ();
10995 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10997 int left
= get_remote_packet_size () - 1;
11001 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11004 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11007 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11009 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11010 remote_buffer_add_string (&p
, &left
, arg
);
11012 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11013 remote_errno
, NULL
, NULL
);
11015 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11019 rs
->fs_pid
= required_pid
;
11024 /* Implementation of to_fileio_open. */
11027 remote_hostio_open (struct target_ops
*self
,
11028 struct inferior
*inf
, const char *filename
,
11029 int flags
, int mode
, int warn_if_slow
,
11032 struct remote_state
*rs
= get_remote_state ();
11034 int left
= get_remote_packet_size () - 1;
11038 static int warning_issued
= 0;
11040 printf_unfiltered (_("Reading %s from remote target...\n"),
11043 if (!warning_issued
)
11045 warning (_("File transfers from remote targets can be slow."
11046 " Use \"set sysroot\" to access files locally"
11048 warning_issued
= 1;
11052 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11055 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11057 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11058 strlen (filename
));
11059 remote_buffer_add_string (&p
, &left
, ",");
11061 remote_buffer_add_int (&p
, &left
, flags
);
11062 remote_buffer_add_string (&p
, &left
, ",");
11064 remote_buffer_add_int (&p
, &left
, mode
);
11066 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11067 remote_errno
, NULL
, NULL
);
11070 /* Implementation of to_fileio_pwrite. */
11073 remote_hostio_pwrite (struct target_ops
*self
,
11074 int fd
, const gdb_byte
*write_buf
, int len
,
11075 ULONGEST offset
, int *remote_errno
)
11077 struct remote_state
*rs
= get_remote_state ();
11079 int left
= get_remote_packet_size ();
11082 readahead_cache_invalidate_fd (fd
);
11084 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11086 remote_buffer_add_int (&p
, &left
, fd
);
11087 remote_buffer_add_string (&p
, &left
, ",");
11089 remote_buffer_add_int (&p
, &left
, offset
);
11090 remote_buffer_add_string (&p
, &left
, ",");
11092 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11093 get_remote_packet_size () - (p
- rs
->buf
));
11095 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11096 remote_errno
, NULL
, NULL
);
11099 /* Helper for the implementation of to_fileio_pread. Read the file
11100 from the remote side with vFile:pread. */
11103 remote_hostio_pread_vFile (struct target_ops
*self
,
11104 int fd
, gdb_byte
*read_buf
, int len
,
11105 ULONGEST offset
, int *remote_errno
)
11107 struct remote_state
*rs
= get_remote_state ();
11110 int left
= get_remote_packet_size ();
11111 int ret
, attachment_len
;
11114 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11116 remote_buffer_add_int (&p
, &left
, fd
);
11117 remote_buffer_add_string (&p
, &left
, ",");
11119 remote_buffer_add_int (&p
, &left
, len
);
11120 remote_buffer_add_string (&p
, &left
, ",");
11122 remote_buffer_add_int (&p
, &left
, offset
);
11124 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11125 remote_errno
, &attachment
,
11131 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11133 if (read_len
!= ret
)
11134 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11139 /* Serve pread from the readahead cache. Returns number of bytes
11140 read, or 0 if the request can't be served from the cache. */
11143 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11144 int fd
, gdb_byte
*read_buf
, size_t len
,
11147 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11149 if (cache
->fd
== fd
11150 && cache
->offset
<= offset
11151 && offset
< cache
->offset
+ cache
->bufsize
)
11153 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11155 if (offset
+ len
> max
)
11156 len
= max
- offset
;
11158 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11165 /* Implementation of to_fileio_pread. */
11168 remote_hostio_pread (struct target_ops
*self
,
11169 int fd
, gdb_byte
*read_buf
, int len
,
11170 ULONGEST offset
, int *remote_errno
)
11173 struct remote_state
*rs
= get_remote_state ();
11174 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11176 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11179 cache
->hit_count
++;
11182 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11183 pulongest (cache
->hit_count
));
11187 cache
->miss_count
++;
11189 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11190 pulongest (cache
->miss_count
));
11193 cache
->offset
= offset
;
11194 cache
->bufsize
= get_remote_packet_size ();
11195 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11197 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11198 cache
->offset
, remote_errno
);
11201 readahead_cache_invalidate_fd (fd
);
11205 cache
->bufsize
= ret
;
11206 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11209 /* Implementation of to_fileio_close. */
11212 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11214 struct remote_state
*rs
= get_remote_state ();
11216 int left
= get_remote_packet_size () - 1;
11218 readahead_cache_invalidate_fd (fd
);
11220 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11222 remote_buffer_add_int (&p
, &left
, fd
);
11224 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11225 remote_errno
, NULL
, NULL
);
11228 /* Implementation of to_fileio_unlink. */
11231 remote_hostio_unlink (struct target_ops
*self
,
11232 struct inferior
*inf
, const char *filename
,
11235 struct remote_state
*rs
= get_remote_state ();
11237 int left
= get_remote_packet_size () - 1;
11239 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11242 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11244 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11245 strlen (filename
));
11247 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11248 remote_errno
, NULL
, NULL
);
11251 /* Implementation of to_fileio_readlink. */
11254 remote_hostio_readlink (struct target_ops
*self
,
11255 struct inferior
*inf
, const char *filename
,
11258 struct remote_state
*rs
= get_remote_state ();
11261 int left
= get_remote_packet_size ();
11262 int len
, attachment_len
;
11266 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11269 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11271 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11272 strlen (filename
));
11274 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11275 remote_errno
, &attachment
,
11281 ret
= (char *) xmalloc (len
+ 1);
11283 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11284 (gdb_byte
*) ret
, len
);
11285 if (read_len
!= len
)
11286 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11292 /* Implementation of to_fileio_fstat. */
11295 remote_hostio_fstat (struct target_ops
*self
,
11296 int fd
, struct stat
*st
,
11299 struct remote_state
*rs
= get_remote_state ();
11301 int left
= get_remote_packet_size ();
11302 int attachment_len
, ret
;
11304 struct fio_stat fst
;
11307 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11309 remote_buffer_add_int (&p
, &left
, fd
);
11311 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11312 remote_errno
, &attachment
,
11316 if (*remote_errno
!= FILEIO_ENOSYS
)
11319 /* Strictly we should return -1, ENOSYS here, but when
11320 "set sysroot remote:" was implemented in August 2008
11321 BFD's need for a stat function was sidestepped with
11322 this hack. This was not remedied until March 2015
11323 so we retain the previous behavior to avoid breaking
11326 Note that the memset is a March 2015 addition; older
11327 GDBs set st_size *and nothing else* so the structure
11328 would have garbage in all other fields. This might
11329 break something but retaining the previous behavior
11330 here would be just too wrong. */
11332 memset (st
, 0, sizeof (struct stat
));
11333 st
->st_size
= INT_MAX
;
11337 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11338 (gdb_byte
*) &fst
, sizeof (fst
));
11340 if (read_len
!= ret
)
11341 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11343 if (read_len
!= sizeof (fst
))
11344 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11345 read_len
, (int) sizeof (fst
));
11347 remote_fileio_to_host_stat (&fst
, st
);
11352 /* Implementation of to_filesystem_is_local. */
11355 remote_filesystem_is_local (struct target_ops
*self
)
11357 /* Valgrind GDB presents itself as a remote target but works
11358 on the local filesystem: it does not implement remote get
11359 and users are not expected to set a sysroot. To handle
11360 this case we treat the remote filesystem as local if the
11361 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11362 does not support vFile:open. */
11363 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11365 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11367 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11369 int fd
, remote_errno
;
11371 /* Try opening a file to probe support. The supplied
11372 filename is irrelevant, we only care about whether
11373 the stub recognizes the packet or not. */
11374 fd
= remote_hostio_open (self
, NULL
, "just probing",
11375 FILEIO_O_RDONLY
, 0700, 0,
11379 remote_hostio_close (self
, fd
, &remote_errno
);
11381 ps
= packet_support (PACKET_vFile_open
);
11384 if (ps
== PACKET_DISABLE
)
11386 static int warning_issued
= 0;
11388 if (!warning_issued
)
11390 warning (_("remote target does not support file"
11391 " transfer, attempting to access files"
11392 " from local filesystem."));
11393 warning_issued
= 1;
11404 remote_fileio_errno_to_host (int errnum
)
11410 case FILEIO_ENOENT
:
11418 case FILEIO_EACCES
:
11420 case FILEIO_EFAULT
:
11424 case FILEIO_EEXIST
:
11426 case FILEIO_ENODEV
:
11428 case FILEIO_ENOTDIR
:
11430 case FILEIO_EISDIR
:
11432 case FILEIO_EINVAL
:
11434 case FILEIO_ENFILE
:
11436 case FILEIO_EMFILE
:
11440 case FILEIO_ENOSPC
:
11442 case FILEIO_ESPIPE
:
11446 case FILEIO_ENOSYS
:
11448 case FILEIO_ENAMETOOLONG
:
11449 return ENAMETOOLONG
;
11455 remote_hostio_error (int errnum
)
11457 int host_error
= remote_fileio_errno_to_host (errnum
);
11459 if (host_error
== -1)
11460 error (_("Unknown remote I/O error %d"), errnum
);
11462 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11466 remote_hostio_close_cleanup (void *opaque
)
11468 int fd
= *(int *) opaque
;
11471 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11475 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11477 struct cleanup
*back_to
, *close_cleanup
;
11478 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11481 int bytes_in_buffer
;
11484 struct remote_state
*rs
= get_remote_state ();
11486 if (!rs
->remote_desc
)
11487 error (_("command can only be used with remote target"));
11489 file
= gdb_fopen_cloexec (local_file
, "rb");
11491 perror_with_name (local_file
);
11492 back_to
= make_cleanup_fclose (file
);
11494 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11495 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11497 0700, 0, &remote_errno
);
11499 remote_hostio_error (remote_errno
);
11501 /* Send up to this many bytes at once. They won't all fit in the
11502 remote packet limit, so we'll transfer slightly fewer. */
11503 io_size
= get_remote_packet_size ();
11504 buffer
= (gdb_byte
*) xmalloc (io_size
);
11505 make_cleanup (xfree
, buffer
);
11507 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11509 bytes_in_buffer
= 0;
11512 while (bytes_in_buffer
|| !saw_eof
)
11516 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11517 io_size
- bytes_in_buffer
,
11522 error (_("Error reading %s."), local_file
);
11525 /* EOF. Unless there is something still in the
11526 buffer from the last iteration, we are done. */
11528 if (bytes_in_buffer
== 0)
11536 bytes
+= bytes_in_buffer
;
11537 bytes_in_buffer
= 0;
11539 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11541 offset
, &remote_errno
);
11544 remote_hostio_error (remote_errno
);
11545 else if (retcode
== 0)
11546 error (_("Remote write of %d bytes returned 0!"), bytes
);
11547 else if (retcode
< bytes
)
11549 /* Short write. Save the rest of the read data for the next
11551 bytes_in_buffer
= bytes
- retcode
;
11552 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11558 discard_cleanups (close_cleanup
);
11559 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11560 remote_hostio_error (remote_errno
);
11563 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11564 do_cleanups (back_to
);
11568 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11570 struct cleanup
*back_to
, *close_cleanup
;
11571 int fd
, remote_errno
, bytes
, io_size
;
11575 struct remote_state
*rs
= get_remote_state ();
11577 if (!rs
->remote_desc
)
11578 error (_("command can only be used with remote target"));
11580 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11581 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11584 remote_hostio_error (remote_errno
);
11586 file
= gdb_fopen_cloexec (local_file
, "wb");
11588 perror_with_name (local_file
);
11589 back_to
= make_cleanup_fclose (file
);
11591 /* Send up to this many bytes at once. They won't all fit in the
11592 remote packet limit, so we'll transfer slightly fewer. */
11593 io_size
= get_remote_packet_size ();
11594 buffer
= (gdb_byte
*) xmalloc (io_size
);
11595 make_cleanup (xfree
, buffer
);
11597 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11602 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11603 fd
, buffer
, io_size
, offset
, &remote_errno
);
11605 /* Success, but no bytes, means end-of-file. */
11608 remote_hostio_error (remote_errno
);
11612 bytes
= fwrite (buffer
, 1, bytes
, file
);
11614 perror_with_name (local_file
);
11617 discard_cleanups (close_cleanup
);
11618 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11619 remote_hostio_error (remote_errno
);
11622 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11623 do_cleanups (back_to
);
11627 remote_file_delete (const char *remote_file
, int from_tty
)
11629 int retcode
, remote_errno
;
11630 struct remote_state
*rs
= get_remote_state ();
11632 if (!rs
->remote_desc
)
11633 error (_("command can only be used with remote target"));
11635 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11636 NULL
, remote_file
, &remote_errno
);
11638 remote_hostio_error (remote_errno
);
11641 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11645 remote_put_command (char *args
, int from_tty
)
11647 struct cleanup
*back_to
;
11651 error_no_arg (_("file to put"));
11653 argv
= gdb_buildargv (args
);
11654 back_to
= make_cleanup_freeargv (argv
);
11655 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11656 error (_("Invalid parameters to remote put"));
11658 remote_file_put (argv
[0], argv
[1], from_tty
);
11660 do_cleanups (back_to
);
11664 remote_get_command (char *args
, int from_tty
)
11666 struct cleanup
*back_to
;
11670 error_no_arg (_("file to get"));
11672 argv
= gdb_buildargv (args
);
11673 back_to
= make_cleanup_freeargv (argv
);
11674 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11675 error (_("Invalid parameters to remote get"));
11677 remote_file_get (argv
[0], argv
[1], from_tty
);
11679 do_cleanups (back_to
);
11683 remote_delete_command (char *args
, int from_tty
)
11685 struct cleanup
*back_to
;
11689 error_no_arg (_("file to delete"));
11691 argv
= gdb_buildargv (args
);
11692 back_to
= make_cleanup_freeargv (argv
);
11693 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11694 error (_("Invalid parameters to remote delete"));
11696 remote_file_delete (argv
[0], from_tty
);
11698 do_cleanups (back_to
);
11702 remote_command (char *args
, int from_tty
)
11704 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11708 remote_can_execute_reverse (struct target_ops
*self
)
11710 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11711 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11718 remote_supports_non_stop (struct target_ops
*self
)
11724 remote_supports_disable_randomization (struct target_ops
*self
)
11726 /* Only supported in extended mode. */
11731 remote_supports_multi_process (struct target_ops
*self
)
11733 struct remote_state
*rs
= get_remote_state ();
11735 return remote_multi_process_p (rs
);
11739 remote_supports_cond_tracepoints (void)
11741 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11745 remote_supports_cond_breakpoints (struct target_ops
*self
)
11747 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11751 remote_supports_fast_tracepoints (void)
11753 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11757 remote_supports_static_tracepoints (void)
11759 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11763 remote_supports_install_in_trace (void)
11765 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11769 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11771 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11776 remote_supports_string_tracing (struct target_ops
*self
)
11778 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11782 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11784 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11788 remote_trace_init (struct target_ops
*self
)
11791 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11792 if (strcmp (target_buf
, "OK") != 0)
11793 error (_("Target does not support this command."));
11796 static void free_actions_list (char **actions_list
);
11797 static void free_actions_list_cleanup_wrapper (void *);
11799 free_actions_list_cleanup_wrapper (void *al
)
11801 free_actions_list ((char **) al
);
11805 free_actions_list (char **actions_list
)
11809 if (actions_list
== 0)
11812 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11813 xfree (actions_list
[ndx
]);
11815 xfree (actions_list
);
11818 /* Recursive routine to walk through command list including loops, and
11819 download packets for each command. */
11822 remote_download_command_source (int num
, ULONGEST addr
,
11823 struct command_line
*cmds
)
11825 struct remote_state
*rs
= get_remote_state ();
11826 struct command_line
*cmd
;
11828 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11830 QUIT
; /* Allow user to bail out with ^C. */
11831 strcpy (rs
->buf
, "QTDPsrc:");
11832 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11833 rs
->buf
+ strlen (rs
->buf
),
11834 rs
->buf_size
- strlen (rs
->buf
));
11836 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11837 if (strcmp (target_buf
, "OK"))
11838 warning (_("Target does not support source download."));
11840 if (cmd
->control_type
== while_control
11841 || cmd
->control_type
== while_stepping_control
)
11843 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11845 QUIT
; /* Allow user to bail out with ^C. */
11846 strcpy (rs
->buf
, "QTDPsrc:");
11847 encode_source_string (num
, addr
, "cmd", "end",
11848 rs
->buf
+ strlen (rs
->buf
),
11849 rs
->buf_size
- strlen (rs
->buf
));
11851 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11852 if (strcmp (target_buf
, "OK"))
11853 warning (_("Target does not support source download."));
11859 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11861 #define BUF_SIZE 2048
11865 char buf
[BUF_SIZE
];
11866 char **tdp_actions
;
11867 char **stepping_actions
;
11869 struct cleanup
*old_chain
= NULL
;
11870 struct agent_expr
*aexpr
;
11871 struct cleanup
*aexpr_chain
= NULL
;
11873 struct breakpoint
*b
= loc
->owner
;
11874 struct tracepoint
*t
= (struct tracepoint
*) b
;
11876 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11877 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11879 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11882 tpaddr
= loc
->address
;
11883 sprintf_vma (addrbuf
, tpaddr
);
11884 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11885 addrbuf
, /* address */
11886 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11887 t
->step_count
, t
->pass_count
);
11888 /* Fast tracepoints are mostly handled by the target, but we can
11889 tell the target how big of an instruction block should be moved
11891 if (b
->type
== bp_fast_tracepoint
)
11893 /* Only test for support at download time; we may not know
11894 target capabilities at definition time. */
11895 if (remote_supports_fast_tracepoints ())
11897 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11899 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11900 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11902 /* If it passed validation at definition but fails now,
11903 something is very wrong. */
11904 internal_error (__FILE__
, __LINE__
,
11905 _("Fast tracepoint not "
11906 "valid during download"));
11909 /* Fast tracepoints are functionally identical to regular
11910 tracepoints, so don't take lack of support as a reason to
11911 give up on the trace run. */
11912 warning (_("Target does not support fast tracepoints, "
11913 "downloading %d as regular tracepoint"), b
->number
);
11915 else if (b
->type
== bp_static_tracepoint
)
11917 /* Only test for support at download time; we may not know
11918 target capabilities at definition time. */
11919 if (remote_supports_static_tracepoints ())
11921 struct static_tracepoint_marker marker
;
11923 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11924 strcat (buf
, ":S");
11926 error (_("Static tracepoint not valid during download"));
11929 /* Fast tracepoints are functionally identical to regular
11930 tracepoints, so don't take lack of support as a reason
11931 to give up on the trace run. */
11932 error (_("Target does not support static tracepoints"));
11934 /* If the tracepoint has a conditional, make it into an agent
11935 expression and append to the definition. */
11938 /* Only test support at download time, we may not know target
11939 capabilities at definition time. */
11940 if (remote_supports_cond_tracepoints ())
11942 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11943 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11944 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11946 pkt
= buf
+ strlen (buf
);
11947 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11948 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11950 do_cleanups (aexpr_chain
);
11953 warning (_("Target does not support conditional tracepoints, "
11954 "ignoring tp %d cond"), b
->number
);
11957 if (b
->commands
|| *default_collect
)
11960 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11961 if (strcmp (target_buf
, "OK"))
11962 error (_("Target does not support tracepoints."));
11964 /* do_single_steps (t); */
11967 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11969 QUIT
; /* Allow user to bail out with ^C. */
11970 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11971 b
->number
, addrbuf
, /* address */
11973 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11976 remote_get_noisy_reply (&target_buf
,
11978 if (strcmp (target_buf
, "OK"))
11979 error (_("Error on target while setting tracepoints."));
11982 if (stepping_actions
)
11984 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11986 QUIT
; /* Allow user to bail out with ^C. */
11987 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11988 b
->number
, addrbuf
, /* address */
11989 ((ndx
== 0) ? "S" : ""),
11990 stepping_actions
[ndx
],
11991 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11993 remote_get_noisy_reply (&target_buf
,
11995 if (strcmp (target_buf
, "OK"))
11996 error (_("Error on target while setting tracepoints."));
12000 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
12002 if (b
->location
!= NULL
)
12004 strcpy (buf
, "QTDPsrc:");
12005 encode_source_string (b
->number
, loc
->address
, "at",
12006 event_location_to_string (b
->location
),
12007 buf
+ strlen (buf
), 2048 - strlen (buf
));
12009 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12010 if (strcmp (target_buf
, "OK"))
12011 warning (_("Target does not support source download."));
12013 if (b
->cond_string
)
12015 strcpy (buf
, "QTDPsrc:");
12016 encode_source_string (b
->number
, loc
->address
,
12017 "cond", b
->cond_string
, buf
+ strlen (buf
),
12018 2048 - strlen (buf
));
12020 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12021 if (strcmp (target_buf
, "OK"))
12022 warning (_("Target does not support source download."));
12024 remote_download_command_source (b
->number
, loc
->address
,
12025 breakpoint_commands (b
));
12028 do_cleanups (old_chain
);
12032 remote_can_download_tracepoint (struct target_ops
*self
)
12034 struct remote_state
*rs
= get_remote_state ();
12035 struct trace_status
*ts
;
12038 /* Don't try to install tracepoints until we've relocated our
12039 symbols, and fetched and merged the target's tracepoint list with
12041 if (rs
->starting_up
)
12044 ts
= current_trace_status ();
12045 status
= remote_get_trace_status (self
, ts
);
12047 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12050 /* If we are in a tracing experiment, but remote stub doesn't support
12051 installing tracepoint in trace, we have to return. */
12052 if (!remote_supports_install_in_trace ())
12060 remote_download_trace_state_variable (struct target_ops
*self
,
12061 struct trace_state_variable
*tsv
)
12063 struct remote_state
*rs
= get_remote_state ();
12066 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12067 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12069 p
= rs
->buf
+ strlen (rs
->buf
);
12070 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12071 error (_("Trace state variable name too long for tsv definition packet"));
12072 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12075 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12076 if (*target_buf
== '\0')
12077 error (_("Target does not support this command."));
12078 if (strcmp (target_buf
, "OK") != 0)
12079 error (_("Error on target while downloading trace state variable."));
12083 remote_enable_tracepoint (struct target_ops
*self
,
12084 struct bp_location
*location
)
12086 struct remote_state
*rs
= get_remote_state ();
12089 sprintf_vma (addr_buf
, location
->address
);
12090 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12091 location
->owner
->number
, addr_buf
);
12093 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12094 if (*rs
->buf
== '\0')
12095 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12096 if (strcmp (rs
->buf
, "OK") != 0)
12097 error (_("Error on target while enabling tracepoint."));
12101 remote_disable_tracepoint (struct target_ops
*self
,
12102 struct bp_location
*location
)
12104 struct remote_state
*rs
= get_remote_state ();
12107 sprintf_vma (addr_buf
, location
->address
);
12108 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12109 location
->owner
->number
, addr_buf
);
12111 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12112 if (*rs
->buf
== '\0')
12113 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12114 if (strcmp (rs
->buf
, "OK") != 0)
12115 error (_("Error on target while disabling tracepoint."));
12119 remote_trace_set_readonly_regions (struct target_ops
*self
)
12123 bfd_size_type size
;
12129 return; /* No information to give. */
12131 strcpy (target_buf
, "QTro");
12132 offset
= strlen (target_buf
);
12133 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12135 char tmp1
[40], tmp2
[40];
12138 if ((s
->flags
& SEC_LOAD
) == 0 ||
12139 /* (s->flags & SEC_CODE) == 0 || */
12140 (s
->flags
& SEC_READONLY
) == 0)
12144 vma
= bfd_get_section_vma (abfd
, s
);
12145 size
= bfd_get_section_size (s
);
12146 sprintf_vma (tmp1
, vma
);
12147 sprintf_vma (tmp2
, vma
+ size
);
12148 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12149 if (offset
+ sec_length
+ 1 > target_buf_size
)
12151 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12153 Too many sections for read-only sections definition packet."));
12156 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12158 offset
+= sec_length
;
12162 putpkt (target_buf
);
12163 getpkt (&target_buf
, &target_buf_size
, 0);
12168 remote_trace_start (struct target_ops
*self
)
12170 putpkt ("QTStart");
12171 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12172 if (*target_buf
== '\0')
12173 error (_("Target does not support this command."));
12174 if (strcmp (target_buf
, "OK") != 0)
12175 error (_("Bogus reply from target: %s"), target_buf
);
12179 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12181 /* Initialize it just to avoid a GCC false warning. */
12183 /* FIXME we need to get register block size some other way. */
12184 extern int trace_regblock_size
;
12185 enum packet_result result
;
12187 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12190 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12192 putpkt ("qTStatus");
12196 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12198 CATCH (ex
, RETURN_MASK_ERROR
)
12200 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12202 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12205 throw_exception (ex
);
12209 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12211 /* If the remote target doesn't do tracing, flag it. */
12212 if (result
== PACKET_UNKNOWN
)
12215 /* We're working with a live target. */
12216 ts
->filename
= NULL
;
12219 error (_("Bogus trace status reply from target: %s"), target_buf
);
12221 /* Function 'parse_trace_status' sets default value of each field of
12222 'ts' at first, so we don't have to do it here. */
12223 parse_trace_status (p
, ts
);
12225 return ts
->running
;
12229 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12230 struct uploaded_tp
*utp
)
12232 struct remote_state
*rs
= get_remote_state ();
12234 struct bp_location
*loc
;
12235 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12236 size_t size
= get_remote_packet_size ();
12240 tp
->base
.hit_count
= 0;
12241 tp
->traceframe_usage
= 0;
12242 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12244 /* If the tracepoint was never downloaded, don't go asking for
12246 if (tp
->number_on_target
== 0)
12248 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12249 phex_nz (loc
->address
, 0));
12251 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12252 if (reply
&& *reply
)
12255 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12261 utp
->hit_count
= 0;
12262 utp
->traceframe_usage
= 0;
12263 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12264 phex_nz (utp
->addr
, 0));
12266 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12267 if (reply
&& *reply
)
12270 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12276 remote_trace_stop (struct target_ops
*self
)
12279 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12280 if (*target_buf
== '\0')
12281 error (_("Target does not support this command."));
12282 if (strcmp (target_buf
, "OK") != 0)
12283 error (_("Bogus reply from target: %s"), target_buf
);
12287 remote_trace_find (struct target_ops
*self
,
12288 enum trace_find_type type
, int num
,
12289 CORE_ADDR addr1
, CORE_ADDR addr2
,
12292 struct remote_state
*rs
= get_remote_state ();
12293 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12295 int target_frameno
= -1, target_tracept
= -1;
12297 /* Lookups other than by absolute frame number depend on the current
12298 trace selected, so make sure it is correct on the remote end
12300 if (type
!= tfind_number
)
12301 set_remote_traceframe ();
12304 strcpy (p
, "QTFrame:");
12305 p
= strchr (p
, '\0');
12309 xsnprintf (p
, endbuf
- p
, "%x", num
);
12312 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12315 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12318 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12319 phex_nz (addr2
, 0));
12321 case tfind_outside
:
12322 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12323 phex_nz (addr2
, 0));
12326 error (_("Unknown trace find type %d"), type
);
12330 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12331 if (*reply
== '\0')
12332 error (_("Target does not support this command."));
12334 while (reply
&& *reply
)
12339 target_frameno
= (int) strtol (p
, &reply
, 16);
12341 error (_("Unable to parse trace frame number"));
12342 /* Don't update our remote traceframe number cache on failure
12343 to select a remote traceframe. */
12344 if (target_frameno
== -1)
12349 target_tracept
= (int) strtol (p
, &reply
, 16);
12351 error (_("Unable to parse tracepoint number"));
12353 case 'O': /* "OK"? */
12354 if (reply
[1] == 'K' && reply
[2] == '\0')
12357 error (_("Bogus reply from target: %s"), reply
);
12360 error (_("Bogus reply from target: %s"), reply
);
12363 *tpp
= target_tracept
;
12365 rs
->remote_traceframe_number
= target_frameno
;
12366 return target_frameno
;
12370 remote_get_trace_state_variable_value (struct target_ops
*self
,
12371 int tsvnum
, LONGEST
*val
)
12373 struct remote_state
*rs
= get_remote_state ();
12377 set_remote_traceframe ();
12379 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12381 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12382 if (reply
&& *reply
)
12386 unpack_varlen_hex (reply
+ 1, &uval
);
12387 *val
= (LONGEST
) uval
;
12395 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12397 struct remote_state
*rs
= get_remote_state ();
12401 strcpy (p
, "QTSave:");
12403 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12404 error (_("Remote file name too long for trace save packet"));
12405 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12408 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12409 if (*reply
== '\0')
12410 error (_("Target does not support this command."));
12411 if (strcmp (reply
, "OK") != 0)
12412 error (_("Bogus reply from target: %s"), reply
);
12416 /* This is basically a memory transfer, but needs to be its own packet
12417 because we don't know how the target actually organizes its trace
12418 memory, plus we want to be able to ask for as much as possible, but
12419 not be unhappy if we don't get as much as we ask for. */
12422 remote_get_raw_trace_data (struct target_ops
*self
,
12423 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12425 struct remote_state
*rs
= get_remote_state ();
12431 strcpy (p
, "qTBuffer:");
12433 p
+= hexnumstr (p
, offset
);
12435 p
+= hexnumstr (p
, len
);
12439 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12440 if (reply
&& *reply
)
12442 /* 'l' by itself means we're at the end of the buffer and
12443 there is nothing more to get. */
12447 /* Convert the reply into binary. Limit the number of bytes to
12448 convert according to our passed-in buffer size, rather than
12449 what was returned in the packet; if the target is
12450 unexpectedly generous and gives us a bigger reply than we
12451 asked for, we don't want to crash. */
12452 rslt
= hex2bin (target_buf
, buf
, len
);
12456 /* Something went wrong, flag as an error. */
12461 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12463 struct remote_state
*rs
= get_remote_state ();
12465 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12469 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12471 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12472 if (*reply
== '\0')
12473 error (_("Target does not support this command."));
12474 if (strcmp (reply
, "OK") != 0)
12475 error (_("Bogus reply from target: %s"), reply
);
12478 warning (_("Target does not support disconnected tracing."));
12482 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12484 struct thread_info
*info
= find_thread_ptid (ptid
);
12486 if (info
&& info
->priv
)
12487 return info
->priv
->core
;
12492 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12494 struct remote_state
*rs
= get_remote_state ();
12497 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12499 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12500 if (*reply
== '\0')
12501 error (_("Target does not support this command."));
12502 if (strcmp (reply
, "OK") != 0)
12503 error (_("Bogus reply from target: %s"), reply
);
12506 static struct traceframe_info
*
12507 remote_traceframe_info (struct target_ops
*self
)
12511 text
= target_read_stralloc (¤t_target
,
12512 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12515 struct traceframe_info
*info
;
12516 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12518 info
= parse_traceframe_info (text
);
12519 do_cleanups (back_to
);
12526 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12527 instruction on which a fast tracepoint may be placed. Returns -1
12528 if the packet is not supported, and 0 if the minimum instruction
12529 length is unknown. */
12532 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12534 struct remote_state
*rs
= get_remote_state ();
12537 /* If we're not debugging a process yet, the IPA can't be
12539 if (!target_has_execution
)
12542 /* Make sure the remote is pointing at the right process. */
12543 set_general_process ();
12545 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12547 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12548 if (*reply
== '\0')
12552 ULONGEST min_insn_len
;
12554 unpack_varlen_hex (reply
, &min_insn_len
);
12556 return (int) min_insn_len
;
12561 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12563 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12565 struct remote_state
*rs
= get_remote_state ();
12566 char *buf
= rs
->buf
;
12567 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12568 enum packet_result result
;
12570 gdb_assert (val
>= 0 || val
== -1);
12571 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12572 /* Send -1 as literal "-1" to avoid host size dependency. */
12576 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12579 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12582 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12583 result
= packet_ok (rs
->buf
,
12584 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12586 if (result
!= PACKET_OK
)
12587 warning (_("Bogus reply from target: %s"), rs
->buf
);
12592 remote_set_trace_notes (struct target_ops
*self
,
12593 const char *user
, const char *notes
,
12594 const char *stop_notes
)
12596 struct remote_state
*rs
= get_remote_state ();
12598 char *buf
= rs
->buf
;
12599 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12602 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12605 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12606 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12612 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12613 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12619 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12620 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12624 /* Ensure the buffer is terminated. */
12628 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12629 if (*reply
== '\0')
12632 if (strcmp (reply
, "OK") != 0)
12633 error (_("Bogus reply from target: %s"), reply
);
12639 remote_use_agent (struct target_ops
*self
, int use
)
12641 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12643 struct remote_state
*rs
= get_remote_state ();
12645 /* If the stub supports QAgent. */
12646 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12648 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12650 if (strcmp (rs
->buf
, "OK") == 0)
12661 remote_can_use_agent (struct target_ops
*self
)
12663 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12666 struct btrace_target_info
12668 /* The ptid of the traced thread. */
12671 /* The obtained branch trace configuration. */
12672 struct btrace_config conf
;
12675 /* Reset our idea of our target's btrace configuration. */
12678 remote_btrace_reset (void)
12680 struct remote_state
*rs
= get_remote_state ();
12682 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12685 /* Check whether the target supports branch tracing. */
12688 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12690 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12692 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12697 case BTRACE_FORMAT_NONE
:
12700 case BTRACE_FORMAT_BTS
:
12701 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12703 case BTRACE_FORMAT_PT
:
12704 /* The trace is decoded on the host. Even if our target supports it,
12705 we still need to have libipt to decode the trace. */
12706 #if defined (HAVE_LIBIPT)
12707 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12708 #else /* !defined (HAVE_LIBIPT) */
12710 #endif /* !defined (HAVE_LIBIPT) */
12713 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12716 /* Synchronize the configuration with the target. */
12719 btrace_sync_conf (const struct btrace_config
*conf
)
12721 struct packet_config
*packet
;
12722 struct remote_state
*rs
;
12723 char *buf
, *pos
, *endbuf
;
12725 rs
= get_remote_state ();
12727 endbuf
= buf
+ get_remote_packet_size ();
12729 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12730 if (packet_config_support (packet
) == PACKET_ENABLE
12731 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12734 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12738 getpkt (&buf
, &rs
->buf_size
, 0);
12740 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12742 if (buf
[0] == 'E' && buf
[1] == '.')
12743 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12745 error (_("Failed to configure the BTS buffer size."));
12748 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12751 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12752 if (packet_config_support (packet
) == PACKET_ENABLE
12753 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12756 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12760 getpkt (&buf
, &rs
->buf_size
, 0);
12762 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12764 if (buf
[0] == 'E' && buf
[1] == '.')
12765 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12767 error (_("Failed to configure the trace buffer size."));
12770 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12774 /* Read the current thread's btrace configuration from the target and
12775 store it into CONF. */
12778 btrace_read_config (struct btrace_config
*conf
)
12782 xml
= target_read_stralloc (¤t_target
,
12783 TARGET_OBJECT_BTRACE_CONF
, "");
12786 struct cleanup
*cleanup
;
12788 cleanup
= make_cleanup (xfree
, xml
);
12789 parse_xml_btrace_conf (conf
, xml
);
12790 do_cleanups (cleanup
);
12794 /* Enable branch tracing. */
12796 static struct btrace_target_info
*
12797 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12798 const struct btrace_config
*conf
)
12800 struct btrace_target_info
*tinfo
= NULL
;
12801 struct packet_config
*packet
= NULL
;
12802 struct remote_state
*rs
= get_remote_state ();
12803 char *buf
= rs
->buf
;
12804 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12806 switch (conf
->format
)
12808 case BTRACE_FORMAT_BTS
:
12809 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12812 case BTRACE_FORMAT_PT
:
12813 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12817 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12818 error (_("Target does not support branch tracing."));
12820 btrace_sync_conf (conf
);
12822 set_general_thread (ptid
);
12824 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12828 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12830 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12831 error (_("Could not enable branch tracing for %s: %s"),
12832 target_pid_to_str (ptid
), rs
->buf
+ 2);
12834 error (_("Could not enable branch tracing for %s."),
12835 target_pid_to_str (ptid
));
12838 tinfo
= XCNEW (struct btrace_target_info
);
12839 tinfo
->ptid
= ptid
;
12841 /* If we fail to read the configuration, we lose some information, but the
12842 tracing itself is not impacted. */
12845 btrace_read_config (&tinfo
->conf
);
12847 CATCH (err
, RETURN_MASK_ERROR
)
12849 if (err
.message
!= NULL
)
12850 warning ("%s", err
.message
);
12857 /* Disable branch tracing. */
12860 remote_disable_btrace (struct target_ops
*self
,
12861 struct btrace_target_info
*tinfo
)
12863 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12864 struct remote_state
*rs
= get_remote_state ();
12865 char *buf
= rs
->buf
;
12866 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12868 if (packet_config_support (packet
) != PACKET_ENABLE
)
12869 error (_("Target does not support branch tracing."));
12871 set_general_thread (tinfo
->ptid
);
12873 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12875 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12877 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12879 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12880 error (_("Could not disable branch tracing for %s: %s"),
12881 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12883 error (_("Could not disable branch tracing for %s."),
12884 target_pid_to_str (tinfo
->ptid
));
12890 /* Teardown branch tracing. */
12893 remote_teardown_btrace (struct target_ops
*self
,
12894 struct btrace_target_info
*tinfo
)
12896 /* We must not talk to the target during teardown. */
12900 /* Read the branch trace. */
12902 static enum btrace_error
12903 remote_read_btrace (struct target_ops
*self
,
12904 struct btrace_data
*btrace
,
12905 struct btrace_target_info
*tinfo
,
12906 enum btrace_read_type type
)
12908 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12909 struct cleanup
*cleanup
;
12913 if (packet_config_support (packet
) != PACKET_ENABLE
)
12914 error (_("Target does not support branch tracing."));
12916 #if !defined(HAVE_LIBEXPAT)
12917 error (_("Cannot process branch tracing result. XML parsing not supported."));
12922 case BTRACE_READ_ALL
:
12925 case BTRACE_READ_NEW
:
12928 case BTRACE_READ_DELTA
:
12932 internal_error (__FILE__
, __LINE__
,
12933 _("Bad branch tracing read type: %u."),
12934 (unsigned int) type
);
12937 xml
= target_read_stralloc (¤t_target
,
12938 TARGET_OBJECT_BTRACE
, annex
);
12940 return BTRACE_ERR_UNKNOWN
;
12942 cleanup
= make_cleanup (xfree
, xml
);
12943 parse_xml_btrace (btrace
, xml
);
12944 do_cleanups (cleanup
);
12946 return BTRACE_ERR_NONE
;
12949 static const struct btrace_config
*
12950 remote_btrace_conf (struct target_ops
*self
,
12951 const struct btrace_target_info
*tinfo
)
12953 return &tinfo
->conf
;
12957 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12959 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12963 /* Implementation of to_load. */
12966 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12968 generic_load (name
, from_tty
);
12971 /* Accepts an integer PID; returns a string representing a file that
12972 can be opened on the remote side to get the symbols for the child
12973 process. Returns NULL if the operation is not supported. */
12976 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12978 static char *filename
= NULL
;
12979 struct inferior
*inf
;
12980 char *annex
= NULL
;
12982 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12985 if (filename
!= NULL
)
12988 inf
= find_inferior_pid (pid
);
12990 internal_error (__FILE__
, __LINE__
,
12991 _("not currently attached to process %d"), pid
);
12993 if (!inf
->fake_pid_p
)
12995 const int annex_size
= 9;
12997 annex
= (char *) alloca (annex_size
);
12998 xsnprintf (annex
, annex_size
, "%x", pid
);
13001 filename
= target_read_stralloc (¤t_target
,
13002 TARGET_OBJECT_EXEC_FILE
, annex
);
13007 /* Implement the to_can_do_single_step target_ops method. */
13010 remote_can_do_single_step (struct target_ops
*ops
)
13012 /* We can only tell whether target supports single step or not by
13013 supported s and S vCont actions if the stub supports vContSupported
13014 feature. If the stub doesn't support vContSupported feature,
13015 we have conservatively to think target doesn't supports single
13017 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13019 struct remote_state
*rs
= get_remote_state ();
13021 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13022 remote_vcont_probe (rs
);
13024 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13031 init_remote_ops (void)
13033 remote_ops
.to_shortname
= "remote";
13034 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13035 remote_ops
.to_doc
=
13036 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13037 Specify the serial device it is connected to\n\
13038 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13039 remote_ops
.to_open
= remote_open
;
13040 remote_ops
.to_close
= remote_close
;
13041 remote_ops
.to_detach
= remote_detach
;
13042 remote_ops
.to_disconnect
= remote_disconnect
;
13043 remote_ops
.to_resume
= remote_resume
;
13044 remote_ops
.to_wait
= remote_wait
;
13045 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13046 remote_ops
.to_store_registers
= remote_store_registers
;
13047 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13048 remote_ops
.to_files_info
= remote_files_info
;
13049 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13050 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13051 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13052 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13053 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13054 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13055 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13056 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13057 remote_ops
.to_watchpoint_addr_within_range
=
13058 remote_watchpoint_addr_within_range
;
13059 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13060 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13061 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13062 remote_ops
.to_region_ok_for_hw_watchpoint
13063 = remote_region_ok_for_hw_watchpoint
;
13064 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13065 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13066 remote_ops
.to_kill
= remote_kill
;
13067 remote_ops
.to_load
= remote_load
;
13068 remote_ops
.to_mourn_inferior
= remote_mourn
;
13069 remote_ops
.to_pass_signals
= remote_pass_signals
;
13070 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13071 remote_ops
.to_program_signals
= remote_program_signals
;
13072 remote_ops
.to_thread_alive
= remote_thread_alive
;
13073 remote_ops
.to_thread_name
= remote_thread_name
;
13074 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13075 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13076 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13077 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13078 remote_ops
.to_stop
= remote_stop
;
13079 remote_ops
.to_interrupt
= remote_interrupt
;
13080 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13081 remote_ops
.to_check_pending_interrupt
= remote_check_pending_interrupt
;
13082 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13083 remote_ops
.to_rcmd
= remote_rcmd
;
13084 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13085 remote_ops
.to_log_command
= serial_log_command
;
13086 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13087 remote_ops
.to_stratum
= process_stratum
;
13088 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13089 remote_ops
.to_has_memory
= default_child_has_memory
;
13090 remote_ops
.to_has_stack
= default_child_has_stack
;
13091 remote_ops
.to_has_registers
= default_child_has_registers
;
13092 remote_ops
.to_has_execution
= default_child_has_execution
;
13093 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13094 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13095 remote_ops
.to_magic
= OPS_MAGIC
;
13096 remote_ops
.to_memory_map
= remote_memory_map
;
13097 remote_ops
.to_flash_erase
= remote_flash_erase
;
13098 remote_ops
.to_flash_done
= remote_flash_done
;
13099 remote_ops
.to_read_description
= remote_read_description
;
13100 remote_ops
.to_search_memory
= remote_search_memory
;
13101 remote_ops
.to_can_async_p
= remote_can_async_p
;
13102 remote_ops
.to_is_async_p
= remote_is_async_p
;
13103 remote_ops
.to_async
= remote_async
;
13104 remote_ops
.to_thread_events
= remote_thread_events
;
13105 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13106 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13107 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13108 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13109 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13110 remote_ops
.to_supports_disable_randomization
13111 = remote_supports_disable_randomization
;
13112 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13113 remote_ops
.to_fileio_open
= remote_hostio_open
;
13114 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13115 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13116 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13117 remote_ops
.to_fileio_close
= remote_hostio_close
;
13118 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13119 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13120 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13121 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13122 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13123 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13124 remote_ops
.to_trace_init
= remote_trace_init
;
13125 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13126 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13127 remote_ops
.to_download_trace_state_variable
13128 = remote_download_trace_state_variable
;
13129 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13130 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13131 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13132 remote_ops
.to_trace_start
= remote_trace_start
;
13133 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13134 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13135 remote_ops
.to_trace_stop
= remote_trace_stop
;
13136 remote_ops
.to_trace_find
= remote_trace_find
;
13137 remote_ops
.to_get_trace_state_variable_value
13138 = remote_get_trace_state_variable_value
;
13139 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13140 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13141 remote_ops
.to_upload_trace_state_variables
13142 = remote_upload_trace_state_variables
;
13143 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13144 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13145 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13146 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13147 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13148 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13149 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13150 remote_ops
.to_verify_memory
= remote_verify_memory
;
13151 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13152 remote_ops
.to_set_permissions
= remote_set_permissions
;
13153 remote_ops
.to_static_tracepoint_marker_at
13154 = remote_static_tracepoint_marker_at
;
13155 remote_ops
.to_static_tracepoint_markers_by_strid
13156 = remote_static_tracepoint_markers_by_strid
;
13157 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13158 remote_ops
.to_use_agent
= remote_use_agent
;
13159 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13160 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13161 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13162 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13163 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13164 remote_ops
.to_read_btrace
= remote_read_btrace
;
13165 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13166 remote_ops
.to_augmented_libraries_svr4_read
=
13167 remote_augmented_libraries_svr4_read
;
13168 remote_ops
.to_follow_fork
= remote_follow_fork
;
13169 remote_ops
.to_follow_exec
= remote_follow_exec
;
13170 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13171 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13172 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13173 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13174 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13175 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13178 /* Set up the extended remote vector by making a copy of the standard
13179 remote vector and adding to it. */
13182 init_extended_remote_ops (void)
13184 extended_remote_ops
= remote_ops
;
13186 extended_remote_ops
.to_shortname
= "extended-remote";
13187 extended_remote_ops
.to_longname
=
13188 "Extended remote serial target in gdb-specific protocol";
13189 extended_remote_ops
.to_doc
=
13190 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13191 Specify the serial device it is connected to (e.g. /dev/ttya).";
13192 extended_remote_ops
.to_open
= extended_remote_open
;
13193 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13194 extended_remote_ops
.to_detach
= extended_remote_detach
;
13195 extended_remote_ops
.to_attach
= extended_remote_attach
;
13196 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13197 extended_remote_ops
.to_supports_disable_randomization
13198 = extended_remote_supports_disable_randomization
;
13202 remote_can_async_p (struct target_ops
*ops
)
13204 struct remote_state
*rs
= get_remote_state ();
13206 if (!target_async_permitted
)
13207 /* We only enable async when the user specifically asks for it. */
13210 /* We're async whenever the serial device is. */
13211 return serial_can_async_p (rs
->remote_desc
);
13215 remote_is_async_p (struct target_ops
*ops
)
13217 struct remote_state
*rs
= get_remote_state ();
13219 if (!target_async_permitted
)
13220 /* We only enable async when the user specifically asks for it. */
13223 /* We're async whenever the serial device is. */
13224 return serial_is_async_p (rs
->remote_desc
);
13227 /* Pass the SERIAL event on and up to the client. One day this code
13228 will be able to delay notifying the client of an event until the
13229 point where an entire packet has been received. */
13231 static serial_event_ftype remote_async_serial_handler
;
13234 remote_async_serial_handler (struct serial
*scb
, void *context
)
13236 /* Don't propogate error information up to the client. Instead let
13237 the client find out about the error by querying the target. */
13238 inferior_event_handler (INF_REG_EVENT
, NULL
);
13242 remote_async_inferior_event_handler (gdb_client_data data
)
13244 inferior_event_handler (INF_REG_EVENT
, NULL
);
13248 remote_async (struct target_ops
*ops
, int enable
)
13250 struct remote_state
*rs
= get_remote_state ();
13254 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13256 /* If there are pending events in the stop reply queue tell the
13257 event loop to process them. */
13258 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13259 mark_async_event_handler (remote_async_inferior_event_token
);
13260 /* For simplicity, below we clear the pending events token
13261 without remembering whether it is marked, so here we always
13262 mark it. If there's actually no pending notification to
13263 process, this ends up being a no-op (other than a spurious
13264 event-loop wakeup). */
13265 if (target_is_non_stop_p ())
13266 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13270 serial_async (rs
->remote_desc
, NULL
, NULL
);
13271 /* If the core is disabling async, it doesn't want to be
13272 disturbed with target events. Clear all async event sources
13274 clear_async_event_handler (remote_async_inferior_event_token
);
13275 if (target_is_non_stop_p ())
13276 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13280 /* Implementation of the to_thread_events method. */
13283 remote_thread_events (struct target_ops
*ops
, int enable
)
13285 struct remote_state
*rs
= get_remote_state ();
13286 size_t size
= get_remote_packet_size ();
13288 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13291 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13293 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13295 switch (packet_ok (rs
->buf
,
13296 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13299 if (strcmp (rs
->buf
, "OK") != 0)
13300 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13303 warning (_("Remote failure reply: %s"), rs
->buf
);
13305 case PACKET_UNKNOWN
:
13311 set_remote_cmd (char *args
, int from_tty
)
13313 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13317 show_remote_cmd (char *args
, int from_tty
)
13319 /* We can't just use cmd_show_list here, because we want to skip
13320 the redundant "show remote Z-packet" and the legacy aliases. */
13321 struct cleanup
*showlist_chain
;
13322 struct cmd_list_element
*list
= remote_show_cmdlist
;
13323 struct ui_out
*uiout
= current_uiout
;
13325 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13326 for (; list
!= NULL
; list
= list
->next
)
13327 if (strcmp (list
->name
, "Z-packet") == 0)
13329 else if (list
->type
== not_set_cmd
)
13330 /* Alias commands are exactly like the original, except they
13331 don't have the normal type. */
13335 struct cleanup
*option_chain
13336 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13338 ui_out_field_string (uiout
, "name", list
->name
);
13339 ui_out_text (uiout
, ": ");
13340 if (list
->type
== show_cmd
)
13341 do_show_command ((char *) NULL
, from_tty
, list
);
13343 cmd_func (list
, NULL
, from_tty
);
13344 /* Close the tuple. */
13345 do_cleanups (option_chain
);
13348 /* Close the tuple. */
13349 do_cleanups (showlist_chain
);
13353 /* Function to be called whenever a new objfile (shlib) is detected. */
13355 remote_new_objfile (struct objfile
*objfile
)
13357 struct remote_state
*rs
= get_remote_state ();
13359 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13360 remote_check_symbols ();
13363 /* Pull all the tracepoints defined on the target and create local
13364 data structures representing them. We don't want to create real
13365 tracepoints yet, we don't want to mess up the user's existing
13369 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13371 struct remote_state
*rs
= get_remote_state ();
13374 /* Ask for a first packet of tracepoint definition. */
13376 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13378 while (*p
&& *p
!= 'l')
13380 parse_tracepoint_definition (p
, utpp
);
13381 /* Ask for another packet of tracepoint definition. */
13383 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13390 remote_upload_trace_state_variables (struct target_ops
*self
,
13391 struct uploaded_tsv
**utsvp
)
13393 struct remote_state
*rs
= get_remote_state ();
13396 /* Ask for a first packet of variable definition. */
13398 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13400 while (*p
&& *p
!= 'l')
13402 parse_tsv_definition (p
, utsvp
);
13403 /* Ask for another packet of variable definition. */
13405 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13411 /* The "set/show range-stepping" show hook. */
13414 show_range_stepping (struct ui_file
*file
, int from_tty
,
13415 struct cmd_list_element
*c
,
13418 fprintf_filtered (file
,
13419 _("Debugger's willingness to use range stepping "
13420 "is %s.\n"), value
);
13423 /* The "set/show range-stepping" set hook. */
13426 set_range_stepping (char *ignore_args
, int from_tty
,
13427 struct cmd_list_element
*c
)
13429 struct remote_state
*rs
= get_remote_state ();
13431 /* Whene enabling, check whether range stepping is actually
13432 supported by the target, and warn if not. */
13433 if (use_range_stepping
)
13435 if (rs
->remote_desc
!= NULL
)
13437 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13438 remote_vcont_probe (rs
);
13440 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13441 && rs
->supports_vCont
.r
)
13445 warning (_("Range stepping is not supported by the current target"));
13450 _initialize_remote (void)
13452 struct cmd_list_element
*cmd
;
13453 const char *cmd_name
;
13455 /* architecture specific data */
13456 remote_gdbarch_data_handle
=
13457 gdbarch_data_register_post_init (init_remote_state
);
13458 remote_g_packet_data_handle
=
13459 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13462 = register_program_space_data_with_cleanup (NULL
,
13463 remote_pspace_data_cleanup
);
13465 /* Initialize the per-target state. At the moment there is only one
13466 of these, not one per target. Only one target is active at a
13468 remote_state
= new_remote_state ();
13470 init_remote_ops ();
13471 add_target (&remote_ops
);
13473 init_extended_remote_ops ();
13474 add_target (&extended_remote_ops
);
13476 /* Hook into new objfile notification. */
13477 observer_attach_new_objfile (remote_new_objfile
);
13478 /* We're no longer interested in notification events of an inferior
13480 observer_attach_inferior_exit (discard_pending_stop_replies
);
13482 /* Set up signal handlers. */
13483 async_sigint_remote_token
=
13484 create_async_signal_handler (async_remote_interrupt
, NULL
);
13485 async_sigint_remote_twice_token
=
13486 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
13489 init_remote_threadtests ();
13492 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13493 /* set/show remote ... */
13495 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13496 Remote protocol specific variables\n\
13497 Configure various remote-protocol specific variables such as\n\
13498 the packets being used"),
13499 &remote_set_cmdlist
, "set remote ",
13500 0 /* allow-unknown */, &setlist
);
13501 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13502 Remote protocol specific variables\n\
13503 Configure various remote-protocol specific variables such as\n\
13504 the packets being used"),
13505 &remote_show_cmdlist
, "show remote ",
13506 0 /* allow-unknown */, &showlist
);
13508 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13509 Compare section data on target to the exec file.\n\
13510 Argument is a single section name (default: all loaded sections).\n\
13511 To compare only read-only loaded sections, specify the -r option."),
13514 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13515 Send an arbitrary packet to a remote target.\n\
13516 maintenance packet TEXT\n\
13517 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13518 this command sends the string TEXT to the inferior, and displays the\n\
13519 response packet. GDB supplies the initial `$' character, and the\n\
13520 terminating `#' character and checksum."),
13523 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13524 Set whether to send break if interrupted."), _("\
13525 Show whether to send break if interrupted."), _("\
13526 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13527 set_remotebreak
, show_remotebreak
,
13528 &setlist
, &showlist
);
13529 cmd_name
= "remotebreak";
13530 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13531 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13532 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13533 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13534 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13536 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13537 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13539 Set interrupt sequence to remote target."), _("\
13540 Show interrupt sequence to remote target."), _("\
13541 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13542 NULL
, show_interrupt_sequence
,
13543 &remote_set_cmdlist
,
13544 &remote_show_cmdlist
);
13546 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13547 &interrupt_on_connect
, _("\
13548 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13549 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13550 If set, interrupt sequence is sent to remote target."),
13552 &remote_set_cmdlist
, &remote_show_cmdlist
);
13554 /* Install commands for configuring memory read/write packets. */
13556 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13557 Set the maximum number of bytes per memory write packet (deprecated)."),
13559 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13560 Show the maximum number of bytes per memory write packet (deprecated)."),
13562 add_cmd ("memory-write-packet-size", no_class
,
13563 set_memory_write_packet_size
, _("\
13564 Set the maximum number of bytes per memory-write packet.\n\
13565 Specify the number of bytes in a packet or 0 (zero) for the\n\
13566 default packet size. The actual limit is further reduced\n\
13567 dependent on the target. Specify ``fixed'' to disable the\n\
13568 further restriction and ``limit'' to enable that restriction."),
13569 &remote_set_cmdlist
);
13570 add_cmd ("memory-read-packet-size", no_class
,
13571 set_memory_read_packet_size
, _("\
13572 Set the maximum number of bytes per memory-read packet.\n\
13573 Specify the number of bytes in a packet or 0 (zero) for the\n\
13574 default packet size. The actual limit is further reduced\n\
13575 dependent on the target. Specify ``fixed'' to disable the\n\
13576 further restriction and ``limit'' to enable that restriction."),
13577 &remote_set_cmdlist
);
13578 add_cmd ("memory-write-packet-size", no_class
,
13579 show_memory_write_packet_size
,
13580 _("Show the maximum number of bytes per memory-write packet."),
13581 &remote_show_cmdlist
);
13582 add_cmd ("memory-read-packet-size", no_class
,
13583 show_memory_read_packet_size
,
13584 _("Show the maximum number of bytes per memory-read packet."),
13585 &remote_show_cmdlist
);
13587 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13588 &remote_hw_watchpoint_limit
, _("\
13589 Set the maximum number of target hardware watchpoints."), _("\
13590 Show the maximum number of target hardware watchpoints."), _("\
13591 Specify a negative limit for unlimited."),
13592 NULL
, NULL
, /* FIXME: i18n: The maximum
13593 number of target hardware
13594 watchpoints is %s. */
13595 &remote_set_cmdlist
, &remote_show_cmdlist
);
13596 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13597 &remote_hw_watchpoint_length_limit
, _("\
13598 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13599 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13600 Specify a negative limit for unlimited."),
13601 NULL
, NULL
, /* FIXME: i18n: The maximum
13602 length (in bytes) of a target
13603 hardware watchpoint is %s. */
13604 &remote_set_cmdlist
, &remote_show_cmdlist
);
13605 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13606 &remote_hw_breakpoint_limit
, _("\
13607 Set the maximum number of target hardware breakpoints."), _("\
13608 Show the maximum number of target hardware breakpoints."), _("\
13609 Specify a negative limit for unlimited."),
13610 NULL
, NULL
, /* FIXME: i18n: The maximum
13611 number of target hardware
13612 breakpoints is %s. */
13613 &remote_set_cmdlist
, &remote_show_cmdlist
);
13615 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13616 &remote_address_size
, _("\
13617 Set the maximum size of the address (in bits) in a memory packet."), _("\
13618 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13620 NULL
, /* FIXME: i18n: */
13621 &setlist
, &showlist
);
13623 init_all_packet_configs ();
13625 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13626 "X", "binary-download", 1);
13628 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13629 "vCont", "verbose-resume", 0);
13631 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13632 "QPassSignals", "pass-signals", 0);
13634 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
13635 "QCatchSyscalls", "catch-syscalls", 0);
13637 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13638 "QProgramSignals", "program-signals", 0);
13640 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13641 "qSymbol", "symbol-lookup", 0);
13643 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13644 "P", "set-register", 1);
13646 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13647 "p", "fetch-register", 1);
13649 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13650 "Z0", "software-breakpoint", 0);
13652 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13653 "Z1", "hardware-breakpoint", 0);
13655 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13656 "Z2", "write-watchpoint", 0);
13658 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13659 "Z3", "read-watchpoint", 0);
13661 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13662 "Z4", "access-watchpoint", 0);
13664 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13665 "qXfer:auxv:read", "read-aux-vector", 0);
13667 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13668 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13670 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13671 "qXfer:features:read", "target-features", 0);
13673 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13674 "qXfer:libraries:read", "library-info", 0);
13676 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13677 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13679 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13680 "qXfer:memory-map:read", "memory-map", 0);
13682 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13683 "qXfer:spu:read", "read-spu-object", 0);
13685 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13686 "qXfer:spu:write", "write-spu-object", 0);
13688 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13689 "qXfer:osdata:read", "osdata", 0);
13691 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13692 "qXfer:threads:read", "threads", 0);
13694 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13695 "qXfer:siginfo:read", "read-siginfo-object", 0);
13697 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13698 "qXfer:siginfo:write", "write-siginfo-object", 0);
13700 add_packet_config_cmd
13701 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13702 "qXfer:traceframe-info:read", "traceframe-info", 0);
13704 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13705 "qXfer:uib:read", "unwind-info-block", 0);
13707 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13708 "qGetTLSAddr", "get-thread-local-storage-address",
13711 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13712 "qGetTIBAddr", "get-thread-information-block-address",
13715 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13716 "bc", "reverse-continue", 0);
13718 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13719 "bs", "reverse-step", 0);
13721 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13722 "qSupported", "supported-packets", 0);
13724 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13725 "qSearch:memory", "search-memory", 0);
13727 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13728 "qTStatus", "trace-status", 0);
13730 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13731 "vFile:setfs", "hostio-setfs", 0);
13733 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13734 "vFile:open", "hostio-open", 0);
13736 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13737 "vFile:pread", "hostio-pread", 0);
13739 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13740 "vFile:pwrite", "hostio-pwrite", 0);
13742 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13743 "vFile:close", "hostio-close", 0);
13745 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13746 "vFile:unlink", "hostio-unlink", 0);
13748 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13749 "vFile:readlink", "hostio-readlink", 0);
13751 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13752 "vFile:fstat", "hostio-fstat", 0);
13754 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13755 "vAttach", "attach", 0);
13757 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13760 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13761 "QStartNoAckMode", "noack", 0);
13763 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13764 "vKill", "kill", 0);
13766 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13767 "qAttached", "query-attached", 0);
13769 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13770 "ConditionalTracepoints",
13771 "conditional-tracepoints", 0);
13773 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13774 "ConditionalBreakpoints",
13775 "conditional-breakpoints", 0);
13777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13778 "BreakpointCommands",
13779 "breakpoint-commands", 0);
13781 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13782 "FastTracepoints", "fast-tracepoints", 0);
13784 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13785 "TracepointSource", "TracepointSource", 0);
13787 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13788 "QAllow", "allow", 0);
13790 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13791 "StaticTracepoints", "static-tracepoints", 0);
13793 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13794 "InstallInTrace", "install-in-trace", 0);
13796 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13797 "qXfer:statictrace:read", "read-sdata-object", 0);
13799 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13800 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13802 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13803 "QDisableRandomization", "disable-randomization", 0);
13805 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13806 "QAgent", "agent", 0);
13808 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13809 "QTBuffer:size", "trace-buffer-size", 0);
13811 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13812 "Qbtrace:off", "disable-btrace", 0);
13814 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13815 "Qbtrace:bts", "enable-btrace-bts", 0);
13817 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13818 "Qbtrace:pt", "enable-btrace-pt", 0);
13820 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13821 "qXfer:btrace", "read-btrace", 0);
13823 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13824 "qXfer:btrace-conf", "read-btrace-conf", 0);
13826 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13827 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13829 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13830 "multiprocess-feature", "multiprocess-feature", 0);
13832 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13833 "swbreak-feature", "swbreak-feature", 0);
13835 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13836 "hwbreak-feature", "hwbreak-feature", 0);
13838 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13839 "fork-event-feature", "fork-event-feature", 0);
13841 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13842 "vfork-event-feature", "vfork-event-feature", 0);
13844 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13845 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13848 "vContSupported", "verbose-resume-supported", 0);
13850 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13851 "exec-event-feature", "exec-event-feature", 0);
13853 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
13854 "vCtrlC", "ctrl-c", 0);
13856 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
13857 "QThreadEvents", "thread-events", 0);
13859 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
13860 "N stop reply", "no-resumed-stop-reply", 0);
13862 /* Assert that we've registered "set remote foo-packet" commands
13863 for all packet configs. */
13867 for (i
= 0; i
< PACKET_MAX
; i
++)
13869 /* Ideally all configs would have a command associated. Some
13870 still don't though. */
13875 case PACKET_QNonStop
:
13876 case PACKET_EnableDisableTracepoints_feature
:
13877 case PACKET_tracenz_feature
:
13878 case PACKET_DisconnectedTracing_feature
:
13879 case PACKET_augmented_libraries_svr4_read_feature
:
13881 /* Additions to this list need to be well justified:
13882 pre-existing packets are OK; new packets are not. */
13890 /* This catches both forgetting to add a config command, and
13891 forgetting to remove a packet from the exception list. */
13892 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13896 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13897 Z sub-packet has its own set and show commands, but users may
13898 have sets to this variable in their .gdbinit files (or in their
13900 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13901 &remote_Z_packet_detect
, _("\
13902 Set use of remote protocol `Z' packets"), _("\
13903 Show use of remote protocol `Z' packets "), _("\
13904 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13906 set_remote_protocol_Z_packet_cmd
,
13907 show_remote_protocol_Z_packet_cmd
,
13908 /* FIXME: i18n: Use of remote protocol
13909 `Z' packets is %s. */
13910 &remote_set_cmdlist
, &remote_show_cmdlist
);
13912 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13913 Manipulate files on the remote system\n\
13914 Transfer files to and from the remote target system."),
13915 &remote_cmdlist
, "remote ",
13916 0 /* allow-unknown */, &cmdlist
);
13918 add_cmd ("put", class_files
, remote_put_command
,
13919 _("Copy a local file to the remote system."),
13922 add_cmd ("get", class_files
, remote_get_command
,
13923 _("Copy a remote file to the local system."),
13926 add_cmd ("delete", class_files
, remote_delete_command
,
13927 _("Delete a remote file."),
13930 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13931 &remote_exec_file_var
, _("\
13932 Set the remote pathname for \"run\""), _("\
13933 Show the remote pathname for \"run\""), NULL
,
13934 set_remote_exec_file
,
13935 show_remote_exec_file
,
13936 &remote_set_cmdlist
,
13937 &remote_show_cmdlist
);
13939 add_setshow_boolean_cmd ("range-stepping", class_run
,
13940 &use_range_stepping
, _("\
13941 Enable or disable range stepping."), _("\
13942 Show whether target-assisted range stepping is enabled."), _("\
13943 If on, and the target supports it, when stepping a source line, GDB\n\
13944 tells the target to step the corresponding range of addresses itself instead\n\
13945 of issuing multiple single-steps. This speeds up source level\n\
13946 stepping. If off, GDB always issues single-steps, even if range\n\
13947 stepping is supported by the target. The default is on."),
13948 set_range_stepping
,
13949 show_range_stepping
,
13953 /* Eventually initialize fileio. See fileio.c */
13954 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13956 /* Take advantage of the fact that the TID field is not used, to tag
13957 special ptids with it set to != 0. */
13958 magic_null_ptid
= ptid_build (42000, -1, 1);
13959 not_sent_ptid
= ptid_build (42000, -2, 1);
13960 any_thread_ptid
= ptid_build (42000, 0, 1);
13962 target_buf_size
= 2048;
13963 target_buf
= (char *) xmalloc (target_buf_size
);