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
= 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 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
622 /* Fetch the global remote target state. */
624 static struct remote_state
*
625 get_remote_state (void)
627 /* Make sure that the remote architecture state has been
628 initialized, because doing so might reallocate rs->buf. Any
629 function which calls getpkt also needs to be mindful of changes
630 to rs->buf, but this call limits the number of places which run
632 get_remote_arch_state ();
634 return get_remote_state_raw ();
637 /* Cleanup routine for the remote module's pspace data. */
640 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
642 char *remote_exec_file
= arg
;
644 xfree (remote_exec_file
);
647 /* Fetch the remote exec-file from the current program space. */
650 get_remote_exec_file (void)
652 char *remote_exec_file
;
654 remote_exec_file
= program_space_data (current_program_space
,
656 if (remote_exec_file
== NULL
)
659 return remote_exec_file
;
662 /* Set the remote exec file for PSPACE. */
665 set_pspace_remote_exec_file (struct program_space
*pspace
,
666 char *remote_exec_file
)
668 char *old_file
= program_space_data (pspace
, remote_pspace_data
);
671 set_program_space_data (pspace
, remote_pspace_data
,
672 xstrdup (remote_exec_file
));
675 /* The "set/show remote exec-file" set command hook. */
678 set_remote_exec_file (char *ignored
, int from_tty
,
679 struct cmd_list_element
*c
)
681 gdb_assert (remote_exec_file_var
!= NULL
);
682 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
685 /* The "set/show remote exec-file" show command hook. */
688 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
689 struct cmd_list_element
*cmd
, const char *value
)
691 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
695 compare_pnums (const void *lhs_
, const void *rhs_
)
697 const struct packet_reg
* const *lhs
= lhs_
;
698 const struct packet_reg
* const *rhs
= rhs_
;
700 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
702 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
709 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
711 int regnum
, num_remote_regs
, offset
;
712 struct packet_reg
**remote_regs
;
714 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
716 struct packet_reg
*r
= ®s
[regnum
];
718 if (register_size (gdbarch
, regnum
) == 0)
719 /* Do not try to fetch zero-sized (placeholder) registers. */
722 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
727 /* Define the g/G packet format as the contents of each register
728 with a remote protocol number, in order of ascending protocol
731 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
732 * sizeof (struct packet_reg
*));
733 for (num_remote_regs
= 0, regnum
= 0;
734 regnum
< gdbarch_num_regs (gdbarch
);
736 if (regs
[regnum
].pnum
!= -1)
737 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
739 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
742 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
744 remote_regs
[regnum
]->in_g_packet
= 1;
745 remote_regs
[regnum
]->offset
= offset
;
746 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
752 /* Given the architecture described by GDBARCH, return the remote
753 protocol register's number and the register's offset in the g/G
754 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
755 If the target does not have a mapping for REGNUM, return false,
756 otherwise, return true. */
759 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
760 int *pnum
, int *poffset
)
763 struct packet_reg
*regs
;
764 struct cleanup
*old_chain
;
766 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
768 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
769 old_chain
= make_cleanup (xfree
, regs
);
771 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
773 *pnum
= regs
[regnum
].pnum
;
774 *poffset
= regs
[regnum
].offset
;
776 do_cleanups (old_chain
);
782 init_remote_state (struct gdbarch
*gdbarch
)
784 struct remote_state
*rs
= get_remote_state_raw ();
785 struct remote_arch_state
*rsa
;
787 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
789 /* Use the architecture to build a regnum<->pnum table, which will be
790 1:1 unless a feature set specifies otherwise. */
791 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
792 gdbarch_num_regs (gdbarch
),
795 /* Record the maximum possible size of the g packet - it may turn out
797 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
799 /* Default maximum number of characters in a packet body. Many
800 remote stubs have a hardwired buffer size of 400 bytes
801 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
802 as the maximum packet-size to ensure that the packet and an extra
803 NUL character can always fit in the buffer. This stops GDB
804 trashing stubs that try to squeeze an extra NUL into what is
805 already a full buffer (As of 1999-12-04 that was most stubs). */
806 rsa
->remote_packet_size
= 400 - 1;
808 /* This one is filled in when a ``g'' packet is received. */
809 rsa
->actual_register_packet_size
= 0;
811 /* Should rsa->sizeof_g_packet needs more space than the
812 default, adjust the size accordingly. Remember that each byte is
813 encoded as two characters. 32 is the overhead for the packet
814 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
815 (``$NN:G...#NN'') is a better guess, the below has been padded a
817 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
818 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
820 /* Make sure that the packet buffer is plenty big enough for
821 this architecture. */
822 if (rs
->buf_size
< rsa
->remote_packet_size
)
824 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
825 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
831 /* Return the current allowed size of a remote packet. This is
832 inferred from the current architecture, and should be used to
833 limit the length of outgoing packets. */
835 get_remote_packet_size (void)
837 struct remote_state
*rs
= get_remote_state ();
838 struct remote_arch_state
*rsa
= get_remote_arch_state ();
840 if (rs
->explicit_packet_size
)
841 return rs
->explicit_packet_size
;
843 return rsa
->remote_packet_size
;
846 static struct packet_reg
*
847 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
849 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
853 struct packet_reg
*r
= &rsa
->regs
[regnum
];
855 gdb_assert (r
->regnum
== regnum
);
860 static struct packet_reg
*
861 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
865 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
867 struct packet_reg
*r
= &rsa
->regs
[i
];
875 static struct target_ops remote_ops
;
877 static struct target_ops extended_remote_ops
;
879 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
880 ``forever'' still use the normal timeout mechanism. This is
881 currently used by the ASYNC code to guarentee that target reads
882 during the initial connect always time-out. Once getpkt has been
883 modified to return a timeout indication and, in turn
884 remote_wait()/wait_for_inferior() have gained a timeout parameter
886 static int wait_forever_enabled_p
= 1;
888 /* Allow the user to specify what sequence to send to the remote
889 when he requests a program interruption: Although ^C is usually
890 what remote systems expect (this is the default, here), it is
891 sometimes preferable to send a break. On other systems such
892 as the Linux kernel, a break followed by g, which is Magic SysRq g
893 is required in order to interrupt the execution. */
894 const char interrupt_sequence_control_c
[] = "Ctrl-C";
895 const char interrupt_sequence_break
[] = "BREAK";
896 const char interrupt_sequence_break_g
[] = "BREAK-g";
897 static const char *const interrupt_sequence_modes
[] =
899 interrupt_sequence_control_c
,
900 interrupt_sequence_break
,
901 interrupt_sequence_break_g
,
904 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
907 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
908 struct cmd_list_element
*c
,
911 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
912 fprintf_filtered (file
,
913 _("Send the ASCII ETX character (Ctrl-c) "
914 "to the remote target to interrupt the "
915 "execution of the program.\n"));
916 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
917 fprintf_filtered (file
,
918 _("send a break signal to the remote target "
919 "to interrupt the execution of the program.\n"));
920 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
921 fprintf_filtered (file
,
922 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
923 "the remote target to interrupt the execution "
924 "of Linux kernel.\n"));
926 internal_error (__FILE__
, __LINE__
,
927 _("Invalid value for interrupt_sequence_mode: %s."),
928 interrupt_sequence_mode
);
931 /* This boolean variable specifies whether interrupt_sequence is sent
932 to the remote target when gdb connects to it.
933 This is mostly needed when you debug the Linux kernel: The Linux kernel
934 expects BREAK g which is Magic SysRq g for connecting gdb. */
935 static int interrupt_on_connect
= 0;
937 /* This variable is used to implement the "set/show remotebreak" commands.
938 Since these commands are now deprecated in favor of "set/show remote
939 interrupt-sequence", it no longer has any effect on the code. */
940 static int remote_break
;
943 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
946 interrupt_sequence_mode
= interrupt_sequence_break
;
948 interrupt_sequence_mode
= interrupt_sequence_control_c
;
952 show_remotebreak (struct ui_file
*file
, int from_tty
,
953 struct cmd_list_element
*c
,
958 /* This variable sets the number of bits in an address that are to be
959 sent in a memory ("M" or "m") packet. Normally, after stripping
960 leading zeros, the entire address would be sent. This variable
961 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
962 initial implementation of remote.c restricted the address sent in
963 memory packets to ``host::sizeof long'' bytes - (typically 32
964 bits). Consequently, for 64 bit targets, the upper 32 bits of an
965 address was never sent. Since fixing this bug may cause a break in
966 some remote targets this variable is principly provided to
967 facilitate backward compatibility. */
969 static unsigned int remote_address_size
;
971 /* Temporary to track who currently owns the terminal. See
972 remote_terminal_* for more details. */
974 static int remote_async_terminal_ours_p
;
977 /* User configurable variables for the number of characters in a
978 memory read/write packet. MIN (rsa->remote_packet_size,
979 rsa->sizeof_g_packet) is the default. Some targets need smaller
980 values (fifo overruns, et.al.) and some users need larger values
981 (speed up transfers). The variables ``preferred_*'' (the user
982 request), ``current_*'' (what was actually set) and ``forced_*''
983 (Positive - a soft limit, negative - a hard limit). */
985 struct memory_packet_config
992 /* The default max memory-write-packet-size. The 16k is historical.
993 (It came from older GDB's using alloca for buffers and the
994 knowledge (folklore?) that some hosts don't cope very well with
995 large alloca calls.) */
996 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
998 /* The minimum remote packet size for memory transfers. Ensures we
999 can write at least one byte. */
1000 #define MIN_MEMORY_PACKET_SIZE 20
1002 /* Compute the current size of a read/write packet. Since this makes
1003 use of ``actual_register_packet_size'' the computation is dynamic. */
1006 get_memory_packet_size (struct memory_packet_config
*config
)
1008 struct remote_state
*rs
= get_remote_state ();
1009 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1012 if (config
->fixed_p
)
1014 if (config
->size
<= 0)
1015 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1017 what_they_get
= config
->size
;
1021 what_they_get
= get_remote_packet_size ();
1022 /* Limit the packet to the size specified by the user. */
1023 if (config
->size
> 0
1024 && what_they_get
> config
->size
)
1025 what_they_get
= config
->size
;
1027 /* Limit it to the size of the targets ``g'' response unless we have
1028 permission from the stub to use a larger packet size. */
1029 if (rs
->explicit_packet_size
== 0
1030 && rsa
->actual_register_packet_size
> 0
1031 && what_they_get
> rsa
->actual_register_packet_size
)
1032 what_they_get
= rsa
->actual_register_packet_size
;
1034 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1035 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1037 /* Make sure there is room in the global buffer for this packet
1038 (including its trailing NUL byte). */
1039 if (rs
->buf_size
< what_they_get
+ 1)
1041 rs
->buf_size
= 2 * what_they_get
;
1042 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
1045 return what_they_get
;
1048 /* Update the size of a read/write packet. If they user wants
1049 something really big then do a sanity check. */
1052 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1054 int fixed_p
= config
->fixed_p
;
1055 long size
= config
->size
;
1058 error (_("Argument required (integer, `fixed' or `limited')."));
1059 else if (strcmp (args
, "hard") == 0
1060 || strcmp (args
, "fixed") == 0)
1062 else if (strcmp (args
, "soft") == 0
1063 || strcmp (args
, "limit") == 0)
1069 size
= strtoul (args
, &end
, 0);
1071 error (_("Invalid %s (bad syntax)."), config
->name
);
1073 /* Instead of explicitly capping the size of a packet to or
1074 disallowing it, the user is allowed to set the size to
1075 something arbitrarily large. */
1078 /* So that the query shows the correct value. */
1080 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1083 if (fixed_p
&& !config
->fixed_p
)
1085 if (! query (_("The target may not be able to correctly handle a %s\n"
1086 "of %ld bytes. Change the packet size? "),
1087 config
->name
, size
))
1088 error (_("Packet size not changed."));
1090 /* Update the config. */
1091 config
->fixed_p
= fixed_p
;
1092 config
->size
= size
;
1096 show_memory_packet_size (struct memory_packet_config
*config
)
1098 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1099 if (config
->fixed_p
)
1100 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1101 get_memory_packet_size (config
));
1103 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1104 get_memory_packet_size (config
));
1107 static struct memory_packet_config memory_write_packet_config
=
1109 "memory-write-packet-size",
1113 set_memory_write_packet_size (char *args
, int from_tty
)
1115 set_memory_packet_size (args
, &memory_write_packet_config
);
1119 show_memory_write_packet_size (char *args
, int from_tty
)
1121 show_memory_packet_size (&memory_write_packet_config
);
1125 get_memory_write_packet_size (void)
1127 return get_memory_packet_size (&memory_write_packet_config
);
1130 static struct memory_packet_config memory_read_packet_config
=
1132 "memory-read-packet-size",
1136 set_memory_read_packet_size (char *args
, int from_tty
)
1138 set_memory_packet_size (args
, &memory_read_packet_config
);
1142 show_memory_read_packet_size (char *args
, int from_tty
)
1144 show_memory_packet_size (&memory_read_packet_config
);
1148 get_memory_read_packet_size (void)
1150 long size
= get_memory_packet_size (&memory_read_packet_config
);
1152 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1153 extra buffer size argument before the memory read size can be
1154 increased beyond this. */
1155 if (size
> get_remote_packet_size ())
1156 size
= get_remote_packet_size ();
1161 /* Generic configuration support for packets the stub optionally
1162 supports. Allows the user to specify the use of the packet as well
1163 as allowing GDB to auto-detect support in the remote stub. */
1167 PACKET_SUPPORT_UNKNOWN
= 0,
1172 struct packet_config
1177 /* If auto, GDB auto-detects support for this packet or feature,
1178 either through qSupported, or by trying the packet and looking
1179 at the response. If true, GDB assumes the target supports this
1180 packet. If false, the packet is disabled. Configs that don't
1181 have an associated command always have this set to auto. */
1182 enum auto_boolean detect
;
1184 /* Does the target support this packet? */
1185 enum packet_support support
;
1188 /* Analyze a packet's return value and update the packet config
1198 static enum packet_support
packet_config_support (struct packet_config
*config
);
1199 static enum packet_support
packet_support (int packet
);
1202 show_packet_config_cmd (struct packet_config
*config
)
1204 char *support
= "internal-error";
1206 switch (packet_config_support (config
))
1209 support
= "enabled";
1211 case PACKET_DISABLE
:
1212 support
= "disabled";
1214 case PACKET_SUPPORT_UNKNOWN
:
1215 support
= "unknown";
1218 switch (config
->detect
)
1220 case AUTO_BOOLEAN_AUTO
:
1221 printf_filtered (_("Support for the `%s' packet "
1222 "is auto-detected, currently %s.\n"),
1223 config
->name
, support
);
1225 case AUTO_BOOLEAN_TRUE
:
1226 case AUTO_BOOLEAN_FALSE
:
1227 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1228 config
->name
, support
);
1234 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1235 const char *title
, int legacy
)
1241 config
->name
= name
;
1242 config
->title
= title
;
1243 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1245 show_doc
= xstrprintf ("Show current use of remote "
1246 "protocol `%s' (%s) packet",
1248 /* set/show TITLE-packet {auto,on,off} */
1249 cmd_name
= xstrprintf ("%s-packet", title
);
1250 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1251 &config
->detect
, set_doc
,
1252 show_doc
, NULL
, /* help_doc */
1254 show_remote_protocol_packet_cmd
,
1255 &remote_set_cmdlist
, &remote_show_cmdlist
);
1256 /* The command code copies the documentation strings. */
1259 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1264 legacy_name
= xstrprintf ("%s-packet", name
);
1265 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1266 &remote_set_cmdlist
);
1267 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1268 &remote_show_cmdlist
);
1272 static enum packet_result
1273 packet_check_result (const char *buf
)
1277 /* The stub recognized the packet request. Check that the
1278 operation succeeded. */
1280 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1282 /* "Enn" - definitly an error. */
1283 return PACKET_ERROR
;
1285 /* Always treat "E." as an error. This will be used for
1286 more verbose error messages, such as E.memtypes. */
1287 if (buf
[0] == 'E' && buf
[1] == '.')
1288 return PACKET_ERROR
;
1290 /* The packet may or may not be OK. Just assume it is. */
1294 /* The stub does not support the packet. */
1295 return PACKET_UNKNOWN
;
1298 static enum packet_result
1299 packet_ok (const char *buf
, struct packet_config
*config
)
1301 enum packet_result result
;
1303 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1304 && config
->support
== PACKET_DISABLE
)
1305 internal_error (__FILE__
, __LINE__
,
1306 _("packet_ok: attempt to use a disabled packet"));
1308 result
= packet_check_result (buf
);
1313 /* The stub recognized the packet request. */
1314 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1317 fprintf_unfiltered (gdb_stdlog
,
1318 "Packet %s (%s) is supported\n",
1319 config
->name
, config
->title
);
1320 config
->support
= PACKET_ENABLE
;
1323 case PACKET_UNKNOWN
:
1324 /* The stub does not support the packet. */
1325 if (config
->detect
== AUTO_BOOLEAN_AUTO
1326 && config
->support
== PACKET_ENABLE
)
1328 /* If the stub previously indicated that the packet was
1329 supported then there is a protocol error. */
1330 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1331 config
->name
, config
->title
);
1333 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1335 /* The user set it wrong. */
1336 error (_("Enabled packet %s (%s) not recognized by stub"),
1337 config
->name
, config
->title
);
1341 fprintf_unfiltered (gdb_stdlog
,
1342 "Packet %s (%s) is NOT supported\n",
1343 config
->name
, config
->title
);
1344 config
->support
= PACKET_DISABLE
;
1365 PACKET_vFile_pwrite
,
1367 PACKET_vFile_unlink
,
1368 PACKET_vFile_readlink
,
1371 PACKET_qXfer_features
,
1372 PACKET_qXfer_exec_file
,
1373 PACKET_qXfer_libraries
,
1374 PACKET_qXfer_libraries_svr4
,
1375 PACKET_qXfer_memory_map
,
1376 PACKET_qXfer_spu_read
,
1377 PACKET_qXfer_spu_write
,
1378 PACKET_qXfer_osdata
,
1379 PACKET_qXfer_threads
,
1380 PACKET_qXfer_statictrace_read
,
1381 PACKET_qXfer_traceframe_info
,
1387 PACKET_QPassSignals
,
1388 PACKET_QProgramSignals
,
1390 PACKET_qSearch_memory
,
1393 PACKET_QStartNoAckMode
,
1395 PACKET_qXfer_siginfo_read
,
1396 PACKET_qXfer_siginfo_write
,
1399 /* Support for conditional tracepoints. */
1400 PACKET_ConditionalTracepoints
,
1402 /* Support for target-side breakpoint conditions. */
1403 PACKET_ConditionalBreakpoints
,
1405 /* Support for target-side breakpoint commands. */
1406 PACKET_BreakpointCommands
,
1408 /* Support for fast tracepoints. */
1409 PACKET_FastTracepoints
,
1411 /* Support for static tracepoints. */
1412 PACKET_StaticTracepoints
,
1414 /* Support for installing tracepoints while a trace experiment is
1416 PACKET_InstallInTrace
,
1420 PACKET_TracepointSource
,
1423 PACKET_QDisableRandomization
,
1425 PACKET_QTBuffer_size
,
1429 PACKET_qXfer_btrace
,
1431 /* Support for the QNonStop packet. */
1434 /* Support for multi-process extensions. */
1435 PACKET_multiprocess_feature
,
1437 /* Support for enabling and disabling tracepoints while a trace
1438 experiment is running. */
1439 PACKET_EnableDisableTracepoints_feature
,
1441 /* Support for collecting strings using the tracenz bytecode. */
1442 PACKET_tracenz_feature
,
1444 /* Support for continuing to run a trace experiment while GDB is
1446 PACKET_DisconnectedTracing_feature
,
1448 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1449 PACKET_augmented_libraries_svr4_read_feature
,
1451 /* Support for the qXfer:btrace-conf:read packet. */
1452 PACKET_qXfer_btrace_conf
,
1454 /* Support for the Qbtrace-conf:bts:size packet. */
1455 PACKET_Qbtrace_conf_bts_size
,
1457 /* Support for swbreak+ feature. */
1458 PACKET_swbreak_feature
,
1460 /* Support for hwbreak+ feature. */
1461 PACKET_hwbreak_feature
,
1463 /* Support for fork events. */
1464 PACKET_fork_event_feature
,
1466 /* Support for vfork events. */
1467 PACKET_vfork_event_feature
,
1469 /* Support for the Qbtrace-conf:pt:size packet. */
1470 PACKET_Qbtrace_conf_pt_size
,
1472 /* Support for exec events. */
1473 PACKET_exec_event_feature
,
1475 /* Support for query supported vCont actions. */
1476 PACKET_vContSupported
,
1481 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1483 /* Returns the packet's corresponding "set remote foo-packet" command
1484 state. See struct packet_config for more details. */
1486 static enum auto_boolean
1487 packet_set_cmd_state (int packet
)
1489 return remote_protocol_packets
[packet
].detect
;
1492 /* Returns whether a given packet or feature is supported. This takes
1493 into account the state of the corresponding "set remote foo-packet"
1494 command, which may be used to bypass auto-detection. */
1496 static enum packet_support
1497 packet_config_support (struct packet_config
*config
)
1499 switch (config
->detect
)
1501 case AUTO_BOOLEAN_TRUE
:
1502 return PACKET_ENABLE
;
1503 case AUTO_BOOLEAN_FALSE
:
1504 return PACKET_DISABLE
;
1505 case AUTO_BOOLEAN_AUTO
:
1506 return config
->support
;
1508 gdb_assert_not_reached (_("bad switch"));
1512 /* Same as packet_config_support, but takes the packet's enum value as
1515 static enum packet_support
1516 packet_support (int packet
)
1518 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1520 return packet_config_support (config
);
1524 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1525 struct cmd_list_element
*c
,
1528 struct packet_config
*packet
;
1530 for (packet
= remote_protocol_packets
;
1531 packet
< &remote_protocol_packets
[PACKET_MAX
];
1534 if (&packet
->detect
== c
->var
)
1536 show_packet_config_cmd (packet
);
1540 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1544 /* Should we try one of the 'Z' requests? */
1548 Z_PACKET_SOFTWARE_BP
,
1549 Z_PACKET_HARDWARE_BP
,
1556 /* For compatibility with older distributions. Provide a ``set remote
1557 Z-packet ...'' command that updates all the Z packet types. */
1559 static enum auto_boolean remote_Z_packet_detect
;
1562 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1563 struct cmd_list_element
*c
)
1567 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1568 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1572 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1573 struct cmd_list_element
*c
,
1578 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1580 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1584 /* Returns true if the multi-process extensions are in effect. */
1587 remote_multi_process_p (struct remote_state
*rs
)
1589 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1592 /* Returns true if fork events are supported. */
1595 remote_fork_event_p (struct remote_state
*rs
)
1597 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1600 /* Returns true if vfork events are supported. */
1603 remote_vfork_event_p (struct remote_state
*rs
)
1605 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1608 /* Returns true if exec events are supported. */
1611 remote_exec_event_p (struct remote_state
*rs
)
1613 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1616 /* Insert fork catchpoint target routine. If fork events are enabled
1617 then return success, nothing more to do. */
1620 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1622 struct remote_state
*rs
= get_remote_state ();
1624 return !remote_fork_event_p (rs
);
1627 /* Remove fork catchpoint target routine. Nothing to do, just
1631 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1636 /* Insert vfork catchpoint target routine. If vfork events are enabled
1637 then return success, nothing more to do. */
1640 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1642 struct remote_state
*rs
= get_remote_state ();
1644 return !remote_vfork_event_p (rs
);
1647 /* Remove vfork catchpoint target routine. Nothing to do, just
1651 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1656 /* Insert exec catchpoint target routine. If exec events are
1657 enabled, just return success. */
1660 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1662 struct remote_state
*rs
= get_remote_state ();
1664 return !remote_exec_event_p (rs
);
1667 /* Remove exec catchpoint target routine. Nothing to do, just
1671 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1676 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1677 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1678 static struct async_signal_handler
*async_sigint_remote_token
;
1681 /* Asynchronous signal handle registered as event loop source for
1682 when we have pending events ready to be passed to the core. */
1684 static struct async_event_handler
*remote_async_inferior_event_token
;
1688 static ptid_t magic_null_ptid
;
1689 static ptid_t not_sent_ptid
;
1690 static ptid_t any_thread_ptid
;
1692 /* Find out if the stub attached to PID (and hence GDB should offer to
1693 detach instead of killing it when bailing out). */
1696 remote_query_attached (int pid
)
1698 struct remote_state
*rs
= get_remote_state ();
1699 size_t size
= get_remote_packet_size ();
1701 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1704 if (remote_multi_process_p (rs
))
1705 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1707 xsnprintf (rs
->buf
, size
, "qAttached");
1710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1712 switch (packet_ok (rs
->buf
,
1713 &remote_protocol_packets
[PACKET_qAttached
]))
1716 if (strcmp (rs
->buf
, "1") == 0)
1720 warning (_("Remote failure reply: %s"), rs
->buf
);
1722 case PACKET_UNKNOWN
:
1729 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1730 has been invented by GDB, instead of reported by the target. Since
1731 we can be connected to a remote system before before knowing about
1732 any inferior, mark the target with execution when we find the first
1733 inferior. If ATTACHED is 1, then we had just attached to this
1734 inferior. If it is 0, then we just created this inferior. If it
1735 is -1, then try querying the remote stub to find out if it had
1736 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1737 attempt to open this inferior's executable as the main executable
1738 if no main executable is open already. */
1740 static struct inferior
*
1741 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1744 struct inferior
*inf
;
1746 /* Check whether this process we're learning about is to be
1747 considered attached, or if is to be considered to have been
1748 spawned by the stub. */
1750 attached
= remote_query_attached (pid
);
1752 if (gdbarch_has_global_solist (target_gdbarch ()))
1754 /* If the target shares code across all inferiors, then every
1755 attach adds a new inferior. */
1756 inf
= add_inferior (pid
);
1758 /* ... and every inferior is bound to the same program space.
1759 However, each inferior may still have its own address
1761 inf
->aspace
= maybe_new_address_space ();
1762 inf
->pspace
= current_program_space
;
1766 /* In the traditional debugging scenario, there's a 1-1 match
1767 between program/address spaces. We simply bind the inferior
1768 to the program space's address space. */
1769 inf
= current_inferior ();
1770 inferior_appeared (inf
, pid
);
1773 inf
->attach_flag
= attached
;
1774 inf
->fake_pid_p
= fake_pid_p
;
1776 /* If no main executable is currently open then attempt to
1777 open the file that was executed to create this inferior. */
1778 if (try_open_exec
&& get_exec_file (0) == NULL
)
1779 exec_file_locate_attach (pid
, 1);
1784 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1785 according to RUNNING. */
1788 remote_add_thread (ptid_t ptid
, int running
)
1790 struct remote_state
*rs
= get_remote_state ();
1792 /* GDB historically didn't pull threads in the initial connection
1793 setup. If the remote target doesn't even have a concept of
1794 threads (e.g., a bare-metal target), even if internally we
1795 consider that a single-threaded target, mentioning a new thread
1796 might be confusing to the user. Be silent then, preserving the
1797 age old behavior. */
1798 if (rs
->starting_up
)
1799 add_thread_silent (ptid
);
1803 set_executing (ptid
, running
);
1804 set_running (ptid
, running
);
1807 /* Come here when we learn about a thread id from the remote target.
1808 It may be the first time we hear about such thread, so take the
1809 opportunity to add it to GDB's thread list. In case this is the
1810 first time we're noticing its corresponding inferior, add it to
1811 GDB's inferior list as well. */
1814 remote_notice_new_inferior (ptid_t currthread
, int running
)
1816 /* If this is a new thread, add it to GDB's thread list.
1817 If we leave it up to WFI to do this, bad things will happen. */
1819 if (in_thread_list (currthread
) && is_exited (currthread
))
1821 /* We're seeing an event on a thread id we knew had exited.
1822 This has to be a new thread reusing the old id. Add it. */
1823 remote_add_thread (currthread
, running
);
1827 if (!in_thread_list (currthread
))
1829 struct inferior
*inf
= NULL
;
1830 int pid
= ptid_get_pid (currthread
);
1832 if (ptid_is_pid (inferior_ptid
)
1833 && pid
== ptid_get_pid (inferior_ptid
))
1835 /* inferior_ptid has no thread member yet. This can happen
1836 with the vAttach -> remote_wait,"TAAthread:" path if the
1837 stub doesn't support qC. This is the first stop reported
1838 after an attach, so this is the main thread. Update the
1839 ptid in the thread list. */
1840 if (in_thread_list (pid_to_ptid (pid
)))
1841 thread_change_ptid (inferior_ptid
, currthread
);
1844 remote_add_thread (currthread
, running
);
1845 inferior_ptid
= currthread
;
1850 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1852 /* inferior_ptid is not set yet. This can happen with the
1853 vRun -> remote_wait,"TAAthread:" path if the stub
1854 doesn't support qC. This is the first stop reported
1855 after an attach, so this is the main thread. Update the
1856 ptid in the thread list. */
1857 thread_change_ptid (inferior_ptid
, currthread
);
1861 /* When connecting to a target remote, or to a target
1862 extended-remote which already was debugging an inferior, we
1863 may not know about it yet. Add it before adding its child
1864 thread, so notifications are emitted in a sensible order. */
1865 if (!in_inferior_list (ptid_get_pid (currthread
)))
1867 struct remote_state
*rs
= get_remote_state ();
1868 int fake_pid_p
= !remote_multi_process_p (rs
);
1870 inf
= remote_add_inferior (fake_pid_p
,
1871 ptid_get_pid (currthread
), -1, 1);
1874 /* This is really a new thread. Add it. */
1875 remote_add_thread (currthread
, running
);
1877 /* If we found a new inferior, let the common code do whatever
1878 it needs to with it (e.g., read shared libraries, insert
1879 breakpoints), unless we're just setting up an all-stop
1883 struct remote_state
*rs
= get_remote_state ();
1885 if (non_stop
|| !rs
->starting_up
)
1886 notice_new_inferior (currthread
, running
, 0);
1891 /* Return the private thread data, creating it if necessary. */
1893 static struct private_thread_info
*
1894 demand_private_info (ptid_t ptid
)
1896 struct thread_info
*info
= find_thread_ptid (ptid
);
1902 info
->priv
= XNEW (struct private_thread_info
);
1903 info
->private_dtor
= free_private_thread_info
;
1904 info
->priv
->core
= -1;
1905 info
->priv
->extra
= 0;
1911 /* Call this function as a result of
1912 1) A halt indication (T packet) containing a thread id
1913 2) A direct query of currthread
1914 3) Successful execution of set thread */
1917 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1919 rs
->general_thread
= currthread
;
1922 /* If 'QPassSignals' is supported, tell the remote stub what signals
1923 it can simply pass through to the inferior without reporting. */
1926 remote_pass_signals (struct target_ops
*self
,
1927 int numsigs
, unsigned char *pass_signals
)
1929 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1931 char *pass_packet
, *p
;
1933 struct remote_state
*rs
= get_remote_state ();
1935 gdb_assert (numsigs
< 256);
1936 for (i
= 0; i
< numsigs
; i
++)
1938 if (pass_signals
[i
])
1941 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1942 strcpy (pass_packet
, "QPassSignals:");
1943 p
= pass_packet
+ strlen (pass_packet
);
1944 for (i
= 0; i
< numsigs
; i
++)
1946 if (pass_signals
[i
])
1949 *p
++ = tohex (i
>> 4);
1950 *p
++ = tohex (i
& 15);
1959 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1961 putpkt (pass_packet
);
1962 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1963 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1964 if (rs
->last_pass_packet
)
1965 xfree (rs
->last_pass_packet
);
1966 rs
->last_pass_packet
= pass_packet
;
1969 xfree (pass_packet
);
1973 /* If 'QProgramSignals' is supported, tell the remote stub what
1974 signals it should pass through to the inferior when detaching. */
1977 remote_program_signals (struct target_ops
*self
,
1978 int numsigs
, unsigned char *signals
)
1980 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1984 struct remote_state
*rs
= get_remote_state ();
1986 gdb_assert (numsigs
< 256);
1987 for (i
= 0; i
< numsigs
; i
++)
1992 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1993 strcpy (packet
, "QProgramSignals:");
1994 p
= packet
+ strlen (packet
);
1995 for (i
= 0; i
< numsigs
; i
++)
1997 if (signal_pass_state (i
))
2000 *p
++ = tohex (i
>> 4);
2001 *p
++ = tohex (i
& 15);
2010 if (!rs
->last_program_signals_packet
2011 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2014 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2015 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2016 xfree (rs
->last_program_signals_packet
);
2017 rs
->last_program_signals_packet
= packet
;
2024 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2025 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2026 thread. If GEN is set, set the general thread, if not, then set
2027 the step/continue thread. */
2029 set_thread (struct ptid ptid
, int gen
)
2031 struct remote_state
*rs
= get_remote_state ();
2032 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2033 char *buf
= rs
->buf
;
2034 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2036 if (ptid_equal (state
, ptid
))
2040 *buf
++ = gen
? 'g' : 'c';
2041 if (ptid_equal (ptid
, magic_null_ptid
))
2042 xsnprintf (buf
, endbuf
- buf
, "0");
2043 else if (ptid_equal (ptid
, any_thread_ptid
))
2044 xsnprintf (buf
, endbuf
- buf
, "0");
2045 else if (ptid_equal (ptid
, minus_one_ptid
))
2046 xsnprintf (buf
, endbuf
- buf
, "-1");
2048 write_ptid (buf
, endbuf
, ptid
);
2050 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2052 rs
->general_thread
= ptid
;
2054 rs
->continue_thread
= ptid
;
2058 set_general_thread (struct ptid ptid
)
2060 set_thread (ptid
, 1);
2064 set_continue_thread (struct ptid ptid
)
2066 set_thread (ptid
, 0);
2069 /* Change the remote current process. Which thread within the process
2070 ends up selected isn't important, as long as it is the same process
2071 as what INFERIOR_PTID points to.
2073 This comes from that fact that there is no explicit notion of
2074 "selected process" in the protocol. The selected process for
2075 general operations is the process the selected general thread
2079 set_general_process (void)
2081 struct remote_state
*rs
= get_remote_state ();
2083 /* If the remote can't handle multiple processes, don't bother. */
2084 if (!rs
->extended
|| !remote_multi_process_p (rs
))
2087 /* We only need to change the remote current thread if it's pointing
2088 at some other process. */
2089 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2090 set_general_thread (inferior_ptid
);
2094 /* Return nonzero if this is the main thread that we made up ourselves
2095 to model non-threaded targets as single-threaded. */
2098 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2100 struct remote_state
*rs
= get_remote_state ();
2103 if (ptid_equal (ptid
, magic_null_ptid
))
2104 /* The main thread is always alive. */
2107 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2108 /* The main thread is always alive. This can happen after a
2109 vAttach, if the remote side doesn't support
2116 /* Return nonzero if the thread PTID is still alive on the remote
2120 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2122 struct remote_state
*rs
= get_remote_state ();
2125 /* Check if this is a thread that we made up ourselves to model
2126 non-threaded targets as single-threaded. */
2127 if (remote_thread_always_alive (ops
, ptid
))
2131 endp
= rs
->buf
+ get_remote_packet_size ();
2134 write_ptid (p
, endp
, ptid
);
2137 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2138 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2141 /* About these extended threadlist and threadinfo packets. They are
2142 variable length packets but, the fields within them are often fixed
2143 length. They are redundent enough to send over UDP as is the
2144 remote protocol in general. There is a matching unit test module
2147 /* WARNING: This threadref data structure comes from the remote O.S.,
2148 libstub protocol encoding, and remote.c. It is not particularly
2151 /* Right now, the internal structure is int. We want it to be bigger.
2152 Plan to fix this. */
2154 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2156 /* gdb_ext_thread_info is an internal GDB data structure which is
2157 equivalent to the reply of the remote threadinfo packet. */
2159 struct gdb_ext_thread_info
2161 threadref threadid
; /* External form of thread reference. */
2162 int active
; /* Has state interesting to GDB?
2164 char display
[256]; /* Brief state display, name,
2165 blocked/suspended. */
2166 char shortname
[32]; /* To be used to name threads. */
2167 char more_display
[256]; /* Long info, statistics, queue depth,
2171 /* The volume of remote transfers can be limited by submitting
2172 a mask containing bits specifying the desired information.
2173 Use a union of these values as the 'selection' parameter to
2174 get_thread_info. FIXME: Make these TAG names more thread specific. */
2176 #define TAG_THREADID 1
2177 #define TAG_EXISTS 2
2178 #define TAG_DISPLAY 4
2179 #define TAG_THREADNAME 8
2180 #define TAG_MOREDISPLAY 16
2182 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2184 static char *unpack_nibble (char *buf
, int *val
);
2186 static char *unpack_byte (char *buf
, int *value
);
2188 static char *pack_int (char *buf
, int value
);
2190 static char *unpack_int (char *buf
, int *value
);
2192 static char *unpack_string (char *src
, char *dest
, int length
);
2194 static char *pack_threadid (char *pkt
, threadref
*id
);
2196 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2198 void int_to_threadref (threadref
*id
, int value
);
2200 static int threadref_to_int (threadref
*ref
);
2202 static void copy_threadref (threadref
*dest
, threadref
*src
);
2204 static int threadmatch (threadref
*dest
, threadref
*src
);
2206 static char *pack_threadinfo_request (char *pkt
, int mode
,
2209 static int remote_unpack_thread_info_response (char *pkt
,
2210 threadref
*expectedref
,
2211 struct gdb_ext_thread_info
2215 static int remote_get_threadinfo (threadref
*threadid
,
2216 int fieldset
, /*TAG mask */
2217 struct gdb_ext_thread_info
*info
);
2219 static char *pack_threadlist_request (char *pkt
, int startflag
,
2221 threadref
*nextthread
);
2223 static int parse_threadlist_response (char *pkt
,
2225 threadref
*original_echo
,
2226 threadref
*resultlist
,
2229 static int remote_get_threadlist (int startflag
,
2230 threadref
*nextthread
,
2234 threadref
*threadlist
);
2236 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2238 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2239 void *context
, int looplimit
);
2241 static int remote_newthread_step (threadref
*ref
, void *context
);
2244 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2245 buffer we're allowed to write to. Returns
2246 BUF+CHARACTERS_WRITTEN. */
2249 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2252 struct remote_state
*rs
= get_remote_state ();
2254 if (remote_multi_process_p (rs
))
2256 pid
= ptid_get_pid (ptid
);
2258 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2260 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2262 tid
= ptid_get_lwp (ptid
);
2264 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2266 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2271 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2272 passed the last parsed char. Returns null_ptid on error. */
2275 read_ptid (char *buf
, char **obuf
)
2279 ULONGEST pid
= 0, tid
= 0;
2283 /* Multi-process ptid. */
2284 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2286 error (_("invalid remote ptid: %s"), p
);
2289 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2292 return ptid_build (pid
, tid
, 0);
2295 /* No multi-process. Just a tid. */
2296 pp
= unpack_varlen_hex (p
, &tid
);
2298 /* Return null_ptid when no thread id is found. */
2306 /* Since the stub is not sending a process id, then default to
2307 what's in inferior_ptid, unless it's null at this point. If so,
2308 then since there's no way to know the pid of the reported
2309 threads, use the magic number. */
2310 if (ptid_equal (inferior_ptid
, null_ptid
))
2311 pid
= ptid_get_pid (magic_null_ptid
);
2313 pid
= ptid_get_pid (inferior_ptid
);
2317 return ptid_build (pid
, tid
, 0);
2323 if (ch
>= 'a' && ch
<= 'f')
2324 return ch
- 'a' + 10;
2325 if (ch
>= '0' && ch
<= '9')
2327 if (ch
>= 'A' && ch
<= 'F')
2328 return ch
- 'A' + 10;
2333 stub_unpack_int (char *buff
, int fieldlength
)
2340 nibble
= stubhex (*buff
++);
2344 retval
= retval
<< 4;
2350 unpack_nibble (char *buf
, int *val
)
2352 *val
= fromhex (*buf
++);
2357 unpack_byte (char *buf
, int *value
)
2359 *value
= stub_unpack_int (buf
, 2);
2364 pack_int (char *buf
, int value
)
2366 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2367 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2368 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2369 buf
= pack_hex_byte (buf
, (value
& 0xff));
2374 unpack_int (char *buf
, int *value
)
2376 *value
= stub_unpack_int (buf
, 8);
2380 #if 0 /* Currently unused, uncomment when needed. */
2381 static char *pack_string (char *pkt
, char *string
);
2384 pack_string (char *pkt
, char *string
)
2389 len
= strlen (string
);
2391 len
= 200; /* Bigger than most GDB packets, junk??? */
2392 pkt
= pack_hex_byte (pkt
, len
);
2396 if ((ch
== '\0') || (ch
== '#'))
2397 ch
= '*'; /* Protect encapsulation. */
2402 #endif /* 0 (unused) */
2405 unpack_string (char *src
, char *dest
, int length
)
2414 pack_threadid (char *pkt
, threadref
*id
)
2417 unsigned char *altid
;
2419 altid
= (unsigned char *) id
;
2420 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2422 pkt
= pack_hex_byte (pkt
, *altid
++);
2428 unpack_threadid (char *inbuf
, threadref
*id
)
2431 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2434 altref
= (char *) id
;
2436 while (inbuf
< limit
)
2438 x
= stubhex (*inbuf
++);
2439 y
= stubhex (*inbuf
++);
2440 *altref
++ = (x
<< 4) | y
;
2445 /* Externally, threadrefs are 64 bits but internally, they are still
2446 ints. This is due to a mismatch of specifications. We would like
2447 to use 64bit thread references internally. This is an adapter
2451 int_to_threadref (threadref
*id
, int value
)
2453 unsigned char *scan
;
2455 scan
= (unsigned char *) id
;
2461 *scan
++ = (value
>> 24) & 0xff;
2462 *scan
++ = (value
>> 16) & 0xff;
2463 *scan
++ = (value
>> 8) & 0xff;
2464 *scan
++ = (value
& 0xff);
2468 threadref_to_int (threadref
*ref
)
2471 unsigned char *scan
;
2477 value
= (value
<< 8) | ((*scan
++) & 0xff);
2482 copy_threadref (threadref
*dest
, threadref
*src
)
2485 unsigned char *csrc
, *cdest
;
2487 csrc
= (unsigned char *) src
;
2488 cdest
= (unsigned char *) dest
;
2495 threadmatch (threadref
*dest
, threadref
*src
)
2497 /* Things are broken right now, so just assume we got a match. */
2499 unsigned char *srcp
, *destp
;
2501 srcp
= (char *) src
;
2502 destp
= (char *) dest
;
2506 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2513 threadid:1, # always request threadid
2520 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2523 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2525 *pkt
++ = 'q'; /* Info Query */
2526 *pkt
++ = 'P'; /* process or thread info */
2527 pkt
= pack_int (pkt
, mode
); /* mode */
2528 pkt
= pack_threadid (pkt
, id
); /* threadid */
2529 *pkt
= '\0'; /* terminate */
2533 /* These values tag the fields in a thread info response packet. */
2534 /* Tagging the fields allows us to request specific fields and to
2535 add more fields as time goes by. */
2537 #define TAG_THREADID 1 /* Echo the thread identifier. */
2538 #define TAG_EXISTS 2 /* Is this process defined enough to
2539 fetch registers and its stack? */
2540 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2541 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2542 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2546 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2547 struct gdb_ext_thread_info
*info
)
2549 struct remote_state
*rs
= get_remote_state ();
2553 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2556 /* info->threadid = 0; FIXME: implement zero_threadref. */
2558 info
->display
[0] = '\0';
2559 info
->shortname
[0] = '\0';
2560 info
->more_display
[0] = '\0';
2562 /* Assume the characters indicating the packet type have been
2564 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2565 pkt
= unpack_threadid (pkt
, &ref
);
2568 warning (_("Incomplete response to threadinfo request."));
2569 if (!threadmatch (&ref
, expectedref
))
2570 { /* This is an answer to a different request. */
2571 warning (_("ERROR RMT Thread info mismatch."));
2574 copy_threadref (&info
->threadid
, &ref
);
2576 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2578 /* Packets are terminated with nulls. */
2579 while ((pkt
< limit
) && mask
&& *pkt
)
2581 pkt
= unpack_int (pkt
, &tag
); /* tag */
2582 pkt
= unpack_byte (pkt
, &length
); /* length */
2583 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2585 warning (_("ERROR RMT: threadinfo tag mismatch."));
2589 if (tag
== TAG_THREADID
)
2593 warning (_("ERROR RMT: length of threadid is not 16."));
2597 pkt
= unpack_threadid (pkt
, &ref
);
2598 mask
= mask
& ~TAG_THREADID
;
2601 if (tag
== TAG_EXISTS
)
2603 info
->active
= stub_unpack_int (pkt
, length
);
2605 mask
= mask
& ~(TAG_EXISTS
);
2608 warning (_("ERROR RMT: 'exists' length too long."));
2614 if (tag
== TAG_THREADNAME
)
2616 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2617 mask
= mask
& ~TAG_THREADNAME
;
2620 if (tag
== TAG_DISPLAY
)
2622 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2623 mask
= mask
& ~TAG_DISPLAY
;
2626 if (tag
== TAG_MOREDISPLAY
)
2628 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2629 mask
= mask
& ~TAG_MOREDISPLAY
;
2632 warning (_("ERROR RMT: unknown thread info tag."));
2633 break; /* Not a tag we know about. */
2639 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2640 struct gdb_ext_thread_info
*info
)
2642 struct remote_state
*rs
= get_remote_state ();
2645 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2647 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2649 if (rs
->buf
[0] == '\0')
2652 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2657 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2660 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2661 threadref
*nextthread
)
2663 *pkt
++ = 'q'; /* info query packet */
2664 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2665 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2666 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2667 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2672 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2675 parse_threadlist_response (char *pkt
, int result_limit
,
2676 threadref
*original_echo
, threadref
*resultlist
,
2679 struct remote_state
*rs
= get_remote_state ();
2681 int count
, resultcount
, done
;
2684 /* Assume the 'q' and 'M chars have been stripped. */
2685 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2686 /* done parse past here */
2687 pkt
= unpack_byte (pkt
, &count
); /* count field */
2688 pkt
= unpack_nibble (pkt
, &done
);
2689 /* The first threadid is the argument threadid. */
2690 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2691 while ((count
-- > 0) && (pkt
< limit
))
2693 pkt
= unpack_threadid (pkt
, resultlist
++);
2694 if (resultcount
++ >= result_limit
)
2702 /* Fetch the next batch of threads from the remote. Returns -1 if the
2703 qL packet is not supported, 0 on error and 1 on success. */
2706 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2707 int *done
, int *result_count
, threadref
*threadlist
)
2709 struct remote_state
*rs
= get_remote_state ();
2712 /* Trancate result limit to be smaller than the packet size. */
2713 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2714 >= get_remote_packet_size ())
2715 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2717 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2719 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2720 if (*rs
->buf
== '\0')
2722 /* Packet not supported. */
2727 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2728 &rs
->echo_nextthread
, threadlist
, done
);
2730 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2732 /* FIXME: This is a good reason to drop the packet. */
2733 /* Possably, there is a duplicate response. */
2735 retransmit immediatly - race conditions
2736 retransmit after timeout - yes
2738 wait for packet, then exit
2740 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2741 return 0; /* I choose simply exiting. */
2743 if (*result_count
<= 0)
2747 warning (_("RMT ERROR : failed to get remote thread list."));
2750 return result
; /* break; */
2752 if (*result_count
> result_limit
)
2755 warning (_("RMT ERROR: threadlist response longer than requested."));
2761 /* Fetch the list of remote threads, with the qL packet, and call
2762 STEPFUNCTION for each thread found. Stops iterating and returns 1
2763 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2764 STEPFUNCTION returns false. If the packet is not supported,
2768 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2771 struct remote_state
*rs
= get_remote_state ();
2772 int done
, i
, result_count
;
2780 if (loopcount
++ > looplimit
)
2783 warning (_("Remote fetch threadlist -infinite loop-."));
2786 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2787 MAXTHREADLISTRESULTS
,
2788 &done
, &result_count
,
2789 rs
->resultthreadlist
);
2792 /* Clear for later iterations. */
2794 /* Setup to resume next batch of thread references, set nextthread. */
2795 if (result_count
>= 1)
2796 copy_threadref (&rs
->nextthread
,
2797 &rs
->resultthreadlist
[result_count
- 1]);
2799 while (result_count
--)
2801 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2811 /* A thread found on the remote target. */
2813 typedef struct thread_item
2815 /* The thread's PTID. */
2818 /* The thread's extra info. May be NULL. */
2821 /* The core the thread was running on. -1 if not known. */
2824 DEF_VEC_O(thread_item_t
);
2826 /* Context passed around to the various methods listing remote
2827 threads. As new threads are found, they're added to the ITEMS
2830 struct threads_listing_context
2832 /* The threads found on the remote target. */
2833 VEC (thread_item_t
) *items
;
2836 /* Discard the contents of the constructed thread listing context. */
2839 clear_threads_listing_context (void *p
)
2841 struct threads_listing_context
*context
= p
;
2843 struct thread_item
*item
;
2845 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2846 xfree (item
->extra
);
2848 VEC_free (thread_item_t
, context
->items
);
2851 /* Remove the thread specified as the related_pid field of WS
2852 from the CONTEXT list. */
2855 threads_listing_context_remove (struct target_waitstatus
*ws
,
2856 struct threads_listing_context
*context
)
2858 struct thread_item
*item
;
2860 ptid_t child_ptid
= ws
->value
.related_pid
;
2862 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2864 if (ptid_equal (item
->ptid
, child_ptid
))
2866 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2873 remote_newthread_step (threadref
*ref
, void *data
)
2875 struct threads_listing_context
*context
= data
;
2876 struct thread_item item
;
2877 int pid
= ptid_get_pid (inferior_ptid
);
2879 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2883 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2885 return 1; /* continue iterator */
2888 #define CRAZY_MAX_THREADS 1000
2891 remote_current_thread (ptid_t oldpid
)
2893 struct remote_state
*rs
= get_remote_state ();
2896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2897 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2902 result
= read_ptid (&rs
->buf
[2], &obuf
);
2903 if (*obuf
!= '\0' && remote_debug
)
2904 fprintf_unfiltered (gdb_stdlog
,
2905 "warning: garbage in qC reply\n");
2913 /* List remote threads using the deprecated qL packet. */
2916 remote_get_threads_with_ql (struct target_ops
*ops
,
2917 struct threads_listing_context
*context
)
2919 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2920 CRAZY_MAX_THREADS
) >= 0)
2926 #if defined(HAVE_LIBEXPAT)
2929 start_thread (struct gdb_xml_parser
*parser
,
2930 const struct gdb_xml_element
*element
,
2931 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2933 struct threads_listing_context
*data
= user_data
;
2935 struct thread_item item
;
2937 struct gdb_xml_value
*attr
;
2939 id
= xml_find_attribute (attributes
, "id")->value
;
2940 item
.ptid
= read_ptid (id
, NULL
);
2942 attr
= xml_find_attribute (attributes
, "core");
2944 item
.core
= *(ULONGEST
*) attr
->value
;
2950 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2954 end_thread (struct gdb_xml_parser
*parser
,
2955 const struct gdb_xml_element
*element
,
2956 void *user_data
, const char *body_text
)
2958 struct threads_listing_context
*data
= user_data
;
2960 if (body_text
&& *body_text
)
2961 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2964 const struct gdb_xml_attribute thread_attributes
[] = {
2965 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2966 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2967 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2970 const struct gdb_xml_element thread_children
[] = {
2971 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2974 const struct gdb_xml_element threads_children
[] = {
2975 { "thread", thread_attributes
, thread_children
,
2976 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2977 start_thread
, end_thread
},
2978 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2981 const struct gdb_xml_element threads_elements
[] = {
2982 { "threads", NULL
, threads_children
,
2983 GDB_XML_EF_NONE
, NULL
, NULL
},
2984 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2989 /* List remote threads using qXfer:threads:read. */
2992 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2993 struct threads_listing_context
*context
)
2995 #if defined(HAVE_LIBEXPAT)
2996 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2998 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2999 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3001 if (xml
!= NULL
&& *xml
!= '\0')
3003 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3004 threads_elements
, xml
, context
);
3007 do_cleanups (back_to
);
3015 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3018 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3019 struct threads_listing_context
*context
)
3021 struct remote_state
*rs
= get_remote_state ();
3023 if (rs
->use_threadinfo_query
)
3027 putpkt ("qfThreadInfo");
3028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3030 if (bufp
[0] != '\0') /* q packet recognized */
3032 while (*bufp
++ == 'm') /* reply contains one or more TID */
3036 struct thread_item item
;
3038 item
.ptid
= read_ptid (bufp
, &bufp
);
3042 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3044 while (*bufp
++ == ','); /* comma-separated list */
3045 putpkt ("qsThreadInfo");
3046 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3053 /* Packet not recognized. */
3054 rs
->use_threadinfo_query
= 0;
3061 /* Implement the to_update_thread_list function for the remote
3065 remote_update_thread_list (struct target_ops
*ops
)
3067 struct remote_state
*rs
= get_remote_state ();
3068 struct threads_listing_context context
;
3069 struct cleanup
*old_chain
;
3072 context
.items
= NULL
;
3073 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3075 /* We have a few different mechanisms to fetch the thread list. Try
3076 them all, starting with the most preferred one first, falling
3077 back to older methods. */
3078 if (remote_get_threads_with_qxfer (ops
, &context
)
3079 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3080 || remote_get_threads_with_ql (ops
, &context
))
3083 struct thread_item
*item
;
3084 struct thread_info
*tp
, *tmp
;
3088 if (VEC_empty (thread_item_t
, context
.items
)
3089 && remote_thread_always_alive (ops
, inferior_ptid
))
3091 /* Some targets don't really support threads, but still
3092 reply an (empty) thread list in response to the thread
3093 listing packets, instead of replying "packet not
3094 supported". Exit early so we don't delete the main
3096 do_cleanups (old_chain
);
3100 /* CONTEXT now holds the current thread list on the remote
3101 target end. Delete GDB-side threads no longer found on the
3103 ALL_THREADS_SAFE (tp
, tmp
)
3106 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3109 if (ptid_equal (item
->ptid
, tp
->ptid
))
3113 if (i
== VEC_length (thread_item_t
, context
.items
))
3116 delete_thread (tp
->ptid
);
3120 /* Remove any unreported fork child threads from CONTEXT so
3121 that we don't interfere with follow fork, which is where
3122 creation of such threads is handled. */
3123 remove_new_fork_children (&context
);
3125 /* And now add threads we don't know about yet to our list. */
3127 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3130 if (!ptid_equal (item
->ptid
, null_ptid
))
3132 struct private_thread_info
*info
;
3133 /* In non-stop mode, we assume new found threads are
3134 running until proven otherwise with a stop reply. In
3135 all-stop, we can only get here if all threads are
3137 int running
= non_stop
? 1 : 0;
3139 remote_notice_new_inferior (item
->ptid
, running
);
3141 info
= demand_private_info (item
->ptid
);
3142 info
->core
= item
->core
;
3143 info
->extra
= item
->extra
;
3151 /* If no thread listing method is supported, then query whether
3152 each known thread is alive, one by one, with the T packet.
3153 If the target doesn't support threads at all, then this is a
3154 no-op. See remote_thread_alive. */
3158 do_cleanups (old_chain
);
3162 * Collect a descriptive string about the given thread.
3163 * The target may say anything it wants to about the thread
3164 * (typically info about its blocked / runnable state, name, etc.).
3165 * This string will appear in the info threads display.
3167 * Optional: targets are not required to implement this function.
3171 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3173 struct remote_state
*rs
= get_remote_state ();
3177 struct gdb_ext_thread_info threadinfo
;
3178 static char display_buf
[100]; /* arbitrary... */
3179 int n
= 0; /* position in display_buf */
3181 if (rs
->remote_desc
== 0) /* paranoia */
3182 internal_error (__FILE__
, __LINE__
,
3183 _("remote_threads_extra_info"));
3185 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3186 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3187 /* This is the main thread which was added by GDB. The remote
3188 server doesn't know about it. */
3191 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3193 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3195 if (info
&& info
->priv
)
3196 return info
->priv
->extra
;
3201 if (rs
->use_threadextra_query
)
3204 char *endb
= rs
->buf
+ get_remote_packet_size ();
3206 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3208 write_ptid (b
, endb
, tp
->ptid
);
3211 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3212 if (rs
->buf
[0] != 0)
3214 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3215 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3216 display_buf
[result
] = '\0';
3221 /* If the above query fails, fall back to the old method. */
3222 rs
->use_threadextra_query
= 0;
3223 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3224 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3225 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3226 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3227 if (threadinfo
.active
)
3229 if (*threadinfo
.shortname
)
3230 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3231 " Name: %s,", threadinfo
.shortname
);
3232 if (*threadinfo
.display
)
3233 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3234 " State: %s,", threadinfo
.display
);
3235 if (*threadinfo
.more_display
)
3236 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3237 " Priority: %s", threadinfo
.more_display
);
3241 /* For purely cosmetic reasons, clear up trailing commas. */
3242 if (',' == display_buf
[n
-1])
3243 display_buf
[n
-1] = ' ';
3252 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3253 struct static_tracepoint_marker
*marker
)
3255 struct remote_state
*rs
= get_remote_state ();
3258 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3260 p
+= hexnumstr (p
, addr
);
3262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3266 error (_("Remote failure reply: %s"), p
);
3270 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3277 static VEC(static_tracepoint_marker_p
) *
3278 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3281 struct remote_state
*rs
= get_remote_state ();
3282 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3283 struct static_tracepoint_marker
*marker
= NULL
;
3284 struct cleanup
*old_chain
;
3287 /* Ask for a first packet of static tracepoint marker
3290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3293 error (_("Remote failure reply: %s"), p
);
3295 old_chain
= make_cleanup (free_current_marker
, &marker
);
3300 marker
= XCNEW (struct static_tracepoint_marker
);
3304 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3306 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3308 VEC_safe_push (static_tracepoint_marker_p
,
3314 release_static_tracepoint_marker (marker
);
3315 memset (marker
, 0, sizeof (*marker
));
3318 while (*p
++ == ','); /* comma-separated list */
3319 /* Ask for another packet of static tracepoint definition. */
3321 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3325 do_cleanups (old_chain
);
3330 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3333 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3335 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3339 /* Restart the remote side; this is an extended protocol operation. */
3342 extended_remote_restart (void)
3344 struct remote_state
*rs
= get_remote_state ();
3346 /* Send the restart command; for reasons I don't understand the
3347 remote side really expects a number after the "R". */
3348 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3351 remote_fileio_reset ();
3354 /* Clean up connection to a remote debugger. */
3357 remote_close (struct target_ops
*self
)
3359 struct remote_state
*rs
= get_remote_state ();
3361 if (rs
->remote_desc
== NULL
)
3362 return; /* already closed */
3364 /* Make sure we leave stdin registered in the event loop, and we
3365 don't leave the async SIGINT signal handler installed. */
3366 remote_terminal_ours (self
);
3368 serial_close (rs
->remote_desc
);
3369 rs
->remote_desc
= NULL
;
3371 /* We don't have a connection to the remote stub anymore. Get rid
3372 of all the inferiors and their threads we were controlling.
3373 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3374 will be unable to find the thread corresponding to (pid, 0, 0). */
3375 inferior_ptid
= null_ptid
;
3376 discard_all_inferiors ();
3378 /* We are closing the remote target, so we should discard
3379 everything of this target. */
3380 discard_pending_stop_replies_in_queue (rs
);
3382 if (remote_async_inferior_event_token
)
3383 delete_async_event_handler (&remote_async_inferior_event_token
);
3385 remote_notif_state_xfree (rs
->notif_state
);
3387 trace_reset_local_state ();
3390 /* Query the remote side for the text, data and bss offsets. */
3395 struct remote_state
*rs
= get_remote_state ();
3398 int lose
, num_segments
= 0, do_sections
, do_segments
;
3399 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3400 struct section_offsets
*offs
;
3401 struct symfile_segment_data
*data
;
3403 if (symfile_objfile
== NULL
)
3406 putpkt ("qOffsets");
3407 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3410 if (buf
[0] == '\000')
3411 return; /* Return silently. Stub doesn't support
3415 warning (_("Remote failure reply: %s"), buf
);
3419 /* Pick up each field in turn. This used to be done with scanf, but
3420 scanf will make trouble if CORE_ADDR size doesn't match
3421 conversion directives correctly. The following code will work
3422 with any size of CORE_ADDR. */
3423 text_addr
= data_addr
= bss_addr
= 0;
3427 if (startswith (ptr
, "Text="))
3430 /* Don't use strtol, could lose on big values. */
3431 while (*ptr
&& *ptr
!= ';')
3432 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3434 if (startswith (ptr
, ";Data="))
3437 while (*ptr
&& *ptr
!= ';')
3438 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3443 if (!lose
&& startswith (ptr
, ";Bss="))
3446 while (*ptr
&& *ptr
!= ';')
3447 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3449 if (bss_addr
!= data_addr
)
3450 warning (_("Target reported unsupported offsets: %s"), buf
);
3455 else if (startswith (ptr
, "TextSeg="))
3458 /* Don't use strtol, could lose on big values. */
3459 while (*ptr
&& *ptr
!= ';')
3460 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3463 if (startswith (ptr
, ";DataSeg="))
3466 while (*ptr
&& *ptr
!= ';')
3467 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3475 error (_("Malformed response to offset query, %s"), buf
);
3476 else if (*ptr
!= '\0')
3477 warning (_("Target reported unsupported offsets: %s"), buf
);
3479 offs
= ((struct section_offsets
*)
3480 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3481 memcpy (offs
, symfile_objfile
->section_offsets
,
3482 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3484 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3485 do_segments
= (data
!= NULL
);
3486 do_sections
= num_segments
== 0;
3488 if (num_segments
> 0)
3490 segments
[0] = text_addr
;
3491 segments
[1] = data_addr
;
3493 /* If we have two segments, we can still try to relocate everything
3494 by assuming that the .text and .data offsets apply to the whole
3495 text and data segments. Convert the offsets given in the packet
3496 to base addresses for symfile_map_offsets_to_segments. */
3497 else if (data
&& data
->num_segments
== 2)
3499 segments
[0] = data
->segment_bases
[0] + text_addr
;
3500 segments
[1] = data
->segment_bases
[1] + data_addr
;
3503 /* If the object file has only one segment, assume that it is text
3504 rather than data; main programs with no writable data are rare,
3505 but programs with no code are useless. Of course the code might
3506 have ended up in the data segment... to detect that we would need
3507 the permissions here. */
3508 else if (data
&& data
->num_segments
== 1)
3510 segments
[0] = data
->segment_bases
[0] + text_addr
;
3513 /* There's no way to relocate by segment. */
3519 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3520 offs
, num_segments
, segments
);
3522 if (ret
== 0 && !do_sections
)
3523 error (_("Can not handle qOffsets TextSeg "
3524 "response with this symbol file"));
3531 free_symfile_segment_data (data
);
3535 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3537 /* This is a temporary kludge to force data and bss to use the
3538 same offsets because that's what nlmconv does now. The real
3539 solution requires changes to the stub and remote.c that I
3540 don't have time to do right now. */
3542 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3543 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3546 objfile_relocate (symfile_objfile
, offs
);
3549 /* Send interrupt_sequence to remote target. */
3551 send_interrupt_sequence (void)
3553 struct remote_state
*rs
= get_remote_state ();
3555 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3556 remote_serial_write ("\x03", 1);
3557 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3558 serial_send_break (rs
->remote_desc
);
3559 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3561 serial_send_break (rs
->remote_desc
);
3562 remote_serial_write ("g", 1);
3565 internal_error (__FILE__
, __LINE__
,
3566 _("Invalid value for interrupt_sequence_mode: %s."),
3567 interrupt_sequence_mode
);
3571 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3572 and extract the PTID. Returns NULL_PTID if not found. */
3575 stop_reply_extract_thread (char *stop_reply
)
3577 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3581 /* Txx r:val ; r:val (...) */
3584 /* Look for "register" named "thread". */
3589 p1
= strchr (p
, ':');
3593 if (strncmp (p
, "thread", p1
- p
) == 0)
3594 return read_ptid (++p1
, &p
);
3596 p1
= strchr (p
, ';');
3608 /* Determine the remote side's current thread. If we have a stop
3609 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3610 "thread" register we can extract the current thread from. If not,
3611 ask the remote which is the current thread with qC. The former
3612 method avoids a roundtrip. */
3615 get_current_thread (char *wait_status
)
3617 ptid_t ptid
= null_ptid
;
3619 /* Note we don't use remote_parse_stop_reply as that makes use of
3620 the target architecture, which we haven't yet fully determined at
3622 if (wait_status
!= NULL
)
3623 ptid
= stop_reply_extract_thread (wait_status
);
3624 if (ptid_equal (ptid
, null_ptid
))
3625 ptid
= remote_current_thread (inferior_ptid
);
3630 /* Query the remote target for which is the current thread/process,
3631 add it to our tables, and update INFERIOR_PTID. The caller is
3632 responsible for setting the state such that the remote end is ready
3633 to return the current thread.
3635 This function is called after handling the '?' or 'vRun' packets,
3636 whose response is a stop reply from which we can also try
3637 extracting the thread. If the target doesn't support the explicit
3638 qC query, we infer the current thread from that stop reply, passed
3639 in in WAIT_STATUS, which may be NULL. */
3642 add_current_inferior_and_thread (char *wait_status
)
3644 struct remote_state
*rs
= get_remote_state ();
3648 inferior_ptid
= null_ptid
;
3650 /* Now, if we have thread information, update inferior_ptid. */
3651 ptid
= get_current_thread (wait_status
);
3653 if (!ptid_equal (ptid
, null_ptid
))
3655 if (!remote_multi_process_p (rs
))
3658 inferior_ptid
= ptid
;
3662 /* Without this, some commands which require an active target
3663 (such as kill) won't work. This variable serves (at least)
3664 double duty as both the pid of the target process (if it has
3665 such), and as a flag indicating that a target is active. */
3666 inferior_ptid
= magic_null_ptid
;
3670 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3672 /* Add the main thread. */
3673 add_thread_silent (inferior_ptid
);
3676 /* Process all initial stop replies the remote side sent in response
3677 to the ? packet. These indicate threads that were already stopped
3678 on initial connection. We mark these threads as stopped and print
3679 their current frame before giving the user the prompt. */
3682 process_initial_stop_replies (void)
3684 int pending_stop_replies
= stop_reply_queue_length ();
3686 /* Consume the initial pending events. */
3687 while (pending_stop_replies
-- > 0)
3689 ptid_t waiton_ptid
= minus_one_ptid
;
3691 struct target_waitstatus ws
;
3692 int ignore_event
= 0;
3694 memset (&ws
, 0, sizeof (ws
));
3695 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3697 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3701 case TARGET_WAITKIND_IGNORE
:
3702 case TARGET_WAITKIND_NO_RESUMED
:
3703 case TARGET_WAITKIND_SIGNALLED
:
3704 case TARGET_WAITKIND_EXITED
:
3705 /* We shouldn't see these, but if we do, just ignore. */
3707 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3711 case TARGET_WAITKIND_EXECD
:
3712 xfree (ws
.value
.execd_pathname
);
3721 switch_to_thread (event_ptid
);
3722 set_executing (event_ptid
, 0);
3723 set_running (event_ptid
, 0);
3725 stop_pc
= get_frame_pc (get_current_frame ());
3726 set_current_sal_from_frame (get_current_frame ());
3728 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3730 enum gdb_signal sig
= ws
.value
.sig
;
3732 /* Stubs traditionally report SIGTRAP as initial signal,
3733 instead of signal 0. Suppress it. */
3734 if (sig
== GDB_SIGNAL_TRAP
)
3736 inferior_thread ()->suspend
.stop_signal
= sig
;
3738 if (signal_print_state (sig
))
3739 observer_notify_signal_received (sig
);
3742 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
3743 observer_notify_normal_stop (NULL
, 1);
3748 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3750 struct remote_state
*rs
= get_remote_state ();
3751 struct packet_config
*noack_config
;
3752 char *wait_status
= NULL
;
3754 immediate_quit
++; /* Allow user to interrupt it. */
3757 if (interrupt_on_connect
)
3758 send_interrupt_sequence ();
3760 /* Ack any packet which the remote side has already sent. */
3761 serial_write (rs
->remote_desc
, "+", 1);
3763 /* Signal other parts that we're going through the initial setup,
3764 and so things may not be stable yet. */
3765 rs
->starting_up
= 1;
3767 /* The first packet we send to the target is the optional "supported
3768 packets" request. If the target can answer this, it will tell us
3769 which later probes to skip. */
3770 remote_query_supported ();
3772 /* If the stub wants to get a QAllow, compose one and send it. */
3773 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3774 remote_set_permissions (target
);
3776 /* Next, we possibly activate noack mode.
3778 If the QStartNoAckMode packet configuration is set to AUTO,
3779 enable noack mode if the stub reported a wish for it with
3782 If set to TRUE, then enable noack mode even if the stub didn't
3783 report it in qSupported. If the stub doesn't reply OK, the
3784 session ends with an error.
3786 If FALSE, then don't activate noack mode, regardless of what the
3787 stub claimed should be the default with qSupported. */
3789 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3790 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3792 putpkt ("QStartNoAckMode");
3793 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3794 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3800 /* Tell the remote that we are using the extended protocol. */
3802 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3805 /* Let the target know which signals it is allowed to pass down to
3807 update_signals_program_target ();
3809 /* Next, if the target can specify a description, read it. We do
3810 this before anything involving memory or registers. */
3811 target_find_description ();
3813 /* Next, now that we know something about the target, update the
3814 address spaces in the program spaces. */
3815 update_address_spaces ();
3817 /* On OSs where the list of libraries is global to all
3818 processes, we fetch them early. */
3819 if (gdbarch_has_global_solist (target_gdbarch ()))
3820 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3824 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3825 error (_("Non-stop mode requested, but remote "
3826 "does not support non-stop"));
3828 putpkt ("QNonStop:1");
3829 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3831 if (strcmp (rs
->buf
, "OK") != 0)
3832 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3834 /* Find about threads and processes the stub is already
3835 controlling. We default to adding them in the running state.
3836 The '?' query below will then tell us about which threads are
3838 remote_update_thread_list (target
);
3840 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3842 /* Don't assume that the stub can operate in all-stop mode.
3843 Request it explicitly. */
3844 putpkt ("QNonStop:0");
3845 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3847 if (strcmp (rs
->buf
, "OK") != 0)
3848 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3851 /* Upload TSVs regardless of whether the target is running or not. The
3852 remote stub, such as GDBserver, may have some predefined or builtin
3853 TSVs, even if the target is not running. */
3854 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3856 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3858 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3859 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3862 /* Check whether the target is running now. */
3864 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3870 struct inferior
*inf
;
3872 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3875 error (_("The target is not running (try extended-remote?)"));
3877 /* We're connected, but not running. Drop out before we
3878 call start_remote. */
3879 rs
->starting_up
= 0;
3884 /* Save the reply for later. */
3885 wait_status
= alloca (strlen (rs
->buf
) + 1);
3886 strcpy (wait_status
, rs
->buf
);
3889 /* Fetch thread list. */
3890 target_update_thread_list ();
3892 /* Let the stub know that we want it to return the thread. */
3893 set_continue_thread (minus_one_ptid
);
3895 if (thread_count () == 0)
3897 /* Target has no concept of threads at all. GDB treats
3898 non-threaded target as single-threaded; add a main
3900 add_current_inferior_and_thread (wait_status
);
3904 /* We have thread information; select the thread the target
3905 says should be current. If we're reconnecting to a
3906 multi-threaded program, this will ideally be the thread
3907 that last reported an event before GDB disconnected. */
3908 inferior_ptid
= get_current_thread (wait_status
);
3909 if (ptid_equal (inferior_ptid
, null_ptid
))
3911 /* Odd... The target was able to list threads, but not
3912 tell us which thread was current (no "thread"
3913 register in T stop reply?). Just pick the first
3914 thread in the thread list then. */
3917 fprintf_unfiltered (gdb_stdlog
,
3918 "warning: couldn't determine remote "
3919 "current thread; picking first in list.\n");
3921 inferior_ptid
= thread_list
->ptid
;
3925 /* init_wait_for_inferior should be called before get_offsets in order
3926 to manage `inserted' flag in bp loc in a correct state.
3927 breakpoint_init_inferior, called from init_wait_for_inferior, set
3928 `inserted' flag to 0, while before breakpoint_re_set, called from
3929 start_remote, set `inserted' flag to 1. In the initialization of
3930 inferior, breakpoint_init_inferior should be called first, and then
3931 breakpoint_re_set can be called. If this order is broken, state of
3932 `inserted' flag is wrong, and cause some problems on breakpoint
3934 init_wait_for_inferior ();
3936 get_offsets (); /* Get text, data & bss offsets. */
3938 /* If we could not find a description using qXfer, and we know
3939 how to do it some other way, try again. This is not
3940 supported for non-stop; it could be, but it is tricky if
3941 there are no stopped threads when we connect. */
3942 if (remote_read_description_p (target
)
3943 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3945 target_clear_description ();
3946 target_find_description ();
3949 /* Use the previously fetched status. */
3950 gdb_assert (wait_status
!= NULL
);
3951 strcpy (rs
->buf
, wait_status
);
3952 rs
->cached_wait_status
= 1;
3955 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3959 ptid_t current_ptid
;
3961 /* Clear WFI global state. Do this before finding about new
3962 threads and inferiors, and setting the current inferior.
3963 Otherwise we would clear the proceed status of the current
3964 inferior when we want its stop_soon state to be preserved
3965 (see notice_new_inferior). */
3966 init_wait_for_inferior ();
3968 /* In non-stop, we will either get an "OK", meaning that there
3969 are no stopped threads at this time; or, a regular stop
3970 reply. In the latter case, there may be more than one thread
3971 stopped --- we pull them all out using the vStopped
3973 if (strcmp (rs
->buf
, "OK") != 0)
3975 struct notif_client
*notif
= ¬if_client_stop
;
3977 /* remote_notif_get_pending_replies acks this one, and gets
3979 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3980 = remote_notif_parse (notif
, rs
->buf
);
3981 remote_notif_get_pending_events (notif
);
3984 if (thread_count () == 0)
3987 error (_("The target is not running (try extended-remote?)"));
3989 /* We're connected, but not running. Drop out before we
3990 call start_remote. */
3991 rs
->starting_up
= 0;
3995 /* Let the stub know that we want it to return the thread. */
3997 /* Force the stub to choose a thread. */
3998 set_general_thread (null_ptid
);
4001 current_ptid
= remote_current_thread (minus_one_ptid
);
4002 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
4003 error (_("remote didn't report the current thread in non-stop mode"));
4005 inferior_ptid
= current_ptid
;
4006 get_offsets (); /* Get text, data & bss offsets. */
4008 /* In non-stop mode, any cached wait status will be stored in
4009 the stop reply queue. */
4010 gdb_assert (wait_status
== NULL
);
4012 /* Report all signals during attach/startup. */
4013 remote_pass_signals (target
, 0, NULL
);
4015 /* If there are already stopped threads, mark them stopped and
4016 report their stops before giving the prompt to the user. */
4017 process_initial_stop_replies ();
4019 switch_to_thread (current_ptid
);
4021 if (target_can_async_p ())
4025 /* If we connected to a live target, do some additional setup. */
4026 if (target_has_execution
)
4028 if (symfile_objfile
) /* No use without a symbol-file. */
4029 remote_check_symbols ();
4032 /* Possibly the target has been engaged in a trace run started
4033 previously; find out where things are at. */
4034 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4036 struct uploaded_tp
*uploaded_tps
= NULL
;
4038 if (current_trace_status ()->running
)
4039 printf_filtered (_("Trace is already running on the target.\n"));
4041 remote_upload_tracepoints (target
, &uploaded_tps
);
4043 merge_uploaded_tracepoints (&uploaded_tps
);
4046 /* The thread and inferior lists are now synchronized with the
4047 target, our symbols have been relocated, and we're merged the
4048 target's tracepoints with ours. We're done with basic start
4050 rs
->starting_up
= 0;
4052 /* Maybe breakpoints are global and need to be inserted now. */
4053 if (breakpoints_should_be_inserted_now ())
4054 insert_breakpoints ();
4057 /* Open a connection to a remote debugger.
4058 NAME is the filename used for communication. */
4061 remote_open (const char *name
, int from_tty
)
4063 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4066 /* Open a connection to a remote debugger using the extended
4067 remote gdb protocol. NAME is the filename used for communication. */
4070 extended_remote_open (const char *name
, int from_tty
)
4072 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4075 /* Reset all packets back to "unknown support". Called when opening a
4076 new connection to a remote target. */
4079 reset_all_packet_configs_support (void)
4083 for (i
= 0; i
< PACKET_MAX
; i
++)
4084 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4087 /* Initialize all packet configs. */
4090 init_all_packet_configs (void)
4094 for (i
= 0; i
< PACKET_MAX
; i
++)
4096 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4097 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4101 /* Symbol look-up. */
4104 remote_check_symbols (void)
4106 struct remote_state
*rs
= get_remote_state ();
4107 char *msg
, *reply
, *tmp
;
4108 struct bound_minimal_symbol sym
;
4110 struct cleanup
*old_chain
;
4112 /* The remote side has no concept of inferiors that aren't running
4113 yet, it only knows about running processes. If we're connected
4114 but our current inferior is not running, we should not invite the
4115 remote target to request symbol lookups related to its
4116 (unrelated) current process. */
4117 if (!target_has_execution
)
4120 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4123 /* Make sure the remote is pointing at the right process. Note
4124 there's no way to select "no process". */
4125 set_general_process ();
4127 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4128 because we need both at the same time. */
4129 msg
= xmalloc (get_remote_packet_size ());
4130 old_chain
= make_cleanup (xfree
, msg
);
4132 /* Invite target to request symbol lookups. */
4134 putpkt ("qSymbol::");
4135 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4136 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
4139 while (startswith (reply
, "qSymbol:"))
4141 struct bound_minimal_symbol sym
;
4144 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4146 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4147 if (sym
.minsym
== NULL
)
4148 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4151 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4152 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4154 /* If this is a function address, return the start of code
4155 instead of any data function descriptor. */
4156 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4160 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4161 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4165 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4169 do_cleanups (old_chain
);
4172 static struct serial
*
4173 remote_serial_open (const char *name
)
4175 static int udp_warning
= 0;
4177 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4178 of in ser-tcp.c, because it is the remote protocol assuming that the
4179 serial connection is reliable and not the serial connection promising
4181 if (!udp_warning
&& startswith (name
, "udp:"))
4183 warning (_("The remote protocol may be unreliable over UDP.\n"
4184 "Some events may be lost, rendering further debugging "
4189 return serial_open (name
);
4192 /* Inform the target of our permission settings. The permission flags
4193 work without this, but if the target knows the settings, it can do
4194 a couple things. First, it can add its own check, to catch cases
4195 that somehow manage to get by the permissions checks in target
4196 methods. Second, if the target is wired to disallow particular
4197 settings (for instance, a system in the field that is not set up to
4198 be able to stop at a breakpoint), it can object to any unavailable
4202 remote_set_permissions (struct target_ops
*self
)
4204 struct remote_state
*rs
= get_remote_state ();
4206 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4207 "WriteReg:%x;WriteMem:%x;"
4208 "InsertBreak:%x;InsertTrace:%x;"
4209 "InsertFastTrace:%x;Stop:%x",
4210 may_write_registers
, may_write_memory
,
4211 may_insert_breakpoints
, may_insert_tracepoints
,
4212 may_insert_fast_tracepoints
, may_stop
);
4214 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4216 /* If the target didn't like the packet, warn the user. Do not try
4217 to undo the user's settings, that would just be maddening. */
4218 if (strcmp (rs
->buf
, "OK") != 0)
4219 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4222 /* This type describes each known response to the qSupported
4224 struct protocol_feature
4226 /* The name of this protocol feature. */
4229 /* The default for this protocol feature. */
4230 enum packet_support default_support
;
4232 /* The function to call when this feature is reported, or after
4233 qSupported processing if the feature is not supported.
4234 The first argument points to this structure. The second
4235 argument indicates whether the packet requested support be
4236 enabled, disabled, or probed (or the default, if this function
4237 is being called at the end of processing and this feature was
4238 not reported). The third argument may be NULL; if not NULL, it
4239 is a NUL-terminated string taken from the packet following
4240 this feature's name and an equals sign. */
4241 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4244 /* The corresponding packet for this feature. Only used if
4245 FUNC is remote_supported_packet. */
4250 remote_supported_packet (const struct protocol_feature
*feature
,
4251 enum packet_support support
,
4252 const char *argument
)
4256 warning (_("Remote qSupported response supplied an unexpected value for"
4257 " \"%s\"."), feature
->name
);
4261 remote_protocol_packets
[feature
->packet
].support
= support
;
4265 remote_packet_size (const struct protocol_feature
*feature
,
4266 enum packet_support support
, const char *value
)
4268 struct remote_state
*rs
= get_remote_state ();
4273 if (support
!= PACKET_ENABLE
)
4276 if (value
== NULL
|| *value
== '\0')
4278 warning (_("Remote target reported \"%s\" without a size."),
4284 packet_size
= strtol (value
, &value_end
, 16);
4285 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4287 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4288 feature
->name
, value
);
4292 /* Record the new maximum packet size. */
4293 rs
->explicit_packet_size
= packet_size
;
4296 static const struct protocol_feature remote_protocol_features
[] = {
4297 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4298 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4299 PACKET_qXfer_auxv
},
4300 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4301 PACKET_qXfer_exec_file
},
4302 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4303 PACKET_qXfer_features
},
4304 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4305 PACKET_qXfer_libraries
},
4306 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4307 PACKET_qXfer_libraries_svr4
},
4308 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4309 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4310 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4311 PACKET_qXfer_memory_map
},
4312 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4313 PACKET_qXfer_spu_read
},
4314 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4315 PACKET_qXfer_spu_write
},
4316 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4317 PACKET_qXfer_osdata
},
4318 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4319 PACKET_qXfer_threads
},
4320 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4321 PACKET_qXfer_traceframe_info
},
4322 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4323 PACKET_QPassSignals
},
4324 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4325 PACKET_QProgramSignals
},
4326 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4327 PACKET_QStartNoAckMode
},
4328 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4329 PACKET_multiprocess_feature
},
4330 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4331 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4332 PACKET_qXfer_siginfo_read
},
4333 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4334 PACKET_qXfer_siginfo_write
},
4335 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4336 PACKET_ConditionalTracepoints
},
4337 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4338 PACKET_ConditionalBreakpoints
},
4339 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4340 PACKET_BreakpointCommands
},
4341 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4342 PACKET_FastTracepoints
},
4343 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4344 PACKET_StaticTracepoints
},
4345 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4346 PACKET_InstallInTrace
},
4347 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4348 PACKET_DisconnectedTracing_feature
},
4349 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4351 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4353 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4354 PACKET_TracepointSource
},
4355 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4357 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4358 PACKET_EnableDisableTracepoints_feature
},
4359 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4360 PACKET_qXfer_fdpic
},
4361 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4363 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4364 PACKET_QDisableRandomization
},
4365 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4366 { "QTBuffer:size", PACKET_DISABLE
,
4367 remote_supported_packet
, PACKET_QTBuffer_size
},
4368 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4369 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4370 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4371 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4372 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4373 PACKET_qXfer_btrace
},
4374 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4375 PACKET_qXfer_btrace_conf
},
4376 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4377 PACKET_Qbtrace_conf_bts_size
},
4378 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4379 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4380 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4381 PACKET_fork_event_feature
},
4382 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4383 PACKET_vfork_event_feature
},
4384 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4385 PACKET_exec_event_feature
},
4386 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4387 PACKET_Qbtrace_conf_pt_size
},
4388 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
}
4391 static char *remote_support_xml
;
4393 /* Register string appended to "xmlRegisters=" in qSupported query. */
4396 register_remote_support_xml (const char *xml
)
4398 #if defined(HAVE_LIBEXPAT)
4399 if (remote_support_xml
== NULL
)
4400 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4403 char *copy
= xstrdup (remote_support_xml
+ 13);
4404 char *p
= strtok (copy
, ",");
4408 if (strcmp (p
, xml
) == 0)
4415 while ((p
= strtok (NULL
, ",")) != NULL
);
4418 remote_support_xml
= reconcat (remote_support_xml
,
4419 remote_support_xml
, ",", xml
,
4426 remote_query_supported_append (char *msg
, const char *append
)
4429 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4431 return xstrdup (append
);
4435 remote_query_supported (void)
4437 struct remote_state
*rs
= get_remote_state ();
4440 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4442 /* The packet support flags are handled differently for this packet
4443 than for most others. We treat an error, a disabled packet, and
4444 an empty response identically: any features which must be reported
4445 to be used will be automatically disabled. An empty buffer
4446 accomplishes this, since that is also the representation for a list
4447 containing no features. */
4450 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4453 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4455 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4456 q
= remote_query_supported_append (q
, "multiprocess+");
4458 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4459 q
= remote_query_supported_append (q
, "swbreak+");
4460 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4461 q
= remote_query_supported_append (q
, "hwbreak+");
4463 if (remote_support_xml
)
4464 q
= remote_query_supported_append (q
, remote_support_xml
);
4466 q
= remote_query_supported_append (q
, "qRelocInsn+");
4470 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4471 != AUTO_BOOLEAN_FALSE
)
4472 q
= remote_query_supported_append (q
, "fork-events+");
4473 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4474 != AUTO_BOOLEAN_FALSE
)
4475 q
= remote_query_supported_append (q
, "vfork-events+");
4476 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4477 != AUTO_BOOLEAN_FALSE
)
4478 q
= remote_query_supported_append (q
, "exec-events+");
4481 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4482 q
= remote_query_supported_append (q
, "vContSupported+");
4484 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4487 do_cleanups (old_chain
);
4489 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4491 /* If an error occured, warn, but do not return - just reset the
4492 buffer to empty and go on to disable features. */
4493 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4496 warning (_("Remote failure reply: %s"), rs
->buf
);
4501 memset (seen
, 0, sizeof (seen
));
4506 enum packet_support is_supported
;
4507 char *p
, *end
, *name_end
, *value
;
4509 /* First separate out this item from the rest of the packet. If
4510 there's another item after this, we overwrite the separator
4511 (terminated strings are much easier to work with). */
4513 end
= strchr (p
, ';');
4516 end
= p
+ strlen (p
);
4526 warning (_("empty item in \"qSupported\" response"));
4531 name_end
= strchr (p
, '=');
4534 /* This is a name=value entry. */
4535 is_supported
= PACKET_ENABLE
;
4536 value
= name_end
+ 1;
4545 is_supported
= PACKET_ENABLE
;
4549 is_supported
= PACKET_DISABLE
;
4553 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4557 warning (_("unrecognized item \"%s\" "
4558 "in \"qSupported\" response"), p
);
4564 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4565 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4567 const struct protocol_feature
*feature
;
4570 feature
= &remote_protocol_features
[i
];
4571 feature
->func (feature
, is_supported
, value
);
4576 /* If we increased the packet size, make sure to increase the global
4577 buffer size also. We delay this until after parsing the entire
4578 qSupported packet, because this is the same buffer we were
4580 if (rs
->buf_size
< rs
->explicit_packet_size
)
4582 rs
->buf_size
= rs
->explicit_packet_size
;
4583 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4586 /* Handle the defaults for unmentioned features. */
4587 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4590 const struct protocol_feature
*feature
;
4592 feature
= &remote_protocol_features
[i
];
4593 feature
->func (feature
, feature
->default_support
, NULL
);
4597 /* Remove any of the remote.c targets from target stack. Upper targets depend
4598 on it so remove them first. */
4601 remote_unpush_target (void)
4603 pop_all_targets_above (process_stratum
- 1);
4607 remote_open_1 (const char *name
, int from_tty
,
4608 struct target_ops
*target
, int extended_p
)
4610 struct remote_state
*rs
= get_remote_state ();
4613 error (_("To open a remote debug connection, you need to specify what\n"
4614 "serial device is attached to the remote system\n"
4615 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4617 /* See FIXME above. */
4618 if (!target_async_permitted
)
4619 wait_forever_enabled_p
= 1;
4621 /* If we're connected to a running target, target_preopen will kill it.
4622 Ask this question first, before target_preopen has a chance to kill
4624 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4627 && !query (_("Already connected to a remote target. Disconnect? ")))
4628 error (_("Still connected."));
4631 /* Here the possibly existing remote target gets unpushed. */
4632 target_preopen (from_tty
);
4634 /* Make sure we send the passed signals list the next time we resume. */
4635 xfree (rs
->last_pass_packet
);
4636 rs
->last_pass_packet
= NULL
;
4638 /* Make sure we send the program signals list the next time we
4640 xfree (rs
->last_program_signals_packet
);
4641 rs
->last_program_signals_packet
= NULL
;
4643 remote_fileio_reset ();
4644 reopen_exec_file ();
4647 rs
->remote_desc
= remote_serial_open (name
);
4648 if (!rs
->remote_desc
)
4649 perror_with_name (name
);
4651 if (baud_rate
!= -1)
4653 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4655 /* The requested speed could not be set. Error out to
4656 top level after closing remote_desc. Take care to
4657 set remote_desc to NULL to avoid closing remote_desc
4659 serial_close (rs
->remote_desc
);
4660 rs
->remote_desc
= NULL
;
4661 perror_with_name (name
);
4665 serial_setparity (rs
->remote_desc
, serial_parity
);
4666 serial_raw (rs
->remote_desc
);
4668 /* If there is something sitting in the buffer we might take it as a
4669 response to a command, which would be bad. */
4670 serial_flush_input (rs
->remote_desc
);
4674 puts_filtered ("Remote debugging using ");
4675 puts_filtered (name
);
4676 puts_filtered ("\n");
4678 push_target (target
); /* Switch to using remote target now. */
4680 /* Register extra event sources in the event loop. */
4681 remote_async_inferior_event_token
4682 = create_async_event_handler (remote_async_inferior_event_handler
,
4684 rs
->notif_state
= remote_notif_state_allocate ();
4686 /* Reset the target state; these things will be queried either by
4687 remote_query_supported or as they are needed. */
4688 reset_all_packet_configs_support ();
4689 rs
->cached_wait_status
= 0;
4690 rs
->explicit_packet_size
= 0;
4692 rs
->extended
= extended_p
;
4693 rs
->waiting_for_stop_reply
= 0;
4694 rs
->ctrlc_pending_p
= 0;
4696 rs
->general_thread
= not_sent_ptid
;
4697 rs
->continue_thread
= not_sent_ptid
;
4698 rs
->remote_traceframe_number
= -1;
4700 /* Probe for ability to use "ThreadInfo" query, as required. */
4701 rs
->use_threadinfo_query
= 1;
4702 rs
->use_threadextra_query
= 1;
4704 readahead_cache_invalidate ();
4706 if (target_async_permitted
)
4708 /* With this target we start out by owning the terminal. */
4709 remote_async_terminal_ours_p
= 1;
4711 /* FIXME: cagney/1999-09-23: During the initial connection it is
4712 assumed that the target is already ready and able to respond to
4713 requests. Unfortunately remote_start_remote() eventually calls
4714 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4715 around this. Eventually a mechanism that allows
4716 wait_for_inferior() to expect/get timeouts will be
4718 wait_forever_enabled_p
= 0;
4721 /* First delete any symbols previously loaded from shared libraries. */
4722 no_shared_libraries (NULL
, 0);
4725 init_thread_list ();
4727 /* Start the remote connection. If error() or QUIT, discard this
4728 target (we'd otherwise be in an inconsistent state) and then
4729 propogate the error on up the exception chain. This ensures that
4730 the caller doesn't stumble along blindly assuming that the
4731 function succeeded. The CLI doesn't have this problem but other
4732 UI's, such as MI do.
4734 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4735 this function should return an error indication letting the
4736 caller restore the previous state. Unfortunately the command
4737 ``target remote'' is directly wired to this function making that
4738 impossible. On a positive note, the CLI side of this problem has
4739 been fixed - the function set_cmd_context() makes it possible for
4740 all the ``target ....'' commands to share a common callback
4741 function. See cli-dump.c. */
4746 remote_start_remote (from_tty
, target
, extended_p
);
4748 CATCH (ex
, RETURN_MASK_ALL
)
4750 /* Pop the partially set up target - unless something else did
4751 already before throwing the exception. */
4752 if (rs
->remote_desc
!= NULL
)
4753 remote_unpush_target ();
4754 if (target_async_permitted
)
4755 wait_forever_enabled_p
= 1;
4756 throw_exception (ex
);
4761 remote_btrace_reset ();
4763 if (target_async_permitted
)
4764 wait_forever_enabled_p
= 1;
4767 /* Detach the specified process. */
4770 remote_detach_pid (int pid
)
4772 struct remote_state
*rs
= get_remote_state ();
4774 if (remote_multi_process_p (rs
))
4775 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4777 strcpy (rs
->buf
, "D");
4780 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4782 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4784 else if (rs
->buf
[0] == '\0')
4785 error (_("Remote doesn't know how to detach"));
4787 error (_("Can't detach process."));
4790 /* This detaches a program to which we previously attached, using
4791 inferior_ptid to identify the process. After this is done, GDB
4792 can be used to debug some other program. We better not have left
4793 any breakpoints in the target program or it'll die when it hits
4797 remote_detach_1 (const char *args
, int from_tty
)
4799 int pid
= ptid_get_pid (inferior_ptid
);
4800 struct remote_state
*rs
= get_remote_state ();
4801 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4805 error (_("Argument given to \"detach\" when remotely debugging."));
4807 if (!target_has_execution
)
4808 error (_("No process to detach from."));
4812 char *exec_file
= get_exec_file (0);
4813 if (exec_file
== NULL
)
4815 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4816 target_pid_to_str (pid_to_ptid (pid
)));
4817 gdb_flush (gdb_stdout
);
4820 /* Tell the remote target to detach. */
4821 remote_detach_pid (pid
);
4823 if (from_tty
&& !rs
->extended
)
4824 puts_filtered (_("Ending remote debugging.\n"));
4826 /* Check to see if we are detaching a fork parent. Note that if we
4827 are detaching a fork child, tp == NULL. */
4828 is_fork_parent
= (tp
!= NULL
4829 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4831 /* If doing detach-on-fork, we don't mourn, because that will delete
4832 breakpoints that should be available for the followed inferior. */
4833 if (!is_fork_parent
)
4834 target_mourn_inferior ();
4837 inferior_ptid
= null_ptid
;
4838 detach_inferior (pid
);
4843 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4845 remote_detach_1 (args
, from_tty
);
4849 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4851 remote_detach_1 (args
, from_tty
);
4854 /* Target follow-fork function for remote targets. On entry, and
4855 at return, the current inferior is the fork parent.
4857 Note that although this is currently only used for extended-remote,
4858 it is named remote_follow_fork in anticipation of using it for the
4859 remote target as well. */
4862 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4865 struct remote_state
*rs
= get_remote_state ();
4866 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4868 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4869 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4871 /* When following the parent and detaching the child, we detach
4872 the child here. For the case of following the child and
4873 detaching the parent, the detach is done in the target-
4874 independent follow fork code in infrun.c. We can't use
4875 target_detach when detaching an unfollowed child because
4876 the client side doesn't know anything about the child. */
4877 if (detach_fork
&& !follow_child
)
4879 /* Detach the fork child. */
4883 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4884 child_pid
= ptid_get_pid (child_ptid
);
4886 remote_detach_pid (child_pid
);
4887 detach_inferior (child_pid
);
4893 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
4894 in the program space of the new inferior. On entry and at return the
4895 current inferior is the exec'ing inferior. INF is the new exec'd
4896 inferior, which may be the same as the exec'ing inferior unless
4897 follow-exec-mode is "new". */
4900 remote_follow_exec (struct target_ops
*ops
,
4901 struct inferior
*inf
, char *execd_pathname
)
4903 /* We know that this is a target file name, so if it has the "target:"
4904 prefix we strip it off before saving it in the program space. */
4905 if (is_target_filename (execd_pathname
))
4906 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
4908 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
4911 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4914 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4917 error (_("Argument given to \"disconnect\" when remotely debugging."));
4919 /* Make sure we unpush even the extended remote targets; mourn
4920 won't do it. So call remote_mourn directly instead of
4921 target_mourn_inferior. */
4922 remote_mourn (target
);
4925 puts_filtered ("Ending remote debugging.\n");
4928 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4929 be chatty about it. */
4932 extended_remote_attach (struct target_ops
*target
, const char *args
,
4935 struct remote_state
*rs
= get_remote_state ();
4937 char *wait_status
= NULL
;
4939 pid
= parse_pid_to_attach (args
);
4941 /* Remote PID can be freely equal to getpid, do not check it here the same
4942 way as in other targets. */
4944 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4945 error (_("This target does not support attaching to a process"));
4949 char *exec_file
= get_exec_file (0);
4952 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4953 target_pid_to_str (pid_to_ptid (pid
)));
4955 printf_unfiltered (_("Attaching to %s\n"),
4956 target_pid_to_str (pid_to_ptid (pid
)));
4958 gdb_flush (gdb_stdout
);
4961 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4963 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4965 switch (packet_ok (rs
->buf
,
4966 &remote_protocol_packets
[PACKET_vAttach
]))
4971 /* Save the reply for later. */
4972 wait_status
= alloca (strlen (rs
->buf
) + 1);
4973 strcpy (wait_status
, rs
->buf
);
4975 else if (strcmp (rs
->buf
, "OK") != 0)
4976 error (_("Attaching to %s failed with: %s"),
4977 target_pid_to_str (pid_to_ptid (pid
)),
4980 case PACKET_UNKNOWN
:
4981 error (_("This target does not support attaching to a process"));
4983 error (_("Attaching to %s failed"),
4984 target_pid_to_str (pid_to_ptid (pid
)));
4987 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4989 inferior_ptid
= pid_to_ptid (pid
);
4993 struct thread_info
*thread
;
4995 /* Get list of threads. */
4996 remote_update_thread_list (target
);
4998 thread
= first_thread_of_process (pid
);
5000 inferior_ptid
= thread
->ptid
;
5002 inferior_ptid
= pid_to_ptid (pid
);
5004 /* Invalidate our notion of the remote current thread. */
5005 record_currthread (rs
, minus_one_ptid
);
5009 /* Now, if we have thread information, update inferior_ptid. */
5010 inferior_ptid
= remote_current_thread (inferior_ptid
);
5012 /* Add the main thread to the thread list. */
5013 add_thread_silent (inferior_ptid
);
5016 /* Next, if the target can specify a description, read it. We do
5017 this before anything involving memory or registers. */
5018 target_find_description ();
5022 /* Use the previously fetched status. */
5023 gdb_assert (wait_status
!= NULL
);
5025 if (target_can_async_p ())
5027 struct notif_event
*reply
5028 = remote_notif_parse (¬if_client_stop
, wait_status
);
5030 push_stop_reply ((struct stop_reply
*) reply
);
5036 gdb_assert (wait_status
!= NULL
);
5037 strcpy (rs
->buf
, wait_status
);
5038 rs
->cached_wait_status
= 1;
5042 gdb_assert (wait_status
== NULL
);
5045 /* Implementation of the to_post_attach method. */
5048 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5050 /* In certain cases GDB might not have had the chance to start
5051 symbol lookup up until now. This could happen if the debugged
5052 binary is not using shared libraries, the vsyscall page is not
5053 present (on Linux) and the binary itself hadn't changed since the
5054 debugging process was started. */
5055 if (symfile_objfile
!= NULL
)
5056 remote_check_symbols();
5060 /* Check for the availability of vCont. This function should also check
5064 remote_vcont_probe (struct remote_state
*rs
)
5068 strcpy (rs
->buf
, "vCont?");
5070 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5073 /* Make sure that the features we assume are supported. */
5074 if (startswith (buf
, "vCont"))
5077 int support_c
, support_C
;
5079 rs
->supports_vCont
.s
= 0;
5080 rs
->supports_vCont
.S
= 0;
5083 rs
->supports_vCont
.t
= 0;
5084 rs
->supports_vCont
.r
= 0;
5085 while (p
&& *p
== ';')
5088 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5089 rs
->supports_vCont
.s
= 1;
5090 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5091 rs
->supports_vCont
.S
= 1;
5092 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5094 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5096 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5097 rs
->supports_vCont
.t
= 1;
5098 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5099 rs
->supports_vCont
.r
= 1;
5101 p
= strchr (p
, ';');
5104 /* If c, and C are not all supported, we can't use vCont. Clearing
5105 BUF will make packet_ok disable the packet. */
5106 if (!support_c
|| !support_C
)
5110 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5113 /* Helper function for building "vCont" resumptions. Write a
5114 resumption to P. ENDP points to one-passed-the-end of the buffer
5115 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5116 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5117 resumed thread should be single-stepped and/or signalled. If PTID
5118 equals minus_one_ptid, then all threads are resumed; if PTID
5119 represents a process, then all threads of the process are resumed;
5120 the thread to be stepped and/or signalled is given in the global
5124 append_resumption (char *p
, char *endp
,
5125 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5127 struct remote_state
*rs
= get_remote_state ();
5129 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5130 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5132 /* GDB is willing to range step. */
5133 && use_range_stepping
5134 /* Target supports range stepping. */
5135 && rs
->supports_vCont
.r
5136 /* We don't currently support range stepping multiple
5137 threads with a wildcard (though the protocol allows it,
5138 so stubs shouldn't make an active effort to forbid
5140 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5142 struct thread_info
*tp
;
5144 if (ptid_equal (ptid
, minus_one_ptid
))
5146 /* If we don't know about the target thread's tid, then
5147 we're resuming magic_null_ptid (see caller). */
5148 tp
= find_thread_ptid (magic_null_ptid
);
5151 tp
= find_thread_ptid (ptid
);
5152 gdb_assert (tp
!= NULL
);
5154 if (tp
->control
.may_range_step
)
5156 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5158 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5159 phex_nz (tp
->control
.step_range_start
,
5161 phex_nz (tp
->control
.step_range_end
,
5165 p
+= xsnprintf (p
, endp
- p
, ";s");
5168 p
+= xsnprintf (p
, endp
- p
, ";s");
5169 else if (siggnal
!= GDB_SIGNAL_0
)
5170 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5172 p
+= xsnprintf (p
, endp
- p
, ";c");
5174 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5178 /* All (-1) threads of process. */
5179 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5181 p
+= xsnprintf (p
, endp
- p
, ":");
5182 p
= write_ptid (p
, endp
, nptid
);
5184 else if (!ptid_equal (ptid
, minus_one_ptid
))
5186 p
+= xsnprintf (p
, endp
- p
, ":");
5187 p
= write_ptid (p
, endp
, ptid
);
5193 /* Append a vCont continue-with-signal action for threads that have a
5194 non-zero stop signal. */
5197 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5199 struct thread_info
*thread
;
5201 ALL_NON_EXITED_THREADS (thread
)
5202 if (ptid_match (thread
->ptid
, ptid
)
5203 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5204 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5206 p
= append_resumption (p
, endp
, thread
->ptid
,
5207 0, thread
->suspend
.stop_signal
);
5208 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5214 /* Resume the remote inferior by using a "vCont" packet. The thread
5215 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5216 resumed thread should be single-stepped and/or signalled. If PTID
5217 equals minus_one_ptid, then all threads are resumed; the thread to
5218 be stepped and/or signalled is given in the global INFERIOR_PTID.
5219 This function returns non-zero iff it resumes the inferior.
5221 This function issues a strict subset of all possible vCont commands at the
5225 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5227 struct remote_state
*rs
= get_remote_state ();
5231 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5232 remote_vcont_probe (rs
);
5234 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5238 endp
= rs
->buf
+ get_remote_packet_size ();
5240 /* If we could generate a wider range of packets, we'd have to worry
5241 about overflowing BUF. Should there be a generic
5242 "multi-part-packet" packet? */
5244 p
+= xsnprintf (p
, endp
- p
, "vCont");
5246 if (ptid_equal (ptid
, magic_null_ptid
))
5248 /* MAGIC_NULL_PTID means that we don't have any active threads,
5249 so we don't have any TID numbers the inferior will
5250 understand. Make sure to only send forms that do not specify
5252 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5254 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5256 /* Resume all threads (of all processes, or of a single
5257 process), with preference for INFERIOR_PTID. This assumes
5258 inferior_ptid belongs to the set of all threads we are about
5260 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5262 /* Step inferior_ptid, with or without signal. */
5263 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5266 /* Also pass down any pending signaled resumption for other
5267 threads not the current. */
5268 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5270 /* And continue others without a signal. */
5271 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5275 /* Scheduler locking; resume only PTID. */
5276 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5279 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5284 /* In non-stop, the stub replies to vCont with "OK". The stop
5285 reply will be reported asynchronously by means of a `%Stop'
5287 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5288 if (strcmp (rs
->buf
, "OK") != 0)
5289 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5295 /* Tell the remote machine to resume. */
5298 remote_resume (struct target_ops
*ops
,
5299 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5301 struct remote_state
*rs
= get_remote_state ();
5304 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5305 (explained in remote-notif.c:handle_notification) so
5306 remote_notif_process is not called. We need find a place where
5307 it is safe to start a 'vNotif' sequence. It is good to do it
5308 before resuming inferior, because inferior was stopped and no RSP
5309 traffic at that moment. */
5311 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5313 rs
->last_sent_signal
= siggnal
;
5314 rs
->last_sent_step
= step
;
5316 /* The vCont packet doesn't need to specify threads via Hc. */
5317 /* No reverse support (yet) for vCont. */
5318 if (execution_direction
!= EXEC_REVERSE
)
5319 if (remote_vcont_resume (ptid
, step
, siggnal
))
5322 /* All other supported resume packets do use Hc, so set the continue
5324 if (ptid_equal (ptid
, minus_one_ptid
))
5325 set_continue_thread (any_thread_ptid
);
5327 set_continue_thread (ptid
);
5330 if (execution_direction
== EXEC_REVERSE
)
5332 /* We don't pass signals to the target in reverse exec mode. */
5333 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5334 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5337 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5338 error (_("Remote reverse-step not supported."));
5339 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5340 error (_("Remote reverse-continue not supported."));
5342 strcpy (buf
, step
? "bs" : "bc");
5344 else if (siggnal
!= GDB_SIGNAL_0
)
5346 buf
[0] = step
? 'S' : 'C';
5347 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5348 buf
[2] = tohex (((int) siggnal
) & 0xf);
5352 strcpy (buf
, step
? "s" : "c");
5357 /* We are about to start executing the inferior, let's register it
5358 with the event loop. NOTE: this is the one place where all the
5359 execution commands end up. We could alternatively do this in each
5360 of the execution commands in infcmd.c. */
5361 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5362 into infcmd.c in order to allow inferior function calls to work
5363 NOT asynchronously. */
5364 if (target_can_async_p ())
5367 /* We've just told the target to resume. The remote server will
5368 wait for the inferior to stop, and then send a stop reply. In
5369 the mean time, we can't start another command/query ourselves
5370 because the stub wouldn't be ready to process it. This applies
5371 only to the base all-stop protocol, however. In non-stop (which
5372 only supports vCont), the stub replies with an "OK", and is
5373 immediate able to process further serial input. */
5375 rs
->waiting_for_stop_reply
= 1;
5379 /* Set up the signal handler for SIGINT, while the target is
5380 executing, ovewriting the 'regular' SIGINT signal handler. */
5382 async_initialize_sigint_signal_handler (void)
5384 signal (SIGINT
, async_handle_remote_sigint
);
5387 /* Signal handler for SIGINT, while the target is executing. */
5389 async_handle_remote_sigint (int sig
)
5391 signal (sig
, async_handle_remote_sigint_twice
);
5392 /* Note we need to go through gdb_call_async_signal_handler in order
5393 to wake up the event loop on Windows. */
5394 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5397 /* Signal handler for SIGINT, installed after SIGINT has already been
5398 sent once. It will take effect the second time that the user sends
5401 async_handle_remote_sigint_twice (int sig
)
5403 signal (sig
, async_handle_remote_sigint
);
5404 /* See note in async_handle_remote_sigint. */
5405 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5408 /* Implementation of to_check_pending_interrupt. */
5411 remote_check_pending_interrupt (struct target_ops
*self
)
5413 struct async_signal_handler
*token
= async_sigint_remote_twice_token
;
5415 if (async_signal_handler_is_marked (token
))
5417 clear_async_signal_handler (token
);
5418 call_async_signal_handler (token
);
5422 /* Perform the real interruption of the target execution, in response
5425 async_remote_interrupt (gdb_client_data arg
)
5428 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5430 target_stop (inferior_ptid
);
5433 /* Perform interrupt, if the first attempt did not succeed. Just give
5434 up on the target alltogether. */
5436 async_remote_interrupt_twice (gdb_client_data arg
)
5439 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5444 /* Reinstall the usual SIGINT handlers, after the target has
5447 async_cleanup_sigint_signal_handler (void *dummy
)
5449 signal (SIGINT
, handle_sigint
);
5452 /* Send ^C to target to halt it. Target will respond, and send us a
5454 static void (*ofunc
) (int);
5456 /* The command line interface's interrupt routine. This function is installed
5457 as a signal handler for SIGINT. The first time a user requests an
5458 interrupt, we call remote_interrupt to send a break or ^C. If there is no
5459 response from the target (it didn't stop when the user requested it),
5460 we ask the user if he'd like to detach from the target. */
5463 sync_remote_interrupt (int signo
)
5465 /* If this doesn't work, try more severe steps. */
5466 signal (signo
, sync_remote_interrupt_twice
);
5468 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5471 /* The user typed ^C twice. */
5474 sync_remote_interrupt_twice (int signo
)
5476 signal (signo
, ofunc
);
5477 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5478 signal (signo
, sync_remote_interrupt
);
5481 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5482 thread, all threads of a remote process, or all threads of all
5486 remote_stop_ns (ptid_t ptid
)
5488 struct remote_state
*rs
= get_remote_state ();
5490 char *endp
= rs
->buf
+ get_remote_packet_size ();
5492 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5493 remote_vcont_probe (rs
);
5495 if (!rs
->supports_vCont
.t
)
5496 error (_("Remote server does not support stopping threads"));
5498 if (ptid_equal (ptid
, minus_one_ptid
)
5499 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5500 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5505 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5507 if (ptid_is_pid (ptid
))
5508 /* All (-1) threads of process. */
5509 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5512 /* Small optimization: if we already have a stop reply for
5513 this thread, no use in telling the stub we want this
5515 if (peek_stop_reply (ptid
))
5521 write_ptid (p
, endp
, nptid
);
5524 /* In non-stop, we get an immediate OK reply. The stop reply will
5525 come in asynchronously by notification. */
5527 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5528 if (strcmp (rs
->buf
, "OK") != 0)
5529 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5532 /* All-stop version of target_interrupt. Sends a break or a ^C to
5533 interrupt the remote target. It is undefined which thread of which
5534 process reports the interrupt. */
5537 remote_interrupt_as (ptid_t ptid
)
5539 struct remote_state
*rs
= get_remote_state ();
5541 rs
->ctrlc_pending_p
= 1;
5543 /* If the inferior is stopped already, but the core didn't know
5544 about it yet, just ignore the request. The cached wait status
5545 will be collected in remote_wait. */
5546 if (rs
->cached_wait_status
)
5549 /* Send interrupt_sequence to remote target. */
5550 send_interrupt_sequence ();
5553 /* Implement the to_stop function for the remote targets. */
5556 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5559 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5562 remote_stop_ns (ptid
);
5565 /* We don't currently have a way to transparently pause the
5566 remote target in all-stop mode. Interrupt it instead. */
5567 remote_interrupt_as (ptid
);
5571 /* Implement the to_interrupt function for the remote targets. */
5574 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5577 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5581 /* We don't currently have a way to ^C the remote target in
5582 non-stop mode. Stop it (with no signal) instead. */
5583 remote_stop_ns (ptid
);
5586 remote_interrupt_as (ptid
);
5589 /* Ask the user what to do when an interrupt is received. */
5592 interrupt_query (void)
5594 struct remote_state
*rs
= get_remote_state ();
5595 struct cleanup
*old_chain
;
5597 old_chain
= make_cleanup_restore_target_terminal ();
5598 target_terminal_ours ();
5600 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5602 if (query (_("The target is not responding to interrupt requests.\n"
5603 "Stop debugging it? ")))
5605 remote_unpush_target ();
5606 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5611 if (query (_("Interrupted while waiting for the program.\n"
5612 "Give up waiting? ")))
5616 do_cleanups (old_chain
);
5619 /* Enable/disable target terminal ownership. Most targets can use
5620 terminal groups to control terminal ownership. Remote targets are
5621 different in that explicit transfer of ownership to/from GDB/target
5625 remote_terminal_inferior (struct target_ops
*self
)
5627 if (!target_async_permitted
)
5628 /* Nothing to do. */
5631 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5632 idempotent. The event-loop GDB talking to an asynchronous target
5633 with a synchronous command calls this function from both
5634 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5635 transfer the terminal to the target when it shouldn't this guard
5637 if (!remote_async_terminal_ours_p
)
5639 delete_file_handler (input_fd
);
5640 remote_async_terminal_ours_p
= 0;
5641 async_initialize_sigint_signal_handler ();
5642 /* NOTE: At this point we could also register our selves as the
5643 recipient of all input. Any characters typed could then be
5644 passed on down to the target. */
5648 remote_terminal_ours (struct target_ops
*self
)
5650 if (!target_async_permitted
)
5651 /* Nothing to do. */
5654 /* See FIXME in remote_terminal_inferior. */
5655 if (remote_async_terminal_ours_p
)
5657 async_cleanup_sigint_signal_handler (NULL
);
5658 add_file_handler (input_fd
, stdin_event_handler
, 0);
5659 remote_async_terminal_ours_p
= 1;
5663 remote_console_output (char *msg
)
5667 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5670 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5674 fputs_unfiltered (tb
, gdb_stdtarg
);
5676 gdb_flush (gdb_stdtarg
);
5679 typedef struct cached_reg
5682 gdb_byte data
[MAX_REGISTER_SIZE
];
5685 DEF_VEC_O(cached_reg_t
);
5687 typedef struct stop_reply
5689 struct notif_event base
;
5691 /* The identifier of the thread about this event */
5694 /* The remote state this event is associated with. When the remote
5695 connection, represented by a remote_state object, is closed,
5696 all the associated stop_reply events should be released. */
5697 struct remote_state
*rs
;
5699 struct target_waitstatus ws
;
5701 /* Expedited registers. This makes remote debugging a bit more
5702 efficient for those targets that provide critical registers as
5703 part of their normal status mechanism (as another roundtrip to
5704 fetch them is avoided). */
5705 VEC(cached_reg_t
) *regcache
;
5707 enum target_stop_reason stop_reason
;
5709 CORE_ADDR watch_data_address
;
5714 DECLARE_QUEUE_P (stop_reply_p
);
5715 DEFINE_QUEUE_P (stop_reply_p
);
5716 /* The list of already fetched and acknowledged stop events. This
5717 queue is used for notification Stop, and other notifications
5718 don't need queue for their events, because the notification events
5719 of Stop can't be consumed immediately, so that events should be
5720 queued first, and be consumed by remote_wait_{ns,as} one per
5721 time. Other notifications can consume their events immediately,
5722 so queue is not needed for them. */
5723 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5726 stop_reply_xfree (struct stop_reply
*r
)
5728 notif_event_xfree ((struct notif_event
*) r
);
5731 /* Return the length of the stop reply queue. */
5734 stop_reply_queue_length (void)
5736 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
5740 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5741 struct notif_event
*event
)
5743 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5747 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5748 struct notif_event
*event
)
5750 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5753 putpkt ((char *) self
->ack_command
);
5755 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5756 /* We got an unknown stop reply. */
5757 error (_("Unknown stop reply"));
5759 push_stop_reply (stop_reply
);
5763 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5765 /* We can't get pending events in remote_notif_process for
5766 notification stop, and we have to do this in remote_wait_ns
5767 instead. If we fetch all queued events from stub, remote stub
5768 may exit and we have no chance to process them back in
5770 mark_async_event_handler (remote_async_inferior_event_token
);
5775 stop_reply_dtr (struct notif_event
*event
)
5777 struct stop_reply
*r
= (struct stop_reply
*) event
;
5779 VEC_free (cached_reg_t
, r
->regcache
);
5782 static struct notif_event
*
5783 remote_notif_stop_alloc_reply (void)
5785 /* We cast to a pointer to the "base class". */
5786 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
5788 r
->dtr
= stop_reply_dtr
;
5793 /* A client of notification Stop. */
5795 struct notif_client notif_client_stop
=
5799 remote_notif_stop_parse
,
5800 remote_notif_stop_ack
,
5801 remote_notif_stop_can_get_pending_events
,
5802 remote_notif_stop_alloc_reply
,
5806 /* A parameter to pass data in and out. */
5808 struct queue_iter_param
5811 struct stop_reply
*output
;
5814 /* Determine if THREAD is a pending fork parent thread. ARG contains
5815 the pid of the process that owns the threads we want to check, or
5816 -1 if we want to check all threads. */
5819 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5822 if (ws
->kind
== TARGET_WAITKIND_FORKED
5823 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5825 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5832 /* Check whether EVENT is a fork event, and if it is, remove the
5833 fork child from the context list passed in DATA. */
5836 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5837 QUEUE_ITER (stop_reply_p
) *iter
,
5841 struct queue_iter_param
*param
= data
;
5842 struct threads_listing_context
*context
= param
->input
;
5844 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5845 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5847 threads_listing_context_remove (&event
->ws
, context
);
5853 /* If CONTEXT contains any fork child threads that have not been
5854 reported yet, remove them from the CONTEXT list. If such a
5855 thread exists it is because we are stopped at a fork catchpoint
5856 and have not yet called follow_fork, which will set up the
5857 host-side data structures for the new process. */
5860 remove_new_fork_children (struct threads_listing_context
*context
)
5862 struct thread_info
* thread
;
5864 struct notif_client
*notif
= ¬if_client_stop
;
5865 struct queue_iter_param param
;
5867 /* For any threads stopped at a fork event, remove the corresponding
5868 fork child threads from the CONTEXT list. */
5869 ALL_NON_EXITED_THREADS (thread
)
5871 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5873 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5875 threads_listing_context_remove (ws
, context
);
5879 /* Check for any pending fork events (not reported or processed yet)
5880 in process PID and remove those fork child threads from the
5881 CONTEXT list as well. */
5882 remote_notif_get_pending_events (notif
);
5883 param
.input
= context
;
5884 param
.output
= NULL
;
5885 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5886 remove_child_of_pending_fork
, ¶m
);
5889 /* Remove stop replies in the queue if its pid is equal to the given
5893 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5894 QUEUE_ITER (stop_reply_p
) *iter
,
5898 struct queue_iter_param
*param
= data
;
5899 struct inferior
*inf
= param
->input
;
5901 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5903 stop_reply_xfree (event
);
5904 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5910 /* Discard all pending stop replies of inferior INF. */
5913 discard_pending_stop_replies (struct inferior
*inf
)
5916 struct queue_iter_param param
;
5917 struct stop_reply
*reply
;
5918 struct remote_state
*rs
= get_remote_state ();
5919 struct remote_notif_state
*rns
= rs
->notif_state
;
5921 /* This function can be notified when an inferior exists. When the
5922 target is not remote, the notification state is NULL. */
5923 if (rs
->remote_desc
== NULL
)
5926 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5928 /* Discard the in-flight notification. */
5929 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5931 stop_reply_xfree (reply
);
5932 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5936 param
.output
= NULL
;
5937 /* Discard the stop replies we have already pulled with
5939 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5940 remove_stop_reply_for_inferior
, ¶m
);
5943 /* If its remote state is equal to the given remote state,
5944 remove EVENT from the stop reply queue. */
5947 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5948 QUEUE_ITER (stop_reply_p
) *iter
,
5952 struct queue_iter_param
*param
= data
;
5953 struct remote_state
*rs
= param
->input
;
5955 if (event
->rs
== rs
)
5957 stop_reply_xfree (event
);
5958 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5964 /* Discard the stop replies for RS in stop_reply_queue. */
5967 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5969 struct queue_iter_param param
;
5972 param
.output
= NULL
;
5973 /* Discard the stop replies we have already pulled with
5975 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5976 remove_stop_reply_of_remote_state
, ¶m
);
5979 /* A parameter to pass data in and out. */
5982 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5983 QUEUE_ITER (stop_reply_p
) *iter
,
5987 struct queue_iter_param
*param
= data
;
5988 ptid_t
*ptid
= param
->input
;
5990 if (ptid_match (event
->ptid
, *ptid
))
5992 param
->output
= event
;
5993 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6000 /* Remove the first reply in 'stop_reply_queue' which matches
6003 static struct stop_reply
*
6004 remote_notif_remove_queued_reply (ptid_t ptid
)
6006 struct queue_iter_param param
;
6008 param
.input
= &ptid
;
6009 param
.output
= NULL
;
6011 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6012 remote_notif_remove_once_on_match
, ¶m
);
6014 fprintf_unfiltered (gdb_stdlog
,
6015 "notif: discard queued event: 'Stop' in %s\n",
6016 target_pid_to_str (ptid
));
6018 return param
.output
;
6021 /* Look for a queued stop reply belonging to PTID. If one is found,
6022 remove it from the queue, and return it. Returns NULL if none is
6023 found. If there are still queued events left to process, tell the
6024 event loop to get back to target_wait soon. */
6026 static struct stop_reply
*
6027 queued_stop_reply (ptid_t ptid
)
6029 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6031 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6032 /* There's still at least an event left. */
6033 mark_async_event_handler (remote_async_inferior_event_token
);
6038 /* Push a fully parsed stop reply in the stop reply queue. Since we
6039 know that we now have at least one queued event left to pass to the
6040 core side, tell the event loop to get back to target_wait soon. */
6043 push_stop_reply (struct stop_reply
*new_event
)
6045 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6048 fprintf_unfiltered (gdb_stdlog
,
6049 "notif: push 'Stop' %s to queue %d\n",
6050 target_pid_to_str (new_event
->ptid
),
6051 QUEUE_length (stop_reply_p
,
6054 mark_async_event_handler (remote_async_inferior_event_token
);
6058 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6059 QUEUE_ITER (stop_reply_p
) *iter
,
6060 struct stop_reply
*event
,
6063 ptid_t
*ptid
= data
;
6065 return !(ptid_equal (*ptid
, event
->ptid
)
6066 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6069 /* Returns true if we have a stop reply for PTID. */
6072 peek_stop_reply (ptid_t ptid
)
6074 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6075 stop_reply_match_ptid_and_ws
, &ptid
);
6078 /* Skip PACKET until the next semi-colon (or end of string). */
6081 skip_to_semicolon (char *p
)
6083 while (*p
!= '\0' && *p
!= ';')
6088 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6089 starting with P and ending with PEND matches PREFIX. */
6092 strprefix (const char *p
, const char *pend
, const char *prefix
)
6094 for ( ; p
< pend
; p
++, prefix
++)
6097 return *prefix
== '\0';
6100 /* Parse the stop reply in BUF. Either the function succeeds, and the
6101 result is stored in EVENT, or throws an error. */
6104 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6106 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6111 event
->ptid
= null_ptid
;
6112 event
->rs
= get_remote_state ();
6113 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6114 event
->ws
.value
.integer
= 0;
6115 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6116 event
->regcache
= NULL
;
6121 case 'T': /* Status with PC, SP, FP, ... */
6122 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6123 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6125 n... = register number
6126 r... = register contents
6129 p
= &buf
[3]; /* after Txx */
6135 p1
= strchr (p
, ':');
6137 error (_("Malformed packet(a) (missing colon): %s\n\
6141 error (_("Malformed packet(a) (missing register number): %s\n\
6145 /* Some "registers" are actually extended stop information.
6146 Note if you're adding a new entry here: GDB 7.9 and
6147 earlier assume that all register "numbers" that start
6148 with an hex digit are real register numbers. Make sure
6149 the server only sends such a packet if it knows the
6150 client understands it. */
6152 if (strprefix (p
, p1
, "thread"))
6153 event
->ptid
= read_ptid (++p1
, &p
);
6154 else if (strprefix (p
, p1
, "watch")
6155 || strprefix (p
, p1
, "rwatch")
6156 || strprefix (p
, p1
, "awatch"))
6158 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6159 p
= unpack_varlen_hex (++p1
, &addr
);
6160 event
->watch_data_address
= (CORE_ADDR
) addr
;
6162 else if (strprefix (p
, p1
, "swbreak"))
6164 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6166 /* Make sure the stub doesn't forget to indicate support
6168 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6169 error (_("Unexpected swbreak stop reason"));
6171 /* The value part is documented as "must be empty",
6172 though we ignore it, in case we ever decide to make
6173 use of it in a backward compatible way. */
6174 p
= skip_to_semicolon (p1
+ 1);
6176 else if (strprefix (p
, p1
, "hwbreak"))
6178 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6180 /* Make sure the stub doesn't forget to indicate support
6182 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6183 error (_("Unexpected hwbreak stop reason"));
6186 p
= skip_to_semicolon (p1
+ 1);
6188 else if (strprefix (p
, p1
, "library"))
6190 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6191 p
= skip_to_semicolon (p1
+ 1);
6193 else if (strprefix (p
, p1
, "replaylog"))
6195 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6196 /* p1 will indicate "begin" or "end", but it makes
6197 no difference for now, so ignore it. */
6198 p
= skip_to_semicolon (p1
+ 1);
6200 else if (strprefix (p
, p1
, "core"))
6204 p
= unpack_varlen_hex (++p1
, &c
);
6207 else if (strprefix (p
, p1
, "fork"))
6209 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6210 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6212 else if (strprefix (p
, p1
, "vfork"))
6214 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6215 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6217 else if (strprefix (p
, p1
, "vforkdone"))
6219 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6220 p
= skip_to_semicolon (p1
+ 1);
6222 else if (strncmp (p
, "exec", p1
- p
) == 0)
6225 char pathname
[PATH_MAX
];
6228 /* Determine the length of the execd pathname. */
6229 p
= unpack_varlen_hex (++p1
, &ignored
);
6230 pathlen
= (p
- p1
) / 2;
6232 /* Save the pathname for event reporting and for
6233 the next run command. */
6234 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6235 pathname
[pathlen
] = '\0';
6237 /* This is freed during event handling. */
6238 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6239 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6241 /* Skip the registers included in this packet, since
6242 they may be for an architecture different from the
6243 one used by the original program. */
6253 p
= skip_to_semicolon (p1
+ 1);
6258 /* Maybe a real ``P'' register number. */
6259 p_temp
= unpack_varlen_hex (p
, &pnum
);
6260 /* If the first invalid character is the colon, we got a
6261 register number. Otherwise, it's an unknown stop
6265 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6266 cached_reg_t cached_reg
;
6269 error (_("Remote sent bad register number %s: %s\n\
6271 hex_string (pnum
), p
, buf
);
6273 cached_reg
.num
= reg
->regnum
;
6276 fieldsize
= hex2bin (p
, cached_reg
.data
,
6277 register_size (target_gdbarch (),
6280 if (fieldsize
< register_size (target_gdbarch (),
6282 warning (_("Remote reply is too short: %s"), buf
);
6284 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6288 /* Not a number. Silently skip unknown optional
6290 p
= skip_to_semicolon (p1
+ 1);
6295 error (_("Remote register badly formatted: %s\nhere: %s"),
6300 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6304 case 'S': /* Old style status, just signal only. */
6308 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6309 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6310 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6311 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6313 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6316 case 'W': /* Target exited. */
6323 /* GDB used to accept only 2 hex chars here. Stubs should
6324 only send more if they detect GDB supports multi-process
6326 p
= unpack_varlen_hex (&buf
[1], &value
);
6330 /* The remote process exited. */
6331 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6332 event
->ws
.value
.integer
= value
;
6336 /* The remote process exited with a signal. */
6337 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6338 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6339 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6341 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6344 /* If no process is specified, assume inferior_ptid. */
6345 pid
= ptid_get_pid (inferior_ptid
);
6354 else if (startswith (p
, "process:"))
6358 p
+= sizeof ("process:") - 1;
6359 unpack_varlen_hex (p
, &upid
);
6363 error (_("unknown stop reply packet: %s"), buf
);
6366 error (_("unknown stop reply packet: %s"), buf
);
6367 event
->ptid
= pid_to_ptid (pid
);
6372 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6373 error (_("No process or thread specified in stop reply: %s"), buf
);
6376 /* When the stub wants to tell GDB about a new notification reply, it
6377 sends a notification (%Stop, for example). Those can come it at
6378 any time, hence, we have to make sure that any pending
6379 putpkt/getpkt sequence we're making is finished, before querying
6380 the stub for more events with the corresponding ack command
6381 (vStopped, for example). E.g., if we started a vStopped sequence
6382 immediately upon receiving the notification, something like this
6390 1.6) <-- (registers reply to step #1.3)
6392 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6395 To solve this, whenever we parse a %Stop notification successfully,
6396 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6397 doing whatever we were doing:
6403 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6404 2.5) <-- (registers reply to step #2.3)
6406 Eventualy after step #2.5, we return to the event loop, which
6407 notices there's an event on the
6408 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6409 associated callback --- the function below. At this point, we're
6410 always safe to start a vStopped sequence. :
6413 2.7) <-- T05 thread:2
6419 remote_notif_get_pending_events (struct notif_client
*nc
)
6421 struct remote_state
*rs
= get_remote_state ();
6423 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6426 fprintf_unfiltered (gdb_stdlog
,
6427 "notif: process: '%s' ack pending event\n",
6431 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6432 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6436 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6437 if (strcmp (rs
->buf
, "OK") == 0)
6440 remote_notif_ack (nc
, rs
->buf
);
6446 fprintf_unfiltered (gdb_stdlog
,
6447 "notif: process: '%s' no pending reply\n",
6452 /* Called when it is decided that STOP_REPLY holds the info of the
6453 event that is to be returned to the core. This function always
6454 destroys STOP_REPLY. */
6457 process_stop_reply (struct stop_reply
*stop_reply
,
6458 struct target_waitstatus
*status
)
6462 *status
= stop_reply
->ws
;
6463 ptid
= stop_reply
->ptid
;
6465 /* If no thread/process was reported by the stub, assume the current
6467 if (ptid_equal (ptid
, null_ptid
))
6468 ptid
= inferior_ptid
;
6470 if (status
->kind
!= TARGET_WAITKIND_EXITED
6471 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6473 struct remote_state
*rs
= get_remote_state ();
6475 /* Expedited registers. */
6476 if (stop_reply
->regcache
)
6478 struct regcache
*regcache
6479 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6484 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6486 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6487 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6490 rs
->stop_reason
= stop_reply
->stop_reason
;
6491 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6493 remote_notice_new_inferior (ptid
, 0);
6494 demand_private_info (ptid
)->core
= stop_reply
->core
;
6497 stop_reply_xfree (stop_reply
);
6501 /* The non-stop mode version of target_wait. */
6504 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6506 struct remote_state
*rs
= get_remote_state ();
6507 struct stop_reply
*stop_reply
;
6511 /* If in non-stop mode, get out of getpkt even if a
6512 notification is received. */
6514 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6515 0 /* forever */, &is_notif
);
6518 if (ret
!= -1 && !is_notif
)
6521 case 'E': /* Error of some sort. */
6522 /* We're out of sync with the target now. Did it continue
6523 or not? We can't tell which thread it was in non-stop,
6524 so just ignore this. */
6525 warning (_("Remote failure reply: %s"), rs
->buf
);
6527 case 'O': /* Console output. */
6528 remote_console_output (rs
->buf
+ 1);
6531 warning (_("Invalid remote reply: %s"), rs
->buf
);
6535 /* Acknowledge a pending stop reply that may have arrived in the
6537 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6538 remote_notif_get_pending_events (¬if_client_stop
);
6540 /* If indeed we noticed a stop reply, we're done. */
6541 stop_reply
= queued_stop_reply (ptid
);
6542 if (stop_reply
!= NULL
)
6543 return process_stop_reply (stop_reply
, status
);
6545 /* Still no event. If we're just polling for an event, then
6546 return to the event loop. */
6547 if (options
& TARGET_WNOHANG
)
6549 status
->kind
= TARGET_WAITKIND_IGNORE
;
6550 return minus_one_ptid
;
6553 /* Otherwise do a blocking wait. */
6554 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6555 1 /* forever */, &is_notif
);
6559 /* Wait until the remote machine stops, then return, storing status in
6560 STATUS just as `wait' would. */
6563 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6565 struct remote_state
*rs
= get_remote_state ();
6566 ptid_t event_ptid
= null_ptid
;
6568 struct stop_reply
*stop_reply
;
6572 status
->kind
= TARGET_WAITKIND_IGNORE
;
6573 status
->value
.integer
= 0;
6575 stop_reply
= queued_stop_reply (ptid
);
6576 if (stop_reply
!= NULL
)
6577 return process_stop_reply (stop_reply
, status
);
6579 if (rs
->cached_wait_status
)
6580 /* Use the cached wait status, but only once. */
6581 rs
->cached_wait_status
= 0;
6586 int forever
= ((options
& TARGET_WNOHANG
) == 0
6587 && wait_forever_enabled_p
);
6589 if (!rs
->waiting_for_stop_reply
)
6591 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6592 return minus_one_ptid
;
6595 if (!target_is_async_p ())
6597 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6598 /* If the user hit C-c before this packet, or between packets,
6599 pretend that it was hit right here. */
6600 if (check_quit_flag ())
6603 sync_remote_interrupt (SIGINT
);
6607 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6608 _never_ wait for ever -> test on target_is_async_p().
6609 However, before we do that we need to ensure that the caller
6610 knows how to take the target into/out of async mode. */
6611 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6612 forever
, &is_notif
);
6614 if (!target_is_async_p ())
6615 signal (SIGINT
, ofunc
);
6617 /* GDB gets a notification. Return to core as this event is
6619 if (ret
!= -1 && is_notif
)
6620 return minus_one_ptid
;
6622 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6623 return minus_one_ptid
;
6628 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6630 /* We got something. */
6631 rs
->waiting_for_stop_reply
= 0;
6633 /* Assume that the target has acknowledged Ctrl-C unless we receive
6634 an 'F' or 'O' packet. */
6635 if (buf
[0] != 'F' && buf
[0] != 'O')
6636 rs
->ctrlc_pending_p
= 0;
6640 case 'E': /* Error of some sort. */
6641 /* We're out of sync with the target now. Did it continue or
6642 not? Not is more likely, so report a stop. */
6643 warning (_("Remote failure reply: %s"), buf
);
6644 status
->kind
= TARGET_WAITKIND_STOPPED
;
6645 status
->value
.sig
= GDB_SIGNAL_0
;
6647 case 'F': /* File-I/O request. */
6648 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6649 rs
->ctrlc_pending_p
= 0;
6651 case 'T': case 'S': case 'X': case 'W':
6653 struct stop_reply
*stop_reply
6654 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6657 event_ptid
= process_stop_reply (stop_reply
, status
);
6660 case 'O': /* Console output. */
6661 remote_console_output (buf
+ 1);
6663 /* The target didn't really stop; keep waiting. */
6664 rs
->waiting_for_stop_reply
= 1;
6668 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6670 /* Zero length reply means that we tried 'S' or 'C' and the
6671 remote system doesn't support it. */
6672 target_terminal_ours_for_output ();
6674 ("Can't send signals to this remote system. %s not sent.\n",
6675 gdb_signal_to_name (rs
->last_sent_signal
));
6676 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6677 target_terminal_inferior ();
6679 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6680 putpkt ((char *) buf
);
6682 /* We just told the target to resume, so a stop reply is in
6684 rs
->waiting_for_stop_reply
= 1;
6687 /* else fallthrough */
6689 warning (_("Invalid remote reply: %s"), buf
);
6691 rs
->waiting_for_stop_reply
= 1;
6695 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6697 /* Nothing interesting happened. If we're doing a non-blocking
6698 poll, we're done. Otherwise, go back to waiting. */
6699 if (options
& TARGET_WNOHANG
)
6700 return minus_one_ptid
;
6704 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6705 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6707 if (!ptid_equal (event_ptid
, null_ptid
))
6708 record_currthread (rs
, event_ptid
);
6710 event_ptid
= inferior_ptid
;
6713 /* A process exit. Invalidate our notion of current thread. */
6714 record_currthread (rs
, minus_one_ptid
);
6719 /* Wait until the remote machine stops, then return, storing status in
6720 STATUS just as `wait' would. */
6723 remote_wait (struct target_ops
*ops
,
6724 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6729 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6731 event_ptid
= remote_wait_as (ptid
, status
, options
);
6733 if (target_is_async_p ())
6735 /* If there are are events left in the queue tell the event loop
6737 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6738 mark_async_event_handler (remote_async_inferior_event_token
);
6744 /* Fetch a single register using a 'p' packet. */
6747 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6749 struct remote_state
*rs
= get_remote_state ();
6751 char regp
[MAX_REGISTER_SIZE
];
6754 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6757 if (reg
->pnum
== -1)
6762 p
+= hexnumstr (p
, reg
->pnum
);
6765 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6769 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6773 case PACKET_UNKNOWN
:
6776 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6777 gdbarch_register_name (get_regcache_arch (regcache
),
6782 /* If this register is unfetchable, tell the regcache. */
6785 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6789 /* Otherwise, parse and supply the value. */
6795 error (_("fetch_register_using_p: early buf termination"));
6797 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6800 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6804 /* Fetch the registers included in the target's 'g' packet. */
6807 send_g_packet (void)
6809 struct remote_state
*rs
= get_remote_state ();
6812 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6813 remote_send (&rs
->buf
, &rs
->buf_size
);
6815 /* We can get out of synch in various cases. If the first character
6816 in the buffer is not a hex character, assume that has happened
6817 and try to fetch another packet to read. */
6818 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6819 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6820 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6821 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6824 fprintf_unfiltered (gdb_stdlog
,
6825 "Bad register packet; fetching a new packet\n");
6826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6829 buf_len
= strlen (rs
->buf
);
6831 /* Sanity check the received packet. */
6832 if (buf_len
% 2 != 0)
6833 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6839 process_g_packet (struct regcache
*regcache
)
6841 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6842 struct remote_state
*rs
= get_remote_state ();
6843 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6848 buf_len
= strlen (rs
->buf
);
6850 /* Further sanity checks, with knowledge of the architecture. */
6851 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6852 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6854 /* Save the size of the packet sent to us by the target. It is used
6855 as a heuristic when determining the max size of packets that the
6856 target can safely receive. */
6857 if (rsa
->actual_register_packet_size
== 0)
6858 rsa
->actual_register_packet_size
= buf_len
;
6860 /* If this is smaller than we guessed the 'g' packet would be,
6861 update our records. A 'g' reply that doesn't include a register's
6862 value implies either that the register is not available, or that
6863 the 'p' packet must be used. */
6864 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6866 rsa
->sizeof_g_packet
= buf_len
/ 2;
6868 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6870 if (rsa
->regs
[i
].pnum
== -1)
6873 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6874 rsa
->regs
[i
].in_g_packet
= 0;
6876 rsa
->regs
[i
].in_g_packet
= 1;
6880 regs
= alloca (rsa
->sizeof_g_packet
);
6882 /* Unimplemented registers read as all bits zero. */
6883 memset (regs
, 0, rsa
->sizeof_g_packet
);
6885 /* Reply describes registers byte by byte, each byte encoded as two
6886 hex characters. Suck them all up, then supply them to the
6887 register cacheing/storage mechanism. */
6890 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6892 if (p
[0] == 0 || p
[1] == 0)
6893 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6894 internal_error (__FILE__
, __LINE__
,
6895 _("unexpected end of 'g' packet reply"));
6897 if (p
[0] == 'x' && p
[1] == 'x')
6898 regs
[i
] = 0; /* 'x' */
6900 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6904 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6906 struct packet_reg
*r
= &rsa
->regs
[i
];
6910 if (r
->offset
* 2 >= strlen (rs
->buf
))
6911 /* This shouldn't happen - we adjusted in_g_packet above. */
6912 internal_error (__FILE__
, __LINE__
,
6913 _("unexpected end of 'g' packet reply"));
6914 else if (rs
->buf
[r
->offset
* 2] == 'x')
6916 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6917 /* The register isn't available, mark it as such (at
6918 the same time setting the value to zero). */
6919 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6922 regcache_raw_supply (regcache
, r
->regnum
,
6929 fetch_registers_using_g (struct regcache
*regcache
)
6932 process_g_packet (regcache
);
6935 /* Make the remote selected traceframe match GDB's selected
6939 set_remote_traceframe (void)
6942 struct remote_state
*rs
= get_remote_state ();
6944 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6947 /* Avoid recursion, remote_trace_find calls us again. */
6948 rs
->remote_traceframe_number
= get_traceframe_number ();
6950 newnum
= target_trace_find (tfind_number
,
6951 get_traceframe_number (), 0, 0, NULL
);
6953 /* Should not happen. If it does, all bets are off. */
6954 if (newnum
!= get_traceframe_number ())
6955 warning (_("could not set remote traceframe"));
6959 remote_fetch_registers (struct target_ops
*ops
,
6960 struct regcache
*regcache
, int regnum
)
6962 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6965 set_remote_traceframe ();
6966 set_general_thread (inferior_ptid
);
6970 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6972 gdb_assert (reg
!= NULL
);
6974 /* If this register might be in the 'g' packet, try that first -
6975 we are likely to read more than one register. If this is the
6976 first 'g' packet, we might be overly optimistic about its
6977 contents, so fall back to 'p'. */
6978 if (reg
->in_g_packet
)
6980 fetch_registers_using_g (regcache
);
6981 if (reg
->in_g_packet
)
6985 if (fetch_register_using_p (regcache
, reg
))
6988 /* This register is not available. */
6989 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6994 fetch_registers_using_g (regcache
);
6996 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6997 if (!rsa
->regs
[i
].in_g_packet
)
6998 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7000 /* This register is not available. */
7001 regcache_raw_supply (regcache
, i
, NULL
);
7005 /* Prepare to store registers. Since we may send them all (using a
7006 'G' request), we have to read out the ones we don't want to change
7010 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7012 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7014 gdb_byte buf
[MAX_REGISTER_SIZE
];
7016 /* Make sure the entire registers array is valid. */
7017 switch (packet_support (PACKET_P
))
7019 case PACKET_DISABLE
:
7020 case PACKET_SUPPORT_UNKNOWN
:
7021 /* Make sure all the necessary registers are cached. */
7022 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7023 if (rsa
->regs
[i
].in_g_packet
)
7024 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7031 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7032 packet was not recognized. */
7035 store_register_using_P (const struct regcache
*regcache
,
7036 struct packet_reg
*reg
)
7038 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7039 struct remote_state
*rs
= get_remote_state ();
7040 /* Try storing a single register. */
7041 char *buf
= rs
->buf
;
7042 gdb_byte regp
[MAX_REGISTER_SIZE
];
7045 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7048 if (reg
->pnum
== -1)
7051 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7052 p
= buf
+ strlen (buf
);
7053 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7054 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7056 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7058 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7063 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7064 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7065 case PACKET_UNKNOWN
:
7068 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7072 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7073 contents of the register cache buffer. FIXME: ignores errors. */
7076 store_registers_using_G (const struct regcache
*regcache
)
7078 struct remote_state
*rs
= get_remote_state ();
7079 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7083 /* Extract all the registers in the regcache copying them into a
7088 regs
= alloca (rsa
->sizeof_g_packet
);
7089 memset (regs
, 0, rsa
->sizeof_g_packet
);
7090 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7092 struct packet_reg
*r
= &rsa
->regs
[i
];
7095 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7099 /* Command describes registers byte by byte,
7100 each byte encoded as two hex characters. */
7103 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7105 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7107 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7108 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7109 error (_("Could not write registers; remote failure reply '%s'"),
7113 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7114 of the register cache buffer. FIXME: ignores errors. */
7117 remote_store_registers (struct target_ops
*ops
,
7118 struct regcache
*regcache
, int regnum
)
7120 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7123 set_remote_traceframe ();
7124 set_general_thread (inferior_ptid
);
7128 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7130 gdb_assert (reg
!= NULL
);
7132 /* Always prefer to store registers using the 'P' packet if
7133 possible; we often change only a small number of registers.
7134 Sometimes we change a larger number; we'd need help from a
7135 higher layer to know to use 'G'. */
7136 if (store_register_using_P (regcache
, reg
))
7139 /* For now, don't complain if we have no way to write the
7140 register. GDB loses track of unavailable registers too
7141 easily. Some day, this may be an error. We don't have
7142 any way to read the register, either... */
7143 if (!reg
->in_g_packet
)
7146 store_registers_using_G (regcache
);
7150 store_registers_using_G (regcache
);
7152 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7153 if (!rsa
->regs
[i
].in_g_packet
)
7154 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7155 /* See above for why we do not issue an error here. */
7160 /* Return the number of hex digits in num. */
7163 hexnumlen (ULONGEST num
)
7167 for (i
= 0; num
!= 0; i
++)
7173 /* Set BUF to the minimum number of hex digits representing NUM. */
7176 hexnumstr (char *buf
, ULONGEST num
)
7178 int len
= hexnumlen (num
);
7180 return hexnumnstr (buf
, num
, len
);
7184 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7187 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7193 for (i
= width
- 1; i
>= 0; i
--)
7195 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7202 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7205 remote_address_masked (CORE_ADDR addr
)
7207 unsigned int address_size
= remote_address_size
;
7209 /* If "remoteaddresssize" was not set, default to target address size. */
7211 address_size
= gdbarch_addr_bit (target_gdbarch ());
7213 if (address_size
> 0
7214 && address_size
< (sizeof (ULONGEST
) * 8))
7216 /* Only create a mask when that mask can safely be constructed
7217 in a ULONGEST variable. */
7220 mask
= (mask
<< address_size
) - 1;
7226 /* Determine whether the remote target supports binary downloading.
7227 This is accomplished by sending a no-op memory write of zero length
7228 to the target at the specified address. It does not suffice to send
7229 the whole packet, since many stubs strip the eighth bit and
7230 subsequently compute a wrong checksum, which causes real havoc with
7233 NOTE: This can still lose if the serial line is not eight-bit
7234 clean. In cases like this, the user should clear "remote
7238 check_binary_download (CORE_ADDR addr
)
7240 struct remote_state
*rs
= get_remote_state ();
7242 switch (packet_support (PACKET_X
))
7244 case PACKET_DISABLE
:
7248 case PACKET_SUPPORT_UNKNOWN
:
7254 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7256 p
+= hexnumstr (p
, (ULONGEST
) 0);
7260 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7261 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7263 if (rs
->buf
[0] == '\0')
7266 fprintf_unfiltered (gdb_stdlog
,
7267 "binary downloading NOT "
7268 "supported by target\n");
7269 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7274 fprintf_unfiltered (gdb_stdlog
,
7275 "binary downloading supported by target\n");
7276 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7283 /* Helper function to resize the payload in order to try to get a good
7284 alignment. We try to write an amount of data such that the next write will
7285 start on an address aligned on REMOTE_ALIGN_WRITES. */
7288 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7290 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7293 /* Write memory data directly to the remote machine.
7294 This does not inform the data cache; the data cache uses this.
7295 HEADER is the starting part of the packet.
7296 MEMADDR is the address in the remote memory space.
7297 MYADDR is the address of the buffer in our space.
7298 LEN_UNITS is the number of addressable units to write.
7299 UNIT_SIZE is the length in bytes of an addressable unit.
7300 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7301 should send data as binary ('X'), or hex-encoded ('M').
7303 The function creates packet of the form
7304 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7306 where encoding of <DATA> is terminated by PACKET_FORMAT.
7308 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7311 Return the transferred status, error or OK (an
7312 'enum target_xfer_status' value). Save the number of addressable units
7313 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7315 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7316 exchange between gdb and the stub could look like (?? in place of the
7322 -> $M1000,3:eeeeffffeeee#??
7326 <- eeeeffffeeeedddd */
7328 static enum target_xfer_status
7329 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7330 const gdb_byte
*myaddr
, ULONGEST len_units
,
7331 int unit_size
, ULONGEST
*xfered_len_units
,
7332 char packet_format
, int use_length
)
7334 struct remote_state
*rs
= get_remote_state ();
7340 int payload_capacity_bytes
;
7341 int payload_length_bytes
;
7343 if (packet_format
!= 'X' && packet_format
!= 'M')
7344 internal_error (__FILE__
, __LINE__
,
7345 _("remote_write_bytes_aux: bad packet format"));
7348 return TARGET_XFER_EOF
;
7350 payload_capacity_bytes
= get_memory_write_packet_size ();
7352 /* The packet buffer will be large enough for the payload;
7353 get_memory_packet_size ensures this. */
7356 /* Compute the size of the actual payload by subtracting out the
7357 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7359 payload_capacity_bytes
-= strlen ("$,:#NN");
7361 /* The comma won't be used. */
7362 payload_capacity_bytes
+= 1;
7363 payload_capacity_bytes
-= strlen (header
);
7364 payload_capacity_bytes
-= hexnumlen (memaddr
);
7366 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7368 strcat (rs
->buf
, header
);
7369 p
= rs
->buf
+ strlen (header
);
7371 /* Compute a best guess of the number of bytes actually transfered. */
7372 if (packet_format
== 'X')
7374 /* Best guess at number of bytes that will fit. */
7375 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7377 payload_capacity_bytes
-= hexnumlen (todo_units
);
7378 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7382 /* Number of bytes that will fit. */
7383 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7385 payload_capacity_bytes
-= hexnumlen (todo_units
);
7386 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7389 if (todo_units
<= 0)
7390 internal_error (__FILE__
, __LINE__
,
7391 _("minimum packet size too small to write data"));
7393 /* If we already need another packet, then try to align the end
7394 of this packet to a useful boundary. */
7395 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7396 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7398 /* Append "<memaddr>". */
7399 memaddr
= remote_address_masked (memaddr
);
7400 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7407 /* Append the length and retain its location and size. It may need to be
7408 adjusted once the packet body has been created. */
7410 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7418 /* Append the packet body. */
7419 if (packet_format
== 'X')
7421 /* Binary mode. Send target system values byte by byte, in
7422 increasing byte addresses. Only escape certain critical
7424 payload_length_bytes
=
7425 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7426 &units_written
, payload_capacity_bytes
);
7428 /* If not all TODO units fit, then we'll need another packet. Make
7429 a second try to keep the end of the packet aligned. Don't do
7430 this if the packet is tiny. */
7431 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7435 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7437 if (new_todo_units
!= units_written
)
7438 payload_length_bytes
=
7439 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7440 (gdb_byte
*) p
, &units_written
,
7441 payload_capacity_bytes
);
7444 p
+= payload_length_bytes
;
7445 if (use_length
&& units_written
< todo_units
)
7447 /* Escape chars have filled up the buffer prematurely,
7448 and we have actually sent fewer units than planned.
7449 Fix-up the length field of the packet. Use the same
7450 number of characters as before. */
7451 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7453 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7458 /* Normal mode: Send target system values byte by byte, in
7459 increasing byte addresses. Each byte is encoded as a two hex
7461 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7462 units_written
= todo_units
;
7465 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7466 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7468 if (rs
->buf
[0] == 'E')
7469 return TARGET_XFER_E_IO
;
7471 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7472 send fewer units than we'd planned. */
7473 *xfered_len_units
= (ULONGEST
) units_written
;
7474 return TARGET_XFER_OK
;
7477 /* Write memory data directly to the remote machine.
7478 This does not inform the data cache; the data cache uses this.
7479 MEMADDR is the address in the remote memory space.
7480 MYADDR is the address of the buffer in our space.
7481 LEN is the number of bytes.
7483 Return the transferred status, error or OK (an
7484 'enum target_xfer_status' value). Save the number of bytes
7485 transferred in *XFERED_LEN. Only transfer a single packet. */
7487 static enum target_xfer_status
7488 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7489 int unit_size
, ULONGEST
*xfered_len
)
7491 char *packet_format
= 0;
7493 /* Check whether the target supports binary download. */
7494 check_binary_download (memaddr
);
7496 switch (packet_support (PACKET_X
))
7499 packet_format
= "X";
7501 case PACKET_DISABLE
:
7502 packet_format
= "M";
7504 case PACKET_SUPPORT_UNKNOWN
:
7505 internal_error (__FILE__
, __LINE__
,
7506 _("remote_write_bytes: bad internal state"));
7508 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7511 return remote_write_bytes_aux (packet_format
,
7512 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7513 packet_format
[0], 1);
7516 /* Read memory data directly from the remote machine.
7517 This does not use the data cache; the data cache uses this.
7518 MEMADDR is the address in the remote memory space.
7519 MYADDR is the address of the buffer in our space.
7520 LEN_UNITS is the number of addressable memory units to read..
7521 UNIT_SIZE is the length in bytes of an addressable unit.
7523 Return the transferred status, error or OK (an
7524 'enum target_xfer_status' value). Save the number of bytes
7525 transferred in *XFERED_LEN_UNITS.
7527 See the comment of remote_write_bytes_aux for an example of
7528 memory read/write exchange between gdb and the stub. */
7530 static enum target_xfer_status
7531 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7532 int unit_size
, ULONGEST
*xfered_len_units
)
7534 struct remote_state
*rs
= get_remote_state ();
7535 int buf_size_bytes
; /* Max size of packet output buffer. */
7540 buf_size_bytes
= get_memory_read_packet_size ();
7541 /* The packet buffer will be large enough for the payload;
7542 get_memory_packet_size ensures this. */
7544 /* Number of units that will fit. */
7545 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7547 /* Construct "m"<memaddr>","<len>". */
7548 memaddr
= remote_address_masked (memaddr
);
7551 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7553 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7556 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7557 if (rs
->buf
[0] == 'E'
7558 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7559 && rs
->buf
[3] == '\0')
7560 return TARGET_XFER_E_IO
;
7561 /* Reply describes memory byte by byte, each byte encoded as two hex
7564 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7565 /* Return what we have. Let higher layers handle partial reads. */
7566 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7567 return TARGET_XFER_OK
;
7570 /* Using the set of read-only target sections of remote, read live
7573 For interface/parameters/return description see target.h,
7576 static enum target_xfer_status
7577 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7578 ULONGEST memaddr
, ULONGEST len
,
7579 int unit_size
, ULONGEST
*xfered_len
)
7581 struct target_section
*secp
;
7582 struct target_section_table
*table
;
7584 secp
= target_section_by_addr (ops
, memaddr
);
7586 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7587 secp
->the_bfd_section
)
7590 struct target_section
*p
;
7591 ULONGEST memend
= memaddr
+ len
;
7593 table
= target_get_section_table (ops
);
7595 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7597 if (memaddr
>= p
->addr
)
7599 if (memend
<= p
->endaddr
)
7601 /* Entire transfer is within this section. */
7602 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7605 else if (memaddr
>= p
->endaddr
)
7607 /* This section ends before the transfer starts. */
7612 /* This section overlaps the transfer. Just do half. */
7613 len
= p
->endaddr
- memaddr
;
7614 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7621 return TARGET_XFER_EOF
;
7624 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7625 first if the requested memory is unavailable in traceframe.
7626 Otherwise, fall back to remote_read_bytes_1. */
7628 static enum target_xfer_status
7629 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7630 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7631 ULONGEST
*xfered_len
)
7634 return TARGET_XFER_EOF
;
7636 if (get_traceframe_number () != -1)
7638 VEC(mem_range_s
) *available
;
7640 /* If we fail to get the set of available memory, then the
7641 target does not support querying traceframe info, and so we
7642 attempt reading from the traceframe anyway (assuming the
7643 target implements the old QTro packet then). */
7644 if (traceframe_available_memory (&available
, memaddr
, len
))
7646 struct cleanup
*old_chain
;
7648 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7650 if (VEC_empty (mem_range_s
, available
)
7651 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7653 enum target_xfer_status res
;
7655 /* Don't read into the traceframe's available
7657 if (!VEC_empty (mem_range_s
, available
))
7659 LONGEST oldlen
= len
;
7661 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7662 gdb_assert (len
<= oldlen
);
7665 do_cleanups (old_chain
);
7667 /* This goes through the topmost target again. */
7668 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7669 len
, unit_size
, xfered_len
);
7670 if (res
== TARGET_XFER_OK
)
7671 return TARGET_XFER_OK
;
7674 /* No use trying further, we know some memory starting
7675 at MEMADDR isn't available. */
7677 return TARGET_XFER_UNAVAILABLE
;
7681 /* Don't try to read more than how much is available, in
7682 case the target implements the deprecated QTro packet to
7683 cater for older GDBs (the target's knowledge of read-only
7684 sections may be outdated by now). */
7685 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7687 do_cleanups (old_chain
);
7691 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7696 /* Sends a packet with content determined by the printf format string
7697 FORMAT and the remaining arguments, then gets the reply. Returns
7698 whether the packet was a success, a failure, or unknown. */
7700 static enum packet_result
remote_send_printf (const char *format
, ...)
7701 ATTRIBUTE_PRINTF (1, 2);
7703 static enum packet_result
7704 remote_send_printf (const char *format
, ...)
7706 struct remote_state
*rs
= get_remote_state ();
7707 int max_size
= get_remote_packet_size ();
7710 va_start (ap
, format
);
7713 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7714 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7716 if (putpkt (rs
->buf
) < 0)
7717 error (_("Communication problem with target."));
7720 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7722 return packet_check_result (rs
->buf
);
7726 restore_remote_timeout (void *p
)
7728 int value
= *(int *)p
;
7730 remote_timeout
= value
;
7733 /* Flash writing can take quite some time. We'll set
7734 effectively infinite timeout for flash operations.
7735 In future, we'll need to decide on a better approach. */
7736 static const int remote_flash_timeout
= 1000;
7739 remote_flash_erase (struct target_ops
*ops
,
7740 ULONGEST address
, LONGEST length
)
7742 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7743 int saved_remote_timeout
= remote_timeout
;
7744 enum packet_result ret
;
7745 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7746 &saved_remote_timeout
);
7748 remote_timeout
= remote_flash_timeout
;
7750 ret
= remote_send_printf ("vFlashErase:%s,%s",
7751 phex (address
, addr_size
),
7755 case PACKET_UNKNOWN
:
7756 error (_("Remote target does not support flash erase"));
7758 error (_("Error erasing flash with vFlashErase packet"));
7763 do_cleanups (back_to
);
7766 static enum target_xfer_status
7767 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7768 ULONGEST length
, ULONGEST
*xfered_len
,
7769 const gdb_byte
*data
)
7771 int saved_remote_timeout
= remote_timeout
;
7772 enum target_xfer_status ret
;
7773 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7774 &saved_remote_timeout
);
7776 remote_timeout
= remote_flash_timeout
;
7777 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7779 do_cleanups (back_to
);
7785 remote_flash_done (struct target_ops
*ops
)
7787 int saved_remote_timeout
= remote_timeout
;
7789 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7790 &saved_remote_timeout
);
7792 remote_timeout
= remote_flash_timeout
;
7793 ret
= remote_send_printf ("vFlashDone");
7794 do_cleanups (back_to
);
7798 case PACKET_UNKNOWN
:
7799 error (_("Remote target does not support vFlashDone"));
7801 error (_("Error finishing flash operation"));
7808 remote_files_info (struct target_ops
*ignore
)
7810 puts_filtered ("Debugging a target over a serial line.\n");
7813 /* Stuff for dealing with the packets which are part of this protocol.
7814 See comment at top of file for details. */
7816 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7817 error to higher layers. Called when a serial error is detected.
7818 The exception message is STRING, followed by a colon and a blank,
7819 the system error message for errno at function entry and final dot
7820 for output compatibility with throw_perror_with_name. */
7823 unpush_and_perror (const char *string
)
7825 int saved_errno
= errno
;
7827 remote_unpush_target ();
7828 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7829 safe_strerror (saved_errno
));
7832 /* Read a single character from the remote end. */
7835 readchar (int timeout
)
7838 struct remote_state
*rs
= get_remote_state ();
7840 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7845 switch ((enum serial_rc
) ch
)
7848 remote_unpush_target ();
7849 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7852 unpush_and_perror (_("Remote communication error. "
7853 "Target disconnected."));
7855 case SERIAL_TIMEOUT
:
7861 /* Wrapper for serial_write that closes the target and throws if
7865 remote_serial_write (const char *str
, int len
)
7867 struct remote_state
*rs
= get_remote_state ();
7869 if (serial_write (rs
->remote_desc
, str
, len
))
7871 unpush_and_perror (_("Remote communication error. "
7872 "Target disconnected."));
7876 /* Send the command in *BUF to the remote machine, and read the reply
7877 into *BUF. Report an error if we get an error reply. Resize
7878 *BUF using xrealloc if necessary to hold the result, and update
7882 remote_send (char **buf
,
7886 getpkt (buf
, sizeof_buf
, 0);
7888 if ((*buf
)[0] == 'E')
7889 error (_("Remote failure reply: %s"), *buf
);
7892 /* Return a pointer to an xmalloc'ed string representing an escaped
7893 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7894 etc. The caller is responsible for releasing the returned
7898 escape_buffer (const char *buf
, int n
)
7900 struct cleanup
*old_chain
;
7901 struct ui_file
*stb
;
7904 stb
= mem_fileopen ();
7905 old_chain
= make_cleanup_ui_file_delete (stb
);
7907 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7908 str
= ui_file_xstrdup (stb
, NULL
);
7909 do_cleanups (old_chain
);
7913 /* Display a null-terminated packet on stdout, for debugging, using C
7917 print_packet (const char *buf
)
7919 puts_filtered ("\"");
7920 fputstr_filtered (buf
, '"', gdb_stdout
);
7921 puts_filtered ("\"");
7925 putpkt (const char *buf
)
7927 return putpkt_binary (buf
, strlen (buf
));
7930 /* Send a packet to the remote machine, with error checking. The data
7931 of the packet is in BUF. The string in BUF can be at most
7932 get_remote_packet_size () - 5 to account for the $, # and checksum,
7933 and for a possible /0 if we are debugging (remote_debug) and want
7934 to print the sent packet as a string. */
7937 putpkt_binary (const char *buf
, int cnt
)
7939 struct remote_state
*rs
= get_remote_state ();
7941 unsigned char csum
= 0;
7942 char *buf2
= xmalloc (cnt
+ 6);
7943 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
7950 /* Catch cases like trying to read memory or listing threads while
7951 we're waiting for a stop reply. The remote server wouldn't be
7952 ready to handle this request, so we'd hang and timeout. We don't
7953 have to worry about this in synchronous mode, because in that
7954 case it's not possible to issue a command while the target is
7955 running. This is not a problem in non-stop mode, because in that
7956 case, the stub is always ready to process serial input. */
7957 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7959 error (_("Cannot execute this command while the target is running.\n"
7960 "Use the \"interrupt\" command to stop the target\n"
7961 "and then try again."));
7964 /* We're sending out a new packet. Make sure we don't look at a
7965 stale cached response. */
7966 rs
->cached_wait_status
= 0;
7968 /* Copy the packet into buffer BUF2, encapsulating it
7969 and giving it a checksum. */
7974 for (i
= 0; i
< cnt
; i
++)
7980 *p
++ = tohex ((csum
>> 4) & 0xf);
7981 *p
++ = tohex (csum
& 0xf);
7983 /* Send it over and over until we get a positive ack. */
7987 int started_error_output
= 0;
7991 struct cleanup
*old_chain
;
7995 str
= escape_buffer (buf2
, p
- buf2
);
7996 old_chain
= make_cleanup (xfree
, str
);
7997 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7998 gdb_flush (gdb_stdlog
);
7999 do_cleanups (old_chain
);
8001 remote_serial_write (buf2
, p
- buf2
);
8003 /* If this is a no acks version of the remote protocol, send the
8004 packet and move on. */
8008 /* Read until either a timeout occurs (-2) or '+' is read.
8009 Handle any notification that arrives in the mean time. */
8012 ch
= readchar (remote_timeout
);
8020 case SERIAL_TIMEOUT
:
8023 if (started_error_output
)
8025 putchar_unfiltered ('\n');
8026 started_error_output
= 0;
8035 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8036 do_cleanups (old_chain
);
8040 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8042 case SERIAL_TIMEOUT
:
8046 do_cleanups (old_chain
);
8049 break; /* Retransmit buffer. */
8053 fprintf_unfiltered (gdb_stdlog
,
8054 "Packet instead of Ack, ignoring it\n");
8055 /* It's probably an old response sent because an ACK
8056 was lost. Gobble up the packet and ack it so it
8057 doesn't get retransmitted when we resend this
8060 remote_serial_write ("+", 1);
8061 continue; /* Now, go look for +. */
8068 /* If we got a notification, handle it, and go back to looking
8070 /* We've found the start of a notification. Now
8071 collect the data. */
8072 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8077 struct cleanup
*old_chain
;
8080 str
= escape_buffer (rs
->buf
, val
);
8081 old_chain
= make_cleanup (xfree
, str
);
8082 fprintf_unfiltered (gdb_stdlog
,
8083 " Notification received: %s\n",
8085 do_cleanups (old_chain
);
8087 handle_notification (rs
->notif_state
, rs
->buf
);
8088 /* We're in sync now, rewait for the ack. */
8095 if (!started_error_output
)
8097 started_error_output
= 1;
8098 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8100 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8101 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8110 if (!started_error_output
)
8112 started_error_output
= 1;
8113 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8115 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8119 break; /* Here to retransmit. */
8123 /* This is wrong. If doing a long backtrace, the user should be
8124 able to get out next time we call QUIT, without anything as
8125 violent as interrupt_query. If we want to provide a way out of
8126 here without getting to the next QUIT, it should be based on
8127 hitting ^C twice as in remote_wait. */
8136 do_cleanups (old_chain
);
8140 /* Come here after finding the start of a frame when we expected an
8141 ack. Do our best to discard the rest of this packet. */
8150 c
= readchar (remote_timeout
);
8153 case SERIAL_TIMEOUT
:
8154 /* Nothing we can do. */
8157 /* Discard the two bytes of checksum and stop. */
8158 c
= readchar (remote_timeout
);
8160 c
= readchar (remote_timeout
);
8163 case '*': /* Run length encoding. */
8164 /* Discard the repeat count. */
8165 c
= readchar (remote_timeout
);
8170 /* A regular character. */
8176 /* Come here after finding the start of the frame. Collect the rest
8177 into *BUF, verifying the checksum, length, and handling run-length
8178 compression. NUL terminate the buffer. If there is not enough room,
8179 expand *BUF using xrealloc.
8181 Returns -1 on error, number of characters in buffer (ignoring the
8182 trailing NULL) on success. (could be extended to return one of the
8183 SERIAL status indications). */
8186 read_frame (char **buf_p
,
8193 struct remote_state
*rs
= get_remote_state ();
8200 c
= readchar (remote_timeout
);
8203 case SERIAL_TIMEOUT
:
8205 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8209 fputs_filtered ("Saw new packet start in middle of old one\n",
8211 return -1; /* Start a new packet, count retries. */
8214 unsigned char pktcsum
;
8220 check_0
= readchar (remote_timeout
);
8222 check_1
= readchar (remote_timeout
);
8224 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8227 fputs_filtered ("Timeout in checksum, retrying\n",
8231 else if (check_0
< 0 || check_1
< 0)
8234 fputs_filtered ("Communication error in checksum\n",
8239 /* Don't recompute the checksum; with no ack packets we
8240 don't have any way to indicate a packet retransmission
8245 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8246 if (csum
== pktcsum
)
8251 struct cleanup
*old_chain
;
8254 str
= escape_buffer (buf
, bc
);
8255 old_chain
= make_cleanup (xfree
, str
);
8256 fprintf_unfiltered (gdb_stdlog
,
8257 "Bad checksum, sentsum=0x%x, "
8258 "csum=0x%x, buf=%s\n",
8259 pktcsum
, csum
, str
);
8260 do_cleanups (old_chain
);
8262 /* Number of characters in buffer ignoring trailing
8266 case '*': /* Run length encoding. */
8271 c
= readchar (remote_timeout
);
8273 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8275 /* The character before ``*'' is repeated. */
8277 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8279 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8281 /* Make some more room in the buffer. */
8282 *sizeof_buf
+= repeat
;
8283 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
8287 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8293 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8297 if (bc
>= *sizeof_buf
- 1)
8299 /* Make some more room in the buffer. */
8301 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
8312 /* Read a packet from the remote machine, with error checking, and
8313 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8314 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8315 rather than timing out; this is used (in synchronous mode) to wait
8316 for a target that is is executing user code to stop. */
8317 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8318 don't have to change all the calls to getpkt to deal with the
8319 return value, because at the moment I don't know what the right
8320 thing to do it for those. */
8328 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
8332 /* Read a packet from the remote machine, with error checking, and
8333 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8334 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8335 rather than timing out; this is used (in synchronous mode) to wait
8336 for a target that is is executing user code to stop. If FOREVER ==
8337 0, this function is allowed to time out gracefully and return an
8338 indication of this to the caller. Otherwise return the number of
8339 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8340 enough reason to return to the caller. *IS_NOTIF is an output
8341 boolean that indicates whether *BUF holds a notification or not
8342 (a regular packet). */
8345 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8346 int expecting_notif
, int *is_notif
)
8348 struct remote_state
*rs
= get_remote_state ();
8354 /* We're reading a new response. Make sure we don't look at a
8355 previously cached response. */
8356 rs
->cached_wait_status
= 0;
8358 strcpy (*buf
, "timeout");
8361 timeout
= watchdog
> 0 ? watchdog
: -1;
8362 else if (expecting_notif
)
8363 timeout
= 0; /* There should already be a char in the buffer. If
8366 timeout
= remote_timeout
;
8370 /* Process any number of notifications, and then return when
8374 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8376 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8378 /* This can loop forever if the remote side sends us
8379 characters continuously, but if it pauses, we'll get
8380 SERIAL_TIMEOUT from readchar because of timeout. Then
8381 we'll count that as a retry.
8383 Note that even when forever is set, we will only wait
8384 forever prior to the start of a packet. After that, we
8385 expect characters to arrive at a brisk pace. They should
8386 show up within remote_timeout intervals. */
8388 c
= readchar (timeout
);
8389 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8391 if (c
== SERIAL_TIMEOUT
)
8393 if (expecting_notif
)
8394 return -1; /* Don't complain, it's normal to not get
8395 anything in this case. */
8397 if (forever
) /* Watchdog went off? Kill the target. */
8400 remote_unpush_target ();
8401 throw_error (TARGET_CLOSE_ERROR
,
8402 _("Watchdog timeout has expired. "
8403 "Target detached."));
8406 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8410 /* We've found the start of a packet or notification.
8411 Now collect the data. */
8412 val
= read_frame (buf
, sizeof_buf
);
8417 remote_serial_write ("-", 1);
8420 if (tries
> MAX_TRIES
)
8422 /* We have tried hard enough, and just can't receive the
8423 packet/notification. Give up. */
8424 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8426 /* Skip the ack char if we're in no-ack mode. */
8427 if (!rs
->noack_mode
)
8428 remote_serial_write ("+", 1);
8432 /* If we got an ordinary packet, return that to our caller. */
8437 struct cleanup
*old_chain
;
8440 str
= escape_buffer (*buf
, val
);
8441 old_chain
= make_cleanup (xfree
, str
);
8442 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8443 do_cleanups (old_chain
);
8446 /* Skip the ack char if we're in no-ack mode. */
8447 if (!rs
->noack_mode
)
8448 remote_serial_write ("+", 1);
8449 if (is_notif
!= NULL
)
8454 /* If we got a notification, handle it, and go back to looking
8458 gdb_assert (c
== '%');
8462 struct cleanup
*old_chain
;
8465 str
= escape_buffer (*buf
, val
);
8466 old_chain
= make_cleanup (xfree
, str
);
8467 fprintf_unfiltered (gdb_stdlog
,
8468 " Notification received: %s\n",
8470 do_cleanups (old_chain
);
8472 if (is_notif
!= NULL
)
8475 handle_notification (rs
->notif_state
, *buf
);
8477 /* Notifications require no acknowledgement. */
8479 if (expecting_notif
)
8486 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8488 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8492 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8495 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8499 /* Check whether EVENT is a fork event for the process specified
8500 by the pid passed in DATA, and if it is, kill the fork child. */
8503 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8504 QUEUE_ITER (stop_reply_p
) *iter
,
8508 struct queue_iter_param
*param
= data
;
8509 int parent_pid
= *(int *) param
->input
;
8511 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8513 struct remote_state
*rs
= get_remote_state ();
8514 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8517 res
= remote_vkill (child_pid
, rs
);
8519 error (_("Can't kill fork child process %d"), child_pid
);
8525 /* Kill any new fork children of process PID that haven't been
8526 processed by follow_fork. */
8529 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8531 struct thread_info
*thread
;
8532 struct notif_client
*notif
= ¬if_client_stop
;
8533 struct queue_iter_param param
;
8535 /* Kill the fork child threads of any threads in process PID
8536 that are stopped at a fork event. */
8537 ALL_NON_EXITED_THREADS (thread
)
8539 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8541 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8543 struct remote_state
*rs
= get_remote_state ();
8544 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8547 res
= remote_vkill (child_pid
, rs
);
8549 error (_("Can't kill fork child process %d"), child_pid
);
8553 /* Check for any pending fork events (not reported or processed yet)
8554 in process PID and kill those fork child threads as well. */
8555 remote_notif_get_pending_events (notif
);
8557 param
.output
= NULL
;
8558 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8559 kill_child_of_pending_fork
, ¶m
);
8564 remote_kill (struct target_ops
*ops
)
8567 /* Catch errors so the user can quit from gdb even when we
8568 aren't on speaking terms with the remote system. */
8573 CATCH (ex
, RETURN_MASK_ERROR
)
8575 if (ex
.error
== TARGET_CLOSE_ERROR
)
8577 /* If we got an (EOF) error that caused the target
8578 to go away, then we're done, that's what we wanted.
8579 "k" is susceptible to cause a premature EOF, given
8580 that the remote server isn't actually required to
8581 reply to "k", and it can happen that it doesn't
8582 even get to reply ACK to the "k". */
8586 /* Otherwise, something went wrong. We didn't actually kill
8587 the target. Just propagate the exception, and let the
8588 user or higher layers decide what to do. */
8589 throw_exception (ex
);
8593 /* We've killed the remote end, we get to mourn it. Since this is
8594 target remote, single-process, mourning the inferior also
8595 unpushes remote_ops. */
8596 target_mourn_inferior ();
8600 remote_vkill (int pid
, struct remote_state
*rs
)
8602 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8605 /* Tell the remote target to detach. */
8606 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8608 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8610 switch (packet_ok (rs
->buf
,
8611 &remote_protocol_packets
[PACKET_vKill
]))
8617 case PACKET_UNKNOWN
:
8620 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8625 extended_remote_kill (struct target_ops
*ops
)
8628 int pid
= ptid_get_pid (inferior_ptid
);
8629 struct remote_state
*rs
= get_remote_state ();
8631 /* If we're stopped while forking and we haven't followed yet, kill the
8632 child task. We need to do this before killing the parent task
8633 because if this is a vfork then the parent will be sleeping. */
8634 kill_new_fork_children (pid
, rs
);
8636 res
= remote_vkill (pid
, rs
);
8637 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8639 /* Don't try 'k' on a multi-process aware stub -- it has no way
8640 to specify the pid. */
8644 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8645 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8648 /* Don't wait for it to die. I'm not really sure it matters whether
8649 we do or not. For the existing stubs, kill is a noop. */
8655 error (_("Can't kill process"));
8657 target_mourn_inferior ();
8661 remote_mourn (struct target_ops
*target
)
8663 unpush_target (target
);
8665 /* remote_close takes care of doing most of the clean up. */
8666 generic_mourn_inferior ();
8670 extended_remote_mourn (struct target_ops
*target
)
8672 struct remote_state
*rs
= get_remote_state ();
8674 /* In case we got here due to an error, but we're going to stay
8676 rs
->waiting_for_stop_reply
= 0;
8678 /* If the current general thread belonged to the process we just
8679 detached from or has exited, the remote side current general
8680 thread becomes undefined. Considering a case like this:
8682 - We just got here due to a detach.
8683 - The process that we're detaching from happens to immediately
8684 report a global breakpoint being hit in non-stop mode, in the
8685 same thread we had selected before.
8686 - GDB attaches to this process again.
8687 - This event happens to be the next event we handle.
8689 GDB would consider that the current general thread didn't need to
8690 be set on the stub side (with Hg), since for all it knew,
8691 GENERAL_THREAD hadn't changed.
8693 Notice that although in all-stop mode, the remote server always
8694 sets the current thread to the thread reporting the stop event,
8695 that doesn't happen in non-stop mode; in non-stop, the stub *must
8696 not* change the current thread when reporting a breakpoint hit,
8697 due to the decoupling of event reporting and event handling.
8699 To keep things simple, we always invalidate our notion of the
8701 record_currthread (rs
, minus_one_ptid
);
8703 /* Unlike "target remote", we do not want to unpush the target; then
8704 the next time the user says "run", we won't be connected. */
8706 /* Call common code to mark the inferior as not running. */
8707 generic_mourn_inferior ();
8709 if (!have_inferiors ())
8711 if (!remote_multi_process_p (rs
))
8713 /* Check whether the target is running now - some remote stubs
8714 automatically restart after kill. */
8716 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8718 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8720 /* Assume that the target has been restarted. Set
8721 inferior_ptid so that bits of core GDB realizes
8722 there's something here, e.g., so that the user can
8723 say "kill" again. */
8724 inferior_ptid
= magic_null_ptid
;
8731 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8733 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8737 extended_remote_disable_randomization (int val
)
8739 struct remote_state
*rs
= get_remote_state ();
8742 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8745 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8747 error (_("Target does not support QDisableRandomization."));
8748 if (strcmp (reply
, "OK") != 0)
8749 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8753 extended_remote_run (char *args
)
8755 struct remote_state
*rs
= get_remote_state ();
8757 const char *remote_exec_file
= get_remote_exec_file ();
8759 /* If the user has disabled vRun support, or we have detected that
8760 support is not available, do not try it. */
8761 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8764 strcpy (rs
->buf
, "vRun;");
8765 len
= strlen (rs
->buf
);
8767 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8768 error (_("Remote file name too long for run packet"));
8769 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8770 strlen (remote_exec_file
));
8772 gdb_assert (args
!= NULL
);
8775 struct cleanup
*back_to
;
8779 argv
= gdb_buildargv (args
);
8780 back_to
= make_cleanup_freeargv (argv
);
8781 for (i
= 0; argv
[i
] != NULL
; i
++)
8783 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8784 error (_("Argument list too long for run packet"));
8785 rs
->buf
[len
++] = ';';
8786 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8789 do_cleanups (back_to
);
8792 rs
->buf
[len
++] = '\0';
8795 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8797 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8800 /* We have a wait response. All is well. */
8802 case PACKET_UNKNOWN
:
8805 if (remote_exec_file
[0] == '\0')
8806 error (_("Running the default executable on the remote target failed; "
8807 "try \"set remote exec-file\"?"));
8809 error (_("Running \"%s\" on the remote target failed"),
8812 gdb_assert_not_reached (_("bad switch"));
8816 /* In the extended protocol we want to be able to do things like
8817 "run" and have them basically work as expected. So we need
8818 a special create_inferior function. We support changing the
8819 executable file and the command line arguments, but not the
8823 extended_remote_create_inferior (struct target_ops
*ops
,
8824 char *exec_file
, char *args
,
8825 char **env
, int from_tty
)
8829 struct remote_state
*rs
= get_remote_state ();
8830 const char *remote_exec_file
= get_remote_exec_file ();
8832 /* If running asynchronously, register the target file descriptor
8833 with the event loop. */
8834 if (target_can_async_p ())
8837 /* Disable address space randomization if requested (and supported). */
8838 if (extended_remote_supports_disable_randomization (ops
))
8839 extended_remote_disable_randomization (disable_randomization
);
8841 /* Now restart the remote server. */
8842 run_worked
= extended_remote_run (args
) != -1;
8845 /* vRun was not supported. Fail if we need it to do what the
8847 if (remote_exec_file
[0])
8848 error (_("Remote target does not support \"set remote exec-file\""));
8850 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8852 /* Fall back to "R". */
8853 extended_remote_restart ();
8856 if (!have_inferiors ())
8858 /* Clean up from the last time we ran, before we mark the target
8859 running again. This will mark breakpoints uninserted, and
8860 get_offsets may insert breakpoints. */
8861 init_thread_list ();
8862 init_wait_for_inferior ();
8865 /* vRun's success return is a stop reply. */
8866 stop_reply
= run_worked
? rs
->buf
: NULL
;
8867 add_current_inferior_and_thread (stop_reply
);
8869 /* Get updated offsets, if the stub uses qOffsets. */
8874 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8875 the list of conditions (in agent expression bytecode format), if any, the
8876 target needs to evaluate. The output is placed into the packet buffer
8877 started from BUF and ended at BUF_END. */
8880 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8881 struct bp_target_info
*bp_tgt
, char *buf
,
8884 struct agent_expr
*aexpr
= NULL
;
8887 char *buf_start
= buf
;
8889 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8892 buf
+= strlen (buf
);
8893 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8896 /* Send conditions to the target and free the vector. */
8898 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8901 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8902 buf
+= strlen (buf
);
8903 for (i
= 0; i
< aexpr
->len
; ++i
)
8904 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8911 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8912 struct bp_target_info
*bp_tgt
, char *buf
)
8914 struct agent_expr
*aexpr
= NULL
;
8917 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8920 buf
+= strlen (buf
);
8922 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8923 buf
+= strlen (buf
);
8925 /* Concatenate all the agent expressions that are commands into the
8928 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8931 sprintf (buf
, "X%x,", aexpr
->len
);
8932 buf
+= strlen (buf
);
8933 for (i
= 0; i
< aexpr
->len
; ++i
)
8934 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8939 /* Insert a breakpoint. On targets that have software breakpoint
8940 support, we ask the remote target to do the work; on targets
8941 which don't, we insert a traditional memory breakpoint. */
8944 remote_insert_breakpoint (struct target_ops
*ops
,
8945 struct gdbarch
*gdbarch
,
8946 struct bp_target_info
*bp_tgt
)
8948 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8949 If it succeeds, then set the support to PACKET_ENABLE. If it
8950 fails, and the user has explicitly requested the Z support then
8951 report an error, otherwise, mark it disabled and go on. */
8953 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8955 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8956 struct remote_state
*rs
;
8959 struct condition_list
*cond
= NULL
;
8961 /* Make sure the remote is pointing at the right process, if
8963 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8964 set_general_process ();
8966 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8968 rs
= get_remote_state ();
8970 endbuf
= rs
->buf
+ get_remote_packet_size ();
8975 addr
= (ULONGEST
) remote_address_masked (addr
);
8976 p
+= hexnumstr (p
, addr
);
8977 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8979 if (remote_supports_cond_breakpoints (ops
))
8980 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8982 if (remote_can_run_breakpoint_commands (ops
))
8983 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8986 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8988 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8993 bp_tgt
->placed_address
= addr
;
8994 bp_tgt
->placed_size
= bpsize
;
8996 case PACKET_UNKNOWN
:
9001 /* If this breakpoint has target-side commands but this stub doesn't
9002 support Z0 packets, throw error. */
9003 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9004 throw_error (NOT_SUPPORTED_ERROR
, _("\
9005 Target doesn't support breakpoints that have target side commands."));
9007 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9011 remote_remove_breakpoint (struct target_ops
*ops
,
9012 struct gdbarch
*gdbarch
,
9013 struct bp_target_info
*bp_tgt
)
9015 CORE_ADDR addr
= bp_tgt
->placed_address
;
9016 struct remote_state
*rs
= get_remote_state ();
9018 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9021 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9023 /* Make sure the remote is pointing at the right process, if
9025 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9026 set_general_process ();
9032 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9033 p
+= hexnumstr (p
, addr
);
9034 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9039 return (rs
->buf
[0] == 'E');
9042 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
9045 static enum Z_packet_type
9046 watchpoint_to_Z_packet (int type
)
9051 return Z_PACKET_WRITE_WP
;
9054 return Z_PACKET_READ_WP
;
9057 return Z_PACKET_ACCESS_WP
;
9060 internal_error (__FILE__
, __LINE__
,
9061 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9066 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9067 enum target_hw_bp_type type
, struct expression
*cond
)
9069 struct remote_state
*rs
= get_remote_state ();
9070 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9072 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9074 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9077 /* Make sure the remote is pointing at the right process, if
9079 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9080 set_general_process ();
9082 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9083 p
= strchr (rs
->buf
, '\0');
9084 addr
= remote_address_masked (addr
);
9085 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9086 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9089 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9091 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9095 case PACKET_UNKNOWN
:
9100 internal_error (__FILE__
, __LINE__
,
9101 _("remote_insert_watchpoint: reached end of function"));
9105 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9106 CORE_ADDR start
, int length
)
9108 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9110 return diff
< length
;
9115 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9116 enum target_hw_bp_type type
, struct expression
*cond
)
9118 struct remote_state
*rs
= get_remote_state ();
9119 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9121 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9123 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9126 /* Make sure the remote is pointing at the right process, if
9128 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9129 set_general_process ();
9131 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9132 p
= strchr (rs
->buf
, '\0');
9133 addr
= remote_address_masked (addr
);
9134 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9135 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9137 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9139 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9142 case PACKET_UNKNOWN
:
9147 internal_error (__FILE__
, __LINE__
,
9148 _("remote_remove_watchpoint: reached end of function"));
9152 int remote_hw_watchpoint_limit
= -1;
9153 int remote_hw_watchpoint_length_limit
= -1;
9154 int remote_hw_breakpoint_limit
= -1;
9157 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9158 CORE_ADDR addr
, int len
)
9160 if (remote_hw_watchpoint_length_limit
== 0)
9162 else if (remote_hw_watchpoint_length_limit
< 0)
9164 else if (len
<= remote_hw_watchpoint_length_limit
)
9171 remote_check_watch_resources (struct target_ops
*self
,
9172 enum bptype type
, int cnt
, int ot
)
9174 if (type
== bp_hardware_breakpoint
)
9176 if (remote_hw_breakpoint_limit
== 0)
9178 else if (remote_hw_breakpoint_limit
< 0)
9180 else if (cnt
<= remote_hw_breakpoint_limit
)
9185 if (remote_hw_watchpoint_limit
== 0)
9187 else if (remote_hw_watchpoint_limit
< 0)
9191 else if (cnt
<= remote_hw_watchpoint_limit
)
9197 /* The to_stopped_by_sw_breakpoint method of target remote. */
9200 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9202 struct remote_state
*rs
= get_remote_state ();
9204 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
9207 /* The to_supports_stopped_by_sw_breakpoint method of target
9211 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9213 struct remote_state
*rs
= get_remote_state ();
9215 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9218 /* The to_stopped_by_hw_breakpoint method of target remote. */
9221 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9223 struct remote_state
*rs
= get_remote_state ();
9225 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
9228 /* The to_supports_stopped_by_hw_breakpoint method of target
9232 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9234 struct remote_state
*rs
= get_remote_state ();
9236 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9240 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9242 struct remote_state
*rs
= get_remote_state ();
9244 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
9248 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9250 struct remote_state
*rs
= get_remote_state ();
9253 if (remote_stopped_by_watchpoint (target
))
9255 *addr_p
= rs
->remote_watch_data_address
;
9264 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9265 struct bp_target_info
*bp_tgt
)
9267 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9268 struct remote_state
*rs
;
9273 /* The length field should be set to the size of a breakpoint
9274 instruction, even though we aren't inserting one ourselves. */
9276 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9278 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9281 /* Make sure the remote is pointing at the right process, if
9283 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9284 set_general_process ();
9286 rs
= get_remote_state ();
9288 endbuf
= rs
->buf
+ get_remote_packet_size ();
9294 addr
= remote_address_masked (addr
);
9295 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9296 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9298 if (remote_supports_cond_breakpoints (self
))
9299 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9301 if (remote_can_run_breakpoint_commands (self
))
9302 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9307 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9310 if (rs
->buf
[1] == '.')
9312 message
= strchr (rs
->buf
+ 2, '.');
9314 error (_("Remote failure reply: %s"), message
+ 1);
9317 case PACKET_UNKNOWN
:
9320 bp_tgt
->placed_address
= addr
;
9321 bp_tgt
->placed_size
= bpsize
;
9324 internal_error (__FILE__
, __LINE__
,
9325 _("remote_insert_hw_breakpoint: reached end of function"));
9330 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9331 struct bp_target_info
*bp_tgt
)
9334 struct remote_state
*rs
= get_remote_state ();
9336 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9338 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9341 /* Make sure the remote is pointing at the right process, if
9343 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9344 set_general_process ();
9350 addr
= remote_address_masked (bp_tgt
->placed_address
);
9351 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9352 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9355 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9357 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9360 case PACKET_UNKNOWN
:
9365 internal_error (__FILE__
, __LINE__
,
9366 _("remote_remove_hw_breakpoint: reached end of function"));
9369 /* Verify memory using the "qCRC:" request. */
9372 remote_verify_memory (struct target_ops
*ops
,
9373 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9375 struct remote_state
*rs
= get_remote_state ();
9376 unsigned long host_crc
, target_crc
;
9379 /* It doesn't make sense to use qCRC if the remote target is
9380 connected but not running. */
9381 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9383 enum packet_result result
;
9385 /* Make sure the remote is pointing at the right process. */
9386 set_general_process ();
9388 /* FIXME: assumes lma can fit into long. */
9389 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9390 (long) lma
, (long) size
);
9393 /* Be clever; compute the host_crc before waiting for target
9395 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9397 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9399 result
= packet_ok (rs
->buf
,
9400 &remote_protocol_packets
[PACKET_qCRC
]);
9401 if (result
== PACKET_ERROR
)
9403 else if (result
== PACKET_OK
)
9405 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9406 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9408 return (host_crc
== target_crc
);
9412 return simple_verify_memory (ops
, data
, lma
, size
);
9415 /* compare-sections command
9417 With no arguments, compares each loadable section in the exec bfd
9418 with the same memory range on the target, and reports mismatches.
9419 Useful for verifying the image on the target against the exec file. */
9422 compare_sections_command (char *args
, int from_tty
)
9425 struct cleanup
*old_chain
;
9427 const char *sectname
;
9436 error (_("command cannot be used without an exec file"));
9438 /* Make sure the remote is pointing at the right process. */
9439 set_general_process ();
9441 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9447 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9449 if (!(s
->flags
& SEC_LOAD
))
9450 continue; /* Skip non-loadable section. */
9452 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9453 continue; /* Skip writeable sections */
9455 size
= bfd_get_section_size (s
);
9457 continue; /* Skip zero-length section. */
9459 sectname
= bfd_get_section_name (exec_bfd
, s
);
9460 if (args
&& strcmp (args
, sectname
) != 0)
9461 continue; /* Not the section selected by user. */
9463 matched
= 1; /* Do this section. */
9466 sectdata
= xmalloc (size
);
9467 old_chain
= make_cleanup (xfree
, sectdata
);
9468 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9470 res
= target_verify_memory (sectdata
, lma
, size
);
9473 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9474 paddress (target_gdbarch (), lma
),
9475 paddress (target_gdbarch (), lma
+ size
));
9477 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9478 paddress (target_gdbarch (), lma
),
9479 paddress (target_gdbarch (), lma
+ size
));
9481 printf_filtered ("matched.\n");
9484 printf_filtered ("MIS-MATCHED!\n");
9488 do_cleanups (old_chain
);
9491 warning (_("One or more sections of the target image does not match\n\
9492 the loaded file\n"));
9493 if (args
&& !matched
)
9494 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9497 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9498 into remote target. The number of bytes written to the remote
9499 target is returned, or -1 for error. */
9501 static enum target_xfer_status
9502 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9503 const char *annex
, const gdb_byte
*writebuf
,
9504 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9505 struct packet_config
*packet
)
9509 struct remote_state
*rs
= get_remote_state ();
9510 int max_size
= get_memory_write_packet_size ();
9512 if (packet
->support
== PACKET_DISABLE
)
9513 return TARGET_XFER_E_IO
;
9515 /* Insert header. */
9516 i
= snprintf (rs
->buf
, max_size
,
9517 "qXfer:%s:write:%s:%s:",
9518 object_name
, annex
? annex
: "",
9519 phex_nz (offset
, sizeof offset
));
9520 max_size
-= (i
+ 1);
9522 /* Escape as much data as fits into rs->buf. */
9523 buf_len
= remote_escape_output
9524 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9526 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9527 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9528 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9529 return TARGET_XFER_E_IO
;
9531 unpack_varlen_hex (rs
->buf
, &n
);
9534 return TARGET_XFER_OK
;
9537 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9538 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9539 number of bytes read is returned, or 0 for EOF, or -1 for error.
9540 The number of bytes read may be less than LEN without indicating an
9541 EOF. PACKET is checked and updated to indicate whether the remote
9542 target supports this object. */
9544 static enum target_xfer_status
9545 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9547 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9548 ULONGEST
*xfered_len
,
9549 struct packet_config
*packet
)
9551 struct remote_state
*rs
= get_remote_state ();
9552 LONGEST i
, n
, packet_len
;
9554 if (packet
->support
== PACKET_DISABLE
)
9555 return TARGET_XFER_E_IO
;
9557 /* Check whether we've cached an end-of-object packet that matches
9559 if (rs
->finished_object
)
9561 if (strcmp (object_name
, rs
->finished_object
) == 0
9562 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9563 && offset
== rs
->finished_offset
)
9564 return TARGET_XFER_EOF
;
9567 /* Otherwise, we're now reading something different. Discard
9569 xfree (rs
->finished_object
);
9570 xfree (rs
->finished_annex
);
9571 rs
->finished_object
= NULL
;
9572 rs
->finished_annex
= NULL
;
9575 /* Request only enough to fit in a single packet. The actual data
9576 may not, since we don't know how much of it will need to be escaped;
9577 the target is free to respond with slightly less data. We subtract
9578 five to account for the response type and the protocol frame. */
9579 n
= min (get_remote_packet_size () - 5, len
);
9580 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9581 object_name
, annex
? annex
: "",
9582 phex_nz (offset
, sizeof offset
),
9583 phex_nz (n
, sizeof n
));
9584 i
= putpkt (rs
->buf
);
9586 return TARGET_XFER_E_IO
;
9589 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9590 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9591 return TARGET_XFER_E_IO
;
9593 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9594 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9596 /* 'm' means there is (or at least might be) more data after this
9597 batch. That does not make sense unless there's at least one byte
9598 of data in this reply. */
9599 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9600 error (_("Remote qXfer reply contained no data."));
9602 /* Got some data. */
9603 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9604 packet_len
- 1, readbuf
, n
);
9606 /* 'l' is an EOF marker, possibly including a final block of data,
9607 or possibly empty. If we have the final block of a non-empty
9608 object, record this fact to bypass a subsequent partial read. */
9609 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9611 rs
->finished_object
= xstrdup (object_name
);
9612 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9613 rs
->finished_offset
= offset
+ i
;
9617 return TARGET_XFER_EOF
;
9621 return TARGET_XFER_OK
;
9625 static enum target_xfer_status
9626 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9627 const char *annex
, gdb_byte
*readbuf
,
9628 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9629 ULONGEST
*xfered_len
)
9631 struct remote_state
*rs
;
9635 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9637 set_remote_traceframe ();
9638 set_general_thread (inferior_ptid
);
9640 rs
= get_remote_state ();
9642 /* Handle memory using the standard memory routines. */
9643 if (object
== TARGET_OBJECT_MEMORY
)
9645 /* If the remote target is connected but not running, we should
9646 pass this request down to a lower stratum (e.g. the executable
9648 if (!target_has_execution
)
9649 return TARGET_XFER_EOF
;
9651 if (writebuf
!= NULL
)
9652 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9655 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9659 /* Handle SPU memory using qxfer packets. */
9660 if (object
== TARGET_OBJECT_SPU
)
9663 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9664 xfered_len
, &remote_protocol_packets
9665 [PACKET_qXfer_spu_read
]);
9667 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9668 xfered_len
, &remote_protocol_packets
9669 [PACKET_qXfer_spu_write
]);
9672 /* Handle extra signal info using qxfer packets. */
9673 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9676 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9677 xfered_len
, &remote_protocol_packets
9678 [PACKET_qXfer_siginfo_read
]);
9680 return remote_write_qxfer (ops
, "siginfo", annex
,
9681 writebuf
, offset
, len
, xfered_len
,
9682 &remote_protocol_packets
9683 [PACKET_qXfer_siginfo_write
]);
9686 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9689 return remote_read_qxfer (ops
, "statictrace", annex
,
9690 readbuf
, offset
, len
, xfered_len
,
9691 &remote_protocol_packets
9692 [PACKET_qXfer_statictrace_read
]);
9694 return TARGET_XFER_E_IO
;
9697 /* Only handle flash writes. */
9698 if (writebuf
!= NULL
)
9704 case TARGET_OBJECT_FLASH
:
9705 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9709 return TARGET_XFER_E_IO
;
9713 /* Map pre-existing objects onto letters. DO NOT do this for new
9714 objects!!! Instead specify new query packets. */
9717 case TARGET_OBJECT_AVR
:
9721 case TARGET_OBJECT_AUXV
:
9722 gdb_assert (annex
== NULL
);
9723 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9725 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9727 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9728 return remote_read_qxfer
9729 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9730 &remote_protocol_packets
[PACKET_qXfer_features
]);
9732 case TARGET_OBJECT_LIBRARIES
:
9733 return remote_read_qxfer
9734 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9735 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9737 case TARGET_OBJECT_LIBRARIES_SVR4
:
9738 return remote_read_qxfer
9739 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9740 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9742 case TARGET_OBJECT_MEMORY_MAP
:
9743 gdb_assert (annex
== NULL
);
9744 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9746 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9748 case TARGET_OBJECT_OSDATA
:
9749 /* Should only get here if we're connected. */
9750 gdb_assert (rs
->remote_desc
);
9751 return remote_read_qxfer
9752 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9753 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9755 case TARGET_OBJECT_THREADS
:
9756 gdb_assert (annex
== NULL
);
9757 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9759 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9761 case TARGET_OBJECT_TRACEFRAME_INFO
:
9762 gdb_assert (annex
== NULL
);
9763 return remote_read_qxfer
9764 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9765 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9767 case TARGET_OBJECT_FDPIC
:
9768 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9770 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9772 case TARGET_OBJECT_OPENVMS_UIB
:
9773 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9775 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9777 case TARGET_OBJECT_BTRACE
:
9778 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9780 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9782 case TARGET_OBJECT_BTRACE_CONF
:
9783 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9785 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9787 case TARGET_OBJECT_EXEC_FILE
:
9788 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9790 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9793 return TARGET_XFER_E_IO
;
9796 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9797 large enough let the caller deal with it. */
9798 if (len
< get_remote_packet_size ())
9799 return TARGET_XFER_E_IO
;
9800 len
= get_remote_packet_size ();
9802 /* Except for querying the minimum buffer size, target must be open. */
9803 if (!rs
->remote_desc
)
9804 error (_("remote query is only available after target open"));
9806 gdb_assert (annex
!= NULL
);
9807 gdb_assert (readbuf
!= NULL
);
9813 /* We used one buffer char for the remote protocol q command and
9814 another for the query type. As the remote protocol encapsulation
9815 uses 4 chars plus one extra in case we are debugging
9816 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9819 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9821 /* Bad caller may have sent forbidden characters. */
9822 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9827 gdb_assert (annex
[i
] == '\0');
9829 i
= putpkt (rs
->buf
);
9831 return TARGET_XFER_E_IO
;
9833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9834 strcpy ((char *) readbuf
, rs
->buf
);
9836 *xfered_len
= strlen ((char *) readbuf
);
9837 return TARGET_XFER_OK
;
9841 remote_search_memory (struct target_ops
* ops
,
9842 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9843 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9844 CORE_ADDR
*found_addrp
)
9846 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9847 struct remote_state
*rs
= get_remote_state ();
9848 int max_size
= get_memory_write_packet_size ();
9849 struct packet_config
*packet
=
9850 &remote_protocol_packets
[PACKET_qSearch_memory
];
9851 /* Number of packet bytes used to encode the pattern;
9852 this could be more than PATTERN_LEN due to escape characters. */
9853 int escaped_pattern_len
;
9854 /* Amount of pattern that was encodable in the packet. */
9855 int used_pattern_len
;
9858 ULONGEST found_addr
;
9860 /* Don't go to the target if we don't have to.
9861 This is done before checking packet->support to avoid the possibility that
9862 a success for this edge case means the facility works in general. */
9863 if (pattern_len
> search_space_len
)
9865 if (pattern_len
== 0)
9867 *found_addrp
= start_addr
;
9871 /* If we already know the packet isn't supported, fall back to the simple
9872 way of searching memory. */
9874 if (packet_config_support (packet
) == PACKET_DISABLE
)
9876 /* Target doesn't provided special support, fall back and use the
9877 standard support (copy memory and do the search here). */
9878 return simple_search_memory (ops
, start_addr
, search_space_len
,
9879 pattern
, pattern_len
, found_addrp
);
9882 /* Make sure the remote is pointing at the right process. */
9883 set_general_process ();
9885 /* Insert header. */
9886 i
= snprintf (rs
->buf
, max_size
,
9887 "qSearch:memory:%s;%s;",
9888 phex_nz (start_addr
, addr_size
),
9889 phex_nz (search_space_len
, sizeof (search_space_len
)));
9890 max_size
-= (i
+ 1);
9892 /* Escape as much data as fits into rs->buf. */
9893 escaped_pattern_len
=
9894 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9895 &used_pattern_len
, max_size
);
9897 /* Bail if the pattern is too large. */
9898 if (used_pattern_len
!= pattern_len
)
9899 error (_("Pattern is too large to transmit to remote target."));
9901 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9902 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9903 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9905 /* The request may not have worked because the command is not
9906 supported. If so, fall back to the simple way. */
9907 if (packet
->support
== PACKET_DISABLE
)
9909 return simple_search_memory (ops
, start_addr
, search_space_len
,
9910 pattern
, pattern_len
, found_addrp
);
9915 if (rs
->buf
[0] == '0')
9917 else if (rs
->buf
[0] == '1')
9920 if (rs
->buf
[1] != ',')
9921 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9922 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9923 *found_addrp
= found_addr
;
9926 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9932 remote_rcmd (struct target_ops
*self
, const char *command
,
9933 struct ui_file
*outbuf
)
9935 struct remote_state
*rs
= get_remote_state ();
9938 if (!rs
->remote_desc
)
9939 error (_("remote rcmd is only available after target open"));
9941 /* Send a NULL command across as an empty command. */
9942 if (command
== NULL
)
9945 /* The query prefix. */
9946 strcpy (rs
->buf
, "qRcmd,");
9947 p
= strchr (rs
->buf
, '\0');
9949 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9950 > get_remote_packet_size ())
9951 error (_("\"monitor\" command ``%s'' is too long."), command
);
9953 /* Encode the actual command. */
9954 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9956 if (putpkt (rs
->buf
) < 0)
9957 error (_("Communication problem with target."));
9959 /* get/display the response */
9964 /* XXX - see also remote_get_noisy_reply(). */
9965 QUIT
; /* Allow user to bail out with ^C. */
9967 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9969 /* Timeout. Continue to (try to) read responses.
9970 This is better than stopping with an error, assuming the stub
9971 is still executing the (long) monitor command.
9972 If needed, the user can interrupt gdb using C-c, obtaining
9973 an effect similar to stop on timeout. */
9978 error (_("Target does not support this command."));
9979 if (buf
[0] == 'O' && buf
[1] != 'K')
9981 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9984 if (strcmp (buf
, "OK") == 0)
9986 if (strlen (buf
) == 3 && buf
[0] == 'E'
9987 && isdigit (buf
[1]) && isdigit (buf
[2]))
9989 error (_("Protocol error with Rcmd"));
9991 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9993 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9995 fputc_unfiltered (c
, outbuf
);
10001 static VEC(mem_region_s
) *
10002 remote_memory_map (struct target_ops
*ops
)
10004 VEC(mem_region_s
) *result
= NULL
;
10005 char *text
= target_read_stralloc (¤t_target
,
10006 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10010 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10012 result
= parse_memory_map (text
);
10013 do_cleanups (back_to
);
10020 packet_command (char *args
, int from_tty
)
10022 struct remote_state
*rs
= get_remote_state ();
10024 if (!rs
->remote_desc
)
10025 error (_("command can only be used with remote target"));
10028 error (_("remote-packet command requires packet text as argument"));
10030 puts_filtered ("sending: ");
10031 print_packet (args
);
10032 puts_filtered ("\n");
10035 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10036 puts_filtered ("received: ");
10037 print_packet (rs
->buf
);
10038 puts_filtered ("\n");
10042 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10044 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10046 static void threadset_test_cmd (char *cmd
, int tty
);
10048 static void threadalive_test (char *cmd
, int tty
);
10050 static void threadlist_test_cmd (char *cmd
, int tty
);
10052 int get_and_display_threadinfo (threadref
*ref
);
10054 static void threadinfo_test_cmd (char *cmd
, int tty
);
10056 static int thread_display_step (threadref
*ref
, void *context
);
10058 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10060 static void init_remote_threadtests (void);
10062 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10065 threadset_test_cmd (char *cmd
, int tty
)
10067 int sample_thread
= SAMPLE_THREAD
;
10069 printf_filtered (_("Remote threadset test\n"));
10070 set_general_thread (sample_thread
);
10075 threadalive_test (char *cmd
, int tty
)
10077 int sample_thread
= SAMPLE_THREAD
;
10078 int pid
= ptid_get_pid (inferior_ptid
);
10079 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10081 if (remote_thread_alive (ptid
))
10082 printf_filtered ("PASS: Thread alive test\n");
10084 printf_filtered ("FAIL: Thread alive test\n");
10087 void output_threadid (char *title
, threadref
*ref
);
10090 output_threadid (char *title
, threadref
*ref
)
10094 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10096 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10100 threadlist_test_cmd (char *cmd
, int tty
)
10103 threadref nextthread
;
10104 int done
, result_count
;
10105 threadref threadlist
[3];
10107 printf_filtered ("Remote Threadlist test\n");
10108 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10109 &result_count
, &threadlist
[0]))
10110 printf_filtered ("FAIL: threadlist test\n");
10113 threadref
*scan
= threadlist
;
10114 threadref
*limit
= scan
+ result_count
;
10116 while (scan
< limit
)
10117 output_threadid (" thread ", scan
++);
10122 display_thread_info (struct gdb_ext_thread_info
*info
)
10124 output_threadid ("Threadid: ", &info
->threadid
);
10125 printf_filtered ("Name: %s\n ", info
->shortname
);
10126 printf_filtered ("State: %s\n", info
->display
);
10127 printf_filtered ("other: %s\n\n", info
->more_display
);
10131 get_and_display_threadinfo (threadref
*ref
)
10135 struct gdb_ext_thread_info threadinfo
;
10137 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10138 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10139 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10140 display_thread_info (&threadinfo
);
10145 threadinfo_test_cmd (char *cmd
, int tty
)
10147 int athread
= SAMPLE_THREAD
;
10151 int_to_threadref (&thread
, athread
);
10152 printf_filtered ("Remote Threadinfo test\n");
10153 if (!get_and_display_threadinfo (&thread
))
10154 printf_filtered ("FAIL cannot get thread info\n");
10158 thread_display_step (threadref
*ref
, void *context
)
10160 /* output_threadid(" threadstep ",ref); *//* simple test */
10161 return get_and_display_threadinfo (ref
);
10165 threadlist_update_test_cmd (char *cmd
, int tty
)
10167 printf_filtered ("Remote Threadlist update test\n");
10168 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10172 init_remote_threadtests (void)
10174 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10175 _("Fetch and print the remote list of "
10176 "thread identifiers, one pkt only"));
10177 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10178 _("Fetch and display info about one thread"));
10179 add_com ("tset", class_obscure
, threadset_test_cmd
,
10180 _("Test setting to a different thread"));
10181 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10182 _("Iterate through updating all remote thread info"));
10183 add_com ("talive", class_obscure
, threadalive_test
,
10184 _(" Remote thread alive test "));
10189 /* Convert a thread ID to a string. Returns the string in a static
10193 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10195 static char buf
[64];
10196 struct remote_state
*rs
= get_remote_state ();
10198 if (ptid_equal (ptid
, null_ptid
))
10199 return normal_pid_to_str (ptid
);
10200 else if (ptid_is_pid (ptid
))
10202 /* Printing an inferior target id. */
10204 /* When multi-process extensions are off, there's no way in the
10205 remote protocol to know the remote process id, if there's any
10206 at all. There's one exception --- when we're connected with
10207 target extended-remote, and we manually attached to a process
10208 with "attach PID". We don't record anywhere a flag that
10209 allows us to distinguish that case from the case of
10210 connecting with extended-remote and the stub already being
10211 attached to a process, and reporting yes to qAttached, hence
10212 no smart special casing here. */
10213 if (!remote_multi_process_p (rs
))
10215 xsnprintf (buf
, sizeof buf
, "Remote target");
10219 return normal_pid_to_str (ptid
);
10223 if (ptid_equal (magic_null_ptid
, ptid
))
10224 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10225 else if (rs
->extended
&& remote_multi_process_p (rs
))
10226 if (ptid_get_lwp (ptid
) == 0)
10227 return normal_pid_to_str (ptid
);
10229 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10230 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10232 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10233 ptid_get_lwp (ptid
));
10238 /* Get the address of the thread local variable in OBJFILE which is
10239 stored at OFFSET within the thread local storage for thread PTID. */
10242 remote_get_thread_local_address (struct target_ops
*ops
,
10243 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10245 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10247 struct remote_state
*rs
= get_remote_state ();
10249 char *endp
= rs
->buf
+ get_remote_packet_size ();
10250 enum packet_result result
;
10252 strcpy (p
, "qGetTLSAddr:");
10254 p
= write_ptid (p
, endp
, ptid
);
10256 p
+= hexnumstr (p
, offset
);
10258 p
+= hexnumstr (p
, lm
);
10262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10263 result
= packet_ok (rs
->buf
,
10264 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10265 if (result
== PACKET_OK
)
10269 unpack_varlen_hex (rs
->buf
, &result
);
10272 else if (result
== PACKET_UNKNOWN
)
10273 throw_error (TLS_GENERIC_ERROR
,
10274 _("Remote target doesn't support qGetTLSAddr packet"));
10276 throw_error (TLS_GENERIC_ERROR
,
10277 _("Remote target failed to process qGetTLSAddr request"));
10280 throw_error (TLS_GENERIC_ERROR
,
10281 _("TLS not supported or disabled on this target"));
10286 /* Provide thread local base, i.e. Thread Information Block address.
10287 Returns 1 if ptid is found and thread_local_base is non zero. */
10290 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10292 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10294 struct remote_state
*rs
= get_remote_state ();
10296 char *endp
= rs
->buf
+ get_remote_packet_size ();
10297 enum packet_result result
;
10299 strcpy (p
, "qGetTIBAddr:");
10301 p
= write_ptid (p
, endp
, ptid
);
10305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10306 result
= packet_ok (rs
->buf
,
10307 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10308 if (result
== PACKET_OK
)
10312 unpack_varlen_hex (rs
->buf
, &result
);
10314 *addr
= (CORE_ADDR
) result
;
10317 else if (result
== PACKET_UNKNOWN
)
10318 error (_("Remote target doesn't support qGetTIBAddr packet"));
10320 error (_("Remote target failed to process qGetTIBAddr request"));
10323 error (_("qGetTIBAddr not supported or disabled on this target"));
10328 /* Support for inferring a target description based on the current
10329 architecture and the size of a 'g' packet. While the 'g' packet
10330 can have any size (since optional registers can be left off the
10331 end), some sizes are easily recognizable given knowledge of the
10332 approximate architecture. */
10334 struct remote_g_packet_guess
10337 const struct target_desc
*tdesc
;
10339 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10340 DEF_VEC_O(remote_g_packet_guess_s
);
10342 struct remote_g_packet_data
10344 VEC(remote_g_packet_guess_s
) *guesses
;
10347 static struct gdbarch_data
*remote_g_packet_data_handle
;
10350 remote_g_packet_data_init (struct obstack
*obstack
)
10352 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10356 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10357 const struct target_desc
*tdesc
)
10359 struct remote_g_packet_data
*data
10360 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
10361 struct remote_g_packet_guess new_guess
, *guess
;
10364 gdb_assert (tdesc
!= NULL
);
10367 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10369 if (guess
->bytes
== bytes
)
10370 internal_error (__FILE__
, __LINE__
,
10371 _("Duplicate g packet description added for size %d"),
10374 new_guess
.bytes
= bytes
;
10375 new_guess
.tdesc
= tdesc
;
10376 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10379 /* Return 1 if remote_read_description would do anything on this target
10380 and architecture, 0 otherwise. */
10383 remote_read_description_p (struct target_ops
*target
)
10385 struct remote_g_packet_data
*data
10386 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10388 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10394 static const struct target_desc
*
10395 remote_read_description (struct target_ops
*target
)
10397 struct remote_g_packet_data
*data
10398 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10400 /* Do not try this during initial connection, when we do not know
10401 whether there is a running but stopped thread. */
10402 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10403 return target
->beneath
->to_read_description (target
->beneath
);
10405 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10407 struct remote_g_packet_guess
*guess
;
10409 int bytes
= send_g_packet ();
10412 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10414 if (guess
->bytes
== bytes
)
10415 return guess
->tdesc
;
10417 /* We discard the g packet. A minor optimization would be to
10418 hold on to it, and fill the register cache once we have selected
10419 an architecture, but it's too tricky to do safely. */
10422 return target
->beneath
->to_read_description (target
->beneath
);
10425 /* Remote file transfer support. This is host-initiated I/O, not
10426 target-initiated; for target-initiated, see remote-fileio.c. */
10428 /* If *LEFT is at least the length of STRING, copy STRING to
10429 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10430 decrease *LEFT. Otherwise raise an error. */
10433 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10435 int len
= strlen (string
);
10438 error (_("Packet too long for target."));
10440 memcpy (*buffer
, string
, len
);
10444 /* NUL-terminate the buffer as a convenience, if there is
10450 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10451 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10452 decrease *LEFT. Otherwise raise an error. */
10455 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10458 if (2 * len
> *left
)
10459 error (_("Packet too long for target."));
10461 bin2hex (bytes
, *buffer
, len
);
10462 *buffer
+= 2 * len
;
10465 /* NUL-terminate the buffer as a convenience, if there is
10471 /* If *LEFT is large enough, convert VALUE to hex and add it to
10472 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10473 decrease *LEFT. Otherwise raise an error. */
10476 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10478 int len
= hexnumlen (value
);
10481 error (_("Packet too long for target."));
10483 hexnumstr (*buffer
, value
);
10487 /* NUL-terminate the buffer as a convenience, if there is
10493 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10494 value, *REMOTE_ERRNO to the remote error number or zero if none
10495 was included, and *ATTACHMENT to point to the start of the annex
10496 if any. The length of the packet isn't needed here; there may
10497 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10499 Return 0 if the packet could be parsed, -1 if it could not. If
10500 -1 is returned, the other variables may not be initialized. */
10503 remote_hostio_parse_result (char *buffer
, int *retcode
,
10504 int *remote_errno
, char **attachment
)
10509 *attachment
= NULL
;
10511 if (buffer
[0] != 'F')
10515 *retcode
= strtol (&buffer
[1], &p
, 16);
10516 if (errno
!= 0 || p
== &buffer
[1])
10519 /* Check for ",errno". */
10523 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10524 if (errno
!= 0 || p
+ 1 == p2
)
10529 /* Check for ";attachment". If there is no attachment, the
10530 packet should end here. */
10533 *attachment
= p
+ 1;
10536 else if (*p
== '\0')
10542 /* Send a prepared I/O packet to the target and read its response.
10543 The prepared packet is in the global RS->BUF before this function
10544 is called, and the answer is there when we return.
10546 COMMAND_BYTES is the length of the request to send, which may include
10547 binary data. WHICH_PACKET is the packet configuration to check
10548 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10549 is set to the error number and -1 is returned. Otherwise the value
10550 returned by the function is returned.
10552 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10553 attachment is expected; an error will be reported if there's a
10554 mismatch. If one is found, *ATTACHMENT will be set to point into
10555 the packet buffer and *ATTACHMENT_LEN will be set to the
10556 attachment's length. */
10559 remote_hostio_send_command (int command_bytes
, int which_packet
,
10560 int *remote_errno
, char **attachment
,
10561 int *attachment_len
)
10563 struct remote_state
*rs
= get_remote_state ();
10564 int ret
, bytes_read
;
10565 char *attachment_tmp
;
10567 if (!rs
->remote_desc
10568 || packet_support (which_packet
) == PACKET_DISABLE
)
10570 *remote_errno
= FILEIO_ENOSYS
;
10574 putpkt_binary (rs
->buf
, command_bytes
);
10575 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10577 /* If it timed out, something is wrong. Don't try to parse the
10579 if (bytes_read
< 0)
10581 *remote_errno
= FILEIO_EINVAL
;
10585 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10588 *remote_errno
= FILEIO_EINVAL
;
10590 case PACKET_UNKNOWN
:
10591 *remote_errno
= FILEIO_ENOSYS
;
10597 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10600 *remote_errno
= FILEIO_EINVAL
;
10604 /* Make sure we saw an attachment if and only if we expected one. */
10605 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10606 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10608 *remote_errno
= FILEIO_EINVAL
;
10612 /* If an attachment was found, it must point into the packet buffer;
10613 work out how many bytes there were. */
10614 if (attachment_tmp
!= NULL
)
10616 *attachment
= attachment_tmp
;
10617 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10623 /* Invalidate the readahead cache. */
10626 readahead_cache_invalidate (void)
10628 struct remote_state
*rs
= get_remote_state ();
10630 rs
->readahead_cache
.fd
= -1;
10633 /* Invalidate the readahead cache if it is holding data for FD. */
10636 readahead_cache_invalidate_fd (int fd
)
10638 struct remote_state
*rs
= get_remote_state ();
10640 if (rs
->readahead_cache
.fd
== fd
)
10641 rs
->readahead_cache
.fd
= -1;
10644 /* Set the filesystem remote_hostio functions that take FILENAME
10645 arguments will use. Return 0 on success, or -1 if an error
10646 occurs (and set *REMOTE_ERRNO). */
10649 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10651 struct remote_state
*rs
= get_remote_state ();
10652 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10654 int left
= get_remote_packet_size () - 1;
10658 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10661 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10664 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10666 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10667 remote_buffer_add_string (&p
, &left
, arg
);
10669 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10670 remote_errno
, NULL
, NULL
);
10672 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10676 rs
->fs_pid
= required_pid
;
10681 /* Implementation of to_fileio_open. */
10684 remote_hostio_open (struct target_ops
*self
,
10685 struct inferior
*inf
, const char *filename
,
10686 int flags
, int mode
, int warn_if_slow
,
10689 struct remote_state
*rs
= get_remote_state ();
10691 int left
= get_remote_packet_size () - 1;
10695 static int warning_issued
= 0;
10697 printf_unfiltered (_("Reading %s from remote target...\n"),
10700 if (!warning_issued
)
10702 warning (_("File transfers from remote targets can be slow."
10703 " Use \"set sysroot\" to access files locally"
10705 warning_issued
= 1;
10709 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10712 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10714 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10715 strlen (filename
));
10716 remote_buffer_add_string (&p
, &left
, ",");
10718 remote_buffer_add_int (&p
, &left
, flags
);
10719 remote_buffer_add_string (&p
, &left
, ",");
10721 remote_buffer_add_int (&p
, &left
, mode
);
10723 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10724 remote_errno
, NULL
, NULL
);
10727 /* Implementation of to_fileio_pwrite. */
10730 remote_hostio_pwrite (struct target_ops
*self
,
10731 int fd
, const gdb_byte
*write_buf
, int len
,
10732 ULONGEST offset
, int *remote_errno
)
10734 struct remote_state
*rs
= get_remote_state ();
10736 int left
= get_remote_packet_size ();
10739 readahead_cache_invalidate_fd (fd
);
10741 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10743 remote_buffer_add_int (&p
, &left
, fd
);
10744 remote_buffer_add_string (&p
, &left
, ",");
10746 remote_buffer_add_int (&p
, &left
, offset
);
10747 remote_buffer_add_string (&p
, &left
, ",");
10749 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10750 get_remote_packet_size () - (p
- rs
->buf
));
10752 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10753 remote_errno
, NULL
, NULL
);
10756 /* Helper for the implementation of to_fileio_pread. Read the file
10757 from the remote side with vFile:pread. */
10760 remote_hostio_pread_vFile (struct target_ops
*self
,
10761 int fd
, gdb_byte
*read_buf
, int len
,
10762 ULONGEST offset
, int *remote_errno
)
10764 struct remote_state
*rs
= get_remote_state ();
10767 int left
= get_remote_packet_size ();
10768 int ret
, attachment_len
;
10771 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10773 remote_buffer_add_int (&p
, &left
, fd
);
10774 remote_buffer_add_string (&p
, &left
, ",");
10776 remote_buffer_add_int (&p
, &left
, len
);
10777 remote_buffer_add_string (&p
, &left
, ",");
10779 remote_buffer_add_int (&p
, &left
, offset
);
10781 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10782 remote_errno
, &attachment
,
10788 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10790 if (read_len
!= ret
)
10791 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10796 /* Serve pread from the readahead cache. Returns number of bytes
10797 read, or 0 if the request can't be served from the cache. */
10800 remote_hostio_pread_from_cache (struct remote_state
*rs
,
10801 int fd
, gdb_byte
*read_buf
, size_t len
,
10804 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10806 if (cache
->fd
== fd
10807 && cache
->offset
<= offset
10808 && offset
< cache
->offset
+ cache
->bufsize
)
10810 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
10812 if (offset
+ len
> max
)
10813 len
= max
- offset
;
10815 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
10822 /* Implementation of to_fileio_pread. */
10825 remote_hostio_pread (struct target_ops
*self
,
10826 int fd
, gdb_byte
*read_buf
, int len
,
10827 ULONGEST offset
, int *remote_errno
)
10830 struct remote_state
*rs
= get_remote_state ();
10831 struct readahead_cache
*cache
= &rs
->readahead_cache
;
10833 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10836 cache
->hit_count
++;
10839 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
10840 pulongest (cache
->hit_count
));
10844 cache
->miss_count
++;
10846 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
10847 pulongest (cache
->miss_count
));
10850 cache
->offset
= offset
;
10851 cache
->bufsize
= get_remote_packet_size ();
10852 cache
->buf
= xrealloc (cache
->buf
, cache
->bufsize
);
10854 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
10855 cache
->offset
, remote_errno
);
10858 readahead_cache_invalidate_fd (fd
);
10862 cache
->bufsize
= ret
;
10863 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
10866 /* Implementation of to_fileio_close. */
10869 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10871 struct remote_state
*rs
= get_remote_state ();
10873 int left
= get_remote_packet_size () - 1;
10875 readahead_cache_invalidate_fd (fd
);
10877 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10879 remote_buffer_add_int (&p
, &left
, fd
);
10881 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10882 remote_errno
, NULL
, NULL
);
10885 /* Implementation of to_fileio_unlink. */
10888 remote_hostio_unlink (struct target_ops
*self
,
10889 struct inferior
*inf
, const char *filename
,
10892 struct remote_state
*rs
= get_remote_state ();
10894 int left
= get_remote_packet_size () - 1;
10896 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10899 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10901 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10902 strlen (filename
));
10904 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10905 remote_errno
, NULL
, NULL
);
10908 /* Implementation of to_fileio_readlink. */
10911 remote_hostio_readlink (struct target_ops
*self
,
10912 struct inferior
*inf
, const char *filename
,
10915 struct remote_state
*rs
= get_remote_state ();
10918 int left
= get_remote_packet_size ();
10919 int len
, attachment_len
;
10923 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10926 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10928 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10929 strlen (filename
));
10931 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10932 remote_errno
, &attachment
,
10938 ret
= xmalloc (len
+ 1);
10940 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10941 (gdb_byte
*) ret
, len
);
10942 if (read_len
!= len
)
10943 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10949 /* Implementation of to_fileio_fstat. */
10952 remote_hostio_fstat (struct target_ops
*self
,
10953 int fd
, struct stat
*st
,
10956 struct remote_state
*rs
= get_remote_state ();
10958 int left
= get_remote_packet_size ();
10959 int attachment_len
, ret
;
10961 struct fio_stat fst
;
10964 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10966 remote_buffer_add_int (&p
, &left
, fd
);
10968 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10969 remote_errno
, &attachment
,
10973 if (*remote_errno
!= FILEIO_ENOSYS
)
10976 /* Strictly we should return -1, ENOSYS here, but when
10977 "set sysroot remote:" was implemented in August 2008
10978 BFD's need for a stat function was sidestepped with
10979 this hack. This was not remedied until March 2015
10980 so we retain the previous behavior to avoid breaking
10983 Note that the memset is a March 2015 addition; older
10984 GDBs set st_size *and nothing else* so the structure
10985 would have garbage in all other fields. This might
10986 break something but retaining the previous behavior
10987 here would be just too wrong. */
10989 memset (st
, 0, sizeof (struct stat
));
10990 st
->st_size
= INT_MAX
;
10994 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10995 (gdb_byte
*) &fst
, sizeof (fst
));
10997 if (read_len
!= ret
)
10998 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11000 if (read_len
!= sizeof (fst
))
11001 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11002 read_len
, (int) sizeof (fst
));
11004 remote_fileio_to_host_stat (&fst
, st
);
11009 /* Implementation of to_filesystem_is_local. */
11012 remote_filesystem_is_local (struct target_ops
*self
)
11014 /* Valgrind GDB presents itself as a remote target but works
11015 on the local filesystem: it does not implement remote get
11016 and users are not expected to set a sysroot. To handle
11017 this case we treat the remote filesystem as local if the
11018 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11019 does not support vFile:open. */
11020 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11022 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11024 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11026 int fd
, remote_errno
;
11028 /* Try opening a file to probe support. The supplied
11029 filename is irrelevant, we only care about whether
11030 the stub recognizes the packet or not. */
11031 fd
= remote_hostio_open (self
, NULL
, "just probing",
11032 FILEIO_O_RDONLY
, 0700, 0,
11036 remote_hostio_close (self
, fd
, &remote_errno
);
11038 ps
= packet_support (PACKET_vFile_open
);
11041 if (ps
== PACKET_DISABLE
)
11043 static int warning_issued
= 0;
11045 if (!warning_issued
)
11047 warning (_("remote target does not support file"
11048 " transfer, attempting to access files"
11049 " from local filesystem."));
11050 warning_issued
= 1;
11061 remote_fileio_errno_to_host (int errnum
)
11067 case FILEIO_ENOENT
:
11075 case FILEIO_EACCES
:
11077 case FILEIO_EFAULT
:
11081 case FILEIO_EEXIST
:
11083 case FILEIO_ENODEV
:
11085 case FILEIO_ENOTDIR
:
11087 case FILEIO_EISDIR
:
11089 case FILEIO_EINVAL
:
11091 case FILEIO_ENFILE
:
11093 case FILEIO_EMFILE
:
11097 case FILEIO_ENOSPC
:
11099 case FILEIO_ESPIPE
:
11103 case FILEIO_ENOSYS
:
11105 case FILEIO_ENAMETOOLONG
:
11106 return ENAMETOOLONG
;
11112 remote_hostio_error (int errnum
)
11114 int host_error
= remote_fileio_errno_to_host (errnum
);
11116 if (host_error
== -1)
11117 error (_("Unknown remote I/O error %d"), errnum
);
11119 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11123 remote_hostio_close_cleanup (void *opaque
)
11125 int fd
= *(int *) opaque
;
11128 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11132 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11134 struct cleanup
*back_to
, *close_cleanup
;
11135 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11138 int bytes_in_buffer
;
11141 struct remote_state
*rs
= get_remote_state ();
11143 if (!rs
->remote_desc
)
11144 error (_("command can only be used with remote target"));
11146 file
= gdb_fopen_cloexec (local_file
, "rb");
11148 perror_with_name (local_file
);
11149 back_to
= make_cleanup_fclose (file
);
11151 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11152 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11154 0700, 0, &remote_errno
);
11156 remote_hostio_error (remote_errno
);
11158 /* Send up to this many bytes at once. They won't all fit in the
11159 remote packet limit, so we'll transfer slightly fewer. */
11160 io_size
= get_remote_packet_size ();
11161 buffer
= xmalloc (io_size
);
11162 make_cleanup (xfree
, buffer
);
11164 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11166 bytes_in_buffer
= 0;
11169 while (bytes_in_buffer
|| !saw_eof
)
11173 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11174 io_size
- bytes_in_buffer
,
11179 error (_("Error reading %s."), local_file
);
11182 /* EOF. Unless there is something still in the
11183 buffer from the last iteration, we are done. */
11185 if (bytes_in_buffer
== 0)
11193 bytes
+= bytes_in_buffer
;
11194 bytes_in_buffer
= 0;
11196 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11198 offset
, &remote_errno
);
11201 remote_hostio_error (remote_errno
);
11202 else if (retcode
== 0)
11203 error (_("Remote write of %d bytes returned 0!"), bytes
);
11204 else if (retcode
< bytes
)
11206 /* Short write. Save the rest of the read data for the next
11208 bytes_in_buffer
= bytes
- retcode
;
11209 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11215 discard_cleanups (close_cleanup
);
11216 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11217 remote_hostio_error (remote_errno
);
11220 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11221 do_cleanups (back_to
);
11225 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11227 struct cleanup
*back_to
, *close_cleanup
;
11228 int fd
, remote_errno
, bytes
, io_size
;
11232 struct remote_state
*rs
= get_remote_state ();
11234 if (!rs
->remote_desc
)
11235 error (_("command can only be used with remote target"));
11237 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11238 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11241 remote_hostio_error (remote_errno
);
11243 file
= gdb_fopen_cloexec (local_file
, "wb");
11245 perror_with_name (local_file
);
11246 back_to
= make_cleanup_fclose (file
);
11248 /* Send up to this many bytes at once. They won't all fit in the
11249 remote packet limit, so we'll transfer slightly fewer. */
11250 io_size
= get_remote_packet_size ();
11251 buffer
= xmalloc (io_size
);
11252 make_cleanup (xfree
, buffer
);
11254 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11259 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11260 fd
, buffer
, io_size
, offset
, &remote_errno
);
11262 /* Success, but no bytes, means end-of-file. */
11265 remote_hostio_error (remote_errno
);
11269 bytes
= fwrite (buffer
, 1, bytes
, file
);
11271 perror_with_name (local_file
);
11274 discard_cleanups (close_cleanup
);
11275 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11276 remote_hostio_error (remote_errno
);
11279 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11280 do_cleanups (back_to
);
11284 remote_file_delete (const char *remote_file
, int from_tty
)
11286 int retcode
, remote_errno
;
11287 struct remote_state
*rs
= get_remote_state ();
11289 if (!rs
->remote_desc
)
11290 error (_("command can only be used with remote target"));
11292 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11293 NULL
, remote_file
, &remote_errno
);
11295 remote_hostio_error (remote_errno
);
11298 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11302 remote_put_command (char *args
, int from_tty
)
11304 struct cleanup
*back_to
;
11308 error_no_arg (_("file to put"));
11310 argv
= gdb_buildargv (args
);
11311 back_to
= make_cleanup_freeargv (argv
);
11312 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11313 error (_("Invalid parameters to remote put"));
11315 remote_file_put (argv
[0], argv
[1], from_tty
);
11317 do_cleanups (back_to
);
11321 remote_get_command (char *args
, int from_tty
)
11323 struct cleanup
*back_to
;
11327 error_no_arg (_("file to get"));
11329 argv
= gdb_buildargv (args
);
11330 back_to
= make_cleanup_freeargv (argv
);
11331 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11332 error (_("Invalid parameters to remote get"));
11334 remote_file_get (argv
[0], argv
[1], from_tty
);
11336 do_cleanups (back_to
);
11340 remote_delete_command (char *args
, int from_tty
)
11342 struct cleanup
*back_to
;
11346 error_no_arg (_("file to delete"));
11348 argv
= gdb_buildargv (args
);
11349 back_to
= make_cleanup_freeargv (argv
);
11350 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11351 error (_("Invalid parameters to remote delete"));
11353 remote_file_delete (argv
[0], from_tty
);
11355 do_cleanups (back_to
);
11359 remote_command (char *args
, int from_tty
)
11361 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11365 remote_can_execute_reverse (struct target_ops
*self
)
11367 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11368 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11375 remote_supports_non_stop (struct target_ops
*self
)
11381 remote_supports_disable_randomization (struct target_ops
*self
)
11383 /* Only supported in extended mode. */
11388 remote_supports_multi_process (struct target_ops
*self
)
11390 struct remote_state
*rs
= get_remote_state ();
11392 /* Only extended-remote handles being attached to multiple
11393 processes, even though plain remote can use the multi-process
11394 thread id extensions, so that GDB knows the target process's
11396 return rs
->extended
&& remote_multi_process_p (rs
);
11400 remote_supports_cond_tracepoints (void)
11402 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11406 remote_supports_cond_breakpoints (struct target_ops
*self
)
11408 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11412 remote_supports_fast_tracepoints (void)
11414 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11418 remote_supports_static_tracepoints (void)
11420 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11424 remote_supports_install_in_trace (void)
11426 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11430 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11432 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11437 remote_supports_string_tracing (struct target_ops
*self
)
11439 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11443 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11445 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11449 remote_trace_init (struct target_ops
*self
)
11452 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11453 if (strcmp (target_buf
, "OK") != 0)
11454 error (_("Target does not support this command."));
11457 static void free_actions_list (char **actions_list
);
11458 static void free_actions_list_cleanup_wrapper (void *);
11460 free_actions_list_cleanup_wrapper (void *al
)
11462 free_actions_list (al
);
11466 free_actions_list (char **actions_list
)
11470 if (actions_list
== 0)
11473 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11474 xfree (actions_list
[ndx
]);
11476 xfree (actions_list
);
11479 /* Recursive routine to walk through command list including loops, and
11480 download packets for each command. */
11483 remote_download_command_source (int num
, ULONGEST addr
,
11484 struct command_line
*cmds
)
11486 struct remote_state
*rs
= get_remote_state ();
11487 struct command_line
*cmd
;
11489 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11491 QUIT
; /* Allow user to bail out with ^C. */
11492 strcpy (rs
->buf
, "QTDPsrc:");
11493 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11494 rs
->buf
+ strlen (rs
->buf
),
11495 rs
->buf_size
- strlen (rs
->buf
));
11497 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11498 if (strcmp (target_buf
, "OK"))
11499 warning (_("Target does not support source download."));
11501 if (cmd
->control_type
== while_control
11502 || cmd
->control_type
== while_stepping_control
)
11504 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11506 QUIT
; /* Allow user to bail out with ^C. */
11507 strcpy (rs
->buf
, "QTDPsrc:");
11508 encode_source_string (num
, addr
, "cmd", "end",
11509 rs
->buf
+ strlen (rs
->buf
),
11510 rs
->buf_size
- strlen (rs
->buf
));
11512 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11513 if (strcmp (target_buf
, "OK"))
11514 warning (_("Target does not support source download."));
11520 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11522 #define BUF_SIZE 2048
11526 char buf
[BUF_SIZE
];
11527 char **tdp_actions
;
11528 char **stepping_actions
;
11530 struct cleanup
*old_chain
= NULL
;
11531 struct agent_expr
*aexpr
;
11532 struct cleanup
*aexpr_chain
= NULL
;
11534 struct breakpoint
*b
= loc
->owner
;
11535 struct tracepoint
*t
= (struct tracepoint
*) b
;
11537 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11538 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11540 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11543 tpaddr
= loc
->address
;
11544 sprintf_vma (addrbuf
, tpaddr
);
11545 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11546 addrbuf
, /* address */
11547 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11548 t
->step_count
, t
->pass_count
);
11549 /* Fast tracepoints are mostly handled by the target, but we can
11550 tell the target how big of an instruction block should be moved
11552 if (b
->type
== bp_fast_tracepoint
)
11554 /* Only test for support at download time; we may not know
11555 target capabilities at definition time. */
11556 if (remote_supports_fast_tracepoints ())
11558 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11560 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11561 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11563 /* If it passed validation at definition but fails now,
11564 something is very wrong. */
11565 internal_error (__FILE__
, __LINE__
,
11566 _("Fast tracepoint not "
11567 "valid during download"));
11570 /* Fast tracepoints are functionally identical to regular
11571 tracepoints, so don't take lack of support as a reason to
11572 give up on the trace run. */
11573 warning (_("Target does not support fast tracepoints, "
11574 "downloading %d as regular tracepoint"), b
->number
);
11576 else if (b
->type
== bp_static_tracepoint
)
11578 /* Only test for support at download time; we may not know
11579 target capabilities at definition time. */
11580 if (remote_supports_static_tracepoints ())
11582 struct static_tracepoint_marker marker
;
11584 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11585 strcat (buf
, ":S");
11587 error (_("Static tracepoint not valid during download"));
11590 /* Fast tracepoints are functionally identical to regular
11591 tracepoints, so don't take lack of support as a reason
11592 to give up on the trace run. */
11593 error (_("Target does not support static tracepoints"));
11595 /* If the tracepoint has a conditional, make it into an agent
11596 expression and append to the definition. */
11599 /* Only test support at download time, we may not know target
11600 capabilities at definition time. */
11601 if (remote_supports_cond_tracepoints ())
11603 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11604 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11605 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11607 pkt
= buf
+ strlen (buf
);
11608 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11609 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11611 do_cleanups (aexpr_chain
);
11614 warning (_("Target does not support conditional tracepoints, "
11615 "ignoring tp %d cond"), b
->number
);
11618 if (b
->commands
|| *default_collect
)
11621 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11622 if (strcmp (target_buf
, "OK"))
11623 error (_("Target does not support tracepoints."));
11625 /* do_single_steps (t); */
11628 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11630 QUIT
; /* Allow user to bail out with ^C. */
11631 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11632 b
->number
, addrbuf
, /* address */
11634 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11637 remote_get_noisy_reply (&target_buf
,
11639 if (strcmp (target_buf
, "OK"))
11640 error (_("Error on target while setting tracepoints."));
11643 if (stepping_actions
)
11645 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11647 QUIT
; /* Allow user to bail out with ^C. */
11648 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11649 b
->number
, addrbuf
, /* address */
11650 ((ndx
== 0) ? "S" : ""),
11651 stepping_actions
[ndx
],
11652 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11654 remote_get_noisy_reply (&target_buf
,
11656 if (strcmp (target_buf
, "OK"))
11657 error (_("Error on target while setting tracepoints."));
11661 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11663 if (b
->location
!= NULL
)
11665 strcpy (buf
, "QTDPsrc:");
11666 encode_source_string (b
->number
, loc
->address
, "at",
11667 event_location_to_string (b
->location
),
11668 buf
+ strlen (buf
), 2048 - strlen (buf
));
11670 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11671 if (strcmp (target_buf
, "OK"))
11672 warning (_("Target does not support source download."));
11674 if (b
->cond_string
)
11676 strcpy (buf
, "QTDPsrc:");
11677 encode_source_string (b
->number
, loc
->address
,
11678 "cond", b
->cond_string
, buf
+ strlen (buf
),
11679 2048 - strlen (buf
));
11681 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11682 if (strcmp (target_buf
, "OK"))
11683 warning (_("Target does not support source download."));
11685 remote_download_command_source (b
->number
, loc
->address
,
11686 breakpoint_commands (b
));
11689 do_cleanups (old_chain
);
11693 remote_can_download_tracepoint (struct target_ops
*self
)
11695 struct remote_state
*rs
= get_remote_state ();
11696 struct trace_status
*ts
;
11699 /* Don't try to install tracepoints until we've relocated our
11700 symbols, and fetched and merged the target's tracepoint list with
11702 if (rs
->starting_up
)
11705 ts
= current_trace_status ();
11706 status
= remote_get_trace_status (self
, ts
);
11708 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11711 /* If we are in a tracing experiment, but remote stub doesn't support
11712 installing tracepoint in trace, we have to return. */
11713 if (!remote_supports_install_in_trace ())
11721 remote_download_trace_state_variable (struct target_ops
*self
,
11722 struct trace_state_variable
*tsv
)
11724 struct remote_state
*rs
= get_remote_state ();
11727 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11728 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11730 p
= rs
->buf
+ strlen (rs
->buf
);
11731 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11732 error (_("Trace state variable name too long for tsv definition packet"));
11733 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11736 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11737 if (*target_buf
== '\0')
11738 error (_("Target does not support this command."));
11739 if (strcmp (target_buf
, "OK") != 0)
11740 error (_("Error on target while downloading trace state variable."));
11744 remote_enable_tracepoint (struct target_ops
*self
,
11745 struct bp_location
*location
)
11747 struct remote_state
*rs
= get_remote_state ();
11750 sprintf_vma (addr_buf
, location
->address
);
11751 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11752 location
->owner
->number
, addr_buf
);
11754 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11755 if (*rs
->buf
== '\0')
11756 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11757 if (strcmp (rs
->buf
, "OK") != 0)
11758 error (_("Error on target while enabling tracepoint."));
11762 remote_disable_tracepoint (struct target_ops
*self
,
11763 struct bp_location
*location
)
11765 struct remote_state
*rs
= get_remote_state ();
11768 sprintf_vma (addr_buf
, location
->address
);
11769 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11770 location
->owner
->number
, addr_buf
);
11772 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11773 if (*rs
->buf
== '\0')
11774 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11775 if (strcmp (rs
->buf
, "OK") != 0)
11776 error (_("Error on target while disabling tracepoint."));
11780 remote_trace_set_readonly_regions (struct target_ops
*self
)
11784 bfd_size_type size
;
11790 return; /* No information to give. */
11792 strcpy (target_buf
, "QTro");
11793 offset
= strlen (target_buf
);
11794 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11796 char tmp1
[40], tmp2
[40];
11799 if ((s
->flags
& SEC_LOAD
) == 0 ||
11800 /* (s->flags & SEC_CODE) == 0 || */
11801 (s
->flags
& SEC_READONLY
) == 0)
11805 vma
= bfd_get_section_vma (abfd
, s
);
11806 size
= bfd_get_section_size (s
);
11807 sprintf_vma (tmp1
, vma
);
11808 sprintf_vma (tmp2
, vma
+ size
);
11809 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11810 if (offset
+ sec_length
+ 1 > target_buf_size
)
11812 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11814 Too many sections for read-only sections definition packet."));
11817 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11819 offset
+= sec_length
;
11823 putpkt (target_buf
);
11824 getpkt (&target_buf
, &target_buf_size
, 0);
11829 remote_trace_start (struct target_ops
*self
)
11831 putpkt ("QTStart");
11832 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11833 if (*target_buf
== '\0')
11834 error (_("Target does not support this command."));
11835 if (strcmp (target_buf
, "OK") != 0)
11836 error (_("Bogus reply from target: %s"), target_buf
);
11840 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11842 /* Initialize it just to avoid a GCC false warning. */
11844 /* FIXME we need to get register block size some other way. */
11845 extern int trace_regblock_size
;
11846 enum packet_result result
;
11848 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11851 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11853 putpkt ("qTStatus");
11857 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11859 CATCH (ex
, RETURN_MASK_ERROR
)
11861 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11863 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11866 throw_exception (ex
);
11870 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11872 /* If the remote target doesn't do tracing, flag it. */
11873 if (result
== PACKET_UNKNOWN
)
11876 /* We're working with a live target. */
11877 ts
->filename
= NULL
;
11880 error (_("Bogus trace status reply from target: %s"), target_buf
);
11882 /* Function 'parse_trace_status' sets default value of each field of
11883 'ts' at first, so we don't have to do it here. */
11884 parse_trace_status (p
, ts
);
11886 return ts
->running
;
11890 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11891 struct uploaded_tp
*utp
)
11893 struct remote_state
*rs
= get_remote_state ();
11895 struct bp_location
*loc
;
11896 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11897 size_t size
= get_remote_packet_size ();
11901 tp
->base
.hit_count
= 0;
11902 tp
->traceframe_usage
= 0;
11903 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11905 /* If the tracepoint was never downloaded, don't go asking for
11907 if (tp
->number_on_target
== 0)
11909 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11910 phex_nz (loc
->address
, 0));
11912 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11913 if (reply
&& *reply
)
11916 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11922 utp
->hit_count
= 0;
11923 utp
->traceframe_usage
= 0;
11924 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11925 phex_nz (utp
->addr
, 0));
11927 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11928 if (reply
&& *reply
)
11931 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11937 remote_trace_stop (struct target_ops
*self
)
11940 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11941 if (*target_buf
== '\0')
11942 error (_("Target does not support this command."));
11943 if (strcmp (target_buf
, "OK") != 0)
11944 error (_("Bogus reply from target: %s"), target_buf
);
11948 remote_trace_find (struct target_ops
*self
,
11949 enum trace_find_type type
, int num
,
11950 CORE_ADDR addr1
, CORE_ADDR addr2
,
11953 struct remote_state
*rs
= get_remote_state ();
11954 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11956 int target_frameno
= -1, target_tracept
= -1;
11958 /* Lookups other than by absolute frame number depend on the current
11959 trace selected, so make sure it is correct on the remote end
11961 if (type
!= tfind_number
)
11962 set_remote_traceframe ();
11965 strcpy (p
, "QTFrame:");
11966 p
= strchr (p
, '\0');
11970 xsnprintf (p
, endbuf
- p
, "%x", num
);
11973 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11976 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11979 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11980 phex_nz (addr2
, 0));
11982 case tfind_outside
:
11983 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11984 phex_nz (addr2
, 0));
11987 error (_("Unknown trace find type %d"), type
);
11991 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11992 if (*reply
== '\0')
11993 error (_("Target does not support this command."));
11995 while (reply
&& *reply
)
12000 target_frameno
= (int) strtol (p
, &reply
, 16);
12002 error (_("Unable to parse trace frame number"));
12003 /* Don't update our remote traceframe number cache on failure
12004 to select a remote traceframe. */
12005 if (target_frameno
== -1)
12010 target_tracept
= (int) strtol (p
, &reply
, 16);
12012 error (_("Unable to parse tracepoint number"));
12014 case 'O': /* "OK"? */
12015 if (reply
[1] == 'K' && reply
[2] == '\0')
12018 error (_("Bogus reply from target: %s"), reply
);
12021 error (_("Bogus reply from target: %s"), reply
);
12024 *tpp
= target_tracept
;
12026 rs
->remote_traceframe_number
= target_frameno
;
12027 return target_frameno
;
12031 remote_get_trace_state_variable_value (struct target_ops
*self
,
12032 int tsvnum
, LONGEST
*val
)
12034 struct remote_state
*rs
= get_remote_state ();
12038 set_remote_traceframe ();
12040 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12042 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12043 if (reply
&& *reply
)
12047 unpack_varlen_hex (reply
+ 1, &uval
);
12048 *val
= (LONGEST
) uval
;
12056 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12058 struct remote_state
*rs
= get_remote_state ();
12062 strcpy (p
, "QTSave:");
12064 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12065 error (_("Remote file name too long for trace save packet"));
12066 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12069 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12070 if (*reply
== '\0')
12071 error (_("Target does not support this command."));
12072 if (strcmp (reply
, "OK") != 0)
12073 error (_("Bogus reply from target: %s"), reply
);
12077 /* This is basically a memory transfer, but needs to be its own packet
12078 because we don't know how the target actually organizes its trace
12079 memory, plus we want to be able to ask for as much as possible, but
12080 not be unhappy if we don't get as much as we ask for. */
12083 remote_get_raw_trace_data (struct target_ops
*self
,
12084 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12086 struct remote_state
*rs
= get_remote_state ();
12092 strcpy (p
, "qTBuffer:");
12094 p
+= hexnumstr (p
, offset
);
12096 p
+= hexnumstr (p
, len
);
12100 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12101 if (reply
&& *reply
)
12103 /* 'l' by itself means we're at the end of the buffer and
12104 there is nothing more to get. */
12108 /* Convert the reply into binary. Limit the number of bytes to
12109 convert according to our passed-in buffer size, rather than
12110 what was returned in the packet; if the target is
12111 unexpectedly generous and gives us a bigger reply than we
12112 asked for, we don't want to crash. */
12113 rslt
= hex2bin (target_buf
, buf
, len
);
12117 /* Something went wrong, flag as an error. */
12122 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12124 struct remote_state
*rs
= get_remote_state ();
12126 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12130 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12132 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12133 if (*reply
== '\0')
12134 error (_("Target does not support this command."));
12135 if (strcmp (reply
, "OK") != 0)
12136 error (_("Bogus reply from target: %s"), reply
);
12139 warning (_("Target does not support disconnected tracing."));
12143 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12145 struct thread_info
*info
= find_thread_ptid (ptid
);
12147 if (info
&& info
->priv
)
12148 return info
->priv
->core
;
12153 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12155 struct remote_state
*rs
= get_remote_state ();
12158 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12160 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12161 if (*reply
== '\0')
12162 error (_("Target does not support this command."));
12163 if (strcmp (reply
, "OK") != 0)
12164 error (_("Bogus reply from target: %s"), reply
);
12167 static struct traceframe_info
*
12168 remote_traceframe_info (struct target_ops
*self
)
12172 text
= target_read_stralloc (¤t_target
,
12173 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12176 struct traceframe_info
*info
;
12177 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12179 info
= parse_traceframe_info (text
);
12180 do_cleanups (back_to
);
12187 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12188 instruction on which a fast tracepoint may be placed. Returns -1
12189 if the packet is not supported, and 0 if the minimum instruction
12190 length is unknown. */
12193 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12195 struct remote_state
*rs
= get_remote_state ();
12198 /* If we're not debugging a process yet, the IPA can't be
12200 if (!target_has_execution
)
12203 /* Make sure the remote is pointing at the right process. */
12204 set_general_process ();
12206 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12208 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12209 if (*reply
== '\0')
12213 ULONGEST min_insn_len
;
12215 unpack_varlen_hex (reply
, &min_insn_len
);
12217 return (int) min_insn_len
;
12222 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12224 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12226 struct remote_state
*rs
= get_remote_state ();
12227 char *buf
= rs
->buf
;
12228 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12229 enum packet_result result
;
12231 gdb_assert (val
>= 0 || val
== -1);
12232 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12233 /* Send -1 as literal "-1" to avoid host size dependency. */
12237 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12240 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12243 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12244 result
= packet_ok (rs
->buf
,
12245 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12247 if (result
!= PACKET_OK
)
12248 warning (_("Bogus reply from target: %s"), rs
->buf
);
12253 remote_set_trace_notes (struct target_ops
*self
,
12254 const char *user
, const char *notes
,
12255 const char *stop_notes
)
12257 struct remote_state
*rs
= get_remote_state ();
12259 char *buf
= rs
->buf
;
12260 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12263 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12266 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12267 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12273 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12274 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12280 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12281 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12285 /* Ensure the buffer is terminated. */
12289 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12290 if (*reply
== '\0')
12293 if (strcmp (reply
, "OK") != 0)
12294 error (_("Bogus reply from target: %s"), reply
);
12300 remote_use_agent (struct target_ops
*self
, int use
)
12302 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12304 struct remote_state
*rs
= get_remote_state ();
12306 /* If the stub supports QAgent. */
12307 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12309 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12311 if (strcmp (rs
->buf
, "OK") == 0)
12322 remote_can_use_agent (struct target_ops
*self
)
12324 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12327 struct btrace_target_info
12329 /* The ptid of the traced thread. */
12332 /* The obtained branch trace configuration. */
12333 struct btrace_config conf
;
12336 /* Reset our idea of our target's btrace configuration. */
12339 remote_btrace_reset (void)
12341 struct remote_state
*rs
= get_remote_state ();
12343 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12346 /* Check whether the target supports branch tracing. */
12349 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12351 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12353 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12358 case BTRACE_FORMAT_NONE
:
12361 case BTRACE_FORMAT_BTS
:
12362 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12364 case BTRACE_FORMAT_PT
:
12365 /* The trace is decoded on the host. Even if our target supports it,
12366 we still need to have libipt to decode the trace. */
12367 #if defined (HAVE_LIBIPT)
12368 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12369 #else /* !defined (HAVE_LIBIPT) */
12371 #endif /* !defined (HAVE_LIBIPT) */
12374 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12377 /* Synchronize the configuration with the target. */
12380 btrace_sync_conf (const struct btrace_config
*conf
)
12382 struct packet_config
*packet
;
12383 struct remote_state
*rs
;
12384 char *buf
, *pos
, *endbuf
;
12386 rs
= get_remote_state ();
12388 endbuf
= buf
+ get_remote_packet_size ();
12390 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12391 if (packet_config_support (packet
) == PACKET_ENABLE
12392 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12395 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12399 getpkt (&buf
, &rs
->buf_size
, 0);
12401 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12403 if (buf
[0] == 'E' && buf
[1] == '.')
12404 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12406 error (_("Failed to configure the BTS buffer size."));
12409 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12412 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12413 if (packet_config_support (packet
) == PACKET_ENABLE
12414 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12417 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12421 getpkt (&buf
, &rs
->buf_size
, 0);
12423 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12425 if (buf
[0] == 'E' && buf
[1] == '.')
12426 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12428 error (_("Failed to configure the trace buffer size."));
12431 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12435 /* Read the current thread's btrace configuration from the target and
12436 store it into CONF. */
12439 btrace_read_config (struct btrace_config
*conf
)
12443 xml
= target_read_stralloc (¤t_target
,
12444 TARGET_OBJECT_BTRACE_CONF
, "");
12447 struct cleanup
*cleanup
;
12449 cleanup
= make_cleanup (xfree
, xml
);
12450 parse_xml_btrace_conf (conf
, xml
);
12451 do_cleanups (cleanup
);
12455 /* Enable branch tracing. */
12457 static struct btrace_target_info
*
12458 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12459 const struct btrace_config
*conf
)
12461 struct btrace_target_info
*tinfo
= NULL
;
12462 struct packet_config
*packet
= NULL
;
12463 struct remote_state
*rs
= get_remote_state ();
12464 char *buf
= rs
->buf
;
12465 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12467 switch (conf
->format
)
12469 case BTRACE_FORMAT_BTS
:
12470 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12473 case BTRACE_FORMAT_PT
:
12474 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12478 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12479 error (_("Target does not support branch tracing."));
12481 btrace_sync_conf (conf
);
12483 set_general_thread (ptid
);
12485 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12487 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12489 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12491 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12492 error (_("Could not enable branch tracing for %s: %s"),
12493 target_pid_to_str (ptid
), rs
->buf
+ 2);
12495 error (_("Could not enable branch tracing for %s."),
12496 target_pid_to_str (ptid
));
12499 tinfo
= XCNEW (struct btrace_target_info
);
12500 tinfo
->ptid
= ptid
;
12502 /* If we fail to read the configuration, we lose some information, but the
12503 tracing itself is not impacted. */
12506 btrace_read_config (&tinfo
->conf
);
12508 CATCH (err
, RETURN_MASK_ERROR
)
12510 if (err
.message
!= NULL
)
12511 warning ("%s", err
.message
);
12518 /* Disable branch tracing. */
12521 remote_disable_btrace (struct target_ops
*self
,
12522 struct btrace_target_info
*tinfo
)
12524 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12525 struct remote_state
*rs
= get_remote_state ();
12526 char *buf
= rs
->buf
;
12527 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12529 if (packet_config_support (packet
) != PACKET_ENABLE
)
12530 error (_("Target does not support branch tracing."));
12532 set_general_thread (tinfo
->ptid
);
12534 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12536 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12538 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12540 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12541 error (_("Could not disable branch tracing for %s: %s"),
12542 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12544 error (_("Could not disable branch tracing for %s."),
12545 target_pid_to_str (tinfo
->ptid
));
12551 /* Teardown branch tracing. */
12554 remote_teardown_btrace (struct target_ops
*self
,
12555 struct btrace_target_info
*tinfo
)
12557 /* We must not talk to the target during teardown. */
12561 /* Read the branch trace. */
12563 static enum btrace_error
12564 remote_read_btrace (struct target_ops
*self
,
12565 struct btrace_data
*btrace
,
12566 struct btrace_target_info
*tinfo
,
12567 enum btrace_read_type type
)
12569 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12570 struct remote_state
*rs
= get_remote_state ();
12571 struct cleanup
*cleanup
;
12575 if (packet_config_support (packet
) != PACKET_ENABLE
)
12576 error (_("Target does not support branch tracing."));
12578 #if !defined(HAVE_LIBEXPAT)
12579 error (_("Cannot process branch tracing result. XML parsing not supported."));
12584 case BTRACE_READ_ALL
:
12587 case BTRACE_READ_NEW
:
12590 case BTRACE_READ_DELTA
:
12594 internal_error (__FILE__
, __LINE__
,
12595 _("Bad branch tracing read type: %u."),
12596 (unsigned int) type
);
12599 xml
= target_read_stralloc (¤t_target
,
12600 TARGET_OBJECT_BTRACE
, annex
);
12602 return BTRACE_ERR_UNKNOWN
;
12604 cleanup
= make_cleanup (xfree
, xml
);
12605 parse_xml_btrace (btrace
, xml
);
12606 do_cleanups (cleanup
);
12608 return BTRACE_ERR_NONE
;
12611 static const struct btrace_config
*
12612 remote_btrace_conf (struct target_ops
*self
,
12613 const struct btrace_target_info
*tinfo
)
12615 return &tinfo
->conf
;
12619 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12621 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12625 /* Implementation of to_load. */
12628 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12630 generic_load (name
, from_tty
);
12633 /* Accepts an integer PID; returns a string representing a file that
12634 can be opened on the remote side to get the symbols for the child
12635 process. Returns NULL if the operation is not supported. */
12638 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12640 static char *filename
= NULL
;
12641 struct inferior
*inf
;
12642 char *annex
= NULL
;
12644 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12647 if (filename
!= NULL
)
12650 inf
= find_inferior_pid (pid
);
12652 internal_error (__FILE__
, __LINE__
,
12653 _("not currently attached to process %d"), pid
);
12655 if (!inf
->fake_pid_p
)
12657 const int annex_size
= 9;
12659 annex
= alloca (annex_size
);
12660 xsnprintf (annex
, annex_size
, "%x", pid
);
12663 filename
= target_read_stralloc (¤t_target
,
12664 TARGET_OBJECT_EXEC_FILE
, annex
);
12669 /* Implement the to_can_do_single_step target_ops method. */
12672 remote_can_do_single_step (struct target_ops
*ops
)
12674 /* We can only tell whether target supports single step or not by
12675 supported s and S vCont actions if the stub supports vContSupported
12676 feature. If the stub doesn't support vContSupported feature,
12677 we have conservatively to think target doesn't supports single
12679 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
12681 struct remote_state
*rs
= get_remote_state ();
12683 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12684 remote_vcont_probe (rs
);
12686 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
12693 init_remote_ops (void)
12695 remote_ops
.to_shortname
= "remote";
12696 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12697 remote_ops
.to_doc
=
12698 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12699 Specify the serial device it is connected to\n\
12700 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12701 remote_ops
.to_open
= remote_open
;
12702 remote_ops
.to_close
= remote_close
;
12703 remote_ops
.to_detach
= remote_detach
;
12704 remote_ops
.to_disconnect
= remote_disconnect
;
12705 remote_ops
.to_resume
= remote_resume
;
12706 remote_ops
.to_wait
= remote_wait
;
12707 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12708 remote_ops
.to_store_registers
= remote_store_registers
;
12709 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12710 remote_ops
.to_files_info
= remote_files_info
;
12711 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12712 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12713 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12714 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12715 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12716 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12717 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12718 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12719 remote_ops
.to_watchpoint_addr_within_range
=
12720 remote_watchpoint_addr_within_range
;
12721 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12722 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12723 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12724 remote_ops
.to_region_ok_for_hw_watchpoint
12725 = remote_region_ok_for_hw_watchpoint
;
12726 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12727 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12728 remote_ops
.to_kill
= remote_kill
;
12729 remote_ops
.to_load
= remote_load
;
12730 remote_ops
.to_mourn_inferior
= remote_mourn
;
12731 remote_ops
.to_pass_signals
= remote_pass_signals
;
12732 remote_ops
.to_program_signals
= remote_program_signals
;
12733 remote_ops
.to_thread_alive
= remote_thread_alive
;
12734 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12735 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12736 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12737 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12738 remote_ops
.to_stop
= remote_stop
;
12739 remote_ops
.to_interrupt
= remote_interrupt
;
12740 remote_ops
.to_check_pending_interrupt
= remote_check_pending_interrupt
;
12741 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12742 remote_ops
.to_rcmd
= remote_rcmd
;
12743 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12744 remote_ops
.to_log_command
= serial_log_command
;
12745 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12746 remote_ops
.to_stratum
= process_stratum
;
12747 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12748 remote_ops
.to_has_memory
= default_child_has_memory
;
12749 remote_ops
.to_has_stack
= default_child_has_stack
;
12750 remote_ops
.to_has_registers
= default_child_has_registers
;
12751 remote_ops
.to_has_execution
= default_child_has_execution
;
12752 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12753 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12754 remote_ops
.to_magic
= OPS_MAGIC
;
12755 remote_ops
.to_memory_map
= remote_memory_map
;
12756 remote_ops
.to_flash_erase
= remote_flash_erase
;
12757 remote_ops
.to_flash_done
= remote_flash_done
;
12758 remote_ops
.to_read_description
= remote_read_description
;
12759 remote_ops
.to_search_memory
= remote_search_memory
;
12760 remote_ops
.to_can_async_p
= remote_can_async_p
;
12761 remote_ops
.to_is_async_p
= remote_is_async_p
;
12762 remote_ops
.to_async
= remote_async
;
12763 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
12764 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12765 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12766 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12767 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12768 remote_ops
.to_supports_disable_randomization
12769 = remote_supports_disable_randomization
;
12770 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12771 remote_ops
.to_fileio_open
= remote_hostio_open
;
12772 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12773 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12774 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12775 remote_ops
.to_fileio_close
= remote_hostio_close
;
12776 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12777 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12778 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12779 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12780 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12781 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12782 remote_ops
.to_trace_init
= remote_trace_init
;
12783 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12784 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12785 remote_ops
.to_download_trace_state_variable
12786 = remote_download_trace_state_variable
;
12787 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12788 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12789 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12790 remote_ops
.to_trace_start
= remote_trace_start
;
12791 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12792 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12793 remote_ops
.to_trace_stop
= remote_trace_stop
;
12794 remote_ops
.to_trace_find
= remote_trace_find
;
12795 remote_ops
.to_get_trace_state_variable_value
12796 = remote_get_trace_state_variable_value
;
12797 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12798 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12799 remote_ops
.to_upload_trace_state_variables
12800 = remote_upload_trace_state_variables
;
12801 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12802 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12803 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12804 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12805 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12806 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12807 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12808 remote_ops
.to_verify_memory
= remote_verify_memory
;
12809 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12810 remote_ops
.to_set_permissions
= remote_set_permissions
;
12811 remote_ops
.to_static_tracepoint_marker_at
12812 = remote_static_tracepoint_marker_at
;
12813 remote_ops
.to_static_tracepoint_markers_by_strid
12814 = remote_static_tracepoint_markers_by_strid
;
12815 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12816 remote_ops
.to_use_agent
= remote_use_agent
;
12817 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12818 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12819 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12820 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12821 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12822 remote_ops
.to_read_btrace
= remote_read_btrace
;
12823 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12824 remote_ops
.to_augmented_libraries_svr4_read
=
12825 remote_augmented_libraries_svr4_read
;
12828 /* Set up the extended remote vector by making a copy of the standard
12829 remote vector and adding to it. */
12832 init_extended_remote_ops (void)
12834 extended_remote_ops
= remote_ops
;
12836 extended_remote_ops
.to_shortname
= "extended-remote";
12837 extended_remote_ops
.to_longname
=
12838 "Extended remote serial target in gdb-specific protocol";
12839 extended_remote_ops
.to_doc
=
12840 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12841 Specify the serial device it is connected to (e.g. /dev/ttya).";
12842 extended_remote_ops
.to_open
= extended_remote_open
;
12843 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12844 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12845 extended_remote_ops
.to_detach
= extended_remote_detach
;
12846 extended_remote_ops
.to_attach
= extended_remote_attach
;
12847 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12848 extended_remote_ops
.to_kill
= extended_remote_kill
;
12849 extended_remote_ops
.to_supports_disable_randomization
12850 = extended_remote_supports_disable_randomization
;
12851 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12852 extended_remote_ops
.to_follow_exec
= remote_follow_exec
;
12853 extended_remote_ops
.to_insert_fork_catchpoint
12854 = remote_insert_fork_catchpoint
;
12855 extended_remote_ops
.to_remove_fork_catchpoint
12856 = remote_remove_fork_catchpoint
;
12857 extended_remote_ops
.to_insert_vfork_catchpoint
12858 = remote_insert_vfork_catchpoint
;
12859 extended_remote_ops
.to_remove_vfork_catchpoint
12860 = remote_remove_vfork_catchpoint
;
12861 extended_remote_ops
.to_insert_exec_catchpoint
12862 = remote_insert_exec_catchpoint
;
12863 extended_remote_ops
.to_remove_exec_catchpoint
12864 = remote_remove_exec_catchpoint
;
12868 remote_can_async_p (struct target_ops
*ops
)
12870 struct remote_state
*rs
= get_remote_state ();
12872 if (!target_async_permitted
)
12873 /* We only enable async when the user specifically asks for it. */
12876 /* We're async whenever the serial device is. */
12877 return serial_can_async_p (rs
->remote_desc
);
12881 remote_is_async_p (struct target_ops
*ops
)
12883 struct remote_state
*rs
= get_remote_state ();
12885 if (!target_async_permitted
)
12886 /* We only enable async when the user specifically asks for it. */
12889 /* We're async whenever the serial device is. */
12890 return serial_is_async_p (rs
->remote_desc
);
12893 /* Pass the SERIAL event on and up to the client. One day this code
12894 will be able to delay notifying the client of an event until the
12895 point where an entire packet has been received. */
12897 static serial_event_ftype remote_async_serial_handler
;
12900 remote_async_serial_handler (struct serial
*scb
, void *context
)
12902 struct remote_state
*rs
= context
;
12904 /* Don't propogate error information up to the client. Instead let
12905 the client find out about the error by querying the target. */
12906 inferior_event_handler (INF_REG_EVENT
, NULL
);
12910 remote_async_inferior_event_handler (gdb_client_data data
)
12912 inferior_event_handler (INF_REG_EVENT
, NULL
);
12916 remote_async (struct target_ops
*ops
, int enable
)
12918 struct remote_state
*rs
= get_remote_state ();
12922 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12924 /* If there are pending events in the stop reply queue tell the
12925 event loop to process them. */
12926 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12927 mark_async_event_handler (remote_async_inferior_event_token
);
12931 serial_async (rs
->remote_desc
, NULL
, NULL
);
12932 clear_async_event_handler (remote_async_inferior_event_token
);
12937 set_remote_cmd (char *args
, int from_tty
)
12939 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12943 show_remote_cmd (char *args
, int from_tty
)
12945 /* We can't just use cmd_show_list here, because we want to skip
12946 the redundant "show remote Z-packet" and the legacy aliases. */
12947 struct cleanup
*showlist_chain
;
12948 struct cmd_list_element
*list
= remote_show_cmdlist
;
12949 struct ui_out
*uiout
= current_uiout
;
12951 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12952 for (; list
!= NULL
; list
= list
->next
)
12953 if (strcmp (list
->name
, "Z-packet") == 0)
12955 else if (list
->type
== not_set_cmd
)
12956 /* Alias commands are exactly like the original, except they
12957 don't have the normal type. */
12961 struct cleanup
*option_chain
12962 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12964 ui_out_field_string (uiout
, "name", list
->name
);
12965 ui_out_text (uiout
, ": ");
12966 if (list
->type
== show_cmd
)
12967 do_show_command ((char *) NULL
, from_tty
, list
);
12969 cmd_func (list
, NULL
, from_tty
);
12970 /* Close the tuple. */
12971 do_cleanups (option_chain
);
12974 /* Close the tuple. */
12975 do_cleanups (showlist_chain
);
12979 /* Function to be called whenever a new objfile (shlib) is detected. */
12981 remote_new_objfile (struct objfile
*objfile
)
12983 struct remote_state
*rs
= get_remote_state ();
12985 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12986 remote_check_symbols ();
12989 /* Pull all the tracepoints defined on the target and create local
12990 data structures representing them. We don't want to create real
12991 tracepoints yet, we don't want to mess up the user's existing
12995 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12997 struct remote_state
*rs
= get_remote_state ();
13000 /* Ask for a first packet of tracepoint definition. */
13002 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13004 while (*p
&& *p
!= 'l')
13006 parse_tracepoint_definition (p
, utpp
);
13007 /* Ask for another packet of tracepoint definition. */
13009 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13016 remote_upload_trace_state_variables (struct target_ops
*self
,
13017 struct uploaded_tsv
**utsvp
)
13019 struct remote_state
*rs
= get_remote_state ();
13022 /* Ask for a first packet of variable definition. */
13024 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13026 while (*p
&& *p
!= 'l')
13028 parse_tsv_definition (p
, utsvp
);
13029 /* Ask for another packet of variable definition. */
13031 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13037 /* The "set/show range-stepping" show hook. */
13040 show_range_stepping (struct ui_file
*file
, int from_tty
,
13041 struct cmd_list_element
*c
,
13044 fprintf_filtered (file
,
13045 _("Debugger's willingness to use range stepping "
13046 "is %s.\n"), value
);
13049 /* The "set/show range-stepping" set hook. */
13052 set_range_stepping (char *ignore_args
, int from_tty
,
13053 struct cmd_list_element
*c
)
13055 struct remote_state
*rs
= get_remote_state ();
13057 /* Whene enabling, check whether range stepping is actually
13058 supported by the target, and warn if not. */
13059 if (use_range_stepping
)
13061 if (rs
->remote_desc
!= NULL
)
13063 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13064 remote_vcont_probe (rs
);
13066 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13067 && rs
->supports_vCont
.r
)
13071 warning (_("Range stepping is not supported by the current target"));
13076 _initialize_remote (void)
13078 struct remote_state
*rs
;
13079 struct cmd_list_element
*cmd
;
13080 const char *cmd_name
;
13082 /* architecture specific data */
13083 remote_gdbarch_data_handle
=
13084 gdbarch_data_register_post_init (init_remote_state
);
13085 remote_g_packet_data_handle
=
13086 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13089 = register_program_space_data_with_cleanup (NULL
,
13090 remote_pspace_data_cleanup
);
13092 /* Initialize the per-target state. At the moment there is only one
13093 of these, not one per target. Only one target is active at a
13095 remote_state
= new_remote_state ();
13097 init_remote_ops ();
13098 add_target (&remote_ops
);
13100 init_extended_remote_ops ();
13101 add_target (&extended_remote_ops
);
13103 /* Hook into new objfile notification. */
13104 observer_attach_new_objfile (remote_new_objfile
);
13105 /* We're no longer interested in notification events of an inferior
13107 observer_attach_inferior_exit (discard_pending_stop_replies
);
13109 /* Set up signal handlers. */
13110 async_sigint_remote_token
=
13111 create_async_signal_handler (async_remote_interrupt
, NULL
);
13112 async_sigint_remote_twice_token
=
13113 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
13116 init_remote_threadtests ();
13119 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13120 /* set/show remote ... */
13122 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13123 Remote protocol specific variables\n\
13124 Configure various remote-protocol specific variables such as\n\
13125 the packets being used"),
13126 &remote_set_cmdlist
, "set remote ",
13127 0 /* allow-unknown */, &setlist
);
13128 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13129 Remote protocol specific variables\n\
13130 Configure various remote-protocol specific variables such as\n\
13131 the packets being used"),
13132 &remote_show_cmdlist
, "show remote ",
13133 0 /* allow-unknown */, &showlist
);
13135 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13136 Compare section data on target to the exec file.\n\
13137 Argument is a single section name (default: all loaded sections).\n\
13138 To compare only read-only loaded sections, specify the -r option."),
13141 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13142 Send an arbitrary packet to a remote target.\n\
13143 maintenance packet TEXT\n\
13144 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13145 this command sends the string TEXT to the inferior, and displays the\n\
13146 response packet. GDB supplies the initial `$' character, and the\n\
13147 terminating `#' character and checksum."),
13150 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13151 Set whether to send break if interrupted."), _("\
13152 Show whether to send break if interrupted."), _("\
13153 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13154 set_remotebreak
, show_remotebreak
,
13155 &setlist
, &showlist
);
13156 cmd_name
= "remotebreak";
13157 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13158 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13159 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13160 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13161 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13163 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13164 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13166 Set interrupt sequence to remote target."), _("\
13167 Show interrupt sequence to remote target."), _("\
13168 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13169 NULL
, show_interrupt_sequence
,
13170 &remote_set_cmdlist
,
13171 &remote_show_cmdlist
);
13173 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13174 &interrupt_on_connect
, _("\
13175 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13176 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13177 If set, interrupt sequence is sent to remote target."),
13179 &remote_set_cmdlist
, &remote_show_cmdlist
);
13181 /* Install commands for configuring memory read/write packets. */
13183 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13184 Set the maximum number of bytes per memory write packet (deprecated)."),
13186 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13187 Show the maximum number of bytes per memory write packet (deprecated)."),
13189 add_cmd ("memory-write-packet-size", no_class
,
13190 set_memory_write_packet_size
, _("\
13191 Set the maximum number of bytes per memory-write packet.\n\
13192 Specify the number of bytes in a packet or 0 (zero) for the\n\
13193 default packet size. The actual limit is further reduced\n\
13194 dependent on the target. Specify ``fixed'' to disable the\n\
13195 further restriction and ``limit'' to enable that restriction."),
13196 &remote_set_cmdlist
);
13197 add_cmd ("memory-read-packet-size", no_class
,
13198 set_memory_read_packet_size
, _("\
13199 Set the maximum number of bytes per memory-read packet.\n\
13200 Specify the number of bytes in a packet or 0 (zero) for the\n\
13201 default packet size. The actual limit is further reduced\n\
13202 dependent on the target. Specify ``fixed'' to disable the\n\
13203 further restriction and ``limit'' to enable that restriction."),
13204 &remote_set_cmdlist
);
13205 add_cmd ("memory-write-packet-size", no_class
,
13206 show_memory_write_packet_size
,
13207 _("Show the maximum number of bytes per memory-write packet."),
13208 &remote_show_cmdlist
);
13209 add_cmd ("memory-read-packet-size", no_class
,
13210 show_memory_read_packet_size
,
13211 _("Show the maximum number of bytes per memory-read packet."),
13212 &remote_show_cmdlist
);
13214 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13215 &remote_hw_watchpoint_limit
, _("\
13216 Set the maximum number of target hardware watchpoints."), _("\
13217 Show the maximum number of target hardware watchpoints."), _("\
13218 Specify a negative limit for unlimited."),
13219 NULL
, NULL
, /* FIXME: i18n: The maximum
13220 number of target hardware
13221 watchpoints is %s. */
13222 &remote_set_cmdlist
, &remote_show_cmdlist
);
13223 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13224 &remote_hw_watchpoint_length_limit
, _("\
13225 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13226 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13227 Specify a negative limit for unlimited."),
13228 NULL
, NULL
, /* FIXME: i18n: The maximum
13229 length (in bytes) of a target
13230 hardware watchpoint is %s. */
13231 &remote_set_cmdlist
, &remote_show_cmdlist
);
13232 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13233 &remote_hw_breakpoint_limit
, _("\
13234 Set the maximum number of target hardware breakpoints."), _("\
13235 Show the maximum number of target hardware breakpoints."), _("\
13236 Specify a negative limit for unlimited."),
13237 NULL
, NULL
, /* FIXME: i18n: The maximum
13238 number of target hardware
13239 breakpoints is %s. */
13240 &remote_set_cmdlist
, &remote_show_cmdlist
);
13242 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13243 &remote_address_size
, _("\
13244 Set the maximum size of the address (in bits) in a memory packet."), _("\
13245 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13247 NULL
, /* FIXME: i18n: */
13248 &setlist
, &showlist
);
13250 init_all_packet_configs ();
13252 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13253 "X", "binary-download", 1);
13255 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13256 "vCont", "verbose-resume", 0);
13258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13259 "QPassSignals", "pass-signals", 0);
13261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13262 "QProgramSignals", "program-signals", 0);
13264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13265 "qSymbol", "symbol-lookup", 0);
13267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13268 "P", "set-register", 1);
13270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13271 "p", "fetch-register", 1);
13273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13274 "Z0", "software-breakpoint", 0);
13276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13277 "Z1", "hardware-breakpoint", 0);
13279 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13280 "Z2", "write-watchpoint", 0);
13282 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13283 "Z3", "read-watchpoint", 0);
13285 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13286 "Z4", "access-watchpoint", 0);
13288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13289 "qXfer:auxv:read", "read-aux-vector", 0);
13291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13292 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13295 "qXfer:features:read", "target-features", 0);
13297 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13298 "qXfer:libraries:read", "library-info", 0);
13300 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13301 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13303 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13304 "qXfer:memory-map:read", "memory-map", 0);
13306 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13307 "qXfer:spu:read", "read-spu-object", 0);
13309 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13310 "qXfer:spu:write", "write-spu-object", 0);
13312 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13313 "qXfer:osdata:read", "osdata", 0);
13315 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13316 "qXfer:threads:read", "threads", 0);
13318 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13319 "qXfer:siginfo:read", "read-siginfo-object", 0);
13321 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13322 "qXfer:siginfo:write", "write-siginfo-object", 0);
13324 add_packet_config_cmd
13325 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13326 "qXfer:traceframe-info:read", "traceframe-info", 0);
13328 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13329 "qXfer:uib:read", "unwind-info-block", 0);
13331 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13332 "qGetTLSAddr", "get-thread-local-storage-address",
13335 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13336 "qGetTIBAddr", "get-thread-information-block-address",
13339 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13340 "bc", "reverse-continue", 0);
13342 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13343 "bs", "reverse-step", 0);
13345 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13346 "qSupported", "supported-packets", 0);
13348 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13349 "qSearch:memory", "search-memory", 0);
13351 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13352 "qTStatus", "trace-status", 0);
13354 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13355 "vFile:setfs", "hostio-setfs", 0);
13357 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13358 "vFile:open", "hostio-open", 0);
13360 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13361 "vFile:pread", "hostio-pread", 0);
13363 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13364 "vFile:pwrite", "hostio-pwrite", 0);
13366 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13367 "vFile:close", "hostio-close", 0);
13369 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13370 "vFile:unlink", "hostio-unlink", 0);
13372 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13373 "vFile:readlink", "hostio-readlink", 0);
13375 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13376 "vFile:fstat", "hostio-fstat", 0);
13378 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13379 "vAttach", "attach", 0);
13381 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13384 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13385 "QStartNoAckMode", "noack", 0);
13387 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13388 "vKill", "kill", 0);
13390 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13391 "qAttached", "query-attached", 0);
13393 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13394 "ConditionalTracepoints",
13395 "conditional-tracepoints", 0);
13397 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13398 "ConditionalBreakpoints",
13399 "conditional-breakpoints", 0);
13401 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13402 "BreakpointCommands",
13403 "breakpoint-commands", 0);
13405 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13406 "FastTracepoints", "fast-tracepoints", 0);
13408 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13409 "TracepointSource", "TracepointSource", 0);
13411 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13412 "QAllow", "allow", 0);
13414 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13415 "StaticTracepoints", "static-tracepoints", 0);
13417 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13418 "InstallInTrace", "install-in-trace", 0);
13420 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13421 "qXfer:statictrace:read", "read-sdata-object", 0);
13423 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13424 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13426 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13427 "QDisableRandomization", "disable-randomization", 0);
13429 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13430 "QAgent", "agent", 0);
13432 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13433 "QTBuffer:size", "trace-buffer-size", 0);
13435 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13436 "Qbtrace:off", "disable-btrace", 0);
13438 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13439 "Qbtrace:bts", "enable-btrace-bts", 0);
13441 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13442 "Qbtrace:pt", "enable-btrace-pt", 0);
13444 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13445 "qXfer:btrace", "read-btrace", 0);
13447 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13448 "qXfer:btrace-conf", "read-btrace-conf", 0);
13450 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13451 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13453 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13454 "multiprocess-feature", "multiprocess-feature", 0);
13456 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13457 "swbreak-feature", "swbreak-feature", 0);
13459 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13460 "hwbreak-feature", "hwbreak-feature", 0);
13462 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13463 "fork-event-feature", "fork-event-feature", 0);
13465 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13466 "vfork-event-feature", "vfork-event-feature", 0);
13468 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13469 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13471 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13472 "vContSupported", "verbose-resume-supported", 0);
13474 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13475 "exec-event-feature", "exec-event-feature", 0);
13477 /* Assert that we've registered "set remote foo-packet" commands
13478 for all packet configs. */
13482 for (i
= 0; i
< PACKET_MAX
; i
++)
13484 /* Ideally all configs would have a command associated. Some
13485 still don't though. */
13490 case PACKET_QNonStop
:
13491 case PACKET_EnableDisableTracepoints_feature
:
13492 case PACKET_tracenz_feature
:
13493 case PACKET_DisconnectedTracing_feature
:
13494 case PACKET_augmented_libraries_svr4_read_feature
:
13496 /* Additions to this list need to be well justified:
13497 pre-existing packets are OK; new packets are not. */
13505 /* This catches both forgetting to add a config command, and
13506 forgetting to remove a packet from the exception list. */
13507 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13511 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13512 Z sub-packet has its own set and show commands, but users may
13513 have sets to this variable in their .gdbinit files (or in their
13515 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13516 &remote_Z_packet_detect
, _("\
13517 Set use of remote protocol `Z' packets"), _("\
13518 Show use of remote protocol `Z' packets "), _("\
13519 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13521 set_remote_protocol_Z_packet_cmd
,
13522 show_remote_protocol_Z_packet_cmd
,
13523 /* FIXME: i18n: Use of remote protocol
13524 `Z' packets is %s. */
13525 &remote_set_cmdlist
, &remote_show_cmdlist
);
13527 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13528 Manipulate files on the remote system\n\
13529 Transfer files to and from the remote target system."),
13530 &remote_cmdlist
, "remote ",
13531 0 /* allow-unknown */, &cmdlist
);
13533 add_cmd ("put", class_files
, remote_put_command
,
13534 _("Copy a local file to the remote system."),
13537 add_cmd ("get", class_files
, remote_get_command
,
13538 _("Copy a remote file to the local system."),
13541 add_cmd ("delete", class_files
, remote_delete_command
,
13542 _("Delete a remote file."),
13545 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13546 &remote_exec_file_var
, _("\
13547 Set the remote pathname for \"run\""), _("\
13548 Show the remote pathname for \"run\""), NULL
,
13549 set_remote_exec_file
,
13550 show_remote_exec_file
,
13551 &remote_set_cmdlist
,
13552 &remote_show_cmdlist
);
13554 add_setshow_boolean_cmd ("range-stepping", class_run
,
13555 &use_range_stepping
, _("\
13556 Enable or disable range stepping."), _("\
13557 Show whether target-assisted range stepping is enabled."), _("\
13558 If on, and the target supports it, when stepping a source line, GDB\n\
13559 tells the target to step the corresponding range of addresses itself instead\n\
13560 of issuing multiple single-steps. This speeds up source level\n\
13561 stepping. If off, GDB always issues single-steps, even if range\n\
13562 stepping is supported by the target. The default is on."),
13563 set_range_stepping
,
13564 show_range_stepping
,
13568 /* Eventually initialize fileio. See fileio.c */
13569 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13571 /* Take advantage of the fact that the TID field is not used, to tag
13572 special ptids with it set to != 0. */
13573 magic_null_ptid
= ptid_build (42000, -1, 1);
13574 not_sent_ptid
= ptid_build (42000, -2, 1);
13575 any_thread_ptid
= ptid_build (42000, 0, 1);
13577 target_buf_size
= 2048;
13578 target_buf
= xmalloc (target_buf_size
);