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"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf
;
76 static long target_buf_size
;
78 /* Per-program-space data key. */
79 static const struct program_space_data
*remote_pspace_data
;
81 /* The variable registered as the control variable used by the
82 remote exec-file commands. While the remote exec-file setting is
83 per-program-space, the set/show machinery uses this as the
84 location of the remote exec-file value. */
85 static char *remote_exec_file_var
;
87 /* The size to align memory write packets, when practical. The protocol
88 does not guarantee any alignment, and gdb will generate short
89 writes and unaligned writes, but even as a best-effort attempt this
90 can improve bulk transfers. For instance, if a write is misaligned
91 relative to the target's data bus, the stub may need to make an extra
92 round trip fetching data from the target. This doesn't make a
93 huge difference, but it's easy to do, so we try to be helpful.
95 The alignment chosen is arbitrary; usually data bus width is
96 important here, not the possibly larger cache line size. */
97 enum { REMOTE_ALIGN_WRITES
= 16 };
99 /* Prototypes for local functions. */
100 static void async_cleanup_sigint_signal_handler (void *dummy
);
101 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
102 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
103 int forever
, int *is_notif
);
105 static void async_handle_remote_sigint (int);
106 static void async_handle_remote_sigint_twice (int);
108 static void remote_files_info (struct target_ops
*ignore
);
110 static void remote_prepare_to_store (struct target_ops
*self
,
111 struct regcache
*regcache
);
113 static void remote_open_1 (const char *, int, struct target_ops
*,
116 static void remote_close (struct target_ops
*self
);
120 static int remote_vkill (int pid
, struct remote_state
*rs
);
122 static void remote_mourn (struct target_ops
*ops
);
124 static void extended_remote_restart (void);
126 static void extended_remote_mourn (struct target_ops
*);
128 static void remote_send (char **buf
, long *sizeof_buf_p
);
130 static int readchar (int timeout
);
132 static void remote_serial_write (const char *str
, int len
);
134 static void remote_kill (struct target_ops
*ops
);
136 static int remote_can_async_p (struct target_ops
*);
138 static int remote_is_async_p (struct target_ops
*);
140 static void remote_async (struct target_ops
*ops
, int enable
);
142 static void sync_remote_interrupt_twice (int signo
);
144 static void interrupt_query (void);
146 static void set_general_thread (struct ptid ptid
);
147 static void set_continue_thread (struct ptid ptid
);
149 static void get_offsets (void);
151 static void skip_frame (void);
153 static long read_frame (char **buf_p
, long *sizeof_buf
);
155 static int hexnumlen (ULONGEST num
);
157 static void init_remote_ops (void);
159 static void init_extended_remote_ops (void);
161 static void remote_stop (struct target_ops
*self
, ptid_t
);
163 static int stubhex (int ch
);
165 static int hexnumstr (char *, ULONGEST
);
167 static int hexnumnstr (char *, ULONGEST
, int);
169 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
171 static void print_packet (const char *);
173 static void compare_sections_command (char *, int);
175 static void packet_command (char *, int);
177 static int stub_unpack_int (char *buff
, int fieldlength
);
179 static ptid_t
remote_current_thread (ptid_t oldptid
);
181 static int putpkt_binary (const char *buf
, int cnt
);
183 static void check_binary_download (CORE_ADDR addr
);
185 struct packet_config
;
187 static void show_packet_config_cmd (struct packet_config
*config
);
189 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
191 struct cmd_list_element
*c
,
194 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
195 static ptid_t
read_ptid (char *buf
, char **obuf
);
197 static void remote_set_permissions (struct target_ops
*self
);
199 static int remote_get_trace_status (struct target_ops
*self
,
200 struct trace_status
*ts
);
202 static int remote_upload_tracepoints (struct target_ops
*self
,
203 struct uploaded_tp
**utpp
);
205 static int remote_upload_trace_state_variables (struct target_ops
*self
,
206 struct uploaded_tsv
**utsvp
);
208 static void remote_query_supported (void);
210 static void remote_check_symbols (void);
212 void _initialize_remote (void);
215 static void stop_reply_xfree (struct stop_reply
*);
216 static void remote_parse_stop_reply (char *, struct stop_reply
*);
217 static void push_stop_reply (struct stop_reply
*);
218 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
219 static int peek_stop_reply (ptid_t ptid
);
221 struct threads_listing_context
;
222 static void remove_new_fork_children (struct threads_listing_context
*);
224 static void remote_async_inferior_event_handler (gdb_client_data
);
226 static void remote_terminal_ours (struct target_ops
*self
);
228 static int remote_read_description_p (struct target_ops
*target
);
230 static void remote_console_output (char *msg
);
232 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
234 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
236 static void remote_btrace_reset (void);
238 static int stop_reply_queue_length (void);
240 static void readahead_cache_invalidate (void);
244 static struct cmd_list_element
*remote_cmdlist
;
246 /* For "set remote" and "show remote". */
248 static struct cmd_list_element
*remote_set_cmdlist
;
249 static struct cmd_list_element
*remote_show_cmdlist
;
251 /* Stub vCont actions support.
253 Each field is a boolean flag indicating whether the stub reports
254 support for the corresponding action. */
256 struct vCont_action_support
271 /* Controls whether GDB is willing to use range stepping. */
273 static int use_range_stepping
= 1;
275 #define OPAQUETHREADBYTES 8
277 /* a 64 bit opaque identifier */
278 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
280 /* About this many threadisds fit in a packet. */
282 #define MAXTHREADLISTRESULTS 32
284 /* Data for the vFile:pread readahead cache. */
286 struct readahead_cache
288 /* The file descriptor for the file that is being cached. -1 if the
292 /* The offset into the file that the cache buffer corresponds
296 /* The buffer holding the cache contents. */
298 /* The buffer's size. We try to read as much as fits into a packet
302 /* Cache hit and miss counters. */
307 /* Description of the remote protocol state for the currently
308 connected target. This is per-target state, and independent of the
309 selected architecture. */
313 /* A buffer to use for incoming packets, and its current size. The
314 buffer is grown dynamically for larger incoming packets.
315 Outgoing packets may also be constructed in this buffer.
316 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
317 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
322 /* True if we're going through initial connection setup (finding out
323 about the remote side's threads, relocating symbols, etc.). */
326 /* If we negotiated packet size explicitly (and thus can bypass
327 heuristics for the largest packet size that will not overflow
328 a buffer in the stub), this will be set to that packet size.
329 Otherwise zero, meaning to use the guessed size. */
330 long explicit_packet_size
;
332 /* remote_wait is normally called when the target is running and
333 waits for a stop reply packet. But sometimes we need to call it
334 when the target is already stopped. We can send a "?" packet
335 and have remote_wait read the response. Or, if we already have
336 the response, we can stash it in BUF and tell remote_wait to
337 skip calling getpkt. This flag is set when BUF contains a
338 stop reply packet and the target is not waiting. */
339 int cached_wait_status
;
341 /* True, if in no ack mode. That is, neither GDB nor the stub will
342 expect acks from each other. The connection is assumed to be
346 /* True if we're connected in extended remote mode. */
349 /* True if we resumed the target and we're waiting for the target to
350 stop. In the mean time, we can't start another command/query.
351 The remote server wouldn't be ready to process it, so we'd
352 timeout waiting for a reply that would never come and eventually
353 we'd close the connection. This can happen in asynchronous mode
354 because we allow GDB commands while the target is running. */
355 int waiting_for_stop_reply
;
357 /* The status of the stub support for the various vCont actions. */
358 struct vCont_action_support supports_vCont
;
360 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
361 responded to that. */
364 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
365 remote_open knows that we don't have a file open when the program
367 struct serial
*remote_desc
;
369 /* These are the threads which we last sent to the remote system. The
370 TID member will be -1 for all or -2 for not sent yet. */
371 ptid_t general_thread
;
372 ptid_t continue_thread
;
374 /* This is the traceframe which we last selected on the remote system.
375 It will be -1 if no traceframe is selected. */
376 int remote_traceframe_number
;
378 char *last_pass_packet
;
380 /* The last QProgramSignals packet sent to the target. We bypass
381 sending a new program signals list down to the target if the new
382 packet is exactly the same as the last we sent. IOW, we only let
383 the target know about program signals list changes. */
384 char *last_program_signals_packet
;
386 enum gdb_signal last_sent_signal
;
390 char *finished_object
;
391 char *finished_annex
;
392 ULONGEST finished_offset
;
394 /* Should we try the 'ThreadInfo' query packet?
396 This variable (NOT available to the user: auto-detect only!)
397 determines whether GDB will use the new, simpler "ThreadInfo"
398 query or the older, more complex syntax for thread queries.
399 This is an auto-detect variable (set to true at each connect,
400 and set to false when the target fails to recognize it). */
401 int use_threadinfo_query
;
402 int use_threadextra_query
;
404 /* This is set to the data address of the access causing the target
405 to stop for a watchpoint. */
406 CORE_ADDR remote_watch_data_address
;
408 /* Whether the target stopped for a breakpoint/watchpoint. */
409 enum target_stop_reason stop_reason
;
411 threadref echo_nextthread
;
412 threadref nextthread
;
413 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
415 /* The state of remote notification. */
416 struct remote_notif_state
*notif_state
;
418 /* The branch trace configuration. */
419 struct btrace_config btrace_config
;
421 /* The argument to the last "vFile:setfs:" packet we sent, used
422 to avoid sending repeated unnecessary "vFile:setfs:" packets.
423 Initialized to -1 to indicate that no "vFile:setfs:" packet
424 has yet been sent. */
427 /* A readahead cache for vFile:pread. Often, reading a binary
428 involves a sequence of small reads. E.g., when parsing an ELF
429 file. A readahead cache helps mostly the case of remote
430 debugging on a connection with higher latency, due to the
431 request/reply nature of the RSP. We only cache data for a single
432 file descriptor at a time. */
433 struct readahead_cache readahead_cache
;
436 /* Private data that we'll store in (struct thread_info)->private. */
437 struct private_thread_info
444 free_private_thread_info (struct private_thread_info
*info
)
450 /* This data could be associated with a target, but we do not always
451 have access to the current target when we need it, so for now it is
452 static. This will be fine for as long as only one target is in use
454 static struct remote_state
*remote_state
;
456 static struct remote_state
*
457 get_remote_state_raw (void)
462 /* Allocate a new struct remote_state with xmalloc, initialize it, and
465 static struct remote_state
*
466 new_remote_state (void)
468 struct remote_state
*result
= XCNEW (struct remote_state
);
470 /* The default buffer size is unimportant; it will be expanded
471 whenever a larger buffer is needed. */
472 result
->buf_size
= 400;
473 result
->buf
= (char *) xmalloc (result
->buf_size
);
474 result
->remote_traceframe_number
= -1;
475 result
->last_sent_signal
= GDB_SIGNAL_0
;
481 /* Description of the remote protocol for a given architecture. */
485 long offset
; /* Offset into G packet. */
486 long regnum
; /* GDB's internal register number. */
487 LONGEST pnum
; /* Remote protocol register number. */
488 int in_g_packet
; /* Always part of G packet. */
489 /* long size in bytes; == register_size (target_gdbarch (), regnum);
491 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
495 struct remote_arch_state
497 /* Description of the remote protocol registers. */
498 long sizeof_g_packet
;
500 /* Description of the remote protocol registers indexed by REGNUM
501 (making an array gdbarch_num_regs in size). */
502 struct packet_reg
*regs
;
504 /* This is the size (in chars) of the first response to the ``g''
505 packet. It is used as a heuristic when determining the maximum
506 size of memory-read and memory-write packets. A target will
507 typically only reserve a buffer large enough to hold the ``g''
508 packet. The size does not include packet overhead (headers and
510 long actual_register_packet_size
;
512 /* This is the maximum size (in chars) of a non read/write packet.
513 It is also used as a cap on the size of read/write packets. */
514 long remote_packet_size
;
517 /* Utility: generate error from an incoming stub packet. */
519 trace_error (char *buf
)
522 return; /* not an error msg */
525 case '1': /* malformed packet error */
526 if (*++buf
== '0') /* general case: */
527 error (_("remote.c: error in outgoing packet."));
529 error (_("remote.c: error in outgoing packet at field #%ld."),
530 strtol (buf
, NULL
, 16));
532 error (_("Target returns error code '%s'."), buf
);
536 /* Utility: wait for reply from stub, while accepting "O" packets. */
538 remote_get_noisy_reply (char **buf_p
,
541 do /* Loop on reply from remote stub. */
545 QUIT
; /* Allow user to bail out with ^C. */
546 getpkt (buf_p
, sizeof_buf
, 0);
550 else if (startswith (buf
, "qRelocInsn:"))
553 CORE_ADDR from
, to
, org_to
;
555 int adjusted_size
= 0;
558 p
= buf
+ strlen ("qRelocInsn:");
559 pp
= unpack_varlen_hex (p
, &ul
);
561 error (_("invalid qRelocInsn packet: %s"), buf
);
565 unpack_varlen_hex (p
, &ul
);
572 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
575 CATCH (ex
, RETURN_MASK_ALL
)
577 if (ex
.error
== MEMORY_ERROR
)
579 /* Propagate memory errors silently back to the
580 target. The stub may have limited the range of
581 addresses we can write to, for example. */
585 /* Something unexpectedly bad happened. Be verbose
586 so we can tell what, and propagate the error back
587 to the stub, so it doesn't get stuck waiting for
589 exception_fprintf (gdb_stderr
, ex
,
590 _("warning: relocating instruction: "));
598 adjusted_size
= to
- org_to
;
600 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
604 else if (buf
[0] == 'O' && buf
[1] != 'K')
605 remote_console_output (buf
+ 1); /* 'O' message from stub */
607 return buf
; /* Here's the actual reply. */
612 /* Handle for retreving the remote protocol data from gdbarch. */
613 static struct gdbarch_data
*remote_gdbarch_data_handle
;
615 static struct remote_arch_state
*
616 get_remote_arch_state (void)
618 gdb_assert (target_gdbarch () != NULL
);
619 return ((struct remote_arch_state
*)
620 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
623 /* Fetch the global remote target state. */
625 static struct remote_state
*
626 get_remote_state (void)
628 /* Make sure that the remote architecture state has been
629 initialized, because doing so might reallocate rs->buf. Any
630 function which calls getpkt also needs to be mindful of changes
631 to rs->buf, but this call limits the number of places which run
633 get_remote_arch_state ();
635 return get_remote_state_raw ();
638 /* Cleanup routine for the remote module's pspace data. */
641 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
643 char *remote_exec_file
= (char *) arg
;
645 xfree (remote_exec_file
);
648 /* Fetch the remote exec-file from the current program space. */
651 get_remote_exec_file (void)
653 char *remote_exec_file
;
656 = (char *) program_space_data (current_program_space
,
658 if (remote_exec_file
== NULL
)
661 return remote_exec_file
;
664 /* Set the remote exec file for PSPACE. */
667 set_pspace_remote_exec_file (struct program_space
*pspace
,
668 char *remote_exec_file
)
670 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
673 set_program_space_data (pspace
, remote_pspace_data
,
674 xstrdup (remote_exec_file
));
677 /* The "set/show remote exec-file" set command hook. */
680 set_remote_exec_file (char *ignored
, int from_tty
,
681 struct cmd_list_element
*c
)
683 gdb_assert (remote_exec_file_var
!= NULL
);
684 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
687 /* The "set/show remote exec-file" show command hook. */
690 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
691 struct cmd_list_element
*cmd
, const char *value
)
693 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
697 compare_pnums (const void *lhs_
, const void *rhs_
)
699 const struct packet_reg
* const *lhs
700 = (const struct packet_reg
* const *) lhs_
;
701 const struct packet_reg
* const *rhs
702 = (const struct packet_reg
* const *) rhs_
;
704 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
706 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
713 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
715 int regnum
, num_remote_regs
, offset
;
716 struct packet_reg
**remote_regs
;
718 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
720 struct packet_reg
*r
= ®s
[regnum
];
722 if (register_size (gdbarch
, regnum
) == 0)
723 /* Do not try to fetch zero-sized (placeholder) registers. */
726 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
731 /* Define the g/G packet format as the contents of each register
732 with a remote protocol number, in order of ascending protocol
735 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
736 for (num_remote_regs
= 0, regnum
= 0;
737 regnum
< gdbarch_num_regs (gdbarch
);
739 if (regs
[regnum
].pnum
!= -1)
740 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
742 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
745 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
747 remote_regs
[regnum
]->in_g_packet
= 1;
748 remote_regs
[regnum
]->offset
= offset
;
749 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
755 /* Given the architecture described by GDBARCH, return the remote
756 protocol register's number and the register's offset in the g/G
757 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
758 If the target does not have a mapping for REGNUM, return false,
759 otherwise, return true. */
762 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
763 int *pnum
, int *poffset
)
766 struct packet_reg
*regs
;
767 struct cleanup
*old_chain
;
769 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
771 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
772 old_chain
= make_cleanup (xfree
, regs
);
774 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
776 *pnum
= regs
[regnum
].pnum
;
777 *poffset
= regs
[regnum
].offset
;
779 do_cleanups (old_chain
);
785 init_remote_state (struct gdbarch
*gdbarch
)
787 struct remote_state
*rs
= get_remote_state_raw ();
788 struct remote_arch_state
*rsa
;
790 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
792 /* Use the architecture to build a regnum<->pnum table, which will be
793 1:1 unless a feature set specifies otherwise. */
794 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
795 gdbarch_num_regs (gdbarch
),
798 /* Record the maximum possible size of the g packet - it may turn out
800 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
802 /* Default maximum number of characters in a packet body. Many
803 remote stubs have a hardwired buffer size of 400 bytes
804 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
805 as the maximum packet-size to ensure that the packet and an extra
806 NUL character can always fit in the buffer. This stops GDB
807 trashing stubs that try to squeeze an extra NUL into what is
808 already a full buffer (As of 1999-12-04 that was most stubs). */
809 rsa
->remote_packet_size
= 400 - 1;
811 /* This one is filled in when a ``g'' packet is received. */
812 rsa
->actual_register_packet_size
= 0;
814 /* Should rsa->sizeof_g_packet needs more space than the
815 default, adjust the size accordingly. Remember that each byte is
816 encoded as two characters. 32 is the overhead for the packet
817 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
818 (``$NN:G...#NN'') is a better guess, the below has been padded a
820 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
821 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
823 /* Make sure that the packet buffer is plenty big enough for
824 this architecture. */
825 if (rs
->buf_size
< rsa
->remote_packet_size
)
827 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
828 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
834 /* Return the current allowed size of a remote packet. This is
835 inferred from the current architecture, and should be used to
836 limit the length of outgoing packets. */
838 get_remote_packet_size (void)
840 struct remote_state
*rs
= get_remote_state ();
841 struct remote_arch_state
*rsa
= get_remote_arch_state ();
843 if (rs
->explicit_packet_size
)
844 return rs
->explicit_packet_size
;
846 return rsa
->remote_packet_size
;
849 static struct packet_reg
*
850 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
852 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
856 struct packet_reg
*r
= &rsa
->regs
[regnum
];
858 gdb_assert (r
->regnum
== regnum
);
863 static struct packet_reg
*
864 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
868 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
870 struct packet_reg
*r
= &rsa
->regs
[i
];
878 static struct target_ops remote_ops
;
880 static struct target_ops extended_remote_ops
;
882 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
883 ``forever'' still use the normal timeout mechanism. This is
884 currently used by the ASYNC code to guarentee that target reads
885 during the initial connect always time-out. Once getpkt has been
886 modified to return a timeout indication and, in turn
887 remote_wait()/wait_for_inferior() have gained a timeout parameter
889 static int wait_forever_enabled_p
= 1;
891 /* Allow the user to specify what sequence to send to the remote
892 when he requests a program interruption: Although ^C is usually
893 what remote systems expect (this is the default, here), it is
894 sometimes preferable to send a break. On other systems such
895 as the Linux kernel, a break followed by g, which is Magic SysRq g
896 is required in order to interrupt the execution. */
897 const char interrupt_sequence_control_c
[] = "Ctrl-C";
898 const char interrupt_sequence_break
[] = "BREAK";
899 const char interrupt_sequence_break_g
[] = "BREAK-g";
900 static const char *const interrupt_sequence_modes
[] =
902 interrupt_sequence_control_c
,
903 interrupt_sequence_break
,
904 interrupt_sequence_break_g
,
907 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
910 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
911 struct cmd_list_element
*c
,
914 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
915 fprintf_filtered (file
,
916 _("Send the ASCII ETX character (Ctrl-c) "
917 "to the remote target to interrupt the "
918 "execution of the program.\n"));
919 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
920 fprintf_filtered (file
,
921 _("send a break signal to the remote target "
922 "to interrupt the execution of the program.\n"));
923 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
924 fprintf_filtered (file
,
925 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
926 "the remote target to interrupt the execution "
927 "of Linux kernel.\n"));
929 internal_error (__FILE__
, __LINE__
,
930 _("Invalid value for interrupt_sequence_mode: %s."),
931 interrupt_sequence_mode
);
934 /* This boolean variable specifies whether interrupt_sequence is sent
935 to the remote target when gdb connects to it.
936 This is mostly needed when you debug the Linux kernel: The Linux kernel
937 expects BREAK g which is Magic SysRq g for connecting gdb. */
938 static int interrupt_on_connect
= 0;
940 /* This variable is used to implement the "set/show remotebreak" commands.
941 Since these commands are now deprecated in favor of "set/show remote
942 interrupt-sequence", it no longer has any effect on the code. */
943 static int remote_break
;
946 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
949 interrupt_sequence_mode
= interrupt_sequence_break
;
951 interrupt_sequence_mode
= interrupt_sequence_control_c
;
955 show_remotebreak (struct ui_file
*file
, int from_tty
,
956 struct cmd_list_element
*c
,
961 /* This variable sets the number of bits in an address that are to be
962 sent in a memory ("M" or "m") packet. Normally, after stripping
963 leading zeros, the entire address would be sent. This variable
964 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
965 initial implementation of remote.c restricted the address sent in
966 memory packets to ``host::sizeof long'' bytes - (typically 32
967 bits). Consequently, for 64 bit targets, the upper 32 bits of an
968 address was never sent. Since fixing this bug may cause a break in
969 some remote targets this variable is principly provided to
970 facilitate backward compatibility. */
972 static unsigned int remote_address_size
;
974 /* Temporary to track who currently owns the terminal. See
975 remote_terminal_* for more details. */
977 static int remote_async_terminal_ours_p
;
980 /* User configurable variables for the number of characters in a
981 memory read/write packet. MIN (rsa->remote_packet_size,
982 rsa->sizeof_g_packet) is the default. Some targets need smaller
983 values (fifo overruns, et.al.) and some users need larger values
984 (speed up transfers). The variables ``preferred_*'' (the user
985 request), ``current_*'' (what was actually set) and ``forced_*''
986 (Positive - a soft limit, negative - a hard limit). */
988 struct memory_packet_config
995 /* The default max memory-write-packet-size. The 16k is historical.
996 (It came from older GDB's using alloca for buffers and the
997 knowledge (folklore?) that some hosts don't cope very well with
998 large alloca calls.) */
999 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1001 /* The minimum remote packet size for memory transfers. Ensures we
1002 can write at least one byte. */
1003 #define MIN_MEMORY_PACKET_SIZE 20
1005 /* Compute the current size of a read/write packet. Since this makes
1006 use of ``actual_register_packet_size'' the computation is dynamic. */
1009 get_memory_packet_size (struct memory_packet_config
*config
)
1011 struct remote_state
*rs
= get_remote_state ();
1012 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1015 if (config
->fixed_p
)
1017 if (config
->size
<= 0)
1018 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1020 what_they_get
= config
->size
;
1024 what_they_get
= get_remote_packet_size ();
1025 /* Limit the packet to the size specified by the user. */
1026 if (config
->size
> 0
1027 && what_they_get
> config
->size
)
1028 what_they_get
= config
->size
;
1030 /* Limit it to the size of the targets ``g'' response unless we have
1031 permission from the stub to use a larger packet size. */
1032 if (rs
->explicit_packet_size
== 0
1033 && rsa
->actual_register_packet_size
> 0
1034 && what_they_get
> rsa
->actual_register_packet_size
)
1035 what_they_get
= rsa
->actual_register_packet_size
;
1037 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1038 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1040 /* Make sure there is room in the global buffer for this packet
1041 (including its trailing NUL byte). */
1042 if (rs
->buf_size
< what_they_get
+ 1)
1044 rs
->buf_size
= 2 * what_they_get
;
1045 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1048 return what_they_get
;
1051 /* Update the size of a read/write packet. If they user wants
1052 something really big then do a sanity check. */
1055 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1057 int fixed_p
= config
->fixed_p
;
1058 long size
= config
->size
;
1061 error (_("Argument required (integer, `fixed' or `limited')."));
1062 else if (strcmp (args
, "hard") == 0
1063 || strcmp (args
, "fixed") == 0)
1065 else if (strcmp (args
, "soft") == 0
1066 || strcmp (args
, "limit") == 0)
1072 size
= strtoul (args
, &end
, 0);
1074 error (_("Invalid %s (bad syntax)."), config
->name
);
1076 /* Instead of explicitly capping the size of a packet to or
1077 disallowing it, the user is allowed to set the size to
1078 something arbitrarily large. */
1081 /* So that the query shows the correct value. */
1083 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1086 if (fixed_p
&& !config
->fixed_p
)
1088 if (! query (_("The target may not be able to correctly handle a %s\n"
1089 "of %ld bytes. Change the packet size? "),
1090 config
->name
, size
))
1091 error (_("Packet size not changed."));
1093 /* Update the config. */
1094 config
->fixed_p
= fixed_p
;
1095 config
->size
= size
;
1099 show_memory_packet_size (struct memory_packet_config
*config
)
1101 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1102 if (config
->fixed_p
)
1103 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1104 get_memory_packet_size (config
));
1106 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1107 get_memory_packet_size (config
));
1110 static struct memory_packet_config memory_write_packet_config
=
1112 "memory-write-packet-size",
1116 set_memory_write_packet_size (char *args
, int from_tty
)
1118 set_memory_packet_size (args
, &memory_write_packet_config
);
1122 show_memory_write_packet_size (char *args
, int from_tty
)
1124 show_memory_packet_size (&memory_write_packet_config
);
1128 get_memory_write_packet_size (void)
1130 return get_memory_packet_size (&memory_write_packet_config
);
1133 static struct memory_packet_config memory_read_packet_config
=
1135 "memory-read-packet-size",
1139 set_memory_read_packet_size (char *args
, int from_tty
)
1141 set_memory_packet_size (args
, &memory_read_packet_config
);
1145 show_memory_read_packet_size (char *args
, int from_tty
)
1147 show_memory_packet_size (&memory_read_packet_config
);
1151 get_memory_read_packet_size (void)
1153 long size
= get_memory_packet_size (&memory_read_packet_config
);
1155 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1156 extra buffer size argument before the memory read size can be
1157 increased beyond this. */
1158 if (size
> get_remote_packet_size ())
1159 size
= get_remote_packet_size ();
1164 /* Generic configuration support for packets the stub optionally
1165 supports. Allows the user to specify the use of the packet as well
1166 as allowing GDB to auto-detect support in the remote stub. */
1170 PACKET_SUPPORT_UNKNOWN
= 0,
1175 struct packet_config
1180 /* If auto, GDB auto-detects support for this packet or feature,
1181 either through qSupported, or by trying the packet and looking
1182 at the response. If true, GDB assumes the target supports this
1183 packet. If false, the packet is disabled. Configs that don't
1184 have an associated command always have this set to auto. */
1185 enum auto_boolean detect
;
1187 /* Does the target support this packet? */
1188 enum packet_support support
;
1191 /* Analyze a packet's return value and update the packet config
1201 static enum packet_support
packet_config_support (struct packet_config
*config
);
1202 static enum packet_support
packet_support (int packet
);
1205 show_packet_config_cmd (struct packet_config
*config
)
1207 char *support
= "internal-error";
1209 switch (packet_config_support (config
))
1212 support
= "enabled";
1214 case PACKET_DISABLE
:
1215 support
= "disabled";
1217 case PACKET_SUPPORT_UNKNOWN
:
1218 support
= "unknown";
1221 switch (config
->detect
)
1223 case AUTO_BOOLEAN_AUTO
:
1224 printf_filtered (_("Support for the `%s' packet "
1225 "is auto-detected, currently %s.\n"),
1226 config
->name
, support
);
1228 case AUTO_BOOLEAN_TRUE
:
1229 case AUTO_BOOLEAN_FALSE
:
1230 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1231 config
->name
, support
);
1237 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1238 const char *title
, int legacy
)
1244 config
->name
= name
;
1245 config
->title
= title
;
1246 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1248 show_doc
= xstrprintf ("Show current use of remote "
1249 "protocol `%s' (%s) packet",
1251 /* set/show TITLE-packet {auto,on,off} */
1252 cmd_name
= xstrprintf ("%s-packet", title
);
1253 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1254 &config
->detect
, set_doc
,
1255 show_doc
, NULL
, /* help_doc */
1257 show_remote_protocol_packet_cmd
,
1258 &remote_set_cmdlist
, &remote_show_cmdlist
);
1259 /* The command code copies the documentation strings. */
1262 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1267 legacy_name
= xstrprintf ("%s-packet", name
);
1268 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1269 &remote_set_cmdlist
);
1270 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1271 &remote_show_cmdlist
);
1275 static enum packet_result
1276 packet_check_result (const char *buf
)
1280 /* The stub recognized the packet request. Check that the
1281 operation succeeded. */
1283 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1285 /* "Enn" - definitly an error. */
1286 return PACKET_ERROR
;
1288 /* Always treat "E." as an error. This will be used for
1289 more verbose error messages, such as E.memtypes. */
1290 if (buf
[0] == 'E' && buf
[1] == '.')
1291 return PACKET_ERROR
;
1293 /* The packet may or may not be OK. Just assume it is. */
1297 /* The stub does not support the packet. */
1298 return PACKET_UNKNOWN
;
1301 static enum packet_result
1302 packet_ok (const char *buf
, struct packet_config
*config
)
1304 enum packet_result result
;
1306 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1307 && config
->support
== PACKET_DISABLE
)
1308 internal_error (__FILE__
, __LINE__
,
1309 _("packet_ok: attempt to use a disabled packet"));
1311 result
= packet_check_result (buf
);
1316 /* The stub recognized the packet request. */
1317 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1320 fprintf_unfiltered (gdb_stdlog
,
1321 "Packet %s (%s) is supported\n",
1322 config
->name
, config
->title
);
1323 config
->support
= PACKET_ENABLE
;
1326 case PACKET_UNKNOWN
:
1327 /* The stub does not support the packet. */
1328 if (config
->detect
== AUTO_BOOLEAN_AUTO
1329 && config
->support
== PACKET_ENABLE
)
1331 /* If the stub previously indicated that the packet was
1332 supported then there is a protocol error. */
1333 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1334 config
->name
, config
->title
);
1336 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1338 /* The user set it wrong. */
1339 error (_("Enabled packet %s (%s) not recognized by stub"),
1340 config
->name
, config
->title
);
1344 fprintf_unfiltered (gdb_stdlog
,
1345 "Packet %s (%s) is NOT supported\n",
1346 config
->name
, config
->title
);
1347 config
->support
= PACKET_DISABLE
;
1368 PACKET_vFile_pwrite
,
1370 PACKET_vFile_unlink
,
1371 PACKET_vFile_readlink
,
1374 PACKET_qXfer_features
,
1375 PACKET_qXfer_exec_file
,
1376 PACKET_qXfer_libraries
,
1377 PACKET_qXfer_libraries_svr4
,
1378 PACKET_qXfer_memory_map
,
1379 PACKET_qXfer_spu_read
,
1380 PACKET_qXfer_spu_write
,
1381 PACKET_qXfer_osdata
,
1382 PACKET_qXfer_threads
,
1383 PACKET_qXfer_statictrace_read
,
1384 PACKET_qXfer_traceframe_info
,
1390 PACKET_QPassSignals
,
1391 PACKET_QProgramSignals
,
1393 PACKET_qSearch_memory
,
1396 PACKET_QStartNoAckMode
,
1398 PACKET_qXfer_siginfo_read
,
1399 PACKET_qXfer_siginfo_write
,
1402 /* Support for conditional tracepoints. */
1403 PACKET_ConditionalTracepoints
,
1405 /* Support for target-side breakpoint conditions. */
1406 PACKET_ConditionalBreakpoints
,
1408 /* Support for target-side breakpoint commands. */
1409 PACKET_BreakpointCommands
,
1411 /* Support for fast tracepoints. */
1412 PACKET_FastTracepoints
,
1414 /* Support for static tracepoints. */
1415 PACKET_StaticTracepoints
,
1417 /* Support for installing tracepoints while a trace experiment is
1419 PACKET_InstallInTrace
,
1423 PACKET_TracepointSource
,
1426 PACKET_QDisableRandomization
,
1428 PACKET_QTBuffer_size
,
1432 PACKET_qXfer_btrace
,
1434 /* Support for the QNonStop packet. */
1437 /* Support for multi-process extensions. */
1438 PACKET_multiprocess_feature
,
1440 /* Support for enabling and disabling tracepoints while a trace
1441 experiment is running. */
1442 PACKET_EnableDisableTracepoints_feature
,
1444 /* Support for collecting strings using the tracenz bytecode. */
1445 PACKET_tracenz_feature
,
1447 /* Support for continuing to run a trace experiment while GDB is
1449 PACKET_DisconnectedTracing_feature
,
1451 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1452 PACKET_augmented_libraries_svr4_read_feature
,
1454 /* Support for the qXfer:btrace-conf:read packet. */
1455 PACKET_qXfer_btrace_conf
,
1457 /* Support for the Qbtrace-conf:bts:size packet. */
1458 PACKET_Qbtrace_conf_bts_size
,
1460 /* Support for swbreak+ feature. */
1461 PACKET_swbreak_feature
,
1463 /* Support for hwbreak+ feature. */
1464 PACKET_hwbreak_feature
,
1466 /* Support for fork events. */
1467 PACKET_fork_event_feature
,
1469 /* Support for vfork events. */
1470 PACKET_vfork_event_feature
,
1472 /* Support for the Qbtrace-conf:pt:size packet. */
1473 PACKET_Qbtrace_conf_pt_size
,
1475 /* Support for exec events. */
1476 PACKET_exec_event_feature
,
1478 /* Support for query supported vCont actions. */
1479 PACKET_vContSupported
,
1484 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1486 /* Returns the packet's corresponding "set remote foo-packet" command
1487 state. See struct packet_config for more details. */
1489 static enum auto_boolean
1490 packet_set_cmd_state (int packet
)
1492 return remote_protocol_packets
[packet
].detect
;
1495 /* Returns whether a given packet or feature is supported. This takes
1496 into account the state of the corresponding "set remote foo-packet"
1497 command, which may be used to bypass auto-detection. */
1499 static enum packet_support
1500 packet_config_support (struct packet_config
*config
)
1502 switch (config
->detect
)
1504 case AUTO_BOOLEAN_TRUE
:
1505 return PACKET_ENABLE
;
1506 case AUTO_BOOLEAN_FALSE
:
1507 return PACKET_DISABLE
;
1508 case AUTO_BOOLEAN_AUTO
:
1509 return config
->support
;
1511 gdb_assert_not_reached (_("bad switch"));
1515 /* Same as packet_config_support, but takes the packet's enum value as
1518 static enum packet_support
1519 packet_support (int packet
)
1521 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1523 return packet_config_support (config
);
1527 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1528 struct cmd_list_element
*c
,
1531 struct packet_config
*packet
;
1533 for (packet
= remote_protocol_packets
;
1534 packet
< &remote_protocol_packets
[PACKET_MAX
];
1537 if (&packet
->detect
== c
->var
)
1539 show_packet_config_cmd (packet
);
1543 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1547 /* Should we try one of the 'Z' requests? */
1551 Z_PACKET_SOFTWARE_BP
,
1552 Z_PACKET_HARDWARE_BP
,
1559 /* For compatibility with older distributions. Provide a ``set remote
1560 Z-packet ...'' command that updates all the Z packet types. */
1562 static enum auto_boolean remote_Z_packet_detect
;
1565 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1566 struct cmd_list_element
*c
)
1570 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1571 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1575 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1576 struct cmd_list_element
*c
,
1581 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1583 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1587 /* Returns true if the multi-process extensions are in effect. */
1590 remote_multi_process_p (struct remote_state
*rs
)
1592 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1595 /* Returns true if fork events are supported. */
1598 remote_fork_event_p (struct remote_state
*rs
)
1600 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1603 /* Returns true if vfork events are supported. */
1606 remote_vfork_event_p (struct remote_state
*rs
)
1608 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1611 /* Returns true if exec events are supported. */
1614 remote_exec_event_p (struct remote_state
*rs
)
1616 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1619 /* Insert fork catchpoint target routine. If fork events are enabled
1620 then return success, nothing more to do. */
1623 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1625 struct remote_state
*rs
= get_remote_state ();
1627 return !remote_fork_event_p (rs
);
1630 /* Remove fork catchpoint target routine. Nothing to do, just
1634 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1639 /* Insert vfork catchpoint target routine. If vfork events are enabled
1640 then return success, nothing more to do. */
1643 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1645 struct remote_state
*rs
= get_remote_state ();
1647 return !remote_vfork_event_p (rs
);
1650 /* Remove vfork catchpoint target routine. Nothing to do, just
1654 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1659 /* Insert exec catchpoint target routine. If exec events are
1660 enabled, just return success. */
1663 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1665 struct remote_state
*rs
= get_remote_state ();
1667 return !remote_exec_event_p (rs
);
1670 /* Remove exec catchpoint target routine. Nothing to do, just
1674 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1679 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1680 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1681 static struct async_signal_handler
*async_sigint_remote_token
;
1684 /* Asynchronous signal handle registered as event loop source for
1685 when we have pending events ready to be passed to the core. */
1687 static struct async_event_handler
*remote_async_inferior_event_token
;
1691 static ptid_t magic_null_ptid
;
1692 static ptid_t not_sent_ptid
;
1693 static ptid_t any_thread_ptid
;
1695 /* Find out if the stub attached to PID (and hence GDB should offer to
1696 detach instead of killing it when bailing out). */
1699 remote_query_attached (int pid
)
1701 struct remote_state
*rs
= get_remote_state ();
1702 size_t size
= get_remote_packet_size ();
1704 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1707 if (remote_multi_process_p (rs
))
1708 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1710 xsnprintf (rs
->buf
, size
, "qAttached");
1713 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1715 switch (packet_ok (rs
->buf
,
1716 &remote_protocol_packets
[PACKET_qAttached
]))
1719 if (strcmp (rs
->buf
, "1") == 0)
1723 warning (_("Remote failure reply: %s"), rs
->buf
);
1725 case PACKET_UNKNOWN
:
1732 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1733 has been invented by GDB, instead of reported by the target. Since
1734 we can be connected to a remote system before before knowing about
1735 any inferior, mark the target with execution when we find the first
1736 inferior. If ATTACHED is 1, then we had just attached to this
1737 inferior. If it is 0, then we just created this inferior. If it
1738 is -1, then try querying the remote stub to find out if it had
1739 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1740 attempt to open this inferior's executable as the main executable
1741 if no main executable is open already. */
1743 static struct inferior
*
1744 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1747 struct inferior
*inf
;
1749 /* Check whether this process we're learning about is to be
1750 considered attached, or if is to be considered to have been
1751 spawned by the stub. */
1753 attached
= remote_query_attached (pid
);
1755 if (gdbarch_has_global_solist (target_gdbarch ()))
1757 /* If the target shares code across all inferiors, then every
1758 attach adds a new inferior. */
1759 inf
= add_inferior (pid
);
1761 /* ... and every inferior is bound to the same program space.
1762 However, each inferior may still have its own address
1764 inf
->aspace
= maybe_new_address_space ();
1765 inf
->pspace
= current_program_space
;
1769 /* In the traditional debugging scenario, there's a 1-1 match
1770 between program/address spaces. We simply bind the inferior
1771 to the program space's address space. */
1772 inf
= current_inferior ();
1773 inferior_appeared (inf
, pid
);
1776 inf
->attach_flag
= attached
;
1777 inf
->fake_pid_p
= fake_pid_p
;
1779 /* If no main executable is currently open then attempt to
1780 open the file that was executed to create this inferior. */
1781 if (try_open_exec
&& get_exec_file (0) == NULL
)
1782 exec_file_locate_attach (pid
, 1);
1787 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1788 according to RUNNING. */
1791 remote_add_thread (ptid_t ptid
, int running
)
1793 struct remote_state
*rs
= get_remote_state ();
1795 /* GDB historically didn't pull threads in the initial connection
1796 setup. If the remote target doesn't even have a concept of
1797 threads (e.g., a bare-metal target), even if internally we
1798 consider that a single-threaded target, mentioning a new thread
1799 might be confusing to the user. Be silent then, preserving the
1800 age old behavior. */
1801 if (rs
->starting_up
)
1802 add_thread_silent (ptid
);
1806 set_executing (ptid
, running
);
1807 set_running (ptid
, running
);
1810 /* Come here when we learn about a thread id from the remote target.
1811 It may be the first time we hear about such thread, so take the
1812 opportunity to add it to GDB's thread list. In case this is the
1813 first time we're noticing its corresponding inferior, add it to
1814 GDB's inferior list as well. */
1817 remote_notice_new_inferior (ptid_t currthread
, int running
)
1819 /* If this is a new thread, add it to GDB's thread list.
1820 If we leave it up to WFI to do this, bad things will happen. */
1822 if (in_thread_list (currthread
) && is_exited (currthread
))
1824 /* We're seeing an event on a thread id we knew had exited.
1825 This has to be a new thread reusing the old id. Add it. */
1826 remote_add_thread (currthread
, running
);
1830 if (!in_thread_list (currthread
))
1832 struct inferior
*inf
= NULL
;
1833 int pid
= ptid_get_pid (currthread
);
1835 if (ptid_is_pid (inferior_ptid
)
1836 && pid
== ptid_get_pid (inferior_ptid
))
1838 /* inferior_ptid has no thread member yet. This can happen
1839 with the vAttach -> remote_wait,"TAAthread:" path if the
1840 stub doesn't support qC. This is the first stop reported
1841 after an attach, so this is the main thread. Update the
1842 ptid in the thread list. */
1843 if (in_thread_list (pid_to_ptid (pid
)))
1844 thread_change_ptid (inferior_ptid
, currthread
);
1847 remote_add_thread (currthread
, running
);
1848 inferior_ptid
= currthread
;
1853 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1855 /* inferior_ptid is not set yet. This can happen with the
1856 vRun -> remote_wait,"TAAthread:" path if the stub
1857 doesn't support qC. This is the first stop reported
1858 after an attach, so this is the main thread. Update the
1859 ptid in the thread list. */
1860 thread_change_ptid (inferior_ptid
, currthread
);
1864 /* When connecting to a target remote, or to a target
1865 extended-remote which already was debugging an inferior, we
1866 may not know about it yet. Add it before adding its child
1867 thread, so notifications are emitted in a sensible order. */
1868 if (!in_inferior_list (ptid_get_pid (currthread
)))
1870 struct remote_state
*rs
= get_remote_state ();
1871 int fake_pid_p
= !remote_multi_process_p (rs
);
1873 inf
= remote_add_inferior (fake_pid_p
,
1874 ptid_get_pid (currthread
), -1, 1);
1877 /* This is really a new thread. Add it. */
1878 remote_add_thread (currthread
, running
);
1880 /* If we found a new inferior, let the common code do whatever
1881 it needs to with it (e.g., read shared libraries, insert
1882 breakpoints), unless we're just setting up an all-stop
1886 struct remote_state
*rs
= get_remote_state ();
1888 if (non_stop
|| !rs
->starting_up
)
1889 notice_new_inferior (currthread
, running
, 0);
1894 /* Return the private thread data, creating it if necessary. */
1896 static struct private_thread_info
*
1897 demand_private_info (ptid_t ptid
)
1899 struct thread_info
*info
= find_thread_ptid (ptid
);
1905 info
->priv
= XNEW (struct private_thread_info
);
1906 info
->private_dtor
= free_private_thread_info
;
1907 info
->priv
->core
= -1;
1908 info
->priv
->extra
= 0;
1914 /* Call this function as a result of
1915 1) A halt indication (T packet) containing a thread id
1916 2) A direct query of currthread
1917 3) Successful execution of set thread */
1920 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1922 rs
->general_thread
= currthread
;
1925 /* If 'QPassSignals' is supported, tell the remote stub what signals
1926 it can simply pass through to the inferior without reporting. */
1929 remote_pass_signals (struct target_ops
*self
,
1930 int numsigs
, unsigned char *pass_signals
)
1932 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1934 char *pass_packet
, *p
;
1936 struct remote_state
*rs
= get_remote_state ();
1938 gdb_assert (numsigs
< 256);
1939 for (i
= 0; i
< numsigs
; i
++)
1941 if (pass_signals
[i
])
1944 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1945 strcpy (pass_packet
, "QPassSignals:");
1946 p
= pass_packet
+ strlen (pass_packet
);
1947 for (i
= 0; i
< numsigs
; i
++)
1949 if (pass_signals
[i
])
1952 *p
++ = tohex (i
>> 4);
1953 *p
++ = tohex (i
& 15);
1962 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1964 putpkt (pass_packet
);
1965 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1966 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1967 if (rs
->last_pass_packet
)
1968 xfree (rs
->last_pass_packet
);
1969 rs
->last_pass_packet
= pass_packet
;
1972 xfree (pass_packet
);
1976 /* If 'QProgramSignals' is supported, tell the remote stub what
1977 signals it should pass through to the inferior when detaching. */
1980 remote_program_signals (struct target_ops
*self
,
1981 int numsigs
, unsigned char *signals
)
1983 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1987 struct remote_state
*rs
= get_remote_state ();
1989 gdb_assert (numsigs
< 256);
1990 for (i
= 0; i
< numsigs
; i
++)
1995 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1996 strcpy (packet
, "QProgramSignals:");
1997 p
= packet
+ strlen (packet
);
1998 for (i
= 0; i
< numsigs
; i
++)
2000 if (signal_pass_state (i
))
2003 *p
++ = tohex (i
>> 4);
2004 *p
++ = tohex (i
& 15);
2013 if (!rs
->last_program_signals_packet
2014 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2017 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2018 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2019 xfree (rs
->last_program_signals_packet
);
2020 rs
->last_program_signals_packet
= packet
;
2027 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2028 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2029 thread. If GEN is set, set the general thread, if not, then set
2030 the step/continue thread. */
2032 set_thread (struct ptid ptid
, int gen
)
2034 struct remote_state
*rs
= get_remote_state ();
2035 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2036 char *buf
= rs
->buf
;
2037 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2039 if (ptid_equal (state
, ptid
))
2043 *buf
++ = gen
? 'g' : 'c';
2044 if (ptid_equal (ptid
, magic_null_ptid
))
2045 xsnprintf (buf
, endbuf
- buf
, "0");
2046 else if (ptid_equal (ptid
, any_thread_ptid
))
2047 xsnprintf (buf
, endbuf
- buf
, "0");
2048 else if (ptid_equal (ptid
, minus_one_ptid
))
2049 xsnprintf (buf
, endbuf
- buf
, "-1");
2051 write_ptid (buf
, endbuf
, ptid
);
2053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2055 rs
->general_thread
= ptid
;
2057 rs
->continue_thread
= ptid
;
2061 set_general_thread (struct ptid ptid
)
2063 set_thread (ptid
, 1);
2067 set_continue_thread (struct ptid ptid
)
2069 set_thread (ptid
, 0);
2072 /* Change the remote current process. Which thread within the process
2073 ends up selected isn't important, as long as it is the same process
2074 as what INFERIOR_PTID points to.
2076 This comes from that fact that there is no explicit notion of
2077 "selected process" in the protocol. The selected process for
2078 general operations is the process the selected general thread
2082 set_general_process (void)
2084 struct remote_state
*rs
= get_remote_state ();
2086 /* If the remote can't handle multiple processes, don't bother. */
2087 if (!rs
->extended
|| !remote_multi_process_p (rs
))
2090 /* We only need to change the remote current thread if it's pointing
2091 at some other process. */
2092 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2093 set_general_thread (inferior_ptid
);
2097 /* Return nonzero if this is the main thread that we made up ourselves
2098 to model non-threaded targets as single-threaded. */
2101 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2103 struct remote_state
*rs
= get_remote_state ();
2106 if (ptid_equal (ptid
, magic_null_ptid
))
2107 /* The main thread is always alive. */
2110 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2111 /* The main thread is always alive. This can happen after a
2112 vAttach, if the remote side doesn't support
2119 /* Return nonzero if the thread PTID is still alive on the remote
2123 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2125 struct remote_state
*rs
= get_remote_state ();
2128 /* Check if this is a thread that we made up ourselves to model
2129 non-threaded targets as single-threaded. */
2130 if (remote_thread_always_alive (ops
, ptid
))
2134 endp
= rs
->buf
+ get_remote_packet_size ();
2137 write_ptid (p
, endp
, ptid
);
2140 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2141 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2144 /* About these extended threadlist and threadinfo packets. They are
2145 variable length packets but, the fields within them are often fixed
2146 length. They are redundent enough to send over UDP as is the
2147 remote protocol in general. There is a matching unit test module
2150 /* WARNING: This threadref data structure comes from the remote O.S.,
2151 libstub protocol encoding, and remote.c. It is not particularly
2154 /* Right now, the internal structure is int. We want it to be bigger.
2155 Plan to fix this. */
2157 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2159 /* gdb_ext_thread_info is an internal GDB data structure which is
2160 equivalent to the reply of the remote threadinfo packet. */
2162 struct gdb_ext_thread_info
2164 threadref threadid
; /* External form of thread reference. */
2165 int active
; /* Has state interesting to GDB?
2167 char display
[256]; /* Brief state display, name,
2168 blocked/suspended. */
2169 char shortname
[32]; /* To be used to name threads. */
2170 char more_display
[256]; /* Long info, statistics, queue depth,
2174 /* The volume of remote transfers can be limited by submitting
2175 a mask containing bits specifying the desired information.
2176 Use a union of these values as the 'selection' parameter to
2177 get_thread_info. FIXME: Make these TAG names more thread specific. */
2179 #define TAG_THREADID 1
2180 #define TAG_EXISTS 2
2181 #define TAG_DISPLAY 4
2182 #define TAG_THREADNAME 8
2183 #define TAG_MOREDISPLAY 16
2185 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2187 static char *unpack_nibble (char *buf
, int *val
);
2189 static char *unpack_byte (char *buf
, int *value
);
2191 static char *pack_int (char *buf
, int value
);
2193 static char *unpack_int (char *buf
, int *value
);
2195 static char *unpack_string (char *src
, char *dest
, int length
);
2197 static char *pack_threadid (char *pkt
, threadref
*id
);
2199 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2201 void int_to_threadref (threadref
*id
, int value
);
2203 static int threadref_to_int (threadref
*ref
);
2205 static void copy_threadref (threadref
*dest
, threadref
*src
);
2207 static int threadmatch (threadref
*dest
, threadref
*src
);
2209 static char *pack_threadinfo_request (char *pkt
, int mode
,
2212 static int remote_unpack_thread_info_response (char *pkt
,
2213 threadref
*expectedref
,
2214 struct gdb_ext_thread_info
2218 static int remote_get_threadinfo (threadref
*threadid
,
2219 int fieldset
, /*TAG mask */
2220 struct gdb_ext_thread_info
*info
);
2222 static char *pack_threadlist_request (char *pkt
, int startflag
,
2224 threadref
*nextthread
);
2226 static int parse_threadlist_response (char *pkt
,
2228 threadref
*original_echo
,
2229 threadref
*resultlist
,
2232 static int remote_get_threadlist (int startflag
,
2233 threadref
*nextthread
,
2237 threadref
*threadlist
);
2239 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2241 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2242 void *context
, int looplimit
);
2244 static int remote_newthread_step (threadref
*ref
, void *context
);
2247 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2248 buffer we're allowed to write to. Returns
2249 BUF+CHARACTERS_WRITTEN. */
2252 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2255 struct remote_state
*rs
= get_remote_state ();
2257 if (remote_multi_process_p (rs
))
2259 pid
= ptid_get_pid (ptid
);
2261 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2263 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2265 tid
= ptid_get_lwp (ptid
);
2267 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2269 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2274 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2275 passed the last parsed char. Returns null_ptid on error. */
2278 read_ptid (char *buf
, char **obuf
)
2282 ULONGEST pid
= 0, tid
= 0;
2286 /* Multi-process ptid. */
2287 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2289 error (_("invalid remote ptid: %s"), p
);
2292 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2295 return ptid_build (pid
, tid
, 0);
2298 /* No multi-process. Just a tid. */
2299 pp
= unpack_varlen_hex (p
, &tid
);
2301 /* Return null_ptid when no thread id is found. */
2309 /* Since the stub is not sending a process id, then default to
2310 what's in inferior_ptid, unless it's null at this point. If so,
2311 then since there's no way to know the pid of the reported
2312 threads, use the magic number. */
2313 if (ptid_equal (inferior_ptid
, null_ptid
))
2314 pid
= ptid_get_pid (magic_null_ptid
);
2316 pid
= ptid_get_pid (inferior_ptid
);
2320 return ptid_build (pid
, tid
, 0);
2326 if (ch
>= 'a' && ch
<= 'f')
2327 return ch
- 'a' + 10;
2328 if (ch
>= '0' && ch
<= '9')
2330 if (ch
>= 'A' && ch
<= 'F')
2331 return ch
- 'A' + 10;
2336 stub_unpack_int (char *buff
, int fieldlength
)
2343 nibble
= stubhex (*buff
++);
2347 retval
= retval
<< 4;
2353 unpack_nibble (char *buf
, int *val
)
2355 *val
= fromhex (*buf
++);
2360 unpack_byte (char *buf
, int *value
)
2362 *value
= stub_unpack_int (buf
, 2);
2367 pack_int (char *buf
, int value
)
2369 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2370 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2371 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2372 buf
= pack_hex_byte (buf
, (value
& 0xff));
2377 unpack_int (char *buf
, int *value
)
2379 *value
= stub_unpack_int (buf
, 8);
2383 #if 0 /* Currently unused, uncomment when needed. */
2384 static char *pack_string (char *pkt
, char *string
);
2387 pack_string (char *pkt
, char *string
)
2392 len
= strlen (string
);
2394 len
= 200; /* Bigger than most GDB packets, junk??? */
2395 pkt
= pack_hex_byte (pkt
, len
);
2399 if ((ch
== '\0') || (ch
== '#'))
2400 ch
= '*'; /* Protect encapsulation. */
2405 #endif /* 0 (unused) */
2408 unpack_string (char *src
, char *dest
, int length
)
2417 pack_threadid (char *pkt
, threadref
*id
)
2420 unsigned char *altid
;
2422 altid
= (unsigned char *) id
;
2423 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2425 pkt
= pack_hex_byte (pkt
, *altid
++);
2431 unpack_threadid (char *inbuf
, threadref
*id
)
2434 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2437 altref
= (char *) id
;
2439 while (inbuf
< limit
)
2441 x
= stubhex (*inbuf
++);
2442 y
= stubhex (*inbuf
++);
2443 *altref
++ = (x
<< 4) | y
;
2448 /* Externally, threadrefs are 64 bits but internally, they are still
2449 ints. This is due to a mismatch of specifications. We would like
2450 to use 64bit thread references internally. This is an adapter
2454 int_to_threadref (threadref
*id
, int value
)
2456 unsigned char *scan
;
2458 scan
= (unsigned char *) id
;
2464 *scan
++ = (value
>> 24) & 0xff;
2465 *scan
++ = (value
>> 16) & 0xff;
2466 *scan
++ = (value
>> 8) & 0xff;
2467 *scan
++ = (value
& 0xff);
2471 threadref_to_int (threadref
*ref
)
2474 unsigned char *scan
;
2480 value
= (value
<< 8) | ((*scan
++) & 0xff);
2485 copy_threadref (threadref
*dest
, threadref
*src
)
2488 unsigned char *csrc
, *cdest
;
2490 csrc
= (unsigned char *) src
;
2491 cdest
= (unsigned char *) dest
;
2498 threadmatch (threadref
*dest
, threadref
*src
)
2500 /* Things are broken right now, so just assume we got a match. */
2502 unsigned char *srcp
, *destp
;
2504 srcp
= (char *) src
;
2505 destp
= (char *) dest
;
2509 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2516 threadid:1, # always request threadid
2523 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2526 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2528 *pkt
++ = 'q'; /* Info Query */
2529 *pkt
++ = 'P'; /* process or thread info */
2530 pkt
= pack_int (pkt
, mode
); /* mode */
2531 pkt
= pack_threadid (pkt
, id
); /* threadid */
2532 *pkt
= '\0'; /* terminate */
2536 /* These values tag the fields in a thread info response packet. */
2537 /* Tagging the fields allows us to request specific fields and to
2538 add more fields as time goes by. */
2540 #define TAG_THREADID 1 /* Echo the thread identifier. */
2541 #define TAG_EXISTS 2 /* Is this process defined enough to
2542 fetch registers and its stack? */
2543 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2544 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2545 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2549 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2550 struct gdb_ext_thread_info
*info
)
2552 struct remote_state
*rs
= get_remote_state ();
2556 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2559 /* info->threadid = 0; FIXME: implement zero_threadref. */
2561 info
->display
[0] = '\0';
2562 info
->shortname
[0] = '\0';
2563 info
->more_display
[0] = '\0';
2565 /* Assume the characters indicating the packet type have been
2567 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2568 pkt
= unpack_threadid (pkt
, &ref
);
2571 warning (_("Incomplete response to threadinfo request."));
2572 if (!threadmatch (&ref
, expectedref
))
2573 { /* This is an answer to a different request. */
2574 warning (_("ERROR RMT Thread info mismatch."));
2577 copy_threadref (&info
->threadid
, &ref
);
2579 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2581 /* Packets are terminated with nulls. */
2582 while ((pkt
< limit
) && mask
&& *pkt
)
2584 pkt
= unpack_int (pkt
, &tag
); /* tag */
2585 pkt
= unpack_byte (pkt
, &length
); /* length */
2586 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2588 warning (_("ERROR RMT: threadinfo tag mismatch."));
2592 if (tag
== TAG_THREADID
)
2596 warning (_("ERROR RMT: length of threadid is not 16."));
2600 pkt
= unpack_threadid (pkt
, &ref
);
2601 mask
= mask
& ~TAG_THREADID
;
2604 if (tag
== TAG_EXISTS
)
2606 info
->active
= stub_unpack_int (pkt
, length
);
2608 mask
= mask
& ~(TAG_EXISTS
);
2611 warning (_("ERROR RMT: 'exists' length too long."));
2617 if (tag
== TAG_THREADNAME
)
2619 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2620 mask
= mask
& ~TAG_THREADNAME
;
2623 if (tag
== TAG_DISPLAY
)
2625 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2626 mask
= mask
& ~TAG_DISPLAY
;
2629 if (tag
== TAG_MOREDISPLAY
)
2631 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2632 mask
= mask
& ~TAG_MOREDISPLAY
;
2635 warning (_("ERROR RMT: unknown thread info tag."));
2636 break; /* Not a tag we know about. */
2642 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2643 struct gdb_ext_thread_info
*info
)
2645 struct remote_state
*rs
= get_remote_state ();
2648 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2650 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2652 if (rs
->buf
[0] == '\0')
2655 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2660 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2663 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2664 threadref
*nextthread
)
2666 *pkt
++ = 'q'; /* info query packet */
2667 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2668 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2669 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2670 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2675 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2678 parse_threadlist_response (char *pkt
, int result_limit
,
2679 threadref
*original_echo
, threadref
*resultlist
,
2682 struct remote_state
*rs
= get_remote_state ();
2684 int count
, resultcount
, done
;
2687 /* Assume the 'q' and 'M chars have been stripped. */
2688 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2689 /* done parse past here */
2690 pkt
= unpack_byte (pkt
, &count
); /* count field */
2691 pkt
= unpack_nibble (pkt
, &done
);
2692 /* The first threadid is the argument threadid. */
2693 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2694 while ((count
-- > 0) && (pkt
< limit
))
2696 pkt
= unpack_threadid (pkt
, resultlist
++);
2697 if (resultcount
++ >= result_limit
)
2705 /* Fetch the next batch of threads from the remote. Returns -1 if the
2706 qL packet is not supported, 0 on error and 1 on success. */
2709 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2710 int *done
, int *result_count
, threadref
*threadlist
)
2712 struct remote_state
*rs
= get_remote_state ();
2715 /* Trancate result limit to be smaller than the packet size. */
2716 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2717 >= get_remote_packet_size ())
2718 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2720 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2722 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2723 if (*rs
->buf
== '\0')
2725 /* Packet not supported. */
2730 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2731 &rs
->echo_nextthread
, threadlist
, done
);
2733 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2735 /* FIXME: This is a good reason to drop the packet. */
2736 /* Possably, there is a duplicate response. */
2738 retransmit immediatly - race conditions
2739 retransmit after timeout - yes
2741 wait for packet, then exit
2743 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2744 return 0; /* I choose simply exiting. */
2746 if (*result_count
<= 0)
2750 warning (_("RMT ERROR : failed to get remote thread list."));
2753 return result
; /* break; */
2755 if (*result_count
> result_limit
)
2758 warning (_("RMT ERROR: threadlist response longer than requested."));
2764 /* Fetch the list of remote threads, with the qL packet, and call
2765 STEPFUNCTION for each thread found. Stops iterating and returns 1
2766 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2767 STEPFUNCTION returns false. If the packet is not supported,
2771 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2774 struct remote_state
*rs
= get_remote_state ();
2775 int done
, i
, result_count
;
2783 if (loopcount
++ > looplimit
)
2786 warning (_("Remote fetch threadlist -infinite loop-."));
2789 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2790 MAXTHREADLISTRESULTS
,
2791 &done
, &result_count
,
2792 rs
->resultthreadlist
);
2795 /* Clear for later iterations. */
2797 /* Setup to resume next batch of thread references, set nextthread. */
2798 if (result_count
>= 1)
2799 copy_threadref (&rs
->nextthread
,
2800 &rs
->resultthreadlist
[result_count
- 1]);
2802 while (result_count
--)
2804 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2814 /* A thread found on the remote target. */
2816 typedef struct thread_item
2818 /* The thread's PTID. */
2821 /* The thread's extra info. May be NULL. */
2824 /* The core the thread was running on. -1 if not known. */
2827 DEF_VEC_O(thread_item_t
);
2829 /* Context passed around to the various methods listing remote
2830 threads. As new threads are found, they're added to the ITEMS
2833 struct threads_listing_context
2835 /* The threads found on the remote target. */
2836 VEC (thread_item_t
) *items
;
2839 /* Discard the contents of the constructed thread listing context. */
2842 clear_threads_listing_context (void *p
)
2844 struct threads_listing_context
*context
2845 = (struct threads_listing_context
*) p
;
2847 struct thread_item
*item
;
2849 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2850 xfree (item
->extra
);
2852 VEC_free (thread_item_t
, context
->items
);
2855 /* Remove the thread specified as the related_pid field of WS
2856 from the CONTEXT list. */
2859 threads_listing_context_remove (struct target_waitstatus
*ws
,
2860 struct threads_listing_context
*context
)
2862 struct thread_item
*item
;
2864 ptid_t child_ptid
= ws
->value
.related_pid
;
2866 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2868 if (ptid_equal (item
->ptid
, child_ptid
))
2870 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2877 remote_newthread_step (threadref
*ref
, void *data
)
2879 struct threads_listing_context
*context
2880 = (struct threads_listing_context
*) data
;
2881 struct thread_item item
;
2882 int pid
= ptid_get_pid (inferior_ptid
);
2884 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2888 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2890 return 1; /* continue iterator */
2893 #define CRAZY_MAX_THREADS 1000
2896 remote_current_thread (ptid_t oldpid
)
2898 struct remote_state
*rs
= get_remote_state ();
2901 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2902 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2907 result
= read_ptid (&rs
->buf
[2], &obuf
);
2908 if (*obuf
!= '\0' && remote_debug
)
2909 fprintf_unfiltered (gdb_stdlog
,
2910 "warning: garbage in qC reply\n");
2918 /* List remote threads using the deprecated qL packet. */
2921 remote_get_threads_with_ql (struct target_ops
*ops
,
2922 struct threads_listing_context
*context
)
2924 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2925 CRAZY_MAX_THREADS
) >= 0)
2931 #if defined(HAVE_LIBEXPAT)
2934 start_thread (struct gdb_xml_parser
*parser
,
2935 const struct gdb_xml_element
*element
,
2936 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2938 struct threads_listing_context
*data
2939 = (struct threads_listing_context
*) user_data
;
2941 struct thread_item item
;
2943 struct gdb_xml_value
*attr
;
2945 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
2946 item
.ptid
= read_ptid (id
, NULL
);
2948 attr
= xml_find_attribute (attributes
, "core");
2950 item
.core
= *(ULONGEST
*) attr
->value
;
2956 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2960 end_thread (struct gdb_xml_parser
*parser
,
2961 const struct gdb_xml_element
*element
,
2962 void *user_data
, const char *body_text
)
2964 struct threads_listing_context
*data
2965 = (struct threads_listing_context
*) user_data
;
2967 if (body_text
&& *body_text
)
2968 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2971 const struct gdb_xml_attribute thread_attributes
[] = {
2972 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2973 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2974 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2977 const struct gdb_xml_element thread_children
[] = {
2978 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2981 const struct gdb_xml_element threads_children
[] = {
2982 { "thread", thread_attributes
, thread_children
,
2983 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2984 start_thread
, end_thread
},
2985 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2988 const struct gdb_xml_element threads_elements
[] = {
2989 { "threads", NULL
, threads_children
,
2990 GDB_XML_EF_NONE
, NULL
, NULL
},
2991 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2996 /* List remote threads using qXfer:threads:read. */
2999 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3000 struct threads_listing_context
*context
)
3002 #if defined(HAVE_LIBEXPAT)
3003 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3005 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3006 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3008 if (xml
!= NULL
&& *xml
!= '\0')
3010 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3011 threads_elements
, xml
, context
);
3014 do_cleanups (back_to
);
3022 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3025 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3026 struct threads_listing_context
*context
)
3028 struct remote_state
*rs
= get_remote_state ();
3030 if (rs
->use_threadinfo_query
)
3034 putpkt ("qfThreadInfo");
3035 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3037 if (bufp
[0] != '\0') /* q packet recognized */
3039 while (*bufp
++ == 'm') /* reply contains one or more TID */
3043 struct thread_item item
;
3045 item
.ptid
= read_ptid (bufp
, &bufp
);
3049 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3051 while (*bufp
++ == ','); /* comma-separated list */
3052 putpkt ("qsThreadInfo");
3053 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3060 /* Packet not recognized. */
3061 rs
->use_threadinfo_query
= 0;
3068 /* Implement the to_update_thread_list function for the remote
3072 remote_update_thread_list (struct target_ops
*ops
)
3074 struct remote_state
*rs
= get_remote_state ();
3075 struct threads_listing_context context
;
3076 struct cleanup
*old_chain
;
3079 context
.items
= NULL
;
3080 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3082 /* We have a few different mechanisms to fetch the thread list. Try
3083 them all, starting with the most preferred one first, falling
3084 back to older methods. */
3085 if (remote_get_threads_with_qxfer (ops
, &context
)
3086 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3087 || remote_get_threads_with_ql (ops
, &context
))
3090 struct thread_item
*item
;
3091 struct thread_info
*tp
, *tmp
;
3095 if (VEC_empty (thread_item_t
, context
.items
)
3096 && remote_thread_always_alive (ops
, inferior_ptid
))
3098 /* Some targets don't really support threads, but still
3099 reply an (empty) thread list in response to the thread
3100 listing packets, instead of replying "packet not
3101 supported". Exit early so we don't delete the main
3103 do_cleanups (old_chain
);
3107 /* CONTEXT now holds the current thread list on the remote
3108 target end. Delete GDB-side threads no longer found on the
3110 ALL_THREADS_SAFE (tp
, tmp
)
3113 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3116 if (ptid_equal (item
->ptid
, tp
->ptid
))
3120 if (i
== VEC_length (thread_item_t
, context
.items
))
3123 delete_thread (tp
->ptid
);
3127 /* Remove any unreported fork child threads from CONTEXT so
3128 that we don't interfere with follow fork, which is where
3129 creation of such threads is handled. */
3130 remove_new_fork_children (&context
);
3132 /* And now add threads we don't know about yet to our list. */
3134 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3137 if (!ptid_equal (item
->ptid
, null_ptid
))
3139 struct private_thread_info
*info
;
3140 /* In non-stop mode, we assume new found threads are
3141 running until proven otherwise with a stop reply. In
3142 all-stop, we can only get here if all threads are
3144 int running
= non_stop
? 1 : 0;
3146 remote_notice_new_inferior (item
->ptid
, running
);
3148 info
= demand_private_info (item
->ptid
);
3149 info
->core
= item
->core
;
3150 info
->extra
= item
->extra
;
3158 /* If no thread listing method is supported, then query whether
3159 each known thread is alive, one by one, with the T packet.
3160 If the target doesn't support threads at all, then this is a
3161 no-op. See remote_thread_alive. */
3165 do_cleanups (old_chain
);
3169 * Collect a descriptive string about the given thread.
3170 * The target may say anything it wants to about the thread
3171 * (typically info about its blocked / runnable state, name, etc.).
3172 * This string will appear in the info threads display.
3174 * Optional: targets are not required to implement this function.
3178 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3180 struct remote_state
*rs
= get_remote_state ();
3184 struct gdb_ext_thread_info threadinfo
;
3185 static char display_buf
[100]; /* arbitrary... */
3186 int n
= 0; /* position in display_buf */
3188 if (rs
->remote_desc
== 0) /* paranoia */
3189 internal_error (__FILE__
, __LINE__
,
3190 _("remote_threads_extra_info"));
3192 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3193 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3194 /* This is the main thread which was added by GDB. The remote
3195 server doesn't know about it. */
3198 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3200 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3202 if (info
&& info
->priv
)
3203 return info
->priv
->extra
;
3208 if (rs
->use_threadextra_query
)
3211 char *endb
= rs
->buf
+ get_remote_packet_size ();
3213 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3215 write_ptid (b
, endb
, tp
->ptid
);
3218 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3219 if (rs
->buf
[0] != 0)
3221 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3222 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3223 display_buf
[result
] = '\0';
3228 /* If the above query fails, fall back to the old method. */
3229 rs
->use_threadextra_query
= 0;
3230 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3231 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3232 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3233 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3234 if (threadinfo
.active
)
3236 if (*threadinfo
.shortname
)
3237 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3238 " Name: %s,", threadinfo
.shortname
);
3239 if (*threadinfo
.display
)
3240 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3241 " State: %s,", threadinfo
.display
);
3242 if (*threadinfo
.more_display
)
3243 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3244 " Priority: %s", threadinfo
.more_display
);
3248 /* For purely cosmetic reasons, clear up trailing commas. */
3249 if (',' == display_buf
[n
-1])
3250 display_buf
[n
-1] = ' ';
3259 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3260 struct static_tracepoint_marker
*marker
)
3262 struct remote_state
*rs
= get_remote_state ();
3265 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3267 p
+= hexnumstr (p
, addr
);
3269 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3273 error (_("Remote failure reply: %s"), p
);
3277 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3284 static VEC(static_tracepoint_marker_p
) *
3285 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3288 struct remote_state
*rs
= get_remote_state ();
3289 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3290 struct static_tracepoint_marker
*marker
= NULL
;
3291 struct cleanup
*old_chain
;
3294 /* Ask for a first packet of static tracepoint marker
3297 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3300 error (_("Remote failure reply: %s"), p
);
3302 old_chain
= make_cleanup (free_current_marker
, &marker
);
3307 marker
= XCNEW (struct static_tracepoint_marker
);
3311 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3313 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3315 VEC_safe_push (static_tracepoint_marker_p
,
3321 release_static_tracepoint_marker (marker
);
3322 memset (marker
, 0, sizeof (*marker
));
3325 while (*p
++ == ','); /* comma-separated list */
3326 /* Ask for another packet of static tracepoint definition. */
3328 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3332 do_cleanups (old_chain
);
3337 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3340 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3342 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3346 /* Restart the remote side; this is an extended protocol operation. */
3349 extended_remote_restart (void)
3351 struct remote_state
*rs
= get_remote_state ();
3353 /* Send the restart command; for reasons I don't understand the
3354 remote side really expects a number after the "R". */
3355 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3358 remote_fileio_reset ();
3361 /* Clean up connection to a remote debugger. */
3364 remote_close (struct target_ops
*self
)
3366 struct remote_state
*rs
= get_remote_state ();
3368 if (rs
->remote_desc
== NULL
)
3369 return; /* already closed */
3371 /* Make sure we leave stdin registered in the event loop, and we
3372 don't leave the async SIGINT signal handler installed. */
3373 remote_terminal_ours (self
);
3375 serial_close (rs
->remote_desc
);
3376 rs
->remote_desc
= NULL
;
3378 /* We don't have a connection to the remote stub anymore. Get rid
3379 of all the inferiors and their threads we were controlling.
3380 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3381 will be unable to find the thread corresponding to (pid, 0, 0). */
3382 inferior_ptid
= null_ptid
;
3383 discard_all_inferiors ();
3385 /* We are closing the remote target, so we should discard
3386 everything of this target. */
3387 discard_pending_stop_replies_in_queue (rs
);
3389 if (remote_async_inferior_event_token
)
3390 delete_async_event_handler (&remote_async_inferior_event_token
);
3392 remote_notif_state_xfree (rs
->notif_state
);
3394 trace_reset_local_state ();
3397 /* Query the remote side for the text, data and bss offsets. */
3402 struct remote_state
*rs
= get_remote_state ();
3405 int lose
, num_segments
= 0, do_sections
, do_segments
;
3406 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3407 struct section_offsets
*offs
;
3408 struct symfile_segment_data
*data
;
3410 if (symfile_objfile
== NULL
)
3413 putpkt ("qOffsets");
3414 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3417 if (buf
[0] == '\000')
3418 return; /* Return silently. Stub doesn't support
3422 warning (_("Remote failure reply: %s"), buf
);
3426 /* Pick up each field in turn. This used to be done with scanf, but
3427 scanf will make trouble if CORE_ADDR size doesn't match
3428 conversion directives correctly. The following code will work
3429 with any size of CORE_ADDR. */
3430 text_addr
= data_addr
= bss_addr
= 0;
3434 if (startswith (ptr
, "Text="))
3437 /* Don't use strtol, could lose on big values. */
3438 while (*ptr
&& *ptr
!= ';')
3439 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3441 if (startswith (ptr
, ";Data="))
3444 while (*ptr
&& *ptr
!= ';')
3445 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3450 if (!lose
&& startswith (ptr
, ";Bss="))
3453 while (*ptr
&& *ptr
!= ';')
3454 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3456 if (bss_addr
!= data_addr
)
3457 warning (_("Target reported unsupported offsets: %s"), buf
);
3462 else if (startswith (ptr
, "TextSeg="))
3465 /* Don't use strtol, could lose on big values. */
3466 while (*ptr
&& *ptr
!= ';')
3467 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3470 if (startswith (ptr
, ";DataSeg="))
3473 while (*ptr
&& *ptr
!= ';')
3474 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3482 error (_("Malformed response to offset query, %s"), buf
);
3483 else if (*ptr
!= '\0')
3484 warning (_("Target reported unsupported offsets: %s"), buf
);
3486 offs
= ((struct section_offsets
*)
3487 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3488 memcpy (offs
, symfile_objfile
->section_offsets
,
3489 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3491 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3492 do_segments
= (data
!= NULL
);
3493 do_sections
= num_segments
== 0;
3495 if (num_segments
> 0)
3497 segments
[0] = text_addr
;
3498 segments
[1] = data_addr
;
3500 /* If we have two segments, we can still try to relocate everything
3501 by assuming that the .text and .data offsets apply to the whole
3502 text and data segments. Convert the offsets given in the packet
3503 to base addresses for symfile_map_offsets_to_segments. */
3504 else if (data
&& data
->num_segments
== 2)
3506 segments
[0] = data
->segment_bases
[0] + text_addr
;
3507 segments
[1] = data
->segment_bases
[1] + data_addr
;
3510 /* If the object file has only one segment, assume that it is text
3511 rather than data; main programs with no writable data are rare,
3512 but programs with no code are useless. Of course the code might
3513 have ended up in the data segment... to detect that we would need
3514 the permissions here. */
3515 else if (data
&& data
->num_segments
== 1)
3517 segments
[0] = data
->segment_bases
[0] + text_addr
;
3520 /* There's no way to relocate by segment. */
3526 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3527 offs
, num_segments
, segments
);
3529 if (ret
== 0 && !do_sections
)
3530 error (_("Can not handle qOffsets TextSeg "
3531 "response with this symbol file"));
3538 free_symfile_segment_data (data
);
3542 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3544 /* This is a temporary kludge to force data and bss to use the
3545 same offsets because that's what nlmconv does now. The real
3546 solution requires changes to the stub and remote.c that I
3547 don't have time to do right now. */
3549 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3550 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3553 objfile_relocate (symfile_objfile
, offs
);
3556 /* Send interrupt_sequence to remote target. */
3558 send_interrupt_sequence (void)
3560 struct remote_state
*rs
= get_remote_state ();
3562 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3563 remote_serial_write ("\x03", 1);
3564 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3565 serial_send_break (rs
->remote_desc
);
3566 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3568 serial_send_break (rs
->remote_desc
);
3569 remote_serial_write ("g", 1);
3572 internal_error (__FILE__
, __LINE__
,
3573 _("Invalid value for interrupt_sequence_mode: %s."),
3574 interrupt_sequence_mode
);
3578 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3579 and extract the PTID. Returns NULL_PTID if not found. */
3582 stop_reply_extract_thread (char *stop_reply
)
3584 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3588 /* Txx r:val ; r:val (...) */
3591 /* Look for "register" named "thread". */
3596 p1
= strchr (p
, ':');
3600 if (strncmp (p
, "thread", p1
- p
) == 0)
3601 return read_ptid (++p1
, &p
);
3603 p1
= strchr (p
, ';');
3615 /* Determine the remote side's current thread. If we have a stop
3616 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3617 "thread" register we can extract the current thread from. If not,
3618 ask the remote which is the current thread with qC. The former
3619 method avoids a roundtrip. */
3622 get_current_thread (char *wait_status
)
3624 ptid_t ptid
= null_ptid
;
3626 /* Note we don't use remote_parse_stop_reply as that makes use of
3627 the target architecture, which we haven't yet fully determined at
3629 if (wait_status
!= NULL
)
3630 ptid
= stop_reply_extract_thread (wait_status
);
3631 if (ptid_equal (ptid
, null_ptid
))
3632 ptid
= remote_current_thread (inferior_ptid
);
3637 /* Query the remote target for which is the current thread/process,
3638 add it to our tables, and update INFERIOR_PTID. The caller is
3639 responsible for setting the state such that the remote end is ready
3640 to return the current thread.
3642 This function is called after handling the '?' or 'vRun' packets,
3643 whose response is a stop reply from which we can also try
3644 extracting the thread. If the target doesn't support the explicit
3645 qC query, we infer the current thread from that stop reply, passed
3646 in in WAIT_STATUS, which may be NULL. */
3649 add_current_inferior_and_thread (char *wait_status
)
3651 struct remote_state
*rs
= get_remote_state ();
3655 inferior_ptid
= null_ptid
;
3657 /* Now, if we have thread information, update inferior_ptid. */
3658 ptid
= get_current_thread (wait_status
);
3660 if (!ptid_equal (ptid
, null_ptid
))
3662 if (!remote_multi_process_p (rs
))
3665 inferior_ptid
= ptid
;
3669 /* Without this, some commands which require an active target
3670 (such as kill) won't work. This variable serves (at least)
3671 double duty as both the pid of the target process (if it has
3672 such), and as a flag indicating that a target is active. */
3673 inferior_ptid
= magic_null_ptid
;
3677 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3679 /* Add the main thread. */
3680 add_thread_silent (inferior_ptid
);
3683 /* Process all initial stop replies the remote side sent in response
3684 to the ? packet. These indicate threads that were already stopped
3685 on initial connection. We mark these threads as stopped and print
3686 their current frame before giving the user the prompt. */
3689 process_initial_stop_replies (void)
3691 int pending_stop_replies
= stop_reply_queue_length ();
3693 /* Consume the initial pending events. */
3694 while (pending_stop_replies
-- > 0)
3696 ptid_t waiton_ptid
= minus_one_ptid
;
3698 struct target_waitstatus ws
;
3699 int ignore_event
= 0;
3701 memset (&ws
, 0, sizeof (ws
));
3702 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3704 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3708 case TARGET_WAITKIND_IGNORE
:
3709 case TARGET_WAITKIND_NO_RESUMED
:
3710 case TARGET_WAITKIND_SIGNALLED
:
3711 case TARGET_WAITKIND_EXITED
:
3712 /* We shouldn't see these, but if we do, just ignore. */
3714 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3718 case TARGET_WAITKIND_EXECD
:
3719 xfree (ws
.value
.execd_pathname
);
3728 switch_to_thread (event_ptid
);
3729 set_executing (event_ptid
, 0);
3730 set_running (event_ptid
, 0);
3732 stop_pc
= get_frame_pc (get_current_frame ());
3733 set_current_sal_from_frame (get_current_frame ());
3735 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3737 enum gdb_signal sig
= ws
.value
.sig
;
3739 /* Stubs traditionally report SIGTRAP as initial signal,
3740 instead of signal 0. Suppress it. */
3741 if (sig
== GDB_SIGNAL_TRAP
)
3743 inferior_thread ()->suspend
.stop_signal
= sig
;
3745 if (signal_print_state (sig
))
3746 observer_notify_signal_received (sig
);
3749 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
3750 observer_notify_normal_stop (NULL
, 1);
3755 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3757 struct remote_state
*rs
= get_remote_state ();
3758 struct packet_config
*noack_config
;
3759 char *wait_status
= NULL
;
3761 immediate_quit
++; /* Allow user to interrupt it. */
3764 if (interrupt_on_connect
)
3765 send_interrupt_sequence ();
3767 /* Ack any packet which the remote side has already sent. */
3768 serial_write (rs
->remote_desc
, "+", 1);
3770 /* Signal other parts that we're going through the initial setup,
3771 and so things may not be stable yet. */
3772 rs
->starting_up
= 1;
3774 /* The first packet we send to the target is the optional "supported
3775 packets" request. If the target can answer this, it will tell us
3776 which later probes to skip. */
3777 remote_query_supported ();
3779 /* If the stub wants to get a QAllow, compose one and send it. */
3780 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3781 remote_set_permissions (target
);
3783 /* Next, we possibly activate noack mode.
3785 If the QStartNoAckMode packet configuration is set to AUTO,
3786 enable noack mode if the stub reported a wish for it with
3789 If set to TRUE, then enable noack mode even if the stub didn't
3790 report it in qSupported. If the stub doesn't reply OK, the
3791 session ends with an error.
3793 If FALSE, then don't activate noack mode, regardless of what the
3794 stub claimed should be the default with qSupported. */
3796 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3797 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3799 putpkt ("QStartNoAckMode");
3800 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3801 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3807 /* Tell the remote that we are using the extended protocol. */
3809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3812 /* Let the target know which signals it is allowed to pass down to
3814 update_signals_program_target ();
3816 /* Next, if the target can specify a description, read it. We do
3817 this before anything involving memory or registers. */
3818 target_find_description ();
3820 /* Next, now that we know something about the target, update the
3821 address spaces in the program spaces. */
3822 update_address_spaces ();
3824 /* On OSs where the list of libraries is global to all
3825 processes, we fetch them early. */
3826 if (gdbarch_has_global_solist (target_gdbarch ()))
3827 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3831 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3832 error (_("Non-stop mode requested, but remote "
3833 "does not support non-stop"));
3835 putpkt ("QNonStop:1");
3836 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3838 if (strcmp (rs
->buf
, "OK") != 0)
3839 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3841 /* Find about threads and processes the stub is already
3842 controlling. We default to adding them in the running state.
3843 The '?' query below will then tell us about which threads are
3845 remote_update_thread_list (target
);
3847 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3849 /* Don't assume that the stub can operate in all-stop mode.
3850 Request it explicitly. */
3851 putpkt ("QNonStop:0");
3852 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3854 if (strcmp (rs
->buf
, "OK") != 0)
3855 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3858 /* Upload TSVs regardless of whether the target is running or not. The
3859 remote stub, such as GDBserver, may have some predefined or builtin
3860 TSVs, even if the target is not running. */
3861 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3863 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3865 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3866 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3869 /* Check whether the target is running now. */
3871 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3877 struct inferior
*inf
;
3879 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3882 error (_("The target is not running (try extended-remote?)"));
3884 /* We're connected, but not running. Drop out before we
3885 call start_remote. */
3886 rs
->starting_up
= 0;
3891 /* Save the reply for later. */
3892 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
3893 strcpy (wait_status
, rs
->buf
);
3896 /* Fetch thread list. */
3897 target_update_thread_list ();
3899 /* Let the stub know that we want it to return the thread. */
3900 set_continue_thread (minus_one_ptid
);
3902 if (thread_count () == 0)
3904 /* Target has no concept of threads at all. GDB treats
3905 non-threaded target as single-threaded; add a main
3907 add_current_inferior_and_thread (wait_status
);
3911 /* We have thread information; select the thread the target
3912 says should be current. If we're reconnecting to a
3913 multi-threaded program, this will ideally be the thread
3914 that last reported an event before GDB disconnected. */
3915 inferior_ptid
= get_current_thread (wait_status
);
3916 if (ptid_equal (inferior_ptid
, null_ptid
))
3918 /* Odd... The target was able to list threads, but not
3919 tell us which thread was current (no "thread"
3920 register in T stop reply?). Just pick the first
3921 thread in the thread list then. */
3924 fprintf_unfiltered (gdb_stdlog
,
3925 "warning: couldn't determine remote "
3926 "current thread; picking first in list.\n");
3928 inferior_ptid
= thread_list
->ptid
;
3932 /* init_wait_for_inferior should be called before get_offsets in order
3933 to manage `inserted' flag in bp loc in a correct state.
3934 breakpoint_init_inferior, called from init_wait_for_inferior, set
3935 `inserted' flag to 0, while before breakpoint_re_set, called from
3936 start_remote, set `inserted' flag to 1. In the initialization of
3937 inferior, breakpoint_init_inferior should be called first, and then
3938 breakpoint_re_set can be called. If this order is broken, state of
3939 `inserted' flag is wrong, and cause some problems on breakpoint
3941 init_wait_for_inferior ();
3943 get_offsets (); /* Get text, data & bss offsets. */
3945 /* If we could not find a description using qXfer, and we know
3946 how to do it some other way, try again. This is not
3947 supported for non-stop; it could be, but it is tricky if
3948 there are no stopped threads when we connect. */
3949 if (remote_read_description_p (target
)
3950 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3952 target_clear_description ();
3953 target_find_description ();
3956 /* Use the previously fetched status. */
3957 gdb_assert (wait_status
!= NULL
);
3958 strcpy (rs
->buf
, wait_status
);
3959 rs
->cached_wait_status
= 1;
3962 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3966 ptid_t current_ptid
;
3968 /* Clear WFI global state. Do this before finding about new
3969 threads and inferiors, and setting the current inferior.
3970 Otherwise we would clear the proceed status of the current
3971 inferior when we want its stop_soon state to be preserved
3972 (see notice_new_inferior). */
3973 init_wait_for_inferior ();
3975 /* In non-stop, we will either get an "OK", meaning that there
3976 are no stopped threads at this time; or, a regular stop
3977 reply. In the latter case, there may be more than one thread
3978 stopped --- we pull them all out using the vStopped
3980 if (strcmp (rs
->buf
, "OK") != 0)
3982 struct notif_client
*notif
= ¬if_client_stop
;
3984 /* remote_notif_get_pending_replies acks this one, and gets
3986 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3987 = remote_notif_parse (notif
, rs
->buf
);
3988 remote_notif_get_pending_events (notif
);
3991 if (thread_count () == 0)
3994 error (_("The target is not running (try extended-remote?)"));
3996 /* We're connected, but not running. Drop out before we
3997 call start_remote. */
3998 rs
->starting_up
= 0;
4002 /* Let the stub know that we want it to return the thread. */
4004 /* Force the stub to choose a thread. */
4005 set_general_thread (null_ptid
);
4008 current_ptid
= remote_current_thread (minus_one_ptid
);
4009 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
4010 error (_("remote didn't report the current thread in non-stop mode"));
4012 inferior_ptid
= current_ptid
;
4013 get_offsets (); /* Get text, data & bss offsets. */
4015 /* In non-stop mode, any cached wait status will be stored in
4016 the stop reply queue. */
4017 gdb_assert (wait_status
== NULL
);
4019 /* Report all signals during attach/startup. */
4020 remote_pass_signals (target
, 0, NULL
);
4022 /* If there are already stopped threads, mark them stopped and
4023 report their stops before giving the prompt to the user. */
4024 process_initial_stop_replies ();
4026 switch_to_thread (current_ptid
);
4028 if (target_can_async_p ())
4032 /* If we connected to a live target, do some additional setup. */
4033 if (target_has_execution
)
4035 if (symfile_objfile
) /* No use without a symbol-file. */
4036 remote_check_symbols ();
4039 /* Possibly the target has been engaged in a trace run started
4040 previously; find out where things are at. */
4041 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4043 struct uploaded_tp
*uploaded_tps
= NULL
;
4045 if (current_trace_status ()->running
)
4046 printf_filtered (_("Trace is already running on the target.\n"));
4048 remote_upload_tracepoints (target
, &uploaded_tps
);
4050 merge_uploaded_tracepoints (&uploaded_tps
);
4053 /* The thread and inferior lists are now synchronized with the
4054 target, our symbols have been relocated, and we're merged the
4055 target's tracepoints with ours. We're done with basic start
4057 rs
->starting_up
= 0;
4059 /* Maybe breakpoints are global and need to be inserted now. */
4060 if (breakpoints_should_be_inserted_now ())
4061 insert_breakpoints ();
4064 /* Open a connection to a remote debugger.
4065 NAME is the filename used for communication. */
4068 remote_open (const char *name
, int from_tty
)
4070 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4073 /* Open a connection to a remote debugger using the extended
4074 remote gdb protocol. NAME is the filename used for communication. */
4077 extended_remote_open (const char *name
, int from_tty
)
4079 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4082 /* Reset all packets back to "unknown support". Called when opening a
4083 new connection to a remote target. */
4086 reset_all_packet_configs_support (void)
4090 for (i
= 0; i
< PACKET_MAX
; i
++)
4091 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4094 /* Initialize all packet configs. */
4097 init_all_packet_configs (void)
4101 for (i
= 0; i
< PACKET_MAX
; i
++)
4103 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4104 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4108 /* Symbol look-up. */
4111 remote_check_symbols (void)
4113 struct remote_state
*rs
= get_remote_state ();
4114 char *msg
, *reply
, *tmp
;
4115 struct bound_minimal_symbol sym
;
4117 struct cleanup
*old_chain
;
4119 /* The remote side has no concept of inferiors that aren't running
4120 yet, it only knows about running processes. If we're connected
4121 but our current inferior is not running, we should not invite the
4122 remote target to request symbol lookups related to its
4123 (unrelated) current process. */
4124 if (!target_has_execution
)
4127 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4130 /* Make sure the remote is pointing at the right process. Note
4131 there's no way to select "no process". */
4132 set_general_process ();
4134 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4135 because we need both at the same time. */
4136 msg
= (char *) xmalloc (get_remote_packet_size ());
4137 old_chain
= make_cleanup (xfree
, msg
);
4139 /* Invite target to request symbol lookups. */
4141 putpkt ("qSymbol::");
4142 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4143 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
4146 while (startswith (reply
, "qSymbol:"))
4148 struct bound_minimal_symbol sym
;
4151 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4153 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4154 if (sym
.minsym
== NULL
)
4155 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4158 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4159 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4161 /* If this is a function address, return the start of code
4162 instead of any data function descriptor. */
4163 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4167 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4168 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4172 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4176 do_cleanups (old_chain
);
4179 static struct serial
*
4180 remote_serial_open (const char *name
)
4182 static int udp_warning
= 0;
4184 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4185 of in ser-tcp.c, because it is the remote protocol assuming that the
4186 serial connection is reliable and not the serial connection promising
4188 if (!udp_warning
&& startswith (name
, "udp:"))
4190 warning (_("The remote protocol may be unreliable over UDP.\n"
4191 "Some events may be lost, rendering further debugging "
4196 return serial_open (name
);
4199 /* Inform the target of our permission settings. The permission flags
4200 work without this, but if the target knows the settings, it can do
4201 a couple things. First, it can add its own check, to catch cases
4202 that somehow manage to get by the permissions checks in target
4203 methods. Second, if the target is wired to disallow particular
4204 settings (for instance, a system in the field that is not set up to
4205 be able to stop at a breakpoint), it can object to any unavailable
4209 remote_set_permissions (struct target_ops
*self
)
4211 struct remote_state
*rs
= get_remote_state ();
4213 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4214 "WriteReg:%x;WriteMem:%x;"
4215 "InsertBreak:%x;InsertTrace:%x;"
4216 "InsertFastTrace:%x;Stop:%x",
4217 may_write_registers
, may_write_memory
,
4218 may_insert_breakpoints
, may_insert_tracepoints
,
4219 may_insert_fast_tracepoints
, may_stop
);
4221 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4223 /* If the target didn't like the packet, warn the user. Do not try
4224 to undo the user's settings, that would just be maddening. */
4225 if (strcmp (rs
->buf
, "OK") != 0)
4226 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4229 /* This type describes each known response to the qSupported
4231 struct protocol_feature
4233 /* The name of this protocol feature. */
4236 /* The default for this protocol feature. */
4237 enum packet_support default_support
;
4239 /* The function to call when this feature is reported, or after
4240 qSupported processing if the feature is not supported.
4241 The first argument points to this structure. The second
4242 argument indicates whether the packet requested support be
4243 enabled, disabled, or probed (or the default, if this function
4244 is being called at the end of processing and this feature was
4245 not reported). The third argument may be NULL; if not NULL, it
4246 is a NUL-terminated string taken from the packet following
4247 this feature's name and an equals sign. */
4248 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4251 /* The corresponding packet for this feature. Only used if
4252 FUNC is remote_supported_packet. */
4257 remote_supported_packet (const struct protocol_feature
*feature
,
4258 enum packet_support support
,
4259 const char *argument
)
4263 warning (_("Remote qSupported response supplied an unexpected value for"
4264 " \"%s\"."), feature
->name
);
4268 remote_protocol_packets
[feature
->packet
].support
= support
;
4272 remote_packet_size (const struct protocol_feature
*feature
,
4273 enum packet_support support
, const char *value
)
4275 struct remote_state
*rs
= get_remote_state ();
4280 if (support
!= PACKET_ENABLE
)
4283 if (value
== NULL
|| *value
== '\0')
4285 warning (_("Remote target reported \"%s\" without a size."),
4291 packet_size
= strtol (value
, &value_end
, 16);
4292 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4294 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4295 feature
->name
, value
);
4299 /* Record the new maximum packet size. */
4300 rs
->explicit_packet_size
= packet_size
;
4303 static const struct protocol_feature remote_protocol_features
[] = {
4304 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4305 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4306 PACKET_qXfer_auxv
},
4307 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4308 PACKET_qXfer_exec_file
},
4309 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4310 PACKET_qXfer_features
},
4311 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4312 PACKET_qXfer_libraries
},
4313 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4314 PACKET_qXfer_libraries_svr4
},
4315 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4316 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4317 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4318 PACKET_qXfer_memory_map
},
4319 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4320 PACKET_qXfer_spu_read
},
4321 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4322 PACKET_qXfer_spu_write
},
4323 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4324 PACKET_qXfer_osdata
},
4325 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4326 PACKET_qXfer_threads
},
4327 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4328 PACKET_qXfer_traceframe_info
},
4329 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4330 PACKET_QPassSignals
},
4331 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4332 PACKET_QProgramSignals
},
4333 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4334 PACKET_QStartNoAckMode
},
4335 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4336 PACKET_multiprocess_feature
},
4337 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4338 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4339 PACKET_qXfer_siginfo_read
},
4340 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4341 PACKET_qXfer_siginfo_write
},
4342 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4343 PACKET_ConditionalTracepoints
},
4344 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4345 PACKET_ConditionalBreakpoints
},
4346 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4347 PACKET_BreakpointCommands
},
4348 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4349 PACKET_FastTracepoints
},
4350 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4351 PACKET_StaticTracepoints
},
4352 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4353 PACKET_InstallInTrace
},
4354 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4355 PACKET_DisconnectedTracing_feature
},
4356 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4358 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4360 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4361 PACKET_TracepointSource
},
4362 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4364 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4365 PACKET_EnableDisableTracepoints_feature
},
4366 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4367 PACKET_qXfer_fdpic
},
4368 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4370 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4371 PACKET_QDisableRandomization
},
4372 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4373 { "QTBuffer:size", PACKET_DISABLE
,
4374 remote_supported_packet
, PACKET_QTBuffer_size
},
4375 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4376 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4377 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4378 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4379 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4380 PACKET_qXfer_btrace
},
4381 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4382 PACKET_qXfer_btrace_conf
},
4383 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4384 PACKET_Qbtrace_conf_bts_size
},
4385 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4386 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4387 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4388 PACKET_fork_event_feature
},
4389 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4390 PACKET_vfork_event_feature
},
4391 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4392 PACKET_exec_event_feature
},
4393 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4394 PACKET_Qbtrace_conf_pt_size
},
4395 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
}
4398 static char *remote_support_xml
;
4400 /* Register string appended to "xmlRegisters=" in qSupported query. */
4403 register_remote_support_xml (const char *xml
)
4405 #if defined(HAVE_LIBEXPAT)
4406 if (remote_support_xml
== NULL
)
4407 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4410 char *copy
= xstrdup (remote_support_xml
+ 13);
4411 char *p
= strtok (copy
, ",");
4415 if (strcmp (p
, xml
) == 0)
4422 while ((p
= strtok (NULL
, ",")) != NULL
);
4425 remote_support_xml
= reconcat (remote_support_xml
,
4426 remote_support_xml
, ",", xml
,
4433 remote_query_supported_append (char *msg
, const char *append
)
4436 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4438 return xstrdup (append
);
4442 remote_query_supported (void)
4444 struct remote_state
*rs
= get_remote_state ();
4447 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4449 /* The packet support flags are handled differently for this packet
4450 than for most others. We treat an error, a disabled packet, and
4451 an empty response identically: any features which must be reported
4452 to be used will be automatically disabled. An empty buffer
4453 accomplishes this, since that is also the representation for a list
4454 containing no features. */
4457 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4460 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4462 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4463 q
= remote_query_supported_append (q
, "multiprocess+");
4465 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4466 q
= remote_query_supported_append (q
, "swbreak+");
4467 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4468 q
= remote_query_supported_append (q
, "hwbreak+");
4470 if (remote_support_xml
)
4471 q
= remote_query_supported_append (q
, remote_support_xml
);
4473 q
= remote_query_supported_append (q
, "qRelocInsn+");
4477 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4478 != AUTO_BOOLEAN_FALSE
)
4479 q
= remote_query_supported_append (q
, "fork-events+");
4480 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4481 != AUTO_BOOLEAN_FALSE
)
4482 q
= remote_query_supported_append (q
, "vfork-events+");
4483 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4484 != AUTO_BOOLEAN_FALSE
)
4485 q
= remote_query_supported_append (q
, "exec-events+");
4488 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4489 q
= remote_query_supported_append (q
, "vContSupported+");
4491 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4494 do_cleanups (old_chain
);
4496 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4498 /* If an error occured, warn, but do not return - just reset the
4499 buffer to empty and go on to disable features. */
4500 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4503 warning (_("Remote failure reply: %s"), rs
->buf
);
4508 memset (seen
, 0, sizeof (seen
));
4513 enum packet_support is_supported
;
4514 char *p
, *end
, *name_end
, *value
;
4516 /* First separate out this item from the rest of the packet. If
4517 there's another item after this, we overwrite the separator
4518 (terminated strings are much easier to work with). */
4520 end
= strchr (p
, ';');
4523 end
= p
+ strlen (p
);
4533 warning (_("empty item in \"qSupported\" response"));
4538 name_end
= strchr (p
, '=');
4541 /* This is a name=value entry. */
4542 is_supported
= PACKET_ENABLE
;
4543 value
= name_end
+ 1;
4552 is_supported
= PACKET_ENABLE
;
4556 is_supported
= PACKET_DISABLE
;
4560 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4564 warning (_("unrecognized item \"%s\" "
4565 "in \"qSupported\" response"), p
);
4571 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4572 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4574 const struct protocol_feature
*feature
;
4577 feature
= &remote_protocol_features
[i
];
4578 feature
->func (feature
, is_supported
, value
);
4583 /* If we increased the packet size, make sure to increase the global
4584 buffer size also. We delay this until after parsing the entire
4585 qSupported packet, because this is the same buffer we were
4587 if (rs
->buf_size
< rs
->explicit_packet_size
)
4589 rs
->buf_size
= rs
->explicit_packet_size
;
4590 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4593 /* Handle the defaults for unmentioned features. */
4594 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4597 const struct protocol_feature
*feature
;
4599 feature
= &remote_protocol_features
[i
];
4600 feature
->func (feature
, feature
->default_support
, NULL
);
4604 /* Remove any of the remote.c targets from target stack. Upper targets depend
4605 on it so remove them first. */
4608 remote_unpush_target (void)
4610 pop_all_targets_above (process_stratum
- 1);
4614 remote_open_1 (const char *name
, int from_tty
,
4615 struct target_ops
*target
, int extended_p
)
4617 struct remote_state
*rs
= get_remote_state ();
4620 error (_("To open a remote debug connection, you need to specify what\n"
4621 "serial device is attached to the remote system\n"
4622 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4624 /* See FIXME above. */
4625 if (!target_async_permitted
)
4626 wait_forever_enabled_p
= 1;
4628 /* If we're connected to a running target, target_preopen will kill it.
4629 Ask this question first, before target_preopen has a chance to kill
4631 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4634 && !query (_("Already connected to a remote target. Disconnect? ")))
4635 error (_("Still connected."));
4638 /* Here the possibly existing remote target gets unpushed. */
4639 target_preopen (from_tty
);
4641 /* Make sure we send the passed signals list the next time we resume. */
4642 xfree (rs
->last_pass_packet
);
4643 rs
->last_pass_packet
= NULL
;
4645 /* Make sure we send the program signals list the next time we
4647 xfree (rs
->last_program_signals_packet
);
4648 rs
->last_program_signals_packet
= NULL
;
4650 remote_fileio_reset ();
4651 reopen_exec_file ();
4654 rs
->remote_desc
= remote_serial_open (name
);
4655 if (!rs
->remote_desc
)
4656 perror_with_name (name
);
4658 if (baud_rate
!= -1)
4660 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4662 /* The requested speed could not be set. Error out to
4663 top level after closing remote_desc. Take care to
4664 set remote_desc to NULL to avoid closing remote_desc
4666 serial_close (rs
->remote_desc
);
4667 rs
->remote_desc
= NULL
;
4668 perror_with_name (name
);
4672 serial_setparity (rs
->remote_desc
, serial_parity
);
4673 serial_raw (rs
->remote_desc
);
4675 /* If there is something sitting in the buffer we might take it as a
4676 response to a command, which would be bad. */
4677 serial_flush_input (rs
->remote_desc
);
4681 puts_filtered ("Remote debugging using ");
4682 puts_filtered (name
);
4683 puts_filtered ("\n");
4685 push_target (target
); /* Switch to using remote target now. */
4687 /* Register extra event sources in the event loop. */
4688 remote_async_inferior_event_token
4689 = create_async_event_handler (remote_async_inferior_event_handler
,
4691 rs
->notif_state
= remote_notif_state_allocate ();
4693 /* Reset the target state; these things will be queried either by
4694 remote_query_supported or as they are needed. */
4695 reset_all_packet_configs_support ();
4696 rs
->cached_wait_status
= 0;
4697 rs
->explicit_packet_size
= 0;
4699 rs
->extended
= extended_p
;
4700 rs
->waiting_for_stop_reply
= 0;
4701 rs
->ctrlc_pending_p
= 0;
4703 rs
->general_thread
= not_sent_ptid
;
4704 rs
->continue_thread
= not_sent_ptid
;
4705 rs
->remote_traceframe_number
= -1;
4707 /* Probe for ability to use "ThreadInfo" query, as required. */
4708 rs
->use_threadinfo_query
= 1;
4709 rs
->use_threadextra_query
= 1;
4711 readahead_cache_invalidate ();
4713 if (target_async_permitted
)
4715 /* With this target we start out by owning the terminal. */
4716 remote_async_terminal_ours_p
= 1;
4718 /* FIXME: cagney/1999-09-23: During the initial connection it is
4719 assumed that the target is already ready and able to respond to
4720 requests. Unfortunately remote_start_remote() eventually calls
4721 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4722 around this. Eventually a mechanism that allows
4723 wait_for_inferior() to expect/get timeouts will be
4725 wait_forever_enabled_p
= 0;
4728 /* First delete any symbols previously loaded from shared libraries. */
4729 no_shared_libraries (NULL
, 0);
4732 init_thread_list ();
4734 /* Start the remote connection. If error() or QUIT, discard this
4735 target (we'd otherwise be in an inconsistent state) and then
4736 propogate the error on up the exception chain. This ensures that
4737 the caller doesn't stumble along blindly assuming that the
4738 function succeeded. The CLI doesn't have this problem but other
4739 UI's, such as MI do.
4741 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4742 this function should return an error indication letting the
4743 caller restore the previous state. Unfortunately the command
4744 ``target remote'' is directly wired to this function making that
4745 impossible. On a positive note, the CLI side of this problem has
4746 been fixed - the function set_cmd_context() makes it possible for
4747 all the ``target ....'' commands to share a common callback
4748 function. See cli-dump.c. */
4753 remote_start_remote (from_tty
, target
, extended_p
);
4755 CATCH (ex
, RETURN_MASK_ALL
)
4757 /* Pop the partially set up target - unless something else did
4758 already before throwing the exception. */
4759 if (rs
->remote_desc
!= NULL
)
4760 remote_unpush_target ();
4761 if (target_async_permitted
)
4762 wait_forever_enabled_p
= 1;
4763 throw_exception (ex
);
4768 remote_btrace_reset ();
4770 if (target_async_permitted
)
4771 wait_forever_enabled_p
= 1;
4774 /* Detach the specified process. */
4777 remote_detach_pid (int pid
)
4779 struct remote_state
*rs
= get_remote_state ();
4781 if (remote_multi_process_p (rs
))
4782 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4784 strcpy (rs
->buf
, "D");
4787 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4789 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4791 else if (rs
->buf
[0] == '\0')
4792 error (_("Remote doesn't know how to detach"));
4794 error (_("Can't detach process."));
4797 /* This detaches a program to which we previously attached, using
4798 inferior_ptid to identify the process. After this is done, GDB
4799 can be used to debug some other program. We better not have left
4800 any breakpoints in the target program or it'll die when it hits
4804 remote_detach_1 (const char *args
, int from_tty
)
4806 int pid
= ptid_get_pid (inferior_ptid
);
4807 struct remote_state
*rs
= get_remote_state ();
4808 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4812 error (_("Argument given to \"detach\" when remotely debugging."));
4814 if (!target_has_execution
)
4815 error (_("No process to detach from."));
4819 char *exec_file
= get_exec_file (0);
4820 if (exec_file
== NULL
)
4822 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4823 target_pid_to_str (pid_to_ptid (pid
)));
4824 gdb_flush (gdb_stdout
);
4827 /* Tell the remote target to detach. */
4828 remote_detach_pid (pid
);
4830 if (from_tty
&& !rs
->extended
)
4831 puts_filtered (_("Ending remote debugging.\n"));
4833 /* Check to see if we are detaching a fork parent. Note that if we
4834 are detaching a fork child, tp == NULL. */
4835 is_fork_parent
= (tp
!= NULL
4836 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4838 /* If doing detach-on-fork, we don't mourn, because that will delete
4839 breakpoints that should be available for the followed inferior. */
4840 if (!is_fork_parent
)
4841 target_mourn_inferior ();
4844 inferior_ptid
= null_ptid
;
4845 detach_inferior (pid
);
4850 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4852 remote_detach_1 (args
, from_tty
);
4856 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4858 remote_detach_1 (args
, from_tty
);
4861 /* Target follow-fork function for remote targets. On entry, and
4862 at return, the current inferior is the fork parent.
4864 Note that although this is currently only used for extended-remote,
4865 it is named remote_follow_fork in anticipation of using it for the
4866 remote target as well. */
4869 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4872 struct remote_state
*rs
= get_remote_state ();
4873 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4875 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4876 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4878 /* When following the parent and detaching the child, we detach
4879 the child here. For the case of following the child and
4880 detaching the parent, the detach is done in the target-
4881 independent follow fork code in infrun.c. We can't use
4882 target_detach when detaching an unfollowed child because
4883 the client side doesn't know anything about the child. */
4884 if (detach_fork
&& !follow_child
)
4886 /* Detach the fork child. */
4890 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4891 child_pid
= ptid_get_pid (child_ptid
);
4893 remote_detach_pid (child_pid
);
4894 detach_inferior (child_pid
);
4900 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
4901 in the program space of the new inferior. On entry and at return the
4902 current inferior is the exec'ing inferior. INF is the new exec'd
4903 inferior, which may be the same as the exec'ing inferior unless
4904 follow-exec-mode is "new". */
4907 remote_follow_exec (struct target_ops
*ops
,
4908 struct inferior
*inf
, char *execd_pathname
)
4910 /* We know that this is a target file name, so if it has the "target:"
4911 prefix we strip it off before saving it in the program space. */
4912 if (is_target_filename (execd_pathname
))
4913 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
4915 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
4918 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4921 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4924 error (_("Argument given to \"disconnect\" when remotely debugging."));
4926 /* Make sure we unpush even the extended remote targets; mourn
4927 won't do it. So call remote_mourn directly instead of
4928 target_mourn_inferior. */
4929 remote_mourn (target
);
4932 puts_filtered ("Ending remote debugging.\n");
4935 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4936 be chatty about it. */
4939 extended_remote_attach (struct target_ops
*target
, const char *args
,
4942 struct remote_state
*rs
= get_remote_state ();
4944 char *wait_status
= NULL
;
4946 pid
= parse_pid_to_attach (args
);
4948 /* Remote PID can be freely equal to getpid, do not check it here the same
4949 way as in other targets. */
4951 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4952 error (_("This target does not support attaching to a process"));
4956 char *exec_file
= get_exec_file (0);
4959 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4960 target_pid_to_str (pid_to_ptid (pid
)));
4962 printf_unfiltered (_("Attaching to %s\n"),
4963 target_pid_to_str (pid_to_ptid (pid
)));
4965 gdb_flush (gdb_stdout
);
4968 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4972 switch (packet_ok (rs
->buf
,
4973 &remote_protocol_packets
[PACKET_vAttach
]))
4978 /* Save the reply for later. */
4979 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4980 strcpy (wait_status
, rs
->buf
);
4982 else if (strcmp (rs
->buf
, "OK") != 0)
4983 error (_("Attaching to %s failed with: %s"),
4984 target_pid_to_str (pid_to_ptid (pid
)),
4987 case PACKET_UNKNOWN
:
4988 error (_("This target does not support attaching to a process"));
4990 error (_("Attaching to %s failed"),
4991 target_pid_to_str (pid_to_ptid (pid
)));
4994 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4996 inferior_ptid
= pid_to_ptid (pid
);
5000 struct thread_info
*thread
;
5002 /* Get list of threads. */
5003 remote_update_thread_list (target
);
5005 thread
= first_thread_of_process (pid
);
5007 inferior_ptid
= thread
->ptid
;
5009 inferior_ptid
= pid_to_ptid (pid
);
5011 /* Invalidate our notion of the remote current thread. */
5012 record_currthread (rs
, minus_one_ptid
);
5016 /* Now, if we have thread information, update inferior_ptid. */
5017 inferior_ptid
= remote_current_thread (inferior_ptid
);
5019 /* Add the main thread to the thread list. */
5020 add_thread_silent (inferior_ptid
);
5023 /* Next, if the target can specify a description, read it. We do
5024 this before anything involving memory or registers. */
5025 target_find_description ();
5029 /* Use the previously fetched status. */
5030 gdb_assert (wait_status
!= NULL
);
5032 if (target_can_async_p ())
5034 struct notif_event
*reply
5035 = remote_notif_parse (¬if_client_stop
, wait_status
);
5037 push_stop_reply ((struct stop_reply
*) reply
);
5043 gdb_assert (wait_status
!= NULL
);
5044 strcpy (rs
->buf
, wait_status
);
5045 rs
->cached_wait_status
= 1;
5049 gdb_assert (wait_status
== NULL
);
5052 /* Implementation of the to_post_attach method. */
5055 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5057 /* In certain cases GDB might not have had the chance to start
5058 symbol lookup up until now. This could happen if the debugged
5059 binary is not using shared libraries, the vsyscall page is not
5060 present (on Linux) and the binary itself hadn't changed since the
5061 debugging process was started. */
5062 if (symfile_objfile
!= NULL
)
5063 remote_check_symbols();
5067 /* Check for the availability of vCont. This function should also check
5071 remote_vcont_probe (struct remote_state
*rs
)
5075 strcpy (rs
->buf
, "vCont?");
5077 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5080 /* Make sure that the features we assume are supported. */
5081 if (startswith (buf
, "vCont"))
5084 int support_c
, support_C
;
5086 rs
->supports_vCont
.s
= 0;
5087 rs
->supports_vCont
.S
= 0;
5090 rs
->supports_vCont
.t
= 0;
5091 rs
->supports_vCont
.r
= 0;
5092 while (p
&& *p
== ';')
5095 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5096 rs
->supports_vCont
.s
= 1;
5097 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5098 rs
->supports_vCont
.S
= 1;
5099 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5101 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5103 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5104 rs
->supports_vCont
.t
= 1;
5105 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5106 rs
->supports_vCont
.r
= 1;
5108 p
= strchr (p
, ';');
5111 /* If c, and C are not all supported, we can't use vCont. Clearing
5112 BUF will make packet_ok disable the packet. */
5113 if (!support_c
|| !support_C
)
5117 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5120 /* Helper function for building "vCont" resumptions. Write a
5121 resumption to P. ENDP points to one-passed-the-end of the buffer
5122 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5123 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5124 resumed thread should be single-stepped and/or signalled. If PTID
5125 equals minus_one_ptid, then all threads are resumed; if PTID
5126 represents a process, then all threads of the process are resumed;
5127 the thread to be stepped and/or signalled is given in the global
5131 append_resumption (char *p
, char *endp
,
5132 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5134 struct remote_state
*rs
= get_remote_state ();
5136 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5137 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5139 /* GDB is willing to range step. */
5140 && use_range_stepping
5141 /* Target supports range stepping. */
5142 && rs
->supports_vCont
.r
5143 /* We don't currently support range stepping multiple
5144 threads with a wildcard (though the protocol allows it,
5145 so stubs shouldn't make an active effort to forbid
5147 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5149 struct thread_info
*tp
;
5151 if (ptid_equal (ptid
, minus_one_ptid
))
5153 /* If we don't know about the target thread's tid, then
5154 we're resuming magic_null_ptid (see caller). */
5155 tp
= find_thread_ptid (magic_null_ptid
);
5158 tp
= find_thread_ptid (ptid
);
5159 gdb_assert (tp
!= NULL
);
5161 if (tp
->control
.may_range_step
)
5163 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5165 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5166 phex_nz (tp
->control
.step_range_start
,
5168 phex_nz (tp
->control
.step_range_end
,
5172 p
+= xsnprintf (p
, endp
- p
, ";s");
5175 p
+= xsnprintf (p
, endp
- p
, ";s");
5176 else if (siggnal
!= GDB_SIGNAL_0
)
5177 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5179 p
+= xsnprintf (p
, endp
- p
, ";c");
5181 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5185 /* All (-1) threads of process. */
5186 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5188 p
+= xsnprintf (p
, endp
- p
, ":");
5189 p
= write_ptid (p
, endp
, nptid
);
5191 else if (!ptid_equal (ptid
, minus_one_ptid
))
5193 p
+= xsnprintf (p
, endp
- p
, ":");
5194 p
= write_ptid (p
, endp
, ptid
);
5200 /* Append a vCont continue-with-signal action for threads that have a
5201 non-zero stop signal. */
5204 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5206 struct thread_info
*thread
;
5208 ALL_NON_EXITED_THREADS (thread
)
5209 if (ptid_match (thread
->ptid
, ptid
)
5210 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5211 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5213 p
= append_resumption (p
, endp
, thread
->ptid
,
5214 0, thread
->suspend
.stop_signal
);
5215 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5221 /* Resume the remote inferior by using a "vCont" packet. The thread
5222 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5223 resumed thread should be single-stepped and/or signalled. If PTID
5224 equals minus_one_ptid, then all threads are resumed; the thread to
5225 be stepped and/or signalled is given in the global INFERIOR_PTID.
5226 This function returns non-zero iff it resumes the inferior.
5228 This function issues a strict subset of all possible vCont commands at the
5232 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5234 struct remote_state
*rs
= get_remote_state ();
5238 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5239 remote_vcont_probe (rs
);
5241 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5245 endp
= rs
->buf
+ get_remote_packet_size ();
5247 /* If we could generate a wider range of packets, we'd have to worry
5248 about overflowing BUF. Should there be a generic
5249 "multi-part-packet" packet? */
5251 p
+= xsnprintf (p
, endp
- p
, "vCont");
5253 if (ptid_equal (ptid
, magic_null_ptid
))
5255 /* MAGIC_NULL_PTID means that we don't have any active threads,
5256 so we don't have any TID numbers the inferior will
5257 understand. Make sure to only send forms that do not specify
5259 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5261 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5263 /* Resume all threads (of all processes, or of a single
5264 process), with preference for INFERIOR_PTID. This assumes
5265 inferior_ptid belongs to the set of all threads we are about
5267 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5269 /* Step inferior_ptid, with or without signal. */
5270 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5273 /* Also pass down any pending signaled resumption for other
5274 threads not the current. */
5275 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5277 /* And continue others without a signal. */
5278 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5282 /* Scheduler locking; resume only PTID. */
5283 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5286 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5291 /* In non-stop, the stub replies to vCont with "OK". The stop
5292 reply will be reported asynchronously by means of a `%Stop'
5294 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5295 if (strcmp (rs
->buf
, "OK") != 0)
5296 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5302 /* Tell the remote machine to resume. */
5305 remote_resume (struct target_ops
*ops
,
5306 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5308 struct remote_state
*rs
= get_remote_state ();
5311 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5312 (explained in remote-notif.c:handle_notification) so
5313 remote_notif_process is not called. We need find a place where
5314 it is safe to start a 'vNotif' sequence. It is good to do it
5315 before resuming inferior, because inferior was stopped and no RSP
5316 traffic at that moment. */
5318 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5320 rs
->last_sent_signal
= siggnal
;
5321 rs
->last_sent_step
= step
;
5323 /* The vCont packet doesn't need to specify threads via Hc. */
5324 /* No reverse support (yet) for vCont. */
5325 if (execution_direction
!= EXEC_REVERSE
)
5326 if (remote_vcont_resume (ptid
, step
, siggnal
))
5329 /* All other supported resume packets do use Hc, so set the continue
5331 if (ptid_equal (ptid
, minus_one_ptid
))
5332 set_continue_thread (any_thread_ptid
);
5334 set_continue_thread (ptid
);
5337 if (execution_direction
== EXEC_REVERSE
)
5339 /* We don't pass signals to the target in reverse exec mode. */
5340 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5341 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5344 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5345 error (_("Remote reverse-step not supported."));
5346 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5347 error (_("Remote reverse-continue not supported."));
5349 strcpy (buf
, step
? "bs" : "bc");
5351 else if (siggnal
!= GDB_SIGNAL_0
)
5353 buf
[0] = step
? 'S' : 'C';
5354 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5355 buf
[2] = tohex (((int) siggnal
) & 0xf);
5359 strcpy (buf
, step
? "s" : "c");
5364 /* We are about to start executing the inferior, let's register it
5365 with the event loop. NOTE: this is the one place where all the
5366 execution commands end up. We could alternatively do this in each
5367 of the execution commands in infcmd.c. */
5368 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5369 into infcmd.c in order to allow inferior function calls to work
5370 NOT asynchronously. */
5371 if (target_can_async_p ())
5374 /* We've just told the target to resume. The remote server will
5375 wait for the inferior to stop, and then send a stop reply. In
5376 the mean time, we can't start another command/query ourselves
5377 because the stub wouldn't be ready to process it. This applies
5378 only to the base all-stop protocol, however. In non-stop (which
5379 only supports vCont), the stub replies with an "OK", and is
5380 immediate able to process further serial input. */
5382 rs
->waiting_for_stop_reply
= 1;
5386 /* Set up the signal handler for SIGINT, while the target is
5387 executing, ovewriting the 'regular' SIGINT signal handler. */
5389 async_initialize_sigint_signal_handler (void)
5391 signal (SIGINT
, async_handle_remote_sigint
);
5394 /* Signal handler for SIGINT, while the target is executing. */
5396 async_handle_remote_sigint (int sig
)
5398 signal (sig
, async_handle_remote_sigint_twice
);
5399 /* Note we need to go through gdb_call_async_signal_handler in order
5400 to wake up the event loop on Windows. */
5401 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5404 /* Signal handler for SIGINT, installed after SIGINT has already been
5405 sent once. It will take effect the second time that the user sends
5408 async_handle_remote_sigint_twice (int sig
)
5410 signal (sig
, async_handle_remote_sigint
);
5411 /* See note in async_handle_remote_sigint. */
5412 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5415 /* Implementation of to_check_pending_interrupt. */
5418 remote_check_pending_interrupt (struct target_ops
*self
)
5420 struct async_signal_handler
*token
= async_sigint_remote_twice_token
;
5422 if (async_signal_handler_is_marked (token
))
5424 clear_async_signal_handler (token
);
5425 call_async_signal_handler (token
);
5429 /* Perform the real interruption of the target execution, in response
5432 async_remote_interrupt (gdb_client_data arg
)
5435 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5437 target_stop (inferior_ptid
);
5440 /* Perform interrupt, if the first attempt did not succeed. Just give
5441 up on the target alltogether. */
5443 async_remote_interrupt_twice (gdb_client_data arg
)
5446 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5451 /* Reinstall the usual SIGINT handlers, after the target has
5454 async_cleanup_sigint_signal_handler (void *dummy
)
5456 signal (SIGINT
, handle_sigint
);
5459 /* Send ^C to target to halt it. Target will respond, and send us a
5461 static void (*ofunc
) (int);
5463 /* The command line interface's interrupt routine. This function is installed
5464 as a signal handler for SIGINT. The first time a user requests an
5465 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5466 response from the target (it didn't stop when the user requested it),
5467 we ask the user if he'd like to detach from the target. */
5470 sync_remote_interrupt (int signo
)
5472 /* If this doesn't work, try more severe steps. */
5473 signal (signo
, sync_remote_interrupt_twice
);
5475 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5478 /* The user typed ^C twice. */
5481 sync_remote_interrupt_twice (int signo
)
5483 signal (signo
, ofunc
);
5484 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5485 signal (signo
, sync_remote_interrupt
);
5488 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5489 thread, all threads of a remote process, or all threads of all
5493 remote_stop_ns (ptid_t ptid
)
5495 struct remote_state
*rs
= get_remote_state ();
5497 char *endp
= rs
->buf
+ get_remote_packet_size ();
5499 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5500 remote_vcont_probe (rs
);
5502 if (!rs
->supports_vCont
.t
)
5503 error (_("Remote server does not support stopping threads"));
5505 if (ptid_equal (ptid
, minus_one_ptid
)
5506 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5507 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5512 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5514 if (ptid_is_pid (ptid
))
5515 /* All (-1) threads of process. */
5516 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5519 /* Small optimization: if we already have a stop reply for
5520 this thread, no use in telling the stub we want this
5522 if (peek_stop_reply (ptid
))
5528 write_ptid (p
, endp
, nptid
);
5531 /* In non-stop, we get an immediate OK reply. The stop reply will
5532 come in asynchronously by notification. */
5534 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5535 if (strcmp (rs
->buf
, "OK") != 0)
5536 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5539 /* All-stop version of target_interrupt. Sends a break or a ^C to
5540 interrupt the remote target. It is undefined which thread of which
5541 process reports the interrupt. */
5544 remote_interrupt_as (ptid_t ptid
)
5546 struct remote_state
*rs
= get_remote_state ();
5548 rs
->ctrlc_pending_p
= 1;
5550 /* If the inferior is stopped already, but the core didn't know
5551 about it yet, just ignore the request. The cached wait status
5552 will be collected in remote_wait. */
5553 if (rs
->cached_wait_status
)
5556 /* Send interrupt_sequence to remote target. */
5557 send_interrupt_sequence ();
5560 /* Implement the to_stop function for the remote targets. */
5563 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5566 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5569 remote_stop_ns (ptid
);
5572 /* We don't currently have a way to transparently pause the
5573 remote target in all-stop mode. Interrupt it instead. */
5574 remote_interrupt_as (ptid
);
5578 /* Implement the to_interrupt function for the remote targets. */
5581 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5584 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5588 /* We don't currently have a way to ^C the remote target in
5589 non-stop mode. Stop it (with no signal) instead. */
5590 remote_stop_ns (ptid
);
5593 remote_interrupt_as (ptid
);
5596 /* Ask the user what to do when an interrupt is received. */
5599 interrupt_query (void)
5601 struct remote_state
*rs
= get_remote_state ();
5602 struct cleanup
*old_chain
;
5604 old_chain
= make_cleanup_restore_target_terminal ();
5605 target_terminal_ours ();
5607 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5609 if (query (_("The target is not responding to interrupt requests.\n"
5610 "Stop debugging it? ")))
5612 remote_unpush_target ();
5613 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5618 if (query (_("Interrupted while waiting for the program.\n"
5619 "Give up waiting? ")))
5623 do_cleanups (old_chain
);
5626 /* Enable/disable target terminal ownership. Most targets can use
5627 terminal groups to control terminal ownership. Remote targets are
5628 different in that explicit transfer of ownership to/from GDB/target
5632 remote_terminal_inferior (struct target_ops
*self
)
5634 if (!target_async_permitted
)
5635 /* Nothing to do. */
5638 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5639 idempotent. The event-loop GDB talking to an asynchronous target
5640 with a synchronous command calls this function from both
5641 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5642 transfer the terminal to the target when it shouldn't this guard
5644 if (!remote_async_terminal_ours_p
)
5646 delete_file_handler (input_fd
);
5647 remote_async_terminal_ours_p
= 0;
5648 async_initialize_sigint_signal_handler ();
5649 /* NOTE: At this point we could also register our selves as the
5650 recipient of all input. Any characters typed could then be
5651 passed on down to the target. */
5655 remote_terminal_ours (struct target_ops
*self
)
5657 if (!target_async_permitted
)
5658 /* Nothing to do. */
5661 /* See FIXME in remote_terminal_inferior. */
5662 if (remote_async_terminal_ours_p
)
5664 async_cleanup_sigint_signal_handler (NULL
);
5665 add_file_handler (input_fd
, stdin_event_handler
, 0);
5666 remote_async_terminal_ours_p
= 1;
5670 remote_console_output (char *msg
)
5674 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5677 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5681 fputs_unfiltered (tb
, gdb_stdtarg
);
5683 gdb_flush (gdb_stdtarg
);
5686 typedef struct cached_reg
5689 gdb_byte data
[MAX_REGISTER_SIZE
];
5692 DEF_VEC_O(cached_reg_t
);
5694 typedef struct stop_reply
5696 struct notif_event base
;
5698 /* The identifier of the thread about this event */
5701 /* The remote state this event is associated with. When the remote
5702 connection, represented by a remote_state object, is closed,
5703 all the associated stop_reply events should be released. */
5704 struct remote_state
*rs
;
5706 struct target_waitstatus ws
;
5708 /* Expedited registers. This makes remote debugging a bit more
5709 efficient for those targets that provide critical registers as
5710 part of their normal status mechanism (as another roundtrip to
5711 fetch them is avoided). */
5712 VEC(cached_reg_t
) *regcache
;
5714 enum target_stop_reason stop_reason
;
5716 CORE_ADDR watch_data_address
;
5721 DECLARE_QUEUE_P (stop_reply_p
);
5722 DEFINE_QUEUE_P (stop_reply_p
);
5723 /* The list of already fetched and acknowledged stop events. This
5724 queue is used for notification Stop, and other notifications
5725 don't need queue for their events, because the notification events
5726 of Stop can't be consumed immediately, so that events should be
5727 queued first, and be consumed by remote_wait_{ns,as} one per
5728 time. Other notifications can consume their events immediately,
5729 so queue is not needed for them. */
5730 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5733 stop_reply_xfree (struct stop_reply
*r
)
5735 notif_event_xfree ((struct notif_event
*) r
);
5738 /* Return the length of the stop reply queue. */
5741 stop_reply_queue_length (void)
5743 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
5747 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5748 struct notif_event
*event
)
5750 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5754 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5755 struct notif_event
*event
)
5757 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5760 putpkt ((char *) self
->ack_command
);
5762 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5763 /* We got an unknown stop reply. */
5764 error (_("Unknown stop reply"));
5766 push_stop_reply (stop_reply
);
5770 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5772 /* We can't get pending events in remote_notif_process for
5773 notification stop, and we have to do this in remote_wait_ns
5774 instead. If we fetch all queued events from stub, remote stub
5775 may exit and we have no chance to process them back in
5777 mark_async_event_handler (remote_async_inferior_event_token
);
5782 stop_reply_dtr (struct notif_event
*event
)
5784 struct stop_reply
*r
= (struct stop_reply
*) event
;
5786 VEC_free (cached_reg_t
, r
->regcache
);
5789 static struct notif_event
*
5790 remote_notif_stop_alloc_reply (void)
5792 /* We cast to a pointer to the "base class". */
5793 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
5795 r
->dtr
= stop_reply_dtr
;
5800 /* A client of notification Stop. */
5802 struct notif_client notif_client_stop
=
5806 remote_notif_stop_parse
,
5807 remote_notif_stop_ack
,
5808 remote_notif_stop_can_get_pending_events
,
5809 remote_notif_stop_alloc_reply
,
5813 /* A parameter to pass data in and out. */
5815 struct queue_iter_param
5818 struct stop_reply
*output
;
5821 /* Determine if THREAD is a pending fork parent thread. ARG contains
5822 the pid of the process that owns the threads we want to check, or
5823 -1 if we want to check all threads. */
5826 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5829 if (ws
->kind
== TARGET_WAITKIND_FORKED
5830 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5832 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5839 /* Check whether EVENT is a fork event, and if it is, remove the
5840 fork child from the context list passed in DATA. */
5843 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5844 QUEUE_ITER (stop_reply_p
) *iter
,
5848 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
5849 struct threads_listing_context
*context
5850 = (struct threads_listing_context
*) param
->input
;
5852 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5853 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5855 threads_listing_context_remove (&event
->ws
, context
);
5861 /* If CONTEXT contains any fork child threads that have not been
5862 reported yet, remove them from the CONTEXT list. If such a
5863 thread exists it is because we are stopped at a fork catchpoint
5864 and have not yet called follow_fork, which will set up the
5865 host-side data structures for the new process. */
5868 remove_new_fork_children (struct threads_listing_context
*context
)
5870 struct thread_info
* thread
;
5872 struct notif_client
*notif
= ¬if_client_stop
;
5873 struct queue_iter_param param
;
5875 /* For any threads stopped at a fork event, remove the corresponding
5876 fork child threads from the CONTEXT list. */
5877 ALL_NON_EXITED_THREADS (thread
)
5879 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5881 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5883 threads_listing_context_remove (ws
, context
);
5887 /* Check for any pending fork events (not reported or processed yet)
5888 in process PID and remove those fork child threads from the
5889 CONTEXT list as well. */
5890 remote_notif_get_pending_events (notif
);
5891 param
.input
= context
;
5892 param
.output
= NULL
;
5893 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5894 remove_child_of_pending_fork
, ¶m
);
5897 /* Remove stop replies in the queue if its pid is equal to the given
5901 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5902 QUEUE_ITER (stop_reply_p
) *iter
,
5906 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
5907 struct inferior
*inf
= (struct inferior
*) param
->input
;
5909 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5911 stop_reply_xfree (event
);
5912 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5918 /* Discard all pending stop replies of inferior INF. */
5921 discard_pending_stop_replies (struct inferior
*inf
)
5924 struct queue_iter_param param
;
5925 struct stop_reply
*reply
;
5926 struct remote_state
*rs
= get_remote_state ();
5927 struct remote_notif_state
*rns
= rs
->notif_state
;
5929 /* This function can be notified when an inferior exists. When the
5930 target is not remote, the notification state is NULL. */
5931 if (rs
->remote_desc
== NULL
)
5934 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5936 /* Discard the in-flight notification. */
5937 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5939 stop_reply_xfree (reply
);
5940 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5944 param
.output
= NULL
;
5945 /* Discard the stop replies we have already pulled with
5947 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5948 remove_stop_reply_for_inferior
, ¶m
);
5951 /* If its remote state is equal to the given remote state,
5952 remove EVENT from the stop reply queue. */
5955 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5956 QUEUE_ITER (stop_reply_p
) *iter
,
5960 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
5961 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
5963 if (event
->rs
== rs
)
5965 stop_reply_xfree (event
);
5966 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5972 /* Discard the stop replies for RS in stop_reply_queue. */
5975 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5977 struct queue_iter_param param
;
5980 param
.output
= NULL
;
5981 /* Discard the stop replies we have already pulled with
5983 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5984 remove_stop_reply_of_remote_state
, ¶m
);
5987 /* A parameter to pass data in and out. */
5990 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5991 QUEUE_ITER (stop_reply_p
) *iter
,
5995 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
5996 ptid_t
*ptid
= (ptid_t
*) param
->input
;
5998 if (ptid_match (event
->ptid
, *ptid
))
6000 param
->output
= event
;
6001 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6008 /* Remove the first reply in 'stop_reply_queue' which matches
6011 static struct stop_reply
*
6012 remote_notif_remove_queued_reply (ptid_t ptid
)
6014 struct queue_iter_param param
;
6016 param
.input
= &ptid
;
6017 param
.output
= NULL
;
6019 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6020 remote_notif_remove_once_on_match
, ¶m
);
6022 fprintf_unfiltered (gdb_stdlog
,
6023 "notif: discard queued event: 'Stop' in %s\n",
6024 target_pid_to_str (ptid
));
6026 return param
.output
;
6029 /* Look for a queued stop reply belonging to PTID. If one is found,
6030 remove it from the queue, and return it. Returns NULL if none is
6031 found. If there are still queued events left to process, tell the
6032 event loop to get back to target_wait soon. */
6034 static struct stop_reply
*
6035 queued_stop_reply (ptid_t ptid
)
6037 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6039 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6040 /* There's still at least an event left. */
6041 mark_async_event_handler (remote_async_inferior_event_token
);
6046 /* Push a fully parsed stop reply in the stop reply queue. Since we
6047 know that we now have at least one queued event left to pass to the
6048 core side, tell the event loop to get back to target_wait soon. */
6051 push_stop_reply (struct stop_reply
*new_event
)
6053 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6056 fprintf_unfiltered (gdb_stdlog
,
6057 "notif: push 'Stop' %s to queue %d\n",
6058 target_pid_to_str (new_event
->ptid
),
6059 QUEUE_length (stop_reply_p
,
6062 mark_async_event_handler (remote_async_inferior_event_token
);
6066 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6067 QUEUE_ITER (stop_reply_p
) *iter
,
6068 struct stop_reply
*event
,
6071 ptid_t
*ptid
= (ptid_t
*) data
;
6073 return !(ptid_equal (*ptid
, event
->ptid
)
6074 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6077 /* Returns true if we have a stop reply for PTID. */
6080 peek_stop_reply (ptid_t ptid
)
6082 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6083 stop_reply_match_ptid_and_ws
, &ptid
);
6086 /* Skip PACKET until the next semi-colon (or end of string). */
6089 skip_to_semicolon (char *p
)
6091 while (*p
!= '\0' && *p
!= ';')
6096 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6097 starting with P and ending with PEND matches PREFIX. */
6100 strprefix (const char *p
, const char *pend
, const char *prefix
)
6102 for ( ; p
< pend
; p
++, prefix
++)
6105 return *prefix
== '\0';
6108 /* Parse the stop reply in BUF. Either the function succeeds, and the
6109 result is stored in EVENT, or throws an error. */
6112 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6114 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6119 event
->ptid
= null_ptid
;
6120 event
->rs
= get_remote_state ();
6121 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6122 event
->ws
.value
.integer
= 0;
6123 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6124 event
->regcache
= NULL
;
6129 case 'T': /* Status with PC, SP, FP, ... */
6130 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6131 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6133 n... = register number
6134 r... = register contents
6137 p
= &buf
[3]; /* after Txx */
6143 p1
= strchr (p
, ':');
6145 error (_("Malformed packet(a) (missing colon): %s\n\
6149 error (_("Malformed packet(a) (missing register number): %s\n\
6153 /* Some "registers" are actually extended stop information.
6154 Note if you're adding a new entry here: GDB 7.9 and
6155 earlier assume that all register "numbers" that start
6156 with an hex digit are real register numbers. Make sure
6157 the server only sends such a packet if it knows the
6158 client understands it. */
6160 if (strprefix (p
, p1
, "thread"))
6161 event
->ptid
= read_ptid (++p1
, &p
);
6162 else if (strprefix (p
, p1
, "watch")
6163 || strprefix (p
, p1
, "rwatch")
6164 || strprefix (p
, p1
, "awatch"))
6166 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6167 p
= unpack_varlen_hex (++p1
, &addr
);
6168 event
->watch_data_address
= (CORE_ADDR
) addr
;
6170 else if (strprefix (p
, p1
, "swbreak"))
6172 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6174 /* Make sure the stub doesn't forget to indicate support
6176 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6177 error (_("Unexpected swbreak stop reason"));
6179 /* The value part is documented as "must be empty",
6180 though we ignore it, in case we ever decide to make
6181 use of it in a backward compatible way. */
6182 p
= skip_to_semicolon (p1
+ 1);
6184 else if (strprefix (p
, p1
, "hwbreak"))
6186 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6188 /* Make sure the stub doesn't forget to indicate support
6190 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6191 error (_("Unexpected hwbreak stop reason"));
6194 p
= skip_to_semicolon (p1
+ 1);
6196 else if (strprefix (p
, p1
, "library"))
6198 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6199 p
= skip_to_semicolon (p1
+ 1);
6201 else if (strprefix (p
, p1
, "replaylog"))
6203 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6204 /* p1 will indicate "begin" or "end", but it makes
6205 no difference for now, so ignore it. */
6206 p
= skip_to_semicolon (p1
+ 1);
6208 else if (strprefix (p
, p1
, "core"))
6212 p
= unpack_varlen_hex (++p1
, &c
);
6215 else if (strprefix (p
, p1
, "fork"))
6217 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6218 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6220 else if (strprefix (p
, p1
, "vfork"))
6222 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6223 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6225 else if (strprefix (p
, p1
, "vforkdone"))
6227 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6228 p
= skip_to_semicolon (p1
+ 1);
6230 else if (strprefix (p
, p1
, "exec"))
6233 char pathname
[PATH_MAX
];
6236 /* Determine the length of the execd pathname. */
6237 p
= unpack_varlen_hex (++p1
, &ignored
);
6238 pathlen
= (p
- p1
) / 2;
6240 /* Save the pathname for event reporting and for
6241 the next run command. */
6242 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6243 pathname
[pathlen
] = '\0';
6245 /* This is freed during event handling. */
6246 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6247 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6249 /* Skip the registers included in this packet, since
6250 they may be for an architecture different from the
6251 one used by the original program. */
6261 p
= skip_to_semicolon (p1
+ 1);
6266 /* Maybe a real ``P'' register number. */
6267 p_temp
= unpack_varlen_hex (p
, &pnum
);
6268 /* If the first invalid character is the colon, we got a
6269 register number. Otherwise, it's an unknown stop
6273 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6274 cached_reg_t cached_reg
;
6277 error (_("Remote sent bad register number %s: %s\n\
6279 hex_string (pnum
), p
, buf
);
6281 cached_reg
.num
= reg
->regnum
;
6284 fieldsize
= hex2bin (p
, cached_reg
.data
,
6285 register_size (target_gdbarch (),
6288 if (fieldsize
< register_size (target_gdbarch (),
6290 warning (_("Remote reply is too short: %s"), buf
);
6292 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6296 /* Not a number. Silently skip unknown optional
6298 p
= skip_to_semicolon (p1
+ 1);
6303 error (_("Remote register badly formatted: %s\nhere: %s"),
6308 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6312 case 'S': /* Old style status, just signal only. */
6316 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6317 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6318 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6319 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6321 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6324 case 'W': /* Target exited. */
6331 /* GDB used to accept only 2 hex chars here. Stubs should
6332 only send more if they detect GDB supports multi-process
6334 p
= unpack_varlen_hex (&buf
[1], &value
);
6338 /* The remote process exited. */
6339 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6340 event
->ws
.value
.integer
= value
;
6344 /* The remote process exited with a signal. */
6345 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6346 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6347 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6349 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6352 /* If no process is specified, assume inferior_ptid. */
6353 pid
= ptid_get_pid (inferior_ptid
);
6362 else if (startswith (p
, "process:"))
6366 p
+= sizeof ("process:") - 1;
6367 unpack_varlen_hex (p
, &upid
);
6371 error (_("unknown stop reply packet: %s"), buf
);
6374 error (_("unknown stop reply packet: %s"), buf
);
6375 event
->ptid
= pid_to_ptid (pid
);
6380 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6381 error (_("No process or thread specified in stop reply: %s"), buf
);
6384 /* When the stub wants to tell GDB about a new notification reply, it
6385 sends a notification (%Stop, for example). Those can come it at
6386 any time, hence, we have to make sure that any pending
6387 putpkt/getpkt sequence we're making is finished, before querying
6388 the stub for more events with the corresponding ack command
6389 (vStopped, for example). E.g., if we started a vStopped sequence
6390 immediately upon receiving the notification, something like this
6398 1.6) <-- (registers reply to step #1.3)
6400 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6403 To solve this, whenever we parse a %Stop notification successfully,
6404 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6405 doing whatever we were doing:
6411 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6412 2.5) <-- (registers reply to step #2.3)
6414 Eventualy after step #2.5, we return to the event loop, which
6415 notices there's an event on the
6416 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6417 associated callback --- the function below. At this point, we're
6418 always safe to start a vStopped sequence. :
6421 2.7) <-- T05 thread:2
6427 remote_notif_get_pending_events (struct notif_client
*nc
)
6429 struct remote_state
*rs
= get_remote_state ();
6431 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6434 fprintf_unfiltered (gdb_stdlog
,
6435 "notif: process: '%s' ack pending event\n",
6439 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6440 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6444 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6445 if (strcmp (rs
->buf
, "OK") == 0)
6448 remote_notif_ack (nc
, rs
->buf
);
6454 fprintf_unfiltered (gdb_stdlog
,
6455 "notif: process: '%s' no pending reply\n",
6460 /* Called when it is decided that STOP_REPLY holds the info of the
6461 event that is to be returned to the core. This function always
6462 destroys STOP_REPLY. */
6465 process_stop_reply (struct stop_reply
*stop_reply
,
6466 struct target_waitstatus
*status
)
6470 *status
= stop_reply
->ws
;
6471 ptid
= stop_reply
->ptid
;
6473 /* If no thread/process was reported by the stub, assume the current
6475 if (ptid_equal (ptid
, null_ptid
))
6476 ptid
= inferior_ptid
;
6478 if (status
->kind
!= TARGET_WAITKIND_EXITED
6479 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6481 struct remote_state
*rs
= get_remote_state ();
6483 /* Expedited registers. */
6484 if (stop_reply
->regcache
)
6486 struct regcache
*regcache
6487 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6492 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6494 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6495 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6498 rs
->stop_reason
= stop_reply
->stop_reason
;
6499 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6501 remote_notice_new_inferior (ptid
, 0);
6502 demand_private_info (ptid
)->core
= stop_reply
->core
;
6505 stop_reply_xfree (stop_reply
);
6509 /* The non-stop mode version of target_wait. */
6512 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6514 struct remote_state
*rs
= get_remote_state ();
6515 struct stop_reply
*stop_reply
;
6519 /* If in non-stop mode, get out of getpkt even if a
6520 notification is received. */
6522 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6523 0 /* forever */, &is_notif
);
6526 if (ret
!= -1 && !is_notif
)
6529 case 'E': /* Error of some sort. */
6530 /* We're out of sync with the target now. Did it continue
6531 or not? We can't tell which thread it was in non-stop,
6532 so just ignore this. */
6533 warning (_("Remote failure reply: %s"), rs
->buf
);
6535 case 'O': /* Console output. */
6536 remote_console_output (rs
->buf
+ 1);
6539 warning (_("Invalid remote reply: %s"), rs
->buf
);
6543 /* Acknowledge a pending stop reply that may have arrived in the
6545 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6546 remote_notif_get_pending_events (¬if_client_stop
);
6548 /* If indeed we noticed a stop reply, we're done. */
6549 stop_reply
= queued_stop_reply (ptid
);
6550 if (stop_reply
!= NULL
)
6551 return process_stop_reply (stop_reply
, status
);
6553 /* Still no event. If we're just polling for an event, then
6554 return to the event loop. */
6555 if (options
& TARGET_WNOHANG
)
6557 status
->kind
= TARGET_WAITKIND_IGNORE
;
6558 return minus_one_ptid
;
6561 /* Otherwise do a blocking wait. */
6562 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6563 1 /* forever */, &is_notif
);
6567 /* Wait until the remote machine stops, then return, storing status in
6568 STATUS just as `wait' would. */
6571 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6573 struct remote_state
*rs
= get_remote_state ();
6574 ptid_t event_ptid
= null_ptid
;
6576 struct stop_reply
*stop_reply
;
6580 status
->kind
= TARGET_WAITKIND_IGNORE
;
6581 status
->value
.integer
= 0;
6583 stop_reply
= queued_stop_reply (ptid
);
6584 if (stop_reply
!= NULL
)
6585 return process_stop_reply (stop_reply
, status
);
6587 if (rs
->cached_wait_status
)
6588 /* Use the cached wait status, but only once. */
6589 rs
->cached_wait_status
= 0;
6594 int forever
= ((options
& TARGET_WNOHANG
) == 0
6595 && wait_forever_enabled_p
);
6597 if (!rs
->waiting_for_stop_reply
)
6599 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6600 return minus_one_ptid
;
6603 if (!target_is_async_p ())
6605 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6606 /* If the user hit C-c before this packet, or between packets,
6607 pretend that it was hit right here. */
6608 if (check_quit_flag ())
6611 sync_remote_interrupt (SIGINT
);
6615 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6616 _never_ wait for ever -> test on target_is_async_p().
6617 However, before we do that we need to ensure that the caller
6618 knows how to take the target into/out of async mode. */
6619 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6620 forever
, &is_notif
);
6622 if (!target_is_async_p ())
6623 signal (SIGINT
, ofunc
);
6625 /* GDB gets a notification. Return to core as this event is
6627 if (ret
!= -1 && is_notif
)
6628 return minus_one_ptid
;
6630 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6631 return minus_one_ptid
;
6636 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6638 /* Assume that the target has acknowledged Ctrl-C unless we receive
6639 an 'F' or 'O' packet. */
6640 if (buf
[0] != 'F' && buf
[0] != 'O')
6641 rs
->ctrlc_pending_p
= 0;
6645 case 'E': /* Error of some sort. */
6646 /* We're out of sync with the target now. Did it continue or
6647 not? Not is more likely, so report a stop. */
6648 rs
->waiting_for_stop_reply
= 0;
6650 warning (_("Remote failure reply: %s"), buf
);
6651 status
->kind
= TARGET_WAITKIND_STOPPED
;
6652 status
->value
.sig
= GDB_SIGNAL_0
;
6654 case 'F': /* File-I/O request. */
6655 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6656 rs
->ctrlc_pending_p
= 0;
6658 case 'T': case 'S': case 'X': case 'W':
6660 struct stop_reply
*stop_reply
;
6662 /* There is a stop reply to handle. */
6663 rs
->waiting_for_stop_reply
= 0;
6666 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6669 event_ptid
= process_stop_reply (stop_reply
, status
);
6672 case 'O': /* Console output. */
6673 remote_console_output (buf
+ 1);
6676 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6678 /* Zero length reply means that we tried 'S' or 'C' and the
6679 remote system doesn't support it. */
6680 target_terminal_ours_for_output ();
6682 ("Can't send signals to this remote system. %s not sent.\n",
6683 gdb_signal_to_name (rs
->last_sent_signal
));
6684 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6685 target_terminal_inferior ();
6687 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6688 putpkt ((char *) buf
);
6691 /* else fallthrough */
6693 warning (_("Invalid remote reply: %s"), buf
);
6697 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6699 /* Nothing interesting happened. If we're doing a non-blocking
6700 poll, we're done. Otherwise, go back to waiting. */
6701 if (options
& TARGET_WNOHANG
)
6702 return minus_one_ptid
;
6706 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6707 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6709 if (!ptid_equal (event_ptid
, null_ptid
))
6710 record_currthread (rs
, event_ptid
);
6712 event_ptid
= inferior_ptid
;
6715 /* A process exit. Invalidate our notion of current thread. */
6716 record_currthread (rs
, minus_one_ptid
);
6721 /* Wait until the remote machine stops, then return, storing status in
6722 STATUS just as `wait' would. */
6725 remote_wait (struct target_ops
*ops
,
6726 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6731 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6733 event_ptid
= remote_wait_as (ptid
, status
, options
);
6735 if (target_is_async_p ())
6737 /* If there are are events left in the queue tell the event loop
6739 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6740 mark_async_event_handler (remote_async_inferior_event_token
);
6746 /* Fetch a single register using a 'p' packet. */
6749 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6751 struct remote_state
*rs
= get_remote_state ();
6753 char regp
[MAX_REGISTER_SIZE
];
6756 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6759 if (reg
->pnum
== -1)
6764 p
+= hexnumstr (p
, reg
->pnum
);
6767 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6771 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6775 case PACKET_UNKNOWN
:
6778 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6779 gdbarch_register_name (get_regcache_arch (regcache
),
6784 /* If this register is unfetchable, tell the regcache. */
6787 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6791 /* Otherwise, parse and supply the value. */
6797 error (_("fetch_register_using_p: early buf termination"));
6799 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6802 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6806 /* Fetch the registers included in the target's 'g' packet. */
6809 send_g_packet (void)
6811 struct remote_state
*rs
= get_remote_state ();
6814 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6815 remote_send (&rs
->buf
, &rs
->buf_size
);
6817 /* We can get out of synch in various cases. If the first character
6818 in the buffer is not a hex character, assume that has happened
6819 and try to fetch another packet to read. */
6820 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6821 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6822 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6823 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6826 fprintf_unfiltered (gdb_stdlog
,
6827 "Bad register packet; fetching a new packet\n");
6828 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6831 buf_len
= strlen (rs
->buf
);
6833 /* Sanity check the received packet. */
6834 if (buf_len
% 2 != 0)
6835 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6841 process_g_packet (struct regcache
*regcache
)
6843 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6844 struct remote_state
*rs
= get_remote_state ();
6845 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6850 buf_len
= strlen (rs
->buf
);
6852 /* Further sanity checks, with knowledge of the architecture. */
6853 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6854 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6856 /* Save the size of the packet sent to us by the target. It is used
6857 as a heuristic when determining the max size of packets that the
6858 target can safely receive. */
6859 if (rsa
->actual_register_packet_size
== 0)
6860 rsa
->actual_register_packet_size
= buf_len
;
6862 /* If this is smaller than we guessed the 'g' packet would be,
6863 update our records. A 'g' reply that doesn't include a register's
6864 value implies either that the register is not available, or that
6865 the 'p' packet must be used. */
6866 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6868 rsa
->sizeof_g_packet
= buf_len
/ 2;
6870 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6872 if (rsa
->regs
[i
].pnum
== -1)
6875 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6876 rsa
->regs
[i
].in_g_packet
= 0;
6878 rsa
->regs
[i
].in_g_packet
= 1;
6882 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
6884 /* Unimplemented registers read as all bits zero. */
6885 memset (regs
, 0, rsa
->sizeof_g_packet
);
6887 /* Reply describes registers byte by byte, each byte encoded as two
6888 hex characters. Suck them all up, then supply them to the
6889 register cacheing/storage mechanism. */
6892 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6894 if (p
[0] == 0 || p
[1] == 0)
6895 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6896 internal_error (__FILE__
, __LINE__
,
6897 _("unexpected end of 'g' packet reply"));
6899 if (p
[0] == 'x' && p
[1] == 'x')
6900 regs
[i
] = 0; /* 'x' */
6902 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6906 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6908 struct packet_reg
*r
= &rsa
->regs
[i
];
6912 if (r
->offset
* 2 >= strlen (rs
->buf
))
6913 /* This shouldn't happen - we adjusted in_g_packet above. */
6914 internal_error (__FILE__
, __LINE__
,
6915 _("unexpected end of 'g' packet reply"));
6916 else if (rs
->buf
[r
->offset
* 2] == 'x')
6918 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6919 /* The register isn't available, mark it as such (at
6920 the same time setting the value to zero). */
6921 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6924 regcache_raw_supply (regcache
, r
->regnum
,
6931 fetch_registers_using_g (struct regcache
*regcache
)
6934 process_g_packet (regcache
);
6937 /* Make the remote selected traceframe match GDB's selected
6941 set_remote_traceframe (void)
6944 struct remote_state
*rs
= get_remote_state ();
6946 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6949 /* Avoid recursion, remote_trace_find calls us again. */
6950 rs
->remote_traceframe_number
= get_traceframe_number ();
6952 newnum
= target_trace_find (tfind_number
,
6953 get_traceframe_number (), 0, 0, NULL
);
6955 /* Should not happen. If it does, all bets are off. */
6956 if (newnum
!= get_traceframe_number ())
6957 warning (_("could not set remote traceframe"));
6961 remote_fetch_registers (struct target_ops
*ops
,
6962 struct regcache
*regcache
, int regnum
)
6964 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6967 set_remote_traceframe ();
6968 set_general_thread (inferior_ptid
);
6972 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6974 gdb_assert (reg
!= NULL
);
6976 /* If this register might be in the 'g' packet, try that first -
6977 we are likely to read more than one register. If this is the
6978 first 'g' packet, we might be overly optimistic about its
6979 contents, so fall back to 'p'. */
6980 if (reg
->in_g_packet
)
6982 fetch_registers_using_g (regcache
);
6983 if (reg
->in_g_packet
)
6987 if (fetch_register_using_p (regcache
, reg
))
6990 /* This register is not available. */
6991 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6996 fetch_registers_using_g (regcache
);
6998 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6999 if (!rsa
->regs
[i
].in_g_packet
)
7000 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7002 /* This register is not available. */
7003 regcache_raw_supply (regcache
, i
, NULL
);
7007 /* Prepare to store registers. Since we may send them all (using a
7008 'G' request), we have to read out the ones we don't want to change
7012 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7014 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7016 gdb_byte buf
[MAX_REGISTER_SIZE
];
7018 /* Make sure the entire registers array is valid. */
7019 switch (packet_support (PACKET_P
))
7021 case PACKET_DISABLE
:
7022 case PACKET_SUPPORT_UNKNOWN
:
7023 /* Make sure all the necessary registers are cached. */
7024 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7025 if (rsa
->regs
[i
].in_g_packet
)
7026 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7033 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7034 packet was not recognized. */
7037 store_register_using_P (const struct regcache
*regcache
,
7038 struct packet_reg
*reg
)
7040 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7041 struct remote_state
*rs
= get_remote_state ();
7042 /* Try storing a single register. */
7043 char *buf
= rs
->buf
;
7044 gdb_byte regp
[MAX_REGISTER_SIZE
];
7047 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7050 if (reg
->pnum
== -1)
7053 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7054 p
= buf
+ strlen (buf
);
7055 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7056 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7058 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7060 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7065 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7066 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7067 case PACKET_UNKNOWN
:
7070 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7074 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7075 contents of the register cache buffer. FIXME: ignores errors. */
7078 store_registers_using_G (const struct regcache
*regcache
)
7080 struct remote_state
*rs
= get_remote_state ();
7081 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7085 /* Extract all the registers in the regcache copying them into a
7090 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7091 memset (regs
, 0, rsa
->sizeof_g_packet
);
7092 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7094 struct packet_reg
*r
= &rsa
->regs
[i
];
7097 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7101 /* Command describes registers byte by byte,
7102 each byte encoded as two hex characters. */
7105 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7107 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7109 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7110 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7111 error (_("Could not write registers; remote failure reply '%s'"),
7115 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7116 of the register cache buffer. FIXME: ignores errors. */
7119 remote_store_registers (struct target_ops
*ops
,
7120 struct regcache
*regcache
, int regnum
)
7122 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7125 set_remote_traceframe ();
7126 set_general_thread (inferior_ptid
);
7130 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7132 gdb_assert (reg
!= NULL
);
7134 /* Always prefer to store registers using the 'P' packet if
7135 possible; we often change only a small number of registers.
7136 Sometimes we change a larger number; we'd need help from a
7137 higher layer to know to use 'G'. */
7138 if (store_register_using_P (regcache
, reg
))
7141 /* For now, don't complain if we have no way to write the
7142 register. GDB loses track of unavailable registers too
7143 easily. Some day, this may be an error. We don't have
7144 any way to read the register, either... */
7145 if (!reg
->in_g_packet
)
7148 store_registers_using_G (regcache
);
7152 store_registers_using_G (regcache
);
7154 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7155 if (!rsa
->regs
[i
].in_g_packet
)
7156 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7157 /* See above for why we do not issue an error here. */
7162 /* Return the number of hex digits in num. */
7165 hexnumlen (ULONGEST num
)
7169 for (i
= 0; num
!= 0; i
++)
7175 /* Set BUF to the minimum number of hex digits representing NUM. */
7178 hexnumstr (char *buf
, ULONGEST num
)
7180 int len
= hexnumlen (num
);
7182 return hexnumnstr (buf
, num
, len
);
7186 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7189 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7195 for (i
= width
- 1; i
>= 0; i
--)
7197 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7204 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7207 remote_address_masked (CORE_ADDR addr
)
7209 unsigned int address_size
= remote_address_size
;
7211 /* If "remoteaddresssize" was not set, default to target address size. */
7213 address_size
= gdbarch_addr_bit (target_gdbarch ());
7215 if (address_size
> 0
7216 && address_size
< (sizeof (ULONGEST
) * 8))
7218 /* Only create a mask when that mask can safely be constructed
7219 in a ULONGEST variable. */
7222 mask
= (mask
<< address_size
) - 1;
7228 /* Determine whether the remote target supports binary downloading.
7229 This is accomplished by sending a no-op memory write of zero length
7230 to the target at the specified address. It does not suffice to send
7231 the whole packet, since many stubs strip the eighth bit and
7232 subsequently compute a wrong checksum, which causes real havoc with
7235 NOTE: This can still lose if the serial line is not eight-bit
7236 clean. In cases like this, the user should clear "remote
7240 check_binary_download (CORE_ADDR addr
)
7242 struct remote_state
*rs
= get_remote_state ();
7244 switch (packet_support (PACKET_X
))
7246 case PACKET_DISABLE
:
7250 case PACKET_SUPPORT_UNKNOWN
:
7256 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7258 p
+= hexnumstr (p
, (ULONGEST
) 0);
7262 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7263 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7265 if (rs
->buf
[0] == '\0')
7268 fprintf_unfiltered (gdb_stdlog
,
7269 "binary downloading NOT "
7270 "supported by target\n");
7271 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7276 fprintf_unfiltered (gdb_stdlog
,
7277 "binary downloading supported by target\n");
7278 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7285 /* Helper function to resize the payload in order to try to get a good
7286 alignment. We try to write an amount of data such that the next write will
7287 start on an address aligned on REMOTE_ALIGN_WRITES. */
7290 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7292 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7295 /* Write memory data directly to the remote machine.
7296 This does not inform the data cache; the data cache uses this.
7297 HEADER is the starting part of the packet.
7298 MEMADDR is the address in the remote memory space.
7299 MYADDR is the address of the buffer in our space.
7300 LEN_UNITS is the number of addressable units to write.
7301 UNIT_SIZE is the length in bytes of an addressable unit.
7302 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7303 should send data as binary ('X'), or hex-encoded ('M').
7305 The function creates packet of the form
7306 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7308 where encoding of <DATA> is terminated by PACKET_FORMAT.
7310 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7313 Return the transferred status, error or OK (an
7314 'enum target_xfer_status' value). Save the number of addressable units
7315 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7317 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7318 exchange between gdb and the stub could look like (?? in place of the
7324 -> $M1000,3:eeeeffffeeee#??
7328 <- eeeeffffeeeedddd */
7330 static enum target_xfer_status
7331 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7332 const gdb_byte
*myaddr
, ULONGEST len_units
,
7333 int unit_size
, ULONGEST
*xfered_len_units
,
7334 char packet_format
, int use_length
)
7336 struct remote_state
*rs
= get_remote_state ();
7342 int payload_capacity_bytes
;
7343 int payload_length_bytes
;
7345 if (packet_format
!= 'X' && packet_format
!= 'M')
7346 internal_error (__FILE__
, __LINE__
,
7347 _("remote_write_bytes_aux: bad packet format"));
7350 return TARGET_XFER_EOF
;
7352 payload_capacity_bytes
= get_memory_write_packet_size ();
7354 /* The packet buffer will be large enough for the payload;
7355 get_memory_packet_size ensures this. */
7358 /* Compute the size of the actual payload by subtracting out the
7359 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7361 payload_capacity_bytes
-= strlen ("$,:#NN");
7363 /* The comma won't be used. */
7364 payload_capacity_bytes
+= 1;
7365 payload_capacity_bytes
-= strlen (header
);
7366 payload_capacity_bytes
-= hexnumlen (memaddr
);
7368 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7370 strcat (rs
->buf
, header
);
7371 p
= rs
->buf
+ strlen (header
);
7373 /* Compute a best guess of the number of bytes actually transfered. */
7374 if (packet_format
== 'X')
7376 /* Best guess at number of bytes that will fit. */
7377 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7379 payload_capacity_bytes
-= hexnumlen (todo_units
);
7380 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7384 /* Number of bytes that will fit. */
7385 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7387 payload_capacity_bytes
-= hexnumlen (todo_units
);
7388 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7391 if (todo_units
<= 0)
7392 internal_error (__FILE__
, __LINE__
,
7393 _("minimum packet size too small to write data"));
7395 /* If we already need another packet, then try to align the end
7396 of this packet to a useful boundary. */
7397 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7398 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7400 /* Append "<memaddr>". */
7401 memaddr
= remote_address_masked (memaddr
);
7402 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7409 /* Append the length and retain its location and size. It may need to be
7410 adjusted once the packet body has been created. */
7412 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7420 /* Append the packet body. */
7421 if (packet_format
== 'X')
7423 /* Binary mode. Send target system values byte by byte, in
7424 increasing byte addresses. Only escape certain critical
7426 payload_length_bytes
=
7427 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7428 &units_written
, payload_capacity_bytes
);
7430 /* If not all TODO units fit, then we'll need another packet. Make
7431 a second try to keep the end of the packet aligned. Don't do
7432 this if the packet is tiny. */
7433 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7437 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7439 if (new_todo_units
!= units_written
)
7440 payload_length_bytes
=
7441 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7442 (gdb_byte
*) p
, &units_written
,
7443 payload_capacity_bytes
);
7446 p
+= payload_length_bytes
;
7447 if (use_length
&& units_written
< todo_units
)
7449 /* Escape chars have filled up the buffer prematurely,
7450 and we have actually sent fewer units than planned.
7451 Fix-up the length field of the packet. Use the same
7452 number of characters as before. */
7453 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7455 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7460 /* Normal mode: Send target system values byte by byte, in
7461 increasing byte addresses. Each byte is encoded as a two hex
7463 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7464 units_written
= todo_units
;
7467 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7470 if (rs
->buf
[0] == 'E')
7471 return TARGET_XFER_E_IO
;
7473 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7474 send fewer units than we'd planned. */
7475 *xfered_len_units
= (ULONGEST
) units_written
;
7476 return TARGET_XFER_OK
;
7479 /* Write memory data directly to the remote machine.
7480 This does not inform the data cache; the data cache uses this.
7481 MEMADDR is the address in the remote memory space.
7482 MYADDR is the address of the buffer in our space.
7483 LEN is the number of bytes.
7485 Return the transferred status, error or OK (an
7486 'enum target_xfer_status' value). Save the number of bytes
7487 transferred in *XFERED_LEN. Only transfer a single packet. */
7489 static enum target_xfer_status
7490 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7491 int unit_size
, ULONGEST
*xfered_len
)
7493 char *packet_format
= 0;
7495 /* Check whether the target supports binary download. */
7496 check_binary_download (memaddr
);
7498 switch (packet_support (PACKET_X
))
7501 packet_format
= "X";
7503 case PACKET_DISABLE
:
7504 packet_format
= "M";
7506 case PACKET_SUPPORT_UNKNOWN
:
7507 internal_error (__FILE__
, __LINE__
,
7508 _("remote_write_bytes: bad internal state"));
7510 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7513 return remote_write_bytes_aux (packet_format
,
7514 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7515 packet_format
[0], 1);
7518 /* Read memory data directly from the remote machine.
7519 This does not use the data cache; the data cache uses this.
7520 MEMADDR is the address in the remote memory space.
7521 MYADDR is the address of the buffer in our space.
7522 LEN_UNITS is the number of addressable memory units to read..
7523 UNIT_SIZE is the length in bytes of an addressable unit.
7525 Return the transferred status, error or OK (an
7526 'enum target_xfer_status' value). Save the number of bytes
7527 transferred in *XFERED_LEN_UNITS.
7529 See the comment of remote_write_bytes_aux for an example of
7530 memory read/write exchange between gdb and the stub. */
7532 static enum target_xfer_status
7533 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7534 int unit_size
, ULONGEST
*xfered_len_units
)
7536 struct remote_state
*rs
= get_remote_state ();
7537 int buf_size_bytes
; /* Max size of packet output buffer. */
7542 buf_size_bytes
= get_memory_read_packet_size ();
7543 /* The packet buffer will be large enough for the payload;
7544 get_memory_packet_size ensures this. */
7546 /* Number of units that will fit. */
7547 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7549 /* Construct "m"<memaddr>","<len>". */
7550 memaddr
= remote_address_masked (memaddr
);
7553 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7555 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7558 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7559 if (rs
->buf
[0] == 'E'
7560 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7561 && rs
->buf
[3] == '\0')
7562 return TARGET_XFER_E_IO
;
7563 /* Reply describes memory byte by byte, each byte encoded as two hex
7566 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7567 /* Return what we have. Let higher layers handle partial reads. */
7568 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7569 return TARGET_XFER_OK
;
7572 /* Using the set of read-only target sections of remote, read live
7575 For interface/parameters/return description see target.h,
7578 static enum target_xfer_status
7579 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7580 ULONGEST memaddr
, ULONGEST len
,
7581 int unit_size
, ULONGEST
*xfered_len
)
7583 struct target_section
*secp
;
7584 struct target_section_table
*table
;
7586 secp
= target_section_by_addr (ops
, memaddr
);
7588 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7589 secp
->the_bfd_section
)
7592 struct target_section
*p
;
7593 ULONGEST memend
= memaddr
+ len
;
7595 table
= target_get_section_table (ops
);
7597 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7599 if (memaddr
>= p
->addr
)
7601 if (memend
<= p
->endaddr
)
7603 /* Entire transfer is within this section. */
7604 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7607 else if (memaddr
>= p
->endaddr
)
7609 /* This section ends before the transfer starts. */
7614 /* This section overlaps the transfer. Just do half. */
7615 len
= p
->endaddr
- memaddr
;
7616 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7623 return TARGET_XFER_EOF
;
7626 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7627 first if the requested memory is unavailable in traceframe.
7628 Otherwise, fall back to remote_read_bytes_1. */
7630 static enum target_xfer_status
7631 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7632 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7633 ULONGEST
*xfered_len
)
7636 return TARGET_XFER_EOF
;
7638 if (get_traceframe_number () != -1)
7640 VEC(mem_range_s
) *available
;
7642 /* If we fail to get the set of available memory, then the
7643 target does not support querying traceframe info, and so we
7644 attempt reading from the traceframe anyway (assuming the
7645 target implements the old QTro packet then). */
7646 if (traceframe_available_memory (&available
, memaddr
, len
))
7648 struct cleanup
*old_chain
;
7650 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7652 if (VEC_empty (mem_range_s
, available
)
7653 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7655 enum target_xfer_status res
;
7657 /* Don't read into the traceframe's available
7659 if (!VEC_empty (mem_range_s
, available
))
7661 LONGEST oldlen
= len
;
7663 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7664 gdb_assert (len
<= oldlen
);
7667 do_cleanups (old_chain
);
7669 /* This goes through the topmost target again. */
7670 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7671 len
, unit_size
, xfered_len
);
7672 if (res
== TARGET_XFER_OK
)
7673 return TARGET_XFER_OK
;
7676 /* No use trying further, we know some memory starting
7677 at MEMADDR isn't available. */
7679 return TARGET_XFER_UNAVAILABLE
;
7683 /* Don't try to read more than how much is available, in
7684 case the target implements the deprecated QTro packet to
7685 cater for older GDBs (the target's knowledge of read-only
7686 sections may be outdated by now). */
7687 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7689 do_cleanups (old_chain
);
7693 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7698 /* Sends a packet with content determined by the printf format string
7699 FORMAT and the remaining arguments, then gets the reply. Returns
7700 whether the packet was a success, a failure, or unknown. */
7702 static enum packet_result
remote_send_printf (const char *format
, ...)
7703 ATTRIBUTE_PRINTF (1, 2);
7705 static enum packet_result
7706 remote_send_printf (const char *format
, ...)
7708 struct remote_state
*rs
= get_remote_state ();
7709 int max_size
= get_remote_packet_size ();
7712 va_start (ap
, format
);
7715 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7716 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7718 if (putpkt (rs
->buf
) < 0)
7719 error (_("Communication problem with target."));
7722 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7724 return packet_check_result (rs
->buf
);
7728 restore_remote_timeout (void *p
)
7730 int value
= *(int *)p
;
7732 remote_timeout
= value
;
7735 /* Flash writing can take quite some time. We'll set
7736 effectively infinite timeout for flash operations.
7737 In future, we'll need to decide on a better approach. */
7738 static const int remote_flash_timeout
= 1000;
7741 remote_flash_erase (struct target_ops
*ops
,
7742 ULONGEST address
, LONGEST length
)
7744 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7745 int saved_remote_timeout
= remote_timeout
;
7746 enum packet_result ret
;
7747 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7748 &saved_remote_timeout
);
7750 remote_timeout
= remote_flash_timeout
;
7752 ret
= remote_send_printf ("vFlashErase:%s,%s",
7753 phex (address
, addr_size
),
7757 case PACKET_UNKNOWN
:
7758 error (_("Remote target does not support flash erase"));
7760 error (_("Error erasing flash with vFlashErase packet"));
7765 do_cleanups (back_to
);
7768 static enum target_xfer_status
7769 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7770 ULONGEST length
, ULONGEST
*xfered_len
,
7771 const gdb_byte
*data
)
7773 int saved_remote_timeout
= remote_timeout
;
7774 enum target_xfer_status ret
;
7775 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7776 &saved_remote_timeout
);
7778 remote_timeout
= remote_flash_timeout
;
7779 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7781 do_cleanups (back_to
);
7787 remote_flash_done (struct target_ops
*ops
)
7789 int saved_remote_timeout
= remote_timeout
;
7791 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7792 &saved_remote_timeout
);
7794 remote_timeout
= remote_flash_timeout
;
7795 ret
= remote_send_printf ("vFlashDone");
7796 do_cleanups (back_to
);
7800 case PACKET_UNKNOWN
:
7801 error (_("Remote target does not support vFlashDone"));
7803 error (_("Error finishing flash operation"));
7810 remote_files_info (struct target_ops
*ignore
)
7812 puts_filtered ("Debugging a target over a serial line.\n");
7815 /* Stuff for dealing with the packets which are part of this protocol.
7816 See comment at top of file for details. */
7818 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7819 error to higher layers. Called when a serial error is detected.
7820 The exception message is STRING, followed by a colon and a blank,
7821 the system error message for errno at function entry and final dot
7822 for output compatibility with throw_perror_with_name. */
7825 unpush_and_perror (const char *string
)
7827 int saved_errno
= errno
;
7829 remote_unpush_target ();
7830 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7831 safe_strerror (saved_errno
));
7834 /* Read a single character from the remote end. */
7837 readchar (int timeout
)
7840 struct remote_state
*rs
= get_remote_state ();
7842 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7847 switch ((enum serial_rc
) ch
)
7850 remote_unpush_target ();
7851 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7854 unpush_and_perror (_("Remote communication error. "
7855 "Target disconnected."));
7857 case SERIAL_TIMEOUT
:
7863 /* Wrapper for serial_write that closes the target and throws if
7867 remote_serial_write (const char *str
, int len
)
7869 struct remote_state
*rs
= get_remote_state ();
7871 if (serial_write (rs
->remote_desc
, str
, len
))
7873 unpush_and_perror (_("Remote communication error. "
7874 "Target disconnected."));
7878 /* Send the command in *BUF to the remote machine, and read the reply
7879 into *BUF. Report an error if we get an error reply. Resize
7880 *BUF using xrealloc if necessary to hold the result, and update
7884 remote_send (char **buf
,
7888 getpkt (buf
, sizeof_buf
, 0);
7890 if ((*buf
)[0] == 'E')
7891 error (_("Remote failure reply: %s"), *buf
);
7894 /* Return a pointer to an xmalloc'ed string representing an escaped
7895 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7896 etc. The caller is responsible for releasing the returned
7900 escape_buffer (const char *buf
, int n
)
7902 struct cleanup
*old_chain
;
7903 struct ui_file
*stb
;
7906 stb
= mem_fileopen ();
7907 old_chain
= make_cleanup_ui_file_delete (stb
);
7909 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7910 str
= ui_file_xstrdup (stb
, NULL
);
7911 do_cleanups (old_chain
);
7915 /* Display a null-terminated packet on stdout, for debugging, using C
7919 print_packet (const char *buf
)
7921 puts_filtered ("\"");
7922 fputstr_filtered (buf
, '"', gdb_stdout
);
7923 puts_filtered ("\"");
7927 putpkt (const char *buf
)
7929 return putpkt_binary (buf
, strlen (buf
));
7932 /* Send a packet to the remote machine, with error checking. The data
7933 of the packet is in BUF. The string in BUF can be at most
7934 get_remote_packet_size () - 5 to account for the $, # and checksum,
7935 and for a possible /0 if we are debugging (remote_debug) and want
7936 to print the sent packet as a string. */
7939 putpkt_binary (const char *buf
, int cnt
)
7941 struct remote_state
*rs
= get_remote_state ();
7943 unsigned char csum
= 0;
7944 char *buf2
= (char *) xmalloc (cnt
+ 6);
7945 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
7952 /* Catch cases like trying to read memory or listing threads while
7953 we're waiting for a stop reply. The remote server wouldn't be
7954 ready to handle this request, so we'd hang and timeout. We don't
7955 have to worry about this in synchronous mode, because in that
7956 case it's not possible to issue a command while the target is
7957 running. This is not a problem in non-stop mode, because in that
7958 case, the stub is always ready to process serial input. */
7959 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7961 error (_("Cannot execute this command while the target is running.\n"
7962 "Use the \"interrupt\" command to stop the target\n"
7963 "and then try again."));
7966 /* We're sending out a new packet. Make sure we don't look at a
7967 stale cached response. */
7968 rs
->cached_wait_status
= 0;
7970 /* Copy the packet into buffer BUF2, encapsulating it
7971 and giving it a checksum. */
7976 for (i
= 0; i
< cnt
; i
++)
7982 *p
++ = tohex ((csum
>> 4) & 0xf);
7983 *p
++ = tohex (csum
& 0xf);
7985 /* Send it over and over until we get a positive ack. */
7989 int started_error_output
= 0;
7993 struct cleanup
*old_chain
;
7997 str
= escape_buffer (buf2
, p
- buf2
);
7998 old_chain
= make_cleanup (xfree
, str
);
7999 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8000 gdb_flush (gdb_stdlog
);
8001 do_cleanups (old_chain
);
8003 remote_serial_write (buf2
, p
- buf2
);
8005 /* If this is a no acks version of the remote protocol, send the
8006 packet and move on. */
8010 /* Read until either a timeout occurs (-2) or '+' is read.
8011 Handle any notification that arrives in the mean time. */
8014 ch
= readchar (remote_timeout
);
8022 case SERIAL_TIMEOUT
:
8025 if (started_error_output
)
8027 putchar_unfiltered ('\n');
8028 started_error_output
= 0;
8037 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8038 do_cleanups (old_chain
);
8042 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8044 case SERIAL_TIMEOUT
:
8048 do_cleanups (old_chain
);
8051 break; /* Retransmit buffer. */
8055 fprintf_unfiltered (gdb_stdlog
,
8056 "Packet instead of Ack, ignoring it\n");
8057 /* It's probably an old response sent because an ACK
8058 was lost. Gobble up the packet and ack it so it
8059 doesn't get retransmitted when we resend this
8062 remote_serial_write ("+", 1);
8063 continue; /* Now, go look for +. */
8070 /* If we got a notification, handle it, and go back to looking
8072 /* We've found the start of a notification. Now
8073 collect the data. */
8074 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8079 struct cleanup
*old_chain
;
8082 str
= escape_buffer (rs
->buf
, val
);
8083 old_chain
= make_cleanup (xfree
, str
);
8084 fprintf_unfiltered (gdb_stdlog
,
8085 " Notification received: %s\n",
8087 do_cleanups (old_chain
);
8089 handle_notification (rs
->notif_state
, rs
->buf
);
8090 /* We're in sync now, rewait for the ack. */
8097 if (!started_error_output
)
8099 started_error_output
= 1;
8100 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8102 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8103 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8112 if (!started_error_output
)
8114 started_error_output
= 1;
8115 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8117 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8121 break; /* Here to retransmit. */
8125 /* This is wrong. If doing a long backtrace, the user should be
8126 able to get out next time we call QUIT, without anything as
8127 violent as interrupt_query. If we want to provide a way out of
8128 here without getting to the next QUIT, it should be based on
8129 hitting ^C twice as in remote_wait. */
8138 do_cleanups (old_chain
);
8142 /* Come here after finding the start of a frame when we expected an
8143 ack. Do our best to discard the rest of this packet. */
8152 c
= readchar (remote_timeout
);
8155 case SERIAL_TIMEOUT
:
8156 /* Nothing we can do. */
8159 /* Discard the two bytes of checksum and stop. */
8160 c
= readchar (remote_timeout
);
8162 c
= readchar (remote_timeout
);
8165 case '*': /* Run length encoding. */
8166 /* Discard the repeat count. */
8167 c
= readchar (remote_timeout
);
8172 /* A regular character. */
8178 /* Come here after finding the start of the frame. Collect the rest
8179 into *BUF, verifying the checksum, length, and handling run-length
8180 compression. NUL terminate the buffer. If there is not enough room,
8181 expand *BUF using xrealloc.
8183 Returns -1 on error, number of characters in buffer (ignoring the
8184 trailing NULL) on success. (could be extended to return one of the
8185 SERIAL status indications). */
8188 read_frame (char **buf_p
,
8195 struct remote_state
*rs
= get_remote_state ();
8202 c
= readchar (remote_timeout
);
8205 case SERIAL_TIMEOUT
:
8207 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8211 fputs_filtered ("Saw new packet start in middle of old one\n",
8213 return -1; /* Start a new packet, count retries. */
8216 unsigned char pktcsum
;
8222 check_0
= readchar (remote_timeout
);
8224 check_1
= readchar (remote_timeout
);
8226 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8229 fputs_filtered ("Timeout in checksum, retrying\n",
8233 else if (check_0
< 0 || check_1
< 0)
8236 fputs_filtered ("Communication error in checksum\n",
8241 /* Don't recompute the checksum; with no ack packets we
8242 don't have any way to indicate a packet retransmission
8247 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8248 if (csum
== pktcsum
)
8253 struct cleanup
*old_chain
;
8256 str
= escape_buffer (buf
, bc
);
8257 old_chain
= make_cleanup (xfree
, str
);
8258 fprintf_unfiltered (gdb_stdlog
,
8259 "Bad checksum, sentsum=0x%x, "
8260 "csum=0x%x, buf=%s\n",
8261 pktcsum
, csum
, str
);
8262 do_cleanups (old_chain
);
8264 /* Number of characters in buffer ignoring trailing
8268 case '*': /* Run length encoding. */
8273 c
= readchar (remote_timeout
);
8275 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8277 /* The character before ``*'' is repeated. */
8279 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8281 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8283 /* Make some more room in the buffer. */
8284 *sizeof_buf
+= repeat
;
8285 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8289 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8295 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8299 if (bc
>= *sizeof_buf
- 1)
8301 /* Make some more room in the buffer. */
8303 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8314 /* Read a packet from the remote machine, with error checking, and
8315 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8316 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8317 rather than timing out; this is used (in synchronous mode) to wait
8318 for a target that is is executing user code to stop. */
8319 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8320 don't have to change all the calls to getpkt to deal with the
8321 return value, because at the moment I don't know what the right
8322 thing to do it for those. */
8330 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
8334 /* Read a packet from the remote machine, with error checking, and
8335 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8336 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8337 rather than timing out; this is used (in synchronous mode) to wait
8338 for a target that is is executing user code to stop. If FOREVER ==
8339 0, this function is allowed to time out gracefully and return an
8340 indication of this to the caller. Otherwise return the number of
8341 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8342 enough reason to return to the caller. *IS_NOTIF is an output
8343 boolean that indicates whether *BUF holds a notification or not
8344 (a regular packet). */
8347 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8348 int expecting_notif
, int *is_notif
)
8350 struct remote_state
*rs
= get_remote_state ();
8356 /* We're reading a new response. Make sure we don't look at a
8357 previously cached response. */
8358 rs
->cached_wait_status
= 0;
8360 strcpy (*buf
, "timeout");
8363 timeout
= watchdog
> 0 ? watchdog
: -1;
8364 else if (expecting_notif
)
8365 timeout
= 0; /* There should already be a char in the buffer. If
8368 timeout
= remote_timeout
;
8372 /* Process any number of notifications, and then return when
8376 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8378 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8380 /* This can loop forever if the remote side sends us
8381 characters continuously, but if it pauses, we'll get
8382 SERIAL_TIMEOUT from readchar because of timeout. Then
8383 we'll count that as a retry.
8385 Note that even when forever is set, we will only wait
8386 forever prior to the start of a packet. After that, we
8387 expect characters to arrive at a brisk pace. They should
8388 show up within remote_timeout intervals. */
8390 c
= readchar (timeout
);
8391 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8393 if (c
== SERIAL_TIMEOUT
)
8395 if (expecting_notif
)
8396 return -1; /* Don't complain, it's normal to not get
8397 anything in this case. */
8399 if (forever
) /* Watchdog went off? Kill the target. */
8402 remote_unpush_target ();
8403 throw_error (TARGET_CLOSE_ERROR
,
8404 _("Watchdog timeout has expired. "
8405 "Target detached."));
8408 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8412 /* We've found the start of a packet or notification.
8413 Now collect the data. */
8414 val
= read_frame (buf
, sizeof_buf
);
8419 remote_serial_write ("-", 1);
8422 if (tries
> MAX_TRIES
)
8424 /* We have tried hard enough, and just can't receive the
8425 packet/notification. Give up. */
8426 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8428 /* Skip the ack char if we're in no-ack mode. */
8429 if (!rs
->noack_mode
)
8430 remote_serial_write ("+", 1);
8434 /* If we got an ordinary packet, return that to our caller. */
8439 struct cleanup
*old_chain
;
8442 str
= escape_buffer (*buf
, val
);
8443 old_chain
= make_cleanup (xfree
, str
);
8444 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8445 do_cleanups (old_chain
);
8448 /* Skip the ack char if we're in no-ack mode. */
8449 if (!rs
->noack_mode
)
8450 remote_serial_write ("+", 1);
8451 if (is_notif
!= NULL
)
8456 /* If we got a notification, handle it, and go back to looking
8460 gdb_assert (c
== '%');
8464 struct cleanup
*old_chain
;
8467 str
= escape_buffer (*buf
, val
);
8468 old_chain
= make_cleanup (xfree
, str
);
8469 fprintf_unfiltered (gdb_stdlog
,
8470 " Notification received: %s\n",
8472 do_cleanups (old_chain
);
8474 if (is_notif
!= NULL
)
8477 handle_notification (rs
->notif_state
, *buf
);
8479 /* Notifications require no acknowledgement. */
8481 if (expecting_notif
)
8488 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8490 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8494 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8497 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8501 /* Check whether EVENT is a fork event for the process specified
8502 by the pid passed in DATA, and if it is, kill the fork child. */
8505 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8506 QUEUE_ITER (stop_reply_p
) *iter
,
8510 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8511 int parent_pid
= *(int *) param
->input
;
8513 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8515 struct remote_state
*rs
= get_remote_state ();
8516 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8519 res
= remote_vkill (child_pid
, rs
);
8521 error (_("Can't kill fork child process %d"), child_pid
);
8527 /* Kill any new fork children of process PID that haven't been
8528 processed by follow_fork. */
8531 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8533 struct thread_info
*thread
;
8534 struct notif_client
*notif
= ¬if_client_stop
;
8535 struct queue_iter_param param
;
8537 /* Kill the fork child threads of any threads in process PID
8538 that are stopped at a fork event. */
8539 ALL_NON_EXITED_THREADS (thread
)
8541 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8543 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8545 struct remote_state
*rs
= get_remote_state ();
8546 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8549 res
= remote_vkill (child_pid
, rs
);
8551 error (_("Can't kill fork child process %d"), child_pid
);
8555 /* Check for any pending fork events (not reported or processed yet)
8556 in process PID and kill those fork child threads as well. */
8557 remote_notif_get_pending_events (notif
);
8559 param
.output
= NULL
;
8560 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8561 kill_child_of_pending_fork
, ¶m
);
8566 remote_kill (struct target_ops
*ops
)
8569 /* Catch errors so the user can quit from gdb even when we
8570 aren't on speaking terms with the remote system. */
8575 CATCH (ex
, RETURN_MASK_ERROR
)
8577 if (ex
.error
== TARGET_CLOSE_ERROR
)
8579 /* If we got an (EOF) error that caused the target
8580 to go away, then we're done, that's what we wanted.
8581 "k" is susceptible to cause a premature EOF, given
8582 that the remote server isn't actually required to
8583 reply to "k", and it can happen that it doesn't
8584 even get to reply ACK to the "k". */
8588 /* Otherwise, something went wrong. We didn't actually kill
8589 the target. Just propagate the exception, and let the
8590 user or higher layers decide what to do. */
8591 throw_exception (ex
);
8595 /* We've killed the remote end, we get to mourn it. Since this is
8596 target remote, single-process, mourning the inferior also
8597 unpushes remote_ops. */
8598 target_mourn_inferior ();
8602 remote_vkill (int pid
, struct remote_state
*rs
)
8604 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8607 /* Tell the remote target to detach. */
8608 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8610 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8612 switch (packet_ok (rs
->buf
,
8613 &remote_protocol_packets
[PACKET_vKill
]))
8619 case PACKET_UNKNOWN
:
8622 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8627 extended_remote_kill (struct target_ops
*ops
)
8630 int pid
= ptid_get_pid (inferior_ptid
);
8631 struct remote_state
*rs
= get_remote_state ();
8633 /* If we're stopped while forking and we haven't followed yet, kill the
8634 child task. We need to do this before killing the parent task
8635 because if this is a vfork then the parent will be sleeping. */
8636 kill_new_fork_children (pid
, rs
);
8638 res
= remote_vkill (pid
, rs
);
8639 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8641 /* Don't try 'k' on a multi-process aware stub -- it has no way
8642 to specify the pid. */
8646 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8647 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8650 /* Don't wait for it to die. I'm not really sure it matters whether
8651 we do or not. For the existing stubs, kill is a noop. */
8657 error (_("Can't kill process"));
8659 target_mourn_inferior ();
8663 remote_mourn (struct target_ops
*target
)
8665 unpush_target (target
);
8667 /* remote_close takes care of doing most of the clean up. */
8668 generic_mourn_inferior ();
8672 extended_remote_mourn (struct target_ops
*target
)
8674 struct remote_state
*rs
= get_remote_state ();
8676 /* In case we got here due to an error, but we're going to stay
8678 rs
->waiting_for_stop_reply
= 0;
8680 /* If the current general thread belonged to the process we just
8681 detached from or has exited, the remote side current general
8682 thread becomes undefined. Considering a case like this:
8684 - We just got here due to a detach.
8685 - The process that we're detaching from happens to immediately
8686 report a global breakpoint being hit in non-stop mode, in the
8687 same thread we had selected before.
8688 - GDB attaches to this process again.
8689 - This event happens to be the next event we handle.
8691 GDB would consider that the current general thread didn't need to
8692 be set on the stub side (with Hg), since for all it knew,
8693 GENERAL_THREAD hadn't changed.
8695 Notice that although in all-stop mode, the remote server always
8696 sets the current thread to the thread reporting the stop event,
8697 that doesn't happen in non-stop mode; in non-stop, the stub *must
8698 not* change the current thread when reporting a breakpoint hit,
8699 due to the decoupling of event reporting and event handling.
8701 To keep things simple, we always invalidate our notion of the
8703 record_currthread (rs
, minus_one_ptid
);
8705 /* Unlike "target remote", we do not want to unpush the target; then
8706 the next time the user says "run", we won't be connected. */
8708 /* Call common code to mark the inferior as not running. */
8709 generic_mourn_inferior ();
8711 if (!have_inferiors ())
8713 if (!remote_multi_process_p (rs
))
8715 /* Check whether the target is running now - some remote stubs
8716 automatically restart after kill. */
8718 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8720 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8722 /* Assume that the target has been restarted. Set
8723 inferior_ptid so that bits of core GDB realizes
8724 there's something here, e.g., so that the user can
8725 say "kill" again. */
8726 inferior_ptid
= magic_null_ptid
;
8733 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8735 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8739 extended_remote_disable_randomization (int val
)
8741 struct remote_state
*rs
= get_remote_state ();
8744 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8747 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8749 error (_("Target does not support QDisableRandomization."));
8750 if (strcmp (reply
, "OK") != 0)
8751 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8755 extended_remote_run (char *args
)
8757 struct remote_state
*rs
= get_remote_state ();
8759 const char *remote_exec_file
= get_remote_exec_file ();
8761 /* If the user has disabled vRun support, or we have detected that
8762 support is not available, do not try it. */
8763 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8766 strcpy (rs
->buf
, "vRun;");
8767 len
= strlen (rs
->buf
);
8769 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8770 error (_("Remote file name too long for run packet"));
8771 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8772 strlen (remote_exec_file
));
8774 gdb_assert (args
!= NULL
);
8777 struct cleanup
*back_to
;
8781 argv
= gdb_buildargv (args
);
8782 back_to
= make_cleanup_freeargv (argv
);
8783 for (i
= 0; argv
[i
] != NULL
; i
++)
8785 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8786 error (_("Argument list too long for run packet"));
8787 rs
->buf
[len
++] = ';';
8788 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8791 do_cleanups (back_to
);
8794 rs
->buf
[len
++] = '\0';
8797 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8799 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8802 /* We have a wait response. All is well. */
8804 case PACKET_UNKNOWN
:
8807 if (remote_exec_file
[0] == '\0')
8808 error (_("Running the default executable on the remote target failed; "
8809 "try \"set remote exec-file\"?"));
8811 error (_("Running \"%s\" on the remote target failed"),
8814 gdb_assert_not_reached (_("bad switch"));
8818 /* In the extended protocol we want to be able to do things like
8819 "run" and have them basically work as expected. So we need
8820 a special create_inferior function. We support changing the
8821 executable file and the command line arguments, but not the
8825 extended_remote_create_inferior (struct target_ops
*ops
,
8826 char *exec_file
, char *args
,
8827 char **env
, int from_tty
)
8831 struct remote_state
*rs
= get_remote_state ();
8832 const char *remote_exec_file
= get_remote_exec_file ();
8834 /* If running asynchronously, register the target file descriptor
8835 with the event loop. */
8836 if (target_can_async_p ())
8839 /* Disable address space randomization if requested (and supported). */
8840 if (extended_remote_supports_disable_randomization (ops
))
8841 extended_remote_disable_randomization (disable_randomization
);
8843 /* Now restart the remote server. */
8844 run_worked
= extended_remote_run (args
) != -1;
8847 /* vRun was not supported. Fail if we need it to do what the
8849 if (remote_exec_file
[0])
8850 error (_("Remote target does not support \"set remote exec-file\""));
8852 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8854 /* Fall back to "R". */
8855 extended_remote_restart ();
8858 if (!have_inferiors ())
8860 /* Clean up from the last time we ran, before we mark the target
8861 running again. This will mark breakpoints uninserted, and
8862 get_offsets may insert breakpoints. */
8863 init_thread_list ();
8864 init_wait_for_inferior ();
8867 /* vRun's success return is a stop reply. */
8868 stop_reply
= run_worked
? rs
->buf
: NULL
;
8869 add_current_inferior_and_thread (stop_reply
);
8871 /* Get updated offsets, if the stub uses qOffsets. */
8876 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8877 the list of conditions (in agent expression bytecode format), if any, the
8878 target needs to evaluate. The output is placed into the packet buffer
8879 started from BUF and ended at BUF_END. */
8882 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8883 struct bp_target_info
*bp_tgt
, char *buf
,
8886 struct agent_expr
*aexpr
= NULL
;
8889 char *buf_start
= buf
;
8891 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8894 buf
+= strlen (buf
);
8895 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8898 /* Send conditions to the target and free the vector. */
8900 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8903 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8904 buf
+= strlen (buf
);
8905 for (i
= 0; i
< aexpr
->len
; ++i
)
8906 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8913 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8914 struct bp_target_info
*bp_tgt
, char *buf
)
8916 struct agent_expr
*aexpr
= NULL
;
8919 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8922 buf
+= strlen (buf
);
8924 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8925 buf
+= strlen (buf
);
8927 /* Concatenate all the agent expressions that are commands into the
8930 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8933 sprintf (buf
, "X%x,", aexpr
->len
);
8934 buf
+= strlen (buf
);
8935 for (i
= 0; i
< aexpr
->len
; ++i
)
8936 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8941 /* Insert a breakpoint. On targets that have software breakpoint
8942 support, we ask the remote target to do the work; on targets
8943 which don't, we insert a traditional memory breakpoint. */
8946 remote_insert_breakpoint (struct target_ops
*ops
,
8947 struct gdbarch
*gdbarch
,
8948 struct bp_target_info
*bp_tgt
)
8950 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8951 If it succeeds, then set the support to PACKET_ENABLE. If it
8952 fails, and the user has explicitly requested the Z support then
8953 report an error, otherwise, mark it disabled and go on. */
8955 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8957 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8958 struct remote_state
*rs
;
8961 struct condition_list
*cond
= NULL
;
8963 /* Make sure the remote is pointing at the right process, if
8965 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8966 set_general_process ();
8968 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8970 rs
= get_remote_state ();
8972 endbuf
= rs
->buf
+ get_remote_packet_size ();
8977 addr
= (ULONGEST
) remote_address_masked (addr
);
8978 p
+= hexnumstr (p
, addr
);
8979 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8981 if (remote_supports_cond_breakpoints (ops
))
8982 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8984 if (remote_can_run_breakpoint_commands (ops
))
8985 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8988 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8990 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8995 bp_tgt
->placed_address
= addr
;
8996 bp_tgt
->placed_size
= bpsize
;
8998 case PACKET_UNKNOWN
:
9003 /* If this breakpoint has target-side commands but this stub doesn't
9004 support Z0 packets, throw error. */
9005 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9006 throw_error (NOT_SUPPORTED_ERROR
, _("\
9007 Target doesn't support breakpoints that have target side commands."));
9009 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9013 remote_remove_breakpoint (struct target_ops
*ops
,
9014 struct gdbarch
*gdbarch
,
9015 struct bp_target_info
*bp_tgt
)
9017 CORE_ADDR addr
= bp_tgt
->placed_address
;
9018 struct remote_state
*rs
= get_remote_state ();
9020 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9023 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9025 /* Make sure the remote is pointing at the right process, if
9027 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9028 set_general_process ();
9034 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9035 p
+= hexnumstr (p
, addr
);
9036 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9039 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9041 return (rs
->buf
[0] == 'E');
9044 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9047 static enum Z_packet_type
9048 watchpoint_to_Z_packet (int type
)
9053 return Z_PACKET_WRITE_WP
;
9056 return Z_PACKET_READ_WP
;
9059 return Z_PACKET_ACCESS_WP
;
9062 internal_error (__FILE__
, __LINE__
,
9063 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9068 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9069 enum target_hw_bp_type type
, struct expression
*cond
)
9071 struct remote_state
*rs
= get_remote_state ();
9072 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9074 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9076 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9079 /* Make sure the remote is pointing at the right process, if
9081 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9082 set_general_process ();
9084 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9085 p
= strchr (rs
->buf
, '\0');
9086 addr
= remote_address_masked (addr
);
9087 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9088 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9091 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9093 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9097 case PACKET_UNKNOWN
:
9102 internal_error (__FILE__
, __LINE__
,
9103 _("remote_insert_watchpoint: reached end of function"));
9107 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9108 CORE_ADDR start
, int length
)
9110 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9112 return diff
< length
;
9117 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9118 enum target_hw_bp_type type
, struct expression
*cond
)
9120 struct remote_state
*rs
= get_remote_state ();
9121 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9123 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9125 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9128 /* Make sure the remote is pointing at the right process, if
9130 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9131 set_general_process ();
9133 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9134 p
= strchr (rs
->buf
, '\0');
9135 addr
= remote_address_masked (addr
);
9136 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9137 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9139 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9141 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9144 case PACKET_UNKNOWN
:
9149 internal_error (__FILE__
, __LINE__
,
9150 _("remote_remove_watchpoint: reached end of function"));
9154 int remote_hw_watchpoint_limit
= -1;
9155 int remote_hw_watchpoint_length_limit
= -1;
9156 int remote_hw_breakpoint_limit
= -1;
9159 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9160 CORE_ADDR addr
, int len
)
9162 if (remote_hw_watchpoint_length_limit
== 0)
9164 else if (remote_hw_watchpoint_length_limit
< 0)
9166 else if (len
<= remote_hw_watchpoint_length_limit
)
9173 remote_check_watch_resources (struct target_ops
*self
,
9174 enum bptype type
, int cnt
, int ot
)
9176 if (type
== bp_hardware_breakpoint
)
9178 if (remote_hw_breakpoint_limit
== 0)
9180 else if (remote_hw_breakpoint_limit
< 0)
9182 else if (cnt
<= remote_hw_breakpoint_limit
)
9187 if (remote_hw_watchpoint_limit
== 0)
9189 else if (remote_hw_watchpoint_limit
< 0)
9193 else if (cnt
<= remote_hw_watchpoint_limit
)
9199 /* The to_stopped_by_sw_breakpoint method of target remote. */
9202 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9204 struct remote_state
*rs
= get_remote_state ();
9206 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
9209 /* The to_supports_stopped_by_sw_breakpoint method of target
9213 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9215 struct remote_state
*rs
= get_remote_state ();
9217 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9220 /* The to_stopped_by_hw_breakpoint method of target remote. */
9223 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9225 struct remote_state
*rs
= get_remote_state ();
9227 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
9230 /* The to_supports_stopped_by_hw_breakpoint method of target
9234 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9236 struct remote_state
*rs
= get_remote_state ();
9238 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9242 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9244 struct remote_state
*rs
= get_remote_state ();
9246 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
9250 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9252 struct remote_state
*rs
= get_remote_state ();
9255 if (remote_stopped_by_watchpoint (target
))
9257 *addr_p
= rs
->remote_watch_data_address
;
9266 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9267 struct bp_target_info
*bp_tgt
)
9269 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9270 struct remote_state
*rs
;
9275 /* The length field should be set to the size of a breakpoint
9276 instruction, even though we aren't inserting one ourselves. */
9278 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9280 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9283 /* Make sure the remote is pointing at the right process, if
9285 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9286 set_general_process ();
9288 rs
= get_remote_state ();
9290 endbuf
= rs
->buf
+ get_remote_packet_size ();
9296 addr
= remote_address_masked (addr
);
9297 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9298 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9300 if (remote_supports_cond_breakpoints (self
))
9301 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9303 if (remote_can_run_breakpoint_commands (self
))
9304 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9307 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9309 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9312 if (rs
->buf
[1] == '.')
9314 message
= strchr (rs
->buf
+ 2, '.');
9316 error (_("Remote failure reply: %s"), message
+ 1);
9319 case PACKET_UNKNOWN
:
9322 bp_tgt
->placed_address
= addr
;
9323 bp_tgt
->placed_size
= bpsize
;
9326 internal_error (__FILE__
, __LINE__
,
9327 _("remote_insert_hw_breakpoint: reached end of function"));
9332 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9333 struct bp_target_info
*bp_tgt
)
9336 struct remote_state
*rs
= get_remote_state ();
9338 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9340 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9343 /* Make sure the remote is pointing at the right process, if
9345 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9346 set_general_process ();
9352 addr
= remote_address_masked (bp_tgt
->placed_address
);
9353 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9354 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9357 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9359 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9362 case PACKET_UNKNOWN
:
9367 internal_error (__FILE__
, __LINE__
,
9368 _("remote_remove_hw_breakpoint: reached end of function"));
9371 /* Verify memory using the "qCRC:" request. */
9374 remote_verify_memory (struct target_ops
*ops
,
9375 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9377 struct remote_state
*rs
= get_remote_state ();
9378 unsigned long host_crc
, target_crc
;
9381 /* It doesn't make sense to use qCRC if the remote target is
9382 connected but not running. */
9383 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9385 enum packet_result result
;
9387 /* Make sure the remote is pointing at the right process. */
9388 set_general_process ();
9390 /* FIXME: assumes lma can fit into long. */
9391 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9392 (long) lma
, (long) size
);
9395 /* Be clever; compute the host_crc before waiting for target
9397 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9399 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9401 result
= packet_ok (rs
->buf
,
9402 &remote_protocol_packets
[PACKET_qCRC
]);
9403 if (result
== PACKET_ERROR
)
9405 else if (result
== PACKET_OK
)
9407 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9408 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9410 return (host_crc
== target_crc
);
9414 return simple_verify_memory (ops
, data
, lma
, size
);
9417 /* compare-sections command
9419 With no arguments, compares each loadable section in the exec bfd
9420 with the same memory range on the target, and reports mismatches.
9421 Useful for verifying the image on the target against the exec file. */
9424 compare_sections_command (char *args
, int from_tty
)
9427 struct cleanup
*old_chain
;
9429 const char *sectname
;
9438 error (_("command cannot be used without an exec file"));
9440 /* Make sure the remote is pointing at the right process. */
9441 set_general_process ();
9443 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9449 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9451 if (!(s
->flags
& SEC_LOAD
))
9452 continue; /* Skip non-loadable section. */
9454 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9455 continue; /* Skip writeable sections */
9457 size
= bfd_get_section_size (s
);
9459 continue; /* Skip zero-length section. */
9461 sectname
= bfd_get_section_name (exec_bfd
, s
);
9462 if (args
&& strcmp (args
, sectname
) != 0)
9463 continue; /* Not the section selected by user. */
9465 matched
= 1; /* Do this section. */
9468 sectdata
= (gdb_byte
*) xmalloc (size
);
9469 old_chain
= make_cleanup (xfree
, sectdata
);
9470 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9472 res
= target_verify_memory (sectdata
, lma
, size
);
9475 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9476 paddress (target_gdbarch (), lma
),
9477 paddress (target_gdbarch (), lma
+ size
));
9479 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9480 paddress (target_gdbarch (), lma
),
9481 paddress (target_gdbarch (), lma
+ size
));
9483 printf_filtered ("matched.\n");
9486 printf_filtered ("MIS-MATCHED!\n");
9490 do_cleanups (old_chain
);
9493 warning (_("One or more sections of the target image does not match\n\
9494 the loaded file\n"));
9495 if (args
&& !matched
)
9496 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9499 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9500 into remote target. The number of bytes written to the remote
9501 target is returned, or -1 for error. */
9503 static enum target_xfer_status
9504 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9505 const char *annex
, const gdb_byte
*writebuf
,
9506 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9507 struct packet_config
*packet
)
9511 struct remote_state
*rs
= get_remote_state ();
9512 int max_size
= get_memory_write_packet_size ();
9514 if (packet
->support
== PACKET_DISABLE
)
9515 return TARGET_XFER_E_IO
;
9517 /* Insert header. */
9518 i
= snprintf (rs
->buf
, max_size
,
9519 "qXfer:%s:write:%s:%s:",
9520 object_name
, annex
? annex
: "",
9521 phex_nz (offset
, sizeof offset
));
9522 max_size
-= (i
+ 1);
9524 /* Escape as much data as fits into rs->buf. */
9525 buf_len
= remote_escape_output
9526 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9528 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9529 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9530 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9531 return TARGET_XFER_E_IO
;
9533 unpack_varlen_hex (rs
->buf
, &n
);
9536 return TARGET_XFER_OK
;
9539 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9540 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9541 number of bytes read is returned, or 0 for EOF, or -1 for error.
9542 The number of bytes read may be less than LEN without indicating an
9543 EOF. PACKET is checked and updated to indicate whether the remote
9544 target supports this object. */
9546 static enum target_xfer_status
9547 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9549 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9550 ULONGEST
*xfered_len
,
9551 struct packet_config
*packet
)
9553 struct remote_state
*rs
= get_remote_state ();
9554 LONGEST i
, n
, packet_len
;
9556 if (packet
->support
== PACKET_DISABLE
)
9557 return TARGET_XFER_E_IO
;
9559 /* Check whether we've cached an end-of-object packet that matches
9561 if (rs
->finished_object
)
9563 if (strcmp (object_name
, rs
->finished_object
) == 0
9564 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9565 && offset
== rs
->finished_offset
)
9566 return TARGET_XFER_EOF
;
9569 /* Otherwise, we're now reading something different. Discard
9571 xfree (rs
->finished_object
);
9572 xfree (rs
->finished_annex
);
9573 rs
->finished_object
= NULL
;
9574 rs
->finished_annex
= NULL
;
9577 /* Request only enough to fit in a single packet. The actual data
9578 may not, since we don't know how much of it will need to be escaped;
9579 the target is free to respond with slightly less data. We subtract
9580 five to account for the response type and the protocol frame. */
9581 n
= min (get_remote_packet_size () - 5, len
);
9582 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9583 object_name
, annex
? annex
: "",
9584 phex_nz (offset
, sizeof offset
),
9585 phex_nz (n
, sizeof n
));
9586 i
= putpkt (rs
->buf
);
9588 return TARGET_XFER_E_IO
;
9591 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9592 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9593 return TARGET_XFER_E_IO
;
9595 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9596 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9598 /* 'm' means there is (or at least might be) more data after this
9599 batch. That does not make sense unless there's at least one byte
9600 of data in this reply. */
9601 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9602 error (_("Remote qXfer reply contained no data."));
9604 /* Got some data. */
9605 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9606 packet_len
- 1, readbuf
, n
);
9608 /* 'l' is an EOF marker, possibly including a final block of data,
9609 or possibly empty. If we have the final block of a non-empty
9610 object, record this fact to bypass a subsequent partial read. */
9611 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9613 rs
->finished_object
= xstrdup (object_name
);
9614 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9615 rs
->finished_offset
= offset
+ i
;
9619 return TARGET_XFER_EOF
;
9623 return TARGET_XFER_OK
;
9627 static enum target_xfer_status
9628 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9629 const char *annex
, gdb_byte
*readbuf
,
9630 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9631 ULONGEST
*xfered_len
)
9633 struct remote_state
*rs
;
9637 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9639 set_remote_traceframe ();
9640 set_general_thread (inferior_ptid
);
9642 rs
= get_remote_state ();
9644 /* Handle memory using the standard memory routines. */
9645 if (object
== TARGET_OBJECT_MEMORY
)
9647 /* If the remote target is connected but not running, we should
9648 pass this request down to a lower stratum (e.g. the executable
9650 if (!target_has_execution
)
9651 return TARGET_XFER_EOF
;
9653 if (writebuf
!= NULL
)
9654 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9657 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9661 /* Handle SPU memory using qxfer packets. */
9662 if (object
== TARGET_OBJECT_SPU
)
9665 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9666 xfered_len
, &remote_protocol_packets
9667 [PACKET_qXfer_spu_read
]);
9669 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9670 xfered_len
, &remote_protocol_packets
9671 [PACKET_qXfer_spu_write
]);
9674 /* Handle extra signal info using qxfer packets. */
9675 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9678 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9679 xfered_len
, &remote_protocol_packets
9680 [PACKET_qXfer_siginfo_read
]);
9682 return remote_write_qxfer (ops
, "siginfo", annex
,
9683 writebuf
, offset
, len
, xfered_len
,
9684 &remote_protocol_packets
9685 [PACKET_qXfer_siginfo_write
]);
9688 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9691 return remote_read_qxfer (ops
, "statictrace", annex
,
9692 readbuf
, offset
, len
, xfered_len
,
9693 &remote_protocol_packets
9694 [PACKET_qXfer_statictrace_read
]);
9696 return TARGET_XFER_E_IO
;
9699 /* Only handle flash writes. */
9700 if (writebuf
!= NULL
)
9706 case TARGET_OBJECT_FLASH
:
9707 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9711 return TARGET_XFER_E_IO
;
9715 /* Map pre-existing objects onto letters. DO NOT do this for new
9716 objects!!! Instead specify new query packets. */
9719 case TARGET_OBJECT_AVR
:
9723 case TARGET_OBJECT_AUXV
:
9724 gdb_assert (annex
== NULL
);
9725 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9727 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9729 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9730 return remote_read_qxfer
9731 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9732 &remote_protocol_packets
[PACKET_qXfer_features
]);
9734 case TARGET_OBJECT_LIBRARIES
:
9735 return remote_read_qxfer
9736 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9737 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9739 case TARGET_OBJECT_LIBRARIES_SVR4
:
9740 return remote_read_qxfer
9741 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9742 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9744 case TARGET_OBJECT_MEMORY_MAP
:
9745 gdb_assert (annex
== NULL
);
9746 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9748 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9750 case TARGET_OBJECT_OSDATA
:
9751 /* Should only get here if we're connected. */
9752 gdb_assert (rs
->remote_desc
);
9753 return remote_read_qxfer
9754 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9755 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9757 case TARGET_OBJECT_THREADS
:
9758 gdb_assert (annex
== NULL
);
9759 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9761 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9763 case TARGET_OBJECT_TRACEFRAME_INFO
:
9764 gdb_assert (annex
== NULL
);
9765 return remote_read_qxfer
9766 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9767 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9769 case TARGET_OBJECT_FDPIC
:
9770 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9772 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9774 case TARGET_OBJECT_OPENVMS_UIB
:
9775 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9777 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9779 case TARGET_OBJECT_BTRACE
:
9780 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9782 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9784 case TARGET_OBJECT_BTRACE_CONF
:
9785 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9787 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9789 case TARGET_OBJECT_EXEC_FILE
:
9790 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9792 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9795 return TARGET_XFER_E_IO
;
9798 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9799 large enough let the caller deal with it. */
9800 if (len
< get_remote_packet_size ())
9801 return TARGET_XFER_E_IO
;
9802 len
= get_remote_packet_size ();
9804 /* Except for querying the minimum buffer size, target must be open. */
9805 if (!rs
->remote_desc
)
9806 error (_("remote query is only available after target open"));
9808 gdb_assert (annex
!= NULL
);
9809 gdb_assert (readbuf
!= NULL
);
9815 /* We used one buffer char for the remote protocol q command and
9816 another for the query type. As the remote protocol encapsulation
9817 uses 4 chars plus one extra in case we are debugging
9818 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9821 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9823 /* Bad caller may have sent forbidden characters. */
9824 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9829 gdb_assert (annex
[i
] == '\0');
9831 i
= putpkt (rs
->buf
);
9833 return TARGET_XFER_E_IO
;
9835 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9836 strcpy ((char *) readbuf
, rs
->buf
);
9838 *xfered_len
= strlen ((char *) readbuf
);
9839 return TARGET_XFER_OK
;
9843 remote_search_memory (struct target_ops
* ops
,
9844 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9845 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9846 CORE_ADDR
*found_addrp
)
9848 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9849 struct remote_state
*rs
= get_remote_state ();
9850 int max_size
= get_memory_write_packet_size ();
9851 struct packet_config
*packet
=
9852 &remote_protocol_packets
[PACKET_qSearch_memory
];
9853 /* Number of packet bytes used to encode the pattern;
9854 this could be more than PATTERN_LEN due to escape characters. */
9855 int escaped_pattern_len
;
9856 /* Amount of pattern that was encodable in the packet. */
9857 int used_pattern_len
;
9860 ULONGEST found_addr
;
9862 /* Don't go to the target if we don't have to.
9863 This is done before checking packet->support to avoid the possibility that
9864 a success for this edge case means the facility works in general. */
9865 if (pattern_len
> search_space_len
)
9867 if (pattern_len
== 0)
9869 *found_addrp
= start_addr
;
9873 /* If we already know the packet isn't supported, fall back to the simple
9874 way of searching memory. */
9876 if (packet_config_support (packet
) == PACKET_DISABLE
)
9878 /* Target doesn't provided special support, fall back and use the
9879 standard support (copy memory and do the search here). */
9880 return simple_search_memory (ops
, start_addr
, search_space_len
,
9881 pattern
, pattern_len
, found_addrp
);
9884 /* Make sure the remote is pointing at the right process. */
9885 set_general_process ();
9887 /* Insert header. */
9888 i
= snprintf (rs
->buf
, max_size
,
9889 "qSearch:memory:%s;%s;",
9890 phex_nz (start_addr
, addr_size
),
9891 phex_nz (search_space_len
, sizeof (search_space_len
)));
9892 max_size
-= (i
+ 1);
9894 /* Escape as much data as fits into rs->buf. */
9895 escaped_pattern_len
=
9896 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9897 &used_pattern_len
, max_size
);
9899 /* Bail if the pattern is too large. */
9900 if (used_pattern_len
!= pattern_len
)
9901 error (_("Pattern is too large to transmit to remote target."));
9903 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9904 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9905 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9907 /* The request may not have worked because the command is not
9908 supported. If so, fall back to the simple way. */
9909 if (packet
->support
== PACKET_DISABLE
)
9911 return simple_search_memory (ops
, start_addr
, search_space_len
,
9912 pattern
, pattern_len
, found_addrp
);
9917 if (rs
->buf
[0] == '0')
9919 else if (rs
->buf
[0] == '1')
9922 if (rs
->buf
[1] != ',')
9923 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9924 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9925 *found_addrp
= found_addr
;
9928 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9934 remote_rcmd (struct target_ops
*self
, const char *command
,
9935 struct ui_file
*outbuf
)
9937 struct remote_state
*rs
= get_remote_state ();
9940 if (!rs
->remote_desc
)
9941 error (_("remote rcmd is only available after target open"));
9943 /* Send a NULL command across as an empty command. */
9944 if (command
== NULL
)
9947 /* The query prefix. */
9948 strcpy (rs
->buf
, "qRcmd,");
9949 p
= strchr (rs
->buf
, '\0');
9951 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9952 > get_remote_packet_size ())
9953 error (_("\"monitor\" command ``%s'' is too long."), command
);
9955 /* Encode the actual command. */
9956 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9958 if (putpkt (rs
->buf
) < 0)
9959 error (_("Communication problem with target."));
9961 /* get/display the response */
9966 /* XXX - see also remote_get_noisy_reply(). */
9967 QUIT
; /* Allow user to bail out with ^C. */
9969 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9971 /* Timeout. Continue to (try to) read responses.
9972 This is better than stopping with an error, assuming the stub
9973 is still executing the (long) monitor command.
9974 If needed, the user can interrupt gdb using C-c, obtaining
9975 an effect similar to stop on timeout. */
9980 error (_("Target does not support this command."));
9981 if (buf
[0] == 'O' && buf
[1] != 'K')
9983 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9986 if (strcmp (buf
, "OK") == 0)
9988 if (strlen (buf
) == 3 && buf
[0] == 'E'
9989 && isdigit (buf
[1]) && isdigit (buf
[2]))
9991 error (_("Protocol error with Rcmd"));
9993 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9995 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9997 fputc_unfiltered (c
, outbuf
);
10003 static VEC(mem_region_s
) *
10004 remote_memory_map (struct target_ops
*ops
)
10006 VEC(mem_region_s
) *result
= NULL
;
10007 char *text
= target_read_stralloc (¤t_target
,
10008 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10012 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10014 result
= parse_memory_map (text
);
10015 do_cleanups (back_to
);
10022 packet_command (char *args
, int from_tty
)
10024 struct remote_state
*rs
= get_remote_state ();
10026 if (!rs
->remote_desc
)
10027 error (_("command can only be used with remote target"));
10030 error (_("remote-packet command requires packet text as argument"));
10032 puts_filtered ("sending: ");
10033 print_packet (args
);
10034 puts_filtered ("\n");
10037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10038 puts_filtered ("received: ");
10039 print_packet (rs
->buf
);
10040 puts_filtered ("\n");
10044 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10046 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10048 static void threadset_test_cmd (char *cmd
, int tty
);
10050 static void threadalive_test (char *cmd
, int tty
);
10052 static void threadlist_test_cmd (char *cmd
, int tty
);
10054 int get_and_display_threadinfo (threadref
*ref
);
10056 static void threadinfo_test_cmd (char *cmd
, int tty
);
10058 static int thread_display_step (threadref
*ref
, void *context
);
10060 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10062 static void init_remote_threadtests (void);
10064 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10067 threadset_test_cmd (char *cmd
, int tty
)
10069 int sample_thread
= SAMPLE_THREAD
;
10071 printf_filtered (_("Remote threadset test\n"));
10072 set_general_thread (sample_thread
);
10077 threadalive_test (char *cmd
, int tty
)
10079 int sample_thread
= SAMPLE_THREAD
;
10080 int pid
= ptid_get_pid (inferior_ptid
);
10081 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10083 if (remote_thread_alive (ptid
))
10084 printf_filtered ("PASS: Thread alive test\n");
10086 printf_filtered ("FAIL: Thread alive test\n");
10089 void output_threadid (char *title
, threadref
*ref
);
10092 output_threadid (char *title
, threadref
*ref
)
10096 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10098 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10102 threadlist_test_cmd (char *cmd
, int tty
)
10105 threadref nextthread
;
10106 int done
, result_count
;
10107 threadref threadlist
[3];
10109 printf_filtered ("Remote Threadlist test\n");
10110 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10111 &result_count
, &threadlist
[0]))
10112 printf_filtered ("FAIL: threadlist test\n");
10115 threadref
*scan
= threadlist
;
10116 threadref
*limit
= scan
+ result_count
;
10118 while (scan
< limit
)
10119 output_threadid (" thread ", scan
++);
10124 display_thread_info (struct gdb_ext_thread_info
*info
)
10126 output_threadid ("Threadid: ", &info
->threadid
);
10127 printf_filtered ("Name: %s\n ", info
->shortname
);
10128 printf_filtered ("State: %s\n", info
->display
);
10129 printf_filtered ("other: %s\n\n", info
->more_display
);
10133 get_and_display_threadinfo (threadref
*ref
)
10137 struct gdb_ext_thread_info threadinfo
;
10139 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10140 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10141 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10142 display_thread_info (&threadinfo
);
10147 threadinfo_test_cmd (char *cmd
, int tty
)
10149 int athread
= SAMPLE_THREAD
;
10153 int_to_threadref (&thread
, athread
);
10154 printf_filtered ("Remote Threadinfo test\n");
10155 if (!get_and_display_threadinfo (&thread
))
10156 printf_filtered ("FAIL cannot get thread info\n");
10160 thread_display_step (threadref
*ref
, void *context
)
10162 /* output_threadid(" threadstep ",ref); *//* simple test */
10163 return get_and_display_threadinfo (ref
);
10167 threadlist_update_test_cmd (char *cmd
, int tty
)
10169 printf_filtered ("Remote Threadlist update test\n");
10170 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10174 init_remote_threadtests (void)
10176 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10177 _("Fetch and print the remote list of "
10178 "thread identifiers, one pkt only"));
10179 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10180 _("Fetch and display info about one thread"));
10181 add_com ("tset", class_obscure
, threadset_test_cmd
,
10182 _("Test setting to a different thread"));
10183 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10184 _("Iterate through updating all remote thread info"));
10185 add_com ("talive", class_obscure
, threadalive_test
,
10186 _(" Remote thread alive test "));
10191 /* Convert a thread ID to a string. Returns the string in a static
10195 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10197 static char buf
[64];
10198 struct remote_state
*rs
= get_remote_state ();
10200 if (ptid_equal (ptid
, null_ptid
))
10201 return normal_pid_to_str (ptid
);
10202 else if (ptid_is_pid (ptid
))
10204 /* Printing an inferior target id. */
10206 /* When multi-process extensions are off, there's no way in the
10207 remote protocol to know the remote process id, if there's any
10208 at all. There's one exception --- when we're connected with
10209 target extended-remote, and we manually attached to a process
10210 with "attach PID". We don't record anywhere a flag that
10211 allows us to distinguish that case from the case of
10212 connecting with extended-remote and the stub already being
10213 attached to a process, and reporting yes to qAttached, hence
10214 no smart special casing here. */
10215 if (!remote_multi_process_p (rs
))
10217 xsnprintf (buf
, sizeof buf
, "Remote target");
10221 return normal_pid_to_str (ptid
);
10225 if (ptid_equal (magic_null_ptid
, ptid
))
10226 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10227 else if (rs
->extended
&& remote_multi_process_p (rs
))
10228 if (ptid_get_lwp (ptid
) == 0)
10229 return normal_pid_to_str (ptid
);
10231 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10232 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10234 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10235 ptid_get_lwp (ptid
));
10240 /* Get the address of the thread local variable in OBJFILE which is
10241 stored at OFFSET within the thread local storage for thread PTID. */
10244 remote_get_thread_local_address (struct target_ops
*ops
,
10245 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10247 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10249 struct remote_state
*rs
= get_remote_state ();
10251 char *endp
= rs
->buf
+ get_remote_packet_size ();
10252 enum packet_result result
;
10254 strcpy (p
, "qGetTLSAddr:");
10256 p
= write_ptid (p
, endp
, ptid
);
10258 p
+= hexnumstr (p
, offset
);
10260 p
+= hexnumstr (p
, lm
);
10264 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10265 result
= packet_ok (rs
->buf
,
10266 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10267 if (result
== PACKET_OK
)
10271 unpack_varlen_hex (rs
->buf
, &result
);
10274 else if (result
== PACKET_UNKNOWN
)
10275 throw_error (TLS_GENERIC_ERROR
,
10276 _("Remote target doesn't support qGetTLSAddr packet"));
10278 throw_error (TLS_GENERIC_ERROR
,
10279 _("Remote target failed to process qGetTLSAddr request"));
10282 throw_error (TLS_GENERIC_ERROR
,
10283 _("TLS not supported or disabled on this target"));
10288 /* Provide thread local base, i.e. Thread Information Block address.
10289 Returns 1 if ptid is found and thread_local_base is non zero. */
10292 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10294 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10296 struct remote_state
*rs
= get_remote_state ();
10298 char *endp
= rs
->buf
+ get_remote_packet_size ();
10299 enum packet_result result
;
10301 strcpy (p
, "qGetTIBAddr:");
10303 p
= write_ptid (p
, endp
, ptid
);
10307 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10308 result
= packet_ok (rs
->buf
,
10309 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10310 if (result
== PACKET_OK
)
10314 unpack_varlen_hex (rs
->buf
, &result
);
10316 *addr
= (CORE_ADDR
) result
;
10319 else if (result
== PACKET_UNKNOWN
)
10320 error (_("Remote target doesn't support qGetTIBAddr packet"));
10322 error (_("Remote target failed to process qGetTIBAddr request"));
10325 error (_("qGetTIBAddr not supported or disabled on this target"));
10330 /* Support for inferring a target description based on the current
10331 architecture and the size of a 'g' packet. While the 'g' packet
10332 can have any size (since optional registers can be left off the
10333 end), some sizes are easily recognizable given knowledge of the
10334 approximate architecture. */
10336 struct remote_g_packet_guess
10339 const struct target_desc
*tdesc
;
10341 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10342 DEF_VEC_O(remote_g_packet_guess_s
);
10344 struct remote_g_packet_data
10346 VEC(remote_g_packet_guess_s
) *guesses
;
10349 static struct gdbarch_data
*remote_g_packet_data_handle
;
10352 remote_g_packet_data_init (struct obstack
*obstack
)
10354 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10358 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10359 const struct target_desc
*tdesc
)
10361 struct remote_g_packet_data
*data
10362 = ((struct remote_g_packet_data
*)
10363 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10364 struct remote_g_packet_guess new_guess
, *guess
;
10367 gdb_assert (tdesc
!= NULL
);
10370 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10372 if (guess
->bytes
== bytes
)
10373 internal_error (__FILE__
, __LINE__
,
10374 _("Duplicate g packet description added for size %d"),
10377 new_guess
.bytes
= bytes
;
10378 new_guess
.tdesc
= tdesc
;
10379 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10382 /* Return 1 if remote_read_description would do anything on this target
10383 and architecture, 0 otherwise. */
10386 remote_read_description_p (struct target_ops
*target
)
10388 struct remote_g_packet_data
*data
10389 = ((struct remote_g_packet_data
*)
10390 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10392 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10398 static const struct target_desc
*
10399 remote_read_description (struct target_ops
*target
)
10401 struct remote_g_packet_data
*data
10402 = ((struct remote_g_packet_data
*)
10403 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10405 /* Do not try this during initial connection, when we do not know
10406 whether there is a running but stopped thread. */
10407 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10408 return target
->beneath
->to_read_description (target
->beneath
);
10410 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10412 struct remote_g_packet_guess
*guess
;
10414 int bytes
= send_g_packet ();
10417 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10419 if (guess
->bytes
== bytes
)
10420 return guess
->tdesc
;
10422 /* We discard the g packet. A minor optimization would be to
10423 hold on to it, and fill the register cache once we have selected
10424 an architecture, but it's too tricky to do safely. */
10427 return target
->beneath
->to_read_description (target
->beneath
);
10430 /* Remote file transfer support. This is host-initiated I/O, not
10431 target-initiated; for target-initiated, see remote-fileio.c. */
10433 /* If *LEFT is at least the length of STRING, copy STRING to
10434 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10435 decrease *LEFT. Otherwise raise an error. */
10438 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10440 int len
= strlen (string
);
10443 error (_("Packet too long for target."));
10445 memcpy (*buffer
, string
, len
);
10449 /* NUL-terminate the buffer as a convenience, if there is
10455 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10456 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10457 decrease *LEFT. Otherwise raise an error. */
10460 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10463 if (2 * len
> *left
)
10464 error (_("Packet too long for target."));
10466 bin2hex (bytes
, *buffer
, len
);
10467 *buffer
+= 2 * len
;
10470 /* NUL-terminate the buffer as a convenience, if there is
10476 /* If *LEFT is large enough, convert VALUE to hex and add it to
10477 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10478 decrease *LEFT. Otherwise raise an error. */
10481 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10483 int len
= hexnumlen (value
);
10486 error (_("Packet too long for target."));
10488 hexnumstr (*buffer
, value
);
10492 /* NUL-terminate the buffer as a convenience, if there is
10498 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10499 value, *REMOTE_ERRNO to the remote error number or zero if none
10500 was included, and *ATTACHMENT to point to the start of the annex
10501 if any. The length of the packet isn't needed here; there may
10502 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10504 Return 0 if the packet could be parsed, -1 if it could not. If
10505 -1 is returned, the other variables may not be initialized. */
10508 remote_hostio_parse_result (char *buffer
, int *retcode
,
10509 int *remote_errno
, char **attachment
)
10514 *attachment
= NULL
;
10516 if (buffer
[0] != 'F')
10520 *retcode
= strtol (&buffer
[1], &p
, 16);
10521 if (errno
!= 0 || p
== &buffer
[1])
10524 /* Check for ",errno". */
10528 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10529 if (errno
!= 0 || p
+ 1 == p2
)
10534 /* Check for ";attachment". If there is no attachment, the
10535 packet should end here. */
10538 *attachment
= p
+ 1;
10541 else if (*p
== '\0')
10547 /* Send a prepared I/O packet to the target and read its response.
10548 The prepared packet is in the global RS->BUF before this function
10549 is called, and the answer is there when we return.
10551 COMMAND_BYTES is the length of the request to send, which may include
10552 binary data. WHICH_PACKET is the packet configuration to check
10553 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10554 is set to the error number and -1 is returned. Otherwise the value
10555 returned by the function is returned.
10557 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10558 attachment is expected; an error will be reported if there's a
10559 mismatch. If one is found, *ATTACHMENT will be set to point into
10560 the packet buffer and *ATTACHMENT_LEN will be set to the
10561 attachment's length. */
10564 remote_hostio_send_command (int command_bytes
, int which_packet
,
10565 int *remote_errno
, char **attachment
,
10566 int *attachment_len
)
10568 struct remote_state
*rs
= get_remote_state ();
10569 int ret
, bytes_read
;
10570 char *attachment_tmp
;
10572 if (!rs
->remote_desc
10573 || packet_support (which_packet
) == PACKET_DISABLE
)
10575 *remote_errno
= FILEIO_ENOSYS
;
10579 putpkt_binary (rs
->buf
, command_bytes
);
10580 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10582 /* If it timed out, something is wrong. Don't try to parse the
10584 if (bytes_read
< 0)
10586 *remote_errno
= FILEIO_EINVAL
;
10590 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10593 *remote_errno
= FILEIO_EINVAL
;
10595 case PACKET_UNKNOWN
:
10596 *remote_errno
= FILEIO_ENOSYS
;
10602 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10605 *remote_errno
= FILEIO_EINVAL
;
10609 /* Make sure we saw an attachment if and only if we expected one. */
10610 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10611 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10613 *remote_errno
= FILEIO_EINVAL
;
10617 /* If an attachment was found, it must point into the packet buffer;
10618 work out how many bytes there were. */
10619 if (attachment_tmp
!= NULL
)
10621 *attachment
= attachment_tmp
;
10622 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10628 /* Invalidate the readahead cache. */
10631 readahead_cache_invalidate (void)
10633 struct remote_state
*rs
= get_remote_state ();
10635 rs
->readahead_cache
.fd
= -1;
10638 /* Invalidate the readahead cache if it is holding data for FD. */
10641 readahead_cache_invalidate_fd (int fd
)
10643 struct remote_state
*rs
= get_remote_state ();
10645 if (rs
->readahead_cache
.fd
== fd
)
10646 rs
->readahead_cache
.fd
= -1;
10649 /* Set the filesystem remote_hostio functions that take FILENAME
10650 arguments will use. Return 0 on success, or -1 if an error
10651 occurs (and set *REMOTE_ERRNO). */
10654 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10656 struct remote_state
*rs
= get_remote_state ();
10657 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10659 int left
= get_remote_packet_size () - 1;
10663 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10666 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10669 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10671 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10672 remote_buffer_add_string (&p
, &left
, arg
);
10674 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10675 remote_errno
, NULL
, NULL
);
10677 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10681 rs
->fs_pid
= required_pid
;
10686 /* Implementation of to_fileio_open. */
10689 remote_hostio_open (struct target_ops
*self
,
10690 struct inferior
*inf
, const char *filename
,
10691 int flags
, int mode
, int warn_if_slow
,
10694 struct remote_state
*rs
= get_remote_state ();
10696 int left
= get_remote_packet_size () - 1;
10700 static int warning_issued
= 0;
10702 printf_unfiltered (_("Reading %s from remote target...\n"),
10705 if (!warning_issued
)
10707 warning (_("File transfers from remote targets can be slow."
10708 " Use \"set sysroot\" to access files locally"
10710 warning_issued
= 1;
10714 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10717 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10719 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10720 strlen (filename
));
10721 remote_buffer_add_string (&p
, &left
, ",");
10723 remote_buffer_add_int (&p
, &left
, flags
);
10724 remote_buffer_add_string (&p
, &left
, ",");
10726 remote_buffer_add_int (&p
, &left
, mode
);
10728 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10729 remote_errno
, NULL
, NULL
);
10732 /* Implementation of to_fileio_pwrite. */
10735 remote_hostio_pwrite (struct target_ops
*self
,
10736 int fd
, const gdb_byte
*write_buf
, int len
,
10737 ULONGEST offset
, int *remote_errno
)
10739 struct remote_state
*rs
= get_remote_state ();
10741 int left
= get_remote_packet_size ();
10744 readahead_cache_invalidate_fd (fd
);
10746 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10748 remote_buffer_add_int (&p
, &left
, fd
);
10749 remote_buffer_add_string (&p
, &left
, ",");
10751 remote_buffer_add_int (&p
, &left
, offset
);
10752 remote_buffer_add_string (&p
, &left
, ",");
10754 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10755 get_remote_packet_size () - (p
- rs
->buf
));
10757 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10758 remote_errno
, NULL
, NULL
);
10761 /* Helper for the implementation of to_fileio_pread. Read the file
10762 from the remote side with vFile:pread. */
10765 remote_hostio_pread_vFile (struct target_ops
*self
,
10766 int fd
, gdb_byte
*read_buf
, int len
,
10767 ULONGEST offset
, int *remote_errno
)
10769 struct remote_state
*rs
= get_remote_state ();
10772 int left
= get_remote_packet_size ();
10773 int ret
, attachment_len
;
10776 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10778 remote_buffer_add_int (&p
, &left
, fd
);
10779 remote_buffer_add_string (&p
, &left
, ",");
10781 remote_buffer_add_int (&p
, &left
, len
);
10782 remote_buffer_add_string (&p
, &left
, ",");
10784 remote_buffer_add_int (&p
, &left
, offset
);
10786 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10787 remote_errno
, &attachment
,
10793 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10795 if (read_len
!= ret
)
10796 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10801 /* Serve pread from the readahead cache. Returns number of bytes
10802 read, or 0 if the request can't be served from the cache. */
10805 remote_hostio_pread_from_cache (struct remote_state
*rs
,
10806 int fd
, gdb_byte
*read_buf
, size_t len
,
10809 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10811 if (cache
->fd
== fd
10812 && cache
->offset
<= offset
10813 && offset
< cache
->offset
+ cache
->bufsize
)
10815 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
10817 if (offset
+ len
> max
)
10818 len
= max
- offset
;
10820 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
10827 /* Implementation of to_fileio_pread. */
10830 remote_hostio_pread (struct target_ops
*self
,
10831 int fd
, gdb_byte
*read_buf
, int len
,
10832 ULONGEST offset
, int *remote_errno
)
10835 struct remote_state
*rs
= get_remote_state ();
10836 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10838 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10841 cache
->hit_count
++;
10844 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
10845 pulongest (cache
->hit_count
));
10849 cache
->miss_count
++;
10851 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
10852 pulongest (cache
->miss_count
));
10855 cache
->offset
= offset
;
10856 cache
->bufsize
= get_remote_packet_size ();
10857 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
10859 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
10860 cache
->offset
, remote_errno
);
10863 readahead_cache_invalidate_fd (fd
);
10867 cache
->bufsize
= ret
;
10868 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10871 /* Implementation of to_fileio_close. */
10874 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10876 struct remote_state
*rs
= get_remote_state ();
10878 int left
= get_remote_packet_size () - 1;
10880 readahead_cache_invalidate_fd (fd
);
10882 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10884 remote_buffer_add_int (&p
, &left
, fd
);
10886 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10887 remote_errno
, NULL
, NULL
);
10890 /* Implementation of to_fileio_unlink. */
10893 remote_hostio_unlink (struct target_ops
*self
,
10894 struct inferior
*inf
, const char *filename
,
10897 struct remote_state
*rs
= get_remote_state ();
10899 int left
= get_remote_packet_size () - 1;
10901 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10904 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10906 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10907 strlen (filename
));
10909 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10910 remote_errno
, NULL
, NULL
);
10913 /* Implementation of to_fileio_readlink. */
10916 remote_hostio_readlink (struct target_ops
*self
,
10917 struct inferior
*inf
, const char *filename
,
10920 struct remote_state
*rs
= get_remote_state ();
10923 int left
= get_remote_packet_size ();
10924 int len
, attachment_len
;
10928 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10931 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10933 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10934 strlen (filename
));
10936 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10937 remote_errno
, &attachment
,
10943 ret
= (char *) xmalloc (len
+ 1);
10945 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10946 (gdb_byte
*) ret
, len
);
10947 if (read_len
!= len
)
10948 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10954 /* Implementation of to_fileio_fstat. */
10957 remote_hostio_fstat (struct target_ops
*self
,
10958 int fd
, struct stat
*st
,
10961 struct remote_state
*rs
= get_remote_state ();
10963 int left
= get_remote_packet_size ();
10964 int attachment_len
, ret
;
10966 struct fio_stat fst
;
10969 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10971 remote_buffer_add_int (&p
, &left
, fd
);
10973 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10974 remote_errno
, &attachment
,
10978 if (*remote_errno
!= FILEIO_ENOSYS
)
10981 /* Strictly we should return -1, ENOSYS here, but when
10982 "set sysroot remote:" was implemented in August 2008
10983 BFD's need for a stat function was sidestepped with
10984 this hack. This was not remedied until March 2015
10985 so we retain the previous behavior to avoid breaking
10988 Note that the memset is a March 2015 addition; older
10989 GDBs set st_size *and nothing else* so the structure
10990 would have garbage in all other fields. This might
10991 break something but retaining the previous behavior
10992 here would be just too wrong. */
10994 memset (st
, 0, sizeof (struct stat
));
10995 st
->st_size
= INT_MAX
;
10999 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11000 (gdb_byte
*) &fst
, sizeof (fst
));
11002 if (read_len
!= ret
)
11003 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11005 if (read_len
!= sizeof (fst
))
11006 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11007 read_len
, (int) sizeof (fst
));
11009 remote_fileio_to_host_stat (&fst
, st
);
11014 /* Implementation of to_filesystem_is_local. */
11017 remote_filesystem_is_local (struct target_ops
*self
)
11019 /* Valgrind GDB presents itself as a remote target but works
11020 on the local filesystem: it does not implement remote get
11021 and users are not expected to set a sysroot. To handle
11022 this case we treat the remote filesystem as local if the
11023 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11024 does not support vFile:open. */
11025 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11027 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11029 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11031 int fd
, remote_errno
;
11033 /* Try opening a file to probe support. The supplied
11034 filename is irrelevant, we only care about whether
11035 the stub recognizes the packet or not. */
11036 fd
= remote_hostio_open (self
, NULL
, "just probing",
11037 FILEIO_O_RDONLY
, 0700, 0,
11041 remote_hostio_close (self
, fd
, &remote_errno
);
11043 ps
= packet_support (PACKET_vFile_open
);
11046 if (ps
== PACKET_DISABLE
)
11048 static int warning_issued
= 0;
11050 if (!warning_issued
)
11052 warning (_("remote target does not support file"
11053 " transfer, attempting to access files"
11054 " from local filesystem."));
11055 warning_issued
= 1;
11066 remote_fileio_errno_to_host (int errnum
)
11072 case FILEIO_ENOENT
:
11080 case FILEIO_EACCES
:
11082 case FILEIO_EFAULT
:
11086 case FILEIO_EEXIST
:
11088 case FILEIO_ENODEV
:
11090 case FILEIO_ENOTDIR
:
11092 case FILEIO_EISDIR
:
11094 case FILEIO_EINVAL
:
11096 case FILEIO_ENFILE
:
11098 case FILEIO_EMFILE
:
11102 case FILEIO_ENOSPC
:
11104 case FILEIO_ESPIPE
:
11108 case FILEIO_ENOSYS
:
11110 case FILEIO_ENAMETOOLONG
:
11111 return ENAMETOOLONG
;
11117 remote_hostio_error (int errnum
)
11119 int host_error
= remote_fileio_errno_to_host (errnum
);
11121 if (host_error
== -1)
11122 error (_("Unknown remote I/O error %d"), errnum
);
11124 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11128 remote_hostio_close_cleanup (void *opaque
)
11130 int fd
= *(int *) opaque
;
11133 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11137 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11139 struct cleanup
*back_to
, *close_cleanup
;
11140 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11143 int bytes_in_buffer
;
11146 struct remote_state
*rs
= get_remote_state ();
11148 if (!rs
->remote_desc
)
11149 error (_("command can only be used with remote target"));
11151 file
= gdb_fopen_cloexec (local_file
, "rb");
11153 perror_with_name (local_file
);
11154 back_to
= make_cleanup_fclose (file
);
11156 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11157 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11159 0700, 0, &remote_errno
);
11161 remote_hostio_error (remote_errno
);
11163 /* Send up to this many bytes at once. They won't all fit in the
11164 remote packet limit, so we'll transfer slightly fewer. */
11165 io_size
= get_remote_packet_size ();
11166 buffer
= (gdb_byte
*) xmalloc (io_size
);
11167 make_cleanup (xfree
, buffer
);
11169 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11171 bytes_in_buffer
= 0;
11174 while (bytes_in_buffer
|| !saw_eof
)
11178 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11179 io_size
- bytes_in_buffer
,
11184 error (_("Error reading %s."), local_file
);
11187 /* EOF. Unless there is something still in the
11188 buffer from the last iteration, we are done. */
11190 if (bytes_in_buffer
== 0)
11198 bytes
+= bytes_in_buffer
;
11199 bytes_in_buffer
= 0;
11201 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11203 offset
, &remote_errno
);
11206 remote_hostio_error (remote_errno
);
11207 else if (retcode
== 0)
11208 error (_("Remote write of %d bytes returned 0!"), bytes
);
11209 else if (retcode
< bytes
)
11211 /* Short write. Save the rest of the read data for the next
11213 bytes_in_buffer
= bytes
- retcode
;
11214 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11220 discard_cleanups (close_cleanup
);
11221 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11222 remote_hostio_error (remote_errno
);
11225 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11226 do_cleanups (back_to
);
11230 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11232 struct cleanup
*back_to
, *close_cleanup
;
11233 int fd
, remote_errno
, bytes
, io_size
;
11237 struct remote_state
*rs
= get_remote_state ();
11239 if (!rs
->remote_desc
)
11240 error (_("command can only be used with remote target"));
11242 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11243 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11246 remote_hostio_error (remote_errno
);
11248 file
= gdb_fopen_cloexec (local_file
, "wb");
11250 perror_with_name (local_file
);
11251 back_to
= make_cleanup_fclose (file
);
11253 /* Send up to this many bytes at once. They won't all fit in the
11254 remote packet limit, so we'll transfer slightly fewer. */
11255 io_size
= get_remote_packet_size ();
11256 buffer
= (gdb_byte
*) xmalloc (io_size
);
11257 make_cleanup (xfree
, buffer
);
11259 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11264 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11265 fd
, buffer
, io_size
, offset
, &remote_errno
);
11267 /* Success, but no bytes, means end-of-file. */
11270 remote_hostio_error (remote_errno
);
11274 bytes
= fwrite (buffer
, 1, bytes
, file
);
11276 perror_with_name (local_file
);
11279 discard_cleanups (close_cleanup
);
11280 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11281 remote_hostio_error (remote_errno
);
11284 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11285 do_cleanups (back_to
);
11289 remote_file_delete (const char *remote_file
, int from_tty
)
11291 int retcode
, remote_errno
;
11292 struct remote_state
*rs
= get_remote_state ();
11294 if (!rs
->remote_desc
)
11295 error (_("command can only be used with remote target"));
11297 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11298 NULL
, remote_file
, &remote_errno
);
11300 remote_hostio_error (remote_errno
);
11303 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11307 remote_put_command (char *args
, int from_tty
)
11309 struct cleanup
*back_to
;
11313 error_no_arg (_("file to put"));
11315 argv
= gdb_buildargv (args
);
11316 back_to
= make_cleanup_freeargv (argv
);
11317 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11318 error (_("Invalid parameters to remote put"));
11320 remote_file_put (argv
[0], argv
[1], from_tty
);
11322 do_cleanups (back_to
);
11326 remote_get_command (char *args
, int from_tty
)
11328 struct cleanup
*back_to
;
11332 error_no_arg (_("file to get"));
11334 argv
= gdb_buildargv (args
);
11335 back_to
= make_cleanup_freeargv (argv
);
11336 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11337 error (_("Invalid parameters to remote get"));
11339 remote_file_get (argv
[0], argv
[1], from_tty
);
11341 do_cleanups (back_to
);
11345 remote_delete_command (char *args
, int from_tty
)
11347 struct cleanup
*back_to
;
11351 error_no_arg (_("file to delete"));
11353 argv
= gdb_buildargv (args
);
11354 back_to
= make_cleanup_freeargv (argv
);
11355 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11356 error (_("Invalid parameters to remote delete"));
11358 remote_file_delete (argv
[0], from_tty
);
11360 do_cleanups (back_to
);
11364 remote_command (char *args
, int from_tty
)
11366 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11370 remote_can_execute_reverse (struct target_ops
*self
)
11372 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11373 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11380 remote_supports_non_stop (struct target_ops
*self
)
11386 remote_supports_disable_randomization (struct target_ops
*self
)
11388 /* Only supported in extended mode. */
11393 remote_supports_multi_process (struct target_ops
*self
)
11395 struct remote_state
*rs
= get_remote_state ();
11397 /* Only extended-remote handles being attached to multiple
11398 processes, even though plain remote can use the multi-process
11399 thread id extensions, so that GDB knows the target process's
11401 return rs
->extended
&& remote_multi_process_p (rs
);
11405 remote_supports_cond_tracepoints (void)
11407 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11411 remote_supports_cond_breakpoints (struct target_ops
*self
)
11413 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11417 remote_supports_fast_tracepoints (void)
11419 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11423 remote_supports_static_tracepoints (void)
11425 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11429 remote_supports_install_in_trace (void)
11431 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11435 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11437 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11442 remote_supports_string_tracing (struct target_ops
*self
)
11444 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11448 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11450 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11454 remote_trace_init (struct target_ops
*self
)
11457 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11458 if (strcmp (target_buf
, "OK") != 0)
11459 error (_("Target does not support this command."));
11462 static void free_actions_list (char **actions_list
);
11463 static void free_actions_list_cleanup_wrapper (void *);
11465 free_actions_list_cleanup_wrapper (void *al
)
11467 free_actions_list ((char **) al
);
11471 free_actions_list (char **actions_list
)
11475 if (actions_list
== 0)
11478 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11479 xfree (actions_list
[ndx
]);
11481 xfree (actions_list
);
11484 /* Recursive routine to walk through command list including loops, and
11485 download packets for each command. */
11488 remote_download_command_source (int num
, ULONGEST addr
,
11489 struct command_line
*cmds
)
11491 struct remote_state
*rs
= get_remote_state ();
11492 struct command_line
*cmd
;
11494 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11496 QUIT
; /* Allow user to bail out with ^C. */
11497 strcpy (rs
->buf
, "QTDPsrc:");
11498 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11499 rs
->buf
+ strlen (rs
->buf
),
11500 rs
->buf_size
- strlen (rs
->buf
));
11502 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11503 if (strcmp (target_buf
, "OK"))
11504 warning (_("Target does not support source download."));
11506 if (cmd
->control_type
== while_control
11507 || cmd
->control_type
== while_stepping_control
)
11509 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11511 QUIT
; /* Allow user to bail out with ^C. */
11512 strcpy (rs
->buf
, "QTDPsrc:");
11513 encode_source_string (num
, addr
, "cmd", "end",
11514 rs
->buf
+ strlen (rs
->buf
),
11515 rs
->buf_size
- strlen (rs
->buf
));
11517 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11518 if (strcmp (target_buf
, "OK"))
11519 warning (_("Target does not support source download."));
11525 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11527 #define BUF_SIZE 2048
11531 char buf
[BUF_SIZE
];
11532 char **tdp_actions
;
11533 char **stepping_actions
;
11535 struct cleanup
*old_chain
= NULL
;
11536 struct agent_expr
*aexpr
;
11537 struct cleanup
*aexpr_chain
= NULL
;
11539 struct breakpoint
*b
= loc
->owner
;
11540 struct tracepoint
*t
= (struct tracepoint
*) b
;
11542 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11543 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11545 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11548 tpaddr
= loc
->address
;
11549 sprintf_vma (addrbuf
, tpaddr
);
11550 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11551 addrbuf
, /* address */
11552 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11553 t
->step_count
, t
->pass_count
);
11554 /* Fast tracepoints are mostly handled by the target, but we can
11555 tell the target how big of an instruction block should be moved
11557 if (b
->type
== bp_fast_tracepoint
)
11559 /* Only test for support at download time; we may not know
11560 target capabilities at definition time. */
11561 if (remote_supports_fast_tracepoints ())
11563 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11565 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11566 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11568 /* If it passed validation at definition but fails now,
11569 something is very wrong. */
11570 internal_error (__FILE__
, __LINE__
,
11571 _("Fast tracepoint not "
11572 "valid during download"));
11575 /* Fast tracepoints are functionally identical to regular
11576 tracepoints, so don't take lack of support as a reason to
11577 give up on the trace run. */
11578 warning (_("Target does not support fast tracepoints, "
11579 "downloading %d as regular tracepoint"), b
->number
);
11581 else if (b
->type
== bp_static_tracepoint
)
11583 /* Only test for support at download time; we may not know
11584 target capabilities at definition time. */
11585 if (remote_supports_static_tracepoints ())
11587 struct static_tracepoint_marker marker
;
11589 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11590 strcat (buf
, ":S");
11592 error (_("Static tracepoint not valid during download"));
11595 /* Fast tracepoints are functionally identical to regular
11596 tracepoints, so don't take lack of support as a reason
11597 to give up on the trace run. */
11598 error (_("Target does not support static tracepoints"));
11600 /* If the tracepoint has a conditional, make it into an agent
11601 expression and append to the definition. */
11604 /* Only test support at download time, we may not know target
11605 capabilities at definition time. */
11606 if (remote_supports_cond_tracepoints ())
11608 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11609 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11610 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11612 pkt
= buf
+ strlen (buf
);
11613 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11614 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11616 do_cleanups (aexpr_chain
);
11619 warning (_("Target does not support conditional tracepoints, "
11620 "ignoring tp %d cond"), b
->number
);
11623 if (b
->commands
|| *default_collect
)
11626 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11627 if (strcmp (target_buf
, "OK"))
11628 error (_("Target does not support tracepoints."));
11630 /* do_single_steps (t); */
11633 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11635 QUIT
; /* Allow user to bail out with ^C. */
11636 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11637 b
->number
, addrbuf
, /* address */
11639 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11642 remote_get_noisy_reply (&target_buf
,
11644 if (strcmp (target_buf
, "OK"))
11645 error (_("Error on target while setting tracepoints."));
11648 if (stepping_actions
)
11650 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11652 QUIT
; /* Allow user to bail out with ^C. */
11653 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11654 b
->number
, addrbuf
, /* address */
11655 ((ndx
== 0) ? "S" : ""),
11656 stepping_actions
[ndx
],
11657 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11659 remote_get_noisy_reply (&target_buf
,
11661 if (strcmp (target_buf
, "OK"))
11662 error (_("Error on target while setting tracepoints."));
11666 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11668 if (b
->location
!= NULL
)
11670 strcpy (buf
, "QTDPsrc:");
11671 encode_source_string (b
->number
, loc
->address
, "at",
11672 event_location_to_string (b
->location
),
11673 buf
+ strlen (buf
), 2048 - strlen (buf
));
11675 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11676 if (strcmp (target_buf
, "OK"))
11677 warning (_("Target does not support source download."));
11679 if (b
->cond_string
)
11681 strcpy (buf
, "QTDPsrc:");
11682 encode_source_string (b
->number
, loc
->address
,
11683 "cond", b
->cond_string
, buf
+ strlen (buf
),
11684 2048 - strlen (buf
));
11686 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11687 if (strcmp (target_buf
, "OK"))
11688 warning (_("Target does not support source download."));
11690 remote_download_command_source (b
->number
, loc
->address
,
11691 breakpoint_commands (b
));
11694 do_cleanups (old_chain
);
11698 remote_can_download_tracepoint (struct target_ops
*self
)
11700 struct remote_state
*rs
= get_remote_state ();
11701 struct trace_status
*ts
;
11704 /* Don't try to install tracepoints until we've relocated our
11705 symbols, and fetched and merged the target's tracepoint list with
11707 if (rs
->starting_up
)
11710 ts
= current_trace_status ();
11711 status
= remote_get_trace_status (self
, ts
);
11713 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11716 /* If we are in a tracing experiment, but remote stub doesn't support
11717 installing tracepoint in trace, we have to return. */
11718 if (!remote_supports_install_in_trace ())
11726 remote_download_trace_state_variable (struct target_ops
*self
,
11727 struct trace_state_variable
*tsv
)
11729 struct remote_state
*rs
= get_remote_state ();
11732 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11733 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11735 p
= rs
->buf
+ strlen (rs
->buf
);
11736 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11737 error (_("Trace state variable name too long for tsv definition packet"));
11738 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11741 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11742 if (*target_buf
== '\0')
11743 error (_("Target does not support this command."));
11744 if (strcmp (target_buf
, "OK") != 0)
11745 error (_("Error on target while downloading trace state variable."));
11749 remote_enable_tracepoint (struct target_ops
*self
,
11750 struct bp_location
*location
)
11752 struct remote_state
*rs
= get_remote_state ();
11755 sprintf_vma (addr_buf
, location
->address
);
11756 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11757 location
->owner
->number
, addr_buf
);
11759 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11760 if (*rs
->buf
== '\0')
11761 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11762 if (strcmp (rs
->buf
, "OK") != 0)
11763 error (_("Error on target while enabling tracepoint."));
11767 remote_disable_tracepoint (struct target_ops
*self
,
11768 struct bp_location
*location
)
11770 struct remote_state
*rs
= get_remote_state ();
11773 sprintf_vma (addr_buf
, location
->address
);
11774 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11775 location
->owner
->number
, addr_buf
);
11777 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11778 if (*rs
->buf
== '\0')
11779 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11780 if (strcmp (rs
->buf
, "OK") != 0)
11781 error (_("Error on target while disabling tracepoint."));
11785 remote_trace_set_readonly_regions (struct target_ops
*self
)
11789 bfd_size_type size
;
11795 return; /* No information to give. */
11797 strcpy (target_buf
, "QTro");
11798 offset
= strlen (target_buf
);
11799 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11801 char tmp1
[40], tmp2
[40];
11804 if ((s
->flags
& SEC_LOAD
) == 0 ||
11805 /* (s->flags & SEC_CODE) == 0 || */
11806 (s
->flags
& SEC_READONLY
) == 0)
11810 vma
= bfd_get_section_vma (abfd
, s
);
11811 size
= bfd_get_section_size (s
);
11812 sprintf_vma (tmp1
, vma
);
11813 sprintf_vma (tmp2
, vma
+ size
);
11814 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11815 if (offset
+ sec_length
+ 1 > target_buf_size
)
11817 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11819 Too many sections for read-only sections definition packet."));
11822 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11824 offset
+= sec_length
;
11828 putpkt (target_buf
);
11829 getpkt (&target_buf
, &target_buf_size
, 0);
11834 remote_trace_start (struct target_ops
*self
)
11836 putpkt ("QTStart");
11837 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11838 if (*target_buf
== '\0')
11839 error (_("Target does not support this command."));
11840 if (strcmp (target_buf
, "OK") != 0)
11841 error (_("Bogus reply from target: %s"), target_buf
);
11845 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11847 /* Initialize it just to avoid a GCC false warning. */
11849 /* FIXME we need to get register block size some other way. */
11850 extern int trace_regblock_size
;
11851 enum packet_result result
;
11853 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11856 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11858 putpkt ("qTStatus");
11862 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11864 CATCH (ex
, RETURN_MASK_ERROR
)
11866 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11868 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11871 throw_exception (ex
);
11875 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11877 /* If the remote target doesn't do tracing, flag it. */
11878 if (result
== PACKET_UNKNOWN
)
11881 /* We're working with a live target. */
11882 ts
->filename
= NULL
;
11885 error (_("Bogus trace status reply from target: %s"), target_buf
);
11887 /* Function 'parse_trace_status' sets default value of each field of
11888 'ts' at first, so we don't have to do it here. */
11889 parse_trace_status (p
, ts
);
11891 return ts
->running
;
11895 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11896 struct uploaded_tp
*utp
)
11898 struct remote_state
*rs
= get_remote_state ();
11900 struct bp_location
*loc
;
11901 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11902 size_t size
= get_remote_packet_size ();
11906 tp
->base
.hit_count
= 0;
11907 tp
->traceframe_usage
= 0;
11908 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11910 /* If the tracepoint was never downloaded, don't go asking for
11912 if (tp
->number_on_target
== 0)
11914 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11915 phex_nz (loc
->address
, 0));
11917 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11918 if (reply
&& *reply
)
11921 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11927 utp
->hit_count
= 0;
11928 utp
->traceframe_usage
= 0;
11929 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11930 phex_nz (utp
->addr
, 0));
11932 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11933 if (reply
&& *reply
)
11936 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11942 remote_trace_stop (struct target_ops
*self
)
11945 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11946 if (*target_buf
== '\0')
11947 error (_("Target does not support this command."));
11948 if (strcmp (target_buf
, "OK") != 0)
11949 error (_("Bogus reply from target: %s"), target_buf
);
11953 remote_trace_find (struct target_ops
*self
,
11954 enum trace_find_type type
, int num
,
11955 CORE_ADDR addr1
, CORE_ADDR addr2
,
11958 struct remote_state
*rs
= get_remote_state ();
11959 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11961 int target_frameno
= -1, target_tracept
= -1;
11963 /* Lookups other than by absolute frame number depend on the current
11964 trace selected, so make sure it is correct on the remote end
11966 if (type
!= tfind_number
)
11967 set_remote_traceframe ();
11970 strcpy (p
, "QTFrame:");
11971 p
= strchr (p
, '\0');
11975 xsnprintf (p
, endbuf
- p
, "%x", num
);
11978 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11981 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11984 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11985 phex_nz (addr2
, 0));
11987 case tfind_outside
:
11988 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11989 phex_nz (addr2
, 0));
11992 error (_("Unknown trace find type %d"), type
);
11996 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11997 if (*reply
== '\0')
11998 error (_("Target does not support this command."));
12000 while (reply
&& *reply
)
12005 target_frameno
= (int) strtol (p
, &reply
, 16);
12007 error (_("Unable to parse trace frame number"));
12008 /* Don't update our remote traceframe number cache on failure
12009 to select a remote traceframe. */
12010 if (target_frameno
== -1)
12015 target_tracept
= (int) strtol (p
, &reply
, 16);
12017 error (_("Unable to parse tracepoint number"));
12019 case 'O': /* "OK"? */
12020 if (reply
[1] == 'K' && reply
[2] == '\0')
12023 error (_("Bogus reply from target: %s"), reply
);
12026 error (_("Bogus reply from target: %s"), reply
);
12029 *tpp
= target_tracept
;
12031 rs
->remote_traceframe_number
= target_frameno
;
12032 return target_frameno
;
12036 remote_get_trace_state_variable_value (struct target_ops
*self
,
12037 int tsvnum
, LONGEST
*val
)
12039 struct remote_state
*rs
= get_remote_state ();
12043 set_remote_traceframe ();
12045 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12047 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12048 if (reply
&& *reply
)
12052 unpack_varlen_hex (reply
+ 1, &uval
);
12053 *val
= (LONGEST
) uval
;
12061 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12063 struct remote_state
*rs
= get_remote_state ();
12067 strcpy (p
, "QTSave:");
12069 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12070 error (_("Remote file name too long for trace save packet"));
12071 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12074 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12075 if (*reply
== '\0')
12076 error (_("Target does not support this command."));
12077 if (strcmp (reply
, "OK") != 0)
12078 error (_("Bogus reply from target: %s"), reply
);
12082 /* This is basically a memory transfer, but needs to be its own packet
12083 because we don't know how the target actually organizes its trace
12084 memory, plus we want to be able to ask for as much as possible, but
12085 not be unhappy if we don't get as much as we ask for. */
12088 remote_get_raw_trace_data (struct target_ops
*self
,
12089 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12091 struct remote_state
*rs
= get_remote_state ();
12097 strcpy (p
, "qTBuffer:");
12099 p
+= hexnumstr (p
, offset
);
12101 p
+= hexnumstr (p
, len
);
12105 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12106 if (reply
&& *reply
)
12108 /* 'l' by itself means we're at the end of the buffer and
12109 there is nothing more to get. */
12113 /* Convert the reply into binary. Limit the number of bytes to
12114 convert according to our passed-in buffer size, rather than
12115 what was returned in the packet; if the target is
12116 unexpectedly generous and gives us a bigger reply than we
12117 asked for, we don't want to crash. */
12118 rslt
= hex2bin (target_buf
, buf
, len
);
12122 /* Something went wrong, flag as an error. */
12127 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12129 struct remote_state
*rs
= get_remote_state ();
12131 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12135 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12137 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12138 if (*reply
== '\0')
12139 error (_("Target does not support this command."));
12140 if (strcmp (reply
, "OK") != 0)
12141 error (_("Bogus reply from target: %s"), reply
);
12144 warning (_("Target does not support disconnected tracing."));
12148 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12150 struct thread_info
*info
= find_thread_ptid (ptid
);
12152 if (info
&& info
->priv
)
12153 return info
->priv
->core
;
12158 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12160 struct remote_state
*rs
= get_remote_state ();
12163 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12165 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12166 if (*reply
== '\0')
12167 error (_("Target does not support this command."));
12168 if (strcmp (reply
, "OK") != 0)
12169 error (_("Bogus reply from target: %s"), reply
);
12172 static struct traceframe_info
*
12173 remote_traceframe_info (struct target_ops
*self
)
12177 text
= target_read_stralloc (¤t_target
,
12178 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12181 struct traceframe_info
*info
;
12182 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12184 info
= parse_traceframe_info (text
);
12185 do_cleanups (back_to
);
12192 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12193 instruction on which a fast tracepoint may be placed. Returns -1
12194 if the packet is not supported, and 0 if the minimum instruction
12195 length is unknown. */
12198 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12200 struct remote_state
*rs
= get_remote_state ();
12203 /* If we're not debugging a process yet, the IPA can't be
12205 if (!target_has_execution
)
12208 /* Make sure the remote is pointing at the right process. */
12209 set_general_process ();
12211 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12213 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12214 if (*reply
== '\0')
12218 ULONGEST min_insn_len
;
12220 unpack_varlen_hex (reply
, &min_insn_len
);
12222 return (int) min_insn_len
;
12227 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12229 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12231 struct remote_state
*rs
= get_remote_state ();
12232 char *buf
= rs
->buf
;
12233 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12234 enum packet_result result
;
12236 gdb_assert (val
>= 0 || val
== -1);
12237 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12238 /* Send -1 as literal "-1" to avoid host size dependency. */
12242 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12245 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12248 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12249 result
= packet_ok (rs
->buf
,
12250 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12252 if (result
!= PACKET_OK
)
12253 warning (_("Bogus reply from target: %s"), rs
->buf
);
12258 remote_set_trace_notes (struct target_ops
*self
,
12259 const char *user
, const char *notes
,
12260 const char *stop_notes
)
12262 struct remote_state
*rs
= get_remote_state ();
12264 char *buf
= rs
->buf
;
12265 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12268 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12271 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12272 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12278 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12279 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12285 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12286 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12290 /* Ensure the buffer is terminated. */
12294 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12295 if (*reply
== '\0')
12298 if (strcmp (reply
, "OK") != 0)
12299 error (_("Bogus reply from target: %s"), reply
);
12305 remote_use_agent (struct target_ops
*self
, int use
)
12307 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12309 struct remote_state
*rs
= get_remote_state ();
12311 /* If the stub supports QAgent. */
12312 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12314 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12316 if (strcmp (rs
->buf
, "OK") == 0)
12327 remote_can_use_agent (struct target_ops
*self
)
12329 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12332 struct btrace_target_info
12334 /* The ptid of the traced thread. */
12337 /* The obtained branch trace configuration. */
12338 struct btrace_config conf
;
12341 /* Reset our idea of our target's btrace configuration. */
12344 remote_btrace_reset (void)
12346 struct remote_state
*rs
= get_remote_state ();
12348 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12351 /* Check whether the target supports branch tracing. */
12354 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12356 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12358 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12363 case BTRACE_FORMAT_NONE
:
12366 case BTRACE_FORMAT_BTS
:
12367 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12369 case BTRACE_FORMAT_PT
:
12370 /* The trace is decoded on the host. Even if our target supports it,
12371 we still need to have libipt to decode the trace. */
12372 #if defined (HAVE_LIBIPT)
12373 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12374 #else /* !defined (HAVE_LIBIPT) */
12376 #endif /* !defined (HAVE_LIBIPT) */
12379 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12382 /* Synchronize the configuration with the target. */
12385 btrace_sync_conf (const struct btrace_config
*conf
)
12387 struct packet_config
*packet
;
12388 struct remote_state
*rs
;
12389 char *buf
, *pos
, *endbuf
;
12391 rs
= get_remote_state ();
12393 endbuf
= buf
+ get_remote_packet_size ();
12395 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12396 if (packet_config_support (packet
) == PACKET_ENABLE
12397 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12400 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12404 getpkt (&buf
, &rs
->buf_size
, 0);
12406 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12408 if (buf
[0] == 'E' && buf
[1] == '.')
12409 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12411 error (_("Failed to configure the BTS buffer size."));
12414 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12417 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12418 if (packet_config_support (packet
) == PACKET_ENABLE
12419 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12422 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12426 getpkt (&buf
, &rs
->buf_size
, 0);
12428 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12430 if (buf
[0] == 'E' && buf
[1] == '.')
12431 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12433 error (_("Failed to configure the trace buffer size."));
12436 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12440 /* Read the current thread's btrace configuration from the target and
12441 store it into CONF. */
12444 btrace_read_config (struct btrace_config
*conf
)
12448 xml
= target_read_stralloc (¤t_target
,
12449 TARGET_OBJECT_BTRACE_CONF
, "");
12452 struct cleanup
*cleanup
;
12454 cleanup
= make_cleanup (xfree
, xml
);
12455 parse_xml_btrace_conf (conf
, xml
);
12456 do_cleanups (cleanup
);
12460 /* Enable branch tracing. */
12462 static struct btrace_target_info
*
12463 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12464 const struct btrace_config
*conf
)
12466 struct btrace_target_info
*tinfo
= NULL
;
12467 struct packet_config
*packet
= NULL
;
12468 struct remote_state
*rs
= get_remote_state ();
12469 char *buf
= rs
->buf
;
12470 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12472 switch (conf
->format
)
12474 case BTRACE_FORMAT_BTS
:
12475 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12478 case BTRACE_FORMAT_PT
:
12479 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12483 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12484 error (_("Target does not support branch tracing."));
12486 btrace_sync_conf (conf
);
12488 set_general_thread (ptid
);
12490 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12492 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12494 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12496 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12497 error (_("Could not enable branch tracing for %s: %s"),
12498 target_pid_to_str (ptid
), rs
->buf
+ 2);
12500 error (_("Could not enable branch tracing for %s."),
12501 target_pid_to_str (ptid
));
12504 tinfo
= XCNEW (struct btrace_target_info
);
12505 tinfo
->ptid
= ptid
;
12507 /* If we fail to read the configuration, we lose some information, but the
12508 tracing itself is not impacted. */
12511 btrace_read_config (&tinfo
->conf
);
12513 CATCH (err
, RETURN_MASK_ERROR
)
12515 if (err
.message
!= NULL
)
12516 warning ("%s", err
.message
);
12523 /* Disable branch tracing. */
12526 remote_disable_btrace (struct target_ops
*self
,
12527 struct btrace_target_info
*tinfo
)
12529 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12530 struct remote_state
*rs
= get_remote_state ();
12531 char *buf
= rs
->buf
;
12532 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12534 if (packet_config_support (packet
) != PACKET_ENABLE
)
12535 error (_("Target does not support branch tracing."));
12537 set_general_thread (tinfo
->ptid
);
12539 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12541 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12543 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12545 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12546 error (_("Could not disable branch tracing for %s: %s"),
12547 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12549 error (_("Could not disable branch tracing for %s."),
12550 target_pid_to_str (tinfo
->ptid
));
12556 /* Teardown branch tracing. */
12559 remote_teardown_btrace (struct target_ops
*self
,
12560 struct btrace_target_info
*tinfo
)
12562 /* We must not talk to the target during teardown. */
12566 /* Read the branch trace. */
12568 static enum btrace_error
12569 remote_read_btrace (struct target_ops
*self
,
12570 struct btrace_data
*btrace
,
12571 struct btrace_target_info
*tinfo
,
12572 enum btrace_read_type type
)
12574 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12575 struct remote_state
*rs
= get_remote_state ();
12576 struct cleanup
*cleanup
;
12580 if (packet_config_support (packet
) != PACKET_ENABLE
)
12581 error (_("Target does not support branch tracing."));
12583 #if !defined(HAVE_LIBEXPAT)
12584 error (_("Cannot process branch tracing result. XML parsing not supported."));
12589 case BTRACE_READ_ALL
:
12592 case BTRACE_READ_NEW
:
12595 case BTRACE_READ_DELTA
:
12599 internal_error (__FILE__
, __LINE__
,
12600 _("Bad branch tracing read type: %u."),
12601 (unsigned int) type
);
12604 xml
= target_read_stralloc (¤t_target
,
12605 TARGET_OBJECT_BTRACE
, annex
);
12607 return BTRACE_ERR_UNKNOWN
;
12609 cleanup
= make_cleanup (xfree
, xml
);
12610 parse_xml_btrace (btrace
, xml
);
12611 do_cleanups (cleanup
);
12613 return BTRACE_ERR_NONE
;
12616 static const struct btrace_config
*
12617 remote_btrace_conf (struct target_ops
*self
,
12618 const struct btrace_target_info
*tinfo
)
12620 return &tinfo
->conf
;
12624 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12626 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12630 /* Implementation of to_load. */
12633 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12635 generic_load (name
, from_tty
);
12638 /* Accepts an integer PID; returns a string representing a file that
12639 can be opened on the remote side to get the symbols for the child
12640 process. Returns NULL if the operation is not supported. */
12643 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12645 static char *filename
= NULL
;
12646 struct inferior
*inf
;
12647 char *annex
= NULL
;
12649 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12652 if (filename
!= NULL
)
12655 inf
= find_inferior_pid (pid
);
12657 internal_error (__FILE__
, __LINE__
,
12658 _("not currently attached to process %d"), pid
);
12660 if (!inf
->fake_pid_p
)
12662 const int annex_size
= 9;
12664 annex
= (char *) alloca (annex_size
);
12665 xsnprintf (annex
, annex_size
, "%x", pid
);
12668 filename
= target_read_stralloc (¤t_target
,
12669 TARGET_OBJECT_EXEC_FILE
, annex
);
12674 /* Implement the to_can_do_single_step target_ops method. */
12677 remote_can_do_single_step (struct target_ops
*ops
)
12679 /* We can only tell whether target supports single step or not by
12680 supported s and S vCont actions if the stub supports vContSupported
12681 feature. If the stub doesn't support vContSupported feature,
12682 we have conservatively to think target doesn't supports single
12684 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
12686 struct remote_state
*rs
= get_remote_state ();
12688 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12689 remote_vcont_probe (rs
);
12691 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
12698 init_remote_ops (void)
12700 remote_ops
.to_shortname
= "remote";
12701 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12702 remote_ops
.to_doc
=
12703 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12704 Specify the serial device it is connected to\n\
12705 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12706 remote_ops
.to_open
= remote_open
;
12707 remote_ops
.to_close
= remote_close
;
12708 remote_ops
.to_detach
= remote_detach
;
12709 remote_ops
.to_disconnect
= remote_disconnect
;
12710 remote_ops
.to_resume
= remote_resume
;
12711 remote_ops
.to_wait
= remote_wait
;
12712 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12713 remote_ops
.to_store_registers
= remote_store_registers
;
12714 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12715 remote_ops
.to_files_info
= remote_files_info
;
12716 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12717 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12718 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12719 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12720 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12721 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12722 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12723 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12724 remote_ops
.to_watchpoint_addr_within_range
=
12725 remote_watchpoint_addr_within_range
;
12726 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12727 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12728 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12729 remote_ops
.to_region_ok_for_hw_watchpoint
12730 = remote_region_ok_for_hw_watchpoint
;
12731 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12732 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12733 remote_ops
.to_kill
= remote_kill
;
12734 remote_ops
.to_load
= remote_load
;
12735 remote_ops
.to_mourn_inferior
= remote_mourn
;
12736 remote_ops
.to_pass_signals
= remote_pass_signals
;
12737 remote_ops
.to_program_signals
= remote_program_signals
;
12738 remote_ops
.to_thread_alive
= remote_thread_alive
;
12739 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12740 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12741 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12742 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12743 remote_ops
.to_stop
= remote_stop
;
12744 remote_ops
.to_interrupt
= remote_interrupt
;
12745 remote_ops
.to_check_pending_interrupt
= remote_check_pending_interrupt
;
12746 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12747 remote_ops
.to_rcmd
= remote_rcmd
;
12748 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12749 remote_ops
.to_log_command
= serial_log_command
;
12750 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12751 remote_ops
.to_stratum
= process_stratum
;
12752 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12753 remote_ops
.to_has_memory
= default_child_has_memory
;
12754 remote_ops
.to_has_stack
= default_child_has_stack
;
12755 remote_ops
.to_has_registers
= default_child_has_registers
;
12756 remote_ops
.to_has_execution
= default_child_has_execution
;
12757 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12758 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12759 remote_ops
.to_magic
= OPS_MAGIC
;
12760 remote_ops
.to_memory_map
= remote_memory_map
;
12761 remote_ops
.to_flash_erase
= remote_flash_erase
;
12762 remote_ops
.to_flash_done
= remote_flash_done
;
12763 remote_ops
.to_read_description
= remote_read_description
;
12764 remote_ops
.to_search_memory
= remote_search_memory
;
12765 remote_ops
.to_can_async_p
= remote_can_async_p
;
12766 remote_ops
.to_is_async_p
= remote_is_async_p
;
12767 remote_ops
.to_async
= remote_async
;
12768 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
12769 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12770 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12771 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12772 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12773 remote_ops
.to_supports_disable_randomization
12774 = remote_supports_disable_randomization
;
12775 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12776 remote_ops
.to_fileio_open
= remote_hostio_open
;
12777 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12778 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12779 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12780 remote_ops
.to_fileio_close
= remote_hostio_close
;
12781 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12782 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12783 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12784 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12785 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12786 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12787 remote_ops
.to_trace_init
= remote_trace_init
;
12788 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12789 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12790 remote_ops
.to_download_trace_state_variable
12791 = remote_download_trace_state_variable
;
12792 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12793 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12794 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12795 remote_ops
.to_trace_start
= remote_trace_start
;
12796 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12797 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12798 remote_ops
.to_trace_stop
= remote_trace_stop
;
12799 remote_ops
.to_trace_find
= remote_trace_find
;
12800 remote_ops
.to_get_trace_state_variable_value
12801 = remote_get_trace_state_variable_value
;
12802 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12803 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12804 remote_ops
.to_upload_trace_state_variables
12805 = remote_upload_trace_state_variables
;
12806 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12807 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12808 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12809 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12810 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12811 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12812 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12813 remote_ops
.to_verify_memory
= remote_verify_memory
;
12814 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12815 remote_ops
.to_set_permissions
= remote_set_permissions
;
12816 remote_ops
.to_static_tracepoint_marker_at
12817 = remote_static_tracepoint_marker_at
;
12818 remote_ops
.to_static_tracepoint_markers_by_strid
12819 = remote_static_tracepoint_markers_by_strid
;
12820 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12821 remote_ops
.to_use_agent
= remote_use_agent
;
12822 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12823 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12824 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12825 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12826 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12827 remote_ops
.to_read_btrace
= remote_read_btrace
;
12828 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12829 remote_ops
.to_augmented_libraries_svr4_read
=
12830 remote_augmented_libraries_svr4_read
;
12833 /* Set up the extended remote vector by making a copy of the standard
12834 remote vector and adding to it. */
12837 init_extended_remote_ops (void)
12839 extended_remote_ops
= remote_ops
;
12841 extended_remote_ops
.to_shortname
= "extended-remote";
12842 extended_remote_ops
.to_longname
=
12843 "Extended remote serial target in gdb-specific protocol";
12844 extended_remote_ops
.to_doc
=
12845 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12846 Specify the serial device it is connected to (e.g. /dev/ttya).";
12847 extended_remote_ops
.to_open
= extended_remote_open
;
12848 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12849 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12850 extended_remote_ops
.to_detach
= extended_remote_detach
;
12851 extended_remote_ops
.to_attach
= extended_remote_attach
;
12852 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12853 extended_remote_ops
.to_kill
= extended_remote_kill
;
12854 extended_remote_ops
.to_supports_disable_randomization
12855 = extended_remote_supports_disable_randomization
;
12856 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12857 extended_remote_ops
.to_follow_exec
= remote_follow_exec
;
12858 extended_remote_ops
.to_insert_fork_catchpoint
12859 = remote_insert_fork_catchpoint
;
12860 extended_remote_ops
.to_remove_fork_catchpoint
12861 = remote_remove_fork_catchpoint
;
12862 extended_remote_ops
.to_insert_vfork_catchpoint
12863 = remote_insert_vfork_catchpoint
;
12864 extended_remote_ops
.to_remove_vfork_catchpoint
12865 = remote_remove_vfork_catchpoint
;
12866 extended_remote_ops
.to_insert_exec_catchpoint
12867 = remote_insert_exec_catchpoint
;
12868 extended_remote_ops
.to_remove_exec_catchpoint
12869 = remote_remove_exec_catchpoint
;
12873 remote_can_async_p (struct target_ops
*ops
)
12875 struct remote_state
*rs
= get_remote_state ();
12877 if (!target_async_permitted
)
12878 /* We only enable async when the user specifically asks for it. */
12881 /* We're async whenever the serial device is. */
12882 return serial_can_async_p (rs
->remote_desc
);
12886 remote_is_async_p (struct target_ops
*ops
)
12888 struct remote_state
*rs
= get_remote_state ();
12890 if (!target_async_permitted
)
12891 /* We only enable async when the user specifically asks for it. */
12894 /* We're async whenever the serial device is. */
12895 return serial_is_async_p (rs
->remote_desc
);
12898 /* Pass the SERIAL event on and up to the client. One day this code
12899 will be able to delay notifying the client of an event until the
12900 point where an entire packet has been received. */
12902 static serial_event_ftype remote_async_serial_handler
;
12905 remote_async_serial_handler (struct serial
*scb
, void *context
)
12907 struct remote_state
*rs
= (struct remote_state
*) context
;
12909 /* Don't propogate error information up to the client. Instead let
12910 the client find out about the error by querying the target. */
12911 inferior_event_handler (INF_REG_EVENT
, NULL
);
12915 remote_async_inferior_event_handler (gdb_client_data data
)
12917 inferior_event_handler (INF_REG_EVENT
, NULL
);
12921 remote_async (struct target_ops
*ops
, int enable
)
12923 struct remote_state
*rs
= get_remote_state ();
12927 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12929 /* If there are pending events in the stop reply queue tell the
12930 event loop to process them. */
12931 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12932 mark_async_event_handler (remote_async_inferior_event_token
);
12936 serial_async (rs
->remote_desc
, NULL
, NULL
);
12937 clear_async_event_handler (remote_async_inferior_event_token
);
12942 set_remote_cmd (char *args
, int from_tty
)
12944 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12948 show_remote_cmd (char *args
, int from_tty
)
12950 /* We can't just use cmd_show_list here, because we want to skip
12951 the redundant "show remote Z-packet" and the legacy aliases. */
12952 struct cleanup
*showlist_chain
;
12953 struct cmd_list_element
*list
= remote_show_cmdlist
;
12954 struct ui_out
*uiout
= current_uiout
;
12956 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12957 for (; list
!= NULL
; list
= list
->next
)
12958 if (strcmp (list
->name
, "Z-packet") == 0)
12960 else if (list
->type
== not_set_cmd
)
12961 /* Alias commands are exactly like the original, except they
12962 don't have the normal type. */
12966 struct cleanup
*option_chain
12967 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12969 ui_out_field_string (uiout
, "name", list
->name
);
12970 ui_out_text (uiout
, ": ");
12971 if (list
->type
== show_cmd
)
12972 do_show_command ((char *) NULL
, from_tty
, list
);
12974 cmd_func (list
, NULL
, from_tty
);
12975 /* Close the tuple. */
12976 do_cleanups (option_chain
);
12979 /* Close the tuple. */
12980 do_cleanups (showlist_chain
);
12984 /* Function to be called whenever a new objfile (shlib) is detected. */
12986 remote_new_objfile (struct objfile
*objfile
)
12988 struct remote_state
*rs
= get_remote_state ();
12990 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12991 remote_check_symbols ();
12994 /* Pull all the tracepoints defined on the target and create local
12995 data structures representing them. We don't want to create real
12996 tracepoints yet, we don't want to mess up the user's existing
13000 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13002 struct remote_state
*rs
= get_remote_state ();
13005 /* Ask for a first packet of tracepoint definition. */
13007 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13009 while (*p
&& *p
!= 'l')
13011 parse_tracepoint_definition (p
, utpp
);
13012 /* Ask for another packet of tracepoint definition. */
13014 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13021 remote_upload_trace_state_variables (struct target_ops
*self
,
13022 struct uploaded_tsv
**utsvp
)
13024 struct remote_state
*rs
= get_remote_state ();
13027 /* Ask for a first packet of variable definition. */
13029 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13031 while (*p
&& *p
!= 'l')
13033 parse_tsv_definition (p
, utsvp
);
13034 /* Ask for another packet of variable definition. */
13036 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13042 /* The "set/show range-stepping" show hook. */
13045 show_range_stepping (struct ui_file
*file
, int from_tty
,
13046 struct cmd_list_element
*c
,
13049 fprintf_filtered (file
,
13050 _("Debugger's willingness to use range stepping "
13051 "is %s.\n"), value
);
13054 /* The "set/show range-stepping" set hook. */
13057 set_range_stepping (char *ignore_args
, int from_tty
,
13058 struct cmd_list_element
*c
)
13060 struct remote_state
*rs
= get_remote_state ();
13062 /* Whene enabling, check whether range stepping is actually
13063 supported by the target, and warn if not. */
13064 if (use_range_stepping
)
13066 if (rs
->remote_desc
!= NULL
)
13068 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13069 remote_vcont_probe (rs
);
13071 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13072 && rs
->supports_vCont
.r
)
13076 warning (_("Range stepping is not supported by the current target"));
13081 _initialize_remote (void)
13083 struct remote_state
*rs
;
13084 struct cmd_list_element
*cmd
;
13085 const char *cmd_name
;
13087 /* architecture specific data */
13088 remote_gdbarch_data_handle
=
13089 gdbarch_data_register_post_init (init_remote_state
);
13090 remote_g_packet_data_handle
=
13091 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13094 = register_program_space_data_with_cleanup (NULL
,
13095 remote_pspace_data_cleanup
);
13097 /* Initialize the per-target state. At the moment there is only one
13098 of these, not one per target. Only one target is active at a
13100 remote_state
= new_remote_state ();
13102 init_remote_ops ();
13103 add_target (&remote_ops
);
13105 init_extended_remote_ops ();
13106 add_target (&extended_remote_ops
);
13108 /* Hook into new objfile notification. */
13109 observer_attach_new_objfile (remote_new_objfile
);
13110 /* We're no longer interested in notification events of an inferior
13112 observer_attach_inferior_exit (discard_pending_stop_replies
);
13114 /* Set up signal handlers. */
13115 async_sigint_remote_token
=
13116 create_async_signal_handler (async_remote_interrupt
, NULL
);
13117 async_sigint_remote_twice_token
=
13118 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
13121 init_remote_threadtests ();
13124 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13125 /* set/show remote ... */
13127 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13128 Remote protocol specific variables\n\
13129 Configure various remote-protocol specific variables such as\n\
13130 the packets being used"),
13131 &remote_set_cmdlist
, "set remote ",
13132 0 /* allow-unknown */, &setlist
);
13133 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13134 Remote protocol specific variables\n\
13135 Configure various remote-protocol specific variables such as\n\
13136 the packets being used"),
13137 &remote_show_cmdlist
, "show remote ",
13138 0 /* allow-unknown */, &showlist
);
13140 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13141 Compare section data on target to the exec file.\n\
13142 Argument is a single section name (default: all loaded sections).\n\
13143 To compare only read-only loaded sections, specify the -r option."),
13146 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13147 Send an arbitrary packet to a remote target.\n\
13148 maintenance packet TEXT\n\
13149 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13150 this command sends the string TEXT to the inferior, and displays the\n\
13151 response packet. GDB supplies the initial `$' character, and the\n\
13152 terminating `#' character and checksum."),
13155 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13156 Set whether to send break if interrupted."), _("\
13157 Show whether to send break if interrupted."), _("\
13158 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13159 set_remotebreak
, show_remotebreak
,
13160 &setlist
, &showlist
);
13161 cmd_name
= "remotebreak";
13162 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13163 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13164 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13165 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13166 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13168 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13169 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13171 Set interrupt sequence to remote target."), _("\
13172 Show interrupt sequence to remote target."), _("\
13173 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13174 NULL
, show_interrupt_sequence
,
13175 &remote_set_cmdlist
,
13176 &remote_show_cmdlist
);
13178 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13179 &interrupt_on_connect
, _("\
13180 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13181 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13182 If set, interrupt sequence is sent to remote target."),
13184 &remote_set_cmdlist
, &remote_show_cmdlist
);
13186 /* Install commands for configuring memory read/write packets. */
13188 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13189 Set the maximum number of bytes per memory write packet (deprecated)."),
13191 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13192 Show the maximum number of bytes per memory write packet (deprecated)."),
13194 add_cmd ("memory-write-packet-size", no_class
,
13195 set_memory_write_packet_size
, _("\
13196 Set the maximum number of bytes per memory-write packet.\n\
13197 Specify the number of bytes in a packet or 0 (zero) for the\n\
13198 default packet size. The actual limit is further reduced\n\
13199 dependent on the target. Specify ``fixed'' to disable the\n\
13200 further restriction and ``limit'' to enable that restriction."),
13201 &remote_set_cmdlist
);
13202 add_cmd ("memory-read-packet-size", no_class
,
13203 set_memory_read_packet_size
, _("\
13204 Set the maximum number of bytes per memory-read packet.\n\
13205 Specify the number of bytes in a packet or 0 (zero) for the\n\
13206 default packet size. The actual limit is further reduced\n\
13207 dependent on the target. Specify ``fixed'' to disable the\n\
13208 further restriction and ``limit'' to enable that restriction."),
13209 &remote_set_cmdlist
);
13210 add_cmd ("memory-write-packet-size", no_class
,
13211 show_memory_write_packet_size
,
13212 _("Show the maximum number of bytes per memory-write packet."),
13213 &remote_show_cmdlist
);
13214 add_cmd ("memory-read-packet-size", no_class
,
13215 show_memory_read_packet_size
,
13216 _("Show the maximum number of bytes per memory-read packet."),
13217 &remote_show_cmdlist
);
13219 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13220 &remote_hw_watchpoint_limit
, _("\
13221 Set the maximum number of target hardware watchpoints."), _("\
13222 Show the maximum number of target hardware watchpoints."), _("\
13223 Specify a negative limit for unlimited."),
13224 NULL
, NULL
, /* FIXME: i18n: The maximum
13225 number of target hardware
13226 watchpoints is %s. */
13227 &remote_set_cmdlist
, &remote_show_cmdlist
);
13228 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13229 &remote_hw_watchpoint_length_limit
, _("\
13230 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13231 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13232 Specify a negative limit for unlimited."),
13233 NULL
, NULL
, /* FIXME: i18n: The maximum
13234 length (in bytes) of a target
13235 hardware watchpoint is %s. */
13236 &remote_set_cmdlist
, &remote_show_cmdlist
);
13237 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13238 &remote_hw_breakpoint_limit
, _("\
13239 Set the maximum number of target hardware breakpoints."), _("\
13240 Show the maximum number of target hardware breakpoints."), _("\
13241 Specify a negative limit for unlimited."),
13242 NULL
, NULL
, /* FIXME: i18n: The maximum
13243 number of target hardware
13244 breakpoints is %s. */
13245 &remote_set_cmdlist
, &remote_show_cmdlist
);
13247 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13248 &remote_address_size
, _("\
13249 Set the maximum size of the address (in bits) in a memory packet."), _("\
13250 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13252 NULL
, /* FIXME: i18n: */
13253 &setlist
, &showlist
);
13255 init_all_packet_configs ();
13257 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13258 "X", "binary-download", 1);
13260 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13261 "vCont", "verbose-resume", 0);
13263 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13264 "QPassSignals", "pass-signals", 0);
13266 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13267 "QProgramSignals", "program-signals", 0);
13269 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13270 "qSymbol", "symbol-lookup", 0);
13272 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13273 "P", "set-register", 1);
13275 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13276 "p", "fetch-register", 1);
13278 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13279 "Z0", "software-breakpoint", 0);
13281 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13282 "Z1", "hardware-breakpoint", 0);
13284 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13285 "Z2", "write-watchpoint", 0);
13287 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13288 "Z3", "read-watchpoint", 0);
13290 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13291 "Z4", "access-watchpoint", 0);
13293 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13294 "qXfer:auxv:read", "read-aux-vector", 0);
13296 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13297 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13299 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13300 "qXfer:features:read", "target-features", 0);
13302 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13303 "qXfer:libraries:read", "library-info", 0);
13305 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13306 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13308 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13309 "qXfer:memory-map:read", "memory-map", 0);
13311 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13312 "qXfer:spu:read", "read-spu-object", 0);
13314 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13315 "qXfer:spu:write", "write-spu-object", 0);
13317 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13318 "qXfer:osdata:read", "osdata", 0);
13320 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13321 "qXfer:threads:read", "threads", 0);
13323 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13324 "qXfer:siginfo:read", "read-siginfo-object", 0);
13326 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13327 "qXfer:siginfo:write", "write-siginfo-object", 0);
13329 add_packet_config_cmd
13330 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13331 "qXfer:traceframe-info:read", "traceframe-info", 0);
13333 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13334 "qXfer:uib:read", "unwind-info-block", 0);
13336 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13337 "qGetTLSAddr", "get-thread-local-storage-address",
13340 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13341 "qGetTIBAddr", "get-thread-information-block-address",
13344 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13345 "bc", "reverse-continue", 0);
13347 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13348 "bs", "reverse-step", 0);
13350 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13351 "qSupported", "supported-packets", 0);
13353 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13354 "qSearch:memory", "search-memory", 0);
13356 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13357 "qTStatus", "trace-status", 0);
13359 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13360 "vFile:setfs", "hostio-setfs", 0);
13362 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13363 "vFile:open", "hostio-open", 0);
13365 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13366 "vFile:pread", "hostio-pread", 0);
13368 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13369 "vFile:pwrite", "hostio-pwrite", 0);
13371 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13372 "vFile:close", "hostio-close", 0);
13374 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13375 "vFile:unlink", "hostio-unlink", 0);
13377 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13378 "vFile:readlink", "hostio-readlink", 0);
13380 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13381 "vFile:fstat", "hostio-fstat", 0);
13383 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13384 "vAttach", "attach", 0);
13386 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13389 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13390 "QStartNoAckMode", "noack", 0);
13392 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13393 "vKill", "kill", 0);
13395 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13396 "qAttached", "query-attached", 0);
13398 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13399 "ConditionalTracepoints",
13400 "conditional-tracepoints", 0);
13402 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13403 "ConditionalBreakpoints",
13404 "conditional-breakpoints", 0);
13406 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13407 "BreakpointCommands",
13408 "breakpoint-commands", 0);
13410 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13411 "FastTracepoints", "fast-tracepoints", 0);
13413 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13414 "TracepointSource", "TracepointSource", 0);
13416 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13417 "QAllow", "allow", 0);
13419 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13420 "StaticTracepoints", "static-tracepoints", 0);
13422 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13423 "InstallInTrace", "install-in-trace", 0);
13425 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13426 "qXfer:statictrace:read", "read-sdata-object", 0);
13428 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13429 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13431 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13432 "QDisableRandomization", "disable-randomization", 0);
13434 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13435 "QAgent", "agent", 0);
13437 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13438 "QTBuffer:size", "trace-buffer-size", 0);
13440 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13441 "Qbtrace:off", "disable-btrace", 0);
13443 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13444 "Qbtrace:bts", "enable-btrace-bts", 0);
13446 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13447 "Qbtrace:pt", "enable-btrace-pt", 0);
13449 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13450 "qXfer:btrace", "read-btrace", 0);
13452 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13453 "qXfer:btrace-conf", "read-btrace-conf", 0);
13455 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13456 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13458 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13459 "multiprocess-feature", "multiprocess-feature", 0);
13461 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13462 "swbreak-feature", "swbreak-feature", 0);
13464 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13465 "hwbreak-feature", "hwbreak-feature", 0);
13467 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13468 "fork-event-feature", "fork-event-feature", 0);
13470 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13471 "vfork-event-feature", "vfork-event-feature", 0);
13473 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13474 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13476 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13477 "vContSupported", "verbose-resume-supported", 0);
13479 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13480 "exec-event-feature", "exec-event-feature", 0);
13482 /* Assert that we've registered "set remote foo-packet" commands
13483 for all packet configs. */
13487 for (i
= 0; i
< PACKET_MAX
; i
++)
13489 /* Ideally all configs would have a command associated. Some
13490 still don't though. */
13495 case PACKET_QNonStop
:
13496 case PACKET_EnableDisableTracepoints_feature
:
13497 case PACKET_tracenz_feature
:
13498 case PACKET_DisconnectedTracing_feature
:
13499 case PACKET_augmented_libraries_svr4_read_feature
:
13501 /* Additions to this list need to be well justified:
13502 pre-existing packets are OK; new packets are not. */
13510 /* This catches both forgetting to add a config command, and
13511 forgetting to remove a packet from the exception list. */
13512 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13516 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13517 Z sub-packet has its own set and show commands, but users may
13518 have sets to this variable in their .gdbinit files (or in their
13520 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13521 &remote_Z_packet_detect
, _("\
13522 Set use of remote protocol `Z' packets"), _("\
13523 Show use of remote protocol `Z' packets "), _("\
13524 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13526 set_remote_protocol_Z_packet_cmd
,
13527 show_remote_protocol_Z_packet_cmd
,
13528 /* FIXME: i18n: Use of remote protocol
13529 `Z' packets is %s. */
13530 &remote_set_cmdlist
, &remote_show_cmdlist
);
13532 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13533 Manipulate files on the remote system\n\
13534 Transfer files to and from the remote target system."),
13535 &remote_cmdlist
, "remote ",
13536 0 /* allow-unknown */, &cmdlist
);
13538 add_cmd ("put", class_files
, remote_put_command
,
13539 _("Copy a local file to the remote system."),
13542 add_cmd ("get", class_files
, remote_get_command
,
13543 _("Copy a remote file to the local system."),
13546 add_cmd ("delete", class_files
, remote_delete_command
,
13547 _("Delete a remote file."),
13550 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13551 &remote_exec_file_var
, _("\
13552 Set the remote pathname for \"run\""), _("\
13553 Show the remote pathname for \"run\""), NULL
,
13554 set_remote_exec_file
,
13555 show_remote_exec_file
,
13556 &remote_set_cmdlist
,
13557 &remote_show_cmdlist
);
13559 add_setshow_boolean_cmd ("range-stepping", class_run
,
13560 &use_range_stepping
, _("\
13561 Enable or disable range stepping."), _("\
13562 Show whether target-assisted range stepping is enabled."), _("\
13563 If on, and the target supports it, when stepping a source line, GDB\n\
13564 tells the target to step the corresponding range of addresses itself instead\n\
13565 of issuing multiple single-steps. This speeds up source level\n\
13566 stepping. If off, GDB always issues single-steps, even if range\n\
13567 stepping is supported by the target. The default is on."),
13568 set_range_stepping
,
13569 show_range_stepping
,
13573 /* Eventually initialize fileio. See fileio.c */
13574 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13576 /* Take advantage of the fact that the TID field is not used, to tag
13577 special ptids with it set to != 0. */
13578 magic_null_ptid
= ptid_build (42000, -1, 1);
13579 not_sent_ptid
= ptid_build (42000, -2, 1);
13580 any_thread_ptid
= ptid_build (42000, 0, 1);
13582 target_buf_size
= 2048;
13583 target_buf
= (char *) xmalloc (target_buf_size
);