1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2015 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"
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 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void async_cleanup_sigint_signal_handler (void *dummy
);
92 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
93 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
94 int forever
, int *is_notif
);
96 static void async_handle_remote_sigint (int);
97 static void async_handle_remote_sigint_twice (int);
99 static void remote_files_info (struct target_ops
*ignore
);
101 static void remote_prepare_to_store (struct target_ops
*self
,
102 struct regcache
*regcache
);
104 static void remote_open_1 (const char *, int, struct target_ops
*,
107 static void remote_close (struct target_ops
*self
);
111 static int remote_vkill (int pid
, struct remote_state
*rs
);
113 static void remote_mourn (struct target_ops
*ops
);
115 static void extended_remote_restart (void);
117 static void extended_remote_mourn (struct target_ops
*);
119 static void remote_send (char **buf
, long *sizeof_buf_p
);
121 static int readchar (int timeout
);
123 static void remote_serial_write (const char *str
, int len
);
125 static void remote_kill (struct target_ops
*ops
);
127 static int remote_can_async_p (struct target_ops
*);
129 static int remote_is_async_p (struct target_ops
*);
131 static void remote_async (struct target_ops
*ops
, int enable
);
133 static void sync_remote_interrupt_twice (int signo
);
135 static void interrupt_query (void);
137 static void set_general_thread (struct ptid ptid
);
138 static void set_continue_thread (struct ptid ptid
);
140 static void get_offsets (void);
142 static void skip_frame (void);
144 static long read_frame (char **buf_p
, long *sizeof_buf
);
146 static int hexnumlen (ULONGEST num
);
148 static void init_remote_ops (void);
150 static void init_extended_remote_ops (void);
152 static void remote_stop (struct target_ops
*self
, ptid_t
);
154 static int stubhex (int ch
);
156 static int hexnumstr (char *, ULONGEST
);
158 static int hexnumnstr (char *, ULONGEST
, int);
160 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
162 static void print_packet (const char *);
164 static void compare_sections_command (char *, int);
166 static void packet_command (char *, int);
168 static int stub_unpack_int (char *buff
, int fieldlength
);
170 static ptid_t
remote_current_thread (ptid_t oldptid
);
172 static int putpkt_binary (const char *buf
, int cnt
);
174 static void check_binary_download (CORE_ADDR addr
);
176 struct packet_config
;
178 static void show_packet_config_cmd (struct packet_config
*config
);
180 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
182 struct cmd_list_element
*c
,
185 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
186 static ptid_t
read_ptid (char *buf
, char **obuf
);
188 static void remote_set_permissions (struct target_ops
*self
);
190 static int remote_get_trace_status (struct target_ops
*self
,
191 struct trace_status
*ts
);
193 static int remote_upload_tracepoints (struct target_ops
*self
,
194 struct uploaded_tp
**utpp
);
196 static int remote_upload_trace_state_variables (struct target_ops
*self
,
197 struct uploaded_tsv
**utsvp
);
199 static void remote_query_supported (void);
201 static void remote_check_symbols (void);
203 void _initialize_remote (void);
206 static void stop_reply_xfree (struct stop_reply
*);
207 static void remote_parse_stop_reply (char *, struct stop_reply
*);
208 static void push_stop_reply (struct stop_reply
*);
209 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
210 static int peek_stop_reply (ptid_t ptid
);
212 struct threads_listing_context
;
213 static void remove_new_fork_children (struct threads_listing_context
*);
215 static void remote_async_inferior_event_handler (gdb_client_data
);
217 static void remote_terminal_ours (struct target_ops
*self
);
219 static int remote_read_description_p (struct target_ops
*target
);
221 static void remote_console_output (char *msg
);
223 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
225 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
227 static void remote_btrace_reset (void);
229 static int stop_reply_queue_length (void);
231 static void readahead_cache_invalidate (void);
235 static struct cmd_list_element
*remote_cmdlist
;
237 /* For "set remote" and "show remote". */
239 static struct cmd_list_element
*remote_set_cmdlist
;
240 static struct cmd_list_element
*remote_show_cmdlist
;
242 /* Stub vCont actions support.
244 Each field is a boolean flag indicating whether the stub reports
245 support for the corresponding action. */
247 struct vCont_action_support
256 /* Controls whether GDB is willing to use range stepping. */
258 static int use_range_stepping
= 1;
260 #define OPAQUETHREADBYTES 8
262 /* a 64 bit opaque identifier */
263 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
265 /* About this many threadisds fit in a packet. */
267 #define MAXTHREADLISTRESULTS 32
269 /* Data for the vFile:pread readahead cache. */
271 struct readahead_cache
273 /* The file descriptor for the file that is being cached. -1 if the
277 /* The offset into the file that the cache buffer corresponds
281 /* The buffer holding the cache contents. */
283 /* The buffer's size. We try to read as much as fits into a packet
287 /* Cache hit and miss counters. */
292 /* Description of the remote protocol state for the currently
293 connected target. This is per-target state, and independent of the
294 selected architecture. */
298 /* A buffer to use for incoming packets, and its current size. The
299 buffer is grown dynamically for larger incoming packets.
300 Outgoing packets may also be constructed in this buffer.
301 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
302 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
307 /* True if we're going through initial connection setup (finding out
308 about the remote side's threads, relocating symbols, etc.). */
311 /* If we negotiated packet size explicitly (and thus can bypass
312 heuristics for the largest packet size that will not overflow
313 a buffer in the stub), this will be set to that packet size.
314 Otherwise zero, meaning to use the guessed size. */
315 long explicit_packet_size
;
317 /* remote_wait is normally called when the target is running and
318 waits for a stop reply packet. But sometimes we need to call it
319 when the target is already stopped. We can send a "?" packet
320 and have remote_wait read the response. Or, if we already have
321 the response, we can stash it in BUF and tell remote_wait to
322 skip calling getpkt. This flag is set when BUF contains a
323 stop reply packet and the target is not waiting. */
324 int cached_wait_status
;
326 /* True, if in no ack mode. That is, neither GDB nor the stub will
327 expect acks from each other. The connection is assumed to be
331 /* True if we're connected in extended remote mode. */
334 /* True if we resumed the target and we're waiting for the target to
335 stop. In the mean time, we can't start another command/query.
336 The remote server wouldn't be ready to process it, so we'd
337 timeout waiting for a reply that would never come and eventually
338 we'd close the connection. This can happen in asynchronous mode
339 because we allow GDB commands while the target is running. */
340 int waiting_for_stop_reply
;
342 /* The status of the stub support for the various vCont actions. */
343 struct vCont_action_support supports_vCont
;
345 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
346 responded to that. */
349 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
350 remote_open knows that we don't have a file open when the program
352 struct serial
*remote_desc
;
354 /* These are the threads which we last sent to the remote system. The
355 TID member will be -1 for all or -2 for not sent yet. */
356 ptid_t general_thread
;
357 ptid_t continue_thread
;
359 /* This is the traceframe which we last selected on the remote system.
360 It will be -1 if no traceframe is selected. */
361 int remote_traceframe_number
;
363 char *last_pass_packet
;
365 /* The last QProgramSignals packet sent to the target. We bypass
366 sending a new program signals list down to the target if the new
367 packet is exactly the same as the last we sent. IOW, we only let
368 the target know about program signals list changes. */
369 char *last_program_signals_packet
;
371 enum gdb_signal last_sent_signal
;
375 char *finished_object
;
376 char *finished_annex
;
377 ULONGEST finished_offset
;
379 /* Should we try the 'ThreadInfo' query packet?
381 This variable (NOT available to the user: auto-detect only!)
382 determines whether GDB will use the new, simpler "ThreadInfo"
383 query or the older, more complex syntax for thread queries.
384 This is an auto-detect variable (set to true at each connect,
385 and set to false when the target fails to recognize it). */
386 int use_threadinfo_query
;
387 int use_threadextra_query
;
389 /* This is set to the data address of the access causing the target
390 to stop for a watchpoint. */
391 CORE_ADDR remote_watch_data_address
;
393 /* Whether the target stopped for a breakpoint/watchpoint. */
394 enum target_stop_reason stop_reason
;
396 threadref echo_nextthread
;
397 threadref nextthread
;
398 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
400 /* The state of remote notification. */
401 struct remote_notif_state
*notif_state
;
403 /* The branch trace configuration. */
404 struct btrace_config btrace_config
;
406 /* The argument to the last "vFile:setfs:" packet we sent, used
407 to avoid sending repeated unnecessary "vFile:setfs:" packets.
408 Initialized to -1 to indicate that no "vFile:setfs:" packet
409 has yet been sent. */
412 /* A readahead cache for vFile:pread. Often, reading a binary
413 involves a sequence of small reads. E.g., when parsing an ELF
414 file. A readahead cache helps mostly the case of remote
415 debugging on a connection with higher latency, due to the
416 request/reply nature of the RSP. We only cache data for a single
417 file descriptor at a time. */
418 struct readahead_cache readahead_cache
;
421 /* Private data that we'll store in (struct thread_info)->private. */
422 struct private_thread_info
429 free_private_thread_info (struct private_thread_info
*info
)
435 /* This data could be associated with a target, but we do not always
436 have access to the current target when we need it, so for now it is
437 static. This will be fine for as long as only one target is in use
439 static struct remote_state
*remote_state
;
441 static struct remote_state
*
442 get_remote_state_raw (void)
447 /* Allocate a new struct remote_state with xmalloc, initialize it, and
450 static struct remote_state
*
451 new_remote_state (void)
453 struct remote_state
*result
= XCNEW (struct remote_state
);
455 /* The default buffer size is unimportant; it will be expanded
456 whenever a larger buffer is needed. */
457 result
->buf_size
= 400;
458 result
->buf
= xmalloc (result
->buf_size
);
459 result
->remote_traceframe_number
= -1;
460 result
->last_sent_signal
= GDB_SIGNAL_0
;
466 /* Description of the remote protocol for a given architecture. */
470 long offset
; /* Offset into G packet. */
471 long regnum
; /* GDB's internal register number. */
472 LONGEST pnum
; /* Remote protocol register number. */
473 int in_g_packet
; /* Always part of G packet. */
474 /* long size in bytes; == register_size (target_gdbarch (), regnum);
476 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
480 struct remote_arch_state
482 /* Description of the remote protocol registers. */
483 long sizeof_g_packet
;
485 /* Description of the remote protocol registers indexed by REGNUM
486 (making an array gdbarch_num_regs in size). */
487 struct packet_reg
*regs
;
489 /* This is the size (in chars) of the first response to the ``g''
490 packet. It is used as a heuristic when determining the maximum
491 size of memory-read and memory-write packets. A target will
492 typically only reserve a buffer large enough to hold the ``g''
493 packet. The size does not include packet overhead (headers and
495 long actual_register_packet_size
;
497 /* This is the maximum size (in chars) of a non read/write packet.
498 It is also used as a cap on the size of read/write packets. */
499 long remote_packet_size
;
502 /* Utility: generate error from an incoming stub packet. */
504 trace_error (char *buf
)
507 return; /* not an error msg */
510 case '1': /* malformed packet error */
511 if (*++buf
== '0') /* general case: */
512 error (_("remote.c: error in outgoing packet."));
514 error (_("remote.c: error in outgoing packet at field #%ld."),
515 strtol (buf
, NULL
, 16));
517 error (_("Target returns error code '%s'."), buf
);
521 /* Utility: wait for reply from stub, while accepting "O" packets. */
523 remote_get_noisy_reply (char **buf_p
,
526 do /* Loop on reply from remote stub. */
530 QUIT
; /* Allow user to bail out with ^C. */
531 getpkt (buf_p
, sizeof_buf
, 0);
535 else if (startswith (buf
, "qRelocInsn:"))
538 CORE_ADDR from
, to
, org_to
;
540 int adjusted_size
= 0;
543 p
= buf
+ strlen ("qRelocInsn:");
544 pp
= unpack_varlen_hex (p
, &ul
);
546 error (_("invalid qRelocInsn packet: %s"), buf
);
550 unpack_varlen_hex (p
, &ul
);
557 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
560 CATCH (ex
, RETURN_MASK_ALL
)
562 if (ex
.error
== MEMORY_ERROR
)
564 /* Propagate memory errors silently back to the
565 target. The stub may have limited the range of
566 addresses we can write to, for example. */
570 /* Something unexpectedly bad happened. Be verbose
571 so we can tell what, and propagate the error back
572 to the stub, so it doesn't get stuck waiting for
574 exception_fprintf (gdb_stderr
, ex
,
575 _("warning: relocating instruction: "));
583 adjusted_size
= to
- org_to
;
585 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
589 else if (buf
[0] == 'O' && buf
[1] != 'K')
590 remote_console_output (buf
+ 1); /* 'O' message from stub */
592 return buf
; /* Here's the actual reply. */
597 /* Handle for retreving the remote protocol data from gdbarch. */
598 static struct gdbarch_data
*remote_gdbarch_data_handle
;
600 static struct remote_arch_state
*
601 get_remote_arch_state (void)
603 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
606 /* Fetch the global remote target state. */
608 static struct remote_state
*
609 get_remote_state (void)
611 /* Make sure that the remote architecture state has been
612 initialized, because doing so might reallocate rs->buf. Any
613 function which calls getpkt also needs to be mindful of changes
614 to rs->buf, but this call limits the number of places which run
616 get_remote_arch_state ();
618 return get_remote_state_raw ();
622 compare_pnums (const void *lhs_
, const void *rhs_
)
624 const struct packet_reg
* const *lhs
= lhs_
;
625 const struct packet_reg
* const *rhs
= rhs_
;
627 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
629 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
636 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
638 int regnum
, num_remote_regs
, offset
;
639 struct packet_reg
**remote_regs
;
641 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
643 struct packet_reg
*r
= ®s
[regnum
];
645 if (register_size (gdbarch
, regnum
) == 0)
646 /* Do not try to fetch zero-sized (placeholder) registers. */
649 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
654 /* Define the g/G packet format as the contents of each register
655 with a remote protocol number, in order of ascending protocol
658 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
659 * sizeof (struct packet_reg
*));
660 for (num_remote_regs
= 0, regnum
= 0;
661 regnum
< gdbarch_num_regs (gdbarch
);
663 if (regs
[regnum
].pnum
!= -1)
664 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
666 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
669 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
671 remote_regs
[regnum
]->in_g_packet
= 1;
672 remote_regs
[regnum
]->offset
= offset
;
673 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
679 /* Given the architecture described by GDBARCH, return the remote
680 protocol register's number and the register's offset in the g/G
681 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
682 If the target does not have a mapping for REGNUM, return false,
683 otherwise, return true. */
686 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
687 int *pnum
, int *poffset
)
690 struct packet_reg
*regs
;
691 struct cleanup
*old_chain
;
693 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
695 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
696 old_chain
= make_cleanup (xfree
, regs
);
698 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
700 *pnum
= regs
[regnum
].pnum
;
701 *poffset
= regs
[regnum
].offset
;
703 do_cleanups (old_chain
);
709 init_remote_state (struct gdbarch
*gdbarch
)
711 struct remote_state
*rs
= get_remote_state_raw ();
712 struct remote_arch_state
*rsa
;
714 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
716 /* Use the architecture to build a regnum<->pnum table, which will be
717 1:1 unless a feature set specifies otherwise. */
718 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
719 gdbarch_num_regs (gdbarch
),
722 /* Record the maximum possible size of the g packet - it may turn out
724 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
726 /* Default maximum number of characters in a packet body. Many
727 remote stubs have a hardwired buffer size of 400 bytes
728 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
729 as the maximum packet-size to ensure that the packet and an extra
730 NUL character can always fit in the buffer. This stops GDB
731 trashing stubs that try to squeeze an extra NUL into what is
732 already a full buffer (As of 1999-12-04 that was most stubs). */
733 rsa
->remote_packet_size
= 400 - 1;
735 /* This one is filled in when a ``g'' packet is received. */
736 rsa
->actual_register_packet_size
= 0;
738 /* Should rsa->sizeof_g_packet needs more space than the
739 default, adjust the size accordingly. Remember that each byte is
740 encoded as two characters. 32 is the overhead for the packet
741 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
742 (``$NN:G...#NN'') is a better guess, the below has been padded a
744 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
745 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
747 /* Make sure that the packet buffer is plenty big enough for
748 this architecture. */
749 if (rs
->buf_size
< rsa
->remote_packet_size
)
751 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
752 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
758 /* Return the current allowed size of a remote packet. This is
759 inferred from the current architecture, and should be used to
760 limit the length of outgoing packets. */
762 get_remote_packet_size (void)
764 struct remote_state
*rs
= get_remote_state ();
765 struct remote_arch_state
*rsa
= get_remote_arch_state ();
767 if (rs
->explicit_packet_size
)
768 return rs
->explicit_packet_size
;
770 return rsa
->remote_packet_size
;
773 static struct packet_reg
*
774 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
776 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
780 struct packet_reg
*r
= &rsa
->regs
[regnum
];
782 gdb_assert (r
->regnum
== regnum
);
787 static struct packet_reg
*
788 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
792 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
794 struct packet_reg
*r
= &rsa
->regs
[i
];
802 static struct target_ops remote_ops
;
804 static struct target_ops extended_remote_ops
;
806 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
807 ``forever'' still use the normal timeout mechanism. This is
808 currently used by the ASYNC code to guarentee that target reads
809 during the initial connect always time-out. Once getpkt has been
810 modified to return a timeout indication and, in turn
811 remote_wait()/wait_for_inferior() have gained a timeout parameter
813 static int wait_forever_enabled_p
= 1;
815 /* Allow the user to specify what sequence to send to the remote
816 when he requests a program interruption: Although ^C is usually
817 what remote systems expect (this is the default, here), it is
818 sometimes preferable to send a break. On other systems such
819 as the Linux kernel, a break followed by g, which is Magic SysRq g
820 is required in order to interrupt the execution. */
821 const char interrupt_sequence_control_c
[] = "Ctrl-C";
822 const char interrupt_sequence_break
[] = "BREAK";
823 const char interrupt_sequence_break_g
[] = "BREAK-g";
824 static const char *const interrupt_sequence_modes
[] =
826 interrupt_sequence_control_c
,
827 interrupt_sequence_break
,
828 interrupt_sequence_break_g
,
831 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
834 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
835 struct cmd_list_element
*c
,
838 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
839 fprintf_filtered (file
,
840 _("Send the ASCII ETX character (Ctrl-c) "
841 "to the remote target to interrupt the "
842 "execution of the program.\n"));
843 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
844 fprintf_filtered (file
,
845 _("send a break signal to the remote target "
846 "to interrupt the execution of the program.\n"));
847 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
848 fprintf_filtered (file
,
849 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
850 "the remote target to interrupt the execution "
851 "of Linux kernel.\n"));
853 internal_error (__FILE__
, __LINE__
,
854 _("Invalid value for interrupt_sequence_mode: %s."),
855 interrupt_sequence_mode
);
858 /* This boolean variable specifies whether interrupt_sequence is sent
859 to the remote target when gdb connects to it.
860 This is mostly needed when you debug the Linux kernel: The Linux kernel
861 expects BREAK g which is Magic SysRq g for connecting gdb. */
862 static int interrupt_on_connect
= 0;
864 /* This variable is used to implement the "set/show remotebreak" commands.
865 Since these commands are now deprecated in favor of "set/show remote
866 interrupt-sequence", it no longer has any effect on the code. */
867 static int remote_break
;
870 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
873 interrupt_sequence_mode
= interrupt_sequence_break
;
875 interrupt_sequence_mode
= interrupt_sequence_control_c
;
879 show_remotebreak (struct ui_file
*file
, int from_tty
,
880 struct cmd_list_element
*c
,
885 /* This variable sets the number of bits in an address that are to be
886 sent in a memory ("M" or "m") packet. Normally, after stripping
887 leading zeros, the entire address would be sent. This variable
888 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
889 initial implementation of remote.c restricted the address sent in
890 memory packets to ``host::sizeof long'' bytes - (typically 32
891 bits). Consequently, for 64 bit targets, the upper 32 bits of an
892 address was never sent. Since fixing this bug may cause a break in
893 some remote targets this variable is principly provided to
894 facilitate backward compatibility. */
896 static unsigned int remote_address_size
;
898 /* Temporary to track who currently owns the terminal. See
899 remote_terminal_* for more details. */
901 static int remote_async_terminal_ours_p
;
903 /* The executable file to use for "run" on the remote side. */
905 static char *remote_exec_file
= "";
908 /* User configurable variables for the number of characters in a
909 memory read/write packet. MIN (rsa->remote_packet_size,
910 rsa->sizeof_g_packet) is the default. Some targets need smaller
911 values (fifo overruns, et.al.) and some users need larger values
912 (speed up transfers). The variables ``preferred_*'' (the user
913 request), ``current_*'' (what was actually set) and ``forced_*''
914 (Positive - a soft limit, negative - a hard limit). */
916 struct memory_packet_config
923 /* Compute the current size of a read/write packet. Since this makes
924 use of ``actual_register_packet_size'' the computation is dynamic. */
927 get_memory_packet_size (struct memory_packet_config
*config
)
929 struct remote_state
*rs
= get_remote_state ();
930 struct remote_arch_state
*rsa
= get_remote_arch_state ();
932 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
933 law?) that some hosts don't cope very well with large alloca()
934 calls. Eventually the alloca() code will be replaced by calls to
935 xmalloc() and make_cleanups() allowing this restriction to either
936 be lifted or removed. */
937 #ifndef MAX_REMOTE_PACKET_SIZE
938 #define MAX_REMOTE_PACKET_SIZE 16384
940 /* NOTE: 20 ensures we can write at least one byte. */
941 #ifndef MIN_REMOTE_PACKET_SIZE
942 #define MIN_REMOTE_PACKET_SIZE 20
947 if (config
->size
<= 0)
948 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
950 what_they_get
= config
->size
;
954 what_they_get
= get_remote_packet_size ();
955 /* Limit the packet to the size specified by the user. */
957 && what_they_get
> config
->size
)
958 what_they_get
= config
->size
;
960 /* Limit it to the size of the targets ``g'' response unless we have
961 permission from the stub to use a larger packet size. */
962 if (rs
->explicit_packet_size
== 0
963 && rsa
->actual_register_packet_size
> 0
964 && what_they_get
> rsa
->actual_register_packet_size
)
965 what_they_get
= rsa
->actual_register_packet_size
;
967 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
968 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
969 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
970 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
972 /* Make sure there is room in the global buffer for this packet
973 (including its trailing NUL byte). */
974 if (rs
->buf_size
< what_they_get
+ 1)
976 rs
->buf_size
= 2 * what_they_get
;
977 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
980 return what_they_get
;
983 /* Update the size of a read/write packet. If they user wants
984 something really big then do a sanity check. */
987 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
989 int fixed_p
= config
->fixed_p
;
990 long size
= config
->size
;
993 error (_("Argument required (integer, `fixed' or `limited')."));
994 else if (strcmp (args
, "hard") == 0
995 || strcmp (args
, "fixed") == 0)
997 else if (strcmp (args
, "soft") == 0
998 || strcmp (args
, "limit") == 0)
1004 size
= strtoul (args
, &end
, 0);
1006 error (_("Invalid %s (bad syntax)."), config
->name
);
1008 /* Instead of explicitly capping the size of a packet to
1009 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
1010 instead allowed to set the size to something arbitrarily
1012 if (size
> MAX_REMOTE_PACKET_SIZE
)
1013 error (_("Invalid %s (too large)."), config
->name
);
1017 if (fixed_p
&& !config
->fixed_p
)
1019 if (! query (_("The target may not be able to correctly handle a %s\n"
1020 "of %ld bytes. Change the packet size? "),
1021 config
->name
, size
))
1022 error (_("Packet size not changed."));
1024 /* Update the config. */
1025 config
->fixed_p
= fixed_p
;
1026 config
->size
= size
;
1030 show_memory_packet_size (struct memory_packet_config
*config
)
1032 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1033 if (config
->fixed_p
)
1034 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1035 get_memory_packet_size (config
));
1037 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1038 get_memory_packet_size (config
));
1041 static struct memory_packet_config memory_write_packet_config
=
1043 "memory-write-packet-size",
1047 set_memory_write_packet_size (char *args
, int from_tty
)
1049 set_memory_packet_size (args
, &memory_write_packet_config
);
1053 show_memory_write_packet_size (char *args
, int from_tty
)
1055 show_memory_packet_size (&memory_write_packet_config
);
1059 get_memory_write_packet_size (void)
1061 return get_memory_packet_size (&memory_write_packet_config
);
1064 static struct memory_packet_config memory_read_packet_config
=
1066 "memory-read-packet-size",
1070 set_memory_read_packet_size (char *args
, int from_tty
)
1072 set_memory_packet_size (args
, &memory_read_packet_config
);
1076 show_memory_read_packet_size (char *args
, int from_tty
)
1078 show_memory_packet_size (&memory_read_packet_config
);
1082 get_memory_read_packet_size (void)
1084 long size
= get_memory_packet_size (&memory_read_packet_config
);
1086 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1087 extra buffer size argument before the memory read size can be
1088 increased beyond this. */
1089 if (size
> get_remote_packet_size ())
1090 size
= get_remote_packet_size ();
1095 /* Generic configuration support for packets the stub optionally
1096 supports. Allows the user to specify the use of the packet as well
1097 as allowing GDB to auto-detect support in the remote stub. */
1101 PACKET_SUPPORT_UNKNOWN
= 0,
1106 struct packet_config
1111 /* If auto, GDB auto-detects support for this packet or feature,
1112 either through qSupported, or by trying the packet and looking
1113 at the response. If true, GDB assumes the target supports this
1114 packet. If false, the packet is disabled. Configs that don't
1115 have an associated command always have this set to auto. */
1116 enum auto_boolean detect
;
1118 /* Does the target support this packet? */
1119 enum packet_support support
;
1122 /* Analyze a packet's return value and update the packet config
1132 static enum packet_support
packet_config_support (struct packet_config
*config
);
1133 static enum packet_support
packet_support (int packet
);
1136 show_packet_config_cmd (struct packet_config
*config
)
1138 char *support
= "internal-error";
1140 switch (packet_config_support (config
))
1143 support
= "enabled";
1145 case PACKET_DISABLE
:
1146 support
= "disabled";
1148 case PACKET_SUPPORT_UNKNOWN
:
1149 support
= "unknown";
1152 switch (config
->detect
)
1154 case AUTO_BOOLEAN_AUTO
:
1155 printf_filtered (_("Support for the `%s' packet "
1156 "is auto-detected, currently %s.\n"),
1157 config
->name
, support
);
1159 case AUTO_BOOLEAN_TRUE
:
1160 case AUTO_BOOLEAN_FALSE
:
1161 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1162 config
->name
, support
);
1168 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1169 const char *title
, int legacy
)
1175 config
->name
= name
;
1176 config
->title
= title
;
1177 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1179 show_doc
= xstrprintf ("Show current use of remote "
1180 "protocol `%s' (%s) packet",
1182 /* set/show TITLE-packet {auto,on,off} */
1183 cmd_name
= xstrprintf ("%s-packet", title
);
1184 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1185 &config
->detect
, set_doc
,
1186 show_doc
, NULL
, /* help_doc */
1188 show_remote_protocol_packet_cmd
,
1189 &remote_set_cmdlist
, &remote_show_cmdlist
);
1190 /* The command code copies the documentation strings. */
1193 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1198 legacy_name
= xstrprintf ("%s-packet", name
);
1199 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1200 &remote_set_cmdlist
);
1201 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1202 &remote_show_cmdlist
);
1206 static enum packet_result
1207 packet_check_result (const char *buf
)
1211 /* The stub recognized the packet request. Check that the
1212 operation succeeded. */
1214 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1216 /* "Enn" - definitly an error. */
1217 return PACKET_ERROR
;
1219 /* Always treat "E." as an error. This will be used for
1220 more verbose error messages, such as E.memtypes. */
1221 if (buf
[0] == 'E' && buf
[1] == '.')
1222 return PACKET_ERROR
;
1224 /* The packet may or may not be OK. Just assume it is. */
1228 /* The stub does not support the packet. */
1229 return PACKET_UNKNOWN
;
1232 static enum packet_result
1233 packet_ok (const char *buf
, struct packet_config
*config
)
1235 enum packet_result result
;
1237 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1238 && config
->support
== PACKET_DISABLE
)
1239 internal_error (__FILE__
, __LINE__
,
1240 _("packet_ok: attempt to use a disabled packet"));
1242 result
= packet_check_result (buf
);
1247 /* The stub recognized the packet request. */
1248 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1251 fprintf_unfiltered (gdb_stdlog
,
1252 "Packet %s (%s) is supported\n",
1253 config
->name
, config
->title
);
1254 config
->support
= PACKET_ENABLE
;
1257 case PACKET_UNKNOWN
:
1258 /* The stub does not support the packet. */
1259 if (config
->detect
== AUTO_BOOLEAN_AUTO
1260 && config
->support
== PACKET_ENABLE
)
1262 /* If the stub previously indicated that the packet was
1263 supported then there is a protocol error. */
1264 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1265 config
->name
, config
->title
);
1267 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1269 /* The user set it wrong. */
1270 error (_("Enabled packet %s (%s) not recognized by stub"),
1271 config
->name
, config
->title
);
1275 fprintf_unfiltered (gdb_stdlog
,
1276 "Packet %s (%s) is NOT supported\n",
1277 config
->name
, config
->title
);
1278 config
->support
= PACKET_DISABLE
;
1299 PACKET_vFile_pwrite
,
1301 PACKET_vFile_unlink
,
1302 PACKET_vFile_readlink
,
1305 PACKET_qXfer_features
,
1306 PACKET_qXfer_exec_file
,
1307 PACKET_qXfer_libraries
,
1308 PACKET_qXfer_libraries_svr4
,
1309 PACKET_qXfer_memory_map
,
1310 PACKET_qXfer_spu_read
,
1311 PACKET_qXfer_spu_write
,
1312 PACKET_qXfer_osdata
,
1313 PACKET_qXfer_threads
,
1314 PACKET_qXfer_statictrace_read
,
1315 PACKET_qXfer_traceframe_info
,
1321 PACKET_QPassSignals
,
1322 PACKET_QProgramSignals
,
1324 PACKET_qSearch_memory
,
1327 PACKET_QStartNoAckMode
,
1329 PACKET_qXfer_siginfo_read
,
1330 PACKET_qXfer_siginfo_write
,
1333 /* Support for conditional tracepoints. */
1334 PACKET_ConditionalTracepoints
,
1336 /* Support for target-side breakpoint conditions. */
1337 PACKET_ConditionalBreakpoints
,
1339 /* Support for target-side breakpoint commands. */
1340 PACKET_BreakpointCommands
,
1342 /* Support for fast tracepoints. */
1343 PACKET_FastTracepoints
,
1345 /* Support for static tracepoints. */
1346 PACKET_StaticTracepoints
,
1348 /* Support for installing tracepoints while a trace experiment is
1350 PACKET_InstallInTrace
,
1354 PACKET_TracepointSource
,
1357 PACKET_QDisableRandomization
,
1359 PACKET_QTBuffer_size
,
1363 PACKET_qXfer_btrace
,
1365 /* Support for the QNonStop packet. */
1368 /* Support for multi-process extensions. */
1369 PACKET_multiprocess_feature
,
1371 /* Support for enabling and disabling tracepoints while a trace
1372 experiment is running. */
1373 PACKET_EnableDisableTracepoints_feature
,
1375 /* Support for collecting strings using the tracenz bytecode. */
1376 PACKET_tracenz_feature
,
1378 /* Support for continuing to run a trace experiment while GDB is
1380 PACKET_DisconnectedTracing_feature
,
1382 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1383 PACKET_augmented_libraries_svr4_read_feature
,
1385 /* Support for the qXfer:btrace-conf:read packet. */
1386 PACKET_qXfer_btrace_conf
,
1388 /* Support for the Qbtrace-conf:bts:size packet. */
1389 PACKET_Qbtrace_conf_bts_size
,
1391 /* Support for swbreak+ feature. */
1392 PACKET_swbreak_feature
,
1394 /* Support for hwbreak+ feature. */
1395 PACKET_hwbreak_feature
,
1397 /* Support for fork events. */
1398 PACKET_fork_event_feature
,
1400 /* Support for vfork events. */
1401 PACKET_vfork_event_feature
,
1403 /* Support for the Qbtrace-conf:pt:size packet. */
1404 PACKET_Qbtrace_conf_pt_size
,
1409 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1411 /* Returns the packet's corresponding "set remote foo-packet" command
1412 state. See struct packet_config for more details. */
1414 static enum auto_boolean
1415 packet_set_cmd_state (int packet
)
1417 return remote_protocol_packets
[packet
].detect
;
1420 /* Returns whether a given packet or feature is supported. This takes
1421 into account the state of the corresponding "set remote foo-packet"
1422 command, which may be used to bypass auto-detection. */
1424 static enum packet_support
1425 packet_config_support (struct packet_config
*config
)
1427 switch (config
->detect
)
1429 case AUTO_BOOLEAN_TRUE
:
1430 return PACKET_ENABLE
;
1431 case AUTO_BOOLEAN_FALSE
:
1432 return PACKET_DISABLE
;
1433 case AUTO_BOOLEAN_AUTO
:
1434 return config
->support
;
1436 gdb_assert_not_reached (_("bad switch"));
1440 /* Same as packet_config_support, but takes the packet's enum value as
1443 static enum packet_support
1444 packet_support (int packet
)
1446 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1448 return packet_config_support (config
);
1452 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1453 struct cmd_list_element
*c
,
1456 struct packet_config
*packet
;
1458 for (packet
= remote_protocol_packets
;
1459 packet
< &remote_protocol_packets
[PACKET_MAX
];
1462 if (&packet
->detect
== c
->var
)
1464 show_packet_config_cmd (packet
);
1468 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1472 /* Should we try one of the 'Z' requests? */
1476 Z_PACKET_SOFTWARE_BP
,
1477 Z_PACKET_HARDWARE_BP
,
1484 /* For compatibility with older distributions. Provide a ``set remote
1485 Z-packet ...'' command that updates all the Z packet types. */
1487 static enum auto_boolean remote_Z_packet_detect
;
1490 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1491 struct cmd_list_element
*c
)
1495 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1496 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1500 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1501 struct cmd_list_element
*c
,
1506 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1508 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1512 /* Returns true if the multi-process extensions are in effect. */
1515 remote_multi_process_p (struct remote_state
*rs
)
1517 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1520 /* Returns true if fork events are supported. */
1523 remote_fork_event_p (struct remote_state
*rs
)
1525 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1528 /* Returns true if vfork events are supported. */
1531 remote_vfork_event_p (struct remote_state
*rs
)
1533 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1536 /* Insert fork catchpoint target routine. If fork events are enabled
1537 then return success, nothing more to do. */
1540 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1542 struct remote_state
*rs
= get_remote_state ();
1544 return !remote_fork_event_p (rs
);
1547 /* Remove fork catchpoint target routine. Nothing to do, just
1551 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1556 /* Insert vfork catchpoint target routine. If vfork events are enabled
1557 then return success, nothing more to do. */
1560 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1562 struct remote_state
*rs
= get_remote_state ();
1564 return !remote_vfork_event_p (rs
);
1567 /* Remove vfork catchpoint target routine. Nothing to do, just
1571 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1576 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1577 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1578 static struct async_signal_handler
*async_sigint_remote_token
;
1581 /* Asynchronous signal handle registered as event loop source for
1582 when we have pending events ready to be passed to the core. */
1584 static struct async_event_handler
*remote_async_inferior_event_token
;
1588 static ptid_t magic_null_ptid
;
1589 static ptid_t not_sent_ptid
;
1590 static ptid_t any_thread_ptid
;
1592 /* Find out if the stub attached to PID (and hence GDB should offer to
1593 detach instead of killing it when bailing out). */
1596 remote_query_attached (int pid
)
1598 struct remote_state
*rs
= get_remote_state ();
1599 size_t size
= get_remote_packet_size ();
1601 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1604 if (remote_multi_process_p (rs
))
1605 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1607 xsnprintf (rs
->buf
, size
, "qAttached");
1610 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1612 switch (packet_ok (rs
->buf
,
1613 &remote_protocol_packets
[PACKET_qAttached
]))
1616 if (strcmp (rs
->buf
, "1") == 0)
1620 warning (_("Remote failure reply: %s"), rs
->buf
);
1622 case PACKET_UNKNOWN
:
1629 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1630 has been invented by GDB, instead of reported by the target. Since
1631 we can be connected to a remote system before before knowing about
1632 any inferior, mark the target with execution when we find the first
1633 inferior. If ATTACHED is 1, then we had just attached to this
1634 inferior. If it is 0, then we just created this inferior. If it
1635 is -1, then try querying the remote stub to find out if it had
1636 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1637 attempt to open this inferior's executable as the main executable
1638 if no main executable is open already. */
1640 static struct inferior
*
1641 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1644 struct inferior
*inf
;
1646 /* Check whether this process we're learning about is to be
1647 considered attached, or if is to be considered to have been
1648 spawned by the stub. */
1650 attached
= remote_query_attached (pid
);
1652 if (gdbarch_has_global_solist (target_gdbarch ()))
1654 /* If the target shares code across all inferiors, then every
1655 attach adds a new inferior. */
1656 inf
= add_inferior (pid
);
1658 /* ... and every inferior is bound to the same program space.
1659 However, each inferior may still have its own address
1661 inf
->aspace
= maybe_new_address_space ();
1662 inf
->pspace
= current_program_space
;
1666 /* In the traditional debugging scenario, there's a 1-1 match
1667 between program/address spaces. We simply bind the inferior
1668 to the program space's address space. */
1669 inf
= current_inferior ();
1670 inferior_appeared (inf
, pid
);
1673 inf
->attach_flag
= attached
;
1674 inf
->fake_pid_p
= fake_pid_p
;
1676 /* If no main executable is currently open then attempt to
1677 open the file that was executed to create this inferior. */
1678 if (try_open_exec
&& get_exec_file (0) == NULL
)
1679 exec_file_locate_attach (pid
, 1);
1684 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1685 according to RUNNING. */
1688 remote_add_thread (ptid_t ptid
, int running
)
1690 struct remote_state
*rs
= get_remote_state ();
1692 /* GDB historically didn't pull threads in the initial connection
1693 setup. If the remote target doesn't even have a concept of
1694 threads (e.g., a bare-metal target), even if internally we
1695 consider that a single-threaded target, mentioning a new thread
1696 might be confusing to the user. Be silent then, preserving the
1697 age old behavior. */
1698 if (rs
->starting_up
)
1699 add_thread_silent (ptid
);
1703 set_executing (ptid
, running
);
1704 set_running (ptid
, running
);
1707 /* Come here when we learn about a thread id from the remote target.
1708 It may be the first time we hear about such thread, so take the
1709 opportunity to add it to GDB's thread list. In case this is the
1710 first time we're noticing its corresponding inferior, add it to
1711 GDB's inferior list as well. */
1714 remote_notice_new_inferior (ptid_t currthread
, int running
)
1716 /* If this is a new thread, add it to GDB's thread list.
1717 If we leave it up to WFI to do this, bad things will happen. */
1719 if (in_thread_list (currthread
) && is_exited (currthread
))
1721 /* We're seeing an event on a thread id we knew had exited.
1722 This has to be a new thread reusing the old id. Add it. */
1723 remote_add_thread (currthread
, running
);
1727 if (!in_thread_list (currthread
))
1729 struct inferior
*inf
= NULL
;
1730 int pid
= ptid_get_pid (currthread
);
1732 if (ptid_is_pid (inferior_ptid
)
1733 && pid
== ptid_get_pid (inferior_ptid
))
1735 /* inferior_ptid has no thread member yet. This can happen
1736 with the vAttach -> remote_wait,"TAAthread:" path if the
1737 stub doesn't support qC. This is the first stop reported
1738 after an attach, so this is the main thread. Update the
1739 ptid in the thread list. */
1740 if (in_thread_list (pid_to_ptid (pid
)))
1741 thread_change_ptid (inferior_ptid
, currthread
);
1744 remote_add_thread (currthread
, running
);
1745 inferior_ptid
= currthread
;
1750 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1752 /* inferior_ptid is not set yet. This can happen with the
1753 vRun -> remote_wait,"TAAthread:" path if the stub
1754 doesn't support qC. This is the first stop reported
1755 after an attach, so this is the main thread. Update the
1756 ptid in the thread list. */
1757 thread_change_ptid (inferior_ptid
, currthread
);
1761 /* When connecting to a target remote, or to a target
1762 extended-remote which already was debugging an inferior, we
1763 may not know about it yet. Add it before adding its child
1764 thread, so notifications are emitted in a sensible order. */
1765 if (!in_inferior_list (ptid_get_pid (currthread
)))
1767 struct remote_state
*rs
= get_remote_state ();
1768 int fake_pid_p
= !remote_multi_process_p (rs
);
1770 inf
= remote_add_inferior (fake_pid_p
,
1771 ptid_get_pid (currthread
), -1, 1);
1774 /* This is really a new thread. Add it. */
1775 remote_add_thread (currthread
, running
);
1777 /* If we found a new inferior, let the common code do whatever
1778 it needs to with it (e.g., read shared libraries, insert
1779 breakpoints), unless we're just setting up an all-stop
1783 struct remote_state
*rs
= get_remote_state ();
1785 if (non_stop
|| !rs
->starting_up
)
1786 notice_new_inferior (currthread
, running
, 0);
1791 /* Return the private thread data, creating it if necessary. */
1793 static struct private_thread_info
*
1794 demand_private_info (ptid_t ptid
)
1796 struct thread_info
*info
= find_thread_ptid (ptid
);
1802 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1803 info
->private_dtor
= free_private_thread_info
;
1804 info
->priv
->core
= -1;
1805 info
->priv
->extra
= 0;
1811 /* Call this function as a result of
1812 1) A halt indication (T packet) containing a thread id
1813 2) A direct query of currthread
1814 3) Successful execution of set thread */
1817 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1819 rs
->general_thread
= currthread
;
1822 /* If 'QPassSignals' is supported, tell the remote stub what signals
1823 it can simply pass through to the inferior without reporting. */
1826 remote_pass_signals (struct target_ops
*self
,
1827 int numsigs
, unsigned char *pass_signals
)
1829 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1831 char *pass_packet
, *p
;
1833 struct remote_state
*rs
= get_remote_state ();
1835 gdb_assert (numsigs
< 256);
1836 for (i
= 0; i
< numsigs
; i
++)
1838 if (pass_signals
[i
])
1841 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1842 strcpy (pass_packet
, "QPassSignals:");
1843 p
= pass_packet
+ strlen (pass_packet
);
1844 for (i
= 0; i
< numsigs
; i
++)
1846 if (pass_signals
[i
])
1849 *p
++ = tohex (i
>> 4);
1850 *p
++ = tohex (i
& 15);
1859 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1861 putpkt (pass_packet
);
1862 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1863 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1864 if (rs
->last_pass_packet
)
1865 xfree (rs
->last_pass_packet
);
1866 rs
->last_pass_packet
= pass_packet
;
1869 xfree (pass_packet
);
1873 /* If 'QProgramSignals' is supported, tell the remote stub what
1874 signals it should pass through to the inferior when detaching. */
1877 remote_program_signals (struct target_ops
*self
,
1878 int numsigs
, unsigned char *signals
)
1880 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1884 struct remote_state
*rs
= get_remote_state ();
1886 gdb_assert (numsigs
< 256);
1887 for (i
= 0; i
< numsigs
; i
++)
1892 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1893 strcpy (packet
, "QProgramSignals:");
1894 p
= packet
+ strlen (packet
);
1895 for (i
= 0; i
< numsigs
; i
++)
1897 if (signal_pass_state (i
))
1900 *p
++ = tohex (i
>> 4);
1901 *p
++ = tohex (i
& 15);
1910 if (!rs
->last_program_signals_packet
1911 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1914 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1915 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1916 xfree (rs
->last_program_signals_packet
);
1917 rs
->last_program_signals_packet
= packet
;
1924 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1925 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1926 thread. If GEN is set, set the general thread, if not, then set
1927 the step/continue thread. */
1929 set_thread (struct ptid ptid
, int gen
)
1931 struct remote_state
*rs
= get_remote_state ();
1932 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1933 char *buf
= rs
->buf
;
1934 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1936 if (ptid_equal (state
, ptid
))
1940 *buf
++ = gen
? 'g' : 'c';
1941 if (ptid_equal (ptid
, magic_null_ptid
))
1942 xsnprintf (buf
, endbuf
- buf
, "0");
1943 else if (ptid_equal (ptid
, any_thread_ptid
))
1944 xsnprintf (buf
, endbuf
- buf
, "0");
1945 else if (ptid_equal (ptid
, minus_one_ptid
))
1946 xsnprintf (buf
, endbuf
- buf
, "-1");
1948 write_ptid (buf
, endbuf
, ptid
);
1950 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1952 rs
->general_thread
= ptid
;
1954 rs
->continue_thread
= ptid
;
1958 set_general_thread (struct ptid ptid
)
1960 set_thread (ptid
, 1);
1964 set_continue_thread (struct ptid ptid
)
1966 set_thread (ptid
, 0);
1969 /* Change the remote current process. Which thread within the process
1970 ends up selected isn't important, as long as it is the same process
1971 as what INFERIOR_PTID points to.
1973 This comes from that fact that there is no explicit notion of
1974 "selected process" in the protocol. The selected process for
1975 general operations is the process the selected general thread
1979 set_general_process (void)
1981 struct remote_state
*rs
= get_remote_state ();
1983 /* If the remote can't handle multiple processes, don't bother. */
1984 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1987 /* We only need to change the remote current thread if it's pointing
1988 at some other process. */
1989 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1990 set_general_thread (inferior_ptid
);
1994 /* Return nonzero if this is the main thread that we made up ourselves
1995 to model non-threaded targets as single-threaded. */
1998 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2000 struct remote_state
*rs
= get_remote_state ();
2003 if (ptid_equal (ptid
, magic_null_ptid
))
2004 /* The main thread is always alive. */
2007 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2008 /* The main thread is always alive. This can happen after a
2009 vAttach, if the remote side doesn't support
2016 /* Return nonzero if the thread PTID is still alive on the remote
2020 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2022 struct remote_state
*rs
= get_remote_state ();
2025 /* Check if this is a thread that we made up ourselves to model
2026 non-threaded targets as single-threaded. */
2027 if (remote_thread_always_alive (ops
, ptid
))
2031 endp
= rs
->buf
+ get_remote_packet_size ();
2034 write_ptid (p
, endp
, ptid
);
2037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2038 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2041 /* About these extended threadlist and threadinfo packets. They are
2042 variable length packets but, the fields within them are often fixed
2043 length. They are redundent enough to send over UDP as is the
2044 remote protocol in general. There is a matching unit test module
2047 /* WARNING: This threadref data structure comes from the remote O.S.,
2048 libstub protocol encoding, and remote.c. It is not particularly
2051 /* Right now, the internal structure is int. We want it to be bigger.
2052 Plan to fix this. */
2054 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2056 /* gdb_ext_thread_info is an internal GDB data structure which is
2057 equivalent to the reply of the remote threadinfo packet. */
2059 struct gdb_ext_thread_info
2061 threadref threadid
; /* External form of thread reference. */
2062 int active
; /* Has state interesting to GDB?
2064 char display
[256]; /* Brief state display, name,
2065 blocked/suspended. */
2066 char shortname
[32]; /* To be used to name threads. */
2067 char more_display
[256]; /* Long info, statistics, queue depth,
2071 /* The volume of remote transfers can be limited by submitting
2072 a mask containing bits specifying the desired information.
2073 Use a union of these values as the 'selection' parameter to
2074 get_thread_info. FIXME: Make these TAG names more thread specific. */
2076 #define TAG_THREADID 1
2077 #define TAG_EXISTS 2
2078 #define TAG_DISPLAY 4
2079 #define TAG_THREADNAME 8
2080 #define TAG_MOREDISPLAY 16
2082 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2084 static char *unpack_nibble (char *buf
, int *val
);
2086 static char *unpack_byte (char *buf
, int *value
);
2088 static char *pack_int (char *buf
, int value
);
2090 static char *unpack_int (char *buf
, int *value
);
2092 static char *unpack_string (char *src
, char *dest
, int length
);
2094 static char *pack_threadid (char *pkt
, threadref
*id
);
2096 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2098 void int_to_threadref (threadref
*id
, int value
);
2100 static int threadref_to_int (threadref
*ref
);
2102 static void copy_threadref (threadref
*dest
, threadref
*src
);
2104 static int threadmatch (threadref
*dest
, threadref
*src
);
2106 static char *pack_threadinfo_request (char *pkt
, int mode
,
2109 static int remote_unpack_thread_info_response (char *pkt
,
2110 threadref
*expectedref
,
2111 struct gdb_ext_thread_info
2115 static int remote_get_threadinfo (threadref
*threadid
,
2116 int fieldset
, /*TAG mask */
2117 struct gdb_ext_thread_info
*info
);
2119 static char *pack_threadlist_request (char *pkt
, int startflag
,
2121 threadref
*nextthread
);
2123 static int parse_threadlist_response (char *pkt
,
2125 threadref
*original_echo
,
2126 threadref
*resultlist
,
2129 static int remote_get_threadlist (int startflag
,
2130 threadref
*nextthread
,
2134 threadref
*threadlist
);
2136 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2138 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2139 void *context
, int looplimit
);
2141 static int remote_newthread_step (threadref
*ref
, void *context
);
2144 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2145 buffer we're allowed to write to. Returns
2146 BUF+CHARACTERS_WRITTEN. */
2149 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2152 struct remote_state
*rs
= get_remote_state ();
2154 if (remote_multi_process_p (rs
))
2156 pid
= ptid_get_pid (ptid
);
2158 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2160 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2162 tid
= ptid_get_lwp (ptid
);
2164 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2166 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2171 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2172 passed the last parsed char. Returns null_ptid on error. */
2175 read_ptid (char *buf
, char **obuf
)
2179 ULONGEST pid
= 0, tid
= 0;
2183 /* Multi-process ptid. */
2184 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2186 error (_("invalid remote ptid: %s"), p
);
2189 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2192 return ptid_build (pid
, tid
, 0);
2195 /* No multi-process. Just a tid. */
2196 pp
= unpack_varlen_hex (p
, &tid
);
2198 /* Return null_ptid when no thread id is found. */
2206 /* Since the stub is not sending a process id, then default to
2207 what's in inferior_ptid, unless it's null at this point. If so,
2208 then since there's no way to know the pid of the reported
2209 threads, use the magic number. */
2210 if (ptid_equal (inferior_ptid
, null_ptid
))
2211 pid
= ptid_get_pid (magic_null_ptid
);
2213 pid
= ptid_get_pid (inferior_ptid
);
2217 return ptid_build (pid
, tid
, 0);
2223 if (ch
>= 'a' && ch
<= 'f')
2224 return ch
- 'a' + 10;
2225 if (ch
>= '0' && ch
<= '9')
2227 if (ch
>= 'A' && ch
<= 'F')
2228 return ch
- 'A' + 10;
2233 stub_unpack_int (char *buff
, int fieldlength
)
2240 nibble
= stubhex (*buff
++);
2244 retval
= retval
<< 4;
2250 unpack_nibble (char *buf
, int *val
)
2252 *val
= fromhex (*buf
++);
2257 unpack_byte (char *buf
, int *value
)
2259 *value
= stub_unpack_int (buf
, 2);
2264 pack_int (char *buf
, int value
)
2266 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2267 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2268 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2269 buf
= pack_hex_byte (buf
, (value
& 0xff));
2274 unpack_int (char *buf
, int *value
)
2276 *value
= stub_unpack_int (buf
, 8);
2280 #if 0 /* Currently unused, uncomment when needed. */
2281 static char *pack_string (char *pkt
, char *string
);
2284 pack_string (char *pkt
, char *string
)
2289 len
= strlen (string
);
2291 len
= 200; /* Bigger than most GDB packets, junk??? */
2292 pkt
= pack_hex_byte (pkt
, len
);
2296 if ((ch
== '\0') || (ch
== '#'))
2297 ch
= '*'; /* Protect encapsulation. */
2302 #endif /* 0 (unused) */
2305 unpack_string (char *src
, char *dest
, int length
)
2314 pack_threadid (char *pkt
, threadref
*id
)
2317 unsigned char *altid
;
2319 altid
= (unsigned char *) id
;
2320 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2322 pkt
= pack_hex_byte (pkt
, *altid
++);
2328 unpack_threadid (char *inbuf
, threadref
*id
)
2331 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2334 altref
= (char *) id
;
2336 while (inbuf
< limit
)
2338 x
= stubhex (*inbuf
++);
2339 y
= stubhex (*inbuf
++);
2340 *altref
++ = (x
<< 4) | y
;
2345 /* Externally, threadrefs are 64 bits but internally, they are still
2346 ints. This is due to a mismatch of specifications. We would like
2347 to use 64bit thread references internally. This is an adapter
2351 int_to_threadref (threadref
*id
, int value
)
2353 unsigned char *scan
;
2355 scan
= (unsigned char *) id
;
2361 *scan
++ = (value
>> 24) & 0xff;
2362 *scan
++ = (value
>> 16) & 0xff;
2363 *scan
++ = (value
>> 8) & 0xff;
2364 *scan
++ = (value
& 0xff);
2368 threadref_to_int (threadref
*ref
)
2371 unsigned char *scan
;
2377 value
= (value
<< 8) | ((*scan
++) & 0xff);
2382 copy_threadref (threadref
*dest
, threadref
*src
)
2385 unsigned char *csrc
, *cdest
;
2387 csrc
= (unsigned char *) src
;
2388 cdest
= (unsigned char *) dest
;
2395 threadmatch (threadref
*dest
, threadref
*src
)
2397 /* Things are broken right now, so just assume we got a match. */
2399 unsigned char *srcp
, *destp
;
2401 srcp
= (char *) src
;
2402 destp
= (char *) dest
;
2406 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2413 threadid:1, # always request threadid
2420 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2423 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2425 *pkt
++ = 'q'; /* Info Query */
2426 *pkt
++ = 'P'; /* process or thread info */
2427 pkt
= pack_int (pkt
, mode
); /* mode */
2428 pkt
= pack_threadid (pkt
, id
); /* threadid */
2429 *pkt
= '\0'; /* terminate */
2433 /* These values tag the fields in a thread info response packet. */
2434 /* Tagging the fields allows us to request specific fields and to
2435 add more fields as time goes by. */
2437 #define TAG_THREADID 1 /* Echo the thread identifier. */
2438 #define TAG_EXISTS 2 /* Is this process defined enough to
2439 fetch registers and its stack? */
2440 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2441 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2442 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2446 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2447 struct gdb_ext_thread_info
*info
)
2449 struct remote_state
*rs
= get_remote_state ();
2453 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2456 /* info->threadid = 0; FIXME: implement zero_threadref. */
2458 info
->display
[0] = '\0';
2459 info
->shortname
[0] = '\0';
2460 info
->more_display
[0] = '\0';
2462 /* Assume the characters indicating the packet type have been
2464 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2465 pkt
= unpack_threadid (pkt
, &ref
);
2468 warning (_("Incomplete response to threadinfo request."));
2469 if (!threadmatch (&ref
, expectedref
))
2470 { /* This is an answer to a different request. */
2471 warning (_("ERROR RMT Thread info mismatch."));
2474 copy_threadref (&info
->threadid
, &ref
);
2476 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2478 /* Packets are terminated with nulls. */
2479 while ((pkt
< limit
) && mask
&& *pkt
)
2481 pkt
= unpack_int (pkt
, &tag
); /* tag */
2482 pkt
= unpack_byte (pkt
, &length
); /* length */
2483 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2485 warning (_("ERROR RMT: threadinfo tag mismatch."));
2489 if (tag
== TAG_THREADID
)
2493 warning (_("ERROR RMT: length of threadid is not 16."));
2497 pkt
= unpack_threadid (pkt
, &ref
);
2498 mask
= mask
& ~TAG_THREADID
;
2501 if (tag
== TAG_EXISTS
)
2503 info
->active
= stub_unpack_int (pkt
, length
);
2505 mask
= mask
& ~(TAG_EXISTS
);
2508 warning (_("ERROR RMT: 'exists' length too long."));
2514 if (tag
== TAG_THREADNAME
)
2516 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2517 mask
= mask
& ~TAG_THREADNAME
;
2520 if (tag
== TAG_DISPLAY
)
2522 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2523 mask
= mask
& ~TAG_DISPLAY
;
2526 if (tag
== TAG_MOREDISPLAY
)
2528 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2529 mask
= mask
& ~TAG_MOREDISPLAY
;
2532 warning (_("ERROR RMT: unknown thread info tag."));
2533 break; /* Not a tag we know about. */
2539 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2540 struct gdb_ext_thread_info
*info
)
2542 struct remote_state
*rs
= get_remote_state ();
2545 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2547 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2549 if (rs
->buf
[0] == '\0')
2552 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2557 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2560 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2561 threadref
*nextthread
)
2563 *pkt
++ = 'q'; /* info query packet */
2564 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2565 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2566 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2567 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2572 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2575 parse_threadlist_response (char *pkt
, int result_limit
,
2576 threadref
*original_echo
, threadref
*resultlist
,
2579 struct remote_state
*rs
= get_remote_state ();
2581 int count
, resultcount
, done
;
2584 /* Assume the 'q' and 'M chars have been stripped. */
2585 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2586 /* done parse past here */
2587 pkt
= unpack_byte (pkt
, &count
); /* count field */
2588 pkt
= unpack_nibble (pkt
, &done
);
2589 /* The first threadid is the argument threadid. */
2590 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2591 while ((count
-- > 0) && (pkt
< limit
))
2593 pkt
= unpack_threadid (pkt
, resultlist
++);
2594 if (resultcount
++ >= result_limit
)
2602 /* Fetch the next batch of threads from the remote. Returns -1 if the
2603 qL packet is not supported, 0 on error and 1 on success. */
2606 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2607 int *done
, int *result_count
, threadref
*threadlist
)
2609 struct remote_state
*rs
= get_remote_state ();
2612 /* Trancate result limit to be smaller than the packet size. */
2613 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2614 >= get_remote_packet_size ())
2615 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2617 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2619 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2620 if (*rs
->buf
== '\0')
2622 /* Packet not supported. */
2627 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2628 &rs
->echo_nextthread
, threadlist
, done
);
2630 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2632 /* FIXME: This is a good reason to drop the packet. */
2633 /* Possably, there is a duplicate response. */
2635 retransmit immediatly - race conditions
2636 retransmit after timeout - yes
2638 wait for packet, then exit
2640 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2641 return 0; /* I choose simply exiting. */
2643 if (*result_count
<= 0)
2647 warning (_("RMT ERROR : failed to get remote thread list."));
2650 return result
; /* break; */
2652 if (*result_count
> result_limit
)
2655 warning (_("RMT ERROR: threadlist response longer than requested."));
2661 /* Fetch the list of remote threads, with the qL packet, and call
2662 STEPFUNCTION for each thread found. Stops iterating and returns 1
2663 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2664 STEPFUNCTION returns false. If the packet is not supported,
2668 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2671 struct remote_state
*rs
= get_remote_state ();
2672 int done
, i
, result_count
;
2680 if (loopcount
++ > looplimit
)
2683 warning (_("Remote fetch threadlist -infinite loop-."));
2686 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2687 MAXTHREADLISTRESULTS
,
2688 &done
, &result_count
,
2689 rs
->resultthreadlist
);
2692 /* Clear for later iterations. */
2694 /* Setup to resume next batch of thread references, set nextthread. */
2695 if (result_count
>= 1)
2696 copy_threadref (&rs
->nextthread
,
2697 &rs
->resultthreadlist
[result_count
- 1]);
2699 while (result_count
--)
2701 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2711 /* A thread found on the remote target. */
2713 typedef struct thread_item
2715 /* The thread's PTID. */
2718 /* The thread's extra info. May be NULL. */
2721 /* The core the thread was running on. -1 if not known. */
2724 DEF_VEC_O(thread_item_t
);
2726 /* Context passed around to the various methods listing remote
2727 threads. As new threads are found, they're added to the ITEMS
2730 struct threads_listing_context
2732 /* The threads found on the remote target. */
2733 VEC (thread_item_t
) *items
;
2736 /* Discard the contents of the constructed thread listing context. */
2739 clear_threads_listing_context (void *p
)
2741 struct threads_listing_context
*context
= p
;
2743 struct thread_item
*item
;
2745 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2746 xfree (item
->extra
);
2748 VEC_free (thread_item_t
, context
->items
);
2751 /* Remove the thread specified as the related_pid field of WS
2752 from the CONTEXT list. */
2755 threads_listing_context_remove (struct target_waitstatus
*ws
,
2756 struct threads_listing_context
*context
)
2758 struct thread_item
*item
;
2760 ptid_t child_ptid
= ws
->value
.related_pid
;
2762 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2764 if (ptid_equal (item
->ptid
, child_ptid
))
2766 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2773 remote_newthread_step (threadref
*ref
, void *data
)
2775 struct threads_listing_context
*context
= data
;
2776 struct thread_item item
;
2777 int pid
= ptid_get_pid (inferior_ptid
);
2779 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2783 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2785 return 1; /* continue iterator */
2788 #define CRAZY_MAX_THREADS 1000
2791 remote_current_thread (ptid_t oldpid
)
2793 struct remote_state
*rs
= get_remote_state ();
2796 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2797 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2802 result
= read_ptid (&rs
->buf
[2], &obuf
);
2803 if (*obuf
!= '\0' && remote_debug
)
2804 fprintf_unfiltered (gdb_stdlog
,
2805 "warning: garbage in qC reply\n");
2813 /* List remote threads using the deprecated qL packet. */
2816 remote_get_threads_with_ql (struct target_ops
*ops
,
2817 struct threads_listing_context
*context
)
2819 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2820 CRAZY_MAX_THREADS
) >= 0)
2826 #if defined(HAVE_LIBEXPAT)
2829 start_thread (struct gdb_xml_parser
*parser
,
2830 const struct gdb_xml_element
*element
,
2831 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2833 struct threads_listing_context
*data
= user_data
;
2835 struct thread_item item
;
2837 struct gdb_xml_value
*attr
;
2839 id
= xml_find_attribute (attributes
, "id")->value
;
2840 item
.ptid
= read_ptid (id
, NULL
);
2842 attr
= xml_find_attribute (attributes
, "core");
2844 item
.core
= *(ULONGEST
*) attr
->value
;
2850 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2854 end_thread (struct gdb_xml_parser
*parser
,
2855 const struct gdb_xml_element
*element
,
2856 void *user_data
, const char *body_text
)
2858 struct threads_listing_context
*data
= user_data
;
2860 if (body_text
&& *body_text
)
2861 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2864 const struct gdb_xml_attribute thread_attributes
[] = {
2865 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2866 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2867 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2870 const struct gdb_xml_element thread_children
[] = {
2871 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2874 const struct gdb_xml_element threads_children
[] = {
2875 { "thread", thread_attributes
, thread_children
,
2876 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2877 start_thread
, end_thread
},
2878 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2881 const struct gdb_xml_element threads_elements
[] = {
2882 { "threads", NULL
, threads_children
,
2883 GDB_XML_EF_NONE
, NULL
, NULL
},
2884 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2889 /* List remote threads using qXfer:threads:read. */
2892 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2893 struct threads_listing_context
*context
)
2895 #if defined(HAVE_LIBEXPAT)
2896 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2898 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2899 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2901 if (xml
!= NULL
&& *xml
!= '\0')
2903 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2904 threads_elements
, xml
, context
);
2907 do_cleanups (back_to
);
2915 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2918 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2919 struct threads_listing_context
*context
)
2921 struct remote_state
*rs
= get_remote_state ();
2923 if (rs
->use_threadinfo_query
)
2927 putpkt ("qfThreadInfo");
2928 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2930 if (bufp
[0] != '\0') /* q packet recognized */
2932 while (*bufp
++ == 'm') /* reply contains one or more TID */
2936 struct thread_item item
;
2938 item
.ptid
= read_ptid (bufp
, &bufp
);
2942 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2944 while (*bufp
++ == ','); /* comma-separated list */
2945 putpkt ("qsThreadInfo");
2946 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2953 /* Packet not recognized. */
2954 rs
->use_threadinfo_query
= 0;
2961 /* Implement the to_update_thread_list function for the remote
2965 remote_update_thread_list (struct target_ops
*ops
)
2967 struct remote_state
*rs
= get_remote_state ();
2968 struct threads_listing_context context
;
2969 struct cleanup
*old_chain
;
2972 context
.items
= NULL
;
2973 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2975 /* We have a few different mechanisms to fetch the thread list. Try
2976 them all, starting with the most preferred one first, falling
2977 back to older methods. */
2978 if (remote_get_threads_with_qxfer (ops
, &context
)
2979 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2980 || remote_get_threads_with_ql (ops
, &context
))
2983 struct thread_item
*item
;
2984 struct thread_info
*tp
, *tmp
;
2988 if (VEC_empty (thread_item_t
, context
.items
)
2989 && remote_thread_always_alive (ops
, inferior_ptid
))
2991 /* Some targets don't really support threads, but still
2992 reply an (empty) thread list in response to the thread
2993 listing packets, instead of replying "packet not
2994 supported". Exit early so we don't delete the main
2996 do_cleanups (old_chain
);
3000 /* CONTEXT now holds the current thread list on the remote
3001 target end. Delete GDB-side threads no longer found on the
3003 ALL_THREADS_SAFE (tp
, tmp
)
3006 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3009 if (ptid_equal (item
->ptid
, tp
->ptid
))
3013 if (i
== VEC_length (thread_item_t
, context
.items
))
3016 delete_thread (tp
->ptid
);
3020 /* Remove any unreported fork child threads from CONTEXT so
3021 that we don't interfere with follow fork, which is where
3022 creation of such threads is handled. */
3023 remove_new_fork_children (&context
);
3025 /* And now add threads we don't know about yet to our list. */
3027 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3030 if (!ptid_equal (item
->ptid
, null_ptid
))
3032 struct private_thread_info
*info
;
3033 /* In non-stop mode, we assume new found threads are
3034 running until proven otherwise with a stop reply. In
3035 all-stop, we can only get here if all threads are
3037 int running
= non_stop
? 1 : 0;
3039 remote_notice_new_inferior (item
->ptid
, running
);
3041 info
= demand_private_info (item
->ptid
);
3042 info
->core
= item
->core
;
3043 info
->extra
= item
->extra
;
3051 /* If no thread listing method is supported, then query whether
3052 each known thread is alive, one by one, with the T packet.
3053 If the target doesn't support threads at all, then this is a
3054 no-op. See remote_thread_alive. */
3058 do_cleanups (old_chain
);
3062 * Collect a descriptive string about the given thread.
3063 * The target may say anything it wants to about the thread
3064 * (typically info about its blocked / runnable state, name, etc.).
3065 * This string will appear in the info threads display.
3067 * Optional: targets are not required to implement this function.
3071 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3073 struct remote_state
*rs
= get_remote_state ();
3077 struct gdb_ext_thread_info threadinfo
;
3078 static char display_buf
[100]; /* arbitrary... */
3079 int n
= 0; /* position in display_buf */
3081 if (rs
->remote_desc
== 0) /* paranoia */
3082 internal_error (__FILE__
, __LINE__
,
3083 _("remote_threads_extra_info"));
3085 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3086 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3087 /* This is the main thread which was added by GDB. The remote
3088 server doesn't know about it. */
3091 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3093 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3095 if (info
&& info
->priv
)
3096 return info
->priv
->extra
;
3101 if (rs
->use_threadextra_query
)
3104 char *endb
= rs
->buf
+ get_remote_packet_size ();
3106 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3108 write_ptid (b
, endb
, tp
->ptid
);
3111 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3112 if (rs
->buf
[0] != 0)
3114 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3115 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3116 display_buf
[result
] = '\0';
3121 /* If the above query fails, fall back to the old method. */
3122 rs
->use_threadextra_query
= 0;
3123 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3124 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3125 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3126 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3127 if (threadinfo
.active
)
3129 if (*threadinfo
.shortname
)
3130 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3131 " Name: %s,", threadinfo
.shortname
);
3132 if (*threadinfo
.display
)
3133 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3134 " State: %s,", threadinfo
.display
);
3135 if (*threadinfo
.more_display
)
3136 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3137 " Priority: %s", threadinfo
.more_display
);
3141 /* For purely cosmetic reasons, clear up trailing commas. */
3142 if (',' == display_buf
[n
-1])
3143 display_buf
[n
-1] = ' ';
3152 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3153 struct static_tracepoint_marker
*marker
)
3155 struct remote_state
*rs
= get_remote_state ();
3158 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3160 p
+= hexnumstr (p
, addr
);
3162 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3166 error (_("Remote failure reply: %s"), p
);
3170 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3177 static VEC(static_tracepoint_marker_p
) *
3178 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3181 struct remote_state
*rs
= get_remote_state ();
3182 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3183 struct static_tracepoint_marker
*marker
= NULL
;
3184 struct cleanup
*old_chain
;
3187 /* Ask for a first packet of static tracepoint marker
3190 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3193 error (_("Remote failure reply: %s"), p
);
3195 old_chain
= make_cleanup (free_current_marker
, &marker
);
3200 marker
= XCNEW (struct static_tracepoint_marker
);
3204 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3206 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3208 VEC_safe_push (static_tracepoint_marker_p
,
3214 release_static_tracepoint_marker (marker
);
3215 memset (marker
, 0, sizeof (*marker
));
3218 while (*p
++ == ','); /* comma-separated list */
3219 /* Ask for another packet of static tracepoint definition. */
3221 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3225 do_cleanups (old_chain
);
3230 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3233 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3235 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3239 /* Restart the remote side; this is an extended protocol operation. */
3242 extended_remote_restart (void)
3244 struct remote_state
*rs
= get_remote_state ();
3246 /* Send the restart command; for reasons I don't understand the
3247 remote side really expects a number after the "R". */
3248 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3251 remote_fileio_reset ();
3254 /* Clean up connection to a remote debugger. */
3257 remote_close (struct target_ops
*self
)
3259 struct remote_state
*rs
= get_remote_state ();
3261 if (rs
->remote_desc
== NULL
)
3262 return; /* already closed */
3264 /* Make sure we leave stdin registered in the event loop, and we
3265 don't leave the async SIGINT signal handler installed. */
3266 remote_terminal_ours (self
);
3268 serial_close (rs
->remote_desc
);
3269 rs
->remote_desc
= NULL
;
3271 /* We don't have a connection to the remote stub anymore. Get rid
3272 of all the inferiors and their threads we were controlling.
3273 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3274 will be unable to find the thread corresponding to (pid, 0, 0). */
3275 inferior_ptid
= null_ptid
;
3276 discard_all_inferiors ();
3278 /* We are closing the remote target, so we should discard
3279 everything of this target. */
3280 discard_pending_stop_replies_in_queue (rs
);
3282 if (remote_async_inferior_event_token
)
3283 delete_async_event_handler (&remote_async_inferior_event_token
);
3285 remote_notif_state_xfree (rs
->notif_state
);
3287 trace_reset_local_state ();
3290 /* Query the remote side for the text, data and bss offsets. */
3295 struct remote_state
*rs
= get_remote_state ();
3298 int lose
, num_segments
= 0, do_sections
, do_segments
;
3299 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3300 struct section_offsets
*offs
;
3301 struct symfile_segment_data
*data
;
3303 if (symfile_objfile
== NULL
)
3306 putpkt ("qOffsets");
3307 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3310 if (buf
[0] == '\000')
3311 return; /* Return silently. Stub doesn't support
3315 warning (_("Remote failure reply: %s"), buf
);
3319 /* Pick up each field in turn. This used to be done with scanf, but
3320 scanf will make trouble if CORE_ADDR size doesn't match
3321 conversion directives correctly. The following code will work
3322 with any size of CORE_ADDR. */
3323 text_addr
= data_addr
= bss_addr
= 0;
3327 if (startswith (ptr
, "Text="))
3330 /* Don't use strtol, could lose on big values. */
3331 while (*ptr
&& *ptr
!= ';')
3332 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3334 if (startswith (ptr
, ";Data="))
3337 while (*ptr
&& *ptr
!= ';')
3338 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3343 if (!lose
&& startswith (ptr
, ";Bss="))
3346 while (*ptr
&& *ptr
!= ';')
3347 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3349 if (bss_addr
!= data_addr
)
3350 warning (_("Target reported unsupported offsets: %s"), buf
);
3355 else if (startswith (ptr
, "TextSeg="))
3358 /* Don't use strtol, could lose on big values. */
3359 while (*ptr
&& *ptr
!= ';')
3360 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3363 if (startswith (ptr
, ";DataSeg="))
3366 while (*ptr
&& *ptr
!= ';')
3367 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3375 error (_("Malformed response to offset query, %s"), buf
);
3376 else if (*ptr
!= '\0')
3377 warning (_("Target reported unsupported offsets: %s"), buf
);
3379 offs
= ((struct section_offsets
*)
3380 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3381 memcpy (offs
, symfile_objfile
->section_offsets
,
3382 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3384 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3385 do_segments
= (data
!= NULL
);
3386 do_sections
= num_segments
== 0;
3388 if (num_segments
> 0)
3390 segments
[0] = text_addr
;
3391 segments
[1] = data_addr
;
3393 /* If we have two segments, we can still try to relocate everything
3394 by assuming that the .text and .data offsets apply to the whole
3395 text and data segments. Convert the offsets given in the packet
3396 to base addresses for symfile_map_offsets_to_segments. */
3397 else if (data
&& data
->num_segments
== 2)
3399 segments
[0] = data
->segment_bases
[0] + text_addr
;
3400 segments
[1] = data
->segment_bases
[1] + data_addr
;
3403 /* If the object file has only one segment, assume that it is text
3404 rather than data; main programs with no writable data are rare,
3405 but programs with no code are useless. Of course the code might
3406 have ended up in the data segment... to detect that we would need
3407 the permissions here. */
3408 else if (data
&& data
->num_segments
== 1)
3410 segments
[0] = data
->segment_bases
[0] + text_addr
;
3413 /* There's no way to relocate by segment. */
3419 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3420 offs
, num_segments
, segments
);
3422 if (ret
== 0 && !do_sections
)
3423 error (_("Can not handle qOffsets TextSeg "
3424 "response with this symbol file"));
3431 free_symfile_segment_data (data
);
3435 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3437 /* This is a temporary kludge to force data and bss to use the
3438 same offsets because that's what nlmconv does now. The real
3439 solution requires changes to the stub and remote.c that I
3440 don't have time to do right now. */
3442 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3443 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3446 objfile_relocate (symfile_objfile
, offs
);
3449 /* Send interrupt_sequence to remote target. */
3451 send_interrupt_sequence (void)
3453 struct remote_state
*rs
= get_remote_state ();
3455 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3456 remote_serial_write ("\x03", 1);
3457 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3458 serial_send_break (rs
->remote_desc
);
3459 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3461 serial_send_break (rs
->remote_desc
);
3462 remote_serial_write ("g", 1);
3465 internal_error (__FILE__
, __LINE__
,
3466 _("Invalid value for interrupt_sequence_mode: %s."),
3467 interrupt_sequence_mode
);
3471 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3472 and extract the PTID. Returns NULL_PTID if not found. */
3475 stop_reply_extract_thread (char *stop_reply
)
3477 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3481 /* Txx r:val ; r:val (...) */
3484 /* Look for "register" named "thread". */
3489 p1
= strchr (p
, ':');
3493 if (strncmp (p
, "thread", p1
- p
) == 0)
3494 return read_ptid (++p1
, &p
);
3496 p1
= strchr (p
, ';');
3508 /* Determine the remote side's current thread. If we have a stop
3509 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3510 "thread" register we can extract the current thread from. If not,
3511 ask the remote which is the current thread with qC. The former
3512 method avoids a roundtrip. */
3515 get_current_thread (char *wait_status
)
3517 ptid_t ptid
= null_ptid
;
3519 /* Note we don't use remote_parse_stop_reply as that makes use of
3520 the target architecture, which we haven't yet fully determined at
3522 if (wait_status
!= NULL
)
3523 ptid
= stop_reply_extract_thread (wait_status
);
3524 if (ptid_equal (ptid
, null_ptid
))
3525 ptid
= remote_current_thread (inferior_ptid
);
3530 /* Query the remote target for which is the current thread/process,
3531 add it to our tables, and update INFERIOR_PTID. The caller is
3532 responsible for setting the state such that the remote end is ready
3533 to return the current thread.
3535 This function is called after handling the '?' or 'vRun' packets,
3536 whose response is a stop reply from which we can also try
3537 extracting the thread. If the target doesn't support the explicit
3538 qC query, we infer the current thread from that stop reply, passed
3539 in in WAIT_STATUS, which may be NULL. */
3542 add_current_inferior_and_thread (char *wait_status
)
3544 struct remote_state
*rs
= get_remote_state ();
3548 inferior_ptid
= null_ptid
;
3550 /* Now, if we have thread information, update inferior_ptid. */
3551 ptid
= get_current_thread (wait_status
);
3553 if (!ptid_equal (ptid
, null_ptid
))
3555 if (!remote_multi_process_p (rs
))
3558 inferior_ptid
= ptid
;
3562 /* Without this, some commands which require an active target
3563 (such as kill) won't work. This variable serves (at least)
3564 double duty as both the pid of the target process (if it has
3565 such), and as a flag indicating that a target is active. */
3566 inferior_ptid
= magic_null_ptid
;
3570 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3572 /* Add the main thread. */
3573 add_thread_silent (inferior_ptid
);
3576 /* Process all initial stop replies the remote side sent in response
3577 to the ? packet. These indicate threads that were already stopped
3578 on initial connection. We mark these threads as stopped and print
3579 their current frame before giving the user the prompt. */
3582 process_initial_stop_replies (void)
3584 int pending_stop_replies
= stop_reply_queue_length ();
3586 /* Consume the initial pending events. */
3587 while (pending_stop_replies
-- > 0)
3589 ptid_t waiton_ptid
= minus_one_ptid
;
3591 struct target_waitstatus ws
;
3592 int ignore_event
= 0;
3594 memset (&ws
, 0, sizeof (ws
));
3595 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3597 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3601 case TARGET_WAITKIND_IGNORE
:
3602 case TARGET_WAITKIND_NO_RESUMED
:
3603 case TARGET_WAITKIND_SIGNALLED
:
3604 case TARGET_WAITKIND_EXITED
:
3605 /* We shouldn't see these, but if we do, just ignore. */
3607 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3611 case TARGET_WAITKIND_EXECD
:
3612 xfree (ws
.value
.execd_pathname
);
3621 switch_to_thread (event_ptid
);
3622 set_executing (event_ptid
, 0);
3623 set_running (event_ptid
, 0);
3625 stop_pc
= get_frame_pc (get_current_frame ());
3626 set_current_sal_from_frame (get_current_frame ());
3628 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3630 enum gdb_signal sig
= ws
.value
.sig
;
3632 /* Stubs traditionally report SIGTRAP as initial signal,
3633 instead of signal 0. Suppress it. */
3634 if (sig
== GDB_SIGNAL_TRAP
)
3636 inferior_thread ()->suspend
.stop_signal
= sig
;
3638 if (signal_print_state (sig
))
3639 observer_notify_signal_received (sig
);
3642 print_stop_event (&ws
);
3643 observer_notify_normal_stop (NULL
, 1);
3648 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3650 struct remote_state
*rs
= get_remote_state ();
3651 struct packet_config
*noack_config
;
3652 char *wait_status
= NULL
;
3654 immediate_quit
++; /* Allow user to interrupt it. */
3657 if (interrupt_on_connect
)
3658 send_interrupt_sequence ();
3660 /* Ack any packet which the remote side has already sent. */
3661 serial_write (rs
->remote_desc
, "+", 1);
3663 /* Signal other parts that we're going through the initial setup,
3664 and so things may not be stable yet. */
3665 rs
->starting_up
= 1;
3667 /* The first packet we send to the target is the optional "supported
3668 packets" request. If the target can answer this, it will tell us
3669 which later probes to skip. */
3670 remote_query_supported ();
3672 /* If the stub wants to get a QAllow, compose one and send it. */
3673 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3674 remote_set_permissions (target
);
3676 /* Next, we possibly activate noack mode.
3678 If the QStartNoAckMode packet configuration is set to AUTO,
3679 enable noack mode if the stub reported a wish for it with
3682 If set to TRUE, then enable noack mode even if the stub didn't
3683 report it in qSupported. If the stub doesn't reply OK, the
3684 session ends with an error.
3686 If FALSE, then don't activate noack mode, regardless of what the
3687 stub claimed should be the default with qSupported. */
3689 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3690 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3692 putpkt ("QStartNoAckMode");
3693 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3694 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3700 /* Tell the remote that we are using the extended protocol. */
3702 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3705 /* Let the target know which signals it is allowed to pass down to
3707 update_signals_program_target ();
3709 /* Next, if the target can specify a description, read it. We do
3710 this before anything involving memory or registers. */
3711 target_find_description ();
3713 /* Next, now that we know something about the target, update the
3714 address spaces in the program spaces. */
3715 update_address_spaces ();
3717 /* On OSs where the list of libraries is global to all
3718 processes, we fetch them early. */
3719 if (gdbarch_has_global_solist (target_gdbarch ()))
3720 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3724 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3725 error (_("Non-stop mode requested, but remote "
3726 "does not support non-stop"));
3728 putpkt ("QNonStop:1");
3729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3731 if (strcmp (rs
->buf
, "OK") != 0)
3732 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3734 /* Find about threads and processes the stub is already
3735 controlling. We default to adding them in the running state.
3736 The '?' query below will then tell us about which threads are
3738 remote_update_thread_list (target
);
3740 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3742 /* Don't assume that the stub can operate in all-stop mode.
3743 Request it explicitly. */
3744 putpkt ("QNonStop:0");
3745 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3747 if (strcmp (rs
->buf
, "OK") != 0)
3748 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3751 /* Upload TSVs regardless of whether the target is running or not. The
3752 remote stub, such as GDBserver, may have some predefined or builtin
3753 TSVs, even if the target is not running. */
3754 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3756 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3758 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3759 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3762 /* Check whether the target is running now. */
3764 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3770 struct inferior
*inf
;
3772 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3775 error (_("The target is not running (try extended-remote?)"));
3777 /* We're connected, but not running. Drop out before we
3778 call start_remote. */
3779 rs
->starting_up
= 0;
3784 /* Save the reply for later. */
3785 wait_status
= alloca (strlen (rs
->buf
) + 1);
3786 strcpy (wait_status
, rs
->buf
);
3789 /* Fetch thread list. */
3790 target_update_thread_list ();
3792 /* Let the stub know that we want it to return the thread. */
3793 set_continue_thread (minus_one_ptid
);
3795 if (thread_count () == 0)
3797 /* Target has no concept of threads at all. GDB treats
3798 non-threaded target as single-threaded; add a main
3800 add_current_inferior_and_thread (wait_status
);
3804 /* We have thread information; select the thread the target
3805 says should be current. If we're reconnecting to a
3806 multi-threaded program, this will ideally be the thread
3807 that last reported an event before GDB disconnected. */
3808 inferior_ptid
= get_current_thread (wait_status
);
3809 if (ptid_equal (inferior_ptid
, null_ptid
))
3811 /* Odd... The target was able to list threads, but not
3812 tell us which thread was current (no "thread"
3813 register in T stop reply?). Just pick the first
3814 thread in the thread list then. */
3817 fprintf_unfiltered (gdb_stdlog
,
3818 "warning: couldn't determine remote "
3819 "current thread; picking first in list.\n");
3821 inferior_ptid
= thread_list
->ptid
;
3825 /* init_wait_for_inferior should be called before get_offsets in order
3826 to manage `inserted' flag in bp loc in a correct state.
3827 breakpoint_init_inferior, called from init_wait_for_inferior, set
3828 `inserted' flag to 0, while before breakpoint_re_set, called from
3829 start_remote, set `inserted' flag to 1. In the initialization of
3830 inferior, breakpoint_init_inferior should be called first, and then
3831 breakpoint_re_set can be called. If this order is broken, state of
3832 `inserted' flag is wrong, and cause some problems on breakpoint
3834 init_wait_for_inferior ();
3836 get_offsets (); /* Get text, data & bss offsets. */
3838 /* If we could not find a description using qXfer, and we know
3839 how to do it some other way, try again. This is not
3840 supported for non-stop; it could be, but it is tricky if
3841 there are no stopped threads when we connect. */
3842 if (remote_read_description_p (target
)
3843 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3845 target_clear_description ();
3846 target_find_description ();
3849 /* Use the previously fetched status. */
3850 gdb_assert (wait_status
!= NULL
);
3851 strcpy (rs
->buf
, wait_status
);
3852 rs
->cached_wait_status
= 1;
3855 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3859 ptid_t current_ptid
;
3861 /* Clear WFI global state. Do this before finding about new
3862 threads and inferiors, and setting the current inferior.
3863 Otherwise we would clear the proceed status of the current
3864 inferior when we want its stop_soon state to be preserved
3865 (see notice_new_inferior). */
3866 init_wait_for_inferior ();
3868 /* In non-stop, we will either get an "OK", meaning that there
3869 are no stopped threads at this time; or, a regular stop
3870 reply. In the latter case, there may be more than one thread
3871 stopped --- we pull them all out using the vStopped
3873 if (strcmp (rs
->buf
, "OK") != 0)
3875 struct notif_client
*notif
= ¬if_client_stop
;
3877 /* remote_notif_get_pending_replies acks this one, and gets
3879 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3880 = remote_notif_parse (notif
, rs
->buf
);
3881 remote_notif_get_pending_events (notif
);
3884 if (thread_count () == 0)
3887 error (_("The target is not running (try extended-remote?)"));
3889 /* We're connected, but not running. Drop out before we
3890 call start_remote. */
3891 rs
->starting_up
= 0;
3895 /* Let the stub know that we want it to return the thread. */
3897 /* Force the stub to choose a thread. */
3898 set_general_thread (null_ptid
);
3901 current_ptid
= remote_current_thread (minus_one_ptid
);
3902 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3903 error (_("remote didn't report the current thread in non-stop mode"));
3905 inferior_ptid
= current_ptid
;
3906 get_offsets (); /* Get text, data & bss offsets. */
3908 /* In non-stop mode, any cached wait status will be stored in
3909 the stop reply queue. */
3910 gdb_assert (wait_status
== NULL
);
3912 /* Report all signals during attach/startup. */
3913 remote_pass_signals (target
, 0, NULL
);
3915 /* If there are already stopped threads, mark them stopped and
3916 report their stops before giving the prompt to the user. */
3917 process_initial_stop_replies ();
3919 switch_to_thread (current_ptid
);
3921 if (target_can_async_p ())
3925 /* If we connected to a live target, do some additional setup. */
3926 if (target_has_execution
)
3928 if (symfile_objfile
) /* No use without a symbol-file. */
3929 remote_check_symbols ();
3932 /* Possibly the target has been engaged in a trace run started
3933 previously; find out where things are at. */
3934 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3936 struct uploaded_tp
*uploaded_tps
= NULL
;
3938 if (current_trace_status ()->running
)
3939 printf_filtered (_("Trace is already running on the target.\n"));
3941 remote_upload_tracepoints (target
, &uploaded_tps
);
3943 merge_uploaded_tracepoints (&uploaded_tps
);
3946 /* The thread and inferior lists are now synchronized with the
3947 target, our symbols have been relocated, and we're merged the
3948 target's tracepoints with ours. We're done with basic start
3950 rs
->starting_up
= 0;
3952 /* Maybe breakpoints are global and need to be inserted now. */
3953 if (breakpoints_should_be_inserted_now ())
3954 insert_breakpoints ();
3957 /* Open a connection to a remote debugger.
3958 NAME is the filename used for communication. */
3961 remote_open (const char *name
, int from_tty
)
3963 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3966 /* Open a connection to a remote debugger using the extended
3967 remote gdb protocol. NAME is the filename used for communication. */
3970 extended_remote_open (const char *name
, int from_tty
)
3972 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3975 /* Reset all packets back to "unknown support". Called when opening a
3976 new connection to a remote target. */
3979 reset_all_packet_configs_support (void)
3983 for (i
= 0; i
< PACKET_MAX
; i
++)
3984 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3987 /* Initialize all packet configs. */
3990 init_all_packet_configs (void)
3994 for (i
= 0; i
< PACKET_MAX
; i
++)
3996 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3997 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4001 /* Symbol look-up. */
4004 remote_check_symbols (void)
4006 struct remote_state
*rs
= get_remote_state ();
4007 char *msg
, *reply
, *tmp
;
4008 struct bound_minimal_symbol sym
;
4011 /* The remote side has no concept of inferiors that aren't running
4012 yet, it only knows about running processes. If we're connected
4013 but our current inferior is not running, we should not invite the
4014 remote target to request symbol lookups related to its
4015 (unrelated) current process. */
4016 if (!target_has_execution
)
4019 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4022 /* Make sure the remote is pointing at the right process. Note
4023 there's no way to select "no process". */
4024 set_general_process ();
4026 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4027 because we need both at the same time. */
4028 msg
= alloca (get_remote_packet_size ());
4030 /* Invite target to request symbol lookups. */
4032 putpkt ("qSymbol::");
4033 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4034 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
4037 while (startswith (reply
, "qSymbol:"))
4039 struct bound_minimal_symbol sym
;
4042 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4044 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4045 if (sym
.minsym
== NULL
)
4046 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4049 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4050 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4052 /* If this is a function address, return the start of code
4053 instead of any data function descriptor. */
4054 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4058 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4059 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4063 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4068 static struct serial
*
4069 remote_serial_open (const char *name
)
4071 static int udp_warning
= 0;
4073 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4074 of in ser-tcp.c, because it is the remote protocol assuming that the
4075 serial connection is reliable and not the serial connection promising
4077 if (!udp_warning
&& startswith (name
, "udp:"))
4079 warning (_("The remote protocol may be unreliable over UDP.\n"
4080 "Some events may be lost, rendering further debugging "
4085 return serial_open (name
);
4088 /* Inform the target of our permission settings. The permission flags
4089 work without this, but if the target knows the settings, it can do
4090 a couple things. First, it can add its own check, to catch cases
4091 that somehow manage to get by the permissions checks in target
4092 methods. Second, if the target is wired to disallow particular
4093 settings (for instance, a system in the field that is not set up to
4094 be able to stop at a breakpoint), it can object to any unavailable
4098 remote_set_permissions (struct target_ops
*self
)
4100 struct remote_state
*rs
= get_remote_state ();
4102 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4103 "WriteReg:%x;WriteMem:%x;"
4104 "InsertBreak:%x;InsertTrace:%x;"
4105 "InsertFastTrace:%x;Stop:%x",
4106 may_write_registers
, may_write_memory
,
4107 may_insert_breakpoints
, may_insert_tracepoints
,
4108 may_insert_fast_tracepoints
, may_stop
);
4110 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4112 /* If the target didn't like the packet, warn the user. Do not try
4113 to undo the user's settings, that would just be maddening. */
4114 if (strcmp (rs
->buf
, "OK") != 0)
4115 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4118 /* This type describes each known response to the qSupported
4120 struct protocol_feature
4122 /* The name of this protocol feature. */
4125 /* The default for this protocol feature. */
4126 enum packet_support default_support
;
4128 /* The function to call when this feature is reported, or after
4129 qSupported processing if the feature is not supported.
4130 The first argument points to this structure. The second
4131 argument indicates whether the packet requested support be
4132 enabled, disabled, or probed (or the default, if this function
4133 is being called at the end of processing and this feature was
4134 not reported). The third argument may be NULL; if not NULL, it
4135 is a NUL-terminated string taken from the packet following
4136 this feature's name and an equals sign. */
4137 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4140 /* The corresponding packet for this feature. Only used if
4141 FUNC is remote_supported_packet. */
4146 remote_supported_packet (const struct protocol_feature
*feature
,
4147 enum packet_support support
,
4148 const char *argument
)
4152 warning (_("Remote qSupported response supplied an unexpected value for"
4153 " \"%s\"."), feature
->name
);
4157 remote_protocol_packets
[feature
->packet
].support
= support
;
4161 remote_packet_size (const struct protocol_feature
*feature
,
4162 enum packet_support support
, const char *value
)
4164 struct remote_state
*rs
= get_remote_state ();
4169 if (support
!= PACKET_ENABLE
)
4172 if (value
== NULL
|| *value
== '\0')
4174 warning (_("Remote target reported \"%s\" without a size."),
4180 packet_size
= strtol (value
, &value_end
, 16);
4181 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4183 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4184 feature
->name
, value
);
4188 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
4190 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
4191 packet_size
, MAX_REMOTE_PACKET_SIZE
);
4192 packet_size
= MAX_REMOTE_PACKET_SIZE
;
4195 /* Record the new maximum packet size. */
4196 rs
->explicit_packet_size
= packet_size
;
4199 static const struct protocol_feature remote_protocol_features
[] = {
4200 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4201 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4202 PACKET_qXfer_auxv
},
4203 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4204 PACKET_qXfer_exec_file
},
4205 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4206 PACKET_qXfer_features
},
4207 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4208 PACKET_qXfer_libraries
},
4209 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4210 PACKET_qXfer_libraries_svr4
},
4211 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4212 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4213 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4214 PACKET_qXfer_memory_map
},
4215 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4216 PACKET_qXfer_spu_read
},
4217 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4218 PACKET_qXfer_spu_write
},
4219 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4220 PACKET_qXfer_osdata
},
4221 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4222 PACKET_qXfer_threads
},
4223 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4224 PACKET_qXfer_traceframe_info
},
4225 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4226 PACKET_QPassSignals
},
4227 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4228 PACKET_QProgramSignals
},
4229 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4230 PACKET_QStartNoAckMode
},
4231 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4232 PACKET_multiprocess_feature
},
4233 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4234 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4235 PACKET_qXfer_siginfo_read
},
4236 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4237 PACKET_qXfer_siginfo_write
},
4238 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4239 PACKET_ConditionalTracepoints
},
4240 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4241 PACKET_ConditionalBreakpoints
},
4242 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4243 PACKET_BreakpointCommands
},
4244 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4245 PACKET_FastTracepoints
},
4246 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4247 PACKET_StaticTracepoints
},
4248 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4249 PACKET_InstallInTrace
},
4250 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4251 PACKET_DisconnectedTracing_feature
},
4252 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4254 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4256 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4257 PACKET_TracepointSource
},
4258 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4260 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4261 PACKET_EnableDisableTracepoints_feature
},
4262 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4263 PACKET_qXfer_fdpic
},
4264 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4266 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4267 PACKET_QDisableRandomization
},
4268 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4269 { "QTBuffer:size", PACKET_DISABLE
,
4270 remote_supported_packet
, PACKET_QTBuffer_size
},
4271 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4272 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4273 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4274 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4275 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4276 PACKET_qXfer_btrace
},
4277 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4278 PACKET_qXfer_btrace_conf
},
4279 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4280 PACKET_Qbtrace_conf_bts_size
},
4281 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4282 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4283 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4284 PACKET_fork_event_feature
},
4285 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4286 PACKET_vfork_event_feature
},
4287 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4288 PACKET_Qbtrace_conf_pt_size
}
4291 static char *remote_support_xml
;
4293 /* Register string appended to "xmlRegisters=" in qSupported query. */
4296 register_remote_support_xml (const char *xml
)
4298 #if defined(HAVE_LIBEXPAT)
4299 if (remote_support_xml
== NULL
)
4300 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4303 char *copy
= xstrdup (remote_support_xml
+ 13);
4304 char *p
= strtok (copy
, ",");
4308 if (strcmp (p
, xml
) == 0)
4315 while ((p
= strtok (NULL
, ",")) != NULL
);
4318 remote_support_xml
= reconcat (remote_support_xml
,
4319 remote_support_xml
, ",", xml
,
4326 remote_query_supported_append (char *msg
, const char *append
)
4329 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4331 return xstrdup (append
);
4335 remote_query_supported (void)
4337 struct remote_state
*rs
= get_remote_state ();
4340 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4342 /* The packet support flags are handled differently for this packet
4343 than for most others. We treat an error, a disabled packet, and
4344 an empty response identically: any features which must be reported
4345 to be used will be automatically disabled. An empty buffer
4346 accomplishes this, since that is also the representation for a list
4347 containing no features. */
4350 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4353 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4355 q
= remote_query_supported_append (q
, "multiprocess+");
4357 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4358 q
= remote_query_supported_append (q
, "swbreak+");
4359 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4360 q
= remote_query_supported_append (q
, "hwbreak+");
4362 if (remote_support_xml
)
4363 q
= remote_query_supported_append (q
, remote_support_xml
);
4365 q
= remote_query_supported_append (q
, "qRelocInsn+");
4369 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4370 != AUTO_BOOLEAN_FALSE
)
4371 q
= remote_query_supported_append (q
, "fork-events+");
4372 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4373 != AUTO_BOOLEAN_FALSE
)
4374 q
= remote_query_supported_append (q
, "vfork-events+");
4377 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4380 do_cleanups (old_chain
);
4382 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4384 /* If an error occured, warn, but do not return - just reset the
4385 buffer to empty and go on to disable features. */
4386 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4389 warning (_("Remote failure reply: %s"), rs
->buf
);
4394 memset (seen
, 0, sizeof (seen
));
4399 enum packet_support is_supported
;
4400 char *p
, *end
, *name_end
, *value
;
4402 /* First separate out this item from the rest of the packet. If
4403 there's another item after this, we overwrite the separator
4404 (terminated strings are much easier to work with). */
4406 end
= strchr (p
, ';');
4409 end
= p
+ strlen (p
);
4419 warning (_("empty item in \"qSupported\" response"));
4424 name_end
= strchr (p
, '=');
4427 /* This is a name=value entry. */
4428 is_supported
= PACKET_ENABLE
;
4429 value
= name_end
+ 1;
4438 is_supported
= PACKET_ENABLE
;
4442 is_supported
= PACKET_DISABLE
;
4446 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4450 warning (_("unrecognized item \"%s\" "
4451 "in \"qSupported\" response"), p
);
4457 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4458 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4460 const struct protocol_feature
*feature
;
4463 feature
= &remote_protocol_features
[i
];
4464 feature
->func (feature
, is_supported
, value
);
4469 /* If we increased the packet size, make sure to increase the global
4470 buffer size also. We delay this until after parsing the entire
4471 qSupported packet, because this is the same buffer we were
4473 if (rs
->buf_size
< rs
->explicit_packet_size
)
4475 rs
->buf_size
= rs
->explicit_packet_size
;
4476 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4479 /* Handle the defaults for unmentioned features. */
4480 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4483 const struct protocol_feature
*feature
;
4485 feature
= &remote_protocol_features
[i
];
4486 feature
->func (feature
, feature
->default_support
, NULL
);
4490 /* Remove any of the remote.c targets from target stack. Upper targets depend
4491 on it so remove them first. */
4494 remote_unpush_target (void)
4496 pop_all_targets_above (process_stratum
- 1);
4500 remote_open_1 (const char *name
, int from_tty
,
4501 struct target_ops
*target
, int extended_p
)
4503 struct remote_state
*rs
= get_remote_state ();
4506 error (_("To open a remote debug connection, you need to specify what\n"
4507 "serial device is attached to the remote system\n"
4508 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4510 /* See FIXME above. */
4511 if (!target_async_permitted
)
4512 wait_forever_enabled_p
= 1;
4514 /* If we're connected to a running target, target_preopen will kill it.
4515 Ask this question first, before target_preopen has a chance to kill
4517 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4520 && !query (_("Already connected to a remote target. Disconnect? ")))
4521 error (_("Still connected."));
4524 /* Here the possibly existing remote target gets unpushed. */
4525 target_preopen (from_tty
);
4527 /* Make sure we send the passed signals list the next time we resume. */
4528 xfree (rs
->last_pass_packet
);
4529 rs
->last_pass_packet
= NULL
;
4531 /* Make sure we send the program signals list the next time we
4533 xfree (rs
->last_program_signals_packet
);
4534 rs
->last_program_signals_packet
= NULL
;
4536 remote_fileio_reset ();
4537 reopen_exec_file ();
4540 rs
->remote_desc
= remote_serial_open (name
);
4541 if (!rs
->remote_desc
)
4542 perror_with_name (name
);
4544 if (baud_rate
!= -1)
4546 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4548 /* The requested speed could not be set. Error out to
4549 top level after closing remote_desc. Take care to
4550 set remote_desc to NULL to avoid closing remote_desc
4552 serial_close (rs
->remote_desc
);
4553 rs
->remote_desc
= NULL
;
4554 perror_with_name (name
);
4558 serial_setparity (rs
->remote_desc
, serial_parity
);
4559 serial_raw (rs
->remote_desc
);
4561 /* If there is something sitting in the buffer we might take it as a
4562 response to a command, which would be bad. */
4563 serial_flush_input (rs
->remote_desc
);
4567 puts_filtered ("Remote debugging using ");
4568 puts_filtered (name
);
4569 puts_filtered ("\n");
4571 push_target (target
); /* Switch to using remote target now. */
4573 /* Register extra event sources in the event loop. */
4574 remote_async_inferior_event_token
4575 = create_async_event_handler (remote_async_inferior_event_handler
,
4577 rs
->notif_state
= remote_notif_state_allocate ();
4579 /* Reset the target state; these things will be queried either by
4580 remote_query_supported or as they are needed. */
4581 reset_all_packet_configs_support ();
4582 rs
->cached_wait_status
= 0;
4583 rs
->explicit_packet_size
= 0;
4585 rs
->extended
= extended_p
;
4586 rs
->waiting_for_stop_reply
= 0;
4587 rs
->ctrlc_pending_p
= 0;
4589 rs
->general_thread
= not_sent_ptid
;
4590 rs
->continue_thread
= not_sent_ptid
;
4591 rs
->remote_traceframe_number
= -1;
4593 /* Probe for ability to use "ThreadInfo" query, as required. */
4594 rs
->use_threadinfo_query
= 1;
4595 rs
->use_threadextra_query
= 1;
4597 readahead_cache_invalidate ();
4599 if (target_async_permitted
)
4601 /* With this target we start out by owning the terminal. */
4602 remote_async_terminal_ours_p
= 1;
4604 /* FIXME: cagney/1999-09-23: During the initial connection it is
4605 assumed that the target is already ready and able to respond to
4606 requests. Unfortunately remote_start_remote() eventually calls
4607 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4608 around this. Eventually a mechanism that allows
4609 wait_for_inferior() to expect/get timeouts will be
4611 wait_forever_enabled_p
= 0;
4614 /* First delete any symbols previously loaded from shared libraries. */
4615 no_shared_libraries (NULL
, 0);
4618 init_thread_list ();
4620 /* Start the remote connection. If error() or QUIT, discard this
4621 target (we'd otherwise be in an inconsistent state) and then
4622 propogate the error on up the exception chain. This ensures that
4623 the caller doesn't stumble along blindly assuming that the
4624 function succeeded. The CLI doesn't have this problem but other
4625 UI's, such as MI do.
4627 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4628 this function should return an error indication letting the
4629 caller restore the previous state. Unfortunately the command
4630 ``target remote'' is directly wired to this function making that
4631 impossible. On a positive note, the CLI side of this problem has
4632 been fixed - the function set_cmd_context() makes it possible for
4633 all the ``target ....'' commands to share a common callback
4634 function. See cli-dump.c. */
4639 remote_start_remote (from_tty
, target
, extended_p
);
4641 CATCH (ex
, RETURN_MASK_ALL
)
4643 /* Pop the partially set up target - unless something else did
4644 already before throwing the exception. */
4645 if (rs
->remote_desc
!= NULL
)
4646 remote_unpush_target ();
4647 if (target_async_permitted
)
4648 wait_forever_enabled_p
= 1;
4649 throw_exception (ex
);
4654 remote_btrace_reset ();
4656 if (target_async_permitted
)
4657 wait_forever_enabled_p
= 1;
4660 /* Detach the specified process. */
4663 remote_detach_pid (int pid
)
4665 struct remote_state
*rs
= get_remote_state ();
4667 if (remote_multi_process_p (rs
))
4668 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4670 strcpy (rs
->buf
, "D");
4673 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4675 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4677 else if (rs
->buf
[0] == '\0')
4678 error (_("Remote doesn't know how to detach"));
4680 error (_("Can't detach process."));
4683 /* This detaches a program to which we previously attached, using
4684 inferior_ptid to identify the process. After this is done, GDB
4685 can be used to debug some other program. We better not have left
4686 any breakpoints in the target program or it'll die when it hits
4690 remote_detach_1 (const char *args
, int from_tty
)
4692 int pid
= ptid_get_pid (inferior_ptid
);
4693 struct remote_state
*rs
= get_remote_state ();
4694 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4698 error (_("Argument given to \"detach\" when remotely debugging."));
4700 if (!target_has_execution
)
4701 error (_("No process to detach from."));
4705 char *exec_file
= get_exec_file (0);
4706 if (exec_file
== NULL
)
4708 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4709 target_pid_to_str (pid_to_ptid (pid
)));
4710 gdb_flush (gdb_stdout
);
4713 /* Tell the remote target to detach. */
4714 remote_detach_pid (pid
);
4716 if (from_tty
&& !rs
->extended
)
4717 puts_filtered (_("Ending remote debugging.\n"));
4719 /* Check to see if we are detaching a fork parent. Note that if we
4720 are detaching a fork child, tp == NULL. */
4721 is_fork_parent
= (tp
!= NULL
4722 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4724 /* If doing detach-on-fork, we don't mourn, because that will delete
4725 breakpoints that should be available for the followed inferior. */
4726 if (!is_fork_parent
)
4727 target_mourn_inferior ();
4730 inferior_ptid
= null_ptid
;
4731 detach_inferior (pid
);
4736 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4738 remote_detach_1 (args
, from_tty
);
4742 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4744 remote_detach_1 (args
, from_tty
);
4747 /* Target follow-fork function for remote targets. On entry, and
4748 at return, the current inferior is the fork parent.
4750 Note that although this is currently only used for extended-remote,
4751 it is named remote_follow_fork in anticipation of using it for the
4752 remote target as well. */
4755 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4758 struct remote_state
*rs
= get_remote_state ();
4759 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4761 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4762 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4764 /* When following the parent and detaching the child, we detach
4765 the child here. For the case of following the child and
4766 detaching the parent, the detach is done in the target-
4767 independent follow fork code in infrun.c. We can't use
4768 target_detach when detaching an unfollowed child because
4769 the client side doesn't know anything about the child. */
4770 if (detach_fork
&& !follow_child
)
4772 /* Detach the fork child. */
4776 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4777 child_pid
= ptid_get_pid (child_ptid
);
4779 remote_detach_pid (child_pid
);
4780 detach_inferior (child_pid
);
4786 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4789 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4792 error (_("Argument given to \"disconnect\" when remotely debugging."));
4794 /* Make sure we unpush even the extended remote targets; mourn
4795 won't do it. So call remote_mourn directly instead of
4796 target_mourn_inferior. */
4797 remote_mourn (target
);
4800 puts_filtered ("Ending remote debugging.\n");
4803 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4804 be chatty about it. */
4807 extended_remote_attach (struct target_ops
*target
, const char *args
,
4810 struct remote_state
*rs
= get_remote_state ();
4812 char *wait_status
= NULL
;
4814 pid
= parse_pid_to_attach (args
);
4816 /* Remote PID can be freely equal to getpid, do not check it here the same
4817 way as in other targets. */
4819 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4820 error (_("This target does not support attaching to a process"));
4824 char *exec_file
= get_exec_file (0);
4827 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4828 target_pid_to_str (pid_to_ptid (pid
)));
4830 printf_unfiltered (_("Attaching to %s\n"),
4831 target_pid_to_str (pid_to_ptid (pid
)));
4833 gdb_flush (gdb_stdout
);
4836 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4838 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4840 switch (packet_ok (rs
->buf
,
4841 &remote_protocol_packets
[PACKET_vAttach
]))
4846 /* Save the reply for later. */
4847 wait_status
= alloca (strlen (rs
->buf
) + 1);
4848 strcpy (wait_status
, rs
->buf
);
4850 else if (strcmp (rs
->buf
, "OK") != 0)
4851 error (_("Attaching to %s failed with: %s"),
4852 target_pid_to_str (pid_to_ptid (pid
)),
4855 case PACKET_UNKNOWN
:
4856 error (_("This target does not support attaching to a process"));
4858 error (_("Attaching to %s failed"),
4859 target_pid_to_str (pid_to_ptid (pid
)));
4862 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4864 inferior_ptid
= pid_to_ptid (pid
);
4868 struct thread_info
*thread
;
4870 /* Get list of threads. */
4871 remote_update_thread_list (target
);
4873 thread
= first_thread_of_process (pid
);
4875 inferior_ptid
= thread
->ptid
;
4877 inferior_ptid
= pid_to_ptid (pid
);
4879 /* Invalidate our notion of the remote current thread. */
4880 record_currthread (rs
, minus_one_ptid
);
4884 /* Now, if we have thread information, update inferior_ptid. */
4885 inferior_ptid
= remote_current_thread (inferior_ptid
);
4887 /* Add the main thread to the thread list. */
4888 add_thread_silent (inferior_ptid
);
4891 /* Next, if the target can specify a description, read it. We do
4892 this before anything involving memory or registers. */
4893 target_find_description ();
4897 /* Use the previously fetched status. */
4898 gdb_assert (wait_status
!= NULL
);
4900 if (target_can_async_p ())
4902 struct notif_event
*reply
4903 = remote_notif_parse (¬if_client_stop
, wait_status
);
4905 push_stop_reply ((struct stop_reply
*) reply
);
4911 gdb_assert (wait_status
!= NULL
);
4912 strcpy (rs
->buf
, wait_status
);
4913 rs
->cached_wait_status
= 1;
4917 gdb_assert (wait_status
== NULL
);
4920 /* Implementation of the to_post_attach method. */
4923 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4925 /* In certain cases GDB might not have had the chance to start
4926 symbol lookup up until now. This could happen if the debugged
4927 binary is not using shared libraries, the vsyscall page is not
4928 present (on Linux) and the binary itself hadn't changed since the
4929 debugging process was started. */
4930 if (symfile_objfile
!= NULL
)
4931 remote_check_symbols();
4935 /* Check for the availability of vCont. This function should also check
4939 remote_vcont_probe (struct remote_state
*rs
)
4943 strcpy (rs
->buf
, "vCont?");
4945 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4948 /* Make sure that the features we assume are supported. */
4949 if (startswith (buf
, "vCont"))
4952 int support_s
, support_S
, support_c
, support_C
;
4958 rs
->supports_vCont
.t
= 0;
4959 rs
->supports_vCont
.r
= 0;
4960 while (p
&& *p
== ';')
4963 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4965 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4967 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4969 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4971 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4972 rs
->supports_vCont
.t
= 1;
4973 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4974 rs
->supports_vCont
.r
= 1;
4976 p
= strchr (p
, ';');
4979 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4980 BUF will make packet_ok disable the packet. */
4981 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4985 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4988 /* Helper function for building "vCont" resumptions. Write a
4989 resumption to P. ENDP points to one-passed-the-end of the buffer
4990 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4991 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4992 resumed thread should be single-stepped and/or signalled. If PTID
4993 equals minus_one_ptid, then all threads are resumed; if PTID
4994 represents a process, then all threads of the process are resumed;
4995 the thread to be stepped and/or signalled is given in the global
4999 append_resumption (char *p
, char *endp
,
5000 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5002 struct remote_state
*rs
= get_remote_state ();
5004 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5005 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5007 /* GDB is willing to range step. */
5008 && use_range_stepping
5009 /* Target supports range stepping. */
5010 && rs
->supports_vCont
.r
5011 /* We don't currently support range stepping multiple
5012 threads with a wildcard (though the protocol allows it,
5013 so stubs shouldn't make an active effort to forbid
5015 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5017 struct thread_info
*tp
;
5019 if (ptid_equal (ptid
, minus_one_ptid
))
5021 /* If we don't know about the target thread's tid, then
5022 we're resuming magic_null_ptid (see caller). */
5023 tp
= find_thread_ptid (magic_null_ptid
);
5026 tp
= find_thread_ptid (ptid
);
5027 gdb_assert (tp
!= NULL
);
5029 if (tp
->control
.may_range_step
)
5031 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5033 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5034 phex_nz (tp
->control
.step_range_start
,
5036 phex_nz (tp
->control
.step_range_end
,
5040 p
+= xsnprintf (p
, endp
- p
, ";s");
5043 p
+= xsnprintf (p
, endp
- p
, ";s");
5044 else if (siggnal
!= GDB_SIGNAL_0
)
5045 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5047 p
+= xsnprintf (p
, endp
- p
, ";c");
5049 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5053 /* All (-1) threads of process. */
5054 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5056 p
+= xsnprintf (p
, endp
- p
, ":");
5057 p
= write_ptid (p
, endp
, nptid
);
5059 else if (!ptid_equal (ptid
, minus_one_ptid
))
5061 p
+= xsnprintf (p
, endp
- p
, ":");
5062 p
= write_ptid (p
, endp
, ptid
);
5068 /* Append a vCont continue-with-signal action for threads that have a
5069 non-zero stop signal. */
5072 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5074 struct thread_info
*thread
;
5076 ALL_NON_EXITED_THREADS (thread
)
5077 if (ptid_match (thread
->ptid
, ptid
)
5078 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5079 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5081 p
= append_resumption (p
, endp
, thread
->ptid
,
5082 0, thread
->suspend
.stop_signal
);
5083 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5089 /* Resume the remote inferior by using a "vCont" packet. The thread
5090 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5091 resumed thread should be single-stepped and/or signalled. If PTID
5092 equals minus_one_ptid, then all threads are resumed; the thread to
5093 be stepped and/or signalled is given in the global INFERIOR_PTID.
5094 This function returns non-zero iff it resumes the inferior.
5096 This function issues a strict subset of all possible vCont commands at the
5100 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5102 struct remote_state
*rs
= get_remote_state ();
5106 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5107 remote_vcont_probe (rs
);
5109 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5113 endp
= rs
->buf
+ get_remote_packet_size ();
5115 /* If we could generate a wider range of packets, we'd have to worry
5116 about overflowing BUF. Should there be a generic
5117 "multi-part-packet" packet? */
5119 p
+= xsnprintf (p
, endp
- p
, "vCont");
5121 if (ptid_equal (ptid
, magic_null_ptid
))
5123 /* MAGIC_NULL_PTID means that we don't have any active threads,
5124 so we don't have any TID numbers the inferior will
5125 understand. Make sure to only send forms that do not specify
5127 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5129 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5131 /* Resume all threads (of all processes, or of a single
5132 process), with preference for INFERIOR_PTID. This assumes
5133 inferior_ptid belongs to the set of all threads we are about
5135 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5137 /* Step inferior_ptid, with or without signal. */
5138 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5141 /* Also pass down any pending signaled resumption for other
5142 threads not the current. */
5143 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5145 /* And continue others without a signal. */
5146 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5150 /* Scheduler locking; resume only PTID. */
5151 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5154 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5159 /* In non-stop, the stub replies to vCont with "OK". The stop
5160 reply will be reported asynchronously by means of a `%Stop'
5162 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5163 if (strcmp (rs
->buf
, "OK") != 0)
5164 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5170 /* Tell the remote machine to resume. */
5173 remote_resume (struct target_ops
*ops
,
5174 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5176 struct remote_state
*rs
= get_remote_state ();
5179 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5180 (explained in remote-notif.c:handle_notification) so
5181 remote_notif_process is not called. We need find a place where
5182 it is safe to start a 'vNotif' sequence. It is good to do it
5183 before resuming inferior, because inferior was stopped and no RSP
5184 traffic at that moment. */
5186 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5188 rs
->last_sent_signal
= siggnal
;
5189 rs
->last_sent_step
= step
;
5191 /* The vCont packet doesn't need to specify threads via Hc. */
5192 /* No reverse support (yet) for vCont. */
5193 if (execution_direction
!= EXEC_REVERSE
)
5194 if (remote_vcont_resume (ptid
, step
, siggnal
))
5197 /* All other supported resume packets do use Hc, so set the continue
5199 if (ptid_equal (ptid
, minus_one_ptid
))
5200 set_continue_thread (any_thread_ptid
);
5202 set_continue_thread (ptid
);
5205 if (execution_direction
== EXEC_REVERSE
)
5207 /* We don't pass signals to the target in reverse exec mode. */
5208 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5209 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5212 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5213 error (_("Remote reverse-step not supported."));
5214 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5215 error (_("Remote reverse-continue not supported."));
5217 strcpy (buf
, step
? "bs" : "bc");
5219 else if (siggnal
!= GDB_SIGNAL_0
)
5221 buf
[0] = step
? 'S' : 'C';
5222 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5223 buf
[2] = tohex (((int) siggnal
) & 0xf);
5227 strcpy (buf
, step
? "s" : "c");
5232 /* We are about to start executing the inferior, let's register it
5233 with the event loop. NOTE: this is the one place where all the
5234 execution commands end up. We could alternatively do this in each
5235 of the execution commands in infcmd.c. */
5236 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5237 into infcmd.c in order to allow inferior function calls to work
5238 NOT asynchronously. */
5239 if (target_can_async_p ())
5242 /* We've just told the target to resume. The remote server will
5243 wait for the inferior to stop, and then send a stop reply. In
5244 the mean time, we can't start another command/query ourselves
5245 because the stub wouldn't be ready to process it. This applies
5246 only to the base all-stop protocol, however. In non-stop (which
5247 only supports vCont), the stub replies with an "OK", and is
5248 immediate able to process further serial input. */
5250 rs
->waiting_for_stop_reply
= 1;
5254 /* Set up the signal handler for SIGINT, while the target is
5255 executing, ovewriting the 'regular' SIGINT signal handler. */
5257 async_initialize_sigint_signal_handler (void)
5259 signal (SIGINT
, async_handle_remote_sigint
);
5262 /* Signal handler for SIGINT, while the target is executing. */
5264 async_handle_remote_sigint (int sig
)
5266 signal (sig
, async_handle_remote_sigint_twice
);
5267 /* Note we need to go through gdb_call_async_signal_handler in order
5268 to wake up the event loop on Windows. */
5269 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5272 /* Signal handler for SIGINT, installed after SIGINT has already been
5273 sent once. It will take effect the second time that the user sends
5276 async_handle_remote_sigint_twice (int sig
)
5278 signal (sig
, async_handle_remote_sigint
);
5279 /* See note in async_handle_remote_sigint. */
5280 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5283 /* Perform the real interruption of the target execution, in response
5286 async_remote_interrupt (gdb_client_data arg
)
5289 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5291 target_stop (inferior_ptid
);
5294 /* Perform interrupt, if the first attempt did not succeed. Just give
5295 up on the target alltogether. */
5297 async_remote_interrupt_twice (gdb_client_data arg
)
5300 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5305 /* Reinstall the usual SIGINT handlers, after the target has
5308 async_cleanup_sigint_signal_handler (void *dummy
)
5310 signal (SIGINT
, handle_sigint
);
5313 /* Send ^C to target to halt it. Target will respond, and send us a
5315 static void (*ofunc
) (int);
5317 /* The command line interface's interrupt routine. This function is installed
5318 as a signal handler for SIGINT. The first time a user requests an
5319 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5320 response from the target (it didn't stop when the user requested it),
5321 we ask the user if he'd like to detach from the target. */
5324 sync_remote_interrupt (int signo
)
5326 /* If this doesn't work, try more severe steps. */
5327 signal (signo
, sync_remote_interrupt_twice
);
5329 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5332 /* The user typed ^C twice. */
5335 sync_remote_interrupt_twice (int signo
)
5337 signal (signo
, ofunc
);
5338 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5339 signal (signo
, sync_remote_interrupt
);
5342 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5343 thread, all threads of a remote process, or all threads of all
5347 remote_stop_ns (ptid_t ptid
)
5349 struct remote_state
*rs
= get_remote_state ();
5351 char *endp
= rs
->buf
+ get_remote_packet_size ();
5353 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5354 remote_vcont_probe (rs
);
5356 if (!rs
->supports_vCont
.t
)
5357 error (_("Remote server does not support stopping threads"));
5359 if (ptid_equal (ptid
, minus_one_ptid
)
5360 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5361 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5366 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5368 if (ptid_is_pid (ptid
))
5369 /* All (-1) threads of process. */
5370 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5373 /* Small optimization: if we already have a stop reply for
5374 this thread, no use in telling the stub we want this
5376 if (peek_stop_reply (ptid
))
5382 write_ptid (p
, endp
, nptid
);
5385 /* In non-stop, we get an immediate OK reply. The stop reply will
5386 come in asynchronously by notification. */
5388 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5389 if (strcmp (rs
->buf
, "OK") != 0)
5390 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5393 /* All-stop version of target_interrupt. Sends a break or a ^C to
5394 interrupt the remote target. It is undefined which thread of which
5395 process reports the interrupt. */
5398 remote_interrupt_as (ptid_t ptid
)
5400 struct remote_state
*rs
= get_remote_state ();
5402 rs
->ctrlc_pending_p
= 1;
5404 /* If the inferior is stopped already, but the core didn't know
5405 about it yet, just ignore the request. The cached wait status
5406 will be collected in remote_wait. */
5407 if (rs
->cached_wait_status
)
5410 /* Send interrupt_sequence to remote target. */
5411 send_interrupt_sequence ();
5414 /* Implement the to_stop function for the remote targets. */
5417 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5420 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5423 remote_stop_ns (ptid
);
5426 /* We don't currently have a way to transparently pause the
5427 remote target in all-stop mode. Interrupt it instead. */
5428 remote_interrupt_as (ptid
);
5432 /* Implement the to_interrupt function for the remote targets. */
5435 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5438 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5442 /* We don't currently have a way to ^C the remote target in
5443 non-stop mode. Stop it (with no signal) instead. */
5444 remote_stop_ns (ptid
);
5447 remote_interrupt_as (ptid
);
5450 /* Ask the user what to do when an interrupt is received. */
5453 interrupt_query (void)
5455 target_terminal_ours ();
5457 if (target_is_async_p ())
5459 signal (SIGINT
, handle_sigint
);
5464 if (query (_("Interrupted while waiting for the program.\n\
5465 Give up (and stop debugging it)? ")))
5467 remote_unpush_target ();
5472 target_terminal_inferior ();
5475 /* Enable/disable target terminal ownership. Most targets can use
5476 terminal groups to control terminal ownership. Remote targets are
5477 different in that explicit transfer of ownership to/from GDB/target
5481 remote_terminal_inferior (struct target_ops
*self
)
5483 if (!target_async_permitted
)
5484 /* Nothing to do. */
5487 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5488 idempotent. The event-loop GDB talking to an asynchronous target
5489 with a synchronous command calls this function from both
5490 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5491 transfer the terminal to the target when it shouldn't this guard
5493 if (!remote_async_terminal_ours_p
)
5495 delete_file_handler (input_fd
);
5496 remote_async_terminal_ours_p
= 0;
5497 async_initialize_sigint_signal_handler ();
5498 /* NOTE: At this point we could also register our selves as the
5499 recipient of all input. Any characters typed could then be
5500 passed on down to the target. */
5504 remote_terminal_ours (struct target_ops
*self
)
5506 if (!target_async_permitted
)
5507 /* Nothing to do. */
5510 /* See FIXME in remote_terminal_inferior. */
5511 if (remote_async_terminal_ours_p
)
5513 async_cleanup_sigint_signal_handler (NULL
);
5514 add_file_handler (input_fd
, stdin_event_handler
, 0);
5515 remote_async_terminal_ours_p
= 1;
5519 remote_console_output (char *msg
)
5523 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5526 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5530 fputs_unfiltered (tb
, gdb_stdtarg
);
5532 gdb_flush (gdb_stdtarg
);
5535 typedef struct cached_reg
5538 gdb_byte data
[MAX_REGISTER_SIZE
];
5541 DEF_VEC_O(cached_reg_t
);
5543 typedef struct stop_reply
5545 struct notif_event base
;
5547 /* The identifier of the thread about this event */
5550 /* The remote state this event is associated with. When the remote
5551 connection, represented by a remote_state object, is closed,
5552 all the associated stop_reply events should be released. */
5553 struct remote_state
*rs
;
5555 struct target_waitstatus ws
;
5557 /* Expedited registers. This makes remote debugging a bit more
5558 efficient for those targets that provide critical registers as
5559 part of their normal status mechanism (as another roundtrip to
5560 fetch them is avoided). */
5561 VEC(cached_reg_t
) *regcache
;
5563 enum target_stop_reason stop_reason
;
5565 CORE_ADDR watch_data_address
;
5570 DECLARE_QUEUE_P (stop_reply_p
);
5571 DEFINE_QUEUE_P (stop_reply_p
);
5572 /* The list of already fetched and acknowledged stop events. This
5573 queue is used for notification Stop, and other notifications
5574 don't need queue for their events, because the notification events
5575 of Stop can't be consumed immediately, so that events should be
5576 queued first, and be consumed by remote_wait_{ns,as} one per
5577 time. Other notifications can consume their events immediately,
5578 so queue is not needed for them. */
5579 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5582 stop_reply_xfree (struct stop_reply
*r
)
5584 notif_event_xfree ((struct notif_event
*) r
);
5587 /* Return the length of the stop reply queue. */
5590 stop_reply_queue_length (void)
5592 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
5596 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5597 struct notif_event
*event
)
5599 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5603 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5604 struct notif_event
*event
)
5606 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5609 putpkt ((char *) self
->ack_command
);
5611 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5612 /* We got an unknown stop reply. */
5613 error (_("Unknown stop reply"));
5615 push_stop_reply (stop_reply
);
5619 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5621 /* We can't get pending events in remote_notif_process for
5622 notification stop, and we have to do this in remote_wait_ns
5623 instead. If we fetch all queued events from stub, remote stub
5624 may exit and we have no chance to process them back in
5626 mark_async_event_handler (remote_async_inferior_event_token
);
5631 stop_reply_dtr (struct notif_event
*event
)
5633 struct stop_reply
*r
= (struct stop_reply
*) event
;
5635 VEC_free (cached_reg_t
, r
->regcache
);
5638 static struct notif_event
*
5639 remote_notif_stop_alloc_reply (void)
5641 struct notif_event
*r
5642 = (struct notif_event
*) XNEW (struct stop_reply
);
5644 r
->dtr
= stop_reply_dtr
;
5649 /* A client of notification Stop. */
5651 struct notif_client notif_client_stop
=
5655 remote_notif_stop_parse
,
5656 remote_notif_stop_ack
,
5657 remote_notif_stop_can_get_pending_events
,
5658 remote_notif_stop_alloc_reply
,
5662 /* A parameter to pass data in and out. */
5664 struct queue_iter_param
5667 struct stop_reply
*output
;
5670 /* Determine if THREAD is a pending fork parent thread. ARG contains
5671 the pid of the process that owns the threads we want to check, or
5672 -1 if we want to check all threads. */
5675 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5678 if (ws
->kind
== TARGET_WAITKIND_FORKED
5679 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5681 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5688 /* Check whether EVENT is a fork event, and if it is, remove the
5689 fork child from the context list passed in DATA. */
5692 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5693 QUEUE_ITER (stop_reply_p
) *iter
,
5697 struct queue_iter_param
*param
= data
;
5698 struct threads_listing_context
*context
= param
->input
;
5700 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5701 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5703 threads_listing_context_remove (&event
->ws
, context
);
5709 /* If CONTEXT contains any fork child threads that have not been
5710 reported yet, remove them from the CONTEXT list. If such a
5711 thread exists it is because we are stopped at a fork catchpoint
5712 and have not yet called follow_fork, which will set up the
5713 host-side data structures for the new process. */
5716 remove_new_fork_children (struct threads_listing_context
*context
)
5718 struct thread_info
* thread
;
5720 struct notif_client
*notif
= ¬if_client_stop
;
5721 struct queue_iter_param param
;
5723 /* For any threads stopped at a fork event, remove the corresponding
5724 fork child threads from the CONTEXT list. */
5725 ALL_NON_EXITED_THREADS (thread
)
5727 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5729 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5731 threads_listing_context_remove (ws
, context
);
5735 /* Check for any pending fork events (not reported or processed yet)
5736 in process PID and remove those fork child threads from the
5737 CONTEXT list as well. */
5738 remote_notif_get_pending_events (notif
);
5739 param
.input
= context
;
5740 param
.output
= NULL
;
5741 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5742 remove_child_of_pending_fork
, ¶m
);
5745 /* Remove stop replies in the queue if its pid is equal to the given
5749 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5750 QUEUE_ITER (stop_reply_p
) *iter
,
5754 struct queue_iter_param
*param
= data
;
5755 struct inferior
*inf
= param
->input
;
5757 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5759 stop_reply_xfree (event
);
5760 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5766 /* Discard all pending stop replies of inferior INF. */
5769 discard_pending_stop_replies (struct inferior
*inf
)
5772 struct queue_iter_param param
;
5773 struct stop_reply
*reply
;
5774 struct remote_state
*rs
= get_remote_state ();
5775 struct remote_notif_state
*rns
= rs
->notif_state
;
5777 /* This function can be notified when an inferior exists. When the
5778 target is not remote, the notification state is NULL. */
5779 if (rs
->remote_desc
== NULL
)
5782 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5784 /* Discard the in-flight notification. */
5785 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5787 stop_reply_xfree (reply
);
5788 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5792 param
.output
= NULL
;
5793 /* Discard the stop replies we have already pulled with
5795 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5796 remove_stop_reply_for_inferior
, ¶m
);
5799 /* If its remote state is equal to the given remote state,
5800 remove EVENT from the stop reply queue. */
5803 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5804 QUEUE_ITER (stop_reply_p
) *iter
,
5808 struct queue_iter_param
*param
= data
;
5809 struct remote_state
*rs
= param
->input
;
5811 if (event
->rs
== rs
)
5813 stop_reply_xfree (event
);
5814 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5820 /* Discard the stop replies for RS in stop_reply_queue. */
5823 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5825 struct queue_iter_param param
;
5828 param
.output
= NULL
;
5829 /* Discard the stop replies we have already pulled with
5831 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5832 remove_stop_reply_of_remote_state
, ¶m
);
5835 /* A parameter to pass data in and out. */
5838 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5839 QUEUE_ITER (stop_reply_p
) *iter
,
5843 struct queue_iter_param
*param
= data
;
5844 ptid_t
*ptid
= param
->input
;
5846 if (ptid_match (event
->ptid
, *ptid
))
5848 param
->output
= event
;
5849 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5856 /* Remove the first reply in 'stop_reply_queue' which matches
5859 static struct stop_reply
*
5860 remote_notif_remove_queued_reply (ptid_t ptid
)
5862 struct queue_iter_param param
;
5864 param
.input
= &ptid
;
5865 param
.output
= NULL
;
5867 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5868 remote_notif_remove_once_on_match
, ¶m
);
5870 fprintf_unfiltered (gdb_stdlog
,
5871 "notif: discard queued event: 'Stop' in %s\n",
5872 target_pid_to_str (ptid
));
5874 return param
.output
;
5877 /* Look for a queued stop reply belonging to PTID. If one is found,
5878 remove it from the queue, and return it. Returns NULL if none is
5879 found. If there are still queued events left to process, tell the
5880 event loop to get back to target_wait soon. */
5882 static struct stop_reply
*
5883 queued_stop_reply (ptid_t ptid
)
5885 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5887 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5888 /* There's still at least an event left. */
5889 mark_async_event_handler (remote_async_inferior_event_token
);
5894 /* Push a fully parsed stop reply in the stop reply queue. Since we
5895 know that we now have at least one queued event left to pass to the
5896 core side, tell the event loop to get back to target_wait soon. */
5899 push_stop_reply (struct stop_reply
*new_event
)
5901 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5904 fprintf_unfiltered (gdb_stdlog
,
5905 "notif: push 'Stop' %s to queue %d\n",
5906 target_pid_to_str (new_event
->ptid
),
5907 QUEUE_length (stop_reply_p
,
5910 mark_async_event_handler (remote_async_inferior_event_token
);
5914 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5915 QUEUE_ITER (stop_reply_p
) *iter
,
5916 struct stop_reply
*event
,
5919 ptid_t
*ptid
= data
;
5921 return !(ptid_equal (*ptid
, event
->ptid
)
5922 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5925 /* Returns true if we have a stop reply for PTID. */
5928 peek_stop_reply (ptid_t ptid
)
5930 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5931 stop_reply_match_ptid_and_ws
, &ptid
);
5934 /* Skip PACKET until the next semi-colon (or end of string). */
5937 skip_to_semicolon (char *p
)
5939 while (*p
!= '\0' && *p
!= ';')
5944 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
5945 starting with P and ending with PEND matches PREFIX. */
5948 strprefix (const char *p
, const char *pend
, const char *prefix
)
5950 for ( ; p
< pend
; p
++, prefix
++)
5953 return *prefix
== '\0';
5956 /* Parse the stop reply in BUF. Either the function succeeds, and the
5957 result is stored in EVENT, or throws an error. */
5960 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5962 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5966 event
->ptid
= null_ptid
;
5967 event
->rs
= get_remote_state ();
5968 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5969 event
->ws
.value
.integer
= 0;
5970 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5971 event
->regcache
= NULL
;
5976 case 'T': /* Status with PC, SP, FP, ... */
5977 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5978 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5980 n... = register number
5981 r... = register contents
5984 p
= &buf
[3]; /* after Txx */
5990 p1
= strchr (p
, ':');
5992 error (_("Malformed packet(a) (missing colon): %s\n\
5996 error (_("Malformed packet(a) (missing register number): %s\n\
6000 /* Some "registers" are actually extended stop information.
6001 Note if you're adding a new entry here: GDB 7.9 and
6002 earlier assume that all register "numbers" that start
6003 with an hex digit are real register numbers. Make sure
6004 the server only sends such a packet if it knows the
6005 client understands it. */
6007 if (strprefix (p
, p1
, "thread"))
6008 event
->ptid
= read_ptid (++p1
, &p
);
6009 else if (strprefix (p
, p1
, "watch")
6010 || strprefix (p
, p1
, "rwatch")
6011 || strprefix (p
, p1
, "awatch"))
6013 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6014 p
= unpack_varlen_hex (++p1
, &addr
);
6015 event
->watch_data_address
= (CORE_ADDR
) addr
;
6017 else if (strprefix (p
, p1
, "swbreak"))
6019 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6021 /* Make sure the stub doesn't forget to indicate support
6023 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6024 error (_("Unexpected swbreak stop reason"));
6026 /* The value part is documented as "must be empty",
6027 though we ignore it, in case we ever decide to make
6028 use of it in a backward compatible way. */
6029 p
= skip_to_semicolon (p1
+ 1);
6031 else if (strprefix (p
, p1
, "hwbreak"))
6033 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6035 /* Make sure the stub doesn't forget to indicate support
6037 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6038 error (_("Unexpected hwbreak stop reason"));
6041 p
= skip_to_semicolon (p1
+ 1);
6043 else if (strprefix (p
, p1
, "library"))
6045 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6046 p
= skip_to_semicolon (p1
+ 1);
6048 else if (strprefix (p
, p1
, "replaylog"))
6050 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6051 /* p1 will indicate "begin" or "end", but it makes
6052 no difference for now, so ignore it. */
6053 p
= skip_to_semicolon (p1
+ 1);
6055 else if (strprefix (p
, p1
, "core"))
6059 p
= unpack_varlen_hex (++p1
, &c
);
6062 else if (strprefix (p
, p1
, "fork"))
6064 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6065 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6067 else if (strprefix (p
, p1
, "vfork"))
6069 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6070 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6072 else if (strprefix (p
, p1
, "vforkdone"))
6074 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6075 p
= skip_to_semicolon (p1
+ 1);
6082 /* Maybe a real ``P'' register number. */
6083 p_temp
= unpack_varlen_hex (p
, &pnum
);
6084 /* If the first invalid character is the colon, we got a
6085 register number. Otherwise, it's an unknown stop
6089 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6090 cached_reg_t cached_reg
;
6093 error (_("Remote sent bad register number %s: %s\n\
6095 hex_string (pnum
), p
, buf
);
6097 cached_reg
.num
= reg
->regnum
;
6100 fieldsize
= hex2bin (p
, cached_reg
.data
,
6101 register_size (target_gdbarch (),
6104 if (fieldsize
< register_size (target_gdbarch (),
6106 warning (_("Remote reply is too short: %s"), buf
);
6108 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6112 /* Not a number. Silently skip unknown optional
6114 p
= skip_to_semicolon (p1
+ 1);
6119 error (_("Remote register badly formatted: %s\nhere: %s"),
6124 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6128 case 'S': /* Old style status, just signal only. */
6132 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6133 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6134 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6135 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6137 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6140 case 'W': /* Target exited. */
6147 /* GDB used to accept only 2 hex chars here. Stubs should
6148 only send more if they detect GDB supports multi-process
6150 p
= unpack_varlen_hex (&buf
[1], &value
);
6154 /* The remote process exited. */
6155 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6156 event
->ws
.value
.integer
= value
;
6160 /* The remote process exited with a signal. */
6161 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6162 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6163 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6165 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6168 /* If no process is specified, assume inferior_ptid. */
6169 pid
= ptid_get_pid (inferior_ptid
);
6178 else if (startswith (p
, "process:"))
6182 p
+= sizeof ("process:") - 1;
6183 unpack_varlen_hex (p
, &upid
);
6187 error (_("unknown stop reply packet: %s"), buf
);
6190 error (_("unknown stop reply packet: %s"), buf
);
6191 event
->ptid
= pid_to_ptid (pid
);
6196 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6197 error (_("No process or thread specified in stop reply: %s"), buf
);
6200 /* When the stub wants to tell GDB about a new notification reply, it
6201 sends a notification (%Stop, for example). Those can come it at
6202 any time, hence, we have to make sure that any pending
6203 putpkt/getpkt sequence we're making is finished, before querying
6204 the stub for more events with the corresponding ack command
6205 (vStopped, for example). E.g., if we started a vStopped sequence
6206 immediately upon receiving the notification, something like this
6214 1.6) <-- (registers reply to step #1.3)
6216 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6219 To solve this, whenever we parse a %Stop notification successfully,
6220 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6221 doing whatever we were doing:
6227 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6228 2.5) <-- (registers reply to step #2.3)
6230 Eventualy after step #2.5, we return to the event loop, which
6231 notices there's an event on the
6232 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6233 associated callback --- the function below. At this point, we're
6234 always safe to start a vStopped sequence. :
6237 2.7) <-- T05 thread:2
6243 remote_notif_get_pending_events (struct notif_client
*nc
)
6245 struct remote_state
*rs
= get_remote_state ();
6247 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6250 fprintf_unfiltered (gdb_stdlog
,
6251 "notif: process: '%s' ack pending event\n",
6255 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6256 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6260 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6261 if (strcmp (rs
->buf
, "OK") == 0)
6264 remote_notif_ack (nc
, rs
->buf
);
6270 fprintf_unfiltered (gdb_stdlog
,
6271 "notif: process: '%s' no pending reply\n",
6276 /* Called when it is decided that STOP_REPLY holds the info of the
6277 event that is to be returned to the core. This function always
6278 destroys STOP_REPLY. */
6281 process_stop_reply (struct stop_reply
*stop_reply
,
6282 struct target_waitstatus
*status
)
6286 *status
= stop_reply
->ws
;
6287 ptid
= stop_reply
->ptid
;
6289 /* If no thread/process was reported by the stub, assume the current
6291 if (ptid_equal (ptid
, null_ptid
))
6292 ptid
= inferior_ptid
;
6294 if (status
->kind
!= TARGET_WAITKIND_EXITED
6295 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6297 struct remote_state
*rs
= get_remote_state ();
6299 /* Expedited registers. */
6300 if (stop_reply
->regcache
)
6302 struct regcache
*regcache
6303 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6308 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6310 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6311 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6314 rs
->stop_reason
= stop_reply
->stop_reason
;
6315 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6317 remote_notice_new_inferior (ptid
, 0);
6318 demand_private_info (ptid
)->core
= stop_reply
->core
;
6321 stop_reply_xfree (stop_reply
);
6325 /* The non-stop mode version of target_wait. */
6328 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6330 struct remote_state
*rs
= get_remote_state ();
6331 struct stop_reply
*stop_reply
;
6335 /* If in non-stop mode, get out of getpkt even if a
6336 notification is received. */
6338 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6339 0 /* forever */, &is_notif
);
6342 if (ret
!= -1 && !is_notif
)
6345 case 'E': /* Error of some sort. */
6346 /* We're out of sync with the target now. Did it continue
6347 or not? We can't tell which thread it was in non-stop,
6348 so just ignore this. */
6349 warning (_("Remote failure reply: %s"), rs
->buf
);
6351 case 'O': /* Console output. */
6352 remote_console_output (rs
->buf
+ 1);
6355 warning (_("Invalid remote reply: %s"), rs
->buf
);
6359 /* Acknowledge a pending stop reply that may have arrived in the
6361 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6362 remote_notif_get_pending_events (¬if_client_stop
);
6364 /* If indeed we noticed a stop reply, we're done. */
6365 stop_reply
= queued_stop_reply (ptid
);
6366 if (stop_reply
!= NULL
)
6367 return process_stop_reply (stop_reply
, status
);
6369 /* Still no event. If we're just polling for an event, then
6370 return to the event loop. */
6371 if (options
& TARGET_WNOHANG
)
6373 status
->kind
= TARGET_WAITKIND_IGNORE
;
6374 return minus_one_ptid
;
6377 /* Otherwise do a blocking wait. */
6378 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6379 1 /* forever */, &is_notif
);
6383 /* Wait until the remote machine stops, then return, storing status in
6384 STATUS just as `wait' would. */
6387 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6389 struct remote_state
*rs
= get_remote_state ();
6390 ptid_t event_ptid
= null_ptid
;
6392 struct stop_reply
*stop_reply
;
6396 status
->kind
= TARGET_WAITKIND_IGNORE
;
6397 status
->value
.integer
= 0;
6399 stop_reply
= queued_stop_reply (ptid
);
6400 if (stop_reply
!= NULL
)
6401 return process_stop_reply (stop_reply
, status
);
6403 if (rs
->cached_wait_status
)
6404 /* Use the cached wait status, but only once. */
6405 rs
->cached_wait_status
= 0;
6410 int forever
= ((options
& TARGET_WNOHANG
) == 0
6411 && wait_forever_enabled_p
);
6413 if (!rs
->waiting_for_stop_reply
)
6415 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6416 return minus_one_ptid
;
6419 if (!target_is_async_p ())
6421 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6422 /* If the user hit C-c before this packet, or between packets,
6423 pretend that it was hit right here. */
6424 if (check_quit_flag ())
6427 sync_remote_interrupt (SIGINT
);
6431 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6432 _never_ wait for ever -> test on target_is_async_p().
6433 However, before we do that we need to ensure that the caller
6434 knows how to take the target into/out of async mode. */
6435 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6436 forever
, &is_notif
);
6438 if (!target_is_async_p ())
6439 signal (SIGINT
, ofunc
);
6441 /* GDB gets a notification. Return to core as this event is
6443 if (ret
!= -1 && is_notif
)
6444 return minus_one_ptid
;
6446 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6447 return minus_one_ptid
;
6452 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6454 /* We got something. */
6455 rs
->waiting_for_stop_reply
= 0;
6457 /* Assume that the target has acknowledged Ctrl-C unless we receive
6458 an 'F' or 'O' packet. */
6459 if (buf
[0] != 'F' && buf
[0] != 'O')
6460 rs
->ctrlc_pending_p
= 0;
6464 case 'E': /* Error of some sort. */
6465 /* We're out of sync with the target now. Did it continue or
6466 not? Not is more likely, so report a stop. */
6467 warning (_("Remote failure reply: %s"), buf
);
6468 status
->kind
= TARGET_WAITKIND_STOPPED
;
6469 status
->value
.sig
= GDB_SIGNAL_0
;
6471 case 'F': /* File-I/O request. */
6472 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6473 rs
->ctrlc_pending_p
= 0;
6475 case 'T': case 'S': case 'X': case 'W':
6477 struct stop_reply
*stop_reply
6478 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6481 event_ptid
= process_stop_reply (stop_reply
, status
);
6484 case 'O': /* Console output. */
6485 remote_console_output (buf
+ 1);
6487 /* The target didn't really stop; keep waiting. */
6488 rs
->waiting_for_stop_reply
= 1;
6492 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6494 /* Zero length reply means that we tried 'S' or 'C' and the
6495 remote system doesn't support it. */
6496 target_terminal_ours_for_output ();
6498 ("Can't send signals to this remote system. %s not sent.\n",
6499 gdb_signal_to_name (rs
->last_sent_signal
));
6500 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6501 target_terminal_inferior ();
6503 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6504 putpkt ((char *) buf
);
6506 /* We just told the target to resume, so a stop reply is in
6508 rs
->waiting_for_stop_reply
= 1;
6511 /* else fallthrough */
6513 warning (_("Invalid remote reply: %s"), buf
);
6515 rs
->waiting_for_stop_reply
= 1;
6519 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6521 /* Nothing interesting happened. If we're doing a non-blocking
6522 poll, we're done. Otherwise, go back to waiting. */
6523 if (options
& TARGET_WNOHANG
)
6524 return minus_one_ptid
;
6528 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6529 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6531 if (!ptid_equal (event_ptid
, null_ptid
))
6532 record_currthread (rs
, event_ptid
);
6534 event_ptid
= inferior_ptid
;
6537 /* A process exit. Invalidate our notion of current thread. */
6538 record_currthread (rs
, minus_one_ptid
);
6543 /* Wait until the remote machine stops, then return, storing status in
6544 STATUS just as `wait' would. */
6547 remote_wait (struct target_ops
*ops
,
6548 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6553 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6555 event_ptid
= remote_wait_as (ptid
, status
, options
);
6557 if (target_is_async_p ())
6559 /* If there are are events left in the queue tell the event loop
6561 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6562 mark_async_event_handler (remote_async_inferior_event_token
);
6568 /* Fetch a single register using a 'p' packet. */
6571 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6573 struct remote_state
*rs
= get_remote_state ();
6575 char regp
[MAX_REGISTER_SIZE
];
6578 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6581 if (reg
->pnum
== -1)
6586 p
+= hexnumstr (p
, reg
->pnum
);
6589 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6593 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6597 case PACKET_UNKNOWN
:
6600 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6601 gdbarch_register_name (get_regcache_arch (regcache
),
6606 /* If this register is unfetchable, tell the regcache. */
6609 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6613 /* Otherwise, parse and supply the value. */
6619 error (_("fetch_register_using_p: early buf termination"));
6621 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6624 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6628 /* Fetch the registers included in the target's 'g' packet. */
6631 send_g_packet (void)
6633 struct remote_state
*rs
= get_remote_state ();
6636 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6637 remote_send (&rs
->buf
, &rs
->buf_size
);
6639 /* We can get out of synch in various cases. If the first character
6640 in the buffer is not a hex character, assume that has happened
6641 and try to fetch another packet to read. */
6642 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6643 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6644 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6645 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6648 fprintf_unfiltered (gdb_stdlog
,
6649 "Bad register packet; fetching a new packet\n");
6650 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6653 buf_len
= strlen (rs
->buf
);
6655 /* Sanity check the received packet. */
6656 if (buf_len
% 2 != 0)
6657 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6663 process_g_packet (struct regcache
*regcache
)
6665 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6666 struct remote_state
*rs
= get_remote_state ();
6667 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6672 buf_len
= strlen (rs
->buf
);
6674 /* Further sanity checks, with knowledge of the architecture. */
6675 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6676 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6678 /* Save the size of the packet sent to us by the target. It is used
6679 as a heuristic when determining the max size of packets that the
6680 target can safely receive. */
6681 if (rsa
->actual_register_packet_size
== 0)
6682 rsa
->actual_register_packet_size
= buf_len
;
6684 /* If this is smaller than we guessed the 'g' packet would be,
6685 update our records. A 'g' reply that doesn't include a register's
6686 value implies either that the register is not available, or that
6687 the 'p' packet must be used. */
6688 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6690 rsa
->sizeof_g_packet
= buf_len
/ 2;
6692 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6694 if (rsa
->regs
[i
].pnum
== -1)
6697 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6698 rsa
->regs
[i
].in_g_packet
= 0;
6700 rsa
->regs
[i
].in_g_packet
= 1;
6704 regs
= alloca (rsa
->sizeof_g_packet
);
6706 /* Unimplemented registers read as all bits zero. */
6707 memset (regs
, 0, rsa
->sizeof_g_packet
);
6709 /* Reply describes registers byte by byte, each byte encoded as two
6710 hex characters. Suck them all up, then supply them to the
6711 register cacheing/storage mechanism. */
6714 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6716 if (p
[0] == 0 || p
[1] == 0)
6717 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6718 internal_error (__FILE__
, __LINE__
,
6719 _("unexpected end of 'g' packet reply"));
6721 if (p
[0] == 'x' && p
[1] == 'x')
6722 regs
[i
] = 0; /* 'x' */
6724 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6728 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6730 struct packet_reg
*r
= &rsa
->regs
[i
];
6734 if (r
->offset
* 2 >= strlen (rs
->buf
))
6735 /* This shouldn't happen - we adjusted in_g_packet above. */
6736 internal_error (__FILE__
, __LINE__
,
6737 _("unexpected end of 'g' packet reply"));
6738 else if (rs
->buf
[r
->offset
* 2] == 'x')
6740 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6741 /* The register isn't available, mark it as such (at
6742 the same time setting the value to zero). */
6743 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6746 regcache_raw_supply (regcache
, r
->regnum
,
6753 fetch_registers_using_g (struct regcache
*regcache
)
6756 process_g_packet (regcache
);
6759 /* Make the remote selected traceframe match GDB's selected
6763 set_remote_traceframe (void)
6766 struct remote_state
*rs
= get_remote_state ();
6768 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6771 /* Avoid recursion, remote_trace_find calls us again. */
6772 rs
->remote_traceframe_number
= get_traceframe_number ();
6774 newnum
= target_trace_find (tfind_number
,
6775 get_traceframe_number (), 0, 0, NULL
);
6777 /* Should not happen. If it does, all bets are off. */
6778 if (newnum
!= get_traceframe_number ())
6779 warning (_("could not set remote traceframe"));
6783 remote_fetch_registers (struct target_ops
*ops
,
6784 struct regcache
*regcache
, int regnum
)
6786 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6789 set_remote_traceframe ();
6790 set_general_thread (inferior_ptid
);
6794 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6796 gdb_assert (reg
!= NULL
);
6798 /* If this register might be in the 'g' packet, try that first -
6799 we are likely to read more than one register. If this is the
6800 first 'g' packet, we might be overly optimistic about its
6801 contents, so fall back to 'p'. */
6802 if (reg
->in_g_packet
)
6804 fetch_registers_using_g (regcache
);
6805 if (reg
->in_g_packet
)
6809 if (fetch_register_using_p (regcache
, reg
))
6812 /* This register is not available. */
6813 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6818 fetch_registers_using_g (regcache
);
6820 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6821 if (!rsa
->regs
[i
].in_g_packet
)
6822 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6824 /* This register is not available. */
6825 regcache_raw_supply (regcache
, i
, NULL
);
6829 /* Prepare to store registers. Since we may send them all (using a
6830 'G' request), we have to read out the ones we don't want to change
6834 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6836 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6838 gdb_byte buf
[MAX_REGISTER_SIZE
];
6840 /* Make sure the entire registers array is valid. */
6841 switch (packet_support (PACKET_P
))
6843 case PACKET_DISABLE
:
6844 case PACKET_SUPPORT_UNKNOWN
:
6845 /* Make sure all the necessary registers are cached. */
6846 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6847 if (rsa
->regs
[i
].in_g_packet
)
6848 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6855 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6856 packet was not recognized. */
6859 store_register_using_P (const struct regcache
*regcache
,
6860 struct packet_reg
*reg
)
6862 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6863 struct remote_state
*rs
= get_remote_state ();
6864 /* Try storing a single register. */
6865 char *buf
= rs
->buf
;
6866 gdb_byte regp
[MAX_REGISTER_SIZE
];
6869 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6872 if (reg
->pnum
== -1)
6875 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6876 p
= buf
+ strlen (buf
);
6877 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6878 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6880 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6882 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6887 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6888 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6889 case PACKET_UNKNOWN
:
6892 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6896 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6897 contents of the register cache buffer. FIXME: ignores errors. */
6900 store_registers_using_G (const struct regcache
*regcache
)
6902 struct remote_state
*rs
= get_remote_state ();
6903 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6907 /* Extract all the registers in the regcache copying them into a
6912 regs
= alloca (rsa
->sizeof_g_packet
);
6913 memset (regs
, 0, rsa
->sizeof_g_packet
);
6914 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6916 struct packet_reg
*r
= &rsa
->regs
[i
];
6919 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6923 /* Command describes registers byte by byte,
6924 each byte encoded as two hex characters. */
6927 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6929 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6931 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6932 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6933 error (_("Could not write registers; remote failure reply '%s'"),
6937 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6938 of the register cache buffer. FIXME: ignores errors. */
6941 remote_store_registers (struct target_ops
*ops
,
6942 struct regcache
*regcache
, int regnum
)
6944 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6947 set_remote_traceframe ();
6948 set_general_thread (inferior_ptid
);
6952 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6954 gdb_assert (reg
!= NULL
);
6956 /* Always prefer to store registers using the 'P' packet if
6957 possible; we often change only a small number of registers.
6958 Sometimes we change a larger number; we'd need help from a
6959 higher layer to know to use 'G'. */
6960 if (store_register_using_P (regcache
, reg
))
6963 /* For now, don't complain if we have no way to write the
6964 register. GDB loses track of unavailable registers too
6965 easily. Some day, this may be an error. We don't have
6966 any way to read the register, either... */
6967 if (!reg
->in_g_packet
)
6970 store_registers_using_G (regcache
);
6974 store_registers_using_G (regcache
);
6976 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6977 if (!rsa
->regs
[i
].in_g_packet
)
6978 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6979 /* See above for why we do not issue an error here. */
6984 /* Return the number of hex digits in num. */
6987 hexnumlen (ULONGEST num
)
6991 for (i
= 0; num
!= 0; i
++)
6997 /* Set BUF to the minimum number of hex digits representing NUM. */
7000 hexnumstr (char *buf
, ULONGEST num
)
7002 int len
= hexnumlen (num
);
7004 return hexnumnstr (buf
, num
, len
);
7008 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7011 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7017 for (i
= width
- 1; i
>= 0; i
--)
7019 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7026 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7029 remote_address_masked (CORE_ADDR addr
)
7031 unsigned int address_size
= remote_address_size
;
7033 /* If "remoteaddresssize" was not set, default to target address size. */
7035 address_size
= gdbarch_addr_bit (target_gdbarch ());
7037 if (address_size
> 0
7038 && address_size
< (sizeof (ULONGEST
) * 8))
7040 /* Only create a mask when that mask can safely be constructed
7041 in a ULONGEST variable. */
7044 mask
= (mask
<< address_size
) - 1;
7050 /* Determine whether the remote target supports binary downloading.
7051 This is accomplished by sending a no-op memory write of zero length
7052 to the target at the specified address. It does not suffice to send
7053 the whole packet, since many stubs strip the eighth bit and
7054 subsequently compute a wrong checksum, which causes real havoc with
7057 NOTE: This can still lose if the serial line is not eight-bit
7058 clean. In cases like this, the user should clear "remote
7062 check_binary_download (CORE_ADDR addr
)
7064 struct remote_state
*rs
= get_remote_state ();
7066 switch (packet_support (PACKET_X
))
7068 case PACKET_DISABLE
:
7072 case PACKET_SUPPORT_UNKNOWN
:
7078 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7080 p
+= hexnumstr (p
, (ULONGEST
) 0);
7084 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7085 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7087 if (rs
->buf
[0] == '\0')
7090 fprintf_unfiltered (gdb_stdlog
,
7091 "binary downloading NOT "
7092 "supported by target\n");
7093 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7098 fprintf_unfiltered (gdb_stdlog
,
7099 "binary downloading supported by target\n");
7100 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7107 /* Helper function to resize the payload in order to try to get a good
7108 alignment. We try to write an amount of data such that the next write will
7109 start on an address aligned on REMOTE_ALIGN_WRITES. */
7112 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7114 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7117 /* Write memory data directly to the remote machine.
7118 This does not inform the data cache; the data cache uses this.
7119 HEADER is the starting part of the packet.
7120 MEMADDR is the address in the remote memory space.
7121 MYADDR is the address of the buffer in our space.
7122 LEN_UNITS is the number of addressable units to write.
7123 UNIT_SIZE is the length in bytes of an addressable unit.
7124 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7125 should send data as binary ('X'), or hex-encoded ('M').
7127 The function creates packet of the form
7128 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7130 where encoding of <DATA> is terminated by PACKET_FORMAT.
7132 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7135 Return the transferred status, error or OK (an
7136 'enum target_xfer_status' value). Save the number of addressable units
7137 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7139 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7140 exchange between gdb and the stub could look like (?? in place of the
7146 -> $M1000,3:eeeeffffeeee#??
7150 <- eeeeffffeeeedddd */
7152 static enum target_xfer_status
7153 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7154 const gdb_byte
*myaddr
, ULONGEST len_units
,
7155 int unit_size
, ULONGEST
*xfered_len_units
,
7156 char packet_format
, int use_length
)
7158 struct remote_state
*rs
= get_remote_state ();
7164 int payload_capacity_bytes
;
7165 int payload_length_bytes
;
7167 if (packet_format
!= 'X' && packet_format
!= 'M')
7168 internal_error (__FILE__
, __LINE__
,
7169 _("remote_write_bytes_aux: bad packet format"));
7172 return TARGET_XFER_EOF
;
7174 payload_capacity_bytes
= get_memory_write_packet_size ();
7176 /* The packet buffer will be large enough for the payload;
7177 get_memory_packet_size ensures this. */
7180 /* Compute the size of the actual payload by subtracting out the
7181 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7183 payload_capacity_bytes
-= strlen ("$,:#NN");
7185 /* The comma won't be used. */
7186 payload_capacity_bytes
+= 1;
7187 payload_capacity_bytes
-= strlen (header
);
7188 payload_capacity_bytes
-= hexnumlen (memaddr
);
7190 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7192 strcat (rs
->buf
, header
);
7193 p
= rs
->buf
+ strlen (header
);
7195 /* Compute a best guess of the number of bytes actually transfered. */
7196 if (packet_format
== 'X')
7198 /* Best guess at number of bytes that will fit. */
7199 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7201 payload_capacity_bytes
-= hexnumlen (todo_units
);
7202 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7206 /* Number of bytes that will fit. */
7207 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7209 payload_capacity_bytes
-= hexnumlen (todo_units
);
7210 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7213 if (todo_units
<= 0)
7214 internal_error (__FILE__
, __LINE__
,
7215 _("minimum packet size too small to write data"));
7217 /* If we already need another packet, then try to align the end
7218 of this packet to a useful boundary. */
7219 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7220 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7222 /* Append "<memaddr>". */
7223 memaddr
= remote_address_masked (memaddr
);
7224 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7231 /* Append the length and retain its location and size. It may need to be
7232 adjusted once the packet body has been created. */
7234 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7242 /* Append the packet body. */
7243 if (packet_format
== 'X')
7245 /* Binary mode. Send target system values byte by byte, in
7246 increasing byte addresses. Only escape certain critical
7248 payload_length_bytes
=
7249 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7250 &units_written
, payload_capacity_bytes
);
7252 /* If not all TODO units fit, then we'll need another packet. Make
7253 a second try to keep the end of the packet aligned. Don't do
7254 this if the packet is tiny. */
7255 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7259 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7261 if (new_todo_units
!= units_written
)
7262 payload_length_bytes
=
7263 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7264 (gdb_byte
*) p
, &units_written
,
7265 payload_capacity_bytes
);
7268 p
+= payload_length_bytes
;
7269 if (use_length
&& units_written
< todo_units
)
7271 /* Escape chars have filled up the buffer prematurely,
7272 and we have actually sent fewer units than planned.
7273 Fix-up the length field of the packet. Use the same
7274 number of characters as before. */
7275 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7277 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7282 /* Normal mode: Send target system values byte by byte, in
7283 increasing byte addresses. Each byte is encoded as a two hex
7285 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7286 units_written
= todo_units
;
7289 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7292 if (rs
->buf
[0] == 'E')
7293 return TARGET_XFER_E_IO
;
7295 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7296 send fewer units than we'd planned. */
7297 *xfered_len_units
= (ULONGEST
) units_written
;
7298 return TARGET_XFER_OK
;
7301 /* Write memory data directly to the remote machine.
7302 This does not inform the data cache; the data cache uses this.
7303 MEMADDR is the address in the remote memory space.
7304 MYADDR is the address of the buffer in our space.
7305 LEN is the number of bytes.
7307 Return the transferred status, error or OK (an
7308 'enum target_xfer_status' value). Save the number of bytes
7309 transferred in *XFERED_LEN. Only transfer a single packet. */
7311 static enum target_xfer_status
7312 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7313 int unit_size
, ULONGEST
*xfered_len
)
7315 char *packet_format
= 0;
7317 /* Check whether the target supports binary download. */
7318 check_binary_download (memaddr
);
7320 switch (packet_support (PACKET_X
))
7323 packet_format
= "X";
7325 case PACKET_DISABLE
:
7326 packet_format
= "M";
7328 case PACKET_SUPPORT_UNKNOWN
:
7329 internal_error (__FILE__
, __LINE__
,
7330 _("remote_write_bytes: bad internal state"));
7332 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7335 return remote_write_bytes_aux (packet_format
,
7336 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7337 packet_format
[0], 1);
7340 /* Read memory data directly from the remote machine.
7341 This does not use the data cache; the data cache uses this.
7342 MEMADDR is the address in the remote memory space.
7343 MYADDR is the address of the buffer in our space.
7344 LEN_UNITS is the number of addressable memory units to read..
7345 UNIT_SIZE is the length in bytes of an addressable unit.
7347 Return the transferred status, error or OK (an
7348 'enum target_xfer_status' value). Save the number of bytes
7349 transferred in *XFERED_LEN_UNITS.
7351 See the comment of remote_write_bytes_aux for an example of
7352 memory read/write exchange between gdb and the stub. */
7354 static enum target_xfer_status
7355 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7356 int unit_size
, ULONGEST
*xfered_len_units
)
7358 struct remote_state
*rs
= get_remote_state ();
7359 int buf_size_bytes
; /* Max size of packet output buffer. */
7364 buf_size_bytes
= get_memory_read_packet_size ();
7365 /* The packet buffer will be large enough for the payload;
7366 get_memory_packet_size ensures this. */
7368 /* Number of units that will fit. */
7369 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7371 /* Construct "m"<memaddr>","<len>". */
7372 memaddr
= remote_address_masked (memaddr
);
7375 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7377 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7380 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7381 if (rs
->buf
[0] == 'E'
7382 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7383 && rs
->buf
[3] == '\0')
7384 return TARGET_XFER_E_IO
;
7385 /* Reply describes memory byte by byte, each byte encoded as two hex
7388 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7389 /* Return what we have. Let higher layers handle partial reads. */
7390 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7391 return TARGET_XFER_OK
;
7394 /* Using the set of read-only target sections of remote, read live
7397 For interface/parameters/return description see target.h,
7400 static enum target_xfer_status
7401 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7402 ULONGEST memaddr
, ULONGEST len
,
7403 int unit_size
, ULONGEST
*xfered_len
)
7405 struct target_section
*secp
;
7406 struct target_section_table
*table
;
7408 secp
= target_section_by_addr (ops
, memaddr
);
7410 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7411 secp
->the_bfd_section
)
7414 struct target_section
*p
;
7415 ULONGEST memend
= memaddr
+ len
;
7417 table
= target_get_section_table (ops
);
7419 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7421 if (memaddr
>= p
->addr
)
7423 if (memend
<= p
->endaddr
)
7425 /* Entire transfer is within this section. */
7426 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7429 else if (memaddr
>= p
->endaddr
)
7431 /* This section ends before the transfer starts. */
7436 /* This section overlaps the transfer. Just do half. */
7437 len
= p
->endaddr
- memaddr
;
7438 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7445 return TARGET_XFER_EOF
;
7448 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7449 first if the requested memory is unavailable in traceframe.
7450 Otherwise, fall back to remote_read_bytes_1. */
7452 static enum target_xfer_status
7453 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7454 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7455 ULONGEST
*xfered_len
)
7458 return TARGET_XFER_EOF
;
7460 if (get_traceframe_number () != -1)
7462 VEC(mem_range_s
) *available
;
7464 /* If we fail to get the set of available memory, then the
7465 target does not support querying traceframe info, and so we
7466 attempt reading from the traceframe anyway (assuming the
7467 target implements the old QTro packet then). */
7468 if (traceframe_available_memory (&available
, memaddr
, len
))
7470 struct cleanup
*old_chain
;
7472 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7474 if (VEC_empty (mem_range_s
, available
)
7475 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7477 enum target_xfer_status res
;
7479 /* Don't read into the traceframe's available
7481 if (!VEC_empty (mem_range_s
, available
))
7483 LONGEST oldlen
= len
;
7485 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7486 gdb_assert (len
<= oldlen
);
7489 do_cleanups (old_chain
);
7491 /* This goes through the topmost target again. */
7492 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7493 len
, unit_size
, xfered_len
);
7494 if (res
== TARGET_XFER_OK
)
7495 return TARGET_XFER_OK
;
7498 /* No use trying further, we know some memory starting
7499 at MEMADDR isn't available. */
7501 return TARGET_XFER_UNAVAILABLE
;
7505 /* Don't try to read more than how much is available, in
7506 case the target implements the deprecated QTro packet to
7507 cater for older GDBs (the target's knowledge of read-only
7508 sections may be outdated by now). */
7509 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7511 do_cleanups (old_chain
);
7515 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7520 /* Sends a packet with content determined by the printf format string
7521 FORMAT and the remaining arguments, then gets the reply. Returns
7522 whether the packet was a success, a failure, or unknown. */
7524 static enum packet_result
remote_send_printf (const char *format
, ...)
7525 ATTRIBUTE_PRINTF (1, 2);
7527 static enum packet_result
7528 remote_send_printf (const char *format
, ...)
7530 struct remote_state
*rs
= get_remote_state ();
7531 int max_size
= get_remote_packet_size ();
7534 va_start (ap
, format
);
7537 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7538 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7540 if (putpkt (rs
->buf
) < 0)
7541 error (_("Communication problem with target."));
7544 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7546 return packet_check_result (rs
->buf
);
7550 restore_remote_timeout (void *p
)
7552 int value
= *(int *)p
;
7554 remote_timeout
= value
;
7557 /* Flash writing can take quite some time. We'll set
7558 effectively infinite timeout for flash operations.
7559 In future, we'll need to decide on a better approach. */
7560 static const int remote_flash_timeout
= 1000;
7563 remote_flash_erase (struct target_ops
*ops
,
7564 ULONGEST address
, LONGEST length
)
7566 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7567 int saved_remote_timeout
= remote_timeout
;
7568 enum packet_result ret
;
7569 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7570 &saved_remote_timeout
);
7572 remote_timeout
= remote_flash_timeout
;
7574 ret
= remote_send_printf ("vFlashErase:%s,%s",
7575 phex (address
, addr_size
),
7579 case PACKET_UNKNOWN
:
7580 error (_("Remote target does not support flash erase"));
7582 error (_("Error erasing flash with vFlashErase packet"));
7587 do_cleanups (back_to
);
7590 static enum target_xfer_status
7591 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7592 ULONGEST length
, ULONGEST
*xfered_len
,
7593 const gdb_byte
*data
)
7595 int saved_remote_timeout
= remote_timeout
;
7596 enum target_xfer_status ret
;
7597 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7598 &saved_remote_timeout
);
7600 remote_timeout
= remote_flash_timeout
;
7601 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7603 do_cleanups (back_to
);
7609 remote_flash_done (struct target_ops
*ops
)
7611 int saved_remote_timeout
= remote_timeout
;
7613 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7614 &saved_remote_timeout
);
7616 remote_timeout
= remote_flash_timeout
;
7617 ret
= remote_send_printf ("vFlashDone");
7618 do_cleanups (back_to
);
7622 case PACKET_UNKNOWN
:
7623 error (_("Remote target does not support vFlashDone"));
7625 error (_("Error finishing flash operation"));
7632 remote_files_info (struct target_ops
*ignore
)
7634 puts_filtered ("Debugging a target over a serial line.\n");
7637 /* Stuff for dealing with the packets which are part of this protocol.
7638 See comment at top of file for details. */
7640 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7641 error to higher layers. Called when a serial error is detected.
7642 The exception message is STRING, followed by a colon and a blank,
7643 the system error message for errno at function entry and final dot
7644 for output compatibility with throw_perror_with_name. */
7647 unpush_and_perror (const char *string
)
7649 int saved_errno
= errno
;
7651 remote_unpush_target ();
7652 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7653 safe_strerror (saved_errno
));
7656 /* Read a single character from the remote end. */
7659 readchar (int timeout
)
7662 struct remote_state
*rs
= get_remote_state ();
7664 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7669 switch ((enum serial_rc
) ch
)
7672 remote_unpush_target ();
7673 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7676 unpush_and_perror (_("Remote communication error. "
7677 "Target disconnected."));
7679 case SERIAL_TIMEOUT
:
7685 /* Wrapper for serial_write that closes the target and throws if
7689 remote_serial_write (const char *str
, int len
)
7691 struct remote_state
*rs
= get_remote_state ();
7693 if (serial_write (rs
->remote_desc
, str
, len
))
7695 unpush_and_perror (_("Remote communication error. "
7696 "Target disconnected."));
7700 /* Send the command in *BUF to the remote machine, and read the reply
7701 into *BUF. Report an error if we get an error reply. Resize
7702 *BUF using xrealloc if necessary to hold the result, and update
7706 remote_send (char **buf
,
7710 getpkt (buf
, sizeof_buf
, 0);
7712 if ((*buf
)[0] == 'E')
7713 error (_("Remote failure reply: %s"), *buf
);
7716 /* Return a pointer to an xmalloc'ed string representing an escaped
7717 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7718 etc. The caller is responsible for releasing the returned
7722 escape_buffer (const char *buf
, int n
)
7724 struct cleanup
*old_chain
;
7725 struct ui_file
*stb
;
7728 stb
= mem_fileopen ();
7729 old_chain
= make_cleanup_ui_file_delete (stb
);
7731 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7732 str
= ui_file_xstrdup (stb
, NULL
);
7733 do_cleanups (old_chain
);
7737 /* Display a null-terminated packet on stdout, for debugging, using C
7741 print_packet (const char *buf
)
7743 puts_filtered ("\"");
7744 fputstr_filtered (buf
, '"', gdb_stdout
);
7745 puts_filtered ("\"");
7749 putpkt (const char *buf
)
7751 return putpkt_binary (buf
, strlen (buf
));
7754 /* Send a packet to the remote machine, with error checking. The data
7755 of the packet is in BUF. The string in BUF can be at most
7756 get_remote_packet_size () - 5 to account for the $, # and checksum,
7757 and for a possible /0 if we are debugging (remote_debug) and want
7758 to print the sent packet as a string. */
7761 putpkt_binary (const char *buf
, int cnt
)
7763 struct remote_state
*rs
= get_remote_state ();
7765 unsigned char csum
= 0;
7766 char *buf2
= alloca (cnt
+ 6);
7773 /* Catch cases like trying to read memory or listing threads while
7774 we're waiting for a stop reply. The remote server wouldn't be
7775 ready to handle this request, so we'd hang and timeout. We don't
7776 have to worry about this in synchronous mode, because in that
7777 case it's not possible to issue a command while the target is
7778 running. This is not a problem in non-stop mode, because in that
7779 case, the stub is always ready to process serial input. */
7780 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7782 error (_("Cannot execute this command while the target is running.\n"
7783 "Use the \"interrupt\" command to stop the target\n"
7784 "and then try again."));
7787 /* We're sending out a new packet. Make sure we don't look at a
7788 stale cached response. */
7789 rs
->cached_wait_status
= 0;
7791 /* Copy the packet into buffer BUF2, encapsulating it
7792 and giving it a checksum. */
7797 for (i
= 0; i
< cnt
; i
++)
7803 *p
++ = tohex ((csum
>> 4) & 0xf);
7804 *p
++ = tohex (csum
& 0xf);
7806 /* Send it over and over until we get a positive ack. */
7810 int started_error_output
= 0;
7814 struct cleanup
*old_chain
;
7818 str
= escape_buffer (buf2
, p
- buf2
);
7819 old_chain
= make_cleanup (xfree
, str
);
7820 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7821 gdb_flush (gdb_stdlog
);
7822 do_cleanups (old_chain
);
7824 remote_serial_write (buf2
, p
- buf2
);
7826 /* If this is a no acks version of the remote protocol, send the
7827 packet and move on. */
7831 /* Read until either a timeout occurs (-2) or '+' is read.
7832 Handle any notification that arrives in the mean time. */
7835 ch
= readchar (remote_timeout
);
7843 case SERIAL_TIMEOUT
:
7846 if (started_error_output
)
7848 putchar_unfiltered ('\n');
7849 started_error_output
= 0;
7858 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7862 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7864 case SERIAL_TIMEOUT
:
7868 break; /* Retransmit buffer. */
7872 fprintf_unfiltered (gdb_stdlog
,
7873 "Packet instead of Ack, ignoring it\n");
7874 /* It's probably an old response sent because an ACK
7875 was lost. Gobble up the packet and ack it so it
7876 doesn't get retransmitted when we resend this
7879 remote_serial_write ("+", 1);
7880 continue; /* Now, go look for +. */
7887 /* If we got a notification, handle it, and go back to looking
7889 /* We've found the start of a notification. Now
7890 collect the data. */
7891 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7896 struct cleanup
*old_chain
;
7899 str
= escape_buffer (rs
->buf
, val
);
7900 old_chain
= make_cleanup (xfree
, str
);
7901 fprintf_unfiltered (gdb_stdlog
,
7902 " Notification received: %s\n",
7904 do_cleanups (old_chain
);
7906 handle_notification (rs
->notif_state
, rs
->buf
);
7907 /* We're in sync now, rewait for the ack. */
7914 if (!started_error_output
)
7916 started_error_output
= 1;
7917 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7919 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7920 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7929 if (!started_error_output
)
7931 started_error_output
= 1;
7932 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7934 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7938 break; /* Here to retransmit. */
7942 /* This is wrong. If doing a long backtrace, the user should be
7943 able to get out next time we call QUIT, without anything as
7944 violent as interrupt_query. If we want to provide a way out of
7945 here without getting to the next QUIT, it should be based on
7946 hitting ^C twice as in remote_wait. */
7957 /* Come here after finding the start of a frame when we expected an
7958 ack. Do our best to discard the rest of this packet. */
7967 c
= readchar (remote_timeout
);
7970 case SERIAL_TIMEOUT
:
7971 /* Nothing we can do. */
7974 /* Discard the two bytes of checksum and stop. */
7975 c
= readchar (remote_timeout
);
7977 c
= readchar (remote_timeout
);
7980 case '*': /* Run length encoding. */
7981 /* Discard the repeat count. */
7982 c
= readchar (remote_timeout
);
7987 /* A regular character. */
7993 /* Come here after finding the start of the frame. Collect the rest
7994 into *BUF, verifying the checksum, length, and handling run-length
7995 compression. NUL terminate the buffer. If there is not enough room,
7996 expand *BUF using xrealloc.
7998 Returns -1 on error, number of characters in buffer (ignoring the
7999 trailing NULL) on success. (could be extended to return one of the
8000 SERIAL status indications). */
8003 read_frame (char **buf_p
,
8010 struct remote_state
*rs
= get_remote_state ();
8017 c
= readchar (remote_timeout
);
8020 case SERIAL_TIMEOUT
:
8022 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8026 fputs_filtered ("Saw new packet start in middle of old one\n",
8028 return -1; /* Start a new packet, count retries. */
8031 unsigned char pktcsum
;
8037 check_0
= readchar (remote_timeout
);
8039 check_1
= readchar (remote_timeout
);
8041 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8044 fputs_filtered ("Timeout in checksum, retrying\n",
8048 else if (check_0
< 0 || check_1
< 0)
8051 fputs_filtered ("Communication error in checksum\n",
8056 /* Don't recompute the checksum; with no ack packets we
8057 don't have any way to indicate a packet retransmission
8062 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8063 if (csum
== pktcsum
)
8068 struct cleanup
*old_chain
;
8071 str
= escape_buffer (buf
, bc
);
8072 old_chain
= make_cleanup (xfree
, str
);
8073 fprintf_unfiltered (gdb_stdlog
,
8074 "Bad checksum, sentsum=0x%x, "
8075 "csum=0x%x, buf=%s\n",
8076 pktcsum
, csum
, str
);
8077 do_cleanups (old_chain
);
8079 /* Number of characters in buffer ignoring trailing
8083 case '*': /* Run length encoding. */
8088 c
= readchar (remote_timeout
);
8090 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8092 /* The character before ``*'' is repeated. */
8094 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8096 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8098 /* Make some more room in the buffer. */
8099 *sizeof_buf
+= repeat
;
8100 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
8104 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8110 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8114 if (bc
>= *sizeof_buf
- 1)
8116 /* Make some more room in the buffer. */
8118 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
8129 /* Read a packet from the remote machine, with error checking, and
8130 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8131 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8132 rather than timing out; this is used (in synchronous mode) to wait
8133 for a target that is is executing user code to stop. */
8134 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8135 don't have to change all the calls to getpkt to deal with the
8136 return value, because at the moment I don't know what the right
8137 thing to do it for those. */
8145 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
8149 /* Read a packet from the remote machine, with error checking, and
8150 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8151 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8152 rather than timing out; this is used (in synchronous mode) to wait
8153 for a target that is is executing user code to stop. If FOREVER ==
8154 0, this function is allowed to time out gracefully and return an
8155 indication of this to the caller. Otherwise return the number of
8156 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8157 enough reason to return to the caller. *IS_NOTIF is an output
8158 boolean that indicates whether *BUF holds a notification or not
8159 (a regular packet). */
8162 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8163 int expecting_notif
, int *is_notif
)
8165 struct remote_state
*rs
= get_remote_state ();
8171 /* We're reading a new response. Make sure we don't look at a
8172 previously cached response. */
8173 rs
->cached_wait_status
= 0;
8175 strcpy (*buf
, "timeout");
8178 timeout
= watchdog
> 0 ? watchdog
: -1;
8179 else if (expecting_notif
)
8180 timeout
= 0; /* There should already be a char in the buffer. If
8183 timeout
= remote_timeout
;
8187 /* Process any number of notifications, and then return when
8191 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8193 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8195 /* This can loop forever if the remote side sends us
8196 characters continuously, but if it pauses, we'll get
8197 SERIAL_TIMEOUT from readchar because of timeout. Then
8198 we'll count that as a retry.
8200 Note that even when forever is set, we will only wait
8201 forever prior to the start of a packet. After that, we
8202 expect characters to arrive at a brisk pace. They should
8203 show up within remote_timeout intervals. */
8205 c
= readchar (timeout
);
8206 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8208 if (c
== SERIAL_TIMEOUT
)
8210 if (expecting_notif
)
8211 return -1; /* Don't complain, it's normal to not get
8212 anything in this case. */
8214 if (forever
) /* Watchdog went off? Kill the target. */
8217 remote_unpush_target ();
8218 throw_error (TARGET_CLOSE_ERROR
,
8219 _("Watchdog timeout has expired. "
8220 "Target detached."));
8223 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8227 /* We've found the start of a packet or notification.
8228 Now collect the data. */
8229 val
= read_frame (buf
, sizeof_buf
);
8234 remote_serial_write ("-", 1);
8237 if (tries
> MAX_TRIES
)
8239 /* We have tried hard enough, and just can't receive the
8240 packet/notification. Give up. */
8241 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8243 /* Skip the ack char if we're in no-ack mode. */
8244 if (!rs
->noack_mode
)
8245 remote_serial_write ("+", 1);
8249 /* If we got an ordinary packet, return that to our caller. */
8254 struct cleanup
*old_chain
;
8257 str
= escape_buffer (*buf
, val
);
8258 old_chain
= make_cleanup (xfree
, str
);
8259 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8260 do_cleanups (old_chain
);
8263 /* Skip the ack char if we're in no-ack mode. */
8264 if (!rs
->noack_mode
)
8265 remote_serial_write ("+", 1);
8266 if (is_notif
!= NULL
)
8271 /* If we got a notification, handle it, and go back to looking
8275 gdb_assert (c
== '%');
8279 struct cleanup
*old_chain
;
8282 str
= escape_buffer (*buf
, val
);
8283 old_chain
= make_cleanup (xfree
, str
);
8284 fprintf_unfiltered (gdb_stdlog
,
8285 " Notification received: %s\n",
8287 do_cleanups (old_chain
);
8289 if (is_notif
!= NULL
)
8292 handle_notification (rs
->notif_state
, *buf
);
8294 /* Notifications require no acknowledgement. */
8296 if (expecting_notif
)
8303 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8305 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8309 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8312 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8316 /* Check whether EVENT is a fork event for the process specified
8317 by the pid passed in DATA, and if it is, kill the fork child. */
8320 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8321 QUEUE_ITER (stop_reply_p
) *iter
,
8325 struct queue_iter_param
*param
= data
;
8326 int parent_pid
= *(int *) param
->input
;
8328 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8330 struct remote_state
*rs
= get_remote_state ();
8331 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8334 res
= remote_vkill (child_pid
, rs
);
8336 error (_("Can't kill fork child process %d"), child_pid
);
8342 /* Kill any new fork children of process PID that haven't been
8343 processed by follow_fork. */
8346 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8348 struct thread_info
*thread
;
8349 struct notif_client
*notif
= ¬if_client_stop
;
8350 struct queue_iter_param param
;
8352 /* Kill the fork child threads of any threads in process PID
8353 that are stopped at a fork event. */
8354 ALL_NON_EXITED_THREADS (thread
)
8356 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8358 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8360 struct remote_state
*rs
= get_remote_state ();
8361 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8364 res
= remote_vkill (child_pid
, rs
);
8366 error (_("Can't kill fork child process %d"), child_pid
);
8370 /* Check for any pending fork events (not reported or processed yet)
8371 in process PID and kill those fork child threads as well. */
8372 remote_notif_get_pending_events (notif
);
8374 param
.output
= NULL
;
8375 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8376 kill_child_of_pending_fork
, ¶m
);
8381 remote_kill (struct target_ops
*ops
)
8384 /* Catch errors so the user can quit from gdb even when we
8385 aren't on speaking terms with the remote system. */
8390 CATCH (ex
, RETURN_MASK_ERROR
)
8392 if (ex
.error
== TARGET_CLOSE_ERROR
)
8394 /* If we got an (EOF) error that caused the target
8395 to go away, then we're done, that's what we wanted.
8396 "k" is susceptible to cause a premature EOF, given
8397 that the remote server isn't actually required to
8398 reply to "k", and it can happen that it doesn't
8399 even get to reply ACK to the "k". */
8403 /* Otherwise, something went wrong. We didn't actually kill
8404 the target. Just propagate the exception, and let the
8405 user or higher layers decide what to do. */
8406 throw_exception (ex
);
8410 /* We've killed the remote end, we get to mourn it. Since this is
8411 target remote, single-process, mourning the inferior also
8412 unpushes remote_ops. */
8413 target_mourn_inferior ();
8417 remote_vkill (int pid
, struct remote_state
*rs
)
8419 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8422 /* Tell the remote target to detach. */
8423 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8425 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8427 switch (packet_ok (rs
->buf
,
8428 &remote_protocol_packets
[PACKET_vKill
]))
8434 case PACKET_UNKNOWN
:
8437 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8442 extended_remote_kill (struct target_ops
*ops
)
8445 int pid
= ptid_get_pid (inferior_ptid
);
8446 struct remote_state
*rs
= get_remote_state ();
8448 /* If we're stopped while forking and we haven't followed yet, kill the
8449 child task. We need to do this before killing the parent task
8450 because if this is a vfork then the parent will be sleeping. */
8451 kill_new_fork_children (pid
, rs
);
8453 res
= remote_vkill (pid
, rs
);
8454 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8456 /* Don't try 'k' on a multi-process aware stub -- it has no way
8457 to specify the pid. */
8461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8462 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8465 /* Don't wait for it to die. I'm not really sure it matters whether
8466 we do or not. For the existing stubs, kill is a noop. */
8472 error (_("Can't kill process"));
8474 target_mourn_inferior ();
8478 remote_mourn (struct target_ops
*target
)
8480 unpush_target (target
);
8482 /* remote_close takes care of doing most of the clean up. */
8483 generic_mourn_inferior ();
8487 extended_remote_mourn (struct target_ops
*target
)
8489 struct remote_state
*rs
= get_remote_state ();
8491 /* In case we got here due to an error, but we're going to stay
8493 rs
->waiting_for_stop_reply
= 0;
8495 /* If the current general thread belonged to the process we just
8496 detached from or has exited, the remote side current general
8497 thread becomes undefined. Considering a case like this:
8499 - We just got here due to a detach.
8500 - The process that we're detaching from happens to immediately
8501 report a global breakpoint being hit in non-stop mode, in the
8502 same thread we had selected before.
8503 - GDB attaches to this process again.
8504 - This event happens to be the next event we handle.
8506 GDB would consider that the current general thread didn't need to
8507 be set on the stub side (with Hg), since for all it knew,
8508 GENERAL_THREAD hadn't changed.
8510 Notice that although in all-stop mode, the remote server always
8511 sets the current thread to the thread reporting the stop event,
8512 that doesn't happen in non-stop mode; in non-stop, the stub *must
8513 not* change the current thread when reporting a breakpoint hit,
8514 due to the decoupling of event reporting and event handling.
8516 To keep things simple, we always invalidate our notion of the
8518 record_currthread (rs
, minus_one_ptid
);
8520 /* Unlike "target remote", we do not want to unpush the target; then
8521 the next time the user says "run", we won't be connected. */
8523 /* Call common code to mark the inferior as not running. */
8524 generic_mourn_inferior ();
8526 if (!have_inferiors ())
8528 if (!remote_multi_process_p (rs
))
8530 /* Check whether the target is running now - some remote stubs
8531 automatically restart after kill. */
8533 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8535 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8537 /* Assume that the target has been restarted. Set
8538 inferior_ptid so that bits of core GDB realizes
8539 there's something here, e.g., so that the user can
8540 say "kill" again. */
8541 inferior_ptid
= magic_null_ptid
;
8548 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8550 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8554 extended_remote_disable_randomization (int val
)
8556 struct remote_state
*rs
= get_remote_state ();
8559 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8562 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8564 error (_("Target does not support QDisableRandomization."));
8565 if (strcmp (reply
, "OK") != 0)
8566 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8570 extended_remote_run (char *args
)
8572 struct remote_state
*rs
= get_remote_state ();
8575 /* If the user has disabled vRun support, or we have detected that
8576 support is not available, do not try it. */
8577 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8580 strcpy (rs
->buf
, "vRun;");
8581 len
= strlen (rs
->buf
);
8583 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8584 error (_("Remote file name too long for run packet"));
8585 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8586 strlen (remote_exec_file
));
8588 gdb_assert (args
!= NULL
);
8591 struct cleanup
*back_to
;
8595 argv
= gdb_buildargv (args
);
8596 back_to
= make_cleanup_freeargv (argv
);
8597 for (i
= 0; argv
[i
] != NULL
; i
++)
8599 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8600 error (_("Argument list too long for run packet"));
8601 rs
->buf
[len
++] = ';';
8602 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8605 do_cleanups (back_to
);
8608 rs
->buf
[len
++] = '\0';
8611 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8613 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8616 /* We have a wait response. All is well. */
8618 case PACKET_UNKNOWN
:
8621 if (remote_exec_file
[0] == '\0')
8622 error (_("Running the default executable on the remote target failed; "
8623 "try \"set remote exec-file\"?"));
8625 error (_("Running \"%s\" on the remote target failed"),
8628 gdb_assert_not_reached (_("bad switch"));
8632 /* In the extended protocol we want to be able to do things like
8633 "run" and have them basically work as expected. So we need
8634 a special create_inferior function. We support changing the
8635 executable file and the command line arguments, but not the
8639 extended_remote_create_inferior (struct target_ops
*ops
,
8640 char *exec_file
, char *args
,
8641 char **env
, int from_tty
)
8645 struct remote_state
*rs
= get_remote_state ();
8647 /* If running asynchronously, register the target file descriptor
8648 with the event loop. */
8649 if (target_can_async_p ())
8652 /* Disable address space randomization if requested (and supported). */
8653 if (extended_remote_supports_disable_randomization (ops
))
8654 extended_remote_disable_randomization (disable_randomization
);
8656 /* Now restart the remote server. */
8657 run_worked
= extended_remote_run (args
) != -1;
8660 /* vRun was not supported. Fail if we need it to do what the
8662 if (remote_exec_file
[0])
8663 error (_("Remote target does not support \"set remote exec-file\""));
8665 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8667 /* Fall back to "R". */
8668 extended_remote_restart ();
8671 if (!have_inferiors ())
8673 /* Clean up from the last time we ran, before we mark the target
8674 running again. This will mark breakpoints uninserted, and
8675 get_offsets may insert breakpoints. */
8676 init_thread_list ();
8677 init_wait_for_inferior ();
8680 /* vRun's success return is a stop reply. */
8681 stop_reply
= run_worked
? rs
->buf
: NULL
;
8682 add_current_inferior_and_thread (stop_reply
);
8684 /* Get updated offsets, if the stub uses qOffsets. */
8689 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8690 the list of conditions (in agent expression bytecode format), if any, the
8691 target needs to evaluate. The output is placed into the packet buffer
8692 started from BUF and ended at BUF_END. */
8695 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8696 struct bp_target_info
*bp_tgt
, char *buf
,
8699 struct agent_expr
*aexpr
= NULL
;
8702 char *buf_start
= buf
;
8704 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8707 buf
+= strlen (buf
);
8708 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8711 /* Send conditions to the target and free the vector. */
8713 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8716 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8717 buf
+= strlen (buf
);
8718 for (i
= 0; i
< aexpr
->len
; ++i
)
8719 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8726 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8727 struct bp_target_info
*bp_tgt
, char *buf
)
8729 struct agent_expr
*aexpr
= NULL
;
8732 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8735 buf
+= strlen (buf
);
8737 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8738 buf
+= strlen (buf
);
8740 /* Concatenate all the agent expressions that are commands into the
8743 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8746 sprintf (buf
, "X%x,", aexpr
->len
);
8747 buf
+= strlen (buf
);
8748 for (i
= 0; i
< aexpr
->len
; ++i
)
8749 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8754 /* Insert a breakpoint. On targets that have software breakpoint
8755 support, we ask the remote target to do the work; on targets
8756 which don't, we insert a traditional memory breakpoint. */
8759 remote_insert_breakpoint (struct target_ops
*ops
,
8760 struct gdbarch
*gdbarch
,
8761 struct bp_target_info
*bp_tgt
)
8763 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8764 If it succeeds, then set the support to PACKET_ENABLE. If it
8765 fails, and the user has explicitly requested the Z support then
8766 report an error, otherwise, mark it disabled and go on. */
8768 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8770 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8771 struct remote_state
*rs
;
8774 struct condition_list
*cond
= NULL
;
8776 /* Make sure the remote is pointing at the right process, if
8778 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8779 set_general_process ();
8781 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8783 rs
= get_remote_state ();
8785 endbuf
= rs
->buf
+ get_remote_packet_size ();
8790 addr
= (ULONGEST
) remote_address_masked (addr
);
8791 p
+= hexnumstr (p
, addr
);
8792 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8794 if (remote_supports_cond_breakpoints (ops
))
8795 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8797 if (remote_can_run_breakpoint_commands (ops
))
8798 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8803 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8808 bp_tgt
->placed_address
= addr
;
8809 bp_tgt
->placed_size
= bpsize
;
8811 case PACKET_UNKNOWN
:
8816 /* If this breakpoint has target-side commands but this stub doesn't
8817 support Z0 packets, throw error. */
8818 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8819 throw_error (NOT_SUPPORTED_ERROR
, _("\
8820 Target doesn't support breakpoints that have target side commands."));
8822 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8826 remote_remove_breakpoint (struct target_ops
*ops
,
8827 struct gdbarch
*gdbarch
,
8828 struct bp_target_info
*bp_tgt
)
8830 CORE_ADDR addr
= bp_tgt
->placed_address
;
8831 struct remote_state
*rs
= get_remote_state ();
8833 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8836 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8838 /* Make sure the remote is pointing at the right process, if
8840 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8841 set_general_process ();
8847 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8848 p
+= hexnumstr (p
, addr
);
8849 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8852 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8854 return (rs
->buf
[0] == 'E');
8857 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8860 static enum Z_packet_type
8861 watchpoint_to_Z_packet (int type
)
8866 return Z_PACKET_WRITE_WP
;
8869 return Z_PACKET_READ_WP
;
8872 return Z_PACKET_ACCESS_WP
;
8875 internal_error (__FILE__
, __LINE__
,
8876 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8881 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8882 enum target_hw_bp_type type
, struct expression
*cond
)
8884 struct remote_state
*rs
= get_remote_state ();
8885 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8887 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8889 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8892 /* Make sure the remote is pointing at the right process, if
8894 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8895 set_general_process ();
8897 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8898 p
= strchr (rs
->buf
, '\0');
8899 addr
= remote_address_masked (addr
);
8900 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8901 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8904 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8906 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8910 case PACKET_UNKNOWN
:
8915 internal_error (__FILE__
, __LINE__
,
8916 _("remote_insert_watchpoint: reached end of function"));
8920 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8921 CORE_ADDR start
, int length
)
8923 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8925 return diff
< length
;
8930 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8931 enum target_hw_bp_type type
, struct expression
*cond
)
8933 struct remote_state
*rs
= get_remote_state ();
8934 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8936 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8938 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8941 /* Make sure the remote is pointing at the right process, if
8943 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8944 set_general_process ();
8946 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8947 p
= strchr (rs
->buf
, '\0');
8948 addr
= remote_address_masked (addr
);
8949 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8950 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8952 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8954 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8957 case PACKET_UNKNOWN
:
8962 internal_error (__FILE__
, __LINE__
,
8963 _("remote_remove_watchpoint: reached end of function"));
8967 int remote_hw_watchpoint_limit
= -1;
8968 int remote_hw_watchpoint_length_limit
= -1;
8969 int remote_hw_breakpoint_limit
= -1;
8972 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8973 CORE_ADDR addr
, int len
)
8975 if (remote_hw_watchpoint_length_limit
== 0)
8977 else if (remote_hw_watchpoint_length_limit
< 0)
8979 else if (len
<= remote_hw_watchpoint_length_limit
)
8986 remote_check_watch_resources (struct target_ops
*self
,
8987 enum bptype type
, int cnt
, int ot
)
8989 if (type
== bp_hardware_breakpoint
)
8991 if (remote_hw_breakpoint_limit
== 0)
8993 else if (remote_hw_breakpoint_limit
< 0)
8995 else if (cnt
<= remote_hw_breakpoint_limit
)
9000 if (remote_hw_watchpoint_limit
== 0)
9002 else if (remote_hw_watchpoint_limit
< 0)
9006 else if (cnt
<= remote_hw_watchpoint_limit
)
9012 /* The to_stopped_by_sw_breakpoint method of target remote. */
9015 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9017 struct remote_state
*rs
= get_remote_state ();
9019 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
9022 /* The to_supports_stopped_by_sw_breakpoint method of target
9026 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9028 struct remote_state
*rs
= get_remote_state ();
9030 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9033 /* The to_stopped_by_hw_breakpoint method of target remote. */
9036 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9038 struct remote_state
*rs
= get_remote_state ();
9040 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
9043 /* The to_supports_stopped_by_hw_breakpoint method of target
9047 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9049 struct remote_state
*rs
= get_remote_state ();
9051 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9055 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9057 struct remote_state
*rs
= get_remote_state ();
9059 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
9063 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9065 struct remote_state
*rs
= get_remote_state ();
9068 if (remote_stopped_by_watchpoint (target
))
9070 *addr_p
= rs
->remote_watch_data_address
;
9079 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9080 struct bp_target_info
*bp_tgt
)
9082 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9083 struct remote_state
*rs
;
9088 /* The length field should be set to the size of a breakpoint
9089 instruction, even though we aren't inserting one ourselves. */
9091 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9093 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9096 /* Make sure the remote is pointing at the right process, if
9098 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9099 set_general_process ();
9101 rs
= get_remote_state ();
9103 endbuf
= rs
->buf
+ get_remote_packet_size ();
9109 addr
= remote_address_masked (addr
);
9110 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9111 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9113 if (remote_supports_cond_breakpoints (self
))
9114 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9116 if (remote_can_run_breakpoint_commands (self
))
9117 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9120 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9122 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9125 if (rs
->buf
[1] == '.')
9127 message
= strchr (rs
->buf
+ 2, '.');
9129 error (_("Remote failure reply: %s"), message
+ 1);
9132 case PACKET_UNKNOWN
:
9135 bp_tgt
->placed_address
= addr
;
9136 bp_tgt
->placed_size
= bpsize
;
9139 internal_error (__FILE__
, __LINE__
,
9140 _("remote_insert_hw_breakpoint: reached end of function"));
9145 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9146 struct bp_target_info
*bp_tgt
)
9149 struct remote_state
*rs
= get_remote_state ();
9151 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9153 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9156 /* Make sure the remote is pointing at the right process, if
9158 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9159 set_general_process ();
9165 addr
= remote_address_masked (bp_tgt
->placed_address
);
9166 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9167 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9170 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9172 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9175 case PACKET_UNKNOWN
:
9180 internal_error (__FILE__
, __LINE__
,
9181 _("remote_remove_hw_breakpoint: reached end of function"));
9184 /* Verify memory using the "qCRC:" request. */
9187 remote_verify_memory (struct target_ops
*ops
,
9188 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9190 struct remote_state
*rs
= get_remote_state ();
9191 unsigned long host_crc
, target_crc
;
9194 /* It doesn't make sense to use qCRC if the remote target is
9195 connected but not running. */
9196 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9198 enum packet_result result
;
9200 /* Make sure the remote is pointing at the right process. */
9201 set_general_process ();
9203 /* FIXME: assumes lma can fit into long. */
9204 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9205 (long) lma
, (long) size
);
9208 /* Be clever; compute the host_crc before waiting for target
9210 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9212 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9214 result
= packet_ok (rs
->buf
,
9215 &remote_protocol_packets
[PACKET_qCRC
]);
9216 if (result
== PACKET_ERROR
)
9218 else if (result
== PACKET_OK
)
9220 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9221 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9223 return (host_crc
== target_crc
);
9227 return simple_verify_memory (ops
, data
, lma
, size
);
9230 /* compare-sections command
9232 With no arguments, compares each loadable section in the exec bfd
9233 with the same memory range on the target, and reports mismatches.
9234 Useful for verifying the image on the target against the exec file. */
9237 compare_sections_command (char *args
, int from_tty
)
9240 struct cleanup
*old_chain
;
9242 const char *sectname
;
9251 error (_("command cannot be used without an exec file"));
9253 /* Make sure the remote is pointing at the right process. */
9254 set_general_process ();
9256 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9262 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9264 if (!(s
->flags
& SEC_LOAD
))
9265 continue; /* Skip non-loadable section. */
9267 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9268 continue; /* Skip writeable sections */
9270 size
= bfd_get_section_size (s
);
9272 continue; /* Skip zero-length section. */
9274 sectname
= bfd_get_section_name (exec_bfd
, s
);
9275 if (args
&& strcmp (args
, sectname
) != 0)
9276 continue; /* Not the section selected by user. */
9278 matched
= 1; /* Do this section. */
9281 sectdata
= xmalloc (size
);
9282 old_chain
= make_cleanup (xfree
, sectdata
);
9283 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9285 res
= target_verify_memory (sectdata
, lma
, size
);
9288 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9289 paddress (target_gdbarch (), lma
),
9290 paddress (target_gdbarch (), lma
+ size
));
9292 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9293 paddress (target_gdbarch (), lma
),
9294 paddress (target_gdbarch (), lma
+ size
));
9296 printf_filtered ("matched.\n");
9299 printf_filtered ("MIS-MATCHED!\n");
9303 do_cleanups (old_chain
);
9306 warning (_("One or more sections of the target image does not match\n\
9307 the loaded file\n"));
9308 if (args
&& !matched
)
9309 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9312 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9313 into remote target. The number of bytes written to the remote
9314 target is returned, or -1 for error. */
9316 static enum target_xfer_status
9317 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9318 const char *annex
, const gdb_byte
*writebuf
,
9319 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9320 struct packet_config
*packet
)
9324 struct remote_state
*rs
= get_remote_state ();
9325 int max_size
= get_memory_write_packet_size ();
9327 if (packet
->support
== PACKET_DISABLE
)
9328 return TARGET_XFER_E_IO
;
9330 /* Insert header. */
9331 i
= snprintf (rs
->buf
, max_size
,
9332 "qXfer:%s:write:%s:%s:",
9333 object_name
, annex
? annex
: "",
9334 phex_nz (offset
, sizeof offset
));
9335 max_size
-= (i
+ 1);
9337 /* Escape as much data as fits into rs->buf. */
9338 buf_len
= remote_escape_output
9339 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9341 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9342 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9343 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9344 return TARGET_XFER_E_IO
;
9346 unpack_varlen_hex (rs
->buf
, &n
);
9349 return TARGET_XFER_OK
;
9352 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9353 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9354 number of bytes read is returned, or 0 for EOF, or -1 for error.
9355 The number of bytes read may be less than LEN without indicating an
9356 EOF. PACKET is checked and updated to indicate whether the remote
9357 target supports this object. */
9359 static enum target_xfer_status
9360 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9362 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9363 ULONGEST
*xfered_len
,
9364 struct packet_config
*packet
)
9366 struct remote_state
*rs
= get_remote_state ();
9367 LONGEST i
, n
, packet_len
;
9369 if (packet
->support
== PACKET_DISABLE
)
9370 return TARGET_XFER_E_IO
;
9372 /* Check whether we've cached an end-of-object packet that matches
9374 if (rs
->finished_object
)
9376 if (strcmp (object_name
, rs
->finished_object
) == 0
9377 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9378 && offset
== rs
->finished_offset
)
9379 return TARGET_XFER_EOF
;
9382 /* Otherwise, we're now reading something different. Discard
9384 xfree (rs
->finished_object
);
9385 xfree (rs
->finished_annex
);
9386 rs
->finished_object
= NULL
;
9387 rs
->finished_annex
= NULL
;
9390 /* Request only enough to fit in a single packet. The actual data
9391 may not, since we don't know how much of it will need to be escaped;
9392 the target is free to respond with slightly less data. We subtract
9393 five to account for the response type and the protocol frame. */
9394 n
= min (get_remote_packet_size () - 5, len
);
9395 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9396 object_name
, annex
? annex
: "",
9397 phex_nz (offset
, sizeof offset
),
9398 phex_nz (n
, sizeof n
));
9399 i
= putpkt (rs
->buf
);
9401 return TARGET_XFER_E_IO
;
9404 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9405 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9406 return TARGET_XFER_E_IO
;
9408 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9409 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9411 /* 'm' means there is (or at least might be) more data after this
9412 batch. That does not make sense unless there's at least one byte
9413 of data in this reply. */
9414 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9415 error (_("Remote qXfer reply contained no data."));
9417 /* Got some data. */
9418 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9419 packet_len
- 1, readbuf
, n
);
9421 /* 'l' is an EOF marker, possibly including a final block of data,
9422 or possibly empty. If we have the final block of a non-empty
9423 object, record this fact to bypass a subsequent partial read. */
9424 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9426 rs
->finished_object
= xstrdup (object_name
);
9427 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9428 rs
->finished_offset
= offset
+ i
;
9432 return TARGET_XFER_EOF
;
9436 return TARGET_XFER_OK
;
9440 static enum target_xfer_status
9441 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9442 const char *annex
, gdb_byte
*readbuf
,
9443 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9444 ULONGEST
*xfered_len
)
9446 struct remote_state
*rs
;
9450 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9452 set_remote_traceframe ();
9453 set_general_thread (inferior_ptid
);
9455 rs
= get_remote_state ();
9457 /* Handle memory using the standard memory routines. */
9458 if (object
== TARGET_OBJECT_MEMORY
)
9460 /* If the remote target is connected but not running, we should
9461 pass this request down to a lower stratum (e.g. the executable
9463 if (!target_has_execution
)
9464 return TARGET_XFER_EOF
;
9466 if (writebuf
!= NULL
)
9467 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9470 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9474 /* Handle SPU memory using qxfer packets. */
9475 if (object
== TARGET_OBJECT_SPU
)
9478 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9479 xfered_len
, &remote_protocol_packets
9480 [PACKET_qXfer_spu_read
]);
9482 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9483 xfered_len
, &remote_protocol_packets
9484 [PACKET_qXfer_spu_write
]);
9487 /* Handle extra signal info using qxfer packets. */
9488 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9491 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9492 xfered_len
, &remote_protocol_packets
9493 [PACKET_qXfer_siginfo_read
]);
9495 return remote_write_qxfer (ops
, "siginfo", annex
,
9496 writebuf
, offset
, len
, xfered_len
,
9497 &remote_protocol_packets
9498 [PACKET_qXfer_siginfo_write
]);
9501 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9504 return remote_read_qxfer (ops
, "statictrace", annex
,
9505 readbuf
, offset
, len
, xfered_len
,
9506 &remote_protocol_packets
9507 [PACKET_qXfer_statictrace_read
]);
9509 return TARGET_XFER_E_IO
;
9512 /* Only handle flash writes. */
9513 if (writebuf
!= NULL
)
9519 case TARGET_OBJECT_FLASH
:
9520 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9524 return TARGET_XFER_E_IO
;
9528 /* Map pre-existing objects onto letters. DO NOT do this for new
9529 objects!!! Instead specify new query packets. */
9532 case TARGET_OBJECT_AVR
:
9536 case TARGET_OBJECT_AUXV
:
9537 gdb_assert (annex
== NULL
);
9538 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9540 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9542 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9543 return remote_read_qxfer
9544 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9545 &remote_protocol_packets
[PACKET_qXfer_features
]);
9547 case TARGET_OBJECT_LIBRARIES
:
9548 return remote_read_qxfer
9549 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9550 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9552 case TARGET_OBJECT_LIBRARIES_SVR4
:
9553 return remote_read_qxfer
9554 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9555 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9557 case TARGET_OBJECT_MEMORY_MAP
:
9558 gdb_assert (annex
== NULL
);
9559 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9561 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9563 case TARGET_OBJECT_OSDATA
:
9564 /* Should only get here if we're connected. */
9565 gdb_assert (rs
->remote_desc
);
9566 return remote_read_qxfer
9567 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9568 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9570 case TARGET_OBJECT_THREADS
:
9571 gdb_assert (annex
== NULL
);
9572 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9574 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9576 case TARGET_OBJECT_TRACEFRAME_INFO
:
9577 gdb_assert (annex
== NULL
);
9578 return remote_read_qxfer
9579 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9580 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9582 case TARGET_OBJECT_FDPIC
:
9583 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9585 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9587 case TARGET_OBJECT_OPENVMS_UIB
:
9588 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9590 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9592 case TARGET_OBJECT_BTRACE
:
9593 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9595 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9597 case TARGET_OBJECT_BTRACE_CONF
:
9598 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9600 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9602 case TARGET_OBJECT_EXEC_FILE
:
9603 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9605 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9608 return TARGET_XFER_E_IO
;
9611 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9612 large enough let the caller deal with it. */
9613 if (len
< get_remote_packet_size ())
9614 return TARGET_XFER_E_IO
;
9615 len
= get_remote_packet_size ();
9617 /* Except for querying the minimum buffer size, target must be open. */
9618 if (!rs
->remote_desc
)
9619 error (_("remote query is only available after target open"));
9621 gdb_assert (annex
!= NULL
);
9622 gdb_assert (readbuf
!= NULL
);
9628 /* We used one buffer char for the remote protocol q command and
9629 another for the query type. As the remote protocol encapsulation
9630 uses 4 chars plus one extra in case we are debugging
9631 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9634 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9636 /* Bad caller may have sent forbidden characters. */
9637 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9642 gdb_assert (annex
[i
] == '\0');
9644 i
= putpkt (rs
->buf
);
9646 return TARGET_XFER_E_IO
;
9648 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9649 strcpy ((char *) readbuf
, rs
->buf
);
9651 *xfered_len
= strlen ((char *) readbuf
);
9652 return TARGET_XFER_OK
;
9656 remote_search_memory (struct target_ops
* ops
,
9657 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9658 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9659 CORE_ADDR
*found_addrp
)
9661 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9662 struct remote_state
*rs
= get_remote_state ();
9663 int max_size
= get_memory_write_packet_size ();
9664 struct packet_config
*packet
=
9665 &remote_protocol_packets
[PACKET_qSearch_memory
];
9666 /* Number of packet bytes used to encode the pattern;
9667 this could be more than PATTERN_LEN due to escape characters. */
9668 int escaped_pattern_len
;
9669 /* Amount of pattern that was encodable in the packet. */
9670 int used_pattern_len
;
9673 ULONGEST found_addr
;
9675 /* Don't go to the target if we don't have to.
9676 This is done before checking packet->support to avoid the possibility that
9677 a success for this edge case means the facility works in general. */
9678 if (pattern_len
> search_space_len
)
9680 if (pattern_len
== 0)
9682 *found_addrp
= start_addr
;
9686 /* If we already know the packet isn't supported, fall back to the simple
9687 way of searching memory. */
9689 if (packet_config_support (packet
) == PACKET_DISABLE
)
9691 /* Target doesn't provided special support, fall back and use the
9692 standard support (copy memory and do the search here). */
9693 return simple_search_memory (ops
, start_addr
, search_space_len
,
9694 pattern
, pattern_len
, found_addrp
);
9697 /* Make sure the remote is pointing at the right process. */
9698 set_general_process ();
9700 /* Insert header. */
9701 i
= snprintf (rs
->buf
, max_size
,
9702 "qSearch:memory:%s;%s;",
9703 phex_nz (start_addr
, addr_size
),
9704 phex_nz (search_space_len
, sizeof (search_space_len
)));
9705 max_size
-= (i
+ 1);
9707 /* Escape as much data as fits into rs->buf. */
9708 escaped_pattern_len
=
9709 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9710 &used_pattern_len
, max_size
);
9712 /* Bail if the pattern is too large. */
9713 if (used_pattern_len
!= pattern_len
)
9714 error (_("Pattern is too large to transmit to remote target."));
9716 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9717 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9718 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9720 /* The request may not have worked because the command is not
9721 supported. If so, fall back to the simple way. */
9722 if (packet
->support
== PACKET_DISABLE
)
9724 return simple_search_memory (ops
, start_addr
, search_space_len
,
9725 pattern
, pattern_len
, found_addrp
);
9730 if (rs
->buf
[0] == '0')
9732 else if (rs
->buf
[0] == '1')
9735 if (rs
->buf
[1] != ',')
9736 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9737 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9738 *found_addrp
= found_addr
;
9741 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9747 remote_rcmd (struct target_ops
*self
, const char *command
,
9748 struct ui_file
*outbuf
)
9750 struct remote_state
*rs
= get_remote_state ();
9753 if (!rs
->remote_desc
)
9754 error (_("remote rcmd is only available after target open"));
9756 /* Send a NULL command across as an empty command. */
9757 if (command
== NULL
)
9760 /* The query prefix. */
9761 strcpy (rs
->buf
, "qRcmd,");
9762 p
= strchr (rs
->buf
, '\0');
9764 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9765 > get_remote_packet_size ())
9766 error (_("\"monitor\" command ``%s'' is too long."), command
);
9768 /* Encode the actual command. */
9769 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9771 if (putpkt (rs
->buf
) < 0)
9772 error (_("Communication problem with target."));
9774 /* get/display the response */
9779 /* XXX - see also remote_get_noisy_reply(). */
9780 QUIT
; /* Allow user to bail out with ^C. */
9782 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9784 /* Timeout. Continue to (try to) read responses.
9785 This is better than stopping with an error, assuming the stub
9786 is still executing the (long) monitor command.
9787 If needed, the user can interrupt gdb using C-c, obtaining
9788 an effect similar to stop on timeout. */
9793 error (_("Target does not support this command."));
9794 if (buf
[0] == 'O' && buf
[1] != 'K')
9796 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9799 if (strcmp (buf
, "OK") == 0)
9801 if (strlen (buf
) == 3 && buf
[0] == 'E'
9802 && isdigit (buf
[1]) && isdigit (buf
[2]))
9804 error (_("Protocol error with Rcmd"));
9806 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9808 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9810 fputc_unfiltered (c
, outbuf
);
9816 static VEC(mem_region_s
) *
9817 remote_memory_map (struct target_ops
*ops
)
9819 VEC(mem_region_s
) *result
= NULL
;
9820 char *text
= target_read_stralloc (¤t_target
,
9821 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9825 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9827 result
= parse_memory_map (text
);
9828 do_cleanups (back_to
);
9835 packet_command (char *args
, int from_tty
)
9837 struct remote_state
*rs
= get_remote_state ();
9839 if (!rs
->remote_desc
)
9840 error (_("command can only be used with remote target"));
9843 error (_("remote-packet command requires packet text as argument"));
9845 puts_filtered ("sending: ");
9846 print_packet (args
);
9847 puts_filtered ("\n");
9850 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9851 puts_filtered ("received: ");
9852 print_packet (rs
->buf
);
9853 puts_filtered ("\n");
9857 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9859 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9861 static void threadset_test_cmd (char *cmd
, int tty
);
9863 static void threadalive_test (char *cmd
, int tty
);
9865 static void threadlist_test_cmd (char *cmd
, int tty
);
9867 int get_and_display_threadinfo (threadref
*ref
);
9869 static void threadinfo_test_cmd (char *cmd
, int tty
);
9871 static int thread_display_step (threadref
*ref
, void *context
);
9873 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9875 static void init_remote_threadtests (void);
9877 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9880 threadset_test_cmd (char *cmd
, int tty
)
9882 int sample_thread
= SAMPLE_THREAD
;
9884 printf_filtered (_("Remote threadset test\n"));
9885 set_general_thread (sample_thread
);
9890 threadalive_test (char *cmd
, int tty
)
9892 int sample_thread
= SAMPLE_THREAD
;
9893 int pid
= ptid_get_pid (inferior_ptid
);
9894 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9896 if (remote_thread_alive (ptid
))
9897 printf_filtered ("PASS: Thread alive test\n");
9899 printf_filtered ("FAIL: Thread alive test\n");
9902 void output_threadid (char *title
, threadref
*ref
);
9905 output_threadid (char *title
, threadref
*ref
)
9909 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9911 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9915 threadlist_test_cmd (char *cmd
, int tty
)
9918 threadref nextthread
;
9919 int done
, result_count
;
9920 threadref threadlist
[3];
9922 printf_filtered ("Remote Threadlist test\n");
9923 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9924 &result_count
, &threadlist
[0]))
9925 printf_filtered ("FAIL: threadlist test\n");
9928 threadref
*scan
= threadlist
;
9929 threadref
*limit
= scan
+ result_count
;
9931 while (scan
< limit
)
9932 output_threadid (" thread ", scan
++);
9937 display_thread_info (struct gdb_ext_thread_info
*info
)
9939 output_threadid ("Threadid: ", &info
->threadid
);
9940 printf_filtered ("Name: %s\n ", info
->shortname
);
9941 printf_filtered ("State: %s\n", info
->display
);
9942 printf_filtered ("other: %s\n\n", info
->more_display
);
9946 get_and_display_threadinfo (threadref
*ref
)
9950 struct gdb_ext_thread_info threadinfo
;
9952 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9953 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9954 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9955 display_thread_info (&threadinfo
);
9960 threadinfo_test_cmd (char *cmd
, int tty
)
9962 int athread
= SAMPLE_THREAD
;
9966 int_to_threadref (&thread
, athread
);
9967 printf_filtered ("Remote Threadinfo test\n");
9968 if (!get_and_display_threadinfo (&thread
))
9969 printf_filtered ("FAIL cannot get thread info\n");
9973 thread_display_step (threadref
*ref
, void *context
)
9975 /* output_threadid(" threadstep ",ref); *//* simple test */
9976 return get_and_display_threadinfo (ref
);
9980 threadlist_update_test_cmd (char *cmd
, int tty
)
9982 printf_filtered ("Remote Threadlist update test\n");
9983 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9987 init_remote_threadtests (void)
9989 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9990 _("Fetch and print the remote list of "
9991 "thread identifiers, one pkt only"));
9992 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9993 _("Fetch and display info about one thread"));
9994 add_com ("tset", class_obscure
, threadset_test_cmd
,
9995 _("Test setting to a different thread"));
9996 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9997 _("Iterate through updating all remote thread info"));
9998 add_com ("talive", class_obscure
, threadalive_test
,
9999 _(" Remote thread alive test "));
10004 /* Convert a thread ID to a string. Returns the string in a static
10008 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10010 static char buf
[64];
10011 struct remote_state
*rs
= get_remote_state ();
10013 if (ptid_equal (ptid
, null_ptid
))
10014 return normal_pid_to_str (ptid
);
10015 else if (ptid_is_pid (ptid
))
10017 /* Printing an inferior target id. */
10019 /* When multi-process extensions are off, there's no way in the
10020 remote protocol to know the remote process id, if there's any
10021 at all. There's one exception --- when we're connected with
10022 target extended-remote, and we manually attached to a process
10023 with "attach PID". We don't record anywhere a flag that
10024 allows us to distinguish that case from the case of
10025 connecting with extended-remote and the stub already being
10026 attached to a process, and reporting yes to qAttached, hence
10027 no smart special casing here. */
10028 if (!remote_multi_process_p (rs
))
10030 xsnprintf (buf
, sizeof buf
, "Remote target");
10034 return normal_pid_to_str (ptid
);
10038 if (ptid_equal (magic_null_ptid
, ptid
))
10039 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10040 else if (rs
->extended
&& remote_multi_process_p (rs
))
10041 if (ptid_get_lwp (ptid
) == 0)
10042 return normal_pid_to_str (ptid
);
10044 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10045 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10047 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10048 ptid_get_lwp (ptid
));
10053 /* Get the address of the thread local variable in OBJFILE which is
10054 stored at OFFSET within the thread local storage for thread PTID. */
10057 remote_get_thread_local_address (struct target_ops
*ops
,
10058 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10060 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10062 struct remote_state
*rs
= get_remote_state ();
10064 char *endp
= rs
->buf
+ get_remote_packet_size ();
10065 enum packet_result result
;
10067 strcpy (p
, "qGetTLSAddr:");
10069 p
= write_ptid (p
, endp
, ptid
);
10071 p
+= hexnumstr (p
, offset
);
10073 p
+= hexnumstr (p
, lm
);
10077 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10078 result
= packet_ok (rs
->buf
,
10079 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10080 if (result
== PACKET_OK
)
10084 unpack_varlen_hex (rs
->buf
, &result
);
10087 else if (result
== PACKET_UNKNOWN
)
10088 throw_error (TLS_GENERIC_ERROR
,
10089 _("Remote target doesn't support qGetTLSAddr packet"));
10091 throw_error (TLS_GENERIC_ERROR
,
10092 _("Remote target failed to process qGetTLSAddr request"));
10095 throw_error (TLS_GENERIC_ERROR
,
10096 _("TLS not supported or disabled on this target"));
10101 /* Provide thread local base, i.e. Thread Information Block address.
10102 Returns 1 if ptid is found and thread_local_base is non zero. */
10105 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10107 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10109 struct remote_state
*rs
= get_remote_state ();
10111 char *endp
= rs
->buf
+ get_remote_packet_size ();
10112 enum packet_result result
;
10114 strcpy (p
, "qGetTIBAddr:");
10116 p
= write_ptid (p
, endp
, ptid
);
10120 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10121 result
= packet_ok (rs
->buf
,
10122 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10123 if (result
== PACKET_OK
)
10127 unpack_varlen_hex (rs
->buf
, &result
);
10129 *addr
= (CORE_ADDR
) result
;
10132 else if (result
== PACKET_UNKNOWN
)
10133 error (_("Remote target doesn't support qGetTIBAddr packet"));
10135 error (_("Remote target failed to process qGetTIBAddr request"));
10138 error (_("qGetTIBAddr not supported or disabled on this target"));
10143 /* Support for inferring a target description based on the current
10144 architecture and the size of a 'g' packet. While the 'g' packet
10145 can have any size (since optional registers can be left off the
10146 end), some sizes are easily recognizable given knowledge of the
10147 approximate architecture. */
10149 struct remote_g_packet_guess
10152 const struct target_desc
*tdesc
;
10154 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10155 DEF_VEC_O(remote_g_packet_guess_s
);
10157 struct remote_g_packet_data
10159 VEC(remote_g_packet_guess_s
) *guesses
;
10162 static struct gdbarch_data
*remote_g_packet_data_handle
;
10165 remote_g_packet_data_init (struct obstack
*obstack
)
10167 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10171 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10172 const struct target_desc
*tdesc
)
10174 struct remote_g_packet_data
*data
10175 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
10176 struct remote_g_packet_guess new_guess
, *guess
;
10179 gdb_assert (tdesc
!= NULL
);
10182 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10184 if (guess
->bytes
== bytes
)
10185 internal_error (__FILE__
, __LINE__
,
10186 _("Duplicate g packet description added for size %d"),
10189 new_guess
.bytes
= bytes
;
10190 new_guess
.tdesc
= tdesc
;
10191 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10194 /* Return 1 if remote_read_description would do anything on this target
10195 and architecture, 0 otherwise. */
10198 remote_read_description_p (struct target_ops
*target
)
10200 struct remote_g_packet_data
*data
10201 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10203 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10209 static const struct target_desc
*
10210 remote_read_description (struct target_ops
*target
)
10212 struct remote_g_packet_data
*data
10213 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10215 /* Do not try this during initial connection, when we do not know
10216 whether there is a running but stopped thread. */
10217 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10218 return target
->beneath
->to_read_description (target
->beneath
);
10220 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10222 struct remote_g_packet_guess
*guess
;
10224 int bytes
= send_g_packet ();
10227 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10229 if (guess
->bytes
== bytes
)
10230 return guess
->tdesc
;
10232 /* We discard the g packet. A minor optimization would be to
10233 hold on to it, and fill the register cache once we have selected
10234 an architecture, but it's too tricky to do safely. */
10237 return target
->beneath
->to_read_description (target
->beneath
);
10240 /* Remote file transfer support. This is host-initiated I/O, not
10241 target-initiated; for target-initiated, see remote-fileio.c. */
10243 /* If *LEFT is at least the length of STRING, copy STRING to
10244 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10245 decrease *LEFT. Otherwise raise an error. */
10248 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10250 int len
= strlen (string
);
10253 error (_("Packet too long for target."));
10255 memcpy (*buffer
, string
, len
);
10259 /* NUL-terminate the buffer as a convenience, if there is
10265 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10266 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10267 decrease *LEFT. Otherwise raise an error. */
10270 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10273 if (2 * len
> *left
)
10274 error (_("Packet too long for target."));
10276 bin2hex (bytes
, *buffer
, len
);
10277 *buffer
+= 2 * len
;
10280 /* NUL-terminate the buffer as a convenience, if there is
10286 /* If *LEFT is large enough, convert VALUE to hex and add it to
10287 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10288 decrease *LEFT. Otherwise raise an error. */
10291 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10293 int len
= hexnumlen (value
);
10296 error (_("Packet too long for target."));
10298 hexnumstr (*buffer
, value
);
10302 /* NUL-terminate the buffer as a convenience, if there is
10308 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10309 value, *REMOTE_ERRNO to the remote error number or zero if none
10310 was included, and *ATTACHMENT to point to the start of the annex
10311 if any. The length of the packet isn't needed here; there may
10312 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10314 Return 0 if the packet could be parsed, -1 if it could not. If
10315 -1 is returned, the other variables may not be initialized. */
10318 remote_hostio_parse_result (char *buffer
, int *retcode
,
10319 int *remote_errno
, char **attachment
)
10324 *attachment
= NULL
;
10326 if (buffer
[0] != 'F')
10330 *retcode
= strtol (&buffer
[1], &p
, 16);
10331 if (errno
!= 0 || p
== &buffer
[1])
10334 /* Check for ",errno". */
10338 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10339 if (errno
!= 0 || p
+ 1 == p2
)
10344 /* Check for ";attachment". If there is no attachment, the
10345 packet should end here. */
10348 *attachment
= p
+ 1;
10351 else if (*p
== '\0')
10357 /* Send a prepared I/O packet to the target and read its response.
10358 The prepared packet is in the global RS->BUF before this function
10359 is called, and the answer is there when we return.
10361 COMMAND_BYTES is the length of the request to send, which may include
10362 binary data. WHICH_PACKET is the packet configuration to check
10363 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10364 is set to the error number and -1 is returned. Otherwise the value
10365 returned by the function is returned.
10367 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10368 attachment is expected; an error will be reported if there's a
10369 mismatch. If one is found, *ATTACHMENT will be set to point into
10370 the packet buffer and *ATTACHMENT_LEN will be set to the
10371 attachment's length. */
10374 remote_hostio_send_command (int command_bytes
, int which_packet
,
10375 int *remote_errno
, char **attachment
,
10376 int *attachment_len
)
10378 struct remote_state
*rs
= get_remote_state ();
10379 int ret
, bytes_read
;
10380 char *attachment_tmp
;
10382 if (!rs
->remote_desc
10383 || packet_support (which_packet
) == PACKET_DISABLE
)
10385 *remote_errno
= FILEIO_ENOSYS
;
10389 putpkt_binary (rs
->buf
, command_bytes
);
10390 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10392 /* If it timed out, something is wrong. Don't try to parse the
10394 if (bytes_read
< 0)
10396 *remote_errno
= FILEIO_EINVAL
;
10400 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10403 *remote_errno
= FILEIO_EINVAL
;
10405 case PACKET_UNKNOWN
:
10406 *remote_errno
= FILEIO_ENOSYS
;
10412 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10415 *remote_errno
= FILEIO_EINVAL
;
10419 /* Make sure we saw an attachment if and only if we expected one. */
10420 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10421 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10423 *remote_errno
= FILEIO_EINVAL
;
10427 /* If an attachment was found, it must point into the packet buffer;
10428 work out how many bytes there were. */
10429 if (attachment_tmp
!= NULL
)
10431 *attachment
= attachment_tmp
;
10432 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10438 /* Invalidate the readahead cache. */
10441 readahead_cache_invalidate (void)
10443 struct remote_state
*rs
= get_remote_state ();
10445 rs
->readahead_cache
.fd
= -1;
10448 /* Invalidate the readahead cache if it is holding data for FD. */
10451 readahead_cache_invalidate_fd (int fd
)
10453 struct remote_state
*rs
= get_remote_state ();
10455 if (rs
->readahead_cache
.fd
== fd
)
10456 rs
->readahead_cache
.fd
= -1;
10459 /* Set the filesystem remote_hostio functions that take FILENAME
10460 arguments will use. Return 0 on success, or -1 if an error
10461 occurs (and set *REMOTE_ERRNO). */
10464 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10466 struct remote_state
*rs
= get_remote_state ();
10467 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10469 int left
= get_remote_packet_size () - 1;
10473 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10476 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10479 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10481 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10482 remote_buffer_add_string (&p
, &left
, arg
);
10484 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10485 remote_errno
, NULL
, NULL
);
10487 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10491 rs
->fs_pid
= required_pid
;
10496 /* Implementation of to_fileio_open. */
10499 remote_hostio_open (struct target_ops
*self
,
10500 struct inferior
*inf
, const char *filename
,
10501 int flags
, int mode
, int *remote_errno
)
10503 struct remote_state
*rs
= get_remote_state ();
10505 int left
= get_remote_packet_size () - 1;
10507 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10510 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10512 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10513 strlen (filename
));
10514 remote_buffer_add_string (&p
, &left
, ",");
10516 remote_buffer_add_int (&p
, &left
, flags
);
10517 remote_buffer_add_string (&p
, &left
, ",");
10519 remote_buffer_add_int (&p
, &left
, mode
);
10521 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10522 remote_errno
, NULL
, NULL
);
10525 /* Implementation of to_fileio_pwrite. */
10528 remote_hostio_pwrite (struct target_ops
*self
,
10529 int fd
, const gdb_byte
*write_buf
, int len
,
10530 ULONGEST offset
, int *remote_errno
)
10532 struct remote_state
*rs
= get_remote_state ();
10534 int left
= get_remote_packet_size ();
10537 readahead_cache_invalidate_fd (fd
);
10539 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10541 remote_buffer_add_int (&p
, &left
, fd
);
10542 remote_buffer_add_string (&p
, &left
, ",");
10544 remote_buffer_add_int (&p
, &left
, offset
);
10545 remote_buffer_add_string (&p
, &left
, ",");
10547 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10548 get_remote_packet_size () - (p
- rs
->buf
));
10550 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10551 remote_errno
, NULL
, NULL
);
10554 /* Helper for the implementation of to_fileio_pread. Read the file
10555 from the remote side with vFile:pread. */
10558 remote_hostio_pread_vFile (struct target_ops
*self
,
10559 int fd
, gdb_byte
*read_buf
, int len
,
10560 ULONGEST offset
, int *remote_errno
)
10562 struct remote_state
*rs
= get_remote_state ();
10565 int left
= get_remote_packet_size ();
10566 int ret
, attachment_len
;
10569 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10571 remote_buffer_add_int (&p
, &left
, fd
);
10572 remote_buffer_add_string (&p
, &left
, ",");
10574 remote_buffer_add_int (&p
, &left
, len
);
10575 remote_buffer_add_string (&p
, &left
, ",");
10577 remote_buffer_add_int (&p
, &left
, offset
);
10579 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10580 remote_errno
, &attachment
,
10586 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10588 if (read_len
!= ret
)
10589 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10594 /* Serve pread from the readahead cache. Returns number of bytes
10595 read, or 0 if the request can't be served from the cache. */
10598 remote_hostio_pread_from_cache (struct remote_state
*rs
,
10599 int fd
, gdb_byte
*read_buf
, size_t len
,
10602 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10604 if (cache
->fd
== fd
10605 && cache
->offset
<= offset
10606 && offset
< cache
->offset
+ cache
->bufsize
)
10608 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
10610 if (offset
+ len
> max
)
10611 len
= max
- offset
;
10613 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
10620 /* Implementation of to_fileio_pread. */
10623 remote_hostio_pread (struct target_ops
*self
,
10624 int fd
, gdb_byte
*read_buf
, int len
,
10625 ULONGEST offset
, int *remote_errno
)
10628 struct remote_state
*rs
= get_remote_state ();
10629 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10631 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10634 cache
->hit_count
++;
10637 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
10638 pulongest (cache
->hit_count
));
10642 cache
->miss_count
++;
10644 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
10645 pulongest (cache
->miss_count
));
10648 cache
->offset
= offset
;
10649 cache
->bufsize
= get_remote_packet_size ();
10650 cache
->buf
= xrealloc (cache
->buf
, cache
->bufsize
);
10652 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
10653 cache
->offset
, remote_errno
);
10656 readahead_cache_invalidate_fd (fd
);
10660 cache
->bufsize
= ret
;
10661 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10664 /* Implementation of to_fileio_close. */
10667 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10669 struct remote_state
*rs
= get_remote_state ();
10671 int left
= get_remote_packet_size () - 1;
10673 readahead_cache_invalidate_fd (fd
);
10675 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10677 remote_buffer_add_int (&p
, &left
, fd
);
10679 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10680 remote_errno
, NULL
, NULL
);
10683 /* Implementation of to_fileio_unlink. */
10686 remote_hostio_unlink (struct target_ops
*self
,
10687 struct inferior
*inf
, const char *filename
,
10690 struct remote_state
*rs
= get_remote_state ();
10692 int left
= get_remote_packet_size () - 1;
10694 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10697 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10699 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10700 strlen (filename
));
10702 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10703 remote_errno
, NULL
, NULL
);
10706 /* Implementation of to_fileio_readlink. */
10709 remote_hostio_readlink (struct target_ops
*self
,
10710 struct inferior
*inf
, const char *filename
,
10713 struct remote_state
*rs
= get_remote_state ();
10716 int left
= get_remote_packet_size ();
10717 int len
, attachment_len
;
10721 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10724 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10726 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10727 strlen (filename
));
10729 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10730 remote_errno
, &attachment
,
10736 ret
= xmalloc (len
+ 1);
10738 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10739 (gdb_byte
*) ret
, len
);
10740 if (read_len
!= len
)
10741 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10747 /* Implementation of to_fileio_fstat. */
10750 remote_hostio_fstat (struct target_ops
*self
,
10751 int fd
, struct stat
*st
,
10754 struct remote_state
*rs
= get_remote_state ();
10756 int left
= get_remote_packet_size ();
10757 int attachment_len
, ret
;
10759 struct fio_stat fst
;
10762 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10764 remote_buffer_add_int (&p
, &left
, fd
);
10766 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10767 remote_errno
, &attachment
,
10771 if (*remote_errno
!= FILEIO_ENOSYS
)
10774 /* Strictly we should return -1, ENOSYS here, but when
10775 "set sysroot remote:" was implemented in August 2008
10776 BFD's need for a stat function was sidestepped with
10777 this hack. This was not remedied until March 2015
10778 so we retain the previous behavior to avoid breaking
10781 Note that the memset is a March 2015 addition; older
10782 GDBs set st_size *and nothing else* so the structure
10783 would have garbage in all other fields. This might
10784 break something but retaining the previous behavior
10785 here would be just too wrong. */
10787 memset (st
, 0, sizeof (struct stat
));
10788 st
->st_size
= INT_MAX
;
10792 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10793 (gdb_byte
*) &fst
, sizeof (fst
));
10795 if (read_len
!= ret
)
10796 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10798 if (read_len
!= sizeof (fst
))
10799 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10800 read_len
, (int) sizeof (fst
));
10802 remote_fileio_to_host_stat (&fst
, st
);
10807 /* Implementation of to_filesystem_is_local. */
10810 remote_filesystem_is_local (struct target_ops
*self
)
10812 /* Valgrind GDB presents itself as a remote target but works
10813 on the local filesystem: it does not implement remote get
10814 and users are not expected to set a sysroot. To handle
10815 this case we treat the remote filesystem as local if the
10816 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
10817 does not support vFile:open. */
10818 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
10820 enum packet_support ps
= packet_support (PACKET_vFile_open
);
10822 if (ps
== PACKET_SUPPORT_UNKNOWN
)
10824 int fd
, remote_errno
;
10826 /* Try opening a file to probe support. The supplied
10827 filename is irrelevant, we only care about whether
10828 the stub recognizes the packet or not. */
10829 fd
= remote_hostio_open (self
, NULL
, "just probing",
10830 FILEIO_O_RDONLY
, 0700,
10834 remote_hostio_close (self
, fd
, &remote_errno
);
10836 ps
= packet_support (PACKET_vFile_open
);
10839 if (ps
== PACKET_DISABLE
)
10841 static int warning_issued
= 0;
10843 if (!warning_issued
)
10845 warning (_("remote target does not support file"
10846 " transfer, attempting to access files"
10847 " from local filesystem."));
10848 warning_issued
= 1;
10859 remote_fileio_errno_to_host (int errnum
)
10865 case FILEIO_ENOENT
:
10873 case FILEIO_EACCES
:
10875 case FILEIO_EFAULT
:
10879 case FILEIO_EEXIST
:
10881 case FILEIO_ENODEV
:
10883 case FILEIO_ENOTDIR
:
10885 case FILEIO_EISDIR
:
10887 case FILEIO_EINVAL
:
10889 case FILEIO_ENFILE
:
10891 case FILEIO_EMFILE
:
10895 case FILEIO_ENOSPC
:
10897 case FILEIO_ESPIPE
:
10901 case FILEIO_ENOSYS
:
10903 case FILEIO_ENAMETOOLONG
:
10904 return ENAMETOOLONG
;
10910 remote_hostio_error (int errnum
)
10912 int host_error
= remote_fileio_errno_to_host (errnum
);
10914 if (host_error
== -1)
10915 error (_("Unknown remote I/O error %d"), errnum
);
10917 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10921 remote_hostio_close_cleanup (void *opaque
)
10923 int fd
= *(int *) opaque
;
10926 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10930 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10932 struct cleanup
*back_to
, *close_cleanup
;
10933 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10936 int bytes_in_buffer
;
10939 struct remote_state
*rs
= get_remote_state ();
10941 if (!rs
->remote_desc
)
10942 error (_("command can only be used with remote target"));
10944 file
= gdb_fopen_cloexec (local_file
, "rb");
10946 perror_with_name (local_file
);
10947 back_to
= make_cleanup_fclose (file
);
10949 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10950 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10952 0700, &remote_errno
);
10954 remote_hostio_error (remote_errno
);
10956 /* Send up to this many bytes at once. They won't all fit in the
10957 remote packet limit, so we'll transfer slightly fewer. */
10958 io_size
= get_remote_packet_size ();
10959 buffer
= xmalloc (io_size
);
10960 make_cleanup (xfree
, buffer
);
10962 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10964 bytes_in_buffer
= 0;
10967 while (bytes_in_buffer
|| !saw_eof
)
10971 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10972 io_size
- bytes_in_buffer
,
10977 error (_("Error reading %s."), local_file
);
10980 /* EOF. Unless there is something still in the
10981 buffer from the last iteration, we are done. */
10983 if (bytes_in_buffer
== 0)
10991 bytes
+= bytes_in_buffer
;
10992 bytes_in_buffer
= 0;
10994 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10996 offset
, &remote_errno
);
10999 remote_hostio_error (remote_errno
);
11000 else if (retcode
== 0)
11001 error (_("Remote write of %d bytes returned 0!"), bytes
);
11002 else if (retcode
< bytes
)
11004 /* Short write. Save the rest of the read data for the next
11006 bytes_in_buffer
= bytes
- retcode
;
11007 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11013 discard_cleanups (close_cleanup
);
11014 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11015 remote_hostio_error (remote_errno
);
11018 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11019 do_cleanups (back_to
);
11023 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11025 struct cleanup
*back_to
, *close_cleanup
;
11026 int fd
, remote_errno
, bytes
, io_size
;
11030 struct remote_state
*rs
= get_remote_state ();
11032 if (!rs
->remote_desc
)
11033 error (_("command can only be used with remote target"));
11035 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11036 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
11038 remote_hostio_error (remote_errno
);
11040 file
= gdb_fopen_cloexec (local_file
, "wb");
11042 perror_with_name (local_file
);
11043 back_to
= make_cleanup_fclose (file
);
11045 /* Send up to this many bytes at once. They won't all fit in the
11046 remote packet limit, so we'll transfer slightly fewer. */
11047 io_size
= get_remote_packet_size ();
11048 buffer
= xmalloc (io_size
);
11049 make_cleanup (xfree
, buffer
);
11051 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11056 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11057 fd
, buffer
, io_size
, offset
, &remote_errno
);
11059 /* Success, but no bytes, means end-of-file. */
11062 remote_hostio_error (remote_errno
);
11066 bytes
= fwrite (buffer
, 1, bytes
, file
);
11068 perror_with_name (local_file
);
11071 discard_cleanups (close_cleanup
);
11072 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11073 remote_hostio_error (remote_errno
);
11076 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11077 do_cleanups (back_to
);
11081 remote_file_delete (const char *remote_file
, int from_tty
)
11083 int retcode
, remote_errno
;
11084 struct remote_state
*rs
= get_remote_state ();
11086 if (!rs
->remote_desc
)
11087 error (_("command can only be used with remote target"));
11089 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11090 NULL
, remote_file
, &remote_errno
);
11092 remote_hostio_error (remote_errno
);
11095 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11099 remote_put_command (char *args
, int from_tty
)
11101 struct cleanup
*back_to
;
11105 error_no_arg (_("file to put"));
11107 argv
= gdb_buildargv (args
);
11108 back_to
= make_cleanup_freeargv (argv
);
11109 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11110 error (_("Invalid parameters to remote put"));
11112 remote_file_put (argv
[0], argv
[1], from_tty
);
11114 do_cleanups (back_to
);
11118 remote_get_command (char *args
, int from_tty
)
11120 struct cleanup
*back_to
;
11124 error_no_arg (_("file to get"));
11126 argv
= gdb_buildargv (args
);
11127 back_to
= make_cleanup_freeargv (argv
);
11128 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11129 error (_("Invalid parameters to remote get"));
11131 remote_file_get (argv
[0], argv
[1], from_tty
);
11133 do_cleanups (back_to
);
11137 remote_delete_command (char *args
, int from_tty
)
11139 struct cleanup
*back_to
;
11143 error_no_arg (_("file to delete"));
11145 argv
= gdb_buildargv (args
);
11146 back_to
= make_cleanup_freeargv (argv
);
11147 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11148 error (_("Invalid parameters to remote delete"));
11150 remote_file_delete (argv
[0], from_tty
);
11152 do_cleanups (back_to
);
11156 remote_command (char *args
, int from_tty
)
11158 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11162 remote_can_execute_reverse (struct target_ops
*self
)
11164 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11165 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11172 remote_supports_non_stop (struct target_ops
*self
)
11178 remote_supports_disable_randomization (struct target_ops
*self
)
11180 /* Only supported in extended mode. */
11185 remote_supports_multi_process (struct target_ops
*self
)
11187 struct remote_state
*rs
= get_remote_state ();
11189 /* Only extended-remote handles being attached to multiple
11190 processes, even though plain remote can use the multi-process
11191 thread id extensions, so that GDB knows the target process's
11193 return rs
->extended
&& remote_multi_process_p (rs
);
11197 remote_supports_cond_tracepoints (void)
11199 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11203 remote_supports_cond_breakpoints (struct target_ops
*self
)
11205 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11209 remote_supports_fast_tracepoints (void)
11211 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11215 remote_supports_static_tracepoints (void)
11217 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11221 remote_supports_install_in_trace (void)
11223 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11227 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11229 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11234 remote_supports_string_tracing (struct target_ops
*self
)
11236 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11240 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11242 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11246 remote_trace_init (struct target_ops
*self
)
11249 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11250 if (strcmp (target_buf
, "OK") != 0)
11251 error (_("Target does not support this command."));
11254 static void free_actions_list (char **actions_list
);
11255 static void free_actions_list_cleanup_wrapper (void *);
11257 free_actions_list_cleanup_wrapper (void *al
)
11259 free_actions_list (al
);
11263 free_actions_list (char **actions_list
)
11267 if (actions_list
== 0)
11270 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11271 xfree (actions_list
[ndx
]);
11273 xfree (actions_list
);
11276 /* Recursive routine to walk through command list including loops, and
11277 download packets for each command. */
11280 remote_download_command_source (int num
, ULONGEST addr
,
11281 struct command_line
*cmds
)
11283 struct remote_state
*rs
= get_remote_state ();
11284 struct command_line
*cmd
;
11286 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11288 QUIT
; /* Allow user to bail out with ^C. */
11289 strcpy (rs
->buf
, "QTDPsrc:");
11290 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11291 rs
->buf
+ strlen (rs
->buf
),
11292 rs
->buf_size
- strlen (rs
->buf
));
11294 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11295 if (strcmp (target_buf
, "OK"))
11296 warning (_("Target does not support source download."));
11298 if (cmd
->control_type
== while_control
11299 || cmd
->control_type
== while_stepping_control
)
11301 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11303 QUIT
; /* Allow user to bail out with ^C. */
11304 strcpy (rs
->buf
, "QTDPsrc:");
11305 encode_source_string (num
, addr
, "cmd", "end",
11306 rs
->buf
+ strlen (rs
->buf
),
11307 rs
->buf_size
- strlen (rs
->buf
));
11309 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11310 if (strcmp (target_buf
, "OK"))
11311 warning (_("Target does not support source download."));
11317 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11319 #define BUF_SIZE 2048
11323 char buf
[BUF_SIZE
];
11324 char **tdp_actions
;
11325 char **stepping_actions
;
11327 struct cleanup
*old_chain
= NULL
;
11328 struct agent_expr
*aexpr
;
11329 struct cleanup
*aexpr_chain
= NULL
;
11331 struct breakpoint
*b
= loc
->owner
;
11332 struct tracepoint
*t
= (struct tracepoint
*) b
;
11334 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11335 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11337 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11340 tpaddr
= loc
->address
;
11341 sprintf_vma (addrbuf
, tpaddr
);
11342 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11343 addrbuf
, /* address */
11344 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11345 t
->step_count
, t
->pass_count
);
11346 /* Fast tracepoints are mostly handled by the target, but we can
11347 tell the target how big of an instruction block should be moved
11349 if (b
->type
== bp_fast_tracepoint
)
11351 /* Only test for support at download time; we may not know
11352 target capabilities at definition time. */
11353 if (remote_supports_fast_tracepoints ())
11355 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11357 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11358 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11360 /* If it passed validation at definition but fails now,
11361 something is very wrong. */
11362 internal_error (__FILE__
, __LINE__
,
11363 _("Fast tracepoint not "
11364 "valid during download"));
11367 /* Fast tracepoints are functionally identical to regular
11368 tracepoints, so don't take lack of support as a reason to
11369 give up on the trace run. */
11370 warning (_("Target does not support fast tracepoints, "
11371 "downloading %d as regular tracepoint"), b
->number
);
11373 else if (b
->type
== bp_static_tracepoint
)
11375 /* Only test for support at download time; we may not know
11376 target capabilities at definition time. */
11377 if (remote_supports_static_tracepoints ())
11379 struct static_tracepoint_marker marker
;
11381 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11382 strcat (buf
, ":S");
11384 error (_("Static tracepoint not valid during download"));
11387 /* Fast tracepoints are functionally identical to regular
11388 tracepoints, so don't take lack of support as a reason
11389 to give up on the trace run. */
11390 error (_("Target does not support static tracepoints"));
11392 /* If the tracepoint has a conditional, make it into an agent
11393 expression and append to the definition. */
11396 /* Only test support at download time, we may not know target
11397 capabilities at definition time. */
11398 if (remote_supports_cond_tracepoints ())
11400 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11401 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11402 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11404 pkt
= buf
+ strlen (buf
);
11405 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11406 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11408 do_cleanups (aexpr_chain
);
11411 warning (_("Target does not support conditional tracepoints, "
11412 "ignoring tp %d cond"), b
->number
);
11415 if (b
->commands
|| *default_collect
)
11418 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11419 if (strcmp (target_buf
, "OK"))
11420 error (_("Target does not support tracepoints."));
11422 /* do_single_steps (t); */
11425 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11427 QUIT
; /* Allow user to bail out with ^C. */
11428 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11429 b
->number
, addrbuf
, /* address */
11431 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11434 remote_get_noisy_reply (&target_buf
,
11436 if (strcmp (target_buf
, "OK"))
11437 error (_("Error on target while setting tracepoints."));
11440 if (stepping_actions
)
11442 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11444 QUIT
; /* Allow user to bail out with ^C. */
11445 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11446 b
->number
, addrbuf
, /* address */
11447 ((ndx
== 0) ? "S" : ""),
11448 stepping_actions
[ndx
],
11449 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11451 remote_get_noisy_reply (&target_buf
,
11453 if (strcmp (target_buf
, "OK"))
11454 error (_("Error on target while setting tracepoints."));
11458 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11460 if (b
->location
!= NULL
)
11462 strcpy (buf
, "QTDPsrc:");
11463 encode_source_string (b
->number
, loc
->address
, "at",
11464 event_location_to_string (b
->location
),
11465 buf
+ strlen (buf
), 2048 - strlen (buf
));
11467 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11468 if (strcmp (target_buf
, "OK"))
11469 warning (_("Target does not support source download."));
11471 if (b
->cond_string
)
11473 strcpy (buf
, "QTDPsrc:");
11474 encode_source_string (b
->number
, loc
->address
,
11475 "cond", b
->cond_string
, buf
+ strlen (buf
),
11476 2048 - strlen (buf
));
11478 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11479 if (strcmp (target_buf
, "OK"))
11480 warning (_("Target does not support source download."));
11482 remote_download_command_source (b
->number
, loc
->address
,
11483 breakpoint_commands (b
));
11486 do_cleanups (old_chain
);
11490 remote_can_download_tracepoint (struct target_ops
*self
)
11492 struct remote_state
*rs
= get_remote_state ();
11493 struct trace_status
*ts
;
11496 /* Don't try to install tracepoints until we've relocated our
11497 symbols, and fetched and merged the target's tracepoint list with
11499 if (rs
->starting_up
)
11502 ts
= current_trace_status ();
11503 status
= remote_get_trace_status (self
, ts
);
11505 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11508 /* If we are in a tracing experiment, but remote stub doesn't support
11509 installing tracepoint in trace, we have to return. */
11510 if (!remote_supports_install_in_trace ())
11518 remote_download_trace_state_variable (struct target_ops
*self
,
11519 struct trace_state_variable
*tsv
)
11521 struct remote_state
*rs
= get_remote_state ();
11524 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11525 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11527 p
= rs
->buf
+ strlen (rs
->buf
);
11528 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11529 error (_("Trace state variable name too long for tsv definition packet"));
11530 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11533 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11534 if (*target_buf
== '\0')
11535 error (_("Target does not support this command."));
11536 if (strcmp (target_buf
, "OK") != 0)
11537 error (_("Error on target while downloading trace state variable."));
11541 remote_enable_tracepoint (struct target_ops
*self
,
11542 struct bp_location
*location
)
11544 struct remote_state
*rs
= get_remote_state ();
11547 sprintf_vma (addr_buf
, location
->address
);
11548 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11549 location
->owner
->number
, addr_buf
);
11551 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11552 if (*rs
->buf
== '\0')
11553 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11554 if (strcmp (rs
->buf
, "OK") != 0)
11555 error (_("Error on target while enabling tracepoint."));
11559 remote_disable_tracepoint (struct target_ops
*self
,
11560 struct bp_location
*location
)
11562 struct remote_state
*rs
= get_remote_state ();
11565 sprintf_vma (addr_buf
, location
->address
);
11566 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11567 location
->owner
->number
, addr_buf
);
11569 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11570 if (*rs
->buf
== '\0')
11571 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11572 if (strcmp (rs
->buf
, "OK") != 0)
11573 error (_("Error on target while disabling tracepoint."));
11577 remote_trace_set_readonly_regions (struct target_ops
*self
)
11581 bfd_size_type size
;
11587 return; /* No information to give. */
11589 strcpy (target_buf
, "QTro");
11590 offset
= strlen (target_buf
);
11591 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11593 char tmp1
[40], tmp2
[40];
11596 if ((s
->flags
& SEC_LOAD
) == 0 ||
11597 /* (s->flags & SEC_CODE) == 0 || */
11598 (s
->flags
& SEC_READONLY
) == 0)
11602 vma
= bfd_get_section_vma (abfd
, s
);
11603 size
= bfd_get_section_size (s
);
11604 sprintf_vma (tmp1
, vma
);
11605 sprintf_vma (tmp2
, vma
+ size
);
11606 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11607 if (offset
+ sec_length
+ 1 > target_buf_size
)
11609 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11611 Too many sections for read-only sections definition packet."));
11614 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11616 offset
+= sec_length
;
11620 putpkt (target_buf
);
11621 getpkt (&target_buf
, &target_buf_size
, 0);
11626 remote_trace_start (struct target_ops
*self
)
11628 putpkt ("QTStart");
11629 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11630 if (*target_buf
== '\0')
11631 error (_("Target does not support this command."));
11632 if (strcmp (target_buf
, "OK") != 0)
11633 error (_("Bogus reply from target: %s"), target_buf
);
11637 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11639 /* Initialize it just to avoid a GCC false warning. */
11641 /* FIXME we need to get register block size some other way. */
11642 extern int trace_regblock_size
;
11643 enum packet_result result
;
11645 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11648 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11650 putpkt ("qTStatus");
11654 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11656 CATCH (ex
, RETURN_MASK_ERROR
)
11658 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11660 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11663 throw_exception (ex
);
11667 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11669 /* If the remote target doesn't do tracing, flag it. */
11670 if (result
== PACKET_UNKNOWN
)
11673 /* We're working with a live target. */
11674 ts
->filename
= NULL
;
11677 error (_("Bogus trace status reply from target: %s"), target_buf
);
11679 /* Function 'parse_trace_status' sets default value of each field of
11680 'ts' at first, so we don't have to do it here. */
11681 parse_trace_status (p
, ts
);
11683 return ts
->running
;
11687 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11688 struct uploaded_tp
*utp
)
11690 struct remote_state
*rs
= get_remote_state ();
11692 struct bp_location
*loc
;
11693 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11694 size_t size
= get_remote_packet_size ();
11698 tp
->base
.hit_count
= 0;
11699 tp
->traceframe_usage
= 0;
11700 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11702 /* If the tracepoint was never downloaded, don't go asking for
11704 if (tp
->number_on_target
== 0)
11706 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11707 phex_nz (loc
->address
, 0));
11709 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11710 if (reply
&& *reply
)
11713 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11719 utp
->hit_count
= 0;
11720 utp
->traceframe_usage
= 0;
11721 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11722 phex_nz (utp
->addr
, 0));
11724 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11725 if (reply
&& *reply
)
11728 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11734 remote_trace_stop (struct target_ops
*self
)
11737 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11738 if (*target_buf
== '\0')
11739 error (_("Target does not support this command."));
11740 if (strcmp (target_buf
, "OK") != 0)
11741 error (_("Bogus reply from target: %s"), target_buf
);
11745 remote_trace_find (struct target_ops
*self
,
11746 enum trace_find_type type
, int num
,
11747 CORE_ADDR addr1
, CORE_ADDR addr2
,
11750 struct remote_state
*rs
= get_remote_state ();
11751 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11753 int target_frameno
= -1, target_tracept
= -1;
11755 /* Lookups other than by absolute frame number depend on the current
11756 trace selected, so make sure it is correct on the remote end
11758 if (type
!= tfind_number
)
11759 set_remote_traceframe ();
11762 strcpy (p
, "QTFrame:");
11763 p
= strchr (p
, '\0');
11767 xsnprintf (p
, endbuf
- p
, "%x", num
);
11770 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11773 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11776 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11777 phex_nz (addr2
, 0));
11779 case tfind_outside
:
11780 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11781 phex_nz (addr2
, 0));
11784 error (_("Unknown trace find type %d"), type
);
11788 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11789 if (*reply
== '\0')
11790 error (_("Target does not support this command."));
11792 while (reply
&& *reply
)
11797 target_frameno
= (int) strtol (p
, &reply
, 16);
11799 error (_("Unable to parse trace frame number"));
11800 /* Don't update our remote traceframe number cache on failure
11801 to select a remote traceframe. */
11802 if (target_frameno
== -1)
11807 target_tracept
= (int) strtol (p
, &reply
, 16);
11809 error (_("Unable to parse tracepoint number"));
11811 case 'O': /* "OK"? */
11812 if (reply
[1] == 'K' && reply
[2] == '\0')
11815 error (_("Bogus reply from target: %s"), reply
);
11818 error (_("Bogus reply from target: %s"), reply
);
11821 *tpp
= target_tracept
;
11823 rs
->remote_traceframe_number
= target_frameno
;
11824 return target_frameno
;
11828 remote_get_trace_state_variable_value (struct target_ops
*self
,
11829 int tsvnum
, LONGEST
*val
)
11831 struct remote_state
*rs
= get_remote_state ();
11835 set_remote_traceframe ();
11837 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11839 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11840 if (reply
&& *reply
)
11844 unpack_varlen_hex (reply
+ 1, &uval
);
11845 *val
= (LONGEST
) uval
;
11853 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11855 struct remote_state
*rs
= get_remote_state ();
11859 strcpy (p
, "QTSave:");
11861 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11862 error (_("Remote file name too long for trace save packet"));
11863 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11866 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11867 if (*reply
== '\0')
11868 error (_("Target does not support this command."));
11869 if (strcmp (reply
, "OK") != 0)
11870 error (_("Bogus reply from target: %s"), reply
);
11874 /* This is basically a memory transfer, but needs to be its own packet
11875 because we don't know how the target actually organizes its trace
11876 memory, plus we want to be able to ask for as much as possible, but
11877 not be unhappy if we don't get as much as we ask for. */
11880 remote_get_raw_trace_data (struct target_ops
*self
,
11881 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11883 struct remote_state
*rs
= get_remote_state ();
11889 strcpy (p
, "qTBuffer:");
11891 p
+= hexnumstr (p
, offset
);
11893 p
+= hexnumstr (p
, len
);
11897 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11898 if (reply
&& *reply
)
11900 /* 'l' by itself means we're at the end of the buffer and
11901 there is nothing more to get. */
11905 /* Convert the reply into binary. Limit the number of bytes to
11906 convert according to our passed-in buffer size, rather than
11907 what was returned in the packet; if the target is
11908 unexpectedly generous and gives us a bigger reply than we
11909 asked for, we don't want to crash. */
11910 rslt
= hex2bin (target_buf
, buf
, len
);
11914 /* Something went wrong, flag as an error. */
11919 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11921 struct remote_state
*rs
= get_remote_state ();
11923 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11927 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11929 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11930 if (*reply
== '\0')
11931 error (_("Target does not support this command."));
11932 if (strcmp (reply
, "OK") != 0)
11933 error (_("Bogus reply from target: %s"), reply
);
11936 warning (_("Target does not support disconnected tracing."));
11940 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11942 struct thread_info
*info
= find_thread_ptid (ptid
);
11944 if (info
&& info
->priv
)
11945 return info
->priv
->core
;
11950 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11952 struct remote_state
*rs
= get_remote_state ();
11955 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11957 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11958 if (*reply
== '\0')
11959 error (_("Target does not support this command."));
11960 if (strcmp (reply
, "OK") != 0)
11961 error (_("Bogus reply from target: %s"), reply
);
11964 static struct traceframe_info
*
11965 remote_traceframe_info (struct target_ops
*self
)
11969 text
= target_read_stralloc (¤t_target
,
11970 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11973 struct traceframe_info
*info
;
11974 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11976 info
= parse_traceframe_info (text
);
11977 do_cleanups (back_to
);
11984 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11985 instruction on which a fast tracepoint may be placed. Returns -1
11986 if the packet is not supported, and 0 if the minimum instruction
11987 length is unknown. */
11990 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11992 struct remote_state
*rs
= get_remote_state ();
11995 /* If we're not debugging a process yet, the IPA can't be
11997 if (!target_has_execution
)
12000 /* Make sure the remote is pointing at the right process. */
12001 set_general_process ();
12003 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12005 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12006 if (*reply
== '\0')
12010 ULONGEST min_insn_len
;
12012 unpack_varlen_hex (reply
, &min_insn_len
);
12014 return (int) min_insn_len
;
12019 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12021 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12023 struct remote_state
*rs
= get_remote_state ();
12024 char *buf
= rs
->buf
;
12025 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12026 enum packet_result result
;
12028 gdb_assert (val
>= 0 || val
== -1);
12029 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12030 /* Send -1 as literal "-1" to avoid host size dependency. */
12034 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12037 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12040 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12041 result
= packet_ok (rs
->buf
,
12042 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12044 if (result
!= PACKET_OK
)
12045 warning (_("Bogus reply from target: %s"), rs
->buf
);
12050 remote_set_trace_notes (struct target_ops
*self
,
12051 const char *user
, const char *notes
,
12052 const char *stop_notes
)
12054 struct remote_state
*rs
= get_remote_state ();
12056 char *buf
= rs
->buf
;
12057 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12060 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12063 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12064 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12070 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12071 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12077 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12078 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12082 /* Ensure the buffer is terminated. */
12086 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12087 if (*reply
== '\0')
12090 if (strcmp (reply
, "OK") != 0)
12091 error (_("Bogus reply from target: %s"), reply
);
12097 remote_use_agent (struct target_ops
*self
, int use
)
12099 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12101 struct remote_state
*rs
= get_remote_state ();
12103 /* If the stub supports QAgent. */
12104 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12106 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12108 if (strcmp (rs
->buf
, "OK") == 0)
12119 remote_can_use_agent (struct target_ops
*self
)
12121 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12124 struct btrace_target_info
12126 /* The ptid of the traced thread. */
12129 /* The obtained branch trace configuration. */
12130 struct btrace_config conf
;
12133 /* Reset our idea of our target's btrace configuration. */
12136 remote_btrace_reset (void)
12138 struct remote_state
*rs
= get_remote_state ();
12140 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12143 /* Check whether the target supports branch tracing. */
12146 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12148 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12150 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12155 case BTRACE_FORMAT_NONE
:
12158 case BTRACE_FORMAT_BTS
:
12159 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12161 case BTRACE_FORMAT_PT
:
12162 /* The trace is decoded on the host. Even if our target supports it,
12163 we still need to have libipt to decode the trace. */
12164 #if defined (HAVE_LIBIPT)
12165 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12166 #else /* !defined (HAVE_LIBIPT) */
12168 #endif /* !defined (HAVE_LIBIPT) */
12171 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12174 /* Synchronize the configuration with the target. */
12177 btrace_sync_conf (const struct btrace_config
*conf
)
12179 struct packet_config
*packet
;
12180 struct remote_state
*rs
;
12181 char *buf
, *pos
, *endbuf
;
12183 rs
= get_remote_state ();
12185 endbuf
= buf
+ get_remote_packet_size ();
12187 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12188 if (packet_config_support (packet
) == PACKET_ENABLE
12189 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12192 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12196 getpkt (&buf
, &rs
->buf_size
, 0);
12198 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12200 if (buf
[0] == 'E' && buf
[1] == '.')
12201 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12203 error (_("Failed to configure the BTS buffer size."));
12206 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12209 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12210 if (packet_config_support (packet
) == PACKET_ENABLE
12211 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12214 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12218 getpkt (&buf
, &rs
->buf_size
, 0);
12220 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12222 if (buf
[0] == 'E' && buf
[1] == '.')
12223 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12225 error (_("Failed to configure the trace buffer size."));
12228 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12232 /* Read the current thread's btrace configuration from the target and
12233 store it into CONF. */
12236 btrace_read_config (struct btrace_config
*conf
)
12240 xml
= target_read_stralloc (¤t_target
,
12241 TARGET_OBJECT_BTRACE_CONF
, "");
12244 struct cleanup
*cleanup
;
12246 cleanup
= make_cleanup (xfree
, xml
);
12247 parse_xml_btrace_conf (conf
, xml
);
12248 do_cleanups (cleanup
);
12252 /* Enable branch tracing. */
12254 static struct btrace_target_info
*
12255 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12256 const struct btrace_config
*conf
)
12258 struct btrace_target_info
*tinfo
= NULL
;
12259 struct packet_config
*packet
= NULL
;
12260 struct remote_state
*rs
= get_remote_state ();
12261 char *buf
= rs
->buf
;
12262 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12264 switch (conf
->format
)
12266 case BTRACE_FORMAT_BTS
:
12267 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12270 case BTRACE_FORMAT_PT
:
12271 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12275 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12276 error (_("Target does not support branch tracing."));
12278 btrace_sync_conf (conf
);
12280 set_general_thread (ptid
);
12282 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12284 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12286 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12288 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12289 error (_("Could not enable branch tracing for %s: %s"),
12290 target_pid_to_str (ptid
), rs
->buf
+ 2);
12292 error (_("Could not enable branch tracing for %s."),
12293 target_pid_to_str (ptid
));
12296 tinfo
= xzalloc (sizeof (*tinfo
));
12297 tinfo
->ptid
= ptid
;
12299 /* If we fail to read the configuration, we lose some information, but the
12300 tracing itself is not impacted. */
12303 btrace_read_config (&tinfo
->conf
);
12305 CATCH (err
, RETURN_MASK_ERROR
)
12307 if (err
.message
!= NULL
)
12308 warning ("%s", err
.message
);
12315 /* Disable branch tracing. */
12318 remote_disable_btrace (struct target_ops
*self
,
12319 struct btrace_target_info
*tinfo
)
12321 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12322 struct remote_state
*rs
= get_remote_state ();
12323 char *buf
= rs
->buf
;
12324 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12326 if (packet_config_support (packet
) != PACKET_ENABLE
)
12327 error (_("Target does not support branch tracing."));
12329 set_general_thread (tinfo
->ptid
);
12331 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12335 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12337 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12338 error (_("Could not disable branch tracing for %s: %s"),
12339 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12341 error (_("Could not disable branch tracing for %s."),
12342 target_pid_to_str (tinfo
->ptid
));
12348 /* Teardown branch tracing. */
12351 remote_teardown_btrace (struct target_ops
*self
,
12352 struct btrace_target_info
*tinfo
)
12354 /* We must not talk to the target during teardown. */
12358 /* Read the branch trace. */
12360 static enum btrace_error
12361 remote_read_btrace (struct target_ops
*self
,
12362 struct btrace_data
*btrace
,
12363 struct btrace_target_info
*tinfo
,
12364 enum btrace_read_type type
)
12366 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12367 struct remote_state
*rs
= get_remote_state ();
12368 struct cleanup
*cleanup
;
12372 if (packet_config_support (packet
) != PACKET_ENABLE
)
12373 error (_("Target does not support branch tracing."));
12375 #if !defined(HAVE_LIBEXPAT)
12376 error (_("Cannot process branch tracing result. XML parsing not supported."));
12381 case BTRACE_READ_ALL
:
12384 case BTRACE_READ_NEW
:
12387 case BTRACE_READ_DELTA
:
12391 internal_error (__FILE__
, __LINE__
,
12392 _("Bad branch tracing read type: %u."),
12393 (unsigned int) type
);
12396 xml
= target_read_stralloc (¤t_target
,
12397 TARGET_OBJECT_BTRACE
, annex
);
12399 return BTRACE_ERR_UNKNOWN
;
12401 cleanup
= make_cleanup (xfree
, xml
);
12402 parse_xml_btrace (btrace
, xml
);
12403 do_cleanups (cleanup
);
12405 return BTRACE_ERR_NONE
;
12408 static const struct btrace_config
*
12409 remote_btrace_conf (struct target_ops
*self
,
12410 const struct btrace_target_info
*tinfo
)
12412 return &tinfo
->conf
;
12416 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12418 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12422 /* Implementation of to_load. */
12425 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12427 generic_load (name
, from_tty
);
12430 /* Accepts an integer PID; returns a string representing a file that
12431 can be opened on the remote side to get the symbols for the child
12432 process. Returns NULL if the operation is not supported. */
12435 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12437 static char *filename
= NULL
;
12438 struct inferior
*inf
;
12439 char *annex
= NULL
;
12441 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12444 if (filename
!= NULL
)
12447 inf
= find_inferior_pid (pid
);
12449 internal_error (__FILE__
, __LINE__
,
12450 _("not currently attached to process %d"), pid
);
12452 if (!inf
->fake_pid_p
)
12454 const int annex_size
= 9;
12456 annex
= alloca (annex_size
);
12457 xsnprintf (annex
, annex_size
, "%x", pid
);
12460 filename
= target_read_stralloc (¤t_target
,
12461 TARGET_OBJECT_EXEC_FILE
, annex
);
12467 init_remote_ops (void)
12469 remote_ops
.to_shortname
= "remote";
12470 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12471 remote_ops
.to_doc
=
12472 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12473 Specify the serial device it is connected to\n\
12474 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12475 remote_ops
.to_open
= remote_open
;
12476 remote_ops
.to_close
= remote_close
;
12477 remote_ops
.to_detach
= remote_detach
;
12478 remote_ops
.to_disconnect
= remote_disconnect
;
12479 remote_ops
.to_resume
= remote_resume
;
12480 remote_ops
.to_wait
= remote_wait
;
12481 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12482 remote_ops
.to_store_registers
= remote_store_registers
;
12483 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12484 remote_ops
.to_files_info
= remote_files_info
;
12485 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12486 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12487 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12488 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12489 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12490 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12491 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12492 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12493 remote_ops
.to_watchpoint_addr_within_range
=
12494 remote_watchpoint_addr_within_range
;
12495 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12496 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12497 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12498 remote_ops
.to_region_ok_for_hw_watchpoint
12499 = remote_region_ok_for_hw_watchpoint
;
12500 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12501 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12502 remote_ops
.to_kill
= remote_kill
;
12503 remote_ops
.to_load
= remote_load
;
12504 remote_ops
.to_mourn_inferior
= remote_mourn
;
12505 remote_ops
.to_pass_signals
= remote_pass_signals
;
12506 remote_ops
.to_program_signals
= remote_program_signals
;
12507 remote_ops
.to_thread_alive
= remote_thread_alive
;
12508 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12509 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12510 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12511 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12512 remote_ops
.to_stop
= remote_stop
;
12513 remote_ops
.to_interrupt
= remote_interrupt
;
12514 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12515 remote_ops
.to_rcmd
= remote_rcmd
;
12516 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12517 remote_ops
.to_log_command
= serial_log_command
;
12518 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12519 remote_ops
.to_stratum
= process_stratum
;
12520 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12521 remote_ops
.to_has_memory
= default_child_has_memory
;
12522 remote_ops
.to_has_stack
= default_child_has_stack
;
12523 remote_ops
.to_has_registers
= default_child_has_registers
;
12524 remote_ops
.to_has_execution
= default_child_has_execution
;
12525 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12526 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12527 remote_ops
.to_magic
= OPS_MAGIC
;
12528 remote_ops
.to_memory_map
= remote_memory_map
;
12529 remote_ops
.to_flash_erase
= remote_flash_erase
;
12530 remote_ops
.to_flash_done
= remote_flash_done
;
12531 remote_ops
.to_read_description
= remote_read_description
;
12532 remote_ops
.to_search_memory
= remote_search_memory
;
12533 remote_ops
.to_can_async_p
= remote_can_async_p
;
12534 remote_ops
.to_is_async_p
= remote_is_async_p
;
12535 remote_ops
.to_async
= remote_async
;
12536 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12537 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12538 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12539 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12540 remote_ops
.to_supports_disable_randomization
12541 = remote_supports_disable_randomization
;
12542 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12543 remote_ops
.to_fileio_open
= remote_hostio_open
;
12544 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12545 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12546 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12547 remote_ops
.to_fileio_close
= remote_hostio_close
;
12548 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12549 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12550 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12551 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12552 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12553 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12554 remote_ops
.to_trace_init
= remote_trace_init
;
12555 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12556 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12557 remote_ops
.to_download_trace_state_variable
12558 = remote_download_trace_state_variable
;
12559 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12560 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12561 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12562 remote_ops
.to_trace_start
= remote_trace_start
;
12563 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12564 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12565 remote_ops
.to_trace_stop
= remote_trace_stop
;
12566 remote_ops
.to_trace_find
= remote_trace_find
;
12567 remote_ops
.to_get_trace_state_variable_value
12568 = remote_get_trace_state_variable_value
;
12569 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12570 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12571 remote_ops
.to_upload_trace_state_variables
12572 = remote_upload_trace_state_variables
;
12573 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12574 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12575 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12576 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12577 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12578 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12579 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12580 remote_ops
.to_verify_memory
= remote_verify_memory
;
12581 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12582 remote_ops
.to_set_permissions
= remote_set_permissions
;
12583 remote_ops
.to_static_tracepoint_marker_at
12584 = remote_static_tracepoint_marker_at
;
12585 remote_ops
.to_static_tracepoint_markers_by_strid
12586 = remote_static_tracepoint_markers_by_strid
;
12587 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12588 remote_ops
.to_use_agent
= remote_use_agent
;
12589 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12590 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12591 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12592 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12593 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12594 remote_ops
.to_read_btrace
= remote_read_btrace
;
12595 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12596 remote_ops
.to_augmented_libraries_svr4_read
=
12597 remote_augmented_libraries_svr4_read
;
12600 /* Set up the extended remote vector by making a copy of the standard
12601 remote vector and adding to it. */
12604 init_extended_remote_ops (void)
12606 extended_remote_ops
= remote_ops
;
12608 extended_remote_ops
.to_shortname
= "extended-remote";
12609 extended_remote_ops
.to_longname
=
12610 "Extended remote serial target in gdb-specific protocol";
12611 extended_remote_ops
.to_doc
=
12612 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12613 Specify the serial device it is connected to (e.g. /dev/ttya).";
12614 extended_remote_ops
.to_open
= extended_remote_open
;
12615 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12616 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12617 extended_remote_ops
.to_detach
= extended_remote_detach
;
12618 extended_remote_ops
.to_attach
= extended_remote_attach
;
12619 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12620 extended_remote_ops
.to_kill
= extended_remote_kill
;
12621 extended_remote_ops
.to_supports_disable_randomization
12622 = extended_remote_supports_disable_randomization
;
12623 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12624 extended_remote_ops
.to_insert_fork_catchpoint
12625 = remote_insert_fork_catchpoint
;
12626 extended_remote_ops
.to_remove_fork_catchpoint
12627 = remote_remove_fork_catchpoint
;
12628 extended_remote_ops
.to_insert_vfork_catchpoint
12629 = remote_insert_vfork_catchpoint
;
12630 extended_remote_ops
.to_remove_vfork_catchpoint
12631 = remote_remove_vfork_catchpoint
;
12635 remote_can_async_p (struct target_ops
*ops
)
12637 struct remote_state
*rs
= get_remote_state ();
12639 if (!target_async_permitted
)
12640 /* We only enable async when the user specifically asks for it. */
12643 /* We're async whenever the serial device is. */
12644 return serial_can_async_p (rs
->remote_desc
);
12648 remote_is_async_p (struct target_ops
*ops
)
12650 struct remote_state
*rs
= get_remote_state ();
12652 if (!target_async_permitted
)
12653 /* We only enable async when the user specifically asks for it. */
12656 /* We're async whenever the serial device is. */
12657 return serial_is_async_p (rs
->remote_desc
);
12660 /* Pass the SERIAL event on and up to the client. One day this code
12661 will be able to delay notifying the client of an event until the
12662 point where an entire packet has been received. */
12664 static serial_event_ftype remote_async_serial_handler
;
12667 remote_async_serial_handler (struct serial
*scb
, void *context
)
12669 struct remote_state
*rs
= context
;
12671 /* Don't propogate error information up to the client. Instead let
12672 the client find out about the error by querying the target. */
12673 inferior_event_handler (INF_REG_EVENT
, NULL
);
12677 remote_async_inferior_event_handler (gdb_client_data data
)
12679 inferior_event_handler (INF_REG_EVENT
, NULL
);
12683 remote_async (struct target_ops
*ops
, int enable
)
12685 struct remote_state
*rs
= get_remote_state ();
12689 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12691 /* If there are pending events in the stop reply queue tell the
12692 event loop to process them. */
12693 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12694 mark_async_event_handler (remote_async_inferior_event_token
);
12698 serial_async (rs
->remote_desc
, NULL
, NULL
);
12699 clear_async_event_handler (remote_async_inferior_event_token
);
12704 set_remote_cmd (char *args
, int from_tty
)
12706 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12710 show_remote_cmd (char *args
, int from_tty
)
12712 /* We can't just use cmd_show_list here, because we want to skip
12713 the redundant "show remote Z-packet" and the legacy aliases. */
12714 struct cleanup
*showlist_chain
;
12715 struct cmd_list_element
*list
= remote_show_cmdlist
;
12716 struct ui_out
*uiout
= current_uiout
;
12718 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12719 for (; list
!= NULL
; list
= list
->next
)
12720 if (strcmp (list
->name
, "Z-packet") == 0)
12722 else if (list
->type
== not_set_cmd
)
12723 /* Alias commands are exactly like the original, except they
12724 don't have the normal type. */
12728 struct cleanup
*option_chain
12729 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12731 ui_out_field_string (uiout
, "name", list
->name
);
12732 ui_out_text (uiout
, ": ");
12733 if (list
->type
== show_cmd
)
12734 do_show_command ((char *) NULL
, from_tty
, list
);
12736 cmd_func (list
, NULL
, from_tty
);
12737 /* Close the tuple. */
12738 do_cleanups (option_chain
);
12741 /* Close the tuple. */
12742 do_cleanups (showlist_chain
);
12746 /* Function to be called whenever a new objfile (shlib) is detected. */
12748 remote_new_objfile (struct objfile
*objfile
)
12750 struct remote_state
*rs
= get_remote_state ();
12752 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12753 remote_check_symbols ();
12756 /* Pull all the tracepoints defined on the target and create local
12757 data structures representing them. We don't want to create real
12758 tracepoints yet, we don't want to mess up the user's existing
12762 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12764 struct remote_state
*rs
= get_remote_state ();
12767 /* Ask for a first packet of tracepoint definition. */
12769 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12771 while (*p
&& *p
!= 'l')
12773 parse_tracepoint_definition (p
, utpp
);
12774 /* Ask for another packet of tracepoint definition. */
12776 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12783 remote_upload_trace_state_variables (struct target_ops
*self
,
12784 struct uploaded_tsv
**utsvp
)
12786 struct remote_state
*rs
= get_remote_state ();
12789 /* Ask for a first packet of variable definition. */
12791 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12793 while (*p
&& *p
!= 'l')
12795 parse_tsv_definition (p
, utsvp
);
12796 /* Ask for another packet of variable definition. */
12798 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12804 /* The "set/show range-stepping" show hook. */
12807 show_range_stepping (struct ui_file
*file
, int from_tty
,
12808 struct cmd_list_element
*c
,
12811 fprintf_filtered (file
,
12812 _("Debugger's willingness to use range stepping "
12813 "is %s.\n"), value
);
12816 /* The "set/show range-stepping" set hook. */
12819 set_range_stepping (char *ignore_args
, int from_tty
,
12820 struct cmd_list_element
*c
)
12822 struct remote_state
*rs
= get_remote_state ();
12824 /* Whene enabling, check whether range stepping is actually
12825 supported by the target, and warn if not. */
12826 if (use_range_stepping
)
12828 if (rs
->remote_desc
!= NULL
)
12830 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12831 remote_vcont_probe (rs
);
12833 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12834 && rs
->supports_vCont
.r
)
12838 warning (_("Range stepping is not supported by the current target"));
12843 _initialize_remote (void)
12845 struct remote_state
*rs
;
12846 struct cmd_list_element
*cmd
;
12847 const char *cmd_name
;
12849 /* architecture specific data */
12850 remote_gdbarch_data_handle
=
12851 gdbarch_data_register_post_init (init_remote_state
);
12852 remote_g_packet_data_handle
=
12853 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12855 /* Initialize the per-target state. At the moment there is only one
12856 of these, not one per target. Only one target is active at a
12858 remote_state
= new_remote_state ();
12860 init_remote_ops ();
12861 add_target (&remote_ops
);
12863 init_extended_remote_ops ();
12864 add_target (&extended_remote_ops
);
12866 /* Hook into new objfile notification. */
12867 observer_attach_new_objfile (remote_new_objfile
);
12868 /* We're no longer interested in notification events of an inferior
12870 observer_attach_inferior_exit (discard_pending_stop_replies
);
12872 /* Set up signal handlers. */
12873 async_sigint_remote_token
=
12874 create_async_signal_handler (async_remote_interrupt
, NULL
);
12875 async_sigint_remote_twice_token
=
12876 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12879 init_remote_threadtests ();
12882 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12883 /* set/show remote ... */
12885 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12886 Remote protocol specific variables\n\
12887 Configure various remote-protocol specific variables such as\n\
12888 the packets being used"),
12889 &remote_set_cmdlist
, "set remote ",
12890 0 /* allow-unknown */, &setlist
);
12891 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12892 Remote protocol specific variables\n\
12893 Configure various remote-protocol specific variables such as\n\
12894 the packets being used"),
12895 &remote_show_cmdlist
, "show remote ",
12896 0 /* allow-unknown */, &showlist
);
12898 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12899 Compare section data on target to the exec file.\n\
12900 Argument is a single section name (default: all loaded sections).\n\
12901 To compare only read-only loaded sections, specify the -r option."),
12904 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12905 Send an arbitrary packet to a remote target.\n\
12906 maintenance packet TEXT\n\
12907 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12908 this command sends the string TEXT to the inferior, and displays the\n\
12909 response packet. GDB supplies the initial `$' character, and the\n\
12910 terminating `#' character and checksum."),
12913 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12914 Set whether to send break if interrupted."), _("\
12915 Show whether to send break if interrupted."), _("\
12916 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12917 set_remotebreak
, show_remotebreak
,
12918 &setlist
, &showlist
);
12919 cmd_name
= "remotebreak";
12920 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12921 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12922 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12923 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12924 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12926 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12927 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12929 Set interrupt sequence to remote target."), _("\
12930 Show interrupt sequence to remote target."), _("\
12931 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12932 NULL
, show_interrupt_sequence
,
12933 &remote_set_cmdlist
,
12934 &remote_show_cmdlist
);
12936 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12937 &interrupt_on_connect
, _("\
12938 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12939 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12940 If set, interrupt sequence is sent to remote target."),
12942 &remote_set_cmdlist
, &remote_show_cmdlist
);
12944 /* Install commands for configuring memory read/write packets. */
12946 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12947 Set the maximum number of bytes per memory write packet (deprecated)."),
12949 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12950 Show the maximum number of bytes per memory write packet (deprecated)."),
12952 add_cmd ("memory-write-packet-size", no_class
,
12953 set_memory_write_packet_size
, _("\
12954 Set the maximum number of bytes per memory-write packet.\n\
12955 Specify the number of bytes in a packet or 0 (zero) for the\n\
12956 default packet size. The actual limit is further reduced\n\
12957 dependent on the target. Specify ``fixed'' to disable the\n\
12958 further restriction and ``limit'' to enable that restriction."),
12959 &remote_set_cmdlist
);
12960 add_cmd ("memory-read-packet-size", no_class
,
12961 set_memory_read_packet_size
, _("\
12962 Set the maximum number of bytes per memory-read packet.\n\
12963 Specify the number of bytes in a packet or 0 (zero) for the\n\
12964 default packet size. The actual limit is further reduced\n\
12965 dependent on the target. Specify ``fixed'' to disable the\n\
12966 further restriction and ``limit'' to enable that restriction."),
12967 &remote_set_cmdlist
);
12968 add_cmd ("memory-write-packet-size", no_class
,
12969 show_memory_write_packet_size
,
12970 _("Show the maximum number of bytes per memory-write packet."),
12971 &remote_show_cmdlist
);
12972 add_cmd ("memory-read-packet-size", no_class
,
12973 show_memory_read_packet_size
,
12974 _("Show the maximum number of bytes per memory-read packet."),
12975 &remote_show_cmdlist
);
12977 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12978 &remote_hw_watchpoint_limit
, _("\
12979 Set the maximum number of target hardware watchpoints."), _("\
12980 Show the maximum number of target hardware watchpoints."), _("\
12981 Specify a negative limit for unlimited."),
12982 NULL
, NULL
, /* FIXME: i18n: The maximum
12983 number of target hardware
12984 watchpoints is %s. */
12985 &remote_set_cmdlist
, &remote_show_cmdlist
);
12986 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12987 &remote_hw_watchpoint_length_limit
, _("\
12988 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12989 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12990 Specify a negative limit for unlimited."),
12991 NULL
, NULL
, /* FIXME: i18n: The maximum
12992 length (in bytes) of a target
12993 hardware watchpoint is %s. */
12994 &remote_set_cmdlist
, &remote_show_cmdlist
);
12995 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12996 &remote_hw_breakpoint_limit
, _("\
12997 Set the maximum number of target hardware breakpoints."), _("\
12998 Show the maximum number of target hardware breakpoints."), _("\
12999 Specify a negative limit for unlimited."),
13000 NULL
, NULL
, /* FIXME: i18n: The maximum
13001 number of target hardware
13002 breakpoints is %s. */
13003 &remote_set_cmdlist
, &remote_show_cmdlist
);
13005 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13006 &remote_address_size
, _("\
13007 Set the maximum size of the address (in bits) in a memory packet."), _("\
13008 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13010 NULL
, /* FIXME: i18n: */
13011 &setlist
, &showlist
);
13013 init_all_packet_configs ();
13015 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13016 "X", "binary-download", 1);
13018 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13019 "vCont", "verbose-resume", 0);
13021 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13022 "QPassSignals", "pass-signals", 0);
13024 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13025 "QProgramSignals", "program-signals", 0);
13027 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13028 "qSymbol", "symbol-lookup", 0);
13030 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13031 "P", "set-register", 1);
13033 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13034 "p", "fetch-register", 1);
13036 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13037 "Z0", "software-breakpoint", 0);
13039 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13040 "Z1", "hardware-breakpoint", 0);
13042 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13043 "Z2", "write-watchpoint", 0);
13045 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13046 "Z3", "read-watchpoint", 0);
13048 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13049 "Z4", "access-watchpoint", 0);
13051 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13052 "qXfer:auxv:read", "read-aux-vector", 0);
13054 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13055 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13057 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13058 "qXfer:features:read", "target-features", 0);
13060 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13061 "qXfer:libraries:read", "library-info", 0);
13063 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13064 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13066 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13067 "qXfer:memory-map:read", "memory-map", 0);
13069 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13070 "qXfer:spu:read", "read-spu-object", 0);
13072 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13073 "qXfer:spu:write", "write-spu-object", 0);
13075 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13076 "qXfer:osdata:read", "osdata", 0);
13078 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13079 "qXfer:threads:read", "threads", 0);
13081 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13082 "qXfer:siginfo:read", "read-siginfo-object", 0);
13084 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13085 "qXfer:siginfo:write", "write-siginfo-object", 0);
13087 add_packet_config_cmd
13088 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13089 "qXfer:traceframe-info:read", "traceframe-info", 0);
13091 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13092 "qXfer:uib:read", "unwind-info-block", 0);
13094 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13095 "qGetTLSAddr", "get-thread-local-storage-address",
13098 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13099 "qGetTIBAddr", "get-thread-information-block-address",
13102 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13103 "bc", "reverse-continue", 0);
13105 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13106 "bs", "reverse-step", 0);
13108 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13109 "qSupported", "supported-packets", 0);
13111 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13112 "qSearch:memory", "search-memory", 0);
13114 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13115 "qTStatus", "trace-status", 0);
13117 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13118 "vFile:setfs", "hostio-setfs", 0);
13120 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13121 "vFile:open", "hostio-open", 0);
13123 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13124 "vFile:pread", "hostio-pread", 0);
13126 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13127 "vFile:pwrite", "hostio-pwrite", 0);
13129 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13130 "vFile:close", "hostio-close", 0);
13132 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13133 "vFile:unlink", "hostio-unlink", 0);
13135 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13136 "vFile:readlink", "hostio-readlink", 0);
13138 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13139 "vFile:fstat", "hostio-fstat", 0);
13141 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13142 "vAttach", "attach", 0);
13144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13147 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13148 "QStartNoAckMode", "noack", 0);
13150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13151 "vKill", "kill", 0);
13153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13154 "qAttached", "query-attached", 0);
13156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13157 "ConditionalTracepoints",
13158 "conditional-tracepoints", 0);
13160 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13161 "ConditionalBreakpoints",
13162 "conditional-breakpoints", 0);
13164 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13165 "BreakpointCommands",
13166 "breakpoint-commands", 0);
13168 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13169 "FastTracepoints", "fast-tracepoints", 0);
13171 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13172 "TracepointSource", "TracepointSource", 0);
13174 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13175 "QAllow", "allow", 0);
13177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13178 "StaticTracepoints", "static-tracepoints", 0);
13180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13181 "InstallInTrace", "install-in-trace", 0);
13183 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13184 "qXfer:statictrace:read", "read-sdata-object", 0);
13186 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13187 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13189 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13190 "QDisableRandomization", "disable-randomization", 0);
13192 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13193 "QAgent", "agent", 0);
13195 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13196 "QTBuffer:size", "trace-buffer-size", 0);
13198 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13199 "Qbtrace:off", "disable-btrace", 0);
13201 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13202 "Qbtrace:bts", "enable-btrace-bts", 0);
13204 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13205 "Qbtrace:pt", "enable-btrace-pt", 0);
13207 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13208 "qXfer:btrace", "read-btrace", 0);
13210 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13211 "qXfer:btrace-conf", "read-btrace-conf", 0);
13213 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13214 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13216 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13217 "swbreak-feature", "swbreak-feature", 0);
13219 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13220 "hwbreak-feature", "hwbreak-feature", 0);
13222 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13223 "fork-event-feature", "fork-event-feature", 0);
13225 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13226 "vfork-event-feature", "vfork-event-feature", 0);
13228 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13229 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13231 /* Assert that we've registered "set remote foo-packet" commands
13232 for all packet configs. */
13236 for (i
= 0; i
< PACKET_MAX
; i
++)
13238 /* Ideally all configs would have a command associated. Some
13239 still don't though. */
13244 case PACKET_QNonStop
:
13245 case PACKET_multiprocess_feature
:
13246 case PACKET_EnableDisableTracepoints_feature
:
13247 case PACKET_tracenz_feature
:
13248 case PACKET_DisconnectedTracing_feature
:
13249 case PACKET_augmented_libraries_svr4_read_feature
:
13251 /* Additions to this list need to be well justified:
13252 pre-existing packets are OK; new packets are not. */
13260 /* This catches both forgetting to add a config command, and
13261 forgetting to remove a packet from the exception list. */
13262 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13266 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13267 Z sub-packet has its own set and show commands, but users may
13268 have sets to this variable in their .gdbinit files (or in their
13270 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13271 &remote_Z_packet_detect
, _("\
13272 Set use of remote protocol `Z' packets"), _("\
13273 Show use of remote protocol `Z' packets "), _("\
13274 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13276 set_remote_protocol_Z_packet_cmd
,
13277 show_remote_protocol_Z_packet_cmd
,
13278 /* FIXME: i18n: Use of remote protocol
13279 `Z' packets is %s. */
13280 &remote_set_cmdlist
, &remote_show_cmdlist
);
13282 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13283 Manipulate files on the remote system\n\
13284 Transfer files to and from the remote target system."),
13285 &remote_cmdlist
, "remote ",
13286 0 /* allow-unknown */, &cmdlist
);
13288 add_cmd ("put", class_files
, remote_put_command
,
13289 _("Copy a local file to the remote system."),
13292 add_cmd ("get", class_files
, remote_get_command
,
13293 _("Copy a remote file to the local system."),
13296 add_cmd ("delete", class_files
, remote_delete_command
,
13297 _("Delete a remote file."),
13300 remote_exec_file
= xstrdup ("");
13301 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13302 &remote_exec_file
, _("\
13303 Set the remote pathname for \"run\""), _("\
13304 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
13305 &remote_set_cmdlist
, &remote_show_cmdlist
);
13307 add_setshow_boolean_cmd ("range-stepping", class_run
,
13308 &use_range_stepping
, _("\
13309 Enable or disable range stepping."), _("\
13310 Show whether target-assisted range stepping is enabled."), _("\
13311 If on, and the target supports it, when stepping a source line, GDB\n\
13312 tells the target to step the corresponding range of addresses itself instead\n\
13313 of issuing multiple single-steps. This speeds up source level\n\
13314 stepping. If off, GDB always issues single-steps, even if range\n\
13315 stepping is supported by the target. The default is on."),
13316 set_range_stepping
,
13317 show_range_stepping
,
13321 /* Eventually initialize fileio. See fileio.c */
13322 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13324 /* Take advantage of the fact that the TID field is not used, to tag
13325 special ptids with it set to != 0. */
13326 magic_null_ptid
= ptid_build (42000, -1, 1);
13327 not_sent_ptid
= ptid_build (42000, -2, 1);
13328 any_thread_ptid
= ptid_build (42000, 0, 1);
13330 target_buf_size
= 2048;
13331 target_buf
= xmalloc (target_buf_size
);